@@ -1000,11 +1000,13 @@ pub(crate) fn set_xdp_rx_ring_size(fd: BorrowedFd<'_>, value: u32) -> io::Result
1000
1000
#[ cfg( target_os = "linux" ) ]
1001
1001
#[ inline]
1002
1002
pub ( crate ) fn get_xdp_mmap_offsets ( fd : BorrowedFd < ' _ > ) -> io:: Result < XdpMmapOffsets > {
1003
- // The kernel will write `xdp_mmap_offsets` or `xdp_mmap_offsets_v1` to the supplied pointer,
1004
- // depending on the kernel version. Both structs only contain u64 values.
1005
- // By using the larger of both as the parameter, we can shuffle the values to the non-v1 version
1006
- // returned by `get_xdp_mmap_offsets` while keeping the return type unaffected by the kernel
1007
- // version. This works because C will layout all struct members one after the other.
1003
+ // The kernel will write `xdp_mmap_offsets` or `xdp_mmap_offsets_v1` to the
1004
+ // supplied pointer, depending on the kernel version. Both structs only
1005
+ // contain u64 values. By using the larger of both as the parameter, we can
1006
+ // shuffle the values to the non-v1 version returned by
1007
+ // `get_xdp_mmap_offsets` while keeping the return type unaffected by the
1008
+ // kernel version. This works because C will layout all struct members one
1009
+ // after the other.
1008
1010
1009
1011
let mut optlen = core:: mem:: size_of :: < xdp_mmap_offsets > ( ) . try_into ( ) . unwrap ( ) ;
1010
1012
debug_assert ! (
@@ -1015,8 +1017,8 @@ pub(crate) fn get_xdp_mmap_offsets(fd: BorrowedFd<'_>) -> io::Result<XdpMmapOffs
1015
1017
getsockopt_raw ( fd, c:: SOL_XDP , c:: XDP_MMAP_OFFSETS , & mut value, & mut optlen) ?;
1016
1018
1017
1019
if optlen as usize == core:: mem:: size_of :: < c:: xdp_mmap_offsets_v1 > ( ) {
1018
- // Safety: All members of xdp_mmap_offsets are u64 and thus are correctly initialized
1019
- // by `MaybeUninit::<xdp_statistics>::zeroed()`
1020
+ // Safety: All members of xdp_mmap_offsets are u64 and thus are correctly
1021
+ // initialized by `MaybeUninit::<xdp_statistics>::zeroed()`
1020
1022
let xpd_mmap_offsets = unsafe { value. assume_init ( ) } ;
1021
1023
Ok ( XdpMmapOffsets {
1022
1024
rx : XdpRingOffset {
@@ -1050,8 +1052,8 @@ pub(crate) fn get_xdp_mmap_offsets(fd: BorrowedFd<'_>) -> io::Result<XdpMmapOffs
1050
1052
core:: mem:: size_of:: <xdp_mmap_offsets>( ) ,
1051
1053
"unexpected getsockopt size"
1052
1054
) ;
1053
- // Safety: All members of xdp_mmap_offsets are u64 and thus are correctly initialized
1054
- // by `MaybeUninit::<xdp_statistics>::zeroed()`
1055
+ // Safety: All members of xdp_mmap_offsets are u64 and thus are correctly
1056
+ // initialized by `MaybeUninit::<xdp_statistics>::zeroed()`
1055
1057
let xpd_mmap_offsets = unsafe { value. assume_init ( ) } ;
1056
1058
Ok ( XdpMmapOffsets {
1057
1059
rx : XdpRingOffset {
@@ -1094,8 +1096,8 @@ pub(crate) fn get_xdp_statistics(fd: BorrowedFd<'_>) -> io::Result<XdpStatistics
1094
1096
getsockopt_raw ( fd, c:: SOL_XDP , c:: XDP_STATISTICS , & mut value, & mut optlen) ?;
1095
1097
1096
1098
if optlen as usize == core:: mem:: size_of :: < xdp_statistics_v1 > ( ) {
1097
- // Safety: All members of xdp_statistics are u64 and thus are correctly initialized
1098
- // by `MaybeUninit::<xdp_statistics>::zeroed()`
1099
+ // Safety: All members of xdp_statistics are u64 and thus are correctly
1100
+ // initialized by `MaybeUninit::<xdp_statistics>::zeroed()`
1099
1101
let xdp_statistics = unsafe { value. assume_init ( ) } ;
1100
1102
Ok ( XdpStatistics {
1101
1103
rx_dropped : xdp_statistics. rx_dropped ,
@@ -1111,8 +1113,8 @@ pub(crate) fn get_xdp_statistics(fd: BorrowedFd<'_>) -> io::Result<XdpStatistics
1111
1113
core:: mem:: size_of:: <xdp_statistics>( ) ,
1112
1114
"unexpected getsockopt size"
1113
1115
) ;
1114
- // Safety: All members of xdp_statistics are u64 and thus are correctly initialized
1115
- // by `MaybeUninit::<xdp_statistics>::zeroed()`
1116
+ // Safety: All members of xdp_statistics are u64 and thus are correctly
1117
+ // initialized by `MaybeUninit::<xdp_statistics>::zeroed()`
1116
1118
let xdp_statistics = unsafe { value. assume_init ( ) } ;
1117
1119
Ok ( XdpStatistics {
1118
1120
rx_dropped : xdp_statistics. rx_dropped ,
0 commit comments