200-add-tc_esfq.patch 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249
  1. --- a/tc/Makefile
  2. +++ b/tc/Makefile
  3. @@ -13,6 +13,7 @@ SHARED_LIBS ?= y
  4. TCMODULES :=
  5. TCMODULES += q_fifo.o
  6. TCMODULES += q_sfq.o
  7. +TCMODULES += q_esfq.o
  8. TCMODULES += q_red.o
  9. TCMODULES += q_prio.o
  10. TCMODULES += q_tbf.o
  11. --- a/include/linux/pkt_sched.h
  12. +++ b/include/linux/pkt_sched.h
  13. @@ -226,6 +226,33 @@ struct tc_sfq_xstats {
  14. __s32 allot;
  15. };
  16. +/* ESFQ section */
  17. +
  18. +enum
  19. +{
  20. + /* traditional */
  21. + TCA_SFQ_HASH_CLASSIC,
  22. + TCA_SFQ_HASH_DST,
  23. + TCA_SFQ_HASH_SRC,
  24. + TCA_SFQ_HASH_FWMARK,
  25. + /* conntrack */
  26. + TCA_SFQ_HASH_CTORIGDST,
  27. + TCA_SFQ_HASH_CTORIGSRC,
  28. + TCA_SFQ_HASH_CTREPLDST,
  29. + TCA_SFQ_HASH_CTREPLSRC,
  30. + TCA_SFQ_HASH_CTNATCHG,
  31. +};
  32. +
  33. +struct tc_esfq_qopt
  34. +{
  35. + unsigned quantum; /* Bytes per round allocated to flow */
  36. + int perturb_period; /* Period of hash perturbation */
  37. + __u32 limit; /* Maximal packets in queue */
  38. + unsigned divisor; /* Hash divisor */
  39. + unsigned flows; /* Maximal number of flows */
  40. + unsigned hash_kind; /* Hash function to use for flow identification */
  41. +};
  42. +
  43. /* RED section */
  44. enum {
  45. --- /dev/null
  46. +++ b/tc/q_esfq.c
  47. @@ -0,0 +1,200 @@
  48. +/*
  49. + * q_esfq.c ESFQ.
  50. + *
  51. + * This program is free software; you can redistribute it and/or
  52. + * modify it under the terms of the GNU General Public License
  53. + * as published by the Free Software Foundation; either version
  54. + * 2 of the License, or (at your option) any later version.
  55. + *
  56. + * Authors: Alexey Kuznetsov, <kuznet@ms2.inr.ac.ru>
  57. + *
  58. + * Changes: Alexander Atanasov, <alex@ssi.bg>
  59. + * Alexander Clouter, <alex@digriz.org.uk>
  60. + * Corey Hickey, <bugfood-c@fatooh.org>
  61. + *
  62. + */
  63. +
  64. +#include <stdio.h>
  65. +#include <stdlib.h>
  66. +#include <unistd.h>
  67. +#include <syslog.h>
  68. +#include <fcntl.h>
  69. +#include <math.h>
  70. +#include <sys/socket.h>
  71. +#include <netinet/in.h>
  72. +#include <arpa/inet.h>
  73. +#include <string.h>
  74. +
  75. +#include "utils.h"
  76. +#include "tc_util.h"
  77. +
  78. +static void explain(void)
  79. +{
  80. + fprintf(stderr, "Usage: ... esfq [ perturb SECS ] [ quantum BYTES ] [ depth FLOWS ]\n\t[ divisor HASHBITS ] [ limit PKTS ] [ hash HASHTYPE]\n");
  81. + fprintf(stderr,"Where: \n");
  82. + fprintf(stderr,"HASHTYPE := { classic | src | dst | ctorigdst | ctorigsrc | ctrepldst | ctreplsrc | ctnatchg }\n");
  83. +}
  84. +
  85. +#define usage() return(-1)
  86. +
  87. +static int esfq_parse_opt(struct qdisc_util *qu, int argc, char **argv, struct nlmsghdr *n)
  88. +{
  89. + int ok=0;
  90. + struct tc_esfq_qopt opt;
  91. +
  92. + memset(&opt, 0, sizeof(opt));
  93. +
  94. + opt.hash_kind= TCA_SFQ_HASH_CLASSIC;
  95. +
  96. + while (argc > 0) {
  97. + if (strcmp(*argv, "quantum") == 0) {
  98. + NEXT_ARG();
  99. + if (get_size(&opt.quantum, *argv)) {
  100. + fprintf(stderr, "Illegal \"quantum\"\n");
  101. + return -1;
  102. + }
  103. + ok++;
  104. + } else if (strcmp(*argv, "perturb") == 0) {
  105. + NEXT_ARG();
  106. + if (get_integer(&opt.perturb_period, *argv, 0)) {
  107. + fprintf(stderr, "Illegal \"perturb\"\n");
  108. + return -1;
  109. + }
  110. + ok++;
  111. + } else if (strcmp(*argv, "depth") == 0) {
  112. + NEXT_ARG();
  113. + if (get_integer((int *) &opt.flows, *argv, 0)) {
  114. + fprintf(stderr, "Illegal \"depth\"\n");
  115. + return -1;
  116. + }
  117. + ok++;
  118. + } else if (strcmp(*argv, "divisor") == 0) {
  119. + NEXT_ARG();
  120. + if (get_integer((int *) &opt.divisor, *argv, 0)) {
  121. + fprintf(stderr, "Illegal \"divisor\"\n");
  122. + return -1;
  123. + }
  124. + if(opt.divisor >= 14) {
  125. + fprintf(stderr, "Illegal \"divisor\": must be < 14\n");
  126. + return -1;
  127. + }
  128. + opt.divisor=pow(2,opt.divisor);
  129. + ok++;
  130. + } else if (strcmp(*argv, "limit") == 0) {
  131. + NEXT_ARG();
  132. + if (get_integer((int *) &opt.limit, *argv, 0)) {
  133. + fprintf(stderr, "Illegal \"limit\"\n");
  134. + return -1;
  135. + }
  136. + ok++;
  137. + } else if (strcmp(*argv, "hash") == 0) {
  138. + NEXT_ARG();
  139. + if(strcmp(*argv, "classic") == 0) {
  140. + opt.hash_kind= TCA_SFQ_HASH_CLASSIC;
  141. + } else
  142. + if(strcmp(*argv, "dst") == 0) {
  143. + opt.hash_kind= TCA_SFQ_HASH_DST;
  144. + } else
  145. + if(strcmp(*argv, "src") == 0) {
  146. + opt.hash_kind= TCA_SFQ_HASH_SRC;
  147. + } else
  148. + if(strcmp(*argv, "ctorigsrc") == 0) {
  149. + opt.hash_kind= TCA_SFQ_HASH_CTORIGSRC;
  150. + } else
  151. + if(strcmp(*argv, "ctorigdst") == 0) {
  152. + opt.hash_kind= TCA_SFQ_HASH_CTORIGDST;
  153. + } else
  154. + if(strcmp(*argv, "ctreplsrc") == 0) {
  155. + opt.hash_kind= TCA_SFQ_HASH_CTREPLSRC;
  156. + } else
  157. + if(strcmp(*argv, "ctrepldst") == 0) {
  158. + opt.hash_kind= TCA_SFQ_HASH_CTREPLDST;
  159. + } else
  160. + if(strcmp(*argv, "ctnatchg") == 0) {
  161. + opt.hash_kind= TCA_SFQ_HASH_CTNATCHG;
  162. + } else {
  163. + fprintf(stderr, "Illegal \"hash\"\n");
  164. + explain();
  165. + return -1;
  166. + }
  167. + ok++;
  168. + } else if (strcmp(*argv, "help") == 0) {
  169. + explain();
  170. + return -1;
  171. + } else {
  172. + fprintf(stderr, "What is \"%s\"?\n", *argv);
  173. + explain();
  174. + return -1;
  175. + }
  176. + argc--; argv++;
  177. + }
  178. +
  179. + if (ok)
  180. + addattr_l(n, 1024, TCA_OPTIONS, &opt, sizeof(opt));
  181. + return 0;
  182. +}
  183. +
  184. +static int esfq_print_opt(struct qdisc_util *qu, FILE *f, struct rtattr *opt)
  185. +{
  186. + struct tc_esfq_qopt *qopt;
  187. + SPRINT_BUF(b1);
  188. +
  189. + if (opt == NULL)
  190. + return 0;
  191. +
  192. + if (RTA_PAYLOAD(opt) < sizeof(*qopt))
  193. + return -1;
  194. + qopt = RTA_DATA(opt);
  195. + fprintf(f, "quantum %s ", sprint_size(qopt->quantum, b1));
  196. + if (show_details) {
  197. + fprintf(f, "limit %up flows %u/%u ",
  198. + qopt->limit, qopt->flows, qopt->divisor);
  199. + }
  200. + if (qopt->perturb_period)
  201. + fprintf(f, "perturb %dsec ", qopt->perturb_period);
  202. +
  203. + fprintf(f,"hash: ");
  204. + switch(qopt->hash_kind)
  205. + {
  206. + case TCA_SFQ_HASH_CLASSIC:
  207. + fprintf(f,"classic");
  208. + break;
  209. + case TCA_SFQ_HASH_DST:
  210. + fprintf(f,"dst");
  211. + break;
  212. + case TCA_SFQ_HASH_SRC:
  213. + fprintf(f,"src");
  214. + break;
  215. + case TCA_SFQ_HASH_CTORIGSRC:
  216. + fprintf(f,"ctorigsrc");
  217. + break;
  218. + case TCA_SFQ_HASH_CTORIGDST:
  219. + fprintf(f,"ctorigdst");
  220. + break;
  221. + case TCA_SFQ_HASH_CTREPLSRC:
  222. + fprintf(f,"ctreplsrc");
  223. + break;
  224. + case TCA_SFQ_HASH_CTREPLDST:
  225. + fprintf(f,"ctrepldst");
  226. + break;
  227. + case TCA_SFQ_HASH_CTNATCHG:
  228. + fprintf(f,"ctnatchg");
  229. + break;
  230. + default:
  231. + fprintf(f,"Unknown");
  232. + }
  233. + return 0;
  234. +}
  235. +
  236. +static int esfq_print_xstats(struct qdisc_util *qu, FILE *f, struct rtattr *xstats)
  237. +{
  238. + return 0;
  239. +}
  240. +
  241. +
  242. +struct qdisc_util esfq_qdisc_util = {
  243. + .id = "esfq",
  244. + .parse_qopt = esfq_parse_opt,
  245. + .print_qopt = esfq_print_opt,
  246. + .print_xstats = esfq_print_xstats,
  247. +};