[PATCH] openggsn[master]: ctrl: cleanup trap creation

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

Max gerrit-no-reply at lists.osmocom.org
Tue May 16 15:11:53 UTC 2017


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

ctrl: cleanup trap creation

Move common trap create/send code into separate function.

Change-Id: Iaadc921b951aeb9b3ad5ab796e13d52017139468
---
M ggsn/ggsn.c
1 file changed, 16 insertions(+), 11 deletions(-)


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

diff --git a/ggsn/ggsn.c b/ggsn/ggsn.c
index 181ba2d..4d07f11 100644
--- a/ggsn/ggsn.c
+++ b/ggsn/ggsn.c
@@ -133,18 +133,26 @@
 }
 #endif
 
+static bool send_trap(const struct gsn_t *gsn, const struct pdp_t *pdp, const struct ippoolm_t *member, const char *var)
+{
+	char val[NAMESIZE];
+
+	snprintf(val, sizeof(val), "%" PRIu64 ",%s", pdp->imsi, inet_ntoa(member->addr));
+
+	if (ctrl_cmd_send_trap(gsn->ctrl, var, val) < 0) {
+		LOGP(DGGSN, LOGL_ERROR, "Failed to create and send TRAP for IMSI %" PRIu64 " [%s].\n", pdp->imsi, var);
+		return false;
+	}
+	return true;
+}
+
 int delete_context(struct pdp_t *pdp)
 {
 	DEBUGP(DGGSN, "Deleting PDP context\n");
 	struct ippoolm_t *member = pdp->peer;
-	char v[NAMESIZE];
 
 	if (pdp->peer) {
-		snprintf(v, sizeof(v), "%" PRIu64 ",%s", pdp->imsi,
-			 inet_ntoa(member->addr));
-		if (ctrl_cmd_send_trap(gsn->ctrl, "imsi-rem-ip", v) < 0)
-			LOGP(DGGSN, LOGL_ERROR, "Failed to create and send TRAP"
-			     " for IMSI %" PRIu64 " PDP deletion.\n", pdp->imsi);
+		send_trap(gsn, pdp, member, "imsi-rem-ip"); /* TRAP with IP removal */
 		ippool_freeip(ippool, (struct ippoolm_t *)pdp->peer);
 	} else
 		SYS_ERR(DGGSN, LOGL_ERROR, 0, "Peer not defined!");
@@ -162,7 +170,6 @@
 {
 	struct in_addr addr;
 	struct ippoolm_t *member;
-	char v[NAMESIZE];
 
 	DEBUGP(DGGSN, "Received create PDP context request\n");
 
@@ -192,10 +199,8 @@
 		SYS_ERR(DGGSN, LOGL_ERROR, 0,
 			"Cannot add tunnel to kernel: %s\n", strerror(errno));
 	}
-/* FIXME: naming? */
-	snprintf(v, sizeof(v), "%" PRIu64 ",%s", pdp->imsi, inet_ntoa(member->addr));
-	if (ctrl_cmd_send_trap(gsn->ctrl, "imsi-ass-ip", v) < 0) {
-		LOGP(DGGSN, LOGL_ERROR, "Trap creation failed.\n");
+
+	if (!send_trap(gsn, pdp, member, "imsi-ass-ip")) { /* TRAP with IP assignment */
 		gtp_create_context_resp(gsn, pdp, GTPCAUSE_NO_RESOURCES);
 		return 0;
 	}

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: Iaadc921b951aeb9b3ad5ab796e13d52017139468
Gerrit-PatchSet: 1
Gerrit-Project: openggsn
Gerrit-Branch: master
Gerrit-Owner: Max <msuraev at sysmocom.de>



More information about the gerrit-log mailing list