lwip: Add LWIP_IPV6 macro to strip IPv6 function in LWIP component

This commit is contained in:
yuanjm
2021-01-18 19:13:22 +08:00
committed by bot
parent 71de11e89d
commit 90696dad89
5 changed files with 42 additions and 8 deletions

View File

@@ -133,6 +133,7 @@ menu "LWIP"
config LWIP_IP6_FRAG config LWIP_IP6_FRAG
bool "Enable fragment outgoing IP6 packets" bool "Enable fragment outgoing IP6 packets"
default y default y
depends on LWIP_IPV6
help help
Enabling this option allows fragmenting outgoing IP6 packets if their size Enabling this option allows fragmenting outgoing IP6 packets if their size
exceeds MTU. exceeds MTU.
@@ -146,6 +147,7 @@ menu "LWIP"
config LWIP_IP6_REASSEMBLY config LWIP_IP6_REASSEMBLY
bool "Enable reassembly incoming fragmented IP6 packets" bool "Enable reassembly incoming fragmented IP6 packets"
default n default n
depends on LWIP_IPV6
help help
Enabling this option allows reassemblying incoming fragmented IP6 packets. Enabling this option allows reassemblying incoming fragmented IP6 packets.
@@ -299,8 +301,18 @@ menu "LWIP"
If rate limiting self-assignment requests, wait this long between If rate limiting self-assignment requests, wait this long between
each request. each request.
config LWIP_IPV6
bool "Enable IPv6"
default y
help
Enable IPv6 function. If not use IPv6 function, set this option to n.
If disable LWIP_IPV6, not adding coap and asio component into the build.
Please assign them to EXCLUDE_COMPONENTS in the make or cmake file in your
project directory, so that the component will not be compiled.
config LWIP_IPV6_AUTOCONFIG config LWIP_IPV6_AUTOCONFIG
bool "Enable IPV6 stateless address autoconfiguration (SLAAC)" bool "Enable IPV6 stateless address autoconfiguration (SLAAC)"
depends on LWIP_IPV6
default n default n
help help
Enabling this option allows the devices to IPV6 stateless address autoconfiguration (SLAAC). Enabling this option allows the devices to IPV6 stateless address autoconfiguration (SLAAC).
@@ -627,7 +639,7 @@ menu "LWIP"
config LWIP_PPP_ENABLE_IPV6 config LWIP_PPP_ENABLE_IPV6
bool "Enable IPV6 support for PPP connections (IPV6CP)" bool "Enable IPV6 support for PPP connections (IPV6CP)"
depends on LWIP_PPP_SUPPORT depends on LWIP_PPP_SUPPORT && LWIP_IPV6
default y default y
help help
Enable IPV6 support in PPP for the local link between the DTE (processor) and DCE (modem). Enable IPV6 support in PPP for the local link between the DTE (processor) and DCE (modem).
@@ -638,6 +650,7 @@ menu "LWIP"
config LWIP_IPV6_MEMP_NUM_ND6_QUEUE config LWIP_IPV6_MEMP_NUM_ND6_QUEUE
int "Max number of IPv6 packets to queue during MAC resolution" int "Max number of IPv6 packets to queue during MAC resolution"
depends on LWIP_IPV6
range 3 20 range 3 20
default 3 default 3
help help
@@ -645,6 +658,7 @@ menu "LWIP"
config LWIP_IPV6_ND6_NUM_NEIGHBORS config LWIP_IPV6_ND6_NUM_NEIGHBORS
int "Max number of entries in IPv6 neighbor cache" int "Max number of entries in IPv6 neighbor cache"
depends on LWIP_IPV6
range 3 10 range 3 10
default 5 default 5
help help
@@ -791,6 +805,7 @@ menu "LWIP"
choice LWIP_HOOK_IP6_ROUTE choice LWIP_HOOK_IP6_ROUTE
prompt "IPv6 route Hook" prompt "IPv6 route Hook"
depends on LWIP_IPV6
default LWIP_HOOK_IP6_ROUTE_NONE default LWIP_HOOK_IP6_ROUTE_NONE
help help
Enables custom IPv6 route hook. Enables custom IPv6 route hook.

View File

