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