Skip to content

Commit a8df4d3

Browse files
committed
Add ControlMessage::Ipv6MulticastHopLimit
When sending IPv6 multicast 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::Ipv6MulticastHopLimit` to specify the limit.
1 parent 75a26cd commit a8df4d3

File tree

1 file changed

+25
-2
lines changed

1 file changed

+25
-2
lines changed

src/sys/socket/mod.rs

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

1115-
/// Configure the sending addressing and interface for v4
1115+
/// Configure the sending addressing and interface for v4.
11161116
///
11171117
/// For further information, please refer to the
11181118
/// [`ip(7)`](https://man7.org/linux/man-pages/man7/ip.7.html) man page.
@@ -1125,7 +1125,7 @@ pub enum ControlMessage<'a> {
11251125
#[cfg_attr(docsrs, doc(cfg(feature = "net")))]
11261126
Ipv4PacketInfo(&'a libc::in_pktinfo),
11271127

1128-
/// Configure the sending addressing and interface for v6
1128+
/// Configure the sending addressing and interface for v6.
11291129
///
11301130
/// For further information, please refer to the
11311131
/// [`ipv6(7)`](https://man7.org/linux/man-pages/man7/ipv6.7.html) man page.
@@ -1150,6 +1150,18 @@ pub enum ControlMessage<'a> {
11501150
#[cfg_attr(docsrs, doc(cfg(feature = "net")))]
11511151
Ipv4SendSrcAddr(&'a libc::in_addr),
11521152

1153+
/// Configure the hop limit for v6 multicast traffic.
1154+
///
1155+
/// Set the multicast hop limit for this message. The argument is an
1156+
/// integer between 0 and 255. Other than the default, the value -1 will
1157+
/// set the hop limit to 1, not the route default. Without this cmsg, UDP
1158+
/// packets sent with sendmsg have a hop limit of 1 and will not leave the
1159+
/// local network.
1160+
/// For further information, please refer to the
1161+
/// [`ipv6(7)`](https://man7.org/linux/man-pages/man7/ipv6.7.html) man page.
1162+
#[cfg(any(target_os = "linux"))]
1163+
Ipv6MulticastHopLimit(&'a libc::c_int),
1164+
11531165
/// SO_RXQ_OVFL indicates that an unsigned 32 bit value
11541166
/// ancilliary msg (cmsg) should be attached to recieved
11551167
/// skbs indicating the number of packets dropped by the
@@ -1263,6 +1275,8 @@ impl<'a> ControlMessage<'a> {
12631275
target_os = "openbsd", target_os = "dragonfly"))]
12641276
#[cfg(feature = "net")]
12651277
ControlMessage::Ipv4SendSrcAddr(addr) => addr as *const _ as *const u8,
1278+
#[cfg(any(target_os = "linux"))]
1279+
ControlMessage::Ipv6MulticastHopLimit(limit) => limit as *const _ as *const u8,
12661280
#[cfg(any(target_os = "android", target_os = "fuchsia", target_os = "linux"))]
12671281
ControlMessage::RxqOvfl(drop_count) => {
12681282
drop_count as *const _ as *const u8
@@ -1326,6 +1340,10 @@ impl<'a> ControlMessage<'a> {
13261340
target_os = "openbsd", target_os = "dragonfly"))]
13271341
#[cfg(feature = "net")]
13281342
ControlMessage::Ipv4SendSrcAddr(addr) => mem::size_of_val(addr),
1343+
#[cfg(any(target_os = "linux"))]
1344+
ControlMessage::Ipv6MulticastHopLimit(limit) => {
1345+
mem::size_of_val(limit)
1346+
},
13291347
#[cfg(any(target_os = "android", target_os = "fuchsia", target_os = "linux"))]
13301348
ControlMessage::RxqOvfl(drop_count) => {
13311349
mem::size_of_val(drop_count)
@@ -1365,6 +1383,9 @@ impl<'a> ControlMessage<'a> {
13651383
target_os = "openbsd", target_os = "dragonfly"))]
13661384
#[cfg(feature = "net")]
13671385
ControlMessage::Ipv4SendSrcAddr(_) => libc::IPPROTO_IP,
1386+
#[cfg(any(target_os = "linux"))]
1387+
#[cfg(feature = "net")]
1388+
ControlMessage::Ipv6MulticastHopLimit(_) => libc::IPPROTO_IPV6,
13681389
#[cfg(any(target_os = "android", target_os = "fuchsia", target_os = "linux"))]
13691390
ControlMessage::RxqOvfl(_) => libc::SOL_SOCKET,
13701391
#[cfg(target_os = "linux")]
@@ -1411,6 +1432,8 @@ impl<'a> ControlMessage<'a> {
14111432
target_os = "openbsd", target_os = "dragonfly"))]
14121433
#[cfg(feature = "net")]
14131434
ControlMessage::Ipv4SendSrcAddr(_) => libc::IP_SENDSRCADDR,
1435+
#[cfg(any(target_os = "linux"))]
1436+
ControlMessage::Ipv6MulticastHopLimit(_) => libc::IPV6_HOPLIMIT,
14141437
#[cfg(any(target_os = "android", target_os = "fuchsia", target_os = "linux"))]
14151438
ControlMessage::RxqOvfl(_) => {
14161439
libc::SO_RXQ_OVFL

0 commit comments

Comments
 (0)