Skip to content

Commit ff11a14

Browse files
htiboschamazonKamathmoninom1
authored
Dev integration hein.v8 (#738)
* Updating tcp utilities * Some more change in dev_integration_hein.v8 * In FreeRTOS_DNS_Parser.c : use 'ipUDP_PAYLOAD_OFFSET_IPv4' in stead of 'ipIP_PAYLOAD_OFFSET' * And a few more corrections * Changes to WinPCap network interface, removed debugging code * After applying uncrustify * Oops, I forgot the push changes in include files. * Now removing it, hopefully --------- Co-authored-by: Nikhil Kamath <[email protected]> Co-authored-by: Monika Singh <[email protected]>
1 parent d0fbbd3 commit ff11a14

35 files changed

+3788
-491
lines changed

source/FreeRTOS_ARP.c

Lines changed: 63 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -151,10 +151,6 @@ eFrameProcessingResult_t eARPProcessPacket( const NetworkBufferDescriptor_t * px
151151
void * pvCopyDest;
152152
NetworkEndPoint_t * pxTargetEndPoint = pxNetworkBuffer->pxEndPoint;
153153

154-
#if ( ipconfigARP_USE_CLASH_DETECTION != 0 )
155-
NetworkEndPoint_t * pxSourceEndPoint;
156-
#endif
157-
158154
/* Next defensive request must not be sent for arpIP_CLASH_RESET_TIMEOUT_MS
159155
* period. */
160156
static TickType_t uxARPClashTimeoutPeriod = pdMS_TO_TICKS( arpIP_CLASH_RESET_TIMEOUT_MS );
@@ -241,7 +237,7 @@ eFrameProcessingResult_t eARPProcessPacket( const NetworkBufferDescriptor_t * px
241237
/* Process received ARP frame to see if there is a clash. */
242238
#if ( ipconfigARP_USE_CLASH_DETECTION != 0 )
243239
{
244-
pxSourceEndPoint = FreeRTOS_FindEndPointOnIP_IPv4( ulSenderProtocolAddress, 2 );
240+
NetworkEndPoint_t * pxSourceEndPoint = FreeRTOS_FindEndPointOnIP_IPv4( ulSenderProtocolAddress, 2 );
245241

246242
if( ( pxSourceEndPoint != NULL ) && ( pxSourceEndPoint->ipv4_settings.ulIPAddress == ulSenderProtocolAddress ) )
247243
{
@@ -419,7 +415,8 @@ static void vARPProcessPacketReply( const ARPPacket_t * pxARPFrame,
419415
vARPRefreshCacheEntry( &( pxARPHeader->xSenderHardwareAddress ), ulSenderProtocolAddress, pxTargetEndPoint );
420416
}
421417

422-
if( pxARPWaitingNetworkBuffer != NULL )
418+
if( ( pxARPWaitingNetworkBuffer != NULL ) &&
419+
( uxIPHeaderSizePacket( pxARPWaitingNetworkBuffer ) == ipSIZE_OF_IPv4_HEADER ) )
423420
{
424421
/* MISRA Ref 11.3.1 [Misaligned access] */
425422
/* More details at: https://github.com/FreeRTOS/FreeRTOS-Plus-TCP/blob/main/MISRA.md#rule-113 */
@@ -499,24 +496,70 @@ BaseType_t xCheckRequiresARPResolution( const NetworkBufferDescriptor_t * pxNetw
499496
{
500497
BaseType_t xNeedsARPResolution = pdFALSE;
501498

502-
/* MISRA Ref 11.3.1 [Misaligned access] */
503-
/* More details at: https://github.com/FreeRTOS/FreeRTOS-Plus-TCP/blob/main/MISRA.md#rule-113 */
504-
/* coverity[misra_c_2012_rule_11_3_violation] */
505-
const IPPacket_t * pxIPPacket = ( ( IPPacket_t * ) pxNetworkBuffer->pucEthernetBuffer );
506-
const IPHeader_t * pxIPHeader = &( pxIPPacket->xIPHeader );
507-
IPV4Parameters_t * pxIPv4Settings = &( pxNetworkBuffer->pxEndPoint->ipv4_settings );
499+
if( uxIPHeaderSizePacket( pxNetworkBuffer ) == ipSIZE_OF_IPv6_HEADER )
500+
{
501+
const IPPacket_IPv6_t * pxIPPacket = ( ( IPPacket_IPv6_t * ) pxNetworkBuffer->pucEthernetBuffer );
502+
const IPHeader_IPv6_t * pxIPHeader = &( pxIPPacket->xIPHeader );
503+
IPv6_Address_t * pxIPAddress = &( pxIPHeader->xSourceAddress );
504+
uint8_t ucNextHeader = pxIPHeader->ucNextHeader;
505+
506+
if( ( ucNextHeader == ipPROTOCOL_TCP ) ||
507+
( ucNextHeader == ipPROTOCOL_UDP ) )
508+
{
509+
IPv6_Type_t eType = xIPv6_GetIPType( pxIPAddress );
510+
FreeRTOS_printf( ( "xCheckRequiresARPResolution: %pip type %s\n", pxIPAddress->ucBytes, ( eType == eIPv6_Global ) ? "Global" : ( eType == eIPv6_LinkLocal ) ? "LinkLocal" : "other" ) );
511+
512+
if( eType == eIPv6_LinkLocal )
513+
{
514+
MACAddress_t xMACAddress;
515+
NetworkEndPoint_t * pxEndPoint;
516+
eARPLookupResult_t eResult;
517+
char pcName[ 80 ];
518+
519+
eResult = eNDGetCacheEntry( pxIPAddress, &xMACAddress, &pxEndPoint );
520+
FreeRTOS_printf( ( "xCheckRequiresARPResolution: eResult %s with EP %s\n", ( eResult == eARPCacheMiss ) ? "Miss" : ( eResult == eARPCacheHit ) ? "Hit" : "Error", pcEndpointName( pxEndPoint, pcName, sizeof pcName ) ) );
521+
522+
if( eResult == eARPCacheMiss )
523+
{
524+
NetworkBufferDescriptor_t * pxTempBuffer;
525+
size_t uxNeededSize;
526+
527+
uxNeededSize = ipSIZE_OF_ETH_HEADER + ipSIZE_OF_IPv6_HEADER + sizeof( ICMPRouterSolicitation_IPv6_t );
528+
pxTempBuffer = pxGetNetworkBufferWithDescriptor( BUFFER_FROM_WHERE_CALL( 199 ) uxNeededSize, 0U );
508529

509-
if( ( pxIPHeader->ulSourceIPAddress & pxIPv4Settings->ulNetMask ) == ( pxIPv4Settings->ulIPAddress & pxIPv4Settings->ulNetMask ) )
530+
if( pxTempBuffer != NULL )
531+
{
532+
pxTempBuffer->pxEndPoint = pxNetworkBuffer->pxEndPoint;
533+
pxTempBuffer->pxInterface = pxNetworkBuffer->pxInterface;
534+
vNDSendNeighbourSolicitation( pxNetworkBuffer, pxIPAddress );
535+
}
536+
537+
xNeedsARPResolution = pdTRUE;
538+
}
539+
}
540+
}
541+
}
542+
else
510543
{
511-
/* If the IP is on the same subnet and we do not have an ARP entry already,
512-
* then we should send out ARP for finding the MAC address. */
513-
if( xIsIPInARPCache( pxIPHeader->ulSourceIPAddress ) == pdFALSE )
544+
/* MISRA Ref 11.3.1 [Misaligned access] */
545+
/* More details at: https://github.com/FreeRTOS/FreeRTOS-Plus-TCP/blob/main/MISRA.md#rule-113 */
546+
/* coverity[misra_c_2012_rule_11_3_violation] */
547+
const IPPacket_t * pxIPPacket = ( ( IPPacket_t * ) pxNetworkBuffer->pucEthernetBuffer );
548+
const IPHeader_t * pxIPHeader = &( pxIPPacket->xIPHeader );
549+
IPV4Parameters_t * pxIPv4Settings = &( pxNetworkBuffer->pxEndPoint->ipv4_settings );
550+
551+
if( ( pxIPHeader->ulSourceIPAddress & pxIPv4Settings->ulNetMask ) == ( pxIPv4Settings->ulIPAddress & pxIPv4Settings->ulNetMask ) )
514552
{
515-
FreeRTOS_OutputARPRequest( pxIPHeader->ulSourceIPAddress );
553+
/* If the IP is on the same subnet and we do not have an ARP entry already,
554+
* then we should send out ARP for finding the MAC address. */
555+
if( xIsIPInARPCache( pxIPHeader->ulSourceIPAddress ) == pdFALSE )
556+
{
557+
FreeRTOS_OutputARPRequest( pxIPHeader->ulSourceIPAddress );
516558

517-
/* This packet needs resolution since this is on the same subnet
518-
* but not in the ARP cache. */
519-
xNeedsARPResolution = pdTRUE;
559+
/* This packet needs resolution since this is on the same subnet
560+
* but not in the ARP cache. */
561+
xNeedsARPResolution = pdTRUE;
562+
}
520563
}
521564
}
522565

source/FreeRTOS_DNS_Networking.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@
154154
if( xReturn <= 0 )
155155
{
156156
/* 'pdFREERTOS_ERRNO_EWOULDBLOCK' is returned in case of a timeout. */
157-
FreeRTOS_printf( ( "DNS_ReadReply returns %d\n", xReturn ) );
157+
FreeRTOS_printf( ( "DNS_ReadReply returns %d\n", ( int ) xReturn ) );
158158
}
159159

160160
return xReturn;

source/FreeRTOS_DNS_Parser.c

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -438,6 +438,7 @@
438438
{
439439
NetworkBufferDescriptor_t * pxNetworkBuffer;
440440
NetworkEndPoint_t * pxEndPoint, xEndPoint;
441+
size_t uxUDPOffset;
441442

442443
pxNetworkBuffer = pxUDPPayloadBuffer_to_NetworkBuffer( pucUDPPayloadBuffer );
443444

@@ -450,6 +451,9 @@
450451
break;
451452
}
452453

454+
uxUDPOffset = ( size_t ) ( pucUDPPayloadBuffer - pxNetworkBuffer->pucEthernetBuffer );
455+
configASSERT( ( uxUDPOffset == ipUDP_PAYLOAD_OFFSET_IPv4 ) || ( uxUDPOffset == ipUDP_PAYLOAD_OFFSET_IPv6 ) );
456+
453457
if( pxNetworkBuffer->pxEndPoint == NULL )
454458
{
455459
/* NetworkInterface is obliged to set 'pxEndPoint' in every received packet,
@@ -480,8 +484,8 @@
480484
}
481485
#endif /* ( ipconfigUSE_IPv6 != 0 ) */
482486

483-
/* If this is not a reply to our DNS request, it might an LLMNR
484-
* request. */
487+
/* If this is not a reply to our DNS request, it might be an mDNS or an LLMNR
488+
* request. Ask the application if it uses the name. */
485489
if( xApplicationDNSQueryHook( &xEndPoint, xSet.pcName ) )
486490
{
487491
int16_t usLength;
@@ -524,7 +528,7 @@
524528
xOffset2 = ( BaseType_t ) ( ( ( uint8_t * ) xSet.pcRequestedName ) - pucUDPPayloadBuffer );
525529

526530
pxNetworkBuffer = pxNewBuffer;
527-
pucNewBuffer = &( pxNetworkBuffer->pucEthernetBuffer[ ipUDP_PAYLOAD_OFFSET_IPv4 ] );
531+
pucNewBuffer = &( pxNetworkBuffer->pucEthernetBuffer[ uxUDPOffset ] );
528532

529533
xSet.pucByte = &( pucNewBuffer[ xOffset1 ] );
530534
xSet.pcRequestedName = ( char * ) &( pucNewBuffer[ xOffset2 ] );
@@ -538,7 +542,7 @@
538542
}
539543
else
540544
{
541-
pucNewBuffer = &( pxNetworkBuffer->pucEthernetBuffer[ ipUDP_PAYLOAD_OFFSET_IPv4 ] );
545+
pucNewBuffer = &( pxNetworkBuffer->pucEthernetBuffer[ uxUDPOffset ] );
542546
}
543547
}
544548

@@ -575,11 +579,11 @@
575579
}
576580
else
577581
{
578-
/*logging*/
579-
FreeRTOS_printf( ( "LLMNR return IPv4 %lxip\n", FreeRTOS_ntohl( xEndPoint.ipv4_settings.ulIPAddress ) ) );
582+
size_t uxDistance;
580583
vSetField16( pxAnswer, LLMNRAnswer_t, usDataLength, ( uint16_t ) sizeof( pxAnswer->ulIPAddress ) );
581584
vSetField32( pxAnswer, LLMNRAnswer_t, ulIPAddress, FreeRTOS_ntohl( xEndPoint.ipv4_settings.ulIPAddress ) );
582-
usLength = ( int16_t ) ( sizeof( *pxAnswer ) + ( size_t ) ( xSet.pucByte - pucNewBuffer ) );
585+
uxDistance = ( size_t ) ( xSet.pucByte - pucNewBuffer );
586+
usLength = ( int16_t ) ( sizeof( *pxAnswer ) + uxDistance );
583587
}
584588

585589
prepareReplyDNSMessage( pxNetworkBuffer, usLength );
@@ -956,14 +960,15 @@
956960
if( pxIPHeader->ulDestinationIPAddress == ipMDNS_IP_ADDRESS )
957961
{
958962
pxIPHeader->ulDestinationIPAddress = ipMDNS_IP_ADDRESS;
963+
pxIPHeader->ucTimeToLive = ipMDNS_TIME_TO_LIVE;
959964
}
960965
else
961966
{
962967
pxIPHeader->ulDestinationIPAddress = pxIPHeader->ulSourceIPAddress;
968+
pxIPHeader->ucTimeToLive = ipconfigUDP_TIME_TO_LIVE;
963969
}
964970

965971
pxIPHeader->ulSourceIPAddress = ( pxEndPoint != NULL ) ? pxEndPoint->ipv4_settings.ulIPAddress : 0U;
966-
pxIPHeader->ucTimeToLive = ipconfigUDP_TIME_TO_LIVE;
967972
pxIPHeader->usIdentification = FreeRTOS_htons( usPacketIdentifier );
968973

969974
/* The stack doesn't support fragments, so the fragment offset field must always be zero.

source/FreeRTOS_IP.c

Lines changed: 21 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1772,31 +1772,32 @@ static eFrameProcessingResult_t prvProcessIPPacket( const IPPacket_t * pxIPPacke
17721772
* entry. */
17731773
if( ucProtocol != ( uint8_t ) ipPROTOCOL_UDP )
17741774
{
1775-
/* Refresh the ARP cache with the IP/MAC-address of the received
1776-
* packet. For UDP packets, this will be done later in
1777-
* xProcessReceivedUDPPacket(), as soon as it's know that the message
1778-
* will be handled. This will prevent the ARP cache getting
1779-
* overwritten with the IP address of useless broadcast packets. */
1780-
if( pxIPPacket->xEthernetHeader.usFrameType == ipIPv6_FRAME_TYPE )
1781-
{
1782-
vNDRefreshCacheEntry( &( pxIPPacket->xEthernetHeader.xSourceAddress ), &( pxIPHeader_IPv6->xSourceAddress ), pxNetworkBuffer->pxEndPoint );
1783-
}
1784-
else
1785-
17861775
if( xCheckRequiresARPResolution( pxNetworkBuffer ) == pdTRUE )
17871776
{
17881777
eReturn = eWaitingARPResolution;
17891778
}
17901779
else
17911780
{
1792-
/* IP address is not on the same subnet, ARP table can be updated.
1793-
* Refresh the ARP cache with the IP/MAC-address of the received
1794-
* packet. For UDP packets, this will be done later in
1781+
/* Refresh the ARP cache with the IP/MAC-address of the received
1782+
* packet. For UDP packets, this will be done later in
17951783
* xProcessReceivedUDPPacket(), as soon as it's know that the message
17961784
* will be handled. This will prevent the ARP cache getting
1797-
* overwritten with the IP address of useless broadcast packets.
1798-
*/
1799-
vARPRefreshCacheEntry( &( pxIPPacket->xEthernetHeader.xSourceAddress ), pxIPHeader->ulSourceIPAddress, pxNetworkBuffer->pxEndPoint );
1785+
* overwritten with the IP address of useless broadcast packets. */
1786+
if( pxIPPacket->xEthernetHeader.usFrameType == ipIPv6_FRAME_TYPE )
1787+
{
1788+
vNDRefreshCacheEntry( &( pxIPPacket->xEthernetHeader.xSourceAddress ), &( pxIPHeader_IPv6->xSourceAddress ), pxNetworkBuffer->pxEndPoint );
1789+
}
1790+
else
1791+
{
1792+
/* IP address is not on the same subnet, ARP table can be updated.
1793+
* Refresh the ARP cache with the IP/MAC-address of the received
1794+
* packet. For UDP packets, this will be done later in
1795+
* xProcessReceivedUDPPacket(), as soon as it's know that the message
1796+
* will be handled. This will prevent the ARP cache getting
1797+
* overwritten with the IP address of useless broadcast packets.
1798+
*/
1799+
vARPRefreshCacheEntry( &( pxIPPacket->xEthernetHeader.xSourceAddress ), pxIPHeader->ulSourceIPAddress, pxNetworkBuffer->pxEndPoint );
1800+
}
18001801
}
18011802
}
18021803

@@ -1812,7 +1813,9 @@ static eFrameProcessingResult_t prvProcessIPPacket( const IPPacket_t * pxIPPacke
18121813
* went wrong because it will not be able to validate what it
18131814
* receives. */
18141815
#if ( ipconfigREPLY_TO_INCOMING_PINGS == 1 ) || ( ipconfigSUPPORT_OUTGOING_PINGS == 1 )
1815-
eReturn = ProcessICMPPacket( pxNetworkBuffer );
1816+
{
1817+
eReturn = ProcessICMPPacket( pxNetworkBuffer );
1818+
}
18161819
#endif /* ( ipconfigREPLY_TO_INCOMING_PINGS == 1 ) || ( ipconfigSUPPORT_OUTGOING_PINGS == 1 ) */
18171820
break;
18181821

source/FreeRTOS_IPv6.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ eFrameProcessingResult_t prvAllowIPPacketIPv6( const IPHeader_IPv6_t * const pxI
166166
const IPv6_Address_t * pxDestinationIPAddress = &( pxIPv6Header->xDestinationAddress );
167167

168168
/* Is the packet for this IP address? */
169-
if( ( FreeRTOS_FindEndPointOnIP_IPv6( pxDestinationIPAddress ) != NULL ) ||
169+
if( ( pxNetworkBuffer->pxEndPoint != NULL ) ||
170170
/* Is it the multicast address FF00::/8 ? */
171171
( xIsIPv6Multicast( pxDestinationIPAddress ) != pdFALSE ) ||
172172
/* Or (during DHCP negotiation) we have no IP-address yet? */

0 commit comments

Comments
 (0)