Skip to content

Commit 3b786fd

Browse files
bors[bot]junhochoi
andauthored
Merge #1692
1692: Add IP_DONTFRAG and IPV6_DONTFRAG SockOpts r=rtzoeller a=junhochoi IP_DONTFRAG: iOS, macOS IPV6_DONTFRAG: android, iOS, linux and macOS Test: `cargo test --test test dontfrag_opts` Some CI tests running ENOPROTOOPT are disabled. Co-authored-by: Junho Choi <[email protected]>
2 parents 131fdf1 + a4b5dfc commit 3b786fd

File tree

3 files changed

+55
-0
lines changed

3 files changed

+55
-0
lines changed

CHANGELOG.md

+3
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,9 @@ This project adheres to [Semantic Versioning](https://semver.org/).
6161
(#[1670](https://github.com/nix-rust/nix/pull/1670))
6262
- Added `waitid`.
6363
(#[1584](https://github.com/nix-rust/nix/pull/1584))
64+
- Added `Ipv6DontFrag` for android, iOS, linux and macOS.
65+
- Added `IpDontFrag` for iOS, macOS.
66+
(#[1692](https://github.com/nix-rust/nix/pull/1692))
6467

6568
### Changed
6669

src/sys/socket/sockopt.rs

+13
Original file line numberDiff line numberDiff line change
@@ -615,6 +615,19 @@ sockopt_impl!(
615615
sockopt_impl!(
616616
/// Set the unicast hop limit for the socket.
617617
Ipv6Ttl, Both, libc::IPPROTO_IPV6, libc::IPV6_UNICAST_HOPS, libc::c_int);
618+
#[cfg(any(target_os = "ios", target_os = "macos"))]
619+
sockopt_impl!(
620+
/// Set "don't fragment packet" flag on the IP packet.
621+
IpDontFrag, Both, libc::IPPROTO_IP, libc::IP_DONTFRAG, bool);
622+
#[cfg(any(
623+
target_os = "android",
624+
target_os = "ios",
625+
target_os = "linux",
626+
target_os = "macos",
627+
))]
628+
sockopt_impl!(
629+
/// Set "don't fragment packet" flag on the IPv6 packet.
630+
Ipv6DontFrag, Both, libc::IPPROTO_IPV6, libc::IPV6_DONTFRAG, bool);
618631

619632
#[allow(missing_docs)]
620633
// Not documented by Linux!

test/sys/test_sockopt.rs

+39
Original file line numberDiff line numberDiff line change
@@ -196,3 +196,42 @@ fn test_ttl_opts() {
196196
setsockopt(fd6, sockopt::Ipv6Ttl, &1)
197197
.expect("setting ipv6ttl on an inet6 socket should succeed");
198198
}
199+
200+
#[test]
201+
#[cfg(any(target_os = "ios", target_os = "macos"))]
202+
fn test_dontfrag_opts() {
203+
let fd4 = socket(AddressFamily::Inet, SockType::Stream, SockFlag::empty(), SockProtocol::Tcp).unwrap();
204+
setsockopt(fd4, sockopt::IpDontFrag, &true)
205+
.expect("setting IP_DONTFRAG on an inet stream socket should succeed");
206+
setsockopt(fd4, sockopt::IpDontFrag, &false)
207+
.expect("unsetting IP_DONTFRAG on an inet stream socket should succeed");
208+
let fd4d = socket(AddressFamily::Inet, SockType::Datagram, SockFlag::empty(), None).unwrap();
209+
setsockopt(fd4d, sockopt::IpDontFrag, &true)
210+
.expect("setting IP_DONTFRAG on an inet datagram socket should succeed");
211+
setsockopt(fd4d, sockopt::IpDontFrag, &false)
212+
.expect("unsetting IP_DONTFRAG on an inet datagram socket should succeed");
213+
}
214+
215+
#[test]
216+
#[cfg(any(
217+
target_os = "android",
218+
target_os = "ios",
219+
target_os = "linux",
220+
target_os = "macos",
221+
)
222+
)]
223+
// Disable the test under emulation because it fails in Cirrus-CI. Lack
224+
// of QEMU support is suspected.
225+
#[cfg_attr(qemu, ignore)]
226+
fn test_v6dontfrag_opts() {
227+
let fd6 = socket(AddressFamily::Inet6, SockType::Stream, SockFlag::empty(), SockProtocol::Tcp).unwrap();
228+
setsockopt(fd6, sockopt::Ipv6DontFrag, &true)
229+
.expect("setting IPV6_DONTFRAG on an inet6 stream socket should succeed");
230+
setsockopt(fd6, sockopt::Ipv6DontFrag, &false)
231+
.expect("unsetting IPV6_DONTFRAG on an inet6 stream socket should succeed");
232+
let fd6d = socket(AddressFamily::Inet6, SockType::Datagram, SockFlag::empty(), None).unwrap();
233+
setsockopt(fd6d, sockopt::Ipv6DontFrag, &true)
234+
.expect("setting IPV6_DONTFRAG on an inet6 datagram socket should succeed");
235+
setsockopt(fd6d, sockopt::Ipv6DontFrag, &false)
236+
.expect("unsetting IPV6_DONTFRAG on an inet6 datagram socket should succeed");
237+
}

0 commit comments

Comments
 (0)