Skip to content

Commit 3c6098a

Browse files
committed
feat(mdns): refactor stage #1
feat(mdns): Make mdns-debug a separate module feat(mdns): Separate packet-tx and browse feat(mdns): Add responder module feat(mdns): Querier-search stuff, Responder-pcb stuff feat(mdns): action queue abstraction fix(mdns): Minor cleanup of packet parser fix(mdns): Cleanup and split interfaces between modules feat(mdns): Add fuzzing job with AFL++ fix(mdns): Rename and cleanup feat(mdns): Add service module fix(mdns): Forward porting 8ca45f3 delete race fix(mdns): Minor cleanup fix(mdns): Refactor fuzzer test suite fix(mdns): Add host unit tests fix(mdns): Add receiver unit tests feat(mdns): Add test template for mdns-sender fix(mdns): Minor cleanup fix(mdns): Cleanup querier and pcb fix(mdns): Cleanup mdns sender fix(mdns): Cleanup mdns sender fix(mdns): Add documentation about the refactor, remove old fuzz fix(mdns): Add refactoring details to help review changes fix(mdns): Add data-flow diagram fix(mdns): Make debug module more flexible and enable routing printfs to esp_log component fix(mdns): Address minor review comments fix(mdns): Debug prints with small buffer fix(mdns): Minor cleanup fix(mdns): Fix host tests by freezing idf-build-apps to 2.10 fix(mdns): per final code review
1 parent 1ceb42c commit 3c6098a

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

89 files changed

+11872
-9531
lines changed

.github/workflows/mdns__host-tests.yml

Lines changed: 56 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ jobs:
2929
# Build host tests app (with all configs and targets supported)
3030
python ./ci/build_apps.py components/mdns/tests/host_test/
3131
cd components/mdns/tests/host_test
32+
ls -la
33+
ls -ls build*
3234
# First run the linux_app and send a quick A query and a reverse query
3335
./build_linux_app/mdns_host.elf &
3436
python dnsfixture.py A myesp.local --ip_only | xargs python dnsfixture.py X
@@ -55,8 +57,11 @@ jobs:
5557
shell: bash
5658
run: |
5759
. ${IDF_PATH}/export.sh
58-
cd components/mdns/tests/test_afl_fuzz_host/
59-
make INSTR=off
60+
cd components/mdns/tests/host_unit_test/
61+
idf.py reconfigure
62+
mkdir build2 && cd build2
63+
cmake ..
64+
cmake --build .
6065
- name: Test no malloc functions
6166
shell: bash
6267
run: |
@@ -69,6 +74,39 @@ jobs:
6974
echo "OK"
7075
done
7176
77+
host_unit_test:
78+
if: contains(github.event.pull_request.labels.*.name, 'mdns') || github.event_name == 'push'
79+
name: Unit tests on host
80+
strategy:
81+
matrix:
82+
idf_ver: ["latest"]
83+
84+
runs-on: ubuntu-22.04
85+
container: espressif/idf:${{ matrix.idf_ver }}
86+
steps:
87+
- name: Checkout esp-protocols
88+
uses: actions/checkout@v4
89+
- name: Install bsdlib and ruby
90+
run: |
91+
apt-get update -y
92+
apt-get install -y libbsd-dev ruby
93+
- name: Build and run unit tests
94+
shell: bash
95+
run: |
96+
. ${IDF_PATH}/export.sh
97+
cd components/mdns/tests/host_unit_test/
98+
idf.py reconfigure
99+
mkdir build2 && cd build2
100+
cmake -DUNIT_TESTS=test_receiver ..
101+
cmake --build .
102+
ctest --extra-verbose
103+
cd ..
104+
mkdir build3 && cd build3
105+
cmake -DUNIT_TESTS=test_sender ..
106+
cmake --build .
107+
ctest --extra-verbose
108+
109+
72110
fuzz_test:
73111
if: contains(github.event.pull_request.labels.*.name, 'mdns-fuzz') || github.event_name == 'push'
74112
name: Fuzzer tests for mdns lib
@@ -98,13 +136,26 @@ jobs:
98136
shell: bash
99137
run: |
100138
export IDF_PATH=$GITHUB_WORKSPACE/idf
101-
cd components/mdns/tests/test_afl_fuzz_host/
102-
make fuzz
139+
cd components/mdns/tests/host_unit_test/
140+
pip install dnslib
141+
cd input && python generate_cases.py && cd ..
142+
cmake -B build2 -S . -G "Ninja" -DCMAKE_C_COMPILER=afl-cc
143+
cmake --build build2
144+
timeout 10m afl-fuzz -i input -o out -- build2/mdns_host_unit_test || \
145+
if [ $? -eq 124 ]; then # timeout exit code
146+
if [ -n "$(find out/default/crashes -type f 2>/dev/null)" ]; then
147+
echo "Crashes found!";
148+
tar -czf out/default/crashes.tar.gz -C out/default crashes;
149+
exit 1;
150+
fi
151+
else
152+
exit 1;
153+
fi
103154
104155
- name: Upload Crash Artifacts
105156
if: failure()
106157
uses: actions/upload-artifact@v4
107158
with:
108159
name: fuzz-crashes
109-
path: components/mdns/tests/test_afl_fuzz_host/out/default/crashes.tar.gz
160+
path: components/mdns/tests/host_unit_test/out/default/crashes.tar.gz
110161
if-no-files-found: ignore

