Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't Fragment Flags patch. #179

Merged
merged 9 commits into from
Feb 3, 2021
1 change: 1 addition & 0 deletions FreeRTOS_DNS.c
Original file line number Diff line number Diff line change
Expand Up @@ -1947,6 +1947,7 @@
pxIPHeader->ulSourceIPAddress = *ipLOCAL_IP_ADDRESS_POINTER;
pxIPHeader->ucTimeToLive = ipconfigUDP_TIME_TO_LIVE;
pxIPHeader->usIdentification = FreeRTOS_htons( usPacketIdentifier );
pxIPHeader->usFragmentOffset = ipFRAGMENT_FLAGS_DONT_FRAGMENT;
usPacketIdentifier++;
pxUDPHeader->usLength = FreeRTOS_htons( ( uint32_t ) lNetLength + ipSIZE_OF_UDP_HEADER );
vFlip_16( pxUDPHeader->usSourcePort, pxUDPHeader->usDestinationPort );
Expand Down
20 changes: 6 additions & 14 deletions FreeRTOS_IP.c
Original file line number Diff line number Diff line change
Expand Up @@ -115,16 +115,6 @@
#define ipCONSIDER_FRAME_FOR_PROCESSING( pucEthernetBuffer ) eProcessBuffer
#endif

#if ( ipconfigETHERNET_DRIVER_FILTERS_PACKETS == 0 )
#if ( ipconfigBYTE_ORDER == pdFREERTOS_LITTLE_ENDIAN )
/** @brief The bits in the two byte IP header field that make up the fragment offset value. */
#define ipFRAGMENT_OFFSET_BIT_MASK ( ( uint16_t ) 0xff0f )
#else
/** @brief The bits in the two byte IP header field that make up the fragment offset value. */
#define ipFRAGMENT_OFFSET_BIT_MASK ( ( uint16_t ) 0x0fff )
#endif /* ipconfigBYTE_ORDER */
#endif /* ipconfigETHERNET_DRIVER_FILTERS_PACKETS */

Comment on lines -118 to -127
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was expanded with more definitions and moved to FreeRTOS_IP_Private.h so that those defines are accessible to al IP-based protocols.

