openvpn ipv6 pool env variables
PATCH 1/1 openvpn ipv6 pool env variables
Hello,
To make it short: yes, the ipv6 pool environment variables are useful, for user-defined scripts to be run at connection for instance to propagate routes, do accounting, etc. The patch below adds them.
Thanks,
Samuel
Add IPv6 pool environment variables
Add ifconfig_ipv6_pool_local_ip, ifconfig_ipv6_pool_remote_ip and ifconfig_ipv6_pool_netbits environment variables, similar to ifconfig_pool_local_ip, ifconfig_pool_remote_ip, and ifconfig_pool_netmask.
doc/openvpn.8 +54 -0
@@ -5755,6 +5755,60 @@ and scripts. .\"********************************************************* .TP +.B ifconfig_ipv6_pool_local_ip +The local +virtual IPv6 address for the TUN/TAP tunnel taken from an +.B \-\-ifconfig-ipv6-push +directive if specified, or otherwise from +the ifconfig pool (controlled by the +.B \-\-ifconfig-ipv6-pool +config file directive). +Only set for +.B \-\-dev tun +tunnels. +This option is set on the server prior to execution +of the +.B \-\-client-connect +and +.B \-\-client-disconnect +scripts. +.\"********************************************************* +.TP +.B ifconfig_ipv6_pool_netbits +The +size of the virtual IPv6 netmask for the TUN/TAP tunnel taken from an +.B \-\-ifconfig-ipv6-push +directive if specified, or otherwise from +the ifconfig pool (controlled by the +.B \-\-ifconfig-ipv6-pool +config file directive). +Only set for +.B \-\-dev tap +tunnels. +This option is set on the server prior to execution +of the +.B \-\-client-connect +and +.B \-\-client-disconnect +scripts. +.\"********************************************************* +.TP +.B ifconfig_ipv6_pool_remote_ip +The remote +virtual IPv6 address for the TUN/TAP tunnel taken from an +.B \-\-ifconfig-ipv6-push +directive if specified, or otherwise from +the ifconfig pool (controlled by the +.B \-\-ifconfig-ipv6-pool +config file directive). +This option is set on the server prior to execution +of the +.B \-\-client-connect +and +.B \-\-client-disconnect +scripts. +.\"********************************************************* +.TP .B link_mtu The maximum packet size (not including the IP header) of tunnel data in UDP tunnel transport mode.
src/openvpn/manage.c +2 -0
@@ -2283,6 +2283,8 @@ env_filter_match (const char *env_str, const int env_filter_level)"dev=" ,"ifconfig_pool_remote_ip=" ,"ifconfig_pool_netmask=" , +"ifconfig_ipv6_pool_remote_ip=" , +"ifconfig_ipv6_pool_netbits=" ,"time_duration=" ,"bytes_sent=" ,"bytes_received="
src/openvpn/multi.c +29 -4
@@ -1426,10 +1426,35 @@ multi_set_virtual_addr_env (struct multi_context *m, struct multi_instance *mi) } } -/* TODO: I'm not exactly sure what these environment variables are -* used for, but if we have them for IPv4, we should also have -* them for IPv6, no? -*/ +setenv_del (mi->context.c2.es,"ifconfig_ipv6_pool_local_ip" ); +setenv_del (mi->context.c2.es,"ifconfig_ipv6_pool_remote_ip" ); +setenv_del (mi->context.c2.es,"ifconfig_ipv6_pool_netbits" ); + +if (mi->context.c2.push_ifconfig_ipv6_defined) + { +const int tunnel_type =TUNNEL_TYPE (mi->context.c1.tuntap); +const int tunnel_topology =TUNNEL_TOPOLOGY (mi->context.c1.tuntap); + +setenv_in6_addr_t (mi->context.c2.es, +"ifconfig_ipv6_pool_remote_ip" , + &mi->context.c2.push_ifconfig_ipv6_local, +SA_SET_IF_NONZERO ); + +if (tunnel_type ==DEV_TYPE_TAP || (tunnel_type ==DEV_TYPE_TUN && tunnel_topology ==TOP_SUBNET )) + { +setenv_int (mi->context.c2.es, +"ifconfig_ipv6_pool_netbits" , + mi->context.c2.push_ifconfig_ipv6_netbits); + } +else if (tunnel_type ==DEV_TYPE_TUN ) + { +setenv_in6_addr_t (mi->context.c2.es, +"ifconfig_ipv6_pool_local_ip" , + &mi->context.c2.push_ifconfig_ipv6_remote, +SA_SET_IF_NONZERO ); + } + } + }/*
src/openvpn/socket.c +17 -1
@@ -2381,7 +2381,10 @@ setenv_sockaddr (struct env_set *es, const char *name_prefix, const struct openv }break ;case AF_INET6 : -openvpn_snprintf (name_buf,sizeof (name_buf),"%s_ip6" , name_prefix); +if (flags &SA_IP_PORT ) +openvpn_snprintf (name_buf,sizeof (name_buf),"%s_ip6" , name_prefix); +else +openvpn_snprintf (name_buf,sizeof (name_buf),"%s" , name_prefix);getnameinfo (&addr->addr.sa,sizeof (struct sockaddr_in6 ), buf,sizeof (buf),NULL ,0 ,NI_NUMERICHOST );setenv_str (es, name_buf, buf);
@@ -2409,6 +2412,19 @@ setenv_in_addr_t (struct env_set *es, const char *name_prefix, in_addr_t addr, c }void +setenv_in6_addr_t (struct env_set *es,const char *name_prefix,struct in6_addr *addr,const bool flags) +{ +if (memcmp (addr, &in6addr_any,sizeof (*addr)) !=0 || !(flags &SA_SET_IF_NONZERO )) + { +struct openvpn_sockaddr si; +CLEAR (si); + si.addr.in6.sin6_family =AF_INET6 ; + si.addr.in6.sin6_addr = *addr; +setenv_sockaddr (es, name_prefix, &si, flags); + } +} + +void setenv_link_socket_actual (struct env_set *es, const char *name_prefix, const struct link_socket_actual *act,
src/openvpn/socket.h +5 -0
@@ -383,6 +383,11 @@ void setenv_in_addr_t (struct env_set *es,in_addr_t addr, const unsigned int flags); +void setenv_in6_addr_t (struct env_set *es, +const char *name_prefix, +struct in6_addr *addr, +const bool flags); + void setenv_link_socket_actual (struct env_set *es, const char *name_prefix, const struct link_socket_actual *act,
Hi,
Quoted 5 lines · Samuel Thibault
Hello,
To make it short: yes, the ipv6 pool environment variables are useful, for user-defined scripts to be run at connection for instance to propagate routes, do accounting, etc. The patch below adds them.
You keep claiming that "yes it's useful". The lack of feedback on the list is partly due to the "To make it short" part of your mail...
I'm a bit reluctant to add more code until I can see a clear use case which can't be answered by the plethora of existing environment variables.
Specifically, "ifconfig_ipv6_local" and "ifconfig_ipv6_netbits" already exist, and the pool will never produce any other netbit length, nor will the server ever reconfigure it's ipv6_local address in response to whatever is pushed to clients. So the only thing that I couldn't see right away in the environment is "what IPv6 address did the remote receive?" and that one *is* available as parameter to the "learn-address" script already today...
(It brings up an interesting question, though. Should we issue a warning if an "ifconfig-ipv6-push" is used that uses a different network or netbits length than the ipv6 transfer net configured on the server? What do we expect to happen if this is configured?)
Looking at the code:
src/openvpn/multi.c multi_set_virtual_addr_env (struct multi_context *m, struct multi_instance *mi) · line 1455
Quoted 13 lines
src/openvpn/multi.c +13
-0+if (tunnel_type ==DEV_TYPE_TAP || (tunnel_type ==DEV_TYPE_TUN && tunnel_topology ==TOP_SUBNET )) + { +setenv_int (mi->context.c2.es, +"ifconfig_ipv6_pool_netbits" , + mi->context.c2.push_ifconfig_ipv6_netbits); + } +else if (tunnel_type ==DEV_TYPE_TUN ) + { +setenv_in6_addr_t (mi->context.c2.es, +"ifconfig_ipv6_pool_local_ip" , + &mi->context.c2.push_ifconfig_ipv6_remote, +SA_SET_IF_NONZERO ); + }
This whole bit is overly complicated. Unlike IPv4, there is no "this could be a remote or a netmask" distinction, and both netbits and context.c2.push_ifconfig_ipv6_remote are always defined, no matter what sort of tunnel type or topology. So if you wanted to set these variables at all, you could do unconditionally - but then, I can't see any added value to "ifconfig_ipv6_netbits" and "ifconfig_ipv6_local", as said before...
Blindly copying the way something is done for IPv4 doesn't make it "right" for IPv6.
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]...Quoted 6 lines · Gert Doering, le Sat 25 May 2013 13:58:19 +0200, a écrit :
Quoted 3 lines
To make it short: yes, the ipv6 pool environment variables are useful, for user-defined scripts to be run at connection for instance to propagate routes, do accounting, etc. The patch below adds them.
You keep claiming that "yes it's useful". The lack of feedback on the list is partly due to the "To make it short" part of your mail...
Ok. I was simply wondering whether it had perhaps got somehow dropped without reason.
As I mentioned too briefly, the reason we need it is the same as for the IPv4 case: to announce the route to our bird daemon on connection, and drop it on disconnection.
Quoted 1 line
Specifically, "
ifconfig_ipv6_local" and "ifconfig_ipv6_netbits" already exist,
Ah, ifconfig_ipv6_netbits didn't when I worked on this patch, I hadn't noticed that had changed. These can indeed go away.
Quoted 4 lines
So the only thing that I couldn't see right away
in the environment is "what IPv6 address did the remote receive?" and that one *is* available as parameter to the "learn-address" script already today...
But we need it from the disconnect script too, to remove the route announcement. It is available for IPv4, I don't see why things should be different between IPv6 and IPv4 here. It would make our script way more obscure for sure (having to record the route somewhere, re-read on disconnect).
Quoted 2 lines
This whole bit is overly complicated. Unlike IPv4, there is no "this could be a remote or a netmask" distinction,
Right, here is a simpler patch.
Samuel
Add IPv6 pool environment variable
Add the ifconfig_ipv6_pool_remote_ip environment variable, similar to ifconfig_pool_remote_ip.
doc/openvpn.8 +16 -0
@@ -5776,6 +5776,22 @@ and scripts. .\"********************************************************* .TP +.B ifconfig_ipv6_pool_remote_ip +The remote +virtual IPv6 address for the TUN/TAP tunnel taken from an +.B \-\-ifconfig-ipv6-push +directive if specified, or otherwise from +the ifconfig pool (controlled by the +.B \-\-ifconfig-ipv6-pool +config file directive). +This option is set on the server prior to execution +of the +.B \-\-client-connect +and +.B \-\-client-disconnect +scripts. +.\"********************************************************* +.TP .B link_mtu The maximum packet size (not including the IP header) of tunnel data in UDP tunnel transport mode.
src/openvpn/manage.c +1 -0
@@ -2384,6 +2384,7 @@ env_filter_match (const char *env_str, const int env_filter_level)"dev=" ,"ifconfig_pool_remote_ip=" ,"ifconfig_pool_netmask=" , +"ifconfig_ipv6_pool_remote_ip=" ,"time_duration=" ,"bytes_sent=" ,"bytes_received="
src/openvpn/multi.c +10 -4
@@ -1437,10 +1437,16 @@ multi_set_virtual_addr_env (struct multi_context *m, struct multi_instance *mi) } } -/* TODO: I'm not exactly sure what these environment variables are -* used for, but if we have them for IPv4, we should also have -* them for IPv6, no? -*/ +setenv_del (mi->context.c2.es,"ifconfig_ipv6_pool_remote_ip" ); + +if (mi->context.c2.push_ifconfig_ipv6_defined) + { +setenv_in6_addr_t (mi->context.c2.es, +"ifconfig_ipv6_pool_remote_ip" , + &mi->context.c2.push_ifconfig_ipv6_local, +SA_SET_IF_NONZERO ); + } + }/*
src/openvpn/socket.c +17 -1
@@ -2391,7 +2391,10 @@ setenv_sockaddr (struct env_set *es, const char *name_prefix, const struct openv }break ;case AF_INET6 : -openvpn_snprintf (name_buf,sizeof (name_buf),"%s_ip6" , name_prefix); +if (flags &SA_IP_PORT ) +openvpn_snprintf (name_buf,sizeof (name_buf),"%s_ip6" , name_prefix); +else +openvpn_snprintf (name_buf,sizeof (name_buf),"%s" , name_prefix);getnameinfo (&addr->addr.sa,sizeof (struct sockaddr_in6 ), buf,sizeof (buf),NULL ,0 ,NI_NUMERICHOST );setenv_str (es, name_buf, buf);
@@ -2419,6 +2422,19 @@ setenv_in_addr_t (struct env_set *es, const char *name_prefix, in_addr_t addr, c }void +setenv_in6_addr_t (struct env_set *es,const char *name_prefix,struct in6_addr *addr,const bool flags) +{ +if (memcmp (addr, &in6addr_any,sizeof (*addr)) !=0 || !(flags &SA_SET_IF_NONZERO )) + { +struct openvpn_sockaddr si; +CLEAR (si); + si.addr.in6.sin6_family =AF_INET6 ; + si.addr.in6.sin6_addr = *addr; +setenv_sockaddr (es, name_prefix, &si, flags); + } +} + +void setenv_link_socket_actual (struct env_set *es, const char *name_prefix, const struct link_socket_actual *act,
src/openvpn/socket.h +5 -0
@@ -383,6 +383,11 @@ void setenv_in_addr_t (struct env_set *es,in_addr_t addr, const unsigned int flags); +void setenv_in6_addr_t (struct env_set *es, +const char *name_prefix, +struct in6_addr *addr, +const bool flags); + void setenv_link_socket_actual (struct env_set *es, const char *name_prefix, const struct link_socket_actual *act,
Hi,
Quoted 8 lines · Samuel Thibault
Quoted 6 lines · Gert Doering, le Sat 25 May 2013 13:58:19 +0200, a écrit :
Quoted 3 lines
To make it short: yes, the ipv6 pool environment variables are useful, for user-defined scripts to be run at connection for instance to propagate routes, do accounting, etc. The patch below adds them.
You keep claiming that "yes it's useful". The lack of feedback on the list is partly due to the "To make it short" part of your mail...
Quoted 6 lines
Ok. I was simply wondering whether it had perhaps got somehow dropped without reason.
As I mentioned too briefly, the reason we need it is the same as for the IPv4 case: to announce the route to our bird daemon on connection, and drop it on disconnection.
Mmmmh. Trying to understand this: so you're not using a common /64 for the tun addresses (= the ifconfig-ipv6-pool), but each client gets some other address, which is then announced on-demand by bird?
I can see that this is useful, but the naming of the environment variables in this case is more confusing, as it's not really related to the *pool*.
Have you looked at the learn-address script? I use something similar at a customer (adding and removing proxy-arp entries on client connect) and learn-address does all I need just fine...
Quoted 10 lines
Quoted 4 lines
So the only thing that I couldn't see right away
in the environment is "what IPv6 address did the remote receive?" and that one *is* available as parameter to the "learn-address" script already today...But we need it from the disconnect script too, to remove the route announcement. It is available for IPv4, I don't see why things should be different between IPv6 and IPv4 here. It would make our script way more obscure for sure (having to record the route somewhere, re-read on disconnect).
Well, learn-address is run on disconnect, but not "right away" - true, so having it in disconnect is useful.
I wonder whether we should also export iroute-ipv6 settings, as that would enable on-demand routing of more than a single IPv6 address.
... need to think more about this.
But thanks anyway for explaining your use case.
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]...Quoted 12 lines · Gert Doering, le Mon 27 May 2013 09:25:12 +0200, a écrit :
Quoted 11 lines · Samuel Thibault
Quoted 6 lines · Gert Doering, le Sat 25 May 2013 13:58:19 +0200, a écrit :
Quoted 3 lines
To make it short: yes, the ipv6 pool environment variables are useful, for user-defined scripts to be run at connection for instance to propagate routes, do accounting, etc. The patch below adds them.
You keep claiming that "yes it's useful". The lack of feedback on the list is partly due to the "To make it short" part of your mail...
Ok. I was simply wondering whether it had perhaps got somehow dropped without reason.
Quoted 6 lines
Quoted 3 lines
As I mentioned too briefly, the reason we need it is the same as for the IPv4 case: to announce the route to our bird daemon on connection, and drop it on disconnection.
Mmmmh. Trying to understand this: so you're not using a common /64 for the tun addresses (= the ifconfig-ipv6-pool),
We are, but,
Quoted 1 line
which is then announced on-demand by bird?
we need to announce it on-demand by bird, because we plan to possibly have several servers. Actually we also add the routes because we already have several openvpn daemons, because we have to let people connect through either udp and tcp, depending on the wild area they happen to have landed on. So we need to tell the kernel which tun (i.e. which openvpn daemon) to push paquets to.
Quoted 3 lines
Have you looked at the learn-address script? I use something similar at a customer (adding and removing proxy-arp entries on client connect) and learn-address does all I need just fine...
That could do it yes, however,
Quoted 2 lines
Well, learn-address is run on disconnect, but not "right away" - true, so having it in disconnect is useful.
yes. The rather random delay hurts by preventing from reconnecting immediately (either to the same daemon, or to another one or even another server), which is a pain when trying to set up the VPN in a wild area :)
Quoted 2 lines
I wonder whether we should also export iroute-ipv6 settings, as that would enable on-demand routing of more than a single IPv6 address.
Actually in our case iroute is fed by radiusplugin, which happens to also already add the route for us, so we didn't have to add that one. But it could be better to have radiusplugin just pass iroute to openvpn, and let the userscript add the route if needed.
Samuel
Hello,
Any news on this issue?
Samuel
Quoted 52 lines · Samuel Thibault, le Mon 27 May 2013 22:05:19 +0200, a écrit :
Quoted 12 lines · Gert Doering, le Mon 27 May 2013 09:25:12 +0200, a écrit :
Quoted 11 lines · Samuel Thibault
Quoted 6 lines · Gert Doering, le Sat 25 May 2013 13:58:19 +0200, a écrit :
Quoted 3 lines
To make it short: yes, the ipv6 pool environment variables are useful, for user-defined scripts to be run at connection for instance to propagate routes, do accounting, etc. The patch below adds them.
You keep claiming that "yes it's useful". The lack of feedback on the list is partly due to the "To make it short" part of your mail...
Ok. I was simply wondering whether it had perhaps got somehow dropped without reason.
Quoted 6 lines
Quoted 3 lines
As I mentioned too briefly, the reason we need it is the same as for the IPv4 case: to announce the route to our bird daemon on connection, and drop it on disconnection.
Mmmmh. Trying to understand this: so you're not using a common /64 for the tun addresses (= the ifconfig-ipv6-pool),
We are, but,
Quoted 1 line
which is then announced on-demand by bird?
we need to announce it on-demand by bird, because we plan to possibly have several servers. Actually we also add the routes because we already have several openvpn daemons, because we have to let people connect through either udp and tcp, depending on the wild area they happen to have landed on. So we need to tell the kernel which tun (i.e. which openvpn daemon) to push paquets to.
Quoted 3 lines
Have you looked at the learn-address script? I use something similar at a customer (adding and removing proxy-arp entries on client connect) and learn-address does all I need just fine...
That could do it yes, however,
Quoted 2 lines
Well, learn-address is run on disconnect, but not "right away" - true, so having it in disconnect is useful.
yes. The rather random delay hurts by preventing from reconnecting immediately (either to the same daemon, or to another one or even another server), which is a pain when trying to set up the VPN in a wild area :)
Quoted 2 lines
I wonder whether we should also export iroute-ipv6 settings, as that would enable on-demand routing of more than a single IPv6 address.
Actually in our case iroute is fed by radiusplugin, which happens to also already add the route for us, so we didn't have to add that one. But it could be better to have radiusplugin just pass iroute to openvpn, and let the userscript add the route if needed.
Hi,
Quoted 1 line · Samuel Thibault
Any news on this issue?
Embarassing as it might be, haven't had time to work on that corner of OpenVPN :-(
But re-reading your mail to understand what this was about (two years about... *sigh*), something else sprung up:
Quoted 4 lines
Quoted 4 lines
Actually in our case iroute is fed by radiusplugin, which happens to also already add the route for us, so we didn't have to add that one. But it could be better to have radiusplugin just pass iroute to openvpn, and let the userscript add the route if needed.
... if you are using radiusplugin, you could use "ifconfig-ipv6-push" to have *radius* set up which IPv6 address a given client gets (as for the iroute-ipv6), so you have that information out of band, not having to rely on OpenVPN's pool handling.
Of course this is only sidestepping the underlying issue, which I agree should be fixed.
(Someone having 2-4 weeks of spare time available I could use?)
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]...