Skip to contentSkip to conversation

Adding routes on Windows using DHCP

Openvpn-devel Jan Just Keijser 5 participants 14 messages Jul 3, 2015 – Jul 9, 2015

lore
Share & tools
lore
#0 lore raw

hi all,

whilst writing the TFTP/WPAD patch I stumbled upon the options to set a default gateway and/or routes using DHCP options. I've patched openvpn to also set DHCP option 3 ("gateway") and indeed, windows picks up the route supplied to it :)

This might be a way to address this topic from the IRC meeting:

Windows 8.1 DNS registration issues

* ipconfig failing to execute during VPN connection

     <https://community.openvpn.net/openvpn/ticket/516>

* Who will fix and how?

It's even possible to run openvpn without admin privileges and set routes this way!
Before you get too excited: it does not seem to be possible to replace an existing default GW this way. the new 0.0.0.0 route has the metric of the tap-win32 adapter , which is better than that of a wifi adapter but worse (30 == higher) than that of a regular LAN Adapter (metric=10).

Before I go any deeper into this: what does the rest think about setting routes on Windows this way? It could be a nice way to circumvent all kinds of "route add" problems.

cheers,

JJK

#1 lore raw
Quoted 23 lines · Jan Just Keijser

hi all,

whilst writing the TFTP/WPAD patch I stumbled upon the options to set a default gateway and/or routes using DHCP options.
I've patched openvpn to also set DHCP option 3 ("gateway") and indeed, windows picks up the route supplied to it :)

This might be a way to address this topic from the IRC meeting:

Windows 8.1 DNS registration issues

* ipconfig failing to execute during VPN connection
<https://community.openvpn.net/openvpn/ticket/516>
* Who will fix and how?

It's even possible to run openvpn without admin privileges and set routes this way!
Before you get too excited: it does not seem to be possible to replace an existing default GW this way. the new 0.0.0.0 route has the metric of the tap-win32 adapter , which is better than that of a wifi adapter but worse (30 == higher) than that of a regular LAN Adapter (metric=10).

Quoted 3 lines

Before I go any deeper into this: what does the rest think about setting routes on Windows this way? It could be a nice way to circumvent all kinds of "route add" problems.

Okay, it's bold of me having opinion on the Windows, who have not used Windows on his personal or work computers the last 15 years.

But I generally think this sounds like a really good idea. I understand doing the routing tricks for --redirect-gateway won't work - and I can personally live with that. I do like that openvpn today then can run without privileges,

A few questions though

* Can you push several routes via DHCP? Or just a single one? If you can push multiple routes, then I'd say we should look into adding a check if --redirect-gateway + non-admin privileged user => provide an solid warning in the logs that redirecting won't work without proper privileges.

* What about IPv6?
Can you push IPv6 routes the same way? Will that also work without privileges?

Signature · 3 lines
kind regards,

David Sommerseth
#2 lore raw

Hi David,

Quoted 30 lines · David Sommerseth
Quoted 14 lines · Jan Just Keijser

hi all,

whilst writing the TFTP/WPAD patch I stumbled upon the options to set a default gateway and/or routes using DHCP options. I've patched openvpn to also set DHCP option 3 ("gateway") and indeed, windows picks up the route supplied to it :)

This might be a way to address this topic from the IRC meeting:

Windows 8.1 DNS registration issues

* ipconfig failing to execute during VPN connection
<https://community.openvpn.net/openvpn/ticket/516>
* Who will fix and how?

Quoted 5 lines

It's even possible to run openvpn without admin privileges and set routes this way!
Before you get too excited: it does not seem to be possible to replace an existing default GW this way. the new 0.0.0.0 route has the metric of the tap-win32 adapter , which is better than that of a wifi adapter but worse (30 == higher) than that of a regular LAN Adapter (metric=10).

Before I go any deeper into this: what does the rest think about setting routes on Windows this way? It could be a nice way to circumvent all kinds of "route add" problems.

Okay, it's bold of me having opinion on the Windows, who have not used Windows on his personal or work computers the last 15 years.

But I generally think this sounds like a really good idea. I understand doing the routing tricks for --redirect-gateway won't work - and I can personally live with that. I do like that openvpn today then can run without privileges,

