- t_client.sh(.in): add "DragonFly" to the OS versions "like FreeBSD"
- tun.c open_tun()
- add DragonFly specific handling of dynamic tun/tap devices
(open /dev/{tun,tap}, assigns first-free node, fdevname(fd) returns
true device name)
--dev tunN (and tapN) works "the old way", by opening /dev/tunN - but
only for devices pre-created with "ifconfig tun3 create"
- set ioctl(TUNSIFMODE, IFF_BROADCAST=1) for "topology subnet" tun ifs
-> this is sufficient to make FreeBSD "ifconfig ipv4" code work
(DragonFly was broken by FreeBSD commit 94db3261659)
- tun.c do_ifconfig_ipv4()
- use TARGET_FREEBSD code path for DragonFly too, just amend the
error message ("FreeBSD/DragonFly ifconfig failed")
- tun.c do_ifconfig_ipv6()
- needs "add_route_connected_v6_net()" for tun and tap(!) devices,
otherwise the on-link /64 is not routed to the tun device
- tun.c undo_ifconfig_ipv4(), undo_ifconfig_ipv6()
- share FreeBSD code to undo IPv4/IPv6 ifconfig on precreated interfaces
- add delete_route_connected_v6_net() call for DragonFly only
(this is not removing fe80:: addresses from the tun if, which upsets
t_client test, but for normal usage is considered "reasonably fine")
- lladdr.c: add TARGET_DRAGONFLY to TARGET_FREEBSD format
v1 -> v2:
- fix clang-format issues
- introduce TUNSIFMODE setting
- revert do_ifconfig_ipv4 change from v1 (use FREEBSD code path)
- use M_ERR instead of M_FATAL
- gate --dev tun/tap check on --dev-node being unset
v2 -> v3:
- clang-format in lladdr.c and t_client.sh.in
Change-Id: I5ab959e7101cf801ac93e5185855e75db0fb6225
Signed-off-by: Gert Doering <[email protected]>
Acked-by: Razvan Cojocaru <[email protected]>
Gerrit URL: https://gerrit.openvpn.net/c/openvpn/+/2170
---
This change was reviewed on Gerrit and approved by at least one
developer. I request to merge it to master.
Gerrit URL: https://gerrit.openvpn.net/c/openvpn/+/2170
This mail reflects revision 3 of this Change.
Acked-by according to Gerrit (reflected above):
Razvan Cojocaru <[email protected]>
diff --git a/src/openvpn/lladdr.c b/src/openvpn/lladdr.c
index 8bd572a..43480f1 100644
--- a/src/openvpn/lladdr.c
+++ b/src/openvpn/lladdr.c
@@ -24,7 +24,7 @@
}
#else /* TARGET_LINUX */
-#if defined(TARGET_OPENBSD) || defined(TARGET_FREEBSD) ||
defined(TARGET_DARWIN)
+#if defined(TARGET_OPENBSD) || defined(TARGET_FREEBSD) ||
defined(TARGET_DARWIN) || defined(TARGET_DRAGONFLY)
#define IFCONFIG_LLADDR_FMT "%s %s lladdr %s"
#elif defined(TARGET_NETBSD)
#define IFCONFIG_LLADDR_FMT "%s %s link %s active"
diff --git a/src/openvpn/tun.c b/src/openvpn/tun.c
index 70fdd7e..c1c5548 100644
--- a/src/openvpn/tun.c
+++ b/src/openvpn/tun.c
@@ -979,7 +979,7 @@
#endif /* ifdef _WIN32 */
}
-#if defined(_WIN32)
+#if defined(_WIN32) || defined(TARGET_DRAGONFLY)
/* some of the platforms will auto-add a "network route" pointing
* to the interface on "ifconfig tunX 2001:db8::1/64", others need
@@ -1160,6 +1160,10 @@
openvpn_execve_check(&argv, es, S_FATAL, "FreeBSD BSD 'ifconfig inet6
-ifdisabled' failed");
#endif
+#ifdef TARGET_DRAGONFLY
+ add_route_connected_v6_net(tt, es);
+#endif
+
#elif defined(TARGET_AIX)
argv_printf(&argv, "%s %s inet6 %s/%d mtu %d up", IFCONFIG_PATH, ifname,
ifconfig_ipv6_local,
tt->netbits_ipv6, tun_mtu);
@@ -1490,7 +1494,7 @@
}
argv_msg(M_INFO, &argv);
- openvpn_execve_check(&argv, es, S_FATAL, "FreeBSD ifconfig failed");
+ openvpn_execve_check(&argv, es, S_FATAL, "FreeBSD/DragonFly ifconfig
failed");
#elif defined(TARGET_AIX)
{
@@ -1623,14 +1627,14 @@
msg(M_WARN, "Linux can't del IP from iface %s", tt->actual_name);
}
}
-#elif defined(TARGET_FREEBSD)
+#elif defined(TARGET_FREEBSD) || defined(TARGET_DRAGONFLY)
struct gc_arena gc = gc_new();
const char *ifconfig_local = print_in_addr_t(tt->local, 0, &gc);
struct argv argv = argv_new();
argv_printf(&argv, "%s %s %s -alias", IFCONFIG_PATH, tt->actual_name,
ifconfig_local);
argv_msg(M_INFO, &argv);
- openvpn_execve_check(&argv, NULL, 0, "FreeBSD ip addr del failed");
+ openvpn_execve_check(&argv, NULL, 0, "FreeBSD/DragonFly ip addr del
failed");
argv_free(&argv);
gc_free(&gc);
@@ -1646,7 +1650,12 @@
{
msg(M_WARN, "Linux can't del IPv6 from iface %s", tt->actual_name);
}
-#elif defined(TARGET_FREEBSD)
+#elif defined(TARGET_FREEBSD) || defined(TARGET_DRAGONFLY)
+
+#ifdef TARGET_DRAGONFLY
+ delete_route_connected_v6_net(tt);
+#endif
+
struct gc_arena gc = gc_new();
const char *ifconfig_ipv6_local = print_in6_addr(tt->local_ipv6, 0, &gc);
struct argv argv = argv_new();
@@ -1655,7 +1664,7 @@
ifconfig_ipv6_local, tt->netbits_ipv6);
argv_msg(M_INFO, &argv);
- openvpn_execve_check(&argv, NULL, 0, "FreeBSD ip -6 addr del failed");
+ openvpn_execve_check(&argv, NULL, 0, "FreeBSD/DragonFly ip -6 addr del
failed");
argv_free(&argv);
gc_free(&gc);
@@ -2897,20 +2906,70 @@
#elif defined(TARGET_DRAGONFLY)
+/* DragonFly tun/tap devices are similar to NetBSD
+ * - for a dynamic tun/tap, open /dev/tun or /dev/tap, get assigned
+ * the first free device, ask with (f)devname(3) what you got, and
+ * the interface will auto-destruct on close
+ * - for a pre-created tun/tap, open "/dev/tun3"
+ * - using "--dev tun3" and have it dynamically created needs a call
+ * to "ifconfig tun3 create" which we don't currently do
+ */
+
void
open_tun(const char *dev, const char *dev_type, const char *dev_node, struct
tuntap *tt,
openvpn_net_ctx_t *ctx)
{
- open_tun_generic(dev, dev_type, dev_node, tt);
-
- if (tt->fd >= 0)
+ if (!dev_node && (strcmp(dev, "tap") == 0 || strcmp(dev, "tun") == 0))
{
- int i = 0;
+ char tunname[256];
+ snprintf(tunname, sizeof(tunname), "/dev/%s", dev);
- /* Disable extended modes */
+ if ((tt->fd = open(tunname, O_RDWR)) < 0)
+ {
+ msg(M_ERR, "Cannot allocate DragonFly TUN/TAP %s dynamically",
tunname);
+ }
+
+ char *devname = fdevname(tt->fd);
+ if (devname == NULL)
+ {
+ msg(M_ERR, "Cannot query DragonFly TUN/TAP device name");
+ }
+ set_nonblock(tt->fd);
+ set_cloexec(tt->fd); /* don't pass fd to scripts */
+ msg(M_INFO, "TUN/TAP device %s opened", devname);
+
+ tt->actual_name = string_alloc(devname, NULL);
+ }
+ else
+ {
+ open_tun_generic(dev, dev_type, dev_node, tt);
+ }
+
+ if (tt->fd >= 0 && tt->type == DEV_TYPE_TUN)
+ {
+ /* see "Interface Flags" in ifnet(9) */
+ int i = IFF_POINTOPOINT | IFF_MULTICAST;
+ if (tt->topology == TOP_SUBNET)
+ {
+ i = IFF_BROADCAST | IFF_MULTICAST;
+ }
+
+ if (ioctl(tt->fd, TUNSIFMODE, &i) < 0)
+ {
+ msg(M_WARN | M_ERRNO, "ioctl(TUNSIFMODE)");
+ }
+
+ /* Disable "link layer" mode (would prepend route-nexthop address
+ * on read, but is incompatible with TUNSIFHEAD multi-af mode) */
+ i = 0;
ioctl(tt->fd, TUNSLMODE, &i);
+
+ /* multi_af mode for v4+v6, see "tun(4)" */
i = 1;
- ioctl(tt->fd, TUNSIFHEAD, &i);
+ if (ioctl(tt->fd, TUNSIFHEAD, &i) < 0)
+ {
+ msg(M_WARN | M_ERRNO, "ioctl(TUNSIFHEAD)");
+ }
}
}
diff --git a/tests/t_client.sh.in b/tests/t_client.sh.in
index 5e924bb..d81cef0 100755
--- a/tests/t_client.sh.in
+++ b/tests/t_client.sh.in
@@ -212,8 +212,8 @@
LANG=C @NETSTAT@ -rn -4 -6
fi
;;
- FreeBSD | NetBSD | Darwin)
- echo "-- FreeBSD/NetBSD/Darwin [MacOS X] --"
+ FreeBSD | DragonFly | NetBSD | Darwin)
+ echo "-- FreeBSD/DragonFly/NetBSD/Darwin [MacOS X] --"
@IFCONFIG@ -a | egrep "(flags=|inet)"
@NETSTAT@ -rn | awk '$3 !~ /^UHL/ { print $1,$2,$3,$NF }'
;;
_______________________________________________
Openvpn-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/openvpn-devel