Skip to content

Commit e3bc3c2

Browse files
authored
Fixes for IPv6, added in CI (#5557)
1 parent 9def8b0 commit e3bc3c2

File tree

12 files changed

+85
-76
lines changed

12 files changed

+85
-76
lines changed

.travis.yml

+8
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,14 @@ jobs:
4444
script: $TRAVIS_BUILD_DIR/tests/common.sh
4545
env:
4646
- BUILD_TYPE=debug_odd
47+
- name: "Build IPv6 (1)"
48+
script: $TRAVIS_BUILD_DIR/tests/common.sh
49+
env:
50+
- BUILD_TYPE=build6_even
51+
- name: "Build IPv6 (2)"
52+
script: $TRAVIS_BUILD_DIR/tests/common.sh
53+
env:
54+
- BUILD_TYPE=build6_odd
4755
- name: "Platformio (1)"
4856
script: $TRAVIS_BUILD_DIR/tests/common.sh
4957
env:

cores/esp8266/IPAddress.cpp

-5
Original file line numberDiff line numberDiff line change
@@ -187,11 +187,6 @@ const IPAddress INADDR_NONE(255,255,255,255);
187187

188188
#if LWIP_IPV6
189189

190-
IPAddress::IPAddress(const ip_addr_t* from)
191-
{
192-
ip_addr_copy(_ip, *from);
193-
}
194-
195190
bool IPAddress::fromString6(const char *address) {
196191
// TODO: test test test
197192

cores/esp8266/IPAddress.h

+3-2
Original file line numberDiff line numberDiff line change
@@ -149,8 +149,8 @@ class IPAddress: public Printable {
149149
/*
150150
lwIP address compatibility
151151
*/
152+
IPAddress(const ipv4_addr& fw_addr) { setV4(); v4() = fw_addr.addr; }
152153
IPAddress(const ipv4_addr* fw_addr) { setV4(); v4() = fw_addr->addr; }
153-
IPAddress(const ip_addr_t& lwip_addr) { _ip = lwip_addr; }
154154

155155
operator ip_addr_t () const { return _ip; }
156156
operator const ip_addr_t*() const { return &_ip; }
@@ -163,7 +163,8 @@ class IPAddress: public Printable {
163163

164164
#if LWIP_IPV6
165165

166-
IPAddress(const ip_addr_t* from);
166+
IPAddress(const ip_addr_t& lwip_addr) { ip_addr_copy(_ip, lwip_addr); }
167+
IPAddress(const ip_addr_t* lwip_addr) { ip_addr_copy(_ip, *lwip_addr); }
167168

168169
uint16_t* raw6()
169170
{

libraries/ESP8266AVRISP/src/ESP8266AVRISP.cpp

+1-4
Original file line numberDiff line numberDiff line change
@@ -74,10 +74,7 @@ AVRISPState_t ESP8266AVRISP::update() {
7474
if (_server.hasClient()) {
7575
_client = _server.available();
7676
_client.setNoDelay(true);
77-
ip_addr_t lip;
78-
lip.addr = _client.remoteIP();
79-
AVRISP_DEBUG("client connect %d.%d.%d.%d:%d", IP2STR(&lip), _client.remotePort());
80-
(void) lip; // Avoid unused warning when not in debug mode
77+
AVRISP_DEBUG("client connect %s:%d", _client.remoteIP().toString().c_str(), _client.remotePort());
8178
_client.setTimeout(100); // for getch()
8279
_state = AVRISP_STATE_PENDING;
8380
_reject_incoming();

libraries/ESP8266NetBIOS/ESP8266NetBIOS.cpp

+10-8
Original file line numberDiff line numberDiff line change
@@ -154,11 +154,9 @@ bool ESP8266NetBIOS::begin(const char *name)
154154
if(_pcb != NULL) {
155155
return true;
156156
}
157-
ip_addr_t addr;
158-
addr.addr = INADDR_ANY;
159157
_pcb = udp_new();
160158
udp_recv(_pcb, &_s_recv, (void *) this);
161-
err_t err = udp_bind(_pcb, &addr, NBNS_PORT);
159+
err_t err = udp_bind(_pcb, INADDR_ANY, NBNS_PORT);
162160
if(err != ERR_OK) {
163161
end();
164162
return false;
@@ -182,9 +180,13 @@ void ESP8266NetBIOS::_recv(udp_pcb *upcb, pbuf *pb, CONST ip_addr_t *addr, uint1
182180
while(pb != NULL) {
183181
uint8_t * data = (uint8_t*)((pb)->payload);
184182
size_t len = pb->len;
185-
ip_hdr* iphdr = reinterpret_cast<ip_hdr*>(data - UDP_HLEN - IP_HLEN);
186-
ip_addr_t saddr;
187-
saddr.addr = iphdr->src.addr;
183+
#if LWIP_VERSION_MAJOR == 1
184+
// check UdpContext.h
185+
const ip_addr_t* saddr = &current_iphdr_src;
186+
#else
187+
// check UdpContext.h
188+
const ip_addr_t* saddr = &ip_data.current_iphdr_src;
189+
#endif
188190

189191
if (len >= sizeof(struct NBNSQUESTION)) {
190192
struct NBNSQUESTION * question = (struct NBNSQUESTION *)data;
@@ -221,7 +223,7 @@ void ESP8266NetBIOS::_recv(udp_pcb *upcb, pbuf *pb, CONST ip_addr_t *addr, uint1
221223
if(pbt != NULL) {
222224
uint8_t* dst = reinterpret_cast<uint8_t*>(pbt->payload);
223225
memcpy(dst, (uint8_t *)&nbnsa, sizeof(nbnsa));
224-
udp_sendto(_pcb, pbt, &saddr, NBNS_PORT);
226+
udp_sendto(_pcb, pbt, saddr, NBNS_PORT);
225227
pbuf_free(pbt);
226228
}
227229
} else if (0 == strcmp(name, "*")) {
@@ -251,7 +253,7 @@ void ESP8266NetBIOS::_recv(udp_pcb *upcb, pbuf *pb, CONST ip_addr_t *addr, uint1
251253
if(pbt != NULL) {
252254
uint8_t* dst = reinterpret_cast<uint8_t*>(pbt->payload);
253255
memcpy(dst, (uint8_t *)&nbnsan, sizeof(nbnsan));
254-
udp_sendto(_pcb, pbt, &saddr, NBNS_PORT);
256+
udp_sendto(_pcb, pbt, saddr, NBNS_PORT);
255257
pbuf_free(pbt);
256258
}
257259
}

libraries/ESP8266WiFi/src/include/UdpContext.h

+5-8
Original file line numberDiff line numberDiff line change
@@ -107,17 +107,14 @@ class UdpContext
107107
udp_disconnect(_pcb);
108108
}
109109

110-
#if LWIP_VERSION_MAJOR == 1
111-
void setMulticastInterface(const ip_addr_t addr)
110+
void setMulticastInterface(const IPAddress& addr)
112111
{
113-
udp_set_multicast_netif_addr(_pcb, addr);
114-
}
112+
#if LWIP_VERSION_MAJOR == 1
113+
udp_set_multicast_netif_addr(_pcb, (ip_addr_t)addr);
115114
#else
116-
void setMulticastInterface(const ip_addr_t* addr)
117-
{
118-
udp_set_multicast_netif_addr(_pcb, ip_2_ip4(addr));
119-
}
115+
udp_set_multicast_netif_addr(_pcb, ip_2_ip4((const ip_addr_t*)addr));
120116
#endif
117+
}
121118

122119
void setMulticastTTL(int ttl)
123120
{

libraries/ESP8266mDNS/src/LEAmDNS_Control.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -244,9 +244,9 @@ bool MDNSResponder::_parseQuery(const MDNSResponder::stcMDNS_MsgHeader& p_MsgHea
244244
ip_info IPInfo_Remote;
245245
if (((IPInfo_Remote.ip.addr = m_pUDPContext->getRemoteAddress())) &&
246246
(((wifi_get_ip_info(SOFTAP_IF, &IPInfo_Local)) &&
247-
(ip_addr_netcmp(&IPInfo_Remote.ip, &IPInfo_Local.ip, &IPInfo_Local.netmask))) || // Remote IP in SOFTAP's subnet OR
247+
(ip4_addr_netcmp(&IPInfo_Remote.ip, &IPInfo_Local.ip, &IPInfo_Local.netmask))) || // Remote IP in SOFTAP's subnet OR
248248
((wifi_get_ip_info(STATION_IF, &IPInfo_Local)) &&
249-
(ip_addr_netcmp(&IPInfo_Remote.ip, &IPInfo_Local.ip, &IPInfo_Local.netmask))))) { // Remote IP in STATION's subnet
249+
(ip4_addr_netcmp(&IPInfo_Remote.ip, &IPInfo_Local.ip, &IPInfo_Local.netmask))))) { // Remote IP in STATION's subnet
250250

251251
DEBUG_EX_RX(DEBUG_OUTPUT.printf_P(PSTR("[MDNSResponder] _parseQuery: Legacy query from local host %s!\n"), IPAddress(m_pUDPContext->getRemoteAddress()).toString().c_str()););
252252

libraries/ESP8266mDNS/src/LEAmDNS_Helpers.cpp

+4-5
Original file line numberDiff line numberDiff line change
@@ -191,19 +191,18 @@ bool MDNSResponder::_allocUDPContext(void) {
191191

192192
_releaseUDPContext();
193193

194-
ip_addr_t multicast_addr;
195194
#ifdef MDNS_IP4_SUPPORT
196-
multicast_addr.addr = DNS_MQUERY_IPV4_GROUP_INIT;
195+
ip_addr_t multicast_addr = DNS_MQUERY_IPV4_GROUP_INIT;
197196
#endif
198197
#ifdef MDNS_IP6_SUPPORT
199-
//TODO: set multicast address
198+
//TODO: set multicast address (lwip_joingroup() is IPv4 only at the time of writing)
200199
multicast_addr.addr = DNS_MQUERY_IPV6_GROUP_INIT;
201200
#endif
202-
if (ERR_OK == igmp_joingroup(IP_ADDR_ANY, &multicast_addr)) {
201+
if (ERR_OK == igmp_joingroup(IP4_ADDR_ANY4, ip_2_ip4(&multicast_addr))) {
203202
m_pUDPContext = new UdpContext;
204203
m_pUDPContext->ref();
205204

206-
if (m_pUDPContext->listen(IP_ADDR_ANY, DNS_MQUERY_PORT)) {
205+
if (m_pUDPContext->listen(IP4_ADDR_ANY, DNS_MQUERY_PORT)) {
207206
m_pUDPContext->setMulticastTTL(MDNS_MULTICAST_TTL);
208207
m_pUDPContext->onRx(std::bind(&MDNSResponder::_callProcess, this));
209208

libraries/ESP8266mDNS/src/LEAmDNS_Transfer.cpp

+15-21
Original file line numberDiff line numberDiff line change
@@ -79,10 +79,10 @@ bool MDNSResponder::_sendMDNSMessage(MDNSResponder::stcMDNSSendParameter& p_rSen
7979
if (p_rSendParameter.m_bResponse) {
8080
if (p_rSendParameter.m_bUnicast) { // Unicast response -> Send to querier
8181
DEBUG_EX_ERR(if (!m_pUDPContext->getRemoteAddress()) { DEBUG_OUTPUT.printf_P(PSTR("[MDNSResponder] _sendMDNSMessage: MISSING remote address for response!\n")); });
82-
ip_addr_t ipRemote;
83-
ipRemote.addr = m_pUDPContext->getRemoteAddress();
82+
IPAddress ipRemote;
83+
ipRemote = m_pUDPContext->getRemoteAddress();
8484
bResult = ((_prepareMDNSMessage(p_rSendParameter, _getResponseMulticastInterface(SOFTAP_MODE | STATION_MODE))) &&
85-
(m_pUDPContext->send(&ipRemote, m_pUDPContext->getRemotePort())));
85+
(m_pUDPContext->send(ipRemote, m_pUDPContext->getRemotePort())));
8686
}
8787
else { // Multicast response -> Send via the same network interface, that received the query
8888
bResult = _sendMDNSMessage_Multicast(p_rSendParameter, (SOFTAP_MODE | STATION_MODE));
@@ -116,26 +116,20 @@ bool MDNSResponder::_sendMDNSMessage_Multicast(MDNSResponder::stcMDNSSendParamet
116116
int p_iWiFiOpMode) {
117117
bool bResult = false;
118118

119-
ip_addr_t ifFromAddress;
120-
ifFromAddress.addr = _getResponseMulticastInterface(p_iWiFiOpMode);
121-
IPAddress fromIPAddress(ifFromAddress.addr);
122-
#if LWIP_VERSION_MAJOR == 1
123-
m_pUDPContext->setMulticastInterface(ifFromAddress);
124-
#else
125-
m_pUDPContext->setMulticastInterface(&ifFromAddress);
126-
#endif
119+
IPAddress fromIPAddress;
120+
fromIPAddress = _getResponseMulticastInterface(p_iWiFiOpMode);
121+
m_pUDPContext->setMulticastInterface(fromIPAddress);
127122

128-
ip_addr_t toMulticastAddress;
129123
#ifdef MDNS_IP4_SUPPORT
130-
toMulticastAddress.addr = DNS_MQUERY_IPV4_GROUP_INIT;
124+
IPAddress toMulticastAddress(DNS_MQUERY_IPV4_GROUP_INIT);
131125
#endif
132126
#ifdef MDNS_IP6_SUPPORT
133127
//TODO: set multicast address
134-
toMulticastAddress.addr = DNS_MQUERY_IPV6_GROUP_INIT;
128+
IPAddress toMulticastAddress(DNS_MQUERY_IPV6_GROUP_INIT);
135129
#endif
136-
DEBUG_EX_INFO(DEBUG_OUTPUT.printf_P(PSTR("[MDNSResponder] _sendMDNSMessage_Multicast: Will send to '%s'.\n"), IPAddress(toMulticastAddress.addr).toString().c_str()););
130+
DEBUG_EX_INFO(DEBUG_OUTPUT.printf_P(PSTR("[MDNSResponder] _sendMDNSMessage_Multicast: Will send to '%s'.\n"), toMulticastAddress.toString().c_str()););
137131
bResult = ((_prepareMDNSMessage(p_rSendParameter, fromIPAddress)) &&
138-
(m_pUDPContext->send(&toMulticastAddress, DNS_MQUERY_PORT)));
132+
(m_pUDPContext->send(toMulticastAddress, DNS_MQUERY_PORT)));
139133

140134
DEBUG_EX_ERR(if (!bResult) { DEBUG_OUTPUT.printf_P(PSTR("[MDNSResponder] _sendMDNSMessage_Multicast: FAILED!\n")); });
141135
return bResult;
@@ -385,13 +379,13 @@ IPAddress MDNSResponder::_getResponseMulticastInterface(int p_iWiFiOpModes) cons
385379
(wifi_get_opmode() & SOFTAP_MODE)) {
386380
//DEBUG_EX_INFO(DEBUG_OUTPUT.printf_P(PSTR("[MDNSResponder] _getResponseMulticastInterface: SOFTAP_MODE\n")););
387381
// Get remote IP address
388-
ip_info IPInfo_Remote;
389-
IPInfo_Remote.ip.addr = m_pUDPContext->getRemoteAddress();
382+
IPAddress IP_Remote;
383+
IP_Remote = m_pUDPContext->getRemoteAddress();
390384
// Get local (AP) IP address
391385
wifi_get_ip_info(SOFTAP_IF, &IPInfo_Local);
392386

393387
if ((IPInfo_Local.ip.addr) && // Has local AP IP address AND
394-
(ip_addr_netcmp(&IPInfo_Remote.ip, &IPInfo_Local.ip, &IPInfo_Local.netmask))) { // Remote address is in the same subnet as the AP
388+
(ip4_addr_netcmp(ip_2_ip4((const ip_addr_t*)IP_Remote), &IPInfo_Local.ip, &IPInfo_Local.netmask))) { // Remote address is in the same subnet as the AP
395389
bFoundMatch = true;
396390
}
397391
}
@@ -402,8 +396,8 @@ IPAddress MDNSResponder::_getResponseMulticastInterface(int p_iWiFiOpModes) cons
402396
// Get local (STATION) IP address
403397
wifi_get_ip_info(STATION_IF, &IPInfo_Local);
404398
}
405-
//DEBUG_EX_INFO(DEBUG_OUTPUT.printf_P(PSTR("[MDNSResponder] _getResponseMulticastInterface(%i): %s\n"), p_iWiFiOpModes, IPAddress(IPInfo_Local.ip.addr).toString().c_str()););
406-
return IPAddress(IPInfo_Local.ip.addr);
399+
//DEBUG_EX_INFO(DEBUG_OUTPUT.printf_P(PSTR("[MDNSResponder] _getResponseMulticastInterface(%i): %s\n"), p_iWiFiOpModes, IPAddress(IPInfo_Local.ip).toString().c_str()););
400+
return IPAddress(IPInfo_Local.ip);
407401
}
408402

409403

tests/common.sh

+20-9
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,9 @@ function build_sketches()
4141
local build_dir=build.tmp
4242
local build_mod=$4
4343
local build_rem=$5
44+
local lwip=$6
4445
mkdir -p $build_dir
45-
local build_cmd="python tools/build.py -b generic -v -w all -s 4M1M -v -k -p $PWD/$build_dir $build_arg "
46+
local build_cmd="python tools/build.py -b generic -v -w all -s 4M1M -v -k -p $PWD/$build_dir -n $lwip $build_arg "
4647
local sketches=$(find $srcpath -name *.ino | sort)
4748
print_size_info >size.log
4849
export ARDUINO_IDE_PATH=$arduino
@@ -116,8 +117,8 @@ function install_ide()
116117
debug_flags="-DDEBUG_ESP_PORT=Serial -DDEBUG_ESP_SSL -DDEBUG_ESP_TLS_MEM -DDEBUG_ESP_HTTP_CLIENT -DDEBUG_ESP_HTTP_SERVER -DDEBUG_ESP_CORE -DDEBUG_ESP_WIFI -DDEBUG_ESP_HTTP_UPDATE -DDEBUG_ESP_UPDATER -DDEBUG_ESP_OTA -DDEBUG_ESP_OOM"
117118
fi
118119
# Set custom warnings for all builds (i.e. could add -Wextra at some point)
119-
echo "compiler.c.extra_flags=-Wall -Wextra -Werror -DLWIP_IPV6=0 $debug_flags" > esp8266/platform.local.txt
120-
echo "compiler.cpp.extra_flags=-Wall -Wextra -Werror -DLWIP_IPV6=0 $debug_flags" >> esp8266/platform.local.txt
120+
echo "compiler.c.extra_flags=-Wall -Wextra -Werror $debug_flags" > esp8266/platform.local.txt
121+
echo "compiler.cpp.extra_flags=-Wall -Wextra -Werror $debug_flags" >> esp8266/platform.local.txt
121122
echo -e "\n----platform.local.txt----"
122123
cat esp8266/platform.local.txt
123124
echo -e "\n----\n"
@@ -196,10 +197,11 @@ function build_sketches_with_arduino()
196197
{
197198
local build_mod=$1
198199
local build_rem=$2
200+
local lwip=$3
199201

200202
# Compile sketches
201203
echo -e "travis_fold:start:sketch_test"
202-
build_sketches $HOME/arduino_ide $TRAVIS_BUILD_DIR/libraries "-l $HOME/Arduino/libraries" $1 $2
204+
build_sketches $HOME/arduino_ide $TRAVIS_BUILD_DIR/libraries "-l $HOME/Arduino/libraries" $build_mod $build_rem $lwip
203205
echo -e "travis_fold:end:sketch_test"
204206

205207
# Generate size report
@@ -221,19 +223,28 @@ fi
221223

222224
if [ "$BUILD_TYPE" = "build" ]; then
223225
install_arduino nodebug
224-
build_sketches_with_arduino 1 0
226+
build_sketches_with_arduino 1 0 lm2f
227+
elif [ "$BUILD_TYPE" = "build6" ]; then
228+
install_arduino nodebug
229+
build_sketches_with_arduino 1 0 lm6f
225230
elif [ "$BUILD_TYPE" = "build_even" ]; then
226231
install_arduino nodebug
227-
build_sketches_with_arduino 2 0
232+
build_sketches_with_arduino 2 0 lm2f
228233
elif [ "$BUILD_TYPE" = "build_odd" ]; then
229234
install_arduino nodebug
230-
build_sketches_with_arduino 2 1
235+
build_sketches_with_arduino 2 1 lm2f
231236
elif [ "$BUILD_TYPE" = "debug_even" ]; then
232237
install_arduino debug
233-
build_sketches_with_arduino 2 0
238+
build_sketches_with_arduino 2 0 lm2f
234239
elif [ "$BUILD_TYPE" = "debug_odd" ]; then
235240
install_arduino debug
236-
build_sketches_with_arduino 2 1
241+
build_sketches_with_arduino 2 1 lm2f
242+
elif [ "$BUILD_TYPE" = "build6_even" ]; then
243+
install_arduino nodebug
244+
build_sketches_with_arduino 2 0 lm6f
245+
elif [ "$BUILD_TYPE" = "build6_odd" ]; then
246+
install_arduino nodebug
247+
build_sketches_with_arduino 2 1 lm6f
237248
elif [ "$BUILD_TYPE" = "platformio" ]; then
238249
# PlatformIO
239250
install_platformio

tests/run_CI_locally.sh

+14-12
Original file line numberDiff line numberDiff line change
@@ -53,25 +53,27 @@ while true; do
5353
cat << EOF
5454
Which build?
5555
1. main
56-
2. debug even
57-
3. debug odd
58-
4. platformio
59-
5. package
60-
6. host
61-
7. style
56+
2. main + IPv6
57+
3. debug even
58+
4. debug odd
59+
5. platformio
60+
6. package
61+
7. host
62+
8. style
6263
EOF
6364

6465
read ans
6566

6667
BUILD_TYPE=""
6768
case "$ans" in
6869
1) BUILD_TYPE=build;;
69-
2) BUILD_TYPE=debug_even;;
70-
3) BUILD_TYPE=debug_odd;;
71-
4) BUILD_TYPE=platformio;;
72-
5) BUILD_TYPE=package;;
73-
6) BUILD_TYPE=host;;
74-
7) BUILD_TYPE=style;;
70+
2) BUILD_TYPE=build6;;
71+
3) BUILD_TYPE=debug_even;;
72+
4) BUILD_TYPE=debug_odd;;
73+
5) BUILD_TYPE=platformio;;
74+
6) BUILD_TYPE=package;;
75+
7) BUILD_TYPE=host;;
76+
8) BUILD_TYPE=style;;
7577
esac
7678
test -z "$BUILD_TYPE" || break
7779
done

tools/build.py

+3
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ def compile(tmp_dir, sketch, tools_dir, hardware_dir, ide_path, f, args):
5050
'FlashMode={flash_mode},' \
5151
'baud=921600,' \
5252
'eesz={flash_size},' \
53+
'ip={lwIP},' \
5354
'ResetMethod=nodemcu'.format(**vars(args))
5455
if args.debug_port and args.debug_level:
5556
cmd += 'dbg={debug_port},lvl={debug_level}'.format(**vars(args))
@@ -85,6 +86,8 @@ def parse_args():
8586
choices=[80, 160], type=int)
8687
parser.add_argument('-m', '--flash_mode', help='Flash mode', default='qio',
8788
choices=['dio', 'qio'])
89+
parser.add_argument('-n', '--lwIP', help='lwIP version', default='lm2f',
90+
choices=['lm2f', 'hb2f', 'lm6f', 'hb6f', 'hb1'])
8891
parser.add_argument('-w', '--warnings', help='Compilation warnings level',
8992
default='none', choices=['none', 'all', 'more'])
9093
parser.add_argument('-o', '--output_binary', help='File name for output binary')

0 commit comments

Comments
 (0)