Skip to contentSkip to conversation

IPv6 enhancement: non-/64 prefix lengths for IPv6

Openvpn-devel Gert Doering 4 participants 8 messages Feb 3, 2012 – Mar 14, 2013 1 message not in the archive

lore
Share & tools
lore
#0 lore raw

Hi,

in time for 2.3, one of the remaining open itches for the IPv6 code is now fixed :-) (and the changes needed turned out to be fairly trivial).

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]...

From 8873bdf1c69c7fd655d7cce23b1dbf2d542b5cab Mon Sep 17 00:00:00 2001
From: Gert Doering <[email protected]...>
Date: Fri, 3 Feb 2012 08:42:09 +0100
Subject: [PATCH] Implement IPv6 interface config with non-/64 prefix lengths.

Add "ifconfig_ipv6_netbits_parm" parameter to init_tun(), use that to initialize tt->netbits_ipv6 (previously: always /64). Actual interface setup code already used tt->netbits_ipv6, so no changes needed there.

Remove restrictions on "/netbits" value for --server-ipv6 config option (can now be /64.../112, previously had to be exactly /64). Supporting even smaller networks could cause problems with ipv6-pool handling and are only allowed for explicit "ifconfig-ipv6", not for "server-ipv6".

Add /netbits to pushed "ifconfig-ipv6" values on server side (client side always accepted this, but ignored it so far, so this does not break compatibility).

Tested on Linux/ifconfig, Linux/iproute2 and FreeBSD 7.4

---
 helper.c  |    8 +++++---
 init.c    |    1 +
 options.c |    5 +++--
 push.c    |    3 ++-
 tun.c     |    4 +++-
 tun.h     |    1 +
 6 files changed, 15 insertions(+), 7 deletions(-)
helper.c +5 -3
index c7333f6..22ea652 100644
@@ -184,12 +184,14 @@ helper_client_server (struct options *o)
 		print_in6_addr( add_in6_addr( o->server_network_ipv6, 1), 0, &o->gc );
 	o->ifconfig_ipv6_remote = 
 		print_in6_addr( add_in6_addr( o->server_network_ipv6, 2), 0, &o->gc );
+	o->ifconfig_ipv6_netbits = o->server_netbits_ipv6;
+
+	/* pool starts at "base address + 0x1000" - leave enough room */
+	ASSERT( o->server_netbits_ipv6 <= 112 );	/* want 16 bits */
 
-	/* pool starts at "base address + 0x10000" */
-	ASSERT( o->server_netbits_ipv6 < 96 );		/* want 32 bits */
 	o->ifconfig_ipv6_pool_defined = true;
 	o->ifconfig_ipv6_pool_base = 
-		add_in6_addr( o->server_network_ipv6, 0x10000 );
+		add_in6_addr( o->server_network_ipv6, 0x1000 );
 	o->ifconfig_ipv6_pool_netbits = o->server_netbits_ipv6;
 
 	o->tun_ipv6 = true;
init.c +1 -0
index b8cb84f..525f441 100644
@@ -1415,6 +1415,7 @@ do_init_tun (struct context *c)
 			   c->options.ifconfig_local,
 			   c->options.ifconfig_remote_netmask,
 			   c->options.ifconfig_ipv6_local,
+			   c->options.ifconfig_ipv6_netbits,
 			   c->options.ifconfig_ipv6_remote,
 			   addr_host (&c->c1.link_socket_addr.local),
 			   addr_host (&c->c1.link_socket_addr.remote),
