From patchwork Sat Jun 27 08:07:09 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Jason A. Donenfeld" X-Patchwork-Id: 1318259 X-Patchwork-Delegate: davem@davemloft.net Return-Path: X-Original-To: patchwork-incoming-netdev@ozlabs.org Delivered-To: patchwork-incoming-netdev@ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=23.128.96.18; helo=vger.kernel.org; envelope-from=netdev-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=zx2c4.com Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=zx2c4.com header.i=@zx2c4.com header.a=rsa-sha1 header.s=mail header.b=U3nsn0Oe; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by ozlabs.org (Postfix) with ESMTP id 49v5vl67dYz9sRk for ; Sat, 27 Jun 2020 18:07:31 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726312AbgF0IH3 (ORCPT ); Sat, 27 Jun 2020 04:07:29 -0400 Received: from mail.zx2c4.com ([192.95.5.64]:48179 "EHLO mail.zx2c4.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725991AbgF0IH1 (ORCPT ); Sat, 27 Jun 2020 04:07:27 -0400 Received: by mail.zx2c4.com (ZX2C4 Mail Server) with ESMTP id bea1e8e4; Sat, 27 Jun 2020 07:48:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=zx2c4.com; h=from:to:cc :subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; s=mail; bh=Cz702woikBQPXSFMDcaXkR3Bj 5s=; b=U3nsn0OeI3SnCKIxa+FX+mmzoj6amZ2g3resRkHlEw/THYlKhhefc9oQp xzqvlsBgbvX+eD7Q/K8w+VuHblCnyK25VxyR5OG3+SU+tZZYuzBdPmTnM0iuBKWW +HN3rCqzlvR0w2vjicj9GjD0hNBFkEC3cjB0WZEmPH4yofmXw/gY3x6jwZh/c/rb bmMl0qNffKucERKRm1dfLntzaQhE+LhDG8QSAE0teUHRXDySreEn8fYis5ZWiNwu APK+4a17kxTyLM4EEE+P05+IE/dc+6XNOb2uhG4mbKW3KfY1rOPsix/kuw2Bzta2 XpyalB9SpcqHb10vlX5UQhNHqK2rg== Received: by mail.zx2c4.com (ZX2C4 Mail Server) with ESMTPSA id 8efff8dc (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Sat, 27 Jun 2020 07:48:02 +0000 (UTC) From: "Jason A. Donenfeld" To: netdev@vger.kernel.org, davem@davemloft.net Cc: "Jason A. Donenfeld" Subject: [PATCH net 1/5] net: ip_tunnel: add header_ops for layer 3 devices Date: Sat, 27 Jun 2020 02:07:09 -0600 Message-Id: <20200627080713.179883-2-Jason@zx2c4.com> In-Reply-To: <20200627080713.179883-1-Jason@zx2c4.com> References: <20200627080713.179883-1-Jason@zx2c4.com> MIME-Version: 1.0 Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org Some devices that take straight up layer 3 packets benefit from having a shared header_ops so that AF_PACKET sockets can inject packets that are recognized. This shared infrastructure will be used by other drivers that currently can't inject packets using AF_PACKET. It also exposes the parser function, as it is useful in standalone form too. Signed-off-by: Jason A. Donenfeld --- include/net/ip_tunnels.h | 3 +++ net/ipv4/ip_tunnel_core.c | 19 +++++++++++++++++++ 2 files changed, 22 insertions(+) diff --git a/include/net/ip_tunnels.h b/include/net/ip_tunnels.h index 076e5d7db7d3..36025dea7612 100644 --- a/include/net/ip_tunnels.h +++ b/include/net/ip_tunnels.h @@ -290,6 +290,9 @@ int ip_tunnel_newlink(struct net_device *dev, struct nlattr *tb[], struct ip_tunnel_parm *p, __u32 fwmark); void ip_tunnel_setup(struct net_device *dev, unsigned int net_id); +extern const struct header_ops ip_tunnel_header_ops; +__be16 ip_tunnel_parse_protocol(const struct sk_buff *skb); + struct ip_tunnel_encap_ops { size_t (*encap_hlen)(struct ip_tunnel_encap *e); int (*build_header)(struct sk_buff *skb, struct ip_tunnel_encap *e, diff --git a/net/ipv4/ip_tunnel_core.c b/net/ipv4/ip_tunnel_core.c index 181b7a2a0247..07d958aa03f8 100644 --- a/net/ipv4/ip_tunnel_core.c +++ b/net/ipv4/ip_tunnel_core.c @@ -1,6 +1,7 @@ // SPDX-License-Identifier: GPL-2.0-only /* * Copyright (c) 2013 Nicira, Inc. + * Copyright (C) 2020 Jason A. Donenfeld . All Rights Reserved. */ #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt @@ -844,3 +845,21 @@ void ip_tunnel_unneed_metadata(void) static_branch_dec(&ip_tunnel_metadata_cnt); } EXPORT_SYMBOL_GPL(ip_tunnel_unneed_metadata); + +/* Returns either the correct skb->protocol value, or 0 if invalid. */ +__be16 ip_tunnel_parse_protocol(const 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; +} +EXPORT_SYMBOL(ip_tunnel_parse_protocol); + +const struct header_ops ip_tunnel_header_ops = { .parse_protocol = ip_tunnel_parse_protocol }; +EXPORT_SYMBOL(ip_tunnel_header_ops); From patchwork Sat Jun 27 08:07:10 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Jason A. Donenfeld" X-Patchwork-Id: 1318260 X-Patchwork-Delegate: davem@davemloft.net Return-Path: X-Original-To: patchwork-incoming-netdev@ozlabs.org Delivered-To: patchwork-incoming-netdev@ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=23.128.96.18; helo=vger.kernel.org; envelope-from=netdev-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=zx2c4.com Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=zx2c4.com header.i=@zx2c4.com header.a=rsa-sha1 header.s=mail header.b=3gFJ1lXv; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by ozlabs.org (Postfix) with ESMTP id 49v5vm5nn8z9sQx for ; Sat, 27 Jun 2020 18:07:32 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726356AbgF0IHb (ORCPT ); Sat, 27 Jun 2020 04:07:31 -0400 Received: from mail.zx2c4.com ([192.95.5.64]:48179 "EHLO mail.zx2c4.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726139AbgF0IH2 (ORCPT ); Sat, 27 Jun 2020 04:07:28 -0400 Received: by mail.zx2c4.com (ZX2C4 Mail Server) with ESMTP id 98160d3d; Sat, 27 Jun 2020 07:48:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=zx2c4.com; h=from:to:cc :subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; s=mail; bh=xKPsjje8Yh5NeiPGcodksFIMq EM=; b=3gFJ1lXvw/h4T7b8GfonTIDVGdvaOawzoQSF+NPaHH2t0JtbP0XHud99H A1Cd+j9fJXscQ/paZ57y5v09fIiGI/SfwMVCx3p+AqYXm3rIe9XK0D1Z7i6xF/ny +sn2DhtI/GSde4ZpCH5rsZB4FtsDzj925sYH5PgtQf443DqUpV8Gszv6wtsN300R X/70kCgBLyS21b9m1ltn0l1zIz0X/a3uo9sP4dR6LF0JiQn9fPvbUH9oqYHRdwfq F2FuMt39/iw4lrJl6MHjtnwZlpmarK0lZaPr3znLly3ReShhYSjqD+ssP2os/fnF csnYPimDxdYsJiF/dkLTSFIIYzcrQ== Received: by mail.zx2c4.com (ZX2C4 Mail Server) with ESMTPSA id 4f8fbdf5 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Sat, 27 Jun 2020 07:48:03 +0000 (UTC) From: "Jason A. Donenfeld" To: netdev@vger.kernel.org, davem@davemloft.net Cc: "Jason A. Donenfeld" Subject: [PATCH net 2/5] net: ipip: implement header_ops->parse_protocol for AF_PACKET Date: Sat, 27 Jun 2020 02:07:10 -0600 Message-Id: <20200627080713.179883-3-Jason@zx2c4.com> In-Reply-To: <20200627080713.179883-1-Jason@zx2c4.com> References: <20200627080713.179883-1-Jason@zx2c4.com> MIME-Version: 1.0 Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org Ipip uses skb->protocol to determine packet type, and bails out if it's not set. For AF_PACKET injection, we need to support its call chain of: packet_sendmsg -> packet_snd -> packet_parse_headers -> dev_parse_header_protocol -> parse_protocol Without a valid parse_protocol, this returns zero, and ipip rejects the skb. So, this wires up the ip_tunnel handler for layer 3 packets for that case. Signed-off-by: Jason A. Donenfeld --- net/ipv4/ipip.c | 1 + net/ipv6/ip6_tunnel.c | 1 + 2 files changed, 2 insertions(+) diff --git a/net/ipv4/ipip.c b/net/ipv4/ipip.c index 40fea52c8277..75d35e76bec2 100644 --- a/net/ipv4/ipip.c +++ b/net/ipv4/ipip.c @@ -361,6 +361,7 @@ static const struct net_device_ops ipip_netdev_ops = { static void ipip_tunnel_setup(struct net_device *dev) { dev->netdev_ops = &ipip_netdev_ops; + dev->header_ops = &ip_tunnel_header_ops; dev->type = ARPHRD_TUNNEL; dev->flags = IFF_NOARP; diff --git a/net/ipv6/ip6_tunnel.c b/net/ipv6/ip6_tunnel.c index 821d96c720b9..a18c378ca5f4 100644 --- a/net/ipv6/ip6_tunnel.c +++ b/net/ipv6/ip6_tunnel.c @@ -1846,6 +1846,7 @@ static const struct net_device_ops ip6_tnl_netdev_ops = { static void ip6_tnl_dev_setup(struct net_device *dev) { dev->netdev_ops = &ip6_tnl_netdev_ops; + dev->header_ops = &ip_tunnel_header_ops; dev->needs_free_netdev = true; dev->priv_destructor = ip6_dev_free; From patchwork Sat Jun 27 08:07:11 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Jason A. Donenfeld" X-Patchwork-Id: 1318261 X-Patchwork-Delegate: davem@davemloft.net Return-Path: X-Original-To: patchwork-incoming-netdev@ozlabs.org Delivered-To: patchwork-incoming-netdev@ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=23.128.96.18; helo=vger.kernel.org; envelope-from=netdev-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=zx2c4.com Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=zx2c4.com header.i=@zx2c4.com header.a=rsa-sha1 header.s=mail header.b=mk6W3tZ3; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by ozlabs.org (Postfix) with ESMTP id 49v5vr2DTyz9sQx for ; Sat, 27 Jun 2020 18:07:36 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726394AbgF0IHf (ORCPT ); Sat, 27 Jun 2020 04:07:35 -0400 Received: from mail.zx2c4.com ([192.95.5.64]:48179 "EHLO mail.zx2c4.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726317AbgF0IHa (ORCPT ); Sat, 27 Jun 2020 04:07:30 -0400 Received: by mail.zx2c4.com (ZX2C4 Mail Server) with ESMTP id f278eb5f; Sat, 27 Jun 2020 07:48:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=zx2c4.com; h=from:to:cc :subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; s=mail; bh=uwnjUE31tMKRKEKYq4haAys8j Ew=; b=mk6W3tZ3kchWeSUuHXnTUxI+s3lBoTrQUEaypnA9g8qkKrjmeFSB6B9ma WKn3EHHuWOhYnXVLTGHCcWaqTUwrPQDBFNS/mYSyvvUXCp2IvFFbQkpEy+e//iIu XaVVXdzxVWTUz0CpcbBBhioSK12ytg4u0bvksKpdUye4CeUdLYElq73kJmwvyahN zyTGRLBbSFpm0nyh0JQ+7RKGvk6HdSMI5UAAa8dwGIFbhTC/I8xGRwTHqaOFH5Qy MJ+HJ4NJfVtye6eXDi0AFy5j6SpWra8xLnpmyut+T9VtUP7d0beIL56YQGBU0ehS m+l+1YcigHYYQLnQ+nEP8u7LEQhsQ== Received: by mail.zx2c4.com (ZX2C4 Mail Server) with ESMTPSA id 89c47963 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Sat, 27 Jun 2020 07:48:05 +0000 (UTC) From: "Jason A. Donenfeld" To: netdev@vger.kernel.org, davem@davemloft.net Cc: "Jason A. Donenfeld" , Hans Wippel Subject: [PATCH net 3/5] wireguard: implement header_ops->parse_protocol for AF_PACKET Date: Sat, 27 Jun 2020 02:07:11 -0600 Message-Id: <20200627080713.179883-4-Jason@zx2c4.com> In-Reply-To: <20200627080713.179883-1-Jason@zx2c4.com> References: <20200627080713.179883-1-Jason@zx2c4.com> MIME-Version: 1.0 Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org WireGuard uses skb->protocol to determine packet type, and bails out if it's not set or set to something it's not expecting. For AF_PACKET injection, we need to support its call chain of: packet_sendmsg -> packet_snd -> packet_parse_headers -> dev_parse_header_protocol -> parse_protocol Without a valid parse_protocol, this returns zero, and wireguard then rejects the skb. So, this wires up the ip_tunnel handler for layer 3 packets for that case. Reported-by: Hans Wippel Signed-off-by: Jason A. Donenfeld --- drivers/net/wireguard/device.c | 1 + 1 file changed, 1 insertion(+) diff --git a/drivers/net/wireguard/device.c b/drivers/net/wireguard/device.c index a8f151b1b5fa..c9f65e96ccb0 100644 --- a/drivers/net/wireguard/device.c +++ b/drivers/net/wireguard/device.c @@ -262,6 +262,7 @@ static void wg_setup(struct net_device *dev) max(sizeof(struct ipv6hdr), sizeof(struct iphdr)); dev->netdev_ops = &netdev_ops; + dev->header_ops = &ip_tunnel_header_ops; dev->hard_header_len = 0; dev->addr_len = 0; dev->needed_headroom = DATA_PACKET_HEAD_ROOM; From patchwork Sat Jun 27 08:07:12 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Jason A. Donenfeld" X-Patchwork-Id: 1318262 X-Patchwork-Delegate: davem@davemloft.net Return-Path: X-Original-To: patchwork-incoming-netdev@ozlabs.org Delivered-To: patchwork-incoming-netdev@ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=23.128.96.18; helo=vger.kernel.org; envelope-from=netdev-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=zx2c4.com Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=zx2c4.com header.i=@zx2c4.com header.a=rsa-sha1 header.s=mail header.b=aY2E+VAG; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by ozlabs.org (Postfix) with ESMTP id 49v5vt1kBtz9sQx for ; Sat, 27 Jun 2020 18:07:38 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726386AbgF0IHe (ORCPT ); Sat, 27 Jun 2020 04:07:34 -0400 Received: from mail.zx2c4.com ([192.95.5.64]:48179 "EHLO mail.zx2c4.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726335AbgF0IHb (ORCPT ); Sat, 27 Jun 2020 04:07:31 -0400 Received: by mail.zx2c4.com (ZX2C4 Mail Server) with ESMTP id 02ed63c5; Sat, 27 Jun 2020 07:48:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=zx2c4.com; h=from:to:cc :subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; s=mail; bh=wplZDiGCa+tCNFlT7tJltU1KK XA=; b=aY2E+VAGIuSlGo9Z3znuyQ7Cp3EKGC+Ct2NiK8p7/N6E2LkdwRQrFqWx3 gjqeD9vqYDXLPgtTVLOTg/OPnJ3+K4UtDJIbTAiJQ2sxiaI3a7Z4Mz45l0t4GwS/ RTyKJxe6yHT+KvStwlGZfH2rztxpwwtsruIhHpLim/Y7tiinoV26LAfSWRle/3Xd SyHudy3GUnBBVdAx3vsQbZNj6pD8QasKglQpqBjAa9mPNRWWAM+YpHixHMEYO4oK 0ZqfVEZzOKSob0g4AdKaUAC0XAqoQQT7LTEXhg3YuRmgPMnKUOT08vYAeaQvUIg+ SiimBBSPMw8TQq0WfoTO8RYGkwg3g== Received: by mail.zx2c4.com (ZX2C4 Mail Server) with ESMTPSA id 516c1408 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Sat, 27 Jun 2020 07:48:06 +0000 (UTC) From: "Jason A. Donenfeld" To: netdev@vger.kernel.org, davem@davemloft.net Cc: "Jason A. Donenfeld" Subject: [PATCH net 4/5] wireguard: queueing: make use of ip_tunnel_parse_protocol Date: Sat, 27 Jun 2020 02:07:12 -0600 Message-Id: <20200627080713.179883-5-Jason@zx2c4.com> In-Reply-To: <20200627080713.179883-1-Jason@zx2c4.com> References: <20200627080713.179883-1-Jason@zx2c4.com> MIME-Version: 1.0 Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org 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 --- drivers/net/wireguard/queueing.h | 19 ++----------------- drivers/net/wireguard/receive.c | 2 +- 2 files changed, 3 insertions(+), 18 deletions(-) diff --git a/drivers/net/wireguard/queueing.h b/drivers/net/wireguard/queueing.h index c58df439dbbe..dfb674e03076 100644 --- a/drivers/net/wireguard/queueing.h +++ b/drivers/net/wireguard/queueing.h @@ -11,6 +11,7 @@ #include #include #include +#include struct wg_device; struct wg_peer; @@ -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; } diff --git a/drivers/net/wireguard/receive.c b/drivers/net/wireguard/receive.c index 9b2ab6fc91cd..2c9551ea6dc7 100644 --- a/drivers/net/wireguard/receive.c +++ b/drivers/net/wireguard/receive.c @@ -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))) From patchwork Sat Jun 27 08:07:13 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Jason A. Donenfeld" X-Patchwork-Id: 1318263 X-Patchwork-Delegate: davem@davemloft.net Return-Path: X-Original-To: patchwork-incoming-netdev@ozlabs.org Delivered-To: patchwork-incoming-netdev@ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=23.128.96.18; helo=vger.kernel.org; envelope-from=netdev-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=zx2c4.com Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=zx2c4.com header.i=@zx2c4.com header.a=rsa-sha1 header.s=mail header.b=R7+RFpp8; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by ozlabs.org (Postfix) with ESMTP id 49v5vw2MvHz9sQx for ; Sat, 27 Jun 2020 18:07:40 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726402AbgF0IHj (ORCPT ); Sat, 27 Jun 2020 04:07:39 -0400 Received: from mail.zx2c4.com ([192.95.5.64]:48179 "EHLO mail.zx2c4.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726139AbgF0IHe (ORCPT ); Sat, 27 Jun 2020 04:07:34 -0400 Received: by mail.zx2c4.com (ZX2C4 Mail Server) with ESMTP id 78266130; Sat, 27 Jun 2020 07:48:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=zx2c4.com; h=from:to:cc :subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; s=mail; bh=yhbQ52i5catljqOFAhcNxV2L/ vc=; b=R7+RFpp8dDhJmSShOsBe9mvuS5x03Im8dQF82SqUIIGebE4T3bGKnALNf zuWYdftbtjfqjlt/ZkMoBkJFR5TBl2SOlB+qH8rJT5Frmh+NbxuXCoR004fV3++I UCZlKhNYHkP9ArBcwTFM7c1O6oTPUXiqtQGp/7fcTRXpjmMD4Y8NrHc3etF9FvB/ rvRCkhR0MWonBxbSBZk3NP7q505jkFjrd1Bej14Mps067lNBqJ/tlU+GYMYAu8Od 1PyTgqM+O8EIvnu7fDm71/8ouRh+mWrss9cHS1aiR7exUuZNG29hk1oesdV4SwNZ e+sBFWuzlISD4MDQBNZc9yV80D6tg== Received: by mail.zx2c4.com (ZX2C4 Mail Server) with ESMTPSA id b41ae87a (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Sat, 27 Jun 2020 07:48:07 +0000 (UTC) From: "Jason A. Donenfeld" To: netdev@vger.kernel.org, davem@davemloft.net Cc: "Jason A. Donenfeld" Subject: [PATCH net 5/5] tun: implement header_ops->parse_protocol for AF_PACKET Date: Sat, 27 Jun 2020 02:07:13 -0600 Message-Id: <20200627080713.179883-6-Jason@zx2c4.com> In-Reply-To: <20200627080713.179883-1-Jason@zx2c4.com> References: <20200627080713.179883-1-Jason@zx2c4.com> MIME-Version: 1.0 Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org The tun driver passes up skb->protocol to userspace in the form of PI headers. For AF_PACKET injection, we need to support its call chain of: packet_sendmsg -> packet_snd -> packet_parse_headers -> dev_parse_header_protocol -> parse_protocol Without a valid parse_protocol, this returns zero, and the tun driver then gives userspace bogus values that it can't deal with. Note that this isn't the case with tap, because tap already benefits from the shared infrastructure for ethernet headers. But with tun, there's nothing. Signed-off-by: Jason A. Donenfeld --- drivers/net/tun.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/drivers/net/tun.c b/drivers/net/tun.c index 858b012074bd..7adeb91bd368 100644 --- a/drivers/net/tun.c +++ b/drivers/net/tun.c @@ -62,6 +62,7 @@ #include #include #include +#include #include #include #include @@ -1351,6 +1352,7 @@ static void tun_net_init(struct net_device *dev) switch (tun->flags & TUN_TYPE_MASK) { case IFF_TUN: dev->netdev_ops = &tun_netdev_ops; + dev->header_ops = &ip_tunnel_header_ops; /* Point-to-Point TUN Device */ dev->hard_header_len = 0;