@@ -11990,6 +11990,16 @@ bpf_sk_base_func_proto(enum bpf_func_id func_id, const struct bpf_prog *prog)
1199011990 return func ;
1199111991}
1199211992
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+
1199312003__bpf_kfunc_start_defs ();
1199412004__bpf_kfunc int bpf_dynptr_from_skb (struct __sk_buff * s , u64 flags ,
1199512005 struct bpf_dynptr * ptr__uninit )
@@ -12007,6 +12017,42 @@ __bpf_kfunc int bpf_dynptr_from_skb(struct __sk_buff *s, u64 flags,
1200712017 return 0 ;
1200812018}
1200912019
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+
1201012056__bpf_kfunc int bpf_dynptr_from_xdp (struct xdp_md * x , u64 flags ,
1201112057 struct bpf_dynptr * ptr__uninit )
1201212058{
@@ -12181,6 +12227,10 @@ BTF_KFUNCS_START(bpf_kfunc_check_set_skb)
1218112227BTF_ID_FLAGS (func , bpf_dynptr_from_skb , KF_TRUSTED_ARGS )
1218212228BTF_KFUNCS_END (bpf_kfunc_check_set_skb )
1218312229
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+
1218412234BTF_KFUNCS_START (bpf_kfunc_check_set_xdp )
1218512235BTF_ID_FLAGS (func , bpf_dynptr_from_xdp )
1218612236BTF_KFUNCS_END (bpf_kfunc_check_set_xdp )
@@ -12202,6 +12252,11 @@ static const struct btf_kfunc_id_set bpf_kfunc_set_skb = {
1220212252 .set = & bpf_kfunc_check_set_skb ,
1220312253};
1220412254
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+
1220512260static const struct btf_kfunc_id_set bpf_kfunc_set_xdp = {
1220612261 .owner = THIS_MODULE ,
1220712262 .set = & bpf_kfunc_check_set_xdp ,
@@ -12237,6 +12292,8 @@ static int __init bpf_kfunc_init(void)
1223712292 ret = ret ?: register_btf_kfunc_id_set (BPF_PROG_TYPE_LWT_SEG6LOCAL , & bpf_kfunc_set_skb );
1223812293 ret = ret ?: register_btf_kfunc_id_set (BPF_PROG_TYPE_NETFILTER , & bpf_kfunc_set_skb );
1223912294 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 );
1224012297 ret = ret ?: register_btf_kfunc_id_set (BPF_PROG_TYPE_XDP , & bpf_kfunc_set_xdp );
1224112298 ret = ret ?: register_btf_kfunc_id_set (BPF_PROG_TYPE_CGROUP_SOCK_ADDR ,
1224212299 & bpf_kfunc_set_sock_addr );
0 commit comments