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

Comparing gvpe/src/vpn.C (file contents):
Revision 1.12 by pcg, Sun Apr 13 00:42:04 2003 UTC vs.
Revision 1.13 by pcg, Sun Apr 13 16:53:36 2003 UTC

300 sum += (sum >> 16); // carry 300 sum += (sum >> 16); // carry
301 301
302 return ~sum; 302 return ~sum;
303} 303}
304 304
305#if ENABLE_ICMP
305bool 306bool
306vpn::send_icmpv4_packet (vpn_packet *pkt, const sockinfo &si, int tos) 307vpn::send_icmpv4_packet (vpn_packet *pkt, const sockinfo &si, int tos)
307{ 308{
308 setsockopt (icmpv4_fd, SOL_IP, IP_TOS, &tos, sizeof tos); 309 setsockopt (icmpv4_fd, SOL_IP, IP_TOS, &tos, sizeof tos);
309 310
317 318
318 sendto (icmpv4_fd, &((*pkt)[0]), pkt->len, 0, si.sav4 (), si.salenv4 ()); 319 sendto (icmpv4_fd, &((*pkt)[0]), pkt->len, 0, si.sav4 (), si.salenv4 ());
319 320
320 return true; 321 return true;
321} 322}
323#endif
322 324
323bool 325bool
324vpn::send_udpv4_packet (vpn_packet *pkt, const sockinfo &si, int tos) 326vpn::send_udpv4_packet (vpn_packet *pkt, const sockinfo &si, int tos)
325{ 327{
326 setsockopt (udpv4_fd, SOL_IP, IP_TOS, &tos, sizeof tos); 328 setsockopt (udpv4_fd, SOL_IP, IP_TOS, &tos, sizeof tos);
348 (const char *)rsi, pkt->typ (), pkt->src (), pkt->dst ()); 350 (const char *)rsi, pkt->typ (), pkt->src (), pkt->dst ());
349 else 351 else
350 { 352 {
351 connection *c = conns[src - 1]; 353 connection *c = conns[src - 1];
352 354
353 if (dst == 0 && !THISNODE->routerprio) 355 if (dst == 0)
354 slog (L_WARN, _("%s(%s): received broadcast, but we are no router"), 356 slog (L_WARN, _("%s(%s): received broadcast (protocol violation)"),
355 c->conf->nodename, (const char *)rsi); 357 c->conf->nodename, (const char *)rsi);
356 else if (dst != 0 && dst != THISNODE->id) 358 else if (dst != 0 && dst != THISNODE->id)
357 { 359 {
358 if (THISNODE->routerprio) 360 if (THISNODE->routerprio)
359 // the tos setting gets lost here. who cares. 361 // the tos setting gets lost here. who cares.
414 revents); 416 revents);
415 exit (1); 417 exit (1);
416 } 418 }
417} 419}
418 420
421#if ENABLE_ICMP
419void 422void
420vpn::icmpv4_ev (io_watcher &w, short revents) 423vpn::icmpv4_ev (io_watcher &w, short revents)
421{ 424{
422 if (revents & (POLLIN | POLLERR)) 425 if (revents & (POLLIN | POLLERR))
423 { 426 {
466 _("FATAL: unknown revents %08x in socket, terminating\n"), 469 _("FATAL: unknown revents %08x in socket, terminating\n"),
467 revents); 470 revents);
468 exit (1); 471 exit (1);
469 } 472 }
470} 473}
474#endif
471 475
472void 476void
473vpn::udpv4_ev (io_watcher &w, short revents) 477vpn::udpv4_ev (io_watcher &w, short revents)
474{ 478{
475 if (revents & (POLLIN | POLLERR)) 479 if (revents & (POLLIN | POLLERR))
547 if (dst != THISNODE->id) 551 if (dst != THISNODE->id)
548 conns[dst - 1]->inject_data_packet (pkt); 552 conns[dst - 1]->inject_data_packet (pkt);
549 } 553 }
550 else 554 else
551 { 555 {
552 // broadcast, first check router, then self, then english 556 // broadcast, this is ugly, but due to the security policy
553 connection *router = find_router (); 557 // we have to connect to all hosts...
554
555 if (router)
556 router->inject_data_packet (pkt, true);
557 else
558 for (conns_vector::iterator c = conns.begin (); c != conns.end (); ++c) 558 for (conns_vector::iterator c = conns.begin (); c != conns.end (); ++c)
559 if ((*c)->conf != THISNODE) 559 if ((*c)->conf != THISNODE)
560 (*c)->inject_data_packet (pkt); 560 (*c)->inject_data_packet (pkt);
561 } 561 }
562 } 562 }
563 563
564 delete pkt; 564 delete pkt;
565 } 565 }
639 639
640 for (conns_vector::iterator i = conns.begin (); i != conns.end (); ++i) 640 for (conns_vector::iterator i = conns.begin (); i != conns.end (); ++i)
641 { 641 {
642 connection *c = *i; 642 connection *c = *i;
643 643
644 if (c->conf->routerprio >= prio 644 if (c->conf->routerprio > prio
645 && c->connectmode == conf_node::C_ALWAYS // so we don't drop the connection if in use 645 && c->connectmode == conf_node::C_ALWAYS // so we don't drop the connection if in use
646 && c->ictx && c->octx 646 && c->ictx && c->octx
647 && c->conf != THISNODE // redundant, since ictx==octx==0 always on thisnode 647 && c->conf != THISNODE) // redundant, since ictx==octx==0 always on thisnode
648 && (!THISNODE->routerprio
649 || c->conf->routerprio <= THISNODE->routerprio))
650 { 648 {
651 prio = c->conf->routerprio; 649 prio = c->conf->routerprio;
652 router = c; 650 router = c;
653 } 651 }
654 } 652 }
663 if (c) 661 if (c)
664 c->send_connect_request (id); 662 c->send_connect_request (id);
665 else 663 else
666 // no router found, aggressively connect to all routers 664 // no router found, aggressively connect to all routers
667 for (conns_vector::iterator i = conns.begin (); i != conns.end (); ++i) 665 for (conns_vector::iterator i = conns.begin (); i != conns.end (); ++i)
668 if ((*i)->conf->routerprio) 666 if ((*i)->conf->routerprio && (*i)->conf != THISNODE)
669 (*i)->establish_connection (); 667 (*i)->establish_connection ();
670} 668}
671 669
672void 670void
673connection::dump_status () 671connection::dump_status ()

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines