Skip to content

Commit

Permalink
sip: set TCP src port at laddr in all Via and Contact headers
Browse files Browse the repository at this point in the history
  • Loading branch information
cspiel1 committed Apr 27, 2022
1 parent 28eef04 commit b83e16c
Show file tree
Hide file tree
Showing 9 changed files with 15 additions and 16 deletions.
2 changes: 1 addition & 1 deletion include/re_sip.h
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ struct sip_keepalive;
struct dnsc;

typedef bool(sip_msg_h)(const struct sip_msg *msg, void *arg);
typedef int(sip_send_h)(enum sip_transp tp, const struct sa *src,
typedef int(sip_send_h)(enum sip_transp tp, struct sa *src,
const struct sa *dst, struct mbuf *mb,
struct mbuf **contp, void *arg);
typedef void(sip_resp_h)(int err, const struct sip_msg *msg, void *arg);
Expand Down
7 changes: 0 additions & 7 deletions src/sip/request.c
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,6 @@ static int request(struct sip_request *req, enum sip_transp tp,
char *branch = NULL;
int err = ENOMEM;
struct sa laddr;
struct sip_conncfg *conncfg;

req->provrecv = false;

Expand All @@ -190,12 +189,6 @@ static int request(struct sip_request *req, enum sip_transp tp,
goto out;

mbuf_set_pos(mbs, 0);
if (tp==SIP_TRANSP_TCP || tp==SIP_TRANSP_TLS) {
conncfg = sip_conncfg_find(req->sip, dst);
if (conncfg && conncfg->srcport)
sa_set_port(&laddr, conncfg->srcport);
}

err = mbuf_printf(mb, "%s %s SIP/2.0\r\n", req->met, req->uri);
err |= mbuf_printf(mb, "Via: SIP/2.0/%s %J;branch=%s;rport\r\n",
sip_transp_name(tp), &laddr, branch);
Expand Down
6 changes: 6 additions & 0 deletions src/sip/transp.c
Original file line number Diff line number Diff line change
Expand Up @@ -1506,6 +1506,7 @@ int sip_transp_laddr(struct sip *sip, struct sa *laddr, enum sip_transp tp,
const struct sa *dst)
{
const struct sip_transport *transp;
struct sip_conncfg *conncfg;

if (!sip || !laddr)
return EINVAL;
Expand All @@ -1515,6 +1516,11 @@ int sip_transp_laddr(struct sip *sip, struct sa *laddr, enum sip_transp tp,
return EPROTONOSUPPORT;

*laddr = transp->laddr;
if (tp != SIP_TRANSP_UDP) {
conncfg = sip_conncfg_find(sip, dst);
if (conncfg && conncfg->srcport)
sa_set_port(laddr, conncfg->srcport);
}

return 0;
}
Expand Down
2 changes: 1 addition & 1 deletion src/sipevent/notify.c
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ static void response_handler(int err, const struct sip_msg *msg, void *arg)
}


static int send_handler(enum sip_transp tp, const struct sa *src,
static int send_handler(enum sip_transp tp, struct sa *src,
const struct sa *dst, struct mbuf *mb,
struct mbuf **contp, void *arg)
{
Expand Down
2 changes: 1 addition & 1 deletion src/sipevent/subscribe.c
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,7 @@ static void response_handler(int err, const struct sip_msg *msg, void *arg)
}


static int send_handler(enum sip_transp tp, const struct sa *src,
static int send_handler(enum sip_transp tp, struct sa *src,
const struct sa *dst, struct mbuf *mb,
struct mbuf **contp, void *arg)
{
Expand Down
6 changes: 3 additions & 3 deletions src/sipreg/reg.c
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ static void response_handler(int err, const struct sip_msg *msg, void *arg)
}


static int send_handler(enum sip_transp tp, const struct sa *src,
static int send_handler(enum sip_transp tp, struct sa *src,
const struct sa *dst, struct mbuf *mb,
struct mbuf **contp, void *arg)
{
Expand All @@ -276,11 +276,11 @@ static int send_handler(enum sip_transp tp, const struct sa *src,
(void)dst;
(void)contp;

reg->laddr = *src;
reg->tp = tp;
if (reg->srcport && tp != SIP_TRANSP_UDP)
sa_set_port(&reg->laddr, reg->srcport);
sa_set_port(src, reg->srcport);

reg->laddr = *src;
err = mbuf_printf(mb, "Contact: <sip:%s@%J%s>;expires=%u%s%s",
reg->cuser, &reg->laddr, sip_transp_param(reg->tp),
reg->expires,
Expand Down
2 changes: 1 addition & 1 deletion src/sipsess/ack.c
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ static void tmr_handler(void *arg)
}


static int send_handler(enum sip_transp tp, const struct sa *src,
static int send_handler(enum sip_transp tp, struct sa *src,
const struct sa *dst, struct mbuf *mb,
struct mbuf **contp, void *arg)
{
Expand Down
2 changes: 1 addition & 1 deletion src/sipsess/connect.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
static int invite(struct sipsess *sess);


static int send_handler(enum sip_transp tp, const struct sa *src,
static int send_handler(enum sip_transp tp, struct sa *src,
const struct sa *dst, struct mbuf *mb,
struct mbuf **contp, void *arg)
{
Expand Down
2 changes: 1 addition & 1 deletion src/sipsess/modify.c
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ static void reinvite_resp_handler(int err, const struct sip_msg *msg,
}


static int send_handler(enum sip_transp tp, const struct sa *src,
static int send_handler(enum sip_transp tp, struct sa *src,
const struct sa *dst, struct mbuf *mb,
struct mbuf **contp, void *arg)
{
Expand Down

0 comments on commit b83e16c

Please sign in to comment.