options.c +3 -2
index 0fbe368..cb9738a 100644
@@ -2926,6 +2926,7 @@ options_string (const struct options *o,
 		     o->ifconfig_local,
 		     o->ifconfig_remote_netmask,
 		     o->ifconfig_ipv6_local,
+		     o->ifconfig_ipv6_netbits,
 		     o->ifconfig_ipv6_remote,
 		     (in_addr_t)0,
 		     (in_addr_t)0,
@@ -5396,9 +5397,9 @@ add_option (struct options *options,
 	  msg (msglevel, "error parsing --server-ipv6 parameter");
 	  goto err;
 	}
-      if ( netbits != 64 )
+      if ( netbits < 64 || netbits > 112 )
 	{
-	  msg( msglevel, "--server-ipv6 settings: only /64 supported right now (not /%d)", netbits );
+	  msg( msglevel, "--server-ipv6 settings: only /64../112 supported right now (not /%d)", netbits );
 	  goto err;
 	}
       options->server_ipv6_defined = true;
push.c +2 -1
index a8ce356..9f4c50e 100644
@@ -245,8 +245,9 @@ send_push_reply (struct context *c)
       /* TODO: push "/netbits" as well, to allow non-/64 subnet sizes
        *       (needs changes in options.c, options.h, and other places)
        */
-      buf_printf( &buf, ",ifconfig-ipv6 %s %s",
+      buf_printf( &buf, ",ifconfig-ipv6 %s/%d %s",
 		    print_in6_addr( c->c2.push_ifconfig_ipv6_local, 0, &gc),
+		    c->c2.push_ifconfig_ipv6_netbits,
 		    print_in6_addr( c->c2.push_ifconfig_ipv6_remote, 0, &gc) );
       if (BLEN (&buf) >= safe_cap)
 	{
tun.c +3 -1
index c9af168..1527ac8 100644
@@ -404,6 +404,7 @@ init_tun (const char *dev,       /* --dev option */
 	  const char *ifconfig_local_parm,          /* --ifconfig parm 1 */
 	  const char *ifconfig_remote_netmask_parm, /* --ifconfig parm 2 */
 	  const char *ifconfig_ipv6_local_parm,     /* --ifconfig parm 1 IPv6 */
+	  int         ifconfig_ipv6_netbits_parm,
 	  const char *ifconfig_ipv6_remote_parm,    /* --ifconfig parm 2 IPv6 */
 	  in_addr_t local_public,
 	  in_addr_t remote_public,
@@ -534,7 +535,7 @@ init_tun (const char *dev,       /* --dev option */
 	{
 	  msg( M_FATAL, "init_tun: problem converting IPv6 ifconfig addresses %s and %s to binary", ifconfig_ipv6_local_parm, ifconfig_ipv6_remote_parm );
 	}
-      tt->netbits_ipv6 = 64;
+      tt->netbits_ipv6 = ifconfig_ipv6_netbits_parm;
 
       /*
        * Set ifconfig parameters
@@ -548,6 +549,7 @@ init_tun (const char *dev,       /* --dev option */
       if (es)
 	{
 	  setenv_str (es, "ifconfig_ipv6_local", ifconfig_ipv6_local);
+	  setenv_int (es, "ifconfig_ipv6_netbits", tt->netbits_ipv6);
 	  setenv_str (es, "ifconfig_ipv6_remote", ifconfig_ipv6_remote);
 	}
       tt->did_ifconfig_ipv6_setup = true;
tun.h +1 -0
index f28b8d8..c0785dd 100644
@@ -225,6 +225,7 @@ struct tuntap *init_tun (const char *dev,       /* --dev option */
 			 const char *ifconfig_local_parm,          /* --ifconfig parm 1 */
 			 const char *ifconfig_remote_netmask_parm, /* --ifconfig parm 2 */
 			 const char *ifconfig_ipv6_local_parm,     /* --ifconfig parm 1 / IPv6 */
+			 int ifconfig_ipv6_netbits_parm,           /* --ifconfig parm 1 / bits */
 			 const char *ifconfig_ipv6_remote_parm,    /* --ifconfig parm 2 / IPv6 */
 			 in_addr_t local_public,
 			 in_addr_t remote_public,
Signature · 1 line
1.7.3.4

A message that is not in the archive (sent off-list or not yet received): [email protected]...

#2 lore raw

Hi,

Quoted 10 lines · Michael

the patch does not remove

+++ b/push.c

(quoted diff) +0 -0
@@ -245,8 +245,9 @@ send_push_reply (struct context *c)
       /* TODO: push "/netbits" as well, to allow non-/64 subnet sizes
        *       (needs changes in options.c, options.h, and other 
 places)
        */
 

though the code now does it?

Indeed, thanks. I overlooked that.

(Need to check with Dazo how to get that into the same commit...)

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

Re: [Openvpn-devel] IPv6 enhancement: non-/64 prefix lengths for IPv6 [v2]

Hi,

Quoted 9 lines · Gert Doering

Review send_push_reply (struct context *c) · line 248

Quoted 8 lines · Michael

the patch does not remove

+++ b/push.c

(quoted diff) +0 -0
@@ -245,8 +245,9 @@ send_push_reply (struct context *c)
       /* TODO: push "/netbits" as well, to allow non-/64 subnet sizes
        *       (needs changes in options.c, options.h, and other 
 places)
        */

Now it does :-) - thanks for pointing this out. v2 patch attached.

"git --reset" is my friend ;-)

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]...

From 53e78848f552235c3270419771f3e3293dfe91ec Mon Sep 17 00:00:00 2001
From: Gert Doering <[email protected]...>
Date: Fri, 3 Feb 2012 17:11:03 +0100
Subject: [PATCH] Implement IPv6 interface config with non-/64 prefix lengths.

Add "ifconfig_ipv6_netbits_parm" parameter to init_tun(), use that to initialize tt->netbits_ipv6 (previously: always /64). Actual interface setup code already used tt->netbits_ipv6, so no changes needed there.

Remove restrictions on "/netbits" value for --server-ipv6 config option (can now be /64.../112, previously had to be exactly /64). Supporting even smaller networks could cause problems with ipv6-pool handling and are only allowed for explicit "ifconfig-ipv6", not for "server-ipv6".

Add /netbits to pushed "ifconfig-ipv6" values on server side (client side always accepted this, but ignored it so far, so this does not break compatibility).

Tested on Linux/ifconfig, Linux/iproute2 and FreeBSD 7.4

---
 TODO.IPv6 |    2 ++
 helper.c  |    8 +++++---
 init.c    |    1 +
 options.c |    5 +++--
 push.c    |    6 ++----
 tun.c     |    4 +++-
 tun.h     |    1 +
 7 files changed, 17 insertions(+), 10 deletions(-)
TODO.IPv6 +2 -0
index 87c47b3..f23cce0 100644
@@ -77,6 +77,8 @@ tun0: flags=8051<UP,POINTOPOINT,RUNNING,MULTICAST> mtu 1500
     of /netbits, and correctly ifconfig'ing this
     (default, if not specified: /64)
 
+    * done * 2012-02-03
+
 11.) do not add ipv6-routes if tun-ipv6 is not set - complain instead
 
      * done * 12.1.10
helper.c +5 -3
index c7333f6..22ea652 100644
@@ -184,12 +184,14 @@ helper_client_server (struct options *o)
 		print_in6_addr( add_in6_addr( o->server_network_ipv6, 1), 0, &o->gc );
 	o->ifconfig_ipv6_remote = 
 		print_in6_addr( add_in6_addr( o->server_network_ipv6, 2), 0, &o->gc );
+	o->ifconfig_ipv6_netbits = o->server_netbits_ipv6;
+
+	/* pool starts at "base address + 0x1000" - leave enough room */
+	ASSERT( o->server_netbits_ipv6 <= 112 );	/* want 16 bits */
 
-	/* pool starts at "base address + 0x10000" */
-	ASSERT( o->server_netbits_ipv6 < 96 );		/* want 32 bits */
 	o->ifconfig_ipv6_pool_defined = true;
 	o->ifconfig_ipv6_pool_base = 
-		add_in6_addr( o->server_network_ipv6, 0x10000 );
+		add_in6_addr( o->server_network_ipv6, 0x1000 );
 	o->ifconfig_ipv6_pool_netbits = o->server_netbits_ipv6;
 
 	o->tun_ipv6 = true;
init.c +1 -0
index b8cb84f..525f441 100644
@@ -1415,6 +1415,7 @@ do_init_tun (struct context *c)
 			   c->options.ifconfig_local,
 			   c->options.ifconfig_remote_netmask,
 			   c->options.ifconfig_ipv6_local,
+			   c->options.ifconfig_ipv6_netbits,
 			   c->options.ifconfig_ipv6_remote,
 			   addr_host (&c->c1.link_socket_addr.local),
 			   addr_host (&c->c1.link_socket_addr.remote),
options.c +3 -2
index 0fbe368..cb9738a 100644
@@ -2926,6 +2926,7 @@ options_string (const struct options *o,
 		     o->ifconfig_local,
 		     o->ifconfig_remote_netmask,
 		     o->ifconfig_ipv6_local,
+		     o->ifconfig_ipv6_netbits,
 		     o->ifconfig_ipv6_remote,
 		     (in_addr_t)0,
 		     (in_addr_t)0,
@@ -5396,9 +5397,9 @@ add_option (struct options *options,
 	  msg (msglevel, "error parsing --server-ipv6 parameter");
 	  goto err;
 	}
-      if ( netbits != 64 )
+      if ( netbits < 64 || netbits > 112 )
 	{
-	  msg( msglevel, "--server-ipv6 settings: only /64 supported right now (not /%d)", netbits );
+	  msg( msglevel, "--server-ipv6 settings: only /64../112 supported right now (not /%d)", netbits );
 	  goto err;
 	}
       options->server_ipv6_defined = true;
push.c +2 -4
index a8ce356..8a8779d 100644
@@ -242,11 +242,9 @@ send_push_reply (struct context *c)
   if ( c->c2.push_ifconfig_ipv6_defined )
     {
       /* IPv6 is put into buffer first, could be lengthy */
-      /* TODO: push "/netbits" as well, to allow non-/64 subnet sizes
-       *       (needs changes in options.c, options.h, and other places)
-       */
-      buf_printf( &buf, ",ifconfig-ipv6 %s %s",
+      buf_printf( &buf, ",ifconfig-ipv6 %s/%d %s",
 		    print_in6_addr( c->c2.push_ifconfig_ipv6_local, 0, &gc),
+		    c->c2.push_ifconfig_ipv6_netbits,
 		    print_in6_addr( c->c2.push_ifconfig_ipv6_remote, 0, &gc) );
       if (BLEN (&buf) >= safe_cap)
 	{
tun.c +3 -1
index c9af168..1527ac8 100644
@@ -404,6 +404,7 @@ init_tun (const char *dev,       /* --dev option */
 	  const char *ifconfig_local_parm,          /* --ifconfig parm 1 */
 	  const char *ifconfig_remote_netmask_parm, /* --ifconfig parm 2 */
 	  const char *ifconfig_ipv6_local_parm,     /* --ifconfig parm 1 IPv6 */
+	  int         ifconfig_ipv6_netbits_parm,
 	  const char *ifconfig_ipv6_remote_parm,    /* --ifconfig parm 2 IPv6 */
 	  in_addr_t local_public,
 	  in_addr_t remote_public,
@@ -534,7 +535,7 @@ init_tun (const char *dev,       /* --dev option */
 	{
 	  msg( M_FATAL, "init_tun: problem converting IPv6 ifconfig addresses %s and %s to binary", ifconfig_ipv6_local_parm, ifconfig_ipv6_remote_parm );
 	}
-      tt->netbits_ipv6 = 64;
+      tt->netbits_ipv6 = ifconfig_ipv6_netbits_parm;
 
       /*
        * Set ifconfig parameters
@@ -548,6 +549,7 @@ init_tun (const char *dev,       /* --dev option */
       if (es)
 	{
 	  setenv_str (es, "ifconfig_ipv6_local", ifconfig_ipv6_local);
+	  setenv_int (es, "ifconfig_ipv6_netbits", tt->netbits_ipv6);
 	  setenv_str (es, "ifconfig_ipv6_remote", ifconfig_ipv6_remote);
 	}
       tt->did_ifconfig_ipv6_setup = true;
tun.h +1 -0
index f28b8d8..c0785dd 100644
@@ -225,6 +225,7 @@ struct tuntap *init_tun (const char *dev,       /* --dev option */
 			 const char *ifconfig_local_parm,          /* --ifconfig parm 1 */
 			 const char *ifconfig_remote_netmask_parm, /* --ifconfig parm 2 */
 			 const char *ifconfig_ipv6_local_parm,     /* --ifconfig parm 1 / IPv6 */
+			 int ifconfig_ipv6_netbits_parm,           /* --ifconfig parm 1 / bits */
 			 const char *ifconfig_ipv6_remote_parm,    /* --ifconfig parm 2 / IPv6 */
 			 in_addr_t local_public,
 			 in_addr_t remote_public,
Signature · 1 line
1.7.3.4
#4 lore raw

Re: [Openvpn-devel] IPv6 enhancement: non-/64 prefix lengths for IPv6 [v2]

Quoted 15 lines · Gert Doering

Hi,

Quoted 9 lines · Gert Doering

Review send_push_reply (struct context *c) · line 248

Quoted 8 lines · Michael

the patch does not remove

+++ b/push.c

(quoted diff) +0 -0
@@ -245,8 +245,9 @@ send_push_reply (struct context *c)
        /* TODO: push "/netbits" as well, to allow non-/64 subnet sizes
         *       (needs changes in options.c, options.h, and other
 places)
         */

Now it does :-) - thanks for pointing this out. v2 patch attached.

Quoted 1 line

"git --reset" is my friend ;-)

ACK. Applied to master branch on -testing and stable.

commit c55e9562d64f381ba46b83a02503f6239e23d3ef

Author: Gert Doering <[email protected]...>
Date:   Fri Feb 3 17:11:03 2012 +0100
    Implement IPv6 interface config with non-/64 prefix lengths.

    Signed-off-by: Gert Doering <[email protected]...>
    Acked-by: David Sommerseth <[email protected]...>
    Signed-off-by: David Sommerseth <[email protected]...>

kind regards,

David Sommerseth

#5 lore raw
In reply to Gert Doering
Quoted 5 lines · On Fri, 3 Feb 2012 09:44:26 +0100 Gert Doering <[email protected]...> wrote:

Hi,

in time for 2.3, one of the remaining open itches for the IPv6 code is now fixed :-) (and the changes needed turned out to be fairly trivial).

Using ifconfig-ipv6-pool instead of server-ipv6(-macro) does not allow non-/64 prefix (in current 2.3). Bug or Feature?

Best regards,
Marcel

#6 lore raw

Hi,

Quoted 6 lines · Marcel Pennewiß
Quoted 3 lines

in time for 2.3, one of the remaining open itches for the IPv6 code is now fixed :-) (and the changes needed turned out to be fairly trivial).

Using ifconfig-ipv6-pool instead of server-ipv6(-macro) does not allow non-/64 prefix (in current 2.3). Bug or Feature?

Smells buggy. As server-ipv6 is just a macro (not really, but sort of).

Indeed... options.c:

else if (streq (p[0], "ifconfig-ipv6-pool") && p[1] )
...

      if ( netbits != 64 )
        {
          msg( msglevel, "--ifconfig-ipv6-pool settings: only /64 supported righ
t now (not /%d)", netbits );
          goto err;
        }

... this is a leftover from the initial days, where nothing else was supported (not for server-ipv6 either).

Patch is trivial, please find attached. David: 2.3.1 and 2.4.0, please :-)

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]...

From cdfbc8952a01acde0eedf08fa0ebefed38fa2763 Mon Sep 17 00:00:00 2001
From: Gert Doering <[email protected]...>
Date: Sun, 20 Jan 2013 20:50:38 +0200
Subject: [PATCH] Permit pool size of /64.../112 for ifconfig-ipv6-pool

(Leftover check from the early days where --server-ipv6 also only accepted /64 - nowadays we handle smaller pools just fine)

---
 src/openvpn/options.c |    4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)
src/openvpn/options.c +2 -2
index 8ca41a3..1d89e4b 100644
@@ -5484,9 +5484,9 @@ add_option (struct options *options,
 	  msg (msglevel, "error parsing --ifconfig-ipv6-pool parameters");
 	  goto err;
 	}
-      if ( netbits != 64 )
+      if ( netbits < 64 || netbits > 112 )
 	{
-	  msg( msglevel, "--ifconfig-ipv6-pool settings: only /64 supported right now (not /%d)", netbits );
+	  msg( msglevel, "--ifconfig-ipv6-pool settings: only /64../112 supported right now (not /%d)", netbits );
 	  goto err;
 	}
 
Signature · 1 line
1.7.3.5
#7 lore raw

Am 20.01.13 19:50, schrieb Gert Doering:

Quoted 21 lines

Hi,

Quoted 5 lines · Marcel Pennewiß
Quoted 3 lines

in time for 2.3, one of the remaining open itches for the IPv6 code is now fixed :-) (and the changes needed turned out to be fairly trivial).

Using ifconfig-ipv6-pool instead of server-ipv6(-macro) does not allow non-/64 prefix (in current 2.3). Bug or Feature?

Smells buggy. As server-ipv6 is just a macro (not really, but sort of).

Indeed... options.c:

else if (streq (p[0], "ifconfig-ipv6-pool") && p[1] )
...

      if ( netbits != 64 )
        {
          msg( msglevel, "--ifconfig-ipv6-pool settings: only /64 supported righ
t now (not /%d)", netbits );
          goto err;
        }
Quoted 4 lines

... this is a leftover from the initial days, where nothing else was supported (not for server-ipv6 either).

Patch is trivial, please find attached. David: 2.3.1 and 2.4.0, please :-)

Patch looks good. ACK from me.

Arne

#8 lore raw
In reply to Gert Doering

Hi,

Quoted 7 lines · Gert Doering

From cdfbc8952a01acde0eedf08fa0ebefed38fa2763 Mon Sep 17 00:00:00 2001
From: Gert Doering <[email protected]...>
Date: Sun, 20 Jan 2013 20:50:38 +0200
Subject: [PATCH] Permit pool size of /64.../112 for ifconfig-ipv6-pool

(Leftover check from the early days where --server-ipv6 also only accepted /64 - nowadays we handle smaller pools just fine)

... talking to myself again... committed to master and release/2.3

commit 704d9273b6e0e253b62eb728fddd5bbb02503eea (master) commit 0fb2391660a369853f20fd4807eaa5ed3461e755 (release/2.3)

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]...