Quoted 8 lines

A few questions though

* Can you push several routes via DHCP? Or just a single one? If you can push multiple routes, then I'd say we should look into adding a check if --redirect-gateway + non-admin privileged user => provide an solid warning in the logs that redirecting won't work without proper privileges.

yes this is possible; it's possible to push multiple gateways and multiple (classless) routes (dhcp options 121 & 249). If the metric on the tap-win adapter is set manually and is set low enough the redirecting the gateway will also work. However, changing the metric requires evelated access...

Quoted 3 lines

* What about IPv6?
Can you push IPv6 routes the same way? Will that also work without privileges?

How are IPv6 addresses handled by OpenVPN / tap-win32 ? IPv6 comes with DHCPv6 which also includes support for pushing routes&gateways. It needs further investigation, however.

JJK

#13 lore raw
In reply to Jan Just Keijser

Hi,

Quoted 2 lines · Jan Just Keijser

It's even possible to run openvpn without admin privileges and set routes this way!

singular route, unfortunlatey - while there is an option to advertise specific routes ("192.168.0.0/24") in DHCP, as far as I understand, nobody supports this - so all you can do is a default route...

Quoted 8 lines

Before you get too excited: it does not seem to be possible to replace an existing default GW this way. the new 0.0.0.0 route has the metric of the tap-win32 adapter , which is better than that of a wifi adapter but worse (30 == higher) than that of a regular LAN Adapter (metric=10).

Before I go any deeper into this: what does the rest think about setting routes on Windows this way? It could be a nice way to circumvent all kinds of "route add" problems.

Won't do IPv6, won't help us installing the /32 needed for "redirect-gateway", and (if my assumption above is true) won't give us more specific routes.

So: nice finding, but not useful enough...

gert

Signature · 4 lines
USENET is *not* the non-clickable part of WWW!
                                                           //www.muc.de/~gert/
Gert Doering - Munich, Germany                             [email protected]...
fax: +49-89-35655025                        [email protected]...
#3 lore raw
In reply to Jan Just Keijser

Hi JJK,

Quoted 11 lines
Quoted 6 lines

* Can you push several routes via DHCP? Or just a single one? If you can push multiple routes, then I'd say we should look into adding a check if --redirect-gateway + non-admin privileged user => provide an solid warning in the logs that redirecting won't work without proper privileges.

yes this is possible; it's possible to push multiple gateways and multiple (classless) routes (dhcp options 121 & 249).
If the metric on the tap-win adapter is set manually and is set low enough the redirecting the gateway will also work. However, changing the metric requires evelated access...

Sorry for the noise if that has been discussed before: Instead of modifying the metric, how about pushing two /1 routes (0.0.0.0/1 and 128.0.0.0/1)?

András

#12 lore raw
In reply to Jan Just Keijser

Hi,

Quoted 4 lines · Jan Just Keijser
Quoted 2 lines

* What about IPv6?
Can you push IPv6 routes the same way? Will that also work without privileges?

How are IPv6 addresses handled by OpenVPN / tap-win32 ?

Calling "netsh.exe" (both for addresses and routes).

Quoted 3 lines

IPv6 comes with
DHCPv6 which also includes support for pushing routes&gateways. It needs further investigation, however.

DHCPv6 does *not* support routing information. You need RA for that, and implementing a full-featured DHCPv6+RA daemon inside OpenVPN is way more work than just getting the (already existing!) code from Heiko for the interactive service tested and merged...

gert

Signature · 4 lines
USENET is *not* the non-clickable part of WWW!
                                                           //www.muc.de/~gert/
Gert Doering - Munich, Germany                             [email protected]...
fax: +49-89-35655025                        [email protected]...
#4 lore raw
In reply to JÁKÓ András

Hi,

Quoted 9 lines · JÁKÓ András
Quoted 5 lines

yes this is possible; it's possible to push multiple gateways and multiple (classless) routes (dhcp options 121 & 249).
If the metric on the tap-win adapter is set manually and is set low enough the redirecting the gateway will also work. However, changing the metric requires evelated access...

Sorry for the noise if that has been discussed before: Instead of modifying the metric, how about pushing two /1 routes (0.0.0.0/1 and 128.0.0.0/1)?

