[PATCH] openggsn[master]: in46_addr: Add new function in46a_prefix_equal()

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
Wed Aug 9 20:15:45 UTC 2017


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

in46_addr: Add new function in46a_prefix_equal()

This function is used to compare an IPv6 address against another,
using the smaller of the two prefix lengths.

Change-Id: Ic993d8abdc90897cb55276f01ae3b8a5eadf5a0d
---
M lib/in46_addr.c
M lib/in46_addr.h
2 files changed, 18 insertions(+), 0 deletions(-)


  git pull ssh://gerrit.osmocom.org:29418/openggsn refs/changes/56/3456/1

diff --git a/lib/in46_addr.c b/lib/in46_addr.c
index 844e318..a220583 100644
--- a/lib/in46_addr.c
+++ b/lib/in46_addr.c
@@ -74,6 +74,23 @@
 		return 0;
 }
 
+/*! Determine if two in46_addr prefix are equal or not
+ *  The prefix length is determined by the shortest of the prefixes of a and b
+ *  \returns 1 in case the common prefix are equal; 0 otherwise */
+int in46a_prefix_equal(const struct in46_addr *a, const struct in46_addr *b)
+{
+	unsigned int len;
+	if (a->len > b->len)
+		len = b->len;
+	else
+		len = a->len;
+
+	if (!memcmp(&a->v6, &b->v6, len))
+		return 1;
+	else
+		return 0;
+}
+
 /*! Match if IPv6 addr1 + addr2 are within same \a mask */
 static int ipv6_within_mask(const struct in6_addr *addr1, const struct in6_addr *addr2,
 			    const struct in6_addr *mask)
diff --git a/lib/in46_addr.h b/lib/in46_addr.h
index a0ad6e1..0afd2b4 100644
--- a/lib/in46_addr.h
+++ b/lib/in46_addr.h
@@ -18,6 +18,7 @@
 extern int in46a_to_sas(struct sockaddr_storage *out, const struct in46_addr *in);
 extern const char *in46a_ntop(const struct in46_addr *in, char *dst, socklen_t dst_size);
 extern int in46a_equal(const struct in46_addr *a, const struct in46_addr *b);
+extern int in46a_prefix_equal(const struct in46_addr *a, const struct in46_addr *b);
 extern int in46a_within_mask(const struct in46_addr *addr, const struct in46_addr *net, size_t prefixlen);
 
 int in46a_to_eua(const struct in46_addr *src, struct ul66_t *eua);

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

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



More information about the gerrit-log mailing list