Skip to content

Commit

Permalink
sys/net/gnrc/tcp: fix gnrc_tcp_open() netif handling
Browse files Browse the repository at this point in the history
gnrc_tcp_open() previously would eventually fail with a timeout without
sending any data when no netif was specified and a link-local target
address was used. This fixes the behavior: Since any interface is
equally valid for a link local address, we just pick the first netif
when no netif is specified.

Especially in the case of a single netif (which is pretty common), the
new behavior will match expectations a lot better.

Co-authored-by: benpicco <[email protected]>
  • Loading branch information
maribu and benpicco committed Nov 12, 2024
1 parent e419c14 commit 874311e
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions sys/net/gnrc/transport_layer/tcp/gnrc_tcp.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
#include "net/af.h"
#include "net/tcp.h"
#include "net/gnrc.h"
#include "net/gnrc/netif.h"
#include "net/gnrc/tcp.h"
#include "include/gnrc_tcp_common.h"
#include "include/gnrc_tcp_fsm.h"
Expand Down Expand Up @@ -394,6 +395,20 @@ int gnrc_tcp_open(gnrc_tcp_tcb_t *tcb, const gnrc_tcp_ep_t *remote, uint16_t loc
return -EINVAL;
}
tcb->ll_iface = remote->netif;

/* When the target is a link-local address and no netif is specified,
* any interface is equally valid. We just take whatever the first
* one is. Often there is only a single interface and than the
* behavior is as expected. If there are multiple interfaces, the
* caller really just has to specify the netif anyway. */
if (ipv6_addr_is_link_local((const ipv6_addr_t *)tcb->peer_addr)
&& tcb->ll_iface == SOCK_ADDR_ANY_NETIF) {
const gnrc_netif_t *netif = gnrc_netif_iter(NULL);
if (!netif) {
return -EINVAL;
}
tcb->ll_iface = netif->pid;
}
}
#endif

Expand Down

0 comments on commit 874311e

Please sign in to comment.