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: 191943 Delivered-To: patch@linaro.org Received: by 2002:a92:d244:0:0:0:0:0 with SMTP id v4csp1178213ilg; Sat, 27 Jun 2020 01:07:31 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxCrFamOOhAPgqimSIlqmPMN7paZMwqK8i/tPeDy+GyfGrlKIiSOKZEe2hUE0LzGDavoOZO X-Received: by 2002:a50:934e:: with SMTP id n14mr7477676eda.88.1593245251346; Sat, 27 Jun 2020 01:07:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1593245251; cv=none; d=google.com; s=arc-20160816; b=zfea8+CNh0d/UxvP1E2pdkdn2rvYBfldi12z0cj63XX2zwVc+yM7U6yuBHX04dbQIK uTgiTyH4iAFsl+BWHCjQMCHHPOyw1WJNU+edrdV8dM+WrdZCHNY+B1Oe+e4/4ozVIljn Dhq32GLyH7prxX3jmuLQGomL7eowhb8CQ09OmTH+pTw+Z0hEyaIGJZPWqbA51jNwG5ZD /dCff6AUlsQWOFzeSgAFri3mIKWJ2F5XCzmzvj32dvqUbs2Gf4czQ5TVgpnRF/dqNIyN jbp4a9n9OcoBtJ56VnL8IFjqFjnjDaeWtLfjeSqQFCmFDi2KD6yELznBbwqm4qp54WkP Kt/g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=9Vp+tw0QaLIycF8HKfRzJuTNoSWc9BINsSk1bY7P088=; b=bNr7gdG/gz7QWlv27/OrxogKAikQ0gD0ERetGgXwvske5ns+74W8lTdZIIQx9G5uzL FUowFBl44BJYJrXVpcc7HAvLSbIYzXhwjwFmzFukv+r5xW8eBL+kKkBE54mjK2tmTAua NHYBO/aLg+oBLc2I0UASWgrcF0ViQ4o32wDmmhqqk1b6V6wiHg8+/fZV0JX17ExLPITS jUm1ChzM7i7R6uXRf3grBg/YNAZOU3V6btrR9EPjSkgjqqvac/J64yC2sXIU70S1G5lV HvyijEaS2lF2hpA1/Vy7J5lmYqaMp6T6EJ9HFr+yAvVGgN5J/rPeigrcbB32JAzGZy29 dBSg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@zx2c4.com header.s=mail header.b=U3nsn0Oe; spf=pass (google.com: domain of netdev-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=netdev-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=zx2c4.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id c25si9181037edv.335.2020.06.27.01.07.31; Sat, 27 Jun 2020 01:07:31 -0700 (PDT) Received-SPF: pass (google.com: domain of netdev-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@zx2c4.com header.s=mail header.b=U3nsn0Oe; spf=pass (google.com: domain of netdev-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=netdev-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=zx2c4.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726312AbgF0IH3 (ORCPT + 9 others); 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(+) -- 2.27.0 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: 191944 Delivered-To: patch@linaro.org Received: by 2002:a92:d244:0:0:0:0:0 with SMTP id v4csp1178228ilg; Sat, 27 Jun 2020 01:07:33 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzRt+gtDn57DwNoesXNakWxy2QESSmmgsjuf8aLXclv9CTyuPdqFrEZUsRDFtrK9tpEhRGe X-Received: by 2002:a17:906:1386:: with SMTP id f6mr5896401ejc.66.1593245252967; Sat, 27 Jun 2020 01:07:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1593245252; cv=none; d=google.com; s=arc-20160816; b=e8XdHWanXFWLP2DVhxpiWRwkrXTFQfMt7S3bF/slmZqxJlnuc9wp3Rq/9r9AUSwJXQ Dvc/PEUY6JhjahK29sxBvPftoPOutCbTr/oSpznxDImskL8464c0nPpuqfjUSqj38yKs LnOJiNGirkW5xsxrTNvxYO05shJY3j4ZRKXyqvwm+t9prDi5iPmz+ls/Ze8JsFvTjFYw bUcStSRAtsazsI77E6LLp5kj+Eb0PX+7qUi2VWeOw6FSxTz+KfRVJk7nL8ZchShFvQmT 15xY55bRfefdJmBzdtsPzCvcc7bDC05HYqyVmXkFI88byiANh3JqzGIARHYkB7495h0E 3TXA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=vWBrPP9l+QKDIyH9arTmX+HFWS9FqfcSiC36xjoMF34=; b=AR52XQs6e6wWRzSua3qlgmyK4fXe60KJPL0+EdbBBErw5wLU2FxK4/wmwQkrOaJZUZ gX1Cbmf6H6KYi/i8JVR8wb5Dfxg0En5Wrm3Bt+XvoW4ziW+skkoaetnAmZ/yNlyxQbXw 7fKRaWbrBcuz1VX5QpYLVhz2SPfQ86PJfOL3BMY/OR/WjIfTJhfXJrtJGp9oW9e25Y04 9im2nQaHI01Y6oUAacNB5hupTqUWVYs/1knBohVoJTDZZknbpXOUW6sH7+mxSuUxGiAv zhQYsZ6FoTdkoyRk58iZPBfDe2geZsDuXm2qej2Le9IIybo0QpLrUFExiT6pfvrvPw1u 1sEg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@zx2c4.com header.s=mail header.b=3gFJ1lXv; spf=pass (google.com: domain of netdev-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=netdev-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=zx2c4.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id c25si9181037edv.335.2020.06.27.01.07.32; Sat, 27 Jun 2020 01:07:32 -0700 (PDT) Received-SPF: pass (google.com: domain of netdev-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@zx2c4.com header.s=mail header.b=3gFJ1lXv; spf=pass (google.com: domain of netdev-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=netdev-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=zx2c4.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726356AbgF0IHb (ORCPT + 9 others); 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(+) -- 2.27.0 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: 191945 Delivered-To: patch@linaro.org Received: by 2002:a92:d244:0:0:0:0:0 with SMTP id v4csp1178258ilg; Sat, 27 Jun 2020 01:07:36 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwfLe/AGoiWOIik/W/62LRUQF9zrlLAU508kkiv4q59afGWXLFtkU66+r4y1X2bx4HLPMTr X-Received: by 2002:a05:6402:202a:: with SMTP id ay10mr7731928edb.0.1593245256422; Sat, 27 Jun 2020 01:07:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1593245256; cv=none; d=google.com; s=arc-20160816; b=udJFBYyt9LKNlqRL5m9M/Y6UTOtqY969ErR5i9uRgBxNlLH30t5QRtFMyKRvj/59Uv lyDKJyvKGUsx3r7angPg5TX2iB4FeJZIE8HmkmHw+Xe3WGnbZQ5Z7QL2dOIjiaSDq3ix mpwER6jNv1m5V1nsV9d22VYNE6hvUTzrKUFANR4jEjV0WFcnIvB1Q+GJqF1i0reQTWPr c6cbC2pBttmmfW4+RNp+9tUahOxSDL/5nuOA19+OA82c8UkSWFk+9eJzNLT1bjv90i5j ZUVnKNkGKr5sppOl5zGw032znVRT17aL1vm5Biky4fuXeMDhYV5OnOxGLc0RFMNGTND9 0Bpg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=kvbxJPl5WzAkWHv1uFWyfOz1qwHCJvWnkUfU7Txylpk=; b=jJT6CrcooyU1YJlWbmvkDJQL5CqkFB4lk70N9J+tB8ER9mlXhm3Zx4viCgbRPHoF76 S423KkNm2pydEu/m5wgL9xjNfH9VO5AqwFDdq19Z6cE3TAIuayIsYO37445CkwdOQdDU u6PfQ9v18OqGDzlkGxRhob4A2YeLluQ6z6TvttW6BQYTDP/w/lrwJ22fHwmEAS6Db1V8 SvRTVPBa1icgRVWPffL5Sx6pNW2OA8kFeSCZwqTAUCqQ8FBac4pvHTTrJO1aThbktOt/ Sv/hOmeqT2lQKxLX80wm/JYyI1O5sfpLUzsGNPitufOBSm4JpTwRIJA3+WD+uKchOBll koog== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@zx2c4.com header.s=mail header.b=mk6W3tZ3; spf=pass (google.com: domain of netdev-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=netdev-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=zx2c4.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id c25si9181037edv.335.2020.06.27.01.07.36; Sat, 27 Jun 2020 01:07:36 -0700 (PDT) Received-SPF: pass (google.com: domain of netdev-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@zx2c4.com header.s=mail header.b=mk6W3tZ3; spf=pass (google.com: domain of netdev-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=netdev-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=zx2c4.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726394AbgF0IHf (ORCPT + 9 others); 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(+) -- 2.27.0 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: 191946 Delivered-To: patch@linaro.org Received: by 2002:a92:d244:0:0:0:0:0 with SMTP id v4csp1178288ilg; Sat, 27 Jun 2020 01:07:38 -0700 (PDT) X-Google-Smtp-Source: ABdhPJz+3HArJEerLlJzTYeNemVckSFc6z5Jb7gmczXQ+JtpbM8piwa7qN6mZv3Se2awXzI7r3y6 X-Received: by 2002:a17:906:745:: with SMTP id z5mr5824733ejb.492.1593245258362; Sat, 27 Jun 2020 01:07:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1593245258; cv=none; d=google.com; s=arc-20160816; b=OD0ciT/rhjR6Ox1lyTVySD9tErdnlGRX/2kKKcfd30a3xuGeXuXKe0u3gcD9uIisVZ QQgLmH+pyHB/+CCM0mE1w5qJMvDSVJFNmnIim4RT0T98JIUkOUHg4Ocv7GLi1Zv0bj1n OKXlkfW+1rkJa+MEOndZmKTjrxt4QMMX/XW9SHduU2muRJ+OokThfoRDnURnqTCMQI3c oXMejTxA3A6StgO8uy9OYtYOy8azcr3GmXuysXMdt1Sv3nhNG9UvuXJSMp12FJuwOFJb dPoUYP0P7kjUPBTT0X7ojzh9h7Yld0wtPdCLskZYA0/dE0G17QsNatb2eIuZEupSlH5E RDMQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=i4UvncsZdE071auos7vEfpOX7gZUN+28WLtIKzVFUtI=; b=ssbvCEadKGKydA2zw0hLpqUP9m/+/I2Q1Gv75yLB32u4h9nudvJhcqAjRo/QvaVqUB Cf+tqY6seFgjudyAs7r6oUuzj+ykBSn1cX/Ot+FfauuwMTuMi3EBcu79EfbOIOdatOPs zkg33wvX7sSKsidoPiLSQuthEbtlVIvqxPLwfm5Ib/yshxI3tB+AcDnIeluc2+KLFt1m nW5xiMhezdhutoOLT40Yy/RWSzy172unCw0hRyoaDjIFNjNPoOFyfk6bBHGb9+0Io7kL rAWgJL7JPcKtmm1/9dFEdjhetLjq+2qMTMEtHujWD6D0EXGz7rW95m+1deFZogFnFuV5 s2/Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@zx2c4.com header.s=mail header.b=aY2E+VAG; spf=pass (google.com: domain of netdev-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=netdev-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=zx2c4.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id c25si9181037edv.335.2020.06.27.01.07.38; Sat, 27 Jun 2020 01:07:38 -0700 (PDT) Received-SPF: pass (google.com: domain of netdev-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@zx2c4.com header.s=mail header.b=aY2E+VAG; spf=pass (google.com: domain of netdev-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=netdev-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=zx2c4.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726386AbgF0IHe (ORCPT + 9 others); 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(-) -- 2.27.0 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: 191947 Delivered-To: patch@linaro.org Received: by 2002:a92:d244:0:0:0:0:0 with SMTP id v4csp1178299ilg; Sat, 27 Jun 2020 01:07:40 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxi1AXMgcF7lzW+dOyuQRLQ6XyQaUkeGxQYKAUeoG99/ShrkQfcmns6HIqj5b/dkMnB55Xa X-Received: by 2002:a50:a661:: with SMTP id d88mr7483539edc.34.1593245260447; Sat, 27 Jun 2020 01:07:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1593245260; cv=none; d=google.com; s=arc-20160816; b=hJsiIXfQnb0FPpT2+EZmH+aKdPoMiCxEDur/MKC4QaiBBNpInknCqxf6nsHnOy9bLY HG5xn3s02v6pag8vF5/kI1+a75LUnDLQEe3VD+pPLPwf91g7CUgxZ+dATo+otvFuMKKL MigZ8CMOiunfXjvjqFSpD00EGMkCht+/QudmmXnyZJ+0USI188WEtlDStZxr7wGd6HT9 HB4S1BAFbHKu5erLHLbUTVio68y0ffyp6LFmdhVQ9wL5adweoFFclGpOhIFRb4/x8eg/ ZnHwX/2DJtcYaqZ2D3SaYoPenMx94MveiTnykDpI/uX3FxNVNv95s8MwsbbZhtgQii9m 4vHg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=nfPFmkx6WYOblu+B7unOiOab2bOyqhxJcYoQTa7pYmg=; b=U9s9uXycS1ZgfeGv8nXSUENc3Rvdzmiz+iuBaMhyLaxFDEaTYmOW2F9pzyAuWJorxy S9mfjdmcehVE5uVgsOhQcOVFfgmPWn/HJBS8yImDs+WBctX5SSjaA8gcNjxKm9JXfkjT bx7UvZAHDfcAngM2uxe11ilLiTeTuR288KHcM12EuzQxYhE/pPrdN6D2ldbnFaHA6m4t tSoAsGWyvqrtQj7VXYfaTxh2BdGDONpbCC3zXQnlGcvSSP6JoH6QwwA1hySjhpwoGsM2 FZsdxR8qL2VFp0prJMKnDIzxG4KgO0DAZkygMHYiJjgDrecSEO7o1j49oasvpiMtyFVo ckRQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@zx2c4.com header.s=mail header.b=R7+RFpp8; spf=pass (google.com: domain of netdev-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=netdev-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=zx2c4.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id c25si9181037edv.335.2020.06.27.01.07.40; Sat, 27 Jun 2020 01:07:40 -0700 (PDT) Received-SPF: pass (google.com: domain of netdev-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@zx2c4.com header.s=mail header.b=R7+RFpp8; spf=pass (google.com: domain of netdev-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=netdev-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=zx2c4.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726402AbgF0IHj (ORCPT + 9 others); 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(+) -- 2.27.0 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;