1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
|
// SPDX-License-Identifier: MIT
// Copyright (c) 2015-2020 Zig Contributors
// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
// The MIT license requires this copyright notice to be included in all copies
// and substantial portions of the software.
usingnamespace @import("../linux.zig");
/// Routing/device hook
pub const NETLINK_ROUTE = 0;
/// Unused number
pub const NETLINK_UNUSED = 1;
/// Reserved for user mode socket protocols
pub const NETLINK_USERSOCK = 2;
/// Unused number, formerly ip_queue
pub const NETLINK_FIREWALL = 3;
/// socket monitoring
pub const NETLINK_SOCK_DIAG = 4;
/// netfilter/iptables ULOG
pub const NETLINK_NFLOG = 5;
/// ipsec
pub const NETLINK_XFRM = 6;
/// SELinux event notifications
pub const NETLINK_SELINUX = 7;
/// Open-iSCSI
pub const NETLINK_ISCSI = 8;
/// auditing
pub const NETLINK_AUDIT = 9;
pub const NETLINK_FIB_LOOKUP = 10;
pub const NETLINK_CONNECTOR = 11;
/// netfilter subsystem
pub const NETLINK_NETFILTER = 12;
pub const NETLINK_IP6_FW = 13;
/// DECnet routing messages
pub const NETLINK_DNRTMSG = 14;
/// Kernel messages to userspace
pub const NETLINK_KOBJECT_UEVENT = 15;
pub const NETLINK_GENERIC = 16;
// leave room for NETLINK_DM (DM Events)
/// SCSI Transports
pub const NETLINK_SCSITRANSPORT = 18;
pub const NETLINK_ECRYPTFS = 19;
pub const NETLINK_RDMA = 20;
/// Crypto layer
pub const NETLINK_CRYPTO = 21;
/// SMC monitoring
pub const NETLINK_SMC = 22;
// Flags values
/// It is request message.
pub const NLM_F_REQUEST = 0x01;
/// Multipart message, terminated by NLMSG_DONE
pub const NLM_F_MULTI = 0x02;
/// Reply with ack, with zero or error code
pub const NLM_F_ACK = 0x04;
/// Echo this request
pub const NLM_F_ECHO = 0x08;
/// Dump was inconsistent due to sequence change
pub const NLM_F_DUMP_INTR = 0x10;
/// Dump was filtered as requested
pub const NLM_F_DUMP_FILTERED = 0x20;
// Modifiers to GET request
/// specify tree root
pub const NLM_F_ROOT = 0x100;
/// return all matching
pub const NLM_F_MATCH = 0x200;
/// atomic GET
pub const NLM_F_ATOMIC = 0x400;
pub const NLM_F_DUMP = NLM_F_ROOT | NLM_F_MATCH;
// Modifiers to NEW request
/// Override existing
pub const NLM_F_REPLACE = 0x100;
/// Do not touch, if it exists
pub const NLM_F_EXCL = 0x200;
/// Create, if it does not exist
pub const NLM_F_CREATE = 0x400;
/// Add to end of list
pub const NLM_F_APPEND = 0x800;
// Modifiers to DELETE request
/// Do not delete recursively
pub const NLM_F_NONREC = 0x100;
// Flags for ACK message
/// request was capped
pub const NLM_F_CAPPED = 0x100;
/// extended ACK TVLs were included
pub const NLM_F_ACK_TLVS = 0x200;
pub const NetlinkMessageType = extern enum(u16) {
/// < 0x10: reserved control messages
pub const MIN_TYPE = 0x10;
/// Nothing.
NOOP = 0x1,
/// Error
ERROR = 0x2,
/// End of a dump
DONE = 0x3,
/// Data lost
OVERRUN = 0x4,
// rtlink types
RTM_NEWLINK = 16,
RTM_DELLINK,
RTM_GETLINK,
RTM_SETLINK,
RTM_NEWADDR = 20,
RTM_DELADDR,
RTM_GETADDR,
RTM_NEWROUTE = 24,
RTM_DELROUTE,
RTM_GETROUTE,
RTM_NEWNEIGH = 28,
RTM_DELNEIGH,
RTM_GETNEIGH,
RTM_NEWRULE = 32,
RTM_DELRULE,
RTM_GETRULE,
RTM_NEWQDISC = 36,
RTM_DELQDISC,
RTM_GETQDISC,
RTM_NEWTCLASS = 40,
RTM_DELTCLASS,
RTM_GETTCLASS,
RTM_NEWTFILTER = 44,
RTM_DELTFILTER,
RTM_GETTFILTER,
RTM_NEWACTION = 48,
RTM_DELACTION,
RTM_GETACTION,
RTM_NEWPREFIX = 52,
RTM_GETMULTICAST = 58,
RTM_GETANYCAST = 62,
RTM_NEWNEIGHTBL = 64,
RTM_GETNEIGHTBL = 66,
RTM_SETNEIGHTBL,
RTM_NEWNDUSEROPT = 68,
RTM_NEWADDRLABEL = 72,
RTM_DELADDRLABEL,
RTM_GETADDRLABEL,
RTM_GETDCB = 78,
RTM_SETDCB,
RTM_NEWNETCONF = 80,
RTM_DELNETCONF,
RTM_GETNETCONF = 82,
RTM_NEWMDB = 84,
RTM_DELMDB = 85,
RTM_GETMDB = 86,
RTM_NEWNSID = 88,
RTM_DELNSID = 89,
RTM_GETNSID = 90,
RTM_NEWSTATS = 92,
RTM_GETSTATS = 94,
RTM_NEWCACHEREPORT = 96,
RTM_NEWCHAIN = 100,
RTM_DELCHAIN,
RTM_GETCHAIN,
RTM_NEWNEXTHOP = 104,
RTM_DELNEXTHOP,
RTM_GETNEXTHOP,
_,
};
/// Netlink socket address
pub const sockaddr_nl = extern struct {
family: sa_family_t = AF_NETLINK,
__pad1: c_ushort = 0,
/// port ID
pid: u32,
/// multicast groups mask
groups: u32,
};
/// Netlink message header
/// Specified in RFC 3549 Section 2.3.2
pub const nlmsghdr = extern struct {
/// Length of message including header
len: u32,
/// Message content
@"type": NetlinkMessageType,
/// Additional flags
flags: u16,
/// Sequence number
seq: u32,
/// Sending process port ID
pid: u32,
};
pub const ifinfomsg = extern struct {
family: u8,
__pad1: u8 = 0,
/// ARPHRD_*
@"type": c_ushort,
/// Link index
index: c_int,
/// IFF_* flags
flags: c_uint,
/// IFF_* change mask
/// is reserved for future use and should be always set to 0xFFFFFFFF.
change: c_uint = 0xFFFFFFFF,
};
pub const rtattr = extern struct {
/// Length of option
len: c_ushort,
/// Type of option
@"type": IFLA,
pub const ALIGNTO = 4;
};
pub const IFLA = extern enum(c_ushort) {
UNSPEC,
ADDRESS,
BROADCAST,
IFNAME,
MTU,
LINK,
QDISC,
STATS,
COST,
PRIORITY,
MASTER,
/// Wireless Extension event
WIRELESS,
/// Protocol specific information for a link
PROTINFO,
TXQLEN,
MAP,
WEIGHT,
OPERSTATE,
LINKMODE,
LINKINFO,
NET_NS_PID,
IFALIAS,
/// Number of VFs if device is SR-IOV PF
NUM_VF,
VFINFO_LIST,
STATS64,
VF_PORTS,
PORT_SELF,
AF_SPEC,
/// Group the device belongs to
GROUP,
NET_NS_FD,
/// Extended info mask, VFs, etc
EXT_MASK,
/// Promiscuity count: > 0 means acts PROMISC
PROMISCUITY,
NUM_TX_QUEUES,
NUM_RX_QUEUES,
CARRIER,
PHYS_PORT_ID,
CARRIER_CHANGES,
PHYS_SWITCH_ID,
LINK_NETNSID,
PHYS_PORT_NAME,
PROTO_DOWN,
GSO_MAX_SEGS,
GSO_MAX_SIZE,
PAD,
XDP,
EVENT,
NEW_NETNSID,
IF_NETNSID = 46,
TARGET_NETNSID = 46, // new alias
CARRIER_UP_COUNT,
CARRIER_DOWN_COUNT,
NEW_IFINDEX,
MIN_MTU,
MAX_MTU,
_,
};
pub const rtnl_link_ifmap = extern struct {
mem_start: u64,
mem_end: u64,
base_addr: u64,
irq: u16,
dma: u8,
port: u8,
};
pub const rtnl_link_stats = extern struct {
/// total packets received
rx_packets: u32,
/// total packets transmitted
tx_packets: u32,
/// total bytes received
rx_bytes: u32,
/// total bytes transmitted
tx_bytes: u32,
/// bad packets received
rx_errors: u32,
/// packet transmit problems
tx_errors: u32,
/// no space in linux buffers
rx_dropped: u32,
/// no space available in linux
tx_dropped: u32,
/// multicast packets received
multicast: u32,
collisions: u32,
// detailed rx_errors
rx_length_errors: u32,
/// receiver ring buff overflow
rx_over_errors: u32,
/// recved pkt with crc error
rx_crc_errors: u32,
/// recv'd frame alignment error
rx_frame_errors: u32,
/// recv'r fifo overrun
rx_fifo_errors: u32,
/// receiver missed packet
rx_missed_errors: u32,
// detailed tx_errors
tx_aborted_errors: u32,
tx_carrier_errors: u32,
tx_fifo_errors: u32,
tx_heartbeat_errors: u32,
tx_window_errors: u32,
// for cslip etc
rx_compressed: u32,
tx_compressed: u32,
/// dropped, no handler found
rx_nohandler: u32,
};
pub const rtnl_link_stats64 = extern struct {
/// total packets received
rx_packets: u64,
/// total packets transmitted
tx_packets: u64,
/// total bytes received
rx_bytes: u64,
/// total bytes transmitted
tx_bytes: u64,
/// bad packets received
rx_errors: u64,
/// packet transmit problems
tx_errors: u64,
/// no space in linux buffers
rx_dropped: u64,
/// no space available in linux
tx_dropped: u64,
/// multicast packets received
multicast: u64,
collisions: u64,
// detailed rx_errors
rx_length_errors: u64,
/// receiver ring buff overflow
rx_over_errors: u64,
/// recved pkt with crc error
rx_crc_errors: u64,
/// recv'd frame alignment error
rx_frame_errors: u64,
/// recv'r fifo overrun
rx_fifo_errors: u64,
/// receiver missed packet
rx_missed_errors: u64,
// detailed tx_errors
tx_aborted_errors: u64,
tx_carrier_errors: u64,
tx_fifo_errors: u64,
tx_heartbeat_errors: u64,
tx_window_errors: u64,
// for cslip etc
rx_compressed: u64,
tx_compressed: u64,
/// dropped, no handler found
rx_nohandler: u64,
};
|