Change in libosmocore[master]: BSSGP: use variable for NSEI

This is merely a historical archive of years 2008-2021, before the migration to mailman3.

A maintained and still updated list archive can be found at https://lists.osmocom.org/hyperkitty/list/gerrit-log@lists.osmocom.org/.

Max gerrit-no-reply at lists.osmocom.org
Mon Mar 11 15:15:05 UTC 2019


Max has uploaded this change for review. ( https://gerrit.osmocom.org/13204


Change subject: BSSGP: use variable for NSEI
......................................................................

BSSGP: use variable for NSEI

Handle NSEI the same way as BVCI is handled: assign it to variable
instead of repetitive calls to msgb_nsei() - this simplifies log update
in follow-up patches and makes code slightly easier to read.

Change-Id: I919a717ca22646849d6ec7f62c677c536db0ed31
---
M src/gb/gprs_bssgp.c
M src/gb/gprs_bssgp_util.c
2 files changed, 29 insertions(+), 25 deletions(-)



  git pull ssh://gerrit.osmocom.org:29418/libosmocore refs/changes/04/13204/1

diff --git a/src/gb/gprs_bssgp.c b/src/gb/gprs_bssgp.c
index 4a4bab3..7acc9d9 100644
--- a/src/gb/gprs_bssgp.c
+++ b/src/gb/gprs_bssgp.c
@@ -307,7 +307,7 @@
 static int bssgp_rx_bvc_block(struct msgb *msg, struct tlv_parsed *tp)
 {
 	struct osmo_bssgp_prim nmp;
-	uint16_t bvci;
+	uint16_t bvci, nsei = msgb_nsei(msg);
 	struct bssgp_bvc_ctx *ptp_ctx;
 
 	bvci = tlvp_val16be(tp, BSSGP_IE_BVCI);
@@ -315,13 +315,13 @@
 		/* 8.3.2: Signalling BVC shall never be blocked */
 		LOGP(DBSSGP, LOGL_ERROR, "NSEI=%u/BVCI=%u "
 			"received block for signalling BVC!?!\n",
-			msgb_nsei(msg), msgb_bvci(msg));
+			nsei, msgb_bvci(msg));
 		return 0;
 	}
 
 	LOGP(DBSSGP, LOGL_INFO, "BSSGP Rx BVCI=%u BVC-BLOCK\n", bvci);
 
-	ptp_ctx = btsctx_by_bvci_nsei(bvci, msgb_nsei(msg));
+	ptp_ctx = btsctx_by_bvci_nsei(bvci, nsei);
 	if (!ptp_ctx)
 		return bssgp_tx_status(BSSGP_CAUSE_UNKNOWN_BVCI, &bvci, msg);
 
@@ -330,7 +330,7 @@
 
 	/* Send NM_BVC_BLOCK.ind to NM */
 	memset(&nmp, 0, sizeof(nmp));
-	nmp.nsei = msgb_nsei(msg);
+	nmp.nsei = nsei;
 	nmp.bvci = bvci;
 	nmp.tp = tp;
 	osmo_prim_init(&nmp.oph, SAP_BSSGP_NM, PRIM_NM_BVC_BLOCK,
@@ -338,14 +338,14 @@
 	bssgp_prim_cb(&nmp.oph, NULL);
 
 	/* We always acknowledge the BLOCKing */
-	return bssgp_tx_simple_bvci(BSSGP_PDUT_BVC_BLOCK_ACK, msgb_nsei(msg),
+	return bssgp_tx_simple_bvci(BSSGP_PDUT_BVC_BLOCK_ACK, nsei,
 				    bvci, msgb_bvci(msg));
 };
 
 static int bssgp_rx_bvc_unblock(struct msgb *msg, struct tlv_parsed *tp)
 {
 	struct osmo_bssgp_prim nmp;
-	uint16_t bvci;
+	uint16_t bvci, nsei = msgb_nsei(msg);
 	struct bssgp_bvc_ctx *ptp_ctx;
 
 	bvci = tlvp_val16be(tp, BSSGP_IE_BVCI);
@@ -353,13 +353,13 @@
 		/* 8.3.2: Signalling BVC shall never be blocked */
 		LOGP(DBSSGP, LOGL_ERROR, "NSEI=%u/BVCI=%u "
 			"received unblock for signalling BVC!?!\n",
-			msgb_nsei(msg), msgb_bvci(msg));
+			nsei, msgb_bvci(msg));
 		return 0;
 	}
 
 	DEBUGP(DBSSGP, "BSSGP BVCI=%u Rx BVC-UNBLOCK\n", bvci);
 
-	ptp_ctx = btsctx_by_bvci_nsei(bvci, msgb_nsei(msg));
+	ptp_ctx = btsctx_by_bvci_nsei(bvci, nsei);
 	if (!ptp_ctx)
 		return bssgp_tx_status(BSSGP_CAUSE_UNKNOWN_BVCI, &bvci, msg);
 
