aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNeels Janosch Hofmeyr <nhofmeyr@sysmocom.de>2022-12-01 03:05:58 +0100
committerNeels Janosch Hofmeyr <nhofmeyr@sysmocom.de>2022-12-08 04:23:09 +0100
commit8368e7d5d59140fc77b890493a47a08cd644e2f8 (patch)
treedc930c39506d69026a3220b288d99d82c9876ed5
parent2ee6a68045bfa3237f28952fd1b456966742a8b0 (diff)
fix coding of Network Instance IE
Network instance names should be coded like in DNS, where each label is preceded by a length byte. Related: SYS#6192 Change-Id: I9d67464ef0f92b0512cfd6e48d203f8828a82a19
-rw-r--r--TODO-RELEASE1
-rw-r--r--configure.ac1
-rw-r--r--contrib/libosmo-pfcp.spec.in1
-rw-r--r--src/libosmo-pfcp/Makefile.am2
-rw-r--r--src/libosmo-pfcp/pfcp_ies_custom.c21
-rw-r--r--tests/libosmo-pfcp/Makefile.am2
-rw-r--r--tests/libosmo-pfcp/pfcp_test.ok8
7 files changed, 28 insertions, 8 deletions
diff --git a/TODO-RELEASE b/TODO-RELEASE
index d0852fc..19c1fce 100644
--- a/TODO-RELEASE
+++ b/TODO-RELEASE
@@ -7,3 +7,4 @@
# If any interfaces have been added since the last public release: c:r:a + 1.
# If any interfaces have been removed or changed since the last public release: c:r:0.
#library what description / commit summary line
+libosmo-pfcp libosmogsm>=1.7.0 libosmo-pfcp now uses API from libosmogsm (from libosmocore.git)
diff --git a/configure.ac b/configure.ac
index ba7ff86..4d10d3f 100644
--- a/configure.ac
+++ b/configure.ac
@@ -38,6 +38,7 @@ PKG_PROG_PKG_CONFIG([0.20])
dnl checks for libraries
PKG_CHECK_MODULES(LIBOSMOCORE, libosmocore >= 1.7.0)
+PKG_CHECK_MODULES(LIBOSMOGSM, libosmogsm >= 1.7.0)
dnl checks for header files
AC_HEADER_STDC
diff --git a/contrib/libosmo-pfcp.spec.in b/contrib/libosmo-pfcp.spec.in
index d6481c2..e789ef6 100644
--- a/contrib/libosmo-pfcp.spec.in
+++ b/contrib/libosmo-pfcp.spec.in
@@ -12,6 +12,7 @@ BuildRequires: libtool >= 2
BuildRequires: lksctp-tools-devel
BuildRequires: pkgconfig >= 0.20
BuildRequires: pkgconfig(libosmocore) >= 1.7.0
+BuildRequires: pkgconfig(libosmogsm) >= 1.7.0
BuildRequires: pkgconfig(talloc)
%description
diff --git a/src/libosmo-pfcp/Makefile.am b/src/libosmo-pfcp/Makefile.am
index d202c6a..6ca88b8 100644
--- a/src/libosmo-pfcp/Makefile.am
+++ b/src/libosmo-pfcp/Makefile.am
@@ -9,12 +9,14 @@ AM_CPPFLAGS = \
AM_CFLAGS = \
-Wall \
$(LIBOSMOCORE_CFLAGS) \
+ $(LIBOSMOGSM_CFLAGS) \
$(LIBOSMOVTY_CFLAGS) \
$(COVERAGE_CFLAGS) \
$(NULL)
AM_LDFLAGS = \
$(LIBOSMOCORE_LIBS) \
+ $(LIBOSMOGSM_LIBS) \
$(LIBOSMOVTY_LIBS) \
$(COVERAGE_LDFLAGS) \
$(NULL)
diff --git a/src/libosmo-pfcp/pfcp_ies_custom.c b/src/libosmo-pfcp/pfcp_ies_custom.c
index 1891902..736f39d 100644
--- a/src/libosmo-pfcp/pfcp_ies_custom.c
+++ b/src/libosmo-pfcp/pfcp_ies_custom.c
@@ -29,6 +29,7 @@
#include <osmocom/core/logging.h>
#include <osmocom/core/utils.h>
#include <osmocom/core/msgb.h>
+#include <osmocom/gsm/apn.h>
#include <osmocom/gtlv/gtlv.h>
@@ -81,6 +82,13 @@
tlv->len - ((POS) - tlv->val)); \
} while (0)
+#define ENSURE_RANGE(NAME, VAL, MINVAL, MAXVAL) \
+ do { \
+ if ((VAL) < (MINVAL) || (VAL) > (MAXVAL)) \
+ RETURN_ERROR(-ERANGE, "%s == %d, should be in range %d .. %d", NAME, \
+ (int)(VAL), (int)(MINVAL), (int)(MAXVAL)); \
+ } while (0)
+
void osmo_pfcp_ie_f_seid_set(struct osmo_pfcp_ie_f_seid *f_seid, uint64_t seid, const struct osmo_sockaddr *remote_addr)
{
*f_seid = (struct osmo_pfcp_ie_f_seid) {
@@ -698,16 +706,21 @@ int osmo_pfcp_enc_to_str_apply_action(char *buf, size_t buflen, const void *enco
int osmo_pfcp_dec_network_inst(void *decoded_struct, void *decode_to, const struct osmo_gtlv_load *tlv)
{
struct osmo_pfcp_ie_network_inst *network_inst = decode_to;
- osmo_strlcpy(network_inst->str, (const char *)tlv->val, OSMO_MIN(sizeof(network_inst->str), tlv->len+1));
+ ENSURE_RANGE("Network Instance value length", tlv->len, 1, sizeof(network_inst->str));
+ if (osmo_apn_to_str(network_inst->str, tlv->val, tlv->len) == NULL)
+ RETURN_ERROR(-EINVAL, "osmo_apn_to_str() failed");
return 0;
}
int osmo_pfcp_enc_network_inst(struct osmo_gtlv_put *tlv, const void *decoded_struct, const void *encode_from)
{
const struct osmo_pfcp_ie_network_inst *network_inst = encode_from;
- unsigned int l = strlen(network_inst->str);
- if (l)
- memcpy(msgb_put(tlv->dst, l), network_inst->str, l);
+ int rc;
+
+ rc = osmo_apn_from_str(tlv->dst->tail, msgb_tailroom(tlv->dst), network_inst->str);
+ if (rc <= 0)
+ RETURN_ERROR(-EINVAL, "osmo_apn_from_str(\"%s\") failed", network_inst->str);
+ msgb_put(tlv->dst, rc);
return 0;
}
diff --git a/tests/libosmo-pfcp/Makefile.am b/tests/libosmo-pfcp/Makefile.am
index e9ff6d3..f4314f2 100644
--- a/tests/libosmo-pfcp/Makefile.am
+++ b/tests/libosmo-pfcp/Makefile.am
@@ -7,6 +7,7 @@ AM_CPPFLAGS = \
AM_CFLAGS = \
-Wall \
$(LIBOSMOCORE_CFLAGS) \
+ $(LIBOSMOGSM_CFLAGS) \
$(NULL)
check_PROGRAMS = \
@@ -24,6 +25,7 @@ pfcp_test_SOURCES = \
pfcp_test_LDADD = \
$(top_builddir)/src/libosmo-pfcp/libosmo-pfcp.la \
$(top_builddir)/src/libosmo-gtlv/libosmo-gtlv.la \
+ $(LIBOSMOGSM_LIBS) \
$(LIBOSMOCORE_LIBS) \
$(NULL)
diff --git a/tests/libosmo-pfcp/pfcp_test.ok b/tests/libosmo-pfcp/pfcp_test.ok
index b8eddb9..02424cd 100644
--- a/tests/libosmo-pfcp/pfcp_test.ok
+++ b/tests/libosmo-pfcp/pfcp_test.ok
@@ -69,8 +69,8 @@ parsed == orig
encoding: SESSION_EST_REQ
PFCPv1 SESSION_EST_REQ hdr={seq=7 SEID=0x0} ies={ 'Node ID'=v4:127.0.0.1 'F-SEID'=0x1234567890abcdef,v4:10.9.8.7 'Create PDR'={ { 'PDR ID'=1 'Precedence'=255 'PDI'={ 'Source Interface'=Core 'Network Instance'="foo" 'UE IP Address'=,dst,v4:192.168.0.23 } 'FAR ID'=1 }, { 'PDR ID'=2 'Precedence'=255 'PDI'={ 'Source Interface'=Access 'F-TEID'=CHOOSE-v4 'Network Instance'="bar" } 'Outer Header Removal'=GTP_U_UDP_IPV4 'FAR ID'=2 } } 'Create FAR'={ { 'FAR ID'=1 'Apply Action'=( FORW ) 'Forwarding Parameters'={ 'Destination Interface'=Access 'Outer Header Creation'=( GTP_U_UDP_IPV4 ),TEID:0xabcdef,v4:10.9.8.7 } }, { 'FAR ID'=2 'Apply Action'=( FORW ) 'Forwarding Parameters'={ 'Destination Interface'=Core } } } }
osmo_pfcp_msg_encode() rc = 0
-21 32 00 d1 00 00 00 00 00 00 00 00 00 00 07 00 00 3c 00 05 00 7f 00 00 01 00 39 00 0d 02 12 34 56 78 90 ab cd ef 0a 09 08 07 00 01 00 2f 00 38 00 02 00 01 00 1d 00 04 00 00 00 ff 00 02 00 15 00 14 00 01 01 00 16 00 03 66 6f 6f 00 5d 00 05 06 c0 a8 00 17 00 6c 00 04 00 00 00 01 00 01 00 30 00 38 00 02 00 02 00 1d 00 04 00 00 00 ff 00 02 00 11 00 14 00 01 00 00 15 00 01 05 00 16 00 03 62 61 72 00 5f 00 01 00 00 6c 00 04 00 00 00 02 00 03 00 25 00 6c 00 04 00 00 00 01 00 2c 00 02 02 00 00 04 00 13 00 2a 00 01 00 00 54 00 0a 01 00 00 ab cd ef 0a 09 08 07 00 03 00 17 00 6c 00 04 00 00 00 02 00 2c 00 02 02 00 00 04 00 05 00 2a 00 01 01 .
-osmo_pfcp_msg_decode_header() rc = 213
+21 32 00 d3 00 00 00 00 00 00 00 00 00 00 07 00 00 3c 00 05 00 7f 00 00 01 00 39 00 0d 02 12 34 56 78 90 ab cd ef 0a 09 08 07 00 01 00 30 00 38 00 02 00 01 00 1d 00 04 00 00 00 ff 00 02 00 16 00 14 00 01 01 00 16 00 04 03 66 6f 6f 00 5d 00 05 06 c0 a8 00 17 00 6c 00 04 00 00 00 01 00 01 00 31 00 38 00 02 00 02 00 1d 00 04 00 00 00 ff 00 02 00 12 00 14 00 01 00 00 15 00 01 05 00 16 00 04 03 62 61 72 00 5f 00 01 00 00 6c 00 04 00 00 00 02 00 03 00 25 00 6c 00 04 00 00 00 01 00 2c 00 02 02 00 00 04 00 13 00 2a 00 01 00 00 54 00 0a 01 00 00 ab cd ef 0a 09 08 07 00 03 00 17 00 6c 00 04 00 00 00 02 00 2c 00 02 02 00 00 04 00 05 00 2a 00 01 01 .
+osmo_pfcp_msg_decode_header() rc = 215
rc == msgb_length()
osmo_pfcp_msg_decode_tlv() rc = 0
parsed == orig
@@ -91,8 +91,8 @@ parsed == orig
encoding: SESSION_MOD_REQ
PFCPv1 SESSION_MOD_REQ hdr={seq=9 SEID=0x0} ies={ 'Remove PDR'={ { 'PDR ID'=1 } } 'Remove FAR'={ { 'FAR ID'=1 } } 'Create PDR'={ { 'PDR ID'=3 'Precedence'=255 'PDI'={ 'Source Interface'=Access 'F-TEID'=CHOOSE-v4 'Network Instance'="baz" } 'Outer Header Removal'=GTP_U_UDP_IPV4 'FAR ID'=3 } } 'Create FAR'={ { 'FAR ID'=3 'Apply Action'=( FORW ) 'Forwarding Parameters'={ 'Destination Interface'=Access 'Outer Header Creation'=( GTP_U_UDP_IPV4 ),TEID:0xabcdef,v4:10.9.8.7 } } } 'Update PDR'={ { 'PDR ID'=1 'Outer Header Removal'=GTP_U_UDP_IPV4 'PDI'={ 'Source Interface'=Access 'F-TEID'=CHOOSE-v4 'Network Instance'="moo" } 'FAR ID'=1 } } 'Update FAR'={ { 'FAR ID'=1 'Update Forwarding Parameters'={ 'Network Instance'="internet" } } } }
osmo_pfcp_msg_encode() rc = 0
-21 34 00 c7 00 00 00 00 00 00 00 00 00 00 09 00 00 0f 00 06 00 38 00 02 00 01 00 10 00 08 00 6c 00 04 00 00 00 01 00 01 00 30 00 38 00 02 00 03 00 1d 00 04 00 00 00 ff 00 02 00 11 00 14 00 01 00 00 15 00 01 05 00 16 00 03 62 61 7a 00 5f 00 01 00 00 6c 00 04 00 00 00 03 00 03 00 25 00 6c 00 04 00 00 00 03 00 2c 00 02 02 00 00 04 00 13 00 2a 00 01 00 00 54 00 0a 01 00 00 ab cd ef 0a 09 08 07 00 09 00 28 00 38 00 02 00 01 00 5f 00 01 00 00 02 00 11 00 14 00 01 00 00 15 00 01 05 00 16 00 03 6d 6f 6f 00 6c 00 04 00 00 00 01 00 0a 00 18 00 6c 00 04 00 00 00 01 00 0b 00 0c 00 16 00 08 69 6e 74 65 72 6e 65 74 .
-osmo_pfcp_msg_decode_header() rc = 203
+21 34 00 ca 00 00 00 00 00 00 00 00 00 00 09 00 00 0f 00 06 00 38 00 02 00 01 00 10 00 08 00 6c 00 04 00 00 00 01 00 01 00 31 00 38 00 02 00 03 00 1d 00 04 00 00 00 ff 00 02 00 12 00 14 00 01 00 00 15 00 01 05 00 16 00 04 03 62 61 7a 00 5f 00 01 00 00 6c 00 04 00 00 00 03 00 03 00 25 00 6c 00 04 00 00 00 03 00 2c 00 02 02 00 00 04 00 13 00 2a 00 01 00 00 54 00 0a 01 00 00 ab cd ef 0a 09 08 07 00 09 00 29 00 38 00 02 00 01 00 5f 00 01 00 00 02 00 12 00 14 00 01 00 00 15 00 01 05 00 16 00 04 03 6d 6f 6f 00 6c 00 04 00 00 00 01 00 0a 00 19 00 6c 00 04 00 00 00 01 00 0b 00 0d 00 16 00 09 08 69 6e 74 65 72 6e 65 74 .
+osmo_pfcp_msg_decode_header() rc = 206
rc == msgb_length()
osmo_pfcp_msg_decode_tlv() rc = 0
parsed == orig