Skip to content

Commit

Permalink
Add additional Linux AF_PACKET options
Browse files Browse the repository at this point in the history
  • Loading branch information
nathaniel-bennett committed Aug 16, 2024
1 parent 436f446 commit f3ba4d0
Show file tree
Hide file tree
Showing 5 changed files with 322 additions and 1 deletion.
19 changes: 18 additions & 1 deletion libc-test/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3412,7 +3412,6 @@ fn test_linux(target: &str) {
"netinet/ip.h",
"netinet/tcp.h",
"netinet/udp.h",
"netpacket/packet.h",
"poll.h",
"pthread.h",
"pty.h",
Expand Down Expand Up @@ -3514,6 +3513,7 @@ fn test_linux(target: &str) {
"linux/if_addr.h",
"linux/if_alg.h",
"linux/if_ether.h",
"linux/if_packet.h",
"linux/if_tun.h",
"linux/if_xdp.h",
"linux/input.h",
Expand Down Expand Up @@ -3690,6 +3690,23 @@ fn test_linux(target: &str) {
if (gnu && sparc64) && (ty == "ip_mreqn" || ty == "hwtstamp_config") {
return true;
}
// FIXME(https://github.com/rust-lang/rust/issues/43894): pass by value for structs that are not an even 32/64 bits on
// big-endian systems corrupts the value for unknown reasons.
if (sparc64 || ppc || ppc64 || s390x)
&& (ty == "sockaddr_pkt"
|| ty == "tpacket_auxdata"
|| ty == "tpacket_hdr_variant1"
|| ty == "tpacket_req3"
|| ty == "tpacket_stats_v3"
|| ty == "tpacket_req_u")
{
return true;
}
// FIXME: musl doesn't compile with `struct fanout_args` for unknown reasons.
if musl && ty == "fanout_args" {
return true;
}

match ty {
// These cannot be tested when "resolv.h" is included and are tested
// in the `linux_elf.rs` file.
Expand Down
62 changes: 62 additions & 0 deletions libc-test/semver/linux.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1805,11 +1805,38 @@ O_RSYNC
O_SYNC
O_TMPFILE
PACKET_ADD_MEMBERSHIP
PACKET_AUXDATA
PACKET_BROADCAST
PACKET_DROP_MEMBERSHIP
PACKET_FANOUT
PACKET_FANOUT_CBPF
PACKET_FANOUT_CPU
PACKET_FANOUT_FLAG_DEFRAG
PACKET_FANOUT_FLAG_ROLLOVER
PACKET_FANOUT_FLAG_UNIQUEID
PACKET_FANOUT_HASH
PACKET_FANOUT_LB
PACKET_FANOUT_QM
PACKET_FANOUT_RND
PACKET_FANOUT_ROLLOVER
PACKET_HOST
PACKET_KERNEL
PACKET_LOOPBACK
PACKET_LOSS
PACKET_MR_ALLMULTI
PACKET_MR_MULTICAST
PACKET_MR_PROMISC
PACKET_MR_UNICAST
PACKET_MULTICAST
PACKET_OTHERHOST
PACKET_OUTGOING
PACKET_QDISC_BYPASS
PACKET_RESERVE
PACKET_RX_RING
PACKET_STATISTICS
PACKET_TIMESTAMP
PACKET_USER
PACKET_VERSION
PENDIN
PF_ALG
PF_APPLETALK
Expand Down Expand Up @@ -3195,6 +3222,23 @@ TLS_GET_RECORD_TYPE
TLS_RX
TLS_SET_RECORD_TYPE
TLS_TX
TP_FT_REQ_FILL_RXHASH
TP_STATUS_AVAILABLE
TP_STATUS_BLK_TMO
TP_STATUS_COPY
TP_STATUS_CSUMNOTREADY
TP_STATUS_CSUM_VALID
TP_STATUS_KERNEL
TP_STATUS_LOSING
TP_STATUS_SENDING
TP_STATUS_SEND_REQUEST
TP_STATUS_TS_RAW_HARDWARE
TP_STATUS_TS_SOFTWARE
TP_STATUS_TS_SYS_HARDWARE
TP_STATUS_USER
TP_STATUS_VLAN_TPID_VALID
TP_STATUS_VLAN_VALID
TP_STATUS_WRONG_FORMAT
TUN_READQ_SIZE
TUN_TAP_DEV
TUN_TUN_DEV
Expand Down Expand Up @@ -3457,6 +3501,7 @@ fanotify_event_metadata
fanotify_init
fanotify_mark
fanotify_response
fanout_args
fchdir
fdatasync
fdopendir
Expand Down Expand Up @@ -3824,6 +3869,7 @@ sockaddr_alg
sockaddr_can
sockaddr_ll
sockaddr_nl
sockaddr_pkt
sockaddr_vm
splice
spwd
Expand Down Expand Up @@ -3861,6 +3907,22 @@ timer_getoverrun
timer_gettime
timer_settime
tmpfile64
tpacket2_hdr
tpacket3_hdr
tpacket_auxdata
tpacket_bd_header_u
tpacket_bd_ts
tpacket_block_desc
tpacket_hdr
tpacket_hdr_v1
tpacket_hdr_variant1
tpacket_req
tpacket_req3
tpacket_req_u
tpacket_rollover_stats
tpacket_stats
tpacket_stats_v3
tpacket_versions
truncate
truncate64
ttyname_r
Expand Down
18 changes: 18 additions & 0 deletions src/unix/linux_like/linux/align.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,24 @@ macro_rules! expand_align {
pub fd: ::c_int,
pub pid: ::c_int,
}

#[repr(align(8))]
pub struct tpacket_rollover_stats {
pub tp_all: ::__u64,
pub tp_huge: ::__u64,
pub tp_failed: ::__u64,
}

#[repr(align(8))]
pub struct tpacket_hdr_v1 {
pub block_status: ::__u32,
pub num_pkts: ::__u32,
pub offset_to_first_pkt: ::__u32,
pub blk_len: ::__u32,
pub seq_num: ::__u64,
pub ts_first_pkt: ::tpacket_bd_ts,
pub ts_last_pkt: ::tpacket_bd_ts,
}
}

s_no_extra_traits! {
Expand Down
Loading

0 comments on commit f3ba4d0

Please sign in to comment.