From aea47a86785590a89ce76d5bbd2c03b814a02437 Mon Sep 17 00:00:00 2001 From: Christian Spielberger Date: Mon, 7 Jun 2021 11:58:57 +0200 Subject: [PATCH] net,sip: check if destination is reachable when selecting transport --- src/sip/transp.c | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/src/sip/transp.c b/src/sip/transp.c index c134ea423..275caefb3 100644 --- a/src/sip/transp.c +++ b/src/sip/transp.c @@ -23,6 +23,7 @@ #include #include #include +#include #include "sip.h" @@ -150,19 +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; - if (sa_is_linklocal(&transp->laddr) != sa_is_linklocal(dst)) + if (!sa_cmp(&src, laddr, SA_ADDR)) continue; return transp;