Received: by 2002:a25:e74b:0:0:0:0:0 with SMTP id e72csp238987ybh; Sat, 18 Jul 2020 02:25:24 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxD4MtOw7H9RT4v5GM2FWqbXMuR3o85QyHN+/XEydX69RzAzSDKduNnLg7FuI7PKGtI1cGu X-Received: by 2002:a50:f187:: with SMTP id x7mr12431218edl.59.1595064323945; Sat, 18 Jul 2020 02:25:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1595064323; cv=none; d=google.com; s=arc-20160816; b=YxDzF4xQrcvXjUBRhOnRqIlXAEQkOYRea+EOp/xkjY79y4tg07C/PjbgARkL8524xH P5uXIbbwhU1DRO8VCn4C4bRyWjsYHXxp0U6uEycM987aZddnwZyuE6VDLU1uiYH9HLMr TjF3zYFLfk8jjoonyk43sFIc1lwfYLUtGNqceVUtiK5g6vrmuvf3LoZZXXovhCeP7v4O Mp5wsQ85rooFwpWC1e0nJv3Dx7ecj0UmrKaVRj/VKpKjzgPr7+g7ym38Re7Q47T1O2vS YGJVXE7nIC/zNKMXjCXvz/tHqNUWq81U60S2tRFiwEToGxkt5dR/Ngi+/V/zBp41vzB9 QbuA== 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 :message-id:date:subject:cc:to:from:dkim-signature; bh=WrTDZIQ+NOpWbn+NLnY4D3XbxZUCHFw2be6ChB52JI8=; b=o0i0cv0I1FvBYkeCwv3uGWyEaKsrLEmLNZzQbyPsNE3W5d8Z3FSIi8FsRpTgYM1Alc viCaVdA/XMvZLTNjUuikoiyz//L8cVf25SzMIRFCLaLUXF/3ds7F0kpVKzqygK2jLEu9 m6MbMJVhSnniUT4ClOVWXB027j2VLi5+3c82aA9TqVpcG9pIcTFSCBI2UzBJ1TLceE0L tI77AI+oLKO05PVDnUYrBHNFeDnuA0Uz5l1dqZh5R4QFonDCnQcXUvtmCi4rK4zMd9kq jjuy8vju/fTKDR1hAetCFziU5qHCdYg/ymXltt1JL44bmbGiA5Q5ccAIeHBaTVubI/rJ xOqA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@cisco.com header.s=iport header.b=XtU7NVYq; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=cisco.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id c13si6959190edw.351.2020.07.18.02.25.01; Sat, 18 Jul 2020 02:25:23 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-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=@cisco.com header.s=iport header.b=XtU7NVYq; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=cisco.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726392AbgGRJYu (ORCPT + 99 others); Sat, 18 Jul 2020 05:24:50 -0400 Received: from bgl-iport-2.cisco.com ([72.163.197.26]:17572 "EHLO bgl-iport-2.cisco.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726179AbgGRJYt (ORCPT ); Sat, 18 Jul 2020 05:24:49 -0400 X-Greylist: delayed 431 seconds by postgrey-1.27 at vger.kernel.org; Sat, 18 Jul 2020 05:24:48 EDT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=cisco.com; i=@cisco.com; l=1947; q=dns/txt; s=iport; t=1595064289; x=1596273889; h=from:to:cc:subject:date:message-id:mime-version: content-transfer-encoding; bh=WXHweetNurO6QLaPH79F1tHWP4XFhUThgJN70Mv6QcA=; b=XtU7NVYqgDzjQBgcBZ/BwrL9bvjzqXxUXRmjaz1LJpZ3AUxQ90unVzsk yYIbUxoVk8e1D7aZDPyIQ7T3fzVFcqoaP3bYI12KJ2wIGGOwQ3Oqy2GC9 iQfVKKN2md+Jixmf3utA5VBdSKYNUSkA9nQLT3C6xn6ICT0JdPgZv7vra Q=; X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: =?us-ascii?q?A0CMAABtvRJf/xjFo0hgHQEBAQEJARIBB?= =?us-ascii?q?QUBgXgGAQsBg2wBIBIsjTSGTAEBAQEBAQaLSI97gX0LAQEBDi8EAQGETIIcJTY?= =?us-ascii?q?HDgIQAQEFAQEBAgEGBG2FZ4YdCwFGKYEVCwiDJoJYJak9gXUziH6BQBSBJAGIA?= =?us-ascii?q?oYCgQePEgSBQwGZbZoWBoJhmVQPIZ9ILbB7gVoJKoFXTSOBboFLUBkNjioXjiw?= =?us-ascii?q?5AzA3AgYIAQEDCY8lAQE?= X-IronPort-AV: E=Sophos;i="5.75,366,1589241600"; d="scan'208";a="156060473" Received: from vla196-nat.cisco.com (HELO bgl-core-2.cisco.com) ([72.163.197.24]) by bgl-iport-2.cisco.com with ESMTP/TLS/DHE-RSA-SEED-SHA; 18 Jul 2020 09:17:33 +0000 Received: from SRIRAKR2-M-R0A8.cisco.com ([10.65.75.112]) by bgl-core-2.cisco.com (8.15.2/8.15.2) with ESMTP id 06I9HWXw006124; Sat, 18 Jul 2020 09:17:32 GMT From: Sriram Krishnan To: Andrew Morton Cc: xe-linux-external@cisco.com, "David S. Miller" , Jakub Kicinski , netdev@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v2] AF_PACKET doesnt strip VLAN information Date: Sat, 18 Jul 2020 14:47:31 +0530 Message-Id: <20200718091732.8761-1-srirakr2@cisco.com> X-Mailer: git-send-email 2.24.0 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Auto-Response-Suppress: DR, OOF, AutoReply X-Outbound-SMTP-Client: 10.65.75.112, [10.65.75.112] X-Outbound-Node: bgl-core-2.cisco.com Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org When an application sends with AF_PACKET and places a vlan header on the raw packet; then the AF_PACKET needs to move the tag into the skb so that it gets processed normally through the rest of the transmit path. This is particularly a problem on Hyper-V where the host only allows vlan in the offload info. Cc: xe-linux-external@cisco.com Cc: Sriram Krishnan Signed-off-by: Sriram Krishnan --- net/packet/af_packet.c | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/net/packet/af_packet.c b/net/packet/af_packet.c index 29bd405adbbd..10988639561e 100644 --- a/net/packet/af_packet.c +++ b/net/packet/af_packet.c @@ -1857,15 +1857,35 @@ static int packet_rcv_spkt(struct sk_buff *skb, struct net_device *dev, return 0; } -static void packet_parse_headers(struct sk_buff *skb, struct socket *sock) +static int packet_parse_headers(struct sk_buff *skb, struct socket *sock) { if ((!skb->protocol || skb->protocol == htons(ETH_P_ALL)) && sock->type == SOCK_RAW) { + __be16 ethertype; + skb_reset_mac_header(skb); + + ethertype = eth_hdr(skb)->h_proto; + /* + * If Vlan tag is present in the packet + * move it to skb + */ + if (eth_type_vlan(ethertype)) { + int err; + __be16 vlan_tci; + + err = __skb_vlan_pop(skb, &vlan_tci); + if (unlikely(err)) + return err; + + __vlan_hwaccel_put_tag(skb, ethertype, vlan_tci); + } + skb->protocol = dev_parse_header_protocol(skb); } skb_probe_transport_header(skb); + return 0; } /* @@ -1987,7 +2007,9 @@ static int packet_sendmsg_spkt(struct socket *sock, struct msghdr *msg, if (unlikely(extra_len == 4)) skb->no_fcs = 1; - packet_parse_headers(skb, sock); + err = packet_parse_headers(skb, sock); + if (err) + goto out_unlock; dev_queue_xmit(skb); rcu_read_unlock(); -- 2.24.0