sch_generic.h 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310
  1. #ifndef __NET_SCHED_GENERIC_H
  2. #define __NET_SCHED_GENERIC_H
  3. #include <linux/config.h>
  4. #include <linux/netdevice.h>
  5. #include <linux/types.h>
  6. #include <linux/rcupdate.h>
  7. #include <linux/module.h>
  8. #include <linux/rtnetlink.h>
  9. #include <linux/pkt_sched.h>
  10. #include <linux/pkt_cls.h>
  11. #include <net/gen_stats.h>
  12. struct Qdisc_ops;
  13. struct qdisc_walker;
  14. struct tcf_walker;
  15. struct module;
  16. struct qdisc_rate_table
  17. {
  18. struct tc_ratespec rate;
  19. u32 data[256];
  20. struct qdisc_rate_table *next;
  21. int refcnt;
  22. };
  23. struct Qdisc
  24. {
  25. int (*enqueue)(struct sk_buff *skb, struct Qdisc *dev);
  26. struct sk_buff * (*dequeue)(struct Qdisc *dev);
  27. unsigned flags;
  28. #define TCQ_F_BUILTIN 1
  29. #define TCQ_F_THROTTLED 2
  30. #define TCQ_F_INGRESS 4
  31. int padded;
  32. struct Qdisc_ops *ops;
  33. u32 handle;
  34. u32 parent;
  35. atomic_t refcnt;
  36. struct sk_buff_head q;
  37. struct net_device *dev;
  38. struct list_head list;
  39. struct gnet_stats_basic bstats;
  40. struct gnet_stats_queue qstats;
  41. struct gnet_stats_rate_est rate_est;
  42. spinlock_t *stats_lock;
  43. struct rcu_head q_rcu;
  44. int (*reshape_fail)(struct sk_buff *skb,
  45. struct Qdisc *q);
  46. /* This field is deprecated, but it is still used by CBQ
  47. * and it will live until better solution will be invented.
  48. */
  49. struct Qdisc *__parent;
  50. };
  51. struct Qdisc_class_ops
  52. {
  53. /* Child qdisc manipulation */
  54. int (*graft)(struct Qdisc *, unsigned long cl,
  55. struct Qdisc *, struct Qdisc **);
  56. struct Qdisc * (*leaf)(struct Qdisc *, unsigned long cl);
  57. /* Class manipulation routines */
  58. unsigned long (*get)(struct Qdisc *, u32 classid);
  59. void (*put)(struct Qdisc *, unsigned long);
  60. int (*change)(struct Qdisc *, u32, u32,
  61. struct rtattr **, unsigned long *);
  62. int (*delete)(struct Qdisc *, unsigned long);
  63. void (*walk)(struct Qdisc *, struct qdisc_walker * arg);
  64. /* Filter manipulation */
  65. struct tcf_proto ** (*tcf_chain)(struct Qdisc *, unsigned long);
  66. unsigned long (*bind_tcf)(struct Qdisc *, unsigned long,
  67. u32 classid);
  68. void (*unbind_tcf)(struct Qdisc *, unsigned long);
  69. /* rtnetlink specific */
  70. int (*dump)(struct Qdisc *, unsigned long,
  71. struct sk_buff *skb, struct tcmsg*);
  72. int (*dump_stats)(struct Qdisc *, unsigned long,
  73. struct gnet_dump *);
  74. };
  75. struct Qdisc_ops
  76. {
  77. struct Qdisc_ops *next;
  78. struct Qdisc_class_ops *cl_ops;
  79. char id[IFNAMSIZ];
  80. int priv_size;
  81. int (*enqueue)(struct sk_buff *, struct Qdisc *);
  82. struct sk_buff * (*dequeue)(struct Qdisc *);
  83. int (*requeue)(struct sk_buff *, struct Qdisc *);
  84. unsigned int (*drop)(struct Qdisc *);
  85. int (*init)(struct Qdisc *, struct rtattr *arg);
  86. void (*reset)(struct Qdisc *);
  87. void (*destroy)(struct Qdisc *);
  88. int (*change)(struct Qdisc *, struct rtattr *arg);
  89. int (*dump)(struct Qdisc *, struct sk_buff *);
  90. int (*dump_stats)(struct Qdisc *, struct gnet_dump *);
  91. struct module *owner;
  92. };
  93. struct tcf_result
  94. {
  95. unsigned long class;
  96. u32 classid;
  97. };
  98. struct tcf_proto_ops
  99. {
  100. struct tcf_proto_ops *next;
  101. char kind[IFNAMSIZ];
  102. int (*classify)(struct sk_buff*, struct tcf_proto*,
  103. struct tcf_result *);
  104. int (*init)(struct tcf_proto*);
  105. void (*destroy)(struct tcf_proto*);
  106. unsigned long (*get)(struct tcf_proto*, u32 handle);
  107. void (*put)(struct tcf_proto*, unsigned long);
  108. int (*change)(struct tcf_proto*, unsigned long,
  109. u32 handle, struct rtattr **,
  110. unsigned long *);
  111. int (*delete)(struct tcf_proto*, unsigned long);
  112. void (*walk)(struct tcf_proto*, struct tcf_walker *arg);
  113. /* rtnetlink specific */
  114. int (*dump)(struct tcf_proto*, unsigned long,
  115. struct sk_buff *skb, struct tcmsg*);
  116. struct module *owner;
  117. };
  118. struct tcf_proto
  119. {
  120. /* Fast access part */
  121. struct tcf_proto *next;
  122. void *root;
  123. int (*classify)(struct sk_buff*, struct tcf_proto*,
  124. struct tcf_result *);
  125. u32 protocol;
  126. /* All the rest */
  127. u32 prio;
  128. u32 classid;
  129. struct Qdisc *q;
  130. void *data;
  131. struct tcf_proto_ops *ops;
  132. };
  133. extern void qdisc_lock_tree(struct net_device *dev);
  134. extern void qdisc_unlock_tree(struct net_device *dev);
  135. #define sch_tree_lock(q) qdisc_lock_tree((q)->dev)
  136. #define sch_tree_unlock(q) qdisc_unlock_tree((q)->dev)
  137. #define tcf_tree_lock(tp) qdisc_lock_tree((tp)->q->dev)
  138. #define tcf_tree_unlock(tp) qdisc_unlock_tree((tp)->q->dev)
  139. extern struct Qdisc noop_qdisc;
  140. extern struct Qdisc_ops noop_qdisc_ops;
  141. extern void dev_init_scheduler(struct net_device *dev);
  142. extern void dev_shutdown(struct net_device *dev);
  143. extern void dev_activate(struct net_device *dev);
  144. extern void dev_deactivate(struct net_device *dev);
  145. extern void qdisc_reset(struct Qdisc *qdisc);
  146. extern void qdisc_destroy(struct Qdisc *qdisc);
  147. extern struct Qdisc *qdisc_alloc(struct net_device *dev, struct Qdisc_ops *ops);
  148. extern struct Qdisc *qdisc_create_dflt(struct net_device *dev,
  149. struct Qdisc_ops *ops);
  150. static inline void
  151. tcf_destroy(struct tcf_proto *tp)
  152. {
  153. tp->ops->destroy(tp);
  154. module_put(tp->ops->owner);
  155. kfree(tp);
  156. }
  157. static inline int __qdisc_enqueue_tail(struct sk_buff *skb, struct Qdisc *sch,
  158. struct sk_buff_head *list)
  159. {
  160. __skb_queue_tail(list, skb);
  161. sch->qstats.backlog += skb->len;
  162. sch->bstats.bytes += skb->len;
  163. sch->bstats.packets++;
  164. return NET_XMIT_SUCCESS;
  165. }
  166. static inline int qdisc_enqueue_tail(struct sk_buff *skb, struct Qdisc *sch)
  167. {
  168. return __qdisc_enqueue_tail(skb, sch, &sch->q);
  169. }
  170. static inline struct sk_buff *__qdisc_dequeue_head(struct Qdisc *sch,
  171. struct sk_buff_head *list)
  172. {
  173. struct sk_buff *skb = __skb_dequeue(list);
  174. if (likely(skb != NULL))
  175. sch->qstats.backlog -= skb->len;
  176. return skb;
  177. }
  178. static inline struct sk_buff *qdisc_dequeue_head(struct Qdisc *sch)
  179. {
  180. return __qdisc_dequeue_head(sch, &sch->q);
  181. }
  182. static inline struct sk_buff *__qdisc_dequeue_tail(struct Qdisc *sch,
  183. struct sk_buff_head *list)
  184. {
  185. struct sk_buff *skb = __skb_dequeue_tail(list);
  186. if (likely(skb != NULL))
  187. sch->qstats.backlog -= skb->len;
  188. return skb;
  189. }
  190. static inline struct sk_buff *qdisc_dequeue_tail(struct Qdisc *sch)
  191. {
  192. return __qdisc_dequeue_tail(sch, &sch->q);
  193. }
  194. static inline int __qdisc_requeue(struct sk_buff *skb, struct Qdisc *sch,
  195. struct sk_buff_head *list)
  196. {
  197. __skb_queue_head(list, skb);
  198. sch->qstats.backlog += skb->len;
  199. sch->qstats.requeues++;
  200. return NET_XMIT_SUCCESS;
  201. }
  202. static inline int qdisc_requeue(struct sk_buff *skb, struct Qdisc *sch)
  203. {
  204. return __qdisc_requeue(skb, sch, &sch->q);
  205. }
  206. static inline void __qdisc_reset_queue(struct Qdisc *sch,
  207. struct sk_buff_head *list)
  208. {
  209. /*
  210. * We do not know the backlog in bytes of this list, it
  211. * is up to the caller to correct it
  212. */
  213. skb_queue_purge(list);
  214. }
  215. static inline void qdisc_reset_queue(struct Qdisc *sch)
  216. {
  217. __qdisc_reset_queue(sch, &sch->q);
  218. sch->qstats.backlog = 0;
  219. }
  220. static inline unsigned int __qdisc_queue_drop(struct Qdisc *sch,
  221. struct sk_buff_head *list)
  222. {
  223. struct sk_buff *skb = __qdisc_dequeue_tail(sch, list);
  224. if (likely(skb != NULL)) {
  225. unsigned int len = skb->len;
  226. kfree_skb(skb);
  227. return len;
  228. }
  229. return 0;
  230. }
  231. static inline unsigned int qdisc_queue_drop(struct Qdisc *sch)
  232. {
  233. return __qdisc_queue_drop(sch, &sch->q);
  234. }
  235. static inline int qdisc_drop(struct sk_buff *skb, struct Qdisc *sch)
  236. {
  237. kfree_skb(skb);
  238. sch->qstats.drops++;
  239. return NET_XMIT_DROP;
  240. }
  241. static inline int qdisc_reshape_fail(struct sk_buff *skb, struct Qdisc *sch)
  242. {
  243. sch->qstats.drops++;
  244. #ifdef CONFIG_NET_CLS_POLICE
  245. if (sch->reshape_fail == NULL || sch->reshape_fail(skb, sch))
  246. goto drop;
  247. return NET_XMIT_SUCCESS;
  248. drop:
  249. #endif
  250. kfree_skb(skb);
  251. return NET_XMIT_DROP;
  252. }
  253. #endif