Change in ...osmo-ggsn[master]: Introduce in46a_is_v{4,6}() helpers

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/.

pespin gerrit-no-reply at lists.osmocom.org
Tue Aug 20 10:31:46 UTC 2019


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


Change subject: Introduce in46a_is_v{4,6}() helpers
......................................................................

Introduce in46a_is_v{4,6}() helpers

It's clearer having size-related checks in one place for a daa structure
in46_addr, instead of spread around the code.

Change-Id: Idc94bf0c8c01bb5a30e36d3c284b99f66b972abb
---
M ggsn/ggsn.c
M lib/in46_addr.h
2 files changed, 16 insertions(+), 12 deletions(-)



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

diff --git a/ggsn/ggsn.c b/ggsn/ggsn.c
index 95371a2..593c319 100644
--- a/ggsn/ggsn.c
+++ b/ggsn/ggsn.c
@@ -482,19 +482,15 @@
  *  \returns The selected peer matching the given IP version. NULL if not present.
  */
 static struct ippoolm_t *pdp_get_peer_ipv(struct pdp_t *pdp, bool is_ipv6) {
-	uint8_t len1, len2, i;
-
-	if (is_ipv6) {
-		len1 = 8;
-		len2 = 16;
-	} else {
-		len1 = sizeof(struct in_addr);
-		len2 = len1;
-	}
+	uint8_t i;
 
 	for (i = 0; i < 2; i++) {
 		struct ippoolm_t * ippool = pdp->peer[i];
-		if (ippool && (ippool->addr.len == len1 || ippool->addr.len == len2))
+		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;
@@ -798,7 +794,7 @@
 
 	/* Allocate dynamic addresses from the pool */
 	for (i = 0; i < num_addr; i++) {
-		if (addr[i].len == sizeof(struct in_addr)) {
+		if (in46a_is_v4(&addr[i])) {
 			/* does this APN actually have an IPv4 pool? */
 			if (!apn_supports_ipv4(apn))
 				goto err_wrong_af;
@@ -811,7 +807,7 @@
 
 			addrv4 = member;
 
-		} else if (addr[i].len == sizeof(struct in6_addr)) {
+		} else if (in46a_is_v6(&addr[i])) {
 
 			/* does this APN actually have an IPv6 pool? */
 			if (!apn_supports_ipv6(apn))
diff --git a/lib/in46_addr.h b/lib/in46_addr.h
index e4654cc..153df00 100644
--- a/lib/in46_addr.h
+++ b/lib/in46_addr.h
@@ -31,3 +31,11 @@
 
 int in46a_to_eua(const struct in46_addr *src, unsigned int size, struct ul66_t *eua);
 int in46a_from_eua(const struct ul66_t *eua, struct in46_addr *dst);
+
+static inline bool in46a_is_v6(const struct in46_addr *addr) {
+	return addr->len == 8 || addr->len == 16;
+}
+
+static inline bool in46a_is_v4(const struct in46_addr *addr) {
+	return addr->len == sizeof(struct in_addr);
+}

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

Gerrit-Project: osmo-ggsn
Gerrit-Branch: master
Gerrit-Change-Id: Idc94bf0c8c01bb5a30e36d3c284b99f66b972abb
Gerrit-Change-Number: 15245
Gerrit-PatchSet: 1
Gerrit-Owner: pespin <pespin at sysmocom.de>
Gerrit-MessageType: newchange
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osmocom.org/pipermail/gerrit-log/attachments/20190820/1233e90a/attachment.htm>


More information about the gerrit-log mailing list