Skip to content

Commit 9d43507

Browse files
committed
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: David S. Miller <[email protected]>
2 parents bc37b24 + cc9039a commit 9d43507

File tree

11 files changed

+22
-55
lines changed

11 files changed

+22
-55
lines changed

include/net/pkt_cls.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,18 @@ tcf_unbind_filter(struct tcf_proto *tp, struct tcf_result *r)
210210
__tcf_unbind_filter(q, r);
211211
}
212212

213+
static inline void tc_cls_bind_class(u32 classid, unsigned long cl,
214+
void *q, struct tcf_result *res,
215+
unsigned long base)
216+
{
217+
if (res->classid == classid) {
218+
if (cl)
219+
__tcf_bind_filter(q, res, base);
220+
else
221+
__tcf_unbind_filter(q, res);
222+
}
223+
}
224+
213225
struct tcf_exts {
214226
#ifdef CONFIG_NET_CLS_ACT
215227
__u32 type; /* for backward compat(TCA_OLD_COMPAT) */

net/sched/cls_basic.c

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -261,12 +261,7 @@ static void basic_bind_class(void *fh, u32 classid, unsigned long cl, void *q,
261261
{
262262
struct basic_filter *f = fh;
263263

264-
if (f && f->res.classid == classid) {
265-
if (cl)
266-
__tcf_bind_filter(q, &f->res, base);
267-
else
268-
__tcf_unbind_filter(q, &f->res);
269-
}
264+
tc_cls_bind_class(classid, cl, q, &f->res, base);
270265
}
271266

272267
static int basic_dump(struct net *net, struct tcf_proto *tp, void *fh,

net/sched/cls_bpf.c

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -635,12 +635,7 @@ static void cls_bpf_bind_class(void *fh, u32 classid, unsigned long cl,
635635
{
636636
struct cls_bpf_prog *prog = fh;
637637

638-
if (prog && prog->res.classid == classid) {
639-
if (cl)
640-
__tcf_bind_filter(q, &prog->res, base);
641-
else
642-
__tcf_unbind_filter(q, &prog->res);
643-
}
638+
tc_cls_bind_class(classid, cl, q, &prog->res, base);
644639
}
645640

646641
static void cls_bpf_walk(struct tcf_proto *tp, struct tcf_walker *arg,

net/sched/cls_flower.c

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3405,12 +3405,7 @@ static void fl_bind_class(void *fh, u32 classid, unsigned long cl, void *q,
34053405
{
34063406
struct cls_fl_filter *f = fh;
34073407

3408-
if (f && f->res.classid == classid) {
3409-
if (cl)
3410-
__tcf_bind_filter(q, &f->res, base);
3411-
else
3412-
__tcf_unbind_filter(q, &f->res);
3413-
}
3408+
tc_cls_bind_class(classid, cl, q, &f->res, base);
34143409
}
34153410

34163411
static bool fl_delete_empty(struct tcf_proto *tp)

net/sched/cls_fw.c

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -416,12 +416,7 @@ static void fw_bind_class(void *fh, u32 classid, unsigned long cl, void *q,
416416
{
417417
struct fw_filter *f = fh;
418418

419-
if (f && f->res.classid == classid) {
420-
if (cl)
421-
__tcf_bind_filter(q, &f->res, base);
422-
else
423-
__tcf_unbind_filter(q, &f->res);
424-
}
419+
tc_cls_bind_class(classid, cl, q, &f->res, base);
425420
}
426421

427422
static struct tcf_proto_ops cls_fw_ops __read_mostly = {

net/sched/cls_matchall.c

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -394,12 +394,7 @@ static void mall_bind_class(void *fh, u32 classid, unsigned long cl, void *q,
394394
{
395395
struct cls_mall_head *head = fh;
396396

397-
if (head && head->res.classid == classid) {
398-
if (cl)
399-
__tcf_bind_filter(q, &head->res, base);
400-
else
401-
__tcf_unbind_filter(q, &head->res);
402-
}
397+
tc_cls_bind_class(classid, cl, q, &head->res, base);
403398
}
404399

405400
static struct tcf_proto_ops cls_mall_ops __read_mostly = {

net/sched/cls_route.c

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -649,12 +649,7 @@ static void route4_bind_class(void *fh, u32 classid, unsigned long cl, void *q,
649649
{
650650
struct route4_filter *f = fh;
651651

652-
if (f && f->res.classid == classid) {
653-
if (cl)
654-
__tcf_bind_filter(q, &f->res, base);
655-
else
656-
__tcf_unbind_filter(q, &f->res);
657-
}
652+
tc_cls_bind_class(classid, cl, q, &f->res, base);
658653
}
659654

660655
static struct tcf_proto_ops cls_route4_ops __read_mostly = {

net/sched/cls_rsvp.h

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -733,12 +733,7 @@ static void rsvp_bind_class(void *fh, u32 classid, unsigned long cl, void *q,
733733
{
734734
struct rsvp_filter *f = fh;
735735

736-
if (f && f->res.classid == classid) {
737-
if (cl)
738-
__tcf_bind_filter(q, &f->res, base);
739-
else
740-
__tcf_unbind_filter(q, &f->res);
741-
}
736+
tc_cls_bind_class(classid, cl, q, &f->res, base);
742737
}
743738

744739
static struct tcf_proto_ops RSVP_OPS __read_mostly = {

net/sched/cls_tcindex.c

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -691,12 +691,7 @@ static void tcindex_bind_class(void *fh, u32 classid, unsigned long cl,
691691
{
692692
struct tcindex_filter_result *r = fh;
693693

694-
if (r && r->res.classid == classid) {
695-
if (cl)
696-
__tcf_bind_filter(q, &r->res, base);
697-
else
698-
__tcf_unbind_filter(q, &r->res);
699-
}
694+
tc_cls_bind_class(classid, cl, q, &r->res, base);
700695
}
701696

702697
static struct tcf_proto_ops cls_tcindex_ops __read_mostly = {

net/sched/cls_u32.c

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1250,12 +1250,7 @@ static void u32_bind_class(void *fh, u32 classid, unsigned long cl, void *q,
12501250
{
12511251
struct tc_u_knode *n = fh;
12521252

1253-
if (n && n->res.classid == classid) {
1254-
if (cl)
1255-
__tcf_bind_filter(q, &n->res, base);
1256-
else
1257-
__tcf_unbind_filter(q, &n->res);
1258-
}
1253+
tc_cls_bind_class(classid, cl, q, &n->res, base);
12591254
}
12601255

12611256
static int u32_dump(struct net *net, struct tcf_proto *tp, void *fh,

0 commit comments

Comments
 (0)