@@ -367,7 +367,7 @@
 
 	/* Send NM_BVC_UNBLOCK.ind to NM */
 	memset(&nmp, 0, sizeof(nmp));
-	nmp.nsei = msgb_nsei(msg);
+	nmp.nsei = nsei;
 	nmp.bvci = bvci;
 	nmp.tp = tp;
 	osmo_prim_init(&nmp.oph, SAP_BSSGP_NM, PRIM_NM_BVC_UNBLOCK,
@@ -375,7 +375,7 @@
 	bssgp_prim_cb(&nmp.oph, NULL);
 
 	/* We always acknowledge the unBLOCKing */
-	return bssgp_tx_simple_bvci(BSSGP_PDUT_BVC_UNBLOCK_ACK, msgb_nsei(msg),
+	return bssgp_tx_simple_bvci(BSSGP_PDUT_BVC_UNBLOCK_ACK, nsei,
 				    bvci, msgb_bvci(msg));
 };
 
@@ -419,7 +419,7 @@
 	struct osmo_bssgp_prim gbp;
 	struct gprs_ra_id raid;
 	uint32_t tlli;
-	uint16_t ns_bvci = msgb_bvci(msg);
+	uint16_t ns_bvci = msgb_bvci(msg), nsei = msgb_nsei(msg);
 	int rc;
 
 	if (!TLVP_PRESENT(tp, BSSGP_IE_TLLI) ||
@@ -438,7 +438,7 @@
 
 	/* Inform GMM about the SUSPEND request */
 	memset(&gbp, 0, sizeof(gbp));
-	gbp.nsei = msgb_nsei(msg);
+	gbp.nsei = nsei;
 	gbp.bvci = ns_bvci;
 	gbp.tlli = tlli;
 	gbp.ra_id = &raid;
@@ -447,9 +447,9 @@
 
 	rc = bssgp_prim_cb(&gbp.oph, NULL);
 	if (rc < 0)
-		return bssgp_tx_suspend_nack(msgb_nsei(msg), tlli, &raid, NULL);
+		return bssgp_tx_suspend_nack(nsei, tlli, &raid, NULL);
 
-	bssgp_tx_suspend_ack(msgb_nsei(msg), tlli, &raid, 0);
+	bssgp_tx_suspend_ack(nsei, tlli, &raid, 0);
 
 	return 0;
 }
@@ -460,7 +460,7 @@
 	struct gprs_ra_id raid;
 	uint32_t tlli;
 	uint8_t suspend_ref;
-	uint16_t ns_bvci = msgb_bvci(msg);
+	uint16_t ns_bvci = msgb_bvci(msg), nsei = msgb_nsei(msg);
 	int rc;
 
 	if (!TLVP_PRESENT(tp, BSSGP_IE_TLLI) ||
@@ -480,7 +480,7 @@
 
 	/* Inform GMM about the RESUME request */
 	memset(&gbp, 0, sizeof(gbp));
-	gbp.nsei = msgb_nsei(msg);
+	gbp.nsei = nsei;
 	gbp.bvci = ns_bvci;
 	gbp.tlli = tlli;
 	gbp.ra_id = &raid;
@@ -490,10 +490,10 @@
 
 	rc = bssgp_prim_cb(&gbp.oph, NULL);
 	if (rc < 0)
-		return bssgp_tx_resume_nack(msgb_nsei(msg), tlli, &raid,
+		return bssgp_tx_resume_nack(nsei, tlli, &raid,
 					    NULL);
 
-	bssgp_tx_resume_ack(msgb_nsei(msg), tlli, &raid);
+	bssgp_tx_resume_ack(nsei, tlli, &raid);
 	return 0;
 }
 
@@ -503,6 +503,7 @@
 {
 	struct osmo_bssgp_prim nmp;
 	uint32_t tlli = 0;
+	uint16_t nsei = msgb_nsei(msg);
 
 	if (!TLVP_PRESENT(tp, BSSGP_IE_TLLI) ||
 	    !TLVP_PRESENT(tp, BSSGP_IE_LLC_FRAMES_DISCARDED) ||
@@ -522,7 +523,7 @@
 
 	/* send NM_LLC_DISCARDED to NM */
 	memset(&nmp, 0, sizeof(nmp));
-	nmp.nsei = msgb_nsei(msg);
+	nmp.nsei = nsei;
 	nmp.bvci = ctx->bvci;
 	nmp.tlli = tlli;
 	nmp.tp = tp;
@@ -535,6 +536,7 @@
 int bssgp_rx_status(struct msgb *msg, struct tlv_parsed *tp,
 	uint16_t bvci, struct bssgp_bvc_ctx *bctx)
 {
+	uint16_t nsei = msgb_nsei(msg);
 	struct osmo_bssgp_prim nmp;
 	enum gprs_bssgp_cause cause;
 
@@ -562,7 +564,7 @@
 
 	/* send NM_STATUS to NM */
 	memset(&nmp, 0, sizeof(nmp));
-	nmp.nsei = msgb_nsei(msg);
+	nmp.nsei = nsei;
 	nmp.bvci = bvci;
 	nmp.tp = tp;
 	osmo_prim_init(&nmp.oph, SAP_BSSGP_NM, PRIM_NM_STATUS,
@@ -801,6 +803,7 @@
 {
 	uint32_t old_leak_rate = bctx->fc->bucket_leak_rate;
 	uint32_t old_r_def_ms = bctx->r_default_ms;
+	uint16_t nsei = msgb_nsei(msg);
 
 	DEBUGP(DBSSGP, "BSSGP BVCI=%u Rx Flow Control BVC\n",
 		bctx->bvci);
@@ -842,7 +845,7 @@
 	fc_queue_timer_cfg(bctx->fc);
 
 	/* Send FLOW_CONTROL_BVC_ACK */
-	return bssgp_tx_fc_bvc_ack(msgb_nsei(msg), *TLVP_VAL(tp, BSSGP_IE_TAG),
+	return bssgp_tx_fc_bvc_ack(nsei, *TLVP_VAL(tp, BSSGP_IE_TAG),
 				   msgb_bvci(msg));
 }
 
@@ -1033,7 +1036,7 @@
 	struct tlv_parsed tp;
 	struct bssgp_bvc_ctx *bctx;
 	uint8_t pdu_type = bgph->pdu_type;
-	uint16_t ns_bvci = msgb_bvci(msg);
+	uint16_t ns_bvci = msgb_bvci(msg), ns_nsei = msgb_nsei(msg);
 	uint16_t bvci = ns_bvci;
 	int data_len;
 	int rc = 0;
@@ -1081,7 +1084,7 @@
 	if (!bctx && bvci != BVCI_SIGNALLING &&
 	    pdu_type != BSSGP_PDUT_BVC_RESET) {
 		LOGP(DBSSGP, LOGL_NOTICE, "NSEI=%u/BVCI=%u Rejecting PDU "
-			"type %s for unknown BVCI\n", msgb_nsei(msg), bvci,
+			"type %s for unknown BVCI\n", ns_nsei, bvci,
 			bssgp_pdu_str(pdu_type));
 		return bssgp_tx_status(BSSGP_CAUSE_UNKNOWN_BVCI, &bvci, msg);
 	}
@@ -1096,7 +1099,7 @@
 		LOGP(DBSSGP, LOGL_NOTICE,
 			"NSEI=%u/BVCI=%u Cannot handle PDU type %s for "
 			"unknown BVCI, NS BVCI %u\n",
-			msgb_nsei(msg), bvci, bssgp_pdu_str(pdu_type), ns_bvci);
+			ns_nsei, bvci, bssgp_pdu_str(pdu_type), ns_bvci);
 
 	return rc;
 }
diff --git a/src/gb/gprs_bssgp_util.c b/src/gb/gprs_bssgp_util.c
index 669dfb8..95bf8285 100644
--- a/src/gb/gprs_bssgp_util.c
+++ b/src/gb/gprs_bssgp_util.c
@@ -216,6 +216,7 @@
 /* Chapter 10.4.14: Status */
 int bssgp_tx_status(uint8_t cause, uint16_t *bvci, struct msgb *orig_msg)
 {
+	uint16_t nsei = msgb_nsei(orig_msg);
 	struct msgb *msg = bssgp_msgb_alloc();
 	struct bssgp_normal_hdr *bgph =
 			(struct bssgp_normal_hdr *) msgb_put(msg, sizeof(*bgph));
@@ -236,7 +237,7 @@
 
 	LOGP(DBSSGP, LOGL_NOTICE, "BSSGP BVCI=%u Tx STATUS, cause=%s\n",
 		bvci ? *bvci : 0, bssgp_cause_str(cause));
-	msgb_nsei(msg) = msgb_nsei(orig_msg);
+	msgb_nsei(msg) = nsei;
 	msgb_bvci(msg) = 0;
 
 	bgph->pdu_type = BSSGP_PDUT_STATUS;

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

Gerrit-Project: libosmocore
Gerrit-Branch: master
Gerrit-MessageType: newchange
Gerrit-Change-Id: I919a717ca22646849d6ec7f62c677c536db0ed31
Gerrit-Change-Number: 13204
Gerrit-PatchSet: 1
Gerrit-Owner: Max <msuraev at sysmocom.de>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osmocom.org/pipermail/gerrit-log/attachments/20190311/724571cb/attachment.htm>


More information about the gerrit-log mailing list