Change in libosmocore[master]: bssgp2_enc_status: Truncate STATUS to MTU if necessary

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/.

daniel gerrit-no-reply at lists.osmocom.org
Fri Feb 12 02:33:43 UTC 2021


daniel has uploaded this change for review. ( https://gerrit.osmocom.org/c/libosmocore/+/22874 )


Change subject: bssgp2_enc_status: Truncate STATUS to MTU if necessary
......................................................................

bssgp2_enc_status: Truncate STATUS to MTU if necessary

Related: OS#4889
Change-Id: Ic39d918c56399ceb0431299ce938e3bf276f678a
---
M include/osmocom/gprs/gprs_bssgp2.h
M src/gb/bssgp_bvc_fsm.c
M src/gb/gprs_bssgp2.c
3 files changed, 17 insertions(+), 6 deletions(-)



  git pull ssh://gerrit.osmocom.org:29418/libosmocore refs/changes/74/22874/1

diff --git a/include/osmocom/gprs/gprs_bssgp2.h b/include/osmocom/gprs/gprs_bssgp2.h
index bf814cb..46186fa 100644
--- a/include/osmocom/gprs/gprs_bssgp2.h
+++ b/include/osmocom/gprs/gprs_bssgp2.h
@@ -59,7 +59,7 @@
 struct msgb *bssgp2_enc_bvc_reset_ack(uint16_t bvci, const struct gprs_ra_id *ra_id, uint16_t cell_id,
 				      const uint8_t *feat_bm, const uint8_t *ext_feat_bm);
 
-struct msgb *bssgp2_enc_status(uint8_t cause, const uint16_t *bvci, const struct msgb *orig_msg);
+struct msgb *bssgp2_enc_status(uint8_t cause, const uint16_t *bvci, const struct msgb *orig_msg, uint16_t mtu);
 
 
 int bssgp2_dec_fc_bvc(struct bssgp2_flow_ctrl *fc, const struct tlv_parsed *tp);
diff --git a/src/gb/bssgp_bvc_fsm.c b/src/gb/bssgp_bvc_fsm.c
index a1edf58..9ac4250 100644
--- a/src/gb/bssgp_bvc_fsm.c
+++ b/src/gb/bssgp_bvc_fsm.c
@@ -238,7 +238,7 @@
 	if (cause == BSSGP_CAUSE_UNKNOWN_BVCI || cause == BSSGP_CAUSE_BVCI_BLOCKED)
 		bvci = &bfp->bvci;
 
-	tx = bssgp2_enc_status(cause, bvci, rx);
+	tx = bssgp2_enc_status(cause, bvci, rx, bfp->mtu);
 
 	if (msgb_bvci(rx) == 0)
 		fi_tx_sig(fi, tx);
diff --git a/src/gb/gprs_bssgp2.c b/src/gb/gprs_bssgp2.c
index 0f519ad..1a7874c 100644
--- a/src/gb/gprs_bssgp2.c
+++ b/src/gb/gprs_bssgp2.c
@@ -217,8 +217,9 @@
 /*! Encode BSSGP STATUS PDU as per TS 48.018 Section 10.4.14.
  *  \param[in] cause BSSGP Cause value
  *  \param[in] bvci optional BVCI - only encoded if non-NULL
- *  \param[in] msg optional message buffer containing PDU in error - only encoded if non-NULL */
-struct msgb *bssgp2_enc_status(uint8_t cause, const uint16_t *bvci, const struct msgb *orig_msg)
+ *  \param[in] msg optional message buffer containing PDU in error - only encoded if non-NULL
+ *  \param[in] mtu Maximum size the NS layer accepts as payload */
+struct msgb *bssgp2_enc_status(uint8_t cause, const uint16_t *bvci, const struct msgb *orig_msg, uint16_t mtu)
 {
 	struct msgb *msg = bssgp_msgb_alloc();
 	struct bssgp_normal_hdr *bgph;
@@ -229,12 +230,22 @@
 	bgph = (struct bssgp_normal_hdr *) msgb_put(msg, sizeof(*bgph));
 	bgph->pdu_type = BSSGP_PDUT_STATUS;
 	msgb_tvlv_put(msg, BSSGP_IE_CAUSE, 1, &cause);
+	/* FIXME: Require/encode BVCI only if cause is BVCI unknown/blocked
+	 * See 3GPP TS 48.018 Ch. 10.4.14 */
 	if (bvci) {
 		uint16_t _bvci = osmo_htons(*bvci);
 		msgb_tvlv_put(msg, BSSGP_IE_BVCI, 2, (uint8_t *) &_bvci);
 	}
-	if (orig_msg)
-		msgb_tvlv_put(msg, BSSGP_IE_PDU_IN_ERROR, msgb_bssgp_len(orig_msg), msgb_bssgph(orig_msg));
+	if (orig_msg) {
+		uint32_t orig_len, max_orig_len;
+		/* Calculate how big the reply would be: the BSSGP msg so far + size of the PDU IN ERROR including tvl */
+		max_orig_len = msgb_length(msg) + TVLV_GROSS_LEN(msgb_bssgp_len(orig_msg));
+		orig_len = msgb_bssgp_len(orig_msg);
+		/* Truncate the difference between max_orig_len and mtu */
+		if (max_orig_len > mtu)
+			orig_len -= max_orig_len - mtu;
+		msgb_tvlv_put(msg, BSSGP_IE_PDU_IN_ERROR, orig_len, msgb_bssgph(orig_msg));
+	}
 
 	return msg;
 }

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

Gerrit-Project: libosmocore
Gerrit-Branch: master
Gerrit-Change-Id: Ic39d918c56399ceb0431299ce938e3bf276f678a
Gerrit-Change-Number: 22874
Gerrit-PatchSet: 1
Gerrit-Owner: daniel <dwillmann at sysmocom.de>
Gerrit-MessageType: newchange
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osmocom.org/pipermail/gerrit-log/attachments/20210212/9c0fded0/attachment.htm>


More information about the gerrit-log mailing list