Skip to content

Commit

Permalink
Merge branch 'cls_bpf-next'
Browse files Browse the repository at this point in the history
Daniel Borkmann says:

====================
Minor cls_bpf updates

Some minor updates resp. follow-ups on cls_bpf, please see
individual patches for details. Will follow with the iproute2
patch after this series.
====================

Signed-off-by: David S. Miller <davem@davemloft.net>
  • Loading branch information
David S. Miller committed Sep 23, 2015
2 parents e1ffc0c + 5cf8ca0 commit 34ea90e
Showing 1 changed file with 16 additions and 15 deletions.
31 changes: 16 additions & 15 deletions net/sched/cls_bpf.c
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,8 @@ static int cls_bpf_exec_opcode(int code)
{
switch (code) {
case TC_ACT_OK:
case TC_ACT_RECLASSIFY:
case TC_ACT_SHOT:
case TC_ACT_PIPE:
case TC_ACT_STOLEN:
case TC_ACT_QUEUED:
case TC_ACT_REDIRECT:
case TC_ACT_UNSPEC:
return code;
Expand Down Expand Up @@ -265,8 +262,7 @@ static int cls_bpf_prog_from_ops(struct nlattr **tb, struct cls_bpf_prog *prog)
return 0;
}

static int cls_bpf_prog_from_efd(struct nlattr **tb, struct cls_bpf_prog *prog,
const struct tcf_proto *tp)
static int cls_bpf_prog_from_efd(struct nlattr **tb, struct cls_bpf_prog *prog)
{
struct bpf_prog *fp;
char *name = NULL;
Expand Down Expand Up @@ -308,22 +304,18 @@ static int cls_bpf_modify_existing(struct net *net, struct tcf_proto *tp,
{
bool is_bpf, is_ebpf, have_exts = false;
struct tcf_exts exts;
u32 classid;
int ret;

is_bpf = tb[TCA_BPF_OPS_LEN] && tb[TCA_BPF_OPS];
is_ebpf = tb[TCA_BPF_FD];

if ((!is_bpf && !is_ebpf) || (is_bpf && is_ebpf) ||
!tb[TCA_BPF_CLASSID])
if ((!is_bpf && !is_ebpf) || (is_bpf && is_ebpf))
return -EINVAL;

tcf_exts_init(&exts, TCA_BPF_ACT, TCA_BPF_POLICE);
ret = tcf_exts_validate(net, tp, tb, est, &exts, ovr);
if (ret < 0)
return ret;

classid = nla_get_u32(tb[TCA_BPF_CLASSID]);
if (tb[TCA_BPF_FLAGS]) {
u32 bpf_flags = nla_get_u32(tb[TCA_BPF_FLAGS]);

Expand All @@ -335,19 +327,21 @@ static int cls_bpf_modify_existing(struct net *net, struct tcf_proto *tp,
have_exts = bpf_flags & TCA_BPF_FLAG_ACT_DIRECT;
}

prog->res.classid = classid;
prog->exts_integrated = have_exts;

ret = is_bpf ? cls_bpf_prog_from_ops(tb, prog) :
cls_bpf_prog_from_efd(tb, prog, tp);
cls_bpf_prog_from_efd(tb, prog);
if (ret < 0) {
tcf_exts_destroy(&exts);
return ret;
}

tcf_bind_filter(tp, &prog->res, base);
tcf_exts_change(tp, &prog->exts, &exts);
if (tb[TCA_BPF_CLASSID]) {
prog->res.classid = nla_get_u32(tb[TCA_BPF_CLASSID]);
tcf_bind_filter(tp, &prog->res, base);
}

tcf_exts_change(tp, &prog->exts, &exts);
return 0;
}

Expand Down Expand Up @@ -468,6 +462,7 @@ static int cls_bpf_dump(struct net *net, struct tcf_proto *tp, unsigned long fh,
{
struct cls_bpf_prog *prog = (struct cls_bpf_prog *) fh;
struct nlattr *nest;
u32 bpf_flags = 0;
int ret;

if (prog == NULL)
Expand All @@ -479,7 +474,8 @@ static int cls_bpf_dump(struct net *net, struct tcf_proto *tp, unsigned long fh,
if (nest == NULL)
goto nla_put_failure;

if (nla_put_u32(skb, TCA_BPF_CLASSID, prog->res.classid))
if (prog->res.classid &&
nla_put_u32(skb, TCA_BPF_CLASSID, prog->res.classid))
goto nla_put_failure;

if (cls_bpf_is_ebpf(prog))
Expand All @@ -492,6 +488,11 @@ static int cls_bpf_dump(struct net *net, struct tcf_proto *tp, unsigned long fh,
if (tcf_exts_dump(skb, &prog->exts) < 0)
goto nla_put_failure;

if (prog->exts_integrated)
bpf_flags |= TCA_BPF_FLAG_ACT_DIRECT;
if (bpf_flags && nla_put_u32(skb, TCA_BPF_FLAGS, bpf_flags))
goto nla_put_failure;

nla_nest_end(skb, nest);

if (tcf_exts_dump_stats(skb, &prog->exts) < 0)
Expand Down

0 comments on commit 34ea90e

Please sign in to comment.