Skip to content

Commit 15efd46

Browse files
committed
sync with latest libbpf repo
sync with libbpf v0.2.0 Signed-off-by: Yonghong Song <[email protected]>
1 parent a1a1775 commit 15efd46

File tree

5 files changed

+123
-21
lines changed

5 files changed

+123
-21
lines changed

docs/kernel-versions.md

+3
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,8 @@ Alphabetical order
199199
Helper | Kernel version | License | Commit |
200200
-------|----------------|---------|--------|
201201
`BPF_FUNC_bind()` | 4.17 | | [`d74bad4e74ee`](https://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/commit/?id=d74bad4e74ee373787a9ae24197c17b7cdc428d5) |
202+
`BPF_FUNC_bpf_per_cpu_ptr()` | 5.10 | | [`eaa6bcb71ef6`](https://github.com/torvalds/linux/commit/eaa6bcb71ef6ed3dc18fc525ee7e293b06b4882b) |
203+
`BPF_FUNC_bpf_this_cpu_ptr()` | 5.10 | | [`63d9b80dcf2c`](https://github.com/torvalds/linux/commit/63d9b80dcf2c67bc5ade61cbbaa09d7af21f43f1) |
202204
`BPF_FUNC_clone_redirect()` | 4.2 | | [`3896d655f4d4`](https://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/commit/?id=3896d655f4d491c67d669a15f275a39f713410f8)
203205
`BPF_FUNC_copy_from_user()` | 5.10 | | [`07be4c4a3e7a`](https://git.kernel.org/pub/scm/linux/kernel/git/netdev/net-next.git/commit?id=07be4c4a3e7a0db148e44b16c5190e753d1c8569)
204206
`BPF_FUNC_csum_diff()` | 4.6 | | [`7d672345ed29`](https://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/commit/?id=7d672345ed295b1356a5d9f7111da1d1d7d65867)
@@ -272,6 +274,7 @@ Helper | Kernel version | License | Commit |
272274
`BPF_FUNC_redirect()` | 4.4 | | [`27b29f63058d`](https://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/commit/?id=27b29f63058d26c6c1742f1993338280d5a41dc6)
273275
`BPF_FUNC_redirect_map()` | 4.14 | | [`97f91a7cf04f`](https://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/commit/?id=97f91a7cf04ff605845c20948b8a80e54cbd3376)
274276
`BPF_FUNC_redirect_neigh()` | 5.10 | | [`b4ab31414970`](https://git.kernel.org/pub/scm/linux/kernel/git/netdev/net-next.git/commit/?id=b4ab31414970a7a03a5d55d75083f2c101a30592)
277+
`BPF_FUNC_redirect_peer()` | 5.10 | | [`9aa1206e8f48`](https://github.com/torvalds/linux/commit/9aa1206e8f48222f35a0c809f33b2f4aaa1e2661)
275278
`BPF_FUNC_reserve_hdr_opt()` | 5.10 | | [`0813a841566f`](https://git.kernel.org/pub/scm/linux/kernel/git/netdev/net-next.git/commit?id=0813a841566f0962a5551be7749b43c45f0022a0)
276279
`BPF_FUNC_ringbuf_discard()` | 5.8 | | [`457f44363a88`](https://github.com/torvalds/linux/commit/457f44363a8894135c85b7a9afd2bd8196db24ab)
277280
`BPF_FUNC_ringbuf_output()` | 5.8 | | [`457f44363a88`](https://github.com/torvalds/linux/commit/457f44363a8894135c85b7a9afd2bd8196db24ab)

src/cc/compat/linux/virtual_bpf.h

+105-15
Original file line numberDiff line numberDiff line change
@@ -357,18 +357,36 @@ enum bpf_link_type {
357357
#define BPF_F_SLEEPABLE (1U << 4)
358358

359359
/* When BPF ldimm64's insn[0].src_reg != 0 then this can have
360-
* two extensions:
361-
*
362-
* insn[0].src_reg: BPF_PSEUDO_MAP_FD BPF_PSEUDO_MAP_VALUE
363-
* insn[0].imm: map fd map fd
364-
* insn[1].imm: 0 offset into value
365-
* insn[0].off: 0 0
366-
* insn[1].off: 0 0
367-
* ldimm64 rewrite: address of map address of map[0]+offset
368-
* verifier type: CONST_PTR_TO_MAP PTR_TO_MAP_VALUE
360+
* the following extensions:
361+
*
362+
* insn[0].src_reg: BPF_PSEUDO_MAP_FD
363+
* insn[0].imm: map fd
364+
* insn[1].imm: 0
365+
* insn[0].off: 0
366+
* insn[1].off: 0
367+
* ldimm64 rewrite: address of map
368+
* verifier type: CONST_PTR_TO_MAP
369369
*/
370370
#define BPF_PSEUDO_MAP_FD 1
371+
/* insn[0].src_reg: BPF_PSEUDO_MAP_VALUE
372+
* insn[0].imm: map fd
373+
* insn[1].imm: offset into value
374+
* insn[0].off: 0
375+
* insn[1].off: 0
376+
* ldimm64 rewrite: address of map[0]+offset
377+
* verifier type: PTR_TO_MAP_VALUE
378+
*/
371379
#define BPF_PSEUDO_MAP_VALUE 2
380+
/* insn[0].src_reg: BPF_PSEUDO_BTF_ID
381+
* insn[0].imm: kernel btd id of VAR
382+
* insn[1].imm: 0
383+
* insn[0].off: 0
384+
* insn[1].off: 0
385+
* ldimm64 rewrite: address of the kernel variable
386+
* verifier type: PTR_TO_BTF_ID or PTR_TO_MEM, depending on whether the var
387+
* is struct/union.
388+
*/
389+
#define BPF_PSEUDO_BTF_ID 3
372390

373391
/* when bpf_call->src_reg == BPF_PSEUDO_CALL, bpf_call->imm == pc-relative
374392
* offset to another bpf function
@@ -415,6 +433,12 @@ enum {
415433

416434
/* Enable memory-mapping BPF map */
417435
BPF_F_MMAPABLE = (1U << 10),
436+
437+
/* Share perf_event among processes */
438+
BPF_F_PRESERVE_ELEMS = (1U << 11),
439+
440+
/* Create a map that is suitable to be an inner map with dynamic max entries */
441+
BPF_F_INNER_MAP = (1U << 12),
418442
};
419443

420444
/* Flags for BPF_PROG_QUERY. */
@@ -1678,7 +1702,7 @@ union bpf_attr {
16781702
* **TCP_CONGESTION**, **TCP_BPF_IW**,
16791703
* **TCP_BPF_SNDCWND_CLAMP**, **TCP_SAVE_SYN**,
16801704
* **TCP_KEEPIDLE**, **TCP_KEEPINTVL**, **TCP_KEEPCNT**,
1681-
* **TCP_SYNCNT**, **TCP_USER_TIMEOUT**.
1705+
* **TCP_SYNCNT**, **TCP_USER_TIMEOUT**, **TCP_NOTSENT_LOWAT**.
16821706
* * **IPPROTO_IP**, which supports *optname* **IP_TOS**.
16831707
* * **IPPROTO_IPV6**, which supports *optname* **IPV6_TCLASS**.
16841708
* Return
@@ -2233,7 +2257,7 @@ union bpf_attr {
22332257
* Description
22342258
* This helper is used in programs implementing policies at the
22352259
* skb socket level. If the sk_buff *skb* is allowed to pass (i.e.
2236-
* if the verdeict eBPF program returns **SK_PASS**), redirect it
2260+
* if the verdict eBPF program returns **SK_PASS**), redirect it
22372261
* to the socket referenced by *map* (of type
22382262
* **BPF_MAP_TYPE_SOCKHASH**) using hash *key*. Both ingress and
22392263
* egress interfaces can be used for redirection. The
@@ -3654,15 +3678,68 @@ union bpf_attr {
36543678
* Return
36553679
* The id is returned or 0 in case the id could not be retrieved.
36563680
*
3657-
* long bpf_redirect_neigh(u32 ifindex, u64 flags)
3681+
* long bpf_redirect_neigh(u32 ifindex, struct bpf_redir_neigh *params, int plen, u64 flags)
36583682
* Description
36593683
* Redirect the packet to another net device of index *ifindex*
36603684
* and fill in L2 addresses from neighboring subsystem. This helper
36613685
* is somewhat similar to **bpf_redirect**\ (), except that it
3662-
* fills in e.g. MAC addresses based on the L3 information from
3663-
* the packet. This helper is supported for IPv4 and IPv6 protocols.
3686+
* populates L2 addresses as well, meaning, internally, the helper
3687+
* relies on the neighbor lookup for the L2 address of the nexthop.
3688+
*
3689+
* The helper will perform a FIB lookup based on the skb's
3690+
* networking header to get the address of the next hop, unless
3691+
* this is supplied by the caller in the *params* argument. The
3692+
* *plen* argument indicates the len of *params* and should be set
3693+
* to 0 if *params* is NULL.
3694+
*
3695+
* The *flags* argument is reserved and must be 0. The helper is
3696+
* currently only supported for tc BPF program types, and enabled
3697+
* for IPv4 and IPv6 protocols.
3698+
* Return
3699+
* The helper returns **TC_ACT_REDIRECT** on success or
3700+
* **TC_ACT_SHOT** on error.
3701+
*
3702+
* void *bpf_per_cpu_ptr(const void *percpu_ptr, u32 cpu)
3703+
* Description
3704+
* Take a pointer to a percpu ksym, *percpu_ptr*, and return a
3705+
* pointer to the percpu kernel variable on *cpu*. A ksym is an
3706+
* extern variable decorated with '__ksym'. For ksym, there is a
3707+
* global var (either static or global) defined of the same name
3708+
* in the kernel. The ksym is percpu if the global var is percpu.
3709+
* The returned pointer points to the global percpu var on *cpu*.
3710+
*
3711+
* bpf_per_cpu_ptr() has the same semantic as per_cpu_ptr() in the
3712+
* kernel, except that bpf_per_cpu_ptr() may return NULL. This
3713+
* happens if *cpu* is larger than nr_cpu_ids. The caller of
3714+
* bpf_per_cpu_ptr() must check the returned value.
3715+
* Return
3716+
* A pointer pointing to the kernel percpu variable on *cpu*, or
3717+
* NULL, if *cpu* is invalid.
3718+
*
3719+
* void *bpf_this_cpu_ptr(const void *percpu_ptr)
3720+
* Description
3721+
* Take a pointer to a percpu ksym, *percpu_ptr*, and return a
3722+
* pointer to the percpu kernel variable on this cpu. See the
3723+
* description of 'ksym' in **bpf_per_cpu_ptr**\ ().
3724+
*
3725+
* bpf_this_cpu_ptr() has the same semantic as this_cpu_ptr() in
3726+
* the kernel. Different from **bpf_per_cpu_ptr**\ (), it would
3727+
* never return NULL.
3728+
* Return
3729+
* A pointer pointing to the kernel percpu variable on this cpu.
3730+
*
3731+
* long bpf_redirect_peer(u32 ifindex, u64 flags)
3732+
* Description
3733+
* Redirect the packet to another net device of index *ifindex*.
3734+
* This helper is somewhat similar to **bpf_redirect**\ (), except
3735+
* that the redirection happens to the *ifindex*' peer device and
3736+
* the netns switch takes place from ingress to ingress without
3737+
* going through the CPU's backlog queue.
3738+
*
36643739
* The *flags* argument is reserved and must be 0. The helper is
3665-
* currently only supported for tc BPF program types.
3740+
* currently only supported for tc BPF program types at the ingress
3741+
* hook and for veth device types. The peer device must reside in a
3742+
* different network namespace.
36663743
* Return
36673744
* The helper returns **TC_ACT_REDIRECT** on success or
36683745
* **TC_ACT_SHOT** on error.
@@ -3821,6 +3898,9 @@ union bpf_attr {
38213898
FN(seq_printf_btf), \
38223899
FN(skb_cgroup_classid), \
38233900
FN(redirect_neigh), \
3901+
FN(bpf_per_cpu_ptr), \
3902+
FN(bpf_this_cpu_ptr), \
3903+
FN(redirect_peer), \
38243904
/* */
38253905

38263906
/* integer value in 'imm' field of BPF_CALL instruction selects which helper
@@ -4831,6 +4911,16 @@ struct bpf_fib_lookup {
48314911
__u8 dmac[6]; /* ETH_ALEN */
48324912
};
48334913

4914+
struct bpf_redir_neigh {
4915+
/* network family for lookup (AF_INET, AF_INET6) */
4916+
__u32 nh_family;
4917+
/* network address of nexthop; skips fib lookup to find gateway */
4918+
union {
4919+
__be32 ipv4_nh;
4920+
__u32 ipv6_nh[4]; /* in6_addr; network order */
4921+
};
4922+
};
4923+
48344924
enum bpf_task_fd_type {
48354925
BPF_FD_TYPE_RAW_TRACEPOINT, /* tp name */
48364926
BPF_FD_TYPE_TRACEPOINT, /* tp name */

src/cc/export/helpers.h

+11-5
Original file line numberDiff line numberDiff line change
@@ -784,16 +784,22 @@ static long (*bpf_d_path)(struct path *path, char *buf, u32 sz) =
784784
static long (*bpf_copy_from_user)(void *dst, u32 size, const void *user_ptr) =
785785
(void *)BPF_FUNC_copy_from_user;
786786

787-
static long (*bpf_snprintf_btf)(char *str, __u32 str_size, struct btf_ptr *ptr,
788-
__u32 btf_ptr_size, __u64 flags) =
787+
static long (*bpf_snprintf_btf)(char *str, u32 str_size, struct btf_ptr *ptr,
788+
u32 btf_ptr_size, u64 flags) =
789789
(void *)BPF_FUNC_snprintf_btf;
790790
static long (*bpf_seq_printf_btf)(struct seq_file *m, struct btf_ptr *ptr,
791-
__u32 ptr_size, __u64 flags) =
791+
u32 ptr_size, u64 flags) =
792792
(void *)BPF_FUNC_seq_printf_btf;
793-
static __u64 (*bpf_skb_cgroup_classid)(struct __sk_buff *skb) =
793+
static u64 (*bpf_skb_cgroup_classid)(struct sk_buff *skb) =
794794
(void *)BPF_FUNC_skb_cgroup_classid;
795-
static long (*bpf_redirect_neigh)(__u32 ifindex, __u64 flags) =
795+
static long (*bpf_redirect_neigh)(u32 ifindex, struct bpf_redir_neigh *params,
796+
u64 flags) =
796797
(void *)BPF_FUNC_redirect_neigh;
798+
static void * (*bpf_per_cpu_ptr)(const void *percpu_ptr, u32 cpu) =
799+
(void *)BPF_FUNC_bpf_per_cpu_ptr;
800+
static void * (*bpf_this_cpu_ptr)(const void *percpu_ptr) =
801+
(void *)BPF_FUNC_bpf_this_cpu_ptr;
802+
long (*bpf_redirect_peer)(u32 ifindex, u64 flags) = (void *)BPF_FUNC_redirect_peer;
797803

798804
/* llvm builtin functions that eBPF C program may use to
799805
* emit BPF_LD_ABS and BPF_LD_IND instructions

src/cc/libbpf.c

+3
Original file line numberDiff line numberDiff line change
@@ -251,6 +251,9 @@ static struct bpf_helper helpers[] = {
251251
{"seq_printf_btf", "5.10"},
252252
{"skb_cgroup_classid", "5.10"},
253253
{"redirect_neigh", "5.10"},
254+
{"per_cpu_ptr", "5.10"},
255+
{"this_cpu_ptr", "5.10"},
256+
{"redirect_peer", "5.10"},
254257
};
255258

256259
static uint64_t ptr_to_u64(void *ptr)

0 commit comments

Comments
 (0)