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 struct rcu_head q_rcu;
47 int (*reshape_fail)(struct sk_buff *skb,
50 /* This field is deprecated, but it is still used by CBQ
51 * and it will live until better solution will be invented.
53 struct Qdisc *__parent;
56 struct Qdisc_class_ops
58 /* Child qdisc manipulation */
59 int (*graft)(struct Qdisc *, unsigned long cl,
60 struct Qdisc *, struct Qdisc **);
61 struct Qdisc * (*leaf)(struct Qdisc *, unsigned long cl);
62 void (*qlen_notify)(struct Qdisc *, unsigned long);
64 /* Class manipulation routines */
65 unsigned long (*get)(struct Qdisc *, u32 classid);
66 void (*put)(struct Qdisc *, unsigned long);
67 int (*change)(struct Qdisc *, u32, u32,
68 struct nlattr **, unsigned long *);
69 int (*delete)(struct Qdisc *, unsigned long);
70 void (*walk)(struct Qdisc *, struct qdisc_walker * arg);
72 /* Filter manipulation */
73 struct tcf_proto ** (*tcf_chain)(struct Qdisc *, unsigned long);
74 unsigned long (*bind_tcf)(struct Qdisc *, unsigned long,
76 void (*unbind_tcf)(struct Qdisc *, unsigned long);
78 /* rtnetlink specific */
79 int (*dump)(struct Qdisc *, unsigned long,
80 struct sk_buff *skb, struct tcmsg*);
81 int (*dump_stats)(struct Qdisc *, unsigned long,
87 struct Qdisc_ops *next;
88 const struct Qdisc_class_ops *cl_ops;
92 int (*enqueue)(struct sk_buff *, struct Qdisc *);
93 struct sk_buff * (*dequeue)(struct Qdisc *);
94 int (*requeue)(struct sk_buff *, struct Qdisc *);
95 unsigned int (*drop)(struct Qdisc *);
97 int (*init)(struct Qdisc *, struct nlattr *arg);
98 void (*reset)(struct Qdisc *);
99 void (*destroy)(struct Qdisc *);
100 int (*change)(struct Qdisc *, struct nlattr *arg);
102 int (*dump)(struct Qdisc *, struct sk_buff *);
103 int (*dump_stats)(struct Qdisc *, struct gnet_dump *);
105 struct module *owner;
117 struct tcf_proto_ops *next;
120 int (*classify)(struct sk_buff*, struct tcf_proto*,
121 struct tcf_result *);
122 int (*init)(struct tcf_proto*);
123 void (*destroy)(struct tcf_proto*);
125 unsigned long (*get)(struct tcf_proto*, u32 handle);
126 void (*put)(struct tcf_proto*, unsigned long);
127 int (*change)(struct tcf_proto*, unsigned long,
128 u32 handle, struct nlattr **,
130 int (*delete)(struct tcf_proto*, unsigned long);
131 void (*walk)(struct tcf_proto*, struct tcf_walker *arg);
133 /* rtnetlink specific */
134 int (*dump)(struct tcf_proto*, unsigned long,
135 struct sk_buff *skb, struct tcmsg*);
137 struct module *owner;
142 /* Fast access part */
143 struct tcf_proto *next;
145 int (*classify)(struct sk_buff*, struct tcf_proto*,
146 struct tcf_result *);
154 struct tcf_proto_ops *ops;
157 static inline struct net_device *qdisc_dev(struct Qdisc *qdisc)
159 return qdisc->dev_queue->dev;
162 extern void qdisc_lock_tree(struct net_device *dev);
163 extern void qdisc_unlock_tree(struct net_device *dev);
165 #define sch_tree_lock(q) qdisc_lock_tree(qdisc_dev(q))
166 #define sch_tree_unlock(q) qdisc_unlock_tree(qdisc_dev(q))
167 #define tcf_tree_lock(tp) qdisc_lock_tree(qdisc_dev((tp)->q))
168 #define tcf_tree_unlock(tp) qdisc_unlock_tree(qdisc_dev((tp)->q))
170 extern struct Qdisc noop_qdisc;
171 extern struct Qdisc_ops noop_qdisc_ops;
173 struct Qdisc_class_common
176 struct hlist_node hnode;
179 struct Qdisc_class_hash
181 struct hlist_head *hash;
182 unsigned int hashsize;
183 unsigned int hashmask;
184 unsigned int hashelems;
187 static inline unsigned int qdisc_class_hash(u32 id, u32 mask)
194 static inline struct Qdisc_class_common *
195 qdisc_class_find(struct Qdisc_class_hash *hash, u32 id)
197 struct Qdisc_class_common *cl;
198 struct hlist_node *n;
201 h = qdisc_class_hash(id, hash->hashmask);
202 hlist_for_each_entry(cl, n, &hash->hash[h], hnode) {
203 if (cl->classid == id)
209 extern int qdisc_class_hash_init(struct Qdisc_class_hash *);
210 extern void qdisc_class_hash_insert(struct Qdisc_class_hash *, struct Qdisc_class_common *);
211 extern void qdisc_class_hash_remove(struct Qdisc_class_hash *, struct Qdisc_class_common *);
212 extern void qdisc_class_hash_grow(struct Qdisc *, struct Qdisc_class_hash *);
213 extern void qdisc_class_hash_destroy(struct Qdisc_class_hash *);
215 extern void dev_init_scheduler(struct net_device *dev);
216 extern void dev_shutdown(struct net_device *dev);
217 extern void dev_activate(struct net_device *dev);
218 extern void dev_deactivate(struct net_device *dev);
219 extern void qdisc_reset(struct Qdisc *qdisc);
220 extern void qdisc_destroy(struct Qdisc *qdisc);
221 extern void qdisc_tree_decrease_qlen(struct Qdisc *qdisc, unsigned int n);
222 extern struct Qdisc *qdisc_alloc(struct netdev_queue *dev_queue,
223 struct Qdisc_ops *ops);
224 extern struct Qdisc *qdisc_create_dflt(struct net_device *dev,
225 struct netdev_queue *dev_queue,
226 struct Qdisc_ops *ops, u32 parentid);
227 extern void tcf_destroy(struct tcf_proto *tp);
228 extern void tcf_destroy_chain(struct tcf_proto **fl);
230 static inline int __qdisc_enqueue_tail(struct sk_buff *skb, struct Qdisc *sch,
231 struct sk_buff_head *list)
233 __skb_queue_tail(list, skb);
234 sch->qstats.backlog += skb->len;
235 sch->bstats.bytes += skb->len;
236 sch->bstats.packets++;
238 return NET_XMIT_SUCCESS;
241 static inline int qdisc_enqueue_tail(struct sk_buff *skb, struct Qdisc *sch)
243 return __qdisc_enqueue_tail(skb, sch, &sch->q);
246 static inline struct sk_buff *__qdisc_dequeue_head(struct Qdisc *sch,
247 struct sk_buff_head *list)
249 struct sk_buff *skb = __skb_dequeue(list);
251 if (likely(skb != NULL))
252 sch->qstats.backlog -= skb->len;
257 static inline struct sk_buff *qdisc_dequeue_head(struct Qdisc *sch)
259 return __qdisc_dequeue_head(sch, &sch->q);
262 static inline struct sk_buff *__qdisc_dequeue_tail(struct Qdisc *sch,
263 struct sk_buff_head *list)
265 struct sk_buff *skb = __skb_dequeue_tail(list);
267 if (likely(skb != NULL))
268 sch->qstats.backlog -= skb->len;
273 static inline struct sk_buff *qdisc_dequeue_tail(struct Qdisc *sch)
275 return __qdisc_dequeue_tail(sch, &sch->q);
278 static inline int __qdisc_requeue(struct sk_buff *skb, struct Qdisc *sch,
279 struct sk_buff_head *list)
281 __skb_queue_head(list, skb);
282 sch->qstats.backlog += skb->len;
283 sch->qstats.requeues++;
285 return NET_XMIT_SUCCESS;
288 static inline int qdisc_requeue(struct sk_buff *skb, struct Qdisc *sch)
290 return __qdisc_requeue(skb, sch, &sch->q);
293 static inline void __qdisc_reset_queue(struct Qdisc *sch,
294 struct sk_buff_head *list)
297 * We do not know the backlog in bytes of this list, it
298 * is up to the caller to correct it
300 skb_queue_purge(list);
303 static inline void qdisc_reset_queue(struct Qdisc *sch)
305 __qdisc_reset_queue(sch, &sch->q);
306 sch->qstats.backlog = 0;
309 static inline unsigned int __qdisc_queue_drop(struct Qdisc *sch,
310 struct sk_buff_head *list)
312 struct sk_buff *skb = __qdisc_dequeue_tail(sch, list);
314 if (likely(skb != NULL)) {
315 unsigned int len = skb->len;
323 static inline unsigned int qdisc_queue_drop(struct Qdisc *sch)
325 return __qdisc_queue_drop(sch, &sch->q);
328 static inline int qdisc_drop(struct sk_buff *skb, struct Qdisc *sch)
333 return NET_XMIT_DROP;
336 static inline int qdisc_reshape_fail(struct sk_buff *skb, struct Qdisc *sch)
340 #ifdef CONFIG_NET_CLS_ACT
341 if (sch->reshape_fail == NULL || sch->reshape_fail(skb, sch))
344 return NET_XMIT_SUCCESS;
349 return NET_XMIT_DROP;
352 /* Length to Time (L2T) lookup in a qdisc_rate_table, to determine how
353 long it will take to send a packet given its size.
355 static inline u32 qdisc_l2t(struct qdisc_rate_table* rtab, unsigned int pktlen)
357 int slot = pktlen + rtab->rate.cell_align + rtab->rate.overhead;
360 slot >>= rtab->rate.cell_log;
362 return (rtab->data[255]*(slot >> 8) + rtab->data[slot & 0xFF]);
363 return rtab->data[slot];
366 #ifdef CONFIG_NET_CLS_ACT
367 static inline struct sk_buff *skb_act_clone(struct sk_buff *skb, gfp_t gfp_mask)
369 struct sk_buff *n = skb_clone(skb, gfp_mask);
372 n->tc_verd = SET_TC_VERD(n->tc_verd, 0);
373 n->tc_verd = CLR_TC_OK2MUNGE(n->tc_verd);
374 n->tc_verd = CLR_TC_MUNGED(n->tc_verd);