neels has uploaded this change for review. ( 
https://gerrit.osmocom.org/c/libosmo-pfcp/+/36348?usp=email )


Change subject: add osmo_pfcp_ip_addrs_get
......................................................................

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
---
M include/osmocom/pfcp/pfcp_ies_custom.h
M src/libosmo-pfcp/pfcp_msg.c
2 files changed, 52 insertions(+), 0 deletions(-)



  git pull ssh://gerrit.osmocom.org:29418/libosmo-pfcp refs/changes/48/36348/1

diff --git a/include/osmocom/pfcp/pfcp_ies_custom.h 
b/include/osmocom/pfcp/pfcp_ies_custom.h
index 0540bfe..84f862a 100644
--- a/include/osmocom/pfcp/pfcp_ies_custom.h
+++ b/include/osmocom/pfcp/pfcp_ies_custom.h
@@ -25,6 +25,7 @@
 #pragma once

 #include <osmocom/core/socket.h>
+#include <osmocom/core/sockaddr_str.h>

 #include <osmocom/pfcp/pfcp_proto.h>

@@ -40,6 +41,11 @@
 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);

+int osmo_pfcp_ip_addrs_get(struct osmo_sockaddr *v4, struct osmo_sockaddr *v6,
+                          struct osmo_pfcp_ip_addrs *src);
+int osmo_pfcp_ip_addrs_get_str(struct osmo_sockaddr_str *v4, struct 
osmo_sockaddr_str *v6,
+                              struct osmo_pfcp_ip_addrs *src);
+
 /* 3GPP TS 29.244 8.2.38, IETF RFC 1035 3.1 */
 struct osmo_pfcp_ie_node_id {
        enum osmo_pfcp_node_id_type type;
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_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. */

--
To view, visit https://gerrit.osmocom.org/c/libosmo-pfcp/+/36348?usp=email
To unsubscribe, or for help writing mail filters, visit 
https://gerrit.osmocom.org/settings

Gerrit-Project: libosmo-pfcp
Gerrit-Branch: master
Gerrit-Change-Id: I4338a83f26ef2443f90cf835621e73aed5eac521
Gerrit-Change-Number: 36348
Gerrit-PatchSet: 1
Gerrit-Owner: neels <nhofm...@sysmocom.de>
Gerrit-MessageType: newchange

Reply via email to