Would work *if* windows supports the "classless routes" option (which I'm not sure of) - and if it accepts DHCP on tap to provide a host route for the VPN server to the original gateway on the normal LAN interface. Without that host route, routing would loop (we'd send packets *to* the VPN server into the tunnel, encapsulate, send to the VPN server, into the tunnel, encapsulate, ... *boom*)

gert

Signature · 4 lines
USENET is *not* the non-clickable part of WWW!
                                                           //www.muc.de/~gert/
Gert Doering - Munich, Germany                             [email protected]...
fax: +49-89-35655025                        [email protected]...
#5 lore raw

Hi,

Quoted 9 lines · Gert Doering
Quoted 8 lines · JÁKÓ András
Quoted 5 lines

yes this is possible; it's possible to push multiple gateways and multiple (classless) routes (dhcp options 121 & 249).
If the metric on the tap-win adapter is set manually and is set low enough the redirecting the gateway will also work. However, changing the metric requires evelated access...

Sorry for the noise if that has been discussed before: Instead of modifying the metric, how about pushing two /1 routes (0.0.0.0/1 and 128.0.0.0/1)?

Quoted 7 lines

Would work *if* windows supports the "classless routes" option (which I'm not sure of) - and if it accepts DHCP on tap to provide a host route for the VPN server to the original gateway on the normal LAN interface. Without that host route, routing would loop (we'd send packets *to* the VPN server into the tunnel, encapsulate, send to the VPN server, into the tunnel, encapsulate, ... *boom*)

