Kill st_fstype member.
[linux-2.6/linux-mips.git] / net / sched / sch_ingress.c
blob947aede019057e510941fa9a7dd46f911b96597d
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/config.h>
11 #include <linux/module.h>
12 #include <linux/types.h>
13 #include <linux/skbuff.h>
14 #include <linux/netdevice.h>
15 #include <linux/rtnetlink.h>
16 #include <linux/netfilter_ipv4.h>
17 #include <linux/netfilter.h>
18 #include <net/pkt_sched.h>
19 #include <asm/byteorder.h>
20 #include <asm/uaccess.h>
21 #include <asm/smp.h>
22 #include <linux/kmod.h>
23 #include <linux/stat.h>
24 #include <linux/interrupt.h>
25 #include <linux/list.h>
28 #undef DEBUG_INGRESS
30 #ifdef DEBUG_INGRESS /* control */
31 #define DPRINTK(format,args...) printk(KERN_DEBUG format,##args)
32 #else
33 #define DPRINTK(format,args...)
34 #endif
36 #if 0 /* data */
37 #define D2PRINTK(format,args...) printk(KERN_DEBUG format,##args)
38 #else
39 #define D2PRINTK(format,args...)
40 #endif
43 #define PRIV(sch) ((struct ingress_qdisc_data *) (sch)->data)
47 struct ingress_qdisc_data {
48 struct Qdisc *q;
49 struct tcf_proto *filter_list;
53 /* ------------------------- Class/flow operations ------------------------- */
56 static int ingress_graft(struct Qdisc *sch,unsigned long arg,
57 struct Qdisc *new,struct Qdisc **old)
59 #ifdef DEBUG_INGRESS
60 struct ingress_qdisc_data *p = PRIV(sch);
61 #endif
63 DPRINTK("ingress_graft(sch %p,[qdisc %p],new %p,old %p)\n",
64 sch, p, new, old);
65 DPRINTK("\n ingress_graft: You cannot add qdiscs to classes");
66 return 1;
70 static struct Qdisc *ingress_leaf(struct Qdisc *sch, unsigned long arg)
72 return NULL;
76 static unsigned long ingress_get(struct Qdisc *sch,u32 classid)
78 #ifdef DEBUG_INGRESS
79 struct ingress_qdisc_data *p = PRIV(sch);
80 #endif
81 DPRINTK("ingress_get(sch %p,[qdisc %p],classid %x)\n", sch, p, classid);
82 return TC_H_MIN(classid) + 1;
86 static unsigned long ingress_bind_filter(struct Qdisc *sch,
87 unsigned long parent, u32 classid)
89 return ingress_get(sch, classid);
93 static void ingress_put(struct Qdisc *sch, unsigned long cl)
98 static int ingress_change(struct Qdisc *sch, u32 classid, u32 parent,
99 struct rtattr **tca, unsigned long *arg)
101 #ifdef DEBUG_INGRESS
102 struct ingress_qdisc_data *p = PRIV(sch);
103 #endif
104 DPRINTK("ingress_change(sch %p,[qdisc %p],classid %x,parent %x),"
105 "arg 0x%lx\n", sch, p, classid, parent, *arg);
106 DPRINTK("No effect. sch_ingress doesnt maintain classes at the moment");
107 return 0;
112 static void ingress_walk(struct Qdisc *sch,struct qdisc_walker *walker)
114 #ifdef DEBUG_INGRESS
115 struct ingress_qdisc_data *p = PRIV(sch);
116 #endif
117 DPRINTK("ingress_walk(sch %p,[qdisc %p],walker %p)\n", sch, p, walker);
118 DPRINTK("No effect. sch_ingress doesnt maintain classes at the moment");
122 static struct tcf_proto **ingress_find_tcf(struct Qdisc *sch,unsigned long cl)
124 struct ingress_qdisc_data *p = PRIV(sch);
126 return &p->filter_list;
130 /* --------------------------- Qdisc operations ---------------------------- */
133 static int ingress_enqueue(struct sk_buff *skb,struct Qdisc *sch)
135 struct ingress_qdisc_data *p = PRIV(sch);
136 struct tcf_result res;
137 int result;
139 D2PRINTK("ingress_enqueue(skb %p,sch %p,[qdisc %p])\n", skb, sch, p);
140 result = tc_classify(skb, p->filter_list, &res);
141 D2PRINTK("result %d class 0x%04x\n", result, res.classid);
143 * Unlike normal "enqueue" functions, ingress_enqueue returns a
144 * firewall FW_* code.
146 switch (result) {
147 #ifdef CONFIG_NET_CLS_POLICE
148 case TC_POLICE_SHOT:
149 result = NF_DROP;
150 break;
151 case TC_POLICE_RECLASSIFY: /* DSCP remarking here ? */
152 case TC_POLICE_OK:
153 case TC_POLICE_UNSPEC:
154 default:
155 result = NF_ACCEPT;
156 break;
157 #endif
160 #ifdef CONFIG_NET_CLS_TCINDEX
161 skb->tc_index = TC_H_MIN(res.classid);
162 #endif
163 return result;
167 static struct sk_buff *ingress_dequeue(struct Qdisc *sch)
170 struct ingress_qdisc_data *p = PRIV(sch);
171 D2PRINTK("ingress_dequeue(sch %p,[qdisc %p])\n",sch,PRIV(p));
173 return NULL;
177 static int ingress_requeue(struct sk_buff *skb,struct Qdisc *sch)
180 struct ingress_qdisc_data *p = PRIV(sch);
181 D2PRINTK("ingress_requeue(skb %p,sch %p,[qdisc %p])\n",skb,sch,PRIV(p));
183 return 0;
186 static int ingress_drop(struct Qdisc *sch)
188 #ifdef DEBUG_INGRESS
189 struct ingress_qdisc_data *p = PRIV(sch);
190 #endif
191 DPRINTK("ingress_drop(sch %p,[qdisc %p])\n", sch, p);
192 return 0;
195 static unsigned int
196 ing_hook(unsigned int hook, struct sk_buff **pskb,
197 const struct net_device *indev,
198 const struct net_device *outdev,
199 int (*okfn)(struct sk_buff *))
202 struct Qdisc *q;
203 struct sk_buff *skb = *pskb;
204 struct net_device *dev = skb->dev;
205 int fwres=NF_ACCEPT;
207 DPRINTK("ing_hook: skb %s dev=%s len=%u\n",
208 skb->sk ? "(owned)" : "(unowned)",
209 skb->dev ? (*pskb)->dev->name : "(no dev)",
210 skb->len);
213 revisit later: Use a private since lock dev->queue_lock is also
214 used on the egress (might slow things for an iota)
217 if (dev->qdisc_ingress) {
218 spin_lock(&dev->queue_lock);
219 if ((q = dev->qdisc_ingress) != NULL)
220 fwres = q->enqueue(skb, q);
221 spin_unlock(&dev->queue_lock);
224 return fwres;
227 /* after ipt_filter */
228 static struct nf_hook_ops ing_ops =
230 { NULL, NULL},
231 ing_hook,
232 PF_INET,
233 NF_IP_PRE_ROUTING,
234 NF_IP_PRI_FILTER + 1
237 int ingress_init(struct Qdisc *sch,struct rtattr *opt)
239 struct ingress_qdisc_data *p = PRIV(sch);
241 DPRINTK("ingress_init(sch %p,[qdisc %p],opt %p)\n",sch,p,opt);
242 memset(p, 0, sizeof(*p));
243 p->filter_list = NULL;
244 p->q = &noop_qdisc;
245 #ifndef MODULE
246 if (nf_register_hook(&ing_ops) < 0) {
247 printk("Unable to register ingress \n");
248 goto error;
250 #endif
251 DPRINTK("ingress_init: qdisc %p\n", sch);
252 MOD_INC_USE_COUNT;
253 return 0;
254 #ifndef MODULE
255 error:
256 #endif
257 return -EINVAL;
261 static void ingress_reset(struct Qdisc *sch)
263 struct ingress_qdisc_data *p = PRIV(sch);
265 DPRINTK("ingress_reset(sch %p,[qdisc %p])\n", sch, p);
268 #if 0
270 /* for future use */
271 qdisc_reset(p->q);
273 #endif
277 /* ------------------------------------------------------------- */
280 /* ------------------------------------------------------------- */
282 static void ingress_destroy(struct Qdisc *sch)
284 struct ingress_qdisc_data *p = PRIV(sch);
285 struct tcf_proto *tp;
287 DPRINTK("ingress_destroy(sch %p,[qdisc %p])\n", sch, p);
288 while (p->filter_list) {
289 tp = p->filter_list;
290 p->filter_list = tp->next;
291 tp->ops->destroy(tp);
293 memset(p, 0, sizeof(*p));
294 p->filter_list = NULL;
296 #if 0
297 /* for future use */
298 qdisc_destroy(p->q);
299 #endif
301 #ifndef MODULE
302 nf_unregister_hook(&ing_ops);
303 #endif
305 MOD_DEC_USE_COUNT;
309 #ifdef CONFIG_RTNETLINK
312 static int ingress_dump(struct Qdisc *sch, struct sk_buff *skb)
314 unsigned char *b = skb->tail;
315 struct rtattr *rta;
317 rta = (struct rtattr *) b;
318 RTA_PUT(skb, TCA_OPTIONS, 0, NULL);
319 rta->rta_len = skb->tail - b;
320 return skb->len;
322 rtattr_failure:
323 skb_trim(skb, b - skb->data);
324 return -1;
327 #endif
330 static struct Qdisc_class_ops ingress_class_ops =
332 ingress_graft, /* graft */
333 ingress_leaf, /* leaf */
334 ingress_get, /* get */
335 ingress_put, /* put */
336 ingress_change, /* change */
337 NULL, /* delete */
338 ingress_walk, /* walk */
340 ingress_find_tcf, /* tcf_chain */
341 ingress_bind_filter, /* bind_tcf */
342 ingress_put, /* unbind_tcf */
344 #ifdef CONFIG_RTNETLINK
345 NULL, /* dump */
346 #endif
349 struct Qdisc_ops ingress_qdisc_ops =
351 NULL, /* next */
352 &ingress_class_ops, /* cl_ops */
353 "ingress",
354 sizeof(struct ingress_qdisc_data),
356 ingress_enqueue, /* enqueue */
357 ingress_dequeue, /* dequeue */
358 ingress_requeue, /* requeue */
359 ingress_drop, /* drop */
361 ingress_init, /* init */
362 ingress_reset, /* reset */
363 ingress_destroy, /* destroy */
364 NULL, /* change */
366 #ifdef CONFIG_RTNETLINK
367 ingress_dump, /* dump */
368 #endif
371 #ifdef MODULE
372 int init_module(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 if (nf_register_hook(&ing_ops) < 0) {
382 printk("Unable to register ingress on hook \n");
383 unregister_qdisc(&ingress_qdisc_ops);
384 return 0;
387 return ret;
391 void cleanup_module(void)
393 nf_unregister_hook(&ing_ops);
394 unregister_qdisc(&ingress_qdisc_ops);
396 #endif