aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPau Espin Pedrol <pespin@sysmocom.de>2023-09-20 19:13:33 +0200
committerPau Espin Pedrol <pespin@sysmocom.de>2023-09-21 10:32:10 +0200
commit945b252a483f5368af242408022c055e1ef53d3f (patch)
treefe20dc27cb4022cc6583580490aedee97e3c4e58
parent1dab088701dfb3b27f73ff4a57a68566b55085ca (diff)
sccp2sua: Produce smaller output if msg contains no optional section
-rw-r--r--src/sccp2sua.c18
-rw-r--r--tests/xua/xua_test.c4
-rw-r--r--tests/xua/xua_test.ok3
3 files changed, 19 insertions, 6 deletions
diff --git a/src/sccp2sua.c b/src/sccp2sua.c
index 9bad528..cdab771 100644
--- a/src/sccp2sua.c
+++ b/src/sccp2sua.c
@@ -987,18 +987,26 @@ static int xua_ies_to_sccp_opts(struct msgb *msg, uint8_t *ptr_opt,
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;
+ }
+ }
+ 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 omitted. */
+ ptr_opt[0] = 0;
}
- msgb_put_u8(msg, SCCP_PNC_END_OF_OPTIONAL);
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 @@ static const struct sccp2sua_testcase sccp2sua_testcases[] = {
},
},
}, {
+ /* 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 @@ SCCP Input: [L2]> 02 01 02 03 00 00 03 02 01 00
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