pespin has uploaded this change for review. ( 
https://gerrit.osmocom.org/c/osmo-ggsn/+/15250


Change subject: Move pdp_get_peer_ipv() to lib/util.*
......................................................................

Move pdp_get_peer_ipv() to lib/util.*

Preparation for next commit, where this function will be needed inside
libmisc (lib/*).

Change-Id: Ibab4f6c09d1e5f0e9cfaea28ae1e7ab5b5c219b5
---
M ggsn/ggsn.c
M ggsn/ggsn.h
M ggsn/ggsn_vty.c
M ggsn/pco.c
M lib/Makefile.am
A lib/util.c
A lib/util.h
7 files changed, 60 insertions(+), 23 deletions(-)



  git pull ssh://gerrit.osmocom.org:29418/osmo-ggsn refs/changes/50/15250/1

diff --git a/ggsn/ggsn.c b/ggsn/ggsn.c
index d519621..35f2527 100644
--- a/ggsn/ggsn.c
+++ b/ggsn/ggsn.c
@@ -51,6 +51,7 @@
 #include "../lib/syserr.h"
 #include "../lib/in46_addr.h"
 #include "../lib/gtp-kernel.h"
+#include "../lib/util.h"
 #include "../gtp/pdp.h"
 #include "../gtp/gtp.h"
 #include "icmpv6.h"
@@ -365,26 +366,6 @@
        return 0;
 }

-/*! Get the peer of pdp based on IP version used.
- *  \param[in] pdp PDP context to select the peer from.
- *  \param[in] v4v6 IP version to select. Valid values are 4 and 6.
- *  \returns The selected peer matching the given IP version. NULL if not 
present.
- */
-struct ippoolm_t *pdp_get_peer_ipv(struct pdp_t *pdp, bool is_ipv6) {
-       uint8_t i;
-
-       for (i = 0; i < 2; i++) {
-               struct ippoolm_t * ippool = pdp->peer[i];
-               if (!ippool)
-                       continue;
-               if (is_ipv6 && in46a_is_v6(&ippool->addr))
-                       return ippool;
-               else if (!is_ipv6 && in46a_is_v4(&ippool->addr))
-                       return ippool;
-       }
-       return NULL;
-}
-
 static bool apn_supports_ipv4(const struct apn_ctx *apn)
 {
        if (apn->v4.cfg.static_prefix.addr.len  || 
apn->v4.cfg.dynamic_prefix.addr.len)
diff --git a/ggsn/ggsn.h b/ggsn/ggsn.h
index 1bd067e..88fd8b9 100644
--- a/ggsn/ggsn.h
+++ b/ggsn/ggsn.h
@@ -145,7 +145,6 @@
 extern int ggsn_stop(struct ggsn_ctx *ggsn);
 extern int apn_start(struct apn_ctx *apn);
 extern int apn_stop(struct apn_ctx *apn);
-extern struct ippoolm_t *pdp_get_peer_ipv(struct pdp_t *pdp, bool is_ipv6);

 #define LOGPAPN(level, apn, fmt, args...)                      \
        LOGP(DGGSN, level, "APN(%s): " fmt, (apn)->cfg.name, ## args)
diff --git a/ggsn/ggsn_vty.c b/ggsn/ggsn_vty.c
index 0a86f49..b85df77 100644
--- a/ggsn/ggsn_vty.c
+++ b/ggsn/ggsn_vty.c
@@ -37,6 +37,8 @@
 #include "../gtp/gtp.h"
 #include "../gtp/pdp.h"

+#include "../lib/util.h"
+
 #include "ggsn.h"

 #define PREFIX_STR     "Prefix (Network/Netmask)\n"
diff --git a/ggsn/pco.c b/ggsn/pco.c
index a55b768..a495e86 100644
--- a/ggsn/pco.c
+++ b/ggsn/pco.c
@@ -15,6 +15,8 @@
 #include <osmocom/core/msgb.h>
 #include <osmocom/gsm/tlv.h>

+#include "../lib/util.h"
+
 #include "pco.h"
 #include "ggsn.h"

diff --git a/lib/Makefile.am b/lib/Makefile.am
index b6e7aba..533d777 100644
--- a/lib/Makefile.am
+++ b/lib/Makefile.am
@@ -1,10 +1,10 @@
 noinst_LIBRARIES = libmisc.a

-noinst_HEADERS = gnugetopt.h ippool.h lookup.h syserr.h tun.h in46_addr.h 
netdev.h gtp-kernel.h
+noinst_HEADERS = gnugetopt.h ippool.h lookup.h syserr.h tun.h in46_addr.h 
netdev.h gtp-kernel.h util.h

 AM_CFLAGS = -O2 -fno-builtin -Wall -DSBINDIR='"$(sbindir)"' -ggdb 
$(LIBOSMOCORE_CFLAGS)

-libmisc_a_SOURCES = getopt1.c getopt.c ippool.c lookup.c tun.c debug.c 
in46_addr.c netdev.c
+libmisc_a_SOURCES = getopt1.c getopt.c ippool.c lookup.c tun.c debug.c 
in46_addr.c netdev.c util.c

 if ENABLE_GTP_KERNEL
 AM_CFLAGS += -DGTP_KERNEL $(LIBGTPNL_CFLAGS)
diff --git a/lib/util.c b/lib/util.c
new file mode 100644
index 0000000..6bb0d85
--- /dev/null
+++ b/lib/util.c
@@ -0,0 +1,35 @@
+/*
+ * misc helpers
+ * Copyright 2019 sysmocom - s.f.m.c. GmbH <[email protected]>
+ *
+ * The contents of this file may be used under the terms of the GNU
+ * General Public License Version 2, provided that the above copyright
+ * notice and this permission notice is included in all copies or
+ * substantial portions of the software.
+ *
+ */
+
+#include "../gtp/pdp.h"
+
+#include "ippool.h"
+#include "in46_addr.h"
+
+/*! Get the peer of pdp based on IP version used.
+*  \param[in] pdp PDP context to select the peer from.
+*  \param[in] v4v6 IP version to select. Valid values are 4 and 6.
+*  \returns The selected peer matching the given IP version. NULL if not 
present.
+*/
+struct ippoolm_t *pdp_get_peer_ipv(struct pdp_t *pdp, bool is_ipv6) {
+       uint8_t i;
+
+       for (i = 0; i < 2; i++) {
+               struct ippoolm_t * ippool = pdp->peer[i];
+               if (!ippool)
+                       continue;
+               if (is_ipv6 && in46a_is_v6(&ippool->addr))
+                       return ippool;
+               else if (!is_ipv6 && in46a_is_v4(&ippool->addr))
+                       return ippool;
+       }
+       return NULL;
+}
diff --git a/lib/util.h b/lib/util.h
new file mode 100644
index 0000000..bc9674d
--- /dev/null
+++ b/lib/util.h
@@ -0,0 +1,18 @@
+#pragma once
+/*
+ * misc helpers
+ * Copyright 2019 sysmocom - s.f.m.c. GmbH <[email protected]>
+ *
+ * The contents of this file may be used under the terms of the GNU
+ * General Public License Version 2, provided that the above copyright
+ * notice and this permission notice is included in all copies or
+ * substantial portions of the software.
+ *
+ */
+
+#include <stdbool.h>
+
+struct ippoolm_t;
+struct pdp_t;
+
+struct ippoolm_t *pdp_get_peer_ipv(struct pdp_t *pdp, bool is_ipv6);

--
To view, visit https://gerrit.osmocom.org/c/osmo-ggsn/+/15250
To unsubscribe, or for help writing mail filters, visit 
https://gerrit.osmocom.org/settings

Gerrit-Project: osmo-ggsn
Gerrit-Branch: master
Gerrit-Change-Id: Ibab4f6c09d1e5f0e9cfaea28ae1e7ab5b5c219b5
Gerrit-Change-Number: 15250
Gerrit-PatchSet: 1
Gerrit-Owner: pespin <[email protected]>
Gerrit-MessageType: newchange

Reply via email to