Skip to content

Commit aa68f29

Browse files
committed
Merge pull request #1660 from petermm/ipv6-disable
ESP32: Default disable (unsupported) IPv6 These changes are made under both the "Apache 2.0" and the "GNU Lesser General Public License 2.1 or later" license terms (dual license). SPDX-License-Identifier: Apache-2.0 OR LGPL-2.1-or-later
2 parents 6e7d9ba + 10dd3fe commit aa68f29

File tree

5 files changed

+22
-1
lines changed

5 files changed

+22
-1
lines changed

src/platforms/esp32/components/avm_builtins/socket_driver.c

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,16 +107,27 @@ uint32_t socket_tuple_to_addr(term addr_tuple)
107107

108108
static void tuple_to_ip_addr(term address_tuple, ip_addr_t *out_addr)
109109
{
110+
#ifdef CONFIG_LWIP_IPV6
110111
out_addr->type = IPADDR_TYPE_V4;
111112
out_addr->u_addr.ip4.addr = htonl(socket_tuple_to_addr(address_tuple));
113+
#else
114+
out_addr->addr = htonl(socket_tuple_to_addr(address_tuple));
115+
#endif
112116
}
113117

114118
static void socket_fill_ipv4_addr_tuple(term addr_tuple, ip_addr_t *addr)
115119
{
120+
#ifdef CONFIG_LWIP_IPV6
116121
uint8_t ad1 = ip4_addr1(&(addr->u_addr.ip4));
117122
uint8_t ad2 = ip4_addr2(&(addr->u_addr.ip4));
118123
uint8_t ad3 = ip4_addr3(&(addr->u_addr.ip4));
119124
uint8_t ad4 = ip4_addr4(&(addr->u_addr.ip4));
125+
#else
126+
uint8_t ad1 = ip4_addr1(addr);
127+
uint8_t ad2 = ip4_addr2(addr);
128+
uint8_t ad3 = ip4_addr3(addr);
129+
uint8_t ad4 = ip4_addr4(addr);
130+
#endif
120131
term_put_tuple_element(addr_tuple, 0, term_from_int11(ad1));
121132
term_put_tuple_element(addr_tuple, 1, term_from_int11(ad2));
122133
term_put_tuple_element(addr_tuple, 2, term_from_int11(ad3));
@@ -127,6 +138,7 @@ static void socket_fill_ipv4_addr_tuple(term addr_tuple, ip_addr_t *addr)
127138
static term socket_addr_to_tuple(Heap *heap, ip_addr_t *addr)
128139
{
129140
term addr_tuple;
141+
#ifdef CONFIG_LWIP_IPV6
130142
switch (IP_GET_TYPE(addr)) {
131143
case IPADDR_TYPE_V4: {
132144
addr_tuple = term_alloc_tuple(4, heap);
@@ -141,6 +153,11 @@ static term socket_addr_to_tuple(Heap *heap, ip_addr_t *addr)
141153
default:
142154
addr_tuple = term_invalid_term();
143155
}
156+
#else
157+
// When IPv6 is disabled, we only have IPv4 addresses
158+
addr_tuple = term_alloc_tuple(4, heap);
159+
socket_fill_ipv4_addr_tuple(addr_tuple, addr);
160+
#endif
144161

145162
return addr_tuple;
146163
}
@@ -888,7 +905,7 @@ static void do_connect(Context *ctx, const GenMessage *gen_message)
888905

889906
TRACE("tcp: connecting to: %s\n", address_string);
890907

891-
struct ip_addr remote_ip;
908+
ip_addr_t remote_ip;
892909
//TODO: use dns_gethostbyname instead
893910
err_t status = netconn_gethostbyname(address_string, &remote_ip);
894911
if (UNLIKELY(status != ERR_OK)) {
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
CONFIG_PARTITION_TABLE_CUSTOM=y
22
CONFIG_ESPTOOLPY_FLASHSIZE_4MB=y
33
CONFIG_MBEDTLS_ECP_FIXED_POINT_OPTIM=y
4+
CONFIG_LWIP_IPV6=n

src/platforms/esp32/sdkconfig.release-defaults

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@ CONFIG_ESPTOOLPY_FLASHSIZE_4MB=y
33
CONFIG_MBEDTLS_ECP_FIXED_POINT_OPTIM=y
44
CONFIG_COMPILER_OPTIMIZATION_PERF=y
55
CONFIG_COMPILER_OPTIMIZATION_ASSERTIONS_SILENT=y
6+
CONFIG_LWIP_IPV6=n

src/platforms/esp32/test/sdkconfig.ci.wokwi

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,4 @@ CONFIG_ETH_USE_OPENETH=n
66
CONFIG_COMPILER_OPTIMIZATION_PERF=y
77
CONFIG_COMPILER_OPTIMIZATION_ASSERTIONS_SILENT=y
88
CONFIG_MBEDTLS_ECP_FIXED_POINT_OPTIM=y
9+
CONFIG_LWIP_IPV6=n

src/platforms/esp32/test/sdkconfig.defaults

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,4 @@ CONFIG_ESP_INT_WDT_TIMEOUT_MS=10000
55
CONFIG_ETH_USE_OPENETH=y
66
CONFIG_AVM_RTC_SLOW_MAX_SIZE=1024
77
CONFIG_MBEDTLS_ECP_FIXED_POINT_OPTIM=y
8+
CONFIG_LWIP_IPV6=n

0 commit comments

Comments
 (0)