Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | #ifndef __NET_SCHED_GENERIC_H |
| 2 | #define __NET_SCHED_GENERIC_H |
| 3 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4 | #include <linux/netdevice.h> |
| 5 | #include <linux/types.h> |
| 6 | #include <linux/rcupdate.h> |
| 7 | #include <linux/module.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8 | #include <linux/pkt_sched.h> |
| 9 | #include <linux/pkt_cls.h> |
| 10 | #include <net/gen_stats.h> |
Thomas Graf | be577dd | 2007-03-22 11:55:50 -0700 | [diff] [blame] | 11 | #include <net/rtnetlink.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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 | |
David S. Miller | e2627c8 | 2008-07-16 00:56:32 -0700 | [diff] [blame] | 26 | enum qdisc_state_t |
| 27 | { |
| 28 | __QDISC_STATE_RUNNING, |
David S. Miller | 37437bb | 2008-07-16 02:15:04 -0700 | [diff] [blame] | 29 | __QDISC_STATE_SCHED, |
David S. Miller | e2627c8 | 2008-07-16 00:56:32 -0700 | [diff] [blame] | 30 | }; |
| 31 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 32 | struct Qdisc |
| 33 | { |
| 34 | int (*enqueue)(struct sk_buff *skb, struct Qdisc *dev); |
| 35 | struct sk_buff * (*dequeue)(struct Qdisc *dev); |
| 36 | unsigned flags; |
| 37 | #define TCQ_F_BUILTIN 1 |
| 38 | #define TCQ_F_THROTTLED 2 |
| 39 | #define TCQ_F_INGRESS 4 |
| 40 | int padded; |
| 41 | struct Qdisc_ops *ops; |
| 42 | u32 handle; |
| 43 | u32 parent; |
| 44 | atomic_t refcnt; |
David S. Miller | e2627c8 | 2008-07-16 00:56:32 -0700 | [diff] [blame] | 45 | unsigned long state; |
David S. Miller | d3b753d | 2008-07-15 20:14:35 -0700 | [diff] [blame] | 46 | struct sk_buff *gso_skb; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 47 | struct sk_buff_head q; |
David S. Miller | bb949fb | 2008-07-08 16:55:56 -0700 | [diff] [blame] | 48 | struct netdev_queue *dev_queue; |
David S. Miller | 37437bb | 2008-07-16 02:15:04 -0700 | [diff] [blame] | 49 | struct Qdisc *next_sched; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 50 | struct list_head list; |
| 51 | |
| 52 | struct gnet_stats_basic bstats; |
| 53 | struct gnet_stats_queue qstats; |
| 54 | struct gnet_stats_rate_est rate_est; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 55 | struct rcu_head q_rcu; |
| 56 | int (*reshape_fail)(struct sk_buff *skb, |
| 57 | struct Qdisc *q); |
| 58 | |
David S. Miller | 72b25a9 | 2008-07-18 20:54:17 -0700 | [diff] [blame] | 59 | void *u32_node; |
| 60 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 61 | /* This field is deprecated, but it is still used by CBQ |
| 62 | * and it will live until better solution will be invented. |
| 63 | */ |
| 64 | struct Qdisc *__parent; |
| 65 | }; |
| 66 | |
| 67 | struct Qdisc_class_ops |
| 68 | { |
| 69 | /* Child qdisc manipulation */ |
| 70 | int (*graft)(struct Qdisc *, unsigned long cl, |
| 71 | struct Qdisc *, struct Qdisc **); |
| 72 | struct Qdisc * (*leaf)(struct Qdisc *, unsigned long cl); |
Patrick McHardy | 43effa1 | 2006-11-29 17:35:48 -0800 | [diff] [blame] | 73 | void (*qlen_notify)(struct Qdisc *, unsigned long); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 74 | |
| 75 | /* Class manipulation routines */ |
| 76 | unsigned long (*get)(struct Qdisc *, u32 classid); |
| 77 | void (*put)(struct Qdisc *, unsigned long); |
| 78 | int (*change)(struct Qdisc *, u32, u32, |
Patrick McHardy | 1e90474 | 2008-01-22 22:11:17 -0800 | [diff] [blame] | 79 | struct nlattr **, unsigned long *); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 80 | int (*delete)(struct Qdisc *, unsigned long); |
| 81 | void (*walk)(struct Qdisc *, struct qdisc_walker * arg); |
| 82 | |
| 83 | /* Filter manipulation */ |
| 84 | struct tcf_proto ** (*tcf_chain)(struct Qdisc *, unsigned long); |
| 85 | unsigned long (*bind_tcf)(struct Qdisc *, unsigned long, |
| 86 | u32 classid); |
| 87 | void (*unbind_tcf)(struct Qdisc *, unsigned long); |
| 88 | |
| 89 | /* rtnetlink specific */ |
| 90 | int (*dump)(struct Qdisc *, unsigned long, |
| 91 | struct sk_buff *skb, struct tcmsg*); |
| 92 | int (*dump_stats)(struct Qdisc *, unsigned long, |
| 93 | struct gnet_dump *); |
| 94 | }; |
| 95 | |
| 96 | struct Qdisc_ops |
| 97 | { |
| 98 | struct Qdisc_ops *next; |
Eric Dumazet | 20fea08 | 2007-11-14 01:44:41 -0800 | [diff] [blame] | 99 | const struct Qdisc_class_ops *cl_ops; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 100 | char id[IFNAMSIZ]; |
| 101 | int priv_size; |
| 102 | |
| 103 | int (*enqueue)(struct sk_buff *, struct Qdisc *); |
| 104 | struct sk_buff * (*dequeue)(struct Qdisc *); |
| 105 | int (*requeue)(struct sk_buff *, struct Qdisc *); |
| 106 | unsigned int (*drop)(struct Qdisc *); |
| 107 | |
Patrick McHardy | 1e90474 | 2008-01-22 22:11:17 -0800 | [diff] [blame] | 108 | int (*init)(struct Qdisc *, struct nlattr *arg); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 109 | void (*reset)(struct Qdisc *); |
| 110 | void (*destroy)(struct Qdisc *); |
Patrick McHardy | 1e90474 | 2008-01-22 22:11:17 -0800 | [diff] [blame] | 111 | int (*change)(struct Qdisc *, struct nlattr *arg); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 112 | |
| 113 | int (*dump)(struct Qdisc *, struct sk_buff *); |
| 114 | int (*dump_stats)(struct Qdisc *, struct gnet_dump *); |
| 115 | |
| 116 | struct module *owner; |
| 117 | }; |
| 118 | |
| 119 | |
| 120 | struct tcf_result |
| 121 | { |
| 122 | unsigned long class; |
| 123 | u32 classid; |
| 124 | }; |
| 125 | |
| 126 | struct tcf_proto_ops |
| 127 | { |
| 128 | struct tcf_proto_ops *next; |
| 129 | char kind[IFNAMSIZ]; |
| 130 | |
| 131 | int (*classify)(struct sk_buff*, struct tcf_proto*, |
| 132 | struct tcf_result *); |
| 133 | int (*init)(struct tcf_proto*); |
| 134 | void (*destroy)(struct tcf_proto*); |
| 135 | |
| 136 | unsigned long (*get)(struct tcf_proto*, u32 handle); |
| 137 | void (*put)(struct tcf_proto*, unsigned long); |
| 138 | int (*change)(struct tcf_proto*, unsigned long, |
Patrick McHardy | add93b6 | 2008-01-22 22:11:33 -0800 | [diff] [blame] | 139 | u32 handle, struct nlattr **, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 140 | unsigned long *); |
| 141 | int (*delete)(struct tcf_proto*, unsigned long); |
| 142 | void (*walk)(struct tcf_proto*, struct tcf_walker *arg); |
| 143 | |
| 144 | /* rtnetlink specific */ |
| 145 | int (*dump)(struct tcf_proto*, unsigned long, |
| 146 | struct sk_buff *skb, struct tcmsg*); |
| 147 | |
| 148 | struct module *owner; |
| 149 | }; |
| 150 | |
| 151 | struct tcf_proto |
| 152 | { |
| 153 | /* Fast access part */ |
| 154 | struct tcf_proto *next; |
| 155 | void *root; |
| 156 | int (*classify)(struct sk_buff*, struct tcf_proto*, |
| 157 | struct tcf_result *); |
Al Viro | 66c6f52 | 2006-11-20 18:07:51 -0800 | [diff] [blame] | 158 | __be16 protocol; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 159 | |
| 160 | /* All the rest */ |
| 161 | u32 prio; |
| 162 | u32 classid; |
| 163 | struct Qdisc *q; |
| 164 | void *data; |
| 165 | struct tcf_proto_ops *ops; |
| 166 | }; |
| 167 | |
David S. Miller | 8387400 | 2008-07-17 00:53:03 -0700 | [diff] [blame] | 168 | static inline spinlock_t *qdisc_lock(struct Qdisc *qdisc) |
| 169 | { |
| 170 | return &qdisc->q.lock; |
| 171 | } |
| 172 | |
David S. Miller | 7698b4f | 2008-07-16 01:42:40 -0700 | [diff] [blame] | 173 | static inline struct Qdisc *qdisc_root(struct Qdisc *qdisc) |
| 174 | { |
| 175 | return qdisc->dev_queue->qdisc; |
| 176 | } |
| 177 | |
| 178 | static inline spinlock_t *qdisc_root_lock(struct Qdisc *qdisc) |
| 179 | { |
| 180 | struct Qdisc *root = qdisc_root(qdisc); |
| 181 | |
David S. Miller | 8387400 | 2008-07-17 00:53:03 -0700 | [diff] [blame] | 182 | return qdisc_lock(root); |
David S. Miller | 7698b4f | 2008-07-16 01:42:40 -0700 | [diff] [blame] | 183 | } |
| 184 | |
David S. Miller | 5ce2d48 | 2008-07-08 17:06:30 -0700 | [diff] [blame] | 185 | static inline struct net_device *qdisc_dev(struct Qdisc *qdisc) |
| 186 | { |
| 187 | return qdisc->dev_queue->dev; |
| 188 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 189 | |
David S. Miller | 78a5b30 | 2008-07-16 03:12:24 -0700 | [diff] [blame] | 190 | static inline void sch_tree_lock(struct Qdisc *q) |
| 191 | { |
| 192 | spin_lock_bh(qdisc_root_lock(q)); |
| 193 | } |
| 194 | |
| 195 | static inline void sch_tree_unlock(struct Qdisc *q) |
| 196 | { |
| 197 | spin_unlock_bh(qdisc_root_lock(q)); |
| 198 | } |
| 199 | |
| 200 | #define tcf_tree_lock(tp) sch_tree_lock((tp)->q) |
| 201 | #define tcf_tree_unlock(tp) sch_tree_unlock((tp)->q) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 202 | |
Thomas Graf | e41a33e | 2005-07-05 14:14:30 -0700 | [diff] [blame] | 203 | extern struct Qdisc noop_qdisc; |
| 204 | extern struct Qdisc_ops noop_qdisc_ops; |
| 205 | |
Patrick McHardy | 6fe1c7a | 2008-07-05 23:21:31 -0700 | [diff] [blame] | 206 | struct Qdisc_class_common |
| 207 | { |
| 208 | u32 classid; |
| 209 | struct hlist_node hnode; |
| 210 | }; |
| 211 | |
| 212 | struct Qdisc_class_hash |
| 213 | { |
| 214 | struct hlist_head *hash; |
| 215 | unsigned int hashsize; |
| 216 | unsigned int hashmask; |
| 217 | unsigned int hashelems; |
| 218 | }; |
| 219 | |
| 220 | static inline unsigned int qdisc_class_hash(u32 id, u32 mask) |
| 221 | { |
| 222 | id ^= id >> 8; |
| 223 | id ^= id >> 4; |
| 224 | return id & mask; |
| 225 | } |
| 226 | |
| 227 | static inline struct Qdisc_class_common * |
| 228 | qdisc_class_find(struct Qdisc_class_hash *hash, u32 id) |
| 229 | { |
| 230 | struct Qdisc_class_common *cl; |
| 231 | struct hlist_node *n; |
| 232 | unsigned int h; |
| 233 | |
| 234 | h = qdisc_class_hash(id, hash->hashmask); |
| 235 | hlist_for_each_entry(cl, n, &hash->hash[h], hnode) { |
| 236 | if (cl->classid == id) |
| 237 | return cl; |
| 238 | } |
| 239 | return NULL; |
| 240 | } |
| 241 | |
| 242 | extern int qdisc_class_hash_init(struct Qdisc_class_hash *); |
| 243 | extern void qdisc_class_hash_insert(struct Qdisc_class_hash *, struct Qdisc_class_common *); |
| 244 | extern void qdisc_class_hash_remove(struct Qdisc_class_hash *, struct Qdisc_class_common *); |
| 245 | extern void qdisc_class_hash_grow(struct Qdisc *, struct Qdisc_class_hash *); |
| 246 | extern void qdisc_class_hash_destroy(struct Qdisc_class_hash *); |
| 247 | |
Thomas Graf | e41a33e | 2005-07-05 14:14:30 -0700 | [diff] [blame] | 248 | extern void dev_init_scheduler(struct net_device *dev); |
| 249 | extern void dev_shutdown(struct net_device *dev); |
| 250 | extern void dev_activate(struct net_device *dev); |
| 251 | extern void dev_deactivate(struct net_device *dev); |
| 252 | extern void qdisc_reset(struct Qdisc *qdisc); |
| 253 | extern void qdisc_destroy(struct Qdisc *qdisc); |
Patrick McHardy | 43effa1 | 2006-11-29 17:35:48 -0800 | [diff] [blame] | 254 | extern void qdisc_tree_decrease_qlen(struct Qdisc *qdisc, unsigned int n); |
David S. Miller | 5ce2d48 | 2008-07-08 17:06:30 -0700 | [diff] [blame] | 255 | extern struct Qdisc *qdisc_alloc(struct netdev_queue *dev_queue, |
David S. Miller | bb949fb | 2008-07-08 16:55:56 -0700 | [diff] [blame] | 256 | struct Qdisc_ops *ops); |
Thomas Graf | e41a33e | 2005-07-05 14:14:30 -0700 | [diff] [blame] | 257 | extern struct Qdisc *qdisc_create_dflt(struct net_device *dev, |
David S. Miller | bb949fb | 2008-07-08 16:55:56 -0700 | [diff] [blame] | 258 | struct netdev_queue *dev_queue, |
Patrick McHardy | 9f9afec | 2006-11-29 17:35:18 -0800 | [diff] [blame] | 259 | struct Qdisc_ops *ops, u32 parentid); |
Patrick McHardy | a48b5a6 | 2007-03-23 11:29:43 -0700 | [diff] [blame] | 260 | extern void tcf_destroy(struct tcf_proto *tp); |
Patrick McHardy | ff31ab5 | 2008-07-01 19:52:38 -0700 | [diff] [blame] | 261 | extern void tcf_destroy_chain(struct tcf_proto **fl); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 262 | |
David S. Miller | 5aa7099 | 2008-07-08 22:59:10 -0700 | [diff] [blame] | 263 | /* Reset all TX qdiscs of a device. */ |
| 264 | static inline void qdisc_reset_all_tx(struct net_device *dev) |
| 265 | { |
David S. Miller | e8a0464 | 2008-07-17 00:34:19 -0700 | [diff] [blame] | 266 | unsigned int i; |
| 267 | for (i = 0; i < dev->num_tx_queues; i++) |
| 268 | qdisc_reset(netdev_get_tx_queue(dev, i)->qdisc); |
David S. Miller | 5aa7099 | 2008-07-08 22:59:10 -0700 | [diff] [blame] | 269 | } |
| 270 | |
David S. Miller | 3e745dd | 2008-07-08 23:00:25 -0700 | [diff] [blame] | 271 | /* Are all TX queues of the device empty? */ |
| 272 | static inline bool qdisc_all_tx_empty(const struct net_device *dev) |
| 273 | { |
David S. Miller | e8a0464 | 2008-07-17 00:34:19 -0700 | [diff] [blame] | 274 | unsigned int i; |
| 275 | for (i = 0; i < dev->num_tx_queues; i++) { |
| 276 | struct netdev_queue *txq = netdev_get_tx_queue(dev, i); |
| 277 | const struct Qdisc *q = txq->qdisc; |
David S. Miller | 3e745dd | 2008-07-08 23:00:25 -0700 | [diff] [blame] | 278 | |
David S. Miller | e8a0464 | 2008-07-17 00:34:19 -0700 | [diff] [blame] | 279 | if (q->q.qlen) |
| 280 | return false; |
| 281 | } |
| 282 | return true; |
David S. Miller | 3e745dd | 2008-07-08 23:00:25 -0700 | [diff] [blame] | 283 | } |
| 284 | |
David S. Miller | 6fa9864 | 2008-07-08 23:01:06 -0700 | [diff] [blame] | 285 | /* Are any of the TX qdiscs changing? */ |
| 286 | static inline bool qdisc_tx_changing(struct net_device *dev) |
| 287 | { |
David S. Miller | e8a0464 | 2008-07-17 00:34:19 -0700 | [diff] [blame] | 288 | unsigned int i; |
| 289 | for (i = 0; i < dev->num_tx_queues; i++) { |
| 290 | struct netdev_queue *txq = netdev_get_tx_queue(dev, i); |
| 291 | if (txq->qdisc != txq->qdisc_sleeping) |
| 292 | return true; |
| 293 | } |
| 294 | return false; |
David S. Miller | 6fa9864 | 2008-07-08 23:01:06 -0700 | [diff] [blame] | 295 | } |
| 296 | |
David S. Miller | e8a0464 | 2008-07-17 00:34:19 -0700 | [diff] [blame] | 297 | /* Is the device using the noop qdisc on all queues? */ |
David S. Miller | 0529794 | 2008-07-08 23:01:27 -0700 | [diff] [blame] | 298 | static inline bool qdisc_tx_is_noop(const struct net_device *dev) |
| 299 | { |
David S. Miller | e8a0464 | 2008-07-17 00:34:19 -0700 | [diff] [blame] | 300 | unsigned int i; |
| 301 | for (i = 0; i < dev->num_tx_queues; i++) { |
| 302 | struct netdev_queue *txq = netdev_get_tx_queue(dev, i); |
| 303 | if (txq->qdisc != &noop_qdisc) |
| 304 | return false; |
| 305 | } |
| 306 | return true; |
David S. Miller | 0529794 | 2008-07-08 23:01:27 -0700 | [diff] [blame] | 307 | } |
| 308 | |
Jussi Kivilinna | 5f86173 | 2008-07-20 00:08:04 -0700 | [diff] [blame^] | 309 | static inline int qdisc_enqueue(struct sk_buff *skb, struct Qdisc *sch) |
| 310 | { |
| 311 | return sch->enqueue(skb, sch); |
| 312 | } |
| 313 | |
| 314 | static inline int qdisc_enqueue_root(struct sk_buff *skb, struct Qdisc *sch) |
| 315 | { |
| 316 | return qdisc_enqueue(skb, sch); |
| 317 | } |
| 318 | |
Thomas Graf | 9972b25 | 2005-06-18 22:57:26 -0700 | [diff] [blame] | 319 | static inline int __qdisc_enqueue_tail(struct sk_buff *skb, struct Qdisc *sch, |
| 320 | struct sk_buff_head *list) |
| 321 | { |
| 322 | __skb_queue_tail(list, skb); |
| 323 | sch->qstats.backlog += skb->len; |
| 324 | sch->bstats.bytes += skb->len; |
| 325 | sch->bstats.packets++; |
| 326 | |
| 327 | return NET_XMIT_SUCCESS; |
| 328 | } |
| 329 | |
| 330 | static inline int qdisc_enqueue_tail(struct sk_buff *skb, struct Qdisc *sch) |
| 331 | { |
| 332 | return __qdisc_enqueue_tail(skb, sch, &sch->q); |
| 333 | } |
| 334 | |
| 335 | static inline struct sk_buff *__qdisc_dequeue_head(struct Qdisc *sch, |
| 336 | struct sk_buff_head *list) |
| 337 | { |
| 338 | struct sk_buff *skb = __skb_dequeue(list); |
| 339 | |
| 340 | if (likely(skb != NULL)) |
| 341 | sch->qstats.backlog -= skb->len; |
| 342 | |
| 343 | return skb; |
| 344 | } |
| 345 | |
| 346 | static inline struct sk_buff *qdisc_dequeue_head(struct Qdisc *sch) |
| 347 | { |
| 348 | return __qdisc_dequeue_head(sch, &sch->q); |
| 349 | } |
| 350 | |
| 351 | static inline struct sk_buff *__qdisc_dequeue_tail(struct Qdisc *sch, |
| 352 | struct sk_buff_head *list) |
| 353 | { |
| 354 | struct sk_buff *skb = __skb_dequeue_tail(list); |
| 355 | |
| 356 | if (likely(skb != NULL)) |
| 357 | sch->qstats.backlog -= skb->len; |
| 358 | |
| 359 | return skb; |
| 360 | } |
| 361 | |
| 362 | static inline struct sk_buff *qdisc_dequeue_tail(struct Qdisc *sch) |
| 363 | { |
| 364 | return __qdisc_dequeue_tail(sch, &sch->q); |
| 365 | } |
| 366 | |
| 367 | static inline int __qdisc_requeue(struct sk_buff *skb, struct Qdisc *sch, |
| 368 | struct sk_buff_head *list) |
| 369 | { |
| 370 | __skb_queue_head(list, skb); |
| 371 | sch->qstats.backlog += skb->len; |
| 372 | sch->qstats.requeues++; |
| 373 | |
| 374 | return NET_XMIT_SUCCESS; |
| 375 | } |
| 376 | |
| 377 | static inline int qdisc_requeue(struct sk_buff *skb, struct Qdisc *sch) |
| 378 | { |
| 379 | return __qdisc_requeue(skb, sch, &sch->q); |
| 380 | } |
| 381 | |
| 382 | static inline void __qdisc_reset_queue(struct Qdisc *sch, |
| 383 | struct sk_buff_head *list) |
| 384 | { |
| 385 | /* |
| 386 | * We do not know the backlog in bytes of this list, it |
| 387 | * is up to the caller to correct it |
| 388 | */ |
David S. Miller | 93245dd | 2008-07-17 04:03:43 -0700 | [diff] [blame] | 389 | __skb_queue_purge(list); |
Thomas Graf | 9972b25 | 2005-06-18 22:57:26 -0700 | [diff] [blame] | 390 | } |
| 391 | |
| 392 | static inline void qdisc_reset_queue(struct Qdisc *sch) |
| 393 | { |
| 394 | __qdisc_reset_queue(sch, &sch->q); |
| 395 | sch->qstats.backlog = 0; |
| 396 | } |
| 397 | |
| 398 | static inline unsigned int __qdisc_queue_drop(struct Qdisc *sch, |
| 399 | struct sk_buff_head *list) |
| 400 | { |
| 401 | struct sk_buff *skb = __qdisc_dequeue_tail(sch, list); |
| 402 | |
| 403 | if (likely(skb != NULL)) { |
| 404 | unsigned int len = skb->len; |
| 405 | kfree_skb(skb); |
| 406 | return len; |
| 407 | } |
| 408 | |
| 409 | return 0; |
| 410 | } |
| 411 | |
| 412 | static inline unsigned int qdisc_queue_drop(struct Qdisc *sch) |
| 413 | { |
| 414 | return __qdisc_queue_drop(sch, &sch->q); |
| 415 | } |
| 416 | |
| 417 | static inline int qdisc_drop(struct sk_buff *skb, struct Qdisc *sch) |
| 418 | { |
| 419 | kfree_skb(skb); |
| 420 | sch->qstats.drops++; |
| 421 | |
| 422 | return NET_XMIT_DROP; |
| 423 | } |
| 424 | |
| 425 | static inline int qdisc_reshape_fail(struct sk_buff *skb, struct Qdisc *sch) |
| 426 | { |
| 427 | sch->qstats.drops++; |
| 428 | |
Patrick McHardy | c3bc7cf | 2007-07-15 00:03:05 -0700 | [diff] [blame] | 429 | #ifdef CONFIG_NET_CLS_ACT |
Thomas Graf | 9972b25 | 2005-06-18 22:57:26 -0700 | [diff] [blame] | 430 | if (sch->reshape_fail == NULL || sch->reshape_fail(skb, sch)) |
| 431 | goto drop; |
| 432 | |
| 433 | return NET_XMIT_SUCCESS; |
| 434 | |
| 435 | drop: |
| 436 | #endif |
| 437 | kfree_skb(skb); |
| 438 | return NET_XMIT_DROP; |
| 439 | } |
| 440 | |
Jesper Dangaard Brouer | e9bef55 | 2007-09-12 16:35:24 +0200 | [diff] [blame] | 441 | /* Length to Time (L2T) lookup in a qdisc_rate_table, to determine how |
| 442 | long it will take to send a packet given its size. |
| 443 | */ |
| 444 | static inline u32 qdisc_l2t(struct qdisc_rate_table* rtab, unsigned int pktlen) |
| 445 | { |
Jesper Dangaard Brouer | e08b099 | 2007-09-12 16:36:28 +0200 | [diff] [blame] | 446 | int slot = pktlen + rtab->rate.cell_align + rtab->rate.overhead; |
| 447 | if (slot < 0) |
| 448 | slot = 0; |
Jesper Dangaard Brouer | e9bef55 | 2007-09-12 16:35:24 +0200 | [diff] [blame] | 449 | slot >>= rtab->rate.cell_log; |
| 450 | if (slot > 255) |
| 451 | return (rtab->data[255]*(slot >> 8) + rtab->data[slot & 0xFF]); |
| 452 | return rtab->data[slot]; |
| 453 | } |
| 454 | |
Jamal Hadi Salim | 12da81d | 2007-10-26 02:47:23 -0700 | [diff] [blame] | 455 | #ifdef CONFIG_NET_CLS_ACT |
| 456 | static inline struct sk_buff *skb_act_clone(struct sk_buff *skb, gfp_t gfp_mask) |
| 457 | { |
| 458 | struct sk_buff *n = skb_clone(skb, gfp_mask); |
| 459 | |
| 460 | if (n) { |
| 461 | n->tc_verd = SET_TC_VERD(n->tc_verd, 0); |
| 462 | n->tc_verd = CLR_TC_OK2MUNGE(n->tc_verd); |
| 463 | n->tc_verd = CLR_TC_MUNGED(n->tc_verd); |
Jamal Hadi Salim | 12da81d | 2007-10-26 02:47:23 -0700 | [diff] [blame] | 464 | } |
| 465 | return n; |
| 466 | } |
| 467 | #endif |
| 468 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 469 | #endif |