From dea76a00691b85e91c04fb4d3aef3d8325e5fb9a Mon Sep 17 00:00:00 2001 From: Pablo Neira Ayuso Date: Sun, 23 Feb 2014 21:55:42 +0100 Subject: [PATCH] gtp: create socket from userspace and pass them as configuration openggsn already sets up the UDP sockets that we need for the control and user planes of GTP. Since we cannot bind two UDP sockets (one from userspace and another from the kernel) to the same port, change the current code to pass the socket descriptors that has been allocated by openggsn (or whatever daemon which uses the GTP kernel infrastructure). Two new attributes are added to set up the tunnel device: IFLA_GTP_FD0 (for GTP0) and IFLA_GTP_FD1 (for GTP1u), which specify the UDP socket created from userspace. Thus, the GTP kernel code only takes care of enabling the kernel UDP encapsulation routine. --- include/libgtpnl/gtpnl.h | 2 +- include/linux/gtp_nl.h | 3 ++- src/gtp-rtnl.c | 5 +++-- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/include/libgtpnl/gtpnl.h b/include/libgtpnl/gtpnl.h index 3c2c624..74fb8cf 100644 --- a/include/libgtpnl/gtpnl.h +++ b/include/libgtpnl/gtpnl.h @@ -14,7 +14,7 @@ int genl_socket_talk(struct mnl_socket *nl, struct nlmsghdr *nlh, uint32_t seq, void *data); int genl_lookup_family(struct mnl_socket *nl, const char *family); -int gtp_dev_create(const char *ifname); +int gtp_dev_create(const char *ifname, int fd0, int fd1); int gtp_dev_destroy(const char *ifname); struct gtp_tunnel; diff --git a/include/linux/gtp_nl.h b/include/linux/gtp_nl.h index 968824c..ff45fba 100644 --- a/include/linux/gtp_nl.h +++ b/include/linux/gtp_nl.h @@ -3,7 +3,8 @@ enum { IFLA_GTP_UNSPEC, - IFLA_GTP_LOCAL_ADDR_IPV4, + IFLA_GTP_FD0, + IFLA_GTP_FD1, IFLA_GTP_HASHSIZE, __IFLA_GTP_MAX, }; diff --git a/src/gtp-rtnl.c b/src/gtp-rtnl.c index 48dbdf0..d5af6fc 100644 --- a/src/gtp-rtnl.c +++ b/src/gtp-rtnl.c @@ -72,7 +72,7 @@ err: return -1; } -int gtp_dev_create(const char *ifname) +int gtp_dev_create(const char *ifname, int fd0, int fd1) { char buf[MNL_SOCKET_BUFFER_SIZE]; struct nlmsghdr *nlh; @@ -90,7 +90,8 @@ int gtp_dev_create(const char *ifname) nest = mnl_attr_nest_start(nlh, IFLA_LINKINFO); mnl_attr_put_str(nlh, IFLA_INFO_KIND, "gtp"); nest2 = mnl_attr_nest_start(nlh, IFLA_INFO_DATA); - mnl_attr_put_u32(nlh, IFLA_GTP_LOCAL_ADDR_IPV4, 0); + mnl_attr_put_u32(nlh, IFLA_GTP_FD0, fd0); + mnl_attr_put_u32(nlh, IFLA_GTP_FD1, fd1); mnl_attr_put_u32(nlh, IFLA_GTP_HASHSIZE, 131072); mnl_attr_nest_end(nlh, nest2); mnl_attr_nest_end(nlh, nest);