Skip to content

Conversation

@evpopov
Copy link
Contributor

@evpopov evpopov commented Jan 24, 2025

Description

The current code incorrectly assumes that broadcast addresses only end in x.x.x.255
When a frame enters the stack, all broadcast tests must be made against the 255.255.255.255 address and against the specific broadcast of the endpoint that the frame was assigned
When an ARP lookup is attempted, we need to check if the user is attempting to send a packet that may be considered a broadcast on any of our IPv4 endpoints. Current code was only calling an outgoing packet a "broadcast" is said packet ended in 0xFF.
This PR attempts to correct both of the above.

Additionally, I've taken the liberty to substitute ipBROADCAST_IP_ADDRESS with FREERTOS_INADDR_BROADCAST and put the new definition in a public header file. Here's my reasoning:

  • INADDR_BROADCAST is a well-known definition that in my opinion is widely used. Just like INADDR_ANY. The original definition's name is obscure.
  • The original definition is supposed to be "inaccessible" or "hidden" to the user because it was in FreeRTOS_IP_Private.h I did not see a good reason for this.

I have also probably broken a bunch of test cases with this and I'd really appreciate it if someone can help with fixing the old tests and maybe even add tests that verify the new changes. For example test that verifies 192.168.0.7 as a broadcast if the endpoint is 192.168.0.1/29, etc...

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

Add xIsIPv4Broadcast helper function that enumerates over all IPv4 endpoints and their corresponding  broadcast addresses.
Adds checks for the 255.255.255.255 address.
Substitutes ipBROADCAST_IP_ADDRESS with FREERTOS_INADDR_BROADCAST to better match the rest of the world.
Cleans up frame filtering a bit to ensure a frame's destination address is NOT matched against other endpoints than the one the frame entered through.
@evpopov evpopov requested a review from a team as a code owner January 24, 2025 14:56
@evpopov evpopov marked this pull request as draft January 24, 2025 14:56
@evpopov evpopov marked this pull request as ready for review January 28, 2025 15:43
@evpopov
Copy link
Contributor Author

evpopov commented Jan 28, 2025

/bot run formatting

struct xNetworkEndPoint ** ppxEndPoint )
{
BaseType_t xIsBroadcast;
uint32_t ulEndPointBroadcast;
Copy link
Member

@tony-josi-aws tony-josi-aws Jan 29, 2025

Choose a reason for hiding this comment

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

NIT: Unused variable ulEndPointBroadcast

uint16_t usProtocolBytes; /**< The total length of the protocol data. */
};

#define ipBROADCAST_IP_ADDRESS 0xffffffffU
Copy link
Member

Choose a reason for hiding this comment

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

There are few more references to ipBROADCAST_IP_ADDRESS in the code - STM32 network interfaces and UTs

@tony-josi-aws
Copy link
Member

Thanks @evpopov for this PR, I have added some minor comments.

@ig15 ig15 added the bug Something isn't working label Jan 29, 2025
@evpopov evpopov force-pushed the BCastAddressDetection_PR branch from 9955e6d to 7f7c4cc Compare January 29, 2025 14:25
Removes an unused variable
Renames  ipBROADCAST_IP_ADDRESS to FREERTOS_INADDR_BROADCAST in the unit tests and the STM32 network driver
@evpopov evpopov force-pushed the BCastAddressDetection_PR branch from 7f7c4cc to fcc0bde Compare January 29, 2025 14:27
@evpopov
Copy link
Contributor Author

evpopov commented Jan 29, 2025

Thanks for catching those @tony-josi-aws
I addressed all of your comments, but I cannot run the unit tests so please verify

@tony-josi-aws tony-josi-aws added enhancement New feature or request and removed bug Something isn't working labels Feb 6, 2025
@tony-josi-aws tony-josi-aws merged commit 4b81c00 into FreeRTOS:main Feb 7, 2025
10 checks passed
@evpopov evpopov deleted the BCastAddressDetection_PR branch May 30, 2025 16:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants