Skip to content

Commit

Permalink
sa,sip: remove sa_is_ipv6ll(); use HAVE_INET6 correctly
Browse files Browse the repository at this point in the history
  • Loading branch information
cspiel1 committed Jun 14, 2021
1 parent 9807205 commit b72938a
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 16 deletions.
20 changes: 13 additions & 7 deletions src/sip/reply.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,13 @@
#include <re_dbg.h>


#if HAVE_INET6
static int dst_set_scopeid(struct sa *dst, struct sip *sip, enum sip_transp tp)
{
struct sa laddr;
int err;

if (!sa_is_ipv6ll(dst))
if (sa_af(dst) != AF_INET6 || !sa_is_linklocal(dst))
return 0;

err = sip_transp_laddr(sip, &laddr, tp, dst);
Expand All @@ -35,14 +36,15 @@ static int dst_set_scopeid(struct sa *dst, struct sip *sip, enum sip_transp tp)
return err;
}

err = sa_cpy_scopeid(dst, &laddr);
if (err) {
DEBUG_WARNING("could not copy scope id from %j to %j\n",
&laddr, dst);
if (sa_af(&laddr) != AF_INET6 || !sa_is_linklocal(&laddr)) {
DEBUG_WARNING("laddr %j is not IPv6 link local\n", &laddr);
return EINVAL;
}

return err;
sa_set_scopeid(dst, sa_scopeid(&laddr));
return 0;
}
#endif


static int vreplyf(struct sip_strans **stp, struct mbuf **mbp, bool trans,
Expand Down Expand Up @@ -143,7 +145,11 @@ static int vreplyf(struct sip_strans **stp, struct mbuf **mbp, bool trans,
mb->pos = 0;

sip_reply_addr(&dst, msg, rport);
dst_set_scopeid(&dst, sip, msg->tp);
#if HAVE_INET6
err = dst_set_scopeid(&dst, sip, msg->tp);
if (err)
goto out;
#endif

if (trans) {
err = sip_strans_reply(stp, sip, msg, &dst, scode, mb);
Expand Down
14 changes: 9 additions & 5 deletions src/sip/request.c
Original file line number Diff line number Diff line change
Expand Up @@ -211,12 +211,13 @@ static int request(struct sip_request *req, enum sip_transp tp,
}


#if HAVE_INET6
static int dst_set_scopeid(struct sa *dst, struct sip_request *req)
{
struct sa laddr;
int err;

if (!sa_is_ipv6ll(dst))
if (sa_af(dst) != AF_INET6 || !sa_is_linklocal(dst))
return 0;

err = sip_transp_laddr(req->sip, &laddr, req->tp, dst);
Expand All @@ -225,14 +226,15 @@ static int dst_set_scopeid(struct sa *dst, struct sip_request *req)
return err;
}

err = sa_cpy_scopeid(dst, &laddr);
if (err) {
DEBUG_WARNING("could not copy scope id from %j to %j\n",
&laddr, dst);
if (sa_af(&laddr) != AF_INET6 || !sa_is_linklocal(&laddr)) {
DEBUG_WARNING("laddr %j is not IPv6 link local\n", &laddr);
return EINVAL;
}

sa_set_scopeid(dst, sa_scopeid(&laddr));
return err;
}
#endif


static int request_next(struct sip_request *req)
Expand Down Expand Up @@ -699,9 +701,11 @@ int sip_request(struct sip_request **reqp, struct sip *sip, bool stateful,
if (!sa_set_str(&dst, req->host,
sip_transp_port(req->tp, route->port))) {

#if HAVE_INET6
err = dst_set_scopeid(&dst, req);
if (err)
goto out;
#endif

err = request(req, req->tp, &dst);
if (!req->stateful) {
Expand Down
6 changes: 2 additions & 4 deletions src/sip/transp.c
Original file line number Diff line number Diff line change
Expand Up @@ -171,8 +171,7 @@ static const struct sip_transport *transp_find(struct sip *sip,
continue;

sa_cpy(&dsttmp, dst);
if (sa_is_ipv6ll(dst))
sa_cpy_scopeid(&dsttmp, src);
sa_set_scopeid(&dsttmp, sa_scopeid(src));

if (net_dst_is_source_addr(&dsttmp, src))
continue;
Expand Down Expand Up @@ -391,8 +390,7 @@ static void udp_recv_handler(const struct sa *src, struct mbuf *mb, void *arg)
msg->src = *src;
msg->dst = transp->laddr;
msg->tp = SIP_TRANSP_UDP;
if (sa_is_ipv6ll(&msg->src))
err = sa_cpy_scopeid(&msg->src, &transp->laddr);
sa_set_scopeid(&msg->src, sa_scopeid(&transp->laddr));

if (err) {
DEBUG_WARNING("could not copy IPv6 scope id from %j to %j\n",
Expand Down

0 comments on commit b72938a

Please sign in to comment.