From 8f5561d694eef73238b1066765b2eed74d1efa89 Mon Sep 17 00:00:00 2001 From: Martine Lenders Date: Tue, 28 Sep 2021 17:41:41 +0200 Subject: [PATCH] tinydtls: sock_dtls: only use ifindex with link-local addresses For global addresses the out-going interface is typically decided by the forwarding information base, so _requiring_ the user to set it with `sock_dtls` is undesirable. This has the caveat, that now on `sock_udp_send()` in the `_write()` method, the sock does not know via which network interface to send a packet with a global address, but again: this is really more a task for the underlying network stack, not the sock layer. --- pkg/tinydtls/contrib/sock_dtls.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/pkg/tinydtls/contrib/sock_dtls.c b/pkg/tinydtls/contrib/sock_dtls.c index 4b8611c115..2705f0a106 100644 --- a/pkg/tinydtls/contrib/sock_dtls.c +++ b/pkg/tinydtls/contrib/sock_dtls.c @@ -813,7 +813,13 @@ static void _ep_to_session(const sock_udp_ep_t *ep, session_t *session) session->port = ep->port; session->size = sizeof(ipv6_addr_t) + /* addr */ sizeof(unsigned short); /* port */ - session->ifindex = ep->netif; + if (ipv6_addr_is_link_local((ipv6_addr_t *)ep->addr.ipv6)) { + /* set ifindex for link-local addresses */ + session->ifindex = ep->netif; + } + else { + session->ifindex = SOCK_ADDR_ANY_NETIF; + } memcpy(&session->addr, &ep->addr.ipv6, sizeof(ipv6_addr_t)); }