From ada9769e32da0152c61ef76fefe403444d61af43 Mon Sep 17 00:00:00 2001 From: Gert Doering Date: Sun, 8 Aug 2010 12:34:00 +0200 Subject: implement IPv6 ifconfig + route setup/deletion on OpenBSD destroy tunX interface on tun_close() tested on OpenBSD 4.7 Signed-off-by: Gert Doering --- tun.c | 36 +++++++++++++++++++++++++++++++++--- 1 file changed, 33 insertions(+), 3 deletions(-) (limited to 'tun.c') diff --git a/tun.c b/tun.c index 3c8fb22..5f636e2 100644 --- a/tun.c +++ b/tun.c @@ -573,7 +573,7 @@ init_tun_post (struct tuntap *tt, } #if defined(TARGET_WIN32) || \ - defined(TARGET_DARWIN) || defined(TARGET_NETBSD) + defined(TARGET_DARWIN) || defined(TARGET_NETBSD) || defined(TARGET_OPENBSD) /* some of the platforms will auto-add a "network route" pointing * to the interface on "ifconfig tunX 2001:db8::1/64", others need @@ -880,7 +880,18 @@ do_ifconfig (struct tuntap *tt, openvpn_execve_check (&argv, es, S_FATAL, "OpenBSD ifconfig failed"); if ( do_ipv6 ) { - msg( M_FATAL, "can't configure IPv6 on OpenBSD yet - unimplemented" ); + argv_printf (&argv, + "%s %s inet6 %s/%d", + IFCONFIG_PATH, + actual, + ifconfig_ipv6_local, + tt->netbits_ipv6 + ); + argv_msg (M_INFO, &argv); + openvpn_execve_check (&argv, es, S_FATAL, "OpenBSD ifconfig inet6 failed"); + + /* and, hooray, we explicitely need to add a route... */ + add_route_connected_v6_net(tt, es); } tt->did_ifconfig = true; @@ -941,7 +952,7 @@ do_ifconfig (struct tuntap *tt, tt->netbits_ipv6 ); argv_msg (M_INFO, &argv); - openvpn_execve_check (&argv, es, S_FATAL, "NetBSD ifconfig failed"); + openvpn_execve_check (&argv, es, S_FATAL, "NetBSD ifconfig inet6 failed"); /* and, hooray, we explicitely need to add a route... */ add_route_connected_v6_net(tt, es); @@ -1910,12 +1921,31 @@ open_tun (const char *dev, const char *dev_type, const char *dev_node, struct tu } } +/* the current way OpenVPN handles tun devices on OpenBSD leads to + * lingering tunX interfaces after close -> for a full cleanup, they + * need to be explicitely destroyed + */ + void close_tun (struct tuntap* tt) { if (tt) { + struct gc_arena gc = gc_new (); + struct argv argv; + + /* setup command, close tun dev (clears tt->actual_name!), run command + */ + + argv_init (&argv); + argv_printf (&argv, "%s %s destroy", + IFCONFIG_PATH, tt->actual_name); + close_tun_generic (tt); + + argv_msg (M_INFO, &argv); + openvpn_execve_check (&argv, NULL, 0, "OpenBSD 'destroy tun interface' failed (non-critical)"); + free (tt); } } -- cgit