1 /* net/sched/sch_ingress.c - Ingress and clsact qdisc
3 * This program is free software; you can redistribute it and/or
4 * modify it under the terms of the GNU General Public License
5 * as published by the Free Software Foundation; either version
6 * 2 of the License, or (at your option) any later version.
8 * Authors: Jamal Hadi Salim 1999
11 #include <linux/module.h>
12 #include <linux/types.h>
13 #include <linux/list.h>
14 #include <linux/skbuff.h>
15 #include <linux/rtnetlink.h>
17 #include <net/netlink.h>
18 #include <net/pkt_sched.h>
19 #include <net/pkt_cls.h>
21 struct ingress_sched_data
{
22 struct tcf_block
*block
;
25 static struct Qdisc
*ingress_leaf(struct Qdisc
*sch
, unsigned long arg
)
30 static unsigned long ingress_get(struct Qdisc
*sch
, u32 classid
)
32 return TC_H_MIN(classid
) + 1;
35 static bool ingress_cl_offload(u32 classid
)
40 static unsigned long ingress_bind_filter(struct Qdisc
*sch
,
41 unsigned long parent
, u32 classid
)
43 return ingress_get(sch
, classid
);
46 static void ingress_put(struct Qdisc
*sch
, unsigned long cl
)
50 static void ingress_walk(struct Qdisc
*sch
, struct qdisc_walker
*walker
)
54 static struct tcf_block
*ingress_tcf_block(struct Qdisc
*sch
, unsigned long cl
)
56 struct ingress_sched_data
*q
= qdisc_priv(sch
);
61 static int ingress_init(struct Qdisc
*sch
, struct nlattr
*opt
)
63 struct ingress_sched_data
*q
= qdisc_priv(sch
);
64 struct net_device
*dev
= qdisc_dev(sch
);
67 err
= tcf_block_get(&q
->block
, &dev
->ingress_cl_list
);
71 net_inc_ingress_queue();
72 sch
->flags
|= TCQ_F_CPUSTATS
;
77 static void ingress_destroy(struct Qdisc
*sch
)
79 struct ingress_sched_data
*q
= qdisc_priv(sch
);
81 tcf_block_put(q
->block
);
82 net_dec_ingress_queue();
85 static int ingress_dump(struct Qdisc
*sch
, struct sk_buff
*skb
)
89 nest
= nla_nest_start(skb
, TCA_OPTIONS
);
93 return nla_nest_end(skb
, nest
);
96 nla_nest_cancel(skb
, nest
);
100 static const struct Qdisc_class_ops ingress_class_ops
= {
101 .leaf
= ingress_leaf
,
104 .walk
= ingress_walk
,
105 .tcf_block
= ingress_tcf_block
,
106 .tcf_cl_offload
= ingress_cl_offload
,
107 .bind_tcf
= ingress_bind_filter
,
108 .unbind_tcf
= ingress_put
,
111 static struct Qdisc_ops ingress_qdisc_ops __read_mostly
= {
112 .cl_ops
= &ingress_class_ops
,
114 .priv_size
= sizeof(struct ingress_sched_data
),
115 .init
= ingress_init
,
116 .destroy
= ingress_destroy
,
117 .dump
= ingress_dump
,
118 .owner
= THIS_MODULE
,
121 struct clsact_sched_data
{
122 struct tcf_block
*ingress_block
;
123 struct tcf_block
*egress_block
;
126 static unsigned long clsact_get(struct Qdisc
*sch
, u32 classid
)
128 switch (TC_H_MIN(classid
)) {
129 case TC_H_MIN(TC_H_MIN_INGRESS
):
130 case TC_H_MIN(TC_H_MIN_EGRESS
):
131 return TC_H_MIN(classid
);
137 static bool clsact_cl_offload(u32 classid
)
139 return TC_H_MIN(classid
) == TC_H_MIN(TC_H_MIN_INGRESS
);
142 static unsigned long clsact_bind_filter(struct Qdisc
*sch
,
143 unsigned long parent
, u32 classid
)
145 return clsact_get(sch
, classid
);
148 static struct tcf_block
*clsact_tcf_block(struct Qdisc
*sch
, unsigned long cl
)
150 struct clsact_sched_data
*q
= qdisc_priv(sch
);
153 case TC_H_MIN(TC_H_MIN_INGRESS
):
154 return q
->ingress_block
;
155 case TC_H_MIN(TC_H_MIN_EGRESS
):
156 return q
->egress_block
;
162 static int clsact_init(struct Qdisc
*sch
, struct nlattr
*opt
)
164 struct clsact_sched_data
*q
= qdisc_priv(sch
);
165 struct net_device
*dev
= qdisc_dev(sch
);
168 err
= tcf_block_get(&q
->ingress_block
, &dev
->ingress_cl_list
);
172 err
= tcf_block_get(&q
->egress_block
, &dev
->egress_cl_list
);
176 net_inc_ingress_queue();
177 net_inc_egress_queue();
179 sch
->flags
|= TCQ_F_CPUSTATS
;
184 static void clsact_destroy(struct Qdisc
*sch
)
186 struct clsact_sched_data
*q
= qdisc_priv(sch
);
188 tcf_block_put(q
->egress_block
);
189 tcf_block_put(q
->ingress_block
);
191 net_dec_ingress_queue();
192 net_dec_egress_queue();
195 static const struct Qdisc_class_ops clsact_class_ops
= {
196 .leaf
= ingress_leaf
,
199 .walk
= ingress_walk
,
200 .tcf_block
= clsact_tcf_block
,
201 .tcf_cl_offload
= clsact_cl_offload
,
202 .bind_tcf
= clsact_bind_filter
,
203 .unbind_tcf
= ingress_put
,
206 static struct Qdisc_ops clsact_qdisc_ops __read_mostly
= {
207 .cl_ops
= &clsact_class_ops
,
209 .priv_size
= sizeof(struct clsact_sched_data
),
211 .destroy
= clsact_destroy
,
212 .dump
= ingress_dump
,
213 .owner
= THIS_MODULE
,
216 static int __init
ingress_module_init(void)
220 ret
= register_qdisc(&ingress_qdisc_ops
);
222 ret
= register_qdisc(&clsact_qdisc_ops
);
224 unregister_qdisc(&ingress_qdisc_ops
);
230 static void __exit
ingress_module_exit(void)
232 unregister_qdisc(&ingress_qdisc_ops
);
233 unregister_qdisc(&clsact_qdisc_ops
);
236 module_init(ingress_module_init
);
237 module_exit(ingress_module_exit
);
239 MODULE_ALIAS("sch_clsact");
240 MODULE_LICENSE("GPL");