ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/gvpe/src/connection.C
(Generate patch)

Comparing gvpe/src/connection.C (file contents):
Revision 1.36 by pcg, Sun May 30 17:36:00 2004 UTC vs.
Revision 1.41 by pcg, Wed Mar 2 05:49:31 2005 UTC

627 protocol = best_protocol (THISNODE->protocols & conf->protocols); 627 protocol = best_protocol (THISNODE->protocols & conf->protocols);
628 628
629 // mask out protocols we cannot establish 629 // mask out protocols we cannot establish
630 if (!conf->udp_port) protocol &= ~PROT_UDPv4; 630 if (!conf->udp_port) protocol &= ~PROT_UDPv4;
631 if (!conf->tcp_port) protocol &= ~PROT_TCPv4; 631 if (!conf->tcp_port) protocol &= ~PROT_TCPv4;
632 if (!conf->dns_port) protocol &= ~PROT_DNSv4;
632 633
633 si.set (conf, protocol); 634 si.set (conf, protocol);
634} 635}
635 636
636// ensure sockinfo is valid, forward if necessary 637// ensure sockinfo is valid, forward if necessary
656} 657}
657 658
658void 659void
659connection::send_vpn_packet (vpn_packet *pkt, const sockinfo &si, int tos) 660connection::send_vpn_packet (vpn_packet *pkt, const sockinfo &si, int tos)
660{ 661{
661 if (!vpn->send_vpn_packet (pkt, si, tos)) 662 bool ok;
663
664 switch (si.prot)
665 {
666 case PROT_IPv4:
667 ok = vpn->send_ipv4_packet (pkt, si, tos); break;
668 case PROT_UDPv4:
669 ok = vpn->send_udpv4_packet (pkt, si, tos); break;
670#if ENABLE_TCP
671 case PROT_TCPv4:
672 ok = vpn->send_tcpv4_packet (pkt, si, tos); break;
673#endif
674#if ENABLE_ICMP
675 case PROT_ICMPv4:
676 ok = vpn->send_icmpv4_packet (pkt, si, tos); break;
677#endif
678#if ENABLE_DNS
679 case PROT_DNSv4:
680 ok = send_dnsv4_packet (pkt, si, tos); break;
681#endif
682
683 default:
684 slog (L_CRIT, _("%s: FATAL: trying to send packet with unsupported protocol"), (const char *)si);
685 ok = false;
686 }
687
688 if (!ok)
662 reset_connection (); 689 reset_connection ();
663} 690}
664 691
665void 692void
666connection::send_ping (const sockinfo &si, u8 pong) 693connection::send_ping (const sockinfo &si, u8 pong)
744 && connectmode != conf_node::C_DISABLED 771 && connectmode != conf_node::C_DISABLED
745 && NOW > w.at) 772 && NOW > w.at)
746 { 773 {
747 double retry_int = double (retry_cnt & 3 ? (retry_cnt & 3) : 1 << (retry_cnt >> 2)) * 0.6; 774 double retry_int = double (retry_cnt & 3 ? (retry_cnt & 3) : 1 << (retry_cnt >> 2)) * 0.6;
748 775
749 if (retry_int < 3600 * 8) 776 if (retry_int < conf->max_retry)
750 retry_cnt++; 777 retry_cnt++;
778 else
779 retry_int = conf->max_retry;
751 780
752 w.start (NOW + retry_int); 781 w.start (NOW + retry_int);
753 782
754 reset_si (); 783 reset_si ();
755 784
783 } 812 }
784 813
785 delete ictx; ictx = 0; 814 delete ictx; ictx = 0;
786 delete octx; octx = 0; 815 delete octx; octx = 0;
787 816
788 si.host= 0; 817 si.host = 0;
789 818
790 last_activity = 0; 819 last_activity = 0;
791 retry_cnt = 0; 820 retry_cnt = 0;
792 821
793 rekey.stop (); 822 rekey.stop ();
1096 break; 1125 break;
1097 1126
1098 case vpn_packet::PT_CONNECT_INFO: 1127 case vpn_packet::PT_CONNECT_INFO:
1099 if (ictx && octx && rsi == si && pkt->hmac_chk (ictx)) 1128 if (ictx && octx && rsi == si && pkt->hmac_chk (ictx))
1100 { 1129 {
1101 connect_info_packet *p = (connect_info_packet *) pkt; 1130 connect_info_packet *p = (connect_info_packet *)pkt;
1102 1131
1103 assert (p->id > 0 && p->id <= vpn->conns.size ()); // hmac-auth does not mean we accept anything 1132 if (p->id > 0 && p->id <= vpn->conns.size ()) // hmac-auth does not mean we accept anything
1104 1133 {
1105 connection *c = vpn->conns[p->id - 1]; 1134 connection *c = vpn->conns[p->id - 1];
1106 1135
1107 c->conf->protocols = p->protocols; 1136 c->conf->protocols = p->protocols;
1108 protocol = best_protocol (c->conf->protocols & THISNODE->protocols & p->si.supported_protocols (c->conf)); 1137 protocol = best_protocol (c->conf->protocols & THISNODE->protocols & p->si.supported_protocols (c->conf));
1109 p->si.upgrade_protocol (protocol, c->conf); 1138 p->si.upgrade_protocol (protocol, c->conf);
1110 1139
1111 slog (L_TRACE, "<<%d PT_CONNECT_INFO(%d,%s) (%d)", 1140 slog (L_TRACE, "<<%d PT_CONNECT_INFO(%d,%s) (%d)",
1112 conf->id, p->id, (const char *)p->si, !c->ictx && !c->octx); 1141 conf->id, p->id, (const char *)p->si, !c->ictx && !c->octx);
1113 1142
1114 const sockinfo &dsi = forward_si (p->si); 1143 const sockinfo &dsi = forward_si (p->si);
1115 1144
1116 if (dsi.valid ()) 1145 if (dsi.valid ())
1117 c->send_auth_request (dsi, true); 1146 c->send_auth_request (dsi, true);
1147 }
1118 } 1148 }
1119 1149
1120 break; 1150 break;
1121 1151
1122 default: 1152 default:
1186 putenv ("STATE=down"); 1216 putenv ("STATE=down");
1187 1217
1188 return ::conf.script_node_up ? ::conf.script_node_down : "node-down"; 1218 return ::conf.script_node_up ? ::conf.script_node_down : "node-down";
1189} 1219}
1190 1220
1191connection::connection(struct vpn *vpn_) 1221connection::connection (struct vpn *vpn, conf_node *conf)
1192: vpn(vpn_) 1222: vpn(vpn), conf(conf)
1193, rekey (this, &connection::rekey_cb) 1223, rekey (this, &connection::rekey_cb)
1194, keepalive (this, &connection::keepalive_cb) 1224, keepalive (this, &connection::keepalive_cb)
1195, establish_connection (this, &connection::establish_connection_cb) 1225, establish_connection (this, &connection::establish_connection_cb)
1226#if ENABLE_DNS
1227, dnsv4_tw (this, &connection::dnsv4_cb)
1228, dns_rcvdq (0), dns_snddq (0)
1229, dns_rcvseq (0), dns_sndseq (0)
1230#endif
1196{ 1231{
1197 octx = ictx = 0; 1232 octx = ictx = 0;
1198 retry_cnt = 0; 1233 retry_cnt = 0;
1199 1234
1235 if (!conf->protocols) // make sure some protocol is enabled
1236 conf->protocols = PROT_UDPv4;
1237
1200 connectmode = conf_node::C_ALWAYS; // initial setting 1238 connectmode = conf_node::C_ALWAYS; // initial setting
1201 reset_connection (); 1239 reset_connection ();
1202} 1240}
1203 1241
1204connection::~connection () 1242connection::~connection ()

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines