<p>Harald Welte <strong>merged</strong> this change.</p><p><a href="https://gerrit.osmocom.org/13291">View Change</a></p><div style="white-space:pre-wrap">Approvals:
  Jenkins Builder: Verified
  Harald Welte: Looks good to me, approved

</div><pre style="font-family: monospace,monospace; white-space: pre-wrap;">gprs_ns: Don't use initial IP/port for anything but SNS<br><br>Section 6.2.1 of 3GPP TS 48.016 states:<br>> A pre-configured endpoint shall not be used for NSE data or signalling<br>> traffic (with the exception of Size and Configuration procedures) unless<br>> it is configured by the SGSN using the auto-configuration procedures.<br><br>However, in the current SNS implementation, the initial IP/Port over<br>which we perform the SNS-SIZE + SNS-CONFIG are treated as one of the<br>normal NS-VCs. Specifically, we also perform the NS-ALIVE procedure on<br>it, which is clearly wrong.<br><br>Let's explicitly create the "initial" NS-VC with data and signalling<br>weight of 0, and ensure we never start the alive timer or send any<br>non-SNS PDUs on this connection as long as SNS was not used to change<br>either of the two weights to non-zero.<br><br>While at it, also safeguard against processing any incoming non-SNS<br>messages on such a all-zero-weight connection.<br><br>Change-Id: I16a91a07e5914d123b2ea2f8413b94e7cd518628<br>Closes: OS#3844<br>---<br>M src/gb/gprs_ns.c<br>1 file changed, 55 insertions(+), 2 deletions(-)<br><br></pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;"><span>diff --git a/src/gb/gprs_ns.c b/src/gb/gprs_ns.c</span><br><span>index 93c219c..8c3b0fa 100644</span><br><span>--- a/src/gb/gprs_ns.c</span><br><span>+++ b/src/gb/gprs_ns.c</span><br><span>@@ -195,6 +195,14 @@</span><br><span>                   LOGP(DNS, LOGL_ERROR, "TX failed (%d) to peer %s\n",  \</span><br><span>                            rc, gprs_ns_ll_str(nsvc));</span><br><span> </span><br><span style="color: hsl(120, 100%, 40%);">+static bool nsvc_is_not_used(const struct gprs_nsvc *nsvc)</span><br><span style="color: hsl(120, 100%, 40%);">+{</span><br><span style="color: hsl(120, 100%, 40%);">+ if (nsvc->data_weight == 0 && nsvc->sig_weight == 0)</span><br><span style="color: hsl(120, 100%, 40%);">+            return true;</span><br><span style="color: hsl(120, 100%, 40%);">+  else</span><br><span style="color: hsl(120, 100%, 40%);">+          return false;</span><br><span style="color: hsl(120, 100%, 40%);">+}</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span> struct msgb *gprs_ns_msgb_alloc(void)</span><br><span> {</span><br><span>     struct msgb *msg = msgb_alloc_headroom(NS_ALLOC_SIZE, NS_ALLOC_HEADROOM,</span><br><span>@@ -444,12 +452,40 @@</span><br><span> static int nsip_sendmsg(struct gprs_nsvc *nsvc, struct msgb *msg);</span><br><span> extern int grps_ns_frgre_sendmsg(struct gprs_nsvc *nsvc, struct msgb *msg);</span><br><span> </span><br><span style="color: hsl(120, 100%, 40%);">+static bool ns_is_sns(uint8_t pdu_type)</span><br><span style="color: hsl(120, 100%, 40%);">+{</span><br><span style="color: hsl(120, 100%, 40%);">+ switch (pdu_type) {</span><br><span style="color: hsl(120, 100%, 40%);">+   case SNS_PDUT_CONFIG:</span><br><span style="color: hsl(120, 100%, 40%);">+ case SNS_PDUT_ACK:</span><br><span style="color: hsl(120, 100%, 40%);">+    case SNS_PDUT_ADD:</span><br><span style="color: hsl(120, 100%, 40%);">+    case SNS_PDUT_CHANGE_WEIGHT:</span><br><span style="color: hsl(120, 100%, 40%);">+  case SNS_PDUT_DELETE:</span><br><span style="color: hsl(120, 100%, 40%);">+ case SNS_PDUT_CONFIG_ACK:</span><br><span style="color: hsl(120, 100%, 40%);">+     case SNS_PDUT_SIZE:</span><br><span style="color: hsl(120, 100%, 40%);">+   case SNS_PDUT_SIZE_ACK:</span><br><span style="color: hsl(120, 100%, 40%);">+               return true;</span><br><span style="color: hsl(120, 100%, 40%);">+  default:</span><br><span style="color: hsl(120, 100%, 40%);">+              return false;</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%);">+</span><br><span> static int gprs_ns_tx(struct gprs_nsvc *nsvc, struct msgb *msg)</span><br><span> {</span><br><span style="color: hsl(120, 100%, 40%);">+        struct gprs_ns_hdr *nsh = (struct gprs_ns_hdr *) msg->l2h;</span><br><span>        int ret;</span><br><span> </span><br><span>         log_set_context(LOG_CTX_GB_NSVC, nsvc);</span><br><span> </span><br><span style="color: hsl(120, 100%, 40%);">+   /* A pre-configured endpoint shall not be used for NSE data or signalling</span><br><span style="color: hsl(120, 100%, 40%);">+      * traffic (with the exception of Size and Configuration procedures) unless it</span><br><span style="color: hsl(120, 100%, 40%);">+         * is configured by the SGSN using the auto-configuration procedures. */</span><br><span style="color: hsl(120, 100%, 40%);">+      if (nsvc_is_not_used(nsvc) && !ns_is_sns(nsh->pdu_type) && nsh->pdu_type != NS_PDUT_STATUS) {</span><br><span style="color: hsl(120, 100%, 40%);">+           LOGP(DNS, LOGL_NOTICE, "Not transmitting %s on unused/pre-configured endpoint\n",</span><br><span style="color: hsl(120, 100%, 40%);">+                   get_value_string(gprs_ns_pdu_strings, nsh->pdu_type));</span><br><span style="color: hsl(120, 100%, 40%);">+             msgb_free(msg);</span><br><span style="color: hsl(120, 100%, 40%);">+               return -EINVAL;</span><br><span style="color: hsl(120, 100%, 40%);">+       }</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span>  /* Increment number of Uplink bytes */</span><br><span>       rate_ctr_inc(&nsvc->ctrg->ctr[NS_CTR_PKTS_OUT]);</span><br><span>   rate_ctr_add(&nsvc->ctrg->ctr[NS_CTR_BYTES_OUT], msgb_l2len(msg));</span><br><span>@@ -1690,6 +1726,13 @@</span><br><span>        rate_ctr_inc(&(*nsvc)->ctrg->ctr[NS_CTR_PKTS_IN]);</span><br><span>         rate_ctr_add(&(*nsvc)->ctrg->ctr[NS_CTR_BYTES_IN], msgb_l2len(msg));</span><br><span> </span><br><span style="color: hsl(120, 100%, 40%);">+    if (nsvc_is_not_used(*nsvc) && !ns_is_sns(nsh->pdu_type) && nsh->pdu_type != NS_PDUT_STATUS) {</span><br><span style="color: hsl(120, 100%, 40%);">+          LOGP(DNS, LOGL_NOTICE, "NSEI=%u Rx %s on unused/pre-configured endpoint, discarding\n",</span><br><span style="color: hsl(120, 100%, 40%);">+                     (*nsvc)->nsei, get_value_string(gprs_ns_pdu_strings, nsh->pdu_type));</span><br><span style="color: hsl(120, 100%, 40%);">+           gprs_ns_tx_status(*nsvc, NS_CAUSE_PROTO_ERR_UNSPEC, 0, msg);</span><br><span style="color: hsl(120, 100%, 40%);">+          return 0;</span><br><span style="color: hsl(120, 100%, 40%);">+     }</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span>  switch (nsh->pdu_type) {</span><br><span>  case NS_PDUT_ALIVE:</span><br><span>          /* If we're dead and blocked and suddenly receive a</span><br><span>@@ -2116,8 +2159,14 @@</span><br><span>      * require some massive code and API changes compared to existing libosmogb,</span><br><span>          * so let's keep the old logic. */</span><br><span>       nsvc = gprs_nsvc_by_rem_addr(nsi, dest);</span><br><span style="color: hsl(0, 100%, 40%);">-        if (!nsvc)</span><br><span style="color: hsl(0, 100%, 40%);">-              nsvc = gprs_nsvc_create(nsi, nsvci);</span><br><span style="color: hsl(120, 100%, 40%);">+  if (!nsvc) {</span><br><span style="color: hsl(120, 100%, 40%);">+          /* create NSVC with 0 data + signalling weight. This is illegal in SNS</span><br><span style="color: hsl(120, 100%, 40%);">+                 * and can hence only be created locally and serves as indication that</span><br><span style="color: hsl(120, 100%, 40%);">+                 * this NS-VC shall not be used for anything except SNS _unless_ it is</span><br><span style="color: hsl(120, 100%, 40%);">+                 * modified via SNS-{CONFIG,CHANGEWEIGHT,ADD} to become part of the</span><br><span style="color: hsl(120, 100%, 40%);">+            * active NS-VCs */</span><br><span style="color: hsl(120, 100%, 40%);">+           nsvc = gprs_nsvc_create2(nsi, nsvci, 0, 0);</span><br><span style="color: hsl(120, 100%, 40%);">+   }</span><br><span>    nsvc->ip.bts_addr = *dest;</span><br><span>        nsvc->nsei = nsei;</span><br><span>        nsvc->remote_end_is_sgsn = 1;</span><br><span>@@ -2161,6 +2210,10 @@</span><br><span> /*! Start the ALIVE timer procedure in all NS-VCs part of this NS Instance */</span><br><span> void gprs_nsvc_start_test(struct gprs_nsvc *nsvc)</span><br><span> {</span><br><span style="color: hsl(120, 100%, 40%);">+  /* skip the initial NS-VC unless it has explicitly been configured</span><br><span style="color: hsl(120, 100%, 40%);">+     * via SNS-CONFIG from the SGSN */</span><br><span style="color: hsl(120, 100%, 40%);">+    if (nsvc_is_not_used(nsvc))</span><br><span style="color: hsl(120, 100%, 40%);">+           return;</span><br><span>      gprs_ns_tx_alive(nsvc);</span><br><span>      nsvc_start_timer(nsvc, NSVC_TIMER_TNS_TEST);</span><br><span> }</span><br><span></span><br></pre><p>To view, visit <a href="https://gerrit.osmocom.org/13291">change 13291</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/13291"/><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-MessageType: merged </div>
<div style="display:none"> Gerrit-Change-Id: I16a91a07e5914d123b2ea2f8413b94e7cd518628 </div>
<div style="display:none"> Gerrit-Change-Number: 13291 </div>
<div style="display:none"> Gerrit-PatchSet: 2 </div>
<div style="display:none"> Gerrit-Owner: Harald Welte <laforge@gnumonks.org> </div>
<div style="display:none"> Gerrit-Reviewer: Harald Welte <laforge@gnumonks.org> </div>
<div style="display:none"> Gerrit-Reviewer: Jenkins Builder (1000002) </div>
<div style="display:none"> Gerrit-CC: Alexander Chemeris <Alexander.Chemeris@gmail.com> </div>