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 struct ingress_sched_data {
22 struct tcf_block *block;
23 struct tcf_block_ext_info block_info;
26 static struct Qdisc *ingress_leaf(struct Qdisc *sch, unsigned long arg)
31 static unsigned long ingress_find(struct Qdisc *sch, u32 classid)
33 return TC_H_MIN(classid) + 1;
36 static unsigned long ingress_bind_filter(struct Qdisc *sch,
37 unsigned long parent, u32 classid)
39 return ingress_find(sch, classid);
42 static void ingress_unbind_filter(struct Qdisc *sch, unsigned long cl)
46 static void ingress_walk(struct Qdisc *sch, struct qdisc_walker *walker)
50 static struct tcf_block *ingress_tcf_block(struct Qdisc *sch, unsigned long cl)
52 struct ingress_sched_data *q = qdisc_priv(sch);
57 static int ingress_init(struct Qdisc *sch, struct nlattr *opt)
59 struct ingress_sched_data *q = qdisc_priv(sch);
60 struct net_device *dev = qdisc_dev(sch);
63 q->block_info.binder_type = TCF_BLOCK_BINDER_TYPE_CLSACT_INGRESS;
65 err = tcf_block_get_ext(&q->block, &dev->ingress_cl_list,
70 net_inc_ingress_queue();
71 sch->flags |= TCQ_F_CPUSTATS;
76 static void ingress_destroy(struct Qdisc *sch)
78 struct ingress_sched_data *q = qdisc_priv(sch);
79 struct net_device *dev = qdisc_dev(sch);
81 tcf_block_put_ext(q->block, &dev->ingress_cl_list,
83 net_dec_ingress_queue();
86 static int ingress_dump(struct Qdisc *sch, struct sk_buff *skb)
90 nest = nla_nest_start(skb, TCA_OPTIONS);
94 return nla_nest_end(skb, nest);
97 nla_nest_cancel(skb, nest);
101 static const struct Qdisc_class_ops ingress_class_ops = {
102 .leaf = ingress_leaf,
103 .find = ingress_find,
104 .walk = ingress_walk,
105 .tcf_block = ingress_tcf_block,
106 .bind_tcf = ingress_bind_filter,
107 .unbind_tcf = ingress_unbind_filter,
110 static struct Qdisc_ops ingress_qdisc_ops __read_mostly = {
111 .cl_ops = &ingress_class_ops,
113 .priv_size = sizeof(struct ingress_sched_data),
114 .init = ingress_init,
115 .destroy = ingress_destroy,
116 .dump = ingress_dump,
117 .owner = THIS_MODULE,
120 struct clsact_sched_data {
121 struct tcf_block *ingress_block;
122 struct tcf_block *egress_block;
123 struct tcf_block_ext_info ingress_block_info;
124 struct tcf_block_ext_info egress_block_info;
127 static unsigned long clsact_find(struct Qdisc *sch, u32 classid)
129 switch (TC_H_MIN(classid)) {
130 case TC_H_MIN(TC_H_MIN_INGRESS):
131 case TC_H_MIN(TC_H_MIN_EGRESS):
132 return TC_H_MIN(classid);
138 static unsigned long clsact_bind_filter(struct Qdisc *sch,
139 unsigned long parent, u32 classid)
141 return clsact_find(sch, classid);
144 static struct tcf_block *clsact_tcf_block(struct Qdisc *sch, unsigned long cl)
146 struct clsact_sched_data *q = qdisc_priv(sch);
149 case TC_H_MIN(TC_H_MIN_INGRESS):
150 return q->ingress_block;
151 case TC_H_MIN(TC_H_MIN_EGRESS):
152 return q->egress_block;
158 static int clsact_init(struct Qdisc *sch, struct nlattr *opt)
160 struct clsact_sched_data *q = qdisc_priv(sch);
161 struct net_device *dev = qdisc_dev(sch);
164 q->ingress_block_info.binder_type = TCF_BLOCK_BINDER_TYPE_CLSACT_INGRESS;
166 err = tcf_block_get_ext(&q->ingress_block, &dev->ingress_cl_list,
167 sch, &q->ingress_block_info);
171 q->egress_block_info.binder_type = TCF_BLOCK_BINDER_TYPE_CLSACT_EGRESS;
173 err = tcf_block_get_ext(&q->egress_block, &dev->egress_cl_list,
174 sch, &q->egress_block_info);
176 goto err_egress_block_get;
178 net_inc_ingress_queue();
179 net_inc_egress_queue();
181 sch->flags |= TCQ_F_CPUSTATS;
185 err_egress_block_get:
186 tcf_block_put_ext(q->ingress_block, &dev->ingress_cl_list,
187 sch, &q->ingress_block_info);
191 static void clsact_destroy(struct Qdisc *sch)
193 struct clsact_sched_data *q = qdisc_priv(sch);
194 struct net_device *dev = qdisc_dev(sch);
196 tcf_block_put_ext(q->egress_block, &dev->egress_cl_list,
197 sch, &q->egress_block_info);
198 tcf_block_put_ext(q->ingress_block, &dev->ingress_cl_list,
199 sch, &q->ingress_block_info);
201 net_dec_ingress_queue();
202 net_dec_egress_queue();
205 static const struct Qdisc_class_ops clsact_class_ops = {
206 .leaf = ingress_leaf,
208 .walk = ingress_walk,
209 .tcf_block = clsact_tcf_block,
210 .bind_tcf = clsact_bind_filter,
211 .unbind_tcf = ingress_unbind_filter,
214 static struct Qdisc_ops clsact_qdisc_ops __read_mostly = {
215 .cl_ops = &clsact_class_ops,
217 .priv_size = sizeof(struct clsact_sched_data),
219 .destroy = clsact_destroy,
220 .dump = ingress_dump,
221 .owner = THIS_MODULE,
224 static int __init ingress_module_init(void)
228 ret = register_qdisc(&ingress_qdisc_ops);
230 ret = register_qdisc(&clsact_qdisc_ops);
232 unregister_qdisc(&ingress_qdisc_ops);
238 static void __exit ingress_module_exit(void)
240 unregister_qdisc(&ingress_qdisc_ops);
241 unregister_qdisc(&clsact_qdisc_ops);
244 module_init(ingress_module_init);
245 module_exit(ingress_module_exit);
247 MODULE_ALIAS("sch_clsact");
248 MODULE_LICENSE("GPL");