Skip to content

Commit

Permalink
UPSTREAM: wireguard: queueing: make use of ip_tunnel_parse_protocol
Browse files Browse the repository at this point in the history
Now that wg_examine_packet_protocol has been added for general
consumption as ip_tunnel_parse_protocol, it's possible to remove
wg_examine_packet_protocol and simply use the new
ip_tunnel_parse_protocol function directly.

Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
(cherry picked from commit 1a574074ae7d1d745c16f7710655f38a53174c27)
Bug: 152722841
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
Change-Id: Ia65b9100a5647c0084108b732f445f3d8a146c3a
Signed-off-by: althafvly <althafvly@gmail.com>
  • Loading branch information
zx2c4 authored and althafvly committed Jan 29, 2022
1 parent 3fece59 commit 0670a93
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 18 deletions.
19 changes: 2 additions & 17 deletions drivers/net/wireguard/queueing.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include <linux/skbuff.h>
#include <linux/ip.h>
#include <linux/ipv6.h>
#include <net/ip_tunnels.h>

struct wg_device;
struct wg_peer;
Expand Down Expand Up @@ -65,25 +66,9 @@ struct packet_cb {
#define PACKET_CB(skb) ((struct packet_cb *)((skb)->cb))
#define PACKET_PEER(skb) (PACKET_CB(skb)->keypair->entry.peer)

/* Returns either the correct skb->protocol value, or 0 if invalid. */
static inline __be16 wg_examine_packet_protocol(struct sk_buff *skb)
{
if (skb_network_header(skb) >= skb->head &&
(skb_network_header(skb) + sizeof(struct iphdr)) <=
skb_tail_pointer(skb) &&
ip_hdr(skb)->version == 4)
return htons(ETH_P_IP);
if (skb_network_header(skb) >= skb->head &&
(skb_network_header(skb) + sizeof(struct ipv6hdr)) <=
skb_tail_pointer(skb) &&
ipv6_hdr(skb)->version == 6)
return htons(ETH_P_IPV6);
return 0;
}

static inline bool wg_check_packet_protocol(struct sk_buff *skb)
{
__be16 real_protocol = wg_examine_packet_protocol(skb);
__be16 real_protocol = ip_tunnel_parse_protocol(skb);
return real_protocol && skb->protocol == real_protocol;
}

Expand Down
2 changes: 1 addition & 1 deletion drivers/net/wireguard/receive.c
Original file line number Diff line number Diff line change
Expand Up @@ -387,7 +387,7 @@ static void wg_packet_consume_data_done(struct wg_peer *peer,
*/
skb->ip_summed = CHECKSUM_UNNECESSARY;
skb->csum_level = ~0; /* All levels */
skb->protocol = wg_examine_packet_protocol(skb);
skb->protocol = ip_tunnel_parse_protocol(skb);
if (skb->protocol == htons(ETH_P_IP)) {
len = ntohs(ip_hdr(skb)->tot_len);
if (unlikely(len < sizeof(struct iphdr)))
Expand Down

0 comments on commit 0670a93

Please sign in to comment.