authorgravatar for jens.goldberg@gmail.comJens Goldberg <jens.goldberg@gmail.com> 2024-08-19 15:01:58+02:00
committergravatar for jens.goldberg@gmail.comJens Goldberg <jens.goldberg@gmail.com> 2024-08-19 15:01:58+02:00
logaf007ec1ff51269cd6135c3e6e2fa5c8b2c02039
tree622e37bae0dbeebffef737b8cbc0a8bddafc9997
parent54e48f7b7dec96c8cdd1a0a0491554b118767817

std.os.linux: Add support for AF_PACKET V3


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

lib/std/os/linux.zig+133
...@@ -6816,6 +6816,139 @@ pub const ifreq = extern struct {...@@ -6816,6 +6816,139 @@ pub const ifreq = extern struct {
6816 },6816 },
6817};6817};
68186818
6819pub const PACKET = struct {
6820 pub const HOST = 0;
6821 pub const BROADCAST = 1;
6822 pub const MULTICAST = 2;
6823 pub const OTHERHOST = 3;
6824 pub const OUTGOING = 4;
6825 pub const LOOPBACK = 5;
6826 pub const USER = 6;
6827 pub const KERNEL = 7;
6828 pub const FASTROUTE = 8;
6829
6830 pub const ADD_MEMBERSHIP = 1;
6831 pub const DROP_MEMBERSHIP = 2;
6832 pub const RECV_OUTPUT = 3;
6833 pub const RX_RING = 5;
6834 pub const STATISTICS = 6;
6835 pub const COPY_THRESH = 7;
6836 pub const AUXDATA = 8;
6837 pub const ORIGDEV = 9;
6838 pub const VERSION = 10;
6839 pub const HDRLEN = 11;
6840 pub const RESERVE = 12;
6841 pub const TX_RING = 13;
6842 pub const LOSS = 14;
6843 pub const VNET_HDR = 15;
6844 pub const TX_TIMESTAMP = 16;
6845 pub const TIMESTAMP = 17;
6846 pub const FANOUT = 18;
6847 pub const TX_HAS_OFF = 19;
6848 pub const QDISC_BYPASS = 20;
6849 pub const ROLLOVER_STATS = 21;
6850 pub const FANOUT_DATA = 22;
6851 pub const IGNORE_OUTGOING = 23;
6852 pub const VNET_HDR_SZ = 24;
6853
6854 pub const FANOUT_HASH = 0;
6855 pub const FANOUT_LB = 1;
6856 pub const FANOUT_CPU = 2;
6857 pub const FANOUT_ROLLOVER = 3;
6858 pub const FANOUT_RND = 4;
6859 pub const FANOUT_QM = 5;
6860 pub const FANOUT_CBPF = 6;
6861 pub const FANOUT_EBPF = 7;
6862 pub const FANOUT_FLAG_ROLLOVER = 0x1000;
6863 pub const FANOUT_FLAG_UNIQUEID = 0x2000;
6864 pub const FANOUT_FLAG_IGNORE_OUTGOING = 0x4000;
6865 pub const FANOUT_FLAG_DEFRAG = 0x8000;
6866};
6867
6868pub const tpacket_versions = enum(u32) {
6869 V1 = 0,
6870 V2 = 1,
6871 V3 = 2,
6872};
6873
6874pub const tpacket_req3 = extern struct {
6875 block_size: c_uint, // Minimal size of contiguous block
6876 block_nr: c_uint, // Number of blocks
6877 frame_size: c_uint, // Size of frame
6878 frame_nr: c_uint, // Total number of frames
6879 retire_blk_tov: c_uint, // Timeout in msecs
6880 sizeof_priv: c_uint, // Offset to private data area
6881 feature_req_word: c_uint,
6882};
6883
6884pub const tpacket_bd_ts = extern struct {
6885 sec: c_uint,
6886 frac: extern union {
6887 usec: c_uint,
6888 nsec: c_uint,
6889 },
6890};
6891
6892pub const TP_STATUS = extern union {
6893 rx: packed struct(u32) {
6894 USER: bool,
6895 COPY: bool,
6896 LOSING: bool,
6897 CSUMNOTREADY: bool,
6898 VLAN_VALID: bool,
6899 BLK_TMO: bool,
6900 VLAN_TPID_VALID: bool,
6901 CSUM_VALID: bool,
6902 GSO_TCP: bool,
6903 _: u20,
6904 TS_SOFTWARE: bool,
6905 TS_SYS_HARDWARE: bool,
6906 TS_RAW_HARDWARE: bool,
6907 },
6908 tx: packed struct(u32) {
6909 SEND_REQUEST: bool,
6910 SENDING: bool,
6911 WRONG_FORMAT: bool,
6912 _: u26,
6913 TS_SOFTWARE: bool,
6914 TS_SYS_HARDWARE: bool,
6915 TS_RAW_HARDWARE: bool,
6916 },
6917};
6918
6919pub const tpacket_block_desc = extern struct {
6920 version: u32,
6921 offset_to_priv: u32,
6922 block_status: TP_STATUS,
6923 num_pkts: u32,
6924 offset_to_first_pkt: u32,
6925 blk_len: u32,
6926 seq_num: u64 align(8),
6927 ts_first_pkt: tpacket_bd_ts,
6928 ts_last_pkt: tpacket_bd_ts,
6929};
6930
6931pub const tpacket3_hdr = extern struct {
6932 next_offset: u32,
6933 sec: u32,
6934 nsec: u32,
6935 snaplen: u32,
6936 len: u32,
6937 status: u32,
6938 mac: u16,
6939 net: u16,
6940 rxhash: u32,
6941 vlan_tci: u32,
6942 vlan_tpid: u16,
6943 padding: [10]u8,
6944};
6945
6946pub const tpacket_stats_v3 = extern struct {
6947 packets: c_uint,
6948 drops: c_uint,
6949 freeze_q_cnt: c_uint,
6950};
6951
6819// doc comments copied from musl6952// doc comments copied from musl
6820pub const rlimit_resource = if (native_arch.isMIPS() or native_arch.isSPARC())6953pub const rlimit_resource = if (native_arch.isMIPS() or native_arch.isSPARC())
6821 arch_bits.rlimit_resource6954 arch_bits.rlimit_resource