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 __QDISC_STATE_RUNNING,
33 int (*enqueue)(struct sk_buff *skb, struct Qdisc *dev);
34 struct sk_buff * (*dequeue)(struct Qdisc *dev);
36 #define TCQ_F_BUILTIN 1
37 #define TCQ_F_THROTTLED 2
38 #define TCQ_F_INGRESS 4
40 struct Qdisc_ops *ops;
45 struct sk_buff *gso_skb;
46 struct sk_buff_head q;
47 struct netdev_queue *dev_queue;
48 struct list_head list;
50 struct gnet_stats_basic bstats;
51 struct gnet_stats_queue qstats;
52 struct gnet_stats_rate_est rate_est;
53 struct rcu_head q_rcu;
54 int (*reshape_fail)(struct sk_buff *skb,
57 /* This field is deprecated, but it is still used by CBQ
58 * and it will live until better solution will be invented.
60 struct Qdisc *__parent;
63 struct Qdisc_class_ops
65 /* Child qdisc manipulation */
66 int (*graft)(struct Qdisc *, unsigned long cl,
67 struct Qdisc *, struct Qdisc **);
68 struct Qdisc * (*leaf)(struct Qdisc *, unsigned long cl);
69 void (*qlen_notify)(struct Qdisc *, unsigned long);
71 /* Class manipulation routines */
72 unsigned long (*get)(struct Qdisc *, u32 classid);
73 void (*put)(struct Qdisc *, unsigned long);
74 int (*change)(struct Qdisc *, u32, u32,
75 struct nlattr **, unsigned long *);
76 int (*delete)(struct Qdisc *, unsigned long);
77 void (*walk)(struct Qdisc *, struct qdisc_walker * arg);
79 /* Filter manipulation */
80 struct tcf_proto ** (*tcf_chain)(struct Qdisc *, unsigned long);
81 unsigned long (*bind_tcf)(struct Qdisc *, unsigned long,
83 void (*unbind_tcf)(struct Qdisc *, unsigned long);
85 /* rtnetlink specific */
86 int (*dump)(struct Qdisc *, unsigned long,
87 struct sk_buff *skb, struct tcmsg*);
88 int (*dump_stats)(struct Qdisc *, unsigned long,
94 struct Qdisc_ops *next;
95 const struct Qdisc_class_ops *cl_ops;
99 int (*enqueue)(struct sk_buff *, struct Qdisc *);
100 struct sk_buff * (*dequeue)(struct Qdisc *);
101 int (*requeue)(struct sk_buff *, struct Qdisc *);
102 unsigned int (*drop)(struct Qdisc *);
104 int (*init)(struct Qdisc *, struct nlattr *arg);
105 void (*reset)(struct Qdisc *);
106 void (*destroy)(struct Qdisc *);
107 int (*change)(struct Qdisc *, struct nlattr *arg);
109 int (*dump)(struct Qdisc *, struct sk_buff *);
110 int (*dump_stats)(struct Qdisc *, struct gnet_dump *);
112 struct module *owner;
124 struct tcf_proto_ops *next;
127 int (*classify)(struct sk_buff*, struct tcf_proto*,
128 struct tcf_result *);
129 int (*init)(struct tcf_proto*);
130 void (*destroy)(struct tcf_proto*);
132 unsigned long (*get)(struct tcf_proto*, u32 handle);
133 void (*put)(struct tcf_proto*, unsigned long);
134 int (*change)(struct tcf_proto*, unsigned long,
135 u32 handle, struct nlattr **,
137 int (*delete)(struct tcf_proto*, unsigned long);
138 void (*walk)(struct tcf_proto*, struct tcf_walker *arg);
140 /* rtnetlink specific */
141 int (*dump)(struct tcf_proto*, unsigned long,
142 struct sk_buff *skb, struct tcmsg*);
144 struct module *owner;
149 /* Fast access part */
150 struct tcf_proto *next;
152 int (*classify)(struct sk_buff*, struct tcf_proto*,
153 struct tcf_result *);
161 struct tcf_proto_ops *ops;
164 static inline struct Qdisc *qdisc_root(struct Qdisc *qdisc)
166 return qdisc->dev_queue->qdisc;
169 static inline spinlock_t *qdisc_root_lock(struct Qdisc *qdisc)
171 struct Qdisc *root = qdisc_root(qdisc);
173 return &root->dev_queue->lock;
176 static inline struct net_device *qdisc_dev(struct Qdisc *qdisc)
178 return qdisc->dev_queue->dev;
181 extern void qdisc_lock_tree(struct net_device *dev);
182 extern void qdisc_unlock_tree(struct net_device *dev);
184 #define sch_tree_lock(q) qdisc_lock_tree(qdisc_dev(q))
185 #define sch_tree_unlock(q) qdisc_unlock_tree(qdisc_dev(q))
186 #define tcf_tree_lock(tp) qdisc_lock_tree(qdisc_dev((tp)->q))
187 #define tcf_tree_unlock(tp) qdisc_unlock_tree(qdisc_dev((tp)->q))
189 extern struct Qdisc noop_qdisc;
190 extern struct Qdisc_ops noop_qdisc_ops;
192 struct Qdisc_class_common
195 struct hlist_node hnode;
198 struct Qdisc_class_hash
200 struct hlist_head *hash;
201 unsigned int hashsize;
202 unsigned int hashmask;
203 unsigned int hashelems;
206 static inline unsigned int qdisc_class_hash(u32 id, u32 mask)
213 static inline struct Qdisc_class_common *
214 qdisc_class_find(struct Qdisc_class_hash *hash, u32 id)
216 struct Qdisc_class_common *cl;
217 struct hlist_node *n;
220 h = qdisc_class_hash(id, hash->hashmask);
221 hlist_for_each_entry(cl, n, &hash->hash[h], hnode) {
222 if (cl->classid == id)
228 extern int qdisc_class_hash_init(struct Qdisc_class_hash *);
229 extern void qdisc_class_hash_insert(struct Qdisc_class_hash *, struct Qdisc_class_common *);
230 extern void qdisc_class_hash_remove(struct Qdisc_class_hash *, struct Qdisc_class_common *);
231 extern void qdisc_class_hash_grow(struct Qdisc *, struct Qdisc_class_hash *);
232 extern void qdisc_class_hash_destroy(struct Qdisc_class_hash *);
234 extern void dev_init_scheduler(struct net_device *dev);
235 extern void dev_shutdown(struct net_device *dev);
236 extern void dev_activate(struct net_device *dev);
237 extern void dev_deactivate(struct net_device *dev);
238 extern void qdisc_reset(struct Qdisc *qdisc);
239 extern void qdisc_destroy(struct Qdisc *qdisc);
240 extern void qdisc_tree_decrease_qlen(struct Qdisc *qdisc, unsigned int n);
241 extern struct Qdisc *qdisc_alloc(struct netdev_queue *dev_queue,
242 struct Qdisc_ops *ops);
243 extern struct Qdisc *qdisc_create_dflt(struct net_device *dev,
244 struct netdev_queue *dev_queue,
245 struct Qdisc_ops *ops, u32 parentid);
246 extern void tcf_destroy(struct tcf_proto *tp);
247 extern void tcf_destroy_chain(struct tcf_proto **fl);
249 /* Reset all TX qdiscs of a device. */
250 static inline void qdisc_reset_all_tx(struct net_device *dev)
253 for (i = 0; i < dev->num_tx_queues; i++)
254 qdisc_reset(netdev_get_tx_queue(dev, i)->qdisc);
257 /* Are all TX queues of the device empty? */
258 static inline bool qdisc_all_tx_empty(const struct net_device *dev)
261 for (i = 0; i < dev->num_tx_queues; i++) {
262 struct netdev_queue *txq = netdev_get_tx_queue(dev, i);
263 const struct Qdisc *q = txq->qdisc;
271 /* Are any of the TX qdiscs changing? */
272 static inline bool qdisc_tx_changing(struct net_device *dev)
275 for (i = 0; i < dev->num_tx_queues; i++) {
276 struct netdev_queue *txq = netdev_get_tx_queue(dev, i);
277 if (txq->qdisc != txq->qdisc_sleeping)
283 /* Is the device using the noop qdisc on all queues? */
284 static inline bool qdisc_tx_is_noop(const struct net_device *dev)
287 for (i = 0; i < dev->num_tx_queues; i++) {
288 struct netdev_queue *txq = netdev_get_tx_queue(dev, i);
289 if (txq->qdisc != &noop_qdisc)
295 static inline int __qdisc_enqueue_tail(struct sk_buff *skb, struct Qdisc *sch,
296 struct sk_buff_head *list)
298 __skb_queue_tail(list, skb);
299 sch->qstats.backlog += skb->len;
300 sch->bstats.bytes += skb->len;
301 sch->bstats.packets++;
303 return NET_XMIT_SUCCESS;
306 static inline int qdisc_enqueue_tail(struct sk_buff *skb, struct Qdisc *sch)
308 return __qdisc_enqueue_tail(skb, sch, &sch->q);
311 static inline struct sk_buff *__qdisc_dequeue_head(struct Qdisc *sch,
312 struct sk_buff_head *list)
314 struct sk_buff *skb = __skb_dequeue(list);
316 if (likely(skb != NULL))
317 sch->qstats.backlog -= skb->len;
322 static inline struct sk_buff *qdisc_dequeue_head(struct Qdisc *sch)
324 return __qdisc_dequeue_head(sch, &sch->q);
327 static inline struct sk_buff *__qdisc_dequeue_tail(struct Qdisc *sch,
328 struct sk_buff_head *list)
330 struct sk_buff *skb = __skb_dequeue_tail(list);
332 if (likely(skb != NULL))
333 sch->qstats.backlog -= skb->len;
338 static inline struct sk_buff *qdisc_dequeue_tail(struct Qdisc *sch)
340 return __qdisc_dequeue_tail(sch, &sch->q);
343 static inline int __qdisc_requeue(struct sk_buff *skb, struct Qdisc *sch,
344 struct sk_buff_head *list)
346 __skb_queue_head(list, skb);
347 sch->qstats.backlog += skb->len;
348 sch->qstats.requeues++;
350 return NET_XMIT_SUCCESS;
353 static inline int qdisc_requeue(struct sk_buff *skb, struct Qdisc *sch)
355 return __qdisc_requeue(skb, sch, &sch->q);
358 static inline void __qdisc_reset_queue(struct Qdisc *sch,
359 struct sk_buff_head *list)
362 * We do not know the backlog in bytes of this list, it
363 * is up to the caller to correct it
365 skb_queue_purge(list);
368 static inline void qdisc_reset_queue(struct Qdisc *sch)
370 __qdisc_reset_queue(sch, &sch->q);
371 sch->qstats.backlog = 0;
374 static inline unsigned int __qdisc_queue_drop(struct Qdisc *sch,
375 struct sk_buff_head *list)
377 struct sk_buff *skb = __qdisc_dequeue_tail(sch, list);
379 if (likely(skb != NULL)) {
380 unsigned int len = skb->len;
388 static inline unsigned int qdisc_queue_drop(struct Qdisc *sch)
390 return __qdisc_queue_drop(sch, &sch->q);
393 static inline int qdisc_drop(struct sk_buff *skb, struct Qdisc *sch)
398 return NET_XMIT_DROP;
401 static inline int qdisc_reshape_fail(struct sk_buff *skb, struct Qdisc *sch)
405 #ifdef CONFIG_NET_CLS_ACT
406 if (sch->reshape_fail == NULL || sch->reshape_fail(skb, sch))
409 return NET_XMIT_SUCCESS;
414 return NET_XMIT_DROP;
417 /* Length to Time (L2T) lookup in a qdisc_rate_table, to determine how
418 long it will take to send a packet given its size.
420 static inline u32 qdisc_l2t(struct qdisc_rate_table* rtab, unsigned int pktlen)
422 int slot = pktlen + rtab->rate.cell_align + rtab->rate.overhead;
425 slot >>= rtab->rate.cell_log;
427 return (rtab->data[255]*(slot >> 8) + rtab->data[slot & 0xFF]);
428 return rtab->data[slot];
431 #ifdef CONFIG_NET_CLS_ACT
432 static inline struct sk_buff *skb_act_clone(struct sk_buff *skb, gfp_t gfp_mask)
434 struct sk_buff *n = skb_clone(skb, gfp_mask);
437 n->tc_verd = SET_TC_VERD(n->tc_verd, 0);
438 n->tc_verd = CLR_TC_OK2MUNGE(n->tc_verd);
439 n->tc_verd = CLR_TC_MUNGED(n->tc_verd);