]> git.kernelconcepts.de Git - karo-tx-linux.git/blob - net/sched/sch_ingress.c
a89cc3278bfb4b045955c71a2a98d97c647a0725
[karo-tx-linux.git] / 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 __rcu  *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 void ingress_walk(struct Qdisc *sch, struct qdisc_walker *walker)
46 {
47 }
48
49 static struct tcf_proto __rcu **ingress_find_tcf(struct Qdisc *sch,
50                                                  unsigned long cl)
51 {
52         struct ingress_qdisc_data *p = qdisc_priv(sch);
53
54         return &p->filter_list;
55 }
56
57 /* --------------------------- Qdisc operations ---------------------------- */
58
59 static int ingress_enqueue(struct sk_buff *skb, struct Qdisc *sch)
60 {
61         struct ingress_qdisc_data *p = qdisc_priv(sch);
62         struct tcf_result res;
63         struct tcf_proto *fl = rcu_dereference_bh(p->filter_list);
64         int result;
65
66         result = tc_classify(skb, fl, &res);
67
68         qdisc_bstats_update_cpu(sch, skb);
69         switch (result) {
70         case TC_ACT_SHOT:
71                 result = TC_ACT_SHOT;
72                 qdisc_qstats_drop_cpu(sch);
73                 break;
74         case TC_ACT_STOLEN:
75         case TC_ACT_QUEUED:
76                 result = TC_ACT_STOLEN;
77                 break;
78         case TC_ACT_RECLASSIFY:
79         case TC_ACT_OK:
80                 skb->tc_index = TC_H_MIN(res.classid);
81         default:
82                 result = TC_ACT_OK;
83                 break;
84         }
85
86         return result;
87 }
88
89 /* ------------------------------------------------------------- */
90
91 static int ingress_init(struct Qdisc *sch, struct nlattr *opt)
92 {
93         net_inc_ingress_queue();
94         sch->flags |= TCQ_F_CPUSTATS;
95
96         return 0;
97 }
98
99 static void ingress_destroy(struct Qdisc *sch)
100 {
101         struct ingress_qdisc_data *p = qdisc_priv(sch);
102
103         tcf_destroy_chain(&p->filter_list);
104         net_dec_ingress_queue();
105 }
106
107 static int ingress_dump(struct Qdisc *sch, struct sk_buff *skb)
108 {
109         struct nlattr *nest;
110
111         nest = nla_nest_start(skb, TCA_OPTIONS);
112         if (nest == NULL)
113                 goto nla_put_failure;
114         return nla_nest_end(skb, nest);
115
116 nla_put_failure:
117         nla_nest_cancel(skb, nest);
118         return -1;
119 }
120
121 static const struct Qdisc_class_ops ingress_class_ops = {
122         .leaf           =       ingress_leaf,
123         .get            =       ingress_get,
124         .put            =       ingress_put,
125         .walk           =       ingress_walk,
126         .tcf_chain      =       ingress_find_tcf,
127         .bind_tcf       =       ingress_bind_filter,
128         .unbind_tcf     =       ingress_put,
129 };
130
131 static struct Qdisc_ops ingress_qdisc_ops __read_mostly = {
132         .cl_ops         =       &ingress_class_ops,
133         .id             =       "ingress",
134         .priv_size      =       sizeof(struct ingress_qdisc_data),
135         .enqueue        =       ingress_enqueue,
136         .init           =       ingress_init,
137         .destroy        =       ingress_destroy,
138         .dump           =       ingress_dump,
139         .owner          =       THIS_MODULE,
140 };
141
142 static int __init ingress_module_init(void)
143 {
144         return register_qdisc(&ingress_qdisc_ops);
145 }
146
147 static void __exit ingress_module_exit(void)
148 {
149         unregister_qdisc(&ingress_qdisc_ops);
150 }
151
152 module_init(ingress_module_init)
153 module_exit(ingress_module_exit)
154 MODULE_LICENSE("GPL");