authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2024-08-23 00:46:18-07:00
committergravatar for noreply@github.comGitHub <noreply@github.com> 2024-08-23 00:46:18-07:00
log60011d28d3a03544f5ba6dd75bdd50f828d2ff7e
tree82c3f10522098ae85a091396026d04b7d3b00820
parent56119c2cbc6818de7b7b17a2d0e242f607bc7edb
parentc3214bcd966b6cb245e937a8599cb6f5b54eeef7
signaturebadge-check Signed by PGP key B5690EEEBB952194

Merge pull request #21137 from Aransentin/af_packet

std.os.linux: Add support for AF_PACKET V3

1 files changed, 147 insertions(+), 0 deletions(-)

lib/std/os/linux.zig+147
...@@ -7067,6 +7067,153 @@ pub const ifreq = extern struct {...@@ -7067,6 +7067,153 @@ pub const ifreq = extern struct {
7067 },7067 },
7068};7068};
70697069
7070pub const PACKET = struct {
7071 pub const HOST = 0;
7072 pub const BROADCAST = 1;
7073 pub const MULTICAST = 2;
7074 pub const OTHERHOST = 3;
7075 pub const OUTGOING = 4;
7076 pub const LOOPBACK = 5;
7077 pub const USER = 6;
7078 pub const KERNEL = 7;
7079
7080 pub const ADD_MEMBERSHIP = 1;
7081 pub const DROP_MEMBERSHIP = 2;
7082 pub const RECV_OUTPUT = 3;
7083 pub const RX_RING = 5;
7084 pub const STATISTICS = 6;
7085 pub const COPY_THRESH = 7;
7086 pub const AUXDATA = 8;
7087 pub const ORIGDEV = 9;
7088 pub const VERSION = 10;
7089 pub const HDRLEN = 11;
7090 pub const RESERVE = 12;
7091 pub const TX_RING = 13;
7092 pub const LOSS = 14;
7093 pub const VNET_HDR = 15;
7094 pub const TX_TIMESTAMP = 16;
7095 pub const TIMESTAMP = 17;
7096 pub const FANOUT = 18;
7097 pub const TX_HAS_OFF = 19;
7098 pub const QDISC_BYPASS = 20;
7099 pub const ROLLOVER_STATS = 21;
7100 pub const FANOUT_DATA = 22;
7101 pub const IGNORE_OUTGOING = 23;
7102 pub const VNET_HDR_SZ = 24;
7103
7104 pub const FANOUT_HASH = 0;
7105 pub const FANOUT_LB = 1;
7106 pub const FANOUT_CPU = 2;
7107 pub const FANOUT_ROLLOVER = 3;
7108 pub const FANOUT_RND = 4;
7109 pub const FANOUT_QM = 5;
7110 pub const FANOUT_CBPF = 6;
7111 pub const FANOUT_EBPF = 7;
7112 pub const FANOUT_FLAG_ROLLOVER = 0x1000;
7113 pub const FANOUT_FLAG_UNIQUEID = 0x2000;
7114 pub const FANOUT_FLAG_IGNORE_OUTGOING = 0x4000;
7115 pub const FANOUT_FLAG_DEFRAG = 0x8000;
7116};
7117
7118pub const tpacket_versions = enum(u32) {
7119 V1 = 0,
7120 V2 = 1,
7121 V3 = 2,
7122};
7123
7124pub const tpacket_req3 = extern struct {
7125 block_size: c_uint, // Minimal size of contiguous block
7126 block_nr: c_uint, // Number of blocks
7127 frame_size: c_uint, // Size of frame
7128 frame_nr: c_uint, // Total number of frames
7129 retire_blk_tov: c_uint, // Timeout in msecs
7130 sizeof_priv: c_uint, // Offset to private data area
7131 feature_req_word: c_uint,
7132};
7133
7134pub const tpacket_bd_ts = extern struct {
7135 sec: c_uint,
7136 frac: extern union {
7137 usec: c_uint,
7138 nsec: c_uint,
7139 },
7140};
7141
7142pub const TP_STATUS = extern union {
7143 rx: packed struct(u32) {
7144 USER: bool,
7145 COPY: bool,
7146 LOSING: bool,
7147 CSUMNOTREADY: bool,
7148 VLAN_VALID: bool,
7149 BLK_TMO: bool,
7150 VLAN_TPID_VALID: bool,
7151 CSUM_VALID: bool,
7152 GSO_TCP: bool,
7153 _: u20,
7154 TS_SOFTWARE: bool,
7155 TS_SYS_HARDWARE: bool,
7156 TS_RAW_HARDWARE: bool,
7157 },
7158 tx: packed struct(u32) {
7159 SEND_REQUEST: bool,
7160 SENDING: bool,
7161 WRONG_FORMAT: bool,
7162 _: u26,
7163 TS_SOFTWARE: bool,
7164 TS_SYS_HARDWARE: bool,
7165 TS_RAW_HARDWARE: bool,
7166 },
7167};
7168
7169pub const tpacket_hdr_v1 = extern struct {
7170 block_status: TP_STATUS,
7171 num_pkts: u32,
7172 offset_to_first_pkt: u32,
7173 blk_len: u32,
7174 seq_num: u64 align(8),
7175 ts_first_pkt: tpacket_bd_ts,
7176 ts_last_pkt: tpacket_bd_ts,
7177};
7178
7179pub const tpacket_bd_header_u = extern union {
7180 bh1: tpacket_hdr_v1,
7181};
7182
7183pub const tpacket_block_desc = extern struct {
7184 version: u32,
7185 offset_to_priv: u32,
7186 hdr: tpacket_bd_header_u,
7187};
7188
7189pub const tpacket_hdr_variant1 = extern struct {
7190 rxhash: u32,
7191 vlan_tci: u32,
7192 vlan_tpid: u16,
7193 padding: u16,
7194};
7195
7196pub const tpacket3_hdr = extern struct {
7197 next_offset: u32,
7198 sec: u32,
7199 nsec: u32,
7200 snaplen: u32,
7201 len: u32,
7202 status: u32,
7203 mac: u16,
7204 net: u16,
7205 variant: extern union {
7206 hv1: tpacket_hdr_variant1,
7207 },
7208 padding: [8]u8,
7209};
7210
7211pub const tpacket_stats_v3 = extern struct {
7212 packets: c_uint,
7213 drops: c_uint,
7214 freeze_q_cnt: c_uint,
7215};
7216
7070// doc comments copied from musl7217// doc comments copied from musl
7071pub const rlimit_resource = if (native_arch.isMIPS()) enum(c_int) {7218pub const rlimit_resource = if (native_arch.isMIPS()) enum(c_int) {
7072 /// Per-process CPU limit, in seconds.7219 /// Per-process CPU limit, in seconds.