1 #ifndef __NET_SCHED_GENERIC_H
2 #define __NET_SCHED_GENERIC_H
4 #include <linux/netdevice.h>
5 #include <linux/types.h>
6 #include <linux/rcupdate.h>
7 #include <linux/module.h>
8 #include <linux/pkt_sched.h>
9 #include <linux/pkt_cls.h>
10 #include <net/gen_stats.h>
11 #include <net/rtnetlink.h>
18 struct qdisc_rate_table
20 struct tc_ratespec rate;
22 struct qdisc_rate_table *next;
28 int (*enqueue)(struct sk_buff *skb, struct Qdisc *dev);
29 struct sk_buff * (*dequeue)(struct Qdisc *dev);
31 #define TCQ_F_BUILTIN 1
32 #define TCQ_F_THROTTLED 2
33 #define TCQ_F_INGRESS 4
35 struct Qdisc_ops *ops;
39 struct sk_buff_head q;
40 struct netdev_queue *dev_queue;
41 struct list_head list;
43 struct gnet_stats_basic bstats;
44 struct gnet_stats_queue qstats;
45 struct gnet_stats_rate_est rate_est;
46 spinlock_t *stats_lock;
47 struct rcu_head q_rcu;
48 int (*reshape_fail)(struct sk_buff *skb,
51 /* This field is deprecated, but it is still used by CBQ
52 * and it will live until better solution will be invented.
54 struct Qdisc *__parent;
57 struct Qdisc_class_ops
59 /* Child qdisc manipulation */
60 int (*graft)(struct Qdisc *, unsigned long cl,
61 struct Qdisc *, struct Qdisc **);
62 struct Qdisc * (*leaf)(struct Qdisc *, unsigned long cl);
63 void (*qlen_notify)(struct Qdisc *, unsigned long);
65 /* Class manipulation routines */
66 unsigned long (*get)(struct Qdisc *, u32 classid);
67 void (*put)(struct Qdisc *, unsigned long);
68 int (*change)(struct Qdisc *, u32, u32,
69 struct nlattr **, unsigned long *);
70 int (*delete)(struct Qdisc *, unsigned long);
71 void (*walk)(struct Qdisc *, struct qdisc_walker * arg);
73 /* Filter manipulation */
74 struct tcf_proto ** (*tcf_chain)(struct Qdisc *, unsigned long);
75 unsigned long (*bind_tcf)(struct Qdisc *, unsigned long,
77 void (*unbind_tcf)(struct Qdisc *, unsigned long);
79 /* rtnetlink specific */
80 int (*dump)(struct Qdisc *, unsigned long,
81 struct sk_buff *skb, struct tcmsg*);
82 int (*dump_stats)(struct Qdisc *, unsigned long,
88 struct Qdisc_ops *next;
89 const struct Qdisc_class_ops *cl_ops;
93 int (*enqueue)(struct sk_buff *, struct Qdisc *);
94 struct sk_buff * (*dequeue)(struct Qdisc *);
95 int (*requeue)(struct sk_buff *, struct Qdisc *);
96 unsigned int (*drop)(struct Qdisc *);
98 int (*init)(struct Qdisc *, struct nlattr *arg);
99 void (*reset)(struct Qdisc *);
100 void (*destroy)(struct Qdisc *);
101 int (*change)(struct Qdisc *, struct nlattr *arg);
103 int (*dump)(struct Qdisc *, struct sk_buff *);
104 int (*dump_stats)(struct Qdisc *, struct gnet_dump *);
106 struct module *owner;
118 struct tcf_proto_ops *next;
121 int (*classify)(struct sk_buff*, struct tcf_proto*,
122 struct tcf_result *);
123 int (*init)(struct tcf_proto*);
124 void (*destroy)(struct tcf_proto*);
126 unsigned long (*get)(struct tcf_proto*, u32 handle);
127 void (*put)(struct tcf_proto*, unsigned long);
128 int (*change)(struct tcf_proto*, unsigned long,
129 u32 handle, struct nlattr **,
131 int (*delete)(struct tcf_proto*, unsigned long);
132 void (*walk)(struct tcf_proto*, struct tcf_walker *arg);
134 /* rtnetlink specific */
135 int (*dump)(struct tcf_proto*, unsigned long,
136 struct sk_buff *skb, struct tcmsg*);
138 struct module *owner;
143 /* Fast access part */
144 struct tcf_proto *next;
146 int (*classify)(struct sk_buff*, struct tcf_proto*,
147 struct tcf_result *);
155 struct tcf_proto_ops *ops;
158 static inline struct net_device *qdisc_dev(struct Qdisc *qdisc)
160 return qdisc->dev_queue->dev;
163 extern void qdisc_lock_tree(struct net_device *dev);
164 extern void qdisc_unlock_tree(struct net_device *dev);
166 #define sch_tree_lock(q) qdisc_lock_tree(qdisc_dev(q))
167 #define sch_tree_unlock(q) qdisc_unlock_tree(qdisc_dev(q))
168 #define tcf_tree_lock(tp) qdisc_lock_tree(qdisc_dev((tp)->q))
169 #define tcf_tree_unlock(tp) qdisc_unlock_tree(qdisc_dev((tp)->q))
171 extern struct Qdisc noop_qdisc;
172 extern struct Qdisc_ops noop_qdisc_ops;
174 struct Qdisc_class_common
177 struct hlist_node hnode;
180 struct Qdisc_class_hash
182 struct hlist_head *hash;
183 unsigned int hashsize;
184 unsigned int hashmask;
185 unsigned int hashelems;
188 static inline unsigned int qdisc_class_hash(u32 id, u32 mask)
195 static inline struct Qdisc_class_common *
196 qdisc_class_find(struct Qdisc_class_hash *hash, u32 id)
198 struct Qdisc_class_common *cl;
199 struct hlist_node *n;
202 h = qdisc_class_hash(id, hash->hashmask);
203 hlist_for_each_entry(cl, n, &hash->hash[h], hnode) {
204 if (cl->classid == id)
210 extern int qdisc_class_hash_init(struct Qdisc_class_hash *);
211 extern void qdisc_class_hash_insert(struct Qdisc_class_hash *, struct Qdisc_class_common *);
212 extern void qdisc_class_hash_remove(struct Qdisc_class_hash *, struct Qdisc_class_common *);
213 extern void qdisc_class_hash_grow(struct Qdisc *, struct Qdisc_class_hash *);
214 extern void qdisc_class_hash_destroy(struct Qdisc_class_hash *);
216 extern void dev_init_scheduler(struct net_device *dev);
217 extern void dev_shutdown(struct net_device *dev);
218 extern void dev_activate(struct net_device *dev);
219 extern void dev_deactivate(struct net_device *dev);
220 extern void qdisc_reset(struct Qdisc *qdisc);
221 extern void qdisc_destroy(struct Qdisc *qdisc);
222 extern void qdisc_tree_decrease_qlen(struct Qdisc *qdisc, unsigned int n);
223 extern struct Qdisc *qdisc_alloc(struct netdev_queue *dev_queue,
224 struct Qdisc_ops *ops);
225 extern struct Qdisc *qdisc_create_dflt(struct net_device *dev,
226 struct netdev_queue *dev_queue,
227 struct Qdisc_ops *ops, u32 parentid);
228 extern void tcf_destroy(struct tcf_proto *tp);
229 extern void tcf_destroy_chain(struct tcf_proto **fl);
231 static inline int __qdisc_enqueue_tail(struct sk_buff *skb, struct Qdisc *sch,
232 struct sk_buff_head *list)
234 __skb_queue_tail(list, skb);
235 sch->qstats.backlog += skb->len;
236 sch->bstats.bytes += skb->len;
237 sch->bstats.packets++;
239 return NET_XMIT_SUCCESS;
242 static inline int qdisc_enqueue_tail(struct sk_buff *skb, struct Qdisc *sch)
244 return __qdisc_enqueue_tail(skb, sch, &sch->q);
247 static inline struct sk_buff *__qdisc_dequeue_head(struct Qdisc *sch,
248 struct sk_buff_head *list)
250 struct sk_buff *skb = __skb_dequeue(list);
252 if (likely(skb != NULL))
253 sch->qstats.backlog -= skb->len;
258 static inline struct sk_buff *qdisc_dequeue_head(struct Qdisc *sch)
260 return __qdisc_dequeue_head(sch, &sch->q);
263 static inline struct sk_buff *__qdisc_dequeue_tail(struct Qdisc *sch,
264 struct sk_buff_head *list)
266 struct sk_buff *skb = __skb_dequeue_tail(list);
268 if (likely(skb != NULL))
269 sch->qstats.backlog -= skb->len;
274 static inline struct sk_buff *qdisc_dequeue_tail(struct Qdisc *sch)
276 return __qdisc_dequeue_tail(sch, &sch->q);
279 static inline int __qdisc_requeue(struct sk_buff *skb, struct Qdisc *sch,
280 struct sk_buff_head *list)
282 __skb_queue_head(list, skb);
283 sch->qstats.backlog += skb->len;
284 sch->qstats.requeues++;
286 return NET_XMIT_SUCCESS;
289 static inline int qdisc_requeue(struct sk_buff *skb, struct Qdisc *sch)
291 return __qdisc_requeue(skb, sch, &sch->q);
294 static inline void __qdisc_reset_queue(struct Qdisc *sch,
295 struct sk_buff_head *list)
298 * We do not know the backlog in bytes of this list, it
299 * is up to the caller to correct it
301 skb_queue_purge(list);
304 static inline void qdisc_reset_queue(struct Qdisc *sch)
306 __qdisc_reset_queue(sch, &sch->q);
307 sch->qstats.backlog = 0;
310 static inline unsigned int __qdisc_queue_drop(struct Qdisc *sch,
311 struct sk_buff_head *list)
313 struct sk_buff *skb = __qdisc_dequeue_tail(sch, list);
315 if (likely(skb != NULL)) {
316 unsigned int len = skb->len;
324 static inline unsigned int qdisc_queue_drop(struct Qdisc *sch)
326 return __qdisc_queue_drop(sch, &sch->q);
329 static inline int qdisc_drop(struct sk_buff *skb, struct Qdisc *sch)
334 return NET_XMIT_DROP;
337 static inline int qdisc_reshape_fail(struct sk_buff *skb, struct Qdisc *sch)
341 #ifdef CONFIG_NET_CLS_ACT
342 if (sch->reshape_fail == NULL || sch->reshape_fail(skb, sch))
345 return NET_XMIT_SUCCESS;
350 return NET_XMIT_DROP;
353 /* Length to Time (L2T) lookup in a qdisc_rate_table, to determine how
354 long it will take to send a packet given its size.
356 static inline u32 qdisc_l2t(struct qdisc_rate_table* rtab, unsigned int pktlen)
358 int slot = pktlen + rtab->rate.cell_align + rtab->rate.overhead;
361 slot >>= rtab->rate.cell_log;
363 return (rtab->data[255]*(slot >> 8) + rtab->data[slot & 0xFF]);
364 return rtab->data[slot];
367 #ifdef CONFIG_NET_CLS_ACT
368 static inline struct sk_buff *skb_act_clone(struct sk_buff *skb, gfp_t gfp_mask)
370 struct sk_buff *n = skb_clone(skb, gfp_mask);
373 n->tc_verd = SET_TC_VERD(n->tc_verd, 0);
374 n->tc_verd = CLR_TC_OK2MUNGE(n->tc_verd);
375 n->tc_verd = CLR_TC_MUNGED(n->tc_verd);