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;
25 static struct Qdisc *ingress_leaf(struct Qdisc *sch, unsigned long arg)
30 static unsigned long ingress_find(struct Qdisc *sch, u32 classid)
32 return TC_H_MIN(classid) + 1;
35 static unsigned long ingress_bind_filter(struct Qdisc *sch,
36 unsigned long parent, u32 classid)
38 return ingress_find(sch, classid);
41 static void ingress_unbind_filter(struct Qdisc *sch, unsigned long cl)
45 static void ingress_walk(struct Qdisc *sch, struct qdisc_walker *walker)
49 static struct tcf_block *ingress_tcf_block(struct Qdisc *sch, unsigned long cl)
51 struct ingress_sched_data *q = qdisc_priv(sch);
56 static int ingress_init(struct Qdisc *sch, struct nlattr *opt)
58 struct ingress_sched_data *q = qdisc_priv(sch);
59 struct net_device *dev = qdisc_dev(sch);
62 err = tcf_block_get(&q->block, &dev->ingress_cl_list);
66 net_inc_ingress_queue();
67 sch->flags |= TCQ_F_CPUSTATS;
72 static void ingress_destroy(struct Qdisc *sch)
74 struct ingress_sched_data *q = qdisc_priv(sch);
76 tcf_block_put(q->block);
77 net_dec_ingress_queue();
80 static int ingress_dump(struct Qdisc *sch, struct sk_buff *skb)
84 nest = nla_nest_start(skb, TCA_OPTIONS);
88 return nla_nest_end(skb, nest);
91 nla_nest_cancel(skb, nest);
95 static const struct Qdisc_class_ops ingress_class_ops = {
99 .tcf_block = ingress_tcf_block,
100 .bind_tcf = ingress_bind_filter,
101 .unbind_tcf = ingress_unbind_filter,
104 static struct Qdisc_ops ingress_qdisc_ops __read_mostly = {
105 .cl_ops = &ingress_class_ops,
107 .priv_size = sizeof(struct ingress_sched_data),
108 .init = ingress_init,
109 .destroy = ingress_destroy,
110 .dump = ingress_dump,
111 .owner = THIS_MODULE,
114 struct clsact_sched_data {
115 struct tcf_block *ingress_block;
116 struct tcf_block *egress_block;
119 static unsigned long clsact_find(struct Qdisc *sch, u32 classid)
121 switch (TC_H_MIN(classid)) {
122 case TC_H_MIN(TC_H_MIN_INGRESS):
123 case TC_H_MIN(TC_H_MIN_EGRESS):
124 return TC_H_MIN(classid);
130 static unsigned long clsact_bind_filter(struct Qdisc *sch,
131 unsigned long parent, u32 classid)
133 return clsact_find(sch, classid);
136 static struct tcf_block *clsact_tcf_block(struct Qdisc *sch, unsigned long cl)
138 struct clsact_sched_data *q = qdisc_priv(sch);
141 case TC_H_MIN(TC_H_MIN_INGRESS):
142 return q->ingress_block;
143 case TC_H_MIN(TC_H_MIN_EGRESS):
144 return q->egress_block;
150 static int clsact_init(struct Qdisc *sch, struct nlattr *opt)
152 struct clsact_sched_data *q = qdisc_priv(sch);
153 struct net_device *dev = qdisc_dev(sch);
156 err = tcf_block_get(&q->ingress_block, &dev->ingress_cl_list);
160 err = tcf_block_get(&q->egress_block, &dev->egress_cl_list);
164 net_inc_ingress_queue();
165 net_inc_egress_queue();
167 sch->flags |= TCQ_F_CPUSTATS;
172 static void clsact_destroy(struct Qdisc *sch)
174 struct clsact_sched_data *q = qdisc_priv(sch);
176 tcf_block_put(q->egress_block);
177 tcf_block_put(q->ingress_block);
179 net_dec_ingress_queue();
180 net_dec_egress_queue();
183 static const struct Qdisc_class_ops clsact_class_ops = {
184 .leaf = ingress_leaf,
186 .walk = ingress_walk,
187 .tcf_block = clsact_tcf_block,
188 .bind_tcf = clsact_bind_filter,
189 .unbind_tcf = ingress_unbind_filter,
192 static struct Qdisc_ops clsact_qdisc_ops __read_mostly = {
193 .cl_ops = &clsact_class_ops,
195 .priv_size = sizeof(struct clsact_sched_data),
197 .destroy = clsact_destroy,
198 .dump = ingress_dump,
199 .owner = THIS_MODULE,
202 static int __init ingress_module_init(void)
206 ret = register_qdisc(&ingress_qdisc_ops);
208 ret = register_qdisc(&clsact_qdisc_ops);
210 unregister_qdisc(&ingress_qdisc_ops);
216 static void __exit ingress_module_exit(void)
218 unregister_qdisc(&ingress_qdisc_ops);
219 unregister_qdisc(&clsact_qdisc_ops);
222 module_init(ingress_module_init);
223 module_exit(ingress_module_exit);
225 MODULE_ALIAS("sch_clsact");
226 MODULE_LICENSE("GPL");