[PATCH] osmo-ggsn[master]: factor out netdev_ip_local_get() from tun_ip_local_get()

This is merely a historical archive of years 2008-2021, before the migration to mailman3.

A maintained and still updated list archive can be found at https://lists.osmocom.org/hyperkitty/list/gerrit-log@lists.osmocom.org/.

Harald Welte gerrit-no-reply at lists.osmocom.org
Sun Nov 12 22:13:55 UTC 2017


Review at  https://gerrit.osmocom.org/4814

factor out netdev_ip_local_get() from tun_ip_local_get()

netdev_ip_local_get() is a generalized version of tun_ip_local_get()
which supports the net device as argument, rather than a tun_t.

Change-Id: I072aa1a55e7bf110706e9207021b776d9b977fb6
---
M lib/tun.c
M lib/tun.h
2 files changed, 25 insertions(+), 4 deletions(-)


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

diff --git a/lib/tun.c b/lib/tun.c
index 3c293a2..fcd04f3 100644
--- a/lib/tun.c
+++ b/lib/tun.c
@@ -750,8 +750,8 @@
 
 #include <ifaddrs.h>
 
-/*! Obtain the local address of the tun device.
- *  \param[in] tun Target device owning the IP
+/*! Obtain the local address of a network device
+ *  \param[in] devname Target device owning the IP
  *  \param[out] prefix_list List of prefix structures to fill with each IPv4/6 and prefix length found.
  *  \param[in] prefix_size Amount of elements allowed to be fill in the prefix_list array.
  *  \param[in] flags Specify which kind of IP to look for: IP_TYPE_IPv4, IP_TYPE_IPv6_LINK, IP_TYPE_IPv6_NONLINK
@@ -763,7 +763,7 @@
  * prefix_size. It can be used with prefix_size=0 to get an estimate of the size
  * needed for prefix_list.
  */
-int tun_ip_local_get(const struct tun_t *tun, struct in46_prefix *prefix_list, size_t prefix_size, int flags)
+int netdev_ip_local_get(const char *devname, struct in46_prefix *prefix_list, size_t prefix_size, int flags)
 {
 	static const uint8_t ll_prefix[] = { 0xfe,0x80, 0,0, 0,0, 0,0 };
 	struct ifaddrs *ifaddr, *ifa;
@@ -779,7 +779,7 @@
 		if (ifa->ifa_addr == NULL)
 			continue;
 
-		if (strcmp(ifa->ifa_name, tun->devname))
+		if (strcmp(ifa->ifa_name, devname))
 			continue;
 
 		if (ifa->ifa_addr->sa_family == AF_INET && (flags & IP_TYPE_IPv4)) {
@@ -820,3 +820,21 @@
 	freeifaddrs(ifaddr);
 	return count;
 }
+
+/*! Obtain the local address of the tun device.
+ *  \param[in] tun Target device owning the IP
+ *  \param[out] prefix_list List of prefix structures to fill with each IPv4/6 and prefix length found.
+ *  \param[in] prefix_size Amount of elements allowed to be fill in the prefix_list array.
+ *  \param[in] flags Specify which kind of IP to look for: IP_TYPE_IPv4, IP_TYPE_IPv6_LINK, IP_TYPE_IPv6_NONLINK
+ *  \returns The number of ips found following the criteria specified by flags, -1 on error.
+ *
+ * This function will fill prefix_list with up to prefix_size IPs following the
+ * criteria specified by flags parameter. It returns the number of IPs matching
+ * the criteria. As a result, the number returned can be bigger than
+ * prefix_size. It can be used with prefix_size=0 to get an estimate of the size
+ * needed for prefix_list.
+ */
+int tun_ip_local_get(const struct tun_t *tun, struct in46_prefix *prefix_list, size_t prefix_size, int flags)
+{
+	return netdev_ip_local_get(tun->devname, prefix_list, prefix_size, flags);
+}
diff --git a/lib/tun.h b/lib/tun.h
index 0b960e5..411deea 100644
--- a/lib/tun.h
+++ b/lib/tun.h
@@ -95,6 +95,9 @@
 
 extern int tun_runscript(struct tun_t *tun, char *script);
 
+int netdev_ip_local_get(const char *devname, struct in46_prefix *prefix_list,
+			size_t prefix_size, int flags);
+
 int tun_ip_local_get(const struct tun_t *tun, struct in46_prefix *prefix_list,
 		     size_t prefix_size, int flags);
 

-- 
To view, visit https://gerrit.osmocom.org/4814
To unsubscribe, visit https://gerrit.osmocom.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I072aa1a55e7bf110706e9207021b776d9b977fb6
Gerrit-PatchSet: 1
Gerrit-Project: osmo-ggsn
Gerrit-Branch: master
Gerrit-Owner: Harald Welte <laforge at gnumonks.org>



More information about the gerrit-log mailing list