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;
24 struct mini_Qdisc_pair miniqp;
27 static struct Qdisc *ingress_leaf(struct Qdisc *sch, unsigned long arg)
32 static unsigned long ingress_find(struct Qdisc *sch, u32 classid)
34 return TC_H_MIN(classid) + 1;
37 static unsigned long ingress_bind_filter(struct Qdisc *sch,
38 unsigned long parent, u32 classid)
40 return ingress_find(sch, classid);
43 static void ingress_unbind_filter(struct Qdisc *sch, unsigned long cl)
47 static void ingress_walk(struct Qdisc *sch, struct qdisc_walker *walker)
51 static struct tcf_block *ingress_tcf_block(struct Qdisc *sch, unsigned long cl)
53 struct ingress_sched_data *q = qdisc_priv(sch);
58 static void clsact_chain_head_change(struct tcf_proto *tp_head, void *priv)
60 struct mini_Qdisc_pair *miniqp = priv;
62 mini_qdisc_pair_swap(miniqp, tp_head);
65 static int ingress_init(struct Qdisc *sch, struct nlattr *opt)
67 struct ingress_sched_data *q = qdisc_priv(sch);
68 struct net_device *dev = qdisc_dev(sch);
71 mini_qdisc_pair_init(&q->miniqp, sch, &dev->miniq_ingress);
73 q->block_info.binder_type = TCF_BLOCK_BINDER_TYPE_CLSACT_INGRESS;
74 q->block_info.chain_head_change = clsact_chain_head_change;
75 q->block_info.chain_head_change_priv = &q->miniqp;
77 err = tcf_block_get_ext(&q->block, sch, &q->block_info);
81 net_inc_ingress_queue();
82 sch->flags |= TCQ_F_CPUSTATS;
87 static void ingress_destroy(struct Qdisc *sch)
89 struct ingress_sched_data *q = qdisc_priv(sch);
91 tcf_block_put_ext(q->block, sch, &q->block_info);
92 net_dec_ingress_queue();
95 static int ingress_dump(struct Qdisc *sch, struct sk_buff *skb)
99 nest = nla_nest_start(skb, TCA_OPTIONS);
101 goto nla_put_failure;
103 return nla_nest_end(skb, nest);
106 nla_nest_cancel(skb, nest);
110 static const struct Qdisc_class_ops ingress_class_ops = {
111 .leaf = ingress_leaf,
112 .find = ingress_find,
113 .walk = ingress_walk,
114 .tcf_block = ingress_tcf_block,
115 .bind_tcf = ingress_bind_filter,
116 .unbind_tcf = ingress_unbind_filter,
119 static struct Qdisc_ops ingress_qdisc_ops __read_mostly = {
120 .cl_ops = &ingress_class_ops,
122 .priv_size = sizeof(struct ingress_sched_data),
123 .init = ingress_init,
124 .destroy = ingress_destroy,
125 .dump = ingress_dump,
126 .owner = THIS_MODULE,
129 struct clsact_sched_data {
130 struct tcf_block *ingress_block;
131 struct tcf_block *egress_block;
132 struct tcf_block_ext_info ingress_block_info;
133 struct tcf_block_ext_info egress_block_info;
134 struct mini_Qdisc_pair miniqp_ingress;
135 struct mini_Qdisc_pair miniqp_egress;
138 static unsigned long clsact_find(struct Qdisc *sch, u32 classid)
140 switch (TC_H_MIN(classid)) {
141 case TC_H_MIN(TC_H_MIN_INGRESS):
142 case TC_H_MIN(TC_H_MIN_EGRESS):
143 return TC_H_MIN(classid);
149 static unsigned long clsact_bind_filter(struct Qdisc *sch,
150 unsigned long parent, u32 classid)
152 return clsact_find(sch, classid);
155 static struct tcf_block *clsact_tcf_block(struct Qdisc *sch, unsigned long cl)
157 struct clsact_sched_data *q = qdisc_priv(sch);
160 case TC_H_MIN(TC_H_MIN_INGRESS):
161 return q->ingress_block;
162 case TC_H_MIN(TC_H_MIN_EGRESS):
163 return q->egress_block;
169 static int clsact_init(struct Qdisc *sch, struct nlattr *opt)
171 struct clsact_sched_data *q = qdisc_priv(sch);
172 struct net_device *dev = qdisc_dev(sch);
175 mini_qdisc_pair_init(&q->miniqp_ingress, sch, &dev->miniq_ingress);
177 q->ingress_block_info.binder_type = TCF_BLOCK_BINDER_TYPE_CLSACT_INGRESS;
178 q->ingress_block_info.chain_head_change = clsact_chain_head_change;
179 q->ingress_block_info.chain_head_change_priv = &q->miniqp_ingress;
181 err = tcf_block_get_ext(&q->ingress_block, sch, &q->ingress_block_info);
185 mini_qdisc_pair_init(&q->miniqp_egress, sch, &dev->miniq_egress);
187 q->egress_block_info.binder_type = TCF_BLOCK_BINDER_TYPE_CLSACT_EGRESS;
188 q->egress_block_info.chain_head_change = clsact_chain_head_change;
189 q->egress_block_info.chain_head_change_priv = &q->miniqp_egress;
191 err = tcf_block_get_ext(&q->egress_block, sch, &q->egress_block_info);
193 goto err_egress_block_get;
195 net_inc_ingress_queue();
196 net_inc_egress_queue();
198 sch->flags |= TCQ_F_CPUSTATS;
202 err_egress_block_get:
203 tcf_block_put_ext(q->ingress_block, sch, &q->ingress_block_info);
207 static void clsact_destroy(struct Qdisc *sch)
209 struct clsact_sched_data *q = qdisc_priv(sch);
211 tcf_block_put_ext(q->egress_block, sch, &q->egress_block_info);
212 tcf_block_put_ext(q->ingress_block, sch, &q->ingress_block_info);
214 net_dec_ingress_queue();
215 net_dec_egress_queue();
218 static const struct Qdisc_class_ops clsact_class_ops = {
219 .leaf = ingress_leaf,
221 .walk = ingress_walk,
222 .tcf_block = clsact_tcf_block,
223 .bind_tcf = clsact_bind_filter,
224 .unbind_tcf = ingress_unbind_filter,
227 static struct Qdisc_ops clsact_qdisc_ops __read_mostly = {
228 .cl_ops = &clsact_class_ops,
230 .priv_size = sizeof(struct clsact_sched_data),
232 .destroy = clsact_destroy,
233 .dump = ingress_dump,
234 .owner = THIS_MODULE,
237 static int __init ingress_module_init(void)
241 ret = register_qdisc(&ingress_qdisc_ops);
243 ret = register_qdisc(&clsact_qdisc_ops);
245 unregister_qdisc(&ingress_qdisc_ops);
251 static void __exit ingress_module_exit(void)
253 unregister_qdisc(&ingress_qdisc_ops);
254 unregister_qdisc(&clsact_qdisc_ops);
257 module_init(ingress_module_init);
258 module_exit(ingress_module_exit);
260 MODULE_ALIAS("sch_clsact");
261 MODULE_LICENSE("GPL");