From 31939dce747cd2ebfef9397f3af5c93e1accde1f Mon Sep 17 00:00:00 2001 From: Nils Jeisecke Date: Mon, 18 May 2020 17:02:14 +0200 Subject: [PATCH] handle rport 'received' ip address in SDP This needs commit 2654229cd9f05f8610b5789443caefc227fa0d9e (Use 'rport' and 'received' parameters to adjust 'Contact' header according to RFC 3581) in libre. --- include/baresip.h | 1 + src/call.c | 13 +++++++++++-- src/core.h | 2 ++ src/reg.c | 6 +++++- src/ua.c | 17 +++++++++++++++++ 5 files changed, 36 insertions(+), 3 deletions(-) diff --git a/include/baresip.h b/include/baresip.h index fa56e6948..72cd555a6 100644 --- a/include/baresip.h +++ b/include/baresip.h @@ -939,6 +939,7 @@ unsigned ua_destroy(struct ua *ua); void ua_pub_gruu_set(struct ua *ua, const struct pl *pval); const char *ua_cuser(const struct ua *ua); const char *ua_local_cuser(const struct ua *ua); +const struct sa *ua_raddr(const struct ua *ua); struct account *ua_account(const struct ua *ua); const char *ua_outbound(const struct ua *ua); struct call *ua_call(const struct ua *ua); diff --git a/src/call.c b/src/call.c index df99989a3..4893cdf00 100644 --- a/src/call.c +++ b/src/call.c @@ -827,6 +827,7 @@ int call_alloc(struct call **callp, const struct config *cfg, struct list *lst, struct call *call; enum vidmode vidmode = prm ? prm->vidmode : VIDMODE_OFF; int err = 0; + const struct sa *raddr; if (!cfg || !local_uri || !acc || !ua || !prm) return EINVAL; @@ -873,8 +874,13 @@ int call_alloc(struct call **callp, const struct config *cfg, struct list *lst, if (sip_msg_hdr_has_value(msg, SIP_HDR_SUPPORTED, "replaces")) call->supported |= REPLACES; + /* if rport/received was set, use this. This is not 100% correct because + * only the ip address ("received") will be used but not the port (which + * would be the SIP port and not the RTP port anyway). */ + raddr = ua_raddr(ua); + /* Init SDP info */ - err = sdp_session_alloc(&call->sdp, &prm->laddr); + err = sdp_session_alloc(&call->sdp, sa_isset(raddr, SA_ADDR | SA_PORT) ? raddr : &prm->laddr); if (err) goto out; @@ -2230,7 +2236,9 @@ int call_accept(struct call *call, struct sipsess_sock *sess_sock, err = sipsess_accept(&call->sess, sess_sock, msg, 180, "Ringing", account_rel100_mode(call->acc), - ua_cuser(call->ua), "application/sdp", NULL, + ua_cuser(call->ua), + ua_raddr(call->ua), + "application/sdp", NULL, auth_handler, call->acc, true, sipsess_offer_handler, sipsess_answer_handler, sipsess_estab_handler, sipsess_info_handler, @@ -2417,6 +2425,7 @@ static int send_invite(struct call *call) call->local_name, call->local_uri, ua_cuser(call->ua), + ua_raddr(call->ua), routev[0] ? routev : NULL, routev[0] ? 1 : 0, "application/sdp", diff --git a/src/core.h b/src/core.h index 6f285e3ef..d4f1f41d8 100644 --- a/src/core.h +++ b/src/core.h @@ -246,6 +246,8 @@ const struct sa *reg_laddr(const struct reg *reg); const struct sa *reg_paddr(const struct reg *reg); void reg_set_custom_hdrs(struct reg *reg, const struct list *hdrs); +const struct sa *reg_raddr(const struct reg *reg); + /* * RTP Stats */ diff --git a/src/reg.c b/src/reg.c index 0b8784d08..c69fe5a37 100644 --- a/src/reg.c +++ b/src/reg.c @@ -426,8 +426,12 @@ const struct sa *reg_laddr(const struct reg *reg) return sipreg_laddr(reg->sipreg); } - const struct sa *reg_paddr(const struct reg *reg) { return reg ? ®->paddr : NULL; } + +const struct sa *reg_raddr(const struct reg *reg) +{ + return sipreg_raddr(reg->sipreg); +} diff --git a/src/ua.c b/src/ua.c index 3b047a0f6..8aacacaa2 100644 --- a/src/ua.c +++ b/src/ua.c @@ -1860,6 +1860,23 @@ const char *ua_cuser(const struct ua *ua) return ua->cuser; } +const struct sa *ua_raddr(const struct ua *ua) +{ + struct le *le; + int i; + + if (!ua) + return NULL; + + for (le = ua->regl.head, i=0; le; le = le->next, i++) { + struct reg *reg = le->data; + const struct sa *raddr = reg_raddr(reg); + if (raddr) + return raddr; + } + + return NULL; +} /** * Get the local contact username