Patchwork [6/9] Add traffic forwarding via RTP to remote application

login
register
mail settings
Submitter Andreas Eversberg
Date May 4, 2014, 9:06 a.m.
Message ID <53660327.5000705@eversberg.eu>
Download mbox | patch
Permalink /patch/345452/
State New
Headers show

Comments

Andreas Eversberg - May 4, 2014, 9:06 a.m.
>>   	S_LCHAN_HANDOVER_FAIL,		/* 04.08 Handover Failed */
>>   	S_LCHAN_HANDOVER_DETECT,	/* 08.58 Handover Detect */
>>   	S_LCHAN_MEAS_REP,		/* 08.58 Measurement Report */
>> +	S_LCHAN_RTP_SOCKET_FREE,
> Use the opportunity to write a bit of information here? Or maybe
> just use S_CHALLOC_FREED to free rtp_socket and introduce a
> S_CHALLOC_RESET to do it in the later case?
>
>> +		struct lchan_signal_data sig;

dear holger,

i chose to use S_CHALLOC_* to trigger RTP socket freeing. see attached 
patch.

best regards

andreas

Patch

From 7b20bbc32146c1a8b5e0191d838b45735f1ae151 Mon Sep 17 00:00:00 2001
From: Andreas Eversberg <jolly@eversberg.eu>
Date: Fri, 18 Apr 2014 11:03:50 +0200
Subject: [PATCH] Move rtp_proxy.c from libtrau to libmsc

In order to free RTP socket when lchan_free() or lchan_reset() is called,
a signal is used between libbsc and rtp_proxy.
---
 openbsc/include/openbsc/signal.h            |  1 +
 openbsc/src/libbsc/chan_alloc.c             | 19 +++++++---------
 openbsc/src/libmsc/Makefile.am              |  3 ++-
 openbsc/src/{libtrau => libmsc}/rtp_proxy.c | 35 +++++++++++++++++++++++++++++
 openbsc/src/libtrau/Makefile.am             |  2 +-
 5 files changed, 47 insertions(+), 13 deletions(-)
 rename openbsc/src/{libtrau => libmsc}/rtp_proxy.c (96%)

diff --git a/openbsc/include/openbsc/signal.h b/openbsc/include/openbsc/signal.h
index 39319f1..31c9187 100644
--- a/openbsc/include/openbsc/signal.h
+++ b/openbsc/include/openbsc/signal.h
@@ -105,6 +105,7 @@  enum signal_lchan {
 enum signal_challoc {
 	S_CHALLOC_ALLOC_FAIL,	/* allocation of lchan has failed */
 	S_CHALLOC_FREED,	/* lchan has been successfully freed */
+	S_CHALLOC_RESET,	/* lchan has been reset */
 };
 
 /* SS_SUBSCR signals */
diff --git a/openbsc/src/libbsc/chan_alloc.c b/openbsc/src/libbsc/chan_alloc.c
index 9b74329..18ffa93 100644
--- a/openbsc/src/libbsc/chan_alloc.c
+++ b/openbsc/src/libbsc/chan_alloc.c
@@ -310,13 +310,6 @@  void lchan_free(struct gsm_lchan *lchan)
 		osmo_signal_dispatch(SS_LCHAN, S_LCHAN_UNEXPECTED_RELEASE, &sig);
 	}
 
-	if (lchan->abis_ip.rtp_socket) {
-		LOGP(DRLL, LOGL_ERROR, "%s RTP Proxy Socket remained open.\n",
-			gsm_lchan_name(lchan));
-		rtp_socket_free(lchan->abis_ip.rtp_socket);
-		lchan->abis_ip.rtp_socket = NULL;
-	}
-
 	/* stop the timer */
 	osmo_timer_del(&lchan->T3101);
 
