summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHolger Hans Peter Freyther <holger@moiji-mobile.com>2015-08-20 14:58:19 +0200
committerHolger Hans Peter Freyther <holger@moiji-mobile.com>2015-08-20 14:58:19 +0200
commite6ed009a36d410fc0cbac7a82d92313bd6d4c084 (patch)
tree23ad7fed198f621cc414a3dee3341ebc934f3c76
parentceef936ea894781a14584efc9256856cca6d1c0f (diff)
mgcp: Begin to separate network and bts endpoints
Make it possible to bind the call-agent to a specific IP address and the network and bts end to different ip addresses. Begin by clarifying which source ip address we want to have.
-rw-r--r--openbsc/include/openbsc/mgcp_internal.h14
-rw-r--r--openbsc/src/libmgcp/mgcp_network.c29
-rw-r--r--openbsc/src/libmgcp/mgcp_protocol.c5
-rw-r--r--openbsc/src/osmo-bsc_nat/bsc_mgcp_utils.c6
4 files changed, 36 insertions, 18 deletions
diff --git a/openbsc/include/openbsc/mgcp_internal.h b/openbsc/include/openbsc/mgcp_internal.h
index 485a124..f97292d 100644
--- a/openbsc/include/openbsc/mgcp_internal.h
+++ b/openbsc/include/openbsc/mgcp_internal.h
@@ -320,3 +320,17 @@ enum {
int mgcp_parse_sdp_data(struct mgcp_endpoint *endp, struct mgcp_rtp_end *rtp, struct mgcp_parse_data *p);
int mgcp_set_audio_info(void *ctx, struct mgcp_rtp_codec *codec,
int payload_type, const char *audio_name);
+
+
+/**
+ * Internal network related
+ */
+static inline const char *mgcp_net_src_addr(struct mgcp_endpoint *endp)
+{
+ return endp->cfg->source_addr;
+}
+
+static inline const char *mgcp_bts_src_addr(struct mgcp_endpoint *endp)
+{
+ return endp->cfg->source_addr;
+}
diff --git a/openbsc/src/libmgcp/mgcp_network.c b/openbsc/src/libmgcp/mgcp_network.c
index 07e1515..c39b627 100644
--- a/openbsc/src/libmgcp/mgcp_network.c
+++ b/openbsc/src/libmgcp/mgcp_network.c
@@ -912,19 +912,20 @@ int mgcp_set_ip_tos(int fd, int tos)
return ret != 0;
}
-static int bind_rtp(struct mgcp_config *cfg, struct mgcp_rtp_end *rtp_end, int endpno)
+static int bind_rtp(struct mgcp_config *cfg, const char *source_addr,
+ struct mgcp_rtp_end *rtp_end, int endpno)
{
- if (mgcp_create_bind(cfg->source_addr, &rtp_end->rtp,
+ if (mgcp_create_bind(source_addr, &rtp_end->rtp,
rtp_end->local_port) != 0) {
LOGP(DMGCP, LOGL_ERROR, "Failed to create RTP port: %s:%d on 0x%x\n",
- cfg->source_addr, rtp_end->local_port, endpno);
+ source_addr, rtp_end->local_port, endpno);
goto cleanup0;
}
- if (mgcp_create_bind(cfg->source_addr, &rtp_end->rtcp,
+ if (mgcp_create_bind(source_addr, &rtp_end->rtcp,
rtp_end->local_port + 1) != 0) {
LOGP(DMGCP, LOGL_ERROR, "Failed to create RTCP port: %s:%d on 0x%x\n",
- cfg->source_addr, rtp_end->local_port + 1, endpno);
+ source_addr, rtp_end->local_port + 1, endpno);
goto cleanup1;
}
@@ -961,7 +962,8 @@ cleanup0:
static int int_bind(const char *port,
struct mgcp_rtp_end *end, int (*cb)(struct osmo_fd *, unsigned),
- struct mgcp_endpoint *_endp, int rtp_port)
+ struct mgcp_endpoint *_endp,
+ const char *source_addr, int rtp_port)
{
if (end->rtp.fd != -1 || end->rtcp.fd != -1) {
LOGP(DMGCP, LOGL_ERROR, "Previous %s was still bound on %d\n",
@@ -974,32 +976,35 @@ static int int_bind(const char *port,
end->rtp.data = _endp;
end->rtcp.data = _endp;
end->rtcp.cb = cb;
- return bind_rtp(_endp->cfg, end, ENDPOINT_NUMBER(_endp));
+ return bind_rtp(_endp->cfg, source_addr, end, ENDPOINT_NUMBER(_endp));
}
-
int mgcp_bind_bts_rtp_port(struct mgcp_endpoint *endp, int rtp_port)
{
return int_bind("bts-port", &endp->bts_end,
- rtp_data_bts, endp, rtp_port);
+ rtp_data_bts, endp,
+ mgcp_bts_src_addr(endp), rtp_port);
}
int mgcp_bind_net_rtp_port(struct mgcp_endpoint *endp, int rtp_port)
{
return int_bind("net-port", &endp->net_end,
- rtp_data_net, endp, rtp_port);
+ rtp_data_net, endp,
+ mgcp_net_src_addr(endp), rtp_port);
}
int mgcp_bind_trans_net_rtp_port(struct mgcp_endpoint *endp, int rtp_port)
{
return int_bind("trans-net", &endp->trans_net,
- rtp_data_trans_net, endp, rtp_port);
+ rtp_data_trans_net, endp,
+ endp->cfg->source_addr, rtp_port);
}
int mgcp_bind_trans_bts_rtp_port(struct mgcp_endpoint *endp, int rtp_port)
{
return int_bind("trans-bts", &endp->trans_bts,
- rtp_data_trans_bts, endp, rtp_port);
+ rtp_data_trans_bts, endp,
+ endp->cfg->source_addr, rtp_port);
}
int mgcp_free_rtp_port(struct mgcp_rtp_end *end)
diff --git a/openbsc/src/libmgcp/mgcp_protocol.c b/openbsc/src/libmgcp/mgcp_protocol.c
index 40ea791..717c1fc 100644
--- a/openbsc/src/libmgcp/mgcp_protocol.c
+++ b/openbsc/src/libmgcp/mgcp_protocol.c
@@ -275,7 +275,7 @@ static struct msgb *create_response_with_sdp(struct mgcp_endpoint *endp,
char osmux_extension[strlen("\nX-Osmux: 255") + 1];
if (!addr)
- addr = endp->cfg->source_addr;
+ addr = mgcp_net_src_addr(endp);
if (endp->osmux.state == OSMUX_STATE_ACTIVATING)
sprintf(osmux_extension, "\nX-Osmux: %u", endp->osmux.cid);
@@ -1389,8 +1389,7 @@ static void send_msg(struct mgcp_endpoint *endp, int endpoint, int port,
if (len < 0)
return;
- nchars = write_response_sdp(endp, buf + len, sizeof(buf) + len - 1,
- endp->cfg->source_addr);
+ nchars = write_response_sdp(endp, buf + len, sizeof(buf) + len - 1, NULL);
if (nchars < 0)
return;
diff --git a/openbsc/src/osmo-bsc_nat/bsc_mgcp_utils.c b/openbsc/src/osmo-bsc_nat/bsc_mgcp_utils.c
index f04c981..f19cb4c 100644
--- a/openbsc/src/osmo-bsc_nat/bsc_mgcp_utils.c
+++ b/openbsc/src/osmo-bsc_nat/bsc_mgcp_utils.c
@@ -269,7 +269,7 @@ static void bsc_mgcp_send_mdcx(struct bsc_connection *bsc, int port, struct mgcp
"\r\n"
"c=IN IP4 %s\r\n"
"m=audio %d RTP/AVP 255\r\n",
- port, bsc->nat->mgcp_cfg->source_addr,
+ port, mgcp_bts_src_addr(endp),
endp->bts_end.local_port);
if (len < 0) {
LOGP(DMGCP, LOGL_ERROR, "snprintf for MDCX failed.\n");
@@ -550,7 +550,7 @@ static int bsc_mgcp_policy_cb(struct mgcp_trunk_config *tcfg, int endpoint, int
/* we need to generate a new and patched message */
bsc_msg = bsc_mgcp_rewrite((char *) nat->mgcp_msg, nat->mgcp_length,
- sccp->bsc_endp, nat->mgcp_cfg->source_addr,
+ sccp->bsc_endp, mgcp_bts_src_addr(mgcp_endp),
mgcp_endp->bts_end.local_port, osmux_cid,
&mgcp_endp->net_end.codec.payload_type,
nat->sdp_ensure_amr_mode_set);
@@ -745,7 +745,7 @@ void bsc_mgcp_forward(struct bsc_connection *bsc, struct msgb *msg)
* with the value of 0 should be no problem.
*/
output = bsc_mgcp_rewrite((char * ) msg->l2h, msgb_l2len(msg), -1,
- bsc->nat->mgcp_cfg->source_addr,
+ mgcp_net_src_addr(endp),
endp->net_end.local_port, -1,
&endp->bts_end.codec.payload_type,
bsc->nat->sdp_ensure_amr_mode_set);