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.55 by pcg, Fri Mar 27 22:02:57 2009 UTC vs.
Revision 1.63 by root, Tue Jan 17 21:38:11 2012 UTC

1/* 1/*
2 vpn.C -- handle the protocol, encryption, handshaking etc. 2 vpn.C -- handle the protocol, encryption, handshaking etc.
3 Copyright (C) 2003-2008 Marc Lehmann <gvpe@schmorp.de> 3 Copyright (C) 2003-2008,2010,2011 Marc Lehmann <gvpe@schmorp.de>
4 4
5 This file is part of GVPE. 5 This file is part of GVPE.
6 6
7 GVPE is free software; you can redistribute it and/or modify it 7 GVPE is free software; you can redistribute it and/or modify it
8 under the terms of the GNU General Public License as published by the 8 under the terms of the GNU General Public License as published by the
484 if (src == 0 || src > conns.size () 484 if (src == 0 || src > conns.size ()
485 || dst > conns.size () 485 || dst > conns.size ()
486 || pkt->typ () >= vpn_packet::PT_MAX) 486 || pkt->typ () >= vpn_packet::PT_MAX)
487 slog (L_WARN, _("(%s): received corrupted packet type %d (src %d, dst %d)."), 487 slog (L_WARN, _("(%s): received corrupted packet type %d (src %d, dst %d)."),
488 (const char *)rsi, pkt->typ (), pkt->src (), pkt->dst ()); 488 (const char *)rsi, pkt->typ (), pkt->src (), pkt->dst ());
489 else if (dst > conns.size ())
490 slog (L_WARN, _("(%s): received corrupted packet type %d (src %d, dst %d)."),
491 (const char *)rsi, pkt->typ (), pkt->src (), pkt->dst ());
492 else 489 else
493 { 490 {
494 connection *c = conns[src - 1]; 491 connection *c = conns[src - 1];
495 492
496 if (dst == 0) 493 if (dst == 0)
516vpn::send_vpn_packet (vpn_packet *pkt, const sockinfo &si, int tos) 513vpn::send_vpn_packet (vpn_packet *pkt, const sockinfo &si, int tos)
517{ 514{
518 switch (si.prot) 515 switch (si.prot)
519 { 516 {
520 case PROT_IPv4: 517 case PROT_IPv4:
521 return send_ipv4_packet (pkt, si, tos); 518 return send_ipv4_packet (pkt, si, tos);
522 519
523 case PROT_UDPv4: 520 case PROT_UDPv4:
524 return send_udpv4_packet (pkt, si, tos); 521 return send_udpv4_packet (pkt, si, tos);
525 522
526#if ENABLE_TCP 523#if ENABLE_TCP
527 case PROT_TCPv4: 524 case PROT_TCPv4:
528 return send_tcpv4_packet (pkt, si, tos); 525 return send_tcpv4_packet (pkt, si, tos);
529#endif 526#endif
530#if ENABLE_ICMP 527#if ENABLE_ICMP
531 case PROT_ICMPv4: 528 case PROT_ICMPv4:
532 return send_icmpv4_packet (pkt, si, tos); 529 return send_icmpv4_packet (pkt, si, tos);
533#endif 530#endif
534#if ENABLE_DNS 531#if ENABLE_DNS
535 case PROT_DNSv4: 532 case PROT_DNSv4:
536 return send_dnsv4_packet (pkt, si, tos); 533 return send_dnsv4_packet (pkt, si, tos);
537#endif 534#endif
538 default: 535 default:
539 slog (L_CRIT, _("%s: FATAL: trying to send packet with unsupported protocol."), (const char *)si); 536 slog (L_CRIT, _("%s: FATAL: trying to send packet with unsupported protocol."), (const char *)si);
540 } 537 }
541 538
559 if (len > 0) 556 if (len > 0)
560 { 557 {
561 pkt->len = len; 558 pkt->len = len;
562 559
563 // raw sockets deliver the ipv4 header, but don't expect it on sends 560 // raw sockets deliver the ipv4 header, but don't expect it on sends
564 pkt->skip_hdr (IP_OVERHEAD); 561 pkt->skip_hdr (pkt->ipv4_hdr_len ());
565 562
566 recv_vpn_packet (pkt, si); 563 recv_vpn_packet (pkt, si);
567 } 564 }
568 else 565 else
569 { 566 {
606 if (hdr->type == ::conf.icmp_type 603 if (hdr->type == ::conf.icmp_type
607 && hdr->code == 255) 604 && hdr->code == 255)
608 { 605 {
609 // raw sockets deliver the ipv4, but don't expect it on sends 606 // raw sockets deliver the ipv4, but don't expect it on sends
610 // this is slow, but... 607 // this is slow, but...
611 pkt->skip_hdr (ICMP_OVERHEAD); 608 pkt->skip_hdr (pkt->ipv4_hdr_len () + (ICMP_OVERHEAD - IP_OVERHEAD));
612 609
613 recv_vpn_packet (pkt, si); 610 recv_vpn_packet (pkt, si);
614 } 611 }
615 } 612 }
616 else 613 else
758 755
759 for (conns_vector::iterator c = conns.begin (); c != conns.end (); ++c) 756 for (conns_vector::iterator c = conns.begin (); c != conns.end (); ++c)
760 (*c)->establish_connection (); 757 (*c)->establish_connection ();
761} 758}
762 759
760bool
763bool vpn::can_direct (conf_node *src, conf_node *dst) const 761vpn::can_direct (conf_node *src, conf_node *dst) const
764{ 762{
765 return src != dst 763 return src != dst
766 && src->may_direct (dst) 764 && src->may_direct (dst)
767 && dst->may_direct (src) 765 && dst->may_direct (src)
768 && (((src->protocols & dst->protocols) && src->connectmode == conf_node::C_ALWAYS) 766 && (((src->protocols & dst->protocols) && src->connectmode == conf_node::C_ALWAYS)
769 || (src->protocols & dst->connectable_protocols ())); 767 || (src->protocols & dst->connectable_protocols ()));
770} 768}
771 769
772// only works for indirect and routed connections: find a router 770// only works for indirect and routed connections: find a router
773// from THISNODE to dst 771// from THISNODE to dst
772connection *
774connection *vpn::find_router_for (const connection *dst) 773vpn::find_router_for (const connection *dst)
775{ 774{
776 connection *router = 0; 775 connection *router = 0;
777 776
778 // first try to find a router with a direct connection, route there 777 // first try to find a router with a direct connection, route there
779 // regardless of any other considerations. 778 // regardless of any other considerations.
818 } 817 }
819 818
820 return router; 819 return router;
821} 820}
822 821
822void
823void vpn::connection_established (connection *c) 823vpn::connection_established (connection *c)
824{ 824{
825 for (conns_vector::iterator i = conns.begin (); i != conns.end (); ++i) 825 for (conns_vector::iterator i = conns.begin (); i != conns.end (); ++i)
826 { 826 {
827 connection *o = *i; 827 connection *o = *i;
828 828
836 o->rekey (); 836 o->rekey ();
837 } 837 }
838 } 838 }
839} 839}
840 840
841void
841void vpn::send_connect_request (connection *c) 842vpn::send_connect_request (connection *c)
842{ 843{
843 connection *r = find_router_for (c); 844 connection *r = find_router_for (c);
844 845
845 if (r) 846 if (r)
846 { 847 {

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines