Skip to content

Commit e862830

Browse files
borkmanndavem330
authored andcommitted
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>
1 parent 34cfb54 commit e862830

4 files changed

Lines changed: 8 additions & 0 deletions

File tree

‎include/uapi/linux/pkt_cls.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -369,6 +369,7 @@ enum {
369369
TCA_BPF_FLAGS,
370370
TCA_BPF_FLAGS_GEN,
371371
TCA_BPF_TAG,
372+
TCA_BPF_ID,
372373
__TCA_BPF_MAX,
373374
};
374375

‎include/uapi/linux/tc_act/tc_bpf.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ enum {
2828
TCA_ACT_BPF_NAME,
2929
TCA_ACT_BPF_PAD,
3030
TCA_ACT_BPF_TAG,
31+
TCA_ACT_BPF_ID,
3132
__TCA_ACT_BPF_MAX,
3233
};
3334
#define TCA_ACT_BPF_MAX (__TCA_ACT_BPF_MAX - 1)

‎net/sched/act_bpf.c‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,9 @@ static int tcf_bpf_dump_ebpf_info(const struct tcf_bpf *prog,
123123
nla_put_string(skb, TCA_ACT_BPF_NAME, prog->bpf_name))
124124
return -EMSGSIZE;
125125

126+
if (nla_put_u32(skb, TCA_ACT_BPF_ID, prog->filter->aux->id))
127+
return -EMSGSIZE;
128+
126129
nla = nla_reserve(skb, TCA_ACT_BPF_TAG, sizeof(prog->filter->tag));
127130
if (nla == NULL)
128131
return -EMSGSIZE;

‎net/sched/cls_bpf.c‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -566,6 +566,9 @@ static int cls_bpf_dump_ebpf_info(const struct cls_bpf_prog *prog,
566566
nla_put_string(skb, TCA_BPF_NAME, prog->bpf_name))
567567
return -EMSGSIZE;
568568

569+
if (nla_put_u32(skb, TCA_BPF_ID, prog->filter->aux->id))
570+
return -EMSGSIZE;
571+
569572
nla = nla_reserve(skb, TCA_BPF_TAG, sizeof(prog->filter->tag));
570573
if (nla == NULL)
571574
return -EMSGSIZE;

0 commit comments

Comments
 (0)