|
58 | 58 |
|
59 | 59 | /* RFC Flags */ |
60 | 60 | /** @brief Type of Neighbour Advertisement packets - ROUTER. */ |
61 | | - #define ndICMPv6_FLAG_ROUTER 0x80000000U |
| 61 | + #define ndICMPv6_FLAG_ROUTER 0x80000000U |
62 | 62 | /** @brief Type of Neighbour Advertisement packets - SOLICIT. */ |
63 | | - #define ndICMPv6_FLAG_SOLICITED 0x40000000U |
| 63 | + #define ndICMPv6_FLAG_SOLICITED 0x40000000U |
64 | 64 | /** @brief Type of Neighbour Advertisement packets - OVERRIDE. */ |
65 | | - #define ndICMPv6_FLAG_OVERRIDE 0x20000000U |
| 65 | + #define ndICMPv6_FLAG_OVERRIDE 0x20000000U |
66 | 66 |
|
67 | | - #define ndDELAY_FIRST_PROBE_TIME_SECONDS ( 5U ) |
| 67 | +/** @brief Seconds to remain in the DELAY state before sending the first probe. */ |
| 68 | + #define ndDELAY_FIRST_PROBE_TIME_SECONDS ( 5U ) |
68 | 69 |
|
69 | | - #define ipconfigMAX_ND_RE_LOOKUP_ATTEMPTS ( 3U ) |
| 70 | +/** @brief Maximum number of ND re-lookup attempts before giving up. */ |
| 71 | + #define ipconfigMAX_ND_RE_LOOKUP_ATTEMPTS ( 3U ) |
70 | 72 |
|
71 | | -/* Ensure this is defined for the ucFlags field */ |
72 | | - #define ndpFLAG_IS_ROUTER ( 0x01U ) |
| 73 | +/** @brief ucFlags bit indicating the neighbour is a router. */ |
| 74 | + #define ndpFLAG_IS_ROUTER ( 0x01U ) |
| 75 | + |
| 76 | +/** @brief Default lifetime (in age ticks) assigned to a fresh ND cache entry. */ |
| 77 | + #ifndef ipconfigMAX_ND_AGE |
| 78 | + #define ipconfigMAX_ND_AGE ( 150U ) |
| 79 | + #endif |
73 | 80 |
|
74 | 81 | /** @brief A block time of 0 simply means "don't block". */ |
75 | 82 | #define ndDONT_BLOCK ( ( TickType_t ) 0 ) |
|
106 | 113 | /** @brief Find the first end-point of type IPv6. */ |
107 | 114 | static NetworkEndPoint_t * pxFindLocalEndpoint( void ); |
108 | 115 |
|
109 | | -/* Two functions to faciliate debugging. */ |
| 116 | +/* Two functions to facilitate debugging. */ |
110 | 117 |
|
111 | 118 | const char * pcNDStateName( eNDState_t eState ); |
112 | 119 | const char * pcNDActionName( eNaAction_t eState ); |
|
145 | 152 | static void vNDPCacheSetState( IPv6_Address_t * pxTargetIP, |
146 | 153 | eNDState_t eState ); |
147 | 154 |
|
148 | | -/** |
149 | | - * @brief Search the NDP cache for an IP address. |
150 | | - * |
151 | | - * @param[in] pxIPAddress: The IPv6 address to look up. |
152 | | - * |
153 | | - * @return Pointer to the cache row if found and valid; NULL otherwise. |
154 | | - */ |
| 155 | +/* Search the NDP cache for an IP address. Documented at the definition. */ |
155 | 156 | NDCacheRow_t * pxNDPCacheLookup( const IPv6_Address_t * pxIPAddress ); |
156 | 157 |
|
157 | 158 | /* Process an incoming packet of the type ipICMP_NEIGHBOR_ADVERTISEMENT_IPv6. */ |
|
358 | 359 | void vNDAgeCache( void ) |
359 | 360 | { |
360 | 361 | BaseType_t x; |
361 | | - extern NetworkBufferDescriptor_t * pxNDWaitingNetworkBuffer; |
362 | | - |
363 | | - /* Ensure the ND age constant is defined. */ |
364 | | - #ifndef ipconfigMAX_ND_AGE |
365 | | - #define ipconfigMAX_ND_AGE ( 150U ) |
366 | | - #endif |
367 | 362 |
|
368 | 363 | for( x = 0; x < ( BaseType_t ) ipconfigND_CACHE_ENTRIES; x++ ) |
369 | 364 | { |
|
556 | 551 | pxEntry->ucState = ( uint8_t ) eState; |
557 | 552 | pxEntry->ucAge = ( uint8_t ) ipconfigMAX_ND_AGE; |
558 | 553 | pxEntry->ucNumProbes = 0; |
559 | | - pxEntry->ulLastMatchingNA = xTaskGetTickCount(); |
| 554 | + pxEntry->ulLastMatchingNA = ( uint32_t ) xTaskGetTickCount(); |
560 | 555 |
|
561 | 556 | if( pxEndPoint != NULL ) |
562 | 557 | { |
|
570 | 565 | } |
571 | 566 | else |
572 | 567 | { |
573 | | - pxEntry->ucFlags &= ~ndpFLAG_IS_ROUTER; |
| 568 | + pxEntry->ucFlags &= ( uint8_t ) ~ndpFLAG_IS_ROUTER; |
574 | 569 | } |
575 | 570 |
|
576 | 571 | /* Essential: Check if a packet was waiting for this resolution. */ |
|
617 | 612 | pxEntry->ucState = ( uint8_t ) eState; |
618 | 613 | pxEntry->ucAge = ( uint8_t ) ipconfigMAX_ND_AGE; |
619 | 614 | pxEntry->ucNumProbes = 0; |
620 | | - pxEntry->ulLastMatchingNA = xTaskGetTickCount(); |
| 615 | + pxEntry->ulLastMatchingNA = ( uint32_t ) xTaskGetTickCount(); |
621 | 616 | pxEntry->pxEndPoint = pxEndPoint; |
622 | 617 |
|
623 | 618 | if( xRouter != pdFALSE ) |
|
689 | 684 | /* If the Target Link-Layer Address (TLLA) is present, validate it. */ |
690 | 685 | if( pxNa->xHasTargetLLA != pdFALSE ) |
691 | 686 | { |
| 687 | + static const uint8_t ucZeroMac[ ipMAC_ADDRESS_LENGTH_BYTES ] = { 0, 0, 0, 0, 0, 0 }; |
| 688 | + |
692 | 689 | /* MAC cannot be multicast (the I/G bit). */ |
693 | 690 | if( ( pxNa->xTargetMAC.ucBytes[ 0 ] & 0x01U ) != 0U ) |
694 | 691 | { |
695 | 692 | break; |
696 | 693 | } |
697 | 694 |
|
698 | 695 | /* MAC cannot be all zeros. */ |
699 | | - static const uint8_t ucZeroMac[ ipMAC_ADDRESS_LENGTH_BYTES ] = { 0, 0, 0, 0, 0, 0 }; |
700 | | - |
701 | 696 | if( memcmp( pxNa->xTargetMAC.ucBytes, ucZeroMac, ipMAC_ADDRESS_LENGTH_BYTES ) == 0 ) |
702 | 697 | { |
703 | 698 | break; |
|
900 | 895 | } |
901 | 896 | /*-----------------------------------------------------------*/ |
902 | 897 |
|
903 | | -/* See if pxNDWaitingNetworkBuffer is filled, and process it when address is resolved. |
| 898 | +/** |
| 899 | + * @brief Process a packet parked in pxNDWaitingNetworkBuffer once the target |
| 900 | + * address has been resolved, sending it if it matches or releasing it. |
| 901 | + * |
| 902 | + * @param[in] pxTargetIP The IPv6 address that has just been resolved. |
904 | 903 | */ |
905 | 904 | void vNDCheckWaitingPacket( const IPv6_Address_t * pxTargetIP ) |
906 | 905 | { |
|
910 | 909 | */ |
911 | 910 | if( pxNDWaitingNetworkBuffer != NULL ) |
912 | 911 | { |
913 | | - BaseType_t xhasReleased = pdFALSE; |
| 912 | + BaseType_t xHasReleased = pdFALSE; |
914 | 913 | NetworkBufferDescriptor_t * pxBuffer = pxNDWaitingNetworkBuffer; |
915 | 914 | const ICMPPacket_IPv6_t * pxIPPacket; |
916 | 915 | BaseType_t xMatch; |
|
924 | 923 | xMatch ? "Sending" : "Giving up", |
925 | 924 | pxIPPacket->xIPHeader.xSourceAddress.ucBytes, |
926 | 925 | pxTargetIP->ucBytes ) ); |
927 | | - FreeRTOS_debug_printf( ( "NDBuffer: match = %d\n", xMatch ) ); |
| 926 | + FreeRTOS_debug_printf( ( "NDBuffer: match = %d\n", ( int ) xMatch ) ); |
928 | 927 |
|
929 | 928 | /* Does the packet we parked match the IP we just resolved? */ |
930 | 929 | if( xMatch != pdFALSE ) |
|
940 | 939 |
|
941 | 940 | if( xSendEventStructToIPTask( &xEventMessage, xDontBlock ) == pdTRUE ) |
942 | 941 | { |
943 | | - xhasReleased = pdTRUE; |
| 942 | + xHasReleased = pdTRUE; |
944 | 943 | } |
945 | 944 |
|
946 | 945 | pxBuffer = NULL; |
947 | 946 | } |
948 | 947 |
|
949 | | - if( xhasReleased == pdFALSE ) |
| 948 | + if( xHasReleased == pdFALSE ) |
950 | 949 | { |
951 | 950 | /* Failed to send the message, so release the network buffer. */ |
952 | 951 | vReleaseNetworkBufferAndDescriptor( pxBuffer ); |
|
1061 | 1060 | * to its own loopback IPv6 address). Because the binding is trusted, it may |
1062 | 1061 | * create a new entry - unlike vNDRefreshCacheEntryAge(), which never inserts. |
1063 | 1062 | * Do NOT call this from the receive path for peer neighbours; that path must go |
1064 | | - * through prvProcessNA()/prvDetermineAction() (see GHSA-4cmm-53v6-5996). |
| 1063 | + * through prvProcessNA()/prvDetermineAction(). |
1065 | 1064 | */ |
1066 | 1065 | void vNDRefreshCacheEntry( const MACAddress_t * pxMACAddress, |
1067 | 1066 | const IPv6_Address_t * pxIPAddress, |
|
1174 | 1173 | void FreeRTOS_PrintNDCache( void ) |
1175 | 1174 | { |
1176 | 1175 | BaseType_t x, xCount = 0; |
1177 | | - char pcBuffer[ 40 ]; |
1178 | 1176 | char pcBuffer_EUI48[ 18 ]; |
1179 | 1177 |
|
1180 | 1178 | /* Loop through each entry in the ND cache. */ |
1181 | 1179 | for( x = 0; x < ipconfigND_CACHE_ENTRIES; x++ ) |
1182 | 1180 | { |
1183 | 1181 | if( xNDCache[ x ].ucState != ( uint8_t ) eND_FREE ) |
1184 | 1182 | { |
| 1183 | + const char * pcHostType = ( xNDCache[ x ].ucFlags & ndpFLAG_IS_ROUTER ) ? "Router" : "Host"; |
| 1184 | + |
1185 | 1185 | /* See if the MAC-address also matches, and we're all happy */ |
1186 | 1186 | FreeRTOS_EUI48_ntop( xNDCache[ x ].xMACAddress.ucBytes, pcBuffer_EUI48, 'a', '-' ); |
1187 | | - const char * pcHostType = ( xNDCache[ x ].ucFlags & ndpFLAG_IS_ROUTER ) ? "Router" : "Host"; |
1188 | 1187 |
|
1189 | 1188 | FreeRTOS_printf( ( " %u | %pip | %s | %s | %u | %s \n", |
1190 | 1189 | ( int ) x, |
|
2119 | 2118 | } |
2120 | 2119 | /*-----------------------------------------------------------*/ |
2121 | 2120 |
|
| 2121 | +/** |
| 2122 | + * @brief Return a human-readable name for an ND cache entry state. |
| 2123 | + * |
| 2124 | + * @param[in] eState The ND state to describe. |
| 2125 | + * |
| 2126 | + * @return A pointer to a constant string describing the state. |
| 2127 | + */ |
2122 | 2128 | const char * pcNDStateName( eNDState_t eState ) |
2123 | 2129 | { |
2124 | | - static char pcSpace[ 16 ]; |
| 2130 | + static char pcSpace[ 24 ]; |
2125 | 2131 | const char * pcReturn; |
2126 | 2132 |
|
2127 | 2133 | switch( eState ) |
|
2159 | 2165 | } |
2160 | 2166 | /*-----------------------------------------------------------*/ |
2161 | 2167 |
|
| 2168 | +/** |
| 2169 | + * @brief Return a human-readable name for a Neighbour Advertisement action. |
| 2170 | + * |
| 2171 | + * @param[in] eState The action to describe. |
| 2172 | + * |
| 2173 | + * @return A pointer to a constant string describing the action. |
| 2174 | + */ |
2162 | 2175 | const char * pcNDActionName( eNaAction_t eState ) |
2163 | 2176 | { |
2164 | | - static char pcSpace[ 16 ]; |
| 2177 | + static char pcSpace[ 24 ]; |
2165 | 2178 | const char * pcReturn; |
2166 | 2179 |
|
2167 | 2180 | switch( eState ) |
|
0 commit comments