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
6 commit 1a574074ae7d1d745c16f7710655f38a53174c27 upstream.
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.
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>
17 drivers/net/wireguard/queueing.h | 19 ++-----------------
18 drivers/net/wireguard/receive.c | 2 +-
19 2 files changed, 3 insertions(+), 18 deletions(-)
21 --- a/drivers/net/wireguard/queueing.h
22 +++ b/drivers/net/wireguard/queueing.h
24 #include <linux/skbuff.h>
26 #include <linux/ipv6.h>
27 +#include <net/ip_tunnels.h>
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)
35 -/* Returns either the correct skb->protocol value, or 0 if invalid. */
36 -static inline __be16 wg_examine_packet_protocol(struct sk_buff *skb)
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);
51 static inline bool wg_check_packet_protocol(struct sk_buff *skb)
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;
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(
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)))