0ab53c575f87b39d72fce0df01bbbef61ae96ecb
[deliverable/linux.git] / include / net / sch_generic.h
1 #ifndef __NET_SCHED_GENERIC_H
2 #define __NET_SCHED_GENERIC_H
3
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>
12
13 struct Qdisc_ops;
14 struct qdisc_walker;
15 struct tcf_walker;
16 struct module;
17
18 struct qdisc_rate_table
19 {
20 struct tc_ratespec rate;
21 u32 data[256];
22 struct qdisc_rate_table *next;
23 int refcnt;
24 };
25
26 struct Qdisc
27 {
28 int (*enqueue)(struct sk_buff *skb, struct Qdisc *dev);
29 struct sk_buff * (*dequeue)(struct Qdisc *dev);
30 unsigned flags;
31 #define TCQ_F_BUILTIN 1
32 #define TCQ_F_THROTTLED 2
33 #define TCQ_F_INGRESS 4
34 int padded;
35 struct Qdisc_ops *ops;
36 u32 handle;
37 u32 parent;
38 atomic_t refcnt;
39 struct sk_buff_head q;
40 struct netdev_queue *dev_queue;
41 struct net_device *dev;
42 struct list_head list;
43
44 struct gnet_stats_basic bstats;
45 struct gnet_stats_queue qstats;
46 struct gnet_stats_rate_est rate_est;
47 spinlock_t *stats_lock;
48 struct rcu_head q_rcu;
49 int (*reshape_fail)(struct sk_buff *skb,
50 struct Qdisc *q);
51
52 /* This field is deprecated, but it is still used by CBQ
53 * and it will live until better solution will be invented.
54 */
55 struct Qdisc *__parent;
56 };
57
58 struct Qdisc_class_ops
59 {
60 /* Child qdisc manipulation */
61 int (*graft)(struct Qdisc *, unsigned long cl,
62 struct Qdisc *, struct Qdisc **);
63 struct Qdisc * (*leaf)(struct Qdisc *, unsigned long cl);
64 void (*qlen_notify)(struct Qdisc *, unsigned long);
65
66 /* Class manipulation routines */
67 unsigned long (*get)(struct Qdisc *, u32 classid);
68 void (*put)(struct Qdisc *, unsigned long);
69 int (*change)(struct Qdisc *, u32, u32,
70 struct nlattr **, unsigned long *);
71 int (*delete)(struct Qdisc *, unsigned long);
72 void (*walk)(struct Qdisc *, struct qdisc_walker * arg);
73
74 /* Filter manipulation */
75 struct tcf_proto ** (*tcf_chain)(struct Qdisc *, unsigned long);
76 unsigned long (*bind_tcf)(struct Qdisc *, unsigned long,
77 u32 classid);
78 void (*unbind_tcf)(struct Qdisc *, unsigned long);
79
80 /* rtnetlink specific */
81 int (*dump)(struct Qdisc *, unsigned long,
82 struct sk_buff *skb, struct tcmsg*);
83 int (*dump_stats)(struct Qdisc *, unsigned long,
84 struct gnet_dump *);
85 };
86
87 struct Qdisc_ops
88 {
89 struct Qdisc_ops *next;
90 const struct Qdisc_class_ops *cl_ops;
91 char id[IFNAMSIZ];
92 int priv_size;
93
94 int (*enqueue)(struct sk_buff *, struct Qdisc *);
95 struct sk_buff * (*dequeue)(struct Qdisc *);
96 int (*requeue)(struct sk_buff *, struct Qdisc *);
97 unsigned int (*drop)(struct Qdisc *);
98
99 int (*init)(struct Qdisc *, struct nlattr *arg);
100 void (*reset)(struct Qdisc *);
101 void (*destroy)(struct Qdisc *);
102 int (*change)(struct Qdisc *, struct nlattr *arg);
103
104 int (*dump)(struct Qdisc *, struct sk_buff *);
105 int (*dump_stats)(struct Qdisc *, struct gnet_dump *);
106
107 struct module *owner;
108 };
109
110
111 struct tcf_result
112 {
113 unsigned long class;
114 u32 classid;
115 };
116
117 struct tcf_proto_ops
118 {
119 struct tcf_proto_ops *next;
120 char kind[IFNAMSIZ];
121
122 int (*classify)(struct sk_buff*, struct tcf_proto*,
123 struct tcf_result *);
124 int (*init)(struct tcf_proto*);
125 void (*destroy)(struct tcf_proto*);
126
127 unsigned long (*get)(struct tcf_proto*, u32 handle);
128 void (*put)(struct tcf_proto*, unsigned long);
129 int (*change)(struct tcf_proto*, unsigned long,
130 u32 handle, struct nlattr **,
131 unsigned long *);
132 int (*delete)(struct tcf_proto*, unsigned long);
133 void (*walk)(struct tcf_proto*, struct tcf_walker *arg);
134
135 /* rtnetlink specific */
136 int (*dump)(struct tcf_proto*, unsigned long,
137 struct sk_buff *skb, struct tcmsg*);
138
139 struct module *owner;
140 };
141
142 struct tcf_proto
143 {
144 /* Fast access part */
145 struct tcf_proto *next;
146 void *root;
147 int (*classify)(struct sk_buff*, struct tcf_proto*,
148 struct tcf_result *);
149 __be16 protocol;
150
151 /* All the rest */
152 u32 prio;
153 u32 classid;
154 struct Qdisc *q;
155 void *data;
156 struct tcf_proto_ops *ops;
157 };
158
159
160 extern void qdisc_lock_tree(struct net_device *dev);
161 extern void qdisc_unlock_tree(struct net_device *dev);
162
163 #define sch_tree_lock(q) qdisc_lock_tree((q)->dev)
164 #define sch_tree_unlock(q) qdisc_unlock_tree((q)->dev)
165 #define tcf_tree_lock(tp) qdisc_lock_tree((tp)->q->dev)
166 #define tcf_tree_unlock(tp) qdisc_unlock_tree((tp)->q->dev)
167
168 extern struct Qdisc noop_qdisc;
169 extern struct Qdisc_ops noop_qdisc_ops;
170
171 struct Qdisc_class_common
172 {
173 u32 classid;
174 struct hlist_node hnode;
175 };
176
177 struct Qdisc_class_hash
178 {
179 struct hlist_head *hash;
180 unsigned int hashsize;
181 unsigned int hashmask;
182 unsigned int hashelems;
183 };
184
185 static inline unsigned int qdisc_class_hash(u32 id, u32 mask)
186 {
187 id ^= id >> 8;
188 id ^= id >> 4;
189 return id & mask;
190 }
191
192 static inline struct Qdisc_class_common *
193 qdisc_class_find(struct Qdisc_class_hash *hash, u32 id)
194 {
195 struct Qdisc_class_common *cl;
196 struct hlist_node *n;
197 unsigned int h;
198
199 h = qdisc_class_hash(id, hash->hashmask);
200 hlist_for_each_entry(cl, n, &hash->hash[h], hnode) {
201 if (cl->classid == id)
202 return cl;
203 }
204 return NULL;
205 }
206
207 extern int qdisc_class_hash_init(struct Qdisc_class_hash *);
208 extern void qdisc_class_hash_insert(struct Qdisc_class_hash *, struct Qdisc_class_common *);
209 extern void qdisc_class_hash_remove(struct Qdisc_class_hash *, struct Qdisc_class_common *);
210 extern void qdisc_class_hash_grow(struct Qdisc *, struct Qdisc_class_hash *);
211 extern void qdisc_class_hash_destroy(struct Qdisc_class_hash *);
212
213 extern void dev_init_scheduler(struct net_device *dev);
214 extern void dev_shutdown(struct net_device *dev);
215 extern void dev_activate(struct net_device *dev);
216 extern void dev_deactivate(struct net_device *dev);
217 extern void qdisc_reset(struct Qdisc *qdisc);
218 extern void qdisc_destroy(struct Qdisc *qdisc);
219 extern void qdisc_tree_decrease_qlen(struct Qdisc *qdisc, unsigned int n);
220 extern struct Qdisc *qdisc_alloc(struct net_device *dev,
221 struct netdev_queue *dev_queue,
222 struct Qdisc_ops *ops);
223 extern struct Qdisc *qdisc_create_dflt(struct net_device *dev,
224 struct netdev_queue *dev_queue,
225 struct Qdisc_ops *ops, u32 parentid);
226 extern void tcf_destroy(struct tcf_proto *tp);
227 extern void tcf_destroy_chain(struct tcf_proto **fl);
228
229 static inline int __qdisc_enqueue_tail(struct sk_buff *skb, struct Qdisc *sch,
230 struct sk_buff_head *list)
231 {
232 __skb_queue_tail(list, skb);
233 sch->qstats.backlog += skb->len;
234 sch->bstats.bytes += skb->len;
235 sch->bstats.packets++;
236
237 return NET_XMIT_SUCCESS;
238 }
239
240 static inline int qdisc_enqueue_tail(struct sk_buff *skb, struct Qdisc *sch)
241 {
242 return __qdisc_enqueue_tail(skb, sch, &sch->q);
243 }
244
245 static inline struct sk_buff *__qdisc_dequeue_head(struct Qdisc *sch,
246 struct sk_buff_head *list)
247 {
248 struct sk_buff *skb = __skb_dequeue(list);
249
250 if (likely(skb != NULL))
251 sch->qstats.backlog -= skb->len;
252
253 return skb;
254 }
255
256 static inline struct sk_buff *qdisc_dequeue_head(struct Qdisc *sch)
257 {
258 return __qdisc_dequeue_head(sch, &sch->q);
259 }
260
261 static inline struct sk_buff *__qdisc_dequeue_tail(struct Qdisc *sch,
262 struct sk_buff_head *list)
263 {
264 struct sk_buff *skb = __skb_dequeue_tail(list);
265
266 if (likely(skb != NULL))
267 sch->qstats.backlog -= skb->len;
268
269 return skb;
270 }
271
272 static inline struct sk_buff *qdisc_dequeue_tail(struct Qdisc *sch)
273 {
274 return __qdisc_dequeue_tail(sch, &sch->q);
275 }
276
277 static inline int __qdisc_requeue(struct sk_buff *skb, struct Qdisc *sch,
278 struct sk_buff_head *list)
279 {
280 __skb_queue_head(list, skb);
281 sch->qstats.backlog += skb->len;
282 sch->qstats.requeues++;
283
284 return NET_XMIT_SUCCESS;
285 }
286
287 static inline int qdisc_requeue(struct sk_buff *skb, struct Qdisc *sch)
288 {
289 return __qdisc_requeue(skb, sch, &sch->q);
290 }
291
292 static inline void __qdisc_reset_queue(struct Qdisc *sch,
293 struct sk_buff_head *list)
294 {
295 /*
296 * We do not know the backlog in bytes of this list, it
297 * is up to the caller to correct it
298 */
299 skb_queue_purge(list);
300 }
301
302 static inline void qdisc_reset_queue(struct Qdisc *sch)
303 {
304 __qdisc_reset_queue(sch, &sch->q);
305 sch->qstats.backlog = 0;
306 }
307
308 static inline unsigned int __qdisc_queue_drop(struct Qdisc *sch,
309 struct sk_buff_head *list)
310 {
311 struct sk_buff *skb = __qdisc_dequeue_tail(sch, list);
312
313 if (likely(skb != NULL)) {
314 unsigned int len = skb->len;
315 kfree_skb(skb);
316 return len;
317 }
318
319 return 0;
320 }
321
322 static inline unsigned int qdisc_queue_drop(struct Qdisc *sch)
323 {
324 return __qdisc_queue_drop(sch, &sch->q);
325 }
326
327 static inline int qdisc_drop(struct sk_buff *skb, struct Qdisc *sch)
328 {
329 kfree_skb(skb);
330 sch->qstats.drops++;
331
332 return NET_XMIT_DROP;
333 }
334
335 static inline int qdisc_reshape_fail(struct sk_buff *skb, struct Qdisc *sch)
336 {
337 sch->qstats.drops++;
338
339 #ifdef CONFIG_NET_CLS_ACT
340 if (sch->reshape_fail == NULL || sch->reshape_fail(skb, sch))
341 goto drop;
342
343 return NET_XMIT_SUCCESS;
344
345 drop:
346 #endif
347 kfree_skb(skb);
348 return NET_XMIT_DROP;
349 }
350
351 /* Length to Time (L2T) lookup in a qdisc_rate_table, to determine how
352 long it will take to send a packet given its size.
353 */
354 static inline u32 qdisc_l2t(struct qdisc_rate_table* rtab, unsigned int pktlen)
355 {
356 int slot = pktlen + rtab->rate.cell_align + rtab->rate.overhead;
357 if (slot < 0)
358 slot = 0;
359 slot >>= rtab->rate.cell_log;
360 if (slot > 255)
361 return (rtab->data[255]*(slot >> 8) + rtab->data[slot & 0xFF]);
362 return rtab->data[slot];
363 }
364
365 #ifdef CONFIG_NET_CLS_ACT
366 static inline struct sk_buff *skb_act_clone(struct sk_buff *skb, gfp_t gfp_mask)
367 {
368 struct sk_buff *n = skb_clone(skb, gfp_mask);
369
370 if (n) {
371 n->tc_verd = SET_TC_VERD(n->tc_verd, 0);
372 n->tc_verd = CLR_TC_OK2MUNGE(n->tc_verd);
373 n->tc_verd = CLR_TC_MUNGED(n->tc_verd);
374 }
375 return n;
376 }
377 #endif
378
379 #endif
This page took 0.075872 seconds and 5 git commands to generate.