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 net_device
*dev
;
42 struct list_head list
;
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
,
52 /* This field is deprecated, but it is still used by CBQ
53 * and it will live until better solution will be invented.
55 struct Qdisc
*__parent
;
58 struct Qdisc_class_ops
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);
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
);
74 /* Filter manipulation */
75 struct tcf_proto
** (*tcf_chain
)(struct Qdisc
*, unsigned long);
76 unsigned long (*bind_tcf
)(struct Qdisc
*, unsigned long,
78 void (*unbind_tcf
)(struct Qdisc
*, unsigned long);
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,
89 struct Qdisc_ops
*next
;
90 const struct Qdisc_class_ops
*cl_ops
;
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
*);
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
);
104 int (*dump
)(struct Qdisc
*, struct sk_buff
*);
105 int (*dump_stats
)(struct Qdisc
*, struct gnet_dump
*);
107 struct module
*owner
;
119 struct tcf_proto_ops
*next
;
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
*);
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
**,
132 int (*delete)(struct tcf_proto
*, unsigned long);
133 void (*walk
)(struct tcf_proto
*, struct tcf_walker
*arg
);
135 /* rtnetlink specific */
136 int (*dump
)(struct tcf_proto
*, unsigned long,
137 struct sk_buff
*skb
, struct tcmsg
*);
139 struct module
*owner
;
144 /* Fast access part */
145 struct tcf_proto
*next
;
147 int (*classify
)(struct sk_buff
*, struct tcf_proto
*,
148 struct tcf_result
*);
156 struct tcf_proto_ops
*ops
;
160 extern void qdisc_lock_tree(struct net_device
*dev
);
161 extern void qdisc_unlock_tree(struct net_device
*dev
);
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)
168 extern struct Qdisc noop_qdisc
;
169 extern struct Qdisc_ops noop_qdisc_ops
;
171 struct Qdisc_class_common
174 struct hlist_node hnode
;
177 struct Qdisc_class_hash
179 struct hlist_head
*hash
;
180 unsigned int hashsize
;
181 unsigned int hashmask
;
182 unsigned int hashelems
;
185 static inline unsigned int qdisc_class_hash(u32 id
, u32 mask
)
192 static inline struct Qdisc_class_common
*
193 qdisc_class_find(struct Qdisc_class_hash
*hash
, u32 id
)
195 struct Qdisc_class_common
*cl
;
196 struct hlist_node
*n
;
199 h
= qdisc_class_hash(id
, hash
->hashmask
);
200 hlist_for_each_entry(cl
, n
, &hash
->hash
[h
], hnode
) {
201 if (cl
->classid
== id
)
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
*);
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
);
229 static inline int __qdisc_enqueue_tail(struct sk_buff
*skb
, struct Qdisc
*sch
,
230 struct sk_buff_head
*list
)
232 __skb_queue_tail(list
, skb
);
233 sch
->qstats
.backlog
+= skb
->len
;
234 sch
->bstats
.bytes
+= skb
->len
;
235 sch
->bstats
.packets
++;
237 return NET_XMIT_SUCCESS
;
240 static inline int qdisc_enqueue_tail(struct sk_buff
*skb
, struct Qdisc
*sch
)
242 return __qdisc_enqueue_tail(skb
, sch
, &sch
->q
);
245 static inline struct sk_buff
*__qdisc_dequeue_head(struct Qdisc
*sch
,
246 struct sk_buff_head
*list
)
248 struct sk_buff
*skb
= __skb_dequeue(list
);
250 if (likely(skb
!= NULL
))
251 sch
->qstats
.backlog
-= skb
->len
;
256 static inline struct sk_buff
*qdisc_dequeue_head(struct Qdisc
*sch
)
258 return __qdisc_dequeue_head(sch
, &sch
->q
);
261 static inline struct sk_buff
*__qdisc_dequeue_tail(struct Qdisc
*sch
,
262 struct sk_buff_head
*list
)
264 struct sk_buff
*skb
= __skb_dequeue_tail(list
);
266 if (likely(skb
!= NULL
))
267 sch
->qstats
.backlog
-= skb
->len
;
272 static inline struct sk_buff
*qdisc_dequeue_tail(struct Qdisc
*sch
)
274 return __qdisc_dequeue_tail(sch
, &sch
->q
);
277 static inline int __qdisc_requeue(struct sk_buff
*skb
, struct Qdisc
*sch
,
278 struct sk_buff_head
*list
)
280 __skb_queue_head(list
, skb
);
281 sch
->qstats
.backlog
+= skb
->len
;
282 sch
->qstats
.requeues
++;
284 return NET_XMIT_SUCCESS
;
287 static inline int qdisc_requeue(struct sk_buff
*skb
, struct Qdisc
*sch
)
289 return __qdisc_requeue(skb
, sch
, &sch
->q
);
292 static inline void __qdisc_reset_queue(struct Qdisc
*sch
,
293 struct sk_buff_head
*list
)
296 * We do not know the backlog in bytes of this list, it
297 * is up to the caller to correct it
299 skb_queue_purge(list
);
302 static inline void qdisc_reset_queue(struct Qdisc
*sch
)
304 __qdisc_reset_queue(sch
, &sch
->q
);
305 sch
->qstats
.backlog
= 0;
308 static inline unsigned int __qdisc_queue_drop(struct Qdisc
*sch
,
309 struct sk_buff_head
*list
)
311 struct sk_buff
*skb
= __qdisc_dequeue_tail(sch
, list
);
313 if (likely(skb
!= NULL
)) {
314 unsigned int len
= skb
->len
;
322 static inline unsigned int qdisc_queue_drop(struct Qdisc
*sch
)
324 return __qdisc_queue_drop(sch
, &sch
->q
);
327 static inline int qdisc_drop(struct sk_buff
*skb
, struct Qdisc
*sch
)
332 return NET_XMIT_DROP
;
335 static inline int qdisc_reshape_fail(struct sk_buff
*skb
, struct Qdisc
*sch
)
339 #ifdef CONFIG_NET_CLS_ACT
340 if (sch
->reshape_fail
== NULL
|| sch
->reshape_fail(skb
, sch
))
343 return NET_XMIT_SUCCESS
;
348 return NET_XMIT_DROP
;
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.
354 static inline u32
qdisc_l2t(struct qdisc_rate_table
* rtab
, unsigned int pktlen
)
356 int slot
= pktlen
+ rtab
->rate
.cell_align
+ rtab
->rate
.overhead
;
359 slot
>>= rtab
->rate
.cell_log
;
361 return (rtab
->data
[255]*(slot
>> 8) + rtab
->data
[slot
& 0xFF]);
362 return rtab
->data
[slot
];
365 #ifdef CONFIG_NET_CLS_ACT
366 static inline struct sk_buff
*skb_act_clone(struct sk_buff
*skb
, gfp_t gfp_mask
)
368 struct sk_buff
*n
= skb_clone(skb
, gfp_mask
);
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
);