Skip to content

Commit

Permalink
nd6: Add support to enable/disable ND6 protocol
Browse files Browse the repository at this point in the history
2.1.3-esp: 7896c6c lwip: add LWIP ND6 config
  • Loading branch information
xiaqilin authored and david-cermak committed Sep 11, 2024
1 parent a5b1295 commit 0a1828f
Show file tree
Hide file tree
Showing 13 changed files with 51 additions and 14 deletions.
1 change: 1 addition & 0 deletions doc/doxygen/lwip.Doxyfile
Original file line number Diff line number Diff line change
Expand Up @@ -2085,6 +2085,7 @@ PREDEFINED = __DOXYGEN__=1 \
LWIP_TCPIP_CORE_LOCKING=1 \
LWIP_IPV4=1 \
LWIP_IPV6=1 \
LWIP_ND6=1 \
LWIP_ICMP=1 \
LWIP_RAW=1 \
LWIP_DHCP=1 \
Expand Down
1 change: 1 addition & 0 deletions doc/doxygen/lwip.Doxyfile.cmake.in
Original file line number Diff line number Diff line change
Expand Up @@ -2085,6 +2085,7 @@ PREDEFINED = __DOXYGEN__=1 \
LWIP_TCPIP_CORE_LOCKING=1 \
LWIP_IPV4=1 \
LWIP_IPV6=1 \
LWIP_ND6=1 \
LWIP_ICMP=1 \
LWIP_RAW=1 \
LWIP_DHCP=1 \
Expand Down
2 changes: 2 additions & 0 deletions src/core/ipv6/icmp6.c
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,9 @@ icmp6_input(struct pbuf *p, struct netif *inp)
case ICMP6_TYPE_RA: /* Router advertisement */
case ICMP6_TYPE_RD: /* Redirect */
case ICMP6_TYPE_PTB: /* Packet too big */
#if LWIP_ND6
nd6_input(p, inp);
#endif /* LWIP_ND6 */
return;
case ICMP6_TYPE_RS:
#if LWIP_IPV6_FORWARD
Expand Down
6 changes: 6 additions & 0 deletions src/core/ipv6/ip6.c
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,9 @@ ip6_route(const ip6_addr_t *src, const ip6_addr_t *dest)
}

/* Get the netif for a suitable router-announced route. */
#if LWIP_ND6
netif = nd6_find_route(dest);
#endif /* LWIP_ND6 */
if (netif != NULL) {
return netif;
}
Expand Down Expand Up @@ -1266,7 +1268,11 @@ ip6_output_if_src(struct pbuf *p, const ip6_addr_t *src, const ip6_addr_t *dest,
#endif /* ENABLE_LOOPBACK */
#if LWIP_IPV6_FRAG
/* don't fragment if interface has mtu set to 0 [loopif] */
#if LWIP_ND6
if (netif_mtu6(netif) && (p->tot_len > nd6_get_destination_mtu(dest, netif))) {
#else
if (netif_mtu6(netif) && (p->tot_len > IP6_MIN_MTU_LENGTH)) {
#endif /* LWIP_ND6 */
return ip6_frag(p, netif, dest);
}
#else
Expand Down
4 changes: 4 additions & 0 deletions src/core/ipv6/ip6_frag.c
Original file line number Diff line number Diff line change
Expand Up @@ -765,7 +765,11 @@ ip6_frag(struct pbuf *p, struct netif *netif, const ip6_addr_t *dest)
#endif
static u32_t identification;
u16_t left, cop;
#if LWIP_ND6
const u16_t mtu = nd6_get_destination_mtu(dest, netif);
#else
const u16_t mtu = IP6_MIN_MTU_LENGTH;
#endif /* LWIP_ND6 */
const u16_t nfb = (u16_t)((mtu - (IP6_HLEN + IP6_FRAG_HLEN)) & IP6_FRAG_OFFSET_MASK);
u16_t fragment_offset = 0;
u16_t last;
Expand Down
4 changes: 2 additions & 2 deletions src/core/ipv6/nd6.c
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@

#include "lwip/opt.h"

#if LWIP_IPV6 /* don't build if not configured for use in lwipopts.h */
#if LWIP_IPV6 && LWIP_ND6 /* don't build if not configured for use in lwipopts.h */

#include "lwip/nd6.h"
#include "lwip/priv/nd6_priv.h"
Expand Down Expand Up @@ -2490,4 +2490,4 @@ nd6_restart_netif(struct netif *netif)
#endif /* LWIP_IPV6_SEND_ROUTER_SOLICIT */
}

#endif /* LWIP_IPV6 */
#endif /* LWIP_IPV6 && LWIP_ND6 */
18 changes: 10 additions & 8 deletions src/core/netif.c
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,9 @@ netif_add(struct netif *netif,
/* IPv6 address autoconfiguration should be enabled by default */
netif->ip6_autoconfig_enabled = 1;
#endif /* LWIP_IPV6_AUTOCONFIG */
#if LWIP_ND6
nd6_restart_netif(netif);
#endif /* LWIP_ND6*/
#endif /* LWIP_IPV6 */
#if LWIP_NETIF_STATUS_CALLBACK
netif->status_callback = NULL;
Expand Down Expand Up @@ -896,9 +898,9 @@ netif_set_up(struct netif *netif)
#endif

netif_issue_reports(netif, NETIF_REPORT_TYPE_IPV4 | NETIF_REPORT_TYPE_IPV6);
#if LWIP_IPV6
#if LWIP_IPV6 && LWIP_ND6
nd6_restart_netif(netif);
#endif /* LWIP_IPV6 */
#endif /* LWIP_IPV6 && LWIP_ND6 */
}
}

