Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

bpf: expose prog id for cls_bpf and act_bpf

In order to be able to retrieve the attached programs from cls_bpf
and act_bpf, we need to expose the prog ids via netlink so that
an application can later on get an fd based on the id through the
BPF_PROG_GET_FD_BY_ID command, and dump related prog info via
BPF_OBJ_GET_INFO_BY_FD command for bpf(2).

Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
Signed-off-by: David S. Miller <davem@davemloft.net>

authored by

Daniel Borkmann and committed by
David S. Miller
e8628307 34cfb542

+8
+1
include/uapi/linux/pkt_cls.h
··· 369 369 TCA_BPF_FLAGS, 370 370 TCA_BPF_FLAGS_GEN, 371 371 TCA_BPF_TAG, 372 + TCA_BPF_ID, 372 373 __TCA_BPF_MAX, 373 374 }; 374 375
+1
include/uapi/linux/tc_act/tc_bpf.h
··· 28 28 TCA_ACT_BPF_NAME, 29 29 TCA_ACT_BPF_PAD, 30 30 TCA_ACT_BPF_TAG, 31 + TCA_ACT_BPF_ID, 31 32 __TCA_ACT_BPF_MAX, 32 33 }; 33 34 #define TCA_ACT_BPF_MAX (__TCA_ACT_BPF_MAX - 1)
+3
net/sched/act_bpf.c
··· 123 123 nla_put_string(skb, TCA_ACT_BPF_NAME, prog->bpf_name)) 124 124 return -EMSGSIZE; 125 125 126 + if (nla_put_u32(skb, TCA_ACT_BPF_ID, prog->filter->aux->id)) 127 + return -EMSGSIZE; 128 + 126 129 nla = nla_reserve(skb, TCA_ACT_BPF_TAG, sizeof(prog->filter->tag)); 127 130 if (nla == NULL) 128 131 return -EMSGSIZE;
+3
net/sched/cls_bpf.c
··· 566 566 nla_put_string(skb, TCA_BPF_NAME, prog->bpf_name)) 567 567 return -EMSGSIZE; 568 568 569 + if (nla_put_u32(skb, TCA_BPF_ID, prog->filter->aux->id)) 570 + return -EMSGSIZE; 571 + 569 572 nla = nla_reserve(skb, TCA_BPF_TAG, sizeof(prog->filter->tag)); 570 573 if (nla == NULL) 571 574 return -EMSGSIZE;