mgw: Find and store RTP conn local_addr once during CRCX handling

It doesn't make sense to call the function several times since anyway we
are only binding during
allocate_port()->mgcp_bind_net_rtp_port()->bind_rtp()->mgcp_create_bind()->osmo_sock_init2().

Let's better calculate the local IP addr once and use that stored value.
THis is a previous step towards next commit updating the local IP addr
and re-bindng if encessary.

Change-Id: I803b99c5e5fe0f92a5bf6796d8c25df88d1608e6
diff --git a/src/libosmo-mgcp/mgcp_protocol.c b/src/libosmo-mgcp/mgcp_protocol.c
index 1269524..1e7ccbf 100644
--- a/src/libosmo-mgcp/mgcp_protocol.c
+++ b/src/libosmo-mgcp/mgcp_protocol.c
@@ -223,24 +223,22 @@
 					     const char *trans_id,
 					     bool add_conn_params)
 {
-	/* TODO: we may want to define another local_ip_osmux var to us for
-	   OSMUX connections. Perhaps adding a new internal API to get it based
-	   on conn type */
-	const char *addr = endp->cfg->local_ip;
+	/* cfg->local_ip allows overwritting the announced IP address with
+	 * regards to the one we actually bind to. Useful in behind-NAT
+	 * scenarios.
+	 * TODO: we may want to define another local_ip_osmux var to
+	 * us for OSMUX connections. Perhaps adding a new internal API to get it
+	 * based on conn type.
+	 */
+	const char *addr = endp->cfg->local_ip ? : conn->end.local_addr;
 	struct msgb *sdp;
 	int rc;
 	struct msgb *result;
-	char local_ip_addr[INET6_ADDRSTRLEN];
 
 	sdp = msgb_alloc_headroom(4096, 128, "sdp record");
 	if (!sdp)
 		return NULL;
 
-	if (!addr) {
-		mgcp_get_local_addr(local_ip_addr, conn);
-		addr = local_ip_addr;
-	}
-
 	/* Attach optional connection parameters */
 	if (add_conn_params) {
 		rc = add_params(sdp, endp, conn);
@@ -943,6 +941,9 @@
 		goto error2;
 	}
 
+	/* Find a local address for conn based on policy and initial SDP remote
+	   information, then find a free port for it */
+	mgcp_get_local_addr(conn->end.local_addr, conn);
 	if (allocate_port(endp, conn) != 0) {
 		rate_ctr_inc(&rate_ctrs->ctr[MGCP_CRCX_FAIL_BIND_PORT]);
 		goto error2;