Skip to content

Commit

Permalink
Merge #1509 #1515
Browse files Browse the repository at this point in the history
1509: Allow Android to use timerfd r=asomers a=rtzoeller

This is a continuation of #1336 which also enables the timerfd tests.

```
running 3 tests
test sys::test_timerfd::test_timerfd_unset ... ok
test sys::test_timerfd::test_timerfd_oneshot ... ok
test sys::test_timerfd::test_timerfd_interval ... ok
```

1515: Add IP_TTL/IPV6_UNICAST_HOPS SockOpts r=asomers a=cemeyer

Test: `cargo test --test test test_ttl_opts`

Co-authored-by: Ryan Zoeller <rtzoeller@rtzoeller.com>
Co-authored-by: Conrad Meyer <cem@FreeBSD.org>
  • Loading branch information
3 people committed Sep 12, 2021
3 parents f44a506 + 2a31ac1 + 1ce595f commit bf4f273
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 2 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ This project adheres to [Semantic Versioning](https://semver.org/).
(#[1514](https://github.com/nix-rust/nix/pull/1514))
- Added `AsRawFd` implementation on `PollFd`.
(#[1516](https://github.com/nix-rust/nix/pull/1516))
- Added `Ipv4Ttl` and `Ipv6Ttl` sockopts.
(#[1515](https://github.com/nix-rust/nix/pull/1515))

### Changed

Expand Down
2 changes: 1 addition & 1 deletion src/sys/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,6 @@ pub mod wait;
#[allow(missing_docs)]
pub mod inotify;

#[cfg(target_os = "linux")]
#[cfg(any(target_os = "android", target_os = "linux"))]
#[allow(missing_docs)]
pub mod timerfd;
4 changes: 4 additions & 0 deletions src/sys/socket/sockopt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -356,6 +356,10 @@ sockopt_impl!(Both, Ipv6V6Only, libc::IPPROTO_IPV6, libc::IPV6_V6ONLY, bool);
sockopt_impl!(Both, Ipv4RecvErr, libc::IPPROTO_IP, libc::IP_RECVERR, bool);
#[cfg(any(target_os = "android", target_os = "linux"))]
sockopt_impl!(Both, Ipv6RecvErr, libc::IPPROTO_IPV6, libc::IPV6_RECVERR, bool);
#[cfg(any(target_os = "android", target_os = "freebsd", target_os = "linux"))]
sockopt_impl!(Both, Ipv4Ttl, libc::IPPROTO_IP, libc::IP_TTL, libc::c_int);
#[cfg(any(target_os = "android", target_os = "freebsd", target_os = "linux"))]
sockopt_impl!(Both, Ipv6Ttl, libc::IPPROTO_IPV6, libc::IPV6_UNICAST_HOPS, libc::c_int);

#[cfg(any(target_os = "android", target_os = "linux"))]
#[derive(Copy, Clone, Debug)]
Expand Down
2 changes: 1 addition & 1 deletion test/sys/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,5 +41,5 @@ mod test_pthread;
target_os = "netbsd",
target_os = "openbsd"))]
mod test_ptrace;
#[cfg(target_os = "linux")]
#[cfg(any(target_os = "android", target_os = "linux"))]
mod test_timerfd;
11 changes: 11 additions & 0 deletions test/sys/test_sockopt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -186,3 +186,14 @@ fn test_so_tcp_keepalive() {
assert_eq!(getsockopt(fd, sockopt::TcpKeepInterval).unwrap(), x + 1);
}
}

#[test]
#[cfg(any(target_os = "android", target_os = "freebsd", target_os = "linux"))]
fn test_ttl_opts() {
let fd4 = socket(AddressFamily::Inet, SockType::Datagram, SockFlag::empty(), None).unwrap();
setsockopt(fd4, sockopt::Ipv4Ttl, &1)
.expect("setting ipv4ttl on an inet socket should succeed");
let fd6 = socket(AddressFamily::Inet6, SockType::Datagram, SockFlag::empty(), None).unwrap();
setsockopt(fd6, sockopt::Ipv6Ttl, &1)
.expect("setting ipv6ttl on an inet6 socket should succeed");
}

0 comments on commit bf4f273

Please sign in to comment.