From 3bf55c32bedcb332bcf4baa05f8dbdb5ccbd7316 Mon Sep 17 00:00:00 2001 From: Harald Welte Date: Wed, 15 Mar 2017 18:03:42 +0100 Subject: [PATCH] Add support for SGSN role via IFLA_GTP_ROLE This patch corresponds to a Linux kernel patch extending the kernel GTP to also cover the SGSN role, not just the GGSN role. In order to keep the API/behavior compatible, gtp_dev_create() will continue to create GGSN-side tunnels, while a new gtp_dev_create_sgsn() is introduced to create SGSN-side tunnels. Signed-off-by: Harald Welte --- src/gtp-rtnl.c | 2 ++ src/libgtpnl.map | 1 + tools/gtp-link.c | 12 +++++++++--- 3 files changed, 12 insertions(+), 3 deletions(-) diff --git a/src/gtp-rtnl.c b/src/gtp-rtnl.c index 256de43..1dfd125 100644 --- a/src/gtp-rtnl.c +++ b/src/gtp-rtnl.c @@ -130,6 +130,8 @@ static int _gtp_dev_create(int dest_ns, const char *gtp_ifname, int fd0, 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_PDP_HASHSIZE, 131072); + if (role != GTP_ROLE_GGSN) + mnl_attr_put_u32(nlh, IFLA_GTP_ROLE, role); mnl_attr_nest_end(nlh, nest2); mnl_attr_nest_end(nlh, nest); diff --git a/src/libgtpnl.map b/src/libgtpnl.map index 9ca83c7..9ce465d 100644 --- a/src/libgtpnl.map +++ b/src/libgtpnl.map @@ -6,6 +6,7 @@ global: genl_lookup_family; gtp_dev_create; + gtp_dev_create_sgsn; gtp_dev_config; gtp_dev_destroy; diff --git a/tools/gtp-link.c b/tools/gtp-link.c index 97dfa45..8367c6e 100644 --- a/tools/gtp-link.c +++ b/tools/gtp-link.c @@ -43,9 +43,9 @@ int main(int argc, char *argv[]) { char buf[MNL_SOCKET_BUFFER_SIZE]; - int ret; + int ret, sgsn_mode = 0; - if (argc != 3) { + if (argc < 3) { printf("Usage: %s \n", argv[0]); exit(EXIT_FAILURE); } @@ -58,6 +58,9 @@ int main(int argc, char *argv[]) return 0; } + if (argc > 3 && !strcmp(argv[3], "--sgsn")) + sgsn_mode = 1; + int fd1 = socket(AF_INET, SOCK_DGRAM, 0); int fd2 = socket(AF_INET, SOCK_DGRAM, 0); struct sockaddr_in sockaddr_fd1 = { @@ -86,7 +89,10 @@ int main(int argc, char *argv[]) exit(EXIT_FAILURE); } - ret = gtp_dev_create(-1, argv[2], fd1, fd2); + if (sgsn_mode) + ret = gtp_dev_create_sgsn(-1, argv[2], fd1, fd2); + else + ret = gtp_dev_create(-1, argv[2], fd1, fd2); if (ret < 0) { perror("cannot create GTP device\n"); exit(EXIT_FAILURE);