Skip to content

Conversation

@13627105546
Copy link
Contributor

Note: Please adhere to Contributing Guidelines.

Summary

  • Why : When using icmp_ping , there is no filter set for the socket. This might cause the socket to receive unwanted ICMP packets or fail to filter out packets that are not Echo Replies, potentially interfering with the ping logic or causing performance issues in noisy network environments.
  • What : This commit adds logic to set the ICMP_FILTER socket option for the ping socket. It introduces a macro ICMP_SET_FILTER and uses setsockopt to configure the filter to only allow ICMP_ECHO_REPLY packets, blocking all other ICMP types.

Impact

  • Users : Users of the ping command will experience more robust behavior as the socket will only process relevant ICMP Echo Reply packets.
  • Build : No impact on build configuration.
  • Hardware : No specific hardware dependency. Depends on the TCP/IP stack implementation of ICMP_FILTER socket option.
  • Compatibility : Backward compatible.

Testing

  • Verification :
  • Verified that the code compiles successfully.
  • Verified that checkpatch.sh passes for the modified files.
  • Target : Verified on local hardware platform.

@xiaoxiang781216
Copy link
Contributor

@13627105546 fix:

d8a9600bc ping4:Set the filter for reply packet.
../nuttx/tools/checkpatch.sh -c -u -m -g b0b90ac72886a7d2ee8d9a16e057a4b2c801984e..HEAD
❌ Remove Gerrit Change-ID's before submitting upstream
Used config files:

@13627105546
Copy link
Contributor Author

@13627105546 fix:

d8a9600bc ping4:Set the filter for reply packet.
../nuttx/tools/checkpatch.sh -c -u -m -g b0b90ac72886a7d2ee8d9a16e057a4b2c801984e..HEAD
❌ Remove Gerrit Change-ID's before submitting upstream
Used config files:

have been remove Change-ID with commits

@simbit18
Copy link
Contributor

@13627105546 please fix

../nuttx/tools/checkpatch.sh -c -u -m -g b0b90ac72886a7d2ee8d9a16e057a4b2c801984e..HEAD
❌ Missing git commit message
Used config files:
    1: .codespellrc
Some checks failed. For contributing guidelines, see:
  https://github.com/apache/nuttx/blob/master/CONTRIBUTING.md
Error: Process completed with exit code 1.

@13627105546
Copy link
Contributor Author

@13627105546 please fix

../nuttx/tools/checkpatch.sh -c -u -m -g b0b90ac72886a7d2ee8d9a16e057a4b2c801984e..HEAD
❌ Missing git commit message
Used config files:
    1: .codespellrc
Some checks failed. For contributing guidelines, see:
  https://github.com/apache/nuttx/blob/master/CONTRIBUTING.md
Error: Process completed with exit code 1.

Done, have been add git commit message

Add setsockopt support to filter ICMP packets.

Signed-off-by: liqinhui <liqinhui@xiaomi.com>
****************************************************************************/

#define ICMP_IOBUFFER_SIZE(x) (sizeof(struct icmp_hdr_s) + (x))
#define ICMP_SET_FILTER(t) (UINT32_MAX - (1U << (t)))
Copy link
Contributor

Choose a reason for hiding this comment

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

why sub UINT32_MAX

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants