<p>laforge has uploaded this change for <strong>review</strong>.</p><p><a href="https://gerrit.osmocom.org/c/libosmocore/+/23412">View Change</a></p><pre style="font-family: monospace,monospace; white-space: pre-wrap;">gprs_ns2_sns: Implement checks during processing of inbound SNS-SIZE<br><br>As per 3GPP TS 48.016 section 6.2.4.1, we need to perform some<br>consistency checks during the SNS-SIZE procedure.  Let's implement them.<br><br>Change-Id: I1638f04ba45fef3ba0b237948dff6022267141fb<br>Related: OS#3373<br>---<br>M src/gb/gprs_ns2_sns.c<br>1 file changed, 59 insertions(+), 1 deletion(-)<br><br></pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;">git pull ssh://gerrit.osmocom.org:29418/libosmocore refs/changes/12/23412/1</pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;"><span>diff --git a/src/gb/gprs_ns2_sns.c b/src/gb/gprs_ns2_sns.c</span><br><span>index 49768c1..2fbfb54 100644</span><br><span>--- a/src/gb/gprs_ns2_sns.c</span><br><span>+++ b/src/gb/gprs_ns2_sns.c</span><br><span>@@ -749,6 +749,31 @@</span><br><span>       }</span><br><span> }</span><br><span> </span><br><span style="color: hsl(120, 100%, 40%);">+static int ns2_sns_count_num_local_ep(struct osmo_fsm_inst *fi, enum ns2_sns_type stype)</span><br><span style="color: hsl(120, 100%, 40%);">+{</span><br><span style="color: hsl(120, 100%, 40%);">+       struct ns2_sns_state *gss = (struct ns2_sns_state *) fi->priv;</span><br><span style="color: hsl(120, 100%, 40%);">+     struct ns2_sns_bind *sbind;</span><br><span style="color: hsl(120, 100%, 40%);">+   int count = 0;</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+      llist_for_each_entry(sbind, &gss->binds, list) {</span><br><span style="color: hsl(120, 100%, 40%);">+               const struct osmo_sockaddr *sa = gprs_ns2_ip_bind_sockaddr(sbind->bind);</span><br><span style="color: hsl(120, 100%, 40%);">+           if (!sa)</span><br><span style="color: hsl(120, 100%, 40%);">+                      continue;</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+           switch (stype) {</span><br><span style="color: hsl(120, 100%, 40%);">+              case IPv4:</span><br><span style="color: hsl(120, 100%, 40%);">+                    if (sa->u.sas.ss_family == AF_INET)</span><br><span style="color: hsl(120, 100%, 40%);">+                                count++;</span><br><span style="color: hsl(120, 100%, 40%);">+                      break;</span><br><span style="color: hsl(120, 100%, 40%);">+                case IPv6:</span><br><span style="color: hsl(120, 100%, 40%);">+                    if (sa->u.sas.ss_family == AF_INET6)</span><br><span style="color: hsl(120, 100%, 40%);">+                               count++;</span><br><span style="color: hsl(120, 100%, 40%);">+                      break;</span><br><span style="color: hsl(120, 100%, 40%);">+                }</span><br><span style="color: hsl(120, 100%, 40%);">+     }</span><br><span style="color: hsl(120, 100%, 40%);">+     return count;</span><br><span style="color: hsl(120, 100%, 40%);">+}</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span> static void ns2_sns_compute_local_ep_from_binds(struct osmo_fsm_inst *fi)</span><br><span> {</span><br><span>         struct ns2_sns_state *gss = (struct ns2_sns_state *) fi->priv;</span><br><span>@@ -2018,7 +2043,6 @@</span><br><span>    struct ns2_sns_state *gss = (struct ns2_sns_state *) fi->priv;</span><br><span>    OSMO_ASSERT(gss->role == GPRS_SNS_ROLE_SGSN);</span><br><span> </span><br><span style="color: hsl(0, 100%, 40%);">-    ns2_sns_compute_local_ep_from_binds(fi);</span><br><span>     /* transmit SGSN-oriented SNS-CONFIG */</span><br><span>      ns2_tx_sns_config(gss->sns_nsvc, true, gss->ip4_local, gss->num_ip4_local,</span><br><span>                    gss->ip6_local, gss->num_ip6_local);</span><br><span>@@ -2123,6 +2147,7 @@</span><br><span> {</span><br><span>    struct ns2_sns_state *gss = (struct ns2_sns_state *) fi->priv;</span><br><span>    struct tlv_parsed *tp = NULL;</span><br><span style="color: hsl(120, 100%, 40%);">+ size_t num_local_eps, num_remote_eps;</span><br><span>        uint8_t flag;</span><br><span>        uint8_t cause;</span><br><span> </span><br><span>@@ -2144,6 +2169,39 @@</span><br><span>                  ns2_tx_sns_size_ack(gss->sns_nsvc, &cause);</span><br><span>                   break;</span><br><span>               }</span><br><span style="color: hsl(120, 100%, 40%);">+             if (TLVP_PRES_LEN(tp, NS_IE_IPv4_EP_NR, 2))</span><br><span style="color: hsl(120, 100%, 40%);">+                   gss->num_max_ip4_remote = tlvp_val16be(tp, NS_IE_IPv4_EP_NR);</span><br><span style="color: hsl(120, 100%, 40%);">+              if (TLVP_PRES_LEN(tp, NS_IE_IPv6_EP_NR, 2))</span><br><span style="color: hsl(120, 100%, 40%);">+                   gss->num_max_ip6_remote = tlvp_val16be(tp, NS_IE_IPv6_EP_NR);</span><br><span style="color: hsl(120, 100%, 40%);">+              /* decide if we go for IPv4 or IPv6 */</span><br><span style="color: hsl(120, 100%, 40%);">+                if (gss->num_max_ip6_remote && ns2_sns_count_num_local_ep(fi, IPv6)) {</span><br><span style="color: hsl(120, 100%, 40%);">+                     gss->ip = IPv6;</span><br><span style="color: hsl(120, 100%, 40%);">+                    num_local_eps = gss->num_ip6_local;</span><br><span style="color: hsl(120, 100%, 40%);">+                        num_remote_eps = gss->num_max_ip4_remote;</span><br><span style="color: hsl(120, 100%, 40%);">+          } else if (gss->num_max_ip4_remote && ns2_sns_count_num_local_ep(fi, IPv4)) {</span><br><span style="color: hsl(120, 100%, 40%);">+                      gss->ip = IPv4;</span><br><span style="color: hsl(120, 100%, 40%);">+                    num_local_eps = gss->num_ip4_local;</span><br><span style="color: hsl(120, 100%, 40%);">+                        num_remote_eps = gss->num_max_ip4_remote;</span><br><span style="color: hsl(120, 100%, 40%);">+          } else {</span><br><span style="color: hsl(120, 100%, 40%);">+                      if (gss->num_ip4_local && !gss->num_max_ip4_remote)</span><br><span style="color: hsl(120, 100%, 40%);">+                             cause = NS_CAUSE_INVAL_NR_IPv4_EP;</span><br><span style="color: hsl(120, 100%, 40%);">+                    else</span><br><span style="color: hsl(120, 100%, 40%);">+                          cause = NS_CAUSE_INVAL_NR_IPv6_EP;</span><br><span style="color: hsl(120, 100%, 40%);">+                    ns2_tx_sns_size_ack(gss->sns_nsvc, &cause);</span><br><span style="color: hsl(120, 100%, 40%);">+                    break;</span><br><span style="color: hsl(120, 100%, 40%);">+                }</span><br><span style="color: hsl(120, 100%, 40%);">+             ns2_sns_compute_local_ep_from_binds(fi);</span><br><span style="color: hsl(120, 100%, 40%);">+              /* ensure number of NS-VCs is sufficient for full mesh */</span><br><span style="color: hsl(120, 100%, 40%);">+             gss->num_max_nsvcs = tlvp_val16be(tp, NS_IE_MAX_NR_NSVC);</span><br><span style="color: hsl(120, 100%, 40%);">+          if (gss->num_max_nsvcs < num_remote_eps * num_local_eps) {</span><br><span style="color: hsl(120, 100%, 40%);">+                      LOGPFSML(fi, LOGL_ERROR, "%zu local and %zu remote EPs, requires %zu NS-VC, "</span><br><span style="color: hsl(120, 100%, 40%);">+                                "but BSS supports only %zu maximum NS-VCs\n", num_local_eps,</span><br><span style="color: hsl(120, 100%, 40%);">+                                num_remote_eps, num_local_eps * num_remote_eps, gss->num_max_nsvcs);</span><br><span style="color: hsl(120, 100%, 40%);">+                      cause = NS_CAUSE_INVAL_NR_NS_VC;</span><br><span style="color: hsl(120, 100%, 40%);">+                      ns2_tx_sns_size_ack(gss->sns_nsvc, &cause);</span><br><span style="color: hsl(120, 100%, 40%);">+                    break;</span><br><span style="color: hsl(120, 100%, 40%);">+                }</span><br><span style="color: hsl(120, 100%, 40%);">+             /* perform state reset, if requested */</span><br><span>              flag = *TLVP_VAL(tp, NS_IE_RESET_FLAG);</span><br><span>              if (flag & 1) {</span><br><span>                  struct gprs_ns2_vc *nsvc, *nsvc2;</span><br><span></span><br></pre><p>To view, visit <a href="https://gerrit.osmocom.org/c/libosmocore/+/23412">change 23412</a>. To unsubscribe, or for help writing mail filters, visit <a href="https://gerrit.osmocom.org/settings">settings</a>.</p><div itemscope itemtype="http://schema.org/EmailMessage"><div itemscope itemprop="action" itemtype="http://schema.org/ViewAction"><link itemprop="url" href="https://gerrit.osmocom.org/c/libosmocore/+/23412"/><meta itemprop="name" content="View Change"/></div></div>

<div style="display:none"> Gerrit-Project: libosmocore </div>
<div style="display:none"> Gerrit-Branch: master </div>
<div style="display:none"> Gerrit-Change-Id: I1638f04ba45fef3ba0b237948dff6022267141fb </div>
<div style="display:none"> Gerrit-Change-Number: 23412 </div>
<div style="display:none"> Gerrit-PatchSet: 1 </div>
<div style="display:none"> Gerrit-Owner: laforge <laforge@osmocom.org> </div>
<div style="display:none"> Gerrit-MessageType: newchange </div>