From be0e831fa33a2590348952ed35df5e9b9b8caf85 Mon Sep 17 00:00:00 2001 From: Daniel Willmann Date: Tue, 23 Apr 2019 16:58:52 +0200 Subject: osmo-bsc_nat: Parse MGCP Connection ID as hex Our ttcn3-bscnat-tests would randomly fail. After the CRCX ACK returns from the MSC the bsc-nat reports it could not find a CI it it and deletes the connection on the BSC-side. This happens because the field is parsed as a decimal value instead of hexadecimal. So a value of 00FED122 is parsed as '0' which is a reserved value in our program. This fix parses the field as hexadecimal value and also logs an error if the value happens to be 0. make check will now test if a hexadecimal CI is parsed correctly. Fixes: OS#3951 Change-Id: I49b8b61644bf706162102dce268cae2265536fc5 --- openbsc/src/libmgcp/mgcp_protocol.c | 8 ++++---- openbsc/src/osmo-bsc_nat/bsc_mgcp_utils.c | 5 ++++- 2 files changed, 8 insertions(+), 5 deletions(-) (limited to 'openbsc/src') diff --git a/openbsc/src/libmgcp/mgcp_protocol.c b/openbsc/src/libmgcp/mgcp_protocol.c index 84dbc1f52..689c91f54 100644 --- a/openbsc/src/libmgcp/mgcp_protocol.c +++ b/openbsc/src/libmgcp/mgcp_protocol.c @@ -208,7 +208,7 @@ static int write_response_sdp(struct mgcp_endpoint *endp, len = snprintf(sdp_record, size, "v=0\r\n" - "o=- %u 23 IN IP4 %s\r\n" + "o=- %x 23 IN IP4 %s\r\n" "s=-\r\n" "c=IN IP4 %s\r\n" "t=0 0\r\n", @@ -285,7 +285,7 @@ static struct msgb *create_response_with_sdp(struct mgcp_endpoint *endp, } len = snprintf(sdp_record, sizeof(sdp_record), - "I: %u%s\n\n", endp->ci, osmux_extension); + "I: %x%s\n\n", endp->ci, osmux_extension); if (len < 0) return NULL; @@ -512,7 +512,7 @@ static int verify_ci(const struct mgcp_endpoint *endp, uint32_t ci = strtoul(_ci, NULL, 10); if (ci != endp->ci) { - LOGP(DMGCP, LOGL_ERROR, "ConnectionIdentifiers do not match on 0x%x. %u != %s\n", + LOGP(DMGCP, LOGL_ERROR, "ConnectionIdentifiers do not match on 0x%x. %x != %x\n", ENDPOINT_NUMBER(endp), endp->ci, _ci); return -1; } @@ -891,7 +891,7 @@ mgcp_header_done: osmo_jibuf_set_dequeue_cb(endp->bts_jb, mgcp_dejitter_udp_send, &endp->net_end); } - LOGP(DMGCP, LOGL_DEBUG, "Creating endpoint on: 0x%x CI: %u port: %u/%u\n", + LOGP(DMGCP, LOGL_DEBUG, "Creating endpoint on: 0x%x CI: %x port: %u/%u\n", ENDPOINT_NUMBER(endp), endp->ci, endp->net_end.local_port, endp->bts_end.local_port); if (p->cfg->change_cb) diff --git a/openbsc/src/osmo-bsc_nat/bsc_mgcp_utils.c b/openbsc/src/osmo-bsc_nat/bsc_mgcp_utils.c index 311ab94cc..17dc659bb 100644 --- a/openbsc/src/osmo-bsc_nat/bsc_mgcp_utils.c +++ b/openbsc/src/osmo-bsc_nat/bsc_mgcp_utils.c @@ -812,11 +812,14 @@ uint32_t bsc_mgcp_extract_ci(const char *str) return CI_UNUSED; } - if (sscanf(res, "I: %u", &ci) != 1) { + if (sscanf(res, "I: %x", &ci) != 1) { LOGP(DMGCP, LOGL_ERROR, "Failed to parse CI in msg '%s'\n", str); return CI_UNUSED; } + if (ci == CI_UNUSED) + LOGP(DMGCP, LOGL_ERROR, "CI field '%s' parsed as reserved value CI_UNUSED\n", str); + return ci; } -- cgit v1.2.3