[PATCH] openggsn[master]: Support setting TUN device IPv6 address + prefix

2017-08-11 Thread Harald Welte
Hello Jenkins Builder,

I'd like you to reexamine a change.  Please visit

https://gerrit.osmocom.org/3408

to look at the new patch set (#9).

Support setting TUN device IPv6 address + prefix

As we can now have PDP contexts with IPv6 user IP payload,
it is useful to extend the TUN related code to be able to
configure the tun device IPv6 address + prefix length

Change-Id: I899d21e52d02e0b8384af29ddd489ff19c8f2cf6
---
M ggsn/ggsn.c
M lib/tun.c
M lib/tun.h
3 files changed, 127 insertions(+), 19 deletions(-)


  git pull ssh://gerrit.osmocom.org:29418/openggsn refs/changes/08/3408/9

diff --git a/ggsn/ggsn.c b/ggsn/ggsn.c
index 991b54c..05a56ae 100644
--- a/ggsn/ggsn.c
+++ b/ggsn/ggsn.c
@@ -70,7 +70,7 @@
 int maxfd = 0; /* For select()*/
 
 struct in_addr listen_;
-struct in_addr netaddr, destaddr, net; /* Network interface   */
+struct in46_addr netaddr, destaddr, net;   /* Network interface   */
 size_t prefixlen;
 struct in46_addr dns1, dns2;   /* PCO DNS address */
 char *ipup, *ipdown;   /* Filename of scripts */
@@ -547,16 +547,16 @@
/* net  */
/* Store net as in_addr net and mask*/
if (args_info.net_arg) {
-   struct in46_addr in46;
-   if (ippool_aton(&in46, &prefixlen, args_info.net_arg, 0)) {
+   if (ippool_aton(&net, &prefixlen, args_info.net_arg, 0)) {
SYS_ERR(DGGSN, LOGL_ERROR, 0,
"Invalid network address: %s!",
args_info.net_arg);
exit(1);
}
-   net.s_addr = in46.v4.s_addr;
-   netaddr.s_addr = htonl(ntohl(net.s_addr) + 1);
-   destaddr.s_addr = htonl(ntohl(net.s_addr) + 1);
+   /* default for network + destination address = net + 1 */
+   netaddr = net;
+   in46a_inc(&netaddr);
+   destaddr = netaddr;
} else {
SYS_ERR(DGGSN, LOGL_ERROR, 0,
"Network address must be specified: %s!",
@@ -710,7 +710,7 @@
maxfd = gsn->fd1u;
 
/* use GTP kernel module for data packet encapsulation */
-   if (gtp_kernel_init(gsn, &net, prefixlen, &args_info) < 0)
+   if (gtp_kernel_init(gsn, &net.v4, prefixlen, &args_info) < 0)
goto err;
 
gtp_set_cb_data_ind(gsn, encaps_tun);
@@ -735,7 +735,7 @@
}
 
DEBUGP(DGGSN, "Setting tun IP address\n");
-   if (tun_setaddr(tun, &netaddr, &destaddr, &prefixlen)) {
+   if (tun_setaddr(tun, &netaddr, &destaddr, prefixlen)) {
SYS_ERR(DGGSN, LOGL_ERROR, 0, "Failed to set tun IP address");
exit(1);
}
diff --git a/lib/tun.c b/lib/tun.c
index 8325f5d..11ea7bc 100644
--- a/lib/tun.c
+++ b/lib/tun.c
@@ -1,6 +1,7 @@
 /* 
  * TUN interface functions.
  * Copyright (C) 2002, 2003, 2004 Mondru AB.
+ * Copyright (C) 2017 by Harald Welte 
  * 
  * The contents of this file may be used under the terms of the GNU
  * General Public License Version 2, provided that the above copyright
@@ -37,16 +38,17 @@
 #include 
 #include 
 #include 
+#include 
 
 #if defined(__linux__)
-#include 
 #include 
 #include 
 #include 
 
 #elif defined (__FreeBSD__)
-#include 
 #include 
+#include 
+#include 
 
 #elif defined (__APPLE__)
 #include 
@@ -65,7 +67,12 @@
 #include "tun.h"
 #include "syserr.h"
 
+static int tun_setaddr4(struct tun_t *this, struct in_addr *addr,
+   struct in_addr *dstaddr, struct in_addr *netmask);
+
 #if defined(__linux__)
+
+#include 
 
 int tun_nlattr(struct nlmsghdr *n, int nsize, int type, void *d, int dlen)
 {
@@ -247,7 +254,7 @@
struct msghdr msg;
 
if (!this->addrs)   /* Use ioctl for first addr to make ping work */
-   return tun_setaddr(this, addr, dstaddr, netmask);
+   return tun_setaddr4(this, addr, dstaddr, netmask);
 
memset(&req, 0, sizeof(req));
req.n.nlmsg_len = NLMSG_LENGTH(sizeof(struct ifaddrmsg));
@@ -345,7 +352,7 @@
 
/* TODO: Is this needed on FreeBSD? */
if (!this->addrs)   /* Use ioctl for first addr to make ping work */
-   return tun_setaddr(this, addr, dstaddr, netmask);   /* TODO 
dstaddr */
+   return tun_setaddr4(this, addr, dstaddr, netmask);  /* TODO 
dstaddr */
 
memset(&areq, 0, sizeof(areq));
 
@@ -391,7 +398,7 @@
 #elif defined (__sun__)
 
if (!this->addrs)   /* Use ioctl for first addr to make ping work */
-   return tun_setaddr(this, addr, dstaddr, netmask);
+   return tun_setaddr4(this, addr, dstaddr, netmask);
 
SYS_ERR(DTUN, LOGL_ERROR, errno,
"Setting multiple addresses not possible on Solaris");
@@ -403,9 +410,8 @@
 
 }
 
-int tun_setaddr(struct tun_t *this,
-  

[PATCH] openggsn[master]: Support setting TUN device IPv6 address + prefix

2017-08-11 Thread Harald Welte
Hello Jenkins Builder,

I'd like you to reexamine a change.  Please visit

https://gerrit.osmocom.org/3408

to look at the new patch set (#8).

Support setting TUN device IPv6 address + prefix

As we can now have PDP contexts with IPv6 user IP payload,
it is useful to extend the TUN related code to be able to
configure the tun device IPv6 address + prefix length

Change-Id: I899d21e52d02e0b8384af29ddd489ff19c8f2cf6
---
M ggsn/ggsn.c
M lib/tun.c
M lib/tun.h
3 files changed, 127 insertions(+), 17 deletions(-)


  git pull ssh://gerrit.osmocom.org:29418/openggsn refs/changes/08/3408/8

diff --git a/ggsn/ggsn.c b/ggsn/ggsn.c
index 991b54c..05a56ae 100644
--- a/ggsn/ggsn.c
+++ b/ggsn/ggsn.c
@@ -70,7 +70,7 @@
 int maxfd = 0; /* For select()*/
 
 struct in_addr listen_;
-struct in_addr netaddr, destaddr, net; /* Network interface   */
+struct in46_addr netaddr, destaddr, net;   /* Network interface   */
 size_t prefixlen;
 struct in46_addr dns1, dns2;   /* PCO DNS address */
 char *ipup, *ipdown;   /* Filename of scripts */
@@ -547,16 +547,16 @@
/* net  */
/* Store net as in_addr net and mask*/
if (args_info.net_arg) {
-   struct in46_addr in46;
-   if (ippool_aton(&in46, &prefixlen, args_info.net_arg, 0)) {
+   if (ippool_aton(&net, &prefixlen, args_info.net_arg, 0)) {
SYS_ERR(DGGSN, LOGL_ERROR, 0,
"Invalid network address: %s!",
args_info.net_arg);
exit(1);
}
-   net.s_addr = in46.v4.s_addr;
-   netaddr.s_addr = htonl(ntohl(net.s_addr) + 1);
-   destaddr.s_addr = htonl(ntohl(net.s_addr) + 1);
+   /* default for network + destination address = net + 1 */
+   netaddr = net;
+   in46a_inc(&netaddr);
+   destaddr = netaddr;
} else {
SYS_ERR(DGGSN, LOGL_ERROR, 0,
"Network address must be specified: %s!",
@@ -710,7 +710,7 @@
maxfd = gsn->fd1u;
 
/* use GTP kernel module for data packet encapsulation */
-   if (gtp_kernel_init(gsn, &net, prefixlen, &args_info) < 0)
+   if (gtp_kernel_init(gsn, &net.v4, prefixlen, &args_info) < 0)
goto err;
 
gtp_set_cb_data_ind(gsn, encaps_tun);
@@ -735,7 +735,7 @@
}
 
DEBUGP(DGGSN, "Setting tun IP address\n");
-   if (tun_setaddr(tun, &netaddr, &destaddr, &prefixlen)) {
+   if (tun_setaddr(tun, &netaddr, &destaddr, prefixlen)) {
SYS_ERR(DGGSN, LOGL_ERROR, 0, "Failed to set tun IP address");
exit(1);
}
diff --git a/lib/tun.c b/lib/tun.c
index 8325f5d..205d39a 100644
--- a/lib/tun.c
+++ b/lib/tun.c
@@ -1,6 +1,7 @@
 /* 
  * TUN interface functions.
  * Copyright (C) 2002, 2003, 2004 Mondru AB.
+ * Copyright (C) 2017 by Harald Welte 
  * 
  * The contents of this file may be used under the terms of the GNU
  * General Public License Version 2, provided that the above copyright
@@ -37,6 +38,7 @@
 #include 
 #include 
 #include 
+#include 
 
 #if defined(__linux__)
 #include 
@@ -47,6 +49,8 @@
 #elif defined (__FreeBSD__)
 #include 
 #include 
+#include 
+#include 
 
 #elif defined (__APPLE__)
 #include 
@@ -65,7 +69,12 @@
 #include "tun.h"
 #include "syserr.h"
 
+static int tun_setaddr4(struct tun_t *this, struct in_addr *addr,
+   struct in_addr *dstaddr, struct in_addr *netmask);
+
 #if defined(__linux__)
+
+#include 
 
 int tun_nlattr(struct nlmsghdr *n, int nsize, int type, void *d, int dlen)
 {
@@ -247,7 +256,7 @@
struct msghdr msg;
 
if (!this->addrs)   /* Use ioctl for first addr to make ping work */
-   return tun_setaddr(this, addr, dstaddr, netmask);
+   return tun_setaddr4(this, addr, dstaddr, netmask);
 
memset(&req, 0, sizeof(req));
req.n.nlmsg_len = NLMSG_LENGTH(sizeof(struct ifaddrmsg));
@@ -345,7 +354,7 @@
 
/* TODO: Is this needed on FreeBSD? */
if (!this->addrs)   /* Use ioctl for first addr to make ping work */
-   return tun_setaddr(this, addr, dstaddr, netmask);   /* TODO 
dstaddr */
+   return tun_setaddr4(this, addr, dstaddr, netmask);  /* TODO 
dstaddr */
 
memset(&areq, 0, sizeof(areq));
 
@@ -391,7 +400,7 @@
 #elif defined (__sun__)
 
if (!this->addrs)   /* Use ioctl for first addr to make ping work */
-   return tun_setaddr(this, addr, dstaddr, netmask);
+   return tun_setaddr4(this, addr, dstaddr, netmask);
 
SYS_ERR(DTUN, LOGL_ERROR, errno,
"Setting multiple addresses not possible on Solaris");
@@ -403,9 +412,8 @@
 
 }
 
-int tun_setaddr(struct tun_t *this,
-   struct in_addr

[PATCH] openggsn[master]: Support setting TUN device IPv6 address + prefix

2017-08-09 Thread Harald Welte
Hello Jenkins Builder,

I'd like you to reexamine a change.  Please visit

https://gerrit.osmocom.org/3408

to look at the new patch set (#7).

Support setting TUN device IPv6 address + prefix

As we can now have PDP contexts with IPv6 user IP payload,
it is useful to extend the TUN related code to be able to
configure the tun device IPv6 address + prefix length

Change-Id: I899d21e52d02e0b8384af29ddd489ff19c8f2cf6
---
M ggsn/ggsn.c
M lib/tun.c
M lib/tun.h
3 files changed, 111 insertions(+), 17 deletions(-)


  git pull ssh://gerrit.osmocom.org:29418/openggsn refs/changes/08/3408/7

diff --git a/ggsn/ggsn.c b/ggsn/ggsn.c
index 991b54c..05a56ae 100644
--- a/ggsn/ggsn.c
+++ b/ggsn/ggsn.c
@@ -70,7 +70,7 @@
 int maxfd = 0; /* For select()*/
 
 struct in_addr listen_;
-struct in_addr netaddr, destaddr, net; /* Network interface   */
+struct in46_addr netaddr, destaddr, net;   /* Network interface   */
 size_t prefixlen;
 struct in46_addr dns1, dns2;   /* PCO DNS address */
 char *ipup, *ipdown;   /* Filename of scripts */
@@ -547,16 +547,16 @@
/* net  */
/* Store net as in_addr net and mask*/
if (args_info.net_arg) {
-   struct in46_addr in46;
-   if (ippool_aton(&in46, &prefixlen, args_info.net_arg, 0)) {
+   if (ippool_aton(&net, &prefixlen, args_info.net_arg, 0)) {
SYS_ERR(DGGSN, LOGL_ERROR, 0,
"Invalid network address: %s!",
args_info.net_arg);
exit(1);
}
-   net.s_addr = in46.v4.s_addr;
-   netaddr.s_addr = htonl(ntohl(net.s_addr) + 1);
-   destaddr.s_addr = htonl(ntohl(net.s_addr) + 1);
+   /* default for network + destination address = net + 1 */
+   netaddr = net;
+   in46a_inc(&netaddr);
+   destaddr = netaddr;
} else {
SYS_ERR(DGGSN, LOGL_ERROR, 0,
"Network address must be specified: %s!",
@@ -710,7 +710,7 @@
maxfd = gsn->fd1u;
 
/* use GTP kernel module for data packet encapsulation */
-   if (gtp_kernel_init(gsn, &net, prefixlen, &args_info) < 0)
+   if (gtp_kernel_init(gsn, &net.v4, prefixlen, &args_info) < 0)
goto err;
 
gtp_set_cb_data_ind(gsn, encaps_tun);
@@ -735,7 +735,7 @@
}
 
DEBUGP(DGGSN, "Setting tun IP address\n");
-   if (tun_setaddr(tun, &netaddr, &destaddr, &prefixlen)) {
+   if (tun_setaddr(tun, &netaddr, &destaddr, prefixlen)) {
SYS_ERR(DGGSN, LOGL_ERROR, 0, "Failed to set tun IP address");
exit(1);
}
diff --git a/lib/tun.c b/lib/tun.c
index 8325f5d..7e0af12 100644
--- a/lib/tun.c
+++ b/lib/tun.c
@@ -1,6 +1,7 @@
 /* 
  * TUN interface functions.
  * Copyright (C) 2002, 2003, 2004 Mondru AB.
+ * Copyright (C) 2017 by Harald Welte 
  * 
  * The contents of this file may be used under the terms of the GNU
  * General Public License Version 2, provided that the above copyright
@@ -65,7 +66,12 @@
 #include "tun.h"
 #include "syserr.h"
 
+static int tun_setaddr4(struct tun_t *this, struct in_addr *addr,
+   struct in_addr *dstaddr, struct in_addr *netmask);
+
 #if defined(__linux__)
+
+#include 
 
 int tun_nlattr(struct nlmsghdr *n, int nsize, int type, void *d, int dlen)
 {
@@ -247,7 +253,7 @@
struct msghdr msg;
 
if (!this->addrs)   /* Use ioctl for first addr to make ping work */
-   return tun_setaddr(this, addr, dstaddr, netmask);
+   return tun_setaddr4(this, addr, dstaddr, netmask);
 
memset(&req, 0, sizeof(req));
req.n.nlmsg_len = NLMSG_LENGTH(sizeof(struct ifaddrmsg));
@@ -345,7 +351,7 @@
 
/* TODO: Is this needed on FreeBSD? */
if (!this->addrs)   /* Use ioctl for first addr to make ping work */
-   return tun_setaddr(this, addr, dstaddr, netmask);   /* TODO 
dstaddr */
+   return tun_setaddr4(this, addr, dstaddr, netmask);  /* TODO 
dstaddr */
 
memset(&areq, 0, sizeof(areq));
 
@@ -391,7 +397,7 @@
 #elif defined (__sun__)
 
if (!this->addrs)   /* Use ioctl for first addr to make ping work */
-   return tun_setaddr(this, addr, dstaddr, netmask);
+   return tun_setaddr4(this, addr, dstaddr, netmask);
 
SYS_ERR(DTUN, LOGL_ERROR, errno,
"Setting multiple addresses not possible on Solaris");
@@ -403,9 +409,8 @@
 
 }
 
-int tun_setaddr(struct tun_t *this,
-   struct in_addr *addr,
-   struct in_addr *dstaddr, struct in_addr *netmask)
+static int tun_setaddr4(struct tun_t *this, struct in_addr *addr,
+   struct in_addr *dstaddr, struct in_addr *netmask)
 {
stru

[PATCH] openggsn[master]: Support setting TUN device IPv6 address + prefix

2017-08-02 Thread Harald Welte

Support setting TUN device IPv6 address + prefix

As we can now have PDP contexts with IPv6 user IP payload,
it is useful to extend the TUN related code to be able to
configure the tun device IPv6 address + prefix length

Change-Id: I899d21e52d02e0b8384af29ddd489ff19c8f2cf6
---
M ggsn/ggsn.c
M lib/tun.c
M lib/tun.h
3 files changed, 111 insertions(+), 17 deletions(-)


  git pull ssh://gerrit.osmocom.org:29418/openggsn refs/changes/08/3408/2

diff --git a/ggsn/ggsn.c b/ggsn/ggsn.c
index c1cea7e..a591321 100644
--- a/ggsn/ggsn.c
+++ b/ggsn/ggsn.c
@@ -69,7 +69,7 @@
 int maxfd = 0; /* For select()*/
 
 struct in_addr listen_;
-struct in_addr netaddr, destaddr, net; /* Network interface   */
+struct in46_addr netaddr, destaddr, net;   /* Network interface   */
 size_t prefixlen;
 struct in_addr dns1, dns2; /* PCO DNS address */
 char *ipup, *ipdown;   /* Filename of scripts */
@@ -409,16 +409,16 @@
/* net  */
/* Store net as in_addr net and mask*/
if (args_info.net_arg) {
-   struct in46_addr in46;
-   if (ippool_aton(&in46, &prefixlen, args_info.net_arg, 0)) {
+   if (ippool_aton(&net, &prefixlen, args_info.net_arg, 0)) {
SYS_ERR(DGGSN, LOGL_ERROR, 0,
"Invalid network address: %s!",
args_info.net_arg);
exit(1);
}
-   net.s_addr = in46.v4.s_addr;
-   netaddr.s_addr = htonl(ntohl(net.s_addr) + 1);
-   destaddr.s_addr = htonl(ntohl(net.s_addr) + 1);
+   /* default for network + destination address = net + 1 */
+   netaddr = net;
+   in46a_inc(&netaddr);
+   destaddr = netaddr;
} else {
SYS_ERR(DGGSN, LOGL_ERROR, 0,
"Network address must be specified: %s!",
@@ -575,7 +575,7 @@
maxfd = gsn->fd1u;
 
/* use GTP kernel module for data packet encapsulation */
-   if (gtp_kernel_init(gsn, &net, prefixlen, &args_info) < 0)
+   if (gtp_kernel_init(gsn, &net.v4, prefixlen, &args_info) < 0)
goto err;
 
gtp_set_cb_data_ind(gsn, encaps_tun);
@@ -600,7 +600,7 @@
}
 
DEBUGP(DGGSN, "Setting tun IP address\n");
-   if (tun_setaddr(tun, &netaddr, &destaddr, &prefixlen)) {
+   if (tun_setaddr(tun, &netaddr, &destaddr, prefixlen)) {
SYS_ERR(DGGSN, LOGL_ERROR, 0, "Failed to set tun IP address");
exit(1);
}
diff --git a/lib/tun.c b/lib/tun.c
index 8325f5d..7e0af12 100644
--- a/lib/tun.c
+++ b/lib/tun.c
@@ -1,6 +1,7 @@
 /* 
  * TUN interface functions.
  * Copyright (C) 2002, 2003, 2004 Mondru AB.
+ * Copyright (C) 2017 by Harald Welte 
  * 
  * The contents of this file may be used under the terms of the GNU
  * General Public License Version 2, provided that the above copyright
@@ -65,7 +66,12 @@
 #include "tun.h"
 #include "syserr.h"
 
+static int tun_setaddr4(struct tun_t *this, struct in_addr *addr,
+   struct in_addr *dstaddr, struct in_addr *netmask);
+
 #if defined(__linux__)
+
+#include 
 
 int tun_nlattr(struct nlmsghdr *n, int nsize, int type, void *d, int dlen)
 {
@@ -247,7 +253,7 @@
struct msghdr msg;
 
if (!this->addrs)   /* Use ioctl for first addr to make ping work */
-   return tun_setaddr(this, addr, dstaddr, netmask);
+   return tun_setaddr4(this, addr, dstaddr, netmask);
 
memset(&req, 0, sizeof(req));
req.n.nlmsg_len = NLMSG_LENGTH(sizeof(struct ifaddrmsg));
@@ -345,7 +351,7 @@
 
/* TODO: Is this needed on FreeBSD? */
if (!this->addrs)   /* Use ioctl for first addr to make ping work */
-   return tun_setaddr(this, addr, dstaddr, netmask);   /* TODO 
dstaddr */
+   return tun_setaddr4(this, addr, dstaddr, netmask);  /* TODO 
dstaddr */
 
memset(&areq, 0, sizeof(areq));
 
@@ -391,7 +397,7 @@
 #elif defined (__sun__)
 
if (!this->addrs)   /* Use ioctl for first addr to make ping work */
-   return tun_setaddr(this, addr, dstaddr, netmask);
+   return tun_setaddr4(this, addr, dstaddr, netmask);
 
SYS_ERR(DTUN, LOGL_ERROR, errno,
"Setting multiple addresses not possible on Solaris");
@@ -403,9 +409,8 @@
 
 }
 
-int tun_setaddr(struct tun_t *this,
-   struct in_addr *addr,
-   struct in_addr *dstaddr, struct in_addr *netmask)
+static int tun_setaddr4(struct tun_t *this, struct in_addr *addr,
+   struct in_addr *dstaddr, struct in_addr *netmask)
 {
struct ifreq ifr;
int fd;
@@ -498,13 +503,99 @@
tun_sifflags(this, IFF_UP | IFF_RUNNING);
 
 #if defined(__FreeBSD__) || defined (__APP

[PATCH] openggsn[master]: Support setting TUN device IPv6 address + prefix

2017-08-02 Thread Harald Welte

Review at  https://gerrit.osmocom.org/3408

Support setting TUN device IPv6 address + prefix

As we can now have PDP contexts with IPv6 user IP payload,
it is useful to extend the TUN related code to be able to
configure the tun device IPv6 address + prefix length

Change-Id: I899d21e52d02e0b8384af29ddd489ff19c8f2cf6
---
M ggsn/ggsn.c
M lib/tun.c
M lib/tun.h
3 files changed, 111 insertions(+), 17 deletions(-)


  git pull ssh://gerrit.osmocom.org:29418/openggsn refs/changes/08/3408/1

diff --git a/ggsn/ggsn.c b/ggsn/ggsn.c
index c1cea7e..a591321 100644
--- a/ggsn/ggsn.c
+++ b/ggsn/ggsn.c
@@ -69,7 +69,7 @@
 int maxfd = 0; /* For select()*/
 
 struct in_addr listen_;
-struct in_addr netaddr, destaddr, net; /* Network interface   */
+struct in46_addr netaddr, destaddr, net;   /* Network interface   */
 size_t prefixlen;
 struct in_addr dns1, dns2; /* PCO DNS address */
 char *ipup, *ipdown;   /* Filename of scripts */
@@ -409,16 +409,16 @@
/* net  */
/* Store net as in_addr net and mask*/
if (args_info.net_arg) {
-   struct in46_addr in46;
-   if (ippool_aton(&in46, &prefixlen, args_info.net_arg, 0)) {
+   if (ippool_aton(&net, &prefixlen, args_info.net_arg, 0)) {
SYS_ERR(DGGSN, LOGL_ERROR, 0,
"Invalid network address: %s!",
args_info.net_arg);
exit(1);
}
-   net.s_addr = in46.v4.s_addr;
-   netaddr.s_addr = htonl(ntohl(net.s_addr) + 1);
-   destaddr.s_addr = htonl(ntohl(net.s_addr) + 1);
+   /* default for network + destination address = net + 1 */
+   netaddr = net;
+   in46a_inc(&netaddr);
+   destaddr = netaddr;
} else {
SYS_ERR(DGGSN, LOGL_ERROR, 0,
"Network address must be specified: %s!",
@@ -575,7 +575,7 @@
maxfd = gsn->fd1u;
 
/* use GTP kernel module for data packet encapsulation */
-   if (gtp_kernel_init(gsn, &net, prefixlen, &args_info) < 0)
+   if (gtp_kernel_init(gsn, &net.v4, prefixlen, &args_info) < 0)
goto err;
 
gtp_set_cb_data_ind(gsn, encaps_tun);
@@ -600,7 +600,7 @@
}
 
DEBUGP(DGGSN, "Setting tun IP address\n");
-   if (tun_setaddr(tun, &netaddr, &destaddr, &prefixlen)) {
+   if (tun_setaddr(tun, &netaddr, &destaddr, prefixlen)) {
SYS_ERR(DGGSN, LOGL_ERROR, 0, "Failed to set tun IP address");
exit(1);
}
diff --git a/lib/tun.c b/lib/tun.c
index 8325f5d..7e0af12 100644
--- a/lib/tun.c
+++ b/lib/tun.c
@@ -1,6 +1,7 @@
 /* 
  * TUN interface functions.
  * Copyright (C) 2002, 2003, 2004 Mondru AB.
+ * Copyright (C) 2017 by Harald Welte 
  * 
  * The contents of this file may be used under the terms of the GNU
  * General Public License Version 2, provided that the above copyright
@@ -65,7 +66,12 @@
 #include "tun.h"
 #include "syserr.h"
 
+static int tun_setaddr4(struct tun_t *this, struct in_addr *addr,
+   struct in_addr *dstaddr, struct in_addr *netmask);
+
 #if defined(__linux__)
+
+#include 
 
 int tun_nlattr(struct nlmsghdr *n, int nsize, int type, void *d, int dlen)
 {
@@ -247,7 +253,7 @@
struct msghdr msg;
 
if (!this->addrs)   /* Use ioctl for first addr to make ping work */
-   return tun_setaddr(this, addr, dstaddr, netmask);
+   return tun_setaddr4(this, addr, dstaddr, netmask);
 
memset(&req, 0, sizeof(req));
req.n.nlmsg_len = NLMSG_LENGTH(sizeof(struct ifaddrmsg));
@@ -345,7 +351,7 @@
 
/* TODO: Is this needed on FreeBSD? */
if (!this->addrs)   /* Use ioctl for first addr to make ping work */
-   return tun_setaddr(this, addr, dstaddr, netmask);   /* TODO 
dstaddr */
+   return tun_setaddr4(this, addr, dstaddr, netmask);  /* TODO 
dstaddr */
 
memset(&areq, 0, sizeof(areq));
 
@@ -391,7 +397,7 @@
 #elif defined (__sun__)
 
if (!this->addrs)   /* Use ioctl for first addr to make ping work */
-   return tun_setaddr(this, addr, dstaddr, netmask);
+   return tun_setaddr4(this, addr, dstaddr, netmask);
 
SYS_ERR(DTUN, LOGL_ERROR, errno,
"Setting multiple addresses not possible on Solaris");
@@ -403,9 +409,8 @@
 
 }
 
-int tun_setaddr(struct tun_t *this,
-   struct in_addr *addr,
-   struct in_addr *dstaddr, struct in_addr *netmask)
+static int tun_setaddr4(struct tun_t *this, struct in_addr *addr,
+   struct in_addr *dstaddr, struct in_addr *netmask)
 {
struct ifreq ifr;
int fd;
@@ -498,13 +503,99 @@
tun_sifflags(this, IFF_UP | IFF_RUNNING);