[MERGED] openggsn[master]: Add control interface

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
Wed Oct 12 11:40:11 UTC 2016


Max has submitted this change and it was merged.

Change subject: Add control interface
......................................................................


Add control interface

Only generation of TRAP messages over Control Interface is supported so
far.

Note: requires corresponding version of libosmoctrl.

Change-Id: Ia76f841d2c9cd14394e9316fcd39f4060e23c898
Related: OS#1646
---
M configure.ac
M ggsn/Makefile.am
M ggsn/ggsn.c
M gtp/gtp.h
4 files changed, 34 insertions(+), 5 deletions(-)

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



diff --git a/configure.ac b/configure.ac
index 9b8d988..b11730b 100644
--- a/configure.ac
+++ b/configure.ac
@@ -117,6 +117,7 @@
 
 PKG_CHECK_MODULES(LIBOSMOCORE, libosmocore >= 0.6.4)
 PKG_CHECK_MODULES(LIBOSMOVTY, libosmovty >= 0.3.0)
+PKG_CHECK_MODULES(LIBOSMOCTRL, libosmoctrl)
 
 AC_CONFIG_FILES([Makefile
                  doc/Makefile
diff --git a/ggsn/Makefile.am b/ggsn/Makefile.am
index c8868c1..3ad3a6e 100644
--- a/ggsn/Makefile.am
+++ b/ggsn/Makefile.am
@@ -2,13 +2,13 @@
 
 AM_LDFLAGS = @EXEC_LDFLAGS@
 
-AM_CFLAGS = -O2 -D_GNU_SOURCE -fno-builtin -Wall -DSBINDIR='"$(sbindir)"' -ggdb $(LIBOSMOCORE_CFLAGS)
+AM_CFLAGS = -O2 -D_GNU_SOURCE -fno-builtin -Wall -DSBINDIR='"$(sbindir)"' -ggdb $(LIBOSMOCORE_CFLAGS) $(LIBOSMOCTRL_CFLAGS)
 
 if ENABLE_GTP_KERNEL
 AM_CFLAGS += -DGTP_KERNEL
-ggsn_LDADD = @EXEC_LDADD@ -lgtp -lgtpnl -L../gtp ../lib/libmisc.a $(LIBOSMOCORE_LIBS)
+ggsn_LDADD = @EXEC_LDADD@ -lgtp -lgtpnl -L../gtp ../lib/libmisc.a $(LIBOSMOCORE_LIBS) $(LIBOSMOCTRL_LIBS)
 else
-ggsn_LDADD = @EXEC_LDADD@ -lgtp -L../gtp ../lib/libmisc.a $(LIBOSMOCORE_LIBS)
+ggsn_LDADD = @EXEC_LDADD@ -lgtp -L../gtp ../lib/libmisc.a $(LIBOSMOCORE_LIBS) $(LIBOSMOCTRL_LIBS)
 endif
 
 ggsn_DEPENDENCIES = ../gtp/libgtp.la ../lib/libmisc.a
diff --git a/ggsn/ggsn.c b/ggsn/ggsn.c
index 6866901..9609d52 100644
--- a/ggsn/ggsn.c
+++ b/ggsn/ggsn.c
@@ -39,7 +39,7 @@
 #include <sys/stat.h>
 #include <fcntl.h>
 #include <unistd.h>
-
+#include <inttypes.h>
 #include <sys/socket.h>
 #include <sys/ioctl.h>
 #include <net/if.h>
@@ -47,6 +47,11 @@
 #include <errno.h>
 
 #include <time.h>
+
+#include <osmocom/core/select.h>
+#include <osmocom/ctrl/control_if.h>
+#include <osmocom/ctrl/control_cmd.h>
+#include <osmocom/ctrl/ports.h>
 
 #include "../lib/tun.h"
 #include "../lib/ippool.h"
@@ -131,6 +136,9 @@
 int delete_context(struct pdp_t *pdp)
 {
 	DEBUGP(DGGSN, "Deleting PDP context\n");
+	struct ippoolm_t *member = pdp->peer;
+	char v[NAMESIZE];
+	snprintf(v, sizeof(v), "%" PRIu64 ",%s", pdp->imsi, inet_ntoa(member->addr));
 	if (pdp->peer)
 		ippool_freeip(ippool, (struct ippoolm_t *)pdp->peer);
 	else
@@ -141,6 +149,9 @@
 			"Cannot delete tunnel from kernel: %s\n",
 			strerror(errno));
 	}
+/* FIXME: naming? */
+	if (ctrl_cmd_send_trap(gsn->ctrl, "imsi-rem-ip", v) < 0)
+		LOGP(DGGSN, LOGL_ERROR, "Trap creation failed.\n");
 
 	return 0;
 }
@@ -149,6 +160,7 @@
 {
 	struct in_addr addr;
 	struct ippoolm_t *member;
+	char v[NAMESIZE];
 
 	DEBUGP(DGGSN, "Received create PDP context request\n");
 
@@ -177,6 +189,13 @@
 	if (gtp_kernel_tunnel_add(pdp) < 0) {
 		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");
+		gtp_create_context_resp(gsn, pdp, GTPCAUSE_NO_RESOURCES);
+		return 0;
 	}
 
 	gtp_create_context_resp(gsn, pdp, GTPCAUSE_ACC_REQ);
@@ -526,6 +545,12 @@
 	gtp_set_cb_delete_context(gsn, delete_context);
 	gtp_set_cb_create_context_ind(gsn, create_context_ind);
 
+	gsn->ctrl = ctrl_interface_setup(NULL, OSMO_CTRL_PORT_GGSN, NULL);
+	if (!gsn->ctrl) {
+		LOGP(DGGSN, LOGL_ERROR, "Failed to create CTRL interface.\n");
+		exit(1);
+	}
+
 	/* skip the configuration of the tun0 if we're using the gtp0 device */
 	if (gtp_kernel_enabled())
 		goto skip_tun;
@@ -597,6 +622,7 @@
 		if (FD_ISSET(gsn->fd1u, &fds))
 			gtp_decaps1u(gsn);
 
+		osmo_select_main(1);
 	}
 err:
 	gtp_kernel_stop();
diff --git a/gtp/gtp.h b/gtp/gtp.h
index 539e255..fd138cc 100644
--- a/gtp/gtp.h
+++ b/gtp/gtp.h
@@ -12,6 +12,8 @@
 #ifndef _GTP_H
 #define _GTP_H
 
+#include <osmocom/ctrl/control_if.h>
+
 #define GTP_MODE_GGSN 1
 #define GTP_MODE_SGSN 2
 
@@ -245,7 +247,7 @@
 
 	unsigned char restart_counter;	/* Increment on restart. Stored on disk */
 	char *statedir;		/* Disk location for permanent storage */
-
+	struct ctrl_handle *ctrl;	/* Control Interface */
 	struct queue_t *queue_req;	/* Request queue */
 	struct queue_t *queue_resp;	/* Response queue */
 

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

Gerrit-MessageType: merged
Gerrit-Change-Id: Ia76f841d2c9cd14394e9316fcd39f4060e23c898
Gerrit-PatchSet: 2
Gerrit-Project: openggsn
Gerrit-Branch: master
Gerrit-Owner: Max <msuraev at sysmocom.de>
Gerrit-Reviewer: Harald Welte <laforge at gnumonks.org>
Gerrit-Reviewer: Jenkins Builder
Gerrit-Reviewer: Max <msuraev at sysmocom.de>



More information about the gerrit-log mailing list