]> git.proxmox.com Git - mirror_ubuntu-bionic-kernel.git/blob - tools/include/uapi/linux/bpf.h
Add a helper function to get socket cookie in eBPF
[mirror_ubuntu-bionic-kernel.git] / tools / include / uapi / linux / bpf.h
1 /* Copyright (c) 2011-2014 PLUMgrid, http://plumgrid.com
2 *
3 * This program is free software; you can redistribute it and/or
4 * modify it under the terms of version 2 of the GNU General Public
5 * License as published by the Free Software Foundation.
6 */
7 #ifndef _UAPI__LINUX_BPF_H__
8 #define _UAPI__LINUX_BPF_H__
9
10 #include <linux/types.h>
11 #include <linux/bpf_common.h>
12
13 /* Extended instruction set based on top of classic BPF */
14
15 /* instruction classes */
16 #define BPF_ALU64 0x07 /* alu mode in double word width */
17
18 /* ld/ldx fields */
19 #define BPF_DW 0x18 /* double word */
20 #define BPF_XADD 0xc0 /* exclusive add */
21
22 /* alu/jmp fields */
23 #define BPF_MOV 0xb0 /* mov reg to reg */
24 #define BPF_ARSH 0xc0 /* sign extending arithmetic shift right */
25
26 /* change endianness of a register */
27 #define BPF_END 0xd0 /* flags for endianness conversion: */
28 #define BPF_TO_LE 0x00 /* convert to little-endian */
29 #define BPF_TO_BE 0x08 /* convert to big-endian */
30 #define BPF_FROM_LE BPF_TO_LE
31 #define BPF_FROM_BE BPF_TO_BE
32
33 #define BPF_JNE 0x50 /* jump != */
34 #define BPF_JSGT 0x60 /* SGT is signed '>', GT in x86 */
35 #define BPF_JSGE 0x70 /* SGE is signed '>=', GE in x86 */
36 #define BPF_CALL 0x80 /* function call */
37 #define BPF_EXIT 0x90 /* function return */
38
39 /* Register numbers */
40 enum {
41 BPF_REG_0 = 0,
42 BPF_REG_1,
43 BPF_REG_2,
44 BPF_REG_3,
45 BPF_REG_4,
46 BPF_REG_5,
47 BPF_REG_6,
48 BPF_REG_7,
49 BPF_REG_8,
50 BPF_REG_9,
51 BPF_REG_10,
52 __MAX_BPF_REG,
53 };
54
55 /* BPF has 10 general purpose 64-bit registers and stack frame. */
56 #define MAX_BPF_REG __MAX_BPF_REG
57
58 struct bpf_insn {
59 __u8 code; /* opcode */
60 __u8 dst_reg:4; /* dest register */
61 __u8 src_reg:4; /* source register */
62 __s16 off; /* signed offset */
63 __s32 imm; /* signed immediate constant */
64 };
65
66 /* Key of an a BPF_MAP_TYPE_LPM_TRIE entry */
67 struct bpf_lpm_trie_key {
68 __u32 prefixlen; /* up to 32 for AF_INET, 128 for AF_INET6 */
69 __u8 data[0]; /* Arbitrary size */
70 };
71
72 /* BPF syscall commands, see bpf(2) man-page for details. */
73 enum bpf_cmd {
74 BPF_MAP_CREATE,
75 BPF_MAP_LOOKUP_ELEM,
76 BPF_MAP_UPDATE_ELEM,
77 BPF_MAP_DELETE_ELEM,
78 BPF_MAP_GET_NEXT_KEY,
79 BPF_PROG_LOAD,
80 BPF_OBJ_PIN,
81 BPF_OBJ_GET,
82 BPF_PROG_ATTACH,
83 BPF_PROG_DETACH,
84 };
85
86 enum bpf_map_type {
87 BPF_MAP_TYPE_UNSPEC,
88 BPF_MAP_TYPE_HASH,
89 BPF_MAP_TYPE_ARRAY,
90 BPF_MAP_TYPE_PROG_ARRAY,
91 BPF_MAP_TYPE_PERF_EVENT_ARRAY,
92 BPF_MAP_TYPE_PERCPU_HASH,
93 BPF_MAP_TYPE_PERCPU_ARRAY,
94 BPF_MAP_TYPE_STACK_TRACE,
95 BPF_MAP_TYPE_CGROUP_ARRAY,
96 BPF_MAP_TYPE_LRU_HASH,
97 BPF_MAP_TYPE_LRU_PERCPU_HASH,
98 BPF_MAP_TYPE_LPM_TRIE,
99 BPF_MAP_TYPE_ARRAY_OF_MAPS,
100 BPF_MAP_TYPE_HASH_OF_MAPS,
101 };
102
103 enum bpf_prog_type {
104 BPF_PROG_TYPE_UNSPEC,
105 BPF_PROG_TYPE_SOCKET_FILTER,
106 BPF_PROG_TYPE_KPROBE,
107 BPF_PROG_TYPE_SCHED_CLS,
108 BPF_PROG_TYPE_SCHED_ACT,
109 BPF_PROG_TYPE_TRACEPOINT,
110 BPF_PROG_TYPE_XDP,
111 BPF_PROG_TYPE_PERF_EVENT,
112 BPF_PROG_TYPE_CGROUP_SKB,
113 BPF_PROG_TYPE_CGROUP_SOCK,
114 BPF_PROG_TYPE_LWT_IN,
115 BPF_PROG_TYPE_LWT_OUT,
116 BPF_PROG_TYPE_LWT_XMIT,
117 };
118
119 enum bpf_attach_type {
120 BPF_CGROUP_INET_INGRESS,
121 BPF_CGROUP_INET_EGRESS,
122 BPF_CGROUP_INET_SOCK_CREATE,
123 __MAX_BPF_ATTACH_TYPE
124 };
125
126 #define MAX_BPF_ATTACH_TYPE __MAX_BPF_ATTACH_TYPE
127
128 /* If BPF_F_ALLOW_OVERRIDE flag is used in BPF_PROG_ATTACH command
129 * to the given target_fd cgroup the descendent cgroup will be able to
130 * override effective bpf program that was inherited from this cgroup
131 */
132 #define BPF_F_ALLOW_OVERRIDE (1U << 0)
133
134 #define BPF_PSEUDO_MAP_FD 1
135
136 /* flags for BPF_MAP_UPDATE_ELEM command */
137 #define BPF_ANY 0 /* create new element or update existing */
138 #define BPF_NOEXIST 1 /* create new element if it didn't exist */
139 #define BPF_EXIST 2 /* update existing element */
140
141 #define BPF_F_NO_PREALLOC (1U << 0)
142 /* Instead of having one common LRU list in the
143 * BPF_MAP_TYPE_LRU_[PERCPU_]HASH map, use a percpu LRU list
144 * which can scale and perform better.
145 * Note, the LRU nodes (including free nodes) cannot be moved
146 * across different LRU lists.
147 */
148 #define BPF_F_NO_COMMON_LRU (1U << 1)
149
150 union bpf_attr {
151 struct { /* anonymous struct used by BPF_MAP_CREATE command */
152 __u32 map_type; /* one of enum bpf_map_type */
153 __u32 key_size; /* size of key in bytes */
154 __u32 value_size; /* size of value in bytes */
155 __u32 max_entries; /* max number of entries in a map */
156 __u32 map_flags; /* prealloc or not */
157 __u32 inner_map_fd; /* fd pointing to the inner map */
158 };
159
160 struct { /* anonymous struct used by BPF_MAP_*_ELEM commands */
161 __u32 map_fd;
162 __aligned_u64 key;
163 union {
164 __aligned_u64 value;
165 __aligned_u64 next_key;
166 };
167 __u64 flags;
168 };
169
170 struct { /* anonymous struct used by BPF_PROG_LOAD command */
171 __u32 prog_type; /* one of enum bpf_prog_type */
172 __u32 insn_cnt;
173 __aligned_u64 insns;
174 __aligned_u64 license;
175 __u32 log_level; /* verbosity level of verifier */
176 __u32 log_size; /* size of user buffer */
177 __aligned_u64 log_buf; /* user supplied buffer */
178 __u32 kern_version; /* checked when prog_type=kprobe */
179 };
180
181 struct { /* anonymous struct used by BPF_OBJ_* commands */
182 __aligned_u64 pathname;
183 __u32 bpf_fd;
184 };
185
186 struct { /* anonymous struct used by BPF_PROG_ATTACH/DETACH commands */
187 __u32 target_fd; /* container object to attach to */
188 __u32 attach_bpf_fd; /* eBPF program to attach */
189 __u32 attach_type;
190 __u32 attach_flags;
191 };
192 } __attribute__((aligned(8)));
193
194 /* BPF helper function descriptions:
195 *
196 * void *bpf_map_lookup_elem(&map, &key)
197 * Return: Map value or NULL
198 *
199 * int bpf_map_update_elem(&map, &key, &value, flags)
200 * Return: 0 on success or negative error
201 *
202 * int bpf_map_delete_elem(&map, &key)
203 * Return: 0 on success or negative error
204 *
205 * int bpf_probe_read(void *dst, int size, void *src)
206 * Return: 0 on success or negative error
207 *
208 * u64 bpf_ktime_get_ns(void)
209 * Return: current ktime
210 *
211 * int bpf_trace_printk(const char *fmt, int fmt_size, ...)
212 * Return: length of buffer written or negative error
213 *
214 * u32 bpf_prandom_u32(void)
215 * Return: random value
216 *
217 * u32 bpf_raw_smp_processor_id(void)
218 * Return: SMP processor ID
219 *
220 * int bpf_skb_store_bytes(skb, offset, from, len, flags)
221 * store bytes into packet
222 * @skb: pointer to skb
223 * @offset: offset within packet from skb->mac_header
224 * @from: pointer where to copy bytes from
225 * @len: number of bytes to store into packet
226 * @flags: bit 0 - if true, recompute skb->csum
227 * other bits - reserved
228 * Return: 0 on success or negative error
229 *
230 * int bpf_l3_csum_replace(skb, offset, from, to, flags)
231 * recompute IP checksum
232 * @skb: pointer to skb
233 * @offset: offset within packet where IP checksum is located
234 * @from: old value of header field
235 * @to: new value of header field
236 * @flags: bits 0-3 - size of header field
237 * other bits - reserved
238 * Return: 0 on success or negative error
239 *
240 * int bpf_l4_csum_replace(skb, offset, from, to, flags)
241 * recompute TCP/UDP checksum
242 * @skb: pointer to skb
243 * @offset: offset within packet where TCP/UDP checksum is located
244 * @from: old value of header field
245 * @to: new value of header field
246 * @flags: bits 0-3 - size of header field
247 * bit 4 - is pseudo header
248 * other bits - reserved
249 * Return: 0 on success or negative error
250 *
251 * int bpf_tail_call(ctx, prog_array_map, index)
252 * jump into another BPF program
253 * @ctx: context pointer passed to next program
254 * @prog_array_map: pointer to map which type is BPF_MAP_TYPE_PROG_ARRAY
255 * @index: index inside array that selects specific program to run
256 * Return: 0 on success or negative error
257 *
258 * int bpf_clone_redirect(skb, ifindex, flags)
259 * redirect to another netdev
260 * @skb: pointer to skb
261 * @ifindex: ifindex of the net device
262 * @flags: bit 0 - if set, redirect to ingress instead of egress
263 * other bits - reserved
264 * Return: 0 on success or negative error
265 *
266 * u64 bpf_get_current_pid_tgid(void)
267 * Return: current->tgid << 32 | current->pid
268 *
269 * u64 bpf_get_current_uid_gid(void)
270 * Return: current_gid << 32 | current_uid
271 *
272 * int bpf_get_current_comm(char *buf, int size_of_buf)
273 * stores current->comm into buf
274 * Return: 0 on success or negative error
275 *
276 * u32 bpf_get_cgroup_classid(skb)
277 * retrieve a proc's classid
278 * @skb: pointer to skb
279 * Return: classid if != 0
280 *
281 * int bpf_skb_vlan_push(skb, vlan_proto, vlan_tci)
282 * Return: 0 on success or negative error
283 *
284 * int bpf_skb_vlan_pop(skb)
285 * Return: 0 on success or negative error
286 *
287 * int bpf_skb_get_tunnel_key(skb, key, size, flags)
288 * int bpf_skb_set_tunnel_key(skb, key, size, flags)
289 * retrieve or populate tunnel metadata
290 * @skb: pointer to skb
291 * @key: pointer to 'struct bpf_tunnel_key'
292 * @size: size of 'struct bpf_tunnel_key'
293 * @flags: room for future extensions
294 * Return: 0 on success or negative error
295 *
296 * u64 bpf_perf_event_read(&map, index)
297 * Return: Number events read or error code
298 *
299 * int bpf_redirect(ifindex, flags)
300 * redirect to another netdev
301 * @ifindex: ifindex of the net device
302 * @flags: bit 0 - if set, redirect to ingress instead of egress
303 * other bits - reserved
304 * Return: TC_ACT_REDIRECT
305 *
306 * u32 bpf_get_route_realm(skb)
307 * retrieve a dst's tclassid
308 * @skb: pointer to skb
309 * Return: realm if != 0
310 *
311 * int bpf_perf_event_output(ctx, map, index, data, size)
312 * output perf raw sample
313 * @ctx: struct pt_regs*
314 * @map: pointer to perf_event_array map
315 * @index: index of event in the map
316 * @data: data on stack to be output as raw data
317 * @size: size of data
318 * Return: 0 on success or negative error
319 *
320 * int bpf_get_stackid(ctx, map, flags)
321 * walk user or kernel stack and return id
322 * @ctx: struct pt_regs*
323 * @map: pointer to stack_trace map
324 * @flags: bits 0-7 - numer of stack frames to skip
325 * bit 8 - collect user stack instead of kernel
326 * bit 9 - compare stacks by hash only
327 * bit 10 - if two different stacks hash into the same stackid
328 * discard old
329 * other bits - reserved
330 * Return: >= 0 stackid on success or negative error
331 *
332 * s64 bpf_csum_diff(from, from_size, to, to_size, seed)
333 * calculate csum diff
334 * @from: raw from buffer
335 * @from_size: length of from buffer
336 * @to: raw to buffer
337 * @to_size: length of to buffer
338 * @seed: optional seed
339 * Return: csum result or negative error code
340 *
341 * int bpf_skb_get_tunnel_opt(skb, opt, size)
342 * retrieve tunnel options metadata
343 * @skb: pointer to skb
344 * @opt: pointer to raw tunnel option data
345 * @size: size of @opt
346 * Return: option size
347 *
348 * int bpf_skb_set_tunnel_opt(skb, opt, size)
349 * populate tunnel options metadata
350 * @skb: pointer to skb
351 * @opt: pointer to raw tunnel option data
352 * @size: size of @opt
353 * Return: 0 on success or negative error
354 *
355 * int bpf_skb_change_proto(skb, proto, flags)
356 * Change protocol of the skb. Currently supported is v4 -> v6,
357 * v6 -> v4 transitions. The helper will also resize the skb. eBPF
358 * program is expected to fill the new headers via skb_store_bytes
359 * and lX_csum_replace.
360 * @skb: pointer to skb
361 * @proto: new skb->protocol type
362 * @flags: reserved
363 * Return: 0 on success or negative error
364 *
365 * int bpf_skb_change_type(skb, type)
366 * Change packet type of skb.
367 * @skb: pointer to skb
368 * @type: new skb->pkt_type type
369 * Return: 0 on success or negative error
370 *
371 * int bpf_skb_under_cgroup(skb, map, index)
372 * Check cgroup2 membership of skb
373 * @skb: pointer to skb
374 * @map: pointer to bpf_map in BPF_MAP_TYPE_CGROUP_ARRAY type
375 * @index: index of the cgroup in the bpf_map
376 * Return:
377 * == 0 skb failed the cgroup2 descendant test
378 * == 1 skb succeeded the cgroup2 descendant test
379 * < 0 error
380 *
381 * u32 bpf_get_hash_recalc(skb)
382 * Retrieve and possibly recalculate skb->hash.
383 * @skb: pointer to skb
384 * Return: hash
385 *
386 * u64 bpf_get_current_task(void)
387 * Returns current task_struct
388 * Return: current
389 *
390 * int bpf_probe_write_user(void *dst, void *src, int len)
391 * safely attempt to write to a location
392 * @dst: destination address in userspace
393 * @src: source address on stack
394 * @len: number of bytes to copy
395 * Return: 0 on success or negative error
396 *
397 * int bpf_current_task_under_cgroup(map, index)
398 * Check cgroup2 membership of current task
399 * @map: pointer to bpf_map in BPF_MAP_TYPE_CGROUP_ARRAY type
400 * @index: index of the cgroup in the bpf_map
401 * Return:
402 * == 0 current failed the cgroup2 descendant test
403 * == 1 current succeeded the cgroup2 descendant test
404 * < 0 error
405 *
406 * int bpf_skb_change_tail(skb, len, flags)
407 * The helper will resize the skb to the given new size, to be used f.e.
408 * with control messages.
409 * @skb: pointer to skb
410 * @len: new skb length
411 * @flags: reserved
412 * Return: 0 on success or negative error
413 *
414 * int bpf_skb_pull_data(skb, len)
415 * The helper will pull in non-linear data in case the skb is non-linear
416 * and not all of len are part of the linear section. Only needed for
417 * read/write with direct packet access.
418 * @skb: pointer to skb
419 * @len: len to make read/writeable
420 * Return: 0 on success or negative error
421 *
422 * s64 bpf_csum_update(skb, csum)
423 * Adds csum into skb->csum in case of CHECKSUM_COMPLETE.
424 * @skb: pointer to skb
425 * @csum: csum to add
426 * Return: csum on success or negative error
427 *
428 * void bpf_set_hash_invalid(skb)
429 * Invalidate current skb->hash.
430 * @skb: pointer to skb
431 *
432 * int bpf_get_numa_node_id()
433 * Return: Id of current NUMA node.
434 *
435 * int bpf_skb_change_head()
436 * Grows headroom of skb and adjusts MAC header offset accordingly.
437 * Will extends/reallocae as required automatically.
438 * May change skb data pointer and will thus invalidate any check
439 * performed for direct packet access.
440 * @skb: pointer to skb
441 * @len: length of header to be pushed in front
442 * @flags: Flags (unused for now)
443 * Return: 0 on success or negative error
444 *
445 * int bpf_xdp_adjust_head(xdp_md, delta)
446 * Adjust the xdp_md.data by delta
447 * @xdp_md: pointer to xdp_md
448 * @delta: An positive/negative integer to be added to xdp_md.data
449 * Return: 0 on success or negative on error
450 *
451 * int bpf_probe_read_str(void *dst, int size, const void *unsafe_ptr)
452 * Copy a NUL terminated string from unsafe address. In case the string
453 * length is smaller than size, the target is not padded with further NUL
454 * bytes. In case the string length is larger than size, just count-1
455 * bytes are copied and the last byte is set to NUL.
456 * @dst: destination address
457 * @size: maximum number of bytes to copy, including the trailing NUL
458 * @unsafe_ptr: unsafe address
459 * Return:
460 * > 0 length of the string including the trailing NUL on success
461 * < 0 error
462 */
463 #define __BPF_FUNC_MAPPER(FN) \
464 FN(unspec), \
465 FN(map_lookup_elem), \
466 FN(map_update_elem), \
467 FN(map_delete_elem), \
468 FN(probe_read), \
469 FN(ktime_get_ns), \
470 FN(trace_printk), \
471 FN(get_prandom_u32), \
472 FN(get_smp_processor_id), \
473 FN(skb_store_bytes), \
474 FN(l3_csum_replace), \
475 FN(l4_csum_replace), \
476 FN(tail_call), \
477 FN(clone_redirect), \
478 FN(get_current_pid_tgid), \
479 FN(get_current_uid_gid), \
480 FN(get_current_comm), \
481 FN(get_cgroup_classid), \
482 FN(skb_vlan_push), \
483 FN(skb_vlan_pop), \
484 FN(skb_get_tunnel_key), \
485 FN(skb_set_tunnel_key), \
486 FN(perf_event_read), \
487 FN(redirect), \
488 FN(get_route_realm), \
489 FN(perf_event_output), \
490 FN(skb_load_bytes), \
491 FN(get_stackid), \
492 FN(csum_diff), \
493 FN(skb_get_tunnel_opt), \
494 FN(skb_set_tunnel_opt), \
495 FN(skb_change_proto), \
496 FN(skb_change_type), \
497 FN(skb_under_cgroup), \
498 FN(get_hash_recalc), \
499 FN(get_current_task), \
500 FN(probe_write_user), \
501 FN(current_task_under_cgroup), \
502 FN(skb_change_tail), \
503 FN(skb_pull_data), \
504 FN(csum_update), \
505 FN(set_hash_invalid), \
506 FN(get_numa_node_id), \
507 FN(skb_change_head), \
508 FN(xdp_adjust_head), \
509 FN(probe_read_str), \
510 FN(get_socket_cookie),
511
512 /* integer value in 'imm' field of BPF_CALL instruction selects which helper
513 * function eBPF program intends to call
514 */
515 #define __BPF_ENUM_FN(x) BPF_FUNC_ ## x
516 enum bpf_func_id {
517 __BPF_FUNC_MAPPER(__BPF_ENUM_FN)
518 __BPF_FUNC_MAX_ID,
519 };
520 #undef __BPF_ENUM_FN
521
522 /* All flags used by eBPF helper functions, placed here. */
523
524 /* BPF_FUNC_skb_store_bytes flags. */
525 #define BPF_F_RECOMPUTE_CSUM (1ULL << 0)
526 #define BPF_F_INVALIDATE_HASH (1ULL << 1)
527
528 /* BPF_FUNC_l3_csum_replace and BPF_FUNC_l4_csum_replace flags.
529 * First 4 bits are for passing the header field size.
530 */
531 #define BPF_F_HDR_FIELD_MASK 0xfULL
532
533 /* BPF_FUNC_l4_csum_replace flags. */
534 #define BPF_F_PSEUDO_HDR (1ULL << 4)
535 #define BPF_F_MARK_MANGLED_0 (1ULL << 5)
536 #define BPF_F_MARK_ENFORCE (1ULL << 6)
537
538 /* BPF_FUNC_clone_redirect and BPF_FUNC_redirect flags. */
539 #define BPF_F_INGRESS (1ULL << 0)
540
541 /* BPF_FUNC_skb_set_tunnel_key and BPF_FUNC_skb_get_tunnel_key flags. */
542 #define BPF_F_TUNINFO_IPV6 (1ULL << 0)
543
544 /* BPF_FUNC_get_stackid flags. */
545 #define BPF_F_SKIP_FIELD_MASK 0xffULL
546 #define BPF_F_USER_STACK (1ULL << 8)
547 #define BPF_F_FAST_STACK_CMP (1ULL << 9)
548 #define BPF_F_REUSE_STACKID (1ULL << 10)
549
550 /* BPF_FUNC_skb_set_tunnel_key flags. */
551 #define BPF_F_ZERO_CSUM_TX (1ULL << 1)
552 #define BPF_F_DONT_FRAGMENT (1ULL << 2)
553
554 /* BPF_FUNC_perf_event_output and BPF_FUNC_perf_event_read flags. */
555 #define BPF_F_INDEX_MASK 0xffffffffULL
556 #define BPF_F_CURRENT_CPU BPF_F_INDEX_MASK
557 /* BPF_FUNC_perf_event_output for sk_buff input context. */
558 #define BPF_F_CTXLEN_MASK (0xfffffULL << 32)
559
560 /* user accessible mirror of in-kernel sk_buff.
561 * new fields can only be added to the end of this structure
562 */
563 struct __sk_buff {
564 __u32 len;
565 __u32 pkt_type;
566 __u32 mark;
567 __u32 queue_mapping;
568 __u32 protocol;
569 __u32 vlan_present;
570 __u32 vlan_tci;
571 __u32 vlan_proto;
572 __u32 priority;
573 __u32 ingress_ifindex;
574 __u32 ifindex;
575 __u32 tc_index;
576 __u32 cb[5];
577 __u32 hash;
578 __u32 tc_classid;
579 __u32 data;
580 __u32 data_end;
581 };
582
583 struct bpf_tunnel_key {
584 __u32 tunnel_id;
585 union {
586 __u32 remote_ipv4;
587 __u32 remote_ipv6[4];
588 };
589 __u8 tunnel_tos;
590 __u8 tunnel_ttl;
591 __u16 tunnel_ext;
592 __u32 tunnel_label;
593 };
594
595 /* Generic BPF return codes which all BPF program types may support.
596 * The values are binary compatible with their TC_ACT_* counter-part to
597 * provide backwards compatibility with existing SCHED_CLS and SCHED_ACT
598 * programs.
599 *
600 * XDP is handled seprately, see XDP_*.
601 */
602 enum bpf_ret_code {
603 BPF_OK = 0,
604 /* 1 reserved */
605 BPF_DROP = 2,
606 /* 3-6 reserved */
607 BPF_REDIRECT = 7,
608 /* >127 are reserved for prog type specific return codes */
609 };
610
611 struct bpf_sock {
612 __u32 bound_dev_if;
613 __u32 family;
614 __u32 type;
615 __u32 protocol;
616 };
617
618 #define XDP_PACKET_HEADROOM 256
619
620 /* User return codes for XDP prog type.
621 * A valid XDP program must return one of these defined values. All other
622 * return codes are reserved for future use. Unknown return codes will result
623 * in packet drop.
624 */
625 enum xdp_action {
626 XDP_ABORTED = 0,
627 XDP_DROP,
628 XDP_PASS,
629 XDP_TX,
630 };
631
632 /* user accessible metadata for XDP packet hook
633 * new fields must be added to the end of this structure
634 */
635 struct xdp_md {
636 __u32 data;
637 __u32 data_end;
638 };
639
640 #endif /* _UAPI__LINUX_BPF_H__ */