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.
This commit is contained in:
Pablo Neira Ayuso 2014-02-23 21:55:42 +01:00 committed by Pablo Neira Ayuso
parent 41ff538fb4
commit dea76a0069
3 changed files with 6 additions and 4 deletions

View File

@ -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;

View File

@ -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,
};

View File

@ -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);