Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix ping with TTL on Linux #99875

Merged
merged 6 commits into from
Apr 16, 2024
Merged

fix ping with TTL on Linux #99875

merged 6 commits into from
Apr 16, 2024

Conversation

wfurt
Copy link
Member

@wfurt wfurt commented Mar 17, 2024

fixes #73232 and #99838.
This was very old regression caused by dotnet/corefx#34084.
While calling Connect on the socket fixes the problem of receiving unrelated messages it also prevents receiving ICMP from intermediate notes as @filipnavara noticed in #73232 (comment).

We could revert the change and implement additional filtering. However it is convenient to let Kernel do it (and work just fine on macOS & FreeBSD). So this change subscribes explicitly to error message and it receives additional information via struct sock_extended_err.

Before the change simple trace route:

furt@kamna:~/projects/ping$ ~/dotnet-latest/dotnet run
Status: TimeExceeded Address: 192.168.0.1
Status: TimeExceeded Address: 63.142.208.1
Status: TimedOut Address: 0.0.0.0
Status: TimeExceeded Address: 142.250.175.168
Status: TimeExceeded Address: 142.251.70.99
Status: TimeExceeded Address: 209.85.254.171
Status: Success Address: 8.8.8.8

and

furt@kamna:~/projects/ping$ sudo ~/dotnet-latest/dotnet bin/Debug/net9.0/ping.dll
Status: TimedOut Address: 0.0.0.0
Status: TimedOut Address: 0.0.0.0
Status: TimedOut Address: 0.0.0.0
Status: TimedOut Address: 0.0.0.0
Status: TimedOut Address: 0.0.0.0
Status: TimedOut Address: 0.0.0.0
Status: Success Address: 8.8.8.8

e.g. the raw socket implementation did not work. With the fix I get same result.

furt@kamna:~/projects/ping$ sudo bin/Release/net9.0/linux-x64/publish/ping
Status: TtlExpired Address: 192.168.0.1
Status: TtlExpired Address: 63.142.208.1
Status: TimedOut Address: 0.0.0.0
Status: TtlExpired Address: 142.250.175.168
Status: TtlExpired Address: 142.251.70.99
Status: TtlExpired Address: 209.85.254.171
Status: Success Address: 8.8.8.8

I don;t have IPv6 connectivity to test IPv6. But nothing in the new code seems IPv4 specific.

@wfurt wfurt requested a review from a team March 18, 2024 03:05
@wfurt wfurt added this to the 9.0.0 milestone Mar 18, 2024
@wfurt wfurt marked this pull request as ready for review March 18, 2024 03:06
@liveans liveans self-requested a review April 10, 2024 20:23
@liveans
Copy link
Member

liveans commented Apr 10, 2024

I'll take a look at this, tomorrow.

Copy link
Member

@liveans liveans left a comment

Choose a reason for hiding this comment

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

LGTM, do you think is there an easy way to add a test for it?

{
SocketConfig socketConfig = GetSocketConfig(address, buffer, timeout, options);
using (Socket socket = GetRawSocket(socketConfig))
{
Span<byte> socketAddress = stackalloc byte[SocketAddress.GetMaximumAddressSize(address.AddressFamily)];
Copy link
Member

Choose a reason for hiding this comment

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

nit: move this just before its first usage, at line 288.

Copy link
Member Author

Choose a reason for hiding this comment

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

Ping.RawSocket.cs(287,48): error CS0255: stackalloc may not be used in a catch or finally block

@wfurt
Copy link
Member Author

wfurt commented Apr 15, 2024

all test failures are known issues.

@wfurt
Copy link
Member Author

wfurt commented Apr 16, 2024

all test failures are known issues.

@wfurt wfurt merged commit 1e42214 into dotnet:main Apr 16, 2024
159 of 163 checks passed
@wfurt wfurt deleted the ping branch April 16, 2024 20:22
matouskozak pushed a commit to matouskozak/runtime that referenced this pull request Apr 30, 2024
* fix ping with TTL on Linux

* feedback

* feedback
@github-actions github-actions bot locked and limited conversation to collaborators May 17, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Ping class responding Timedout not reading response when ICMP Time-to-live exceeded.
5 participants