mgcp: Prepare to have different port allocation strategies.
diff --git a/openbsc/include/openbsc/mgcp.h b/openbsc/include/openbsc/mgcp.h
index 9d0c60f..e8d4bb0 100644
--- a/openbsc/include/openbsc/mgcp.h
+++ b/openbsc/include/openbsc/mgcp.h
@@ -80,6 +80,19 @@
 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 @@
 	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 211ec3e..ba0ae8d 100644
--- a/openbsc/src/mgcp/mgcp_protocol.c
+++ b/openbsc/src/mgcp/mgcp_protocol.c
@@ -427,10 +427,10 @@
 	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 @@
 	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 fe73c7a..0ba3511 100644
--- a/openbsc/src/mgcp/mgcp_vty.c
+++ b/openbsc/src/mgcp/mgcp_vty.c
@@ -56,8 +56,11 @@
 		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 @@
       "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 @@
       "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 @@
 		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;