17
17
#include "mdns_networking.h"
18
18
#include "esp_log.h"
19
19
#include "esp_random.h"
20
+ #include "lwip/opt.h"
20
21
21
22
#if CONFIG_ETH_ENABLED && CONFIG_MDNS_PREDEF_NETIF_ETH
22
23
#include "esp_eth.h"
@@ -185,7 +186,7 @@ static inline void _mdns_clean_netif_ptr(mdns_if_t tcpip_if)
185
186
static mdns_if_t _mdns_get_if_from_esp_netif (esp_netif_t * esp_netif )
186
187
{
187
188
for (int i = 0 ; i < MDNS_MAX_INTERFACES ; ++ i ) {
188
- if (esp_netif == s_esp_netifs [i ].netif ) {
189
+ if (esp_netif == s_esp_netifs [i ].netif || ( s_esp_netifs [ i ]. predefined && esp_netif == esp_netif_from_preset_if ( s_esp_netifs [ i ]. predef_if )) ) {
189
190
return i ;
190
191
}
191
192
}
@@ -1361,7 +1362,9 @@ static uint8_t _mdns_append_answer(uint8_t *packet, uint16_t *index, mdns_out_an
1361
1362
return _mdns_append_txt_record (packet , index , answer -> service , answer -> flush , answer -> bye ) > 0 ;
1362
1363
} else if (answer -> type == MDNS_TYPE_SDPTR ) {
1363
1364
return _mdns_append_sdptr_record (packet , index , answer -> service , answer -> flush , answer -> bye ) > 0 ;
1364
- } else if (answer -> type == MDNS_TYPE_A ) {
1365
+ }
1366
+ #if LWIP_IPV4
1367
+ else if (answer -> type == MDNS_TYPE_A ) {
1365
1368
if (answer -> host == & _mdns_self_host ) {
1366
1369
esp_netif_ip_info_t if_ip_info ;
1367
1370
if (!mdns_is_netif_ready (tcpip_if , MDNS_IP_PROTOCOL_V4 ) && _mdns_server -> interfaces [tcpip_if ].pcbs [MDNS_IP_PROTOCOL_V4 ].state != PCB_DUP ) {
@@ -1388,7 +1391,8 @@ static uint8_t _mdns_append_answer(uint8_t *packet, uint16_t *index, mdns_out_an
1388
1391
return _mdns_append_host_answer (packet , index , answer -> host , ESP_IPADDR_TYPE_V4 , answer -> flush , answer -> bye );
1389
1392
}
1390
1393
}
1391
- #if CONFIG_LWIP_IPV6
1394
+ #endif /* LWIP_IPV4 */
1395
+ #if LWIP_IPV6
1392
1396
else if (answer -> type == MDNS_TYPE_AAAA ) {
1393
1397
if (answer -> host == & _mdns_self_host ) {
1394
1398
struct esp_ip6_addr if_ip6s [NETIF_IPV6_MAX_NUMS ];
@@ -1426,7 +1430,7 @@ static uint8_t _mdns_append_answer(uint8_t *packet, uint16_t *index, mdns_out_an
1426
1430
answer -> bye );
1427
1431
}
1428
1432
}
1429
- #endif
1433
+ #endif /* LWIP_IPV6 */
1430
1434
return 0 ;
1431
1435
}
1432
1436
@@ -2878,6 +2882,7 @@ static void _mdns_dup_interface(mdns_if_t tcpip_if)
2878
2882
}
2879
2883
}
2880
2884
2885
+ #if LWIP_IPV4
2881
2886
/**
2882
2887
* @brief Detect IPv4 address collision
2883
2888
*/
@@ -2891,7 +2896,6 @@ static int _mdns_check_a_collision(esp_ip4_addr_t *ip, mdns_if_t tcpip_if)
2891
2896
if (esp_netif_get_ip_info (_mdns_get_esp_netif (tcpip_if ), & if_ip_info )) {
2892
2897
return 1 ;//they win
2893
2898
}
2894
-
2895
2899
int ret = memcmp ((uint8_t * )& if_ip_info .ip .addr , (uint8_t * )& ip -> addr , sizeof (esp_ip4_addr_t ));
2896
2900
if (ret > 0 ) {
2897
2901
return -1 ;//we win
@@ -2912,8 +2916,9 @@ static int _mdns_check_a_collision(esp_ip4_addr_t *ip, mdns_if_t tcpip_if)
2912
2916
}
2913
2917
return 0 ;//same
2914
2918
}
2919
+ #endif // LWIP_IPV4
2915
2920
2916
- #if CONFIG_LWIP_IPV6
2921
+ #if LWIP_IPV6
2917
2922
/**
2918
2923
* @brief Detect IPv6 address collision
2919
2924
*/
@@ -2947,7 +2952,7 @@ static int _mdns_check_aaaa_collision(esp_ip6_addr_t *ip, mdns_if_t tcpip_if)
2947
2952
}
2948
2953
return 0 ;//same
2949
2954
}
2950
- #endif
2955
+ #endif /* LWIP_IPV6 */
2951
2956
2952
2957
static bool _hostname_is_ours (const char * hostname )
2953
2958
{
@@ -3510,22 +3515,28 @@ void mdns_parse_packet(mdns_rx_packet_t *packet)
3510
3515
3511
3516
#ifndef CONFIG_MDNS_SKIP_SUPPRESSING_OWN_QUERIES
3512
3517
// Check if the packet wasn't sent by us
3518
+ #if LWIP_IPV4
3513
3519
if (packet -> ip_protocol == MDNS_IP_PROTOCOL_V4 ) {
3514
3520
esp_netif_ip_info_t if_ip_info ;
3515
3521
if (esp_netif_get_ip_info (_mdns_get_esp_netif (packet -> tcpip_if ), & if_ip_info ) == ESP_OK &&
3516
3522
memcmp (& if_ip_info .ip .addr , & packet -> src .u_addr .ip4 .addr , sizeof (esp_ip4_addr_t )) == 0 ) {
3517
3523
return ;
3518
3524
}
3519
- #if CONFIG_LWIP_IPV6
3520
- } else {
3521
- struct esp_ip6_addr if_ip6 ;
3522
- if (esp_netif_get_ip6_linklocal (_mdns_get_esp_netif (packet -> tcpip_if ), & if_ip6 ) == ESP_OK &&
3523
- memcmp (& if_ip6 , & packet -> src .u_addr .ip6 , sizeof (esp_ip6_addr_t )) == 0 ) {
3524
- return ;
3525
- }
3526
- #endif
3527
3525
}
3526
+ #endif // LWIP_IPV4
3527
+ #if LWIP_IPV4 && LWIP_IPV6
3528
+ else
3528
3529
#endif
3530
+ #if LWIP_IPV6
3531
+ if (packet -> ip_protocol == MDNS_IP_PROTOCOL_V6 ) {
3532
+ struct esp_ip6_addr if_ip6 ;
3533
+ if (esp_netif_get_ip6_linklocal (_mdns_get_esp_netif (packet -> tcpip_if ), & if_ip6 ) == ESP_OK &&
3534
+ memcmp (& if_ip6 , & packet -> src .u_addr .ip6 , sizeof (esp_ip6_addr_t )) == 0 ) {
3535
+ return ;
3536
+ }
3537
+ }
3538
+ #endif // LWIP_IPV6
3539
+ #endif // CONFIG_MDNS_SKIP_SUPPRESSING_OWN_QUERIES
3529
3540
3530
3541
// Check for the minimum size of mdns packet
3531
3542
if (len <= MDNS_HEAD_ADDITIONAL_OFFSET ) {
@@ -3888,7 +3899,7 @@ void mdns_parse_packet(mdns_rx_packet_t *packet)
3888
3899
}
3889
3900
3890
3901
}
3891
- #if CONFIG_LWIP_IPV6
3902
+ #if LWIP_IPV6
3892
3903
else if (type == MDNS_TYPE_AAAA ) {//ipv6
3893
3904
esp_ip_addr_t ip6 ;
3894
3905
ip6 .type = ESP_IPADDR_TYPE_V6 ;
@@ -3941,7 +3952,8 @@ void mdns_parse_packet(mdns_rx_packet_t *packet)
3941
3952
}
3942
3953
3943
3954
}
3944
- #endif
3955
+ #endif /* LWIP_IPV6 */
3956
+ #if LWIP_IPV4
3945
3957
else if (type == MDNS_TYPE_A ) {
3946
3958
esp_ip_addr_t ip ;
3947
3959
ip .type = ESP_IPADDR_TYPE_V4 ;
@@ -3994,6 +4006,7 @@ void mdns_parse_packet(mdns_rx_packet_t *packet)
3994
4006
}
3995
4007
3996
4008
}
4009
+ #endif /* LWIP_IPV4 */
3997
4010
}
3998
4011
//end while
3999
4012
if (parsed_packet -> authoritative ) {
@@ -4095,6 +4108,7 @@ static void perform_event_action(mdns_if_t mdns_if, mdns_event_actions_t action)
4095
4108
}
4096
4109
4097
4110
#ifdef CONFIG_MDNS_RESPOND_REVERSE_QUERIES
4111
+ #if LWIP_IPV4
4098
4112
if (action & MDNS_EVENT_IP4_REVERSE_LOOKUP ) {
4099
4113
esp_netif_ip_info_t if_ip_info ;
4100
4114
if (esp_netif_get_ip_info (_mdns_get_esp_netif (mdns_if ), & if_ip_info ) == ESP_OK ) {
@@ -4108,14 +4122,13 @@ static void perform_event_action(mdns_if_t mdns_if, mdns_event_actions_t action)
4108
4122
}
4109
4123
}
4110
4124
}
4111
-
4112
- #ifdef CONFIG_LWIP_IPV6
4125
+ #endif /* LWIP_IPV4 */
4126
+ #if LWIP_IPV6
4113
4127
if (action & MDNS_EVENT_IP6_REVERSE_LOOKUP ) {
4114
4128
esp_ip6_addr_t addr6 ;
4115
4129
if (!esp_netif_get_ip6_linklocal (_mdns_get_esp_netif (mdns_if ), & addr6 ) && !_ipv6_address_is_zero (addr6 )) {
4116
4130
uint8_t * paddr = (uint8_t * )& addr6 .addr ;
4117
4131
const char sub [] = "ip6" ;
4118
- const size_t query_name_size = 4 * sizeof (addr6 .addr ) /* (2 nibbles + 2 dots)/per byte of IP address */ + sizeof (sub );
4119
4132
char * reverse_query_name = malloc (query_name_size );
4120
4133
if (reverse_query_name ) {
4121
4134
char * ptr = & reverse_query_name [query_name_size ]; // point to the end
@@ -4133,7 +4146,7 @@ static void perform_event_action(mdns_if_t mdns_if, mdns_event_actions_t action)
4133
4146
}
4134
4147
}
4135
4148
}
4136
- #endif /* CONFIG_LWIP_IPV6 */
4149
+ #endif /* LWIP_IPV6 */
4137
4150
#endif /* CONFIG_MDNS_RESPOND_REVERSE_QUERIES */
4138
4151
}
4139
4152
@@ -5484,22 +5497,25 @@ esp_err_t mdns_init(void)
5484
5497
#endif
5485
5498
5486
5499
uint8_t i ;
5487
- #if CONFIG_LWIP_IPV6
5500
+ #if LWIP_IPV6
5488
5501
esp_ip6_addr_t tmp_addr6 ;
5489
5502
#endif
5503
+ #if LWIP_IPV4
5490
5504
esp_netif_ip_info_t if_ip_info ;
5505
+ #endif
5491
5506
5492
5507
for (i = 0 ; i < MDNS_MAX_INTERFACES ; i ++ ) {
5493
- #if CONFIG_LWIP_IPV6
5508
+ #if LWIP_IPV6
5494
5509
if (!esp_netif_get_ip6_linklocal (_mdns_get_esp_netif (i ), & tmp_addr6 ) && !_ipv6_address_is_zero (tmp_addr6 )) {
5495
5510
_mdns_enable_pcb (i , MDNS_IP_PROTOCOL_V6 );
5496
5511
}
5497
5512
#endif
5513
+ #if LWIP_IPV4
5498
5514
if (!esp_netif_get_ip_info (_mdns_get_esp_netif (i ), & if_ip_info ) && if_ip_info .ip .addr ) {
5499
5515
_mdns_enable_pcb (i , MDNS_IP_PROTOCOL_V4 );
5500
5516
}
5517
+ #endif
5501
5518
}
5502
-
5503
5519
if (_mdns_service_task_start ()) {
5504
5520
//service start failed!
5505
5521
err = ESP_FAIL ;
0 commit comments