Skip to content

Commit c8970cf

Browse files
sinhphamgretchenfrage
authored andcommitted
Add interface_index to RecvMeta
1 parent 7d7afb5 commit c8970cf

File tree

4 files changed

+12
-0
lines changed

4 files changed

+12
-0
lines changed

quinn-udp/src/fallback.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ impl UdpSocketState {
7272
addr: addr.as_socket().unwrap(),
7373
ecn: None,
7474
dst_ip: None,
75+
interface_index: None,
7576
};
7677
Ok(1)
7778
}

quinn-udp/src/lib.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,8 @@ pub struct RecvMeta {
115115
/// Populated on platforms: Windows, Linux, Android (API level > 25),
116116
/// FreeBSD, OpenBSD, NetBSD, macOS, and iOS.
117117
pub dst_ip: Option<IpAddr>,
118+
/// The interface index of the interface on which the datagram was received
119+
pub interface_index: Option<u32>,
118120
}
119121

120122
impl Default for RecvMeta {
@@ -126,6 +128,7 @@ impl Default for RecvMeta {
126128
stride: 0,
127129
ecn: None,
128130
dst_ip: None,
131+
interface_index: None,
129132
}
130133
}
131134
}

quinn-udp/src/unix.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -704,6 +704,7 @@ fn decode_recv(
704704
let name = unsafe { name.assume_init() };
705705
let mut ecn_bits = 0;
706706
let mut dst_ip = None;
707+
let mut interface_index = None;
707708
#[allow(unused_mut)] // only mutable on Linux
708709
let mut stride = len;
709710

@@ -736,6 +737,7 @@ fn decode_recv(
736737
dst_ip = Some(IpAddr::V4(Ipv4Addr::from(
737738
pktinfo.ipi_addr.s_addr.to_ne_bytes(),
738739
)));
740+
interface_index = Some(pktinfo.ipi_ifindex as u32);
739741
}
740742
#[cfg(any(bsd, apple))]
741743
(libc::IPPROTO_IP, libc::IP_RECVDSTADDR) => {
@@ -745,6 +747,7 @@ fn decode_recv(
745747
(libc::IPPROTO_IPV6, libc::IPV6_PKTINFO) => {
746748
let pktinfo = unsafe { cmsg::decode::<libc::in6_pktinfo, libc::cmsghdr>(cmsg) };
747749
dst_ip = Some(IpAddr::V6(Ipv6Addr::from(pktinfo.ipi6_addr.s6_addr)));
750+
interface_index = Some(pktinfo.ipi6_ifindex as u32);
748751
}
749752
#[cfg(any(target_os = "linux", target_os = "android"))]
750753
(libc::SOL_UDP, gro::UDP_GRO) => unsafe {
@@ -784,6 +787,7 @@ fn decode_recv(
784787
addr,
785788
ecn: EcnCodepoint::from_bits(ecn_bits),
786789
dst_ip,
790+
interface_index,
787791
}
788792
}
789793

quinn-udp/src/windows.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,7 @@ impl UdpSocketState {
225225
// Decode control messages (PKTINFO and ECN)
226226
let mut ecn_bits = 0;
227227
let mut dst_ip = None;
228+
let mut interface_index = None;
228229
let mut stride = len;
229230

230231
let cmsg_iter = unsafe { cmsg::Iter::new(&wsa_msg) };
@@ -238,12 +239,14 @@ impl UdpSocketState {
238239
// Addr is stored in big endian format
239240
let ip4 = Ipv4Addr::from(u32::from_be(unsafe { pktinfo.ipi_addr.S_un.S_addr }));
240241
dst_ip = Some(ip4.into());
242+
interface_index = Some(pktinfo.ipi_ifindex);
241243
}
242244
(WinSock::IPPROTO_IPV6, WinSock::IPV6_PKTINFO) => {
243245
let pktinfo =
244246
unsafe { cmsg::decode::<WinSock::IN6_PKTINFO, WinSock::CMSGHDR>(cmsg) };
245247
// Addr is stored in big endian format
246248
dst_ip = Some(IpAddr::from(unsafe { pktinfo.ipi6_addr.u.Byte }));
249+
interface_index = Some(pktinfo.ipi6_ifindex);
247250
}
248251
(WinSock::IPPROTO_IP, WinSock::IP_ECN) => {
249252
// ECN is a C integer https://learn.microsoft.com/en-us/windows/win32/winsock/winsock-ecn
@@ -268,6 +271,7 @@ impl UdpSocketState {
268271
addr: addr.unwrap(),
269272
ecn: EcnCodepoint::from_bits(ecn_bits as u8),
270273
dst_ip,
274+
interface_index,
271275
};
272276
Ok(1)
273277
}

0 commit comments

Comments
 (0)