]>
Commit | Line | Data |
---|---|---|
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 | |
6529eaba JP |
21 | struct ingress_sched_data { |
22 | struct tcf_block *block; | |
6e40cf2d | 23 | struct tcf_block_ext_info block_info; |
46209401 | 24 | struct mini_Qdisc_pair miniqp; |
6529eaba JP |
25 | }; |
26 | ||
1da177e4 LT |
27 | static struct Qdisc *ingress_leaf(struct Qdisc *sch, unsigned long arg) |
28 | { | |
29 | return NULL; | |
30 | } | |
31 | ||
143976ce | 32 | static unsigned long ingress_find(struct Qdisc *sch, u32 classid) |
1da177e4 | 33 | { |
1da177e4 LT |
34 | return TC_H_MIN(classid) + 1; |
35 | } | |
36 | ||
1da177e4 | 37 | static unsigned long ingress_bind_filter(struct Qdisc *sch, |
58f4df42 | 38 | unsigned long parent, u32 classid) |
1da177e4 | 39 | { |
143976ce | 40 | return ingress_find(sch, classid); |
1da177e4 LT |
41 | } |
42 | ||
143976ce | 43 | static void ingress_unbind_filter(struct Qdisc *sch, unsigned long cl) |
1da177e4 LT |
44 | { |
45 | } | |
46 | ||
58f4df42 | 47 | static void ingress_walk(struct Qdisc *sch, struct qdisc_walker *walker) |
1da177e4 | 48 | { |
1da177e4 LT |
49 | } |
50 | ||
cbaacc4e AA |
51 | static struct tcf_block *ingress_tcf_block(struct Qdisc *sch, unsigned long cl, |
52 | struct netlink_ext_ack *extack) | |
1da177e4 | 53 | { |
6529eaba | 54 | struct ingress_sched_data *q = qdisc_priv(sch); |
1da177e4 | 55 | |
6529eaba | 56 | return q->block; |
1da177e4 LT |
57 | } |
58 | ||
c7eb7d72 JP |
59 | static void clsact_chain_head_change(struct tcf_proto *tp_head, void *priv) |
60 | { | |
46209401 | 61 | struct mini_Qdisc_pair *miniqp = priv; |
c7eb7d72 | 62 | |
46209401 | 63 | mini_qdisc_pair_swap(miniqp, tp_head); |
51ab2994 JP |
64 | }; |
65 | ||
66 | static void ingress_ingress_block_set(struct Qdisc *sch, u32 block_index) | |
67 | { | |
68 | struct ingress_sched_data *q = qdisc_priv(sch); | |
69 | ||
70 | q->block_info.block_index = block_index; | |
71 | } | |
72 | ||
73 | static u32 ingress_ingress_block_get(struct Qdisc *sch) | |
74 | { | |
75 | struct ingress_sched_data *q = qdisc_priv(sch); | |
76 | ||
77 | return q->block_info.block_index; | |
c7eb7d72 JP |
78 | } |
79 | ||
e63d7dfd AA |
80 | static int ingress_init(struct Qdisc *sch, struct nlattr *opt, |
81 | struct netlink_ext_ack *extack) | |
4577139b | 82 | { |
6529eaba JP |
83 | struct ingress_sched_data *q = qdisc_priv(sch); |
84 | struct net_device *dev = qdisc_dev(sch); | |
6529eaba | 85 | |
b59e6979 JP |
86 | net_inc_ingress_queue(); |
87 | ||
46209401 JP |
88 | mini_qdisc_pair_init(&q->miniqp, sch, &dev->miniq_ingress); |
89 | ||
6e40cf2d | 90 | q->block_info.binder_type = TCF_BLOCK_BINDER_TYPE_CLSACT_INGRESS; |
c7eb7d72 | 91 | q->block_info.chain_head_change = clsact_chain_head_change; |
46209401 | 92 | q->block_info.chain_head_change_priv = &q->miniqp; |
6e40cf2d | 93 | |
c02b3741 | 94 | return tcf_block_get_ext(&q->block, sch, &q->block_info, extack); |
4577139b DB |
95 | } |
96 | ||
1da177e4 LT |
97 | static void ingress_destroy(struct Qdisc *sch) |
98 | { | |
6529eaba | 99 | struct ingress_sched_data *q = qdisc_priv(sch); |
1da177e4 | 100 | |
c7eb7d72 | 101 | tcf_block_put_ext(q->block, sch, &q->block_info); |
4577139b | 102 | net_dec_ingress_queue(); |
1da177e4 LT |
103 | } |
104 | ||
1da177e4 LT |
105 | static int ingress_dump(struct Qdisc *sch, struct sk_buff *skb) |
106 | { | |
4b3550ef | 107 | struct nlattr *nest; |
1da177e4 | 108 | |
4b3550ef PM |
109 | nest = nla_nest_start(skb, TCA_OPTIONS); |
110 | if (nest == NULL) | |
111 | goto nla_put_failure; | |
d2788d34 | 112 | |
d59b7d80 | 113 | return nla_nest_end(skb, nest); |
1da177e4 | 114 | |
1e90474c | 115 | nla_put_failure: |
4b3550ef | 116 | nla_nest_cancel(skb, nest); |
1da177e4 LT |
117 | return -1; |
118 | } | |
119 | ||
20fea08b | 120 | static const struct Qdisc_class_ops ingress_class_ops = { |
1da177e4 | 121 | .leaf = ingress_leaf, |
143976ce | 122 | .find = ingress_find, |
1da177e4 | 123 | .walk = ingress_walk, |
6529eaba | 124 | .tcf_block = ingress_tcf_block, |
1da177e4 | 125 | .bind_tcf = ingress_bind_filter, |
143976ce | 126 | .unbind_tcf = ingress_unbind_filter, |
1da177e4 LT |
127 | }; |
128 | ||
20fea08b | 129 | static struct Qdisc_ops ingress_qdisc_ops __read_mostly = { |
51ab2994 JP |
130 | .cl_ops = &ingress_class_ops, |
131 | .id = "ingress", | |
132 | .priv_size = sizeof(struct ingress_sched_data), | |
133 | .static_flags = TCQ_F_CPUSTATS, | |
134 | .init = ingress_init, | |
135 | .destroy = ingress_destroy, | |
136 | .dump = ingress_dump, | |
137 | .ingress_block_set = ingress_ingress_block_set, | |
138 | .ingress_block_get = ingress_ingress_block_get, | |
139 | .owner = THIS_MODULE, | |
1da177e4 LT |
140 | }; |
141 | ||
6529eaba JP |
142 | struct clsact_sched_data { |
143 | struct tcf_block *ingress_block; | |
144 | struct tcf_block *egress_block; | |
6e40cf2d JP |
145 | struct tcf_block_ext_info ingress_block_info; |
146 | struct tcf_block_ext_info egress_block_info; | |
46209401 JP |
147 | struct mini_Qdisc_pair miniqp_ingress; |
148 | struct mini_Qdisc_pair miniqp_egress; | |
6529eaba JP |
149 | }; |
150 | ||
143976ce | 151 | static unsigned long clsact_find(struct Qdisc *sch, u32 classid) |
1f211a1b DB |
152 | { |
153 | switch (TC_H_MIN(classid)) { | |
154 | case TC_H_MIN(TC_H_MIN_INGRESS): | |
155 | case TC_H_MIN(TC_H_MIN_EGRESS): | |
156 | return TC_H_MIN(classid); | |
157 | default: | |
158 | return 0; | |
159 | } | |
160 | } | |
161 | ||
162 | static unsigned long clsact_bind_filter(struct Qdisc *sch, | |
163 | unsigned long parent, u32 classid) | |
164 | { | |
143976ce | 165 | return clsact_find(sch, classid); |
1f211a1b DB |
166 | } |
167 | ||
cbaacc4e AA |
168 | static struct tcf_block *clsact_tcf_block(struct Qdisc *sch, unsigned long cl, |
169 | struct netlink_ext_ack *extack) | |
1f211a1b | 170 | { |
6529eaba | 171 | struct clsact_sched_data *q = qdisc_priv(sch); |
1f211a1b DB |
172 | |
173 | switch (cl) { | |
174 | case TC_H_MIN(TC_H_MIN_INGRESS): | |
6529eaba | 175 | return q->ingress_block; |
1f211a1b | 176 | case TC_H_MIN(TC_H_MIN_EGRESS): |
6529eaba | 177 | return q->egress_block; |
1f211a1b DB |
178 | default: |
179 | return NULL; | |
180 | } | |
181 | } | |
182 | ||
51ab2994 JP |
183 | static void clsact_ingress_block_set(struct Qdisc *sch, u32 block_index) |
184 | { | |
185 | struct clsact_sched_data *q = qdisc_priv(sch); | |
186 | ||
187 | q->ingress_block_info.block_index = block_index; | |
188 | } | |
189 | ||
190 | static void clsact_egress_block_set(struct Qdisc *sch, u32 block_index) | |
191 | { | |
192 | struct clsact_sched_data *q = qdisc_priv(sch); | |
193 | ||
194 | q->egress_block_info.block_index = block_index; | |
195 | } | |
196 | ||
197 | static u32 clsact_ingress_block_get(struct Qdisc *sch) | |
198 | { | |
199 | struct clsact_sched_data *q = qdisc_priv(sch); | |
200 | ||
201 | return q->ingress_block_info.block_index; | |
202 | } | |
203 | ||
204 | static u32 clsact_egress_block_get(struct Qdisc *sch) | |
205 | { | |
206 | struct clsact_sched_data *q = qdisc_priv(sch); | |
207 | ||
208 | return q->egress_block_info.block_index; | |
209 | } | |
210 | ||
e63d7dfd AA |
211 | static int clsact_init(struct Qdisc *sch, struct nlattr *opt, |
212 | struct netlink_ext_ack *extack) | |
1f211a1b | 213 | { |
6529eaba JP |
214 | struct clsact_sched_data *q = qdisc_priv(sch); |
215 | struct net_device *dev = qdisc_dev(sch); | |
216 | int err; | |
217 | ||
b59e6979 JP |
218 | net_inc_ingress_queue(); |
219 | net_inc_egress_queue(); | |
220 | ||
46209401 JP |
221 | mini_qdisc_pair_init(&q->miniqp_ingress, sch, &dev->miniq_ingress); |
222 | ||
6e40cf2d | 223 | q->ingress_block_info.binder_type = TCF_BLOCK_BINDER_TYPE_CLSACT_INGRESS; |
c7eb7d72 | 224 | q->ingress_block_info.chain_head_change = clsact_chain_head_change; |
46209401 | 225 | q->ingress_block_info.chain_head_change_priv = &q->miniqp_ingress; |
6e40cf2d | 226 | |
8d1a77f9 AA |
227 | err = tcf_block_get_ext(&q->ingress_block, sch, &q->ingress_block_info, |
228 | extack); | |
6529eaba JP |
229 | if (err) |
230 | return err; | |
231 | ||
46209401 JP |
232 | mini_qdisc_pair_init(&q->miniqp_egress, sch, &dev->miniq_egress); |
233 | ||
6e40cf2d | 234 | q->egress_block_info.binder_type = TCF_BLOCK_BINDER_TYPE_CLSACT_EGRESS; |
c7eb7d72 | 235 | q->egress_block_info.chain_head_change = clsact_chain_head_change; |
46209401 | 236 | q->egress_block_info.chain_head_change_priv = &q->miniqp_egress; |
6e40cf2d | 237 | |
c02b3741 | 238 | return tcf_block_get_ext(&q->egress_block, sch, &q->egress_block_info, extack); |
1f211a1b DB |
239 | } |
240 | ||
241 | static void clsact_destroy(struct Qdisc *sch) | |
242 | { | |
6529eaba | 243 | struct clsact_sched_data *q = qdisc_priv(sch); |
1f211a1b | 244 | |
c7eb7d72 JP |
245 | tcf_block_put_ext(q->egress_block, sch, &q->egress_block_info); |
246 | tcf_block_put_ext(q->ingress_block, sch, &q->ingress_block_info); | |
1f211a1b DB |
247 | |
248 | net_dec_ingress_queue(); | |
249 | net_dec_egress_queue(); | |
250 | } | |
251 | ||
252 | static const struct Qdisc_class_ops clsact_class_ops = { | |
253 | .leaf = ingress_leaf, | |
143976ce | 254 | .find = clsact_find, |
1f211a1b | 255 | .walk = ingress_walk, |
6529eaba | 256 | .tcf_block = clsact_tcf_block, |
1f211a1b | 257 | .bind_tcf = clsact_bind_filter, |
143976ce | 258 | .unbind_tcf = ingress_unbind_filter, |
1f211a1b DB |
259 | }; |
260 | ||
261 | static struct Qdisc_ops clsact_qdisc_ops __read_mostly = { | |
51ab2994 JP |
262 | .cl_ops = &clsact_class_ops, |
263 | .id = "clsact", | |
264 | .priv_size = sizeof(struct clsact_sched_data), | |
265 | .static_flags = TCQ_F_CPUSTATS, | |
266 | .init = clsact_init, | |
267 | .destroy = clsact_destroy, | |
268 | .dump = ingress_dump, | |
269 | .ingress_block_set = clsact_ingress_block_set, | |
270 | .egress_block_set = clsact_egress_block_set, | |
271 | .ingress_block_get = clsact_ingress_block_get, | |
272 | .egress_block_get = clsact_egress_block_get, | |
273 | .owner = THIS_MODULE, | |
1f211a1b DB |
274 | }; |
275 | ||
1da177e4 LT |
276 | static int __init ingress_module_init(void) |
277 | { | |
1f211a1b DB |
278 | int ret; |
279 | ||
280 | ret = register_qdisc(&ingress_qdisc_ops); | |
281 | if (!ret) { | |
282 | ret = register_qdisc(&clsact_qdisc_ops); | |
283 | if (ret) | |
284 | unregister_qdisc(&ingress_qdisc_ops); | |
285 | } | |
286 | ||
287 | return ret; | |
1da177e4 | 288 | } |
58f4df42 | 289 | |
10297b99 | 290 | static void __exit ingress_module_exit(void) |
1da177e4 LT |
291 | { |
292 | unregister_qdisc(&ingress_qdisc_ops); | |
1f211a1b | 293 | unregister_qdisc(&clsact_qdisc_ops); |
1da177e4 | 294 | } |
58f4df42 | 295 | |
d2788d34 DB |
296 | module_init(ingress_module_init); |
297 | module_exit(ingress_module_exit); | |
298 | ||
1f211a1b | 299 | MODULE_ALIAS("sch_clsact"); |
1da177e4 | 300 | MODULE_LICENSE("GPL"); |