]> git.proxmox.com Git - mirror_ubuntu-artful-kernel.git/blame - net/sched/sch_ingress.c
net: sched: move tc_classify function to cls_api.c
[mirror_ubuntu-artful-kernel.git] / net / sched / sch_ingress.c
CommitLineData
1f211a1b
DB
1/* net/sched/sch_ingress.c - Ingress and clsact qdisc
2 *
1da177e4
LT
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.
7 *
8 * Authors: Jamal Hadi Salim 1999
9 */
10
1da177e4
LT
11#include <linux/module.h>
12#include <linux/types.h>
0ba48053 13#include <linux/list.h>
1da177e4 14#include <linux/skbuff.h>
1da177e4 15#include <linux/rtnetlink.h>
d2788d34 16
dc5fc579 17#include <net/netlink.h>
1da177e4 18#include <net/pkt_sched.h>
cf1facda 19#include <net/pkt_cls.h>
1da177e4 20
1da177e4
LT
21static struct Qdisc *ingress_leaf(struct Qdisc *sch, unsigned long arg)
22{
23 return NULL;
24}
25
58f4df42 26static unsigned long ingress_get(struct Qdisc *sch, u32 classid)
1da177e4 27{
1da177e4
LT
28 return TC_H_MIN(classid) + 1;
29}
30
92c075db
DB
31static bool ingress_cl_offload(u32 classid)
32{
33 return true;
34}
35
1da177e4 36static unsigned long ingress_bind_filter(struct Qdisc *sch,
58f4df42 37 unsigned long parent, u32 classid)
1da177e4
LT
38{
39 return ingress_get(sch, classid);
40}
41
1da177e4
LT
42static void ingress_put(struct Qdisc *sch, unsigned long cl)
43{
44}
45
58f4df42 46static void ingress_walk(struct Qdisc *sch, struct qdisc_walker *walker)
1da177e4 47{
1da177e4
LT
48}
49
25d8c0d5
JF
50static struct tcf_proto __rcu **ingress_find_tcf(struct Qdisc *sch,
51 unsigned long cl)
1da177e4 52{
d2788d34 53 struct net_device *dev = qdisc_dev(sch);
1da177e4 54
d2788d34 55 return &dev->ingress_cl_list;
1da177e4
LT
56}
57
4577139b
DB
58static int ingress_init(struct Qdisc *sch, struct nlattr *opt)
59{
60 net_inc_ingress_queue();
087c1a60 61 sch->flags |= TCQ_F_CPUSTATS;
4577139b
DB
62
63 return 0;
64}
65
1da177e4
LT
66static void ingress_destroy(struct Qdisc *sch)
67{
d2788d34 68 struct net_device *dev = qdisc_dev(sch);
1da177e4 69
d2788d34 70 tcf_destroy_chain(&dev->ingress_cl_list);
4577139b 71 net_dec_ingress_queue();
1da177e4
LT
72}
73
1da177e4
LT
74static int ingress_dump(struct Qdisc *sch, struct sk_buff *skb)
75{
4b3550ef 76 struct nlattr *nest;
1da177e4 77
4b3550ef
PM
78 nest = nla_nest_start(skb, TCA_OPTIONS);
79 if (nest == NULL)
80 goto nla_put_failure;
d2788d34 81
d59b7d80 82 return nla_nest_end(skb, nest);
1da177e4 83
1e90474c 84nla_put_failure:
4b3550ef 85 nla_nest_cancel(skb, nest);
1da177e4
LT
86 return -1;
87}
88
20fea08b 89static const struct Qdisc_class_ops ingress_class_ops = {
1da177e4
LT
90 .leaf = ingress_leaf,
91 .get = ingress_get,
92 .put = ingress_put,
1da177e4
LT
93 .walk = ingress_walk,
94 .tcf_chain = ingress_find_tcf,
92c075db 95 .tcf_cl_offload = ingress_cl_offload,
1da177e4
LT
96 .bind_tcf = ingress_bind_filter,
97 .unbind_tcf = ingress_put,
1da177e4
LT
98};
99
20fea08b 100static struct Qdisc_ops ingress_qdisc_ops __read_mostly = {
1da177e4
LT
101 .cl_ops = &ingress_class_ops,
102 .id = "ingress",
4577139b 103 .init = ingress_init,
1da177e4 104 .destroy = ingress_destroy,
1da177e4
LT
105 .dump = ingress_dump,
106 .owner = THIS_MODULE,
107};
108
1f211a1b
DB
109static unsigned long clsact_get(struct Qdisc *sch, u32 classid)
110{
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);
115 default:
116 return 0;
117 }
118}
119
92c075db
DB
120static bool clsact_cl_offload(u32 classid)
121{
122 return TC_H_MIN(classid) == TC_H_MIN(TC_H_MIN_INGRESS);
123}
124
1f211a1b
DB
125static unsigned long clsact_bind_filter(struct Qdisc *sch,
126 unsigned long parent, u32 classid)
127{
128 return clsact_get(sch, classid);
129}
130
131static struct tcf_proto __rcu **clsact_find_tcf(struct Qdisc *sch,
132 unsigned long cl)
133{
134 struct net_device *dev = qdisc_dev(sch);
135
136 switch (cl) {
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;
141 default:
142 return NULL;
143 }
144}
145
146static int clsact_init(struct Qdisc *sch, struct nlattr *opt)
147{
148 net_inc_ingress_queue();
149 net_inc_egress_queue();
150
151 sch->flags |= TCQ_F_CPUSTATS;
152
153 return 0;
154}
155
156static void clsact_destroy(struct Qdisc *sch)
157{
158 struct net_device *dev = qdisc_dev(sch);
159
160 tcf_destroy_chain(&dev->ingress_cl_list);
161 tcf_destroy_chain(&dev->egress_cl_list);
162
163 net_dec_ingress_queue();
164 net_dec_egress_queue();
165}
166
167static const struct Qdisc_class_ops clsact_class_ops = {
168 .leaf = ingress_leaf,
169 .get = clsact_get,
170 .put = ingress_put,
171 .walk = ingress_walk,
172 .tcf_chain = clsact_find_tcf,
92c075db 173 .tcf_cl_offload = clsact_cl_offload,
1f211a1b
DB
174 .bind_tcf = clsact_bind_filter,
175 .unbind_tcf = ingress_put,
176};
177
178static struct Qdisc_ops clsact_qdisc_ops __read_mostly = {
179 .cl_ops = &clsact_class_ops,
180 .id = "clsact",
181 .init = clsact_init,
182 .destroy = clsact_destroy,
183 .dump = ingress_dump,
184 .owner = THIS_MODULE,
185};
186
1da177e4
LT
187static int __init ingress_module_init(void)
188{
1f211a1b
DB
189 int ret;
190
191 ret = register_qdisc(&ingress_qdisc_ops);
192 if (!ret) {
193 ret = register_qdisc(&clsact_qdisc_ops);
194 if (ret)
195 unregister_qdisc(&ingress_qdisc_ops);
196 }
197
198 return ret;
1da177e4 199}
58f4df42 200
10297b99 201static void __exit ingress_module_exit(void)
1da177e4
LT
202{
203 unregister_qdisc(&ingress_qdisc_ops);
1f211a1b 204 unregister_qdisc(&clsact_qdisc_ops);
1da177e4 205}
58f4df42 206
d2788d34
DB
207module_init(ingress_module_init);
208module_exit(ingress_module_exit);
209
1f211a1b 210MODULE_ALIAS("sch_clsact");
1da177e4 211MODULE_LICENSE("GPL");