Expand Down Expand Up @@ -976,9 +978,9 @@ netif_set_down(struct netif *netif)
}
#endif /* LWIP_IPV4 && LWIP_ARP */

#if LWIP_IPV6
#if LWIP_IPV6 && LWIP_ND6
nd6_cleanup_netif(netif);
#endif /* LWIP_IPV6 */
#endif /* LWIP_IPV6 && LWIP_ND6 */

NETIF_STATUS_CALLBACK(netif);
}
Expand Down Expand Up @@ -1039,9 +1041,9 @@ netif_set_link_up(struct netif *netif)
#endif /* LWIP_AUTOIP */

netif_issue_reports(netif, NETIF_REPORT_TYPE_IPV4 | NETIF_REPORT_TYPE_IPV6);
#if LWIP_IPV6
#if LWIP_IPV6 && LWIP_ND6
nd6_restart_netif(netif);
#endif /* LWIP_IPV6 */
#endif /* LWIP_IPV6 && LWIP_ND6 */

NETIF_LINK_CALLBACK(netif);
#if LWIP_NETIF_EXT_STATUS_CALLBACK
Expand Down Expand Up @@ -1464,12 +1466,12 @@ netif_ip6_addr_set_state(struct netif *netif, s8_t addr_idx, u8_t state)
u8_t new_valid = state & IP6_ADDR_VALID;
LWIP_DEBUGF(NETIF_DEBUG | LWIP_DBG_STATE, ("netif_ip6_addr_set_state: netif address state being changed\n"));

#if LWIP_IPV6_MLD
#if LWIP_IPV6_MLD && LWIP_ND6
/* Reevaluate solicited-node multicast group membership. */
if (netif->flags & NETIF_FLAG_MLD6) {
nd6_adjust_mld_membership(netif, addr_idx, state);
}
#endif /* LWIP_IPV6_MLD */
#endif /* LWIP_IPV6_MLD && LWIP_ND6 */

