aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHarald Welte <laforge@gnumonks.org>2018-05-26 22:56:59 +0200
committerHarald Welte <laforge@gnumonks.org>2018-11-29 18:14:25 +0100
commitba6c93d3c4563032892e71e4c87b2152df3c74cb (patch)
tree4a6be11f4aa0c1b747cbee7850f153e8b22e564b
parent7ae0f9c271fd403bab96897056eb2efe87b2adec (diff)
Re-introduce support for IPA-encapsulated MGCPlaforge/mgcp-ipa
Old osmo-bsc-sccplite already supported this, but in the migration over to libosmo-sigtran and to real 3GPP AoIP, this functionality got lost. We now crate a UDP proxy socket. Any MGCP commands received via IPA from MSC (or rather: bsc_nat) are retransmitted to the MGW via UDP on this socket. Any responses back from the MGW received on the UDP socket are retransmitted back to MSC/bsc_nat as MGCP inside the IPA multiplex. Closes: OS#2536 Change-Id: I38ad8fa645c08900e0e1f1b4b96136bc6d96b3ab
-rw-r--r--include/osmocom/bsc/bsc_msc_data.h11
-rw-r--r--include/osmocom/bsc/osmo_bsc_sigtran.h9
-rw-r--r--src/osmo-bsc/Makefile.am1
-rw-r--r--src/osmo-bsc/osmo_bsc_ctrl.c59
-rw-r--r--src/osmo-bsc/osmo_bsc_mgcp.c91
-rw-r--r--src/osmo-bsc/osmo_bsc_msc.c31
-rw-r--r--src/osmo-bsc/osmo_bsc_sigtran.c4
7 files changed, 186 insertions, 20 deletions
diff --git a/include/osmocom/bsc/bsc_msc_data.h b/include/osmocom/bsc/bsc_msc_data.h
index 0c2094e3a..5cda2aabd 100644
--- a/include/osmocom/bsc/bsc_msc_data.h
+++ b/include/osmocom/bsc/bsc_msc_data.h
@@ -31,6 +31,7 @@
#include "debug.h"
#include <osmocom/core/timer.h>
+#include <osmocom/core/select.h>
#include <osmocom/gsm/protocol/gsm_04_08.h>
@@ -140,6 +141,16 @@ struct bsc_msc_data {
uint32_t x_osmo_ign;
bool x_osmo_ign_configured;
+
+ /* Proxy between IPA/SCCPlite encapsulated MGCP and UDP */
+ struct {
+ /* local (BSC) IP address to be used */
+ char *local_addr;
+ /* local (BSC) UDP port to be usd to talk with MGW */
+ uint16_t local_port;
+ /* UDP socket for proxying MGCP via SCCPlite/IPA */
+ struct osmo_fd ofd;
+ } mgcp_ipa;
};
/*
diff --git a/include/osmocom/bsc/osmo_bsc_sigtran.h b/include/osmocom/bsc/osmo_bsc_sigtran.h
index bd8b06398..b934d51d3 100644
--- a/include/osmocom/bsc/osmo_bsc_sigtran.h
+++ b/include/osmocom/bsc/osmo_bsc_sigtran.h
@@ -44,3 +44,12 @@ void osmo_bsc_sigtran_tx_reset_ack(const struct bsc_msc_data *msc);
/* receive + process a CTRL command from the piggy-back on the IPA/SCCPlite link */
int bsc_sccplite_rx_ctrl(struct osmo_ss7_asp *asp, struct msgb *msg);
+
+/* receive + process a MGCP message from the piggy-back on the IPA/SCCPlite link */
+int bsc_sccplite_rx_mgcp(struct osmo_ss7_asp *asp, struct msgb *msg);
+
+/* send a message via SCCPLite to given MSC */
+int bsc_sccplite_msc_send(struct bsc_msc_data *msc, struct msgb *msg);
+
+/* we received some data on the UDP proxy socket from the MGW. Pass it to MSC via IPA */
+int bsc_sccplite_mgcp_proxy_cb(struct osmo_fd *ofd, unsigned int what);
diff --git a/src/osmo-bsc/Makefile.am b/src/osmo-bsc/Makefile.am
index 364228d8c..c665fa863 100644
--- a/src/osmo-bsc/Makefile.am
+++ b/src/osmo-bsc/Makefile.am
@@ -81,6 +81,7 @@ osmo_bsc_SOURCES = \
osmo_bsc_grace.c \
osmo_bsc_lcls.c \
osmo_bsc_main.c \
+ osmo_bsc_mgcp.c \
osmo_bsc_msc.c \
osmo_bsc_sigtran.c \
osmo_bsc_vty.c \
diff --git a/src/osmo-bsc/osmo_bsc_ctrl.c b/src/osmo-bsc/osmo_bsc_ctrl.c
index 80699f877..afe061ecc 100644
--- a/src/osmo-bsc/osmo_bsc_ctrl.c
+++ b/src/osmo-bsc/osmo_bsc_ctrl.c
@@ -52,6 +52,39 @@ static struct osmo_ss7_as *msc_get_ss7_as(struct bsc_msc_data *msc)
return rt->dest.as;
}
+static int _ss7_as_send(struct osmo_ss7_as *as, struct msgb *msg)
+{
+ struct osmo_ss7_asp *asp;
+ unsigned int i;
+
+ /* FIXME: unify with xua_as_transmit_msg() and perform proper ASP lookup */
+ for (i = 0; i < ARRAY_SIZE(as->cfg.asps); i++) {
+ asp = as->cfg.asps[i];
+ if (!asp)
+ continue;
+ /* FIXME: deal with multiple ASPs per AS */
+ return osmo_ss7_asp_send(asp, msg);
+ }
+ msgb_free(msg);
+ return -1;
+}
+
+int bsc_sccplite_msc_send(struct bsc_msc_data *msc, struct msgb *msg)
+{
+ struct osmo_ss7_as *as;
+
+ as = msc_get_ss7_as(msc);
+ if (!as) {
+ msgb_free(msg);
+ return -1;
+ }
+
+ /* don't attempt to send CTRL on a non-SCCPlite AS */
+ if (as->cfg.proto != OSMO_SS7_ASP_PROT_IPA)
+ return 0;
+
+ return _ss7_as_send(as, msg);
+}
/* Encode a CTRL command and send it to the given ASP
* \param[in] asp ASP through which we shall send the encoded message
@@ -83,30 +116,20 @@ static int sccplite_asp_ctrl_cmd_send(struct osmo_ss7_asp *asp, struct ctrl_cmd
* Caller must hence free 'cmd' itself. */
static int sccplite_msc_ctrl_cmd_send(struct bsc_msc_data *msc, struct ctrl_cmd *cmd)
{
- struct osmo_ss7_as *as;
- struct osmo_ss7_asp *asp;
- unsigned int i;
+ struct msgb *msg;
- as = msc_get_ss7_as(msc);
- if (!as)
+ msg = ctrl_cmd_make(cmd);
+ if (!msg)
return -1;
- /* don't attempt to send CTRL on a non-SCCPlite AS */
- if (as->cfg.proto != OSMO_SS7_ASP_PROT_IPA)
- return 0;
+ ipa_prepend_header_ext(msg, IPAC_PROTO_EXT_CTRL);
+ ipa_prepend_header(msg, IPAC_PROTO_OSMO);
- /* FIXME: unify with xua_as_transmit_msg() and perform proper ASP lookup */
- for (i = 0; i < ARRAY_SIZE(as->cfg.asps); i++) {
- asp = as->cfg.asps[i];
- if (!asp)
- continue;
- /* FIXME: deal with multiple ASPs per AS */
- return sccplite_asp_ctrl_cmd_send(asp, cmd);
- }
- return -1;
+ return bsc_sccplite_msc_send(msc, msg);
}
-/* receive + process a CTRL command from the piggy-back on the IPA/SCCPlite link */
+/* receive + process a CTRL command from the piggy-back on the IPA/SCCPlite link.
+ * Transfers msg ownership. */
int bsc_sccplite_rx_ctrl(struct osmo_ss7_asp *asp, struct msgb *msg)
{
struct ctrl_cmd *cmd;
diff --git a/src/osmo-bsc/osmo_bsc_mgcp.c b/src/osmo-bsc/osmo_bsc_mgcp.c
new file mode 100644
index 000000000..d984125ab
--- /dev/null
+++ b/src/osmo-bsc/osmo_bsc_mgcp.c
@@ -0,0 +1,91 @@
+/*
+ * SCCPlite MGCP handling
+ *
+ * (C) 2018 by Harald Welte <laforge@gnumonks.org>
+ * 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 <osmocom/bsc/bsc_msc_data.h>
+#include <osmocom/bsc/osmo_bsc.h>
+#include <osmocom/bsc/gsm_data.h>
+#include <osmocom/bsc/debug.h>
+#include <osmocom/gsm/ipa.h>
+#include <osmocom/gsm/protocol/ipaccess.h>
+#include <osmocom/bsc/osmo_bsc_sigtran.h>
+
+#include <arpa/inet.h>
+
+/* Determine MSC based on the ASP over which the message was received */
+static struct bsc_msc_data *msc_from_asp(struct osmo_ss7_asp *asp)
+{
+ int msc_nr;
+ /* this is rather ugly, as we of course have MTP-level routing between
+ * the local SCCP user (BSC) and the AS/ASPs. However, for the most simple
+ * SCCPlite case, there is a 1:1 mapping between ASP and AS, and using
+ * the libosmo-sigtran "simple client", the names are "as[p]-clnt-msc-%u",
+ * as set in osmo_bsc_sigtran_init() */
+ if (sscanf(asp->cfg.name, "asp-clnt-msc-%u", &msc_nr) != 1) {
+ LOGP(DMSC, LOGL_ERROR, "Cannot find to which MSC the ASP %s belongs\n", asp->cfg.name);
+ return NULL;
+ }
+ return osmo_msc_data_find(bsc_gsmnet, msc_nr);
+}
+
+/* We received an IPA-encapsulated MGCP message from a MSC. Transfers msg ownership. */
+int bsc_sccplite_rx_mgcp(struct osmo_ss7_asp *asp, struct msgb *msg)
+{
+ struct bsc_msc_data *msc;
+ int rc;
+
+ LOGP(DMSC, LOGL_NOTICE, "%s: Received IPA-encapsulated MGCP: %s\n", asp->cfg.name, msg->l2h);
+ msc = msc_from_asp(asp);
+ if (msc) {
+ /* we don't have a write queue here as we simply expect the socket buffers
+ * to be large enouhg to deal with whatever small/infrequent MGCP messages */
+ rc = send(msc->mgcp_ipa.ofd.fd, msgb_l2(msg), msgb_l2len(msg), 0);
+ } else
+ rc = 0;
+
+ msgb_free(msg);
+ return rc;
+}
+
+/* we received some data on the UDP proxy socket from the MGW. Pass it to MSC via IPA */
+int bsc_sccplite_mgcp_proxy_cb(struct osmo_fd *ofd, unsigned int what)
+{
+ struct bsc_msc_data *msc = ofd->data;
+ struct msgb *msg;
+ int rc;
+
+ if (!(what & BSC_FD_READ))
+ return 0;
+
+ msg = msgb_alloc_headroom(1024, 16, "MGCP->IPA");
+ OSMO_ASSERT(msg);
+ rc = recv(ofd->fd, msg->data, msgb_tailroom(msg), 0);
+ if (rc <= 0) {
+ LOGP(DMSC, LOGL_ERROR, "error receiving data from MGCP<-> IPA proxy UDP socket: "
+ "%s\n", strerror(errno));
+ msgb_free(msg);
+ return rc;
+ }
+ msg->l2h = msgb_put(msg, rc);
+ LOGP(DMSC, LOGL_NOTICE, "Received MGCP on UDP proxy socket: %s\n", msg->l2h);
+
+ ipa_prepend_header(msg, IPAC_PROTO_MGCP_OLD);
+ return bsc_sccplite_msc_send(msc, msg);
+}
diff --git a/src/osmo-bsc/osmo_bsc_msc.c b/src/osmo-bsc/osmo_bsc_msc.c
index 71931e615..77db7a6fc 100644
--- a/src/osmo-bsc/osmo_bsc_msc.c
+++ b/src/osmo-bsc/osmo_bsc_msc.c
@@ -27,26 +27,49 @@
#include <osmocom/bsc/gsm_data.h>
#include <osmocom/bsc/ipaccess.h>
#include <osmocom/bsc/bsc_msc_data.h>
+#include <osmocom/bsc/osmo_bsc_sigtran.h>
#include <osmocom/bsc/signal.h>
#include <osmocom/core/talloc.h>
+#include <osmocom/core/socket.h>
#include <osmocom/gsm/gsm0808.h>
#include <osmocom/abis/ipa.h>
+#include <osmocom/mgcp_client/mgcp_client.h>
+
#include <sys/socket.h>
#include <netinet/tcp.h>
#include <unistd.h>
-int osmo_bsc_msc_init(struct bsc_msc_data *data)
+int osmo_bsc_msc_init(struct bsc_msc_data *msc)
{
+ struct gsm_network *net = msc->network;
+ uint16_t mgw_port;
+ int rc;
+
/* FIXME: This is a leftover from the old architecture that used
* sccp-lite with osmocom specific authentication. Since we now
* changed to AoIP the connected status and the authentication
* status is managed differently. However osmo_bsc_filter.c still
* needs the flags to be set to one. See also: OS#3112 */
- data->is_authenticated = 1;
+ msc->is_authenticated = 1;
+
+ if (net->mgw.conf->remote_port == -1)
+ mgw_port = 2427;
+ else
+ mgw_port = net->mgw.conf->remote_port;
+
+ rc = osmo_sock_init2_ofd(&msc->mgcp_ipa.ofd, AF_INET, SOCK_DGRAM, IPPROTO_UDP,
+ msc->mgcp_ipa.local_addr, msc->mgcp_ipa.local_port,
+ net->mgw.conf->remote_addr, mgw_port,
+ OSMO_SOCK_F_BIND | OSMO_SOCK_F_CONNECT);
+ if (rc < 0) {
+ LOGP(DMSC, LOGL_ERROR, "msc %u: Could not create/connect/bind MGCP proxy socket: %d\n",
+ msc->nr, rc);
+ return rc;
+ }
return 0;
}
@@ -116,6 +139,10 @@ struct bsc_msc_data *osmo_msc_data_alloc(struct gsm_network *net, int nr)
msc_data->audio_support[4]->ver = 3;
msc_data->audio_support[4]->hr = 1;
+ osmo_fd_setup(&msc_data->mgcp_ipa.ofd, -1, BSC_FD_READ, &bsc_sccplite_mgcp_proxy_cb, msc_data, 0);
+ msc_data->mgcp_ipa.local_addr = talloc_strdup(msc_data, "0.0.0.0");
+ msc_data->mgcp_ipa.local_port = 0; /* dynamic */
+
return msc_data;
}
diff --git a/src/osmo-bsc/osmo_bsc_sigtran.c b/src/osmo-bsc/osmo_bsc_sigtran.c
index 4b2c4aeac..a8fb7037f 100644
--- a/src/osmo-bsc/osmo_bsc_sigtran.c
+++ b/src/osmo-bsc/osmo_bsc_sigtran.c
@@ -593,8 +593,12 @@ static int asp_rx_unknown(struct osmo_ss7_asp *asp, int ppid_mux, struct msgb *m
switch (iph_ext->proto) {
case IPAC_PROTO_EXT_CTRL:
return bsc_sccplite_rx_ctrl(asp, msg);
+ case IPAC_PROTO_EXT_MGCP:
+ return bsc_sccplite_rx_mgcp(asp, msg);
}
break;
+ case IPAC_PROTO_MGCP_OLD:
+ return bsc_sccplite_rx_mgcp(asp, msg);
default:
break;
}