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