Merge tag 'platform-drivers-x86-v4.1-1' of git://git.infradead.org/users/dvhart/linux...
[linux-2.6-block.git] / net / sched / sch_ingress.c
CommitLineData
10297b99 1/* net/sched/sch_ingress.c - Ingress qdisc
1da177e4
LT
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
1da177e4
LT
10#include <linux/module.h>
11#include <linux/types.h>
0ba48053 12#include <linux/list.h>
1da177e4 13#include <linux/skbuff.h>
1da177e4 14#include <linux/rtnetlink.h>
dc5fc579 15#include <net/netlink.h>
1da177e4 16#include <net/pkt_sched.h>
1da177e4
LT
17
18
1da177e4 19struct ingress_qdisc_data {
25d8c0d5 20 struct tcf_proto __rcu *filter_list;
1da177e4
LT
21};
22
1da177e4
LT
23/* ------------------------- Class/flow operations ------------------------- */
24
1da177e4
LT
25static struct Qdisc *ingress_leaf(struct Qdisc *sch, unsigned long arg)
26{
27 return NULL;
28}
29
58f4df42 30static unsigned long ingress_get(struct Qdisc *sch, u32 classid)
1da177e4 31{
1da177e4
LT
32 return TC_H_MIN(classid) + 1;
33}
34
1da177e4 35static unsigned long ingress_bind_filter(struct Qdisc *sch,
58f4df42 36 unsigned long parent, u32 classid)
1da177e4
LT
37{
38 return ingress_get(sch, classid);
39}
40
1da177e4
LT
41static void ingress_put(struct Qdisc *sch, unsigned long cl)
42{
43}
44
58f4df42 45static void ingress_walk(struct Qdisc *sch, struct qdisc_walker *walker)
1da177e4 46{
1da177e4
LT
47}
48
25d8c0d5
JF
49static struct tcf_proto __rcu **ingress_find_tcf(struct Qdisc *sch,
50 unsigned long cl)
1da177e4 51{
cb53c048 52 struct ingress_qdisc_data *p = qdisc_priv(sch);
1da177e4
LT
53
54 return &p->filter_list;
55}
56
1da177e4
LT
57/* --------------------------- Qdisc operations ---------------------------- */
58
58f4df42 59static int ingress_enqueue(struct sk_buff *skb, struct Qdisc *sch)
1da177e4 60{
cb53c048 61 struct ingress_qdisc_data *p = qdisc_priv(sch);
1da177e4 62 struct tcf_result res;
25d8c0d5 63 struct tcf_proto *fl = rcu_dereference_bh(p->filter_list);
1da177e4
LT
64 int result;
65
25d8c0d5 66 result = tc_classify(skb, fl, &res);
a4781221 67
bfe0d029 68 qdisc_bstats_update(sch, skb);
1da177e4 69 switch (result) {
58f4df42
PM
70 case TC_ACT_SHOT:
71 result = TC_ACT_SHOT;
25331d6c 72 qdisc_qstats_drop(sch);
58f4df42
PM
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;
3ff50b79 84 }
1da177e4
LT
85
86 return result;
87}
88
1da177e4
LT
89/* ------------------------------------------------------------- */
90
4577139b
DB
91static int ingress_init(struct Qdisc *sch, struct nlattr *opt)
92{
93 net_inc_ingress_queue();
94
95 return 0;
96}
97
1da177e4
LT
98static void ingress_destroy(struct Qdisc *sch)
99{
cb53c048 100 struct ingress_qdisc_data *p = qdisc_priv(sch);
1da177e4 101
ff31ab56 102 tcf_destroy_chain(&p->filter_list);
4577139b 103 net_dec_ingress_queue();
1da177e4
LT
104}
105
1da177e4
LT
106static int ingress_dump(struct Qdisc *sch, struct sk_buff *skb)
107{
4b3550ef 108 struct nlattr *nest;
1da177e4 109
4b3550ef
PM
110 nest = nla_nest_start(skb, TCA_OPTIONS);
111 if (nest == NULL)
112 goto nla_put_failure;
d59b7d80 113 return nla_nest_end(skb, nest);
1da177e4 114
1e90474c 115nla_put_failure:
4b3550ef 116 nla_nest_cancel(skb, nest);
1da177e4
LT
117 return -1;
118}
119
20fea08b 120static const struct Qdisc_class_ops ingress_class_ops = {
1da177e4
LT
121 .leaf = ingress_leaf,
122 .get = ingress_get,
123 .put = ingress_put,
1da177e4
LT
124 .walk = ingress_walk,
125 .tcf_chain = ingress_find_tcf,
126 .bind_tcf = ingress_bind_filter,
127 .unbind_tcf = ingress_put,
1da177e4
LT
128};
129
20fea08b 130static struct Qdisc_ops ingress_qdisc_ops __read_mostly = {
1da177e4
LT
131 .cl_ops = &ingress_class_ops,
132 .id = "ingress",
133 .priv_size = sizeof(struct ingress_qdisc_data),
134 .enqueue = ingress_enqueue,
4577139b 135 .init = ingress_init,
1da177e4 136 .destroy = ingress_destroy,
1da177e4
LT
137 .dump = ingress_dump,
138 .owner = THIS_MODULE,
139};
140
141static int __init ingress_module_init(void)
142{
89168764 143 return register_qdisc(&ingress_qdisc_ops);
1da177e4 144}
58f4df42 145
10297b99 146static void __exit ingress_module_exit(void)
1da177e4
LT
147{
148 unregister_qdisc(&ingress_qdisc_ops);
1da177e4 149}
58f4df42 150
1da177e4
LT
151module_init(ingress_module_init)
152module_exit(ingress_module_exit)
153MODULE_LICENSE("GPL");