Blame SOURCES/bcc-0.20.0-sync-with-latest-libbpf-repo-3529.patch

afd259
From 0c12dfe26a362db181e6172cb56a39cd002a6892 Mon Sep 17 00:00:00 2001
afd259
From: yonghong-song <yhs@fb.com>
afd259
Date: Sun, 18 Jul 2021 15:05:34 -0700
afd259
Subject: [PATCH] sync with latest libbpf repo (#3529)
afd259
afd259
sync with latest libbpf repo which is upto commit
afd259
  21f90f61b084 sync: latest libbpf changes from kernel
afd259
afd259
Signed-off-by: Yonghong Song <yhs@fb.com>
afd259
---
afd259
 docs/kernel-versions.md           |   8 ++
afd259
 introspection/bps.c               |   1 +
afd259
 src/cc/compat/linux/virtual_bpf.h | 167 ++++++++++++++++++++++++++++--
afd259
 src/cc/export/helpers.h           |  17 +++
afd259
 src/cc/libbpf.c                   |   8 ++
afd259
 5 files changed, 190 insertions(+), 11 deletions(-)
afd259
afd259
diff --git a/docs/kernel-versions.md b/docs/kernel-versions.md
afd259
index 9192aa43..33318624 100644
afd259
--- a/docs/kernel-versions.md
afd259
+++ b/docs/kernel-versions.md
afd259
@@ -208,6 +208,7 @@ Helper | Kernel version | License | Commit |
afd259
 -------|----------------|---------|--------|
afd259
 `BPF_FUNC_bind()` | 4.17 |  | [`d74bad4e74ee`](https://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/commit/?id=d74bad4e74ee373787a9ae24197c17b7cdc428d5) |
afd259
 `BPF_FUNC_bprm_opts_set()` | 5.11 |  | [`3f6719c7b62f`](https://github.com/torvalds/linux/commit/3f6719c7b62f0327c9091e26d0da10e65668229e)
afd259
+`BPF_FUNC_btf_find_by_name_kind()` | 5.14 |  | [`3d78417b60fb`](https://github.com/torvalds/linux/commit/3d78417b60fba249cc555468cb72d96f5cde2964)
afd259
 `BPF_FUNC_check_mtu()` | 5.12 |  | [`34b2021cc616`](https://github.com/torvalds/linux/commit/34b2021cc61642d61c3cf943d9e71925b827941b)
afd259
 `BPF_FUNC_clone_redirect()` | 4.2 |  | [`3896d655f4d4`](https://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/commit/?id=3896d655f4d491c67d669a15f275a39f713410f8)
afd259
 `BPF_FUNC_copy_from_user()` | 5.10 |  | [`07be4c4a3e7a`](https://git.kernel.org/pub/scm/linux/kernel/git/netdev/net-next.git/commit?id=07be4c4a3e7a0db148e44b16c5190e753d1c8569)
afd259
@@ -226,6 +227,7 @@ Helper | Kernel version | License | Commit |
afd259
 `BPF_FUNC_get_current_task()` | 4.8 | GPL | [`606274c5abd8`](https://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/commit/?id=606274c5abd8e245add01bc7145a8cbb92b69ba8)
afd259
 `BPF_FUNC_get_current_task_btf()` | 5.11 | GPL | [`3ca1032ab7ab`](https://github.com/torvalds/linux/commit/3ca1032ab7ab010eccb107aa515598788f7d93bb)
afd259
 `BPF_FUNC_get_current_uid_gid()` | 4.2 |  | [`ffeedafbf023`](https://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/commit/?id=ffeedafbf0236f03aeb2e8db273b3e5ae5f5bc89)
afd259
+`BPF_FUNC_get_func_ip()` | 5.15 |  | [`5d8b583d04ae`](https://git.kernel.org/pub/scm/linux/kernel/git/bpf/bpf-next.git/commit/?id=5d8b583d04aedb3bd5f6d227a334c210c7d735f9)
afd259
 `BPF_FUNC_get_hash_recalc()` | 4.8 |  | [`13c5c240f789`](https://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/commit/?id=13c5c240f789bbd2bcacb14a23771491485ae61f)
afd259
 `BPF_FUNC_get_listener_sock()` | 5.1 |  | [`dbafd7ddd623`](https://kernel.googlesource.com/pub/scm/linux/kernel/git/davem/net-next/+/dbafd7ddd62369b2f3926ab847cbf8fc40e800b7)
afd259
 `BPF_FUNC_get_local_storage()` | 4.19 |  | [`cd3394317653`](https://github.com/torvalds/linux/commit/cd3394317653837e2eb5c5d0904a8996102af9fc)
afd259
@@ -352,6 +354,8 @@ Helper | Kernel version | License | Commit |
afd259
 `BPF_FUNC_store_hdr_opt()` | 5.10 |  | [`0813a841566f`](https://git.kernel.org/pub/scm/linux/kernel/git/netdev/net-next.git/commit?id=0813a841566f0962a5551be7749b43c45f0022a0)
afd259
 `BPF_FUNC_strtol()` | 5.2 |  | [`d7a4cb9b6705`](https://kernel.googlesource.com/pub/scm/linux/kernel/git/davem/net-next/+/d7a4cb9b6705a89937d12c8158a35a3145dc967a)
afd259
 `BPF_FUNC_strtoul()` | 5.2 |  | [`d7a4cb9b6705`](https://kernel.googlesource.com/pub/scm/linux/kernel/git/davem/net-next/+/d7a4cb9b6705a89937d12c8158a35a3145dc967a)
afd259
+`BPF_FUNC_sys_bpf()` | 5.14 |  | [`79a7f8bdb159`](https://github.com/torvalds/linux/commit/79a7f8bdb159d9914b58740f3d31d602a6e4aca8)
afd259
+`BPF_FUNC_sys_close()` | 5.14 |  | [`3abea089246f`](https://github.com/torvalds/linux/commit/3abea089246f76c1517b054ddb5946f3f1dbd2c0)
afd259
 `BPF_FUNC_sysctl_get_current_value()` | 5.2 |  | [`1d11b3016cec`](https://kernel.googlesource.com/pub/scm/linux/kernel/git/davem/net-next/+/1d11b3016cec4ed9770b98e82a61708c8f4926e7)
afd259
 `BPF_FUNC_sysctl_get_name()` | 5.2 |  | [`808649fb787d`](https://kernel.googlesource.com/pub/scm/linux/kernel/git/davem/net-next/+/808649fb787d918a48a360a668ee4ee9023f0c11)
afd259
 `BPF_FUNC_sysctl_get_new_value()` | 5.2 |  | [`4e63acdff864`](https://kernel.googlesource.com/pub/scm/linux/kernel/git/davem/net-next/+/4e63acdff864654cee0ac5aaeda3913798ee78f6)
afd259
@@ -364,6 +368,10 @@ Helper | Kernel version | License | Commit |
afd259
 `BPF_FUNC_tcp_send_ack()` | 5.5 | | [`206057fe020a`](https://git.kernel.org/pub/scm/linux/kernel/git/bpf/bpf-next.git/commit/?id=206057fe020ac5c037d5e2dd6562a9bd216ec765)
afd259
 `BPF_FUNC_tcp_sock()` | 5.1 |  | [`655a51e536c0`](https://git.kernel.org/pub/scm/linux/kernel/git/bpf/bpf-next.git/commit/?id=655a51e536c09d15ffa3603b1b6fce2b45b85a1f)
afd259
 `BPF_FUNC_this_cpu_ptr()` | 5.10 |  | [`63d9b80dcf2c`](https://github.com/torvalds/linux/commit/63d9b80dcf2c67bc5ade61cbbaa09d7af21f43f1) |
afd259
+`BPF_FUNC_timer_init()` | 5.15 |  | [`b00628b1c7d5`](https://git.kernel.org/pub/scm/linux/kernel/git/bpf/bpf-next.git/commit/?id=b00628b1c7d595ae5b544e059c27b1f5828314b4)
afd259
+`BPF_FUNC_timer_set_callback()` | 5.15 |  | [`b00628b1c7d5`](https://git.kernel.org/pub/scm/linux/kernel/git/bpf/bpf-next.git/commit/?id=b00628b1c7d595ae5b544e059c27b1f5828314b4)
afd259
+`BPF_FUNC_timer_start()` | 5.15 |  | [`b00628b1c7d5`](https://git.kernel.org/pub/scm/linux/kernel/git/bpf/bpf-next.git/commit/?id=b00628b1c7d595ae5b544e059c27b1f5828314b4)
afd259
+`BPF_FUNC_timer_cancel()` | 5.15 |  | [`b00628b1c7d5`](https://git.kernel.org/pub/scm/linux/kernel/git/bpf/bpf-next.git/commit/?id=b00628b1c7d595ae5b544e059c27b1f5828314b4)
afd259
 `BPF_FUNC_trace_printk()` | 4.1 | GPL | [`9c959c863f82`](https://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/commit/?id=9c959c863f8217a2ff3d7c296e8223654d240569)
afd259
 `BPF_FUNC_xdp_adjust_head()` | 4.10 |  | [`17bedab27231`](https://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/commit/?id=17bedab2723145d17b14084430743549e6943d03)
afd259
 `BPF_FUNC_xdp_adjust_meta()` | 4.15 |  | [`de8f3a83b0a0`](https://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/commit/?id=de8f3a83b0a0fddb2cf56e7a718127e9619ea3da)
afd259
diff --git a/introspection/bps.c b/introspection/bps.c
afd259
index e92da3f6..25a88cbd 100644
afd259
--- a/introspection/bps.c
afd259
+++ b/introspection/bps.c
afd259
@@ -47,6 +47,7 @@ static const char * const prog_type_strings[] = {
afd259
   [BPF_PROG_TYPE_EXT] = "ext",
afd259
   [BPF_PROG_TYPE_LSM] = "lsm",
afd259
   [BPF_PROG_TYPE_SK_LOOKUP] = "sk_lookup",
afd259
+  [BPF_PROG_TYPE_SYSCALL] = "syscall",
afd259
 };
afd259
 
afd259
 static const char * const map_type_strings[] = {
afd259
diff --git a/src/cc/compat/linux/virtual_bpf.h b/src/cc/compat/linux/virtual_bpf.h
afd259
index 3490bc14..bf4bc3a6 100644
afd259
--- a/src/cc/compat/linux/virtual_bpf.h
afd259
+++ b/src/cc/compat/linux/virtual_bpf.h
afd259
@@ -325,9 +325,6 @@ union bpf_iter_link_info {
afd259
  *		**BPF_PROG_TYPE_SK_LOOKUP**
afd259
  *			*data_in* and *data_out* must be NULL.
afd259
  *
afd259
- *		**BPF_PROG_TYPE_XDP**
afd259
- *			*ctx_in* and *ctx_out* must be NULL.
afd259
- *
afd259
  *		**BPF_PROG_TYPE_RAW_TRACEPOINT**,
afd259
  *		**BPF_PROG_TYPE_RAW_TRACEPOINT_WRITABLE**
afd259
  *
afd259
@@ -528,6 +525,15 @@ union bpf_iter_link_info {
afd259
  *		Look up an element with the given *key* in the map referred to
afd259
  *		by the file descriptor *fd*, and if found, delete the element.
afd259
  *
afd259
+ *		For **BPF_MAP_TYPE_QUEUE** and **BPF_MAP_TYPE_STACK** map
afd259
+ *		types, the *flags* argument needs to be set to 0, but for other
afd259
+ *		map types, it may be specified as:
afd259
+ *
afd259
+ *		**BPF_F_LOCK**
afd259
+ *			Look up and delete the value of a spin-locked map
afd259
+ *			without returning the lock. This must be specified if
afd259
+ *			the elements contain a spinlock.
afd259
+ *
afd259
  *		The **BPF_MAP_TYPE_QUEUE** and **BPF_MAP_TYPE_STACK** map types
afd259
  *		implement this command as a "pop" operation, deleting the top
afd259
  *		element rather than one corresponding to *key*.
afd259
@@ -537,6 +543,10 @@ union bpf_iter_link_info {
afd259
  *		This command is only valid for the following map types:
afd259
  *		* **BPF_MAP_TYPE_QUEUE**
afd259
  *		* **BPF_MAP_TYPE_STACK**
afd259
+ *		* **BPF_MAP_TYPE_HASH**
afd259
+ *		* **BPF_MAP_TYPE_PERCPU_HASH**
afd259
+ *		* **BPF_MAP_TYPE_LRU_HASH**
afd259
+ *		* **BPF_MAP_TYPE_LRU_PERCPU_HASH**
afd259
  *
afd259
  *	Return
afd259
  *		Returns zero on success. On error, -1 is returned and *errno*
afd259
@@ -838,6 +848,7 @@ enum bpf_cmd {
afd259
 	BPF_PROG_ATTACH,
afd259
 	BPF_PROG_DETACH,
afd259
 	BPF_PROG_TEST_RUN,
afd259
+	BPF_PROG_RUN = BPF_PROG_TEST_RUN,
afd259
 	BPF_PROG_GET_NEXT_ID,
afd259
 	BPF_MAP_GET_NEXT_ID,
afd259
 	BPF_PROG_GET_FD_BY_ID,
afd259
@@ -938,6 +949,7 @@ enum bpf_prog_type {
afd259
 	BPF_PROG_TYPE_EXT,
afd259
 	BPF_PROG_TYPE_LSM,
afd259
 	BPF_PROG_TYPE_SK_LOOKUP,
afd259
+	BPF_PROG_TYPE_SYSCALL, /* a program that can execute syscalls */
afd259
 };
afd259
 
afd259
 enum bpf_attach_type {
afd259
@@ -980,6 +992,8 @@ enum bpf_attach_type {
afd259
 	BPF_SK_LOOKUP,
afd259
 	BPF_XDP,
afd259
 	BPF_SK_SKB_VERDICT,
afd259
+	BPF_SK_REUSEPORT_SELECT,
afd259
+	BPF_SK_REUSEPORT_SELECT_OR_MIGRATE,
afd259
 	__MAX_BPF_ATTACH_TYPE
afd259
 };
afd259
 
afd259
@@ -1098,8 +1112,8 @@ enum bpf_link_type {
afd259
 /* When BPF ldimm64's insn[0].src_reg != 0 then this can have
afd259
  * the following extensions:
afd259
  *
afd259
- * insn[0].src_reg:  BPF_PSEUDO_MAP_FD
afd259
- * insn[0].imm:      map fd
afd259
+ * insn[0].src_reg:  BPF_PSEUDO_MAP_[FD|IDX]
afd259
+ * insn[0].imm:      map fd or fd_idx
afd259
  * insn[1].imm:      0
afd259
  * insn[0].off:      0
afd259
  * insn[1].off:      0
afd259
@@ -1107,15 +1121,19 @@ enum bpf_link_type {
afd259
  * verifier type:    CONST_PTR_TO_MAP
afd259
  */
afd259
 #define BPF_PSEUDO_MAP_FD	1
afd259
-/* insn[0].src_reg:  BPF_PSEUDO_MAP_VALUE
afd259
- * insn[0].imm:      map fd
afd259
+#define BPF_PSEUDO_MAP_IDX	5
afd259
+
afd259
+/* insn[0].src_reg:  BPF_PSEUDO_MAP_[IDX_]VALUE
afd259
+ * insn[0].imm:      map fd or fd_idx
afd259
  * insn[1].imm:      offset into value
afd259
  * insn[0].off:      0
afd259
  * insn[1].off:      0
afd259
  * ldimm64 rewrite:  address of map[0]+offset
afd259
  * verifier type:    PTR_TO_MAP_VALUE
afd259
  */
afd259
-#define BPF_PSEUDO_MAP_VALUE	2
afd259
+#define BPF_PSEUDO_MAP_VALUE		2
afd259
+#define BPF_PSEUDO_MAP_IDX_VALUE	6
afd259
+
afd259
 /* insn[0].src_reg:  BPF_PSEUDO_BTF_ID
afd259
  * insn[0].imm:      kernel btd id of VAR
afd259
  * insn[1].imm:      0
afd259
@@ -1315,6 +1333,8 @@ union bpf_attr {
afd259
 			/* or valid module BTF object fd or 0 to attach to vmlinux */
afd259
 			__u32		attach_btf_obj_fd;
afd259
 		};
afd259
+		__u32		:32;		/* pad */
afd259
+		__aligned_u64	fd_array;	/* array of FDs */
afd259
 	};
afd259
 
afd259
 	struct { /* anonymous struct used by BPF_OBJ_* commands */
afd259
@@ -2535,8 +2555,12 @@ union bpf_attr {
afd259
  * 		The lower two bits of *flags* are used as the return code if
afd259
  * 		the map lookup fails. This is so that the return value can be
afd259
  * 		one of the XDP program return codes up to **XDP_TX**, as chosen
afd259
- * 		by the caller. Any higher bits in the *flags* argument must be
afd259
- * 		unset.
afd259
+ * 		by the caller. The higher bits of *flags* can be set to
afd259
+ * 		BPF_F_BROADCAST or BPF_F_EXCLUDE_INGRESS as defined below.
afd259
+ *
afd259
+ * 		With BPF_F_BROADCAST the packet will be broadcasted to all the
afd259
+ * 		interfaces in the map, with BPF_F_EXCLUDE_INGRESS the ingress
afd259
+ * 		interface will be excluded when do broadcasting.
afd259
  *
afd259
  * 		See also **bpf_redirect**\ (), which only supports redirecting
afd259
  * 		to an ifindex, but doesn't require a map to do so.
afd259
@@ -3223,7 +3247,7 @@ union bpf_attr {
afd259
  * long bpf_sk_select_reuseport(struct sk_reuseport_md *reuse, struct bpf_map *map, void *key, u64 flags)
afd259
  *	Description
afd259
  *		Select a **SO_REUSEPORT** socket from a
afd259
- *		**BPF_MAP_TYPE_REUSEPORT_ARRAY** *map*.
afd259
+ *		**BPF_MAP_TYPE_REUSEPORT_SOCKARRAY** *map*.
afd259
  *		It checks the selected socket is matching the incoming
afd259
  *		request in the socket buffer.
afd259
  *	Return
afd259
@@ -4736,6 +4760,94 @@ union bpf_attr {
afd259
  *		be zero-terminated except when **str_size** is 0.
afd259
  *
afd259
  *		Or **-EBUSY** if the per-CPU memory copy buffer is busy.
afd259
+ *
afd259
+ * long bpf_sys_bpf(u32 cmd, void *attr, u32 attr_size)
afd259
+ * 	Description
afd259
+ * 		Execute bpf syscall with given arguments.
afd259
+ * 	Return
afd259
+ * 		A syscall result.
afd259
+ *
afd259
+ * long bpf_btf_find_by_name_kind(char *name, int name_sz, u32 kind, int flags)
afd259
+ * 	Description
afd259
+ * 		Find BTF type with given name and kind in vmlinux BTF or in module's BTFs.
afd259
+ * 	Return
afd259
+ * 		Returns btf_id and btf_obj_fd in lower and upper 32 bits.
afd259
+ *
afd259
+ * long bpf_sys_close(u32 fd)
afd259
+ * 	Description
afd259
+ * 		Execute close syscall for given FD.
afd259
+ * 	Return
afd259
+ * 		A syscall result.
afd259
+ *
afd259
+ * long bpf_timer_init(struct bpf_timer *timer, struct bpf_map *map, u64 flags)
afd259
+ *	Description
afd259
+ *		Initialize the timer.
afd259
+ *		First 4 bits of *flags* specify clockid.
afd259
+ *		Only CLOCK_MONOTONIC, CLOCK_REALTIME, CLOCK_BOOTTIME are allowed.
afd259
+ *		All other bits of *flags* are reserved.
afd259
+ *		The verifier will reject the program if *timer* is not from
afd259
+ *		the same *map*.
afd259
+ *	Return
afd259
+ *		0 on success.
afd259
+ *		**-EBUSY** if *timer* is already initialized.
afd259
+ *		**-EINVAL** if invalid *flags* are passed.
afd259
+ *		**-EPERM** if *timer* is in a map that doesn't have any user references.
afd259
+ *		The user space should either hold a file descriptor to a map with timers
afd259
+ *		or pin such map in bpffs. When map is unpinned or file descriptor is
afd259
+ *		closed all timers in the map will be cancelled and freed.
afd259
+ *
afd259
+ * long bpf_timer_set_callback(struct bpf_timer *timer, void *callback_fn)
afd259
+ *	Description
afd259
+ *		Configure the timer to call *callback_fn* static function.
afd259
+ *	Return
afd259
+ *		0 on success.
afd259
+ *		**-EINVAL** if *timer* was not initialized with bpf_timer_init() earlier.
afd259
+ *		**-EPERM** if *timer* is in a map that doesn't have any user references.
afd259
+ *		The user space should either hold a file descriptor to a map with timers
afd259
+ *		or pin such map in bpffs. When map is unpinned or file descriptor is
afd259
+ *		closed all timers in the map will be cancelled and freed.
afd259
+ *
afd259
+ * long bpf_timer_start(struct bpf_timer *timer, u64 nsecs, u64 flags)
afd259
+ *	Description
afd259
+ *		Set timer expiration N nanoseconds from the current time. The
afd259
+ *		configured callback will be invoked in soft irq context on some cpu
afd259
+ *		and will not repeat unless another bpf_timer_start() is made.
afd259
+ *		In such case the next invocation can migrate to a different cpu.
afd259
+ *		Since struct bpf_timer is a field inside map element the map
afd259
+ *		owns the timer. The bpf_timer_set_callback() will increment refcnt
afd259
+ *		of BPF program to make sure that callback_fn code stays valid.
afd259
+ *		When user space reference to a map reaches zero all timers
afd259
+ *		in a map are cancelled and corresponding program's refcnts are
afd259
+ *		decremented. This is done to make sure that Ctrl-C of a user
afd259
+ *		process doesn't leave any timers running. If map is pinned in
afd259
+ *		bpffs the callback_fn can re-arm itself indefinitely.
afd259
+ *		bpf_map_update/delete_elem() helpers and user space sys_bpf commands
afd259
+ *		cancel and free the timer in the given map element.
afd259
+ *		The map can contain timers that invoke callback_fn-s from different
afd259
+ *		programs. The same callback_fn can serve different timers from
afd259
+ *		different maps if key/value layout matches across maps.
afd259
+ *		Every bpf_timer_set_callback() can have different callback_fn.
afd259
+ *
afd259
+ *	Return
afd259
+ *		0 on success.
afd259
+ *		**-EINVAL** if *timer* was not initialized with bpf_timer_init() earlier
afd259
+ *		or invalid *flags* are passed.
afd259
+ *
afd259
+ * long bpf_timer_cancel(struct bpf_timer *timer)
afd259
+ *	Description
afd259
+ *		Cancel the timer and wait for callback_fn to finish if it was running.
afd259
+ *	Return
afd259
+ *		0 if the timer was not active.
afd259
+ *		1 if the timer was active.
afd259
+ *		**-EINVAL** if *timer* was not initialized with bpf_timer_init() earlier.
afd259
+ *		**-EDEADLK** if callback_fn tried to call bpf_timer_cancel() on its
afd259
+ *		own timer which would have led to a deadlock otherwise.
afd259
+ *
afd259
+ * u64 bpf_get_func_ip(void *ctx)
afd259
+ * 	Description
afd259
+ * 		Get address of the traced function (for tracing and kprobe programs).
afd259
+ * 	Return
afd259
+ * 		Address of the traced function.
afd259
  */
afd259
 #define __BPF_FUNC_MAPPER(FN)		\
afd259
 	FN(unspec),			\
afd259
@@ -4904,6 +5016,14 @@ union bpf_attr {
afd259
 	FN(check_mtu),			\
afd259
 	FN(for_each_map_elem),		\
afd259
 	FN(snprintf),			\
afd259
+	FN(sys_bpf),			\
afd259
+	FN(btf_find_by_name_kind),	\
afd259
+	FN(sys_close),			\
afd259
+	FN(timer_init),			\
afd259
+	FN(timer_set_callback),		\
afd259
+	FN(timer_start),		\
afd259
+	FN(timer_cancel),		\
afd259
+	FN(get_func_ip),		\
afd259
 	/* */
afd259
 
afd259
 /* integer value in 'imm' field of BPF_CALL instruction selects which helper
afd259
@@ -5081,6 +5201,12 @@ enum {
afd259
 	BPF_F_BPRM_SECUREEXEC	= (1ULL << 0),
afd259
 };
afd259
 
afd259
+/* Flags for bpf_redirect_map helper */
afd259
+enum {
afd259
+	BPF_F_BROADCAST		= (1ULL << 3),
afd259
+	BPF_F_EXCLUDE_INGRESS	= (1ULL << 4),
afd259
+};
afd259
+
afd259
 #define __bpf_md_ptr(type, name)	\
afd259
 union {					\
afd259
 	type name;			\
afd259
@@ -5365,6 +5491,20 @@ struct sk_reuseport_md {
afd259
 	__u32 ip_protocol;	/* IP protocol. e.g. IPPROTO_TCP, IPPROTO_UDP */
afd259
 	__u32 bind_inany;	/* Is sock bound to an INANY address? */
afd259
 	__u32 hash;		/* A hash of the packet 4 tuples */
afd259
+	/* When reuse->migrating_sk is NULL, it is selecting a sk for the
afd259
+	 * new incoming connection request (e.g. selecting a listen sk for
afd259
+	 * the received SYN in the TCP case).  reuse->sk is one of the sk
afd259
+	 * in the reuseport group. The bpf prog can use reuse->sk to learn
afd259
+	 * the local listening ip/port without looking into the skb.
afd259
+	 *
afd259
+	 * When reuse->migrating_sk is not NULL, reuse->sk is closed and
afd259
+	 * reuse->migrating_sk is the socket that needs to be migrated
afd259
+	 * to another listening socket.  migrating_sk could be a fullsock
afd259
+	 * sk that is fully established or a reqsk that is in-the-middle
afd259
+	 * of 3-way handshake.
afd259
+	 */
afd259
+	__bpf_md_ptr(struct bpf_sock *, sk);
afd259
+	__bpf_md_ptr(struct bpf_sock *, migrating_sk);
afd259
 };
afd259
 
afd259
 #define BPF_TAG_SIZE	8
afd259
@@ -6010,6 +6150,11 @@ struct bpf_spin_lock {
afd259
 	__u32	val;
afd259
 };
afd259
 
afd259
+struct bpf_timer {
afd259
+	__u64 :64;
afd259
+	__u64 :64;
afd259
+} __attribute__((aligned(8)));
afd259
+
afd259
 struct bpf_sysctl {
afd259
 	__u32	write;		/* Sysctl is being read (= 0) or written (= 1).
afd259
 				 * Allows 1,2,4-byte read, but no write.
afd259
diff --git a/src/cc/export/helpers.h b/src/cc/export/helpers.h
afd259
index e9137f7f..a4e9b705 100644
afd259
--- a/src/cc/export/helpers.h
afd259
+++ b/src/cc/export/helpers.h
afd259
@@ -847,6 +847,23 @@ static long (*bpf_snprintf)(char *str, __u32 str_size, const char *fmt,
afd259
                             __u64 *data, __u32 data_len) =
afd259
   (void *)BPF_FUNC_snprintf;
afd259
 
afd259
+static long (*bpf_sys_bpf)(__u32 cmd, void *attr, __u32 attr_size) =
afd259
+  (void *)BPF_FUNC_sys_bpf;
afd259
+static long (*bpf_btf_find_by_name_kind)(char *name, int name_sz, __u32 kind, int flags) =
afd259
+  (void *)BPF_FUNC_btf_find_by_name_kind;
afd259
+static long (*bpf_sys_close)(__u32 fd) = (void *)BPF_FUNC_sys_close;
afd259
+
afd259
+struct bpf_timer;
afd259
+static long (*bpf_timer_init)(struct bpf_timer *timer, void *map, __u64 flags) =
afd259
+  (void *)BPF_FUNC_timer_init;
afd259
+static long (*bpf_timer_set_callback)(struct bpf_timer *timer, void *callback_fn) =
afd259
+  (void *)BPF_FUNC_timer_set_callback;
afd259
+static long (*bpf_timer_start)(struct bpf_timer *timer, __u64 nsecs, __u64 flags) =
afd259
+  (void *)BPF_FUNC_timer_start;
afd259
+static long (*bpf_timer_cancel)(struct bpf_timer *timer) = (void *)BPF_FUNC_timer_cancel;
afd259
+
afd259
+static __u64 (*bpf_get_func_ip)(void *ctx) = (void *)BPF_FUNC_get_func_ip;
afd259
+
afd259
 /* llvm builtin functions that eBPF C program may use to
afd259
  * emit BPF_LD_ABS and BPF_LD_IND instructions
afd259
  */
afd259
diff --git a/src/cc/libbpf.c b/src/cc/libbpf.c
afd259
index b83d68fd..f3608cfe 100644
afd259
--- a/src/cc/libbpf.c
afd259
+++ b/src/cc/libbpf.c
afd259
@@ -270,6 +270,14 @@ static struct bpf_helper helpers[] = {
afd259
   {"check_mtu", "5.12"},
afd259
   {"for_each_map_elem", "5.13"},
afd259
   {"snprintf", "5.13"},
afd259
+  {"sys_bpf", "5.14"},
afd259
+  {"btf_find_by_name_kind", "5.14"},
afd259
+  {"sys_close", "5.14"},
afd259
+  {"timer_init", "5.15"},
afd259
+  {"timer_set_callback", "5.15"},
afd259
+  {"timer_start", "5.15"},
afd259
+  {"timer_cancel", "5.15"},
afd259
+  {"get_func_ip", "5.15"},
afd259
 };
afd259
 
afd259
 static uint64_t ptr_to_u64(void *ptr)
afd259
-- 
afd259
2.31.1
afd259