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 <laforge@gnumonks.org>
This commit is contained in:
Harald Welte 2017-03-15 18:03:42 +01:00
parent a7a4df366b
commit 3bf55c32be
3 changed files with 12 additions and 3 deletions

View File

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

View File

@ -6,6 +6,7 @@ global:
genl_lookup_family;
gtp_dev_create;
gtp_dev_create_sgsn;
gtp_dev_config;
gtp_dev_destroy;

View File

@ -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 <add|del> <device>\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);