kernel: 5.4: import wireguard backport
[openwrt/openwrt.git] / target / linux / generic / backport-5.4 / 080-wireguard-0111-wireguard-queueing-make-use-of-ip_tunnel_parse_proto.patch
1 From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
2 From: "Jason A. Donenfeld" <Jason@zx2c4.com>
3 Date: Mon, 29 Jun 2020 19:06:21 -0600
4 Subject: [PATCH] wireguard: queueing: make use of ip_tunnel_parse_protocol
5
6 commit 1a574074ae7d1d745c16f7710655f38a53174c27 upstream.
7
8 Now that wg_examine_packet_protocol has been added for general
9 consumption as ip_tunnel_parse_protocol, it's possible to remove
10 wg_examine_packet_protocol and simply use the new
11 ip_tunnel_parse_protocol function directly.
12
13 Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
14 Signed-off-by: David S. Miller <davem@davemloft.net>
15 Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
16 ---
17 drivers/net/wireguard/queueing.h | 19 ++-----------------
18 drivers/net/wireguard/receive.c | 2 +-
19 2 files changed, 3 insertions(+), 18 deletions(-)
20
21 --- a/drivers/net/wireguard/queueing.h
22 +++ b/drivers/net/wireguard/queueing.h
23 @@ -11,6 +11,7 @@
24 #include <linux/skbuff.h>
25 #include <linux/ip.h>
26 #include <linux/ipv6.h>
27 +#include <net/ip_tunnels.h>
28
29 struct wg_device;
30 struct wg_peer;
31 @@ -65,25 +66,9 @@ struct packet_cb {
32 #define PACKET_CB(skb) ((struct packet_cb *)((skb)->cb))
33 #define PACKET_PEER(skb) (PACKET_CB(skb)->keypair->entry.peer)
34
35 -/* Returns either the correct skb->protocol value, or 0 if invalid. */
36 -static inline __be16 wg_examine_packet_protocol(struct sk_buff *skb)
37 -{
38 - if (skb_network_header(skb) >= skb->head &&
39 - (skb_network_header(skb) + sizeof(struct iphdr)) <=
40 - skb_tail_pointer(skb) &&
41 - ip_hdr(skb)->version == 4)
42 - return htons(ETH_P_IP);
43 - if (skb_network_header(skb) >= skb->head &&
44 - (skb_network_header(skb) + sizeof(struct ipv6hdr)) <=
45 - skb_tail_pointer(skb) &&
46 - ipv6_hdr(skb)->version == 6)
47 - return htons(ETH_P_IPV6);
48 - return 0;
49 -}
50 -
51 static inline bool wg_check_packet_protocol(struct sk_buff *skb)
52 {
53 - __be16 real_protocol = wg_examine_packet_protocol(skb);
54 + __be16 real_protocol = ip_tunnel_parse_protocol(skb);
55 return real_protocol && skb->protocol == real_protocol;
56 }
57
58 --- a/drivers/net/wireguard/receive.c
59 +++ b/drivers/net/wireguard/receive.c
60 @@ -387,7 +387,7 @@ static void wg_packet_consume_data_done(
61 */
62 skb->ip_summed = CHECKSUM_UNNECESSARY;
63 skb->csum_level = ~0; /* All levels */
64 - skb->protocol = wg_examine_packet_protocol(skb);
65 + skb->protocol = ip_tunnel_parse_protocol(skb);
66 if (skb->protocol == htons(ETH_P_IP)) {
67 len = ntohs(ip_hdr(skb)->tot_len);
68 if (unlikely(len < sizeof(struct iphdr)))