kernel: 5.4: import wireguard backport
[openwrt/openwrt.git] / target / linux / generic / backport-5.4 / 080-wireguard-0110-wireguard-implement-header_ops-parse_protocol-for-AF.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:20 -0600
4 Subject: [PATCH] wireguard: implement header_ops->parse_protocol for AF_PACKET
5
6 commit 01a4967c71c004f8ecad4ab57021348636502fa9 upstream.
7
8 WireGuard uses skb->protocol to determine packet type, and bails out if
9 it's not set or set to something it's not expecting. For AF_PACKET
10 injection, we need to support its call chain of:
11
12 packet_sendmsg -> packet_snd -> packet_parse_headers ->
13 dev_parse_header_protocol -> parse_protocol
14
15 Without a valid parse_protocol, this returns zero, and wireguard then
16 rejects the skb. So, this wires up the ip_tunnel handler for layer 3
17 packets for that case.
18
19 Reported-by: Hans Wippel <ndev@hwipl.net>
20 Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
21 Signed-off-by: David S. Miller <davem@davemloft.net>
22 Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
23 ---
24 drivers/net/wireguard/device.c | 1 +
25 1 file changed, 1 insertion(+)
26
27 --- a/drivers/net/wireguard/device.c
28 +++ b/drivers/net/wireguard/device.c
29 @@ -262,6 +262,7 @@ static void wg_setup(struct net_device *
30 max(sizeof(struct ipv6hdr), sizeof(struct iphdr));
31
32 dev->netdev_ops = &netdev_ops;
33 + dev->header_ops = &ip_tunnel_header_ops;
34 dev->hard_header_len = 0;
35 dev->addr_len = 0;
36 dev->needed_headroom = DATA_PACKET_HEAD_ROOM;