sch_generic.h 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675
  1. #ifndef __NET_SCHED_GENERIC_H
  2. #define __NET_SCHED_GENERIC_H
  3. #include <linux/netdevice.h>
  4. #include <linux/types.h>
  5. #include <linux/rcupdate.h>
  6. #include <linux/pkt_sched.h>
  7. #include <linux/pkt_cls.h>
  8. #include <net/gen_stats.h>
  9. #include <net/rtnetlink.h>
  10. struct Qdisc_ops;
  11. struct qdisc_walker;
  12. struct tcf_walker;
  13. struct module;
  14. struct qdisc_rate_table {
  15. struct tc_ratespec rate;
  16. u32 data[256];
  17. struct qdisc_rate_table *next;
  18. int refcnt;
  19. };
  20. enum qdisc_state_t {
  21. __QDISC_STATE_SCHED,
  22. __QDISC_STATE_DEACTIVATED,
  23. __QDISC_STATE_THROTTLED,
  24. };
  25. /*
  26. * following bits are only changed while qdisc lock is held
  27. */
  28. enum qdisc___state_t {
  29. __QDISC___STATE_RUNNING = 1,
  30. };
  31. struct qdisc_size_table {
  32. struct rcu_head rcu;
  33. struct list_head list;
  34. struct tc_sizespec szopts;
  35. int refcnt;
  36. u16 data[];
  37. };
  38. struct Qdisc {
  39. int (*enqueue)(struct sk_buff *skb, struct Qdisc *dev);
  40. struct sk_buff * (*dequeue)(struct Qdisc *dev);
  41. unsigned int flags;
  42. #define TCQ_F_BUILTIN 1
  43. #define TCQ_F_INGRESS 2
  44. #define TCQ_F_CAN_BYPASS 4
  45. #define TCQ_F_MQROOT 8
  46. #define TCQ_F_WARN_NONWC (1 << 16)
  47. int padded;
  48. const struct Qdisc_ops *ops;
  49. struct qdisc_size_table __rcu *stab;
  50. struct list_head list;
  51. u32 handle;
  52. u32 parent;
  53. atomic_t refcnt;
  54. struct gnet_stats_rate_est rate_est;
  55. int (*reshape_fail)(struct sk_buff *skb,
  56. struct Qdisc *q);
  57. void *u32_node;
  58. /* This field is deprecated, but it is still used by CBQ
  59. * and it will live until better solution will be invented.
  60. */
  61. struct Qdisc *__parent;
  62. struct netdev_queue *dev_queue;
  63. struct Qdisc *next_sched;
  64. struct sk_buff *gso_skb;
  65. /*
  66. * For performance sake on SMP, we put highly modified fields at the end
  67. */
  68. unsigned long state;
  69. struct sk_buff_head q;
  70. struct gnet_stats_basic_packed bstats;
  71. unsigned int __state;
  72. struct gnet_stats_queue qstats;
  73. struct rcu_head rcu_head;
  74. spinlock_t busylock;
  75. u32 limit;
  76. };
  77. static inline bool qdisc_is_running(const struct Qdisc *qdisc)
  78. {
  79. return (qdisc->__state & __QDISC___STATE_RUNNING) ? true : false;
  80. }
  81. static inline bool qdisc_run_begin(struct Qdisc *qdisc)
  82. {
  83. if (qdisc_is_running(qdisc))
  84. return false;
  85. qdisc->__state |= __QDISC___STATE_RUNNING;
  86. return true;
  87. }
  88. static inline void qdisc_run_end(struct Qdisc *qdisc)
  89. {
  90. qdisc->__state &= ~__QDISC___STATE_RUNNING;
  91. }
  92. static inline bool qdisc_is_throttled(const struct Qdisc *qdisc)
  93. {
  94. return test_bit(__QDISC_STATE_THROTTLED, &qdisc->state) ? true : false;
  95. }
  96. static inline void qdisc_throttled(struct Qdisc *qdisc)
  97. {
  98. set_bit(__QDISC_STATE_THROTTLED, &qdisc->state);
  99. }
  100. static inline void qdisc_unthrottled(struct Qdisc *qdisc)
  101. {
  102. clear_bit(__QDISC_STATE_THROTTLED, &qdisc->state);
  103. }
  104. struct Qdisc_class_ops {
  105. /* Child qdisc manipulation */
  106. struct netdev_queue * (*select_queue)(struct Qdisc *, struct tcmsg *);
  107. int (*graft)(struct Qdisc *, unsigned long cl,
  108. struct Qdisc *, struct Qdisc **);
  109. struct Qdisc * (*leaf)(struct Qdisc *, unsigned long cl);
  110. void (*qlen_notify)(struct Qdisc *, unsigned long);
  111. /* Class manipulation routines */
  112. unsigned long (*get)(struct Qdisc *, u32 classid);
  113. void (*put)(struct Qdisc *, unsigned long);
  114. int (*change)(struct Qdisc *, u32, u32,
  115. struct nlattr **, unsigned long *);
  116. int (*delete)(struct Qdisc *, unsigned long);
  117. void (*walk)(struct Qdisc *, struct qdisc_walker * arg);
  118. /* Filter manipulation */
  119. struct tcf_proto ** (*tcf_chain)(struct Qdisc *, unsigned long);
  120. unsigned long (*bind_tcf)(struct Qdisc *, unsigned long,
  121. u32 classid);
  122. void (*unbind_tcf)(struct Qdisc *, unsigned long);
  123. /* rtnetlink specific */
  124. int (*dump)(struct Qdisc *, unsigned long,
  125. struct sk_buff *skb, struct tcmsg*);
  126. int (*dump_stats)(struct Qdisc *, unsigned long,
  127. struct gnet_dump *);
  128. };
  129. struct Qdisc_ops {
  130. struct Qdisc_ops *next;
  131. const struct Qdisc_class_ops *cl_ops;
  132. char id[IFNAMSIZ];
  133. int priv_size;
  134. int (*enqueue)(struct sk_buff *, struct Qdisc *);
  135. struct sk_buff * (*dequeue)(struct Qdisc *);
  136. struct sk_buff * (*peek)(struct Qdisc *);
  137. unsigned int (*drop)(struct Qdisc *);
  138. int (*init)(struct Qdisc *, struct nlattr *arg);
  139. void (*reset)(struct Qdisc *);
  140. void (*destroy)(struct Qdisc *);
  141. int (*change)(struct Qdisc *, struct nlattr *arg);
  142. void (*attach)(struct Qdisc *);
  143. int (*dump)(struct Qdisc *, struct sk_buff *);
  144. int (*dump_stats)(struct Qdisc *, struct gnet_dump *);
  145. struct module *owner;
  146. };
  147. struct tcf_result {
  148. unsigned long class;
  149. u32 classid;
  150. };
  151. struct tcf_proto_ops {
  152. struct tcf_proto_ops *next;
  153. char kind[IFNAMSIZ];
  154. int (*classify)(struct sk_buff *,
  155. const struct tcf_proto *,
  156. struct tcf_result *);
  157. int (*init)(struct tcf_proto*);
  158. void (*destroy)(struct tcf_proto*);
  159. unsigned long (*get)(struct tcf_proto*, u32 handle);
  160. void (*put)(struct tcf_proto*, unsigned long);
  161. int (*change)(struct sk_buff *,
  162. struct tcf_proto*, unsigned long,
  163. u32 handle, struct nlattr **,
  164. unsigned long *);
  165. int (*delete)(struct tcf_proto*, unsigned long);
  166. void (*walk)(struct tcf_proto*, struct tcf_walker *arg);
  167. /* rtnetlink specific */
  168. int (*dump)(struct tcf_proto*, unsigned long,
  169. struct sk_buff *skb, struct tcmsg*);
  170. struct module *owner;
  171. };
  172. struct tcf_proto {
  173. /* Fast access part */
  174. struct tcf_proto *next;
  175. void *root;
  176. int (*classify)(struct sk_buff *,
  177. const struct tcf_proto *,
  178. struct tcf_result *);
  179. __be16 protocol;
  180. /* All the rest */
  181. u32 prio;
  182. u32 classid;
  183. struct Qdisc *q;
  184. void *data;
  185. const struct tcf_proto_ops *ops;
  186. };
  187. struct qdisc_skb_cb {
  188. unsigned int pkt_len;
  189. u16 slave_dev_queue_mapping;
  190. u16 _pad;
  191. unsigned char data[20];
  192. };
  193. static inline void qdisc_cb_private_validate(const struct sk_buff *skb, int sz)
  194. {
  195. struct qdisc_skb_cb *qcb;
  196. BUILD_BUG_ON(sizeof(skb->cb) < offsetof(struct qdisc_skb_cb, data) + sz);
  197. BUILD_BUG_ON(sizeof(qcb->data) < sz);
  198. }
  199. static inline int qdisc_qlen(const struct Qdisc *q)
  200. {
  201. return q->q.qlen;
  202. }
  203. static inline struct qdisc_skb_cb *qdisc_skb_cb(const struct sk_buff *skb)
  204. {
  205. return (struct qdisc_skb_cb *)skb->cb;
  206. }
  207. static inline spinlock_t *qdisc_lock(struct Qdisc *qdisc)
  208. {
  209. return &qdisc->q.lock;
  210. }
  211. static inline struct Qdisc *qdisc_root(const struct Qdisc *qdisc)
  212. {
  213. return qdisc->dev_queue->qdisc;
  214. }
  215. static inline struct Qdisc *qdisc_root_sleeping(const struct Qdisc *qdisc)
  216. {
  217. return qdisc->dev_queue->qdisc_sleeping;
  218. }
  219. /* The qdisc root lock is a mechanism by which to top level
  220. * of a qdisc tree can be locked from any qdisc node in the
  221. * forest. This allows changing the configuration of some
  222. * aspect of the qdisc tree while blocking out asynchronous
  223. * qdisc access in the packet processing paths.
  224. *
  225. * It is only legal to do this when the root will not change
  226. * on us. Otherwise we'll potentially lock the wrong qdisc
  227. * root. This is enforced by holding the RTNL semaphore, which
  228. * all users of this lock accessor must do.
  229. */
  230. static inline spinlock_t *qdisc_root_lock(const struct Qdisc *qdisc)
  231. {
  232. struct Qdisc *root = qdisc_root(qdisc);
  233. ASSERT_RTNL();
  234. return qdisc_lock(root);
  235. }
  236. static inline spinlock_t *qdisc_root_sleeping_lock(const struct Qdisc *qdisc)
  237. {
  238. struct Qdisc *root = qdisc_root_sleeping(qdisc);
  239. ASSERT_RTNL();
  240. return qdisc_lock(root);
  241. }
  242. static inline struct net_device *qdisc_dev(const struct Qdisc *qdisc)
  243. {
  244. return qdisc->dev_queue->dev;
  245. }
  246. static inline void sch_tree_lock(const struct Qdisc *q)
  247. {
  248. spin_lock_bh(qdisc_root_sleeping_lock(q));
  249. }
  250. static inline void sch_tree_unlock(const struct Qdisc *q)
  251. {
  252. spin_unlock_bh(qdisc_root_sleeping_lock(q));
  253. }
  254. #define tcf_tree_lock(tp) sch_tree_lock((tp)->q)
  255. #define tcf_tree_unlock(tp) sch_tree_unlock((tp)->q)
  256. extern struct Qdisc noop_qdisc;
  257. extern struct Qdisc_ops noop_qdisc_ops;
  258. extern struct Qdisc_ops pfifo_fast_ops;
  259. extern struct Qdisc_ops mq_qdisc_ops;
  260. struct Qdisc_class_common {
  261. u32 classid;
  262. struct hlist_node hnode;
  263. };
  264. struct Qdisc_class_hash {
  265. struct hlist_head *hash;
  266. unsigned int hashsize;
  267. unsigned int hashmask;
  268. unsigned int hashelems;
  269. };
  270. static inline unsigned int qdisc_class_hash(u32 id, u32 mask)
  271. {
  272. id ^= id >> 8;
  273. id ^= id >> 4;
  274. return id & mask;
  275. }
  276. static inline struct Qdisc_class_common *
  277. qdisc_class_find(const struct Qdisc_class_hash *hash, u32 id)
  278. {
  279. struct Qdisc_class_common *cl;
  280. struct hlist_node *n;
  281. unsigned int h;
  282. h = qdisc_class_hash(id, hash->hashmask);
  283. hlist_for_each_entry(cl, n, &hash->hash[h], hnode) {
  284. if (cl->classid == id)
  285. return cl;
  286. }
  287. return NULL;
  288. }
  289. extern int qdisc_class_hash_init(struct Qdisc_class_hash *);
  290. extern void qdisc_class_hash_insert(struct Qdisc_class_hash *, struct Qdisc_class_common *);
  291. extern void qdisc_class_hash_remove(struct Qdisc_class_hash *, struct Qdisc_class_common *);
  292. extern void qdisc_class_hash_grow(struct Qdisc *, struct Qdisc_class_hash *);
  293. extern void qdisc_class_hash_destroy(struct Qdisc_class_hash *);
  294. extern void dev_init_scheduler(struct net_device *dev);
  295. extern void dev_shutdown(struct net_device *dev);
  296. extern void dev_activate(struct net_device *dev);
  297. extern void dev_deactivate(struct net_device *dev);
  298. extern void dev_deactivate_many(struct list_head *head);
  299. extern struct Qdisc *dev_graft_qdisc(struct netdev_queue *dev_queue,
  300. struct Qdisc *qdisc);
  301. extern void qdisc_reset(struct Qdisc *qdisc);
  302. extern void qdisc_destroy(struct Qdisc *qdisc);
  303. extern void qdisc_tree_decrease_qlen(struct Qdisc *qdisc, unsigned int n);
  304. extern struct Qdisc *qdisc_alloc(struct netdev_queue *dev_queue,
  305. struct Qdisc_ops *ops);
  306. extern struct Qdisc *qdisc_create_dflt(struct netdev_queue *dev_queue,
  307. struct Qdisc_ops *ops, u32 parentid);
  308. extern void __qdisc_calculate_pkt_len(struct sk_buff *skb,
  309. const struct qdisc_size_table *stab);
  310. extern void tcf_destroy(struct tcf_proto *tp);
  311. extern void tcf_destroy_chain(struct tcf_proto **fl);
  312. /* Reset all TX qdiscs greater then index of a device. */
  313. static inline void qdisc_reset_all_tx_gt(struct net_device *dev, unsigned int i)
  314. {
  315. struct Qdisc *qdisc;
  316. for (; i < dev->num_tx_queues; i++) {
  317. qdisc = netdev_get_tx_queue(dev, i)->qdisc;
  318. if (qdisc) {
  319. spin_lock_bh(qdisc_lock(qdisc));
  320. qdisc_reset(qdisc);
  321. spin_unlock_bh(qdisc_lock(qdisc));
  322. }
  323. }
  324. }
  325. static inline void qdisc_reset_all_tx(struct net_device *dev)
  326. {
  327. qdisc_reset_all_tx_gt(dev, 0);
  328. }
  329. /* Are all TX queues of the device empty? */
  330. static inline bool qdisc_all_tx_empty(const struct net_device *dev)
  331. {
  332. unsigned int i;
  333. for (i = 0; i < dev->num_tx_queues; i++) {
  334. struct netdev_queue *txq = netdev_get_tx_queue(dev, i);
  335. const struct Qdisc *q = txq->qdisc;
  336. if (q->q.qlen)
  337. return false;
  338. }
  339. return true;
  340. }
  341. /* Are any of the TX qdiscs changing? */
  342. static inline bool qdisc_tx_changing(const struct net_device *dev)
  343. {
  344. unsigned int i;
  345. for (i = 0; i < dev->num_tx_queues; i++) {
  346. struct netdev_queue *txq = netdev_get_tx_queue(dev, i);
  347. if (txq->qdisc != txq->qdisc_sleeping)
  348. return true;
  349. }
  350. return false;
  351. }
  352. /* Is the device using the noop qdisc on all queues? */
  353. static inline bool qdisc_tx_is_noop(const struct net_device *dev)
  354. {
  355. unsigned int i;
  356. for (i = 0; i < dev->num_tx_queues; i++) {
  357. struct netdev_queue *txq = netdev_get_tx_queue(dev, i);
  358. if (txq->qdisc != &noop_qdisc)
  359. return false;
  360. }
  361. return true;
  362. }
  363. static inline unsigned int qdisc_pkt_len(const struct sk_buff *skb)
  364. {
  365. return qdisc_skb_cb(skb)->pkt_len;
  366. }
  367. /* additional qdisc xmit flags (NET_XMIT_MASK in linux/netdevice.h) */
  368. enum net_xmit_qdisc_t {
  369. __NET_XMIT_STOLEN = 0x00010000,
  370. __NET_XMIT_BYPASS = 0x00020000,
  371. };
  372. #ifdef CONFIG_NET_CLS_ACT
  373. #define net_xmit_drop_count(e) ((e) & __NET_XMIT_STOLEN ? 0 : 1)
  374. #else
  375. #define net_xmit_drop_count(e) (1)
  376. #endif
  377. static inline void qdisc_calculate_pkt_len(struct sk_buff *skb,
  378. const struct Qdisc *sch)
  379. {
  380. #ifdef CONFIG_NET_SCHED
  381. struct qdisc_size_table *stab = rcu_dereference_bh(sch->stab);
  382. if (stab)
  383. __qdisc_calculate_pkt_len(skb, stab);
  384. #endif
  385. }
  386. static inline int qdisc_enqueue(struct sk_buff *skb, struct Qdisc *sch)
  387. {
  388. qdisc_calculate_pkt_len(skb, sch);
  389. return sch->enqueue(skb, sch);
  390. }
  391. static inline int qdisc_enqueue_root(struct sk_buff *skb, struct Qdisc *sch)
  392. {
  393. qdisc_skb_cb(skb)->pkt_len = skb->len;
  394. return qdisc_enqueue(skb, sch) & NET_XMIT_MASK;
  395. }
  396. static inline void bstats_update(struct gnet_stats_basic_packed *bstats,
  397. const struct sk_buff *skb)
  398. {
  399. bstats->bytes += qdisc_pkt_len(skb);
  400. bstats->packets += skb_is_gso(skb) ? skb_shinfo(skb)->gso_segs : 1;
  401. }
  402. static inline void qdisc_bstats_update(struct Qdisc *sch,
  403. const struct sk_buff *skb)
  404. {
  405. bstats_update(&sch->bstats, skb);
  406. }
  407. static inline int __qdisc_enqueue_tail(struct sk_buff *skb, struct Qdisc *sch,
  408. struct sk_buff_head *list)
  409. {
  410. __skb_queue_tail(list, skb);
  411. sch->qstats.backlog += qdisc_pkt_len(skb);
  412. return NET_XMIT_SUCCESS;
  413. }
  414. static inline int qdisc_enqueue_tail(struct sk_buff *skb, struct Qdisc *sch)
  415. {
  416. return __qdisc_enqueue_tail(skb, sch, &sch->q);
  417. }
  418. static inline struct sk_buff *__qdisc_dequeue_head(struct Qdisc *sch,
  419. struct sk_buff_head *list)
  420. {
  421. struct sk_buff *skb = __skb_dequeue(list);
  422. if (likely(skb != NULL)) {
  423. sch->qstats.backlog -= qdisc_pkt_len(skb);
  424. qdisc_bstats_update(sch, skb);
  425. }
  426. return skb;
  427. }
  428. static inline struct sk_buff *qdisc_dequeue_head(struct Qdisc *sch)
  429. {
  430. return __qdisc_dequeue_head(sch, &sch->q);
  431. }
  432. static inline unsigned int __qdisc_queue_drop_head(struct Qdisc *sch,
  433. struct sk_buff_head *list)
  434. {
  435. struct sk_buff *skb = __skb_dequeue(list);
  436. if (likely(skb != NULL)) {
  437. unsigned int len = qdisc_pkt_len(skb);
  438. sch->qstats.backlog -= len;
  439. kfree_skb(skb);
  440. return len;
  441. }
  442. return 0;
  443. }
  444. static inline unsigned int qdisc_queue_drop_head(struct Qdisc *sch)
  445. {
  446. return __qdisc_queue_drop_head(sch, &sch->q);
  447. }
  448. static inline struct sk_buff *__qdisc_dequeue_tail(struct Qdisc *sch,
  449. struct sk_buff_head *list)
  450. {
  451. struct sk_buff *skb = __skb_dequeue_tail(list);
  452. if (likely(skb != NULL))
  453. sch->qstats.backlog -= qdisc_pkt_len(skb);
  454. return skb;
  455. }
  456. static inline struct sk_buff *qdisc_dequeue_tail(struct Qdisc *sch)
  457. {
  458. return __qdisc_dequeue_tail(sch, &sch->q);
  459. }
  460. static inline struct sk_buff *qdisc_peek_head(struct Qdisc *sch)
  461. {
  462. return skb_peek(&sch->q);
  463. }
  464. /* generic pseudo peek method for non-work-conserving qdisc */
  465. static inline struct sk_buff *qdisc_peek_dequeued(struct Qdisc *sch)
  466. {
  467. /* we can reuse ->gso_skb because peek isn't called for root qdiscs */
  468. if (!sch->gso_skb) {
  469. sch->gso_skb = sch->dequeue(sch);
  470. if (sch->gso_skb)
  471. /* it's still part of the queue */
  472. sch->q.qlen++;
  473. }
  474. return sch->gso_skb;
  475. }
  476. /* use instead of qdisc->dequeue() for all qdiscs queried with ->peek() */
  477. static inline struct sk_buff *qdisc_dequeue_peeked(struct Qdisc *sch)
  478. {
  479. struct sk_buff *skb = sch->gso_skb;
  480. if (skb) {
  481. sch->gso_skb = NULL;
  482. sch->q.qlen--;
  483. } else {
  484. skb = sch->dequeue(sch);
  485. }
  486. return skb;
  487. }
  488. static inline void __qdisc_reset_queue(struct Qdisc *sch,
  489. struct sk_buff_head *list)
  490. {
  491. /*
  492. * We do not know the backlog in bytes of this list, it
  493. * is up to the caller to correct it
  494. */
  495. __skb_queue_purge(list);
  496. }
  497. static inline void qdisc_reset_queue(struct Qdisc *sch)
  498. {
  499. __qdisc_reset_queue(sch, &sch->q);
  500. sch->qstats.backlog = 0;
  501. }
  502. static inline unsigned int __qdisc_queue_drop(struct Qdisc *sch,
  503. struct sk_buff_head *list)
  504. {
  505. struct sk_buff *skb = __qdisc_dequeue_tail(sch, list);
  506. if (likely(skb != NULL)) {
  507. unsigned int len = qdisc_pkt_len(skb);
  508. kfree_skb(skb);
  509. return len;
  510. }
  511. return 0;
  512. }
  513. static inline unsigned int qdisc_queue_drop(struct Qdisc *sch)
  514. {
  515. return __qdisc_queue_drop(sch, &sch->q);
  516. }
  517. static inline int qdisc_drop(struct sk_buff *skb, struct Qdisc *sch)
  518. {
  519. kfree_skb(skb);
  520. sch->qstats.drops++;
  521. return NET_XMIT_DROP;
  522. }
  523. static inline int qdisc_reshape_fail(struct sk_buff *skb, struct Qdisc *sch)
  524. {
  525. sch->qstats.drops++;
  526. #ifdef CONFIG_NET_CLS_ACT
  527. if (sch->reshape_fail == NULL || sch->reshape_fail(skb, sch))
  528. goto drop;
  529. return NET_XMIT_SUCCESS;
  530. drop:
  531. #endif
  532. kfree_skb(skb);
  533. return NET_XMIT_DROP;
  534. }
  535. /* Length to Time (L2T) lookup in a qdisc_rate_table, to determine how
  536. long it will take to send a packet given its size.
  537. */
  538. static inline u32 qdisc_l2t(struct qdisc_rate_table* rtab, unsigned int pktlen)
  539. {
  540. int slot = pktlen + rtab->rate.cell_align + rtab->rate.overhead;
  541. if (slot < 0)
  542. slot = 0;
  543. slot >>= rtab->rate.cell_log;
  544. if (slot > 255)
  545. return rtab->data[255]*(slot >> 8) + rtab->data[slot & 0xFF];
  546. return rtab->data[slot];
  547. }
  548. #ifdef CONFIG_NET_CLS_ACT
  549. static inline struct sk_buff *skb_act_clone(struct sk_buff *skb, gfp_t gfp_mask,
  550. int action)
  551. {
  552. struct sk_buff *n;
  553. n = skb_clone(skb, gfp_mask);
  554. if (n) {
  555. n->tc_verd = SET_TC_VERD(n->tc_verd, 0);
  556. n->tc_verd = CLR_TC_OK2MUNGE(n->tc_verd);
  557. n->tc_verd = CLR_TC_MUNGED(n->tc_verd);
  558. }
  559. return n;
  560. }
  561. #endif
  562. #endif