@@ -360,18 +353,22 @@  void lchan_free(struct gsm_lchan *lchan)
  */
 void lchan_reset(struct gsm_lchan *lchan)
 {
+	struct challoc_signal_data sig;
+
 	osmo_timer_del(&lchan->T3101);
 	osmo_timer_del(&lchan->T3109);
 	osmo_timer_del(&lchan->T3111);
 	osmo_timer_del(&lchan->error_timer);
 
+	memset(&sig, 0, sizeof(sig));
+	sig.type = lchan->type;
+
 	lchan->type = GSM_LCHAN_NONE;
 	lchan->state = LCHAN_S_NONE;
 
-	if (lchan->abis_ip.rtp_socket) {
-		rtp_socket_free(lchan->abis_ip.rtp_socket);
-		lchan->abis_ip.rtp_socket = NULL;
-	}
+	sig.lchan = lchan;
+	sig.bts = lchan->ts->trx->bts;
+	osmo_signal_dispatch(SS_CHALLOC, S_CHALLOC_RESET, &sig);
 }
 
 /* Drive the release process of the lchan */
diff --git a/openbsc/src/libmsc/Makefile.am b/openbsc/src/libmsc/Makefile.am
index 24db2c2..4d44a62 100644
--- a/openbsc/src/libmsc/Makefile.am
+++ b/openbsc/src/libmsc/Makefile.am
@@ -17,7 +17,8 @@  libmsc_a_SOURCES =	auth.c \
 			ussd.c \
 			vty_interface_layer3.c \
 			transaction.c \
-			osmo_msc.c ctrl_commands.c
+			osmo_msc.c ctrl_commands.c \
+			rtp_proxy.c
 
 if BUILD_SMPP
 noinst_HEADERS = smpp_smsc.h
diff --git a/openbsc/src/libtrau/rtp_proxy.c b/openbsc/src/libmsc/rtp_proxy.c
similarity index 96%
rename from openbsc/src/libtrau/rtp_proxy.c
rename to openbsc/src/libmsc/rtp_proxy.c
index 82d50ae..b86d228 100644
--- a/openbsc/src/libtrau/rtp_proxy.c
+++ b/openbsc/src/libmsc/rtp_proxy.c
@@ -36,6 +36,7 @@ 
 #include <openbsc/rtp_proxy.h>
 #include <openbsc/mncc.h>
 #include <openbsc/trau_upqueue.h>
+#include <openbsc/signal.h>
 
 /* attempt to determine byte order */
 #include <sys/param.h>
@@ -830,3 +831,37 @@  int rtp_socket_free(struct rtp_socket *rs)
 
 	return 0;
 }
+
+static int rtp_handle_challoc_signal(unsigned int subsys, unsigned int signal,
+				   void *handler_data, void *signal_data)
+{
+	struct gsm_lchan *lchan;
+	struct challoc_signal_data *sig;
+
+	if (subsys != SS_CHALLOC)
+		return 0;
+
+
+	sig = signal_data;
+	if (!sig->lchan || !sig->lchan->conn)
+		return 0;
+
+	lchan = sig->lchan;
+
+	switch (signal) {
+	case S_CHALLOC_FREED:
+	case S_CHALLOC_RESET:
+		if (lchan->abis_ip.rtp_socket) {
+			rtp_socket_free(lchan->abis_ip.rtp_socket);
+			lchan->abis_ip.rtp_socket = NULL;
+		}
+		break;
+	}
+
+	return 0;
+}
+
+static __attribute__((constructor)) void on_dso_load_rtp_proxy(void)
+{
+	osmo_signal_register_handler(SS_CHALLOC, rtp_handle_challoc_signal, NULL);
+}
diff --git a/openbsc/src/libtrau/Makefile.am b/openbsc/src/libtrau/Makefile.am
index 0c8cf17..7b71417 100644
--- a/openbsc/src/libtrau/Makefile.am
+++ b/openbsc/src/libtrau/Makefile.am
@@ -4,4 +4,4 @@  AM_LDFLAGS = $(LIBOSMOCORE_LIBS) $(LIBOSMOGSM_LIBS) $(LIBOSMOABIS_LIBS) $(COVERA
 
 noinst_LIBRARIES = libtrau.a
 
-libtrau_a_SOURCES = rtp_proxy.c trau_mux.c trau_upqueue.c
+libtrau_a_SOURCES = trau_mux.c trau_upqueue.c
-- 
1.8.1.5