x86: use the correct cpuid method to detect MWAIT support for C states
[linux-2.6/next.git] / net / sched / sch_ingress.c
blob3f72d528273cc4f5a7ff9664d623a428ed718324
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 /* Thanks to Doron Oz for this hack */
23 #if !defined(CONFIG_NET_CLS_ACT) && defined(CONFIG_NETFILTER)
24 static int nf_registered;
25 #endif
27 struct ingress_qdisc_data {
28 struct tcf_proto *filter_list;
31 /* ------------------------- Class/flow operations ------------------------- */
33 static int ingress_graft(struct Qdisc *sch, unsigned long arg,
34 struct Qdisc *new, struct Qdisc **old)
36 return -EOPNOTSUPP;
39 static struct Qdisc *ingress_leaf(struct Qdisc *sch, unsigned long arg)
41 return NULL;
44 static unsigned long ingress_get(struct Qdisc *sch, u32 classid)
46 return TC_H_MIN(classid) + 1;
49 static unsigned long ingress_bind_filter(struct Qdisc *sch,
50 unsigned long parent, u32 classid)
52 return ingress_get(sch, classid);
55 static void ingress_put(struct Qdisc *sch, unsigned long cl)
59 static int ingress_change(struct Qdisc *sch, u32 classid, u32 parent,
60 struct nlattr **tca, unsigned long *arg)
62 return 0;
65 static void ingress_walk(struct Qdisc *sch, struct qdisc_walker *walker)
67 return;
70 static struct tcf_proto **ingress_find_tcf(struct Qdisc *sch, unsigned long cl)
72 struct ingress_qdisc_data *p = qdisc_priv(sch);
74 return &p->filter_list;
77 /* --------------------------- Qdisc operations ---------------------------- */
79 static int ingress_enqueue(struct sk_buff *skb, struct Qdisc *sch)
81 struct ingress_qdisc_data *p = qdisc_priv(sch);
82 struct tcf_result res;
83 int result;
85 result = tc_classify(skb, p->filter_list, &res);
88 * Unlike normal "enqueue" functions, ingress_enqueue returns a
89 * firewall FW_* code.
91 #ifdef CONFIG_NET_CLS_ACT
92 sch->bstats.packets++;
93 sch->bstats.bytes += skb->len;
94 switch (result) {
95 case TC_ACT_SHOT:
96 result = TC_ACT_SHOT;
97 sch->qstats.drops++;
98 break;
99 case TC_ACT_STOLEN:
100 case TC_ACT_QUEUED:
101 result = TC_ACT_STOLEN;
102 break;
103 case TC_ACT_RECLASSIFY:
104 case TC_ACT_OK:
105 skb->tc_index = TC_H_MIN(res.classid);
106 default:
107 result = TC_ACT_OK;
108 break;
110 #else
111 result = NF_ACCEPT;
112 sch->bstats.packets++;
113 sch->bstats.bytes += skb->len;
114 #endif
116 return result;
119 #if !defined(CONFIG_NET_CLS_ACT) && defined(CONFIG_NETFILTER)
120 static unsigned int ing_hook(unsigned int hook, struct sk_buff *skb,
121 const struct net_device *indev,
122 const struct net_device *outdev,
123 int (*okfn)(struct sk_buff *))
126 struct Qdisc *q;
127 struct net_device *dev = skb->dev;
128 int fwres = NF_ACCEPT;
130 if (dev->qdisc_ingress) {
131 spin_lock(&dev->ingress_lock);
132 if ((q = dev->qdisc_ingress) != NULL)
133 fwres = q->enqueue(skb, q);
134 spin_unlock(&dev->ingress_lock);
137 return fwres;
140 /* after ipt_filter */
141 static struct nf_hook_ops ing_ops[] __read_mostly = {
143 .hook = ing_hook,
144 .owner = THIS_MODULE,
145 .pf = PF_INET,
146 .hooknum = NF_INET_PRE_ROUTING,
147 .priority = NF_IP_PRI_FILTER + 1,
150 .hook = ing_hook,
151 .owner = THIS_MODULE,
152 .pf = PF_INET6,
153 .hooknum = NF_INET_PRE_ROUTING,
154 .priority = NF_IP6_PRI_FILTER + 1,
157 #endif
159 static int ingress_init(struct Qdisc *sch, struct nlattr *opt)
161 #if !defined(CONFIG_NET_CLS_ACT) && defined(CONFIG_NETFILTER)
162 printk("Ingress scheduler: Classifier actions prefered over netfilter\n");
164 if (!nf_registered) {
165 if (nf_register_hooks(ing_ops, ARRAY_SIZE(ing_ops)) < 0) {
166 printk("ingress qdisc registration error \n");
167 return -EINVAL;
169 nf_registered++;
171 #endif
172 return 0;
175 /* ------------------------------------------------------------- */
177 static void ingress_destroy(struct Qdisc *sch)
179 struct ingress_qdisc_data *p = qdisc_priv(sch);
181 tcf_destroy_chain(p->filter_list);
184 static int ingress_dump(struct Qdisc *sch, struct sk_buff *skb)
186 struct nlattr *nest;
188 nest = nla_nest_start(skb, TCA_OPTIONS);
189 if (nest == NULL)
190 goto nla_put_failure;
191 nla_nest_end(skb, nest);
192 return skb->len;
194 nla_put_failure:
195 nla_nest_cancel(skb, nest);
196 return -1;
199 static const struct Qdisc_class_ops ingress_class_ops = {
200 .graft = ingress_graft,
201 .leaf = ingress_leaf,
202 .get = ingress_get,
203 .put = ingress_put,
204 .change = ingress_change,
205 .walk = ingress_walk,
206 .tcf_chain = ingress_find_tcf,
207 .bind_tcf = ingress_bind_filter,
208 .unbind_tcf = ingress_put,
211 static struct Qdisc_ops ingress_qdisc_ops __read_mostly = {
212 .cl_ops = &ingress_class_ops,
213 .id = "ingress",
214 .priv_size = sizeof(struct ingress_qdisc_data),
215 .enqueue = ingress_enqueue,
216 .init = ingress_init,
217 .destroy = ingress_destroy,
218 .dump = ingress_dump,
219 .owner = THIS_MODULE,
222 static int __init ingress_module_init(void)
224 return register_qdisc(&ingress_qdisc_ops);
227 static void __exit ingress_module_exit(void)
229 unregister_qdisc(&ingress_qdisc_ops);
230 #if !defined(CONFIG_NET_CLS_ACT) && defined(CONFIG_NETFILTER)
231 if (nf_registered)
232 nf_unregister_hooks(ing_ops, ARRAY_SIZE(ing_ops));
233 #endif
236 module_init(ingress_module_init)
237 module_exit(ingress_module_exit)
238 MODULE_LICENSE("GPL");