@@ -11990,6 +11990,16 @@ bpf_sk_base_func_proto(enum bpf_func_id func_id, const struct bpf_prog *prog)
11990
11990
return func ;
11991
11991
}
11992
11992
11993
+ /**
11994
+ * bpf_skb_meta_pointer() - Gets a mutable pointer within the skb metadata area.
11995
+ * @skb: socket buffer carrying the metadata
11996
+ * @offset: offset into the metadata area, must be <= skb_metadata_len()
11997
+ */
11998
+ void * bpf_skb_meta_pointer (struct sk_buff * skb , u32 offset )
11999
+ {
12000
+ return skb_metadata_end (skb ) - skb_metadata_len (skb ) + offset ;
12001
+ }
12002
+
11993
12003
__bpf_kfunc_start_defs ();
11994
12004
__bpf_kfunc int bpf_dynptr_from_skb (struct __sk_buff * s , u64 flags ,
11995
12005
struct bpf_dynptr * ptr__uninit )
@@ -12007,6 +12017,42 @@ __bpf_kfunc int bpf_dynptr_from_skb(struct __sk_buff *s, u64 flags,
12007
12017
return 0 ;
12008
12018
}
12009
12019
12020
+ /**
12021
+ * bpf_dynptr_from_skb_meta() - Initialize a dynptr to the skb metadata area.
12022
+ * @skb_: socket buffer carrying the metadata
12023
+ * @flags: future use, must be zero
12024
+ * @ptr__uninit: dynptr to initialize
12025
+ *
12026
+ * Set up a dynptr for access to the metadata area earlier allocated from the
12027
+ * XDP context with bpf_xdp_adjust_meta(). Serves as an alternative to
12028
+ * &__sk_buff->data_meta.
12029
+ *
12030
+ * If passed @skb_ is a clone which shares the data with the original, the
12031
+ * dynptr will be read-only. This limitation may be lifted in the future.
12032
+ *
12033
+ * Return:
12034
+ * * %0 - dynptr ready to use
12035
+ * * %-EINVAL - invalid flags, dynptr set to null
12036
+ */
12037
+ __bpf_kfunc int bpf_dynptr_from_skb_meta (struct __sk_buff * skb_ , u64 flags ,
12038
+ struct bpf_dynptr * ptr__uninit )
12039
+ {
12040
+ struct bpf_dynptr_kern * ptr = (struct bpf_dynptr_kern * )ptr__uninit ;
12041
+ struct sk_buff * skb = (struct sk_buff * )skb_ ;
12042
+
12043
+ if (flags ) {
12044
+ bpf_dynptr_set_null (ptr );
12045
+ return - EINVAL ;
12046
+ }
12047
+
12048
+ bpf_dynptr_init (ptr , skb , BPF_DYNPTR_TYPE_SKB_META , 0 , skb_metadata_len (skb ));
12049
+
12050
+ if (skb_cloned (skb ))
12051
+ bpf_dynptr_set_rdonly (ptr );
12052
+
12053
+ return 0 ;
12054
+ }
12055
+
12010
12056
__bpf_kfunc int bpf_dynptr_from_xdp (struct xdp_md * x , u64 flags ,
12011
12057
struct bpf_dynptr * ptr__uninit )
12012
12058
{
@@ -12181,6 +12227,10 @@ BTF_KFUNCS_START(bpf_kfunc_check_set_skb)
12181
12227
BTF_ID_FLAGS (func , bpf_dynptr_from_skb , KF_TRUSTED_ARGS )
12182
12228
BTF_KFUNCS_END (bpf_kfunc_check_set_skb )
12183
12229
12230
+ BTF_KFUNCS_START (bpf_kfunc_check_set_skb_meta )
12231
+ BTF_ID_FLAGS (func , bpf_dynptr_from_skb_meta , KF_TRUSTED_ARGS )
12232
+ BTF_KFUNCS_END (bpf_kfunc_check_set_skb_meta )
12233
+
12184
12234
BTF_KFUNCS_START (bpf_kfunc_check_set_xdp )
12185
12235
BTF_ID_FLAGS (func , bpf_dynptr_from_xdp )
12186
12236
BTF_KFUNCS_END (bpf_kfunc_check_set_xdp )
@@ -12202,6 +12252,11 @@ static const struct btf_kfunc_id_set bpf_kfunc_set_skb = {
12202
12252
.set = & bpf_kfunc_check_set_skb ,
12203
12253
};
12204
12254
12255
+ static const struct btf_kfunc_id_set bpf_kfunc_set_skb_meta = {
12256
+ .owner = THIS_MODULE ,
12257
+ .set = & bpf_kfunc_check_set_skb_meta ,
12258
+ };
12259
+
12205
12260
static const struct btf_kfunc_id_set bpf_kfunc_set_xdp = {
12206
12261
.owner = THIS_MODULE ,
12207
12262
.set = & bpf_kfunc_check_set_xdp ,
@@ -12237,6 +12292,8 @@ static int __init bpf_kfunc_init(void)
12237
12292
ret = ret ?: register_btf_kfunc_id_set (BPF_PROG_TYPE_LWT_SEG6LOCAL , & bpf_kfunc_set_skb );
12238
12293
ret = ret ?: register_btf_kfunc_id_set (BPF_PROG_TYPE_NETFILTER , & bpf_kfunc_set_skb );
12239
12294
ret = ret ?: register_btf_kfunc_id_set (BPF_PROG_TYPE_TRACING , & bpf_kfunc_set_skb );
12295
+ ret = ret ?: register_btf_kfunc_id_set (BPF_PROG_TYPE_SCHED_CLS , & bpf_kfunc_set_skb_meta );
12296
+ ret = ret ?: register_btf_kfunc_id_set (BPF_PROG_TYPE_SCHED_ACT , & bpf_kfunc_set_skb_meta );
12240
12297
ret = ret ?: register_btf_kfunc_id_set (BPF_PROG_TYPE_XDP , & bpf_kfunc_set_xdp );
12241
12298
ret = ret ?: register_btf_kfunc_id_set (BPF_PROG_TYPE_CGROUP_SOCK_ADDR ,
12242
12299
& bpf_kfunc_set_sock_addr );
0 commit comments