AFAICT windows does support that option (that's what I was referring to with options 121 or 249) . OTOH, I am *not* sure if it allows you to set a 0.0.0.0/1 route using that option, but I guess there's only one way to find out.

As for IPv6: that is going to be a problem indeed, although a draft exists for handing out IPv6 routes over DHCP(v6); not sure how much work that would entail though.
I think Heiko's interactive service is "the way forward" but it does look like the "DHCP route" is too interesting to ignore. I will have more time next week to explore it, so I'll get back to the list then.

JJK

#6 lore raw

Hi,

Quoted 10 lines · Jan Just Keijser
Quoted 9 lines · Gert Doering
Quoted 8 lines · JÁKÓ András
Quoted 5 lines

yes this is possible; it's possible to push multiple gateways and multiple (classless) routes (dhcp options 121 & 249).
If the metric on the tap-win adapter is set manually and is set low enough the redirecting the gateway will also work. However, changing the metric requires evelated access...

Sorry for the noise if that has been discussed before: Instead of modifying the metric, how about pushing two /1 routes (0.0.0.0/1 and 128.0.0.0/1)?

Quoted 8 lines
Quoted 7 lines

Would work *if* windows supports the "classless routes" option (which I'm not sure of) - and if it accepts DHCP on tap to provide a host route for the VPN server to the original gateway on the normal LAN interface. Without that host route, routing would loop (we'd send packets *to* the VPN server into the tunnel, encapsulate, send to the VPN server, into the tunnel, encapsulate, ... *boom*)

AFAICT windows does support that option (that's what I was referring to with options 121 or 249) . OTOH, I am *not* sure if it allows you to set a 0.0.0.0/1 route using that option, but I guess there's only one way to find out.

FWIW: I've patched openvpn to set routes using DHCP on Windows and yes, it works: I can add any route to the system routing tables, including 0.0.0.0/1 and 128.0.0.1/1 ; this could be used as an alternative to requiring elevated privileges.

JJK

#7 lore raw
Quoted 7 lines · Jan Just Keijser

FWIW: I've patched openvpn to set routes using DHCP on Windows and yes, it works: I can add any route to the system routing tables, including 0.0.0.0/1 and 128.0.0.1/1 ; this could be used as an alternative to requiring elevated privileges.

This is excellent news. Is routing the only function that needs admin privileges on windows while starting openvpn?

I have been using a management-interface based client and the openvpn service to support Windows users without needing admin privileges. Given the unreliability of the windows service it would be great if non-admin users can run openvpn.exe.

I am looking forward to testing this. Is there a binary available?

Thanks,

Selva

#9 lore raw
In reply to Jan Just Keijser

Hi,

Quoted 9 lines · Jan Just Keijser
Quoted 4 lines

AFAICT windows does support that option (that's what I was referring to with options 121 or 249) . OTOH, I am *not* sure if it allows you to set a 0.0.0.0/1 route using that option, but I guess there's only one way to find out.

FWIW: I've patched openvpn to set routes using DHCP on Windows and yes, it works: I can add any route to the system routing tables, including 0.0.0.0/1 and 128.0.0.1/1 ; this could be used as an alternative to requiring elevated privileges.

Unless you can also set the host route for the VPN gateway (point to a gateway on a *different* interface), this is not really helping... just adding 2x /1 will just cause recursion as packets to the VPN server will be happily routed into the tap interface again.

gert

Signature · 4 lines
USENET is *not* the non-clickable part of WWW!
                                                           //www.muc.de/~gert/
Gert Doering - Munich, Germany                             [email protected]...
fax: +49-89-35655025                        [email protected]...
#8 lore raw
In reply to Selva Nair

hi,

Quoted 9 lines · Selva Nair
Quoted 4 lines · Jan Just Keijser

FWIW: I've patched openvpn to set routes using DHCP on Windows and yes, it works: I can add any route to the system routing tables, including 0.0.0.0/1 and 128.0.0.1/1 ; this could be used as an alternative to requiring elevated privileges.

This is excellent news. Is routing the only function that needs admin privileges on windows while starting openvpn?

It's less excellent than it might sound - anything IPv4-only is not good enough in 2015 (and I have my doubts that it will be able to do the redirect-gateway work needed in a large number of VPn cases - but might be pleasantly surprised).

gert

Signature · 4 lines
USENET is *not* the non-clickable part of WWW!
                                                           //www.muc.de/~gert/
Gert Doering - Munich, Germany                             [email protected]...
fax: +49-89-35655025                        [email protected]...
#10 lore raw
In reply to Gert Doering

Yo,

Quoted 11 lines · Gert Doering

Hi,

Quoted 4 lines · Jan Just Keijser
Quoted 2 lines

AFAICT windows does support that option (that's what I was referring to with options 121 or 249) . OTOH, I am *not* sure if it allows you to set a 0.0.0.0/1 route using that option, but I guess there's only one way to find out.

FWIW: I've patched openvpn to set routes using DHCP on Windows and yes, it works: I can add any route to the system routing tables, including 0.0.0.0/1 and 128.0.0.1/1 ; this could be used as an alternative to requiring elevated privileges.

Unless you can also set the host route for the VPN gateway (point to a gateway on a *different* interface), this is not really helping... just adding 2x /1 will just cause recursion as packets to the VPN server will be happily routed into the tap interface again.

as usual, Gert is right :(
I've added an explicit /32 route to the OpenVPN server via DHCP , which Windows picks up, including the right LAN GW address *BUT* it associates it with the VPN interface, not the regular LAN interface. Thus you end up with a "bite your own tail" route and the VPN collapses.

So I guess the only thing this DHCP-trick is useful for is if you're not redirecting all traffic - in that case you can run openvpn in non-privileged mode and set a bunch of routes to go over the VPN, just not the default route.

@Selva: my current patch contains hardcoded addresses and is just a proof-of-concept. I cannot share the executable with you.

JJK

#11 lore raw
Quoted 6 lines · Jan Just Keijser

as usual, Gert is right :(
I've added an explicit /32 route to the OpenVPN server via DHCP , which Windows picks up, including the right LAN GW address *BUT* it associates it with the VPN interface, not the regular LAN interface. Thus you end up with a "bite your own tail" route and the VPN collapses.

Quoted 8 lines

So I guess the only thing this DHCP-trick is useful for is if you're not redirecting all traffic - in that case you can run openvpn in non-privileged mode and set a bunch of routes to go over the VPN, just not the default route.

@Selva: my current patch contains hardcoded addresses and is just a proof-of-concept. I cannot share the executable with you.

No problem, the fact that the route would apply only to the particular interface is a major disappointment. Kind of obvious once Gert pointed it out, though :)

I suppose, going forward, replacing the service by nssm is the best option for those of us using the mgmt-interface to control the process as non-admin user.

Thanks,

Selva