mgcp: Prepare to have different port allocation strategies.
This commit is contained in:
parent
a3b46c9ac0
commit
15e7389cf0
|
@ -80,6 +80,19 @@ typedef int (*mgcp_change)(struct mgcp_config *cfg, int endpoint, int state);
|
|||
typedef int (*mgcp_policy)(struct mgcp_config *cfg, int endpoint, int state, const char *transactio_id);
|
||||
typedef int (*mgcp_reset)(struct mgcp_config *cfg);
|
||||
|
||||
#define PORT_ALLOC_STATIC 0
|
||||
#define PORT_ALLOC_DYNAMIC 1
|
||||
|
||||
/**
|
||||
* This holds information on how to allocate ports
|
||||
*/
|
||||
struct mgcp_port_range {
|
||||
int mode;
|
||||
|
||||
/* pre-allocated from a base? */
|
||||
int base_port;
|
||||
};
|
||||
|
||||
struct mgcp_config {
|
||||
int source_port;
|
||||
char *local_ip;
|
||||
|
@ -92,8 +105,9 @@ struct mgcp_config {
|
|||
char *audio_name;
|
||||
int audio_payload;
|
||||
int audio_loop;
|
||||
int rtp_bts_base_port;
|
||||
int rtp_net_base_port;
|
||||
|
||||
struct mgcp_port_range bts_ports;
|
||||
struct mgcp_port_range net_ports;
|
||||
int endp_dscp;
|
||||
|
||||
/* spec handling */
|
||||
|
|
|
@ -427,10 +427,10 @@ static struct msgb *handle_create_con(struct mgcp_config *cfg, struct msgb *msg)
|
|||
memset(&endp->net_end.addr, 0, sizeof(endp->net_end.addr));
|
||||
|
||||
/* 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->bts_ports.base_port);
|
||||
endp->bts_end.local_port = port;
|
||||
|
||||
port = rtp_calculate_port(ENDPOINT_NUMBER(endp), cfg->rtp_net_base_port);
|
||||
port = rtp_calculate_port(ENDPOINT_NUMBER(endp), cfg->net_ports.base_port);
|
||||
endp->net_end.local_port = port;
|
||||
|
||||
/* assign a local call identifier or fail */
|
||||
|
@ -710,8 +710,9 @@ struct mgcp_config *mgcp_config_alloc(void)
|
|||
cfg->source_addr = talloc_strdup(cfg, "0.0.0.0");
|
||||
cfg->audio_name = talloc_strdup(cfg, "GSM-EFR/8000");
|
||||
cfg->audio_payload = 97;
|
||||
cfg->rtp_bts_base_port = RTP_PORT_DEFAULT;
|
||||
cfg->rtp_net_base_port = RTP_PORT_NET_DEFAULT;
|
||||
|
||||
cfg->bts_ports.base_port = RTP_PORT_DEFAULT;
|
||||
cfg->net_ports.base_port = RTP_PORT_NET_DEFAULT;
|
||||
|
||||
return cfg;
|
||||
}
|
||||
|
|
|
@ -56,8 +56,11 @@ static int config_write_mgcp(struct vty *vty)
|
|||
vty_out(vty, " bts ip %s%s", g_cfg->bts_ip, 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, " 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);
|
||||
|
||||
if (g_cfg->bts_ports.mode == PORT_ALLOC_STATIC)
|
||||
vty_out(vty, " rtp bts-base %u%s", g_cfg->bts_ports.base_port, VTY_NEWLINE);
|
||||
if (g_cfg->net_ports.mode == PORT_ALLOC_STATIC)
|
||||
vty_out(vty, " rtp net-base %u%s", g_cfg->net_ports.base_port, VTY_NEWLINE);
|
||||
vty_out(vty, " rtp ip-dscp %d%s", g_cfg->endp_dscp, VTY_NEWLINE);
|
||||
if (g_cfg->audio_payload != -1)
|
||||
vty_out(vty, " sdp audio payload number %d%s", g_cfg->audio_payload, VTY_NEWLINE);
|
||||
|
@ -160,7 +163,8 @@ DEFUN(cfg_mgcp_rtp_bts_base_port,
|
|||
"Base port to use")
|
||||
{
|
||||
unsigned int port = atoi(argv[0]);
|
||||
g_cfg->rtp_bts_base_port = port;
|
||||
g_cfg->bts_ports.mode = PORT_ALLOC_STATIC;
|
||||
g_cfg->bts_ports.base_port = port;
|
||||
return CMD_SUCCESS;
|
||||
}
|
||||
|
||||
|
@ -170,7 +174,8 @@ DEFUN(cfg_mgcp_rtp_net_base_port,
|
|||
"Base port to use for network port\n" "Port\n")
|
||||
{
|
||||
unsigned int port = atoi(argv[0]);
|
||||
g_cfg->rtp_net_base_port = port;
|
||||
g_cfg->net_ports.mode = PORT_ALLOC_STATIC;
|
||||
g_cfg->net_ports.base_port = port;
|
||||
return CMD_SUCCESS;
|
||||
}
|
||||
|
||||
|
@ -329,13 +334,15 @@ int mgcp_parse_config(const char *config_file, struct mgcp_config *cfg)
|
|||
struct mgcp_endpoint *endp = &g_cfg->endpoints[i];
|
||||
int rtp_port;
|
||||
|
||||
rtp_port = rtp_calculate_port(ENDPOINT_NUMBER(endp), g_cfg->rtp_bts_base_port);
|
||||
rtp_port = rtp_calculate_port(ENDPOINT_NUMBER(endp),
|
||||
g_cfg->bts_ports.base_port);
|
||||
if (mgcp_bind_bts_rtp_port(endp, rtp_port) != 0) {
|
||||
LOGP(DMGCP, LOGL_FATAL, "Failed to bind: %d\n", rtp_port);
|
||||
return -1;
|
||||
}
|
||||
|
||||
rtp_port = rtp_calculate_port(ENDPOINT_NUMBER(endp), g_cfg->rtp_net_base_port);
|
||||
rtp_port = rtp_calculate_port(ENDPOINT_NUMBER(endp),
|
||||
g_cfg->net_ports.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;
|
||||
|
|
Loading…
Reference in New Issue