Skip to content

Commit

Permalink
Merge #1867
Browse files Browse the repository at this point in the history
1867: Add routing socket type on macOS r=asomers a=pinkisemils

This is a small change to add the routing socket type to the list of socket types one can open with `nix`. I've added a smoke test to see that a socket of such type can actually be opened, but I'm not sure if such a test belongs in the codebase here.

Co-authored-by: Emils <emils@mullvad.net>
  • Loading branch information
bors[bot] and pinkisemils authored Nov 29, 2022
2 parents f263f45 + d08d4e2 commit ed8319c
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 0 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ This project adheres to [Semantic Versioning](https://semver.org/).

## [Unreleased] - ReleaseDate
### Added
- Add `PF_ROUTE` to `SockType` on macOS, iOS, all of the BSDs, Fuchsia, Haiku, Illumos.
([#1867](https://github.com/nix-rust/nix/pull/1867))

### Changed
### Fixed
### Removed
Expand Down
5 changes: 5 additions & 0 deletions src/sys/socket/addr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,9 @@ pub enum AddressFamily {
#[cfg(any(target_os = "android", target_os = "linux"))]
#[cfg_attr(docsrs, doc(cfg(all())))]
Netlink = libc::AF_NETLINK,
/// Kernel interface for interacting with the routing table
#[cfg(not(any(target_os = "redox", target_os = "linux", target_os = "android")))]
Route = libc::PF_ROUTE,
/// Low level packet interface (see [`packet(7)`](https://man7.org/linux/man-pages/man7/packet.7.html))
#[cfg(any(
target_os = "android",
Expand Down Expand Up @@ -421,6 +424,8 @@ impl AddressFamily {
libc::AF_NETLINK => Some(AddressFamily::Netlink),
#[cfg(any(target_os = "macos", target_os = "macos"))]
libc::AF_SYSTEM => Some(AddressFamily::System),
#[cfg(not(any(target_os = "redox", target_os = "linux", target_os = "android")))]
libc::PF_ROUTE => Some(AddressFamily::Route),
#[cfg(any(target_os = "android", target_os = "linux"))]
libc::AF_PACKET => Some(AddressFamily::Packet),
#[cfg(any(
Expand Down
12 changes: 12 additions & 0 deletions src/sys/socket/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2484,4 +2484,16 @@ mod tests {
fn can_use_cmsg_space() {
let _ = cmsg_space!(u8);
}

#[cfg(not(any(target_os = "redox", target_os = "linux", target_os = "android")))]
#[test]
fn can_open_routing_socket() {
let _ = super::socket(
super::AddressFamily::Route,
super::SockType::Raw,
super::SockFlag::empty(),
None,
)
.expect("Failed to open routing socket");
}
}

0 comments on commit ed8319c

Please sign in to comment.