Commit 9d435073 authored by David S. Miller's avatar David S. Miller

Merge branch 'tc-bind_class-hook'

Zhengchao Shao says:

====================
refactor duplicate codes in bind_class hook function

All the bind_class callback duplicate the same logic, so we can refactor
them. First, ensure n arg not empty before call bind_class hook function.
Then, add tc_cls_bind_class() helper. Last, use tc_cls_bind_class() in
filter.
====================
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parents bc37b24e cc9039a1
...@@ -210,6 +210,18 @@ tcf_unbind_filter(struct tcf_proto *tp, struct tcf_result *r) ...@@ -210,6 +210,18 @@ tcf_unbind_filter(struct tcf_proto *tp, struct tcf_result *r)
__tcf_unbind_filter(q, r); __tcf_unbind_filter(q, r);
} }
static inline void tc_cls_bind_class(u32 classid, unsigned long cl,
void *q, struct tcf_result *res,
unsigned long base)
{
if (res->classid == classid) {
if (cl)
__tcf_bind_filter(q, res, base);
else
__tcf_unbind_filter(q, res);
}
}
struct tcf_exts { struct tcf_exts {
#ifdef CONFIG_NET_CLS_ACT #ifdef CONFIG_NET_CLS_ACT
__u32 type; /* for backward compat(TCA_OLD_COMPAT) */ __u32 type; /* for backward compat(TCA_OLD_COMPAT) */
......
...@@ -261,12 +261,7 @@ static void basic_bind_class(void *fh, u32 classid, unsigned long cl, void *q, ...@@ -261,12 +261,7 @@ static void basic_bind_class(void *fh, u32 classid, unsigned long cl, void *q,
{ {
struct basic_filter *f = fh; struct basic_filter *f = fh;
if (f && f->res.classid == classid) { tc_cls_bind_class(classid, cl, q, &f->res, base);
if (cl)
__tcf_bind_filter(q, &f->res, base);
else
__tcf_unbind_filter(q, &f->res);
}
} }
static int basic_dump(struct net *net, struct tcf_proto *tp, void *fh, static int basic_dump(struct net *net, struct tcf_proto *tp, void *fh,
......
...@@ -635,12 +635,7 @@ static void cls_bpf_bind_class(void *fh, u32 classid, unsigned long cl, ...@@ -635,12 +635,7 @@ static void cls_bpf_bind_class(void *fh, u32 classid, unsigned long cl,
{ {
struct cls_bpf_prog *prog = fh; struct cls_bpf_prog *prog = fh;
if (prog && prog->res.classid == classid) { tc_cls_bind_class(classid, cl, q, &prog->res, base);
if (cl)
__tcf_bind_filter(q, &prog->res, base);
else
__tcf_unbind_filter(q, &prog->res);
}
} }
static void cls_bpf_walk(struct tcf_proto *tp, struct tcf_walker *arg, static void cls_bpf_walk(struct tcf_proto *tp, struct tcf_walker *arg,
......
...@@ -3405,12 +3405,7 @@ static void fl_bind_class(void *fh, u32 classid, unsigned long cl, void *q, ...@@ -3405,12 +3405,7 @@ static void fl_bind_class(void *fh, u32 classid, unsigned long cl, void *q,
{ {
struct cls_fl_filter *f = fh; struct cls_fl_filter *f = fh;
if (f && f->res.classid == classid) { tc_cls_bind_class(classid, cl, q, &f->res, base);
if (cl)
__tcf_bind_filter(q, &f->res, base);
else
__tcf_unbind_filter(q, &f->res);
}
} }
static bool fl_delete_empty(struct tcf_proto *tp) static bool fl_delete_empty(struct tcf_proto *tp)
......
...@@ -416,12 +416,7 @@ static void fw_bind_class(void *fh, u32 classid, unsigned long cl, void *q, ...@@ -416,12 +416,7 @@ static void fw_bind_class(void *fh, u32 classid, unsigned long cl, void *q,
{ {
struct fw_filter *f = fh; struct fw_filter *f = fh;
if (f && f->res.classid == classid) { tc_cls_bind_class(classid, cl, q, &f->res, base);
if (cl)
__tcf_bind_filter(q, &f->res, base);
else
__tcf_unbind_filter(q, &f->res);
}
} }
static struct tcf_proto_ops cls_fw_ops __read_mostly = { static struct tcf_proto_ops cls_fw_ops __read_mostly = {
......
...@@ -394,12 +394,7 @@ static void mall_bind_class(void *fh, u32 classid, unsigned long cl, void *q, ...@@ -394,12 +394,7 @@ static void mall_bind_class(void *fh, u32 classid, unsigned long cl, void *q,
{ {
struct cls_mall_head *head = fh; struct cls_mall_head *head = fh;
if (head && head->res.classid == classid) { tc_cls_bind_class(classid, cl, q, &head->res, base);
if (cl)
__tcf_bind_filter(q, &head->res, base);
else
__tcf_unbind_filter(q, &head->res);
}
} }
static struct tcf_proto_ops cls_mall_ops __read_mostly = { static struct tcf_proto_ops cls_mall_ops __read_mostly = {
......
...@@ -649,12 +649,7 @@ static void route4_bind_class(void *fh, u32 classid, unsigned long cl, void *q, ...@@ -649,12 +649,7 @@ static void route4_bind_class(void *fh, u32 classid, unsigned long cl, void *q,
{ {
struct route4_filter *f = fh; struct route4_filter *f = fh;
if (f && f->res.classid == classid) { tc_cls_bind_class(classid, cl, q, &f->res, base);
if (cl)
__tcf_bind_filter(q, &f->res, base);
else
__tcf_unbind_filter(q, &f->res);
}
} }
static struct tcf_proto_ops cls_route4_ops __read_mostly = { static struct tcf_proto_ops cls_route4_ops __read_mostly = {
......
...@@ -733,12 +733,7 @@ static void rsvp_bind_class(void *fh, u32 classid, unsigned long cl, void *q, ...@@ -733,12 +733,7 @@ static void rsvp_bind_class(void *fh, u32 classid, unsigned long cl, void *q,
{ {
struct rsvp_filter *f = fh; struct rsvp_filter *f = fh;
if (f && f->res.classid == classid) { tc_cls_bind_class(classid, cl, q, &f->res, base);
if (cl)
__tcf_bind_filter(q, &f->res, base);
else
__tcf_unbind_filter(q, &f->res);
}
} }
static struct tcf_proto_ops RSVP_OPS __read_mostly = { static struct tcf_proto_ops RSVP_OPS __read_mostly = {
......
...@@ -691,12 +691,7 @@ static void tcindex_bind_class(void *fh, u32 classid, unsigned long cl, ...@@ -691,12 +691,7 @@ static void tcindex_bind_class(void *fh, u32 classid, unsigned long cl,
{ {
struct tcindex_filter_result *r = fh; struct tcindex_filter_result *r = fh;
if (r && r->res.classid == classid) { tc_cls_bind_class(classid, cl, q, &r->res, base);
if (cl)
__tcf_bind_filter(q, &r->res, base);
else
__tcf_unbind_filter(q, &r->res);
}
} }
static struct tcf_proto_ops cls_tcindex_ops __read_mostly = { static struct tcf_proto_ops cls_tcindex_ops __read_mostly = {
......
...@@ -1250,12 +1250,7 @@ static void u32_bind_class(void *fh, u32 classid, unsigned long cl, void *q, ...@@ -1250,12 +1250,7 @@ static void u32_bind_class(void *fh, u32 classid, unsigned long cl, void *q,
{ {
struct tc_u_knode *n = fh; struct tc_u_knode *n = fh;
if (n && n->res.classid == classid) { tc_cls_bind_class(classid, cl, q, &n->res, base);
if (cl)
__tcf_bind_filter(q, &n->res, base);
else
__tcf_unbind_filter(q, &n->res);
}
} }
static int u32_dump(struct net *net, struct tcf_proto *tp, void *fh, static int u32_dump(struct net *net, struct tcf_proto *tp, void *fh,
......
...@@ -1915,7 +1915,7 @@ static int tcf_node_bind(struct tcf_proto *tp, void *n, struct tcf_walker *arg) ...@@ -1915,7 +1915,7 @@ static int tcf_node_bind(struct tcf_proto *tp, void *n, struct tcf_walker *arg)
{ {
struct tcf_bind_args *a = (void *)arg; struct tcf_bind_args *a = (void *)arg;
if (tp->ops->bind_class) { if (n && tp->ops->bind_class) {
struct Qdisc *q = tcf_block_q(tp->chain->block); struct Qdisc *q = tcf_block_q(tp->chain->block);
sch_tree_lock(q); sch_tree_lock(q);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment