]> git.proxmox.com Git - mirror_ubuntu-bionic-kernel.git/blame - net/sched/sch_ingress.c
[NET_SCHED]: sch_ingress: remove excessive debugging
[mirror_ubuntu-bionic-kernel.git] / net / sched / sch_ingress.c
CommitLineData
10297b99 1/* net/sched/sch_ingress.c - Ingress qdisc
1da177e4
LT
2 * This program is free software; you can redistribute it and/or
3 * modify it under the terms of the GNU General Public License
4 * as published by the Free Software Foundation; either version
5 * 2 of the License, or (at your option) any later version.
6 *
7 * Authors: Jamal Hadi Salim 1999
8 */
9
1da177e4
LT
10#include <linux/module.h>
11#include <linux/types.h>
0ba48053 12#include <linux/list.h>
1da177e4 13#include <linux/skbuff.h>
1da177e4
LT
14#include <linux/rtnetlink.h>
15#include <linux/netfilter_ipv4.h>
16#include <linux/netfilter_ipv6.h>
17#include <linux/netfilter.h>
dc5fc579 18#include <net/netlink.h>
1da177e4 19#include <net/pkt_sched.h>
1da177e4
LT
20
21
1da177e4
LT
22#define PRIV(sch) qdisc_priv(sch)
23
58f4df42 24/* Thanks to Doron Oz for this hack */
1da177e4
LT
25#ifndef CONFIG_NET_CLS_ACT
26#ifdef CONFIG_NETFILTER
10297b99 27static int nf_registered;
1da177e4
LT
28#endif
29#endif
30
31struct ingress_qdisc_data {
32 struct Qdisc *q;
33 struct tcf_proto *filter_list;
34};
35
1da177e4
LT
36/* ------------------------- Class/flow operations ------------------------- */
37
58f4df42
PM
38static int ingress_graft(struct Qdisc *sch, unsigned long arg,
39 struct Qdisc *new, struct Qdisc **old)
1da177e4 40{
10297b99 41 return 1;
1da177e4
LT
42}
43
1da177e4
LT
44static struct Qdisc *ingress_leaf(struct Qdisc *sch, unsigned long arg)
45{
46 return NULL;
47}
48
58f4df42 49static unsigned long ingress_get(struct Qdisc *sch, u32 classid)
1da177e4 50{
1da177e4
LT
51 return TC_H_MIN(classid) + 1;
52}
53
1da177e4 54static unsigned long ingress_bind_filter(struct Qdisc *sch,
58f4df42 55 unsigned long parent, u32 classid)
1da177e4
LT
56{
57 return ingress_get(sch, classid);
58}
59
1da177e4
LT
60static void ingress_put(struct Qdisc *sch, unsigned long cl)
61{
62}
63
1da177e4 64static int ingress_change(struct Qdisc *sch, u32 classid, u32 parent,
58f4df42 65 struct rtattr **tca, unsigned long *arg)
1da177e4 66{
1da177e4
LT
67 return 0;
68}
69
58f4df42 70static void ingress_walk(struct Qdisc *sch, struct qdisc_walker *walker)
1da177e4 71{
a4781221 72 return;
1da177e4
LT
73}
74
58f4df42 75static struct tcf_proto **ingress_find_tcf(struct Qdisc *sch, unsigned long cl)
1da177e4
LT
76{
77 struct ingress_qdisc_data *p = PRIV(sch);
78
79 return &p->filter_list;
80}
81
1da177e4
LT
82/* --------------------------- Qdisc operations ---------------------------- */
83
58f4df42 84static int ingress_enqueue(struct sk_buff *skb, struct Qdisc *sch)
1da177e4
LT
85{
86 struct ingress_qdisc_data *p = PRIV(sch);
87 struct tcf_result res;
88 int result;
89
1da177e4 90 result = tc_classify(skb, p->filter_list, &res);
a4781221 91
1da177e4
LT
92 /*
93 * Unlike normal "enqueue" functions, ingress_enqueue returns a
94 * firewall FW_* code.
95 */
96#ifdef CONFIG_NET_CLS_ACT
97 sch->bstats.packets++;
98 sch->bstats.bytes += skb->len;
99 switch (result) {
58f4df42
PM
100 case TC_ACT_SHOT:
101 result = TC_ACT_SHOT;
102 sch->qstats.drops++;
103 break;
104 case TC_ACT_STOLEN:
105 case TC_ACT_QUEUED:
106 result = TC_ACT_STOLEN;
107 break;
108 case TC_ACT_RECLASSIFY:
109 case TC_ACT_OK:
110 skb->tc_index = TC_H_MIN(res.classid);
111 default:
112 result = TC_ACT_OK;
113 break;
3ff50b79 114 }
1da177e4 115#else
1da177e4
LT
116 result = NF_ACCEPT;
117 sch->bstats.packets++;
118 sch->bstats.bytes += skb->len;
1da177e4
LT
119#endif
120
121 return result;
122}
123
1da177e4
LT
124static struct sk_buff *ingress_dequeue(struct Qdisc *sch)
125{
1da177e4
LT
126 return NULL;
127}
128
58f4df42 129static int ingress_requeue(struct sk_buff *skb, struct Qdisc *sch)
1da177e4 130{
1da177e4
LT
131 return 0;
132}
133
134static unsigned int ingress_drop(struct Qdisc *sch)
135{
1da177e4
LT
136 return 0;
137}
138
139#ifndef CONFIG_NET_CLS_ACT
140#ifdef CONFIG_NETFILTER
58f4df42 141static unsigned int ing_hook(unsigned int hook, struct sk_buff *skb,
10297b99
YH
142 const struct net_device *indev,
143 const struct net_device *outdev,
144 int (*okfn)(struct sk_buff *))
1da177e4 145{
10297b99 146
1da177e4 147 struct Qdisc *q;
10297b99 148 struct net_device *dev = skb->dev;
58f4df42 149 int fwres = NF_ACCEPT;
1da177e4 150
1da177e4 151 if (dev->qdisc_ingress) {
fd44de7c 152 spin_lock(&dev->ingress_lock);
1da177e4
LT
153 if ((q = dev->qdisc_ingress) != NULL)
154 fwres = q->enqueue(skb, q);
fd44de7c 155 spin_unlock(&dev->ingress_lock);
10297b99
YH
156 }
157
1da177e4
LT
158 return fwres;
159}
160
161/* after ipt_filter */
1999414a 162static struct nf_hook_ops ing_ops[] __read_mostly = {
41c5b317
PM
163 {
164 .hook = ing_hook,
165 .owner = THIS_MODULE,
166 .pf = PF_INET,
167 .hooknum = NF_INET_PRE_ROUTING,
168 .priority = NF_IP_PRI_FILTER + 1,
169 },
170 {
171 .hook = ing_hook,
172 .owner = THIS_MODULE,
173 .pf = PF_INET6,
174 .hooknum = NF_INET_PRE_ROUTING,
175 .priority = NF_IP6_PRI_FILTER + 1,
176 },
1da177e4 177};
1da177e4
LT
178#endif
179#endif
180
58f4df42 181static int ingress_init(struct Qdisc *sch, struct rtattr *opt)
1da177e4
LT
182{
183 struct ingress_qdisc_data *p = PRIV(sch);
184
58f4df42
PM
185 /* Make sure either netfilter or preferably CLS_ACT is
186 * compiled in */
1da177e4
LT
187#ifndef CONFIG_NET_CLS_ACT
188#ifndef CONFIG_NETFILTER
189 printk("You MUST compile classifier actions into the kernel\n");
190 return -EINVAL;
191#else
192 printk("Ingress scheduler: Classifier actions prefered over netfilter\n");
193#endif
194#endif
10297b99 195
1da177e4
LT
196#ifndef CONFIG_NET_CLS_ACT
197#ifdef CONFIG_NETFILTER
198 if (!nf_registered) {
41c5b317 199 if (nf_register_hooks(ing_ops, ARRAY_SIZE(ing_ops)) < 0) {
1da177e4
LT
200 printk("ingress qdisc registration error \n");
201 return -EINVAL;
202 }
203 nf_registered++;
1da177e4
LT
204 }
205#endif
206#endif
1da177e4
LT
207 p->q = &noop_qdisc;
208 return 0;
209}
210
1da177e4
LT
211static void ingress_reset(struct Qdisc *sch)
212{
a4781221 213 return;
1da177e4
LT
214}
215
1da177e4
LT
216/* ------------------------------------------------------------- */
217
218static void ingress_destroy(struct Qdisc *sch)
219{
220 struct ingress_qdisc_data *p = PRIV(sch);
1da177e4 221
a48b5a61 222 tcf_destroy_chain(p->filter_list);
1da177e4
LT
223}
224
1da177e4
LT
225static int ingress_dump(struct Qdisc *sch, struct sk_buff *skb)
226{
27a884dc 227 unsigned char *b = skb_tail_pointer(skb);
1da177e4
LT
228 struct rtattr *rta;
229
58f4df42 230 rta = (struct rtattr *)b;
1da177e4 231 RTA_PUT(skb, TCA_OPTIONS, 0, NULL);
27a884dc 232 rta->rta_len = skb_tail_pointer(skb) - b;
1da177e4
LT
233 return skb->len;
234
235rtattr_failure:
dc5fc579 236 nlmsg_trim(skb, b);
1da177e4
LT
237 return -1;
238}
239
20fea08b 240static const struct Qdisc_class_ops ingress_class_ops = {
1da177e4
LT
241 .graft = ingress_graft,
242 .leaf = ingress_leaf,
243 .get = ingress_get,
244 .put = ingress_put,
245 .change = ingress_change,
1da177e4
LT
246 .walk = ingress_walk,
247 .tcf_chain = ingress_find_tcf,
248 .bind_tcf = ingress_bind_filter,
249 .unbind_tcf = ingress_put,
1da177e4
LT
250};
251
20fea08b 252static struct Qdisc_ops ingress_qdisc_ops __read_mostly = {
1da177e4
LT
253 .cl_ops = &ingress_class_ops,
254 .id = "ingress",
255 .priv_size = sizeof(struct ingress_qdisc_data),
256 .enqueue = ingress_enqueue,
257 .dequeue = ingress_dequeue,
258 .requeue = ingress_requeue,
259 .drop = ingress_drop,
260 .init = ingress_init,
261 .reset = ingress_reset,
262 .destroy = ingress_destroy,
1da177e4
LT
263 .dump = ingress_dump,
264 .owner = THIS_MODULE,
265};
266
267static int __init ingress_module_init(void)
268{
269 int ret = 0;
270
271 if ((ret = register_qdisc(&ingress_qdisc_ops)) < 0) {
272 printk("Unable to register Ingress qdisc\n");
273 return ret;
274 }
275
276 return ret;
277}
58f4df42 278
10297b99 279static void __exit ingress_module_exit(void)
1da177e4
LT
280{
281 unregister_qdisc(&ingress_qdisc_ops);
282#ifndef CONFIG_NET_CLS_ACT
283#ifdef CONFIG_NETFILTER
41c5b317
PM
284 if (nf_registered)
285 nf_unregister_hooks(ing_ops, ARRAY_SIZE(ing_ops));
1da177e4
LT
286#endif
287#endif
288}
58f4df42 289
1da177e4
LT
290module_init(ingress_module_init)
291module_exit(ingress_module_exit)
292MODULE_LICENSE("GPL");