if (old_valid && !new_valid) {
/* address about to be removed by setting invalid */
Expand Down
5 changes: 5 additions & 0 deletions src/core/tcp.c
Original file line number Diff line number Diff line change
Expand Up @@ -2265,8 +2265,13 @@ tcp_eff_send_mss_netif(u16_t sendmss, struct netif *outif, const ip_addr_t *dest
if (IP_IS_V6(dest))
#endif /* LWIP_IPV4 */
{
#if LWIP_ND6
/* First look in destination cache, to see if there is a Path MTU. */
mtu = nd6_get_destination_mtu(ip_2_ip6(dest), outif);
#else
LWIP_UNUSED_ARG(outif); /* in case LWIP_ND6 is disabled */
mtu = TCP_MSS;
#endif /* LWIP_ND6 */
}
#if LWIP_IPV4
else
Expand Down
8 changes: 4 additions & 4 deletions src/core/tcp_in.c
Original file line number Diff line number Diff line change
Expand Up @@ -1328,12 +1328,12 @@ tcp_receive(struct tcp_pcb *pcb)
}
#endif /* TCP_OVERSIZE */

#if LWIP_IPV6 && LWIP_ND6_TCP_REACHABILITY_HINTS
#if LWIP_IPV6 && LWIP_ND6_TCP_REACHABILITY_HINTS && LWIP_ND6
if (ip_current_is_v6()) {
/* Inform neighbor reachability of forward progress. */
nd6_reachability_hint(ip6_current_src_addr());
}
#endif /* LWIP_IPV6 && LWIP_ND6_TCP_REACHABILITY_HINTS*/
#endif /* LWIP_IPV6 && LWIP_ND6_TCP_REACHABILITY_HINTS && LWIP_ND6 */

pcb->snd_buf = (tcpwnd_size_t)(pcb->snd_buf + recv_acked);
/* check if this ACK ends our retransmission of in-flight data */
Expand Down Expand Up @@ -1675,12 +1675,12 @@ tcp_receive(struct tcp_pcb *pcb)
}
#endif /* LWIP_TCP_SACK_OUT */

#if LWIP_IPV6 && LWIP_ND6_TCP_REACHABILITY_HINTS
#if LWIP_IPV6 && LWIP_ND6_TCP_REACHABILITY_HINTS && LWIP_ND6
if (ip_current_is_v6()) {
/* Inform neighbor reachability of forward progress. */
nd6_reachability_hint(ip6_current_src_addr());
}
#endif /* LWIP_IPV6 && LWIP_ND6_TCP_REACHABILITY_HINTS*/
#endif /* LWIP_IPV6 && LWIP_ND6_TCP_REACHABILITY_HINTS && LWIP_ND6*/

} else {
/* We get here if the incoming segment is out-of-sequence. */
Expand Down
2 changes: 2 additions & 0 deletions src/core/timeouts.c
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,9 @@ const struct lwip_cyclic_timer lwip_cyclic_timers[] = {
{DNS_TMR_INTERVAL, HANDLER(dns_tmr)},
#endif /* LWIP_DNS */
#if LWIP_IPV6
#if LWIP_ND6
{ND6_TMR_INTERVAL, HANDLER(nd6_tmr)},
#endif /* LWIP_ND6 */
#if LWIP_IPV6_REASS && !ESP_LWIP_IP6_REASSEMBLY_TIMERS_ONDEMAND
{IP6_REASS_TMR_INTERVAL, HANDLER(ip6_reass_tmr)},
#endif /* LWIP_IPV6_REASS */
Expand Down
12 changes: 12 additions & 0 deletions src/include/lwip/opt.h
Original file line number Diff line number Diff line change
Expand Up @@ -2448,6 +2448,18 @@
#define LWIP_IPV6 0
#endif

/**
* LWIP_ND6==1: Enable NDP
* when LWIP_IPV6 is enabled in lwIP, NDP timer is enabled by default with a timeout of 1 second.
* However, in the case of sleepy end-device, NDP is not required.
* This leads to CPU waking up every 1 second, resulting in increased power consumption.
* Therefore, add a option to control nd6, using LWIP_ND6 enable/disable ND6 protocol.
* Unless you are very clear that you do not need to use ND6, please do not disable it!
*/
#if !defined LWIP_ND6 || defined __DOXYGEN__
#define LWIP_ND6 1
#endif

/**
* IPV6_REASS_MAXAGE: Maximum time (in multiples of IP6_REASS_TMR_INTERVAL - so seconds, normally)
* a fragmented IP packet waits for all fragments to arrive. If not all fragments arrived
Expand Down
1 change: 1 addition & 0 deletions test/fuzz/lwipopts.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
#define SYS_LIGHTWEIGHT_PROT 0

#define LWIP_IPV6 1
#define LWIP_ND6 1
#define IPV6_FRAG_COPYHEADER 1
#define LWIP_IPV6_DUP_DETECT_ATTEMPTS 0

Expand Down
1 change: 1 addition & 0 deletions test/unit/lwipopts.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
#define LWIP_TESTMODE 1

#define LWIP_IPV6 1
#define LWIP_ND6 1

#define LWIP_CHECKSUM_ON_COPY 1
#define TCP_CHECKSUM_ON_COPY_SANITY_CHECK 1
Expand Down

0 comments on commit 0a1828f

Please sign in to comment.