pespin has uploaded this change for review. ( https://gerrit.osmocom.org/c/libosmo-sccp/+/34466?usp=email )
Change subject: sccp2sua: Produce smaller output if msg contains no optional section ......................................................................
sccp2sua: Produce smaller output if msg contains no optional section
Change-Id: I5c8fcb30b76ac7bafd4a99bc3004049644e7e3f9 --- M src/sccp2sua.c M tests/xua/xua_test.c M tests/xua/xua_test.ok 3 files changed, 28 insertions(+), 6 deletions(-)
git pull ssh://gerrit.osmocom.org:29418/libosmo-sccp refs/changes/66/34466/1
diff --git a/src/sccp2sua.c b/src/sccp2sua.c index 9bad528..2f09a8f 100644 --- a/src/sccp2sua.c +++ b/src/sccp2sua.c @@ -987,18 +987,26 @@ enum sccp_message_types type, const struct xua_msg *xua) { const struct xua_msg_part *part; - - /* store relative pointer to start of optional part */ - *ptr_opt = msg->tail - ptr_opt; + bool any_added = false; + uint8_t *old_tail = msg->tail;
llist_for_each_entry(part, &xua->headers, entry) { /* make sure we don't add a SCCP option for information * that is already present in mandatory fixed or * mandatory variable parts of the header */ - if (!sccp_is_mandatory(type, part) && sccp_option_permitted(type, part)) + if (!sccp_is_mandatory(type, part) && sccp_option_permitted(type, part)) { sccp_msg_add_sua_opt(type, msg, part); + any_added = true; + } } - msgb_put_u8(msg, SCCP_PNC_END_OF_OPTIONAL); + if (any_added) { + msgb_put_u8(msg, SCCP_PNC_END_OF_OPTIONAL); + /* store relative pointer to start of optional part */ + *ptr_opt = old_tail - ptr_opt; + } else { + /* If nothing was added, simply update the pointer to 0 to signal the optional part is ommited. */ + ptr_opt[0] = 0; + }
return 0; } diff --git a/tests/xua/xua_test.c b/tests/xua/xua_test.c index 6b4eef5..628d860 100644 --- a/tests/xua/xua_test.c +++ b/tests/xua/xua_test.c @@ -439,6 +439,10 @@ }, }, }, { + /* This case expectedly prints "Input != re-encoded output!" because input has + * (struct sccp_connection_confirm).optional_start=1 pointing to SCCP_PNC_END_OF_OPTIONAL, + * while our (re-)encoder uses optional_start=0 which means entire msg is 1 byte + * lower (hence better). Both are valid. */ .name = "BSSMAP-CC", .sccp = PANDSIZ(bssmap_cc), .sua = { diff --git a/tests/xua/xua_test.ok b/tests/xua/xua_test.ok index 6738cc0..cb6aab1 100644 --- a/tests/xua/xua_test.ok +++ b/tests/xua/xua_test.ok @@ -55,7 +55,8 @@ Transcoding message SCCP -> XUA Decoded SUA: HDR=(CO:COAK,V=0,LEN=0), PART(T=Protocol Class,L=4,D=00000002), PART(T=Destination Reference,L=4,D=00010203), PART(T=Source Reference,L=4,D=00000003) Re-Encoding decoded SUA to SCCP -SCCP Output: [L2]> 02 01 02 03 00 00 03 02 01 00 +SCCP Output: [L2]> 02 01 02 03 00 00 03 02 00 +Input != re-encoded output!
=> BSSMAP-DTAP SCCP Input: [L2]> 06 00 00 03 00 01 0f 01 00 0c 03 05 5c 08 11 81 33 66 02 13 45 f4