Skip to content

Commit 8c0c989

Browse files
wqx6suren-gabrielyan-espressif
authored andcommitted
fix(mdns): define CONFIG_LWIP_IPV4 in mdns_private.h if it is not defined for IDF v5.0
1 parent 562987d commit 8c0c989

File tree

12 files changed

+197
-194
lines changed

12 files changed

+197
-194
lines changed

.github/workflows/mdns__build-target-test.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,10 +71,12 @@ jobs:
7171
- name: Run ${{ matrix.test.app }} application on ${{ matrix.idf_target }}
7272
working-directory: components/mdns/${{ matrix.test.path }}
7373
run: |
74+
pip install dpkt
7475
unzip ci/artifacts.zip -d ci
7576
for dir in `ls -d ci/build_*`; do
7677
rm -rf build sdkconfig.defaults
7778
mv $dir build
79+
cat build/config/sdkconfig.h
7880
python -m pytest --log-cli-level DEBUG --junit-xml=./results_${{ matrix.test.app }}_${{ matrix.idf_target }}_${{ matrix.idf_ver }}_${dir#"ci/build_"}.xml --target=${{ matrix.idf_target }}
7981
done
8082
- uses: actions/upload-artifact@v3

components/mdns/Kconfig

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -77,20 +77,6 @@ menu "mDNS"
7777
Configures period of mDNS timer, which periodically transmits packets
7878
and schedules mDNS searches.
7979

80-
config MDNS_IPV4
81-
bool "Enable IPv4 for mDNS"
82-
default y
83-
select LWIP_IPV4
84-
help
85-
Enable IPv4 for mDNS
86-
87-
config MDNS_IPV6
88-
bool "Enable IPv6 for mDNS"
89-
default y
90-
select LWIP_IPV6
91-
help
92-
Enable IPv6 for mDNS
93-
9480
config MDNS_NETWORKING_SOCKET
9581
bool "Use BSD sockets for mDNS networking"
9682
default n

components/mdns/examples/query_advertise/main/mdns_example_main.c

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,12 @@
2121
#include "driver/gpio.h"
2222
#include "netdb.h"
2323

24+
#if ESP_IDF_VERSION < ESP_IDF_VERSION_VAL(5, 1, 0)
25+
/* CONFIG_LWIP_IPV4 was introduced in IDF v5.1, set CONFIG_LWIP_IPV4 to 1 by default for IDF v5.0 */
26+
#ifndef CONFIG_LWIP_IPV4
27+
#define CONFIG_LWIP_IPV4 1
28+
#endif // CONFIG_LWIP_IPV4
29+
#endif // ESP_IDF_VERSION < ESP_IDF_VERSION_VAL(5, 1, 0)
2430

2531
#define EXAMPLE_MDNS_INSTANCE CONFIG_MDNS_INSTANCE
2632
#define EXAMPLE_BUTTON_GPIO CONFIG_MDNS_BUTTON_GPIO
@@ -227,7 +233,7 @@ static void query_mdns_hosts_async(const char *host_name)
227233
vTaskDelay(50 / portTICK_PERIOD_MS);
228234
}
229235
}
230-
236+
#ifdef CONFIG_LWIP_IPV4
231237
static void query_mdns_host(const char *host_name)
232238
{
233239
ESP_LOGI(TAG, "Query A: %s.local", host_name);
@@ -247,6 +253,7 @@ static void query_mdns_host(const char *host_name)
247253

248254
ESP_LOGI(TAG, "Query A: %s.local resolved to: " IPSTR, host_name, IP2STR(&addr));
249255
}
256+
#endif // CONFIG_LWIP_IPV4
250257

