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