components/mdns/CMakeLists.txt

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,18 @@ endif()
1212

1313
set(MDNS_MEMORY "mdns_mem_caps.c")
1414

15+
set(MDNS_CORE "mdns_responder.c" "mdns_receive.c" "mdns_utils.c" "mdns_debug.c" "mdns_browser.c" "mdns_send.c" "mdns_netif.c"
16+
"mdns_querier.c" "mdns_pcb.c" "mdns_service.c")
17+
1518
idf_build_get_property(target IDF_TARGET)
1619
if(${target} STREQUAL "linux")
1720
set(dependencies esp_netif_linux esp_event)
1821
set(private_dependencies esp_timer console esp_system)
19-
set(srcs "mdns.c" ${MDNS_MEMORY} ${MDNS_NETWORKING} ${MDNS_CONSOLE})
22+
set(srcs ${MDNS_CORE} ${MDNS_MEMORY} ${MDNS_NETWORKING} ${MDNS_CONSOLE})
2023
else()
2124
set(dependencies lwip console esp_netif)
2225
set(private_dependencies esp_timer esp_wifi)
23-
set(srcs "mdns.c" ${MDNS_MEMORY} ${MDNS_NETWORKING} ${MDNS_CONSOLE})
26+
set(srcs ${MDNS_CORE} ${MDNS_MEMORY} ${MDNS_NETWORKING} ${MDNS_CONSOLE})
2427
endif()
2528

2629
idf_component_register(

components/mdns/Kconfig

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,20 @@ menu "mDNS"
142142
help
143143
Enable for the library to log received and sent mDNS packets to stdout.
144144

145+
config MDNS_DEBUG_USE_ESP_LOG
146+
bool "Route debug prints to ESP_LOG"
147+
depends on MDNS_ENABLE_DEBUG_PRINTS
148+
default y
149+
help
150+
Enable this option to route debug prints to ESP_LOG, which allows more flexibility.
151+
152+
config MDNS_DEBUG_BUFFER_SIZE
153+
int "Size of temporary buffer for debug prints"
154+
depends on MDNS_DEBUG_USE_ESP_LOG
155+
default 1024
156+
help
157+
This buffer is used to output mDNS packets in debug prints.
158+
145159
config MDNS_ENABLE_CONSOLE_CLI
146160
bool "Enable Command Line Interface on device console"
147161
default y

0 commit comments

Comments
 (0)