ath79: mikrotik: erase firmware on SPI NOR before install
[openwrt/openwrt.git] / target / linux / generic / hack-5.4 / 641-sch_cake-fix-IP-protocol-handling-in-the-presence-of.patch
1 From a00590d570212c3c633bd463cef8ec7377cc7993 Mon Sep 17 00:00:00 2001
2 From: Kevin Darbyshire-Bryant <ldir@darbyshire-bryant.me.uk>
3 Date: Tue, 30 Jun 2020 12:07:44 +0100
4 Subject: [PATCH] sch_cake: fix IP protocol handling in the presence of VLAN
5 tags
6 MIME-Version: 1.0
7 Content-Type: text/plain; charset=UTF-8
8 Content-Transfer-Encoding: 8bit
9
10 From: Ilya Ponetayev <i.ponetaev@ndmsystems.com>
11
12 CAKE was using the return value of tc_skb_protocol() and expecting it to be
13 the IP protocol type. This can fail in the presence of QinQ VLAN tags,
14 making CAKE unable to handle ECN marking and diffserv parsing in this case.
15 Fix this by implementing our own version of tc_skb_protocol(), which will
16 use skb->protocol directly, but also parse and skip over any VLAN tags and
17 return the inner protocol number instead.
18
19 Also fix CE marking by implementing a version of INET_ECN_set_ce() that
20 uses the same parsing routine.
21
22 Fixes: ea82511518f4 ("sch_cake: Add NAT awareness to packet classifier")
23 Fixes: b2100cc56fca ("sch_cake: Use tc_skb_protocol() helper for getting packet protocol")
24 Fixes: 046f6fd5daef ("sched: Add Common Applications Kept Enhanced (cake) qdisc")
25 Signed-off-by: Ilya Ponetayev <i.ponetaev@ndmsystems.com>
26 [ squash original two patches, rewrite commit message ]
27 Signed-off-by: Toke Høiland-Jørgensen <toke@redhat.com>
28 Signed-off-by: Kevin Darbyshire-Bryant <ldir@darbyshire-bryant.me.uk>
29 ---
30 net/sched/sch_cake.c | 52 +++++++++++++++++++++++++++++++++++++++++---
31 1 file changed, 49 insertions(+), 3 deletions(-)
32
33 --- a/net/sched/sch_cake.c
34 +++ b/net/sched/sch_cake.c
35 @@ -497,6 +497,52 @@ static bool cobalt_queue_empty(struct co
36 return down;
37 }
38
39 +static __be16 cake_skb_proto(const struct sk_buff *skb)
40 +{
41 + unsigned int offset = skb_mac_offset(skb) + sizeof(struct ethhdr);
42 + __be16 proto = skb->protocol;
43 + struct vlan_hdr vhdr, *vh;
44 +
45 + while (proto == htons(ETH_P_8021Q) || proto == htons(ETH_P_8021AD)) {
46 + vh = skb_header_pointer(skb, offset, sizeof(vhdr), &vhdr);
47 + if (!vh)
48 + break;
49 +
50 + proto = vh->h_vlan_encapsulated_proto;
51 + offset += sizeof(vhdr);
52 + }
53 +
54 + return proto;
55 +}
56 +
57 +static int cake_set_ce(struct sk_buff *skb)
58 +{
59 + int wlen = skb_network_offset(skb);
60 +
61 + switch (cake_skb_proto(skb)) {
62 + case htons(ETH_P_IP):
63 + wlen += sizeof(struct iphdr);
64 + if (!pskb_may_pull(skb, wlen) ||
65 + skb_try_make_writable(skb, wlen))
66 + return 0;
67 +
68 + return IP_ECN_set_ce(ip_hdr(skb));
69 +
70 + case htons(ETH_P_IPV6):
71 + wlen += sizeof(struct ipv6hdr);
72 + if (!pskb_may_pull(skb, wlen) ||
73 + skb_try_make_writable(skb, wlen))
74 + return 0;
75 +
76 + return IP6_ECN_set_ce(skb, ipv6_hdr(skb));
77 +
78 + default:
79 + return 0;
80 + }
81 +
82 + return 0;
83 +}
84 +
85 /* Call this with a freshly dequeued packet for possible congestion marking.
86 * Returns true as an instruction to drop the packet, false for delivery.
87 */
88 @@ -549,7 +595,7 @@ static bool cobalt_should_drop(struct co
89
90 if (next_due && vars->dropping) {
91 /* Use ECN mark if possible, otherwise drop */
92 - drop = !(vars->ecn_marked = INET_ECN_set_ce(skb));
93 + drop = !(vars->ecn_marked = cake_set_ce(skb));
94
95 vars->count++;
96 if (!vars->count)
97 @@ -592,7 +638,7 @@ static bool cake_update_flowkeys(struct
98 bool rev = !skb->_nfct, upd = false;
99 __be32 ip;
100
101 - if (tc_skb_protocol(skb) != htons(ETH_P_IP))
102 + if (cake_skb_proto(skb) != htons(ETH_P_IP))
103 return false;
104
105 if (!nf_ct_get_tuple_skb(&tuple, skb))
106 @@ -1557,7 +1603,7 @@ static u8 cake_handle_diffserv(struct sk
107 u16 *buf, buf_;
108 u8 dscp;
109
110 - switch (tc_skb_protocol(skb)) {
111 + switch (cake_skb_proto(skb)) {
112 case htons(ETH_P_IP):
113 buf = skb_header_pointer(skb, offset, sizeof(buf_), &buf_);
114 if (unlikely(!buf))