net_sched: fix class grafting errno codes
[safe/jmp/linux-2.6] / net / sched / sch_ingress.c
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.
6  *
7  * Authors:     Jamal Hadi Salim 1999
8  */
9
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 <net/netlink.h>
16 #include <net/pkt_sched.h>
17
18
19 struct ingress_qdisc_data {
20         struct tcf_proto        *filter_list;
21 };
22
23 /* ------------------------- Class/flow operations ------------------------- */
24
25 static struct Qdisc *ingress_leaf(struct Qdisc *sch, unsigned long arg)
26 {
27         return NULL;
28 }
29
30 static unsigned long ingress_get(struct Qdisc *sch, u32 classid)
31 {
32         return TC_H_MIN(classid) + 1;
33 }
34
35 static unsigned long ingress_bind_filter(struct Qdisc *sch,
36                                          unsigned long parent, u32 classid)
37 {
38         return ingress_get(sch, classid);
39 }
40
41 static void ingress_put(struct Qdisc *sch, unsigned long cl)
42 {
43 }
44
45 static int ingress_change(struct Qdisc *sch, u32 classid, u32 parent,
46                           struct nlattr **tca, unsigned long *arg)
47 {
48         return 0;
49 }
50
51 static void ingress_walk(struct Qdisc *sch, struct qdisc_walker *walker)
52 {
53         return;
54 }
55
56 static struct tcf_proto **ingress_find_tcf(struct Qdisc *sch, unsigned long cl)
57 {
58         struct ingress_qdisc_data *p = qdisc_priv(sch);
59
60         return &p->filter_list;
61 }
62
63 /* --------------------------- Qdisc operations ---------------------------- */
64
65 static int ingress_enqueue(struct sk_buff *skb, struct Qdisc *sch)
66 {
67         struct ingress_qdisc_data *p = qdisc_priv(sch);
68         struct tcf_result res;
69         int result;
70
71         result = tc_classify(skb, p->filter_list, &res);
72
73         sch->bstats.packets++;
74         sch->bstats.bytes += qdisc_pkt_len(skb);
75         switch (result) {
76         case TC_ACT_SHOT:
77                 result = TC_ACT_SHOT;
78                 sch->qstats.drops++;
79                 break;
80         case TC_ACT_STOLEN:
81         case TC_ACT_QUEUED:
82                 result = TC_ACT_STOLEN;
83                 break;
84         case TC_ACT_RECLASSIFY:
85         case TC_ACT_OK:
86                 skb->tc_index = TC_H_MIN(res.classid);
87         default:
88                 result = TC_ACT_OK;
89                 break;
90         }
91
92         return result;
93 }
94
95 /* ------------------------------------------------------------- */
96
97 static void ingress_destroy(struct Qdisc *sch)
98 {
99         struct ingress_qdisc_data *p = qdisc_priv(sch);
100
101         tcf_destroy_chain(&p->filter_list);
102 }
103
104 static int ingress_dump(struct Qdisc *sch, struct sk_buff *skb)
105 {
106         struct nlattr *nest;
107
108         nest = nla_nest_start(skb, TCA_OPTIONS);
109         if (nest == NULL)
110                 goto nla_put_failure;
111         nla_nest_end(skb, nest);
112         return skb->len;
113
114 nla_put_failure:
115         nla_nest_cancel(skb, nest);
116         return -1;
117 }
118
119 static const struct Qdisc_class_ops ingress_class_ops = {
120         .leaf           =       ingress_leaf,
121         .get            =       ingress_get,
122         .put            =       ingress_put,
123         .change         =       ingress_change,
124         .walk           =       ingress_walk,
125         .tcf_chain      =       ingress_find_tcf,
126         .bind_tcf       =       ingress_bind_filter,
127         .unbind_tcf     =       ingress_put,
128 };
129
130 static struct Qdisc_ops ingress_qdisc_ops __read_mostly = {
131         .cl_ops         =       &ingress_class_ops,
132         .id             =       "ingress",
133         .priv_size      =       sizeof(struct ingress_qdisc_data),
134         .enqueue        =       ingress_enqueue,
135         .destroy        =       ingress_destroy,
136         .dump           =       ingress_dump,
137         .owner          =       THIS_MODULE,
138 };
139
140 static int __init ingress_module_init(void)
141 {
142         return register_qdisc(&ingress_qdisc_ops);
143 }
144
145 static void __exit ingress_module_exit(void)
146 {
147         unregister_qdisc(&ingress_qdisc_ops);
148 }
149
150 module_init(ingress_module_init)
151 module_exit(ingress_module_exit)
152 MODULE_LICENSE("GPL");