sch_generic.h 7.3 KB

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