osmith has uploaded this change for review.

View Change

tools: gtp-tunnel: add IPv6 support

This breaks backward compatibility, but this tool is intended for
testing purpose.

Change-Id: Ifdc104b158afa6343e3aa6142ffa9591db209c4f
---
M tools/gtp-tunnel.c
1 file changed, 61 insertions(+), 13 deletions(-)

git pull ssh://gerrit.osmocom.org:29418/libgtpnl refs/changes/37/34737/1
diff --git a/tools/gtp-tunnel.c b/tools/gtp-tunnel.c
index 1868097..3f5de5f 100644
--- a/tools/gtp-tunnel.c
+++ b/tools/gtp-tunnel.c
@@ -43,22 +43,29 @@

static void add_usage(const char *name)
{
- printf("%s add <gtp device> <v0> <tid> <ms-addr> <sgsn-addr>\n",
+ printf("%s add <gtp device> <v0> <tid> <family> <ms-addr> <sgsn-addr>\n",
name);
- printf("%s add <gtp device> <v1> <i_tei> <o_tei> <ms-addr> <sgsn-addr>\n",
+ printf("%s add <gtp device> <v1> <i_tei> <o_tei> <family> <ms-addr> <sgsn-addr>\n",
name);
}

static int
add_tunnel(int argc, char *argv[], int genl_id, struct mnl_socket *nl)
{
+ union {
+ struct in_addr addr;
+ struct in6_addr addr6;
+ } ms;
+ union {
+ struct in_addr addr;
+ struct in6_addr addr6;
+ } sgsn;
struct gtp_tunnel *t;
- uint32_t gtp_ifidx;
- struct in_addr ms, sgsn;
uint32_t gtp_version;
- int optidx;
+ uint32_t gtp_ifidx;
+ int optidx, family;

- if (argc < 7 || argc > 8) {
+ if (argc < 8 || argc > 9) {
add_usage(argv[0]);
return EXIT_FAILURE;
}
@@ -95,17 +102,46 @@
gtp_tunnel_set_o_tei(t, atoi(argv[optidx++]));
}

- if (inet_aton(argv[optidx++], &ms) < 0) {
- perror("bad address for ms");
- exit(EXIT_FAILURE);
+ if (!strcmp(argv[optidx], "ip")) {
+ family = AF_INET;
+ } else if (!strcmp(argv[optidx], "ip6")) {
+ family = AF_INET6;
+ } else {
+ fprintf(stderr, "wrong family `%s', expecting `ip' or `ip6'\n", argv[optidx]);
+ return EXIT_FAILURE;
}
- gtp_tunnel_set_ms_ip4(t, &ms);

- if (inet_aton(argv[optidx++], &sgsn) < 0) {
- perror("bad address for sgsn");
+ gtp_tunnel_set_family(t, family);
+
+ optidx++;
+
+ if (inet_pton(family, argv[optidx++], &ms) <= 0) {
+ fprintf(stderr, "bad address for ms\n");
exit(EXIT_FAILURE);
}
- gtp_tunnel_set_sgsn_ip4(t, &sgsn);
+
+ switch (family) {
+ case AF_INET:
+ gtp_tunnel_set_ms_ip4(t, &ms.addr);
+ break;
+ case AF_INET6:
+ gtp_tunnel_set_ms_ip6(t, &ms.addr6);
+ break;
+ }
+
+ if (inet_pton(family, argv[optidx++], &sgsn) <= 0) {
+ fprintf(stderr, "bad address for sgsn\n");
+ exit(EXIT_FAILURE);
+ }
+
+ switch (family) {
+ case AF_INET:
+ gtp_tunnel_set_sgsn_ip4(t, &sgsn.addr);
+ break;
+ case AF_INET6:
+ gtp_tunnel_set_sgsn_ip6(t, &sgsn.addr6);
+ break;
+ }

gtp_add_tunnel(genl_id, nl, t);


To view, visit change 34737. To unsubscribe, or for help writing mail filters, visit settings.

Gerrit-Project: libgtpnl
Gerrit-Branch: master
Gerrit-Change-Id: Ifdc104b158afa6343e3aa6142ffa9591db209c4f
Gerrit-Change-Number: 34737
Gerrit-PatchSet: 1
Gerrit-Owner: osmith <osmith@sysmocom.de>
Gerrit-MessageType: newchange