libc/new/linux_uapi/linux/
if_packet.rs1use crate::prelude::*;
4
5s! {
6 #[deprecated(since = "0.2.70", note = "sockaddr_ll type should be used instead")]
7 pub struct sockaddr_pkt {
8 pub spkt_family: c_ushort,
9 pub spkt_device: [c_uchar; 14],
10 pub spkt_protocol: c_ushort,
11 }
12}
13
14pub const PACKET_HOST: c_uchar = 0;
15pub const PACKET_BROADCAST: c_uchar = 1;
16pub const PACKET_MULTICAST: c_uchar = 2;
17pub const PACKET_OTHERHOST: c_uchar = 3;
18pub const PACKET_OUTGOING: c_uchar = 4;
19pub const PACKET_LOOPBACK: c_uchar = 5;
20pub const PACKET_USER: c_uchar = 6;
21pub const PACKET_KERNEL: c_uchar = 7;
22
23pub const PACKET_ADD_MEMBERSHIP: c_int = 1;
24pub const PACKET_DROP_MEMBERSHIP: c_int = 2;
25pub const PACKET_RECV_OUTPUT: c_int = 3;
26pub const PACKET_RX_RING: c_int = 5;
27pub const PACKET_STATISTICS: c_int = 6;
28pub const PACKET_COPY_THRESH: c_int = 7;
29pub const PACKET_AUXDATA: c_int = 8;
30pub const PACKET_ORIGDEV: c_int = 9;
31pub const PACKET_VERSION: c_int = 10;
32pub const PACKET_HDRLEN: c_int = 11;
33pub const PACKET_RESERVE: c_int = 12;
34pub const PACKET_TX_RING: c_int = 13;
35pub const PACKET_LOSS: c_int = 14;
36pub const PACKET_VNET_HDR: c_int = 15;
37pub const PACKET_TX_TIMESTAMP: c_int = 16;
38pub const PACKET_TIMESTAMP: c_int = 17;
39pub const PACKET_FANOUT: c_int = 18;
40pub const PACKET_TX_HAS_OFF: c_int = 19;
41pub const PACKET_QDISC_BYPASS: c_int = 20;
42pub const PACKET_ROLLOVER_STATS: c_int = 21;
43pub const PACKET_FANOUT_DATA: c_int = 22;
44pub const PACKET_IGNORE_OUTGOING: c_int = 23;
45pub const PACKET_VNET_HDR_SZ: c_int = 24;
46
47pub const PACKET_FANOUT_HASH: c_uint = 0;
48pub const PACKET_FANOUT_LB: c_uint = 1;
49pub const PACKET_FANOUT_CPU: c_uint = 2;
50pub const PACKET_FANOUT_ROLLOVER: c_uint = 3;
51pub const PACKET_FANOUT_RND: c_uint = 4;
52pub const PACKET_FANOUT_QM: c_uint = 5;
53pub const PACKET_FANOUT_CBPF: c_uint = 6;
54pub const PACKET_FANOUT_EBPF: c_uint = 7;
55pub const PACKET_FANOUT_FLAG_ROLLOVER: c_uint = 0x1000;
56pub const PACKET_FANOUT_FLAG_UNIQUEID: c_uint = 0x2000;
57pub const PACKET_FANOUT_FLAG_IGNORE_OUTGOING: c_uint = 0x4000;
58pub const PACKET_FANOUT_FLAG_DEFRAG: c_uint = 0x8000;
59
60s! {
61 pub struct tpacket_stats {
62 pub tp_packets: c_uint,
63 pub tp_drops: c_uint,
64 }
65
66 pub struct tpacket_stats_v3 {
67 pub tp_packets: c_uint,
68 pub tp_drops: c_uint,
69 pub tp_freeze_q_cnt: c_uint,
70 }
71
72 #[repr(align(8))]
73 pub struct tpacket_rollover_stats {
74 pub tp_all: crate::__u64,
75 pub tp_huge: crate::__u64,
76 pub tp_failed: crate::__u64,
77 }
78
79 pub struct tpacket_auxdata {
80 pub tp_status: u32,
81 pub tp_len: u32,
82 pub tp_snaplen: u32,
83 pub tp_mac: u16,
84 pub tp_net: u16,
85 pub tp_vlan_tci: u16,
86 pub tp_vlan_tpid: u16,
87 }
88}
89
90pub const TP_STATUS_KERNEL: u32 = 0;
91pub const TP_STATUS_USER: u32 = 1 << 0;
92pub const TP_STATUS_COPY: u32 = 1 << 1;
93pub const TP_STATUS_LOSING: u32 = 1 << 2;
94pub const TP_STATUS_CSUMNOTREADY: u32 = 1 << 3;
95pub const TP_STATUS_VLAN_VALID: u32 = 1 << 4;
96pub const TP_STATUS_BLK_TMO: u32 = 1 << 5;
97pub const TP_STATUS_VLAN_TPID_VALID: u32 = 1 << 6;
98pub const TP_STATUS_CSUM_VALID: u32 = 1 << 7;
99
100pub const TP_STATUS_AVAILABLE: u32 = 0;
101pub const TP_STATUS_SEND_REQUEST: u32 = 1 << 0;
102pub const TP_STATUS_SENDING: u32 = 1 << 1;
103pub const TP_STATUS_WRONG_FORMAT: u32 = 1 << 2;
104
105pub const TP_STATUS_TS_SOFTWARE: u32 = 1 << 29;
106pub const TP_STATUS_TS_SYS_HARDWARE: u32 = 1 << 30;
107pub const TP_STATUS_TS_RAW_HARDWARE: u32 = 1 << 31;
108
109pub const TP_FT_REQ_FILL_RXHASH: u32 = 1;
110
111s! {
112 pub struct tpacket_hdr {
113 pub tp_status: c_ulong,
114 pub tp_len: c_uint,
115 pub tp_snaplen: c_uint,
116 pub tp_mac: c_ushort,
117 pub tp_net: c_ushort,
118 pub tp_sec: c_uint,
119 pub tp_usec: c_uint,
120 }
121}
122
123pub const TPACKET_ALIGNMENT: usize = 16;
124f! {
125 pub unsafe fn TPACKET_ALIGN(x: usize) -> usize {
126 (x + TPACKET_ALIGNMENT - 1) & !(TPACKET_ALIGNMENT - 1)
127 }
128}
129pub const TPACKET_HDRLEN: usize = ((size_of::<tpacket_hdr>() + TPACKET_ALIGNMENT - 1)
130 & !(TPACKET_ALIGNMENT - 1))
131 + size_of::<crate::sockaddr_ll>();
132
133s! {
134 pub struct tpacket2_hdr {
135 pub tp_status: u32,
136 pub tp_len: u32,
137 pub tp_snaplen: u32,
138 pub tp_mac: u16,
139 pub tp_net: u16,
140 pub tp_sec: u32,
141 pub tp_nsec: u32,
142 pub tp_vlan_tci: u16,
143 pub tp_vlan_tpid: u16,
144 pub tp_padding: [u8; 4],
145 }
146
147 pub struct tpacket_hdr_variant1 {
148 pub tp_rxhash: u32,
149 pub tp_vlan_tci: u32,
150 pub tp_vlan_tpid: u16,
151 pub tp_padding: u16,
152 }
153
154 pub struct tpacket3_hdr {
155 pub tp_next_offset: u32,
156 pub tp_sec: u32,
157 pub tp_nsec: u32,
158 pub tp_snaplen: u32,
159 pub tp_len: u32,
160 pub tp_status: u32,
161 pub tp_mac: u16,
162 pub tp_net: u16,
163 pub hv1: tpacket_hdr_variant1,
164 pub tp_padding: [u8; 8],
165 }
166
167 pub struct tpacket_bd_ts {
168 pub ts_sec: c_uint,
169 pub ts_usec: c_uint,
170 }
171
172 #[repr(align(8))]
173 pub struct tpacket_hdr_v1 {
174 pub block_status: u32,
175 pub num_pkts: u32,
176 pub offset_to_first_pkt: u32,
177 pub blk_len: u32,
178 pub seq_num: crate::__u64,
179 pub ts_first_pkt: tpacket_bd_ts,
180 pub ts_last_pkt: tpacket_bd_ts,
181 }
182}
183
184s_no_extra_traits! {
185 pub union tpacket_bd_header_u {
186 pub bh1: tpacket_hdr_v1,
187 }
188
189 pub struct tpacket_block_desc {
190 pub version: u32,
191 pub offset_to_priv: u32,
192 pub hdr: tpacket_bd_header_u,
193 }
194}
195
196pub const TPACKET2_HDRLEN: usize = ((size_of::<tpacket2_hdr>() + TPACKET_ALIGNMENT - 1)
197 & !(TPACKET_ALIGNMENT - 1))
198 + size_of::<crate::sockaddr_ll>();
199pub const TPACKET3_HDRLEN: usize = ((size_of::<tpacket3_hdr>() + TPACKET_ALIGNMENT - 1)
200 & !(TPACKET_ALIGNMENT - 1))
201 + size_of::<crate::sockaddr_ll>();
202
203e! {
204 #[repr(u32)]
205 pub enum tpacket_versions {
206 TPACKET_V1,
207 TPACKET_V2,
208 TPACKET_V3,
209 }
210}
211
212s! {
213 pub struct tpacket_req {
214 pub tp_block_size: c_uint,
215 pub tp_block_nr: c_uint,
216 pub tp_frame_size: c_uint,
217 pub tp_frame_nr: c_uint,
218 }
219
220 pub struct tpacket_req3 {
221 pub tp_block_size: c_uint,
222 pub tp_block_nr: c_uint,
223 pub tp_frame_size: c_uint,
224 pub tp_frame_nr: c_uint,
225 pub tp_retire_blk_tov: c_uint,
226 pub tp_sizeof_priv: c_uint,
227 pub tp_feature_req_word: c_uint,
228 }
229}
230
231s_no_extra_traits! {
232 pub union tpacket_req_u {
233 pub req: tpacket_req,
234 pub req3: tpacket_req3,
235 }
236}
237
238s! {
239 pub struct packet_mreq {
240 pub mr_ifindex: c_int,
241 pub mr_type: c_ushort,
242 pub mr_alen: c_ushort,
243 pub mr_address: [c_uchar; 8],
244 }
245
246 pub struct fanout_args {
247 #[cfg(target_endian = "little")]
248 pub id: u16,
249 pub type_flags: u16,
250 #[cfg(target_endian = "big")]
251 pub id: u16,
252 pub max_num_members: u32,
253 }
254}
255
256pub const PACKET_MR_MULTICAST: c_int = 0;
257pub const PACKET_MR_PROMISC: c_int = 1;
258pub const PACKET_MR_ALLMULTI: c_int = 2;