mirror of
https://gitea.osmocom.org/cellular-infrastructure/osmo-mgw.git
synced 2025-11-02 04:53:24 +00:00
Compare commits
14 Commits
openbsc/0.
...
openbsc/0.
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
79dcd719e0 | ||
|
|
8b19dee437 | ||
|
|
5f2cd84281 | ||
|
|
3f29cc8303 | ||
|
|
386a940736 | ||
|
|
bd7b3c5e45 | ||
|
|
e97155a2af | ||
|
|
2126233590 | ||
|
|
88b597e21c | ||
|
|
b54048fe25 | ||
|
|
fbca4ea117 | ||
|
|
43eb1a3db0 | ||
|
|
74779c68f7 | ||
|
|
d414c06fd9 |
@@ -98,7 +98,15 @@ struct mgcp_endpoint {
|
||||
/* port status for bts/net */
|
||||
struct mgcp_rtp_end bts_end;
|
||||
struct mgcp_rtp_end net_end;
|
||||
struct mgcp_rtp_end transcoder_end;
|
||||
|
||||
/*
|
||||
* For transcoding we will send from the local_port
|
||||
* of trans_bts and it will arrive at trans_net from
|
||||
* where we will forward it to the network.
|
||||
*/
|
||||
struct mgcp_rtp_end trans_bts;
|
||||
struct mgcp_rtp_end trans_net;
|
||||
int is_transcoded;
|
||||
|
||||
/* sequence bits */
|
||||
struct mgcp_rtp_state net_state;
|
||||
@@ -124,7 +132,15 @@ int mgcp_analyze_header(struct mgcp_config *cfg, struct msgb *msg,
|
||||
int mgcp_send_dummy(struct mgcp_endpoint *endp);
|
||||
int mgcp_bind_bts_rtp_port(struct mgcp_endpoint *endp, int rtp_port);
|
||||
int mgcp_bind_net_rtp_port(struct mgcp_endpoint *endp, int rtp_port);
|
||||
int mgcp_bind_transcoder_rtp_port(struct mgcp_endpoint *enp, int rtp_port);
|
||||
int mgcp_bind_trans_bts_rtp_port(struct mgcp_endpoint *enp, int rtp_port);
|
||||
int mgcp_bind_trans_net_rtp_port(struct mgcp_endpoint *enp, int rtp_port);
|
||||
int mgcp_free_rtp_port(struct mgcp_rtp_end *end);
|
||||
|
||||
/* For transcoding we need to manage an in and an output that are connected */
|
||||
static inline int endp_back_channel(int endpoint)
|
||||
{
|
||||
return endpoint + 60;
|
||||
}
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
@@ -168,31 +168,22 @@ static int forward_data(int fd, struct mgcp_rtp_tap *tap, const char *buf, int l
|
||||
(struct sockaddr *)&tap->forward, sizeof(tap->forward));
|
||||
}
|
||||
|
||||
static int send_transcoder(struct mgcp_endpoint *endp, int is_rtp,
|
||||
const char *buf, int len)
|
||||
static int send_transcoder(struct mgcp_rtp_end *end, struct mgcp_config *cfg,
|
||||
int is_rtp, const char *buf, int len)
|
||||
{
|
||||
int rc;
|
||||
int port;
|
||||
struct mgcp_config *cfg = endp->cfg;
|
||||
struct sockaddr_in addr;
|
||||
|
||||
if (endp->transcoder_end.rtp_port == 0) {
|
||||
LOGP(DMGCP, LOGL_ERROR, "Transcoder port not known on 0x%x\n",
|
||||
ENDPOINT_NUMBER(endp));
|
||||
return -1;
|
||||
}
|
||||
|
||||
port = rtp_calculate_port(ENDPOINT_NUMBER(endp), cfg->transcoder_remote_base);
|
||||
if (!is_rtp)
|
||||
port += 1;
|
||||
port = is_rtp ? end->rtp_port : end->rtcp_port;
|
||||
|
||||
addr.sin_family = AF_INET;
|
||||
addr.sin_addr = cfg->transcoder_in;
|
||||
addr.sin_port = htons(port);
|
||||
addr.sin_port = port;
|
||||
|
||||
rc = sendto(is_rtp ?
|
||||
endp->bts_end.rtp.fd :
|
||||
endp->bts_end.rtcp.fd, buf, len, 0,
|
||||
end->rtp.fd :
|
||||
end->rtcp.fd, buf, len, 0,
|
||||
(struct sockaddr *) &addr, sizeof(addr));
|
||||
|
||||
if (rc != len)
|
||||
@@ -306,7 +297,10 @@ static int rtp_data_net(struct bsc_fd *fd, unsigned int what)
|
||||
endp->net_end.packets += 1;
|
||||
|
||||
forward_data(fd->fd, &endp->taps[MGCP_TAP_NET_IN], buf, rc);
|
||||
return send_to(endp, DEST_BTS, proto == PROTO_RTP, &addr, &buf[0], rc);
|
||||
if (endp->is_transcoded)
|
||||
return send_transcoder(&endp->trans_net, endp->cfg, proto == PROTO_RTP, &buf[0], rc);
|
||||
else
|
||||
return send_to(endp, DEST_BTS, proto == PROTO_RTP, &addr, &buf[0], rc);
|
||||
}
|
||||
|
||||
static void discover_bts(struct mgcp_endpoint *endp, int proto, struct sockaddr_in *addr)
|
||||
@@ -383,53 +377,67 @@ static int rtp_data_bts(struct bsc_fd *fd, unsigned int what)
|
||||
endp->bts_end.packets += 1;
|
||||
|
||||
forward_data(fd->fd, &endp->taps[MGCP_TAP_BTS_IN], buf, rc);
|
||||
if (cfg->transcoder_ip)
|
||||
return send_transcoder(endp, proto == PROTO_RTP, &buf[0], rc);
|
||||
if (endp->is_transcoded)
|
||||
return send_transcoder(&endp->trans_bts, endp->cfg, proto == PROTO_RTP, &buf[0], rc);
|
||||
else
|
||||
return send_to(endp, DEST_NETWORK, proto == PROTO_RTP, &addr, &buf[0], rc);
|
||||
}
|
||||
|
||||
static int rtp_data_transcoder(struct bsc_fd *fd, unsigned int what)
|
||||
static int rtp_data_transcoder(struct mgcp_rtp_end *end, struct mgcp_endpoint *_endp,
|
||||
int dest, struct bsc_fd *fd)
|
||||
{
|
||||
char buf[4096];
|
||||
struct sockaddr_in addr;
|
||||
struct mgcp_endpoint *endp;
|
||||
struct mgcp_config *cfg;
|
||||
int rc, proto;
|
||||
|
||||
endp = (struct mgcp_endpoint *) fd->data;
|
||||
cfg = endp->cfg;
|
||||
|
||||
rc = recevice_from(endp, fd->fd, &addr, buf, sizeof(buf));
|
||||
cfg = _endp->cfg;
|
||||
rc = recevice_from(_endp, fd->fd, &addr, buf, sizeof(buf));
|
||||
if (rc <= 0)
|
||||
return -1;
|
||||
|
||||
proto = fd == &endp->transcoder_end.rtp ? PROTO_RTP : PROTO_RTCP;
|
||||
proto = fd == &end->rtp ? PROTO_RTP : PROTO_RTCP;
|
||||
|
||||
if (memcmp(&addr.sin_addr, &cfg->transcoder_in, sizeof(addr.sin_addr)) != 0) {
|
||||
LOGP(DMGCP, LOGL_ERROR,
|
||||
"Data not coming from transcoder: %s on 0x%x\n",
|
||||
inet_ntoa(addr.sin_addr), ENDPOINT_NUMBER(endp));
|
||||
"Data not coming from transcoder dest: %d %s on 0x%x\n",
|
||||
dest, inet_ntoa(addr.sin_addr), ENDPOINT_NUMBER(_endp));
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (endp->transcoder_end.rtp_port != addr.sin_port &&
|
||||
endp->transcoder_end.rtcp_port != addr.sin_port) {
|
||||
if (end->rtp_port != addr.sin_port &&
|
||||
end->rtcp_port != addr.sin_port) {
|
||||
LOGP(DMGCP, LOGL_ERROR,
|
||||
"Data from wrong transcoder source port %d on 0x%x\n",
|
||||
ntohs(addr.sin_port), ENDPOINT_NUMBER(endp));
|
||||
"Data from wrong transcoder dest %d source port %d on 0x%x\n",
|
||||
dest, ntohs(addr.sin_port), ENDPOINT_NUMBER(_endp));
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* throw away the dummy message */
|
||||
if (rc == 1 && buf[0] == DUMMY_LOAD) {
|
||||
LOGP(DMGCP, LOGL_NOTICE, "Filtered dummy from transcoder on 0x%x\n",
|
||||
ENDPOINT_NUMBER(endp));
|
||||
LOGP(DMGCP, LOGL_NOTICE, "Filtered dummy from transcoder dest %d on 0x%x\n",
|
||||
dest, ENDPOINT_NUMBER(_endp));
|
||||
return 0;
|
||||
}
|
||||
|
||||
endp->transcoder_end.packets += 1;
|
||||
return send_to(endp, DEST_NETWORK, proto == PROTO_RTP, &addr, &buf[0], rc);
|
||||
end->packets += 1;
|
||||
return send_to(_endp, dest, proto == PROTO_RTP, &addr, &buf[0], rc);
|
||||
}
|
||||
|
||||
static int rtp_data_trans_net(struct bsc_fd *fd, unsigned int what)
|
||||
{
|
||||
struct mgcp_endpoint *endp;
|
||||
endp = (struct mgcp_endpoint *) fd->data;
|
||||
|
||||
return rtp_data_transcoder(&endp->trans_net, endp, DEST_NETWORK, fd);
|
||||
}
|
||||
|
||||
static int rtp_data_trans_bts(struct bsc_fd *fd, unsigned int what)
|
||||
{
|
||||
struct mgcp_endpoint *endp;
|
||||
endp = (struct mgcp_endpoint *) fd->data;
|
||||
|
||||
return rtp_data_transcoder(&endp->trans_bts, endp, DEST_BTS, fd);
|
||||
}
|
||||
|
||||
static int create_bind(const char *source_addr, struct bsc_fd *fd, int port)
|
||||
@@ -511,52 +519,47 @@ cleanup0:
|
||||
return -1;
|
||||
}
|
||||
|
||||
int mgcp_bind_bts_rtp_port(struct mgcp_endpoint *endp, int rtp_port)
|
||||
static int int_bind(const char *port,
|
||||
struct mgcp_rtp_end *end, int (*cb)(struct bsc_fd *, unsigned),
|
||||
struct mgcp_endpoint *_endp, int rtp_port)
|
||||
{
|
||||
if (endp->bts_end.rtp.fd != -1 || endp->bts_end.rtcp.fd != -1) {
|
||||
LOGP(DMGCP, LOGL_ERROR, "Previous bts-port was still bound on %d\n",
|
||||
ENDPOINT_NUMBER(endp));
|
||||
mgcp_free_rtp_port(&endp->bts_end);
|
||||
if (end->rtp.fd != -1 || end->rtcp.fd != -1) {
|
||||
LOGP(DMGCP, LOGL_ERROR, "Previous %s was still bound on %d\n",
|
||||
port, ENDPOINT_NUMBER(_endp));
|
||||
mgcp_free_rtp_port(end);
|
||||
}
|
||||
|
||||
endp->bts_end.local_port = rtp_port;
|
||||
endp->bts_end.rtp.cb = rtp_data_bts;
|
||||
endp->bts_end.rtp.data = endp;
|
||||
endp->bts_end.rtcp.data = endp;
|
||||
endp->bts_end.rtcp.cb = rtp_data_bts;
|
||||
return bind_rtp(endp->cfg, &endp->bts_end, ENDPOINT_NUMBER(endp));
|
||||
end->local_port = rtp_port;
|
||||
end->rtp.cb = cb;
|
||||
end->rtp.data = _endp;
|
||||
end->rtcp.data = _endp;
|
||||
end->rtcp.cb = cb;
|
||||
return bind_rtp(_endp->cfg, 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);
|
||||
}
|
||||
|
||||
int mgcp_bind_net_rtp_port(struct mgcp_endpoint *endp, int rtp_port)
|
||||
{
|
||||
if (endp->net_end.rtp.fd != -1 || endp->net_end.rtcp.fd != -1) {
|
||||
LOGP(DMGCP, LOGL_ERROR, "Previous net-port was still bound on %d\n",
|
||||
ENDPOINT_NUMBER(endp));
|
||||
mgcp_free_rtp_port(&endp->net_end);
|
||||
}
|
||||
|
||||
endp->net_end.local_port = rtp_port;
|
||||
endp->net_end.rtp.cb = rtp_data_net;
|
||||
endp->net_end.rtp.data = endp;
|
||||
endp->net_end.rtcp.data = endp;
|
||||
endp->net_end.rtcp.cb = rtp_data_net;
|
||||
return bind_rtp(endp->cfg, &endp->net_end, ENDPOINT_NUMBER(endp));
|
||||
return int_bind("net-port", &endp->net_end,
|
||||
rtp_data_net, endp, rtp_port);
|
||||
}
|
||||
|
||||
int mgcp_bind_transcoder_rtp_port(struct mgcp_endpoint *endp, int rtp_port)
|
||||
int mgcp_bind_trans_net_rtp_port(struct mgcp_endpoint *endp, int rtp_port)
|
||||
{
|
||||
if (endp->transcoder_end.rtp.fd != -1 || endp->transcoder_end.rtcp.fd != -1) {
|
||||
LOGP(DMGCP, LOGL_ERROR, "Previous net-port was still bound on %d\n",
|
||||
ENDPOINT_NUMBER(endp));
|
||||
mgcp_free_rtp_port(&endp->transcoder_end);
|
||||
}
|
||||
return int_bind("trans-net", &endp->trans_net,
|
||||
rtp_data_trans_net, endp, rtp_port);
|
||||
}
|
||||
|
||||
endp->transcoder_end.local_port = rtp_port;
|
||||
endp->transcoder_end.rtp.cb = rtp_data_transcoder;
|
||||
endp->transcoder_end.rtp.data = endp;
|
||||
endp->transcoder_end.rtcp.data = endp;
|
||||
endp->transcoder_end.rtcp.cb = rtp_data_transcoder;
|
||||
return bind_rtp(endp->cfg, &endp->transcoder_end, ENDPOINT_NUMBER(endp));
|
||||
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);
|
||||
}
|
||||
|
||||
int mgcp_free_rtp_port(struct mgcp_rtp_end *end)
|
||||
|
||||
@@ -382,7 +382,6 @@ static int allocate_port(struct mgcp_endpoint *endp, struct mgcp_rtp_end *end,
|
||||
int i;
|
||||
|
||||
if (range->mode == PORT_ALLOC_STATIC) {
|
||||
end->local_port = rtp_calculate_port(ENDPOINT_NUMBER(endp), range->base_port);
|
||||
end->local_alloc = PORT_ALLOC_STATIC;
|
||||
return 0;
|
||||
}
|
||||
@@ -421,12 +420,26 @@ static int allocate_ports(struct mgcp_endpoint *endp)
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (endp->cfg->transcoder_ip &&
|
||||
allocate_port(endp, &endp->transcoder_end, &endp->cfg->transcoder_ports,
|
||||
mgcp_bind_transcoder_rtp_port) != 0) {
|
||||
mgcp_rtp_end_reset(&endp->net_end);
|
||||
mgcp_rtp_end_reset(&endp->bts_end);
|
||||
return -1;
|
||||
if (endp->cfg->transcoder_ip) {
|
||||
if (allocate_port(endp, &endp->trans_net,
|
||||
&endp->cfg->transcoder_ports,
|
||||
mgcp_bind_trans_net_rtp_port) != 0) {
|
||||
mgcp_rtp_end_reset(&endp->net_end);
|
||||
mgcp_rtp_end_reset(&endp->bts_end);
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (allocate_port(endp, &endp->trans_bts,
|
||||
&endp->cfg->transcoder_ports,
|
||||
mgcp_bind_trans_bts_rtp_port) != 0) {
|
||||
mgcp_rtp_end_reset(&endp->net_end);
|
||||
mgcp_rtp_end_reset(&endp->bts_end);
|
||||
mgcp_rtp_end_reset(&endp->trans_net);
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* remember that we have set up transcoding */
|
||||
endp->is_transcoded = 1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
@@ -790,12 +803,14 @@ struct mgcp_config *mgcp_config_alloc(void)
|
||||
|
||||
static void mgcp_rtp_end_reset(struct mgcp_rtp_end *end)
|
||||
{
|
||||
if (end->local_alloc == PORT_ALLOC_DYNAMIC)
|
||||
if (end->local_alloc == PORT_ALLOC_DYNAMIC) {
|
||||
mgcp_free_rtp_port(end);
|
||||
end->local_port = 0;
|
||||
}
|
||||
|
||||
end->packets = 0;
|
||||
memset(&end->addr, 0, sizeof(end->addr));
|
||||
end->rtp_port = end->rtcp_port = end->local_port = 0;
|
||||
end->rtp_port = end->rtcp_port = 0;
|
||||
end->payload_type = -1;
|
||||
end->local_alloc = -1;
|
||||
}
|
||||
@@ -823,7 +838,8 @@ int mgcp_endpoints_allocate(struct mgcp_config *cfg)
|
||||
cfg->endpoints[i].cfg = cfg;
|
||||
mgcp_rtp_end_init(&cfg->endpoints[i].net_end);
|
||||
mgcp_rtp_end_init(&cfg->endpoints[i].bts_end);
|
||||
mgcp_rtp_end_init(&cfg->endpoints[i].transcoder_end);
|
||||
mgcp_rtp_end_init(&cfg->endpoints[i].trans_net);
|
||||
mgcp_rtp_end_init(&cfg->endpoints[i].trans_bts);
|
||||
}
|
||||
|
||||
return 0;
|
||||
@@ -847,7 +863,9 @@ void mgcp_free_endp(struct mgcp_endpoint *endp)
|
||||
|
||||
mgcp_rtp_end_reset(&endp->bts_end);
|
||||
mgcp_rtp_end_reset(&endp->net_end);
|
||||
mgcp_rtp_end_reset(&endp->transcoder_end);
|
||||
mgcp_rtp_end_reset(&endp->trans_net);
|
||||
mgcp_rtp_end_reset(&endp->trans_bts);
|
||||
endp->is_transcoded = 0;
|
||||
|
||||
memset(&endp->net_state, 0, sizeof(endp->net_state));
|
||||
memset(&endp->bts_state, 0, sizeof(endp->bts_state));
|
||||
@@ -858,12 +876,6 @@ void mgcp_free_endp(struct mgcp_endpoint *endp)
|
||||
memset(&endp->taps, 0, sizeof(endp->taps));
|
||||
}
|
||||
|
||||
/* For transcoding we need to manage an in and an output that are connected */
|
||||
static int back_channel(int endpoint)
|
||||
{
|
||||
return endpoint + 60;
|
||||
}
|
||||
|
||||
static int send_trans(struct mgcp_config *cfg, const char *buf, int len)
|
||||
{
|
||||
struct sockaddr_in addr;
|
||||
@@ -925,27 +937,31 @@ static void create_transcoder(struct mgcp_endpoint *endp)
|
||||
{
|
||||
int port;
|
||||
int in_endp = ENDPOINT_NUMBER(endp);
|
||||
int out_endp = back_channel(in_endp);
|
||||
int out_endp = endp_back_channel(in_endp);
|
||||
|
||||
if (!endp->cfg->transcoder_ip)
|
||||
if (!endp->is_transcoded)
|
||||
return;
|
||||
|
||||
send_msg(endp, in_endp, endp->bts_end.local_port, "CRCX", "recvonly");
|
||||
send_msg(endp, in_endp, endp->bts_end.local_port, "MDCX", "recvonly");
|
||||
send_msg(endp, out_endp, endp->transcoder_end.local_port, "CRCX", "sendrecv");
|
||||
send_msg(endp, out_endp, endp->transcoder_end.local_port, "MDCX", "sendrecv");
|
||||
send_msg(endp, in_endp, endp->trans_bts.local_port, "CRCX", "sendrecv");
|
||||
send_msg(endp, in_endp, endp->trans_bts.local_port, "MDCX", "sendrecv");
|
||||
send_msg(endp, out_endp, endp->trans_net.local_port, "CRCX", "sendrecv");
|
||||
send_msg(endp, out_endp, endp->trans_net.local_port, "MDCX", "sendrecv");
|
||||
|
||||
port = rtp_calculate_port(in_endp, endp->cfg->transcoder_remote_base);
|
||||
endp->trans_bts.rtp_port = htons(port);
|
||||
endp->trans_bts.rtcp_port = htons(port + 1);
|
||||
|
||||
port = rtp_calculate_port(out_endp, endp->cfg->transcoder_remote_base);
|
||||
endp->transcoder_end.rtp_port = htons(port);
|
||||
endp->transcoder_end.rtcp_port = htons(port + 1);
|
||||
endp->trans_net.rtp_port = htons(port);
|
||||
endp->trans_net.rtcp_port = htons(port + 1);
|
||||
}
|
||||
|
||||
static void delete_transcoder(struct mgcp_endpoint *endp)
|
||||
{
|
||||
int in_endp = ENDPOINT_NUMBER(endp);
|
||||
int out_endp = back_channel(in_endp);
|
||||
int out_endp = endp_back_channel(in_endp);
|
||||
|
||||
if (!endp->cfg->transcoder_ip)
|
||||
if (!endp->is_transcoded)
|
||||
return;
|
||||
|
||||
send_dlcx(endp, in_endp);
|
||||
|
||||
@@ -99,14 +99,14 @@ DEFUN(show_mcgp, show_mgcp_cmd, "show mgcp",
|
||||
vty_out(vty, "MGCP is up and running with %u endpoints:%s", g_cfg->number_endpoints - 1, VTY_NEWLINE);
|
||||
for (i = 1; i < g_cfg->number_endpoints; ++i) {
|
||||
struct mgcp_endpoint *endp = &g_cfg->endpoints[i];
|
||||
vty_out(vty, " Endpoint 0x%.2x: CI: %d net: %u/%u bts: %u/%u on %s traffic received bts: %u/%u remote: %u/%u transcoder: %u%s",
|
||||
vty_out(vty, " Endpoint 0x%.2x: CI: %d net: %u/%u bts: %u/%u on %s traffic received bts: %u/%u remote: %u/%u transcoder: %u/%u%s",
|
||||
i, endp->ci,
|
||||
ntohs(endp->net_end.rtp_port), ntohs(endp->net_end.rtcp_port),
|
||||
ntohs(endp->bts_end.rtp_port), ntohs(endp->bts_end.rtcp_port),
|
||||
inet_ntoa(endp->bts_end.addr),
|
||||
endp->bts_end.packets, endp->bts_state.lost_no,
|
||||
endp->net_end.packets, endp->net_state.lost_no,
|
||||
endp->transcoder_end.packets,
|
||||
endp->trans_net.packets, endp->trans_bts.packets,
|
||||
VTY_NEWLINE);
|
||||
}
|
||||
|
||||
@@ -319,6 +319,20 @@ DEFUN(cfg_mgcp_transcoder,
|
||||
return CMD_SUCCESS;
|
||||
}
|
||||
|
||||
DEFUN(cfg_mgcp_no_transcoder,
|
||||
cfg_mgcp_no_transcoder_cmd,
|
||||
NO_STR "transcoder-mgw",
|
||||
"Disable the transcoding\n")
|
||||
{
|
||||
if (g_cfg->transcoder_ip) {
|
||||
LOGP(DMGCP, LOGL_NOTICE, "Disabling transcoding on future calls.\n");
|
||||
talloc_free(g_cfg->transcoder_ip);
|
||||
g_cfg->transcoder_ip = NULL;
|
||||
}
|
||||
|
||||
return CMD_SUCCESS;
|
||||
}
|
||||
|
||||
DEFUN(cfg_mgcp_transcoder_remote_base,
|
||||
cfg_mgcp_transcoder_remote_base_cmd,
|
||||
"transcoder-remote-base <0-65534>",
|
||||
@@ -453,6 +467,7 @@ int mgcp_vty_init(void)
|
||||
install_element(MGCP_NODE, &cfg_mgcp_number_endp_cmd);
|
||||
install_element(MGCP_NODE, &cfg_mgcp_agent_addr_cmd);
|
||||
install_element(MGCP_NODE, &cfg_mgcp_transcoder_cmd);
|
||||
install_element(MGCP_NODE, &cfg_mgcp_no_transcoder_cmd);
|
||||
install_element(MGCP_NODE, &cfg_mgcp_transcoder_remote_base_cmd);
|
||||
return 0;
|
||||
}
|
||||
@@ -508,13 +523,23 @@ int mgcp_parse_config(const char *config_file, struct mgcp_config *cfg)
|
||||
}
|
||||
|
||||
if (g_cfg->transcoder_ip && g_cfg->transcoder_ports.mode == PORT_ALLOC_STATIC) {
|
||||
/* network side */
|
||||
rtp_port = rtp_calculate_port(ENDPOINT_NUMBER(endp),
|
||||
g_cfg->transcoder_ports.base_port);
|
||||
if (mgcp_bind_transcoder_rtp_port(endp, rtp_port) != 0) {
|
||||
if (mgcp_bind_trans_net_rtp_port(endp, rtp_port) != 0) {
|
||||
LOGP(DMGCP, LOGL_FATAL, "Failed to bind: %d\n", rtp_port);
|
||||
return -1;
|
||||
}
|
||||
endp->transcoder_end.local_alloc = PORT_ALLOC_STATIC;
|
||||
endp->trans_net.local_alloc = PORT_ALLOC_STATIC;
|
||||
|
||||
/* bts side */
|
||||
rtp_port = rtp_calculate_port(endp_back_channel(ENDPOINT_NUMBER(endp)),
|
||||
g_cfg->transcoder_ports.base_port);
|
||||
if (mgcp_bind_trans_bts_rtp_port(endp, rtp_port) != 0) {
|
||||
LOGP(DMGCP, LOGL_FATAL, "Failed to bind: %d\n", rtp_port);
|
||||
return -1;
|
||||
}
|
||||
endp->trans_bts.local_alloc = PORT_ALLOC_STATIC;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -252,26 +252,36 @@ static void nat_send_rlsd_bsc(struct sccp_connections *conn)
|
||||
bsc_write(conn->bsc, msg, IPAC_PROTO_SCCP);
|
||||
}
|
||||
|
||||
static void nat_send_clrc_bsc(struct sccp_connections *conn)
|
||||
static struct msgb *nat_creat_clrc(struct sccp_connections *conn, uint8_t cause)
|
||||
{
|
||||
struct msgb *msg;
|
||||
struct msgb *sccp;
|
||||
|
||||
msg = gsm0808_create_clear_command(0x20);
|
||||
msg = gsm0808_create_clear_command(cause);
|
||||
if (!msg) {
|
||||
LOGP(DNAT, LOGL_ERROR, "Failed to allocate clear command.\n");
|
||||
return;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
sccp = sccp_create_dt1(&conn->real_ref, msg->data, msg->len);
|
||||
if (!sccp) {
|
||||
LOGP(DNAT, LOGL_ERROR, "Failed to allocate SCCP msg.\n");
|
||||
msgb_free(msg);
|
||||
return;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
msgb_free(msg);
|
||||
bsc_write(conn->bsc, sccp, IPAC_PROTO_SCCP);
|
||||
return sccp;
|
||||
}
|
||||
|
||||
static int nat_send_clrc_bsc(struct sccp_connections *conn)
|
||||
{
|
||||
struct msgb *sccp;
|
||||
|
||||
sccp = nat_creat_clrc(conn, 0x20);
|
||||
if (!sccp)
|
||||
return -1;
|
||||
return bsc_write(conn->bsc, sccp, IPAC_PROTO_SCCP);
|
||||
}
|
||||
|
||||
static void nat_send_rlc(struct bsc_msc_connection *msc_con,
|
||||
@@ -424,6 +434,8 @@ static void bsc_send_con_release(struct bsc_connection *bsc, struct sccp_connect
|
||||
}
|
||||
}
|
||||
|
||||
nat_send_clrc_bsc(con);
|
||||
|
||||
rlsd = sccp_create_rlsd(&con->remote_ref, &con->real_ref,
|
||||
SCCP_RELEASE_CAUSE_END_USER_ORIGINATED);
|
||||
if (!rlsd) {
|
||||
@@ -458,7 +470,7 @@ static void bsc_send_con_refuse(struct bsc_connection *bsc,
|
||||
* 2.) queue data for downstream.. and the RLC should delete everything
|
||||
*/
|
||||
if (payload) {
|
||||
struct msgb *cc, *udt, *rlsd;
|
||||
struct msgb *cc, *udt, *clear, *rlsd;
|
||||
struct sccp_connections *con;
|
||||
con = create_sccp_src_ref(bsc, parsed);
|
||||
if (!con)
|
||||
@@ -483,17 +495,27 @@ static void bsc_send_con_refuse(struct bsc_connection *bsc,
|
||||
goto send_refuse;
|
||||
}
|
||||
|
||||
/* 3. send a RLSD */
|
||||
rlsd = sccp_create_rlsd(&con->remote_ref, &con->real_ref,
|
||||
SCCP_RELEASE_CAUSE_END_USER_ORIGINATED);
|
||||
if (!rlsd) {
|
||||
/* 3. send a Clear Command */
|
||||
clear = nat_creat_clrc(con, 0x20);
|
||||
if (!clear) {
|
||||
msgb_free(cc);
|
||||
msgb_free(udt);
|
||||
goto send_refuse;
|
||||
}
|
||||
|
||||
/* 4. send a RLSD */
|
||||
rlsd = sccp_create_rlsd(&con->remote_ref, &con->real_ref,
|
||||
SCCP_RELEASE_CAUSE_END_USER_ORIGINATED);
|
||||
if (!rlsd) {
|
||||
msgb_free(cc);
|
||||
msgb_free(udt);
|
||||
msgb_free(clear);
|
||||
goto send_refuse;
|
||||
}
|
||||
|
||||
bsc_write(bsc, cc, IPAC_PROTO_SCCP);
|
||||
bsc_write(bsc, udt, IPAC_PROTO_SCCP);
|
||||
bsc_write(bsc, clear, IPAC_PROTO_SCCP);
|
||||
bsc_write(bsc, rlsd, IPAC_PROTO_SCCP);
|
||||
msgb_free(payload);
|
||||
return;
|
||||
|
||||
@@ -785,9 +785,9 @@ struct msgb *bsc_nat_rewrite_setup(struct bsc_nat *nat, struct msgb *msg, struct
|
||||
regex_t reg;
|
||||
regmatch_t matches[2];
|
||||
|
||||
if (entry->mcc[0] == '*' || strncmp(entry->mcc, imsi, 3) != 0)
|
||||
if (entry->mcc[0] != '*' && strncmp(entry->mcc, imsi, 3) != 0)
|
||||
continue;
|
||||
if (entry->mnc[0] == '*' || strncmp(entry->mnc, imsi + 3, 2) != 0)
|
||||
if (entry->mnc[0] != '*' && strncmp(entry->mnc, imsi + 3, 2) != 0)
|
||||
continue;
|
||||
|
||||
if (entry->text[0] == '+') {
|
||||
|
||||
@@ -878,6 +878,68 @@ static void test_setup_rewrite()
|
||||
}
|
||||
|
||||
msgb_free(out);
|
||||
|
||||
/* Make sure that a wildcard is matching */
|
||||
entry.mnc = "*";
|
||||
msg = msgb_alloc(4096, "test_dt_filter");
|
||||
copy_to_msg(msg, cc_setup_national, ARRAY_SIZE(cc_setup_national));
|
||||
parsed = bsc_nat_parse(msg);
|
||||
if (!parsed) {
|
||||
fprintf(stderr, "FAIL: Could not parse ID resp\n");
|
||||
abort();
|
||||
}
|
||||
|
||||
out = bsc_nat_rewrite_setup(nat, msg, parsed, imsi);
|
||||
if (!out) {
|
||||
fprintf(stderr, "FAIL: A new message should be created.\n");
|
||||
abort();
|
||||
}
|
||||
|
||||
if (msg == out) {
|
||||
fprintf(stderr, "FAIL: The message should have changed\n");
|
||||
abort();
|
||||
}
|
||||
|
||||
if (out->len != ARRAY_SIZE(cc_setup_national_patched)) {
|
||||
fprintf(stderr, "FAIL: Length is wrong.\n");
|
||||
abort();
|
||||
}
|
||||
|
||||
if (memcmp(cc_setup_national_patched, out->data, out->len) != 0) {
|
||||
fprintf(stderr, "FAIL: Data is wrong.\n");
|
||||
fprintf(stderr, "Data was: %s\n", hexdump(out->data, out->len));
|
||||
abort();
|
||||
}
|
||||
|
||||
msgb_free(out);
|
||||
|
||||
/* Make sure that a wildcard is matching */
|
||||
entry.mnc = "09";
|
||||
msg = msgb_alloc(4096, "test_dt_filter");
|
||||
copy_to_msg(msg, cc_setup_national, ARRAY_SIZE(cc_setup_national));
|
||||
parsed = bsc_nat_parse(msg);
|
||||
if (!parsed) {
|
||||
fprintf(stderr, "FAIL: Could not parse ID resp\n");
|
||||
abort();
|
||||
}
|
||||
|
||||
out = bsc_nat_rewrite_setup(nat, msg, parsed, imsi);
|
||||
if (out != msg) {
|
||||
fprintf(stderr, "FAIL: The message should be unchanged.\n");
|
||||
abort();
|
||||
}
|
||||
|
||||
if (out->len != ARRAY_SIZE(cc_setup_national)) {
|
||||
fprintf(stderr, "FAIL: Foo\n");
|
||||
abort();
|
||||
}
|
||||
|
||||
if (memcmp(out->data, cc_setup_national, ARRAY_SIZE(cc_setup_national)) != 0) {
|
||||
fprintf(stderr, "FAIL: The message should really be unchanged.\n");
|
||||
abort();
|
||||
}
|
||||
|
||||
msgb_free(out);
|
||||
}
|
||||
|
||||
int main(int argc, char **argv)
|
||||
|
||||
Reference in New Issue
Block a user