diff options
author | Neels Janosch Hofmeyr <nhofmeyr@sysmocom.de> | 2024-03-16 05:50:14 +0100 |
---|---|---|
committer | Neels Hofmeyr <nhofmeyr@sysmocom.de> | 2024-03-19 04:42:26 +0100 |
commit | f1f869e623578a6bf694d58b5e266969ef13b18e (patch) | |
tree | 4b9efdd8447d77ff550c7bac86b6cb71acfed14f /src | |
parent | 5d2ee7e72c62db67ee3f70805e7d40f3c154209f (diff) |
add osmo_pfcp_ip_addrs_get
This pattern shows up a lot when working with PFCP. Let's make it easier
to handle IPv4 and v6 at the same time.
Change-Id: I4338a83f26ef2443f90cf835621e73aed5eac521
Diffstat (limited to 'src')
-rw-r--r-- | src/libosmo-pfcp/pfcp_msg.c | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/src/libosmo-pfcp/pfcp_msg.c b/src/libosmo-pfcp/pfcp_msg.c index abcee18..8ae5ab4 100644 --- a/src/libosmo-pfcp/pfcp_msg.c +++ b/src/libosmo-pfcp/pfcp_msg.c @@ -514,6 +514,40 @@ int osmo_pfcp_ip_addrs_set(struct osmo_pfcp_ip_addrs *dst, const struct osmo_soc } } +int osmo_pfcp_ip_addrs_get(struct osmo_sockaddr *v4, struct osmo_sockaddr *v6, struct osmo_pfcp_ip_addrs *src) +{ + if (v4) { + if (src->v4_present) + *v4 = src->v4; + else + *v4 = (struct osmo_sockaddr){}; + } + if (v6) { + if (src->v6_present) + *v6 = src->v6; + else + *v6 = (struct osmo_sockaddr){}; + } + return 0; +} + +int osmo_pfcp_ip_addrs_get_str(struct osmo_sockaddr_str *v4, struct osmo_sockaddr_str *v6, struct osmo_pfcp_ip_addrs *src) +{ + if (v4) { + if (src->v4_present) + return osmo_sockaddr_str_from_sockaddr(v4, &src->v4.u.sas); + else + *v4 = (struct osmo_sockaddr_str){}; + } + if (v6) { + if (src->v6_present) + return osmo_sockaddr_str_from_sockaddr(v6, &src->v6.u.sas); + else + *v6 = (struct osmo_sockaddr_str){}; + } + return 0; +} + /* If a osmo_fsm_inst placed in m->ctx deallocates before the osmo_pfcp_msg, call this function, to make sure to avoid * use after free. Alternatively use m->ctx.*_use_count to make sure the FSM inst does not deallocate before the * osmo_pfcp_msg is discarded from the resend queue. */ |