<p>laforge has uploaded this change for <strong>review</strong>.</p><p><a href="https://gerrit.osmocom.org/c/osmo-sgsn/+/21473">View Change</a></p><pre style="font-family: monospace,monospace; white-space: pre-wrap;">gbproxy: Move BSS-side BVC-RESET processing to its own function<br><br>The switch clause was getting a bit too long/nested, let's add<br>a separate gbprox_rx_bvc_reset_from_bss() function.<br><br>Change-Id: If262566e275cca96035045d1194ce102c0942eb6<br>---<br>M src/gbproxy/gb_proxy.c<br>1 file changed, 87 insertions(+), 70 deletions(-)<br><br></pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;">git pull ssh://gerrit.osmocom.org:29418/osmo-sgsn refs/changes/73/21473/1</pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;"><span>diff --git a/src/gbproxy/gb_proxy.c b/src/gbproxy/gb_proxy.c</span><br><span>index c5abeb9..4f2aa2d 100644</span><br><span>--- a/src/gbproxy/gb_proxy.c</span><br><span>+++ b/src/gbproxy/gb_proxy.c</span><br><span>@@ -1008,6 +1008,89 @@</span><br><span> return gbprox_relay2peer(msg, peer, ns_bvci);</span><br><span> }</span><br><span> </span><br><span style="color: hsl(120, 100%, 40%);">+/* process a BVC-RESET message from the BSS side */</span><br><span style="color: hsl(120, 100%, 40%);">+static int gbprox_rx_bvc_reset_from_bss(struct gbproxy_config *cfg, struct msgb *msg,</span><br><span style="color: hsl(120, 100%, 40%);">+ uint16_t nsei, struct tlv_parsed *tp,</span><br><span style="color: hsl(120, 100%, 40%);">+ int *copy_to_sgsn2)</span><br><span style="color: hsl(120, 100%, 40%);">+{</span><br><span style="color: hsl(120, 100%, 40%);">+ struct gbproxy_peer *from_peer = NULL;</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ /* If we receive a BVC reset on the signalling endpoint, we</span><br><span style="color: hsl(120, 100%, 40%);">+ * don't want the SGSN to reset, as the signalling endpoint</span><br><span style="color: hsl(120, 100%, 40%);">+ * is common for all point-to-point BVCs (and thus all BTS) */</span><br><span style="color: hsl(120, 100%, 40%);">+ if (TLVP_PRESENT(tp, BSSGP_IE_BVCI)) {</span><br><span style="color: hsl(120, 100%, 40%);">+ uint16_t bvci = ntohs(tlvp_val16_unal(tp, BSSGP_IE_BVCI));</span><br><span style="color: hsl(120, 100%, 40%);">+ LOGP(DGPRS, LOGL_INFO, "NSE(%05u) Rx BVC RESET (BVCI=%05u)\n", nsei, bvci);</span><br><span style="color: hsl(120, 100%, 40%);">+ if (bvci == 0) {</span><br><span style="color: hsl(120, 100%, 40%);">+ struct gbproxy_nse *nse;</span><br><span style="color: hsl(120, 100%, 40%);">+ /* Ensure the NSE peer is there and clear all PtP BVCs */</span><br><span style="color: hsl(120, 100%, 40%);">+ nse = gbproxy_nse_by_nsei_or_new(cfg, nsei);</span><br><span style="color: hsl(120, 100%, 40%);">+ if (!nse) {</span><br><span style="color: hsl(120, 100%, 40%);">+ LOGP(DGPRS, LOGL_ERROR, "Could not create NSE(%05u)\n", nsei);</span><br><span style="color: hsl(120, 100%, 40%);">+ bssgp_tx_status(BSSGP_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 style="color: hsl(120, 100%, 40%);">+ gbproxy_cleanup_peers(cfg, nsei, 0);</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ /* FIXME: only do this if SGSN is alive! */</span><br><span style="color: hsl(120, 100%, 40%);">+ LOGPNSE(nse, LOGL_INFO, "Tx fake "</span><br><span style="color: hsl(120, 100%, 40%);">+ "BVC RESET ACK of BVCI=0\n");</span><br><span style="color: hsl(120, 100%, 40%);">+ bssgp_tx_simple_bvci(BSSGP_PDUT_BVC_RESET_ACK, nsei, 0, 0);</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%);">+ from_peer = gbproxy_peer_by_bvci(cfg, bvci);</span><br><span style="color: hsl(120, 100%, 40%);">+ if (!from_peer) {</span><br><span style="color: hsl(120, 100%, 40%);">+ struct gbproxy_nse *nse = gbproxy_nse_by_nsei(cfg, nsei);</span><br><span style="color: hsl(120, 100%, 40%);">+ if (!nse) {</span><br><span style="color: hsl(120, 100%, 40%);">+ LOGP(DGPRS, LOGL_NOTICE, "NSE(%05u) Got PtP BVC reset before signalling reset for "</span><br><span style="color: hsl(120, 100%, 40%);">+ "BVCI=%05u\n", nsei, bvci);</span><br><span style="color: hsl(120, 100%, 40%);">+ bssgp_tx_status(BSSGP_CAUSE_PDU_INCOMP_STATE, NULL, 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%);">+ /* if a PTP-BVC is reset, and we don't know that</span><br><span style="color: hsl(120, 100%, 40%);">+ * PTP-BVCI yet, we should allocate a new peer */</span><br><span style="color: hsl(120, 100%, 40%);">+ from_peer = gbproxy_peer_alloc(nse, bvci);</span><br><span style="color: hsl(120, 100%, 40%);">+ OSMO_ASSERT(from_peer);</span><br><span style="color: hsl(120, 100%, 40%);">+ LOGPBVC(from_peer, LOGL_INFO, "Allocated new peer\n");</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%);">+ /* Could have moved to a different NSE */</span><br><span style="color: hsl(120, 100%, 40%);">+ if (!check_peer_nsei(from_peer, nsei)) {</span><br><span style="color: hsl(120, 100%, 40%);">+ LOGPBVC(from_peer, LOGL_NOTICE, "moving peer to NSE(%05u)\n", nsei);</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ struct gbproxy_nse *nse_new = gbproxy_nse_by_nsei(cfg, nsei);</span><br><span style="color: hsl(120, 100%, 40%);">+ if (!nse_new) {</span><br><span style="color: hsl(120, 100%, 40%);">+ LOGP(DGPRS, LOGL_NOTICE, "NSE(%05u) Got PtP BVC reset before signalling reset for "</span><br><span style="color: hsl(120, 100%, 40%);">+ "BVCI=%05u\n", bvci, nsei);</span><br><span style="color: hsl(120, 100%, 40%);">+ bssgp_tx_status(BSSGP_CAUSE_PDU_INCOMP_STATE, NULL, 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 style="color: hsl(120, 100%, 40%);">+ /* Move peer to different NSE */</span><br><span style="color: hsl(120, 100%, 40%);">+ gbproxy_peer_move(from_peer, nse_new);</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%);">+ if (TLVP_PRESENT(tp, BSSGP_IE_CELL_ID)) {</span><br><span style="color: hsl(120, 100%, 40%);">+ struct gprs_ra_id raid;</span><br><span style="color: hsl(120, 100%, 40%);">+ /* We have a Cell Identifier present in this</span><br><span style="color: hsl(120, 100%, 40%);">+ * PDU, this means we can extend our local</span><br><span style="color: hsl(120, 100%, 40%);">+ * state information about this particular cell</span><br><span style="color: hsl(120, 100%, 40%);">+ * */</span><br><span style="color: hsl(120, 100%, 40%);">+ memcpy(from_peer->ra,</span><br><span style="color: hsl(120, 100%, 40%);">+ TLVP_VAL(tp, BSSGP_IE_CELL_ID),</span><br><span style="color: hsl(120, 100%, 40%);">+ sizeof(from_peer->ra));</span><br><span style="color: hsl(120, 100%, 40%);">+ gsm48_parse_ra(&raid, from_peer->ra);</span><br><span style="color: hsl(120, 100%, 40%);">+ LOGPBVC(from_peer, LOGL_INFO, "Cell ID %s\n",</span><br><span style="color: hsl(120, 100%, 40%);">+ osmo_rai_name(&raid));</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span style="color: hsl(120, 100%, 40%);">+ if (cfg->route_to_sgsn2)</span><br><span style="color: hsl(120, 100%, 40%);">+ *copy_to_sgsn2 = 1;</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span style="color: hsl(120, 100%, 40%);">+ /* continue processing / relaying to SGSN[s] */</span><br><span style="color: hsl(120, 100%, 40%);">+ return 1;</span><br><span style="color: hsl(120, 100%, 40%);">+}</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span> /* Receive an incoming signalling message from a BSS-side NS-VC */</span><br><span> static int gbprox_rx_sig_from_bss(struct gbproxy_config *cfg,</span><br><span> struct msgb *msg, uint16_t nsei,</span><br><span>@@ -1061,76 +1144,10 @@</span><br><span> /* FIXME: This only supports one BSS per RA */</span><br><span> break;</span><br><span> case BSSGP_PDUT_BVC_RESET:</span><br><span style="color: hsl(0, 100%, 40%);">- /* If we receive a BVC reset on the signalling endpoint, we</span><br><span style="color: hsl(0, 100%, 40%);">- * don't want the SGSN to reset, as the signalling endpoint</span><br><span style="color: hsl(0, 100%, 40%);">- * is common for all point-to-point BVCs (and thus all BTS) */</span><br><span style="color: hsl(0, 100%, 40%);">- if (TLVP_PRESENT(&tp, BSSGP_IE_BVCI)) {</span><br><span style="color: hsl(0, 100%, 40%);">- uint16_t bvci = ntohs(tlvp_val16_unal(&tp, BSSGP_IE_BVCI));</span><br><span style="color: hsl(0, 100%, 40%);">- LOGP(DGPRS, LOGL_INFO, "NSE(%05u) Rx BVC RESET (BVCI=%05u)\n",</span><br><span style="color: hsl(0, 100%, 40%);">- nsei, bvci);</span><br><span style="color: hsl(0, 100%, 40%);">- if (bvci == 0) {</span><br><span style="color: hsl(0, 100%, 40%);">- struct gbproxy_nse *nse;</span><br><span style="color: hsl(0, 100%, 40%);">- /* Ensure the NSE peer is there and clear all PtP BVCs */</span><br><span style="color: hsl(0, 100%, 40%);">- nse = gbproxy_nse_by_nsei_or_new(cfg, nsei);</span><br><span style="color: hsl(0, 100%, 40%);">- if (!nse) {</span><br><span style="color: hsl(0, 100%, 40%);">- LOGP(DGPRS, LOGL_ERROR, "Could not create NSE(%05u)\n", nsei);</span><br><span style="color: hsl(0, 100%, 40%);">- return bssgp_tx_status(BSSGP_CAUSE_PROTO_ERR_UNSPEC, 0, msg);</span><br><span style="color: hsl(0, 100%, 40%);">- }</span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span style="color: hsl(0, 100%, 40%);">- gbproxy_cleanup_peers(cfg, nsei, 0);</span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span style="color: hsl(0, 100%, 40%);">- /* FIXME: only do this if SGSN is alive! */</span><br><span style="color: hsl(0, 100%, 40%);">- LOGPNSE(nse, LOGL_INFO, "Tx fake "</span><br><span style="color: hsl(0, 100%, 40%);">- "BVC RESET ACK of BVCI=0\n");</span><br><span style="color: hsl(0, 100%, 40%);">- return bssgp_tx_simple_bvci(BSSGP_PDUT_BVC_RESET_ACK,</span><br><span style="color: hsl(0, 100%, 40%);">- nsei, 0, ns_bvci);</span><br><span style="color: hsl(0, 100%, 40%);">- }</span><br><span style="color: hsl(0, 100%, 40%);">- from_peer = gbproxy_peer_by_bvci(cfg, bvci);</span><br><span style="color: hsl(0, 100%, 40%);">- if (!from_peer) {</span><br><span style="color: hsl(0, 100%, 40%);">- struct gbproxy_nse *nse = gbproxy_nse_by_nsei(cfg, nsei);</span><br><span style="color: hsl(0, 100%, 40%);">- if (!nse) {</span><br><span style="color: hsl(0, 100%, 40%);">- LOGP(DGPRS, LOGL_NOTICE, "NSE(%05u) Got PtP BVC reset before signalling reset for "</span><br><span style="color: hsl(0, 100%, 40%);">- "BVCI=%05u\n", nsei, bvci);</span><br><span style="color: hsl(0, 100%, 40%);">- return bssgp_tx_status(BSSGP_CAUSE_PDU_INCOMP_STATE, NULL, msg);</span><br><span style="color: hsl(0, 100%, 40%);">- }</span><br><span style="color: hsl(0, 100%, 40%);">- /* if a PTP-BVC is reset, and we don't know that</span><br><span style="color: hsl(0, 100%, 40%);">- * PTP-BVCI yet, we should allocate a new peer */</span><br><span style="color: hsl(0, 100%, 40%);">- from_peer = gbproxy_peer_alloc(nse, bvci);</span><br><span style="color: hsl(0, 100%, 40%);">- OSMO_ASSERT(from_peer);</span><br><span style="color: hsl(0, 100%, 40%);">- LOGPBVC(from_peer, LOGL_INFO, "Allocated new peer\n");</span><br><span style="color: hsl(0, 100%, 40%);">- }</span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span style="color: hsl(0, 100%, 40%);">- /* Could have moved to a different NSE */</span><br><span style="color: hsl(0, 100%, 40%);">- if (!check_peer_nsei(from_peer, nsei)) {</span><br><span style="color: hsl(0, 100%, 40%);">- LOGPBVC(from_peer, LOGL_NOTICE, "moving peer to NSE(%05u)\n", nsei);</span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span style="color: hsl(0, 100%, 40%);">- struct gbproxy_nse *nse_new = gbproxy_nse_by_nsei(cfg, nsei);</span><br><span style="color: hsl(0, 100%, 40%);">- if (!nse_new) {</span><br><span style="color: hsl(0, 100%, 40%);">- LOGP(DGPRS, LOGL_NOTICE, "NSE(%05u) Got PtP BVC reset before signalling reset for "</span><br><span style="color: hsl(0, 100%, 40%);">- "BVCI=%05u\n", bvci, nsei);</span><br><span style="color: hsl(0, 100%, 40%);">- return bssgp_tx_status(BSSGP_CAUSE_PDU_INCOMP_STATE, NULL, msg);</span><br><span style="color: hsl(0, 100%, 40%);">- }</span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span style="color: hsl(0, 100%, 40%);">- /* Move peer to different NSE */</span><br><span style="color: hsl(0, 100%, 40%);">- gbproxy_peer_move(from_peer, nse_new);</span><br><span style="color: hsl(0, 100%, 40%);">- }</span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span style="color: hsl(0, 100%, 40%);">- if (TLVP_PRESENT(&tp, BSSGP_IE_CELL_ID)) {</span><br><span style="color: hsl(0, 100%, 40%);">- struct gprs_ra_id raid;</span><br><span style="color: hsl(0, 100%, 40%);">- /* We have a Cell Identifier present in this</span><br><span style="color: hsl(0, 100%, 40%);">- * PDU, this means we can extend our local</span><br><span style="color: hsl(0, 100%, 40%);">- * state information about this particular cell</span><br><span style="color: hsl(0, 100%, 40%);">- * */</span><br><span style="color: hsl(0, 100%, 40%);">- memcpy(from_peer->ra,</span><br><span style="color: hsl(0, 100%, 40%);">- TLVP_VAL(&tp, BSSGP_IE_CELL_ID),</span><br><span style="color: hsl(0, 100%, 40%);">- sizeof(from_peer->ra));</span><br><span style="color: hsl(0, 100%, 40%);">- gsm48_parse_ra(&raid, from_peer->ra);</span><br><span style="color: hsl(0, 100%, 40%);">- LOGPBVC(from_peer, LOGL_INFO, "Cell ID %s\n",</span><br><span style="color: hsl(0, 100%, 40%);">- osmo_rai_name(&raid));</span><br><span style="color: hsl(0, 100%, 40%);">- }</span><br><span style="color: hsl(0, 100%, 40%);">- if (cfg->route_to_sgsn2)</span><br><span style="color: hsl(0, 100%, 40%);">- copy_to_sgsn2 = 1;</span><br><span style="color: hsl(0, 100%, 40%);">- }</span><br><span style="color: hsl(120, 100%, 40%);">+ rc = gbprox_rx_bvc_reset_from_bss(cfg, msg, nsei, &tp, ©_to_sgsn2);</span><br><span style="color: hsl(120, 100%, 40%);">+ /* if function retruns 0, we terminate processing here */</span><br><span style="color: hsl(120, 100%, 40%);">+ if (rc == 0)</span><br><span style="color: hsl(120, 100%, 40%);">+ return 0;</span><br><span> break;</span><br><span> }</span><br><span> </span><br><span></span><br></pre><p>To view, visit <a href="https://gerrit.osmocom.org/c/osmo-sgsn/+/21473">change 21473</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-sgsn/+/21473"/><meta itemprop="name" content="View Change"/></div></div>
<div style="display:none"> Gerrit-Project: osmo-sgsn </div>
<div style="display:none"> Gerrit-Branch: master </div>
<div style="display:none"> Gerrit-Change-Id: If262566e275cca96035045d1194ce102c0942eb6 </div>
<div style="display:none"> Gerrit-Change-Number: 21473 </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>