--- gvpe/src/vpn.C 2004/07/25 18:11:40 1.25 +++ gvpe/src/vpn.C 2005/03/07 01:31:26 1.32 @@ -1,8 +1,10 @@ /* vpn.C -- handle the protocol, encryption, handshaking etc. - Copyright (C) 2003-2004 Marc Lehmann + Copyright (C) 2003-2005 Marc Lehmann - This program is free software; you can redistribute it and/or modify + This file is part of GVPE. + + GVPE is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. @@ -13,7 +15,7 @@ GNU General Public License for more details. You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software + along with gvpe; if not, write to the Free Software Foundation, Inc. 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ @@ -228,18 +230,32 @@ #if ENABLE_DNS if (THISNODE->protocols & PROT_DNSv4) { + dns_forwarder.set (::conf.dns_forw_host, ::conf.dns_forw_port, PROT_DNSv4); + dnsv4_fd = socket (PF_INET, SOCK_DGRAM, IPPROTO_UDP); if (dnsv4_fd < 0) return -1; +#if defined(SOL_IP) && defined(IP_MTU_DISCOVER) + // this I really consider a linux bug. I am neither connected + // nor do I fragment myself. Linux still sets DF and doesn't + // fragment for me sometimes. + { + int oval = IP_PMTUDISC_DONT; + setsockopt (udpv4_fd, SOL_IP, IP_MTU_DISCOVER, &oval, sizeof oval); + } +#endif + // standard daemon practise... { int oval = 1; - setsockopt (tcpv4_fd, SOL_SOCKET, SO_REUSEADDR, &oval, sizeof oval); + setsockopt (dnsv4_fd, SOL_SOCKET, SO_REUSEADDR, &oval, sizeof oval); } - sockinfo si (THISNODE, PROT_DNSv4); + sockinfo si (THISNODE->dns_hostname, + THISNODE->dns_hostname ? THISNODE->dns_port : 0, + PROT_DNSv4); if (bind (dnsv4_fd, si.sav4 (), si.salenv4 ())) { @@ -267,39 +283,6 @@ return 0; } -// send a vpn packet out to other hosts -bool -vpn::send_vpn_packet (vpn_packet *pkt, const sockinfo &si, int tos) -{ - switch (si.prot) - { - case PROT_IPv4: - return send_ipv4_packet (pkt, si, tos); - - case PROT_UDPv4: - return send_udpv4_packet (pkt, si, tos); - -#if ENABLE_TCP - case PROT_TCPv4: - return send_tcpv4_packet (pkt, si, tos); -#endif - -#if ENABLE_ICMP - case PROT_ICMPv4: - return send_icmpv4_packet (pkt, si, tos); -#endif - -#if ENABLE_DNS - case PROT_DNSv4: - return send_dnsv4_packet (pkt, si, tos); -#endif - - default: - slog (L_CRIT, _("%s: FATAL: trying to send packet with unsupported protocol"), (const char *)si); - return false; - } -} - bool vpn::send_ipv4_packet (vpn_packet *pkt, const sockinfo &si, int tos) { @@ -426,6 +409,35 @@ } } +bool +vpn::send_vpn_packet (vpn_packet *pkt, const sockinfo &si, int tos) +{ + switch (si.prot) + { + case PROT_IPv4: + return send_ipv4_packet (pkt, si, tos); + case PROT_UDPv4: + return send_udpv4_packet (pkt, si, tos); +#if ENABLE_TCP + case PROT_TCPv4: + return send_tcpv4_packet (pkt, si, tos); +#endif +#if ENABLE_ICMP + case PROT_ICMPv4: + return send_icmpv4_packet (pkt, si, tos); +#endif +#if ENABLE_DNS + case PROT_DNSv4: + return send_dnsv4_packet (pkt, si, tos); +#endif + + default: + slog (L_CRIT, _("%s: FATAL: trying to send packet with unsupported protocol"), (const char *)si); + } + + return false; +} + void vpn::ipv4_ev (io_watcher &w, short revents) { @@ -444,8 +456,7 @@ { pkt->len = len; - // raw sockets deliver the ipv4, but don't expect it on sends - // this is slow, but... + // raw sockets deliver the ipv4 header, but don't expect it on sends pkt->skip_hdr (IP_OVERHEAD); recv_vpn_packet (pkt, si); @@ -461,8 +472,8 @@ else { slog (L_ERR, - _("FATAL: unknown revents %08x in socket, terminating\n"), - revents); + _("FATAL: unknown revents %08x in socket, terminating\n"), + revents); exit (EXIT_FAILURE); } } @@ -573,7 +584,7 @@ if (src != THISNODE->id) { - slog (L_ERR, _("FATAL: tap packet not originating on current node received, exiting.")); + slog (L_ERR, _("FATAL: tap packet not originating on current node received (if-up script not working properly?), exiting.")); exit (EXIT_FAILURE); } @@ -641,18 +652,15 @@ for (configuration::node_vector::iterator i = conf.nodes.begin (); i != conf.nodes.end (); ++i) { - connection *conn = new connection (this); - - conn->conf = *i; + connection *conn = new connection (this, *i); conns.push_back (conn); - conn->establish_connection (); } } connection *vpn::find_router () { - u32 prio = 0; + u32 prio = 1; connection *router = 0; for (conns_vector::iterator i = conns.begin (); i != conns.end (); ++i)