From 3b1131936ec02f9edf2c891e8ea2d3d8859f8150 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nils=20F=C3=BCrste?= Date: Tue, 26 Oct 2021 18:37:55 +0200 Subject: [PATCH] Fix GTP-U bearer address conversion Addresses with a leading 0 in hex represenatation were converted without the leading 0 and padded afterwards with a trailing 0. This leaded to wrong IPs in the GTP-U bearer setup. --- srsenb/src/stack/ngap/ngap_ue_bearer_manager.cc | 2 +- srsenb/src/stack/upper/gtpu.cc | 7 ++++--- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/srsenb/src/stack/ngap/ngap_ue_bearer_manager.cc b/srsenb/src/stack/ngap/ngap_ue_bearer_manager.cc index 68944c3d6..55ceb18c2 100644 --- a/srsenb/src/stack/ngap/ngap_ue_bearer_manager.cc +++ b/srsenb/src/stack/ngap/ngap_ue_bearer_manager.cc @@ -86,7 +86,7 @@ int ngap_ue_bearer_manager::add_gtpu_bearer(uint16_t logger.info("Addr in %x", addr_in); - tunnel.address_in.from_number(addr_in); + tunnel.address_in.from_number(addr_in, 32); tunnel.teid_in = rtn.value(); logger.info("Added GTPU tunnel rnti 0x%04x, pdu_session_id=%d, teid_out %d, teid_in %d, address out 0x%x, " diff --git a/srsenb/src/stack/upper/gtpu.cc b/srsenb/src/stack/upper/gtpu.cc index 41ee99d97..a0555edc8 100644 --- a/srsenb/src/stack/upper/gtpu.cc +++ b/srsenb/src/stack/upper/gtpu.cc @@ -510,11 +510,12 @@ srsran::expected gtpu::add_bearer(uint16_t rnti, } // Return bind address for S1AP and NGAP setup - struct in_addr inaddr; - if ((inet_pton(AF_INET, gtp_bind_addr.c_str(), &inaddr)) < 1) { + uint8_t addr_in_tmp[4]; + if ((inet_pton(AF_INET, gtp_bind_addr.c_str(), &addr_in_tmp)) < 1) { logger.error("Invalid address or failure during conversion: %s\n", gtp_bind_addr.c_str()); } - addr_in = ntohl(inaddr.s_addr); + addr_in = 0; + addr_in = addr_in_tmp[3] | (addr_in_tmp[2] << 8) | (addr_in_tmp[1] << 16) | (addr_in_tmp[0] << 24); return teid_in; }