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 May 3, 2024
1 parent 2918100 commit a319b9e
Show file tree
Hide file tree
Showing 6 changed files with 352 additions and 2 deletions.
19 changes: 18 additions & 1 deletion libc-test/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3369,7 +3369,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 @@ -3471,6 +3470,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 @@ -3647,6 +3647,23 @@ fn test_linux(target: &str) {
if (gnu && sparc64) && (ty == "ip_mreqn" || ty == "hwtstamp_config") {
return true;
}
// FIXME: 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 @@ -1802,11 +1802,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 @@ -3191,6 +3218,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 @@ -3453,6 +3497,7 @@ fanotify_event_metadata
fanotify_init
fanotify_mark
fanotify_response
fanout_args
fchdir
fdatasync
fdopendir
Expand Down Expand Up @@ -3820,6 +3865,7 @@ sockaddr_alg
sockaddr_can
sockaddr_ll
sockaddr_nl
sockaddr_pkt
sockaddr_vm
splice
spwd
Expand Down Expand Up @@ -3857,6 +3903,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
20 changes: 20 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 Expand Up @@ -200,6 +218,8 @@ macro_rules! expand_align {
pub af: u32,
pub data: [u8; CANXL_MAX_DLEN],
}


}
};
}

0 comments on commit a319b9e

Please sign in to comment.