Open
Description
Describe the bug
On FreeBSD, if OpenVPN is configured to use a specific tun interface, and the interface exists but does not have the TUNSIFMODE
ioctl set, then OpenVPN fails to properly set up the interface and dies.
root@host# cat /var/log/daemon.log
... output trimmed ...
openvpn[2580]: Failed to create interface tun0 (SIOCSIFNAME): File exists (errno=17)
openvpn[2580]: dco_set_ifmode: failed to set ifmode=00008002: Invalid argument (errno=22)
openvpn[2580]: DCO device tun0 already exists, won't be destroyed at shutdown
openvpn[2580]: do_ifconfig, ipv4=1, ipv6=0
openvpn[2580]: /sbin/ifconfig tun0 10.8.0.1/24 mtu 1500 up
openvpn[2580]: FreeBSD ifconfig failed: external program exited with error status: 1
openvpn[2580]: Exiting due to fatal error
... output trimmed ...
To Reproduce
root@host# cat /usr/local/etc/openvpn/openvpn.conf
... output trimmed ...
dev tun0
topology subnet
server 10.8.0.0 255.255.255.0
;persist-tun
verb 9
... output trimmed ...
root@host# ifconfig tun0 destroy
root@host# ifconfig tun0 create
root@host# ifconfig tun0
tun0: flags=8010<POINTOPOINT,MULTICAST> metric 0 mtu 1500
options=80000<LINKSTATE>
groups: tun
nd6 options=29<PERFORMNUD,IFDISABLED,AUTO_LINKLOCAL>
root@host# service openvpn onestart
Expected behavior
root@host# cat /var/log/daemon.log
... output trimmed ...
Jul 11 18:07:11 pris openvpn[2769]: DCO device tun0 opened
Jul 11 18:07:11 pris openvpn[2769]: do_ifconfig, ipv4=1, ipv6=0
Jul 11 18:07:11 pris openvpn[2769]: /sbin/ifconfig tun0 10.8.0.1/24 mtu 1500 up
... output trimmed ...
root@host# ifconfig tun0
tun0: flags=1008003<UP,BROADCAST,MULTICAST,LOWER_UP> metric 0 mtu 1500
options=80000<LINKSTATE>
inet 10.8.0.1 netmask 0xffffff00 broadcast 10.8.0.255
groups: openvpn
nd6 options=29<PERFORMNUD,IFDISABLED,AUTO_LINKLOCAL>
Version information (please complete the following information):
root@host# openvpn --version
OpenVPN 2.6.14 amd64-portbld-freebsd14.2 [SSL (OpenSSL)] [LZO] [LZ4] [PKCS11] [MH/RECVDA] [AEAD] [DCO]
library versions: OpenSSL 3.0.16 11 Feb 2025, LZO 2.10
DCO version: FreeBSD 14.2-RELEASE-p1 GENERIC
... output trimmed ...