From 5909e9e54ce896225a142f8dc68da02972d5f668 Mon Sep 17 00:00:00 2001 From: David Cermak Date: Thu, 17 Feb 2022 10:40:32 +0100 Subject: [PATCH] mdns: Remove legacy esp_event API * Original commit: espressif/esp-idf@e46aa515bdf5606a3d868f1034774d5fc96904b8 --- components/mdns/include/mdns.h | 13 ------------- components/mdns/mdns.c | 19 +++++++------------ components/mdns/test/test_mdns.c | 1 + components/mdns/test_afl_fuzz_host/Makefile | 2 +- components/mdns/test_afl_fuzz_host/README.md | 7 +++++-- .../mdns/test_afl_fuzz_host/esp32_mock.h | 3 +++ 6 files changed, 17 insertions(+), 28 deletions(-) diff --git a/components/mdns/include/mdns.h b/components/mdns/include/mdns.h index cfbdadcbf..55de0dbab 100644 --- a/components/mdns/include/mdns.h +++ b/components/mdns/include/mdns.h @@ -11,7 +11,6 @@ extern "C" { #endif #include -#include "esp_event.h" #define MDNS_TYPE_A 0x0001 #define MDNS_TYPE_PTR 0x000C @@ -717,18 +716,6 @@ esp_err_t mdns_query_a(const char * host_name, uint32_t timeout, esp_ip4_addr_t esp_err_t mdns_query_aaaa(const char * host_name, uint32_t timeout, esp_ip6_addr_t * addr); #endif -/** - * @brief System event handler - * This method controls the service state on all active interfaces and applications are required - * to call it from the system event handler for normal operation of mDNS service. - * - * Please note that hostname must not contain domain name, as mDNS uses '.local' domain. - * - * @param ctx The system event context - * @param event The system event - */ -esp_err_t mdns_handle_system_event(void *ctx, system_event_t *event) __attribute__((deprecated)); - #ifdef __cplusplus } #endif diff --git a/components/mdns/mdns.c b/components/mdns/mdns.c index 20c9a4505..67fa442e7 100644 --- a/components/mdns/mdns.c +++ b/components/mdns/mdns.c @@ -4,16 +4,17 @@ * SPDX-License-Identifier: Apache-2.0 */ -#include "mdns.h" -#include "mdns_private.h" -#include "mdns_networking.h" -#include "esp_log.h" +#include +#include #include "freertos/FreeRTOS.h" #include "freertos/task.h" #include "freertos/queue.h" #include "freertos/semphr.h" -#include -#include +#include "esp_log.h" +#include "esp_event.h" +#include "mdns.h" +#include "mdns_private.h" +#include "mdns_networking.h" #ifdef MDNS_ENABLE_DEBUG void mdns_debug_packet(const uint8_t * data, size_t len); @@ -4875,12 +4876,6 @@ static esp_err_t _mdns_service_task_stop(void) * Public Methods * */ -esp_err_t mdns_handle_system_event(void *ctx, system_event_t *event) -{ - /* no-op, kept for compatibility */ - return ESP_OK; -} - static void event_handler(void* arg, esp_event_base_t event_base, int32_t event_id, void* event_data) { diff --git a/components/mdns/test/test_mdns.c b/components/mdns/test/test_mdns.c index abdad0e63..88bc49dbc 100644 --- a/components/mdns/test/test_mdns.c +++ b/components/mdns/test/test_mdns.c @@ -1,5 +1,6 @@ #include "test_utils.h" #include "mdns.h" +#include "esp_event.h" #include "unity.h" diff --git a/components/mdns/test_afl_fuzz_host/Makefile b/components/mdns/test_afl_fuzz_host/Makefile index a343fe3d6..096e122e6 100644 --- a/components/mdns/test_afl_fuzz_host/Makefile +++ b/components/mdns/test_afl_fuzz_host/Makefile @@ -20,7 +20,7 @@ CFLAGS=-g -Wno-unused-value -Wno-missing-declarations -Wno-pointer-bool-conversi -I$(COMPONENTS_DIR)/esp_wifi/include \ -I$(COMPONENTS_DIR)/freertos/FreeRTOS-Kernel \ -I$(COMPONENTS_DIR)/freertos/FreeRTOS-Kernel/include \ - -I$(COMPONENTS_DIR)/freertos/FreeRTOS-Kernel/portable/xtensa/include \ + -I$(COMPONENTS_DIR)/freertos/esp_additions/include/freertos \ -I$(COMPONENTS_DIR)/hal/include \ -I$(COMPONENTS_DIR)/hal/esp32/include \ -I$(COMPONENTS_DIR)/heap/include \ diff --git a/components/mdns/test_afl_fuzz_host/README.md b/components/mdns/test_afl_fuzz_host/README.md index 4a9e68200..11f9c5e6d 100644 --- a/components/mdns/test_afl_fuzz_host/README.md +++ b/components/mdns/test_afl_fuzz_host/README.md @@ -1,7 +1,7 @@ ## Introduction This test uses [american fuzzy lop](http://lcamtuf.coredump.cx/afl/) to mangle real mdns packets and look for exceptions caused by the parser. -A few actual packets are collected and exported as bins in the ```in``` folder, which is then passed as input to AFL when testing. The setup procedure for the test includes all possible services and scenarios that could be used with the given input packets.The output of the parser before fuzzing can be found in [input_packets.txt](input_packets.txt) +A few actual packets are collected and exported as bins in the `in` folder, which is then passed as input to AFL when testing. The setup procedure for the test includes all possible services and scenarios that could be used with the given input packets.The output of the parser before fuzzing can be found in [input_packets.txt](input_packets.txt) ## Building and running the tests using AFL To build and run the tests using AFL(afl-clang-fast) instrumentation @@ -14,6 +14,7 @@ make fuzz (Please note you have to install AFL instrumentation first, check `Installing AFL` section) ## Building the tests using GCC INSTR(off) + To build the tests without AFL instrumentations and instead of that use GCC compiler(In this case it will only check for compilation issues and will not run AFL tests). ```bash @@ -21,8 +22,10 @@ cd $IDF_PATH/components/mdns/test_afl_host make INSTR=off ``` +Note, that this setup is useful if we want to reproduce issues reported by fuzzer tests executed in the CI, or to simulate how the packet parser treats the input packets on the host machine. + ## Installing AFL -To run the test yourself, you need to dounload the [latest afl archive](http://lcamtuf.coredump.cx/afl/releases/afl-latest.tgz) and extract it to a folder on your computer. +To run the test yourself, you need to download the [latest afl archive](http://lcamtuf.coredump.cx/afl/releases/afl-latest.tgz) and extract it to a folder on your computer. The rest of the document will refer to that folder as ```PATH_TO_AFL```. diff --git a/components/mdns/test_afl_fuzz_host/esp32_mock.h b/components/mdns/test_afl_fuzz_host/esp32_mock.h index 2c268b6b5..b5187cb0c 100644 --- a/components/mdns/test_afl_fuzz_host/esp32_mock.h +++ b/components/mdns/test_afl_fuzz_host/esp32_mock.h @@ -8,6 +8,9 @@ // Skip these include files #define ESP_MDNS_NETWORKING_H_ +#define INC_FREERTOS_H +#define QUEUE_H +#define SEMAPHORE_H #define _TCPIP_ADAPTER_H_ #define _ESP_TASK_H_