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

Use socket connections for TCP tracing #134

Closed
fujiapple852 opened this issue May 6, 2022 · 0 comments · Fixed by #147
Closed

Use socket connections for TCP tracing #134

fujiapple852 opened this issue May 6, 2022 · 0 comments · Fixed by #147
Labels
enhancement New feature or request tcp
Milestone

Comments

@fujiapple852
Copy link
Owner

fujiapple852 commented May 6, 2022

Current approach

The current approach for tcp probing is to construct a TcpPacket and then send_to it over channel constructed with:

TransportChannelType::Layer4(TransportProtocol::Ipv4(IpNextHeaderProtocols::Tcp))

Which is effectively:

socket(AF_INET, SOCK_RAW, 6)

Problem

With this setup, response packets (syn / rst) are never delivered to the socket as, presumably, we have never called bind or connect. We're essentially sending a tcp packet. as a datagram.

Whilst this works to a point (we can receive the icmp TimeExceeded responses to get the bulk of the trace), we don't receive syn / rst / ack and so we don't ever get the response from the target.

Solution

The solution is to create a normal (not raw socket) TCP connection to the target.

The tool mtr takes a similar approach, see construct_ip4_packet() and open_stream_socket() in construct_unix.c where it goes through a normal socket -> bind -> connect setup.

See also receive_replies_from_probe_socket() in probe_unix.c for where the the per-probe TCP socket is checked using select and a successful connection or ECONNREFUSED is used to indicate that the target has responded.

@fujiapple852 fujiapple852 added enhancement New feature or request tcp labels May 6, 2022
@fujiapple852 fujiapple852 added this to the 0.4.0 milestone May 6, 2022
@fujiapple852 fujiapple852 self-assigned this May 9, 2022
@fujiapple852 fujiapple852 changed the title Use connect for TCP tracing Use socket connections for TCP tracing May 13, 2022
@fujiapple852 fujiapple852 removed their assignment May 15, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request tcp
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant