[PATCH] osmo-ggsn[master]: gtp-kernel: Make sure repeated calls to gtp_kernel_init() ar...

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:57 UTC 2017


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

gtp-kernel: Make sure repeated calls to gtp_kernel_init() are safe

We have to factor out the "run once" code and make sure to really
only run that once, while the per-device code remains in the
gtp_kernel_init() function.

Change-Id: Iba5bd71e4b725eef59fe4f233fbb965e396a06c3
---
M ggsn/gtp-kernel.c
1 file changed, 25 insertions(+), 15 deletions(-)


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

diff --git a/ggsn/gtp-kernel.c b/ggsn/gtp-kernel.c
index e1553bd..8f538a2 100644
--- a/ggsn/gtp-kernel.c
+++ b/ggsn/gtp-kernel.c
@@ -53,10 +53,35 @@
 	struct mnl_socket	*nl;
 } gtp_nl;
 
+static int gtp_kernel_init_once(void)
+{
+	/* only initialize once */
+	if (gtp_nl.nl)
+		return 0;
+
+	gtp_nl.nl = genl_socket_open();
+	if (gtp_nl.nl == NULL) {
+		SYS_ERR(DGGSN, LOGL_ERROR, 0, "cannot create genetlink socket\n");
+		return -1;
+	}
+	gtp_nl.genl_id = genl_lookup_family(gtp_nl.nl, "gtp");
+	if (gtp_nl.genl_id < 0) {
+		SYS_ERR(DGGSN, LOGL_ERROR, 0,
+			"cannot lookup GTP genetlink ID\n");
+		return -1;
+	}
+	SYS_ERR(DGGSN, LOGL_DEBUG, 0, "Initialized GTP kernel mode (genl ID is %d)\n", gtp_nl.genl_id);
+
+	return 0;
+}
+
 int gtp_kernel_init(struct gsn_t *gsn, const char *devname, struct in46_prefix *prefix, const char *ipup)
 {
 	struct in_addr net;
 	const char *net_arg;
+
+	if (!gtp_nl.nl)
+		gtp_kernel_init_once();
 
 	if (prefix->addr.len != 4) {
 		SYS_ERR(DGGSN, LOGL_ERROR, 0,
@@ -71,21 +96,6 @@
 			strerror(errno));
 		return -1;
 	}
-
-	gtp_nl.nl = genl_socket_open();
-	if (gtp_nl.nl == NULL) {
-		SYS_ERR(DGGSN, LOGL_ERROR, 0,
-			"cannot create genetlink socket\n");
-		return -1;
-	}
-	gtp_nl.genl_id = genl_lookup_family(gtp_nl.nl, "gtp");
-	if (gtp_nl.genl_id < 0) {
-		SYS_ERR(DGGSN, LOGL_ERROR, 0,
-			"cannot lookup GTP genetlink ID\n");
-		return -1;
-	}
-	SYS_ERR(DGGSN, LOGL_DEBUG, 0,
-		"Using the GTP kernel mode (genl ID is %d)\n", gtp_nl.genl_id);
 
 	net_arg = in46p_ntoa(prefix);
 

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: Iba5bd71e4b725eef59fe4f233fbb965e396a06c3
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