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

Comparing gvpe/src/protocol.C (file contents):
Revision 1.4 by pcg, Thu Mar 6 18:43:07 2003 UTC vs.
Revision 1.6 by pcg, Sun Mar 9 12:40:18 2003 UTC

481connection::send_ping (SOCKADDR *dsa, u8 pong) 481connection::send_ping (SOCKADDR *dsa, u8 pong)
482{ 482{
483 ping_packet *pkt = new ping_packet; 483 ping_packet *pkt = new ping_packet;
484 484
485 pkt->setup (conf->id, pong ? ping_packet::PT_PONG : ping_packet::PT_PING); 485 pkt->setup (conf->id, pong ? ping_packet::PT_PONG : ping_packet::PT_PING);
486 vpn->send_vpn_packet (pkt, dsa); 486 vpn->send_vpn_packet (pkt, dsa, IPTOS_LOWDELAY);
487 487
488 delete pkt; 488 delete pkt;
489} 489}
490 490
491void 491void
496 if (limiter.can (dsa)) 496 if (limiter.can (dsa))
497 { 497 {
498 config_packet *pkt = new config_packet; 498 config_packet *pkt = new config_packet;
499 499
500 pkt->setup (vpn_packet::PT_RESET, conf->id); 500 pkt->setup (vpn_packet::PT_RESET, conf->id);
501 vpn->send_vpn_packet (pkt, dsa); 501 vpn->send_vpn_packet (pkt, dsa, IPTOS_MINCOST);
502 502
503 delete pkt; 503 delete pkt;
504 } 504 }
505} 505}
506 506
550 fatal ("RSA_public_encrypt error"); 550 fatal ("RSA_public_encrypt error");
551#endif 551#endif
552 552
553 slog (L_TRACE, ">>%d PT_AUTH(%d) [%s]", conf->id, subtype, (const char *)sockinfo (sa)); 553 slog (L_TRACE, ">>%d PT_AUTH(%d) [%s]", conf->id, subtype, (const char *)sockinfo (sa));
554 554
555 vpn->send_vpn_packet (pkt, sa); 555 vpn->send_vpn_packet (pkt, sa, IPTOS_RELIABILITY);
556 556
557 delete pkt; 557 delete pkt;
558 } 558 }
559} 559}
560 560
561void 561void
562connection::establish_connection () 562connection::establish_connection ()
563{ 563{
564 if (!ictx && conf != THISNODE && conf->connectmode != conf_node::C_NEVER) 564 if (!ictx && conf != THISNODE && connectmode != conf_node::C_NEVER)
565 { 565 {
566 if (now >= next_retry) 566 if (now >= next_retry)
567 { 567 {
568 int retry_int = retry_cnt & 3 ? (retry_cnt & 3) : 1 << (retry_cnt >> 2); 568 int retry_int = retry_cnt & 3 ? (retry_cnt & 3) : 1 << (retry_cnt >> 2);
569 569
570 if (retry_cnt < (17 << 2) | 3) 570 if (retry_cnt < (17 << 2) | 3)
571 retry_cnt++; 571 retry_cnt++;
572 572
573 if (conf->connectmode == conf_node::C_ONDEMAND 573 if (connectmode == conf_node::C_ONDEMAND
574 && retry_int > ::conf.keepalive) 574 && retry_int > ::conf.keepalive)
575 retry_int = ::conf.keepalive; 575 retry_int = ::conf.keepalive;
576 576
577 next_retry = now + retry_int; 577 next_retry = now + retry_int;
578 next_wakeup (next_retry); 578 next_wakeup (next_retry);
635 635
636void 636void
637connection::send_data_packet (tap_packet * pkt, bool broadcast) 637connection::send_data_packet (tap_packet * pkt, bool broadcast)
638{ 638{
639 vpndata_packet *p = new vpndata_packet; 639 vpndata_packet *p = new vpndata_packet;
640 int tos = 0;
641
642 if (conf->inherit_tos
643 && (*pkt)[12] == 0x08 && (*pkt)[13] == 0x00 // IP
644 && ((*pkt)[14] & 0xf0) == 0x40) // IPv4
645 tos = (*pkt)[15] & IPTOS_TOS_MASK;
646 printf ("%d %02x %02x %02x %02x = %02x\n", (int)conf->inherit_tos, (*pkt)[12],(*pkt)[13],(*pkt)[14],(*pkt)[15], tos);
640 647
641 p->setup (this, broadcast ? 0 : conf->id, &((*pkt)[6 + 6]), pkt->len - 6 - 6, ++oseqno); // skip 2 macs 648 p->setup (this, broadcast ? 0 : conf->id, &((*pkt)[6 + 6]), pkt->len - 6 - 6, ++oseqno); // skip 2 macs
642 vpn->send_vpn_packet (p, &sa); 649 vpn->send_vpn_packet (p, &sa, tos);
643 650
644 delete p; 651 delete p;
645 652
646 if (oseqno > MAX_SEQNO) 653 if (oseqno > MAX_SEQNO)
647 rekey (); 654 rekey ();
692 { 699 {
693 reset_connection (); 700 reset_connection ();
694 701
695 config_packet *p = (config_packet *) pkt; 702 config_packet *p = (config_packet *) pkt;
696 if (p->chk_config ()) 703 if (p->chk_config ())
697 if (conf->connectmode == conf_node::C_ALWAYS) 704 if (connectmode == conf_node::C_ALWAYS)
698 establish_connection (); 705 establish_connection ();
699 706
700 //D slog the protocol mismatch? 707 //D slog the protocol mismatch?
701 } 708 }
702 break; 709 break;
781 while (tap_packet *p = queue.get ()) 788 while (tap_packet *p = queue.get ())
782 { 789 {
783 send_data_packet (p); 790 send_data_packet (p);
784 delete p; 791 delete p;
785 } 792 }
793
794 connectmode = conf->connectmode;
786 795
787 slog (L_INFO, _("connection to %d (%s %s) established"), 796 slog (L_INFO, _("connection to %d (%s %s) established"),
788 conf->id, conf->nodename, (const char *)sockinfo (ssa)); 797 conf->id, conf->nodename, (const char *)sockinfo (ssa));
789 798
790 if (::conf.script_node_up) 799 if (::conf.script_node_up)
949 958
950void connection::timer () 959void connection::timer ()
951{ 960{
952 if (conf != THISNODE) 961 if (conf != THISNODE)
953 { 962 {
954 if (now >= next_retry && conf->connectmode == conf_node::C_ALWAYS) 963 if (now >= next_retry && connectmode == conf_node::C_ALWAYS)
955 establish_connection (); 964 establish_connection ();
956 965
957 if (ictx && octx) 966 if (ictx && octx)
958 { 967 {
959 if (now >= next_rekey) 968 if (now >= next_rekey)
1093 1102
1094 return 0; 1103 return 0;
1095} 1104}
1096 1105
1097void 1106void
1098vpn::send_vpn_packet (vpn_packet *pkt, SOCKADDR *sa) 1107vpn::send_vpn_packet (vpn_packet *pkt, SOCKADDR *sa, int tos)
1099{ 1108{
1109 setsockopt (socket_fd, SOL_IP, IP_TOS, &tos, sizeof tos);
1100 sendto (socket_fd, &((*pkt)[0]), pkt->len, 0, (sockaddr *)sa, sizeof (*sa)); 1110 sendto (socket_fd, &((*pkt)[0]), pkt->len, 0, (sockaddr *)sa, sizeof (*sa));
1101} 1111}
1102 1112
1103void 1113void
1104vpn::shutdown_all () 1114vpn::shutdown_all ()
1121 connection *conn = new connection (this); 1131 connection *conn = new connection (this);
1122 1132
1123 conn->conf = *i; 1133 conn->conf = *i;
1124 conns.push_back (conn); 1134 conns.push_back (conn);
1125 1135
1126 if (conn->conf->connectmode == conf_node::C_ALWAYS)
1127 conn->establish_connection (); 1136 conn->establish_connection ();
1128 } 1137 }
1129} 1138}
1130 1139
1131connection *vpn::find_router () 1140connection *vpn::find_router ()
1132{ 1141{
1136 for (conns_vector::iterator i = conns.begin (); i != conns.end (); ++i) 1145 for (conns_vector::iterator i = conns.begin (); i != conns.end (); ++i)
1137 { 1146 {
1138 connection *c = *i; 1147 connection *c = *i;
1139 1148
1140 if (c->conf->routerprio > prio 1149 if (c->conf->routerprio > prio
1141 && c->conf->connectmode == conf_node::C_ALWAYS 1150 && c->connectmode == conf_node::C_ALWAYS
1142 && c->conf != THISNODE 1151 && c->conf != THISNODE
1143 && c->ictx && c->octx) 1152 && c->ictx && c->octx)
1144 { 1153 {
1145 prio = c->conf->routerprio; 1154 prio = c->conf->routerprio;
1146 router = c; 1155 router = c;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines