lynxis lazus has uploaded this change for review. ( 
https://gerrit.osmocom.org/c/libosmocore/+/24589 )


Change subject: gprs_ns2_sns: replace ns2_sns_type with address family
......................................................................

gprs_ns2_sns: replace ns2_sns_type with address family

Reduces the code as the conversion between address family (bind)
and ns2_sns_type is not needed anymore.

Related: OS#5036
Change-Id: I1bcdd43af34c926d4b88491d00669422c299bef7
---
M src/gb/gprs_ns2_sns.c
1 file changed, 23 insertions(+), 28 deletions(-)



  git pull ssh://gerrit.osmocom.org:29418/libosmocore refs/changes/89/24589/1

diff --git a/src/gb/gprs_ns2_sns.c b/src/gb/gprs_ns2_sns.c
index 0badcee..ec4bd87 100644
--- a/src/gb/gprs_ns2_sns.c
+++ b/src/gb/gprs_ns2_sns.c
@@ -56,11 +56,6 @@

 #define S(x)   (1 << (x))

-enum ns2_sns_type {
-       IPv4,
-       IPv6,
-};
-
 enum ns2_sns_role {
        GPRS_SNS_ROLE_BSS,
        GPRS_SNS_ROLE_SGSN,
@@ -132,7 +127,7 @@
 struct ns2_sns_state {
        struct gprs_ns2_nse *nse;

-       enum ns2_sns_type ip;
+       int family;
        enum ns2_sns_role role;         /* local role: BSS or SGSN */

        /* holds the list of initial SNS endpoints */
@@ -665,14 +660,14 @@
        /* Upon receiving an SNS-ADD PDU, if the consequent number of IPv4 
endpoints
         * exceeds the number of IPv4 endpoints supported by the NSE, the NSE 
shall send
         * an SNS-ACK PDU with a cause code set to "Invalid number of IP4 
Endpoints". */
-       switch (gss->ip) {
-       case IPv4:
+       switch (gss->family) {
+       case AF_INET:
                if (gss->remote.num_ip4 >= gss->num_max_ip4_remote)
                        return -NS_CAUSE_INVAL_NR_NS_VC;
                /* TODO: log message duplicate */
                rc = add_ip4_elem(gss, &gss->remote, ip4);
                break;
-       case IPv6:
+       case AF_INET6:
                if (gss->remote.num_ip6 >= gss->num_max_ip6_remote)
                        return -NS_CAUSE_INVAL_NR_NS_VC;
                /* TODO: log message duplicate */
@@ -689,8 +684,8 @@
        /* Upon receiving an SNS-ADD PDU containing an already configured IP 
endpoint the
         * NSE shall send an SNS-ACK PDU with the cause code "Protocol error -
         * unspecified" */
-       switch (gss->ip) {
-       case IPv4:
+       switch (gss->family) {
+       case AF_INET:
                nsvc = nsvc_by_ip4_elem(nse, ip4);
                if (nsvc) {
                        /* the nsvc should be already in sync with the ip4 / 
ip6 elements */
@@ -700,7 +695,7 @@
                /* TODO: failure case */
                ns2_nsvc_create_ip4(fi, nse, ip4);
                break;
-       case IPv6:
+       case AF_INET6:
                nsvc = nsvc_by_ip6_elem(nse, ip6);
                if (nsvc) {
                        /* the nsvc should be already in sync with the ip4 / 
ip6 elements */
@@ -751,7 +746,7 @@
        }
 }

-static int ns2_sns_count_num_local_ep(struct osmo_fsm_inst *fi, enum 
ns2_sns_type stype)
+static int ns2_sns_count_num_local_ep(struct osmo_fsm_inst *fi, int ip_proto)
 {
        struct ns2_sns_state *gss = (struct ns2_sns_state *) fi->priv;
        struct ns2_sns_bind *sbind;
@@ -762,12 +757,12 @@
                if (!sa)
                        continue;

-               switch (stype) {
-               case IPv4:
+               switch (ip_proto) {
+               case AF_INET:
                        if (sa->u.sas.ss_family == AF_INET)
                                count++;
                        break;
-               case IPv6:
+               case AF_INET6:
                        if (sa->u.sas.ss_family == AF_INET6)
                                count++;
                        break;
@@ -805,8 +800,8 @@
                return;
        }

-       switch (gss->ip) {
-       case IPv4:
+       switch (gss->family) {
+       case AF_INET:
                ip4_elems = talloc_realloc(fi, gss->local.ip4, struct 
gprs_ns_ie_ip4_elem, count);
                if (!ip4_elems)
                        return;
@@ -840,7 +835,7 @@
                gss->local.num_ip4 = count;
                gss->num_max_nsvcs = OSMO_MAX(gss->num_max_ip4_remote * 
gss->local.num_ip4, 8);
                break;
-       case IPv6:
+       case AF_INET6:
                /* IPv6 */
                ip6_elems = talloc_realloc(fi, gss->local.ip6, struct 
gprs_ns_ie_ip6_elem, count);
                if (!ip6_elems)
@@ -959,13 +954,13 @@
                gss->N = 0;

        /* Transmit SNS-CONFIG */
-       switch (gss->ip) {
-       case IPv4:
+       switch (gss->family) {
+       case AF_INET:
                ns2_tx_sns_config(gss->sns_nsvc, true,
                                  gss->local.ip4, gss->local.num_ip4,
                                  NULL, 0);
                break;
-       case IPv6:
+       case AF_INET6:
                ns2_tx_sns_config(gss->sns_nsvc, true,
                                  NULL, 0,
                                  gss->local.ip6, gss->local.num_ip6);
@@ -1108,7 +1103,7 @@
         */

        trans_id = *TLVP_VAL(tp, NS_IE_TRANS_ID);
-       if (gss->ip == IPv4) {
+       if (gss->family == AF_INET) {
                if (!TLVP_PRESENT(tp, NS_IE_IPv4_LIST)) {
                        cause = NS_CAUSE_INVAL_NR_IPv4_EP;
                        ns2_tx_sns_ack(gss->sns_nsvc, trans_id, &cause, NULL, 
0, NULL, 0);
@@ -1172,7 +1167,7 @@
         * TODO: check if IPv4_LIST/IPv6_LIST and IP_ADDR is present at the 
same time
         */
        trans_id = *TLVP_VAL(tp, NS_IE_TRANS_ID);
-       if (gss->ip == IPv4) {
+       if (gss->family == AF_INET) {
                if (TLVP_PRESENT(tp, NS_IE_IPv4_LIST)) {
                        v4_list = (const struct gprs_ns_ie_ip4_elem *) 
TLVP_VAL(tp, NS_IE_IPv4_LIST);
                        num_v4 = TLVP_LEN(tp, NS_IE_IPv4_LIST) / 
sizeof(*v4_list);
@@ -2246,13 +2241,13 @@
                if (TLVP_PRES_LEN(tp, NS_IE_IPv6_EP_NR, 2))
                        gss->num_max_ip6_remote = tlvp_val16be(tp, 
NS_IE_IPv6_EP_NR);
                /* decide if we go for IPv4 or IPv6 */
-               if (gss->num_max_ip6_remote && ns2_sns_count_num_local_ep(fi, 
IPv6)) {
-                       gss->ip = IPv6;
+               if (gss->num_max_ip6_remote && ns2_sns_count_num_local_ep(fi, 
AF_INET6)) {
+                       gss->family = AF_INET6;
                        ns2_sns_compute_local_ep_from_binds(fi);
                        num_local_eps = gss->local.num_ip6;
                        num_remote_eps = gss->num_max_ip6_remote;
-               } else if (gss->num_max_ip4_remote && 
ns2_sns_count_num_local_ep(fi, IPv4)) {
-                       gss->ip = IPv4;
+               } else if (gss->num_max_ip4_remote && 
ns2_sns_count_num_local_ep(fi, AF_INET)) {
+                       gss->family = AF_INET;
                        ns2_sns_compute_local_ep_from_binds(fi);
                        num_local_eps = gss->local.num_ip4;
                        num_remote_eps = gss->num_max_ip4_remote;

--
To view, visit https://gerrit.osmocom.org/c/libosmocore/+/24589
To unsubscribe, or for help writing mail filters, visit 
https://gerrit.osmocom.org/settings

Gerrit-Project: libosmocore
Gerrit-Branch: master
Gerrit-Change-Id: I1bcdd43af34c926d4b88491d00669422c299bef7
Gerrit-Change-Number: 24589
Gerrit-PatchSet: 1
Gerrit-Owner: lynxis lazus <lyn...@fe80.eu>
Gerrit-MessageType: newchange

Reply via email to