aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorHolger Hans Peter Freyther <zecke@selfish.org>2011-09-15 19:30:20 +0200
committerHolger Hans Peter Freyther <zecke@selfish.org>2011-09-15 19:30:20 +0200
commitb1dfc462dfa308d62b939847dbee2218c3a25fc1 (patch)
tree45e37d40b8cb870873a66586217e04ca7d0e84fa /src
parent588754c7d391482de6b903e3a80a0df103d314d8 (diff)
cellmgr: Patch the MGCP messages and replace the domain name
Replace the domain name with a new name domain that can be configured via the VTY interface.
Diffstat (limited to 'src')
-rw-r--r--src/Makefile.am4
-rw-r--r--src/mgcp_patch.c111
-rw-r--r--src/msc_conn.c2
3 files changed, 115 insertions, 2 deletions
diff --git a/src/Makefile.am b/src/Makefile.am
index 4d68f30..5684a8a 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -14,7 +14,7 @@ cellmgr_ng_SOURCES = main.c mtp_layer3.c thread.c input/ipaccess.c pcap.c \
bss_patch.c bssap_sccp.c bsc_sccp.c bsc_ussd.c links.c \
msc_conn.c link_udp.c snmp_mtp.c debug.c isup.c \
mtp_link.c counter.c sccp_state.c bsc.c ss7_application.c \
- vty_interface_legacy.c vty_interface_cmds.c
+ vty_interface_legacy.c vty_interface_cmds.c mgcp_patch.c
cellmgr_ng_LDADD = $(LIBOSMOCORE_LIBS) $(LIBOSMOGSM_LIBS) $(LIBOSMOVTY_LIBS) \
$(LIBOSMOSCCP_LIBS) $(NEXUSWARE_C7_LIBS) \
-lpthread -lnetsnmp -lcrypto
@@ -23,7 +23,7 @@ osmo_stp_SOURCES = main_stp.c mtp_layer3.c thread.c pcap.c link_udp.c snmp_mtp.c
debug.c links.c isup.c sctp_m2ua.c msc_conn.c sccp_state.c \
bss_patch.c bssap_sccp.c bsc_sccp.c bsc_ussd.c input/ipaccess.c \
mtp_link.c counter.c bsc.c ss7_application.c \
- vty_interface.c vty_interface_cmds.c
+ vty_interface.c vty_interface_cmds.c mgcp_patch.c
osmo_stp_LDADD = $(LIBOSMOCORE_LIBS) $(LIBOSMOGSM_LIBS) $(LIBOSMOVTY_LIBS) \
$(LIBOSMOSCCP_LIBS) $(NEXUSWARE_C7_LIBS) \
-lpthread -lnetsnmp -lcrypto -lm2ua -lsctp
diff --git a/src/mgcp_patch.c b/src/mgcp_patch.c
new file mode 100644
index 0000000..f4a8579
--- /dev/null
+++ b/src/mgcp_patch.c
@@ -0,0 +1,111 @@
+/* MGCP message patching */
+/*
+ * (C) 2011 by Holger Hans Peter Freyther <zecke@selfish.org>
+ * (C) 2011 by On-Waves
+ * All Rights Reserved
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include <mgcp_patch.h>
+#include <cellmgr_debug.h>
+#include <ss7_application.h>
+#include <string.h>
+
+#include <osmocom/gsm/tlv.h>
+
+
+struct msgb *mgcp_patch(struct ss7_application *app, struct msgb *msg)
+{
+ char *token, *remaining;
+ struct msgb *out;
+ int len, out_len, state, i;
+
+ if (!app->mgcp_domain_name)
+ return msg;
+
+ if (msgb_tailroom(msg) <= strlen(app->mgcp_domain_name)) {
+ LOGP(DMGCP, LOGL_ERROR, "Not enough space to add a zero line.\n");
+ return msg;
+ }
+
+ msg->l2h[msgb_l2len(msg)] = '\0';
+
+ /**
+ * We now need to rewrite the message, but actually only the first
+ * line and the rest can be copied.
+ */
+ out = msgb_alloc_headroom(4096, 128, "MGCP Patch Copy");
+ if (!out) {
+ LOGP(DMGCP, LOGL_ERROR, "Failed to create the MSGB copy.\n");
+ return NULL;
+ }
+
+
+ remaining = (char *) msg->l2h;
+ token = strsep(&remaining, "\n");
+ if (!token) {
+ LOGP(DMGCP, LOGL_ERROR, "Failed to split the MGCP.\n");
+ msgb_free(out);
+ return msg;
+ }
+
+ len = strlen(token);
+ out->l2h = msgb_put(out, 0);
+
+ /*
+ * State machine for copying and modifying the MGCP line, first find
+ * half of the endpoint, put ours, copy the rest of the line
+ */
+ state = 0;
+ for (i = 0; i < len; ++i) {
+ switch (state) {
+ case 2:
+ if (token[i] == '@')
+ state += 1;
+ msgb_v_put(out, token[i]);
+ break;
+ case 3:
+ /* copy the new name */
+ out->l3h = msgb_put(out, strlen(app->mgcp_domain_name));
+ memcpy(out->l3h, app->mgcp_domain_name, msgb_l3len(out));
+
+ /* skip everything to the next whitespace */
+ for (; i < len; ++i) {
+ if (token[i] == ' ') {
+ break;
+ }
+ }
+
+ for (; i < len; ++i)
+ msgb_v_put(out, token[i]);
+ msgb_v_put(out, '\n');
+ break;
+ default:
+ if (token[i] == ' ')
+ state += 1;
+ msgb_v_put(out, token[i]);
+ break;
+ }
+ }
+
+ /* append the rest */
+ out_len = msgb_l2len(msg) - len - 1;
+ out->l3h = msgb_put(out, out_len);
+ memcpy(out->l3h, &msg->l2h[len + 1], out_len);
+
+ msgb_free(msg);
+ return out;
+}
+
diff --git a/src/msc_conn.c b/src/msc_conn.c
index 551a781..0e61dd3 100644
--- a/src/msc_conn.c
+++ b/src/msc_conn.c
@@ -27,6 +27,7 @@
#include <mtp_data.h>
#include <cellmgr_debug.h>
#include <ss7_application.h>
+#include <mgcp_patch.h>
#include <osmocom/core/talloc.h>
#include <osmocom/gsm/tlv.h>
@@ -158,6 +159,7 @@ static int ipaccess_a_fd_cb(struct osmo_fd *bfd)
} else if (hh->proto == IPAC_PROTO_SCCP) {
msc_dispatch_sccp(fw, msg);
} else if (hh->proto == NAT_MUX) {
+ msg = mgcp_patch(fw->app, msg);
mgcp_forward(fw, msg->l2h, msgb_l2len(msg));
} else {
LOGP(DMSC, LOGL_ERROR, "Unknown IPA proto 0x%x\n", hh->proto);