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; | |
23 | }; | |
24 | ||
1da177e4 LT |
25 | static struct Qdisc *ingress_leaf(struct Qdisc *sch, unsigned long arg) |
26 | { | |
27 | return NULL; | |
28 | } | |
29 | ||
143976ce | 30 | static unsigned long ingress_find(struct Qdisc *sch, u32 classid) |
1da177e4 | 31 | { |
1da177e4 LT |
32 | return TC_H_MIN(classid) + 1; |
33 | } | |
34 | ||
1da177e4 | 35 | static unsigned long ingress_bind_filter(struct Qdisc *sch, |
58f4df42 | 36 | unsigned long parent, u32 classid) |
1da177e4 | 37 | { |
143976ce | 38 | return ingress_find(sch, classid); |
1da177e4 LT |
39 | } |
40 | ||
143976ce | 41 | static void ingress_unbind_filter(struct Qdisc *sch, unsigned long cl) |
1da177e4 LT |
42 | { |
43 | } | |
44 | ||
58f4df42 | 45 | static void ingress_walk(struct Qdisc *sch, struct qdisc_walker *walker) |
1da177e4 | 46 | { |
1da177e4 LT |
47 | } |
48 | ||
6529eaba | 49 | static struct tcf_block *ingress_tcf_block(struct Qdisc *sch, unsigned long cl) |
1da177e4 | 50 | { |
6529eaba | 51 | struct ingress_sched_data *q = qdisc_priv(sch); |
1da177e4 | 52 | |
6529eaba | 53 | return q->block; |
1da177e4 LT |
54 | } |
55 | ||
4577139b DB |
56 | static int ingress_init(struct Qdisc *sch, struct nlattr *opt) |
57 | { | |
6529eaba JP |
58 | struct ingress_sched_data *q = qdisc_priv(sch); |
59 | struct net_device *dev = qdisc_dev(sch); | |
60 | int err; | |
61 | ||
62 | err = tcf_block_get(&q->block, &dev->ingress_cl_list); | |
63 | if (err) | |
64 | return err; | |
65 | ||
4577139b | 66 | net_inc_ingress_queue(); |
087c1a60 | 67 | sch->flags |= TCQ_F_CPUSTATS; |
4577139b DB |
68 | |
69 | return 0; | |
70 | } | |
71 | ||
1da177e4 LT |
72 | static void ingress_destroy(struct Qdisc *sch) |
73 | { | |
6529eaba | 74 | struct ingress_sched_data *q = qdisc_priv(sch); |
1da177e4 | 75 | |
6529eaba | 76 | tcf_block_put(q->block); |
4577139b | 77 | net_dec_ingress_queue(); |
1da177e4 LT |
78 | } |
79 | ||
1da177e4 LT |
80 | static int ingress_dump(struct Qdisc *sch, struct sk_buff *skb) |
81 | { | |
4b3550ef | 82 | struct nlattr *nest; |
1da177e4 | 83 | |
4b3550ef PM |
84 | nest = nla_nest_start(skb, TCA_OPTIONS); |
85 | if (nest == NULL) | |
86 | goto nla_put_failure; | |
d2788d34 | 87 | |
d59b7d80 | 88 | return nla_nest_end(skb, nest); |
1da177e4 | 89 | |
1e90474c | 90 | nla_put_failure: |
4b3550ef | 91 | nla_nest_cancel(skb, nest); |
1da177e4 LT |
92 | return -1; |
93 | } | |
94 | ||
20fea08b | 95 | static const struct Qdisc_class_ops ingress_class_ops = { |
1da177e4 | 96 | .leaf = ingress_leaf, |
143976ce | 97 | .find = ingress_find, |
1da177e4 | 98 | .walk = ingress_walk, |
6529eaba | 99 | .tcf_block = ingress_tcf_block, |
1da177e4 | 100 | .bind_tcf = ingress_bind_filter, |
143976ce | 101 | .unbind_tcf = ingress_unbind_filter, |
1da177e4 LT |
102 | }; |
103 | ||
20fea08b | 104 | static struct Qdisc_ops ingress_qdisc_ops __read_mostly = { |
1da177e4 LT |
105 | .cl_ops = &ingress_class_ops, |
106 | .id = "ingress", | |
6529eaba | 107 | .priv_size = sizeof(struct ingress_sched_data), |
4577139b | 108 | .init = ingress_init, |
1da177e4 | 109 | .destroy = ingress_destroy, |
1da177e4 LT |
110 | .dump = ingress_dump, |
111 | .owner = THIS_MODULE, | |
112 | }; | |
113 | ||
6529eaba JP |
114 | struct clsact_sched_data { |
115 | struct tcf_block *ingress_block; | |
116 | struct tcf_block *egress_block; | |
117 | }; | |
118 | ||
143976ce | 119 | static unsigned long clsact_find(struct Qdisc *sch, u32 classid) |
1f211a1b DB |
120 | { |
121 | switch (TC_H_MIN(classid)) { | |
122 | case TC_H_MIN(TC_H_MIN_INGRESS): | |
123 | case TC_H_MIN(TC_H_MIN_EGRESS): | |
124 | return TC_H_MIN(classid); | |
125 | default: | |
126 | return 0; | |
127 | } | |
128 | } | |
129 | ||
130 | static unsigned long clsact_bind_filter(struct Qdisc *sch, | |
131 | unsigned long parent, u32 classid) | |
132 | { | |
143976ce | 133 | return clsact_find(sch, classid); |
1f211a1b DB |
134 | } |
135 | ||
6529eaba | 136 | static struct tcf_block *clsact_tcf_block(struct Qdisc *sch, unsigned long cl) |
1f211a1b | 137 | { |
6529eaba | 138 | struct clsact_sched_data *q = qdisc_priv(sch); |
1f211a1b DB |
139 | |
140 | switch (cl) { | |
141 | case TC_H_MIN(TC_H_MIN_INGRESS): | |
6529eaba | 142 | return q->ingress_block; |
1f211a1b | 143 | case TC_H_MIN(TC_H_MIN_EGRESS): |
6529eaba | 144 | return q->egress_block; |
1f211a1b DB |
145 | default: |
146 | return NULL; | |
147 | } | |
148 | } | |
149 | ||
150 | static int clsact_init(struct Qdisc *sch, struct nlattr *opt) | |
151 | { | |
6529eaba JP |
152 | struct clsact_sched_data *q = qdisc_priv(sch); |
153 | struct net_device *dev = qdisc_dev(sch); | |
154 | int err; | |
155 | ||
156 | err = tcf_block_get(&q->ingress_block, &dev->ingress_cl_list); | |
157 | if (err) | |
158 | return err; | |
159 | ||
160 | err = tcf_block_get(&q->egress_block, &dev->egress_cl_list); | |
161 | if (err) | |
162 | return err; | |
163 | ||
1f211a1b DB |
164 | net_inc_ingress_queue(); |
165 | net_inc_egress_queue(); | |
166 | ||
167 | sch->flags |= TCQ_F_CPUSTATS; | |
168 | ||
169 | return 0; | |
170 | } | |
171 | ||
172 | static void clsact_destroy(struct Qdisc *sch) | |
173 | { | |
6529eaba | 174 | struct clsact_sched_data *q = qdisc_priv(sch); |
1f211a1b | 175 | |
6529eaba JP |
176 | tcf_block_put(q->egress_block); |
177 | tcf_block_put(q->ingress_block); | |
1f211a1b DB |
178 | |
179 | net_dec_ingress_queue(); | |
180 | net_dec_egress_queue(); | |
181 | } | |
182 | ||
183 | static const struct Qdisc_class_ops clsact_class_ops = { | |
184 | .leaf = ingress_leaf, | |
143976ce | 185 | .find = clsact_find, |
1f211a1b | 186 | .walk = ingress_walk, |
6529eaba | 187 | .tcf_block = clsact_tcf_block, |
1f211a1b | 188 | .bind_tcf = clsact_bind_filter, |
143976ce | 189 | .unbind_tcf = ingress_unbind_filter, |
1f211a1b DB |
190 | }; |
191 | ||
192 | static struct Qdisc_ops clsact_qdisc_ops __read_mostly = { | |
193 | .cl_ops = &clsact_class_ops, | |
194 | .id = "clsact", | |
6529eaba | 195 | .priv_size = sizeof(struct clsact_sched_data), |
1f211a1b DB |
196 | .init = clsact_init, |
197 | .destroy = clsact_destroy, | |
198 | .dump = ingress_dump, | |
199 | .owner = THIS_MODULE, | |
200 | }; | |
201 | ||
1da177e4 LT |
202 | static int __init ingress_module_init(void) |
203 | { | |
1f211a1b DB |
204 | int ret; |
205 | ||
206 | ret = register_qdisc(&ingress_qdisc_ops); | |
207 | if (!ret) { | |
208 | ret = register_qdisc(&clsact_qdisc_ops); | |
209 | if (ret) | |
210 | unregister_qdisc(&ingress_qdisc_ops); | |
211 | } | |
212 | ||
213 | return ret; | |
1da177e4 | 214 | } |
58f4df42 | 215 | |
10297b99 | 216 | static void __exit ingress_module_exit(void) |
1da177e4 LT |
217 | { |
218 | unregister_qdisc(&ingress_qdisc_ops); | |
1f211a1b | 219 | unregister_qdisc(&clsact_qdisc_ops); |
1da177e4 | 220 | } |
58f4df42 | 221 | |
d2788d34 DB |
222 | module_init(ingress_module_init); |
223 | module_exit(ingress_module_exit); | |
224 | ||
1f211a1b | 225 | MODULE_ALIAS("sch_clsact"); |
1da177e4 | 226 | MODULE_LICENSE("GPL"); |