Skip to content

Commit 9adc8e2

Browse files
committed
2075: Add ControlMessage::Ipv6HopLimit
When sending IPv6 packets with `sendmsg`, Linux does not use the hop limit set on the socket. Instead, the hop limit has to be specified for each individual message with ancillary data in a cmsg. This commit adds the enum variant `ControlMessage::Ipv6HopLimit` to specify the limit.
1 parent c375a10 commit 9adc8e2

File tree

2 files changed

+27
-9
lines changed

2 files changed

+27
-9
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ This project adheres to [Semantic Versioning](https://semver.org/).
2121
- Added `SOF_TIMESTAMPING_OPT_ID` and `SOF_TIMESTAMPING_OPT_TSONLY` to `nix::sys::socket::TimestampingFlag`.
2222
([#2048](https://github.com/nix-rust/nix/pull/2048))
2323
- Enabled socket timestamping options on Android. ([#2077](https://github.com/nix-rust/nix/pull/2077))
24+
- Added `Ipv6HopLimit` to `::nix::sys::socket::ControlMessage` for linux.
25+
([#2074](https://github.com/nix-rust/nix/pull/2074))
2426

2527
### Changed
2628

src/sys/socket/mod.rs

Lines changed: 25 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1116,7 +1116,7 @@ pub enum ControlMessage<'a> {
11161116
#[cfg_attr(docsrs, doc(cfg(feature = "net")))]
11171117
UdpGsoSegments(&'a u16),
11181118

1119-
/// Configure the sending addressing and interface for v4
1119+
/// Configure the sending addressing and interface for v4.
11201120
///
11211121
/// For further information, please refer to the
11221122
/// [`ip(7)`](https://man7.org/linux/man-pages/man7/ip.7.html) man page.
@@ -1129,7 +1129,7 @@ pub enum ControlMessage<'a> {
11291129
#[cfg_attr(docsrs, doc(cfg(feature = "net")))]
11301130
Ipv4PacketInfo(&'a libc::in_pktinfo),
11311131

1132-
/// Configure the sending addressing and interface for v6
1132+
/// Configure the sending addressing and interface for v6.
11331133
///
11341134
/// For further information, please refer to the
11351135
/// [`ipv6(7)`](https://man7.org/linux/man-pages/man7/ipv6.7.html) man page.
@@ -1154,6 +1154,17 @@ pub enum ControlMessage<'a> {
11541154
#[cfg_attr(docsrs, doc(cfg(feature = "net")))]
11551155
Ipv4SendSrcAddr(&'a libc::in_addr),
11561156

1157+
/// Configure the hop limit for v6 multicast traffic.
1158+
///
1159+
/// Set the IPv6 hop limit for this message. The argument is an integer
1160+
/// between 0 and 255. A value of -1 will set the hop limit to the route
1161+
/// default if possible on the interface. Without this cmsg, packets sent
1162+
/// with sendmsg have a hop limit of 1 and will not leave the local network.
1163+
/// For further information, please refer to the
1164+
/// [`ipv6(7)`](https://man7.org/linux/man-pages/man7/ipv6.7.html) man page.
1165+
#[cfg(any(target_os = "linux"))]
1166+
Ipv6HopLimit(&'a libc::c_int),
1167+
11571168
/// SO_RXQ_OVFL indicates that an unsigned 32 bit value
11581169
/// ancilliary msg (cmsg) should be attached to recieved
11591170
/// skbs indicating the number of packets dropped by the
@@ -1267,6 +1278,8 @@ impl<'a> ControlMessage<'a> {
12671278
target_os = "openbsd", target_os = "dragonfly"))]
12681279
#[cfg(feature = "net")]
12691280
ControlMessage::Ipv4SendSrcAddr(addr) => addr as *const _ as *const u8,
1281+
#[cfg(any(target_os = "linux"))]
1282+
ControlMessage::Ipv6HopLimit(limit) => limit as *const _ as *const u8,
12701283
#[cfg(any(target_os = "android", target_os = "fuchsia", target_os = "linux"))]
12711284
ControlMessage::RxqOvfl(drop_count) => {
12721285
drop_count as *const _ as *const u8
@@ -1330,6 +1343,10 @@ impl<'a> ControlMessage<'a> {
13301343
target_os = "openbsd", target_os = "dragonfly"))]
13311344
#[cfg(feature = "net")]
13321345
ControlMessage::Ipv4SendSrcAddr(addr) => mem::size_of_val(addr),
1346+
#[cfg(any(target_os = "linux"))]
1347+
ControlMessage::Ipv6HopLimit(limit) => {
1348+
mem::size_of_val(limit)
1349+
},
13331350
#[cfg(any(target_os = "android", target_os = "fuchsia", target_os = "linux"))]
13341351
ControlMessage::RxqOvfl(drop_count) => {
13351352
mem::size_of_val(drop_count)
@@ -1369,6 +1386,9 @@ impl<'a> ControlMessage<'a> {
13691386
target_os = "openbsd", target_os = "dragonfly"))]
13701387
#[cfg(feature = "net")]
13711388
ControlMessage::Ipv4SendSrcAddr(_) => libc::IPPROTO_IP,
1389+
#[cfg(any(target_os = "linux"))]
1390+
#[cfg(feature = "net")]
1391+
ControlMessage::Ipv6HopLimit(_) => libc::IPPROTO_IPV6,
13721392
#[cfg(any(target_os = "android", target_os = "fuchsia", target_os = "linux"))]
13731393
ControlMessage::RxqOvfl(_) => libc::SOL_SOCKET,
13741394
#[cfg(target_os = "linux")]
@@ -1415,6 +1435,8 @@ impl<'a> ControlMessage<'a> {
14151435
target_os = "openbsd", target_os = "dragonfly"))]
14161436
#[cfg(feature = "net")]
14171437
ControlMessage::Ipv4SendSrcAddr(_) => libc::IP_SENDSRCADDR,
1438+
#[cfg(any(target_os = "linux"))]
1439+
ControlMessage::Ipv6HopLimit(_) => libc::IPV6_HOPLIMIT,
14181440
#[cfg(any(target_os = "android", target_os = "fuchsia", target_os = "linux"))]
14191441
ControlMessage::RxqOvfl(_) => {
14201442
libc::SO_RXQ_OVFL
@@ -2240,13 +2262,7 @@ pub fn recvfrom<T: SockaddrLike>(
22402262
&mut len as *mut socklen_t,
22412263
))? as usize;
22422264

2243-
Ok((
2244-
ret,
2245-
T::from_raw(
2246-
addr.assume_init().as_ptr(),
2247-
Some(len),
2248-
),
2249-
))
2265+
Ok((ret, T::from_raw(addr.assume_init().as_ptr(), Some(len))))
22502266
}
22512267
}
22522268

0 commit comments

Comments
 (0)