diff options
author | Harald Welte <laforge@gnumonks.org> | 2018-05-26 22:56:59 +0200 |
---|---|---|
committer | laforge <laforge@gnumonks.org> | 2019-06-18 18:09:26 +0000 |
commit | 1626f909461becfe1bb09707640ab23685b970dd (patch) | |
tree | 53813aaf3aef62737bb66bc25d97c14b48fecb56 /src/osmo-bsc | |
parent | 062cd20993f6c6c0525c17cfe94b8721db79964d (diff) |
Re-introduce support for IPA-encapsulated MGCP
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 create 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
Diffstat (limited to 'src/osmo-bsc')
-rw-r--r-- | src/osmo-bsc/Makefile.am | 1 | ||||
-rw-r--r-- | src/osmo-bsc/osmo_bsc_ctrl.c | 59 | ||||
-rw-r--r-- | src/osmo-bsc/osmo_bsc_mgcp.c | 92 | ||||
-rw-r--r-- | src/osmo-bsc/osmo_bsc_msc.c | 31 | ||||
-rw-r--r-- | src/osmo-bsc/osmo_bsc_sigtran.c | 4 |
5 files changed, 167 insertions, 20 deletions
diff --git a/src/osmo-bsc/Makefile.am b/src/osmo-bsc/Makefile.am index e88e6144b..d50515b0f 100644 --- a/src/osmo-bsc/Makefile.am +++ b/src/osmo-bsc/Makefile.am @@ -78,6 +78,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..bec793032 --- /dev/null +++ b/src/osmo-bsc/osmo_bsc_mgcp.c @@ -0,0 +1,92 @@ +/* + * 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 enough 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); + msg->l2h[rc] = '\0'; + 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 6a6b1a93d..7e78d947c 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 >= 0) + mgw_port = net->mgw.conf->remote_port; + else + mgw_port = MGCP_CLIENT_REMOTE_PORT_DEFAULT; + + 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; } @@ -117,6 +140,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 18f269da0..763e1e161 100644 --- a/src/osmo-bsc/osmo_bsc_sigtran.c +++ b/src/osmo-bsc/osmo_bsc_sigtran.c @@ -611,8 +611,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; } |