aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHolger Hans Peter Freyther <zecke@selfish.org>2010-08-05 07:10:56 +0800
committerHolger Hans Peter Freyther <zecke@selfish.org>2010-08-05 07:10:56 +0800
commit15e7389cf06af3e83d4a5d232d9409fc02002cd0 (patch)
tree8e357703e73b5afc511a413fdbb9f654d36b444a
parenta3b46c9ac06adbd16fb0d9a6ae1e31395adca85a (diff)
mgcp: Prepare to have different port allocation strategies.
-rw-r--r--openbsc/include/openbsc/mgcp.h18
-rw-r--r--openbsc/src/mgcp/mgcp_protocol.c9
-rw-r--r--openbsc/src/mgcp/mgcp_vty.c19
3 files changed, 34 insertions, 12 deletions
diff --git a/openbsc/include/openbsc/mgcp.h b/openbsc/include/openbsc/mgcp.h
index 9d0c60f33..e8d4bb02d 100644
--- a/openbsc/include/openbsc/mgcp.h
+++ b/openbsc/include/openbsc/mgcp.h
@@ -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 */
diff --git a/openbsc/src/mgcp/mgcp_protocol.c b/openbsc/src/mgcp/mgcp_protocol.c
index 211ec3ea8..ba0ae8d8e 100644
--- a/openbsc/src/mgcp/mgcp_protocol.c
+++ b/openbsc/src/mgcp/mgcp_protocol.c
@@ -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;
}
diff --git a/openbsc/src/mgcp/mgcp_vty.c b/openbsc/src/mgcp/mgcp_vty.c
index fe73c7acf..0ba3511be 100644
--- a/openbsc/src/mgcp/mgcp_vty.c
+++ b/openbsc/src/mgcp/mgcp_vty.c
@@ -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;