mirror of
https://github.com/esp8266/Arduino.git
synced 2025-07-27 18:02:17 +03:00
Fixes for IPv6, added in CI (#5557)
This commit is contained in:
@ -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();
|
||||
|
@ -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;
|
||||
@ -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 = ¤t_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;
|
||||
@ -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, "*")) {
|
||||
@ -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);
|
||||
}
|
||||
}
|
||||
|
@ -107,17 +107,14 @@ public:
|
||||
udp_disconnect(_pcb);
|
||||
}
|
||||
|
||||
void setMulticastInterface(const IPAddress& addr)
|
||||
{
|
||||
#if LWIP_VERSION_MAJOR == 1
|
||||
void setMulticastInterface(const ip_addr_t addr)
|
||||
{
|
||||
udp_set_multicast_netif_addr(_pcb, addr);
|
||||
}
|
||||
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)
|
||||
{
|
||||
|
@ -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()););
|
||||
|
||||
|
@ -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));
|
||||
|
||||
|
@ -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));
|
||||
@ -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;
|
||||
@ -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;
|
||||
}
|
||||
}
|
||||
@ -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);
|
||||
}
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user