Procházet zdrojové kódy

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

yuanjm před 5 roky
rodič
revize
d80db218da

+ 16 - 1
components/lwip/Kconfig

@@ -133,6 +133,7 @@ menu "LWIP"
     config LWIP_IP6_FRAG
         bool "Enable fragment outgoing IP6 packets"
         default y
+        depends on LWIP_IPV6
         help
             Enabling this option allows fragmenting outgoing IP6 packets if their size
             exceeds MTU.
@@ -146,6 +147,7 @@ menu "LWIP"
     config LWIP_IP6_REASSEMBLY
         bool "Enable reassembly incoming fragmented IP6 packets"
         default n
+        depends on LWIP_IPV6
         help
             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
             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
         bool "Enable IPV6 stateless address autoconfiguration (SLAAC)"
+        depends on LWIP_IPV6
         default n
         help
             Enabling this option allows the devices to IPV6 stateless address autoconfiguration (SLAAC).
@@ -627,7 +639,7 @@ menu "LWIP"
 
     config LWIP_PPP_ENABLE_IPV6
         bool "Enable IPV6 support for PPP connections (IPV6CP)"
-        depends on LWIP_PPP_SUPPORT
+        depends on LWIP_PPP_SUPPORT && LWIP_IPV6
         default y
         help
             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
         int "Max number of IPv6 packets to queue during MAC resolution"
+        depends on LWIP_IPV6
         range 3 20
         default 3
         help
@@ -645,6 +658,7 @@ menu "LWIP"
 
     config LWIP_IPV6_ND6_NUM_NEIGHBORS
         int "Max number of entries in IPv6 neighbor cache"
+        depends on LWIP_IPV6
         range 3 10
         default 5
         help
@@ -791,6 +805,7 @@ menu "LWIP"
 
         choice LWIP_HOOK_IP6_ROUTE
             prompt "IPv6 route Hook"
+            depends on LWIP_IPV6
             default LWIP_HOOK_IP6_ROUTE_NONE
             help
                 Enables custom IPv6 route hook.

+ 19 - 4
components/lwip/apps/ping/ping_sock.c

@@ -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);
             IP_SET_TYPE_VAL(ep->recv_addr, IPADDR_TYPE_V4);
             data_head = (uint16_t)(sizeof(struct ip_hdr) + sizeof(struct icmp_echo_hdr));
-        } else {
+        }
+#if CONFIG_LWIP_IPV6
+        else {
             // IPv6
             struct sockaddr_in6 *from6 = (struct sockaddr_in6 *)&from;
             inet6_addr_to_ip6addr(ip_2_ip6(&ep->recv_addr), &from6->sin6_addr);
             IP_SET_TYPE_VAL(ep->recv_addr, IPADDR_TYPE_V6);
             data_head = (uint16_t)(sizeof(struct ip6_hdr) + sizeof(struct icmp6_echo_hdr));
         }
+#endif
         if (len >= data_head) {
             if (IP_IS_V4_VAL(ep->recv_addr)) {              // Currently we process IPv4
                 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
                     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 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)) {
@@ -140,6 +145,7 @@ static int esp_ping_receive(esp_ping_t *ep)
                     return len;
                 }
             }
+#endif
         }
         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 */
-    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);
-    } else {
+    }
+#if CONFIG_LWIP_IPV6
+    else {
         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);
     /* set if index */
     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));
         ep->packet_hdr->type = ICMP_ECHO;
     }
+#if CONFIG_LWIP_IPV6
     if (IP_IS_V6(&config->target_addr)) {
         struct sockaddr_in6 *to6 = (struct sockaddr_in6 *)&ep->target_addr;
         to6->sin6_family = AF_INET6;
         inet6_addr_from_ip6addr(&to6->sin6_addr, ip_2_ip6(&config->target_addr));
         ep->packet_hdr->type = ICMP6_TYPE_EREQ;
     }
+#endif
     /* return ping handle to user */
     *hdl_out = (esp_ping_handle_t)ep;
     return ESP_OK;

+ 1 - 1
components/lwip/include/apps/ping/ping_sock.h

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

+ 4 - 0
components/lwip/port/esp32/debug/lwip_debug.c

@@ -23,7 +23,11 @@
 #include "lwip/memp.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)
+#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) \
         DBG_LWIP_IP_SHOW("local ip", (pcb)->local_ip);\
         DBG_LWIP_IP_SHOW("remote ip", (pcb)->local_ip);\

+ 2 - 2
components/lwip/port/esp32/include/lwipopts.h

@@ -749,7 +749,7 @@
 /**
  * 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.
@@ -962,7 +962,7 @@
 #define ESP_AUTO_IP                     1
 #define ESP_PBUF                        1
 #define ESP_PPP                         1
-#define ESP_IPV6                        1
+#define ESP_IPV6                        LWIP_IPV6
 #define ESP_SOCKET                      1
 #define ESP_LWIP_SELECT                 1
 #define ESP_LWIP_LOCK                   1