[S] Change in libosmo-pfcp[master]: pfcp_msg: Introduce API osmo_pfcp_ie_node_id_from_str()
pespin has uploaded this change for review. ( https://gerrit.osmocom.org/c/libosmo-pfcp/+/44073?usp=email ) Change subject: pfcp_msg: Introduce API osmo_pfcp_ie_node_id_from_str() ...................................................................... pfcp_msg: Introduce API osmo_pfcp_ie_node_id_from_str() This API is useful in parsing a string input containing an IP(v4 or v6) address or an FQDN. Related: SYS#7719 Depends: libosmocore.git Change-id I196dc4ab58ab300e2b16daeb214278cfb9bb8226 Change-Id: Ibfb53fddb618a4480d873ceb783e56c0a0e5fead --- M TODO-RELEASE M include/osmocom/pfcp/pfcp_msg.h M src/libosmo-pfcp/pfcp_msg.c 3 files changed, 33 insertions(+), 0 deletions(-) git pull ssh://gerrit.osmocom.org:29418/libosmo-pfcp refs/changes/73/44073/1 diff --git a/TODO-RELEASE b/TODO-RELEASE index 0ed7189..0c339f7 100644 --- a/TODO-RELEASE +++ b/TODO-RELEASE @@ -7,3 +7,5 @@ # 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 add osmo_pfcp_ie_node_id_from_str() +libosmcore >1.14.2 osmo_sockaddr_pton() diff --git a/include/osmocom/pfcp/pfcp_msg.h b/include/osmocom/pfcp/pfcp_msg.h index 2fde3e5..c0f8fb5 100644 --- a/include/osmocom/pfcp/pfcp_msg.h +++ b/include/osmocom/pfcp/pfcp_msg.h @@ -168,6 +168,7 @@ int osmo_pfcp_ie_node_id_from_osmo_sockaddr(struct osmo_pfcp_ie_node_id *node_id, const struct osmo_sockaddr *os); int osmo_pfcp_ie_node_id_to_osmo_sockaddr(const struct osmo_pfcp_ie_node_id *node_id, struct osmo_sockaddr *os); +int osmo_pfcp_ie_node_id_from_str(struct osmo_pfcp_ie_node_id *node_id, const char *str); int osmo_pfcp_ie_node_id_cmp(const struct osmo_pfcp_ie_node_id *a, const struct osmo_pfcp_ie_node_id *b); #define OSMO_PFCP_MSG_MEMB(M, OFS) ((OFS) <= 0 ? NULL : (void *)((uint8_t *)(M) + OFS)) diff --git a/src/libosmo-pfcp/pfcp_msg.c b/src/libosmo-pfcp/pfcp_msg.c index 2e0db31..ccf4fe1 100644 --- a/src/libosmo-pfcp/pfcp_msg.c +++ b/src/libosmo-pfcp/pfcp_msg.c @@ -135,6 +135,36 @@ return 0; } +int osmo_pfcp_ie_node_id_from_str(struct osmo_pfcp_ie_node_id *node_id, const char *str) +{ + int rc; + + if (!str) + return -EINVAL; + if (str[0] == '\0') + return -EINVAL; + + rc = osmo_sockaddr_pton(str, &node_id->ip.u.sa); + + if (rc != 1) { /* pton() failed, assume fqdn: */ + node_id->type = OSMO_PFCP_NODE_ID_T_FQDN; + OSMO_STRLCPY_ARRAY(node_id->fqdn, str); + return 0; + } + + switch (node_id->ip.u.sa.sa_family) { + case AF_INET: + node_id->type = OSMO_PFCP_NODE_ID_T_IPV4; + break; + case AF_INET6: + node_id->type = OSMO_PFCP_NODE_ID_T_IPV6; + break; + default: + return -ENOTSUP; + } + return 0; +} + int osmo_pfcp_ie_node_id_cmp(const struct osmo_pfcp_ie_node_id *a, const struct osmo_pfcp_ie_node_id *b) { if (a == b) -- To view, visit https://gerrit.osmocom.org/c/libosmo-pfcp/+/44073?usp=email To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings?usp=email Gerrit-MessageType: newchange Gerrit-Project: libosmo-pfcp Gerrit-Branch: master Gerrit-Change-Id: Ibfb53fddb618a4480d873ceb783e56c0a0e5fead Gerrit-Change-Number: 44073 Gerrit-PatchSet: 1 Gerrit-Owner: pespin <pespin@sysmocom.de>
participants (1)
-
pespin