osmith has submitted this change. ( 
https://gerrit.osmocom.org/c/libgtpnl/+/34734?usp=email )

Change subject: Use struct gtp_addr for ms_addr and sgsn_addr
......................................................................

Use struct gtp_addr for ms_addr and sgsn_addr

Prepare for IPv6 support by using a new struct for MS and SGSN
addresses, in which either an IPv4 or IPv6 can be stored.

Related: OS#6096
Change-Id: Ifc7e3b03a723fb544d1c7b789101102b2c27b60e
---
M src/gtp-genl.c
M src/gtp.c
M src/internal.h
3 files changed, 42 insertions(+), 17 deletions(-)

Approvals:
  pespin: Looks good to me, but someone else must approve
  laforge: Looks good to me, approved
  Jenkins Builder: Verified




diff --git a/src/gtp-genl.c b/src/gtp-genl.c
index 9c9e8d3..82ef8ab 100644
--- a/src/gtp-genl.c
+++ b/src/gtp-genl.c
@@ -48,10 +48,10 @@
        if (t->ifns >= 0)
                mnl_attr_put_u32(nlh, GTPA_NET_NS_FD, t->ifns);
        mnl_attr_put_u32(nlh, GTPA_LINK, t->ifidx);
-       if (t->sgsn_addr.s_addr)
-               mnl_attr_put_u32(nlh, GTPA_PEER_ADDRESS, t->sgsn_addr.s_addr);
-       if (t->ms_addr.s_addr)
-               mnl_attr_put_u32(nlh, GTPA_MS_ADDRESS, t->ms_addr.s_addr);
+       if (t->sgsn_addr.ip4.s_addr)
+               mnl_attr_put_u32(nlh, GTPA_PEER_ADDRESS, 
t->sgsn_addr.ip4.s_addr);
+       if (t->ms_addr.ip4.s_addr)
+               mnl_attr_put_u32(nlh, GTPA_MS_ADDRESS, t->ms_addr.ip4.s_addr);
        if (t->gtp_version == GTP_V0) {
                mnl_attr_put_u64(nlh, GTPA_TID, t->u.v0.tid);
                mnl_attr_put_u16(nlh, GTPA_FLOW, t->u.v0.flowid);
@@ -116,8 +116,8 @@
                        uint32_t o_tei;
                } v1;
        } u;
-       struct in_addr  sgsn_addr;
-       struct in_addr  ms_addr;
+       struct gtp_addr sgsn_addr;
+       struct gtp_addr ms_addr;
 };

 static int genl_gtp_validate_cb(const struct nlattr *attr, void *data)
