aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNeels Janosch Hofmeyr <nhofmeyr@sysmocom.de>2022-11-26 02:53:56 +0100
committerNeels Janosch Hofmeyr <nhofmeyr@sysmocom.de>2022-11-26 03:04:13 +0100
commitc41bfcbbf0a364eaefe1782a60e41562edd0e3aa (patch)
treeb9ceeb34b4bc72de2122cf6ccd5de1ff4b425cae
parent25c4c9b355f294c954dfed7017db9ace20d6de09 (diff)
add osmo_pfcp_ip_addrs_to_str_*()
Move static function ip_addrs_to_str_buf() to public API as osmo_pfcp_ip_addrs_to_str_buf() and osmo_pfcp_ip_addrs_to_str_c(). So far the static function was only used in places where it follows other strings, so that it made sense to always start with a comma. Move this comma out of the function to the callers. Sensibly handle a NULL pointer and an empty address set. Rationale: osmo-upf would like to print an osmo_pfcp_ip_addrs struct in logging. Change-Id: I5f67db8d347690cbb1ce273a2d072636859f1bf6
-rw-r--r--include/osmocom/pfcp/pfcp_ies_custom.h2
-rw-r--r--src/libosmo-pfcp/pfcp_ies_custom.c40
2 files changed, 33 insertions, 9 deletions
diff --git a/include/osmocom/pfcp/pfcp_ies_custom.h b/include/osmocom/pfcp/pfcp_ies_custom.h
index f273a87..565fee2 100644
--- a/include/osmocom/pfcp/pfcp_ies_custom.h
+++ b/include/osmocom/pfcp/pfcp_ies_custom.h
@@ -37,6 +37,8 @@ struct osmo_pfcp_ip_addrs {
};
int osmo_pfcp_ip_addrs_set(struct osmo_pfcp_ip_addrs *dst, const struct osmo_sockaddr *addr);
+int osmo_pfcp_ip_addrs_to_str_buf(char *buf, size_t buflen, const struct osmo_pfcp_ip_addrs *addrs);
+char *osmo_pfcp_ip_addrs_to_str_c(void *ctx, const struct osmo_pfcp_ip_addrs *addrs);
/* 3GPP TS 29.244 8.2.38, IETF RFC 1035 3.1 */
struct osmo_pfcp_ie_node_id {
diff --git a/src/libosmo-pfcp/pfcp_ies_custom.c b/src/libosmo-pfcp/pfcp_ies_custom.c
index 0175c6f..422b6a9 100644
--- a/src/libosmo-pfcp/pfcp_ies_custom.c
+++ b/src/libosmo-pfcp/pfcp_ies_custom.c
@@ -514,26 +514,41 @@ int osmo_pfcp_enc_f_seid(struct osmo_gtlv_put *tlv, const void *decoded_struct,
return 0;
}
-static int ip_addrs_to_str_buf(char *buf, size_t buflen, const struct osmo_pfcp_ip_addrs *addrs)
+int osmo_pfcp_ip_addrs_to_str_buf(char *buf, size_t buflen, const struct osmo_pfcp_ip_addrs *addrs)
{
struct osmo_strbuf sb = { .buf = buf, .len = buflen };
+ if (!addrs) {
+ OSMO_STRBUF_PRINTF(sb, "NULL-addr");
+ return sb.chars_needed;
+ }
+ if (!(addrs->v4_present || addrs->v6_present)) {
+ OSMO_STRBUF_PRINTF(sb, "empty:-addr");
+ return sb.chars_needed;
+ }
if (addrs->v4_present) {
- OSMO_STRBUF_PRINTF(sb, ",v4:");
+ OSMO_STRBUF_PRINTF(sb, "v4:");
OSMO_STRBUF_APPEND(sb, osmo_sockaddr_to_str_buf2, &addrs->v4);
}
+ if (addrs->v4_present && addrs->v6_present)
+ OSMO_STRBUF_PRINTF(sb, ",");
if (addrs->v6_present) {
- OSMO_STRBUF_PRINTF(sb, ",v6:");
+ OSMO_STRBUF_PRINTF(sb, "v6:");
OSMO_STRBUF_APPEND(sb, osmo_sockaddr_to_str_buf2, &addrs->v6);
}
return sb.chars_needed;
}
+char *osmo_pfcp_ip_addrs_to_str_c(void *ctx, const struct osmo_pfcp_ip_addrs *addrs)
+{
+ OSMO_NAME_C_IMPL(ctx, 32, "ERROR", osmo_pfcp_ip_addrs_to_str_buf, addrs)
+}
+
int osmo_pfcp_enc_to_str_f_seid(char *buf, size_t buflen, const void *encode_from)
{
const struct osmo_pfcp_ie_f_seid *f_seid = encode_from;
struct osmo_strbuf sb = { .buf = buf, .len = buflen };
- OSMO_STRBUF_PRINTF(sb, "0x%"PRIx64, f_seid->seid);
- OSMO_STRBUF_APPEND(sb, ip_addrs_to_str_buf, &f_seid->ip_addr);
+ OSMO_STRBUF_PRINTF(sb, "0x%"PRIx64",", f_seid->seid);
+ OSMO_STRBUF_APPEND(sb, osmo_pfcp_ip_addrs_to_str_buf, &f_seid->ip_addr);
return sb.chars_needed;
}
@@ -640,8 +655,8 @@ int osmo_pfcp_ie_f_teid_to_str_buf(char *buf, size_t buflen, const struct osmo_p
if (ft->choose.choose_id_present)
OSMO_STRBUF_PRINTF(sb, "-id%u", ft->choose.choose_id);
} else {
- OSMO_STRBUF_PRINTF(sb, "TEID-0x%x", ft->fixed.teid);
- OSMO_STRBUF_APPEND(sb, ip_addrs_to_str_buf, &ft->fixed.ip_addr);
+ OSMO_STRBUF_PRINTF(sb, "TEID-0x%x,", ft->fixed.teid);
+ OSMO_STRBUF_APPEND(sb, osmo_pfcp_ip_addrs_to_str_buf, &ft->fixed.ip_addr);
}
return sb.chars_needed;
}
@@ -849,7 +864,10 @@ int osmo_pfcp_enc_to_str_outer_header_creation(char *buf, size_t buflen, const v
OSMO_STRBUF_APPEND(sb, osmo_pfcp_bits_to_str_buf, ohc->desc_bits, osmo_pfcp_outer_header_creation_strs);
if (ohc->teid_present)
OSMO_STRBUF_PRINTF(sb, ",TEID:0x%x", ohc->teid);
- OSMO_STRBUF_APPEND(sb, ip_addrs_to_str_buf, &ohc->ip_addr);
+
+ OSMO_STRBUF_PRINTF(sb, ",");
+ OSMO_STRBUF_APPEND(sb, osmo_pfcp_ip_addrs_to_str_buf, &ohc->ip_addr);
+
if (ohc->port_number_present)
OSMO_STRBUF_PRINTF(sb, ",port:%u", ohc->port_number);
if (ohc->c_tag_present)
@@ -1015,7 +1033,11 @@ int osmo_pfcp_enc_to_str_ue_ip_address(char *buf, size_t buflen, const void *enc
OSMO_STRBUF_PRINTF(sb, "%schv4", sb.pos ? "," : "");
if (uia->ip_is_destination)
OSMO_STRBUF_PRINTF(sb, "%sdst", sb.pos ? "," : "");
- OSMO_STRBUF_APPEND(sb, ip_addrs_to_str_buf, &uia->ip_addr);
+
+ if (sb.pos)
+ OSMO_STRBUF_PRINTF(sb, ",");
+ OSMO_STRBUF_APPEND(sb, osmo_pfcp_ip_addrs_to_str_buf, &uia->ip_addr);
+
if (uia->ipv6_prefix_delegation_bits_present)
OSMO_STRBUF_PRINTF(sb, ",ipv6-prefix-deleg:%x", uia->ipv6_prefix_delegation_bits);
if (uia->ipv6_prefix_length_present)