@@ -114,13 +114,16 @@ static int esp_ping_receive(esp_ping_t *ep)
inet_addr_to_ip4addr(ip_2_ip4(&ep->recv_addr), &from4->sin_addr); inet_addr_to_ip4addr(ip_2_ip4(&ep->recv_addr), &from4->sin_addr);
IP_SET_TYPE_VAL(ep->recv_addr, IPADDR_TYPE_V4); IP_SET_TYPE_VAL(ep->recv_addr, IPADDR_TYPE_V4);
data_head = (uint16_t)(sizeof(struct ip_hdr) + sizeof(struct icmp_echo_hdr)); data_head = (uint16_t)(sizeof(struct ip_hdr) + sizeof(struct icmp_echo_hdr));
} else { }
#if CONFIG_LWIP_IPV6
else {
// IPv6 // IPv6
struct sockaddr_in6 *from6 = (struct sockaddr_in6 *)&from; struct sockaddr_in6 *from6 = (struct sockaddr_in6 *)&from;
inet6_addr_to_ip6addr(ip_2_ip6(&ep->recv_addr), &from6->sin6_addr); inet6_addr_to_ip6addr(ip_2_ip6(&ep->recv_addr), &from6->sin6_addr);
IP_SET_TYPE_VAL(ep->recv_addr, IPADDR_TYPE_V6); IP_SET_TYPE_VAL(ep->recv_addr, IPADDR_TYPE_V6);
data_head = (uint16_t)(sizeof(struct ip6_hdr) + sizeof(struct icmp6_echo_hdr)); data_head = (uint16_t)(sizeof(struct ip6_hdr) + sizeof(struct icmp6_echo_hdr));
} }
#endif
if (len >= data_head) { if (len >= data_head) {
if (IP_IS_V4_VAL(ep->recv_addr)) { // Currently we process IPv4 if (IP_IS_V4_VAL(ep->recv_addr)) { // Currently we process IPv4
struct ip_hdr *iphdr = (struct ip_hdr *)buf; struct ip_hdr *iphdr = (struct ip_hdr *)buf;
@@ -131,7 +134,9 @@ static int esp_ping_receive(esp_ping_t *ep)
ep->recv_len = lwip_ntohs(IPH_LEN(iphdr)) - data_head; // The data portion of ICMP ep->recv_len = lwip_ntohs(IPH_LEN(iphdr)) - data_head; // The data portion of ICMP
return len; return len;
} }
} else if (IP_IS_V6_VAL(ep->recv_addr)) { // Currently we process IPv6 }
#if CONFIG_LWIP_IPV6
else if (IP_IS_V6_VAL(ep->recv_addr)) { // Currently we process IPv6
struct ip6_hdr *iphdr = (struct ip6_hdr *)buf; struct ip6_hdr *iphdr = (struct ip6_hdr *)buf;
struct icmp6_echo_hdr *iecho6 = (struct icmp6_echo_hdr *)(buf + sizeof(struct ip6_hdr)); // IPv6 head length is 40 struct icmp6_echo_hdr *iecho6 = (struct icmp6_echo_hdr *)(buf + sizeof(struct ip6_hdr)); // IPv6 head length is 40
if ((iecho6->id == ep->packet_hdr->id) && (iecho6->seqno == ep->packet_hdr->seqno)) { if ((iecho6->id == ep->packet_hdr->id) && (iecho6->seqno == ep->packet_hdr->seqno)) {
@@ -140,6 +145,7 @@ static int esp_ping_receive(esp_ping_t *ep)
return len; return len;
} }
} }
#endif
} }
fromlen = sizeof(from); fromlen = sizeof(from);
} }
@@ -249,11 +255,18 @@ esp_err_t esp_ping_new_session(const esp_ping_config_t *config, const esp_ping_c
} }
/* create socket */ /* create socket */
if (IP_IS_V4(&config->target_addr) || ip6_addr_isipv4mappedipv6(ip_2_ip6(&config->target_addr))) { if (IP_IS_V4(&config->target_addr)
#if CONFIG_LWIP_IPV6
|| ip6_addr_isipv4mappedipv6(ip_2_ip6(&config->target_addr))
#endif
) {
ep->sock = socket(AF_INET, SOCK_RAW, IP_PROTO_ICMP); ep->sock = socket(AF_INET, SOCK_RAW, IP_PROTO_ICMP);
} else { }
#if CONFIG_LWIP_IPV6
else {
ep->sock = socket(AF_INET6, SOCK_RAW, IP6_NEXTH_ICMP6); ep->sock = socket(AF_INET6, SOCK_RAW, IP6_NEXTH_ICMP6);
} }
#endif
PING_CHECK(ep->sock > 0, "create socket failed: %d", err, ESP_FAIL, ep->sock); PING_CHECK(ep->sock > 0, "create socket failed: %d", err, ESP_FAIL, ep->sock);
/* set if index */ /* set if index */
if(config->interface) { if(config->interface) {
@@ -281,12 +294,14 @@ esp_err_t esp_ping_new_session(const esp_ping_config_t *config, const esp_ping_c
inet_addr_from_ip4addr(&to4->sin_addr, ip_2_ip4(&config->target_addr)); inet_addr_from_ip4addr(&to4->sin_addr, ip_2_ip4(&config->target_addr));
ep->packet_hdr->type = ICMP_ECHO; ep->packet_hdr->type = ICMP_ECHO;
} }
#if CONFIG_LWIP_IPV6
if (IP_IS_V6(&config->target_addr)) { if (IP_IS_V6(&config->target_addr)) {
struct sockaddr_in6 *to6 = (struct sockaddr_in6 *)&ep->target_addr; struct sockaddr_in6 *to6 = (struct sockaddr_in6 *)&ep->target_addr;
to6->sin6_family = AF_INET6; to6->sin6_family = AF_INET6;
inet6_addr_from_ip6addr(&to6->sin6_addr, ip_2_ip6(&config->target_addr)); inet6_addr_from_ip6addr(&to6->sin6_addr, ip_2_ip6(&config->target_addr));
ep->packet_hdr->type = ICMP6_TYPE_EREQ; ep->packet_hdr->type = ICMP6_TYPE_EREQ;
} }
#endif
/* return ping handle to user */ /* return ping handle to user */
*hdl_out = (esp_ping_handle_t)ep; *hdl_out = (esp_ping_handle_t)ep;
return ESP_OK; return ESP_OK;

View File

@@ -85,7 +85,7 @@ typedef struct {
.timeout_ms = 1000, \ .timeout_ms = 1000, \
.data_size = 64, \ .data_size = 64, \
.tos = 0, \ .tos = 0, \
.target_addr = ip_addr_any_type, \ .target_addr = *(IP_ANY_TYPE), \
.task_stack_size = 2048, \ .task_stack_size = 2048, \
.task_prio = 2, \ .task_prio = 2, \
.interface = 0,\ .interface = 0,\

View File

@@ -23,7 +23,11 @@
#include "lwip/memp.h" #include "lwip/memp.h"
#include "esp_log.h" #include "esp_log.h"
#if CONFIG_LWIP_IPV6
#define DBG_LWIP_IP_SHOW(info, ip) ESP_LWIP_LOGI("%s type=%d ip=%x", (info), (ip).type, (ip).u_addr.ip4.addr) #define DBG_LWIP_IP_SHOW(info, ip) ESP_LWIP_LOGI("%s type=%d ip=%x", (info), (ip).type, (ip).u_addr.ip4.addr)
#else
#define DBG_LWIP_IP_SHOW(info, ip) ESP_LWIP_LOGI("%s type=%d ip=%x", (info), IPADDR_TYPE_V4, (ip).addr)
#endif
#define DBG_LWIP_IP_PCB_SHOW(pcb) \ #define DBG_LWIP_IP_PCB_SHOW(pcb) \
DBG_LWIP_IP_SHOW("local ip", (pcb)->local_ip);\ DBG_LWIP_IP_SHOW("local ip", (pcb)->local_ip);\
DBG_LWIP_IP_SHOW("remote ip", (pcb)->local_ip);\ DBG_LWIP_IP_SHOW("remote ip", (pcb)->local_ip);\

View File

@@ -749,7 +749,7 @@
/** /**
* LWIP_IPV6==1: Enable IPv6 * LWIP_IPV6==1: Enable IPv6
*/ */
#define LWIP_IPV6 1 #define LWIP_IPV6 CONFIG_LWIP_IPV6
/** /**
* MEMP_NUM_ND6_QUEUE: Max number of IPv6 packets to queue during MAC resolution. * MEMP_NUM_ND6_QUEUE: Max number of IPv6 packets to queue during MAC resolution.
@@ -962,7 +962,7 @@
#define ESP_AUTO_IP 1 #define ESP_AUTO_IP 1
#define ESP_PBUF 1 #define ESP_PBUF 1
#define ESP_PPP 1 #define ESP_PPP 1
#define ESP_IPV6 1 #define ESP_IPV6 LWIP_IPV6
#define ESP_SOCKET 1 #define ESP_SOCKET 1
#define ESP_LWIP_SELECT 1 #define ESP_LWIP_SELECT 1
#define ESP_LWIP_LOCK 1 #define ESP_LWIP_LOCK 1