sysctl: ipv6 route flushing (kill binary path)
[wrt350n-kernel.git] / net / sched / sch_ingress.c
blob3f8335e6ea2eb51acac63d034fd9664a215a447e
1 /* net/sched/sch_ingress.c - Ingress qdisc
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.
7 * Authors: Jamal Hadi Salim 1999
8 */
10 #include <linux/module.h>
11 #include <linux/types.h>
12 #include <linux/list.h>
13 #include <linux/skbuff.h>
14 #include <linux/rtnetlink.h>
15 #include <linux/netfilter_ipv4.h>
16 #include <linux/netfilter_ipv6.h>
17 #include <linux/netfilter.h>
18 #include <net/netlink.h>
19 #include <net/pkt_sched.h>
22 #undef DEBUG_INGRESS
24 #ifdef DEBUG_INGRESS /* control */
25 #define DPRINTK(format,args...) printk(KERN_DEBUG format,##args)
26 #else
27 #define DPRINTK(format,args...)
28 #endif
30 #if 0 /* data */
31 #define D2PRINTK(format,args...) printk(KERN_DEBUG format,##args)
32 #else
33 #define D2PRINTK(format,args...)
34 #endif
37 #define PRIV(sch) qdisc_priv(sch)
40 /* Thanks to Doron Oz for this hack
42 #ifndef CONFIG_NET_CLS_ACT
43 #ifdef CONFIG_NETFILTER
44 static int nf_registered;
45 #endif
46 #endif
48 struct ingress_qdisc_data {
49 struct Qdisc *q;
50 struct tcf_proto *filter_list;
54 /* ------------------------- Class/flow operations ------------------------- */
57 static int ingress_graft(struct Qdisc *sch,unsigned long arg,
58 struct Qdisc *new,struct Qdisc **old)
60 #ifdef DEBUG_INGRESS
61 struct ingress_qdisc_data *p = PRIV(sch);
62 #endif
64 DPRINTK("ingress_graft(sch %p,[qdisc %p],new %p,old %p)\n",
65 sch, p, new, old);
66 DPRINTK("\n ingress_graft: You cannot add qdiscs to classes");
67 return 1;
71 static struct Qdisc *ingress_leaf(struct Qdisc *sch, unsigned long arg)
73 return NULL;
77 static unsigned long ingress_get(struct Qdisc *sch,u32 classid)
79 #ifdef DEBUG_INGRESS
80 struct ingress_qdisc_data *p = PRIV(sch);
81 #endif
82 DPRINTK("ingress_get(sch %p,[qdisc %p],classid %x)\n", sch, p, classid);
83 return TC_H_MIN(classid) + 1;
87 static unsigned long ingress_bind_filter(struct Qdisc *sch,
88 unsigned long parent, u32 classid)
90 return ingress_get(sch, classid);
94 static void ingress_put(struct Qdisc *sch, unsigned long cl)
99 static int ingress_change(struct Qdisc *sch, u32 classid, u32 parent,
100 struct rtattr **tca, unsigned long *arg)
102 #ifdef DEBUG_INGRESS
103 struct ingress_qdisc_data *p = PRIV(sch);
104 #endif
105 DPRINTK("ingress_change(sch %p,[qdisc %p],classid %x,parent %x),"
106 "arg 0x%lx\n", sch, p, classid, parent, *arg);
107 DPRINTK("No effect. sch_ingress doesn't maintain classes at the moment");
108 return 0;
113 static void ingress_walk(struct Qdisc *sch,struct qdisc_walker *walker)
115 #ifdef DEBUG_INGRESS
116 struct ingress_qdisc_data *p = PRIV(sch);
117 #endif
118 DPRINTK("ingress_walk(sch %p,[qdisc %p],walker %p)\n", sch, p, walker);
119 DPRINTK("No effect. sch_ingress doesn't maintain classes at the moment");
123 static struct tcf_proto **ingress_find_tcf(struct Qdisc *sch,unsigned long cl)
125 struct ingress_qdisc_data *p = PRIV(sch);
127 return &p->filter_list;
131 /* --------------------------- Qdisc operations ---------------------------- */
134 static int ingress_enqueue(struct sk_buff *skb,struct Qdisc *sch)
136 struct ingress_qdisc_data *p = PRIV(sch);
137 struct tcf_result res;
138 int result;
140 D2PRINTK("ingress_enqueue(skb %p,sch %p,[qdisc %p])\n", skb, sch, p);
141 result = tc_classify(skb, p->filter_list, &res);
142 D2PRINTK("result %d class 0x%04x\n", result, res.classid);
144 * Unlike normal "enqueue" functions, ingress_enqueue returns a
145 * firewall FW_* code.
147 #ifdef CONFIG_NET_CLS_ACT
148 sch->bstats.packets++;
149 sch->bstats.bytes += skb->len;
150 switch (result) {
151 case TC_ACT_SHOT:
152 result = TC_ACT_SHOT;
153 sch->qstats.drops++;
154 break;
155 case TC_ACT_STOLEN:
156 case TC_ACT_QUEUED:
157 result = TC_ACT_STOLEN;
158 break;
159 case TC_ACT_RECLASSIFY:
160 case TC_ACT_OK:
161 skb->tc_index = TC_H_MIN(res.classid);
162 default:
163 result = TC_ACT_OK;
164 break;
166 #else
167 D2PRINTK("Overriding result to ACCEPT\n");
168 result = NF_ACCEPT;
169 sch->bstats.packets++;
170 sch->bstats.bytes += skb->len;
171 #endif
173 return result;
177 static struct sk_buff *ingress_dequeue(struct Qdisc *sch)
180 struct ingress_qdisc_data *p = PRIV(sch);
181 D2PRINTK("ingress_dequeue(sch %p,[qdisc %p])\n",sch,PRIV(p));
183 return NULL;
187 static int ingress_requeue(struct sk_buff *skb,struct Qdisc *sch)
190 struct ingress_qdisc_data *p = PRIV(sch);
191 D2PRINTK("ingress_requeue(skb %p,sch %p,[qdisc %p])\n",skb,sch,PRIV(p));
193 return 0;
196 static unsigned int ingress_drop(struct Qdisc *sch)
198 #ifdef DEBUG_INGRESS
199 struct ingress_qdisc_data *p = PRIV(sch);
200 #endif
201 DPRINTK("ingress_drop(sch %p,[qdisc %p])\n", sch, p);
202 return 0;
205 #ifndef CONFIG_NET_CLS_ACT
206 #ifdef CONFIG_NETFILTER
207 static unsigned int
208 ing_hook(unsigned int hook, struct sk_buff *skb,
209 const struct net_device *indev,
210 const struct net_device *outdev,
211 int (*okfn)(struct sk_buff *))
214 struct Qdisc *q;
215 struct net_device *dev = skb->dev;
216 int fwres=NF_ACCEPT;
218 DPRINTK("ing_hook: skb %s dev=%s len=%u\n",
219 skb->sk ? "(owned)" : "(unowned)",
220 skb->dev ? skb->dev->name : "(no dev)",
221 skb->len);
223 if (dev->qdisc_ingress) {
224 spin_lock(&dev->ingress_lock);
225 if ((q = dev->qdisc_ingress) != NULL)
226 fwres = q->enqueue(skb, q);
227 spin_unlock(&dev->ingress_lock);
230 return fwres;
233 /* after ipt_filter */
234 static struct nf_hook_ops ing_ops = {
235 .hook = ing_hook,
236 .owner = THIS_MODULE,
237 .pf = PF_INET,
238 .hooknum = NF_IP_PRE_ROUTING,
239 .priority = NF_IP_PRI_FILTER + 1,
242 static struct nf_hook_ops ing6_ops = {
243 .hook = ing_hook,
244 .owner = THIS_MODULE,
245 .pf = PF_INET6,
246 .hooknum = NF_IP6_PRE_ROUTING,
247 .priority = NF_IP6_PRI_FILTER + 1,
250 #endif
251 #endif
253 static int ingress_init(struct Qdisc *sch,struct rtattr *opt)
255 struct ingress_qdisc_data *p = PRIV(sch);
257 /* Make sure either netfilter or preferably CLS_ACT is
258 * compiled in */
259 #ifndef CONFIG_NET_CLS_ACT
260 #ifndef CONFIG_NETFILTER
261 printk("You MUST compile classifier actions into the kernel\n");
262 return -EINVAL;
263 #else
264 printk("Ingress scheduler: Classifier actions prefered over netfilter\n");
265 #endif
266 #endif
268 #ifndef CONFIG_NET_CLS_ACT
269 #ifdef CONFIG_NETFILTER
270 if (!nf_registered) {
271 if (nf_register_hook(&ing_ops) < 0) {
272 printk("ingress qdisc registration error \n");
273 return -EINVAL;
275 nf_registered++;
277 if (nf_register_hook(&ing6_ops) < 0) {
278 printk("IPv6 ingress qdisc registration error, " \
279 "disabling IPv6 support.\n");
280 } else
281 nf_registered++;
283 #endif
284 #endif
286 DPRINTK("ingress_init(sch %p,[qdisc %p],opt %p)\n",sch,p,opt);
287 p->q = &noop_qdisc;
288 return 0;
292 static void ingress_reset(struct Qdisc *sch)
294 struct ingress_qdisc_data *p = PRIV(sch);
296 DPRINTK("ingress_reset(sch %p,[qdisc %p])\n", sch, p);
299 #if 0
301 /* for future use */
302 qdisc_reset(p->q);
304 #endif
308 /* ------------------------------------------------------------- */
311 /* ------------------------------------------------------------- */
313 static void ingress_destroy(struct Qdisc *sch)
315 struct ingress_qdisc_data *p = PRIV(sch);
317 DPRINTK("ingress_destroy(sch %p,[qdisc %p])\n", sch, p);
318 tcf_destroy_chain(p->filter_list);
319 #if 0
320 /* for future use */
321 qdisc_destroy(p->q);
322 #endif
326 static int ingress_dump(struct Qdisc *sch, struct sk_buff *skb)
328 unsigned char *b = skb_tail_pointer(skb);
329 struct rtattr *rta;
331 rta = (struct rtattr *) b;
332 RTA_PUT(skb, TCA_OPTIONS, 0, NULL);
333 rta->rta_len = skb_tail_pointer(skb) - b;
334 return skb->len;
336 rtattr_failure:
337 nlmsg_trim(skb, b);
338 return -1;
341 static struct Qdisc_class_ops ingress_class_ops = {
342 .graft = ingress_graft,
343 .leaf = ingress_leaf,
344 .get = ingress_get,
345 .put = ingress_put,
346 .change = ingress_change,
347 .delete = NULL,
348 .walk = ingress_walk,
349 .tcf_chain = ingress_find_tcf,
350 .bind_tcf = ingress_bind_filter,
351 .unbind_tcf = ingress_put,
352 .dump = NULL,
355 static struct Qdisc_ops ingress_qdisc_ops = {
356 .next = NULL,
357 .cl_ops = &ingress_class_ops,
358 .id = "ingress",
359 .priv_size = sizeof(struct ingress_qdisc_data),
360 .enqueue = ingress_enqueue,
361 .dequeue = ingress_dequeue,
362 .requeue = ingress_requeue,
363 .drop = ingress_drop,
364 .init = ingress_init,
365 .reset = ingress_reset,
366 .destroy = ingress_destroy,
367 .change = NULL,
368 .dump = ingress_dump,
369 .owner = THIS_MODULE,
372 static int __init ingress_module_init(void)
374 int ret = 0;
376 if ((ret = register_qdisc(&ingress_qdisc_ops)) < 0) {
377 printk("Unable to register Ingress qdisc\n");
378 return ret;
381 return ret;
383 static void __exit ingress_module_exit(void)
385 unregister_qdisc(&ingress_qdisc_ops);
386 #ifndef CONFIG_NET_CLS_ACT
387 #ifdef CONFIG_NETFILTER
388 if (nf_registered) {
389 nf_unregister_hook(&ing_ops);
390 if (nf_registered > 1)
391 nf_unregister_hook(&ing6_ops);
393 #endif
394 #endif
396 module_init(ingress_module_init)
397 module_exit(ingress_module_exit)
398 MODULE_LICENSE("GPL");