gtp-rtnl: and netns support

Signed-off-by: Andreas Schultz <aschultz@tpip.net>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
diff --git a/src/gtp-genl.c b/src/gtp-genl.c
index c1f60ab..bffa7a5 100644
--- a/src/gtp-genl.c
+++ b/src/gtp-genl.c
@@ -44,6 +44,8 @@
 static void gtp_build_payload(struct nlmsghdr *nlh, struct gtp_tunnel *t)
 {
 	mnl_attr_put_u32(nlh, GTPA_VERSION, t->gtp_version);
+	if (t->ifns >= 0)
+		mnl_attr_put_u32(nlh, GTPA_NET_NS_FD, t->ifns);
 	mnl_attr_put_u32(nlh, GTPA_LINK, t->ifidx);
 	mnl_attr_put_u32(nlh, GTPA_SGSN_ADDRESS, t->sgsn_addr.s_addr);
 	mnl_attr_put_u32(nlh, GTPA_MS_ADDRESS, t->ms_addr.s_addr);
diff --git a/src/gtp-rtnl.c b/src/gtp-rtnl.c
index 22b9430..76e2021 100644
--- a/src/gtp-rtnl.c
+++ b/src/gtp-rtnl.c
@@ -104,7 +104,7 @@
 	return ret;
 }
 
-int gtp_dev_create(const char *gtp_ifname, const char *real_ifname,
+int gtp_dev_create(int dest_ns, const char *gtp_ifname, const char *real_ifname,
 		   int fd0, int fd1)
 {
 	char buf[MNL_SOCKET_BUFFER_SIZE];
@@ -120,6 +120,8 @@
 	ifm->ifi_change |= IFF_UP;
 	ifm->ifi_flags |= IFF_UP;
 
+	if (dest_ns >= 0)
+		mnl_attr_put_u32(nlh, IFLA_NET_NS_FD, dest_ns);
 	mnl_attr_put_u32(nlh, IFLA_LINK, if_nametoindex(real_ifname));
 	mnl_attr_put_str(nlh, IFLA_IFNAME, gtp_ifname);
 	nest = mnl_attr_nest_start(nlh, IFLA_LINKINFO);
diff --git a/src/gtp.c b/src/gtp.c
index 4534091..6e3d473 100644
--- a/src/gtp.c
+++ b/src/gtp.c
@@ -39,6 +39,12 @@
 }
 EXPORT_SYMBOL(gtp_tunnel_free);
 
+void gtp_tunnel_set_ifns(struct gtp_tunnel *t, int ifns)
+{
+	t->ifns = ifns;
+}
+EXPORT_SYMBOL(gtp_tunnel_set_ifns);
+
 void gtp_tunnel_set_ifidx(struct gtp_tunnel *t, uint32_t ifidx)
 {
 	t->ifidx = ifidx;
@@ -75,6 +81,12 @@
 }
 EXPORT_SYMBOL(gtp_tunnel_set_flowid);
 
+const int gtp_tunnel_get_ifns(struct gtp_tunnel *t)
+{
+	return t->ifns;
+}
+EXPORT_SYMBOL(gtp_tunnel_get_ifns);
+
 const uint32_t gtp_tunnel_get_ifidx(struct gtp_tunnel *t)
 {
 	return t->ifidx;
diff --git a/src/internal.h b/src/internal.h
index 75b3954..68f0135 100644
--- a/src/internal.h
+++ b/src/internal.h
@@ -13,6 +13,7 @@
 #include <netinet/in.h>
 
 struct gtp_tunnel {
+	int             ifns;
 	uint32_t	ifidx;
 	struct in_addr	ms_addr;
 	struct in_addr	sgsn_addr;
diff --git a/src/libgtpnl.map b/src/libgtpnl.map
index 6e69ef8..2368467 100644
--- a/src/libgtpnl.map
+++ b/src/libgtpnl.map
@@ -15,12 +15,14 @@
 
   gtp_tunnel_alloc;
   gtp_tunnel_free;
+  gtp_tunnel_set_ifns;
   gtp_tunnel_set_ifidx;
   gtp_tunnel_set_ms_ip4;
   gtp_tunnel_set_sgsn_ip4;
   gtp_tunnel_set_version;
   gtp_tunnel_set_tid;
   gtp_tunnel_set_flowid;
+  gtp_tunnel_get_ifns;
   gtp_tunnel_get_ifidx;
   gtp_tunnel_get_ms_ip4;
   gtp_tunnel_get_sgsn_ip4;