From patchwork Tue Jun 30 01:06:18 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: 192035 Delivered-To: patch@linaro.org Received: by 2002:a92:d244:0:0:0:0:0 with SMTP id v4csp3369410ilg; Mon, 29 Jun 2020 18:06:42 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyj45N0QoxA18YutXucKMiZiC8lF4+dtQBhLQghCkAs9cIsA7uiE4A6Wq+QdrN5/brvO7Pm X-Received: by 2002:a50:d983:: with SMTP id w3mr19896933edj.110.1593479202363; Mon, 29 Jun 2020 18:06:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1593479202; cv=none; d=google.com; s=arc-20160816; b=UExKrtoW+oGoETdVw4OtztUngXNr8in/8tz9nndgb5/WiVNM0vORcVz9EClch9PAkN WY41kJPOFDs3UkA91be3PnOLVFZEA6oKxJS8H5fTmZKhI4OPq40pb4VCQiChjEt8Bl54 PcKmJ6G5F/IBcp2zZD8jq6KhBkV+ADZtBA2adwq7HW/7219QXTihZKJmtchu7fqCHJ5s NY1zIWOfK+19Bta2iL2xI2yWjA/nPgpKc3XA2CbFiFGmWQbUtGAPXcinKzpyRmkKAzJ5 PYjVxQotXGYkLqDpTSRqfSP7Yqci6Z6wTlR0h/LquPWOVQObhqvrVi23wylpIDsG/2JZ 5TMw== 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=uuEjy/E7PJZj5yntKxFXiGM0N88IADXqnS6SsFS3S1U=; b=B+ffkhjyCMiYfs4N1tToZF2qD/PFI2QTuIU29AXBz5/MXiA6jnEE1QV0UudYois6Qk Cg6NyCkNYcTDG41xa1+MXOHzvKCxSEMXMDBTSIFFHrM2O/kG/ya1S50AaURpibNXgQsT JkMQe2/wwx4wo0j1x3AYwthIIojiGnTXRMQ0e/vONvOD1RmdmoxZe2K9JGbpadNVS8dy rYuoPqvuf7iTKc/rB+sQ5qNBxMz3hAOPRmIq5sAbx9JQUrIENDbjhD7Fg8+lSuJ3glsg rIV8cmsGmFWhk23/Ui7bot/3tRGDiBcOo1Crn9DRXWYZWv8Fwt0CudizBRed66U06OiM hJrA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@zx2c4.com header.s=mail header.b=XEry14lB; 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 d17si849269edu.223.2020.06.29.18.06.42; Mon, 29 Jun 2020 18:06:42 -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=XEry14lB; 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 S1727771AbgF3BGl (ORCPT + 9 others); Mon, 29 Jun 2020 21:06:41 -0400 Received: from mail.zx2c4.com ([192.95.5.64]:60171 "EHLO mail.zx2c4.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726712AbgF3BGj (ORCPT ); Mon, 29 Jun 2020 21:06:39 -0400 Received: by mail.zx2c4.com (ZX2C4 Mail Server) with ESMTP id b9c2aa66; Tue, 30 Jun 2020 00:46:55 +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=R30iPEA3kGpRlXyH+u+OY6kpV j0=; b=XEry14lBpFDbO3+ezVRNpL9Bo2UX5mK8G9Qn+ygAPlQVvzUKufbFlcwJY Wb8424JH0f9fM0EsT6GG79hJcYUG1WbWdAFGTP6Rpap2twxCL7OxMLA4TetLnQ9F 7soa6MRAV/f5kbZKVgeJpBioo1bBZHZcn2p6Z1RZa0b7tY/9PKVo4OF84NZKUg34 nNHIUwmg2ugVtueq6jyqeuJaejxKKrVb3iWYn2znoYAYtMA8xkbW/6wyq0oD6vcv C4lNzf5CSbvDQv04655VgYKeoDAR8v07fzsfcrokvsFlnfCNrspO8SxpxXlIo+Ro RXGFdhunnNQUkp0Z03T5WB+EyheVA== Received: by mail.zx2c4.com (ZX2C4 Mail Server) with ESMTPSA id 3d06bb00 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Tue, 30 Jun 2020 00:46:54 +0000 (UTC) From: "Jason A. Donenfeld" To: netdev@vger.kernel.org, davem@davemloft.net Cc: "Jason A. Donenfeld" , Hans Wippel Subject: [PATCH net v2 1/8] net: ip_tunnel: add header_ops for layer 3 devices Date: Mon, 29 Jun 2020 19:06:18 -0600 Message-Id: <20200630010625.469202-2-Jason@zx2c4.com> In-Reply-To: <20200630010625.469202-1-Jason@zx2c4.com> References: <20200630010625.469202-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 --- Changes v1->v2: - [Willem] Remove added copyright header from v1. include/net/ip_tunnels.h | 3 +++ net/ipv4/ip_tunnel_core.c | 18 ++++++++++++++++++ 2 files changed, 21 insertions(+) -- 2.27.0 Acked-by: Willem de Bruijn 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..f8b419e2475c 100644 --- a/net/ipv4/ip_tunnel_core.c +++ b/net/ipv4/ip_tunnel_core.c @@ -844,3 +844,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 Tue Jun 30 01:06:19 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: 192036 Delivered-To: patch@linaro.org Received: by 2002:a92:d244:0:0:0:0:0 with SMTP id v4csp3369442ilg; Mon, 29 Jun 2020 18:06:45 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwUV+hiqudwPa2AXqB2wky0cbddO4V6+Vau1CitzC9s8DDXvI5IU0YnBCPlnb9pLRMP0MvO X-Received: by 2002:a17:906:e299:: with SMTP id gg25mr15855222ejb.160.1593479205005; Mon, 29 Jun 2020 18:06:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1593479205; cv=none; d=google.com; s=arc-20160816; b=XGjzLvI4eZLd+DIRp5xGWC+Iq6hxYuGHInCZvMNFIYO3bgcklcAZ0ZPcEZK7ECAsKO rzCdPwGnRSe/cvqyCYc5/FgAiWWMyJUQ77/cAPKQGFRxJ0Yr5Oj2Ume1RC7tyYVFEXQw P2Fharph1nVZUz0GQ8ETy7yttD4ETmT6vqVUGLH+0MR5U9A1ydQvbVTfB3rMCkCfgc6u m6SjOsqv9CSayt2M2ZovJ0lKwZ7mi/RtvsMLXveooPs3cfLmHW3VeuIEvBVj64cWG+jx 5K3UXNGZ64Y6heNhUyoQ5U/L1EGNKUxp+H24VzBbgNCSTlUmqTbx3H+Adporg6uz/Mp0 N7uQ== 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=O1me50yZkMjTx/4a5jYTP3vIASDqShVhambMgmxo2fdUdmWXSeJGtMcFfqjcxqilXC fO23cJfF5VyybuypSwzjFRsIcbruFUn2GYnvlZI6wxdeQJcITP9oP2d026jhLJScHu9p RtEKLvP6cnujQ+NKWl4IB0VkMbH/5hGPu5OSuiaUaT/qb19n37pZVfn2K7wLzmxyjKHu H8N/kHTW7uwbEI0jzsrPvjCYX77VDvY6kRqmyNjzszusbAfissWOIenGzWE6QXyGlBv2 vv/fPx9TbshLF/8zpDh1c54Sk/+Vvd7rPE3QEwDKPOgDdXEnxq9kJYnUw1vTIK0b6+h4 3hqQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@zx2c4.com header.s=mail header.b=Q52ZVdS2; 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 d17si849269edu.223.2020.06.29.18.06.44; Mon, 29 Jun 2020 18:06:45 -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=Q52ZVdS2; 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 S1727921AbgF3BGn (ORCPT + 9 others); Mon, 29 Jun 2020 21:06:43 -0400 Received: from mail.zx2c4.com ([192.95.5.64]:60171 "EHLO mail.zx2c4.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726712AbgF3BGm (ORCPT ); Mon, 29 Jun 2020 21:06:42 -0400 Received: by mail.zx2c4.com (ZX2C4 Mail Server) with ESMTP id 0323f243; Tue, 30 Jun 2020 00:46:57 +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=Q52ZVdS2df6sLWVXiAnYvG0t1Kpkwc6tQ98PRlNuUyjRqZOMI0dyC1jzW wf6uabx7/Nv2H6FwWSkmhz8rlw/AYib89Hq/mKLOmemyK0+KsaF3ByAz4VJOuuZ6 UHU33r04I13qbC3ge5v3SSJ3AABEYD7S3TxKLkVBh3IOtHSPsrlDas1ZMJmw/+Yq zr7Dno9+plGtZmtD8A2FlPxjl/lqAlx0e2YPoosqz0vOB1OD8OVcfvNnYNI/pX1W BA7ralk6oQ9OLkRtLf5acoqD2h7kWO3UVRPvr+1ByF/VWIcXy+HHqLBzKm9zHsAL UXeLoaGZ32LDgBBjEO/RpsRTWQSCQ== Received: by mail.zx2c4.com (ZX2C4 Mail Server) with ESMTPSA id 9353f973 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Tue, 30 Jun 2020 00:46:56 +0000 (UTC) From: "Jason A. Donenfeld" To: netdev@vger.kernel.org, davem@davemloft.net Cc: "Jason A. Donenfeld" , Hans Wippel Subject: [PATCH net v2 2/8] net: ipip: implement header_ops->parse_protocol for AF_PACKET Date: Mon, 29 Jun 2020 19:06:19 -0600 Message-Id: <20200630010625.469202-3-Jason@zx2c4.com> In-Reply-To: <20200630010625.469202-1-Jason@zx2c4.com> References: <20200630010625.469202-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 Acked-by: Willem de Bruijn 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 Tue Jun 30 01:06:20 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: 192037 Delivered-To: patch@linaro.org Received: by 2002:a92:d244:0:0:0:0:0 with SMTP id v4csp3369487ilg; Mon, 29 Jun 2020 18:06:48 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyL6uWBWLAHWcJiMzVk3w93gIk2Sx7IfxSQvERoPsHiCX9Qdn1RJX2jvB9LWmVrWY4CfN4x X-Received: by 2002:a50:b065:: with SMTP id i92mr21664451edd.112.1593479207963; Mon, 29 Jun 2020 18:06:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1593479207; cv=none; d=google.com; s=arc-20160816; b=Ku5/jAPs/UWJuMWdymmHQu84Y0WHflNHX7tj/3D+6vJe5X+H1aLPm0toXfSwNhQHS8 c9ROj329s+4sutbMuYO2fJ+Cjnu9MyleA9OkdMQkPKw77FKjwVuMmmLV+KNeWLXVpbt5 hr1yi5Cq13jaKA/QNT5QdfSpR01G0ZoTQ9YRDlXPMhdWYMG+Yu3IT3+DF1OzmY+3+J56 Xm3YMvgL3Fo2HbHC1lPq2Uh78ZQNsVRCFiO4hLvdRazZqS2mYwekxJbup+jpUy7LkZPq rB7rTizFCL7L/WvooUtRpVfUwlRxu/F277tesGs+Isw7WjzbtpiocqL2lsvC9drQwt0k 2Dig== 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=q5uLu9q/M74YcP4Stt3qJWw10AeuRcgRj2LfR7JruLjGb4NCyrixWzOpCXc6B6dSZM ZHnhFjsLf1/0P/wa+VB9EbPwFdEIspuNLkAAQffe7VdYd/u6Tw/MP3CSfWljPbK8rALo 0UpN5fjeqiCsNJz3J6xoN57VejrgI7PlKO9LqK3YPrdbjXkB6AjOjuX4vuW89cjNLakH xbI72hzrqZ0K0fQLpom3WB3UEzHW8MspAGJpJaqG+3SQIYLGj6CVxufOOnMighar7Ly+ BBL6kCNQg78ERPCqZ8XZrnAfQoaUQbOzrUG4ctFF1oKIAxnuhbdFlRfeJ4VEsKhhMyEU XgWw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@zx2c4.com header.s=mail header.b=nwPcNe37; 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 d17si849269edu.223.2020.06.29.18.06.47; Mon, 29 Jun 2020 18:06:47 -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=nwPcNe37; 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 S1727863AbgF3BGr (ORCPT + 9 others); Mon, 29 Jun 2020 21:06:47 -0400 Received: from mail.zx2c4.com ([192.95.5.64]:60171 "EHLO mail.zx2c4.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727780AbgF3BGn (ORCPT ); Mon, 29 Jun 2020 21:06:43 -0400 Received: by mail.zx2c4.com (ZX2C4 Mail Server) with ESMTP id 4290374f; Tue, 30 Jun 2020 00:46:58 +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=nwPcNe37L5CN62lr+nhaWqiTbDSySqUdWEqRGfqa7qfLiEoj+2iNc25uH 4G2lHP9P8wtVYvDIqcF41KEh6HvjdqHDfF52zsaWlBpITLFTKeN1V5qsmJK8Qul2 b75dR6w1XC+bbGHbze8x/otYgPEg+adx0tudhYYDeQ5Sd9biHhNe+MF776FzVB0/ T6+E7VVJVTK87eRteL9cogaw93KkM9U1buDKSd3OIhP3j9dWfMdMiWQ/e0QNGOrz RHqjFA/OclAmuW5KIzFTu1g6YyhWSg8M2xqQwC3cYc/7sbclr3r2D6t8GIWewnxT yt5XwnW890pUouVD3thFDARN5GuBA== Received: by mail.zx2c4.com (ZX2C4 Mail Server) with ESMTPSA id 89153989 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Tue, 30 Jun 2020 00:46:57 +0000 (UTC) From: "Jason A. Donenfeld" To: netdev@vger.kernel.org, davem@davemloft.net Cc: "Jason A. Donenfeld" , Hans Wippel Subject: [PATCH net v2 3/8] wireguard: implement header_ops->parse_protocol for AF_PACKET Date: Mon, 29 Jun 2020 19:06:20 -0600 Message-Id: <20200630010625.469202-4-Jason@zx2c4.com> In-Reply-To: <20200630010625.469202-1-Jason@zx2c4.com> References: <20200630010625.469202-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 Tue Jun 30 01:06:21 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: 192038 Delivered-To: patch@linaro.org Received: by 2002:a92:d244:0:0:0:0:0 with SMTP id v4csp3369509ilg; Mon, 29 Jun 2020 18:06:49 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzcv9GINArGyy3pnq5fPAPh0ELsb71JCjwdBJ+0vh9cwznZ2yjkQEn8I2yY4D0pQizxxdBd X-Received: by 2002:aa7:db57:: with SMTP id n23mr20160433edt.235.1593479209312; Mon, 29 Jun 2020 18:06:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1593479209; cv=none; d=google.com; s=arc-20160816; b=HY0E73lIA6TFp+W3kB+Z9en19mO6e5vVP97+IiYmK5hT66RXWuvvTlTWMOkDa1JuL6 5lpeA2wx1yoTCXtLMxUBmdtrZbnscKqFX4A9+mboCnCUjSSbQgZ74p1zkDZ4akyHmyTX zfIFZ2RGn45ytF73F9nkS3ubilyRC1O/3WLlS8O50qTOLDBcWpdX6rq+uo5apuDMvWBd hoxvsG2QQsT46V5LqyDqVNHsOVH3zoBNRIPuAYQgucf2WDK5ktpdQ0VrMbwLc0lS8qQS MQLh5J09weSFCda+mNaBCNhJ6SCiFl+8EmIeTezcw2gfo/TBBHYCmHD1jnZl4dMYfrp/ WG9w== 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=rhyBmVk7DOIM+w6dR+1mtIeveqLd0w3BJyRQV9JVItqtAC7D+WsRxmBHPTp8WOQzlS VhLzA31QdQHTq+Pcx37cmY3mFzxZtMuxRkJD8hrBDbakw9rzRhOrPR9PoXGFK8NlIShr 8jYhP7oFwf6ZFTGUoBw9XQp6GIWhQn0y+7CmQaQllY57pzHUB57PFvRKeBmUitFaZbGk lsMFqcJAnSKCvRb7CfXSdcrKnKidy0CdKFy3R06Vs24EGinhHJN8AO63xopHJH+Pto+y VoE+ZN2AvpgZT1oFTGIo4LspYGoI/PnaG9nEnriKYhSP1MJcVAjaUHsUh30e5rB+VJY8 NkEw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@zx2c4.com header.s=mail header.b=ZLiZhqeF; 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 d17si849269edu.223.2020.06.29.18.06.49; Mon, 29 Jun 2020 18:06:49 -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=ZLiZhqeF; 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 S1728071AbgF3BGs (ORCPT + 9 others); Mon, 29 Jun 2020 21:06:48 -0400 Received: from mail.zx2c4.com ([192.95.5.64]:60171 "EHLO mail.zx2c4.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728002AbgF3BGo (ORCPT ); Mon, 29 Jun 2020 21:06:44 -0400 Received: by mail.zx2c4.com (ZX2C4 Mail Server) with ESMTP id bef50b85; Tue, 30 Jun 2020 00:46:59 +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=ZLiZhqeFSg8qWscgoLPL/k+jTUteh5vV7+UPEnqrHZr7uz/OrMHHQQ4on GR8XUG3avxiLesNm797RrjS96R3lpLOMoUVEqoEJb6H1QoFolyXZaD/jUPqI1SQA dAtH3J89EV00cHIiUiHAfJIGG+lwTMBNcLCWQpEn2f0v8N54tfgXQ1jCtVYIXvVD aN5HsSvj3z1c4y9N7i8FIx1iBaUWOxrQDTtANB0Ty/BFxdRyTfPHnmR/yAsH5MQj 4SMvDTqwcwqf854fca8SO6hG9jrD6F4uwsdfMmGo6ExUQu4FeiF6oFUD9SmUfmk5 6fVP/KI6RO+kfoOMpZqoLGbQhUzSQ== Received: by mail.zx2c4.com (ZX2C4 Mail Server) with ESMTPSA id 1ffb52d8 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Tue, 30 Jun 2020 00:46:58 +0000 (UTC) From: "Jason A. Donenfeld" To: netdev@vger.kernel.org, davem@davemloft.net Cc: "Jason A. Donenfeld" , Hans Wippel Subject: [PATCH net v2 4/8] wireguard: queueing: make use of ip_tunnel_parse_protocol Date: Mon, 29 Jun 2020 19:06:21 -0600 Message-Id: <20200630010625.469202-5-Jason@zx2c4.com> In-Reply-To: <20200630010625.469202-1-Jason@zx2c4.com> References: <20200630010625.469202-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 Tue Jun 30 01:06:22 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: 192040 Delivered-To: patch@linaro.org Received: by 2002:a92:d244:0:0:0:0:0 with SMTP id v4csp3369552ilg; Mon, 29 Jun 2020 18:06:53 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzBL0Vg49RR5mznxnWM0zG3NFHn0TFofkCPWt/SbL79s9zSAxeEzt9dkKkCzy97JSyYWuWs X-Received: by 2002:a50:d8c2:: with SMTP id y2mr12593103edj.114.1593479213505; Mon, 29 Jun 2020 18:06:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1593479213; cv=none; d=google.com; s=arc-20160816; b=pDqYOn2Kp9mkxo0i0xA8k3IO9dDNyNbtcAswTdlMmXYi+vK9zkQeNcizU/6VJwJc3m 6ot5wjcxteiq5oJ+5YAbOHoVgLC6//ebB1cm6TJgq9lpvUj0kQBU1gCSFxBEFpJFAcuk XCNUBGJWfswLkKRMlrhINYvWXKRpgKol6awcUrKFj+5yzzLjQYJg7m7u7sXAZi+KBQQh npMuHN+/mkwid7mghOqx9Gp3SXatTaPgphatbTYSPgKiYACTDnFVrOk11/49P5TOR+jw Vz+WSWK9UwKpaQGeYSVTcG+MEIkPmMB80eJS69IqcjqiJMHpE54BbRwU5ZiFSEoUiQNC IgWg== 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=XNzFU6OpMmBp5T3OWFxdbUiH/Dc9ZhwhGOCp6vmelFRRuYbnkwIO5P0U1F0cuc+bAQ 8KGnJWoZfkML0KNNRW21VI6P6yR50cNcVSfCC/OoG6xou0GjCeUxQbXkIQzl3S9TyA+I OPqJMpwXWvljFFRm9vkUNMBGrQlJA+uEuQYFZtDokpQPAKfuQUewuVBQO79aU0xJcwqU /QwvlkQnA2VckgY+grrWAQRjI5mamkWvnYA7DDsuurJxXcHMEzlJz8NlsKhi8uyRM7qK ZAmYl8uQH2ULWnEnrn+oJfCTIoh3ccZu7vc2m6y7CDnerw8y4OIRIBFaV+LgYOR+7Zno 1vDg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@zx2c4.com header.s=mail header.b=TLrlpmwa; 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 d17si849269edu.223.2020.06.29.18.06.53; Mon, 29 Jun 2020 18:06:53 -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=TLrlpmwa; 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 S1728142AbgF3BGw (ORCPT + 9 others); Mon, 29 Jun 2020 21:06:52 -0400 Received: from mail.zx2c4.com ([192.95.5.64]:60171 "EHLO mail.zx2c4.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728024AbgF3BGp (ORCPT ); Mon, 29 Jun 2020 21:06:45 -0400 Received: by mail.zx2c4.com (ZX2C4 Mail Server) with ESMTP id e00a5875; Tue, 30 Jun 2020 00:47:01 +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=TLrlpmwaTRb9+gAnZoo7lj3ktt+WOh3dfJLrxQ0tZCHikMcQktsTZKL4D VwXy59ZAnPCXP+xnvTrBnwtwfRW3M80+KMwO2Y1prKw0kq2sJmw6jeTI/26XUKBJ GUlvrzwlww9JJKrcoBeGDfo6CObNpqtaCQA82jVbXvb4131zHxWXtXv0VICDWPXh I1/zRq/X4imqDTz0DTic3IvMfqSr6dkluYAME0EZpPgY2hqfKic+UqeVzffBTaYz qdVHIwE3D1XS2GY/V43wEYLrPe3NJnnalYyzl5sne07OY+/0uEhRLnJ/VFg1fajE t7rFoFZYjz3/J6IfgrpUHfAJvIqng== Received: by mail.zx2c4.com (ZX2C4 Mail Server) with ESMTPSA id 35fbf544 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Tue, 30 Jun 2020 00:47:00 +0000 (UTC) From: "Jason A. Donenfeld" To: netdev@vger.kernel.org, davem@davemloft.net Cc: "Jason A. Donenfeld" , Hans Wippel Subject: [PATCH net v2 5/8] tun: implement header_ops->parse_protocol for AF_PACKET Date: Mon, 29 Jun 2020 19:06:22 -0600 Message-Id: <20200630010625.469202-6-Jason@zx2c4.com> In-Reply-To: <20200630010625.469202-1-Jason@zx2c4.com> References: <20200630010625.469202-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; From patchwork Tue Jun 30 01:06:23 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: 192039 Delivered-To: patch@linaro.org Received: by 2002:a92:d244:0:0:0:0:0 with SMTP id v4csp3369534ilg; Mon, 29 Jun 2020 18:06:52 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxTsCUFhMKMZydPAUbZaemzhmoP0A4bNcDkPcqBRgpcc1/qJizaThHlN2Dg40Jfp54ccNYt X-Received: by 2002:a17:906:b45:: with SMTP id v5mr15823787ejg.464.1593479211974; Mon, 29 Jun 2020 18:06:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1593479211; cv=none; d=google.com; s=arc-20160816; b=iiEksRtqWPMLFb2U4ZCPwvLYNCgXIKJM8duCdGF/6aJVyreFX0+6/7LIZHavpKrFA3 6nEJ+g108Qlkp34WPuvi9Up4W0Sci/YwP+ItRiM+75R1Yv1BJjB9oy54XWHtFMuVH8aU nCglEOKLDmZXTjKFcB3F8gkg8OSy81xQ9qayxOjNdnnS4HwQd1YLotH6zNy3ugv3IL/P ZhOtn7lP/qKruyx62pZlU1M3LkJmEsfFAGkNsJ3o64CvN8uFFuy5Vq2MTAP2WcbOAOiE NuLLY4h3cnhswW43IA8sxeFe5xT24jzATDZHKDWWyne4jHqn2VN97cEzqldbMDn09HiM va+w== 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=I8jhAw1C48W3klydTEg2q9rxPa/43f6yYo0iZ4Sjjkk=; b=XycXybo1LKgDawYdo0rBY4OX1zaFiOJ7bbB+Lr8Ms1KK+4DzoBXkdOuwYlBhxc1FaP gvLTufTdRvtbjOjrVFGdsj0N4yn4k53NBxOYOnD6JgBAJ72oCQv0HblkERUUcJxkzwP7 9xHd6xpx4MiHZPMFYhrlbju39pCUXNAJRdUdrKj9Iov8VA32CdEs0ungFOpYtC2T0PXM XesKcNL/P+jrAKFSZsuyNe+q7tFLuNXvJU8+aajegRt3aaNPAdmWszE1H2vxRIIjSAEb Cl1ff1CpvjgF8jgB7fmTblaWGjswq2+2bZgB4GSOPJ/i9X/J69b2u1meUs+y4BwkqnNm HYbA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@zx2c4.com header.s=mail header.b=zKuKVmZ4; 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 d17si849269edu.223.2020.06.29.18.06.51; Mon, 29 Jun 2020 18:06:51 -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=zKuKVmZ4; 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 S1728116AbgF3BGu (ORCPT + 9 others); Mon, 29 Jun 2020 21:06:50 -0400 Received: from mail.zx2c4.com ([192.95.5.64]:60171 "EHLO mail.zx2c4.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727780AbgF3BGr (ORCPT ); Mon, 29 Jun 2020 21:06:47 -0400 Received: by mail.zx2c4.com (ZX2C4 Mail Server) with ESMTP id 5e605d44; Tue, 30 Jun 2020 00:47:02 +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=Fi3F3RTKj50aJq3o7a+r71FKJ OQ=; b=zKuKVmZ4EIvXtJvV2PO6NY1kmkaa8KuqG1oF3iKDzaWCminGCzIHSpvQf ie9rjShsJ04k5TozrFyTcJZ5D7EgMndgkAQxNXh1qMplsfNw8fSIPOQJCyN+lsqY 9ZUxY6vBGgbeMrytfU1My6/ogaqk2LtrdGvdJsqSsCCVfqPCCrMUX2AkNOhtpoW6 RqP9A7npwU1FlilC6rs2zu9OtP1/xUMPwKSDvZOBJw5icELON8vvxhGasf9jYftC sMIy5Zm4ViG4eg/mx0ivrYQ8V4lrKX7r2NIBXeEKHnBAUzj4gQ6yfHHfsaOSu6tg OvAwc8JcOJDZxoBNC4DZCdZPjNHsQ== Received: by mail.zx2c4.com (ZX2C4 Mail Server) with ESMTPSA id b6d6483f (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Tue, 30 Jun 2020 00:47:01 +0000 (UTC) From: "Jason A. Donenfeld" To: netdev@vger.kernel.org, davem@davemloft.net Cc: "Jason A. Donenfeld" , Hans Wippel Subject: [PATCH net v2 6/8] net: vti: implement header_ops->parse_protocol for AF_PACKET Date: Mon, 29 Jun 2020 19:06:23 -0600 Message-Id: <20200630010625.469202-7-Jason@zx2c4.com> In-Reply-To: <20200630010625.469202-1-Jason@zx2c4.com> References: <20200630010625.469202-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 Vti 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 vti 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/ip_vti.c | 1 + net/ipv6/ip6_vti.c | 1 + 2 files changed, 2 insertions(+) -- 2.27.0 diff --git a/net/ipv4/ip_vti.c b/net/ipv4/ip_vti.c index 1d9c8cff5ac3..460ca1099e8a 100644 --- a/net/ipv4/ip_vti.c +++ b/net/ipv4/ip_vti.c @@ -441,6 +441,7 @@ static const struct net_device_ops vti_netdev_ops = { static void vti_tunnel_setup(struct net_device *dev) { dev->netdev_ops = &vti_netdev_ops; + dev->header_ops = &ip_tunnel_header_ops; dev->type = ARPHRD_TUNNEL; ip_tunnel_setup(dev, vti_net_id); } diff --git a/net/ipv6/ip6_vti.c b/net/ipv6/ip6_vti.c index 1147f647b9a0..0d964160a9dd 100644 --- a/net/ipv6/ip6_vti.c +++ b/net/ipv6/ip6_vti.c @@ -905,6 +905,7 @@ static const struct net_device_ops vti6_netdev_ops = { static void vti6_dev_setup(struct net_device *dev) { dev->netdev_ops = &vti6_netdev_ops; + dev->header_ops = &ip_tunnel_header_ops; dev->needs_free_netdev = true; dev->priv_destructor = vti6_dev_free; From patchwork Tue Jun 30 01:06:24 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: 192042 Delivered-To: patch@linaro.org Received: by 2002:a92:d244:0:0:0:0:0 with SMTP id v4csp3369638ilg; Mon, 29 Jun 2020 18:06:59 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwlQ1K4EEpWaTc1rKM5LRxPrdAT+h7qe7ORDAles+74uj9ailvwwc0u9W/IPB4HUlfLaKsG X-Received: by 2002:a17:906:dbe5:: with SMTP id yd5mr16515199ejb.328.1593479219248; Mon, 29 Jun 2020 18:06:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1593479219; cv=none; d=google.com; s=arc-20160816; b=HzLwWskhftZhmsmGN2Vj1A8AbQPQ+C+VW26q0g/N1bSDg1PjhwTHI1ujFMk6BgKs/i LslhqnVUrSy35G12H60DfATVN7Kwu5f4+eiw/C1KdZLvs6B9G1NcZRzMrxCu3+I6uGpl lfrWtajsOFDSoJS1nloX+E3c+PxDbC2spxxSU917vRC8uaWtrs9QERtyxhwNVTklSKfS 3AS8UexkBuyLDkAMmMry1XGBQ0sk/PCrIPAwOlBjJxmiP22HrN6M53LfbXygAcLVHY9T ZZSGD94GSEkCC42Z88mkXoUOAoUolF5aC0SVDUjq8YR2vXxu4JSXF1wIMRiulXZWI9jI hikw== 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=FBfHJDhXp2F9ZJzGtf+GpIVUbU+Vj14G7RQYJ5uW2TU=; b=HS6Gv5kd1FxdPRECtDfThkOF6gEaCVfi3j4aE7FTYIVB6a1AbktO6hULbz2wTTt+dO TFzqQher8jouQ6KnJOOC8YwEipaJEZVmNB7Y4uwEkJsSmw2tl7gUoPd9zb0dXWJUI2lX nASvXdroJPyQu/17C/yK31kSaEzLhLAxKzaelaJyufbuf7fXtR6nN1RTSipVRWJuQ2r2 rLjaRAgfDs2rVhBD+Pc5n0/53d9005e9YO7SgX6ZFxzpanKMeyOhryq1/psOAfbTO/oq IATBMNyestRkzD97TwpBx2yjXwutI464lKEKQKCTzYkFWn97H6/DNIb7x+/UmJ783mxU tUZA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@zx2c4.com header.s=mail header.b=RGb76Hs+; 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 d17si849269edu.223.2020.06.29.18.06.59; Mon, 29 Jun 2020 18:06:59 -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=RGb76Hs+; 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 S1728164AbgF3BG6 (ORCPT + 9 others); Mon, 29 Jun 2020 21:06:58 -0400 Received: from mail.zx2c4.com ([192.95.5.64]:60171 "EHLO mail.zx2c4.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728002AbgF3BGt (ORCPT ); Mon, 29 Jun 2020 21:06:49 -0400 Received: by mail.zx2c4.com (ZX2C4 Mail Server) with ESMTP id 9a11897b; Tue, 30 Jun 2020 00:47: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=A0lWy9h3jqc1a7KNAk9VRzVMi Yo=; b=RGb76Hs+stzcpM6Cm3qD56ZvWNFk3f9dZcsx92Q29Tj5kV+uppfxIv94b w1PwC8r8ar6tePQD97SNREOHcPs/FndQ6VaDvAshGEz/+y58px5TV+Ffka7Mfq6f MC4vgNC3kukh6Z6OrTMuIBj7BAnogbwc2iBXucjZkARU90SQZA/giM1s04cVI1/X 9RtnbkQh23lqBAnwewf3yHncs8yV0F7KcGFiVXQmhBPK/Ho5kU5DJWakOm7rVxPj fh44FEqyQZXH1xynzLj3wDCcDAPW1+3IjNFi9q7EzkolZRt/2JmzhRg0xldyZSY8 r5cy93m7QmyIoLwrLxEjr1614OuMw== Received: by mail.zx2c4.com (ZX2C4 Mail Server) with ESMTPSA id e95283e4 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Tue, 30 Jun 2020 00:47:02 +0000 (UTC) From: "Jason A. Donenfeld" To: netdev@vger.kernel.org, davem@davemloft.net Cc: "Jason A. Donenfeld" , Hans Wippel , Willem de Bruijn Subject: [PATCH net v2 7/8] net: sit: implement header_ops->parse_protocol for AF_PACKET Date: Mon, 29 Jun 2020 19:06:24 -0600 Message-Id: <20200630010625.469202-8-Jason@zx2c4.com> In-Reply-To: <20200630010625.469202-1-Jason@zx2c4.com> References: <20200630010625.469202-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 Sit 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 sit rejects the skb. So, this wires up the ip_tunnel handler for layer 3 packets for that case. Reported-by: Willem de Bruijn Signed-off-by: Jason A. Donenfeld --- net/ipv6/sit.c | 1 + 1 file changed, 1 insertion(+) -- 2.27.0 diff --git a/net/ipv6/sit.c b/net/ipv6/sit.c index 1fbb4dfbb191..5e2c34c0ac97 100644 --- a/net/ipv6/sit.c +++ b/net/ipv6/sit.c @@ -1421,6 +1421,7 @@ static void ipip6_tunnel_setup(struct net_device *dev) int t_hlen = tunnel->hlen + sizeof(struct iphdr); dev->netdev_ops = &ipip6_netdev_ops; + dev->header_ops = &ip_tunnel_header_ops; dev->needs_free_netdev = true; dev->priv_destructor = ipip6_dev_free; From patchwork Tue Jun 30 01:06:25 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: 192041 Delivered-To: patch@linaro.org Received: by 2002:a92:d244:0:0:0:0:0 with SMTP id v4csp3369600ilg; Mon, 29 Jun 2020 18:06:56 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxh/WjeLNQluZs/0W//A9SUA/DH8dgES8hJBOXdMAEVZUi90XL9vz4wDIhMgfM7vo5ODbB8 X-Received: by 2002:a17:907:7290:: with SMTP id dt16mr15830893ejc.63.1593479216790; Mon, 29 Jun 2020 18:06:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1593479216; cv=none; d=google.com; s=arc-20160816; b=w7mQ7RqAsEoGrRNYhDRJ4+UooxKIzddTZTafLJgMOY8d4OBrgaW3Ll6TWAuUnO6HG9 lLr3ipRFGtuctuBOm68uKbwjnKgP+QTKCbC/J/BOEh3z7o1wona2L0POQKy+WvlH/UxS romZKKeQNy2IkSs/rKeE8ABP3XjnfPHa2lWVofYiqlpvAbxFmGmCorGhMpb7hBaD+0AD Fx3gbKs6E0kF+TF1WAkI0GvYqVTR6Sz6wsgS/Es2vJB+PmyFB8WcnW08uHcDEg+PPsOp 0jpuQlIk4PQc7sGnyQ6Fd5W5JABRs4Fp1X+dkJhE/jmH6f8V7WiG44t1NBNq9PA7u1Ws 17SA== 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=CYVeM0VGgK2O51gjZogDnpe9MrghVt+D6sBtn2W8no0=; b=ZCB2nBlBfW2Hipbeeujt8QkWPp+l+Xnvhc+VkvnfmcQBBJXoom3V3s5KrsvG6hB+j/ cau+SkLtOKaxbXUggtwnZD10bhCZD5f+HrvbHM+qFhR574yI0i4l0TbYZ0iupZxT1BJi VvAOJS0viXpW3vsaKBGjw82KeI4P+jSVKz5f9u+3cCxMDvAPQjw8npS1pXzCJGkgLnmM KMYgcMQMOmmXfiLMQq+s6z5OUJ17meHaXLAHb/bYr6K1tDk2sMuGZBO6gkbHwOVfS3/O WfVn6tfpHvwM9DpAPXGH7t7/laA27DLclsN3/8EjdddkQQHr8CFvLAg59GjVyZsBPG1g X5Lg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@zx2c4.com header.s=mail header.b=E1BIat3K; 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 d17si849269edu.223.2020.06.29.18.06.56; Mon, 29 Jun 2020 18:06:56 -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=E1BIat3K; 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 S1728156AbgF3BGy (ORCPT + 9 others); Mon, 29 Jun 2020 21:06:54 -0400 Received: from mail.zx2c4.com ([192.95.5.64]:60171 "EHLO mail.zx2c4.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728126AbgF3BGw (ORCPT ); Mon, 29 Jun 2020 21:06:52 -0400 Received: by mail.zx2c4.com (ZX2C4 Mail Server) with ESMTP id 0907e8c1; Tue, 30 Jun 2020 00:47: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=Xmy6YQJ23F4/CDIjrR9nvLnBL T8=; b=E1BIat3KtHtdKTksZkvYg+PDN33dnMfbh0VKPugk3LYYV3tIA0K1PqwQQ dvajTKXueWFSyDfmJQfsxJO5md7rI/zKUMxMlgncZow4jsTl2m97zOiVrz4dD9f2 YSnKsFTyUij4Uo603KgmbVkZg9Pso2n0+P1vhpTdsqjLQ8JCmSi8L2vN2d9pmgvK uh5XMqV3UHrtJMt81AsArrB1WxZ5ueVxLZCte/4pCLVjfbY8AFOW67e8rf3t0Jkp E3MtLMUfNg42Lo6dC6RrP2h2HLQCuYjLv160KUp0l9opYTJ6fFg8SigarvPBOd3R 7bltHQBon1n8Dz2MgdbpCzW0NgvcQ== Received: by mail.zx2c4.com (ZX2C4 Mail Server) with ESMTPSA id d98247d1 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Tue, 30 Jun 2020 00:47:04 +0000 (UTC) From: "Jason A. Donenfeld" To: netdev@vger.kernel.org, davem@davemloft.net Cc: "Jason A. Donenfeld" , Hans Wippel , Willem de Bruijn Subject: [PATCH net v2 8/8] net: xfrmi: implement header_ops->parse_protocol for AF_PACKET Date: Mon, 29 Jun 2020 19:06:25 -0600 Message-Id: <20200630010625.469202-9-Jason@zx2c4.com> In-Reply-To: <20200630010625.469202-1-Jason@zx2c4.com> References: <20200630010625.469202-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 xfrm interface 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 xfrmi rejects the skb. So, this wires up the ip_tunnel handler for layer 3 packets for that case. Reported-by: Willem de Bruijn Signed-off-by: Jason A. Donenfeld --- net/xfrm/xfrm_interface.c | 2 ++ 1 file changed, 2 insertions(+) -- 2.27.0 diff --git a/net/xfrm/xfrm_interface.c b/net/xfrm/xfrm_interface.c index c407ecbc5d46..b615729812e5 100644 --- a/net/xfrm/xfrm_interface.c +++ b/net/xfrm/xfrm_interface.c @@ -37,6 +37,7 @@ #include #include #include +#include #include #include #include @@ -581,6 +582,7 @@ static const struct net_device_ops xfrmi_netdev_ops = { static void xfrmi_dev_setup(struct net_device *dev) { dev->netdev_ops = &xfrmi_netdev_ops; + dev->header_ops = &ip_tunnel_header_ops; dev->type = ARPHRD_NONE; dev->mtu = ETH_DATA_LEN; dev->min_mtu = ETH_MIN_MTU;