/** @brief The maximum time the IP task is allowed to remain in the Blocked state if no
* events are posted to the network event queue. */
#ifndef ipconfigMAX_IP_TASK_SLEEP_TIME
Expand Down Expand Up @@ -1853,10 +1843,11 @@ static eFrameProcessingResult_t prvAllowIPPacket( const IPPacket_t * const pxIPP
* This method may decrease the usage of sparse network buffers. */
uint32_t ulDestinationIPAddress = pxIPHeader->ulDestinationIPAddress;

/* Ensure that the incoming packet is not fragmented (only outgoing
* packets can be fragmented) as these are the only handled IP frames
* currently. */
if( ( pxIPHeader->usFragmentOffset & ipFRAGMENT_OFFSET_BIT_MASK ) != 0U )
/* Ensure that the incoming packet is not fragmented. This stack
doesn't not support IP fragmentation and always sets the "don't fragment"
flag on outgoing IP frames. The first fragment coming in will have its
"more fragments" flag set and later fragments will have a non-zero offset. */
if( ( pxIPHeader->usFragmentOffset & ipFRAGMENT_OFFSET_BIT_MASK ) != 0U || ( pxIPHeader->usFragmentOffset & ipFRAGMENT_FLAGS_MORE_FRAGMENTS ) != 0U )
{
/* Can not handle, fragmented packet. */
eReturn = eReleaseBuffer;
Expand Down Expand Up @@ -2248,6 +2239,7 @@ static eFrameProcessingResult_t prvProcessIPPacket( IPPacket_t * pxIPPacket,
pxICMPHeader->ucTypeOfMessage = ( uint8_t ) ipICMP_ECHO_REPLY;
pxIPHeader->ulDestinationIPAddress = pxIPHeader->ulSourceIPAddress;
pxIPHeader->ulSourceIPAddress = *ipLOCAL_IP_ADDRESS_POINTER;
pxIPHeader->usFragmentOffset = ipFRAGMENT_FLAGS_DONT_FRAGMENT;

/* Update the checksum because the ucTypeOfMessage member in the header
* has been changed to ipICMP_ECHO_REPLY. This is faster than calling
Expand Down
2 changes: 1 addition & 1 deletion FreeRTOS_TCP_IP.c
Original file line number Diff line number Diff line change
Expand Up @@ -962,7 +962,7 @@
/* Just an increasing number. */
pxIPHeader->usIdentification = FreeRTOS_htons( usPacketIdentifier );
usPacketIdentifier++;
pxIPHeader->usFragmentOffset = 0U;
pxIPHeader->usFragmentOffset = ipFRAGMENT_FLAGS_DONT_FRAGMENT;

/* Important: tell NIC driver how many bytes must be sent. */
pxNetworkBuffer->xDataLength = ulLen + ipSIZE_OF_ETH_HEADER;
Expand Down
1 change: 1 addition & 0 deletions FreeRTOS_UDP_IP.c
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,7 @@ void vProcessGeneratedUDPPacket( NetworkBufferDescriptor_t * const pxNetworkBuff

pxIPHeader->usLength = FreeRTOS_htons( pxIPHeader->usLength );
pxIPHeader->ulDestinationIPAddress = pxNetworkBuffer->ulIPAddress;
pxIPHeader->usFragmentOffset = ipFRAGMENT_FLAGS_DONT_FRAGMENT;

#if ( ipconfigUSE_LLMNR == 1 )
{
Expand Down
24 changes: 21 additions & 3 deletions include/FreeRTOS_IP_Private.h
Original file line number Diff line number Diff line change
Expand Up @@ -382,9 +382,6 @@
#define ipFRAGMENTATION_PARAMETERS_OFFSET ( 6 )
#define ipSOCKET_OPTIONS_OFFSET ( 6 )

/* Only used when outgoing fragmentation is being used (FreeRTOSIPConfig.h
* setting. */
#define ipGET_UDP_PAYLOAD_OFFSET_FOR_FRAGMENT( usFragmentOffset ) ( ( ( usFragmentOffset ) == 0 ) ? ipUDP_PAYLOAD_OFFSET_IPv4 : ipIP_PAYLOAD_OFFSET )

/* The offset into a UDP packet at which the UDP data (payload) starts. */
#define ipUDP_PAYLOAD_OFFSET_IPv4 ( sizeof( UDPPacket_t ) )
Expand Down Expand Up @@ -418,6 +415,27 @@

#endif /* ipconfigBYTE_ORDER == pdFREERTOS_LITTLE_ENDIAN */

#if( ipconfigETHERNET_DRIVER_FILTERS_PACKETS == 0 )
#if( ipconfigBYTE_ORDER == pdFREERTOS_LITTLE_ENDIAN )
/* The bits in the two byte IP header field that make up the fragment offset value. */
#define ipFRAGMENT_OFFSET_BIT_MASK ( ( uint16_t ) 0xff0f )
/* The bits in the two byte IP header field that make up the flags value. */
#define ipFRAGMENT_FLAGS_BIT_MASK ( ( uint16_t ) 0x00f0 )
/* Don't Fragment Flag */
#define ipFRAGMENT_FLAGS_DONT_FRAGMENT ( ( uint16_t ) 0x0040 )
/* More Fragments Flag */
#define ipFRAGMENT_FLAGS_MORE_FRAGMENTS ( ( uint16_t ) 0x0020 )
#else
/* The bits in the two byte IP header field that make up the fragment offset value. */
#define ipFRAGMENT_OFFSET_BIT_MASK ( ( uint16_t ) 0x0fff )
/* The bits in the two byte IP header field that make up the flags value. */
#define ipFRAGMENT_FLAGS_BIT_MASK ( ( uint16_t ) 0xf000 )
/* Don't Fragment Flag */
#define ipFRAGMENT_FLAGS_DONT_FRAGMENT ( ( uint16_t ) 0x4000 )
/* More Fragments Flag */
#define ipFRAGMENT_FLAGS_MORE_FRAGMENTS ( ( uint16_t ) 0x2000 )
#endif /* ipconfigBYTE_ORDER */
#endif /* ipconfigETHERNET_DRIVER_FILTERS_PACKETS */

/* For convenience, a MAC address of all zeros and another of all 0xffs are
* defined const for quick reference. */
Expand Down