251258
static void initialise_button(void)
252259
{
@@ -265,7 +272,9 @@ static void check_button(void)
265272
bool new_level = gpio_get_level(EXAMPLE_BUTTON_GPIO);
266273
if (!new_level && old_level) {
267274
query_mdns_hosts_async("esp32-mdns");
275+
#ifdef CONFIG_LWIP_IPV4
268276
query_mdns_host("esp32");
277+
#endif
269278
query_mdns_service("_arduino", "_tcp");
270279
query_mdns_service("_http", "_tcp");
271280
query_mdns_service("_printer", "_tcp");
@@ -286,7 +295,9 @@ static void mdns_example_task(void *pvParameters)
286295
{
287296
#if CONFIG_MDNS_RESOLVE_TEST_SERVICES == 1
288297
/* Send initial queries that are started by CI tester */
298+
#ifdef CONFIG_LWIP_IPV4
289299
query_mdns_host("tinytester");
300+
#endif
290301
query_mdns_host_with_gethostbyname("tinytester-lwip.local");
291302
query_mdns_host_with_getaddrinfo("tinytester-lwip.local");
292303
#endif
@@ -363,10 +374,10 @@ static void query_mdns_host_with_gethostbyname(char *host)
363374
unsigned int i = 0;
364375
while (res->h_addr_list[i] != NULL) {
365376
ESP_LOGI(TAG, "gethostbyname: %s resolved to: %s", host,
366-
#if LWIP_IPV6 && LWIP_IPV4
377+
#if defined(CONFIG_LWIP_IPV6) && defined(CONFIG_LWIP_IPV4)
367378
res->h_addrtype == AF_INET ? inet_ntoa(*(struct in_addr *) (res->h_addr_list[i])) :
368379
inet6_ntoa(*(struct in6_addr *) (res->h_addr_list[i]))
369-
#elif LWIP_IPV6
380+
#elif defined(CONFIG_LWIP_IPV6)
370381
inet6_ntoa(*(struct in6_addr *) (res->h_addr_list[i]))
371382
#else
372383
inet_ntoa(*(struct in_addr *) (res->h_addr_list[i]))
@@ -393,11 +404,11 @@ static void query_mdns_host_with_getaddrinfo(char *host)
393404
if (!getaddrinfo(host, NULL, &hints, &res)) {
394405
while (res) {
395406
char *resolved_addr;
396-
#if LWIP_IPV6 && LWIP_IPV4
407+
#if defined(CONFIG_LWIP_IPV6) && defined(CONFIG_LWIP_IPV4)
397408
resolved_addr = res->ai_family == AF_INET ?
398409
inet_ntoa(((struct sockaddr_in *) res->ai_addr)->sin_addr) :
399410
inet6_ntoa(((struct sockaddr_in6 *) res->ai_addr)->sin6_addr);
400-
#elif LWIP_IPV6
411+
#elif defined(CONFIG_LWIP_IPV6)
401412
resolved_addr = inet6_ntoa(((struct sockaddr_in6 *) res->ai_addr)->sin6_addr);
402413
#else
403414
resolved_addr = inet_ntoa(((struct sockaddr_in *) res->ai_addr)->sin_addr);

components/mdns/examples/query_advertise/pytest_mdns.py

Lines changed: 76 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -87,26 +87,30 @@ def mdns_server(esp_host, events):
8787
continue
8888
data, addr = sock.recvfrom(1024)
8989
dns = dpkt.dns.DNS(data)
90-
if len(dns.qd) > 0 and dns.qd[0].type == dpkt.dns.DNS_A:
91-
if dns.qd[0].name == TESTER_NAME:
92-
print('Received query: {} '.format(dns.__repr__()))
93-
sock.sendto(get_dns_answer_to_mdns(TESTER_NAME),
94-
(MCAST_GRP, UDP_PORT))
95-
elif dns.qd[0].name == TESTER_NAME_LWIP:
96-
print('Received query: {} '.format(dns.__repr__()))
97-
sock.sendto(
98-
get_dns_answer_to_mdns_lwip(TESTER_NAME_LWIP, dns.id),
99-
addr)
100-
if len(dns.an) > 0 and dns.an[0].type == dpkt.dns.DNS_A:
101-
print('Received answer from {}'.format(dns.an[0].name))
102-
if dns.an[0].name == esp_host + u'.local':
103-
print('Received answer to esp32-mdns query: {}'.format(
104-
dns.__repr__()))
105-
events['esp_answered'].set()
106-
if dns.an[0].name == esp_host + u'-delegated.local':
107-
print('Received answer to esp32-mdns-delegate query: {}'.
108-
format(dns.__repr__()))
109-
events['esp_delegated_answered'].set()
90+
if len(dns.qd) > 0:
91+
for dns_query in dns.qd:
92+
if dns_query.type == dpkt.dns.DNS_A:
93+
if dns_query.name == TESTER_NAME:
94+
print('Received query: {} '.format(dns.__repr__()))
95+
sock.sendto(get_dns_answer_to_mdns(TESTER_NAME),
96+
(MCAST_GRP, UDP_PORT))
97+
elif dns_query.name == TESTER_NAME_LWIP:
98+
print('Received query: {} '.format(dns.__repr__()))
99+
sock.sendto(
100+
get_dns_answer_to_mdns_lwip(TESTER_NAME_LWIP, dns.id),
101+
addr)
102+
if len(dns.an) > 0:
103+
for dns_answer in dns.an:
104+
if dns_answer.type == dpkt.dns.DNS_A:
105+
print('Received answer from {}'.format(dns_answer.name))
106+
if dns_answer.name == esp_host + u'.local':
107+
print('Received answer to esp32-mdns query: {}'.format(
108+
dns.__repr__()))
109+
events['esp_answered'].set()
110+
if dns_answer.name == esp_host + u'-delegated.local':
111+
print('Received answer to esp32-mdns-delegate query: {}'.format(
112+
dns.__repr__()))
113+
events['esp_delegated_answered'].set()
110114
except socket.timeout:
111115
break
112116
except dpkt.UnpackError:
@@ -133,62 +137,66 @@ def test_examples_protocol_mdns(dut):
133137
}
134138
mdns_responder = Thread(target=mdns_server,
135139
args=(str(specific_host), mdns_server_events))
136-
ipv4 = dut.expect(r'IPv4 address: (\d+\.\d+\.\d+\.\d+)[^\d]',
137-
timeout=30)[1].decode()
138-
ip_addresses = [ipv4]
140+
ip_addresses = []
141+
if dut.app.sdkconfig.get('LWIP_IPV4') is True:
142+
ipv4 = dut.expect(r'IPv4 address: (\d+\.\d+\.\d+\.\d+)[^\d]',
143+
timeout=30)[1].decode()
144+
ip_addresses.append(ipv4)
139145
if dut.app.sdkconfig.get('LWIP_IPV6') is True:
140146
ipv6_r = r':'.join((r'[0-9a-fA-F]{4}', ) * 8)
141147
ipv6 = dut.expect(ipv6_r, timeout=30)[0].decode()
142148
ip_addresses.append(ipv6)
143149
print('Connected with IP addresses: {}'.format(','.join(ip_addresses)))
144150
try:
145-
# 3. check the mdns name is accessible.
151+
# TODO: Add test for example disabling IPV4
146152
mdns_responder.start()
147-
if not mdns_server_events['esp_answered'].wait(timeout=30):
148-
raise ValueError(
149-
'Test has failed: did not receive mdns answer within timeout')
150-
if not mdns_server_events['esp_delegated_answered'].wait(timeout=30):
151-
raise ValueError(
152-
'Test has failed: did not receive mdns answer for delegated host within timeout'
153+
if dut.app.sdkconfig.get('LWIP_IPV4') is True:
154+
# 3. check the mdns name is accessible.
155+
if not mdns_server_events['esp_answered'].wait(timeout=30):
156+
raise ValueError(
157+
'Test has failed: did not receive mdns answer within timeout')
158+
if not mdns_server_events['esp_delegated_answered'].wait(timeout=30):
159+
raise ValueError(
160+
'Test has failed: did not receive mdns answer for delegated host within timeout'
161+
)
162+
# 4. check DUT output if mdns advertized host is resolved
163+
dut.expect(
164+
re.compile(
165+
b'mdns-test: Query A: tinytester.local resolved to: 127.0.0.1')
153166
)
154-
# 4. check DUT output if mdns advertized host is resolved
155-
dut.expect(
156-
re.compile(
157-
b'mdns-test: Query A: tinytester.local resolved to: 127.0.0.1')
158-
)
159-
dut.expect(
160-
re.compile(
161-
b'mdns-test: gethostbyname: tinytester-lwip.local resolved to: 127.0.0.1'
162-
))
163-
dut.expect(
164-
re.compile(
165-
b'mdns-test: getaddrinfo: tinytester-lwip.local resolved to: 127.0.0.1'
166-
))
167-
# 5. check the DUT answers to `dig` command
168-
dig_output = subprocess.check_output([
169-
'dig', '+short', '-p', '5353', '@224.0.0.251',
170-
'{}.local'.format(specific_host)
171-
])
172-
print('Resolving {} using "dig" succeeded with:\n{}'.format(
173-
specific_host, dig_output))
174-
if not ipv4.encode('utf-8') in dig_output:
175-
raise ValueError(
176-
'Test has failed: Incorrectly resolved DUT hostname using dig'
177-
"Output should've contained DUT's IP address:{}".format(ipv4))
178-
# 6. check the DUT reverse lookup
179-
if dut.app.sdkconfig.get('MDNS_RESPOND_REVERSE_QUERIES') is True:
180-
for ip_address in ip_addresses:
181-
dig_output = subprocess.check_output([
182-
'dig', '+short', '-p', '5353', '@224.0.0.251', '-x',
183-
'{}'.format(ip_address)
184-
])
185-
print('Reverse lookup for {} using "dig" succeeded with:\n{}'.
186-
format(ip_address, dig_output))
187-
if specific_host not in dig_output.decode():
188-
raise ValueError(
189-
'Test has failed: Incorrectly resolved DUT IP address using dig'
190-
"Output should've contained DUT's name:{}".format(
191-
specific_host))
167+
dut.expect(
168+
re.compile(
169+
b'mdns-test: gethostbyname: tinytester-lwip.local resolved to: 127.0.0.1'
170+
))
171+
dut.expect(
172+
re.compile(
173+
b'mdns-test: getaddrinfo: tinytester-lwip.local resolved to: 127.0.0.1'
174+
))
175+
# 5. check the DUT answers to `dig` command
176+
dig_output = subprocess.check_output([
177+
'dig', '+short', '-p', '5353', '@224.0.0.251',
178+
'{}.local'.format(specific_host)
179+
])
180+
print('Resolving {} using "dig" succeeded with:\n{}'.format(
181+
specific_host, dig_output))
182+
if not ipv4.encode('utf-8') in dig_output:
183+
raise ValueError(
184+
'Test has failed: Incorrectly resolved DUT hostname using dig'
185+
"Output should've contained DUT's IP address:{}".format(ipv4))
186+
# 6. check the DUT reverse lookup
187+
if dut.app.sdkconfig.get('MDNS_RESPOND_REVERSE_QUERIES') is True:
188+
for ip_address in ip_addresses:
189+
dig_output = subprocess.check_output([
190+
'dig', '+short', '-p', '5353', '@224.0.0.251', '-x',
191+
'{}'.format(ip_address)
192+
])
193+
print('Reverse lookup for {} using "dig" succeeded with:\n{}'.
194+
format(ip_address, dig_output))
195+
if specific_host not in dig_output.decode():
196+
raise ValueError(
197+
'Test has failed: Incorrectly resolved DUT IP address using dig'
198+
"Output should've contained DUT's name:{}".format(
199+
specific_host))
192200

193201
finally:
194202
mdns_server_events['stop'].set()

components/mdns/examples/query_advertise/sdkconfig.ci.eth_no_ipv4

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ CONFIG_IDF_TARGET="esp32"
22
CONFIG_MDNS_RESOLVE_TEST_SERVICES=y
33
CONFIG_MDNS_ADD_MAC_TO_HOSTNAME=y
44
CONFIG_MDNS_PUBLISH_DELEGATE_HOST=y
5-
CONFIG_MDNS_IPV4=n
65
CONFIG_LWIP_DNS_SUPPORT_MDNS_QUERIES=y
76
CONFIG_LWIP_IPV4=n
87
CONFIG_EXAMPLE_CONNECT_ETHERNET=y

components/mdns/examples/query_advertise/sdkconfig.ci.eth_no_ipv6

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ CONFIG_IDF_TARGET="esp32"
22
CONFIG_MDNS_RESOLVE_TEST_SERVICES=y
33
CONFIG_MDNS_ADD_MAC_TO_HOSTNAME=y
44
CONFIG_MDNS_PUBLISH_DELEGATE_HOST=y
5-
CONFIG_MDNS_IPV6=n
65
CONFIG_LWIP_DNS_SUPPORT_MDNS_QUERIES=y
76
CONFIG_LWIP_IPV6=n
87
CONFIG_EXAMPLE_CONNECT_IPV6=n

0 commit comments

Comments
 (0)