network: autdetect rtp bind ip-address

Currently there are two ways to set the rtp bind ip-address (local
ip address where the rtp streams are bound to). It is possible to
set no set an rtp bind ip, if none no address is configured, then
the ip address where the mgcp service is bound to is used.

On a system with multiple network interfaces it is likely that
there are the remote end is not reachable through the interface
that has been configured. In this case rtp ip-probing can be
enabled via vty option in order to automatically detect the
ip address of the interface that points towards the remote end.

The autodetection can only work if the ip-address is known when
a CRCX is performed. For this the remote entity must include the
remote ip address in the sdp trailer.

Implement probing to determine te right local ip address
Add debug log to display which ip address is actually used
Add a VTY option for the probing functionality.

Change-Id: Ia57cf7dab8421fd3ab6e1515727db0080373485e
diff --git a/src/libosmo-mgcp/mgcp_protocol.c b/src/libosmo-mgcp/mgcp_protocol.c
index 4826790..8c6bd6e 100644
--- a/src/libosmo-mgcp/mgcp_protocol.c
+++ b/src/libosmo-mgcp/mgcp_protocol.c
@@ -203,13 +203,16 @@
 	int rc;
 	struct msgb *result;
 	char osmux_extension[strlen("\nX-Osmux: 255") + 1];
+	char local_ip_addr[INET_ADDRSTRLEN];
 
 	sdp = msgb_alloc_headroom(4096, 128, "sdp record");
 	if (!sdp)
 		return NULL;
 
-	if (!addr)
-		addr = mgcp_net_src_addr(endp);
+	if (!addr) {
+		mgcp_get_local_addr(local_ip_addr, conn);
+		addr = local_ip_addr;
+	}
 
 	if (conn->osmux.state == OSMUX_STATE_NEGOTIATING) {
 		sprintf(osmux_extension, "\nX-Osmux: %u", conn->osmux.cid);
@@ -597,12 +600,6 @@
 		goto error2;
 	}
 
-	mgcp_rtp_end_config(endp, 0, &conn->end);
-
-	if (allocate_port(endp, conn) != 0) {
-		goto error2;
-	}
-
 	/* Annotate Osmux circuit ID and set it to negotiating state until this
 	 * is fully set up from the dummy load. */
 	conn->osmux.state = OSMUX_STATE_DISABLED;
@@ -630,6 +627,12 @@
 		conn->end.force_output_ptime = 1;
 	}
 
+	mgcp_rtp_end_config(endp, 0, &conn->end);
+
+	if (allocate_port(endp, conn) != 0) {
+		goto error2;
+	}
+
 	if (setup_rtp_processing(endp, conn) != 0) {
 		LOGP(DLMGCP, LOGL_ERROR,
 		     "CRCX: endpoint:%x could not start RTP processing!\n",