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

Currently socket2 has no way to set the DF bit on packets. The attached patch adds it. #487

Open
jcdutton opened this issue Jan 8, 2024 · 3 comments

Comments

@jcdutton
Copy link

jcdutton commented Jan 8, 2024

socket2.diff.txt
Hi,
Currently socket2 has no way to set the DF bit on packets.
The DF bit is needed for Path MTU discovery and also for creating arbitrary ICMP packets with the DF bit set.
Please see the attached patch that will add it.
I have only been able to test it on Linux, not Windows.
This might also be needed to enable Path MTU discovery on TCP sessions when using socket2.

For example, some sample code to send an ICMP packet with the DF bit set:
let domain = Domain::IPV4;
let ty = Type::DGRAM;
let protocol = Some(Protocol::ICMPV4);
let mut sock1 = create_socket(domain, ty, protocol);
let mut sock1r = sock1.unwrap();
let res1 = Socket::set_mtu_discover(&sock1r, true);
let mut sock2 = sock1r;
sock2.set_read_timeout(Some(timeout))?;
let destination = SocketAddr::new(addr.clone(), 0); // destination
let sockaddr1: SockAddr = destination.into();
let result = make_data(&data, size3);
let payload = result.unwrap();
let res2 = sock2.send_to(&payload, &sockaddr1);

@Thomasdezeeuw
Copy link
Collaborator

Pull request would be welcome.

@jcdutton
Copy link
Author

jcdutton commented Jan 17, 2024

@Thomasdezeeuw

Pull request would be welcome.

I would like someone else to check it does not break socket2 on other platforms first (e.g. windows), and maybe re-craft it to work on more platforms before we commit it. For example, I don't know if I have put "use libc;" in a place that will work on windows platforms.
I have tested it on Linux x86_64 but nothing else.

@Thomasdezeeuw
Copy link
Collaborator

@jcdutton we have our CI setup for that. It tests on 3 platforms and builds on a large number of others. You can use it if you send a pull request.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants