Merge branch 'cls_bpf-next'

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>
This commit is contained in:
David S. Miller 2015-09-23 14:29:02 -07:00
commit 34ea90ef72

View file

@ -65,11 +65,8 @@ static int cls_bpf_exec_opcode(int code)
{ {
switch (code) { switch (code) {
case TC_ACT_OK: case TC_ACT_OK:
case TC_ACT_RECLASSIFY:
case TC_ACT_SHOT: case TC_ACT_SHOT:
case TC_ACT_PIPE:
case TC_ACT_STOLEN: case TC_ACT_STOLEN:
case TC_ACT_QUEUED:
case TC_ACT_REDIRECT: case TC_ACT_REDIRECT:
case TC_ACT_UNSPEC: case TC_ACT_UNSPEC:
return code; return code;
@ -265,8 +262,7 @@ static int cls_bpf_prog_from_ops(struct nlattr **tb, struct cls_bpf_prog *prog)
return 0; return 0;
} }
static int cls_bpf_prog_from_efd(struct nlattr **tb, struct cls_bpf_prog *prog, static int cls_bpf_prog_from_efd(struct nlattr **tb, struct cls_bpf_prog *prog)
const struct tcf_proto *tp)
{ {
struct bpf_prog *fp; struct bpf_prog *fp;
char *name = NULL; char *name = NULL;
@ -308,14 +304,11 @@ static int cls_bpf_modify_existing(struct net *net, struct tcf_proto *tp,
{ {
bool is_bpf, is_ebpf, have_exts = false; bool is_bpf, is_ebpf, have_exts = false;
struct tcf_exts exts; struct tcf_exts exts;
u32 classid;
int ret; int ret;
is_bpf = tb[TCA_BPF_OPS_LEN] && tb[TCA_BPF_OPS]; is_bpf = tb[TCA_BPF_OPS_LEN] && tb[TCA_BPF_OPS];
is_ebpf = tb[TCA_BPF_FD]; is_ebpf = tb[TCA_BPF_FD];
if ((!is_bpf && !is_ebpf) || (is_bpf && is_ebpf))
if ((!is_bpf && !is_ebpf) || (is_bpf && is_ebpf) ||
!tb[TCA_BPF_CLASSID])
return -EINVAL; return -EINVAL;
tcf_exts_init(&exts, TCA_BPF_ACT, TCA_BPF_POLICE); tcf_exts_init(&exts, TCA_BPF_ACT, TCA_BPF_POLICE);
@ -323,7 +316,6 @@ static int cls_bpf_modify_existing(struct net *net, struct tcf_proto *tp,
if (ret < 0) if (ret < 0)
return ret; return ret;
classid = nla_get_u32(tb[TCA_BPF_CLASSID]);
if (tb[TCA_BPF_FLAGS]) { if (tb[TCA_BPF_FLAGS]) {
u32 bpf_flags = nla_get_u32(tb[TCA_BPF_FLAGS]); u32 bpf_flags = nla_get_u32(tb[TCA_BPF_FLAGS]);
@ -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; have_exts = bpf_flags & TCA_BPF_FLAG_ACT_DIRECT;
} }
prog->res.classid = classid;
prog->exts_integrated = have_exts; prog->exts_integrated = have_exts;
ret = is_bpf ? cls_bpf_prog_from_ops(tb, prog) : 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) { if (ret < 0) {
tcf_exts_destroy(&exts); tcf_exts_destroy(&exts);
return ret; return ret;
} }
tcf_bind_filter(tp, &prog->res, base); if (tb[TCA_BPF_CLASSID]) {
tcf_exts_change(tp, &prog->exts, &exts); 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; return 0;
} }
@ -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 cls_bpf_prog *prog = (struct cls_bpf_prog *) fh;
struct nlattr *nest; struct nlattr *nest;
u32 bpf_flags = 0;
int ret; int ret;
if (prog == NULL) if (prog == NULL)
@ -479,7 +474,8 @@ static int cls_bpf_dump(struct net *net, struct tcf_proto *tp, unsigned long fh,
if (nest == NULL) if (nest == NULL)
goto nla_put_failure; 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; goto nla_put_failure;
if (cls_bpf_is_ebpf(prog)) if (cls_bpf_is_ebpf(prog))
@ -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) if (tcf_exts_dump(skb, &prog->exts) < 0)
goto nla_put_failure; 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); nla_nest_end(skb, nest);
if (tcf_exts_dump_stats(skb, &prog->exts) < 0) if (tcf_exts_dump_stats(skb, &prog->exts) < 0)