--- gvpe/src/vpn.C 2005/03/23 21:55:39 1.33 +++ gvpe/src/vpn.C 2007/12/01 23:35:31 1.40 @@ -16,7 +16,7 @@ You should have received a copy of the GNU General Public License along with gvpe; if not, write to the Free Software - Foundation, Inc. 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + Foundation, Inc. 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ #include "config.h" @@ -60,17 +60,21 @@ char *env; asprintf (&env, "CONFBASE=%s", confbase); putenv (env); - asprintf (&env, "NODENAME=%s", THISNODE->nodename); putenv (env); - asprintf (&env, "NODEID=%d", THISNODE->id); putenv (env); asprintf (&env, "IFNAME=%s", tap->interface ()); putenv (env); asprintf (&env, "IFTYPE=%s", IFTYPE); putenv (env); asprintf (&env, "IFSUBTYPE=%s", IFSUBTYPE); putenv (env); asprintf (&env, "MTU=%d", mtu); putenv (env); - asprintf (&env, "MAC=%02x:%02x:%02x:%02x:%02x:%02x", - 0xfe, 0xfd, 0x80, 0x00, THISNODE->id >> 8, - THISNODE->id & 0xff); putenv (env); + asprintf (&env, "NODES=%d", conns.size ()); putenv (env); + asprintf (&env, "NODEID=%d", THISNODE->id); putenv (env); + + conns [THISNODE->id - 1]->script_init_env (""); - // TODO: info for other nodes, maybe? + for (conns_vector::iterator c = conns.begin (); c != conns.end (); ++c) + { + char ext[16]; + snprintf (ext, 16, "_%d", (*c)->conf->id); + (*c)->script_init_env (ext); + } } const char *vpn::script_if_init () @@ -106,6 +110,7 @@ return -1; fcntl (ipv4_fd, F_SETFL, O_NONBLOCK); + fcntl (ipv4_fd, F_SETFD, FD_CLOEXEC); #if defined(SOL_IP) && defined(IP_MTU_DISCOVER) // this I really consider a linux bug. I am neither connected @@ -125,7 +130,7 @@ exit (EXIT_FAILURE); } - ipv4_ev_watcher.start (ipv4_fd, EVENT_READ); + ipv4_ev_watcher.start (ipv4_fd, EV_READ); } udpv4_fd = -1; @@ -138,6 +143,7 @@ return -1; fcntl (udpv4_fd, F_SETFL, O_NONBLOCK); + fcntl (udpv4_fd, F_SETFD, FD_CLOEXEC); // standard daemon practise... { @@ -163,7 +169,7 @@ exit (EXIT_FAILURE); } - udpv4_ev_watcher.start (udpv4_fd, EVENT_READ); + udpv4_ev_watcher.start (udpv4_fd, EV_READ); } icmpv4_fd = -1; @@ -177,6 +183,7 @@ return -1; fcntl (icmpv4_fd, F_SETFL, O_NONBLOCK); + fcntl (icmpv4_fd, F_SETFD, FD_CLOEXEC); #ifdef ICMP_FILTER { @@ -195,7 +202,7 @@ // fragment for me sometimes. { int oval = IP_PMTUDISC_DONT; - setsockopt (udpv4_fd, SOL_IP, IP_MTU_DISCOVER, &oval, sizeof oval); + setsockopt (icmpv4_fd, SOL_IP, IP_MTU_DISCOVER, &oval, sizeof oval); } #endif @@ -207,7 +214,7 @@ exit (EXIT_FAILURE); } - icmpv4_ev_watcher.start (icmpv4_fd, EVENT_READ); + icmpv4_ev_watcher.start (icmpv4_fd, EV_READ); } #endif @@ -222,6 +229,7 @@ return -1; fcntl (tcpv4_fd, F_SETFL, O_NONBLOCK); + fcntl (tcpv4_fd, F_SETFD, FD_CLOEXEC); // standard daemon practise... { @@ -243,7 +251,7 @@ exit (EXIT_FAILURE); } - tcpv4_ev_watcher.start (tcpv4_fd, EVENT_READ); + tcpv4_ev_watcher.start (tcpv4_fd, EV_READ); } #endif @@ -257,15 +265,18 @@ if (dnsv4_fd < 0) return -1; -#if defined(SOL_IP) && defined(IP_MTU_DISCOVER) + fcntl (dnsv4_fd, F_SETFL, O_NONBLOCK); + fcntl (dnsv4_fd, F_SETFD, FD_CLOEXEC); + +# 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); + setsockopt (dnsv4_fd, SOL_IP, IP_MTU_DISCOVER, &oval, sizeof oval); } -#endif +# endif // standard daemon practise... { @@ -283,10 +294,16 @@ exit (EXIT_FAILURE); } - dnsv4_ev_watcher.start (dnsv4_fd, EVENT_READ); + dnsv4_ev_watcher.start (dnsv4_fd, EV_READ); } #endif + ///////////////////////////////////////////////////////////////////////////// + + reconnect_all (); + + ///////////////////////////////////////////////////////////////////////////// + tap = new tap_device (); if (!tap) //D this, of course, never catches { @@ -294,6 +311,8 @@ exit (EXIT_FAILURE); } + fcntl (tap->fd, F_SETFD, FD_CLOEXEC); + if (tap->if_up () && !run_script (run_script_cb (this, &vpn::script_if_init), true)) { @@ -308,9 +327,7 @@ exit (EXIT_FAILURE); } - tap_ev_watcher.start (tap->fd, EVENT_READ); - - reconnect_all (); + tap_ev_watcher.start (tap->fd, EV_READ); return 0; } @@ -471,9 +488,9 @@ } void -vpn::ipv4_ev (io_watcher &w, short revents) +vpn::ipv4_ev (ev::io &w, int revents) { - if (revents & EVENT_READ) + if (revents & EV_READ) { vpn_packet *pkt = new vpn_packet; struct sockaddr_in sa; @@ -512,9 +529,9 @@ #if ENABLE_ICMP void -vpn::icmpv4_ev (io_watcher &w, short revents) +vpn::icmpv4_ev (ev::io &w, int revents) { - if (revents & EVENT_READ) + if (revents & EV_READ) { vpn_packet *pkt = new vpn_packet; struct sockaddr_in sa; @@ -560,9 +577,9 @@ #endif void -vpn::udpv4_ev (io_watcher &w, short revents) +vpn::udpv4_ev (ev::io &w, int revents) { - if (revents & EVENT_READ) + if (revents & EV_READ) { vpn_packet *pkt = new vpn_packet; struct sockaddr_in sa; @@ -597,9 +614,9 @@ } void -vpn::tap_ev (io_watcher &w, short revents) +vpn::tap_ev (ev::io &w, int revents) { - if (revents & EVENT_READ) + if (revents & EV_READ) { /* process data */ tap_packet *pkt; @@ -639,7 +656,7 @@ } void -vpn::event_cb (time_watcher &w) +vpn::event_cb (ev::timer &w, int) { if (events) { @@ -740,7 +757,7 @@ void vpn::dump_status () { - slog (L_NOTICE, _("BEGIN status dump (%ld)"), (long)NOW); + slog (L_NOTICE, _("BEGIN status dump (%ld)"), (long)ev_now ()); for (conns_vector::iterator c = conns.begin (); c != conns.end (); ++c) (*c)->dump_status ();