blob: 8fe6999b642ac3c039f40621f4ca123d129718c4 [file] [log] [blame]
Daniel Borkmann1f211a12016-01-07 22:29:47 +01001/* net/sched/sch_ingress.c - Ingress and clsact qdisc
2 *
Linus Torvalds1da177e2005-04-16 15:20:36 -07003 * 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
Linus Torvalds1da177e2005-04-16 15:20:36 -070011#include <linux/module.h>
12#include <linux/types.h>
Patrick McHardy0ba48052007-07-02 22:49:07 -070013#include <linux/list.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070014#include <linux/skbuff.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070015#include <linux/rtnetlink.h>
Daniel Borkmannd2788d32015-05-09 22:51:32 +020016
Arnaldo Carvalho de Melodc5fc572007-03-25 23:06:12 -070017#include <net/netlink.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070018#include <net/pkt_sched.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070019
Linus Torvalds1da177e2005-04-16 15:20:36 -070020static struct Qdisc *ingress_leaf(struct Qdisc *sch, unsigned long arg)
21{
22 return NULL;
23}
24
Patrick McHardy58f4df42008-01-21 00:11:01 -080025static unsigned long ingress_get(struct Qdisc *sch, u32 classid)
Linus Torvalds1da177e2005-04-16 15:20:36 -070026{
Linus Torvalds1da177e2005-04-16 15:20:36 -070027 return TC_H_MIN(classid) + 1;
28}
29
Daniel Borkmann92c075d2016-06-06 22:50:39 +020030static bool ingress_cl_offload(u32 classid)
31{
32 return true;
33}
34
Linus Torvalds1da177e2005-04-16 15:20:36 -070035static unsigned long ingress_bind_filter(struct Qdisc *sch,
Patrick McHardy58f4df42008-01-21 00:11:01 -080036 unsigned long parent, u32 classid)
Linus Torvalds1da177e2005-04-16 15:20:36 -070037{
38 return ingress_get(sch, classid);
39}
40
Linus Torvalds1da177e2005-04-16 15:20:36 -070041static void ingress_put(struct Qdisc *sch, unsigned long cl)
42{
43}
44
Patrick McHardy58f4df42008-01-21 00:11:01 -080045static void ingress_walk(struct Qdisc *sch, struct qdisc_walker *walker)
Linus Torvalds1da177e2005-04-16 15:20:36 -070046{
Linus Torvalds1da177e2005-04-16 15:20:36 -070047}
48
John Fastabend25d8c0d2014-09-12 20:05:27 -070049static struct tcf_proto __rcu **ingress_find_tcf(struct Qdisc *sch,
50 unsigned long cl)
Linus Torvalds1da177e2005-04-16 15:20:36 -070051{
Daniel Borkmannd2788d32015-05-09 22:51:32 +020052 struct net_device *dev = qdisc_dev(sch);
Linus Torvalds1da177e2005-04-16 15:20:36 -070053
Daniel Borkmannd2788d32015-05-09 22:51:32 +020054 return &dev->ingress_cl_list;
Linus Torvalds1da177e2005-04-16 15:20:36 -070055}
56
Daniel Borkmann45771392015-04-10 23:07:54 +020057static int ingress_init(struct Qdisc *sch, struct nlattr *opt)
58{
59 net_inc_ingress_queue();
Alexei Starovoitov087c1a62015-04-30 20:14:07 -070060 sch->flags |= TCQ_F_CPUSTATS;
Daniel Borkmann45771392015-04-10 23:07:54 +020061
62 return 0;
63}
64
Linus Torvalds1da177e2005-04-16 15:20:36 -070065static void ingress_destroy(struct Qdisc *sch)
66{
Daniel Borkmannd2788d32015-05-09 22:51:32 +020067 struct net_device *dev = qdisc_dev(sch);
Linus Torvalds1da177e2005-04-16 15:20:36 -070068
Daniel Borkmannd2788d32015-05-09 22:51:32 +020069 tcf_destroy_chain(&dev->ingress_cl_list);
Daniel Borkmann45771392015-04-10 23:07:54 +020070 net_dec_ingress_queue();
Linus Torvalds1da177e2005-04-16 15:20:36 -070071}
72
Linus Torvalds1da177e2005-04-16 15:20:36 -070073static int ingress_dump(struct Qdisc *sch, struct sk_buff *skb)
74{
Patrick McHardy4b3550ef2008-01-23 20:34:11 -080075 struct nlattr *nest;
Linus Torvalds1da177e2005-04-16 15:20:36 -070076
Patrick McHardy4b3550ef2008-01-23 20:34:11 -080077 nest = nla_nest_start(skb, TCA_OPTIONS);
78 if (nest == NULL)
79 goto nla_put_failure;
Daniel Borkmannd2788d32015-05-09 22:51:32 +020080
Yang Yingliangd59b7d82014-03-12 10:20:32 +080081 return nla_nest_end(skb, nest);
Linus Torvalds1da177e2005-04-16 15:20:36 -070082
Patrick McHardy1e904742008-01-22 22:11:17 -080083nla_put_failure:
Patrick McHardy4b3550ef2008-01-23 20:34:11 -080084 nla_nest_cancel(skb, nest);
Linus Torvalds1da177e2005-04-16 15:20:36 -070085 return -1;
86}
87
Eric Dumazet20fea082007-11-14 01:44:41 -080088static const struct Qdisc_class_ops ingress_class_ops = {
Linus Torvalds1da177e2005-04-16 15:20:36 -070089 .leaf = ingress_leaf,
90 .get = ingress_get,
91 .put = ingress_put,
Linus Torvalds1da177e2005-04-16 15:20:36 -070092 .walk = ingress_walk,
93 .tcf_chain = ingress_find_tcf,
Daniel Borkmann92c075d2016-06-06 22:50:39 +020094 .tcf_cl_offload = ingress_cl_offload,
Linus Torvalds1da177e2005-04-16 15:20:36 -070095 .bind_tcf = ingress_bind_filter,
96 .unbind_tcf = ingress_put,
Linus Torvalds1da177e2005-04-16 15:20:36 -070097};
98
Eric Dumazet20fea082007-11-14 01:44:41 -080099static struct Qdisc_ops ingress_qdisc_ops __read_mostly = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700100 .cl_ops = &ingress_class_ops,
101 .id = "ingress",
Daniel Borkmann45771392015-04-10 23:07:54 +0200102 .init = ingress_init,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700103 .destroy = ingress_destroy,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700104 .dump = ingress_dump,
105 .owner = THIS_MODULE,
106};
107
Daniel Borkmann1f211a12016-01-07 22:29:47 +0100108static unsigned long clsact_get(struct Qdisc *sch, u32 classid)
109{
110 switch (TC_H_MIN(classid)) {
111 case TC_H_MIN(TC_H_MIN_INGRESS):
112 case TC_H_MIN(TC_H_MIN_EGRESS):
113 return TC_H_MIN(classid);
114 default:
115 return 0;
116 }
117}
118
Daniel Borkmann92c075d2016-06-06 22:50:39 +0200119static bool clsact_cl_offload(u32 classid)
120{
121 return TC_H_MIN(classid) == TC_H_MIN(TC_H_MIN_INGRESS);
122}
123
Daniel Borkmann1f211a12016-01-07 22:29:47 +0100124static unsigned long clsact_bind_filter(struct Qdisc *sch,
125 unsigned long parent, u32 classid)
126{
127 return clsact_get(sch, classid);
128}
129
130static struct tcf_proto __rcu **clsact_find_tcf(struct Qdisc *sch,
131 unsigned long cl)
132{
133 struct net_device *dev = qdisc_dev(sch);
134
135 switch (cl) {
136 case TC_H_MIN(TC_H_MIN_INGRESS):
137 return &dev->ingress_cl_list;
138 case TC_H_MIN(TC_H_MIN_EGRESS):
139 return &dev->egress_cl_list;
140 default:
141 return NULL;
142 }
143}
144
145static int clsact_init(struct Qdisc *sch, struct nlattr *opt)
146{
147 net_inc_ingress_queue();
148 net_inc_egress_queue();
149
150 sch->flags |= TCQ_F_CPUSTATS;
151
152 return 0;
153}
154
155static void clsact_destroy(struct Qdisc *sch)
156{
157 struct net_device *dev = qdisc_dev(sch);
158
159 tcf_destroy_chain(&dev->ingress_cl_list);
160 tcf_destroy_chain(&dev->egress_cl_list);
161
162 net_dec_ingress_queue();
163 net_dec_egress_queue();
164}
165
166static const struct Qdisc_class_ops clsact_class_ops = {
167 .leaf = ingress_leaf,
168 .get = clsact_get,
169 .put = ingress_put,
170 .walk = ingress_walk,
171 .tcf_chain = clsact_find_tcf,
Daniel Borkmann92c075d2016-06-06 22:50:39 +0200172 .tcf_cl_offload = clsact_cl_offload,
Daniel Borkmann1f211a12016-01-07 22:29:47 +0100173 .bind_tcf = clsact_bind_filter,
174 .unbind_tcf = ingress_put,
175};
176
177static struct Qdisc_ops clsact_qdisc_ops __read_mostly = {
178 .cl_ops = &clsact_class_ops,
179 .id = "clsact",
180 .init = clsact_init,
181 .destroy = clsact_destroy,
182 .dump = ingress_dump,
183 .owner = THIS_MODULE,
184};
185
Linus Torvalds1da177e2005-04-16 15:20:36 -0700186static int __init ingress_module_init(void)
187{
Daniel Borkmann1f211a12016-01-07 22:29:47 +0100188 int ret;
189
190 ret = register_qdisc(&ingress_qdisc_ops);
191 if (!ret) {
192 ret = register_qdisc(&clsact_qdisc_ops);
193 if (ret)
194 unregister_qdisc(&ingress_qdisc_ops);
195 }
196
197 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700198}
Patrick McHardy58f4df42008-01-21 00:11:01 -0800199
YOSHIFUJI Hideaki10297b92007-02-09 23:25:16 +0900200static void __exit ingress_module_exit(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700201{
202 unregister_qdisc(&ingress_qdisc_ops);
Daniel Borkmann1f211a12016-01-07 22:29:47 +0100203 unregister_qdisc(&clsact_qdisc_ops);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700204}
Patrick McHardy58f4df42008-01-21 00:11:01 -0800205
Daniel Borkmannd2788d32015-05-09 22:51:32 +0200206module_init(ingress_module_init);
207module_exit(ingress_module_exit);
208
Daniel Borkmann1f211a12016-01-07 22:29:47 +0100209MODULE_ALIAS("sch_clsact");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700210MODULE_LICENSE("GPL");