Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

IPv6 link local support #106

Merged
merged 2 commits into from
Jul 15, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
69 changes: 60 additions & 9 deletions src/sip/transp.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,15 @@
#include <re_http.h>
#include <re_websock.h>
#include <re_sip.h>
#include <re_net.h>
#include "sip.h"


#define DEBUG_MODULE "transp"
#define DEBUG_LEVEL 5
#include <re_dbg.h>


enum {
TCP_ACCEPT_TIMEOUT = 32,
TCP_IDLE_TIMEOUT = 900,
Expand Down Expand Up @@ -145,16 +151,33 @@ static const struct sip_transport *transp_find(struct sip *sip,
int af, const struct sa *dst)
{
struct le *le;
(void)dst;
struct sa dsttmp;

for (le = sip->transpl.head; le; le = le->next) {

const struct sip_transport *transp = le->data;
const struct sa *laddr = &transp->laddr;
struct sa src;

if (transp->tp != tp)
continue;

if (af != AF_UNSPEC && sa_af(&transp->laddr) != af)
if (af != AF_UNSPEC && sa_af(laddr) != af)
continue;

if (!sa_isset(dst, SA_ADDR))
return transp;

if (sa_is_linklocal(laddr) != sa_is_linklocal(dst))
continue;

sa_cpy(&dsttmp, dst);
sa_set_scopeid(&dsttmp, sa_scopeid(laddr));

if (net_dst_source_addr_get(&dsttmp, &src))
continue;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is it so that the route check is only done for link-local ?

if so the baresip PR cannot really be applied, as it assumes that multiple addr
for all address types work.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no, the route check is done for each laddr.


if (!sa_cmp(&src, laddr, SA_ADDR))
continue;

return transp;
Expand Down Expand Up @@ -390,6 +413,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;
sa_set_scopeid(&msg->src, sa_scopeid(&transp->laddr));

sip_recv(transp->sip, msg, 0);

Expand Down Expand Up @@ -1029,6 +1053,25 @@ static int ws_conn_send(struct sip_connqent **qentp, struct sip *sip,
}


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

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

err = sip_transp_laddr(sip, &laddr, tp, dst);
if (err)
return err;

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


int sip_transp_init(struct sip *sip, uint32_t sz)
{
return hash_alloc(&sip->ht_conn, sz);
Expand Down Expand Up @@ -1343,25 +1386,33 @@ int sip_transp_send(struct sip_connqent **qentp, struct sip *sip, void *sock,
const struct sip_transport *transp;
struct sip_conn *conn;
bool secure = false;
struct sa dsttmp;
int err;

if (!sip || !dst || !mb)
return EINVAL;

sa_cpy(&dsttmp, dst);
#if HAVE_INET6
err = dst_set_scopeid(sip, &dsttmp, tp);
if (err)
return err;
#endif

switch (tp) {

case SIP_TRANSP_UDP:
if (!sock) {
transp = transp_find(sip, tp, sa_af(dst), dst);
transp = transp_find(sip, tp, sa_af(&dsttmp), &dsttmp);
if (!transp)
return EPROTONOSUPPORT;

sock = transp->sock;
}

trace_send(sip, tp, sock, dst, mb);
trace_send(sip, tp, sock, &dsttmp, mb);

err = udp_send(sock, dst, mb);
err = udp_send(sock, &dsttmp, mb);
break;

case SIP_TRANSP_TLS:
Expand All @@ -1373,12 +1424,12 @@ int sip_transp_send(struct sip_connqent **qentp, struct sip *sip, void *sock,

if (conn && conn->tc) {

trace_send(sip, tp, conn, dst, mb);
trace_send(sip, tp, conn, &dsttmp, mb);

err = tcp_send(conn->tc, mb);
}
else
err = conn_send(qentp, sip, secure, dst, host, mb,
err = conn_send(qentp, sip, secure, &dsttmp, host, mb,
transph, arg);
break;

Expand All @@ -1390,7 +1441,7 @@ int sip_transp_send(struct sip_connqent **qentp, struct sip *sip, void *sock,
conn = sock;
if (conn && conn->websock_conn) {

trace_send(sip, tp, conn, dst, mb);
trace_send(sip, tp, conn, &dsttmp, mb);

err = websock_send(conn->websock_conn, WEBSOCK_BIN,
"%b",
Expand All @@ -1401,7 +1452,7 @@ int sip_transp_send(struct sip_connqent **qentp, struct sip *sip, void *sock,
}
}
else {
err = ws_conn_send(qentp, sip, secure, dst, mb,
err = ws_conn_send(qentp, sip, secure, &dsttmp, mb,
transph, arg);
if (err) {
re_fprintf(stderr, "ws_conn_send failed"
Expand Down