add option to handle Ping TTL for raw socket and system utility#30324
add option to handle Ping TTL for raw socket and system utility#30324wfurt merged 5 commits intodotnet:masterfrom
Conversation
|
@dotnet-bot test Outerloop Windows x64 Debug Build |
| } | ||
| else | ||
| { | ||
| // Linux uses -t ttl for both IPv4 & IPv6 |
There was a problem hiding this comment.
And macOS uses -t for ipv4?
There was a problem hiding this comment.
yes. It is TTL for IPv4 and Hop Limit for IPv6.
| } | ||
|
|
||
| string processArgs = UnixCommandLinePing.ConstructCommandLine(buffer.Length, address.ToString(), isIpv4); | ||
| string processArgs = UnixCommandLinePing.ConstructCommandLine(buffer.Length, address.ToString(), isIpv4, options?.Ttl ?? 0); |
There was a problem hiding this comment.
Is there a way to test this?
There was a problem hiding this comment.
test if the option is supported by ping?
There was a problem hiding this comment.
Sorry, I didn't mean to comment on this line specifically... I meant test that this PR is doing what was intended, that the TTL is being respected now.
There was a problem hiding this comment.
yes. I did run wireshark when running on my Ubuntu VM. I'll re-run the test on OSX.
As far as unit test, we would need stable server with distance greater than 1.
Than we could craft outerloop test and verify results with different TTL.
|
|
||
| private static readonly string s_discoveredPing4UtilityPath = GetPingUtilityPath(ipv4: true); | ||
| private static readonly string s_discoveredPing6UtilityPath = GetPingUtilityPath(ipv4: false); | ||
| private static readonly bool s_isOSX = Environment.OSVersion.Platform == PlatformID.MacOSX; |
There was a problem hiding this comment.
Did you test this and it worked? I thought we returned PlatformID.Unix for macOS.
|
cc: @janvorli for any other platform thoughts. |
|
Merged with upstream changes and correct some issues. So I refactored tests little bit so we try basic address tests for both IPv4 and IPv6 - in similar way how we test sockets. As I mentioned originally, more work will be needed for "don't fragment" as busybox implementation on Alpine does not support it. |
| public void SendPingWithIPAddress_AddressAsString(AddressFamily addressFamily) | ||
| { | ||
| IPAddress localIpAddress = TestSettings.GetLocalIPAddress(); | ||
| if (localIpAddress == null) |
There was a problem hiding this comment.
I assume addressFamily should be passed to GetLocalIPAddress here.
There was a problem hiding this comment.
yes, it is. I don't know why github does not show it.
There was a problem hiding this comment.
I don't know why github does not show it
Because it's not there :-) I just pulled down your change, and it's:
IPAddress localIpAddress = TestSettings.GetLocalIPAddress();
if (localIpAddress == null)There was a problem hiding this comment.
yes, I found it. I was looking at wrong lines. sorry.
There was a problem hiding this comment.
it so happened line 128 has almost exact (and right code). but the broken was on 146.
Updated and pushed change.
| { | ||
| IPAddress localIpAddress = TestSettings.GetLocalIPAddress(); | ||
| IPAddress localIpAddress = TestSettings.GetLocalIPAddress(addressFamily); | ||
|
|
There was a problem hiding this comment.
Nit: the other tests don't have this blank line
| public void SendPingWithIPAddress_AddressAsString(AddressFamily addressFamily) | ||
| { | ||
| IPAddress localIpAddress = TestSettings.GetLocalIPAddress(); | ||
| if (localIpAddress == null) |
| { | ||
| IPAddress localIpAddress = TestSettings.GetLocalIPAddress(); | ||
| IPAddress localIpAddress = TestSettings.GetLocalIPAddress(addressFamily); | ||
|
|
| } | ||
|
|
||
| throw new InvalidOperationException("Unable to discover any addresses for the local host."); | ||
| return addressFamily == AddressFamily.InterNetwork ? IPAddress.Parse("127.0.0.1") : IPAddress.Parse("::1"); |
There was a problem hiding this comment.
IPAddress.Loopback and IPAddress.IPv6Loopback?
…et/corefx#30324) * add option to handle TTL for raw socket and system utility * add missing blank line * incorporate feedback and merge with upstream * feedback from review Commit migrated from dotnet/corefx@3035218
related to #9350
This adds TTL option to Unix Ping implementation. It handles both - raw socket as well as system command line utility. I did some testing and -t seems pretty standard even on busybox on Alpine.
Don't fragment will need some more research and testing. It is less common (like busybox does not have it). Also PMTU discovery is default now on Linux so "don't fragment is set by default".
I tested the fix running tests as normal user and root. All existing tests are passing.
To really test this, we would need Outerloop test with some predictable and stable target.