Page MenuHomeFreeBSD

ping tests: Add tests for IP header options
ClosedPublic

Authored by jlduran_gmail.com on Feb 9 2023, 8:46 PM.
Tags
None
Referenced Files
Unknown Object (File)
Fri, Apr 19, 4:38 AM
Unknown Object (File)
Wed, Mar 27, 10:51 AM
Unknown Object (File)
Mar 8 2024, 10:13 PM
Unknown Object (File)
Mar 8 2024, 10:13 PM
Unknown Object (File)
Mar 8 2024, 10:13 PM
Unknown Object (File)
Mar 8 2024, 10:13 PM
Unknown Object (File)
Mar 8 2024, 12:56 PM
Unknown Object (File)
Mar 8 2024, 12:46 PM

Details

Summary

The function pr_pack() prints out a packet, if the IP packet contains options, these are printed as well.

Test the functionality fixed in 70960bb86a3ba5b6f5c4652e613e6313a7ed1ac1.

Test Plan

DISCLAIMER: My preferred route would be to implement D38431, however for reasons detailed in that review, we'll resort to fixing what we currently have.

Diff Detail

Repository
rG FreeBSD src repository
Lint
Lint Not Applicable
Unit
Tests Not Applicable

Event Timeline

@markj already made a few suggestions by email. Let's move the discussion here.

sbin/ping/ping.c
1381 ↗(On Diff #116888)

This (int) cast also isn't needed.

1455 ↗(On Diff #116888)

I think we need to adjust hlen here and in the default case to avoid an infinite loop.

sbin/ping/ping.c
1455 ↗(On Diff #116888)

Nice! will add a test case for NOP as well.

jlduran_gmail.com marked 2 inline comments as done.

Address comments:

  • Add single NOP case
  • Remove unneeded int cast
  • There is no need to decrease hlen, as cp is advancing to the next octet, (single NOP case added as proof). However, let's be pedantic (and true to the original implementation), and decrease it.
sbin/ping/ping.c
1391 ↗(On Diff #117013)

I believe, to really stay true to the original implementation, we should also decrease hlen by 1 accordingly, here and in the other routing options. However, I'd like to avoid magic numbers, but I’m afraid the constants from ip.h are meant to be used as offsets (https://github.com/freebsd/freebsd-src/blob/6957cd86d9143f5ff179515e52fc42946e642f66/sys/netinet/ip.h#L162..L168)… We’ll see…

So isn't there now a mismatch between hlen and cp when handling IPOPT_LSRR and other options? The loop header increments cp once each iteration but doesn't decrement hlen to match.

Perhaps this suggests that the better solution is to handle IPOPT_EOL by forcibly breaking out of the loop, rather than setting hlen to zero?

So isn't there now a mismatch between hlen and cp when handling IPOPT_LSRR and other options? The loop header increments cp once each iteration but doesn't decrement hlen to match.

I'll test locally with a packet containing LSRR options with just a couple of routers + NOP and see the remaining hlen value.

Perhaps this suggests that the better solution is to handle IPOPT_EOL by forcibly breaking out of the loop, rather than setting hlen to zero?

I believe it is doing both.

If it helps, I have somewhere another branch where I declare an int optslen var, which is hlen - sizeof(struct ip), and use it inside the for loop insted of hlen, kind of like it was before.

Why the original authors decrease hlen, I haven't investigated, but there's probably a historical reason. With this patch hlen ends being either 0 or 20 depending on whether the original IP packet had options or not.

Wouldn't it be simpler to simply revert hlen back to a signed int?

jlduran_gmail.com retitled this revision from ping: Fix an unsigned integer overflow to ping tests: Add tests for IP header options.
jlduran_gmail.com edited the summary of this revision. (Show Details)

Now that the fix is in place, just commit the tests.

This revision is now accepted and ready to land.Mar 10 2023, 5:57 PM
This revision was automatically updated to reflect the committed changes.