[MERGED] osmo-ggsn[master]: Replace EUA magic numbers for IETF, IPv4 and IPv6 with #defines

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 Oct 1 10:23:50 UTC 2017


Harald Welte has submitted this change and it was merged.

Change subject: Replace EUA magic numbers for IETF, IPv4 and IPv6 with #defines
......................................................................


Replace EUA magic numbers for IETF, IPv4 and IPv6 with #defines

Change-Id: I33f65e404217e717bd795e5229c8d9456a7b3739
---
M gtp/gtp.c
M gtp/pdp.c
M gtp/pdp.h
M lib/in46_addr.c
4 files changed, 17 insertions(+), 12 deletions(-)

Approvals:
  Harald Welte: Looks good to me, approved
  Jenkins Builder: Verified



diff --git a/gtp/gtp.c b/gtp/gtp.c
index fee49b5..3051aaa 100644
--- a/gtp/gtp.c
+++ b/gtp/gtp.c
@@ -3259,8 +3259,8 @@
 
 int ipv42eua(struct ul66_t *eua, struct in_addr *src)
 {
-	eua->v[0] = 0xf1;	/* IETF */
-	eua->v[1] = 0x21;	/* IPv4 */
+	eua->v[0] = PDP_EUA_ORG_IETF;
+	eua->v[1] = PDP_EUA_TYPE_v4;
 	if (src) {
 		eua->l = 6;
 		memcpy(&eua->v[2], src, 4);
@@ -3272,7 +3272,7 @@
 
 int eua2ipv4(struct in_addr *dst, struct ul66_t *eua)
 {
-	if ((eua->l != 6) || (eua->v[0] != 0xf1) || (eua->v[1] = 0x21))
+	if ((eua->l != 6) || (eua->v[0] != PDP_EUA_ORG_IETF) || (eua->v[1] != PDP_EUA_TYPE_v4))
 		return -1;	/* Not IPv4 address */
 	memcpy(dst, &eua->v[2], 4);
 	return 0;
diff --git a/gtp/pdp.c b/gtp/pdp.c
index d3e9232..b1e1ff3 100644
--- a/gtp/pdp.c
+++ b/gtp/pdp.c
@@ -367,15 +367,15 @@
 int pdp_ntoeua(struct in_addr *src, struct ul66_t *eua)
 {
 	eua->l = 6;
-	eua->v[0] = 0xf1;	/* IETF */
-	eua->v[1] = 0x21;	/* IPv4 */
+	eua->v[0] = PDP_EUA_ORG_IETF;
+	eua->v[1] = PDP_EUA_TYPE_v4;
 	memcpy(&eua->v[2], src, 4);	/* Copy a 4 byte address */
 	return 0;
 }
 
 int pdp_euaton(struct ul66_t *eua, struct in_addr *dst)
 {
-	if ((eua->l != 6) || (eua->v[0] != 0xf1) || (eua->v[1] != 0x21)) {
+	if ((eua->l != 6) || (eua->v[0] != PDP_EUA_ORG_IETF) || (eua->v[1] != PDP_EUA_TYPE_v4)) {
 		return EOF;
 	}
 	memcpy(dst, &eua->v[2], 4);	/* Copy a 4 byte address */
diff --git a/gtp/pdp.h b/gtp/pdp.h
index 106d544..f1d8ad6 100644
--- a/gtp/pdp.h
+++ b/gtp/pdp.h
@@ -23,6 +23,10 @@
 #define PDP_MAX 1024		/* Max number of PDP contexts */
 #define PDP_MAXNSAPI 16		/* Max number of NSAPI */
 
+#define PDP_EUA_ORG_IETF	0xF1
+#define PDP_EUA_TYPE_v4		0x21
+#define PDP_EUA_TYPE_v6		0x57
+
 /* GTP Information elements from 29.060 v3.9.0 7.7 Information Elements */
 /* Also covers version 0. Note that version 0 6: QOS Profile was superceded *
  * by 135: QOS Profile in version 1 */
diff --git a/lib/in46_addr.c b/lib/in46_addr.c
index 4b5fd64..f78a40b 100644
--- a/lib/in46_addr.c
+++ b/lib/in46_addr.c
@@ -10,6 +10,7 @@
  */
 
 #include "../lib/in46_addr.h"
+#include "../gtp/pdp.h"
 
 #include <osmocom/core/utils.h>
 
@@ -201,15 +202,15 @@
 	switch (src->len) {
 	case 4:
 		eua->l = 6;
-		eua->v[0] = 0xf1;	/* IETF */
-		eua->v[1] = 0x21;	/* IPv4 */
+		eua->v[0] = PDP_EUA_ORG_IETF;
+		eua->v[1] = PDP_EUA_TYPE_v4;
 		memcpy(&eua->v[2], &src->v4, 4);	/* Copy a 4 byte address */
 		break;
 	case 8:
 	case 16:
 		eua->l = 18;
-		eua->v[0] = 0xf1;	/* IETF */
-		eua->v[1] = 0x57;	/* IPv6 */
+		eua->v[0] = PDP_EUA_ORG_IETF;
+		eua->v[1] = PDP_EUA_TYPE_v6;
 		memcpy(&eua->v[2], &src->v6, 16);	/* Copy a 16 byte address */
 		break;
 	default:
@@ -230,14 +231,14 @@
 		return -1;
 
 	switch (eua->v[1]) {
-	case 0x21:
+	case PDP_EUA_TYPE_v4:
 		dst->len = 4;
 		if (eua->l >= 6)
 			memcpy(&dst->v4, &eua->v[2], 4);	/* Copy a 4 byte address */
 		else
 			dst->v4.s_addr = 0;
 		break;
-	case 0x57:
+	case PDP_EUA_TYPE_v6:
 		dst->len = 16;
 		if (eua->l >= 18)
 			memcpy(&dst->v6, &eua->v[2], 16);	/* Copy a 16 byte address */

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

Gerrit-MessageType: merged
Gerrit-Change-Id: I33f65e404217e717bd795e5229c8d9456a7b3739
Gerrit-PatchSet: 4
Gerrit-Project: osmo-ggsn
Gerrit-Branch: master
Gerrit-Owner: Harald Welte <laforge at gnumonks.org>
Gerrit-Reviewer: Harald Welte <laforge at gnumonks.org>
Gerrit-Reviewer: Jenkins Builder



More information about the gerrit-log mailing list