Attention is currently required from: Arne Schwabe.
Hello Arne Schwabe,
I'd like you to do a code review.
Please visit
https://gerrit.openvpn.net/c/openvpn/+/2170?usp=email
to review the following change.
Change subject: DragonFly: bring things back into a working state
......................................................................
DragonFly: bring things back into a working state
- 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"
- tun.c do_ifconfig_ipv4()
- bring back "old FreeBSD" IPv4 ifconfig handling (all tun interfaces
are "p2p", TOPOLOGY_SUBNET is simulated with an extra network route)
this part is based on "patch-src_openvpn_tun.c" to OpenVPN 2.6.14
in DragonFly "dports"
(TODO: see if TUNSIFMODE -> IFF_BROADCAST works here?)
- 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
- lladdr.c: add TARGET_DRAGONFLY to TARGET_FREEBSD format
Change-Id: I5ab959e7101cf801ac93e5185855e75db0fb6225
Signed-off-by: Gert Doering <[email protected]>
---
M src/openvpn/lladdr.c
M src/openvpn/tun.c
M tests/t_client.sh.in
3 files changed, 82 insertions(+), 6 deletions(-)
git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/70/2170/1
diff --git a/src/openvpn/lladdr.c b/src/openvpn/lladdr.c
index 8bd572a..c70e282 100644
--- a/src/openvpn/lladdr.c
+++ b/src/openvpn/lladdr.c
@@ -24,7 +24,8 @@
}
#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 bcea331..605a9fe 100644
--- a/src/openvpn/tun.c
+++ b/src/openvpn/tun.c
@@ -965,7 +965,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
@@ -1147,6 +1147,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);
@@ -1461,7 +1465,7 @@
add_route(&r, tt, 0, NULL, es, NULL);
}
-#elif defined(TARGET_FREEBSD) || defined(TARGET_DRAGONFLY)
+#elif defined(TARGET_FREEBSD)
/* example: ifconfig tun2 10.2.0.2 10.2.0.1 mtu 1450 netmask
255.255.255.255 up */
if (tun_p2p) /* point-to-point tun */
@@ -1479,6 +1483,44 @@
argv_msg(M_INFO, &argv);
openvpn_execve_check(&argv, es, S_FATAL, "FreeBSD ifconfig failed");
+#elif defined(TARGET_DRAGONFLY)
+ in_addr_t remote_end = INADDR_ANY; /* for "virtual" subnet topology */
+
+ /* example: ifconfig tun2 10.2.0.2 10.2.0.1 mtu 1450 netmask
255.255.255.255 up */
+ if (tun_p2p) /* point-to-point tun */
+ {
+ argv_printf(&argv, "%s %s %s %s mtu %d netmask 255.255.255.255 up",
+ IFCONFIG_PATH, ifname, ifconfig_local,
+ ifconfig_remote_netmask, tun_mtu);
+ }
+ else if (tt->type == DEV_TYPE_TUN && tt->topology == TOP_SUBNET)
+ {
+ remote_end = create_arbitrary_remote(tt);
+ argv_printf(&argv, "%s %s %s %s mtu %d netmask %s up", IFCONFIG_PATH,
+ ifname, ifconfig_local, print_in_addr_t(remote_end, 0,
&gc),
+ tun_mtu, ifconfig_remote_netmask);
+ }
+ else
+ {
+ argv_printf(&argv, "%s %s %s netmask %s mtu %d",
+ IFCONFIG_PATH, ifname, ifconfig_local,
+ ifconfig_remote_netmask, tun_mtu);
+ }
+ argv_msg(M_INFO, &argv);
+ openvpn_execve_check(&argv, es, S_FATAL, "DragonFly ifconfig failed");
+
+ /* Add a network route for the local tun interface */
+ if (tt->type == DEV_TYPE_TUN && tt->topology == TOP_SUBNET)
+ {
+ struct route_ipv4 r;
+ CLEAR(r);
+ r.flags = RT_DEFINED;
+ r.network = tt->local & tt->remote_netmask;
+ r.netmask = tt->remote_netmask;
+ r.gateway = remote_end;
+ add_route(&r, tt, 0, NULL, es, NULL);
+ }
+
#elif defined(TARGET_AIX)
{
/* AIX ifconfig will complain if it can't find ODM path in env */
@@ -2853,11 +2895,44 @@
#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 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 (strcmp(dev, "tap") == 0 || strcmp(dev, "tun") == 0)
+ {
+ char tunname[256];
+ snprintf(tunname, sizeof(tunname), "/dev/%s", dev);
+
+ if ((tt->fd = open(tunname, O_RDWR)) < 0)
+ {
+ msg(M_FATAL, "Cannot allocate DragonFly TUN/TAP %s dynamically",
tunname);
+ }
+
+ char *devname = fdevname(tt->fd);
+ if (devname == NULL)
+ {
+ msg(M_FATAL, "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)
{
diff --git a/tests/t_client.sh.in b/tests/t_client.sh.in
index 5e924bb..7488d4b 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 }'
;;
--
To view, visit https://gerrit.openvpn.net/c/openvpn/+/2170?usp=email
To unsubscribe, or for help writing mail filters, visit
https://gerrit.openvpn.net/settings?usp=email
Gerrit-MessageType: newchange
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I5ab959e7101cf801ac93e5185855e75db0fb6225
Gerrit-Change-Number: 2170
Gerrit-PatchSet: 1
Gerrit-Owner: Gert Doering <[email protected]>
Gerrit-Reviewer: Arne Schwabe <[email protected]>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: Arne Schwabe <[email protected]>
_______________________________________________
Openvpn-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/openvpn-devel