diff --git a/.github/.cSpellWords.txt b/.github/.cSpellWords.txt index d192c57c51..ed12e1e9c1 100644 --- a/.github/.cSpellWords.txt +++ b/.github/.cSpellWords.txt @@ -454,6 +454,7 @@ FPSP FRAMERX FRMFILTER frms +fsanitize FSDMA FTSR FUDUP diff --git a/.github/CONTRIBUTING.md b/.github/CONTRIBUTING.md index d3c6a6611f..3b1c0cd1d9 100644 --- a/.github/CONTRIBUTING.md +++ b/.github/CONTRIBUTING.md @@ -33,7 +33,7 @@ When creating a new topic on the forums or filing an issue, please include as ma ## Contributing via pull request Contributions via pull requests are much appreciated. Before sending us a pull request, please ensure that: -1. You are working against the latest source on the *master* branch. +1. You are working against the latest source on the *main* branch. 2. You check existing open, and recently merged, pull requests to make sure someone else hasn't addressed the problem already. 3. You open an issue to discuss any significant work - we would hate for your time to be wasted. @@ -63,7 +63,7 @@ Looking at the existing issues is a great way to find something to contribute on ## Licensing -The FreeRTOS-Plus-TCP library is released under the MIT open source license, the text of which can be found [here](https://github.com/FreeRTOS/FreeRTOS-Plus-TCP/blob/master/LICENSE.md) +The FreeRTOS-Plus-TCP library is released under the MIT open source license, the text of which can be found [here](https://github.com/FreeRTOS/FreeRTOS-Plus-TCP/blob/main/LICENSE.md) Additional license files can be found in the folders containing any supplementary libraries licensed by their respective copyright owners where applicable. diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 1c93092c8c..ba6a8c1660 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -38,27 +38,56 @@ jobs: echo "::endgroup::" echo -e "${{ env.bashPass }} ${{ env.stepName }} ${{ env.bashEnd }}" + # Separate builds for sanitizers and coverage: + # These can currently not be combined without branch coverage dilution. - env: - stepName: Build Unit Tests + stepName: Build Unit Tests (aubsan build) name: ${{ env.stepName }} run: | # ${{ env.stepName }} echo -e "::group::${{ env.bashInfo }} ${{ env.stepName }} ${{ env.bashEnd }}" - cmake -S test/unit-test -B test/unit-test/build/ -G Ninja - cmake --build test/unit-test/build/ --target all + cmake --fresh -G Ninja -S test/unit-test -B test/unit-test/build/ -DSANITIZE=address,undefined + ninja -C test/unit-test/build/ echo "::endgroup::" echo -e "${{ env.bashPass }} ${{ env.stepName }} ${{ env.bashEnd }}" - env: - stepName: Run Unit Tests + stepName: Run Unit Tests (aubsan build) name: ${{ env.stepName }} shell: bash run: | # ${{ env.stepName }} echo -e "::group::${{ env.bashInfo }} ${{ env.stepName }} ${{ env.bashEnd }}" + env ASAN_OPTIONS=detect_odr_violation=0 ctest --test-dir test/unit-test/build/ -E system --output-on-failure + + echo "::endgroup::" + echo -e "${{ env.bashPass }} ${{ env.stepName }} ${{ env.bashEnd }}" + + - env: + stepName: Build Unit Tests (coverage build) + name: ${{ env.stepName }} + run: | + # ${{ env.stepName }} + echo -e "::group::${{ env.bashInfo }} ${{ env.stepName }} ${{ env.bashEnd }}" + + cmake --fresh -G Ninja -S test/unit-test -B test/unit-test/build/ -DSANITIZE= + ninja -C test/unit-test/build/ + + echo "::endgroup::" + echo -e "${{ env.bashPass }} ${{ env.stepName }} ${{ env.bashEnd }}" + + - env: + stepName: Run Unit Tests (coverage build) + name: ${{ env.stepName }} + shell: bash + run: | + # ${{ env.stepName }} + echo -e "::group::${{ env.bashInfo }} ${{ env.stepName }} ${{ env.bashEnd }}" + + find test/unit-test/build/ -name '*.gcda' -delete ctest --test-dir test/unit-test/build/ -E system --output-on-failure echo "::endgroup::" @@ -170,7 +199,7 @@ jobs: # ${{ env.stepName }} echo -e "::group::${{ env.bashInfo }} ${{ env.stepName }} ${{ env.bashEnd }}" - cmake -S . -B build -DFREERTOS_PLUS_TCP_TEST_CONFIGURATION=ENABLE_ALL + cmake -S . -B build -DFREERTOS_PLUS_TCP_ENABLE_BUILD_CHECKS=ON -DFREERTOS_PLUS_TCP_TEST_CONFIGURATION=ENABLE_ALL cmake --build build --target freertos_plus_tcp_build_test echo "::endgroup::" @@ -183,7 +212,7 @@ jobs: # ${{ env.stepName }} echo -e "::group::${{ env.bashInfo }} ${{ env.stepName }} ${{ env.bashEnd }}" - cmake -S . -B build -DFREERTOS_PLUS_TCP_TEST_CONFIGURATION=ENABLE_ALL_IPV4 + cmake -S . -B build -DFREERTOS_PLUS_TCP_ENABLE_BUILD_CHECKS=ON -DFREERTOS_PLUS_TCP_TEST_CONFIGURATION=ENABLE_ALL_IPV4 cmake --build build --target clean cmake --build build --target freertos_plus_tcp_build_test @@ -197,7 +226,7 @@ jobs: # ${{ env.stepName }} echo -e "::group::${{ env.bashInfo }} ${{ env.stepName }} ${{ env.bashEnd }}" - cmake -S . -B build -DFREERTOS_PLUS_TCP_TEST_CONFIGURATION=ENABLE_ALL_IPV6 + cmake -S . -B build -DFREERTOS_PLUS_TCP_ENABLE_BUILD_CHECKS=ON -DFREERTOS_PLUS_TCP_TEST_CONFIGURATION=ENABLE_ALL_IPV6 cmake --build build --target freertos_plus_tcp_build_test echo "::endgroup::" @@ -210,7 +239,7 @@ jobs: # ${{ env.stepName }} echo -e "::group::${{ env.bashInfo }} ${{ env.stepName }} ${{ env.bashEnd }}" - cmake -S . -B build -DFREERTOS_PLUS_TCP_TEST_CONFIGURATION=ENABLE_ALL_IPV4_IPV6 + cmake -S . -B build -DFREERTOS_PLUS_TCP_ENABLE_BUILD_CHECKS=ON -DFREERTOS_PLUS_TCP_TEST_CONFIGURATION=ENABLE_ALL_IPV4_IPV6 cmake --build build --target clean cmake --build build --target freertos_plus_tcp_build_test @@ -224,7 +253,7 @@ jobs: # ${{ env.stepName }} echo -e "::group::${{ env.bashInfo }} ${{ env.stepName }} ${{ env.bashEnd }}" - cmake -S . -B build -DFREERTOS_PLUS_TCP_TEST_CONFIGURATION=ENABLE_ALL_IPV4_TCP + cmake -S . -B build -DFREERTOS_PLUS_TCP_ENABLE_BUILD_CHECKS=ON -DFREERTOS_PLUS_TCP_TEST_CONFIGURATION=ENABLE_ALL_IPV4_TCP cmake --build build --target clean cmake --build build --target freertos_plus_tcp_build_test @@ -238,7 +267,7 @@ jobs: # ${{ env.stepName }} echo -e "::group::${{ env.bashInfo }} ${{ env.stepName }} ${{ env.bashEnd }}" - cmake -S . -B build -DFREERTOS_PLUS_TCP_TEST_CONFIGURATION=ENABLE_ALL_IPV6_TCP + cmake -S . -B build -DFREERTOS_PLUS_TCP_ENABLE_BUILD_CHECKS=ON -DFREERTOS_PLUS_TCP_TEST_CONFIGURATION=ENABLE_ALL_IPV6_TCP cmake --build build --target freertos_plus_tcp_build_test echo "::endgroup::" @@ -251,7 +280,7 @@ jobs: # ${{ env.stepName }} echo -e "::group::${{ env.bashInfo }} ${{ env.stepName }} ${{ env.bashEnd }}" - cmake -S . -B build -DFREERTOS_PLUS_TCP_TEST_CONFIGURATION=DISABLE_ALL + cmake -S . -B build -DFREERTOS_PLUS_TCP_ENABLE_BUILD_CHECKS=ON -DFREERTOS_PLUS_TCP_TEST_CONFIGURATION=DISABLE_ALL cmake --build build --target clean cmake --build build --target freertos_plus_tcp_build_test @@ -265,7 +294,7 @@ jobs: # ${{ env.stepName }} echo -e "::group::${{ env.bashInfo }} ${{ env.stepName }} ${{ env.bashEnd }}" - cmake -S . -B build -DFREERTOS_PLUS_TCP_TEST_CONFIGURATION=DEFAULT_CONF + cmake -S . -B build -DFREERTOS_PLUS_TCP_ENABLE_BUILD_CHECKS=ON -DFREERTOS_PLUS_TCP_TEST_CONFIGURATION=DEFAULT_CONF cmake --build build --target clean cmake --build build --target freertos_plus_tcp_build_test @@ -276,7 +305,7 @@ jobs: stepName: Build checks (Header Self Contain) shell: bash run: | - cmake -S . -B build -DFREERTOS_PLUS_TCP_TEST_CONFIGURATION=HEADER_SELF_CONTAIN + cmake -S . -B build -DFREERTOS_PLUS_TCP_ENABLE_BUILD_CHECKS=ON -DFREERTOS_PLUS_TCP_TEST_CONFIGURATION=HEADER_SELF_CONTAIN cmake --build build --target clean cmake --build build --target freertos_plus_tcp_build_test_FreeRTOS_DHCP cmake --build build --target freertos_plus_tcp_build_test_FreeRTOS_DNS @@ -377,7 +406,7 @@ jobs: - name: Set up CBMC runner uses: FreeRTOS/CI-CD-Github-Actions/set_up_cbmc_runner@main with: - cbmc_version: "5.61.0" + cbmc_version: "5.95.1" - env: stepName: Install Dependencies diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 6018d07f23..fd11afee3b 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -55,7 +55,7 @@ jobs: - name: Checkout code uses: actions/checkout@v4 with: - ref: ${{ github.event.inputs.commit_id }} + ref: ${{ github.event.inputs.version_number }} path: FreeRTOS-Plus-TCP submodules: recursive - name: Checkout disabled submodules diff --git a/CMakeLists.txt b/CMakeLists.txt index 1f31f011e1..c68019ad3a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,5 +1,5 @@ -cmake_minimum_required(VERSION 3.15) +cmake_minimum_required(VERSION 3.21) cmake_policy(SET CMP0048 NEW) # project version cmake_policy(SET CMP0076 NEW) # full paths @@ -20,6 +20,7 @@ endif() # Options option(FREERTOS_PLUS_TCP_BUILD_TEST "Build the test for FreeRTOS Plus TCP" OFF) +option(FREERTOS_PLUS_TCP_ENABLE_BUILD_CHECKS "Enable the build checks for FreeRTOS-Plus-TCP" OFF) # Configuration # Override these at project level with: @@ -149,32 +150,6 @@ endif() # There is also the need to add a target - typically an interface library that describes the # Configuration for FreeRTOS-Kernel and FreeRTOS-Plus-TCP. # This is called freertos_config -# If not defined will be default compile with one of the test build combinations AllEnable. - -# Select the appropriate Build Test configuration -# This is only used when freertos_config is not defined, otherwise the build test will be performed -# on the config defined in the freertos_config -set(FREERTOS_PLUS_TCP_TEST_CONFIGURATION "CUSTOM" CACHE STRING "FreeRTOS Plus TCP Build Test configuration") -set(FREERTOS_PLUS_TCP_TEST_CONFIGURATION_LIST - CUSTOM # Custom (external) configuration -eg from a top-level project - ENABLE_ALL # Enable all configuration settings - ENABLE_ALL_IPV4 # Enable all configuration settings IPv4 UDP - ENABLE_ALL_IPV6 # Enable all configuration settings IPv6 UDP - ENABLE_ALL_IPV4_TCP # Enable all configuration settings IPv4 TCP - ENABLE_ALL_IPV6_TCP # Enable all configuration settings IPv6 TCP - ENABLE_ALL_IPV4_IPV6 # Enable all configuration settings IPv4 IPv6 UDP - DISABLE_ALL # Disable all configuration settings - HEADER_SELF_CONTAIN # Enable header self contain test - DEFAULT_CONF # Default (typical) configuration -) -if(NOT FREERTOS_PLUS_TCP_TEST_CONFIGURATION IN_LIST FREERTOS_PLUS_TCP_TEST_CONFIGURATION_LIST) - message(FATAL_ERROR "Invalid FREERTOS_PLUS_TCP_TEST_CONFIGURATION value '${FREERTOS_PLUS_TCP_TEST_CONFIGURATION}' should be one of: ${FREERTOS_PLUS_TCP_TEST_CONFIGURATION_LIST}") -else() - message(STATUS "Using FreeRTOS-Plus-TCP Test Configuration : ${FREERTOS_PLUS_TCP_TEST_CONFIGURATION}") - if (NOT FREERTOS_PLUS_TCP_TEST_CONFIGURATION STREQUAL "CUSTOM") - message(WARNING "FreeRTOS-Kernel configuration settings are configured by FreeRTOS-Plus-TCP") - endif() -endif() ######################################################################## # External Dependencies @@ -199,4 +174,6 @@ add_subdirectory(source) add_subdirectory(tools) add_subdirectory(test) -FetchContent_MakeAvailable(freertos_kernel cmock) +if(PROJECT_IS_TOP_LEVEL) + FetchContent_MakeAvailable(freertos_kernel cmock) +endif() \ No newline at end of file diff --git a/History.txt b/History.txt index 5b33b4d65a..3275574f99 100644 --- a/History.txt +++ b/History.txt @@ -1,5 +1,74 @@ Documentation and download available at https://www.FreeRTOS.org/ +Changes between FreeRTOS-plus-TCP V4.2.0 and V4.1.0 released June 24, 2024 + + It was possible for a carefully crafted DNS response with domain name + length value greater than the actual domain name length, to cause a buffer + over-read within the DNS Response Parser. This issue affects applications + using DNS functionality of the FreeRTOS-Plus-TCP stack. + Applications that do not use DNS functionality are not affected, + even when the DNS functionality is enabled. + This issue has been fixed by modifying the code to ensure that the DNS + Response Parser never attempts to read beyond the DNS + response buffer boundary. + We would like to thank Paschal Amusuo, James C. Davis, and + Aravind Machiry of Purdue University, for reporting this issue. + + Fixed possible freed memory being reused while creating TCP sockets. + We thank @htibosch for their contribution. + + Fixed possible NULL pointer dereference in TCP transmission. + We thank @anordal for their contribution. + + Added network interface port for ARM Corstone-315 (MPS4_CS315). + We thank @david-hazi-arm for their contribution. + + Fixed MISRA C 2012 issues in the code + + Replaced the usage strcpy with strncpy + + Improved memory allocation failure handling in `vDNSSetCallBack` by + propagating error signal back. We thank @hlef for reporting this issue. + + Improved memory allocation failure handling in `prvCreateSectors` by + propagating error signal back. We thank @hlef for reporting this issue. + + Enabled build on CI with sanitizers, fixed all AddressSanitizer + and UB-Sanitizer errors. We thank @anordal for their contribution. + + Fixed mDNS lookups while parsing the mDNS answers. + We thank @htibosch for their contribution. + + Fixed DNS name resolution responses when the device IP address + is `0.0.0.0`. We thank @evpopov for their contribution. + + Avoided FreeRTOS-Plus-TCP forcing to use the compilation options + set in the library CMake project in user projects. + We thank @apcountryman for their contribution. + + Enabled user control of compiler analysis for non ISO statements. + We thank @thirtytwobits for their contribution + + Fixed use of removed macro in ATSAME5x network interface. + We thank @apcountryman for their contribution. + + Fixed inconsistent use of `ipconfigCOMPATIBLE_WITH_SINGLE` + & `ipconfigIPv4_BACKWARD_COMPATIBLE` + + Resolved Unit Test Build Warnings + + Added network interface functions for multicast MAC address filtering. + We thank @evpopov for their contribution. + + Fixed missing `ipconfigUSE_DNS_CACHE` check in FreeRTOS_DNS.c. + + Avoided compiler warnings about the printf formats in IPv6 modules. + We thank @htibosch for their contribution. + + Removed deprecated macro `ipconfigMULTI_INTERFACE`. + We thank @HTRamsey for their contribution. + + Removed unused function xProcessedTCPMessage. + We thank @HTRamsey for their contribution. + + Removed deprecated macros ipLOCAL_MAC_ADDRESS and + `ipLOCAL_IP_ADDRESS_POINTER`. We thank @HTRamsey for their contribution. + + Fixed eARPGetCacheEntryGateWay to properly report when no valid gateway is found + for a packet that needs to be sent outside the local network. + We thank @evpopov for their contribution. + + Combined duplicated IPv4/IPv6 TCP code. + We thank @HTRamsey for their contribution. + + Improved validation of configuration macros in the default + IP config using static compile time checks. + We thank @HTRamsey for their contribution. + + Repaired ARP unit tests which were accessing packet memory + outside of allocated bounds. + + Moved CMake compile options to test builds to avoid build issues in + user projects that might be not be supporting compiler options used + in the original Cmake. We thank @apcountryman for their contribution. + + Cleaned up CMake by adding: additional unit tests, incorporating missing + network interface support, removing unused "config files" that are no longer + required, and fixing file name issues in the unit testing framework. + We thank @HTRamsey for their contribution. + Changes between FreeRTOS-plus-TCP V4.1.0 and V4.0.0 released March 8, 2024 + Add new Network Interface for Corstone-300 FVP (MPS3_AN552). We thank @urutva for their contribution. diff --git a/README.md b/README.md index 269b49d002..08ed92b14a 100644 --- a/README.md +++ b/README.md @@ -3,6 +3,12 @@ FreeRTOS-Plus-TCP is a lightweight TCP/IP stack for FreeRTOS. It provides a fami This library has undergone static code analysis and checks for compliance with the [MISRA coding standard](https://www.misra.org.uk/). Any deviations from the MISRA C:2012 guidelines are documented under [MISRA Deviations](https://github.com/FreeRTOS/FreeRTOS-Plus-TCP/blob/main/MISRA.md). The library is validated for memory safety and data structure invariance through the [CBMC automated reasoning tool](https://www.cprover.org/cbmc/) for the functions that parse data originating from the network. The library is also protocol tested using Maxwell protocol tester for both IPv4 and IPv6. +**FreeRTOS-Plus-TCP Library V4.2.2 +[source code](https://github.com/FreeRTOS/FreeRTOS-Plus-TCP/tree/V4.2.2/source) +is part of the +[FreeRTOS 202406.01 LTS](https://github.com/FreeRTOS/FreeRTOS-LTS/tree/202406.01-LTS) +release.** + ## Getting started The easiest way to use version 4.0.0 and later of FreeRTOS-Plus-TCP is to refer the Getting started Guide (found [here](https://github.com/FreeRTOS/FreeRTOS-Plus-TCP/blob/main/GettingStarted.md)) Another way is to start with the pre-configured IPv4 Windows Simulator demo (found in [this directory](https://github.com/FreeRTOS/FreeRTOS/tree/main/FreeRTOS-Plus/Demo/FreeRTOS_Plus_TCP_Minimal_Windows_Simulator)) or IPv6 Multi-endpoint Windows Simulator demo (found in [this directory](https://github.com/FreeRTOS/FreeRTOS/tree/main/FreeRTOS-Plus/Demo/FreeRTOS_Plus_TCP_IPv6_Demo/IPv6_Multi_WinSim_demo)). That way you will have the correct FreeRTOS source files included, and the correct include paths configured. Once a demo application is building and executing you can remove the demo application files, and start to add in your own application source files. See the [FreeRTOS Kernel Quick Start Guide](https://www.freertos.org/FreeRTOS-quick-start-guide.html) for detailed instructions and other useful links. @@ -45,7 +51,7 @@ Add the following into your project's main or a subdirectory's `CMakeLists.txt`: ```cmake FetchContent_Declare( freertos_plus_tcp GIT_REPOSITORY https://github.com/FreeRTOS/FreeRTOS-Plus-TCP.git - GIT_TAG master #Note: Best practice to use specific git-hash or tagged version + GIT_TAG main #Note: Best practice to use specific git-hash or tagged version GIT_SUBMODULES "" # Don't grab any submodules since not latest ) ``` @@ -54,13 +60,12 @@ FetchContent_Declare( freertos_plus_tcp - this particular example supports a native and cross-compiled build option. ```cmake -set( FREERTOS_PLUS_FAT_DEV_SUPPORT OFF CACHE BOOL "" FORCE) # Select the native compile PORT -set( FREERTOS_PLUS_FAT_PORT "POSIX" CACHE STRING "" FORCE) -# Select the cross-compile PORT +set( FREERTOS_PLUS_TCP_NETWORK_IF "POSIX" CACHE STRING "" FORCE) +# Or: select a cross-compile PORT if (CMAKE_CROSSCOMPILING) - # Eg. Zynq 2019_3 version of port - set(FREERTOS_PLUS_FAT_PORT "ZYNQ_2019_3" CACHE STRING "" FORCE) + # Eg. STM32Hxx version of port + set(FREERTOS_PLUS_TCP_NETWORK_IF "STM32HXX" CACHE STRING "" FORCE) endif() FetchContent_MakeAvailable(freertos_plus_tcp) diff --git a/docs/doxygen/config.doxyfile b/docs/doxygen/config.doxyfile index 76b46aedec..9f406bd078 100644 --- a/docs/doxygen/config.doxyfile +++ b/docs/doxygen/config.doxyfile @@ -48,7 +48,7 @@ PROJECT_NAME = FreeRTOS-Plus-TCP # could be handy for archiving the generated documentation or if some version # control system is used. -PROJECT_NUMBER = V4.1.0 +PROJECT_NUMBER = V4.2.0 # Using the PROJECT_BRIEF tag one can provide an optional one line description # for a project that appears at the top of each page and should give viewer a diff --git a/manifest.yml b/manifest.yml index 503347f619..5f19b66e96 100644 --- a/manifest.yml +++ b/manifest.yml @@ -1,12 +1,12 @@ name: "FreeRTOS-Plus-TCP" -version: "V4.1.0" +version: "V4.2.0" description: "Thread safe FreeRTOS TCP/IP stack working on top of the FreeRTOS-Kernel to implement the TCP/IP protocol. Suitable for microcontrollers." license: "MIT" dependencies: - name: "FreeRTOS-Kernel" - version: "V11.0.1" + version: "V11.1.0" license: "MIT" repository: type: "git" diff --git a/source/CMakeLists.txt b/source/CMakeLists.txt index ccda4fd505..6a6c429b23 100644 --- a/source/CMakeLists.txt +++ b/source/CMakeLists.txt @@ -1,7 +1,5 @@ add_library( freertos_plus_tcp STATIC ) -set_property(TARGET freertos_plus_tcp PROPERTY C_STANDARD 90) - target_sources( freertos_plus_tcp PRIVATE include/FreeRTOS_ARP.h @@ -94,11 +92,6 @@ target_include_directories( freertos_plus_tcp include ) -# Suppressions required to build clean with GCC -if(CMAKE_C_COMPILER_ID STREQUAL GNU) - set_source_files_properties(FreeRTOS_Sockets.c PROPERTIES COMPILE_FLAGS -Wno-pedantic) -endif() - target_link_libraries( freertos_plus_tcp PUBLIC freertos_config diff --git a/source/FreeRTOS_ARP.c b/source/FreeRTOS_ARP.c index 6e7f38704c..654e566e3d 100644 --- a/source/FreeRTOS_ARP.c +++ b/source/FreeRTOS_ARP.c @@ -239,7 +239,7 @@ /* Process received ARP frame to see if there is a clash. */ #if ( ipconfigARP_USE_CLASH_DETECTION != 0 ) { - NetworkEndPoint_t * pxSourceEndPoint = FreeRTOS_FindEndPointOnIP_IPv4( ulSenderProtocolAddress, 2 ); + NetworkEndPoint_t * pxSourceEndPoint = FreeRTOS_FindEndPointOnIP_IPv4( ulSenderProtocolAddress ); if( ( pxSourceEndPoint != NULL ) && ( pxSourceEndPoint->ipv4_settings.ulIPAddress == ulSenderProtocolAddress ) ) { @@ -620,7 +620,7 @@ { #if ( ipconfigARP_STORES_REMOTE_ADDRESSES == 0 ) /* Only process the IP address if it is on the local network. */ - BaseType_t xAddressIsLocal = ( FreeRTOS_FindEndPointOnNetMask( ulIPAddress, 2 ) != NULL ) ? 1 : 0; /* ARP remote address. */ + BaseType_t xAddressIsLocal = ( FreeRTOS_FindEndPointOnNetMask( ulIPAddress ) != NULL ) ? 1 : 0; /* ARP remote address. */ /* Only process the IP address if it matches with one of the end-points. */ if( xAddressIsLocal != 0 ) @@ -710,7 +710,7 @@ BaseType_t xReturn = pdFALSE; #if ( ipconfigARP_STORES_REMOTE_ADDRESSES != 0 ) - BaseType_t xAddressIsLocal = ( FreeRTOS_FindEndPointOnNetMask( ulIPAddress, 2 ) != NULL ) ? 1 : 0; /* ARP remote address. */ + BaseType_t xAddressIsLocal = ( FreeRTOS_FindEndPointOnNetMask( ulIPAddress ) != NULL ) ? 1 : 0; /* ARP remote address. */ #endif /* Start with the maximum possible number. */ @@ -776,7 +776,7 @@ /* If ARP stores the MAC address of IP addresses outside the * network, than the MAC address of the gateway should not be * overwritten. */ - BaseType_t xOtherIsLocal = ( FreeRTOS_FindEndPointOnNetMask( xARPCache[ x ].ulIPAddress, 3 ) != NULL ) ? 1 : 0; /* ARP remote address. */ + BaseType_t xOtherIsLocal = ( FreeRTOS_FindEndPointOnNetMask( xARPCache[ x ].ulIPAddress ) != NULL ) ? 1 : 0; /* ARP remote address. */ if( xAddressIsLocal == xOtherIsLocal ) { @@ -891,7 +891,7 @@ *( ppxEndPoint ) = NULL; ulAddressToLookup = *pulIPAddress; - pxEndPoint = FreeRTOS_FindEndPointOnIP_IPv4( ulAddressToLookup, 0 ); + pxEndPoint = FreeRTOS_FindEndPointOnIP_IPv4( ulAddressToLookup ); if( xIsIPv4Multicast( ulAddressToLookup ) != 0 ) { @@ -918,7 +918,7 @@ { /* This is a broadcast so it uses the broadcast MAC address. */ ( void ) memcpy( pxMACAddress->ucBytes, xBroadcastMACAddress.ucBytes, sizeof( MACAddress_t ) ); - pxEndPoint = FreeRTOS_FindEndPointOnNetMask( ulAddressToLookup, 4 ); + pxEndPoint = FreeRTOS_FindEndPointOnNetMask( ulAddressToLookup ); if( pxEndPoint != NULL ) { @@ -955,7 +955,7 @@ /* It is assumed that devices with the same netmask are on the same * LAN and don't need a gateway. */ - pxEndPoint = FreeRTOS_FindEndPointOnNetMask( ulAddressToLookup, 4 ); + pxEndPoint = FreeRTOS_FindEndPointOnNetMask( ulAddressToLookup ); if( pxEndPoint == NULL ) { @@ -1249,7 +1249,7 @@ /* Its assumed that IPv4 endpoints belonging to different physical interface * in the system will have a different subnet, but endpoints on same interface * may have it. */ - NetworkEndPoint_t * pxEndPoint = FreeRTOS_FindEndPointOnNetMask( ulIPAddress, 12 ); + NetworkEndPoint_t * pxEndPoint = FreeRTOS_FindEndPointOnNetMask( ulIPAddress ); if( pxEndPoint != NULL ) { diff --git a/source/FreeRTOS_DNS.c b/source/FreeRTOS_DNS.c index 1b2252a052..82e2c6dbfe 100644 --- a/source/FreeRTOS_DNS.c +++ b/source/FreeRTOS_DNS.c @@ -57,6 +57,48 @@ #include "FreeRTOS_DNS_Callback.h" +/** @brief The MAC address used for LLMNR. */ +const MACAddress_t xLLMNR_MacAddress = { { 0x01, 0x00, 0x5e, 0x00, 0x00, 0xfc } }; + +/** @brief The IPv6 link-scope multicast MAC address */ +const MACAddress_t xLLMNR_MacAddressIPv6 = { { 0x33, 0x33, 0x00, 0x01, 0x00, 0x03 } }; + +/** @brief The IPv6 link-scope multicast address */ +const IPv6_Address_t ipLLMNR_IP_ADDR_IPv6 = +{ + { /* ff02::1:3 */ + 0xff, 0x02, + 0x00, 0x00, + 0x00, 0x00, + 0x00, 0x00, + 0x00, 0x00, + 0x00, 0x00, + 0x00, 0x01, + 0x00, 0x03, + } +}; + +/** @brief The MAC address used for MDNS. */ +const MACAddress_t xMDNS_MacAddress = { { 0x01, 0x00, 0x5e, 0x00, 0x00, 0xfb } }; + +/** @brief The IPv6 multicast DNS MAC address. */ +const MACAddress_t xMDNS_MacAddressIPv6 = { { 0x33, 0x33, 0x00, 0x00, 0x00, 0xFB } }; + +/** @brief multicast DNS IPv6 address */ +const IPv6_Address_t ipMDNS_IP_ADDR_IPv6 = +{ + { /* ff02::fb */ + 0xff, 0x02, + 0x00, 0x00, + 0x00, 0x00, + 0x00, 0x00, + 0x00, 0x00, + 0x00, 0x00, + 0x00, 0x00, + 0x00, 0xfb, + } +}; + /* Exclude the entire file if DNS is not enabled. */ #if ( ipconfigUSE_DNS != 0 ) @@ -95,73 +137,10 @@ struct freertos_addrinfo ** ppxAddressInfo, BaseType_t xFamily ); - #if ( ipconfigUSE_LLMNR == 1 ) - /** @brief The MAC address used for LLMNR. */ - const MACAddress_t xLLMNR_MacAddress = { { 0x01, 0x00, 0x5e, 0x00, 0x00, 0xfc } }; - #endif /* ipconfigUSE_LLMNR == 1 */ - /*-----------------------------------------------------------*/ - #if ( ipconfigUSE_LLMNR == 1 ) && ( ipconfigUSE_IPv6 != 0 ) - -/** - * @brief The IPv6 link-scope multicast address - */ - const IPv6_Address_t ipLLMNR_IP_ADDR_IPv6 = - { - { /* ff02::1:3 */ - 0xff, 0x02, - 0x00, 0x00, - 0x00, 0x00, - 0x00, 0x00, - 0x00, 0x00, - 0x00, 0x00, - 0x00, 0x01, - 0x00, 0x03, - } - }; - -/** - * @brief The IPv6 link-scope multicast MAC address - */ - const MACAddress_t xLLMNR_MacAddressIPv6 = { { 0x33, 0x33, 0x00, 0x01, 0x00, 0x03 } }; - #endif /* ipconfigUSE_LLMNR && ipconfigUSE_IPv6 */ - - #if ( ipconfigUSE_MDNS == 1 ) && ( ipconfigUSE_IPv6 != 0 ) - -/** - * @brief multicast DNS IPv6 address - */ - const IPv6_Address_t ipMDNS_IP_ADDR_IPv6 = - { - { /* ff02::fb */ - 0xff, 0x02, - 0x00, 0x00, - 0x00, 0x00, - 0x00, 0x00, - 0x00, 0x00, - 0x00, 0x00, - 0x00, 0x00, - 0x00, 0xfb, - } - }; - -/** - * @brief The IPv6 multicast DNS MAC address. - * The MAC-addresses are provided here in case a network - * interface needs it. - */ - const MACAddress_t xMDNS_MACAddressIPv6 = { { 0x33, 0x33, 0x00, 0x00, 0x00, 0xFB } }; - #endif /* ( ipconfigUSE_MDNS == 1 ) && ( ipconfigUSE_IPv6 != 0 ) */ - - - #if ( ipconfigUSE_MDNS == 1 ) - /** @brief The MAC address used for MDNS. */ - const MACAddress_t xMDNS_MacAddress = { { 0x01, 0x00, 0x5e, 0x00, 0x00, 0xfb } }; - #endif /* ipconfigUSE_MDNS == 1 */ /** @brief This global variable is being used to indicate to the driver which IP type * is preferred for name service lookup, either IPv6 or IPv4. */ -/* TODO: Fix IPv6 DNS query in Windows Simulator. */ IPPreference_t xDNS_IP_Preference = xPreferenceIPv4; /*-----------------------------------------------------------*/ @@ -609,6 +588,10 @@ BaseType_t xHasRandom = pdFALSE; TickType_t uxIdentifier = 0U; + #if ( ipconfigDNS_USE_CALLBACKS == 1 ) + BaseType_t xReturnSetCallback = pdPASS; + #endif + #if ( ipconfigUSE_DNS_CACHE != 0 ) BaseType_t xLengthOk = pdFALSE; #endif @@ -657,7 +640,7 @@ if( ulIPAddress != 0UL ) { #if ( ipconfigUSE_IPv6 != 0 ) - if( ( ppxAddressInfo != NULL ) && ( ( *ppxAddressInfo )->ai_family == FREERTOS_AF_INET6 ) ) + if( ( ppxAddressInfo != NULL ) && ( *ppxAddressInfo != NULL ) && ( ( *ppxAddressInfo )->ai_family == FREERTOS_AF_INET6 ) ) { FreeRTOS_printf( ( "prvPrepareLookup: found '%s' in cache: %pip\n", pcHostName, ( void * ) ( *ppxAddressInfo )->xPrivateStorage.sockaddr.sin_address.xIP_IPv6.ucBytes ) ); @@ -691,12 +674,12 @@ if( xHasRandom != pdFALSE ) { uxReadTimeOut_ticks = 0U; - vDNSSetCallBack( pcHostName, - pvSearchID, - pCallbackFunction, - uxTimeout, - ( TickType_t ) uxIdentifier, - ( xFamily == FREERTOS_AF_INET6 ) ? pdTRUE : pdFALSE ); + xReturnSetCallback = xDNSSetCallBack( pcHostName, + pvSearchID, + pCallbackFunction, + uxTimeout, + ( TickType_t ) uxIdentifier, + ( xFamily == FREERTOS_AF_INET6 ) ? pdTRUE : pdFALSE ); } } else /* When ipconfigDNS_USE_CALLBACKS enabled, ppxAddressInfo is always non null. */ @@ -708,7 +691,13 @@ } #endif /* if ( ipconfigDNS_USE_CALLBACKS == 1 ) */ - if( ( ulIPAddress == 0U ) && ( xHasRandom != pdFALSE ) ) + if( ( ulIPAddress == 0U ) && + + #if ( ipconfigDNS_USE_CALLBACKS == 1 ) + ( xReturnSetCallback == pdPASS ) && + #endif + + ( xHasRandom != pdFALSE ) ) { ulIPAddress = prvGetHostByName( pcHostName, uxIdentifier, @@ -1250,17 +1239,6 @@ /* Make sure all fields of the 'sockaddr' are cleared. */ ( void ) memset( ( void * ) &xAddress, 0, sizeof( xAddress ) ); - #if ( ipconfigUSE_IPv6 != 0 ) - if( xFamily == ( BaseType_t ) FREERTOS_AF_INET6 ) - { - xDNS_IP_Preference = xPreferenceIPv6; - } - else - { - xDNS_IP_Preference = xPreferenceIPv4; - } - #endif /* ( ipconfigUSE_IPv6 != 0 ) */ - pxEndPoint = prvFillSockAddress( &xAddress, pcHostName ); if( pxEndPoint != NULL ) @@ -1519,7 +1497,7 @@ uxIndex = uxStart + 1U; /* Copy in the host name. */ - ( void ) strcpy( ( char * ) &( pucUDPPayloadBuffer[ uxIndex ] ), pcHostName ); + ( void ) strncpy( ( char * ) &( pucUDPPayloadBuffer[ uxIndex ] ), pcHostName, strlen( pcHostName ) + 1U ); /* Walk through the string to replace the '.' characters with byte * counts. pucStart holds the address of the byte count. Walking the @@ -1649,6 +1627,42 @@ /*-----------------------------------------------------------*/ +/** + * @brief Sets the DNS IP preference while doing DNS lookup to indicate the preference + * for a DNS server: either IPv4 or IPv6. Defaults to xPreferenceIPv4 + * @param[in] eIPPreference IP preference, can be either xPreferenceIPv4 or + * xPreferenceIPv6 + * @return pdPASS on success and pdFAIL on failure. + */ + BaseType_t FreeRTOS_SetDNSIPPreference( IPPreference_t eIPPreference ) + { + BaseType_t xReturn = pdPASS; + + switch( eIPPreference ) + { + #if ( ipconfigUSE_IPv4 != 0 ) + case xPreferenceIPv4: + xDNS_IP_Preference = xPreferenceIPv4; + break; + #endif + + #if ( ipconfigUSE_IPv6 != 0 ) + case xPreferenceIPv6: + xDNS_IP_Preference = xPreferenceIPv6; + break; + #endif + + default: + xReturn = pdFAIL; + FreeRTOS_printf( ( "Invalid DNS IPPreference_t\n" ) ); + break; + } + + return xReturn; + } + +/*-----------------------------------------------------------*/ + #endif /* ipconfigUSE_DNS != 0 */ /*-----------------------------------------------------------*/ diff --git a/source/FreeRTOS_DNS_Cache.c b/source/FreeRTOS_DNS_Cache.c index 4c3f5715ae..119be881d1 100644 --- a/source/FreeRTOS_DNS_Cache.c +++ b/source/FreeRTOS_DNS_Cache.c @@ -448,10 +448,9 @@ /* Add or update the item. */ if( strlen( pcName ) < ( size_t ) ipconfigDNS_CACHE_NAME_LENGTH ) { - ( void ) strcpy( xDNSCache[ uxFreeEntry ].pcName, pcName ); + ( void ) strncpy( xDNSCache[ uxFreeEntry ].pcName, pcName, strlen( pcName ) ); ( void ) memcpy( &( xDNSCache[ uxFreeEntry ].xAddresses[ 0 ] ), pxIP, sizeof( *pxIP ) ); - xDNSCache[ uxFreeEntry ].ulTTL = ulTTL; xDNSCache[ uxFreeEntry ].ulTimeWhenAddedInSeconds = ulCurrentTimeSeconds; #if ( ipconfigDNS_CACHE_ADDRESSES_PER_ENTRY > 1 ) diff --git a/source/FreeRTOS_DNS_Callback.c b/source/FreeRTOS_DNS_Callback.c index 6aaf7172df..15bddbfe51 100644 --- a/source/FreeRTOS_DNS_Callback.c +++ b/source/FreeRTOS_DNS_Callback.c @@ -129,13 +129,14 @@ * @param[in] uxIdentifier Random number used as ID in the DNS message. * @param[in] xIsIPv6 pdTRUE if the address type should be IPv6. */ - void vDNSSetCallBack( const char * pcHostName, - void * pvSearchID, - FOnDNSEvent pCallbackFunction, - TickType_t uxTimeout, - TickType_t uxIdentifier, - BaseType_t xIsIPv6 ) + BaseType_t xDNSSetCallBack( const char * pcHostName, + void * pvSearchID, + FOnDNSEvent pCallbackFunction, + TickType_t uxTimeout, + TickType_t uxIdentifier, + BaseType_t xIsIPv6 ) { + BaseType_t xReturn = pdPASS; size_t lLength = strlen( pcHostName ); /* MISRA Ref 4.12.1 [Use of dynamic memory]. */ @@ -154,7 +155,7 @@ vDNSTimerReload( FreeRTOS_min_uint32( 1000U, ( uint32_t ) uxTimeout ) ); } - ( void ) strcpy( pxCallback->pcName, pcHostName ); + ( void ) strncpy( pxCallback->pcName, pcHostName, lLength + 1U ); pxCallback->pCallbackFunction = pCallbackFunction; pxCallback->pvSearchID = pvSearchID; pxCallback->uxRemainingTime = uxTimeout; @@ -171,9 +172,12 @@ } else { - FreeRTOS_debug_printf( ( " vDNSSetCallBack : Could not allocate memory: %u bytes", + xReturn = pdFAIL; + FreeRTOS_debug_printf( ( " xDNSSetCallBack : Could not allocate memory: %u bytes", ( unsigned ) ( sizeof( *pxCallback ) + lLength ) ) ); } + + return xReturn; } /*-----------------------------------------------------------*/ diff --git a/source/FreeRTOS_DNS_Parser.c b/source/FreeRTOS_DNS_Parser.c index c1148a646d..13fb75a858 100644 --- a/source/FreeRTOS_DNS_Parser.c +++ b/source/FreeRTOS_DNS_Parser.c @@ -250,7 +250,6 @@ * An error code (dnsPARSE_ERROR) if there was an error in the DNS response. * 0 if xExpected set to pdFALSE. */ -/* TODO cross check again */ uint32_t DNS_ParseDNSReply( uint8_t * pucUDPPayloadBuffer, size_t uxBufferLength, struct freertos_addrinfo ** ppxAddressInfo, @@ -296,21 +295,53 @@ { size_t uxBytesRead = 0U; size_t uxResult; + BaseType_t xIsResponse = pdFALSE; /* Start at the first byte after the header. */ xSet.pucUDPPayloadBuffer = pucUDPPayloadBuffer; + /* Skip 12-byte header. */ xSet.pucByte = &( pucUDPPayloadBuffer[ sizeof( DNSMessage_t ) ] ); xSet.uxSourceBytesRemaining -= sizeof( DNSMessage_t ); - /* Skip any question records. */ + /* The number of questions supplied. */ xSet.usQuestions = FreeRTOS_ntohs( xSet.pxDNSMessageHeader->usQuestions ); + /* The number of answer records. */ + xSet.usAnswers = FreeRTOS_ntohs( xSet.pxDNSMessageHeader->usAnswers ); - if( xSet.usQuestions == 0U ) + if( ( xSet.pxDNSMessageHeader->usFlags & dnsRX_FLAGS_MASK ) == dnsEXPECTED_RX_FLAGS ) { - /* The IP-stack will only accept DNS replies that have a copy - * of the questions. */ - xReturn = pdFALSE; - break; + xIsResponse = pdTRUE; + + if( xSet.usAnswers == 0U ) + { + /* This is a response that does not include answers. */ + xReturn = pdFALSE; + break; + } + + if( xSet.usQuestions == 0U ) + { + #if ( ( ipconfigUSE_LLMNR == 1 ) || ( ipconfigUSE_MDNS == 1 ) ) + { + xSet.pcRequestedName = ( char * ) xSet.pucByte; + } + #endif + + #if ( ipconfigUSE_DNS_CACHE == 1 ) || ( ipconfigDNS_USE_CALLBACKS == 1 ) + uxResult = DNS_ReadNameField( &xSet, + sizeof( xSet.pcName ) ); + ( void ) uxResult; + #endif + } + } + else + { + if( xSet.usQuestions == 0U ) + { + /* This is a query that does not include any question. */ + xReturn = pdFALSE; + break; + } } for( x = 0U; x < xSet.usQuestions; x++ ) @@ -329,6 +360,7 @@ { uxResult = DNS_ReadNameField( &xSet, sizeof( xSet.pcName ) ); + ( void ) uxResult; } else #endif /* ipconfigUSE_DNS_CACHE || ipconfigDNS_USE_CALLBACKS */ @@ -377,13 +409,9 @@ break; } - /* Search through the answer records. */ - xSet.pxDNSMessageHeader->usAnswers = - FreeRTOS_ntohs( xSet.pxDNSMessageHeader->usAnswers ); - - if( ( xSet.pxDNSMessageHeader->usFlags & dnsRX_FLAGS_MASK ) - == dnsEXPECTED_RX_FLAGS ) + if( xIsResponse == pdTRUE ) { + /* Search through the answer records. */ ulIPAddress = parseDNSAnswer( &( xSet ), ppxAddressInfo, &uxBytesRead ); } @@ -589,7 +617,7 @@ } /** - * @brief perform a dns lookup in the local cache {TODO WRONG} + * @brief Process DNS answer field in a DNS response packet from a DNS server. * @param[in] pxSet a set of variables that are shared among the helper functions. * @param[out] ppxAddressInfo a linked list storing the DNS answers. * @param[out] uxBytesRead total bytes consumed by the function @@ -609,7 +637,7 @@ struct freertos_addrinfo * pxNewAddress = NULL; - for( x = 0U; x < pxSet->pxDNSMessageHeader->usAnswers; x++ ) + for( x = 0U; x < pxSet->usAnswers; x++ ) { BaseType_t xDoAccept = pdFALSE; @@ -620,7 +648,7 @@ } uxResult = DNS_SkipNameField( pxSet->pucByte, - sizeof( pxSet->pcName ) ); + pxSet->uxSourceBytesRemaining ); /* Check for a malformed response. */ if( uxResult == 0U ) @@ -658,7 +686,7 @@ } else if( pxSet->usType == ( uint16_t ) dnsTYPE_A_HOST ) { - pxSet->uxAddressLength = ipSIZE_OF_IPv4_ADDRESS; /*TODO check if fine */ + pxSet->uxAddressLength = ipSIZE_OF_IPv4_ADDRESS; if( pxSet->uxSourceBytesRemaining >= ( sizeof( DNSAnswerRecord_t ) + pxSet->uxAddressLength ) ) { diff --git a/source/FreeRTOS_IP.c b/source/FreeRTOS_IP.c index 2ca7ba98e1..e9b5ef0297 100644 --- a/source/FreeRTOS_IP.c +++ b/source/FreeRTOS_IP.c @@ -92,19 +92,11 @@ #endif #endif -/** @brief If ipconfigETHERNET_DRIVER_FILTERS_FRAME_TYPES is set to 1, then the Ethernet - * driver will filter incoming packets and only pass the stack those packets it - * considers need processing. In this case ipCONSIDER_FRAME_FOR_PROCESSING() can - * be #-defined away. If ipconfigETHERNET_DRIVER_FILTERS_FRAME_TYPES is set to 0 - * then the Ethernet driver will pass all received packets to the stack, and the - * stack must do the filtering itself. In this case ipCONSIDER_FRAME_FOR_PROCESSING - * needs to call eConsiderFrameForProcessing. - */ -#if ipconfigETHERNET_DRIVER_FILTERS_FRAME_TYPES == 0 - #define ipCONSIDER_FRAME_FOR_PROCESSING( pucEthernetBuffer ) eConsiderFrameForProcessing( ( pucEthernetBuffer ) ) -#else - #define ipCONSIDER_FRAME_FOR_PROCESSING( pucEthernetBuffer ) eProcessBuffer -#endif +/** @brief The frame type field in the Ethernet header must have a value greater than 0x0600. + * If the configuration option ipconfigFILTER_OUT_NON_ETHERNET_II_FRAMES is enabled, the stack + * will discard packets with a frame type value less than or equal to 0x0600. + * However, if this option is disabled, the stack will continue to process these packets. */ +#define ipIS_ETHERNET_FRAME_TYPE_INVALID( usFrameType ) ( ( usFrameType ) <= 0x0600U ) static void prvCallDHCP_RA_Handler( NetworkEndPoint_t * pxEndPoint ); @@ -1451,85 +1443,165 @@ BaseType_t xSendEventStructToIPTask( const IPStackEvent_t * pxEvent, */ eFrameProcessingResult_t eConsiderFrameForProcessing( const uint8_t * const pucEthernetBuffer ) { - eFrameProcessingResult_t eReturn = eProcessBuffer; - const EthernetHeader_t * pxEthernetHeader = NULL; - const NetworkEndPoint_t * pxEndPoint = NULL; + eFrameProcessingResult_t eReturn = eReleaseBuffer; - if( pucEthernetBuffer == NULL ) - { - eReturn = eReleaseBuffer; - } - else + do { - /* Map the buffer onto Ethernet Header struct for easy access to fields. */ + const EthernetHeader_t * pxEthernetHeader = NULL; + const NetworkEndPoint_t * pxEndPoint = NULL; + uint16_t usFrameType; + + /* First, check the packet buffer is non-null. */ + if( pucEthernetBuffer == NULL ) + { + /* The packet buffer was null - release it. */ + break; + } + /* Map the buffer onto Ethernet Header struct for easy access to fields. */ /* MISRA Ref 11.3.1 [Misaligned access] */ /* More details at: https://github.com/FreeRTOS/FreeRTOS-Plus-TCP/blob/main/MISRA.md#rule-113 */ /* coverity[misra_c_2012_rule_11_3_violation] */ pxEthernetHeader = ( ( const EthernetHeader_t * ) pucEthernetBuffer ); + usFrameType = pxEthernetHeader->usFrameType; - /* Examine the destination MAC from the Ethernet header to see if it matches - * that of an end point managed by FreeRTOS+TCP. */ + /* Second, filter based on ethernet frame type. */ + /* The frame type field in the Ethernet header must have a value greater than 0x0600. */ + if( ipIS_ETHERNET_FRAME_TYPE_INVALID( FreeRTOS_ntohs( usFrameType ) ) ) + { + /* The packet was not an Ethernet II frame */ + #if ipconfigIS_ENABLED( ipconfigFILTER_OUT_NON_ETHERNET_II_FRAMES ) + /* filtering is enabled - release it. */ + break; + #else + /* filtering is disabled - continue filter checks. */ + #endif + } + else if( usFrameType == ipARP_FRAME_TYPE ) + { + /* The frame is an ARP type */ + #if ipconfigIS_DISABLED( ipconfigUSE_IPv4 ) + /* IPv4 is disabled - release it. */ + break; + #else + /* IPv4 is enabled - Continue filter checks. */ + #endif + } + else if( usFrameType == ipIPv4_FRAME_TYPE ) + { + /* The frame is an IPv4 type */ + #if ipconfigIS_DISABLED( ipconfigUSE_IPv4 ) + /* IPv4 is disabled - release it. */ + break; + #else + /* IPv4 is enabled - Continue filter checks. */ + #endif + } + else if( usFrameType == ipIPv6_FRAME_TYPE ) + { + /* The frame is an IPv6 type */ + #if ipconfigIS_DISABLED( ipconfigUSE_IPv6 ) + /* IPv6 is disabled - release it. */ + break; + #else + /* IPv6 is enabled - Continue filter checks. */ + #endif + } + else + { + /* The frame is an unsupported Ethernet II type */ + #if ipconfigIS_DISABLED( ipconfigPROCESS_CUSTOM_ETHERNET_FRAMES ) + /* Processing custom ethernet frames is disabled - release it. */ + break; + #else + /* Processing custom ethernet frames is enabled - Continue filter checks. */ + #endif + } + + /* Third, filter based on destination mac address. */ pxEndPoint = FreeRTOS_FindEndPointOnMAC( &( pxEthernetHeader->xDestinationAddress ), NULL ); if( pxEndPoint != NULL ) { - /* The packet was directed to this node - process it. */ - eReturn = eProcessBuffer; + /* A destination endpoint was found - Continue filter checks. */ } else if( memcmp( xBroadcastMACAddress.ucBytes, pxEthernetHeader->xDestinationAddress.ucBytes, sizeof( MACAddress_t ) ) == 0 ) { - /* The packet was a broadcast - process it. */ - eReturn = eProcessBuffer; + /* The packet was a broadcast - Continue filter checks. */ } - else - #if ( ( ipconfigUSE_LLMNR == 1 ) && ( ipconfigUSE_DNS != 0 ) ) - if( memcmp( xLLMNR_MacAddress.ucBytes, pxEthernetHeader->xDestinationAddress.ucBytes, sizeof( MACAddress_t ) ) == 0 ) - { - /* The packet is a request for LLMNR - process it. */ - eReturn = eProcessBuffer; - } - else - #endif /* ipconfigUSE_LLMNR */ - #if ( ( ipconfigUSE_MDNS == 1 ) && ( ipconfigUSE_DNS != 0 ) ) - if( memcmp( xMDNS_MacAddress.ucBytes, pxEthernetHeader->xDestinationAddress.ucBytes, sizeof( MACAddress_t ) ) == 0 ) - { - /* The packet is a request for MDNS - process it. */ - eReturn = eProcessBuffer; - } - else - #endif /* ipconfigUSE_MDNS */ - if( ( pxEthernetHeader->xDestinationAddress.ucBytes[ 0 ] == ipMULTICAST_MAC_ADDRESS_IPv6_0 ) && - ( pxEthernetHeader->xDestinationAddress.ucBytes[ 1 ] == ipMULTICAST_MAC_ADDRESS_IPv6_1 ) ) + else if( memcmp( xLLMNR_MacAddress.ucBytes, pxEthernetHeader->xDestinationAddress.ucBytes, sizeof( MACAddress_t ) ) == 0 ) { - /* The packet is a request for LLMNR - process it. */ - eReturn = eProcessBuffer; + /* The packet is a request for LLMNR using IPv4 */ + #if ( ipconfigIS_DISABLED( ipconfigUSE_DNS ) || ipconfigIS_DISABLED( ipconfigUSE_LLMNR ) || ipconfigIS_DISABLED( ipconfigUSE_IPv4 ) ) + /* DNS, LLMNR, or IPv4 is disabled - release it. */ + break; + #else + /* DNS, LLMNR, and IPv4 are enabled - Continue filter checks. */ + #endif } - else + else if( memcmp( xLLMNR_MacAddressIPv6.ucBytes, pxEthernetHeader->xDestinationAddress.ucBytes, sizeof( MACAddress_t ) ) == 0 ) { - /* The packet was not a broadcast, or for this node, just release - * the buffer without taking any other action. */ - eReturn = eReleaseBuffer; + /* The packet is a request for LLMNR using IPv6 */ + #if ( ipconfigIS_DISABLED( ipconfigUSE_DNS ) || ipconfigIS_DISABLED( ipconfigUSE_LLMNR ) || ipconfigIS_DISABLED( ipconfigUSE_IPv6 ) ) + /* DNS, LLMNR, or IPv6 is disabled - release it. */ + break; + #else + /* DNS, LLMNR, and IPv6 are enabled - Continue filter checks. */ + #endif } - } - - #if ( ipconfigFILTER_OUT_NON_ETHERNET_II_FRAMES == 1 ) - { - uint16_t usFrameType; - - if( eReturn == eProcessBuffer ) + else if( memcmp( xMDNS_MacAddress.ucBytes, pxEthernetHeader->xDestinationAddress.ucBytes, sizeof( MACAddress_t ) ) == 0 ) { - usFrameType = pxEthernetHeader->usFrameType; - usFrameType = FreeRTOS_ntohs( usFrameType ); - - if( usFrameType <= 0x600U ) - { - /* Not an Ethernet II frame. */ - eReturn = eReleaseBuffer; - } + /* The packet is a request for MDNS using IPv4 */ + #if ( ipconfigIS_DISABLED( ipconfigUSE_DNS ) || ipconfigIS_DISABLED( ipconfigUSE_MDNS ) || ipconfigIS_DISABLED( ipconfigUSE_IPv4 ) ) + /* DNS, MDNS, or IPv4 is disabled - release it. */ + break; + #else + /* DNS, MDNS, and IPv4 are enabled - Continue filter checks. */ + #endif + } + else if( memcmp( xMDNS_MacAddressIPv6.ucBytes, pxEthernetHeader->xDestinationAddress.ucBytes, sizeof( MACAddress_t ) ) == 0 ) + { + /* The packet is a request for MDNS using IPv6 */ + #if ( ipconfigIS_DISABLED( ipconfigUSE_DNS ) || ipconfigIS_DISABLED( ipconfigUSE_MDNS ) || ipconfigIS_DISABLED( ipconfigUSE_IPv6 ) ) + /* DNS, MDNS, or IPv6 is disabled - release it. */ + break; + #else + /* DNS, MDNS, and IPv6 are enabled - Continue filter checks. */ + #endif + } + else if( ( pxEthernetHeader->xDestinationAddress.ucBytes[ 0 ] == ipMULTICAST_MAC_ADDRESS_IPv4_0 ) && + ( pxEthernetHeader->xDestinationAddress.ucBytes[ 1 ] == ipMULTICAST_MAC_ADDRESS_IPv4_1 ) && + ( pxEthernetHeader->xDestinationAddress.ucBytes[ 2 ] == ipMULTICAST_MAC_ADDRESS_IPv4_2 ) && + ( pxEthernetHeader->xDestinationAddress.ucBytes[ 3 ] <= 0x7fU ) ) + { + /* The packet is an IPv4 Multicast */ + #if ipconfigIS_DISABLED( ipconfigUSE_IPv4 ) + /* IPv4 is disabled - release it. */ + break; + #else + /* IPv4 is enabled - Continue filter checks. */ + #endif + } + else if( ( pxEthernetHeader->xDestinationAddress.ucBytes[ 0 ] == ipMULTICAST_MAC_ADDRESS_IPv6_0 ) && + ( pxEthernetHeader->xDestinationAddress.ucBytes[ 1 ] == ipMULTICAST_MAC_ADDRESS_IPv6_1 ) ) + { + /* The packet is an IPv6 Multicast */ + #if ipconfigIS_DISABLED( ipconfigUSE_IPv6 ) + /* IPv6 is disabled - release it. */ + break; + #else + /* IPv6 is enabled - Continue filter checks. */ + #endif + } + else + { + /* The packet was not a broadcast, or for this node - release it */ + break; } - } - #endif /* ipconfigFILTER_OUT_NON_ETHERNET_II_FRAMES == 1 */ + + /* All checks have been passed, process the packet. */ + eReturn = eProcessBuffer; + } while( ipFALSE_BOOL ); return eReturn; } @@ -1575,8 +1647,6 @@ static void prvProcessEthernetPacket( NetworkBufferDescriptor_t * const pxNetwor break; } - eReturned = ipCONSIDER_FRAME_FOR_PROCESSING( pxNetworkBuffer->pucEthernetBuffer ); - /* Map the buffer onto the Ethernet Header struct for easy access to the fields. */ /* MISRA Ref 11.3.1 [Misaligned access] */ @@ -1586,7 +1656,7 @@ static void prvProcessEthernetPacket( NetworkBufferDescriptor_t * const pxNetwor /* The condition "eReturned == eProcessBuffer" must be true. */ #if ( ipconfigETHERNET_DRIVER_FILTERS_FRAME_TYPES == 0 ) - if( eReturned == eProcessBuffer ) + if( eConsiderFrameForProcessing( pxNetworkBuffer->pucEthernetBuffer ) == eProcessBuffer ) #endif { /* Interpret the received Ethernet packet. */ @@ -1983,7 +2053,6 @@ static eFrameProcessingResult_t prvProcessIPPacket( const IPPacket_t * pxIPPacke } } - /* TODO: eReturn != eReleaseBuffer */ if( eReturn != eWaitingResolution ) { switch( ucProtocol ) @@ -2124,7 +2193,7 @@ void vReturnEthernetFrame( NetworkBufferDescriptor_t * pxNetworkBuffer, #if ( ipconfigUSE_IPv4 != 0 ) case ipIPv4_FRAME_TYPE: - pxNetworkBuffer->pxEndPoint = FreeRTOS_FindEndPointOnNetMask( pxIPPacket->xIPHeader.ulDestinationIPAddress, 7 ); + pxNetworkBuffer->pxEndPoint = FreeRTOS_FindEndPointOnNetMask( pxIPPacket->xIPHeader.ulDestinationIPAddress ); break; #endif /* ( ipconfigUSE_IPv4 != 0 ) */ diff --git a/source/FreeRTOS_IPv4.c b/source/FreeRTOS_IPv4.c index d095f1266e..bd8ab19197 100644 --- a/source/FreeRTOS_IPv4.c +++ b/source/FreeRTOS_IPv4.c @@ -318,7 +318,7 @@ enum eFrameProcessingResult prvAllowIPPacketIPv4( const struct xIP_PACKET * cons } } else if( - ( FreeRTOS_FindEndPointOnIP_IPv4( ulDestinationIPAddress, 4 ) == NULL ) && + ( FreeRTOS_FindEndPointOnIP_IPv4( ulDestinationIPAddress ) == NULL ) && /* Is it an IPv4 broadcast address x.x.x.255 ? */ ( ( FreeRTOS_ntohl( ulDestinationIPAddress ) & 0xffU ) != 0xffU ) && ( xIsIPv4Multicast( ulDestinationIPAddress ) == pdFALSE ) && diff --git a/source/FreeRTOS_IPv4_Utils.c b/source/FreeRTOS_IPv4_Utils.c index b79bdc8de8..f7c1d3f847 100644 --- a/source/FreeRTOS_IPv4_Utils.c +++ b/source/FreeRTOS_IPv4_Utils.c @@ -59,9 +59,9 @@ void vSetMultiCastIPv4MacAddress( uint32_t ulIPAddress, { uint32_t ulIP = FreeRTOS_ntohl( ulIPAddress ); - pxMACAddress->ucBytes[ 0 ] = ( uint8_t ) 0x01U; - pxMACAddress->ucBytes[ 1 ] = ( uint8_t ) 0x00U; - pxMACAddress->ucBytes[ 2 ] = ( uint8_t ) 0x5EU; + pxMACAddress->ucBytes[ 0 ] = ( uint8_t ) ipMULTICAST_MAC_ADDRESS_IPv4_0; + pxMACAddress->ucBytes[ 1 ] = ( uint8_t ) ipMULTICAST_MAC_ADDRESS_IPv4_1; + pxMACAddress->ucBytes[ 2 ] = ( uint8_t ) ipMULTICAST_MAC_ADDRESS_IPv4_2; pxMACAddress->ucBytes[ 3 ] = ( uint8_t ) ( ( ulIP >> 16 ) & 0x7fU ); /* Use 7 bits. */ pxMACAddress->ucBytes[ 4 ] = ( uint8_t ) ( ( ulIP >> 8 ) & 0xffU ); /* Use 8 bits. */ pxMACAddress->ucBytes[ 5 ] = ( uint8_t ) ( ( ulIP ) & 0xffU ); /* Use 8 bits. */ diff --git a/source/FreeRTOS_IPv6_Utils.c b/source/FreeRTOS_IPv6_Utils.c index f35995bb5a..9e9f2abd6d 100644 --- a/source/FreeRTOS_IPv6_Utils.c +++ b/source/FreeRTOS_IPv6_Utils.c @@ -55,8 +55,8 @@ void vSetMultiCastIPv6MacAddress( const IPv6_Address_t * pxAddress, MACAddress_t * pxMACAddress ) { - pxMACAddress->ucBytes[ 0 ] = 0x33U; - pxMACAddress->ucBytes[ 1 ] = 0x33U; + pxMACAddress->ucBytes[ 0 ] = ipMULTICAST_MAC_ADDRESS_IPv6_0; + pxMACAddress->ucBytes[ 1 ] = ipMULTICAST_MAC_ADDRESS_IPv6_1; pxMACAddress->ucBytes[ 2 ] = pxAddress->ucBytes[ 12 ]; pxMACAddress->ucBytes[ 3 ] = pxAddress->ucBytes[ 13 ]; pxMACAddress->ucBytes[ 4 ] = pxAddress->ucBytes[ 14 ]; diff --git a/source/FreeRTOS_RA.c b/source/FreeRTOS_RA.c index 956c56fa60..a9ef1fc8b0 100644 --- a/source/FreeRTOS_RA.c +++ b/source/FreeRTOS_RA.c @@ -488,7 +488,7 @@ if( pxEndPoint->xRAData.bits.bRouterReplied != pdFALSE_UNSIGNED ) { /* Obtained configuration from a router. */ - uxNewReloadTime = pdMS_TO_TICKS( 1000U * pxEndPoint->xRAData.ulPreferredLifeTime ); + uxNewReloadTime = pdMS_TO_TICKS( ( 1000U * ( uint64_t ) pxEndPoint->xRAData.ulPreferredLifeTime ) ); pxEndPoint->xRAData.eRAState = eRAStatePreLease; iptraceRA_SUCCEEDED( &( pxEndPoint->ipv6_settings.xIPAddress ) ); FreeRTOS_printf( ( "RA: succeeded, using IP address %pip Reload after %u seconds\n", diff --git a/source/FreeRTOS_Routing.c b/source/FreeRTOS_Routing.c index 2abeafe8b2..a480568639 100644 --- a/source/FreeRTOS_Routing.c +++ b/source/FreeRTOS_Routing.c @@ -141,12 +141,6 @@ struct xIPv6_Couple #if ( ipconfigCOMPATIBLE_WITH_SINGLE == 0 ) - #if ( ipconfigHAS_ROUTING_STATISTICS == 1 ) - RoutingStats_t xRoutingStatistics; - #endif - -/*-----------------------------------------------------------*/ - /** * @brief Add a network interface to the list of interfaces. Check if the interface was * already added in an earlier call. @@ -380,29 +374,13 @@ struct xIPv6_Couple * @brief Find the end-point which has a given IPv4 address. * * @param[in] ulIPAddress The IP-address of interest, or 0 if any IPv4 end-point may be returned. - * @param[in] ulWhere For maintaining routing statistics ulWhere acts as an index to the data structure - * that keep track of the number of times 'FreeRTOS_FindEndPointOnIP_IPv4()' - * has been called from a particular location. Used only if - * ipconfigHAS_ROUTING_STATISTICS is enabled. * * @return The end-point found or NULL. */ - NetworkEndPoint_t * FreeRTOS_FindEndPointOnIP_IPv4( uint32_t ulIPAddress, - uint32_t ulWhere ) + NetworkEndPoint_t * FreeRTOS_FindEndPointOnIP_IPv4( uint32_t ulIPAddress ) { NetworkEndPoint_t * pxEndPoint = pxNetworkEndPoints; - #if ( ipconfigHAS_ROUTING_STATISTICS == 1 ) - uint32_t ulLocationCount = ( uint32_t ) ( sizeof( xRoutingStatistics.ulLocationsIP ) / sizeof( xRoutingStatistics.ulLocationsIP[ 0 ] ) ); - - xRoutingStatistics.ulOnIp++; - - if( ulWhere < ulLocationCount ) - { - xRoutingStatistics.ulLocationsIP[ ulWhere ]++; - } - #endif /* ( ipconfigHAS_ROUTING_STATISTICS == 1 ) */ - while( pxEndPoint != NULL ) { #if ( ipconfigUSE_IPv4 != 0 ) @@ -457,12 +435,6 @@ struct xIPv6_Couple { NetworkEndPoint_t * pxEndPoint = pxNetworkEndPoints; - #if ( ipconfigHAS_ROUTING_STATISTICS == 1 ) - { - xRoutingStatistics.ulOnMAC++; - } - #endif - /* If input MAC address is NULL, return NULL. */ if( pxMACAddress == NULL ) { @@ -496,18 +468,12 @@ struct xIPv6_Couple * @brief Find an end-point that handles a given IPv4-address. * * @param[in] ulIPAddress The IP-address for which an end-point is looked-up. - * @param[in] ulWhere For maintaining routing statistics ulWhere acts as an index to the data structure - * that keep track of the number of times 'FreeRTOS_InterfaceEndPointOnNetMask()' - * has been called from a particular location. Used only if - * ipconfigHAS_ROUTING_STATISTICS is enabled. * * @return An end-point that has the same network mask as the given IP-address. */ - NetworkEndPoint_t * FreeRTOS_FindEndPointOnNetMask( uint32_t ulIPAddress, - uint32_t ulWhere ) + NetworkEndPoint_t * FreeRTOS_FindEndPointOnNetMask( uint32_t ulIPAddress ) { - /* The 'ulWhere' parameter is only for debugging purposes. */ - return FreeRTOS_InterfaceEndPointOnNetMask( NULL, ulIPAddress, ulWhere ); + return FreeRTOS_InterfaceEndPointOnNetMask( NULL, ulIPAddress ); } /*-----------------------------------------------------------*/ @@ -518,30 +484,13 @@ struct xIPv6_Couple * pxInterface is NULL. * @param[in] ulIPAddress The IP-address for which an end-point is looked-up. * - * @param[in] ulWhere For maintaining routing statistics ulWhere acts as an index to the data structure - * that keep track of the number of times 'FreeRTOS_InterfaceEndPointOnNetMask()' - * has been called from a particular location. Used only if - * ipconfigHAS_ROUTING_STATISTICS is enabled. - * * @return An end-point that has the same network mask as the given IP-address. */ NetworkEndPoint_t * FreeRTOS_InterfaceEndPointOnNetMask( const NetworkInterface_t * pxInterface, - uint32_t ulIPAddress, - uint32_t ulWhere ) + uint32_t ulIPAddress ) { NetworkEndPoint_t * pxEndPoint = pxNetworkEndPoints; - #if ( ipconfigHAS_ROUTING_STATISTICS == 1 ) - uint32_t ulLocationCount = ( uint32_t ) ( sizeof( xRoutingStatistics.ulLocations ) / sizeof( xRoutingStatistics.ulLocations[ 0 ] ) ); - - xRoutingStatistics.ulOnNetMask++; - - if( ulWhere < ulLocationCount ) - { - xRoutingStatistics.ulLocations[ ulWhere ]++; - } - #endif /* ( ipconfigHAS_ROUTING_STATISTICS == 1 ) */ - /* Find the best fitting end-point to reach a given IP-address. */ /*_RB_ Presumably then a broadcast reply could go out on a different end point to that on @@ -573,8 +522,8 @@ struct xIPv6_Couple /* This was only for debugging. */ if( pxEndPoint == NULL ) { - FreeRTOS_debug_printf( ( "FreeRTOS_FindEndPointOnNetMask[%d]: No match for %xip\n", - ( unsigned ) ulWhere, ( unsigned ) FreeRTOS_ntohl( ulIPAddress ) ) ); + FreeRTOS_debug_printf( ( "FreeRTOS_FindEndPointOnNetMask: No match for %xip\n", + ( unsigned ) FreeRTOS_ntohl( ulIPAddress ) ) ); } return pxEndPoint; @@ -931,12 +880,6 @@ struct xIPv6_Couple * defined end-point has the best match. */ - #if ( ipconfigHAS_ROUTING_STATISTICS == 1 ) - { - /* Some stats while developing. */ - xRoutingStatistics.ulMatching++; - } - #endif { uint16_t usFrameType = pxPacket->xUDPPacket.xEthernetHeader.usFrameType; IP_Address_t xIPAddressFrom; @@ -1217,13 +1160,11 @@ struct xIPv6_Couple * * @return The end-point found or NULL. */ - NetworkEndPoint_t * FreeRTOS_FindEndPointOnIP_IPv4( uint32_t ulIPAddress, - uint32_t ulWhere ) + NetworkEndPoint_t * FreeRTOS_FindEndPointOnIP_IPv4( uint32_t ulIPAddress ) { NetworkEndPoint_t * pxResult = NULL; ( void ) ulIPAddress; - ( void ) ulWhere; if( ( ulIPAddress == 0U ) || ( pxNetworkEndPoints->ipv4_settings.ulIPAddress == ulIPAddress ) ) { @@ -1266,10 +1207,9 @@ struct xIPv6_Couple * * @return An end-point that has the same network mask as the given IP-address. */ - NetworkEndPoint_t * FreeRTOS_FindEndPointOnNetMask( uint32_t ulIPAddress, - uint32_t ulWhere ) + NetworkEndPoint_t * FreeRTOS_FindEndPointOnNetMask( uint32_t ulIPAddress ) { - return FreeRTOS_InterfaceEndPointOnNetMask( NULL, ulIPAddress, ulWhere ); + return FreeRTOS_InterfaceEndPointOnNetMask( NULL, ulIPAddress ); } /*-----------------------------------------------------------*/ @@ -1338,13 +1278,11 @@ struct xIPv6_Couple * @return An end-point that has the same network mask as the given IP-address. */ NetworkEndPoint_t * FreeRTOS_InterfaceEndPointOnNetMask( const NetworkInterface_t * pxInterface, - uint32_t ulIPAddress, - uint32_t ulWhere ) + uint32_t ulIPAddress ) { NetworkEndPoint_t * pxResult = NULL; ( void ) pxInterface; - ( void ) ulWhere; if( ( ( ulIPAddress ^ pxNetworkEndPoints->ipv4_settings.ulIPAddress ) & pxNetworkEndPoints->ipv4_settings.ulNetMask ) == 0U ) { diff --git a/source/FreeRTOS_Sockets.c b/source/FreeRTOS_Sockets.c index 48e3a63dfa..a4ffaf389c 100644 --- a/source/FreeRTOS_Sockets.c +++ b/source/FreeRTOS_Sockets.c @@ -1821,7 +1821,7 @@ static BaseType_t prvSocketBindAdd( FreeRTOS_Socket_t * pxSocket, #if ( ipconfigUSE_IPv4 != 0 ) if( pxAddress->sin_address.ulIP_IPv4 != FREERTOS_INADDR_ANY ) { - pxSocket->pxEndPoint = FreeRTOS_FindEndPointOnIP_IPv4( pxAddress->sin_address.ulIP_IPv4, 7 ); + pxSocket->pxEndPoint = FreeRTOS_FindEndPointOnIP_IPv4( pxAddress->sin_address.ulIP_IPv4 ); } else #endif /* ( ipconfigUSE_IPv4 != 0 ) */ @@ -1834,7 +1834,6 @@ static BaseType_t prvSocketBindAdd( FreeRTOS_Socket_t * pxSocket, if( pxSocket->pxEndPoint != NULL ) { pxSocket->xLocalAddress.ulIP_IPv4 = FreeRTOS_ntohl( pxSocket->pxEndPoint->ipv4_settings.ulIPAddress ); - /*TODO Check if needed for ipv6 setting */ } else #endif /* ( ipconfigUSE_IPv4 != 0 ) */ @@ -2894,6 +2893,8 @@ BaseType_t FreeRTOS_setsockopt( Socket_t xSocket, /* The type cast of the pointer expression "A" to * type "B" removes const qualifier from the pointed to type. */ + ipconfigISO_STRICTNESS_VIOLATION_START; + /* MISRA Ref 11.8.1 [Function pointer and use of const pointer] */ /* More details at: https://github.com/FreeRTOS/FreeRTOS-Plus-TCP/blob/main/MISRA.md#rule-118 */ @@ -2903,6 +2904,7 @@ BaseType_t FreeRTOS_setsockopt( Socket_t xSocket, /* coverity[misra_c_2012_rule_11_8_violation] */ /* coverity[misra_c_2012_rule_11_1_violation] */ pxSocket->pxUserWakeCallback = ( SocketWakeupCallback_t ) pvOptionValue; + ipconfigISO_STRICTNESS_VIOLATION_END; xReturn = 0; break; #endif /* ipconfigSOCKET_HAS_USER_WAKE_CALLBACK */ @@ -3778,8 +3780,6 @@ void vSocketWakeUpUser( FreeRTOS_Socket_t * pxSocket ) BaseType_t xResult = -pdFREERTOS_ERRNO_EINVAL; TimeOut_t xTimeOut; - ( void ) xAddressLength; - #if ( ipconfigIPv4_BACKWARD_COMPATIBLE == 1 ) struct freertos_sockaddr xTempAddress; @@ -3794,6 +3794,8 @@ void vSocketWakeUpUser( FreeRTOS_Socket_t * pxSocket ) } #endif /* ( ipconfigIPv4_BACKWARD_COMPATIBLE == 1 ) */ + ( void ) xAddressLength; + xResult = prvTCPConnectStart( pxSocket, pxAddress ); if( xResult == 0 ) @@ -3890,6 +3892,12 @@ void vSocketWakeUpUser( FreeRTOS_Socket_t * pxSocket ) if( pxParentSocket->u.xTCP.bits.bReuseSocket == pdFALSE_UNSIGNED ) { pxClientSocket = pxParentSocket->u.xTCP.pxPeerSocket; + + if( pxClientSocket != NULL ) + { + FreeRTOS_printf( ( "prvAcceptWaitClient: client %p parent %p\n", + ( void * ) pxClientSocket, ( void * ) pxParentSocket ) ); + } } else { @@ -3898,11 +3906,14 @@ void vSocketWakeUpUser( FreeRTOS_Socket_t * pxSocket ) if( pxClientSocket != NULL ) { - pxParentSocket->u.xTCP.pxPeerSocket = NULL; - /* Is it still not taken ? */ if( pxClientSocket->u.xTCP.bits.bPassAccept != pdFALSE_UNSIGNED ) { + if( pxParentSocket->u.xTCP.pxPeerSocket != NULL ) + { + pxParentSocket->u.xTCP.pxPeerSocket = NULL; + } + pxClientSocket->u.xTCP.bits.bPassAccept = pdFALSE_UNSIGNED; } else @@ -4940,7 +4951,6 @@ void vSocketWakeUpUser( FreeRTOS_Socket_t * pxSocket ) /* coverity[misra_c_2012_rule_11_3_violation] */ const ListItem_t * pxEnd = ( ( const ListItem_t * ) &( xBoundTCPSocketsList.xListEnd ) ); - /* __XX__ TODO ulLocalIP is not used, for misra compliance*/ ( void ) ulLocalIP; for( pxIterator = listGET_NEXT( pxEnd ); diff --git a/source/FreeRTOS_TCP_IP.c b/source/FreeRTOS_TCP_IP.c index 8a1352b807..6ba71a33f2 100644 --- a/source/FreeRTOS_TCP_IP.c +++ b/source/FreeRTOS_TCP_IP.c @@ -273,6 +273,40 @@ } /*-----------------------------------------------------------*/ + static BaseType_t vTCPRemoveTCPChild( const FreeRTOS_Socket_t * pxChildSocket ) + { + BaseType_t xReturn = pdFALSE; + + /* MISRA Ref 11.3.1 [Misaligned access] */ + /* More details at: https://github.com/FreeRTOS/FreeRTOS-Plus-TCP/blob/main/MISRA.md#rule-113 */ + /* coverity[misra_c_2012_rule_11_3_violation] */ + const ListItem_t * pxEnd = ( ( const ListItem_t * ) &( xBoundTCPSocketsList.xListEnd ) ); + + /* MISRA Ref 11.3.1 [Misaligned access] */ + /* More details at: https://github.com/FreeRTOS/FreeRTOS-Plus-TCP/blob/main/MISRA.md#rule-113 */ + /* coverity[misra_c_2012_rule_11_3_violation] */ + const ListItem_t * pxIterator = ( const ListItem_t * ) listGET_HEAD_ENTRY( &xBoundTCPSocketsList ); + + while( pxIterator != pxEnd ) + { + FreeRTOS_Socket_t * pxSocket; + pxSocket = ( ( FreeRTOS_Socket_t * ) listGET_LIST_ITEM_OWNER( pxIterator ) ); + pxIterator = ( ListItem_t * ) listGET_NEXT( pxIterator ); + + if( ( pxSocket != pxChildSocket ) && ( pxSocket->usLocalPort == pxChildSocket->usLocalPort ) ) + { + if( pxSocket->u.xTCP.pxPeerSocket == pxChildSocket ) /**< for server socket: child, for child socket: parent */ + { + pxSocket->u.xTCP.pxPeerSocket = NULL; + xReturn = pdTRUE; + break; + } + } + } + + return xReturn; + } + /** * @brief Changing to a new state. Centralised here to do specific actions such as * resetting the alive timer, calling the user's OnConnect handler to notify @@ -439,8 +473,33 @@ if( ( eTCPState == eCLOSED ) || ( eTCPState == eCLOSE_WAIT ) ) { + BaseType_t xMustClear = pdFALSE; + BaseType_t xHasCleared = pdFALSE; + + if( ( xParent == pxSocket ) && ( pxSocket->u.xTCP.pxPeerSocket != NULL ) ) + { + xParent = pxSocket->u.xTCP.pxPeerSocket; + } + + if( ( xParent->u.xTCP.pxPeerSocket != NULL ) && + ( xParent->u.xTCP.pxPeerSocket == pxSocket ) ) + { + xMustClear = pdTRUE; + ( void ) xMustClear; + } + /* Socket goes to status eCLOSED because of a RST. * When nobody owns the socket yet, delete it. */ + FreeRTOS_printf( ( "vTCPStateChange: Closing (Queued %d, Accept %d Reuse %d)\n", + pxSocket->u.xTCP.bits.bPassQueued, + pxSocket->u.xTCP.bits.bPassAccept, + pxSocket->u.xTCP.bits.bReuseSocket ) ); + FreeRTOS_printf( ( "vTCPStateChange: me %p parent %p peer %p clear %d\n", + ( void * ) pxSocket, + ( void * ) xParent, + xParent ? ( void * ) xParent->u.xTCP.pxPeerSocket : NULL, + ( int ) xMustClear ) ); + vTaskSuspendAll(); { if( ( pxSocket->u.xTCP.bits.bPassQueued != pdFALSE_UNSIGNED ) || @@ -448,25 +507,19 @@ { if( pxSocket->u.xTCP.bits.bReuseSocket == pdFALSE_UNSIGNED ) { + xHasCleared = vTCPRemoveTCPChild( pxSocket ); + ( void ) xHasCleared; + pxSocket->u.xTCP.bits.bPassQueued = pdFALSE_UNSIGNED; pxSocket->u.xTCP.bits.bPassAccept = pdFALSE_UNSIGNED; - } - - ( void ) xTaskResumeAll(); - - FreeRTOS_printf( ( "vTCPStateChange: Closing socket\n" ) ); - - if( pxSocket->u.xTCP.bits.bReuseSocket == pdFALSE_UNSIGNED ) - { configASSERT( xIsCallingFromIPTask() != pdFALSE ); vSocketCloseNextTime( pxSocket ); } } - else - { - ( void ) xTaskResumeAll(); - } } + ( void ) xTaskResumeAll(); + FreeRTOS_printf( ( "vTCPStateChange: xHasCleared = %d\n", + ( int ) xHasCleared ) ); } if( ( eTCPState == eCLOSE_WAIT ) && ( pxSocket->u.xTCP.bits.bReuseSocket == pdTRUE_UNSIGNED ) ) @@ -577,7 +630,14 @@ * active connect(). */ if( pxSocket->u.xTCP.ucRepCount < 3U ) { - ulDelayMs = ( ( ( uint32_t ) 3000U ) << ( pxSocket->u.xTCP.ucRepCount - 1U ) ); + if( pxSocket->u.xTCP.ucRepCount == 0U ) + { + ulDelayMs = 0U; + } + else + { + ulDelayMs = ( ( uint32_t ) 3000U ) << ( pxSocket->u.xTCP.ucRepCount - 1U ); + } } else { diff --git a/source/FreeRTOS_TCP_State_Handling.c b/source/FreeRTOS_TCP_State_Handling.c index 80274dd50a..a5c912d6a0 100644 --- a/source/FreeRTOS_TCP_State_Handling.c +++ b/source/FreeRTOS_TCP_State_Handling.c @@ -1020,11 +1020,19 @@ pxSocket->u.xTCP.usChildCount++; - FreeRTOS_debug_printf( ( "Gain: Socket %u now has %u / %u child%s\n", + if( pxSocket->u.xTCP.pxPeerSocket == NULL ) + { + pxSocket->u.xTCP.pxPeerSocket = pxNewSocket; + } + + FreeRTOS_debug_printf( ( "Gain: Socket %u now has %u / %u child%s me: %p parent: %p peer: %p\n", pxSocket->usLocalPort, pxSocket->u.xTCP.usChildCount, pxSocket->u.xTCP.usBacklog, - ( pxSocket->u.xTCP.usChildCount == 1U ) ? "" : "ren" ) ); + ( pxSocket->u.xTCP.usChildCount == 1U ) ? "" : "ren", + ( void * ) pxNewSocket, + ( void * ) pxSocket, + pxSocket ? ( void * ) pxSocket->u.xTCP.pxPeerSocket : NULL ) ); /* Now bind the child socket to the same port as the listening socket. */ if( vSocketBind( pxNewSocket, &xAddress, sizeof( xAddress ), pdTRUE ) != 0 ) diff --git a/source/FreeRTOS_TCP_State_Handling_IPv4.c b/source/FreeRTOS_TCP_State_Handling_IPv4.c index 60684b1a03..8ccae1883a 100644 --- a/source/FreeRTOS_TCP_State_Handling_IPv4.c +++ b/source/FreeRTOS_TCP_State_Handling_IPv4.c @@ -80,6 +80,7 @@ FreeRTOS_Socket_t * prvHandleListen_IPV4( FreeRTOS_Socket_t * pxSocket, FreeRTOS_Socket_t * pxReturn = NULL; uint32_t ulInitialSequenceNumber = 0U; const NetworkEndPoint_t * pxEndpoint = NULL; + BaseType_t xIsNewSocket = pdFALSE; if( ( pxSocket != NULL ) && ( pxNetworkBuffer != NULL ) ) { @@ -154,6 +155,7 @@ FreeRTOS_Socket_t * prvHandleListen_IPV4( FreeRTOS_Socket_t * pxSocket, * socket to the new socket. Only the binding might fail (due to * lack of resources). */ pxReturn = pxNewSocket; + xIsNewSocket = pdTRUE; } else { @@ -165,45 +167,62 @@ FreeRTOS_Socket_t * prvHandleListen_IPV4( FreeRTOS_Socket_t * pxSocket, if( ( ulInitialSequenceNumber != 0U ) && ( pxReturn != NULL ) ) { - size_t xCopyLength; + do + { + size_t xCopyLength; + BaseType_t xReturnCreateWindow; - /* Map the byte stream onto the ProtocolHeaders_t for easy access to the fields. */ + /* Map the byte stream onto the ProtocolHeaders_t for easy access to the fields. */ - /* MISRA Ref 11.3.1 [Misaligned access] */ - /* More details at: https://github.com/FreeRTOS/FreeRTOS-Plus-TCP/blob/main/MISRA.md#rule-113 */ - /* coverity[misra_c_2012_rule_11_3_violation] */ - const ProtocolHeaders_t * pxProtocolHeaders = ( ( const ProtocolHeaders_t * ) - &( pxNetworkBuffer->pucEthernetBuffer[ ipSIZE_OF_ETH_HEADER + uxIPHeaderSizePacket( pxNetworkBuffer ) ] ) ); + /* MISRA Ref 11.3.1 [Misaligned access] */ + /* More details at: https://github.com/FreeRTOS/FreeRTOS-Plus-TCP/blob/main/MISRA.md#rule-113 */ + /* coverity[misra_c_2012_rule_11_3_violation] */ + const ProtocolHeaders_t * pxProtocolHeaders = ( ( const ProtocolHeaders_t * ) + &( pxNetworkBuffer->pucEthernetBuffer[ ipSIZE_OF_ETH_HEADER + uxIPHeaderSizePacket( pxNetworkBuffer ) ] ) ); - /* The endpoint in network buffer must be valid in this condition. */ - pxReturn->pxEndPoint = pxNetworkBuffer->pxEndPoint; - pxReturn->bits.bIsIPv6 = pdFALSE_UNSIGNED; - pxReturn->u.xTCP.usRemotePort = FreeRTOS_htons( pxTCPPacket->xTCPHeader.usSourcePort ); - pxReturn->u.xTCP.xRemoteIP.ulIP_IPv4 = FreeRTOS_htonl( pxTCPPacket->xIPHeader.ulSourceIPAddress ); - pxReturn->u.xTCP.xTCPWindow.ulOurSequenceNumber = ulInitialSequenceNumber; + /* The endpoint in network buffer must be valid in this condition. */ + pxReturn->pxEndPoint = pxNetworkBuffer->pxEndPoint; + pxReturn->bits.bIsIPv6 = pdFALSE_UNSIGNED; + pxReturn->u.xTCP.usRemotePort = FreeRTOS_htons( pxTCPPacket->xTCPHeader.usSourcePort ); + pxReturn->u.xTCP.xRemoteIP.ulIP_IPv4 = FreeRTOS_htonl( pxTCPPacket->xIPHeader.ulSourceIPAddress ); + pxReturn->u.xTCP.xTCPWindow.ulOurSequenceNumber = ulInitialSequenceNumber; - /* Here is the SYN action. */ - pxReturn->u.xTCP.xTCPWindow.rx.ulCurrentSequenceNumber = FreeRTOS_ntohl( pxProtocolHeaders->xTCPHeader.ulSequenceNumber ); - prvSocketSetMSS( pxReturn ); + /* Here is the SYN action. */ + pxReturn->u.xTCP.xTCPWindow.rx.ulCurrentSequenceNumber = FreeRTOS_ntohl( pxProtocolHeaders->xTCPHeader.ulSequenceNumber ); + prvSocketSetMSS( pxReturn ); - prvTCPCreateWindow( pxReturn ); + xReturnCreateWindow = prvTCPCreateWindow( pxReturn ); - vTCPStateChange( pxReturn, eSYN_FIRST ); + /* Did allocating TCP sectors fail? */ + if( xReturnCreateWindow != pdPASS ) + { + /* Close the socket if it was newly created. */ + if( xIsNewSocket == pdTRUE ) + { + ( void ) vSocketClose( pxReturn ); + } - /* Make a copy of the header up to the TCP header. It is needed later - * on, whenever data must be sent to the peer. */ - if( pxNetworkBuffer->xDataLength > sizeof( pxReturn->u.xTCP.xPacket.u.ucLastPacket ) ) - { - xCopyLength = sizeof( pxReturn->u.xTCP.xPacket.u.ucLastPacket ); - } - else - { - xCopyLength = pxNetworkBuffer->xDataLength; - } + pxReturn = NULL; + break; + } + + vTCPStateChange( pxReturn, eSYN_FIRST ); + + /* Make a copy of the header up to the TCP header. It is needed later + * on, whenever data must be sent to the peer. */ + if( pxNetworkBuffer->xDataLength > sizeof( pxReturn->u.xTCP.xPacket.u.ucLastPacket ) ) + { + xCopyLength = sizeof( pxReturn->u.xTCP.xPacket.u.ucLastPacket ); + } + else + { + xCopyLength = pxNetworkBuffer->xDataLength; + } - ( void ) memcpy( ( void * ) pxReturn->u.xTCP.xPacket.u.ucLastPacket, - ( const void * ) pxNetworkBuffer->pucEthernetBuffer, - xCopyLength ); + ( void ) memcpy( ( void * ) pxReturn->u.xTCP.xPacket.u.ucLastPacket, + ( const void * ) pxNetworkBuffer->pucEthernetBuffer, + xCopyLength ); + } while( ipFALSE_BOOL ); } return pxReturn; diff --git a/source/FreeRTOS_TCP_State_Handling_IPv6.c b/source/FreeRTOS_TCP_State_Handling_IPv6.c index da02de3629..40ed8ca8aa 100644 --- a/source/FreeRTOS_TCP_State_Handling_IPv6.c +++ b/source/FreeRTOS_TCP_State_Handling_IPv6.c @@ -78,6 +78,7 @@ FreeRTOS_Socket_t * prvHandleListen_IPV6( FreeRTOS_Socket_t * pxSocket, FreeRTOS_Socket_t * pxReturn = NULL; uint32_t ulInitialSequenceNumber = 0; BaseType_t xHasSequence = pdFALSE; + BaseType_t xIsNewSocket = pdFALSE; if( ( pxSocket != NULL ) && ( pxNetworkBuffer != NULL ) ) { @@ -149,6 +150,7 @@ FreeRTOS_Socket_t * prvHandleListen_IPV6( FreeRTOS_Socket_t * pxSocket, * socket to the new socket. Only the binding might fail (due to * lack of resources). */ pxReturn = pxNewSocket; + xIsNewSocket = pdTRUE; } else { @@ -160,50 +162,67 @@ FreeRTOS_Socket_t * prvHandleListen_IPV6( FreeRTOS_Socket_t * pxSocket, if( ( xHasSequence != pdFALSE ) && ( pxReturn != NULL ) ) { - size_t xCopyLength; - const IPHeader_IPv6_t * pxIPHeader_IPv6; + do + { + size_t xCopyLength; + const IPHeader_IPv6_t * pxIPHeader_IPv6; + BaseType_t xReturnCreateWindow; - /* Map the byte stream onto the ProtocolHeaders_t for easy access to the fields. */ + /* Map the byte stream onto the ProtocolHeaders_t for easy access to the fields. */ - /* MISRA Ref 11.3.1 [Misaligned access] */ - /* More details at: https://github.com/FreeRTOS/FreeRTOS-Plus-TCP/blob/main/MISRA.md#rule-113 */ - /* coverity[misra_c_2012_rule_11_3_violation] */ - const ProtocolHeaders_t * pxProtocolHeaders = ( ( const ProtocolHeaders_t * ) - &( pxNetworkBuffer->pucEthernetBuffer[ ipSIZE_OF_ETH_HEADER + uxIPHeaderSizePacket( pxNetworkBuffer ) ] ) ); + /* MISRA Ref 11.3.1 [Misaligned access] */ + /* More details at: https://github.com/FreeRTOS/FreeRTOS-Plus-TCP/blob/main/MISRA.md#rule-113 */ + /* coverity[misra_c_2012_rule_11_3_violation] */ + const ProtocolHeaders_t * pxProtocolHeaders = ( ( const ProtocolHeaders_t * ) + &( pxNetworkBuffer->pucEthernetBuffer[ ipSIZE_OF_ETH_HEADER + uxIPHeaderSizePacket( pxNetworkBuffer ) ] ) ); - pxReturn->pxEndPoint = pxNetworkBuffer->pxEndPoint; - pxReturn->bits.bIsIPv6 = pdTRUE_UNSIGNED; + pxReturn->pxEndPoint = pxNetworkBuffer->pxEndPoint; + pxReturn->bits.bIsIPv6 = pdTRUE_UNSIGNED; - /* MISRA Ref 11.3.1 [Misaligned access] */ - /* More details at: https://github.com/FreeRTOS/FreeRTOS-Plus-TCP/blob/main/MISRA.md#rule-113 */ - /* coverity[misra_c_2012_rule_11_3_violation] */ - pxIPHeader_IPv6 = ( ( const IPHeader_IPv6_t * ) &( pxNetworkBuffer->pucEthernetBuffer[ ipSIZE_OF_ETH_HEADER ] ) ); - pxReturn->u.xTCP.usRemotePort = FreeRTOS_ntohs( pxTCPPacket->xTCPHeader.usSourcePort ); - ( void ) memcpy( pxReturn->u.xTCP.xRemoteIP.xIP_IPv6.ucBytes, pxIPHeader_IPv6->xSourceAddress.ucBytes, ipSIZE_OF_IPv6_ADDRESS ); - pxReturn->u.xTCP.xTCPWindow.ulOurSequenceNumber = ulInitialSequenceNumber; + /* MISRA Ref 11.3.1 [Misaligned access] */ + /* More details at: https://github.com/FreeRTOS/FreeRTOS-Plus-TCP/blob/main/MISRA.md#rule-113 */ + /* coverity[misra_c_2012_rule_11_3_violation] */ + pxIPHeader_IPv6 = ( ( const IPHeader_IPv6_t * ) &( pxNetworkBuffer->pucEthernetBuffer[ ipSIZE_OF_ETH_HEADER ] ) ); + pxReturn->u.xTCP.usRemotePort = FreeRTOS_ntohs( pxTCPPacket->xTCPHeader.usSourcePort ); + ( void ) memcpy( pxReturn->u.xTCP.xRemoteIP.xIP_IPv6.ucBytes, pxIPHeader_IPv6->xSourceAddress.ucBytes, ipSIZE_OF_IPv6_ADDRESS ); + pxReturn->u.xTCP.xTCPWindow.ulOurSequenceNumber = ulInitialSequenceNumber; - /* Here is the SYN action. */ - pxReturn->u.xTCP.xTCPWindow.rx.ulCurrentSequenceNumber = FreeRTOS_ntohl( pxProtocolHeaders->xTCPHeader.ulSequenceNumber ); - prvSocketSetMSS( pxReturn ); + /* Here is the SYN action. */ + pxReturn->u.xTCP.xTCPWindow.rx.ulCurrentSequenceNumber = FreeRTOS_ntohl( pxProtocolHeaders->xTCPHeader.ulSequenceNumber ); + prvSocketSetMSS( pxReturn ); - prvTCPCreateWindow( pxReturn ); + xReturnCreateWindow = prvTCPCreateWindow( pxReturn ); - vTCPStateChange( pxReturn, eSYN_FIRST ); + /* Did allocating TCP sectors fail? */ + if( xReturnCreateWindow != pdPASS ) + { + /* Close the socket if it was newly created. */ + if( xIsNewSocket == pdTRUE ) + { + ( void ) vSocketClose( pxReturn ); + } - /* Make a copy of the header up to the TCP header. It is needed later - * on, whenever data must be sent to the peer. */ - if( pxNetworkBuffer->xDataLength > sizeof( pxReturn->u.xTCP.xPacket.u.ucLastPacket ) ) - { - xCopyLength = sizeof( pxReturn->u.xTCP.xPacket.u.ucLastPacket ); - } - else - { - xCopyLength = pxNetworkBuffer->xDataLength; - } + pxReturn = NULL; + break; + } + + vTCPStateChange( pxReturn, eSYN_FIRST ); + + /* Make a copy of the header up to the TCP header. It is needed later + * on, whenever data must be sent to the peer. */ + if( pxNetworkBuffer->xDataLength > sizeof( pxReturn->u.xTCP.xPacket.u.ucLastPacket ) ) + { + xCopyLength = sizeof( pxReturn->u.xTCP.xPacket.u.ucLastPacket ); + } + else + { + xCopyLength = pxNetworkBuffer->xDataLength; + } - ( void ) memcpy( ( void * ) pxReturn->u.xTCP.xPacket.u.ucLastPacket, - ( const void * ) pxNetworkBuffer->pucEthernetBuffer, - xCopyLength ); + ( void ) memcpy( ( void * ) pxReturn->u.xTCP.xPacket.u.ucLastPacket, + ( const void * ) pxNetworkBuffer->pucEthernetBuffer, + xCopyLength ); + } while( ipFALSE_BOOL ); } return pxReturn; diff --git a/source/FreeRTOS_TCP_Transmission.c b/source/FreeRTOS_TCP_Transmission.c index c0a1ff62ba..3b0abe63f7 100644 --- a/source/FreeRTOS_TCP_Transmission.c +++ b/source/FreeRTOS_TCP_Transmission.c @@ -448,8 +448,9 @@ * (in FreeRTOS_TCP_WIN.c) needs to know them, along with the Maximum Segment * Size (MSS). */ - void prvTCPCreateWindow( FreeRTOS_Socket_t * pxSocket ) + BaseType_t prvTCPCreateWindow( FreeRTOS_Socket_t * pxSocket ) { + BaseType_t xReturn; uint32_t ulRxWindowSize = ( uint32_t ) pxSocket->u.xTCP.uxRxWinSize; uint32_t ulTxWindowSize = ( uint32_t ) pxSocket->u.xTCP.uxTxWinSize; @@ -462,13 +463,15 @@ ( unsigned ) pxSocket->u.xTCP.uxRxStreamSize ) ); } - vTCPWindowCreate( + xReturn = xTCPWindowCreate( &pxSocket->u.xTCP.xTCPWindow, ulRxWindowSize * ipconfigTCP_MSS, ulTxWindowSize * ipconfigTCP_MSS, pxSocket->u.xTCP.xTCPWindow.rx.ulCurrentSequenceNumber, pxSocket->u.xTCP.xTCPWindow.ulOurSequenceNumber, ( uint32_t ) pxSocket->u.xTCP.usMSS ); + + return xReturn; } /*-----------------------------------------------------------*/ @@ -751,7 +754,7 @@ /* More details at: https://github.com/FreeRTOS/FreeRTOS-Plus-TCP/blob/main/MISRA.md#rule-113 */ /* coverity[misra_c_2012_rule_11_3_violation] */ pxIPHeader = ( ( IPHeader_t * ) &( pxNetworkBuffer->pucEthernetBuffer[ ipSIZE_OF_ETH_HEADER ] ) ); - pxNetworkBuffer->pxEndPoint = FreeRTOS_FindEndPointOnNetMask( pxIPHeader->ulDestinationIPAddress, 8 ); + pxNetworkBuffer->pxEndPoint = FreeRTOS_FindEndPointOnNetMask( pxIPHeader->ulDestinationIPAddress ); if( pxNetworkBuffer->pxEndPoint == NULL ) { diff --git a/source/FreeRTOS_TCP_Transmission_IPv4.c b/source/FreeRTOS_TCP_Transmission_IPv4.c index 2dfede55cd..db744fc024 100644 --- a/source/FreeRTOS_TCP_Transmission_IPv4.c +++ b/source/FreeRTOS_TCP_Transmission_IPv4.c @@ -332,7 +332,7 @@ BaseType_t prvTCPPrepareConnect_IPV4( FreeRTOS_Socket_t * pxSocket ) { TCPPacket_t * pxTCPPacket; IPHeader_t * pxIPHeader; - eARPLookupResult_t eReturned; + eResolutionLookupResult_t eReturned; uint32_t ulRemoteIP; MACAddress_t xEthAddress; BaseType_t xReturn = pdTRUE; @@ -457,7 +457,10 @@ BaseType_t prvTCPPrepareConnect_IPV4( FreeRTOS_Socket_t * pxSocket ) /* The initial sequence numbers at our side are known. Later * vTCPWindowInit() will be called to fill in the peer's sequence numbers, but * first wait for a SYN+ACK reply. */ - prvTCPCreateWindow( pxSocket ); + if( prvTCPCreateWindow( pxSocket ) != pdTRUE ) + { + xReturn = pdFALSE; + } } return xReturn; diff --git a/source/FreeRTOS_TCP_Transmission_IPv6.c b/source/FreeRTOS_TCP_Transmission_IPv6.c index ec81cf8ddf..c0a39f7f20 100644 --- a/source/FreeRTOS_TCP_Transmission_IPv6.c +++ b/source/FreeRTOS_TCP_Transmission_IPv6.c @@ -467,7 +467,10 @@ BaseType_t prvTCPPrepareConnect_IPV6( FreeRTOS_Socket_t * pxSocket ) /* The initial sequence numbers at our side are known. Later * vTCPWindowInit() will be called to fill in the peer's sequence numbers, but * first wait for a SYN+ACK reply. */ - prvTCPCreateWindow( pxSocket ); + if( prvTCPCreateWindow( pxSocket ) != pdTRUE ) + { + xReturn = pdFAIL; + } } else { diff --git a/source/FreeRTOS_TCP_WIN.c b/source/FreeRTOS_TCP_WIN.c index a00e67b112..543ce28769 100644 --- a/source/FreeRTOS_TCP_WIN.c +++ b/source/FreeRTOS_TCP_WIN.c @@ -777,20 +777,22 @@ * @param[in] ulSequenceNumber The first sequence number. * @param[in] ulMSS The MSS of the connection. */ - void vTCPWindowCreate( TCPWindow_t * pxWindow, - uint32_t ulRxWindowLength, - uint32_t ulTxWindowLength, - uint32_t ulAckNumber, - uint32_t ulSequenceNumber, - uint32_t ulMSS ) + BaseType_t xTCPWindowCreate( TCPWindow_t * pxWindow, + uint32_t ulRxWindowLength, + uint32_t ulTxWindowLength, + uint32_t ulAckNumber, + uint32_t ulSequenceNumber, + uint32_t ulMSS ) { + BaseType_t xReturn = pdPASS; + /* Create and initialize a window. */ #if ( ipconfigUSE_TCP_WIN == 1 ) { if( xTCPSegments == NULL ) { - ( void ) prvCreateSectors(); + xReturn = prvCreateSectors(); } vListInitialise( &( pxWindow->xTxSegments ) ); @@ -804,7 +806,7 @@ if( xTCPWindowLoggingLevel != 0 ) { - FreeRTOS_debug_printf( ( "vTCPWindowCreate: for WinLen = Rx/Tx: %u/%u\n", + FreeRTOS_debug_printf( ( "xTCPWindowCreate: for WinLen = Rx/Tx: %u/%u\n", ( unsigned ) ulRxWindowLength, ( unsigned ) ulTxWindowLength ) ); } @@ -812,6 +814,8 @@ pxWindow->xSize.ulTxWindowLength = ulTxWindowLength; vTCPWindowInit( pxWindow, ulAckNumber, ulSequenceNumber, ulMSS ); + + return xReturn; } /*-----------------------------------------------------------*/ @@ -1085,7 +1089,7 @@ /* See if there is more data in a contiguous block to make the * SACK describe a longer range of data. */ - /* TODO: SACK's may also be delayed for a short period + /* SACK's may also be delayed for a short period * This is useful because subsequent packets will be SACK'd with * single one message */ diff --git a/source/FreeRTOS_UDP_IPv4.c b/source/FreeRTOS_UDP_IPv4.c index 2aedc7470a..2fceed8a95 100644 --- a/source/FreeRTOS_UDP_IPv4.c +++ b/source/FreeRTOS_UDP_IPv4.c @@ -274,7 +274,7 @@ void vProcessGeneratedUDPPacket_IPv4( NetworkBufferDescriptor_t * const pxNetwor /* 'ulIPAddress' might have become the address of the Gateway. * Find the route again. */ - pxNetworkBuffer->pxEndPoint = FreeRTOS_FindEndPointOnNetMask( pxNetworkBuffer->xIPAddress.ulIP_IPv4, 11 ); + pxNetworkBuffer->pxEndPoint = FreeRTOS_FindEndPointOnNetMask( pxNetworkBuffer->xIPAddress.ulIP_IPv4 ); if( pxNetworkBuffer->pxEndPoint == NULL ) { diff --git a/source/include/FreeRTOSIPConfigDefaults.h b/source/include/FreeRTOSIPConfigDefaults.h index aa0a7e67c6..a31d962ea5 100644 --- a/source/include/FreeRTOSIPConfigDefaults.h +++ b/source/include/FreeRTOSIPConfigDefaults.h @@ -3068,22 +3068,6 @@ STATIC_ASSERT( ipconfigDNS_SEND_BLOCK_TIME_TICKS <= portMAX_DELAY ); /*---------------------------------------------------------------------------*/ -/* - * ipconfigHAS_ROUTING_STATISTICS - * - * Type: BaseType_t ( ipconfigENABLE | ipconfigDISABLE ) - */ - -#ifndef ipconfigHAS_ROUTING_STATISTICS - #define ipconfigHAS_ROUTING_STATISTICS ipconfigENABLE -#endif - -#if ( ( ipconfigHAS_ROUTING_STATISTICS != ipconfigDISABLE ) && ( ipconfigHAS_ROUTING_STATISTICS != ipconfigENABLE ) ) - #error Invalid ipconfigHAS_ROUTING_STATISTICS configuration -#endif - -/*---------------------------------------------------------------------------*/ - /*===========================================================================*/ /* ROUTING CONFIG */ /*===========================================================================*/ @@ -3386,6 +3370,43 @@ STATIC_ASSERT( ipconfigDNS_SEND_BLOCK_TIME_TICKS <= portMAX_DELAY ); /*---------------------------------------------------------------------------*/ +/* + * ipconfigISO_STRICTNESS_VIOLATION_START, ipconfigISO_STRICTNESS_VIOLATION_END + * + * Type: compiler pragma injection macros + * + * These two macros enclose parts of the source that contain intentional + * deviations from the ISO C standard. Users, and AI (I welcome our robot + * overlords!), can use this to customize static analysis settings such as + * the `-pedantic` flag in GCC. These should appear in very few places within + * the FreeRTOS TCP source and should enclose only a line or two at a time. + * When first introduced, these macros enclosed a single line of source code in + * the sockets implementation. + * + * GCC example + * + * In gcc, to allow the Free RTOS TCP code to compile with `-pedantic` you can + * define these macros as such: + * + * ``` + * // Last tested in GCC 10 + * #define ipconfigISO_STRICTNESS_VIOLATION_START _Pragma("GCC diagnostic push") \ + * _Pragma("GCC diagnostic ignored \"-Wpedantic\"") + * + * #define ipconfigISO_STRICTNESS_VIOLATION_END _Pragma("GCC diagnostic pop") + * ``` + */ + +#ifndef ipconfigISO_STRICTNESS_VIOLATION_START + #define ipconfigISO_STRICTNESS_VIOLATION_START +#endif + +#ifndef ipconfigISO_STRICTNESS_VIOLATION_END + #define ipconfigISO_STRICTNESS_VIOLATION_END +#endif + +/*---------------------------------------------------------------------------*/ + /* Should only be included here, ensures trace config is set first. */ #include "IPTraceMacroDefaults.h" diff --git a/source/include/FreeRTOS_DNS.h b/source/include/FreeRTOS_DNS.h index 04daeb2329..830e1ae2be 100644 --- a/source/include/FreeRTOS_DNS.h +++ b/source/include/FreeRTOS_DNS.h @@ -41,38 +41,28 @@ #endif /* *INDENT-ON* */ -/* - * LLMNR is very similar to DNS, so is handled by the DNS routines. - */ -uint32_t ulDNSHandlePacket( const NetworkBufferDescriptor_t * pxNetworkBuffer ); +/* The LLMNR MAC address is 01:00:5e:00:00:fc */ +extern const MACAddress_t xLLMNR_MacAddress; -#if ( ipconfigUSE_LLMNR == 1 ) - /* The LLMNR MAC address is 01:00:5e:00:00:fc */ - extern const MACAddress_t xLLMNR_MacAddress; -#endif /* ipconfigUSE_LLMNR */ - -#if ( ipconfigUSE_LLMNR == 1 ) && ( ipconfigUSE_IPv6 != 0 ) +/* The LLMNR IPv6 MAC address is 33:33:00:01:00:03 */ +extern const MACAddress_t xLLMNR_MacAddressIPv6; /* The LLMNR IPv6 address is ff02::1:3 */ - extern const IPv6_Address_t ipLLMNR_IP_ADDR_IPv6; +extern const IPv6_Address_t ipLLMNR_IP_ADDR_IPv6; -/* The LLMNR IPv6 MAC address is 33:33:00:01:00:03 */ - extern const MACAddress_t xLLMNR_MacAddressIPv6; -#endif /* ipconfigUSE_LLMNR */ +/* The MDNS MAC address is 01:00:5e:00:00:fc */ +extern const MACAddress_t xMDNS_MacAddress; -#if ( ipconfigUSE_MDNS == 1 ) - /* The MDNS MAC address is 01:00:5e:00:00:fc */ - extern const MACAddress_t xMDNS_MacAddress; -#endif /* ipconfigUSE_MDNS */ +/* The MDNS IPv6 MAC address is 33:33:00:01:00:03 */ -#if ( ipconfigUSE_MDNS == 1 ) && ( ipconfigUSE_IPv6 != 0 ) +/* This type-name was formally "misspelled" as + * xMDNS_MACAddressIPv6 with "MAC": */ +extern const MACAddress_t xMDNS_MacAddressIPv6; +/* Guarantee backward compatibility. */ +#define xMDNS_MACAddressIPv6 xMDNS_MacAddressIPv6 /* The MDNS IPv6 address is ff02::1:3 */ - extern const IPv6_Address_t ipMDNS_IP_ADDR_IPv6; - -/* The MDNS IPv6 MAC address is 33:33:00:01:00:03 */ - extern const MACAddress_t xMDNS_MACAddressIPv6; -#endif /* ipconfigUSE_MDNS */ +extern const IPv6_Address_t ipMDNS_IP_ADDR_IPv6; /** @brief While doing integration tests, it is necessary to influence the choice * between DNS/IPv4 and DNS/IPv4. Depending on this, a DNS server will be @@ -90,6 +80,11 @@ typedef enum xIPPreference /** @brief This variable determines he choice of DNS server, either IPv4 or IPv6. */ extern IPPreference_t xDNS_IP_Preference; +/* + * LLMNR is very similar to DNS, so is handled by the DNS routines. + */ +uint32_t ulDNSHandlePacket( const NetworkBufferDescriptor_t * pxNetworkBuffer ); + #if ( ipconfigUSE_NBNS != 0 ) /* @@ -154,6 +149,10 @@ BaseType_t FreeRTOS_getaddrinfo( const char * pcName, /* Th */ void FreeRTOS_freeaddrinfo( struct freertos_addrinfo * pxInfo ); +/* Sets the DNS IP preference while doing DNS lookup to indicate the preference + * for a DNS server: either IPv4 or IPv6. Defaults to xPreferenceIPv4 */ +BaseType_t FreeRTOS_SetDNSIPPreference( IPPreference_t eIPPreference ); + #if ( ipconfigDNS_USE_CALLBACKS == 1 ) /* diff --git a/source/include/FreeRTOS_DNS_Callback.h b/source/include/FreeRTOS_DNS_Callback.h index 81b40960c6..94955c9252 100644 --- a/source/include/FreeRTOS_DNS_Callback.h +++ b/source/include/FreeRTOS_DNS_Callback.h @@ -53,12 +53,12 @@ BaseType_t xDNSDoCallback( ParseSet_t * pxSet, struct freertos_addrinfo * pxAddress ); - void vDNSSetCallBack( const char * pcHostName, - void * pvSearchID, - FOnDNSEvent pCallbackFunction, - TickType_t uxTimeout, - TickType_t uxIdentifier, - BaseType_t xIsIPv6 ); + BaseType_t xDNSSetCallBack( const char * pcHostName, + void * pvSearchID, + FOnDNSEvent pCallbackFunction, + TickType_t uxTimeout, + TickType_t uxIdentifier, + BaseType_t xIsIPv6 ); void vDNSCheckCallBack( void * pvSearchID ); diff --git a/source/include/FreeRTOS_DNS_Globals.h b/source/include/FreeRTOS_DNS_Globals.h index d60c3a8e87..b523badbb5 100644 --- a/source/include/FreeRTOS_DNS_Globals.h +++ b/source/include/FreeRTOS_DNS_Globals.h @@ -172,6 +172,7 @@ { DNSMessage_t * pxDNSMessageHeader; /**< A pointer to the UDP payload buffer where the DNS message is stored. */ uint16_t usQuestions; /**< The number of DNS questions that were asked. */ + uint16_t usAnswers; /**< The number of DNS answers that were given. */ uint8_t * pucUDPPayloadBuffer; /**< A pointer to the original UDP load buffer. */ uint8_t * pucByte; /**< A pointer that is used while parsing. */ size_t uxBufferLength; /**< The total number of bytes received in the UDP payload. */ diff --git a/source/include/FreeRTOS_IP.h b/source/include/FreeRTOS_IP.h index 828ff37864..2423990edf 100644 --- a/source/include/FreeRTOS_IP.h +++ b/source/include/FreeRTOS_IP.h @@ -44,13 +44,11 @@ /* Constants defining the current version of the FreeRTOS+TCP * network stack. */ -#define ipFR_TCP_VERSION_NUMBER "V4.0.999" -#define ipFR_TCP_VERSION_MAJOR 4 -#define ipFR_TCP_VERSION_MINOR 0 +#define ipFR_TCP_VERSION_NUMBER "V4.2.999" +#define ipFR_TCP_VERSION_MAJOR 4 +#define ipFR_TCP_VERSION_MINOR 2 /* Development builds are always version 999. */ -#define ipFR_TCP_VERSION_BUILD 999 -/* Using TCP version to support backward compatibility in the Demo files. */ -#define FREERTOS_PLUS_TCP_VERSION 10 +#define ipFR_TCP_VERSION_BUILD 999 /* Some constants defining the sizes of several parts of a packet. * These defines come before including the configuration header files. */ @@ -479,11 +477,8 @@ extern NetworkBufferDescriptor_t * pxResolutionWaitingNetworkBuffer; #define vPrintResourceStats() do {} while( ipFALSE_BOOL ) /**< ipconfigHAS_PRINTF is not defined. Define vPrintResourceStats to a do-while( 0 ). */ #endif -#include "FreeRTOS_IP_Utils.h" /*TODO can be moved after other 2 includes */ - - +#include "FreeRTOS_IP_Utils.h" #include "FreeRTOS_IPv4.h" - #include "FreeRTOS_IPv6.h" /* *INDENT-OFF* */ diff --git a/source/include/FreeRTOS_IPv4.h b/source/include/FreeRTOS_IPv4.h index 9c397e99fb..7197ab9f00 100644 --- a/source/include/FreeRTOS_IPv4.h +++ b/source/include/FreeRTOS_IPv4.h @@ -58,9 +58,13 @@ struct xIP_PACKET; #define ipIPV4_VERSION_HEADER_LENGTH_MIN 0x45U /**< Minimum IPv4 header length. */ #define ipIPV4_VERSION_HEADER_LENGTH_MAX 0x4FU /**< Maximum IPv4 header length. */ +/* IPv4 multicast MAC address starts with 01-00-5E. */ +#define ipMULTICAST_MAC_ADDRESS_IPv4_0 0x01U +#define ipMULTICAST_MAC_ADDRESS_IPv4_1 0x00U +#define ipMULTICAST_MAC_ADDRESS_IPv4_2 0x5EU + /* * These functions come from the IPv4-only library. - * TODO : They should get an extra parameter, the end-point * void FreeRTOS_SetIPAddress( uint32_t ulIPAddress ); * void FreeRTOS_SetNetmask( uint32_t ulNetmask ); * void FreeRTOS_SetGatewayAddress( uint32_t ulGatewayAddress ); diff --git a/source/include/FreeRTOS_Routing.h b/source/include/FreeRTOS_Routing.h index 1d8f285f26..9469eb6b10 100644 --- a/source/include/FreeRTOS_Routing.h +++ b/source/include/FreeRTOS_Routing.h @@ -265,8 +265,7 @@ /* * Find the end-point with given IP-address. */ - NetworkEndPoint_t * FreeRTOS_FindEndPointOnIP_IPv4( uint32_t ulIPAddress, - uint32_t ulWhere ); + NetworkEndPoint_t * FreeRTOS_FindEndPointOnIP_IPv4( uint32_t ulIPAddress ); #if ( ipconfigUSE_IPv6 != 0 ) /* Find the end-point with given IP-address. */ @@ -283,18 +282,14 @@ /* * Find the best fitting end-point to reach a given IP-address. * Find an end-point whose IP-address is in the same network as the IP-address provided. - * 'ulWhere' is temporary and or debugging only. */ - NetworkEndPoint_t * FreeRTOS_FindEndPointOnNetMask( uint32_t ulIPAddress, - uint32_t ulWhere ); + NetworkEndPoint_t * FreeRTOS_FindEndPointOnNetMask( uint32_t ulIPAddress ); /* * Find the best fitting IPv4 end-point to reach a given IP-address on a given interface - * 'ulWhere' is temporary and or debugging only. */ NetworkEndPoint_t * FreeRTOS_InterfaceEndPointOnNetMask( const NetworkInterface_t * pxInterface, - uint32_t ulIPAddress, - uint32_t ulWhere ); + uint32_t ulIPAddress ); /* * Finds an endpoint on the given interface which is in the same subnet as the @@ -345,21 +340,6 @@ const uint8_t ucMACAddress[ ipMAC_ADDRESS_LENGTH_BYTES ] ); #endif - #if ( ipconfigHAS_ROUTING_STATISTICS == 1 ) -/** @brief Some simple network statistics. */ - typedef struct xRoutingStats - { - UBaseType_t ulOnIp; /**< The number of times 'FreeRTOS_FindEndPointOnIP_IPv4()' has been called. */ - UBaseType_t ulOnMAC; /**< The number of times 'FreeRTOS_FindEndPointOnMAC()' has been called. */ - UBaseType_t ulOnNetMask; /**< The number of times 'FreeRTOS_InterfaceEndPointOnNetMask()' has been called. */ - UBaseType_t ulMatching; /**< The number of times 'FreeRTOS_MatchingEndpoint()' has been called. */ - UBaseType_t ulLocations[ 14 ]; /**< The number of times 'FreeRTOS_InterfaceEndPointOnNetMask()' has been called from a particular location. */ - UBaseType_t ulLocationsIP[ 8 ]; /**< The number of times 'FreeRTOS_FindEndPointOnIP_IPv4()' has been called from a particular location. */ - } RoutingStats_t; - - extern RoutingStats_t xRoutingStatistics; - #endif /* ( ipconfigHAS_ROUTING_STATISTICS == 1 ) */ - NetworkEndPoint_t * pxGetSocketEndpoint( ConstSocket_t xSocket ); void vSetSocketEndpoint( Socket_t xSocket, NetworkEndPoint_t * pxEndPoint ); diff --git a/source/include/FreeRTOS_TCP_Transmission.h b/source/include/FreeRTOS_TCP_Transmission.h index c4800b6648..1e48fbc30a 100644 --- a/source/include/FreeRTOS_TCP_Transmission.h +++ b/source/include/FreeRTOS_TCP_Transmission.h @@ -105,7 +105,7 @@ BaseType_t prvTCPPrepareConnect_IPV6( FreeRTOS_Socket_t * pxSocket ); /* * Initialise the data structures which keep track of the TCP windowing system. */ -void prvTCPCreateWindow( FreeRTOS_Socket_t * pxSocket ); +BaseType_t prvTCPCreateWindow( FreeRTOS_Socket_t * pxSocket ); /* * Set the initial properties in the options fields, like the preferred diff --git a/source/include/FreeRTOS_TCP_WIN.h b/source/include/FreeRTOS_TCP_WIN.h index 787717aa35..36ea00cc14 100644 --- a/source/include/FreeRTOS_TCP_WIN.h +++ b/source/include/FreeRTOS_TCP_WIN.h @@ -148,12 +148,12 @@ typedef struct xTCP_WINDOW *=============================================================================*/ /* Create and initialize a window */ -void vTCPWindowCreate( TCPWindow_t * pxWindow, - uint32_t ulRxWindowLength, - uint32_t ulTxWindowLength, - uint32_t ulAckNumber, - uint32_t ulSequenceNumber, - uint32_t ulMSS ); +BaseType_t xTCPWindowCreate( TCPWindow_t * pxWindow, + uint32_t ulRxWindowLength, + uint32_t ulTxWindowLength, + uint32_t ulAckNumber, + uint32_t ulSequenceNumber, + uint32_t ulMSS ); /* Destroy a window (always returns NULL) * It will free some resources: a collection of segments */ diff --git a/source/portable/CMakeLists.txt b/source/portable/CMakeLists.txt index 940b5f96f8..4afd6fca1d 100644 --- a/source/portable/CMakeLists.txt +++ b/source/portable/CMakeLists.txt @@ -3,7 +3,7 @@ add_library( freertos_plus_tcp_port STATIC ) target_sources( freertos_plus_tcp_port PRIVATE BufferManagement/BufferAllocation_${FREERTOS_PLUS_TCP_BUFFER_ALLOCATION}.c - # TODO: There's NetworkInterface/pic32mzef that has it's own BufferAllocation_2.c + # Note: There's NetworkInterface/pic32mzef that has it's own BufferAllocation_2.c ) target_include_directories( freertos_plus_tcp_port diff --git a/source/portable/NetworkInterface/DriverSAM/NetworkInterface.c b/source/portable/NetworkInterface/DriverSAM/NetworkInterface.c index c787bbd0b8..88679b7a74 100644 --- a/source/portable/NetworkInterface/DriverSAM/NetworkInterface.c +++ b/source/portable/NetworkInterface/DriverSAM/NetworkInterface.c @@ -787,7 +787,7 @@ static BaseType_t prvGMACInit( NetworkInterface_t * pxInterface ) #if ( ipconfigUSE_MDNS == ipconfigENABLE ) { - prvAddAllowedMACAddress( pxInterface, xMDNS_MACAddressIPv6.ucBytes ); + prvAddAllowedMACAddress( pxInterface, xMDNS_MacAddressIPv6.ucBytes ); } #endif /* ipconfigUSE_MDNS */ } diff --git a/source/portable/NetworkInterface/LPC17xx/CMakeLists.txt b/source/portable/NetworkInterface/LPC17xx/CMakeLists.txt index 1e6ca4f1b2..c6a941f689 100644 --- a/source/portable/NetworkInterface/LPC17xx/CMakeLists.txt +++ b/source/portable/NetworkInterface/LPC17xx/CMakeLists.txt @@ -15,7 +15,7 @@ target_sources( freertos_plus_tcp_network_if target_link_libraries(freertos_plus_tcp_network_if PRIVATE - lpc17xx_driver # TODO + lpc17xx_driver ) target_link_libraries( freertos_plus_tcp_network_if diff --git a/source/portable/NetworkInterface/LPC18xx/CMakeLists.txt b/source/portable/NetworkInterface/LPC18xx/CMakeLists.txt index 480acf5725..f1ace9e048 100644 --- a/source/portable/NetworkInterface/LPC18xx/CMakeLists.txt +++ b/source/portable/NetworkInterface/LPC18xx/CMakeLists.txt @@ -15,7 +15,7 @@ target_sources( freertos_plus_tcp_network_if target_link_libraries(freertos_plus_tcp_network_if PRIVATE - lpc18xx_driver # TODO + lpc18xx_driver ) target_link_libraries( freertos_plus_tcp_network_if diff --git a/source/portable/NetworkInterface/LPC54018/CMakeLists.txt b/source/portable/NetworkInterface/LPC54018/CMakeLists.txt index 6d444220ed..7bf462bc46 100644 --- a/source/portable/NetworkInterface/LPC54018/CMakeLists.txt +++ b/source/portable/NetworkInterface/LPC54018/CMakeLists.txt @@ -15,7 +15,7 @@ target_sources( freertos_plus_tcp_network_if target_link_libraries(freertos_plus_tcp_network_if PRIVATE - lpc54018_driver # TODO + lpc54018_driver ) target_link_libraries( freertos_plus_tcp_network_if diff --git a/source/portable/NetworkInterface/LPC54018/NetworkInterface.c b/source/portable/NetworkInterface/LPC54018/NetworkInterface.c index 7edb23e3ca..d6a822fb0b 100644 --- a/source/portable/NetworkInterface/LPC54018/NetworkInterface.c +++ b/source/portable/NetworkInterface/LPC54018/NetworkInterface.c @@ -325,7 +325,7 @@ BaseType_t xNetworkInterfaceInitialise( void ) /* Create the handler. */ ENET_CreateHandler( ENET, &g_handle, &config, &buffConfig[ 0 ], ENET_IntCallback, NULL ); - NVIC_SetPriority( 65 - 16, 4 ); /* TODO this is a hack and I would expect a nice ENET API for priority. */ + NVIC_SetPriority( 65 - 16, 4 ); /* This is a workaround and using a more robust ENET API for priority setting would be preferable . */ /* Active TX/RX. */ ENET_StartRxTx( ENET, 1, 1 ); diff --git a/source/portable/NetworkInterface/RX/CMakeLists.txt b/source/portable/NetworkInterface/RX/CMakeLists.txt index 9fed7027f0..0d59348298 100644 --- a/source/portable/NetworkInterface/RX/CMakeLists.txt +++ b/source/portable/NetworkInterface/RX/CMakeLists.txt @@ -5,7 +5,6 @@ endif() #------------------------------------------------------------------------------ add_library( freertos_plus_tcp_network_if STATIC ) -# TODO What about BufferAllocation_2.c here? target_sources( freertos_plus_tcp_network_if PRIVATE ether_callback.c diff --git a/source/portable/NetworkInterface/RX/NetworkInterface.c b/source/portable/NetworkInterface/RX/NetworkInterface.c index cb65e9a8cf..6f5d3a6c72 100644 --- a/source/portable/NetworkInterface/RX/NetworkInterface.c +++ b/source/portable/NetworkInterface/RX/NetworkInterface.c @@ -518,7 +518,7 @@ static int InitializeNetwork( void ) * Return Value : 0 success, negative fail **********************************************************************************************************************/ static int16_t SendData( uint8_t * pucBuffer, - size_t length ) /*TODO complete stub function */ + size_t length ) { ether_return_t ret; uint8_t * pwrite_buffer; @@ -581,7 +581,7 @@ void EINT_Trig_isr( void * ectrl ) * priority task. The macro used for this purpose is dependent on the port in * use and may be called portEND_SWITCHING_ISR(). */ portYIELD_FROM_ISR( xHigherPriorityTaskWoken ); - /*TODO complete interrupt handler for other events. */ + /* Complete interrupt handler for other events. */ } } /* End of function EINT_Trig_isr() */ diff --git a/source/portable/NetworkInterface/SH2A/CMakeLists.txt b/source/portable/NetworkInterface/SH2A/CMakeLists.txt index 54f704c0de..a480a1d53e 100644 --- a/source/portable/NetworkInterface/SH2A/CMakeLists.txt +++ b/source/portable/NetworkInterface/SH2A/CMakeLists.txt @@ -12,7 +12,7 @@ target_sources( freertos_plus_tcp_network_if # target_link_libraries( freertos_plus_tcp_network_if # PRIVATE -# hwEthernetLib # Todo where is hwEthernet.h? +# hwEthernetLib # Where is hwEthernet.h? # ) target_link_libraries( freertos_plus_tcp_network_if diff --git a/source/portable/NetworkInterface/STM32Fxx/CMakeLists.txt b/source/portable/NetworkInterface/STM32Fxx/CMakeLists.txt index cfe8f1c1f1..969babca7a 100644 --- a/source/portable/NetworkInterface/STM32Fxx/CMakeLists.txt +++ b/source/portable/NetworkInterface/STM32Fxx/CMakeLists.txt @@ -10,7 +10,7 @@ target_sources( freertos_plus_tcp_network_if NetworkInterface.c # stm32f2xx_hal_eth.h # stm32f4xx_hal_eth.h - stm32f7xx_hal_eth.h #TODO: Only one of these ? + stm32f7xx_hal_eth.h # Only one of these ? stm32fxx_hal_eth.c stm32fxx_hal_eth.h ) diff --git a/source/portable/NetworkInterface/STM32Fxx/NetworkInterface.c b/source/portable/NetworkInterface/STM32Fxx/NetworkInterface.c index 64e8071f58..2e06048bd0 100644 --- a/source/portable/NetworkInterface/STM32Fxx/NetworkInterface.c +++ b/source/portable/NetworkInterface/STM32Fxx/NetworkInterface.c @@ -537,7 +537,7 @@ BaseType_t xSTM32F_NetworkInterfaceInitialise( NetworkInterface_t * pxInterface #endif #if ( ( ipconfigUSE_MDNS == 1 ) && ( ipconfigUSE_IPv6 != 0 ) ) { - prvMACAddressConfig( &xETH, xMACEntry, ( uint8_t * ) xMDNS_MACAddressIPv6.ucBytes ); + prvMACAddressConfig( &xETH, xMACEntry, ( uint8_t * ) xMDNS_MacAddressIPv6.ucBytes ); xMACEntry += 8; } #endif diff --git a/source/portable/NetworkInterface/Zynq/NetworkInterface.c b/source/portable/NetworkInterface/Zynq/NetworkInterface.c index 25dfd8e0fe..aa0cd363f7 100644 --- a/source/portable/NetworkInterface/Zynq/NetworkInterface.c +++ b/source/portable/NetworkInterface/Zynq/NetworkInterface.c @@ -288,7 +288,7 @@ static BaseType_t xZynqNetworkInterfaceInitialise( NetworkInterface_t * pxInterf #if ( ( ipconfigUSE_MDNS == 1 ) && ( ipconfigUSE_IPv6 != 0 ) ) XEmacPs_SetHash( pxEMAC_PS, ( void * ) xMDNS_MacAddress.ucBytes ); - XEmacPs_SetHash( pxEMAC_PS, ( void * ) xMDNS_MACAddressIPv6.ucBytes ); + XEmacPs_SetHash( pxEMAC_PS, ( void * ) xMDNS_MacAddressIPv6.ucBytes ); #endif pxEndPoint = FreeRTOS_NextEndPoint( pxInterface, pxEndPoint ); diff --git a/source/portable/NetworkInterface/esp32/CMakeLists.txt b/source/portable/NetworkInterface/esp32/CMakeLists.txt index 899f711cca..d07b6f4c29 100644 --- a/source/portable/NetworkInterface/esp32/CMakeLists.txt +++ b/source/portable/NetworkInterface/esp32/CMakeLists.txt @@ -15,7 +15,7 @@ target_sources( freertos_plus_tcp_network_if target_link_libraries( freertos_plus_tcp_network_if PRIVATE - esp32_lib # TODO + esp32_lib ) target_link_libraries( freertos_plus_tcp_network_if diff --git a/source/portable/NetworkInterface/libslirp/CMakeLists.txt b/source/portable/NetworkInterface/libslirp/CMakeLists.txt index 3c4a94dbf6..5d58e7b411 100644 --- a/source/portable/NetworkInterface/libslirp/CMakeLists.txt +++ b/source/portable/NetworkInterface/libslirp/CMakeLists.txt @@ -16,7 +16,7 @@ target_sources( freertos_plus_tcp_network_if target_link_libraries(freertos_plus_tcp_network_if PRIVATE - slirp # TODO + slirp ) target_link_libraries( freertos_plus_tcp_network_if diff --git a/source/portable/NetworkInterface/pic32mzef/CMakeLists.txt b/source/portable/NetworkInterface/pic32mzef/CMakeLists.txt index 31f5ff6ea3..5e295e7573 100644 --- a/source/portable/NetworkInterface/pic32mzef/CMakeLists.txt +++ b/source/portable/NetworkInterface/pic32mzef/CMakeLists.txt @@ -6,7 +6,7 @@ endif() #------------------------------------------------------------------------------ add_library( freertos_plus_tcp_network_if STATIC ) -# TODO What about BufferAllocation_2.c here? +# What about BufferAllocation_2.c here? target_sources( freertos_plus_tcp_network_if PRIVATE $<$:NetworkInterface_eth.c> diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index fb71ba3463..0a3de4a8a1 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -1,4 +1,6 @@ -add_subdirectory(build-combination) +if(FREERTOS_PLUS_TCP_ENABLE_BUILD_CHECKS) + add_subdirectory(build-combination) +endif() if(FREERTOS_PLUS_TCP_BUILD_TEST) add_subdirectory(Coverity) diff --git a/test/FreeRTOS-Kernel b/test/FreeRTOS-Kernel index 0240cd55f2..dbf70559b2 160000 --- a/test/FreeRTOS-Kernel +++ b/test/FreeRTOS-Kernel @@ -1 +1 @@ -Subproject commit 0240cd55f20be7100439b606086709b74a105cb1 +Subproject commit dbf70559b27d39c1fdb68dfb9a32140b6a6777a0 diff --git a/test/build-combination/AllDisable/FreeRTOSIPConfig.h b/test/build-combination/AllDisable/FreeRTOSIPConfig.h index 4fa5a62250..b84c2670c6 100644 --- a/test/build-combination/AllDisable/FreeRTOSIPConfig.h +++ b/test/build-combination/AllDisable/FreeRTOSIPConfig.h @@ -294,4 +294,10 @@ #define portINLINE __inline +#define ipconfigISO_STRICTNESS_VIOLATION_START \ + _Pragma("GCC diagnostic push") \ + _Pragma("GCC diagnostic ignored \"-Wpedantic\"") + +#define ipconfigISO_STRICTNESS_VIOLATION_END _Pragma("GCC diagnostic pop") + #endif /* FREERTOS_IP_CONFIG_H */ diff --git a/test/build-combination/AllEnable/FreeRTOSIPConfig.h b/test/build-combination/AllEnable/FreeRTOSIPConfig.h index 769bd39fdb..bdafa06272 100644 --- a/test/build-combination/AllEnable/FreeRTOSIPConfig.h +++ b/test/build-combination/AllEnable/FreeRTOSIPConfig.h @@ -322,4 +322,10 @@ #define portINLINE __inline +#define ipconfigISO_STRICTNESS_VIOLATION_START \ + _Pragma("GCC diagnostic push") \ + _Pragma("GCC diagnostic ignored \"-Wpedantic\"") + +#define ipconfigISO_STRICTNESS_VIOLATION_END _Pragma("GCC diagnostic pop") + #endif /* FREERTOS_IP_CONFIG_H */ diff --git a/test/build-combination/CMakeLists.txt b/test/build-combination/CMakeLists.txt index 23505fca3a..0fb813e576 100644 --- a/test/build-combination/CMakeLists.txt +++ b/test/build-combination/CMakeLists.txt @@ -1,3 +1,26 @@ +# Select the appropriate Build Test configuration +set(FREERTOS_PLUS_TCP_TEST_CONFIGURATION "CUSTOM" CACHE STRING "FreeRTOS Plus TCP Build Test configuration") +set(FREERTOS_PLUS_TCP_TEST_CONFIGURATION_LIST + CUSTOM # Custom (external) configuration -eg from a top-level project + ENABLE_ALL # Enable all configuration settings + ENABLE_ALL_IPV4 # Enable all configuration settings IPv4 UDP + ENABLE_ALL_IPV6 # Enable all configuration settings IPv6 UDP + ENABLE_ALL_IPV4_TCP # Enable all configuration settings IPv4 TCP + ENABLE_ALL_IPV6_TCP # Enable all configuration settings IPv6 TCP + ENABLE_ALL_IPV4_IPV6 # Enable all configuration settings IPv4 IPv6 UDP + DISABLE_ALL # Disable all configuration settings + HEADER_SELF_CONTAIN # Enable header self contain test + DEFAULT_CONF # Default (typical) configuration +) +if(NOT FREERTOS_PLUS_TCP_TEST_CONFIGURATION IN_LIST FREERTOS_PLUS_TCP_TEST_CONFIGURATION_LIST) + message(FATAL_ERROR "Invalid FREERTOS_PLUS_TCP_TEST_CONFIGURATION value '${FREERTOS_PLUS_TCP_TEST_CONFIGURATION}' should be one of: ${FREERTOS_PLUS_TCP_TEST_CONFIGURATION_LIST}") +else() + message(STATUS "Using FreeRTOS-Plus-TCP Test Configuration : ${FREERTOS_PLUS_TCP_TEST_CONFIGURATION}") + if (NOT FREERTOS_PLUS_TCP_TEST_CONFIGURATION STREQUAL "CUSTOM") + message(WARNING "FreeRTOS-Kernel configuration settings are configured by FreeRTOS-Plus-TCP") + endif() +endif() + add_library( freertos_plus_tcp_config_common INTERFACE ) target_include_directories(freertos_plus_tcp_config_common INTERFACE Common ) @@ -75,6 +98,7 @@ else() endif() # FreeRTOS-Plus-TCP compilation options configuration +set_property(TARGET freertos_plus_tcp PROPERTY C_STANDARD 90) target_compile_options(freertos_plus_tcp PRIVATE diff --git a/test/build-combination/Enable_IPv4/FreeRTOSIPConfig.h b/test/build-combination/Enable_IPv4/FreeRTOSIPConfig.h index 41ca29e67e..1af6f8bf92 100644 --- a/test/build-combination/Enable_IPv4/FreeRTOSIPConfig.h +++ b/test/build-combination/Enable_IPv4/FreeRTOSIPConfig.h @@ -325,4 +325,10 @@ #define portINLINE __inline +#define ipconfigISO_STRICTNESS_VIOLATION_START \ + _Pragma("GCC diagnostic push") \ + _Pragma("GCC diagnostic ignored \"-Wpedantic\"") + +#define ipconfigISO_STRICTNESS_VIOLATION_END _Pragma("GCC diagnostic pop") + #endif /* FREERTOS_IP_CONFIG_H */ diff --git a/test/build-combination/Enable_IPv4_IPv6/FreeRTOSIPConfig.h b/test/build-combination/Enable_IPv4_IPv6/FreeRTOSIPConfig.h index 33c322b3f3..758c68f907 100644 --- a/test/build-combination/Enable_IPv4_IPv6/FreeRTOSIPConfig.h +++ b/test/build-combination/Enable_IPv4_IPv6/FreeRTOSIPConfig.h @@ -325,4 +325,10 @@ #define portINLINE __inline +#define ipconfigISO_STRICTNESS_VIOLATION_START \ + _Pragma("GCC diagnostic push") \ + _Pragma("GCC diagnostic ignored \"-Wpedantic\"") + +#define ipconfigISO_STRICTNESS_VIOLATION_END _Pragma("GCC diagnostic pop") + #endif /* FREERTOS_IP_CONFIG_H */ diff --git a/test/build-combination/Enable_IPv4_TCP/FreeRTOSIPConfig.h b/test/build-combination/Enable_IPv4_TCP/FreeRTOSIPConfig.h index ca3b03a46c..9689f54a66 100644 --- a/test/build-combination/Enable_IPv4_TCP/FreeRTOSIPConfig.h +++ b/test/build-combination/Enable_IPv4_TCP/FreeRTOSIPConfig.h @@ -325,4 +325,10 @@ #define portINLINE __inline +#define ipconfigISO_STRICTNESS_VIOLATION_START \ + _Pragma("GCC diagnostic push") \ + _Pragma("GCC diagnostic ignored \"-Wpedantic\"") + +#define ipconfigISO_STRICTNESS_VIOLATION_END _Pragma("GCC diagnostic pop") + #endif /* FREERTOS_IP_CONFIG_H */ diff --git a/test/build-combination/Enable_IPv6/FreeRTOSIPConfig.h b/test/build-combination/Enable_IPv6/FreeRTOSIPConfig.h index 5838f89d7e..5be4d7c3f4 100644 --- a/test/build-combination/Enable_IPv6/FreeRTOSIPConfig.h +++ b/test/build-combination/Enable_IPv6/FreeRTOSIPConfig.h @@ -325,4 +325,10 @@ #define portINLINE __inline +#define ipconfigISO_STRICTNESS_VIOLATION_START \ + _Pragma("GCC diagnostic push") \ + _Pragma("GCC diagnostic ignored \"-Wpedantic\"") + +#define ipconfigISO_STRICTNESS_VIOLATION_END _Pragma("GCC diagnostic pop") + #endif /* FREERTOS_IP_CONFIG_H */ diff --git a/test/build-combination/Enable_IPv6_TCP/FreeRTOSIPConfig.h b/test/build-combination/Enable_IPv6_TCP/FreeRTOSIPConfig.h index a3fc56f2a9..2a4b581d9e 100644 --- a/test/build-combination/Enable_IPv6_TCP/FreeRTOSIPConfig.h +++ b/test/build-combination/Enable_IPv6_TCP/FreeRTOSIPConfig.h @@ -325,4 +325,10 @@ #define portINLINE __inline +#define ipconfigISO_STRICTNESS_VIOLATION_START \ + _Pragma("GCC diagnostic push") \ + _Pragma("GCC diagnostic ignored \"-Wpedantic\"") + +#define ipconfigISO_STRICTNESS_VIOLATION_END _Pragma("GCC diagnostic pop") + #endif /* FREERTOS_IP_CONFIG_H */ diff --git a/test/build-combination/Header_Self_Contain/FreeRTOSIPConfig.h b/test/build-combination/Header_Self_Contain/FreeRTOSIPConfig.h index c27b20c3cc..0516653469 100644 --- a/test/build-combination/Header_Self_Contain/FreeRTOSIPConfig.h +++ b/test/build-combination/Header_Self_Contain/FreeRTOSIPConfig.h @@ -321,4 +321,10 @@ #define portINLINE __inline +#define ipconfigISO_STRICTNESS_VIOLATION_START \ + _Pragma("GCC diagnostic push") \ + _Pragma("GCC diagnostic ignored \"-Wpedantic\"") + +#define ipconfigISO_STRICTNESS_VIOLATION_END _Pragma("GCC diagnostic pop") + #endif /* FREERTOS_IP_CONFIG_H */ diff --git a/test/build-combination/README.md b/test/build-combination/README.md index 8d7aca4957..a57b63c0ad 100644 --- a/test/build-combination/README.md +++ b/test/build-combination/README.md @@ -9,19 +9,19 @@ All the CMake commands are to be run from the root of the repository. * Build checks (Enable all functionalities) ``` -cmake -S . -B build -DFREERTOS_PLUS_TCP_TEST_CONFIGURATION=ENABLE_ALL +cmake -S . -B build -DFREERTOS_PLUS_TCP_ENABLE_BUILD_CHECKS=ON -DFREERTOS_PLUS_TCP_TEST_CONFIGURATION=ENABLE_ALL cmake --build build --target freertos_plus_tcp_build_test ``` * Build checks (Disable all functionalities) ``` -cmake -S . -B build -DFREERTOS_PLUS_TCP_TEST_CONFIGURATION=DISABLE_ALL +cmake -S . -B build -DFREERTOS_PLUS_TCP_ENABLE_BUILD_CHECKS=ON -DFREERTOS_PLUS_TCP_TEST_CONFIGURATION=DISABLE_ALL cmake --build build --target freertos_plus_tcp_build_test ``` * Build checks (Default configuration) ``` -cmake -S . -B build -DFREERTOS_PLUS_TCP_TEST_CONFIGURATION=DEFAULT_CONF +cmake -S . -B build -DFREERTOS_PLUS_TCP_ENABLE_BUILD_CHECKS=ON -DFREERTOS_PLUS_TCP_TEST_CONFIGURATION=DEFAULT_CONF cmake --build build --target freertos_plus_tcp_build_test ``` @@ -31,21 +31,21 @@ All the CMake commands are to be run from the root of the repository. * Build checks (Enable all functionalities) ``` -cmake -S . -B build -DFREERTOS_PLUS_TCP_TEST_CONFIGURATION=ENABLE_ALL -DCMAKE_GENERATOR_PLATFORM=Win32 +cmake -S . -B build -DFREERTOS_PLUS_TCP_ENABLE_BUILD_CHECKS=ON -DFREERTOS_PLUS_TCP_TEST_CONFIGURATION=ENABLE_ALL -DCMAKE_GENERATOR_PLATFORM=Win32 ``` Open the generated Visual Studio Solution file `test\build-combination\build\FreeRTOS-Plus-TCP Build Combination.sln` in Visual Studio and click `Build --> Build Solution`. * Build checks (Disable all functionalities) ``` -cmake -S . -B build -DFREERTOS_PLUS_TCP_TEST_CONFIGURATION=ENABLE_ALL -DCMAKE_GENERATOR_PLATFORM=Win32 +cmake -S . -B build -DFREERTOS_PLUS_TCP_ENABLE_BUILD_CHECKS=ON -DFREERTOS_PLUS_TCP_TEST_CONFIGURATION=ENABLE_ALL -DCMAKE_GENERATOR_PLATFORM=Win32 ``` Open the generated Visual Studio Solution file `test\build-combination\build\FreeRTOS-Plus-TCP Build Combination.sln` in Visual Studio and click `Build --> Build Solution`. * Build checks (Default configuration) ``` -cmake -S . -B build -DFREERTOS_PLUS_TCP_TEST_CONFIGURATION=ENABLE_ALL -DCMAKE_GENERATOR_PLATFORM=Win32 +cmake -S . -B build -DFREERTOS_PLUS_TCP_ENABLE_BUILD_CHECKS=ON -DFREERTOS_PLUS_TCP_TEST_CONFIGURATION=ENABLE_ALL -DCMAKE_GENERATOR_PLATFORM=Win32 ``` Open the generated Visual Studio Solution file `test\build-combination\build\FreeRTOS-Plus-TCP Build Combination.sln` in Visual Studio and click `Build --> Build Solution`. diff --git a/test/cbmc/proofs/ARP/ARPAgeCache/ARPAgeCache_harness.c b/test/cbmc/proofs/ARP/ARPAgeCache/ARPAgeCache_harness.c index 5a5b3e7c2a..509cacb7ba 100644 --- a/test/cbmc/proofs/ARP/ARPAgeCache/ARPAgeCache_harness.c +++ b/test/cbmc/proofs/ARP/ARPAgeCache/ARPAgeCache_harness.c @@ -33,6 +33,12 @@ BaseType_t NetworkInterfaceOutputFunction_Stub( struct xNetworkInterface * pxDes return 0; } + +void FreeRTOS_OutputAdvertiseIPv6( NetworkEndPoint_t * pxEndPoint ) +{ + __CPROVER_assert( pxEndPoint != NULL, "The Endpoint cannot be NULL." ); +} + void harness() { /* diff --git a/test/cbmc/proofs/ARP/ARPAgeCache/Makefile.json b/test/cbmc/proofs/ARP/ARPAgeCache/Makefile.json index 24de2ff3c0..b122ddc7dc 100644 --- a/test/cbmc/proofs/ARP/ARPAgeCache/Makefile.json +++ b/test/cbmc/proofs/ARP/ARPAgeCache/Makefile.json @@ -15,6 +15,9 @@ "$(FREERTOS_PLUS_TCP)/source/FreeRTOS_IP.goto", "$(FREERTOS_PLUS_TCP)/source/FreeRTOS_Routing.goto", "$(FREERTOS_PLUS_TCP)/source/FreeRTOS_ARP.goto", + "$(FREERTOS_PLUS_TCP)/source/FreeRTOS_IP_Utils.goto", + "$(FREERTOS_PLUS_TCP)/test/cbmc/stubs/freertos_kernel_api.goto", + "$(FREERTOS_PLUS_TCP)/test/cbmc/stubs/freertos_api.goto", "$(FREERTOS_PLUS_TCP)/test/FreeRTOS-Kernel/tasks.goto" ], "DEF": diff --git a/test/cbmc/proofs/ARP/ARPGetCacheEntry/Configurations.json b/test/cbmc/proofs/ARP/ARPGetCacheEntry/Configurations.json index aa4d602966..3301afb404 100644 --- a/test/cbmc/proofs/ARP/ARPGetCacheEntry/Configurations.json +++ b/test/cbmc/proofs/ARP/ARPGetCacheEntry/Configurations.json @@ -14,6 +14,8 @@ [ "$(ENTRY)_harness.goto", "$(FREERTOS_PLUS_TCP)/source/FreeRTOS_Routing.goto", + "$(FREERTOS_PLUS_TCP)/source/FreeRTOS_IPv4.goto", + "$(FREERTOS_PLUS_TCP)/source/FreeRTOS_IPv4_Utils.goto", "$(FREERTOS_PLUS_TCP)/source/FreeRTOS_ARP.goto" ], "DEF": diff --git a/test/cbmc/proofs/ARP/ARPProcessPacket/ARPProcessPacket_harness.c b/test/cbmc/proofs/ARP/ARPProcessPacket/ARPProcessPacket_harness.c index 539f02d180..98841d9d09 100644 --- a/test/cbmc/proofs/ARP/ARPProcessPacket/ARPProcessPacket_harness.c +++ b/test/cbmc/proofs/ARP/ARPProcessPacket/ARPProcessPacket_harness.c @@ -1,5 +1,3 @@ -#include "cbmc.h" - /* FreeRTOS includes. */ #include "FreeRTOS.h" #include "queue.h" @@ -10,8 +8,36 @@ #include "FreeRTOS_ARP.h" #include "FreeRTOS_Routing.h" +/* CBMC includes. */ +#include "cbmc.h" + /* This pointer is maintained by the IP-task. Defined in FreeRTOS_IP.c */ extern NetworkBufferDescriptor_t * pxARPWaitingNetworkBuffer; +NetworkEndPoint_t * pxNetworkEndPoint_Temp; + +/* Stub FreeRTOS_FindEndPointOnNetMask_IPv6 as its not relevant to the + * correctness of the proof */ +NetworkEndPoint_t * FreeRTOS_FindEndPointOnNetMask_IPv6( const IPv6_Address_t * pxIPv6Address ) +{ + __CPROVER_assert( pxIPv6Address != NULL, "Precondition: pxIPv6Address != NULL" ); + + /* Assume at least one end-point is available */ + return pxNetworkEndPoint_Temp; +} + +/* Stub FreeRTOS_FindEndPointOnNetMask_IPv6 as its not relevant to the + * correctness of the proof */ +NetworkEndPoint_t * FreeRTOS_FindEndPointOnNetMask( uint32_t ulIPAddress ) +{ + /* Assume at least one end-point is available */ + return pxNetworkEndPoint_Temp; +} + +/* Get rid of configASSERT in FreeRTOS_TCP_IP.c */ +BaseType_t xIsCallingFromIPTask( void ) +{ + return pdTRUE; +} /* This is an output function and need not be tested with this proof. */ void FreeRTOS_OutputARPRequest_Multi( NetworkEndPoint_t * pxEndPoint, @@ -20,11 +46,11 @@ void FreeRTOS_OutputARPRequest_Multi( NetworkEndPoint_t * pxEndPoint, } /* This function is proved elsewhere hence stubbing it out */ -eARPLookupResult_t eARPGetCacheEntry( uint32_t * pulIPAddress, +eResolutionLookupResult_t eARPGetCacheEntry( uint32_t * pulIPAddress, MACAddress_t * const pxMACAddress, struct xNetworkEndPoint ** ppxEndPoint ) { - eARPLookupResult_t eReturn; + eResolutionLookupResult_t eReturn; __CPROVER_assert( pulIPAddress != NULL, "pulIPAddress cannot be NULL." ); __CPROVER_assert( pxMACAddress != NULL, "pxMACAddress cannot be NULL." ); @@ -36,9 +62,19 @@ eARPLookupResult_t eARPGetCacheEntry( uint32_t * pulIPAddress, void harness() { - NetworkBufferDescriptor_t xLocalBuffer; + NetworkBufferDescriptor_t * pxLocalBuffer; + NetworkBufferDescriptor_t * pxNetworkBuffer2; + TickType_t xBlockTimeTicks; uint16_t usEthernetBufferSize; + /* + * The assumption made here is that the buffer pointed by pucEthernetBuffer + * is at least allocated to sizeof(ARPPacket_t) size but eventually an even larger buffer. + * This is not checked inside eARPProcessPacket. + */ + uint8_t ucBUFFER_SIZE; + + /* Non deterministically determine whether the pxARPWaitingNetworkBuffer will * point to some valid data or will it be NULL. */ if( nondet_bool() ) @@ -47,48 +83,34 @@ void harness() * checked in the function as the pointer is stored by the IP-task itself * and therefore it will always be of the required size. */ __CPROVER_assume( usEthernetBufferSize >= sizeof( IPPacket_t ) ); - - /* Add matching data length to the network buffer descriptor. */ - __CPROVER_assume( xLocalBuffer.xDataLength == usEthernetBufferSize ); - - xLocalBuffer.pucEthernetBuffer = malloc( usEthernetBufferSize ); + pxLocalBuffer = pxGetNetworkBufferWithDescriptor( usEthernetBufferSize, xBlockTimeTicks ); /* Since this pointer is maintained by the IP-task, either the pointer - * pxARPWaitingNetworkBuffer will be NULL or xLocalBuffer.pucEthernetBuffer + * pxARPWaitingNetworkBuffer will be NULL or pxLocalBuffer->pucEthernetBuffer * will be non-NULL. */ - __CPROVER_assume( xLocalBuffer.pucEthernetBuffer != NULL ); + __CPROVER_assume( pxLocalBuffer != NULL ); + __CPROVER_assume( pxLocalBuffer->pucEthernetBuffer != NULL ); + __CPROVER_assume( pxLocalBuffer->xDataLength == usEthernetBufferSize ); - pxARPWaitingNetworkBuffer = &xLocalBuffer; + pxARPWaitingNetworkBuffer = pxLocalBuffer; } else { pxARPWaitingNetworkBuffer = NULL; } - /* - * The assumption made here is that the buffer pointed by pucEthernetBuffer - * is at least allocated to sizeof(ARPPacket_t) size but eventually an even larger buffer. - * This is not checked inside eARPProcessPacket. - */ - uint8_t ucBUFFER_SIZE; - - void * xBuffer = malloc( ucBUFFER_SIZE + sizeof( ARPPacket_t ) ); - - __CPROVER_assume( xBuffer != NULL ); - - NetworkBufferDescriptor_t xNetworkBuffer2; - - xNetworkBuffer2.pucEthernetBuffer = xBuffer; - xNetworkBuffer2.xDataLength = ucBUFFER_SIZE + sizeof( ARPPacket_t ); + pxNetworkBuffer2 = pxGetNetworkBufferWithDescriptor( ucBUFFER_SIZE + sizeof( ARPPacket_t ), xBlockTimeTicks ); + __CPROVER_assume( pxNetworkBuffer2 != NULL ); + __CPROVER_assume( pxNetworkBuffer2->pucEthernetBuffer != NULL ); /* * This proof assumes one end point is present. */ - xNetworkBuffer2.pxEndPoint = ( NetworkEndPoint_t * ) malloc( sizeof( NetworkEndPoint_t ) ); - __CPROVER_assume( xNetworkBuffer2.pxEndPoint != NULL ); - xNetworkBuffer2.pxEndPoint->pxNext = NULL; + pxNetworkBuffer2->pxEndPoint = ( NetworkEndPoint_t * ) safeMalloc( sizeof( NetworkEndPoint_t ) ); + __CPROVER_assume( pxNetworkBuffer2->pxEndPoint != NULL ); + pxNetworkBuffer2->pxEndPoint->pxNext = NULL; /* eARPProcessPacket will be called in the source code only after checking if - * xNetworkBuffer2.pucEthernetBuffer is not NULL, hence, __CPROVER_assume( xBuffer != NULL ); */ - eARPProcessPacket( &xNetworkBuffer2 ); + * pxNetworkBuffer2->pucEthernetBuffer is not NULL, hence, __CPROVER_assume( xBuffer != NULL ); */ + eARPProcessPacket( pxNetworkBuffer2 ); } diff --git a/test/cbmc/proofs/ARP/ARPProcessPacket/Makefile.json b/test/cbmc/proofs/ARP/ARPProcessPacket/Makefile.json index 00079ded19..003611ae97 100644 --- a/test/cbmc/proofs/ARP/ARPProcessPacket/Makefile.json +++ b/test/cbmc/proofs/ARP/ARPProcessPacket/Makefile.json @@ -11,6 +11,9 @@ [ "$(ENTRY)_harness.goto", "$(FREERTOS_PLUS_TCP)/source/FreeRTOS_ARP.goto", - "$(FREERTOS_PLUS_TCP)/source/FreeRTOS_IP.goto" + "$(FREERTOS_PLUS_TCP)/source/FreeRTOS_IP.goto", + "$(FREERTOS_PLUS_TCP)/test/cbmc/stubs/cbmc.goto", + "$(FREERTOS_PLUS_TCP)/test/cbmc/stubs/freertos_api.goto", + "$(FREERTOS_PLUS_TCP)/test/cbmc/stubs/freertos_kernel_api.goto" ] } diff --git a/test/cbmc/proofs/ARP/ARPSendGratuitous/Makefile.json b/test/cbmc/proofs/ARP/ARPSendGratuitous/Makefile.json index f069f59597..044a2b2c2d 100644 --- a/test/cbmc/proofs/ARP/ARPSendGratuitous/Makefile.json +++ b/test/cbmc/proofs/ARP/ARPSendGratuitous/Makefile.json @@ -10,7 +10,9 @@ "$(ENTRY)_harness.goto", "$(FREERTOS_PLUS_TCP)/source/FreeRTOS_ARP.goto", "$(FREERTOS_PLUS_TCP)/source/FreeRTOS_IP.goto", - "$(FREERTOS_PLUS_TCP)/test/FreeRTOS-Kernel/tasks.goto" + "$(FREERTOS_PLUS_TCP)/source/FreeRTOS_IP_Utils.goto", + "$(FREERTOS_PLUS_TCP)/test/FreeRTOS-Kernel/tasks.goto", + "$(FREERTOS_PLUS_TCP)/test/cbmc/stubs/freertos_kernel_api.goto" ], "DEF": [ diff --git a/test/cbmc/proofs/ARP/ARP_FreeRTOS_OutputARPRequest/Configurations.json b/test/cbmc/proofs/ARP/ARP_FreeRTOS_OutputARPRequest/Configurations.json index 62bb3e0523..5e2c516c39 100644 --- a/test/cbmc/proofs/ARP/ARP_FreeRTOS_OutputARPRequest/Configurations.json +++ b/test/cbmc/proofs/ARP/ARP_FreeRTOS_OutputARPRequest/Configurations.json @@ -37,7 +37,9 @@ "$(ENTRY)_harness.goto", "$(FREERTOS_PLUS_TCP)/source/FreeRTOS_IP.goto", "$(FREERTOS_PLUS_TCP)/source/FreeRTOS_Routing.goto", - "$(FREERTOS_PLUS_TCP)/source/FreeRTOS_ARP.goto" + "$(FREERTOS_PLUS_TCP)/source/FreeRTOS_ARP.goto", + "$(FREERTOS_PLUS_TCP)/test/cbmc/stubs/cbmc.goto", + "$(FREERTOS_PLUS_TCP)/test/cbmc/stubs/freertos_api.goto" ], #That is the minimal required size for an ARPPacket_t plus offset in the buffer. "MINIMUM_PACKET_BYTES": 50, diff --git a/test/cbmc/proofs/ARP/ARP_FreeRTOS_OutputARPRequest/OutputARPRequest_harness.c b/test/cbmc/proofs/ARP/ARP_FreeRTOS_OutputARPRequest/OutputARPRequest_harness.c index 9337fb4f74..b5b45cf674 100644 --- a/test/cbmc/proofs/ARP/ARP_FreeRTOS_OutputARPRequest/OutputARPRequest_harness.c +++ b/test/cbmc/proofs/ARP/ARP_FreeRTOS_OutputARPRequest/OutputARPRequest_harness.c @@ -35,6 +35,8 @@ #include "FreeRTOS_IP_Private.h" #include "FreeRTOS_ARP.h" +/* CBMC includes. */ +#include "cbmc.h" ARPPacket_t xARPPacket; NetworkBufferDescriptor_t xNetworkBuffer; @@ -56,15 +58,15 @@ NetworkBufferDescriptor_t * pxGetNetworkBufferWithDescriptor( size_t xRequestedS { #ifdef CBMC_PROOF_ASSUMPTION_HOLDS #if ( ipconfigETHERNET_MINIMUM_PACKET_BYTES > 0 ) - xNetworkBuffer.pucEthernetBuffer = malloc( ipconfigETHERNET_MINIMUM_PACKET_BYTES ); + xNetworkBuffer.pucEthernetBuffer = safeMalloc( ipconfigETHERNET_MINIMUM_PACKET_BYTES ); #else - xNetworkBuffer.pucEthernetBuffer = malloc( xRequestedSizeBytes ); + xNetworkBuffer.pucEthernetBuffer = safeMalloc( xRequestedSizeBytes ); #endif #else uint32_t malloc_size; __CPROVER_assert( !__CPROVER_overflow_mult( 2, xRequestedSizeBytes ) ); __CPROVER_assume( malloc_size > 0 && malloc_size < 2 * xRequestedSizeBytes ); - xNetworkBuffer.pucEthernetBuffer = malloc( malloc_size ); + xNetworkBuffer.pucEthernetBuffer = safeMalloc( malloc_size ); #endif __CPROVER_assume( xNetworkBuffer.pucEthernetBuffer != NULL ); @@ -72,6 +74,21 @@ NetworkBufferDescriptor_t * pxGetNetworkBufferWithDescriptor( size_t xRequestedS return &xNetworkBuffer; } +/* STUB! + * In this function, it only allocates network buffer by pxGetNetworkBufferWithDescriptor + * stub function above here. In this case, we should just free the allocated pucEthernetBuffer. + */ +void vReleaseNetworkBufferAndDescriptor( NetworkBufferDescriptor_t * const pxNetworkBuffer ) +{ + __CPROVER_assert( pxNetworkBuffer != NULL, + "Precondition: pxNetworkBuffer != NULL" ); + + if( pxNetworkBuffer->pucEthernetBuffer != NULL ) + { + free( pxNetworkBuffer->pucEthernetBuffer ); + } +} + BaseType_t NetworkInterfaceOutputFunction_Stub( struct xNetworkInterface * pxDescriptor, NetworkBufferDescriptor_t * const pxNetworkBuffer, BaseType_t xReleaseAfterSend ) @@ -81,6 +98,14 @@ BaseType_t NetworkInterfaceOutputFunction_Stub( struct xNetworkInterface * pxDes __CPROVER_assert( pxNetworkBuffer->pucEthernetBuffer != NULL, "The ethernet buffer cannot be NULL." ); } +BaseType_t xIsCallingFromIPTask( void ) +{ + BaseType_t xReturn; + + __CPROVER_assume( xReturn == pdFALSE || xReturn == pdTRUE ); + + return xReturn; +} void harness() { @@ -92,16 +117,16 @@ void harness() * Assumes one endpoint and interface is present. */ - pxNetworkEndPoints = ( NetworkEndPoint_t * ) malloc( sizeof( NetworkEndPoint_t ) ); + pxNetworkEndPoints = ( NetworkEndPoint_t * ) safeMalloc( sizeof( NetworkEndPoint_t ) ); __CPROVER_assume( pxNetworkEndPoints != NULL ); /* Interface init. */ - pxNetworkEndPoints->pxNetworkInterface = ( NetworkInterface_t * ) malloc( sizeof( NetworkInterface_t ) ); + pxNetworkEndPoints->pxNetworkInterface = ( NetworkInterface_t * ) safeMalloc( sizeof( NetworkInterface_t ) ); __CPROVER_assume( pxNetworkEndPoints->pxNetworkInterface != NULL ); if( nondet_bool() ) { - pxNetworkEndPoints->pxNext = ( NetworkEndPoint_t * ) malloc( sizeof( NetworkEndPoint_t ) ); + pxNetworkEndPoints->pxNext = ( NetworkEndPoint_t * ) safeMalloc( sizeof( NetworkEndPoint_t ) ); __CPROVER_assume( pxNetworkEndPoints->pxNext != NULL ); pxNetworkEndPoints->pxNext->pxNext = NULL; pxNetworkEndPoints->pxNext->pxNetworkInterface = pxNetworkEndPoints->pxNetworkInterface; diff --git a/test/cbmc/proofs/ARP/ARP_OutputARPRequest_buffer_alloc1/Configurations.json b/test/cbmc/proofs/ARP/ARP_OutputARPRequest_buffer_alloc1/Configurations.json index e243382c31..ff5898c18c 100644 --- a/test/cbmc/proofs/ARP/ARP_OutputARPRequest_buffer_alloc1/Configurations.json +++ b/test/cbmc/proofs/ARP/ARP_OutputARPRequest_buffer_alloc1/Configurations.json @@ -14,7 +14,9 @@ "$(FREERTOS_PLUS_TCP)/source/FreeRTOS_Routing.goto", "$(FREERTOS_PLUS_TCP)/source/portable/BufferManagement/BufferAllocation_1.goto", "$(FREERTOS_PLUS_TCP)/test/FreeRTOS-Kernel/list.goto", - "$(FREERTOS_PLUS_TCP)/test/FreeRTOS-Kernel/queue.goto" + "$(FREERTOS_PLUS_TCP)/test/FreeRTOS-Kernel/queue.goto", + "$(FREERTOS_PLUS_TCP)/test/cbmc/proofs/CBMCStubLibrary/tasksStubs.goto", + "$(FREERTOS_PLUS_TCP)/test/cbmc/stubs/freertos_kernel_api.goto" ], "DEF": [ diff --git a/test/cbmc/proofs/ARP/ARP_OutputARPRequest_buffer_alloc1/OutputARPRequest_harness.c b/test/cbmc/proofs/ARP/ARP_OutputARPRequest_buffer_alloc1/OutputARPRequest_harness.c index 492d97683a..03c74e467c 100644 --- a/test/cbmc/proofs/ARP/ARP_OutputARPRequest_buffer_alloc1/OutputARPRequest_harness.c +++ b/test/cbmc/proofs/ARP/ARP_OutputARPRequest_buffer_alloc1/OutputARPRequest_harness.c @@ -75,6 +75,14 @@ BaseType_t NetworkInterfaceOutputFunction_Stub( struct xNetworkInterface * pxDes } } +BaseType_t xIsCallingFromIPTask( void ) +{ + BaseType_t xReturn; + + __CPROVER_assume( xReturn == pdFALSE || xReturn == pdTRUE ); + + return xReturn; +} void harness() { diff --git a/test/cbmc/proofs/ARP/ARP_OutputARPRequest_buffer_alloc2/Configurations.json b/test/cbmc/proofs/ARP/ARP_OutputARPRequest_buffer_alloc2/Configurations.json index 5b2cdd30db..d37f17720e 100644 --- a/test/cbmc/proofs/ARP/ARP_OutputARPRequest_buffer_alloc2/Configurations.json +++ b/test/cbmc/proofs/ARP/ARP_OutputARPRequest_buffer_alloc2/Configurations.json @@ -14,7 +14,9 @@ "$(FREERTOS_PLUS_TCP)/source/FreeRTOS_Routing.goto", "$(FREERTOS_PLUS_TCP)/source/portable/BufferManagement/BufferAllocation_2.goto", "$(FREERTOS_PLUS_TCP)/test/FreeRTOS-Kernel/list.goto", - "$(FREERTOS_PLUS_TCP)/test/FreeRTOS-Kernel/queue.goto" + "$(FREERTOS_PLUS_TCP)/test/FreeRTOS-Kernel/queue.goto", + "$(FREERTOS_PLUS_TCP)/test/cbmc/stubs/freertos_kernel_api.goto", + "$(FREERTOS_PLUS_TCP)/test/cbmc/proofs/CBMCStubLibrary/tasksStubs.goto" ], "DEF": [ diff --git a/test/cbmc/proofs/ARP/ARP_OutputARPRequest_buffer_alloc2/OutputARPRequest_harness.c b/test/cbmc/proofs/ARP/ARP_OutputARPRequest_buffer_alloc2/OutputARPRequest_harness.c index 4d84934494..b87ae8b30e 100644 --- a/test/cbmc/proofs/ARP/ARP_OutputARPRequest_buffer_alloc2/OutputARPRequest_harness.c +++ b/test/cbmc/proofs/ARP/ARP_OutputARPRequest_buffer_alloc2/OutputARPRequest_harness.c @@ -55,6 +55,15 @@ BaseType_t NetworkInterfaceOutputFunction_Stub( struct xNetworkInterface * pxDes } } +BaseType_t xIsCallingFromIPTask( void ) +{ + BaseType_t xReturn; + + __CPROVER_assume( xReturn == pdFALSE || xReturn == pdTRUE ); + + return xReturn; +} + void harness() { BaseType_t xRes = xNetworkBuffersInitialise(); diff --git a/test/cbmc/proofs/ARP/xCheckRequiresARPResolution/xCheckRequiresARPResolution_harness.c b/test/cbmc/proofs/ARP/xCheckRequiresARPResolution/xCheckRequiresARPResolution_harness.c index 99c8c5051a..995a98a5ea 100644 --- a/test/cbmc/proofs/ARP/xCheckRequiresARPResolution/xCheckRequiresARPResolution_harness.c +++ b/test/cbmc/proofs/ARP/xCheckRequiresARPResolution/xCheckRequiresARPResolution_harness.c @@ -55,11 +55,11 @@ IPv6_Type_t xIPv6_GetIPType( const IPv6_Address_t * pxAddress ) } /* Abstraction of eNDGetCacheEntry. */ -eARPLookupResult_t eNDGetCacheEntry( IPv6_Address_t * pxIPAddress, +eResolutionLookupResult_t eNDGetCacheEntry( IPv6_Address_t * pxIPAddress, MACAddress_t * const pxMACAddress, struct xNetworkEndPoint ** ppxEndPoint ) { - eARPLookupResult_t xReturn; + eResolutionLookupResult_t xReturn; __CPROVER_assert( __CPROVER_r_ok( pxIPAddress, sizeof( IPv6_Address_t ) ), "pxIPAddress must be readable" ); __CPROVER_assert( __CPROVER_w_ok( pxMACAddress, sizeof( MACAddress_t ) ), "pxMACAddress must be writeable" ); diff --git a/test/cbmc/proofs/CheckOptionsInner/CheckOptionsInner_harness.c b/test/cbmc/proofs/CheckOptionsInner/CheckOptionsInner_harness.c index e4a08e2eee..8ac5d6a827 100644 --- a/test/cbmc/proofs/CheckOptionsInner/CheckOptionsInner_harness.c +++ b/test/cbmc/proofs/CheckOptionsInner/CheckOptionsInner_harness.c @@ -87,7 +87,7 @@ void harness() /* Preconditions */ /* CBMC model of pointers limits the size of the buffer */ - __CPROVER_assume( buffer_size < CBMC_MAX_OBJECT_SIZE ); + __CPROVER_assume( buffer_size < ipconfigNETWORK_MTU ); /* Both preconditions are required to avoid integer overflow in the */ /* pointer offset of the pointer pucPtr + uxIndex + 8 */ diff --git a/test/cbmc/proofs/CheckOptionsInner/Makefile.json b/test/cbmc/proofs/CheckOptionsInner/Makefile.json index a902bcc944..522ca4ccad 100644 --- a/test/cbmc/proofs/CheckOptionsInner/Makefile.json +++ b/test/cbmc/proofs/CheckOptionsInner/Makefile.json @@ -12,6 +12,7 @@ "OBJS": [ "$(ENTRY)_harness.goto", + "$(FREERTOS_PLUS_TCP)/source/FreeRTOS_IP_Utils.goto", "$(FREERTOS_PLUS_TCP)/source/FreeRTOS_TCP_Reception.goto", "$(FREERTOS_PLUS_TCP)/source/FreeRTOS_TCP_IP.goto", "$(FREERTOS_PLUS_TCP)/source/FreeRTOS_TCP_WIN.goto", @@ -21,6 +22,7 @@ ], "DEF": [ - "ipconfigUSE_TCP=1" + "ipconfigUSE_TCP=1", + "ipconfigNETWORK_MTU=586" ] } diff --git a/test/cbmc/proofs/CheckOptionsOuter/CheckOptionsOuter_harness.c b/test/cbmc/proofs/CheckOptionsOuter/CheckOptionsOuter_harness.c index 3d58d0dd1d..867305d930 100644 --- a/test/cbmc/proofs/CheckOptionsOuter/CheckOptionsOuter_harness.c +++ b/test/cbmc/proofs/CheckOptionsOuter/CheckOptionsOuter_harness.c @@ -81,7 +81,7 @@ void harness() ****************************************************************/ /* CBMC model of pointers limits the size of the buffer */ - __CPROVER_assume( buffer_size < CBMC_MAX_OBJECT_SIZE ); + __CPROVER_assume( buffer_size < ipconfigNETWORK_MTU ); /* Preconditions */ __CPROVER_assume( 8 <= buffer_size ); /* ulFirst and ulLast */ diff --git a/test/cbmc/proofs/CheckOptionsOuter/Makefile.json b/test/cbmc/proofs/CheckOptionsOuter/Makefile.json index d97be23e62..898d1ea5ba 100644 --- a/test/cbmc/proofs/CheckOptionsOuter/Makefile.json +++ b/test/cbmc/proofs/CheckOptionsOuter/Makefile.json @@ -12,6 +12,7 @@ "OBJS": [ "$(ENTRY)_harness.goto", + "$(FREERTOS_PLUS_TCP)/source/FreeRTOS_IP_Utils.goto", "$(FREERTOS_PLUS_TCP)/source/FreeRTOS_TCP_Reception.goto", "$(FREERTOS_PLUS_TCP)/source/FreeRTOS_TCP_WIN.goto", "$(FREERTOS_PLUS_TCP)/source/FreeRTOS_Stream_Buffer.goto", @@ -20,5 +21,6 @@ ], "DEF": [ + "ipconfigNETWORK_MTU=586" ] } diff --git a/test/cbmc/proofs/DHCP/DHCPProcess/DHCPProcess_harness.c b/test/cbmc/proofs/DHCP/DHCPProcess/DHCPProcess_harness.c index 10c6aacf83..29fabf6576 100644 --- a/test/cbmc/proofs/DHCP/DHCPProcess/DHCPProcess_harness.c +++ b/test/cbmc/proofs/DHCP/DHCPProcess/DHCPProcess_harness.c @@ -166,6 +166,13 @@ int32_t FreeRTOS_recvfrom( Socket_t xSocket, return retVal; } +void * vSocketClose( FreeRTOS_Socket_t * pxSocket ) +{ + __CPROVER_assert( pxSocket != NULL, "Closing socket cannot be NULL." ); + + return NULL; +} + /**************************************************************** * The proof of vDHCPProcess ****************************************************************/ diff --git a/test/cbmc/proofs/DHCP/DHCPProcess/Makefile.json b/test/cbmc/proofs/DHCP/DHCPProcess/Makefile.json index 99e79d3b2e..f74a67537a 100644 --- a/test/cbmc/proofs/DHCP/DHCPProcess/Makefile.json +++ b/test/cbmc/proofs/DHCP/DHCPProcess/Makefile.json @@ -24,7 +24,8 @@ "$(FREERTOS_PLUS_TCP)/test/cbmc/stubs/cbmc.goto", "$(FREERTOS_PLUS_TCP)/source/FreeRTOS_DHCP.goto", "$(FREERTOS_PLUS_TCP)/source/FreeRTOS_IP.goto", - "$(FREERTOS_PLUS_TCP)/source/FreeRTOS_ARP.goto" + "$(FREERTOS_PLUS_TCP)/source/FreeRTOS_ARP.goto", + "$(FREERTOS_PLUS_TCP)/test/cbmc/stubs/freertos_api.goto" ], "DEF": [ diff --git a/test/cbmc/proofs/DHCP/DHCPProcessEndPoint/DHCPProcessEndPoint_harness.c b/test/cbmc/proofs/DHCP/DHCPProcessEndPoint/DHCPProcessEndPoint_harness.c index db482595cd..bd53b27456 100644 --- a/test/cbmc/proofs/DHCP/DHCPProcessEndPoint/DHCPProcessEndPoint_harness.c +++ b/test/cbmc/proofs/DHCP/DHCPProcessEndPoint/DHCPProcessEndPoint_harness.c @@ -145,6 +145,35 @@ Socket_t FreeRTOS_socket( BaseType_t xDomain, return ensure_FreeRTOS_Socket_t_is_allocated(); } +void vApplicationIPNetworkEventHook_Multi( eIPCallbackEvent_t eNetworkEvent, + struct xNetworkEndPoint * pxEndPoint ) +{ + __CPROVER_assert( eNetworkEvent == eNetworkUp || eNetworkEvent == eNetworkDown, "Network event is not correct" ); + __CPROVER_assert( pxEndPoint != NULL, "Endpoint cannot be NULL" ); +} + +BaseType_t xIsCallingFromIPTask( void ) +{ + BaseType_t xReturn; + + __CPROVER_assume( xReturn == pdFALSE || xReturn == pdTRUE ); + + return xReturn; +} + +void * vSocketClose( FreeRTOS_Socket_t * pxSocket ) +{ + __CPROVER_assert( pxSocket != NULL, "Closing socket cannot be NULL" ); + + return NULL; +} + +void vManageSolicitedNodeAddress( const struct xNetworkEndPoint * pxEndPoint, + BaseType_t xNetworkGoingUp ) +{ + __CPROVER_assert( pxEndPoint != NULL, "Endpoint cannot be NULL" ); + __CPROVER_assert( pxEndPoint->pxNetworkInterface != NULL, "The network interface cannot be NULL" ); +} /**************************************************************** * The proof of vDHCPProcess @@ -178,6 +207,7 @@ void harness() __CPROVER_assume( pxNetworkEndPoint_Temp != NULL ); pxNetworkEndPoint_Temp->pxNext = NULL; pxNetworkEndPoint_Temp->xDHCPData.xDHCPSocket = NULL; + pxNetworkEndPoint_Temp->pxNetworkInterface = pxNetworkEndPoints->pxNetworkInterface; /**************************************************************** * Initialize the counter used to bound the number of times diff --git a/test/cbmc/proofs/DHCP/DHCPProcessEndPoint/Makefile.json b/test/cbmc/proofs/DHCP/DHCPProcessEndPoint/Makefile.json index ed74976135..59cfc8cc63 100644 --- a/test/cbmc/proofs/DHCP/DHCPProcessEndPoint/Makefile.json +++ b/test/cbmc/proofs/DHCP/DHCPProcessEndPoint/Makefile.json @@ -23,8 +23,10 @@ "$(ENTRY)_harness.goto", "$(FREERTOS_PLUS_TCP)/test/cbmc/stubs/cbmc.goto", "$(FREERTOS_PLUS_TCP)/test/cbmc/stubs/freertos_api.goto", + "$(FREERTOS_PLUS_TCP)/test/cbmc/stubs/freertos_kernel_api.goto", "$(FREERTOS_PLUS_TCP)/source/FreeRTOS_DHCP.goto", "$(FREERTOS_PLUS_TCP)/source/FreeRTOS_IP.goto", + "$(FREERTOS_PLUS_TCP)/source/FreeRTOS_IP_Timers.goto", "$(FREERTOS_PLUS_TCP)/source/FreeRTOS_ARP.goto" ], "DEF": diff --git a/test/cbmc/proofs/DHCPv6/DHCPv6HandleOption/DHCPv6HandleOption_harness.c b/test/cbmc/proofs/DHCPv6/DHCPv6HandleOption/DHCPv6HandleOption_harness.c index 7a54953136..96b30b73cd 100644 --- a/test/cbmc/proofs/DHCPv6/DHCPv6HandleOption/DHCPv6HandleOption_harness.c +++ b/test/cbmc/proofs/DHCPv6/DHCPv6HandleOption/DHCPv6HandleOption_harness.c @@ -74,6 +74,23 @@ BaseType_t __CPROVER_file_local_FreeRTOS_DHCPv6_c_prvDHCPv6_subOption( uint16_t return nondet_BaseType(); } +uint16_t usBitConfig_read_16( BitConfig_t * pxConfig ) +{ + return ( uint16_t ) nondet_uint32(); +} + +uint8_t ucBitConfig_read_8( BitConfig_t * pxConfig ) +{ + return ( uint8_t ) nondet_uint32(); +} + +BaseType_t xBitConfig_read_uc( BitConfig_t * pxConfig, + uint8_t * pucData, + size_t uxSize ) +{ + return nondet_BaseType(); +} + void harness() { BaseType_t xResult; diff --git a/test/cbmc/proofs/DHCPv6/DHCPv6HandleOption/Makefile.json b/test/cbmc/proofs/DHCPv6/DHCPv6HandleOption/Makefile.json index 09859a60b0..ba6dbd18f5 100644 --- a/test/cbmc/proofs/DHCPv6/DHCPv6HandleOption/Makefile.json +++ b/test/cbmc/proofs/DHCPv6/DHCPv6HandleOption/Makefile.json @@ -5,12 +5,6 @@ "--unwind 2", "--nondet-static --flush" ], - "INSTFLAGS": - [ - "--remove-function-body usBitConfig_read_16", - "--remove-function-body xBitConfig_read_uc", - "--remove-function-body ucBitConfig_read_8" - ], "OPT": [ "--export-file-local-symbols" diff --git a/test/cbmc/proofs/DHCPv6/DHCPv6Process/Makefile.json b/test/cbmc/proofs/DHCPv6/DHCPv6Process/Makefile.json index 40839470b2..fba06214ba 100644 --- a/test/cbmc/proofs/DHCPv6/DHCPv6Process/Makefile.json +++ b/test/cbmc/proofs/DHCPv6/DHCPv6Process/Makefile.json @@ -19,6 +19,9 @@ [ "$(ENTRY)_harness.goto", "$(FREERTOS_PLUS_TCP)/test/cbmc/stubs/cbmc.goto", - "$(FREERTOS_PLUS_TCP)/source/FreeRTOS_DHCPv6.goto" + "$(FREERTOS_PLUS_TCP)/test/cbmc/stubs/freertos_api.goto", + "$(FREERTOS_PLUS_TCP)/test/cbmc/stubs/freertos_kernel_api.goto", + "$(FREERTOS_PLUS_TCP)/source/FreeRTOS_DHCPv6.goto", + "$(FREERTOS_PLUS_TCP)/source/FreeRTOS_IP_Timers.goto" ] } \ No newline at end of file diff --git a/test/cbmc/proofs/DHCPv6/DHCPv6ProcessEndPoint/DHCPv6ProcessEndPoint_harness.c b/test/cbmc/proofs/DHCPv6/DHCPv6ProcessEndPoint/DHCPv6ProcessEndPoint_harness.c index 9157a86f2e..350c13cce2 100644 --- a/test/cbmc/proofs/DHCPv6/DHCPv6ProcessEndPoint/DHCPv6ProcessEndPoint_harness.c +++ b/test/cbmc/proofs/DHCPv6/DHCPv6ProcessEndPoint/DHCPv6ProcessEndPoint_harness.c @@ -77,6 +77,18 @@ Socket_t FreeRTOS_socket( BaseType_t xDomain, return pxSocket; } +void vIPNetworkUpCalls( struct xNetworkEndPoint * pxEndPoint ) +{ + __CPROVER_assert( pxEndPoint != NULL, "Endpoint cannot be NULL" ); +} + +void * vSocketClose( FreeRTOS_Socket_t * pxSocket ) +{ + __CPROVER_assert( pxSocket != NULL, "Closing socket cannot be NULL." ); + + return NULL; +} + /** * For the purpose of this proof we assume that xSocketValid returns true always. * This has to do with assertions in the source code that checks for socket being invalid. diff --git a/test/cbmc/proofs/DHCPv6/DHCPv6ProcessEndPoint/Makefile.json b/test/cbmc/proofs/DHCPv6/DHCPv6ProcessEndPoint/Makefile.json index d2d5931bcd..21e1105ac8 100644 --- a/test/cbmc/proofs/DHCPv6/DHCPv6ProcessEndPoint/Makefile.json +++ b/test/cbmc/proofs/DHCPv6/DHCPv6ProcessEndPoint/Makefile.json @@ -5,14 +5,6 @@ "--nondet-static --flush", "--unwind 1" ], - "INSTFLAGS": - [ - "--remove-function-body vIPSetDHCP_RATimerEnableState", - "--remove-function-body vDHCP_RATimerReload", - "--remove-function-body vIPNetworkUpCalls", - "--remove-function-body prvCloseDHCPv6Socket", - "--remove-function-body prvSendDHCPMessage" - ], "OPT": [ "--export-file-local-symbols" @@ -25,6 +17,8 @@ [ "$(ENTRY)_harness.goto", "$(FREERTOS_PLUS_TCP)/test/cbmc/stubs/cbmc.goto", + "$(FREERTOS_PLUS_TCP)/test/cbmc/stubs/freertos_api.goto", + "$(FREERTOS_PLUS_TCP)/test/cbmc/stubs/freertos_kernel_api.goto", "$(FREERTOS_PLUS_TCP)/source/FreeRTOS_DHCPv6.goto", "$(FREERTOS_PLUS_TCP)/source/FreeRTOS_IP.goto", "$(FREERTOS_PLUS_TCP)/source/FreeRTOS_IP_Timers.goto" diff --git a/test/cbmc/proofs/DHCPv6/SendDHCPMessage/Makefile.json b/test/cbmc/proofs/DHCPv6/SendDHCPMessage/Makefile.json index 08cb3e73a1..98bc9f7248 100644 --- a/test/cbmc/proofs/DHCPv6/SendDHCPMessage/Makefile.json +++ b/test/cbmc/proofs/DHCPv6/SendDHCPMessage/Makefile.json @@ -4,20 +4,6 @@ [ "--nondet-static" ], - "INSTFLAGS": - [ - "--remove-function-body xApplicationGetRandomNumber", - "--remove-function-body ulApplicationTimeHook", - "--remove-function-body xBitConfig_init", - "--remove-function-body vBitConfig_write_8", - "--remove-function-body vBitConfig_write_uc", - "--remove-function-body vBitConfig_write_16", - "--remove-function-body vBitConfig_write_32", - "--remove-function-body pucBitConfig_peek_last_index_uc", - "--remove-function-body FreeRTOS_inet_pton6", - "--remove-function-body FreeRTOS_sendto", - "--remove-function-body vBitConfig_release" - ], "OPT": [ "--export-file-local-symbols" @@ -29,9 +15,9 @@ "OBJS": [ "$(ENTRY)_harness.goto", + "$(FREERTOS_PLUS_TCP)/source/FreeRTOS_DHCPv6.goto", "$(FREERTOS_PLUS_TCP)/test/cbmc/stubs/cbmc.goto", - "$(FREERTOS_PLUS_TCP)/source/FreeRTOS_Sockets.goto", - "$(FREERTOS_PLUS_TCP)/source/FreeRTOS_BitConfig.goto", - "$(FREERTOS_PLUS_TCP)/source/FreeRTOS_DHCPv6.goto" + "$(FREERTOS_PLUS_TCP)/test/cbmc/stubs/freertos_api.goto", + "$(FREERTOS_PLUS_TCP)/test/cbmc/stubs/freertos_kernel_api.goto" ] } \ No newline at end of file diff --git a/test/cbmc/proofs/DHCPv6/SendDHCPMessage/SendDHCPMessage_harness.c b/test/cbmc/proofs/DHCPv6/SendDHCPMessage/SendDHCPMessage_harness.c index fc28867207..436b96cf5d 100644 --- a/test/cbmc/proofs/DHCPv6/SendDHCPMessage/SendDHCPMessage_harness.c +++ b/test/cbmc/proofs/DHCPv6/SendDHCPMessage/SendDHCPMessage_harness.c @@ -42,14 +42,103 @@ #include "FreeRTOS_DHCP.h" #include "FreeRTOS_DHCPv6.h" #include "FreeRTOS_ARP.h" +#include "FreeRTOS_BitConfig.h" /* CBMC includes. */ #include "cbmc.h" +void __CPROVER_file_local_FreeRTOS_DHCPv6_c_prvSendDHCPMessage( NetworkEndPoint_t * pxEndPoint ); +BaseType_t xBitConfig_init( BitConfig_t * pxConfig, + const uint8_t * pucData, + size_t uxSize ) +{ + BaseType_t xReturn; -void __CPROVER_file_local_FreeRTOS_DHCPv6_c_prvSendDHCPMessage( NetworkEndPoint_t * pxEndPoint ); + __CPROVER_assert( pxConfig != NULL, "pxConfig cannot be NULL" ); + + if( nondet_bool() ) + { + xReturn = pdTRUE; + + pxConfig->ucContents = safeMalloc( uxSize ); + __CPROVER_assume( pxConfig->ucContents != NULL ); + } + else + { + xReturn = pdFALSE; + } + + return xReturn; +} + +BaseType_t pucBitConfig_peek_last_index_uc( BitConfig_t * pxConfig, + uint8_t * pucData, + size_t uxSize ) +{ + BaseType_t xReturn; + + __CPROVER_assert( pxConfig != NULL, "pxConfig cannot be NULL" ); + __CPROVER_assert( pucData != NULL, "pucData cannot be NULL" ); + + __CPROVER_assume( xReturn == pdTRUE || xReturn == pdFALSE ); + + return xReturn; +} + +void vBitConfig_write_uc( BitConfig_t * pxConfig, + const uint8_t * pucData, + size_t uxSize ) +{ + __CPROVER_assert( pxConfig != NULL, "pxConfig cannot be NULL" ); + __CPROVER_assert( pucData != NULL, "pucData cannot be NULL" ); +} + +void vBitConfig_write_8( BitConfig_t * pxConfig, + uint8_t ucValue ) +{ + __CPROVER_assert( pxConfig != NULL, "pxConfig cannot be NULL" ); +} +void vBitConfig_write_16( BitConfig_t * pxConfig, + uint16_t usValue ) +{ + __CPROVER_assert( pxConfig != NULL, "pxConfig cannot be NULL" ); +} + +void vBitConfig_write_32( BitConfig_t * pxConfig, + uint32_t ulValue ) +{ + __CPROVER_assert( pxConfig != NULL, "pxConfig cannot be NULL" ); +} + +void vBitConfig_release( BitConfig_t * pxConfig ) +{ + __CPROVER_assert( pxConfig != NULL, "pxConfig cannot be NULL" ); + + if( pxConfig->ucContents != NULL ) + { + free( pxConfig->ucContents ); + } +} + +BaseType_t FreeRTOS_inet_pton6( const char * pcSource, + void * pvDestination ) +{ + BaseType_t xReturn; + + __CPROVER_assert( pcSource != NULL, "pcSource cannot be NULL" ); + __CPROVER_assert( pvDestination != NULL, "pvDestination cannot be NULL" ); + + __CPROVER_assume( xReturn == pdTRUE || xReturn == pdFALSE ); + + return xReturn; +} + +uint32_t ulApplicationTimeHook( void ) +{ + return nondet_uint32(); +} void harness() { diff --git a/test/cbmc/proofs/DNS/CreateDNSMessage/Makefile.json b/test/cbmc/proofs/DNS/CreateDNSMessage/Makefile.json index 5bb6f67d9d..8961c19ff1 100644 --- a/test/cbmc/proofs/DNS/CreateDNSMessage/Makefile.json +++ b/test/cbmc/proofs/DNS/CreateDNSMessage/Makefile.json @@ -7,7 +7,7 @@ [ "--unwind 1", "--unwindset strlen.0:{HOSTNAME_UNWIND}", - "--unwindset strcpy.0:{HOSTNAME_UNWIND}", + "--unwindset strncpy.0:{HOSTNAME_UNWIND}", "--unwindset __CPROVER_file_local_FreeRTOS_DNS_c_prvCreateDNSMessage.0:{HOSTNAME_UNWIND}", "--unwindset __CPROVER_file_local_FreeRTOS_DNS_c_prvCreateDNSMessage.1:{HOSTNAME_UNWIND}", "--nondet-static" diff --git a/test/cbmc/proofs/DNS/DNSHandlePacket/DNShandlePacket_harness.c b/test/cbmc/proofs/DNS/DNSHandlePacket/DNShandlePacket_harness.c index 983f1f1092..52106ba65f 100644 --- a/test/cbmc/proofs/DNS/DNSHandlePacket/DNShandlePacket_harness.c +++ b/test/cbmc/proofs/DNS/DNSHandlePacket/DNShandlePacket_harness.c @@ -7,11 +7,18 @@ #include "FreeRTOS_DNS.h" #include "FreeRTOS_IP_Private.h" -/* Function prvParseDNSReply is proven to be correct separately. */ -uint32_t prvParseDNSReply( uint8_t * pucUDPPayloadBuffer, - size_t xBufferLength, - BaseType_t xExpected ) +/* CBMC includes. */ +#include "cbmc.h" + +/* Function DNS_ParseDNSReply is proven to be correct separately. */ +uint32_t DNS_ParseDNSReply( uint8_t * pucUDPPayloadBuffer, + size_t uxBufferLength, + struct freertos_addrinfo ** ppxAddressInfo, + BaseType_t xExpected, + uint16_t usPort ) { + __CPROVER_assert( pucUDPPayloadBuffer != NULL, "pucUDPPayloadBuffer cannot be NULL" ); + return nondet_uint32(); } void harness() diff --git a/test/cbmc/proofs/DNS/DNSHandlePacket/Makefile.json b/test/cbmc/proofs/DNS/DNSHandlePacket/Makefile.json index 27864b1461..511a166ca5 100644 --- a/test/cbmc/proofs/DNS/DNSHandlePacket/Makefile.json +++ b/test/cbmc/proofs/DNS/DNSHandlePacket/Makefile.json @@ -4,7 +4,8 @@ "OBJS": [ "$(ENTRY)_harness.goto", - "$(FREERTOS_PLUS_TCP)/source/FreeRTOS_DNS.goto" + "$(FREERTOS_PLUS_TCP)/source/FreeRTOS_DNS.goto", + "$(FREERTOS_PLUS_TCP)/source/FreeRTOS_IP.goto" ], "DEF": [ diff --git a/test/cbmc/proofs/DNS/DNSTreatNBNS/DNS_TreatNBNS_harness.c b/test/cbmc/proofs/DNS/DNSTreatNBNS/DNS_TreatNBNS_harness.c index d6be53942f..7d1d706698 100644 --- a/test/cbmc/proofs/DNS/DNSTreatNBNS/DNS_TreatNBNS_harness.c +++ b/test/cbmc/proofs/DNS/DNSTreatNBNS/DNS_TreatNBNS_harness.c @@ -38,6 +38,7 @@ #include "cbmc.h" +const BaseType_t xBufferAllocFixedSize = pdFALSE; NetworkBufferDescriptor_t xNetworkBuffer; NetworkBufferDescriptor_t * pxUDPPayloadBuffer_to_NetworkBuffer( const void * pvBuffer ) @@ -67,6 +68,11 @@ NetworkBufferDescriptor_t * pxResizeNetworkBufferWithDescriptor( NetworkBufferDe uint8_t * pucNewBuffer = safeMalloc( xNewSizeBytes ); __CPROVER_assume( pucNewBuffer != NULL ); + if( pxNetworkBuffer->pucEthernetBuffer ) + { + free( pxNetworkBuffer->pucEthernetBuffer ); + } + pxNetworkBuffer->pucEthernetBuffer = pucNewBuffer; if( nondet_bool() ) @@ -88,6 +94,26 @@ void prepareReplyDNSMessage( NetworkBufferDescriptor_t * pxNetworkBuffer, __CPROVER_assert( pxNetworkBuffer != NULL, "pxNetworkBuffer: pvBuffer != NULL" ); } +BaseType_t xApplicationDNSQueryHook_Multi( struct xNetworkEndPoint * pxEndPoint, + const char * pcName ) +{ + BaseType_t xReturn; + + __CPROVER_assert( strlen( pcName ) < ipconfigDNS_CACHE_NAME_LENGTH, "The length of domain name must be less than cache size" ); + __CPROVER_assume( xReturn == pdFALSE || xReturn == pdTRUE ); + + return xReturn; +} + +/* vReturnEthernetFrame() is proved separately */ +void vReturnEthernetFrame( NetworkBufferDescriptor_t * pxNetworkBuffer, + BaseType_t xReleaseAfterSend ) +{ + __CPROVER_assert( pxNetworkBuffer != NULL, "xNetworkBuffer != NULL" ); + __CPROVER_assert( pxNetworkBuffer->pucEthernetBuffer != NULL, "pxNetworkBuffer->pucEthernetBuffer != NULL" ); + __CPROVER_assert( __CPROVER_r_ok( pxNetworkBuffer->pucEthernetBuffer, pxNetworkBuffer->xDataLength ), "Data must be valid" ); +} + void harness() { uint32_t ulIPAddress; @@ -103,6 +129,7 @@ void harness() xNetworkBuffer.pucEthernetBuffer = safeMalloc( xDataSize ); xNetworkBuffer.xDataLength = xDataSize; + __CPROVER_assume( xNetworkBuffer.pucEthernetBuffer != NULL ); if( nondet_bool() ) { diff --git a/test/cbmc/proofs/DNS/DNSTreatNBNS/Makefile.json b/test/cbmc/proofs/DNS/DNSTreatNBNS/Makefile.json index 458443eb78..d3ab0d582a 100644 --- a/test/cbmc/proofs/DNS/DNSTreatNBNS/Makefile.json +++ b/test/cbmc/proofs/DNS/DNSTreatNBNS/Makefile.json @@ -1,18 +1,24 @@ { "ENTRY": "DNS_TreatNBNS", "USE_CACHE":1, + "NBNS_NAME_MAX_LENGTH":17, "CBMCFLAGS": [ "--unwind 1", - "--unwindset DNS_TreatNBNS.0:16", - "--nondet-static" + "--unwindset DNS_TreatNBNS.0:{NBNS_NAME_MAX_LENGTH}", + "--unwindset prvFindEntryIndex.0:2", + "--unwindset strcmp.0:{NBNS_NAME_MAX_LENGTH}", + "--unwindset strlen.0:{NBNS_NAME_MAX_LENGTH}", + "--unwindset strncpy.0:{NBNS_NAME_MAX_LENGTH}" ], "OBJS": [ "$(ENTRY)_harness.goto", - "$(FREERTOS_PLUS_TCP)/test/cbmc/stubs/cbmc.goto", "$(FREERTOS_PLUS_TCP)/source/FreeRTOS_IP_Utils.goto", - "$(FREERTOS_PLUS_TCP)/source/FreeRTOS_DNS_Parser.goto" + "$(FREERTOS_PLUS_TCP)/source/FreeRTOS_DNS_Parser.goto", + "$(FREERTOS_PLUS_TCP)/source/FreeRTOS_DNS_Cache.goto", + "$(FREERTOS_PLUS_TCP)/test/cbmc/stubs/cbmc.goto", + "$(FREERTOS_PLUS_TCP)/test/cbmc/stubs/freertos_kernel_api.goto" ], "DEF": [ diff --git a/test/cbmc/proofs/DNS/DNSgetHostByName/DNSgetHostByName_harness.c b/test/cbmc/proofs/DNS/DNSgetHostByName/DNSgetHostByName_harness.c index e849b4ee1b..9e5658074a 100644 --- a/test/cbmc/proofs/DNS/DNSgetHostByName/DNSgetHostByName_harness.c +++ b/test/cbmc/proofs/DNS/DNSgetHostByName/DNSgetHostByName_harness.c @@ -17,6 +17,7 @@ #include "NetworkBufferManagement.h" #include "NetworkInterface.h" +/* CBMC includes. */ #include "cbmc.h" uint32_t FreeRTOS_dnslookup( const char * pcHostName ); @@ -37,6 +38,7 @@ size_t __CPROVER_file_local_FreeRTOS_DNS_c_prvCreateDNSMessage( uint8_t * pucUDP const char * pcHostName, TickType_t uxIdentifier, UBaseType_t uxHostType ); +uintptr_t __CPROVER_file_local_FreeRTOS_IP_Utils_c_void_ptr_to_uintptr( const void * pvPointer ); /**************************************************************** * We abstract: @@ -56,6 +58,54 @@ size_t __CPROVER_file_local_FreeRTOS_DNS_c_prvCreateDNSMessage( uint8_t * pucUDP * bound the iterations of strcmp. ****************************************************************/ +/*We assume that the pxGetNetworkBufferWithDescriptor function is implemented correctly and returns a valid data structure. */ +/*This is the mock to mimic the correct expected behavior. If this allocation fails, this might invalidate the proof. */ +NetworkBufferDescriptor_t * pxGetNetworkBufferWithDescriptor( size_t xRequestedSizeBytes, + TickType_t xBlockTimeTicks ) +{ + NetworkBufferDescriptor_t * pxNetworkBuffer = ( NetworkBufferDescriptor_t * ) safeMalloc( sizeof( NetworkBufferDescriptor_t ) ); + + if( pxNetworkBuffer != NULL ) + { + pxNetworkBuffer->pucEthernetBuffer = safeMalloc( xRequestedSizeBytes + ipUDP_PAYLOAD_IP_TYPE_OFFSET ); + + if( pxNetworkBuffer->pucEthernetBuffer == NULL ) + { + free( pxNetworkBuffer ); + pxNetworkBuffer = NULL; + } + else + { + pxNetworkBuffer->pucEthernetBuffer = ( ( uint8_t * ) pxNetworkBuffer->pucEthernetBuffer ) + ipUDP_PAYLOAD_IP_TYPE_OFFSET; + pxNetworkBuffer->xDataLength = xRequestedSizeBytes; + } + } + + return pxNetworkBuffer; +} + +/* + * In this function, it only allocates network buffer by pxGetNetworkBufferWithDescriptor + * stub function above here. In this case, we should free both network buffer descriptor and pucEthernetBuffer. + */ +void vReleaseNetworkBufferAndDescriptor( NetworkBufferDescriptor_t * const pxNetworkBuffer ) +{ + __CPROVER_assert( pxNetworkBuffer != NULL, + "Precondition: pxNetworkBuffer != NULL" ); + + free( pxNetworkBuffer->pucEthernetBuffer - ipUDP_PAYLOAD_IP_TYPE_OFFSET ); + free( pxNetworkBuffer ); +} + +/* FreeRTOS_ReleaseUDPPayloadBuffer is mocked here and the memory + * is not freed as the buffer allocated by the FreeRTOS_recvfrom is static + * memory */ +void FreeRTOS_ReleaseUDPPayloadBuffer( void * pvBuffer ) +{ + __CPROVER_assert( pvBuffer != NULL, + "FreeRTOS precondition: pvBuffer != NULL" ); +} + /**************************************************************** * Abstract DNS_ParseDNSReply proved memory safe in ParseDNSReply. * @@ -96,6 +146,22 @@ uint32_t DNS_SendRequest( Socket_t xDNSSocket, return ret; } +/**************************************************************** +* Abstract DNS_BindSocket +* +* We stub out this function with return constraint of true or false +* +****************************************************************/ +BaseType_t DNS_BindSocket( Socket_t xSocket, + uint16_t usPort ) +{ + BaseType_t xReturn; + + __CPROVER_assume( xReturn == pdTRUE || xReturn == pdFALSE ); + + return xReturn; +} + /**************************************************************** * Abstract DNS_ReadReply * @@ -106,20 +172,39 @@ BaseType_t DNS_ReadReply( ConstSocket_t xDNSSocket, struct freertos_sockaddr * xAddress, struct xDNSBuffer * pxDNSBuf ) { - BaseType_t ret; int len; + uintptr_t uxTypeOffset; + const uint8_t * pucIPType; + uint8_t ucIPType; + NetworkBufferDescriptor_t * pxNetworkEndPoints; - __CPROVER_assume( ( len > sizeof( DNSMessage_t ) ) && ( len < CBMC_MAX_OBJECT_SIZE ) ); + __CPROVER_assume( ( len > sizeof( DNSMessage_t ) ) && ( len < ipconfigNETWORK_MTU ) ); - pxDNSBuf->pucPayloadBuffer = malloc( len ); + pxNetworkEndPoints = pxGetNetworkBufferWithDescriptor( len, 0 ); + __CPROVER_assume( pxNetworkEndPoints != NULL ); + __CPROVER_assume( pxNetworkEndPoints->pucEthernetBuffer != NULL ); + pxDNSBuf->pucPayloadBuffer = pxNetworkEndPoints->pucEthernetBuffer; pxDNSBuf->uxPayloadLength = len; - __CPROVER_assume( pxDNSBuf->pucPayloadBuffer != NULL ); - __CPROVER_havoc_slice( pxDNSBuf->pucPayloadBuffer, pxDNSBuf->uxPayloadLength ); - return ret; + /* When IPv6 is supported, find out the type of the packet. + * It is stored 48 bytes before the payload buffer as 0x40 or 0x60. */ + uxTypeOffset = __CPROVER_file_local_FreeRTOS_IP_Utils_c_void_ptr_to_uintptr( pxDNSBuf->pucPayloadBuffer ); + uxTypeOffset -= ipUDP_PAYLOAD_IP_TYPE_OFFSET; + pucIPType = ( const uint8_t * ) uxTypeOffset; + + /* For an IPv4 packet, pucIPType points to 6 bytes before the pucEthernetBuffer, + * for a IPv6 packet, pucIPType will point to the first byte of the IP-header: 'ucVersionTrafficClass'. */ + ucIPType = pucIPType[ 0 ] & 0xf0U; + + /* To help the translation from a UDP payload pointer to a networkBuffer, + * a byte was stored at a certain negative offset (-48 bytes). + * It must have a value of either 0x4x or 0x6x. */ + __CPROVER_assume( ( ucIPType == ipTYPE_IPv4 ) || ( ucIPType == ipTYPE_IPv6 ) ); + + return nondet_basetype(); } @@ -177,30 +262,11 @@ size_t __CPROVER_file_local_FreeRTOS_DNS_c_prvCreateDNSMessage( uint8_t * pucUDP return size; } -/*We assume that the pxGetNetworkBufferWithDescriptor function is implemented correctly and returns a valid data structure. */ -/*This is the mock to mimic the correct expected behavior. If this allocation fails, this might invalidate the proof. */ -NetworkBufferDescriptor_t * pxGetNetworkBufferWithDescriptor( size_t xRequestedSizeBytes, - TickType_t xBlockTimeTicks ) +uint32_t Prepare_CacheLookup( const char * pcHostName, + BaseType_t xFamily, + struct freertos_addrinfo ** ppxAddressInfo ) { - NetworkBufferDescriptor_t * pxNetworkBuffer = ( NetworkBufferDescriptor_t * ) malloc( sizeof( NetworkBufferDescriptor_t ) ); - - if( pxNetworkBuffer != NULL ) - { - pxNetworkBuffer->pucEthernetBuffer = malloc( xRequestedSizeBytes + ipUDP_PAYLOAD_IP_TYPE_OFFSET ); - - if( pxNetworkBuffer->pucEthernetBuffer == NULL ) - { - free( pxNetworkBuffer ); - pxNetworkBuffer = NULL; - } - else - { - pxNetworkBuffer->pucEthernetBuffer = ( ( uint8_t * ) pxNetworkBuffer->pucEthernetBuffer ) + ipUDP_PAYLOAD_IP_TYPE_OFFSET; - pxNetworkBuffer->xDataLength = xRequestedSizeBytes; - } - } - - return pxNetworkBuffer; + return nondet_uint32(); } /**************************************************************** diff --git a/test/cbmc/proofs/DNS/DNSgetHostByName/Makefile.json b/test/cbmc/proofs/DNS/DNSgetHostByName/Makefile.json index 66b7cad54e..46a0c62cf2 100644 --- a/test/cbmc/proofs/DNS/DNSgetHostByName/Makefile.json +++ b/test/cbmc/proofs/DNS/DNSgetHostByName/Makefile.json @@ -11,6 +11,7 @@ "ENDPOINT_DNS_ADDRESS_COUNT": 5, "HOSTNAME_UNWIND": "__eval {MAX_HOSTNAME_LEN} + 1", "ENDPOINT_DNS_ADDRESS_COUNT_UNWIND": "__eval {ENDPOINT_DNS_ADDRESS_COUNT} + 1", + "DNS_CACHE_ENTRIES": 2, "CBMCFLAGS": [ @@ -30,11 +31,13 @@ "OBJS": [ "$(ENTRY)_harness.goto", - "$(FREERTOS_PLUS_TCP)/test/cbmc/stubs/cbmc.goto", - "$(FREERTOS_PLUS_TCP)/source/FreeRTOS_Routing.goto", + "$(FREERTOS_PLUS_TCP)/source/FreeRTOS_IP_Utils.goto", "$(FREERTOS_PLUS_TCP)/source/FreeRTOS_DNS.goto", "$(FREERTOS_PLUS_TCP)/source/FreeRTOS_Routing.goto", - "$(FREERTOS_PLUS_TCP)/source/FreeRTOS_DNS_Parser.goto" + "$(FREERTOS_PLUS_TCP)/source/FreeRTOS_DNS_Parser.goto", + "$(FREERTOS_PLUS_TCP)/test/cbmc/stubs/freertos_api.goto", + "$(FREERTOS_PLUS_TCP)/test/cbmc/stubs/freertos_kernel_api.goto", + "$(FREERTOS_PLUS_TCP)/test/cbmc/stubs/cbmc.goto" ], "DEF": @@ -42,6 +45,7 @@ "ipconfigUSE_IPv6=1", "ipconfigDNS_USE_CALLBACKS={callback}", "MAX_HOSTNAME_LEN={MAX_HOSTNAME_LEN}", - "ipconfigENDPOINT_DNS_ADDRESS_COUNT={ENDPOINT_DNS_ADDRESS_COUNT}" + "ipconfigENDPOINT_DNS_ADDRESS_COUNT={ENDPOINT_DNS_ADDRESS_COUNT}", + "ipconfigDNS_CACHE_ENTRIES={DNS_CACHE_ENTRIES}" ] } diff --git a/test/cbmc/proofs/DNS/DNSgetHostByName_a/DNSgetHostByName_a_harness.c b/test/cbmc/proofs/DNS/DNSgetHostByName_a/DNSgetHostByName_a_harness.c index 7b7c4a3fb9..03d1ecb736 100644 --- a/test/cbmc/proofs/DNS/DNSgetHostByName_a/DNSgetHostByName_a_harness.c +++ b/test/cbmc/proofs/DNS/DNSgetHostByName_a/DNSgetHostByName_a_harness.c @@ -17,8 +17,11 @@ #include "NetworkBufferManagement.h" #include "NetworkInterface.h" +/* CBMC includes. */ #include "cbmc.h" +uintptr_t __CPROVER_file_local_FreeRTOS_IP_Utils_c_void_ptr_to_uintptr( const void * pvPointer ); + /**************************************************************** * We abstract: * @@ -37,6 +40,54 @@ * bound the iterations of strcmp. ****************************************************************/ +/*We assume that the pxGetNetworkBufferWithDescriptor function is implemented correctly and returns a valid data structure. */ +/*This is the mock to mimic the correct expected behavior. If this allocation fails, this might invalidate the proof. */ +NetworkBufferDescriptor_t * pxGetNetworkBufferWithDescriptor( size_t xRequestedSizeBytes, + TickType_t xBlockTimeTicks ) +{ + NetworkBufferDescriptor_t * pxNetworkBuffer = ( NetworkBufferDescriptor_t * ) safeMalloc( sizeof( NetworkBufferDescriptor_t ) ); + + if( pxNetworkBuffer != NULL ) + { + pxNetworkBuffer->pucEthernetBuffer = safeMalloc( xRequestedSizeBytes + ipBUFFER_PADDING + ipUDP_PAYLOAD_IP_TYPE_OFFSET ); + + if( pxNetworkBuffer->pucEthernetBuffer == NULL ) + { + free( pxNetworkBuffer ); + pxNetworkBuffer = NULL; + } + else + { + pxNetworkBuffer->pucEthernetBuffer = ( ( uint8_t * ) pxNetworkBuffer->pucEthernetBuffer ) + ipBUFFER_PADDING + ipUDP_PAYLOAD_IP_TYPE_OFFSET; + pxNetworkBuffer->xDataLength = xRequestedSizeBytes; + } + } + + return pxNetworkBuffer; +} + +/* + * In this function, it only allocates network buffer by pxGetNetworkBufferWithDescriptor + * stub function above here. In this case, we should free both network buffer descriptor and pucEthernetBuffer. + */ +void vReleaseNetworkBufferAndDescriptor( NetworkBufferDescriptor_t * const pxNetworkBuffer ) +{ + __CPROVER_assert( pxNetworkBuffer != NULL, + "Precondition: pxNetworkBuffer != NULL" ); + + free( pxNetworkBuffer->pucEthernetBuffer - ( ipUDP_PAYLOAD_IP_TYPE_OFFSET + ipBUFFER_PADDING ) ); + free( pxNetworkBuffer ); +} + +/* FreeRTOS_ReleaseUDPPayloadBuffer is mocked here and the memory + * is not freed as the buffer allocated by the FreeRTOS_recvfrom is static + * memory */ +void FreeRTOS_ReleaseUDPPayloadBuffer( void * pvBuffer ) +{ + __CPROVER_assert( pvBuffer != NULL, + "FreeRTOS precondition: pvBuffer != NULL" ); +} + /**************************************************************** * Abstract DNS_ParseDNSReply proved memory safe in ParseDNSReply. * @@ -111,37 +162,93 @@ BaseType_t NetworkInterfaceOutputFunction_Stub( struct xNetworkInterface * pxDes return ret; } -/*We assume that the pxGetNetworkBufferWithDescriptor function is implemented correctly and returns a valid data structure. */ -/*This is the mock to mimic the correct expected behavior. If this allocation fails, this might invalidate the proof. */ -NetworkBufferDescriptor_t * pxGetNetworkBufferWithDescriptor( size_t xRequestedSizeBytes, - TickType_t xBlockTimeTicks ) +Socket_t DNS_CreateSocket( TickType_t uxReadTimeout_ticks ) { - NetworkBufferDescriptor_t * pxNetworkBuffer = ( NetworkBufferDescriptor_t * ) malloc( sizeof( NetworkBufferDescriptor_t ) ); + Socket_t xSock = safeMalloc( sizeof( struct xSOCKET ) ); - if( pxNetworkBuffer != NULL ) - { - pxNetworkBuffer->pucEthernetBuffer = malloc( xRequestedSizeBytes + ipUDP_PAYLOAD_IP_TYPE_OFFSET ); + return xSock; +} - if( pxNetworkBuffer->pucEthernetBuffer == NULL ) - { - free( pxNetworkBuffer ); - pxNetworkBuffer = NULL; - } - else - { - pxNetworkBuffer->pucEthernetBuffer = ( ( uint8_t * ) pxNetworkBuffer->pucEthernetBuffer ) + ipUDP_PAYLOAD_IP_TYPE_OFFSET; - pxNetworkBuffer->xDataLength = xRequestedSizeBytes; - } - } +void DNS_CloseSocket( Socket_t xDNSSocket ) +{ + __CPROVER_assert( xDNSSocket != NULL, "The xDNSSocket cannot be NULL." ); + free( xDNSSocket ); +} - return pxNetworkBuffer; +/**************************************************************** +* Abstract DNS_BindSocket +* +* We stub out this function with return constraint of true or false +* +****************************************************************/ +BaseType_t DNS_BindSocket( Socket_t xSocket, + uint16_t usPort ) +{ + BaseType_t xReturn; + + __CPROVER_assume( xReturn == pdTRUE || xReturn == pdFALSE ); + + return xReturn; } -Socket_t DNS_CreateSocket( TickType_t uxReadTimeout_ticks ) +/**************************************************************** +* Abstract DNS_SendRequest +* +* We stub out this function with return constraint of true or false +* +****************************************************************/ +uint32_t DNS_SendRequest( Socket_t xDNSSocket, + struct freertos_sockaddr * xAddress, + struct xDNSBuffer * pxDNSBuf ) { - Socket_t xSock = safeMalloc( sizeof( struct xSOCKET ) ); + uint32_t ret; - return xSock; + __CPROVER_assume( ret >= 0 ); + __CPROVER_assume( ret <= 1 ); + + return ret; +} + +/**************************************************************** +* Abstract DNS_ReadReply +* +* We stub out this function which returned a dns_buffer filled with random data +* +****************************************************************/ +BaseType_t DNS_ReadReply( ConstSocket_t xDNSSocket, + struct freertos_sockaddr * xAddress, + struct xDNSBuffer * pxDNSBuf ) +{ + int len; + NetworkBufferDescriptor_t * pxNetworkBuffer; + + __CPROVER_assume( ( len > sizeof( DNSMessage_t ) ) && ( len < ipconfigNETWORK_MTU ) ); + + pxNetworkBuffer = pxGetNetworkBufferWithDescriptor( len, 0 ); + __CPROVER_assume( pxNetworkBuffer != NULL ); + __CPROVER_assume( pxNetworkBuffer->pucEthernetBuffer != NULL ); + + pxDNSBuf->pucPayloadBuffer = pxNetworkBuffer->pucEthernetBuffer; + pxDNSBuf->uxPayloadLength = len; + + __CPROVER_havoc_slice( pxDNSBuf->pucPayloadBuffer, pxDNSBuf->uxPayloadLength ); + + return nondet_basetype(); +} + +/* Function xDNSSetCallBack is proven to be correct separately. */ +BaseType_t xDNSSetCallBack( const char * pcHostName, + void * pvSearchID, + FOnDNSEvent pCallbackFunction, + TickType_t xTimeout, + TickType_t xIdentifier, + BaseType_t xIsIPv6 ) +{ + BaseType_t xReturn; + + __CPROVER_assume( xReturn == pdTRUE || xReturn == pdFALSE ); + + return xReturn; } uint32_t Prepare_CacheLookup( const char * pcHostName, diff --git a/test/cbmc/proofs/DNS/DNSgetHostByName_a/Makefile.json b/test/cbmc/proofs/DNS/DNSgetHostByName_a/Makefile.json index f67cb0a113..e4114a1a63 100644 --- a/test/cbmc/proofs/DNS/DNSgetHostByName_a/Makefile.json +++ b/test/cbmc/proofs/DNS/DNSgetHostByName_a/Makefile.json @@ -24,11 +24,12 @@ "OBJS": [ "$(ENTRY)_harness.goto", - "$(FREERTOS_PLUS_TCP)/test/cbmc/stubs/cbmc.goto", "$(FREERTOS_PLUS_TCP)/source/FreeRTOS_Routing.goto", "$(FREERTOS_PLUS_TCP)/source/FreeRTOS_DNS.goto", "$(FREERTOS_PLUS_TCP)/source/FreeRTOS_DNS_Parser.goto", - "$(FREERTOS_PLUS_TCP)/source/FreeRTOS_IP.goto" + "$(FREERTOS_PLUS_TCP)/source/FreeRTOS_IP_Utils.goto", + "$(FREERTOS_PLUS_TCP)/test/cbmc/stubs/cbmc.goto", + "$(FREERTOS_PLUS_TCP)/test/cbmc/stubs/freertos_api.goto" ], "DEF": [ diff --git a/test/cbmc/proofs/DNS/DNSgetHostByName_cancel/DNSgetHostByName_cancel_harness.c b/test/cbmc/proofs/DNS/DNSgetHostByName_cancel/DNSgetHostByName_cancel_harness.c index 8536a2612e..e4ec2ecff5 100644 --- a/test/cbmc/proofs/DNS/DNSgetHostByName_cancel/DNSgetHostByName_cancel_harness.c +++ b/test/cbmc/proofs/DNS/DNSgetHostByName_cancel/DNSgetHostByName_cancel_harness.c @@ -8,39 +8,52 @@ #include "FreeRTOS_DNS.h" #include "FreeRTOS_IP_Private.h" +/* CBMC includes. */ +#include "cbmc.h" /* This proof assumes the length of pcHostName is bounded by MAX_HOSTNAME_LEN. This also abstracts the concurrency. */ void vDNSInitialise( void ); -void vDNSSetCallBack( const char * pcHostName, - void * pvSearchID, - FOnDNSEvent pCallbackFunction, - TickType_t xTimeout, - TickType_t xIdentifier, - BaseType_t xIsIPv6 ); +BaseType_t xDNSSetCallBack( const char * pcHostName, + void * pvSearchID, + FOnDNSEvent pCallbackFunction, + TickType_t xTimeout, + TickType_t xIdentifier, + BaseType_t xIsIPv6 ); -void * safeMalloc( size_t xWantedSize ) /* Returns a NULL pointer if the wanted size is 0. */ +/* Abstraction of uxListRemove from list. This also abstracts the concurrency. */ +void vListInitialise( List_t * const pxList ) { - if( xWantedSize == 0 ) - { - return NULL; - } + __CPROVER_assert( pxList != NULL, "pxList cannot be NULL" ); - uint8_t byte; + pxList->pxIndex = ( ListItem_t * ) &( pxList->xListEnd ); + pxList->xListEnd.xItemValue = portMAX_DELAY; - return byte ? malloc( xWantedSize ) : NULL; + /* The list end next and previous pointers point to itself so we know + * when the list is empty. */ + pxList->xListEnd.pxNext = ( ListItem_t * ) &( pxList->xListEnd ); + pxList->xListEnd.pxPrevious = ( ListItem_t * ) &( pxList->xListEnd ); + pxList->uxNumberOfItems = ( UBaseType_t ) 0U; } -/* Abstraction of xTaskCheckForTimeOut from task pool. This also abstracts the concurrency. */ -BaseType_t xTaskCheckForTimeOut( TimeOut_t * const pxTimeOut, - TickType_t * const pxTicksToWait ) +/* Abstraction of uxListRemove from list. This also abstracts the concurrency. */ +UBaseType_t uxListRemove( ListItem_t * const pxItemToRemove ) { -} + List_t * const pxList = pxItemToRemove->pxContainer; -/* Abstraction of xTaskResumeAll from task pool. This also abstracts the concurrency. */ -BaseType_t xTaskResumeAll( void ) -{ + pxItemToRemove->pxNext->pxPrevious = pxItemToRemove->pxPrevious; + pxItemToRemove->pxPrevious->pxNext = pxItemToRemove->pxNext; + + if( pxList->pxIndex == pxItemToRemove ) + { + pxList->pxIndex = pxItemToRemove->pxPrevious; + } + + pxItemToRemove->pxContainer = NULL; + ( pxList->uxNumberOfItems )--; + + return pxList->uxNumberOfItems; } /* The function func mimics the callback function.*/ @@ -59,15 +72,14 @@ void harness() TickType_t xIdentifier; BaseType_t xIsIPv6; size_t len; + BaseType_t xReturn; - __CPROVER_assume( len >= 0 && len <= MAX_HOSTNAME_LEN ); + __CPROVER_assume( len > 0 && len <= MAX_HOSTNAME_LEN ); char * pcHostName = safeMalloc( len ); + __CPROVER_assume( pcHostName != NULL ); + __CPROVER_havoc_slice( pcHostName, len - 1 ); + pcHostName[ len - 1 ] = NULL; - if( len && pcHostName ) - { - pcHostName[ len - 1 ] = NULL; - } - - vDNSSetCallBack( pcHostName, &pvSearchID, pCallback, xTimeout, xIdentifier, xIsIPv6 ); /* Add an item to be able to check the cancel function if the list is non-empty. */ + xReturn = xDNSSetCallBack( pcHostName, &pvSearchID, pCallback, xTimeout, xIdentifier, xIsIPv6 ); /* Add an item to be able to check the cancel function if the list is non-empty. */ FreeRTOS_gethostbyname_cancel( &pvSearchID ); } diff --git a/test/cbmc/proofs/DNS/DNSgetHostByName_cancel/Makefile.json b/test/cbmc/proofs/DNS/DNSgetHostByName_cancel/Makefile.json index 8f568fb540..fc7bfc4c01 100644 --- a/test/cbmc/proofs/DNS/DNSgetHostByName_cancel/Makefile.json +++ b/test/cbmc/proofs/DNS/DNSgetHostByName_cancel/Makefile.json @@ -10,14 +10,18 @@ [ "--unwind 1", "--unwindset prvProcessDNSCache.0:5,strlen.0:{HOSTNAME_UNWIND},__builtin___strcpy_chk.0:{HOSTNAME_UNWIND},vDNSCheckCallBack.0:2,strcpy.0:{HOSTNAME_UNWIND}", - "--nondet-static" + "--unwindset strncpy.0:{HOSTNAME_UNWIND}" ], "OBJS": [ "$(ENTRY)_harness.goto", + "$(FREERTOS_PLUS_TCP)/source/FreeRTOS_IP_Utils.goto", + "$(FREERTOS_PLUS_TCP)/source/FreeRTOS_IP_Timers.goto", "$(FREERTOS_PLUS_TCP)/source/FreeRTOS_DNS.goto", - "$(FREERTOS_PLUS_TCP)/test/FreeRTOS-Kernel/tasks.goto", - "$(FREERTOS_PLUS_TCP)/test/FreeRTOS-Kernel/list.goto" + "$(FREERTOS_PLUS_TCP)/source/FreeRTOS_DNS_Callback.goto", + "$(FREERTOS_PLUS_TCP)/test/cbmc/stubs/freertos_kernel_api.goto", + "$(FREERTOS_PLUS_TCP)/test/cbmc/stubs/freertos_api.goto", + "$(FREERTOS_PLUS_TCP)/test/cbmc/stubs/cbmc.goto" ], "DEF": [ diff --git a/test/cbmc/proofs/DNS/prepareReplyDNSMessage/Makefile.json b/test/cbmc/proofs/DNS/prepareReplyDNSMessage/Makefile.json index f4f366afbf..29e55e2b6f 100644 --- a/test/cbmc/proofs/DNS/prepareReplyDNSMessage/Makefile.json +++ b/test/cbmc/proofs/DNS/prepareReplyDNSMessage/Makefile.json @@ -10,6 +10,7 @@ [ "$(ENTRY)_harness.goto", "$(FREERTOS_PLUS_TCP)/test/cbmc/stubs/cbmc.goto", + "$(FREERTOS_PLUS_TCP)/source/FreeRTOS_IP.goto", "$(FREERTOS_PLUS_TCP)/source/FreeRTOS_IP_Utils.goto", "$(FREERTOS_PLUS_TCP)/source/FreeRTOS_DNS_Parser.goto" ], diff --git a/test/cbmc/proofs/DNS/prepareReplyDNSMessage/prepareReplyDNSMessage_harness.c b/test/cbmc/proofs/DNS/prepareReplyDNSMessage/prepareReplyDNSMessage_harness.c index 851bd44744..d753329458 100644 --- a/test/cbmc/proofs/DNS/prepareReplyDNSMessage/prepareReplyDNSMessage_harness.c +++ b/test/cbmc/proofs/DNS/prepareReplyDNSMessage/prepareReplyDNSMessage_harness.c @@ -53,8 +53,7 @@ NetworkEndPoint_t * FreeRTOS_FindEndPointOnNetMask_IPv6( const IPv6_Address_t * /* Stub FreeRTOS_FindEndPointOnNetMask_IPv6 as its not relevant to the * correctness of the proof */ -NetworkEndPoint_t * FreeRTOS_FindEndPointOnNetMask( uint32_t ulIPAddress, - uint32_t ulWhere ) +NetworkEndPoint_t * FreeRTOS_FindEndPointOnNetMask( uint32_t ulIPAddress ) { /* Assume at least one end-point is available */ return pxNetworkEndPoint_Temp; diff --git a/test/cbmc/proofs/DNS_ParseDNSReply/Configurations.json b/test/cbmc/proofs/DNS_ParseDNSReply/Configurations.json new file mode 100644 index 0000000000..80f783f4cd --- /dev/null +++ b/test/cbmc/proofs/DNS_ParseDNSReply/Configurations.json @@ -0,0 +1,50 @@ +{ + "ENTRY": "DNS_ParseDNSReply", + "TEST_PAYLOAD_SIZE": 2, + "TEST_IPV4_PACKET_SIZE": 29, + "TEST_IPV6_PACKET_SIZE": 49, + "CBMCFLAGS": + [ + "--unwind 1", + "--unwindset DNS_ParseDNSReply.0:{TEST_PAYLOAD_SIZE}", + "--unwindset DNS_ReadNameField.0:{TEST_PAYLOAD_SIZE}", + "--unwindset DNS_ReadNameField.1:{TEST_PAYLOAD_SIZE}", + "--unwindset parseDNSAnswer.0:{TEST_PAYLOAD_SIZE}", + "--unwindset strncpy.0:{TEST_PAYLOAD_SIZE}" + ], + "OPT": + [ + "--export-file-local-symbols" + ], + "OBJS": + [ + "$(ENTRY)_harness.goto", + "$(FREERTOS_PLUS_TCP)/source/FreeRTOS_DNS_Parser.goto", + "$(FREERTOS_PLUS_TCP)/test/cbmc/stubs/cbmc.goto" + ], + "DEF": + [ + { + "IPv4": + [ + "TEST_PACKET_SIZE={TEST_IPV4_PACKET_SIZE}", + "ipconfigUSE_LLMNR=1", + "ipconfigUSE_MDNS=1", + "IS_TESTING_IPV6=0" + ] + }, + { + "IPv6": + [ + "TEST_PACKET_SIZE={TEST_IPV6_PACKET_SIZE}", + "ipconfigUSE_LLMNR=1", + "ipconfigUSE_MDNS=1", + "IS_TESTING_IPV6=1" + ] + } + ], + "INC": + [ + "$(FREERTOS_PLUS_TCP)/test/cbmc/include" + ] +} \ No newline at end of file diff --git a/test/cbmc/proofs/DNS_ParseDNSReply/DNS_ParseDNSReply_harness.c b/test/cbmc/proofs/DNS_ParseDNSReply/DNS_ParseDNSReply_harness.c new file mode 100644 index 0000000000..9fae89ddc8 --- /dev/null +++ b/test/cbmc/proofs/DNS_ParseDNSReply/DNS_ParseDNSReply_harness.c @@ -0,0 +1,211 @@ +/* Standard includes. */ +#include + +/* FreeRTOS includes. */ +#include "FreeRTOS.h" +#include "task.h" +#include "queue.h" +#include "list.h" +#include "semphr.h" + +/* FreeRTOS+TCP includes. */ +#include "FreeRTOS_IP.h" +#include "FreeRTOS_DNS.h" +#include "FreeRTOS_DNS_Parser.h" +#include "NetworkBufferManagement.h" +#include "NetworkInterface.h" +#include "IPTraceMacroDefaults.h" + +#include "cbmc.h" +#include "../../utility/memory_assignments.c" + +/**************************************************************** +* Signature of function under test +****************************************************************/ + +uint32_t DNS_ParseDNSReply( uint8_t * pucUDPPayloadBuffer, + size_t uxBufferLength, + struct freertos_addrinfo ** ppxAddressInfo, + BaseType_t xExpected, + uint16_t usPort ); + +NetworkBufferDescriptor_t xNetworkBuffer; +int lIsIPv6Packet; + +size_t uxIPHeaderSizePacket( const NetworkBufferDescriptor_t * pxNetworkBuffer ) +{ + #if IS_TESTING_IPV6 + return ipSIZE_OF_IPv6_HEADER; + #else + return ipSIZE_OF_IPv4_HEADER; + #endif +} + +NetworkBufferDescriptor_t * pxUDPPayloadBuffer_to_NetworkBuffer( const void * pvBuffer ) +{ + __CPROVER_assert( pvBuffer != NULL, "Precondition: pvBuffer != NULL" ); + NetworkBufferDescriptor_t * pxRBuf; + + if( nondet_bool() ) + { + pxRBuf = NULL; + } + else + { + pxRBuf = &xNetworkBuffer; + } + + return pxRBuf; +} + +uint32_t ulChar2u32( const uint8_t * pucPtr ) +{ + __CPROVER_assert( __CPROVER_r_ok( pucPtr, 4 ), "must be 4 bytes legal address to read" ); +} + +uint16_t usChar2u16( const uint8_t * pucPtr ) +{ + __CPROVER_assert( __CPROVER_r_ok( pucPtr, 2 ), "must be 2 bytes legal address to read" ); +} + +const char * FreeRTOS_inet_ntop( BaseType_t xAddressFamily, + const void * pvSource, + char * pcDestination, + socklen_t uxSize ) +{ + __CPROVER_assert( __CPROVER_r_ok( pcDestination, uxSize ), "input buffer must be available" ); + + #if IS_TESTING_IPV6 + __CPROVER_assert( ( xAddressFamily == FREERTOS_AF_INET6 && __CPROVER_r_ok( pvSource, 16 ) ), "input address must be available" ); + #else + __CPROVER_assert( ( xAddressFamily == FREERTOS_AF_INET && __CPROVER_r_ok( pvSource, 4 ) ), "input address must be available" ); + #endif +} + +BaseType_t xApplicationDNSQueryHook_Multi( struct xNetworkEndPoint * pxEndPoint, + const char * pcName ) +{ + __CPROVER_assert( strlen( pcName ) < ipconfigDNS_CACHE_NAME_LENGTH, "The length of domain name must be less than cache size" ); +} + +void vReleaseNetworkBufferAndDescriptor( NetworkBufferDescriptor_t * const pxNetworkBuffer ) +{ + __CPROVER_assert( pxNetworkBuffer, "network descriptor must be valid." ); + __CPROVER_assert( pxNetworkBuffer->pucEthernetBuffer, "network buffer must be valid." ); + + free( pxNetworkBuffer->pucEthernetBuffer ); + free( pxNetworkBuffer ); +} + +/* The checksum generation is stubbed out since the actual checksum + * does not matter. The stub will return an indeterminate value each time. */ +uint16_t usGenerateChecksum( uint16_t usSum, + const uint8_t * pucNextData, + size_t uxByteCount ) +{ + uint16_t usReturn; + + __CPROVER_assert( __CPROVER_r_ok( pucNextData, uxByteCount ), "Data must be valid" ); + + /* Return an indeterminate value. */ + return usReturn; +} + +/* The checksum generation is stubbed out since the actual checksum + * does not matter. The stub will return an indeterminate value each time. */ +uint16_t usGenerateProtocolChecksum( const uint8_t * const pucEthernetBuffer, + size_t uxBufferLength, + BaseType_t xOutgoingPacket ) +{ + uint16_t usReturn; + + __CPROVER_assert( __CPROVER_r_ok( pucEthernetBuffer, uxBufferLength ), "Data must be valid" ); + + /* Return an indeterminate value. */ + return usReturn; +} + +/* pxDuplicateNetworkBufferWithDescriptor() is proved separately */ +NetworkBufferDescriptor_t * pxDuplicateNetworkBufferWithDescriptor( const NetworkBufferDescriptor_t * const pxNetworkBuffer, + size_t xNewLength ) +{ + NetworkBufferDescriptor_t * pxNetworkBuffer = safeMalloc( sizeof( NetworkBufferDescriptor_t ) ); + + if( ensure_memory_is_valid( pxNetworkBuffer, xNewLength ) ) + { + pxNetworkBuffer->pucEthernetBuffer = safeMalloc( xNewLength ); + __CPROVER_assume( pxNetworkBuffer->pucEthernetBuffer ); + pxNetworkBuffer->xDataLength = xNewLength; + } + + return pxNetworkBuffer; +} + +/* vReturnEthernetFrame() is proved separately */ +void vReturnEthernetFrame( NetworkBufferDescriptor_t * pxNetworkBuffer, + BaseType_t xReleaseAfterSend ) +{ + __CPROVER_assert( pxNetworkBuffer != NULL, "xNetworkBuffer != NULL" ); + __CPROVER_assert( pxNetworkBuffer->pucEthernetBuffer != NULL, "pxNetworkBuffer->pucEthernetBuffer != NULL" ); + __CPROVER_assert( __CPROVER_r_ok( pxNetworkBuffer->pucEthernetBuffer, pxNetworkBuffer->xDataLength ), "Data must be valid" ); +} + +uint32_t parseDNSAnswer( ParseSet_t * pxSet, + struct freertos_addrinfo ** ppxAddressInfo, + size_t * uxBytesRead ) +{ + uint32_t result; + + __CPROVER_assert( __CPROVER_r_ok( pxSet->pucByte, pxSet->uxSourceBytesRemaining ), "Data must be valid" ); + + return result; +} + +/**************************************************************** +* Proof of prvParseDNSReply +****************************************************************/ + +void harness() +{ + size_t uxBufferLength; + uint16_t usPort; + struct freertos_addrinfo * pxAddressInfo; + BaseType_t xExpected; + NetworkEndPoint_t * pxNetworkEndPoint_Temp = ( NetworkEndPoint_t * ) safeMalloc( sizeof( NetworkEndPoint_t ) ); + const uint32_t ulIpv4UdpOffset = 42, ulIpv6UdpOffset = 62; + uint8_t * pPayloadBuffer; + size_t uxPayloadBufferLength; + + __CPROVER_assert( TEST_PACKET_SIZE < CBMC_MAX_OBJECT_SIZE, + "TEST_PACKET_SIZE < CBMC_MAX_OBJECT_SIZE" ); + + __CPROVER_assume( uxBufferLength < CBMC_MAX_OBJECT_SIZE ); + __CPROVER_assume( uxBufferLength <= TEST_PACKET_SIZE ); + + lIsIPv6Packet = IS_TESTING_IPV6; + + xNetworkBuffer.pucEthernetBuffer = safeMalloc( uxBufferLength ); + xNetworkBuffer.xDataLength = uxBufferLength; + xNetworkBuffer.pxEndPoint = pxNetworkEndPoint_Temp; + + __CPROVER_assume( xNetworkBuffer.pucEthernetBuffer != NULL ); + + if( lIsIPv6Packet ) + { + __CPROVER_assume( uxBufferLength >= ulIpv6UdpOffset ); /* 62 is total size of IPv4 UDP header, including ethernet, IPv6, UDP headers. */ + pPayloadBuffer = xNetworkBuffer.pucEthernetBuffer + ulIpv6UdpOffset; + uxPayloadBufferLength = uxBufferLength - ulIpv6UdpOffset; + } + else + { + __CPROVER_assume( uxBufferLength >= ulIpv4UdpOffset ); /* 42 is total size of IPv4 UDP header, including ethernet, IPv4, UDP headers. */ + pPayloadBuffer = xNetworkBuffer.pucEthernetBuffer + ulIpv4UdpOffset; + uxPayloadBufferLength = uxBufferLength - ulIpv4UdpOffset; + } + + uint32_t index = DNS_ParseDNSReply( pPayloadBuffer, + uxPayloadBufferLength, + &pxAddressInfo, + xExpected, + usPort ); +} diff --git a/test/cbmc/proofs/IP/ProcessEthernetPacket/Makefile.json b/test/cbmc/proofs/IP/ProcessEthernetPacket/Makefile.json index 4a2b35b440..101f63983f 100644 --- a/test/cbmc/proofs/IP/ProcessEthernetPacket/Makefile.json +++ b/test/cbmc/proofs/IP/ProcessEthernetPacket/Makefile.json @@ -12,6 +12,9 @@ [ "$(ENTRY)_harness.goto", "$(FREERTOS_PLUS_TCP)/test/cbmc/stubs/cbmc.goto", - "$(FREERTOS_PLUS_TCP)/source/FreeRTOS_IP.goto" + "$(FREERTOS_PLUS_TCP)/test/cbmc/stubs/freertos_api.goto", + "$(FREERTOS_PLUS_TCP)/test/cbmc/stubs/freertos_kernel_api.goto", + "$(FREERTOS_PLUS_TCP)/source/FreeRTOS_IP.goto", + "$(FREERTOS_PLUS_TCP)/source/FreeRTOS_IP_Timers.goto" ] } diff --git a/test/cbmc/proofs/IP/SendEventToIPTask/Makefile.json b/test/cbmc/proofs/IP/SendEventToIPTask/Makefile.json index 30727432c1..dfffab176a 100644 --- a/test/cbmc/proofs/IP/SendEventToIPTask/Makefile.json +++ b/test/cbmc/proofs/IP/SendEventToIPTask/Makefile.json @@ -36,6 +36,8 @@ [ "$(ENTRY)_harness.goto", "$(FREERTOS_PLUS_TCP)/source/FreeRTOS_IP.goto", - "$(FREERTOS_PLUS_TCP)/test/FreeRTOS-Kernel/tasks.goto" + "$(FREERTOS_PLUS_TCP)/source/FreeRTOS_IP_Timers.goto", + "$(FREERTOS_PLUS_TCP)/test/cbmc/stubs/freertos_kernel_api.goto", + "$(FREERTOS_PLUS_TCP)/test/cbmc/stubs/freertos_api.goto" ] } diff --git a/test/cbmc/proofs/IP/SendEventToIPTask/SendEventToIPTask_harness.c b/test/cbmc/proofs/IP/SendEventToIPTask/SendEventToIPTask_harness.c index 706bdb9051..665d0ee927 100644 --- a/test/cbmc/proofs/IP/SendEventToIPTask/SendEventToIPTask_harness.c +++ b/test/cbmc/proofs/IP/SendEventToIPTask/SendEventToIPTask_harness.c @@ -36,6 +36,16 @@ #include "FreeRTOS_IP.h" #include "FreeRTOS_IP_Private.h" +/* Abstraction of xIsCallingFromIPTask */ +BaseType_t xIsCallingFromIPTask( void ) +{ + BaseType_t xReturn; + + __CPROVER_assume( ( xReturn == pdTRUE ) || ( xReturn == pdFALSE ) ); + + return xReturn; +} + /* The harness test proceeds to call SendEventToIPTask with an unconstrained value */ void harness() { diff --git a/test/cbmc/proofs/Makefile.template b/test/cbmc/proofs/Makefile.template index 094fd560c1..15cf815dbb 100644 --- a/test/cbmc/proofs/Makefile.template +++ b/test/cbmc/proofs/Makefile.template @@ -105,7 +105,11 @@ $(ENTRY)5.goto: $(ENTRY)4.goto $(GOTO_INSTRUMENT) --drop-unused-functions @RULE_INPUT@ @RULE_OUTPUT@ \ > $(ENTRY)5.txt 2>&1 -$(ENTRY).goto: $(ENTRY)5.goto +$(ENTRY)6.goto: $(ENTRY)5.goto + $(GOTO_INSTRUMENT) --generate-function-body '(?!__CPROVER).*' --generate-function-body-options assert-false @RULE_INPUT@ @RULE_OUTPUT@ \ + > $(ENTRY)6.txt 2>&1 + +$(ENTRY).goto: $(ENTRY)6.goto @CP@ @RULE_INPUT@ @RULE_OUTPUT@ # ____________________________________________________________________ diff --git a/test/cbmc/proofs/ND/prvProcessICMPMessage_IPv6/Makefile.json b/test/cbmc/proofs/ND/prvProcessICMPMessage_IPv6/Makefile.json index 09f7d0beb9..151aefe2ec 100644 --- a/test/cbmc/proofs/ND/prvProcessICMPMessage_IPv6/Makefile.json +++ b/test/cbmc/proofs/ND/prvProcessICMPMessage_IPv6/Makefile.json @@ -8,8 +8,11 @@ "OBJS": [ "$(ENTRY)_harness.goto", - "$(FREERTOS_PLUS_TCP)/source/FreeRTOS_ND.goto" - + "$(FREERTOS_PLUS_TCP)/source/FreeRTOS_IP_Timers.goto", + "$(FREERTOS_PLUS_TCP)/source/FreeRTOS_ND.goto", + "$(FREERTOS_PLUS_TCP)/test/cbmc/stubs/freertos_kernel_api.goto", + "$(FREERTOS_PLUS_TCP)/test/cbmc/stubs/freertos_api.goto", + "$(FREERTOS_PLUS_TCP)/test/cbmc/stubs/cbmc.goto" ], "DEF": [ diff --git a/test/cbmc/proofs/ND/prvProcessICMPMessage_IPv6/ProcessICMPMessage_IPv6_harness.c b/test/cbmc/proofs/ND/prvProcessICMPMessage_IPv6/ProcessICMPMessage_IPv6_harness.c index 990736bc7d..0b02ac8ed2 100644 --- a/test/cbmc/proofs/ND/prvProcessICMPMessage_IPv6/ProcessICMPMessage_IPv6_harness.c +++ b/test/cbmc/proofs/ND/prvProcessICMPMessage_IPv6/ProcessICMPMessage_IPv6_harness.c @@ -37,7 +37,6 @@ #include "FreeRTOS_ND.h" /* CBMC includes. */ -#include "../../utility/memory_assignments.c" #include "cbmc.h" extern NDCacheRow_t xNDCache[ ipconfigND_CACHE_ENTRIES ]; @@ -70,6 +69,12 @@ void vReceiveNA( const NetworkBufferDescriptor_t * pxNetworkBuffer ) __CPROVER_assert( pxNetworkBuffer != NULL, "The network buffer descriptor cannot be NULL." ); } +/* This function has been tested separately. Therefore, we assume that the implementation is correct. */ +void vReceiveRA( const NetworkBufferDescriptor_t * pxNetworkBuffer ) +{ + __CPROVER_assert( pxNetworkBuffer != NULL, "The network buffer descriptor cannot be NULL." ); +} + /* This function has been tested separately. Therefore, we assume that the implementation is correct. */ BaseType_t xSendEventStructToIPTask( const IPStackEvent_t * pxEvent, TickType_t uxTimeout ) @@ -103,7 +108,7 @@ NetworkEndPoint_t * FreeRTOS_InterfaceEPInSameSubnet_IPv6( const NetworkInterfac pxEndPoints = ( NetworkEndPoint_t * ) safeMalloc( sizeof( NetworkEndPoint_t ) ); - if( ensure_memory_is_valid( pxEndPoints, sizeof( NetworkEndPoint_t ) ) ) + if( ( pxEndPoints ) && __CPROVER_w_ok( pxEndPoints, sizeof( NetworkEndPoint_t ) ) ) { /* Interface init. */ pxEndPoints->pxNetworkInterface = ( NetworkInterface_t * ) safeMalloc( sizeof( NetworkInterface_t ) ); @@ -116,21 +121,32 @@ NetworkEndPoint_t * FreeRTOS_InterfaceEPInSameSubnet_IPv6( const NetworkInterfac return pxEndPoints; } +size_t uxIPHeaderSizePacket( const NetworkBufferDescriptor_t * pxNetworkBuffer ) +{ + size_t uxResult; + + __CPROVER_assume( ( uxResult == ipSIZE_OF_IPv4_HEADER ) || ( uxResult == ipSIZE_OF_IPv6_HEADER ) ); + + return uxResult; +} + void harness() { - NetworkBufferDescriptor_t * pxNetworkBuffer = ensure_FreeRTOS_NetworkBuffer_is_allocated(); + NetworkBufferDescriptor_t * pxNetworkBuffer; uint32_t ulLen; uint16_t usEthernetBufferSize; - NetworkBufferDescriptor_t xLocalBuffer; + NetworkBufferDescriptor_t * pxLocalARPWaitingNetworkBuffer; + + __CPROVER_assume( ( ulLen >= sizeof( ICMPPacket_IPv6_t ) ) && ( ulLen < ipconfigNETWORK_MTU ) ); + + pxNetworkBuffer = pxGetNetworkBufferWithDescriptor( ulLen, 0 ); /* The code does not expect pxNetworkBuffer to be NULL. */ __CPROVER_assume( pxNetworkBuffer != NULL ); - - __CPROVER_assume( ( ulLen >= sizeof( ICMPPacket_IPv6_t ) ) && ( ulLen < ipconfigNETWORK_MTU ) ); + __CPROVER_assume( pxNetworkBuffer->pucEthernetBuffer != NULL ); + __CPROVER_havoc_slice( pxNetworkBuffer->pucEthernetBuffer, ulLen ); pxNetworkBuffer->xDataLength = ulLen; - pxNetworkBuffer->pucEthernetBuffer = safeMalloc( ulLen ); - __CPROVER_assume( pxNetworkBuffer->pucEthernetBuffer != NULL ); /* Add an end point to the network buffer present. Its assumed that the * network interface layer correctly assigns the end point to the generated buffer. */ @@ -147,19 +163,20 @@ void harness() /* The packet must at least be as big as an IPv6 Packet. The size is not * checked in the function as the pointer is stored by the IP-task itself * and therefore it will always be of the required size. */ - __CPROVER_assume( usEthernetBufferSize >= sizeof( IPPacket_IPv6_t ) ); - - /* Add matching data length to the network buffer descriptor. */ - __CPROVER_assume( xLocalBuffer.xDataLength == usEthernetBufferSize ); - - xLocalBuffer.pucEthernetBuffer = safeMalloc( usEthernetBufferSize ); + __CPROVER_assume( ( usEthernetBufferSize >= sizeof( IPPacket_IPv6_t ) ) && ( usEthernetBufferSize < ipconfigNETWORK_MTU ) ); + pxLocalARPWaitingNetworkBuffer = pxGetNetworkBufferWithDescriptor( usEthernetBufferSize, 0 ); /* Since this pointer is maintained by the IP-task, either the pointer - * pxARPWaitingNetworkBuffer will be NULL or xLocalBuffer.pucEthernetBuffer + * pxARPWaitingNetworkBuffer will be NULL or pxLocalARPWaitingNetworkBuffer.pucEthernetBuffer * will be non-NULL. */ - __CPROVER_assume( xLocalBuffer.pucEthernetBuffer != NULL ); + __CPROVER_assume( pxLocalARPWaitingNetworkBuffer != NULL ); + __CPROVER_assume( pxLocalARPWaitingNetworkBuffer->pucEthernetBuffer != NULL ); + __CPROVER_havoc_slice( pxLocalARPWaitingNetworkBuffer->pucEthernetBuffer, usEthernetBufferSize ); + + /* Add matching data length to the network buffer descriptor. */ + pxLocalARPWaitingNetworkBuffer->xDataLength = usEthernetBufferSize; - pxARPWaitingNetworkBuffer = &xLocalBuffer; + pxARPWaitingNetworkBuffer = pxLocalARPWaitingNetworkBuffer; } else { diff --git a/test/cbmc/proofs/ND/prvReturnICMP_IPv6/Makefile.json b/test/cbmc/proofs/ND/prvReturnICMP_IPv6/Makefile.json index cdc3a4f0a2..47de0cd15d 100644 --- a/test/cbmc/proofs/ND/prvReturnICMP_IPv6/Makefile.json +++ b/test/cbmc/proofs/ND/prvReturnICMP_IPv6/Makefile.json @@ -8,8 +8,11 @@ "OBJS": [ "$(ENTRY)_harness.goto", - "$(FREERTOS_PLUS_TCP)/source/FreeRTOS_ND.goto" - + "$(FREERTOS_PLUS_TCP)/source/FreeRTOS_IP_Timers.goto", + "$(FREERTOS_PLUS_TCP)/source/FreeRTOS_ND.goto", + "$(FREERTOS_PLUS_TCP)/test/cbmc/stubs/freertos_kernel_api.goto", + "$(FREERTOS_PLUS_TCP)/test/cbmc/stubs/freertos_api.goto", + "$(FREERTOS_PLUS_TCP)/test/cbmc/stubs/cbmc.goto" ], "INC": [ diff --git a/test/cbmc/proofs/ND/prvReturnICMP_IPv6/ReturnICMP_IPv6_harness.c b/test/cbmc/proofs/ND/prvReturnICMP_IPv6/ReturnICMP_IPv6_harness.c index b40437501a..e0340a76cd 100644 --- a/test/cbmc/proofs/ND/prvReturnICMP_IPv6/ReturnICMP_IPv6_harness.c +++ b/test/cbmc/proofs/ND/prvReturnICMP_IPv6/ReturnICMP_IPv6_harness.c @@ -37,7 +37,6 @@ #include "FreeRTOS_ND.h" /* CBMC includes. */ -#include "../../utility/memory_assignments.c" #include "cbmc.h" extern NDCacheRow_t xNDCache[ ipconfigND_CACHE_ENTRIES ]; @@ -72,6 +71,12 @@ void vReceiveNA( const NetworkBufferDescriptor_t * pxNetworkBuffer ) __CPROVER_assert( pxNetworkBuffer->pucEthernetBuffer != NULL, "The Ethernet buffer cannot be NULL." ); } +/* This function has been tested separately. Therefore, we assume that the implementation is correct. */ +void vReceiveRA( const NetworkBufferDescriptor_t * pxNetworkBuffer ) +{ + __CPROVER_assert( pxNetworkBuffer != NULL, "The network buffer descriptor cannot be NULL." ); +} + /* This function has been tested separately. Therefore, we assume that the implementation is correct. */ BaseType_t xSendEventStructToIPTask( const IPStackEvent_t * pxEvent, TickType_t uxTimeout ) @@ -106,7 +111,7 @@ NetworkEndPoint_t * FreeRTOS_InterfaceEPInSameSubnet_IPv6( const NetworkInterfac pxEndPoints = ( NetworkEndPoint_t * ) safeMalloc( sizeof( NetworkEndPoint_t ) ); - if( ensure_memory_is_valid( pxEndPoints, sizeof( NetworkEndPoint_t ) ) ) + if( ( pxEndPoints ) && __CPROVER_w_ok( pxEndPoints, sizeof( NetworkEndPoint_t ) ) ) { /* Interface init. */ pxEndPoints->pxNetworkInterface = ( NetworkInterface_t * ) safeMalloc( sizeof( NetworkInterface_t ) ); @@ -119,21 +124,33 @@ NetworkEndPoint_t * FreeRTOS_InterfaceEPInSameSubnet_IPv6( const NetworkInterfac return pxEndPoints; } +size_t uxIPHeaderSizePacket( const NetworkBufferDescriptor_t * pxNetworkBuffer ) +{ + size_t uxResult; + + __CPROVER_assume( ( uxResult == ipSIZE_OF_IPv4_HEADER ) || ( uxResult == ipSIZE_OF_IPv6_HEADER ) ); + + return uxResult; +} + void harness() { - NetworkBufferDescriptor_t * pxNetworkBuffer = ensure_FreeRTOS_NetworkBuffer_is_allocated(); + NetworkBufferDescriptor_t * pxNetworkBuffer; uint32_t ulLen; - NetworkBufferDescriptor_t xLocalBuffer; + NetworkBufferDescriptor_t * pxLocalARPWaitingNetworkBuffer; uint16_t usEthernetBufferSize; - /* The code does not expect both of these to be equal to NULL at the same time. */ - __CPROVER_assume( pxNetworkBuffer != NULL ); - __CPROVER_assume( ( ulLen >= sizeof( ICMPPacket_IPv6_t ) ) && ( ulLen < ipconfigNETWORK_MTU ) ); + pxNetworkBuffer = pxGetNetworkBufferWithDescriptor( ulLen, 0 ); + + /* The code does not expect pxNetworkBuffer to be NULL. */ + __CPROVER_assume( pxNetworkBuffer != NULL ); + pxNetworkBuffer->xDataLength = ulLen; pxNetworkBuffer->pucEthernetBuffer = safeMalloc( ulLen ); - __CPROVER_assume( pxNetworkBuffer->pucEthernetBuffer ); + __CPROVER_assume( pxNetworkBuffer->pucEthernetBuffer != NULL ); + __CPROVER_havoc_slice( pxNetworkBuffer->pucEthernetBuffer, ulLen ); /* Add an end point to the network buffer present. Its assumed that the * network interface layer correctly assigns the end point to the generated buffer. */ @@ -149,19 +166,20 @@ void harness() /* The packet must at least be as big as an IPv6 Packet. The size is not * checked in the function as the pointer is stored by the IP-task itself * and therefore it will always be of the required size. */ - __CPROVER_assume( usEthernetBufferSize >= sizeof( IPPacket_IPv6_t ) ); - - /* Add matching data length to the network buffer descriptor. */ - __CPROVER_assume( xLocalBuffer.xDataLength == usEthernetBufferSize ); - - xLocalBuffer.pucEthernetBuffer = safeMalloc( usEthernetBufferSize ); + __CPROVER_assume( ( usEthernetBufferSize >= sizeof( IPPacket_IPv6_t ) ) && ( usEthernetBufferSize < ipconfigNETWORK_MTU ) ); + pxLocalARPWaitingNetworkBuffer = pxGetNetworkBufferWithDescriptor( usEthernetBufferSize, 0 ); /* Since this pointer is maintained by the IP-task, either the pointer - * pxARPWaitingNetworkBuffer will be NULL or xLocalBuffer.pucEthernetBuffer + * pxARPWaitingNetworkBuffer will be NULL or pxLocalARPWaitingNetworkBuffer.pucEthernetBuffer * will be non-NULL. */ - __CPROVER_assume( xLocalBuffer.pucEthernetBuffer != NULL ); + __CPROVER_assume( pxLocalARPWaitingNetworkBuffer != NULL ); + __CPROVER_assume( pxLocalARPWaitingNetworkBuffer->pucEthernetBuffer != NULL ); + __CPROVER_havoc_slice( pxLocalARPWaitingNetworkBuffer->pucEthernetBuffer, usEthernetBufferSize ); + + /* Add matching data length to the network buffer descriptor. */ + pxLocalARPWaitingNetworkBuffer->xDataLength = usEthernetBufferSize; - pxARPWaitingNetworkBuffer = &xLocalBuffer; + pxARPWaitingNetworkBuffer = pxLocalARPWaitingNetworkBuffer; prvProcessICMPMessage_IPv6( pxNetworkBuffer ); } diff --git a/test/cbmc/proofs/ParseDNSReply/Makefile.json b/test/cbmc/proofs/ParseDNSReply/Makefile.json deleted file mode 100644 index aefd62da62..0000000000 --- a/test/cbmc/proofs/ParseDNSReply/Makefile.json +++ /dev/null @@ -1,68 +0,0 @@ -# The proof depends on one parameter: -# NETWORK_BUFFER_SIZE is the size of the network buffer being parsed -# The buffer size must be bounded because we must bound the number of -# iterations loops iterating over the buffer. - -{ - "ENTRY": "ParseDNSReply", - -################################################################ -# This is the network buffer size. -# Reasonable values are size > 12 = sizeof(xDNSMessage) - "NETWORK_BUFFER_SIZE": 40, - -################################################################ -# This is the size of the buffer into which the name is copied. -# Set to any positive value. -# In the source, NAME_SIZE=254 and NETWORK_BUFFER_SIZE >> NAME_SIZE -# In the proof, NAME_SIZE >= 4 required for good coverage. - "NAME_SIZE": "10", - -################################################################ -# Loop prvParseDNSReply.0: -# file lib/FreeRTOS-Plus-TCP/source/FreeRTOS_DNS.c line 915 - "PARSELOOP0": "prvParseDNSReply.0", - -# M = sizeof( DNSMessage_t ) = 12 -# U = sizeof( uint32_t) = 4 -# Loop bound is (NETWORK_BUFFER_SIZE - M) div (U+1) + 1 tight for SIZE >= M -# Loop bound is 1 for 0 <= SIZE < M - "PARSELOOP0_UNWIND": - "__eval 1 if {NETWORK_BUFFER_SIZE} < 12 else ({NETWORK_BUFFER_SIZE} - 12) / 5 + 1", - -################################################################ -# Loop prvParseDNSReply.1: -# file lib/FreeRTOS-Plus-TCP/source/FreeRTOS_DNS.c line 989 - "PARSELOOP1": "prvParseDNSReply.1", - -# A = sizeof( DNSAnswerRecord_t ) = 10 -# M = sizeof( DNSMessage_t ) = 12 -# U = sizeof( uint32_t) = 4 -# Loop bound is (NETWORK_BUFFER_SIZE - M - A) div (A+1) + A + 1 tight -# for SIZE >= M + A -# Loop bound is (NETWORK_BUFFER_SIZE - M) + 1 for M <= SIZE < M + A -# Loop bound is 1 for 0 <= SIZE < M - "PARSELOOP1_UNWIND": - "__eval 1 if {NETWORK_BUFFER_SIZE} < 12 else ({NETWORK_BUFFER_SIZE} - 11 if {NETWORK_BUFFER_SIZE} < 22 else ({NETWORK_BUFFER_SIZE} - 12 - 10) / 11 + 11)", - -################################################################ - - "CBMCFLAGS": - [ - "--unwind 1", - "--unwindset {PARSELOOP0}:{PARSELOOP0_UNWIND},{PARSELOOP1}:{PARSELOOP1_UNWIND},prvProcessDNSCache.0:5" - ], - - "OBJS": - [ - "$(ENTRY)_harness.goto", - "$(FREERTOS_PLUS_TCP)/source/FreeRTOS_DNS.goto", - "$(FREERTOS_PLUS_TCP)/test/FreeRTOS-Kernel/tasks.goto" - ], - - "DEF": - [ - "NETWORK_BUFFER_SIZE={NETWORK_BUFFER_SIZE}", - "NAME_SIZE={NAME_SIZE}" - ] -} diff --git a/test/cbmc/proofs/ParseDNSReply/ParseDNSReply_harness.c b/test/cbmc/proofs/ParseDNSReply/ParseDNSReply_harness.c deleted file mode 100644 index 74e594fbd2..0000000000 --- a/test/cbmc/proofs/ParseDNSReply/ParseDNSReply_harness.c +++ /dev/null @@ -1,130 +0,0 @@ -/* Standard includes. */ -#include - -/* FreeRTOS includes. */ -#include "FreeRTOS.h" -#include "task.h" -#include "queue.h" -#include "list.h" -#include "semphr.h" - -/* FreeRTOS+TCP includes. */ -#include "FreeRTOS_IP.h" -#include "FreeRTOS_Sockets.h" -#include "FreeRTOS_IP_Private.h" -#include "FreeRTOS_UDP_IP.h" -#include "FreeRTOS_DNS.h" -#include "FreeRTOS_DNS_Parser.h" -#include "NetworkBufferManagement.h" -#include "NetworkInterface.h" -#include "IPTraceMacroDefaults.h" - -#include "cbmc.h" - -/**************************************************************** -* Signature of function under test -****************************************************************/ - -uint32_t prvParseDNSReply( uint8_t * pucUDPPayloadBuffer, - size_t uxBufferLength, - BaseType_t xExpected ); - -/**************************************************************** -* Abstraction of DNS_ReadNameField proved in ReadNameField -****************************************************************/ - -size_t DNS_ReadNameField( const uint8_t * pucByte, - size_t uxRemainingBytes, - char * pcName, - size_t uxDestLen ) -{ - __CPROVER_assert( NETWORK_BUFFER_SIZE < CBMC_MAX_OBJECT_SIZE, - "NETWORK_BUFFER_SIZE < CBMC_MAX_OBJECT_SIZE" ); - __CPROVER_assert( NAME_SIZE < CBMC_MAX_OBJECT_SIZE, - "NAME_SIZE < CBMC_MAX_OBJECT_SIZE" ); - __CPROVER_assert( NAME_SIZE >= 4, - "NAME_SIZE >= 4 required for good coverage." ); - - - /* Preconditions */ - __CPROVER_assert( uxRemainingBytes < CBMC_MAX_OBJECT_SIZE, - "ReadNameField: uxRemainingBytes < CBMC_MAX_OBJECT_SIZE)" ); - __CPROVER_assert( uxDestLen < CBMC_MAX_OBJECT_SIZE, - "ReadNameField: uxDestLen < CBMC_MAX_OBJECT_SIZE)" ); - - __CPROVER_assert( uxRemainingBytes <= NETWORK_BUFFER_SIZE, - "ReadNameField: uxRemainingBytes <= NETWORK_BUFFER_SIZE)" ); - - /* This precondition in the function contract for prvReadNameField - * fails because prvCheckOptions called prvReadNameField with the - * constant value 254. - * __CPROVER_assert(uxDestLen <= NAME_SIZE, - * "ReadNameField: uxDestLen <= NAME_SIZE)"); - */ - - __CPROVER_assert( pucByte != NULL, - "ReadNameField: pucByte != NULL )" ); - __CPROVER_assert( pcName != NULL, - "ReadNameField: pcName != NULL )" ); - - __CPROVER_assert( uxDestLen > 0, - "ReadNameField: uxDestLen > 0)" ); - - /* Return value */ - size_t index; - - /* Postconditions */ - __CPROVER_assume( index <= uxDestLen + 1 && index <= uxRemainingBytes ); - - return index; -} - -/**************************************************************** -* Abstraction of DNS_SkipNameField proved in SkipNameField -****************************************************************/ - -size_t DNS_SkipNameField( const uint8_t * pucByte, - size_t uxLength ) -{ - __CPROVER_assert( NETWORK_BUFFER_SIZE < CBMC_MAX_OBJECT_SIZE, - "NETWORK_BUFFER_SIZE < CBMC_MAX_OBJECT_SIZE" ); - - - /* Preconditions */ - __CPROVER_assert( uxLength < CBMC_MAX_OBJECT_SIZE, - "SkipNameField: uxLength < CBMC_MAX_OBJECT_SIZE)" ); - __CPROVER_assert( uxLength <= NETWORK_BUFFER_SIZE, - "SkipNameField: uxLength <= NETWORK_BUFFER_SIZE)" ); - __CPROVER_assert( pucByte != NULL, - "SkipNameField: pucByte != NULL)" ); - - /* Return value */ - size_t index; - - /* Postconditions */ - __CPROVER_assume( index <= uxLength ); - - return index; -} - -/**************************************************************** -* Proof of prvParseDNSReply -****************************************************************/ - -void harness() -{ - size_t uxBufferLength; - BaseType_t xExpected; - uint8_t * pucUDPPayloadBuffer = malloc( uxBufferLength ); - - __CPROVER_assert( NETWORK_BUFFER_SIZE < CBMC_MAX_OBJECT_SIZE, - "NETWORK_BUFFER_SIZE < CBMC_MAX_OBJECT_SIZE" ); - - __CPROVER_assume( uxBufferLength < CBMC_MAX_OBJECT_SIZE ); - __CPROVER_assume( uxBufferLength <= NETWORK_BUFFER_SIZE ); - __CPROVER_assume( pucUDPPayloadBuffer != NULL ); - - uint32_t index = prvParseDNSReply( pucUDPPayloadBuffer, - uxBufferLength, - xExpected ); -} diff --git a/test/cbmc/proofs/RA/vReceiveRA/Makefile.json b/test/cbmc/proofs/RA/vReceiveRA/Makefile.json index 8b995fc8d1..1a4edbd460 100644 --- a/test/cbmc/proofs/RA/vReceiveRA/Makefile.json +++ b/test/cbmc/proofs/RA/vReceiveRA/Makefile.json @@ -4,6 +4,7 @@ [ "--unwind 2", "--unwindset FreeRTOS_NextEndPoint.0:1", + "--unwindset FreeRTOS_CreateIPv6Address.0:5", "--nondet-static" ], "OPT": @@ -13,8 +14,13 @@ "OBJS": [ "$(ENTRY)_harness.goto", + "$(FREERTOS_PLUS_TCP)/source/FreeRTOS_IP_Timers.goto", "$(FREERTOS_PLUS_TCP)/source/FreeRTOS_Routing.goto", - "$(FREERTOS_PLUS_TCP)/source/FreeRTOS_RA.goto" + "$(FREERTOS_PLUS_TCP)/source/FreeRTOS_RA.goto", + "$(FREERTOS_PLUS_TCP)/source/FreeRTOS_ND.goto", + "$(FREERTOS_PLUS_TCP)/test/cbmc/stubs/freertos_api.goto", + "$(FREERTOS_PLUS_TCP)/test/cbmc/stubs/freertos_kernel_api.goto", + "$(FREERTOS_PLUS_TCP)/test/cbmc/stubs/cbmc.goto" ], "INC": diff --git a/test/cbmc/proofs/RA/vReceiveRA/ReceiveRA_harness.c b/test/cbmc/proofs/RA/vReceiveRA/ReceiveRA_harness.c index e7f6cf5051..424c458326 100644 --- a/test/cbmc/proofs/RA/vReceiveRA/ReceiveRA_harness.c +++ b/test/cbmc/proofs/RA/vReceiveRA/ReceiveRA_harness.c @@ -37,7 +37,6 @@ #include "FreeRTOS_ND.h" /* CBMC includes. */ -#include "../../utility/memory_assignments.c" #include "cbmc.h" /* This function has been tested separately. Therefore, we assume that the implementation is correct. */ @@ -45,6 +44,11 @@ ICMPPrefixOption_IPv6_t * __CPROVER_file_local_FreeRTOS_RA_c_vReceiveRA_ReadRepl { ICMPPrefixOption_IPv6_t * pxPrefixOption = safeMalloc( sizeof( ICMPPrefixOption_IPv6_t ) ); + if( pxPrefixOption ) + { + __CPROVER_assume( ( pxPrefixOption->ucPrefixLength > 0U ) && ( pxPrefixOption->ucPrefixLength <= ( 8U * ipSIZE_OF_IPv6_ADDRESS ) ) ); + } + return pxPrefixOption; } @@ -75,30 +79,56 @@ void vNDSendRouterSolicitation( NetworkBufferDescriptor_t * pxNetworkBuffer, __CPROVER_assert( pxIPAddress != NULL, "The pxIPAddress cannot be NULL." ); } -void harness() +/* The checksum generation is stubbed out since the actual checksum + * does not matter. The stub will return an indeterminate value each time. */ +uint16_t usGenerateProtocolChecksum( const uint8_t * const pucEthernetBuffer, + size_t uxBufferLength, + BaseType_t xOutgoingPacket ) { - NetworkBufferDescriptor_t * pxNetworkBuffer = ensure_FreeRTOS_NetworkBuffer_is_allocated(); - NetworkInterface_t * pxInterface = ( NetworkInterface_t * ) safeMalloc( sizeof( NetworkInterface_t ) ); - uint32_t ulLen; + __CPROVER_assert( pucEthernetBuffer != NULL, "Ethernet buffer cannot be NULL" ); - /* The code does not expect pxNetworkBuffer to be NULL. */ - __CPROVER_assume( pxNetworkBuffer != NULL ); - - __CPROVER_assume( ( ulLen >= sizeof( ICMPPacket_IPv6_t ) ) && ( ulLen < ipconfigNETWORK_MTU ) ); - pxNetworkBuffer->pucEthernetBuffer = safeMalloc( ulLen ); - __CPROVER_assume( pxNetworkBuffer->pucEthernetBuffer != NULL ); + /* Return an indeterminate value. */ + return ( uint16_t ) nondet_uint32(); +} - pxNetworkBuffer->pxInterface = safeMalloc( sizeof( NetworkInterface_t ) ); - __CPROVER_assume( pxNetworkBuffer->pxInterface != NULL ); +/* vReturnEthernetFrame() is proved separately */ +void vReturnEthernetFrame( NetworkBufferDescriptor_t * pxNetworkBuffer, + BaseType_t xReleaseAfterSend ) +{ + __CPROVER_assert( pxNetworkBuffer != NULL, "xNetworkBuffer != NULL" ); + __CPROVER_assert( pxNetworkBuffer->pucEthernetBuffer != NULL, "pxNetworkBuffer->pucEthernetBuffer != NULL" ); + __CPROVER_assert( __CPROVER_r_ok( pxNetworkBuffer->pucEthernetBuffer, pxNetworkBuffer->xDataLength ), "Data must be valid" ); +} - pxNetworkBuffer->pxEndPoint = safeMalloc( sizeof( NetworkEndPoint_t ) ); +void harness() +{ + NetworkBufferDescriptor_t * pxNetworkBuffer; + NetworkInterface_t * pxInterface = ( NetworkInterface_t * ) safeMalloc( sizeof( NetworkInterface_t ) ); + uint32_t ulLen; /* Initialize global Endpoint variable */ pxNetworkEndPoints = ( NetworkEndPoint_t * ) safeMalloc( sizeof( NetworkEndPoint_t ) ); __CPROVER_assume( pxNetworkEndPoints != NULL ); - pxNetworkEndPoints->pxNetworkInterface = pxNetworkBuffer->pxInterface; + pxNetworkEndPoints->pxNetworkInterface = safeMalloc( sizeof( NetworkInterface_t ) ); + __CPROVER_assume( pxNetworkEndPoints->pxNetworkInterface != NULL ); __CPROVER_assume( pxNetworkEndPoints->pxNetworkInterface != NULL ); pxNetworkEndPoints->pxNext = NULL; + /* Initialize network buffer. */ + __CPROVER_assume( ( ulLen >= sizeof( ICMPPacket_IPv6_t ) ) && ( ulLen < ipconfigNETWORK_MTU ) ); + + pxNetworkBuffer = pxGetNetworkBufferWithDescriptor( ulLen, 0 ); + + /* The code does not expect pxNetworkBuffer to be NULL. */ + __CPROVER_assume( pxNetworkBuffer != NULL ); + __CPROVER_assume( pxNetworkBuffer->pucEthernetBuffer != NULL ); + __CPROVER_havoc_slice( pxNetworkBuffer->pucEthernetBuffer, ulLen ); + + pxNetworkBuffer->pxInterface = pxNetworkEndPoints->pxNetworkInterface; + pxNetworkBuffer->pxEndPoint = pxNetworkEndPoints; + + /* The prefix length must be equal to or less than 128 to avoid assertion in FreeRTOS_CreateIPv6Address(). */ + __CPROVER_assume( ( pxNetworkEndPoints->ipv6_settings.uxPrefixLength > 0U ) && ( pxNetworkEndPoints->ipv6_settings.uxPrefixLength <= ( 8U * ipSIZE_OF_IPv6_ADDRESS ) ) ); + vReceiveRA( pxNetworkBuffer ); } diff --git a/test/cbmc/proofs/RA/vReceiveRA_ReadReply/Makefile.json b/test/cbmc/proofs/RA/vReceiveRA_ReadReply/Makefile.json index 61d93b3d5d..91ff527323 100644 --- a/test/cbmc/proofs/RA/vReceiveRA_ReadReply/Makefile.json +++ b/test/cbmc/proofs/RA/vReceiveRA_ReadReply/Makefile.json @@ -12,6 +12,7 @@ "OBJS": [ "$(ENTRY)_harness.goto", + "$(FREERTOS_PLUS_TCP)/source/FreeRTOS_IP_Utils.goto", "$(FREERTOS_PLUS_TCP)/source/FreeRTOS_RA.goto" ], diff --git a/test/cbmc/proofs/Routing/MatchingEndpoint/MatchingEndpoint_harness.c b/test/cbmc/proofs/Routing/MatchingEndpoint/MatchingEndpoint_harness.c index dbcde05c02..1496562b1b 100644 --- a/test/cbmc/proofs/Routing/MatchingEndpoint/MatchingEndpoint_harness.c +++ b/test/cbmc/proofs/Routing/MatchingEndpoint/MatchingEndpoint_harness.c @@ -39,6 +39,16 @@ #include "../../utility/memory_assignments.c" #include "cbmc.h" +/* Abstraction of xIsIPv6Loopback returns either true or false. */ +BaseType_t xIsIPv6Loopback( const IPv6_Address_t * pxAddress ) +{ + BaseType_t xReturn; + + __CPROVER_assume( xReturn == pdTRUE || xReturn == pdFALSE ); + + return xReturn; +} + void harness() { NetworkInterface_t * pxNetworkInterface = safeMalloc( sizeof( NetworkInterface_t ) ); diff --git a/test/cbmc/proofs/Socket/lTCPAddRxdata/TCPAddRxdata_harness.c b/test/cbmc/proofs/Socket/lTCPAddRxdata/TCPAddRxdata_harness.c index fb73ca397d..123b945277 100644 --- a/test/cbmc/proofs/Socket/lTCPAddRxdata/TCPAddRxdata_harness.c +++ b/test/cbmc/proofs/Socket/lTCPAddRxdata/TCPAddRxdata_harness.c @@ -34,11 +34,45 @@ void * pvPortMallocLarge( size_t xWantedSize ) return safeMalloc( xWantedSize ); } +size_t uxStreamBufferFrontSpace( const StreamBuffer_t * const pxBuffer ) +{ + size_t uxReturn; + + return uxReturn; +} + +BaseType_t xSendEventToIPTask( eIPEvent_t eEvent ) +{ + BaseType_t xReturn; + + __CPROVER_assume( ( xReturn == pdTRUE ) || ( xReturn == pdFALSE ) ); + + return xReturn; +} + +void vTCPStateChange( FreeRTOS_Socket_t * pxSocket, + enum eTCP_STATE eTCPState ) +{ +} + +size_t uxStreamBufferAdd( StreamBuffer_t * const pxBuffer, + size_t uxOffset, + const uint8_t * const pucData, + size_t uxByteCount ) +{ + size_t uxReturn; + + __CPROVER_assert( __CPROVER_r_ok( pucData, uxByteCount ), "Data pointer must be valid to read" ); + __CPROVER_assume( uxReturn <= uxByteCount ); + + return uxReturn; +} + void harness() { - FreeRTOS_Socket_t * pxSocket = ensure_FreeRTOS_Socket_t_is_allocated( sizeof( FreeRTOS_Socket_t ) ); + FreeRTOS_Socket_t * pxSocket = ensure_FreeRTOS_Socket_t_is_allocated(); size_t uxOffset; - const uint8_t * pcData; + const uint8_t * pcData = NULL; uint32_t ulByteCount; /* This function expect socket to be not NULL, as it has been validated previously */ @@ -48,7 +82,9 @@ void harness() __CPROVER_assume( pxSocket->u.xTCP.uxRxStreamSize >= 0 && pxSocket->u.xTCP.uxRxStreamSize < ipconfigTCP_RX_BUFFER_LENGTH ); __CPROVER_assume( pxSocket->u.xTCP.uxTxStreamSize >= 0 && pxSocket->u.xTCP.uxTxStreamSize < ipconfigTCP_TX_BUFFER_LENGTH ); + __CPROVER_assume( ulByteCount > 0U ); pcData = safeMalloc( ulByteCount ); + __CPROVER_assume( pcData != NULL ); lTCPAddRxdata( pxSocket, uxOffset, pcData, ulByteCount ); } diff --git a/test/cbmc/proofs/Socket/vSocketBind/ALLOW_ETHERNET_DRIVER_FILTERS_PACKETS/Makefile.json b/test/cbmc/proofs/Socket/vSocketBind/ALLOW_ETHERNET_DRIVER_FILTERS_PACKETS/Makefile.json index 379ae7a399..336e6d2ece 100644 --- a/test/cbmc/proofs/Socket/vSocketBind/ALLOW_ETHERNET_DRIVER_FILTERS_PACKETS/Makefile.json +++ b/test/cbmc/proofs/Socket/vSocketBind/ALLOW_ETHERNET_DRIVER_FILTERS_PACKETS/Makefile.json @@ -13,7 +13,8 @@ "$(FREERTOS_PLUS_TCP)/test/FreeRTOS-Kernel/list.goto", "$(FREERTOS_PLUS_TCP)/source/FreeRTOS_Routing.goto", "$(FREERTOS_PLUS_TCP)/source/FreeRTOS_Sockets.goto", - "$(ENTRY)_harness.goto" + "$(ENTRY)_harness.goto", + "$(FREERTOS_PLUS_TCP)/test/cbmc/stubs/freertos_kernel_api.goto" ], "INSTFLAGS": [ diff --git a/test/cbmc/proofs/Socket/vSocketClose/Configurations.json b/test/cbmc/proofs/Socket/vSocketClose/Configurations.json index 50df094177..f36f3dc532 100644 --- a/test/cbmc/proofs/Socket/vSocketClose/Configurations.json +++ b/test/cbmc/proofs/Socket/vSocketClose/Configurations.json @@ -9,6 +9,7 @@ [ "$(FREERTOS_PLUS_TCP)/test/FreeRTOS-Kernel/list.goto", "$(FREERTOS_PLUS_TCP)/source/FreeRTOS_Sockets.goto", + "$(FREERTOS_PLUS_TCP)/test/cbmc/stubs/freertos_kernel_api.goto", "$(ENTRY)_harness.goto" ], "DEF": diff --git a/test/cbmc/proofs/TCP/prvHandleListen/Makefile.json b/test/cbmc/proofs/TCP/prvHandleListen/Makefile.json index 856e50c30c..ab47b60c1b 100644 --- a/test/cbmc/proofs/TCP/prvHandleListen/Makefile.json +++ b/test/cbmc/proofs/TCP/prvHandleListen/Makefile.json @@ -9,6 +9,7 @@ [ "$(ENTRY)_harness.goto", "$(FREERTOS_PLUS_TCP)/test/cbmc/stubs/cbmc.goto", + "$(FREERTOS_PLUS_TCP)/test/cbmc/stubs/freertos_api.goto", "$(FREERTOS_PLUS_TCP)/source/FreeRTOS_TCP_State_Handling.goto", "$(FREERTOS_PLUS_TCP)/source/FreeRTOS_TCP_State_Handling_IPv4.goto" ], @@ -19,7 +20,6 @@ ], "INSTFLAGS": [ - "--remove-function-body prvTCPSendReset" ], "INC": [ diff --git a/test/cbmc/proofs/TCP/prvHandleListen/prvHandleListen_harness.c b/test/cbmc/proofs/TCP/prvHandleListen/prvHandleListen_harness.c index a742293721..3fa5aadd81 100644 --- a/test/cbmc/proofs/TCP/prvHandleListen/prvHandleListen_harness.c +++ b/test/cbmc/proofs/TCP/prvHandleListen/prvHandleListen_harness.c @@ -53,6 +53,66 @@ Socket_t FreeRTOS_socket( BaseType_t xDomain, return ensure_FreeRTOS_Socket_t_is_allocated(); } +BaseType_t vSocketBind( FreeRTOS_Socket_t * pxSocket, + struct freertos_sockaddr * pxBindAddress, + size_t uxAddressLength, + BaseType_t xInternal ) +{ + BaseType_t xRet; + + __CPROVER_assert( pxSocket != NULL, + "FreeRTOS precondition: pxSocket != NULL" ); + __CPROVER_assert( pxBindAddress != NULL, + "FreeRTOS precondition: pxBindAddress != NULL" ); + + return xRet; +} + +void * vSocketClose( FreeRTOS_Socket_t * pxSocket ) +{ + __CPROVER_assert( pxSocket != NULL, "Closing socket cannot be NULL" ); + + return NULL; +} + +BaseType_t prvTCPSendReset( NetworkBufferDescriptor_t * pxNetworkBuffer ) +{ + BaseType_t xReturn; + + __CPROVER_assume( ( xReturn == pdTRUE ) || ( xReturn == pdFALSE ) ); + + return xReturn; +} + +void vTCPStateChange( FreeRTOS_Socket_t * pxSocket, + enum eTCP_STATE eTCPState ) +{ +} + +BaseType_t prvTCPCreateWindow( FreeRTOS_Socket_t * pxSocket ) +{ + BaseType_t xReturn; + + __CPROVER_assume( ( xReturn == pdTRUE ) || ( xReturn == pdFALSE ) ); + + return xReturn; +} + +void prvSocketSetMSS( FreeRTOS_Socket_t * pxSocket ) +{ + __CPROVER_assert( pxSocket != NULL, "pxSocket cannot be NULL" ); +} + +size_t FreeRTOS_GetLocalAddress( ConstSocket_t xSocket, + struct freertos_sockaddr * pxAddress ) +{ + size_t uxReturn; + + __CPROVER_assert( pxAddress != NULL, "pxAddress cannot be NULL" ); + + return uxReturn; +} + void harness() { size_t xDataLength; diff --git a/test/cbmc/proofs/TCP/prvHandleListen_IPv6/Makefile.json b/test/cbmc/proofs/TCP/prvHandleListen_IPv6/Makefile.json index aa1ee4f706..b824b9a396 100644 --- a/test/cbmc/proofs/TCP/prvHandleListen_IPv6/Makefile.json +++ b/test/cbmc/proofs/TCP/prvHandleListen_IPv6/Makefile.json @@ -11,6 +11,7 @@ [ "$(ENTRY)_harness.goto", "$(FREERTOS_PLUS_TCP)/test/cbmc/stubs/cbmc.goto", + "$(FREERTOS_PLUS_TCP)/test/cbmc/stubs/freertos_api.goto", "$(FREERTOS_PLUS_TCP)/source/FreeRTOS_TCP_State_Handling.goto", "$(FREERTOS_PLUS_TCP)/source/FreeRTOS_TCP_State_Handling_IPv6.goto" ], @@ -21,7 +22,6 @@ ], "INSTFLAGS": [ - "--remove-function-body prvTCPSendReset" ], "INC": [ diff --git a/test/cbmc/proofs/TCP/prvHandleListen_IPv6/prvHandleListen_IPv6_harness.c b/test/cbmc/proofs/TCP/prvHandleListen_IPv6/prvHandleListen_IPv6_harness.c index 5134b5bca1..8be5891f9c 100644 --- a/test/cbmc/proofs/TCP/prvHandleListen_IPv6/prvHandleListen_IPv6_harness.c +++ b/test/cbmc/proofs/TCP/prvHandleListen_IPv6/prvHandleListen_IPv6_harness.c @@ -53,6 +53,66 @@ Socket_t FreeRTOS_socket( BaseType_t xDomain, return ensure_FreeRTOS_Socket_t_is_allocated(); } +BaseType_t vSocketBind( FreeRTOS_Socket_t * pxSocket, + struct freertos_sockaddr * pxBindAddress, + size_t uxAddressLength, + BaseType_t xInternal ) +{ + BaseType_t xRet; + + __CPROVER_assert( pxSocket != NULL, + "FreeRTOS precondition: pxSocket != NULL" ); + __CPROVER_assert( pxBindAddress != NULL, + "FreeRTOS precondition: pxBindAddress != NULL" ); + + return xRet; +} + +void * vSocketClose( FreeRTOS_Socket_t * pxSocket ) +{ + __CPROVER_assert( pxSocket != NULL, "Closing socket cannot be NULL" ); + + return NULL; +} + +void prvSocketSetMSS( FreeRTOS_Socket_t * pxSocket ) +{ + __CPROVER_assert( pxSocket != NULL, "pxSocket cannot be NULL" ); +} + +BaseType_t prvTCPSendReset( NetworkBufferDescriptor_t * pxNetworkBuffer ) +{ + BaseType_t xReturn; + + __CPROVER_assume( ( xReturn == pdTRUE ) || ( xReturn == pdFALSE ) ); + + return xReturn; +} + +void vTCPStateChange( FreeRTOS_Socket_t * pxSocket, + enum eTCP_STATE eTCPState ) +{ +} + +BaseType_t prvTCPCreateWindow( FreeRTOS_Socket_t * pxSocket ) +{ + BaseType_t xReturn; + + __CPROVER_assume( ( xReturn == pdTRUE ) || ( xReturn == pdFALSE ) ); + + return xReturn; +} + +size_t FreeRTOS_GetLocalAddress( ConstSocket_t xSocket, + struct freertos_sockaddr * pxAddress ) +{ + size_t uxReturn; + + __CPROVER_assert( pxAddress != NULL, "pxAddress cannot be NULL" ); + + return uxReturn; +} + void harness() { size_t xDataLength; diff --git a/test/cbmc/proofs/TCP/prvSendData/Makefile.json b/test/cbmc/proofs/TCP/prvSendData/Makefile.json index cfc73e67ea..f8b8a29f1d 100644 --- a/test/cbmc/proofs/TCP/prvSendData/Makefile.json +++ b/test/cbmc/proofs/TCP/prvSendData/Makefile.json @@ -8,7 +8,8 @@ "OBJS": [ "$(ENTRY)_harness.goto", - "$(FREERTOS_PLUS_TCP)/source/FreeRTOS_TCP_Transmission.goto" + "$(FREERTOS_PLUS_TCP)/source/FreeRTOS_TCP_Transmission.goto", + "$(FREERTOS_PLUS_TCP)/test/cbmc/stubs/cbmc.goto" ], "INC": [ diff --git a/test/cbmc/proofs/TCP/prvSendData/SendData_harness.c b/test/cbmc/proofs/TCP/prvSendData/SendData_harness.c index 83da8405bb..1f76a23fcd 100644 --- a/test/cbmc/proofs/TCP/prvSendData/SendData_harness.c +++ b/test/cbmc/proofs/TCP/prvSendData/SendData_harness.c @@ -36,7 +36,7 @@ #include "FreeRTOS_TCP_IP.h" /* CBMC includes. */ -#include "../../utility/memory_assignments.c" +#include "cbmc.h" /**************************************************************** * Declare the IP Header Size external to the harness so it can be @@ -52,15 +52,75 @@ size_t uxIPHeaderSizePacket( const NetworkBufferDescriptor_t * pxNetworkBuffer ) return uxIPHeaderSizePacket_uxResult; } +void prvTCPReturnPacket( FreeRTOS_Socket_t * pxSocket, + NetworkBufferDescriptor_t * pxDescriptor, + uint32_t ulLen, + BaseType_t xReleaseAfterSend ) +{ + __CPROVER_assert( pxSocket != NULL, "pxSocket should not be NULL" ); + __CPROVER_assert( pxDescriptor != NULL, "pxDescriptor should not be NULL" ); + __CPROVER_assert( pxDescriptor->pucEthernetBuffer != NULL, "pucEthernetBuffer should not be NULL" ); +} + +void prvTCPReturnPacket_IPV4( FreeRTOS_Socket_t * pxSocket, + NetworkBufferDescriptor_t * pxDescriptor, + uint32_t ulLen, + BaseType_t xReleaseAfterSend ) +{ + __CPROVER_assert( pxSocket != NULL, "pxSocket should not be NULL" ); + __CPROVER_assert( pxDescriptor != NULL, "pxDescriptor should not be NULL" ); + __CPROVER_assert( pxDescriptor->pucEthernetBuffer != NULL, "pucEthernetBuffer should not be NULL" ); +} + +/* Memory assignment for FreeRTOS_Socket_t */ +FreeRTOS_Socket_t * ensure_FreeRTOS_Socket_t_is_allocated() +{ + size_t buf_size; /* Give buffer_size an unconstrained value */ + FreeRTOS_Socket_t * pxSocket = safeMalloc( sizeof( FreeRTOS_Socket_t ) ); + + __CPROVER_assume( pxSocket != NULL ); + pxSocket->u.xTCP.rxStream = safeMalloc( sizeof( StreamBuffer_t ) ); + pxSocket->u.xTCP.txStream = safeMalloc( sizeof( StreamBuffer_t ) ); + pxSocket->u.xTCP.pxPeerSocket = safeMalloc( sizeof( FreeRTOS_Socket_t ) ); + pxSocket->pxEndPoint = safeMalloc( sizeof( NetworkEndPoint_t ) ); + pxSocket->u.xTCP.pxAckMessage = safeMalloc( sizeof( NetworkBufferDescriptor_t ) ); + + if( pxSocket->u.xTCP.pxAckMessage != NULL ) + { + __CPROVER_assume( ( buf_size > ( ipSIZE_OF_ETH_HEADER + ipSIZE_OF_IPv6_HEADER + sizeof( TCPHeader_t ) ) ) && ( buf_size < ipconfigNETWORK_MTU ) ); + pxSocket->u.xTCP.pxAckMessage->pucEthernetBuffer = safeMalloc( buf_size ); + __CPROVER_assume( pxSocket->u.xTCP.pxAckMessage->pucEthernetBuffer != NULL ); + } + + return pxSocket; +} + +/* + * In this function, it only allocates network buffer by harness. + */ +void vReleaseNetworkBufferAndDescriptor( NetworkBufferDescriptor_t * const pxNetworkBuffer ) +{ + __CPROVER_assert( pxNetworkBuffer != NULL, + "Precondition: pxNetworkBuffer != NULL" ); + + if( pxNetworkBuffer->pucEthernetBuffer != NULL ) + { + free( pxNetworkBuffer->pucEthernetBuffer ); + } + + free( pxNetworkBuffer ); +} + void harness() { FreeRTOS_Socket_t * pxSocket = ensure_FreeRTOS_Socket_t_is_allocated(); - NetworkBufferDescriptor_t * pxNetworkBuffer = ensure_FreeRTOS_NetworkBuffer_is_allocated(); + NetworkBufferDescriptor_t * pxNetworkBuffer; uint32_t ulReceiveLength; BaseType_t xByteCount; size_t buf_size; /* Give buffer_size an unconstrained value */ /* The code does not expect pxSocket/pxNetworkBuffer to be equal to NULL. */ + pxNetworkBuffer = safeMalloc( sizeof( NetworkBufferDescriptor_t ) ); __CPROVER_assume( pxSocket != NULL ); __CPROVER_assume( pxNetworkBuffer != NULL ); @@ -73,7 +133,7 @@ void harness() uxIPHeaderSizePacket_uxResult = ipSIZE_OF_IPv4_HEADER; } - __CPROVER_assume( buf_size > ( ipSIZE_OF_ETH_HEADER + uxIPHeaderSizePacket_uxResult + sizeof( TCPHeader_t ) ) ); + __CPROVER_assume( ( buf_size > ( ipSIZE_OF_ETH_HEADER + uxIPHeaderSizePacket_uxResult + sizeof( TCPHeader_t ) ) ) && ( buf_size < ipconfigNETWORK_MTU ) ); pxNetworkBuffer->pucEthernetBuffer = safeMalloc( buf_size ); __CPROVER_assume( pxNetworkBuffer->pucEthernetBuffer != NULL ); diff --git a/test/cbmc/proofs/TCP/prvTCPHandleState/Makefile.json b/test/cbmc/proofs/TCP/prvTCPHandleState/Makefile.json index a192cca2df..bc6f29b9c1 100644 --- a/test/cbmc/proofs/TCP/prvTCPHandleState/Makefile.json +++ b/test/cbmc/proofs/TCP/prvTCPHandleState/Makefile.json @@ -39,23 +39,27 @@ "OBJS": [ "$(ENTRY)_harness.goto", + "$(FREERTOS_PLUS_TCP)/test/FreeRTOS-Kernel/list.goto", "$(FREERTOS_PLUS_TCP)/source/FreeRTOS_TCP_IP.goto", "$(FREERTOS_PLUS_TCP)/source/FreeRTOS_TCP_State_Handling.goto", "$(FREERTOS_PLUS_TCP)/source/FreeRTOS_TCP_Reception.goto", "$(FREERTOS_PLUS_TCP)/source/FreeRTOS_IP.goto", "$(FREERTOS_PLUS_TCP)/source/FreeRTOS_IP_Utils.goto", - "$(FREERTOS_PLUS_TCP)/source/FreeRTOS_IP_Timers.goto" + "$(FREERTOS_PLUS_TCP)/source/FreeRTOS_IP_Timers.goto", + "$(FREERTOS_PLUS_TCP)/test/cbmc/stubs/cbmc.goto", + "$(FREERTOS_PLUS_TCP)/test/cbmc/stubs/freertos_api.goto", + "$(FREERTOS_PLUS_TCP)/test/cbmc/stubs/freertos_kernel_api.goto" ], "DEF": [ + "ipconfigUSE_TCP=1", "ipconfigZERO_COPY_TX_DRIVER={TX_DRIVER}", "ipconfigUSE_LINKED_RX_MESSAGES={RX_MESSAGES}", - "FREERTOS_TCP_ENABLE_VERIFICATION" + "FREERTOS_TCP_ENABLE_VERIFICATION", + "ipconfigNETWORK_MTU=586" ], "INSTFLAGS": [ - "--remove-function-body prvTCPPrepareSend", - "--remove-function-body prvTCPReturnPacket" ], "INC": [ diff --git a/test/cbmc/proofs/TCP/prvTCPHandleState/TCPHandleState_harness.c b/test/cbmc/proofs/TCP/prvTCPHandleState/TCPHandleState_harness.c index 199d032716..c73802300d 100644 --- a/test/cbmc/proofs/TCP/prvTCPHandleState/TCPHandleState_harness.c +++ b/test/cbmc/proofs/TCP/prvTCPHandleState/TCPHandleState_harness.c @@ -35,7 +35,8 @@ #include "FreeRTOS_IP_Private.h" #include "FreeRTOS_TCP_IP.h" -#include "../../utility/memory_assignments.c" +/* CBMC includes. */ +#include "cbmc.h" extern FreeRTOS_Socket_t * xSocketToListen; @@ -61,47 +62,225 @@ TaskHandle_t xTaskGetCurrentTaskHandle( void ) BaseType_t publicTCPHandleState( FreeRTOS_Socket_t * pxSocket, NetworkBufferDescriptor_t ** ppxNetworkBuffer ); +void * vSocketClose( FreeRTOS_Socket_t * pxSocket ) +{ + __CPROVER_assert( pxSocket != NULL, "Closing socket cannot be NULL." ); + + return NULL; +} + +void vSocketWakeUpUser( FreeRTOS_Socket_t * pxSocket ) +{ + __CPROVER_assert( pxSocket != NULL, "Closing socket cannot be NULL." ); + + return NULL; +} + +/* Memory assignment for FreeRTOS_Socket_t */ +FreeRTOS_Socket_t * ensure_FreeRTOS_Socket_t_is_allocated() +{ + size_t buf_size; /* Give buffer_size an unconstrained value */ + FreeRTOS_Socket_t * pxSocket = safeMalloc( sizeof( FreeRTOS_Socket_t ) ); + + __CPROVER_assume( pxSocket != NULL ); + pxSocket->u.xTCP.rxStream = safeMalloc( sizeof( StreamBuffer_t ) ); + pxSocket->u.xTCP.txStream = safeMalloc( sizeof( StreamBuffer_t ) ); + pxSocket->u.xTCP.pxPeerSocket = safeMalloc( sizeof( FreeRTOS_Socket_t ) ); + pxSocket->pxEndPoint = safeMalloc( sizeof( NetworkEndPoint_t ) ); + pxSocket->u.xTCP.pxAckMessage = safeMalloc( sizeof( NetworkBufferDescriptor_t ) ); + + if( pxSocket->u.xTCP.pxAckMessage != NULL ) + { + __CPROVER_assume( ( buf_size > ( ipSIZE_OF_ETH_HEADER + ipSIZE_OF_IPv6_HEADER + sizeof( TCPHeader_t ) ) ) && ( buf_size < ipconfigNETWORK_MTU ) ); + pxSocket->u.xTCP.pxAckMessage->pucEthernetBuffer = safeMalloc( buf_size ); + __CPROVER_assume( pxSocket->u.xTCP.pxAckMessage->pucEthernetBuffer != NULL ); + } + + return pxSocket; +} + +/* lTCPAddRxdata is proven separately. */ +int32_t lTCPAddRxdata( FreeRTOS_Socket_t * pxSocket, + size_t uxOffset, + const uint8_t * pcData, + uint32_t ulByteCount ) +{ + return nondet_int32(); +} + +/* prvSendData is proven separately. */ +BaseType_t prvSendData( FreeRTOS_Socket_t * pxSocket, + NetworkBufferDescriptor_t ** ppxNetworkBuffer, + uint32_t ulReceiveLength, + BaseType_t xByteCount ) +{ + __CPROVER_assert( pxSocket != NULL, "pxSocket cannot be NULL" ); + __CPROVER_assert( *ppxNetworkBuffer != NULL, "*ppxNetworkBuffer cannot be NULL" ); + + return nondet_BaseType(); +} + +/* prvTCPPrepareSend is proven separately. */ +int32_t prvTCPPrepareSend( FreeRTOS_Socket_t * pxSocket, + NetworkBufferDescriptor_t ** ppxNetworkBuffer, + UBaseType_t uxOptionsLength ) +{ + __CPROVER_assert( pxSocket != NULL, "pxSocket cannot be NULL" ); + __CPROVER_assert( *ppxNetworkBuffer != NULL, "*ppxNetworkBuffer cannot be NULL" ); + + return nondet_int32(); +} + +/* Mock all window APIs */ +int32_t lTCPWindowRxCheck( TCPWindow_t * pxWindow, + uint32_t ulSequenceNumber, + uint32_t ulLength, + uint32_t ulSpace, + uint32_t * pulSkipCount ) +{ + __CPROVER_assert( pxWindow != NULL, "pxWindow cannot be NULL" ); + __CPROVER_assert( __CPROVER_r_ok( pxWindow, sizeof( TCPWindow_t ) ), "pxWindow must be readable" ); + *pulSkipCount = nondet_uint32(); + + return nondet_int32(); +} + +uint32_t ulTCPWindowTxAck( TCPWindow_t * pxWindow, + uint32_t ulSequenceNumber ) +{ + __CPROVER_assert( pxWindow != NULL, "pxWindow cannot be NULL" ); + __CPROVER_assert( __CPROVER_r_ok( pxWindow, sizeof( TCPWindow_t ) ), "pxWindow must be readable" ); + + return nondet_uint32(); +} + +void vTCPWindowInit( TCPWindow_t * pxWindow, + uint32_t ulAckNumber, + uint32_t ulSequenceNumber, + uint32_t ulMSS ) +{ + __CPROVER_assert( pxWindow != NULL, "pxWindow cannot be NULL" ); + __CPROVER_assert( __CPROVER_r_ok( pxWindow, sizeof( TCPWindow_t ) ), "pxWindow must be readable" ); +} + +BaseType_t xTCPWindowRxEmpty( const TCPWindow_t * pxWindow ) +{ + __CPROVER_assert( pxWindow != NULL, "pxWindow cannot be NULL" ); + __CPROVER_assert( __CPROVER_r_ok( pxWindow, sizeof( TCPWindow_t ) ), "pxWindow must be readable" ); + + return nondet_BaseType(); +} + +BaseType_t xTCPWindowTxDone( const TCPWindow_t * pxWindow ) +{ + __CPROVER_assert( pxWindow != NULL, "pxWindow cannot be NULL" ); + __CPROVER_assert( __CPROVER_r_ok( pxWindow, sizeof( TCPWindow_t ) ), "pxWindow must be readable" ); + + return nondet_BaseType(); +} + +/* Mock all stream buffer APIs */ +size_t uxStreamBufferGet( StreamBuffer_t * const pxBuffer, + size_t uxOffset, + uint8_t * const pucData, + size_t uxMaxCount, + BaseType_t xPeek ) +{ + __CPROVER_assert( pxBuffer != NULL, "pxBuffer cannot be NULL" ); + + return nondet_sizet(); +} + +size_t uxStreamBufferGetSpace( const StreamBuffer_t * const pxBuffer ) +{ + __CPROVER_assert( pxBuffer != NULL, "pxBuffer cannot be NULL" ); + + return nondet_sizet(); +} + +/* Mock all transmission APIs. */ +UBaseType_t prvSetOptions( FreeRTOS_Socket_t * pxSocket, + const NetworkBufferDescriptor_t * pxNetworkBuffer ) +{ + __CPROVER_assert( pxSocket != NULL, "pxSocket cannot be NULL" ); + __CPROVER_assert( pxNetworkBuffer != NULL, "pxNetworkBuffer cannot be NULL" ); + + return nondet_ubasetype(); +} + +UBaseType_t prvSetSynAckOptions( FreeRTOS_Socket_t * pxSocket, + TCPHeader_t * pxTCPHeader ) +{ + __CPROVER_assert( pxSocket != NULL, "pxSocket cannot be NULL" ); + __CPROVER_assert( pxTCPHeader != NULL, "pxTCPHeader cannot be NULL" ); + + return nondet_ubasetype(); +} + +void prvTCPAddTxData( FreeRTOS_Socket_t * pxSocket ) +{ + __CPROVER_assert( pxSocket != NULL, "pxSocket cannot be NULL" ); +} + +BaseType_t prvTCPSendReset( NetworkBufferDescriptor_t * pxNetworkBuffer ) +{ + __CPROVER_assert( pxNetworkBuffer != NULL, "pxNetworkBuffer cannot be NULL" ); + + return nondet_BaseType(); +} + +const char * FreeRTOS_inet_ntop( BaseType_t xAddressFamily, + const void * pvSource, + char * pcDestination, + socklen_t uxSize ) +{ + __CPROVER_assert( __CPROVER_r_ok( pcDestination, uxSize ), "input buffer must be available" ); + + __CPROVER_assert( ( xAddressFamily == FREERTOS_AF_INET6 && __CPROVER_r_ok( pvSource, 16 ) ) || + ( xAddressFamily == FREERTOS_AF_INET && __CPROVER_r_ok( pvSource, 4 ) ), + "input address must be available" ); +} + void harness() { FreeRTOS_Socket_t * pxSocket = ensure_FreeRTOS_Socket_t_is_allocated(); - size_t socketSize = sizeof( FreeRTOS_Socket_t ); - if( ensure_memory_is_valid( pxSocket, socketSize ) ) + __CPROVER_assume( pxSocket != NULL ); + + /* ucOptionLength is the number of valid bytes in ulOptionsData[]. + * ulOptionsData[] is initialized as uint32_t ulOptionsData[ipSIZE_TCP_OPTIONS/sizeof(uint32_t)]. + * This assumption is required for a memcpy function that copies uxOptionsLength + * data from pxTCPHeader->ucOptdata to pxTCPWindow->ulOptionsData.*/ + __CPROVER_assume( pxSocket->u.xTCP.xTCPWindow.ucOptionLength == sizeof( uint32_t ) * ipSIZE_TCP_OPTIONS / sizeof( uint32_t ) ); + /* uxRxWinSize is initialized as size_t. This assumption is required to terminate `while(uxWinSize > 0xfffful)` loop.*/ + __CPROVER_assume( pxSocket->u.xTCP.uxRxWinSize >= 0 && pxSocket->u.xTCP.uxRxWinSize <= sizeof( size_t ) ); + /* uxRxWinSize is initialized as uint16_t. This assumption is required to terminate `while(uxWinSize > 0xfffful)` loop.*/ + __CPROVER_assume( pxSocket->u.xTCP.usMSS == sizeof( uint16_t ) ); + + if( xIsCallingFromIPTask() == pdFALSE ) { - /* ucOptionLength is the number of valid bytes in ulOptionsData[]. - * ulOptionsData[] is initialized as uint32_t ulOptionsData[ipSIZE_TCP_OPTIONS/sizeof(uint32_t)]. - * This assumption is required for a memcpy function that copies uxOptionsLength - * data from pxTCPHeader->ucOptdata to pxTCPWindow->ulOptionsData.*/ - __CPROVER_assume( pxSocket->u.xTCP.xTCPWindow.ucOptionLength == sizeof( uint32_t ) * ipSIZE_TCP_OPTIONS / sizeof( uint32_t ) ); - /* uxRxWinSize is initialized as size_t. This assumption is required to terminate `while(uxWinSize > 0xfffful)` loop.*/ - __CPROVER_assume( pxSocket->u.xTCP.uxRxWinSize >= 0 && pxSocket->u.xTCP.uxRxWinSize <= sizeof( size_t ) ); - /* uxRxWinSize is initialized as uint16_t. This assumption is required to terminate `while(uxWinSize > 0xfffful)` loop.*/ - __CPROVER_assume( pxSocket->u.xTCP.usMSS == sizeof( uint16_t ) ); - - if( xIsCallingFromIPTask() == pdFALSE ) - { - __CPROVER_assume( pxSocket->u.xTCP.bits.bPassQueued == pdFALSE_UNSIGNED ); - __CPROVER_assume( pxSocket->u.xTCP.bits.bPassAccept == pdFALSE_UNSIGNED ); - } + __CPROVER_assume( pxSocket->u.xTCP.bits.bPassQueued == pdFALSE_UNSIGNED ); + __CPROVER_assume( pxSocket->u.xTCP.bits.bPassAccept == pdFALSE_UNSIGNED ); } - NetworkBufferDescriptor_t * pxNetworkBuffer = ensure_FreeRTOS_NetworkBuffer_is_allocated(); - size_t bufferSize = sizeof( NetworkBufferDescriptor_t ); + NetworkBufferDescriptor_t * pxNetworkBuffer = safeMalloc( sizeof( NetworkBufferDescriptor_t ) ); + __CPROVER_assume( pxNetworkBuffer != NULL ); FreeRTOS_Socket_t xSck; xSocketToListen = &xSck; - if( ensure_memory_is_valid( pxNetworkBuffer, bufferSize ) ) - { - /* Allocates min. buffer size required for the proof */ - pxNetworkBuffer->pucEthernetBuffer = safeMalloc( sizeof( TCPPacket_t ) + uxIPHeaderSizeSocket( pxSocket ) ); - } + /* Call to init the socket list. */ + vListInitialise( &xBoundTCPSocketsList ); - if( ensure_memory_is_valid( pxSocket, socketSize ) && - ensure_memory_is_valid( pxNetworkBuffer, bufferSize ) && - ensure_memory_is_valid( pxNetworkBuffer->pucEthernetBuffer, sizeof( TCPPacket_t ) ) && - ensure_memory_is_valid( pxSocket->u.xTCP.pxPeerSocket, socketSize ) ) + /* Allocates min. buffer size required for the proof */ + pxNetworkBuffer->pucEthernetBuffer = safeMalloc( sizeof( TCPPacket_t ) + uxIPHeaderSizeSocket( pxSocket ) ); + __CPROVER_assume( pxNetworkBuffer->pucEthernetBuffer != NULL ); + + if( pxSocket->u.xTCP.bits.bReuseSocket == pdFALSE ) { - publicTCPHandleState( pxSocket, &pxNetworkBuffer ); + /* Make sure we have parent socket if reuse is set to FALSE to avoid assertion in vTCPStateChange(). */ + __CPROVER_assume( pxSocket->u.xTCP.pxPeerSocket != NULL ); } + + publicTCPHandleState( pxSocket, &pxNetworkBuffer ); } diff --git a/test/cbmc/proofs/TCP/prvTCPPrepareSend/Makefile.json b/test/cbmc/proofs/TCP/prvTCPPrepareSend/Makefile.json index 97cbf2b02d..e1dd2fdf05 100644 --- a/test/cbmc/proofs/TCP/prvTCPPrepareSend/Makefile.json +++ b/test/cbmc/proofs/TCP/prvTCPPrepareSend/Makefile.json @@ -31,18 +31,28 @@ "CBMCFLAGS": [ "--unwind 1", + "--unwindset __CPROVER_file_local_FreeRTOS_TCP_IP_c_vTCPRemoveTCPChild.0:1", "--nondet-static" ], "OBJS": [ "$(ENTRY)_harness.goto", + "$(FREERTOS_PLUS_TCP)/test/FreeRTOS-Kernel/list.goto", "$(FREERTOS_PLUS_TCP)/source/FreeRTOS_IP.goto", "$(FREERTOS_PLUS_TCP)/source/FreeRTOS_TCP_IP.goto", - "$(FREERTOS_PLUS_TCP)/source/FreeRTOS_TCP_Transmission.goto" + "$(FREERTOS_PLUS_TCP)/source/FreeRTOS_TCP_Transmission.goto", + "$(FREERTOS_PLUS_TCP)/test/cbmc/stubs/freertos_kernel_api.goto", + "$(FREERTOS_PLUS_TCP)/test/cbmc/stubs/freertos_api.goto", + "$(FREERTOS_PLUS_TCP)/test/cbmc/stubs/cbmc.goto" + ], + "OPT": + [ + "--export-file-local-symbols" ], "DEF": [ - "FREERTOS_TCP_ENABLE_VERIFICATION" + "FREERTOS_TCP_ENABLE_VERIFICATION", + "CBMC_REQUIRE_NETWORKBUFFER_ETHERNETBUFFER_NONNULL" ], "INC": [ diff --git a/test/cbmc/proofs/TCP/prvTCPPrepareSend/TCPPrepareSend_harness.c b/test/cbmc/proofs/TCP/prvTCPPrepareSend/TCPPrepareSend_harness.c index 06e6e7d9ab..63bfac2799 100644 --- a/test/cbmc/proofs/TCP/prvTCPPrepareSend/TCPPrepareSend_harness.c +++ b/test/cbmc/proofs/TCP/prvTCPPrepareSend/TCPPrepareSend_harness.c @@ -36,30 +36,35 @@ #include "FreeRTOS_TCP_IP.h" #include "FreeRTOS_Stream_Buffer.h" -#include "../../utility/memory_assignments.c" +/* CBMC includes. */ +#include "cbmc.h" /* This proof assumes that pxGetNetworkBufferWithDescriptor is implemented correctly. */ int32_t publicTCPPrepareSend( FreeRTOS_Socket_t * pxSocket, NetworkBufferDescriptor_t ** ppxNetworkBuffer, UBaseType_t uxOptionsLength ); -/* Abstraction of pxGetNetworkBufferWithDescriptor. It creates a buffer. */ -NetworkBufferDescriptor_t * pxGetNetworkBufferWithDescriptor( size_t xRequestedSizeBytes, - TickType_t xBlockTimeTicks ) +/* Memory assignment for FreeRTOS_Socket_t */ +FreeRTOS_Socket_t * ensure_FreeRTOS_Socket_t_is_allocated() { - NetworkBufferDescriptor_t * pxBuffer = ensure_FreeRTOS_NetworkBuffer_is_allocated(); - size_t bufferSize = sizeof( NetworkBufferDescriptor_t ); + size_t buf_size; /* Give buffer_size an unconstrained value */ + FreeRTOS_Socket_t * pxSocket = safeMalloc( sizeof( FreeRTOS_Socket_t ) + sizeof( IPTCPSocket_t ) ); - if( ensure_memory_is_valid( pxBuffer, bufferSize ) ) + __CPROVER_assume( pxSocket != NULL ); + pxSocket->u.xTCP.rxStream = safeMalloc( sizeof( StreamBuffer_t ) ); + pxSocket->u.xTCP.txStream = safeMalloc( sizeof( StreamBuffer_t ) ); + pxSocket->u.xTCP.pxPeerSocket = safeMalloc( sizeof( FreeRTOS_Socket_t ) ); + pxSocket->pxEndPoint = safeMalloc( sizeof( NetworkEndPoint_t ) ); + pxSocket->u.xTCP.pxAckMessage = safeMalloc( sizeof( NetworkBufferDescriptor_t ) ); + + if( pxSocket->u.xTCP.pxAckMessage != NULL ) { - /* The code does not expect pucEthernetBuffer to be equal to NULL if - * pxBuffer is not NULL. */ - pxBuffer->pucEthernetBuffer = malloc( xRequestedSizeBytes ); - __CPROVER_assume( pxBuffer->pucEthernetBuffer != NULL ); - pxBuffer->xDataLength = xRequestedSizeBytes; + __CPROVER_assume( ( buf_size > ( ipSIZE_OF_ETH_HEADER + ipSIZE_OF_IPv6_HEADER + sizeof( TCPHeader_t ) ) ) && ( buf_size < ipconfigNETWORK_MTU ) ); + pxSocket->u.xTCP.pxAckMessage->pucEthernetBuffer = safeMalloc( buf_size ); + __CPROVER_assume( pxSocket->u.xTCP.pxAckMessage->pucEthernetBuffer != NULL ); } - return pxBuffer; + return pxSocket; } /* Get rid of configASSERT in FreeRTOS_TCP_IP.c */ @@ -68,34 +73,94 @@ BaseType_t xIsCallingFromIPTask( void ) return pdTRUE; } -void harness() +/* Mock FreeRTOS_TCP_State_Handling.h APIs */ +BaseType_t prvTCPSocketIsActive( eIPTCPState_t eStatus ) { - FreeRTOS_Socket_t * pxSocket = malloc( sizeof( FreeRTOS_Socket_t ) ); + return nondet_BaseType(); +} - __CPROVER_assume( pxSocket != NULL ); - pxSocket->u.xTCP.rxStream = malloc( sizeof( StreamBuffer_t ) ); - pxSocket->u.xTCP.txStream = malloc( sizeof( StreamBuffer_t ) ); - pxSocket->u.xTCP.pxPeerSocket = malloc( sizeof( FreeRTOS_Socket_t ) ); +/* Mock FreeRTOS_TCP_WIN.h APIs */ +BaseType_t xTCPWindowTxDone( const TCPWindow_t * pxWindow ) +{ + __CPROVER_assert( pxWindow != NULL, "pxWindow cannot be NULL" ); + return nondet_uint32(); +} + +uint32_t ulTCPWindowTxGet( TCPWindow_t * pxWindow, + uint32_t ulWindowSize, + int32_t * plPosition ) +{ + uint32_t ulReturn = nondet_uint32(); - NetworkBufferDescriptor_t * pxNetworkBuffer = ensure_FreeRTOS_NetworkBuffer_is_allocated(); + __CPROVER_assert( pxWindow != NULL, "pxWindow cannot be NULL" ); + __CPROVER_assert( plPosition != NULL, "plPosition cannot be NULL" ); + + /* This function returns the data length of next sending window, which is never larger than network MTU. */ + __CPROVER_assume( ulReturn < ipconfigNETWORK_MTU ); + return ulReturn; +} + +/* Mock FreeRTOS_Stream_Buffers.h APIs */ +size_t uxStreamBufferDistance( const StreamBuffer_t * const pxBuffer, + size_t uxLower, + size_t uxUpper ) +{ + __CPROVER_assert( pxBuffer != NULL, "pxBuffer cannot be NULL" ); + return nondet_sizet(); +} + +size_t uxStreamBufferGet( StreamBuffer_t * const pxBuffer, + size_t uxOffset, + uint8_t * const pucData, + size_t uxMaxCount, + BaseType_t xPeek ) +{ + __CPROVER_assert( pxBuffer != NULL, "pxBuffer cannot be NULL" ); + return nondet_sizet(); +} + +void * vSocketClose( FreeRTOS_Socket_t * pxSocket ) +{ + __CPROVER_assert( pxSocket != NULL, "Closing socket cannot be NULL." ); + + return NULL; +} + +void vSocketWakeUpUser( FreeRTOS_Socket_t * pxSocket ) +{ + __CPROVER_assert( pxSocket != NULL, "Closing socket cannot be NULL." ); + + return NULL; +} + +void harness() +{ + NetworkBufferDescriptor_t * pxNetworkBuffer; + FreeRTOS_Socket_t * pxSocket; size_t socketSize = sizeof( FreeRTOS_Socket_t ); /* Allocates min. buffer size required for the proof */ - size_t bufferSize = sizeof( TCPPacket_t ) + uxIPHeaderSizeSocket( pxSocket ); + size_t bufferSize; - if( ensure_memory_is_valid( pxNetworkBuffer, sizeof( *pxNetworkBuffer ) ) ) - { - pxNetworkBuffer->xDataLength = bufferSize; + pxSocket = ensure_FreeRTOS_Socket_t_is_allocated(); + __CPROVER_assume( pxSocket != NULL ); - /* The code does not expect pucEthernetBuffer to be equal to NULL if - * pxNetworkBuffer is not NULL. */ - pxNetworkBuffer->pucEthernetBuffer = malloc( bufferSize ); - __CPROVER_assume( pxNetworkBuffer->pucEthernetBuffer != NULL ); + if( pxSocket->u.xTCP.bits.bReuseSocket == pdFALSE ) + { + /* Make sure we have parent socket if reuse is set to FALSE to avoid assertion in vTCPStateChange(). */ + __CPROVER_assume( pxSocket->u.xTCP.pxPeerSocket != NULL ); } - UBaseType_t uxOptionsLength; + bufferSize = sizeof( TCPPacket_t ) + ipSIZE_OF_IPv6_HEADER; + + pxNetworkBuffer = pxGetNetworkBufferWithDescriptor( bufferSize, 0 ); + __CPROVER_assume( pxNetworkBuffer != NULL ); + __CPROVER_assume( pxNetworkBuffer->pucEthernetBuffer != NULL ); + + /* Call to init the socket list. */ + vListInitialise( &xBoundTCPSocketsList ); if( pxSocket ) { - publicTCPPrepareSend( pxSocket, &pxNetworkBuffer, uxOptionsLength ); + publicTCPPrepareSend( pxSocket, &pxNetworkBuffer, 0 ); } } diff --git a/test/cbmc/proofs/TCP/prvTCPReturnPacket/Makefile.json b/test/cbmc/proofs/TCP/prvTCPReturnPacket/Makefile.json index 1b67f5a076..12a17ef309 100644 --- a/test/cbmc/proofs/TCP/prvTCPReturnPacket/Makefile.json +++ b/test/cbmc/proofs/TCP/prvTCPReturnPacket/Makefile.json @@ -39,14 +39,19 @@ "$(ENTRY)_harness.goto", "$(FREERTOS_PLUS_TCP)/source/FreeRTOS_Stream_Buffer.goto", "$(FREERTOS_PLUS_TCP)/source/FreeRTOS_IP.goto", + "$(FREERTOS_PLUS_TCP)/source/FreeRTOS_IP_Utils.goto", "$(FREERTOS_PLUS_TCP)/source/FreeRTOS_TCP_IP.goto", "$(FREERTOS_PLUS_TCP)/source/FreeRTOS_TCP_Transmission_IPv4.goto", - "$(FREERTOS_PLUS_TCP)/source/FreeRTOS_TCP_Transmission.goto" + "$(FREERTOS_PLUS_TCP)/source/FreeRTOS_TCP_Transmission.goto", + "$(FREERTOS_PLUS_TCP)/test/cbmc/stubs/freertos_kernel_api.goto", + "$(FREERTOS_PLUS_TCP)/test/cbmc/stubs/freertos_api.goto", + "$(FREERTOS_PLUS_TCP)/test/cbmc/stubs/cbmc.goto" ], "DEF": [ "ipconfigUSE_LINKED_RX_MESSAGES={RX_MESSAGES}", - "FREERTOS_TCP_ENABLE_VERIFICATION" + "FREERTOS_TCP_ENABLE_VERIFICATION", + "CBMC_REQUIRE_NETWORKBUFFER_ETHERNETBUFFER_NONNULL" ], "INC": [ diff --git a/test/cbmc/proofs/TCP/prvTCPReturnPacket/TCPReturnPacket_harness.c b/test/cbmc/proofs/TCP/prvTCPReturnPacket/TCPReturnPacket_harness.c index fa4097c126..ffbbba664f 100644 --- a/test/cbmc/proofs/TCP/prvTCPReturnPacket/TCPReturnPacket_harness.c +++ b/test/cbmc/proofs/TCP/prvTCPReturnPacket/TCPReturnPacket_harness.c @@ -37,10 +37,42 @@ #include "FreeRTOS_TCP_IP.h" #include "FreeRTOS_TCP_Transmission.h" -#include "../../utility/memory_assignments.c" - +/* CBMC includes */ #include "cbmc.h" +/* prvTCPReturnPacket_IPV6 is proven separately. */ +void prvTCPReturnPacket_IPV6( FreeRTOS_Socket_t * pxSocket, + NetworkBufferDescriptor_t * pxDescriptor, + uint32_t ulLen, + BaseType_t xReleaseAfterSend ) +{ + __CPROVER_assert( pxSocket != NULL, "pxSocket cannot be NULL" ); + __CPROVER_assert( pxDescriptor != NULL, "pxDescriptor cannot be NULL" ); +} + +/* Memory assignment for FreeRTOS_Socket_t */ +FreeRTOS_Socket_t * ensure_FreeRTOS_Socket_t_is_allocated() +{ + size_t buf_size; /* Give buffer_size an unconstrained value */ + FreeRTOS_Socket_t * pxSocket = safeMalloc( sizeof( FreeRTOS_Socket_t ) + sizeof( IPTCPSocket_t ) ); + + __CPROVER_assume( pxSocket != NULL ); + pxSocket->u.xTCP.rxStream = safeMalloc( sizeof( StreamBuffer_t ) ); + pxSocket->u.xTCP.txStream = safeMalloc( sizeof( StreamBuffer_t ) ); + pxSocket->u.xTCP.pxPeerSocket = safeMalloc( sizeof( FreeRTOS_Socket_t ) ); + pxSocket->pxEndPoint = safeMalloc( sizeof( NetworkEndPoint_t ) ); + pxSocket->u.xTCP.pxAckMessage = safeMalloc( sizeof( NetworkBufferDescriptor_t ) ); + + if( pxSocket->u.xTCP.pxAckMessage != NULL ) + { + __CPROVER_assume( ( buf_size > ( ipSIZE_OF_ETH_HEADER + ipSIZE_OF_IPv6_HEADER + sizeof( TCPHeader_t ) ) ) && ( buf_size < ipconfigNETWORK_MTU ) ); + pxSocket->u.xTCP.pxAckMessage->pucEthernetBuffer = safeMalloc( buf_size ); + __CPROVER_assume( pxSocket->u.xTCP.pxAckMessage->pucEthernetBuffer != NULL ); + } + + return pxSocket; +} + /* * This function is implemented by a third party. * After looking through a couple of samples in the demos folder, it seems @@ -89,27 +121,31 @@ void prvTCPReturn_SetEndPoint( const FreeRTOS_Socket_t * pxSocket, NetworkBufferDescriptor_t * pxDuplicateNetworkBufferWithDescriptor( const NetworkBufferDescriptor_t * const pxNetworkBuffer, size_t xNewLength ) { - NetworkBufferDescriptor_t * pxNetworkBuffer = safeMalloc( xNewLength ); + NetworkBufferDescriptor_t * pxLocalNetworkBuffer; + EthernetHeader_t * pxHeader; + + pxLocalNetworkBuffer = pxGetNetworkBufferWithDescriptor( xNewLength, 0 ); - if( ensure_memory_is_valid( pxNetworkBuffer, xNewLength ) ) + if( pxLocalNetworkBuffer != NULL ) { - pxNetworkBuffer->pucEthernetBuffer = safeMalloc( sizeof( TCPPacket_t ) ); - __CPROVER_assume( pxNetworkBuffer->pucEthernetBuffer ); + /* In this test case, we only focus on IPv4. */ + pxHeader = ( ( const EthernetHeader_t * ) pxNetworkBuffer->pucEthernetBuffer ); + __CPROVER_assume( pxHeader->usFrameType != ipIPv6_FRAME_TYPE ); /* Add an end point to the network buffer present. Its assumed that the * network interface layer correctly assigns the end point to the generated buffer. */ - pxNetworkBuffer->pxEndPoint = ( NetworkEndPoint_t * ) safeMalloc( sizeof( NetworkEndPoint_t ) ); - __CPROVER_assume( pxNetworkBuffer->pxEndPoint != NULL ); - pxNetworkBuffer->pxEndPoint->pxNext = NULL; + pxLocalNetworkBuffer->pxEndPoint = ( NetworkEndPoint_t * ) safeMalloc( sizeof( NetworkEndPoint_t ) ); + __CPROVER_assume( pxLocalNetworkBuffer->pxEndPoint != NULL ); + pxLocalNetworkBuffer->pxEndPoint->pxNext = NULL; /* Add an interface */ - pxNetworkBuffer->pxEndPoint->pxNetworkInterface = ( NetworkInterface_t * ) safeMalloc( sizeof( NetworkInterface_t ) ); - __CPROVER_assume( pxNetworkBuffer->pxEndPoint->pxNetworkInterface != NULL ); + pxLocalNetworkBuffer->pxEndPoint->pxNetworkInterface = ( NetworkInterface_t * ) safeMalloc( sizeof( NetworkInterface_t ) ); + __CPROVER_assume( pxLocalNetworkBuffer->pxEndPoint->pxNetworkInterface != NULL ); - pxNetworkBuffer->pxEndPoint->pxNetworkInterface->pfOutput = NetworkInterfaceOutputFunction_Stub; + pxLocalNetworkBuffer->pxEndPoint->pxNetworkInterface->pfOutput = NetworkInterfaceOutputFunction_Stub; } - return pxNetworkBuffer; + return pxLocalNetworkBuffer; } uint16_t usGenerateProtocolChecksum( const uint8_t * const pucEthernetBuffer, @@ -137,12 +173,12 @@ uint16_t usGenerateChecksum( uint16_t usSum, } /* This function has been tested separately. Therefore, we assume that the implementation is correct. */ -eARPLookupResult_t eARPGetCacheEntry( uint32_t * pulIPAddress, +eResolutionLookupResult_t eARPGetCacheEntry( uint32_t * pulIPAddress, MACAddress_t * const pxMACAddress, struct xNetworkEndPoint ** ppxEndPoint ) { /* Assume random ARP lookup result. */ - eARPLookupResult_t eReturn; + eResolutionLookupResult_t eReturn; /* Make sure NULL pointers are not passed as arguments. */ __CPROVER_assert( pulIPAddress != NULL, "The pulIPAddress cannot be NULL" ); @@ -169,29 +205,38 @@ eARPLookupResult_t eARPGetCacheEntry( uint32_t * pulIPAddress, void harness() { - FreeRTOS_Socket_t * pxSocket = ensure_FreeRTOS_Socket_t_is_allocated(); - NetworkBufferDescriptor_t * pxNetworkBuffer = ensure_FreeRTOS_NetworkBuffer_is_allocated(); + FreeRTOS_Socket_t * pxSocket; + NetworkBufferDescriptor_t * pxNetworkBuffer; BaseType_t xReleaseAfterSend; uint32_t ulLen; + EthernetHeader_t * pxHeader; + + pxSocket = ensure_FreeRTOS_Socket_t_is_allocated(); + + if( pxSocket != NULL ) + { + /* In this test case, we only focus on IPv4. */ + __CPROVER_assume( pxSocket->bits.bIsIPv6 == pdFALSE_UNSIGNED ); + } + + __CPROVER_assume( ( ulLen >= sizeof( TCPPacket_t ) ) && ( ulLen < ipconfigNETWORK_MTU - ipSIZE_OF_ETH_HEADER ) ); + pxNetworkBuffer = pxGetNetworkBufferWithDescriptor( ulLen + ipSIZE_OF_ETH_HEADER, 0 ); /* The code does not expect both of these to be equal to NULL at the same time. */ __CPROVER_assume( pxSocket != NULL || pxNetworkBuffer != NULL ); /* If network buffer is properly created. */ - if( ensure_memory_is_valid( pxNetworkBuffer, sizeof( *pxNetworkBuffer ) ) ) + if( pxNetworkBuffer != NULL ) { - /* Assume that the length is proper. */ - __CPROVER_assume( ( ulLen >= sizeof( TCPPacket_t ) ) && ( ulLen < ipconfigNETWORK_MTU ) ); - pxNetworkBuffer->pucEthernetBuffer = safeMalloc( ulLen + ipSIZE_OF_ETH_HEADER ); - __CPROVER_assume( pxNetworkBuffer->pucEthernetBuffer ); - - pxNetworkBuffer->xDataLength = ( size_t ) ulLen; + /* In this test case, we only focus on IPv4. */ + pxHeader = ( ( const EthernetHeader_t * ) pxNetworkBuffer->pucEthernetBuffer ); + __CPROVER_assume( pxHeader->usFrameType != ipIPv6_FRAME_TYPE ); /* Add an end point to the network buffer present. Its assumed that the * network interface layer correctly assigns the end point to the generated buffer. */ pxNetworkBuffer->pxEndPoint = ( NetworkEndPoint_t * ) safeMalloc( sizeof( NetworkEndPoint_t ) ); - if( ensure_memory_is_valid( pxNetworkBuffer->pxEndPoint, sizeof( NetworkEndPoint_t ) ) ) + if( pxNetworkBuffer->pxEndPoint != NULL ) { /* Add an interface */ pxNetworkBuffer->pxEndPoint->pxNetworkInterface = ( NetworkInterface_t * ) safeMalloc( sizeof( NetworkInterface_t ) ); diff --git a/test/cbmc/proofs/TCP/prvTCPReturnPacket_IPv6/Makefile.json b/test/cbmc/proofs/TCP/prvTCPReturnPacket_IPv6/Makefile.json index 9b28c3b345..629ef713d4 100644 --- a/test/cbmc/proofs/TCP/prvTCPReturnPacket_IPv6/Makefile.json +++ b/test/cbmc/proofs/TCP/prvTCPReturnPacket_IPv6/Makefile.json @@ -11,14 +11,19 @@ "$(ENTRY)_harness.goto", "$(FREERTOS_PLUS_TCP)/source/FreeRTOS_Stream_Buffer.goto", "$(FREERTOS_PLUS_TCP)/source/FreeRTOS_IP.goto", + "$(FREERTOS_PLUS_TCP)/source/FreeRTOS_IP_Utils.goto", "$(FREERTOS_PLUS_TCP)/source/FreeRTOS_TCP_IP.goto", "$(FREERTOS_PLUS_TCP)/source/FreeRTOS_TCP_Transmission_IPv6.goto", - "$(FREERTOS_PLUS_TCP)/source/FreeRTOS_TCP_Transmission.goto" + "$(FREERTOS_PLUS_TCP)/source/FreeRTOS_TCP_Transmission.goto", + "$(FREERTOS_PLUS_TCP)/test/cbmc/stubs/freertos_kernel_api.goto", + "$(FREERTOS_PLUS_TCP)/test/cbmc/stubs/freertos_api.goto", + "$(FREERTOS_PLUS_TCP)/test/cbmc/stubs/cbmc.goto" ], "DEF": [ "ipconfigUSE_LINKED_RX_MESSAGES={RX_MESSAGES}", - "FREERTOS_TCP_ENABLE_VERIFICATION" + "FREERTOS_TCP_ENABLE_VERIFICATION", + "CBMC_REQUIRE_NETWORKBUFFER_ETHERNETBUFFER_NONNULL" ], "INC": [ diff --git a/test/cbmc/proofs/TCP/prvTCPReturnPacket_IPv6/TCPReturnPacket_IPv6_harness.c b/test/cbmc/proofs/TCP/prvTCPReturnPacket_IPv6/TCPReturnPacket_IPv6_harness.c index ea2e87b2fd..c419189802 100644 --- a/test/cbmc/proofs/TCP/prvTCPReturnPacket_IPv6/TCPReturnPacket_IPv6_harness.c +++ b/test/cbmc/proofs/TCP/prvTCPReturnPacket_IPv6/TCPReturnPacket_IPv6_harness.c @@ -35,10 +35,9 @@ #include "FreeRTOS_IP_Private.h" #include "FreeRTOS_TCP_IP.h" #include "FreeRTOS_TCP_Transmission.h" +#include "FreeRTOS_ND.h" /* CBMC includes. */ -#include "../../utility/memory_assignments.c" - #include "cbmc.h" /* @@ -64,6 +63,51 @@ BaseType_t NetworkInterfaceOutputFunction_Stub( struct xNetworkInterface * pxDes return 0; } +/* Memory assignment for FreeRTOS_Socket_t */ +FreeRTOS_Socket_t * ensure_FreeRTOS_Socket_t_is_allocated() +{ + size_t buf_size; /* Give buffer_size an unconstrained value */ + FreeRTOS_Socket_t * pxSocket = safeMalloc( sizeof( FreeRTOS_Socket_t ) + sizeof( IPTCPSocket_t ) ); + + __CPROVER_assume( pxSocket != NULL ); + pxSocket->u.xTCP.rxStream = safeMalloc( sizeof( StreamBuffer_t ) ); + pxSocket->u.xTCP.txStream = safeMalloc( sizeof( StreamBuffer_t ) ); + pxSocket->u.xTCP.pxPeerSocket = safeMalloc( sizeof( FreeRTOS_Socket_t ) ); + pxSocket->pxEndPoint = safeMalloc( sizeof( NetworkEndPoint_t ) ); + pxSocket->u.xTCP.pxAckMessage = safeMalloc( sizeof( NetworkBufferDescriptor_t ) ); + + if( pxSocket->u.xTCP.pxAckMessage != NULL ) + { + __CPROVER_assume( ( buf_size > ( ipSIZE_OF_ETH_HEADER + ipSIZE_OF_IPv6_HEADER + sizeof( TCPHeader_t ) ) ) && ( buf_size < ipconfigNETWORK_MTU ) ); + pxSocket->u.xTCP.pxAckMessage->pucEthernetBuffer = safeMalloc( buf_size ); + __CPROVER_assume( pxSocket->u.xTCP.pxAckMessage->pucEthernetBuffer != NULL ); + } + + return pxSocket; +} + +void prvTCPReturnPacket_IPV4( FreeRTOS_Socket_t * pxSocket, + NetworkBufferDescriptor_t * pxDescriptor, + uint32_t ulLen, + BaseType_t xReleaseAfterSend ) +{ + __CPROVER_assert( pxSocket != NULL, "pxSocket cannot be NULL" ); + __CPROVER_assert( pxDescriptor != NULL, "pxDescriptor cannot be NULL" ); +} + +/* Abstraction of eNDGetCacheEntry. */ +eResolutionLookupResult_t eNDGetCacheEntry( IPv6_Address_t * pxIPAddress, + MACAddress_t * const pxMACAddress, + struct xNetworkEndPoint ** ppxEndPoint ) +{ + eResolutionLookupResult_t xReturn; + + __CPROVER_assert( __CPROVER_r_ok( pxIPAddress, sizeof( IPv6_Address_t ) ), "pxIPAddress must be readable" ); + __CPROVER_assert( __CPROVER_w_ok( pxMACAddress, sizeof( MACAddress_t ) ), "pxMACAddress must be writeable" ); + + return xReturn; +} + /* Abstraction of this functions creates an endpoint and assign it to network interface * endpoint, real endpoint doesn't matter in this test. */ void prvTCPReturn_SetEndPoint( const FreeRTOS_Socket_t * pxSocket, @@ -87,27 +131,31 @@ void prvTCPReturn_SetEndPoint( const FreeRTOS_Socket_t * pxSocket, NetworkBufferDescriptor_t * pxDuplicateNetworkBufferWithDescriptor( const NetworkBufferDescriptor_t * const pxNetworkBuffer, size_t xNewLength ) { - NetworkBufferDescriptor_t * pxNetworkBuffer = safeMalloc( xNewLength ); + NetworkBufferDescriptor_t * pxLocalNetworkBuffer; + EthernetHeader_t * pxHeader; + + pxLocalNetworkBuffer = pxGetNetworkBufferWithDescriptor( xNewLength, 0 ); - if( ensure_memory_is_valid( pxNetworkBuffer, xNewLength ) ) + if( pxLocalNetworkBuffer != NULL ) { - pxNetworkBuffer->pucEthernetBuffer = safeMalloc( sizeof( TCPPacket_t ) ); - __CPROVER_assume( pxNetworkBuffer->pucEthernetBuffer ); + /* In this test case, we only focus on IPv6. */ + pxHeader = ( ( const EthernetHeader_t * ) pxNetworkBuffer->pucEthernetBuffer ); + __CPROVER_assume( pxHeader->usFrameType == ipIPv6_FRAME_TYPE ); /* Add an end point to the network buffer present. Its assumed that the * network interface layer correctly assigns the end point to the generated buffer. */ - pxNetworkBuffer->pxEndPoint = ( NetworkEndPoint_t * ) safeMalloc( sizeof( NetworkEndPoint_t ) ); - __CPROVER_assume( pxNetworkBuffer->pxEndPoint != NULL ); - pxNetworkBuffer->pxEndPoint->pxNext = NULL; + pxLocalNetworkBuffer->pxEndPoint = ( NetworkEndPoint_t * ) safeMalloc( sizeof( NetworkEndPoint_t ) ); + __CPROVER_assume( pxLocalNetworkBuffer->pxEndPoint != NULL ); + pxLocalNetworkBuffer->pxEndPoint->pxNext = NULL; /* Add an interface */ - pxNetworkBuffer->pxEndPoint->pxNetworkInterface = ( NetworkInterface_t * ) safeMalloc( sizeof( NetworkInterface_t ) ); - __CPROVER_assume( pxNetworkBuffer->pxEndPoint->pxNetworkInterface != NULL ); + pxLocalNetworkBuffer->pxEndPoint->pxNetworkInterface = ( NetworkInterface_t * ) safeMalloc( sizeof( NetworkInterface_t ) ); + __CPROVER_assume( pxLocalNetworkBuffer->pxEndPoint->pxNetworkInterface != NULL ); - pxNetworkBuffer->pxEndPoint->pxNetworkInterface->pfOutput = NetworkInterfaceOutputFunction_Stub; + pxLocalNetworkBuffer->pxEndPoint->pxNetworkInterface->pfOutput = NetworkInterfaceOutputFunction_Stub; } - return pxNetworkBuffer; + return pxLocalNetworkBuffer; } uint16_t usGenerateProtocolChecksum( const uint8_t * const pucEthernetBuffer, @@ -136,29 +184,38 @@ uint16_t usGenerateChecksum( uint16_t usSum, void harness() { - FreeRTOS_Socket_t * pxSocket = ensure_FreeRTOS_Socket_t_is_allocated(); - NetworkBufferDescriptor_t * pxNetworkBuffer = ensure_FreeRTOS_NetworkBuffer_is_allocated(); + FreeRTOS_Socket_t * pxSocket; + NetworkBufferDescriptor_t * pxNetworkBuffer; BaseType_t xReleaseAfterSend; uint32_t ulLen; + EthernetHeader_t * pxHeader; + + pxSocket = ensure_FreeRTOS_Socket_t_is_allocated(); + + if( pxSocket != NULL ) + { + /* In this test case, we only focus on IPv6. */ + __CPROVER_assume( pxSocket->bits.bIsIPv6 != pdFALSE_UNSIGNED ); + } + + __CPROVER_assume( ( ulLen >= sizeof( TCPPacket_IPv6_t ) ) && ( ulLen < ipconfigNETWORK_MTU - ipSIZE_OF_ETH_HEADER ) ); + pxNetworkBuffer = pxGetNetworkBufferWithDescriptor( ulLen + ipSIZE_OF_ETH_HEADER, 0 ); /* The code does not expect both of these to be equal to NULL at the same time. */ __CPROVER_assume( pxSocket != NULL || pxNetworkBuffer != NULL ); /* If network buffer is properly created. */ - if( ensure_memory_is_valid( pxNetworkBuffer, sizeof( *pxNetworkBuffer ) ) ) + if( pxNetworkBuffer != NULL ) { - /* Assume that the length is proper. */ - __CPROVER_assume( ( ulLen >= sizeof( TCPPacket_IPv6_t ) ) && ( ulLen < ipconfigNETWORK_MTU ) ); - pxNetworkBuffer->pucEthernetBuffer = safeMalloc( ulLen + ipSIZE_OF_ETH_HEADER ); - __CPROVER_assume( pxNetworkBuffer->pucEthernetBuffer != NULL ); - - pxNetworkBuffer->xDataLength = ( size_t ) ( ulLen + ipSIZE_OF_ETH_HEADER ); + /* In this test case, we only focus on IPv6. */ + pxHeader = ( ( const EthernetHeader_t * ) pxNetworkBuffer->pucEthernetBuffer ); + __CPROVER_assume( pxHeader->usFrameType == ipIPv6_FRAME_TYPE ); /* Add an end point to the network buffer present. Its assumed that the * network interface layer correctly assigns the end point to the generated buffer. */ pxNetworkBuffer->pxEndPoint = ( NetworkEndPoint_t * ) safeMalloc( sizeof( NetworkEndPoint_t ) ); - if( ensure_memory_is_valid( pxNetworkBuffer->pxEndPoint, sizeof( NetworkEndPoint_t ) ) ) + if( pxNetworkBuffer->pxEndPoint != NULL ) { /* Add an interface */ pxNetworkBuffer->pxEndPoint->pxNetworkInterface = ( NetworkInterface_t * ) safeMalloc( sizeof( NetworkInterface_t ) ); diff --git a/test/cbmc/proofs/UDP/vProcessGeneratedUDPPacket/vProcessGeneratedUDPPacket_harness.c b/test/cbmc/proofs/UDP/vProcessGeneratedUDPPacket/vProcessGeneratedUDPPacket_harness.c index b56bc475bd..6a51a5a68a 100644 --- a/test/cbmc/proofs/UDP/vProcessGeneratedUDPPacket/vProcessGeneratedUDPPacket_harness.c +++ b/test/cbmc/proofs/UDP/vProcessGeneratedUDPPacket/vProcessGeneratedUDPPacket_harness.c @@ -19,6 +19,12 @@ #include "memory_assignments.c" #include "freertos_api.c" +/* vProcessGeneratedUDPPacket_IPv6 is proven separately. */ +void vProcessGeneratedUDPPacket_IPv6( NetworkBufferDescriptor_t * const pxNetworkBuffer ) +{ + __CPROVER_assert( pxNetworkBuffer != NULL, "pxNetworkBuffer cannot be NULL" ); +} + /* We do not need to calculate the actual checksum for the proof to be complete. * Neither does the checksum matter for completeness. */ uint16_t usGenerateChecksum( uint16_t usSum, @@ -33,7 +39,6 @@ uint16_t usGenerateChecksum( uint16_t usSum, return usChecksum; } - /* We do not need to calculate the actual checksum for the proof to be complete. * Neither does the checksum matter for completeness. */ uint16_t usGenerateProtocolChecksum( const uint8_t * const pucEthernetBuffer, @@ -64,13 +69,13 @@ void vARPGenerateRequestPacket( NetworkBufferDescriptor_t * const pxNetworkBuffe /* This function has been tested separately. Therefore, we assume that the implementation is correct. */ -eARPLookupResult_t eARPGetCacheEntry( uint32_t * pulIPAddress, +eResolutionLookupResult_t eARPGetCacheEntry( uint32_t * pulIPAddress, MACAddress_t * const pxMACAddress ) { __CPROVER_assert( pulIPAddress != NULL, "pulIPAddress cannot be NULL" ); __CPROVER_assert( pxMACAddress != NULL, "pxMACAddress cannot be NULL" ); - eARPLookupResult_t eResult; + eResolutionLookupResult_t eResult; return eResult; } diff --git a/test/cbmc/proofs/UDP/vProcessGeneratedUDPPacket_IPv6/vProcessGeneratedUDPPacket_IPv6_harness.c b/test/cbmc/proofs/UDP/vProcessGeneratedUDPPacket_IPv6/vProcessGeneratedUDPPacket_IPv6_harness.c index 000fb49a9a..ed34fd3aeb 100644 --- a/test/cbmc/proofs/UDP/vProcessGeneratedUDPPacket_IPv6/vProcessGeneratedUDPPacket_IPv6_harness.c +++ b/test/cbmc/proofs/UDP/vProcessGeneratedUDPPacket_IPv6/vProcessGeneratedUDPPacket_IPv6_harness.c @@ -48,11 +48,11 @@ uint16_t usGenerateProtocolChecksum( const uint8_t * const pucEthernetBuffer, } /* This function has been tested separately. Therefore, we assume that the implementation is correct. */ -eARPLookupResult_t eNDGetCacheEntry( IPv6_Address_t * pxIPAddress, +eResolutionLookupResult_t eNDGetCacheEntry( IPv6_Address_t * pxIPAddress, MACAddress_t * const pxMACAddress, struct xNetworkEndPoint ** ppxEndPoint ) { - eARPLookupResult_t eResult; + eResolutionLookupResult_t eResult; __CPROVER_assert( pxIPAddress != NULL, "pxIPAddress cannot be NULL" ); __CPROVER_assert( pxMACAddress != NULL, "pxMACAddress cannot be NULL" ); diff --git a/test/cbmc/proofs/parsing/ProcessIPPacket/ProcessIPPacket_harness.c b/test/cbmc/proofs/parsing/ProcessIPPacket/ProcessIPPacket_harness.c index a1c0c80b03..5b926e4c48 100644 --- a/test/cbmc/proofs/parsing/ProcessIPPacket/ProcessIPPacket_harness.c +++ b/test/cbmc/proofs/parsing/ProcessIPPacket/ProcessIPPacket_harness.c @@ -9,9 +9,96 @@ /* CBMC includes. */ #include "cbmc.h" +NetworkEndPoint_t xEndpoint; + eFrameProcessingResult_t __CPROVER_file_local_FreeRTOS_IP_c_prvProcessIPPacket( const IPPacket_t * pxIPPacket, NetworkBufferDescriptor_t * const pxNetworkBuffer ); +/* Check if input is a valid extension header ID. */ +BaseType_t xIsExtensionHeader( uint8_t ucCurrentHeader ) +{ + BaseType_t xReturn = pdFALSE; + + switch( ucCurrentHeader ) + { + case ipIPv6_EXT_HEADER_HOP_BY_HOP: + case ipIPv6_EXT_HEADER_DESTINATION_OPTIONS: + case ipIPv6_EXT_HEADER_ROUTING_HEADER: + case ipIPv6_EXT_HEADER_FRAGMENT_HEADER: + case ipIPv6_EXT_HEADER_AUTHEN_HEADER: + case ipIPv6_EXT_HEADER_SECURE_PAYLOAD: + case ipIPv6_EXT_HEADER_MOBILITY_HEADER: + xReturn = pdTRUE; + break; + } + + return xReturn; +} + +/* Abstraction of xGetExtensionOrder. To ensure the result of prepared extension headers is same. */ +BaseType_t xGetExtensionOrder( uint8_t ucProtocol, + uint8_t ucNextHeader ) +{ + return xIsExtensionHeader( ucProtocol ); +} + +BaseType_t xCheckRequiresARPResolution( const NetworkBufferDescriptor_t * pxNetworkBuffer ) +{ + BaseType_t xReturn; + + __CPROVER_assert( pxNetworkBuffer != NULL, "pxNetworkBuffer cannot be NULL" ); + __CPROVER_assert( __CPROVER_r_ok( pxNetworkBuffer->pucEthernetBuffer, pxNetworkBuffer->xDataLength ), "Data in pxNetworkBuffer must be readable" ); +} + +void vARPRefreshCacheEntryAge( const MACAddress_t * pxMACAddress, + const uint32_t ulIPAddress ) +{ + __CPROVER_assert( pxMACAddress != NULL, "pxMACAddress cannot be NULL" ); +} + +void vNDRefreshCacheEntry( const MACAddress_t * pxMACAddress, + const IPv6_Address_t * pxIPAddress, + NetworkEndPoint_t * pxEndPoint ) +{ + __CPROVER_assert( pxMACAddress != NULL, "pxMACAddress cannot be NULL" ); + __CPROVER_assert( pxIPAddress != NULL, "pxIPAddress cannot be NULL" ); + __CPROVER_assert( pxEndPoint != NULL, "pxEndPoint cannot be NULL" ); +} + +NetworkEndPoint_t * FreeRTOS_FindEndPointOnIP_IPv4( uint32_t ulIPAddress ) +{ + NetworkEndPoint_t * pxEndpoint = NULL; + + if( nondet_bool() ) + { + pxEndpoint = pxNetworkEndPoints; + } + + return pxEndpoint; +} + +/* proof is done separately */ +eFrameProcessingResult_t ProcessICMPPacket( const NetworkBufferDescriptor_t * const pxNetworkBuffer ) +{ + eFrameProcessingResult_t xReturn; + + __CPROVER_assert( pxNetworkBuffer != NULL, "pxEndPoint cannot be NULL" ); + __CPROVER_assert( __CPROVER_r_ok( pxNetworkBuffer->pucEthernetBuffer, pxNetworkBuffer->xDataLength ), "Data in pxNetworkBuffer must be readable" ); + + return xReturn; +} + +/* proof is done separately */ +eFrameProcessingResult_t prvProcessICMPMessage_IPv6( NetworkBufferDescriptor_t * const pxNetworkBuffer ) +{ + eFrameProcessingResult_t xReturn; + + __CPROVER_assert( pxNetworkBuffer != NULL, "pxEndPoint cannot be NULL" ); + __CPROVER_assert( __CPROVER_r_ok( pxNetworkBuffer->pucEthernetBuffer, pxNetworkBuffer->xDataLength ), "Data in pxNetworkBuffer must be readable" ); + + return xReturn; +} + /* proof is done separately */ BaseType_t xProcessReceivedTCPPacket( NetworkBufferDescriptor_t * pxNetworkBuffer ) { @@ -67,6 +154,7 @@ void harness() { NetworkBufferDescriptor_t * const pxNetworkBuffer = safeMalloc( sizeof( NetworkBufferDescriptor_t ) ); uint8_t * pucEthernetBuffer = ( uint8_t * ) safeMalloc( ipTOTAL_ETHERNET_FRAME_SIZE + ipIP_TYPE_OFFSET ); + EthernetHeader_t * pxHeader; __CPROVER_assume( pxNetworkBuffer != NULL ); __CPROVER_assume( pucEthernetBuffer != NULL ); @@ -83,7 +171,10 @@ void harness() __CPROVER_assume( pxNetworkEndPoints != NULL ); __CPROVER_assume( pxNetworkEndPoints->pxNext == NULL ); - IPPacket_t * const pxIPPacket = ( IPPacket_t * ) pxNetworkBuffer->pucEthernetBuffer; + /* In this test case, we only focus on IPv4. */ + pxHeader = ( ( const EthernetHeader_t * ) pxNetworkBuffer->pucEthernetBuffer ); + __CPROVER_assume( pxHeader->usFrameType != ipIPv6_FRAME_TYPE ); + IPPacket_t * const pxIPPacket = ( IPPacket_t * ) pxNetworkBuffer->pucEthernetBuffer; __CPROVER_file_local_FreeRTOS_IP_c_prvProcessIPPacket( pxIPPacket, pxNetworkBuffer ); } diff --git a/test/cbmc/proofs/parsing/ProcessReceivedTCPPacket/Makefile.json b/test/cbmc/proofs/parsing/ProcessReceivedTCPPacket/Makefile.json index f2643c9b98..bb142d42a4 100644 --- a/test/cbmc/proofs/parsing/ProcessReceivedTCPPacket/Makefile.json +++ b/test/cbmc/proofs/parsing/ProcessReceivedTCPPacket/Makefile.json @@ -10,6 +10,8 @@ [ "$(ENTRY)_harness.goto", "$(FREERTOS_PLUS_TCP)/test/cbmc/stubs/cbmc.goto", + "$(FREERTOS_PLUS_TCP)/test/cbmc/stubs/freertos_api.goto", + "$(FREERTOS_PLUS_TCP)/test/cbmc/stubs/freertos_kernel_api.goto", "$(FREERTOS_PLUS_TCP)/source/FreeRTOS_IP.goto", "$(FREERTOS_PLUS_TCP)/source/FreeRTOS_IP_Utils.goto", "$(FREERTOS_PLUS_TCP)/source/FreeRTOS_IP_Timers.goto", @@ -23,16 +25,11 @@ ], "INSTFLAGS": [ - "--remove-function-body prvSingleStepTCPHeaderOptions", - "--remove-function-body prvCheckOptions", - "--remove-function-body prvTCPPrepareSend", - "--remove-function-body prvTCPReturnPacket", - "--remove-function-body prvTCPHandleState", - "--remove-function-body vTCPStateChange" ], "DEF": [ - "FREERTOS_TCP_ENABLE_VERIFICATION" + "FREERTOS_TCP_ENABLE_VERIFICATION", + "CBMC_GETNETWORKBUFFER_FAILURE_BOUND" ], "INC": [ diff --git a/test/cbmc/proofs/parsing/ProcessReceivedTCPPacket/ProcessReceivedTCPPacket_harness.c b/test/cbmc/proofs/parsing/ProcessReceivedTCPPacket/ProcessReceivedTCPPacket_harness.c index 00f6e8014c..c15387b900 100644 --- a/test/cbmc/proofs/parsing/ProcessReceivedTCPPacket/ProcessReceivedTCPPacket_harness.c +++ b/test/cbmc/proofs/parsing/ProcessReceivedTCPPacket/ProcessReceivedTCPPacket_harness.c @@ -35,6 +35,81 @@ TaskHandle_t xTaskGetCurrentTaskHandle( void ) return pxCurrentTCB; } +/* Abstraction of vTCPStateChange */ +void vTCPStateChange( FreeRTOS_Socket_t * pxSocket, + enum eTCP_STATE eTCPState ) +{ +} + +/* prvTCPReturnPacket is proven separately */ +void prvTCPReturnPacket( FreeRTOS_Socket_t * pxSocket, + NetworkBufferDescriptor_t * pxDescriptor, + uint32_t ulLen, + BaseType_t xReleaseAfterSend ) +{ + __CPROVER_assert( pxSocket != NULL, "pxSocket should not be NULL" ); + __CPROVER_assert( pxDescriptor != NULL, "pxDescriptor should not be NULL" ); + __CPROVER_assert( pxDescriptor->pucEthernetBuffer != NULL, "pucEthernetBuffer should not be NULL" ); +} + +/* prvTCPPrepareSend is proven separately. */ +int32_t prvTCPPrepareSend( FreeRTOS_Socket_t * pxSocket, + NetworkBufferDescriptor_t ** ppxNetworkBuffer, + UBaseType_t uxOptionsLength ) +{ + __CPROVER_assert( pxSocket != NULL, "pxSocket cannot be NULL" ); + __CPROVER_assert( *ppxNetworkBuffer != NULL, "*ppxNetworkBuffer cannot be NULL" ); + __CPROVER_assert( __CPROVER_r_ok( ( *ppxNetworkBuffer )->pucEthernetBuffer, ( *ppxNetworkBuffer )->xDataLength ), "Data in *ppxNetworkBuffer must be readable" ); + + return nondet_int32(); +} + +/* prvTCPHandleState is proven separately. */ +BaseType_t prvTCPHandleState( FreeRTOS_Socket_t * pxSocket, + NetworkBufferDescriptor_t ** ppxNetworkBuffer ) +{ + __CPROVER_assert( pxSocket != NULL, "pxSocket cannot be NULL" ); + __CPROVER_assert( *ppxNetworkBuffer != NULL, "*ppxNetworkBuffer cannot be NULL" ); + __CPROVER_assert( __CPROVER_r_ok( ( *ppxNetworkBuffer )->pucEthernetBuffer, ( *ppxNetworkBuffer )->xDataLength ), "Data in *ppxNetworkBuffer must be readable" ); + + return nondet_basetype(); +} + +/* prvCheckOptions is proven separately. */ +BaseType_t prvCheckOptions( FreeRTOS_Socket_t * pxSocket, + const NetworkBufferDescriptor_t * pxNetworkBuffer ) +{ + __CPROVER_assert( pxSocket != NULL, "pxSocket cannot be NULL" ); + __CPROVER_assert( pxNetworkBuffer != NULL, "*ppxNetworkBuffer cannot be NULL" ); + __CPROVER_assert( __CPROVER_r_ok( pxNetworkBuffer->pucEthernetBuffer, pxNetworkBuffer->xDataLength ), "Data in *ppxNetworkBuffer must be readable" ); + + return nondet_basetype(); +} + +BaseType_t xTCPWindowTxHasData( TCPWindow_t const * pxWindow, + uint32_t ulWindowSize, + TickType_t * pulDelay ) +{ + __CPROVER_assert( pxWindow != NULL, "pxWindow cannot be NULL" ); + __CPROVER_assert( pulDelay != NULL, "pulDelay cannot be NULL" ); + + return nondet_basetype(); +} + +/* Abstraction of xSequenceLessThan */ +BaseType_t xSequenceLessThan( uint32_t a, + uint32_t b ) +{ + return nondet_basetype(); +} + +/* Abstraction of xSequenceGreaterThan */ +BaseType_t xSequenceGreaterThan( uint32_t a, + uint32_t b ) +{ + return nondet_basetype(); +} + /* Abstraction of prvHandleListen_IPV4 */ FreeRTOS_Socket_t * prvHandleListen_IPV4( FreeRTOS_Socket_t * pxSocket, NetworkBufferDescriptor_t * pxNetworkBuffer ) @@ -98,14 +173,12 @@ size_t uxIPHeaderSizeSocket( const FreeRTOS_Socket_t * pxSocket ) void harness() { - NetworkBufferDescriptor_t * pxNetworkBuffer = safeMalloc( sizeof( NetworkBufferDescriptor_t ) ); + NetworkBufferDescriptor_t * pxNetworkBuffer; + + pxNetworkBuffer = pxGetNetworkBufferWithDescriptor( sizeof( TCPPacket_t ), 0 ); /* To avoid asserting on the network buffer being NULL. */ __CPROVER_assume( pxNetworkBuffer != NULL ); - - pxNetworkBuffer->pucEthernetBuffer = safeMalloc( sizeof( TCPPacket_t ) ); - - /* To avoid asserting on the ethernet buffer being NULL. */ __CPROVER_assume( pxNetworkBuffer->pucEthernetBuffer != NULL ); xProcessReceivedTCPPacket( pxNetworkBuffer ); diff --git a/test/cbmc/proofs/parsing/ProcessReceivedTCPPacket_IPv6/Makefile.json b/test/cbmc/proofs/parsing/ProcessReceivedTCPPacket_IPv6/Makefile.json index 53a28f7332..c37bc279d3 100644 --- a/test/cbmc/proofs/parsing/ProcessReceivedTCPPacket_IPv6/Makefile.json +++ b/test/cbmc/proofs/parsing/ProcessReceivedTCPPacket_IPv6/Makefile.json @@ -10,23 +10,17 @@ [ "$(ENTRY)_harness.goto", "$(FREERTOS_PLUS_TCP)/test/cbmc/stubs/cbmc.goto", - "$(FREERTOS_PLUS_TCP)/source/FreeRTOS_TCP_IP.goto", - "$(FREERTOS_PLUS_TCP)/source/FreeRTOS_TCP_IP_IPv6.goto", - "$(FREERTOS_PLUS_TCP)/source/FreeRTOS_TCP_Transmission.goto", - "$(FREERTOS_PLUS_TCP)/source/FreeRTOS_TCP_Transmission_IPv6.goto" + "$(FREERTOS_PLUS_TCP)/test/cbmc/stubs/freertos_api.goto", + "$(FREERTOS_PLUS_TCP)/test/cbmc/stubs/freertos_kernel_api.goto", + "$(FREERTOS_PLUS_TCP)/source/FreeRTOS_TCP_IP.goto" ], "INSTFLAGS": [ - "--remove-function-body prvSingleStepTCPHeaderOptions", - "--remove-function-body prvCheckOptions", - "--remove-function-body prvTCPPrepareSend", - "--remove-function-body prvTCPReturnPacket", - "--remove-function-body prvTCPHandleState", - "--remove-function-body vTCPStateChange" ], "DEF": [ - "FREERTOS_TCP_ENABLE_VERIFICATION" + "FREERTOS_TCP_ENABLE_VERIFICATION", + "CBMC_GETNETWORKBUFFER_FAILURE_BOUND" ], "INC": [ diff --git a/test/cbmc/proofs/parsing/ProcessReceivedTCPPacket_IPv6/ProcessReceivedTCPPacket_IPv6_harness.c b/test/cbmc/proofs/parsing/ProcessReceivedTCPPacket_IPv6/ProcessReceivedTCPPacket_IPv6_harness.c index c2be060cee..4135a9144f 100644 --- a/test/cbmc/proofs/parsing/ProcessReceivedTCPPacket_IPv6/ProcessReceivedTCPPacket_IPv6_harness.c +++ b/test/cbmc/proofs/parsing/ProcessReceivedTCPPacket_IPv6/ProcessReceivedTCPPacket_IPv6_harness.c @@ -99,20 +99,18 @@ size_t uxIPHeaderSizeSocket( const FreeRTOS_Socket_t * pxSocket ) void harness() { - NetworkBufferDescriptor_t * pxNetworkBuffer = safeMalloc( sizeof( NetworkBufferDescriptor_t ) ); + NetworkBufferDescriptor_t * pxNetworkBuffer; EthernetHeader_t * pxEthernetHeader; - /* To avoid asserting on the network buffer being NULL. */ - __CPROVER_assume( pxNetworkBuffer != NULL ); - - pxNetworkBuffer->pucEthernetBuffer = safeMalloc( sizeof( TCPPacket_IPv6_t ) ); + pxNetworkBuffer = pxGetNetworkBufferWithDescriptor( sizeof( TCPPacket_IPv6_t ), 0 ); /* To avoid asserting on the ethernet buffer being NULL. */ + __CPROVER_assume( pxNetworkBuffer != NULL ); __CPROVER_assume( pxNetworkBuffer->pucEthernetBuffer != NULL ); - /* Ethernet frame type is checked before calling xProcessReceivedTCPPacket_IPV6. */ + /* In this test case, we focus on IPv6 packets. */ pxEthernetHeader = ( EthernetHeader_t * ) pxNetworkBuffer->pucEthernetBuffer; __CPROVER_assume( pxEthernetHeader->usFrameType == ipIPv6_FRAME_TYPE ); - xProcessReceivedTCPPacket_IPV6( pxNetworkBuffer ); + xProcessReceivedTCPPacket( pxNetworkBuffer ); } diff --git a/test/cbmc/proofs/parsing/ProcessReceivedUDPPacket/Makefile.json b/test/cbmc/proofs/parsing/ProcessReceivedUDPPacket/Makefile.json index bc0bc61db1..8c6859f4b8 100644 --- a/test/cbmc/proofs/parsing/ProcessReceivedUDPPacket/Makefile.json +++ b/test/cbmc/proofs/parsing/ProcessReceivedUDPPacket/Makefile.json @@ -11,6 +11,8 @@ "OBJS": [ "$(ENTRY)_harness.goto", + "$(FREERTOS_PLUS_TCP)/test/cbmc/stubs/cbmc.goto", + "$(FREERTOS_PLUS_TCP)/test/cbmc/stubs/freertos_api.goto", "$(FREERTOS_PLUS_TCP)/test/cbmc/stubs/freertos_kernel_api.goto", "$(FREERTOS_PLUS_TCP)/source/FreeRTOS_UDP_IP.goto", "$(FREERTOS_PLUS_TCP)/source/FreeRTOS_UDP_IPv4.goto", diff --git a/test/cbmc/proofs/parsing/ProcessReceivedUDPPacket/ProcessReceivedUDPPacket_harness.c b/test/cbmc/proofs/parsing/ProcessReceivedUDPPacket/ProcessReceivedUDPPacket_harness.c index 6d282aca97..0b2b8c14c5 100644 --- a/test/cbmc/proofs/parsing/ProcessReceivedUDPPacket/ProcessReceivedUDPPacket_harness.c +++ b/test/cbmc/proofs/parsing/ProcessReceivedUDPPacket/ProcessReceivedUDPPacket_harness.c @@ -9,6 +9,9 @@ #include "FreeRTOS_UDP_IP.h" #include "FreeRTOS_TCP_IP.h" +/* CBMC includes. */ +#include "cbmc.h" + /*This proof assumes that pxUDPSocketLookup is implemented correctly. */ /* This proof was done before. Hence we assume it to be correct here. */ @@ -17,6 +20,12 @@ void vARPRefreshCacheEntry( const MACAddress_t * pxMACAddress, { } +void vARPRefreshCacheEntryAge( const MACAddress_t * pxMACAddress, + const uint32_t ulIPAddress ) +{ + __CPROVER_assert( pxMACAddress != NULL, "pxMACAddress cannot be NULL" ); +} + /* This proof was done before. Hence we assume it to be correct here. */ BaseType_t xIsDHCPSocket( Socket_t xSocket ) { @@ -68,19 +77,6 @@ BaseType_t xProcessReceivedUDPPacket_IPv6( NetworkBufferDescriptor_t * pxNetwork return xReturn; } -/* Implementation of safe malloc */ -void * safeMalloc( size_t xWantedSize ) -{ - if( xWantedSize == 0 ) - { - return NULL; - } - - uint8_t byte; - - return byte ? malloc( xWantedSize ) : NULL; -} - /* Abstraction of pxUDPSocketLookup */ FreeRTOS_Socket_t * pxUDPSocketLookup( UBaseType_t uxLocalPort ) { @@ -89,26 +85,23 @@ FreeRTOS_Socket_t * pxUDPSocketLookup( UBaseType_t uxLocalPort ) void harness() { - NetworkBufferDescriptor_t * pxNetworkBuffer = safeMalloc( sizeof( NetworkBufferDescriptor_t ) ); - BaseType_t * pxIsWaitingForARPResolution; + NetworkBufferDescriptor_t * pxNetworkBuffer; + BaseType_t xIsWaitingForARPResolution; NetworkEndPoint_t xEndpoint; uint16_t usPort; + EthernetHeader_t * pxHeader; - pxIsWaitingForARPResolution = safeMalloc( sizeof( BaseType_t ) ); - - /* The function under test is only called by the IP-task. The below pointer is an - * address of a local variable which is being passed to the function under test. - * Thus, it cannot ever be NULL. */ - __CPROVER_assume( pxIsWaitingForARPResolution != NULL ); - + pxNetworkBuffer = pxGetNetworkBufferWithDescriptor( sizeof( UDPPacket_t ), 0 ); /* The network buffer must not be NULL, checked in prvProcessEthernetPacket. */ __CPROVER_assume( pxNetworkBuffer != NULL ); + __CPROVER_assume( pxNetworkBuffer->pucEthernetBuffer != NULL ); - pxNetworkBuffer->pucEthernetBuffer = safeMalloc( sizeof( UDPPacket_t ) ); pxNetworkBuffer->pxEndPoint = &xEndpoint; - /* The ethernet buffer must be valid. */ - __CPROVER_assume( pxNetworkBuffer->pucEthernetBuffer != NULL ); + /* In this test case, we only focus on IPv4. */ + pxHeader = ( ( const EthernetHeader_t * ) pxNetworkBuffer->pucEthernetBuffer ); + __CPROVER_assume( pxHeader->usFrameType != ipIPv6_FRAME_TYPE ); - xProcessReceivedUDPPacket( pxNetworkBuffer, usPort, pxIsWaitingForARPResolution ); + xIsWaitingForARPResolution = nondet_BaseType(); + xProcessReceivedUDPPacket( pxNetworkBuffer, usPort, &xIsWaitingForARPResolution ); } diff --git a/test/cbmc/proofs/prvChecksumIPv6Checks/Makefile.json b/test/cbmc/proofs/prvChecksumIPv6Checks/Makefile.json index 9645ee00a4..7d84cfceee 100644 --- a/test/cbmc/proofs/prvChecksumIPv6Checks/Makefile.json +++ b/test/cbmc/proofs/prvChecksumIPv6Checks/Makefile.json @@ -13,6 +13,7 @@ [ "$(ENTRY)_harness.goto", "$(FREERTOS_PLUS_TCP)/test/cbmc/stubs/cbmc.goto", + "$(FREERTOS_PLUS_TCP)/source/FreeRTOS_IPv6.goto", "$(FREERTOS_PLUS_TCP)/source/FreeRTOS_IPv6_Utils.goto" ], "INSTFLAGS": diff --git a/test/cbmc/stubs/freertos_api.c b/test/cbmc/stubs/freertos_api.c index a8fdfcf62a..db349a25ad 100644 --- a/test/cbmc/stubs/freertos_api.c +++ b/test/cbmc/stubs/freertos_api.c @@ -49,6 +49,21 @@ Socket_t FreeRTOS_socket( BaseType_t xDomain, } } +/**************************************************************** +* Abstract FreeRTOS_socket. +* https://www.freertos.org/FreeRTOS-Plus/FreeRTOS_Plus_TCP/API/socket.html +* +* We stub out this function to do nothing but allocate space for a +* socket containing unconstrained data or return an error. +****************************************************************/ + +BaseType_t FreeRTOS_listen( Socket_t xSocket, + BaseType_t xBacklog ) +{ + __CPROVER_assert( xSocket != NULL, "Socket cannot be NULL" ); + return nondet_BaseType(); +} + /**************************************************************** * Abstract FreeRTOS_setsockopt. * https://www.freertos.org/FreeRTOS-Plus/FreeRTOS_Plus_TCP/API/setsockopt.html @@ -135,30 +150,11 @@ int32_t FreeRTOS_recvfrom( Socket_t xSocket, __CPROVER_assert( pvBuffer != NULL, "FreeRTOS precondition: pvBuffer != NULL" ); - /**************************************************************** - * TODO: We need to check this out. - * - * The code calls recvfrom with these parameters NULL, it is not - * clear from the documentation that this is allowed. - ****************************************************************/ - #if 0 - __CPROVER_assert( pxSourceAddress != NULL, - "FreeRTOS precondition: pxSourceAddress != NULL" ); - __CPROVER_assert( pxSourceAddressLength != NULL, - "FreeRTOS precondition: pxSourceAddress != NULL" ); - #endif - size_t payload_size; __CPROVER_assume( payload_size + sizeof( UDPPacket_t ) < CBMC_MAX_OBJECT_SIZE ); - /**************************************************************** - * TODO: We need to make this lower bound explicit in the Makefile.json - * - * DNSMessage_t is a typedef in FreeRTOS_DNS.c - * sizeof(DNSMessage_t) = 6 * sizeof(uint16_t) - ****************************************************************/ - __CPROVER_assume( payload_size >= 6 * sizeof( uint16_t ) ); + __CPROVER_assume( payload_size >= sizeof( DNSMessage_t ) ); #ifdef CBMC_FREERTOS_RECVFROM_BUFFER_BOUND __CPROVER_assume( payload_size <= CBMC_FREERTOS_RECVFROM_BUFFER_BOUND ); @@ -407,3 +403,42 @@ BaseType_t xNetworkInterfaceOutput( NetworkBufferDescriptor_t * const pxNetworkB } /****************************************************************/ + +/**************************************************************** +* Abstract vIPSetARPResolutionTimerEnableState +****************************************************************/ +void vIPSetARPResolutionTimerEnableState( BaseType_t xEnableState ) +{ +} + +/****************************************************************/ + +/**************************************************************** +* Abstract vIPSetARPResolutionTimerEnableState +****************************************************************/ +BaseType_t xApplicationGetRandomNumber( uint32_t * pulNumber ) +{ + __CPROVER_assert( pulNumber != NULL, "The input number cannot be NULL" ); + + BaseType_t xReturn; + + *pulNumber = nondet_uint32(); + + /* Return some random value. */ + return xReturn; +} + +/****************************************************************/ + +/**************************************************************** +* Abstract vIPSetARPResolutionTimerEnableState +****************************************************************/ +uint32_t ulApplicationGetNextSequenceNumber( uint32_t ulSourceAddress, + uint16_t usSourcePort, + uint32_t ulDestinationAddress, + uint16_t usDestinationPort ) +{ + return nondet_uint32(); +} + +/****************************************************************/ diff --git a/test/cbmc/stubs/freertos_kernel_api.c b/test/cbmc/stubs/freertos_kernel_api.c index b74b4ec09c..79fd0ff822 100644 --- a/test/cbmc/stubs/freertos_kernel_api.c +++ b/test/cbmc/stubs/freertos_kernel_api.c @@ -80,3 +80,91 @@ EventBits_t xEventGroupSetBits( EventGroupHandle_t xEventGroup, } /****************************************************************/ + +/**************************************************************** +* Abstract xEventGroupSetBits +****************************************************************/ +void vEventGroupDelete( EventGroupHandle_t xEventGroup ) +{ +} + +/****************************************************************/ + +/**************************************************************** +* Abstract xEventGroupSetBits +****************************************************************/ +EventGroupHandle_t xEventGroupCreate( void ) +{ + EventGroupHandle_t xReturn; + + return xReturn; +} + +/****************************************************************/ + +/**************************************************************** +* Abstract xQueueGenericSend +****************************************************************/ +BaseType_t xQueueGenericSend( QueueHandle_t xQueue, + const void * const pvItemToQueue, + TickType_t xTicksToWait, + const BaseType_t xCopyPosition ) +{ + BaseType_t xReturn; + + __CPROVER_assume( ( xReturn == pdTRUE ) || ( xReturn == pdFALSE ) ); + + return xReturn; +} + +/****************************************************************/ + +/**************************************************************** +* Abstract uxQueueMessagesWaiting +****************************************************************/ +UBaseType_t uxQueueMessagesWaiting( const QueueHandle_t xQueue ) +{ + UBaseType_t uxReturn; + + __CPROVER_assume( uxReturn <= 2 ); + + return uxReturn; +} + +/****************************************************************/ + +/**************************************************************** +* Abstract vTaskSetTimeOutState +****************************************************************/ +void vTaskSetTimeOutState( TimeOut_t * const pxTimeOut ) +{ +} + +/****************************************************************/ + +/**************************************************************** +* Abstract xTaskCheckForTimeOut +****************************************************************/ +BaseType_t xTaskCheckForTimeOut( TimeOut_t * const pxTimeOut, + TickType_t * const pxTicksToWait ) +{ + BaseType_t xReturn; + + __CPROVER_assume( ( xReturn == pdTRUE ) || ( xReturn == pdFALSE ) ); + + return xReturn; +} + +/****************************************************************/ + +/**************************************************************** +* Abstract xTaskGetTickCount +****************************************************************/ +TickType_t xTaskGetTickCount( void ) +{ + TickType_t xReturn; + + return xReturn; +} + +/****************************************************************/ diff --git a/test/unit-test/CMakeLists.txt b/test/unit-test/CMakeLists.txt index 253cf45b2b..cac757688e 100644 --- a/test/unit-test/CMakeLists.txt +++ b/test/unit-test/CMakeLists.txt @@ -18,6 +18,12 @@ if( ${PROJECT_SOURCE_DIR} STREQUAL ${PROJECT_BINARY_DIR} ) message( FATAL_ERROR "In-source build is not allowed. Please build in a separate directory, such as ${PROJECT_SOURCE_DIR}/build." ) endif() +set(SANITIZE "" CACHE STRING "Comma-separated list of compiler sanitizers to enable; empty string disables.") +if(NOT ${SANITIZE} STREQUAL "") + add_compile_options(-fsanitize=${SANITIZE} -fno-sanitize-recover) + add_link_options(-fsanitize=${SANITIZE} -fno-sanitize-recover) +endif() + # Set global path variables. get_filename_component( __MODULE_ROOT_DIR "${CMAKE_CURRENT_LIST_DIR}/../.." ABSOLUTE ) set( MODULE_ROOT_DIR ${__MODULE_ROOT_DIR} CACHE INTERNAL "FreeRTOS-Plus-TCP repository root." ) diff --git a/test/unit-test/ConfigFiles/FreeRTOSIPConfig.h b/test/unit-test/ConfigFiles/FreeRTOSIPConfig.h index 09ddb181c6..2dc487b48c 100644 --- a/test/unit-test/ConfigFiles/FreeRTOSIPConfig.h +++ b/test/unit-test/ConfigFiles/FreeRTOSIPConfig.h @@ -306,6 +306,7 @@ #define ipconfigUSE_NBNS ( 1 ) #define ipconfigUSE_LLMNR ( 1 ) +#define ipconfigUSE_MDNS ( 1 ) #define ipconfigDNS_USE_CALLBACKS 1 #define ipconfigUSE_ARP_REMOVE_ENTRY 1 diff --git a/test/unit-test/FreeRTOS_ARP/FreeRTOS_ARP_stubs.c b/test/unit-test/FreeRTOS_ARP/FreeRTOS_ARP_stubs.c index 829eaa17e7..4bb309b72f 100644 --- a/test/unit-test/FreeRTOS_ARP/FreeRTOS_ARP_stubs.c +++ b/test/unit-test/FreeRTOS_ARP/FreeRTOS_ARP_stubs.c @@ -78,7 +78,7 @@ void vApplicationDaemonTaskStartupHook( void ) } void vApplicationGetTimerTaskMemory( StaticTask_t ** ppxTimerTaskTCBBuffer, StackType_t ** ppxTimerTaskStackBuffer, - uint32_t * pulTimerTaskStackSize ) + configSTACK_DEPTH_TYPE * puxTimerTaskStackSize ) { } void vPortDeleteThread( void * pvTaskToDelete ) @@ -125,7 +125,7 @@ void vPortCloseRunningThread( void * pvTaskToDelete, } void vApplicationGetIdleTaskMemory( StaticTask_t ** ppxIdleTaskTCBBuffer, StackType_t ** ppxIdleTaskStackBuffer, - uint32_t * pulIdleTaskStackSize ) + configSTACK_DEPTH_TYPE * puxIdleTaskStackSize ) { } void vConfigureTimerForRunTimeStats( void ) diff --git a/test/unit-test/FreeRTOS_ARP/FreeRTOS_ARP_utest.c b/test/unit-test/FreeRTOS_ARP/FreeRTOS_ARP_utest.c index ce017b622e..b0e3d04c1e 100644 --- a/test/unit-test/FreeRTOS_ARP/FreeRTOS_ARP_utest.c +++ b/test/unit-test/FreeRTOS_ARP/FreeRTOS_ARP_utest.c @@ -1923,7 +1923,7 @@ void test_vARPRefreshCacheEntry_IPAndMACInDifferentLocations1( void ) void test_eARPGetCacheEntryByMac_catchAssert( void ) { uint32_t ulIPAddress = 0x12345678, ulEntryToTest; - eARPLookupResult_t eResult; + eResolutionLookupResult_t eResult; MACAddress_t xMACAddress = { 0x22, 0x22, 0x22, 0x22, 0x22, 0x22 }; int i; struct xNetworkInterface * xInterface; @@ -1936,7 +1936,7 @@ void test_eARPGetCacheEntryByMac_catchAssert( void ) void test_eARPGetCacheEntryByMac_NullInterface( void ) { uint32_t ulIPAddress = 0x12345678, ulEntryToTest; - eARPLookupResult_t eResult; + eResolutionLookupResult_t eResult; MACAddress_t xMACAddress = { 0x22, 0x22, 0x22, 0x22, 0x22, 0x22 }; int i; struct xNetworkInterface * xInterface; @@ -1958,7 +1958,7 @@ void test_eARPGetCacheEntryByMac_NullInterface( void ) void test_eARPGetCacheEntryByMac_NoMatchingEntries( void ) { uint32_t ulIPAddress = 0x12345678, ulEntryToTest; - eARPLookupResult_t eResult; + eResolutionLookupResult_t eResult; MACAddress_t xMACAddress = { 0x22, 0x22, 0x22, 0x22, 0x22, 0x22 }; int i; struct xNetworkInterface * xInterface; @@ -1980,16 +1980,20 @@ void test_eARPGetCacheEntryByMac_NoMatchingEntries( void ) void test_eARPGetCacheEntryByMac_OneMatchingEntry( void ) { uint32_t ulIPAddress = 0x12345678, ulEntryToTest; - eARPLookupResult_t eResult; + eResolutionLookupResult_t eResult; MACAddress_t xMACAddress = { 0x22, 0x22, 0x22, 0x22, 0x22, 0x22 }; int i; - struct xNetworkInterface * xInterface; + NetworkEndPoint_t xNetworkEndPoint = { 0 }; + NetworkInterface_t xInterface, * pxInterface = NULL; + + xNetworkEndPoint.pxNetworkInterface = &xInterface; /* =================================================== */ /* Make sure one entry matches. */ for( i = 0; i < ipconfigARP_CACHE_ENTRIES; i++ ) { xARPCache[ i ].ulIPAddress = 0xAABBCCDD; + xARPCache[ i ].pxEndPoint = &xNetworkEndPoint; memset( xARPCache[ i ].xMACAddress.ucBytes, 0x11, sizeof( xMACAddress.ucBytes ) ); } @@ -1999,6 +2003,7 @@ void test_eARPGetCacheEntryByMac_OneMatchingEntry( void ) eResult = eARPGetCacheEntryByMac( &xMACAddress, &ulIPAddress, &xInterface ); TEST_ASSERT_EQUAL( eResolutionCacheHit, eResult ); TEST_ASSERT_EQUAL( xARPCache[ ulEntryToTest ].ulIPAddress, ulIPAddress ); + TEST_ASSERT_EQUAL( &xInterface, pxInterface ); /* =================================================== */ eResult = eARPGetCacheEntryByMac( &xMACAddress, &ulIPAddress, NULL ); TEST_ASSERT_EQUAL( eResolutionCacheHit, eResult ); @@ -2026,7 +2031,7 @@ void test_eARPGetCacheEntry_IPMatchesBroadcastAddr( void ) { uint32_t ulIPAddress; MACAddress_t xMACAddress; - eARPLookupResult_t eResult; + eResolutionLookupResult_t eResult; uint32_t ulSavedGatewayAddress; struct xNetworkEndPoint * pxEndPoint, xEndPoint; @@ -2048,7 +2053,7 @@ void test_eARPGetCacheEntry_IPMatchesBroadcastAddr_NullEndPointOnNetMask( void ) { uint32_t ulIPAddress; MACAddress_t xMACAddress; - eARPLookupResult_t eResult; + eResolutionLookupResult_t eResult; uint32_t ulSavedGatewayAddress; struct xNetworkEndPoint * pxEndPoint, xEndPoint; @@ -2069,7 +2074,7 @@ void test_eARPGetCacheEntry_MultiCastAddr( void ) { uint32_t ulIPAddress; MACAddress_t xMACAddress; - eARPLookupResult_t eResult; + eResolutionLookupResult_t eResult; uint32_t ulSavedGatewayAddress; struct xNetworkEndPoint * pxEndPoint, xEndPoint; @@ -2104,7 +2109,7 @@ void test_eARPGetCacheEntry_IPMatchesOtherBroadcastAddr( void ) { uint32_t ulIPAddress; MACAddress_t xMACAddress; - eARPLookupResult_t eResult; + eResolutionLookupResult_t eResult; uint32_t ulSavedGatewayAddress; struct xNetworkInterface * xInterface; struct xNetworkEndPoint * pxEndPoint, xEndPoint; @@ -2122,14 +2127,11 @@ void test_eARPGetCacheEntry_IPMatchesOtherBroadcastAddr( void ) /* =================================================== */ } -/* TODO: _TJ_: For the time being test_eARPGetCacheEntry_LocalIPIsZero and test_eARPGetCacheEntry_LocalIPMatchesReceivedIP */ -/* test cases are removed as we need to reevaluate if those cases are required for IPv6 */ - void test_eARPGetCacheEntry_MatchingInvalidEntry( void ) { uint32_t ulIPAddress; MACAddress_t xMACAddress; - eARPLookupResult_t eResult; + eResolutionLookupResult_t eResult; uint32_t ulSavedGatewayAddress; struct xNetworkInterface * xInterface; struct xNetworkEndPoint * pxEndPoint, xEndPoint; @@ -2158,7 +2160,7 @@ void test_eARPGetCacheEntry_MatchingValidEntry( void ) { uint32_t ulIPAddress; MACAddress_t xMACAddress; - eARPLookupResult_t eResult; + eResolutionLookupResult_t eResult; uint32_t ulSavedGatewayAddress; struct xNetworkInterface * xInterface; struct xNetworkEndPoint * pxEndPoint, xEndPoint; @@ -2188,7 +2190,7 @@ void test_eARPGetCacheEntry_GatewayAddressZero( void ) { uint32_t ulIPAddress; MACAddress_t xMACAddress; - eARPLookupResult_t eResult; + eResolutionLookupResult_t eResult; uint32_t ulSavedGatewayAddress; struct xNetworkInterface * xInterface; struct xNetworkEndPoint * pxEndPoint, xEndPoint; @@ -2219,7 +2221,7 @@ void test_eARPGetCacheEntry_AddressNotOnLocalAddress( void ) { uint32_t ulIPAddress; MACAddress_t xMACAddress; - eARPLookupResult_t eResult; + eResolutionLookupResult_t eResult; uint32_t ulSavedGatewayAddress; struct xNetworkInterface * xInterface; struct xNetworkEndPoint * pxEndPoint, xEndPoint; @@ -2246,7 +2248,7 @@ void test_eARPGetCacheEntry_NoCacheHit( void ) { uint32_t ulIPAddress; MACAddress_t xMACAddress; - eARPLookupResult_t eResult; + eResolutionLookupResult_t eResult; uint32_t ulSavedGatewayAddress; struct xNetworkInterface * xInterface; struct xNetworkEndPoint * pxEndPoint, xEndPoint; @@ -2257,6 +2259,7 @@ void test_eARPGetCacheEntry_NoCacheHit( void ) { xARPCache[ i ].ulIPAddress = 0; xARPCache[ i ].ucValid = ( uint8_t ) pdTRUE; + xARPCache[ i ].pxEndPoint = NULL; } ulSavedGatewayAddress = xNetworkAddressing.ulGatewayAddress; @@ -2323,7 +2326,7 @@ void test_vARPAgeCache( void ) xARPCache[ ucEntryToCheck ].ulIPAddress = 0xAAAAAAAA; xARPCache[ ucEntryToCheck ].pxEndPoint = &xEndPoint; - FreeRTOS_FindEndPointOnNetMask_ExpectAndReturn( xARPCache[ ucEntryToCheck ].ulIPAddress, 12, &xEndPoint ); + FreeRTOS_FindEndPointOnNetMask_ExpectAndReturn( xARPCache[ ucEntryToCheck ].ulIPAddress, &xEndPoint ); /* The function which calls 'pxGetNetworkBufferWithDescriptor' is 'FreeRTOS_OutputARPRequest'. * It doesn't return anything and will be tested separately. */ @@ -2346,7 +2349,7 @@ void test_vARPAgeCache( void ) /* Set an IP address */ xARPCache[ ucEntryToCheck ].ulIPAddress = 0xAAAAAAAA; - FreeRTOS_FindEndPointOnNetMask_ExpectAndReturn( xARPCache[ ucEntryToCheck ].ulIPAddress, 12, &xEndPoint ); + FreeRTOS_FindEndPointOnNetMask_ExpectAndReturn( xARPCache[ ucEntryToCheck ].ulIPAddress, &xEndPoint ); /* The function which calls 'pxGetNetworkBufferWithDescriptor' is 'FreeRTOS_OutputARPRequest'. * It doesn't return anything and will be tested separately. */ @@ -2452,7 +2455,7 @@ void test_FreeRTOS_OutputARPRequest( void ) /* =================================================== */ - FreeRTOS_FindEndPointOnNetMask_ExpectAndReturn( ulIPAddress, 12, &xEndPoint ); + FreeRTOS_FindEndPointOnNetMask_ExpectAndReturn( ulIPAddress, &xEndPoint ); pxGetNetworkBufferWithDescriptor_ExpectAndReturn( sizeof( ARPPacket_t ), 0, &xNetworkBuffer ); @@ -2465,7 +2468,7 @@ void test_FreeRTOS_OutputARPRequest( void ) xNetworkInterfaceOutput_ARP_STUB_CallCount = 0; - FreeRTOS_FindEndPointOnNetMask_ExpectAndReturn( ulIPAddress, 12, &xEndPoint ); + FreeRTOS_FindEndPointOnNetMask_ExpectAndReturn( ulIPAddress, &xEndPoint ); pxGetNetworkBufferWithDescriptor_ExpectAndReturn( sizeof( ARPPacket_t ), 0, &xNetworkBuffer ); @@ -2479,7 +2482,7 @@ void test_FreeRTOS_OutputARPRequest( void ) /* =================================================== */ xNetworkInterfaceOutput_ARP_STUB_CallCount = 0; - FreeRTOS_FindEndPointOnNetMask_ExpectAndReturn( ulIPAddress, 12, &xEndPoint ); + FreeRTOS_FindEndPointOnNetMask_ExpectAndReturn( ulIPAddress, &xEndPoint ); pxGetNetworkBufferWithDescriptor_ExpectAndReturn( sizeof( ARPPacket_t ), 0, &xNetworkBuffer ); xIsCallingFromIPTask_IgnoreAndReturn( pdFALSE ); @@ -2495,7 +2498,7 @@ void test_FreeRTOS_OutputARPRequest( void ) /* =================================================== */ xEndPoint.pxNetworkInterface = NULL; - FreeRTOS_FindEndPointOnNetMask_ExpectAndReturn( ulIPAddress, 12, &xEndPoint ); + FreeRTOS_FindEndPointOnNetMask_ExpectAndReturn( ulIPAddress, &xEndPoint ); pxGetNetworkBufferWithDescriptor_ExpectAndReturn( sizeof( ARPPacket_t ), 0, &xNetworkBuffer ); xIsCallingFromIPTask_IgnoreAndReturn( pdTRUE ); @@ -2510,7 +2513,7 @@ void test_FreeRTOS_OutputARPRequest( void ) /* =================================================== */ xNetworkBuffer.xDataLength = ( size_t ) ipconfigETHERNET_MINIMUM_PACKET_BYTES; - FreeRTOS_FindEndPointOnNetMask_ExpectAndReturn( ulIPAddress, 12, &xEndPoint ); + FreeRTOS_FindEndPointOnNetMask_ExpectAndReturn( ulIPAddress, &xEndPoint ); pxGetNetworkBufferWithDescriptor_ExpectAndReturn( sizeof( ARPPacket_t ), 0, &xNetworkBuffer ); xIsCallingFromIPTask_IgnoreAndReturn( pdTRUE ); @@ -2526,7 +2529,7 @@ void test_FreeRTOS_OutputARPRequest( void ) /* =================================================== */ xEndPoint.bits.bIPv6 = 1; - FreeRTOS_FindEndPointOnNetMask_ExpectAndReturn( ulIPAddress, 12, &xEndPoint ); + FreeRTOS_FindEndPointOnNetMask_ExpectAndReturn( ulIPAddress, &xEndPoint ); FreeRTOS_OutputARPRequest( ulIPAddress ); TEST_ASSERT_EQUAL( xNetworkInterfaceOutput_ARP_STUB_CallCount, 0 ); @@ -2538,7 +2541,7 @@ void test_FreeRTOS_OutputARPRequest( void ) xEndPoint.bits.bIPv6 = 0; xEndPoint.ipv4_settings.ulIPAddress = 0U; - FreeRTOS_FindEndPointOnNetMask_ExpectAndReturn( ulIPAddress, 12, &xEndPoint ); + FreeRTOS_FindEndPointOnNetMask_ExpectAndReturn( ulIPAddress, &xEndPoint ); FreeRTOS_OutputARPRequest( ulIPAddress ); TEST_ASSERT_EQUAL( xNetworkInterfaceOutput_ARP_STUB_CallCount, 0 ); @@ -2552,7 +2555,7 @@ void test_FreeRTOS_OutputARPRequest_NullEndpoint( void ) { uint32_t ulIPAddress = 0x1234ABCD; - FreeRTOS_FindEndPointOnNetMask_ExpectAndReturn( ulIPAddress, 12, NULL ); + FreeRTOS_FindEndPointOnNetMask_ExpectAndReturn( ulIPAddress, NULL ); FreeRTOS_OutputARPRequest( ulIPAddress ); } @@ -2633,7 +2636,7 @@ void test_xARPWaitResolution_GNWFailsNoTimeout( void ) /* Make sure that there are enough stubs for all the repetitive calls. */ for( i = 0; i < ipconfigMAX_ARP_RETRANSMISSIONS; i++ ) { - FreeRTOS_FindEndPointOnNetMask_ExpectAndReturn( ulIPAddress, 12, &xEndPoint ); + FreeRTOS_FindEndPointOnNetMask_ExpectAndReturn( ulIPAddress, &xEndPoint ); pxGetNetworkBufferWithDescriptor_ExpectAndReturn( sizeof( ARPPacket_t ), 0, NULL ); vTaskDelay_Expect( pdMS_TO_TICKS( 250U ) ); FreeRTOS_FindEndPointOnIP_IPv4_ExpectAnyArgsAndReturn( NULL ); @@ -2684,7 +2687,7 @@ void test_xARPWaitResolution( void ) /* Make sure that there are enough stubs for all the repetitive calls. */ for( i = 0; i < ( ipconfigMAX_ARP_RETRANSMISSIONS - 1 ); i++ ) { - FreeRTOS_FindEndPointOnNetMask_ExpectAndReturn( ulIPAddress, 12, &xEndPoint ); + FreeRTOS_FindEndPointOnNetMask_ExpectAndReturn( ulIPAddress, &xEndPoint ); pxGetNetworkBufferWithDescriptor_ExpectAndReturn( sizeof( ARPPacket_t ), 0, NULL ); vTaskDelay_Expect( pdMS_TO_TICKS( 250U ) ); FreeRTOS_FindEndPointOnIP_IPv4_ExpectAnyArgsAndReturn( NULL ); @@ -2693,7 +2696,7 @@ void test_xARPWaitResolution( void ) xTaskCheckForTimeOut_IgnoreAndReturn( pdFALSE ); } - FreeRTOS_FindEndPointOnNetMask_ExpectAndReturn( ulIPAddress, 12, &xEndPoint ); + FreeRTOS_FindEndPointOnNetMask_ExpectAndReturn( ulIPAddress, &xEndPoint ); pxGetNetworkBufferWithDescriptor_ExpectAndReturn( sizeof( ARPPacket_t ), 0, NULL ); vTaskDelay_Expect( pdMS_TO_TICKS( 250U ) ); FreeRTOS_FindEndPointOnIP_IPv4_ExpectAnyArgsAndReturn( NULL ); @@ -2732,7 +2735,7 @@ void test_xARPWaitResolution( void ) /* Make sure that there are enough stubs for all the repetitive calls. */ for( i = 0; i < ( ipconfigMAX_ARP_RETRANSMISSIONS - 2 ); i++ ) { - FreeRTOS_FindEndPointOnNetMask_ExpectAndReturn( ulIPAddress, 12, &xEndPoint ); + FreeRTOS_FindEndPointOnNetMask_ExpectAndReturn( ulIPAddress, &xEndPoint ); pxGetNetworkBufferWithDescriptor_ExpectAndReturn( sizeof( ARPPacket_t ), 0, NULL ); vTaskDelay_Expect( pdMS_TO_TICKS( 250U ) ); FreeRTOS_FindEndPointOnIP_IPv4_ExpectAnyArgsAndReturn( NULL ); @@ -2741,7 +2744,7 @@ void test_xARPWaitResolution( void ) xTaskCheckForTimeOut_IgnoreAndReturn( pdFALSE ); } - FreeRTOS_FindEndPointOnNetMask_ExpectAndReturn( ulIPAddress, 12, &xEndPoint ); + FreeRTOS_FindEndPointOnNetMask_ExpectAndReturn( ulIPAddress, &xEndPoint ); pxGetNetworkBufferWithDescriptor_ExpectAndReturn( sizeof( ARPPacket_t ), 0, NULL ); vTaskDelay_Expect( pdMS_TO_TICKS( 250U ) ); FreeRTOS_FindEndPointOnIP_IPv4_ExpectAnyArgsAndReturn( NULL ); diff --git a/test/unit-test/FreeRTOS_ARP_DataLenLessThanMinPacket/FreeRTOS_ARP_DataLenLessThanMinPacket_stubs.c b/test/unit-test/FreeRTOS_ARP_DataLenLessThanMinPacket/FreeRTOS_ARP_DataLenLessThanMinPacket_stubs.c index a8f3bca4e7..3b5e529963 100644 --- a/test/unit-test/FreeRTOS_ARP_DataLenLessThanMinPacket/FreeRTOS_ARP_DataLenLessThanMinPacket_stubs.c +++ b/test/unit-test/FreeRTOS_ARP_DataLenLessThanMinPacket/FreeRTOS_ARP_DataLenLessThanMinPacket_stubs.c @@ -74,7 +74,7 @@ void vApplicationDaemonTaskStartupHook( void ) } void vApplicationGetTimerTaskMemory( StaticTask_t ** ppxTimerTaskTCBBuffer, StackType_t ** ppxTimerTaskStackBuffer, - uint32_t * pulTimerTaskStackSize ) + configSTACK_DEPTH_TYPE * puxTimerTaskStackSize ) { } void vPortDeleteThread( void * pvTaskToDelete ) @@ -121,7 +121,7 @@ void vPortCloseRunningThread( void * pvTaskToDelete, } void vApplicationGetIdleTaskMemory( StaticTask_t ** ppxIdleTaskTCBBuffer, StackType_t ** ppxIdleTaskStackBuffer, - uint32_t * pulIdleTaskStackSize ) + configSTACK_DEPTH_TYPE * puxIdleTaskStackSize ) { } void vConfigureTimerForRunTimeStats( void ) diff --git a/test/unit-test/FreeRTOS_ARP_DataLenLessThanMinPacket/FreeRTOS_ARP_DataLenLessThanMinPacket_utest.c b/test/unit-test/FreeRTOS_ARP_DataLenLessThanMinPacket/FreeRTOS_ARP_DataLenLessThanMinPacket_utest.c index 34b55c43b4..75b5515015 100644 --- a/test/unit-test/FreeRTOS_ARP_DataLenLessThanMinPacket/FreeRTOS_ARP_DataLenLessThanMinPacket_utest.c +++ b/test/unit-test/FreeRTOS_ARP_DataLenLessThanMinPacket/FreeRTOS_ARP_DataLenLessThanMinPacket_utest.c @@ -54,7 +54,7 @@ void test_FreeRTOS_OutputARPRequest_MinimumPacketSizeLessThanARPPacket( void ) /* =================================================== */ - FreeRTOS_FindEndPointOnNetMask_ExpectAndReturn( ulIPAddress, 12, &xEndPoint ); + FreeRTOS_FindEndPointOnNetMask_ExpectAndReturn( ulIPAddress, &xEndPoint ); pxGetNetworkBufferWithDescriptor_ExpectAndReturn( sizeof( ARPPacket_t ), 0, &xNetworkBuffer ); xIsCallingFromIPTask_IgnoreAndReturn( pdTRUE ); diff --git a/test/unit-test/FreeRTOS_DHCP/FreeRTOS_DHCP_stubs.c b/test/unit-test/FreeRTOS_DHCP/FreeRTOS_DHCP_stubs.c index 0556507109..c3a2dd4e83 100644 --- a/test/unit-test/FreeRTOS_DHCP/FreeRTOS_DHCP_stubs.c +++ b/test/unit-test/FreeRTOS_DHCP/FreeRTOS_DHCP_stubs.c @@ -12,6 +12,11 @@ #include "FreeRTOS_IP.h" #include "FreeRTOS_IP_Private.h" +#define prvROUND_UP_TO( SIZE, ALIGNMENT ) ( ( ( SIZE ) + ( ALIGNMENT ) -1 ) / ( ALIGNMENT ) *( ALIGNMENT ) ) + +/* FIXME: Consider instead fixing ipBUFFER_PADDING if it's supposed to be pointer aligned. */ +#define prvALIGNED_BUFFER_PADDING prvROUND_UP_TO( ipBUFFER_PADDING, sizeof( void * ) ) + struct xNetworkEndPoint * pxNetworkEndPoints = NULL; NetworkInterface_t xInterfaces[ 1 ]; @@ -129,7 +134,7 @@ void vApplicationDaemonTaskStartupHook( void ) } void vApplicationGetTimerTaskMemory( StaticTask_t ** ppxTimerTaskTCBBuffer, StackType_t ** ppxTimerTaskStackBuffer, - uint32_t * pulTimerTaskStackSize ) + configSTACK_DEPTH_TYPE * puxTimerTaskStackSize ) { } void vPortDeleteThread( void * pvTaskToDelete ) @@ -176,7 +181,7 @@ void vPortCloseRunningThread( void * pvTaskToDelete, } void vApplicationGetIdleTaskMemory( StaticTask_t ** ppxIdleTaskTCBBuffer, StackType_t ** ppxIdleTaskStackBuffer, - uint32_t * pulIdleTaskStackSize ) + configSTACK_DEPTH_TYPE * puxIdleTaskStackSize ) { } void vConfigureTimerForRunTimeStats( void ) @@ -212,9 +217,9 @@ static NetworkBufferDescriptor_t * GetNetworkBuffer( size_t SizeOfEthBuf, long unsigned int xTimeToBlock, int callbacks ) { - NetworkBufferDescriptor_t * pxNetworkBuffer = malloc( sizeof( NetworkBufferDescriptor_t ) + ipBUFFER_PADDING ) + ipBUFFER_PADDING; + NetworkBufferDescriptor_t * pxNetworkBuffer = malloc( sizeof( NetworkBufferDescriptor_t ) + prvALIGNED_BUFFER_PADDING ) + prvALIGNED_BUFFER_PADDING; - pxNetworkBuffer->pucEthernetBuffer = malloc( SizeOfEthBuf + ipBUFFER_PADDING ) + ipBUFFER_PADDING; + pxNetworkBuffer->pucEthernetBuffer = malloc( SizeOfEthBuf + prvALIGNED_BUFFER_PADDING ) + prvALIGNED_BUFFER_PADDING; /* Ignore the callback count. */ ( void ) callbacks; @@ -230,9 +235,9 @@ static NetworkBufferDescriptor_t * GetNetworkBuffer( size_t SizeOfEthBuf, static void ReleaseNetworkBuffer( void ) { /* Free the ethernet buffer. */ - free( ( ( uint8_t * ) pxGlobalNetworkBuffer[ --GlobalBufferCounter ]->pucEthernetBuffer ) - ipBUFFER_PADDING ); + free( ( ( uint8_t * ) pxGlobalNetworkBuffer[ --GlobalBufferCounter ]->pucEthernetBuffer ) - prvALIGNED_BUFFER_PADDING ); /* Free the network buffer. */ - free( ( ( uint8_t * ) pxGlobalNetworkBuffer[ GlobalBufferCounter ] ) - ipBUFFER_PADDING ); + free( ( ( uint8_t * ) pxGlobalNetworkBuffer[ GlobalBufferCounter ] ) - prvALIGNED_BUFFER_PADDING ); } static void ReleaseUDPBuffer( const void * temp, @@ -289,19 +294,19 @@ static int32_t FreeRTOS_recvfrom_Generic( const ConstSocket_t xSocket, return ulGenericLength; } -static int32_t FreeRTOS_recvfrom_Generic_NullBuffer( const ConstSocket_t xSocket, - void * pvBuffer, - size_t uxBufferLength, - BaseType_t xFlags, - struct freertos_sockaddr * pxSourceAddress, - socklen_t * pxSourceAddressLength, - int callbacks ) +static int32_t FreeRTOS_recvfrom_Small_NullBuffer( const ConstSocket_t xSocket, + void * pvBuffer, + size_t uxBufferLength, + BaseType_t xFlags, + struct freertos_sockaddr * pxSourceAddress, + socklen_t * pxSourceAddressLength, + int callbacks ) { - pvBuffer = NULL; - return xSizeofUDPBuffer; + /* Admittedly, returning a (NULL, 1) slice is contrived, but coverage speaks. */ + *( ( uint8_t ** ) pvBuffer ) = NULL; + return 1; } - static int32_t FreeRTOS_recvfrom_eWaitingOfferRecvfromLessBytesNoTimeout( const ConstSocket_t xSocket, void * pvBuffer, size_t uxBufferLength, @@ -336,7 +341,7 @@ static int32_t FreeRTOS_recvfrom_ResetAndIncorrectStateWithSocketAlreadyCreated_ pxIterator = pxIterator->pxNext; } - if( xFlags == FREERTOS_ZERO_COPY + FREERTOS_MSG_PEEK ) + if( ( xFlags & FREERTOS_ZERO_COPY ) != 0 ) { *( ( uint8_t ** ) pvBuffer ) = pucUDPBuffer; } diff --git a/test/unit-test/FreeRTOS_DHCP/FreeRTOS_DHCP_utest.c b/test/unit-test/FreeRTOS_DHCP/FreeRTOS_DHCP_utest.c index 7da21e3584..dfe97e4038 100644 --- a/test/unit-test/FreeRTOS_DHCP/FreeRTOS_DHCP_utest.c +++ b/test/unit-test/FreeRTOS_DHCP/FreeRTOS_DHCP_utest.c @@ -53,6 +53,38 @@ extern uint8_t pucUDPBuffer[]; extern uint8_t DHCP_header[]; +/*-------------------------------------Helpers--------------------------------*/ + +static void prvWriteDHCPOption( uint8_t ** ppucBuf, + uint8_t ucOp, + const void * pvPayload, + uint8_t ucLen ) +{ + uint8_t * pucBuf = *ppucBuf; + + *pucBuf++ = ucOp; + *pucBuf++ = ucLen; + memcpy( pucBuf, pvPayload, ucLen ); + pucBuf += ucLen; + + *ppucBuf = pucBuf; +} + +static void prvWriteDHCPOptionU8( uint8_t ** ppucBuf, + uint8_t ucOp, + uint8_t ucPayload ) +{ + prvWriteDHCPOption( ppucBuf, ucOp, &ucPayload, sizeof( ucPayload ) ); +} + +static void prvWriteDHCPOptionU32( uint8_t ** ppucBuf, + uint8_t ucOp, + uint32_t ulPayload ) +{ + /* TBD: htonl(ulPayload)? */ + prvWriteDHCPOption( ppucBuf, ucOp, &ulPayload, sizeof( ulPayload ) ); +} + /*---------------------------------------Test Cases--------------------------*/ void test_xIsDHCPSocket( void ) { @@ -1554,9 +1586,7 @@ void test_vDHCPProcessEndPoint_eWaitingOfferNullUDPBuffer( void ) pxNetworkEndPoints = pxEndPoint; - FreeRTOS_recvfrom_ExpectAndReturn( xDHCPv4Socket, NULL, 0UL, FREERTOS_ZERO_COPY, NULL, NULL, 1 ); - /* Ignore the buffer argument though. */ - FreeRTOS_recvfrom_IgnoreArg_pvBuffer(); + FreeRTOS_recvfrom_Stub( FreeRTOS_recvfrom_Small_NullBuffer ); vDHCPProcessEndPoint( pdFALSE, pdTRUE, pxEndPoint ); } @@ -2654,7 +2684,7 @@ void test_vDHCPProcess_eWaitingOfferCorrectDHCPMessageTwoOptionsSendFails( void /* Add length. */ DHCPOption[ 1 ] = 4; /* Add the offer byte. */ - *( ( uint32_t * ) &DHCPOption[ 2 ] ) = DHCPServerAddress; + memcpy( &DHCPOption[ 2 ], &DHCPServerAddress, sizeof( DHCPServerAddress ) ); /* Put the information in global variables to be returned by @@ -2751,7 +2781,7 @@ void test_vDHCPProcess_eWaitingOfferCorrectDHCPMessageTwoOptionsSendSucceeds( vo /* Add length. */ DHCPOption[ 1 ] = 4; /* Add the offer byte. */ - *( ( uint32_t * ) &DHCPOption[ 2 ] ) = DHCPServerAddress; + memcpy( &DHCPOption[ 2 ], &DHCPServerAddress, sizeof( DHCPServerAddress ) ); /* Put the information in global variables to be returned by @@ -2853,7 +2883,7 @@ void test_vDHCPProcess_eWaitingOfferCorrectDHCPMessageTwoOptionsDHCPHookReturnDe /* Add length. */ DHCPOption[ 1 ] = 4; /* Add the offer byte. */ - *( ( uint32_t * ) &DHCPOption[ 2 ] ) = DHCPServerAddress; + memcpy( &DHCPOption[ 2 ], &DHCPServerAddress, sizeof( DHCPServerAddress ) ); /* Put the information in global variables to be returned by @@ -2952,7 +2982,7 @@ void test_vDHCPProcess_eWaitingOfferCorrectDHCPMessageTwoOptionsDHCPHookReturnEr /* Add length. */ DHCPOption[ 1 ] = 4; /* Add the offer byte. */ - *( ( uint32_t * ) &DHCPOption[ 2 ] ) = DHCPServerAddress; + memcpy( &DHCPOption[ 2 ], &DHCPServerAddress, sizeof( DHCPServerAddress ) ); /* Put the information in global variables to be returned by @@ -3052,7 +3082,7 @@ void test_vDHCPProcess_eWaitingAcknowledgeTwoOptionsIncorrectServerNoTimeout( vo /* Add length. */ DHCPOption[ 1 ] = 4; /* Add the offer byte. */ - *( ( uint32_t * ) &DHCPOption[ 2 ] ) = DHCPServerAddress; + memcpy( &DHCPOption[ 2 ], &DHCPServerAddress, sizeof( DHCPServerAddress ) ); /* Put the information in global variables to be returned by * the FreeRTOS_recvrom. */ @@ -3137,7 +3167,7 @@ void test_vDHCPProcess_eWaitingAcknowledgeTwoOptionsIncorrectServerTimeoutGNBfai /* Add length. */ DHCPOption[ 1 ] = 4; /* Add the offer byte. */ - *( ( uint32_t * ) &DHCPOption[ 2 ] ) = DHCPServerAddress; + memcpy( &DHCPOption[ 2 ], &DHCPServerAddress, sizeof( DHCPServerAddress ) ); /* Put the information in global variables to be returned by * the FreeRTOS_recvrom. */ @@ -3227,7 +3257,7 @@ void test_vDHCPProcess_eWaitingAcknowledgeTwoOptionsIncorrectServerTimeoutGNBSuc /* Add length. */ DHCPOption[ 1 ] = 4; /* Add the offer byte. */ - *( ( uint32_t * ) &DHCPOption[ 2 ] ) = DHCPServerAddress; + memcpy( &DHCPOption[ 2 ], &DHCPServerAddress, sizeof( DHCPServerAddress ) ); /* Put the information in global variables to be returned by @@ -3322,7 +3352,7 @@ void test_vDHCPProcess_eWaitingAcknowledgeTwoOptionsIncorrectServerTimeoutPeriod /* Add length. */ DHCPOption[ 1 ] = 4; /* Add the offer byte. */ - *( ( uint32_t * ) &DHCPOption[ 2 ] ) = DHCPServerAddress; + memcpy( &DHCPOption[ 2 ], &DHCPServerAddress, sizeof( DHCPServerAddress ) ); /* Put the information in global variables to be returned by @@ -3407,7 +3437,7 @@ void test_vDHCPProcess_eWaitingAcknowledgeTwoOptionsIncorrectServerTimeoutPeriod /* Add length. */ DHCPOption[ 1 ] = 4; /* Add the offer byte. */ - *( ( uint32_t * ) &DHCPOption[ 2 ] ) = DHCPServerAddress; + memcpy( &DHCPOption[ 2 ], &DHCPServerAddress, sizeof( DHCPServerAddress ) ); /* Put the information in global variables to be returned by @@ -3493,7 +3523,7 @@ void test_vDHCPProcess_eWaitingAcknowledgeTwoOptionsCorrectServerLeaseTimeZero( /* Add length. */ DHCPOption[ 1 ] = 4; /* Add the offer byte. */ - *( ( uint32_t * ) &DHCPOption[ 2 ] ) = DHCPServerAddress; + memcpy( &DHCPOption[ 2 ], &DHCPServerAddress, sizeof( DHCPServerAddress ) ); /* Put the information in global variables to be returned by @@ -3594,7 +3624,7 @@ void test_vDHCPProcess_eWaitingAcknowledgeTwoOptionsCorrectServerLeaseTimeLessTh /* Add length. */ DHCPOption[ 1 ] = 4; /* Add the offer byte. */ - *( ( uint32_t * ) &DHCPOption[ 2 ] ) = DHCPServerAddress; + memcpy( &DHCPOption[ 2 ], &DHCPServerAddress, sizeof( DHCPServerAddress ) ); /* Put the information in global variables to be returned by @@ -3693,7 +3723,7 @@ void test_vDHCPProcess_eWaitingAcknowledge_TwoOptions_CorrectServer_AptLeaseTime /* Add length. */ DHCPOption[ 1 ] = 4; /* Add the offer byte. */ - *( ( uint32_t * ) &DHCPOption[ 2 ] ) = DHCPServerAddress; + memcpy( &DHCPOption[ 2 ], &DHCPServerAddress, sizeof( DHCPServerAddress ) ); /* Put the information in global variables to be returned by @@ -3791,7 +3821,7 @@ void test_vDHCPProcess_eWaitingAcknowledge_TwoOptions_NACK( void ) /* Add length. */ DHCPOption[ 1 ] = 4; /* Add the offer byte. */ - *( ( uint32_t * ) &DHCPOption[ 2 ] ) = DHCPServerAddress; + memcpy( &DHCPOption[ 2 ], &DHCPServerAddress, sizeof( DHCPServerAddress ) ); /* Put the information in global variables to be returned by @@ -3878,7 +3908,7 @@ void test_vDHCPProcess_eWaitingAcknowledge_TwoOptions_OFFER( void ) /* Add length. */ DHCPOption[ 1 ] = 4; /* Add the offer byte. */ - *( ( uint32_t * ) &DHCPOption[ 2 ] ) = DHCPServerAddress; + memcpy( &DHCPOption[ 2 ], &DHCPServerAddress, sizeof( DHCPServerAddress ) ); /* Put the information in global variables to be returned by @@ -3980,7 +4010,7 @@ void test_vDHCPProcess_eWaitingAcknowledge_AllOptionsCorrectLength( void ) /* Add length. */ DHCPOption[ 1 ] = 4; /* Add the offer byte. */ - *( ( uint32_t * ) &DHCPOption[ 2 ] ) = DHCPServerAddress; + memcpy( &DHCPOption[ 2 ], &DHCPServerAddress, sizeof( DHCPServerAddress ) ); DHCPOption += 6; /* Add Message type code. */ @@ -3988,7 +4018,7 @@ void test_vDHCPProcess_eWaitingAcknowledge_AllOptionsCorrectLength( void ) /* Add length. */ DHCPOption[ 1 ] = 4; /* Add the offer byte. */ - *( ( uint32_t * ) &DHCPOption[ 2 ] ) = ulSubnetMask; + memcpy( &DHCPOption[ 2 ], &ulSubnetMask, sizeof( ulSubnetMask ) ); DHCPOption += 6; /* Add Message type code. */ @@ -3996,7 +4026,7 @@ void test_vDHCPProcess_eWaitingAcknowledge_AllOptionsCorrectLength( void ) /* Add length. */ DHCPOption[ 1 ] = 4; /* Add the offer byte. */ - *( ( uint32_t * ) &DHCPOption[ 2 ] ) = ulGateway; + memcpy( &DHCPOption[ 2 ], &ulGateway, sizeof( ulGateway ) ); DHCPOption += 6; /* Add Message type code. */ @@ -4004,7 +4034,7 @@ void test_vDHCPProcess_eWaitingAcknowledge_AllOptionsCorrectLength( void ) /* Add length. */ DHCPOption[ 1 ] = 4; /* Add the offer byte. */ - *( ( uint32_t * ) &DHCPOption[ 2 ] ) = ulLeaseTime; + memcpy( &DHCPOption[ 2 ], &ulLeaseTime, sizeof( ulLeaseTime ) ); DHCPOption += 6; /* Add Message type code. */ @@ -4012,7 +4042,7 @@ void test_vDHCPProcess_eWaitingAcknowledge_AllOptionsCorrectLength( void ) /* Add length. */ DHCPOption[ 1 ] = 4; /* Add the offer byte. */ - *( ( uint32_t * ) &DHCPOption[ 2 ] ) = ulDNSServer; + memcpy( &DHCPOption[ 2 ], &ulDNSServer, sizeof( ulDNSServer ) ); /* Put the information in global variables to be returned by @@ -4126,7 +4156,7 @@ void test_vDHCPProcess_eWaitingAcknowledge_AllOptionsCorrectLength2( void ) /* Add length. */ DHCPOption[ 1 ] = 4; /* Add the offer byte. */ - *( ( uint32_t * ) &DHCPOption[ 2 ] ) = DHCPServerAddress; + memcpy( &DHCPOption[ 2 ], &DHCPServerAddress, sizeof( DHCPServerAddress ) ); DHCPOption += 6; /* Add Message type code. */ @@ -4134,7 +4164,7 @@ void test_vDHCPProcess_eWaitingAcknowledge_AllOptionsCorrectLength2( void ) /* Add length. */ DHCPOption[ 1 ] = 4; /* Add the offer byte. */ - *( ( uint32_t * ) &DHCPOption[ 2 ] ) = ulSubnetMask; + memcpy( &DHCPOption[ 2 ], &ulSubnetMask, sizeof( ulSubnetMask ) ); DHCPOption += 6; /* Add Message type code. */ @@ -4142,7 +4172,7 @@ void test_vDHCPProcess_eWaitingAcknowledge_AllOptionsCorrectLength2( void ) /* Add length. */ DHCPOption[ 1 ] = 4; /* Add the offer byte. */ - *( ( uint32_t * ) &DHCPOption[ 2 ] ) = ulGateway; + memcpy( &DHCPOption[ 2 ], &ulGateway, sizeof( ulGateway ) ); DHCPOption += 6; /* Add Message type code. */ @@ -4150,7 +4180,7 @@ void test_vDHCPProcess_eWaitingAcknowledge_AllOptionsCorrectLength2( void ) /* Add length. */ DHCPOption[ 1 ] = 4; /* Add the offer byte. */ - *( ( uint32_t * ) &DHCPOption[ 2 ] ) = ulLeaseTime; + memcpy( &DHCPOption[ 2 ], &ulLeaseTime, sizeof( ulLeaseTime ) ); DHCPOption += 6; /* Add Message type code. */ @@ -4158,7 +4188,7 @@ void test_vDHCPProcess_eWaitingAcknowledge_AllOptionsCorrectLength2( void ) /* Add length. */ DHCPOption[ 1 ] = 4; /* Add the offer byte. */ - *( ( uint32_t * ) &DHCPOption[ 2 ] ) = ulDNSServer; + memcpy( &DHCPOption[ 2 ], &ulDNSServer, sizeof( ulDNSServer ) ); /* Put the information in global variables to be returned by @@ -4273,7 +4303,7 @@ void test_vDHCPProcess_eWaitingAcknowledge_DNSIncorrectLength( void ) /* Add length. */ DHCPOption[ 1 ] = 4; /* Add the offer byte. */ - *( ( uint32_t * ) &DHCPOption[ 2 ] ) = DHCPServerAddress; + memcpy( &DHCPOption[ 2 ], &DHCPServerAddress, sizeof( DHCPServerAddress ) ); DHCPOption += 6; /* Add Message type code. */ @@ -4281,7 +4311,7 @@ void test_vDHCPProcess_eWaitingAcknowledge_DNSIncorrectLength( void ) /* Add length. */ DHCPOption[ 1 ] = 4; /* Add the offer byte. */ - *( ( uint32_t * ) &DHCPOption[ 2 ] ) = ulSubnetMask; + memcpy( &DHCPOption[ 2 ], &ulSubnetMask, sizeof( ulSubnetMask ) ); DHCPOption += 6; /* Add Message type code. */ @@ -4289,7 +4319,7 @@ void test_vDHCPProcess_eWaitingAcknowledge_DNSIncorrectLength( void ) /* Add length. */ DHCPOption[ 1 ] = 4; /* Add the offer byte. */ - *( ( uint32_t * ) &DHCPOption[ 2 ] ) = ulGateway; + memcpy( &DHCPOption[ 2 ], &ulGateway, sizeof( ulGateway ) ); DHCPOption += 6; /* Add Message type code. */ @@ -4297,7 +4327,7 @@ void test_vDHCPProcess_eWaitingAcknowledge_DNSIncorrectLength( void ) /* Add length. */ DHCPOption[ 1 ] = 4; /* Add the offer byte. */ - *( ( uint32_t * ) &DHCPOption[ 2 ] ) = ulLeaseTime; + memcpy( &DHCPOption[ 2 ], &ulLeaseTime, sizeof( ulLeaseTime ) ); DHCPOption += 6; /* Add Message type code. */ @@ -4305,7 +4335,7 @@ void test_vDHCPProcess_eWaitingAcknowledge_DNSIncorrectLength( void ) /* Add length. */ DHCPOption[ 1 ] = 3; /* Add the offer byte. */ - *( ( uint32_t * ) &DHCPOption[ 2 ] ) = ulDNSServer; + memcpy( &DHCPOption[ 2 ], &ulDNSServer, sizeof( ulDNSServer ) ); /* Put the information in global variables to be returned by @@ -4363,33 +4393,29 @@ void test_vDHCPProcess_eWaitingAcknowledge_DNSIncorrectLength( void ) TEST_ASSERT_EQUAL( xIPv4Addressing->ulNetMask, ulSubnetMask ); } -void test_vDHCPProcess_eWaitingAcknowledge_DNSIncorrectLength2( void ) +void test_vDHCPProcess_eWaitingAcknowledge_DNSServerOverabundance( void ) { struct xSOCKET xTestSocket; - TickType_t xTimeValue = 1234; - /* Create a bit longer DHCP message but keep it empty. */ - const BaseType_t xTotalLength = sizeof( struct xDHCPMessage_IPv4 ) + 1U /* Padding */ - + 3U /* DHCP offer */ - + 6U /* Server IP address */ - + 6U /* Subnet Mask */ - + 6U /* Gateway */ - + 6U /* Lease time */ - + 24U /* DNS server */ - + 1U /* End */; - uint8_t DHCPMsg[ xTotalLength ]; uint32_t DHCPServerAddress = 0xC0A80001; /* 192.168.0.1 */ uint32_t ulClientIPAddress = 0xC0A8000A; /* 192.168.0.10 */ uint32_t ulSubnetMask = 0xFFFFF100; /* 255.255.241.0 */ uint32_t ulGateway = 0xC0A80001; /* 192.168.0.1 */ uint32_t ulLeaseTime = 0x00000096; /* 150 seconds */ uint32_t ulDNSServer = 0xC0010101; /* 192.1.1.1 */ + uint8_t DHCPMsg[ + sizeof( DHCPMessage_IPv4_t ) + + 2U + sizeof( ( uint8_t ) dhcpMESSAGE_TYPE_ACK ) + + 2U + sizeof( DHCPServerAddress ) + + 2U + sizeof( ulSubnetMask ) + + 2U + sizeof( ulGateway ) + + 2U + sizeof( ulLeaseTime ) + + 2U + sizeof( ulDNSServer ) * ( ipconfigENDPOINT_DNS_ADDRESS_COUNT + 1 ) + ]; DHCPMessage_IPv4_t * pxDHCPMessage = ( DHCPMessage_IPv4_t * ) DHCPMsg; NetworkEndPoint_t xEndPoint = { 0 }, * pxEndPoint = &xEndPoint; IPV4Parameters_t * xIPv4Addressing = &( pxEndPoint->ipv4_settings ); - - DHCPMsg[ xTotalLength - 1U ] = 0xFF; - + size_t xDNSServersToAdd = ipconfigENDPOINT_DNS_ADDRESS_COUNT + 1; /* Set the header - or at least the start of DHCP message. */ memset( DHCPMsg, 0, sizeof( DHCPMsg ) ); @@ -4404,8 +4430,8 @@ void test_vDHCPProcess_eWaitingAcknowledge_DNSIncorrectLength2( void ) /* Set the client IP address. */ pxDHCPMessage->ulYourIPAddress_yiaddr = ulClientIPAddress; - /* Leave one byte for the padding. */ - uint8_t * DHCPOption = &DHCPMsg[ sizeof( struct xDHCPMessage_IPv4 ) + 1 ]; + uint8_t * DHCPOption = &DHCPMsg[ sizeof( DHCPMessage_IPv4_t ) ]; + /* Add Message type code. */ DHCPOption[ 0 ] = dhcpIPv4_MESSAGE_TYPE_OPTION_CODE; /* Add length. */ @@ -4413,13 +4439,13 @@ void test_vDHCPProcess_eWaitingAcknowledge_DNSIncorrectLength2( void ) /* Add the offer byte. */ DHCPOption[ 2 ] = dhcpMESSAGE_TYPE_ACK; - DHCPOption += 4; + DHCPOption += 3; /* Add Message type code. */ DHCPOption[ 0 ] = dhcpIPv4_SERVER_IP_ADDRESS_OPTION_CODE; /* Add length. */ DHCPOption[ 1 ] = 4; /* Add the offer byte. */ - *( ( uint32_t * ) &DHCPOption[ 2 ] ) = DHCPServerAddress; + memcpy( &DHCPOption[ 2 ], &DHCPServerAddress, sizeof( DHCPServerAddress ) ); DHCPOption += 6; /* Add Message type code. */ @@ -4427,7 +4453,7 @@ void test_vDHCPProcess_eWaitingAcknowledge_DNSIncorrectLength2( void ) /* Add length. */ DHCPOption[ 1 ] = 4; /* Add the offer byte. */ - *( ( uint32_t * ) &DHCPOption[ 2 ] ) = ulSubnetMask; + memcpy( &DHCPOption[ 2 ], &ulSubnetMask, sizeof( ulSubnetMask ) ); DHCPOption += 6; /* Add Message type code. */ @@ -4435,7 +4461,7 @@ void test_vDHCPProcess_eWaitingAcknowledge_DNSIncorrectLength2( void ) /* Add length. */ DHCPOption[ 1 ] = 4; /* Add the offer byte. */ - *( ( uint32_t * ) &DHCPOption[ 2 ] ) = ulGateway; + memcpy( &DHCPOption[ 2 ], &ulGateway, sizeof( ulGateway ) ); DHCPOption += 6; /* Add Message type code. */ @@ -4443,21 +4469,29 @@ void test_vDHCPProcess_eWaitingAcknowledge_DNSIncorrectLength2( void ) /* Add length. */ DHCPOption[ 1 ] = 4; /* Add the offer byte. */ - *( ( uint32_t * ) &DHCPOption[ 2 ] ) = ulLeaseTime; + memcpy( &DHCPOption[ 2 ], &ulLeaseTime, sizeof( ulLeaseTime ) ); DHCPOption += 6; /* Add Message type code. */ DHCPOption[ 0 ] = dhcpIPv4_DNS_SERVER_OPTIONS_CODE; /* Add length. */ - DHCPOption[ 1 ] = 24; - /* Add the offer byte. */ - *( ( uint32_t * ) &DHCPOption[ 2 ] ) = ulDNSServer; + DHCPOption[ 1 ] = xDNSServersToAdd * sizeof( ulDNSServer ); + DHCPOption += 2; + while( xDNSServersToAdd-- > 0U ) + { + memcpy( DHCPOption, &ulDNSServer, sizeof( ulDNSServer ) ); + DHCPOption += sizeof( ulDNSServer ); + } + + /* A stop byte shall not be necessary to prevent the DHCP option parser from running off the end of the buffer. */ + /* *DHCPOption++ = 0xFF; */ + TEST_ASSERT_EQUAL( DHCPOption - DHCPMsg, sizeof( DHCPMsg ) ); /* Put the information in global variables to be returned by * the FreeRTOS_recvrom. */ ucGenericPtr = DHCPMsg; - ulGenericLength = sizeof( DHCPMsg ) + 100; /* ulGenericLength is incremented by 100 to have uxDNSCount > ipconfigENDPOINT_DNS_ADDRESS_COUNT scenario */ + ulGenericLength = sizeof( DHCPMsg ); /* This should remain unchanged. */ xDHCPv4Socket = &xTestSocket; @@ -4534,9 +4568,6 @@ void test_vDHCPProcess_eWaitingAcknowledge_IncorrectDNSServerAddress( void ) NetworkEndPoint_t xEndPoint = { 0 }, * pxEndPoint = &xEndPoint; IPV4Parameters_t * xIPv4Addressing = &( pxEndPoint->ipv4_settings ); - DHCPMsg[ xTotalLength - 1U ] = 0xFF; - - /* Set the header - or at least the start of DHCP message. */ memset( DHCPMsg, 0, sizeof( DHCPMsg ) ); /* Copy the header here. */ @@ -4552,53 +4583,16 @@ void test_vDHCPProcess_eWaitingAcknowledge_IncorrectDNSServerAddress( void ) /* Leave one byte for the padding. */ uint8_t * DHCPOption = &DHCPMsg[ sizeof( struct xDHCPMessage_IPv4 ) + 1 ]; - /* Add Message type code. */ - DHCPOption[ 0 ] = dhcpIPv4_MESSAGE_TYPE_OPTION_CODE; - /* Add length. */ - DHCPOption[ 1 ] = 1; - /* Add the offer byte. */ - DHCPOption[ 2 ] = dhcpMESSAGE_TYPE_ACK; - - DHCPOption += 4; - /* Add Message type code. */ - DHCPOption[ 0 ] = dhcpIPv4_SERVER_IP_ADDRESS_OPTION_CODE; - /* Add length. */ - DHCPOption[ 1 ] = 4; - /* Add the offer byte. */ - *( ( uint32_t * ) &DHCPOption[ 2 ] ) = DHCPServerAddress; - - DHCPOption += 6; - /* Add Message type code. */ - DHCPOption[ 0 ] = dhcpIPv4_SUBNET_MASK_OPTION_CODE; - /* Add length. */ - DHCPOption[ 1 ] = 4; - /* Add the offer byte. */ - *( ( uint32_t * ) &DHCPOption[ 2 ] ) = ulSubnetMask; - - DHCPOption += 6; - /* Add Message type code. */ - DHCPOption[ 0 ] = dhcpIPv4_GATEWAY_OPTION_CODE; - /* Add length. */ - DHCPOption[ 1 ] = 4; - /* Add the offer byte. */ - *( ( uint32_t * ) &DHCPOption[ 2 ] ) = ulGateway; - - DHCPOption += 6; - /* Add Message type code. */ - DHCPOption[ 0 ] = dhcpIPv4_LEASE_TIME_OPTION_CODE; - /* Add length. */ - DHCPOption[ 1 ] = 4; - /* Add the offer byte. */ - *( ( uint32_t * ) &DHCPOption[ 2 ] ) = ulLeaseTime; - DHCPOption += 6; - /* Add Message type code. */ - DHCPOption[ 0 ] = dhcpIPv4_DNS_SERVER_OPTIONS_CODE; - /* Add length. */ - DHCPOption[ 1 ] = 4; - /* Add the offer byte. */ - *( ( uint32_t * ) &DHCPOption[ 2 ] ) = FREERTOS_INADDR_ANY; + prvWriteDHCPOptionU8( &DHCPOption, dhcpIPv4_MESSAGE_TYPE_OPTION_CODE, dhcpMESSAGE_TYPE_ACK ); + prvWriteDHCPOptionU32( &DHCPOption, dhcpIPv4_SERVER_IP_ADDRESS_OPTION_CODE, DHCPServerAddress ); + prvWriteDHCPOptionU32( &DHCPOption, dhcpIPv4_SUBNET_MASK_OPTION_CODE, ulSubnetMask ); + prvWriteDHCPOptionU32( &DHCPOption, dhcpIPv4_GATEWAY_OPTION_CODE, ulGateway ); + prvWriteDHCPOptionU32( &DHCPOption, dhcpIPv4_LEASE_TIME_OPTION_CODE, ulLeaseTime ); + prvWriteDHCPOptionU32( &DHCPOption, dhcpIPv4_DNS_SERVER_OPTIONS_CODE, FREERTOS_INADDR_ANY ); + *DHCPOption++ = 0xFF; + TEST_ASSERT_EQUAL( DHCPOption - DHCPMsg, xTotalLength ); /* Put the information in global variables to be returned by * the FreeRTOS_recvrom. */ @@ -4680,9 +4674,6 @@ void test_vDHCPProcess_eWaitingAcknowledge_IncorrectDNSServerAddress2( void ) NetworkEndPoint_t xEndPoint = { 0 }, * pxEndPoint = &xEndPoint; IPV4Parameters_t * xIPv4Addressing = &( pxEndPoint->ipv4_settings ); - DHCPMsg[ xTotalLength - 1U ] = 0xFF; - - /* Set the header - or at least the start of DHCP message. */ memset( DHCPMsg, 0, sizeof( DHCPMsg ) ); /* Copy the header here. */ @@ -4698,53 +4689,16 @@ void test_vDHCPProcess_eWaitingAcknowledge_IncorrectDNSServerAddress2( void ) /* Leave one byte for the padding. */ uint8_t * DHCPOption = &DHCPMsg[ sizeof( struct xDHCPMessage_IPv4 ) + 1 ]; - /* Add Message type code. */ - DHCPOption[ 0 ] = dhcpIPv4_MESSAGE_TYPE_OPTION_CODE; - /* Add length. */ - DHCPOption[ 1 ] = 1; - /* Add the offer byte. */ - DHCPOption[ 2 ] = dhcpMESSAGE_TYPE_ACK; - DHCPOption += 4; - /* Add Message type code. */ - DHCPOption[ 0 ] = dhcpIPv4_SERVER_IP_ADDRESS_OPTION_CODE; - /* Add length. */ - DHCPOption[ 1 ] = 4; - /* Add the offer byte. */ - *( ( uint32_t * ) &DHCPOption[ 2 ] ) = DHCPServerAddress; - - DHCPOption += 6; - /* Add Message type code. */ - DHCPOption[ 0 ] = dhcpIPv4_SUBNET_MASK_OPTION_CODE; - /* Add length. */ - DHCPOption[ 1 ] = 4; - /* Add the offer byte. */ - *( ( uint32_t * ) &DHCPOption[ 2 ] ) = ulSubnetMask; - - DHCPOption += 6; - /* Add Message type code. */ - DHCPOption[ 0 ] = dhcpIPv4_GATEWAY_OPTION_CODE; - /* Add length. */ - DHCPOption[ 1 ] = 4; - /* Add the offer byte. */ - *( ( uint32_t * ) &DHCPOption[ 2 ] ) = ulGateway; - - DHCPOption += 6; - /* Add Message type code. */ - DHCPOption[ 0 ] = dhcpIPv4_LEASE_TIME_OPTION_CODE; - /* Add length. */ - DHCPOption[ 1 ] = 4; - /* Add the offer byte. */ - *( ( uint32_t * ) &DHCPOption[ 2 ] ) = ulLeaseTime; - - DHCPOption += 6; - /* Add Message type code. */ - DHCPOption[ 0 ] = dhcpIPv4_DNS_SERVER_OPTIONS_CODE; - /* Add length. */ - DHCPOption[ 1 ] = 4; - /* Add the offer byte. */ - *( ( uint32_t * ) &DHCPOption[ 2 ] ) = ipBROADCAST_IP_ADDRESS; + prvWriteDHCPOptionU8( &DHCPOption, dhcpIPv4_MESSAGE_TYPE_OPTION_CODE, dhcpMESSAGE_TYPE_ACK ); + prvWriteDHCPOptionU32( &DHCPOption, dhcpIPv4_SERVER_IP_ADDRESS_OPTION_CODE, DHCPServerAddress ); + prvWriteDHCPOptionU32( &DHCPOption, dhcpIPv4_SUBNET_MASK_OPTION_CODE, ulSubnetMask ); + prvWriteDHCPOptionU32( &DHCPOption, dhcpIPv4_GATEWAY_OPTION_CODE, ulGateway ); + prvWriteDHCPOptionU32( &DHCPOption, dhcpIPv4_LEASE_TIME_OPTION_CODE, ulLeaseTime ); + prvWriteDHCPOptionU32( &DHCPOption, dhcpIPv4_DNS_SERVER_OPTIONS_CODE, ipBROADCAST_IP_ADDRESS ); + *DHCPOption++ = 0xFF; + TEST_ASSERT_EQUAL( DHCPOption - DHCPMsg, xTotalLength ); /* Put the information in global variables to be returned by * the FreeRTOS_recvrom. */ @@ -4817,9 +4771,6 @@ void test_vDHCPProcess_eWaitingAcknowledge_IPv4ServerIncorrectLength( void ) uint8_t DHCPMsg[ xTotalLength ]; uint32_t DHCPServerAddress = 0xC0A80001; /* 192.168.0.1 */ uint32_t ulClientIPAddress = 0xC0A8000A; /* 192.168.0.10 */ - uint32_t ulSubnetMask = 0xFFFFF100; /* 255.255.241.0 */ - uint32_t ulGateway = 0xC0A80001; /* 192.168.0.1 */ - uint32_t ulLeaseTime = 0x00000096; /* 150 seconds */ DHCPMessage_IPv4_t * pxDHCPMessage = ( DHCPMessage_IPv4_t * ) DHCPMsg; NetworkEndPoint_t xEndPoint = { 0 }, * pxEndPoint = &xEndPoint; @@ -4854,7 +4805,7 @@ void test_vDHCPProcess_eWaitingAcknowledge_IPv4ServerIncorrectLength( void ) /* Add length. */ DHCPOption[ 1 ] = 4; /* Add the offer byte. */ - *( ( uint32_t * ) &DHCPOption[ 2 ] ) = DHCPServerAddress; + memcpy( &DHCPOption[ 2 ], &DHCPServerAddress, sizeof( DHCPServerAddress ) ); DHCPOption += 6; /* Add Message type code. */ @@ -4862,7 +4813,7 @@ void test_vDHCPProcess_eWaitingAcknowledge_IPv4ServerIncorrectLength( void ) /* Add length. */ DHCPOption[ 1 ] = 3; /* Add the offer byte. */ - *( ( uint32_t * ) &DHCPOption[ 2 ] ) = DHCPServerAddress; + memcpy( &DHCPOption[ 2 ], &DHCPServerAddress, sizeof( DHCPServerAddress ) ); /* Put the information in global variables to be returned by * the FreeRTOS_recvrom. */ @@ -4927,22 +4878,15 @@ void test_vDHCPProcess_eWaitingAcknowledge_SubnetMaskIncorrectLength( void ) const BaseType_t xTotalLength = sizeof( struct xDHCPMessage_IPv4 ) + 1U /* Padding */ + 3U /* DHCP offer */ + 6U /* Server IP address */ - + 6U /* Subnet Mask */ - + 6U /* Gateway */ - + 6U /* Lease time */ + + 5U /* Subnet Mask, truncated */ + 1U /* End */; uint8_t DHCPMsg[ xTotalLength ]; uint32_t DHCPServerAddress = 0xC0A80001; /* 192.168.0.1 */ uint32_t ulClientIPAddress = 0xC0A8000A; /* 192.168.0.10 */ uint32_t ulSubnetMask = 0xFFFFF100; /* 255.255.241.0 */ - uint32_t ulGateway = 0xC0A80001; /* 192.168.0.1 */ - uint32_t ulLeaseTime = 0x00000096; /* 150 seconds */ DHCPMessage_IPv4_t * pxDHCPMessage = ( DHCPMessage_IPv4_t * ) DHCPMsg; NetworkEndPoint_t xEndPoint = { 0 }, * pxEndPoint = &xEndPoint; - DHCPMsg[ xTotalLength - 1U ] = 0xFF; - - /* Set the header - or at least the start of DHCP message. */ memset( DHCPMsg, 0, sizeof( DHCPMsg ) ); /* Copy the header here. */ @@ -4958,28 +4902,13 @@ void test_vDHCPProcess_eWaitingAcknowledge_SubnetMaskIncorrectLength( void ) /* Leave one byte for the padding. */ uint8_t * DHCPOption = &DHCPMsg[ sizeof( struct xDHCPMessage_IPv4 ) + 1 ]; - /* Add Message type code. */ - DHCPOption[ 0 ] = dhcpIPv4_MESSAGE_TYPE_OPTION_CODE; - /* Add length. */ - DHCPOption[ 1 ] = 1; - /* Add the offer byte. */ - DHCPOption[ 2 ] = dhcpMESSAGE_TYPE_ACK; - DHCPOption += 4; - /* Add Message type code. */ - DHCPOption[ 0 ] = dhcpIPv4_SERVER_IP_ADDRESS_OPTION_CODE; - /* Add length. */ - DHCPOption[ 1 ] = 4; - /* Add the offer byte. */ - *( ( uint32_t * ) &DHCPOption[ 2 ] ) = DHCPServerAddress; + prvWriteDHCPOptionU8( &DHCPOption, dhcpIPv4_MESSAGE_TYPE_OPTION_CODE, dhcpMESSAGE_TYPE_ACK ); + prvWriteDHCPOptionU32( &DHCPOption, dhcpIPv4_SERVER_IP_ADDRESS_OPTION_CODE, DHCPServerAddress ); + prvWriteDHCPOption( &DHCPOption, dhcpIPv4_SUBNET_MASK_OPTION_CODE, &ulSubnetMask, 3 ); - DHCPOption += 6; - /* Add Message type code. */ - DHCPOption[ 0 ] = dhcpIPv4_SUBNET_MASK_OPTION_CODE; - /* Add incorrect length. */ - DHCPOption[ 1 ] = 3; - /* Add the offer byte. */ - *( ( uint32_t * ) &DHCPOption[ 2 ] ) = ulSubnetMask; + *DHCPOption++ = 0xFF; + TEST_ASSERT_EQUAL( DHCPOption - DHCPMsg, xTotalLength ); /* Put the information in global variables to be returned by * the FreeRTOS_recvrom. */ @@ -5045,20 +4974,15 @@ void test_vDHCPProcess_eWaitingAcknowledge_GatewayIncorrectLength( void ) + 6U /* Server IP address */ + 6U /* Subnet Mask */ + 6U /* Gateway */ - + 6U /* Lease time */ + 1U /* End */; uint8_t DHCPMsg[ xTotalLength ]; uint32_t DHCPServerAddress = 0xC0A80001; /* 192.168.0.1 */ uint32_t ulClientIPAddress = 0xC0A8000A; /* 192.168.0.10 */ uint32_t ulSubnetMask = 0xFFFFF100; /* 255.255.241.0 */ uint32_t ulGateway = 0xC0A80001; /* 192.168.0.1 */ - uint32_t ulLeaseTime = 0x00000096; /* 150 seconds */ DHCPMessage_IPv4_t * pxDHCPMessage = ( DHCPMessage_IPv4_t * ) DHCPMsg; NetworkEndPoint_t xEndPoint = { 0 }, * pxEndPoint = &xEndPoint; - DHCPMsg[ xTotalLength - 1U ] = 0xFF; - - /* Set the header - or at least the start of DHCP message. */ memset( DHCPMsg, 0, sizeof( DHCPMsg ) ); /* Copy the header here. */ @@ -5074,36 +4998,21 @@ void test_vDHCPProcess_eWaitingAcknowledge_GatewayIncorrectLength( void ) /* Leave one byte for the padding. */ uint8_t * DHCPOption = &DHCPMsg[ sizeof( struct xDHCPMessage_IPv4 ) + 1 ]; - /* Add Message type code. */ - DHCPOption[ 0 ] = dhcpIPv4_MESSAGE_TYPE_OPTION_CODE; - /* Add length. */ - DHCPOption[ 1 ] = 1; - /* Add the offer byte. */ - DHCPOption[ 2 ] = dhcpMESSAGE_TYPE_ACK; - DHCPOption += 4; - /* Add Message type code. */ - DHCPOption[ 0 ] = dhcpIPv4_SERVER_IP_ADDRESS_OPTION_CODE; - /* Add length. */ - DHCPOption[ 1 ] = 4; - /* Add the offer byte. */ - *( ( uint32_t * ) &DHCPOption[ 2 ] ) = DHCPServerAddress; + prvWriteDHCPOptionU8( &DHCPOption, dhcpIPv4_MESSAGE_TYPE_OPTION_CODE, dhcpMESSAGE_TYPE_ACK ); + prvWriteDHCPOptionU32( &DHCPOption, dhcpIPv4_SERVER_IP_ADDRESS_OPTION_CODE, DHCPServerAddress ); + prvWriteDHCPOptionU32( &DHCPOption, dhcpIPv4_SUBNET_MASK_OPTION_CODE, ulSubnetMask ); - DHCPOption += 6; - /* Add Message type code. */ - DHCPOption[ 0 ] = dhcpIPv4_SUBNET_MASK_OPTION_CODE; - /* Add length. */ - DHCPOption[ 1 ] = 4; - /* Add the offer byte. */ - *( ( uint32_t * ) &DHCPOption[ 2 ] ) = ulSubnetMask; - - DHCPOption += 6; /* Add Message type code. */ DHCPOption[ 0 ] = dhcpIPv4_GATEWAY_OPTION_CODE; /* Add incorrect length. */ DHCPOption[ 1 ] = 2; /* Add the offer byte. */ - *( ( uint32_t * ) &DHCPOption[ 2 ] ) = ulGateway; + memcpy( &DHCPOption[ 2 ], &ulGateway, sizeof( ulGateway ) ); + DHCPOption += 6; + + *DHCPOption++ = 0xFF; + TEST_ASSERT_EQUAL( DHCPOption - DHCPMsg, xTotalLength ); /* Put the information in global variables to be returned by * the FreeRTOS_recvrom. */ @@ -5170,7 +5079,7 @@ void test_vDHCPProcess_eWaitingAcknowledge_LeaseTimeIncorrectLength( void ) + 6U /* Server IP address */ + 6U /* Subnet Mask */ + 6U /* Gateway */ - + 6U /* Lease time */ + + 5U /* Lease time, truncated */ + 1U /* End */; uint8_t DHCPMsg[ xTotalLength ]; uint32_t DHCPServerAddress = 0xC0A80001; /* 192.168.0.1 */ @@ -5181,9 +5090,6 @@ void test_vDHCPProcess_eWaitingAcknowledge_LeaseTimeIncorrectLength( void ) DHCPMessage_IPv4_t * pxDHCPMessage = ( DHCPMessage_IPv4_t * ) DHCPMsg; NetworkEndPoint_t xEndPoint = { 0 }, * pxEndPoint = &xEndPoint; - DHCPMsg[ xTotalLength - 1U ] = 0xFF; - - /* Set the header - or at least the start of DHCP message. */ memset( DHCPMsg, 0, sizeof( DHCPMsg ) ); /* Copy the header here. */ @@ -5199,45 +5105,15 @@ void test_vDHCPProcess_eWaitingAcknowledge_LeaseTimeIncorrectLength( void ) /* Leave one byte for the padding. */ uint8_t * DHCPOption = &DHCPMsg[ sizeof( struct xDHCPMessage_IPv4 ) + 1 ]; - /* Add Message type code. */ - DHCPOption[ 0 ] = dhcpIPv4_MESSAGE_TYPE_OPTION_CODE; - /* Add length. */ - DHCPOption[ 1 ] = 1; - /* Add the offer byte. */ - DHCPOption[ 2 ] = dhcpMESSAGE_TYPE_ACK; - - DHCPOption += 4; - /* Add Message type code. */ - DHCPOption[ 0 ] = dhcpIPv4_SERVER_IP_ADDRESS_OPTION_CODE; - /* Add length. */ - DHCPOption[ 1 ] = 4; - /* Add the offer byte. */ - *( ( uint32_t * ) &DHCPOption[ 2 ] ) = DHCPServerAddress; - - DHCPOption += 6; - /* Add Message type code. */ - DHCPOption[ 0 ] = dhcpIPv4_SUBNET_MASK_OPTION_CODE; - /* Add length. */ - DHCPOption[ 1 ] = 4; - /* Add the offer byte. */ - *( ( uint32_t * ) &DHCPOption[ 2 ] ) = ulSubnetMask; - - DHCPOption += 6; - /* Add Message type code. */ - DHCPOption[ 0 ] = dhcpIPv4_GATEWAY_OPTION_CODE; - /* Add length. */ - DHCPOption[ 1 ] = 4; - /* Add the offer byte. */ - *( ( uint32_t * ) &DHCPOption[ 2 ] ) = ulGateway; - DHCPOption += 6; - /* Add Message type code. */ - DHCPOption[ 0 ] = dhcpIPv4_LEASE_TIME_OPTION_CODE; - /* Add incorrect length. */ - DHCPOption[ 1 ] = 3; - /* Add the offer byte. */ - *( ( uint32_t * ) &DHCPOption[ 2 ] ) = ulLeaseTime; + prvWriteDHCPOptionU8( &DHCPOption, dhcpIPv4_MESSAGE_TYPE_OPTION_CODE, dhcpMESSAGE_TYPE_ACK ); + prvWriteDHCPOptionU32( &DHCPOption, dhcpIPv4_SERVER_IP_ADDRESS_OPTION_CODE, DHCPServerAddress ); + prvWriteDHCPOptionU32( &DHCPOption, dhcpIPv4_SUBNET_MASK_OPTION_CODE, ulSubnetMask ); + prvWriteDHCPOptionU32( &DHCPOption, dhcpIPv4_GATEWAY_OPTION_CODE, ulGateway ); + prvWriteDHCPOption( &DHCPOption, dhcpIPv4_LEASE_TIME_OPTION_CODE, &ulLeaseTime, 3 ); + *DHCPOption++ = 0xFF; + TEST_ASSERT_EQUAL( DHCPOption - DHCPMsg, xTotalLength ); /* Put the information in global variables to be returned by * the FreeRTOS_recvrom. */ @@ -5303,7 +5179,7 @@ void test_vDHCPProcess_eWaitingAcknowledge_LeaseTimeIncorrectLength2( void ) + 6U /* Server IP address */ + 6U /* Subnet Mask */ + 6U /* Gateway */ - + 6U /* Lease time */ + + 5U /* Lease time */ + 1U /* End */; uint8_t DHCPMsg[ xTotalLength ]; uint32_t DHCPServerAddress = 0xC0A80001; /* 192.168.0.1 */ @@ -5314,9 +5190,6 @@ void test_vDHCPProcess_eWaitingAcknowledge_LeaseTimeIncorrectLength2( void ) DHCPMessage_IPv4_t * pxDHCPMessage = ( DHCPMessage_IPv4_t * ) DHCPMsg; NetworkEndPoint_t xEndPoint = { 0 }, * pxEndPoint = &xEndPoint; - DHCPMsg[ xTotalLength - 1U ] = 0xFF; - - /* Set the header - or at least the start of DHCP message. */ memset( DHCPMsg, 0, sizeof( DHCPMsg ) ); /* Copy the header here. */ @@ -5332,45 +5205,15 @@ void test_vDHCPProcess_eWaitingAcknowledge_LeaseTimeIncorrectLength2( void ) /* Leave one byte for the padding. */ uint8_t * DHCPOption = &DHCPMsg[ sizeof( struct xDHCPMessage_IPv4 ) + 1 ]; - /* Add Message type code. */ - DHCPOption[ 0 ] = dhcpIPv4_MESSAGE_TYPE_OPTION_CODE; - /* Add length. */ - DHCPOption[ 1 ] = 1; - /* Add the offer byte. */ - DHCPOption[ 2 ] = dhcpMESSAGE_TYPE_ACK; - - DHCPOption += 4; - /* Add Message type code. */ - DHCPOption[ 0 ] = dhcpIPv4_SERVER_IP_ADDRESS_OPTION_CODE; - /* Add length. */ - DHCPOption[ 1 ] = 4; - /* Add the offer byte. */ - *( ( uint32_t * ) &DHCPOption[ 2 ] ) = DHCPServerAddress + 0x1234; - DHCPOption += 6; - /* Add Message type code. */ - DHCPOption[ 0 ] = dhcpIPv4_SUBNET_MASK_OPTION_CODE; - /* Add length. */ - DHCPOption[ 1 ] = 4; - /* Add the offer byte. */ - *( ( uint32_t * ) &DHCPOption[ 2 ] ) = ulSubnetMask; - - DHCPOption += 6; - /* Add Message type code. */ - DHCPOption[ 0 ] = dhcpIPv4_GATEWAY_OPTION_CODE; - /* Add length. */ - DHCPOption[ 1 ] = 4; - /* Add the offer byte. */ - *( ( uint32_t * ) &DHCPOption[ 2 ] ) = ulGateway; - - DHCPOption += 6; - /* Add Message type code. */ - DHCPOption[ 0 ] = dhcpIPv4_LEASE_TIME_OPTION_CODE; - /* Add incorrect length. */ - DHCPOption[ 1 ] = 3; - /* Add the offer byte. */ - *( ( uint32_t * ) &DHCPOption[ 2 ] ) = ulLeaseTime; + prvWriteDHCPOptionU8( &DHCPOption, dhcpIPv4_MESSAGE_TYPE_OPTION_CODE, dhcpMESSAGE_TYPE_ACK ); + prvWriteDHCPOptionU32( &DHCPOption, dhcpIPv4_SERVER_IP_ADDRESS_OPTION_CODE, DHCPServerAddress + 0x1234 ); + prvWriteDHCPOptionU32( &DHCPOption, dhcpIPv4_SUBNET_MASK_OPTION_CODE, ulSubnetMask ); + prvWriteDHCPOptionU32( &DHCPOption, dhcpIPv4_GATEWAY_OPTION_CODE, ulGateway ); + prvWriteDHCPOption( &DHCPOption, dhcpIPv4_LEASE_TIME_OPTION_CODE, &ulLeaseTime, 3 ); + *DHCPOption++ = 0xFF; + TEST_ASSERT_EQUAL( DHCPOption - DHCPMsg, xTotalLength ); /* Put the information in global variables to be returned by * the FreeRTOS_recvrom. */ @@ -5903,7 +5746,7 @@ void test_xProcessCheckOption_LengthByteZero( void ) BaseType_t xResult; ProcessSet_t xSet; - uint8_t ucUDPPayload[ 1 ]; + uint8_t ucUDPPayload[ 2 ]; memset( &( ucUDPPayload ), 0, sizeof( ucUDPPayload ) ); @@ -5912,7 +5755,7 @@ void test_xProcessCheckOption_LengthByteZero( void ) xSet.ucOptionCode = dhcpIPv4_MESSAGE_TYPE_OPTION_CODE; xSet.pucByte = ucUDPPayload; xSet.uxIndex = 0; - xSet.uxPayloadDataLength = 2; + xSet.uxPayloadDataLength = sizeof( ucUDPPayload ); xResult = xProcessCheckOption( &xSet ); diff --git a/test/unit-test/FreeRTOS_DHCPv6/FreeRTOS_DHCPv6_utest.c b/test/unit-test/FreeRTOS_DHCPv6/FreeRTOS_DHCPv6_utest.c index 86e6a7f007..29a0492331 100644 --- a/test/unit-test/FreeRTOS_DHCPv6/FreeRTOS_DHCPv6_utest.c +++ b/test/unit-test/FreeRTOS_DHCPv6/FreeRTOS_DHCPv6_utest.c @@ -1388,6 +1388,7 @@ void test_vDHCPv6Process_ResetFromInit() vDHCP_RATimerReload_Expect( &xEndPoint, dhcpINITIAL_TIMER_PERIOD ); vDHCPv6Process( pdTRUE, &xEndPoint ); + vPortFree( xEndPoint.pxDHCPMessage ); /* Make LeakSanitizer happy. */ /* The endpoint sends the DHCPv6 Solicitation message to find the DHCPv6 server. * Then change the state to eWaitingSendFirstDiscover. */ diff --git a/test/unit-test/FreeRTOS_DNS/FreeRTOS_DNS_utest.c b/test/unit-test/FreeRTOS_DNS/FreeRTOS_DNS_utest.c index eeea226265..69ef050dfe 100644 --- a/test/unit-test/FreeRTOS_DNS/FreeRTOS_DNS_utest.c +++ b/test/unit-test/FreeRTOS_DNS/FreeRTOS_DNS_utest.c @@ -149,10 +149,10 @@ void test_FreeRTOS_gethostbyname_FailNullAddress( void ) void test_FreeRTOS_gethostbyname_FailLongAddress( void ) { uint32_t ret; - char address[ ipconfigDNS_CACHE_NAME_LENGTH + 3 ]; + char address[ ipconfigDNS_CACHE_NAME_LENGTH + 1 ]; memset( address, 'a', ipconfigDNS_CACHE_NAME_LENGTH ); - address[ ipconfigDNS_CACHE_NAME_LENGTH + 3 ] = '\0'; + address[ ipconfigDNS_CACHE_NAME_LENGTH ] = '\0'; ret = FreeRTOS_gethostbyname( address ); @@ -609,7 +609,7 @@ void test_FreeRTOS_gethostbyname_a_SetCallback( void ) FreeRTOS_inet_addr_ExpectAndReturn( GOOD_ADDRESS, 0 ); Prepare_CacheLookup_ExpectAnyArgsAndReturn( 0 ); xApplicationGetRandomNumber_IgnoreAndReturn( pdTRUE ); - vDNSSetCallBack_ExpectAnyArgs(); + xDNSSetCallBack_ExpectAnyArgsAndReturn( pdPASS ); DNS_CreateSocket_ExpectAnyArgsAndReturn( NULL ); ret = FreeRTOS_gethostbyname_a( GOOD_ADDRESS, @@ -665,7 +665,7 @@ void test_FreeRTOS_gethostbyname_a_Callback( void ) } /** - * @brief Ensures that if vDNSSetCallBack is called the client is put in + * @brief Ensures that if xDNSSetCallBack is called the client is put in * asynchronous mode, and only one retry is performed by calling * prvGetHostByNameOp instead of prvGetHostByNameOp_WithRetry */ @@ -700,7 +700,7 @@ void test_FreeRTOS_gethostbyname_a_NoCallbackRetryOnce( void ) Prepare_CacheLookup_ExpectAnyArgsAndReturn( 0 ); xApplicationGetRandomNumber_ExpectAnyArgsAndReturn( pdTRUE ); xApplicationGetRandomNumber_ReturnThruPtr_pulNumber( &ulNumber ); - vDNSSetCallBack_ExpectAnyArgs(); + xDNSSetCallBack_ExpectAnyArgsAndReturn( pdPASS ); /* in prvGetHostByName */ DNS_CreateSocket_ExpectAnyArgsAndReturn( &xDNSSocket ); @@ -776,10 +776,9 @@ void test_FreeRTOS_getaddrinfo_a_UnknownHintFamily( void ) void test_FreeRTOS_getaddrinfo_a_IPv4AddressFound( void ) { BaseType_t xReturn; - struct freertos_addrinfo xAddress, * pxAddress = &xAddress; + struct freertos_addrinfo * pxAddress; struct freertos_addrinfo xHint, * pxHint = &xHint; - memset( &xAddress, 0, sizeof( struct freertos_addrinfo ) ); memset( &xHint, 0, sizeof( struct freertos_addrinfo ) ); xHint.ai_family = FREERTOS_AF_INET4; @@ -794,6 +793,8 @@ void test_FreeRTOS_getaddrinfo_a_IPv4AddressFound( void ) TEST_ASSERT_EQUAL( FREERTOS_AF_INET4, pxAddress->ai_family ); TEST_ASSERT_EQUAL( DOTTED_IPV4_ADDRESS_UINT32, FreeRTOS_htonl( pxAddress->ai_addr->sin_address.ulIP_IPv4 ) ); TEST_ASSERT_EQUAL( ipSIZE_OF_IPv4_ADDRESS, pxAddress->ai_addrlen ); + + vPortFree( pxAddress ); /* Make LeakSanitizer happy. */ } /** @@ -802,10 +803,9 @@ void test_FreeRTOS_getaddrinfo_a_IPv4AddressFound( void ) void test_FreeRTOS_getaddrinfo_a_IPv6AddressFound( void ) { BaseType_t xReturn; - struct freertos_addrinfo xAddress, * pxAddress = &xAddress; + struct freertos_addrinfo * pxAddress; struct freertos_addrinfo xHint, * pxHint = &xHint; - memset( &xAddress, 0, sizeof( struct freertos_addrinfo ) ); memset( &xHint, 0, sizeof( struct freertos_addrinfo ) ); xHint.ai_family = FREERTOS_AF_INET6; @@ -821,6 +821,8 @@ void test_FreeRTOS_getaddrinfo_a_IPv6AddressFound( void ) TEST_ASSERT_EQUAL( FREERTOS_AF_INET6, pxAddress->ai_family ); TEST_ASSERT_EQUAL_MEMORY( xIPv6Address.ucBytes, pxAddress->ai_addr->sin_address.xIP_IPv6.ucBytes, ipSIZE_OF_IPv6_ADDRESS ); TEST_ASSERT_EQUAL( ipSIZE_OF_IPv6_ADDRESS, pxAddress->ai_addrlen ); + + vPortFree( pxAddress ); /* Make LeakSanitizer happy. */ } /** @@ -829,17 +831,16 @@ void test_FreeRTOS_getaddrinfo_a_IPv6AddressFound( void ) void test_FreeRTOS_getaddrinfo_a_IPv4DomainCacheFound( void ) { BaseType_t xReturn; - struct freertos_addrinfo xAddress, * pxAddress = &xAddress; + struct freertos_addrinfo * pxAddress; struct freertos_addrinfo xExpectedAddress, * pxExpectedAddress = &xExpectedAddress; - memset( &xAddress, 0, sizeof( struct freertos_addrinfo ) ); memset( &xExpectedAddress, 0, sizeof( struct freertos_addrinfo ) ); xExpectedAddress.ai_family = FREERTOS_AF_INET4; FreeRTOS_inet_addr_ExpectAndReturn( GOOD_ADDRESS, 0 ); Prepare_CacheLookup_ExpectAndReturn( GOOD_ADDRESS, FREERTOS_AF_INET4, &pxAddress, DOTTED_IPV4_ADDRESS_UINT32 ); - Prepare_CacheLookup_ReturnMemThruPtr_ppxAddressInfo( &pxExpectedAddress, sizeof( struct freertos_addrinfo ) ); + Prepare_CacheLookup_ReturnMemThruPtr_ppxAddressInfo( &pxExpectedAddress, sizeof( struct freertos_addrinfo * ) ); xReturn = FreeRTOS_getaddrinfo_a( GOOD_ADDRESS, "Service", NULL, &pxAddress, dns_callback, NULL, 0U ); @@ -893,7 +894,7 @@ void test_FreeRTOS_getaddrinfo_a_IPv4DomainCacheMiss_Random( void ) Prepare_CacheLookup_ExpectAndReturn( GOOD_ADDRESS, FREERTOS_AF_INET4, &pxAddress, 0 ); xApplicationGetRandomNumber_ExpectAnyArgsAndReturn( pdTRUE ); xApplicationGetRandomNumber_ReturnMemThruPtr_pulNumber( &ulRandom, sizeof( uint32_t ) ); - vDNSSetCallBack_Expect( GOOD_ADDRESS, NULL, dns_callback, 0U, ulRandom, pdFALSE ); + xDNSSetCallBack_ExpectAndReturn( GOOD_ADDRESS, NULL, dns_callback, 0U, ulRandom, pdFALSE, pdPASS ); DNS_CreateSocket_ExpectAndReturn( 0U, NULL ); xReturn = FreeRTOS_getaddrinfo_a( GOOD_ADDRESS, "Service", NULL, &pxAddress, dns_callback, NULL, 0U ); @@ -921,7 +922,7 @@ void test_FreeRTOS_getaddrinfo_a_IPv6DomainCacheMiss_Random( void ) Prepare_CacheLookup_ExpectAndReturn( GOOD_ADDRESS, FREERTOS_AF_INET6, &pxAddress, 0 ); xApplicationGetRandomNumber_ExpectAnyArgsAndReturn( pdTRUE ); xApplicationGetRandomNumber_ReturnMemThruPtr_pulNumber( &ulRandom, sizeof( uint32_t ) ); - vDNSSetCallBack_Expect( GOOD_ADDRESS, NULL, dns_callback, 0U, ulRandom, pdTRUE ); + xDNSSetCallBack_ExpectAndReturn( GOOD_ADDRESS, NULL, dns_callback, 0U, ulRandom, pdTRUE, pdPASS ); DNS_CreateSocket_ExpectAndReturn( 0U, NULL ); xReturn = FreeRTOS_getaddrinfo_a( GOOD_ADDRESS, "Service", pxHint, &pxAddress, dns_callback, NULL, 0U ); @@ -955,7 +956,7 @@ void test_FreeRTOS_getaddrinfo_a_IPv6Random_EndPointNotFound( void ) Prepare_CacheLookup_ExpectAndReturn( GOOD_ADDRESS, FREERTOS_AF_INET6, &pxAddress, 0 ); xApplicationGetRandomNumber_ExpectAnyArgsAndReturn( pdTRUE ); xApplicationGetRandomNumber_ReturnMemThruPtr_pulNumber( &ulRandom, sizeof( uint32_t ) ); - vDNSSetCallBack_Expect( GOOD_ADDRESS, NULL, dns_callback, 0U, ulRandom, pdTRUE ); + xDNSSetCallBack_ExpectAndReturn( GOOD_ADDRESS, NULL, dns_callback, 0U, ulRandom, pdTRUE, pdPASS ); /* In prvGetHostByName */ DNS_CreateSocket_ExpectAndReturn( 0U, &xDNSSocket ); @@ -970,6 +971,40 @@ void test_FreeRTOS_getaddrinfo_a_IPv6Random_EndPointNotFound( void ) TEST_ASSERT_EQUAL( -pdFREERTOS_ERRNO_ENOENT, xReturn ); } +/** + * @brief Try to get IP address through network but malloc fails while setting + * callback + */ +void test_FreeRTOS_getaddrinfo_a_IPv6Random_SetCallBackFails( void ) +{ + BaseType_t xReturn; + struct freertos_addrinfo xAddress, * pxAddress = &xAddress; + struct freertos_addrinfo xHint, * pxHint = &xHint; + uint32_t ulRandom = 0x1234U; + struct xSOCKET xDNSSocket; + NetworkEndPoint_t xEndPoint; + + memset( &xAddress, 0, sizeof( struct freertos_addrinfo ) ); + memset( &xHint, 0, sizeof( struct freertos_addrinfo ) ); + memset( &xDNSSocket, 0, sizeof( struct xSOCKET ) ); + memset( &xEndPoint, 0, sizeof( xEndPoint ) ); + + xEndPoint.bits.bIPv6 = pdFALSE; + + xHint.ai_family = FREERTOS_AF_INET6; + + FreeRTOS_inet_pton6_ExpectAndReturn( GOOD_ADDRESS, NULL, 0 ); + FreeRTOS_inet_pton6_IgnoreArg_pvDestination(); + Prepare_CacheLookup_ExpectAndReturn( GOOD_ADDRESS, FREERTOS_AF_INET6, &pxAddress, 0 ); + xApplicationGetRandomNumber_ExpectAnyArgsAndReturn( pdTRUE ); + xApplicationGetRandomNumber_ReturnMemThruPtr_pulNumber( &ulRandom, sizeof( uint32_t ) ); + xDNSSetCallBack_ExpectAndReturn( GOOD_ADDRESS, NULL, dns_callback, 0U, ulRandom, pdTRUE, pdFAIL ); + + xReturn = FreeRTOS_getaddrinfo_a( GOOD_ADDRESS, "Service", pxHint, &pxAddress, dns_callback, NULL, 0U ); + + TEST_ASSERT_EQUAL( -pdFREERTOS_ERRNO_ENOENT, xReturn ); +} + /** * @brief IPv4 socket bind fail with domain name containing dot */ @@ -1010,7 +1045,7 @@ void test_FreeRTOS_getaddrinfo_a_IPv4Random_BindFailWithDot( void ) Prepare_CacheLookup_ExpectAndReturn( GOOD_ADDRESS, FREERTOS_AF_INET4, &pxAddress, 0 ); xApplicationGetRandomNumber_ExpectAnyArgsAndReturn( pdTRUE ); xApplicationGetRandomNumber_ReturnMemThruPtr_pulNumber( &ulRandom, sizeof( uint32_t ) ); - vDNSSetCallBack_Expect( GOOD_ADDRESS, NULL, dns_callback, 0U, ulRandom, pdFALSE ); + xDNSSetCallBack_ExpectAndReturn( GOOD_ADDRESS, NULL, dns_callback, 0U, ulRandom, pdFALSE, pdPASS ); /* In prvGetHostByName */ DNS_CreateSocket_ExpectAndReturn( 0U, &xDNSSocket ); @@ -1040,6 +1075,8 @@ void test_FreeRTOS_getaddrinfo_a_IPv6Random_BindFailWithDot( void ) struct xSOCKET xDNSSocket; NetworkEndPoint_t xEndPoint[ 5 ]; + xDNS_IP_Preference = xPreferenceIPv6; + memset( &xAddress, 0, sizeof( struct freertos_addrinfo ) ); memset( &xHint, 0, sizeof( struct freertos_addrinfo ) ); memset( &xDNSSocket, 0, sizeof( struct xSOCKET ) ); @@ -1077,7 +1114,7 @@ void test_FreeRTOS_getaddrinfo_a_IPv6Random_BindFailWithDot( void ) Prepare_CacheLookup_ExpectAndReturn( GOOD_ADDRESS, FREERTOS_AF_INET6, &pxAddress, 0 ); xApplicationGetRandomNumber_ExpectAnyArgsAndReturn( pdTRUE ); xApplicationGetRandomNumber_ReturnMemThruPtr_pulNumber( &ulRandom, sizeof( uint32_t ) ); - vDNSSetCallBack_Expect( GOOD_ADDRESS, NULL, dns_callback, 0U, ulRandom, pdTRUE ); + xDNSSetCallBack_ExpectAndReturn( GOOD_ADDRESS, NULL, dns_callback, 0U, ulRandom, pdTRUE, pdPASS ); /* In prvGetHostByName */ DNS_CreateSocket_ExpectAndReturn( 0U, &xDNSSocket ); @@ -1126,7 +1163,7 @@ void test_FreeRTOS_getaddrinfo_a_IPv4Random_BindFailWODot( void ) Prepare_CacheLookup_ExpectAndReturn( LLMNR_ADDRESS, FREERTOS_AF_INET4, &pxAddress, 0 ); xApplicationGetRandomNumber_ExpectAnyArgsAndReturn( pdTRUE ); xApplicationGetRandomNumber_ReturnMemThruPtr_pulNumber( &ulRandom, sizeof( uint32_t ) ); - vDNSSetCallBack_Expect( LLMNR_ADDRESS, NULL, dns_callback, 0U, ulRandom, pdFALSE ); + xDNSSetCallBack_ExpectAndReturn( LLMNR_ADDRESS, NULL, dns_callback, 0U, ulRandom, pdFALSE, pdPASS ); /* In prvGetHostByName */ DNS_CreateSocket_ExpectAndReturn( 0U, &xDNSSocket ); @@ -1154,6 +1191,8 @@ void test_FreeRTOS_getaddrinfo_a_IPv6Random_BindFailWODot( void ) struct xSOCKET xDNSSocket; NetworkEndPoint_t xEndPoint[ 2 ]; + xDNS_IP_Preference = xPreferenceIPv6; + memset( &xAddress, 0, sizeof( struct freertos_addrinfo ) ); memset( &xHint, 0, sizeof( struct freertos_addrinfo ) ); memset( &xDNSSocket, 0, sizeof( struct xSOCKET ) ); @@ -1172,7 +1211,7 @@ void test_FreeRTOS_getaddrinfo_a_IPv6Random_BindFailWODot( void ) Prepare_CacheLookup_ExpectAndReturn( LLMNR_ADDRESS, FREERTOS_AF_INET6, &pxAddress, 0 ); xApplicationGetRandomNumber_ExpectAnyArgsAndReturn( pdTRUE ); xApplicationGetRandomNumber_ReturnMemThruPtr_pulNumber( &ulRandom, sizeof( uint32_t ) ); - vDNSSetCallBack_Expect( LLMNR_ADDRESS, NULL, dns_callback, 0U, ulRandom, pdTRUE ); + xDNSSetCallBack_ExpectAndReturn( LLMNR_ADDRESS, NULL, dns_callback, 0U, ulRandom, pdTRUE, pdPASS ); /* In prvGetHostByName */ DNS_CreateSocket_ExpectAndReturn( 0U, &xDNSSocket ); @@ -1214,7 +1253,7 @@ void test_FreeRTOS_getaddrinfo_a_IPv4Random_InvalidDNSServerIndex( void ) Prepare_CacheLookup_ExpectAndReturn( GOOD_ADDRESS, FREERTOS_AF_INET4, &pxAddress, 0 ); xApplicationGetRandomNumber_ExpectAnyArgsAndReturn( pdTRUE ); xApplicationGetRandomNumber_ReturnMemThruPtr_pulNumber( &ulRandom, sizeof( uint32_t ) ); - vDNSSetCallBack_Expect( GOOD_ADDRESS, NULL, dns_callback, 0U, ulRandom, pdFALSE ); + xDNSSetCallBack_ExpectAndReturn( GOOD_ADDRESS, NULL, dns_callback, 0U, ulRandom, pdFALSE, pdPASS ); /* In prvGetHostByName */ DNS_CreateSocket_ExpectAndReturn( 0U, &xDNSSocket ); @@ -1237,6 +1276,8 @@ void test_FreeRTOS_getaddrinfo_a_IPv6Random_InvalidDNSServerIndex( void ) struct xSOCKET xDNSSocket; NetworkEndPoint_t xEndPoint; + xDNS_IP_Preference = xPreferenceIPv6; + memset( &xAddress, 0, sizeof( struct freertos_addrinfo ) ); memset( &xHint, 0, sizeof( struct freertos_addrinfo ) ); memset( &xDNSSocket, 0, sizeof( struct xSOCKET ) ); @@ -1252,7 +1293,7 @@ void test_FreeRTOS_getaddrinfo_a_IPv6Random_InvalidDNSServerIndex( void ) Prepare_CacheLookup_ExpectAndReturn( GOOD_ADDRESS, FREERTOS_AF_INET6, &pxAddress, 0 ); xApplicationGetRandomNumber_ExpectAnyArgsAndReturn( pdTRUE ); xApplicationGetRandomNumber_ReturnMemThruPtr_pulNumber( &ulRandom, sizeof( uint32_t ) ); - vDNSSetCallBack_Expect( GOOD_ADDRESS, NULL, dns_callback, 0U, ulRandom, pdTRUE ); + xDNSSetCallBack_ExpectAndReturn( GOOD_ADDRESS, NULL, dns_callback, 0U, ulRandom, pdTRUE, pdPASS ); /* In prvGetHostByName */ DNS_CreateSocket_ExpectAndReturn( 0U, &xDNSSocket ); @@ -1291,7 +1332,7 @@ void test_FreeRTOS_getaddrinfo_a_IPv4Random_UnknownPreference( void ) Prepare_CacheLookup_ExpectAndReturn( GOOD_ADDRESS, FREERTOS_AF_INET4, &pxAddress, 0 ); xApplicationGetRandomNumber_ExpectAnyArgsAndReturn( pdTRUE ); xApplicationGetRandomNumber_ReturnMemThruPtr_pulNumber( &ulRandom, sizeof( uint32_t ) ); - vDNSSetCallBack_Expect( GOOD_ADDRESS, NULL, dns_callback, 0U, ulRandom, pdFALSE ); + xDNSSetCallBack_ExpectAndReturn( GOOD_ADDRESS, NULL, dns_callback, 0U, ulRandom, pdFALSE, pdPASS ); /* In prvGetHostByName */ DNS_CreateSocket_ExpectAndReturn( 0U, &xDNSSocket ); @@ -1323,6 +1364,8 @@ void test_FreeRTOS_getaddrinfo_a_IPv6Random_DNSReplySuccess( void ) struct xDNSBuffer xReceiveBuffer; DNSMessage_t * pxDNSMessageHeader = NULL; + xDNS_IP_Preference = xPreferenceIPv6; + memset( &xAddress, 0, sizeof( struct freertos_addrinfo ) ); memset( &xHint, 0, sizeof( struct freertos_addrinfo ) ); memset( &xExpectedAddress, 0, sizeof( struct freertos_addrinfo ) ); @@ -1355,7 +1398,7 @@ void test_FreeRTOS_getaddrinfo_a_IPv6Random_DNSReplySuccess( void ) Prepare_CacheLookup_ExpectAndReturn( GOOD_ADDRESS, FREERTOS_AF_INET6, &pxAddress, 0 ); xApplicationGetRandomNumber_ExpectAnyArgsAndReturn( pdTRUE ); xApplicationGetRandomNumber_ReturnMemThruPtr_pulNumber( &ulRandom, sizeof( uint32_t ) ); - vDNSSetCallBack_Expect( GOOD_ADDRESS, NULL, dns_callback, 0U, ulRandom, pdTRUE ); + xDNSSetCallBack_ExpectAndReturn( GOOD_ADDRESS, NULL, dns_callback, 0U, ulRandom, pdTRUE, pdPASS ); /* In prvGetHostByName */ DNS_CreateSocket_ExpectAndReturn( 0U, &xDNSSocket ); @@ -1407,6 +1450,8 @@ void test_FreeRTOS_getaddrinfo_a_IPv6Random_RetryExhaust( void ) DNSMessage_t * pxDNSMessageHeader = NULL; int i; + xDNS_IP_Preference = xPreferenceIPv6; + memset( &xAddress, 0, sizeof( struct freertos_addrinfo ) ); memset( &xHint, 0, sizeof( struct freertos_addrinfo ) ); memset( &xExpectedAddress, 0, sizeof( struct freertos_addrinfo ) ); @@ -1522,7 +1567,7 @@ void test_FreeRTOS_getaddrinfo_a_IPv4Random_LocalDNSSuccess( void ) Prepare_CacheLookup_ExpectAndReturn( LOCAL_ADDRESS, FREERTOS_AF_INET4, &pxAddress, 0 ); xApplicationGetRandomNumber_ExpectAnyArgsAndReturn( pdTRUE ); xApplicationGetRandomNumber_ReturnMemThruPtr_pulNumber( &ulRandom, sizeof( uint32_t ) ); - vDNSSetCallBack_Expect( LOCAL_ADDRESS, NULL, dns_callback, 0U, ulRandom, pdFALSE ); + xDNSSetCallBack_ExpectAndReturn( LOCAL_ADDRESS, NULL, dns_callback, 0U, ulRandom, pdFALSE, pdPASS ); /* In prvGetHostByName */ DNS_CreateSocket_ExpectAnyArgsAndReturn( &xDNSSocket ); @@ -1576,6 +1621,8 @@ void test_FreeRTOS_getaddrinfo_a_IPv6Random_LocalDNSSuccess( void ) DNSMessage_t * pxDNSMessageHeader = NULL; int i; + xDNS_IP_Preference = xPreferenceIPv6; + memset( &xAddress, 0, sizeof( struct freertos_addrinfo ) ); memset( &xHint, 0, sizeof( struct freertos_addrinfo ) ); memset( &xExpectedAddress, 0, sizeof( struct freertos_addrinfo ) ); @@ -1608,7 +1655,7 @@ void test_FreeRTOS_getaddrinfo_a_IPv6Random_LocalDNSSuccess( void ) Prepare_CacheLookup_ExpectAndReturn( LOCAL_ADDRESS, FREERTOS_AF_INET6, &pxAddress, 0 ); xApplicationGetRandomNumber_ExpectAnyArgsAndReturn( pdTRUE ); xApplicationGetRandomNumber_ReturnMemThruPtr_pulNumber( &ulRandom, sizeof( uint32_t ) ); - vDNSSetCallBack_Expect( LOCAL_ADDRESS, NULL, dns_callback, 0U, ulRandom, pdTRUE ); + xDNSSetCallBack_ExpectAndReturn( LOCAL_ADDRESS, NULL, dns_callback, 0U, ulRandom, pdTRUE, pdPASS ); /* In prvGetHostByName */ DNS_CreateSocket_ExpectAnyArgsAndReturn( &xDNSSocket ); @@ -1661,6 +1708,8 @@ void test_FreeRTOS_getaddrinfo_a_IPv4Random_LocalDNSUnknownPreference( void ) DNSMessage_t * pxDNSMessageHeader = NULL; int i; + xDNS_IP_Preference = xPreferenceIPv6; + memset( &xAddress, 0, sizeof( struct freertos_addrinfo ) ); memset( &xHint, 0, sizeof( struct freertos_addrinfo ) ); memset( &xExpectedAddress, 0, sizeof( struct freertos_addrinfo ) ); @@ -1694,7 +1743,7 @@ void test_FreeRTOS_getaddrinfo_a_IPv4Random_LocalDNSUnknownPreference( void ) Prepare_CacheLookup_ExpectAndReturn( LOCAL_ADDRESS, FREERTOS_AF_INET4, &pxAddress, 0 ); xApplicationGetRandomNumber_ExpectAnyArgsAndReturn( pdTRUE ); xApplicationGetRandomNumber_ReturnMemThruPtr_pulNumber( &ulRandom, sizeof( uint32_t ) ); - vDNSSetCallBack_Expect( LOCAL_ADDRESS, NULL, dns_callback, 0U, ulRandom, pdFALSE ); + xDNSSetCallBack_ExpectAndReturn( LOCAL_ADDRESS, NULL, dns_callback, 0U, ulRandom, pdFALSE, pdPASS ); /* In prvGetHostByName */ DNS_CreateSocket_ExpectAnyArgsAndReturn( &xDNSSocket ); @@ -1732,6 +1781,8 @@ void test_FreeRTOS_getaddrinfo_a_IPv6Random_LLMNRDNSSuccess( void ) DNSMessage_t * pxDNSMessageHeader = NULL; int i; + xDNS_IP_Preference = xPreferenceIPv6; + memset( &xAddress, 0, sizeof( struct freertos_addrinfo ) ); memset( &xHint, 0, sizeof( struct freertos_addrinfo ) ); memset( &xExpectedAddress, 0, sizeof( struct freertos_addrinfo ) ); @@ -1764,7 +1815,7 @@ void test_FreeRTOS_getaddrinfo_a_IPv6Random_LLMNRDNSSuccess( void ) Prepare_CacheLookup_ExpectAndReturn( LLMNR_ADDRESS, FREERTOS_AF_INET6, &pxAddress, 0 ); xApplicationGetRandomNumber_ExpectAnyArgsAndReturn( pdTRUE ); xApplicationGetRandomNumber_ReturnMemThruPtr_pulNumber( &ulRandom, sizeof( uint32_t ) ); - vDNSSetCallBack_Expect( LLMNR_ADDRESS, NULL, dns_callback, 0U, ulRandom, pdTRUE ); + xDNSSetCallBack_ExpectAndReturn( LLMNR_ADDRESS, NULL, dns_callback, 0U, ulRandom, pdTRUE, pdPASS ); /* In prvGetHostByName */ DNS_CreateSocket_ExpectAnyArgsAndReturn( &xDNSSocket ); @@ -1843,7 +1894,7 @@ void test_FreeRTOS_getaddrinfo_a_IPv6Random_LLMNRDNSNoEndPoint( void ) Prepare_CacheLookup_ExpectAndReturn( LLMNR_ADDRESS, FREERTOS_AF_INET6, &pxAddress, 0 ); xApplicationGetRandomNumber_ExpectAnyArgsAndReturn( pdTRUE ); xApplicationGetRandomNumber_ReturnMemThruPtr_pulNumber( &ulRandom, sizeof( uint32_t ) ); - vDNSSetCallBack_Expect( LLMNR_ADDRESS, NULL, dns_callback, 0U, ulRandom, pdTRUE ); + xDNSSetCallBack_ExpectAndReturn( LLMNR_ADDRESS, NULL, dns_callback, 0U, ulRandom, pdTRUE, pdPASS ); /* In prvGetHostByName */ DNS_CreateSocket_ExpectAnyArgsAndReturn( &xDNSSocket ); @@ -1910,7 +1961,7 @@ void test_FreeRTOS_getaddrinfo_a_IPv4Random_LLMNRDNSUnknownPreference( void ) Prepare_CacheLookup_ExpectAndReturn( LLMNR_ADDRESS, FREERTOS_AF_INET4, &pxAddress, 0 ); xApplicationGetRandomNumber_ExpectAnyArgsAndReturn( pdTRUE ); xApplicationGetRandomNumber_ReturnMemThruPtr_pulNumber( &ulRandom, sizeof( uint32_t ) ); - vDNSSetCallBack_Expect( LLMNR_ADDRESS, NULL, dns_callback, 0U, ulRandom, pdFALSE ); + xDNSSetCallBack_ExpectAndReturn( LLMNR_ADDRESS, NULL, dns_callback, 0U, ulRandom, pdFALSE, pdPASS ); /* In prvGetHostByName */ DNS_CreateSocket_ExpectAnyArgsAndReturn( &xDNSSocket ); @@ -2025,6 +2076,8 @@ void test_FreeRTOS_getaddrinfo_a_IPv6Random_LLMNRFail( void ) DNSMessage_t * pxDNSMessageHeader = NULL; int i; + xDNS_IP_Preference = xPreferenceIPv6; + memset( &xAddress, 0, sizeof( struct freertos_addrinfo ) ); memset( &xHint, 0, sizeof( struct freertos_addrinfo ) ); memset( &xExpectedAddress, 0, sizeof( struct freertos_addrinfo ) ); @@ -2125,6 +2178,8 @@ void test_FreeRTOS_getaddrinfo_a_IPv4Random_PortSpecified( void ) DNSMessage_t * pxDNSMessageHeader = NULL; uint16_t usExpectPort = 0x1234; + xDNS_IP_Preference = xPreferenceIPv6; + memset( &xAddress, 0, sizeof( struct freertos_addrinfo ) ); memset( &xHint, 0, sizeof( struct freertos_addrinfo ) ); memset( &xExpectedAddress, 0, sizeof( struct freertos_addrinfo ) ); @@ -2159,7 +2214,7 @@ void test_FreeRTOS_getaddrinfo_a_IPv4Random_PortSpecified( void ) Prepare_CacheLookup_ExpectAndReturn( GOOD_ADDRESS, FREERTOS_AF_INET6, &pxAddress, 0 ); xApplicationGetRandomNumber_ExpectAnyArgsAndReturn( pdTRUE ); xApplicationGetRandomNumber_ReturnMemThruPtr_pulNumber( &ulRandom, sizeof( uint32_t ) ); - vDNSSetCallBack_Expect( GOOD_ADDRESS, NULL, dns_callback, 0U, ulRandom, pdTRUE ); + xDNSSetCallBack_ExpectAndReturn( GOOD_ADDRESS, NULL, dns_callback, 0U, ulRandom, pdTRUE, pdPASS ); /* In prvGetHostByName */ DNS_CreateSocket_ExpectAndReturn( 0U, &xDNSSocket ); @@ -2224,3 +2279,38 @@ void test_FreeRTOS_freeaddrinfo_NullInput( void ) { FreeRTOS_freeaddrinfo( NULL ); } + +/** + * @brief Preference is IPv6 + */ +void test_FreeRTOS_SetDNSIPPreference_IPv4( void ) +{ + BaseType_t xReturn; + + xReturn = FreeRTOS_SetDNSIPPreference( xPreferenceIPv4 ); + TEST_ASSERT_EQUAL( pdPASS, xReturn ); + TEST_ASSERT_EQUAL( xPreferenceIPv4, xDNS_IP_Preference ); +} + +/** + * @brief Preference is IPv6 + */ +void test_FreeRTOS_SetDNSIPPreference_IPv6( void ) +{ + BaseType_t xReturn; + + xReturn = FreeRTOS_SetDNSIPPreference( xPreferenceIPv6 ); + TEST_ASSERT_EQUAL( pdPASS, xReturn ); + TEST_ASSERT_EQUAL( xPreferenceIPv6, xDNS_IP_Preference ); +} + +/** + * @brief Preference is None + */ +void test_FreeRTOS_SetDNSIPPreference_None( void ) +{ + BaseType_t xReturn; + + xReturn = FreeRTOS_SetDNSIPPreference( xPreferenceNone ); + TEST_ASSERT_EQUAL( pdFAIL, xReturn ); +} diff --git a/test/unit-test/FreeRTOS_DNS/ut.cmake b/test/unit-test/FreeRTOS_DNS/ut.cmake index f9d25a146d..4e0db6bffd 100644 --- a/test/unit-test/FreeRTOS_DNS/ut.cmake +++ b/test/unit-test/FreeRTOS_DNS/ut.cmake @@ -42,7 +42,7 @@ list(APPEND mock_define_list # ================= Create the library under test here (edit) ================== -add_compile_options(-Wno-pedantic -Wno-div-by-zero -O0 -ggdb3) +add_compile_options(-Wno-pedantic -ggdb3) # list the files you would like to test here set(real_source_files "") list(APPEND real_source_files diff --git a/test/unit-test/FreeRTOS_DNS_Cache/FreeRTOS_DNS_Cache_utest.c b/test/unit-test/FreeRTOS_DNS_Cache/FreeRTOS_DNS_Cache_utest.c index 1994b128d9..89c9aeb4f4 100644 --- a/test/unit-test/FreeRTOS_DNS_Cache/FreeRTOS_DNS_Cache_utest.c +++ b/test/unit-test/FreeRTOS_DNS_Cache/FreeRTOS_DNS_Cache_utest.c @@ -495,15 +495,12 @@ void test_prepare_DNSLookup( void ) void test_prepare_DNSLookup2( void ) { - BaseType_t x = 0U; - BaseType_t xFamily; + BaseType_t x; struct freertos_addrinfo * pxAddressInfo = NULL; - struct freertos_addrinfo ** ppxAddressInfo; IPv46_Address_t xAddress; - xFamily = FREERTOS_AF_INET; xAddress.xIs_IPv6 = pdFALSE; - ppxAddressInfo = &pxAddressInfo; + xAddress.xIPAddress.ulIP_IPv4 = ~0U; xTaskGetTickCount_ExpectAndReturn( 3000 ); /* 3 seconds */ FreeRTOS_inet_ntop_ExpectAnyArgsAndReturn( NULL ); @@ -516,7 +513,7 @@ void test_prepare_DNSLookup2( void ) pxNew_AddrInfo_ExpectAnyArgsAndReturn( NULL ); FreeRTOS_inet_ntop_ExpectAnyArgsAndReturn( NULL ); - x = Prepare_CacheLookup( "helloman", xFamily, ppxAddressInfo ); + x = Prepare_CacheLookup( "helloman", FREERTOS_AF_INET, &pxAddressInfo ); TEST_ASSERT_EQUAL( 0, x ); } @@ -525,13 +522,11 @@ void test_prepare_DNSLookup2( void ) */ void test_prepare_DNSLookup3( void ) { - BaseType_t x = 0U; - BaseType_t xFamily; - struct freertos_addrinfo ** ppxAddressInfo = NULL; + BaseType_t x; IPv46_Address_t xAddress; - xFamily = FREERTOS_AF_INET; xAddress.xIs_IPv6 = pdFALSE; + xAddress.xIPAddress.ulIP_IPv4 = ~0U; xTaskGetTickCount_ExpectAndReturn( 3000 ); FreeRTOS_inet_ntop_ExpectAnyArgsAndReturn( NULL ); @@ -543,7 +538,7 @@ void test_prepare_DNSLookup3( void ) xTaskGetTickCount_ExpectAndReturn( 5000 ); FreeRTOS_inet_ntop_ExpectAnyArgsAndReturn( NULL ); - x = Prepare_CacheLookup( "helloman", xFamily, ppxAddressInfo ); + x = Prepare_CacheLookup( "helloman", FREERTOS_AF_INET, NULL ); TEST_ASSERT_EQUAL( 0, x ); } @@ -552,13 +547,11 @@ void test_prepare_DNSLookup3( void ) */ void test_prepare_DNSLookup4( void ) { - BaseType_t x = 0U; - BaseType_t xFamily; - struct freertos_addrinfo ** ppxAddressInfo = NULL; + BaseType_t x; IPv46_Address_t xAddress; - xFamily = FREERTOS_AF_INET; xAddress.xIs_IPv6 = pdFALSE; + xAddress.xIPAddress.ulIP_IPv4 = ~0U; xTaskGetTickCount_ExpectAndReturn( 3000 ); FreeRTOS_inet_ntop_ExpectAnyArgsAndReturn( NULL ); @@ -570,7 +563,7 @@ void test_prepare_DNSLookup4( void ) xTaskGetTickCount_ExpectAndReturn( 5000 ); FreeRTOS_inet_ntop_ExpectAnyArgsAndReturn( NULL ); - x = Prepare_CacheLookup( "hello", xFamily, ppxAddressInfo ); + x = Prepare_CacheLookup( "hello", FREERTOS_AF_INET, NULL ); TEST_ASSERT_EQUAL( 0, x ); } @@ -629,14 +622,14 @@ void test_prepare_DNSLookup6( void ) */ void test_prepare_DNSLookup_IPv6( void ) { - BaseType_t x = 0U; - BaseType_t xFamily; + BaseType_t x; + BaseType_t xFamily = FREERTOS_AF_INET6; struct freertos_addrinfo * pxAddressInfo = &pucAddrBuffer[ 0 ]; - struct freertos_addrinfo ** ppxAddressInfo = ( struct freertos_addrinfo ** ) &pucAddrBuffer; + struct freertos_addrinfo ** ppxAddressInfo = ( struct freertos_addrinfo ** ) &pxAddressInfo; IPv46_Address_t xAddress; - xFamily = FREERTOS_AF_INET6; xAddress.xIs_IPv6 = pdTRUE; + memcpy( xAddress.xIPAddress.xIP_IPv6.ucBytes, "great ip address", 16 ); *ppxAddressInfo = pxAddressInfo; @@ -680,6 +673,7 @@ void test_prepare_DNSLookup2_IPv6( void ) xFamily = FREERTOS_AF_INET6; xAddress.xIs_IPv6 = pdTRUE; + memcpy( xAddress.xIPAddress.xIP_IPv6.ucBytes, "great ip address", 16 ); ppxAddressInfo = &pxAddressInfo; xTaskGetTickCount_ExpectAndReturn( 3000 ); /* 3 seconds */ @@ -709,6 +703,7 @@ void test_prepare_DNSLookup3_IPv6( void ) xFamily = FREERTOS_AF_INET6; xAddress.xIs_IPv6 = pdTRUE; + memcpy( xAddress.xIPAddress.xIP_IPv6.ucBytes, "great ip address", 16 ); xTaskGetTickCount_ExpectAndReturn( 3000 ); FreeRTOS_inet_ntop_ExpectAnyArgsAndReturn( NULL ); @@ -737,6 +732,7 @@ void test_prepare_DNSLookup4_IPv6( void ) xFamily = FREERTOS_AF_INET6; xAddress.xIs_IPv6 = pdTRUE; + memcpy( xAddress.xIPAddress.xIP_IPv6.ucBytes, "great ip address", 16 ); xTaskGetTickCount_ExpectAndReturn( 3000 ); FreeRTOS_inet_ntop_ExpectAnyArgsAndReturn( NULL ); diff --git a/test/unit-test/FreeRTOS_DNS_Cache/ut.cmake b/test/unit-test/FreeRTOS_DNS_Cache/ut.cmake index 6c20e12103..b9c5e9e619 100755 --- a/test/unit-test/FreeRTOS_DNS_Cache/ut.cmake +++ b/test/unit-test/FreeRTOS_DNS_Cache/ut.cmake @@ -39,7 +39,7 @@ list(APPEND mock_define_list # ================= Create the library under test here (edit) ================== -add_compile_options(-Wno-pedantic -Wno-div-by-zero -O0 -ggdb3) +add_compile_options(-Wno-pedantic -ggdb3) # list the files you would like to test here set(real_source_files "" ) diff --git a/test/unit-test/FreeRTOS_DNS_Callback/FreeRTOS_DNS_Callback_utest.c b/test/unit-test/FreeRTOS_DNS_Callback/FreeRTOS_DNS_Callback_utest.c index 816a19944b..d351003872 100644 --- a/test/unit-test/FreeRTOS_DNS_Callback/FreeRTOS_DNS_Callback_utest.c +++ b/test/unit-test/FreeRTOS_DNS_Callback/FreeRTOS_DNS_Callback_utest.c @@ -65,6 +65,10 @@ typedef void (* FOnDNSEvent ) ( const char * /* pcName */, /* =========================== GLOBAL VARIABLES =========================== */ static int callback_called = 0; +/* The second element is for the flexible array member + * /* when pvPortMalloc is mocked to return this object. + */ +static DNSCallback_t dnsCallback[ 2 ]; /* =========================== STATIC FUNCTIONS =========================== */ static void dns_callback( const char * pcName, @@ -74,8 +78,6 @@ static void dns_callback( const char * pcName, callback_called = 1; } - -static DNSCallback_t dnsCallback; /* ============================ TEST FIXTURES ============================= */ /** @@ -86,7 +88,7 @@ void setUp( void ) vListInitialise_ExpectAnyArgs(); vDNSCallbackInitialise(); callback_called = 0; - memset( &dnsCallback, 0x00, sizeof( DNSCallback_t ) ); + memset( dnsCallback, 0x00, sizeof( dnsCallback ) ); } /** @@ -142,14 +144,14 @@ void test_xDNSDoCallback_success_equal_identifier( void ) char pc_name[] = "test"; strcpy( pxSet.pcName, pc_name ); - dnsCallback.pCallbackFunction = dns_callback; + dnsCallback->pCallbackFunction = dns_callback; listGET_END_MARKER_ExpectAnyArgsAndReturn( ( ListItem_t * ) 4 ); vTaskSuspendAll_Expect(); listGET_NEXT_ExpectAnyArgsAndReturn( ( ListItem_t * ) 8 ); - listGET_LIST_ITEM_OWNER_ExpectAnyArgsAndReturn( &dnsCallback ); + listGET_LIST_ITEM_OWNER_ExpectAnyArgsAndReturn( dnsCallback ); listGET_LIST_ITEM_VALUE_ExpectAnyArgsAndReturn( 123 ); uxListRemove_ExpectAnyArgsAndReturn( pdTRUE ); vPortFree_ExpectAnyArgs(); @@ -176,14 +178,14 @@ void test_xDNSDoCallback_success_equal_identifier_set_timer( void ) pxSet.pxDNSMessageHeader->usIdentifier = 123; char pc_name[] = "test"; strcpy( pxSet.pcName, pc_name ); - dnsCallback.pCallbackFunction = dns_callback; + dnsCallback->pCallbackFunction = dns_callback; /* Expectations */ listGET_END_MARKER_ExpectAnyArgsAndReturn( ( ListItem_t * ) 4 ); vTaskSuspendAll_Expect(); listGET_NEXT_ExpectAnyArgsAndReturn( ( ListItem_t * ) 8 ); - listGET_LIST_ITEM_OWNER_ExpectAnyArgsAndReturn( &dnsCallback ); + listGET_LIST_ITEM_OWNER_ExpectAnyArgsAndReturn( dnsCallback ); listGET_LIST_ITEM_VALUE_ExpectAnyArgsAndReturn( 123 ); uxListRemove_ExpectAnyArgsAndReturn( pdTRUE ); vPortFree_ExpectAnyArgs(); @@ -203,12 +205,89 @@ void test_xDNSDoCallback_success_equal_identifier_set_timer( void ) /** * @brief Happy Path! */ -void test_vDNSSetCallback_success( void ) +void test_xDNSDoCallback_success_equal_port_number_equal_name( void ) +{ + BaseType_t ret; + ParseSet_t pxSet; + struct freertos_addrinfo pxAddress; + DNSMessage_t xDNSMessageHeader; + char pc_name[] = "test"; + uint8_t dnsCallbackMemory[ sizeof( DNSCallback_t ) + ipconfigDNS_CACHE_NAME_LENGTH ]; + DNSCallback_t * pxDnsCallback = ( DNSCallback_t * ) &dnsCallbackMemory; + + pxSet.pxDNSMessageHeader = &xDNSMessageHeader; + pxSet.usPortNumber = FreeRTOS_htons( ipMDNS_PORT ); + strcpy( pxSet.pcName, pc_name ); + pxDnsCallback->pCallbackFunction = dns_callback; + strcpy( pxDnsCallback->pcName, pc_name ); + + /* Expectations */ + listGET_END_MARKER_ExpectAnyArgsAndReturn( ( ListItem_t * ) 4 ); + vTaskSuspendAll_Expect(); + listGET_NEXT_ExpectAnyArgsAndReturn( ( ListItem_t * ) 8 ); + + listGET_LIST_ITEM_OWNER_ExpectAnyArgsAndReturn( pxDnsCallback ); + uxListRemove_ExpectAnyArgsAndReturn( pdTRUE ); + vPortFree_ExpectAnyArgs(); + listLIST_IS_EMPTY_ExpectAnyArgsAndReturn( pdTRUE ); + + vIPSetDNSTimerEnableState_ExpectAnyArgs(); + + xTaskResumeAll_ExpectAndReturn( pdFALSE ); + /* API Call */ + ret = xDNSDoCallback( &pxSet, &pxAddress ); + + /* Validations */ + TEST_ASSERT_EQUAL( pdTRUE, ret ); + TEST_ASSERT_EQUAL( 1, callback_called ); +} + +/** + * @brief A failure path occurs when the port number is for MDNS but + * the name does not match. + */ +void test_xDNSDoCallback_fail_equal_port_number_not_equal_name( void ) +{ + BaseType_t ret; + ParseSet_t pxSet; + struct freertos_addrinfo pxAddress; + DNSMessage_t xDNSMessageHeader; + + pxSet.pxDNSMessageHeader = &xDNSMessageHeader; + pxSet.pxDNSMessageHeader->usIdentifier = 123; + pxSet.usPortNumber = FreeRTOS_htons( ipMDNS_PORT ); + char pc_name[] = "test"; + strcpy( pxSet.pcName, pc_name ); + dnsCallback->pCallbackFunction = dns_callback; + dnsCallback->pcName[ 0 ] = '\0'; + + /* Expectations */ + listGET_END_MARKER_ExpectAnyArgsAndReturn( ( ListItem_t * ) 4 ); + vTaskSuspendAll_Expect(); + listGET_NEXT_ExpectAnyArgsAndReturn( ( ListItem_t * ) 8 ); + + listGET_LIST_ITEM_OWNER_ExpectAnyArgsAndReturn( dnsCallback ); + listGET_NEXT_ExpectAnyArgsAndReturn( ( ListItem_t * ) 4 ); + + xTaskResumeAll_ExpectAndReturn( pdFALSE ); + /* API Call */ + ret = xDNSDoCallback( &pxSet, &pxAddress ); + + /* Validations */ + TEST_ASSERT_EQUAL( pdFALSE, ret ); + TEST_ASSERT_EQUAL( 0, callback_called ); +} + +/** + * @brief Happy Path! + */ +void test_xDNSSetCallBack_success( void ) { void * pvSearchID = NULL; + BaseType_t xReturn; /* Expectations */ - pvPortMalloc_ExpectAnyArgsAndReturn( &dnsCallback ); + pvPortMalloc_ExpectAnyArgsAndReturn( dnsCallback ); listLIST_IS_EMPTY_ExpectAnyArgsAndReturn( pdFALSE ); vTaskSetTimeOutState_ExpectAnyArgs(); listSET_LIST_ITEM_OWNER_ExpectAnyArgs(); @@ -218,24 +297,26 @@ void test_vDNSSetCallback_success( void ) xTaskResumeAll_ExpectAndReturn( pdFALSE ); /* API Call */ - vDNSSetCallBack( "hostname", pvSearchID, dns_callback, 56, 123, pdFALSE ); + xReturn = xDNSSetCallBack( "hostname", pvSearchID, dns_callback, 56, 123, pdFALSE ); /* Validations */ - TEST_ASSERT_EQUAL( 0, strcmp( dnsCallback.pcName, "hostname" ) ); - TEST_ASSERT_EQUAL( dns_callback, dnsCallback.pCallbackFunction ); - TEST_ASSERT_EQUAL( pvSearchID, dnsCallback.pvSearchID ); - TEST_ASSERT_EQUAL( 56, dnsCallback.uxRemainingTime ); + TEST_ASSERT_EQUAL( 0, strcmp( dnsCallback->pcName, "hostname" ) ); + TEST_ASSERT_EQUAL( dns_callback, dnsCallback->pCallbackFunction ); + TEST_ASSERT_EQUAL( pvSearchID, dnsCallback->pvSearchID ); + TEST_ASSERT_EQUAL( 56, dnsCallback->uxRemainingTime ); + TEST_ASSERT_EQUAL( pdPASS, xReturn ); } /** * @brief Happy Path! */ -void test_vDNSSetCallback_success_empty_list( void ) +void test_xDNSSetCallBack_success_empty_list( void ) { void * pvSearchID = NULL; + BaseType_t xReturn; /* Expectations */ - pvPortMalloc_ExpectAnyArgsAndReturn( &dnsCallback ); + pvPortMalloc_ExpectAnyArgsAndReturn( dnsCallback ); listLIST_IS_EMPTY_ExpectAnyArgsAndReturn( pdTRUE ); FreeRTOS_min_uint32_ExpectAnyArgsAndReturn( 0 ); vDNSTimerReload_ExpectAnyArgs(); @@ -247,27 +328,30 @@ void test_vDNSSetCallback_success_empty_list( void ) xTaskResumeAll_ExpectAndReturn( pdFALSE ); /* API Call */ - vDNSSetCallBack( "hostname", pvSearchID, dns_callback, 56, 123, pdFALSE ); + xReturn = xDNSSetCallBack( "hostname", pvSearchID, dns_callback, 56, 123, pdFALSE ); /* Validations */ - TEST_ASSERT_EQUAL( 0, strcmp( dnsCallback.pcName, "hostname" ) ); - TEST_ASSERT_EQUAL( dns_callback, dnsCallback.pCallbackFunction ); - TEST_ASSERT_EQUAL( pvSearchID, dnsCallback.pvSearchID ); - TEST_ASSERT_EQUAL( 56, dnsCallback.uxRemainingTime ); + TEST_ASSERT_EQUAL( 0, strcmp( dnsCallback->pcName, "hostname" ) ); + TEST_ASSERT_EQUAL( dns_callback, dnsCallback->pCallbackFunction ); + TEST_ASSERT_EQUAL( pvSearchID, dnsCallback->pvSearchID ); + TEST_ASSERT_EQUAL( 56, dnsCallback->uxRemainingTime ); + TEST_ASSERT_EQUAL( pdPASS, xReturn ); } /** * @brief Memory Allocation failed */ -void test_vDNSSetCallback_malloc_failed( void ) +void test_xDNSSetCallBack_malloc_failed( void ) { void * pvSearchID = NULL; + BaseType_t xReturn; /* Expectations */ pvPortMalloc_ExpectAnyArgsAndReturn( NULL ); /* API Call */ - vDNSSetCallBack( "hostname", pvSearchID, dns_callback, 56, 123, pdFALSE ); + xReturn = xDNSSetCallBack( "hostname", pvSearchID, dns_callback, 56, 123, pdFALSE ); + TEST_ASSERT_EQUAL( pdFAIL, xReturn ); } @@ -278,13 +362,13 @@ void test_vDNSCheckCallback_success_search_id_not_null( void ) { void * pvSearchID = ( void * ) 456; - dnsCallback.pvSearchID = pvSearchID; + dnsCallback->pvSearchID = pvSearchID; listGET_END_MARKER_ExpectAnyArgsAndReturn( ( ListItem_t * ) 8 ); vListInitialise_ExpectAnyArgs(); vTaskSuspendAll_Expect(); listGET_NEXT_ExpectAnyArgsAndReturn( ( ListItem_t * ) 16 ); - listGET_LIST_ITEM_OWNER_ExpectAnyArgsAndReturn( &dnsCallback ); + listGET_LIST_ITEM_OWNER_ExpectAnyArgsAndReturn( dnsCallback ); listGET_NEXT_ExpectAnyArgsAndReturn( ( ListItem_t * ) 8 ); /* end marker */ uxListRemove_ExpectAnyArgsAndReturn( pdFALSE ); vPortFree_ExpectAnyArgs(); @@ -306,13 +390,13 @@ void test_vDNSCheckCallback_success_search_id_not_null_list_empty( void ) { void * pvSearchID = ( void * ) 456; - dnsCallback.pvSearchID = pvSearchID; + dnsCallback->pvSearchID = pvSearchID; listGET_END_MARKER_ExpectAnyArgsAndReturn( ( ListItem_t * ) 8 ); vListInitialise_ExpectAnyArgs(); vTaskSuspendAll_Expect(); listGET_NEXT_ExpectAnyArgsAndReturn( ( ListItem_t * ) 16 ); - listGET_LIST_ITEM_OWNER_ExpectAnyArgsAndReturn( &dnsCallback ); + listGET_LIST_ITEM_OWNER_ExpectAnyArgsAndReturn( dnsCallback ); listGET_NEXT_ExpectAnyArgsAndReturn( ( ListItem_t * ) 8 ); /* end marker */ uxListRemove_ExpectAnyArgsAndReturn( pdFALSE ); vPortFree_ExpectAnyArgs(); @@ -333,13 +417,13 @@ void test_vDNSCheckCallback_success_search_id_null( void ) { void * pvSearchID = ( void * ) 456; - dnsCallback.pvSearchID = pvSearchID; + dnsCallback->pvSearchID = pvSearchID; listGET_END_MARKER_ExpectAnyArgsAndReturn( ( ListItem_t * ) 8 ); vListInitialise_ExpectAnyArgs(); vTaskSuspendAll_Expect(); listGET_NEXT_ExpectAnyArgsAndReturn( ( ListItem_t * ) 16 ); - listGET_LIST_ITEM_OWNER_ExpectAnyArgsAndReturn( &dnsCallback ); + listGET_LIST_ITEM_OWNER_ExpectAnyArgsAndReturn( dnsCallback ); listGET_NEXT_ExpectAnyArgsAndReturn( ( ListItem_t * ) 8 ); /* end marker */ xTaskCheckForTimeOut_ExpectAnyArgsAndReturn( pdFALSE ); @@ -363,15 +447,15 @@ void test_vDNSCheckCallback_success_search_id_null_timeout( void ) List_t xTempList; void * pvSearchID = ( void * ) 456; - dnsCallback.pvSearchID = pvSearchID; - dnsCallback.xIsIPv6 = 0; - dnsCallback.pCallbackFunction = dns_callback; + dnsCallback->pvSearchID = pvSearchID; + dnsCallback->xIsIPv6 = 0; + dnsCallback->pCallbackFunction = dns_callback; listGET_END_MARKER_ExpectAnyArgsAndReturn( ( ListItem_t * ) 8 ); vListInitialise_ExpectAnyArgs(); vTaskSuspendAll_Expect(); listGET_NEXT_ExpectAnyArgsAndReturn( ( ListItem_t * ) 16 ); - listGET_LIST_ITEM_OWNER_ExpectAnyArgsAndReturn( &dnsCallback ); + listGET_LIST_ITEM_OWNER_ExpectAnyArgsAndReturn( dnsCallback ); listGET_NEXT_ExpectAnyArgsAndReturn( ( ListItem_t * ) 8 ); /* end marker */ xTaskCheckForTimeOut_ExpectAnyArgsAndReturn( pdTRUE ); @@ -383,7 +467,7 @@ void test_vDNSCheckCallback_success_search_id_null_timeout( void ) listGET_END_MARKER_ExpectAnyArgsAndReturn( NULL ); listGET_NEXT_ExpectAnyArgsAndReturn( ( ListItem_t * ) 16 ); - listGET_LIST_ITEM_OWNER_ExpectAnyArgsAndReturn( &dnsCallback ); + listGET_LIST_ITEM_OWNER_ExpectAnyArgsAndReturn( dnsCallback ); listGET_NEXT_ExpectAnyArgsAndReturn( NULL ); /* end marker */ uxListRemove_ExpectAnyArgsAndReturn( pdTRUE ); vPortFree_ExpectAnyArgs(); @@ -407,15 +491,15 @@ void test_vDNSCheckCallback_success_search_id_null_timeout_IPv6( void ) List_t xTempList; void * pvSearchID = ( void * ) 456; - dnsCallback.pvSearchID = pvSearchID; - dnsCallback.xIsIPv6 = 1; - dnsCallback.pCallbackFunction = dns_callback; + dnsCallback->pvSearchID = pvSearchID; + dnsCallback->xIsIPv6 = 1; + dnsCallback->pCallbackFunction = dns_callback; listGET_END_MARKER_ExpectAnyArgsAndReturn( ( ListItem_t * ) 8 ); vListInitialise_ExpectAnyArgs(); vTaskSuspendAll_Expect(); listGET_NEXT_ExpectAnyArgsAndReturn( ( ListItem_t * ) 16 ); - listGET_LIST_ITEM_OWNER_ExpectAnyArgsAndReturn( &dnsCallback ); + listGET_LIST_ITEM_OWNER_ExpectAnyArgsAndReturn( dnsCallback ); listGET_NEXT_ExpectAnyArgsAndReturn( ( ListItem_t * ) 8 ); /* end marker */ xTaskCheckForTimeOut_ExpectAnyArgsAndReturn( pdTRUE ); @@ -427,7 +511,7 @@ void test_vDNSCheckCallback_success_search_id_null_timeout_IPv6( void ) listGET_END_MARKER_ExpectAnyArgsAndReturn( NULL ); listGET_NEXT_ExpectAnyArgsAndReturn( ( ListItem_t * ) 16 ); - listGET_LIST_ITEM_OWNER_ExpectAnyArgsAndReturn( &dnsCallback ); + listGET_LIST_ITEM_OWNER_ExpectAnyArgsAndReturn( dnsCallback ); listGET_NEXT_ExpectAnyArgsAndReturn( NULL ); /* end marker */ uxListRemove_ExpectAnyArgsAndReturn( pdTRUE ); vPortFree_ExpectAnyArgs(); @@ -451,15 +535,15 @@ void test_vDNSCheckCallback_success_search_id_null_timeout2( void ) void * pvSearchID = ( void * ) 456; void * pvSearchID2 = ( void * ) 457; - dnsCallback.pvSearchID = pvSearchID2; - dnsCallback.xIsIPv6 = 0; - dnsCallback.pCallbackFunction = dns_callback; + dnsCallback->pvSearchID = pvSearchID2; + dnsCallback->xIsIPv6 = 0; + dnsCallback->pCallbackFunction = dns_callback; listGET_END_MARKER_ExpectAnyArgsAndReturn( ( ListItem_t * ) 8 ); vListInitialise_ExpectAnyArgs(); vTaskSuspendAll_Expect(); listGET_NEXT_ExpectAnyArgsAndReturn( ( ListItem_t * ) 16 ); - listGET_LIST_ITEM_OWNER_ExpectAnyArgsAndReturn( &dnsCallback ); + listGET_LIST_ITEM_OWNER_ExpectAnyArgsAndReturn( dnsCallback ); listGET_NEXT_ExpectAnyArgsAndReturn( ( ListItem_t * ) 8 ); /* end marker */ xTaskCheckForTimeOut_ExpectAnyArgsAndReturn( pdTRUE ); @@ -471,7 +555,7 @@ void test_vDNSCheckCallback_success_search_id_null_timeout2( void ) listGET_END_MARKER_ExpectAnyArgsAndReturn( NULL ); listGET_NEXT_ExpectAnyArgsAndReturn( ( ListItem_t * ) 16 ); - listGET_LIST_ITEM_OWNER_ExpectAnyArgsAndReturn( &dnsCallback ); + listGET_LIST_ITEM_OWNER_ExpectAnyArgsAndReturn( dnsCallback ); listGET_NEXT_ExpectAnyArgsAndReturn( NULL ); /* end marker */ uxListRemove_ExpectAnyArgsAndReturn( pdTRUE ); vPortFree_ExpectAnyArgs(); @@ -495,15 +579,15 @@ void test_vDNSCheckCallback_success_search_id_null_timeout2_IPv6( void ) void * pvSearchID = ( void * ) 456; void * pvSearchID2 = ( void * ) 457; - dnsCallback.pvSearchID = pvSearchID2; - dnsCallback.xIsIPv6 = 1; - dnsCallback.pCallbackFunction = dns_callback; + dnsCallback->pvSearchID = pvSearchID2; + dnsCallback->xIsIPv6 = 1; + dnsCallback->pCallbackFunction = dns_callback; listGET_END_MARKER_ExpectAnyArgsAndReturn( ( ListItem_t * ) 8 ); vListInitialise_ExpectAnyArgs(); vTaskSuspendAll_Expect(); listGET_NEXT_ExpectAnyArgsAndReturn( ( ListItem_t * ) 16 ); - listGET_LIST_ITEM_OWNER_ExpectAnyArgsAndReturn( &dnsCallback ); + listGET_LIST_ITEM_OWNER_ExpectAnyArgsAndReturn( dnsCallback ); listGET_NEXT_ExpectAnyArgsAndReturn( ( ListItem_t * ) 8 ); /* end marker */ xTaskCheckForTimeOut_ExpectAnyArgsAndReturn( pdTRUE ); @@ -515,7 +599,7 @@ void test_vDNSCheckCallback_success_search_id_null_timeout2_IPv6( void ) listGET_END_MARKER_ExpectAnyArgsAndReturn( NULL ); listGET_NEXT_ExpectAnyArgsAndReturn( ( ListItem_t * ) 16 ); - listGET_LIST_ITEM_OWNER_ExpectAnyArgsAndReturn( &dnsCallback ); + listGET_LIST_ITEM_OWNER_ExpectAnyArgsAndReturn( dnsCallback ); listGET_NEXT_ExpectAnyArgsAndReturn( NULL ); /* end marker */ uxListRemove_ExpectAnyArgsAndReturn( pdTRUE ); vPortFree_ExpectAnyArgs(); diff --git a/test/unit-test/FreeRTOS_DNS_Callback/ut.cmake b/test/unit-test/FreeRTOS_DNS_Callback/ut.cmake index e1962eaaa3..6d0688f6e7 100644 --- a/test/unit-test/FreeRTOS_DNS_Callback/ut.cmake +++ b/test/unit-test/FreeRTOS_DNS_Callback/ut.cmake @@ -41,7 +41,7 @@ list(APPEND mock_define_list # ================= Create the library under test here (edit) ================== -add_compile_options(-Wno-pedantic -Wno-div-by-zero -O0 -ggdb3) +add_compile_options(-Wno-pedantic -ggdb3) # list the files you would like to test here set(real_source_files "") list(APPEND real_source_files diff --git a/test/unit-test/FreeRTOS_DNS_ConfigNoCallback/FreeRTOS_DNS_ConfigNoCallback_utest.c b/test/unit-test/FreeRTOS_DNS_ConfigNoCallback/FreeRTOS_DNS_ConfigNoCallback_utest.c index 74ed71c802..b00f4970ec 100644 --- a/test/unit-test/FreeRTOS_DNS_ConfigNoCallback/FreeRTOS_DNS_ConfigNoCallback_utest.c +++ b/test/unit-test/FreeRTOS_DNS_ConfigNoCallback/FreeRTOS_DNS_ConfigNoCallback_utest.c @@ -90,10 +90,9 @@ void setUp( void ) void test_FreeRTOS_getaddrinfo_IPv4AddressFound( void ) { BaseType_t xReturn; - struct freertos_addrinfo xAddress, * pxAddress = &xAddress; + struct freertos_addrinfo * pxAddress; struct freertos_addrinfo xHint, * pxHint = &xHint; - memset( &xAddress, 0, sizeof( struct freertos_addrinfo ) ); memset( &xHint, 0, sizeof( struct freertos_addrinfo ) ); xHint.ai_family = FREERTOS_AF_INET4; @@ -107,6 +106,8 @@ void test_FreeRTOS_getaddrinfo_IPv4AddressFound( void ) TEST_ASSERT_EQUAL( FREERTOS_AF_INET4, pxAddress->ai_family ); TEST_ASSERT_EQUAL( DOTTED_IPV4_ADDRESS_UINT32, FreeRTOS_htonl( pxAddress->ai_addr->sin_address.ulIP_IPv4 ) ); TEST_ASSERT_EQUAL( ipSIZE_OF_IPv4_ADDRESS, pxAddress->ai_addrlen ); + + vPortFree( pxAddress ); /* Make LeakSanitizer happy. */ } /** diff --git a/test/unit-test/FreeRTOS_DNS_ConfigNoCallback/ut.cmake b/test/unit-test/FreeRTOS_DNS_ConfigNoCallback/ut.cmake index 9e63fd66e7..6146679ff6 100644 --- a/test/unit-test/FreeRTOS_DNS_ConfigNoCallback/ut.cmake +++ b/test/unit-test/FreeRTOS_DNS_ConfigNoCallback/ut.cmake @@ -41,7 +41,7 @@ list(APPEND mock_define_list # ================= Create the library under test here (edit) ================== -add_compile_options(-Wno-pedantic -Wno-div-by-zero -O0 -ggdb3) +add_compile_options(-Wno-pedantic -ggdb3) # list the files you would like to test here set(real_source_files "") list(APPEND real_source_files diff --git a/test/unit-test/FreeRTOS_DNS_Networking/FreeRTOS_DNS_Networking_utest.c b/test/unit-test/FreeRTOS_DNS_Networking/FreeRTOS_DNS_Networking_utest.c index 8419e537fe..f109cd6629 100644 --- a/test/unit-test/FreeRTOS_DNS_Networking/FreeRTOS_DNS_Networking_utest.c +++ b/test/unit-test/FreeRTOS_DNS_Networking/FreeRTOS_DNS_Networking_utest.c @@ -195,7 +195,8 @@ void test_SendRequest_fail( void ) struct freertos_sockaddr xAddress; struct xDNSBuffer pxDNSBuf; - FreeRTOS_sendto_ExpectAnyArgsAndReturn( pdFALSE ); + pxDNSBuf.uxPayloadLength = 1024; + FreeRTOS_sendto_ExpectAnyArgsAndReturn( 1023 ); ret = DNS_SendRequest( s, &xAddress, &pxDNSBuf ); diff --git a/test/unit-test/FreeRTOS_DNS_Networking/ut.cmake b/test/unit-test/FreeRTOS_DNS_Networking/ut.cmake index 36328c3386..083ffaf027 100644 --- a/test/unit-test/FreeRTOS_DNS_Networking/ut.cmake +++ b/test/unit-test/FreeRTOS_DNS_Networking/ut.cmake @@ -35,7 +35,7 @@ list(APPEND mock_define_list # ================= Create the library under test here (edit) ================== -add_compile_options(-Wno-pedantic -Wno-div-by-zero -O0 -ggdb3) +add_compile_options(-Wno-pedantic -ggdb3) # list the files you would like to test here set(real_source_files "" ) diff --git a/test/unit-test/FreeRTOS_DNS_Parser/FreeRTOS_DNS_Parser_utest.c b/test/unit-test/FreeRTOS_DNS_Parser/FreeRTOS_DNS_Parser_utest.c index 0a487c20d0..cee6d148a6 100644 --- a/test/unit-test/FreeRTOS_DNS_Parser/FreeRTOS_DNS_Parser_utest.c +++ b/test/unit-test/FreeRTOS_DNS_Parser/FreeRTOS_DNS_Parser_utest.c @@ -57,6 +57,10 @@ #define BAD_ADDRESS "this is a bad address" #define DOTTED_ADDRESS "192.268.0.1" +#define prvROUND_UP_TO( SIZE, ALIGNMENT ) ( ( ( SIZE ) + ( ALIGNMENT ) -1 ) / ( ALIGNMENT ) *( ALIGNMENT ) ) + +#define prvALIGNED_UDP_PAYLOAD_OFFSET_IPv4 prvROUND_UP_TO( ipUDP_PAYLOAD_OFFSET_IPv4, sizeof( void * ) ) + typedef void (* FOnDNSEvent ) ( const char * /* pcName */, void * /* pvSearchID */, struct freertos_addrinfo * /* pxAddressInfo */ ); @@ -1463,6 +1467,90 @@ void test_DNS_ParseDNSReply_answer_record_no_answers( void ) TEST_ASSERT_EQUAL( pdFALSE, ret ); } +/** + * @brief Check the case when the DNS answer record + * doesn't have any answers. + */ +void test_DNS_ParseDNSReply_answer_record_no_answers2( void ) +{ + uint32_t ret; + uint8_t pucUDPPayloadBuffer[ 250 ]; + size_t uxBufferLength = 250; + char dns[ 64 ]; + struct freertos_addrinfo * pxAddressInfo; + uint16_t usPort; + const uint16_t usFlags = dnsEXPECTED_RX_FLAGS; + + memset( dns, 'a', 64 ); + memset( pucUDPPayloadBuffer, 0x00, uxBufferLength ); + dns[ 63 ] = 0; + BaseType_t xExpected = pdFALSE; + size_t beg = sizeof( DNSMessage_t ); + + pucUDPPayloadBuffer[ offsetof( DNSMessage_t, usQuestions ) ] = 0; + pucUDPPayloadBuffer[ offsetof( DNSMessage_t, usAnswers ) ] = 0; + + memcpy( &pucUDPPayloadBuffer[ offsetof( DNSMessage_t, usFlags ) ], &usFlags, sizeof( uint16_t ) ); + + pucUDPPayloadBuffer[ beg ] = 38; + beg++; + strcpy( pucUDPPayloadBuffer + beg, "FreeRTOSbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb" ); + beg += 38; + + ret = DNS_ParseDNSReply( pucUDPPayloadBuffer, + uxBufferLength, + &pxAddressInfo, + xExpected, + usPort ); + TEST_ASSERT_EQUAL( pdFALSE, ret ); +} + +/** + * @brief Check the case when the DNS answer record + * doesn't have any questions. + */ +void test_DNS_ParseDNSReply_answer_record_no_questions( void ) +{ + uint32_t ret; + uint8_t pucUDPPayloadBuffer[ 250 ]; + size_t uxBufferLength = 250; + char dns[ 64 ]; + struct freertos_addrinfo * pxAddressInfo; + uint16_t usPort; + const uint16_t usFlags = dnsEXPECTED_RX_FLAGS; + + memset( dns, 'a', 64 ); + memset( pucUDPPayloadBuffer, 0x00, uxBufferLength ); + dns[ 63 ] = 0; + BaseType_t xExpected = pdFALSE; + size_t beg = sizeof( DNSMessage_t ); + + DNSMessage_t * dns_header; + + dns_header = ( DNSMessage_t * ) &pucUDPPayloadBuffer; + + dns_header->usQuestions = FreeRTOS_htons( 0 ); + dns_header->usAnswers = FreeRTOS_htons( 1 ); + + memcpy( &pucUDPPayloadBuffer[ offsetof( DNSMessage_t, usFlags ) ], &usFlags, sizeof( uint16_t ) ); + + pucUDPPayloadBuffer[ beg ] = 38; + beg++; + strcpy( pucUDPPayloadBuffer + beg, "FreeRTOSbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb" ); + beg += 38; + + usChar2u16_ExpectAnyArgsAndReturn( dnsTYPE_A_HOST ); /* usType */ + + hook_return = pdTRUE; + + ret = DNS_ParseDNSReply( pucUDPPayloadBuffer, + uxBufferLength, + &pxAddressInfo, + xExpected, + usPort ); + TEST_ASSERT_EQUAL( pdFALSE, ret ); +} + /** * @brief Test DNS_ParseDNSReply when the endpoint has an invalid IP (0) */ @@ -1545,8 +1633,8 @@ void test_DNS_ParseDNSReply_InvalidEndpointIP( void ) void test_DNS_ParseDNSReply_InvalidEndpointType( void ) { uint32_t ret; - uint8_t udp_buffer[ 250 + ipUDP_PAYLOAD_OFFSET_IPv4 ] = { 0 }; - uint8_t * pucUDPPayloadBuffer = ( ( uint8_t * ) udp_buffer ) + ipUDP_PAYLOAD_OFFSET_IPv4; + uint8_t udp_buffer[ prvALIGNED_UDP_PAYLOAD_OFFSET_IPv4 + 250 ] = { 0 }; + uint8_t * pucUDPPayloadBuffer = udp_buffer + prvALIGNED_UDP_PAYLOAD_OFFSET_IPv4; size_t uxBufferLength = 250; struct freertos_addrinfo * pxAddressInfo; uint16_t usPort; @@ -1558,11 +1646,11 @@ void test_DNS_ParseDNSReply_InvalidEndpointType( void ) memset( pucUDPPayloadBuffer, 0x00, uxBufferLength ); NetworkBufferDescriptor_t pxNetworkBuffer = { 0 }; - pxNetworkBuffer.pucEthernetBuffer = udp_buffer; + pxNetworkBuffer.pucEthernetBuffer = udp_buffer + prvALIGNED_UDP_PAYLOAD_OFFSET_IPv4 - ipUDP_PAYLOAD_OFFSET_IPv4; pxNetworkBuffer.xDataLength = uxBufferLength; NetworkBufferDescriptor_t pxNewBuffer; - pxNewBuffer.pucEthernetBuffer = udp_buffer; + pxNewBuffer.pucEthernetBuffer = udp_buffer + prvALIGNED_UDP_PAYLOAD_OFFSET_IPv4 - ipUDP_PAYLOAD_OFFSET_IPv4; pxNewBuffer.xDataLength = uxBufferLength; pxNetworkBuffer.pxEndPoint = &xEndPoint; xEndPoint.bits.bIPv6 = pdTRUE; @@ -1684,8 +1772,8 @@ void test_DNS_ParseDNSReply_answer_record_too_many_answers( void ) void test_DNS_ParseDNSReply_answer_lmmnr_reply_xBufferAllocFixedsize( void ) { uint32_t ret; - uint8_t udp_buffer[ 250 + ipUDP_PAYLOAD_OFFSET_IPv4 ] = { 0 }; - uint8_t * pucUDPPayloadBuffer = ( ( uint8_t * ) udp_buffer ) + ipUDP_PAYLOAD_OFFSET_IPv4; + uint8_t udp_buffer[ prvALIGNED_UDP_PAYLOAD_OFFSET_IPv4 + 250 ] = { 0 }; + uint8_t * pucUDPPayloadBuffer = udp_buffer + prvALIGNED_UDP_PAYLOAD_OFFSET_IPv4; size_t uxBufferLength = 250; struct freertos_addrinfo * pxAddressInfo; uint16_t usPort; @@ -1697,11 +1785,11 @@ void test_DNS_ParseDNSReply_answer_lmmnr_reply_xBufferAllocFixedsize( void ) memset( pucUDPPayloadBuffer, 0x00, uxBufferLength ); NetworkBufferDescriptor_t pxNetworkBuffer = { 0 }; - pxNetworkBuffer.pucEthernetBuffer = udp_buffer; + pxNetworkBuffer.pucEthernetBuffer = udp_buffer + prvALIGNED_UDP_PAYLOAD_OFFSET_IPv4 - ipUDP_PAYLOAD_OFFSET_IPv4; pxNetworkBuffer.xDataLength = uxBufferLength; NetworkBufferDescriptor_t pxNewBuffer; - pxNewBuffer.pucEthernetBuffer = udp_buffer; + pxNewBuffer.pucEthernetBuffer = udp_buffer + prvALIGNED_UDP_PAYLOAD_OFFSET_IPv4 - ipUDP_PAYLOAD_OFFSET_IPv4; pxNewBuffer.xDataLength = uxBufferLength; char dns[ 64 ]; @@ -1762,8 +1850,8 @@ void test_DNS_ParseDNSReply_answer_lmmnr_reply_xBufferAllocFixedsize( void ) void test_DNS_ParseDNSReply_answer_lmmnr_reply( void ) { uint32_t ret; - uint8_t udp_buffer[ 250 + ipUDP_PAYLOAD_OFFSET_IPv4 ] = { 0 }; - uint8_t * pucUDPPayloadBuffer = ( ( uint8_t * ) udp_buffer ) + ipUDP_PAYLOAD_OFFSET_IPv4; + uint8_t udp_buffer[ prvALIGNED_UDP_PAYLOAD_OFFSET_IPv4 + 250 ] = { 0 }; + uint8_t * pucUDPPayloadBuffer = udp_buffer + prvALIGNED_UDP_PAYLOAD_OFFSET_IPv4; size_t uxBufferLength = 250; struct freertos_addrinfo * pxAddressInfo; uint16_t usPort; @@ -1772,7 +1860,7 @@ void test_DNS_ParseDNSReply_answer_lmmnr_reply( void ) memset( pucUDPPayloadBuffer, 0x00, uxBufferLength ); NetworkBufferDescriptor_t pxNetworkBuffer = { 0 }; - pxNetworkBuffer.pucEthernetBuffer = udp_buffer; + pxNetworkBuffer.pucEthernetBuffer = udp_buffer + prvALIGNED_UDP_PAYLOAD_OFFSET_IPv4 - ipUDP_PAYLOAD_OFFSET_IPv4; pxNetworkBuffer.xDataLength = uxBufferLength; char dns[ 64 ]; @@ -1907,7 +1995,7 @@ void test_DNS_ParseDNSReply_answer_lmmnr_reply2( void ) */ void test_DNS_ParseDNSReply_answer_lmmnr_reply3( void ) { - uint32_t ret; + uint32_t ret = 0xDEADC0DE; uint8_t udp_buffer[ 250 + ipUDP_PAYLOAD_OFFSET_IPv4 ] = { 0 }; uint8_t * pucUDPPayloadBuffer = ( ( uint8_t * ) udp_buffer ) + ipUDP_PAYLOAD_OFFSET_IPv4 - 1; size_t uxBufferLength = 250; @@ -1970,7 +2058,8 @@ void test_DNS_ParseDNSReply_answer_lmmnr_reply3( void ) xExpected, usPort ) ); - TEST_ASSERT_EQUAL( pdFALSE, ret ); + /* ret is not reassigned, because the function asserts. */ + TEST_ASSERT_EQUAL( 0xDEADC0DE, ret ); ASSERT_DNS_QUERY_HOOK_NOT_CALLED(); } @@ -2817,6 +2906,7 @@ void test_parseDNSAnswer_null_bytes( void ) xSet.pxDNSMessageHeader = &pxDNSMessageHeader; xSet.pucByte = pucByte; + xSet.usAnswers = ipconfigDNS_CACHE_ADDRESSES_PER_ENTRY; xSet.uxSourceBytesRemaining = uxsourceBytesRemaining; xSet.xDoStore = pdTRUE; xSet.usNumARecordsStored = 0; @@ -2853,6 +2943,7 @@ void test_parseDNSAnswer_recordstored_gt_count( void ) char pcName[ 300 ]; DNSAnswerRecord_t * pxDNSAnswerRecord; IPv46_Address_t ip_address; + const uint32_t ulTestAddress = 0xABCD1234; ip_address.xIPAddress.ulIP_IPv4 = 1234; ip_address.xIs_IPv6 = pdFALSE; @@ -2865,6 +2956,7 @@ void test_parseDNSAnswer_recordstored_gt_count( void ) xSet.xDoStore = pdTRUE; xSet.usNumARecordsStored = 0; xSet.ppxLastAddress = &pxAddressInfo_2; + xSet.usAnswers = ipconfigDNS_CACHE_ADDRESSES_PER_ENTRY; memset( pucByte, 0x00, uxsourceBytesRemaining ); @@ -2876,8 +2968,7 @@ void test_parseDNSAnswer_recordstored_gt_count( void ) pxDNSAnswerRecord->usDataLength = FreeRTOS_htons( ipSIZE_OF_IPv4_ADDRESS ); pxDNSAnswerRecord->usType = ( dnsTYPE_A_HOST ); - uint32_t * pulTestAddress = ( uint32_t * ) ( ( ( uint8_t * ) pxDNSAnswerRecord ) + sizeof( DNSAnswerRecord_t ) ); - *pulTestAddress = 0xABCD1234; + memcpy( ( ( uint8_t * ) pxDNSAnswerRecord ) + sizeof( DNSAnswerRecord_t ), &ulTestAddress, sizeof( ulTestAddress ) ); usChar2u16_ExpectAnyArgsAndReturn( dnsTYPE_A_HOST ); /* usType */ pxNew_AddrInfo_ExpectAnyArgsAndReturn( pxAddressInfo ); @@ -2915,6 +3006,7 @@ void test_parseDNSAnswer_recordstored_gt_count_diffUsType( void ) xSet.xDoStore = pdTRUE; xSet.usNumARecordsStored = 0; xSet.ppxLastAddress = &pxAddressInfo_2; + xSet.usAnswers = ipconfigDNS_CACHE_ADDRESSES_PER_ENTRY; memset( pucByte, 0x00, uxsourceBytesRemaining ); @@ -2959,6 +3051,7 @@ void test_parseDNSAnswer_recordNOTstored_gt_count_diffUsType( void ) xSet.xDoStore = pdTRUE; xSet.usNumARecordsStored = 0; xSet.ppxLastAddress = &pxAddressInfo_2; + xSet.usAnswers = ipconfigDNS_CACHE_ADDRESSES_PER_ENTRY; memset( pucByte, 0x00, uxsourceBytesRemaining ); @@ -2971,12 +3064,10 @@ void test_parseDNSAnswer_recordNOTstored_gt_count_diffUsType( void ) pxDNSAnswerRecord->usDataLength = FreeRTOS_htons( ipSIZE_OF_IPv4_ADDRESS ); pxDNSAnswerRecord->usType = ( dnsTYPE_AAAA_HOST ); - usChar2u16_ExpectAnyArgsAndReturn( dnsTYPE_AAAA_HOST ); /* usType */ - ret = parseDNSAnswer( &xSet, &pxAddressInfo, &uxBytesRead ); TEST_ASSERT_EQUAL( 0, ret ); - TEST_ASSERT_EQUAL( 40, uxBytesRead ); + TEST_ASSERT_EQUAL( 0, uxBytesRead ); } /** @@ -3004,6 +3095,8 @@ void test_parseDNSAnswer_recordstored_gt_count_IPv6_fail1( void ) xSet.usNumARecordsStored = 0; xSet.ppxLastAddress = &pxAddressInfo_2; xSet.uxAddressLength = ipSIZE_OF_IPv6_ADDRESS; + xSet.usAnswers = ipconfigDNS_CACHE_ADDRESSES_PER_ENTRY; + memset( pucByte, 0x00, uxsourceBytesRemaining ); @@ -3048,6 +3141,8 @@ void test_parseDNSAnswer_recordstored_gt_count_IPv6_fail2( void ) xSet.usNumARecordsStored = 0; xSet.uxAddressLength = ipSIZE_OF_IPv6_ADDRESS; xSet.ppxLastAddress = &pxAddressInfo_2; + xSet.usAnswers = ipconfigDNS_CACHE_ADDRESSES_PER_ENTRY; + memset( pucByte, 0x00, uxsourceBytesRemaining ); @@ -3086,7 +3181,7 @@ void test_parseDNSAnswer_recordstored_gt_count_IPv6_success( void ) memset( &( ip_address.xIPAddress.xIP_IPv6 ), 1, ipSIZE_OF_IPv6_ADDRESS ); ip_address.xIs_IPv6 = pdTRUE; ParseSet_t xSet = { 0 }; - struct freertos_addrinfo * pxAddressInfo, * pxAddressInfo_2; + struct freertos_addrinfo xAddressInfo = { 0 }, * pxAddressInfo, * pxAddressInfo_2; xSet.pxDNSMessageHeader = &pxDNSMessageHeader; xSet.pucByte = pucByte; @@ -3094,6 +3189,8 @@ void test_parseDNSAnswer_recordstored_gt_count_IPv6_success( void ) xSet.xDoStore = pdTRUE; xSet.usNumARecordsStored = 0; xSet.ppxLastAddress = &pxAddressInfo_2; + xSet.usAnswers = ipconfigDNS_CACHE_ADDRESSES_PER_ENTRY; + memset( pucByte, 0x00, uxsourceBytesRemaining ); @@ -3106,7 +3203,7 @@ void test_parseDNSAnswer_recordstored_gt_count_IPv6_success( void ) pxDNSAnswerRecord->usType = ( dnsTYPE_AAAA_HOST ); usChar2u16_ExpectAnyArgsAndReturn( dnsTYPE_AAAA_HOST ); /* usType */ - pxNew_AddrInfo_ExpectAnyArgsAndReturn( pxAddressInfo ); + pxNew_AddrInfo_ExpectAnyArgsAndReturn( &xAddressInfo ); xDNSDoCallback_ExpectAnyArgsAndReturn( pdTRUE ); FreeRTOS_dns_update_ExpectAnyArgsAndReturn( pdTRUE ); FreeRTOS_dns_update_ReturnThruPtr_pxIP( &ip_address ); @@ -3145,6 +3242,8 @@ void test_parseDNSAnswer_recordstored_gt_count_IPv6_success2( void ) xSet.xDoStore = pdTRUE; xSet.usNumARecordsStored = 0; xSet.ppxLastAddress = &pxAddressInfo_2; + xSet.usAnswers = ipconfigDNS_CACHE_ADDRESSES_PER_ENTRY; + memset( pucByte, 0x00, uxsourceBytesRemaining ); @@ -3196,6 +3295,8 @@ void test_parseDNSAnswer_recordstored_gt_count_IPv6_success3( void ) xSet.xDoStore = pdTRUE; xSet.usNumARecordsStored = 0; xSet.ppxLastAddress = &pxAddressInfo_2; + xSet.usAnswers = ipconfigDNS_CACHE_ADDRESSES_PER_ENTRY; + memset( pucByte, 0x00, uxsourceBytesRemaining ); @@ -3231,6 +3332,7 @@ void test_parseDNSAnswer_recordstored_gt_count_IPv6_fail_nullLinkedListForDNSAns char pcName[ 300 ]; DNSAnswerRecord_t * pxDNSAnswerRecord; IPv46_Address_t ip_address; + const uint32_t ulTestAddress = 0xABCD1234; memset( &( ip_address.xIPAddress.xIP_IPv6 ), 1, ipSIZE_OF_IPv6_ADDRESS ); ip_address.xIs_IPv6 = pdTRUE; @@ -3243,6 +3345,8 @@ void test_parseDNSAnswer_recordstored_gt_count_IPv6_fail_nullLinkedListForDNSAns xSet.xDoStore = pdTRUE; xSet.usNumARecordsStored = 0; xSet.ppxLastAddress = &pxAddressInfo_2; + xSet.usAnswers = ipconfigDNS_CACHE_ADDRESSES_PER_ENTRY; + memset( pucByte, 0x00, uxsourceBytesRemaining ); @@ -3254,8 +3358,7 @@ void test_parseDNSAnswer_recordstored_gt_count_IPv6_fail_nullLinkedListForDNSAns pxDNSAnswerRecord->usDataLength = FreeRTOS_htons( ipSIZE_OF_IPv4_ADDRESS ); pxDNSAnswerRecord->usType = ( dnsTYPE_A_HOST ); - uint32_t * pulTestAddress = ( uint32_t * ) ( ( ( uint8_t * ) pxDNSAnswerRecord ) + sizeof( DNSAnswerRecord_t ) ); - *pulTestAddress = 0xABCD1234; + memcpy( ( ( uint8_t * ) pxDNSAnswerRecord ) + sizeof( DNSAnswerRecord_t ), &ulTestAddress, sizeof( ulTestAddress ) ); usChar2u16_ExpectAnyArgsAndReturn( dnsTYPE_A_HOST ); /* usType */ xDNSDoCallback_ExpectAnyArgsAndReturn( pdTRUE ); @@ -3327,6 +3430,8 @@ void test_parseDNSAnswer_recordstored_gt_count2( void ) xSet.usNumARecordsStored = 0; xSet.pxDNSMessageHeader = &pxDNSMessageHeader; xSet.uxSourceBytesRemaining = uxsourceBytesRemaining; + xSet.usAnswers = ipconfigDNS_CACHE_ADDRESSES_PER_ENTRY + 1; + strcpy( xSet.pcName, pcName ); xSet.xDoStore = xDoStore; @@ -3364,11 +3469,12 @@ void test_parseDNSAnswer_dns_nocallback_false( void ) BaseType_t xDoStore = pdTRUE; DNSAnswerRecord_t * pxDNSAnswerRecord; IPv46_Address_t ip_address; + const uint32_t ulTestAddress = 0xABCD1234; ip_address.xIPAddress.ulIP_IPv4 = 5678; ip_address.xIs_IPv6 = pdFALSE; ParseSet_t xSet = { 0 }; - struct freertos_addrinfo * pxAddressInfo; + struct freertos_addrinfo xAddressInfo = { 0 }; struct freertos_addrinfo ** ppxAddressInfo = ( struct freertos_addrinfo ** ) &pucAddrBuffer; *ppxAddressInfo = NULL; @@ -3383,8 +3489,7 @@ void test_parseDNSAnswer_dns_nocallback_false( void ) pxDNSAnswerRecord->usDataLength = FreeRTOS_htons( ipSIZE_OF_IPv4_ADDRESS ); pxDNSAnswerRecord->usType = ( dnsTYPE_A_HOST ); - uint32_t * pulTestAddress = ( uint32_t * ) ( ( ( uint8_t * ) pxDNSAnswerRecord ) + sizeof( DNSAnswerRecord_t ) ); - *pulTestAddress = 0xABCD1234; + memcpy( ( ( uint8_t * ) pxDNSAnswerRecord ) + sizeof( DNSAnswerRecord_t ), &ulTestAddress, sizeof( ulTestAddress ) ); xSet.pucByte = pucByte; xSet.usNumARecordsStored = 0; @@ -3392,9 +3497,10 @@ void test_parseDNSAnswer_dns_nocallback_false( void ) xSet.uxSourceBytesRemaining = uxsourceBytesRemaining; xSet.xDoStore = xDoStore; xSet.ppxLastAddress = ppxAddressInfo; + xSet.usAnswers = ipconfigDNS_CACHE_ADDRESSES_PER_ENTRY + 1; usChar2u16_ExpectAnyArgsAndReturn( dnsTYPE_A_HOST ); /* usType */ - pxNew_AddrInfo_ExpectAnyArgsAndReturn( pxAddressInfo ); + pxNew_AddrInfo_ExpectAnyArgsAndReturn( &xAddressInfo ); xDNSDoCallback_ExpectAnyArgsAndReturn( pdFALSE ); FreeRTOS_dns_update_ExpectAnyArgsAndReturn( pdTRUE ); FreeRTOS_dns_update_ReturnThruPtr_pxIP( &ip_address ); @@ -3423,6 +3529,7 @@ void test_parseDNSAnswer_do_store_false( void ) ParseSet_t xSet = { 0 }; struct freertos_addrinfo * pxAddressInfo; struct freertos_addrinfo ** ppxAddressInfo = ( struct freertos_addrinfo ** ) &pucAddrBuffer; + const uint32_t ulTestAddress = 0xABCD1234; memset( pucByte, 0x00, 300 ); memset( pcName, 0x00, 300 ); @@ -3438,9 +3545,10 @@ void test_parseDNSAnswer_do_store_false( void ) xSet.uxSourceBytesRemaining = uxsourceBytesRemaining; xSet.xDoStore = xDoStore; xSet.ppxLastAddress = ppxAddressInfo; + xSet.usAnswers = ipconfigDNS_CACHE_ADDRESSES_PER_ENTRY + 1; usChar2u16_ExpectAnyArgsAndReturn( dnsTYPE_A_HOST ); /* usType */ - pxNew_AddrInfo_ExpectAnyArgsAndReturn( pxAddressInfo ); + pxNew_AddrInfo_ExpectAnyArgsAndReturn( NULL ); xDNSDoCallback_ExpectAnyArgsAndReturn( pdFALSE ); FreeRTOS_inet_ntop_ExpectAnyArgsAndReturn( "ignored" ); @@ -3448,8 +3556,7 @@ void test_parseDNSAnswer_do_store_false( void ) pxDNSAnswerRecord->usDataLength = FreeRTOS_htons( ipSIZE_OF_IPv4_ADDRESS ); pxDNSAnswerRecord->usType = ( dnsTYPE_A_HOST ); - uint32_t * pulTestAddress = ( uint32_t * ) ( ( ( uint8_t * ) pxDNSAnswerRecord ) + sizeof( DNSAnswerRecord_t ) ); - *pulTestAddress = 0xABCD1234; + memcpy( ( ( uint8_t * ) pxDNSAnswerRecord ) + sizeof( DNSAnswerRecord_t ), &ulTestAddress, sizeof( ulTestAddress ) ); ret = parseDNSAnswer( &xSet, &pxAddressInfo, &uxBytesRead ); @@ -3486,6 +3593,7 @@ void test_parseDNSAnswer_dnsanswerrecord_datalength_ne_addresslength( void ) xSet.pxDNSMessageHeader = &pxDNSMessageHeader; xSet.uxSourceBytesRemaining = uxsourceBytesRemaining; xSet.xDoStore = xDoStore; + xSet.usAnswers = ipconfigDNS_CACHE_ADDRESSES_PER_ENTRY + 1; usChar2u16_ExpectAnyArgsAndReturn( dnsTYPE_A_HOST ); /* usType */ @@ -3529,6 +3637,7 @@ void test_parseDNSAnswer_remaining_gt_datalength( void ) xSet.pxDNSMessageHeader = &pxDNSMessageHeader; xSet.uxSourceBytesRemaining = uxsourceBytesRemaining; xSet.xDoStore = xDoStore; + xSet.usAnswers = ipconfigDNS_CACHE_ADDRESSES_PER_ENTRY + 1; usChar2u16_ExpectAnyArgsAndReturn( dnsTYPE_A_HOST ); /* usType */ @@ -3574,6 +3683,7 @@ void test_parseDNSAnswer_remaining_lt_uint16( void ) xSet.pxDNSMessageHeader = &pxDNSMessageHeader; xSet.uxSourceBytesRemaining = uxsourceBytesRemaining; xSet.xDoStore = xDoStore; + xSet.usAnswers = ipconfigDNS_CACHE_ADDRESSES_PER_ENTRY + 1; ret = parseDNSAnswer( &xSet, &pxAddressInfo, &uxBytesRead ); @@ -3614,6 +3724,7 @@ void test_parseDNSAnswer_remaining_lt_dnsanswerrecord( void ) xSet.pxDNSMessageHeader = &pxDNSMessageHeader; xSet.uxSourceBytesRemaining = uxsourceBytesRemaining; xSet.xDoStore = xDoStore; + xSet.usAnswers = ipconfigDNS_CACHE_ADDRESSES_PER_ENTRY + 1; usChar2u16_ExpectAnyArgsAndReturn( dnsTYPE_A_HOST + 1 ); usChar2u16_ExpectAnyArgsAndReturn( dnsTYPE_A_HOST ); diff --git a/test/unit-test/FreeRTOS_DNS_Parser/ut.cmake b/test/unit-test/FreeRTOS_DNS_Parser/ut.cmake index d8520accda..5356fb1be4 100755 --- a/test/unit-test/FreeRTOS_DNS_Parser/ut.cmake +++ b/test/unit-test/FreeRTOS_DNS_Parser/ut.cmake @@ -36,7 +36,7 @@ list(APPEND mock_define_list # ================= Create the library under test here (edit) ================== -add_compile_options(-Wno-pedantic -Wno-div-by-zero -O0 -ggdb3) +add_compile_options(-Wno-pedantic -ggdb3) # list the files you would like to test here set(real_source_files "" ) diff --git a/test/unit-test/FreeRTOS_IP/FreeRTOS_IP_stubs.c b/test/unit-test/FreeRTOS_IP/FreeRTOS_IP_stubs.c index f25be869e9..117d487d18 100644 --- a/test/unit-test/FreeRTOS_IP/FreeRTOS_IP_stubs.c +++ b/test/unit-test/FreeRTOS_IP/FreeRTOS_IP_stubs.c @@ -53,6 +53,12 @@ struct xNetworkEndPoint * pxNetworkEndPoints = NULL; const MACAddress_t xLLMNR_MacAddress = { { 0x01, 0x00, 0x5e, 0x00, 0x00, 0xfc } }; +const MACAddress_t xLLMNR_MacAddressIPv6 = { { 0x33, 0x33, 0x00, 0x01, 0x00, 0x03 } }; + +const MACAddress_t xMDNS_MacAddress = { { 0x01, 0x00, 0x5e, 0x00, 0x00, 0xfb } }; + +const MACAddress_t xMDNS_MacAddressIPv6 = { { 0x33, 0x33, 0x00, 0x00, 0x00, 0xFB } }; + void vPortEnterCritical( void ) { } diff --git a/test/unit-test/FreeRTOS_IP/FreeRTOS_IP_utest.c b/test/unit-test/FreeRTOS_IP/FreeRTOS_IP_utest.c index 45815ca5c3..ff9a69706b 100644 --- a/test/unit-test/FreeRTOS_IP/FreeRTOS_IP_utest.c +++ b/test/unit-test/FreeRTOS_IP/FreeRTOS_IP_utest.c @@ -267,7 +267,7 @@ void test_FreeRTOS_GetUDPPayloadBuffer_BlockTimeEqualToConfig( void ) uint8_t pucEthernetBuffer[ 1500 ]; /* Put the ethernet buffer in place. */ - pxNetworkBuffer->pucEthernetBuffer = pucEthernetBuffer; + pxNetworkBuffer->pucEthernetBuffer = pucEthernetBuffer + ipIP_TYPE_OFFSET; pxNetworkBuffer->xDataLength = 0; pxGetNetworkBufferWithDescriptor_ExpectAndReturn( sizeof( UDPPacket_t ) + uxRequestedSizeBytes, uxBlockTimeTicks, pxNetworkBuffer ); @@ -291,7 +291,7 @@ void test_FreeRTOS_GetUDPPayloadBuffer_BlockTimeLessThanConfig( void ) uint8_t pucEthernetBuffer[ 1500 ]; /* Put the ethernet buffer in place. */ - pxNetworkBuffer->pucEthernetBuffer = pucEthernetBuffer; + pxNetworkBuffer->pucEthernetBuffer = pucEthernetBuffer + ipIP_TYPE_OFFSET; pxNetworkBuffer->xDataLength = 0; pxGetNetworkBufferWithDescriptor_ExpectAndReturn( sizeof( UDPPacket_t ) + uxRequestedSizeBytes, uxBlockTimeTicks, pxNetworkBuffer ); @@ -316,7 +316,7 @@ void test_FreeRTOS_GetUDPPayloadBuffer_BlockTimeMoreThanConfig( void ) uint8_t pucEthernetBuffer[ 1500 ]; /* Put the ethernet buffer in place. */ - pxNetworkBuffer->pucEthernetBuffer = pucEthernetBuffer; + pxNetworkBuffer->pucEthernetBuffer = pucEthernetBuffer + ipIP_TYPE_OFFSET; pxNetworkBuffer->xDataLength = 0; pxGetNetworkBufferWithDescriptor_ExpectAndReturn( sizeof( UDPPacket_t ) + uxRequestedSizeBytes, ipconfigUDP_MAX_SEND_BLOCK_TIME_TICKS, pxNetworkBuffer ); @@ -1560,7 +1560,7 @@ void test_eConsiderFrameForProcessing_LocalMACMatch( void ) /* Align endpoint's & packet's MAC address. */ memset( pxEndPoint->xMACAddress.ucBytes, 0xAA, sizeof( MACAddress_t ) ); memcpy( pxEthernetHeader->xDestinationAddress.ucBytes, pxEndPoint->xMACAddress.ucBytes, sizeof( MACAddress_t ) ); - pxEthernetHeader->usFrameType = FreeRTOS_htons( 0x0800 ); + pxEthernetHeader->usFrameType = ipIPv4_FRAME_TYPE; eResult = eConsiderFrameForProcessing( ucEthernetBuffer ); @@ -1579,9 +1579,6 @@ void test_eConsiderFrameForProcessing_LocalMACMatchInvalidFrameType( void ) uint8_t ucEthernetBuffer[ ipconfigTCP_MSS ]; EthernetHeader_t * pxEthernetHeader; - /* eConsiderFrameForProcessing */ - FreeRTOS_FindEndPointOnMAC_ExpectAnyArgsAndReturn( pxEndPoint ); - /* Map the buffer onto Ethernet Header struct for easy access to fields. */ pxEthernetHeader = ( EthernetHeader_t * ) ucEthernetBuffer; @@ -1590,7 +1587,7 @@ void test_eConsiderFrameForProcessing_LocalMACMatchInvalidFrameType( void ) /* Align endpoint's & packet's MAC address. */ memset( pxEndPoint->xMACAddress.ucBytes, 0xAA, sizeof( MACAddress_t ) ); memcpy( pxEthernetHeader->xDestinationAddress.ucBytes, pxEndPoint->xMACAddress.ucBytes, sizeof( MACAddress_t ) ); - pxEthernetHeader->usFrameType = FreeRTOS_htons( 0 ); + pxEthernetHeader->usFrameType = 0; eResult = eConsiderFrameForProcessing( ucEthernetBuffer ); @@ -1609,9 +1606,6 @@ void test_eConsiderFrameForProcessing_LocalMACMatchInvalidFrameType1( void ) uint8_t ucEthernetBuffer[ ipconfigTCP_MSS ]; EthernetHeader_t * pxEthernetHeader; - /* eConsiderFrameForProcessing */ - FreeRTOS_FindEndPointOnMAC_ExpectAnyArgsAndReturn( pxEndPoint ); - /* Map the buffer onto Ethernet Header struct for easy access to fields. */ pxEthernetHeader = ( EthernetHeader_t * ) ucEthernetBuffer; @@ -1647,7 +1641,7 @@ void test_eConsiderFrameForProcessing_BroadCastMACMatch( void ) memset( ucEthernetBuffer, 0x00, ipconfigTCP_MSS ); memcpy( pxEthernetHeader->xDestinationAddress.ucBytes, xBroadcastMACAddress.ucBytes, sizeof( MACAddress_t ) ); - pxEthernetHeader->usFrameType = 0xFFFF; + pxEthernetHeader->usFrameType = ipIPv4_FRAME_TYPE; eResult = eConsiderFrameForProcessing( ucEthernetBuffer ); @@ -1674,7 +1668,88 @@ void test_eConsiderFrameForProcessing_LLMNR_MACMatch( void ) memset( ucEthernetBuffer, 0x00, ipconfigTCP_MSS ); memcpy( pxEthernetHeader->xDestinationAddress.ucBytes, xLLMNR_MacAddress.ucBytes, sizeof( MACAddress_t ) ); - pxEthernetHeader->usFrameType = 0xFFFF; + pxEthernetHeader->usFrameType = ipIPv4_FRAME_TYPE; + + eResult = eConsiderFrameForProcessing( ucEthernetBuffer ); + + TEST_ASSERT_EQUAL( eProcessBuffer, eResult ); +} + +/** + * @brief test_eConsiderFrameForProcessing_LLMNR_IPv6_MACMatch + * eConsiderFrameForProcessing must return eProcessBuffer when the MAC address in packet + * matches LLMNR MAC address and the frame type is valid. + */ +void test_eConsiderFrameForProcessing_LLMNR_IPv6_MACMatch( void ) +{ + eFrameProcessingResult_t eResult; + uint8_t ucEthernetBuffer[ ipconfigTCP_MSS ]; + EthernetHeader_t * pxEthernetHeader; + + /* eConsiderFrameForProcessing */ + FreeRTOS_FindEndPointOnMAC_ExpectAnyArgsAndReturn( NULL ); + + /* Map the buffer onto Ethernet Header struct for easy access to fields. */ + pxEthernetHeader = ( EthernetHeader_t * ) ucEthernetBuffer; + + memset( ucEthernetBuffer, 0x00, ipconfigTCP_MSS ); + + memcpy( pxEthernetHeader->xDestinationAddress.ucBytes, xLLMNR_MacAddressIPv6.ucBytes, sizeof( MACAddress_t ) ); + pxEthernetHeader->usFrameType = ipIPv6_FRAME_TYPE; + + eResult = eConsiderFrameForProcessing( ucEthernetBuffer ); + + TEST_ASSERT_EQUAL( eProcessBuffer, eResult ); +} + +/** + * @brief test_eConsiderFrameForProcessing_MDNS_MACMatch + * eConsiderFrameForProcessing must return eProcessBuffer when the MAC address in packet + * matches MDNS MAC address and the frame type is valid. + */ +void test_eConsiderFrameForProcessing_MDNS_MACMatch( void ) +{ + eFrameProcessingResult_t eResult; + uint8_t ucEthernetBuffer[ ipconfigTCP_MSS ]; + EthernetHeader_t * pxEthernetHeader; + + /* eConsiderFrameForProcessing */ + FreeRTOS_FindEndPointOnMAC_ExpectAnyArgsAndReturn( NULL ); + + /* Map the buffer onto Ethernet Header struct for easy access to fields. */ + pxEthernetHeader = ( EthernetHeader_t * ) ucEthernetBuffer; + + memset( ucEthernetBuffer, 0x00, ipconfigTCP_MSS ); + + memcpy( pxEthernetHeader->xDestinationAddress.ucBytes, xMDNS_MacAddress.ucBytes, sizeof( MACAddress_t ) ); + pxEthernetHeader->usFrameType = ipIPv4_FRAME_TYPE; + + eResult = eConsiderFrameForProcessing( ucEthernetBuffer ); + + TEST_ASSERT_EQUAL( eProcessBuffer, eResult ); +} + +/** + * @brief test_eConsiderFrameForProcessing_MDNS_IPv6_MACMatch + * eConsiderFrameForProcessing must return eProcessBuffer when the MAC address in packet + * matches LLMNR MAC address and the frame type is valid. + */ +void test_eConsiderFrameForProcessing_MDNS_IPv6_MACMatch( void ) +{ + eFrameProcessingResult_t eResult; + uint8_t ucEthernetBuffer[ ipconfigTCP_MSS ]; + EthernetHeader_t * pxEthernetHeader; + + /* eConsiderFrameForProcessing */ + FreeRTOS_FindEndPointOnMAC_ExpectAnyArgsAndReturn( NULL ); + + /* Map the buffer onto Ethernet Header struct for easy access to fields. */ + pxEthernetHeader = ( EthernetHeader_t * ) ucEthernetBuffer; + + memset( ucEthernetBuffer, 0x00, ipconfigTCP_MSS ); + + memcpy( pxEthernetHeader->xDestinationAddress.ucBytes, xMDNS_MacAddressIPv6.ucBytes, sizeof( MACAddress_t ) ); + pxEthernetHeader->usFrameType = ipIPv6_FRAME_TYPE; eResult = eConsiderFrameForProcessing( ucEthernetBuffer ); @@ -1702,7 +1777,7 @@ void test_eConsiderFrameForProcessing_NotMatch( void ) memset( ucEthernetBuffer, 0x00, ipconfigTCP_MSS ); memcpy( pxEthernetHeader->xDestinationAddress.ucBytes, &xMACAddress, sizeof( MACAddress_t ) ); - pxEthernetHeader->usFrameType = 0xFFFF; + pxEthernetHeader->usFrameType = ipIPv4_FRAME_TYPE; eResult = eConsiderFrameForProcessing( ucEthernetBuffer ); @@ -1710,11 +1785,127 @@ void test_eConsiderFrameForProcessing_NotMatch( void ) } /** - * @brief test_eConsiderFrameForProcessing_IPv6BroadCastMACMatch + * @brief test_eConsiderFrameForProcessing_Multicast_MACMatch * eConsiderFrameForProcessing must return eProcessBuffer when the MAC address in packet - * matches IPv6 broadcast MAC address and the frame type is valid. + * matches IPv6 Multicast MAC address and the frame type is valid. */ -void test_eConsiderFrameForProcessing_IPv6BroadCastMACMatch( void ) +void test_eConsiderFrameForProcessing_Multicast_MACMatch( void ) +{ + eFrameProcessingResult_t eResult; + uint8_t ucEthernetBuffer[ ipconfigTCP_MSS ]; + EthernetHeader_t * pxEthernetHeader; + + /* eConsiderFrameForProcessing */ + FreeRTOS_FindEndPointOnMAC_ExpectAnyArgsAndReturn( NULL ); + + /* Map the buffer onto Ethernet Header struct for easy access to fields. */ + pxEthernetHeader = ( EthernetHeader_t * ) ucEthernetBuffer; + + memset( ucEthernetBuffer, 0x00, ipconfigTCP_MSS ); + + pxEthernetHeader->xDestinationAddress.ucBytes[ 0 ] = ipMULTICAST_MAC_ADDRESS_IPv4_0; + pxEthernetHeader->xDestinationAddress.ucBytes[ 1 ] = ipMULTICAST_MAC_ADDRESS_IPv4_1; + pxEthernetHeader->xDestinationAddress.ucBytes[ 2 ] = ipMULTICAST_MAC_ADDRESS_IPv4_2; + pxEthernetHeader->usFrameType = ipIPv4_FRAME_TYPE; + + eResult = eConsiderFrameForProcessing( ucEthernetBuffer ); + + TEST_ASSERT_EQUAL( eProcessBuffer, eResult ); +} + +/** + * @brief test_eConsiderFrameForProcessing_Multicast_MACNotMatch1 + * eConsiderFrameForProcessing must return eReleaseBuffer when the MAC address in packet + * does not match IPv4 Multicast MAC address. + */ +void test_eConsiderFrameForProcessing_Multicast_MACNotMatch1( void ) +{ + eFrameProcessingResult_t eResult; + uint8_t ucEthernetBuffer[ ipconfigTCP_MSS ]; + EthernetHeader_t * pxEthernetHeader; + + /* eConsiderFrameForProcessing */ + FreeRTOS_FindEndPointOnMAC_ExpectAnyArgsAndReturn( NULL ); + + /* Map the buffer onto Ethernet Header struct for easy access to fields. */ + pxEthernetHeader = ( EthernetHeader_t * ) ucEthernetBuffer; + + memset( ucEthernetBuffer, 0x00, ipconfigTCP_MSS ); + + pxEthernetHeader->xDestinationAddress.ucBytes[ 0 ] = ipMULTICAST_MAC_ADDRESS_IPv4_0; + pxEthernetHeader->xDestinationAddress.ucBytes[ 1 ] = 0xFF; + pxEthernetHeader->usFrameType = ipIPv4_FRAME_TYPE; + + eResult = eConsiderFrameForProcessing( ucEthernetBuffer ); + + TEST_ASSERT_EQUAL( eReleaseBuffer, eResult ); +} + +/** + * @brief test_eConsiderFrameForProcessing_Multicast_MACNotMatch2 + * eConsiderFrameForProcessing must return eReleaseBuffer when the MAC address in packet + * does not match IPv4 Multicast MAC address. + */ +void test_eConsiderFrameForProcessing_Multicast_MACNotMatch2( void ) +{ + eFrameProcessingResult_t eResult; + uint8_t ucEthernetBuffer[ ipconfigTCP_MSS ]; + EthernetHeader_t * pxEthernetHeader; + + /* eConsiderFrameForProcessing */ + FreeRTOS_FindEndPointOnMAC_ExpectAnyArgsAndReturn( NULL ); + + /* Map the buffer onto Ethernet Header struct for easy access to fields. */ + pxEthernetHeader = ( EthernetHeader_t * ) ucEthernetBuffer; + + memset( ucEthernetBuffer, 0x00, ipconfigTCP_MSS ); + + pxEthernetHeader->xDestinationAddress.ucBytes[ 0 ] = ipMULTICAST_MAC_ADDRESS_IPv4_0; + pxEthernetHeader->xDestinationAddress.ucBytes[ 1 ] = ipMULTICAST_MAC_ADDRESS_IPv4_1; + pxEthernetHeader->xDestinationAddress.ucBytes[ 2 ] = 0xFF; + pxEthernetHeader->usFrameType = ipIPv4_FRAME_TYPE; + + eResult = eConsiderFrameForProcessing( ucEthernetBuffer ); + + TEST_ASSERT_EQUAL( eReleaseBuffer, eResult ); +} + +/** + * @brief test_eConsiderFrameForProcessing_Multicast_MACNotMatch3 + * eConsiderFrameForProcessing must return eReleaseBuffer when the MAC address in packet + * does not match IPv4 Multicast MAC address. + */ +void test_eConsiderFrameForProcessing_Multicast_MACNotMatch3( void ) +{ + eFrameProcessingResult_t eResult; + uint8_t ucEthernetBuffer[ ipconfigTCP_MSS ]; + EthernetHeader_t * pxEthernetHeader; + + /* eConsiderFrameForProcessing */ + FreeRTOS_FindEndPointOnMAC_ExpectAnyArgsAndReturn( NULL ); + + /* Map the buffer onto Ethernet Header struct for easy access to fields. */ + pxEthernetHeader = ( EthernetHeader_t * ) ucEthernetBuffer; + + memset( ucEthernetBuffer, 0x00, ipconfigTCP_MSS ); + + pxEthernetHeader->xDestinationAddress.ucBytes[ 0 ] = ipMULTICAST_MAC_ADDRESS_IPv4_0; + pxEthernetHeader->xDestinationAddress.ucBytes[ 1 ] = ipMULTICAST_MAC_ADDRESS_IPv4_1; + pxEthernetHeader->xDestinationAddress.ucBytes[ 2 ] = ipMULTICAST_MAC_ADDRESS_IPv4_2; + pxEthernetHeader->xDestinationAddress.ucBytes[ 3 ] = 0xFF; + pxEthernetHeader->usFrameType = ipIPv4_FRAME_TYPE; + + eResult = eConsiderFrameForProcessing( ucEthernetBuffer ); + + TEST_ASSERT_EQUAL( eReleaseBuffer, eResult ); +} + +/** + * @brief test_eConsiderFrameForProcessing_IPv6_Multicast_MACMatch + * eConsiderFrameForProcessing must return eProcessBuffer when the MAC address in packet + * matches IPv6 Multicast MAC address and the frame type is valid. + */ +void test_eConsiderFrameForProcessing_IPv6_Multicast_MACMatch( void ) { eFrameProcessingResult_t eResult; uint8_t ucEthernetBuffer[ ipconfigTCP_MSS ]; @@ -1730,7 +1921,7 @@ void test_eConsiderFrameForProcessing_IPv6BroadCastMACMatch( void ) pxEthernetHeader->xDestinationAddress.ucBytes[ 0 ] = ipMULTICAST_MAC_ADDRESS_IPv6_0; pxEthernetHeader->xDestinationAddress.ucBytes[ 1 ] = ipMULTICAST_MAC_ADDRESS_IPv6_1; - pxEthernetHeader->usFrameType = 0xFFFF; + pxEthernetHeader->usFrameType = ipIPv6_FRAME_TYPE; eResult = eConsiderFrameForProcessing( ucEthernetBuffer ); @@ -1758,6 +1949,56 @@ void test_eConsiderFrameForProcessing_IPv6BroadCastMACPartialMatch( void ) pxEthernetHeader->xDestinationAddress.ucBytes[ 0 ] = ipMULTICAST_MAC_ADDRESS_IPv6_0; pxEthernetHeader->xDestinationAddress.ucBytes[ 1 ] = 0x00; + pxEthernetHeader->usFrameType = ipIPv6_FRAME_TYPE; + + eResult = eConsiderFrameForProcessing( ucEthernetBuffer ); + + TEST_ASSERT_EQUAL( eReleaseBuffer, eResult ); +} + +/** + * @brief test_eConsiderFrameForProcessing_ArpBoardcastMacMatch + * eConsiderFrameForProcessing must return eProcessBuffer when the MAC address in packet + * matches broadcast MAC address and the frame type is ARP. + */ +void test_eConsiderFrameForProcessing_ArpBoardcastMacMatch( void ) +{ + eFrameProcessingResult_t eResult; + uint8_t ucEthernetBuffer[ ipconfigTCP_MSS ]; + EthernetHeader_t * pxEthernetHeader; + + /* eConsiderFrameForProcessing */ + FreeRTOS_FindEndPointOnMAC_ExpectAnyArgsAndReturn( NULL ); + + /* Map the buffer onto Ethernet Header struct for easy access to fields. */ + pxEthernetHeader = ( EthernetHeader_t * ) ucEthernetBuffer; + + memset( ucEthernetBuffer, 0x00, ipconfigTCP_MSS ); + + memcpy( pxEthernetHeader->xDestinationAddress.ucBytes, xBroadcastMACAddress.ucBytes, sizeof( MACAddress_t ) ); + pxEthernetHeader->usFrameType = ipARP_FRAME_TYPE; + + eResult = eConsiderFrameForProcessing( ucEthernetBuffer ); + + TEST_ASSERT_EQUAL( eProcessBuffer, eResult ); +} + +/** + * @brief test_eConsiderFrameForProcessing_UnknownFrameType + * eConsiderFrameForProcessing must return eReleaseBuffer when the frame type + * is unknown. + */ +void test_eConsiderFrameForProcessing_UnknownFrameType( void ) +{ + eFrameProcessingResult_t eResult; + uint8_t ucEthernetBuffer[ ipconfigTCP_MSS ]; + EthernetHeader_t * pxEthernetHeader; + + /* Map the buffer onto Ethernet Header struct for easy access to fields. */ + pxEthernetHeader = ( EthernetHeader_t * ) ucEthernetBuffer; + + memset( ucEthernetBuffer, 0x00, ipconfigTCP_MSS ); + pxEthernetHeader->usFrameType = 0xFFFF; eResult = eConsiderFrameForProcessing( ucEthernetBuffer ); @@ -1989,10 +2230,12 @@ void test_prvProcessEthernetPacket_ARPFrameType_eFrameConsumed( void ) uint8_t ucEtherBuffer[ ipconfigTCP_MSS ]; EthernetHeader_t * pxEthernetHeader; struct xNetworkInterface xInterface; + NetworkEndPoint_t xNetworkEndPoint = { 0 }; pxNetworkBuffer->xDataLength = ipconfigTCP_MSS; pxNetworkBuffer->pucEthernetBuffer = ucEtherBuffer; pxNetworkBuffer->pxInterface = &xInterface; + pxNetworkBuffer->pxEndPoint = &xNetworkEndPoint; pxEthernetHeader = ( EthernetHeader_t * ) pxNetworkBuffer->pucEthernetBuffer; @@ -2017,10 +2260,12 @@ void test_prvProcessEthernetPacket_ARPFrameType_SmallerDataLength( void ) uint8_t ucEtherBuffer[ ipconfigTCP_MSS ]; EthernetHeader_t * pxEthernetHeader; struct xNetworkInterface xInterface; + NetworkEndPoint_t xNetworkEndPoint = { 0 }; pxNetworkBuffer->xDataLength = sizeof( EthernetHeader_t ); pxNetworkBuffer->pucEthernetBuffer = ucEtherBuffer; pxNetworkBuffer->pxInterface = &xInterface; + pxNetworkBuffer->pxEndPoint = &xNetworkEndPoint; pxEthernetHeader = ( EthernetHeader_t * ) pxNetworkBuffer->pucEthernetBuffer; @@ -2045,10 +2290,12 @@ void test_prvProcessEthernetPacket_IPv4FrameType_LessData( void ) uint8_t ucEtherBuffer[ ipconfigTCP_MSS ]; EthernetHeader_t * pxEthernetHeader; struct xNetworkInterface xInterface; + NetworkEndPoint_t xNetworkEndPoint = { 0 }; pxNetworkBuffer->xDataLength = sizeof( EthernetHeader_t ); pxNetworkBuffer->pucEthernetBuffer = ucEtherBuffer; pxNetworkBuffer->pxInterface = &xInterface; + pxNetworkBuffer->pxEndPoint = &xNetworkEndPoint; pxEthernetHeader = ( EthernetHeader_t * ) pxNetworkBuffer->pucEthernetBuffer; @@ -2070,17 +2317,17 @@ void test_prvProcessEthernetPacket_IPv4FrameType_AptData( void ) { NetworkBufferDescriptor_t xNetworkBuffer; NetworkBufferDescriptor_t * pxNetworkBuffer = &xNetworkBuffer; - uint8_t ucEtherBuffer[ ipconfigTCP_MSS ]; + uint8_t ucEthernetBuffer[ ipconfigTCP_MSS ] = { 0 }; EthernetHeader_t * pxEthernetHeader; IPPacket_t * pxIPPacket; IPHeader_t * pxIPHeader; struct xNetworkInterface xInterface; - - memset( pxNetworkBuffer->pucEthernetBuffer, 0, ipconfigTCP_MSS ); + NetworkEndPoint_t xNetworkEndPoint = { 0 }; pxNetworkBuffer->xDataLength = ipconfigTCP_MSS; - pxNetworkBuffer->pucEthernetBuffer = ucEtherBuffer; + pxNetworkBuffer->pucEthernetBuffer = ucEthernetBuffer; pxNetworkBuffer->pxInterface = &xInterface; + pxNetworkBuffer->pxEndPoint = &xNetworkEndPoint; pxEthernetHeader = ( EthernetHeader_t * ) pxNetworkBuffer->pucEthernetBuffer; pxEthernetHeader->usFrameType = ipIPv4_FRAME_TYPE; @@ -2103,16 +2350,14 @@ void test_prvProcessEthernetPacket_InterfaceNull( void ) { NetworkBufferDescriptor_t xNetworkBuffer; NetworkBufferDescriptor_t * pxNetworkBuffer = &xNetworkBuffer; - uint8_t ucEtherBuffer[ ipconfigTCP_MSS ]; + uint8_t ucEthernetBuffer[ ipconfigTCP_MSS ] = { 0 }; EthernetHeader_t * pxEthernetHeader; IPPacket_t * pxIPPacket; IPHeader_t * pxIPHeader; struct xNetworkInterface xInterface; - memset( pxNetworkBuffer->pucEthernetBuffer, 0, ipconfigTCP_MSS ); - pxNetworkBuffer->xDataLength = ipconfigTCP_MSS; - pxNetworkBuffer->pucEthernetBuffer = ucEtherBuffer; + pxNetworkBuffer->pucEthernetBuffer = ucEthernetBuffer; pxNetworkBuffer->pxInterface = NULL; vReleaseNetworkBufferAndDescriptor_Expect( pxNetworkBuffer ); @@ -2221,15 +2466,13 @@ void test_prvProcessIPPacket_ValidHeader_ARPResolutionReqd( void ) eFrameProcessingResult_t eResult; IPPacket_t * pxIPPacket; NetworkBufferDescriptor_t * pxNetworkBuffer, xNetworkBuffer; - uint8_t ucEthBuffer[ ipconfigTCP_MSS ]; + uint8_t ucEthBuffer[ ipIP_TYPE_OFFSET + ipconfigTCP_MSS ] = { 0 }; IPHeader_t * pxIPHeader; struct xNetworkInterface xInterface; - memset( ucEthBuffer, 0, ipconfigTCP_MSS ); - /* Initialize network buffer descriptor. */ pxNetworkBuffer = &xNetworkBuffer; - pxNetworkBuffer->pucEthernetBuffer = ucEthBuffer; + pxNetworkBuffer->pucEthernetBuffer = ucEthBuffer + ipIP_TYPE_OFFSET; pxNetworkBuffer->pxInterface = &xInterface; /* Initialize ethernet layer. */ @@ -2258,15 +2501,13 @@ void test_prvProcessIPPacket_ARPResolutionNotReqd_InvalidProt( void ) eFrameProcessingResult_t eResult; IPPacket_t * pxIPPacket; NetworkBufferDescriptor_t * pxNetworkBuffer, xNetworkBuffer; - uint8_t ucEthBuffer[ ipconfigTCP_MSS ]; + uint8_t ucEthBuffer[ ipIP_TYPE_OFFSET + ipconfigTCP_MSS ] = { 0 }; IPHeader_t * pxIPHeader; struct xNetworkInterface xInterface; - memset( ucEthBuffer, 0, ipconfigTCP_MSS ); - /* Initialize network buffer descriptor. */ pxNetworkBuffer = &xNetworkBuffer; - pxNetworkBuffer->pucEthernetBuffer = ucEthBuffer; + pxNetworkBuffer->pucEthernetBuffer = ucEthBuffer + ipIP_TYPE_OFFSET; pxNetworkBuffer->xDataLength = ipconfigTCP_MSS; /* Initialize ethernet layer. */ @@ -2299,15 +2540,13 @@ void test_prvProcessIPPacket_ARPResolutionNotReqd_ICMPRelease( void ) eFrameProcessingResult_t eResult; IPPacket_t * pxIPPacket; NetworkBufferDescriptor_t * pxNetworkBuffer, xNetworkBuffer; - uint8_t ucEthBuffer[ ipconfigTCP_MSS ]; + uint8_t ucEthBuffer[ ipIP_TYPE_OFFSET + ipconfigTCP_MSS ] = { 0 }; IPHeader_t * pxIPHeader; struct xNetworkInterface xInterface; - memset( ucEthBuffer, 0, ipconfigTCP_MSS ); - /* Initialize network buffer descriptor. */ pxNetworkBuffer = &xNetworkBuffer; - pxNetworkBuffer->pucEthernetBuffer = ucEthBuffer; + pxNetworkBuffer->pucEthernetBuffer = ucEthBuffer + ipIP_TYPE_OFFSET; pxNetworkBuffer->xDataLength = ipconfigTCP_MSS; pxNetworkBuffer->pxInterface = &xInterface; @@ -2341,15 +2580,13 @@ void test_prvProcessIPPacket_ARPResolutionNotReqd_ICMPProcess( void ) eFrameProcessingResult_t eResult; IPPacket_t * pxIPPacket; NetworkBufferDescriptor_t * pxNetworkBuffer, xNetworkBuffer; - uint8_t ucEthBuffer[ ipconfigTCP_MSS ]; + uint8_t ucEthBuffer[ ipIP_TYPE_OFFSET + ipconfigTCP_MSS ] = { 0 }; IPHeader_t * pxIPHeader; struct xNetworkInterface xInterface; - memset( ucEthBuffer, 0, ipconfigTCP_MSS ); - /* Initialize network buffer descriptor. */ pxNetworkBuffer = &xNetworkBuffer; - pxNetworkBuffer->pucEthernetBuffer = ucEthBuffer; + pxNetworkBuffer->pucEthernetBuffer = ucEthBuffer + ipIP_TYPE_OFFSET; pxNetworkBuffer->xDataLength = ipconfigTCP_MSS; pxNetworkBuffer->pxInterface = &xInterface; @@ -2383,16 +2620,14 @@ void test_prvProcessIPPacket_ARPResolutionNotReqd_UDPZeroLength( void ) eFrameProcessingResult_t eResult; IPPacket_t * pxIPPacket; NetworkBufferDescriptor_t * pxNetworkBuffer, xNetworkBuffer; - uint8_t ucEthBuffer[ ipconfigTCP_MSS ]; + uint8_t ucEthBuffer[ ipIP_TYPE_OFFSET + ipconfigTCP_MSS ] = { 0 }; IPHeader_t * pxIPHeader; UDPPacket_t * pxUDPPacket; struct xNetworkInterface xInterface; - memset( ucEthBuffer, 0, ipconfigTCP_MSS ); - /* Initialize network buffer descriptor. */ pxNetworkBuffer = &xNetworkBuffer; - pxNetworkBuffer->pucEthernetBuffer = ucEthBuffer; + pxNetworkBuffer->pucEthernetBuffer = ucEthBuffer + ipIP_TYPE_OFFSET; pxNetworkBuffer->xDataLength = ipconfigTCP_MSS; pxNetworkBuffer->pxInterface = &xInterface; @@ -2428,16 +2663,14 @@ void test_prvProcessIPPacket_ARPResolutionNotReqd_UDPLengthGreaterThanIPHeader( eFrameProcessingResult_t eResult; IPPacket_t * pxIPPacket; NetworkBufferDescriptor_t * pxNetworkBuffer, xNetworkBuffer; - uint8_t ucEthBuffer[ ipconfigTCP_MSS ]; + uint8_t ucEthBuffer[ ipIP_TYPE_OFFSET + ipconfigTCP_MSS ] = { 0 }; IPHeader_t * pxIPHeader; UDPPacket_t * pxUDPPacket; struct xNetworkInterface xInterface; - memset( ucEthBuffer, 0, ipconfigTCP_MSS ); - /* Initialize network buffer descriptor. */ pxNetworkBuffer = &xNetworkBuffer; - pxNetworkBuffer->pucEthernetBuffer = ucEthBuffer; + pxNetworkBuffer->pucEthernetBuffer = ucEthBuffer + ipIP_TYPE_OFFSET; pxNetworkBuffer->xDataLength = ipconfigTCP_MSS; pxNetworkBuffer->pxInterface = &xInterface; @@ -2473,16 +2706,14 @@ void test_prvProcessIPPacket_ARPResolutionNotReqd_UDPHappyPath( void ) eFrameProcessingResult_t eResult; IPPacket_t * pxIPPacket; NetworkBufferDescriptor_t * pxNetworkBuffer, xNetworkBuffer; - uint8_t ucEthBuffer[ ipconfigTCP_MSS ]; + uint8_t ucEthBuffer[ ipIP_TYPE_OFFSET + ipconfigTCP_MSS ] = { 0 }; IPHeader_t * pxIPHeader; struct xNetworkInterface xInterface; UDPPacket_t * pxUDPPacket; - memset( ucEthBuffer, 0, ipconfigTCP_MSS ); - /* Initialize network buffer descriptor. */ pxNetworkBuffer = &xNetworkBuffer; - pxNetworkBuffer->pucEthernetBuffer = ucEthBuffer; + pxNetworkBuffer->pucEthernetBuffer = ucEthBuffer + ipIP_TYPE_OFFSET; pxNetworkBuffer->xDataLength = ipconfigTCP_MSS; pxNetworkBuffer->pxInterface = &xInterface; @@ -2518,16 +2749,14 @@ void test_prvProcessIPPacket_ARPResolutionNotReqd_UDPProcessFail( void ) eFrameProcessingResult_t eResult; IPPacket_t * pxIPPacket; NetworkBufferDescriptor_t * pxNetworkBuffer, xNetworkBuffer; - uint8_t ucEthBuffer[ ipconfigTCP_MSS ]; + uint8_t ucEthBuffer[ ipIP_TYPE_OFFSET + ipconfigTCP_MSS ] = { 0 }; IPHeader_t * pxIPHeader; UDPPacket_t * pxUDPPacket; struct xNetworkInterface xInterface; - memset( ucEthBuffer, 0, ipconfigTCP_MSS ); - /* Initialize network buffer descriptor. */ pxNetworkBuffer = &xNetworkBuffer; - pxNetworkBuffer->pucEthernetBuffer = ucEthBuffer; + pxNetworkBuffer->pucEthernetBuffer = ucEthBuffer + ipIP_TYPE_OFFSET; pxNetworkBuffer->xDataLength = ipconfigTCP_MSS; pxNetworkBuffer->pxInterface = &xInterface; @@ -2566,17 +2795,15 @@ void test_prvProcessIPPacket_ARPResolutionReqd_UDP( void ) IPPacket_t * pxIPPacket; NetworkBufferDescriptor_t * pxNetworkBuffer, xNetworkBuffer; UBaseType_t uxHeaderLength = 0; - uint8_t ucEthBuffer[ ipconfigTCP_MSS ]; + uint8_t ucEthBuffer[ ipIP_TYPE_OFFSET + ipconfigTCP_MSS ] = { 0 }; IPHeader_t * pxIPHeader; UDPPacket_t * pxUDPPacket; BaseType_t xReturnValue = pdTRUE; struct xNetworkInterface xInterface; - memset( ucEthBuffer, 0, ipconfigTCP_MSS ); - /* Initialize network buffer descriptor. */ pxNetworkBuffer = &xNetworkBuffer; - pxNetworkBuffer->pucEthernetBuffer = ucEthBuffer; + pxNetworkBuffer->pucEthernetBuffer = ucEthBuffer + ipIP_TYPE_OFFSET; pxNetworkBuffer->xDataLength = ipconfigTCP_MSS; pxNetworkBuffer->pxInterface = &xInterface; @@ -2619,17 +2846,15 @@ void test_prvProcessIPPacket_ARPResolutionReqd_UDP1( void ) eFrameProcessingResult_t eResult; IPPacket_t * pxIPPacket; NetworkBufferDescriptor_t * pxNetworkBuffer, xNetworkBuffer; - uint8_t ucEthBuffer[ ipconfigTCP_MSS ]; + uint8_t ucEthBuffer[ ipIP_TYPE_OFFSET + ipconfigTCP_MSS ] = { 0 }; IPHeader_t * pxIPHeader; UDPPacket_t * pxUDPPacket; BaseType_t xReturnValue = pdTRUE; struct xNetworkInterface xInterface; - memset( ucEthBuffer, 0, ipconfigTCP_MSS ); - /* Initialize network buffer descriptor. */ pxNetworkBuffer = &xNetworkBuffer; - pxNetworkBuffer->pucEthernetBuffer = ucEthBuffer; + pxNetworkBuffer->pucEthernetBuffer = ucEthBuffer + ipIP_TYPE_OFFSET; pxNetworkBuffer->xDataLength = sizeof( UDPPacket_t ); pxNetworkBuffer->pxInterface = &xInterface; @@ -2670,16 +2895,15 @@ void test_prvProcessIPPacket_TCP( void ) eFrameProcessingResult_t eResult; IPPacket_t * pxIPPacket; NetworkBufferDescriptor_t * pxNetworkBuffer, xNetworkBuffer; - uint8_t ucEthBuffer[ ipconfigTCP_MSS ]; + uint8_t ucEthBuffer[ ipIP_TYPE_OFFSET + ipconfigTCP_MSS ] = { 0 }; IPHeader_t * pxIPHeader; BaseType_t xReturnValue = pdTRUE; struct xNetworkInterface xInterface; - memset( ucEthBuffer, 0, ipconfigTCP_MSS ); /* Initialize network buffer descriptor. */ pxNetworkBuffer = &xNetworkBuffer; - pxNetworkBuffer->pucEthernetBuffer = ucEthBuffer; + pxNetworkBuffer->pucEthernetBuffer = ucEthBuffer + ipIP_TYPE_OFFSET; pxNetworkBuffer->xDataLength = sizeof( UDPPacket_t ); pxNetworkBuffer->pxInterface = &xInterface; @@ -2714,17 +2938,15 @@ void test_prvProcessIPPacket_TCPProcessFail( void ) eFrameProcessingResult_t eResult; IPPacket_t * pxIPPacket; NetworkBufferDescriptor_t * pxNetworkBuffer, xNetworkBuffer; - uint8_t ucEthBuffer[ ipconfigTCP_MSS ]; + uint8_t ucEthBuffer[ ipIP_TYPE_OFFSET + ipconfigTCP_MSS ] = { 0 }; IPHeader_t * pxIPHeader; BaseType_t xReturnValue = pdTRUE; NetworkEndPoint_t xEndPoint = { 0 }; struct xNetworkInterface xInterface; - memset( ucEthBuffer, 0, ipconfigTCP_MSS ); - /* Initialize network buffer descriptor. */ pxNetworkBuffer = &xNetworkBuffer; - pxNetworkBuffer->pucEthernetBuffer = ucEthBuffer; + pxNetworkBuffer->pucEthernetBuffer = ucEthBuffer + ipIP_TYPE_OFFSET; pxNetworkBuffer->xDataLength = sizeof( UDPPacket_t ); pxNetworkBuffer->pxInterface = &xInterface; @@ -2759,15 +2981,13 @@ void test_prvProcessIPPacket_UDP_ExternalLoopback( void ) eFrameProcessingResult_t eResult; IPPacket_t * pxIPPacket; NetworkBufferDescriptor_t * pxNetworkBuffer, xNetworkBuffer; - uint8_t ucEthBuffer[ ipconfigTCP_MSS ]; + uint8_t ucEthBuffer[ ipIP_TYPE_OFFSET + ipconfigTCP_MSS ] = { 0 }; IPHeader_t * pxIPHeader; struct xNetworkInterface xInterface; - memset( ucEthBuffer, 0, ipconfigTCP_MSS ); - /* Initialize network buffer descriptor. */ pxNetworkBuffer = &xNetworkBuffer; - pxNetworkBuffer->pucEthernetBuffer = ucEthBuffer; + pxNetworkBuffer->pucEthernetBuffer = ucEthBuffer + ipIP_TYPE_OFFSET; pxNetworkBuffer->xDataLength = ipconfigTCP_MSS; pxNetworkBuffer->pxInterface = &xInterface; @@ -2799,15 +3019,13 @@ void test_prvProcessIPPacket_UDP_GreaterLoopbackAddress( void ) eFrameProcessingResult_t eResult; IPPacket_t * pxIPPacket; NetworkBufferDescriptor_t * pxNetworkBuffer, xNetworkBuffer; - uint8_t ucEthBuffer[ ipconfigTCP_MSS ]; + uint8_t ucEthBuffer[ ipIP_TYPE_OFFSET + ipconfigTCP_MSS ] = { 0 }; IPHeader_t * pxIPHeader; struct xNetworkInterface xInterface; - memset( ucEthBuffer, 0, ipconfigTCP_MSS ); - /* Initialize network buffer descriptor. */ pxNetworkBuffer = &xNetworkBuffer; - pxNetworkBuffer->pucEthernetBuffer = ucEthBuffer; + pxNetworkBuffer->pucEthernetBuffer = ucEthBuffer + ipIP_TYPE_OFFSET; pxNetworkBuffer->xDataLength = 0; pxNetworkBuffer->pxInterface = &xInterface; @@ -2839,15 +3057,13 @@ void test_prvProcessIPPacket_UDP_LessLoopbackAddress( void ) eFrameProcessingResult_t eResult; IPPacket_t * pxIPPacket; NetworkBufferDescriptor_t * pxNetworkBuffer, xNetworkBuffer; - uint8_t ucEthBuffer[ ipconfigTCP_MSS ]; + uint8_t ucEthBuffer[ ipIP_TYPE_OFFSET + ipconfigTCP_MSS ] = { 0 }; IPHeader_t * pxIPHeader; struct xNetworkInterface xInterface; - memset( ucEthBuffer, 0, ipconfigTCP_MSS ); - /* Initialize network buffer descriptor. */ pxNetworkBuffer = &xNetworkBuffer; - pxNetworkBuffer->pucEthernetBuffer = ucEthBuffer; + pxNetworkBuffer->pucEthernetBuffer = ucEthBuffer + ipIP_TYPE_OFFSET; pxNetworkBuffer->xDataLength = 0; pxNetworkBuffer->pxInterface = &xInterface; @@ -2879,15 +3095,13 @@ void test_prvProcessIPPacket_UDP_IPHeaderLengthTooLarge( void ) eFrameProcessingResult_t eResult; IPPacket_t * pxIPPacket; NetworkBufferDescriptor_t * pxNetworkBuffer, xNetworkBuffer; - uint8_t ucEthBuffer[ ipconfigTCP_MSS ]; + uint8_t ucEthBuffer[ ipIP_TYPE_OFFSET + ipconfigTCP_MSS ] = { 0 }; IPHeader_t * pxIPHeader; struct xNetworkInterface xInterface; - memset( ucEthBuffer, 0, ipconfigTCP_MSS ); - /* Initialize network buffer descriptor. */ pxNetworkBuffer = &xNetworkBuffer; - pxNetworkBuffer->pucEthernetBuffer = ucEthBuffer; + pxNetworkBuffer->pucEthernetBuffer = ucEthBuffer + ipIP_TYPE_OFFSET; pxNetworkBuffer->xDataLength = ipSIZE_OF_ETH_HEADER + ipSIZE_OF_IPv4_HEADER; pxNetworkBuffer->pxInterface = &xInterface; @@ -2915,17 +3129,15 @@ void test_prvProcessIPPacket_UDP_IPv6_HappyPath( void ) eFrameProcessingResult_t eResult; IPPacket_IPv6_t * pxIPPacket; NetworkBufferDescriptor_t * pxNetworkBuffer, xNetworkBuffer; - uint8_t ucEthBuffer[ ipconfigTCP_MSS ]; + uint8_t ucEthBuffer[ ipIP_TYPE_OFFSET + ipconfigTCP_MSS ] = { 0 }; IPHeader_IPv6_t * pxIPHeader; UDPPacket_IPv6_t * pxUDPPacket; BaseType_t xReturnValue = pdTRUE; struct xNetworkInterface xInterface; - memset( ucEthBuffer, 0, ipconfigTCP_MSS ); - /* Initialize network buffer descriptor. */ pxNetworkBuffer = &xNetworkBuffer; - pxNetworkBuffer->pucEthernetBuffer = ucEthBuffer; + pxNetworkBuffer->pucEthernetBuffer = ucEthBuffer + ipIP_TYPE_OFFSET; pxNetworkBuffer->xDataLength = ipconfigTCP_MSS; pxNetworkBuffer->pxInterface = &xInterface; @@ -2962,17 +3174,15 @@ void test_prvProcessIPPacket_UDP_IPv6_ExtensionHappyPath( void ) eFrameProcessingResult_t eResult; IPPacket_IPv6_t * pxIPPacket; NetworkBufferDescriptor_t * pxNetworkBuffer, xNetworkBuffer; - uint8_t ucEthBuffer[ ipconfigTCP_MSS ]; + uint8_t ucEthBuffer[ ipIP_TYPE_OFFSET + ipconfigTCP_MSS ] = { 0 }; IPHeader_IPv6_t * pxIPHeader; UDPPacket_IPv6_t * pxUDPPacket; BaseType_t xReturnValue = pdTRUE; struct xNetworkInterface xInterface; - memset( ucEthBuffer, 0, ipconfigTCP_MSS ); - /* Initialize network buffer descriptor. */ pxNetworkBuffer = &xNetworkBuffer; - pxNetworkBuffer->pucEthernetBuffer = ucEthBuffer; + pxNetworkBuffer->pucEthernetBuffer = ucEthBuffer + ipIP_TYPE_OFFSET; pxNetworkBuffer->xDataLength = ipconfigTCP_MSS; pxNetworkBuffer->pxInterface = &xInterface; @@ -3017,16 +3227,14 @@ void test_prvProcessIPPacket_UDP_IPv6_ExtensionHandleFail( void ) IPPacket_IPv6_t * pxIPPacket; NetworkBufferDescriptor_t * pxNetworkBuffer, xNetworkBuffer; UBaseType_t uxHeaderLength = 0; - uint8_t ucEthBuffer[ ipconfigTCP_MSS ]; + uint8_t ucEthBuffer[ ipIP_TYPE_OFFSET + ipconfigTCP_MSS ] = { 0 }; IPHeader_IPv6_t * pxIPHeader; UDPPacket_IPv6_t * pxUDPPacket; BaseType_t xReturnValue = pdTRUE; struct xNetworkInterface xInterface; - memset( ucEthBuffer, 0, ipconfigTCP_MSS ); - pxNetworkBuffer = &xNetworkBuffer; - pxNetworkBuffer->pucEthernetBuffer = ucEthBuffer; + pxNetworkBuffer->pucEthernetBuffer = ucEthBuffer + ipIP_TYPE_OFFSET; pxNetworkBuffer->xDataLength = ipconfigTCP_MSS; pxNetworkBuffer->pxInterface = &xInterface; @@ -3068,16 +3276,14 @@ void test_prvProcessIPPacket_TCP_IPv6_HappyPath( void ) IPPacket_IPv6_t * pxIPPacket; NetworkBufferDescriptor_t * pxNetworkBuffer, xNetworkBuffer; UBaseType_t uxHeaderLength = 0; - uint8_t ucEthBuffer[ ipconfigTCP_MSS ]; + uint8_t ucEthBuffer[ ipIP_TYPE_OFFSET + ipconfigTCP_MSS ] = { 0 }; IPHeader_IPv6_t * pxIPHeader; TCPPacket_IPv6_t * pxTCPPacket; BaseType_t xReturnValue = pdTRUE; struct xNetworkInterface xInterface; - memset( ucEthBuffer, 0, ipconfigTCP_MSS ); - pxNetworkBuffer = &xNetworkBuffer; - pxNetworkBuffer->pucEthernetBuffer = ucEthBuffer; + pxNetworkBuffer->pucEthernetBuffer = ucEthBuffer + ipIP_TYPE_OFFSET; pxNetworkBuffer->xDataLength = ipconfigTCP_MSS; pxNetworkBuffer->pxInterface = &xInterface; @@ -3120,16 +3326,14 @@ void test_prvProcessIPPacket_TCP_IPv6_ARPResolution( void ) IPPacket_IPv6_t * pxIPPacket; NetworkBufferDescriptor_t * pxNetworkBuffer, xNetworkBuffer; UBaseType_t uxHeaderLength = 0; - uint8_t ucEthBuffer[ ipconfigTCP_MSS ]; + uint8_t ucEthBuffer[ ipIP_TYPE_OFFSET + ipconfigTCP_MSS ] = { 0 }; IPHeader_IPv6_t * pxIPHeader; TCPPacket_IPv6_t * pxTCPPacket; BaseType_t xReturnValue = pdTRUE; struct xNetworkInterface xInterface; - memset( ucEthBuffer, 0, ipconfigTCP_MSS ); - pxNetworkBuffer = &xNetworkBuffer; - pxNetworkBuffer->pucEthernetBuffer = ucEthBuffer; + pxNetworkBuffer->pucEthernetBuffer = ucEthBuffer + ipIP_TYPE_OFFSET; pxNetworkBuffer->xDataLength = ipconfigTCP_MSS; pxNetworkBuffer->pxInterface = &xInterface; @@ -3169,16 +3373,14 @@ void test_prvProcessIPPacket_ICMP_IPv6_HappyPath( void ) IPPacket_IPv6_t * pxIPPacket; NetworkBufferDescriptor_t * pxNetworkBuffer, xNetworkBuffer; UBaseType_t uxHeaderLength = 0; - uint8_t ucEthBuffer[ ipconfigTCP_MSS ]; + uint8_t ucEthBuffer[ ipIP_TYPE_OFFSET + ipconfigTCP_MSS ] = { 0 }; IPHeader_IPv6_t * pxIPHeader; ICMPPacket_IPv6_t * pxICMPPacket; BaseType_t xReturnValue = pdTRUE; struct xNetworkInterface xInterface; - memset( ucEthBuffer, 0, ipconfigTCP_MSS ); - pxNetworkBuffer = &xNetworkBuffer; - pxNetworkBuffer->pucEthernetBuffer = ucEthBuffer; + pxNetworkBuffer->pucEthernetBuffer = ucEthBuffer + ipIP_TYPE_OFFSET; pxNetworkBuffer->xDataLength = ipconfigTCP_MSS; pxNetworkBuffer->pxInterface = &xInterface; @@ -3220,15 +3422,13 @@ void test_prvProcessIPPacket_IPv6_LessPacketSize( void ) IPPacket_IPv6_t * pxIPPacket; NetworkBufferDescriptor_t * pxNetworkBuffer, xNetworkBuffer; UBaseType_t uxHeaderLength = 0; - uint8_t ucEthBuffer[ ipconfigTCP_MSS ]; + uint8_t ucEthBuffer[ ipIP_TYPE_OFFSET + ipconfigTCP_MSS ] = { 0 }; IPHeader_IPv6_t * pxIPHeader; struct xNetworkInterface xInterface; BaseType_t xReturnValue = pdTRUE; - memset( ucEthBuffer, 0, ipconfigTCP_MSS ); - pxNetworkBuffer = &xNetworkBuffer; - pxNetworkBuffer->pucEthernetBuffer = ucEthBuffer; + pxNetworkBuffer->pucEthernetBuffer = ucEthBuffer + ipIP_TYPE_OFFSET; pxNetworkBuffer->xDataLength = sizeof( IPPacket_IPv6_t ) - 1; pxNetworkBuffer->pxInterface = &xInterface; diff --git a/test/unit-test/FreeRTOS_IP_DiffConfig/FreeRTOS_IP_DiffConfig_stubs.c b/test/unit-test/FreeRTOS_IP_DiffConfig/FreeRTOS_IP_DiffConfig_stubs.c index 3b13966be3..9a9ea5162b 100644 --- a/test/unit-test/FreeRTOS_IP_DiffConfig/FreeRTOS_IP_DiffConfig_stubs.c +++ b/test/unit-test/FreeRTOS_IP_DiffConfig/FreeRTOS_IP_DiffConfig_stubs.c @@ -50,9 +50,15 @@ struct xNetworkInterface * pxNetworkInterfaces = NULL; /** @brief A list of all network end-points. Each element has a next pointer. */ struct xNetworkEndPoint * pxNetworkEndPoints = NULL; +const MACAddress_t xDefault_MacAddress = { { 0x11, 0x22, 0x33, 0x44, 0x55, 0x66 } }; + const MACAddress_t xLLMNR_MacAddress = { { 0x01, 0x00, 0x5e, 0x00, 0x00, 0xfc } }; -const MACAddress_t xDefault_MacAddress = { { 0x11, 0x22, 0x33, 0x44, 0x55, 0x66 } }; +const MACAddress_t xLLMNR_MacAddressIPv6 = { { 0x33, 0x33, 0x00, 0x01, 0x00, 0x03 } }; + +const MACAddress_t xMDNS_MacAddress = { { 0x01, 0x00, 0x5e, 0x00, 0x00, 0xfb } }; + +const MACAddress_t xMDNS_MacAddressIPv6 = { { 0x33, 0x33, 0x00, 0x00, 0x00, 0xFB } }; void vPortEnterCritical( void ) { diff --git a/test/unit-test/FreeRTOS_IP_DiffConfig1/FreeRTOS_IP_DiffConfig1_stubs.c b/test/unit-test/FreeRTOS_IP_DiffConfig1/FreeRTOS_IP_DiffConfig1_stubs.c index 5968e321ca..2d454be482 100644 --- a/test/unit-test/FreeRTOS_IP_DiffConfig1/FreeRTOS_IP_DiffConfig1_stubs.c +++ b/test/unit-test/FreeRTOS_IP_DiffConfig1/FreeRTOS_IP_DiffConfig1_stubs.c @@ -51,9 +51,15 @@ struct xNetworkInterface * pxNetworkInterfaces = NULL; /** @brief A list of all network end-points. Each element has a next pointer. */ struct xNetworkEndPoint * pxNetworkEndPoints = NULL; +const MACAddress_t xDefault_MacAddress = { { 0x11, 0x22, 0x33, 0x44, 0x55, 0x66 } }; + const MACAddress_t xLLMNR_MacAddress = { { 0x01, 0x00, 0x5e, 0x00, 0x00, 0xfc } }; -const MACAddress_t xDefault_MacAddress = { { 0x11, 0x22, 0x33, 0x44, 0x55, 0x66 } }; +const MACAddress_t xLLMNR_MacAddressIPv6 = { { 0x33, 0x33, 0x00, 0x01, 0x00, 0x03 } }; + +const MACAddress_t xMDNS_MacAddress = { { 0x01, 0x00, 0x5e, 0x00, 0x00, 0xfb } }; + +const MACAddress_t xMDNS_MacAddressIPv6 = { { 0x33, 0x33, 0x00, 0x00, 0x00, 0xFB } }; void vPortEnterCritical( void ) { diff --git a/test/unit-test/FreeRTOS_IP_DiffConfig1/FreeRTOS_IP_DiffConfig1_utest.c b/test/unit-test/FreeRTOS_IP_DiffConfig1/FreeRTOS_IP_DiffConfig1_utest.c index f420447d65..3a1652158a 100644 --- a/test/unit-test/FreeRTOS_IP_DiffConfig1/FreeRTOS_IP_DiffConfig1_utest.c +++ b/test/unit-test/FreeRTOS_IP_DiffConfig1/FreeRTOS_IP_DiffConfig1_utest.c @@ -441,7 +441,7 @@ void test_FreeRTOS_GetUDPPayloadBuffer_BlockTimeEqualToConfigBackwardCompatible( uint8_t pucEthernetBuffer[ 1500 ]; /* Put the ethernet buffer in place. */ - pxNetworkBuffer->pucEthernetBuffer = pucEthernetBuffer; + pxNetworkBuffer->pucEthernetBuffer = pucEthernetBuffer + ipIP_TYPE_OFFSET; pxNetworkBuffer->xDataLength = 0; pxGetNetworkBufferWithDescriptor_ExpectAndReturn( sizeof( UDPPacket_t ) + uxRequestedSizeBytes, uxBlockTimeTicks, pxNetworkBuffer ); @@ -786,3 +786,26 @@ void test_FreeRTOS_GetUDPPayloadBuffer_BlockTimeEqualToConfig_IPv6NotSupported( TEST_ASSERT_EQUAL_PTR( NULL, pvReturn ); } + +/** + * @brief test_eConsiderFrameForProcessing_IPv6_FrameType_But_Disabled + * eConsiderFrameForProcessing must return eReleaseBuffer when the frame type is IPv6 but + * ipconfigUSE_IPv6 is disabled. + */ +void test_eConsiderFrameForProcessing_IPv6_FrameType_But_Disabled( void ) +{ + eFrameProcessingResult_t eResult; + uint8_t ucEthernetBuffer[ ipconfigNETWORK_MTU ]; + EthernetHeader_t * pxEthernetHeader; + + /* Map the buffer onto Ethernet Header struct for easy access to fields. */ + pxEthernetHeader = ( EthernetHeader_t * ) ucEthernetBuffer; + + memset( ucEthernetBuffer, 0x00, ipconfigNETWORK_MTU ); + + pxEthernetHeader->usFrameType = ipIPv6_FRAME_TYPE; + + eResult = eConsiderFrameForProcessing( ucEthernetBuffer ); + + TEST_ASSERT_EQUAL( eReleaseBuffer, eResult ); +} diff --git a/test/unit-test/FreeRTOS_IP_DiffConfig2/FreeRTOSIPConfig.h b/test/unit-test/FreeRTOS_IP_DiffConfig2/FreeRTOSIPConfig.h index cbcbc93853..73c8ac7478 100644 --- a/test/unit-test/FreeRTOS_IP_DiffConfig2/FreeRTOSIPConfig.h +++ b/test/unit-test/FreeRTOS_IP_DiffConfig2/FreeRTOSIPConfig.h @@ -302,7 +302,8 @@ #define ipconfigUSE_NBNS ( 1 ) -#define ipconfigUSE_LLMNR ( 1 ) +#define ipconfigUSE_LLMNR ( 0 ) +#define ipconfigUSE_MDNS ( 0 ) #define ipconfigDNS_USE_CALLBACKS 1 #define ipconfigUSE_ARP_REMOVE_ENTRY 1 diff --git a/test/unit-test/FreeRTOS_IP_DiffConfig2/FreeRTOS_IP_DiffConfig2_stubs.c b/test/unit-test/FreeRTOS_IP_DiffConfig2/FreeRTOS_IP_DiffConfig2_stubs.c index f35bef3063..641b42e4b7 100644 --- a/test/unit-test/FreeRTOS_IP_DiffConfig2/FreeRTOS_IP_DiffConfig2_stubs.c +++ b/test/unit-test/FreeRTOS_IP_DiffConfig2/FreeRTOS_IP_DiffConfig2_stubs.c @@ -51,6 +51,12 @@ struct xNetworkEndPoint * pxNetworkEndPoints = NULL; const MACAddress_t xLLMNR_MacAddress = { { 0x01, 0x00, 0x5e, 0x00, 0x00, 0xfc } }; +const MACAddress_t xLLMNR_MacAddressIPv6 = { { 0x33, 0x33, 0x00, 0x01, 0x00, 0x03 } }; + +const MACAddress_t xMDNS_MacAddress = { { 0x01, 0x00, 0x5e, 0x00, 0x00, 0xfb } }; + +const MACAddress_t xMDNS_MacAddressIPv6 = { { 0x33, 0x33, 0x00, 0x00, 0x00, 0xFB } }; + void vPortEnterCritical( void ) { } diff --git a/test/unit-test/FreeRTOS_IP_DiffConfig2/FreeRTOS_IP_DiffConfig2_utest.c b/test/unit-test/FreeRTOS_IP_DiffConfig2/FreeRTOS_IP_DiffConfig2_utest.c index 15bfe29cc9..25cf53b60e 100644 --- a/test/unit-test/FreeRTOS_IP_DiffConfig2/FreeRTOS_IP_DiffConfig2_utest.c +++ b/test/unit-test/FreeRTOS_IP_DiffConfig2/FreeRTOS_IP_DiffConfig2_utest.c @@ -143,3 +143,115 @@ void test_FreeRTOS_IPInit_HappyPathDHCP( void ) TEST_ASSERT_EQUAL( pdPASS, xReturn ); TEST_ASSERT_EQUAL( IPInItHappyPath_xTaskHandleToSet, FreeRTOS_GetIPTaskHandle() ); } + +/** + * @brief test_eConsiderFrameForProcessing_LLMNR_IPv4_MACMatch_But_Disabled + * eConsiderFrameForProcessing must return eReleaseBuffer when the MAC address in packet + * matches LLMNR MAC address and the frame type is valid but any of ipconfigUSE_DNS, ipconfigUSE_LLMNR + * or ipconfigUSE_IPv4 is disabled. + */ +void test_eConsiderFrameForProcessing_LLMNR_IPv4_MACMatch_But_Disabled( void ) +{ + eFrameProcessingResult_t eResult; + uint8_t ucEthernetBuffer[ ipconfigNETWORK_MTU ]; + EthernetHeader_t * pxEthernetHeader; + + /* eConsiderFrameForProcessing */ + FreeRTOS_FindEndPointOnMAC_ExpectAnyArgsAndReturn( NULL ); + + /* Map the buffer onto Ethernet Header struct for easy access to fields. */ + pxEthernetHeader = ( EthernetHeader_t * ) ucEthernetBuffer; + + memset( ucEthernetBuffer, 0x00, ipconfigNETWORK_MTU ); + + memcpy( pxEthernetHeader->xDestinationAddress.ucBytes, xLLMNR_MacAddress.ucBytes, sizeof( MACAddress_t ) ); + pxEthernetHeader->usFrameType = ipIPv4_FRAME_TYPE; + + eResult = eConsiderFrameForProcessing( ucEthernetBuffer ); + + TEST_ASSERT_EQUAL( eReleaseBuffer, eResult ); +} + +/** + * @brief test_eConsiderFrameForProcessing_LLMNR_IPv6_MACMatch_But_Disabled + * eConsiderFrameForProcessing must return eReleaseBuffer when the MAC address in packet + * matches LLMNR MAC address and the frame type is valid but any of ipconfigUSE_DNS, ipconfigUSE_LLMNR + * or ipconfigUSE_IPv6 is disabled. + */ +void test_eConsiderFrameForProcessing_LLMNR_IPv6_MACMatch_But_Disabled( void ) +{ + eFrameProcessingResult_t eResult; + uint8_t ucEthernetBuffer[ ipconfigNETWORK_MTU ]; + EthernetHeader_t * pxEthernetHeader; + + /* eConsiderFrameForProcessing */ + FreeRTOS_FindEndPointOnMAC_ExpectAnyArgsAndReturn( NULL ); + + /* Map the buffer onto Ethernet Header struct for easy access to fields. */ + pxEthernetHeader = ( EthernetHeader_t * ) ucEthernetBuffer; + + memset( ucEthernetBuffer, 0x00, ipconfigNETWORK_MTU ); + + memcpy( pxEthernetHeader->xDestinationAddress.ucBytes, xLLMNR_MacAddressIPv6.ucBytes, sizeof( MACAddress_t ) ); + pxEthernetHeader->usFrameType = ipIPv6_FRAME_TYPE; + + eResult = eConsiderFrameForProcessing( ucEthernetBuffer ); + + TEST_ASSERT_EQUAL( eReleaseBuffer, eResult ); +} + +/** + * @brief test_eConsiderFrameForProcessing_MDNS_IPv6_MACMatch_But_Disabled + * eConsiderFrameForProcessing must return eReleaseBuffer when the MAC address in packet + * matches MDNS MAC address and the frame type is valid but any of ipconfigUSE_DNS, ipconfigUSE_MDNS + * or ipconfigUSE_IPv6 is disabled. + */ +void test_eConsiderFrameForProcessing_MDNS_IPv6_MACMatch_But_Disabled( void ) +{ + eFrameProcessingResult_t eResult; + uint8_t ucEthernetBuffer[ ipconfigNETWORK_MTU ]; + EthernetHeader_t * pxEthernetHeader; + + /* eConsiderFrameForProcessing */ + FreeRTOS_FindEndPointOnMAC_ExpectAnyArgsAndReturn( NULL ); + + /* Map the buffer onto Ethernet Header struct for easy access to fields. */ + pxEthernetHeader = ( EthernetHeader_t * ) ucEthernetBuffer; + + memset( ucEthernetBuffer, 0x00, ipconfigNETWORK_MTU ); + + memcpy( pxEthernetHeader->xDestinationAddress.ucBytes, xMDNS_MacAddressIPv6.ucBytes, sizeof( MACAddress_t ) ); + pxEthernetHeader->usFrameType = ipIPv6_FRAME_TYPE; + + eResult = eConsiderFrameForProcessing( ucEthernetBuffer ); + + TEST_ASSERT_EQUAL( eReleaseBuffer, eResult ); +} + +/** + * @brief test_eConsiderFrameForProcessing_MDNS_IPv4_MACMatch_But_Disabled + * eConsiderFrameForProcessing must return eReleaseBuffer when the MAC address in packet + * matches MDNS MAC address and the frame type is valid but any of ipconfigUSE_DNS, ipconfigUSE_MDNS + * or ipconfigUSE_IPv4 is disabled. + */ +void test_eConsiderFrameForProcessing_MDNS_IPv4_MACMatch_But_Disabled( void ) +{ + eFrameProcessingResult_t eResult; + uint8_t ucEthernetBuffer[ ipconfigNETWORK_MTU ]; + EthernetHeader_t * pxEthernetHeader; + + /* eConsiderFrameForProcessing */ + FreeRTOS_FindEndPointOnMAC_ExpectAnyArgsAndReturn( NULL ); + + /* Map the buffer onto Ethernet Header struct for easy access to fields. */ + pxEthernetHeader = ( EthernetHeader_t * ) ucEthernetBuffer; + + memset( ucEthernetBuffer, 0x00, ipconfigNETWORK_MTU ); + + memcpy( pxEthernetHeader->xDestinationAddress.ucBytes, xMDNS_MacAddress.ucBytes, sizeof( MACAddress_t ) ); + pxEthernetHeader->usFrameType = ipIPv4_FRAME_TYPE; + + eResult = eConsiderFrameForProcessing( ucEthernetBuffer ); + + TEST_ASSERT_EQUAL( eReleaseBuffer, eResult ); +} diff --git a/test/unit-test/FreeRTOS_IP_DiffConfig3/FreeRTOS_IP_DiffConfig3_stubs.c b/test/unit-test/FreeRTOS_IP_DiffConfig3/FreeRTOS_IP_DiffConfig3_stubs.c index ddaffbd0a7..938937b617 100644 --- a/test/unit-test/FreeRTOS_IP_DiffConfig3/FreeRTOS_IP_DiffConfig3_stubs.c +++ b/test/unit-test/FreeRTOS_IP_DiffConfig3/FreeRTOS_IP_DiffConfig3_stubs.c @@ -52,6 +52,12 @@ struct xNetworkEndPoint * pxNetworkEndPoints = NULL; const MACAddress_t xLLMNR_MacAddress = { { 0x01, 0x00, 0x5e, 0x00, 0x00, 0xfc } }; +const MACAddress_t xLLMNR_MacAddressIPv6 = { { 0x33, 0x33, 0x00, 0x01, 0x00, 0x03 } }; + +const MACAddress_t xMDNS_MacAddress = { { 0x01, 0x00, 0x5e, 0x00, 0x00, 0xfb } }; + +const MACAddress_t xMDNS_MacAddressIPv6 = { { 0x33, 0x33, 0x00, 0x00, 0x00, 0xFB } }; + void vPortEnterCritical( void ) { } diff --git a/test/unit-test/FreeRTOS_IPv6/FreeRTOS_IPv6_stubs.c b/test/unit-test/FreeRTOS_IPv6/FreeRTOS_IPv6_stubs.c index 03ba1b2c32..5767d82acb 100644 --- a/test/unit-test/FreeRTOS_IPv6/FreeRTOS_IPv6_stubs.c +++ b/test/unit-test/FreeRTOS_IPv6/FreeRTOS_IPv6_stubs.c @@ -109,7 +109,11 @@ static NetworkBufferDescriptor_t * prvInitializeNetworkDescriptorWithExtensionHe { static NetworkBufferDescriptor_t xNetworkBuffer; /* Ethernet header + IPv6 header + Maximum protocol header + IPv6 Extension Headers + 1 payload */ - static uint8_t pcNetworkBuffer[ sizeof( EthernetHeader_t ) + sizeof( IPHeader_IPv6_t ) + TEST_IPv6_DEFAULT_EXTENSION_HEADERS_LENGTH + sizeof( ICMPHeader_IPv6_t ) + 1U ]; + static uint8_t pcNetworkBuffer[ + sizeof( EthernetHeader_t ) + sizeof( IPHeader_IPv6_t ) + TEST_IPv6_DEFAULT_EXTENSION_HEADERS_LENGTH + + configMAX( sizeof( ICMPHeader_IPv6_t ), sizeof( TCPHeader_t ) ) + + 1U + ]; EthernetHeader_t * pxEthHeader = ( EthernetHeader_t * ) pcNetworkBuffer; IPHeader_IPv6_t * pxIPv6Header = ( IPHeader_IPv6_t * ) &( pcNetworkBuffer[ sizeof( EthernetHeader_t ) ] ); uint8_t * pxIPv6ExtHeader = ( uint8_t * ) &( pcNetworkBuffer[ sizeof( EthernetHeader_t ) + sizeof( IPHeader_IPv6_t ) ] ); diff --git a/test/unit-test/FreeRTOS_IPv6/FreeRTOS_IPv6_utest.c b/test/unit-test/FreeRTOS_IPv6/FreeRTOS_IPv6_utest.c index b869cef098..edcfab7656 100644 --- a/test/unit-test/FreeRTOS_IPv6/FreeRTOS_IPv6_utest.c +++ b/test/unit-test/FreeRTOS_IPv6/FreeRTOS_IPv6_utest.c @@ -310,10 +310,10 @@ void test_eHandleIPv6ExtensionHeaders_TCPHappyPath() uint8_t ucExtHeaderNum = 7U; uint8_t ucProtocol = ipPROTOCOL_TCP; NetworkBufferDescriptor_t * pxNetworkBuffer = prvInitializeNetworkDescriptorWithExtensionHeader( ucProtocol ); - TCPHeader_t * pxProtocolHeader = ( TCPHeader_t * ) &( pxNetworkBuffer->pucEthernetBuffer[ ipSIZE_OF_ETH_HEADER + ipSIZE_OF_IPv6_HEADER + TEST_IPv6_DEFAULT_EXTENSION_HEADERS_LENGTH ] ); - uint8_t * pxPayload; + uint8_t * pxPayload = &( pxNetworkBuffer->pucEthernetBuffer[ + ipSIZE_OF_ETH_HEADER + ipSIZE_OF_IPv6_HEADER + TEST_IPv6_DEFAULT_EXTENSION_HEADERS_LENGTH + sizeof( TCPHeader_t ) + ] ); - pxPayload = ( uint8_t * ) ( pxProtocolHeader + 1 ); *pxPayload = 'a'; usGetExtensionHeaderLength_ExpectAndReturn( pxNetworkBuffer->pucEthernetBuffer, pxNetworkBuffer->xDataLength, NULL, ucExtHeaderNum * 8U ); diff --git a/test/unit-test/FreeRTOS_ND/FreeRTOS_ND_utest.c b/test/unit-test/FreeRTOS_ND/FreeRTOS_ND_utest.c index 61f32fad66..084866a1cf 100644 --- a/test/unit-test/FreeRTOS_ND/FreeRTOS_ND_utest.c +++ b/test/unit-test/FreeRTOS_ND/FreeRTOS_ND_utest.c @@ -110,7 +110,7 @@ static const MACAddress_t xDefaultMACAddress = { 0x22, 0x22, 0x22, 0x22, 0x22, 0 */ void test_eNDGetCacheEntry_MulticastEndPoint( void ) { - eARPLookupResult_t eResult; + eResolutionLookupResult_t eResult; MACAddress_t xMACAddress; IPv6_Address_t xIPAddress; NetworkEndPoint_t xEndPoint, * pxEndPoint = &xEndPoint; @@ -134,7 +134,7 @@ void test_eNDGetCacheEntry_MulticastEndPoint( void ) void test_eNDGetCacheEntry_Multicast_ValidEndPoint( void ) { NetworkEndPoint_t xEndPoint1, xEndPoint2, xEndPoint3, * pxEndPoint = &xEndPoint1; - eARPLookupResult_t eResult; + eResolutionLookupResult_t eResult; MACAddress_t xMACAddress; IPv6_Address_t xIPAddress; @@ -164,7 +164,7 @@ void test_eNDGetCacheEntry_Multicast_ValidEndPoint( void ) void test_eNDGetCacheEntry_Multicast_InvalidEndPoint( void ) { NetworkEndPoint_t ** ppxEndPoint = NULL; - eARPLookupResult_t eResult; + eResolutionLookupResult_t eResult; MACAddress_t xMACAddress; IPv6_Address_t xIPAddress; @@ -188,7 +188,7 @@ void test_eNDGetCacheEntry_NDCacheLookupHit_InvalidEndPoint( void ) MACAddress_t xMACAddress; IPv6_Address_t xIPAddress; NetworkEndPoint_t ** ppxEndPoint = NULL; - eARPLookupResult_t eResult; + eResolutionLookupResult_t eResult; BaseType_t xUseEntry = 0; xIsIPv6AllowedMulticast_ExpectAnyArgsAndReturn( pdFALSE ); @@ -217,7 +217,7 @@ void test_eNDGetCacheEntry_NDCacheLookupHit_ValidEndPoint( void ) MACAddress_t xMACAddress; IPv6_Address_t xIPAddress; NetworkEndPoint_t * pxEndPoint, xEndPoint1, xEndPoint2; - eARPLookupResult_t eResult; + eResolutionLookupResult_t eResult; BaseType_t xUseEntry = 0; xIsIPv6AllowedMulticast_ExpectAnyArgsAndReturn( pdFALSE ); @@ -247,7 +247,7 @@ void test_eNDGetCacheEntry_NDCacheLookupHit_ValidEndPoint( void ) void test_eNDGetCacheEntry_NDCacheLookupMiss_InvalidEntry( void ) { NetworkEndPoint_t * pxEndPoint, xEndPoint; - eARPLookupResult_t eResult; + eResolutionLookupResult_t eResult; BaseType_t xUseEntry = 0; MACAddress_t xMACAddress; IPv6_Address_t xIPAddress; @@ -274,7 +274,7 @@ void test_eNDGetCacheEntry_NDCacheLookupMiss_InvalidEntry( void ) void test_eNDGetCacheEntry_NDCacheLookupMiss_InvalidEntry2( void ) { NetworkEndPoint_t ** ppxEndPoint = NULL, xEndPoint; - eARPLookupResult_t eResult; + eResolutionLookupResult_t eResult; BaseType_t xUseEntry = 0; MACAddress_t xMACAddress; IPv6_Address_t xIPAddress; @@ -301,7 +301,7 @@ void test_eNDGetCacheEntry_NDCacheLookupMiss_InvalidEntry2( void ) void test_eNDGetCacheEntry_NDCacheLookupMiss_NoEntry( void ) { NetworkEndPoint_t * pxEndPoint, xEndPoint; - eARPLookupResult_t eResult; + eResolutionLookupResult_t eResult; BaseType_t xUseEntry = 0; MACAddress_t xMACAddress; IPv6_Address_t xIPAddress; @@ -329,7 +329,7 @@ void test_eNDGetCacheEntry_NDCacheLookupMiss_NoEntry( void ) void test_eNDGetCacheEntry_NDCacheLookupMiss_NoLinkLocal( void ) { NetworkEndPoint_t * pxEndPoint, xEndPoint; - eARPLookupResult_t eResult; + eResolutionLookupResult_t eResult; BaseType_t xUseEntry = 0; MACAddress_t xMACAddress; IPv6_Address_t xIPAddress; @@ -361,7 +361,7 @@ void test_eNDGetCacheEntry_NDCacheLookupMiss_NoLinkLocal( void ) void test_eNDGetCacheEntry_NDCacheLookupMiss_LinkLocal( void ) { NetworkEndPoint_t * pxEndPoint, xEndPoint; - eARPLookupResult_t eResult; + eResolutionLookupResult_t eResult; BaseType_t xUseEntry = 0; MACAddress_t xMACAddress; IPv6_Address_t xIPAddress; @@ -392,7 +392,7 @@ void test_eNDGetCacheEntry_NDCacheLookupHit_Gateway( void ) MACAddress_t xMACAddress; IPv6_Address_t xIPAddress; NetworkEndPoint_t * pxEndPoint, xEndPoint1, xEndPoint2; - eARPLookupResult_t eResult; + eResolutionLookupResult_t eResult; BaseType_t xUseEntry = 0; pxEndPoint = &xEndPoint2; @@ -425,7 +425,7 @@ void test_eNDGetCacheEntry_NDCacheLookupMiss_Gateway( void ) MACAddress_t xMACAddress; IPv6_Address_t xIPAddress; NetworkEndPoint_t * pxEndPoint, xEndPoint1, xEndPoint2; - eARPLookupResult_t eResult; + eResolutionLookupResult_t eResult; BaseType_t xUseEntry = 0; pxEndPoint = &xEndPoint2; @@ -455,9 +455,8 @@ void test_eNDGetCacheEntry_NDCacheLookupMiss_Gateway( void ) void test_eNDGetCacheEntry_NDCacheLookupMiss_NoEP( void ) { MACAddress_t xMACAddress; - IPv6_Address_t xIPAddress; NetworkEndPoint_t * pxEndPoint, xEndPoint; - eARPLookupResult_t eResult; + eResolutionLookupResult_t eResult; BaseType_t xUseEntry = 0; ( void ) memset( xNDCache, 0, sizeof( xNDCache ) ); @@ -472,7 +471,8 @@ void test_eNDGetCacheEntry_NDCacheLookupMiss_NoEP( void ) FreeRTOS_FindGateWay_ExpectAnyArgsAndReturn( NULL ); - eResult = eNDGetCacheEntry( &xIPAddress, &xMACAddress, &pxEndPoint ); + /* TODO: This function should take a const pointer; remove const cast when it does. */ + eResult = eNDGetCacheEntry( ( IPv6_Address_t * ) &xSiteLocalIPAddress, &xMACAddress, &pxEndPoint ); TEST_ASSERT_EQUAL( eResolutionCacheMiss, eResult ); } @@ -1039,13 +1039,16 @@ void test_SendPingRequestIPv6_NULL_Buffer( void ) */ void test_SendPingRequestIPv6_Assert( void ) { - NetworkEndPoint_t xEndPoint, * pxEndPoint = &xEndPoint; - NetworkBufferDescriptor_t xNetworkBuffer, * pxNetworkBuffer = &xNetworkBuffer; - IPv6_Address_t xIPAddress; + NetworkEndPoint_t xEndPoint = { 0 }, * pxEndPoint = &xEndPoint; + NetworkBufferDescriptor_t xNetworkBuffer = { 0 }; + uint8_t ucEthernetBuffer[ 1500 ] = { 0 }; + IPv6_Address_t xIPAddress = { 0 }; size_t uxNumberOfBytesToSend = 100; BaseType_t xReturn; uint16_t usSequenceNumber = 1; + xNetworkBuffer.pucEthernetBuffer = ucEthernetBuffer; + xNetworkBuffer.xDataLength = sizeof( ucEthernetBuffer ); ( void ) memcpy( xIPAddress.ucBytes, xDefaultIPAddress.ucBytes, ipSIZE_OF_IPv6_ADDRESS ); pxEndPoint->bits.bIPv6 = 1; @@ -1057,7 +1060,7 @@ void test_SendPingRequestIPv6_Assert( void ) uxGetNumberOfFreeNetworkBuffers_ExpectAndReturn( 4U ); - pxGetNetworkBufferWithDescriptor_ExpectAnyArgsAndReturn( pxNetworkBuffer ); + pxGetNetworkBufferWithDescriptor_ExpectAnyArgsAndReturn( &xNetworkBuffer ); xSendEventStructToIPTask_IgnoreAndReturn( pdPASS ); xReturn = FreeRTOS_SendPingRequestIPv6( &xIPAddress, uxNumberOfBytesToSend, 0 ); @@ -1073,12 +1076,15 @@ void test_SendPingRequestIPv6_Assert( void ) void test_SendPingRequestIPv6_SendToIP_Pass( void ) { NetworkEndPoint_t xEndPoint, * pxEndPoint = &xEndPoint; - NetworkBufferDescriptor_t xNetworkBuffer, * pxNetworkBuffer = &xNetworkBuffer; + NetworkBufferDescriptor_t xNetworkBuffer = { 0 }, * pxNetworkBuffer = &xNetworkBuffer; + uint8_t ucEthernetBuffer[ 1500 ] = { 0 }; IPv6_Address_t xIPAddress; size_t uxNumberOfBytesToSend = 100; BaseType_t xReturn; uint16_t usSequenceNumber = 1; + xNetworkBuffer.pucEthernetBuffer = ucEthernetBuffer; + xNetworkBuffer.xDataLength = sizeof( ucEthernetBuffer ); ( void ) memcpy( xIPAddress.ucBytes, xDefaultIPAddress.ucBytes, ipSIZE_OF_IPv6_ADDRESS ); pxEndPoint->bits.bIPv6 = 1; @@ -1107,11 +1113,13 @@ void test_SendPingRequestIPv6_SendToIP_Fail( void ) { NetworkEndPoint_t xEndPoint, * pxEndPoint = &xEndPoint; NetworkBufferDescriptor_t xNetworkBuffer, * pxNetworkBuffer = &xNetworkBuffer; + uint8_t ucEthernetBuffer[ 1500 ] = { 0 }; IPv6_Address_t xIPAddress; size_t uxNumberOfBytesToSend = 100; BaseType_t xReturn; uint16_t usSequenceNumber = 1; + xNetworkBuffer.pucEthernetBuffer = ucEthernetBuffer; ( void ) memcpy( xIPAddress.ucBytes, xDefaultIPAddress.ucBytes, ipSIZE_OF_IPv6_ADDRESS ); pxEndPoint->bits.bIPv6 = 1; @@ -1454,15 +1462,17 @@ void test_prvProcessICMPMessage_IPv6_ipICMP_PING_REPLY_IPv6_eSuccess( void ) */ void test_prvProcessICMPMessage_IPv6_NeighborSolicitationNullEP( void ) { - NetworkBufferDescriptor_t xNetworkBuffer, * pxNetworkBuffer = &xNetworkBuffer; - ICMPPacket_IPv6_t xICMPPacket; - NetworkEndPoint_t xEndPoint; + NetworkBufferDescriptor_t xNetworkBuffer = { 0 }, * pxNetworkBuffer = &xNetworkBuffer; + ICMPPacket_IPv6_t xICMPPacket = { 0 }; + NetworkEndPoint_t xEndPoint = { 0 }; eFrameProcessingResult_t eReturn; xEndPoint.bits.bIPv6 = pdTRUE_UNSIGNED; + ( void ) memcpy( xEndPoint.ipv6_settings.xIPAddress.ucBytes, xDefaultIPAddress.ucBytes, ipSIZE_OF_IPv6_ADDRESS ); xICMPPacket.xICMPHeaderIPv6.ucTypeOfMessage = ipICMP_NEIGHBOR_SOLICITATION_IPv6; pxNetworkBuffer->pxEndPoint = &xEndPoint; pxNetworkBuffer->pucEthernetBuffer = ( uint8_t * ) &xICMPPacket; + pxNetworkBuffer->xDataLength = sizeof( xICMPPacket ); FreeRTOS_InterfaceEPInSameSubnet_IPv6_ExpectAnyArgsAndReturn( NULL ); @@ -1497,34 +1507,6 @@ void test_prvProcessICMPMessage_IPv6_NeighborSolicitationIncorrectLen( void ) TEST_ASSERT_EQUAL( eReturn, eReleaseBuffer ); } - -/** - * @brief This function process ICMP message when message type is - * ipICMP_NEIGHBOR_SOLICITATION_IPv6. - * It handles case where the ICMP header address does not - * match which means the message is not for us, - * ignore it. - */ -void test_prvProcessICMPMessage_IPv6_NeighborSolicitationCorrectLen( void ) -{ - NetworkBufferDescriptor_t xNetworkBuffer, * pxNetworkBuffer = &xNetworkBuffer; - ICMPPacket_IPv6_t xICMPPacket; - NetworkEndPoint_t xEndPoint; - eFrameProcessingResult_t eReturn; - - xEndPoint.bits.bIPv6 = pdTRUE_UNSIGNED; - xICMPPacket.xICMPHeaderIPv6.ucTypeOfMessage = ipICMP_NEIGHBOR_SOLICITATION_IPv6; - pxNetworkBuffer->pxEndPoint = &xEndPoint; - pxNetworkBuffer->pucEthernetBuffer = ( uint8_t * ) &xICMPPacket; - pxNetworkBuffer->xDataLength = xHeaderSize + ipBUFFER_PADDING; - - FreeRTOS_InterfaceEPInSameSubnet_IPv6_ExpectAnyArgsAndReturn( &xEndPoint ); - - eReturn = prvProcessICMPMessage_IPv6( pxNetworkBuffer ); - - TEST_ASSERT_EQUAL( eReturn, eReleaseBuffer ); -} - /** * @brief This function process ICMP message when message type is * ipICMP_NEIGHBOR_SOLICITATION_IPv6. diff --git a/test/unit-test/FreeRTOS_RA/FreeRTOS_RA_stubs.c b/test/unit-test/FreeRTOS_RA/FreeRTOS_RA_stubs.c index f20c7d847c..e6c503f5f0 100644 --- a/test/unit-test/FreeRTOS_RA/FreeRTOS_RA_stubs.c +++ b/test/unit-test/FreeRTOS_RA/FreeRTOS_RA_stubs.c @@ -29,7 +29,7 @@ * (maybe DHCP is still in process, or the addressing needs a gateway but there * isn't a gateway defined) then return eResolutionFailed. */ -eARPLookupResult_t eNDGetCacheEntry( IPv6_Address_t * pxIPAddress, +eResolutionLookupResult_t eNDGetCacheEntry( IPv6_Address_t * pxIPAddress, MACAddress_t * const pxMACAddress, struct xNetworkEndPoint ** ppxEndPoint ) { diff --git a/test/unit-test/FreeRTOS_RA/FreeRTOS_RA_utest.c b/test/unit-test/FreeRTOS_RA/FreeRTOS_RA_utest.c index a1dfca94e0..b82ae59832 100644 --- a/test/unit-test/FreeRTOS_RA/FreeRTOS_RA_utest.c +++ b/test/unit-test/FreeRTOS_RA/FreeRTOS_RA_utest.c @@ -52,6 +52,19 @@ #include "FreeRTOS_ND.h" #include "FreeRTOS_RA_stubs.c" +/* ================================ TYPES ================================= */ + +#include "pack_struct_start.h" +struct xEthernetPacketICMPv6RouterAdvertisementPrefixOption +{ + EthernetHeader_t xEthernetHeader; /* 0 + 14 = 14 */ + IPHeader_IPv6_t xIPHeader; /* 14 + 40 = 54 */ + ICMPRouterAdvertisement_IPv6_t xAdvertisement; /* 54 + 16 = 70 */ + ICMPPrefixOption_IPv6_t xPrefixOption; /* 70 + 32 = 102 */ +} +#include "pack_struct_end.h" +typedef struct xEthernetPacketICMPv6RouterAdvertisementPrefixOption EthernetPacketICMPv6RouterAdvertisementPrefixOption_t; + /* =========================== EXTERN VARIABLES =========================== */ /** The default value for the IPv6-field 'ucVersionTrafficClass'. */ @@ -866,17 +879,15 @@ void test_vReceiveRA_ValidICMPPrefix_IncorrectOption( void ) */ void test_vReceiveRA_vRAProccess( void ) { - NetworkBufferDescriptor_t * pxNetworkBuffer, xNetworkBuffer, xNetworkBuffer2; - ICMPPacket_IPv6_t xICMPPacket; + NetworkBufferDescriptor_t * pxNetworkBuffer, xNetworkBuffer; + EthernetPacketICMPv6RouterAdvertisementPrefixOption_t xICMPPacket; NetworkInterface_t xInterface; - size_t uxIndex = 0U, uxNeededSize, uxOptionsLength; - uint8_t * pucBytes; NetworkEndPoint_t xEndPoint, * pxEndPoint = &xEndPoint; ICMPPrefixOption_IPv6_t * pxPrefixOption; ICMPRouterAdvertisement_IPv6_t * pxAdvertisement; memset( &xNetworkBuffer, 0, sizeof( NetworkBufferDescriptor_t ) ); - memset( &xICMPPacket, 0, sizeof( ICMPPacket_IPv6_t ) ); + memset( &xICMPPacket, 0, sizeof( xICMPPacket ) ); memset( &xInterface, 0, sizeof( NetworkInterface_t ) ); memset( &xEndPoint, 0, sizeof( NetworkEndPoint_t ) ); @@ -884,11 +895,10 @@ void test_vReceiveRA_vRAProccess( void ) pxNetworkBuffer->pucEthernetBuffer = ( uint8_t * ) &xICMPPacket; pxNetworkBuffer->pxInterface = &xInterface; pxNetworkBuffer->xDataLength = raHeaderBytesRA + raPrefixOptionlen; - uxNeededSize = raHeaderBytesRA; - pxAdvertisement = ( ( ICMPRouterAdvertisement_IPv6_t * ) &( xICMPPacket.xICMPHeaderIPv6 ) ); + pxAdvertisement = &xICMPPacket.xAdvertisement; pxAdvertisement->usLifetime = pdTRUE_UNSIGNED; - pxPrefixOption = ( ICMPPrefixOption_IPv6_t * ) &( pxNetworkBuffer->pucEthernetBuffer[ uxNeededSize ] ); + pxPrefixOption = &xICMPPacket.xPrefixOption; pxPrefixOption->ucType = ndICMP_PREFIX_INFORMATION; /* Only 1 option */ pxPrefixOption->ucLength = 1; @@ -906,17 +916,15 @@ void test_vReceiveRA_vRAProccess( void ) */ void test_vReceiveRA_vRAProcess( void ) { - NetworkBufferDescriptor_t * pxNetworkBuffer, xNetworkBuffer, xNetworkBuffer2; - ICMPPacket_IPv6_t xICMPPacket; + NetworkBufferDescriptor_t * pxNetworkBuffer, xNetworkBuffer; + EthernetPacketICMPv6RouterAdvertisementPrefixOption_t xICMPPacket; NetworkInterface_t xInterface; - size_t uxIndex = 0U, uxNeededSize, uxOptionsLength; - uint8_t * pucBytes; NetworkEndPoint_t xEndPoint, * pxEndPoint = &xEndPoint; ICMPPrefixOption_IPv6_t * pxPrefixOption; ICMPRouterAdvertisement_IPv6_t * pxAdvertisement; memset( &xNetworkBuffer, 0, sizeof( NetworkBufferDescriptor_t ) ); - memset( &xICMPPacket, 0, sizeof( ICMPPacket_IPv6_t ) ); + memset( &xICMPPacket, 0, sizeof( xICMPPacket ) ); memset( &xInterface, 0, sizeof( NetworkInterface_t ) ); memset( &xEndPoint, 0, sizeof( NetworkEndPoint_t ) ); @@ -924,11 +932,10 @@ void test_vReceiveRA_vRAProcess( void ) pxNetworkBuffer->pucEthernetBuffer = ( uint8_t * ) &xICMPPacket; pxNetworkBuffer->pxInterface = &xInterface; pxNetworkBuffer->xDataLength = raHeaderBytesRA + raPrefixOptionlen; - uxNeededSize = raHeaderBytesRA; - pxAdvertisement = ( ( ICMPRouterAdvertisement_IPv6_t * ) &( xICMPPacket.xICMPHeaderIPv6 ) ); + pxAdvertisement = &xICMPPacket.xAdvertisement; pxAdvertisement->usLifetime = pdTRUE_UNSIGNED; - pxPrefixOption = ( ICMPPrefixOption_IPv6_t * ) &( pxNetworkBuffer->pucEthernetBuffer[ uxNeededSize ] ); + pxPrefixOption = &xICMPPacket.xPrefixOption; pxPrefixOption->ucType = ndICMP_PREFIX_INFORMATION; /* Only 1 option */ pxPrefixOption->ucLength = 1; diff --git a/test/unit-test/FreeRTOS_Routing/FreeRTOSIPConfig.h b/test/unit-test/FreeRTOS_Routing/FreeRTOSIPConfig.h index 317cc58abc..a3ed8a1a01 100644 --- a/test/unit-test/FreeRTOS_Routing/FreeRTOSIPConfig.h +++ b/test/unit-test/FreeRTOS_Routing/FreeRTOSIPConfig.h @@ -40,8 +40,6 @@ #define ipconfigCOMPATIBLE_WITH_SINGLE ( 0 ) -#define ipconfigHAS_ROUTING_STATISTICS ( 1 ) - /* Set to 1 to print out debug messages. If ipconfigHAS_DEBUG_PRINTF is set to * 1 then FreeRTOS_debug_printf should be defined to the function used to print * out the debugging messages. */ diff --git a/test/unit-test/FreeRTOS_Routing/FreeRTOS_Routing_utest.c b/test/unit-test/FreeRTOS_Routing/FreeRTOS_Routing_utest.c index 8a96488b4c..8a10c4a7fa 100644 --- a/test/unit-test/FreeRTOS_Routing/FreeRTOS_Routing_utest.c +++ b/test/unit-test/FreeRTOS_Routing/FreeRTOS_Routing_utest.c @@ -68,7 +68,6 @@ /* Default IPv4 netmask is 192.168.123.1, which is 0x017BA8C0. */ #define IPV4_DEFAULT_DNS_SERVER ( 0x017BA8C0 ) -extern RoutingStats_t xRoutingStatistics; const struct xIPv6_Address FreeRTOS_in6addr_any; const struct xIPv6_Address FreeRTOS_in6addr_loopback; @@ -1334,7 +1333,7 @@ void test_FreeRTOS_FindEndPointOnIP_IPv4_HappyPath( void ) pxNetworkEndPoints = &xEndPoint; - pxEndPoint = FreeRTOS_FindEndPointOnIP_IPv4( IPV4_DEFAULT_ADDRESS, 0 ); + pxEndPoint = FreeRTOS_FindEndPointOnIP_IPv4( IPV4_DEFAULT_ADDRESS ); TEST_ASSERT_EQUAL( &xEndPoint, pxEndPoint ); } @@ -1355,7 +1354,6 @@ void test_FreeRTOS_FindEndPointOnIP_IPv4_NotFound( void ) { NetworkEndPoint_t xEndPoint[ 2 ]; NetworkEndPoint_t * pxEndPoint = NULL; - uint32_t ulWhere; /* Initialize e0. */ memset( &xEndPoint[ 0 ], 0, sizeof( NetworkEndPoint_t ) ); @@ -1368,9 +1366,7 @@ void test_FreeRTOS_FindEndPointOnIP_IPv4_NotFound( void ) xEndPoint[ 1 ].bits.bIPv6 = pdTRUE; pxNetworkEndPoints->pxNext = &xEndPoint[ 1 ]; - /* Set ulWhere to boundary of array size to toggle corner case. */ - ulWhere = sizeof( xRoutingStatistics.ulLocationsIP ) / sizeof( xRoutingStatistics.ulLocationsIP[ 0 ] ); - pxEndPoint = FreeRTOS_FindEndPointOnIP_IPv4( IPV4_DEFAULT_GATEWAY, ulWhere ); + pxEndPoint = FreeRTOS_FindEndPointOnIP_IPv4( IPV4_DEFAULT_GATEWAY ); TEST_ASSERT_EQUAL( NULL, pxEndPoint ); } @@ -1402,13 +1398,13 @@ void test_FreeRTOS_FindEndPointOnIP_IPv4_MultipleEndpoints( void ) xEndPoint[ 1 ].ipv4_settings.ulIPAddress = IPV4_DEFAULT_GATEWAY; pxNetworkEndPoints->pxNext = &xEndPoint[ 1 ]; - pxEndPoint = FreeRTOS_FindEndPointOnIP_IPv4( IPV4_DEFAULT_ADDRESS, 0 ); + pxEndPoint = FreeRTOS_FindEndPointOnIP_IPv4( IPV4_DEFAULT_ADDRESS ); TEST_ASSERT_EQUAL( &xEndPoint[ 0 ], pxEndPoint ); - pxEndPoint = FreeRTOS_FindEndPointOnIP_IPv4( IPV4_DEFAULT_GATEWAY, 0 ); + pxEndPoint = FreeRTOS_FindEndPointOnIP_IPv4( IPV4_DEFAULT_GATEWAY ); TEST_ASSERT_EQUAL( &xEndPoint[ 1 ], pxEndPoint ); - pxEndPoint = FreeRTOS_FindEndPointOnIP_IPv4( IPV4_DEFAULT_DNS_SERVER, 0 ); + pxEndPoint = FreeRTOS_FindEndPointOnIP_IPv4( IPV4_DEFAULT_DNS_SERVER ); TEST_ASSERT_EQUAL( NULL, pxEndPoint ); } @@ -1436,7 +1432,7 @@ void test_FreeRTOS_FindEndPointOnIP_IPv4_AnyEndpoint( void ) xEndPoint[ 1 ].ipv4_settings.ulIPAddress = IPV4_DEFAULT_GATEWAY; pxNetworkEndPoints->pxNext = &xEndPoint[ 1 ]; - pxEndPoint = FreeRTOS_FindEndPointOnIP_IPv4( 0, 0 ); + pxEndPoint = FreeRTOS_FindEndPointOnIP_IPv4( 0 ); TEST_ASSERT_EQUAL( &xEndPoint[ 0 ], pxEndPoint ); } @@ -1462,9 +1458,9 @@ void test_FreeRTOS_FindEndPointOnIP_IPv4_ZeroAddressEndpoint( void ) xEndPoint.ipv4_settings.ulIPAddress = 0; pxNetworkEndPoints = &xEndPoint; - pxEndPoint = FreeRTOS_FindEndPointOnIP_IPv4( IPV4_DEFAULT_ADDRESS, 0 ); + pxEndPoint = FreeRTOS_FindEndPointOnIP_IPv4( IPV4_DEFAULT_ADDRESS ); TEST_ASSERT_EQUAL( &xEndPoint, pxEndPoint ); - pxEndPoint = FreeRTOS_FindEndPointOnIP_IPv4( IPV4_DEFAULT_GATEWAY, 0 ); + pxEndPoint = FreeRTOS_FindEndPointOnIP_IPv4( IPV4_DEFAULT_GATEWAY ); TEST_ASSERT_EQUAL( &xEndPoint, pxEndPoint ); } @@ -1797,7 +1793,7 @@ void test_FreeRTOS_FindEndPointOnNetMask_HappyPath( void ) pxNetworkEndPoints = &xEndPoint; /* IPV4_DEFAULT_DNS_SERVER is 192.168.123.1 within the network region. */ - pxEndPoint = FreeRTOS_FindEndPointOnNetMask( IPV4_DEFAULT_DNS_SERVER, 0 ); + pxEndPoint = FreeRTOS_FindEndPointOnNetMask( IPV4_DEFAULT_DNS_SERVER ); TEST_ASSERT_EQUAL( &xEndPoint, pxEndPoint ); } @@ -1826,7 +1822,7 @@ void test_FreeRTOS_FindEndPointOnNetMask_NotFound( void ) pxNetworkEndPoints = &xEndPoint; /* 192.168.1.1 is 0x0101A8C0. */ - pxEndPoint = FreeRTOS_FindEndPointOnNetMask( 0x0101A8C0, 0 ); + pxEndPoint = FreeRTOS_FindEndPointOnNetMask( 0x0101A8C0 ); TEST_ASSERT_EQUAL( NULL, pxEndPoint ); } @@ -1924,7 +1920,6 @@ void test_FreeRTOS_InterfaceEndPointOnNetMask_HappyPath( void ) NetworkEndPoint_t xEndPoint; NetworkEndPoint_t * pxEndPoint = NULL; NetworkInterface_t xNetworkInterface; - uint32_t ulWhere; /* Initialize network interface and add it to the list. */ memset( &xNetworkInterface, 0, sizeof( NetworkInterface_t ) ); @@ -1937,10 +1932,8 @@ void test_FreeRTOS_InterfaceEndPointOnNetMask_HappyPath( void ) xEndPoint.pxNetworkInterface = &xNetworkInterface; pxNetworkEndPoints = &xEndPoint; - /* Set ulWhere to boundary of array size to toggle corner case. */ - ulWhere = sizeof( xRoutingStatistics.ulLocations ) / sizeof( xRoutingStatistics.ulLocations[ 0 ] ); /* IPV4_DEFAULT_ADDRESS is 192.168.123.1 within the network region. */ - pxEndPoint = FreeRTOS_InterfaceEndPointOnNetMask( &xNetworkInterface, IPV4_DEFAULT_DNS_SERVER, ulWhere ); + pxEndPoint = FreeRTOS_InterfaceEndPointOnNetMask( &xNetworkInterface, IPV4_DEFAULT_DNS_SERVER ); TEST_ASSERT_EQUAL( &xEndPoint, pxEndPoint ); } @@ -1967,7 +1960,6 @@ void test_FreeRTOS_InterfaceEndPointOnNetMask_DifferentInterface( void ) NetworkEndPoint_t xEndPoint[ 2 ]; NetworkEndPoint_t * pxEndPoint = NULL; NetworkInterface_t xNetworkInterface[ 2 ]; - uint32_t ulWhere; /* 192.168.124.223 is 0xDF7CA8C0. */ uint32_t ulE1IPAddress = 0xDF7CA8C0; /* 192.168.124.1 is 0x017CA8C0. */ @@ -1993,10 +1985,8 @@ void test_FreeRTOS_InterfaceEndPointOnNetMask_DifferentInterface( void ) xEndPoint[ 1 ].pxNetworkInterface = &xNetworkInterface[ 1 ]; pxNetworkEndPoints->pxNext = &xEndPoint[ 1 ]; - /* Set ulWhere to boundary of array size to toggle corner case. */ - ulWhere = sizeof( xRoutingStatistics.ulLocations ) / sizeof( xRoutingStatistics.ulLocations[ 0 ] ); /* IPV4_DEFAULT_ADDRESS is 192.168.123.1 within the network region. */ - pxEndPoint = FreeRTOS_InterfaceEndPointOnNetMask( &xNetworkInterface[ 1 ], ulQueryIPAddress, ulWhere ); + pxEndPoint = FreeRTOS_InterfaceEndPointOnNetMask( &xNetworkInterface[ 1 ], ulQueryIPAddress ); TEST_ASSERT_EQUAL( &xEndPoint[ 1 ], pxEndPoint ); } @@ -2034,7 +2024,7 @@ void test_FreeRTOS_InterfaceEndPointOnNetMask_NotFound( void ) pxNetworkEndPoints = &xEndPoint; /* IPV4_DEFAULT_ADDRESS is 192.168.123.1 within the network region. */ - pxEndPoint = FreeRTOS_InterfaceEndPointOnNetMask( &xNetworkInterface, IPV4_DEFAULT_DNS_SERVER, 0 ); + pxEndPoint = FreeRTOS_InterfaceEndPointOnNetMask( &xNetworkInterface, IPV4_DEFAULT_DNS_SERVER ); TEST_ASSERT_EQUAL( NULL, pxEndPoint ); } @@ -2081,7 +2071,7 @@ void test_FreeRTOS_InterfaceEndPointOnNetMask_Broadcast( void ) pxNetworkEndPoints->pxNext = &xEndPoint[ 1 ]; /* IPV4_DEFAULT_ADDRESS is 192.168.123.1 within the network region. */ - pxEndPoint = FreeRTOS_InterfaceEndPointOnNetMask( &xNetworkInterface, 0xFFFFFFFF, 0 ); + pxEndPoint = FreeRTOS_InterfaceEndPointOnNetMask( &xNetworkInterface, 0xFFFFFFFF ); TEST_ASSERT_EQUAL( &xEndPoint[ 1 ], pxEndPoint ); } @@ -2382,8 +2372,8 @@ void test_pcEndpointName_IPv4_HappyPath() { NetworkEndPoint_t xEndPoint; FreeRTOS_Socket_t xSocket; - char cIPString[] = "192.168.123.223"; - int lNameSize = sizeof( cIPString ) + 1; + static const char cIPString[] = "192.168.123.223"; + uint32_t lNameSize = sizeof( cIPString ); char cName[ lNameSize ]; const char * pcName = NULL; @@ -2391,7 +2381,7 @@ void test_pcEndpointName_IPv4_HappyPath() memset( &xEndPoint, 0, sizeof( NetworkEndPoint_t ) ); xEndPoint.ipv4_settings.ulIPAddress = IPV4_DEFAULT_ADDRESS; - memset( &cName, 0, sizeof( cName ) ); + memset( cName, 0, sizeof( cName ) ); xStubFreeRTOS_inet_ntop_TargetFamily = FREERTOS_AF_INET4; pvStubFreeRTOS_inet_ntop_TargetSource = &( xEndPoint.ipv4_settings.ulIPAddress ); @@ -2510,8 +2500,8 @@ void test_pcEndpointName_IPv6_HappyPath() { NetworkEndPoint_t xEndPoint; FreeRTOS_Socket_t xSocket; - const char cIPString[] = "2001::1"; - int lNameSize = sizeof( cIPString ) + 1; + static const char cIPString[] = "2001::1"; + uint32_t lNameSize = sizeof( cIPString ); char cName[ lNameSize ]; const char * pcName; @@ -2520,7 +2510,7 @@ void test_pcEndpointName_IPv6_HappyPath() xEndPoint.bits.bIPv6 = pdTRUE; memcpy( xEndPoint.ipv6_settings.xIPAddress.ucBytes, &xDefaultIPAddress_IPv6.ucBytes, sizeof( IPv6_Address_t ) ); - memset( &cName, 0, sizeof( cName ) ); + memset( cName, 0, sizeof( cName ) ); xStubFreeRTOS_inet_ntop_TargetFamily = FREERTOS_AF_INET6; pvStubFreeRTOS_inet_ntop_TargetSource = xEndPoint.ipv6_settings.xIPAddress.ucBytes; diff --git a/test/unit-test/FreeRTOS_Routing_ConfigCompatibleWithSingle/FreeRTOSIPConfig.h b/test/unit-test/FreeRTOS_Routing_ConfigCompatibleWithSingle/FreeRTOSIPConfig.h index 9d550f5d2e..2f38e010f4 100644 --- a/test/unit-test/FreeRTOS_Routing_ConfigCompatibleWithSingle/FreeRTOSIPConfig.h +++ b/test/unit-test/FreeRTOS_Routing_ConfigCompatibleWithSingle/FreeRTOSIPConfig.h @@ -42,8 +42,6 @@ #define ipconfigCOMPATIBLE_WITH_SINGLE ( 1 ) -#define ipconfigHAS_ROUTING_STATISTICS ( 0 ) - #define ipconfigPROCESS_CUSTOM_ETHERNET_FRAMES ( 0 ) /* Set to 1 to print out debug messages. If ipconfigHAS_DEBUG_PRINTF is set to diff --git a/test/unit-test/FreeRTOS_Routing_ConfigCompatibleWithSingle/FreeRTOS_Routing_ConfigCompatibleWithSingle_utest.c b/test/unit-test/FreeRTOS_Routing_ConfigCompatibleWithSingle/FreeRTOS_Routing_ConfigCompatibleWithSingle_utest.c index 4b3145f32c..0ab121e620 100644 --- a/test/unit-test/FreeRTOS_Routing_ConfigCompatibleWithSingle/FreeRTOS_Routing_ConfigCompatibleWithSingle_utest.c +++ b/test/unit-test/FreeRTOS_Routing_ConfigCompatibleWithSingle/FreeRTOS_Routing_ConfigCompatibleWithSingle_utest.c @@ -740,7 +740,7 @@ void test_FreeRTOS_FindEndPointOnIP_IPv4_HappyPath( void ) pxNetworkEndPoints = &xEndPoint; - pxEndPoint = FreeRTOS_FindEndPointOnIP_IPv4( IPV4_DEFAULT_ADDRESS, 0 ); + pxEndPoint = FreeRTOS_FindEndPointOnIP_IPv4( IPV4_DEFAULT_ADDRESS ); TEST_ASSERT_EQUAL( &xEndPoint, pxEndPoint ); } @@ -766,7 +766,7 @@ void test_FreeRTOS_FindEndPointOnIP_IPv4_NotFound( void ) xEndPoint.ipv4_settings.ulIPAddress = IPV4_DEFAULT_ADDRESS; pxNetworkEndPoints = &xEndPoint; - pxEndPoint = FreeRTOS_FindEndPointOnIP_IPv4( IPV4_DEFAULT_GATEWAY, 0 ); + pxEndPoint = FreeRTOS_FindEndPointOnIP_IPv4( IPV4_DEFAULT_GATEWAY ); TEST_ASSERT_EQUAL( NULL, pxEndPoint ); } @@ -790,7 +790,7 @@ void test_FreeRTOS_FindEndPointOnIP_IPv4_AnyEndpoint( void ) xEndPoint.ipv4_settings.ulIPAddress = IPV4_DEFAULT_ADDRESS; pxNetworkEndPoints = &xEndPoint; - pxEndPoint = FreeRTOS_FindEndPointOnIP_IPv4( 0, 0 ); + pxEndPoint = FreeRTOS_FindEndPointOnIP_IPv4( 0 ); TEST_ASSERT_EQUAL( &xEndPoint, pxEndPoint ); } @@ -917,7 +917,7 @@ void test_FreeRTOS_FindEndPointOnNetMask_HappyPath( void ) pxNetworkEndPoints = &xEndPoint; /* IPV4_DEFAULT_DNS_SERVER is 192.168.123.1 within the network region. */ - pxEndPoint = FreeRTOS_FindEndPointOnNetMask( IPV4_DEFAULT_DNS_SERVER, 0 ); + pxEndPoint = FreeRTOS_FindEndPointOnNetMask( IPV4_DEFAULT_DNS_SERVER ); TEST_ASSERT_EQUAL( &xEndPoint, pxEndPoint ); } @@ -946,7 +946,7 @@ void test_FreeRTOS_FindEndPointOnNetMask_NotFound( void ) pxNetworkEndPoints = &xEndPoint; /* 192.168.1.1 is 0x0101A8C0. */ - pxEndPoint = FreeRTOS_FindEndPointOnNetMask( 0x0101A8C0, 0 ); + pxEndPoint = FreeRTOS_FindEndPointOnNetMask( 0x0101A8C0 ); TEST_ASSERT_EQUAL( NULL, pxEndPoint ); } @@ -981,7 +981,7 @@ void test_FreeRTOS_InterfaceEndPointOnNetMask_HappyPath( void ) pxNetworkEndPoints = &xEndPoint; /* IPV4_DEFAULT_ADDRESS is 192.168.123.1 within the network region. */ - pxEndPoint = FreeRTOS_InterfaceEndPointOnNetMask( &xNetworkInterface, IPV4_DEFAULT_DNS_SERVER, 0 ); + pxEndPoint = FreeRTOS_InterfaceEndPointOnNetMask( &xNetworkInterface, IPV4_DEFAULT_DNS_SERVER ); TEST_ASSERT_EQUAL( &xEndPoint, pxEndPoint ); } @@ -1016,7 +1016,7 @@ void test_FreeRTOS_InterfaceEndPointOnNetMask_NotFound( void ) pxNetworkEndPoints = &xEndPoint; /* 192.168.122.1 is not in the network region. */ - pxEndPoint = FreeRTOS_InterfaceEndPointOnNetMask( &xNetworkInterface, 0x017AA8C0, 0 ); + pxEndPoint = FreeRTOS_InterfaceEndPointOnNetMask( &xNetworkInterface, 0x017AA8C0 ); TEST_ASSERT_EQUAL( NULL, pxEndPoint ); } diff --git a/test/unit-test/FreeRTOS_Routing_ConfigV4Only/FreeRTOSIPConfig.h b/test/unit-test/FreeRTOS_Routing_ConfigV4Only/FreeRTOSIPConfig.h index 47838e9c67..53c48bdeff 100644 --- a/test/unit-test/FreeRTOS_Routing_ConfigV4Only/FreeRTOSIPConfig.h +++ b/test/unit-test/FreeRTOS_Routing_ConfigV4Only/FreeRTOSIPConfig.h @@ -44,8 +44,6 @@ #define ipconfigCOMPATIBLE_WITH_SINGLE ( 0 ) -#define ipconfigHAS_ROUTING_STATISTICS ( 1 ) - #define ipconfigPROCESS_CUSTOM_ETHERNET_FRAMES ( 1 ) /* Set to 1 to print out debug messages. If ipconfigHAS_DEBUG_PRINTF is set to diff --git a/test/unit-test/FreeRTOS_Sockets/FreeRTOS_Sockets_TCP_API_utest.c b/test/unit-test/FreeRTOS_Sockets/FreeRTOS_Sockets_TCP_API_utest.c index 10933c2af4..5880a45430 100644 --- a/test/unit-test/FreeRTOS_Sockets/FreeRTOS_Sockets_TCP_API_utest.c +++ b/test/unit-test/FreeRTOS_Sockets/FreeRTOS_Sockets_TCP_API_utest.c @@ -128,6 +128,34 @@ void test_FreeRTOS_accept_ClientSocketTaken( void ) pxReturn = FreeRTOS_accept( &xServerSocket, &xAddress, &xAddressLength ); TEST_ASSERT_EQUAL( NULL, pxReturn ); +} + +/** + * @brief Client socket is already taken. + */ +void test_FreeRTOS_accept_PeerSocketNullWithReuseSocket( void ) +{ + FreeRTOS_Socket_t xServerSocket, * pxReturn, xPeerSocket; + struct freertos_sockaddr xAddress; + socklen_t xAddressLength; + + memset( &xServerSocket, 0, sizeof( xServerSocket ) ); + memset( &xPeerSocket, 0, sizeof( xPeerSocket ) ); + + /* Invalid Protocol */ + listLIST_ITEM_CONTAINER_ExpectAnyArgsAndReturn( &xBoundTCPSocketsList ); + xServerSocket.ucProtocol = FREERTOS_IPPROTO_TCP; + xServerSocket.u.xTCP.eTCPState = eTCP_LISTEN; + + xServerSocket.u.xTCP.pxPeerSocket = NULL; + xServerSocket.u.xTCP.bits.bPassAccept = pdTRUE_UNSIGNED; + xServerSocket.u.xTCP.bits.bReuseSocket = pdTRUE_UNSIGNED; + + vTaskSuspendAll_Expect(); + xTaskResumeAll_ExpectAndReturn( pdFALSE ); + + pxReturn = FreeRTOS_accept( &xServerSocket, &xAddress, &xAddressLength ); + TEST_ASSERT_EQUAL( &xServerSocket, pxReturn ); TEST_ASSERT_EQUAL( NULL, xServerSocket.u.xTCP.pxPeerSocket ); } diff --git a/test/unit-test/FreeRTOS_Sockets/FreeRTOS_Sockets_stubs.c b/test/unit-test/FreeRTOS_Sockets/FreeRTOS_Sockets_stubs.c index 34fe7a2c2c..2ac4847522 100644 --- a/test/unit-test/FreeRTOS_Sockets/FreeRTOS_Sockets_stubs.c +++ b/test/unit-test/FreeRTOS_Sockets/FreeRTOS_Sockets_stubs.c @@ -54,6 +54,8 @@ BaseType_t xRNGStatus; BaseType_t xLocalReceiveCallback_Return; uint8_t xLocalReceiveCallback_Called = 0; +BaseType_t xTCPWindowLoggingLevel = 0; + /* ======================== Stub Callback Functions ========================= */ EventBits_t xStubForEventGroupWaitBits( EventGroupHandle_t xEventGroup, diff --git a/test/unit-test/FreeRTOS_Sockets_DiffConfig/FreeRTOS_Sockets_DiffConfig_privates_utest.c b/test/unit-test/FreeRTOS_Sockets_DiffConfig/FreeRTOS_Sockets_DiffConfig_privates_utest.c index 3b612ec210..0c61574b04 100644 --- a/test/unit-test/FreeRTOS_Sockets_DiffConfig/FreeRTOS_Sockets_DiffConfig_privates_utest.c +++ b/test/unit-test/FreeRTOS_Sockets_DiffConfig/FreeRTOS_Sockets_DiffConfig_privates_utest.c @@ -56,7 +56,11 @@ #include "catch_assert.h" -/* ============================== Test Cases ============================== */ +/* ============================ EXTERN VARIABLES ============================ */ + +BaseType_t xTCPWindowLoggingLevel = 0; + +/* =============================== Test Cases =============================== */ /** * @brief Binding successful. diff --git a/test/unit-test/FreeRTOS_Sockets_DiffConfig1/FreeRTOS_Sockets_DiffConfig1_GenericAPI_utest.c b/test/unit-test/FreeRTOS_Sockets_DiffConfig1/FreeRTOS_Sockets_DiffConfig1_GenericAPI_utest.c index c20dba9197..9b43c4c6e1 100644 --- a/test/unit-test/FreeRTOS_Sockets_DiffConfig1/FreeRTOS_Sockets_DiffConfig1_GenericAPI_utest.c +++ b/test/unit-test/FreeRTOS_Sockets_DiffConfig1/FreeRTOS_Sockets_DiffConfig1_GenericAPI_utest.c @@ -53,7 +53,9 @@ /* ============================ EXTERN VARIABLES ============================ */ /* 2001::1 */ -static IPv6_Address_t xIPv6Address = { { 0x20, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01 } }; +static const IPv6_Address_t xIPv6Address = { { 0x20, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01 } }; + +BaseType_t xTCPWindowLoggingLevel = 0; /* ============================== Test Cases ============================== */ @@ -231,7 +233,7 @@ void test_FreeRTOS_connect_SocketValuesNULL_NullDestinationAddress( void ) void test_prvSocketProps_UDPv6() { FreeRTOS_Socket_t xSocket; - IPv6_Address_t * pxIPv6SrcAddress = &xIPv6Address; /* 2001::1 */ + const IPv6_Address_t * pxIPv6SrcAddress = &xIPv6Address; /* 2001::1 */ uint16_t usSrcPort = 1024U; const char * pcReturn; @@ -251,7 +253,7 @@ void test_prvSocketProps_UDPv6() void test_prvSocketProps_TCPv6() { FreeRTOS_Socket_t xSocket; - IPv6_Address_t * pxIPv6SrcAddress = &xIPv6Address; /* 2001::1 */ + const IPv6_Address_t * pxIPv6SrcAddress = &xIPv6Address; /* 2001::1 */ IPv6_Address_t xIPv6RemoteAddress = { { 0x20, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02 } }; /* 2001::2 */ uint16_t usSrcPort = 1024U; uint16_t usRemotePort = 2048U; diff --git a/test/unit-test/FreeRTOS_Sockets_DiffConfig1/FreeRTOS_Sockets_DiffConfig1_TCP_API_utest.c b/test/unit-test/FreeRTOS_Sockets_DiffConfig1/FreeRTOS_Sockets_DiffConfig1_TCP_API_utest.c index 361b05fa1e..03b3687521 100644 --- a/test/unit-test/FreeRTOS_Sockets_DiffConfig1/FreeRTOS_Sockets_DiffConfig1_TCP_API_utest.c +++ b/test/unit-test/FreeRTOS_Sockets_DiffConfig1/FreeRTOS_Sockets_DiffConfig1_TCP_API_utest.c @@ -50,7 +50,9 @@ /* ============================ EXTERN VARIABLES ============================ */ /* 2001::1 */ -static IPv6_Address_t xIPv6Address = { { 0x20, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01 } }; +static const IPv6_Address_t xIPv6Address = { { 0x20, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01 } }; + +BaseType_t xTCPWindowLoggingLevel = 0; /* =============================== Test Cases =============================== */ diff --git a/test/unit-test/FreeRTOS_Sockets_DiffConfig1/FreeRTOS_Sockets_DiffConfig1_UDP_API_utest.c b/test/unit-test/FreeRTOS_Sockets_DiffConfig1/FreeRTOS_Sockets_DiffConfig1_UDP_API_utest.c index 7fe9363774..af3ee7d8fc 100644 --- a/test/unit-test/FreeRTOS_Sockets_DiffConfig1/FreeRTOS_Sockets_DiffConfig1_UDP_API_utest.c +++ b/test/unit-test/FreeRTOS_Sockets_DiffConfig1/FreeRTOS_Sockets_DiffConfig1_UDP_API_utest.c @@ -46,6 +46,8 @@ #define TEST_MAX_UDPV4_PAYLOAD_LENGTH ipconfigNETWORK_MTU - ( ipSIZE_OF_IPv4_HEADER + ipSIZE_OF_UDP_HEADER ) +BaseType_t xTCPWindowLoggingLevel = 0; + /* =============================== Test Cases =============================== */ /** diff --git a/test/unit-test/FreeRTOS_Sockets_DiffConfig1/FreeRTOS_Sockets_DiffConfig1_privates_utest.c b/test/unit-test/FreeRTOS_Sockets_DiffConfig1/FreeRTOS_Sockets_DiffConfig1_privates_utest.c index 45e1968897..752aef9c01 100644 --- a/test/unit-test/FreeRTOS_Sockets_DiffConfig1/FreeRTOS_Sockets_DiffConfig1_privates_utest.c +++ b/test/unit-test/FreeRTOS_Sockets_DiffConfig1/FreeRTOS_Sockets_DiffConfig1_privates_utest.c @@ -54,6 +54,8 @@ BaseType_t prvDetermineSocketSize( BaseType_t xDomain, BaseType_t xProtocol, size_t * pxSocketSize ); +BaseType_t xTCPWindowLoggingLevel = 0; + /* ============================== Test Cases ============================== */ /** diff --git a/test/unit-test/FreeRTOS_TCP_IP/FreeRTOS_TCP_IP_utest.c b/test/unit-test/FreeRTOS_TCP_IP/FreeRTOS_TCP_IP_utest.c index 55d4c112b1..7eee3348c6 100644 --- a/test/unit-test/FreeRTOS_TCP_IP/FreeRTOS_TCP_IP_utest.c +++ b/test/unit-test/FreeRTOS_TCP_IP/FreeRTOS_TCP_IP_utest.c @@ -34,15 +34,14 @@ #include #include -/*#include "mock_task.h" */ -#include "mock_TCP_IP_list_macros.h" +#include "mock_task.h" +#include "mock_list.h" /* This must come after list.h is included (in this case, indirectly * by mock_list.h). */ +#include "mock_TCP_IP_list_macros.h" #include "mock_queue.h" -#include "mock_task.h" #include "mock_event_groups.h" -#include "mock_list.h" #include "mock_FreeRTOS_IP.h" #include "mock_FreeRTOS_IP_Utils.h" @@ -55,7 +54,6 @@ #include "mock_FreeRTOS_UDP_IP.h" #include "mock_FreeRTOS_TCP_Transmission.h" #include "mock_FreeRTOS_TCP_Reception.h" -#include "mock_TCP_IP_list_macros.h" #include "catch_assert.h" @@ -82,6 +80,11 @@ uint8_t ucEthernetBuffer[ ipconfigNETWORK_MTU ] = 0xc3, 0x17 }; +static void test_Helper_ListInitialise( List_t * const pxList ); + +static void test_Helper_ListInsertEnd( List_t * const pxList, + ListItem_t * const pxNewListItem ); + /* ============================== Test Cases ============================== */ /** @@ -692,6 +695,103 @@ void test_vTCPStateChange_ClosedState( void ) TEST_ASSERT_EQUAL( xTickCountAlive, xSocket.u.xTCP.xLastAliveTime ); } +/** + * @brief Test functionality when the state to be reached and the + * current state equal to closed state, with child socket. + */ +void test_vTCPStateChange_ClosedState_ChildSocket( void ) +{ + FreeRTOS_Socket_t xSocket = { 0 }; + FreeRTOS_Socket_t xChildSocket = { 0 }; + enum eTCP_STATE eTCPState; + BaseType_t xTickCountAck = 0xAABBEEDD; + BaseType_t xTickCountAlive = 0xAABBEFDD; + + memset( &xSocket, 0, sizeof( xSocket ) ); + eTCPState = eCLOSED; + xSocket.u.xTCP.pxPeerSocket = &xChildSocket; + xChildSocket.u.xTCP.pxPeerSocket = &xSocket; + + vTaskSuspendAll_Expect(); + xTaskResumeAll_ExpectAndReturn( 0 ); + xTaskGetTickCount_ExpectAndReturn( xTickCountAck ); + xTaskGetTickCount_ExpectAndReturn( xTickCountAlive ); + FreeRTOS_inet_ntop_ExpectAnyArgsAndReturn( NULL ); + + vSocketWakeUpUser_Expect( &xChildSocket ); + + vTCPStateChange( &xSocket, eTCPState ); + + TEST_ASSERT_EQUAL( eCLOSED, xSocket.u.xTCP.eTCPState ); + TEST_ASSERT_EQUAL( xTickCountAck, xSocket.u.xTCP.xLastActTime ); + TEST_ASSERT_EQUAL( pdFALSE_UNSIGNED, xSocket.u.xTCP.bits.bWaitKeepAlive ); + TEST_ASSERT_EQUAL( pdFALSE_UNSIGNED, xSocket.u.xTCP.bits.bSendKeepAlive ); + TEST_ASSERT_EQUAL( 0, xSocket.u.xTCP.ucKeepRepCount ); + TEST_ASSERT_EQUAL( xTickCountAlive, xSocket.u.xTCP.xLastAliveTime ); +} + +/** + * @brief Test functionality when the state to be reached and the + * current state equal to closed state, with child socket. + */ +void test_vTCPStateChange_EstablishedState_ChildSocket2( void ) +{ + FreeRTOS_Socket_t xSocket = { 0 }; + FreeRTOS_Socket_t xSocketParent2 = { 0 }; + FreeRTOS_Socket_t xChildSocket = { 0 }; + enum eTCP_STATE eTCPState; + BaseType_t xTickCountAck = 0xAABBEEDD; + BaseType_t xTickCountAlive = 0xAABBEFDD; + + memset( &xSocket, 0, sizeof( xSocket ) ); + eTCPState = eCLOSED; + xSocket.u.xTCP.pxPeerSocket = &xChildSocket; + xSocket.u.xTCP.eTCPState = eESTABLISHED; + xChildSocket.u.xTCP.pxPeerSocket = &xSocketParent2; + xSocket.u.xTCP.bits.bPassQueued = pdTRUE_UNSIGNED; + xSocket.u.xTCP.bits.bReuseSocket = pdFALSE_UNSIGNED; + + prvTCPSocketIsActive_ExpectAndReturn( xSocket.u.xTCP.eTCPState, pdTRUE ); + vTaskSuspendAll_Expect(); + + ListItem_t xLocalListItem; + FreeRTOS_Socket_t xSocket2; + + memset( &xSocket2, 0, sizeof( xSocket ) ); + + pxSocket = &xSocket; + List_t * pSocketList = &xBoundTCPSocketsList; + ListItem_t NewEntry; + + pxSocket->xBoundSocketListItem.xItemValue = 40000; + pxSocket->xBoundSocketListItem.pvOwner = pxSocket; + pxSocket->ucProtocol = FREERTOS_IPPROTO_UDP; + pxSocket->u.xTCP.bits.bPassAccept = pdTRUE; + + test_Helper_ListInitialise( pSocketList ); + test_Helper_ListInsertEnd( &xBoundTCPSocketsList, &( pxSocket->xBoundSocketListItem ) ); + + xIsCallingFromIPTask_ExpectAndReturn( pdTRUE ); + + vSocketClose_ExpectAnyArgsAndReturn( NULL ); + + xTaskResumeAll_ExpectAndReturn( 0 ); + xTaskGetTickCount_ExpectAndReturn( xTickCountAck ); + xTaskGetTickCount_ExpectAndReturn( xTickCountAlive ); + FreeRTOS_inet_ntop_ExpectAnyArgsAndReturn( NULL ); + + vSocketWakeUpUser_Expect( &xChildSocket ); + + vTCPStateChange( &xSocket, eTCPState ); + + TEST_ASSERT_EQUAL( eCLOSED, xSocket.u.xTCP.eTCPState ); + TEST_ASSERT_EQUAL( xTickCountAck, xSocket.u.xTCP.xLastActTime ); + TEST_ASSERT_EQUAL( pdFALSE_UNSIGNED, xSocket.u.xTCP.bits.bWaitKeepAlive ); + TEST_ASSERT_EQUAL( pdFALSE_UNSIGNED, xSocket.u.xTCP.bits.bSendKeepAlive ); + TEST_ASSERT_EQUAL( 0, xSocket.u.xTCP.ucKeepRepCount ); + TEST_ASSERT_EQUAL( xTickCountAlive, xSocket.u.xTCP.xLastAliveTime ); +} + /** * @brief Test functionality when the state to be reached is closed wait * and current state is equal to connect syn. @@ -956,9 +1056,34 @@ void test_vTCPStateChange_ClosedWaitState_CallingFromIPTask( void ) xSocket.u.xTCP.bits.bPassQueued = pdTRUE_UNSIGNED; vTaskSuspendAll_Expect(); - xTaskResumeAll_ExpectAndReturn( 0 ); + ListItem_t xLocalListItem; + FreeRTOS_Socket_t xSocket2; + + memset( &xSocket2, 0, sizeof( xSocket ) ); + + pxSocket = &xSocket; + List_t * pSocketList = &xBoundTCPSocketsList; + ListItem_t NewEntry; + + pxSocket->xBoundSocketListItem.xItemValue = 40000; + pxSocket->xBoundSocketListItem.pvOwner = pxSocket; + pxSocket->ucProtocol = FREERTOS_IPPROTO_UDP; + pxSocket->u.xTCP.bits.bPassAccept = pdTRUE; + + test_Helper_ListInitialise( pSocketList ); + test_Helper_ListInsertEnd( &xBoundTCPSocketsList, &( pxSocket->xBoundSocketListItem ) ); + + xIsCallingFromIPTask_ExpectAndReturn( pdTRUE ); + /* FIXME: Different behaviour with -fsanitize=address,undefined. */ + if( xSocketToClose != &xSocket ) + { + vSocketClose_ExpectAnyArgsAndReturn( NULL ); + } + + xTaskResumeAll_ExpectAndReturn( 0 ); + xTaskGetTickCount_ExpectAndReturn( xTickCountAck ); xTaskGetTickCount_ExpectAndReturn( xTickCountAlive ); FreeRTOS_inet_ntop_ExpectAnyArgsAndReturn( NULL ); @@ -993,9 +1118,26 @@ void test_vTCPStateChange_ClosedWaitState_NotCallingFromIPTask( void ) xSocket.u.xTCP.bits.bPassQueued = pdTRUE_UNSIGNED; vTaskSuspendAll_Expect(); - xTaskResumeAll_ExpectAndReturn( 0 ); + ListItem_t xLocalListItem; + FreeRTOS_Socket_t xSocket2; + + memset( &xSocket2, 0, sizeof( xSocket ) ); + + pxSocket = &xSocket; + List_t * pSocketList = &xBoundTCPSocketsList; + ListItem_t NewEntry; + + pxSocket->xBoundSocketListItem.xItemValue = 40000; + pxSocket->xBoundSocketListItem.pvOwner = pxSocket; + pxSocket->ucProtocol = FREERTOS_IPPROTO_UDP; + pxSocket->u.xTCP.bits.bPassAccept = pdTRUE; + + test_Helper_ListInitialise( pSocketList ); + test_Helper_ListInsertEnd( &xBoundTCPSocketsList, &( pxSocket->xBoundSocketListItem ) ); + xIsCallingFromIPTask_ExpectAndReturn( pdFALSE ); + catch_assert( vTCPStateChange( &xSocket, eTCPState ) ); } @@ -1017,9 +1159,33 @@ void test_vTCPStateChange_ClosedWaitState_CallingFromIPTask1( void ) xSocket.u.xTCP.bits.bPassAccept = pdTRUE_UNSIGNED; vTaskSuspendAll_Expect(); - xTaskResumeAll_ExpectAndReturn( 0 ); + ListItem_t xLocalListItem; + FreeRTOS_Socket_t xSocket2; + + memset( &xSocket2, 0, sizeof( xSocket ) ); + + pxSocket = &xSocket; + List_t * pSocketList = &xBoundTCPSocketsList; + ListItem_t NewEntry; + + pxSocket->xBoundSocketListItem.xItemValue = 40000; + pxSocket->xBoundSocketListItem.pvOwner = pxSocket; + pxSocket->ucProtocol = FREERTOS_IPPROTO_UDP; + pxSocket->u.xTCP.bits.bPassAccept = pdTRUE; + + test_Helper_ListInitialise( pSocketList ); + test_Helper_ListInsertEnd( &xBoundTCPSocketsList, &( pxSocket->xBoundSocketListItem ) ); + xIsCallingFromIPTask_ExpectAndReturn( pdTRUE ); + /* FIXME: Different behaviour with -fsanitize=address,undefined. */ + if( xSocketToClose != &xSocket ) + { + vSocketClose_ExpectAnyArgsAndReturn( NULL ); + } + + xTaskResumeAll_ExpectAndReturn( 0 ); + xTaskGetTickCount_ExpectAndReturn( xTickCountAck ); xTaskGetTickCount_ExpectAndReturn( xTickCountAlive ); FreeRTOS_inet_ntop_ExpectAnyArgsAndReturn( NULL ); @@ -1052,7 +1218,23 @@ void test_vTCPStateChange_ClosedWaitState_NotCallingFromIPTask1( void ) xSocket.u.xTCP.bits.bPassAccept = pdTRUE_UNSIGNED; vTaskSuspendAll_Expect(); - xTaskResumeAll_ExpectAndReturn( 0 ); + ListItem_t xLocalListItem; + FreeRTOS_Socket_t xSocket2; + + memset( &xSocket2, 0, sizeof( xSocket ) ); + + pxSocket = &xSocket; + List_t * pSocketList = &xBoundTCPSocketsList; + ListItem_t NewEntry; + + pxSocket->xBoundSocketListItem.xItemValue = 40000; + pxSocket->xBoundSocketListItem.pvOwner = pxSocket; + pxSocket->ucProtocol = FREERTOS_IPPROTO_UDP; + pxSocket->u.xTCP.bits.bPassAccept = pdTRUE; + + test_Helper_ListInitialise( pSocketList ); + test_Helper_ListInsertEnd( &xBoundTCPSocketsList, &( pxSocket->xBoundSocketListItem ) ); + xIsCallingFromIPTask_ExpectAndReturn( pdFALSE ); catch_assert( vTCPStateChange( &xSocket, eTCPState ) ); @@ -1438,7 +1620,6 @@ void test_vTCPStateChange_ClosedToEstablishedState_SelectWrite_QueuedBitSet_Pare TEST_ASSERT_EQUAL( 100, xSocket.u.xTCP.usTimeout ); TEST_ASSERT_EQUAL( eSOCKET_ACCEPT, xParentSock.xEventBits ); TEST_ASSERT_EQUAL( &xSocket, xParentSock.u.xTCP.pxPeerSocket ); - TEST_ASSERT_EQUAL( NULL, xSocket.u.xTCP.pxPeerSocket ); TEST_ASSERT_EQUAL( pdFALSE_UNSIGNED, xSocket.u.xTCP.bits.bPassQueued ); TEST_ASSERT_EQUAL( pdTRUE_UNSIGNED, xSocket.u.xTCP.bits.bPassAccept ); } @@ -1491,7 +1672,6 @@ void test_vTCPStateChange_ClosedToEstablishedState_QueuedBitSet_ParentNonNULL_Ha TEST_ASSERT_EQUAL( 100, xSocket.u.xTCP.usTimeout ); TEST_ASSERT_EQUAL( eSOCKET_ACCEPT, xParentSock.xEventBits ); TEST_ASSERT_EQUAL( &xSocket, xParentSock.u.xTCP.pxPeerSocket ); - TEST_ASSERT_EQUAL( NULL, xSocket.u.xTCP.pxPeerSocket ); TEST_ASSERT_EQUAL( pdFALSE_UNSIGNED, xSocket.u.xTCP.bits.bPassQueued ); TEST_ASSERT_EQUAL( pdTRUE_UNSIGNED, xSocket.u.xTCP.bits.bPassAccept ); } @@ -1546,7 +1726,6 @@ void test_vTCPStateChange_ClosedToEstablishedState_QueuedBitSet_ParentNonNULL_Ha TEST_ASSERT_EQUAL( 100, xSocket.u.xTCP.usTimeout ); TEST_ASSERT_EQUAL( eSOCKET_ACCEPT, xParentSock.xEventBits ); TEST_ASSERT_EQUAL( &xSocket, xParentSock.u.xTCP.pxPeerSocket ); - TEST_ASSERT_EQUAL( NULL, xSocket.u.xTCP.pxPeerSocket ); TEST_ASSERT_EQUAL( pdFALSE_UNSIGNED, xSocket.u.xTCP.bits.bPassQueued ); TEST_ASSERT_EQUAL( pdTRUE_UNSIGNED, xSocket.u.xTCP.bits.bPassAccept ); } @@ -1597,7 +1776,6 @@ void test_vTCPStateChange_ClosedToEstablishedState_SelectRead_QueuedBitSet_Paren TEST_ASSERT_EQUAL( 0, xSocket.u.xTCP.ucKeepRepCount ); TEST_ASSERT_EQUAL( xTickCountAlive, xSocket.u.xTCP.xLastAliveTime ); TEST_ASSERT_EQUAL( 100, xSocket.u.xTCP.usTimeout ); - TEST_ASSERT_EQUAL( NULL, xSocket.u.xTCP.pxPeerSocket ); TEST_ASSERT_EQUAL( pdFALSE_UNSIGNED, xSocket.u.xTCP.bits.bPassQueued ); TEST_ASSERT_EQUAL( pdTRUE_UNSIGNED, xSocket.u.xTCP.bits.bPassAccept ); TEST_ASSERT_EQUAL( eSOCKET_ACCEPT | ( eSELECT_READ << SOCKET_EVENT_BIT_COUNT ), xSocket.xEventBits ); @@ -1642,17 +1820,18 @@ void test_xProcessReceivedTCPPacket_Null_Buffer( void ) void test_xProcessReceivedTCPPacket_IPv6_FrameType( void ) { BaseType_t Return = pdFALSE; - EthernetHeader_t xEthHeader; + uint8_t xEthBuffer[ 1500 ] = { 0 }; - pxNetworkBuffer = &xNetworkBuffer; - pxNetworkBuffer->pucEthernetBuffer = ( uint8_t * ) &xEthHeader; + ( ( EthernetHeader_t * ) xEthBuffer )->usFrameType = ipIPv6_FRAME_TYPE; - xEthHeader.usFrameType = ipIPv6_FRAME_TYPE; + pxNetworkBuffer = &xNetworkBuffer; + pxNetworkBuffer->pucEthernetBuffer = xEthBuffer; pxNetworkBuffer->xDataLength = 100; uxIPHeaderSizePacket_ExpectAnyArgsAndReturn( ipSIZE_OF_IPv6_HEADER ); pxTCPSocketLookup_ExpectAnyArgsAndReturn( NULL ); + prvTCPSendReset_ExpectAnyArgsAndReturn( pdTRUE ); Return = xProcessReceivedTCPPacket( pxNetworkBuffer ); @@ -2444,3 +2623,102 @@ void test_xTCPCheckNewClient_Found( void ) TEST_ASSERT_EQUAL( pdTRUE, Return ); TEST_ASSERT_EQUAL_PTR( pxSocket, pxSocket->u.xTCP.pxPeerSocket ); } + +/** + * @brief This function validates the case when the child socket is found in + * the bounded socket list. + */ +void test_vTCPRemoveTCPChild_ChildSocketFound( void ) +{ + BaseType_t Return = pdFALSE; + + ListItem_t xLocalListItem; + FreeRTOS_Socket_t xChildSocket; + + memset( &xChildSocket, 0, sizeof( xSocket ) ); + + pxSocket = &xSocket; + List_t * pSocketList = &xBoundTCPSocketsList; + ListItem_t NewEntry; + + pxSocket->xBoundSocketListItem.xItemValue = 40000; + pxSocket->xBoundSocketListItem.pvOwner = pxSocket; + pxSocket->ucProtocol = FREERTOS_IPPROTO_UDP; + pxSocket->u.xTCP.bits.bPassAccept = pdTRUE; + pxSocket->u.xTCP.pxPeerSocket = &xChildSocket; + + xChildSocket.usLocalPort = FreeRTOS_ntohs( 40000 ); + + test_Helper_ListInitialise( pSocketList ); + test_Helper_ListInsertEnd( &xBoundTCPSocketsList, &( pxSocket->xBoundSocketListItem ) ); + + pxSocket->usLocalPort = FreeRTOS_ntohs( 40000 ); + Return = vTCPRemoveTCPChild( &xChildSocket ); + TEST_ASSERT_EQUAL( pdTRUE, Return ); +} + +/** + * @brief This function validates the case when the child socket is found in + * the bounded socket list but non matching port number. + */ +void test_vTCPRemoveTCPChild_ChildSocketFound_DifferentPortNumber( void ) +{ + BaseType_t Return = pdFALSE; + + ListItem_t xLocalListItem; + FreeRTOS_Socket_t xChildSocket; + + memset( &xChildSocket, 0, sizeof( xSocket ) ); + + pxSocket = &xSocket; + List_t * pSocketList = &xBoundTCPSocketsList; + ListItem_t NewEntry; + + pxSocket->xBoundSocketListItem.xItemValue = 40000; + pxSocket->xBoundSocketListItem.pvOwner = pxSocket; + pxSocket->ucProtocol = FREERTOS_IPPROTO_UDP; + pxSocket->u.xTCP.bits.bPassAccept = pdTRUE; + pxSocket->u.xTCP.pxPeerSocket = &xChildSocket; + + xChildSocket.usLocalPort = FreeRTOS_ntohs( 80000 ); + + test_Helper_ListInitialise( pSocketList ); + test_Helper_ListInsertEnd( &xBoundTCPSocketsList, &( pxSocket->xBoundSocketListItem ) ); + + pxSocket->usLocalPort = FreeRTOS_ntohs( 40000 ); + Return = vTCPRemoveTCPChild( &xChildSocket ); + TEST_ASSERT_EQUAL( pdFALSE, Return ); +} + +/** + * @brief This function validates the case when no child socket is found in + * the bounded socket list but matching port number is present. + */ +void test_vTCPRemoveTCPChild_NoChildSocketFound_MatchingPortNumber( void ) +{ + BaseType_t Return = pdFALSE; + + ListItem_t xLocalListItem; + FreeRTOS_Socket_t xChildSocket; + + memset( &xChildSocket, 0, sizeof( xSocket ) ); + + pxSocket = &xSocket; + List_t * pSocketList = &xBoundTCPSocketsList; + ListItem_t NewEntry; + + pxSocket->xBoundSocketListItem.xItemValue = 40000; + pxSocket->xBoundSocketListItem.pvOwner = pxSocket; + pxSocket->ucProtocol = FREERTOS_IPPROTO_UDP; + pxSocket->u.xTCP.bits.bPassAccept = pdTRUE; + pxSocket->u.xTCP.pxPeerSocket = NULL; + + xChildSocket.usLocalPort = FreeRTOS_ntohs( 40000 ); + + test_Helper_ListInitialise( pSocketList ); + test_Helper_ListInsertEnd( &xBoundTCPSocketsList, &( pxSocket->xBoundSocketListItem ) ); + + pxSocket->usLocalPort = FreeRTOS_ntohs( 40000 ); + Return = vTCPRemoveTCPChild( &xChildSocket ); + TEST_ASSERT_EQUAL( pdFALSE, Return ); +} diff --git a/test/unit-test/FreeRTOS_TCP_IP/TCP_IP_list_macros.h b/test/unit-test/FreeRTOS_TCP_IP/TCP_IP_list_macros.h index 97fb8f8eb4..0ed60a2064 100644 --- a/test/unit-test/FreeRTOS_TCP_IP/TCP_IP_list_macros.h +++ b/test/unit-test/FreeRTOS_TCP_IP/TCP_IP_list_macros.h @@ -29,9 +29,13 @@ #define LIST_MACRO_H #include +#include #include #include +#undef listGET_HEAD_ENTRY +ListItem_t * listGET_HEAD_ENTRY( List_t * pxList ); + #undef listSET_LIST_ITEM_OWNER void listSET_LIST_ITEM_OWNER( ListItem_t * pxListItem, void * owner ); diff --git a/test/unit-test/FreeRTOS_TCP_State_Handling/FreeRTOS_TCP_State_Handling_utest.c b/test/unit-test/FreeRTOS_TCP_State_Handling/FreeRTOS_TCP_State_Handling_utest.c index 41cd1a78ce..b65fb12698 100644 --- a/test/unit-test/FreeRTOS_TCP_State_Handling/FreeRTOS_TCP_State_Handling_utest.c +++ b/test/unit-test/FreeRTOS_TCP_State_Handling/FreeRTOS_TCP_State_Handling_utest.c @@ -1800,6 +1800,7 @@ void test_prvTCPSocketCopy_BindError( void ) pxSocket->u.xTCP.uxTxWinSize = 0x123456; pxSocket->pxSocketSet = ( struct xSOCKET_SET * ) 0x1111111; pxSocket->xSelectBits = eSELECT_READ; + pxSocket->u.xTCP.pxPeerSocket = &MockReturnSocket; FreeRTOS_GetLocalAddress_ExpectAndReturn( pxSocket, NULL, pdTRUE ); FreeRTOS_GetLocalAddress_IgnoreArg_pxAddress(); @@ -1811,6 +1812,7 @@ void test_prvTCPSocketCopy_BindError( void ) TEST_ASSERT_NOT_EQUAL( pxSocket->usLocalPort, MockReturnSocket.usLocalPort ); TEST_ASSERT_EQUAL( pxSocket->u.xTCP.uxTxWinSize, MockReturnSocket.u.xTCP.uxTxWinSize ); TEST_ASSERT_EQUAL( ( pxSocket->xSelectBits | eSELECT_READ | eSELECT_EXCEPT ), MockReturnSocket.xSelectBits ); + TEST_ASSERT_EQUAL( pxSocket->u.xTCP.pxPeerSocket, &MockReturnSocket ); } /** diff --git a/test/unit-test/FreeRTOS_TCP_State_Handling_IPv4/FreeRTOS_TCP_State_Handling_IPv4_utest.c b/test/unit-test/FreeRTOS_TCP_State_Handling_IPv4/FreeRTOS_TCP_State_Handling_IPv4_utest.c index acf161694a..03d81f9f32 100644 --- a/test/unit-test/FreeRTOS_TCP_State_Handling_IPv4/FreeRTOS_TCP_State_Handling_IPv4_utest.c +++ b/test/unit-test/FreeRTOS_TCP_State_Handling_IPv4/FreeRTOS_TCP_State_Handling_IPv4_utest.c @@ -122,7 +122,7 @@ void test_prvHandleListen_IPV4_ReuseSocket( void ) ulApplicationGetNextSequenceNumber_ExpectAnyArgsAndReturn( 1000 ); uxIPHeaderSizePacket_ExpectAndReturn( pxNetworkBuffer, ipSIZE_OF_IPv4_HEADER ); prvSocketSetMSS_ExpectAnyArgs(); - prvTCPCreateWindow_ExpectAnyArgs(); + prvTCPCreateWindow_ExpectAnyArgsAndReturn( pdPASS ); vTCPStateChange_Ignore(); pxReturn = prvHandleListen_IPV4( pxSocket, pxNetworkBuffer ); @@ -131,6 +131,38 @@ void test_prvHandleListen_IPV4_ReuseSocket( void ) TEST_ASSERT_EQUAL( 1000, pxReturn->u.xTCP.xTCPWindow.ulOurSequenceNumber ); } +/** + * @brief Flag of reuse socket is enabled and create TCP window failed. + */ +void test_prvHandleListen_IPV4_ReuseSocket_CreateWindowFailed( void ) +{ + FreeRTOS_Socket_t * pxReturn = NULL; + NetworkEndPoint_t xEndPoint = { 0 }; + + xEndPoint.ipv4_settings.ulIPAddress = 0x0800a8c0; + + pxSocket = &xSocket; + + pxNetworkBuffer = &xNetworkBuffer; + pxNetworkBuffer->pucEthernetBuffer = ucEthernetBuffer; + pxNetworkBuffer->pxEndPoint = &xEndPoint; + + TCPPacket_t * pxTCPPacket = ( ( TCPPacket_t * ) pxNetworkBuffer->pucEthernetBuffer ); + pxTCPPacket->xIPHeader.ulDestinationIPAddress = 0x0800a8c0; + + pxSocket->u.xTCP.bits.bReuseSocket = pdTRUE; + + ulApplicationGetNextSequenceNumber_ExpectAnyArgsAndReturn( 1000 ); + uxIPHeaderSizePacket_ExpectAndReturn( pxNetworkBuffer, ipSIZE_OF_IPv4_HEADER ); + prvSocketSetMSS_ExpectAnyArgs(); + prvTCPCreateWindow_ExpectAnyArgsAndReturn( pdFAIL ); + vTCPStateChange_Ignore(); + + pxReturn = prvHandleListen_IPV4( pxSocket, pxNetworkBuffer ); + + TEST_ASSERT_EQUAL( NULL, pxReturn ); +} + /** * @brief Number of child socket is beyond limitation. */ @@ -191,7 +223,7 @@ void test_prvHandleListen_IPV4_NewSocketGood( void ) prvTCPSocketCopy_ExpectAndReturn( &MockReturnSocket, pxSocket, pdTRUE ); uxIPHeaderSizePacket_ExpectAndReturn( pxNetworkBuffer, ipSIZE_OF_IPv4_HEADER ); prvSocketSetMSS_ExpectAnyArgs(); - prvTCPCreateWindow_ExpectAnyArgs(); + prvTCPCreateWindow_ExpectAnyArgsAndReturn( pdPASS ); vTCPStateChange_ExpectAnyArgs(); pxReturn = prvHandleListen_IPV4( pxSocket, pxNetworkBuffer ); @@ -200,6 +232,43 @@ void test_prvHandleListen_IPV4_NewSocketGood( void ) TEST_ASSERT_EQUAL( 1000, pxReturn->u.xTCP.xTCPWindow.ulOurSequenceNumber ); } +/** + * @brief Create TCP window failed. + */ +void test_prvHandleListen_IPV4_NewSocket_CreateWindowFailed( void ) +{ + FreeRTOS_Socket_t * pxReturn = NULL; + FreeRTOS_Socket_t MockReturnSocket; + NetworkEndPoint_t xEndPoint = { 0 }; + + xEndPoint.ipv4_settings.ulIPAddress = 0x0800a8c0; + + pxSocket = &xSocket; + + pxNetworkBuffer = &xNetworkBuffer; + pxNetworkBuffer->pucEthernetBuffer = ucEthernetBuffer; + pxNetworkBuffer->pxEndPoint = &xEndPoint; + + TCPPacket_t * pxTCPPacket = ( ( TCPPacket_t * ) pxNetworkBuffer->pucEthernetBuffer ); + pxTCPPacket->xIPHeader.ulDestinationIPAddress = 0x0800a8c0; + + pxSocket->u.xTCP.bits.bReuseSocket = pdFALSE; + pxSocket->u.xTCP.usChildCount = 1; + pxSocket->u.xTCP.usBacklog = 9; + + ulApplicationGetNextSequenceNumber_ExpectAnyArgsAndReturn( 1000 ); + FreeRTOS_socket_ExpectAnyArgsAndReturn( &MockReturnSocket ); + prvTCPSocketCopy_ExpectAndReturn( &MockReturnSocket, pxSocket, pdTRUE ); + uxIPHeaderSizePacket_ExpectAndReturn( pxNetworkBuffer, ipSIZE_OF_IPv4_HEADER ); + prvSocketSetMSS_ExpectAnyArgs(); + prvTCPCreateWindow_ExpectAnyArgsAndReturn( pdFAIL ); + vSocketClose_ExpectAndReturn( &MockReturnSocket, NULL ); + + pxReturn = prvHandleListen_IPV4( pxSocket, pxNetworkBuffer ); + + TEST_ASSERT_EQUAL( NULL, pxReturn ); +} + /** * @brief Happy path with valid data length. */ @@ -230,7 +299,7 @@ void test_prvHandleListen_IPV4_NewSocketGoodValidDataLength( void ) prvTCPSocketCopy_ExpectAndReturn( &MockReturnSocket, pxSocket, pdTRUE ); uxIPHeaderSizePacket_ExpectAndReturn( pxNetworkBuffer, ipSIZE_OF_IPv4_HEADER ); prvSocketSetMSS_ExpectAnyArgs(); - prvTCPCreateWindow_ExpectAnyArgs(); + prvTCPCreateWindow_ExpectAnyArgsAndReturn( pdPASS ); vTCPStateChange_ExpectAnyArgs(); pxReturn = prvHandleListen_IPV4( pxSocket, pxNetworkBuffer ); diff --git a/test/unit-test/FreeRTOS_TCP_State_Handling_IPv6/FreeRTOS_TCP_State_Handling_IPv6_utest.c b/test/unit-test/FreeRTOS_TCP_State_Handling_IPv6/FreeRTOS_TCP_State_Handling_IPv6_utest.c index 0c0897b309..2c7b2499db 100644 --- a/test/unit-test/FreeRTOS_TCP_State_Handling_IPv6/FreeRTOS_TCP_State_Handling_IPv6_utest.c +++ b/test/unit-test/FreeRTOS_TCP_State_Handling_IPv6/FreeRTOS_TCP_State_Handling_IPv6_utest.c @@ -201,7 +201,7 @@ void test_prvHandleListen_IPV6_ReuseSocket( void ) uxIPHeaderSizePacket_ExpectAndReturn( pxNetworkBuffer, ipSIZE_OF_IPv6_HEADER ); prvSocketSetMSS_ExpectAnyArgs(); - prvTCPCreateWindow_ExpectAnyArgs(); + prvTCPCreateWindow_ExpectAnyArgsAndReturn( pdPASS ); vTCPStateChange_Expect( NULL, eSYN_FIRST ); vTCPStateChange_IgnoreArg_pxSocket(); @@ -210,6 +210,42 @@ void test_prvHandleListen_IPV6_ReuseSocket( void ) TEST_ASSERT_EQUAL( pxSocket, pxReturn ); } +/** + * @brief Reuse bit is set in socket handler but the TCP window creation + * fails. + */ +void test_prvHandleListen_IPV6_ReuseSocket_CreateWindowFails( void ) +{ + FreeRTOS_Socket_t * pxReturn; + TCPPacket_IPv6_t * pxTCPPacket = NULL; + uint32_t ulRandomReturn = 0x12345678; + + pxSocket = &xSocket; + pxNetworkBuffer = &xNetworkBuffer; + pxEndPoint = &xEndPoint; + + pxNetworkBuffer->pucEthernetBuffer = pucEthernetBuffer; + pxNetworkBuffer->pxEndPoint = pxEndPoint; + + /* Set same IPv6 address to endpoint & buffer. */ + pxTCPPacket = ( TCPPacket_IPv6_t * ) pxNetworkBuffer->pucEthernetBuffer; + memcpy( pxTCPPacket->xIPHeader.xDestinationAddress.ucBytes, xIPv6Address.ucBytes, ipSIZE_OF_IPv6_ADDRESS ); + memcpy( pxEndPoint->ipv6_settings.xIPAddress.ucBytes, xIPv6Address.ucBytes, ipSIZE_OF_IPv6_ADDRESS ); + + xApplicationGetRandomNumber_ExpectAnyArgsAndReturn( pdPASS ); + xApplicationGetRandomNumber_ReturnMemThruPtr_pulNumber( &ulRandomReturn, sizeof( ulRandomReturn ) ); + + pxSocket->u.xTCP.bits.bReuseSocket = pdTRUE; + + uxIPHeaderSizePacket_ExpectAndReturn( pxNetworkBuffer, ipSIZE_OF_IPv6_HEADER ); + prvSocketSetMSS_ExpectAnyArgs(); + prvTCPCreateWindow_ExpectAnyArgsAndReturn( pdFAIL ); + + pxReturn = prvHandleListen_IPV6( pxSocket, pxNetworkBuffer ); + + TEST_ASSERT_EQUAL( NULL, pxReturn ); +} + /** * @brief Number of child socket is beyond limitation. */ @@ -396,7 +432,7 @@ void test_prvHandleListen_IPV6_NewSocketGood( void ) prvTCPSocketCopy_ExpectAndReturn( pxChildSocket, pxSocket, pdTRUE ); uxIPHeaderSizePacket_ExpectAndReturn( pxNetworkBuffer, ipSIZE_OF_IPv6_HEADER ); prvSocketSetMSS_ExpectAnyArgs(); - prvTCPCreateWindow_ExpectAnyArgs(); + prvTCPCreateWindow_ExpectAnyArgsAndReturn( pdPASS ); vTCPStateChange_Expect( NULL, eSYN_FIRST ); vTCPStateChange_IgnoreArg_pxSocket(); @@ -408,6 +444,54 @@ void test_prvHandleListen_IPV6_NewSocketGood( void ) TEST_ASSERT_EQUAL_MEMORY( xIPv6Address.ucBytes, pxReturn->u.xTCP.xRemoteIP.xIP_IPv6.ucBytes, ipSIZE_OF_IPv6_ADDRESS ); } +/** + * @brief Create TCP window fails + */ +void test_prvHandleListen_IPV6_CreateWindowFails( void ) +{ + FreeRTOS_Socket_t * pxReturn; + TCPPacket_IPv6_t * pxTCPPacket = NULL; + uint32_t ulRandomReturn = 0x12345678; + FreeRTOS_Socket_t xChildSocket, * pxChildSocket; + uint16_t usSrcPort = 0x1234; + + pxSocket = &xSocket; + pxNetworkBuffer = &xNetworkBuffer; + pxEndPoint = &xEndPoint; + + pxNetworkBuffer->pucEthernetBuffer = pucEthernetBuffer; + pxNetworkBuffer->pxEndPoint = pxEndPoint; + + /* Set same IPv6 address to endpoint & buffer. */ + pxTCPPacket = ( TCPPacket_IPv6_t * ) pxNetworkBuffer->pucEthernetBuffer; + pxTCPPacket->xTCPHeader.usSourcePort = FreeRTOS_htons( usSrcPort ); + memcpy( pxTCPPacket->xIPHeader.xSourceAddress.ucBytes, xIPv6Address.ucBytes, ipSIZE_OF_IPv6_ADDRESS ); + memcpy( pxTCPPacket->xIPHeader.xDestinationAddress.ucBytes, xIPv6Address.ucBytes, ipSIZE_OF_IPv6_ADDRESS ); + memcpy( pxEndPoint->ipv6_settings.xIPAddress.ucBytes, xIPv6Address.ucBytes, ipSIZE_OF_IPv6_ADDRESS ); + + xApplicationGetRandomNumber_ExpectAnyArgsAndReturn( pdPASS ); + xApplicationGetRandomNumber_ReturnMemThruPtr_pulNumber( &ulRandomReturn, sizeof( ulRandomReturn ) ); + + pxSocket->u.xTCP.bits.bReuseSocket = pdFALSE; + pxSocket->u.xTCP.usChildCount = 1; + pxSocket->u.xTCP.usBacklog = 9; + + memset( &xChildSocket, 0, sizeof( xChildSocket ) ); + pxChildSocket = &xChildSocket; + + FreeRTOS_socket_ExpectAndReturn( FREERTOS_AF_INET6, FREERTOS_SOCK_STREAM, FREERTOS_IPPROTO_TCP, pxChildSocket ); + prvTCPSocketCopy_ExpectAndReturn( pxChildSocket, pxSocket, pdTRUE ); + uxIPHeaderSizePacket_ExpectAndReturn( pxNetworkBuffer, ipSIZE_OF_IPv6_HEADER ); + prvSocketSetMSS_ExpectAnyArgs(); + prvTCPCreateWindow_ExpectAnyArgsAndReturn( pdFAIL ); + vSocketClose_ExpectAndReturn( pxChildSocket, NULL ); + + pxReturn = prvHandleListen_IPV6( pxSocket, pxNetworkBuffer ); + + TEST_ASSERT_EQUAL( NULL, pxReturn ); +} + + /** * @brief Happy path with valid data length. */ @@ -448,7 +532,7 @@ void test_prvHandleListen_IPV6_NewSocketGoodValidDataLength( void ) prvTCPSocketCopy_ExpectAndReturn( pxChildSocket, pxSocket, pdTRUE ); uxIPHeaderSizePacket_ExpectAndReturn( pxNetworkBuffer, ipSIZE_OF_IPv6_HEADER ); prvSocketSetMSS_ExpectAnyArgs(); - prvTCPCreateWindow_ExpectAnyArgs(); + prvTCPCreateWindow_ExpectAnyArgsAndReturn( pdPASS ); vTCPStateChange_Expect( NULL, eSYN_FIRST ); vTCPStateChange_IgnoreArg_pxSocket(); diff --git a/test/unit-test/FreeRTOS_TCP_Transmission/FreeRTOS_TCP_Transmission_utest.c b/test/unit-test/FreeRTOS_TCP_Transmission/FreeRTOS_TCP_Transmission_utest.c index 667eabe09c..4980db9eb4 100644 --- a/test/unit-test/FreeRTOS_TCP_Transmission/FreeRTOS_TCP_Transmission_utest.c +++ b/test/unit-test/FreeRTOS_TCP_Transmission/FreeRTOS_TCP_Transmission_utest.c @@ -107,7 +107,7 @@ void test_prvTCPMakeSurePrepared_NotPrepared( void ) eARPGetCacheEntry_ExpectAnyArgsAndReturn( eResolutionCacheHit ); ulApplicationGetNextSequenceNumber_ExpectAnyArgsAndReturn( 1000 ); prvSocketSetMSS_ExpectAnyArgs(); - vTCPWindowCreate_ExpectAnyArgs(); + xTCPWindowCreate_ExpectAnyArgsAndReturn( pdPASS ); xResult = prvTCPMakeSurePrepared( pxSocket ); TEST_ASSERT_EQUAL( pdTRUE, xResult ); @@ -813,6 +813,7 @@ void test_prvTCPReturnPacket_No_KL( void ) pxTCPPacket->xTCPHeader.ulAckNr = 0; pxSocket->pxEndPoint = &xEndPoint; pxEndPoint = &xEndPoint; + pxNetworkBuffer->pxEndPoint = &xEndPoint; uxIPHeaderSizePacket_IgnoreAndReturn( ipSIZE_OF_IPv4_HEADER ); uxStreamBufferFrontSpace_ExpectAnyArgsAndReturn( 1000 ); @@ -867,6 +868,7 @@ void test_prvTCPReturnPacket_No_KL_LocalIP( void ) pxTCPPacket->xTCPHeader.ulAckNr = 0; pxSocket->pxEndPoint = &xEndPoint; pxEndPoint = &xEndPoint; + pxNetworkBuffer->pxEndPoint = &xEndPoint; uxIPHeaderSizePacket_IgnoreAndReturn( ipSIZE_OF_IPv4_HEADER ); uxStreamBufferFrontSpace_ExpectAnyArgsAndReturn( 1000 ); @@ -927,6 +929,7 @@ void test_prvTCPReturnPacket_No_KL_LocalIP_GT_Eth_Packet_Length( void ) pxTCPWindow->rx.ulCurrentSequenceNumber = 50; pxTCPPacket->xTCPHeader.ulAckNr = 0; pxEndPoint = &xEndPoint; + pxNetworkBuffer->pxEndPoint = &xEndPoint; uxIPHeaderSizePacket_IgnoreAndReturn( ipSIZE_OF_IPv4_HEADER ); uxStreamBufferFrontSpace_ExpectAnyArgsAndReturn( 1000 ); @@ -966,6 +969,7 @@ void test_prvTCPReturnPacket_No_KL_LocalIP_ARP_Not_Hit( void ) xEndPoint.pxNetworkInterface->pfOutput = &NetworkInterfaceOutputFunction_Stub; NetworkInterfaceOutputFunction_Stub_Called = 0; pxSocket->pxEndPoint = &xEndPoint; + pxNetworkBuffer->pxEndPoint = &xEndPoint; pxSocket->u.xTCP.rxStream = ( StreamBuffer_t * ) 0x12345678; pxSocket->u.xTCP.uxRxStreamSize = 1500; @@ -1035,6 +1039,7 @@ void test_prvTCPReturnPacket_No_KL_Fin_Suppress_Rx_Stop( void ) pxTCPPacket->xTCPHeader.ulAckNr = 0; pxTCPPacket->xTCPHeader.ucTCPFlags = tcpTCP_FLAG_FIN; pxEndPoint = &xEndPoint; + pxNetworkBuffer->pxEndPoint = &xEndPoint; uxIPHeaderSizeSocket_IgnoreAndReturn( ipSIZE_OF_IPv4_HEADER ); uxIPHeaderSizePacket_IgnoreAndReturn( ipSIZE_OF_IPv4_HEADER ); @@ -1086,6 +1091,7 @@ void test_prvTCPReturnPacket_No_KL_Fin_Not_Suppress_Low_Water( void ) pxTCPPacket->xTCPHeader.ulAckNr = 0; pxTCPPacket->xTCPHeader.ucTCPFlags = tcpTCP_FLAG_FIN; pxEndPoint = &xEndPoint; + pxNetworkBuffer->pxEndPoint = &xEndPoint; uxIPHeaderSizeSocket_IgnoreAndReturn( ipSIZE_OF_IPv4_HEADER ); uxIPHeaderSizePacket_IgnoreAndReturn( ipSIZE_OF_IPv4_HEADER ); @@ -1137,6 +1143,7 @@ void test_prvTCPReturnPacket_No_KL_Fin_Not_Suppress_Big_Win( void ) pxTCPPacket->xTCPHeader.ulAckNr = 0; pxTCPPacket->xTCPHeader.ucTCPFlags = tcpTCP_FLAG_FIN; pxEndPoint = &xEndPoint; + pxNetworkBuffer->pxEndPoint = &xEndPoint; uxIPHeaderSizeSocket_IgnoreAndReturn( ipSIZE_OF_IPv4_HEADER ); uxIPHeaderSizePacket_IgnoreAndReturn( ipSIZE_OF_IPv4_HEADER ); @@ -1186,7 +1193,7 @@ void test_prvTCPPrepareConnect_Ready( void ) eARPGetCacheEntry_ExpectAnyArgsAndReturn( eResolutionCacheHit ); ulApplicationGetNextSequenceNumber_ExpectAnyArgsAndReturn( 0x11111111 ); prvSocketSetMSS_ExpectAnyArgs(); - vTCPWindowCreate_ExpectAnyArgs(); + xTCPWindowCreate_ExpectAnyArgsAndReturn( pdPASS ); Return = prvTCPPrepareConnect( pxSocket ); TEST_ASSERT_EQUAL( pdTRUE, Return ); @@ -1194,6 +1201,26 @@ void test_prvTCPPrepareConnect_Ready( void ) TEST_ASSERT_EQUAL( 0, pxSocket->u.xTCP.ucRepCount ); } +/* test for prvTCPPrepareConnect function, TCP window creation fails. */ +void test_prvTCPPrepareConnect_Ready_TCPWindowCreateFail( void ) +{ + BaseType_t Return = pdFALSE; + + pxSocket = &xSocket; + + pxSocket->u.xTCP.ucRepCount = 0; + pxSocket->u.xTCP.bits.bConnPrepared = pdFALSE; + pxSocket->bits.bIsIPv6 = pdFALSE; + + eARPGetCacheEntry_ExpectAnyArgsAndReturn( eARPCacheHit ); + ulApplicationGetNextSequenceNumber_ExpectAnyArgsAndReturn( 0x11111111 ); + prvSocketSetMSS_ExpectAnyArgs(); + xTCPWindowCreate_ExpectAnyArgsAndReturn( pdFAIL ); + + Return = prvTCPPrepareConnect( pxSocket ); + TEST_ASSERT_EQUAL( pdFAIL, Return ); +} + /* test for prvTCPPrepareConnect function */ void test_prvTCPPrepareConnect_No_Arp_Entry( void ) { @@ -2151,6 +2178,7 @@ void test_prvSendData_AckMsg_Not_Null_Small_Length( void ) pxTCPWindow->rx.ulCurrentSequenceNumber = 50; pxTCPPacket->xTCPHeader.ulAckNr = 0; pxEndPoint = &xEndPoint; + pxNetworkBuffer->pxEndPoint = &xEndPoint; uxIPHeaderSizePacket_IgnoreAndReturn( ipSIZE_OF_IPv4_HEADER ); vReleaseNetworkBufferAndDescriptor_ExpectAnyArgs(); @@ -2207,7 +2235,7 @@ void test_prvSendData_AckMsg_Not_Null_Same_NetBuffer_Syn_State( void ) pxTCPWindow->rx.ulCurrentSequenceNumber = 50; pxTCPPacket->xTCPHeader.ulAckNr = 0; pxEndPoint = &xEndPoint; - + pxNetworkBuffer->pxEndPoint = &xEndPoint; uxIPHeaderSizePacket_IgnoreAndReturn( ipSIZE_OF_IPv4_HEADER ); uxStreamBufferFrontSpace_ExpectAnyArgsAndReturn( 1000 ); @@ -2263,6 +2291,7 @@ void test_prvSendData_AckMsg_Not_Null_Same_NetBuffer_Syn_State_Data_To_Send( voi pxTCPWindow->rx.ulCurrentSequenceNumber = 50; pxTCPPacket->xTCPHeader.ulAckNr = 0; pxEndPoint = &xEndPoint; + pxNetworkBuffer->pxEndPoint = &xEndPoint; uxIPHeaderSizePacket_IgnoreAndReturn( ipSIZE_OF_IPv4_HEADER ); uxStreamBufferFrontSpace_ExpectAnyArgsAndReturn( 1000 ); @@ -2318,6 +2347,7 @@ void test_prvSendData_AckMsg_Null_Syn_State_Data_To_Send( void ) pxTCPWindow->rx.ulCurrentSequenceNumber = 50; pxTCPPacket->xTCPHeader.ulAckNr = 0; pxEndPoint = &xEndPoint; + pxNetworkBuffer->pxEndPoint = &xEndPoint; uxIPHeaderSizePacket_IgnoreAndReturn( ipSIZE_OF_IPv4_HEADER ); uxStreamBufferFrontSpace_ExpectAnyArgsAndReturn( 1000 ); @@ -2374,6 +2404,7 @@ void test_prvSendData_AckMsg_Null_Syn_State_Data_To_Send_Log( void ) pxTCPWindow->rx.ulCurrentSequenceNumber = 50; pxTCPPacket->xTCPHeader.ulAckNr = 0; pxEndPoint = &xEndPoint; + pxNetworkBuffer->pxEndPoint = &xEndPoint; uxIPHeaderSizePacket_IgnoreAndReturn( ipSIZE_OF_IPv4_HEADER ); uxStreamBufferFrontSpace_ExpectAnyArgsAndReturn( 1000 ); @@ -2430,6 +2461,7 @@ void test_prvSendData_AckMsg_Null_Syn_State_Data_To_Send_Rcv_Zero( void ) pxTCPWindow->rx.ulCurrentSequenceNumber = 50; pxTCPPacket->xTCPHeader.ulAckNr = 0; pxEndPoint = &xEndPoint; + pxNetworkBuffer->pxEndPoint = &xEndPoint; uxIPHeaderSizePacket_IgnoreAndReturn( ipSIZE_OF_IPv4_HEADER ); uxStreamBufferFrontSpace_ExpectAnyArgsAndReturn( 1000 ); diff --git a/test/unit-test/FreeRTOS_TCP_Transmission/TCP_Transmission_list_macros.h b/test/unit-test/FreeRTOS_TCP_Transmission/TCP_Transmission_list_macros.h index b59f487a75..1db6ff4328 100644 --- a/test/unit-test/FreeRTOS_TCP_Transmission/TCP_Transmission_list_macros.h +++ b/test/unit-test/FreeRTOS_TCP_Transmission/TCP_Transmission_list_macros.h @@ -50,9 +50,7 @@ NetworkEndPoint_t * FreeRTOS_FindEndPointOnIP_IPv6( const IPv6_Address_t * pxIPA /* * Find the best fitting end-point to reach a given IP-address. * Find an end-point whose IP-address is in the same network as the IP-address provided. - * 'ulWhere' is temporary and or debugging only. */ -NetworkEndPoint_t * FreeRTOS_FindEndPointOnNetMask( uint32_t ulIPAddress, - uint32_t ulWhere ); +NetworkEndPoint_t * FreeRTOS_FindEndPointOnNetMask( uint32_t ulIPAddress ); #endif /* ifndef LIST_MACRO_H */ diff --git a/test/unit-test/FreeRTOS_TCP_Transmission_IPv6/FreeRTOS_TCP_Transmission_IPv6_stubs.c b/test/unit-test/FreeRTOS_TCP_Transmission_IPv6/FreeRTOS_TCP_Transmission_IPv6_stubs.c index 63e4450285..b53a945ee6 100644 --- a/test/unit-test/FreeRTOS_TCP_Transmission_IPv6/FreeRTOS_TCP_Transmission_IPv6_stubs.c +++ b/test/unit-test/FreeRTOS_TCP_Transmission_IPv6/FreeRTOS_TCP_Transmission_IPv6_stubs.c @@ -71,13 +71,6 @@ void prvTCPReturn_SetSequenceNumber( FreeRTOS_Socket_t * pxSocket, { } -/* - * Initialise the data structures which keep track of the TCP windowing system. - */ -void prvTCPCreateWindow( FreeRTOS_Socket_t * pxSocket ) -{ -} - /* * Return or send a packet to the other party. */ diff --git a/test/unit-test/FreeRTOS_TCP_Transmission_IPv6/FreeRTOS_TCP_Transmission_IPv6_utest.c b/test/unit-test/FreeRTOS_TCP_Transmission_IPv6/FreeRTOS_TCP_Transmission_IPv6_utest.c index 55f0daa5be..b840ebb61b 100644 --- a/test/unit-test/FreeRTOS_TCP_Transmission_IPv6/FreeRTOS_TCP_Transmission_IPv6_utest.c +++ b/test/unit-test/FreeRTOS_TCP_Transmission_IPv6/FreeRTOS_TCP_Transmission_IPv6_utest.c @@ -46,6 +46,8 @@ #include "mock_FreeRTOS_TCP_Utils.h" #include "mock_FreeRTOS_TCP_State_Handling.h" #include "mock_FreeRTOS_ND.h" +#include "mock_TCP_Transmission_IPv6_list_macros.h" + #include "FreeRTOS_TCP_Transmission.h" #include "FreeRTOS_TCP_Transmission_IPv6_stubs.c" @@ -462,6 +464,7 @@ void test_prvTCPPrepareConnect_IPV6_CacheMiss_ValidEP( void ) pxGetNetworkBufferWithDescriptor_ExpectAnyArgsAndReturn( NULL ); prvSocketSetMSS_ExpectAnyArgs(); + prvTCPCreateWindow_ExpectAnyArgsAndReturn( pdPASS ); xReturn = prvTCPPrepareConnect_IPV6( pxSocket ); @@ -490,6 +493,7 @@ void test_prvTCPPrepareConnect_IPV6_DefaultCase_ValidEP( void ) vNDSendNeighbourSolicitation_ExpectAnyArgs(); prvSocketSetMSS_ExpectAnyArgs(); + prvTCPCreateWindow_ExpectAnyArgsAndReturn( pdPASS ); xReturn = prvTCPPrepareConnect_IPV6( pxSocket ); @@ -519,6 +523,7 @@ void test_prvTCPPrepareConnect_IPV6_HappyPath_IPv4( void ) ulApplicationGetNextSequenceNumber_ExpectAnyArgsAndReturn( 10 ); prvSocketSetMSS_ExpectAnyArgs(); + prvTCPCreateWindow_ExpectAnyArgsAndReturn( pdPASS ); xReturn = prvTCPPrepareConnect_IPV6( pxSocket ); @@ -547,6 +552,7 @@ void test_prvTCPPrepareConnect_IPV6_HappyPath_IPv6( void ) ulApplicationGetNextSequenceNumber_ExpectAnyArgsAndReturn( 10 ); prvSocketSetMSS_ExpectAnyArgs(); + prvTCPCreateWindow_ExpectAnyArgsAndReturn( pdPASS ); xReturn = prvTCPPrepareConnect_IPV6( pxSocket ); @@ -554,6 +560,34 @@ void test_prvTCPPrepareConnect_IPV6_HappyPath_IPv6( void ) TEST_ASSERT_EQUAL_MEMORY( pxSocket->pxEndPoint, pxEndPoint, sizeof( NetworkEndPoint_t ) ); } +/** + * @brief This function validates successfully created a + * packet but the TCP window creation fails. + */ +void test_prvTCPPrepareConnect_IPV6_CreateTCPWindowFails( void ) +{ + FreeRTOS_Socket_t xSocket, * pxSocket = &xSocket; + NetworkEndPoint_t xEndPoint, * pxEndPoint = &xEndPoint; + NetworkBufferDescriptor_t xNetworkBuffer; + BaseType_t xReturn = pdFALSE; + + memset( pxEndPoint, 0, sizeof( NetworkEndPoint_t ) ); + memset( &xNetworkBuffer, 0, sizeof( NetworkBufferDescriptor_t ) ); + pxSocket->bits.bIsIPv6 = 1; + eNDGetCacheEntry_ExpectAnyArgsAndReturn( eARPCacheHit ); + eNDGetCacheEntry_ReturnThruPtr_ppxEndPoint( &pxEndPoint ); + + uxIPHeaderSizeSocket_ExpectAnyArgsAndReturn( ipSIZE_OF_IPv6_HEADER ); + ulApplicationGetNextSequenceNumber_ExpectAnyArgsAndReturn( 10 ); + + prvSocketSetMSS_ExpectAnyArgs(); + prvTCPCreateWindow_ExpectAnyArgsAndReturn( pdFAIL ); + + xReturn = prvTCPPrepareConnect_IPV6( pxSocket ); + + TEST_ASSERT_EQUAL( pdFAIL, xReturn ); +} + /** * @brief This function validates sending a TCP protocol control packet, * when an un synchronised packet is received. diff --git a/test/unit-test/FreeRTOS_TCP_Transmission_IPv6/TCP_Transmission_IPv6_list_macros.h b/test/unit-test/FreeRTOS_TCP_Transmission_IPv6/TCP_Transmission_IPv6_list_macros.h new file mode 100644 index 0000000000..e721f55b85 --- /dev/null +++ b/test/unit-test/FreeRTOS_TCP_Transmission_IPv6/TCP_Transmission_IPv6_list_macros.h @@ -0,0 +1,37 @@ +/* + * FreeRTOS+TCP + * Copyright (C) 2022 Amazon.com, Inc. or its affiliates. All Rights Reserved. + * + * SPDX-License-Identifier: MIT + * + * Permission is hereby granted, free of charge, to any person obtaining a copy of + * this software and associated documentation files (the "Software"), to deal in + * the Software without restriction, including without limitation the rights to + * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of + * the Software, and to permit persons to whom the Software is furnished to do so, + * subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS + * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR + * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER + * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + * http://aws.amazon.com/freertos + * http://www.FreeRTOS.org + */ +#ifndef LIST_MACRO_H +#define LIST_MACRO_H + +#include +#include +#include +#include + +BaseType_t prvTCPCreateWindow( FreeRTOS_Socket_t * pxSocket ); + +#endif /* ifndef LIST_MACRO_H */ diff --git a/test/unit-test/FreeRTOS_TCP_Transmission_IPv6/ut.cmake b/test/unit-test/FreeRTOS_TCP_Transmission_IPv6/ut.cmake index df5df3c5ac..47205d3a6c 100644 --- a/test/unit-test/FreeRTOS_TCP_Transmission_IPv6/ut.cmake +++ b/test/unit-test/FreeRTOS_TCP_Transmission_IPv6/ut.cmake @@ -21,6 +21,7 @@ list(APPEND mock_list "${CMAKE_BINARY_DIR}/Annexed_TCP/FreeRTOS_TCP_State_Handling.h" "${CMAKE_BINARY_DIR}/Annexed_TCP/FreeRTOS_IP_Private.h" "${CMAKE_BINARY_DIR}/Annexed_TCP/NetworkBufferManagement.h" + "${MODULE_ROOT_DIR}/test/unit-test/${project_name}/TCP_Transmission_IPv6_list_macros.h" ) set(mock_include_list "") diff --git a/test/unit-test/FreeRTOS_TCP_WIN/FreeRTOS_TCP_WIN_stubs.c b/test/unit-test/FreeRTOS_TCP_WIN/FreeRTOS_TCP_WIN_stubs.c index 1177c3d519..ac2ce0f751 100644 --- a/test/unit-test/FreeRTOS_TCP_WIN/FreeRTOS_TCP_WIN_stubs.c +++ b/test/unit-test/FreeRTOS_TCP_WIN/FreeRTOS_TCP_WIN_stubs.c @@ -95,7 +95,7 @@ void vApplicationDaemonTaskStartupHook( void ) void vApplicationGetTimerTaskMemory( StaticTask_t ** ppxTimerTaskTCBBuffer, StackType_t ** ppxTimerTaskStackBuffer, - uint32_t * pulTimerTaskStackSize ) + configSTACK_DEPTH_TYPE * puxTimerTaskStackSize ) { } @@ -144,7 +144,7 @@ void vPortCloseRunningThread( void * pvTaskToDelete, void vApplicationGetIdleTaskMemory( StaticTask_t ** ppxIdleTaskTCBBuffer, StackType_t ** ppxIdleTaskStackBuffer, - uint32_t * pulIdleTaskStackSize ) + configSTACK_DEPTH_TYPE * puxIdleTaskStackSize ) { } diff --git a/test/unit-test/FreeRTOS_TCP_WIN/FreeRTOS_TCP_WIN_utest.c b/test/unit-test/FreeRTOS_TCP_WIN/FreeRTOS_TCP_WIN_utest.c index dfabac3746..365f450201 100644 --- a/test/unit-test/FreeRTOS_TCP_WIN/FreeRTOS_TCP_WIN_utest.c +++ b/test/unit-test/FreeRTOS_TCP_WIN/FreeRTOS_TCP_WIN_utest.c @@ -193,12 +193,15 @@ void test_vTCPWindowDestroy_list_length_zero( void ) void test_vTCPWindowDestroy_list_length_not_zero( void ) { TCPWindow_t xWindow = { 0 }; - List_t * pxSegments = &( xWindow.xRxSegments ); + TCPSegment_t xSegment = { 0 }; + + xSegment.xQueueItem.pvContainer = &xWindow.xPriorityQueue; + xSegment.xSegmentItem.pvContainer = &xWindow.xPriorityQueue; listLIST_IS_INITIALISED_ExpectAnyArgsAndReturn( pdFALSE ); listLIST_IS_INITIALISED_ExpectAnyArgsAndReturn( pdTRUE ); listCURRENT_LIST_LENGTH_ExpectAnyArgsAndReturn( 1 ); - listGET_OWNER_OF_HEAD_ENTRY_ExpectAnyArgsAndReturn( pxSegments ); + listGET_OWNER_OF_HEAD_ENTRY_ExpectAnyArgsAndReturn( &xSegment ); /* ->vTCPWindowFree */ uxListRemove_ExpectAnyArgsAndReturn( pdTRUE ); uxListRemove_ExpectAnyArgsAndReturn( pdTRUE ); @@ -239,7 +242,7 @@ void test_vTCPWindowDestroy_list_no_segment_container( void ) vTCPWindowDestroy( &xWindow ); } -void test_vTCPWindowCreate_success( void ) +void test_xTCPWindowCreate_success( void ) { TCPWindow_t xWindow = { 0 }; uint32_t ulRxWindowLength = 0; @@ -247,6 +250,7 @@ void test_vTCPWindowCreate_success( void ) uint32_t ulAckNumber = 0; uint32_t ulSequenceNumber = 0; uint32_t ulMSS = 0; + BaseType_t xReturn; void * mlc = malloc( ipconfigTCP_WIN_SEG_COUNT * sizeof( xTCPSegments[ 0 ] ) ); @@ -267,16 +271,48 @@ void test_vTCPWindowCreate_success( void ) vListInitialise_ExpectAnyArgs(); - vTCPWindowCreate( &xWindow, - ulRxWindowLength, - ulTxWindowLength, - ulAckNumber, - ulSequenceNumber, - ulMSS ); + xReturn = xTCPWindowCreate( &xWindow, + ulRxWindowLength, + ulTxWindowLength, + ulAckNumber, + ulSequenceNumber, + ulMSS ); + TEST_ASSERT_EQUAL( pdPASS, xReturn ); free( mlc ); } -void test_vTCPWindowCreate_tcp_segment_null( void ) +void test_xTCPWindowCreate_AllocationFailed( void ) +{ + TCPWindow_t xWindow = { 0 }; + uint32_t ulRxWindowLength = 0; + uint32_t ulTxWindowLength = 0; + uint32_t ulAckNumber = 0; + uint32_t ulSequenceNumber = 0; + uint32_t ulMSS = 0; + BaseType_t xReturn; + + /* ->prvCreateSectors */ + vListInitialise_ExpectAnyArgs(); + pvPortMalloc_ExpectAnyArgsAndReturn( NULL ); + + /* back */ + vListInitialise_ExpectAnyArgs(); + vListInitialise_ExpectAnyArgs(); + vListInitialise_ExpectAnyArgs(); + vListInitialise_ExpectAnyArgs(); + vListInitialise_ExpectAnyArgs(); + + + xReturn = xTCPWindowCreate( &xWindow, + ulRxWindowLength, + ulTxWindowLength, + ulAckNumber, + ulSequenceNumber, + ulMSS ); + TEST_ASSERT_EQUAL( pdFAIL, xReturn ); +} + +void test_xTCPWindowCreate_tcp_segment_null( void ) { TCPWindow_t xWindow = { 0 }; uint32_t ulRxWindowLength = 0; @@ -284,6 +320,7 @@ void test_vTCPWindowCreate_tcp_segment_null( void ) uint32_t ulAckNumber = 0; uint32_t ulSequenceNumber = 0; uint32_t ulMSS = 0; + BaseType_t xReturn; /* ->prvCreateSectors */ vListInitialise_ExpectAnyArgs(); @@ -296,15 +333,16 @@ void test_vTCPWindowCreate_tcp_segment_null( void ) vListInitialise_ExpectAnyArgs(); - vTCPWindowCreate( &xWindow, - ulRxWindowLength, - ulTxWindowLength, - ulAckNumber, - ulSequenceNumber, - ulMSS ); + xReturn = xTCPWindowCreate( &xWindow, + ulRxWindowLength, + ulTxWindowLength, + ulAckNumber, + ulSequenceNumber, + ulMSS ); + TEST_ASSERT_EQUAL( pdFAIL, xReturn ); } -void test_vTCPWindowCreate_null_tcpSegment( void ) +void test_xTCPWindowCreate_null_tcpSegment( void ) { TCPWindow_t xWindow = { 0 }; uint32_t ulRxWindowLength = 0; @@ -312,6 +350,7 @@ void test_vTCPWindowCreate_null_tcpSegment( void ) uint32_t ulAckNumber = 0; uint32_t ulSequenceNumber = 0; uint32_t ulMSS = 0; + BaseType_t xReturn; xTCPSegments = ( TCPSegment_t * ) 32; @@ -321,12 +360,13 @@ void test_vTCPWindowCreate_null_tcpSegment( void ) vListInitialise_ExpectAnyArgs(); vListInitialise_ExpectAnyArgs(); - vTCPWindowCreate( &xWindow, - ulRxWindowLength, - ulTxWindowLength, - ulAckNumber, - ulSequenceNumber, - ulMSS ); + xReturn = xTCPWindowCreate( &xWindow, + ulRxWindowLength, + ulTxWindowLength, + ulAckNumber, + ulSequenceNumber, + ulMSS ); + TEST_ASSERT_EQUAL( pdPASS, xReturn ); TEST_ASSERT_EQUAL( ulRxWindowLength, xWindow.xSize.ulRxWindowLength ); TEST_ASSERT_EQUAL( ulTxWindowLength, xWindow.xSize.ulTxWindowLength ); } @@ -389,11 +429,14 @@ void test_vTCPSegmentCleanup_segment_null( void ) void test_vTCPSegmentCleanup_segment_not_null( void ) { /* will be freed by the function under test */ - xTCPSegments = ( TCPSegment_t * ) malloc( 123 ); + TCPSegment_t * pxTCPSegment = malloc( sizeof( TCPSegment_t ) ); + + xTCPSegments = pxTCPSegment; vPortFree_Expect( xTCPSegments ); vTCPSegmentCleanup(); TEST_ASSERT_NULL( xTCPSegments ); + free( pxTCPSegment ); } void test_lTCPWindowRxCheck_sequence_nums_equal( void ) @@ -1044,13 +1087,14 @@ void test_lTCPWindowTxAdd_nothing_to_do( void ) { int32_t lDone; TCPWindow_t xWindow = { 0 }; + TCPSegment_t xSegment = { 0 }; uint32_t ulLength = 0; int32_t lPosition = 0; int32_t lMax = 0; BaseType_t xBackup = xTCPWindowLoggingLevel; /* in real code, this points to a list of segments */ - xWindow.pxHeadSegment = malloc( sizeof( TCPSegment_t ) ); + xWindow.pxHeadSegment = &xSegment; xTCPWindowLoggingLevel = 3; @@ -1062,7 +1106,6 @@ void test_lTCPWindowTxAdd_nothing_to_do( void ) TEST_ASSERT_EQUAL( 0, lDone ); xTCPWindowLoggingLevel = xBackup; - free( xWindow.pxHeadSegment ); } void test_lTCPWindowTxAdd_null_txSegment( void ) @@ -1230,7 +1273,9 @@ void test_lTCPWindowTxAdd_lBytesLeft_gt_zero_data_length_gt_maxlen( void ) int32_t lMax = 0; /* in real code, this points to a list of segments */ - xWindow.pxHeadSegment = malloc( sizeof( TCPSegment_t ) ); + TCPSegment_t * pxTCPSegment = malloc( sizeof( TCPSegment_t ) ); + + xWindow.pxHeadSegment = pxTCPSegment; xWindow.pxHeadSegment->lMaxLength = 300; xWindow.pxHeadSegment->lDataLength = 200; xWindow.pxHeadSegment->u.bits.bOutstanding = pdTRUE_UNSIGNED; @@ -1262,7 +1307,7 @@ void test_lTCPWindowTxAdd_lBytesLeft_gt_zero_data_length_gt_maxlen( void ) TEST_ASSERT_EQUAL( 25, lDone ); TEST_ASSERT_NULL( xWindow.pxHeadSegment ); - free( xWindow.pxHeadSegment ); + free( pxTCPSegment ); } void test_lTCPWindowTxAdd_lBytesLeft_gt_zero_data_length_lt_maxlen( void ) diff --git a/test/unit-test/FreeRTOS_TCP_WIN/ut.cmake b/test/unit-test/FreeRTOS_TCP_WIN/ut.cmake index b36711c84f..309104dc86 100644 --- a/test/unit-test/FreeRTOS_TCP_WIN/ut.cmake +++ b/test/unit-test/FreeRTOS_TCP_WIN/ut.cmake @@ -32,7 +32,7 @@ list(APPEND mock_define_list # ================= Create the library under test here (edit) ================== -add_compile_options(-Wno-pedantic -Wno-div-by-zero -O0 -ggdb3) +add_compile_options(-Wno-pedantic -ggdb3) # list the files you would like to test here set(real_source_files "") list(APPEND real_source_files diff --git a/test/unit-test/FreeRTOS_Tiny_TCP/FreeRTOS_Tiny_TCP_stubs.c b/test/unit-test/FreeRTOS_Tiny_TCP/FreeRTOS_Tiny_TCP_stubs.c index 13f0ee5351..d0b303547b 100644 --- a/test/unit-test/FreeRTOS_Tiny_TCP/FreeRTOS_Tiny_TCP_stubs.c +++ b/test/unit-test/FreeRTOS_Tiny_TCP/FreeRTOS_Tiny_TCP_stubs.c @@ -88,7 +88,7 @@ void vApplicationDaemonTaskStartupHook( void ) } void vApplicationGetTimerTaskMemory( StaticTask_t ** ppxTimerTaskTCBBuffer, StackType_t ** ppxTimerTaskStackBuffer, - uint32_t * pulTimerTaskStackSize ) + configSTACK_DEPTH_TYPE * puxTimerTaskStackSize ) { } void vPortDeleteThread( void * pvTaskToDelete ) @@ -135,7 +135,7 @@ void vPortCloseRunningThread( void * pvTaskToDelete, } void vApplicationGetIdleTaskMemory( StaticTask_t ** ppxIdleTaskTCBBuffer, StackType_t ** ppxIdleTaskStackBuffer, - uint32_t * pulIdleTaskStackSize ) + configSTACK_DEPTH_TYPE * puxIdleTaskStackSize ) { } void vConfigureTimerForRunTimeStats( void ) diff --git a/test/unit-test/FreeRTOS_Tiny_TCP/ut.cmake b/test/unit-test/FreeRTOS_Tiny_TCP/ut.cmake index 656973395e..959ae9dd9f 100644 --- a/test/unit-test/FreeRTOS_Tiny_TCP/ut.cmake +++ b/test/unit-test/FreeRTOS_Tiny_TCP/ut.cmake @@ -29,7 +29,7 @@ list(APPEND mock_define_list # ================= Create the library under test here (edit) ================== -add_compile_options(-Wno-pedantic -Wno-div-by-zero -O0 -ggdb3) +add_compile_options(-Wno-pedantic -ggdb3) # list the files you would like to test here set(real_source_files "") list(APPEND real_source_files diff --git a/test/unit-test/FreeRTOS_UDP_IP/FreeRTOS_UDP_IP_list_macros.h b/test/unit-test/FreeRTOS_UDP_IP/FreeRTOS_UDP_IP_list_macros.h index a520eec33c..0342e9d1e1 100644 --- a/test/unit-test/FreeRTOS_UDP_IP/FreeRTOS_UDP_IP_list_macros.h +++ b/test/unit-test/FreeRTOS_UDP_IP/FreeRTOS_UDP_IP_list_macros.h @@ -86,6 +86,6 @@ BaseType_t xProcessReceivedUDPPacket_IPv6( NetworkBufferDescriptor_t * pxNetwork uint16_t usPort, BaseType_t * pxIsWaitingForARPResolution ); -NetworkEndPoint_t * FreeRTOS_FindEndPointOnNetMask( uint32_t ulIPAddress, - uint32_t ulWhere ); +NetworkEndPoint_t * FreeRTOS_FindEndPointOnNetMask( uint32_t ulIPAddress ); + #endif /* ifndef LIST_MACRO_H */ diff --git a/test/unit-test/FreeRTOS_UDP_IPv4/FreeRTOS_UDP_IPv4_utest.c b/test/unit-test/FreeRTOS_UDP_IPv4/FreeRTOS_UDP_IPv4_utest.c index bd41b5a9b7..a41f28ae51 100644 --- a/test/unit-test/FreeRTOS_UDP_IPv4/FreeRTOS_UDP_IPv4_utest.c +++ b/test/unit-test/FreeRTOS_UDP_IPv4/FreeRTOS_UDP_IPv4_utest.c @@ -1658,8 +1658,7 @@ void test_vProcessGeneratedUDPPacket_IPv4_UDPCacheMissEndPointFound() eARPGetCacheEntry_IgnoreArg_pulIPAddress(); vARPRefreshCacheEntry_Expect( NULL, pxNetworkBuffer->xIPAddress.ulIP_IPv4, NULL ); - FreeRTOS_FindEndPointOnNetMask_ExpectAndReturn( pxNetworkBuffer->xIPAddress.ulIP_IPv4, 0, pxEndPoint ); - FreeRTOS_FindEndPointOnNetMask_IgnoreArg_ulWhere(); + FreeRTOS_FindEndPointOnNetMask_ExpectAndReturn( pxNetworkBuffer->xIPAddress.ulIP_IPv4, pxEndPoint ); vARPGenerateRequestPacket_Expect( pxNetworkBuffer ); @@ -1691,8 +1690,7 @@ void test_vProcessGeneratedUDPPacket_IPv4_UDPCacheMissEndPointNotFound() eARPGetCacheEntry_IgnoreArg_pulIPAddress(); vARPRefreshCacheEntry_Expect( NULL, pxNetworkBuffer->xIPAddress.ulIP_IPv4, NULL ); - FreeRTOS_FindEndPointOnNetMask_ExpectAndReturn( pxNetworkBuffer->xIPAddress.ulIP_IPv4, 0, NULL ); - FreeRTOS_FindEndPointOnNetMask_IgnoreArg_ulWhere(); + FreeRTOS_FindEndPointOnNetMask_ExpectAndReturn( pxNetworkBuffer->xIPAddress.ulIP_IPv4, NULL ); vReleaseNetworkBufferAndDescriptor_Expect( pxNetworkBuffer ); vProcessGeneratedUDPPacket_IPv4( pxNetworkBuffer ); diff --git a/test/unit-test/cmock/create_test.cmake b/test/unit-test/cmock/create_test.cmake index e44be268c1..f8e46c1e6c 100644 --- a/test/unit-test/cmock/create_test.cmake +++ b/test/unit-test/cmock/create_test.cmake @@ -19,7 +19,7 @@ function(create_test test_name ) add_executable(${test_name} ${test_src} ${test_name}_runner.c) set_target_properties(${test_name} PROPERTIES - COMPILE_FLAG "-Wall -O0 -ggdb" + COMPILE_FLAG "-Wall -ggdb3" RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin/tests" INSTALL_RPATH_USE_LINK_PATH TRUE LINK_FLAGS " \ diff --git a/tools/CMakeLists.txt b/tools/CMakeLists.txt index dfbbdc5b8a..d9d827138b 100644 --- a/tools/CMakeLists.txt +++ b/tools/CMakeLists.txt @@ -17,7 +17,7 @@ target_include_directories( freertos_plus_tcp_utilities SYSTEM tcp_utilities/include ) -#TODO(phelter): Investigate and fix in freertos_plus_tcp if not already fixed. +# Investigate and fix in freertos_plus_tcp if not already fixed. target_compile_options( freertos_plus_tcp_utilities PRIVATE $<$:-Wno-extra-semi-stmt> diff --git a/tools/tcp_utilities/plus_tcp_demo_cli.c b/tools/tcp_utilities/plus_tcp_demo_cli.c index d1a5bb1272..37e00e72b4 100644 --- a/tools/tcp_utilities/plus_tcp_demo_cli.c +++ b/tools/tcp_utilities/plus_tcp_demo_cli.c @@ -279,7 +279,7 @@ static void handle_ifconfig( char * pcBuffer ) } /*-----------------------------------------------------------*/ -static const char * pcARPReturnType( eARPLookupResult_t eResult ) +static const char * pcARPReturnType( eResolutionLookupResult_t eResult ) { const char * pcReturn = "Unknown"; @@ -453,7 +453,7 @@ static void handle_arpq( char * pcBuffer ) { CommandOptions_t xOptions; char * ptr = pcBuffer; - eARPLookupResult_t eResult = eResolutionCacheMiss; + eResolutionLookupResult_t eResult = eResolutionCacheMiss; uint32_t ulIPAddress; uint32_t ulLookUpIP; MACAddress_t xMACAddress;