-
Notifications
You must be signed in to change notification settings - Fork 1.1k
FreeRTOS+TCP : pass payload length when calling UDP callback #1625
Conversation
In /* TX checksum offloading has NOT been implemented in the Wi-Fi of ESP32. */
#define ipconfigDRIVER_INCLUDED_TX_IP_CHECKSUM 0 That is redundant, because 0 is already the default. I added it for clarity, to confirm that the WiFi module can only offload checksums during reception, not during transmission. Correction : the above comment has nothing to do with this PR 1625, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See comments and check unit test for possible failures after this change.
@@ -280,7 +280,8 @@ UDPPacket_t *pxUDPPacket = (UDPPacket_t *) pxNetworkBuffer->pucEthernetBuffer; | |||
destinationAddress.sin_port = usPort; | |||
destinationAddress.sin_addr = pxUDPPacket->xIPHeader.ulDestinationIPAddress; | |||
|
|||
if( xHandler( ( Socket_t ) pxSocket, ( void* ) pcData, ( size_t ) pxNetworkBuffer->xDataLength, | |||
/* The value of 'xDataLength' was proven to be at least the size of a UDP packet in prvProcessIPPacket(). */ | |||
if( xHandler( ( Socket_t ) pxSocket, ( void* ) pcData, ( size_t ) ( pxNetworkBuffer->xDataLength - ipUDP_PAYLOAD_OFFSET_IPv4 ), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
FYI we recently found an integer overflow case in the unit test for ulDNSHandlePacket()
and fixed it by explicitly checking that pxNetworkBuffer->xDataLength >= sizeof( UDPPacket_t )
. Will we see another failing unit test if we don't do that check prior to line 284 here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, I hadn't see your earlier PR. Thanks for pointing out. I will respond directly to it.
Thanks, Hein
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm confused by the implication of the change in behavior from the perspective of the callee. Is this within the specification of xHandler?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@htibosch As Gary pointed out do we need to make sure that pxNetworkBuffer->xDataLength >= ipUDP_PAYLOAD_OFFSET_IPv4
before doing pxNetworkBuffer->xDataLength - ipUDP_PAYLOAD_OFFSET_IPv4
i.e.
if( pxNetworkBuffer->xDataLength >= ipUDP_PAYLOAD_OFFSET_IPv4 )
{
/* Call xHandler. */
}
else
{
/* Handle malformed packet. */
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@aggarg, @htibosch 's comment on PR #1615 points out that this was validated in prvProcessIPPacket()
, so we are probably okay here. That PR was in response to a failing unit test in which ulDNSHandlePacket()
was called directly, so that condition hadn't been guaranteed. We'll move forward with this and monitor the unit test results for any regressions.
@@ -280,7 +280,8 @@ UDPPacket_t *pxUDPPacket = (UDPPacket_t *) pxNetworkBuffer->pucEthernetBuffer; | |||
destinationAddress.sin_port = usPort; | |||
destinationAddress.sin_addr = pxUDPPacket->xIPHeader.ulDestinationIPAddress; | |||
|
|||
if( xHandler( ( Socket_t ) pxSocket, ( void* ) pcData, ( size_t ) pxNetworkBuffer->xDataLength, | |||
/* The value of 'xDataLength' was proven to be at least the size of a UDP packet in prvProcessIPPacket(). */ | |||
if( xHandler( ( Socket_t ) pxSocket, ( void* ) pcData, ( size_t ) ( pxNetworkBuffer->xDataLength - ipUDP_PAYLOAD_OFFSET_IPv4 ), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm confused by the implication of the change in behavior from the perspective of the callee. Is this within the specification of xHandler?
@dcgaws wrote:
Yes it is. My xHandler was complaining because the packets were too long since applying PR 1625. |
@@ -280,7 +280,8 @@ UDPPacket_t *pxUDPPacket = (UDPPacket_t *) pxNetworkBuffer->pucEthernetBuffer; | |||
destinationAddress.sin_port = usPort; | |||
destinationAddress.sin_addr = pxUDPPacket->xIPHeader.ulDestinationIPAddress; | |||
|
|||
if( xHandler( ( Socket_t ) pxSocket, ( void* ) pcData, ( size_t ) pxNetworkBuffer->xDataLength, | |||
/* The value of 'xDataLength' was proven to be at least the size of a UDP packet in prvProcessIPPacket(). */ | |||
if( xHandler( ( Socket_t ) pxSocket, ( void* ) pcData, ( size_t ) ( pxNetworkBuffer->xDataLength - ipUDP_PAYLOAD_OFFSET_IPv4 ), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@aggarg, @htibosch 's comment on PR #1615 points out that this was validated in prvProcessIPPacket()
, so we are probably okay here. That PR was in response to a failing unit test in which ulDNSHandlePacket()
was called directly, so that condition hadn't been guaranteed. We'll move forward with this and monitor the unit test results for any regressions.
Description
Recently, it was decided to let
NetworkBufferDescriptor::xDataLength
always mean: the total size of the network packet. Before that, it could also mean: "payload size", depending on the location in the code. That was confusing.This was changed in PR #1513.
However, by mistake, I hadn't tested the
ipconfigUSE_CALLBACKS
option with UDP after the PR.In
xProcessReceivedUDPPacket()
, the value ofxDataLength
should have been corrected withipUDP_PAYLOAD_OFFSET_IPv4
:pcData was pointing correctly to the UDP payload, but
xDataLength
was too large.Checklist:
By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.