010-cake-fwmark.patch 4.8 KB

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