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