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: 1319444 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=XEry14lB; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by ozlabs.org (Postfix) with ESMTP id 49wmQp1XVwz9sQx for ; Tue, 30 Jun 2020 11:06:42 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727771AbgF3BGl (ORCPT ); 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 Acked-by: Willem de Bruijn --- 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(+) 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: 1319445 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=Q52ZVdS2; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by ozlabs.org (Postfix) with ESMTP id 49wmQr50LPz9sQx for ; Tue, 30 Jun 2020 11:06:44 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727921AbgF3BGn (ORCPT ); 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 Acked-by: Willem de Bruijn --- 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 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: 1319446 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=nwPcNe37; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by ozlabs.org (Postfix) with ESMTP id 49wmQv5xl1z9sQx for ; Tue, 30 Jun 2020 11:06:47 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727863AbgF3BGr (ORCPT ); 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(+) 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: 1319447 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=ZLiZhqeF; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by ozlabs.org (Postfix) with ESMTP id 49wmQx1DLWz9sQx for ; Tue, 30 Jun 2020 11:06:49 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728071AbgF3BGs (ORCPT ); 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(-) 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: 1319449 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=TLrlpmwa; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by ozlabs.org (Postfix) with ESMTP id 49wmR12lrdz9sRk for ; Tue, 30 Jun 2020 11:06:53 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728142AbgF3BGw (ORCPT ); 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(+) 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: 1319448 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=zKuKVmZ4; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by ozlabs.org (Postfix) with ESMTP id 49wmQz5twgz9sRk for ; Tue, 30 Jun 2020 11:06:51 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728116AbgF3BGu (ORCPT ); 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(+) 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: 1319451 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=RGb76Hs+; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by ozlabs.org (Postfix) with ESMTP id 49wmR70vdDz9sQx for ; Tue, 30 Jun 2020 11:06:59 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728164AbgF3BG6 (ORCPT ); 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(+) 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: 1319450 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=E1BIat3K; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by ozlabs.org (Postfix) with ESMTP id 49wmR44mspz9sQx for ; Tue, 30 Jun 2020 11:06:56 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728156AbgF3BGy (ORCPT ); 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(+) 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;