gtp: provide interface to set family

Kernel now supports for TID/I_TEI to be used in both IPv4 and IPv6 GTP
tunnels. This improves dualstack support for MS/UE so GTP traffic can
be identified with the same tunnel identifier.

Update gtp-tunnel to specify the family, since a tunnel is now
identified by the following tuple [ version, identifier, family ].

Change-Id: I584d3997ffb89cd430dfda9615a4ce0ce517ab2a
This commit is contained in:
Pablo Neira Ayuso 2024-01-31 19:03:13 +01:00 committed by Oliver Smith
parent 0e7a635481
commit ed42b8afa6
5 changed files with 24 additions and 2 deletions

View File

@ -11,6 +11,7 @@ void gtp_tunnel_free(struct gtp_tunnel *t);
void gtp_tunnel_set_ifns(struct gtp_tunnel *t, int ifns);
void gtp_tunnel_set_ifidx(struct gtp_tunnel *t, uint32_t ifidx);
void gtp_tunnel_set_family(struct gtp_tunnel *t, uint16_t family);
void gtp_tunnel_set_ms_ip4(struct gtp_tunnel *t, struct in_addr *ms_addr);
void gtp_tunnel_set_sgsn_ip4(struct gtp_tunnel *t, struct in_addr *sgsn_addr);
void gtp_tunnel_set_ms_ip6(struct gtp_tunnel *t, const struct in6_addr *ms_addr);

View File

@ -58,6 +58,12 @@ void gtp_tunnel_set_ifidx(struct gtp_tunnel *t, uint32_t ifidx)
}
EXPORT_SYMBOL(gtp_tunnel_set_ifidx);
void gtp_tunnel_set_family(struct gtp_tunnel *t, uint16_t family)
{
t->ms_addr.family = family;
}
EXPORT_SYMBOL(gtp_tunnel_set_family);
void gtp_tunnel_set_ms_ip4(struct gtp_tunnel *t, struct in_addr *ms_addr)
{
t->ms_addr.family = AF_INET;

View File

@ -43,3 +43,7 @@ LIBGTPNL_1.1 {
gtp_tunnel_set_ms_ip6;
gtp_tunnel_set_sgsn_ip6;
} LIBGTPNL_1.0;
LIBGTPNL_1.2 {
gtp_tunnel_set_family;
} LIBGTPNL_1.1;

View File

@ -75,6 +75,7 @@ static int setup_socket(struct gtp_server_sock *gtp_sock, int family)
{
int fd1 = socket(family, SOCK_DGRAM, 0);
int fd2 = socket(family, SOCK_DGRAM, 0);
int one = 1;
if (fd1 < 0 || fd2 < 0)
return -1;

View File

@ -131,8 +131,8 @@ del_tunnel(int argc, char *argv[], int genl_id, struct mnl_socket *nl)
struct gtp_tunnel *t;
uint32_t gtp_ifidx;
if (argc != 5) {
printf("%s del <gtp device> <version> <tid>\n",
if (argc != 6) {
printf("%s del <gtp device> <version> <tid> <family>\n",
argv[0]);
return EXIT_FAILURE;
}
@ -160,6 +160,16 @@ del_tunnel(int argc, char *argv[], int genl_id, struct mnl_socket *nl)
return EXIT_FAILURE;
}
if (strcmp(argv[5], "ip") == 0) {
gtp_tunnel_set_family(t, AF_INET);
} else if (strcmp(argv[5], "ip6") == 0) {
gtp_tunnel_set_family(t, AF_INET6);
} else {
fprintf(stderr, "wrong family %s, use ip or ip6\n", argv[5]);
gtp_tunnel_free(t);
return EXIT_FAILURE;
}
gtp_del_tunnel(genl_id, nl, t);
gtp_tunnel_free(t);