recent change to ifconfig breaks OpenVPN?
Dear Jim and other OpenVPN hackers,
there is an OpenVPN regression, apparently affecting 2.1 on FreeBSD-8, and caused by OpenVPN configuring the local address on a P2P interface for the local AND ALSO the remote address.
See http://lists.freebsd.org/pipermail/freebsd-current/2009-July/010032.html and followups for details.
Am 30.07.2009, 08:40 Uhr, schrieb Stefan Bethke <[email protected]...>:
Quoted 5 lines
I'm not sure if that is a more general problem with OpenVPN (at least in
--topology subnet mode), or a specific problem in the FreeBSD-specific
code. I just looked at a Linux box connected to the same OpenVPN server, and their ifconfig invocation looks different from ours, so the FreeBSD-specific code at least plays some role.I'd still like to know whether the change to the routing code is intentional or a regression.
Stefan,
Which version of OpenVPN are you using?
It might seem that this is a FreeBSD regression, as OpenVPN assumes this about --topology subnet, so that the using of the local address as remote is intentional.
(This is from the current OpenVPN 2.1-RC manpage):
subnet -- Use a subnet rather than a point-to-point
topology by
configuring the tun interface with a local IP address and
subnet
mask, similar to the topology used in --dev tap and
ethernet
bridging mode. This mode allocates a single IP address per
con-
necting client and works on Windows as well. Only
available
when server and clients are OpenVPN 2.1 or higher, or
OpenVPN
2.0.x which has been manually patched with the --topology
direc-
tive code. When used on Windows, requires version 8.2 or
higher
of the TAP-Win32 driver. When used on *nix, requires that
the
tun driver supports an ifconfig(8) command which sets a
subnet
instead of a remote endpoint IP address.
I see this in the ChangeLog:
2006.04.05 -- Version 2.1-beta12
...
* "topology subnet" fix for FreeBSD (Benoit Bourdin).
...
And it appears that exactly this patch may be the culprit. This is from the OpenVPN 2.1 source repository:
------------------------------------------------------------------------
r986 | james | 2006-04-05 08:28:19 +0200 (Wed, 05 Apr 2006) | 2 lines Changed paths:
M /branches/BETA21/openvpn/tun.c
"topology subnet" fix for FreeBSD (Benoit Bourdin).
------------------------------------------------------------------------
tun.c +25 -2
@@ -795,19 +795,42 @@ ifconfig_remote_netmask, tun_mtu ); - else - openvpn_snprintf (command_line, sizeof (command_line), + else { +if (tt->topology ==TOP_SUBNET ) +openvpn_snprintf (command_line,sizeof (command_line), +IFCONFIG_PATH " %s %s %s netmask %s mtu %d up" , + actual, + ifconfig_local, + ifconfig_local, + ifconfig_remote_netmask, + tun_mtu + ); +else +openvpn_snprintf (command_line,sizeof (command_line),IFCONFIG_PATH " %s %s netmask %s mtu %d up" , actual, ifconfig_local, ifconfig_remote_netmask, tun_mtu ); + }msg (M_INFO ,"%s" , command_line);system_check (command_line, es,S_FATAL ,"FreeBSD ifconfig failed" ); tt->did_ifconfig = true; +/* Add a network route for the local tun interface */ +if (!tun && tt->topology ==TOP_SUBNET ) + { +struct route r; +CLEAR (r); + r.defined = true; + r.network = tt->local & tt->remote_netmask; + r.netmask = tt->remote_netmask; + r.gateway = tt->local; +add_route (&r, tt,0 , es); + } +#elif defined (WIN32 ) {/*
Signature · 1 line
Matthias Andree
I'm leaving off freebsd-current, since I believe the problem is in OpenVPN's tun.c, as pointed out by Matthias below.
Some background on my issue: FreeBSD 8.0-beta2 has apparently introduced a change where the previously working ifconfig invocation is now failing. I'm leaving out the discussion on what exactly that change is and if this effect is desired or not, but concentrate on what OpenVPN is trying to do. We're strictly talking --topology subnet here. tap's are not affected. I haven't tested any other topology.
As can be seen in the commit below, ifconfig is invoked with both the local and the remote IP address set to the server-assigned local address. If this code could be changed to call ifconfig with the local address and the server's VPN address (I believe generally .1) things should be fine. (Also on earlier versions of FreeBSD.) It might be necessary to install an explicit route for the subnet, since FreeBSD will only install a host route for the remote end of the point-to-point link. Please note that FreeBSD's tun interface is always in point-to-point mode, and cannot be configured as a broadcast interface.
A cursory read of tun.c and tun.h shows that struct tuntap doesn't have the server's VPN address, and it appears the server does not push it. Is this available somewhere, or would it be OK to calculate it? (First address in the cidr block the local address is in modulo the netmask.)
Thanks,
Stefan
Am 30.07.2009 um 10:11 schrieb Matthias Andree:
Quoted 66 lines
And it appears that exactly this patch may be the culprit. This is from the OpenVPN 2.1 source repository:
------------------------------------------------------------------------
r986 | james | 2006-04-05 08:28:19 +0200 (Wed, 05 Apr 2006) | 2 lines Changed paths:
M /branches/BETA21/openvpn/tun.c"topology subnet" fix for FreeBSD (Benoit Bourdin).
------------------------------------------------------------------------
Index:
tun.c
===================================================================tun.c +25
-2@@ -795,19 +795,42 @@ ifconfig_remote_netmask, tun_mtu ); - else - openvpn_snprintf (command_line, sizeof (command_line), + else { +if (tt->topology ==TOP_SUBNET ) +openvpn_snprintf (command_line,sizeof (command_line), + IFCONFIG_PATH " %s %s %s netmask %s mtu %d up", + actual, + ifconfig_local, + ifconfig_local, + ifconfig_remote_netmask, + tun_mtu + ); +else +openvpn_snprintf (command_line,sizeof (command_line),IFCONFIG_PATH " %s %s netmask %s mtu %d up" , actual, ifconfig_local, ifconfig_remote_netmask, tun_mtu ); + }msg (M_INFO ,"%s" , command_line);system_check (command_line, es,S_FATAL ,"FreeBSD ifconfig failed"); tt->did_ifconfig = true; +/* Add a network route for the local tun interface */ +if (!tun && tt->topology ==TOP_SUBNET ) + { +struct route r; +CLEAR (r); + r.defined = true; + r.network = tt->local & tt->remote_netmask; + r.netmask = tt->remote_netmask; + r.gateway = tt->local; +add_route (&r, tt,0 , es); + } +#elif defined (WIN32 ){ /*Signature · 1 line
Matthias Andree
Signature · 1 line
Stefan Bethke <[email protected]...> Fon +49 151 14070811
Am 31.07.2009, 00:36 Uhr, schrieb Bjoern A. Zeeb <[email protected]...>:
Quoted 7 lines
Yeah that is as great as we are or rather were.
So really, fix the openvpn scripts that assign the address to interfaces to do something that would make sense from the ``man ip'' (not the literal command) point of view. Just that it's "working" somewhere or used to work elswhere neither means that it was correct nor made sense at any time before.
It's actually in the C code where it was advertised as FreeBSD fix. OpenVPN runs in 'topology subnet' mode here, which is documented as follows:
Use a subnet rather than a point-to-point topology by configuring the tun interface with a local IP address and subnet mask, similar to the topology used in --dev tap and ethernet bridging mode. This mode allocates a single IP address per con- necting client [... MS-Windows stuff here ...]
When used on *nix, requires that the
tun driver supports an ifconfig(8) command which sets a subnet instead of a remote endpoint IP address.
I wonder if TUNSIFMODE (see tun(4)) is somehow needed and if so, already done, and how the proper ifconfig call would look like in this case. Stefan already uttered some ideas in that direction.
I haven't had much time to investigate yet.
Signature · 1 line
Matthias Andree
Am 30.07.2009 um 10:47 schrieb Stefan Bethke:
Quoted 10 lines
I'm leaving off freebsd-current, since I believe the problem is in OpenVPN's
tun.c, as pointed out by Matthias below.Some background on my issue: FreeBSD 8.0-beta2 has apparently introduced a change where the previously working ifconfig invocation is now failing. I'm leaving out the discussion on what exactly that change is and if this effect is desired or not, but concentrate on what OpenVPN is trying to do. We're strictly talking --topology subnet here. tap's are not affected. I haven't tested any other topology.
Quoted 9 lines
As can be seen in the commit below, ifconfig is invoked with both the local and the remote IP address set to the server-assigned local address. If this code could be changed to call ifconfig with the local address and the server's VPN address (I believe generally .1) things should be fine. (Also on earlier versions of FreeBSD.) It might be necessary to install an explicit route for the subnet, since FreeBSD will only install a host route for the remote end of the point- to-point link. Please note that FreeBSD's tun interface is always in point-to-point mode, and cannot be configured as a broadcast interface.
Luckily, FreeBSD's tun can be switched from point-to-point mode to broadcast. The attached patch does this. I've tested this successfully on FreeBSD 7-stable and 8-beta2, with server and client in --topology subnet and net30 modes.
Stefan
Signature · 2 lines
-- Stefan Bethke <[email protected]...> Fon +49 151 14070811
Am 01.08.2009, 13:37 Uhr, schrieb Stefan Bethke <[email protected]...>:
Quoted 24 lines
Am 30.07.2009 um 10:47 schrieb Stefan Bethke:
Quoted 10 lines
I'm leaving off freebsd-current, since I believe the problem is in OpenVPN's
tun.c, as pointed out by Matthias below.Some background on my issue: FreeBSD 8.0-beta2 has apparently introduced a change where the previously working ifconfig invocation is now failing. I'm leaving out the discussion on what exactly that change is and if this effect is desired or not, but concentrate on what OpenVPN is trying to do. We're strictly talking --topology subnet here. tap's are not affected. I haven't tested any other topology.
Quoted 11 lines
As can be seen in the commit below, ifconfig is invoked with both the local and the remote IP address set to the server-assigned local address. If this code could be changed to call ifconfig with the local address and the server's VPN address (I believe generally .1) things should be fine. (Also on earlier versions of FreeBSD.) It might be necessary to install an explicit route for the subnet, since FreeBSD will only install a host route for the remote end of the point-
to-point link. Please note that FreeBSD's tun interface is always in point-to-point mode, and cannot be configured as a broadcast interface.
Quoted 4 lines
Luckily, FreeBSD's tun can be switched from point-to-point mode to broadcast. The attached patch does this. I've tested this successfully on FreeBSD 7-stable and 8-beta2, with server and client in --topology subnet and net30 modes.
I hope to try this on FreeBSD 6.X tomorrow, as that's also a supported release.
Signature · 1 line
Matthias Andree