@@ -167,11 +167,13 @@
        if (tb[GTPA_O_TEI])
                pdp.u.v1.o_tei = mnl_attr_get_u32(tb[GTPA_O_TEI]);
        if (tb[GTPA_PEER_ADDRESS]) {
-               pdp.sgsn_addr.s_addr =
+               pdp.sgsn_addr.family = AF_INET;
+               pdp.sgsn_addr.ip4.s_addr =
                        mnl_attr_get_u32(tb[GTPA_PEER_ADDRESS]);
        }
        if (tb[GTPA_MS_ADDRESS]) {
-               pdp.ms_addr.s_addr = mnl_attr_get_u32(tb[GTPA_MS_ADDRESS]);
+               pdp.ms_addr.family = AF_INET;
+               pdp.ms_addr.ip4.s_addr = mnl_attr_get_u32(tb[GTPA_MS_ADDRESS]);
        }
        if (tb[GTPA_VERSION]) {
                pdp.version = mnl_attr_get_u32(tb[GTPA_VERSION]);
@@ -179,15 +181,15 @@

        printf("version %u ", pdp.version);
        if (pdp.version == GTP_V0) {
-               inet_ntop(AF_INET, &pdp.ms_addr, buf, sizeof(buf));
+               inet_ntop(AF_INET, &pdp.ms_addr.ip4, buf, sizeof(buf));
                printf("tid %"PRIu64" ms_addr %s ",
                       pdp.u.v0.tid, buf);
        } else if (pdp.version == GTP_V1) {
-               inet_ntop(AF_INET, &pdp.ms_addr, buf, sizeof(buf));
+               inet_ntop(AF_INET, &pdp.ms_addr.ip4, buf, sizeof(buf));
                printf("tei %u/%u ms_addr %s ", pdp.u.v1.i_tei,
                       pdp.u.v1.o_tei, buf);
        }
-       inet_ntop(AF_INET, &pdp.sgsn_addr, buf, sizeof(buf));
+       inet_ntop(AF_INET, &pdp.sgsn_addr.ip4, buf, sizeof(buf));
        printf("sgsn_addr %s\n", buf);

        return MNL_CB_OK;
diff --git a/src/gtp.c b/src/gtp.c
index e65b0b6..4eadc29 100644
--- a/src/gtp.c
+++ b/src/gtp.c
@@ -60,13 +60,15 @@

 void gtp_tunnel_set_ms_ip4(struct gtp_tunnel *t, struct in_addr *ms_addr)
 {
-       t->ms_addr = *ms_addr;
+       t->ms_addr.family = AF_INET;
+       t->ms_addr.ip4 = *ms_addr;
 }
 EXPORT_SYMBOL(gtp_tunnel_set_ms_ip4);

 void gtp_tunnel_set_sgsn_ip4(struct gtp_tunnel *t, struct in_addr *sgsn_addr)
 {
-       t->sgsn_addr = *sgsn_addr;
+       t->sgsn_addr.family = AF_INET;
+       t->sgsn_addr.ip4 = *sgsn_addr;
 }
 EXPORT_SYMBOL(gtp_tunnel_set_sgsn_ip4);

@@ -114,13 +116,13 @@

 const struct in_addr *gtp_tunnel_get_ms_ip4(struct gtp_tunnel *t)
 {
-       return &t->ms_addr;
+       return &t->ms_addr.ip4;
 }
 EXPORT_SYMBOL(gtp_tunnel_get_ms_ip4);

 const struct in_addr *gtp_tunnel_get_sgsn_ip4(struct gtp_tunnel *t)
 {
-       return &t->sgsn_addr;
+       return &t->sgsn_addr.ip4;
 }
 EXPORT_SYMBOL(gtp_tunnel_get_sgsn_ip4);

diff --git a/src/internal.h b/src/internal.h
index 1754e3b..ce8a683 100644
--- a/src/internal.h
+++ b/src/internal.h
@@ -12,11 +12,19 @@
 #include <stdint.h>
 #include <netinet/in.h>

+struct gtp_addr {
+       sa_family_t family;
+       union {
+               struct in_addr ip4;
+               struct in6_addr ip6;
+       };
+};
+
 struct gtp_tunnel {
        int             ifns;
        uint32_t        ifidx;
-       struct in_addr  ms_addr;
-       struct in_addr  sgsn_addr;
+       struct gtp_addr ms_addr;
+       struct gtp_addr sgsn_addr;
        int             gtp_version;
        union {
                struct {

--
To view, visit https://gerrit.osmocom.org/c/libgtpnl/+/34734?usp=email
To unsubscribe, or for help writing mail filters, visit 
https://gerrit.osmocom.org/settings

Gerrit-Project: libgtpnl
Gerrit-Branch: master
Gerrit-Change-Id: Ifc7e3b03a723fb544d1c7b789101102b2c27b60e
Gerrit-Change-Number: 34734
Gerrit-PatchSet: 2
Gerrit-Owner: osmith <[email protected]>
Gerrit-Reviewer: Jenkins Builder
Gerrit-Reviewer: laforge <[email protected]>
Gerrit-Reviewer: osmith <[email protected]>
Gerrit-Reviewer: pespin <[email protected]>
Gerrit-MessageType: merged

Reply via email to