Skip to content

Commit 82a29b7

Browse files
committed
Merge branch 'fix/lwip_drop_ipv6_if_no_ll' into 'master'
fix(lwip): Add default IPv6 input filter to drop traffic if ipv6 not assigned Closes IDF-10472 See merge request espressif/esp-idf!32165
2 parents 0c9d7c9 + 98fdb1a commit 82a29b7

File tree

2 files changed

+25
-7
lines changed

2 files changed

+25
-7
lines changed

components/lwip/Kconfig

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1355,11 +1355,15 @@ menu "LWIP"
13551355
choice LWIP_HOOK_IP6_INPUT
13561356
prompt "IPv6 packet input"
13571357
depends on LWIP_IPV6
1358-
default LWIP_HOOK_IP6_INPUT_NONE
1358+
default LWIP_HOOK_IP6_INPUT_DEFAULT
13591359
help
13601360
Enables custom IPv6 packet input.
1361-
Setting this to "default" provides weak implementation
1362-
stub that could be overwritten in application code.
1361+
Setting this to "default" provides weak IDF implementation,
1362+
which drops all incoming IPv6 traffic if the interface has no link local address.
1363+
(this default implementation is "weak" and could be still overwritten
1364+
in the application if some additional IPv6 input packet filtering is needed)
1365+
Setting this to "none" removes this default filter and conforms to the lwIP
1366+
implementation (which accepts multicasts even if the interface has no link local address)
13631367
Setting this to "custom" provides hook's declaration
13641368
only and expects the application to implement it.
13651369

components/lwip/port/hooks/lwip_default_hooks.c

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* SPDX-FileCopyrightText: 2020-2022 Espressif Systems (Shanghai) CO LTD
2+
* SPDX-FileCopyrightText: 2020-2024 Espressif Systems (Shanghai) CO LTD
33
*
44
* SPDX-License-Identifier: Apache-2.0
55
*/
@@ -56,11 +56,25 @@ const ip_addr_t *__weak lwip_hook_ip6_select_source_address(struct netif *netif,
5656
#endif
5757

5858
#ifdef CONFIG_LWIP_HOOK_IP6_INPUT_DEFAULT
59+
/**
60+
* @brief The default IPv6 input hook checks if we already have an IPv6 address (netif->ip6_addr[0] is link local),
61+
* so we drop all incoming IPv6 packets if the input netif has no LL address.
62+
*
63+
* LWIP accepts IPv6 multicast packets even if the ip6_addr[] for the given address wasn't set,
64+
* this may cause trouble if we enable IPv6 SLAAC (LWIP_IPV6_AUTOCONFIG), but have not created any LL address.
65+
* If the router sends a packet to all nodes 0xff01::1 with RDNSS servers, it would be accepted and rewrite
66+
* DNS server info with IPv6 values (which won't be routable without any IPv6 address assigned)
67+
*/
5968
int __weak lwip_hook_ip6_input(struct pbuf *p, struct netif *inp)
6069
{
61-
LWIP_UNUSED_ARG(p);
62-
LWIP_UNUSED_ARG(inp);
63-
70+
/* Check if the first IPv6 address (link-local) is unassigned (all zeros).
71+
* If the address is empty, it indicates that no link-local address has been configured,
72+
* and the interface should not accept incoming IPv6 traffic. */
73+
if (ip6_addr_isany(ip_2_ip6(&inp->ip6_addr[0]))) {
74+
/* We don't have an LL address -> eat this packet here, so it won't get accepted on the input netif */
75+
pbuf_free(p);
76+
return 1;
77+
}
6478
return 0;
6579
}
6680
#endif

0 commit comments

Comments
 (0)