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
This commit is contained in:
Pau Espin 2020-09-03 14:20:07 +02:00
parent 8a2a1b22fe
commit 71d42e778a
3 changed files with 15 additions and 14 deletions

View File

@ -118,6 +118,9 @@ struct mgcp_rtp_end {
/* local UDP port number of the RTP socket; RTCP is +1 */
int local_port;
/* where the endpoint RTP connection binds to, set during CRCX and
* possibly updated during MDCX */
char local_addr[INET6_ADDRSTRLEN];
};
struct mgcp_rtp_tap {

View File

@ -1620,7 +1620,6 @@ int mgcp_bind_net_rtp_port(struct mgcp_endpoint *endp, int rtp_port,
{
char name[512];
struct mgcp_rtp_end *end;
char local_ip_addr[INET6_ADDRSTRLEN];
snprintf(name, sizeof(name), "%s-%s", conn->conn->name, conn->conn->id);
end = &conn->end;
@ -1643,9 +1642,7 @@ int mgcp_bind_net_rtp_port(struct mgcp_endpoint *endp, int rtp_port,
end->rtcp.data = conn;
end->rtcp.cb = rtp_data_net;
mgcp_get_local_addr(local_ip_addr, conn);
return bind_rtp(endp->cfg, local_ip_addr, end, endp);
return bind_rtp(endp->cfg, conn->end.local_addr, end, endp);
}
/*! free allocated RTP and RTCP ports.

View File

@ -223,24 +223,22 @@ static struct msgb *create_response_with_sdp(struct mgcp_endpoint *endp,
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 @@ mgcp_header_done:
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;