[MERGED] osmo-ggsn[master]: gtp.c: Determine GTP version from header

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
Fri Jan 26 00:32:56 UTC 2018


Harald Welte has submitted this change and it was merged.

Change subject: gtp.c: Determine GTP version from header
......................................................................


gtp.c: Determine GTP version from header

Change-Id: I843071a090e877fd529e1e0b799df3585bf836d8
---
M gtp/gtp.c
1 file changed, 14 insertions(+), 8 deletions(-)

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



diff --git a/gtp/gtp.c b/gtp/gtp.c
index 8652470..f513b9b 100644
--- a/gtp/gtp.c
+++ b/gtp/gtp.c
@@ -2757,7 +2757,7 @@
 	socklen_t peerlen;
 	int status;
 	struct gtp0_header *pheader;
-	int version = 0;	/* GTP version should be determined from header! */
+	uint8_t version;
 	int fd = gsn->fd0;
 
 	/* TODO: Need strategy of userspace buffering and blocking */
@@ -2793,12 +2793,14 @@
 
 		pheader = (struct gtp0_header *)(buffer);
 
+		version = GTPHDR_F_GET_VER(pheader->flags);
+
 		/* Version should be gtp0 (or earlier) */
 		/* 09.60 is somewhat unclear on this issue. On gsn->fd0 we expect only */
 		/* GTP 0 messages. If other version message is received we reply that we */
 		/* only support version 0, implying that this is the only version */
 		/* supported on this port */
-		if (GTPHDR_F_GET_VER(pheader->flags) > 0) {
+		if (version > 0) {
 			gsn->unsup++;
 			GTP_LOGPKG(LOGL_ERROR, &peer, buffer,
 				    status, "Unsupported GTP version\n");
@@ -2902,7 +2904,7 @@
 	socklen_t peerlen;
 	int status;
 	struct gtp1_header_short *pheader;
-	int version = 1;	/* TODO GTP version should be determined from header! */
+	uint8_t version;
 	int fd = gsn->fd1c;
 
 	/* TODO: Need strategy of userspace buffering and blocking */
@@ -2938,8 +2940,10 @@
 
 		pheader = (struct gtp1_header_short *)(buffer);
 
+		version = GTPHDR_F_GET_VER(pheader->flags);
+
 		/* Version must be no larger than GTP 1 */
-		if (GTPHDR_F_GET_VER(pheader->flags) > 1) {
+		if (version > 1) {
 			gsn->unsup++;
 			GTP_LOGPKG(LOGL_ERROR, &peer, buffer,
 				    status, "Unsupported GTP version\n");
@@ -2952,7 +2956,7 @@
 		/* 29.060 is somewhat unclear on this issue. On gsn->fd1c we expect only */
 		/* GTP 1 messages. If GTP 0 message is received we silently discard */
 		/* the message */
-		if (GTPHDR_F_GET_VER(pheader->flags) < 1) {
+		if (version < 1) {
 			gsn->unsup++;
 			GTP_LOGPKG(LOGL_ERROR, &peer, buffer,
 				    status, "Unsupported GTP version\n");
@@ -3077,7 +3081,7 @@
 	socklen_t peerlen;
 	int status;
 	struct gtp1_header_short *pheader;
-	int version = 1;	/* GTP version should be determined from header! */
+	uint8_t version;
 	int fd = gsn->fd1u;
 
 	/* TODO: Need strategy of userspace buffering and blocking */
@@ -3114,8 +3118,10 @@
 
 		pheader = (struct gtp1_header_short *)(buffer);
 
+		version = GTPHDR_F_GET_VER(pheader->flags);
+
 		/* Version must be no larger than GTP 1 */
-		if (GTPHDR_F_GET_VER(pheader->flags) > 1) {
+		if (version > 1) {
 			gsn->unsup++;
 			GTP_LOGPKG(LOGL_ERROR, &peer, buffer,
 				    status, "Unsupported GTP version\n");
@@ -3127,7 +3133,7 @@
 		/* 29.060 is somewhat unclear on this issue. On gsn->fd1c we expect only */
 		/* GTP 1 messages. If GTP 0 message is received we silently discard */
 		/* the message */
-		if (GTPHDR_F_GET_VER(pheader->flags) < 1) {
+		if (version < 1) {
 			gsn->unsup++;
 			GTP_LOGPKG(LOGL_ERROR, &peer, buffer,
 				    status, "Unsupported GTP version\n");

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

Gerrit-MessageType: merged
Gerrit-Change-Id: I843071a090e877fd529e1e0b799df3585bf836d8
Gerrit-PatchSet: 1
Gerrit-Project: osmo-ggsn
Gerrit-Branch: master
Gerrit-Owner: Pau Espin Pedrol <pespin at sysmocom.de>
Gerrit-Reviewer: Harald Welte <laforge at gnumonks.org>
Gerrit-Reviewer: Jenkins Builder



More information about the gerrit-log mailing list