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.59 by root, Fri Sep 16 17:59:46 2011 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
521 return send_ipv4_packet (pkt, si, tos); 521 return send_ipv4_packet (pkt, si, tos);
522 522
523 case PROT_UDPv4: 523 case PROT_UDPv4:
524 return send_udpv4_packet (pkt, si, tos); 524 return send_udpv4_packet (pkt, si, tos);
525 525
526#if ENABLE_TCP 526#if ENABLE_TCP
527 case PROT_TCPv4: 527 case PROT_TCPv4:
528 return send_tcpv4_packet (pkt, si, tos); 528 return send_tcpv4_packet (pkt, si, tos);
529#endif 529#endif
530#if ENABLE_ICMP 530#if ENABLE_ICMP
531 case PROT_ICMPv4: 531 case PROT_ICMPv4:
559 if (len > 0) 559 if (len > 0)
560 { 560 {
561 pkt->len = len; 561 pkt->len = len;
562 562
563 // raw sockets deliver the ipv4 header, but don't expect it on sends 563 // raw sockets deliver the ipv4 header, but don't expect it on sends
564 pkt->skip_hdr (IP_OVERHEAD); 564 pkt->skip_ipv4_hdr ();
565 565
566 recv_vpn_packet (pkt, si); 566 recv_vpn_packet (pkt, si);
567 } 567 }
568 else 568 else
569 { 569 {
606 if (hdr->type == ::conf.icmp_type 606 if (hdr->type == ::conf.icmp_type
607 && hdr->code == 255) 607 && hdr->code == 255)
608 { 608 {
609 // raw sockets deliver the ipv4, but don't expect it on sends 609 // raw sockets deliver the ipv4, but don't expect it on sends
610 // this is slow, but... 610 // this is slow, but...
611 pkt->skip_hdr (ICMP_OVERHEAD); 611 pkt->skip_ipv4_hdr (ICMP_OVERHEAD - IP_OVERHEAD);
612 612
613 recv_vpn_packet (pkt, si); 613 recv_vpn_packet (pkt, si);
614 } 614 }
615 } 615 }
616 else 616 else
758 758
759 for (conns_vector::iterator c = conns.begin (); c != conns.end (); ++c) 759 for (conns_vector::iterator c = conns.begin (); c != conns.end (); ++c)
760 (*c)->establish_connection (); 760 (*c)->establish_connection ();
761} 761}
762 762
763bool
763bool vpn::can_direct (conf_node *src, conf_node *dst) const 764vpn::can_direct (conf_node *src, conf_node *dst) const
764{ 765{
765 return src != dst 766 return src != dst
766 && src->may_direct (dst) 767 && src->may_direct (dst)
767 && dst->may_direct (src) 768 && dst->may_direct (src)
768 && (((src->protocols & dst->protocols) && src->connectmode == conf_node::C_ALWAYS) 769 && (((src->protocols & dst->protocols) && src->connectmode == conf_node::C_ALWAYS)
769 || (src->protocols & dst->connectable_protocols ())); 770 || (src->protocols & dst->connectable_protocols ()));
770} 771}
771 772
772// only works for indirect and routed connections: find a router 773// only works for indirect and routed connections: find a router
773// from THISNODE to dst 774// from THISNODE to dst
775connection *
774connection *vpn::find_router_for (const connection *dst) 776vpn::find_router_for (const connection *dst)
775{ 777{
776 connection *router = 0; 778 connection *router = 0;
777 779
778 // first try to find a router with a direct connection, route there 780 // first try to find a router with a direct connection, route there
779 // regardless of any other considerations. 781 // regardless of any other considerations.
818 } 820 }
819 821
820 return router; 822 return router;
821} 823}
822 824
825void
823void vpn::connection_established (connection *c) 826vpn::connection_established (connection *c)
824{ 827{
825 for (conns_vector::iterator i = conns.begin (); i != conns.end (); ++i) 828 for (conns_vector::iterator i = conns.begin (); i != conns.end (); ++i)
826 { 829 {
827 connection *o = *i; 830 connection *o = *i;
828 831
836 o->rekey (); 839 o->rekey ();
837 } 840 }
838 } 841 }
839} 842}
840 843
844void
841void vpn::send_connect_request (connection *c) 845vpn::send_connect_request (connection *c)
842{ 846{
843 connection *r = find_router_for (c); 847 connection *r = find_router_for (c);
844 848
845 if (r) 849 if (r)
846 { 850 {

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines