bpf: expose prog id for cls_bpf and act_bpf
authorDaniel Borkmann <daniel@iogearbox.net>
Wed, 21 Jun 2017 18:16:11 +0000 (20:16 +0200)
committerDavid S. Miller <davem@davemloft.net>
Wed, 21 Jun 2017 19:14:23 +0000 (15:14 -0400)
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>
include/uapi/linux/pkt_cls.h
include/uapi/linux/tc_act/tc_bpf.h
net/sched/act_bpf.c
net/sched/cls_bpf.c

index 2055783e6ee9c33cb8d6ffe12b0f1a61e13a3af3..d5e2bf68d0d4038ab51a3799636ac16c1f63cf4f 100644 (file)
@@ -369,6 +369,7 @@ enum {
        TCA_BPF_FLAGS,
        TCA_BPF_FLAGS_GEN,
        TCA_BPF_TAG,
+       TCA_BPF_ID,
        __TCA_BPF_MAX,
 };
 
index 975b50dc8d1d466bb60c6279de7ebde1d05bd54f..8dc2ac05eecf05650a3ac0751385134559aaeddf 100644 (file)
@@ -28,6 +28,7 @@ enum {
        TCA_ACT_BPF_NAME,
        TCA_ACT_BPF_PAD,
        TCA_ACT_BPF_TAG,
+       TCA_ACT_BPF_ID,
        __TCA_ACT_BPF_MAX,
 };
 #define TCA_ACT_BPF_MAX (__TCA_ACT_BPF_MAX - 1)
index d33947d6e9d017a05b704d233ec97f73abb2ab74..9afe1337cfd109a5dc92746cec2997e7a96390ee 100644 (file)
@@ -123,6 +123,9 @@ static int tcf_bpf_dump_ebpf_info(const struct tcf_bpf *prog,
            nla_put_string(skb, TCA_ACT_BPF_NAME, prog->bpf_name))
                return -EMSGSIZE;
 
+       if (nla_put_u32(skb, TCA_ACT_BPF_ID, prog->filter->aux->id))
+               return -EMSGSIZE;
+
        nla = nla_reserve(skb, TCA_ACT_BPF_TAG, sizeof(prog->filter->tag));
        if (nla == NULL)
                return -EMSGSIZE;
index be0cfdf489762cfbc28894214b1188ba3c1c5fda..f57bd531ba98e0661768e347a2e0b80d04affe30 100644 (file)
@@ -566,6 +566,9 @@ static int cls_bpf_dump_ebpf_info(const struct cls_bpf_prog *prog,
            nla_put_string(skb, TCA_BPF_NAME, prog->bpf_name))
                return -EMSGSIZE;
 
+       if (nla_put_u32(skb, TCA_BPF_ID, prog->filter->aux->id))
+               return -EMSGSIZE;
+
        nla = nla_reserve(skb, TCA_BPF_TAG, sizeof(prog->filter->tag));
        if (nla == NULL)
                return -EMSGSIZE;