010-cake-fwmark.patch 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. From 9572f793e6945dd90a3cd4db34814b9b1616cfe9 Mon Sep 17 00:00:00 2001
  2. From: =?UTF-8?q?Toke=20H=C3=B8iland-J=C3=B8rgensen?= <[email protected]>
  3. Date: Mon, 18 Mar 2019 01:30:19 +0100
  4. Subject: [PATCH] pkt_sched.h: Add support for CAKE FWMARK
  5. MIME-Version: 1.0
  6. Content-Type: text/plain; charset=UTF-8
  7. Content-Transfer-Encoding: 8bit
  8. Signed-off-by: Toke Høiland-Jørgensen <[email protected]>
  9. ---
  10. include/uapi/linux/pkt_sched.h | 1 +
  11. 1 file changed, 1 insertion(+)
  12. diff --git a/include/uapi/linux/pkt_sched.h b/include/uapi/linux/pkt_sched.h
  13. index 01f96352..ef78de0c 100644
  14. --- a/include/uapi/linux/pkt_sched.h
  15. +++ b/include/uapi/linux/pkt_sched.h
  16. @@ -954,6 +954,7 @@ enum {
  17. TCA_CAKE_INGRESS,
  18. TCA_CAKE_ACK_FILTER,
  19. TCA_CAKE_SPLIT_GSO,
  20. + TCA_CAKE_FWMARK,
  21. __TCA_CAKE_MAX
  22. };
  23. #define TCA_CAKE_MAX (__TCA_CAKE_MAX - 1)
  24. From 5ebfe1f6fea2bb3bfccf4cf93829516caaa0233d Mon Sep 17 00:00:00 2001
  25. From: =?UTF-8?q?Toke=20H=C3=B8iland-J=C3=B8rgensen?= <[email protected]>
  26. Date: Mon, 18 Mar 2019 01:30:45 +0100
  27. Subject: [PATCH] q_cake: Add support for setting the fwmark option
  28. MIME-Version: 1.0
  29. Content-Type: text/plain; charset=UTF-8
  30. Content-Transfer-Encoding: 8bit
  31. This adds support for the newly added fwmark option to CAKE, which allows
  32. overriding the tin selection from the per-packet firewall marks. The fwmark
  33. field is a bitmask that is applied to the fwmark to select the tin.
  34. Signed-off-by: Toke Høiland-Jørgensen <[email protected]>
  35. ---
  36. man/man8/tc-cake.8 | 16 ++++++++++++++++
  37. tc/q_cake.c | 24 ++++++++++++++++++++++++
  38. 2 files changed, 40 insertions(+)
  39. diff --git a/man/man8/tc-cake.8 b/man/man8/tc-cake.8
  40. index eda436e1..8c57eadd 100644
  41. --- a/man/man8/tc-cake.8
  42. +++ b/man/man8/tc-cake.8
  43. @@ -91,6 +91,10 @@ TIME |
  44. LIMIT ]
  45. .br
  46. [
  47. +.BR fwmark
  48. +MASK ]
  49. +.br
  50. +[
  51. .BR ptm
  52. |
  53. .BR atm
  54. @@ -524,6 +528,18 @@ preset on the modern Internet is firmly discouraged.
  55. .br
  56. Voice (CS7, CS6, EF, VA, TOS4), 25% threshold, reduced Codel interval.
  57. +.PP
  58. +.B fwmark
  59. +MASK
  60. +.br
  61. + This options turns on fwmark-based overriding of CAKE's tin selection.
  62. +If set, the option specifies a bitmask that will be applied to the fwmark
  63. +associated with each packet. If the result of this masking is non-zero, the
  64. +result will be right-shifted by the number of least-significant unset bits in
  65. +the mask value, and the result will be used as a the tin number for that packet.
  66. +This can be used to set policies in a firewall script that will override CAKE's
  67. +built-in tin selection.
  68. +
  69. .SH OTHER PARAMETERS
  70. .B memlimit
  71. LIMIT
  72. diff --git a/tc/q_cake.c b/tc/q_cake.c
  73. index e827e3f1..307a12c0 100644
  74. --- a/tc/q_cake.c
  75. +++ b/tc/q_cake.c
  76. @@ -82,6 +82,7 @@ static void explain(void)
  77. " [ split-gso* | no-split-gso ]\n"
  78. " [ ack-filter | ack-filter-aggressive | no-ack-filter* ]\n"
  79. " [ memlimit LIMIT ]\n"
  80. +" [ fwmark MASK ]\n"
  81. " [ ptm | atm | noatm* ] [ overhead N | conservative | raw* ]\n"
  82. " [ mpu N ] [ ingress | egress* ]\n"
  83. " (* marks defaults)\n");
  84. @@ -106,6 +107,7 @@ static int cake_parse_opt(struct qdisc_util *qu, int argc, char **argv,
  85. int autorate = -1;
  86. int ingress = -1;
  87. int overhead = 0;
  88. + int fwmark = -1;
  89. int wash = -1;
  90. int nat = -1;
  91. int atm = -1;
  92. @@ -332,6 +334,16 @@ static int cake_parse_opt(struct qdisc_util *qu, int argc, char **argv,
  93. "Illegal value for \"memlimit\": \"%s\"\n", *argv);
  94. return -1;
  95. }
  96. + } else if (strcmp(*argv, "fwmark") == 0) {
  97. + unsigned int fwm;
  98. +
  99. + NEXT_ARG();
  100. + if (get_u32(&fwm, *argv, 0)) {
  101. + fprintf(stderr,
  102. + "Illegal value for \"fwmark\": \"%s\"\n", *argv);
  103. + return -1;
  104. + }
  105. + fwmark = fwm;
  106. } else if (strcmp(*argv, "help") == 0) {
  107. explain();
  108. return -1;
  109. @@ -376,6 +388,9 @@ static int cake_parse_opt(struct qdisc_util *qu, int argc, char **argv,
  110. if (memlimit)
  111. addattr_l(n, 1024, TCA_CAKE_MEMORY, &memlimit,
  112. sizeof(memlimit));
  113. + if (fwmark != -1)
  114. + addattr_l(n, 1024, TCA_CAKE_FWMARK, &fwmark,
  115. + sizeof(fwmark));
  116. if (nat != -1)
  117. addattr_l(n, 1024, TCA_CAKE_NAT, &nat, sizeof(nat));
  118. if (wash != -1)
  119. @@ -409,6 +424,7 @@ static int cake_print_opt(struct qdisc_util *qu, FILE *f, struct rtattr *opt)
  120. struct rtattr *tb[TCA_CAKE_MAX + 1];
  121. unsigned int interval = 0;
  122. unsigned int memlimit = 0;
  123. + unsigned int fwmark = 0;
  124. __u64 bandwidth = 0;
  125. int ack_filter = 0;
  126. int split_gso = 0;
  127. @@ -507,6 +523,10 @@ static int cake_print_opt(struct qdisc_util *qu, FILE *f, struct rtattr *opt)
  128. RTA_PAYLOAD(tb[TCA_CAKE_RTT]) >= sizeof(__u32)) {
  129. interval = rta_getattr_u32(tb[TCA_CAKE_RTT]);
  130. }
  131. + if (tb[TCA_CAKE_FWMARK] &&
  132. + RTA_PAYLOAD(tb[TCA_CAKE_FWMARK]) >= sizeof(__u32)) {
  133. + fwmark = rta_getattr_u32(tb[TCA_CAKE_FWMARK]);
  134. + }
  135. if (wash)
  136. print_string(PRINT_FP, NULL, "wash ", NULL);
  137. @@ -559,6 +579,10 @@ static int cake_print_opt(struct qdisc_util *qu, FILE *f, struct rtattr *opt)
  138. sprint_size(memlimit, b1));
  139. }
  140. + if (fwmark)
  141. + print_uint(PRINT_FP, NULL, "fwmark 0x%x ", fwmark);
  142. + print_0xhex(PRINT_JSON, "fwmark", NULL, fwmark);
  143. +
  144. return 0;
  145. }