1 /* net/sched/sch_ingress.c - Ingress and clsact qdisc
3 * This program is free software; you can redistribute it and/or
4 * modify it under the terms of the GNU General Public License
5 * as published by the Free Software Foundation; either version
6 * 2 of the License, or (at your option) any later version.
8 * Authors: Jamal Hadi Salim 1999
11 #include <linux/module.h>
12 #include <linux/types.h>
13 #include <linux/list.h>
14 #include <linux/skbuff.h>
15 #include <linux/rtnetlink.h>
17 #include <net/netlink.h>
18 #include <net/pkt_sched.h>
19 #include <net/pkt_cls.h>
21 static struct Qdisc
*ingress_leaf(struct Qdisc
*sch
, unsigned long arg
)
26 static unsigned long ingress_get(struct Qdisc
*sch
, u32 classid
)
28 return TC_H_MIN(classid
) + 1;
31 static bool ingress_cl_offload(u32 classid
)
36 static unsigned long ingress_bind_filter(struct Qdisc
*sch
,
37 unsigned long parent
, u32 classid
)
39 return ingress_get(sch
, classid
);
42 static void ingress_put(struct Qdisc
*sch
, unsigned long cl
)
46 static void ingress_walk(struct Qdisc
*sch
, struct qdisc_walker
*walker
)
50 static struct tcf_proto __rcu
**ingress_find_tcf(struct Qdisc
*sch
,
53 struct net_device
*dev
= qdisc_dev(sch
);
55 return &dev
->ingress_cl_list
;
58 static int ingress_init(struct Qdisc
*sch
, struct nlattr
*opt
)
60 net_inc_ingress_queue();
61 sch
->flags
|= TCQ_F_CPUSTATS
;
66 static void ingress_destroy(struct Qdisc
*sch
)
68 struct net_device
*dev
= qdisc_dev(sch
);
70 tcf_destroy_chain(&dev
->ingress_cl_list
);
71 net_dec_ingress_queue();
74 static int ingress_dump(struct Qdisc
*sch
, struct sk_buff
*skb
)
78 nest
= nla_nest_start(skb
, TCA_OPTIONS
);
82 return nla_nest_end(skb
, nest
);
85 nla_nest_cancel(skb
, nest
);
89 static const struct Qdisc_class_ops ingress_class_ops
= {
94 .tcf_chain
= ingress_find_tcf
,
95 .tcf_cl_offload
= ingress_cl_offload
,
96 .bind_tcf
= ingress_bind_filter
,
97 .unbind_tcf
= ingress_put
,
100 static struct Qdisc_ops ingress_qdisc_ops __read_mostly
= {
101 .cl_ops
= &ingress_class_ops
,
103 .init
= ingress_init
,
104 .destroy
= ingress_destroy
,
105 .dump
= ingress_dump
,
106 .owner
= THIS_MODULE
,
109 static unsigned long clsact_get(struct Qdisc
*sch
, u32 classid
)
111 switch (TC_H_MIN(classid
)) {
112 case TC_H_MIN(TC_H_MIN_INGRESS
):
113 case TC_H_MIN(TC_H_MIN_EGRESS
):
114 return TC_H_MIN(classid
);
120 static bool clsact_cl_offload(u32 classid
)
122 return TC_H_MIN(classid
) == TC_H_MIN(TC_H_MIN_INGRESS
);
125 static unsigned long clsact_bind_filter(struct Qdisc
*sch
,
126 unsigned long parent
, u32 classid
)
128 return clsact_get(sch
, classid
);
131 static struct tcf_proto __rcu
**clsact_find_tcf(struct Qdisc
*sch
,
134 struct net_device
*dev
= qdisc_dev(sch
);
137 case TC_H_MIN(TC_H_MIN_INGRESS
):
138 return &dev
->ingress_cl_list
;
139 case TC_H_MIN(TC_H_MIN_EGRESS
):
140 return &dev
->egress_cl_list
;
146 static int clsact_init(struct Qdisc
*sch
, struct nlattr
*opt
)
148 net_inc_ingress_queue();
149 net_inc_egress_queue();
151 sch
->flags
|= TCQ_F_CPUSTATS
;
156 static void clsact_destroy(struct Qdisc
*sch
)
158 struct net_device
*dev
= qdisc_dev(sch
);
160 tcf_destroy_chain(&dev
->ingress_cl_list
);
161 tcf_destroy_chain(&dev
->egress_cl_list
);
163 net_dec_ingress_queue();
164 net_dec_egress_queue();
167 static const struct Qdisc_class_ops clsact_class_ops
= {
168 .leaf
= ingress_leaf
,
171 .walk
= ingress_walk
,
172 .tcf_chain
= clsact_find_tcf
,
173 .tcf_cl_offload
= clsact_cl_offload
,
174 .bind_tcf
= clsact_bind_filter
,
175 .unbind_tcf
= ingress_put
,
178 static struct Qdisc_ops clsact_qdisc_ops __read_mostly
= {
179 .cl_ops
= &clsact_class_ops
,
182 .destroy
= clsact_destroy
,
183 .dump
= ingress_dump
,
184 .owner
= THIS_MODULE
,
187 static int __init
ingress_module_init(void)
191 ret
= register_qdisc(&ingress_qdisc_ops
);
193 ret
= register_qdisc(&clsact_qdisc_ops
);
195 unregister_qdisc(&ingress_qdisc_ops
);
201 static void __exit
ingress_module_exit(void)
203 unregister_qdisc(&ingress_qdisc_ops
);
204 unregister_qdisc(&clsact_qdisc_ops
);
207 module_init(ingress_module_init
);
208 module_exit(ingress_module_exit
);
210 MODULE_ALIAS("sch_clsact");
211 MODULE_LICENSE("GPL");