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>
20 static struct Qdisc *ingress_leaf(struct Qdisc *sch, unsigned long arg)
25 static unsigned long ingress_get(struct Qdisc *sch, u32 classid)
27 return TC_H_MIN(classid) + 1;
30 static bool ingress_cl_offload(u32 classid)
35 static unsigned long ingress_bind_filter(struct Qdisc *sch,
36 unsigned long parent, u32 classid)
38 return ingress_get(sch, classid);
41 static void ingress_put(struct Qdisc *sch, unsigned long cl)
45 static void ingress_walk(struct Qdisc *sch, struct qdisc_walker *walker)
49 static struct tcf_proto __rcu **ingress_find_tcf(struct Qdisc *sch,
52 struct net_device *dev = qdisc_dev(sch);
54 return &dev->ingress_cl_list;
57 static int ingress_init(struct Qdisc *sch, struct nlattr *opt)
59 net_inc_ingress_queue();
60 sch->flags |= TCQ_F_CPUSTATS;
65 static void ingress_destroy(struct Qdisc *sch)
67 struct net_device *dev = qdisc_dev(sch);
69 tcf_destroy_chain(&dev->ingress_cl_list);
70 net_dec_ingress_queue();
73 static int ingress_dump(struct Qdisc *sch, struct sk_buff *skb)
77 nest = nla_nest_start(skb, TCA_OPTIONS);
81 return nla_nest_end(skb, nest);
84 nla_nest_cancel(skb, nest);
88 static const struct Qdisc_class_ops ingress_class_ops = {
93 .tcf_chain = ingress_find_tcf,
94 .tcf_cl_offload = ingress_cl_offload,
95 .bind_tcf = ingress_bind_filter,
96 .unbind_tcf = ingress_put,
99 static struct Qdisc_ops ingress_qdisc_ops __read_mostly = {
100 .cl_ops = &ingress_class_ops,
102 .init = ingress_init,
103 .destroy = ingress_destroy,
104 .dump = ingress_dump,
105 .owner = THIS_MODULE,
108 static unsigned long clsact_get(struct Qdisc *sch, u32 classid)
110 switch (TC_H_MIN(classid)) {
111 case TC_H_MIN(TC_H_MIN_INGRESS):
112 case TC_H_MIN(TC_H_MIN_EGRESS):
113 return TC_H_MIN(classid);
119 static bool clsact_cl_offload(u32 classid)
121 return TC_H_MIN(classid) == TC_H_MIN(TC_H_MIN_INGRESS);
124 static unsigned long clsact_bind_filter(struct Qdisc *sch,
125 unsigned long parent, u32 classid)
127 return clsact_get(sch, classid);
130 static struct tcf_proto __rcu **clsact_find_tcf(struct Qdisc *sch,
133 struct net_device *dev = qdisc_dev(sch);
136 case TC_H_MIN(TC_H_MIN_INGRESS):
137 return &dev->ingress_cl_list;
138 case TC_H_MIN(TC_H_MIN_EGRESS):
139 return &dev->egress_cl_list;
145 static int clsact_init(struct Qdisc *sch, struct nlattr *opt)
147 net_inc_ingress_queue();
148 net_inc_egress_queue();
150 sch->flags |= TCQ_F_CPUSTATS;
155 static void clsact_destroy(struct Qdisc *sch)
157 struct net_device *dev = qdisc_dev(sch);
159 tcf_destroy_chain(&dev->ingress_cl_list);
160 tcf_destroy_chain(&dev->egress_cl_list);
162 net_dec_ingress_queue();
163 net_dec_egress_queue();
166 static const struct Qdisc_class_ops clsact_class_ops = {
167 .leaf = ingress_leaf,
170 .walk = ingress_walk,
171 .tcf_chain = clsact_find_tcf,
172 .tcf_cl_offload = clsact_cl_offload,
173 .bind_tcf = clsact_bind_filter,
174 .unbind_tcf = ingress_put,
177 static struct Qdisc_ops clsact_qdisc_ops __read_mostly = {
178 .cl_ops = &clsact_class_ops,
181 .destroy = clsact_destroy,
182 .dump = ingress_dump,
183 .owner = THIS_MODULE,
186 static int __init ingress_module_init(void)
190 ret = register_qdisc(&ingress_qdisc_ops);
192 ret = register_qdisc(&clsact_qdisc_ops);
194 unregister_qdisc(&ingress_qdisc_ops);
200 static void __exit ingress_module_exit(void)
202 unregister_qdisc(&ingress_qdisc_ops);
203 unregister_qdisc(&clsact_qdisc_ops);
206 module_init(ingress_module_init);
207 module_exit(ingress_module_exit);
209 MODULE_ALIAS("sch_clsact");
210 MODULE_LICENSE("GPL");