17c2aad20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
27c2aad20Sopenharmony_ci/* Copyright (c) 2011-2014 PLUMgrid, http://plumgrid.com
37c2aad20Sopenharmony_ci *
47c2aad20Sopenharmony_ci * This program is free software; you can redistribute it and/or
57c2aad20Sopenharmony_ci * modify it under the terms of version 2 of the GNU General Public
67c2aad20Sopenharmony_ci * License as published by the Free Software Foundation.
77c2aad20Sopenharmony_ci */
87c2aad20Sopenharmony_ci#ifndef _UAPI__LINUX_BPF_H__
97c2aad20Sopenharmony_ci#define _UAPI__LINUX_BPF_H__
107c2aad20Sopenharmony_ci
117c2aad20Sopenharmony_ci#include <linux/types.h>
127c2aad20Sopenharmony_ci#include <linux/bpf_common.h>
137c2aad20Sopenharmony_ci
147c2aad20Sopenharmony_ci/* Extended instruction set based on top of classic BPF */
157c2aad20Sopenharmony_ci
167c2aad20Sopenharmony_ci/* instruction classes */
177c2aad20Sopenharmony_ci#define BPF_JMP32	0x06	/* jmp mode in word width */
187c2aad20Sopenharmony_ci#define BPF_ALU64	0x07	/* alu mode in double word width */
197c2aad20Sopenharmony_ci
207c2aad20Sopenharmony_ci/* ld/ldx fields */
217c2aad20Sopenharmony_ci#define BPF_DW		0x18	/* double word (64-bit) */
227c2aad20Sopenharmony_ci#define BPF_MEMSX	0x80	/* load with sign extension */
237c2aad20Sopenharmony_ci#define BPF_ATOMIC	0xc0	/* atomic memory ops - op type in immediate */
247c2aad20Sopenharmony_ci#define BPF_XADD	0xc0	/* exclusive add - legacy name */
257c2aad20Sopenharmony_ci
267c2aad20Sopenharmony_ci/* alu/jmp fields */
277c2aad20Sopenharmony_ci#define BPF_MOV		0xb0	/* mov reg to reg */
287c2aad20Sopenharmony_ci#define BPF_ARSH	0xc0	/* sign extending arithmetic shift right */
297c2aad20Sopenharmony_ci
307c2aad20Sopenharmony_ci/* change endianness of a register */
317c2aad20Sopenharmony_ci#define BPF_END		0xd0	/* flags for endianness conversion: */
327c2aad20Sopenharmony_ci#define BPF_TO_LE	0x00	/* convert to little-endian */
337c2aad20Sopenharmony_ci#define BPF_TO_BE	0x08	/* convert to big-endian */
347c2aad20Sopenharmony_ci#define BPF_FROM_LE	BPF_TO_LE
357c2aad20Sopenharmony_ci#define BPF_FROM_BE	BPF_TO_BE
367c2aad20Sopenharmony_ci
377c2aad20Sopenharmony_ci/* jmp encodings */
387c2aad20Sopenharmony_ci#define BPF_JNE		0x50	/* jump != */
397c2aad20Sopenharmony_ci#define BPF_JLT		0xa0	/* LT is unsigned, '<' */
407c2aad20Sopenharmony_ci#define BPF_JLE		0xb0	/* LE is unsigned, '<=' */
417c2aad20Sopenharmony_ci#define BPF_JSGT	0x60	/* SGT is signed '>', GT in x86 */
427c2aad20Sopenharmony_ci#define BPF_JSGE	0x70	/* SGE is signed '>=', GE in x86 */
437c2aad20Sopenharmony_ci#define BPF_JSLT	0xc0	/* SLT is signed, '<' */
447c2aad20Sopenharmony_ci#define BPF_JSLE	0xd0	/* SLE is signed, '<=' */
457c2aad20Sopenharmony_ci#define BPF_CALL	0x80	/* function call */
467c2aad20Sopenharmony_ci#define BPF_EXIT	0x90	/* function return */
477c2aad20Sopenharmony_ci
487c2aad20Sopenharmony_ci/* atomic op type fields (stored in immediate) */
497c2aad20Sopenharmony_ci#define BPF_FETCH	0x01	/* not an opcode on its own, used to build others */
507c2aad20Sopenharmony_ci#define BPF_XCHG	(0xe0 | BPF_FETCH)	/* atomic exchange */
517c2aad20Sopenharmony_ci#define BPF_CMPXCHG	(0xf0 | BPF_FETCH)	/* atomic compare-and-write */
527c2aad20Sopenharmony_ci
537c2aad20Sopenharmony_ci/* Register numbers */
547c2aad20Sopenharmony_cienum {
557c2aad20Sopenharmony_ci	BPF_REG_0 = 0,
567c2aad20Sopenharmony_ci	BPF_REG_1,
577c2aad20Sopenharmony_ci	BPF_REG_2,
587c2aad20Sopenharmony_ci	BPF_REG_3,
597c2aad20Sopenharmony_ci	BPF_REG_4,
607c2aad20Sopenharmony_ci	BPF_REG_5,
617c2aad20Sopenharmony_ci	BPF_REG_6,
627c2aad20Sopenharmony_ci	BPF_REG_7,
637c2aad20Sopenharmony_ci	BPF_REG_8,
647c2aad20Sopenharmony_ci	BPF_REG_9,
657c2aad20Sopenharmony_ci	BPF_REG_10,
667c2aad20Sopenharmony_ci	__MAX_BPF_REG,
677c2aad20Sopenharmony_ci};
687c2aad20Sopenharmony_ci
697c2aad20Sopenharmony_ci/* BPF has 10 general purpose 64-bit registers and stack frame. */
707c2aad20Sopenharmony_ci#define MAX_BPF_REG	__MAX_BPF_REG
717c2aad20Sopenharmony_ci
727c2aad20Sopenharmony_cistruct bpf_insn {
737c2aad20Sopenharmony_ci	__u8	code;		/* opcode */
747c2aad20Sopenharmony_ci	__u8	dst_reg:4;	/* dest register */
757c2aad20Sopenharmony_ci	__u8	src_reg:4;	/* source register */
767c2aad20Sopenharmony_ci	__s16	off;		/* signed offset */
777c2aad20Sopenharmony_ci	__s32	imm;		/* signed immediate constant */
787c2aad20Sopenharmony_ci};
797c2aad20Sopenharmony_ci
807c2aad20Sopenharmony_ci/* Key of an a BPF_MAP_TYPE_LPM_TRIE entry */
817c2aad20Sopenharmony_cistruct bpf_lpm_trie_key {
827c2aad20Sopenharmony_ci	__u32	prefixlen;	/* up to 32 for AF_INET, 128 for AF_INET6 */
837c2aad20Sopenharmony_ci	__u8	data[0];	/* Arbitrary size */
847c2aad20Sopenharmony_ci};
857c2aad20Sopenharmony_ci
867c2aad20Sopenharmony_cistruct bpf_cgroup_storage_key {
877c2aad20Sopenharmony_ci	__u64	cgroup_inode_id;	/* cgroup inode id */
887c2aad20Sopenharmony_ci	__u32	attach_type;		/* program attach type (enum bpf_attach_type) */
897c2aad20Sopenharmony_ci};
907c2aad20Sopenharmony_ci
917c2aad20Sopenharmony_cienum bpf_cgroup_iter_order {
927c2aad20Sopenharmony_ci	BPF_CGROUP_ITER_ORDER_UNSPEC = 0,
937c2aad20Sopenharmony_ci	BPF_CGROUP_ITER_SELF_ONLY,		/* process only a single object. */
947c2aad20Sopenharmony_ci	BPF_CGROUP_ITER_DESCENDANTS_PRE,	/* walk descendants in pre-order. */
957c2aad20Sopenharmony_ci	BPF_CGROUP_ITER_DESCENDANTS_POST,	/* walk descendants in post-order. */
967c2aad20Sopenharmony_ci	BPF_CGROUP_ITER_ANCESTORS_UP,		/* walk ancestors upward. */
977c2aad20Sopenharmony_ci};
987c2aad20Sopenharmony_ci
997c2aad20Sopenharmony_ciunion bpf_iter_link_info {
1007c2aad20Sopenharmony_ci	struct {
1017c2aad20Sopenharmony_ci		__u32	map_fd;
1027c2aad20Sopenharmony_ci	} map;
1037c2aad20Sopenharmony_ci	struct {
1047c2aad20Sopenharmony_ci		enum bpf_cgroup_iter_order order;
1057c2aad20Sopenharmony_ci
1067c2aad20Sopenharmony_ci		/* At most one of cgroup_fd and cgroup_id can be non-zero. If
1077c2aad20Sopenharmony_ci		 * both are zero, the walk starts from the default cgroup v2
1087c2aad20Sopenharmony_ci		 * root. For walking v1 hierarchy, one should always explicitly
1097c2aad20Sopenharmony_ci		 * specify cgroup_fd.
1107c2aad20Sopenharmony_ci		 */
1117c2aad20Sopenharmony_ci		__u32	cgroup_fd;
1127c2aad20Sopenharmony_ci		__u64	cgroup_id;
1137c2aad20Sopenharmony_ci	} cgroup;
1147c2aad20Sopenharmony_ci	/* Parameters of task iterators. */
1157c2aad20Sopenharmony_ci	struct {
1167c2aad20Sopenharmony_ci		__u32	tid;
1177c2aad20Sopenharmony_ci		__u32	pid;
1187c2aad20Sopenharmony_ci		__u32	pid_fd;
1197c2aad20Sopenharmony_ci	} task;
1207c2aad20Sopenharmony_ci};
1217c2aad20Sopenharmony_ci
1227c2aad20Sopenharmony_ci/* BPF syscall commands, see bpf(2) man-page for more details. */
1237c2aad20Sopenharmony_ci/**
1247c2aad20Sopenharmony_ci * DOC: eBPF Syscall Preamble
1257c2aad20Sopenharmony_ci *
1267c2aad20Sopenharmony_ci * The operation to be performed by the **bpf**\ () system call is determined
1277c2aad20Sopenharmony_ci * by the *cmd* argument. Each operation takes an accompanying argument,
1287c2aad20Sopenharmony_ci * provided via *attr*, which is a pointer to a union of type *bpf_attr* (see
1297c2aad20Sopenharmony_ci * below). The size argument is the size of the union pointed to by *attr*.
1307c2aad20Sopenharmony_ci */
1317c2aad20Sopenharmony_ci/**
1327c2aad20Sopenharmony_ci * DOC: eBPF Syscall Commands
1337c2aad20Sopenharmony_ci *
1347c2aad20Sopenharmony_ci * BPF_MAP_CREATE
1357c2aad20Sopenharmony_ci *	Description
1367c2aad20Sopenharmony_ci *		Create a map and return a file descriptor that refers to the
1377c2aad20Sopenharmony_ci *		map. The close-on-exec file descriptor flag (see **fcntl**\ (2))
1387c2aad20Sopenharmony_ci *		is automatically enabled for the new file descriptor.
1397c2aad20Sopenharmony_ci *
1407c2aad20Sopenharmony_ci *		Applying **close**\ (2) to the file descriptor returned by
1417c2aad20Sopenharmony_ci *		**BPF_MAP_CREATE** will delete the map (but see NOTES).
1427c2aad20Sopenharmony_ci *
1437c2aad20Sopenharmony_ci *	Return
1447c2aad20Sopenharmony_ci *		A new file descriptor (a nonnegative integer), or -1 if an
1457c2aad20Sopenharmony_ci *		error occurred (in which case, *errno* is set appropriately).
1467c2aad20Sopenharmony_ci *
1477c2aad20Sopenharmony_ci * BPF_MAP_LOOKUP_ELEM
1487c2aad20Sopenharmony_ci *	Description
1497c2aad20Sopenharmony_ci *		Look up an element with a given *key* in the map referred to
1507c2aad20Sopenharmony_ci *		by the file descriptor *map_fd*.
1517c2aad20Sopenharmony_ci *
1527c2aad20Sopenharmony_ci *		The *flags* argument may be specified as one of the
1537c2aad20Sopenharmony_ci *		following:
1547c2aad20Sopenharmony_ci *
1557c2aad20Sopenharmony_ci *		**BPF_F_LOCK**
1567c2aad20Sopenharmony_ci *			Look up the value of a spin-locked map without
1577c2aad20Sopenharmony_ci *			returning the lock. This must be specified if the
1587c2aad20Sopenharmony_ci *			elements contain a spinlock.
1597c2aad20Sopenharmony_ci *
1607c2aad20Sopenharmony_ci *	Return
1617c2aad20Sopenharmony_ci *		Returns zero on success. On error, -1 is returned and *errno*
1627c2aad20Sopenharmony_ci *		is set appropriately.
1637c2aad20Sopenharmony_ci *
1647c2aad20Sopenharmony_ci * BPF_MAP_UPDATE_ELEM
1657c2aad20Sopenharmony_ci *	Description
1667c2aad20Sopenharmony_ci *		Create or update an element (key/value pair) in a specified map.
1677c2aad20Sopenharmony_ci *
1687c2aad20Sopenharmony_ci *		The *flags* argument should be specified as one of the
1697c2aad20Sopenharmony_ci *		following:
1707c2aad20Sopenharmony_ci *
1717c2aad20Sopenharmony_ci *		**BPF_ANY**
1727c2aad20Sopenharmony_ci *			Create a new element or update an existing element.
1737c2aad20Sopenharmony_ci *		**BPF_NOEXIST**
1747c2aad20Sopenharmony_ci *			Create a new element only if it did not exist.
1757c2aad20Sopenharmony_ci *		**BPF_EXIST**
1767c2aad20Sopenharmony_ci *			Update an existing element.
1777c2aad20Sopenharmony_ci *		**BPF_F_LOCK**
1787c2aad20Sopenharmony_ci *			Update a spin_lock-ed map element.
1797c2aad20Sopenharmony_ci *
1807c2aad20Sopenharmony_ci *	Return
1817c2aad20Sopenharmony_ci *		Returns zero on success. On error, -1 is returned and *errno*
1827c2aad20Sopenharmony_ci *		is set appropriately.
1837c2aad20Sopenharmony_ci *
1847c2aad20Sopenharmony_ci *		May set *errno* to **EINVAL**, **EPERM**, **ENOMEM**,
1857c2aad20Sopenharmony_ci *		**E2BIG**, **EEXIST**, or **ENOENT**.
1867c2aad20Sopenharmony_ci *
1877c2aad20Sopenharmony_ci *		**E2BIG**
1887c2aad20Sopenharmony_ci *			The number of elements in the map reached the
1897c2aad20Sopenharmony_ci *			*max_entries* limit specified at map creation time.
1907c2aad20Sopenharmony_ci *		**EEXIST**
1917c2aad20Sopenharmony_ci *			If *flags* specifies **BPF_NOEXIST** and the element
1927c2aad20Sopenharmony_ci *			with *key* already exists in the map.
1937c2aad20Sopenharmony_ci *		**ENOENT**
1947c2aad20Sopenharmony_ci *			If *flags* specifies **BPF_EXIST** and the element with
1957c2aad20Sopenharmony_ci *			*key* does not exist in the map.
1967c2aad20Sopenharmony_ci *
1977c2aad20Sopenharmony_ci * BPF_MAP_DELETE_ELEM
1987c2aad20Sopenharmony_ci *	Description
1997c2aad20Sopenharmony_ci *		Look up and delete an element by key in a specified map.
2007c2aad20Sopenharmony_ci *
2017c2aad20Sopenharmony_ci *	Return
2027c2aad20Sopenharmony_ci *		Returns zero on success. On error, -1 is returned and *errno*
2037c2aad20Sopenharmony_ci *		is set appropriately.
2047c2aad20Sopenharmony_ci *
2057c2aad20Sopenharmony_ci * BPF_MAP_GET_NEXT_KEY
2067c2aad20Sopenharmony_ci *	Description
2077c2aad20Sopenharmony_ci *		Look up an element by key in a specified map and return the key
2087c2aad20Sopenharmony_ci *		of the next element. Can be used to iterate over all elements
2097c2aad20Sopenharmony_ci *		in the map.
2107c2aad20Sopenharmony_ci *
2117c2aad20Sopenharmony_ci *	Return
2127c2aad20Sopenharmony_ci *		Returns zero on success. On error, -1 is returned and *errno*
2137c2aad20Sopenharmony_ci *		is set appropriately.
2147c2aad20Sopenharmony_ci *
2157c2aad20Sopenharmony_ci *		The following cases can be used to iterate over all elements of
2167c2aad20Sopenharmony_ci *		the map:
2177c2aad20Sopenharmony_ci *
2187c2aad20Sopenharmony_ci *		* If *key* is not found, the operation returns zero and sets
2197c2aad20Sopenharmony_ci *		  the *next_key* pointer to the key of the first element.
2207c2aad20Sopenharmony_ci *		* If *key* is found, the operation returns zero and sets the
2217c2aad20Sopenharmony_ci *		  *next_key* pointer to the key of the next element.
2227c2aad20Sopenharmony_ci *		* If *key* is the last element, returns -1 and *errno* is set
2237c2aad20Sopenharmony_ci *		  to **ENOENT**.
2247c2aad20Sopenharmony_ci *
2257c2aad20Sopenharmony_ci *		May set *errno* to **ENOMEM**, **EFAULT**, **EPERM**, or
2267c2aad20Sopenharmony_ci *		**EINVAL** on error.
2277c2aad20Sopenharmony_ci *
2287c2aad20Sopenharmony_ci * BPF_PROG_LOAD
2297c2aad20Sopenharmony_ci *	Description
2307c2aad20Sopenharmony_ci *		Verify and load an eBPF program, returning a new file
2317c2aad20Sopenharmony_ci *		descriptor associated with the program.
2327c2aad20Sopenharmony_ci *
2337c2aad20Sopenharmony_ci *		Applying **close**\ (2) to the file descriptor returned by
2347c2aad20Sopenharmony_ci *		**BPF_PROG_LOAD** will unload the eBPF program (but see NOTES).
2357c2aad20Sopenharmony_ci *
2367c2aad20Sopenharmony_ci *		The close-on-exec file descriptor flag (see **fcntl**\ (2)) is
2377c2aad20Sopenharmony_ci *		automatically enabled for the new file descriptor.
2387c2aad20Sopenharmony_ci *
2397c2aad20Sopenharmony_ci *	Return
2407c2aad20Sopenharmony_ci *		A new file descriptor (a nonnegative integer), or -1 if an
2417c2aad20Sopenharmony_ci *		error occurred (in which case, *errno* is set appropriately).
2427c2aad20Sopenharmony_ci *
2437c2aad20Sopenharmony_ci * BPF_OBJ_PIN
2447c2aad20Sopenharmony_ci *	Description
2457c2aad20Sopenharmony_ci *		Pin an eBPF program or map referred by the specified *bpf_fd*
2467c2aad20Sopenharmony_ci *		to the provided *pathname* on the filesystem.
2477c2aad20Sopenharmony_ci *
2487c2aad20Sopenharmony_ci *		The *pathname* argument must not contain a dot (".").
2497c2aad20Sopenharmony_ci *
2507c2aad20Sopenharmony_ci *		On success, *pathname* retains a reference to the eBPF object,
2517c2aad20Sopenharmony_ci *		preventing deallocation of the object when the original
2527c2aad20Sopenharmony_ci *		*bpf_fd* is closed. This allow the eBPF object to live beyond
2537c2aad20Sopenharmony_ci *		**close**\ (\ *bpf_fd*\ ), and hence the lifetime of the parent
2547c2aad20Sopenharmony_ci *		process.
2557c2aad20Sopenharmony_ci *
2567c2aad20Sopenharmony_ci *		Applying **unlink**\ (2) or similar calls to the *pathname*
2577c2aad20Sopenharmony_ci *		unpins the object from the filesystem, removing the reference.
2587c2aad20Sopenharmony_ci *		If no other file descriptors or filesystem nodes refer to the
2597c2aad20Sopenharmony_ci *		same object, it will be deallocated (see NOTES).
2607c2aad20Sopenharmony_ci *
2617c2aad20Sopenharmony_ci *		The filesystem type for the parent directory of *pathname* must
2627c2aad20Sopenharmony_ci *		be **BPF_FS_MAGIC**.
2637c2aad20Sopenharmony_ci *
2647c2aad20Sopenharmony_ci *	Return
2657c2aad20Sopenharmony_ci *		Returns zero on success. On error, -1 is returned and *errno*
2667c2aad20Sopenharmony_ci *		is set appropriately.
2677c2aad20Sopenharmony_ci *
2687c2aad20Sopenharmony_ci * BPF_OBJ_GET
2697c2aad20Sopenharmony_ci *	Description
2707c2aad20Sopenharmony_ci *		Open a file descriptor for the eBPF object pinned to the
2717c2aad20Sopenharmony_ci *		specified *pathname*.
2727c2aad20Sopenharmony_ci *
2737c2aad20Sopenharmony_ci *	Return
2747c2aad20Sopenharmony_ci *		A new file descriptor (a nonnegative integer), or -1 if an
2757c2aad20Sopenharmony_ci *		error occurred (in which case, *errno* is set appropriately).
2767c2aad20Sopenharmony_ci *
2777c2aad20Sopenharmony_ci * BPF_PROG_ATTACH
2787c2aad20Sopenharmony_ci *	Description
2797c2aad20Sopenharmony_ci *		Attach an eBPF program to a *target_fd* at the specified
2807c2aad20Sopenharmony_ci *		*attach_type* hook.
2817c2aad20Sopenharmony_ci *
2827c2aad20Sopenharmony_ci *		The *attach_type* specifies the eBPF attachment point to
2837c2aad20Sopenharmony_ci *		attach the program to, and must be one of *bpf_attach_type*
2847c2aad20Sopenharmony_ci *		(see below).
2857c2aad20Sopenharmony_ci *
2867c2aad20Sopenharmony_ci *		The *attach_bpf_fd* must be a valid file descriptor for a
2877c2aad20Sopenharmony_ci *		loaded eBPF program of a cgroup, flow dissector, LIRC, sockmap
2887c2aad20Sopenharmony_ci *		or sock_ops type corresponding to the specified *attach_type*.
2897c2aad20Sopenharmony_ci *
2907c2aad20Sopenharmony_ci *		The *target_fd* must be a valid file descriptor for a kernel
2917c2aad20Sopenharmony_ci *		object which depends on the attach type of *attach_bpf_fd*:
2927c2aad20Sopenharmony_ci *
2937c2aad20Sopenharmony_ci *		**BPF_PROG_TYPE_CGROUP_DEVICE**,
2947c2aad20Sopenharmony_ci *		**BPF_PROG_TYPE_CGROUP_SKB**,
2957c2aad20Sopenharmony_ci *		**BPF_PROG_TYPE_CGROUP_SOCK**,
2967c2aad20Sopenharmony_ci *		**BPF_PROG_TYPE_CGROUP_SOCK_ADDR**,
2977c2aad20Sopenharmony_ci *		**BPF_PROG_TYPE_CGROUP_SOCKOPT**,
2987c2aad20Sopenharmony_ci *		**BPF_PROG_TYPE_CGROUP_SYSCTL**,
2997c2aad20Sopenharmony_ci *		**BPF_PROG_TYPE_SOCK_OPS**
3007c2aad20Sopenharmony_ci *
3017c2aad20Sopenharmony_ci *			Control Group v2 hierarchy with the eBPF controller
3027c2aad20Sopenharmony_ci *			enabled. Requires the kernel to be compiled with
3037c2aad20Sopenharmony_ci *			**CONFIG_CGROUP_BPF**.
3047c2aad20Sopenharmony_ci *
3057c2aad20Sopenharmony_ci *		**BPF_PROG_TYPE_FLOW_DISSECTOR**
3067c2aad20Sopenharmony_ci *
3077c2aad20Sopenharmony_ci *			Network namespace (eg /proc/self/ns/net).
3087c2aad20Sopenharmony_ci *
3097c2aad20Sopenharmony_ci *		**BPF_PROG_TYPE_LIRC_MODE2**
3107c2aad20Sopenharmony_ci *
3117c2aad20Sopenharmony_ci *			LIRC device path (eg /dev/lircN). Requires the kernel
3127c2aad20Sopenharmony_ci *			to be compiled with **CONFIG_BPF_LIRC_MODE2**.
3137c2aad20Sopenharmony_ci *
3147c2aad20Sopenharmony_ci *		**BPF_PROG_TYPE_SK_SKB**,
3157c2aad20Sopenharmony_ci *		**BPF_PROG_TYPE_SK_MSG**
3167c2aad20Sopenharmony_ci *
3177c2aad20Sopenharmony_ci *			eBPF map of socket type (eg **BPF_MAP_TYPE_SOCKHASH**).
3187c2aad20Sopenharmony_ci *
3197c2aad20Sopenharmony_ci *	Return
3207c2aad20Sopenharmony_ci *		Returns zero on success. On error, -1 is returned and *errno*
3217c2aad20Sopenharmony_ci *		is set appropriately.
3227c2aad20Sopenharmony_ci *
3237c2aad20Sopenharmony_ci * BPF_PROG_DETACH
3247c2aad20Sopenharmony_ci *	Description
3257c2aad20Sopenharmony_ci *		Detach the eBPF program associated with the *target_fd* at the
3267c2aad20Sopenharmony_ci *		hook specified by *attach_type*. The program must have been
3277c2aad20Sopenharmony_ci *		previously attached using **BPF_PROG_ATTACH**.
3287c2aad20Sopenharmony_ci *
3297c2aad20Sopenharmony_ci *	Return
3307c2aad20Sopenharmony_ci *		Returns zero on success. On error, -1 is returned and *errno*
3317c2aad20Sopenharmony_ci *		is set appropriately.
3327c2aad20Sopenharmony_ci *
3337c2aad20Sopenharmony_ci * BPF_PROG_TEST_RUN
3347c2aad20Sopenharmony_ci *	Description
3357c2aad20Sopenharmony_ci *		Run the eBPF program associated with the *prog_fd* a *repeat*
3367c2aad20Sopenharmony_ci *		number of times against a provided program context *ctx_in* and
3377c2aad20Sopenharmony_ci *		data *data_in*, and return the modified program context
3387c2aad20Sopenharmony_ci *		*ctx_out*, *data_out* (for example, packet data), result of the
3397c2aad20Sopenharmony_ci *		execution *retval*, and *duration* of the test run.
3407c2aad20Sopenharmony_ci *
3417c2aad20Sopenharmony_ci *		The sizes of the buffers provided as input and output
3427c2aad20Sopenharmony_ci *		parameters *ctx_in*, *ctx_out*, *data_in*, and *data_out* must
3437c2aad20Sopenharmony_ci *		be provided in the corresponding variables *ctx_size_in*,
3447c2aad20Sopenharmony_ci *		*ctx_size_out*, *data_size_in*, and/or *data_size_out*. If any
3457c2aad20Sopenharmony_ci *		of these parameters are not provided (ie set to NULL), the
3467c2aad20Sopenharmony_ci *		corresponding size field must be zero.
3477c2aad20Sopenharmony_ci *
3487c2aad20Sopenharmony_ci *		Some program types have particular requirements:
3497c2aad20Sopenharmony_ci *
3507c2aad20Sopenharmony_ci *		**BPF_PROG_TYPE_SK_LOOKUP**
3517c2aad20Sopenharmony_ci *			*data_in* and *data_out* must be NULL.
3527c2aad20Sopenharmony_ci *
3537c2aad20Sopenharmony_ci *		**BPF_PROG_TYPE_RAW_TRACEPOINT**,
3547c2aad20Sopenharmony_ci *		**BPF_PROG_TYPE_RAW_TRACEPOINT_WRITABLE**
3557c2aad20Sopenharmony_ci *
3567c2aad20Sopenharmony_ci *			*ctx_out*, *data_in* and *data_out* must be NULL.
3577c2aad20Sopenharmony_ci *			*repeat* must be zero.
3587c2aad20Sopenharmony_ci *
3597c2aad20Sopenharmony_ci *		BPF_PROG_RUN is an alias for BPF_PROG_TEST_RUN.
3607c2aad20Sopenharmony_ci *
3617c2aad20Sopenharmony_ci *	Return
3627c2aad20Sopenharmony_ci *		Returns zero on success. On error, -1 is returned and *errno*
3637c2aad20Sopenharmony_ci *		is set appropriately.
3647c2aad20Sopenharmony_ci *
3657c2aad20Sopenharmony_ci *		**ENOSPC**
3667c2aad20Sopenharmony_ci *			Either *data_size_out* or *ctx_size_out* is too small.
3677c2aad20Sopenharmony_ci *		**ENOTSUPP**
3687c2aad20Sopenharmony_ci *			This command is not supported by the program type of
3697c2aad20Sopenharmony_ci *			the program referred to by *prog_fd*.
3707c2aad20Sopenharmony_ci *
3717c2aad20Sopenharmony_ci * BPF_PROG_GET_NEXT_ID
3727c2aad20Sopenharmony_ci *	Description
3737c2aad20Sopenharmony_ci *		Fetch the next eBPF program currently loaded into the kernel.
3747c2aad20Sopenharmony_ci *
3757c2aad20Sopenharmony_ci *		Looks for the eBPF program with an id greater than *start_id*
3767c2aad20Sopenharmony_ci *		and updates *next_id* on success. If no other eBPF programs
3777c2aad20Sopenharmony_ci *		remain with ids higher than *start_id*, returns -1 and sets
3787c2aad20Sopenharmony_ci *		*errno* to **ENOENT**.
3797c2aad20Sopenharmony_ci *
3807c2aad20Sopenharmony_ci *	Return
3817c2aad20Sopenharmony_ci *		Returns zero on success. On error, or when no id remains, -1
3827c2aad20Sopenharmony_ci *		is returned and *errno* is set appropriately.
3837c2aad20Sopenharmony_ci *
3847c2aad20Sopenharmony_ci * BPF_MAP_GET_NEXT_ID
3857c2aad20Sopenharmony_ci *	Description
3867c2aad20Sopenharmony_ci *		Fetch the next eBPF map currently loaded into the kernel.
3877c2aad20Sopenharmony_ci *
3887c2aad20Sopenharmony_ci *		Looks for the eBPF map with an id greater than *start_id*
3897c2aad20Sopenharmony_ci *		and updates *next_id* on success. If no other eBPF maps
3907c2aad20Sopenharmony_ci *		remain with ids higher than *start_id*, returns -1 and sets
3917c2aad20Sopenharmony_ci *		*errno* to **ENOENT**.
3927c2aad20Sopenharmony_ci *
3937c2aad20Sopenharmony_ci *	Return
3947c2aad20Sopenharmony_ci *		Returns zero on success. On error, or when no id remains, -1
3957c2aad20Sopenharmony_ci *		is returned and *errno* is set appropriately.
3967c2aad20Sopenharmony_ci *
3977c2aad20Sopenharmony_ci * BPF_PROG_GET_FD_BY_ID
3987c2aad20Sopenharmony_ci *	Description
3997c2aad20Sopenharmony_ci *		Open a file descriptor for the eBPF program corresponding to
4007c2aad20Sopenharmony_ci *		*prog_id*.
4017c2aad20Sopenharmony_ci *
4027c2aad20Sopenharmony_ci *	Return
4037c2aad20Sopenharmony_ci *		A new file descriptor (a nonnegative integer), or -1 if an
4047c2aad20Sopenharmony_ci *		error occurred (in which case, *errno* is set appropriately).
4057c2aad20Sopenharmony_ci *
4067c2aad20Sopenharmony_ci * BPF_MAP_GET_FD_BY_ID
4077c2aad20Sopenharmony_ci *	Description
4087c2aad20Sopenharmony_ci *		Open a file descriptor for the eBPF map corresponding to
4097c2aad20Sopenharmony_ci *		*map_id*.
4107c2aad20Sopenharmony_ci *
4117c2aad20Sopenharmony_ci *	Return
4127c2aad20Sopenharmony_ci *		A new file descriptor (a nonnegative integer), or -1 if an
4137c2aad20Sopenharmony_ci *		error occurred (in which case, *errno* is set appropriately).
4147c2aad20Sopenharmony_ci *
4157c2aad20Sopenharmony_ci * BPF_OBJ_GET_INFO_BY_FD
4167c2aad20Sopenharmony_ci *	Description
4177c2aad20Sopenharmony_ci *		Obtain information about the eBPF object corresponding to
4187c2aad20Sopenharmony_ci *		*bpf_fd*.
4197c2aad20Sopenharmony_ci *
4207c2aad20Sopenharmony_ci *		Populates up to *info_len* bytes of *info*, which will be in
4217c2aad20Sopenharmony_ci *		one of the following formats depending on the eBPF object type
4227c2aad20Sopenharmony_ci *		of *bpf_fd*:
4237c2aad20Sopenharmony_ci *
4247c2aad20Sopenharmony_ci *		* **struct bpf_prog_info**
4257c2aad20Sopenharmony_ci *		* **struct bpf_map_info**
4267c2aad20Sopenharmony_ci *		* **struct bpf_btf_info**
4277c2aad20Sopenharmony_ci *		* **struct bpf_link_info**
4287c2aad20Sopenharmony_ci *
4297c2aad20Sopenharmony_ci *	Return
4307c2aad20Sopenharmony_ci *		Returns zero on success. On error, -1 is returned and *errno*
4317c2aad20Sopenharmony_ci *		is set appropriately.
4327c2aad20Sopenharmony_ci *
4337c2aad20Sopenharmony_ci * BPF_PROG_QUERY
4347c2aad20Sopenharmony_ci *	Description
4357c2aad20Sopenharmony_ci *		Obtain information about eBPF programs associated with the
4367c2aad20Sopenharmony_ci *		specified *attach_type* hook.
4377c2aad20Sopenharmony_ci *
4387c2aad20Sopenharmony_ci *		The *target_fd* must be a valid file descriptor for a kernel
4397c2aad20Sopenharmony_ci *		object which depends on the attach type of *attach_bpf_fd*:
4407c2aad20Sopenharmony_ci *
4417c2aad20Sopenharmony_ci *		**BPF_PROG_TYPE_CGROUP_DEVICE**,
4427c2aad20Sopenharmony_ci *		**BPF_PROG_TYPE_CGROUP_SKB**,
4437c2aad20Sopenharmony_ci *		**BPF_PROG_TYPE_CGROUP_SOCK**,
4447c2aad20Sopenharmony_ci *		**BPF_PROG_TYPE_CGROUP_SOCK_ADDR**,
4457c2aad20Sopenharmony_ci *		**BPF_PROG_TYPE_CGROUP_SOCKOPT**,
4467c2aad20Sopenharmony_ci *		**BPF_PROG_TYPE_CGROUP_SYSCTL**,
4477c2aad20Sopenharmony_ci *		**BPF_PROG_TYPE_SOCK_OPS**
4487c2aad20Sopenharmony_ci *
4497c2aad20Sopenharmony_ci *			Control Group v2 hierarchy with the eBPF controller
4507c2aad20Sopenharmony_ci *			enabled. Requires the kernel to be compiled with
4517c2aad20Sopenharmony_ci *			**CONFIG_CGROUP_BPF**.
4527c2aad20Sopenharmony_ci *
4537c2aad20Sopenharmony_ci *		**BPF_PROG_TYPE_FLOW_DISSECTOR**
4547c2aad20Sopenharmony_ci *
4557c2aad20Sopenharmony_ci *			Network namespace (eg /proc/self/ns/net).
4567c2aad20Sopenharmony_ci *
4577c2aad20Sopenharmony_ci *		**BPF_PROG_TYPE_LIRC_MODE2**
4587c2aad20Sopenharmony_ci *
4597c2aad20Sopenharmony_ci *			LIRC device path (eg /dev/lircN). Requires the kernel
4607c2aad20Sopenharmony_ci *			to be compiled with **CONFIG_BPF_LIRC_MODE2**.
4617c2aad20Sopenharmony_ci *
4627c2aad20Sopenharmony_ci *		**BPF_PROG_QUERY** always fetches the number of programs
4637c2aad20Sopenharmony_ci *		attached and the *attach_flags* which were used to attach those
4647c2aad20Sopenharmony_ci *		programs. Additionally, if *prog_ids* is nonzero and the number
4657c2aad20Sopenharmony_ci *		of attached programs is less than *prog_cnt*, populates
4667c2aad20Sopenharmony_ci *		*prog_ids* with the eBPF program ids of the programs attached
4677c2aad20Sopenharmony_ci *		at *target_fd*.
4687c2aad20Sopenharmony_ci *
4697c2aad20Sopenharmony_ci *		The following flags may alter the result:
4707c2aad20Sopenharmony_ci *
4717c2aad20Sopenharmony_ci *		**BPF_F_QUERY_EFFECTIVE**
4727c2aad20Sopenharmony_ci *			Only return information regarding programs which are
4737c2aad20Sopenharmony_ci *			currently effective at the specified *target_fd*.
4747c2aad20Sopenharmony_ci *
4757c2aad20Sopenharmony_ci *	Return
4767c2aad20Sopenharmony_ci *		Returns zero on success. On error, -1 is returned and *errno*
4777c2aad20Sopenharmony_ci *		is set appropriately.
4787c2aad20Sopenharmony_ci *
4797c2aad20Sopenharmony_ci * BPF_RAW_TRACEPOINT_OPEN
4807c2aad20Sopenharmony_ci *	Description
4817c2aad20Sopenharmony_ci *		Attach an eBPF program to a tracepoint *name* to access kernel
4827c2aad20Sopenharmony_ci *		internal arguments of the tracepoint in their raw form.
4837c2aad20Sopenharmony_ci *
4847c2aad20Sopenharmony_ci *		The *prog_fd* must be a valid file descriptor associated with
4857c2aad20Sopenharmony_ci *		a loaded eBPF program of type **BPF_PROG_TYPE_RAW_TRACEPOINT**.
4867c2aad20Sopenharmony_ci *
4877c2aad20Sopenharmony_ci *		No ABI guarantees are made about the content of tracepoint
4887c2aad20Sopenharmony_ci *		arguments exposed to the corresponding eBPF program.
4897c2aad20Sopenharmony_ci *
4907c2aad20Sopenharmony_ci *		Applying **close**\ (2) to the file descriptor returned by
4917c2aad20Sopenharmony_ci *		**BPF_RAW_TRACEPOINT_OPEN** will delete the map (but see NOTES).
4927c2aad20Sopenharmony_ci *
4937c2aad20Sopenharmony_ci *	Return
4947c2aad20Sopenharmony_ci *		A new file descriptor (a nonnegative integer), or -1 if an
4957c2aad20Sopenharmony_ci *		error occurred (in which case, *errno* is set appropriately).
4967c2aad20Sopenharmony_ci *
4977c2aad20Sopenharmony_ci * BPF_BTF_LOAD
4987c2aad20Sopenharmony_ci *	Description
4997c2aad20Sopenharmony_ci *		Verify and load BPF Type Format (BTF) metadata into the kernel,
5007c2aad20Sopenharmony_ci *		returning a new file descriptor associated with the metadata.
5017c2aad20Sopenharmony_ci *		BTF is described in more detail at
5027c2aad20Sopenharmony_ci *		https://www.kernel.org/doc/html/latest/bpf/btf.html.
5037c2aad20Sopenharmony_ci *
5047c2aad20Sopenharmony_ci *		The *btf* parameter must point to valid memory providing
5057c2aad20Sopenharmony_ci *		*btf_size* bytes of BTF binary metadata.
5067c2aad20Sopenharmony_ci *
5077c2aad20Sopenharmony_ci *		The returned file descriptor can be passed to other **bpf**\ ()
5087c2aad20Sopenharmony_ci *		subcommands such as **BPF_PROG_LOAD** or **BPF_MAP_CREATE** to
5097c2aad20Sopenharmony_ci *		associate the BTF with those objects.
5107c2aad20Sopenharmony_ci *
5117c2aad20Sopenharmony_ci *		Similar to **BPF_PROG_LOAD**, **BPF_BTF_LOAD** has optional
5127c2aad20Sopenharmony_ci *		parameters to specify a *btf_log_buf*, *btf_log_size* and
5137c2aad20Sopenharmony_ci *		*btf_log_level* which allow the kernel to return freeform log
5147c2aad20Sopenharmony_ci *		output regarding the BTF verification process.
5157c2aad20Sopenharmony_ci *
5167c2aad20Sopenharmony_ci *	Return
5177c2aad20Sopenharmony_ci *		A new file descriptor (a nonnegative integer), or -1 if an
5187c2aad20Sopenharmony_ci *		error occurred (in which case, *errno* is set appropriately).
5197c2aad20Sopenharmony_ci *
5207c2aad20Sopenharmony_ci * BPF_BTF_GET_FD_BY_ID
5217c2aad20Sopenharmony_ci *	Description
5227c2aad20Sopenharmony_ci *		Open a file descriptor for the BPF Type Format (BTF)
5237c2aad20Sopenharmony_ci *		corresponding to *btf_id*.
5247c2aad20Sopenharmony_ci *
5257c2aad20Sopenharmony_ci *	Return
5267c2aad20Sopenharmony_ci *		A new file descriptor (a nonnegative integer), or -1 if an
5277c2aad20Sopenharmony_ci *		error occurred (in which case, *errno* is set appropriately).
5287c2aad20Sopenharmony_ci *
5297c2aad20Sopenharmony_ci * BPF_TASK_FD_QUERY
5307c2aad20Sopenharmony_ci *	Description
5317c2aad20Sopenharmony_ci *		Obtain information about eBPF programs associated with the
5327c2aad20Sopenharmony_ci *		target process identified by *pid* and *fd*.
5337c2aad20Sopenharmony_ci *
5347c2aad20Sopenharmony_ci *		If the *pid* and *fd* are associated with a tracepoint, kprobe
5357c2aad20Sopenharmony_ci *		or uprobe perf event, then the *prog_id* and *fd_type* will
5367c2aad20Sopenharmony_ci *		be populated with the eBPF program id and file descriptor type
5377c2aad20Sopenharmony_ci *		of type **bpf_task_fd_type**. If associated with a kprobe or
5387c2aad20Sopenharmony_ci *		uprobe, the  *probe_offset* and *probe_addr* will also be
5397c2aad20Sopenharmony_ci *		populated. Optionally, if *buf* is provided, then up to
5407c2aad20Sopenharmony_ci *		*buf_len* bytes of *buf* will be populated with the name of
5417c2aad20Sopenharmony_ci *		the tracepoint, kprobe or uprobe.
5427c2aad20Sopenharmony_ci *
5437c2aad20Sopenharmony_ci *		The resulting *prog_id* may be introspected in deeper detail
5447c2aad20Sopenharmony_ci *		using **BPF_PROG_GET_FD_BY_ID** and **BPF_OBJ_GET_INFO_BY_FD**.
5457c2aad20Sopenharmony_ci *
5467c2aad20Sopenharmony_ci *	Return
5477c2aad20Sopenharmony_ci *		Returns zero on success. On error, -1 is returned and *errno*
5487c2aad20Sopenharmony_ci *		is set appropriately.
5497c2aad20Sopenharmony_ci *
5507c2aad20Sopenharmony_ci * BPF_MAP_LOOKUP_AND_DELETE_ELEM
5517c2aad20Sopenharmony_ci *	Description
5527c2aad20Sopenharmony_ci *		Look up an element with the given *key* in the map referred to
5537c2aad20Sopenharmony_ci *		by the file descriptor *fd*, and if found, delete the element.
5547c2aad20Sopenharmony_ci *
5557c2aad20Sopenharmony_ci *		For **BPF_MAP_TYPE_QUEUE** and **BPF_MAP_TYPE_STACK** map
5567c2aad20Sopenharmony_ci *		types, the *flags* argument needs to be set to 0, but for other
5577c2aad20Sopenharmony_ci *		map types, it may be specified as:
5587c2aad20Sopenharmony_ci *
5597c2aad20Sopenharmony_ci *		**BPF_F_LOCK**
5607c2aad20Sopenharmony_ci *			Look up and delete the value of a spin-locked map
5617c2aad20Sopenharmony_ci *			without returning the lock. This must be specified if
5627c2aad20Sopenharmony_ci *			the elements contain a spinlock.
5637c2aad20Sopenharmony_ci *
5647c2aad20Sopenharmony_ci *		The **BPF_MAP_TYPE_QUEUE** and **BPF_MAP_TYPE_STACK** map types
5657c2aad20Sopenharmony_ci *		implement this command as a "pop" operation, deleting the top
5667c2aad20Sopenharmony_ci *		element rather than one corresponding to *key*.
5677c2aad20Sopenharmony_ci *		The *key* and *key_len* parameters should be zeroed when
5687c2aad20Sopenharmony_ci *		issuing this operation for these map types.
5697c2aad20Sopenharmony_ci *
5707c2aad20Sopenharmony_ci *		This command is only valid for the following map types:
5717c2aad20Sopenharmony_ci *		* **BPF_MAP_TYPE_QUEUE**
5727c2aad20Sopenharmony_ci *		* **BPF_MAP_TYPE_STACK**
5737c2aad20Sopenharmony_ci *		* **BPF_MAP_TYPE_HASH**
5747c2aad20Sopenharmony_ci *		* **BPF_MAP_TYPE_PERCPU_HASH**
5757c2aad20Sopenharmony_ci *		* **BPF_MAP_TYPE_LRU_HASH**
5767c2aad20Sopenharmony_ci *		* **BPF_MAP_TYPE_LRU_PERCPU_HASH**
5777c2aad20Sopenharmony_ci *
5787c2aad20Sopenharmony_ci *	Return
5797c2aad20Sopenharmony_ci *		Returns zero on success. On error, -1 is returned and *errno*
5807c2aad20Sopenharmony_ci *		is set appropriately.
5817c2aad20Sopenharmony_ci *
5827c2aad20Sopenharmony_ci * BPF_MAP_FREEZE
5837c2aad20Sopenharmony_ci *	Description
5847c2aad20Sopenharmony_ci *		Freeze the permissions of the specified map.
5857c2aad20Sopenharmony_ci *
5867c2aad20Sopenharmony_ci *		Write permissions may be frozen by passing zero *flags*.
5877c2aad20Sopenharmony_ci *		Upon success, no future syscall invocations may alter the
5887c2aad20Sopenharmony_ci *		map state of *map_fd*. Write operations from eBPF programs
5897c2aad20Sopenharmony_ci *		are still possible for a frozen map.
5907c2aad20Sopenharmony_ci *
5917c2aad20Sopenharmony_ci *		Not supported for maps of type **BPF_MAP_TYPE_STRUCT_OPS**.
5927c2aad20Sopenharmony_ci *
5937c2aad20Sopenharmony_ci *	Return
5947c2aad20Sopenharmony_ci *		Returns zero on success. On error, -1 is returned and *errno*
5957c2aad20Sopenharmony_ci *		is set appropriately.
5967c2aad20Sopenharmony_ci *
5977c2aad20Sopenharmony_ci * BPF_BTF_GET_NEXT_ID
5987c2aad20Sopenharmony_ci *	Description
5997c2aad20Sopenharmony_ci *		Fetch the next BPF Type Format (BTF) object currently loaded
6007c2aad20Sopenharmony_ci *		into the kernel.
6017c2aad20Sopenharmony_ci *
6027c2aad20Sopenharmony_ci *		Looks for the BTF object with an id greater than *start_id*
6037c2aad20Sopenharmony_ci *		and updates *next_id* on success. If no other BTF objects
6047c2aad20Sopenharmony_ci *		remain with ids higher than *start_id*, returns -1 and sets
6057c2aad20Sopenharmony_ci *		*errno* to **ENOENT**.
6067c2aad20Sopenharmony_ci *
6077c2aad20Sopenharmony_ci *	Return
6087c2aad20Sopenharmony_ci *		Returns zero on success. On error, or when no id remains, -1
6097c2aad20Sopenharmony_ci *		is returned and *errno* is set appropriately.
6107c2aad20Sopenharmony_ci *
6117c2aad20Sopenharmony_ci * BPF_MAP_LOOKUP_BATCH
6127c2aad20Sopenharmony_ci *	Description
6137c2aad20Sopenharmony_ci *		Iterate and fetch multiple elements in a map.
6147c2aad20Sopenharmony_ci *
6157c2aad20Sopenharmony_ci *		Two opaque values are used to manage batch operations,
6167c2aad20Sopenharmony_ci *		*in_batch* and *out_batch*. Initially, *in_batch* must be set
6177c2aad20Sopenharmony_ci *		to NULL to begin the batched operation. After each subsequent
6187c2aad20Sopenharmony_ci *		**BPF_MAP_LOOKUP_BATCH**, the caller should pass the resultant
6197c2aad20Sopenharmony_ci *		*out_batch* as the *in_batch* for the next operation to
6207c2aad20Sopenharmony_ci *		continue iteration from the current point.
6217c2aad20Sopenharmony_ci *
6227c2aad20Sopenharmony_ci *		The *keys* and *values* are output parameters which must point
6237c2aad20Sopenharmony_ci *		to memory large enough to hold *count* items based on the key
6247c2aad20Sopenharmony_ci *		and value size of the map *map_fd*. The *keys* buffer must be
6257c2aad20Sopenharmony_ci *		of *key_size* * *count*. The *values* buffer must be of
6267c2aad20Sopenharmony_ci *		*value_size* * *count*.
6277c2aad20Sopenharmony_ci *
6287c2aad20Sopenharmony_ci *		The *elem_flags* argument may be specified as one of the
6297c2aad20Sopenharmony_ci *		following:
6307c2aad20Sopenharmony_ci *
6317c2aad20Sopenharmony_ci *		**BPF_F_LOCK**
6327c2aad20Sopenharmony_ci *			Look up the value of a spin-locked map without
6337c2aad20Sopenharmony_ci *			returning the lock. This must be specified if the
6347c2aad20Sopenharmony_ci *			elements contain a spinlock.
6357c2aad20Sopenharmony_ci *
6367c2aad20Sopenharmony_ci *		On success, *count* elements from the map are copied into the
6377c2aad20Sopenharmony_ci *		user buffer, with the keys copied into *keys* and the values
6387c2aad20Sopenharmony_ci *		copied into the corresponding indices in *values*.
6397c2aad20Sopenharmony_ci *
6407c2aad20Sopenharmony_ci *		If an error is returned and *errno* is not **EFAULT**, *count*
6417c2aad20Sopenharmony_ci *		is set to the number of successfully processed elements.
6427c2aad20Sopenharmony_ci *
6437c2aad20Sopenharmony_ci *	Return
6447c2aad20Sopenharmony_ci *		Returns zero on success. On error, -1 is returned and *errno*
6457c2aad20Sopenharmony_ci *		is set appropriately.
6467c2aad20Sopenharmony_ci *
6477c2aad20Sopenharmony_ci *		May set *errno* to **ENOSPC** to indicate that *keys* or
6487c2aad20Sopenharmony_ci *		*values* is too small to dump an entire bucket during
6497c2aad20Sopenharmony_ci *		iteration of a hash-based map type.
6507c2aad20Sopenharmony_ci *
6517c2aad20Sopenharmony_ci * BPF_MAP_LOOKUP_AND_DELETE_BATCH
6527c2aad20Sopenharmony_ci *	Description
6537c2aad20Sopenharmony_ci *		Iterate and delete all elements in a map.
6547c2aad20Sopenharmony_ci *
6557c2aad20Sopenharmony_ci *		This operation has the same behavior as
6567c2aad20Sopenharmony_ci *		**BPF_MAP_LOOKUP_BATCH** with two exceptions:
6577c2aad20Sopenharmony_ci *
6587c2aad20Sopenharmony_ci *		* Every element that is successfully returned is also deleted
6597c2aad20Sopenharmony_ci *		  from the map. This is at least *count* elements. Note that
6607c2aad20Sopenharmony_ci *		  *count* is both an input and an output parameter.
6617c2aad20Sopenharmony_ci *		* Upon returning with *errno* set to **EFAULT**, up to
6627c2aad20Sopenharmony_ci *		  *count* elements may be deleted without returning the keys
6637c2aad20Sopenharmony_ci *		  and values of the deleted elements.
6647c2aad20Sopenharmony_ci *
6657c2aad20Sopenharmony_ci *	Return
6667c2aad20Sopenharmony_ci *		Returns zero on success. On error, -1 is returned and *errno*
6677c2aad20Sopenharmony_ci *		is set appropriately.
6687c2aad20Sopenharmony_ci *
6697c2aad20Sopenharmony_ci * BPF_MAP_UPDATE_BATCH
6707c2aad20Sopenharmony_ci *	Description
6717c2aad20Sopenharmony_ci *		Update multiple elements in a map by *key*.
6727c2aad20Sopenharmony_ci *
6737c2aad20Sopenharmony_ci *		The *keys* and *values* are input parameters which must point
6747c2aad20Sopenharmony_ci *		to memory large enough to hold *count* items based on the key
6757c2aad20Sopenharmony_ci *		and value size of the map *map_fd*. The *keys* buffer must be
6767c2aad20Sopenharmony_ci *		of *key_size* * *count*. The *values* buffer must be of
6777c2aad20Sopenharmony_ci *		*value_size* * *count*.
6787c2aad20Sopenharmony_ci *
6797c2aad20Sopenharmony_ci *		Each element specified in *keys* is sequentially updated to the
6807c2aad20Sopenharmony_ci *		value in the corresponding index in *values*. The *in_batch*
6817c2aad20Sopenharmony_ci *		and *out_batch* parameters are ignored and should be zeroed.
6827c2aad20Sopenharmony_ci *
6837c2aad20Sopenharmony_ci *		The *elem_flags* argument should be specified as one of the
6847c2aad20Sopenharmony_ci *		following:
6857c2aad20Sopenharmony_ci *
6867c2aad20Sopenharmony_ci *		**BPF_ANY**
6877c2aad20Sopenharmony_ci *			Create new elements or update a existing elements.
6887c2aad20Sopenharmony_ci *		**BPF_NOEXIST**
6897c2aad20Sopenharmony_ci *			Create new elements only if they do not exist.
6907c2aad20Sopenharmony_ci *		**BPF_EXIST**
6917c2aad20Sopenharmony_ci *			Update existing elements.
6927c2aad20Sopenharmony_ci *		**BPF_F_LOCK**
6937c2aad20Sopenharmony_ci *			Update spin_lock-ed map elements. This must be
6947c2aad20Sopenharmony_ci *			specified if the map value contains a spinlock.
6957c2aad20Sopenharmony_ci *
6967c2aad20Sopenharmony_ci *		On success, *count* elements from the map are updated.
6977c2aad20Sopenharmony_ci *
6987c2aad20Sopenharmony_ci *		If an error is returned and *errno* is not **EFAULT**, *count*
6997c2aad20Sopenharmony_ci *		is set to the number of successfully processed elements.
7007c2aad20Sopenharmony_ci *
7017c2aad20Sopenharmony_ci *	Return
7027c2aad20Sopenharmony_ci *		Returns zero on success. On error, -1 is returned and *errno*
7037c2aad20Sopenharmony_ci *		is set appropriately.
7047c2aad20Sopenharmony_ci *
7057c2aad20Sopenharmony_ci *		May set *errno* to **EINVAL**, **EPERM**, **ENOMEM**, or
7067c2aad20Sopenharmony_ci *		**E2BIG**. **E2BIG** indicates that the number of elements in
7077c2aad20Sopenharmony_ci *		the map reached the *max_entries* limit specified at map
7087c2aad20Sopenharmony_ci *		creation time.
7097c2aad20Sopenharmony_ci *
7107c2aad20Sopenharmony_ci *		May set *errno* to one of the following error codes under
7117c2aad20Sopenharmony_ci *		specific circumstances:
7127c2aad20Sopenharmony_ci *
7137c2aad20Sopenharmony_ci *		**EEXIST**
7147c2aad20Sopenharmony_ci *			If *flags* specifies **BPF_NOEXIST** and the element
7157c2aad20Sopenharmony_ci *			with *key* already exists in the map.
7167c2aad20Sopenharmony_ci *		**ENOENT**
7177c2aad20Sopenharmony_ci *			If *flags* specifies **BPF_EXIST** and the element with
7187c2aad20Sopenharmony_ci *			*key* does not exist in the map.
7197c2aad20Sopenharmony_ci *
7207c2aad20Sopenharmony_ci * BPF_MAP_DELETE_BATCH
7217c2aad20Sopenharmony_ci *	Description
7227c2aad20Sopenharmony_ci *		Delete multiple elements in a map by *key*.
7237c2aad20Sopenharmony_ci *
7247c2aad20Sopenharmony_ci *		The *keys* parameter is an input parameter which must point
7257c2aad20Sopenharmony_ci *		to memory large enough to hold *count* items based on the key
7267c2aad20Sopenharmony_ci *		size of the map *map_fd*, that is, *key_size* * *count*.
7277c2aad20Sopenharmony_ci *
7287c2aad20Sopenharmony_ci *		Each element specified in *keys* is sequentially deleted. The
7297c2aad20Sopenharmony_ci *		*in_batch*, *out_batch*, and *values* parameters are ignored
7307c2aad20Sopenharmony_ci *		and should be zeroed.
7317c2aad20Sopenharmony_ci *
7327c2aad20Sopenharmony_ci *		The *elem_flags* argument may be specified as one of the
7337c2aad20Sopenharmony_ci *		following:
7347c2aad20Sopenharmony_ci *
7357c2aad20Sopenharmony_ci *		**BPF_F_LOCK**
7367c2aad20Sopenharmony_ci *			Look up the value of a spin-locked map without
7377c2aad20Sopenharmony_ci *			returning the lock. This must be specified if the
7387c2aad20Sopenharmony_ci *			elements contain a spinlock.
7397c2aad20Sopenharmony_ci *
7407c2aad20Sopenharmony_ci *		On success, *count* elements from the map are updated.
7417c2aad20Sopenharmony_ci *
7427c2aad20Sopenharmony_ci *		If an error is returned and *errno* is not **EFAULT**, *count*
7437c2aad20Sopenharmony_ci *		is set to the number of successfully processed elements. If
7447c2aad20Sopenharmony_ci *		*errno* is **EFAULT**, up to *count* elements may be been
7457c2aad20Sopenharmony_ci *		deleted.
7467c2aad20Sopenharmony_ci *
7477c2aad20Sopenharmony_ci *	Return
7487c2aad20Sopenharmony_ci *		Returns zero on success. On error, -1 is returned and *errno*
7497c2aad20Sopenharmony_ci *		is set appropriately.
7507c2aad20Sopenharmony_ci *
7517c2aad20Sopenharmony_ci * BPF_LINK_CREATE
7527c2aad20Sopenharmony_ci *	Description
7537c2aad20Sopenharmony_ci *		Attach an eBPF program to a *target_fd* at the specified
7547c2aad20Sopenharmony_ci *		*attach_type* hook and return a file descriptor handle for
7557c2aad20Sopenharmony_ci *		managing the link.
7567c2aad20Sopenharmony_ci *
7577c2aad20Sopenharmony_ci *	Return
7587c2aad20Sopenharmony_ci *		A new file descriptor (a nonnegative integer), or -1 if an
7597c2aad20Sopenharmony_ci *		error occurred (in which case, *errno* is set appropriately).
7607c2aad20Sopenharmony_ci *
7617c2aad20Sopenharmony_ci * BPF_LINK_UPDATE
7627c2aad20Sopenharmony_ci *	Description
7637c2aad20Sopenharmony_ci *		Update the eBPF program in the specified *link_fd* to
7647c2aad20Sopenharmony_ci *		*new_prog_fd*.
7657c2aad20Sopenharmony_ci *
7667c2aad20Sopenharmony_ci *	Return
7677c2aad20Sopenharmony_ci *		Returns zero on success. On error, -1 is returned and *errno*
7687c2aad20Sopenharmony_ci *		is set appropriately.
7697c2aad20Sopenharmony_ci *
7707c2aad20Sopenharmony_ci * BPF_LINK_GET_FD_BY_ID
7717c2aad20Sopenharmony_ci *	Description
7727c2aad20Sopenharmony_ci *		Open a file descriptor for the eBPF Link corresponding to
7737c2aad20Sopenharmony_ci *		*link_id*.
7747c2aad20Sopenharmony_ci *
7757c2aad20Sopenharmony_ci *	Return
7767c2aad20Sopenharmony_ci *		A new file descriptor (a nonnegative integer), or -1 if an
7777c2aad20Sopenharmony_ci *		error occurred (in which case, *errno* is set appropriately).
7787c2aad20Sopenharmony_ci *
7797c2aad20Sopenharmony_ci * BPF_LINK_GET_NEXT_ID
7807c2aad20Sopenharmony_ci *	Description
7817c2aad20Sopenharmony_ci *		Fetch the next eBPF link currently loaded into the kernel.
7827c2aad20Sopenharmony_ci *
7837c2aad20Sopenharmony_ci *		Looks for the eBPF link with an id greater than *start_id*
7847c2aad20Sopenharmony_ci *		and updates *next_id* on success. If no other eBPF links
7857c2aad20Sopenharmony_ci *		remain with ids higher than *start_id*, returns -1 and sets
7867c2aad20Sopenharmony_ci *		*errno* to **ENOENT**.
7877c2aad20Sopenharmony_ci *
7887c2aad20Sopenharmony_ci *	Return
7897c2aad20Sopenharmony_ci *		Returns zero on success. On error, or when no id remains, -1
7907c2aad20Sopenharmony_ci *		is returned and *errno* is set appropriately.
7917c2aad20Sopenharmony_ci *
7927c2aad20Sopenharmony_ci * BPF_ENABLE_STATS
7937c2aad20Sopenharmony_ci *	Description
7947c2aad20Sopenharmony_ci *		Enable eBPF runtime statistics gathering.
7957c2aad20Sopenharmony_ci *
7967c2aad20Sopenharmony_ci *		Runtime statistics gathering for the eBPF runtime is disabled
7977c2aad20Sopenharmony_ci *		by default to minimize the corresponding performance overhead.
7987c2aad20Sopenharmony_ci *		This command enables statistics globally.
7997c2aad20Sopenharmony_ci *
8007c2aad20Sopenharmony_ci *		Multiple programs may independently enable statistics.
8017c2aad20Sopenharmony_ci *		After gathering the desired statistics, eBPF runtime statistics
8027c2aad20Sopenharmony_ci *		may be disabled again by calling **close**\ (2) for the file
8037c2aad20Sopenharmony_ci *		descriptor returned by this function. Statistics will only be
8047c2aad20Sopenharmony_ci *		disabled system-wide when all outstanding file descriptors
8057c2aad20Sopenharmony_ci *		returned by prior calls for this subcommand are closed.
8067c2aad20Sopenharmony_ci *
8077c2aad20Sopenharmony_ci *	Return
8087c2aad20Sopenharmony_ci *		A new file descriptor (a nonnegative integer), or -1 if an
8097c2aad20Sopenharmony_ci *		error occurred (in which case, *errno* is set appropriately).
8107c2aad20Sopenharmony_ci *
8117c2aad20Sopenharmony_ci * BPF_ITER_CREATE
8127c2aad20Sopenharmony_ci *	Description
8137c2aad20Sopenharmony_ci *		Create an iterator on top of the specified *link_fd* (as
8147c2aad20Sopenharmony_ci *		previously created using **BPF_LINK_CREATE**) and return a
8157c2aad20Sopenharmony_ci *		file descriptor that can be used to trigger the iteration.
8167c2aad20Sopenharmony_ci *
8177c2aad20Sopenharmony_ci *		If the resulting file descriptor is pinned to the filesystem
8187c2aad20Sopenharmony_ci *		using  **BPF_OBJ_PIN**, then subsequent **read**\ (2) syscalls
8197c2aad20Sopenharmony_ci *		for that path will trigger the iterator to read kernel state
8207c2aad20Sopenharmony_ci *		using the eBPF program attached to *link_fd*.
8217c2aad20Sopenharmony_ci *
8227c2aad20Sopenharmony_ci *	Return
8237c2aad20Sopenharmony_ci *		A new file descriptor (a nonnegative integer), or -1 if an
8247c2aad20Sopenharmony_ci *		error occurred (in which case, *errno* is set appropriately).
8257c2aad20Sopenharmony_ci *
8267c2aad20Sopenharmony_ci * BPF_LINK_DETACH
8277c2aad20Sopenharmony_ci *	Description
8287c2aad20Sopenharmony_ci *		Forcefully detach the specified *link_fd* from its
8297c2aad20Sopenharmony_ci *		corresponding attachment point.
8307c2aad20Sopenharmony_ci *
8317c2aad20Sopenharmony_ci *	Return
8327c2aad20Sopenharmony_ci *		Returns zero on success. On error, -1 is returned and *errno*
8337c2aad20Sopenharmony_ci *		is set appropriately.
8347c2aad20Sopenharmony_ci *
8357c2aad20Sopenharmony_ci * BPF_PROG_BIND_MAP
8367c2aad20Sopenharmony_ci *	Description
8377c2aad20Sopenharmony_ci *		Bind a map to the lifetime of an eBPF program.
8387c2aad20Sopenharmony_ci *
8397c2aad20Sopenharmony_ci *		The map identified by *map_fd* is bound to the program
8407c2aad20Sopenharmony_ci *		identified by *prog_fd* and only released when *prog_fd* is
8417c2aad20Sopenharmony_ci *		released. This may be used in cases where metadata should be
8427c2aad20Sopenharmony_ci *		associated with a program which otherwise does not contain any
8437c2aad20Sopenharmony_ci *		references to the map (for example, embedded in the eBPF
8447c2aad20Sopenharmony_ci *		program instructions).
8457c2aad20Sopenharmony_ci *
8467c2aad20Sopenharmony_ci *	Return
8477c2aad20Sopenharmony_ci *		Returns zero on success. On error, -1 is returned and *errno*
8487c2aad20Sopenharmony_ci *		is set appropriately.
8497c2aad20Sopenharmony_ci *
8507c2aad20Sopenharmony_ci * NOTES
8517c2aad20Sopenharmony_ci *	eBPF objects (maps and programs) can be shared between processes.
8527c2aad20Sopenharmony_ci *
8537c2aad20Sopenharmony_ci *	* After **fork**\ (2), the child inherits file descriptors
8547c2aad20Sopenharmony_ci *	  referring to the same eBPF objects.
8557c2aad20Sopenharmony_ci *	* File descriptors referring to eBPF objects can be transferred over
8567c2aad20Sopenharmony_ci *	  **unix**\ (7) domain sockets.
8577c2aad20Sopenharmony_ci *	* File descriptors referring to eBPF objects can be duplicated in the
8587c2aad20Sopenharmony_ci *	  usual way, using **dup**\ (2) and similar calls.
8597c2aad20Sopenharmony_ci *	* File descriptors referring to eBPF objects can be pinned to the
8607c2aad20Sopenharmony_ci *	  filesystem using the **BPF_OBJ_PIN** command of **bpf**\ (2).
8617c2aad20Sopenharmony_ci *
8627c2aad20Sopenharmony_ci *	An eBPF object is deallocated only after all file descriptors referring
8637c2aad20Sopenharmony_ci *	to the object have been closed and no references remain pinned to the
8647c2aad20Sopenharmony_ci *	filesystem or attached (for example, bound to a program or device).
8657c2aad20Sopenharmony_ci */
8667c2aad20Sopenharmony_cienum bpf_cmd {
8677c2aad20Sopenharmony_ci	BPF_MAP_CREATE,
8687c2aad20Sopenharmony_ci	BPF_MAP_LOOKUP_ELEM,
8697c2aad20Sopenharmony_ci	BPF_MAP_UPDATE_ELEM,
8707c2aad20Sopenharmony_ci	BPF_MAP_DELETE_ELEM,
8717c2aad20Sopenharmony_ci	BPF_MAP_GET_NEXT_KEY,
8727c2aad20Sopenharmony_ci	BPF_PROG_LOAD,
8737c2aad20Sopenharmony_ci	BPF_OBJ_PIN,
8747c2aad20Sopenharmony_ci	BPF_OBJ_GET,
8757c2aad20Sopenharmony_ci	BPF_PROG_ATTACH,
8767c2aad20Sopenharmony_ci	BPF_PROG_DETACH,
8777c2aad20Sopenharmony_ci	BPF_PROG_TEST_RUN,
8787c2aad20Sopenharmony_ci	BPF_PROG_RUN = BPF_PROG_TEST_RUN,
8797c2aad20Sopenharmony_ci	BPF_PROG_GET_NEXT_ID,
8807c2aad20Sopenharmony_ci	BPF_MAP_GET_NEXT_ID,
8817c2aad20Sopenharmony_ci	BPF_PROG_GET_FD_BY_ID,
8827c2aad20Sopenharmony_ci	BPF_MAP_GET_FD_BY_ID,
8837c2aad20Sopenharmony_ci	BPF_OBJ_GET_INFO_BY_FD,
8847c2aad20Sopenharmony_ci	BPF_PROG_QUERY,
8857c2aad20Sopenharmony_ci	BPF_RAW_TRACEPOINT_OPEN,
8867c2aad20Sopenharmony_ci	BPF_BTF_LOAD,
8877c2aad20Sopenharmony_ci	BPF_BTF_GET_FD_BY_ID,
8887c2aad20Sopenharmony_ci	BPF_TASK_FD_QUERY,
8897c2aad20Sopenharmony_ci	BPF_MAP_LOOKUP_AND_DELETE_ELEM,
8907c2aad20Sopenharmony_ci	BPF_MAP_FREEZE,
8917c2aad20Sopenharmony_ci	BPF_BTF_GET_NEXT_ID,
8927c2aad20Sopenharmony_ci	BPF_MAP_LOOKUP_BATCH,
8937c2aad20Sopenharmony_ci	BPF_MAP_LOOKUP_AND_DELETE_BATCH,
8947c2aad20Sopenharmony_ci	BPF_MAP_UPDATE_BATCH,
8957c2aad20Sopenharmony_ci	BPF_MAP_DELETE_BATCH,
8967c2aad20Sopenharmony_ci	BPF_LINK_CREATE,
8977c2aad20Sopenharmony_ci	BPF_LINK_UPDATE,
8987c2aad20Sopenharmony_ci	BPF_LINK_GET_FD_BY_ID,
8997c2aad20Sopenharmony_ci	BPF_LINK_GET_NEXT_ID,
9007c2aad20Sopenharmony_ci	BPF_ENABLE_STATS,
9017c2aad20Sopenharmony_ci	BPF_ITER_CREATE,
9027c2aad20Sopenharmony_ci	BPF_LINK_DETACH,
9037c2aad20Sopenharmony_ci	BPF_PROG_BIND_MAP,
9047c2aad20Sopenharmony_ci};
9057c2aad20Sopenharmony_ci
9067c2aad20Sopenharmony_cienum bpf_map_type {
9077c2aad20Sopenharmony_ci	BPF_MAP_TYPE_UNSPEC,
9087c2aad20Sopenharmony_ci	BPF_MAP_TYPE_HASH,
9097c2aad20Sopenharmony_ci	BPF_MAP_TYPE_ARRAY,
9107c2aad20Sopenharmony_ci	BPF_MAP_TYPE_PROG_ARRAY,
9117c2aad20Sopenharmony_ci	BPF_MAP_TYPE_PERF_EVENT_ARRAY,
9127c2aad20Sopenharmony_ci	BPF_MAP_TYPE_PERCPU_HASH,
9137c2aad20Sopenharmony_ci	BPF_MAP_TYPE_PERCPU_ARRAY,
9147c2aad20Sopenharmony_ci	BPF_MAP_TYPE_STACK_TRACE,
9157c2aad20Sopenharmony_ci	BPF_MAP_TYPE_CGROUP_ARRAY,
9167c2aad20Sopenharmony_ci	BPF_MAP_TYPE_LRU_HASH,
9177c2aad20Sopenharmony_ci	BPF_MAP_TYPE_LRU_PERCPU_HASH,
9187c2aad20Sopenharmony_ci	BPF_MAP_TYPE_LPM_TRIE,
9197c2aad20Sopenharmony_ci	BPF_MAP_TYPE_ARRAY_OF_MAPS,
9207c2aad20Sopenharmony_ci	BPF_MAP_TYPE_HASH_OF_MAPS,
9217c2aad20Sopenharmony_ci	BPF_MAP_TYPE_DEVMAP,
9227c2aad20Sopenharmony_ci	BPF_MAP_TYPE_SOCKMAP,
9237c2aad20Sopenharmony_ci	BPF_MAP_TYPE_CPUMAP,
9247c2aad20Sopenharmony_ci	BPF_MAP_TYPE_XSKMAP,
9257c2aad20Sopenharmony_ci	BPF_MAP_TYPE_SOCKHASH,
9267c2aad20Sopenharmony_ci	BPF_MAP_TYPE_CGROUP_STORAGE_DEPRECATED,
9277c2aad20Sopenharmony_ci	/* BPF_MAP_TYPE_CGROUP_STORAGE is available to bpf programs attaching
9287c2aad20Sopenharmony_ci	 * to a cgroup. The newer BPF_MAP_TYPE_CGRP_STORAGE is available to
9297c2aad20Sopenharmony_ci	 * both cgroup-attached and other progs and supports all functionality
9307c2aad20Sopenharmony_ci	 * provided by BPF_MAP_TYPE_CGROUP_STORAGE. So mark
9317c2aad20Sopenharmony_ci	 * BPF_MAP_TYPE_CGROUP_STORAGE deprecated.
9327c2aad20Sopenharmony_ci	 */
9337c2aad20Sopenharmony_ci	BPF_MAP_TYPE_CGROUP_STORAGE = BPF_MAP_TYPE_CGROUP_STORAGE_DEPRECATED,
9347c2aad20Sopenharmony_ci	BPF_MAP_TYPE_REUSEPORT_SOCKARRAY,
9357c2aad20Sopenharmony_ci	BPF_MAP_TYPE_PERCPU_CGROUP_STORAGE_DEPRECATED,
9367c2aad20Sopenharmony_ci	/* BPF_MAP_TYPE_PERCPU_CGROUP_STORAGE is available to bpf programs
9377c2aad20Sopenharmony_ci	 * attaching to a cgroup. The new mechanism (BPF_MAP_TYPE_CGRP_STORAGE +
9387c2aad20Sopenharmony_ci	 * local percpu kptr) supports all BPF_MAP_TYPE_PERCPU_CGROUP_STORAGE
9397c2aad20Sopenharmony_ci	 * functionality and more. So mark * BPF_MAP_TYPE_PERCPU_CGROUP_STORAGE
9407c2aad20Sopenharmony_ci	 * deprecated.
9417c2aad20Sopenharmony_ci	 */
9427c2aad20Sopenharmony_ci	BPF_MAP_TYPE_PERCPU_CGROUP_STORAGE = BPF_MAP_TYPE_PERCPU_CGROUP_STORAGE_DEPRECATED,
9437c2aad20Sopenharmony_ci	BPF_MAP_TYPE_QUEUE,
9447c2aad20Sopenharmony_ci	BPF_MAP_TYPE_STACK,
9457c2aad20Sopenharmony_ci	BPF_MAP_TYPE_SK_STORAGE,
9467c2aad20Sopenharmony_ci	BPF_MAP_TYPE_DEVMAP_HASH,
9477c2aad20Sopenharmony_ci	BPF_MAP_TYPE_STRUCT_OPS,
9487c2aad20Sopenharmony_ci	BPF_MAP_TYPE_RINGBUF,
9497c2aad20Sopenharmony_ci	BPF_MAP_TYPE_INODE_STORAGE,
9507c2aad20Sopenharmony_ci	BPF_MAP_TYPE_TASK_STORAGE,
9517c2aad20Sopenharmony_ci	BPF_MAP_TYPE_BLOOM_FILTER,
9527c2aad20Sopenharmony_ci	BPF_MAP_TYPE_USER_RINGBUF,
9537c2aad20Sopenharmony_ci	BPF_MAP_TYPE_CGRP_STORAGE,
9547c2aad20Sopenharmony_ci};
9557c2aad20Sopenharmony_ci
9567c2aad20Sopenharmony_ci/* Note that tracing related programs such as
9577c2aad20Sopenharmony_ci * BPF_PROG_TYPE_{KPROBE,TRACEPOINT,PERF_EVENT,RAW_TRACEPOINT}
9587c2aad20Sopenharmony_ci * are not subject to a stable API since kernel internal data
9597c2aad20Sopenharmony_ci * structures can change from release to release and may
9607c2aad20Sopenharmony_ci * therefore break existing tracing BPF programs. Tracing BPF
9617c2aad20Sopenharmony_ci * programs correspond to /a/ specific kernel which is to be
9627c2aad20Sopenharmony_ci * analyzed, and not /a/ specific kernel /and/ all future ones.
9637c2aad20Sopenharmony_ci */
9647c2aad20Sopenharmony_cienum bpf_prog_type {
9657c2aad20Sopenharmony_ci	BPF_PROG_TYPE_UNSPEC,
9667c2aad20Sopenharmony_ci	BPF_PROG_TYPE_SOCKET_FILTER,
9677c2aad20Sopenharmony_ci	BPF_PROG_TYPE_KPROBE,
9687c2aad20Sopenharmony_ci	BPF_PROG_TYPE_SCHED_CLS,
9697c2aad20Sopenharmony_ci	BPF_PROG_TYPE_SCHED_ACT,
9707c2aad20Sopenharmony_ci	BPF_PROG_TYPE_TRACEPOINT,
9717c2aad20Sopenharmony_ci	BPF_PROG_TYPE_XDP,
9727c2aad20Sopenharmony_ci	BPF_PROG_TYPE_PERF_EVENT,
9737c2aad20Sopenharmony_ci	BPF_PROG_TYPE_CGROUP_SKB,
9747c2aad20Sopenharmony_ci	BPF_PROG_TYPE_CGROUP_SOCK,
9757c2aad20Sopenharmony_ci	BPF_PROG_TYPE_LWT_IN,
9767c2aad20Sopenharmony_ci	BPF_PROG_TYPE_LWT_OUT,
9777c2aad20Sopenharmony_ci	BPF_PROG_TYPE_LWT_XMIT,
9787c2aad20Sopenharmony_ci	BPF_PROG_TYPE_SOCK_OPS,
9797c2aad20Sopenharmony_ci	BPF_PROG_TYPE_SK_SKB,
9807c2aad20Sopenharmony_ci	BPF_PROG_TYPE_CGROUP_DEVICE,
9817c2aad20Sopenharmony_ci	BPF_PROG_TYPE_SK_MSG,
9827c2aad20Sopenharmony_ci	BPF_PROG_TYPE_RAW_TRACEPOINT,
9837c2aad20Sopenharmony_ci	BPF_PROG_TYPE_CGROUP_SOCK_ADDR,
9847c2aad20Sopenharmony_ci	BPF_PROG_TYPE_LWT_SEG6LOCAL,
9857c2aad20Sopenharmony_ci	BPF_PROG_TYPE_LIRC_MODE2,
9867c2aad20Sopenharmony_ci	BPF_PROG_TYPE_SK_REUSEPORT,
9877c2aad20Sopenharmony_ci	BPF_PROG_TYPE_FLOW_DISSECTOR,
9887c2aad20Sopenharmony_ci	BPF_PROG_TYPE_CGROUP_SYSCTL,
9897c2aad20Sopenharmony_ci	BPF_PROG_TYPE_RAW_TRACEPOINT_WRITABLE,
9907c2aad20Sopenharmony_ci	BPF_PROG_TYPE_CGROUP_SOCKOPT,
9917c2aad20Sopenharmony_ci	BPF_PROG_TYPE_TRACING,
9927c2aad20Sopenharmony_ci	BPF_PROG_TYPE_STRUCT_OPS,
9937c2aad20Sopenharmony_ci	BPF_PROG_TYPE_EXT,
9947c2aad20Sopenharmony_ci	BPF_PROG_TYPE_LSM,
9957c2aad20Sopenharmony_ci	BPF_PROG_TYPE_SK_LOOKUP,
9967c2aad20Sopenharmony_ci	BPF_PROG_TYPE_SYSCALL, /* a program that can execute syscalls */
9977c2aad20Sopenharmony_ci	BPF_PROG_TYPE_NETFILTER,
9987c2aad20Sopenharmony_ci};
9997c2aad20Sopenharmony_ci
10007c2aad20Sopenharmony_cienum bpf_attach_type {
10017c2aad20Sopenharmony_ci	BPF_CGROUP_INET_INGRESS,
10027c2aad20Sopenharmony_ci	BPF_CGROUP_INET_EGRESS,
10037c2aad20Sopenharmony_ci	BPF_CGROUP_INET_SOCK_CREATE,
10047c2aad20Sopenharmony_ci	BPF_CGROUP_SOCK_OPS,
10057c2aad20Sopenharmony_ci	BPF_SK_SKB_STREAM_PARSER,
10067c2aad20Sopenharmony_ci	BPF_SK_SKB_STREAM_VERDICT,
10077c2aad20Sopenharmony_ci	BPF_CGROUP_DEVICE,
10087c2aad20Sopenharmony_ci	BPF_SK_MSG_VERDICT,
10097c2aad20Sopenharmony_ci	BPF_CGROUP_INET4_BIND,
10107c2aad20Sopenharmony_ci	BPF_CGROUP_INET6_BIND,
10117c2aad20Sopenharmony_ci	BPF_CGROUP_INET4_CONNECT,
10127c2aad20Sopenharmony_ci	BPF_CGROUP_INET6_CONNECT,
10137c2aad20Sopenharmony_ci	BPF_CGROUP_INET4_POST_BIND,
10147c2aad20Sopenharmony_ci	BPF_CGROUP_INET6_POST_BIND,
10157c2aad20Sopenharmony_ci	BPF_CGROUP_UDP4_SENDMSG,
10167c2aad20Sopenharmony_ci	BPF_CGROUP_UDP6_SENDMSG,
10177c2aad20Sopenharmony_ci	BPF_LIRC_MODE2,
10187c2aad20Sopenharmony_ci	BPF_FLOW_DISSECTOR,
10197c2aad20Sopenharmony_ci	BPF_CGROUP_SYSCTL,
10207c2aad20Sopenharmony_ci	BPF_CGROUP_UDP4_RECVMSG,
10217c2aad20Sopenharmony_ci	BPF_CGROUP_UDP6_RECVMSG,
10227c2aad20Sopenharmony_ci	BPF_CGROUP_GETSOCKOPT,
10237c2aad20Sopenharmony_ci	BPF_CGROUP_SETSOCKOPT,
10247c2aad20Sopenharmony_ci	BPF_TRACE_RAW_TP,
10257c2aad20Sopenharmony_ci	BPF_TRACE_FENTRY,
10267c2aad20Sopenharmony_ci	BPF_TRACE_FEXIT,
10277c2aad20Sopenharmony_ci	BPF_MODIFY_RETURN,
10287c2aad20Sopenharmony_ci	BPF_LSM_MAC,
10297c2aad20Sopenharmony_ci	BPF_TRACE_ITER,
10307c2aad20Sopenharmony_ci	BPF_CGROUP_INET4_GETPEERNAME,
10317c2aad20Sopenharmony_ci	BPF_CGROUP_INET6_GETPEERNAME,
10327c2aad20Sopenharmony_ci	BPF_CGROUP_INET4_GETSOCKNAME,
10337c2aad20Sopenharmony_ci	BPF_CGROUP_INET6_GETSOCKNAME,
10347c2aad20Sopenharmony_ci	BPF_XDP_DEVMAP,
10357c2aad20Sopenharmony_ci	BPF_CGROUP_INET_SOCK_RELEASE,
10367c2aad20Sopenharmony_ci	BPF_XDP_CPUMAP,
10377c2aad20Sopenharmony_ci	BPF_SK_LOOKUP,
10387c2aad20Sopenharmony_ci	BPF_XDP,
10397c2aad20Sopenharmony_ci	BPF_SK_SKB_VERDICT,
10407c2aad20Sopenharmony_ci	BPF_SK_REUSEPORT_SELECT,
10417c2aad20Sopenharmony_ci	BPF_SK_REUSEPORT_SELECT_OR_MIGRATE,
10427c2aad20Sopenharmony_ci	BPF_PERF_EVENT,
10437c2aad20Sopenharmony_ci	BPF_TRACE_KPROBE_MULTI,
10447c2aad20Sopenharmony_ci	BPF_LSM_CGROUP,
10457c2aad20Sopenharmony_ci	BPF_STRUCT_OPS,
10467c2aad20Sopenharmony_ci	BPF_NETFILTER,
10477c2aad20Sopenharmony_ci	BPF_TCX_INGRESS,
10487c2aad20Sopenharmony_ci	BPF_TCX_EGRESS,
10497c2aad20Sopenharmony_ci	BPF_TRACE_UPROBE_MULTI,
10507c2aad20Sopenharmony_ci	BPF_CGROUP_UNIX_CONNECT,
10517c2aad20Sopenharmony_ci	BPF_CGROUP_UNIX_SENDMSG,
10527c2aad20Sopenharmony_ci	BPF_CGROUP_UNIX_RECVMSG,
10537c2aad20Sopenharmony_ci	BPF_CGROUP_UNIX_GETPEERNAME,
10547c2aad20Sopenharmony_ci	BPF_CGROUP_UNIX_GETSOCKNAME,
10557c2aad20Sopenharmony_ci	BPF_NETKIT_PRIMARY,
10567c2aad20Sopenharmony_ci	BPF_NETKIT_PEER,
10577c2aad20Sopenharmony_ci	__MAX_BPF_ATTACH_TYPE
10587c2aad20Sopenharmony_ci};
10597c2aad20Sopenharmony_ci
10607c2aad20Sopenharmony_ci#define MAX_BPF_ATTACH_TYPE __MAX_BPF_ATTACH_TYPE
10617c2aad20Sopenharmony_ci
10627c2aad20Sopenharmony_cienum bpf_link_type {
10637c2aad20Sopenharmony_ci	BPF_LINK_TYPE_UNSPEC = 0,
10647c2aad20Sopenharmony_ci	BPF_LINK_TYPE_RAW_TRACEPOINT = 1,
10657c2aad20Sopenharmony_ci	BPF_LINK_TYPE_TRACING = 2,
10667c2aad20Sopenharmony_ci	BPF_LINK_TYPE_CGROUP = 3,
10677c2aad20Sopenharmony_ci	BPF_LINK_TYPE_ITER = 4,
10687c2aad20Sopenharmony_ci	BPF_LINK_TYPE_NETNS = 5,
10697c2aad20Sopenharmony_ci	BPF_LINK_TYPE_XDP = 6,
10707c2aad20Sopenharmony_ci	BPF_LINK_TYPE_PERF_EVENT = 7,
10717c2aad20Sopenharmony_ci	BPF_LINK_TYPE_KPROBE_MULTI = 8,
10727c2aad20Sopenharmony_ci	BPF_LINK_TYPE_STRUCT_OPS = 9,
10737c2aad20Sopenharmony_ci	BPF_LINK_TYPE_NETFILTER = 10,
10747c2aad20Sopenharmony_ci	BPF_LINK_TYPE_TCX = 11,
10757c2aad20Sopenharmony_ci	BPF_LINK_TYPE_UPROBE_MULTI = 12,
10767c2aad20Sopenharmony_ci	BPF_LINK_TYPE_NETKIT = 13,
10777c2aad20Sopenharmony_ci	MAX_BPF_LINK_TYPE,
10787c2aad20Sopenharmony_ci};
10797c2aad20Sopenharmony_ci
10807c2aad20Sopenharmony_cienum bpf_perf_event_type {
10817c2aad20Sopenharmony_ci	BPF_PERF_EVENT_UNSPEC = 0,
10827c2aad20Sopenharmony_ci	BPF_PERF_EVENT_UPROBE = 1,
10837c2aad20Sopenharmony_ci	BPF_PERF_EVENT_URETPROBE = 2,
10847c2aad20Sopenharmony_ci	BPF_PERF_EVENT_KPROBE = 3,
10857c2aad20Sopenharmony_ci	BPF_PERF_EVENT_KRETPROBE = 4,
10867c2aad20Sopenharmony_ci	BPF_PERF_EVENT_TRACEPOINT = 5,
10877c2aad20Sopenharmony_ci	BPF_PERF_EVENT_EVENT = 6,
10887c2aad20Sopenharmony_ci};
10897c2aad20Sopenharmony_ci
10907c2aad20Sopenharmony_ci/* cgroup-bpf attach flags used in BPF_PROG_ATTACH command
10917c2aad20Sopenharmony_ci *
10927c2aad20Sopenharmony_ci * NONE(default): No further bpf programs allowed in the subtree.
10937c2aad20Sopenharmony_ci *
10947c2aad20Sopenharmony_ci * BPF_F_ALLOW_OVERRIDE: If a sub-cgroup installs some bpf program,
10957c2aad20Sopenharmony_ci * the program in this cgroup yields to sub-cgroup program.
10967c2aad20Sopenharmony_ci *
10977c2aad20Sopenharmony_ci * BPF_F_ALLOW_MULTI: If a sub-cgroup installs some bpf program,
10987c2aad20Sopenharmony_ci * that cgroup program gets run in addition to the program in this cgroup.
10997c2aad20Sopenharmony_ci *
11007c2aad20Sopenharmony_ci * Only one program is allowed to be attached to a cgroup with
11017c2aad20Sopenharmony_ci * NONE or BPF_F_ALLOW_OVERRIDE flag.
11027c2aad20Sopenharmony_ci * Attaching another program on top of NONE or BPF_F_ALLOW_OVERRIDE will
11037c2aad20Sopenharmony_ci * release old program and attach the new one. Attach flags has to match.
11047c2aad20Sopenharmony_ci *
11057c2aad20Sopenharmony_ci * Multiple programs are allowed to be attached to a cgroup with
11067c2aad20Sopenharmony_ci * BPF_F_ALLOW_MULTI flag. They are executed in FIFO order
11077c2aad20Sopenharmony_ci * (those that were attached first, run first)
11087c2aad20Sopenharmony_ci * The programs of sub-cgroup are executed first, then programs of
11097c2aad20Sopenharmony_ci * this cgroup and then programs of parent cgroup.
11107c2aad20Sopenharmony_ci * When children program makes decision (like picking TCP CA or sock bind)
11117c2aad20Sopenharmony_ci * parent program has a chance to override it.
11127c2aad20Sopenharmony_ci *
11137c2aad20Sopenharmony_ci * With BPF_F_ALLOW_MULTI a new program is added to the end of the list of
11147c2aad20Sopenharmony_ci * programs for a cgroup. Though it's possible to replace an old program at
11157c2aad20Sopenharmony_ci * any position by also specifying BPF_F_REPLACE flag and position itself in
11167c2aad20Sopenharmony_ci * replace_bpf_fd attribute. Old program at this position will be released.
11177c2aad20Sopenharmony_ci *
11187c2aad20Sopenharmony_ci * A cgroup with MULTI or OVERRIDE flag allows any attach flags in sub-cgroups.
11197c2aad20Sopenharmony_ci * A cgroup with NONE doesn't allow any programs in sub-cgroups.
11207c2aad20Sopenharmony_ci * Ex1:
11217c2aad20Sopenharmony_ci * cgrp1 (MULTI progs A, B) ->
11227c2aad20Sopenharmony_ci *    cgrp2 (OVERRIDE prog C) ->
11237c2aad20Sopenharmony_ci *      cgrp3 (MULTI prog D) ->
11247c2aad20Sopenharmony_ci *        cgrp4 (OVERRIDE prog E) ->
11257c2aad20Sopenharmony_ci *          cgrp5 (NONE prog F)
11267c2aad20Sopenharmony_ci * the event in cgrp5 triggers execution of F,D,A,B in that order.
11277c2aad20Sopenharmony_ci * if prog F is detached, the execution is E,D,A,B
11287c2aad20Sopenharmony_ci * if prog F and D are detached, the execution is E,A,B
11297c2aad20Sopenharmony_ci * if prog F, E and D are detached, the execution is C,A,B
11307c2aad20Sopenharmony_ci *
11317c2aad20Sopenharmony_ci * All eligible programs are executed regardless of return code from
11327c2aad20Sopenharmony_ci * earlier programs.
11337c2aad20Sopenharmony_ci */
11347c2aad20Sopenharmony_ci#define BPF_F_ALLOW_OVERRIDE	(1U << 0)
11357c2aad20Sopenharmony_ci#define BPF_F_ALLOW_MULTI	(1U << 1)
11367c2aad20Sopenharmony_ci/* Generic attachment flags. */
11377c2aad20Sopenharmony_ci#define BPF_F_REPLACE		(1U << 2)
11387c2aad20Sopenharmony_ci#define BPF_F_BEFORE		(1U << 3)
11397c2aad20Sopenharmony_ci#define BPF_F_AFTER		(1U << 4)
11407c2aad20Sopenharmony_ci#define BPF_F_ID		(1U << 5)
11417c2aad20Sopenharmony_ci#define BPF_F_LINK		BPF_F_LINK /* 1 << 13 */
11427c2aad20Sopenharmony_ci
11437c2aad20Sopenharmony_ci/* If BPF_F_STRICT_ALIGNMENT is used in BPF_PROG_LOAD command, the
11447c2aad20Sopenharmony_ci * verifier will perform strict alignment checking as if the kernel
11457c2aad20Sopenharmony_ci * has been built with CONFIG_EFFICIENT_UNALIGNED_ACCESS not set,
11467c2aad20Sopenharmony_ci * and NET_IP_ALIGN defined to 2.
11477c2aad20Sopenharmony_ci */
11487c2aad20Sopenharmony_ci#define BPF_F_STRICT_ALIGNMENT	(1U << 0)
11497c2aad20Sopenharmony_ci
11507c2aad20Sopenharmony_ci/* If BPF_F_ANY_ALIGNMENT is used in BPF_PROG_LOAD command, the
11517c2aad20Sopenharmony_ci * verifier will allow any alignment whatsoever.  On platforms
11527c2aad20Sopenharmony_ci * with strict alignment requirements for loads ands stores (such
11537c2aad20Sopenharmony_ci * as sparc and mips) the verifier validates that all loads and
11547c2aad20Sopenharmony_ci * stores provably follow this requirement.  This flag turns that
11557c2aad20Sopenharmony_ci * checking and enforcement off.
11567c2aad20Sopenharmony_ci *
11577c2aad20Sopenharmony_ci * It is mostly used for testing when we want to validate the
11587c2aad20Sopenharmony_ci * context and memory access aspects of the verifier, but because
11597c2aad20Sopenharmony_ci * of an unaligned access the alignment check would trigger before
11607c2aad20Sopenharmony_ci * the one we are interested in.
11617c2aad20Sopenharmony_ci */
11627c2aad20Sopenharmony_ci#define BPF_F_ANY_ALIGNMENT	(1U << 1)
11637c2aad20Sopenharmony_ci
11647c2aad20Sopenharmony_ci/* BPF_F_TEST_RND_HI32 is used in BPF_PROG_LOAD command for testing purpose.
11657c2aad20Sopenharmony_ci * Verifier does sub-register def/use analysis and identifies instructions whose
11667c2aad20Sopenharmony_ci * def only matters for low 32-bit, high 32-bit is never referenced later
11677c2aad20Sopenharmony_ci * through implicit zero extension. Therefore verifier notifies JIT back-ends
11687c2aad20Sopenharmony_ci * that it is safe to ignore clearing high 32-bit for these instructions. This
11697c2aad20Sopenharmony_ci * saves some back-ends a lot of code-gen. However such optimization is not
11707c2aad20Sopenharmony_ci * necessary on some arches, for example x86_64, arm64 etc, whose JIT back-ends
11717c2aad20Sopenharmony_ci * hence hasn't used verifier's analysis result. But, we really want to have a
11727c2aad20Sopenharmony_ci * way to be able to verify the correctness of the described optimization on
11737c2aad20Sopenharmony_ci * x86_64 on which testsuites are frequently exercised.
11747c2aad20Sopenharmony_ci *
11757c2aad20Sopenharmony_ci * So, this flag is introduced. Once it is set, verifier will randomize high
11767c2aad20Sopenharmony_ci * 32-bit for those instructions who has been identified as safe to ignore them.
11777c2aad20Sopenharmony_ci * Then, if verifier is not doing correct analysis, such randomization will
11787c2aad20Sopenharmony_ci * regress tests to expose bugs.
11797c2aad20Sopenharmony_ci */
11807c2aad20Sopenharmony_ci#define BPF_F_TEST_RND_HI32	(1U << 2)
11817c2aad20Sopenharmony_ci
11827c2aad20Sopenharmony_ci/* The verifier internal test flag. Behavior is undefined */
11837c2aad20Sopenharmony_ci#define BPF_F_TEST_STATE_FREQ	(1U << 3)
11847c2aad20Sopenharmony_ci
11857c2aad20Sopenharmony_ci/* If BPF_F_SLEEPABLE is used in BPF_PROG_LOAD command, the verifier will
11867c2aad20Sopenharmony_ci * restrict map and helper usage for such programs. Sleepable BPF programs can
11877c2aad20Sopenharmony_ci * only be attached to hooks where kernel execution context allows sleeping.
11887c2aad20Sopenharmony_ci * Such programs are allowed to use helpers that may sleep like
11897c2aad20Sopenharmony_ci * bpf_copy_from_user().
11907c2aad20Sopenharmony_ci */
11917c2aad20Sopenharmony_ci#define BPF_F_SLEEPABLE		(1U << 4)
11927c2aad20Sopenharmony_ci
11937c2aad20Sopenharmony_ci/* If BPF_F_XDP_HAS_FRAGS is used in BPF_PROG_LOAD command, the loaded program
11947c2aad20Sopenharmony_ci * fully support xdp frags.
11957c2aad20Sopenharmony_ci */
11967c2aad20Sopenharmony_ci#define BPF_F_XDP_HAS_FRAGS	(1U << 5)
11977c2aad20Sopenharmony_ci
11987c2aad20Sopenharmony_ci/* If BPF_F_XDP_DEV_BOUND_ONLY is used in BPF_PROG_LOAD command, the loaded
11997c2aad20Sopenharmony_ci * program becomes device-bound but can access XDP metadata.
12007c2aad20Sopenharmony_ci */
12017c2aad20Sopenharmony_ci#define BPF_F_XDP_DEV_BOUND_ONLY	(1U << 6)
12027c2aad20Sopenharmony_ci
12037c2aad20Sopenharmony_ci/* The verifier internal test flag. Behavior is undefined */
12047c2aad20Sopenharmony_ci#define BPF_F_TEST_REG_INVARIANTS	(1U << 7)
12057c2aad20Sopenharmony_ci
12067c2aad20Sopenharmony_ci/* link_create.kprobe_multi.flags used in LINK_CREATE command for
12077c2aad20Sopenharmony_ci * BPF_TRACE_KPROBE_MULTI attach type to create return probe.
12087c2aad20Sopenharmony_ci */
12097c2aad20Sopenharmony_cienum {
12107c2aad20Sopenharmony_ci	BPF_F_KPROBE_MULTI_RETURN = (1U << 0)
12117c2aad20Sopenharmony_ci};
12127c2aad20Sopenharmony_ci
12137c2aad20Sopenharmony_ci/* link_create.uprobe_multi.flags used in LINK_CREATE command for
12147c2aad20Sopenharmony_ci * BPF_TRACE_UPROBE_MULTI attach type to create return probe.
12157c2aad20Sopenharmony_ci */
12167c2aad20Sopenharmony_cienum {
12177c2aad20Sopenharmony_ci	BPF_F_UPROBE_MULTI_RETURN = (1U << 0)
12187c2aad20Sopenharmony_ci};
12197c2aad20Sopenharmony_ci
12207c2aad20Sopenharmony_ci/* link_create.netfilter.flags used in LINK_CREATE command for
12217c2aad20Sopenharmony_ci * BPF_PROG_TYPE_NETFILTER to enable IP packet defragmentation.
12227c2aad20Sopenharmony_ci */
12237c2aad20Sopenharmony_ci#define BPF_F_NETFILTER_IP_DEFRAG (1U << 0)
12247c2aad20Sopenharmony_ci
12257c2aad20Sopenharmony_ci/* When BPF ldimm64's insn[0].src_reg != 0 then this can have
12267c2aad20Sopenharmony_ci * the following extensions:
12277c2aad20Sopenharmony_ci *
12287c2aad20Sopenharmony_ci * insn[0].src_reg:  BPF_PSEUDO_MAP_[FD|IDX]
12297c2aad20Sopenharmony_ci * insn[0].imm:      map fd or fd_idx
12307c2aad20Sopenharmony_ci * insn[1].imm:      0
12317c2aad20Sopenharmony_ci * insn[0].off:      0
12327c2aad20Sopenharmony_ci * insn[1].off:      0
12337c2aad20Sopenharmony_ci * ldimm64 rewrite:  address of map
12347c2aad20Sopenharmony_ci * verifier type:    CONST_PTR_TO_MAP
12357c2aad20Sopenharmony_ci */
12367c2aad20Sopenharmony_ci#define BPF_PSEUDO_MAP_FD	1
12377c2aad20Sopenharmony_ci#define BPF_PSEUDO_MAP_IDX	5
12387c2aad20Sopenharmony_ci
12397c2aad20Sopenharmony_ci/* insn[0].src_reg:  BPF_PSEUDO_MAP_[IDX_]VALUE
12407c2aad20Sopenharmony_ci * insn[0].imm:      map fd or fd_idx
12417c2aad20Sopenharmony_ci * insn[1].imm:      offset into value
12427c2aad20Sopenharmony_ci * insn[0].off:      0
12437c2aad20Sopenharmony_ci * insn[1].off:      0
12447c2aad20Sopenharmony_ci * ldimm64 rewrite:  address of map[0]+offset
12457c2aad20Sopenharmony_ci * verifier type:    PTR_TO_MAP_VALUE
12467c2aad20Sopenharmony_ci */
12477c2aad20Sopenharmony_ci#define BPF_PSEUDO_MAP_VALUE		2
12487c2aad20Sopenharmony_ci#define BPF_PSEUDO_MAP_IDX_VALUE	6
12497c2aad20Sopenharmony_ci
12507c2aad20Sopenharmony_ci/* insn[0].src_reg:  BPF_PSEUDO_BTF_ID
12517c2aad20Sopenharmony_ci * insn[0].imm:      kernel btd id of VAR
12527c2aad20Sopenharmony_ci * insn[1].imm:      0
12537c2aad20Sopenharmony_ci * insn[0].off:      0
12547c2aad20Sopenharmony_ci * insn[1].off:      0
12557c2aad20Sopenharmony_ci * ldimm64 rewrite:  address of the kernel variable
12567c2aad20Sopenharmony_ci * verifier type:    PTR_TO_BTF_ID or PTR_TO_MEM, depending on whether the var
12577c2aad20Sopenharmony_ci *                   is struct/union.
12587c2aad20Sopenharmony_ci */
12597c2aad20Sopenharmony_ci#define BPF_PSEUDO_BTF_ID	3
12607c2aad20Sopenharmony_ci/* insn[0].src_reg:  BPF_PSEUDO_FUNC
12617c2aad20Sopenharmony_ci * insn[0].imm:      insn offset to the func
12627c2aad20Sopenharmony_ci * insn[1].imm:      0
12637c2aad20Sopenharmony_ci * insn[0].off:      0
12647c2aad20Sopenharmony_ci * insn[1].off:      0
12657c2aad20Sopenharmony_ci * ldimm64 rewrite:  address of the function
12667c2aad20Sopenharmony_ci * verifier type:    PTR_TO_FUNC.
12677c2aad20Sopenharmony_ci */
12687c2aad20Sopenharmony_ci#define BPF_PSEUDO_FUNC		4
12697c2aad20Sopenharmony_ci
12707c2aad20Sopenharmony_ci/* when bpf_call->src_reg == BPF_PSEUDO_CALL, bpf_call->imm == pc-relative
12717c2aad20Sopenharmony_ci * offset to another bpf function
12727c2aad20Sopenharmony_ci */
12737c2aad20Sopenharmony_ci#define BPF_PSEUDO_CALL		1
12747c2aad20Sopenharmony_ci/* when bpf_call->src_reg == BPF_PSEUDO_KFUNC_CALL,
12757c2aad20Sopenharmony_ci * bpf_call->imm == btf_id of a BTF_KIND_FUNC in the running kernel
12767c2aad20Sopenharmony_ci */
12777c2aad20Sopenharmony_ci#define BPF_PSEUDO_KFUNC_CALL	2
12787c2aad20Sopenharmony_ci
12797c2aad20Sopenharmony_ci/* flags for BPF_MAP_UPDATE_ELEM command */
12807c2aad20Sopenharmony_cienum {
12817c2aad20Sopenharmony_ci	BPF_ANY		= 0, /* create new element or update existing */
12827c2aad20Sopenharmony_ci	BPF_NOEXIST	= 1, /* create new element if it didn't exist */
12837c2aad20Sopenharmony_ci	BPF_EXIST	= 2, /* update existing element */
12847c2aad20Sopenharmony_ci	BPF_F_LOCK	= 4, /* spin_lock-ed map_lookup/map_update */
12857c2aad20Sopenharmony_ci};
12867c2aad20Sopenharmony_ci
12877c2aad20Sopenharmony_ci/* flags for BPF_MAP_CREATE command */
12887c2aad20Sopenharmony_cienum {
12897c2aad20Sopenharmony_ci	BPF_F_NO_PREALLOC	= (1U << 0),
12907c2aad20Sopenharmony_ci/* Instead of having one common LRU list in the
12917c2aad20Sopenharmony_ci * BPF_MAP_TYPE_LRU_[PERCPU_]HASH map, use a percpu LRU list
12927c2aad20Sopenharmony_ci * which can scale and perform better.
12937c2aad20Sopenharmony_ci * Note, the LRU nodes (including free nodes) cannot be moved
12947c2aad20Sopenharmony_ci * across different LRU lists.
12957c2aad20Sopenharmony_ci */
12967c2aad20Sopenharmony_ci	BPF_F_NO_COMMON_LRU	= (1U << 1),
12977c2aad20Sopenharmony_ci/* Specify numa node during map creation */
12987c2aad20Sopenharmony_ci	BPF_F_NUMA_NODE		= (1U << 2),
12997c2aad20Sopenharmony_ci
13007c2aad20Sopenharmony_ci/* Flags for accessing BPF object from syscall side. */
13017c2aad20Sopenharmony_ci	BPF_F_RDONLY		= (1U << 3),
13027c2aad20Sopenharmony_ci	BPF_F_WRONLY		= (1U << 4),
13037c2aad20Sopenharmony_ci
13047c2aad20Sopenharmony_ci/* Flag for stack_map, store build_id+offset instead of pointer */
13057c2aad20Sopenharmony_ci	BPF_F_STACK_BUILD_ID	= (1U << 5),
13067c2aad20Sopenharmony_ci
13077c2aad20Sopenharmony_ci/* Zero-initialize hash function seed. This should only be used for testing. */
13087c2aad20Sopenharmony_ci	BPF_F_ZERO_SEED		= (1U << 6),
13097c2aad20Sopenharmony_ci
13107c2aad20Sopenharmony_ci/* Flags for accessing BPF object from program side. */
13117c2aad20Sopenharmony_ci	BPF_F_RDONLY_PROG	= (1U << 7),
13127c2aad20Sopenharmony_ci	BPF_F_WRONLY_PROG	= (1U << 8),
13137c2aad20Sopenharmony_ci
13147c2aad20Sopenharmony_ci/* Clone map from listener for newly accepted socket */
13157c2aad20Sopenharmony_ci	BPF_F_CLONE		= (1U << 9),
13167c2aad20Sopenharmony_ci
13177c2aad20Sopenharmony_ci/* Enable memory-mapping BPF map */
13187c2aad20Sopenharmony_ci	BPF_F_MMAPABLE		= (1U << 10),
13197c2aad20Sopenharmony_ci
13207c2aad20Sopenharmony_ci/* Share perf_event among processes */
13217c2aad20Sopenharmony_ci	BPF_F_PRESERVE_ELEMS	= (1U << 11),
13227c2aad20Sopenharmony_ci
13237c2aad20Sopenharmony_ci/* Create a map that is suitable to be an inner map with dynamic max entries */
13247c2aad20Sopenharmony_ci	BPF_F_INNER_MAP		= (1U << 12),
13257c2aad20Sopenharmony_ci
13267c2aad20Sopenharmony_ci/* Create a map that will be registered/unregesitered by the backed bpf_link */
13277c2aad20Sopenharmony_ci	BPF_F_LINK		= (1U << 13),
13287c2aad20Sopenharmony_ci
13297c2aad20Sopenharmony_ci/* Get path from provided FD in BPF_OBJ_PIN/BPF_OBJ_GET commands */
13307c2aad20Sopenharmony_ci	BPF_F_PATH_FD		= (1U << 14),
13317c2aad20Sopenharmony_ci};
13327c2aad20Sopenharmony_ci
13337c2aad20Sopenharmony_ci/* Flags for BPF_PROG_QUERY. */
13347c2aad20Sopenharmony_ci
13357c2aad20Sopenharmony_ci/* Query effective (directly attached + inherited from ancestor cgroups)
13367c2aad20Sopenharmony_ci * programs that will be executed for events within a cgroup.
13377c2aad20Sopenharmony_ci * attach_flags with this flag are always returned 0.
13387c2aad20Sopenharmony_ci */
13397c2aad20Sopenharmony_ci#define BPF_F_QUERY_EFFECTIVE	(1U << 0)
13407c2aad20Sopenharmony_ci
13417c2aad20Sopenharmony_ci/* Flags for BPF_PROG_TEST_RUN */
13427c2aad20Sopenharmony_ci
13437c2aad20Sopenharmony_ci/* If set, run the test on the cpu specified by bpf_attr.test.cpu */
13447c2aad20Sopenharmony_ci#define BPF_F_TEST_RUN_ON_CPU	(1U << 0)
13457c2aad20Sopenharmony_ci/* If set, XDP frames will be transmitted after processing */
13467c2aad20Sopenharmony_ci#define BPF_F_TEST_XDP_LIVE_FRAMES	(1U << 1)
13477c2aad20Sopenharmony_ci
13487c2aad20Sopenharmony_ci/* type for BPF_ENABLE_STATS */
13497c2aad20Sopenharmony_cienum bpf_stats_type {
13507c2aad20Sopenharmony_ci	/* enabled run_time_ns and run_cnt */
13517c2aad20Sopenharmony_ci	BPF_STATS_RUN_TIME = 0,
13527c2aad20Sopenharmony_ci};
13537c2aad20Sopenharmony_ci
13547c2aad20Sopenharmony_cienum bpf_stack_build_id_status {
13557c2aad20Sopenharmony_ci	/* user space need an empty entry to identify end of a trace */
13567c2aad20Sopenharmony_ci	BPF_STACK_BUILD_ID_EMPTY = 0,
13577c2aad20Sopenharmony_ci	/* with valid build_id and offset */
13587c2aad20Sopenharmony_ci	BPF_STACK_BUILD_ID_VALID = 1,
13597c2aad20Sopenharmony_ci	/* couldn't get build_id, fallback to ip */
13607c2aad20Sopenharmony_ci	BPF_STACK_BUILD_ID_IP = 2,
13617c2aad20Sopenharmony_ci};
13627c2aad20Sopenharmony_ci
13637c2aad20Sopenharmony_ci#define BPF_BUILD_ID_SIZE 20
13647c2aad20Sopenharmony_cistruct bpf_stack_build_id {
13657c2aad20Sopenharmony_ci	__s32		status;
13667c2aad20Sopenharmony_ci	unsigned char	build_id[BPF_BUILD_ID_SIZE];
13677c2aad20Sopenharmony_ci	union {
13687c2aad20Sopenharmony_ci		__u64	offset;
13697c2aad20Sopenharmony_ci		__u64	ip;
13707c2aad20Sopenharmony_ci	};
13717c2aad20Sopenharmony_ci};
13727c2aad20Sopenharmony_ci
13737c2aad20Sopenharmony_ci#define BPF_OBJ_NAME_LEN 16U
13747c2aad20Sopenharmony_ci
13757c2aad20Sopenharmony_ciunion bpf_attr {
13767c2aad20Sopenharmony_ci	struct { /* anonymous struct used by BPF_MAP_CREATE command */
13777c2aad20Sopenharmony_ci		__u32	map_type;	/* one of enum bpf_map_type */
13787c2aad20Sopenharmony_ci		__u32	key_size;	/* size of key in bytes */
13797c2aad20Sopenharmony_ci		__u32	value_size;	/* size of value in bytes */
13807c2aad20Sopenharmony_ci		__u32	max_entries;	/* max number of entries in a map */
13817c2aad20Sopenharmony_ci		__u32	map_flags;	/* BPF_MAP_CREATE related
13827c2aad20Sopenharmony_ci					 * flags defined above.
13837c2aad20Sopenharmony_ci					 */
13847c2aad20Sopenharmony_ci		__u32	inner_map_fd;	/* fd pointing to the inner map */
13857c2aad20Sopenharmony_ci		__u32	numa_node;	/* numa node (effective only if
13867c2aad20Sopenharmony_ci					 * BPF_F_NUMA_NODE is set).
13877c2aad20Sopenharmony_ci					 */
13887c2aad20Sopenharmony_ci		char	map_name[BPF_OBJ_NAME_LEN];
13897c2aad20Sopenharmony_ci		__u32	map_ifindex;	/* ifindex of netdev to create on */
13907c2aad20Sopenharmony_ci		__u32	btf_fd;		/* fd pointing to a BTF type data */
13917c2aad20Sopenharmony_ci		__u32	btf_key_type_id;	/* BTF type_id of the key */
13927c2aad20Sopenharmony_ci		__u32	btf_value_type_id;	/* BTF type_id of the value */
13937c2aad20Sopenharmony_ci		__u32	btf_vmlinux_value_type_id;/* BTF type_id of a kernel-
13947c2aad20Sopenharmony_ci						   * struct stored as the
13957c2aad20Sopenharmony_ci						   * map value
13967c2aad20Sopenharmony_ci						   */
13977c2aad20Sopenharmony_ci		/* Any per-map-type extra fields
13987c2aad20Sopenharmony_ci		 *
13997c2aad20Sopenharmony_ci		 * BPF_MAP_TYPE_BLOOM_FILTER - the lowest 4 bits indicate the
14007c2aad20Sopenharmony_ci		 * number of hash functions (if 0, the bloom filter will default
14017c2aad20Sopenharmony_ci		 * to using 5 hash functions).
14027c2aad20Sopenharmony_ci		 */
14037c2aad20Sopenharmony_ci		__u64	map_extra;
14047c2aad20Sopenharmony_ci	};
14057c2aad20Sopenharmony_ci
14067c2aad20Sopenharmony_ci	struct { /* anonymous struct used by BPF_MAP_*_ELEM commands */
14077c2aad20Sopenharmony_ci		__u32		map_fd;
14087c2aad20Sopenharmony_ci		__aligned_u64	key;
14097c2aad20Sopenharmony_ci		union {
14107c2aad20Sopenharmony_ci			__aligned_u64 value;
14117c2aad20Sopenharmony_ci			__aligned_u64 next_key;
14127c2aad20Sopenharmony_ci		};
14137c2aad20Sopenharmony_ci		__u64		flags;
14147c2aad20Sopenharmony_ci	};
14157c2aad20Sopenharmony_ci
14167c2aad20Sopenharmony_ci	struct { /* struct used by BPF_MAP_*_BATCH commands */
14177c2aad20Sopenharmony_ci		__aligned_u64	in_batch;	/* start batch,
14187c2aad20Sopenharmony_ci						 * NULL to start from beginning
14197c2aad20Sopenharmony_ci						 */
14207c2aad20Sopenharmony_ci		__aligned_u64	out_batch;	/* output: next start batch */
14217c2aad20Sopenharmony_ci		__aligned_u64	keys;
14227c2aad20Sopenharmony_ci		__aligned_u64	values;
14237c2aad20Sopenharmony_ci		__u32		count;		/* input/output:
14247c2aad20Sopenharmony_ci						 * input: # of key/value
14257c2aad20Sopenharmony_ci						 * elements
14267c2aad20Sopenharmony_ci						 * output: # of filled elements
14277c2aad20Sopenharmony_ci						 */
14287c2aad20Sopenharmony_ci		__u32		map_fd;
14297c2aad20Sopenharmony_ci		__u64		elem_flags;
14307c2aad20Sopenharmony_ci		__u64		flags;
14317c2aad20Sopenharmony_ci	} batch;
14327c2aad20Sopenharmony_ci
14337c2aad20Sopenharmony_ci	struct { /* anonymous struct used by BPF_PROG_LOAD command */
14347c2aad20Sopenharmony_ci		__u32		prog_type;	/* one of enum bpf_prog_type */
14357c2aad20Sopenharmony_ci		__u32		insn_cnt;
14367c2aad20Sopenharmony_ci		__aligned_u64	insns;
14377c2aad20Sopenharmony_ci		__aligned_u64	license;
14387c2aad20Sopenharmony_ci		__u32		log_level;	/* verbosity level of verifier */
14397c2aad20Sopenharmony_ci		__u32		log_size;	/* size of user buffer */
14407c2aad20Sopenharmony_ci		__aligned_u64	log_buf;	/* user supplied buffer */
14417c2aad20Sopenharmony_ci		__u32		kern_version;	/* not used */
14427c2aad20Sopenharmony_ci		__u32		prog_flags;
14437c2aad20Sopenharmony_ci		char		prog_name[BPF_OBJ_NAME_LEN];
14447c2aad20Sopenharmony_ci		__u32		prog_ifindex;	/* ifindex of netdev to prep for */
14457c2aad20Sopenharmony_ci		/* For some prog types expected attach type must be known at
14467c2aad20Sopenharmony_ci		 * load time to verify attach type specific parts of prog
14477c2aad20Sopenharmony_ci		 * (context accesses, allowed helpers, etc).
14487c2aad20Sopenharmony_ci		 */
14497c2aad20Sopenharmony_ci		__u32		expected_attach_type;
14507c2aad20Sopenharmony_ci		__u32		prog_btf_fd;	/* fd pointing to BTF type data */
14517c2aad20Sopenharmony_ci		__u32		func_info_rec_size;	/* userspace bpf_func_info size */
14527c2aad20Sopenharmony_ci		__aligned_u64	func_info;	/* func info */
14537c2aad20Sopenharmony_ci		__u32		func_info_cnt;	/* number of bpf_func_info records */
14547c2aad20Sopenharmony_ci		__u32		line_info_rec_size;	/* userspace bpf_line_info size */
14557c2aad20Sopenharmony_ci		__aligned_u64	line_info;	/* line info */
14567c2aad20Sopenharmony_ci		__u32		line_info_cnt;	/* number of bpf_line_info records */
14577c2aad20Sopenharmony_ci		__u32		attach_btf_id;	/* in-kernel BTF type id to attach to */
14587c2aad20Sopenharmony_ci		union {
14597c2aad20Sopenharmony_ci			/* valid prog_fd to attach to bpf prog */
14607c2aad20Sopenharmony_ci			__u32		attach_prog_fd;
14617c2aad20Sopenharmony_ci			/* or valid module BTF object fd or 0 to attach to vmlinux */
14627c2aad20Sopenharmony_ci			__u32		attach_btf_obj_fd;
14637c2aad20Sopenharmony_ci		};
14647c2aad20Sopenharmony_ci		__u32		core_relo_cnt;	/* number of bpf_core_relo */
14657c2aad20Sopenharmony_ci		__aligned_u64	fd_array;	/* array of FDs */
14667c2aad20Sopenharmony_ci		__aligned_u64	core_relos;
14677c2aad20Sopenharmony_ci		__u32		core_relo_rec_size; /* sizeof(struct bpf_core_relo) */
14687c2aad20Sopenharmony_ci		/* output: actual total log contents size (including termintaing zero).
14697c2aad20Sopenharmony_ci		 * It could be both larger than original log_size (if log was
14707c2aad20Sopenharmony_ci		 * truncated), or smaller (if log buffer wasn't filled completely).
14717c2aad20Sopenharmony_ci		 */
14727c2aad20Sopenharmony_ci		__u32		log_true_size;
14737c2aad20Sopenharmony_ci	};
14747c2aad20Sopenharmony_ci
14757c2aad20Sopenharmony_ci	struct { /* anonymous struct used by BPF_OBJ_* commands */
14767c2aad20Sopenharmony_ci		__aligned_u64	pathname;
14777c2aad20Sopenharmony_ci		__u32		bpf_fd;
14787c2aad20Sopenharmony_ci		__u32		file_flags;
14797c2aad20Sopenharmony_ci		/* Same as dirfd in openat() syscall; see openat(2)
14807c2aad20Sopenharmony_ci		 * manpage for details of path FD and pathname semantics;
14817c2aad20Sopenharmony_ci		 * path_fd should accompanied by BPF_F_PATH_FD flag set in
14827c2aad20Sopenharmony_ci		 * file_flags field, otherwise it should be set to zero;
14837c2aad20Sopenharmony_ci		 * if BPF_F_PATH_FD flag is not set, AT_FDCWD is assumed.
14847c2aad20Sopenharmony_ci		 */
14857c2aad20Sopenharmony_ci		__s32		path_fd;
14867c2aad20Sopenharmony_ci	};
14877c2aad20Sopenharmony_ci
14887c2aad20Sopenharmony_ci	struct { /* anonymous struct used by BPF_PROG_ATTACH/DETACH commands */
14897c2aad20Sopenharmony_ci		union {
14907c2aad20Sopenharmony_ci			__u32	target_fd;	/* target object to attach to or ... */
14917c2aad20Sopenharmony_ci			__u32	target_ifindex;	/* target ifindex */
14927c2aad20Sopenharmony_ci		};
14937c2aad20Sopenharmony_ci		__u32		attach_bpf_fd;
14947c2aad20Sopenharmony_ci		__u32		attach_type;
14957c2aad20Sopenharmony_ci		__u32		attach_flags;
14967c2aad20Sopenharmony_ci		__u32		replace_bpf_fd;
14977c2aad20Sopenharmony_ci		union {
14987c2aad20Sopenharmony_ci			__u32	relative_fd;
14997c2aad20Sopenharmony_ci			__u32	relative_id;
15007c2aad20Sopenharmony_ci		};
15017c2aad20Sopenharmony_ci		__u64		expected_revision;
15027c2aad20Sopenharmony_ci	};
15037c2aad20Sopenharmony_ci
15047c2aad20Sopenharmony_ci	struct { /* anonymous struct used by BPF_PROG_TEST_RUN command */
15057c2aad20Sopenharmony_ci		__u32		prog_fd;
15067c2aad20Sopenharmony_ci		__u32		retval;
15077c2aad20Sopenharmony_ci		__u32		data_size_in;	/* input: len of data_in */
15087c2aad20Sopenharmony_ci		__u32		data_size_out;	/* input/output: len of data_out
15097c2aad20Sopenharmony_ci						 *   returns ENOSPC if data_out
15107c2aad20Sopenharmony_ci						 *   is too small.
15117c2aad20Sopenharmony_ci						 */
15127c2aad20Sopenharmony_ci		__aligned_u64	data_in;
15137c2aad20Sopenharmony_ci		__aligned_u64	data_out;
15147c2aad20Sopenharmony_ci		__u32		repeat;
15157c2aad20Sopenharmony_ci		__u32		duration;
15167c2aad20Sopenharmony_ci		__u32		ctx_size_in;	/* input: len of ctx_in */
15177c2aad20Sopenharmony_ci		__u32		ctx_size_out;	/* input/output: len of ctx_out
15187c2aad20Sopenharmony_ci						 *   returns ENOSPC if ctx_out
15197c2aad20Sopenharmony_ci						 *   is too small.
15207c2aad20Sopenharmony_ci						 */
15217c2aad20Sopenharmony_ci		__aligned_u64	ctx_in;
15227c2aad20Sopenharmony_ci		__aligned_u64	ctx_out;
15237c2aad20Sopenharmony_ci		__u32		flags;
15247c2aad20Sopenharmony_ci		__u32		cpu;
15257c2aad20Sopenharmony_ci		__u32		batch_size;
15267c2aad20Sopenharmony_ci	} test;
15277c2aad20Sopenharmony_ci
15287c2aad20Sopenharmony_ci	struct { /* anonymous struct used by BPF_*_GET_*_ID */
15297c2aad20Sopenharmony_ci		union {
15307c2aad20Sopenharmony_ci			__u32		start_id;
15317c2aad20Sopenharmony_ci			__u32		prog_id;
15327c2aad20Sopenharmony_ci			__u32		map_id;
15337c2aad20Sopenharmony_ci			__u32		btf_id;
15347c2aad20Sopenharmony_ci			__u32		link_id;
15357c2aad20Sopenharmony_ci		};
15367c2aad20Sopenharmony_ci		__u32		next_id;
15377c2aad20Sopenharmony_ci		__u32		open_flags;
15387c2aad20Sopenharmony_ci	};
15397c2aad20Sopenharmony_ci
15407c2aad20Sopenharmony_ci	struct { /* anonymous struct used by BPF_OBJ_GET_INFO_BY_FD */
15417c2aad20Sopenharmony_ci		__u32		bpf_fd;
15427c2aad20Sopenharmony_ci		__u32		info_len;
15437c2aad20Sopenharmony_ci		__aligned_u64	info;
15447c2aad20Sopenharmony_ci	} info;
15457c2aad20Sopenharmony_ci
15467c2aad20Sopenharmony_ci	struct { /* anonymous struct used by BPF_PROG_QUERY command */
15477c2aad20Sopenharmony_ci		union {
15487c2aad20Sopenharmony_ci			__u32	target_fd;	/* target object to query or ... */
15497c2aad20Sopenharmony_ci			__u32	target_ifindex;	/* target ifindex */
15507c2aad20Sopenharmony_ci		};
15517c2aad20Sopenharmony_ci		__u32		attach_type;
15527c2aad20Sopenharmony_ci		__u32		query_flags;
15537c2aad20Sopenharmony_ci		__u32		attach_flags;
15547c2aad20Sopenharmony_ci		__aligned_u64	prog_ids;
15557c2aad20Sopenharmony_ci		union {
15567c2aad20Sopenharmony_ci			__u32	prog_cnt;
15577c2aad20Sopenharmony_ci			__u32	count;
15587c2aad20Sopenharmony_ci		};
15597c2aad20Sopenharmony_ci		__u32		:32;
15607c2aad20Sopenharmony_ci		/* output: per-program attach_flags.
15617c2aad20Sopenharmony_ci		 * not allowed to be set during effective query.
15627c2aad20Sopenharmony_ci		 */
15637c2aad20Sopenharmony_ci		__aligned_u64	prog_attach_flags;
15647c2aad20Sopenharmony_ci		__aligned_u64	link_ids;
15657c2aad20Sopenharmony_ci		__aligned_u64	link_attach_flags;
15667c2aad20Sopenharmony_ci		__u64		revision;
15677c2aad20Sopenharmony_ci	} query;
15687c2aad20Sopenharmony_ci
15697c2aad20Sopenharmony_ci	struct { /* anonymous struct used by BPF_RAW_TRACEPOINT_OPEN command */
15707c2aad20Sopenharmony_ci		__u64 name;
15717c2aad20Sopenharmony_ci		__u32 prog_fd;
15727c2aad20Sopenharmony_ci	} raw_tracepoint;
15737c2aad20Sopenharmony_ci
15747c2aad20Sopenharmony_ci	struct { /* anonymous struct for BPF_BTF_LOAD */
15757c2aad20Sopenharmony_ci		__aligned_u64	btf;
15767c2aad20Sopenharmony_ci		__aligned_u64	btf_log_buf;
15777c2aad20Sopenharmony_ci		__u32		btf_size;
15787c2aad20Sopenharmony_ci		__u32		btf_log_size;
15797c2aad20Sopenharmony_ci		__u32		btf_log_level;
15807c2aad20Sopenharmony_ci		/* output: actual total log contents size (including termintaing zero).
15817c2aad20Sopenharmony_ci		 * It could be both larger than original log_size (if log was
15827c2aad20Sopenharmony_ci		 * truncated), or smaller (if log buffer wasn't filled completely).
15837c2aad20Sopenharmony_ci		 */
15847c2aad20Sopenharmony_ci		__u32		btf_log_true_size;
15857c2aad20Sopenharmony_ci	};
15867c2aad20Sopenharmony_ci
15877c2aad20Sopenharmony_ci	struct {
15887c2aad20Sopenharmony_ci		__u32		pid;		/* input: pid */
15897c2aad20Sopenharmony_ci		__u32		fd;		/* input: fd */
15907c2aad20Sopenharmony_ci		__u32		flags;		/* input: flags */
15917c2aad20Sopenharmony_ci		__u32		buf_len;	/* input/output: buf len */
15927c2aad20Sopenharmony_ci		__aligned_u64	buf;		/* input/output:
15937c2aad20Sopenharmony_ci						 *   tp_name for tracepoint
15947c2aad20Sopenharmony_ci						 *   symbol for kprobe
15957c2aad20Sopenharmony_ci						 *   filename for uprobe
15967c2aad20Sopenharmony_ci						 */
15977c2aad20Sopenharmony_ci		__u32		prog_id;	/* output: prod_id */
15987c2aad20Sopenharmony_ci		__u32		fd_type;	/* output: BPF_FD_TYPE_* */
15997c2aad20Sopenharmony_ci		__u64		probe_offset;	/* output: probe_offset */
16007c2aad20Sopenharmony_ci		__u64		probe_addr;	/* output: probe_addr */
16017c2aad20Sopenharmony_ci	} task_fd_query;
16027c2aad20Sopenharmony_ci
16037c2aad20Sopenharmony_ci	struct { /* struct used by BPF_LINK_CREATE command */
16047c2aad20Sopenharmony_ci		union {
16057c2aad20Sopenharmony_ci			__u32		prog_fd;	/* eBPF program to attach */
16067c2aad20Sopenharmony_ci			__u32		map_fd;		/* struct_ops to attach */
16077c2aad20Sopenharmony_ci		};
16087c2aad20Sopenharmony_ci		union {
16097c2aad20Sopenharmony_ci			__u32	target_fd;	/* target object to attach to or ... */
16107c2aad20Sopenharmony_ci			__u32	target_ifindex; /* target ifindex */
16117c2aad20Sopenharmony_ci		};
16127c2aad20Sopenharmony_ci		__u32		attach_type;	/* attach type */
16137c2aad20Sopenharmony_ci		__u32		flags;		/* extra flags */
16147c2aad20Sopenharmony_ci		union {
16157c2aad20Sopenharmony_ci			__u32	target_btf_id;	/* btf_id of target to attach to */
16167c2aad20Sopenharmony_ci			struct {
16177c2aad20Sopenharmony_ci				__aligned_u64	iter_info;	/* extra bpf_iter_link_info */
16187c2aad20Sopenharmony_ci				__u32		iter_info_len;	/* iter_info length */
16197c2aad20Sopenharmony_ci			};
16207c2aad20Sopenharmony_ci			struct {
16217c2aad20Sopenharmony_ci				/* black box user-provided value passed through
16227c2aad20Sopenharmony_ci				 * to BPF program at the execution time and
16237c2aad20Sopenharmony_ci				 * accessible through bpf_get_attach_cookie() BPF helper
16247c2aad20Sopenharmony_ci				 */
16257c2aad20Sopenharmony_ci				__u64		bpf_cookie;
16267c2aad20Sopenharmony_ci			} perf_event;
16277c2aad20Sopenharmony_ci			struct {
16287c2aad20Sopenharmony_ci				__u32		flags;
16297c2aad20Sopenharmony_ci				__u32		cnt;
16307c2aad20Sopenharmony_ci				__aligned_u64	syms;
16317c2aad20Sopenharmony_ci				__aligned_u64	addrs;
16327c2aad20Sopenharmony_ci				__aligned_u64	cookies;
16337c2aad20Sopenharmony_ci			} kprobe_multi;
16347c2aad20Sopenharmony_ci			struct {
16357c2aad20Sopenharmony_ci				/* this is overlaid with the target_btf_id above. */
16367c2aad20Sopenharmony_ci				__u32		target_btf_id;
16377c2aad20Sopenharmony_ci				/* black box user-provided value passed through
16387c2aad20Sopenharmony_ci				 * to BPF program at the execution time and
16397c2aad20Sopenharmony_ci				 * accessible through bpf_get_attach_cookie() BPF helper
16407c2aad20Sopenharmony_ci				 */
16417c2aad20Sopenharmony_ci				__u64		cookie;
16427c2aad20Sopenharmony_ci			} tracing;
16437c2aad20Sopenharmony_ci			struct {
16447c2aad20Sopenharmony_ci				__u32		pf;
16457c2aad20Sopenharmony_ci				__u32		hooknum;
16467c2aad20Sopenharmony_ci				__s32		priority;
16477c2aad20Sopenharmony_ci				__u32		flags;
16487c2aad20Sopenharmony_ci			} netfilter;
16497c2aad20Sopenharmony_ci			struct {
16507c2aad20Sopenharmony_ci				union {
16517c2aad20Sopenharmony_ci					__u32	relative_fd;
16527c2aad20Sopenharmony_ci					__u32	relative_id;
16537c2aad20Sopenharmony_ci				};
16547c2aad20Sopenharmony_ci				__u64		expected_revision;
16557c2aad20Sopenharmony_ci			} tcx;
16567c2aad20Sopenharmony_ci			struct {
16577c2aad20Sopenharmony_ci				__aligned_u64	path;
16587c2aad20Sopenharmony_ci				__aligned_u64	offsets;
16597c2aad20Sopenharmony_ci				__aligned_u64	ref_ctr_offsets;
16607c2aad20Sopenharmony_ci				__aligned_u64	cookies;
16617c2aad20Sopenharmony_ci				__u32		cnt;
16627c2aad20Sopenharmony_ci				__u32		flags;
16637c2aad20Sopenharmony_ci				__u32		pid;
16647c2aad20Sopenharmony_ci			} uprobe_multi;
16657c2aad20Sopenharmony_ci			struct {
16667c2aad20Sopenharmony_ci				union {
16677c2aad20Sopenharmony_ci					__u32	relative_fd;
16687c2aad20Sopenharmony_ci					__u32	relative_id;
16697c2aad20Sopenharmony_ci				};
16707c2aad20Sopenharmony_ci				__u64		expected_revision;
16717c2aad20Sopenharmony_ci			} netkit;
16727c2aad20Sopenharmony_ci		};
16737c2aad20Sopenharmony_ci	} link_create;
16747c2aad20Sopenharmony_ci
16757c2aad20Sopenharmony_ci	struct { /* struct used by BPF_LINK_UPDATE command */
16767c2aad20Sopenharmony_ci		__u32		link_fd;	/* link fd */
16777c2aad20Sopenharmony_ci		union {
16787c2aad20Sopenharmony_ci			/* new program fd to update link with */
16797c2aad20Sopenharmony_ci			__u32		new_prog_fd;
16807c2aad20Sopenharmony_ci			/* new struct_ops map fd to update link with */
16817c2aad20Sopenharmony_ci			__u32           new_map_fd;
16827c2aad20Sopenharmony_ci		};
16837c2aad20Sopenharmony_ci		__u32		flags;		/* extra flags */
16847c2aad20Sopenharmony_ci		union {
16857c2aad20Sopenharmony_ci			/* expected link's program fd; is specified only if
16867c2aad20Sopenharmony_ci			 * BPF_F_REPLACE flag is set in flags.
16877c2aad20Sopenharmony_ci			 */
16887c2aad20Sopenharmony_ci			__u32		old_prog_fd;
16897c2aad20Sopenharmony_ci			/* expected link's map fd; is specified only
16907c2aad20Sopenharmony_ci			 * if BPF_F_REPLACE flag is set.
16917c2aad20Sopenharmony_ci			 */
16927c2aad20Sopenharmony_ci			__u32           old_map_fd;
16937c2aad20Sopenharmony_ci		};
16947c2aad20Sopenharmony_ci	} link_update;
16957c2aad20Sopenharmony_ci
16967c2aad20Sopenharmony_ci	struct {
16977c2aad20Sopenharmony_ci		__u32		link_fd;
16987c2aad20Sopenharmony_ci	} link_detach;
16997c2aad20Sopenharmony_ci
17007c2aad20Sopenharmony_ci	struct { /* struct used by BPF_ENABLE_STATS command */
17017c2aad20Sopenharmony_ci		__u32		type;
17027c2aad20Sopenharmony_ci	} enable_stats;
17037c2aad20Sopenharmony_ci
17047c2aad20Sopenharmony_ci	struct { /* struct used by BPF_ITER_CREATE command */
17057c2aad20Sopenharmony_ci		__u32		link_fd;
17067c2aad20Sopenharmony_ci		__u32		flags;
17077c2aad20Sopenharmony_ci	} iter_create;
17087c2aad20Sopenharmony_ci
17097c2aad20Sopenharmony_ci	struct { /* struct used by BPF_PROG_BIND_MAP command */
17107c2aad20Sopenharmony_ci		__u32		prog_fd;
17117c2aad20Sopenharmony_ci		__u32		map_fd;
17127c2aad20Sopenharmony_ci		__u32		flags;		/* extra flags */
17137c2aad20Sopenharmony_ci	} prog_bind_map;
17147c2aad20Sopenharmony_ci
17157c2aad20Sopenharmony_ci} __attribute__((aligned(8)));
17167c2aad20Sopenharmony_ci
17177c2aad20Sopenharmony_ci/* The description below is an attempt at providing documentation to eBPF
17187c2aad20Sopenharmony_ci * developers about the multiple available eBPF helper functions. It can be
17197c2aad20Sopenharmony_ci * parsed and used to produce a manual page. The workflow is the following,
17207c2aad20Sopenharmony_ci * and requires the rst2man utility:
17217c2aad20Sopenharmony_ci *
17227c2aad20Sopenharmony_ci *     $ ./scripts/bpf_doc.py \
17237c2aad20Sopenharmony_ci *             --filename include/uapi/linux/bpf.h > /tmp/bpf-helpers.rst
17247c2aad20Sopenharmony_ci *     $ rst2man /tmp/bpf-helpers.rst > /tmp/bpf-helpers.7
17257c2aad20Sopenharmony_ci *     $ man /tmp/bpf-helpers.7
17267c2aad20Sopenharmony_ci *
17277c2aad20Sopenharmony_ci * Note that in order to produce this external documentation, some RST
17287c2aad20Sopenharmony_ci * formatting is used in the descriptions to get "bold" and "italics" in
17297c2aad20Sopenharmony_ci * manual pages. Also note that the few trailing white spaces are
17307c2aad20Sopenharmony_ci * intentional, removing them would break paragraphs for rst2man.
17317c2aad20Sopenharmony_ci *
17327c2aad20Sopenharmony_ci * Start of BPF helper function descriptions:
17337c2aad20Sopenharmony_ci *
17347c2aad20Sopenharmony_ci * void *bpf_map_lookup_elem(struct bpf_map *map, const void *key)
17357c2aad20Sopenharmony_ci * 	Description
17367c2aad20Sopenharmony_ci * 		Perform a lookup in *map* for an entry associated to *key*.
17377c2aad20Sopenharmony_ci * 	Return
17387c2aad20Sopenharmony_ci * 		Map value associated to *key*, or **NULL** if no entry was
17397c2aad20Sopenharmony_ci * 		found.
17407c2aad20Sopenharmony_ci *
17417c2aad20Sopenharmony_ci * long bpf_map_update_elem(struct bpf_map *map, const void *key, const void *value, u64 flags)
17427c2aad20Sopenharmony_ci * 	Description
17437c2aad20Sopenharmony_ci * 		Add or update the value of the entry associated to *key* in
17447c2aad20Sopenharmony_ci * 		*map* with *value*. *flags* is one of:
17457c2aad20Sopenharmony_ci *
17467c2aad20Sopenharmony_ci * 		**BPF_NOEXIST**
17477c2aad20Sopenharmony_ci * 			The entry for *key* must not exist in the map.
17487c2aad20Sopenharmony_ci * 		**BPF_EXIST**
17497c2aad20Sopenharmony_ci * 			The entry for *key* must already exist in the map.
17507c2aad20Sopenharmony_ci * 		**BPF_ANY**
17517c2aad20Sopenharmony_ci * 			No condition on the existence of the entry for *key*.
17527c2aad20Sopenharmony_ci *
17537c2aad20Sopenharmony_ci * 		Flag value **BPF_NOEXIST** cannot be used for maps of types
17547c2aad20Sopenharmony_ci * 		**BPF_MAP_TYPE_ARRAY** or **BPF_MAP_TYPE_PERCPU_ARRAY**  (all
17557c2aad20Sopenharmony_ci * 		elements always exist), the helper would return an error.
17567c2aad20Sopenharmony_ci * 	Return
17577c2aad20Sopenharmony_ci * 		0 on success, or a negative error in case of failure.
17587c2aad20Sopenharmony_ci *
17597c2aad20Sopenharmony_ci * long bpf_map_delete_elem(struct bpf_map *map, const void *key)
17607c2aad20Sopenharmony_ci * 	Description
17617c2aad20Sopenharmony_ci * 		Delete entry with *key* from *map*.
17627c2aad20Sopenharmony_ci * 	Return
17637c2aad20Sopenharmony_ci * 		0 on success, or a negative error in case of failure.
17647c2aad20Sopenharmony_ci *
17657c2aad20Sopenharmony_ci * long bpf_probe_read(void *dst, u32 size, const void *unsafe_ptr)
17667c2aad20Sopenharmony_ci * 	Description
17677c2aad20Sopenharmony_ci * 		For tracing programs, safely attempt to read *size* bytes from
17687c2aad20Sopenharmony_ci * 		kernel space address *unsafe_ptr* and store the data in *dst*.
17697c2aad20Sopenharmony_ci *
17707c2aad20Sopenharmony_ci * 		Generally, use **bpf_probe_read_user**\ () or
17717c2aad20Sopenharmony_ci * 		**bpf_probe_read_kernel**\ () instead.
17727c2aad20Sopenharmony_ci * 	Return
17737c2aad20Sopenharmony_ci * 		0 on success, or a negative error in case of failure.
17747c2aad20Sopenharmony_ci *
17757c2aad20Sopenharmony_ci * u64 bpf_ktime_get_ns(void)
17767c2aad20Sopenharmony_ci * 	Description
17777c2aad20Sopenharmony_ci * 		Return the time elapsed since system boot, in nanoseconds.
17787c2aad20Sopenharmony_ci * 		Does not include time the system was suspended.
17797c2aad20Sopenharmony_ci * 		See: **clock_gettime**\ (**CLOCK_MONOTONIC**)
17807c2aad20Sopenharmony_ci * 	Return
17817c2aad20Sopenharmony_ci * 		Current *ktime*.
17827c2aad20Sopenharmony_ci *
17837c2aad20Sopenharmony_ci * long bpf_trace_printk(const char *fmt, u32 fmt_size, ...)
17847c2aad20Sopenharmony_ci * 	Description
17857c2aad20Sopenharmony_ci * 		This helper is a "printk()-like" facility for debugging. It
17867c2aad20Sopenharmony_ci * 		prints a message defined by format *fmt* (of size *fmt_size*)
17877c2aad20Sopenharmony_ci * 		to file *\/sys/kernel/tracing/trace* from TraceFS, if
17887c2aad20Sopenharmony_ci * 		available. It can take up to three additional **u64**
17897c2aad20Sopenharmony_ci * 		arguments (as an eBPF helpers, the total number of arguments is
17907c2aad20Sopenharmony_ci * 		limited to five).
17917c2aad20Sopenharmony_ci *
17927c2aad20Sopenharmony_ci * 		Each time the helper is called, it appends a line to the trace.
17937c2aad20Sopenharmony_ci * 		Lines are discarded while *\/sys/kernel/tracing/trace* is
17947c2aad20Sopenharmony_ci * 		open, use *\/sys/kernel/tracing/trace_pipe* to avoid this.
17957c2aad20Sopenharmony_ci * 		The format of the trace is customizable, and the exact output
17967c2aad20Sopenharmony_ci * 		one will get depends on the options set in
17977c2aad20Sopenharmony_ci * 		*\/sys/kernel/tracing/trace_options* (see also the
17987c2aad20Sopenharmony_ci * 		*README* file under the same directory). However, it usually
17997c2aad20Sopenharmony_ci * 		defaults to something like:
18007c2aad20Sopenharmony_ci *
18017c2aad20Sopenharmony_ci * 		::
18027c2aad20Sopenharmony_ci *
18037c2aad20Sopenharmony_ci * 			telnet-470   [001] .N.. 419421.045894: 0x00000001: <formatted msg>
18047c2aad20Sopenharmony_ci *
18057c2aad20Sopenharmony_ci * 		In the above:
18067c2aad20Sopenharmony_ci *
18077c2aad20Sopenharmony_ci * 			* ``telnet`` is the name of the current task.
18087c2aad20Sopenharmony_ci * 			* ``470`` is the PID of the current task.
18097c2aad20Sopenharmony_ci * 			* ``001`` is the CPU number on which the task is
18107c2aad20Sopenharmony_ci * 			  running.
18117c2aad20Sopenharmony_ci * 			* In ``.N..``, each character refers to a set of
18127c2aad20Sopenharmony_ci * 			  options (whether irqs are enabled, scheduling
18137c2aad20Sopenharmony_ci * 			  options, whether hard/softirqs are running, level of
18147c2aad20Sopenharmony_ci * 			  preempt_disabled respectively). **N** means that
18157c2aad20Sopenharmony_ci * 			  **TIF_NEED_RESCHED** and **PREEMPT_NEED_RESCHED**
18167c2aad20Sopenharmony_ci * 			  are set.
18177c2aad20Sopenharmony_ci * 			* ``419421.045894`` is a timestamp.
18187c2aad20Sopenharmony_ci * 			* ``0x00000001`` is a fake value used by BPF for the
18197c2aad20Sopenharmony_ci * 			  instruction pointer register.
18207c2aad20Sopenharmony_ci * 			* ``<formatted msg>`` is the message formatted with
18217c2aad20Sopenharmony_ci * 			  *fmt*.
18227c2aad20Sopenharmony_ci *
18237c2aad20Sopenharmony_ci * 		The conversion specifiers supported by *fmt* are similar, but
18247c2aad20Sopenharmony_ci * 		more limited than for printk(). They are **%d**, **%i**,
18257c2aad20Sopenharmony_ci * 		**%u**, **%x**, **%ld**, **%li**, **%lu**, **%lx**, **%lld**,
18267c2aad20Sopenharmony_ci * 		**%lli**, **%llu**, **%llx**, **%p**, **%s**. No modifier (size
18277c2aad20Sopenharmony_ci * 		of field, padding with zeroes, etc.) is available, and the
18287c2aad20Sopenharmony_ci * 		helper will return **-EINVAL** (but print nothing) if it
18297c2aad20Sopenharmony_ci * 		encounters an unknown specifier.
18307c2aad20Sopenharmony_ci *
18317c2aad20Sopenharmony_ci * 		Also, note that **bpf_trace_printk**\ () is slow, and should
18327c2aad20Sopenharmony_ci * 		only be used for debugging purposes. For this reason, a notice
18337c2aad20Sopenharmony_ci * 		block (spanning several lines) is printed to kernel logs and
18347c2aad20Sopenharmony_ci * 		states that the helper should not be used "for production use"
18357c2aad20Sopenharmony_ci * 		the first time this helper is used (or more precisely, when
18367c2aad20Sopenharmony_ci * 		**trace_printk**\ () buffers are allocated). For passing values
18377c2aad20Sopenharmony_ci * 		to user space, perf events should be preferred.
18387c2aad20Sopenharmony_ci * 	Return
18397c2aad20Sopenharmony_ci * 		The number of bytes written to the buffer, or a negative error
18407c2aad20Sopenharmony_ci * 		in case of failure.
18417c2aad20Sopenharmony_ci *
18427c2aad20Sopenharmony_ci * u32 bpf_get_prandom_u32(void)
18437c2aad20Sopenharmony_ci * 	Description
18447c2aad20Sopenharmony_ci * 		Get a pseudo-random number.
18457c2aad20Sopenharmony_ci *
18467c2aad20Sopenharmony_ci * 		From a security point of view, this helper uses its own
18477c2aad20Sopenharmony_ci * 		pseudo-random internal state, and cannot be used to infer the
18487c2aad20Sopenharmony_ci * 		seed of other random functions in the kernel. However, it is
18497c2aad20Sopenharmony_ci * 		essential to note that the generator used by the helper is not
18507c2aad20Sopenharmony_ci * 		cryptographically secure.
18517c2aad20Sopenharmony_ci * 	Return
18527c2aad20Sopenharmony_ci * 		A random 32-bit unsigned value.
18537c2aad20Sopenharmony_ci *
18547c2aad20Sopenharmony_ci * u32 bpf_get_smp_processor_id(void)
18557c2aad20Sopenharmony_ci * 	Description
18567c2aad20Sopenharmony_ci * 		Get the SMP (symmetric multiprocessing) processor id. Note that
18577c2aad20Sopenharmony_ci * 		all programs run with migration disabled, which means that the
18587c2aad20Sopenharmony_ci * 		SMP processor id is stable during all the execution of the
18597c2aad20Sopenharmony_ci * 		program.
18607c2aad20Sopenharmony_ci * 	Return
18617c2aad20Sopenharmony_ci * 		The SMP id of the processor running the program.
18627c2aad20Sopenharmony_ci *
18637c2aad20Sopenharmony_ci * long bpf_skb_store_bytes(struct sk_buff *skb, u32 offset, const void *from, u32 len, u64 flags)
18647c2aad20Sopenharmony_ci * 	Description
18657c2aad20Sopenharmony_ci * 		Store *len* bytes from address *from* into the packet
18667c2aad20Sopenharmony_ci * 		associated to *skb*, at *offset*. *flags* are a combination of
18677c2aad20Sopenharmony_ci * 		**BPF_F_RECOMPUTE_CSUM** (automatically recompute the
18687c2aad20Sopenharmony_ci * 		checksum for the packet after storing the bytes) and
18697c2aad20Sopenharmony_ci * 		**BPF_F_INVALIDATE_HASH** (set *skb*\ **->hash**, *skb*\
18707c2aad20Sopenharmony_ci * 		**->swhash** and *skb*\ **->l4hash** to 0).
18717c2aad20Sopenharmony_ci *
18727c2aad20Sopenharmony_ci * 		A call to this helper is susceptible to change the underlying
18737c2aad20Sopenharmony_ci * 		packet buffer. Therefore, at load time, all checks on pointers
18747c2aad20Sopenharmony_ci * 		previously done by the verifier are invalidated and must be
18757c2aad20Sopenharmony_ci * 		performed again, if the helper is used in combination with
18767c2aad20Sopenharmony_ci * 		direct packet access.
18777c2aad20Sopenharmony_ci * 	Return
18787c2aad20Sopenharmony_ci * 		0 on success, or a negative error in case of failure.
18797c2aad20Sopenharmony_ci *
18807c2aad20Sopenharmony_ci * long bpf_l3_csum_replace(struct sk_buff *skb, u32 offset, u64 from, u64 to, u64 size)
18817c2aad20Sopenharmony_ci * 	Description
18827c2aad20Sopenharmony_ci * 		Recompute the layer 3 (e.g. IP) checksum for the packet
18837c2aad20Sopenharmony_ci * 		associated to *skb*. Computation is incremental, so the helper
18847c2aad20Sopenharmony_ci * 		must know the former value of the header field that was
18857c2aad20Sopenharmony_ci * 		modified (*from*), the new value of this field (*to*), and the
18867c2aad20Sopenharmony_ci * 		number of bytes (2 or 4) for this field, stored in *size*.
18877c2aad20Sopenharmony_ci * 		Alternatively, it is possible to store the difference between
18887c2aad20Sopenharmony_ci * 		the previous and the new values of the header field in *to*, by
18897c2aad20Sopenharmony_ci * 		setting *from* and *size* to 0. For both methods, *offset*
18907c2aad20Sopenharmony_ci * 		indicates the location of the IP checksum within the packet.
18917c2aad20Sopenharmony_ci *
18927c2aad20Sopenharmony_ci * 		This helper works in combination with **bpf_csum_diff**\ (),
18937c2aad20Sopenharmony_ci * 		which does not update the checksum in-place, but offers more
18947c2aad20Sopenharmony_ci * 		flexibility and can handle sizes larger than 2 or 4 for the
18957c2aad20Sopenharmony_ci * 		checksum to update.
18967c2aad20Sopenharmony_ci *
18977c2aad20Sopenharmony_ci * 		A call to this helper is susceptible to change the underlying
18987c2aad20Sopenharmony_ci * 		packet buffer. Therefore, at load time, all checks on pointers
18997c2aad20Sopenharmony_ci * 		previously done by the verifier are invalidated and must be
19007c2aad20Sopenharmony_ci * 		performed again, if the helper is used in combination with
19017c2aad20Sopenharmony_ci * 		direct packet access.
19027c2aad20Sopenharmony_ci * 	Return
19037c2aad20Sopenharmony_ci * 		0 on success, or a negative error in case of failure.
19047c2aad20Sopenharmony_ci *
19057c2aad20Sopenharmony_ci * long bpf_l4_csum_replace(struct sk_buff *skb, u32 offset, u64 from, u64 to, u64 flags)
19067c2aad20Sopenharmony_ci * 	Description
19077c2aad20Sopenharmony_ci * 		Recompute the layer 4 (e.g. TCP, UDP or ICMP) checksum for the
19087c2aad20Sopenharmony_ci * 		packet associated to *skb*. Computation is incremental, so the
19097c2aad20Sopenharmony_ci * 		helper must know the former value of the header field that was
19107c2aad20Sopenharmony_ci * 		modified (*from*), the new value of this field (*to*), and the
19117c2aad20Sopenharmony_ci * 		number of bytes (2 or 4) for this field, stored on the lowest
19127c2aad20Sopenharmony_ci * 		four bits of *flags*. Alternatively, it is possible to store
19137c2aad20Sopenharmony_ci * 		the difference between the previous and the new values of the
19147c2aad20Sopenharmony_ci * 		header field in *to*, by setting *from* and the four lowest
19157c2aad20Sopenharmony_ci * 		bits of *flags* to 0. For both methods, *offset* indicates the
19167c2aad20Sopenharmony_ci * 		location of the IP checksum within the packet. In addition to
19177c2aad20Sopenharmony_ci * 		the size of the field, *flags* can be added (bitwise OR) actual
19187c2aad20Sopenharmony_ci * 		flags. With **BPF_F_MARK_MANGLED_0**, a null checksum is left
19197c2aad20Sopenharmony_ci * 		untouched (unless **BPF_F_MARK_ENFORCE** is added as well), and
19207c2aad20Sopenharmony_ci * 		for updates resulting in a null checksum the value is set to
19217c2aad20Sopenharmony_ci * 		**CSUM_MANGLED_0** instead. Flag **BPF_F_PSEUDO_HDR** indicates
19227c2aad20Sopenharmony_ci * 		the checksum is to be computed against a pseudo-header.
19237c2aad20Sopenharmony_ci *
19247c2aad20Sopenharmony_ci * 		This helper works in combination with **bpf_csum_diff**\ (),
19257c2aad20Sopenharmony_ci * 		which does not update the checksum in-place, but offers more
19267c2aad20Sopenharmony_ci * 		flexibility and can handle sizes larger than 2 or 4 for the
19277c2aad20Sopenharmony_ci * 		checksum to update.
19287c2aad20Sopenharmony_ci *
19297c2aad20Sopenharmony_ci * 		A call to this helper is susceptible to change the underlying
19307c2aad20Sopenharmony_ci * 		packet buffer. Therefore, at load time, all checks on pointers
19317c2aad20Sopenharmony_ci * 		previously done by the verifier are invalidated and must be
19327c2aad20Sopenharmony_ci * 		performed again, if the helper is used in combination with
19337c2aad20Sopenharmony_ci * 		direct packet access.
19347c2aad20Sopenharmony_ci * 	Return
19357c2aad20Sopenharmony_ci * 		0 on success, or a negative error in case of failure.
19367c2aad20Sopenharmony_ci *
19377c2aad20Sopenharmony_ci * long bpf_tail_call(void *ctx, struct bpf_map *prog_array_map, u32 index)
19387c2aad20Sopenharmony_ci * 	Description
19397c2aad20Sopenharmony_ci * 		This special helper is used to trigger a "tail call", or in
19407c2aad20Sopenharmony_ci * 		other words, to jump into another eBPF program. The same stack
19417c2aad20Sopenharmony_ci * 		frame is used (but values on stack and in registers for the
19427c2aad20Sopenharmony_ci * 		caller are not accessible to the callee). This mechanism allows
19437c2aad20Sopenharmony_ci * 		for program chaining, either for raising the maximum number of
19447c2aad20Sopenharmony_ci * 		available eBPF instructions, or to execute given programs in
19457c2aad20Sopenharmony_ci * 		conditional blocks. For security reasons, there is an upper
19467c2aad20Sopenharmony_ci * 		limit to the number of successive tail calls that can be
19477c2aad20Sopenharmony_ci * 		performed.
19487c2aad20Sopenharmony_ci *
19497c2aad20Sopenharmony_ci * 		Upon call of this helper, the program attempts to jump into a
19507c2aad20Sopenharmony_ci * 		program referenced at index *index* in *prog_array_map*, a
19517c2aad20Sopenharmony_ci * 		special map of type **BPF_MAP_TYPE_PROG_ARRAY**, and passes
19527c2aad20Sopenharmony_ci * 		*ctx*, a pointer to the context.
19537c2aad20Sopenharmony_ci *
19547c2aad20Sopenharmony_ci * 		If the call succeeds, the kernel immediately runs the first
19557c2aad20Sopenharmony_ci * 		instruction of the new program. This is not a function call,
19567c2aad20Sopenharmony_ci * 		and it never returns to the previous program. If the call
19577c2aad20Sopenharmony_ci * 		fails, then the helper has no effect, and the caller continues
19587c2aad20Sopenharmony_ci * 		to run its subsequent instructions. A call can fail if the
19597c2aad20Sopenharmony_ci * 		destination program for the jump does not exist (i.e. *index*
19607c2aad20Sopenharmony_ci * 		is superior to the number of entries in *prog_array_map*), or
19617c2aad20Sopenharmony_ci * 		if the maximum number of tail calls has been reached for this
19627c2aad20Sopenharmony_ci * 		chain of programs. This limit is defined in the kernel by the
19637c2aad20Sopenharmony_ci * 		macro **MAX_TAIL_CALL_CNT** (not accessible to user space),
19647c2aad20Sopenharmony_ci *		which is currently set to 33.
19657c2aad20Sopenharmony_ci * 	Return
19667c2aad20Sopenharmony_ci * 		0 on success, or a negative error in case of failure.
19677c2aad20Sopenharmony_ci *
19687c2aad20Sopenharmony_ci * long bpf_clone_redirect(struct sk_buff *skb, u32 ifindex, u64 flags)
19697c2aad20Sopenharmony_ci * 	Description
19707c2aad20Sopenharmony_ci * 		Clone and redirect the packet associated to *skb* to another
19717c2aad20Sopenharmony_ci * 		net device of index *ifindex*. Both ingress and egress
19727c2aad20Sopenharmony_ci * 		interfaces can be used for redirection. The **BPF_F_INGRESS**
19737c2aad20Sopenharmony_ci * 		value in *flags* is used to make the distinction (ingress path
19747c2aad20Sopenharmony_ci * 		is selected if the flag is present, egress path otherwise).
19757c2aad20Sopenharmony_ci * 		This is the only flag supported for now.
19767c2aad20Sopenharmony_ci *
19777c2aad20Sopenharmony_ci * 		In comparison with **bpf_redirect**\ () helper,
19787c2aad20Sopenharmony_ci * 		**bpf_clone_redirect**\ () has the associated cost of
19797c2aad20Sopenharmony_ci * 		duplicating the packet buffer, but this can be executed out of
19807c2aad20Sopenharmony_ci * 		the eBPF program. Conversely, **bpf_redirect**\ () is more
19817c2aad20Sopenharmony_ci * 		efficient, but it is handled through an action code where the
19827c2aad20Sopenharmony_ci * 		redirection happens only after the eBPF program has returned.
19837c2aad20Sopenharmony_ci *
19847c2aad20Sopenharmony_ci * 		A call to this helper is susceptible to change the underlying
19857c2aad20Sopenharmony_ci * 		packet buffer. Therefore, at load time, all checks on pointers
19867c2aad20Sopenharmony_ci * 		previously done by the verifier are invalidated and must be
19877c2aad20Sopenharmony_ci * 		performed again, if the helper is used in combination with
19887c2aad20Sopenharmony_ci * 		direct packet access.
19897c2aad20Sopenharmony_ci * 	Return
19907c2aad20Sopenharmony_ci * 		0 on success, or a negative error in case of failure. Positive
19917c2aad20Sopenharmony_ci * 		error indicates a potential drop or congestion in the target
19927c2aad20Sopenharmony_ci * 		device. The particular positive error codes are not defined.
19937c2aad20Sopenharmony_ci *
19947c2aad20Sopenharmony_ci * u64 bpf_get_current_pid_tgid(void)
19957c2aad20Sopenharmony_ci * 	Description
19967c2aad20Sopenharmony_ci * 		Get the current pid and tgid.
19977c2aad20Sopenharmony_ci * 	Return
19987c2aad20Sopenharmony_ci * 		A 64-bit integer containing the current tgid and pid, and
19997c2aad20Sopenharmony_ci * 		created as such:
20007c2aad20Sopenharmony_ci * 		*current_task*\ **->tgid << 32 \|**
20017c2aad20Sopenharmony_ci * 		*current_task*\ **->pid**.
20027c2aad20Sopenharmony_ci *
20037c2aad20Sopenharmony_ci * u64 bpf_get_current_uid_gid(void)
20047c2aad20Sopenharmony_ci * 	Description
20057c2aad20Sopenharmony_ci * 		Get the current uid and gid.
20067c2aad20Sopenharmony_ci * 	Return
20077c2aad20Sopenharmony_ci * 		A 64-bit integer containing the current GID and UID, and
20087c2aad20Sopenharmony_ci * 		created as such: *current_gid* **<< 32 \|** *current_uid*.
20097c2aad20Sopenharmony_ci *
20107c2aad20Sopenharmony_ci * long bpf_get_current_comm(void *buf, u32 size_of_buf)
20117c2aad20Sopenharmony_ci * 	Description
20127c2aad20Sopenharmony_ci * 		Copy the **comm** attribute of the current task into *buf* of
20137c2aad20Sopenharmony_ci * 		*size_of_buf*. The **comm** attribute contains the name of
20147c2aad20Sopenharmony_ci * 		the executable (excluding the path) for the current task. The
20157c2aad20Sopenharmony_ci * 		*size_of_buf* must be strictly positive. On success, the
20167c2aad20Sopenharmony_ci * 		helper makes sure that the *buf* is NUL-terminated. On failure,
20177c2aad20Sopenharmony_ci * 		it is filled with zeroes.
20187c2aad20Sopenharmony_ci * 	Return
20197c2aad20Sopenharmony_ci * 		0 on success, or a negative error in case of failure.
20207c2aad20Sopenharmony_ci *
20217c2aad20Sopenharmony_ci * u32 bpf_get_cgroup_classid(struct sk_buff *skb)
20227c2aad20Sopenharmony_ci * 	Description
20237c2aad20Sopenharmony_ci * 		Retrieve the classid for the current task, i.e. for the net_cls
20247c2aad20Sopenharmony_ci * 		cgroup to which *skb* belongs.
20257c2aad20Sopenharmony_ci *
20267c2aad20Sopenharmony_ci * 		This helper can be used on TC egress path, but not on ingress.
20277c2aad20Sopenharmony_ci *
20287c2aad20Sopenharmony_ci * 		The net_cls cgroup provides an interface to tag network packets
20297c2aad20Sopenharmony_ci * 		based on a user-provided identifier for all traffic coming from
20307c2aad20Sopenharmony_ci * 		the tasks belonging to the related cgroup. See also the related
20317c2aad20Sopenharmony_ci * 		kernel documentation, available from the Linux sources in file
20327c2aad20Sopenharmony_ci * 		*Documentation/admin-guide/cgroup-v1/net_cls.rst*.
20337c2aad20Sopenharmony_ci *
20347c2aad20Sopenharmony_ci * 		The Linux kernel has two versions for cgroups: there are
20357c2aad20Sopenharmony_ci * 		cgroups v1 and cgroups v2. Both are available to users, who can
20367c2aad20Sopenharmony_ci * 		use a mixture of them, but note that the net_cls cgroup is for
20377c2aad20Sopenharmony_ci * 		cgroup v1 only. This makes it incompatible with BPF programs
20387c2aad20Sopenharmony_ci * 		run on cgroups, which is a cgroup-v2-only feature (a socket can
20397c2aad20Sopenharmony_ci * 		only hold data for one version of cgroups at a time).
20407c2aad20Sopenharmony_ci *
20417c2aad20Sopenharmony_ci * 		This helper is only available is the kernel was compiled with
20427c2aad20Sopenharmony_ci * 		the **CONFIG_CGROUP_NET_CLASSID** configuration option set to
20437c2aad20Sopenharmony_ci * 		"**y**" or to "**m**".
20447c2aad20Sopenharmony_ci * 	Return
20457c2aad20Sopenharmony_ci * 		The classid, or 0 for the default unconfigured classid.
20467c2aad20Sopenharmony_ci *
20477c2aad20Sopenharmony_ci * long bpf_skb_vlan_push(struct sk_buff *skb, __be16 vlan_proto, u16 vlan_tci)
20487c2aad20Sopenharmony_ci * 	Description
20497c2aad20Sopenharmony_ci * 		Push a *vlan_tci* (VLAN tag control information) of protocol
20507c2aad20Sopenharmony_ci * 		*vlan_proto* to the packet associated to *skb*, then update
20517c2aad20Sopenharmony_ci * 		the checksum. Note that if *vlan_proto* is different from
20527c2aad20Sopenharmony_ci * 		**ETH_P_8021Q** and **ETH_P_8021AD**, it is considered to
20537c2aad20Sopenharmony_ci * 		be **ETH_P_8021Q**.
20547c2aad20Sopenharmony_ci *
20557c2aad20Sopenharmony_ci * 		A call to this helper is susceptible to change the underlying
20567c2aad20Sopenharmony_ci * 		packet buffer. Therefore, at load time, all checks on pointers
20577c2aad20Sopenharmony_ci * 		previously done by the verifier are invalidated and must be
20587c2aad20Sopenharmony_ci * 		performed again, if the helper is used in combination with
20597c2aad20Sopenharmony_ci * 		direct packet access.
20607c2aad20Sopenharmony_ci * 	Return
20617c2aad20Sopenharmony_ci * 		0 on success, or a negative error in case of failure.
20627c2aad20Sopenharmony_ci *
20637c2aad20Sopenharmony_ci * long bpf_skb_vlan_pop(struct sk_buff *skb)
20647c2aad20Sopenharmony_ci * 	Description
20657c2aad20Sopenharmony_ci * 		Pop a VLAN header from the packet associated to *skb*.
20667c2aad20Sopenharmony_ci *
20677c2aad20Sopenharmony_ci * 		A call to this helper is susceptible to change the underlying
20687c2aad20Sopenharmony_ci * 		packet buffer. Therefore, at load time, all checks on pointers
20697c2aad20Sopenharmony_ci * 		previously done by the verifier are invalidated and must be
20707c2aad20Sopenharmony_ci * 		performed again, if the helper is used in combination with
20717c2aad20Sopenharmony_ci * 		direct packet access.
20727c2aad20Sopenharmony_ci * 	Return
20737c2aad20Sopenharmony_ci * 		0 on success, or a negative error in case of failure.
20747c2aad20Sopenharmony_ci *
20757c2aad20Sopenharmony_ci * long bpf_skb_get_tunnel_key(struct sk_buff *skb, struct bpf_tunnel_key *key, u32 size, u64 flags)
20767c2aad20Sopenharmony_ci * 	Description
20777c2aad20Sopenharmony_ci * 		Get tunnel metadata. This helper takes a pointer *key* to an
20787c2aad20Sopenharmony_ci * 		empty **struct bpf_tunnel_key** of **size**, that will be
20797c2aad20Sopenharmony_ci * 		filled with tunnel metadata for the packet associated to *skb*.
20807c2aad20Sopenharmony_ci * 		The *flags* can be set to **BPF_F_TUNINFO_IPV6**, which
20817c2aad20Sopenharmony_ci * 		indicates that the tunnel is based on IPv6 protocol instead of
20827c2aad20Sopenharmony_ci * 		IPv4.
20837c2aad20Sopenharmony_ci *
20847c2aad20Sopenharmony_ci * 		The **struct bpf_tunnel_key** is an object that generalizes the
20857c2aad20Sopenharmony_ci * 		principal parameters used by various tunneling protocols into a
20867c2aad20Sopenharmony_ci * 		single struct. This way, it can be used to easily make a
20877c2aad20Sopenharmony_ci * 		decision based on the contents of the encapsulation header,
20887c2aad20Sopenharmony_ci * 		"summarized" in this struct. In particular, it holds the IP
20897c2aad20Sopenharmony_ci * 		address of the remote end (IPv4 or IPv6, depending on the case)
20907c2aad20Sopenharmony_ci * 		in *key*\ **->remote_ipv4** or *key*\ **->remote_ipv6**. Also,
20917c2aad20Sopenharmony_ci * 		this struct exposes the *key*\ **->tunnel_id**, which is
20927c2aad20Sopenharmony_ci * 		generally mapped to a VNI (Virtual Network Identifier), making
20937c2aad20Sopenharmony_ci * 		it programmable together with the **bpf_skb_set_tunnel_key**\
20947c2aad20Sopenharmony_ci * 		() helper.
20957c2aad20Sopenharmony_ci *
20967c2aad20Sopenharmony_ci * 		Let's imagine that the following code is part of a program
20977c2aad20Sopenharmony_ci * 		attached to the TC ingress interface, on one end of a GRE
20987c2aad20Sopenharmony_ci * 		tunnel, and is supposed to filter out all messages coming from
20997c2aad20Sopenharmony_ci * 		remote ends with IPv4 address other than 10.0.0.1:
21007c2aad20Sopenharmony_ci *
21017c2aad20Sopenharmony_ci * 		::
21027c2aad20Sopenharmony_ci *
21037c2aad20Sopenharmony_ci * 			int ret;
21047c2aad20Sopenharmony_ci * 			struct bpf_tunnel_key key = {};
21057c2aad20Sopenharmony_ci *
21067c2aad20Sopenharmony_ci * 			ret = bpf_skb_get_tunnel_key(skb, &key, sizeof(key), 0);
21077c2aad20Sopenharmony_ci * 			if (ret < 0)
21087c2aad20Sopenharmony_ci * 				return TC_ACT_SHOT;	// drop packet
21097c2aad20Sopenharmony_ci *
21107c2aad20Sopenharmony_ci * 			if (key.remote_ipv4 != 0x0a000001)
21117c2aad20Sopenharmony_ci * 				return TC_ACT_SHOT;	// drop packet
21127c2aad20Sopenharmony_ci *
21137c2aad20Sopenharmony_ci * 			return TC_ACT_OK;		// accept packet
21147c2aad20Sopenharmony_ci *
21157c2aad20Sopenharmony_ci * 		This interface can also be used with all encapsulation devices
21167c2aad20Sopenharmony_ci * 		that can operate in "collect metadata" mode: instead of having
21177c2aad20Sopenharmony_ci * 		one network device per specific configuration, the "collect
21187c2aad20Sopenharmony_ci * 		metadata" mode only requires a single device where the
21197c2aad20Sopenharmony_ci * 		configuration can be extracted from this helper.
21207c2aad20Sopenharmony_ci *
21217c2aad20Sopenharmony_ci * 		This can be used together with various tunnels such as VXLan,
21227c2aad20Sopenharmony_ci * 		Geneve, GRE or IP in IP (IPIP).
21237c2aad20Sopenharmony_ci * 	Return
21247c2aad20Sopenharmony_ci * 		0 on success, or a negative error in case of failure.
21257c2aad20Sopenharmony_ci *
21267c2aad20Sopenharmony_ci * long bpf_skb_set_tunnel_key(struct sk_buff *skb, struct bpf_tunnel_key *key, u32 size, u64 flags)
21277c2aad20Sopenharmony_ci * 	Description
21287c2aad20Sopenharmony_ci * 		Populate tunnel metadata for packet associated to *skb.* The
21297c2aad20Sopenharmony_ci * 		tunnel metadata is set to the contents of *key*, of *size*. The
21307c2aad20Sopenharmony_ci * 		*flags* can be set to a combination of the following values:
21317c2aad20Sopenharmony_ci *
21327c2aad20Sopenharmony_ci * 		**BPF_F_TUNINFO_IPV6**
21337c2aad20Sopenharmony_ci * 			Indicate that the tunnel is based on IPv6 protocol
21347c2aad20Sopenharmony_ci * 			instead of IPv4.
21357c2aad20Sopenharmony_ci * 		**BPF_F_ZERO_CSUM_TX**
21367c2aad20Sopenharmony_ci * 			For IPv4 packets, add a flag to tunnel metadata
21377c2aad20Sopenharmony_ci * 			indicating that checksum computation should be skipped
21387c2aad20Sopenharmony_ci * 			and checksum set to zeroes.
21397c2aad20Sopenharmony_ci * 		**BPF_F_DONT_FRAGMENT**
21407c2aad20Sopenharmony_ci * 			Add a flag to tunnel metadata indicating that the
21417c2aad20Sopenharmony_ci * 			packet should not be fragmented.
21427c2aad20Sopenharmony_ci * 		**BPF_F_SEQ_NUMBER**
21437c2aad20Sopenharmony_ci * 			Add a flag to tunnel metadata indicating that a
21447c2aad20Sopenharmony_ci * 			sequence number should be added to tunnel header before
21457c2aad20Sopenharmony_ci * 			sending the packet. This flag was added for GRE
21467c2aad20Sopenharmony_ci * 			encapsulation, but might be used with other protocols
21477c2aad20Sopenharmony_ci * 			as well in the future.
21487c2aad20Sopenharmony_ci * 		**BPF_F_NO_TUNNEL_KEY**
21497c2aad20Sopenharmony_ci * 			Add a flag to tunnel metadata indicating that no tunnel
21507c2aad20Sopenharmony_ci * 			key should be set in the resulting tunnel header.
21517c2aad20Sopenharmony_ci *
21527c2aad20Sopenharmony_ci * 		Here is a typical usage on the transmit path:
21537c2aad20Sopenharmony_ci *
21547c2aad20Sopenharmony_ci * 		::
21557c2aad20Sopenharmony_ci *
21567c2aad20Sopenharmony_ci * 			struct bpf_tunnel_key key;
21577c2aad20Sopenharmony_ci * 			     populate key ...
21587c2aad20Sopenharmony_ci * 			bpf_skb_set_tunnel_key(skb, &key, sizeof(key), 0);
21597c2aad20Sopenharmony_ci * 			bpf_clone_redirect(skb, vxlan_dev_ifindex, 0);
21607c2aad20Sopenharmony_ci *
21617c2aad20Sopenharmony_ci * 		See also the description of the **bpf_skb_get_tunnel_key**\ ()
21627c2aad20Sopenharmony_ci * 		helper for additional information.
21637c2aad20Sopenharmony_ci * 	Return
21647c2aad20Sopenharmony_ci * 		0 on success, or a negative error in case of failure.
21657c2aad20Sopenharmony_ci *
21667c2aad20Sopenharmony_ci * u64 bpf_perf_event_read(struct bpf_map *map, u64 flags)
21677c2aad20Sopenharmony_ci * 	Description
21687c2aad20Sopenharmony_ci * 		Read the value of a perf event counter. This helper relies on a
21697c2aad20Sopenharmony_ci * 		*map* of type **BPF_MAP_TYPE_PERF_EVENT_ARRAY**. The nature of
21707c2aad20Sopenharmony_ci * 		the perf event counter is selected when *map* is updated with
21717c2aad20Sopenharmony_ci * 		perf event file descriptors. The *map* is an array whose size
21727c2aad20Sopenharmony_ci * 		is the number of available CPUs, and each cell contains a value
21737c2aad20Sopenharmony_ci * 		relative to one CPU. The value to retrieve is indicated by
21747c2aad20Sopenharmony_ci * 		*flags*, that contains the index of the CPU to look up, masked
21757c2aad20Sopenharmony_ci * 		with **BPF_F_INDEX_MASK**. Alternatively, *flags* can be set to
21767c2aad20Sopenharmony_ci * 		**BPF_F_CURRENT_CPU** to indicate that the value for the
21777c2aad20Sopenharmony_ci * 		current CPU should be retrieved.
21787c2aad20Sopenharmony_ci *
21797c2aad20Sopenharmony_ci * 		Note that before Linux 4.13, only hardware perf event can be
21807c2aad20Sopenharmony_ci * 		retrieved.
21817c2aad20Sopenharmony_ci *
21827c2aad20Sopenharmony_ci * 		Also, be aware that the newer helper
21837c2aad20Sopenharmony_ci * 		**bpf_perf_event_read_value**\ () is recommended over
21847c2aad20Sopenharmony_ci * 		**bpf_perf_event_read**\ () in general. The latter has some ABI
21857c2aad20Sopenharmony_ci * 		quirks where error and counter value are used as a return code
21867c2aad20Sopenharmony_ci * 		(which is wrong to do since ranges may overlap). This issue is
21877c2aad20Sopenharmony_ci * 		fixed with **bpf_perf_event_read_value**\ (), which at the same
21887c2aad20Sopenharmony_ci * 		time provides more features over the **bpf_perf_event_read**\
21897c2aad20Sopenharmony_ci * 		() interface. Please refer to the description of
21907c2aad20Sopenharmony_ci * 		**bpf_perf_event_read_value**\ () for details.
21917c2aad20Sopenharmony_ci * 	Return
21927c2aad20Sopenharmony_ci * 		The value of the perf event counter read from the map, or a
21937c2aad20Sopenharmony_ci * 		negative error code in case of failure.
21947c2aad20Sopenharmony_ci *
21957c2aad20Sopenharmony_ci * long bpf_redirect(u32 ifindex, u64 flags)
21967c2aad20Sopenharmony_ci * 	Description
21977c2aad20Sopenharmony_ci * 		Redirect the packet to another net device of index *ifindex*.
21987c2aad20Sopenharmony_ci * 		This helper is somewhat similar to **bpf_clone_redirect**\
21997c2aad20Sopenharmony_ci * 		(), except that the packet is not cloned, which provides
22007c2aad20Sopenharmony_ci * 		increased performance.
22017c2aad20Sopenharmony_ci *
22027c2aad20Sopenharmony_ci * 		Except for XDP, both ingress and egress interfaces can be used
22037c2aad20Sopenharmony_ci * 		for redirection. The **BPF_F_INGRESS** value in *flags* is used
22047c2aad20Sopenharmony_ci * 		to make the distinction (ingress path is selected if the flag
22057c2aad20Sopenharmony_ci * 		is present, egress path otherwise). Currently, XDP only
22067c2aad20Sopenharmony_ci * 		supports redirection to the egress interface, and accepts no
22077c2aad20Sopenharmony_ci * 		flag at all.
22087c2aad20Sopenharmony_ci *
22097c2aad20Sopenharmony_ci * 		The same effect can also be attained with the more generic
22107c2aad20Sopenharmony_ci * 		**bpf_redirect_map**\ (), which uses a BPF map to store the
22117c2aad20Sopenharmony_ci * 		redirect target instead of providing it directly to the helper.
22127c2aad20Sopenharmony_ci * 	Return
22137c2aad20Sopenharmony_ci * 		For XDP, the helper returns **XDP_REDIRECT** on success or
22147c2aad20Sopenharmony_ci * 		**XDP_ABORTED** on error. For other program types, the values
22157c2aad20Sopenharmony_ci * 		are **TC_ACT_REDIRECT** on success or **TC_ACT_SHOT** on
22167c2aad20Sopenharmony_ci * 		error.
22177c2aad20Sopenharmony_ci *
22187c2aad20Sopenharmony_ci * u32 bpf_get_route_realm(struct sk_buff *skb)
22197c2aad20Sopenharmony_ci * 	Description
22207c2aad20Sopenharmony_ci * 		Retrieve the realm or the route, that is to say the
22217c2aad20Sopenharmony_ci * 		**tclassid** field of the destination for the *skb*. The
22227c2aad20Sopenharmony_ci * 		identifier retrieved is a user-provided tag, similar to the
22237c2aad20Sopenharmony_ci * 		one used with the net_cls cgroup (see description for
22247c2aad20Sopenharmony_ci * 		**bpf_get_cgroup_classid**\ () helper), but here this tag is
22257c2aad20Sopenharmony_ci * 		held by a route (a destination entry), not by a task.
22267c2aad20Sopenharmony_ci *
22277c2aad20Sopenharmony_ci * 		Retrieving this identifier works with the clsact TC egress hook
22287c2aad20Sopenharmony_ci * 		(see also **tc-bpf(8)**), or alternatively on conventional
22297c2aad20Sopenharmony_ci * 		classful egress qdiscs, but not on TC ingress path. In case of
22307c2aad20Sopenharmony_ci * 		clsact TC egress hook, this has the advantage that, internally,
22317c2aad20Sopenharmony_ci * 		the destination entry has not been dropped yet in the transmit
22327c2aad20Sopenharmony_ci * 		path. Therefore, the destination entry does not need to be
22337c2aad20Sopenharmony_ci * 		artificially held via **netif_keep_dst**\ () for a classful
22347c2aad20Sopenharmony_ci * 		qdisc until the *skb* is freed.
22357c2aad20Sopenharmony_ci *
22367c2aad20Sopenharmony_ci * 		This helper is available only if the kernel was compiled with
22377c2aad20Sopenharmony_ci * 		**CONFIG_IP_ROUTE_CLASSID** configuration option.
22387c2aad20Sopenharmony_ci * 	Return
22397c2aad20Sopenharmony_ci * 		The realm of the route for the packet associated to *skb*, or 0
22407c2aad20Sopenharmony_ci * 		if none was found.
22417c2aad20Sopenharmony_ci *
22427c2aad20Sopenharmony_ci * long bpf_perf_event_output(void *ctx, struct bpf_map *map, u64 flags, void *data, u64 size)
22437c2aad20Sopenharmony_ci * 	Description
22447c2aad20Sopenharmony_ci * 		Write raw *data* blob into a special BPF perf event held by
22457c2aad20Sopenharmony_ci * 		*map* of type **BPF_MAP_TYPE_PERF_EVENT_ARRAY**. This perf
22467c2aad20Sopenharmony_ci * 		event must have the following attributes: **PERF_SAMPLE_RAW**
22477c2aad20Sopenharmony_ci * 		as **sample_type**, **PERF_TYPE_SOFTWARE** as **type**, and
22487c2aad20Sopenharmony_ci * 		**PERF_COUNT_SW_BPF_OUTPUT** as **config**.
22497c2aad20Sopenharmony_ci *
22507c2aad20Sopenharmony_ci * 		The *flags* are used to indicate the index in *map* for which
22517c2aad20Sopenharmony_ci * 		the value must be put, masked with **BPF_F_INDEX_MASK**.
22527c2aad20Sopenharmony_ci * 		Alternatively, *flags* can be set to **BPF_F_CURRENT_CPU**
22537c2aad20Sopenharmony_ci * 		to indicate that the index of the current CPU core should be
22547c2aad20Sopenharmony_ci * 		used.
22557c2aad20Sopenharmony_ci *
22567c2aad20Sopenharmony_ci * 		The value to write, of *size*, is passed through eBPF stack and
22577c2aad20Sopenharmony_ci * 		pointed by *data*.
22587c2aad20Sopenharmony_ci *
22597c2aad20Sopenharmony_ci * 		The context of the program *ctx* needs also be passed to the
22607c2aad20Sopenharmony_ci * 		helper.
22617c2aad20Sopenharmony_ci *
22627c2aad20Sopenharmony_ci * 		On user space, a program willing to read the values needs to
22637c2aad20Sopenharmony_ci * 		call **perf_event_open**\ () on the perf event (either for
22647c2aad20Sopenharmony_ci * 		one or for all CPUs) and to store the file descriptor into the
22657c2aad20Sopenharmony_ci * 		*map*. This must be done before the eBPF program can send data
22667c2aad20Sopenharmony_ci * 		into it. An example is available in file
22677c2aad20Sopenharmony_ci * 		*samples/bpf/trace_output_user.c* in the Linux kernel source
22687c2aad20Sopenharmony_ci * 		tree (the eBPF program counterpart is in
22697c2aad20Sopenharmony_ci * 		*samples/bpf/trace_output_kern.c*).
22707c2aad20Sopenharmony_ci *
22717c2aad20Sopenharmony_ci * 		**bpf_perf_event_output**\ () achieves better performance
22727c2aad20Sopenharmony_ci * 		than **bpf_trace_printk**\ () for sharing data with user
22737c2aad20Sopenharmony_ci * 		space, and is much better suitable for streaming data from eBPF
22747c2aad20Sopenharmony_ci * 		programs.
22757c2aad20Sopenharmony_ci *
22767c2aad20Sopenharmony_ci * 		Note that this helper is not restricted to tracing use cases
22777c2aad20Sopenharmony_ci * 		and can be used with programs attached to TC or XDP as well,
22787c2aad20Sopenharmony_ci * 		where it allows for passing data to user space listeners. Data
22797c2aad20Sopenharmony_ci * 		can be:
22807c2aad20Sopenharmony_ci *
22817c2aad20Sopenharmony_ci * 		* Only custom structs,
22827c2aad20Sopenharmony_ci * 		* Only the packet payload, or
22837c2aad20Sopenharmony_ci * 		* A combination of both.
22847c2aad20Sopenharmony_ci * 	Return
22857c2aad20Sopenharmony_ci * 		0 on success, or a negative error in case of failure.
22867c2aad20Sopenharmony_ci *
22877c2aad20Sopenharmony_ci * long bpf_skb_load_bytes(const void *skb, u32 offset, void *to, u32 len)
22887c2aad20Sopenharmony_ci * 	Description
22897c2aad20Sopenharmony_ci * 		This helper was provided as an easy way to load data from a
22907c2aad20Sopenharmony_ci * 		packet. It can be used to load *len* bytes from *offset* from
22917c2aad20Sopenharmony_ci * 		the packet associated to *skb*, into the buffer pointed by
22927c2aad20Sopenharmony_ci * 		*to*.
22937c2aad20Sopenharmony_ci *
22947c2aad20Sopenharmony_ci * 		Since Linux 4.7, usage of this helper has mostly been replaced
22957c2aad20Sopenharmony_ci * 		by "direct packet access", enabling packet data to be
22967c2aad20Sopenharmony_ci * 		manipulated with *skb*\ **->data** and *skb*\ **->data_end**
22977c2aad20Sopenharmony_ci * 		pointing respectively to the first byte of packet data and to
22987c2aad20Sopenharmony_ci * 		the byte after the last byte of packet data. However, it
22997c2aad20Sopenharmony_ci * 		remains useful if one wishes to read large quantities of data
23007c2aad20Sopenharmony_ci * 		at once from a packet into the eBPF stack.
23017c2aad20Sopenharmony_ci * 	Return
23027c2aad20Sopenharmony_ci * 		0 on success, or a negative error in case of failure.
23037c2aad20Sopenharmony_ci *
23047c2aad20Sopenharmony_ci * long bpf_get_stackid(void *ctx, struct bpf_map *map, u64 flags)
23057c2aad20Sopenharmony_ci * 	Description
23067c2aad20Sopenharmony_ci * 		Walk a user or a kernel stack and return its id. To achieve
23077c2aad20Sopenharmony_ci * 		this, the helper needs *ctx*, which is a pointer to the context
23087c2aad20Sopenharmony_ci * 		on which the tracing program is executed, and a pointer to a
23097c2aad20Sopenharmony_ci * 		*map* of type **BPF_MAP_TYPE_STACK_TRACE**.
23107c2aad20Sopenharmony_ci *
23117c2aad20Sopenharmony_ci * 		The last argument, *flags*, holds the number of stack frames to
23127c2aad20Sopenharmony_ci * 		skip (from 0 to 255), masked with
23137c2aad20Sopenharmony_ci * 		**BPF_F_SKIP_FIELD_MASK**. The next bits can be used to set
23147c2aad20Sopenharmony_ci * 		a combination of the following flags:
23157c2aad20Sopenharmony_ci *
23167c2aad20Sopenharmony_ci * 		**BPF_F_USER_STACK**
23177c2aad20Sopenharmony_ci * 			Collect a user space stack instead of a kernel stack.
23187c2aad20Sopenharmony_ci * 		**BPF_F_FAST_STACK_CMP**
23197c2aad20Sopenharmony_ci * 			Compare stacks by hash only.
23207c2aad20Sopenharmony_ci * 		**BPF_F_REUSE_STACKID**
23217c2aad20Sopenharmony_ci * 			If two different stacks hash into the same *stackid*,
23227c2aad20Sopenharmony_ci * 			discard the old one.
23237c2aad20Sopenharmony_ci *
23247c2aad20Sopenharmony_ci * 		The stack id retrieved is a 32 bit long integer handle which
23257c2aad20Sopenharmony_ci * 		can be further combined with other data (including other stack
23267c2aad20Sopenharmony_ci * 		ids) and used as a key into maps. This can be useful for
23277c2aad20Sopenharmony_ci * 		generating a variety of graphs (such as flame graphs or off-cpu
23287c2aad20Sopenharmony_ci * 		graphs).
23297c2aad20Sopenharmony_ci *
23307c2aad20Sopenharmony_ci * 		For walking a stack, this helper is an improvement over
23317c2aad20Sopenharmony_ci * 		**bpf_probe_read**\ (), which can be used with unrolled loops
23327c2aad20Sopenharmony_ci * 		but is not efficient and consumes a lot of eBPF instructions.
23337c2aad20Sopenharmony_ci * 		Instead, **bpf_get_stackid**\ () can collect up to
23347c2aad20Sopenharmony_ci * 		**PERF_MAX_STACK_DEPTH** both kernel and user frames. Note that
23357c2aad20Sopenharmony_ci * 		this limit can be controlled with the **sysctl** program, and
23367c2aad20Sopenharmony_ci * 		that it should be manually increased in order to profile long
23377c2aad20Sopenharmony_ci * 		user stacks (such as stacks for Java programs). To do so, use:
23387c2aad20Sopenharmony_ci *
23397c2aad20Sopenharmony_ci * 		::
23407c2aad20Sopenharmony_ci *
23417c2aad20Sopenharmony_ci * 			# sysctl kernel.perf_event_max_stack=<new value>
23427c2aad20Sopenharmony_ci * 	Return
23437c2aad20Sopenharmony_ci * 		The positive or null stack id on success, or a negative error
23447c2aad20Sopenharmony_ci * 		in case of failure.
23457c2aad20Sopenharmony_ci *
23467c2aad20Sopenharmony_ci * s64 bpf_csum_diff(__be32 *from, u32 from_size, __be32 *to, u32 to_size, __wsum seed)
23477c2aad20Sopenharmony_ci * 	Description
23487c2aad20Sopenharmony_ci * 		Compute a checksum difference, from the raw buffer pointed by
23497c2aad20Sopenharmony_ci * 		*from*, of length *from_size* (that must be a multiple of 4),
23507c2aad20Sopenharmony_ci * 		towards the raw buffer pointed by *to*, of size *to_size*
23517c2aad20Sopenharmony_ci * 		(same remark). An optional *seed* can be added to the value
23527c2aad20Sopenharmony_ci * 		(this can be cascaded, the seed may come from a previous call
23537c2aad20Sopenharmony_ci * 		to the helper).
23547c2aad20Sopenharmony_ci *
23557c2aad20Sopenharmony_ci * 		This is flexible enough to be used in several ways:
23567c2aad20Sopenharmony_ci *
23577c2aad20Sopenharmony_ci * 		* With *from_size* == 0, *to_size* > 0 and *seed* set to
23587c2aad20Sopenharmony_ci * 		  checksum, it can be used when pushing new data.
23597c2aad20Sopenharmony_ci * 		* With *from_size* > 0, *to_size* == 0 and *seed* set to
23607c2aad20Sopenharmony_ci * 		  checksum, it can be used when removing data from a packet.
23617c2aad20Sopenharmony_ci * 		* With *from_size* > 0, *to_size* > 0 and *seed* set to 0, it
23627c2aad20Sopenharmony_ci * 		  can be used to compute a diff. Note that *from_size* and
23637c2aad20Sopenharmony_ci * 		  *to_size* do not need to be equal.
23647c2aad20Sopenharmony_ci *
23657c2aad20Sopenharmony_ci * 		This helper can be used in combination with
23667c2aad20Sopenharmony_ci * 		**bpf_l3_csum_replace**\ () and **bpf_l4_csum_replace**\ (), to
23677c2aad20Sopenharmony_ci * 		which one can feed in the difference computed with
23687c2aad20Sopenharmony_ci * 		**bpf_csum_diff**\ ().
23697c2aad20Sopenharmony_ci * 	Return
23707c2aad20Sopenharmony_ci * 		The checksum result, or a negative error code in case of
23717c2aad20Sopenharmony_ci * 		failure.
23727c2aad20Sopenharmony_ci *
23737c2aad20Sopenharmony_ci * long bpf_skb_get_tunnel_opt(struct sk_buff *skb, void *opt, u32 size)
23747c2aad20Sopenharmony_ci * 	Description
23757c2aad20Sopenharmony_ci * 		Retrieve tunnel options metadata for the packet associated to
23767c2aad20Sopenharmony_ci * 		*skb*, and store the raw tunnel option data to the buffer *opt*
23777c2aad20Sopenharmony_ci * 		of *size*.
23787c2aad20Sopenharmony_ci *
23797c2aad20Sopenharmony_ci * 		This helper can be used with encapsulation devices that can
23807c2aad20Sopenharmony_ci * 		operate in "collect metadata" mode (please refer to the related
23817c2aad20Sopenharmony_ci * 		note in the description of **bpf_skb_get_tunnel_key**\ () for
23827c2aad20Sopenharmony_ci * 		more details). A particular example where this can be used is
23837c2aad20Sopenharmony_ci * 		in combination with the Geneve encapsulation protocol, where it
23847c2aad20Sopenharmony_ci * 		allows for pushing (with **bpf_skb_get_tunnel_opt**\ () helper)
23857c2aad20Sopenharmony_ci * 		and retrieving arbitrary TLVs (Type-Length-Value headers) from
23867c2aad20Sopenharmony_ci * 		the eBPF program. This allows for full customization of these
23877c2aad20Sopenharmony_ci * 		headers.
23887c2aad20Sopenharmony_ci * 	Return
23897c2aad20Sopenharmony_ci * 		The size of the option data retrieved.
23907c2aad20Sopenharmony_ci *
23917c2aad20Sopenharmony_ci * long bpf_skb_set_tunnel_opt(struct sk_buff *skb, void *opt, u32 size)
23927c2aad20Sopenharmony_ci * 	Description
23937c2aad20Sopenharmony_ci * 		Set tunnel options metadata for the packet associated to *skb*
23947c2aad20Sopenharmony_ci * 		to the option data contained in the raw buffer *opt* of *size*.
23957c2aad20Sopenharmony_ci *
23967c2aad20Sopenharmony_ci * 		See also the description of the **bpf_skb_get_tunnel_opt**\ ()
23977c2aad20Sopenharmony_ci * 		helper for additional information.
23987c2aad20Sopenharmony_ci * 	Return
23997c2aad20Sopenharmony_ci * 		0 on success, or a negative error in case of failure.
24007c2aad20Sopenharmony_ci *
24017c2aad20Sopenharmony_ci * long bpf_skb_change_proto(struct sk_buff *skb, __be16 proto, u64 flags)
24027c2aad20Sopenharmony_ci * 	Description
24037c2aad20Sopenharmony_ci * 		Change the protocol of the *skb* to *proto*. Currently
24047c2aad20Sopenharmony_ci * 		supported are transition from IPv4 to IPv6, and from IPv6 to
24057c2aad20Sopenharmony_ci * 		IPv4. The helper takes care of the groundwork for the
24067c2aad20Sopenharmony_ci * 		transition, including resizing the socket buffer. The eBPF
24077c2aad20Sopenharmony_ci * 		program is expected to fill the new headers, if any, via
24087c2aad20Sopenharmony_ci * 		**skb_store_bytes**\ () and to recompute the checksums with
24097c2aad20Sopenharmony_ci * 		**bpf_l3_csum_replace**\ () and **bpf_l4_csum_replace**\
24107c2aad20Sopenharmony_ci * 		(). The main case for this helper is to perform NAT64
24117c2aad20Sopenharmony_ci * 		operations out of an eBPF program.
24127c2aad20Sopenharmony_ci *
24137c2aad20Sopenharmony_ci * 		Internally, the GSO type is marked as dodgy so that headers are
24147c2aad20Sopenharmony_ci * 		checked and segments are recalculated by the GSO/GRO engine.
24157c2aad20Sopenharmony_ci * 		The size for GSO target is adapted as well.
24167c2aad20Sopenharmony_ci *
24177c2aad20Sopenharmony_ci * 		All values for *flags* are reserved for future usage, and must
24187c2aad20Sopenharmony_ci * 		be left at zero.
24197c2aad20Sopenharmony_ci *
24207c2aad20Sopenharmony_ci * 		A call to this helper is susceptible to change the underlying
24217c2aad20Sopenharmony_ci * 		packet buffer. Therefore, at load time, all checks on pointers
24227c2aad20Sopenharmony_ci * 		previously done by the verifier are invalidated and must be
24237c2aad20Sopenharmony_ci * 		performed again, if the helper is used in combination with
24247c2aad20Sopenharmony_ci * 		direct packet access.
24257c2aad20Sopenharmony_ci * 	Return
24267c2aad20Sopenharmony_ci * 		0 on success, or a negative error in case of failure.
24277c2aad20Sopenharmony_ci *
24287c2aad20Sopenharmony_ci * long bpf_skb_change_type(struct sk_buff *skb, u32 type)
24297c2aad20Sopenharmony_ci * 	Description
24307c2aad20Sopenharmony_ci * 		Change the packet type for the packet associated to *skb*. This
24317c2aad20Sopenharmony_ci * 		comes down to setting *skb*\ **->pkt_type** to *type*, except
24327c2aad20Sopenharmony_ci * 		the eBPF program does not have a write access to *skb*\
24337c2aad20Sopenharmony_ci * 		**->pkt_type** beside this helper. Using a helper here allows
24347c2aad20Sopenharmony_ci * 		for graceful handling of errors.
24357c2aad20Sopenharmony_ci *
24367c2aad20Sopenharmony_ci * 		The major use case is to change incoming *skb*s to
24377c2aad20Sopenharmony_ci * 		**PACKET_HOST** in a programmatic way instead of having to
24387c2aad20Sopenharmony_ci * 		recirculate via **redirect**\ (..., **BPF_F_INGRESS**), for
24397c2aad20Sopenharmony_ci * 		example.
24407c2aad20Sopenharmony_ci *
24417c2aad20Sopenharmony_ci * 		Note that *type* only allows certain values. At this time, they
24427c2aad20Sopenharmony_ci * 		are:
24437c2aad20Sopenharmony_ci *
24447c2aad20Sopenharmony_ci * 		**PACKET_HOST**
24457c2aad20Sopenharmony_ci * 			Packet is for us.
24467c2aad20Sopenharmony_ci * 		**PACKET_BROADCAST**
24477c2aad20Sopenharmony_ci * 			Send packet to all.
24487c2aad20Sopenharmony_ci * 		**PACKET_MULTICAST**
24497c2aad20Sopenharmony_ci * 			Send packet to group.
24507c2aad20Sopenharmony_ci * 		**PACKET_OTHERHOST**
24517c2aad20Sopenharmony_ci * 			Send packet to someone else.
24527c2aad20Sopenharmony_ci * 	Return
24537c2aad20Sopenharmony_ci * 		0 on success, or a negative error in case of failure.
24547c2aad20Sopenharmony_ci *
24557c2aad20Sopenharmony_ci * long bpf_skb_under_cgroup(struct sk_buff *skb, struct bpf_map *map, u32 index)
24567c2aad20Sopenharmony_ci * 	Description
24577c2aad20Sopenharmony_ci * 		Check whether *skb* is a descendant of the cgroup2 held by
24587c2aad20Sopenharmony_ci * 		*map* of type **BPF_MAP_TYPE_CGROUP_ARRAY**, at *index*.
24597c2aad20Sopenharmony_ci * 	Return
24607c2aad20Sopenharmony_ci * 		The return value depends on the result of the test, and can be:
24617c2aad20Sopenharmony_ci *
24627c2aad20Sopenharmony_ci * 		* 0, if the *skb* failed the cgroup2 descendant test.
24637c2aad20Sopenharmony_ci * 		* 1, if the *skb* succeeded the cgroup2 descendant test.
24647c2aad20Sopenharmony_ci * 		* A negative error code, if an error occurred.
24657c2aad20Sopenharmony_ci *
24667c2aad20Sopenharmony_ci * u32 bpf_get_hash_recalc(struct sk_buff *skb)
24677c2aad20Sopenharmony_ci * 	Description
24687c2aad20Sopenharmony_ci * 		Retrieve the hash of the packet, *skb*\ **->hash**. If it is
24697c2aad20Sopenharmony_ci * 		not set, in particular if the hash was cleared due to mangling,
24707c2aad20Sopenharmony_ci * 		recompute this hash. Later accesses to the hash can be done
24717c2aad20Sopenharmony_ci * 		directly with *skb*\ **->hash**.
24727c2aad20Sopenharmony_ci *
24737c2aad20Sopenharmony_ci * 		Calling **bpf_set_hash_invalid**\ (), changing a packet
24747c2aad20Sopenharmony_ci * 		prototype with **bpf_skb_change_proto**\ (), or calling
24757c2aad20Sopenharmony_ci * 		**bpf_skb_store_bytes**\ () with the
24767c2aad20Sopenharmony_ci * 		**BPF_F_INVALIDATE_HASH** are actions susceptible to clear
24777c2aad20Sopenharmony_ci * 		the hash and to trigger a new computation for the next call to
24787c2aad20Sopenharmony_ci * 		**bpf_get_hash_recalc**\ ().
24797c2aad20Sopenharmony_ci * 	Return
24807c2aad20Sopenharmony_ci * 		The 32-bit hash.
24817c2aad20Sopenharmony_ci *
24827c2aad20Sopenharmony_ci * u64 bpf_get_current_task(void)
24837c2aad20Sopenharmony_ci * 	Description
24847c2aad20Sopenharmony_ci * 		Get the current task.
24857c2aad20Sopenharmony_ci * 	Return
24867c2aad20Sopenharmony_ci * 		A pointer to the current task struct.
24877c2aad20Sopenharmony_ci *
24887c2aad20Sopenharmony_ci * long bpf_probe_write_user(void *dst, const void *src, u32 len)
24897c2aad20Sopenharmony_ci * 	Description
24907c2aad20Sopenharmony_ci * 		Attempt in a safe way to write *len* bytes from the buffer
24917c2aad20Sopenharmony_ci * 		*src* to *dst* in memory. It only works for threads that are in
24927c2aad20Sopenharmony_ci * 		user context, and *dst* must be a valid user space address.
24937c2aad20Sopenharmony_ci *
24947c2aad20Sopenharmony_ci * 		This helper should not be used to implement any kind of
24957c2aad20Sopenharmony_ci * 		security mechanism because of TOC-TOU attacks, but rather to
24967c2aad20Sopenharmony_ci * 		debug, divert, and manipulate execution of semi-cooperative
24977c2aad20Sopenharmony_ci * 		processes.
24987c2aad20Sopenharmony_ci *
24997c2aad20Sopenharmony_ci * 		Keep in mind that this feature is meant for experiments, and it
25007c2aad20Sopenharmony_ci * 		has a risk of crashing the system and running programs.
25017c2aad20Sopenharmony_ci * 		Therefore, when an eBPF program using this helper is attached,
25027c2aad20Sopenharmony_ci * 		a warning including PID and process name is printed to kernel
25037c2aad20Sopenharmony_ci * 		logs.
25047c2aad20Sopenharmony_ci * 	Return
25057c2aad20Sopenharmony_ci * 		0 on success, or a negative error in case of failure.
25067c2aad20Sopenharmony_ci *
25077c2aad20Sopenharmony_ci * long bpf_current_task_under_cgroup(struct bpf_map *map, u32 index)
25087c2aad20Sopenharmony_ci * 	Description
25097c2aad20Sopenharmony_ci * 		Check whether the probe is being run is the context of a given
25107c2aad20Sopenharmony_ci * 		subset of the cgroup2 hierarchy. The cgroup2 to test is held by
25117c2aad20Sopenharmony_ci * 		*map* of type **BPF_MAP_TYPE_CGROUP_ARRAY**, at *index*.
25127c2aad20Sopenharmony_ci * 	Return
25137c2aad20Sopenharmony_ci * 		The return value depends on the result of the test, and can be:
25147c2aad20Sopenharmony_ci *
25157c2aad20Sopenharmony_ci *		* 1, if current task belongs to the cgroup2.
25167c2aad20Sopenharmony_ci *		* 0, if current task does not belong to the cgroup2.
25177c2aad20Sopenharmony_ci * 		* A negative error code, if an error occurred.
25187c2aad20Sopenharmony_ci *
25197c2aad20Sopenharmony_ci * long bpf_skb_change_tail(struct sk_buff *skb, u32 len, u64 flags)
25207c2aad20Sopenharmony_ci * 	Description
25217c2aad20Sopenharmony_ci * 		Resize (trim or grow) the packet associated to *skb* to the
25227c2aad20Sopenharmony_ci * 		new *len*. The *flags* are reserved for future usage, and must
25237c2aad20Sopenharmony_ci * 		be left at zero.
25247c2aad20Sopenharmony_ci *
25257c2aad20Sopenharmony_ci * 		The basic idea is that the helper performs the needed work to
25267c2aad20Sopenharmony_ci * 		change the size of the packet, then the eBPF program rewrites
25277c2aad20Sopenharmony_ci * 		the rest via helpers like **bpf_skb_store_bytes**\ (),
25287c2aad20Sopenharmony_ci * 		**bpf_l3_csum_replace**\ (), **bpf_l3_csum_replace**\ ()
25297c2aad20Sopenharmony_ci * 		and others. This helper is a slow path utility intended for
25307c2aad20Sopenharmony_ci * 		replies with control messages. And because it is targeted for
25317c2aad20Sopenharmony_ci * 		slow path, the helper itself can afford to be slow: it
25327c2aad20Sopenharmony_ci * 		implicitly linearizes, unclones and drops offloads from the
25337c2aad20Sopenharmony_ci * 		*skb*.
25347c2aad20Sopenharmony_ci *
25357c2aad20Sopenharmony_ci * 		A call to this helper is susceptible to change the underlying
25367c2aad20Sopenharmony_ci * 		packet buffer. Therefore, at load time, all checks on pointers
25377c2aad20Sopenharmony_ci * 		previously done by the verifier are invalidated and must be
25387c2aad20Sopenharmony_ci * 		performed again, if the helper is used in combination with
25397c2aad20Sopenharmony_ci * 		direct packet access.
25407c2aad20Sopenharmony_ci * 	Return
25417c2aad20Sopenharmony_ci * 		0 on success, or a negative error in case of failure.
25427c2aad20Sopenharmony_ci *
25437c2aad20Sopenharmony_ci * long bpf_skb_pull_data(struct sk_buff *skb, u32 len)
25447c2aad20Sopenharmony_ci * 	Description
25457c2aad20Sopenharmony_ci * 		Pull in non-linear data in case the *skb* is non-linear and not
25467c2aad20Sopenharmony_ci * 		all of *len* are part of the linear section. Make *len* bytes
25477c2aad20Sopenharmony_ci * 		from *skb* readable and writable. If a zero value is passed for
25487c2aad20Sopenharmony_ci *		*len*, then all bytes in the linear part of *skb* will be made
25497c2aad20Sopenharmony_ci *		readable and writable.
25507c2aad20Sopenharmony_ci *
25517c2aad20Sopenharmony_ci * 		This helper is only needed for reading and writing with direct
25527c2aad20Sopenharmony_ci * 		packet access.
25537c2aad20Sopenharmony_ci *
25547c2aad20Sopenharmony_ci * 		For direct packet access, testing that offsets to access
25557c2aad20Sopenharmony_ci * 		are within packet boundaries (test on *skb*\ **->data_end**) is
25567c2aad20Sopenharmony_ci * 		susceptible to fail if offsets are invalid, or if the requested
25577c2aad20Sopenharmony_ci * 		data is in non-linear parts of the *skb*. On failure the
25587c2aad20Sopenharmony_ci * 		program can just bail out, or in the case of a non-linear
25597c2aad20Sopenharmony_ci * 		buffer, use a helper to make the data available. The
25607c2aad20Sopenharmony_ci * 		**bpf_skb_load_bytes**\ () helper is a first solution to access
25617c2aad20Sopenharmony_ci * 		the data. Another one consists in using **bpf_skb_pull_data**
25627c2aad20Sopenharmony_ci * 		to pull in once the non-linear parts, then retesting and
25637c2aad20Sopenharmony_ci * 		eventually access the data.
25647c2aad20Sopenharmony_ci *
25657c2aad20Sopenharmony_ci * 		At the same time, this also makes sure the *skb* is uncloned,
25667c2aad20Sopenharmony_ci * 		which is a necessary condition for direct write. As this needs
25677c2aad20Sopenharmony_ci * 		to be an invariant for the write part only, the verifier
25687c2aad20Sopenharmony_ci * 		detects writes and adds a prologue that is calling
25697c2aad20Sopenharmony_ci * 		**bpf_skb_pull_data()** to effectively unclone the *skb* from
25707c2aad20Sopenharmony_ci * 		the very beginning in case it is indeed cloned.
25717c2aad20Sopenharmony_ci *
25727c2aad20Sopenharmony_ci * 		A call to this helper is susceptible to change the underlying
25737c2aad20Sopenharmony_ci * 		packet buffer. Therefore, at load time, all checks on pointers
25747c2aad20Sopenharmony_ci * 		previously done by the verifier are invalidated and must be
25757c2aad20Sopenharmony_ci * 		performed again, if the helper is used in combination with
25767c2aad20Sopenharmony_ci * 		direct packet access.
25777c2aad20Sopenharmony_ci * 	Return
25787c2aad20Sopenharmony_ci * 		0 on success, or a negative error in case of failure.
25797c2aad20Sopenharmony_ci *
25807c2aad20Sopenharmony_ci * s64 bpf_csum_update(struct sk_buff *skb, __wsum csum)
25817c2aad20Sopenharmony_ci * 	Description
25827c2aad20Sopenharmony_ci * 		Add the checksum *csum* into *skb*\ **->csum** in case the
25837c2aad20Sopenharmony_ci * 		driver has supplied a checksum for the entire packet into that
25847c2aad20Sopenharmony_ci * 		field. Return an error otherwise. This helper is intended to be
25857c2aad20Sopenharmony_ci * 		used in combination with **bpf_csum_diff**\ (), in particular
25867c2aad20Sopenharmony_ci * 		when the checksum needs to be updated after data has been
25877c2aad20Sopenharmony_ci * 		written into the packet through direct packet access.
25887c2aad20Sopenharmony_ci * 	Return
25897c2aad20Sopenharmony_ci * 		The checksum on success, or a negative error code in case of
25907c2aad20Sopenharmony_ci * 		failure.
25917c2aad20Sopenharmony_ci *
25927c2aad20Sopenharmony_ci * void bpf_set_hash_invalid(struct sk_buff *skb)
25937c2aad20Sopenharmony_ci * 	Description
25947c2aad20Sopenharmony_ci * 		Invalidate the current *skb*\ **->hash**. It can be used after
25957c2aad20Sopenharmony_ci * 		mangling on headers through direct packet access, in order to
25967c2aad20Sopenharmony_ci * 		indicate that the hash is outdated and to trigger a
25977c2aad20Sopenharmony_ci * 		recalculation the next time the kernel tries to access this
25987c2aad20Sopenharmony_ci * 		hash or when the **bpf_get_hash_recalc**\ () helper is called.
25997c2aad20Sopenharmony_ci * 	Return
26007c2aad20Sopenharmony_ci * 		void.
26017c2aad20Sopenharmony_ci *
26027c2aad20Sopenharmony_ci * long bpf_get_numa_node_id(void)
26037c2aad20Sopenharmony_ci * 	Description
26047c2aad20Sopenharmony_ci * 		Return the id of the current NUMA node. The primary use case
26057c2aad20Sopenharmony_ci * 		for this helper is the selection of sockets for the local NUMA
26067c2aad20Sopenharmony_ci * 		node, when the program is attached to sockets using the
26077c2aad20Sopenharmony_ci * 		**SO_ATTACH_REUSEPORT_EBPF** option (see also **socket(7)**),
26087c2aad20Sopenharmony_ci * 		but the helper is also available to other eBPF program types,
26097c2aad20Sopenharmony_ci * 		similarly to **bpf_get_smp_processor_id**\ ().
26107c2aad20Sopenharmony_ci * 	Return
26117c2aad20Sopenharmony_ci * 		The id of current NUMA node.
26127c2aad20Sopenharmony_ci *
26137c2aad20Sopenharmony_ci * long bpf_skb_change_head(struct sk_buff *skb, u32 len, u64 flags)
26147c2aad20Sopenharmony_ci * 	Description
26157c2aad20Sopenharmony_ci * 		Grows headroom of packet associated to *skb* and adjusts the
26167c2aad20Sopenharmony_ci * 		offset of the MAC header accordingly, adding *len* bytes of
26177c2aad20Sopenharmony_ci * 		space. It automatically extends and reallocates memory as
26187c2aad20Sopenharmony_ci * 		required.
26197c2aad20Sopenharmony_ci *
26207c2aad20Sopenharmony_ci * 		This helper can be used on a layer 3 *skb* to push a MAC header
26217c2aad20Sopenharmony_ci * 		for redirection into a layer 2 device.
26227c2aad20Sopenharmony_ci *
26237c2aad20Sopenharmony_ci * 		All values for *flags* are reserved for future usage, and must
26247c2aad20Sopenharmony_ci * 		be left at zero.
26257c2aad20Sopenharmony_ci *
26267c2aad20Sopenharmony_ci * 		A call to this helper is susceptible to change the underlying
26277c2aad20Sopenharmony_ci * 		packet buffer. Therefore, at load time, all checks on pointers
26287c2aad20Sopenharmony_ci * 		previously done by the verifier are invalidated and must be
26297c2aad20Sopenharmony_ci * 		performed again, if the helper is used in combination with
26307c2aad20Sopenharmony_ci * 		direct packet access.
26317c2aad20Sopenharmony_ci * 	Return
26327c2aad20Sopenharmony_ci * 		0 on success, or a negative error in case of failure.
26337c2aad20Sopenharmony_ci *
26347c2aad20Sopenharmony_ci * long bpf_xdp_adjust_head(struct xdp_buff *xdp_md, int delta)
26357c2aad20Sopenharmony_ci * 	Description
26367c2aad20Sopenharmony_ci * 		Adjust (move) *xdp_md*\ **->data** by *delta* bytes. Note that
26377c2aad20Sopenharmony_ci * 		it is possible to use a negative value for *delta*. This helper
26387c2aad20Sopenharmony_ci * 		can be used to prepare the packet for pushing or popping
26397c2aad20Sopenharmony_ci * 		headers.
26407c2aad20Sopenharmony_ci *
26417c2aad20Sopenharmony_ci * 		A call to this helper is susceptible to change the underlying
26427c2aad20Sopenharmony_ci * 		packet buffer. Therefore, at load time, all checks on pointers
26437c2aad20Sopenharmony_ci * 		previously done by the verifier are invalidated and must be
26447c2aad20Sopenharmony_ci * 		performed again, if the helper is used in combination with
26457c2aad20Sopenharmony_ci * 		direct packet access.
26467c2aad20Sopenharmony_ci * 	Return
26477c2aad20Sopenharmony_ci * 		0 on success, or a negative error in case of failure.
26487c2aad20Sopenharmony_ci *
26497c2aad20Sopenharmony_ci * long bpf_probe_read_str(void *dst, u32 size, const void *unsafe_ptr)
26507c2aad20Sopenharmony_ci * 	Description
26517c2aad20Sopenharmony_ci * 		Copy a NUL terminated string from an unsafe kernel address
26527c2aad20Sopenharmony_ci * 		*unsafe_ptr* to *dst*. See **bpf_probe_read_kernel_str**\ () for
26537c2aad20Sopenharmony_ci * 		more details.
26547c2aad20Sopenharmony_ci *
26557c2aad20Sopenharmony_ci * 		Generally, use **bpf_probe_read_user_str**\ () or
26567c2aad20Sopenharmony_ci * 		**bpf_probe_read_kernel_str**\ () instead.
26577c2aad20Sopenharmony_ci * 	Return
26587c2aad20Sopenharmony_ci * 		On success, the strictly positive length of the string,
26597c2aad20Sopenharmony_ci * 		including the trailing NUL character. On error, a negative
26607c2aad20Sopenharmony_ci * 		value.
26617c2aad20Sopenharmony_ci *
26627c2aad20Sopenharmony_ci * u64 bpf_get_socket_cookie(struct sk_buff *skb)
26637c2aad20Sopenharmony_ci * 	Description
26647c2aad20Sopenharmony_ci * 		If the **struct sk_buff** pointed by *skb* has a known socket,
26657c2aad20Sopenharmony_ci * 		retrieve the cookie (generated by the kernel) of this socket.
26667c2aad20Sopenharmony_ci * 		If no cookie has been set yet, generate a new cookie. Once
26677c2aad20Sopenharmony_ci * 		generated, the socket cookie remains stable for the life of the
26687c2aad20Sopenharmony_ci * 		socket. This helper can be useful for monitoring per socket
26697c2aad20Sopenharmony_ci * 		networking traffic statistics as it provides a global socket
26707c2aad20Sopenharmony_ci * 		identifier that can be assumed unique.
26717c2aad20Sopenharmony_ci * 	Return
26727c2aad20Sopenharmony_ci * 		A 8-byte long unique number on success, or 0 if the socket
26737c2aad20Sopenharmony_ci * 		field is missing inside *skb*.
26747c2aad20Sopenharmony_ci *
26757c2aad20Sopenharmony_ci * u64 bpf_get_socket_cookie(struct bpf_sock_addr *ctx)
26767c2aad20Sopenharmony_ci * 	Description
26777c2aad20Sopenharmony_ci * 		Equivalent to bpf_get_socket_cookie() helper that accepts
26787c2aad20Sopenharmony_ci * 		*skb*, but gets socket from **struct bpf_sock_addr** context.
26797c2aad20Sopenharmony_ci * 	Return
26807c2aad20Sopenharmony_ci * 		A 8-byte long unique number.
26817c2aad20Sopenharmony_ci *
26827c2aad20Sopenharmony_ci * u64 bpf_get_socket_cookie(struct bpf_sock_ops *ctx)
26837c2aad20Sopenharmony_ci * 	Description
26847c2aad20Sopenharmony_ci * 		Equivalent to **bpf_get_socket_cookie**\ () helper that accepts
26857c2aad20Sopenharmony_ci * 		*skb*, but gets socket from **struct bpf_sock_ops** context.
26867c2aad20Sopenharmony_ci * 	Return
26877c2aad20Sopenharmony_ci * 		A 8-byte long unique number.
26887c2aad20Sopenharmony_ci *
26897c2aad20Sopenharmony_ci * u64 bpf_get_socket_cookie(struct sock *sk)
26907c2aad20Sopenharmony_ci * 	Description
26917c2aad20Sopenharmony_ci * 		Equivalent to **bpf_get_socket_cookie**\ () helper that accepts
26927c2aad20Sopenharmony_ci * 		*sk*, but gets socket from a BTF **struct sock**. This helper
26937c2aad20Sopenharmony_ci * 		also works for sleepable programs.
26947c2aad20Sopenharmony_ci * 	Return
26957c2aad20Sopenharmony_ci * 		A 8-byte long unique number or 0 if *sk* is NULL.
26967c2aad20Sopenharmony_ci *
26977c2aad20Sopenharmony_ci * u32 bpf_get_socket_uid(struct sk_buff *skb)
26987c2aad20Sopenharmony_ci * 	Description
26997c2aad20Sopenharmony_ci * 		Get the owner UID of the socked associated to *skb*.
27007c2aad20Sopenharmony_ci * 	Return
27017c2aad20Sopenharmony_ci * 		The owner UID of the socket associated to *skb*. If the socket
27027c2aad20Sopenharmony_ci * 		is **NULL**, or if it is not a full socket (i.e. if it is a
27037c2aad20Sopenharmony_ci * 		time-wait or a request socket instead), **overflowuid** value
27047c2aad20Sopenharmony_ci * 		is returned (note that **overflowuid** might also be the actual
27057c2aad20Sopenharmony_ci * 		UID value for the socket).
27067c2aad20Sopenharmony_ci *
27077c2aad20Sopenharmony_ci * long bpf_set_hash(struct sk_buff *skb, u32 hash)
27087c2aad20Sopenharmony_ci * 	Description
27097c2aad20Sopenharmony_ci * 		Set the full hash for *skb* (set the field *skb*\ **->hash**)
27107c2aad20Sopenharmony_ci * 		to value *hash*.
27117c2aad20Sopenharmony_ci * 	Return
27127c2aad20Sopenharmony_ci * 		0
27137c2aad20Sopenharmony_ci *
27147c2aad20Sopenharmony_ci * long bpf_setsockopt(void *bpf_socket, int level, int optname, void *optval, int optlen)
27157c2aad20Sopenharmony_ci * 	Description
27167c2aad20Sopenharmony_ci * 		Emulate a call to **setsockopt()** on the socket associated to
27177c2aad20Sopenharmony_ci * 		*bpf_socket*, which must be a full socket. The *level* at
27187c2aad20Sopenharmony_ci * 		which the option resides and the name *optname* of the option
27197c2aad20Sopenharmony_ci * 		must be specified, see **setsockopt(2)** for more information.
27207c2aad20Sopenharmony_ci * 		The option value of length *optlen* is pointed by *optval*.
27217c2aad20Sopenharmony_ci *
27227c2aad20Sopenharmony_ci * 		*bpf_socket* should be one of the following:
27237c2aad20Sopenharmony_ci *
27247c2aad20Sopenharmony_ci * 		* **struct bpf_sock_ops** for **BPF_PROG_TYPE_SOCK_OPS**.
27257c2aad20Sopenharmony_ci *		* **struct bpf_sock_addr** for **BPF_CGROUP_INET4_CONNECT**,
27267c2aad20Sopenharmony_ci *		  **BPF_CGROUP_INET6_CONNECT** and **BPF_CGROUP_UNIX_CONNECT**.
27277c2aad20Sopenharmony_ci *
27287c2aad20Sopenharmony_ci * 		This helper actually implements a subset of **setsockopt()**.
27297c2aad20Sopenharmony_ci * 		It supports the following *level*\ s:
27307c2aad20Sopenharmony_ci *
27317c2aad20Sopenharmony_ci * 		* **SOL_SOCKET**, which supports the following *optname*\ s:
27327c2aad20Sopenharmony_ci * 		  **SO_RCVBUF**, **SO_SNDBUF**, **SO_MAX_PACING_RATE**,
27337c2aad20Sopenharmony_ci * 		  **SO_PRIORITY**, **SO_RCVLOWAT**, **SO_MARK**,
27347c2aad20Sopenharmony_ci * 		  **SO_BINDTODEVICE**, **SO_KEEPALIVE**, **SO_REUSEADDR**,
27357c2aad20Sopenharmony_ci * 		  **SO_REUSEPORT**, **SO_BINDTOIFINDEX**, **SO_TXREHASH**.
27367c2aad20Sopenharmony_ci * 		* **IPPROTO_TCP**, which supports the following *optname*\ s:
27377c2aad20Sopenharmony_ci * 		  **TCP_CONGESTION**, **TCP_BPF_IW**,
27387c2aad20Sopenharmony_ci * 		  **TCP_BPF_SNDCWND_CLAMP**, **TCP_SAVE_SYN**,
27397c2aad20Sopenharmony_ci * 		  **TCP_KEEPIDLE**, **TCP_KEEPINTVL**, **TCP_KEEPCNT**,
27407c2aad20Sopenharmony_ci * 		  **TCP_SYNCNT**, **TCP_USER_TIMEOUT**, **TCP_NOTSENT_LOWAT**,
27417c2aad20Sopenharmony_ci * 		  **TCP_NODELAY**, **TCP_MAXSEG**, **TCP_WINDOW_CLAMP**,
27427c2aad20Sopenharmony_ci * 		  **TCP_THIN_LINEAR_TIMEOUTS**, **TCP_BPF_DELACK_MAX**,
27437c2aad20Sopenharmony_ci * 		  **TCP_BPF_RTO_MIN**.
27447c2aad20Sopenharmony_ci * 		* **IPPROTO_IP**, which supports *optname* **IP_TOS**.
27457c2aad20Sopenharmony_ci * 		* **IPPROTO_IPV6**, which supports the following *optname*\ s:
27467c2aad20Sopenharmony_ci * 		  **IPV6_TCLASS**, **IPV6_AUTOFLOWLABEL**.
27477c2aad20Sopenharmony_ci * 	Return
27487c2aad20Sopenharmony_ci * 		0 on success, or a negative error in case of failure.
27497c2aad20Sopenharmony_ci *
27507c2aad20Sopenharmony_ci * long bpf_skb_adjust_room(struct sk_buff *skb, s32 len_diff, u32 mode, u64 flags)
27517c2aad20Sopenharmony_ci * 	Description
27527c2aad20Sopenharmony_ci * 		Grow or shrink the room for data in the packet associated to
27537c2aad20Sopenharmony_ci * 		*skb* by *len_diff*, and according to the selected *mode*.
27547c2aad20Sopenharmony_ci *
27557c2aad20Sopenharmony_ci * 		By default, the helper will reset any offloaded checksum
27567c2aad20Sopenharmony_ci * 		indicator of the skb to CHECKSUM_NONE. This can be avoided
27577c2aad20Sopenharmony_ci * 		by the following flag:
27587c2aad20Sopenharmony_ci *
27597c2aad20Sopenharmony_ci * 		* **BPF_F_ADJ_ROOM_NO_CSUM_RESET**: Do not reset offloaded
27607c2aad20Sopenharmony_ci * 		  checksum data of the skb to CHECKSUM_NONE.
27617c2aad20Sopenharmony_ci *
27627c2aad20Sopenharmony_ci *		There are two supported modes at this time:
27637c2aad20Sopenharmony_ci *
27647c2aad20Sopenharmony_ci *		* **BPF_ADJ_ROOM_MAC**: Adjust room at the mac layer
27657c2aad20Sopenharmony_ci * 		  (room space is added or removed between the layer 2 and
27667c2aad20Sopenharmony_ci * 		  layer 3 headers).
27677c2aad20Sopenharmony_ci *
27687c2aad20Sopenharmony_ci * 		* **BPF_ADJ_ROOM_NET**: Adjust room at the network layer
27697c2aad20Sopenharmony_ci * 		  (room space is added or removed between the layer 3 and
27707c2aad20Sopenharmony_ci * 		  layer 4 headers).
27717c2aad20Sopenharmony_ci *
27727c2aad20Sopenharmony_ci *		The following flags are supported at this time:
27737c2aad20Sopenharmony_ci *
27747c2aad20Sopenharmony_ci *		* **BPF_F_ADJ_ROOM_FIXED_GSO**: Do not adjust gso_size.
27757c2aad20Sopenharmony_ci *		  Adjusting mss in this way is not allowed for datagrams.
27767c2aad20Sopenharmony_ci *
27777c2aad20Sopenharmony_ci *		* **BPF_F_ADJ_ROOM_ENCAP_L3_IPV4**,
27787c2aad20Sopenharmony_ci *		  **BPF_F_ADJ_ROOM_ENCAP_L3_IPV6**:
27797c2aad20Sopenharmony_ci *		  Any new space is reserved to hold a tunnel header.
27807c2aad20Sopenharmony_ci *		  Configure skb offsets and other fields accordingly.
27817c2aad20Sopenharmony_ci *
27827c2aad20Sopenharmony_ci *		* **BPF_F_ADJ_ROOM_ENCAP_L4_GRE**,
27837c2aad20Sopenharmony_ci *		  **BPF_F_ADJ_ROOM_ENCAP_L4_UDP**:
27847c2aad20Sopenharmony_ci *		  Use with ENCAP_L3 flags to further specify the tunnel type.
27857c2aad20Sopenharmony_ci *
27867c2aad20Sopenharmony_ci *		* **BPF_F_ADJ_ROOM_ENCAP_L2**\ (*len*):
27877c2aad20Sopenharmony_ci *		  Use with ENCAP_L3/L4 flags to further specify the tunnel
27887c2aad20Sopenharmony_ci *		  type; *len* is the length of the inner MAC header.
27897c2aad20Sopenharmony_ci *
27907c2aad20Sopenharmony_ci *		* **BPF_F_ADJ_ROOM_ENCAP_L2_ETH**:
27917c2aad20Sopenharmony_ci *		  Use with BPF_F_ADJ_ROOM_ENCAP_L2 flag to further specify the
27927c2aad20Sopenharmony_ci *		  L2 type as Ethernet.
27937c2aad20Sopenharmony_ci *
27947c2aad20Sopenharmony_ci *		* **BPF_F_ADJ_ROOM_DECAP_L3_IPV4**,
27957c2aad20Sopenharmony_ci *		  **BPF_F_ADJ_ROOM_DECAP_L3_IPV6**:
27967c2aad20Sopenharmony_ci *		  Indicate the new IP header version after decapsulating the outer
27977c2aad20Sopenharmony_ci *		  IP header. Used when the inner and outer IP versions are different.
27987c2aad20Sopenharmony_ci *
27997c2aad20Sopenharmony_ci * 		A call to this helper is susceptible to change the underlying
28007c2aad20Sopenharmony_ci * 		packet buffer. Therefore, at load time, all checks on pointers
28017c2aad20Sopenharmony_ci * 		previously done by the verifier are invalidated and must be
28027c2aad20Sopenharmony_ci * 		performed again, if the helper is used in combination with
28037c2aad20Sopenharmony_ci * 		direct packet access.
28047c2aad20Sopenharmony_ci * 	Return
28057c2aad20Sopenharmony_ci * 		0 on success, or a negative error in case of failure.
28067c2aad20Sopenharmony_ci *
28077c2aad20Sopenharmony_ci * long bpf_redirect_map(struct bpf_map *map, u64 key, u64 flags)
28087c2aad20Sopenharmony_ci * 	Description
28097c2aad20Sopenharmony_ci * 		Redirect the packet to the endpoint referenced by *map* at
28107c2aad20Sopenharmony_ci * 		index *key*. Depending on its type, this *map* can contain
28117c2aad20Sopenharmony_ci * 		references to net devices (for forwarding packets through other
28127c2aad20Sopenharmony_ci * 		ports), or to CPUs (for redirecting XDP frames to another CPU;
28137c2aad20Sopenharmony_ci * 		but this is only implemented for native XDP (with driver
28147c2aad20Sopenharmony_ci * 		support) as of this writing).
28157c2aad20Sopenharmony_ci *
28167c2aad20Sopenharmony_ci * 		The lower two bits of *flags* are used as the return code if
28177c2aad20Sopenharmony_ci * 		the map lookup fails. This is so that the return value can be
28187c2aad20Sopenharmony_ci * 		one of the XDP program return codes up to **XDP_TX**, as chosen
28197c2aad20Sopenharmony_ci * 		by the caller. The higher bits of *flags* can be set to
28207c2aad20Sopenharmony_ci * 		BPF_F_BROADCAST or BPF_F_EXCLUDE_INGRESS as defined below.
28217c2aad20Sopenharmony_ci *
28227c2aad20Sopenharmony_ci * 		With BPF_F_BROADCAST the packet will be broadcasted to all the
28237c2aad20Sopenharmony_ci * 		interfaces in the map, with BPF_F_EXCLUDE_INGRESS the ingress
28247c2aad20Sopenharmony_ci * 		interface will be excluded when do broadcasting.
28257c2aad20Sopenharmony_ci *
28267c2aad20Sopenharmony_ci * 		See also **bpf_redirect**\ (), which only supports redirecting
28277c2aad20Sopenharmony_ci * 		to an ifindex, but doesn't require a map to do so.
28287c2aad20Sopenharmony_ci * 	Return
28297c2aad20Sopenharmony_ci * 		**XDP_REDIRECT** on success, or the value of the two lower bits
28307c2aad20Sopenharmony_ci * 		of the *flags* argument on error.
28317c2aad20Sopenharmony_ci *
28327c2aad20Sopenharmony_ci * long bpf_sk_redirect_map(struct sk_buff *skb, struct bpf_map *map, u32 key, u64 flags)
28337c2aad20Sopenharmony_ci * 	Description
28347c2aad20Sopenharmony_ci * 		Redirect the packet to the socket referenced by *map* (of type
28357c2aad20Sopenharmony_ci * 		**BPF_MAP_TYPE_SOCKMAP**) at index *key*. Both ingress and
28367c2aad20Sopenharmony_ci * 		egress interfaces can be used for redirection. The
28377c2aad20Sopenharmony_ci * 		**BPF_F_INGRESS** value in *flags* is used to make the
28387c2aad20Sopenharmony_ci * 		distinction (ingress path is selected if the flag is present,
28397c2aad20Sopenharmony_ci * 		egress path otherwise). This is the only flag supported for now.
28407c2aad20Sopenharmony_ci * 	Return
28417c2aad20Sopenharmony_ci * 		**SK_PASS** on success, or **SK_DROP** on error.
28427c2aad20Sopenharmony_ci *
28437c2aad20Sopenharmony_ci * long bpf_sock_map_update(struct bpf_sock_ops *skops, struct bpf_map *map, void *key, u64 flags)
28447c2aad20Sopenharmony_ci * 	Description
28457c2aad20Sopenharmony_ci * 		Add an entry to, or update a *map* referencing sockets. The
28467c2aad20Sopenharmony_ci * 		*skops* is used as a new value for the entry associated to
28477c2aad20Sopenharmony_ci * 		*key*. *flags* is one of:
28487c2aad20Sopenharmony_ci *
28497c2aad20Sopenharmony_ci * 		**BPF_NOEXIST**
28507c2aad20Sopenharmony_ci * 			The entry for *key* must not exist in the map.
28517c2aad20Sopenharmony_ci * 		**BPF_EXIST**
28527c2aad20Sopenharmony_ci * 			The entry for *key* must already exist in the map.
28537c2aad20Sopenharmony_ci * 		**BPF_ANY**
28547c2aad20Sopenharmony_ci * 			No condition on the existence of the entry for *key*.
28557c2aad20Sopenharmony_ci *
28567c2aad20Sopenharmony_ci * 		If the *map* has eBPF programs (parser and verdict), those will
28577c2aad20Sopenharmony_ci * 		be inherited by the socket being added. If the socket is
28587c2aad20Sopenharmony_ci * 		already attached to eBPF programs, this results in an error.
28597c2aad20Sopenharmony_ci * 	Return
28607c2aad20Sopenharmony_ci * 		0 on success, or a negative error in case of failure.
28617c2aad20Sopenharmony_ci *
28627c2aad20Sopenharmony_ci * long bpf_xdp_adjust_meta(struct xdp_buff *xdp_md, int delta)
28637c2aad20Sopenharmony_ci * 	Description
28647c2aad20Sopenharmony_ci * 		Adjust the address pointed by *xdp_md*\ **->data_meta** by
28657c2aad20Sopenharmony_ci * 		*delta* (which can be positive or negative). Note that this
28667c2aad20Sopenharmony_ci * 		operation modifies the address stored in *xdp_md*\ **->data**,
28677c2aad20Sopenharmony_ci * 		so the latter must be loaded only after the helper has been
28687c2aad20Sopenharmony_ci * 		called.
28697c2aad20Sopenharmony_ci *
28707c2aad20Sopenharmony_ci * 		The use of *xdp_md*\ **->data_meta** is optional and programs
28717c2aad20Sopenharmony_ci * 		are not required to use it. The rationale is that when the
28727c2aad20Sopenharmony_ci * 		packet is processed with XDP (e.g. as DoS filter), it is
28737c2aad20Sopenharmony_ci * 		possible to push further meta data along with it before passing
28747c2aad20Sopenharmony_ci * 		to the stack, and to give the guarantee that an ingress eBPF
28757c2aad20Sopenharmony_ci * 		program attached as a TC classifier on the same device can pick
28767c2aad20Sopenharmony_ci * 		this up for further post-processing. Since TC works with socket
28777c2aad20Sopenharmony_ci * 		buffers, it remains possible to set from XDP the **mark** or
28787c2aad20Sopenharmony_ci * 		**priority** pointers, or other pointers for the socket buffer.
28797c2aad20Sopenharmony_ci * 		Having this scratch space generic and programmable allows for
28807c2aad20Sopenharmony_ci * 		more flexibility as the user is free to store whatever meta
28817c2aad20Sopenharmony_ci * 		data they need.
28827c2aad20Sopenharmony_ci *
28837c2aad20Sopenharmony_ci * 		A call to this helper is susceptible to change the underlying
28847c2aad20Sopenharmony_ci * 		packet buffer. Therefore, at load time, all checks on pointers
28857c2aad20Sopenharmony_ci * 		previously done by the verifier are invalidated and must be
28867c2aad20Sopenharmony_ci * 		performed again, if the helper is used in combination with
28877c2aad20Sopenharmony_ci * 		direct packet access.
28887c2aad20Sopenharmony_ci * 	Return
28897c2aad20Sopenharmony_ci * 		0 on success, or a negative error in case of failure.
28907c2aad20Sopenharmony_ci *
28917c2aad20Sopenharmony_ci * long bpf_perf_event_read_value(struct bpf_map *map, u64 flags, struct bpf_perf_event_value *buf, u32 buf_size)
28927c2aad20Sopenharmony_ci * 	Description
28937c2aad20Sopenharmony_ci * 		Read the value of a perf event counter, and store it into *buf*
28947c2aad20Sopenharmony_ci * 		of size *buf_size*. This helper relies on a *map* of type
28957c2aad20Sopenharmony_ci * 		**BPF_MAP_TYPE_PERF_EVENT_ARRAY**. The nature of the perf event
28967c2aad20Sopenharmony_ci * 		counter is selected when *map* is updated with perf event file
28977c2aad20Sopenharmony_ci * 		descriptors. The *map* is an array whose size is the number of
28987c2aad20Sopenharmony_ci * 		available CPUs, and each cell contains a value relative to one
28997c2aad20Sopenharmony_ci * 		CPU. The value to retrieve is indicated by *flags*, that
29007c2aad20Sopenharmony_ci * 		contains the index of the CPU to look up, masked with
29017c2aad20Sopenharmony_ci * 		**BPF_F_INDEX_MASK**. Alternatively, *flags* can be set to
29027c2aad20Sopenharmony_ci * 		**BPF_F_CURRENT_CPU** to indicate that the value for the
29037c2aad20Sopenharmony_ci * 		current CPU should be retrieved.
29047c2aad20Sopenharmony_ci *
29057c2aad20Sopenharmony_ci * 		This helper behaves in a way close to
29067c2aad20Sopenharmony_ci * 		**bpf_perf_event_read**\ () helper, save that instead of
29077c2aad20Sopenharmony_ci * 		just returning the value observed, it fills the *buf*
29087c2aad20Sopenharmony_ci * 		structure. This allows for additional data to be retrieved: in
29097c2aad20Sopenharmony_ci * 		particular, the enabled and running times (in *buf*\
29107c2aad20Sopenharmony_ci * 		**->enabled** and *buf*\ **->running**, respectively) are
29117c2aad20Sopenharmony_ci * 		copied. In general, **bpf_perf_event_read_value**\ () is
29127c2aad20Sopenharmony_ci * 		recommended over **bpf_perf_event_read**\ (), which has some
29137c2aad20Sopenharmony_ci * 		ABI issues and provides fewer functionalities.
29147c2aad20Sopenharmony_ci *
29157c2aad20Sopenharmony_ci * 		These values are interesting, because hardware PMU (Performance
29167c2aad20Sopenharmony_ci * 		Monitoring Unit) counters are limited resources. When there are
29177c2aad20Sopenharmony_ci * 		more PMU based perf events opened than available counters,
29187c2aad20Sopenharmony_ci * 		kernel will multiplex these events so each event gets certain
29197c2aad20Sopenharmony_ci * 		percentage (but not all) of the PMU time. In case that
29207c2aad20Sopenharmony_ci * 		multiplexing happens, the number of samples or counter value
29217c2aad20Sopenharmony_ci * 		will not reflect the case compared to when no multiplexing
29227c2aad20Sopenharmony_ci * 		occurs. This makes comparison between different runs difficult.
29237c2aad20Sopenharmony_ci * 		Typically, the counter value should be normalized before
29247c2aad20Sopenharmony_ci * 		comparing to other experiments. The usual normalization is done
29257c2aad20Sopenharmony_ci * 		as follows.
29267c2aad20Sopenharmony_ci *
29277c2aad20Sopenharmony_ci * 		::
29287c2aad20Sopenharmony_ci *
29297c2aad20Sopenharmony_ci * 			normalized_counter = counter * t_enabled / t_running
29307c2aad20Sopenharmony_ci *
29317c2aad20Sopenharmony_ci * 		Where t_enabled is the time enabled for event and t_running is
29327c2aad20Sopenharmony_ci * 		the time running for event since last normalization. The
29337c2aad20Sopenharmony_ci * 		enabled and running times are accumulated since the perf event
29347c2aad20Sopenharmony_ci * 		open. To achieve scaling factor between two invocations of an
29357c2aad20Sopenharmony_ci * 		eBPF program, users can use CPU id as the key (which is
29367c2aad20Sopenharmony_ci * 		typical for perf array usage model) to remember the previous
29377c2aad20Sopenharmony_ci * 		value and do the calculation inside the eBPF program.
29387c2aad20Sopenharmony_ci * 	Return
29397c2aad20Sopenharmony_ci * 		0 on success, or a negative error in case of failure.
29407c2aad20Sopenharmony_ci *
29417c2aad20Sopenharmony_ci * long bpf_perf_prog_read_value(struct bpf_perf_event_data *ctx, struct bpf_perf_event_value *buf, u32 buf_size)
29427c2aad20Sopenharmony_ci * 	Description
29437c2aad20Sopenharmony_ci * 		For an eBPF program attached to a perf event, retrieve the
29447c2aad20Sopenharmony_ci * 		value of the event counter associated to *ctx* and store it in
29457c2aad20Sopenharmony_ci * 		the structure pointed by *buf* and of size *buf_size*. Enabled
29467c2aad20Sopenharmony_ci * 		and running times are also stored in the structure (see
29477c2aad20Sopenharmony_ci * 		description of helper **bpf_perf_event_read_value**\ () for
29487c2aad20Sopenharmony_ci * 		more details).
29497c2aad20Sopenharmony_ci * 	Return
29507c2aad20Sopenharmony_ci * 		0 on success, or a negative error in case of failure.
29517c2aad20Sopenharmony_ci *
29527c2aad20Sopenharmony_ci * long bpf_getsockopt(void *bpf_socket, int level, int optname, void *optval, int optlen)
29537c2aad20Sopenharmony_ci * 	Description
29547c2aad20Sopenharmony_ci * 		Emulate a call to **getsockopt()** on the socket associated to
29557c2aad20Sopenharmony_ci * 		*bpf_socket*, which must be a full socket. The *level* at
29567c2aad20Sopenharmony_ci * 		which the option resides and the name *optname* of the option
29577c2aad20Sopenharmony_ci * 		must be specified, see **getsockopt(2)** for more information.
29587c2aad20Sopenharmony_ci * 		The retrieved value is stored in the structure pointed by
29597c2aad20Sopenharmony_ci * 		*opval* and of length *optlen*.
29607c2aad20Sopenharmony_ci *
29617c2aad20Sopenharmony_ci * 		*bpf_socket* should be one of the following:
29627c2aad20Sopenharmony_ci *
29637c2aad20Sopenharmony_ci * 		* **struct bpf_sock_ops** for **BPF_PROG_TYPE_SOCK_OPS**.
29647c2aad20Sopenharmony_ci *		* **struct bpf_sock_addr** for **BPF_CGROUP_INET4_CONNECT**,
29657c2aad20Sopenharmony_ci *		  **BPF_CGROUP_INET6_CONNECT** and **BPF_CGROUP_UNIX_CONNECT**.
29667c2aad20Sopenharmony_ci *
29677c2aad20Sopenharmony_ci * 		This helper actually implements a subset of **getsockopt()**.
29687c2aad20Sopenharmony_ci * 		It supports the same set of *optname*\ s that is supported by
29697c2aad20Sopenharmony_ci * 		the **bpf_setsockopt**\ () helper.  The exceptions are
29707c2aad20Sopenharmony_ci * 		**TCP_BPF_*** is **bpf_setsockopt**\ () only and
29717c2aad20Sopenharmony_ci * 		**TCP_SAVED_SYN** is **bpf_getsockopt**\ () only.
29727c2aad20Sopenharmony_ci * 	Return
29737c2aad20Sopenharmony_ci * 		0 on success, or a negative error in case of failure.
29747c2aad20Sopenharmony_ci *
29757c2aad20Sopenharmony_ci * long bpf_override_return(struct pt_regs *regs, u64 rc)
29767c2aad20Sopenharmony_ci * 	Description
29777c2aad20Sopenharmony_ci * 		Used for error injection, this helper uses kprobes to override
29787c2aad20Sopenharmony_ci * 		the return value of the probed function, and to set it to *rc*.
29797c2aad20Sopenharmony_ci * 		The first argument is the context *regs* on which the kprobe
29807c2aad20Sopenharmony_ci * 		works.
29817c2aad20Sopenharmony_ci *
29827c2aad20Sopenharmony_ci * 		This helper works by setting the PC (program counter)
29837c2aad20Sopenharmony_ci * 		to an override function which is run in place of the original
29847c2aad20Sopenharmony_ci * 		probed function. This means the probed function is not run at
29857c2aad20Sopenharmony_ci * 		all. The replacement function just returns with the required
29867c2aad20Sopenharmony_ci * 		value.
29877c2aad20Sopenharmony_ci *
29887c2aad20Sopenharmony_ci * 		This helper has security implications, and thus is subject to
29897c2aad20Sopenharmony_ci * 		restrictions. It is only available if the kernel was compiled
29907c2aad20Sopenharmony_ci * 		with the **CONFIG_BPF_KPROBE_OVERRIDE** configuration
29917c2aad20Sopenharmony_ci * 		option, and in this case it only works on functions tagged with
29927c2aad20Sopenharmony_ci * 		**ALLOW_ERROR_INJECTION** in the kernel code.
29937c2aad20Sopenharmony_ci *
29947c2aad20Sopenharmony_ci * 		Also, the helper is only available for the architectures having
29957c2aad20Sopenharmony_ci * 		the CONFIG_FUNCTION_ERROR_INJECTION option. As of this writing,
29967c2aad20Sopenharmony_ci * 		x86 architecture is the only one to support this feature.
29977c2aad20Sopenharmony_ci * 	Return
29987c2aad20Sopenharmony_ci * 		0
29997c2aad20Sopenharmony_ci *
30007c2aad20Sopenharmony_ci * long bpf_sock_ops_cb_flags_set(struct bpf_sock_ops *bpf_sock, int argval)
30017c2aad20Sopenharmony_ci * 	Description
30027c2aad20Sopenharmony_ci * 		Attempt to set the value of the **bpf_sock_ops_cb_flags** field
30037c2aad20Sopenharmony_ci * 		for the full TCP socket associated to *bpf_sock_ops* to
30047c2aad20Sopenharmony_ci * 		*argval*.
30057c2aad20Sopenharmony_ci *
30067c2aad20Sopenharmony_ci * 		The primary use of this field is to determine if there should
30077c2aad20Sopenharmony_ci * 		be calls to eBPF programs of type
30087c2aad20Sopenharmony_ci * 		**BPF_PROG_TYPE_SOCK_OPS** at various points in the TCP
30097c2aad20Sopenharmony_ci * 		code. A program of the same type can change its value, per
30107c2aad20Sopenharmony_ci * 		connection and as necessary, when the connection is
30117c2aad20Sopenharmony_ci * 		established. This field is directly accessible for reading, but
30127c2aad20Sopenharmony_ci * 		this helper must be used for updates in order to return an
30137c2aad20Sopenharmony_ci * 		error if an eBPF program tries to set a callback that is not
30147c2aad20Sopenharmony_ci * 		supported in the current kernel.
30157c2aad20Sopenharmony_ci *
30167c2aad20Sopenharmony_ci * 		*argval* is a flag array which can combine these flags:
30177c2aad20Sopenharmony_ci *
30187c2aad20Sopenharmony_ci * 		* **BPF_SOCK_OPS_RTO_CB_FLAG** (retransmission time out)
30197c2aad20Sopenharmony_ci * 		* **BPF_SOCK_OPS_RETRANS_CB_FLAG** (retransmission)
30207c2aad20Sopenharmony_ci * 		* **BPF_SOCK_OPS_STATE_CB_FLAG** (TCP state change)
30217c2aad20Sopenharmony_ci * 		* **BPF_SOCK_OPS_RTT_CB_FLAG** (every RTT)
30227c2aad20Sopenharmony_ci *
30237c2aad20Sopenharmony_ci * 		Therefore, this function can be used to clear a callback flag by
30247c2aad20Sopenharmony_ci * 		setting the appropriate bit to zero. e.g. to disable the RTO
30257c2aad20Sopenharmony_ci * 		callback:
30267c2aad20Sopenharmony_ci *
30277c2aad20Sopenharmony_ci * 		**bpf_sock_ops_cb_flags_set(bpf_sock,**
30287c2aad20Sopenharmony_ci * 			**bpf_sock->bpf_sock_ops_cb_flags & ~BPF_SOCK_OPS_RTO_CB_FLAG)**
30297c2aad20Sopenharmony_ci *
30307c2aad20Sopenharmony_ci * 		Here are some examples of where one could call such eBPF
30317c2aad20Sopenharmony_ci * 		program:
30327c2aad20Sopenharmony_ci *
30337c2aad20Sopenharmony_ci * 		* When RTO fires.
30347c2aad20Sopenharmony_ci * 		* When a packet is retransmitted.
30357c2aad20Sopenharmony_ci * 		* When the connection terminates.
30367c2aad20Sopenharmony_ci * 		* When a packet is sent.
30377c2aad20Sopenharmony_ci * 		* When a packet is received.
30387c2aad20Sopenharmony_ci * 	Return
30397c2aad20Sopenharmony_ci * 		Code **-EINVAL** if the socket is not a full TCP socket;
30407c2aad20Sopenharmony_ci * 		otherwise, a positive number containing the bits that could not
30417c2aad20Sopenharmony_ci * 		be set is returned (which comes down to 0 if all bits were set
30427c2aad20Sopenharmony_ci * 		as required).
30437c2aad20Sopenharmony_ci *
30447c2aad20Sopenharmony_ci * long bpf_msg_redirect_map(struct sk_msg_buff *msg, struct bpf_map *map, u32 key, u64 flags)
30457c2aad20Sopenharmony_ci * 	Description
30467c2aad20Sopenharmony_ci * 		This helper is used in programs implementing policies at the
30477c2aad20Sopenharmony_ci * 		socket level. If the message *msg* is allowed to pass (i.e. if
30487c2aad20Sopenharmony_ci * 		the verdict eBPF program returns **SK_PASS**), redirect it to
30497c2aad20Sopenharmony_ci * 		the socket referenced by *map* (of type
30507c2aad20Sopenharmony_ci * 		**BPF_MAP_TYPE_SOCKMAP**) at index *key*. Both ingress and
30517c2aad20Sopenharmony_ci * 		egress interfaces can be used for redirection. The
30527c2aad20Sopenharmony_ci * 		**BPF_F_INGRESS** value in *flags* is used to make the
30537c2aad20Sopenharmony_ci * 		distinction (ingress path is selected if the flag is present,
30547c2aad20Sopenharmony_ci * 		egress path otherwise). This is the only flag supported for now.
30557c2aad20Sopenharmony_ci * 	Return
30567c2aad20Sopenharmony_ci * 		**SK_PASS** on success, or **SK_DROP** on error.
30577c2aad20Sopenharmony_ci *
30587c2aad20Sopenharmony_ci * long bpf_msg_apply_bytes(struct sk_msg_buff *msg, u32 bytes)
30597c2aad20Sopenharmony_ci * 	Description
30607c2aad20Sopenharmony_ci * 		For socket policies, apply the verdict of the eBPF program to
30617c2aad20Sopenharmony_ci * 		the next *bytes* (number of bytes) of message *msg*.
30627c2aad20Sopenharmony_ci *
30637c2aad20Sopenharmony_ci * 		For example, this helper can be used in the following cases:
30647c2aad20Sopenharmony_ci *
30657c2aad20Sopenharmony_ci * 		* A single **sendmsg**\ () or **sendfile**\ () system call
30667c2aad20Sopenharmony_ci * 		  contains multiple logical messages that the eBPF program is
30677c2aad20Sopenharmony_ci * 		  supposed to read and for which it should apply a verdict.
30687c2aad20Sopenharmony_ci * 		* An eBPF program only cares to read the first *bytes* of a
30697c2aad20Sopenharmony_ci * 		  *msg*. If the message has a large payload, then setting up
30707c2aad20Sopenharmony_ci * 		  and calling the eBPF program repeatedly for all bytes, even
30717c2aad20Sopenharmony_ci * 		  though the verdict is already known, would create unnecessary
30727c2aad20Sopenharmony_ci * 		  overhead.
30737c2aad20Sopenharmony_ci *
30747c2aad20Sopenharmony_ci * 		When called from within an eBPF program, the helper sets a
30757c2aad20Sopenharmony_ci * 		counter internal to the BPF infrastructure, that is used to
30767c2aad20Sopenharmony_ci * 		apply the last verdict to the next *bytes*. If *bytes* is
30777c2aad20Sopenharmony_ci * 		smaller than the current data being processed from a
30787c2aad20Sopenharmony_ci * 		**sendmsg**\ () or **sendfile**\ () system call, the first
30797c2aad20Sopenharmony_ci * 		*bytes* will be sent and the eBPF program will be re-run with
30807c2aad20Sopenharmony_ci * 		the pointer for start of data pointing to byte number *bytes*
30817c2aad20Sopenharmony_ci * 		**+ 1**. If *bytes* is larger than the current data being
30827c2aad20Sopenharmony_ci * 		processed, then the eBPF verdict will be applied to multiple
30837c2aad20Sopenharmony_ci * 		**sendmsg**\ () or **sendfile**\ () calls until *bytes* are
30847c2aad20Sopenharmony_ci * 		consumed.
30857c2aad20Sopenharmony_ci *
30867c2aad20Sopenharmony_ci * 		Note that if a socket closes with the internal counter holding
30877c2aad20Sopenharmony_ci * 		a non-zero value, this is not a problem because data is not
30887c2aad20Sopenharmony_ci * 		being buffered for *bytes* and is sent as it is received.
30897c2aad20Sopenharmony_ci * 	Return
30907c2aad20Sopenharmony_ci * 		0
30917c2aad20Sopenharmony_ci *
30927c2aad20Sopenharmony_ci * long bpf_msg_cork_bytes(struct sk_msg_buff *msg, u32 bytes)
30937c2aad20Sopenharmony_ci * 	Description
30947c2aad20Sopenharmony_ci * 		For socket policies, prevent the execution of the verdict eBPF
30957c2aad20Sopenharmony_ci * 		program for message *msg* until *bytes* (byte number) have been
30967c2aad20Sopenharmony_ci * 		accumulated.
30977c2aad20Sopenharmony_ci *
30987c2aad20Sopenharmony_ci * 		This can be used when one needs a specific number of bytes
30997c2aad20Sopenharmony_ci * 		before a verdict can be assigned, even if the data spans
31007c2aad20Sopenharmony_ci * 		multiple **sendmsg**\ () or **sendfile**\ () calls. The extreme
31017c2aad20Sopenharmony_ci * 		case would be a user calling **sendmsg**\ () repeatedly with
31027c2aad20Sopenharmony_ci * 		1-byte long message segments. Obviously, this is bad for
31037c2aad20Sopenharmony_ci * 		performance, but it is still valid. If the eBPF program needs
31047c2aad20Sopenharmony_ci * 		*bytes* bytes to validate a header, this helper can be used to
31057c2aad20Sopenharmony_ci * 		prevent the eBPF program to be called again until *bytes* have
31067c2aad20Sopenharmony_ci * 		been accumulated.
31077c2aad20Sopenharmony_ci * 	Return
31087c2aad20Sopenharmony_ci * 		0
31097c2aad20Sopenharmony_ci *
31107c2aad20Sopenharmony_ci * long bpf_msg_pull_data(struct sk_msg_buff *msg, u32 start, u32 end, u64 flags)
31117c2aad20Sopenharmony_ci * 	Description
31127c2aad20Sopenharmony_ci * 		For socket policies, pull in non-linear data from user space
31137c2aad20Sopenharmony_ci * 		for *msg* and set pointers *msg*\ **->data** and *msg*\
31147c2aad20Sopenharmony_ci * 		**->data_end** to *start* and *end* bytes offsets into *msg*,
31157c2aad20Sopenharmony_ci * 		respectively.
31167c2aad20Sopenharmony_ci *
31177c2aad20Sopenharmony_ci * 		If a program of type **BPF_PROG_TYPE_SK_MSG** is run on a
31187c2aad20Sopenharmony_ci * 		*msg* it can only parse data that the (**data**, **data_end**)
31197c2aad20Sopenharmony_ci * 		pointers have already consumed. For **sendmsg**\ () hooks this
31207c2aad20Sopenharmony_ci * 		is likely the first scatterlist element. But for calls relying
31217c2aad20Sopenharmony_ci * 		on the **sendpage** handler (e.g. **sendfile**\ ()) this will
31227c2aad20Sopenharmony_ci * 		be the range (**0**, **0**) because the data is shared with
31237c2aad20Sopenharmony_ci * 		user space and by default the objective is to avoid allowing
31247c2aad20Sopenharmony_ci * 		user space to modify data while (or after) eBPF verdict is
31257c2aad20Sopenharmony_ci * 		being decided. This helper can be used to pull in data and to
31267c2aad20Sopenharmony_ci * 		set the start and end pointer to given values. Data will be
31277c2aad20Sopenharmony_ci * 		copied if necessary (i.e. if data was not linear and if start
31287c2aad20Sopenharmony_ci * 		and end pointers do not point to the same chunk).
31297c2aad20Sopenharmony_ci *
31307c2aad20Sopenharmony_ci * 		A call to this helper is susceptible to change the underlying
31317c2aad20Sopenharmony_ci * 		packet buffer. Therefore, at load time, all checks on pointers
31327c2aad20Sopenharmony_ci * 		previously done by the verifier are invalidated and must be
31337c2aad20Sopenharmony_ci * 		performed again, if the helper is used in combination with
31347c2aad20Sopenharmony_ci * 		direct packet access.
31357c2aad20Sopenharmony_ci *
31367c2aad20Sopenharmony_ci * 		All values for *flags* are reserved for future usage, and must
31377c2aad20Sopenharmony_ci * 		be left at zero.
31387c2aad20Sopenharmony_ci * 	Return
31397c2aad20Sopenharmony_ci * 		0 on success, or a negative error in case of failure.
31407c2aad20Sopenharmony_ci *
31417c2aad20Sopenharmony_ci * long bpf_bind(struct bpf_sock_addr *ctx, struct sockaddr *addr, int addr_len)
31427c2aad20Sopenharmony_ci * 	Description
31437c2aad20Sopenharmony_ci * 		Bind the socket associated to *ctx* to the address pointed by
31447c2aad20Sopenharmony_ci * 		*addr*, of length *addr_len*. This allows for making outgoing
31457c2aad20Sopenharmony_ci * 		connection from the desired IP address, which can be useful for
31467c2aad20Sopenharmony_ci * 		example when all processes inside a cgroup should use one
31477c2aad20Sopenharmony_ci * 		single IP address on a host that has multiple IP configured.
31487c2aad20Sopenharmony_ci *
31497c2aad20Sopenharmony_ci * 		This helper works for IPv4 and IPv6, TCP and UDP sockets. The
31507c2aad20Sopenharmony_ci * 		domain (*addr*\ **->sa_family**) must be **AF_INET** (or
31517c2aad20Sopenharmony_ci * 		**AF_INET6**). It's advised to pass zero port (**sin_port**
31527c2aad20Sopenharmony_ci * 		or **sin6_port**) which triggers IP_BIND_ADDRESS_NO_PORT-like
31537c2aad20Sopenharmony_ci * 		behavior and lets the kernel efficiently pick up an unused
31547c2aad20Sopenharmony_ci * 		port as long as 4-tuple is unique. Passing non-zero port might
31557c2aad20Sopenharmony_ci * 		lead to degraded performance.
31567c2aad20Sopenharmony_ci * 	Return
31577c2aad20Sopenharmony_ci * 		0 on success, or a negative error in case of failure.
31587c2aad20Sopenharmony_ci *
31597c2aad20Sopenharmony_ci * long bpf_xdp_adjust_tail(struct xdp_buff *xdp_md, int delta)
31607c2aad20Sopenharmony_ci * 	Description
31617c2aad20Sopenharmony_ci * 		Adjust (move) *xdp_md*\ **->data_end** by *delta* bytes. It is
31627c2aad20Sopenharmony_ci * 		possible to both shrink and grow the packet tail.
31637c2aad20Sopenharmony_ci * 		Shrink done via *delta* being a negative integer.
31647c2aad20Sopenharmony_ci *
31657c2aad20Sopenharmony_ci * 		A call to this helper is susceptible to change the underlying
31667c2aad20Sopenharmony_ci * 		packet buffer. Therefore, at load time, all checks on pointers
31677c2aad20Sopenharmony_ci * 		previously done by the verifier are invalidated and must be
31687c2aad20Sopenharmony_ci * 		performed again, if the helper is used in combination with
31697c2aad20Sopenharmony_ci * 		direct packet access.
31707c2aad20Sopenharmony_ci * 	Return
31717c2aad20Sopenharmony_ci * 		0 on success, or a negative error in case of failure.
31727c2aad20Sopenharmony_ci *
31737c2aad20Sopenharmony_ci * long bpf_skb_get_xfrm_state(struct sk_buff *skb, u32 index, struct bpf_xfrm_state *xfrm_state, u32 size, u64 flags)
31747c2aad20Sopenharmony_ci * 	Description
31757c2aad20Sopenharmony_ci * 		Retrieve the XFRM state (IP transform framework, see also
31767c2aad20Sopenharmony_ci * 		**ip-xfrm(8)**) at *index* in XFRM "security path" for *skb*.
31777c2aad20Sopenharmony_ci *
31787c2aad20Sopenharmony_ci * 		The retrieved value is stored in the **struct bpf_xfrm_state**
31797c2aad20Sopenharmony_ci * 		pointed by *xfrm_state* and of length *size*.
31807c2aad20Sopenharmony_ci *
31817c2aad20Sopenharmony_ci * 		All values for *flags* are reserved for future usage, and must
31827c2aad20Sopenharmony_ci * 		be left at zero.
31837c2aad20Sopenharmony_ci *
31847c2aad20Sopenharmony_ci * 		This helper is available only if the kernel was compiled with
31857c2aad20Sopenharmony_ci * 		**CONFIG_XFRM** configuration option.
31867c2aad20Sopenharmony_ci * 	Return
31877c2aad20Sopenharmony_ci * 		0 on success, or a negative error in case of failure.
31887c2aad20Sopenharmony_ci *
31897c2aad20Sopenharmony_ci * long bpf_get_stack(void *ctx, void *buf, u32 size, u64 flags)
31907c2aad20Sopenharmony_ci * 	Description
31917c2aad20Sopenharmony_ci * 		Return a user or a kernel stack in bpf program provided buffer.
31927c2aad20Sopenharmony_ci * 		To achieve this, the helper needs *ctx*, which is a pointer
31937c2aad20Sopenharmony_ci * 		to the context on which the tracing program is executed.
31947c2aad20Sopenharmony_ci * 		To store the stacktrace, the bpf program provides *buf* with
31957c2aad20Sopenharmony_ci * 		a nonnegative *size*.
31967c2aad20Sopenharmony_ci *
31977c2aad20Sopenharmony_ci * 		The last argument, *flags*, holds the number of stack frames to
31987c2aad20Sopenharmony_ci * 		skip (from 0 to 255), masked with
31997c2aad20Sopenharmony_ci * 		**BPF_F_SKIP_FIELD_MASK**. The next bits can be used to set
32007c2aad20Sopenharmony_ci * 		the following flags:
32017c2aad20Sopenharmony_ci *
32027c2aad20Sopenharmony_ci * 		**BPF_F_USER_STACK**
32037c2aad20Sopenharmony_ci * 			Collect a user space stack instead of a kernel stack.
32047c2aad20Sopenharmony_ci * 		**BPF_F_USER_BUILD_ID**
32057c2aad20Sopenharmony_ci * 			Collect (build_id, file_offset) instead of ips for user
32067c2aad20Sopenharmony_ci * 			stack, only valid if **BPF_F_USER_STACK** is also
32077c2aad20Sopenharmony_ci * 			specified.
32087c2aad20Sopenharmony_ci *
32097c2aad20Sopenharmony_ci * 			*file_offset* is an offset relative to the beginning
32107c2aad20Sopenharmony_ci * 			of the executable or shared object file backing the vma
32117c2aad20Sopenharmony_ci * 			which the *ip* falls in. It is *not* an offset relative
32127c2aad20Sopenharmony_ci * 			to that object's base address. Accordingly, it must be
32137c2aad20Sopenharmony_ci * 			adjusted by adding (sh_addr - sh_offset), where
32147c2aad20Sopenharmony_ci * 			sh_{addr,offset} correspond to the executable section
32157c2aad20Sopenharmony_ci * 			containing *file_offset* in the object, for comparisons
32167c2aad20Sopenharmony_ci * 			to symbols' st_value to be valid.
32177c2aad20Sopenharmony_ci *
32187c2aad20Sopenharmony_ci * 		**bpf_get_stack**\ () can collect up to
32197c2aad20Sopenharmony_ci * 		**PERF_MAX_STACK_DEPTH** both kernel and user frames, subject
32207c2aad20Sopenharmony_ci * 		to sufficient large buffer size. Note that
32217c2aad20Sopenharmony_ci * 		this limit can be controlled with the **sysctl** program, and
32227c2aad20Sopenharmony_ci * 		that it should be manually increased in order to profile long
32237c2aad20Sopenharmony_ci * 		user stacks (such as stacks for Java programs). To do so, use:
32247c2aad20Sopenharmony_ci *
32257c2aad20Sopenharmony_ci * 		::
32267c2aad20Sopenharmony_ci *
32277c2aad20Sopenharmony_ci * 			# sysctl kernel.perf_event_max_stack=<new value>
32287c2aad20Sopenharmony_ci * 	Return
32297c2aad20Sopenharmony_ci * 		The non-negative copied *buf* length equal to or less than
32307c2aad20Sopenharmony_ci * 		*size* on success, or a negative error in case of failure.
32317c2aad20Sopenharmony_ci *
32327c2aad20Sopenharmony_ci * long bpf_skb_load_bytes_relative(const void *skb, u32 offset, void *to, u32 len, u32 start_header)
32337c2aad20Sopenharmony_ci * 	Description
32347c2aad20Sopenharmony_ci * 		This helper is similar to **bpf_skb_load_bytes**\ () in that
32357c2aad20Sopenharmony_ci * 		it provides an easy way to load *len* bytes from *offset*
32367c2aad20Sopenharmony_ci * 		from the packet associated to *skb*, into the buffer pointed
32377c2aad20Sopenharmony_ci * 		by *to*. The difference to **bpf_skb_load_bytes**\ () is that
32387c2aad20Sopenharmony_ci * 		a fifth argument *start_header* exists in order to select a
32397c2aad20Sopenharmony_ci * 		base offset to start from. *start_header* can be one of:
32407c2aad20Sopenharmony_ci *
32417c2aad20Sopenharmony_ci * 		**BPF_HDR_START_MAC**
32427c2aad20Sopenharmony_ci * 			Base offset to load data from is *skb*'s mac header.
32437c2aad20Sopenharmony_ci * 		**BPF_HDR_START_NET**
32447c2aad20Sopenharmony_ci * 			Base offset to load data from is *skb*'s network header.
32457c2aad20Sopenharmony_ci *
32467c2aad20Sopenharmony_ci * 		In general, "direct packet access" is the preferred method to
32477c2aad20Sopenharmony_ci * 		access packet data, however, this helper is in particular useful
32487c2aad20Sopenharmony_ci * 		in socket filters where *skb*\ **->data** does not always point
32497c2aad20Sopenharmony_ci * 		to the start of the mac header and where "direct packet access"
32507c2aad20Sopenharmony_ci * 		is not available.
32517c2aad20Sopenharmony_ci * 	Return
32527c2aad20Sopenharmony_ci * 		0 on success, or a negative error in case of failure.
32537c2aad20Sopenharmony_ci *
32547c2aad20Sopenharmony_ci * long bpf_fib_lookup(void *ctx, struct bpf_fib_lookup *params, int plen, u32 flags)
32557c2aad20Sopenharmony_ci *	Description
32567c2aad20Sopenharmony_ci *		Do FIB lookup in kernel tables using parameters in *params*.
32577c2aad20Sopenharmony_ci *		If lookup is successful and result shows packet is to be
32587c2aad20Sopenharmony_ci *		forwarded, the neighbor tables are searched for the nexthop.
32597c2aad20Sopenharmony_ci *		If successful (ie., FIB lookup shows forwarding and nexthop
32607c2aad20Sopenharmony_ci *		is resolved), the nexthop address is returned in ipv4_dst
32617c2aad20Sopenharmony_ci *		or ipv6_dst based on family, smac is set to mac address of
32627c2aad20Sopenharmony_ci *		egress device, dmac is set to nexthop mac address, rt_metric
32637c2aad20Sopenharmony_ci *		is set to metric from route (IPv4/IPv6 only), and ifindex
32647c2aad20Sopenharmony_ci *		is set to the device index of the nexthop from the FIB lookup.
32657c2aad20Sopenharmony_ci *
32667c2aad20Sopenharmony_ci *		*plen* argument is the size of the passed in struct.
32677c2aad20Sopenharmony_ci *		*flags* argument can be a combination of one or more of the
32687c2aad20Sopenharmony_ci *		following values:
32697c2aad20Sopenharmony_ci *
32707c2aad20Sopenharmony_ci *		**BPF_FIB_LOOKUP_DIRECT**
32717c2aad20Sopenharmony_ci *			Do a direct table lookup vs full lookup using FIB
32727c2aad20Sopenharmony_ci *			rules.
32737c2aad20Sopenharmony_ci *		**BPF_FIB_LOOKUP_TBID**
32747c2aad20Sopenharmony_ci *			Used with BPF_FIB_LOOKUP_DIRECT.
32757c2aad20Sopenharmony_ci *			Use the routing table ID present in *params*->tbid
32767c2aad20Sopenharmony_ci *			for the fib lookup.
32777c2aad20Sopenharmony_ci *		**BPF_FIB_LOOKUP_OUTPUT**
32787c2aad20Sopenharmony_ci *			Perform lookup from an egress perspective (default is
32797c2aad20Sopenharmony_ci *			ingress).
32807c2aad20Sopenharmony_ci *		**BPF_FIB_LOOKUP_SKIP_NEIGH**
32817c2aad20Sopenharmony_ci *			Skip the neighbour table lookup. *params*->dmac
32827c2aad20Sopenharmony_ci *			and *params*->smac will not be set as output. A common
32837c2aad20Sopenharmony_ci *			use case is to call **bpf_redirect_neigh**\ () after
32847c2aad20Sopenharmony_ci *			doing **bpf_fib_lookup**\ ().
32857c2aad20Sopenharmony_ci *		**BPF_FIB_LOOKUP_SRC**
32867c2aad20Sopenharmony_ci *			Derive and set source IP addr in *params*->ipv{4,6}_src
32877c2aad20Sopenharmony_ci *			for the nexthop. If the src addr cannot be derived,
32887c2aad20Sopenharmony_ci *			**BPF_FIB_LKUP_RET_NO_SRC_ADDR** is returned. In this
32897c2aad20Sopenharmony_ci *			case, *params*->dmac and *params*->smac are not set either.
32907c2aad20Sopenharmony_ci *
32917c2aad20Sopenharmony_ci *		*ctx* is either **struct xdp_md** for XDP programs or
32927c2aad20Sopenharmony_ci *		**struct sk_buff** tc cls_act programs.
32937c2aad20Sopenharmony_ci *	Return
32947c2aad20Sopenharmony_ci *		* < 0 if any input argument is invalid
32957c2aad20Sopenharmony_ci *		*   0 on success (packet is forwarded, nexthop neighbor exists)
32967c2aad20Sopenharmony_ci *		* > 0 one of **BPF_FIB_LKUP_RET_** codes explaining why the
32977c2aad20Sopenharmony_ci *		  packet is not forwarded or needs assist from full stack
32987c2aad20Sopenharmony_ci *
32997c2aad20Sopenharmony_ci *		If lookup fails with BPF_FIB_LKUP_RET_FRAG_NEEDED, then the MTU
33007c2aad20Sopenharmony_ci *		was exceeded and output params->mtu_result contains the MTU.
33017c2aad20Sopenharmony_ci *
33027c2aad20Sopenharmony_ci * long bpf_sock_hash_update(struct bpf_sock_ops *skops, struct bpf_map *map, void *key, u64 flags)
33037c2aad20Sopenharmony_ci *	Description
33047c2aad20Sopenharmony_ci *		Add an entry to, or update a sockhash *map* referencing sockets.
33057c2aad20Sopenharmony_ci *		The *skops* is used as a new value for the entry associated to
33067c2aad20Sopenharmony_ci *		*key*. *flags* is one of:
33077c2aad20Sopenharmony_ci *
33087c2aad20Sopenharmony_ci *		**BPF_NOEXIST**
33097c2aad20Sopenharmony_ci *			The entry for *key* must not exist in the map.
33107c2aad20Sopenharmony_ci *		**BPF_EXIST**
33117c2aad20Sopenharmony_ci *			The entry for *key* must already exist in the map.
33127c2aad20Sopenharmony_ci *		**BPF_ANY**
33137c2aad20Sopenharmony_ci *			No condition on the existence of the entry for *key*.
33147c2aad20Sopenharmony_ci *
33157c2aad20Sopenharmony_ci *		If the *map* has eBPF programs (parser and verdict), those will
33167c2aad20Sopenharmony_ci *		be inherited by the socket being added. If the socket is
33177c2aad20Sopenharmony_ci *		already attached to eBPF programs, this results in an error.
33187c2aad20Sopenharmony_ci *	Return
33197c2aad20Sopenharmony_ci *		0 on success, or a negative error in case of failure.
33207c2aad20Sopenharmony_ci *
33217c2aad20Sopenharmony_ci * long bpf_msg_redirect_hash(struct sk_msg_buff *msg, struct bpf_map *map, void *key, u64 flags)
33227c2aad20Sopenharmony_ci *	Description
33237c2aad20Sopenharmony_ci *		This helper is used in programs implementing policies at the
33247c2aad20Sopenharmony_ci *		socket level. If the message *msg* is allowed to pass (i.e. if
33257c2aad20Sopenharmony_ci *		the verdict eBPF program returns **SK_PASS**), redirect it to
33267c2aad20Sopenharmony_ci *		the socket referenced by *map* (of type
33277c2aad20Sopenharmony_ci *		**BPF_MAP_TYPE_SOCKHASH**) using hash *key*. Both ingress and
33287c2aad20Sopenharmony_ci *		egress interfaces can be used for redirection. The
33297c2aad20Sopenharmony_ci *		**BPF_F_INGRESS** value in *flags* is used to make the
33307c2aad20Sopenharmony_ci *		distinction (ingress path is selected if the flag is present,
33317c2aad20Sopenharmony_ci *		egress path otherwise). This is the only flag supported for now.
33327c2aad20Sopenharmony_ci *	Return
33337c2aad20Sopenharmony_ci *		**SK_PASS** on success, or **SK_DROP** on error.
33347c2aad20Sopenharmony_ci *
33357c2aad20Sopenharmony_ci * long bpf_sk_redirect_hash(struct sk_buff *skb, struct bpf_map *map, void *key, u64 flags)
33367c2aad20Sopenharmony_ci *	Description
33377c2aad20Sopenharmony_ci *		This helper is used in programs implementing policies at the
33387c2aad20Sopenharmony_ci *		skb socket level. If the sk_buff *skb* is allowed to pass (i.e.
33397c2aad20Sopenharmony_ci *		if the verdict eBPF program returns **SK_PASS**), redirect it
33407c2aad20Sopenharmony_ci *		to the socket referenced by *map* (of type
33417c2aad20Sopenharmony_ci *		**BPF_MAP_TYPE_SOCKHASH**) using hash *key*. Both ingress and
33427c2aad20Sopenharmony_ci *		egress interfaces can be used for redirection. The
33437c2aad20Sopenharmony_ci *		**BPF_F_INGRESS** value in *flags* is used to make the
33447c2aad20Sopenharmony_ci *		distinction (ingress path is selected if the flag is present,
33457c2aad20Sopenharmony_ci *		egress otherwise). This is the only flag supported for now.
33467c2aad20Sopenharmony_ci *	Return
33477c2aad20Sopenharmony_ci *		**SK_PASS** on success, or **SK_DROP** on error.
33487c2aad20Sopenharmony_ci *
33497c2aad20Sopenharmony_ci * long bpf_lwt_push_encap(struct sk_buff *skb, u32 type, void *hdr, u32 len)
33507c2aad20Sopenharmony_ci *	Description
33517c2aad20Sopenharmony_ci *		Encapsulate the packet associated to *skb* within a Layer 3
33527c2aad20Sopenharmony_ci *		protocol header. This header is provided in the buffer at
33537c2aad20Sopenharmony_ci *		address *hdr*, with *len* its size in bytes. *type* indicates
33547c2aad20Sopenharmony_ci *		the protocol of the header and can be one of:
33557c2aad20Sopenharmony_ci *
33567c2aad20Sopenharmony_ci *		**BPF_LWT_ENCAP_SEG6**
33577c2aad20Sopenharmony_ci *			IPv6 encapsulation with Segment Routing Header
33587c2aad20Sopenharmony_ci *			(**struct ipv6_sr_hdr**). *hdr* only contains the SRH,
33597c2aad20Sopenharmony_ci *			the IPv6 header is computed by the kernel.
33607c2aad20Sopenharmony_ci *		**BPF_LWT_ENCAP_SEG6_INLINE**
33617c2aad20Sopenharmony_ci *			Only works if *skb* contains an IPv6 packet. Insert a
33627c2aad20Sopenharmony_ci *			Segment Routing Header (**struct ipv6_sr_hdr**) inside
33637c2aad20Sopenharmony_ci *			the IPv6 header.
33647c2aad20Sopenharmony_ci *		**BPF_LWT_ENCAP_IP**
33657c2aad20Sopenharmony_ci *			IP encapsulation (GRE/GUE/IPIP/etc). The outer header
33667c2aad20Sopenharmony_ci *			must be IPv4 or IPv6, followed by zero or more
33677c2aad20Sopenharmony_ci *			additional headers, up to **LWT_BPF_MAX_HEADROOM**
33687c2aad20Sopenharmony_ci *			total bytes in all prepended headers. Please note that
33697c2aad20Sopenharmony_ci *			if **skb_is_gso**\ (*skb*) is true, no more than two
33707c2aad20Sopenharmony_ci *			headers can be prepended, and the inner header, if
33717c2aad20Sopenharmony_ci *			present, should be either GRE or UDP/GUE.
33727c2aad20Sopenharmony_ci *
33737c2aad20Sopenharmony_ci *		**BPF_LWT_ENCAP_SEG6**\ \* types can be called by BPF programs
33747c2aad20Sopenharmony_ci *		of type **BPF_PROG_TYPE_LWT_IN**; **BPF_LWT_ENCAP_IP** type can
33757c2aad20Sopenharmony_ci *		be called by bpf programs of types **BPF_PROG_TYPE_LWT_IN** and
33767c2aad20Sopenharmony_ci *		**BPF_PROG_TYPE_LWT_XMIT**.
33777c2aad20Sopenharmony_ci *
33787c2aad20Sopenharmony_ci * 		A call to this helper is susceptible to change the underlying
33797c2aad20Sopenharmony_ci * 		packet buffer. Therefore, at load time, all checks on pointers
33807c2aad20Sopenharmony_ci * 		previously done by the verifier are invalidated and must be
33817c2aad20Sopenharmony_ci * 		performed again, if the helper is used in combination with
33827c2aad20Sopenharmony_ci * 		direct packet access.
33837c2aad20Sopenharmony_ci *	Return
33847c2aad20Sopenharmony_ci * 		0 on success, or a negative error in case of failure.
33857c2aad20Sopenharmony_ci *
33867c2aad20Sopenharmony_ci * long bpf_lwt_seg6_store_bytes(struct sk_buff *skb, u32 offset, const void *from, u32 len)
33877c2aad20Sopenharmony_ci *	Description
33887c2aad20Sopenharmony_ci *		Store *len* bytes from address *from* into the packet
33897c2aad20Sopenharmony_ci *		associated to *skb*, at *offset*. Only the flags, tag and TLVs
33907c2aad20Sopenharmony_ci *		inside the outermost IPv6 Segment Routing Header can be
33917c2aad20Sopenharmony_ci *		modified through this helper.
33927c2aad20Sopenharmony_ci *
33937c2aad20Sopenharmony_ci * 		A call to this helper is susceptible to change the underlying
33947c2aad20Sopenharmony_ci * 		packet buffer. Therefore, at load time, all checks on pointers
33957c2aad20Sopenharmony_ci * 		previously done by the verifier are invalidated and must be
33967c2aad20Sopenharmony_ci * 		performed again, if the helper is used in combination with
33977c2aad20Sopenharmony_ci * 		direct packet access.
33987c2aad20Sopenharmony_ci *	Return
33997c2aad20Sopenharmony_ci * 		0 on success, or a negative error in case of failure.
34007c2aad20Sopenharmony_ci *
34017c2aad20Sopenharmony_ci * long bpf_lwt_seg6_adjust_srh(struct sk_buff *skb, u32 offset, s32 delta)
34027c2aad20Sopenharmony_ci *	Description
34037c2aad20Sopenharmony_ci *		Adjust the size allocated to TLVs in the outermost IPv6
34047c2aad20Sopenharmony_ci *		Segment Routing Header contained in the packet associated to
34057c2aad20Sopenharmony_ci *		*skb*, at position *offset* by *delta* bytes. Only offsets
34067c2aad20Sopenharmony_ci *		after the segments are accepted. *delta* can be as well
34077c2aad20Sopenharmony_ci *		positive (growing) as negative (shrinking).
34087c2aad20Sopenharmony_ci *
34097c2aad20Sopenharmony_ci * 		A call to this helper is susceptible to change the underlying
34107c2aad20Sopenharmony_ci * 		packet buffer. Therefore, at load time, all checks on pointers
34117c2aad20Sopenharmony_ci * 		previously done by the verifier are invalidated and must be
34127c2aad20Sopenharmony_ci * 		performed again, if the helper is used in combination with
34137c2aad20Sopenharmony_ci * 		direct packet access.
34147c2aad20Sopenharmony_ci *	Return
34157c2aad20Sopenharmony_ci * 		0 on success, or a negative error in case of failure.
34167c2aad20Sopenharmony_ci *
34177c2aad20Sopenharmony_ci * long bpf_lwt_seg6_action(struct sk_buff *skb, u32 action, void *param, u32 param_len)
34187c2aad20Sopenharmony_ci *	Description
34197c2aad20Sopenharmony_ci *		Apply an IPv6 Segment Routing action of type *action* to the
34207c2aad20Sopenharmony_ci *		packet associated to *skb*. Each action takes a parameter
34217c2aad20Sopenharmony_ci *		contained at address *param*, and of length *param_len* bytes.
34227c2aad20Sopenharmony_ci *		*action* can be one of:
34237c2aad20Sopenharmony_ci *
34247c2aad20Sopenharmony_ci *		**SEG6_LOCAL_ACTION_END_X**
34257c2aad20Sopenharmony_ci *			End.X action: Endpoint with Layer-3 cross-connect.
34267c2aad20Sopenharmony_ci *			Type of *param*: **struct in6_addr**.
34277c2aad20Sopenharmony_ci *		**SEG6_LOCAL_ACTION_END_T**
34287c2aad20Sopenharmony_ci *			End.T action: Endpoint with specific IPv6 table lookup.
34297c2aad20Sopenharmony_ci *			Type of *param*: **int**.
34307c2aad20Sopenharmony_ci *		**SEG6_LOCAL_ACTION_END_B6**
34317c2aad20Sopenharmony_ci *			End.B6 action: Endpoint bound to an SRv6 policy.
34327c2aad20Sopenharmony_ci *			Type of *param*: **struct ipv6_sr_hdr**.
34337c2aad20Sopenharmony_ci *		**SEG6_LOCAL_ACTION_END_B6_ENCAP**
34347c2aad20Sopenharmony_ci *			End.B6.Encap action: Endpoint bound to an SRv6
34357c2aad20Sopenharmony_ci *			encapsulation policy.
34367c2aad20Sopenharmony_ci *			Type of *param*: **struct ipv6_sr_hdr**.
34377c2aad20Sopenharmony_ci *
34387c2aad20Sopenharmony_ci * 		A call to this helper is susceptible to change the underlying
34397c2aad20Sopenharmony_ci * 		packet buffer. Therefore, at load time, all checks on pointers
34407c2aad20Sopenharmony_ci * 		previously done by the verifier are invalidated and must be
34417c2aad20Sopenharmony_ci * 		performed again, if the helper is used in combination with
34427c2aad20Sopenharmony_ci * 		direct packet access.
34437c2aad20Sopenharmony_ci *	Return
34447c2aad20Sopenharmony_ci * 		0 on success, or a negative error in case of failure.
34457c2aad20Sopenharmony_ci *
34467c2aad20Sopenharmony_ci * long bpf_rc_repeat(void *ctx)
34477c2aad20Sopenharmony_ci *	Description
34487c2aad20Sopenharmony_ci *		This helper is used in programs implementing IR decoding, to
34497c2aad20Sopenharmony_ci *		report a successfully decoded repeat key message. This delays
34507c2aad20Sopenharmony_ci *		the generation of a key up event for previously generated
34517c2aad20Sopenharmony_ci *		key down event.
34527c2aad20Sopenharmony_ci *
34537c2aad20Sopenharmony_ci *		Some IR protocols like NEC have a special IR message for
34547c2aad20Sopenharmony_ci *		repeating last button, for when a button is held down.
34557c2aad20Sopenharmony_ci *
34567c2aad20Sopenharmony_ci *		The *ctx* should point to the lirc sample as passed into
34577c2aad20Sopenharmony_ci *		the program.
34587c2aad20Sopenharmony_ci *
34597c2aad20Sopenharmony_ci *		This helper is only available is the kernel was compiled with
34607c2aad20Sopenharmony_ci *		the **CONFIG_BPF_LIRC_MODE2** configuration option set to
34617c2aad20Sopenharmony_ci *		"**y**".
34627c2aad20Sopenharmony_ci *	Return
34637c2aad20Sopenharmony_ci *		0
34647c2aad20Sopenharmony_ci *
34657c2aad20Sopenharmony_ci * long bpf_rc_keydown(void *ctx, u32 protocol, u64 scancode, u32 toggle)
34667c2aad20Sopenharmony_ci *	Description
34677c2aad20Sopenharmony_ci *		This helper is used in programs implementing IR decoding, to
34687c2aad20Sopenharmony_ci *		report a successfully decoded key press with *scancode*,
34697c2aad20Sopenharmony_ci *		*toggle* value in the given *protocol*. The scancode will be
34707c2aad20Sopenharmony_ci *		translated to a keycode using the rc keymap, and reported as
34717c2aad20Sopenharmony_ci *		an input key down event. After a period a key up event is
34727c2aad20Sopenharmony_ci *		generated. This period can be extended by calling either
34737c2aad20Sopenharmony_ci *		**bpf_rc_keydown**\ () again with the same values, or calling
34747c2aad20Sopenharmony_ci *		**bpf_rc_repeat**\ ().
34757c2aad20Sopenharmony_ci *
34767c2aad20Sopenharmony_ci *		Some protocols include a toggle bit, in case the button was
34777c2aad20Sopenharmony_ci *		released and pressed again between consecutive scancodes.
34787c2aad20Sopenharmony_ci *
34797c2aad20Sopenharmony_ci *		The *ctx* should point to the lirc sample as passed into
34807c2aad20Sopenharmony_ci *		the program.
34817c2aad20Sopenharmony_ci *
34827c2aad20Sopenharmony_ci *		The *protocol* is the decoded protocol number (see
34837c2aad20Sopenharmony_ci *		**enum rc_proto** for some predefined values).
34847c2aad20Sopenharmony_ci *
34857c2aad20Sopenharmony_ci *		This helper is only available is the kernel was compiled with
34867c2aad20Sopenharmony_ci *		the **CONFIG_BPF_LIRC_MODE2** configuration option set to
34877c2aad20Sopenharmony_ci *		"**y**".
34887c2aad20Sopenharmony_ci *	Return
34897c2aad20Sopenharmony_ci *		0
34907c2aad20Sopenharmony_ci *
34917c2aad20Sopenharmony_ci * u64 bpf_skb_cgroup_id(struct sk_buff *skb)
34927c2aad20Sopenharmony_ci * 	Description
34937c2aad20Sopenharmony_ci * 		Return the cgroup v2 id of the socket associated with the *skb*.
34947c2aad20Sopenharmony_ci * 		This is roughly similar to the **bpf_get_cgroup_classid**\ ()
34957c2aad20Sopenharmony_ci * 		helper for cgroup v1 by providing a tag resp. identifier that
34967c2aad20Sopenharmony_ci * 		can be matched on or used for map lookups e.g. to implement
34977c2aad20Sopenharmony_ci * 		policy. The cgroup v2 id of a given path in the hierarchy is
34987c2aad20Sopenharmony_ci * 		exposed in user space through the f_handle API in order to get
34997c2aad20Sopenharmony_ci * 		to the same 64-bit id.
35007c2aad20Sopenharmony_ci *
35017c2aad20Sopenharmony_ci * 		This helper can be used on TC egress path, but not on ingress,
35027c2aad20Sopenharmony_ci * 		and is available only if the kernel was compiled with the
35037c2aad20Sopenharmony_ci * 		**CONFIG_SOCK_CGROUP_DATA** configuration option.
35047c2aad20Sopenharmony_ci * 	Return
35057c2aad20Sopenharmony_ci * 		The id is returned or 0 in case the id could not be retrieved.
35067c2aad20Sopenharmony_ci *
35077c2aad20Sopenharmony_ci * u64 bpf_get_current_cgroup_id(void)
35087c2aad20Sopenharmony_ci * 	Description
35097c2aad20Sopenharmony_ci * 		Get the current cgroup id based on the cgroup within which
35107c2aad20Sopenharmony_ci * 		the current task is running.
35117c2aad20Sopenharmony_ci * 	Return
35127c2aad20Sopenharmony_ci * 		A 64-bit integer containing the current cgroup id based
35137c2aad20Sopenharmony_ci * 		on the cgroup within which the current task is running.
35147c2aad20Sopenharmony_ci *
35157c2aad20Sopenharmony_ci * void *bpf_get_local_storage(void *map, u64 flags)
35167c2aad20Sopenharmony_ci *	Description
35177c2aad20Sopenharmony_ci *		Get the pointer to the local storage area.
35187c2aad20Sopenharmony_ci *		The type and the size of the local storage is defined
35197c2aad20Sopenharmony_ci *		by the *map* argument.
35207c2aad20Sopenharmony_ci *		The *flags* meaning is specific for each map type,
35217c2aad20Sopenharmony_ci *		and has to be 0 for cgroup local storage.
35227c2aad20Sopenharmony_ci *
35237c2aad20Sopenharmony_ci *		Depending on the BPF program type, a local storage area
35247c2aad20Sopenharmony_ci *		can be shared between multiple instances of the BPF program,
35257c2aad20Sopenharmony_ci *		running simultaneously.
35267c2aad20Sopenharmony_ci *
35277c2aad20Sopenharmony_ci *		A user should care about the synchronization by himself.
35287c2aad20Sopenharmony_ci *		For example, by using the **BPF_ATOMIC** instructions to alter
35297c2aad20Sopenharmony_ci *		the shared data.
35307c2aad20Sopenharmony_ci *	Return
35317c2aad20Sopenharmony_ci *		A pointer to the local storage area.
35327c2aad20Sopenharmony_ci *
35337c2aad20Sopenharmony_ci * long bpf_sk_select_reuseport(struct sk_reuseport_md *reuse, struct bpf_map *map, void *key, u64 flags)
35347c2aad20Sopenharmony_ci *	Description
35357c2aad20Sopenharmony_ci *		Select a **SO_REUSEPORT** socket from a
35367c2aad20Sopenharmony_ci *		**BPF_MAP_TYPE_REUSEPORT_SOCKARRAY** *map*.
35377c2aad20Sopenharmony_ci *		It checks the selected socket is matching the incoming
35387c2aad20Sopenharmony_ci *		request in the socket buffer.
35397c2aad20Sopenharmony_ci *	Return
35407c2aad20Sopenharmony_ci *		0 on success, or a negative error in case of failure.
35417c2aad20Sopenharmony_ci *
35427c2aad20Sopenharmony_ci * u64 bpf_skb_ancestor_cgroup_id(struct sk_buff *skb, int ancestor_level)
35437c2aad20Sopenharmony_ci *	Description
35447c2aad20Sopenharmony_ci *		Return id of cgroup v2 that is ancestor of cgroup associated
35457c2aad20Sopenharmony_ci *		with the *skb* at the *ancestor_level*.  The root cgroup is at
35467c2aad20Sopenharmony_ci *		*ancestor_level* zero and each step down the hierarchy
35477c2aad20Sopenharmony_ci *		increments the level. If *ancestor_level* == level of cgroup
35487c2aad20Sopenharmony_ci *		associated with *skb*, then return value will be same as that
35497c2aad20Sopenharmony_ci *		of **bpf_skb_cgroup_id**\ ().
35507c2aad20Sopenharmony_ci *
35517c2aad20Sopenharmony_ci *		The helper is useful to implement policies based on cgroups
35527c2aad20Sopenharmony_ci *		that are upper in hierarchy than immediate cgroup associated
35537c2aad20Sopenharmony_ci *		with *skb*.
35547c2aad20Sopenharmony_ci *
35557c2aad20Sopenharmony_ci *		The format of returned id and helper limitations are same as in
35567c2aad20Sopenharmony_ci *		**bpf_skb_cgroup_id**\ ().
35577c2aad20Sopenharmony_ci *	Return
35587c2aad20Sopenharmony_ci *		The id is returned or 0 in case the id could not be retrieved.
35597c2aad20Sopenharmony_ci *
35607c2aad20Sopenharmony_ci * struct bpf_sock *bpf_sk_lookup_tcp(void *ctx, struct bpf_sock_tuple *tuple, u32 tuple_size, u64 netns, u64 flags)
35617c2aad20Sopenharmony_ci *	Description
35627c2aad20Sopenharmony_ci *		Look for TCP socket matching *tuple*, optionally in a child
35637c2aad20Sopenharmony_ci *		network namespace *netns*. The return value must be checked,
35647c2aad20Sopenharmony_ci *		and if non-**NULL**, released via **bpf_sk_release**\ ().
35657c2aad20Sopenharmony_ci *
35667c2aad20Sopenharmony_ci *		The *ctx* should point to the context of the program, such as
35677c2aad20Sopenharmony_ci *		the skb or socket (depending on the hook in use). This is used
35687c2aad20Sopenharmony_ci *		to determine the base network namespace for the lookup.
35697c2aad20Sopenharmony_ci *
35707c2aad20Sopenharmony_ci *		*tuple_size* must be one of:
35717c2aad20Sopenharmony_ci *
35727c2aad20Sopenharmony_ci *		**sizeof**\ (*tuple*\ **->ipv4**)
35737c2aad20Sopenharmony_ci *			Look for an IPv4 socket.
35747c2aad20Sopenharmony_ci *		**sizeof**\ (*tuple*\ **->ipv6**)
35757c2aad20Sopenharmony_ci *			Look for an IPv6 socket.
35767c2aad20Sopenharmony_ci *
35777c2aad20Sopenharmony_ci *		If the *netns* is a negative signed 32-bit integer, then the
35787c2aad20Sopenharmony_ci *		socket lookup table in the netns associated with the *ctx*
35797c2aad20Sopenharmony_ci *		will be used. For the TC hooks, this is the netns of the device
35807c2aad20Sopenharmony_ci *		in the skb. For socket hooks, this is the netns of the socket.
35817c2aad20Sopenharmony_ci *		If *netns* is any other signed 32-bit value greater than or
35827c2aad20Sopenharmony_ci *		equal to zero then it specifies the ID of the netns relative to
35837c2aad20Sopenharmony_ci *		the netns associated with the *ctx*. *netns* values beyond the
35847c2aad20Sopenharmony_ci *		range of 32-bit integers are reserved for future use.
35857c2aad20Sopenharmony_ci *
35867c2aad20Sopenharmony_ci *		All values for *flags* are reserved for future usage, and must
35877c2aad20Sopenharmony_ci *		be left at zero.
35887c2aad20Sopenharmony_ci *
35897c2aad20Sopenharmony_ci *		This helper is available only if the kernel was compiled with
35907c2aad20Sopenharmony_ci *		**CONFIG_NET** configuration option.
35917c2aad20Sopenharmony_ci *	Return
35927c2aad20Sopenharmony_ci *		Pointer to **struct bpf_sock**, or **NULL** in case of failure.
35937c2aad20Sopenharmony_ci *		For sockets with reuseport option, the **struct bpf_sock**
35947c2aad20Sopenharmony_ci *		result is from *reuse*\ **->socks**\ [] using the hash of the
35957c2aad20Sopenharmony_ci *		tuple.
35967c2aad20Sopenharmony_ci *
35977c2aad20Sopenharmony_ci * struct bpf_sock *bpf_sk_lookup_udp(void *ctx, struct bpf_sock_tuple *tuple, u32 tuple_size, u64 netns, u64 flags)
35987c2aad20Sopenharmony_ci *	Description
35997c2aad20Sopenharmony_ci *		Look for UDP socket matching *tuple*, optionally in a child
36007c2aad20Sopenharmony_ci *		network namespace *netns*. The return value must be checked,
36017c2aad20Sopenharmony_ci *		and if non-**NULL**, released via **bpf_sk_release**\ ().
36027c2aad20Sopenharmony_ci *
36037c2aad20Sopenharmony_ci *		The *ctx* should point to the context of the program, such as
36047c2aad20Sopenharmony_ci *		the skb or socket (depending on the hook in use). This is used
36057c2aad20Sopenharmony_ci *		to determine the base network namespace for the lookup.
36067c2aad20Sopenharmony_ci *
36077c2aad20Sopenharmony_ci *		*tuple_size* must be one of:
36087c2aad20Sopenharmony_ci *
36097c2aad20Sopenharmony_ci *		**sizeof**\ (*tuple*\ **->ipv4**)
36107c2aad20Sopenharmony_ci *			Look for an IPv4 socket.
36117c2aad20Sopenharmony_ci *		**sizeof**\ (*tuple*\ **->ipv6**)
36127c2aad20Sopenharmony_ci *			Look for an IPv6 socket.
36137c2aad20Sopenharmony_ci *
36147c2aad20Sopenharmony_ci *		If the *netns* is a negative signed 32-bit integer, then the
36157c2aad20Sopenharmony_ci *		socket lookup table in the netns associated with the *ctx*
36167c2aad20Sopenharmony_ci *		will be used. For the TC hooks, this is the netns of the device
36177c2aad20Sopenharmony_ci *		in the skb. For socket hooks, this is the netns of the socket.
36187c2aad20Sopenharmony_ci *		If *netns* is any other signed 32-bit value greater than or
36197c2aad20Sopenharmony_ci *		equal to zero then it specifies the ID of the netns relative to
36207c2aad20Sopenharmony_ci *		the netns associated with the *ctx*. *netns* values beyond the
36217c2aad20Sopenharmony_ci *		range of 32-bit integers are reserved for future use.
36227c2aad20Sopenharmony_ci *
36237c2aad20Sopenharmony_ci *		All values for *flags* are reserved for future usage, and must
36247c2aad20Sopenharmony_ci *		be left at zero.
36257c2aad20Sopenharmony_ci *
36267c2aad20Sopenharmony_ci *		This helper is available only if the kernel was compiled with
36277c2aad20Sopenharmony_ci *		**CONFIG_NET** configuration option.
36287c2aad20Sopenharmony_ci *	Return
36297c2aad20Sopenharmony_ci *		Pointer to **struct bpf_sock**, or **NULL** in case of failure.
36307c2aad20Sopenharmony_ci *		For sockets with reuseport option, the **struct bpf_sock**
36317c2aad20Sopenharmony_ci *		result is from *reuse*\ **->socks**\ [] using the hash of the
36327c2aad20Sopenharmony_ci *		tuple.
36337c2aad20Sopenharmony_ci *
36347c2aad20Sopenharmony_ci * long bpf_sk_release(void *sock)
36357c2aad20Sopenharmony_ci *	Description
36367c2aad20Sopenharmony_ci *		Release the reference held by *sock*. *sock* must be a
36377c2aad20Sopenharmony_ci *		non-**NULL** pointer that was returned from
36387c2aad20Sopenharmony_ci *		**bpf_sk_lookup_xxx**\ ().
36397c2aad20Sopenharmony_ci *	Return
36407c2aad20Sopenharmony_ci *		0 on success, or a negative error in case of failure.
36417c2aad20Sopenharmony_ci *
36427c2aad20Sopenharmony_ci * long bpf_map_push_elem(struct bpf_map *map, const void *value, u64 flags)
36437c2aad20Sopenharmony_ci * 	Description
36447c2aad20Sopenharmony_ci * 		Push an element *value* in *map*. *flags* is one of:
36457c2aad20Sopenharmony_ci *
36467c2aad20Sopenharmony_ci * 		**BPF_EXIST**
36477c2aad20Sopenharmony_ci * 			If the queue/stack is full, the oldest element is
36487c2aad20Sopenharmony_ci * 			removed to make room for this.
36497c2aad20Sopenharmony_ci * 	Return
36507c2aad20Sopenharmony_ci * 		0 on success, or a negative error in case of failure.
36517c2aad20Sopenharmony_ci *
36527c2aad20Sopenharmony_ci * long bpf_map_pop_elem(struct bpf_map *map, void *value)
36537c2aad20Sopenharmony_ci * 	Description
36547c2aad20Sopenharmony_ci * 		Pop an element from *map*.
36557c2aad20Sopenharmony_ci * 	Return
36567c2aad20Sopenharmony_ci * 		0 on success, or a negative error in case of failure.
36577c2aad20Sopenharmony_ci *
36587c2aad20Sopenharmony_ci * long bpf_map_peek_elem(struct bpf_map *map, void *value)
36597c2aad20Sopenharmony_ci * 	Description
36607c2aad20Sopenharmony_ci * 		Get an element from *map* without removing it.
36617c2aad20Sopenharmony_ci * 	Return
36627c2aad20Sopenharmony_ci * 		0 on success, or a negative error in case of failure.
36637c2aad20Sopenharmony_ci *
36647c2aad20Sopenharmony_ci * long bpf_msg_push_data(struct sk_msg_buff *msg, u32 start, u32 len, u64 flags)
36657c2aad20Sopenharmony_ci *	Description
36667c2aad20Sopenharmony_ci *		For socket policies, insert *len* bytes into *msg* at offset
36677c2aad20Sopenharmony_ci *		*start*.
36687c2aad20Sopenharmony_ci *
36697c2aad20Sopenharmony_ci *		If a program of type **BPF_PROG_TYPE_SK_MSG** is run on a
36707c2aad20Sopenharmony_ci *		*msg* it may want to insert metadata or options into the *msg*.
36717c2aad20Sopenharmony_ci *		This can later be read and used by any of the lower layer BPF
36727c2aad20Sopenharmony_ci *		hooks.
36737c2aad20Sopenharmony_ci *
36747c2aad20Sopenharmony_ci *		This helper may fail if under memory pressure (a malloc
36757c2aad20Sopenharmony_ci *		fails) in these cases BPF programs will get an appropriate
36767c2aad20Sopenharmony_ci *		error and BPF programs will need to handle them.
36777c2aad20Sopenharmony_ci *	Return
36787c2aad20Sopenharmony_ci *		0 on success, or a negative error in case of failure.
36797c2aad20Sopenharmony_ci *
36807c2aad20Sopenharmony_ci * long bpf_msg_pop_data(struct sk_msg_buff *msg, u32 start, u32 len, u64 flags)
36817c2aad20Sopenharmony_ci *	Description
36827c2aad20Sopenharmony_ci *		Will remove *len* bytes from a *msg* starting at byte *start*.
36837c2aad20Sopenharmony_ci *		This may result in **ENOMEM** errors under certain situations if
36847c2aad20Sopenharmony_ci *		an allocation and copy are required due to a full ring buffer.
36857c2aad20Sopenharmony_ci *		However, the helper will try to avoid doing the allocation
36867c2aad20Sopenharmony_ci *		if possible. Other errors can occur if input parameters are
36877c2aad20Sopenharmony_ci *		invalid either due to *start* byte not being valid part of *msg*
36887c2aad20Sopenharmony_ci *		payload and/or *pop* value being to large.
36897c2aad20Sopenharmony_ci *	Return
36907c2aad20Sopenharmony_ci *		0 on success, or a negative error in case of failure.
36917c2aad20Sopenharmony_ci *
36927c2aad20Sopenharmony_ci * long bpf_rc_pointer_rel(void *ctx, s32 rel_x, s32 rel_y)
36937c2aad20Sopenharmony_ci *	Description
36947c2aad20Sopenharmony_ci *		This helper is used in programs implementing IR decoding, to
36957c2aad20Sopenharmony_ci *		report a successfully decoded pointer movement.
36967c2aad20Sopenharmony_ci *
36977c2aad20Sopenharmony_ci *		The *ctx* should point to the lirc sample as passed into
36987c2aad20Sopenharmony_ci *		the program.
36997c2aad20Sopenharmony_ci *
37007c2aad20Sopenharmony_ci *		This helper is only available is the kernel was compiled with
37017c2aad20Sopenharmony_ci *		the **CONFIG_BPF_LIRC_MODE2** configuration option set to
37027c2aad20Sopenharmony_ci *		"**y**".
37037c2aad20Sopenharmony_ci *	Return
37047c2aad20Sopenharmony_ci *		0
37057c2aad20Sopenharmony_ci *
37067c2aad20Sopenharmony_ci * long bpf_spin_lock(struct bpf_spin_lock *lock)
37077c2aad20Sopenharmony_ci *	Description
37087c2aad20Sopenharmony_ci *		Acquire a spinlock represented by the pointer *lock*, which is
37097c2aad20Sopenharmony_ci *		stored as part of a value of a map. Taking the lock allows to
37107c2aad20Sopenharmony_ci *		safely update the rest of the fields in that value. The
37117c2aad20Sopenharmony_ci *		spinlock can (and must) later be released with a call to
37127c2aad20Sopenharmony_ci *		**bpf_spin_unlock**\ (\ *lock*\ ).
37137c2aad20Sopenharmony_ci *
37147c2aad20Sopenharmony_ci *		Spinlocks in BPF programs come with a number of restrictions
37157c2aad20Sopenharmony_ci *		and constraints:
37167c2aad20Sopenharmony_ci *
37177c2aad20Sopenharmony_ci *		* **bpf_spin_lock** objects are only allowed inside maps of
37187c2aad20Sopenharmony_ci *		  types **BPF_MAP_TYPE_HASH** and **BPF_MAP_TYPE_ARRAY** (this
37197c2aad20Sopenharmony_ci *		  list could be extended in the future).
37207c2aad20Sopenharmony_ci *		* BTF description of the map is mandatory.
37217c2aad20Sopenharmony_ci *		* The BPF program can take ONE lock at a time, since taking two
37227c2aad20Sopenharmony_ci *		  or more could cause dead locks.
37237c2aad20Sopenharmony_ci *		* Only one **struct bpf_spin_lock** is allowed per map element.
37247c2aad20Sopenharmony_ci *		* When the lock is taken, calls (either BPF to BPF or helpers)
37257c2aad20Sopenharmony_ci *		  are not allowed.
37267c2aad20Sopenharmony_ci *		* The **BPF_LD_ABS** and **BPF_LD_IND** instructions are not
37277c2aad20Sopenharmony_ci *		  allowed inside a spinlock-ed region.
37287c2aad20Sopenharmony_ci *		* The BPF program MUST call **bpf_spin_unlock**\ () to release
37297c2aad20Sopenharmony_ci *		  the lock, on all execution paths, before it returns.
37307c2aad20Sopenharmony_ci *		* The BPF program can access **struct bpf_spin_lock** only via
37317c2aad20Sopenharmony_ci *		  the **bpf_spin_lock**\ () and **bpf_spin_unlock**\ ()
37327c2aad20Sopenharmony_ci *		  helpers. Loading or storing data into the **struct
37337c2aad20Sopenharmony_ci *		  bpf_spin_lock** *lock*\ **;** field of a map is not allowed.
37347c2aad20Sopenharmony_ci *		* To use the **bpf_spin_lock**\ () helper, the BTF description
37357c2aad20Sopenharmony_ci *		  of the map value must be a struct and have **struct
37367c2aad20Sopenharmony_ci *		  bpf_spin_lock** *anyname*\ **;** field at the top level.
37377c2aad20Sopenharmony_ci *		  Nested lock inside another struct is not allowed.
37387c2aad20Sopenharmony_ci *		* The **struct bpf_spin_lock** *lock* field in a map value must
37397c2aad20Sopenharmony_ci *		  be aligned on a multiple of 4 bytes in that value.
37407c2aad20Sopenharmony_ci *		* Syscall with command **BPF_MAP_LOOKUP_ELEM** does not copy
37417c2aad20Sopenharmony_ci *		  the **bpf_spin_lock** field to user space.
37427c2aad20Sopenharmony_ci *		* Syscall with command **BPF_MAP_UPDATE_ELEM**, or update from
37437c2aad20Sopenharmony_ci *		  a BPF program, do not update the **bpf_spin_lock** field.
37447c2aad20Sopenharmony_ci *		* **bpf_spin_lock** cannot be on the stack or inside a
37457c2aad20Sopenharmony_ci *		  networking packet (it can only be inside of a map values).
37467c2aad20Sopenharmony_ci *		* **bpf_spin_lock** is available to root only.
37477c2aad20Sopenharmony_ci *		* Tracing programs and socket filter programs cannot use
37487c2aad20Sopenharmony_ci *		  **bpf_spin_lock**\ () due to insufficient preemption checks
37497c2aad20Sopenharmony_ci *		  (but this may change in the future).
37507c2aad20Sopenharmony_ci *		* **bpf_spin_lock** is not allowed in inner maps of map-in-map.
37517c2aad20Sopenharmony_ci *	Return
37527c2aad20Sopenharmony_ci *		0
37537c2aad20Sopenharmony_ci *
37547c2aad20Sopenharmony_ci * long bpf_spin_unlock(struct bpf_spin_lock *lock)
37557c2aad20Sopenharmony_ci *	Description
37567c2aad20Sopenharmony_ci *		Release the *lock* previously locked by a call to
37577c2aad20Sopenharmony_ci *		**bpf_spin_lock**\ (\ *lock*\ ).
37587c2aad20Sopenharmony_ci *	Return
37597c2aad20Sopenharmony_ci *		0
37607c2aad20Sopenharmony_ci *
37617c2aad20Sopenharmony_ci * struct bpf_sock *bpf_sk_fullsock(struct bpf_sock *sk)
37627c2aad20Sopenharmony_ci *	Description
37637c2aad20Sopenharmony_ci *		This helper gets a **struct bpf_sock** pointer such
37647c2aad20Sopenharmony_ci *		that all the fields in this **bpf_sock** can be accessed.
37657c2aad20Sopenharmony_ci *	Return
37667c2aad20Sopenharmony_ci *		A **struct bpf_sock** pointer on success, or **NULL** in
37677c2aad20Sopenharmony_ci *		case of failure.
37687c2aad20Sopenharmony_ci *
37697c2aad20Sopenharmony_ci * struct bpf_tcp_sock *bpf_tcp_sock(struct bpf_sock *sk)
37707c2aad20Sopenharmony_ci *	Description
37717c2aad20Sopenharmony_ci *		This helper gets a **struct bpf_tcp_sock** pointer from a
37727c2aad20Sopenharmony_ci *		**struct bpf_sock** pointer.
37737c2aad20Sopenharmony_ci *	Return
37747c2aad20Sopenharmony_ci *		A **struct bpf_tcp_sock** pointer on success, or **NULL** in
37757c2aad20Sopenharmony_ci *		case of failure.
37767c2aad20Sopenharmony_ci *
37777c2aad20Sopenharmony_ci * long bpf_skb_ecn_set_ce(struct sk_buff *skb)
37787c2aad20Sopenharmony_ci *	Description
37797c2aad20Sopenharmony_ci *		Set ECN (Explicit Congestion Notification) field of IP header
37807c2aad20Sopenharmony_ci *		to **CE** (Congestion Encountered) if current value is **ECT**
37817c2aad20Sopenharmony_ci *		(ECN Capable Transport). Otherwise, do nothing. Works with IPv6
37827c2aad20Sopenharmony_ci *		and IPv4.
37837c2aad20Sopenharmony_ci *	Return
37847c2aad20Sopenharmony_ci *		1 if the **CE** flag is set (either by the current helper call
37857c2aad20Sopenharmony_ci *		or because it was already present), 0 if it is not set.
37867c2aad20Sopenharmony_ci *
37877c2aad20Sopenharmony_ci * struct bpf_sock *bpf_get_listener_sock(struct bpf_sock *sk)
37887c2aad20Sopenharmony_ci *	Description
37897c2aad20Sopenharmony_ci *		Return a **struct bpf_sock** pointer in **TCP_LISTEN** state.
37907c2aad20Sopenharmony_ci *		**bpf_sk_release**\ () is unnecessary and not allowed.
37917c2aad20Sopenharmony_ci *	Return
37927c2aad20Sopenharmony_ci *		A **struct bpf_sock** pointer on success, or **NULL** in
37937c2aad20Sopenharmony_ci *		case of failure.
37947c2aad20Sopenharmony_ci *
37957c2aad20Sopenharmony_ci * struct bpf_sock *bpf_skc_lookup_tcp(void *ctx, struct bpf_sock_tuple *tuple, u32 tuple_size, u64 netns, u64 flags)
37967c2aad20Sopenharmony_ci *	Description
37977c2aad20Sopenharmony_ci *		Look for TCP socket matching *tuple*, optionally in a child
37987c2aad20Sopenharmony_ci *		network namespace *netns*. The return value must be checked,
37997c2aad20Sopenharmony_ci *		and if non-**NULL**, released via **bpf_sk_release**\ ().
38007c2aad20Sopenharmony_ci *
38017c2aad20Sopenharmony_ci *		This function is identical to **bpf_sk_lookup_tcp**\ (), except
38027c2aad20Sopenharmony_ci *		that it also returns timewait or request sockets. Use
38037c2aad20Sopenharmony_ci *		**bpf_sk_fullsock**\ () or **bpf_tcp_sock**\ () to access the
38047c2aad20Sopenharmony_ci *		full structure.
38057c2aad20Sopenharmony_ci *
38067c2aad20Sopenharmony_ci *		This helper is available only if the kernel was compiled with
38077c2aad20Sopenharmony_ci *		**CONFIG_NET** configuration option.
38087c2aad20Sopenharmony_ci *	Return
38097c2aad20Sopenharmony_ci *		Pointer to **struct bpf_sock**, or **NULL** in case of failure.
38107c2aad20Sopenharmony_ci *		For sockets with reuseport option, the **struct bpf_sock**
38117c2aad20Sopenharmony_ci *		result is from *reuse*\ **->socks**\ [] using the hash of the
38127c2aad20Sopenharmony_ci *		tuple.
38137c2aad20Sopenharmony_ci *
38147c2aad20Sopenharmony_ci * long bpf_tcp_check_syncookie(void *sk, void *iph, u32 iph_len, struct tcphdr *th, u32 th_len)
38157c2aad20Sopenharmony_ci * 	Description
38167c2aad20Sopenharmony_ci * 		Check whether *iph* and *th* contain a valid SYN cookie ACK for
38177c2aad20Sopenharmony_ci * 		the listening socket in *sk*.
38187c2aad20Sopenharmony_ci *
38197c2aad20Sopenharmony_ci * 		*iph* points to the start of the IPv4 or IPv6 header, while
38207c2aad20Sopenharmony_ci * 		*iph_len* contains **sizeof**\ (**struct iphdr**) or
38217c2aad20Sopenharmony_ci * 		**sizeof**\ (**struct ipv6hdr**).
38227c2aad20Sopenharmony_ci *
38237c2aad20Sopenharmony_ci * 		*th* points to the start of the TCP header, while *th_len*
38247c2aad20Sopenharmony_ci *		contains the length of the TCP header (at least
38257c2aad20Sopenharmony_ci *		**sizeof**\ (**struct tcphdr**)).
38267c2aad20Sopenharmony_ci * 	Return
38277c2aad20Sopenharmony_ci * 		0 if *iph* and *th* are a valid SYN cookie ACK, or a negative
38287c2aad20Sopenharmony_ci * 		error otherwise.
38297c2aad20Sopenharmony_ci *
38307c2aad20Sopenharmony_ci * long bpf_sysctl_get_name(struct bpf_sysctl *ctx, char *buf, size_t buf_len, u64 flags)
38317c2aad20Sopenharmony_ci *	Description
38327c2aad20Sopenharmony_ci *		Get name of sysctl in /proc/sys/ and copy it into provided by
38337c2aad20Sopenharmony_ci *		program buffer *buf* of size *buf_len*.
38347c2aad20Sopenharmony_ci *
38357c2aad20Sopenharmony_ci *		The buffer is always NUL terminated, unless it's zero-sized.
38367c2aad20Sopenharmony_ci *
38377c2aad20Sopenharmony_ci *		If *flags* is zero, full name (e.g. "net/ipv4/tcp_mem") is
38387c2aad20Sopenharmony_ci *		copied. Use **BPF_F_SYSCTL_BASE_NAME** flag to copy base name
38397c2aad20Sopenharmony_ci *		only (e.g. "tcp_mem").
38407c2aad20Sopenharmony_ci *	Return
38417c2aad20Sopenharmony_ci *		Number of character copied (not including the trailing NUL).
38427c2aad20Sopenharmony_ci *
38437c2aad20Sopenharmony_ci *		**-E2BIG** if the buffer wasn't big enough (*buf* will contain
38447c2aad20Sopenharmony_ci *		truncated name in this case).
38457c2aad20Sopenharmony_ci *
38467c2aad20Sopenharmony_ci * long bpf_sysctl_get_current_value(struct bpf_sysctl *ctx, char *buf, size_t buf_len)
38477c2aad20Sopenharmony_ci *	Description
38487c2aad20Sopenharmony_ci *		Get current value of sysctl as it is presented in /proc/sys
38497c2aad20Sopenharmony_ci *		(incl. newline, etc), and copy it as a string into provided
38507c2aad20Sopenharmony_ci *		by program buffer *buf* of size *buf_len*.
38517c2aad20Sopenharmony_ci *
38527c2aad20Sopenharmony_ci *		The whole value is copied, no matter what file position user
38537c2aad20Sopenharmony_ci *		space issued e.g. sys_read at.
38547c2aad20Sopenharmony_ci *
38557c2aad20Sopenharmony_ci *		The buffer is always NUL terminated, unless it's zero-sized.
38567c2aad20Sopenharmony_ci *	Return
38577c2aad20Sopenharmony_ci *		Number of character copied (not including the trailing NUL).
38587c2aad20Sopenharmony_ci *
38597c2aad20Sopenharmony_ci *		**-E2BIG** if the buffer wasn't big enough (*buf* will contain
38607c2aad20Sopenharmony_ci *		truncated name in this case).
38617c2aad20Sopenharmony_ci *
38627c2aad20Sopenharmony_ci *		**-EINVAL** if current value was unavailable, e.g. because
38637c2aad20Sopenharmony_ci *		sysctl is uninitialized and read returns -EIO for it.
38647c2aad20Sopenharmony_ci *
38657c2aad20Sopenharmony_ci * long bpf_sysctl_get_new_value(struct bpf_sysctl *ctx, char *buf, size_t buf_len)
38667c2aad20Sopenharmony_ci *	Description
38677c2aad20Sopenharmony_ci *		Get new value being written by user space to sysctl (before
38687c2aad20Sopenharmony_ci *		the actual write happens) and copy it as a string into
38697c2aad20Sopenharmony_ci *		provided by program buffer *buf* of size *buf_len*.
38707c2aad20Sopenharmony_ci *
38717c2aad20Sopenharmony_ci *		User space may write new value at file position > 0.
38727c2aad20Sopenharmony_ci *
38737c2aad20Sopenharmony_ci *		The buffer is always NUL terminated, unless it's zero-sized.
38747c2aad20Sopenharmony_ci *	Return
38757c2aad20Sopenharmony_ci *		Number of character copied (not including the trailing NUL).
38767c2aad20Sopenharmony_ci *
38777c2aad20Sopenharmony_ci *		**-E2BIG** if the buffer wasn't big enough (*buf* will contain
38787c2aad20Sopenharmony_ci *		truncated name in this case).
38797c2aad20Sopenharmony_ci *
38807c2aad20Sopenharmony_ci *		**-EINVAL** if sysctl is being read.
38817c2aad20Sopenharmony_ci *
38827c2aad20Sopenharmony_ci * long bpf_sysctl_set_new_value(struct bpf_sysctl *ctx, const char *buf, size_t buf_len)
38837c2aad20Sopenharmony_ci *	Description
38847c2aad20Sopenharmony_ci *		Override new value being written by user space to sysctl with
38857c2aad20Sopenharmony_ci *		value provided by program in buffer *buf* of size *buf_len*.
38867c2aad20Sopenharmony_ci *
38877c2aad20Sopenharmony_ci *		*buf* should contain a string in same form as provided by user
38887c2aad20Sopenharmony_ci *		space on sysctl write.
38897c2aad20Sopenharmony_ci *
38907c2aad20Sopenharmony_ci *		User space may write new value at file position > 0. To override
38917c2aad20Sopenharmony_ci *		the whole sysctl value file position should be set to zero.
38927c2aad20Sopenharmony_ci *	Return
38937c2aad20Sopenharmony_ci *		0 on success.
38947c2aad20Sopenharmony_ci *
38957c2aad20Sopenharmony_ci *		**-E2BIG** if the *buf_len* is too big.
38967c2aad20Sopenharmony_ci *
38977c2aad20Sopenharmony_ci *		**-EINVAL** if sysctl is being read.
38987c2aad20Sopenharmony_ci *
38997c2aad20Sopenharmony_ci * long bpf_strtol(const char *buf, size_t buf_len, u64 flags, long *res)
39007c2aad20Sopenharmony_ci *	Description
39017c2aad20Sopenharmony_ci *		Convert the initial part of the string from buffer *buf* of
39027c2aad20Sopenharmony_ci *		size *buf_len* to a long integer according to the given base
39037c2aad20Sopenharmony_ci *		and save the result in *res*.
39047c2aad20Sopenharmony_ci *
39057c2aad20Sopenharmony_ci *		The string may begin with an arbitrary amount of white space
39067c2aad20Sopenharmony_ci *		(as determined by **isspace**\ (3)) followed by a single
39077c2aad20Sopenharmony_ci *		optional '**-**' sign.
39087c2aad20Sopenharmony_ci *
39097c2aad20Sopenharmony_ci *		Five least significant bits of *flags* encode base, other bits
39107c2aad20Sopenharmony_ci *		are currently unused.
39117c2aad20Sopenharmony_ci *
39127c2aad20Sopenharmony_ci *		Base must be either 8, 10, 16 or 0 to detect it automatically
39137c2aad20Sopenharmony_ci *		similar to user space **strtol**\ (3).
39147c2aad20Sopenharmony_ci *	Return
39157c2aad20Sopenharmony_ci *		Number of characters consumed on success. Must be positive but
39167c2aad20Sopenharmony_ci *		no more than *buf_len*.
39177c2aad20Sopenharmony_ci *
39187c2aad20Sopenharmony_ci *		**-EINVAL** if no valid digits were found or unsupported base
39197c2aad20Sopenharmony_ci *		was provided.
39207c2aad20Sopenharmony_ci *
39217c2aad20Sopenharmony_ci *		**-ERANGE** if resulting value was out of range.
39227c2aad20Sopenharmony_ci *
39237c2aad20Sopenharmony_ci * long bpf_strtoul(const char *buf, size_t buf_len, u64 flags, unsigned long *res)
39247c2aad20Sopenharmony_ci *	Description
39257c2aad20Sopenharmony_ci *		Convert the initial part of the string from buffer *buf* of
39267c2aad20Sopenharmony_ci *		size *buf_len* to an unsigned long integer according to the
39277c2aad20Sopenharmony_ci *		given base and save the result in *res*.
39287c2aad20Sopenharmony_ci *
39297c2aad20Sopenharmony_ci *		The string may begin with an arbitrary amount of white space
39307c2aad20Sopenharmony_ci *		(as determined by **isspace**\ (3)).
39317c2aad20Sopenharmony_ci *
39327c2aad20Sopenharmony_ci *		Five least significant bits of *flags* encode base, other bits
39337c2aad20Sopenharmony_ci *		are currently unused.
39347c2aad20Sopenharmony_ci *
39357c2aad20Sopenharmony_ci *		Base must be either 8, 10, 16 or 0 to detect it automatically
39367c2aad20Sopenharmony_ci *		similar to user space **strtoul**\ (3).
39377c2aad20Sopenharmony_ci *	Return
39387c2aad20Sopenharmony_ci *		Number of characters consumed on success. Must be positive but
39397c2aad20Sopenharmony_ci *		no more than *buf_len*.
39407c2aad20Sopenharmony_ci *
39417c2aad20Sopenharmony_ci *		**-EINVAL** if no valid digits were found or unsupported base
39427c2aad20Sopenharmony_ci *		was provided.
39437c2aad20Sopenharmony_ci *
39447c2aad20Sopenharmony_ci *		**-ERANGE** if resulting value was out of range.
39457c2aad20Sopenharmony_ci *
39467c2aad20Sopenharmony_ci * void *bpf_sk_storage_get(struct bpf_map *map, void *sk, void *value, u64 flags)
39477c2aad20Sopenharmony_ci *	Description
39487c2aad20Sopenharmony_ci *		Get a bpf-local-storage from a *sk*.
39497c2aad20Sopenharmony_ci *
39507c2aad20Sopenharmony_ci *		Logically, it could be thought of getting the value from
39517c2aad20Sopenharmony_ci *		a *map* with *sk* as the **key**.  From this
39527c2aad20Sopenharmony_ci *		perspective,  the usage is not much different from
39537c2aad20Sopenharmony_ci *		**bpf_map_lookup_elem**\ (*map*, **&**\ *sk*) except this
39547c2aad20Sopenharmony_ci *		helper enforces the key must be a full socket and the map must
39557c2aad20Sopenharmony_ci *		be a **BPF_MAP_TYPE_SK_STORAGE** also.
39567c2aad20Sopenharmony_ci *
39577c2aad20Sopenharmony_ci *		Underneath, the value is stored locally at *sk* instead of
39587c2aad20Sopenharmony_ci *		the *map*.  The *map* is used as the bpf-local-storage
39597c2aad20Sopenharmony_ci *		"type". The bpf-local-storage "type" (i.e. the *map*) is
39607c2aad20Sopenharmony_ci *		searched against all bpf-local-storages residing at *sk*.
39617c2aad20Sopenharmony_ci *
39627c2aad20Sopenharmony_ci *		*sk* is a kernel **struct sock** pointer for LSM program.
39637c2aad20Sopenharmony_ci *		*sk* is a **struct bpf_sock** pointer for other program types.
39647c2aad20Sopenharmony_ci *
39657c2aad20Sopenharmony_ci *		An optional *flags* (**BPF_SK_STORAGE_GET_F_CREATE**) can be
39667c2aad20Sopenharmony_ci *		used such that a new bpf-local-storage will be
39677c2aad20Sopenharmony_ci *		created if one does not exist.  *value* can be used
39687c2aad20Sopenharmony_ci *		together with **BPF_SK_STORAGE_GET_F_CREATE** to specify
39697c2aad20Sopenharmony_ci *		the initial value of a bpf-local-storage.  If *value* is
39707c2aad20Sopenharmony_ci *		**NULL**, the new bpf-local-storage will be zero initialized.
39717c2aad20Sopenharmony_ci *	Return
39727c2aad20Sopenharmony_ci *		A bpf-local-storage pointer is returned on success.
39737c2aad20Sopenharmony_ci *
39747c2aad20Sopenharmony_ci *		**NULL** if not found or there was an error in adding
39757c2aad20Sopenharmony_ci *		a new bpf-local-storage.
39767c2aad20Sopenharmony_ci *
39777c2aad20Sopenharmony_ci * long bpf_sk_storage_delete(struct bpf_map *map, void *sk)
39787c2aad20Sopenharmony_ci *	Description
39797c2aad20Sopenharmony_ci *		Delete a bpf-local-storage from a *sk*.
39807c2aad20Sopenharmony_ci *	Return
39817c2aad20Sopenharmony_ci *		0 on success.
39827c2aad20Sopenharmony_ci *
39837c2aad20Sopenharmony_ci *		**-ENOENT** if the bpf-local-storage cannot be found.
39847c2aad20Sopenharmony_ci *		**-EINVAL** if sk is not a fullsock (e.g. a request_sock).
39857c2aad20Sopenharmony_ci *
39867c2aad20Sopenharmony_ci * long bpf_send_signal(u32 sig)
39877c2aad20Sopenharmony_ci *	Description
39887c2aad20Sopenharmony_ci *		Send signal *sig* to the process of the current task.
39897c2aad20Sopenharmony_ci *		The signal may be delivered to any of this process's threads.
39907c2aad20Sopenharmony_ci *	Return
39917c2aad20Sopenharmony_ci *		0 on success or successfully queued.
39927c2aad20Sopenharmony_ci *
39937c2aad20Sopenharmony_ci *		**-EBUSY** if work queue under nmi is full.
39947c2aad20Sopenharmony_ci *
39957c2aad20Sopenharmony_ci *		**-EINVAL** if *sig* is invalid.
39967c2aad20Sopenharmony_ci *
39977c2aad20Sopenharmony_ci *		**-EPERM** if no permission to send the *sig*.
39987c2aad20Sopenharmony_ci *
39997c2aad20Sopenharmony_ci *		**-EAGAIN** if bpf program can try again.
40007c2aad20Sopenharmony_ci *
40017c2aad20Sopenharmony_ci * s64 bpf_tcp_gen_syncookie(void *sk, void *iph, u32 iph_len, struct tcphdr *th, u32 th_len)
40027c2aad20Sopenharmony_ci *	Description
40037c2aad20Sopenharmony_ci *		Try to issue a SYN cookie for the packet with corresponding
40047c2aad20Sopenharmony_ci *		IP/TCP headers, *iph* and *th*, on the listening socket in *sk*.
40057c2aad20Sopenharmony_ci *
40067c2aad20Sopenharmony_ci *		*iph* points to the start of the IPv4 or IPv6 header, while
40077c2aad20Sopenharmony_ci *		*iph_len* contains **sizeof**\ (**struct iphdr**) or
40087c2aad20Sopenharmony_ci *		**sizeof**\ (**struct ipv6hdr**).
40097c2aad20Sopenharmony_ci *
40107c2aad20Sopenharmony_ci *		*th* points to the start of the TCP header, while *th_len*
40117c2aad20Sopenharmony_ci *		contains the length of the TCP header with options (at least
40127c2aad20Sopenharmony_ci *		**sizeof**\ (**struct tcphdr**)).
40137c2aad20Sopenharmony_ci *	Return
40147c2aad20Sopenharmony_ci *		On success, lower 32 bits hold the generated SYN cookie in
40157c2aad20Sopenharmony_ci *		followed by 16 bits which hold the MSS value for that cookie,
40167c2aad20Sopenharmony_ci *		and the top 16 bits are unused.
40177c2aad20Sopenharmony_ci *
40187c2aad20Sopenharmony_ci *		On failure, the returned value is one of the following:
40197c2aad20Sopenharmony_ci *
40207c2aad20Sopenharmony_ci *		**-EINVAL** SYN cookie cannot be issued due to error
40217c2aad20Sopenharmony_ci *
40227c2aad20Sopenharmony_ci *		**-ENOENT** SYN cookie should not be issued (no SYN flood)
40237c2aad20Sopenharmony_ci *
40247c2aad20Sopenharmony_ci *		**-EOPNOTSUPP** kernel configuration does not enable SYN cookies
40257c2aad20Sopenharmony_ci *
40267c2aad20Sopenharmony_ci *		**-EPROTONOSUPPORT** IP packet version is not 4 or 6
40277c2aad20Sopenharmony_ci *
40287c2aad20Sopenharmony_ci * long bpf_skb_output(void *ctx, struct bpf_map *map, u64 flags, void *data, u64 size)
40297c2aad20Sopenharmony_ci * 	Description
40307c2aad20Sopenharmony_ci * 		Write raw *data* blob into a special BPF perf event held by
40317c2aad20Sopenharmony_ci * 		*map* of type **BPF_MAP_TYPE_PERF_EVENT_ARRAY**. This perf
40327c2aad20Sopenharmony_ci * 		event must have the following attributes: **PERF_SAMPLE_RAW**
40337c2aad20Sopenharmony_ci * 		as **sample_type**, **PERF_TYPE_SOFTWARE** as **type**, and
40347c2aad20Sopenharmony_ci * 		**PERF_COUNT_SW_BPF_OUTPUT** as **config**.
40357c2aad20Sopenharmony_ci *
40367c2aad20Sopenharmony_ci * 		The *flags* are used to indicate the index in *map* for which
40377c2aad20Sopenharmony_ci * 		the value must be put, masked with **BPF_F_INDEX_MASK**.
40387c2aad20Sopenharmony_ci * 		Alternatively, *flags* can be set to **BPF_F_CURRENT_CPU**
40397c2aad20Sopenharmony_ci * 		to indicate that the index of the current CPU core should be
40407c2aad20Sopenharmony_ci * 		used.
40417c2aad20Sopenharmony_ci *
40427c2aad20Sopenharmony_ci * 		The value to write, of *size*, is passed through eBPF stack and
40437c2aad20Sopenharmony_ci * 		pointed by *data*.
40447c2aad20Sopenharmony_ci *
40457c2aad20Sopenharmony_ci * 		*ctx* is a pointer to in-kernel struct sk_buff.
40467c2aad20Sopenharmony_ci *
40477c2aad20Sopenharmony_ci * 		This helper is similar to **bpf_perf_event_output**\ () but
40487c2aad20Sopenharmony_ci * 		restricted to raw_tracepoint bpf programs.
40497c2aad20Sopenharmony_ci * 	Return
40507c2aad20Sopenharmony_ci * 		0 on success, or a negative error in case of failure.
40517c2aad20Sopenharmony_ci *
40527c2aad20Sopenharmony_ci * long bpf_probe_read_user(void *dst, u32 size, const void *unsafe_ptr)
40537c2aad20Sopenharmony_ci * 	Description
40547c2aad20Sopenharmony_ci * 		Safely attempt to read *size* bytes from user space address
40557c2aad20Sopenharmony_ci * 		*unsafe_ptr* and store the data in *dst*.
40567c2aad20Sopenharmony_ci * 	Return
40577c2aad20Sopenharmony_ci * 		0 on success, or a negative error in case of failure.
40587c2aad20Sopenharmony_ci *
40597c2aad20Sopenharmony_ci * long bpf_probe_read_kernel(void *dst, u32 size, const void *unsafe_ptr)
40607c2aad20Sopenharmony_ci * 	Description
40617c2aad20Sopenharmony_ci * 		Safely attempt to read *size* bytes from kernel space address
40627c2aad20Sopenharmony_ci * 		*unsafe_ptr* and store the data in *dst*.
40637c2aad20Sopenharmony_ci * 	Return
40647c2aad20Sopenharmony_ci * 		0 on success, or a negative error in case of failure.
40657c2aad20Sopenharmony_ci *
40667c2aad20Sopenharmony_ci * long bpf_probe_read_user_str(void *dst, u32 size, const void *unsafe_ptr)
40677c2aad20Sopenharmony_ci * 	Description
40687c2aad20Sopenharmony_ci * 		Copy a NUL terminated string from an unsafe user address
40697c2aad20Sopenharmony_ci * 		*unsafe_ptr* to *dst*. The *size* should include the
40707c2aad20Sopenharmony_ci * 		terminating NUL byte. In case the string length is smaller than
40717c2aad20Sopenharmony_ci * 		*size*, the target is not padded with further NUL bytes. If the
40727c2aad20Sopenharmony_ci * 		string length is larger than *size*, just *size*-1 bytes are
40737c2aad20Sopenharmony_ci * 		copied and the last byte is set to NUL.
40747c2aad20Sopenharmony_ci *
40757c2aad20Sopenharmony_ci * 		On success, returns the number of bytes that were written,
40767c2aad20Sopenharmony_ci * 		including the terminal NUL. This makes this helper useful in
40777c2aad20Sopenharmony_ci * 		tracing programs for reading strings, and more importantly to
40787c2aad20Sopenharmony_ci * 		get its length at runtime. See the following snippet:
40797c2aad20Sopenharmony_ci *
40807c2aad20Sopenharmony_ci * 		::
40817c2aad20Sopenharmony_ci *
40827c2aad20Sopenharmony_ci * 			SEC("kprobe/sys_open")
40837c2aad20Sopenharmony_ci * 			void bpf_sys_open(struct pt_regs *ctx)
40847c2aad20Sopenharmony_ci * 			{
40857c2aad20Sopenharmony_ci * 			        char buf[PATHLEN]; // PATHLEN is defined to 256
40867c2aad20Sopenharmony_ci * 			        int res = bpf_probe_read_user_str(buf, sizeof(buf),
40877c2aad20Sopenharmony_ci * 				                                  ctx->di);
40887c2aad20Sopenharmony_ci *
40897c2aad20Sopenharmony_ci * 				// Consume buf, for example push it to
40907c2aad20Sopenharmony_ci * 				// userspace via bpf_perf_event_output(); we
40917c2aad20Sopenharmony_ci * 				// can use res (the string length) as event
40927c2aad20Sopenharmony_ci * 				// size, after checking its boundaries.
40937c2aad20Sopenharmony_ci * 			}
40947c2aad20Sopenharmony_ci *
40957c2aad20Sopenharmony_ci * 		In comparison, using **bpf_probe_read_user**\ () helper here
40967c2aad20Sopenharmony_ci * 		instead to read the string would require to estimate the length
40977c2aad20Sopenharmony_ci * 		at compile time, and would often result in copying more memory
40987c2aad20Sopenharmony_ci * 		than necessary.
40997c2aad20Sopenharmony_ci *
41007c2aad20Sopenharmony_ci * 		Another useful use case is when parsing individual process
41017c2aad20Sopenharmony_ci * 		arguments or individual environment variables navigating
41027c2aad20Sopenharmony_ci * 		*current*\ **->mm->arg_start** and *current*\
41037c2aad20Sopenharmony_ci * 		**->mm->env_start**: using this helper and the return value,
41047c2aad20Sopenharmony_ci * 		one can quickly iterate at the right offset of the memory area.
41057c2aad20Sopenharmony_ci * 	Return
41067c2aad20Sopenharmony_ci * 		On success, the strictly positive length of the output string,
41077c2aad20Sopenharmony_ci * 		including the trailing NUL character. On error, a negative
41087c2aad20Sopenharmony_ci * 		value.
41097c2aad20Sopenharmony_ci *
41107c2aad20Sopenharmony_ci * long bpf_probe_read_kernel_str(void *dst, u32 size, const void *unsafe_ptr)
41117c2aad20Sopenharmony_ci * 	Description
41127c2aad20Sopenharmony_ci * 		Copy a NUL terminated string from an unsafe kernel address *unsafe_ptr*
41137c2aad20Sopenharmony_ci * 		to *dst*. Same semantics as with **bpf_probe_read_user_str**\ () apply.
41147c2aad20Sopenharmony_ci * 	Return
41157c2aad20Sopenharmony_ci * 		On success, the strictly positive length of the string, including
41167c2aad20Sopenharmony_ci * 		the trailing NUL character. On error, a negative value.
41177c2aad20Sopenharmony_ci *
41187c2aad20Sopenharmony_ci * long bpf_tcp_send_ack(void *tp, u32 rcv_nxt)
41197c2aad20Sopenharmony_ci *	Description
41207c2aad20Sopenharmony_ci *		Send out a tcp-ack. *tp* is the in-kernel struct **tcp_sock**.
41217c2aad20Sopenharmony_ci *		*rcv_nxt* is the ack_seq to be sent out.
41227c2aad20Sopenharmony_ci *	Return
41237c2aad20Sopenharmony_ci *		0 on success, or a negative error in case of failure.
41247c2aad20Sopenharmony_ci *
41257c2aad20Sopenharmony_ci * long bpf_send_signal_thread(u32 sig)
41267c2aad20Sopenharmony_ci *	Description
41277c2aad20Sopenharmony_ci *		Send signal *sig* to the thread corresponding to the current task.
41287c2aad20Sopenharmony_ci *	Return
41297c2aad20Sopenharmony_ci *		0 on success or successfully queued.
41307c2aad20Sopenharmony_ci *
41317c2aad20Sopenharmony_ci *		**-EBUSY** if work queue under nmi is full.
41327c2aad20Sopenharmony_ci *
41337c2aad20Sopenharmony_ci *		**-EINVAL** if *sig* is invalid.
41347c2aad20Sopenharmony_ci *
41357c2aad20Sopenharmony_ci *		**-EPERM** if no permission to send the *sig*.
41367c2aad20Sopenharmony_ci *
41377c2aad20Sopenharmony_ci *		**-EAGAIN** if bpf program can try again.
41387c2aad20Sopenharmony_ci *
41397c2aad20Sopenharmony_ci * u64 bpf_jiffies64(void)
41407c2aad20Sopenharmony_ci *	Description
41417c2aad20Sopenharmony_ci *		Obtain the 64bit jiffies
41427c2aad20Sopenharmony_ci *	Return
41437c2aad20Sopenharmony_ci *		The 64 bit jiffies
41447c2aad20Sopenharmony_ci *
41457c2aad20Sopenharmony_ci * long bpf_read_branch_records(struct bpf_perf_event_data *ctx, void *buf, u32 size, u64 flags)
41467c2aad20Sopenharmony_ci *	Description
41477c2aad20Sopenharmony_ci *		For an eBPF program attached to a perf event, retrieve the
41487c2aad20Sopenharmony_ci *		branch records (**struct perf_branch_entry**) associated to *ctx*
41497c2aad20Sopenharmony_ci *		and store it in the buffer pointed by *buf* up to size
41507c2aad20Sopenharmony_ci *		*size* bytes.
41517c2aad20Sopenharmony_ci *	Return
41527c2aad20Sopenharmony_ci *		On success, number of bytes written to *buf*. On error, a
41537c2aad20Sopenharmony_ci *		negative value.
41547c2aad20Sopenharmony_ci *
41557c2aad20Sopenharmony_ci *		The *flags* can be set to **BPF_F_GET_BRANCH_RECORDS_SIZE** to
41567c2aad20Sopenharmony_ci *		instead return the number of bytes required to store all the
41577c2aad20Sopenharmony_ci *		branch entries. If this flag is set, *buf* may be NULL.
41587c2aad20Sopenharmony_ci *
41597c2aad20Sopenharmony_ci *		**-EINVAL** if arguments invalid or **size** not a multiple
41607c2aad20Sopenharmony_ci *		of **sizeof**\ (**struct perf_branch_entry**\ ).
41617c2aad20Sopenharmony_ci *
41627c2aad20Sopenharmony_ci *		**-ENOENT** if architecture does not support branch records.
41637c2aad20Sopenharmony_ci *
41647c2aad20Sopenharmony_ci * long bpf_get_ns_current_pid_tgid(u64 dev, u64 ino, struct bpf_pidns_info *nsdata, u32 size)
41657c2aad20Sopenharmony_ci *	Description
41667c2aad20Sopenharmony_ci *		Returns 0 on success, values for *pid* and *tgid* as seen from the current
41677c2aad20Sopenharmony_ci *		*namespace* will be returned in *nsdata*.
41687c2aad20Sopenharmony_ci *	Return
41697c2aad20Sopenharmony_ci *		0 on success, or one of the following in case of failure:
41707c2aad20Sopenharmony_ci *
41717c2aad20Sopenharmony_ci *		**-EINVAL** if dev and inum supplied don't match dev_t and inode number
41727c2aad20Sopenharmony_ci *              with nsfs of current task, or if dev conversion to dev_t lost high bits.
41737c2aad20Sopenharmony_ci *
41747c2aad20Sopenharmony_ci *		**-ENOENT** if pidns does not exists for the current task.
41757c2aad20Sopenharmony_ci *
41767c2aad20Sopenharmony_ci * long bpf_xdp_output(void *ctx, struct bpf_map *map, u64 flags, void *data, u64 size)
41777c2aad20Sopenharmony_ci *	Description
41787c2aad20Sopenharmony_ci *		Write raw *data* blob into a special BPF perf event held by
41797c2aad20Sopenharmony_ci *		*map* of type **BPF_MAP_TYPE_PERF_EVENT_ARRAY**. This perf
41807c2aad20Sopenharmony_ci *		event must have the following attributes: **PERF_SAMPLE_RAW**
41817c2aad20Sopenharmony_ci *		as **sample_type**, **PERF_TYPE_SOFTWARE** as **type**, and
41827c2aad20Sopenharmony_ci *		**PERF_COUNT_SW_BPF_OUTPUT** as **config**.
41837c2aad20Sopenharmony_ci *
41847c2aad20Sopenharmony_ci *		The *flags* are used to indicate the index in *map* for which
41857c2aad20Sopenharmony_ci *		the value must be put, masked with **BPF_F_INDEX_MASK**.
41867c2aad20Sopenharmony_ci *		Alternatively, *flags* can be set to **BPF_F_CURRENT_CPU**
41877c2aad20Sopenharmony_ci *		to indicate that the index of the current CPU core should be
41887c2aad20Sopenharmony_ci *		used.
41897c2aad20Sopenharmony_ci *
41907c2aad20Sopenharmony_ci *		The value to write, of *size*, is passed through eBPF stack and
41917c2aad20Sopenharmony_ci *		pointed by *data*.
41927c2aad20Sopenharmony_ci *
41937c2aad20Sopenharmony_ci *		*ctx* is a pointer to in-kernel struct xdp_buff.
41947c2aad20Sopenharmony_ci *
41957c2aad20Sopenharmony_ci *		This helper is similar to **bpf_perf_eventoutput**\ () but
41967c2aad20Sopenharmony_ci *		restricted to raw_tracepoint bpf programs.
41977c2aad20Sopenharmony_ci *	Return
41987c2aad20Sopenharmony_ci *		0 on success, or a negative error in case of failure.
41997c2aad20Sopenharmony_ci *
42007c2aad20Sopenharmony_ci * u64 bpf_get_netns_cookie(void *ctx)
42017c2aad20Sopenharmony_ci * 	Description
42027c2aad20Sopenharmony_ci * 		Retrieve the cookie (generated by the kernel) of the network
42037c2aad20Sopenharmony_ci * 		namespace the input *ctx* is associated with. The network
42047c2aad20Sopenharmony_ci * 		namespace cookie remains stable for its lifetime and provides
42057c2aad20Sopenharmony_ci * 		a global identifier that can be assumed unique. If *ctx* is
42067c2aad20Sopenharmony_ci * 		NULL, then the helper returns the cookie for the initial
42077c2aad20Sopenharmony_ci * 		network namespace. The cookie itself is very similar to that
42087c2aad20Sopenharmony_ci * 		of **bpf_get_socket_cookie**\ () helper, but for network
42097c2aad20Sopenharmony_ci * 		namespaces instead of sockets.
42107c2aad20Sopenharmony_ci * 	Return
42117c2aad20Sopenharmony_ci * 		A 8-byte long opaque number.
42127c2aad20Sopenharmony_ci *
42137c2aad20Sopenharmony_ci * u64 bpf_get_current_ancestor_cgroup_id(int ancestor_level)
42147c2aad20Sopenharmony_ci * 	Description
42157c2aad20Sopenharmony_ci * 		Return id of cgroup v2 that is ancestor of the cgroup associated
42167c2aad20Sopenharmony_ci * 		with the current task at the *ancestor_level*. The root cgroup
42177c2aad20Sopenharmony_ci * 		is at *ancestor_level* zero and each step down the hierarchy
42187c2aad20Sopenharmony_ci * 		increments the level. If *ancestor_level* == level of cgroup
42197c2aad20Sopenharmony_ci * 		associated with the current task, then return value will be the
42207c2aad20Sopenharmony_ci * 		same as that of **bpf_get_current_cgroup_id**\ ().
42217c2aad20Sopenharmony_ci *
42227c2aad20Sopenharmony_ci * 		The helper is useful to implement policies based on cgroups
42237c2aad20Sopenharmony_ci * 		that are upper in hierarchy than immediate cgroup associated
42247c2aad20Sopenharmony_ci * 		with the current task.
42257c2aad20Sopenharmony_ci *
42267c2aad20Sopenharmony_ci * 		The format of returned id and helper limitations are same as in
42277c2aad20Sopenharmony_ci * 		**bpf_get_current_cgroup_id**\ ().
42287c2aad20Sopenharmony_ci * 	Return
42297c2aad20Sopenharmony_ci * 		The id is returned or 0 in case the id could not be retrieved.
42307c2aad20Sopenharmony_ci *
42317c2aad20Sopenharmony_ci * long bpf_sk_assign(struct sk_buff *skb, void *sk, u64 flags)
42327c2aad20Sopenharmony_ci *	Description
42337c2aad20Sopenharmony_ci *		Helper is overloaded depending on BPF program type. This
42347c2aad20Sopenharmony_ci *		description applies to **BPF_PROG_TYPE_SCHED_CLS** and
42357c2aad20Sopenharmony_ci *		**BPF_PROG_TYPE_SCHED_ACT** programs.
42367c2aad20Sopenharmony_ci *
42377c2aad20Sopenharmony_ci *		Assign the *sk* to the *skb*. When combined with appropriate
42387c2aad20Sopenharmony_ci *		routing configuration to receive the packet towards the socket,
42397c2aad20Sopenharmony_ci *		will cause *skb* to be delivered to the specified socket.
42407c2aad20Sopenharmony_ci *		Subsequent redirection of *skb* via  **bpf_redirect**\ (),
42417c2aad20Sopenharmony_ci *		**bpf_clone_redirect**\ () or other methods outside of BPF may
42427c2aad20Sopenharmony_ci *		interfere with successful delivery to the socket.
42437c2aad20Sopenharmony_ci *
42447c2aad20Sopenharmony_ci *		This operation is only valid from TC ingress path.
42457c2aad20Sopenharmony_ci *
42467c2aad20Sopenharmony_ci *		The *flags* argument must be zero.
42477c2aad20Sopenharmony_ci *	Return
42487c2aad20Sopenharmony_ci *		0 on success, or a negative error in case of failure:
42497c2aad20Sopenharmony_ci *
42507c2aad20Sopenharmony_ci *		**-EINVAL** if specified *flags* are not supported.
42517c2aad20Sopenharmony_ci *
42527c2aad20Sopenharmony_ci *		**-ENOENT** if the socket is unavailable for assignment.
42537c2aad20Sopenharmony_ci *
42547c2aad20Sopenharmony_ci *		**-ENETUNREACH** if the socket is unreachable (wrong netns).
42557c2aad20Sopenharmony_ci *
42567c2aad20Sopenharmony_ci *		**-EOPNOTSUPP** if the operation is not supported, for example
42577c2aad20Sopenharmony_ci *		a call from outside of TC ingress.
42587c2aad20Sopenharmony_ci *
42597c2aad20Sopenharmony_ci * long bpf_sk_assign(struct bpf_sk_lookup *ctx, struct bpf_sock *sk, u64 flags)
42607c2aad20Sopenharmony_ci *	Description
42617c2aad20Sopenharmony_ci *		Helper is overloaded depending on BPF program type. This
42627c2aad20Sopenharmony_ci *		description applies to **BPF_PROG_TYPE_SK_LOOKUP** programs.
42637c2aad20Sopenharmony_ci *
42647c2aad20Sopenharmony_ci *		Select the *sk* as a result of a socket lookup.
42657c2aad20Sopenharmony_ci *
42667c2aad20Sopenharmony_ci *		For the operation to succeed passed socket must be compatible
42677c2aad20Sopenharmony_ci *		with the packet description provided by the *ctx* object.
42687c2aad20Sopenharmony_ci *
42697c2aad20Sopenharmony_ci *		L4 protocol (**IPPROTO_TCP** or **IPPROTO_UDP**) must
42707c2aad20Sopenharmony_ci *		be an exact match. While IP family (**AF_INET** or
42717c2aad20Sopenharmony_ci *		**AF_INET6**) must be compatible, that is IPv6 sockets
42727c2aad20Sopenharmony_ci *		that are not v6-only can be selected for IPv4 packets.
42737c2aad20Sopenharmony_ci *
42747c2aad20Sopenharmony_ci *		Only TCP listeners and UDP unconnected sockets can be
42757c2aad20Sopenharmony_ci *		selected. *sk* can also be NULL to reset any previous
42767c2aad20Sopenharmony_ci *		selection.
42777c2aad20Sopenharmony_ci *
42787c2aad20Sopenharmony_ci *		*flags* argument can combination of following values:
42797c2aad20Sopenharmony_ci *
42807c2aad20Sopenharmony_ci *		* **BPF_SK_LOOKUP_F_REPLACE** to override the previous
42817c2aad20Sopenharmony_ci *		  socket selection, potentially done by a BPF program
42827c2aad20Sopenharmony_ci *		  that ran before us.
42837c2aad20Sopenharmony_ci *
42847c2aad20Sopenharmony_ci *		* **BPF_SK_LOOKUP_F_NO_REUSEPORT** to skip
42857c2aad20Sopenharmony_ci *		  load-balancing within reuseport group for the socket
42867c2aad20Sopenharmony_ci *		  being selected.
42877c2aad20Sopenharmony_ci *
42887c2aad20Sopenharmony_ci *		On success *ctx->sk* will point to the selected socket.
42897c2aad20Sopenharmony_ci *
42907c2aad20Sopenharmony_ci *	Return
42917c2aad20Sopenharmony_ci *		0 on success, or a negative errno in case of failure.
42927c2aad20Sopenharmony_ci *
42937c2aad20Sopenharmony_ci *		* **-EAFNOSUPPORT** if socket family (*sk->family*) is
42947c2aad20Sopenharmony_ci *		  not compatible with packet family (*ctx->family*).
42957c2aad20Sopenharmony_ci *
42967c2aad20Sopenharmony_ci *		* **-EEXIST** if socket has been already selected,
42977c2aad20Sopenharmony_ci *		  potentially by another program, and
42987c2aad20Sopenharmony_ci *		  **BPF_SK_LOOKUP_F_REPLACE** flag was not specified.
42997c2aad20Sopenharmony_ci *
43007c2aad20Sopenharmony_ci *		* **-EINVAL** if unsupported flags were specified.
43017c2aad20Sopenharmony_ci *
43027c2aad20Sopenharmony_ci *		* **-EPROTOTYPE** if socket L4 protocol
43037c2aad20Sopenharmony_ci *		  (*sk->protocol*) doesn't match packet protocol
43047c2aad20Sopenharmony_ci *		  (*ctx->protocol*).
43057c2aad20Sopenharmony_ci *
43067c2aad20Sopenharmony_ci *		* **-ESOCKTNOSUPPORT** if socket is not in allowed
43077c2aad20Sopenharmony_ci *		  state (TCP listening or UDP unconnected).
43087c2aad20Sopenharmony_ci *
43097c2aad20Sopenharmony_ci * u64 bpf_ktime_get_boot_ns(void)
43107c2aad20Sopenharmony_ci * 	Description
43117c2aad20Sopenharmony_ci * 		Return the time elapsed since system boot, in nanoseconds.
43127c2aad20Sopenharmony_ci * 		Does include the time the system was suspended.
43137c2aad20Sopenharmony_ci * 		See: **clock_gettime**\ (**CLOCK_BOOTTIME**)
43147c2aad20Sopenharmony_ci * 	Return
43157c2aad20Sopenharmony_ci * 		Current *ktime*.
43167c2aad20Sopenharmony_ci *
43177c2aad20Sopenharmony_ci * long bpf_seq_printf(struct seq_file *m, const char *fmt, u32 fmt_size, const void *data, u32 data_len)
43187c2aad20Sopenharmony_ci * 	Description
43197c2aad20Sopenharmony_ci * 		**bpf_seq_printf**\ () uses seq_file **seq_printf**\ () to print
43207c2aad20Sopenharmony_ci * 		out the format string.
43217c2aad20Sopenharmony_ci * 		The *m* represents the seq_file. The *fmt* and *fmt_size* are for
43227c2aad20Sopenharmony_ci * 		the format string itself. The *data* and *data_len* are format string
43237c2aad20Sopenharmony_ci * 		arguments. The *data* are a **u64** array and corresponding format string
43247c2aad20Sopenharmony_ci * 		values are stored in the array. For strings and pointers where pointees
43257c2aad20Sopenharmony_ci * 		are accessed, only the pointer values are stored in the *data* array.
43267c2aad20Sopenharmony_ci * 		The *data_len* is the size of *data* in bytes - must be a multiple of 8.
43277c2aad20Sopenharmony_ci *
43287c2aad20Sopenharmony_ci *		Formats **%s**, **%p{i,I}{4,6}** requires to read kernel memory.
43297c2aad20Sopenharmony_ci *		Reading kernel memory may fail due to either invalid address or
43307c2aad20Sopenharmony_ci *		valid address but requiring a major memory fault. If reading kernel memory
43317c2aad20Sopenharmony_ci *		fails, the string for **%s** will be an empty string, and the ip
43327c2aad20Sopenharmony_ci *		address for **%p{i,I}{4,6}** will be 0. Not returning error to
43337c2aad20Sopenharmony_ci *		bpf program is consistent with what **bpf_trace_printk**\ () does for now.
43347c2aad20Sopenharmony_ci * 	Return
43357c2aad20Sopenharmony_ci * 		0 on success, or a negative error in case of failure:
43367c2aad20Sopenharmony_ci *
43377c2aad20Sopenharmony_ci *		**-EBUSY** if per-CPU memory copy buffer is busy, can try again
43387c2aad20Sopenharmony_ci *		by returning 1 from bpf program.
43397c2aad20Sopenharmony_ci *
43407c2aad20Sopenharmony_ci *		**-EINVAL** if arguments are invalid, or if *fmt* is invalid/unsupported.
43417c2aad20Sopenharmony_ci *
43427c2aad20Sopenharmony_ci *		**-E2BIG** if *fmt* contains too many format specifiers.
43437c2aad20Sopenharmony_ci *
43447c2aad20Sopenharmony_ci *		**-EOVERFLOW** if an overflow happened: The same object will be tried again.
43457c2aad20Sopenharmony_ci *
43467c2aad20Sopenharmony_ci * long bpf_seq_write(struct seq_file *m, const void *data, u32 len)
43477c2aad20Sopenharmony_ci * 	Description
43487c2aad20Sopenharmony_ci * 		**bpf_seq_write**\ () uses seq_file **seq_write**\ () to write the data.
43497c2aad20Sopenharmony_ci * 		The *m* represents the seq_file. The *data* and *len* represent the
43507c2aad20Sopenharmony_ci * 		data to write in bytes.
43517c2aad20Sopenharmony_ci * 	Return
43527c2aad20Sopenharmony_ci * 		0 on success, or a negative error in case of failure:
43537c2aad20Sopenharmony_ci *
43547c2aad20Sopenharmony_ci *		**-EOVERFLOW** if an overflow happened: The same object will be tried again.
43557c2aad20Sopenharmony_ci *
43567c2aad20Sopenharmony_ci * u64 bpf_sk_cgroup_id(void *sk)
43577c2aad20Sopenharmony_ci *	Description
43587c2aad20Sopenharmony_ci *		Return the cgroup v2 id of the socket *sk*.
43597c2aad20Sopenharmony_ci *
43607c2aad20Sopenharmony_ci *		*sk* must be a non-**NULL** pointer to a socket, e.g. one
43617c2aad20Sopenharmony_ci *		returned from **bpf_sk_lookup_xxx**\ (),
43627c2aad20Sopenharmony_ci *		**bpf_sk_fullsock**\ (), etc. The format of returned id is
43637c2aad20Sopenharmony_ci *		same as in **bpf_skb_cgroup_id**\ ().
43647c2aad20Sopenharmony_ci *
43657c2aad20Sopenharmony_ci *		This helper is available only if the kernel was compiled with
43667c2aad20Sopenharmony_ci *		the **CONFIG_SOCK_CGROUP_DATA** configuration option.
43677c2aad20Sopenharmony_ci *	Return
43687c2aad20Sopenharmony_ci *		The id is returned or 0 in case the id could not be retrieved.
43697c2aad20Sopenharmony_ci *
43707c2aad20Sopenharmony_ci * u64 bpf_sk_ancestor_cgroup_id(void *sk, int ancestor_level)
43717c2aad20Sopenharmony_ci *	Description
43727c2aad20Sopenharmony_ci *		Return id of cgroup v2 that is ancestor of cgroup associated
43737c2aad20Sopenharmony_ci *		with the *sk* at the *ancestor_level*.  The root cgroup is at
43747c2aad20Sopenharmony_ci *		*ancestor_level* zero and each step down the hierarchy
43757c2aad20Sopenharmony_ci *		increments the level. If *ancestor_level* == level of cgroup
43767c2aad20Sopenharmony_ci *		associated with *sk*, then return value will be same as that
43777c2aad20Sopenharmony_ci *		of **bpf_sk_cgroup_id**\ ().
43787c2aad20Sopenharmony_ci *
43797c2aad20Sopenharmony_ci *		The helper is useful to implement policies based on cgroups
43807c2aad20Sopenharmony_ci *		that are upper in hierarchy than immediate cgroup associated
43817c2aad20Sopenharmony_ci *		with *sk*.
43827c2aad20Sopenharmony_ci *
43837c2aad20Sopenharmony_ci *		The format of returned id and helper limitations are same as in
43847c2aad20Sopenharmony_ci *		**bpf_sk_cgroup_id**\ ().
43857c2aad20Sopenharmony_ci *	Return
43867c2aad20Sopenharmony_ci *		The id is returned or 0 in case the id could not be retrieved.
43877c2aad20Sopenharmony_ci *
43887c2aad20Sopenharmony_ci * long bpf_ringbuf_output(void *ringbuf, void *data, u64 size, u64 flags)
43897c2aad20Sopenharmony_ci * 	Description
43907c2aad20Sopenharmony_ci * 		Copy *size* bytes from *data* into a ring buffer *ringbuf*.
43917c2aad20Sopenharmony_ci * 		If **BPF_RB_NO_WAKEUP** is specified in *flags*, no notification
43927c2aad20Sopenharmony_ci * 		of new data availability is sent.
43937c2aad20Sopenharmony_ci * 		If **BPF_RB_FORCE_WAKEUP** is specified in *flags*, notification
43947c2aad20Sopenharmony_ci * 		of new data availability is sent unconditionally.
43957c2aad20Sopenharmony_ci * 		If **0** is specified in *flags*, an adaptive notification
43967c2aad20Sopenharmony_ci * 		of new data availability is sent.
43977c2aad20Sopenharmony_ci *
43987c2aad20Sopenharmony_ci * 		An adaptive notification is a notification sent whenever the user-space
43997c2aad20Sopenharmony_ci * 		process has caught up and consumed all available payloads. In case the user-space
44007c2aad20Sopenharmony_ci * 		process is still processing a previous payload, then no notification is needed
44017c2aad20Sopenharmony_ci * 		as it will process the newly added payload automatically.
44027c2aad20Sopenharmony_ci * 	Return
44037c2aad20Sopenharmony_ci * 		0 on success, or a negative error in case of failure.
44047c2aad20Sopenharmony_ci *
44057c2aad20Sopenharmony_ci * void *bpf_ringbuf_reserve(void *ringbuf, u64 size, u64 flags)
44067c2aad20Sopenharmony_ci * 	Description
44077c2aad20Sopenharmony_ci * 		Reserve *size* bytes of payload in a ring buffer *ringbuf*.
44087c2aad20Sopenharmony_ci * 		*flags* must be 0.
44097c2aad20Sopenharmony_ci * 	Return
44107c2aad20Sopenharmony_ci * 		Valid pointer with *size* bytes of memory available; NULL,
44117c2aad20Sopenharmony_ci * 		otherwise.
44127c2aad20Sopenharmony_ci *
44137c2aad20Sopenharmony_ci * void bpf_ringbuf_submit(void *data, u64 flags)
44147c2aad20Sopenharmony_ci * 	Description
44157c2aad20Sopenharmony_ci * 		Submit reserved ring buffer sample, pointed to by *data*.
44167c2aad20Sopenharmony_ci * 		If **BPF_RB_NO_WAKEUP** is specified in *flags*, no notification
44177c2aad20Sopenharmony_ci * 		of new data availability is sent.
44187c2aad20Sopenharmony_ci * 		If **BPF_RB_FORCE_WAKEUP** is specified in *flags*, notification
44197c2aad20Sopenharmony_ci * 		of new data availability is sent unconditionally.
44207c2aad20Sopenharmony_ci * 		If **0** is specified in *flags*, an adaptive notification
44217c2aad20Sopenharmony_ci * 		of new data availability is sent.
44227c2aad20Sopenharmony_ci *
44237c2aad20Sopenharmony_ci * 		See 'bpf_ringbuf_output()' for the definition of adaptive notification.
44247c2aad20Sopenharmony_ci * 	Return
44257c2aad20Sopenharmony_ci * 		Nothing. Always succeeds.
44267c2aad20Sopenharmony_ci *
44277c2aad20Sopenharmony_ci * void bpf_ringbuf_discard(void *data, u64 flags)
44287c2aad20Sopenharmony_ci * 	Description
44297c2aad20Sopenharmony_ci * 		Discard reserved ring buffer sample, pointed to by *data*.
44307c2aad20Sopenharmony_ci * 		If **BPF_RB_NO_WAKEUP** is specified in *flags*, no notification
44317c2aad20Sopenharmony_ci * 		of new data availability is sent.
44327c2aad20Sopenharmony_ci * 		If **BPF_RB_FORCE_WAKEUP** is specified in *flags*, notification
44337c2aad20Sopenharmony_ci * 		of new data availability is sent unconditionally.
44347c2aad20Sopenharmony_ci * 		If **0** is specified in *flags*, an adaptive notification
44357c2aad20Sopenharmony_ci * 		of new data availability is sent.
44367c2aad20Sopenharmony_ci *
44377c2aad20Sopenharmony_ci * 		See 'bpf_ringbuf_output()' for the definition of adaptive notification.
44387c2aad20Sopenharmony_ci * 	Return
44397c2aad20Sopenharmony_ci * 		Nothing. Always succeeds.
44407c2aad20Sopenharmony_ci *
44417c2aad20Sopenharmony_ci * u64 bpf_ringbuf_query(void *ringbuf, u64 flags)
44427c2aad20Sopenharmony_ci *	Description
44437c2aad20Sopenharmony_ci *		Query various characteristics of provided ring buffer. What
44447c2aad20Sopenharmony_ci *		exactly is queries is determined by *flags*:
44457c2aad20Sopenharmony_ci *
44467c2aad20Sopenharmony_ci *		* **BPF_RB_AVAIL_DATA**: Amount of data not yet consumed.
44477c2aad20Sopenharmony_ci *		* **BPF_RB_RING_SIZE**: The size of ring buffer.
44487c2aad20Sopenharmony_ci *		* **BPF_RB_CONS_POS**: Consumer position (can wrap around).
44497c2aad20Sopenharmony_ci *		* **BPF_RB_PROD_POS**: Producer(s) position (can wrap around).
44507c2aad20Sopenharmony_ci *
44517c2aad20Sopenharmony_ci *		Data returned is just a momentary snapshot of actual values
44527c2aad20Sopenharmony_ci *		and could be inaccurate, so this facility should be used to
44537c2aad20Sopenharmony_ci *		power heuristics and for reporting, not to make 100% correct
44547c2aad20Sopenharmony_ci *		calculation.
44557c2aad20Sopenharmony_ci *	Return
44567c2aad20Sopenharmony_ci *		Requested value, or 0, if *flags* are not recognized.
44577c2aad20Sopenharmony_ci *
44587c2aad20Sopenharmony_ci * long bpf_csum_level(struct sk_buff *skb, u64 level)
44597c2aad20Sopenharmony_ci * 	Description
44607c2aad20Sopenharmony_ci * 		Change the skbs checksum level by one layer up or down, or
44617c2aad20Sopenharmony_ci * 		reset it entirely to none in order to have the stack perform
44627c2aad20Sopenharmony_ci * 		checksum validation. The level is applicable to the following
44637c2aad20Sopenharmony_ci * 		protocols: TCP, UDP, GRE, SCTP, FCOE. For example, a decap of
44647c2aad20Sopenharmony_ci * 		| ETH | IP | UDP | GUE | IP | TCP | into | ETH | IP | TCP |
44657c2aad20Sopenharmony_ci * 		through **bpf_skb_adjust_room**\ () helper with passing in
44667c2aad20Sopenharmony_ci * 		**BPF_F_ADJ_ROOM_NO_CSUM_RESET** flag would require one	call
44677c2aad20Sopenharmony_ci * 		to **bpf_csum_level**\ () with **BPF_CSUM_LEVEL_DEC** since
44687c2aad20Sopenharmony_ci * 		the UDP header is removed. Similarly, an encap of the latter
44697c2aad20Sopenharmony_ci * 		into the former could be accompanied by a helper call to
44707c2aad20Sopenharmony_ci * 		**bpf_csum_level**\ () with **BPF_CSUM_LEVEL_INC** if the
44717c2aad20Sopenharmony_ci * 		skb is still intended to be processed in higher layers of the
44727c2aad20Sopenharmony_ci * 		stack instead of just egressing at tc.
44737c2aad20Sopenharmony_ci *
44747c2aad20Sopenharmony_ci * 		There are three supported level settings at this time:
44757c2aad20Sopenharmony_ci *
44767c2aad20Sopenharmony_ci * 		* **BPF_CSUM_LEVEL_INC**: Increases skb->csum_level for skbs
44777c2aad20Sopenharmony_ci * 		  with CHECKSUM_UNNECESSARY.
44787c2aad20Sopenharmony_ci * 		* **BPF_CSUM_LEVEL_DEC**: Decreases skb->csum_level for skbs
44797c2aad20Sopenharmony_ci * 		  with CHECKSUM_UNNECESSARY.
44807c2aad20Sopenharmony_ci * 		* **BPF_CSUM_LEVEL_RESET**: Resets skb->csum_level to 0 and
44817c2aad20Sopenharmony_ci * 		  sets CHECKSUM_NONE to force checksum validation by the stack.
44827c2aad20Sopenharmony_ci * 		* **BPF_CSUM_LEVEL_QUERY**: No-op, returns the current
44837c2aad20Sopenharmony_ci * 		  skb->csum_level.
44847c2aad20Sopenharmony_ci * 	Return
44857c2aad20Sopenharmony_ci * 		0 on success, or a negative error in case of failure. In the
44867c2aad20Sopenharmony_ci * 		case of **BPF_CSUM_LEVEL_QUERY**, the current skb->csum_level
44877c2aad20Sopenharmony_ci * 		is returned or the error code -EACCES in case the skb is not
44887c2aad20Sopenharmony_ci * 		subject to CHECKSUM_UNNECESSARY.
44897c2aad20Sopenharmony_ci *
44907c2aad20Sopenharmony_ci * struct tcp6_sock *bpf_skc_to_tcp6_sock(void *sk)
44917c2aad20Sopenharmony_ci *	Description
44927c2aad20Sopenharmony_ci *		Dynamically cast a *sk* pointer to a *tcp6_sock* pointer.
44937c2aad20Sopenharmony_ci *	Return
44947c2aad20Sopenharmony_ci *		*sk* if casting is valid, or **NULL** otherwise.
44957c2aad20Sopenharmony_ci *
44967c2aad20Sopenharmony_ci * struct tcp_sock *bpf_skc_to_tcp_sock(void *sk)
44977c2aad20Sopenharmony_ci *	Description
44987c2aad20Sopenharmony_ci *		Dynamically cast a *sk* pointer to a *tcp_sock* pointer.
44997c2aad20Sopenharmony_ci *	Return
45007c2aad20Sopenharmony_ci *		*sk* if casting is valid, or **NULL** otherwise.
45017c2aad20Sopenharmony_ci *
45027c2aad20Sopenharmony_ci * struct tcp_timewait_sock *bpf_skc_to_tcp_timewait_sock(void *sk)
45037c2aad20Sopenharmony_ci * 	Description
45047c2aad20Sopenharmony_ci *		Dynamically cast a *sk* pointer to a *tcp_timewait_sock* pointer.
45057c2aad20Sopenharmony_ci *	Return
45067c2aad20Sopenharmony_ci *		*sk* if casting is valid, or **NULL** otherwise.
45077c2aad20Sopenharmony_ci *
45087c2aad20Sopenharmony_ci * struct tcp_request_sock *bpf_skc_to_tcp_request_sock(void *sk)
45097c2aad20Sopenharmony_ci * 	Description
45107c2aad20Sopenharmony_ci *		Dynamically cast a *sk* pointer to a *tcp_request_sock* pointer.
45117c2aad20Sopenharmony_ci *	Return
45127c2aad20Sopenharmony_ci *		*sk* if casting is valid, or **NULL** otherwise.
45137c2aad20Sopenharmony_ci *
45147c2aad20Sopenharmony_ci * struct udp6_sock *bpf_skc_to_udp6_sock(void *sk)
45157c2aad20Sopenharmony_ci * 	Description
45167c2aad20Sopenharmony_ci *		Dynamically cast a *sk* pointer to a *udp6_sock* pointer.
45177c2aad20Sopenharmony_ci *	Return
45187c2aad20Sopenharmony_ci *		*sk* if casting is valid, or **NULL** otherwise.
45197c2aad20Sopenharmony_ci *
45207c2aad20Sopenharmony_ci * long bpf_get_task_stack(struct task_struct *task, void *buf, u32 size, u64 flags)
45217c2aad20Sopenharmony_ci *	Description
45227c2aad20Sopenharmony_ci *		Return a user or a kernel stack in bpf program provided buffer.
45237c2aad20Sopenharmony_ci *		Note: the user stack will only be populated if the *task* is
45247c2aad20Sopenharmony_ci *		the current task; all other tasks will return -EOPNOTSUPP.
45257c2aad20Sopenharmony_ci *		To achieve this, the helper needs *task*, which is a valid
45267c2aad20Sopenharmony_ci *		pointer to **struct task_struct**. To store the stacktrace, the
45277c2aad20Sopenharmony_ci *		bpf program provides *buf* with a nonnegative *size*.
45287c2aad20Sopenharmony_ci *
45297c2aad20Sopenharmony_ci *		The last argument, *flags*, holds the number of stack frames to
45307c2aad20Sopenharmony_ci *		skip (from 0 to 255), masked with
45317c2aad20Sopenharmony_ci *		**BPF_F_SKIP_FIELD_MASK**. The next bits can be used to set
45327c2aad20Sopenharmony_ci *		the following flags:
45337c2aad20Sopenharmony_ci *
45347c2aad20Sopenharmony_ci *		**BPF_F_USER_STACK**
45357c2aad20Sopenharmony_ci *			Collect a user space stack instead of a kernel stack.
45367c2aad20Sopenharmony_ci *			The *task* must be the current task.
45377c2aad20Sopenharmony_ci *		**BPF_F_USER_BUILD_ID**
45387c2aad20Sopenharmony_ci *			Collect buildid+offset instead of ips for user stack,
45397c2aad20Sopenharmony_ci *			only valid if **BPF_F_USER_STACK** is also specified.
45407c2aad20Sopenharmony_ci *
45417c2aad20Sopenharmony_ci *		**bpf_get_task_stack**\ () can collect up to
45427c2aad20Sopenharmony_ci *		**PERF_MAX_STACK_DEPTH** both kernel and user frames, subject
45437c2aad20Sopenharmony_ci *		to sufficient large buffer size. Note that
45447c2aad20Sopenharmony_ci *		this limit can be controlled with the **sysctl** program, and
45457c2aad20Sopenharmony_ci *		that it should be manually increased in order to profile long
45467c2aad20Sopenharmony_ci *		user stacks (such as stacks for Java programs). To do so, use:
45477c2aad20Sopenharmony_ci *
45487c2aad20Sopenharmony_ci *		::
45497c2aad20Sopenharmony_ci *
45507c2aad20Sopenharmony_ci *			# sysctl kernel.perf_event_max_stack=<new value>
45517c2aad20Sopenharmony_ci *	Return
45527c2aad20Sopenharmony_ci * 		The non-negative copied *buf* length equal to or less than
45537c2aad20Sopenharmony_ci * 		*size* on success, or a negative error in case of failure.
45547c2aad20Sopenharmony_ci *
45557c2aad20Sopenharmony_ci * long bpf_load_hdr_opt(struct bpf_sock_ops *skops, void *searchby_res, u32 len, u64 flags)
45567c2aad20Sopenharmony_ci *	Description
45577c2aad20Sopenharmony_ci *		Load header option.  Support reading a particular TCP header
45587c2aad20Sopenharmony_ci *		option for bpf program (**BPF_PROG_TYPE_SOCK_OPS**).
45597c2aad20Sopenharmony_ci *
45607c2aad20Sopenharmony_ci *		If *flags* is 0, it will search the option from the
45617c2aad20Sopenharmony_ci *		*skops*\ **->skb_data**.  The comment in **struct bpf_sock_ops**
45627c2aad20Sopenharmony_ci *		has details on what skb_data contains under different
45637c2aad20Sopenharmony_ci *		*skops*\ **->op**.
45647c2aad20Sopenharmony_ci *
45657c2aad20Sopenharmony_ci *		The first byte of the *searchby_res* specifies the
45667c2aad20Sopenharmony_ci *		kind that it wants to search.
45677c2aad20Sopenharmony_ci *
45687c2aad20Sopenharmony_ci *		If the searching kind is an experimental kind
45697c2aad20Sopenharmony_ci *		(i.e. 253 or 254 according to RFC6994).  It also
45707c2aad20Sopenharmony_ci *		needs to specify the "magic" which is either
45717c2aad20Sopenharmony_ci *		2 bytes or 4 bytes.  It then also needs to
45727c2aad20Sopenharmony_ci *		specify the size of the magic by using
45737c2aad20Sopenharmony_ci *		the 2nd byte which is "kind-length" of a TCP
45747c2aad20Sopenharmony_ci *		header option and the "kind-length" also
45757c2aad20Sopenharmony_ci *		includes the first 2 bytes "kind" and "kind-length"
45767c2aad20Sopenharmony_ci *		itself as a normal TCP header option also does.
45777c2aad20Sopenharmony_ci *
45787c2aad20Sopenharmony_ci *		For example, to search experimental kind 254 with
45797c2aad20Sopenharmony_ci *		2 byte magic 0xeB9F, the searchby_res should be
45807c2aad20Sopenharmony_ci *		[ 254, 4, 0xeB, 0x9F, 0, 0, .... 0 ].
45817c2aad20Sopenharmony_ci *
45827c2aad20Sopenharmony_ci *		To search for the standard window scale option (3),
45837c2aad20Sopenharmony_ci *		the *searchby_res* should be [ 3, 0, 0, .... 0 ].
45847c2aad20Sopenharmony_ci *		Note, kind-length must be 0 for regular option.
45857c2aad20Sopenharmony_ci *
45867c2aad20Sopenharmony_ci *		Searching for No-Op (0) and End-of-Option-List (1) are
45877c2aad20Sopenharmony_ci *		not supported.
45887c2aad20Sopenharmony_ci *
45897c2aad20Sopenharmony_ci *		*len* must be at least 2 bytes which is the minimal size
45907c2aad20Sopenharmony_ci *		of a header option.
45917c2aad20Sopenharmony_ci *
45927c2aad20Sopenharmony_ci *		Supported flags:
45937c2aad20Sopenharmony_ci *
45947c2aad20Sopenharmony_ci *		* **BPF_LOAD_HDR_OPT_TCP_SYN** to search from the
45957c2aad20Sopenharmony_ci *		  saved_syn packet or the just-received syn packet.
45967c2aad20Sopenharmony_ci *
45977c2aad20Sopenharmony_ci *	Return
45987c2aad20Sopenharmony_ci *		> 0 when found, the header option is copied to *searchby_res*.
45997c2aad20Sopenharmony_ci *		The return value is the total length copied. On failure, a
46007c2aad20Sopenharmony_ci *		negative error code is returned:
46017c2aad20Sopenharmony_ci *
46027c2aad20Sopenharmony_ci *		**-EINVAL** if a parameter is invalid.
46037c2aad20Sopenharmony_ci *
46047c2aad20Sopenharmony_ci *		**-ENOMSG** if the option is not found.
46057c2aad20Sopenharmony_ci *
46067c2aad20Sopenharmony_ci *		**-ENOENT** if no syn packet is available when
46077c2aad20Sopenharmony_ci *		**BPF_LOAD_HDR_OPT_TCP_SYN** is used.
46087c2aad20Sopenharmony_ci *
46097c2aad20Sopenharmony_ci *		**-ENOSPC** if there is not enough space.  Only *len* number of
46107c2aad20Sopenharmony_ci *		bytes are copied.
46117c2aad20Sopenharmony_ci *
46127c2aad20Sopenharmony_ci *		**-EFAULT** on failure to parse the header options in the
46137c2aad20Sopenharmony_ci *		packet.
46147c2aad20Sopenharmony_ci *
46157c2aad20Sopenharmony_ci *		**-EPERM** if the helper cannot be used under the current
46167c2aad20Sopenharmony_ci *		*skops*\ **->op**.
46177c2aad20Sopenharmony_ci *
46187c2aad20Sopenharmony_ci * long bpf_store_hdr_opt(struct bpf_sock_ops *skops, const void *from, u32 len, u64 flags)
46197c2aad20Sopenharmony_ci *	Description
46207c2aad20Sopenharmony_ci *		Store header option.  The data will be copied
46217c2aad20Sopenharmony_ci *		from buffer *from* with length *len* to the TCP header.
46227c2aad20Sopenharmony_ci *
46237c2aad20Sopenharmony_ci *		The buffer *from* should have the whole option that
46247c2aad20Sopenharmony_ci *		includes the kind, kind-length, and the actual
46257c2aad20Sopenharmony_ci *		option data.  The *len* must be at least kind-length
46267c2aad20Sopenharmony_ci *		long.  The kind-length does not have to be 4 byte
46277c2aad20Sopenharmony_ci *		aligned.  The kernel will take care of the padding
46287c2aad20Sopenharmony_ci *		and setting the 4 bytes aligned value to th->doff.
46297c2aad20Sopenharmony_ci *
46307c2aad20Sopenharmony_ci *		This helper will check for duplicated option
46317c2aad20Sopenharmony_ci *		by searching the same option in the outgoing skb.
46327c2aad20Sopenharmony_ci *
46337c2aad20Sopenharmony_ci *		This helper can only be called during
46347c2aad20Sopenharmony_ci *		**BPF_SOCK_OPS_WRITE_HDR_OPT_CB**.
46357c2aad20Sopenharmony_ci *
46367c2aad20Sopenharmony_ci *	Return
46377c2aad20Sopenharmony_ci *		0 on success, or negative error in case of failure:
46387c2aad20Sopenharmony_ci *
46397c2aad20Sopenharmony_ci *		**-EINVAL** If param is invalid.
46407c2aad20Sopenharmony_ci *
46417c2aad20Sopenharmony_ci *		**-ENOSPC** if there is not enough space in the header.
46427c2aad20Sopenharmony_ci *		Nothing has been written
46437c2aad20Sopenharmony_ci *
46447c2aad20Sopenharmony_ci *		**-EEXIST** if the option already exists.
46457c2aad20Sopenharmony_ci *
46467c2aad20Sopenharmony_ci *		**-EFAULT** on failure to parse the existing header options.
46477c2aad20Sopenharmony_ci *
46487c2aad20Sopenharmony_ci *		**-EPERM** if the helper cannot be used under the current
46497c2aad20Sopenharmony_ci *		*skops*\ **->op**.
46507c2aad20Sopenharmony_ci *
46517c2aad20Sopenharmony_ci * long bpf_reserve_hdr_opt(struct bpf_sock_ops *skops, u32 len, u64 flags)
46527c2aad20Sopenharmony_ci *	Description
46537c2aad20Sopenharmony_ci *		Reserve *len* bytes for the bpf header option.  The
46547c2aad20Sopenharmony_ci *		space will be used by **bpf_store_hdr_opt**\ () later in
46557c2aad20Sopenharmony_ci *		**BPF_SOCK_OPS_WRITE_HDR_OPT_CB**.
46567c2aad20Sopenharmony_ci *
46577c2aad20Sopenharmony_ci *		If **bpf_reserve_hdr_opt**\ () is called multiple times,
46587c2aad20Sopenharmony_ci *		the total number of bytes will be reserved.
46597c2aad20Sopenharmony_ci *
46607c2aad20Sopenharmony_ci *		This helper can only be called during
46617c2aad20Sopenharmony_ci *		**BPF_SOCK_OPS_HDR_OPT_LEN_CB**.
46627c2aad20Sopenharmony_ci *
46637c2aad20Sopenharmony_ci *	Return
46647c2aad20Sopenharmony_ci *		0 on success, or negative error in case of failure:
46657c2aad20Sopenharmony_ci *
46667c2aad20Sopenharmony_ci *		**-EINVAL** if a parameter is invalid.
46677c2aad20Sopenharmony_ci *
46687c2aad20Sopenharmony_ci *		**-ENOSPC** if there is not enough space in the header.
46697c2aad20Sopenharmony_ci *
46707c2aad20Sopenharmony_ci *		**-EPERM** if the helper cannot be used under the current
46717c2aad20Sopenharmony_ci *		*skops*\ **->op**.
46727c2aad20Sopenharmony_ci *
46737c2aad20Sopenharmony_ci * void *bpf_inode_storage_get(struct bpf_map *map, void *inode, void *value, u64 flags)
46747c2aad20Sopenharmony_ci *	Description
46757c2aad20Sopenharmony_ci *		Get a bpf_local_storage from an *inode*.
46767c2aad20Sopenharmony_ci *
46777c2aad20Sopenharmony_ci *		Logically, it could be thought of as getting the value from
46787c2aad20Sopenharmony_ci *		a *map* with *inode* as the **key**.  From this
46797c2aad20Sopenharmony_ci *		perspective,  the usage is not much different from
46807c2aad20Sopenharmony_ci *		**bpf_map_lookup_elem**\ (*map*, **&**\ *inode*) except this
46817c2aad20Sopenharmony_ci *		helper enforces the key must be an inode and the map must also
46827c2aad20Sopenharmony_ci *		be a **BPF_MAP_TYPE_INODE_STORAGE**.
46837c2aad20Sopenharmony_ci *
46847c2aad20Sopenharmony_ci *		Underneath, the value is stored locally at *inode* instead of
46857c2aad20Sopenharmony_ci *		the *map*.  The *map* is used as the bpf-local-storage
46867c2aad20Sopenharmony_ci *		"type". The bpf-local-storage "type" (i.e. the *map*) is
46877c2aad20Sopenharmony_ci *		searched against all bpf_local_storage residing at *inode*.
46887c2aad20Sopenharmony_ci *
46897c2aad20Sopenharmony_ci *		An optional *flags* (**BPF_LOCAL_STORAGE_GET_F_CREATE**) can be
46907c2aad20Sopenharmony_ci *		used such that a new bpf_local_storage will be
46917c2aad20Sopenharmony_ci *		created if one does not exist.  *value* can be used
46927c2aad20Sopenharmony_ci *		together with **BPF_LOCAL_STORAGE_GET_F_CREATE** to specify
46937c2aad20Sopenharmony_ci *		the initial value of a bpf_local_storage.  If *value* is
46947c2aad20Sopenharmony_ci *		**NULL**, the new bpf_local_storage will be zero initialized.
46957c2aad20Sopenharmony_ci *	Return
46967c2aad20Sopenharmony_ci *		A bpf_local_storage pointer is returned on success.
46977c2aad20Sopenharmony_ci *
46987c2aad20Sopenharmony_ci *		**NULL** if not found or there was an error in adding
46997c2aad20Sopenharmony_ci *		a new bpf_local_storage.
47007c2aad20Sopenharmony_ci *
47017c2aad20Sopenharmony_ci * int bpf_inode_storage_delete(struct bpf_map *map, void *inode)
47027c2aad20Sopenharmony_ci *	Description
47037c2aad20Sopenharmony_ci *		Delete a bpf_local_storage from an *inode*.
47047c2aad20Sopenharmony_ci *	Return
47057c2aad20Sopenharmony_ci *		0 on success.
47067c2aad20Sopenharmony_ci *
47077c2aad20Sopenharmony_ci *		**-ENOENT** if the bpf_local_storage cannot be found.
47087c2aad20Sopenharmony_ci *
47097c2aad20Sopenharmony_ci * long bpf_d_path(struct path *path, char *buf, u32 sz)
47107c2aad20Sopenharmony_ci *	Description
47117c2aad20Sopenharmony_ci *		Return full path for given **struct path** object, which
47127c2aad20Sopenharmony_ci *		needs to be the kernel BTF *path* object. The path is
47137c2aad20Sopenharmony_ci *		returned in the provided buffer *buf* of size *sz* and
47147c2aad20Sopenharmony_ci *		is zero terminated.
47157c2aad20Sopenharmony_ci *
47167c2aad20Sopenharmony_ci *	Return
47177c2aad20Sopenharmony_ci *		On success, the strictly positive length of the string,
47187c2aad20Sopenharmony_ci *		including the trailing NUL character. On error, a negative
47197c2aad20Sopenharmony_ci *		value.
47207c2aad20Sopenharmony_ci *
47217c2aad20Sopenharmony_ci * long bpf_copy_from_user(void *dst, u32 size, const void *user_ptr)
47227c2aad20Sopenharmony_ci * 	Description
47237c2aad20Sopenharmony_ci * 		Read *size* bytes from user space address *user_ptr* and store
47247c2aad20Sopenharmony_ci * 		the data in *dst*. This is a wrapper of **copy_from_user**\ ().
47257c2aad20Sopenharmony_ci * 	Return
47267c2aad20Sopenharmony_ci * 		0 on success, or a negative error in case of failure.
47277c2aad20Sopenharmony_ci *
47287c2aad20Sopenharmony_ci * long bpf_snprintf_btf(char *str, u32 str_size, struct btf_ptr *ptr, u32 btf_ptr_size, u64 flags)
47297c2aad20Sopenharmony_ci *	Description
47307c2aad20Sopenharmony_ci *		Use BTF to store a string representation of *ptr*->ptr in *str*,
47317c2aad20Sopenharmony_ci *		using *ptr*->type_id.  This value should specify the type
47327c2aad20Sopenharmony_ci *		that *ptr*->ptr points to. LLVM __builtin_btf_type_id(type, 1)
47337c2aad20Sopenharmony_ci *		can be used to look up vmlinux BTF type ids. Traversing the
47347c2aad20Sopenharmony_ci *		data structure using BTF, the type information and values are
47357c2aad20Sopenharmony_ci *		stored in the first *str_size* - 1 bytes of *str*.  Safe copy of
47367c2aad20Sopenharmony_ci *		the pointer data is carried out to avoid kernel crashes during
47377c2aad20Sopenharmony_ci *		operation.  Smaller types can use string space on the stack;
47387c2aad20Sopenharmony_ci *		larger programs can use map data to store the string
47397c2aad20Sopenharmony_ci *		representation.
47407c2aad20Sopenharmony_ci *
47417c2aad20Sopenharmony_ci *		The string can be subsequently shared with userspace via
47427c2aad20Sopenharmony_ci *		bpf_perf_event_output() or ring buffer interfaces.
47437c2aad20Sopenharmony_ci *		bpf_trace_printk() is to be avoided as it places too small
47447c2aad20Sopenharmony_ci *		a limit on string size to be useful.
47457c2aad20Sopenharmony_ci *
47467c2aad20Sopenharmony_ci *		*flags* is a combination of
47477c2aad20Sopenharmony_ci *
47487c2aad20Sopenharmony_ci *		**BTF_F_COMPACT**
47497c2aad20Sopenharmony_ci *			no formatting around type information
47507c2aad20Sopenharmony_ci *		**BTF_F_NONAME**
47517c2aad20Sopenharmony_ci *			no struct/union member names/types
47527c2aad20Sopenharmony_ci *		**BTF_F_PTR_RAW**
47537c2aad20Sopenharmony_ci *			show raw (unobfuscated) pointer values;
47547c2aad20Sopenharmony_ci *			equivalent to printk specifier %px.
47557c2aad20Sopenharmony_ci *		**BTF_F_ZERO**
47567c2aad20Sopenharmony_ci *			show zero-valued struct/union members; they
47577c2aad20Sopenharmony_ci *			are not displayed by default
47587c2aad20Sopenharmony_ci *
47597c2aad20Sopenharmony_ci *	Return
47607c2aad20Sopenharmony_ci *		The number of bytes that were written (or would have been
47617c2aad20Sopenharmony_ci *		written if output had to be truncated due to string size),
47627c2aad20Sopenharmony_ci *		or a negative error in cases of failure.
47637c2aad20Sopenharmony_ci *
47647c2aad20Sopenharmony_ci * long bpf_seq_printf_btf(struct seq_file *m, struct btf_ptr *ptr, u32 ptr_size, u64 flags)
47657c2aad20Sopenharmony_ci *	Description
47667c2aad20Sopenharmony_ci *		Use BTF to write to seq_write a string representation of
47677c2aad20Sopenharmony_ci *		*ptr*->ptr, using *ptr*->type_id as per bpf_snprintf_btf().
47687c2aad20Sopenharmony_ci *		*flags* are identical to those used for bpf_snprintf_btf.
47697c2aad20Sopenharmony_ci *	Return
47707c2aad20Sopenharmony_ci *		0 on success or a negative error in case of failure.
47717c2aad20Sopenharmony_ci *
47727c2aad20Sopenharmony_ci * u64 bpf_skb_cgroup_classid(struct sk_buff *skb)
47737c2aad20Sopenharmony_ci * 	Description
47747c2aad20Sopenharmony_ci * 		See **bpf_get_cgroup_classid**\ () for the main description.
47757c2aad20Sopenharmony_ci * 		This helper differs from **bpf_get_cgroup_classid**\ () in that
47767c2aad20Sopenharmony_ci * 		the cgroup v1 net_cls class is retrieved only from the *skb*'s
47777c2aad20Sopenharmony_ci * 		associated socket instead of the current process.
47787c2aad20Sopenharmony_ci * 	Return
47797c2aad20Sopenharmony_ci * 		The id is returned or 0 in case the id could not be retrieved.
47807c2aad20Sopenharmony_ci *
47817c2aad20Sopenharmony_ci * long bpf_redirect_neigh(u32 ifindex, struct bpf_redir_neigh *params, int plen, u64 flags)
47827c2aad20Sopenharmony_ci * 	Description
47837c2aad20Sopenharmony_ci * 		Redirect the packet to another net device of index *ifindex*
47847c2aad20Sopenharmony_ci * 		and fill in L2 addresses from neighboring subsystem. This helper
47857c2aad20Sopenharmony_ci * 		is somewhat similar to **bpf_redirect**\ (), except that it
47867c2aad20Sopenharmony_ci * 		populates L2 addresses as well, meaning, internally, the helper
47877c2aad20Sopenharmony_ci * 		relies on the neighbor lookup for the L2 address of the nexthop.
47887c2aad20Sopenharmony_ci *
47897c2aad20Sopenharmony_ci * 		The helper will perform a FIB lookup based on the skb's
47907c2aad20Sopenharmony_ci * 		networking header to get the address of the next hop, unless
47917c2aad20Sopenharmony_ci * 		this is supplied by the caller in the *params* argument. The
47927c2aad20Sopenharmony_ci * 		*plen* argument indicates the len of *params* and should be set
47937c2aad20Sopenharmony_ci * 		to 0 if *params* is NULL.
47947c2aad20Sopenharmony_ci *
47957c2aad20Sopenharmony_ci * 		The *flags* argument is reserved and must be 0. The helper is
47967c2aad20Sopenharmony_ci * 		currently only supported for tc BPF program types, and enabled
47977c2aad20Sopenharmony_ci * 		for IPv4 and IPv6 protocols.
47987c2aad20Sopenharmony_ci * 	Return
47997c2aad20Sopenharmony_ci * 		The helper returns **TC_ACT_REDIRECT** on success or
48007c2aad20Sopenharmony_ci * 		**TC_ACT_SHOT** on error.
48017c2aad20Sopenharmony_ci *
48027c2aad20Sopenharmony_ci * void *bpf_per_cpu_ptr(const void *percpu_ptr, u32 cpu)
48037c2aad20Sopenharmony_ci *     Description
48047c2aad20Sopenharmony_ci *             Take a pointer to a percpu ksym, *percpu_ptr*, and return a
48057c2aad20Sopenharmony_ci *             pointer to the percpu kernel variable on *cpu*. A ksym is an
48067c2aad20Sopenharmony_ci *             extern variable decorated with '__ksym'. For ksym, there is a
48077c2aad20Sopenharmony_ci *             global var (either static or global) defined of the same name
48087c2aad20Sopenharmony_ci *             in the kernel. The ksym is percpu if the global var is percpu.
48097c2aad20Sopenharmony_ci *             The returned pointer points to the global percpu var on *cpu*.
48107c2aad20Sopenharmony_ci *
48117c2aad20Sopenharmony_ci *             bpf_per_cpu_ptr() has the same semantic as per_cpu_ptr() in the
48127c2aad20Sopenharmony_ci *             kernel, except that bpf_per_cpu_ptr() may return NULL. This
48137c2aad20Sopenharmony_ci *             happens if *cpu* is larger than nr_cpu_ids. The caller of
48147c2aad20Sopenharmony_ci *             bpf_per_cpu_ptr() must check the returned value.
48157c2aad20Sopenharmony_ci *     Return
48167c2aad20Sopenharmony_ci *             A pointer pointing to the kernel percpu variable on *cpu*, or
48177c2aad20Sopenharmony_ci *             NULL, if *cpu* is invalid.
48187c2aad20Sopenharmony_ci *
48197c2aad20Sopenharmony_ci * void *bpf_this_cpu_ptr(const void *percpu_ptr)
48207c2aad20Sopenharmony_ci *	Description
48217c2aad20Sopenharmony_ci *		Take a pointer to a percpu ksym, *percpu_ptr*, and return a
48227c2aad20Sopenharmony_ci *		pointer to the percpu kernel variable on this cpu. See the
48237c2aad20Sopenharmony_ci *		description of 'ksym' in **bpf_per_cpu_ptr**\ ().
48247c2aad20Sopenharmony_ci *
48257c2aad20Sopenharmony_ci *		bpf_this_cpu_ptr() has the same semantic as this_cpu_ptr() in
48267c2aad20Sopenharmony_ci *		the kernel. Different from **bpf_per_cpu_ptr**\ (), it would
48277c2aad20Sopenharmony_ci *		never return NULL.
48287c2aad20Sopenharmony_ci *	Return
48297c2aad20Sopenharmony_ci *		A pointer pointing to the kernel percpu variable on this cpu.
48307c2aad20Sopenharmony_ci *
48317c2aad20Sopenharmony_ci * long bpf_redirect_peer(u32 ifindex, u64 flags)
48327c2aad20Sopenharmony_ci * 	Description
48337c2aad20Sopenharmony_ci * 		Redirect the packet to another net device of index *ifindex*.
48347c2aad20Sopenharmony_ci * 		This helper is somewhat similar to **bpf_redirect**\ (), except
48357c2aad20Sopenharmony_ci * 		that the redirection happens to the *ifindex*' peer device and
48367c2aad20Sopenharmony_ci * 		the netns switch takes place from ingress to ingress without
48377c2aad20Sopenharmony_ci * 		going through the CPU's backlog queue.
48387c2aad20Sopenharmony_ci *
48397c2aad20Sopenharmony_ci * 		The *flags* argument is reserved and must be 0. The helper is
48407c2aad20Sopenharmony_ci * 		currently only supported for tc BPF program types at the ingress
48417c2aad20Sopenharmony_ci * 		hook and for veth device types. The peer device must reside in a
48427c2aad20Sopenharmony_ci * 		different network namespace.
48437c2aad20Sopenharmony_ci * 	Return
48447c2aad20Sopenharmony_ci * 		The helper returns **TC_ACT_REDIRECT** on success or
48457c2aad20Sopenharmony_ci * 		**TC_ACT_SHOT** on error.
48467c2aad20Sopenharmony_ci *
48477c2aad20Sopenharmony_ci * void *bpf_task_storage_get(struct bpf_map *map, struct task_struct *task, void *value, u64 flags)
48487c2aad20Sopenharmony_ci *	Description
48497c2aad20Sopenharmony_ci *		Get a bpf_local_storage from the *task*.
48507c2aad20Sopenharmony_ci *
48517c2aad20Sopenharmony_ci *		Logically, it could be thought of as getting the value from
48527c2aad20Sopenharmony_ci *		a *map* with *task* as the **key**.  From this
48537c2aad20Sopenharmony_ci *		perspective,  the usage is not much different from
48547c2aad20Sopenharmony_ci *		**bpf_map_lookup_elem**\ (*map*, **&**\ *task*) except this
48557c2aad20Sopenharmony_ci *		helper enforces the key must be a task_struct and the map must also
48567c2aad20Sopenharmony_ci *		be a **BPF_MAP_TYPE_TASK_STORAGE**.
48577c2aad20Sopenharmony_ci *
48587c2aad20Sopenharmony_ci *		Underneath, the value is stored locally at *task* instead of
48597c2aad20Sopenharmony_ci *		the *map*.  The *map* is used as the bpf-local-storage
48607c2aad20Sopenharmony_ci *		"type". The bpf-local-storage "type" (i.e. the *map*) is
48617c2aad20Sopenharmony_ci *		searched against all bpf_local_storage residing at *task*.
48627c2aad20Sopenharmony_ci *
48637c2aad20Sopenharmony_ci *		An optional *flags* (**BPF_LOCAL_STORAGE_GET_F_CREATE**) can be
48647c2aad20Sopenharmony_ci *		used such that a new bpf_local_storage will be
48657c2aad20Sopenharmony_ci *		created if one does not exist.  *value* can be used
48667c2aad20Sopenharmony_ci *		together with **BPF_LOCAL_STORAGE_GET_F_CREATE** to specify
48677c2aad20Sopenharmony_ci *		the initial value of a bpf_local_storage.  If *value* is
48687c2aad20Sopenharmony_ci *		**NULL**, the new bpf_local_storage will be zero initialized.
48697c2aad20Sopenharmony_ci *	Return
48707c2aad20Sopenharmony_ci *		A bpf_local_storage pointer is returned on success.
48717c2aad20Sopenharmony_ci *
48727c2aad20Sopenharmony_ci *		**NULL** if not found or there was an error in adding
48737c2aad20Sopenharmony_ci *		a new bpf_local_storage.
48747c2aad20Sopenharmony_ci *
48757c2aad20Sopenharmony_ci * long bpf_task_storage_delete(struct bpf_map *map, struct task_struct *task)
48767c2aad20Sopenharmony_ci *	Description
48777c2aad20Sopenharmony_ci *		Delete a bpf_local_storage from a *task*.
48787c2aad20Sopenharmony_ci *	Return
48797c2aad20Sopenharmony_ci *		0 on success.
48807c2aad20Sopenharmony_ci *
48817c2aad20Sopenharmony_ci *		**-ENOENT** if the bpf_local_storage cannot be found.
48827c2aad20Sopenharmony_ci *
48837c2aad20Sopenharmony_ci * struct task_struct *bpf_get_current_task_btf(void)
48847c2aad20Sopenharmony_ci *	Description
48857c2aad20Sopenharmony_ci *		Return a BTF pointer to the "current" task.
48867c2aad20Sopenharmony_ci *		This pointer can also be used in helpers that accept an
48877c2aad20Sopenharmony_ci *		*ARG_PTR_TO_BTF_ID* of type *task_struct*.
48887c2aad20Sopenharmony_ci *	Return
48897c2aad20Sopenharmony_ci *		Pointer to the current task.
48907c2aad20Sopenharmony_ci *
48917c2aad20Sopenharmony_ci * long bpf_bprm_opts_set(struct linux_binprm *bprm, u64 flags)
48927c2aad20Sopenharmony_ci *	Description
48937c2aad20Sopenharmony_ci *		Set or clear certain options on *bprm*:
48947c2aad20Sopenharmony_ci *
48957c2aad20Sopenharmony_ci *		**BPF_F_BPRM_SECUREEXEC** Set the secureexec bit
48967c2aad20Sopenharmony_ci *		which sets the **AT_SECURE** auxv for glibc. The bit
48977c2aad20Sopenharmony_ci *		is cleared if the flag is not specified.
48987c2aad20Sopenharmony_ci *	Return
48997c2aad20Sopenharmony_ci *		**-EINVAL** if invalid *flags* are passed, zero otherwise.
49007c2aad20Sopenharmony_ci *
49017c2aad20Sopenharmony_ci * u64 bpf_ktime_get_coarse_ns(void)
49027c2aad20Sopenharmony_ci * 	Description
49037c2aad20Sopenharmony_ci * 		Return a coarse-grained version of the time elapsed since
49047c2aad20Sopenharmony_ci * 		system boot, in nanoseconds. Does not include time the system
49057c2aad20Sopenharmony_ci * 		was suspended.
49067c2aad20Sopenharmony_ci *
49077c2aad20Sopenharmony_ci * 		See: **clock_gettime**\ (**CLOCK_MONOTONIC_COARSE**)
49087c2aad20Sopenharmony_ci * 	Return
49097c2aad20Sopenharmony_ci * 		Current *ktime*.
49107c2aad20Sopenharmony_ci *
49117c2aad20Sopenharmony_ci * long bpf_ima_inode_hash(struct inode *inode, void *dst, u32 size)
49127c2aad20Sopenharmony_ci *	Description
49137c2aad20Sopenharmony_ci *		Returns the stored IMA hash of the *inode* (if it's available).
49147c2aad20Sopenharmony_ci *		If the hash is larger than *size*, then only *size*
49157c2aad20Sopenharmony_ci *		bytes will be copied to *dst*
49167c2aad20Sopenharmony_ci *	Return
49177c2aad20Sopenharmony_ci *		The **hash_algo** is returned on success,
49187c2aad20Sopenharmony_ci *		**-EOPNOTSUP** if IMA is disabled or **-EINVAL** if
49197c2aad20Sopenharmony_ci *		invalid arguments are passed.
49207c2aad20Sopenharmony_ci *
49217c2aad20Sopenharmony_ci * struct socket *bpf_sock_from_file(struct file *file)
49227c2aad20Sopenharmony_ci *	Description
49237c2aad20Sopenharmony_ci *		If the given file represents a socket, returns the associated
49247c2aad20Sopenharmony_ci *		socket.
49257c2aad20Sopenharmony_ci *	Return
49267c2aad20Sopenharmony_ci *		A pointer to a struct socket on success or NULL if the file is
49277c2aad20Sopenharmony_ci *		not a socket.
49287c2aad20Sopenharmony_ci *
49297c2aad20Sopenharmony_ci * long bpf_check_mtu(void *ctx, u32 ifindex, u32 *mtu_len, s32 len_diff, u64 flags)
49307c2aad20Sopenharmony_ci *	Description
49317c2aad20Sopenharmony_ci *		Check packet size against exceeding MTU of net device (based
49327c2aad20Sopenharmony_ci *		on *ifindex*).  This helper will likely be used in combination
49337c2aad20Sopenharmony_ci *		with helpers that adjust/change the packet size.
49347c2aad20Sopenharmony_ci *
49357c2aad20Sopenharmony_ci *		The argument *len_diff* can be used for querying with a planned
49367c2aad20Sopenharmony_ci *		size change. This allows to check MTU prior to changing packet
49377c2aad20Sopenharmony_ci *		ctx. Providing a *len_diff* adjustment that is larger than the
49387c2aad20Sopenharmony_ci *		actual packet size (resulting in negative packet size) will in
49397c2aad20Sopenharmony_ci *		principle not exceed the MTU, which is why it is not considered
49407c2aad20Sopenharmony_ci *		a failure.  Other BPF helpers are needed for performing the
49417c2aad20Sopenharmony_ci *		planned size change; therefore the responsibility for catching
49427c2aad20Sopenharmony_ci *		a negative packet size belongs in those helpers.
49437c2aad20Sopenharmony_ci *
49447c2aad20Sopenharmony_ci *		Specifying *ifindex* zero means the MTU check is performed
49457c2aad20Sopenharmony_ci *		against the current net device.  This is practical if this isn't
49467c2aad20Sopenharmony_ci *		used prior to redirect.
49477c2aad20Sopenharmony_ci *
49487c2aad20Sopenharmony_ci *		On input *mtu_len* must be a valid pointer, else verifier will
49497c2aad20Sopenharmony_ci *		reject BPF program.  If the value *mtu_len* is initialized to
49507c2aad20Sopenharmony_ci *		zero then the ctx packet size is use.  When value *mtu_len* is
49517c2aad20Sopenharmony_ci *		provided as input this specify the L3 length that the MTU check
49527c2aad20Sopenharmony_ci *		is done against. Remember XDP and TC length operate at L2, but
49537c2aad20Sopenharmony_ci *		this value is L3 as this correlate to MTU and IP-header tot_len
49547c2aad20Sopenharmony_ci *		values which are L3 (similar behavior as bpf_fib_lookup).
49557c2aad20Sopenharmony_ci *
49567c2aad20Sopenharmony_ci *		The Linux kernel route table can configure MTUs on a more
49577c2aad20Sopenharmony_ci *		specific per route level, which is not provided by this helper.
49587c2aad20Sopenharmony_ci *		For route level MTU checks use the **bpf_fib_lookup**\ ()
49597c2aad20Sopenharmony_ci *		helper.
49607c2aad20Sopenharmony_ci *
49617c2aad20Sopenharmony_ci *		*ctx* is either **struct xdp_md** for XDP programs or
49627c2aad20Sopenharmony_ci *		**struct sk_buff** for tc cls_act programs.
49637c2aad20Sopenharmony_ci *
49647c2aad20Sopenharmony_ci *		The *flags* argument can be a combination of one or more of the
49657c2aad20Sopenharmony_ci *		following values:
49667c2aad20Sopenharmony_ci *
49677c2aad20Sopenharmony_ci *		**BPF_MTU_CHK_SEGS**
49687c2aad20Sopenharmony_ci *			This flag will only works for *ctx* **struct sk_buff**.
49697c2aad20Sopenharmony_ci *			If packet context contains extra packet segment buffers
49707c2aad20Sopenharmony_ci *			(often knows as GSO skb), then MTU check is harder to
49717c2aad20Sopenharmony_ci *			check at this point, because in transmit path it is
49727c2aad20Sopenharmony_ci *			possible for the skb packet to get re-segmented
49737c2aad20Sopenharmony_ci *			(depending on net device features).  This could still be
49747c2aad20Sopenharmony_ci *			a MTU violation, so this flag enables performing MTU
49757c2aad20Sopenharmony_ci *			check against segments, with a different violation
49767c2aad20Sopenharmony_ci *			return code to tell it apart. Check cannot use len_diff.
49777c2aad20Sopenharmony_ci *
49787c2aad20Sopenharmony_ci *		On return *mtu_len* pointer contains the MTU value of the net
49797c2aad20Sopenharmony_ci *		device.  Remember the net device configured MTU is the L3 size,
49807c2aad20Sopenharmony_ci *		which is returned here and XDP and TC length operate at L2.
49817c2aad20Sopenharmony_ci *		Helper take this into account for you, but remember when using
49827c2aad20Sopenharmony_ci *		MTU value in your BPF-code.
49837c2aad20Sopenharmony_ci *
49847c2aad20Sopenharmony_ci *	Return
49857c2aad20Sopenharmony_ci *		* 0 on success, and populate MTU value in *mtu_len* pointer.
49867c2aad20Sopenharmony_ci *
49877c2aad20Sopenharmony_ci *		* < 0 if any input argument is invalid (*mtu_len* not updated)
49887c2aad20Sopenharmony_ci *
49897c2aad20Sopenharmony_ci *		MTU violations return positive values, but also populate MTU
49907c2aad20Sopenharmony_ci *		value in *mtu_len* pointer, as this can be needed for
49917c2aad20Sopenharmony_ci *		implementing PMTU handing:
49927c2aad20Sopenharmony_ci *
49937c2aad20Sopenharmony_ci *		* **BPF_MTU_CHK_RET_FRAG_NEEDED**
49947c2aad20Sopenharmony_ci *		* **BPF_MTU_CHK_RET_SEGS_TOOBIG**
49957c2aad20Sopenharmony_ci *
49967c2aad20Sopenharmony_ci * long bpf_for_each_map_elem(struct bpf_map *map, void *callback_fn, void *callback_ctx, u64 flags)
49977c2aad20Sopenharmony_ci *	Description
49987c2aad20Sopenharmony_ci *		For each element in **map**, call **callback_fn** function with
49997c2aad20Sopenharmony_ci *		**map**, **callback_ctx** and other map-specific parameters.
50007c2aad20Sopenharmony_ci *		The **callback_fn** should be a static function and
50017c2aad20Sopenharmony_ci *		the **callback_ctx** should be a pointer to the stack.
50027c2aad20Sopenharmony_ci *		The **flags** is used to control certain aspects of the helper.
50037c2aad20Sopenharmony_ci *		Currently, the **flags** must be 0.
50047c2aad20Sopenharmony_ci *
50057c2aad20Sopenharmony_ci *		The following are a list of supported map types and their
50067c2aad20Sopenharmony_ci *		respective expected callback signatures:
50077c2aad20Sopenharmony_ci *
50087c2aad20Sopenharmony_ci *		BPF_MAP_TYPE_HASH, BPF_MAP_TYPE_PERCPU_HASH,
50097c2aad20Sopenharmony_ci *		BPF_MAP_TYPE_LRU_HASH, BPF_MAP_TYPE_LRU_PERCPU_HASH,
50107c2aad20Sopenharmony_ci *		BPF_MAP_TYPE_ARRAY, BPF_MAP_TYPE_PERCPU_ARRAY
50117c2aad20Sopenharmony_ci *
50127c2aad20Sopenharmony_ci *		long (\*callback_fn)(struct bpf_map \*map, const void \*key, void \*value, void \*ctx);
50137c2aad20Sopenharmony_ci *
50147c2aad20Sopenharmony_ci *		For per_cpu maps, the map_value is the value on the cpu where the
50157c2aad20Sopenharmony_ci *		bpf_prog is running.
50167c2aad20Sopenharmony_ci *
50177c2aad20Sopenharmony_ci *		If **callback_fn** return 0, the helper will continue to the next
50187c2aad20Sopenharmony_ci *		element. If return value is 1, the helper will skip the rest of
50197c2aad20Sopenharmony_ci *		elements and return. Other return values are not used now.
50207c2aad20Sopenharmony_ci *
50217c2aad20Sopenharmony_ci *	Return
50227c2aad20Sopenharmony_ci *		The number of traversed map elements for success, **-EINVAL** for
50237c2aad20Sopenharmony_ci *		invalid **flags**.
50247c2aad20Sopenharmony_ci *
50257c2aad20Sopenharmony_ci * long bpf_snprintf(char *str, u32 str_size, const char *fmt, u64 *data, u32 data_len)
50267c2aad20Sopenharmony_ci *	Description
50277c2aad20Sopenharmony_ci *		Outputs a string into the **str** buffer of size **str_size**
50287c2aad20Sopenharmony_ci *		based on a format string stored in a read-only map pointed by
50297c2aad20Sopenharmony_ci *		**fmt**.
50307c2aad20Sopenharmony_ci *
50317c2aad20Sopenharmony_ci *		Each format specifier in **fmt** corresponds to one u64 element
50327c2aad20Sopenharmony_ci *		in the **data** array. For strings and pointers where pointees
50337c2aad20Sopenharmony_ci *		are accessed, only the pointer values are stored in the *data*
50347c2aad20Sopenharmony_ci *		array. The *data_len* is the size of *data* in bytes - must be
50357c2aad20Sopenharmony_ci *		a multiple of 8.
50367c2aad20Sopenharmony_ci *
50377c2aad20Sopenharmony_ci *		Formats **%s** and **%p{i,I}{4,6}** require to read kernel
50387c2aad20Sopenharmony_ci *		memory. Reading kernel memory may fail due to either invalid
50397c2aad20Sopenharmony_ci *		address or valid address but requiring a major memory fault. If
50407c2aad20Sopenharmony_ci *		reading kernel memory fails, the string for **%s** will be an
50417c2aad20Sopenharmony_ci *		empty string, and the ip address for **%p{i,I}{4,6}** will be 0.
50427c2aad20Sopenharmony_ci *		Not returning error to bpf program is consistent with what
50437c2aad20Sopenharmony_ci *		**bpf_trace_printk**\ () does for now.
50447c2aad20Sopenharmony_ci *
50457c2aad20Sopenharmony_ci *	Return
50467c2aad20Sopenharmony_ci *		The strictly positive length of the formatted string, including
50477c2aad20Sopenharmony_ci *		the trailing zero character. If the return value is greater than
50487c2aad20Sopenharmony_ci *		**str_size**, **str** contains a truncated string, guaranteed to
50497c2aad20Sopenharmony_ci *		be zero-terminated except when **str_size** is 0.
50507c2aad20Sopenharmony_ci *
50517c2aad20Sopenharmony_ci *		Or **-EBUSY** if the per-CPU memory copy buffer is busy.
50527c2aad20Sopenharmony_ci *
50537c2aad20Sopenharmony_ci * long bpf_sys_bpf(u32 cmd, void *attr, u32 attr_size)
50547c2aad20Sopenharmony_ci * 	Description
50557c2aad20Sopenharmony_ci * 		Execute bpf syscall with given arguments.
50567c2aad20Sopenharmony_ci * 	Return
50577c2aad20Sopenharmony_ci * 		A syscall result.
50587c2aad20Sopenharmony_ci *
50597c2aad20Sopenharmony_ci * long bpf_btf_find_by_name_kind(char *name, int name_sz, u32 kind, int flags)
50607c2aad20Sopenharmony_ci * 	Description
50617c2aad20Sopenharmony_ci * 		Find BTF type with given name and kind in vmlinux BTF or in module's BTFs.
50627c2aad20Sopenharmony_ci * 	Return
50637c2aad20Sopenharmony_ci * 		Returns btf_id and btf_obj_fd in lower and upper 32 bits.
50647c2aad20Sopenharmony_ci *
50657c2aad20Sopenharmony_ci * long bpf_sys_close(u32 fd)
50667c2aad20Sopenharmony_ci * 	Description
50677c2aad20Sopenharmony_ci * 		Execute close syscall for given FD.
50687c2aad20Sopenharmony_ci * 	Return
50697c2aad20Sopenharmony_ci * 		A syscall result.
50707c2aad20Sopenharmony_ci *
50717c2aad20Sopenharmony_ci * long bpf_timer_init(struct bpf_timer *timer, struct bpf_map *map, u64 flags)
50727c2aad20Sopenharmony_ci *	Description
50737c2aad20Sopenharmony_ci *		Initialize the timer.
50747c2aad20Sopenharmony_ci *		First 4 bits of *flags* specify clockid.
50757c2aad20Sopenharmony_ci *		Only CLOCK_MONOTONIC, CLOCK_REALTIME, CLOCK_BOOTTIME are allowed.
50767c2aad20Sopenharmony_ci *		All other bits of *flags* are reserved.
50777c2aad20Sopenharmony_ci *		The verifier will reject the program if *timer* is not from
50787c2aad20Sopenharmony_ci *		the same *map*.
50797c2aad20Sopenharmony_ci *	Return
50807c2aad20Sopenharmony_ci *		0 on success.
50817c2aad20Sopenharmony_ci *		**-EBUSY** if *timer* is already initialized.
50827c2aad20Sopenharmony_ci *		**-EINVAL** if invalid *flags* are passed.
50837c2aad20Sopenharmony_ci *		**-EPERM** if *timer* is in a map that doesn't have any user references.
50847c2aad20Sopenharmony_ci *		The user space should either hold a file descriptor to a map with timers
50857c2aad20Sopenharmony_ci *		or pin such map in bpffs. When map is unpinned or file descriptor is
50867c2aad20Sopenharmony_ci *		closed all timers in the map will be cancelled and freed.
50877c2aad20Sopenharmony_ci *
50887c2aad20Sopenharmony_ci * long bpf_timer_set_callback(struct bpf_timer *timer, void *callback_fn)
50897c2aad20Sopenharmony_ci *	Description
50907c2aad20Sopenharmony_ci *		Configure the timer to call *callback_fn* static function.
50917c2aad20Sopenharmony_ci *	Return
50927c2aad20Sopenharmony_ci *		0 on success.
50937c2aad20Sopenharmony_ci *		**-EINVAL** if *timer* was not initialized with bpf_timer_init() earlier.
50947c2aad20Sopenharmony_ci *		**-EPERM** if *timer* is in a map that doesn't have any user references.
50957c2aad20Sopenharmony_ci *		The user space should either hold a file descriptor to a map with timers
50967c2aad20Sopenharmony_ci *		or pin such map in bpffs. When map is unpinned or file descriptor is
50977c2aad20Sopenharmony_ci *		closed all timers in the map will be cancelled and freed.
50987c2aad20Sopenharmony_ci *
50997c2aad20Sopenharmony_ci * long bpf_timer_start(struct bpf_timer *timer, u64 nsecs, u64 flags)
51007c2aad20Sopenharmony_ci *	Description
51017c2aad20Sopenharmony_ci *		Set timer expiration N nanoseconds from the current time. The
51027c2aad20Sopenharmony_ci *		configured callback will be invoked in soft irq context on some cpu
51037c2aad20Sopenharmony_ci *		and will not repeat unless another bpf_timer_start() is made.
51047c2aad20Sopenharmony_ci *		In such case the next invocation can migrate to a different cpu.
51057c2aad20Sopenharmony_ci *		Since struct bpf_timer is a field inside map element the map
51067c2aad20Sopenharmony_ci *		owns the timer. The bpf_timer_set_callback() will increment refcnt
51077c2aad20Sopenharmony_ci *		of BPF program to make sure that callback_fn code stays valid.
51087c2aad20Sopenharmony_ci *		When user space reference to a map reaches zero all timers
51097c2aad20Sopenharmony_ci *		in a map are cancelled and corresponding program's refcnts are
51107c2aad20Sopenharmony_ci *		decremented. This is done to make sure that Ctrl-C of a user
51117c2aad20Sopenharmony_ci *		process doesn't leave any timers running. If map is pinned in
51127c2aad20Sopenharmony_ci *		bpffs the callback_fn can re-arm itself indefinitely.
51137c2aad20Sopenharmony_ci *		bpf_map_update/delete_elem() helpers and user space sys_bpf commands
51147c2aad20Sopenharmony_ci *		cancel and free the timer in the given map element.
51157c2aad20Sopenharmony_ci *		The map can contain timers that invoke callback_fn-s from different
51167c2aad20Sopenharmony_ci *		programs. The same callback_fn can serve different timers from
51177c2aad20Sopenharmony_ci *		different maps if key/value layout matches across maps.
51187c2aad20Sopenharmony_ci *		Every bpf_timer_set_callback() can have different callback_fn.
51197c2aad20Sopenharmony_ci *
51207c2aad20Sopenharmony_ci *		*flags* can be one of:
51217c2aad20Sopenharmony_ci *
51227c2aad20Sopenharmony_ci *		**BPF_F_TIMER_ABS**
51237c2aad20Sopenharmony_ci *			Start the timer in absolute expire value instead of the
51247c2aad20Sopenharmony_ci *			default relative one.
51257c2aad20Sopenharmony_ci *		**BPF_F_TIMER_CPU_PIN**
51267c2aad20Sopenharmony_ci *			Timer will be pinned to the CPU of the caller.
51277c2aad20Sopenharmony_ci *
51287c2aad20Sopenharmony_ci *	Return
51297c2aad20Sopenharmony_ci *		0 on success.
51307c2aad20Sopenharmony_ci *		**-EINVAL** if *timer* was not initialized with bpf_timer_init() earlier
51317c2aad20Sopenharmony_ci *		or invalid *flags* are passed.
51327c2aad20Sopenharmony_ci *
51337c2aad20Sopenharmony_ci * long bpf_timer_cancel(struct bpf_timer *timer)
51347c2aad20Sopenharmony_ci *	Description
51357c2aad20Sopenharmony_ci *		Cancel the timer and wait for callback_fn to finish if it was running.
51367c2aad20Sopenharmony_ci *	Return
51377c2aad20Sopenharmony_ci *		0 if the timer was not active.
51387c2aad20Sopenharmony_ci *		1 if the timer was active.
51397c2aad20Sopenharmony_ci *		**-EINVAL** if *timer* was not initialized with bpf_timer_init() earlier.
51407c2aad20Sopenharmony_ci *		**-EDEADLK** if callback_fn tried to call bpf_timer_cancel() on its
51417c2aad20Sopenharmony_ci *		own timer which would have led to a deadlock otherwise.
51427c2aad20Sopenharmony_ci *
51437c2aad20Sopenharmony_ci * u64 bpf_get_func_ip(void *ctx)
51447c2aad20Sopenharmony_ci * 	Description
51457c2aad20Sopenharmony_ci * 		Get address of the traced function (for tracing and kprobe programs).
51467c2aad20Sopenharmony_ci *
51477c2aad20Sopenharmony_ci * 		When called for kprobe program attached as uprobe it returns
51487c2aad20Sopenharmony_ci * 		probe address for both entry and return uprobe.
51497c2aad20Sopenharmony_ci *
51507c2aad20Sopenharmony_ci * 	Return
51517c2aad20Sopenharmony_ci * 		Address of the traced function for kprobe.
51527c2aad20Sopenharmony_ci * 		0 for kprobes placed within the function (not at the entry).
51537c2aad20Sopenharmony_ci * 		Address of the probe for uprobe and return uprobe.
51547c2aad20Sopenharmony_ci *
51557c2aad20Sopenharmony_ci * u64 bpf_get_attach_cookie(void *ctx)
51567c2aad20Sopenharmony_ci * 	Description
51577c2aad20Sopenharmony_ci * 		Get bpf_cookie value provided (optionally) during the program
51587c2aad20Sopenharmony_ci * 		attachment. It might be different for each individual
51597c2aad20Sopenharmony_ci * 		attachment, even if BPF program itself is the same.
51607c2aad20Sopenharmony_ci * 		Expects BPF program context *ctx* as a first argument.
51617c2aad20Sopenharmony_ci *
51627c2aad20Sopenharmony_ci * 		Supported for the following program types:
51637c2aad20Sopenharmony_ci *			- kprobe/uprobe;
51647c2aad20Sopenharmony_ci *			- tracepoint;
51657c2aad20Sopenharmony_ci *			- perf_event.
51667c2aad20Sopenharmony_ci * 	Return
51677c2aad20Sopenharmony_ci *		Value specified by user at BPF link creation/attachment time
51687c2aad20Sopenharmony_ci *		or 0, if it was not specified.
51697c2aad20Sopenharmony_ci *
51707c2aad20Sopenharmony_ci * long bpf_task_pt_regs(struct task_struct *task)
51717c2aad20Sopenharmony_ci *	Description
51727c2aad20Sopenharmony_ci *		Get the struct pt_regs associated with **task**.
51737c2aad20Sopenharmony_ci *	Return
51747c2aad20Sopenharmony_ci *		A pointer to struct pt_regs.
51757c2aad20Sopenharmony_ci *
51767c2aad20Sopenharmony_ci * long bpf_get_branch_snapshot(void *entries, u32 size, u64 flags)
51777c2aad20Sopenharmony_ci *	Description
51787c2aad20Sopenharmony_ci *		Get branch trace from hardware engines like Intel LBR. The
51797c2aad20Sopenharmony_ci *		hardware engine is stopped shortly after the helper is
51807c2aad20Sopenharmony_ci *		called. Therefore, the user need to filter branch entries
51817c2aad20Sopenharmony_ci *		based on the actual use case. To capture branch trace
51827c2aad20Sopenharmony_ci *		before the trigger point of the BPF program, the helper
51837c2aad20Sopenharmony_ci *		should be called at the beginning of the BPF program.
51847c2aad20Sopenharmony_ci *
51857c2aad20Sopenharmony_ci *		The data is stored as struct perf_branch_entry into output
51867c2aad20Sopenharmony_ci *		buffer *entries*. *size* is the size of *entries* in bytes.
51877c2aad20Sopenharmony_ci *		*flags* is reserved for now and must be zero.
51887c2aad20Sopenharmony_ci *
51897c2aad20Sopenharmony_ci *	Return
51907c2aad20Sopenharmony_ci *		On success, number of bytes written to *buf*. On error, a
51917c2aad20Sopenharmony_ci *		negative value.
51927c2aad20Sopenharmony_ci *
51937c2aad20Sopenharmony_ci *		**-EINVAL** if *flags* is not zero.
51947c2aad20Sopenharmony_ci *
51957c2aad20Sopenharmony_ci *		**-ENOENT** if architecture does not support branch records.
51967c2aad20Sopenharmony_ci *
51977c2aad20Sopenharmony_ci * long bpf_trace_vprintk(const char *fmt, u32 fmt_size, const void *data, u32 data_len)
51987c2aad20Sopenharmony_ci *	Description
51997c2aad20Sopenharmony_ci *		Behaves like **bpf_trace_printk**\ () helper, but takes an array of u64
52007c2aad20Sopenharmony_ci *		to format and can handle more format args as a result.
52017c2aad20Sopenharmony_ci *
52027c2aad20Sopenharmony_ci *		Arguments are to be used as in **bpf_seq_printf**\ () helper.
52037c2aad20Sopenharmony_ci *	Return
52047c2aad20Sopenharmony_ci *		The number of bytes written to the buffer, or a negative error
52057c2aad20Sopenharmony_ci *		in case of failure.
52067c2aad20Sopenharmony_ci *
52077c2aad20Sopenharmony_ci * struct unix_sock *bpf_skc_to_unix_sock(void *sk)
52087c2aad20Sopenharmony_ci * 	Description
52097c2aad20Sopenharmony_ci *		Dynamically cast a *sk* pointer to a *unix_sock* pointer.
52107c2aad20Sopenharmony_ci *	Return
52117c2aad20Sopenharmony_ci *		*sk* if casting is valid, or **NULL** otherwise.
52127c2aad20Sopenharmony_ci *
52137c2aad20Sopenharmony_ci * long bpf_kallsyms_lookup_name(const char *name, int name_sz, int flags, u64 *res)
52147c2aad20Sopenharmony_ci *	Description
52157c2aad20Sopenharmony_ci *		Get the address of a kernel symbol, returned in *res*. *res* is
52167c2aad20Sopenharmony_ci *		set to 0 if the symbol is not found.
52177c2aad20Sopenharmony_ci *	Return
52187c2aad20Sopenharmony_ci *		On success, zero. On error, a negative value.
52197c2aad20Sopenharmony_ci *
52207c2aad20Sopenharmony_ci *		**-EINVAL** if *flags* is not zero.
52217c2aad20Sopenharmony_ci *
52227c2aad20Sopenharmony_ci *		**-EINVAL** if string *name* is not the same size as *name_sz*.
52237c2aad20Sopenharmony_ci *
52247c2aad20Sopenharmony_ci *		**-ENOENT** if symbol is not found.
52257c2aad20Sopenharmony_ci *
52267c2aad20Sopenharmony_ci *		**-EPERM** if caller does not have permission to obtain kernel address.
52277c2aad20Sopenharmony_ci *
52287c2aad20Sopenharmony_ci * long bpf_find_vma(struct task_struct *task, u64 addr, void *callback_fn, void *callback_ctx, u64 flags)
52297c2aad20Sopenharmony_ci *	Description
52307c2aad20Sopenharmony_ci *		Find vma of *task* that contains *addr*, call *callback_fn*
52317c2aad20Sopenharmony_ci *		function with *task*, *vma*, and *callback_ctx*.
52327c2aad20Sopenharmony_ci *		The *callback_fn* should be a static function and
52337c2aad20Sopenharmony_ci *		the *callback_ctx* should be a pointer to the stack.
52347c2aad20Sopenharmony_ci *		The *flags* is used to control certain aspects of the helper.
52357c2aad20Sopenharmony_ci *		Currently, the *flags* must be 0.
52367c2aad20Sopenharmony_ci *
52377c2aad20Sopenharmony_ci *		The expected callback signature is
52387c2aad20Sopenharmony_ci *
52397c2aad20Sopenharmony_ci *		long (\*callback_fn)(struct task_struct \*task, struct vm_area_struct \*vma, void \*callback_ctx);
52407c2aad20Sopenharmony_ci *
52417c2aad20Sopenharmony_ci *	Return
52427c2aad20Sopenharmony_ci *		0 on success.
52437c2aad20Sopenharmony_ci *		**-ENOENT** if *task->mm* is NULL, or no vma contains *addr*.
52447c2aad20Sopenharmony_ci *		**-EBUSY** if failed to try lock mmap_lock.
52457c2aad20Sopenharmony_ci *		**-EINVAL** for invalid **flags**.
52467c2aad20Sopenharmony_ci *
52477c2aad20Sopenharmony_ci * long bpf_loop(u32 nr_loops, void *callback_fn, void *callback_ctx, u64 flags)
52487c2aad20Sopenharmony_ci *	Description
52497c2aad20Sopenharmony_ci *		For **nr_loops**, call **callback_fn** function
52507c2aad20Sopenharmony_ci *		with **callback_ctx** as the context parameter.
52517c2aad20Sopenharmony_ci *		The **callback_fn** should be a static function and
52527c2aad20Sopenharmony_ci *		the **callback_ctx** should be a pointer to the stack.
52537c2aad20Sopenharmony_ci *		The **flags** is used to control certain aspects of the helper.
52547c2aad20Sopenharmony_ci *		Currently, the **flags** must be 0. Currently, nr_loops is
52557c2aad20Sopenharmony_ci *		limited to 1 << 23 (~8 million) loops.
52567c2aad20Sopenharmony_ci *
52577c2aad20Sopenharmony_ci *		long (\*callback_fn)(u32 index, void \*ctx);
52587c2aad20Sopenharmony_ci *
52597c2aad20Sopenharmony_ci *		where **index** is the current index in the loop. The index
52607c2aad20Sopenharmony_ci *		is zero-indexed.
52617c2aad20Sopenharmony_ci *
52627c2aad20Sopenharmony_ci *		If **callback_fn** returns 0, the helper will continue to the next
52637c2aad20Sopenharmony_ci *		loop. If return value is 1, the helper will skip the rest of
52647c2aad20Sopenharmony_ci *		the loops and return. Other return values are not used now,
52657c2aad20Sopenharmony_ci *		and will be rejected by the verifier.
52667c2aad20Sopenharmony_ci *
52677c2aad20Sopenharmony_ci *	Return
52687c2aad20Sopenharmony_ci *		The number of loops performed, **-EINVAL** for invalid **flags**,
52697c2aad20Sopenharmony_ci *		**-E2BIG** if **nr_loops** exceeds the maximum number of loops.
52707c2aad20Sopenharmony_ci *
52717c2aad20Sopenharmony_ci * long bpf_strncmp(const char *s1, u32 s1_sz, const char *s2)
52727c2aad20Sopenharmony_ci *	Description
52737c2aad20Sopenharmony_ci *		Do strncmp() between **s1** and **s2**. **s1** doesn't need
52747c2aad20Sopenharmony_ci *		to be null-terminated and **s1_sz** is the maximum storage
52757c2aad20Sopenharmony_ci *		size of **s1**. **s2** must be a read-only string.
52767c2aad20Sopenharmony_ci *	Return
52777c2aad20Sopenharmony_ci *		An integer less than, equal to, or greater than zero
52787c2aad20Sopenharmony_ci *		if the first **s1_sz** bytes of **s1** is found to be
52797c2aad20Sopenharmony_ci *		less than, to match, or be greater than **s2**.
52807c2aad20Sopenharmony_ci *
52817c2aad20Sopenharmony_ci * long bpf_get_func_arg(void *ctx, u32 n, u64 *value)
52827c2aad20Sopenharmony_ci *	Description
52837c2aad20Sopenharmony_ci *		Get **n**-th argument register (zero based) of the traced function (for tracing programs)
52847c2aad20Sopenharmony_ci *		returned in **value**.
52857c2aad20Sopenharmony_ci *
52867c2aad20Sopenharmony_ci *	Return
52877c2aad20Sopenharmony_ci *		0 on success.
52887c2aad20Sopenharmony_ci *		**-EINVAL** if n >= argument register count of traced function.
52897c2aad20Sopenharmony_ci *
52907c2aad20Sopenharmony_ci * long bpf_get_func_ret(void *ctx, u64 *value)
52917c2aad20Sopenharmony_ci *	Description
52927c2aad20Sopenharmony_ci *		Get return value of the traced function (for tracing programs)
52937c2aad20Sopenharmony_ci *		in **value**.
52947c2aad20Sopenharmony_ci *
52957c2aad20Sopenharmony_ci *	Return
52967c2aad20Sopenharmony_ci *		0 on success.
52977c2aad20Sopenharmony_ci *		**-EOPNOTSUPP** for tracing programs other than BPF_TRACE_FEXIT or BPF_MODIFY_RETURN.
52987c2aad20Sopenharmony_ci *
52997c2aad20Sopenharmony_ci * long bpf_get_func_arg_cnt(void *ctx)
53007c2aad20Sopenharmony_ci *	Description
53017c2aad20Sopenharmony_ci *		Get number of registers of the traced function (for tracing programs) where
53027c2aad20Sopenharmony_ci *		function arguments are stored in these registers.
53037c2aad20Sopenharmony_ci *
53047c2aad20Sopenharmony_ci *	Return
53057c2aad20Sopenharmony_ci *		The number of argument registers of the traced function.
53067c2aad20Sopenharmony_ci *
53077c2aad20Sopenharmony_ci * int bpf_get_retval(void)
53087c2aad20Sopenharmony_ci *	Description
53097c2aad20Sopenharmony_ci *		Get the BPF program's return value that will be returned to the upper layers.
53107c2aad20Sopenharmony_ci *
53117c2aad20Sopenharmony_ci *		This helper is currently supported by cgroup programs and only by the hooks
53127c2aad20Sopenharmony_ci *		where BPF program's return value is returned to the userspace via errno.
53137c2aad20Sopenharmony_ci *	Return
53147c2aad20Sopenharmony_ci *		The BPF program's return value.
53157c2aad20Sopenharmony_ci *
53167c2aad20Sopenharmony_ci * int bpf_set_retval(int retval)
53177c2aad20Sopenharmony_ci *	Description
53187c2aad20Sopenharmony_ci *		Set the BPF program's return value that will be returned to the upper layers.
53197c2aad20Sopenharmony_ci *
53207c2aad20Sopenharmony_ci *		This helper is currently supported by cgroup programs and only by the hooks
53217c2aad20Sopenharmony_ci *		where BPF program's return value is returned to the userspace via errno.
53227c2aad20Sopenharmony_ci *
53237c2aad20Sopenharmony_ci *		Note that there is the following corner case where the program exports an error
53247c2aad20Sopenharmony_ci *		via bpf_set_retval but signals success via 'return 1':
53257c2aad20Sopenharmony_ci *
53267c2aad20Sopenharmony_ci *			bpf_set_retval(-EPERM);
53277c2aad20Sopenharmony_ci *			return 1;
53287c2aad20Sopenharmony_ci *
53297c2aad20Sopenharmony_ci *		In this case, the BPF program's return value will use helper's -EPERM. This
53307c2aad20Sopenharmony_ci *		still holds true for cgroup/bind{4,6} which supports extra 'return 3' success case.
53317c2aad20Sopenharmony_ci *
53327c2aad20Sopenharmony_ci *	Return
53337c2aad20Sopenharmony_ci *		0 on success, or a negative error in case of failure.
53347c2aad20Sopenharmony_ci *
53357c2aad20Sopenharmony_ci * u64 bpf_xdp_get_buff_len(struct xdp_buff *xdp_md)
53367c2aad20Sopenharmony_ci *	Description
53377c2aad20Sopenharmony_ci *		Get the total size of a given xdp buff (linear and paged area)
53387c2aad20Sopenharmony_ci *	Return
53397c2aad20Sopenharmony_ci *		The total size of a given xdp buffer.
53407c2aad20Sopenharmony_ci *
53417c2aad20Sopenharmony_ci * long bpf_xdp_load_bytes(struct xdp_buff *xdp_md, u32 offset, void *buf, u32 len)
53427c2aad20Sopenharmony_ci *	Description
53437c2aad20Sopenharmony_ci *		This helper is provided as an easy way to load data from a
53447c2aad20Sopenharmony_ci *		xdp buffer. It can be used to load *len* bytes from *offset* from
53457c2aad20Sopenharmony_ci *		the frame associated to *xdp_md*, into the buffer pointed by
53467c2aad20Sopenharmony_ci *		*buf*.
53477c2aad20Sopenharmony_ci *	Return
53487c2aad20Sopenharmony_ci *		0 on success, or a negative error in case of failure.
53497c2aad20Sopenharmony_ci *
53507c2aad20Sopenharmony_ci * long bpf_xdp_store_bytes(struct xdp_buff *xdp_md, u32 offset, void *buf, u32 len)
53517c2aad20Sopenharmony_ci *	Description
53527c2aad20Sopenharmony_ci *		Store *len* bytes from buffer *buf* into the frame
53537c2aad20Sopenharmony_ci *		associated to *xdp_md*, at *offset*.
53547c2aad20Sopenharmony_ci *	Return
53557c2aad20Sopenharmony_ci *		0 on success, or a negative error in case of failure.
53567c2aad20Sopenharmony_ci *
53577c2aad20Sopenharmony_ci * long bpf_copy_from_user_task(void *dst, u32 size, const void *user_ptr, struct task_struct *tsk, u64 flags)
53587c2aad20Sopenharmony_ci *	Description
53597c2aad20Sopenharmony_ci *		Read *size* bytes from user space address *user_ptr* in *tsk*'s
53607c2aad20Sopenharmony_ci *		address space, and stores the data in *dst*. *flags* is not
53617c2aad20Sopenharmony_ci *		used yet and is provided for future extensibility. This helper
53627c2aad20Sopenharmony_ci *		can only be used by sleepable programs.
53637c2aad20Sopenharmony_ci *	Return
53647c2aad20Sopenharmony_ci *		0 on success, or a negative error in case of failure. On error
53657c2aad20Sopenharmony_ci *		*dst* buffer is zeroed out.
53667c2aad20Sopenharmony_ci *
53677c2aad20Sopenharmony_ci * long bpf_skb_set_tstamp(struct sk_buff *skb, u64 tstamp, u32 tstamp_type)
53687c2aad20Sopenharmony_ci *	Description
53697c2aad20Sopenharmony_ci *		Change the __sk_buff->tstamp_type to *tstamp_type*
53707c2aad20Sopenharmony_ci *		and set *tstamp* to the __sk_buff->tstamp together.
53717c2aad20Sopenharmony_ci *
53727c2aad20Sopenharmony_ci *		If there is no need to change the __sk_buff->tstamp_type,
53737c2aad20Sopenharmony_ci *		the tstamp value can be directly written to __sk_buff->tstamp
53747c2aad20Sopenharmony_ci *		instead.
53757c2aad20Sopenharmony_ci *
53767c2aad20Sopenharmony_ci *		BPF_SKB_TSTAMP_DELIVERY_MONO is the only tstamp that
53777c2aad20Sopenharmony_ci *		will be kept during bpf_redirect_*().  A non zero
53787c2aad20Sopenharmony_ci *		*tstamp* must be used with the BPF_SKB_TSTAMP_DELIVERY_MONO
53797c2aad20Sopenharmony_ci *		*tstamp_type*.
53807c2aad20Sopenharmony_ci *
53817c2aad20Sopenharmony_ci *		A BPF_SKB_TSTAMP_UNSPEC *tstamp_type* can only be used
53827c2aad20Sopenharmony_ci *		with a zero *tstamp*.
53837c2aad20Sopenharmony_ci *
53847c2aad20Sopenharmony_ci *		Only IPv4 and IPv6 skb->protocol are supported.
53857c2aad20Sopenharmony_ci *
53867c2aad20Sopenharmony_ci *		This function is most useful when it needs to set a
53877c2aad20Sopenharmony_ci *		mono delivery time to __sk_buff->tstamp and then
53887c2aad20Sopenharmony_ci *		bpf_redirect_*() to the egress of an iface.  For example,
53897c2aad20Sopenharmony_ci *		changing the (rcv) timestamp in __sk_buff->tstamp at
53907c2aad20Sopenharmony_ci *		ingress to a mono delivery time and then bpf_redirect_*()
53917c2aad20Sopenharmony_ci *		to sch_fq@phy-dev.
53927c2aad20Sopenharmony_ci *	Return
53937c2aad20Sopenharmony_ci *		0 on success.
53947c2aad20Sopenharmony_ci *		**-EINVAL** for invalid input
53957c2aad20Sopenharmony_ci *		**-EOPNOTSUPP** for unsupported protocol
53967c2aad20Sopenharmony_ci *
53977c2aad20Sopenharmony_ci * long bpf_ima_file_hash(struct file *file, void *dst, u32 size)
53987c2aad20Sopenharmony_ci *	Description
53997c2aad20Sopenharmony_ci *		Returns a calculated IMA hash of the *file*.
54007c2aad20Sopenharmony_ci *		If the hash is larger than *size*, then only *size*
54017c2aad20Sopenharmony_ci *		bytes will be copied to *dst*
54027c2aad20Sopenharmony_ci *	Return
54037c2aad20Sopenharmony_ci *		The **hash_algo** is returned on success,
54047c2aad20Sopenharmony_ci *		**-EOPNOTSUP** if the hash calculation failed or **-EINVAL** if
54057c2aad20Sopenharmony_ci *		invalid arguments are passed.
54067c2aad20Sopenharmony_ci *
54077c2aad20Sopenharmony_ci * void *bpf_kptr_xchg(void *map_value, void *ptr)
54087c2aad20Sopenharmony_ci *	Description
54097c2aad20Sopenharmony_ci *		Exchange kptr at pointer *map_value* with *ptr*, and return the
54107c2aad20Sopenharmony_ci *		old value. *ptr* can be NULL, otherwise it must be a referenced
54117c2aad20Sopenharmony_ci *		pointer which will be released when this helper is called.
54127c2aad20Sopenharmony_ci *	Return
54137c2aad20Sopenharmony_ci *		The old value of kptr (which can be NULL). The returned pointer
54147c2aad20Sopenharmony_ci *		if not NULL, is a reference which must be released using its
54157c2aad20Sopenharmony_ci *		corresponding release function, or moved into a BPF map before
54167c2aad20Sopenharmony_ci *		program exit.
54177c2aad20Sopenharmony_ci *
54187c2aad20Sopenharmony_ci * void *bpf_map_lookup_percpu_elem(struct bpf_map *map, const void *key, u32 cpu)
54197c2aad20Sopenharmony_ci * 	Description
54207c2aad20Sopenharmony_ci * 		Perform a lookup in *percpu map* for an entry associated to
54217c2aad20Sopenharmony_ci * 		*key* on *cpu*.
54227c2aad20Sopenharmony_ci * 	Return
54237c2aad20Sopenharmony_ci * 		Map value associated to *key* on *cpu*, or **NULL** if no entry
54247c2aad20Sopenharmony_ci * 		was found or *cpu* is invalid.
54257c2aad20Sopenharmony_ci *
54267c2aad20Sopenharmony_ci * struct mptcp_sock *bpf_skc_to_mptcp_sock(void *sk)
54277c2aad20Sopenharmony_ci *	Description
54287c2aad20Sopenharmony_ci *		Dynamically cast a *sk* pointer to a *mptcp_sock* pointer.
54297c2aad20Sopenharmony_ci *	Return
54307c2aad20Sopenharmony_ci *		*sk* if casting is valid, or **NULL** otherwise.
54317c2aad20Sopenharmony_ci *
54327c2aad20Sopenharmony_ci * long bpf_dynptr_from_mem(void *data, u32 size, u64 flags, struct bpf_dynptr *ptr)
54337c2aad20Sopenharmony_ci *	Description
54347c2aad20Sopenharmony_ci *		Get a dynptr to local memory *data*.
54357c2aad20Sopenharmony_ci *
54367c2aad20Sopenharmony_ci *		*data* must be a ptr to a map value.
54377c2aad20Sopenharmony_ci *		The maximum *size* supported is DYNPTR_MAX_SIZE.
54387c2aad20Sopenharmony_ci *		*flags* is currently unused.
54397c2aad20Sopenharmony_ci *	Return
54407c2aad20Sopenharmony_ci *		0 on success, -E2BIG if the size exceeds DYNPTR_MAX_SIZE,
54417c2aad20Sopenharmony_ci *		-EINVAL if flags is not 0.
54427c2aad20Sopenharmony_ci *
54437c2aad20Sopenharmony_ci * long bpf_ringbuf_reserve_dynptr(void *ringbuf, u32 size, u64 flags, struct bpf_dynptr *ptr)
54447c2aad20Sopenharmony_ci *	Description
54457c2aad20Sopenharmony_ci *		Reserve *size* bytes of payload in a ring buffer *ringbuf*
54467c2aad20Sopenharmony_ci *		through the dynptr interface. *flags* must be 0.
54477c2aad20Sopenharmony_ci *
54487c2aad20Sopenharmony_ci *		Please note that a corresponding bpf_ringbuf_submit_dynptr or
54497c2aad20Sopenharmony_ci *		bpf_ringbuf_discard_dynptr must be called on *ptr*, even if the
54507c2aad20Sopenharmony_ci *		reservation fails. This is enforced by the verifier.
54517c2aad20Sopenharmony_ci *	Return
54527c2aad20Sopenharmony_ci *		0 on success, or a negative error in case of failure.
54537c2aad20Sopenharmony_ci *
54547c2aad20Sopenharmony_ci * void bpf_ringbuf_submit_dynptr(struct bpf_dynptr *ptr, u64 flags)
54557c2aad20Sopenharmony_ci *	Description
54567c2aad20Sopenharmony_ci *		Submit reserved ring buffer sample, pointed to by *data*,
54577c2aad20Sopenharmony_ci *		through the dynptr interface. This is a no-op if the dynptr is
54587c2aad20Sopenharmony_ci *		invalid/null.
54597c2aad20Sopenharmony_ci *
54607c2aad20Sopenharmony_ci *		For more information on *flags*, please see
54617c2aad20Sopenharmony_ci *		'bpf_ringbuf_submit'.
54627c2aad20Sopenharmony_ci *	Return
54637c2aad20Sopenharmony_ci *		Nothing. Always succeeds.
54647c2aad20Sopenharmony_ci *
54657c2aad20Sopenharmony_ci * void bpf_ringbuf_discard_dynptr(struct bpf_dynptr *ptr, u64 flags)
54667c2aad20Sopenharmony_ci *	Description
54677c2aad20Sopenharmony_ci *		Discard reserved ring buffer sample through the dynptr
54687c2aad20Sopenharmony_ci *		interface. This is a no-op if the dynptr is invalid/null.
54697c2aad20Sopenharmony_ci *
54707c2aad20Sopenharmony_ci *		For more information on *flags*, please see
54717c2aad20Sopenharmony_ci *		'bpf_ringbuf_discard'.
54727c2aad20Sopenharmony_ci *	Return
54737c2aad20Sopenharmony_ci *		Nothing. Always succeeds.
54747c2aad20Sopenharmony_ci *
54757c2aad20Sopenharmony_ci * long bpf_dynptr_read(void *dst, u32 len, const struct bpf_dynptr *src, u32 offset, u64 flags)
54767c2aad20Sopenharmony_ci *	Description
54777c2aad20Sopenharmony_ci *		Read *len* bytes from *src* into *dst*, starting from *offset*
54787c2aad20Sopenharmony_ci *		into *src*.
54797c2aad20Sopenharmony_ci *		*flags* is currently unused.
54807c2aad20Sopenharmony_ci *	Return
54817c2aad20Sopenharmony_ci *		0 on success, -E2BIG if *offset* + *len* exceeds the length
54827c2aad20Sopenharmony_ci *		of *src*'s data, -EINVAL if *src* is an invalid dynptr or if
54837c2aad20Sopenharmony_ci *		*flags* is not 0.
54847c2aad20Sopenharmony_ci *
54857c2aad20Sopenharmony_ci * long bpf_dynptr_write(const struct bpf_dynptr *dst, u32 offset, void *src, u32 len, u64 flags)
54867c2aad20Sopenharmony_ci *	Description
54877c2aad20Sopenharmony_ci *		Write *len* bytes from *src* into *dst*, starting from *offset*
54887c2aad20Sopenharmony_ci *		into *dst*.
54897c2aad20Sopenharmony_ci *
54907c2aad20Sopenharmony_ci *		*flags* must be 0 except for skb-type dynptrs.
54917c2aad20Sopenharmony_ci *
54927c2aad20Sopenharmony_ci *		For skb-type dynptrs:
54937c2aad20Sopenharmony_ci *		    *  All data slices of the dynptr are automatically
54947c2aad20Sopenharmony_ci *		       invalidated after **bpf_dynptr_write**\ (). This is
54957c2aad20Sopenharmony_ci *		       because writing may pull the skb and change the
54967c2aad20Sopenharmony_ci *		       underlying packet buffer.
54977c2aad20Sopenharmony_ci *
54987c2aad20Sopenharmony_ci *		    *  For *flags*, please see the flags accepted by
54997c2aad20Sopenharmony_ci *		       **bpf_skb_store_bytes**\ ().
55007c2aad20Sopenharmony_ci *	Return
55017c2aad20Sopenharmony_ci *		0 on success, -E2BIG if *offset* + *len* exceeds the length
55027c2aad20Sopenharmony_ci *		of *dst*'s data, -EINVAL if *dst* is an invalid dynptr or if *dst*
55037c2aad20Sopenharmony_ci *		is a read-only dynptr or if *flags* is not correct. For skb-type dynptrs,
55047c2aad20Sopenharmony_ci *		other errors correspond to errors returned by **bpf_skb_store_bytes**\ ().
55057c2aad20Sopenharmony_ci *
55067c2aad20Sopenharmony_ci * void *bpf_dynptr_data(const struct bpf_dynptr *ptr, u32 offset, u32 len)
55077c2aad20Sopenharmony_ci *	Description
55087c2aad20Sopenharmony_ci *		Get a pointer to the underlying dynptr data.
55097c2aad20Sopenharmony_ci *
55107c2aad20Sopenharmony_ci *		*len* must be a statically known value. The returned data slice
55117c2aad20Sopenharmony_ci *		is invalidated whenever the dynptr is invalidated.
55127c2aad20Sopenharmony_ci *
55137c2aad20Sopenharmony_ci *		skb and xdp type dynptrs may not use bpf_dynptr_data. They should
55147c2aad20Sopenharmony_ci *		instead use bpf_dynptr_slice and bpf_dynptr_slice_rdwr.
55157c2aad20Sopenharmony_ci *	Return
55167c2aad20Sopenharmony_ci *		Pointer to the underlying dynptr data, NULL if the dynptr is
55177c2aad20Sopenharmony_ci *		read-only, if the dynptr is invalid, or if the offset and length
55187c2aad20Sopenharmony_ci *		is out of bounds.
55197c2aad20Sopenharmony_ci *
55207c2aad20Sopenharmony_ci * s64 bpf_tcp_raw_gen_syncookie_ipv4(struct iphdr *iph, struct tcphdr *th, u32 th_len)
55217c2aad20Sopenharmony_ci *	Description
55227c2aad20Sopenharmony_ci *		Try to issue a SYN cookie for the packet with corresponding
55237c2aad20Sopenharmony_ci *		IPv4/TCP headers, *iph* and *th*, without depending on a
55247c2aad20Sopenharmony_ci *		listening socket.
55257c2aad20Sopenharmony_ci *
55267c2aad20Sopenharmony_ci *		*iph* points to the IPv4 header.
55277c2aad20Sopenharmony_ci *
55287c2aad20Sopenharmony_ci *		*th* points to the start of the TCP header, while *th_len*
55297c2aad20Sopenharmony_ci *		contains the length of the TCP header (at least
55307c2aad20Sopenharmony_ci *		**sizeof**\ (**struct tcphdr**)).
55317c2aad20Sopenharmony_ci *	Return
55327c2aad20Sopenharmony_ci *		On success, lower 32 bits hold the generated SYN cookie in
55337c2aad20Sopenharmony_ci *		followed by 16 bits which hold the MSS value for that cookie,
55347c2aad20Sopenharmony_ci *		and the top 16 bits are unused.
55357c2aad20Sopenharmony_ci *
55367c2aad20Sopenharmony_ci *		On failure, the returned value is one of the following:
55377c2aad20Sopenharmony_ci *
55387c2aad20Sopenharmony_ci *		**-EINVAL** if *th_len* is invalid.
55397c2aad20Sopenharmony_ci *
55407c2aad20Sopenharmony_ci * s64 bpf_tcp_raw_gen_syncookie_ipv6(struct ipv6hdr *iph, struct tcphdr *th, u32 th_len)
55417c2aad20Sopenharmony_ci *	Description
55427c2aad20Sopenharmony_ci *		Try to issue a SYN cookie for the packet with corresponding
55437c2aad20Sopenharmony_ci *		IPv6/TCP headers, *iph* and *th*, without depending on a
55447c2aad20Sopenharmony_ci *		listening socket.
55457c2aad20Sopenharmony_ci *
55467c2aad20Sopenharmony_ci *		*iph* points to the IPv6 header.
55477c2aad20Sopenharmony_ci *
55487c2aad20Sopenharmony_ci *		*th* points to the start of the TCP header, while *th_len*
55497c2aad20Sopenharmony_ci *		contains the length of the TCP header (at least
55507c2aad20Sopenharmony_ci *		**sizeof**\ (**struct tcphdr**)).
55517c2aad20Sopenharmony_ci *	Return
55527c2aad20Sopenharmony_ci *		On success, lower 32 bits hold the generated SYN cookie in
55537c2aad20Sopenharmony_ci *		followed by 16 bits which hold the MSS value for that cookie,
55547c2aad20Sopenharmony_ci *		and the top 16 bits are unused.
55557c2aad20Sopenharmony_ci *
55567c2aad20Sopenharmony_ci *		On failure, the returned value is one of the following:
55577c2aad20Sopenharmony_ci *
55587c2aad20Sopenharmony_ci *		**-EINVAL** if *th_len* is invalid.
55597c2aad20Sopenharmony_ci *
55607c2aad20Sopenharmony_ci *		**-EPROTONOSUPPORT** if CONFIG_IPV6 is not builtin.
55617c2aad20Sopenharmony_ci *
55627c2aad20Sopenharmony_ci * long bpf_tcp_raw_check_syncookie_ipv4(struct iphdr *iph, struct tcphdr *th)
55637c2aad20Sopenharmony_ci *	Description
55647c2aad20Sopenharmony_ci *		Check whether *iph* and *th* contain a valid SYN cookie ACK
55657c2aad20Sopenharmony_ci *		without depending on a listening socket.
55667c2aad20Sopenharmony_ci *
55677c2aad20Sopenharmony_ci *		*iph* points to the IPv4 header.
55687c2aad20Sopenharmony_ci *
55697c2aad20Sopenharmony_ci *		*th* points to the TCP header.
55707c2aad20Sopenharmony_ci *	Return
55717c2aad20Sopenharmony_ci *		0 if *iph* and *th* are a valid SYN cookie ACK.
55727c2aad20Sopenharmony_ci *
55737c2aad20Sopenharmony_ci *		On failure, the returned value is one of the following:
55747c2aad20Sopenharmony_ci *
55757c2aad20Sopenharmony_ci *		**-EACCES** if the SYN cookie is not valid.
55767c2aad20Sopenharmony_ci *
55777c2aad20Sopenharmony_ci * long bpf_tcp_raw_check_syncookie_ipv6(struct ipv6hdr *iph, struct tcphdr *th)
55787c2aad20Sopenharmony_ci *	Description
55797c2aad20Sopenharmony_ci *		Check whether *iph* and *th* contain a valid SYN cookie ACK
55807c2aad20Sopenharmony_ci *		without depending on a listening socket.
55817c2aad20Sopenharmony_ci *
55827c2aad20Sopenharmony_ci *		*iph* points to the IPv6 header.
55837c2aad20Sopenharmony_ci *
55847c2aad20Sopenharmony_ci *		*th* points to the TCP header.
55857c2aad20Sopenharmony_ci *	Return
55867c2aad20Sopenharmony_ci *		0 if *iph* and *th* are a valid SYN cookie ACK.
55877c2aad20Sopenharmony_ci *
55887c2aad20Sopenharmony_ci *		On failure, the returned value is one of the following:
55897c2aad20Sopenharmony_ci *
55907c2aad20Sopenharmony_ci *		**-EACCES** if the SYN cookie is not valid.
55917c2aad20Sopenharmony_ci *
55927c2aad20Sopenharmony_ci *		**-EPROTONOSUPPORT** if CONFIG_IPV6 is not builtin.
55937c2aad20Sopenharmony_ci *
55947c2aad20Sopenharmony_ci * u64 bpf_ktime_get_tai_ns(void)
55957c2aad20Sopenharmony_ci *	Description
55967c2aad20Sopenharmony_ci *		A nonsettable system-wide clock derived from wall-clock time but
55977c2aad20Sopenharmony_ci *		ignoring leap seconds.  This clock does not experience
55987c2aad20Sopenharmony_ci *		discontinuities and backwards jumps caused by NTP inserting leap
55997c2aad20Sopenharmony_ci *		seconds as CLOCK_REALTIME does.
56007c2aad20Sopenharmony_ci *
56017c2aad20Sopenharmony_ci *		See: **clock_gettime**\ (**CLOCK_TAI**)
56027c2aad20Sopenharmony_ci *	Return
56037c2aad20Sopenharmony_ci *		Current *ktime*.
56047c2aad20Sopenharmony_ci *
56057c2aad20Sopenharmony_ci * long bpf_user_ringbuf_drain(struct bpf_map *map, void *callback_fn, void *ctx, u64 flags)
56067c2aad20Sopenharmony_ci *	Description
56077c2aad20Sopenharmony_ci *		Drain samples from the specified user ring buffer, and invoke
56087c2aad20Sopenharmony_ci *		the provided callback for each such sample:
56097c2aad20Sopenharmony_ci *
56107c2aad20Sopenharmony_ci *		long (\*callback_fn)(const struct bpf_dynptr \*dynptr, void \*ctx);
56117c2aad20Sopenharmony_ci *
56127c2aad20Sopenharmony_ci *		If **callback_fn** returns 0, the helper will continue to try
56137c2aad20Sopenharmony_ci *		and drain the next sample, up to a maximum of
56147c2aad20Sopenharmony_ci *		BPF_MAX_USER_RINGBUF_SAMPLES samples. If the return value is 1,
56157c2aad20Sopenharmony_ci *		the helper will skip the rest of the samples and return. Other
56167c2aad20Sopenharmony_ci *		return values are not used now, and will be rejected by the
56177c2aad20Sopenharmony_ci *		verifier.
56187c2aad20Sopenharmony_ci *	Return
56197c2aad20Sopenharmony_ci *		The number of drained samples if no error was encountered while
56207c2aad20Sopenharmony_ci *		draining samples, or 0 if no samples were present in the ring
56217c2aad20Sopenharmony_ci *		buffer. If a user-space producer was epoll-waiting on this map,
56227c2aad20Sopenharmony_ci *		and at least one sample was drained, they will receive an event
56237c2aad20Sopenharmony_ci *		notification notifying them of available space in the ring
56247c2aad20Sopenharmony_ci *		buffer. If the BPF_RB_NO_WAKEUP flag is passed to this
56257c2aad20Sopenharmony_ci *		function, no wakeup notification will be sent. If the
56267c2aad20Sopenharmony_ci *		BPF_RB_FORCE_WAKEUP flag is passed, a wakeup notification will
56277c2aad20Sopenharmony_ci *		be sent even if no sample was drained.
56287c2aad20Sopenharmony_ci *
56297c2aad20Sopenharmony_ci *		On failure, the returned value is one of the following:
56307c2aad20Sopenharmony_ci *
56317c2aad20Sopenharmony_ci *		**-EBUSY** if the ring buffer is contended, and another calling
56327c2aad20Sopenharmony_ci *		context was concurrently draining the ring buffer.
56337c2aad20Sopenharmony_ci *
56347c2aad20Sopenharmony_ci *		**-EINVAL** if user-space is not properly tracking the ring
56357c2aad20Sopenharmony_ci *		buffer due to the producer position not being aligned to 8
56367c2aad20Sopenharmony_ci *		bytes, a sample not being aligned to 8 bytes, or the producer
56377c2aad20Sopenharmony_ci *		position not matching the advertised length of a sample.
56387c2aad20Sopenharmony_ci *
56397c2aad20Sopenharmony_ci *		**-E2BIG** if user-space has tried to publish a sample which is
56407c2aad20Sopenharmony_ci *		larger than the size of the ring buffer, or which cannot fit
56417c2aad20Sopenharmony_ci *		within a struct bpf_dynptr.
56427c2aad20Sopenharmony_ci *
56437c2aad20Sopenharmony_ci * void *bpf_cgrp_storage_get(struct bpf_map *map, struct cgroup *cgroup, void *value, u64 flags)
56447c2aad20Sopenharmony_ci *	Description
56457c2aad20Sopenharmony_ci *		Get a bpf_local_storage from the *cgroup*.
56467c2aad20Sopenharmony_ci *
56477c2aad20Sopenharmony_ci *		Logically, it could be thought of as getting the value from
56487c2aad20Sopenharmony_ci *		a *map* with *cgroup* as the **key**.  From this
56497c2aad20Sopenharmony_ci *		perspective,  the usage is not much different from
56507c2aad20Sopenharmony_ci *		**bpf_map_lookup_elem**\ (*map*, **&**\ *cgroup*) except this
56517c2aad20Sopenharmony_ci *		helper enforces the key must be a cgroup struct and the map must also
56527c2aad20Sopenharmony_ci *		be a **BPF_MAP_TYPE_CGRP_STORAGE**.
56537c2aad20Sopenharmony_ci *
56547c2aad20Sopenharmony_ci *		In reality, the local-storage value is embedded directly inside of the
56557c2aad20Sopenharmony_ci *		*cgroup* object itself, rather than being located in the
56567c2aad20Sopenharmony_ci *		**BPF_MAP_TYPE_CGRP_STORAGE** map. When the local-storage value is
56577c2aad20Sopenharmony_ci *		queried for some *map* on a *cgroup* object, the kernel will perform an
56587c2aad20Sopenharmony_ci *		O(n) iteration over all of the live local-storage values for that
56597c2aad20Sopenharmony_ci *		*cgroup* object until the local-storage value for the *map* is found.
56607c2aad20Sopenharmony_ci *
56617c2aad20Sopenharmony_ci *		An optional *flags* (**BPF_LOCAL_STORAGE_GET_F_CREATE**) can be
56627c2aad20Sopenharmony_ci *		used such that a new bpf_local_storage will be
56637c2aad20Sopenharmony_ci *		created if one does not exist.  *value* can be used
56647c2aad20Sopenharmony_ci *		together with **BPF_LOCAL_STORAGE_GET_F_CREATE** to specify
56657c2aad20Sopenharmony_ci *		the initial value of a bpf_local_storage.  If *value* is
56667c2aad20Sopenharmony_ci *		**NULL**, the new bpf_local_storage will be zero initialized.
56677c2aad20Sopenharmony_ci *	Return
56687c2aad20Sopenharmony_ci *		A bpf_local_storage pointer is returned on success.
56697c2aad20Sopenharmony_ci *
56707c2aad20Sopenharmony_ci *		**NULL** if not found or there was an error in adding
56717c2aad20Sopenharmony_ci *		a new bpf_local_storage.
56727c2aad20Sopenharmony_ci *
56737c2aad20Sopenharmony_ci * long bpf_cgrp_storage_delete(struct bpf_map *map, struct cgroup *cgroup)
56747c2aad20Sopenharmony_ci *	Description
56757c2aad20Sopenharmony_ci *		Delete a bpf_local_storage from a *cgroup*.
56767c2aad20Sopenharmony_ci *	Return
56777c2aad20Sopenharmony_ci *		0 on success.
56787c2aad20Sopenharmony_ci *
56797c2aad20Sopenharmony_ci *		**-ENOENT** if the bpf_local_storage cannot be found.
56807c2aad20Sopenharmony_ci */
56817c2aad20Sopenharmony_ci#define ___BPF_FUNC_MAPPER(FN, ctx...)			\
56827c2aad20Sopenharmony_ci	FN(unspec, 0, ##ctx)				\
56837c2aad20Sopenharmony_ci	FN(map_lookup_elem, 1, ##ctx)			\
56847c2aad20Sopenharmony_ci	FN(map_update_elem, 2, ##ctx)			\
56857c2aad20Sopenharmony_ci	FN(map_delete_elem, 3, ##ctx)			\
56867c2aad20Sopenharmony_ci	FN(probe_read, 4, ##ctx)			\
56877c2aad20Sopenharmony_ci	FN(ktime_get_ns, 5, ##ctx)			\
56887c2aad20Sopenharmony_ci	FN(trace_printk, 6, ##ctx)			\
56897c2aad20Sopenharmony_ci	FN(get_prandom_u32, 7, ##ctx)			\
56907c2aad20Sopenharmony_ci	FN(get_smp_processor_id, 8, ##ctx)		\
56917c2aad20Sopenharmony_ci	FN(skb_store_bytes, 9, ##ctx)			\
56927c2aad20Sopenharmony_ci	FN(l3_csum_replace, 10, ##ctx)			\
56937c2aad20Sopenharmony_ci	FN(l4_csum_replace, 11, ##ctx)			\
56947c2aad20Sopenharmony_ci	FN(tail_call, 12, ##ctx)			\
56957c2aad20Sopenharmony_ci	FN(clone_redirect, 13, ##ctx)			\
56967c2aad20Sopenharmony_ci	FN(get_current_pid_tgid, 14, ##ctx)		\
56977c2aad20Sopenharmony_ci	FN(get_current_uid_gid, 15, ##ctx)		\
56987c2aad20Sopenharmony_ci	FN(get_current_comm, 16, ##ctx)			\
56997c2aad20Sopenharmony_ci	FN(get_cgroup_classid, 17, ##ctx)		\
57007c2aad20Sopenharmony_ci	FN(skb_vlan_push, 18, ##ctx)			\
57017c2aad20Sopenharmony_ci	FN(skb_vlan_pop, 19, ##ctx)			\
57027c2aad20Sopenharmony_ci	FN(skb_get_tunnel_key, 20, ##ctx)		\
57037c2aad20Sopenharmony_ci	FN(skb_set_tunnel_key, 21, ##ctx)		\
57047c2aad20Sopenharmony_ci	FN(perf_event_read, 22, ##ctx)			\
57057c2aad20Sopenharmony_ci	FN(redirect, 23, ##ctx)				\
57067c2aad20Sopenharmony_ci	FN(get_route_realm, 24, ##ctx)			\
57077c2aad20Sopenharmony_ci	FN(perf_event_output, 25, ##ctx)		\
57087c2aad20Sopenharmony_ci	FN(skb_load_bytes, 26, ##ctx)			\
57097c2aad20Sopenharmony_ci	FN(get_stackid, 27, ##ctx)			\
57107c2aad20Sopenharmony_ci	FN(csum_diff, 28, ##ctx)			\
57117c2aad20Sopenharmony_ci	FN(skb_get_tunnel_opt, 29, ##ctx)		\
57127c2aad20Sopenharmony_ci	FN(skb_set_tunnel_opt, 30, ##ctx)		\
57137c2aad20Sopenharmony_ci	FN(skb_change_proto, 31, ##ctx)			\
57147c2aad20Sopenharmony_ci	FN(skb_change_type, 32, ##ctx)			\
57157c2aad20Sopenharmony_ci	FN(skb_under_cgroup, 33, ##ctx)			\
57167c2aad20Sopenharmony_ci	FN(get_hash_recalc, 34, ##ctx)			\
57177c2aad20Sopenharmony_ci	FN(get_current_task, 35, ##ctx)			\
57187c2aad20Sopenharmony_ci	FN(probe_write_user, 36, ##ctx)			\
57197c2aad20Sopenharmony_ci	FN(current_task_under_cgroup, 37, ##ctx)	\
57207c2aad20Sopenharmony_ci	FN(skb_change_tail, 38, ##ctx)			\
57217c2aad20Sopenharmony_ci	FN(skb_pull_data, 39, ##ctx)			\
57227c2aad20Sopenharmony_ci	FN(csum_update, 40, ##ctx)			\
57237c2aad20Sopenharmony_ci	FN(set_hash_invalid, 41, ##ctx)			\
57247c2aad20Sopenharmony_ci	FN(get_numa_node_id, 42, ##ctx)			\
57257c2aad20Sopenharmony_ci	FN(skb_change_head, 43, ##ctx)			\
57267c2aad20Sopenharmony_ci	FN(xdp_adjust_head, 44, ##ctx)			\
57277c2aad20Sopenharmony_ci	FN(probe_read_str, 45, ##ctx)			\
57287c2aad20Sopenharmony_ci	FN(get_socket_cookie, 46, ##ctx)		\
57297c2aad20Sopenharmony_ci	FN(get_socket_uid, 47, ##ctx)			\
57307c2aad20Sopenharmony_ci	FN(set_hash, 48, ##ctx)				\
57317c2aad20Sopenharmony_ci	FN(setsockopt, 49, ##ctx)			\
57327c2aad20Sopenharmony_ci	FN(skb_adjust_room, 50, ##ctx)			\
57337c2aad20Sopenharmony_ci	FN(redirect_map, 51, ##ctx)			\
57347c2aad20Sopenharmony_ci	FN(sk_redirect_map, 52, ##ctx)			\
57357c2aad20Sopenharmony_ci	FN(sock_map_update, 53, ##ctx)			\
57367c2aad20Sopenharmony_ci	FN(xdp_adjust_meta, 54, ##ctx)			\
57377c2aad20Sopenharmony_ci	FN(perf_event_read_value, 55, ##ctx)		\
57387c2aad20Sopenharmony_ci	FN(perf_prog_read_value, 56, ##ctx)		\
57397c2aad20Sopenharmony_ci	FN(getsockopt, 57, ##ctx)			\
57407c2aad20Sopenharmony_ci	FN(override_return, 58, ##ctx)			\
57417c2aad20Sopenharmony_ci	FN(sock_ops_cb_flags_set, 59, ##ctx)		\
57427c2aad20Sopenharmony_ci	FN(msg_redirect_map, 60, ##ctx)			\
57437c2aad20Sopenharmony_ci	FN(msg_apply_bytes, 61, ##ctx)			\
57447c2aad20Sopenharmony_ci	FN(msg_cork_bytes, 62, ##ctx)			\
57457c2aad20Sopenharmony_ci	FN(msg_pull_data, 63, ##ctx)			\
57467c2aad20Sopenharmony_ci	FN(bind, 64, ##ctx)				\
57477c2aad20Sopenharmony_ci	FN(xdp_adjust_tail, 65, ##ctx)			\
57487c2aad20Sopenharmony_ci	FN(skb_get_xfrm_state, 66, ##ctx)		\
57497c2aad20Sopenharmony_ci	FN(get_stack, 67, ##ctx)			\
57507c2aad20Sopenharmony_ci	FN(skb_load_bytes_relative, 68, ##ctx)		\
57517c2aad20Sopenharmony_ci	FN(fib_lookup, 69, ##ctx)			\
57527c2aad20Sopenharmony_ci	FN(sock_hash_update, 70, ##ctx)			\
57537c2aad20Sopenharmony_ci	FN(msg_redirect_hash, 71, ##ctx)		\
57547c2aad20Sopenharmony_ci	FN(sk_redirect_hash, 72, ##ctx)			\
57557c2aad20Sopenharmony_ci	FN(lwt_push_encap, 73, ##ctx)			\
57567c2aad20Sopenharmony_ci	FN(lwt_seg6_store_bytes, 74, ##ctx)		\
57577c2aad20Sopenharmony_ci	FN(lwt_seg6_adjust_srh, 75, ##ctx)		\
57587c2aad20Sopenharmony_ci	FN(lwt_seg6_action, 76, ##ctx)			\
57597c2aad20Sopenharmony_ci	FN(rc_repeat, 77, ##ctx)			\
57607c2aad20Sopenharmony_ci	FN(rc_keydown, 78, ##ctx)			\
57617c2aad20Sopenharmony_ci	FN(skb_cgroup_id, 79, ##ctx)			\
57627c2aad20Sopenharmony_ci	FN(get_current_cgroup_id, 80, ##ctx)		\
57637c2aad20Sopenharmony_ci	FN(get_local_storage, 81, ##ctx)		\
57647c2aad20Sopenharmony_ci	FN(sk_select_reuseport, 82, ##ctx)		\
57657c2aad20Sopenharmony_ci	FN(skb_ancestor_cgroup_id, 83, ##ctx)		\
57667c2aad20Sopenharmony_ci	FN(sk_lookup_tcp, 84, ##ctx)			\
57677c2aad20Sopenharmony_ci	FN(sk_lookup_udp, 85, ##ctx)			\
57687c2aad20Sopenharmony_ci	FN(sk_release, 86, ##ctx)			\
57697c2aad20Sopenharmony_ci	FN(map_push_elem, 87, ##ctx)			\
57707c2aad20Sopenharmony_ci	FN(map_pop_elem, 88, ##ctx)			\
57717c2aad20Sopenharmony_ci	FN(map_peek_elem, 89, ##ctx)			\
57727c2aad20Sopenharmony_ci	FN(msg_push_data, 90, ##ctx)			\
57737c2aad20Sopenharmony_ci	FN(msg_pop_data, 91, ##ctx)			\
57747c2aad20Sopenharmony_ci	FN(rc_pointer_rel, 92, ##ctx)			\
57757c2aad20Sopenharmony_ci	FN(spin_lock, 93, ##ctx)			\
57767c2aad20Sopenharmony_ci	FN(spin_unlock, 94, ##ctx)			\
57777c2aad20Sopenharmony_ci	FN(sk_fullsock, 95, ##ctx)			\
57787c2aad20Sopenharmony_ci	FN(tcp_sock, 96, ##ctx)				\
57797c2aad20Sopenharmony_ci	FN(skb_ecn_set_ce, 97, ##ctx)			\
57807c2aad20Sopenharmony_ci	FN(get_listener_sock, 98, ##ctx)		\
57817c2aad20Sopenharmony_ci	FN(skc_lookup_tcp, 99, ##ctx)			\
57827c2aad20Sopenharmony_ci	FN(tcp_check_syncookie, 100, ##ctx)		\
57837c2aad20Sopenharmony_ci	FN(sysctl_get_name, 101, ##ctx)			\
57847c2aad20Sopenharmony_ci	FN(sysctl_get_current_value, 102, ##ctx)	\
57857c2aad20Sopenharmony_ci	FN(sysctl_get_new_value, 103, ##ctx)		\
57867c2aad20Sopenharmony_ci	FN(sysctl_set_new_value, 104, ##ctx)		\
57877c2aad20Sopenharmony_ci	FN(strtol, 105, ##ctx)				\
57887c2aad20Sopenharmony_ci	FN(strtoul, 106, ##ctx)				\
57897c2aad20Sopenharmony_ci	FN(sk_storage_get, 107, ##ctx)			\
57907c2aad20Sopenharmony_ci	FN(sk_storage_delete, 108, ##ctx)		\
57917c2aad20Sopenharmony_ci	FN(send_signal, 109, ##ctx)			\
57927c2aad20Sopenharmony_ci	FN(tcp_gen_syncookie, 110, ##ctx)		\
57937c2aad20Sopenharmony_ci	FN(skb_output, 111, ##ctx)			\
57947c2aad20Sopenharmony_ci	FN(probe_read_user, 112, ##ctx)			\
57957c2aad20Sopenharmony_ci	FN(probe_read_kernel, 113, ##ctx)		\
57967c2aad20Sopenharmony_ci	FN(probe_read_user_str, 114, ##ctx)		\
57977c2aad20Sopenharmony_ci	FN(probe_read_kernel_str, 115, ##ctx)		\
57987c2aad20Sopenharmony_ci	FN(tcp_send_ack, 116, ##ctx)			\
57997c2aad20Sopenharmony_ci	FN(send_signal_thread, 117, ##ctx)		\
58007c2aad20Sopenharmony_ci	FN(jiffies64, 118, ##ctx)			\
58017c2aad20Sopenharmony_ci	FN(read_branch_records, 119, ##ctx)		\
58027c2aad20Sopenharmony_ci	FN(get_ns_current_pid_tgid, 120, ##ctx)		\
58037c2aad20Sopenharmony_ci	FN(xdp_output, 121, ##ctx)			\
58047c2aad20Sopenharmony_ci	FN(get_netns_cookie, 122, ##ctx)		\
58057c2aad20Sopenharmony_ci	FN(get_current_ancestor_cgroup_id, 123, ##ctx)	\
58067c2aad20Sopenharmony_ci	FN(sk_assign, 124, ##ctx)			\
58077c2aad20Sopenharmony_ci	FN(ktime_get_boot_ns, 125, ##ctx)		\
58087c2aad20Sopenharmony_ci	FN(seq_printf, 126, ##ctx)			\
58097c2aad20Sopenharmony_ci	FN(seq_write, 127, ##ctx)			\
58107c2aad20Sopenharmony_ci	FN(sk_cgroup_id, 128, ##ctx)			\
58117c2aad20Sopenharmony_ci	FN(sk_ancestor_cgroup_id, 129, ##ctx)		\
58127c2aad20Sopenharmony_ci	FN(ringbuf_output, 130, ##ctx)			\
58137c2aad20Sopenharmony_ci	FN(ringbuf_reserve, 131, ##ctx)			\
58147c2aad20Sopenharmony_ci	FN(ringbuf_submit, 132, ##ctx)			\
58157c2aad20Sopenharmony_ci	FN(ringbuf_discard, 133, ##ctx)			\
58167c2aad20Sopenharmony_ci	FN(ringbuf_query, 134, ##ctx)			\
58177c2aad20Sopenharmony_ci	FN(csum_level, 135, ##ctx)			\
58187c2aad20Sopenharmony_ci	FN(skc_to_tcp6_sock, 136, ##ctx)		\
58197c2aad20Sopenharmony_ci	FN(skc_to_tcp_sock, 137, ##ctx)			\
58207c2aad20Sopenharmony_ci	FN(skc_to_tcp_timewait_sock, 138, ##ctx)	\
58217c2aad20Sopenharmony_ci	FN(skc_to_tcp_request_sock, 139, ##ctx)		\
58227c2aad20Sopenharmony_ci	FN(skc_to_udp6_sock, 140, ##ctx)		\
58237c2aad20Sopenharmony_ci	FN(get_task_stack, 141, ##ctx)			\
58247c2aad20Sopenharmony_ci	FN(load_hdr_opt, 142, ##ctx)			\
58257c2aad20Sopenharmony_ci	FN(store_hdr_opt, 143, ##ctx)			\
58267c2aad20Sopenharmony_ci	FN(reserve_hdr_opt, 144, ##ctx)			\
58277c2aad20Sopenharmony_ci	FN(inode_storage_get, 145, ##ctx)		\
58287c2aad20Sopenharmony_ci	FN(inode_storage_delete, 146, ##ctx)		\
58297c2aad20Sopenharmony_ci	FN(d_path, 147, ##ctx)				\
58307c2aad20Sopenharmony_ci	FN(copy_from_user, 148, ##ctx)			\
58317c2aad20Sopenharmony_ci	FN(snprintf_btf, 149, ##ctx)			\
58327c2aad20Sopenharmony_ci	FN(seq_printf_btf, 150, ##ctx)			\
58337c2aad20Sopenharmony_ci	FN(skb_cgroup_classid, 151, ##ctx)		\
58347c2aad20Sopenharmony_ci	FN(redirect_neigh, 152, ##ctx)			\
58357c2aad20Sopenharmony_ci	FN(per_cpu_ptr, 153, ##ctx)			\
58367c2aad20Sopenharmony_ci	FN(this_cpu_ptr, 154, ##ctx)			\
58377c2aad20Sopenharmony_ci	FN(redirect_peer, 155, ##ctx)			\
58387c2aad20Sopenharmony_ci	FN(task_storage_get, 156, ##ctx)		\
58397c2aad20Sopenharmony_ci	FN(task_storage_delete, 157, ##ctx)		\
58407c2aad20Sopenharmony_ci	FN(get_current_task_btf, 158, ##ctx)		\
58417c2aad20Sopenharmony_ci	FN(bprm_opts_set, 159, ##ctx)			\
58427c2aad20Sopenharmony_ci	FN(ktime_get_coarse_ns, 160, ##ctx)		\
58437c2aad20Sopenharmony_ci	FN(ima_inode_hash, 161, ##ctx)			\
58447c2aad20Sopenharmony_ci	FN(sock_from_file, 162, ##ctx)			\
58457c2aad20Sopenharmony_ci	FN(check_mtu, 163, ##ctx)			\
58467c2aad20Sopenharmony_ci	FN(for_each_map_elem, 164, ##ctx)		\
58477c2aad20Sopenharmony_ci	FN(snprintf, 165, ##ctx)			\
58487c2aad20Sopenharmony_ci	FN(sys_bpf, 166, ##ctx)				\
58497c2aad20Sopenharmony_ci	FN(btf_find_by_name_kind, 167, ##ctx)		\
58507c2aad20Sopenharmony_ci	FN(sys_close, 168, ##ctx)			\
58517c2aad20Sopenharmony_ci	FN(timer_init, 169, ##ctx)			\
58527c2aad20Sopenharmony_ci	FN(timer_set_callback, 170, ##ctx)		\
58537c2aad20Sopenharmony_ci	FN(timer_start, 171, ##ctx)			\
58547c2aad20Sopenharmony_ci	FN(timer_cancel, 172, ##ctx)			\
58557c2aad20Sopenharmony_ci	FN(get_func_ip, 173, ##ctx)			\
58567c2aad20Sopenharmony_ci	FN(get_attach_cookie, 174, ##ctx)		\
58577c2aad20Sopenharmony_ci	FN(task_pt_regs, 175, ##ctx)			\
58587c2aad20Sopenharmony_ci	FN(get_branch_snapshot, 176, ##ctx)		\
58597c2aad20Sopenharmony_ci	FN(trace_vprintk, 177, ##ctx)			\
58607c2aad20Sopenharmony_ci	FN(skc_to_unix_sock, 178, ##ctx)		\
58617c2aad20Sopenharmony_ci	FN(kallsyms_lookup_name, 179, ##ctx)		\
58627c2aad20Sopenharmony_ci	FN(find_vma, 180, ##ctx)			\
58637c2aad20Sopenharmony_ci	FN(loop, 181, ##ctx)				\
58647c2aad20Sopenharmony_ci	FN(strncmp, 182, ##ctx)				\
58657c2aad20Sopenharmony_ci	FN(get_func_arg, 183, ##ctx)			\
58667c2aad20Sopenharmony_ci	FN(get_func_ret, 184, ##ctx)			\
58677c2aad20Sopenharmony_ci	FN(get_func_arg_cnt, 185, ##ctx)		\
58687c2aad20Sopenharmony_ci	FN(get_retval, 186, ##ctx)			\
58697c2aad20Sopenharmony_ci	FN(set_retval, 187, ##ctx)			\
58707c2aad20Sopenharmony_ci	FN(xdp_get_buff_len, 188, ##ctx)		\
58717c2aad20Sopenharmony_ci	FN(xdp_load_bytes, 189, ##ctx)			\
58727c2aad20Sopenharmony_ci	FN(xdp_store_bytes, 190, ##ctx)			\
58737c2aad20Sopenharmony_ci	FN(copy_from_user_task, 191, ##ctx)		\
58747c2aad20Sopenharmony_ci	FN(skb_set_tstamp, 192, ##ctx)			\
58757c2aad20Sopenharmony_ci	FN(ima_file_hash, 193, ##ctx)			\
58767c2aad20Sopenharmony_ci	FN(kptr_xchg, 194, ##ctx)			\
58777c2aad20Sopenharmony_ci	FN(map_lookup_percpu_elem, 195, ##ctx)		\
58787c2aad20Sopenharmony_ci	FN(skc_to_mptcp_sock, 196, ##ctx)		\
58797c2aad20Sopenharmony_ci	FN(dynptr_from_mem, 197, ##ctx)			\
58807c2aad20Sopenharmony_ci	FN(ringbuf_reserve_dynptr, 198, ##ctx)		\
58817c2aad20Sopenharmony_ci	FN(ringbuf_submit_dynptr, 199, ##ctx)		\
58827c2aad20Sopenharmony_ci	FN(ringbuf_discard_dynptr, 200, ##ctx)		\
58837c2aad20Sopenharmony_ci	FN(dynptr_read, 201, ##ctx)			\
58847c2aad20Sopenharmony_ci	FN(dynptr_write, 202, ##ctx)			\
58857c2aad20Sopenharmony_ci	FN(dynptr_data, 203, ##ctx)			\
58867c2aad20Sopenharmony_ci	FN(tcp_raw_gen_syncookie_ipv4, 204, ##ctx)	\
58877c2aad20Sopenharmony_ci	FN(tcp_raw_gen_syncookie_ipv6, 205, ##ctx)	\
58887c2aad20Sopenharmony_ci	FN(tcp_raw_check_syncookie_ipv4, 206, ##ctx)	\
58897c2aad20Sopenharmony_ci	FN(tcp_raw_check_syncookie_ipv6, 207, ##ctx)	\
58907c2aad20Sopenharmony_ci	FN(ktime_get_tai_ns, 208, ##ctx)		\
58917c2aad20Sopenharmony_ci	FN(user_ringbuf_drain, 209, ##ctx)		\
58927c2aad20Sopenharmony_ci	FN(cgrp_storage_get, 210, ##ctx)		\
58937c2aad20Sopenharmony_ci	FN(cgrp_storage_delete, 211, ##ctx)		\
58947c2aad20Sopenharmony_ci	/* */
58957c2aad20Sopenharmony_ci
58967c2aad20Sopenharmony_ci/* backwards-compatibility macros for users of __BPF_FUNC_MAPPER that don't
58977c2aad20Sopenharmony_ci * know or care about integer value that is now passed as second argument
58987c2aad20Sopenharmony_ci */
58997c2aad20Sopenharmony_ci#define __BPF_FUNC_MAPPER_APPLY(name, value, FN) FN(name),
59007c2aad20Sopenharmony_ci#define __BPF_FUNC_MAPPER(FN) ___BPF_FUNC_MAPPER(__BPF_FUNC_MAPPER_APPLY, FN)
59017c2aad20Sopenharmony_ci
59027c2aad20Sopenharmony_ci/* integer value in 'imm' field of BPF_CALL instruction selects which helper
59037c2aad20Sopenharmony_ci * function eBPF program intends to call
59047c2aad20Sopenharmony_ci */
59057c2aad20Sopenharmony_ci#define __BPF_ENUM_FN(x, y) BPF_FUNC_ ## x = y,
59067c2aad20Sopenharmony_cienum bpf_func_id {
59077c2aad20Sopenharmony_ci	___BPF_FUNC_MAPPER(__BPF_ENUM_FN)
59087c2aad20Sopenharmony_ci	__BPF_FUNC_MAX_ID,
59097c2aad20Sopenharmony_ci};
59107c2aad20Sopenharmony_ci#undef __BPF_ENUM_FN
59117c2aad20Sopenharmony_ci
59127c2aad20Sopenharmony_ci/* All flags used by eBPF helper functions, placed here. */
59137c2aad20Sopenharmony_ci
59147c2aad20Sopenharmony_ci/* BPF_FUNC_skb_store_bytes flags. */
59157c2aad20Sopenharmony_cienum {
59167c2aad20Sopenharmony_ci	BPF_F_RECOMPUTE_CSUM		= (1ULL << 0),
59177c2aad20Sopenharmony_ci	BPF_F_INVALIDATE_HASH		= (1ULL << 1),
59187c2aad20Sopenharmony_ci};
59197c2aad20Sopenharmony_ci
59207c2aad20Sopenharmony_ci/* BPF_FUNC_l3_csum_replace and BPF_FUNC_l4_csum_replace flags.
59217c2aad20Sopenharmony_ci * First 4 bits are for passing the header field size.
59227c2aad20Sopenharmony_ci */
59237c2aad20Sopenharmony_cienum {
59247c2aad20Sopenharmony_ci	BPF_F_HDR_FIELD_MASK		= 0xfULL,
59257c2aad20Sopenharmony_ci};
59267c2aad20Sopenharmony_ci
59277c2aad20Sopenharmony_ci/* BPF_FUNC_l4_csum_replace flags. */
59287c2aad20Sopenharmony_cienum {
59297c2aad20Sopenharmony_ci	BPF_F_PSEUDO_HDR		= (1ULL << 4),
59307c2aad20Sopenharmony_ci	BPF_F_MARK_MANGLED_0		= (1ULL << 5),
59317c2aad20Sopenharmony_ci	BPF_F_MARK_ENFORCE		= (1ULL << 6),
59327c2aad20Sopenharmony_ci};
59337c2aad20Sopenharmony_ci
59347c2aad20Sopenharmony_ci/* BPF_FUNC_clone_redirect and BPF_FUNC_redirect flags. */
59357c2aad20Sopenharmony_cienum {
59367c2aad20Sopenharmony_ci	BPF_F_INGRESS			= (1ULL << 0),
59377c2aad20Sopenharmony_ci};
59387c2aad20Sopenharmony_ci
59397c2aad20Sopenharmony_ci/* BPF_FUNC_skb_set_tunnel_key and BPF_FUNC_skb_get_tunnel_key flags. */
59407c2aad20Sopenharmony_cienum {
59417c2aad20Sopenharmony_ci	BPF_F_TUNINFO_IPV6		= (1ULL << 0),
59427c2aad20Sopenharmony_ci};
59437c2aad20Sopenharmony_ci
59447c2aad20Sopenharmony_ci/* flags for both BPF_FUNC_get_stackid and BPF_FUNC_get_stack. */
59457c2aad20Sopenharmony_cienum {
59467c2aad20Sopenharmony_ci	BPF_F_SKIP_FIELD_MASK		= 0xffULL,
59477c2aad20Sopenharmony_ci	BPF_F_USER_STACK		= (1ULL << 8),
59487c2aad20Sopenharmony_ci/* flags used by BPF_FUNC_get_stackid only. */
59497c2aad20Sopenharmony_ci	BPF_F_FAST_STACK_CMP		= (1ULL << 9),
59507c2aad20Sopenharmony_ci	BPF_F_REUSE_STACKID		= (1ULL << 10),
59517c2aad20Sopenharmony_ci/* flags used by BPF_FUNC_get_stack only. */
59527c2aad20Sopenharmony_ci	BPF_F_USER_BUILD_ID		= (1ULL << 11),
59537c2aad20Sopenharmony_ci};
59547c2aad20Sopenharmony_ci
59557c2aad20Sopenharmony_ci/* BPF_FUNC_skb_set_tunnel_key flags. */
59567c2aad20Sopenharmony_cienum {
59577c2aad20Sopenharmony_ci	BPF_F_ZERO_CSUM_TX		= (1ULL << 1),
59587c2aad20Sopenharmony_ci	BPF_F_DONT_FRAGMENT		= (1ULL << 2),
59597c2aad20Sopenharmony_ci	BPF_F_SEQ_NUMBER		= (1ULL << 3),
59607c2aad20Sopenharmony_ci	BPF_F_NO_TUNNEL_KEY		= (1ULL << 4),
59617c2aad20Sopenharmony_ci};
59627c2aad20Sopenharmony_ci
59637c2aad20Sopenharmony_ci/* BPF_FUNC_skb_get_tunnel_key flags. */
59647c2aad20Sopenharmony_cienum {
59657c2aad20Sopenharmony_ci	BPF_F_TUNINFO_FLAGS		= (1ULL << 4),
59667c2aad20Sopenharmony_ci};
59677c2aad20Sopenharmony_ci
59687c2aad20Sopenharmony_ci/* BPF_FUNC_perf_event_output, BPF_FUNC_perf_event_read and
59697c2aad20Sopenharmony_ci * BPF_FUNC_perf_event_read_value flags.
59707c2aad20Sopenharmony_ci */
59717c2aad20Sopenharmony_cienum {
59727c2aad20Sopenharmony_ci	BPF_F_INDEX_MASK		= 0xffffffffULL,
59737c2aad20Sopenharmony_ci	BPF_F_CURRENT_CPU		= BPF_F_INDEX_MASK,
59747c2aad20Sopenharmony_ci/* BPF_FUNC_perf_event_output for sk_buff input context. */
59757c2aad20Sopenharmony_ci	BPF_F_CTXLEN_MASK		= (0xfffffULL << 32),
59767c2aad20Sopenharmony_ci};
59777c2aad20Sopenharmony_ci
59787c2aad20Sopenharmony_ci/* Current network namespace */
59797c2aad20Sopenharmony_cienum {
59807c2aad20Sopenharmony_ci	BPF_F_CURRENT_NETNS		= (-1L),
59817c2aad20Sopenharmony_ci};
59827c2aad20Sopenharmony_ci
59837c2aad20Sopenharmony_ci/* BPF_FUNC_csum_level level values. */
59847c2aad20Sopenharmony_cienum {
59857c2aad20Sopenharmony_ci	BPF_CSUM_LEVEL_QUERY,
59867c2aad20Sopenharmony_ci	BPF_CSUM_LEVEL_INC,
59877c2aad20Sopenharmony_ci	BPF_CSUM_LEVEL_DEC,
59887c2aad20Sopenharmony_ci	BPF_CSUM_LEVEL_RESET,
59897c2aad20Sopenharmony_ci};
59907c2aad20Sopenharmony_ci
59917c2aad20Sopenharmony_ci/* BPF_FUNC_skb_adjust_room flags. */
59927c2aad20Sopenharmony_cienum {
59937c2aad20Sopenharmony_ci	BPF_F_ADJ_ROOM_FIXED_GSO	= (1ULL << 0),
59947c2aad20Sopenharmony_ci	BPF_F_ADJ_ROOM_ENCAP_L3_IPV4	= (1ULL << 1),
59957c2aad20Sopenharmony_ci	BPF_F_ADJ_ROOM_ENCAP_L3_IPV6	= (1ULL << 2),
59967c2aad20Sopenharmony_ci	BPF_F_ADJ_ROOM_ENCAP_L4_GRE	= (1ULL << 3),
59977c2aad20Sopenharmony_ci	BPF_F_ADJ_ROOM_ENCAP_L4_UDP	= (1ULL << 4),
59987c2aad20Sopenharmony_ci	BPF_F_ADJ_ROOM_NO_CSUM_RESET	= (1ULL << 5),
59997c2aad20Sopenharmony_ci	BPF_F_ADJ_ROOM_ENCAP_L2_ETH	= (1ULL << 6),
60007c2aad20Sopenharmony_ci	BPF_F_ADJ_ROOM_DECAP_L3_IPV4	= (1ULL << 7),
60017c2aad20Sopenharmony_ci	BPF_F_ADJ_ROOM_DECAP_L3_IPV6	= (1ULL << 8),
60027c2aad20Sopenharmony_ci};
60037c2aad20Sopenharmony_ci
60047c2aad20Sopenharmony_cienum {
60057c2aad20Sopenharmony_ci	BPF_ADJ_ROOM_ENCAP_L2_MASK	= 0xff,
60067c2aad20Sopenharmony_ci	BPF_ADJ_ROOM_ENCAP_L2_SHIFT	= 56,
60077c2aad20Sopenharmony_ci};
60087c2aad20Sopenharmony_ci
60097c2aad20Sopenharmony_ci#define BPF_F_ADJ_ROOM_ENCAP_L2(len)	(((__u64)len & \
60107c2aad20Sopenharmony_ci					  BPF_ADJ_ROOM_ENCAP_L2_MASK) \
60117c2aad20Sopenharmony_ci					 << BPF_ADJ_ROOM_ENCAP_L2_SHIFT)
60127c2aad20Sopenharmony_ci
60137c2aad20Sopenharmony_ci/* BPF_FUNC_sysctl_get_name flags. */
60147c2aad20Sopenharmony_cienum {
60157c2aad20Sopenharmony_ci	BPF_F_SYSCTL_BASE_NAME		= (1ULL << 0),
60167c2aad20Sopenharmony_ci};
60177c2aad20Sopenharmony_ci
60187c2aad20Sopenharmony_ci/* BPF_FUNC_<kernel_obj>_storage_get flags */
60197c2aad20Sopenharmony_cienum {
60207c2aad20Sopenharmony_ci	BPF_LOCAL_STORAGE_GET_F_CREATE	= (1ULL << 0),
60217c2aad20Sopenharmony_ci	/* BPF_SK_STORAGE_GET_F_CREATE is only kept for backward compatibility
60227c2aad20Sopenharmony_ci	 * and BPF_LOCAL_STORAGE_GET_F_CREATE must be used instead.
60237c2aad20Sopenharmony_ci	 */
60247c2aad20Sopenharmony_ci	BPF_SK_STORAGE_GET_F_CREATE  = BPF_LOCAL_STORAGE_GET_F_CREATE,
60257c2aad20Sopenharmony_ci};
60267c2aad20Sopenharmony_ci
60277c2aad20Sopenharmony_ci/* BPF_FUNC_read_branch_records flags. */
60287c2aad20Sopenharmony_cienum {
60297c2aad20Sopenharmony_ci	BPF_F_GET_BRANCH_RECORDS_SIZE	= (1ULL << 0),
60307c2aad20Sopenharmony_ci};
60317c2aad20Sopenharmony_ci
60327c2aad20Sopenharmony_ci/* BPF_FUNC_bpf_ringbuf_commit, BPF_FUNC_bpf_ringbuf_discard, and
60337c2aad20Sopenharmony_ci * BPF_FUNC_bpf_ringbuf_output flags.
60347c2aad20Sopenharmony_ci */
60357c2aad20Sopenharmony_cienum {
60367c2aad20Sopenharmony_ci	BPF_RB_NO_WAKEUP		= (1ULL << 0),
60377c2aad20Sopenharmony_ci	BPF_RB_FORCE_WAKEUP		= (1ULL << 1),
60387c2aad20Sopenharmony_ci};
60397c2aad20Sopenharmony_ci
60407c2aad20Sopenharmony_ci/* BPF_FUNC_bpf_ringbuf_query flags */
60417c2aad20Sopenharmony_cienum {
60427c2aad20Sopenharmony_ci	BPF_RB_AVAIL_DATA = 0,
60437c2aad20Sopenharmony_ci	BPF_RB_RING_SIZE = 1,
60447c2aad20Sopenharmony_ci	BPF_RB_CONS_POS = 2,
60457c2aad20Sopenharmony_ci	BPF_RB_PROD_POS = 3,
60467c2aad20Sopenharmony_ci};
60477c2aad20Sopenharmony_ci
60487c2aad20Sopenharmony_ci/* BPF ring buffer constants */
60497c2aad20Sopenharmony_cienum {
60507c2aad20Sopenharmony_ci	BPF_RINGBUF_BUSY_BIT		= (1U << 31),
60517c2aad20Sopenharmony_ci	BPF_RINGBUF_DISCARD_BIT		= (1U << 30),
60527c2aad20Sopenharmony_ci	BPF_RINGBUF_HDR_SZ		= 8,
60537c2aad20Sopenharmony_ci};
60547c2aad20Sopenharmony_ci
60557c2aad20Sopenharmony_ci/* BPF_FUNC_sk_assign flags in bpf_sk_lookup context. */
60567c2aad20Sopenharmony_cienum {
60577c2aad20Sopenharmony_ci	BPF_SK_LOOKUP_F_REPLACE		= (1ULL << 0),
60587c2aad20Sopenharmony_ci	BPF_SK_LOOKUP_F_NO_REUSEPORT	= (1ULL << 1),
60597c2aad20Sopenharmony_ci};
60607c2aad20Sopenharmony_ci
60617c2aad20Sopenharmony_ci/* Mode for BPF_FUNC_skb_adjust_room helper. */
60627c2aad20Sopenharmony_cienum bpf_adj_room_mode {
60637c2aad20Sopenharmony_ci	BPF_ADJ_ROOM_NET,
60647c2aad20Sopenharmony_ci	BPF_ADJ_ROOM_MAC,
60657c2aad20Sopenharmony_ci};
60667c2aad20Sopenharmony_ci
60677c2aad20Sopenharmony_ci/* Mode for BPF_FUNC_skb_load_bytes_relative helper. */
60687c2aad20Sopenharmony_cienum bpf_hdr_start_off {
60697c2aad20Sopenharmony_ci	BPF_HDR_START_MAC,
60707c2aad20Sopenharmony_ci	BPF_HDR_START_NET,
60717c2aad20Sopenharmony_ci};
60727c2aad20Sopenharmony_ci
60737c2aad20Sopenharmony_ci/* Encapsulation type for BPF_FUNC_lwt_push_encap helper. */
60747c2aad20Sopenharmony_cienum bpf_lwt_encap_mode {
60757c2aad20Sopenharmony_ci	BPF_LWT_ENCAP_SEG6,
60767c2aad20Sopenharmony_ci	BPF_LWT_ENCAP_SEG6_INLINE,
60777c2aad20Sopenharmony_ci	BPF_LWT_ENCAP_IP,
60787c2aad20Sopenharmony_ci};
60797c2aad20Sopenharmony_ci
60807c2aad20Sopenharmony_ci/* Flags for bpf_bprm_opts_set helper */
60817c2aad20Sopenharmony_cienum {
60827c2aad20Sopenharmony_ci	BPF_F_BPRM_SECUREEXEC	= (1ULL << 0),
60837c2aad20Sopenharmony_ci};
60847c2aad20Sopenharmony_ci
60857c2aad20Sopenharmony_ci/* Flags for bpf_redirect_map helper */
60867c2aad20Sopenharmony_cienum {
60877c2aad20Sopenharmony_ci	BPF_F_BROADCAST		= (1ULL << 3),
60887c2aad20Sopenharmony_ci	BPF_F_EXCLUDE_INGRESS	= (1ULL << 4),
60897c2aad20Sopenharmony_ci};
60907c2aad20Sopenharmony_ci
60917c2aad20Sopenharmony_ci#define __bpf_md_ptr(type, name)	\
60927c2aad20Sopenharmony_ciunion {					\
60937c2aad20Sopenharmony_ci	type name;			\
60947c2aad20Sopenharmony_ci	__u64 :64;			\
60957c2aad20Sopenharmony_ci} __attribute__((aligned(8)))
60967c2aad20Sopenharmony_ci
60977c2aad20Sopenharmony_cienum {
60987c2aad20Sopenharmony_ci	BPF_SKB_TSTAMP_UNSPEC,
60997c2aad20Sopenharmony_ci	BPF_SKB_TSTAMP_DELIVERY_MONO,	/* tstamp has mono delivery time */
61007c2aad20Sopenharmony_ci	/* For any BPF_SKB_TSTAMP_* that the bpf prog cannot handle,
61017c2aad20Sopenharmony_ci	 * the bpf prog should handle it like BPF_SKB_TSTAMP_UNSPEC
61027c2aad20Sopenharmony_ci	 * and try to deduce it by ingress, egress or skb->sk->sk_clockid.
61037c2aad20Sopenharmony_ci	 */
61047c2aad20Sopenharmony_ci};
61057c2aad20Sopenharmony_ci
61067c2aad20Sopenharmony_ci/* user accessible mirror of in-kernel sk_buff.
61077c2aad20Sopenharmony_ci * new fields can only be added to the end of this structure
61087c2aad20Sopenharmony_ci */
61097c2aad20Sopenharmony_cistruct __sk_buff {
61107c2aad20Sopenharmony_ci	__u32 len;
61117c2aad20Sopenharmony_ci	__u32 pkt_type;
61127c2aad20Sopenharmony_ci	__u32 mark;
61137c2aad20Sopenharmony_ci	__u32 queue_mapping;
61147c2aad20Sopenharmony_ci	__u32 protocol;
61157c2aad20Sopenharmony_ci	__u32 vlan_present;
61167c2aad20Sopenharmony_ci	__u32 vlan_tci;
61177c2aad20Sopenharmony_ci	__u32 vlan_proto;
61187c2aad20Sopenharmony_ci	__u32 priority;
61197c2aad20Sopenharmony_ci	__u32 ingress_ifindex;
61207c2aad20Sopenharmony_ci	__u32 ifindex;
61217c2aad20Sopenharmony_ci	__u32 tc_index;
61227c2aad20Sopenharmony_ci	__u32 cb[5];
61237c2aad20Sopenharmony_ci	__u32 hash;
61247c2aad20Sopenharmony_ci	__u32 tc_classid;
61257c2aad20Sopenharmony_ci	__u32 data;
61267c2aad20Sopenharmony_ci	__u32 data_end;
61277c2aad20Sopenharmony_ci	__u32 napi_id;
61287c2aad20Sopenharmony_ci
61297c2aad20Sopenharmony_ci	/* Accessed by BPF_PROG_TYPE_sk_skb types from here to ... */
61307c2aad20Sopenharmony_ci	__u32 family;
61317c2aad20Sopenharmony_ci	__u32 remote_ip4;	/* Stored in network byte order */
61327c2aad20Sopenharmony_ci	__u32 local_ip4;	/* Stored in network byte order */
61337c2aad20Sopenharmony_ci	__u32 remote_ip6[4];	/* Stored in network byte order */
61347c2aad20Sopenharmony_ci	__u32 local_ip6[4];	/* Stored in network byte order */
61357c2aad20Sopenharmony_ci	__u32 remote_port;	/* Stored in network byte order */
61367c2aad20Sopenharmony_ci	__u32 local_port;	/* stored in host byte order */
61377c2aad20Sopenharmony_ci	/* ... here. */
61387c2aad20Sopenharmony_ci
61397c2aad20Sopenharmony_ci	__u32 data_meta;
61407c2aad20Sopenharmony_ci	__bpf_md_ptr(struct bpf_flow_keys *, flow_keys);
61417c2aad20Sopenharmony_ci	__u64 tstamp;
61427c2aad20Sopenharmony_ci	__u32 wire_len;
61437c2aad20Sopenharmony_ci	__u32 gso_segs;
61447c2aad20Sopenharmony_ci	__bpf_md_ptr(struct bpf_sock *, sk);
61457c2aad20Sopenharmony_ci	__u32 gso_size;
61467c2aad20Sopenharmony_ci	__u8  tstamp_type;
61477c2aad20Sopenharmony_ci	__u32 :24;		/* Padding, future use. */
61487c2aad20Sopenharmony_ci	__u64 hwtstamp;
61497c2aad20Sopenharmony_ci};
61507c2aad20Sopenharmony_ci
61517c2aad20Sopenharmony_cistruct bpf_tunnel_key {
61527c2aad20Sopenharmony_ci	__u32 tunnel_id;
61537c2aad20Sopenharmony_ci	union {
61547c2aad20Sopenharmony_ci		__u32 remote_ipv4;
61557c2aad20Sopenharmony_ci		__u32 remote_ipv6[4];
61567c2aad20Sopenharmony_ci	};
61577c2aad20Sopenharmony_ci	__u8 tunnel_tos;
61587c2aad20Sopenharmony_ci	__u8 tunnel_ttl;
61597c2aad20Sopenharmony_ci	union {
61607c2aad20Sopenharmony_ci		__u16 tunnel_ext;	/* compat */
61617c2aad20Sopenharmony_ci		__be16 tunnel_flags;
61627c2aad20Sopenharmony_ci	};
61637c2aad20Sopenharmony_ci	__u32 tunnel_label;
61647c2aad20Sopenharmony_ci	union {
61657c2aad20Sopenharmony_ci		__u32 local_ipv4;
61667c2aad20Sopenharmony_ci		__u32 local_ipv6[4];
61677c2aad20Sopenharmony_ci	};
61687c2aad20Sopenharmony_ci};
61697c2aad20Sopenharmony_ci
61707c2aad20Sopenharmony_ci/* user accessible mirror of in-kernel xfrm_state.
61717c2aad20Sopenharmony_ci * new fields can only be added to the end of this structure
61727c2aad20Sopenharmony_ci */
61737c2aad20Sopenharmony_cistruct bpf_xfrm_state {
61747c2aad20Sopenharmony_ci	__u32 reqid;
61757c2aad20Sopenharmony_ci	__u32 spi;	/* Stored in network byte order */
61767c2aad20Sopenharmony_ci	__u16 family;
61777c2aad20Sopenharmony_ci	__u16 ext;	/* Padding, future use. */
61787c2aad20Sopenharmony_ci	union {
61797c2aad20Sopenharmony_ci		__u32 remote_ipv4;	/* Stored in network byte order */
61807c2aad20Sopenharmony_ci		__u32 remote_ipv6[4];	/* Stored in network byte order */
61817c2aad20Sopenharmony_ci	};
61827c2aad20Sopenharmony_ci};
61837c2aad20Sopenharmony_ci
61847c2aad20Sopenharmony_ci/* Generic BPF return codes which all BPF program types may support.
61857c2aad20Sopenharmony_ci * The values are binary compatible with their TC_ACT_* counter-part to
61867c2aad20Sopenharmony_ci * provide backwards compatibility with existing SCHED_CLS and SCHED_ACT
61877c2aad20Sopenharmony_ci * programs.
61887c2aad20Sopenharmony_ci *
61897c2aad20Sopenharmony_ci * XDP is handled seprately, see XDP_*.
61907c2aad20Sopenharmony_ci */
61917c2aad20Sopenharmony_cienum bpf_ret_code {
61927c2aad20Sopenharmony_ci	BPF_OK = 0,
61937c2aad20Sopenharmony_ci	/* 1 reserved */
61947c2aad20Sopenharmony_ci	BPF_DROP = 2,
61957c2aad20Sopenharmony_ci	/* 3-6 reserved */
61967c2aad20Sopenharmony_ci	BPF_REDIRECT = 7,
61977c2aad20Sopenharmony_ci	/* >127 are reserved for prog type specific return codes.
61987c2aad20Sopenharmony_ci	 *
61997c2aad20Sopenharmony_ci	 * BPF_LWT_REROUTE: used by BPF_PROG_TYPE_LWT_IN and
62007c2aad20Sopenharmony_ci	 *    BPF_PROG_TYPE_LWT_XMIT to indicate that skb had been
62017c2aad20Sopenharmony_ci	 *    changed and should be routed based on its new L3 header.
62027c2aad20Sopenharmony_ci	 *    (This is an L3 redirect, as opposed to L2 redirect
62037c2aad20Sopenharmony_ci	 *    represented by BPF_REDIRECT above).
62047c2aad20Sopenharmony_ci	 */
62057c2aad20Sopenharmony_ci	BPF_LWT_REROUTE = 128,
62067c2aad20Sopenharmony_ci	/* BPF_FLOW_DISSECTOR_CONTINUE: used by BPF_PROG_TYPE_FLOW_DISSECTOR
62077c2aad20Sopenharmony_ci	 *   to indicate that no custom dissection was performed, and
62087c2aad20Sopenharmony_ci	 *   fallback to standard dissector is requested.
62097c2aad20Sopenharmony_ci	 */
62107c2aad20Sopenharmony_ci	BPF_FLOW_DISSECTOR_CONTINUE = 129,
62117c2aad20Sopenharmony_ci};
62127c2aad20Sopenharmony_ci
62137c2aad20Sopenharmony_cistruct bpf_sock {
62147c2aad20Sopenharmony_ci	__u32 bound_dev_if;
62157c2aad20Sopenharmony_ci	__u32 family;
62167c2aad20Sopenharmony_ci	__u32 type;
62177c2aad20Sopenharmony_ci	__u32 protocol;
62187c2aad20Sopenharmony_ci	__u32 mark;
62197c2aad20Sopenharmony_ci	__u32 priority;
62207c2aad20Sopenharmony_ci	/* IP address also allows 1 and 2 bytes access */
62217c2aad20Sopenharmony_ci	__u32 src_ip4;
62227c2aad20Sopenharmony_ci	__u32 src_ip6[4];
62237c2aad20Sopenharmony_ci	__u32 src_port;		/* host byte order */
62247c2aad20Sopenharmony_ci	__be16 dst_port;	/* network byte order */
62257c2aad20Sopenharmony_ci	__u16 :16;		/* zero padding */
62267c2aad20Sopenharmony_ci	__u32 dst_ip4;
62277c2aad20Sopenharmony_ci	__u32 dst_ip6[4];
62287c2aad20Sopenharmony_ci	__u32 state;
62297c2aad20Sopenharmony_ci	__s32 rx_queue_mapping;
62307c2aad20Sopenharmony_ci};
62317c2aad20Sopenharmony_ci
62327c2aad20Sopenharmony_cistruct bpf_tcp_sock {
62337c2aad20Sopenharmony_ci	__u32 snd_cwnd;		/* Sending congestion window		*/
62347c2aad20Sopenharmony_ci	__u32 srtt_us;		/* smoothed round trip time << 3 in usecs */
62357c2aad20Sopenharmony_ci	__u32 rtt_min;
62367c2aad20Sopenharmony_ci	__u32 snd_ssthresh;	/* Slow start size threshold		*/
62377c2aad20Sopenharmony_ci	__u32 rcv_nxt;		/* What we want to receive next		*/
62387c2aad20Sopenharmony_ci	__u32 snd_nxt;		/* Next sequence we send		*/
62397c2aad20Sopenharmony_ci	__u32 snd_una;		/* First byte we want an ack for	*/
62407c2aad20Sopenharmony_ci	__u32 mss_cache;	/* Cached effective mss, not including SACKS */
62417c2aad20Sopenharmony_ci	__u32 ecn_flags;	/* ECN status bits.			*/
62427c2aad20Sopenharmony_ci	__u32 rate_delivered;	/* saved rate sample: packets delivered */
62437c2aad20Sopenharmony_ci	__u32 rate_interval_us;	/* saved rate sample: time elapsed */
62447c2aad20Sopenharmony_ci	__u32 packets_out;	/* Packets which are "in flight"	*/
62457c2aad20Sopenharmony_ci	__u32 retrans_out;	/* Retransmitted packets out		*/
62467c2aad20Sopenharmony_ci	__u32 total_retrans;	/* Total retransmits for entire connection */
62477c2aad20Sopenharmony_ci	__u32 segs_in;		/* RFC4898 tcpEStatsPerfSegsIn
62487c2aad20Sopenharmony_ci				 * total number of segments in.
62497c2aad20Sopenharmony_ci				 */
62507c2aad20Sopenharmony_ci	__u32 data_segs_in;	/* RFC4898 tcpEStatsPerfDataSegsIn
62517c2aad20Sopenharmony_ci				 * total number of data segments in.
62527c2aad20Sopenharmony_ci				 */
62537c2aad20Sopenharmony_ci	__u32 segs_out;		/* RFC4898 tcpEStatsPerfSegsOut
62547c2aad20Sopenharmony_ci				 * The total number of segments sent.
62557c2aad20Sopenharmony_ci				 */
62567c2aad20Sopenharmony_ci	__u32 data_segs_out;	/* RFC4898 tcpEStatsPerfDataSegsOut
62577c2aad20Sopenharmony_ci				 * total number of data segments sent.
62587c2aad20Sopenharmony_ci				 */
62597c2aad20Sopenharmony_ci	__u32 lost_out;		/* Lost packets			*/
62607c2aad20Sopenharmony_ci	__u32 sacked_out;	/* SACK'd packets			*/
62617c2aad20Sopenharmony_ci	__u64 bytes_received;	/* RFC4898 tcpEStatsAppHCThruOctetsReceived
62627c2aad20Sopenharmony_ci				 * sum(delta(rcv_nxt)), or how many bytes
62637c2aad20Sopenharmony_ci				 * were acked.
62647c2aad20Sopenharmony_ci				 */
62657c2aad20Sopenharmony_ci	__u64 bytes_acked;	/* RFC4898 tcpEStatsAppHCThruOctetsAcked
62667c2aad20Sopenharmony_ci				 * sum(delta(snd_una)), or how many bytes
62677c2aad20Sopenharmony_ci				 * were acked.
62687c2aad20Sopenharmony_ci				 */
62697c2aad20Sopenharmony_ci	__u32 dsack_dups;	/* RFC4898 tcpEStatsStackDSACKDups
62707c2aad20Sopenharmony_ci				 * total number of DSACK blocks received
62717c2aad20Sopenharmony_ci				 */
62727c2aad20Sopenharmony_ci	__u32 delivered;	/* Total data packets delivered incl. rexmits */
62737c2aad20Sopenharmony_ci	__u32 delivered_ce;	/* Like the above but only ECE marked packets */
62747c2aad20Sopenharmony_ci	__u32 icsk_retransmits;	/* Number of unrecovered [RTO] timeouts */
62757c2aad20Sopenharmony_ci};
62767c2aad20Sopenharmony_ci
62777c2aad20Sopenharmony_cistruct bpf_sock_tuple {
62787c2aad20Sopenharmony_ci	union {
62797c2aad20Sopenharmony_ci		struct {
62807c2aad20Sopenharmony_ci			__be32 saddr;
62817c2aad20Sopenharmony_ci			__be32 daddr;
62827c2aad20Sopenharmony_ci			__be16 sport;
62837c2aad20Sopenharmony_ci			__be16 dport;
62847c2aad20Sopenharmony_ci		} ipv4;
62857c2aad20Sopenharmony_ci		struct {
62867c2aad20Sopenharmony_ci			__be32 saddr[4];
62877c2aad20Sopenharmony_ci			__be32 daddr[4];
62887c2aad20Sopenharmony_ci			__be16 sport;
62897c2aad20Sopenharmony_ci			__be16 dport;
62907c2aad20Sopenharmony_ci		} ipv6;
62917c2aad20Sopenharmony_ci	};
62927c2aad20Sopenharmony_ci};
62937c2aad20Sopenharmony_ci
62947c2aad20Sopenharmony_ci/* (Simplified) user return codes for tcx prog type.
62957c2aad20Sopenharmony_ci * A valid tcx program must return one of these defined values. All other
62967c2aad20Sopenharmony_ci * return codes are reserved for future use. Must remain compatible with
62977c2aad20Sopenharmony_ci * their TC_ACT_* counter-parts. For compatibility in behavior, unknown
62987c2aad20Sopenharmony_ci * return codes are mapped to TCX_NEXT.
62997c2aad20Sopenharmony_ci */
63007c2aad20Sopenharmony_cienum tcx_action_base {
63017c2aad20Sopenharmony_ci	TCX_NEXT	= -1,
63027c2aad20Sopenharmony_ci	TCX_PASS	= 0,
63037c2aad20Sopenharmony_ci	TCX_DROP	= 2,
63047c2aad20Sopenharmony_ci	TCX_REDIRECT	= 7,
63057c2aad20Sopenharmony_ci};
63067c2aad20Sopenharmony_ci
63077c2aad20Sopenharmony_cistruct bpf_xdp_sock {
63087c2aad20Sopenharmony_ci	__u32 queue_id;
63097c2aad20Sopenharmony_ci};
63107c2aad20Sopenharmony_ci
63117c2aad20Sopenharmony_ci#define XDP_PACKET_HEADROOM 256
63127c2aad20Sopenharmony_ci
63137c2aad20Sopenharmony_ci/* User return codes for XDP prog type.
63147c2aad20Sopenharmony_ci * A valid XDP program must return one of these defined values. All other
63157c2aad20Sopenharmony_ci * return codes are reserved for future use. Unknown return codes will
63167c2aad20Sopenharmony_ci * result in packet drops and a warning via bpf_warn_invalid_xdp_action().
63177c2aad20Sopenharmony_ci */
63187c2aad20Sopenharmony_cienum xdp_action {
63197c2aad20Sopenharmony_ci	XDP_ABORTED = 0,
63207c2aad20Sopenharmony_ci	XDP_DROP,
63217c2aad20Sopenharmony_ci	XDP_PASS,
63227c2aad20Sopenharmony_ci	XDP_TX,
63237c2aad20Sopenharmony_ci	XDP_REDIRECT,
63247c2aad20Sopenharmony_ci};
63257c2aad20Sopenharmony_ci
63267c2aad20Sopenharmony_ci/* user accessible metadata for XDP packet hook
63277c2aad20Sopenharmony_ci * new fields must be added to the end of this structure
63287c2aad20Sopenharmony_ci */
63297c2aad20Sopenharmony_cistruct xdp_md {
63307c2aad20Sopenharmony_ci	__u32 data;
63317c2aad20Sopenharmony_ci	__u32 data_end;
63327c2aad20Sopenharmony_ci	__u32 data_meta;
63337c2aad20Sopenharmony_ci	/* Below access go through struct xdp_rxq_info */
63347c2aad20Sopenharmony_ci	__u32 ingress_ifindex; /* rxq->dev->ifindex */
63357c2aad20Sopenharmony_ci	__u32 rx_queue_index;  /* rxq->queue_index  */
63367c2aad20Sopenharmony_ci
63377c2aad20Sopenharmony_ci	__u32 egress_ifindex;  /* txq->dev->ifindex */
63387c2aad20Sopenharmony_ci};
63397c2aad20Sopenharmony_ci
63407c2aad20Sopenharmony_ci/* DEVMAP map-value layout
63417c2aad20Sopenharmony_ci *
63427c2aad20Sopenharmony_ci * The struct data-layout of map-value is a configuration interface.
63437c2aad20Sopenharmony_ci * New members can only be added to the end of this structure.
63447c2aad20Sopenharmony_ci */
63457c2aad20Sopenharmony_cistruct bpf_devmap_val {
63467c2aad20Sopenharmony_ci	__u32 ifindex;   /* device index */
63477c2aad20Sopenharmony_ci	union {
63487c2aad20Sopenharmony_ci		int   fd;  /* prog fd on map write */
63497c2aad20Sopenharmony_ci		__u32 id;  /* prog id on map read */
63507c2aad20Sopenharmony_ci	} bpf_prog;
63517c2aad20Sopenharmony_ci};
63527c2aad20Sopenharmony_ci
63537c2aad20Sopenharmony_ci/* CPUMAP map-value layout
63547c2aad20Sopenharmony_ci *
63557c2aad20Sopenharmony_ci * The struct data-layout of map-value is a configuration interface.
63567c2aad20Sopenharmony_ci * New members can only be added to the end of this structure.
63577c2aad20Sopenharmony_ci */
63587c2aad20Sopenharmony_cistruct bpf_cpumap_val {
63597c2aad20Sopenharmony_ci	__u32 qsize;	/* queue size to remote target CPU */
63607c2aad20Sopenharmony_ci	union {
63617c2aad20Sopenharmony_ci		int   fd;	/* prog fd on map write */
63627c2aad20Sopenharmony_ci		__u32 id;	/* prog id on map read */
63637c2aad20Sopenharmony_ci	} bpf_prog;
63647c2aad20Sopenharmony_ci};
63657c2aad20Sopenharmony_ci
63667c2aad20Sopenharmony_cienum sk_action {
63677c2aad20Sopenharmony_ci	SK_DROP = 0,
63687c2aad20Sopenharmony_ci	SK_PASS,
63697c2aad20Sopenharmony_ci};
63707c2aad20Sopenharmony_ci
63717c2aad20Sopenharmony_ci/* user accessible metadata for SK_MSG packet hook, new fields must
63727c2aad20Sopenharmony_ci * be added to the end of this structure
63737c2aad20Sopenharmony_ci */
63747c2aad20Sopenharmony_cistruct sk_msg_md {
63757c2aad20Sopenharmony_ci	__bpf_md_ptr(void *, data);
63767c2aad20Sopenharmony_ci	__bpf_md_ptr(void *, data_end);
63777c2aad20Sopenharmony_ci
63787c2aad20Sopenharmony_ci	__u32 family;
63797c2aad20Sopenharmony_ci	__u32 remote_ip4;	/* Stored in network byte order */
63807c2aad20Sopenharmony_ci	__u32 local_ip4;	/* Stored in network byte order */
63817c2aad20Sopenharmony_ci	__u32 remote_ip6[4];	/* Stored in network byte order */
63827c2aad20Sopenharmony_ci	__u32 local_ip6[4];	/* Stored in network byte order */
63837c2aad20Sopenharmony_ci	__u32 remote_port;	/* Stored in network byte order */
63847c2aad20Sopenharmony_ci	__u32 local_port;	/* stored in host byte order */
63857c2aad20Sopenharmony_ci	__u32 size;		/* Total size of sk_msg */
63867c2aad20Sopenharmony_ci
63877c2aad20Sopenharmony_ci	__bpf_md_ptr(struct bpf_sock *, sk); /* current socket */
63887c2aad20Sopenharmony_ci};
63897c2aad20Sopenharmony_ci
63907c2aad20Sopenharmony_cistruct sk_reuseport_md {
63917c2aad20Sopenharmony_ci	/*
63927c2aad20Sopenharmony_ci	 * Start of directly accessible data. It begins from
63937c2aad20Sopenharmony_ci	 * the tcp/udp header.
63947c2aad20Sopenharmony_ci	 */
63957c2aad20Sopenharmony_ci	__bpf_md_ptr(void *, data);
63967c2aad20Sopenharmony_ci	/* End of directly accessible data */
63977c2aad20Sopenharmony_ci	__bpf_md_ptr(void *, data_end);
63987c2aad20Sopenharmony_ci	/*
63997c2aad20Sopenharmony_ci	 * Total length of packet (starting from the tcp/udp header).
64007c2aad20Sopenharmony_ci	 * Note that the directly accessible bytes (data_end - data)
64017c2aad20Sopenharmony_ci	 * could be less than this "len".  Those bytes could be
64027c2aad20Sopenharmony_ci	 * indirectly read by a helper "bpf_skb_load_bytes()".
64037c2aad20Sopenharmony_ci	 */
64047c2aad20Sopenharmony_ci	__u32 len;
64057c2aad20Sopenharmony_ci	/*
64067c2aad20Sopenharmony_ci	 * Eth protocol in the mac header (network byte order). e.g.
64077c2aad20Sopenharmony_ci	 * ETH_P_IP(0x0800) and ETH_P_IPV6(0x86DD)
64087c2aad20Sopenharmony_ci	 */
64097c2aad20Sopenharmony_ci	__u32 eth_protocol;
64107c2aad20Sopenharmony_ci	__u32 ip_protocol;	/* IP protocol. e.g. IPPROTO_TCP, IPPROTO_UDP */
64117c2aad20Sopenharmony_ci	__u32 bind_inany;	/* Is sock bound to an INANY address? */
64127c2aad20Sopenharmony_ci	__u32 hash;		/* A hash of the packet 4 tuples */
64137c2aad20Sopenharmony_ci	/* When reuse->migrating_sk is NULL, it is selecting a sk for the
64147c2aad20Sopenharmony_ci	 * new incoming connection request (e.g. selecting a listen sk for
64157c2aad20Sopenharmony_ci	 * the received SYN in the TCP case).  reuse->sk is one of the sk
64167c2aad20Sopenharmony_ci	 * in the reuseport group. The bpf prog can use reuse->sk to learn
64177c2aad20Sopenharmony_ci	 * the local listening ip/port without looking into the skb.
64187c2aad20Sopenharmony_ci	 *
64197c2aad20Sopenharmony_ci	 * When reuse->migrating_sk is not NULL, reuse->sk is closed and
64207c2aad20Sopenharmony_ci	 * reuse->migrating_sk is the socket that needs to be migrated
64217c2aad20Sopenharmony_ci	 * to another listening socket.  migrating_sk could be a fullsock
64227c2aad20Sopenharmony_ci	 * sk that is fully established or a reqsk that is in-the-middle
64237c2aad20Sopenharmony_ci	 * of 3-way handshake.
64247c2aad20Sopenharmony_ci	 */
64257c2aad20Sopenharmony_ci	__bpf_md_ptr(struct bpf_sock *, sk);
64267c2aad20Sopenharmony_ci	__bpf_md_ptr(struct bpf_sock *, migrating_sk);
64277c2aad20Sopenharmony_ci};
64287c2aad20Sopenharmony_ci
64297c2aad20Sopenharmony_ci#define BPF_TAG_SIZE	8
64307c2aad20Sopenharmony_ci
64317c2aad20Sopenharmony_cistruct bpf_prog_info {
64327c2aad20Sopenharmony_ci	__u32 type;
64337c2aad20Sopenharmony_ci	__u32 id;
64347c2aad20Sopenharmony_ci	__u8  tag[BPF_TAG_SIZE];
64357c2aad20Sopenharmony_ci	__u32 jited_prog_len;
64367c2aad20Sopenharmony_ci	__u32 xlated_prog_len;
64377c2aad20Sopenharmony_ci	__aligned_u64 jited_prog_insns;
64387c2aad20Sopenharmony_ci	__aligned_u64 xlated_prog_insns;
64397c2aad20Sopenharmony_ci	__u64 load_time;	/* ns since boottime */
64407c2aad20Sopenharmony_ci	__u32 created_by_uid;
64417c2aad20Sopenharmony_ci	__u32 nr_map_ids;
64427c2aad20Sopenharmony_ci	__aligned_u64 map_ids;
64437c2aad20Sopenharmony_ci	char name[BPF_OBJ_NAME_LEN];
64447c2aad20Sopenharmony_ci	__u32 ifindex;
64457c2aad20Sopenharmony_ci	__u32 gpl_compatible:1;
64467c2aad20Sopenharmony_ci	__u32 :31; /* alignment pad */
64477c2aad20Sopenharmony_ci	__u64 netns_dev;
64487c2aad20Sopenharmony_ci	__u64 netns_ino;
64497c2aad20Sopenharmony_ci	__u32 nr_jited_ksyms;
64507c2aad20Sopenharmony_ci	__u32 nr_jited_func_lens;
64517c2aad20Sopenharmony_ci	__aligned_u64 jited_ksyms;
64527c2aad20Sopenharmony_ci	__aligned_u64 jited_func_lens;
64537c2aad20Sopenharmony_ci	__u32 btf_id;
64547c2aad20Sopenharmony_ci	__u32 func_info_rec_size;
64557c2aad20Sopenharmony_ci	__aligned_u64 func_info;
64567c2aad20Sopenharmony_ci	__u32 nr_func_info;
64577c2aad20Sopenharmony_ci	__u32 nr_line_info;
64587c2aad20Sopenharmony_ci	__aligned_u64 line_info;
64597c2aad20Sopenharmony_ci	__aligned_u64 jited_line_info;
64607c2aad20Sopenharmony_ci	__u32 nr_jited_line_info;
64617c2aad20Sopenharmony_ci	__u32 line_info_rec_size;
64627c2aad20Sopenharmony_ci	__u32 jited_line_info_rec_size;
64637c2aad20Sopenharmony_ci	__u32 nr_prog_tags;
64647c2aad20Sopenharmony_ci	__aligned_u64 prog_tags;
64657c2aad20Sopenharmony_ci	__u64 run_time_ns;
64667c2aad20Sopenharmony_ci	__u64 run_cnt;
64677c2aad20Sopenharmony_ci	__u64 recursion_misses;
64687c2aad20Sopenharmony_ci	__u32 verified_insns;
64697c2aad20Sopenharmony_ci	__u32 attach_btf_obj_id;
64707c2aad20Sopenharmony_ci	__u32 attach_btf_id;
64717c2aad20Sopenharmony_ci} __attribute__((aligned(8)));
64727c2aad20Sopenharmony_ci
64737c2aad20Sopenharmony_cistruct bpf_map_info {
64747c2aad20Sopenharmony_ci	__u32 type;
64757c2aad20Sopenharmony_ci	__u32 id;
64767c2aad20Sopenharmony_ci	__u32 key_size;
64777c2aad20Sopenharmony_ci	__u32 value_size;
64787c2aad20Sopenharmony_ci	__u32 max_entries;
64797c2aad20Sopenharmony_ci	__u32 map_flags;
64807c2aad20Sopenharmony_ci	char  name[BPF_OBJ_NAME_LEN];
64817c2aad20Sopenharmony_ci	__u32 ifindex;
64827c2aad20Sopenharmony_ci	__u32 btf_vmlinux_value_type_id;
64837c2aad20Sopenharmony_ci	__u64 netns_dev;
64847c2aad20Sopenharmony_ci	__u64 netns_ino;
64857c2aad20Sopenharmony_ci	__u32 btf_id;
64867c2aad20Sopenharmony_ci	__u32 btf_key_type_id;
64877c2aad20Sopenharmony_ci	__u32 btf_value_type_id;
64887c2aad20Sopenharmony_ci	__u32 :32;	/* alignment pad */
64897c2aad20Sopenharmony_ci	__u64 map_extra;
64907c2aad20Sopenharmony_ci} __attribute__((aligned(8)));
64917c2aad20Sopenharmony_ci
64927c2aad20Sopenharmony_cistruct bpf_btf_info {
64937c2aad20Sopenharmony_ci	__aligned_u64 btf;
64947c2aad20Sopenharmony_ci	__u32 btf_size;
64957c2aad20Sopenharmony_ci	__u32 id;
64967c2aad20Sopenharmony_ci	__aligned_u64 name;
64977c2aad20Sopenharmony_ci	__u32 name_len;
64987c2aad20Sopenharmony_ci	__u32 kernel_btf;
64997c2aad20Sopenharmony_ci} __attribute__((aligned(8)));
65007c2aad20Sopenharmony_ci
65017c2aad20Sopenharmony_cistruct bpf_link_info {
65027c2aad20Sopenharmony_ci	__u32 type;
65037c2aad20Sopenharmony_ci	__u32 id;
65047c2aad20Sopenharmony_ci	__u32 prog_id;
65057c2aad20Sopenharmony_ci	union {
65067c2aad20Sopenharmony_ci		struct {
65077c2aad20Sopenharmony_ci			__aligned_u64 tp_name; /* in/out: tp_name buffer ptr */
65087c2aad20Sopenharmony_ci			__u32 tp_name_len;     /* in/out: tp_name buffer len */
65097c2aad20Sopenharmony_ci		} raw_tracepoint;
65107c2aad20Sopenharmony_ci		struct {
65117c2aad20Sopenharmony_ci			__u32 attach_type;
65127c2aad20Sopenharmony_ci			__u32 target_obj_id; /* prog_id for PROG_EXT, otherwise btf object id */
65137c2aad20Sopenharmony_ci			__u32 target_btf_id; /* BTF type id inside the object */
65147c2aad20Sopenharmony_ci		} tracing;
65157c2aad20Sopenharmony_ci		struct {
65167c2aad20Sopenharmony_ci			__u64 cgroup_id;
65177c2aad20Sopenharmony_ci			__u32 attach_type;
65187c2aad20Sopenharmony_ci		} cgroup;
65197c2aad20Sopenharmony_ci		struct {
65207c2aad20Sopenharmony_ci			__aligned_u64 target_name; /* in/out: target_name buffer ptr */
65217c2aad20Sopenharmony_ci			__u32 target_name_len;	   /* in/out: target_name buffer len */
65227c2aad20Sopenharmony_ci
65237c2aad20Sopenharmony_ci			/* If the iter specific field is 32 bits, it can be put
65247c2aad20Sopenharmony_ci			 * in the first or second union. Otherwise it should be
65257c2aad20Sopenharmony_ci			 * put in the second union.
65267c2aad20Sopenharmony_ci			 */
65277c2aad20Sopenharmony_ci			union {
65287c2aad20Sopenharmony_ci				struct {
65297c2aad20Sopenharmony_ci					__u32 map_id;
65307c2aad20Sopenharmony_ci				} map;
65317c2aad20Sopenharmony_ci			};
65327c2aad20Sopenharmony_ci			union {
65337c2aad20Sopenharmony_ci				struct {
65347c2aad20Sopenharmony_ci					__u64 cgroup_id;
65357c2aad20Sopenharmony_ci					__u32 order;
65367c2aad20Sopenharmony_ci				} cgroup;
65377c2aad20Sopenharmony_ci				struct {
65387c2aad20Sopenharmony_ci					__u32 tid;
65397c2aad20Sopenharmony_ci					__u32 pid;
65407c2aad20Sopenharmony_ci				} task;
65417c2aad20Sopenharmony_ci			};
65427c2aad20Sopenharmony_ci		} iter;
65437c2aad20Sopenharmony_ci		struct  {
65447c2aad20Sopenharmony_ci			__u32 netns_ino;
65457c2aad20Sopenharmony_ci			__u32 attach_type;
65467c2aad20Sopenharmony_ci		} netns;
65477c2aad20Sopenharmony_ci		struct {
65487c2aad20Sopenharmony_ci			__u32 ifindex;
65497c2aad20Sopenharmony_ci		} xdp;
65507c2aad20Sopenharmony_ci		struct {
65517c2aad20Sopenharmony_ci			__u32 map_id;
65527c2aad20Sopenharmony_ci		} struct_ops;
65537c2aad20Sopenharmony_ci		struct {
65547c2aad20Sopenharmony_ci			__u32 pf;
65557c2aad20Sopenharmony_ci			__u32 hooknum;
65567c2aad20Sopenharmony_ci			__s32 priority;
65577c2aad20Sopenharmony_ci			__u32 flags;
65587c2aad20Sopenharmony_ci		} netfilter;
65597c2aad20Sopenharmony_ci		struct {
65607c2aad20Sopenharmony_ci			__aligned_u64 addrs;
65617c2aad20Sopenharmony_ci			__u32 count; /* in/out: kprobe_multi function count */
65627c2aad20Sopenharmony_ci			__u32 flags;
65637c2aad20Sopenharmony_ci			__u64 missed;
65647c2aad20Sopenharmony_ci		} kprobe_multi;
65657c2aad20Sopenharmony_ci		struct {
65667c2aad20Sopenharmony_ci			__u32 type; /* enum bpf_perf_event_type */
65677c2aad20Sopenharmony_ci			__u32 :32;
65687c2aad20Sopenharmony_ci			union {
65697c2aad20Sopenharmony_ci				struct {
65707c2aad20Sopenharmony_ci					__aligned_u64 file_name; /* in/out */
65717c2aad20Sopenharmony_ci					__u32 name_len;
65727c2aad20Sopenharmony_ci					__u32 offset; /* offset from file_name */
65737c2aad20Sopenharmony_ci				} uprobe; /* BPF_PERF_EVENT_UPROBE, BPF_PERF_EVENT_URETPROBE */
65747c2aad20Sopenharmony_ci				struct {
65757c2aad20Sopenharmony_ci					__aligned_u64 func_name; /* in/out */
65767c2aad20Sopenharmony_ci					__u32 name_len;
65777c2aad20Sopenharmony_ci					__u32 offset; /* offset from func_name */
65787c2aad20Sopenharmony_ci					__u64 addr;
65797c2aad20Sopenharmony_ci					__u64 missed;
65807c2aad20Sopenharmony_ci				} kprobe; /* BPF_PERF_EVENT_KPROBE, BPF_PERF_EVENT_KRETPROBE */
65817c2aad20Sopenharmony_ci				struct {
65827c2aad20Sopenharmony_ci					__aligned_u64 tp_name;   /* in/out */
65837c2aad20Sopenharmony_ci					__u32 name_len;
65847c2aad20Sopenharmony_ci				} tracepoint; /* BPF_PERF_EVENT_TRACEPOINT */
65857c2aad20Sopenharmony_ci				struct {
65867c2aad20Sopenharmony_ci					__u64 config;
65877c2aad20Sopenharmony_ci					__u32 type;
65887c2aad20Sopenharmony_ci				} event; /* BPF_PERF_EVENT_EVENT */
65897c2aad20Sopenharmony_ci			};
65907c2aad20Sopenharmony_ci		} perf_event;
65917c2aad20Sopenharmony_ci		struct {
65927c2aad20Sopenharmony_ci			__u32 ifindex;
65937c2aad20Sopenharmony_ci			__u32 attach_type;
65947c2aad20Sopenharmony_ci		} tcx;
65957c2aad20Sopenharmony_ci		struct {
65967c2aad20Sopenharmony_ci			__u32 ifindex;
65977c2aad20Sopenharmony_ci			__u32 attach_type;
65987c2aad20Sopenharmony_ci		} netkit;
65997c2aad20Sopenharmony_ci	};
66007c2aad20Sopenharmony_ci} __attribute__((aligned(8)));
66017c2aad20Sopenharmony_ci
66027c2aad20Sopenharmony_ci/* User bpf_sock_addr struct to access socket fields and sockaddr struct passed
66037c2aad20Sopenharmony_ci * by user and intended to be used by socket (e.g. to bind to, depends on
66047c2aad20Sopenharmony_ci * attach type).
66057c2aad20Sopenharmony_ci */
66067c2aad20Sopenharmony_cistruct bpf_sock_addr {
66077c2aad20Sopenharmony_ci	__u32 user_family;	/* Allows 4-byte read, but no write. */
66087c2aad20Sopenharmony_ci	__u32 user_ip4;		/* Allows 1,2,4-byte read and 4-byte write.
66097c2aad20Sopenharmony_ci				 * Stored in network byte order.
66107c2aad20Sopenharmony_ci				 */
66117c2aad20Sopenharmony_ci	__u32 user_ip6[4];	/* Allows 1,2,4,8-byte read and 4,8-byte write.
66127c2aad20Sopenharmony_ci				 * Stored in network byte order.
66137c2aad20Sopenharmony_ci				 */
66147c2aad20Sopenharmony_ci	__u32 user_port;	/* Allows 1,2,4-byte read and 4-byte write.
66157c2aad20Sopenharmony_ci				 * Stored in network byte order
66167c2aad20Sopenharmony_ci				 */
66177c2aad20Sopenharmony_ci	__u32 family;		/* Allows 4-byte read, but no write */
66187c2aad20Sopenharmony_ci	__u32 type;		/* Allows 4-byte read, but no write */
66197c2aad20Sopenharmony_ci	__u32 protocol;		/* Allows 4-byte read, but no write */
66207c2aad20Sopenharmony_ci	__u32 msg_src_ip4;	/* Allows 1,2,4-byte read and 4-byte write.
66217c2aad20Sopenharmony_ci				 * Stored in network byte order.
66227c2aad20Sopenharmony_ci				 */
66237c2aad20Sopenharmony_ci	__u32 msg_src_ip6[4];	/* Allows 1,2,4,8-byte read and 4,8-byte write.
66247c2aad20Sopenharmony_ci				 * Stored in network byte order.
66257c2aad20Sopenharmony_ci				 */
66267c2aad20Sopenharmony_ci	__bpf_md_ptr(struct bpf_sock *, sk);
66277c2aad20Sopenharmony_ci};
66287c2aad20Sopenharmony_ci
66297c2aad20Sopenharmony_ci/* User bpf_sock_ops struct to access socket values and specify request ops
66307c2aad20Sopenharmony_ci * and their replies.
66317c2aad20Sopenharmony_ci * Some of this fields are in network (bigendian) byte order and may need
66327c2aad20Sopenharmony_ci * to be converted before use (bpf_ntohl() defined in samples/bpf/bpf_endian.h).
66337c2aad20Sopenharmony_ci * New fields can only be added at the end of this structure
66347c2aad20Sopenharmony_ci */
66357c2aad20Sopenharmony_cistruct bpf_sock_ops {
66367c2aad20Sopenharmony_ci	__u32 op;
66377c2aad20Sopenharmony_ci	union {
66387c2aad20Sopenharmony_ci		__u32 args[4];		/* Optionally passed to bpf program */
66397c2aad20Sopenharmony_ci		__u32 reply;		/* Returned by bpf program	    */
66407c2aad20Sopenharmony_ci		__u32 replylong[4];	/* Optionally returned by bpf prog  */
66417c2aad20Sopenharmony_ci	};
66427c2aad20Sopenharmony_ci	__u32 family;
66437c2aad20Sopenharmony_ci	__u32 remote_ip4;	/* Stored in network byte order */
66447c2aad20Sopenharmony_ci	__u32 local_ip4;	/* Stored in network byte order */
66457c2aad20Sopenharmony_ci	__u32 remote_ip6[4];	/* Stored in network byte order */
66467c2aad20Sopenharmony_ci	__u32 local_ip6[4];	/* Stored in network byte order */
66477c2aad20Sopenharmony_ci	__u32 remote_port;	/* Stored in network byte order */
66487c2aad20Sopenharmony_ci	__u32 local_port;	/* stored in host byte order */
66497c2aad20Sopenharmony_ci	__u32 is_fullsock;	/* Some TCP fields are only valid if
66507c2aad20Sopenharmony_ci				 * there is a full socket. If not, the
66517c2aad20Sopenharmony_ci				 * fields read as zero.
66527c2aad20Sopenharmony_ci				 */
66537c2aad20Sopenharmony_ci	__u32 snd_cwnd;
66547c2aad20Sopenharmony_ci	__u32 srtt_us;		/* Averaged RTT << 3 in usecs */
66557c2aad20Sopenharmony_ci	__u32 bpf_sock_ops_cb_flags; /* flags defined in uapi/linux/tcp.h */
66567c2aad20Sopenharmony_ci	__u32 state;
66577c2aad20Sopenharmony_ci	__u32 rtt_min;
66587c2aad20Sopenharmony_ci	__u32 snd_ssthresh;
66597c2aad20Sopenharmony_ci	__u32 rcv_nxt;
66607c2aad20Sopenharmony_ci	__u32 snd_nxt;
66617c2aad20Sopenharmony_ci	__u32 snd_una;
66627c2aad20Sopenharmony_ci	__u32 mss_cache;
66637c2aad20Sopenharmony_ci	__u32 ecn_flags;
66647c2aad20Sopenharmony_ci	__u32 rate_delivered;
66657c2aad20Sopenharmony_ci	__u32 rate_interval_us;
66667c2aad20Sopenharmony_ci	__u32 packets_out;
66677c2aad20Sopenharmony_ci	__u32 retrans_out;
66687c2aad20Sopenharmony_ci	__u32 total_retrans;
66697c2aad20Sopenharmony_ci	__u32 segs_in;
66707c2aad20Sopenharmony_ci	__u32 data_segs_in;
66717c2aad20Sopenharmony_ci	__u32 segs_out;
66727c2aad20Sopenharmony_ci	__u32 data_segs_out;
66737c2aad20Sopenharmony_ci	__u32 lost_out;
66747c2aad20Sopenharmony_ci	__u32 sacked_out;
66757c2aad20Sopenharmony_ci	__u32 sk_txhash;
66767c2aad20Sopenharmony_ci	__u64 bytes_received;
66777c2aad20Sopenharmony_ci	__u64 bytes_acked;
66787c2aad20Sopenharmony_ci	__bpf_md_ptr(struct bpf_sock *, sk);
66797c2aad20Sopenharmony_ci	/* [skb_data, skb_data_end) covers the whole TCP header.
66807c2aad20Sopenharmony_ci	 *
66817c2aad20Sopenharmony_ci	 * BPF_SOCK_OPS_PARSE_HDR_OPT_CB: The packet received
66827c2aad20Sopenharmony_ci	 * BPF_SOCK_OPS_HDR_OPT_LEN_CB:   Not useful because the
66837c2aad20Sopenharmony_ci	 *                                header has not been written.
66847c2aad20Sopenharmony_ci	 * BPF_SOCK_OPS_WRITE_HDR_OPT_CB: The header and options have
66857c2aad20Sopenharmony_ci	 *				  been written so far.
66867c2aad20Sopenharmony_ci	 * BPF_SOCK_OPS_ACTIVE_ESTABLISHED_CB:  The SYNACK that concludes
66877c2aad20Sopenharmony_ci	 *					the 3WHS.
66887c2aad20Sopenharmony_ci	 * BPF_SOCK_OPS_PASSIVE_ESTABLISHED_CB: The ACK that concludes
66897c2aad20Sopenharmony_ci	 *					the 3WHS.
66907c2aad20Sopenharmony_ci	 *
66917c2aad20Sopenharmony_ci	 * bpf_load_hdr_opt() can also be used to read a particular option.
66927c2aad20Sopenharmony_ci	 */
66937c2aad20Sopenharmony_ci	__bpf_md_ptr(void *, skb_data);
66947c2aad20Sopenharmony_ci	__bpf_md_ptr(void *, skb_data_end);
66957c2aad20Sopenharmony_ci	__u32 skb_len;		/* The total length of a packet.
66967c2aad20Sopenharmony_ci				 * It includes the header, options,
66977c2aad20Sopenharmony_ci				 * and payload.
66987c2aad20Sopenharmony_ci				 */
66997c2aad20Sopenharmony_ci	__u32 skb_tcp_flags;	/* tcp_flags of the header.  It provides
67007c2aad20Sopenharmony_ci				 * an easy way to check for tcp_flags
67017c2aad20Sopenharmony_ci				 * without parsing skb_data.
67027c2aad20Sopenharmony_ci				 *
67037c2aad20Sopenharmony_ci				 * In particular, the skb_tcp_flags
67047c2aad20Sopenharmony_ci				 * will still be available in
67057c2aad20Sopenharmony_ci				 * BPF_SOCK_OPS_HDR_OPT_LEN even though
67067c2aad20Sopenharmony_ci				 * the outgoing header has not
67077c2aad20Sopenharmony_ci				 * been written yet.
67087c2aad20Sopenharmony_ci				 */
67097c2aad20Sopenharmony_ci	__u64 skb_hwtstamp;
67107c2aad20Sopenharmony_ci};
67117c2aad20Sopenharmony_ci
67127c2aad20Sopenharmony_ci/* Definitions for bpf_sock_ops_cb_flags */
67137c2aad20Sopenharmony_cienum {
67147c2aad20Sopenharmony_ci	BPF_SOCK_OPS_RTO_CB_FLAG	= (1<<0),
67157c2aad20Sopenharmony_ci	BPF_SOCK_OPS_RETRANS_CB_FLAG	= (1<<1),
67167c2aad20Sopenharmony_ci	BPF_SOCK_OPS_STATE_CB_FLAG	= (1<<2),
67177c2aad20Sopenharmony_ci	BPF_SOCK_OPS_RTT_CB_FLAG	= (1<<3),
67187c2aad20Sopenharmony_ci	/* Call bpf for all received TCP headers.  The bpf prog will be
67197c2aad20Sopenharmony_ci	 * called under sock_ops->op == BPF_SOCK_OPS_PARSE_HDR_OPT_CB
67207c2aad20Sopenharmony_ci	 *
67217c2aad20Sopenharmony_ci	 * Please refer to the comment in BPF_SOCK_OPS_PARSE_HDR_OPT_CB
67227c2aad20Sopenharmony_ci	 * for the header option related helpers that will be useful
67237c2aad20Sopenharmony_ci	 * to the bpf programs.
67247c2aad20Sopenharmony_ci	 *
67257c2aad20Sopenharmony_ci	 * It could be used at the client/active side (i.e. connect() side)
67267c2aad20Sopenharmony_ci	 * when the server told it that the server was in syncookie
67277c2aad20Sopenharmony_ci	 * mode and required the active side to resend the bpf-written
67287c2aad20Sopenharmony_ci	 * options.  The active side can keep writing the bpf-options until
67297c2aad20Sopenharmony_ci	 * it received a valid packet from the server side to confirm
67307c2aad20Sopenharmony_ci	 * the earlier packet (and options) has been received.  The later
67317c2aad20Sopenharmony_ci	 * example patch is using it like this at the active side when the
67327c2aad20Sopenharmony_ci	 * server is in syncookie mode.
67337c2aad20Sopenharmony_ci	 *
67347c2aad20Sopenharmony_ci	 * The bpf prog will usually turn this off in the common cases.
67357c2aad20Sopenharmony_ci	 */
67367c2aad20Sopenharmony_ci	BPF_SOCK_OPS_PARSE_ALL_HDR_OPT_CB_FLAG	= (1<<4),
67377c2aad20Sopenharmony_ci	/* Call bpf when kernel has received a header option that
67387c2aad20Sopenharmony_ci	 * the kernel cannot handle.  The bpf prog will be called under
67397c2aad20Sopenharmony_ci	 * sock_ops->op == BPF_SOCK_OPS_PARSE_HDR_OPT_CB.
67407c2aad20Sopenharmony_ci	 *
67417c2aad20Sopenharmony_ci	 * Please refer to the comment in BPF_SOCK_OPS_PARSE_HDR_OPT_CB
67427c2aad20Sopenharmony_ci	 * for the header option related helpers that will be useful
67437c2aad20Sopenharmony_ci	 * to the bpf programs.
67447c2aad20Sopenharmony_ci	 */
67457c2aad20Sopenharmony_ci	BPF_SOCK_OPS_PARSE_UNKNOWN_HDR_OPT_CB_FLAG = (1<<5),
67467c2aad20Sopenharmony_ci	/* Call bpf when the kernel is writing header options for the
67477c2aad20Sopenharmony_ci	 * outgoing packet.  The bpf prog will first be called
67487c2aad20Sopenharmony_ci	 * to reserve space in a skb under
67497c2aad20Sopenharmony_ci	 * sock_ops->op == BPF_SOCK_OPS_HDR_OPT_LEN_CB.  Then
67507c2aad20Sopenharmony_ci	 * the bpf prog will be called to write the header option(s)
67517c2aad20Sopenharmony_ci	 * under sock_ops->op == BPF_SOCK_OPS_WRITE_HDR_OPT_CB.
67527c2aad20Sopenharmony_ci	 *
67537c2aad20Sopenharmony_ci	 * Please refer to the comment in BPF_SOCK_OPS_HDR_OPT_LEN_CB
67547c2aad20Sopenharmony_ci	 * and BPF_SOCK_OPS_WRITE_HDR_OPT_CB for the header option
67557c2aad20Sopenharmony_ci	 * related helpers that will be useful to the bpf programs.
67567c2aad20Sopenharmony_ci	 *
67577c2aad20Sopenharmony_ci	 * The kernel gets its chance to reserve space and write
67587c2aad20Sopenharmony_ci	 * options first before the BPF program does.
67597c2aad20Sopenharmony_ci	 */
67607c2aad20Sopenharmony_ci	BPF_SOCK_OPS_WRITE_HDR_OPT_CB_FLAG = (1<<6),
67617c2aad20Sopenharmony_ci/* Mask of all currently supported cb flags */
67627c2aad20Sopenharmony_ci	BPF_SOCK_OPS_ALL_CB_FLAGS       = 0x7F,
67637c2aad20Sopenharmony_ci};
67647c2aad20Sopenharmony_ci
67657c2aad20Sopenharmony_ci/* List of known BPF sock_ops operators.
67667c2aad20Sopenharmony_ci * New entries can only be added at the end
67677c2aad20Sopenharmony_ci */
67687c2aad20Sopenharmony_cienum {
67697c2aad20Sopenharmony_ci	BPF_SOCK_OPS_VOID,
67707c2aad20Sopenharmony_ci	BPF_SOCK_OPS_TIMEOUT_INIT,	/* Should return SYN-RTO value to use or
67717c2aad20Sopenharmony_ci					 * -1 if default value should be used
67727c2aad20Sopenharmony_ci					 */
67737c2aad20Sopenharmony_ci	BPF_SOCK_OPS_RWND_INIT,		/* Should return initial advertized
67747c2aad20Sopenharmony_ci					 * window (in packets) or -1 if default
67757c2aad20Sopenharmony_ci					 * value should be used
67767c2aad20Sopenharmony_ci					 */
67777c2aad20Sopenharmony_ci	BPF_SOCK_OPS_TCP_CONNECT_CB,	/* Calls BPF program right before an
67787c2aad20Sopenharmony_ci					 * active connection is initialized
67797c2aad20Sopenharmony_ci					 */
67807c2aad20Sopenharmony_ci	BPF_SOCK_OPS_ACTIVE_ESTABLISHED_CB,	/* Calls BPF program when an
67817c2aad20Sopenharmony_ci						 * active connection is
67827c2aad20Sopenharmony_ci						 * established
67837c2aad20Sopenharmony_ci						 */
67847c2aad20Sopenharmony_ci	BPF_SOCK_OPS_PASSIVE_ESTABLISHED_CB,	/* Calls BPF program when a
67857c2aad20Sopenharmony_ci						 * passive connection is
67867c2aad20Sopenharmony_ci						 * established
67877c2aad20Sopenharmony_ci						 */
67887c2aad20Sopenharmony_ci	BPF_SOCK_OPS_NEEDS_ECN,		/* If connection's congestion control
67897c2aad20Sopenharmony_ci					 * needs ECN
67907c2aad20Sopenharmony_ci					 */
67917c2aad20Sopenharmony_ci	BPF_SOCK_OPS_BASE_RTT,		/* Get base RTT. The correct value is
67927c2aad20Sopenharmony_ci					 * based on the path and may be
67937c2aad20Sopenharmony_ci					 * dependent on the congestion control
67947c2aad20Sopenharmony_ci					 * algorithm. In general it indicates
67957c2aad20Sopenharmony_ci					 * a congestion threshold. RTTs above
67967c2aad20Sopenharmony_ci					 * this indicate congestion
67977c2aad20Sopenharmony_ci					 */
67987c2aad20Sopenharmony_ci	BPF_SOCK_OPS_RTO_CB,		/* Called when an RTO has triggered.
67997c2aad20Sopenharmony_ci					 * Arg1: value of icsk_retransmits
68007c2aad20Sopenharmony_ci					 * Arg2: value of icsk_rto
68017c2aad20Sopenharmony_ci					 * Arg3: whether RTO has expired
68027c2aad20Sopenharmony_ci					 */
68037c2aad20Sopenharmony_ci	BPF_SOCK_OPS_RETRANS_CB,	/* Called when skb is retransmitted.
68047c2aad20Sopenharmony_ci					 * Arg1: sequence number of 1st byte
68057c2aad20Sopenharmony_ci					 * Arg2: # segments
68067c2aad20Sopenharmony_ci					 * Arg3: return value of
68077c2aad20Sopenharmony_ci					 *       tcp_transmit_skb (0 => success)
68087c2aad20Sopenharmony_ci					 */
68097c2aad20Sopenharmony_ci	BPF_SOCK_OPS_STATE_CB,		/* Called when TCP changes state.
68107c2aad20Sopenharmony_ci					 * Arg1: old_state
68117c2aad20Sopenharmony_ci					 * Arg2: new_state
68127c2aad20Sopenharmony_ci					 */
68137c2aad20Sopenharmony_ci	BPF_SOCK_OPS_TCP_LISTEN_CB,	/* Called on listen(2), right after
68147c2aad20Sopenharmony_ci					 * socket transition to LISTEN state.
68157c2aad20Sopenharmony_ci					 */
68167c2aad20Sopenharmony_ci	BPF_SOCK_OPS_RTT_CB,		/* Called on every RTT.
68177c2aad20Sopenharmony_ci					 */
68187c2aad20Sopenharmony_ci	BPF_SOCK_OPS_PARSE_HDR_OPT_CB,	/* Parse the header option.
68197c2aad20Sopenharmony_ci					 * It will be called to handle
68207c2aad20Sopenharmony_ci					 * the packets received at
68217c2aad20Sopenharmony_ci					 * an already established
68227c2aad20Sopenharmony_ci					 * connection.
68237c2aad20Sopenharmony_ci					 *
68247c2aad20Sopenharmony_ci					 * sock_ops->skb_data:
68257c2aad20Sopenharmony_ci					 * Referring to the received skb.
68267c2aad20Sopenharmony_ci					 * It covers the TCP header only.
68277c2aad20Sopenharmony_ci					 *
68287c2aad20Sopenharmony_ci					 * bpf_load_hdr_opt() can also
68297c2aad20Sopenharmony_ci					 * be used to search for a
68307c2aad20Sopenharmony_ci					 * particular option.
68317c2aad20Sopenharmony_ci					 */
68327c2aad20Sopenharmony_ci	BPF_SOCK_OPS_HDR_OPT_LEN_CB,	/* Reserve space for writing the
68337c2aad20Sopenharmony_ci					 * header option later in
68347c2aad20Sopenharmony_ci					 * BPF_SOCK_OPS_WRITE_HDR_OPT_CB.
68357c2aad20Sopenharmony_ci					 * Arg1: bool want_cookie. (in
68367c2aad20Sopenharmony_ci					 *       writing SYNACK only)
68377c2aad20Sopenharmony_ci					 *
68387c2aad20Sopenharmony_ci					 * sock_ops->skb_data:
68397c2aad20Sopenharmony_ci					 * Not available because no header has
68407c2aad20Sopenharmony_ci					 * been	written yet.
68417c2aad20Sopenharmony_ci					 *
68427c2aad20Sopenharmony_ci					 * sock_ops->skb_tcp_flags:
68437c2aad20Sopenharmony_ci					 * The tcp_flags of the
68447c2aad20Sopenharmony_ci					 * outgoing skb. (e.g. SYN, ACK, FIN).
68457c2aad20Sopenharmony_ci					 *
68467c2aad20Sopenharmony_ci					 * bpf_reserve_hdr_opt() should
68477c2aad20Sopenharmony_ci					 * be used to reserve space.
68487c2aad20Sopenharmony_ci					 */
68497c2aad20Sopenharmony_ci	BPF_SOCK_OPS_WRITE_HDR_OPT_CB,	/* Write the header options
68507c2aad20Sopenharmony_ci					 * Arg1: bool want_cookie. (in
68517c2aad20Sopenharmony_ci					 *       writing SYNACK only)
68527c2aad20Sopenharmony_ci					 *
68537c2aad20Sopenharmony_ci					 * sock_ops->skb_data:
68547c2aad20Sopenharmony_ci					 * Referring to the outgoing skb.
68557c2aad20Sopenharmony_ci					 * It covers the TCP header
68567c2aad20Sopenharmony_ci					 * that has already been written
68577c2aad20Sopenharmony_ci					 * by the kernel and the
68587c2aad20Sopenharmony_ci					 * earlier bpf-progs.
68597c2aad20Sopenharmony_ci					 *
68607c2aad20Sopenharmony_ci					 * sock_ops->skb_tcp_flags:
68617c2aad20Sopenharmony_ci					 * The tcp_flags of the outgoing
68627c2aad20Sopenharmony_ci					 * skb. (e.g. SYN, ACK, FIN).
68637c2aad20Sopenharmony_ci					 *
68647c2aad20Sopenharmony_ci					 * bpf_store_hdr_opt() should
68657c2aad20Sopenharmony_ci					 * be used to write the
68667c2aad20Sopenharmony_ci					 * option.
68677c2aad20Sopenharmony_ci					 *
68687c2aad20Sopenharmony_ci					 * bpf_load_hdr_opt() can also
68697c2aad20Sopenharmony_ci					 * be used to search for a
68707c2aad20Sopenharmony_ci					 * particular option that
68717c2aad20Sopenharmony_ci					 * has already been written
68727c2aad20Sopenharmony_ci					 * by the kernel or the
68737c2aad20Sopenharmony_ci					 * earlier bpf-progs.
68747c2aad20Sopenharmony_ci					 */
68757c2aad20Sopenharmony_ci};
68767c2aad20Sopenharmony_ci
68777c2aad20Sopenharmony_ci/* List of TCP states. There is a build check in net/ipv4/tcp.c to detect
68787c2aad20Sopenharmony_ci * changes between the TCP and BPF versions. Ideally this should never happen.
68797c2aad20Sopenharmony_ci * If it does, we need to add code to convert them before calling
68807c2aad20Sopenharmony_ci * the BPF sock_ops function.
68817c2aad20Sopenharmony_ci */
68827c2aad20Sopenharmony_cienum {
68837c2aad20Sopenharmony_ci	BPF_TCP_ESTABLISHED = 1,
68847c2aad20Sopenharmony_ci	BPF_TCP_SYN_SENT,
68857c2aad20Sopenharmony_ci	BPF_TCP_SYN_RECV,
68867c2aad20Sopenharmony_ci	BPF_TCP_FIN_WAIT1,
68877c2aad20Sopenharmony_ci	BPF_TCP_FIN_WAIT2,
68887c2aad20Sopenharmony_ci	BPF_TCP_TIME_WAIT,
68897c2aad20Sopenharmony_ci	BPF_TCP_CLOSE,
68907c2aad20Sopenharmony_ci	BPF_TCP_CLOSE_WAIT,
68917c2aad20Sopenharmony_ci	BPF_TCP_LAST_ACK,
68927c2aad20Sopenharmony_ci	BPF_TCP_LISTEN,
68937c2aad20Sopenharmony_ci	BPF_TCP_CLOSING,	/* Now a valid state */
68947c2aad20Sopenharmony_ci	BPF_TCP_NEW_SYN_RECV,
68957c2aad20Sopenharmony_ci
68967c2aad20Sopenharmony_ci	BPF_TCP_MAX_STATES	/* Leave at the end! */
68977c2aad20Sopenharmony_ci};
68987c2aad20Sopenharmony_ci
68997c2aad20Sopenharmony_cienum {
69007c2aad20Sopenharmony_ci	TCP_BPF_IW		= 1001,	/* Set TCP initial congestion window */
69017c2aad20Sopenharmony_ci	TCP_BPF_SNDCWND_CLAMP	= 1002,	/* Set sndcwnd_clamp */
69027c2aad20Sopenharmony_ci	TCP_BPF_DELACK_MAX	= 1003, /* Max delay ack in usecs */
69037c2aad20Sopenharmony_ci	TCP_BPF_RTO_MIN		= 1004, /* Min delay ack in usecs */
69047c2aad20Sopenharmony_ci	/* Copy the SYN pkt to optval
69057c2aad20Sopenharmony_ci	 *
69067c2aad20Sopenharmony_ci	 * BPF_PROG_TYPE_SOCK_OPS only.  It is similar to the
69077c2aad20Sopenharmony_ci	 * bpf_getsockopt(TCP_SAVED_SYN) but it does not limit
69087c2aad20Sopenharmony_ci	 * to only getting from the saved_syn.  It can either get the
69097c2aad20Sopenharmony_ci	 * syn packet from:
69107c2aad20Sopenharmony_ci	 *
69117c2aad20Sopenharmony_ci	 * 1. the just-received SYN packet (only available when writing the
69127c2aad20Sopenharmony_ci	 *    SYNACK).  It will be useful when it is not necessary to
69137c2aad20Sopenharmony_ci	 *    save the SYN packet for latter use.  It is also the only way
69147c2aad20Sopenharmony_ci	 *    to get the SYN during syncookie mode because the syn
69157c2aad20Sopenharmony_ci	 *    packet cannot be saved during syncookie.
69167c2aad20Sopenharmony_ci	 *
69177c2aad20Sopenharmony_ci	 * OR
69187c2aad20Sopenharmony_ci	 *
69197c2aad20Sopenharmony_ci	 * 2. the earlier saved syn which was done by
69207c2aad20Sopenharmony_ci	 *    bpf_setsockopt(TCP_SAVE_SYN).
69217c2aad20Sopenharmony_ci	 *
69227c2aad20Sopenharmony_ci	 * The bpf_getsockopt(TCP_BPF_SYN*) option will hide where the
69237c2aad20Sopenharmony_ci	 * SYN packet is obtained.
69247c2aad20Sopenharmony_ci	 *
69257c2aad20Sopenharmony_ci	 * If the bpf-prog does not need the IP[46] header,  the
69267c2aad20Sopenharmony_ci	 * bpf-prog can avoid parsing the IP header by using
69277c2aad20Sopenharmony_ci	 * TCP_BPF_SYN.  Otherwise, the bpf-prog can get both
69287c2aad20Sopenharmony_ci	 * IP[46] and TCP header by using TCP_BPF_SYN_IP.
69297c2aad20Sopenharmony_ci	 *
69307c2aad20Sopenharmony_ci	 *      >0: Total number of bytes copied
69317c2aad20Sopenharmony_ci	 * -ENOSPC: Not enough space in optval. Only optlen number of
69327c2aad20Sopenharmony_ci	 *          bytes is copied.
69337c2aad20Sopenharmony_ci	 * -ENOENT: The SYN skb is not available now and the earlier SYN pkt
69347c2aad20Sopenharmony_ci	 *	    is not saved by setsockopt(TCP_SAVE_SYN).
69357c2aad20Sopenharmony_ci	 */
69367c2aad20Sopenharmony_ci	TCP_BPF_SYN		= 1005, /* Copy the TCP header */
69377c2aad20Sopenharmony_ci	TCP_BPF_SYN_IP		= 1006, /* Copy the IP[46] and TCP header */
69387c2aad20Sopenharmony_ci	TCP_BPF_SYN_MAC         = 1007, /* Copy the MAC, IP[46], and TCP header */
69397c2aad20Sopenharmony_ci};
69407c2aad20Sopenharmony_ci
69417c2aad20Sopenharmony_cienum {
69427c2aad20Sopenharmony_ci	BPF_LOAD_HDR_OPT_TCP_SYN = (1ULL << 0),
69437c2aad20Sopenharmony_ci};
69447c2aad20Sopenharmony_ci
69457c2aad20Sopenharmony_ci/* args[0] value during BPF_SOCK_OPS_HDR_OPT_LEN_CB and
69467c2aad20Sopenharmony_ci * BPF_SOCK_OPS_WRITE_HDR_OPT_CB.
69477c2aad20Sopenharmony_ci */
69487c2aad20Sopenharmony_cienum {
69497c2aad20Sopenharmony_ci	BPF_WRITE_HDR_TCP_CURRENT_MSS = 1,	/* Kernel is finding the
69507c2aad20Sopenharmony_ci						 * total option spaces
69517c2aad20Sopenharmony_ci						 * required for an established
69527c2aad20Sopenharmony_ci						 * sk in order to calculate the
69537c2aad20Sopenharmony_ci						 * MSS.  No skb is actually
69547c2aad20Sopenharmony_ci						 * sent.
69557c2aad20Sopenharmony_ci						 */
69567c2aad20Sopenharmony_ci	BPF_WRITE_HDR_TCP_SYNACK_COOKIE = 2,	/* Kernel is in syncookie mode
69577c2aad20Sopenharmony_ci						 * when sending a SYN.
69587c2aad20Sopenharmony_ci						 */
69597c2aad20Sopenharmony_ci};
69607c2aad20Sopenharmony_ci
69617c2aad20Sopenharmony_cistruct bpf_perf_event_value {
69627c2aad20Sopenharmony_ci	__u64 counter;
69637c2aad20Sopenharmony_ci	__u64 enabled;
69647c2aad20Sopenharmony_ci	__u64 running;
69657c2aad20Sopenharmony_ci};
69667c2aad20Sopenharmony_ci
69677c2aad20Sopenharmony_cienum {
69687c2aad20Sopenharmony_ci	BPF_DEVCG_ACC_MKNOD	= (1ULL << 0),
69697c2aad20Sopenharmony_ci	BPF_DEVCG_ACC_READ	= (1ULL << 1),
69707c2aad20Sopenharmony_ci	BPF_DEVCG_ACC_WRITE	= (1ULL << 2),
69717c2aad20Sopenharmony_ci};
69727c2aad20Sopenharmony_ci
69737c2aad20Sopenharmony_cienum {
69747c2aad20Sopenharmony_ci	BPF_DEVCG_DEV_BLOCK	= (1ULL << 0),
69757c2aad20Sopenharmony_ci	BPF_DEVCG_DEV_CHAR	= (1ULL << 1),
69767c2aad20Sopenharmony_ci};
69777c2aad20Sopenharmony_ci
69787c2aad20Sopenharmony_cistruct bpf_cgroup_dev_ctx {
69797c2aad20Sopenharmony_ci	/* access_type encoded as (BPF_DEVCG_ACC_* << 16) | BPF_DEVCG_DEV_* */
69807c2aad20Sopenharmony_ci	__u32 access_type;
69817c2aad20Sopenharmony_ci	__u32 major;
69827c2aad20Sopenharmony_ci	__u32 minor;
69837c2aad20Sopenharmony_ci};
69847c2aad20Sopenharmony_ci
69857c2aad20Sopenharmony_cistruct bpf_raw_tracepoint_args {
69867c2aad20Sopenharmony_ci	__u64 args[0];
69877c2aad20Sopenharmony_ci};
69887c2aad20Sopenharmony_ci
69897c2aad20Sopenharmony_ci/* DIRECT:  Skip the FIB rules and go to FIB table associated with device
69907c2aad20Sopenharmony_ci * OUTPUT:  Do lookup from egress perspective; default is ingress
69917c2aad20Sopenharmony_ci */
69927c2aad20Sopenharmony_cienum {
69937c2aad20Sopenharmony_ci	BPF_FIB_LOOKUP_DIRECT  = (1U << 0),
69947c2aad20Sopenharmony_ci	BPF_FIB_LOOKUP_OUTPUT  = (1U << 1),
69957c2aad20Sopenharmony_ci	BPF_FIB_LOOKUP_SKIP_NEIGH = (1U << 2),
69967c2aad20Sopenharmony_ci	BPF_FIB_LOOKUP_TBID    = (1U << 3),
69977c2aad20Sopenharmony_ci	BPF_FIB_LOOKUP_SRC     = (1U << 4),
69987c2aad20Sopenharmony_ci};
69997c2aad20Sopenharmony_ci
70007c2aad20Sopenharmony_cienum {
70017c2aad20Sopenharmony_ci	BPF_FIB_LKUP_RET_SUCCESS,      /* lookup successful */
70027c2aad20Sopenharmony_ci	BPF_FIB_LKUP_RET_BLACKHOLE,    /* dest is blackholed; can be dropped */
70037c2aad20Sopenharmony_ci	BPF_FIB_LKUP_RET_UNREACHABLE,  /* dest is unreachable; can be dropped */
70047c2aad20Sopenharmony_ci	BPF_FIB_LKUP_RET_PROHIBIT,     /* dest not allowed; can be dropped */
70057c2aad20Sopenharmony_ci	BPF_FIB_LKUP_RET_NOT_FWDED,    /* packet is not forwarded */
70067c2aad20Sopenharmony_ci	BPF_FIB_LKUP_RET_FWD_DISABLED, /* fwding is not enabled on ingress */
70077c2aad20Sopenharmony_ci	BPF_FIB_LKUP_RET_UNSUPP_LWT,   /* fwd requires encapsulation */
70087c2aad20Sopenharmony_ci	BPF_FIB_LKUP_RET_NO_NEIGH,     /* no neighbor entry for nh */
70097c2aad20Sopenharmony_ci	BPF_FIB_LKUP_RET_FRAG_NEEDED,  /* fragmentation required to fwd */
70107c2aad20Sopenharmony_ci	BPF_FIB_LKUP_RET_NO_SRC_ADDR,  /* failed to derive IP src addr */
70117c2aad20Sopenharmony_ci};
70127c2aad20Sopenharmony_ci
70137c2aad20Sopenharmony_cistruct bpf_fib_lookup {
70147c2aad20Sopenharmony_ci	/* input:  network family for lookup (AF_INET, AF_INET6)
70157c2aad20Sopenharmony_ci	 * output: network family of egress nexthop
70167c2aad20Sopenharmony_ci	 */
70177c2aad20Sopenharmony_ci	__u8	family;
70187c2aad20Sopenharmony_ci
70197c2aad20Sopenharmony_ci	/* set if lookup is to consider L4 data - e.g., FIB rules */
70207c2aad20Sopenharmony_ci	__u8	l4_protocol;
70217c2aad20Sopenharmony_ci	__be16	sport;
70227c2aad20Sopenharmony_ci	__be16	dport;
70237c2aad20Sopenharmony_ci
70247c2aad20Sopenharmony_ci	union {	/* used for MTU check */
70257c2aad20Sopenharmony_ci		/* input to lookup */
70267c2aad20Sopenharmony_ci		__u16	tot_len; /* L3 length from network hdr (iph->tot_len) */
70277c2aad20Sopenharmony_ci
70287c2aad20Sopenharmony_ci		/* output: MTU value */
70297c2aad20Sopenharmony_ci		__u16	mtu_result;
70307c2aad20Sopenharmony_ci	};
70317c2aad20Sopenharmony_ci	/* input: L3 device index for lookup
70327c2aad20Sopenharmony_ci	 * output: device index from FIB lookup
70337c2aad20Sopenharmony_ci	 */
70347c2aad20Sopenharmony_ci	__u32	ifindex;
70357c2aad20Sopenharmony_ci
70367c2aad20Sopenharmony_ci	union {
70377c2aad20Sopenharmony_ci		/* inputs to lookup */
70387c2aad20Sopenharmony_ci		__u8	tos;		/* AF_INET  */
70397c2aad20Sopenharmony_ci		__be32	flowinfo;	/* AF_INET6, flow_label + priority */
70407c2aad20Sopenharmony_ci
70417c2aad20Sopenharmony_ci		/* output: metric of fib result (IPv4/IPv6 only) */
70427c2aad20Sopenharmony_ci		__u32	rt_metric;
70437c2aad20Sopenharmony_ci	};
70447c2aad20Sopenharmony_ci
70457c2aad20Sopenharmony_ci	/* input: source address to consider for lookup
70467c2aad20Sopenharmony_ci	 * output: source address result from lookup
70477c2aad20Sopenharmony_ci	 */
70487c2aad20Sopenharmony_ci	union {
70497c2aad20Sopenharmony_ci		__be32		ipv4_src;
70507c2aad20Sopenharmony_ci		__u32		ipv6_src[4];  /* in6_addr; network order */
70517c2aad20Sopenharmony_ci	};
70527c2aad20Sopenharmony_ci
70537c2aad20Sopenharmony_ci	/* input to bpf_fib_lookup, ipv{4,6}_dst is destination address in
70547c2aad20Sopenharmony_ci	 * network header. output: bpf_fib_lookup sets to gateway address
70557c2aad20Sopenharmony_ci	 * if FIB lookup returns gateway route
70567c2aad20Sopenharmony_ci	 */
70577c2aad20Sopenharmony_ci	union {
70587c2aad20Sopenharmony_ci		__be32		ipv4_dst;
70597c2aad20Sopenharmony_ci		__u32		ipv6_dst[4];  /* in6_addr; network order */
70607c2aad20Sopenharmony_ci	};
70617c2aad20Sopenharmony_ci
70627c2aad20Sopenharmony_ci	union {
70637c2aad20Sopenharmony_ci		struct {
70647c2aad20Sopenharmony_ci			/* output */
70657c2aad20Sopenharmony_ci			__be16	h_vlan_proto;
70667c2aad20Sopenharmony_ci			__be16	h_vlan_TCI;
70677c2aad20Sopenharmony_ci		};
70687c2aad20Sopenharmony_ci		/* input: when accompanied with the
70697c2aad20Sopenharmony_ci		 * 'BPF_FIB_LOOKUP_DIRECT | BPF_FIB_LOOKUP_TBID` flags, a
70707c2aad20Sopenharmony_ci		 * specific routing table to use for the fib lookup.
70717c2aad20Sopenharmony_ci		 */
70727c2aad20Sopenharmony_ci		__u32	tbid;
70737c2aad20Sopenharmony_ci	};
70747c2aad20Sopenharmony_ci
70757c2aad20Sopenharmony_ci	__u8	smac[6];     /* ETH_ALEN */
70767c2aad20Sopenharmony_ci	__u8	dmac[6];     /* ETH_ALEN */
70777c2aad20Sopenharmony_ci};
70787c2aad20Sopenharmony_ci
70797c2aad20Sopenharmony_cistruct bpf_redir_neigh {
70807c2aad20Sopenharmony_ci	/* network family for lookup (AF_INET, AF_INET6) */
70817c2aad20Sopenharmony_ci	__u32 nh_family;
70827c2aad20Sopenharmony_ci	/* network address of nexthop; skips fib lookup to find gateway */
70837c2aad20Sopenharmony_ci	union {
70847c2aad20Sopenharmony_ci		__be32		ipv4_nh;
70857c2aad20Sopenharmony_ci		__u32		ipv6_nh[4];  /* in6_addr; network order */
70867c2aad20Sopenharmony_ci	};
70877c2aad20Sopenharmony_ci};
70887c2aad20Sopenharmony_ci
70897c2aad20Sopenharmony_ci/* bpf_check_mtu flags*/
70907c2aad20Sopenharmony_cienum  bpf_check_mtu_flags {
70917c2aad20Sopenharmony_ci	BPF_MTU_CHK_SEGS  = (1U << 0),
70927c2aad20Sopenharmony_ci};
70937c2aad20Sopenharmony_ci
70947c2aad20Sopenharmony_cienum bpf_check_mtu_ret {
70957c2aad20Sopenharmony_ci	BPF_MTU_CHK_RET_SUCCESS,      /* check and lookup successful */
70967c2aad20Sopenharmony_ci	BPF_MTU_CHK_RET_FRAG_NEEDED,  /* fragmentation required to fwd */
70977c2aad20Sopenharmony_ci	BPF_MTU_CHK_RET_SEGS_TOOBIG,  /* GSO re-segmentation needed to fwd */
70987c2aad20Sopenharmony_ci};
70997c2aad20Sopenharmony_ci
71007c2aad20Sopenharmony_cienum bpf_task_fd_type {
71017c2aad20Sopenharmony_ci	BPF_FD_TYPE_RAW_TRACEPOINT,	/* tp name */
71027c2aad20Sopenharmony_ci	BPF_FD_TYPE_TRACEPOINT,		/* tp name */
71037c2aad20Sopenharmony_ci	BPF_FD_TYPE_KPROBE,		/* (symbol + offset) or addr */
71047c2aad20Sopenharmony_ci	BPF_FD_TYPE_KRETPROBE,		/* (symbol + offset) or addr */
71057c2aad20Sopenharmony_ci	BPF_FD_TYPE_UPROBE,		/* filename + offset */
71067c2aad20Sopenharmony_ci	BPF_FD_TYPE_URETPROBE,		/* filename + offset */
71077c2aad20Sopenharmony_ci};
71087c2aad20Sopenharmony_ci
71097c2aad20Sopenharmony_cienum {
71107c2aad20Sopenharmony_ci	BPF_FLOW_DISSECTOR_F_PARSE_1ST_FRAG		= (1U << 0),
71117c2aad20Sopenharmony_ci	BPF_FLOW_DISSECTOR_F_STOP_AT_FLOW_LABEL		= (1U << 1),
71127c2aad20Sopenharmony_ci	BPF_FLOW_DISSECTOR_F_STOP_AT_ENCAP		= (1U << 2),
71137c2aad20Sopenharmony_ci};
71147c2aad20Sopenharmony_ci
71157c2aad20Sopenharmony_cistruct bpf_flow_keys {
71167c2aad20Sopenharmony_ci	__u16	nhoff;
71177c2aad20Sopenharmony_ci	__u16	thoff;
71187c2aad20Sopenharmony_ci	__u16	addr_proto;			/* ETH_P_* of valid addrs */
71197c2aad20Sopenharmony_ci	__u8	is_frag;
71207c2aad20Sopenharmony_ci	__u8	is_first_frag;
71217c2aad20Sopenharmony_ci	__u8	is_encap;
71227c2aad20Sopenharmony_ci	__u8	ip_proto;
71237c2aad20Sopenharmony_ci	__be16	n_proto;
71247c2aad20Sopenharmony_ci	__be16	sport;
71257c2aad20Sopenharmony_ci	__be16	dport;
71267c2aad20Sopenharmony_ci	union {
71277c2aad20Sopenharmony_ci		struct {
71287c2aad20Sopenharmony_ci			__be32	ipv4_src;
71297c2aad20Sopenharmony_ci			__be32	ipv4_dst;
71307c2aad20Sopenharmony_ci		};
71317c2aad20Sopenharmony_ci		struct {
71327c2aad20Sopenharmony_ci			__u32	ipv6_src[4];	/* in6_addr; network order */
71337c2aad20Sopenharmony_ci			__u32	ipv6_dst[4];	/* in6_addr; network order */
71347c2aad20Sopenharmony_ci		};
71357c2aad20Sopenharmony_ci	};
71367c2aad20Sopenharmony_ci	__u32	flags;
71377c2aad20Sopenharmony_ci	__be32	flow_label;
71387c2aad20Sopenharmony_ci};
71397c2aad20Sopenharmony_ci
71407c2aad20Sopenharmony_cistruct bpf_func_info {
71417c2aad20Sopenharmony_ci	__u32	insn_off;
71427c2aad20Sopenharmony_ci	__u32	type_id;
71437c2aad20Sopenharmony_ci};
71447c2aad20Sopenharmony_ci
71457c2aad20Sopenharmony_ci#define BPF_LINE_INFO_LINE_NUM(line_col)	((line_col) >> 10)
71467c2aad20Sopenharmony_ci#define BPF_LINE_INFO_LINE_COL(line_col)	((line_col) & 0x3ff)
71477c2aad20Sopenharmony_ci
71487c2aad20Sopenharmony_cistruct bpf_line_info {
71497c2aad20Sopenharmony_ci	__u32	insn_off;
71507c2aad20Sopenharmony_ci	__u32	file_name_off;
71517c2aad20Sopenharmony_ci	__u32	line_off;
71527c2aad20Sopenharmony_ci	__u32	line_col;
71537c2aad20Sopenharmony_ci};
71547c2aad20Sopenharmony_ci
71557c2aad20Sopenharmony_cistruct bpf_spin_lock {
71567c2aad20Sopenharmony_ci	__u32	val;
71577c2aad20Sopenharmony_ci};
71587c2aad20Sopenharmony_ci
71597c2aad20Sopenharmony_cistruct bpf_timer {
71607c2aad20Sopenharmony_ci	__u64 __opaque[2];
71617c2aad20Sopenharmony_ci} __attribute__((aligned(8)));
71627c2aad20Sopenharmony_ci
71637c2aad20Sopenharmony_cistruct bpf_dynptr {
71647c2aad20Sopenharmony_ci	__u64 __opaque[2];
71657c2aad20Sopenharmony_ci} __attribute__((aligned(8)));
71667c2aad20Sopenharmony_ci
71677c2aad20Sopenharmony_cistruct bpf_list_head {
71687c2aad20Sopenharmony_ci	__u64 __opaque[2];
71697c2aad20Sopenharmony_ci} __attribute__((aligned(8)));
71707c2aad20Sopenharmony_ci
71717c2aad20Sopenharmony_cistruct bpf_list_node {
71727c2aad20Sopenharmony_ci	__u64 __opaque[3];
71737c2aad20Sopenharmony_ci} __attribute__((aligned(8)));
71747c2aad20Sopenharmony_ci
71757c2aad20Sopenharmony_cistruct bpf_rb_root {
71767c2aad20Sopenharmony_ci	__u64 __opaque[2];
71777c2aad20Sopenharmony_ci} __attribute__((aligned(8)));
71787c2aad20Sopenharmony_ci
71797c2aad20Sopenharmony_cistruct bpf_rb_node {
71807c2aad20Sopenharmony_ci	__u64 __opaque[4];
71817c2aad20Sopenharmony_ci} __attribute__((aligned(8)));
71827c2aad20Sopenharmony_ci
71837c2aad20Sopenharmony_cistruct bpf_refcount {
71847c2aad20Sopenharmony_ci	__u32 __opaque[1];
71857c2aad20Sopenharmony_ci} __attribute__((aligned(4)));
71867c2aad20Sopenharmony_ci
71877c2aad20Sopenharmony_cistruct bpf_sysctl {
71887c2aad20Sopenharmony_ci	__u32	write;		/* Sysctl is being read (= 0) or written (= 1).
71897c2aad20Sopenharmony_ci				 * Allows 1,2,4-byte read, but no write.
71907c2aad20Sopenharmony_ci				 */
71917c2aad20Sopenharmony_ci	__u32	file_pos;	/* Sysctl file position to read from, write to.
71927c2aad20Sopenharmony_ci				 * Allows 1,2,4-byte read an 4-byte write.
71937c2aad20Sopenharmony_ci				 */
71947c2aad20Sopenharmony_ci};
71957c2aad20Sopenharmony_ci
71967c2aad20Sopenharmony_cistruct bpf_sockopt {
71977c2aad20Sopenharmony_ci	__bpf_md_ptr(struct bpf_sock *, sk);
71987c2aad20Sopenharmony_ci	__bpf_md_ptr(void *, optval);
71997c2aad20Sopenharmony_ci	__bpf_md_ptr(void *, optval_end);
72007c2aad20Sopenharmony_ci
72017c2aad20Sopenharmony_ci	__s32	level;
72027c2aad20Sopenharmony_ci	__s32	optname;
72037c2aad20Sopenharmony_ci	__s32	optlen;
72047c2aad20Sopenharmony_ci	__s32	retval;
72057c2aad20Sopenharmony_ci};
72067c2aad20Sopenharmony_ci
72077c2aad20Sopenharmony_cistruct bpf_pidns_info {
72087c2aad20Sopenharmony_ci	__u32 pid;
72097c2aad20Sopenharmony_ci	__u32 tgid;
72107c2aad20Sopenharmony_ci};
72117c2aad20Sopenharmony_ci
72127c2aad20Sopenharmony_ci/* User accessible data for SK_LOOKUP programs. Add new fields at the end. */
72137c2aad20Sopenharmony_cistruct bpf_sk_lookup {
72147c2aad20Sopenharmony_ci	union {
72157c2aad20Sopenharmony_ci		__bpf_md_ptr(struct bpf_sock *, sk); /* Selected socket */
72167c2aad20Sopenharmony_ci		__u64 cookie; /* Non-zero if socket was selected in PROG_TEST_RUN */
72177c2aad20Sopenharmony_ci	};
72187c2aad20Sopenharmony_ci
72197c2aad20Sopenharmony_ci	__u32 family;		/* Protocol family (AF_INET, AF_INET6) */
72207c2aad20Sopenharmony_ci	__u32 protocol;		/* IP protocol (IPPROTO_TCP, IPPROTO_UDP) */
72217c2aad20Sopenharmony_ci	__u32 remote_ip4;	/* Network byte order */
72227c2aad20Sopenharmony_ci	__u32 remote_ip6[4];	/* Network byte order */
72237c2aad20Sopenharmony_ci	__be16 remote_port;	/* Network byte order */
72247c2aad20Sopenharmony_ci	__u16 :16;		/* Zero padding */
72257c2aad20Sopenharmony_ci	__u32 local_ip4;	/* Network byte order */
72267c2aad20Sopenharmony_ci	__u32 local_ip6[4];	/* Network byte order */
72277c2aad20Sopenharmony_ci	__u32 local_port;	/* Host byte order */
72287c2aad20Sopenharmony_ci	__u32 ingress_ifindex;		/* The arriving interface. Determined by inet_iif. */
72297c2aad20Sopenharmony_ci};
72307c2aad20Sopenharmony_ci
72317c2aad20Sopenharmony_ci/*
72327c2aad20Sopenharmony_ci * struct btf_ptr is used for typed pointer representation; the
72337c2aad20Sopenharmony_ci * type id is used to render the pointer data as the appropriate type
72347c2aad20Sopenharmony_ci * via the bpf_snprintf_btf() helper described above.  A flags field -
72357c2aad20Sopenharmony_ci * potentially to specify additional details about the BTF pointer
72367c2aad20Sopenharmony_ci * (rather than its mode of display) - is included for future use.
72377c2aad20Sopenharmony_ci * Display flags - BTF_F_* - are passed to bpf_snprintf_btf separately.
72387c2aad20Sopenharmony_ci */
72397c2aad20Sopenharmony_cistruct btf_ptr {
72407c2aad20Sopenharmony_ci	void *ptr;
72417c2aad20Sopenharmony_ci	__u32 type_id;
72427c2aad20Sopenharmony_ci	__u32 flags;		/* BTF ptr flags; unused at present. */
72437c2aad20Sopenharmony_ci};
72447c2aad20Sopenharmony_ci
72457c2aad20Sopenharmony_ci/*
72467c2aad20Sopenharmony_ci * Flags to control bpf_snprintf_btf() behaviour.
72477c2aad20Sopenharmony_ci *     - BTF_F_COMPACT: no formatting around type information
72487c2aad20Sopenharmony_ci *     - BTF_F_NONAME: no struct/union member names/types
72497c2aad20Sopenharmony_ci *     - BTF_F_PTR_RAW: show raw (unobfuscated) pointer values;
72507c2aad20Sopenharmony_ci *       equivalent to %px.
72517c2aad20Sopenharmony_ci *     - BTF_F_ZERO: show zero-valued struct/union members; they
72527c2aad20Sopenharmony_ci *       are not displayed by default
72537c2aad20Sopenharmony_ci */
72547c2aad20Sopenharmony_cienum {
72557c2aad20Sopenharmony_ci	BTF_F_COMPACT	=	(1ULL << 0),
72567c2aad20Sopenharmony_ci	BTF_F_NONAME	=	(1ULL << 1),
72577c2aad20Sopenharmony_ci	BTF_F_PTR_RAW	=	(1ULL << 2),
72587c2aad20Sopenharmony_ci	BTF_F_ZERO	=	(1ULL << 3),
72597c2aad20Sopenharmony_ci};
72607c2aad20Sopenharmony_ci
72617c2aad20Sopenharmony_ci/* bpf_core_relo_kind encodes which aspect of captured field/type/enum value
72627c2aad20Sopenharmony_ci * has to be adjusted by relocations. It is emitted by llvm and passed to
72637c2aad20Sopenharmony_ci * libbpf and later to the kernel.
72647c2aad20Sopenharmony_ci */
72657c2aad20Sopenharmony_cienum bpf_core_relo_kind {
72667c2aad20Sopenharmony_ci	BPF_CORE_FIELD_BYTE_OFFSET = 0,      /* field byte offset */
72677c2aad20Sopenharmony_ci	BPF_CORE_FIELD_BYTE_SIZE = 1,        /* field size in bytes */
72687c2aad20Sopenharmony_ci	BPF_CORE_FIELD_EXISTS = 2,           /* field existence in target kernel */
72697c2aad20Sopenharmony_ci	BPF_CORE_FIELD_SIGNED = 3,           /* field signedness (0 - unsigned, 1 - signed) */
72707c2aad20Sopenharmony_ci	BPF_CORE_FIELD_LSHIFT_U64 = 4,       /* bitfield-specific left bitshift */
72717c2aad20Sopenharmony_ci	BPF_CORE_FIELD_RSHIFT_U64 = 5,       /* bitfield-specific right bitshift */
72727c2aad20Sopenharmony_ci	BPF_CORE_TYPE_ID_LOCAL = 6,          /* type ID in local BPF object */
72737c2aad20Sopenharmony_ci	BPF_CORE_TYPE_ID_TARGET = 7,         /* type ID in target kernel */
72747c2aad20Sopenharmony_ci	BPF_CORE_TYPE_EXISTS = 8,            /* type existence in target kernel */
72757c2aad20Sopenharmony_ci	BPF_CORE_TYPE_SIZE = 9,              /* type size in bytes */
72767c2aad20Sopenharmony_ci	BPF_CORE_ENUMVAL_EXISTS = 10,        /* enum value existence in target kernel */
72777c2aad20Sopenharmony_ci	BPF_CORE_ENUMVAL_VALUE = 11,         /* enum value integer value */
72787c2aad20Sopenharmony_ci	BPF_CORE_TYPE_MATCHES = 12,          /* type match in target kernel */
72797c2aad20Sopenharmony_ci};
72807c2aad20Sopenharmony_ci
72817c2aad20Sopenharmony_ci/*
72827c2aad20Sopenharmony_ci * "struct bpf_core_relo" is used to pass relocation data form LLVM to libbpf
72837c2aad20Sopenharmony_ci * and from libbpf to the kernel.
72847c2aad20Sopenharmony_ci *
72857c2aad20Sopenharmony_ci * CO-RE relocation captures the following data:
72867c2aad20Sopenharmony_ci * - insn_off - instruction offset (in bytes) within a BPF program that needs
72877c2aad20Sopenharmony_ci *   its insn->imm field to be relocated with actual field info;
72887c2aad20Sopenharmony_ci * - type_id - BTF type ID of the "root" (containing) entity of a relocatable
72897c2aad20Sopenharmony_ci *   type or field;
72907c2aad20Sopenharmony_ci * - access_str_off - offset into corresponding .BTF string section. String
72917c2aad20Sopenharmony_ci *   interpretation depends on specific relocation kind:
72927c2aad20Sopenharmony_ci *     - for field-based relocations, string encodes an accessed field using
72937c2aad20Sopenharmony_ci *       a sequence of field and array indices, separated by colon (:). It's
72947c2aad20Sopenharmony_ci *       conceptually very close to LLVM's getelementptr ([0]) instruction's
72957c2aad20Sopenharmony_ci *       arguments for identifying offset to a field.
72967c2aad20Sopenharmony_ci *     - for type-based relocations, strings is expected to be just "0";
72977c2aad20Sopenharmony_ci *     - for enum value-based relocations, string contains an index of enum
72987c2aad20Sopenharmony_ci *       value within its enum type;
72997c2aad20Sopenharmony_ci * - kind - one of enum bpf_core_relo_kind;
73007c2aad20Sopenharmony_ci *
73017c2aad20Sopenharmony_ci * Example:
73027c2aad20Sopenharmony_ci *   struct sample {
73037c2aad20Sopenharmony_ci *       int a;
73047c2aad20Sopenharmony_ci *       struct {
73057c2aad20Sopenharmony_ci *           int b[10];
73067c2aad20Sopenharmony_ci *       };
73077c2aad20Sopenharmony_ci *   };
73087c2aad20Sopenharmony_ci *
73097c2aad20Sopenharmony_ci *   struct sample *s = ...;
73107c2aad20Sopenharmony_ci *   int *x = &s->a;     // encoded as "0:0" (a is field #0)
73117c2aad20Sopenharmony_ci *   int *y = &s->b[5];  // encoded as "0:1:0:5" (anon struct is field #1,
73127c2aad20Sopenharmony_ci *                       // b is field #0 inside anon struct, accessing elem #5)
73137c2aad20Sopenharmony_ci *   int *z = &s[10]->b; // encoded as "10:1" (ptr is used as an array)
73147c2aad20Sopenharmony_ci *
73157c2aad20Sopenharmony_ci * type_id for all relocs in this example will capture BTF type id of
73167c2aad20Sopenharmony_ci * `struct sample`.
73177c2aad20Sopenharmony_ci *
73187c2aad20Sopenharmony_ci * Such relocation is emitted when using __builtin_preserve_access_index()
73197c2aad20Sopenharmony_ci * Clang built-in, passing expression that captures field address, e.g.:
73207c2aad20Sopenharmony_ci *
73217c2aad20Sopenharmony_ci * bpf_probe_read(&dst, sizeof(dst),
73227c2aad20Sopenharmony_ci *		  __builtin_preserve_access_index(&src->a.b.c));
73237c2aad20Sopenharmony_ci *
73247c2aad20Sopenharmony_ci * In this case Clang will emit field relocation recording necessary data to
73257c2aad20Sopenharmony_ci * be able to find offset of embedded `a.b.c` field within `src` struct.
73267c2aad20Sopenharmony_ci *
73277c2aad20Sopenharmony_ci * [0] https://llvm.org/docs/LangRef.html#getelementptr-instruction
73287c2aad20Sopenharmony_ci */
73297c2aad20Sopenharmony_cistruct bpf_core_relo {
73307c2aad20Sopenharmony_ci	__u32 insn_off;
73317c2aad20Sopenharmony_ci	__u32 type_id;
73327c2aad20Sopenharmony_ci	__u32 access_str_off;
73337c2aad20Sopenharmony_ci	enum bpf_core_relo_kind kind;
73347c2aad20Sopenharmony_ci};
73357c2aad20Sopenharmony_ci
73367c2aad20Sopenharmony_ci/*
73377c2aad20Sopenharmony_ci * Flags to control bpf_timer_start() behaviour.
73387c2aad20Sopenharmony_ci *     - BPF_F_TIMER_ABS: Timeout passed is absolute time, by default it is
73397c2aad20Sopenharmony_ci *       relative to current time.
73407c2aad20Sopenharmony_ci *     - BPF_F_TIMER_CPU_PIN: Timer will be pinned to the CPU of the caller.
73417c2aad20Sopenharmony_ci */
73427c2aad20Sopenharmony_cienum {
73437c2aad20Sopenharmony_ci	BPF_F_TIMER_ABS = (1ULL << 0),
73447c2aad20Sopenharmony_ci	BPF_F_TIMER_CPU_PIN = (1ULL << 1),
73457c2aad20Sopenharmony_ci};
73467c2aad20Sopenharmony_ci
73477c2aad20Sopenharmony_ci/* BPF numbers iterator state */
73487c2aad20Sopenharmony_cistruct bpf_iter_num {
73497c2aad20Sopenharmony_ci	/* opaque iterator state; having __u64 here allows to preserve correct
73507c2aad20Sopenharmony_ci	 * alignment requirements in vmlinux.h, generated from BTF
73517c2aad20Sopenharmony_ci	 */
73527c2aad20Sopenharmony_ci	__u64 __opaque[1];
73537c2aad20Sopenharmony_ci} __attribute__((aligned(8)));
73547c2aad20Sopenharmony_ci
73557c2aad20Sopenharmony_ci#endif /* _UAPI__LINUX_BPF_H__ */
7356