Skip to content

Commit

Permalink
handle rport 'received' ip address in SDP
Browse files Browse the repository at this point in the history
This needs commit 2654229cd9f05f8610b5789443caefc227fa0d9e (Use 'rport'
and 'received' parameters to adjust 'Contact' header according to RFC
3581) in libre.
  • Loading branch information
Nils Jeisecke committed Oct 28, 2024
1 parent cba1998 commit 31939dc
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 3 deletions.
1 change: 1 addition & 0 deletions include/baresip.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
13 changes: 11 additions & 2 deletions src/call.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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",
Expand Down
2 changes: 2 additions & 0 deletions src/core.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down
6 changes: 5 additions & 1 deletion src/reg.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 ? &reg->paddr : NULL;
}

const struct sa *reg_raddr(const struct reg *reg)
{
return sipreg_raddr(reg->sipreg);
}
17 changes: 17 additions & 0 deletions src/ua.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 31939dc

Please sign in to comment.