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 | ||
6529eaba | 51 | static struct tcf_block *ingress_tcf_block(struct Qdisc *sch, unsigned long cl) |
1da177e4 | 52 | { |
6529eaba | 53 | struct ingress_sched_data *q = qdisc_priv(sch); |
1da177e4 | 54 | |
6529eaba | 55 | return q->block; |
1da177e4 LT |
56 | } |
57 | ||
c7eb7d72 JP |
58 | static void clsact_chain_head_change(struct tcf_proto *tp_head, void *priv) |
59 | { | |
46209401 | 60 | struct mini_Qdisc_pair *miniqp = priv; |
c7eb7d72 | 61 | |
46209401 | 62 | mini_qdisc_pair_swap(miniqp, tp_head); |
c7eb7d72 JP |
63 | } |
64 | ||
4577139b DB |
65 | static int ingress_init(struct Qdisc *sch, struct nlattr *opt) |
66 | { | |
6529eaba JP |
67 | struct ingress_sched_data *q = qdisc_priv(sch); |
68 | struct net_device *dev = qdisc_dev(sch); | |
69 | int err; | |
70 | ||
b59e6979 JP |
71 | net_inc_ingress_queue(); |
72 | ||
46209401 JP |
73 | mini_qdisc_pair_init(&q->miniqp, sch, &dev->miniq_ingress); |
74 | ||
6e40cf2d | 75 | q->block_info.binder_type = TCF_BLOCK_BINDER_TYPE_CLSACT_INGRESS; |
c7eb7d72 | 76 | q->block_info.chain_head_change = clsact_chain_head_change; |
46209401 | 77 | q->block_info.chain_head_change_priv = &q->miniqp; |
6e40cf2d | 78 | |
c7eb7d72 | 79 | err = tcf_block_get_ext(&q->block, sch, &q->block_info); |
6529eaba JP |
80 | if (err) |
81 | return err; | |
82 | ||
087c1a60 | 83 | sch->flags |= TCQ_F_CPUSTATS; |
4577139b DB |
84 | |
85 | return 0; | |
86 | } | |
87 | ||
1da177e4 LT |
88 | static void ingress_destroy(struct Qdisc *sch) |
89 | { | |
6529eaba | 90 | struct ingress_sched_data *q = qdisc_priv(sch); |
1da177e4 | 91 | |
c7eb7d72 | 92 | tcf_block_put_ext(q->block, sch, &q->block_info); |
4577139b | 93 | net_dec_ingress_queue(); |
1da177e4 LT |
94 | } |
95 | ||
1da177e4 LT |
96 | static int ingress_dump(struct Qdisc *sch, struct sk_buff *skb) |
97 | { | |
4b3550ef | 98 | struct nlattr *nest; |
1da177e4 | 99 | |
4b3550ef PM |
100 | nest = nla_nest_start(skb, TCA_OPTIONS); |
101 | if (nest == NULL) | |
102 | goto nla_put_failure; | |
d2788d34 | 103 | |
d59b7d80 | 104 | return nla_nest_end(skb, nest); |
1da177e4 | 105 | |
1e90474c | 106 | nla_put_failure: |
4b3550ef | 107 | nla_nest_cancel(skb, nest); |
1da177e4 LT |
108 | return -1; |
109 | } | |
110 | ||
20fea08b | 111 | static const struct Qdisc_class_ops ingress_class_ops = { |
1da177e4 | 112 | .leaf = ingress_leaf, |
143976ce | 113 | .find = ingress_find, |
1da177e4 | 114 | .walk = ingress_walk, |
6529eaba | 115 | .tcf_block = ingress_tcf_block, |
1da177e4 | 116 | .bind_tcf = ingress_bind_filter, |
143976ce | 117 | .unbind_tcf = ingress_unbind_filter, |
1da177e4 LT |
118 | }; |
119 | ||
20fea08b | 120 | static struct Qdisc_ops ingress_qdisc_ops __read_mostly = { |
1da177e4 LT |
121 | .cl_ops = &ingress_class_ops, |
122 | .id = "ingress", | |
6529eaba | 123 | .priv_size = sizeof(struct ingress_sched_data), |
4577139b | 124 | .init = ingress_init, |
1da177e4 | 125 | .destroy = ingress_destroy, |
1da177e4 LT |
126 | .dump = ingress_dump, |
127 | .owner = THIS_MODULE, | |
128 | }; | |
129 | ||
6529eaba JP |
130 | struct clsact_sched_data { |
131 | struct tcf_block *ingress_block; | |
132 | struct tcf_block *egress_block; | |
6e40cf2d JP |
133 | struct tcf_block_ext_info ingress_block_info; |
134 | struct tcf_block_ext_info egress_block_info; | |
46209401 JP |
135 | struct mini_Qdisc_pair miniqp_ingress; |
136 | struct mini_Qdisc_pair miniqp_egress; | |
6529eaba JP |
137 | }; |
138 | ||
143976ce | 139 | static unsigned long clsact_find(struct Qdisc *sch, u32 classid) |
1f211a1b DB |
140 | { |
141 | switch (TC_H_MIN(classid)) { | |
142 | case TC_H_MIN(TC_H_MIN_INGRESS): | |
143 | case TC_H_MIN(TC_H_MIN_EGRESS): | |
144 | return TC_H_MIN(classid); | |
145 | default: | |
146 | return 0; | |
147 | } | |
148 | } | |
149 | ||
150 | static unsigned long clsact_bind_filter(struct Qdisc *sch, | |
151 | unsigned long parent, u32 classid) | |
152 | { | |
143976ce | 153 | return clsact_find(sch, classid); |
1f211a1b DB |
154 | } |
155 | ||
6529eaba | 156 | static struct tcf_block *clsact_tcf_block(struct Qdisc *sch, unsigned long cl) |
1f211a1b | 157 | { |
6529eaba | 158 | struct clsact_sched_data *q = qdisc_priv(sch); |
1f211a1b DB |
159 | |
160 | switch (cl) { | |
161 | case TC_H_MIN(TC_H_MIN_INGRESS): | |
6529eaba | 162 | return q->ingress_block; |
1f211a1b | 163 | case TC_H_MIN(TC_H_MIN_EGRESS): |
6529eaba | 164 | return q->egress_block; |
1f211a1b DB |
165 | default: |
166 | return NULL; | |
167 | } | |
168 | } | |
169 | ||
170 | static int clsact_init(struct Qdisc *sch, struct nlattr *opt) | |
171 | { | |
6529eaba JP |
172 | struct clsact_sched_data *q = qdisc_priv(sch); |
173 | struct net_device *dev = qdisc_dev(sch); | |
174 | int err; | |
175 | ||
b59e6979 JP |
176 | net_inc_ingress_queue(); |
177 | net_inc_egress_queue(); | |
178 | ||
46209401 JP |
179 | mini_qdisc_pair_init(&q->miniqp_ingress, sch, &dev->miniq_ingress); |
180 | ||
6e40cf2d | 181 | q->ingress_block_info.binder_type = TCF_BLOCK_BINDER_TYPE_CLSACT_INGRESS; |
c7eb7d72 | 182 | q->ingress_block_info.chain_head_change = clsact_chain_head_change; |
46209401 | 183 | q->ingress_block_info.chain_head_change_priv = &q->miniqp_ingress; |
6e40cf2d | 184 | |
c7eb7d72 | 185 | err = tcf_block_get_ext(&q->ingress_block, sch, &q->ingress_block_info); |
6529eaba JP |
186 | if (err) |
187 | return err; | |
188 | ||
46209401 JP |
189 | mini_qdisc_pair_init(&q->miniqp_egress, sch, &dev->miniq_egress); |
190 | ||
6e40cf2d | 191 | q->egress_block_info.binder_type = TCF_BLOCK_BINDER_TYPE_CLSACT_EGRESS; |
c7eb7d72 | 192 | q->egress_block_info.chain_head_change = clsact_chain_head_change; |
46209401 | 193 | q->egress_block_info.chain_head_change_priv = &q->miniqp_egress; |
6e40cf2d | 194 | |
c7eb7d72 | 195 | err = tcf_block_get_ext(&q->egress_block, sch, &q->egress_block_info); |
6529eaba | 196 | if (err) |
343723dd | 197 | return err; |
6529eaba | 198 | |
1f211a1b DB |
199 | sch->flags |= TCQ_F_CPUSTATS; |
200 | ||
201 | return 0; | |
202 | } | |
203 | ||
204 | static void clsact_destroy(struct Qdisc *sch) | |
205 | { | |
6529eaba | 206 | struct clsact_sched_data *q = qdisc_priv(sch); |
1f211a1b | 207 | |
c7eb7d72 JP |
208 | tcf_block_put_ext(q->egress_block, sch, &q->egress_block_info); |
209 | tcf_block_put_ext(q->ingress_block, sch, &q->ingress_block_info); | |
1f211a1b DB |
210 | |
211 | net_dec_ingress_queue(); | |
212 | net_dec_egress_queue(); | |
213 | } | |
214 | ||
215 | static const struct Qdisc_class_ops clsact_class_ops = { | |
216 | .leaf = ingress_leaf, | |
143976ce | 217 | .find = clsact_find, |
1f211a1b | 218 | .walk = ingress_walk, |
6529eaba | 219 | .tcf_block = clsact_tcf_block, |
1f211a1b | 220 | .bind_tcf = clsact_bind_filter, |
143976ce | 221 | .unbind_tcf = ingress_unbind_filter, |
1f211a1b DB |
222 | }; |
223 | ||
224 | static struct Qdisc_ops clsact_qdisc_ops __read_mostly = { | |
225 | .cl_ops = &clsact_class_ops, | |
226 | .id = "clsact", | |
6529eaba | 227 | .priv_size = sizeof(struct clsact_sched_data), |
1f211a1b DB |
228 | .init = clsact_init, |
229 | .destroy = clsact_destroy, | |
230 | .dump = ingress_dump, | |
231 | .owner = THIS_MODULE, | |
232 | }; | |
233 | ||
1da177e4 LT |
234 | static int __init ingress_module_init(void) |
235 | { | |
1f211a1b DB |
236 | int ret; |
237 | ||
238 | ret = register_qdisc(&ingress_qdisc_ops); | |
239 | if (!ret) { | |
240 | ret = register_qdisc(&clsact_qdisc_ops); | |
241 | if (ret) | |
242 | unregister_qdisc(&ingress_qdisc_ops); | |
243 | } | |
244 | ||
245 | return ret; | |
1da177e4 | 246 | } |
58f4df42 | 247 | |
10297b99 | 248 | static void __exit ingress_module_exit(void) |
1da177e4 LT |
249 | { |
250 | unregister_qdisc(&ingress_qdisc_ops); | |
1f211a1b | 251 | unregister_qdisc(&clsact_qdisc_ops); |
1da177e4 | 252 | } |
58f4df42 | 253 | |
d2788d34 DB |
254 | module_init(ingress_module_init); |
255 | module_exit(ingress_module_exit); | |
256 | ||
1f211a1b | 257 | MODULE_ALIAS("sch_clsact"); |
1da177e4 | 258 | MODULE_LICENSE("GPL"); |