<p>daniel has uploaded this change for <strong>review</strong>.</p><p><a href="https://gerrit.osmocom.org/c/osmo-gbproxy/+/26062">View Change</a></p><pre style="font-family: monospace,monospace; white-space: pre-wrap;">gbproxy: Move BSSGP decoding into its own function and use it<br><br>This code was copied in BSS and SGSN PTP receive functions and also in<br>the functions that extract the inner PDU-in-error from the STATUS PDU.<br><br>Use a central function for less code duplication and better<br>maintainability.<br><br>This also fixes TTCN3 test TC_status_ptp_ul_tlli the c&p omitted the<br>special handling of UL/DL unitdata.<br><br>Related: OS#4892<br>Change-Id: I882aa97b0f4158affe45e81e4e4701bd36ef89f7<br>---<br>M src/gb_proxy.c<br>1 file changed, 27 insertions(+), 36 deletions(-)<br><br></pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;">git pull ssh://gerrit.osmocom.org:29418/osmo-gbproxy refs/changes/62/26062/1</pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;"><span>diff --git a/src/gb_proxy.c b/src/gb_proxy.c</span><br><span>index 7333e80..066d262 100644</span><br><span>--- a/src/gb_proxy.c</span><br><span>+++ b/src/gb_proxy.c</span><br><span>@@ -380,6 +380,29 @@</span><br><span>  return gbprox_relay2peer(msg, sgsn_bvc, sig_bvci ? 0 : sgsn_bvc->bvci);</span><br><span> }</span><br><span> </span><br><span style="color: hsl(120, 100%, 40%);">+static int gbproxy_decode_bssgp(const struct bssgp_normal_hdr *bgph, int msg_len, struct tlv_parsed *tp, const char *log_pfx)</span><br><span style="color: hsl(120, 100%, 40%);">+{</span><br><span style="color: hsl(120, 100%, 40%);">+ int rc;</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+     /* UL_UNITDATA has a different header than all other uplink PDUs */</span><br><span style="color: hsl(120, 100%, 40%);">+   if (bgph->pdu_type == BSSGP_PDUT_UL_UNITDATA || bgph->pdu_type == BSSGP_PDUT_DL_UNITDATA) {</span><br><span style="color: hsl(120, 100%, 40%);">+             const struct bssgp_ud_hdr *budh = (struct bssgp_ud_hdr *) bgph;</span><br><span style="color: hsl(120, 100%, 40%);">+               if (msg_len < sizeof(*budh))</span><br><span style="color: hsl(120, 100%, 40%);">+                       return -OSMO_TLVP_ERR_MAND_IE_MISSING;</span><br><span style="color: hsl(120, 100%, 40%);">+                rc = osmo_tlv_prot_parse(&osmo_pdef_bssgp, tp, 1, budh->pdu_type, budh->data,</span><br><span style="color: hsl(120, 100%, 40%);">+                                        msg_len - sizeof(*budh), 0, 0, DGPRS, log_pfx);</span><br><span style="color: hsl(120, 100%, 40%);">+              /* populate TLLI from the fixed headser into the TLV-parsed array so later code</span><br><span style="color: hsl(120, 100%, 40%);">+                * doesn't have to worry where the TLLI came from */</span><br><span style="color: hsl(120, 100%, 40%);">+              tp->lv[BSSGP_IE_TLLI].len = 4;</span><br><span style="color: hsl(120, 100%, 40%);">+             tp->lv[BSSGP_IE_TLLI].val = (const uint8_t *) &budh->tlli;</span><br><span style="color: hsl(120, 100%, 40%);">+  } else {</span><br><span style="color: hsl(120, 100%, 40%);">+              rc = osmo_tlv_prot_parse(&osmo_pdef_bssgp, tp, 1, bgph->pdu_type, bgph->data,</span><br><span style="color: hsl(120, 100%, 40%);">+                                        msg_len - sizeof(*bgph), 0, 0, DGPRS, log_pfx);</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 rc;</span><br><span style="color: hsl(120, 100%, 40%);">+}</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span> static int gbproxy_tlli_from_status_pdu(struct tlv_parsed *tp, uint32_t *tlli, char *log_pfx);</span><br><span> </span><br><span> /* Receive an incoming PTP message from a BSS-side NS-VC */</span><br><span>@@ -419,21 +442,7 @@</span><br><span>          return tx_status(nse, ns_bvci, BSSGP_CAUSE_UNKNOWN_BVCI, &ns_bvci, msg);</span><br><span>         }</span><br><span> </span><br><span style="color: hsl(0, 100%, 40%);">-   /* UL_UNITDATA has a different header than all other uplink PDUs */</span><br><span style="color: hsl(0, 100%, 40%);">-     if (bgph->pdu_type == BSSGP_PDUT_UL_UNITDATA) {</span><br><span style="color: hsl(0, 100%, 40%);">-              const struct bssgp_ud_hdr *budh = (struct bssgp_ud_hdr *) msgb_bssgph(msg);</span><br><span style="color: hsl(0, 100%, 40%);">-             if (msgb_bssgp_len(msg) < sizeof(*budh))</span><br><span style="color: hsl(0, 100%, 40%);">-                     return tx_status(nse, ns_bvci, BSSGP_CAUSE_INV_MAND_INF, NULL, msg);</span><br><span style="color: hsl(0, 100%, 40%);">-            rc = osmo_tlv_prot_parse(&osmo_pdef_bssgp, &tp, 1, bgph->pdu_type, budh->data,</span><br><span style="color: hsl(0, 100%, 40%);">-                                     msgb_bssgp_len(msg) - sizeof(*budh), 0, 0, DGPRS, log_pfx);</span><br><span style="color: hsl(0, 100%, 40%);">-            /* populate TLLI from the fixed headser into the TLV-parsed array so later code</span><br><span style="color: hsl(0, 100%, 40%);">-          * doesn't have to worry where the TLLI came from */</span><br><span style="color: hsl(0, 100%, 40%);">-                tp.lv[BSSGP_IE_TLLI].len = 4;</span><br><span style="color: hsl(0, 100%, 40%);">-           tp.lv[BSSGP_IE_TLLI].val = (const uint8_t *) &budh->tlli;</span><br><span style="color: hsl(0, 100%, 40%);">-        } else {</span><br><span style="color: hsl(0, 100%, 40%);">-                rc = osmo_tlv_prot_parse(&osmo_pdef_bssgp, &tp, 1, bgph->pdu_type, bgph->data,</span><br><span style="color: hsl(0, 100%, 40%);">-                                     msgb_bssgp_len(msg) - sizeof(*bgph), 0, 0, DGPRS, log_pfx);</span><br><span style="color: hsl(0, 100%, 40%);">-    }</span><br><span style="color: hsl(120, 100%, 40%);">+     rc = gbproxy_decode_bssgp(bgph, msgb_bssgp_len(msg), &tp, log_pfx);</span><br><span>      if (rc < 0) {</span><br><span>             rate_ctr_inc(rate_ctr_group_get_ctr(nse->cfg->ctrg, GBPROX_GLOB_CTR_PROTO_ERR_BSS));</span><br><span>           return tx_status_from_tlvp(nse, rc, msg);</span><br><span>@@ -567,21 +576,7 @@</span><br><span>             return tx_status(nse, ns_bvci, BSSGP_CAUSE_BVCI_BLOCKED, &ns_bvci, msg);</span><br><span>         }</span><br><span> </span><br><span style="color: hsl(0, 100%, 40%);">-   /* DL_UNITDATA has a different header than all other uplink PDUs */</span><br><span style="color: hsl(0, 100%, 40%);">-     if (bgph->pdu_type == BSSGP_PDUT_DL_UNITDATA) {</span><br><span style="color: hsl(0, 100%, 40%);">-              const struct bssgp_ud_hdr *budh = (struct bssgp_ud_hdr *) msgb_bssgph(msg);</span><br><span style="color: hsl(0, 100%, 40%);">-             if (msgb_bssgp_len(msg) < sizeof(*budh))</span><br><span style="color: hsl(0, 100%, 40%);">-                     return tx_status(nse, ns_bvci, BSSGP_CAUSE_INV_MAND_INF, NULL, msg);</span><br><span style="color: hsl(0, 100%, 40%);">-            rc = osmo_tlv_prot_parse(&osmo_pdef_bssgp, &tp, 1, bgph->pdu_type, budh->data,</span><br><span style="color: hsl(0, 100%, 40%);">-                                     msgb_bssgp_len(msg) - sizeof(*budh), 0, 0, DGPRS, log_pfx);</span><br><span style="color: hsl(0, 100%, 40%);">-            /* populate TLLI from the fixed headser into the TLV-parsed array so later code</span><br><span style="color: hsl(0, 100%, 40%);">-          * doesn't have to worry where the TLLI came from */</span><br><span style="color: hsl(0, 100%, 40%);">-                tp.lv[BSSGP_IE_TLLI].len = 4;</span><br><span style="color: hsl(0, 100%, 40%);">-           tp.lv[BSSGP_IE_TLLI].val = (const uint8_t *) &budh->tlli;</span><br><span style="color: hsl(0, 100%, 40%);">-        } else {</span><br><span style="color: hsl(0, 100%, 40%);">-                rc = osmo_tlv_prot_parse(&osmo_pdef_bssgp, &tp, 1, bgph->pdu_type, bgph->data,</span><br><span style="color: hsl(0, 100%, 40%);">-                                     msgb_bssgp_len(msg) - sizeof(*bgph), 0, 0, DGPRS, log_pfx);</span><br><span style="color: hsl(0, 100%, 40%);">-    }</span><br><span style="color: hsl(120, 100%, 40%);">+     rc = gbproxy_decode_bssgp(bgph, msgb_bssgp_len(msg), &tp, log_pfx);</span><br><span>      if (rc < 0) {</span><br><span>             rate_ctr_inc(rate_ctr_group_get_ctr(nse->cfg->ctrg, GBPROX_GLOB_CTR_PROTO_ERR_BSS));</span><br><span>           return tx_status_from_tlvp(nse, rc, msg);</span><br><span>@@ -1017,9 +1012,7 @@</span><br><span>    struct tlv_parsed tp_inner[2];</span><br><span> </span><br><span>   /* TODO: Parse partial messages as well */</span><br><span style="color: hsl(0, 100%, 40%);">-      rc = osmo_tlv_prot_parse(&osmo_pdef_bssgp, tp_inner, ARRAY_SIZE(tp_inner), bgph->pdu_type, bgph->data,</span><br><span style="color: hsl(0, 100%, 40%);">-                                 pdu_len - sizeof(*bgph), 0, 0, DGPRS, log_pfx);</span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span style="color: hsl(120, 100%, 40%);">+      rc = gbproxy_decode_bssgp(bgph, pdu_len, &tp_inner[0], log_pfx);</span><br><span>         if (rc < 0)</span><br><span>               return rc;</span><br><span> </span><br><span>@@ -1047,9 +1040,7 @@</span><br><span>       struct tlv_parsed tp_inner[2];</span><br><span> </span><br><span>   /* TODO: Parse partial messages as well */</span><br><span style="color: hsl(0, 100%, 40%);">-      rc = osmo_tlv_prot_parse(&osmo_pdef_bssgp, tp_inner, ARRAY_SIZE(tp_inner), bgph->pdu_type, bgph->data,</span><br><span style="color: hsl(0, 100%, 40%);">-                                 pdu_len - sizeof(*bgph), 0, 0, DGPRS, log_pfx);</span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span style="color: hsl(120, 100%, 40%);">+      rc = gbproxy_decode_bssgp(bgph, pdu_len, &tp_inner[0], log_pfx);</span><br><span>         if (rc < 0)</span><br><span>               return rc;</span><br><span> </span><br><span></span><br></pre><p>To view, visit <a href="https://gerrit.osmocom.org/c/osmo-gbproxy/+/26062">change 26062</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/osmo-gbproxy/+/26062"/><meta itemprop="name" content="View Change"/></div></div>

<div style="display:none"> Gerrit-Project: osmo-gbproxy </div>
<div style="display:none"> Gerrit-Branch: master </div>
<div style="display:none"> Gerrit-Change-Id: I882aa97b0f4158affe45e81e4e4701bd36ef89f7 </div>
<div style="display:none"> Gerrit-Change-Number: 26062 </div>
<div style="display:none"> Gerrit-PatchSet: 1 </div>
<div style="display:none"> Gerrit-Owner: daniel <dwillmann@sysmocom.de> </div>
<div style="display:none"> Gerrit-MessageType: newchange </div>