pespin has submitted this change. ( https://gerrit.osmocom.org/c/osmo-sgsn/+/38435?usp=email )
Change subject: ranap: Fix decoding of padded ITU X.213 IPv4 TLA in Rab Ass Resp ......................................................................
ranap: Fix decoding of padded ITU X.213 IPv4 TLA in Rab Ass Resp
Simply use the existing omos-iuh library helper to decode the IP address, which is more robust than existing adhoc code in osmo-sgsn. The library version already supports decoding ITU X.213 IANA binary IPv4 addresses padded to 20 bytes.
Related: OS#6508 Related: SYS#7119 Change-Id: I9c48b676068574338f60b6ed7ad8b61ba748b52e --- M src/sgsn/gprs_ranap.c 1 file changed, 23 insertions(+), 15 deletions(-)
Approvals: lynxis lazus: Looks good to me, approved Jenkins Builder: Verified
diff --git a/src/sgsn/gprs_ranap.c b/src/sgsn/gprs_ranap.c index 51954ce..8548d59 100644 --- a/src/sgsn/gprs_ranap.c +++ b/src/sgsn/gprs_ranap.c @@ -29,6 +29,7 @@ #include <osmocom/gprs/gprs_msgb.h>
#include <osmocom/ranap/ranap_common.h> +#include <osmocom/ranap/iu_helpers.h>
#include <osmocom/sgsn/gprs_gmm.h> #include <osmocom/sgsn/gprs_sm.h> @@ -60,6 +61,7 @@ bool require_pdp_update = false; struct sgsn_pdp_ctx *pdp = NULL; RANAP_RAB_SetupOrModifiedItem_t *item = &setup_ies->raB_SetupOrModifiedItem; + int rc;
rab_id = item->rAB_ID.buf[0];
@@ -70,25 +72,31 @@ }
if (item->transportLayerAddress) { + struct osmo_sockaddr addr; LOGPC(DRANAP, LOGL_INFO, " Setup: (%u/%s)", rab_id, osmo_hexdump(item->transportLayerAddress->buf, item->transportLayerAddress->size)); - switch (item->transportLayerAddress->size) { - case 7: - /* It must be IPv4 inside a X213 NSAP */ - memcpy(pdp->lib->gsnlu.v, &item->transportLayerAddress->buf[3], 4); + rc = ranap_transp_layer_addr_decode2(&addr, NULL, item->transportLayerAddress); + if (rc < 0) { + LOGP(DRANAP, LOGL_ERROR, + "RAB Assignment Resp: Unknown Transport Layer Address (size %u): %s\n", + item->transportLayerAddress->size, + osmo_hexdump(item->transportLayerAddress->buf, item->transportLayerAddress->size)); + return -1; + } + + switch (addr.u.sa.sa_family) { + case AF_INET: + memcpy(pdp->lib->gsnlu.v, (uint8_t *)&addr.u.sin.sin_addr.s_addr, 4); break; - case 4: - /* It must be a raw IPv4 address */ - memcpy(pdp->lib->gsnlu.v, item->transportLayerAddress->buf, 4); - break; - case 16: - /* TODO: It must be a raw IPv6 address */ - case 19: - /* TODO: It must be IPv6 inside a X213 NSAP */ + case AF_INET6: + /* TODO: Support IPv6 address */ + LOGP(DRANAP, LOGL_ERROR, + "RAB Assignment Resp: IPv6 transport layer address not supported!\n"); + return -1; default: - LOGP(DRANAP, LOGL_ERROR, "RAB Assignment Resp: Unknown " - "transport layer address size %u\n", - item->transportLayerAddress->size); + LOGP(DRANAP, LOGL_ERROR, + "RAB Assignment Resp: Unexpected transport layer address size %u\n", + item->transportLayerAddress->size); return -1; } require_pdp_update = true;