Skip to content

Fixes for IPv6, added in CI #5557

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 12 commits into from
Dec 27, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,14 @@ jobs:
script: $TRAVIS_BUILD_DIR/tests/common.sh
env:
- BUILD_TYPE=debug_odd
- name: "Build IPv6 (1)"
script: $TRAVIS_BUILD_DIR/tests/common.sh
env:
- BUILD_TYPE=build6_even
- name: "Build IPv6 (2)"
script: $TRAVIS_BUILD_DIR/tests/common.sh
env:
- BUILD_TYPE=build6_odd
- name: "Platformio (1)"
script: $TRAVIS_BUILD_DIR/tests/common.sh
env:
Expand Down
5 changes: 0 additions & 5 deletions cores/esp8266/IPAddress.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -187,11 +187,6 @@ const IPAddress INADDR_NONE(255,255,255,255);

#if LWIP_IPV6

IPAddress::IPAddress(const ip_addr_t* from)
{
ip_addr_copy(_ip, *from);
}

bool IPAddress::fromString6(const char *address) {
// TODO: test test test

Expand Down
5 changes: 3 additions & 2 deletions cores/esp8266/IPAddress.h
Original file line number Diff line number Diff line change
Expand Up @@ -149,8 +149,8 @@ class IPAddress: public Printable {
/*
lwIP address compatibility
*/
IPAddress(const ipv4_addr& fw_addr) { setV4(); v4() = fw_addr.addr; }
IPAddress(const ipv4_addr* fw_addr) { setV4(); v4() = fw_addr->addr; }
IPAddress(const ip_addr_t& lwip_addr) { _ip = lwip_addr; }

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

#if LWIP_IPV6

IPAddress(const ip_addr_t* from);
IPAddress(const ip_addr_t& lwip_addr) { ip_addr_copy(_ip, lwip_addr); }
IPAddress(const ip_addr_t* lwip_addr) { ip_addr_copy(_ip, *lwip_addr); }

uint16_t* raw6()
{
Expand Down
5 changes: 1 addition & 4 deletions libraries/ESP8266AVRISP/src/ESP8266AVRISP.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,10 +74,7 @@ AVRISPState_t ESP8266AVRISP::update() {
if (_server.hasClient()) {
_client = _server.available();
_client.setNoDelay(true);
ip_addr_t lip;
lip.addr = _client.remoteIP();
AVRISP_DEBUG("client connect %d.%d.%d.%d:%d", IP2STR(&lip), _client.remotePort());
(void) lip; // Avoid unused warning when not in debug mode
AVRISP_DEBUG("client connect %s:%d", _client.remoteIP().toString().c_str(), _client.remotePort());
_client.setTimeout(100); // for getch()
_state = AVRISP_STATE_PENDING;
_reject_incoming();
Expand Down
18 changes: 10 additions & 8 deletions libraries/ESP8266NetBIOS/ESP8266NetBIOS.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -154,11 +154,9 @@ bool ESP8266NetBIOS::begin(const char *name)
if(_pcb != NULL) {
return true;
}
ip_addr_t addr;
addr.addr = INADDR_ANY;
_pcb = udp_new();
udp_recv(_pcb, &_s_recv, (void *) this);
err_t err = udp_bind(_pcb, &addr, NBNS_PORT);
err_t err = udp_bind(_pcb, INADDR_ANY, NBNS_PORT);
if(err != ERR_OK) {
end();
return false;
Expand All @@ -182,9 +180,13 @@ void ESP8266NetBIOS::_recv(udp_pcb *upcb, pbuf *pb, CONST ip_addr_t *addr, uint1
while(pb != NULL) {
uint8_t * data = (uint8_t*)((pb)->payload);
size_t len = pb->len;
ip_hdr* iphdr = reinterpret_cast<ip_hdr*>(data - UDP_HLEN - IP_HLEN);
ip_addr_t saddr;
saddr.addr = iphdr->src.addr;
#if LWIP_VERSION_MAJOR == 1
// check UdpContext.h
const ip_addr_t* saddr = &current_iphdr_src;
#else
// check UdpContext.h
const ip_addr_t* saddr = &ip_data.current_iphdr_src;
#endif

if (len >= sizeof(struct NBNSQUESTION)) {
struct NBNSQUESTION * question = (struct NBNSQUESTION *)data;
Expand Down Expand Up @@ -221,7 +223,7 @@ void ESP8266NetBIOS::_recv(udp_pcb *upcb, pbuf *pb, CONST ip_addr_t *addr, uint1
if(pbt != NULL) {
uint8_t* dst = reinterpret_cast<uint8_t*>(pbt->payload);
memcpy(dst, (uint8_t *)&nbnsa, sizeof(nbnsa));
udp_sendto(_pcb, pbt, &saddr, NBNS_PORT);
udp_sendto(_pcb, pbt, saddr, NBNS_PORT);
pbuf_free(pbt);
}
} else if (0 == strcmp(name, "*")) {
Expand Down Expand Up @@ -251,7 +253,7 @@ void ESP8266NetBIOS::_recv(udp_pcb *upcb, pbuf *pb, CONST ip_addr_t *addr, uint1
if(pbt != NULL) {
uint8_t* dst = reinterpret_cast<uint8_t*>(pbt->payload);
memcpy(dst, (uint8_t *)&nbnsan, sizeof(nbnsan));
udp_sendto(_pcb, pbt, &saddr, NBNS_PORT);
udp_sendto(_pcb, pbt, saddr, NBNS_PORT);
pbuf_free(pbt);
}
}
Expand Down
13 changes: 5 additions & 8 deletions libraries/ESP8266WiFi/src/include/UdpContext.h
Original file line number Diff line number Diff line change
Expand Up @@ -107,17 +107,14 @@ class UdpContext
udp_disconnect(_pcb);
}

#if LWIP_VERSION_MAJOR == 1
void setMulticastInterface(const ip_addr_t addr)
void setMulticastInterface(const IPAddress& addr)
{
udp_set_multicast_netif_addr(_pcb, addr);
}
#if LWIP_VERSION_MAJOR == 1
udp_set_multicast_netif_addr(_pcb, (ip_addr_t)addr);
#else
void setMulticastInterface(const ip_addr_t* addr)
{
udp_set_multicast_netif_addr(_pcb, ip_2_ip4(addr));
}
udp_set_multicast_netif_addr(_pcb, ip_2_ip4((const ip_addr_t*)addr));
#endif
}

void setMulticastTTL(int ttl)
{
Expand Down
4 changes: 2 additions & 2 deletions libraries/ESP8266mDNS/src/LEAmDNS_Control.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -244,9 +244,9 @@ bool MDNSResponder::_parseQuery(const MDNSResponder::stcMDNS_MsgHeader& p_MsgHea
ip_info IPInfo_Remote;
if (((IPInfo_Remote.ip.addr = m_pUDPContext->getRemoteAddress())) &&
(((wifi_get_ip_info(SOFTAP_IF, &IPInfo_Local)) &&
(ip_addr_netcmp(&IPInfo_Remote.ip, &IPInfo_Local.ip, &IPInfo_Local.netmask))) || // Remote IP in SOFTAP's subnet OR
(ip4_addr_netcmp(&IPInfo_Remote.ip, &IPInfo_Local.ip, &IPInfo_Local.netmask))) || // Remote IP in SOFTAP's subnet OR
((wifi_get_ip_info(STATION_IF, &IPInfo_Local)) &&
(ip_addr_netcmp(&IPInfo_Remote.ip, &IPInfo_Local.ip, &IPInfo_Local.netmask))))) { // Remote IP in STATION's subnet
(ip4_addr_netcmp(&IPInfo_Remote.ip, &IPInfo_Local.ip, &IPInfo_Local.netmask))))) { // Remote IP in STATION's subnet

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

Expand Down
9 changes: 4 additions & 5 deletions libraries/ESP8266mDNS/src/LEAmDNS_Helpers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -191,19 +191,18 @@ bool MDNSResponder::_allocUDPContext(void) {

_releaseUDPContext();

ip_addr_t multicast_addr;
#ifdef MDNS_IP4_SUPPORT
multicast_addr.addr = DNS_MQUERY_IPV4_GROUP_INIT;
ip_addr_t multicast_addr = DNS_MQUERY_IPV4_GROUP_INIT;
#endif
#ifdef MDNS_IP6_SUPPORT
//TODO: set multicast address
//TODO: set multicast address (lwip_joingroup() is IPv4 only at the time of writing)
multicast_addr.addr = DNS_MQUERY_IPV6_GROUP_INIT;
#endif
if (ERR_OK == igmp_joingroup(IP_ADDR_ANY, &multicast_addr)) {
if (ERR_OK == igmp_joingroup(IP4_ADDR_ANY4, ip_2_ip4(&multicast_addr))) {
m_pUDPContext = new UdpContext;
m_pUDPContext->ref();

if (m_pUDPContext->listen(IP_ADDR_ANY, DNS_MQUERY_PORT)) {
if (m_pUDPContext->listen(IP4_ADDR_ANY, DNS_MQUERY_PORT)) {
m_pUDPContext->setMulticastTTL(MDNS_MULTICAST_TTL);
m_pUDPContext->onRx(std::bind(&MDNSResponder::_callProcess, this));

Expand Down
36 changes: 15 additions & 21 deletions libraries/ESP8266mDNS/src/LEAmDNS_Transfer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,10 +79,10 @@ bool MDNSResponder::_sendMDNSMessage(MDNSResponder::stcMDNSSendParameter& p_rSen
if (p_rSendParameter.m_bResponse) {
if (p_rSendParameter.m_bUnicast) { // Unicast response -> Send to querier
DEBUG_EX_ERR(if (!m_pUDPContext->getRemoteAddress()) { DEBUG_OUTPUT.printf_P(PSTR("[MDNSResponder] _sendMDNSMessage: MISSING remote address for response!\n")); });
ip_addr_t ipRemote;
ipRemote.addr = m_pUDPContext->getRemoteAddress();
IPAddress ipRemote;
ipRemote = m_pUDPContext->getRemoteAddress();
bResult = ((_prepareMDNSMessage(p_rSendParameter, _getResponseMulticastInterface(SOFTAP_MODE | STATION_MODE))) &&
(m_pUDPContext->send(&ipRemote, m_pUDPContext->getRemotePort())));
(m_pUDPContext->send(ipRemote, m_pUDPContext->getRemotePort())));
}
else { // Multicast response -> Send via the same network interface, that received the query
bResult = _sendMDNSMessage_Multicast(p_rSendParameter, (SOFTAP_MODE | STATION_MODE));
Expand Down Expand Up @@ -116,26 +116,20 @@ bool MDNSResponder::_sendMDNSMessage_Multicast(MDNSResponder::stcMDNSSendParamet
int p_iWiFiOpMode) {
bool bResult = false;

ip_addr_t ifFromAddress;
ifFromAddress.addr = _getResponseMulticastInterface(p_iWiFiOpMode);
IPAddress fromIPAddress(ifFromAddress.addr);
#if LWIP_VERSION_MAJOR == 1
m_pUDPContext->setMulticastInterface(ifFromAddress);
#else
m_pUDPContext->setMulticastInterface(&ifFromAddress);
#endif
IPAddress fromIPAddress;
fromIPAddress = _getResponseMulticastInterface(p_iWiFiOpMode);
m_pUDPContext->setMulticastInterface(fromIPAddress);

ip_addr_t toMulticastAddress;
#ifdef MDNS_IP4_SUPPORT
toMulticastAddress.addr = DNS_MQUERY_IPV4_GROUP_INIT;
IPAddress toMulticastAddress(DNS_MQUERY_IPV4_GROUP_INIT);
#endif
#ifdef MDNS_IP6_SUPPORT
//TODO: set multicast address
toMulticastAddress.addr = DNS_MQUERY_IPV6_GROUP_INIT;
IPAddress toMulticastAddress(DNS_MQUERY_IPV6_GROUP_INIT);
#endif
DEBUG_EX_INFO(DEBUG_OUTPUT.printf_P(PSTR("[MDNSResponder] _sendMDNSMessage_Multicast: Will send to '%s'.\n"), IPAddress(toMulticastAddress.addr).toString().c_str()););
DEBUG_EX_INFO(DEBUG_OUTPUT.printf_P(PSTR("[MDNSResponder] _sendMDNSMessage_Multicast: Will send to '%s'.\n"), toMulticastAddress.toString().c_str()););
bResult = ((_prepareMDNSMessage(p_rSendParameter, fromIPAddress)) &&
(m_pUDPContext->send(&toMulticastAddress, DNS_MQUERY_PORT)));
(m_pUDPContext->send(toMulticastAddress, DNS_MQUERY_PORT)));

DEBUG_EX_ERR(if (!bResult) { DEBUG_OUTPUT.printf_P(PSTR("[MDNSResponder] _sendMDNSMessage_Multicast: FAILED!\n")); });
return bResult;
Expand Down Expand Up @@ -385,13 +379,13 @@ IPAddress MDNSResponder::_getResponseMulticastInterface(int p_iWiFiOpModes) cons
(wifi_get_opmode() & SOFTAP_MODE)) {
//DEBUG_EX_INFO(DEBUG_OUTPUT.printf_P(PSTR("[MDNSResponder] _getResponseMulticastInterface: SOFTAP_MODE\n")););
// Get remote IP address
ip_info IPInfo_Remote;
IPInfo_Remote.ip.addr = m_pUDPContext->getRemoteAddress();
IPAddress IP_Remote;
IP_Remote = m_pUDPContext->getRemoteAddress();
// Get local (AP) IP address
wifi_get_ip_info(SOFTAP_IF, &IPInfo_Local);

if ((IPInfo_Local.ip.addr) && // Has local AP IP address AND
(ip_addr_netcmp(&IPInfo_Remote.ip, &IPInfo_Local.ip, &IPInfo_Local.netmask))) { // Remote address is in the same subnet as the AP
(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
bFoundMatch = true;
}
}
Expand All @@ -402,8 +396,8 @@ IPAddress MDNSResponder::_getResponseMulticastInterface(int p_iWiFiOpModes) cons
// Get local (STATION) IP address
wifi_get_ip_info(STATION_IF, &IPInfo_Local);
}
//DEBUG_EX_INFO(DEBUG_OUTPUT.printf_P(PSTR("[MDNSResponder] _getResponseMulticastInterface(%i): %s\n"), p_iWiFiOpModes, IPAddress(IPInfo_Local.ip.addr).toString().c_str()););
return IPAddress(IPInfo_Local.ip.addr);
//DEBUG_EX_INFO(DEBUG_OUTPUT.printf_P(PSTR("[MDNSResponder] _getResponseMulticastInterface(%i): %s\n"), p_iWiFiOpModes, IPAddress(IPInfo_Local.ip).toString().c_str()););
return IPAddress(IPInfo_Local.ip);
}


Expand Down
29 changes: 20 additions & 9 deletions tests/common.sh
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,9 @@ function build_sketches()
local build_dir=build.tmp
local build_mod=$4
local build_rem=$5
local lwip=$6
mkdir -p $build_dir
local build_cmd="python tools/build.py -b generic -v -w all -s 4M1M -v -k -p $PWD/$build_dir $build_arg "
local build_cmd="python tools/build.py -b generic -v -w all -s 4M1M -v -k -p $PWD/$build_dir -n $lwip $build_arg "
local sketches=$(find $srcpath -name *.ino | sort)
print_size_info >size.log
export ARDUINO_IDE_PATH=$arduino
Expand Down Expand Up @@ -116,8 +117,8 @@ function install_ide()
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"
fi
# Set custom warnings for all builds (i.e. could add -Wextra at some point)
echo "compiler.c.extra_flags=-Wall -Wextra -Werror -DLWIP_IPV6=0 $debug_flags" > esp8266/platform.local.txt
echo "compiler.cpp.extra_flags=-Wall -Wextra -Werror -DLWIP_IPV6=0 $debug_flags" >> esp8266/platform.local.txt
echo "compiler.c.extra_flags=-Wall -Wextra -Werror $debug_flags" > esp8266/platform.local.txt
echo "compiler.cpp.extra_flags=-Wall -Wextra -Werror $debug_flags" >> esp8266/platform.local.txt
echo -e "\n----platform.local.txt----"
cat esp8266/platform.local.txt
echo -e "\n----\n"
Expand Down Expand Up @@ -196,10 +197,11 @@ function build_sketches_with_arduino()
{
local build_mod=$1
local build_rem=$2
local lwip=$3

# Compile sketches
echo -e "travis_fold:start:sketch_test"
build_sketches $HOME/arduino_ide $TRAVIS_BUILD_DIR/libraries "-l $HOME/Arduino/libraries" $1 $2
build_sketches $HOME/arduino_ide $TRAVIS_BUILD_DIR/libraries "-l $HOME/Arduino/libraries" $build_mod $build_rem $lwip
echo -e "travis_fold:end:sketch_test"

# Generate size report
Expand All @@ -221,19 +223,28 @@ fi

if [ "$BUILD_TYPE" = "build" ]; then
install_arduino nodebug
build_sketches_with_arduino 1 0
build_sketches_with_arduino 1 0 lm2f
elif [ "$BUILD_TYPE" = "build6" ]; then
install_arduino nodebug
build_sketches_with_arduino 1 0 lm6f
elif [ "$BUILD_TYPE" = "build_even" ]; then
install_arduino nodebug
build_sketches_with_arduino 2 0
build_sketches_with_arduino 2 0 lm2f
elif [ "$BUILD_TYPE" = "build_odd" ]; then
install_arduino nodebug
build_sketches_with_arduino 2 1
build_sketches_with_arduino 2 1 lm2f
elif [ "$BUILD_TYPE" = "debug_even" ]; then
install_arduino debug
build_sketches_with_arduino 2 0
build_sketches_with_arduino 2 0 lm2f
elif [ "$BUILD_TYPE" = "debug_odd" ]; then
install_arduino debug
build_sketches_with_arduino 2 1
build_sketches_with_arduino 2 1 lm2f
elif [ "$BUILD_TYPE" = "build6_even" ]; then
install_arduino nodebug
build_sketches_with_arduino 2 0 lm6f
elif [ "$BUILD_TYPE" = "build6_odd" ]; then
install_arduino nodebug
build_sketches_with_arduino 2 1 lm6f
elif [ "$BUILD_TYPE" = "platformio" ]; then
# PlatformIO
install_platformio
Expand Down
26 changes: 14 additions & 12 deletions tests/run_CI_locally.sh
Original file line number Diff line number Diff line change
Expand Up @@ -53,25 +53,27 @@ while true; do
cat << EOF
Which build?
1. main
2. debug even
3. debug odd
4. platformio
5. package
6. host
7. style
2. main + IPv6
3. debug even
4. debug odd
5. platformio
6. package
7. host
8. style
EOF

read ans

BUILD_TYPE=""
case "$ans" in
1) BUILD_TYPE=build;;
2) BUILD_TYPE=debug_even;;
3) BUILD_TYPE=debug_odd;;
4) BUILD_TYPE=platformio;;
5) BUILD_TYPE=package;;
6) BUILD_TYPE=host;;
7) BUILD_TYPE=style;;
2) BUILD_TYPE=build6;;
3) BUILD_TYPE=debug_even;;
4) BUILD_TYPE=debug_odd;;
5) BUILD_TYPE=platformio;;
6) BUILD_TYPE=package;;
7) BUILD_TYPE=host;;
8) BUILD_TYPE=style;;
esac
test -z "$BUILD_TYPE" || break
done
Expand Down
3 changes: 3 additions & 0 deletions tools/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ def compile(tmp_dir, sketch, tools_dir, hardware_dir, ide_path, f, args):
'FlashMode={flash_mode},' \
'baud=921600,' \
'eesz={flash_size},' \
'ip={lwIP},' \
'ResetMethod=nodemcu'.format(**vars(args))
if args.debug_port and args.debug_level:
cmd += 'dbg={debug_port},lvl={debug_level}'.format(**vars(args))
Expand Down Expand Up @@ -85,6 +86,8 @@ def parse_args():
choices=[80, 160], type=int)
parser.add_argument('-m', '--flash_mode', help='Flash mode', default='qio',
choices=['dio', 'qio'])
parser.add_argument('-n', '--lwIP', help='lwIP version', default='lm2f',
choices=['lm2f', 'hb2f', 'lm6f', 'hb6f', 'hb1'])
parser.add_argument('-w', '--warnings', help='Compilation warnings level',
default='none', choices=['none', 'all', 'more'])
parser.add_argument('-o', '--output_binary', help='File name for output binary')
Expand Down