[Openvpn-devel,v2] dco_freebsd: close DCO fds when closing the tun device
Commit Message
From: Antonio Quartulli <antonio@mandelbit.com>
On FreeBSD close_tun_dco() is never called: its only call site lives in
the Linux close_tun(), behind a TARGET_FREEBSD guard that can never be
true there. As a result the DCO control socket and notification pipe
leak every time the tun device is closed (e.g. on restart without
--persist-tun).
Call close_tun_dco() from the FreeBSD close_tun() as well. Since that
function already destroys the interface via "ifconfig destroy" (and
keeps it when persistent_if is set), reduce close_tun_dco() to closing
the fds and drop the now unused remove_interface().
While at it, remove the dead TARGET_FREEBSD guard from the Linux
close_tun().
Change-Id: I10326c787cd8149e7617279e45166073d66b9101
Signed-off-by: Antonio Quartulli <antonio@mandelbit.com>
Acked-by: Razvan Cojocaru <razvanc@mailbox.org>
Gerrit URL: https://gerrit.openvpn.net/c/openvpn/+/1897
---
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/+/1897
This mail reflects revision 2 of this Change.
Acked-by according to Gerrit (reflected above):
Razvan Cojocaru <razvanc@mailbox.org>
@@ -306,26 +306,6 @@
return 0;
}
-static int
-remove_interface(struct tuntap *tt)
-{
- int ret;
- struct ifreq ifr;
-
- CLEAR(ifr);
- snprintf(ifr.ifr_name, IFNAMSIZ, "%s", tt->dco.ifname);
-
- ret = ioctl(tt->dco.fd, SIOCIFDESTROY, &ifr);
- if (ret)
- {
- msg(M_ERR, "Failed to remove interface %s", ifr.ifr_name);
- }
-
- tt->dco.ifname[0] = 0;
-
- return ret;
-}
-
int
open_tun_dco(struct tuntap *tt, openvpn_net_ctx_t *ctx, const char *dev)
{
@@ -348,7 +328,7 @@
void
close_tun_dco(struct tuntap *tt, openvpn_net_ctx_t *ctx)
{
- remove_interface(tt);
+ /* the interface itself is destroyed by close_tun() via ifconfig */
close_fd(&tt->dco);
}
@@ -2240,12 +2240,10 @@
{
ASSERT(tt);
-#if defined(TARGET_LINUX) || defined(TARGET_FREEBSD)
if (tun_dco_enabled(tt))
{
close_tun_dco(tt, ctx);
}
-#endif
close_tun_generic(tt);
free(tt);
}
@@ -2825,6 +2823,11 @@
{
ASSERT(tt);
+ if (tun_dco_enabled(tt))
+ {
+ close_tun_dco(tt, ctx);
+ }
+
if (tt->persistent_if) /* keep pre-existing if around */
{
close_tun_generic(tt);