mgcp: Allocate a different port for the networking...
Use the right source port when sending the message.
This commit is contained in:
parent
ee4657c376
commit
81938e9a57
|
@ -29,6 +29,7 @@
|
||||||
#include <arpa/inet.h>
|
#include <arpa/inet.h>
|
||||||
|
|
||||||
#define RTP_PORT_DEFAULT 4000
|
#define RTP_PORT_DEFAULT 4000
|
||||||
|
#define RTP_PORT_NET_DEFAULT 16000
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Calculate the RTP audio port for the given multiplex
|
* Calculate the RTP audio port for the given multiplex
|
||||||
|
@ -92,6 +93,7 @@ struct mgcp_config {
|
||||||
int audio_payload;
|
int audio_payload;
|
||||||
int audio_loop;
|
int audio_loop;
|
||||||
int rtp_bts_base_port;
|
int rtp_bts_base_port;
|
||||||
|
int rtp_net_base_port;
|
||||||
int endp_dscp;
|
int endp_dscp;
|
||||||
|
|
||||||
/* spec handling */
|
/* spec handling */
|
||||||
|
|
|
@ -99,5 +99,6 @@ int mgcp_analyze_header(struct mgcp_config *cfg, struct msgb *msg,
|
||||||
const char **transaction_id, struct mgcp_endpoint **endp);
|
const char **transaction_id, struct mgcp_endpoint **endp);
|
||||||
int mgcp_send_dummy(struct mgcp_endpoint *endp);
|
int mgcp_send_dummy(struct mgcp_endpoint *endp);
|
||||||
int mgcp_bind_bts_rtp_port(struct mgcp_endpoint *endp, int rtp_port);
|
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);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -236,21 +236,27 @@ static int rtp_data_cb(struct bsc_fd *fd, unsigned int what)
|
||||||
dest = !dest;
|
dest = !dest;
|
||||||
|
|
||||||
if (dest == DEST_NETWORK) {
|
if (dest == DEST_NETWORK) {
|
||||||
if (proto == PROTO_RTP)
|
if (proto == PROTO_RTP) {
|
||||||
patch_and_count(endp, &endp->bts_state,
|
patch_and_count(endp, &endp->bts_state,
|
||||||
endp->net_end.payload_type,
|
endp->net_end.payload_type,
|
||||||
&addr, buf, rc);
|
&addr, buf, rc);
|
||||||
return udp_send(fd->fd, &endp->net_end.addr,
|
return udp_send(endp->net_end.rtp.fd, &endp->net_end.addr,
|
||||||
proto == PROTO_RTP ? endp->net_end.rtp_port : endp->net_end.rtcp_port,
|
endp->net_end.rtp_port, buf, rc);
|
||||||
buf, rc);
|
} else {
|
||||||
|
return udp_send(endp->net_end.rtcp.fd, &endp->net_end.addr,
|
||||||
|
endp->net_end.rtcp_port, buf, rc);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
if (proto == PROTO_RTP)
|
if (proto == PROTO_RTP) {
|
||||||
patch_and_count(endp, &endp->net_state,
|
patch_and_count(endp, &endp->net_state,
|
||||||
endp->bts_end.payload_type,
|
endp->bts_end.payload_type,
|
||||||
&addr, buf, rc);
|
&addr, buf, rc);
|
||||||
return udp_send(fd->fd, &endp->bts_end.addr,
|
return udp_send(endp->bts_end.rtp.fd, &endp->bts_end.addr,
|
||||||
proto == PROTO_RTP ? endp->bts_end.rtp_port : endp->bts_end.rtcp_port,
|
endp->bts_end.rtp_port, buf, rc);
|
||||||
buf, rc);
|
} else {
|
||||||
|
return udp_send(endp->bts_end.rtcp.fd, &endp->bts_end.addr,
|
||||||
|
endp->bts_end.rtcp_port, buf, rc);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -286,53 +292,47 @@ static int set_ip_tos(int fd, int tos)
|
||||||
return ret != 0;
|
return ret != 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int bind_rtp(struct mgcp_endpoint *endp)
|
static int bind_rtp(struct mgcp_config *cfg, struct mgcp_rtp_end *rtp_end, int endpno)
|
||||||
{
|
{
|
||||||
struct mgcp_config *cfg = endp->cfg;
|
if (create_bind(cfg->source_addr, &rtp_end->rtp, rtp_end->local_port) != 0) {
|
||||||
|
|
||||||
if (create_bind(cfg->source_addr, &endp->bts_end.rtp, endp->bts_end.local_port) != 0) {
|
|
||||||
LOGP(DMGCP, LOGL_ERROR, "Failed to create RTP port: %s:%d on 0x%x\n",
|
LOGP(DMGCP, LOGL_ERROR, "Failed to create RTP port: %s:%d on 0x%x\n",
|
||||||
cfg->source_addr, endp->bts_end.local_port, ENDPOINT_NUMBER(endp));
|
cfg->source_addr, rtp_end->local_port, endpno);
|
||||||
goto cleanup0;
|
goto cleanup0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (create_bind(cfg->source_addr, &endp->bts_end.rtcp, endp->bts_end.local_port + 1) != 0) {
|
if (create_bind(cfg->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",
|
LOGP(DMGCP, LOGL_ERROR, "Failed to create RTCP port: %s:%d on 0x%x\n",
|
||||||
cfg->source_addr, endp->bts_end.local_port + 1, ENDPOINT_NUMBER(endp));
|
cfg->source_addr, rtp_end->local_port + 1, endpno);
|
||||||
goto cleanup1;
|
goto cleanup1;
|
||||||
}
|
}
|
||||||
|
|
||||||
set_ip_tos(endp->bts_end.rtp.fd, cfg->endp_dscp);
|
set_ip_tos(rtp_end->rtp.fd, cfg->endp_dscp);
|
||||||
set_ip_tos(endp->bts_end.rtcp.fd, cfg->endp_dscp);
|
set_ip_tos(rtp_end->rtcp.fd, cfg->endp_dscp);
|
||||||
|
|
||||||
endp->bts_end.rtp.cb = rtp_data_cb;
|
rtp_end->rtp.when = BSC_FD_READ;
|
||||||
endp->bts_end.rtp.data = endp;
|
if (bsc_register_fd(&rtp_end->rtp) != 0) {
|
||||||
endp->bts_end.rtp.when = BSC_FD_READ;
|
|
||||||
if (bsc_register_fd(&endp->bts_end.rtp) != 0) {
|
|
||||||
LOGP(DMGCP, LOGL_ERROR, "Failed to register RTP port %d on 0x%x\n",
|
LOGP(DMGCP, LOGL_ERROR, "Failed to register RTP port %d on 0x%x\n",
|
||||||
endp->bts_end.local_port, ENDPOINT_NUMBER(endp));
|
rtp_end->local_port, endpno);
|
||||||
goto cleanup2;
|
goto cleanup2;
|
||||||
}
|
}
|
||||||
|
|
||||||
endp->bts_end.rtcp.cb = rtp_data_cb;
|
rtp_end->rtcp.when = BSC_FD_READ;
|
||||||
endp->bts_end.rtcp.data = endp;
|
if (bsc_register_fd(&rtp_end->rtcp) != 0) {
|
||||||
endp->bts_end.rtcp.when = BSC_FD_READ;
|
|
||||||
if (bsc_register_fd(&endp->bts_end.rtcp) != 0) {
|
|
||||||
LOGP(DMGCP, LOGL_ERROR, "Failed to register RTCP port %d on 0x%x\n",
|
LOGP(DMGCP, LOGL_ERROR, "Failed to register RTCP port %d on 0x%x\n",
|
||||||
endp->bts_end.local_port + 1, ENDPOINT_NUMBER(endp));
|
rtp_end->local_port + 1, endpno);
|
||||||
goto cleanup3;
|
goto cleanup3;
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
cleanup3:
|
cleanup3:
|
||||||
bsc_unregister_fd(&endp->bts_end.rtp);
|
bsc_unregister_fd(&rtp_end->rtp);
|
||||||
cleanup2:
|
cleanup2:
|
||||||
close(endp->bts_end.rtcp.fd);
|
close(rtp_end->rtcp.fd);
|
||||||
endp->bts_end.rtcp.fd = -1;
|
rtp_end->rtcp.fd = -1;
|
||||||
cleanup1:
|
cleanup1:
|
||||||
close(endp->bts_end.rtp.fd);
|
close(rtp_end->rtp.fd);
|
||||||
endp->bts_end.rtp.fd = -1;
|
rtp_end->rtp.fd = -1;
|
||||||
cleanup0:
|
cleanup0:
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
@ -340,5 +340,19 @@ cleanup0:
|
||||||
int mgcp_bind_bts_rtp_port(struct mgcp_endpoint *endp, int rtp_port)
|
int mgcp_bind_bts_rtp_port(struct mgcp_endpoint *endp, int rtp_port)
|
||||||
{
|
{
|
||||||
endp->bts_end.local_port = rtp_port;
|
endp->bts_end.local_port = rtp_port;
|
||||||
return bind_rtp(endp);
|
endp->bts_end.rtp.cb = rtp_data_cb;
|
||||||
|
endp->bts_end.rtp.data = endp;
|
||||||
|
endp->bts_end.rtcp.data = endp;
|
||||||
|
endp->bts_end.rtcp.cb = rtp_data_cb;
|
||||||
|
return bind_rtp(endp->cfg, &endp->bts_end, ENDPOINT_NUMBER(endp));
|
||||||
|
}
|
||||||
|
|
||||||
|
int mgcp_bind_net_rtp_port(struct mgcp_endpoint *endp, int rtp_port)
|
||||||
|
{
|
||||||
|
endp->net_end.local_port = rtp_port;
|
||||||
|
endp->net_end.rtp.cb = rtp_data_cb;
|
||||||
|
endp->net_end.rtp.data = endp;
|
||||||
|
endp->net_end.rtcp.data = endp;
|
||||||
|
endp->net_end.rtcp.cb = rtp_data_cb;
|
||||||
|
return bind_rtp(endp->cfg, &endp->net_end, ENDPOINT_NUMBER(endp));
|
||||||
}
|
}
|
||||||
|
|
|
@ -429,6 +429,8 @@ static struct msgb *handle_create_con(struct mgcp_config *cfg, struct msgb *msg)
|
||||||
/* bind to the port now */
|
/* bind to the port now */
|
||||||
port = rtp_calculate_port(ENDPOINT_NUMBER(endp), cfg->rtp_bts_base_port);
|
port = rtp_calculate_port(ENDPOINT_NUMBER(endp), cfg->rtp_bts_base_port);
|
||||||
endp->bts_end.local_port = port;
|
endp->bts_end.local_port = port;
|
||||||
|
|
||||||
|
port = rtp_calculate_port(ENDPOINT_NUMBER(endp), cfg->rtp_net_base_port);
|
||||||
endp->net_end.local_port = port;
|
endp->net_end.local_port = port;
|
||||||
|
|
||||||
/* assign a local call identifier or fail */
|
/* assign a local call identifier or fail */
|
||||||
|
@ -709,6 +711,7 @@ struct mgcp_config *mgcp_config_alloc(void)
|
||||||
cfg->audio_name = talloc_strdup(cfg, "GSM-EFR/8000");
|
cfg->audio_name = talloc_strdup(cfg, "GSM-EFR/8000");
|
||||||
cfg->audio_payload = 97;
|
cfg->audio_payload = 97;
|
||||||
cfg->rtp_bts_base_port = RTP_PORT_DEFAULT;
|
cfg->rtp_bts_base_port = RTP_PORT_DEFAULT;
|
||||||
|
cfg->rtp_net_base_port = RTP_PORT_NET_DEFAULT;
|
||||||
|
|
||||||
return cfg;
|
return cfg;
|
||||||
}
|
}
|
||||||
|
|
|
@ -57,6 +57,7 @@ static int config_write_mgcp(struct vty *vty)
|
||||||
vty_out(vty, " bind ip %s%s", g_cfg->source_addr, VTY_NEWLINE);
|
vty_out(vty, " bind ip %s%s", g_cfg->source_addr, VTY_NEWLINE);
|
||||||
vty_out(vty, " bind port %u%s", g_cfg->source_port, VTY_NEWLINE);
|
vty_out(vty, " bind port %u%s", g_cfg->source_port, VTY_NEWLINE);
|
||||||
vty_out(vty, " rtp bts-base %u%s", g_cfg->rtp_bts_base_port, VTY_NEWLINE);
|
vty_out(vty, " rtp bts-base %u%s", g_cfg->rtp_bts_base_port, VTY_NEWLINE);
|
||||||
|
vty_out(vty, " rtp net-base %u%s", g_cfg->rtp_net_base_port, VTY_NEWLINE);
|
||||||
vty_out(vty, " rtp ip-dscp %d%s", g_cfg->endp_dscp, VTY_NEWLINE);
|
vty_out(vty, " rtp ip-dscp %d%s", g_cfg->endp_dscp, VTY_NEWLINE);
|
||||||
if (g_cfg->audio_payload != -1)
|
if (g_cfg->audio_payload != -1)
|
||||||
vty_out(vty, " sdp audio payload number %d%s", g_cfg->audio_payload, VTY_NEWLINE);
|
vty_out(vty, " sdp audio payload number %d%s", g_cfg->audio_payload, VTY_NEWLINE);
|
||||||
|
@ -163,6 +164,16 @@ DEFUN(cfg_mgcp_rtp_bts_base_port,
|
||||||
return CMD_SUCCESS;
|
return CMD_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
DEFUN(cfg_mgcp_rtp_net_base_port,
|
||||||
|
cfg_mgcp_rtp_net_base_port_cmd,
|
||||||
|
"rtp net-base <0-65534>",
|
||||||
|
"Base port to use for network port\n" "Port\n")
|
||||||
|
{
|
||||||
|
unsigned int port = atoi(argv[0]);
|
||||||
|
g_cfg->rtp_net_base_port = port;
|
||||||
|
return CMD_SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
ALIAS_DEPRECATED(cfg_mgcp_rtp_bts_base_port, cfg_mgcp_rtp_base_port_cmd,
|
ALIAS_DEPRECATED(cfg_mgcp_rtp_bts_base_port, cfg_mgcp_rtp_base_port_cmd,
|
||||||
"rtp base <0-65534>", "Base port to use")
|
"rtp base <0-65534>", "Base port to use")
|
||||||
|
|
||||||
|
@ -277,6 +288,7 @@ int mgcp_vty_init(void)
|
||||||
install_element(MGCP_NODE, &cfg_mgcp_bind_early_cmd);
|
install_element(MGCP_NODE, &cfg_mgcp_bind_early_cmd);
|
||||||
install_element(MGCP_NODE, &cfg_mgcp_rtp_base_port_cmd);
|
install_element(MGCP_NODE, &cfg_mgcp_rtp_base_port_cmd);
|
||||||
install_element(MGCP_NODE, &cfg_mgcp_rtp_bts_base_port_cmd);
|
install_element(MGCP_NODE, &cfg_mgcp_rtp_bts_base_port_cmd);
|
||||||
|
install_element(MGCP_NODE, &cfg_mgcp_rtp_net_base_port_cmd);
|
||||||
install_element(MGCP_NODE, &cfg_mgcp_rtp_ip_dscp_cmd);
|
install_element(MGCP_NODE, &cfg_mgcp_rtp_ip_dscp_cmd);
|
||||||
install_element(MGCP_NODE, &cfg_mgcp_rtp_ip_tos_cmd);
|
install_element(MGCP_NODE, &cfg_mgcp_rtp_ip_tos_cmd);
|
||||||
install_element(MGCP_NODE, &cfg_mgcp_sdp_payload_number_cmd);
|
install_element(MGCP_NODE, &cfg_mgcp_sdp_payload_number_cmd);
|
||||||
|
@ -322,6 +334,12 @@ int mgcp_parse_config(const char *config_file, struct mgcp_config *cfg)
|
||||||
LOGP(DMGCP, LOGL_FATAL, "Failed to bind: %d\n", rtp_port);
|
LOGP(DMGCP, LOGL_FATAL, "Failed to bind: %d\n", rtp_port);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
rtp_port = rtp_calculate_port(ENDPOINT_NUMBER(endp), g_cfg->rtp_net_base_port);
|
||||||
|
if (mgcp_bind_net_rtp_port(endp, rtp_port) != 0) {
|
||||||
|
LOGP(DMGCP, LOGL_FATAL, "Failed to bind: %d\n", rtp_port);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|
Loading…
Reference in New Issue