$route_vpn_gateway enviro. variable and "route-gateway dhcp"

How to customize and extend your OpenVPN installation.

Moderators: TinCanTech, TinCanTech, TinCanTech, TinCanTech, TinCanTech, TinCanTech

Post Reply
beamerblvd
OpenVpn Newbie
Posts: 12
Joined: Thu May 12, 2011 1:57 pm

$route_vpn_gateway enviro. variable and "route-gateway dhcp"

Post by beamerblvd » Thu May 12, 2011 3:24 pm

My OpenVPN server bridges with a DHCP-serving interface and pushes "route-gateway dhcp" to clients so that the gateway and IP address will be configured using DHCP. This works great on Windows, but as everyone knows it's not supported natively on *nix systems.

So, I have an UP script for the clients that calls "ipconfig set tap0 DHCP" to configure the tap interface for DHCP. However, I've started helping out on the Tunnelblick project and I'd like to make a generic do-everything script ... that is, an UP script that recognizes when it needs to use DHCP and uses it, and recognizes when it doesn't need to use DHCP and doesn't use it, without requiring user input.

I took a look at the environmental variables available to UP scripts on the man page and saw this one:

route_vpn_gateway: The default gateway used by --route options, as specified in either the --route-gateway option or the second parameter to --ifconfig when --dev tun is specified. Set prior to --up script execution.

This seemed like a no-brainer to me. I'd test if the $route_vpn_gateway value was "dhcp" to determine if I need to use DHCP. Unfortunately, it didn't work that way. $route_vpn_gateway only has a value when the pushed/configured "route-gateway" value is an IP address. When it's set to "dhcp," $route_vpn_gateway is unset. I thought maybe "foreign_option_{n}" or some other variable might have the information I needed, but a quick printenv reveals that there are NO environmental variables available to the script that indicate DHCP should be in use.

So, my question is, is there any way (I'm not seeing it) to get the actual value of "route-gateway" (whether pushed or in the client config) from within the UP script, even if that value is "dhcp?" If not, should I file a bug that $route_vpn_gateway doesn't correctly indicate DHCP, or request that some other environmental variable (a foreign option or something like $route_gateway_dhcp) be added?

Ideas? Thoughts?

Thanks!

Nick

User avatar
janjust
Forum Team
Posts: 2703
Joined: Fri Aug 20, 2010 2:57 pm
Location: Amsterdam
Contact:

Re: $route_vpn_gateway enviro. variable and "route-gateway d

Post by janjust » Fri May 13, 2011 10:37 am

it sounds like you're using a bridged setup with an external DHCP server ; in that case OpenVPN does not know the gateway, as it is provided by the DHCP server itself. The DHCPREQ & DCHPACK are processed outside of OpenVPN and hence no env var is known. You'd need to extract this information from the DHCP code, not from OpenVPN.

beamerblvd
OpenVpn Newbie
Posts: 12
Joined: Thu May 12, 2011 1:57 pm

Re: $route_vpn_gateway enviro. variable and "route-gateway d

Post by beamerblvd » Fri May 13, 2011 2:40 pm

janjust wrote:it sounds like you're using a bridged setup with an external DHCP server ; in that case OpenVPN does not know the gateway, as it is provided by the DHCP server itself. The DHCPREQ & DCHPACK are processed outside of OpenVPN and hence no env var is known. You'd need to extract this information from the DHCP code, not from OpenVPN.
Yes, I'm using a bridged setup with an external DHCP server. I know that OpenVPN doesn't know the gateway. I'm not expecting $route_vpn_gateway in the up script to contain the gateway (the UP script, after all, is the process configuring the gateway via `ipconfig set tap0 DHCP`). What I expect is for $route_vpn_gateway to be equal to the value of the "route-gateway" setting in OpenVPN. OpenVPN always knows the value of route-gateway. It's either an IP address or (in my case) the literal text value of it is set to "dhcp." You can see that in this OpenVPN-logged output below (before the UP script is called):

Code: Select all

2011-05-01 18:36:11 PUSH: Received control message: 'PUSH_REPLY,dhcp-option DNS 172.16.122.1,route 192.168.122.0 255.255.255.0 172.16.122.1,dhcp-option DOMAIN nickhq.com,route-gateway dhcp,ping 10,ping-restart 60'
As you can see by the presence of "route-gateway dhcp" in the log output, OpenVPN doesn't know the gateway address, but it DOES know that "route-gateway dhcp" was pushed to the client. Additionally, if I specify "route-gateway dhcp" in the client config file, OpenVPN knows that, too. It seems to me that, in this case, $route_vpn_gateway should literally be set to the string "dhcp" (as opposed to being unset, which is currently the case, or set to an IP address, which isn't possible). If nothing else, there should be some other environmental variable (such as a $foreign_option_{n} variable or $route_gateway_is_dhcp="true") that indicates that the "route-gateway dhcp" option was present or pushed.

So what I'm asking is, is there some other way for me to see within the script that "route-gateway dhcp" was present or pushed, or do I need to file a bug?

Thanks

User avatar
janjust
Forum Team
Posts: 2703
Joined: Fri Aug 20, 2010 2:57 pm
Location: Amsterdam
Contact:

Re: $route_vpn_gateway enviro. variable and "route-gateway d

Post by janjust » Fri May 13, 2011 3:11 pm

I'd file it as a feature request - I'm not sure if it's absolutely needed . Isn't the *absence* of the env var enough?

beamerblvd
OpenVpn Newbie
Posts: 12
Joined: Thu May 12, 2011 1:57 pm

Re: $route_vpn_gateway enviro. variable and "route-gateway d

Post by beamerblvd » Fri May 13, 2011 3:21 pm

janjust wrote:I'd file it as a feature request - I'm not sure if it's absolutely needed . Isn't the *absence* of the env var enough?
The absence of the env var very well might be enough, and if someone who knew the code well could confirm to me with 100% certainty that the only time $route_vpn_gateway is blank is when it's DHCP, I would be completely satisfied with that answer. I just don't know is the problem.

User avatar
janjust
Forum Team
Posts: 2703
Joined: Fri Aug 20, 2010 2:57 pm
Location: Amsterdam
Contact:

Re: $route_vpn_gateway enviro. variable and "route-gateway d

Post by janjust » Fri May 13, 2011 3:35 pm

regardless of whether the current code sets it or not, it would need to be marked as a "Feature" , so that the behaviour is documented and remains the same in the future.... I'd file it as a feature request on the Trac pages or the openvpn-devel mailing list.

beamerblvd
OpenVpn Newbie
Posts: 12
Joined: Thu May 12, 2011 1:57 pm

Re: $route_vpn_gateway enviro. variable and "route-gateway d

Post by beamerblvd » Fri May 13, 2011 3:41 pm

janjust wrote:regardless of whether the current code sets it or not, it would need to be marked as a "Feature" , so that the behaviour is documented and remains the same in the future.... I'd file it as a feature request on the Trac pages or the openvpn-devel mailing list.
Thanks. Will do.

Post Reply