Skip to content

Commit 1203d6c

Browse files
Merge #1289
1289: Add Netlink Protocol Families to SockProtocol enum r=asomers a=sinkingpoint Currently the SockProtocol enum is rather scarce. This commit adds the Netlink protocols defined in netlink(7) to the SockProtocol enum allowing us to use the Nix socket library for more in-depth Netlink work. Because of the way libc sockets work, this is a bit more annoying than it has any right to be - the Socket Family and the Socket protocol are intertwined in that a given c_int protocol can represent different things depending on the family. This means that as we add values to this enum we're going to get collisions (Indeed, I've left out a few values that collided with the existing TCP/UDP Protocols). I'm not sure how we would want to handle this going forward - maybe different Protocol enums for different Familys, with `Into<SockProtocol>` methods? I followed the existing pattern in this file when adding these, but perhaps as this enum gets bigger, we should use the libc_enum macro for cleanliness? Co-authored-by: sinkingpoint <[email protected]>
2 parents 83db58c + 481424e commit 1203d6c

File tree

2 files changed

+60
-0
lines changed

2 files changed

+60
-0
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ All notable changes to this project will be documented in this file.
44
This project adheres to [Semantic Versioning](http://semver.org/).
55

66
## [Unreleased] - ReleaseDate
7+
- Added Netlink protocol families to the `SockProtocol` enum
8+
(#[1289](https://github.com/nix-rust/nix/pull/1289))
79
### Added
810
### Changed
911
### Fixed

src/sys/socket/mod.rs

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,64 @@ pub enum SockProtocol {
9292
/// ([ref](https://developer.apple.com/library/content/documentation/Darwin/Conceptual/NKEConceptual/control/control.html))
9393
#[cfg(any(target_os = "ios", target_os = "macos"))]
9494
KextControl = libc::SYSPROTO_CONTROL,
95+
/// Receives routing and link updates and may be used to modify the routing tables (both IPv4 and IPv6), IP addresses, link
96+
// parameters, neighbor setups, queueing disciplines, traffic classes and packet classifiers
97+
/// ([ref](https://www.man7.org/linux/man-pages/man7/netlink.7.html))
98+
#[cfg(any(target_os = "android", target_os = "linux"))]
99+
NetlinkRoute = libc::NETLINK_ROUTE,
100+
/// Reserved for user-mode socket protocols
101+
/// ([ref](https://www.man7.org/linux/man-pages/man7/netlink.7.html))
102+
#[cfg(any(target_os = "android", target_os = "linux"))]
103+
NetlinkUserSock = libc::NETLINK_USERSOCK,
104+
/// Query information about sockets of various protocol families from the kernel
105+
/// ([ref](https://www.man7.org/linux/man-pages/man7/netlink.7.html))
106+
#[cfg(any(target_os = "android", target_os = "linux"))]
107+
NetlinkSockDiag = libc::NETLINK_SOCK_DIAG,
108+
/// SELinux event notifications.
109+
/// ([ref](https://www.man7.org/linux/man-pages/man7/netlink.7.html))
110+
#[cfg(any(target_os = "android", target_os = "linux"))]
111+
NetlinkSELinux = libc::NETLINK_SELINUX,
112+
/// Open-iSCSI
113+
/// ([ref](https://www.man7.org/linux/man-pages/man7/netlink.7.html))
114+
#[cfg(any(target_os = "android", target_os = "linux"))]
115+
NetlinkISCSI = libc::NETLINK_ISCSI,
116+
/// Auditing
117+
/// ([ref](https://www.man7.org/linux/man-pages/man7/netlink.7.html))
118+
#[cfg(any(target_os = "android", target_os = "linux"))]
119+
NetlinkAudit = libc::NETLINK_AUDIT,
120+
/// Access to FIB lookup from user space
121+
/// ([ref](https://www.man7.org/linux/man-pages/man7/netlink.7.html))
122+
#[cfg(any(target_os = "android", target_os = "linux"))]
123+
NetlinkFIBLookup = libc::NETLINK_FIB_LOOKUP,
124+
/// Netfilter subsystem
125+
/// ([ref](https://www.man7.org/linux/man-pages/man7/netlink.7.html))
126+
#[cfg(any(target_os = "android", target_os = "linux"))]
127+
NetlinkNetFilter = libc::NETLINK_NETFILTER,
128+
/// SCSI Transports
129+
/// ([ref](https://www.man7.org/linux/man-pages/man7/netlink.7.html))
130+
#[cfg(any(target_os = "android", target_os = "linux"))]
131+
NetlinkSCSITransport = libc::NETLINK_SCSITRANSPORT,
132+
/// Infiniband RDMA
133+
/// ([ref](https://www.man7.org/linux/man-pages/man7/netlink.7.html))
134+
#[cfg(any(target_os = "android", target_os = "linux"))]
135+
NetlinkRDMA = libc::NETLINK_RDMA,
136+
/// Transport IPv6 packets from netfilter to user space. Used by ip6_queue kernel module.
137+
/// ([ref](https://www.man7.org/linux/man-pages/man7/netlink.7.html))
138+
#[cfg(any(target_os = "android", target_os = "linux"))]
139+
NetlinkIPv6Firewall = libc::NETLINK_IP6_FW,
140+
/// DECnet routing messages
141+
/// ([ref](https://www.man7.org/linux/man-pages/man7/netlink.7.html))
142+
#[cfg(any(target_os = "android", target_os = "linux"))]
143+
NetlinkDECNetRoutingMessage = libc::NETLINK_DNRTMSG,
144+
/// Kernel messages to user space
145+
/// ([ref](https://www.man7.org/linux/man-pages/man7/netlink.7.html))
146+
#[cfg(any(target_os = "android", target_os = "linux"))]
147+
NetlinkKObjectUEvent = libc::NETLINK_KOBJECT_UEVENT,
148+
/// Netlink interface to request information about ciphers registered with the kernel crypto API as well as allow
149+
/// configuration of the kernel crypto API.
150+
/// ([ref](https://www.man7.org/linux/man-pages/man7/netlink.7.html))
151+
#[cfg(any(target_os = "android", target_os = "linux"))]
152+
NetlinkCrypto = libc::NETLINK_CRYPTO,
95153
}
96154

97155
libc_bitflags!{

0 commit comments

Comments
 (0)