diff --git a/source/FreeRTOS_DNS.c b/source/FreeRTOS_DNS.c index eb8760c67..4b3805df1 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,69 +137,7 @@ 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. */ diff --git a/source/FreeRTOS_IP.c b/source/FreeRTOS_IP.c index 8f3519eb8..024805f0a 100644 --- a/source/FreeRTOS_IP.c +++ b/source/FreeRTOS_IP.c @@ -1451,15 +1451,17 @@ BaseType_t xSendEventStructToIPTask( const IPStackEvent_t * pxEvent, */ eFrameProcessingResult_t eConsiderFrameForProcessing( const uint8_t * const pucEthernetBuffer ) { - eFrameProcessingResult_t eReturn = eProcessBuffer; + eFrameProcessingResult_t eReturn = eReleaseBuffer; do { const EthernetHeader_t * pxEthernetHeader = NULL; const NetworkEndPoint_t * pxEndPoint = NULL; + /* First, check the packet buffer is non-null. */ if( pucEthernetBuffer == NULL ) { + /* The packet buffer was null - release it. */ eReturn = eReleaseBuffer; break; } @@ -1470,87 +1472,122 @@ eFrameProcessingResult_t eConsiderFrameForProcessing( const uint8_t * const pucE /* coverity[misra_c_2012_rule_11_3_violation] */ pxEthernetHeader = ( ( const EthernetHeader_t * ) pucEthernetBuffer ); - switch( pxEthernetHeader->usFrameType ) + /* Second, filter based on ethernet frame type. */ + if( FreeRTOS_ntohs( pxEthernetHeader->usFrameType ) <= 0x600U ) { - case ipARP_FRAME_TYPE: - case ipIPv4_FRAME_TYPE: - #if ipconfigIS_DISABLED( ipconfigUSE_IPv4 ) - eReturn = eReleaseBuffer; - #endif + /* The packet was not an Ethernet II frame */ + #if ipconfigIS_ENABLED( ipconfigFILTER_OUT_NON_ETHERNET_II_FRAMES ) + /* filtering is enabled - release it. */ break; - - case ipIPv6_FRAME_TYPE: - #if ipconfigIS_DISABLED( ipconfigUSE_IPv6 ) - eReturn = eReleaseBuffer; - #endif + #else + /* filtering is disabled - continue filter checks. */ + #endif + } + else if( pxEthernetHeader->usFrameType == ipARP_FRAME_TYPE ) + { + /* The frame is an ARP type */ + #if ipconfigIS_DISABLED( ipconfigUSE_IPv4 ) + /* IPv4 is disabled - release it. */ break; - - default: - if( FreeRTOS_ntohs( pxEthernetHeader->usFrameType ) <= 0x600U ) - { - #if ipconfigIS_ENABLED( ipconfigFILTER_OUT_NON_ETHERNET_II_FRAMES ) - eReturn = eReleaseBuffer; - #endif - } - else - { - #if ipconfigIS_DISABLED( ipconfigPROCESS_CUSTOM_ETHERNET_FRAMES ) - eReturn = eReleaseBuffer; - #endif - } + #else + /* IPv4 is enabled - Continue filter checks. */ + #endif + } + else if( pxEthernetHeader->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 } - - if( eReturn == eReleaseBuffer ) + else if( pxEthernetHeader->usFrameType == ipIPv6_FRAME_TYPE ) { - /* No use to do more testing. */ - break; + /* 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 } - /* Examine the destination MAC from the Ethernet header to see if it matches - * that of an end point managed by FreeRTOS+TCP. */ - pxEndPoint = FreeRTOS_MatchingEndpoint( NULL, pucEthernetBuffer ); + /* Third, filter based on destination mac address. */ + pxEndPoint = FreeRTOS_FindEndPointOnMAC( &( pxEthernetHeader->xDestinationAddress ), NULL ); if( pxEndPoint != NULL ) { - break; + /* A destination endpoint was found - Continue filter checks. */ } - - #if ipconfigIS_ENABLED( ipconfigUSE_DNS ) - #if ipconfigIS_ENABLED( ipconfigUSE_LLMNR ) - #if ipconfigIS_ENABLED( ipconfigUSE_IPv4 ) - if( memcmp( xLLMNR_MacAddress.ucBytes, pxEthernetHeader->xDestinationAddress.ucBytes, sizeof( MACAddress_t ) ) == 0 ) - { - /* The packet is a request for LLMNR - process it. */ - break; - } - #endif - #if ipconfigIS_ENABLED( ipconfigUSE_IPv6 ) - if( memcmp( xLLMNR_MacAddressIPv6.ucBytes, pxEthernetHeader->xDestinationAddress.ucBytes, sizeof( MACAddress_t ) ) == 0 ) - { - /* The packet is a request for LLMNR - process it. */ - break; - } - #endif + else if( memcmp( xBroadcastMACAddress.ucBytes, pxEthernetHeader->xDestinationAddress.ucBytes, sizeof( MACAddress_t ) ) == 0 ) + { + /* The packet was a broadcast - Continue filter checks. */ + } + else if( memcmp( xLLMNR_MacAddress.ucBytes, pxEthernetHeader->xDestinationAddress.ucBytes, sizeof( MACAddress_t ) ) == 0 ) + { + /* 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 - #if ipconfigIS_ENABLED( ipconfigUSE_MDNS ) - #if ipconfigIS_ENABLED( ipconfigUSE_IPv4 ) - if( memcmp( xMDNS_MacAddress.ucBytes, pxEthernetHeader->xDestinationAddress.ucBytes, sizeof( MACAddress_t ) ) == 0 ) - { - /* The packet is a request for MDNS - process it. */ - break; - } - #endif - #if ipconfigIS_ENABLED( ipconfigUSE_IPv6 ) - if( memcmp( xMDNS_MACAddressIPv6.ucBytes, pxEthernetHeader->xDestinationAddress.ucBytes, sizeof( MACAddress_t ) ) == 0 ) - { - /* The packet is a request for MDNS - process it. */ - break; - } - #endif + } + else if( memcmp( xLLMNR_MacAddressIPv6.ucBytes, pxEthernetHeader->xDestinationAddress.ucBytes, sizeof( MACAddress_t ) ) == 0 ) + { + /* 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 - #endif + } + else if( memcmp( xMDNS_MacAddress.ucBytes, pxEthernetHeader->xDestinationAddress.ucBytes, sizeof( MACAddress_t ) ) == 0 ) + { + /* 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_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 + } - eReturn = eReleaseBuffer; + /* All checks have been passed, process the packet. */ + eReturn = eProcessBuffer; } while( ipFALSE_BOOL ); return eReturn; diff --git a/source/include/FreeRTOS_DNS.h b/source/include/FreeRTOS_DNS.h index 04daeb232..90b4860cb 100644 --- a/source/include/FreeRTOS_DNS.h +++ b/source/include/FreeRTOS_DNS.h @@ -41,38 +41,23 @@ #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; - -/* The LLMNR IPv6 MAC address is 33:33:00:01:00:03 */ - extern const MACAddress_t xLLMNR_MacAddressIPv6; -#endif /* ipconfigUSE_LLMNR */ +extern const IPv6_Address_t ipLLMNR_IP_ADDR_IPv6; -#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 MAC address is 01:00:5e:00:00:fc */ +extern const MACAddress_t xMDNS_MacAddress; -#if ( ipconfigUSE_MDNS == 1 ) && ( ipconfigUSE_IPv6 != 0 ) +/* The MDNS IPv6 MAC address is 33:33:00:01:00:03 */ +extern const MACAddress_t 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 +75,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 ) /*