authorgravatar for jens.goldberg@gmail.comJens Goldberg <jens.goldberg@gmail.com> 2021-06-08 01:33:29+00:00
committergravatar for noreply@github.comGitHub <noreply@github.com> 2021-06-07 21:33:29-04:00
log7462b0e5b9d03ed6704c83f444b083a973278da5
tree134f43317bf7b1a712c0c20a0675d4fe5213bc96
parentfa6546ba743fe145ad65d9ca76fe9e9e01d05056
signaturebadge-question-mark Signed by PGP key 4AEE18F83AFDEB23

Add Linux XDP bits (#9019)


2 files changed, 87 insertions(+), 1 deletions(-)

lib/std/os/bits/linux.zig+5-1
......@@ -30,6 +30,7 @@ pub usingnamespace switch (arch) {
3030pub usingnamespace @import("linux/netlink.zig");
3131pub usingnamespace @import("linux/prctl.zig");
3232pub usingnamespace @import("linux/securebits.zig");
33pub usingnamespace @import("linux/xdp.zig");
3334
3435const is_mips = arch.isMIPS();
3536const is_ppc = arch.isPPC();
......@@ -408,7 +409,8 @@ pub const PF_VSOCK = 40;
408409pub const PF_KCM = 41;
409410pub const PF_QIPCRTR = 42;
410411pub const PF_SMC = 43;
411pub const PF_MAX = 44;
412pub const PF_XDP = 44;
413pub const PF_MAX = 45;
412414
413415pub const AF_UNSPEC = PF_UNSPEC;
414416pub const AF_LOCAL = PF_LOCAL;
......@@ -457,6 +459,7 @@ pub const AF_VSOCK = PF_VSOCK;
457459pub const AF_KCM = PF_KCM;
458460pub const AF_QIPCRTR = PF_QIPCRTR;
459461pub const AF_SMC = PF_SMC;
462pub const AF_XDP = PF_XDP;
460463pub const AF_MAX = PF_MAX;
461464
462465pub usingnamespace if (is_mips)
......@@ -601,6 +604,7 @@ pub const SOL_ALG = 279;
601604pub const SOL_NFC = 280;
602605pub const SOL_KCM = 281;
603606pub const SOL_TLS = 282;
607pub const SOL_XDP = 283;
604608
605609pub const SOMAXCONN = 128;
606610
lib/std/os/bits/linux/xdp.zig created+82
......@@ -0,0 +1,82 @@
1// SPDX-License-Identifier: MIT
2// Copyright (c) 2015-2021 Zig Contributors
3// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
4// The MIT license requires this copyright notice to be included in all copies
5// and substantial portions of the software.
6usingnamespace @import("../linux.zig");
7
8pub const XDP_SHARED_UMEM = (1 << 0);
9pub const XDP_COPY = (1 << 1);
10pub const XDP_ZEROCOPY = (1 << 2);
11
12pub const XDP_UMEM_UNALIGNED_CHUNK_FLAG = (1 << 0);
13
14pub const sockaddr_xdp = extern struct {
15 family: u16 = AF_XDP,
16 flags: u16,
17 ifindex: u32,
18 queue_id: u32,
19 shared_umem_fd: u32,
20};
21
22pub const XDP_USE_NEED_WAKEUP = (1 << 3);
23
24pub const xdp_ring_offset = extern struct {
25 producer: u64,
26 consumer: u64,
27 desc: u64,
28 flags: u64,
29};
30
31pub const xdp_mmap_offsets = extern struct {
32 rx: xdp_ring_offset,
33 tx: xdp_ring_offset,
34 fr: xdp_ring_offset,
35 cr: xdp_ring_offset,
36};
37
38pub const XDP_MMAP_OFFSETS = 1;
39pub const XDP_RX_RING = 2;
40pub const XDP_TX_RING = 3;
41pub const XDP_UMEM_REG = 4;
42pub const XDP_UMEM_FILL_RING = 5;
43pub const XDP_UMEM_COMPLETION_RING = 6;
44pub const XDP_STATISTICS = 7;
45pub const XDP_OPTIONS = 8;
46
47pub const xdp_umem_reg = extern struct {
48 addr: u64,
49 len: u64,
50 chunk_size: u32,
51 headroom: u32,
52 flags: u32,
53};
54
55pub const xdp_statistics = extern struct {
56 rx_dropped: u64,
57 rx_invalid_descs: u64,
58 tx_invalid_descs: u64,
59 rx_ring_full: u64,
60 rx_fill_ring_empty_descs: u64,
61 tx_ring_empty_descs: u64,
62};
63
64pub const xdp_options = extern struct {
65 flags: u32,
66};
67
68pub const XDP_OPTIONS_ZEROCOPY = (1 << 0);
69
70pub const XDP_PGOFF_RX_RING = 0;
71pub const XDP_PGOFF_TX_RING = 0x80000000;
72pub const XDP_UMEM_PGOFF_FILL_RING = 0x100000000;
73pub const XDP_UMEM_PGOFF_COMPLETION_RING = 0x180000000;
74
75pub const XSK_UNALIGNED_BUF_OFFSET_SHIFT = 48;
76pub const XSK_UNALIGNED_BUF_ADDR_MASK = (1 << XSK_UNALIGNED_BUF_OFFSET_SHIFT) - 1;
77
78pub const xdp_desc = extern struct {
79 addr: u64,
80 len: u32,
81 options: u32,
82};