Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp4751982pxj; Wed, 12 May 2021 12:24:42 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzDIJLbsM8ypMZO1Ez3p6mNiLyTdl5zR4Xh0xapJnzozrI3wIbbHpxPbFe/EQtzx1qIEPjF X-Received: by 2002:a17:907:62a7:: with SMTP id nd39mr39470339ejc.502.1620847482277; Wed, 12 May 2021 12:24:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1620847482; cv=none; d=google.com; s=arc-20160816; b=nCs2qLdOHM3wmdlUbt20nfVwt6nYVtPrmDjxRXtm19iryFGcr9EhOl1KllT3b3Ffgr ghc4cAk/3x539a3xEbPsqfAxhJf/g0z9NoLdFwNTEnT39nW3DWXcq/G5jumdezeyKezl xl7WeXa6FB/53vuDxhns7+zIvF5GUTXK6t2vx0LBjvpPjWt3NhPP2B5RBuACIs4Y7kVq /dtYNo77ojv7ALztm0Z+JoOKTfNi5//LjIIHvGFrmQAmPi/wdCc4mNnWU+9zon8suQAL Fvn+5of90J1zm/sSG+Nzu8aQAJJLwPWWvlZNeuQVcAVY+c2GK0L955ou95IicYbEWTZM 4imw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=38ZB8xLF8ve9YhFnaCXTpx/YPa6Q8RmO/UIYeAZ61gQ=; b=TNQ+deXYIP36LQJPN4rcT9kiDmS2AWPldRV47SxJ2oFm3CImszUHa1k8SrW3yh+SFY RwkBfJOov+DoTCgtQdK6L31MtXlRq9s1HxCK+l1YgzlPjzGHf0FzDB2vhy5s/O6pr0nR O+XxBrXZtaKYj4bojMh7a5XMtuoc1fcxWeHZf1tG2+SRKjXsrfCTa+dRcElCfxYue6en GAWabMVeumooh+PUL5iQqBTEhq3Gmcz08ZnOgkuI6XaTS3h/L6qIfNirfnlMZn7NMyUM hYJ6oyS8rVHtRGxRORD4oUmpzLyMGFlKObCgfym1Nt0hypqqMi5zNhVG8OHcdf61etMO 44Lw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=iANx1esk; 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=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id kq6si742198ejb.103.2021.05.12.12.24.17; Wed, 12 May 2021 12:24:42 -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=@linuxfoundation.org header.s=korg header.b=iANx1esk; 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=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1359318AbhELTO5 (ORCPT + 99 others); Wed, 12 May 2021 15:14:57 -0400 Received: from mail.kernel.org ([198.145.29.99]:41654 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239621AbhELQpO (ORCPT ); Wed, 12 May 2021 12:45:14 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 04E2561E6F; Wed, 12 May 2021 16:14:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1620836074; bh=ysjtPelP3VLrbcSf0jawYViv8f4OKICeVu5TAjMk2HM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=iANx1eskXvnH8rq4NbJ/786e2T/gMi9gvDRTfB29miFl9Xv9aRV5nC6ycka1x48qp 4fLFE5lH/OVktIFH18XujEOzUrpEWhrjIjg3Pd6fs0dEFTbcKF4hQqn7I2dq7aBtxm q+dXFiqKybgUdnCXXbnPZmw3/7K8pwVU6PNaRhG4= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Pablo Neira Ayuso , Sasha Levin Subject: [PATCH 5.12 598/677] netfilter: nftables_offload: special ethertype handling for VLAN Date: Wed, 12 May 2021 16:50:44 +0200 Message-Id: <20210512144857.240638051@linuxfoundation.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210512144837.204217980@linuxfoundation.org> References: <20210512144837.204217980@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Pablo Neira Ayuso [ Upstream commit 783003f3bb8a565326e89d18bbd948ad8ffc816a ] The nftables offload parser sets FLOW_DISSECTOR_KEY_BASIC .n_proto to the ethertype field in the ethertype frame. However: - FLOW_DISSECTOR_KEY_BASIC .n_proto field always stores either IPv4 or IPv6 ethertypes. - FLOW_DISSECTOR_KEY_VLAN .vlan_tpid stores either the 802.1q and 802.1ad ethertypes. Same as for FLOW_DISSECTOR_KEY_CVLAN. This function adjusts the flow dissector to handle two scenarios: 1) FLOW_DISSECTOR_KEY_VLAN .vlan_tpid is set to 802.1q or 802.1ad. Then, transfer: - the .n_proto field to FLOW_DISSECTOR_KEY_VLAN .tpid. - the original FLOW_DISSECTOR_KEY_VLAN .tpid to the FLOW_DISSECTOR_KEY_CVLAN .tpid - the original FLOW_DISSECTOR_KEY_CVLAN .tpid to the .n_proto field. 2) .n_proto is set to 802.1q or 802.1ad. Then, transfer: - the .n_proto field to FLOW_DISSECTOR_KEY_VLAN .tpid. - the original FLOW_DISSECTOR_KEY_VLAN .tpid to the .n_proto field. Fixes: a82055af5959 ("netfilter: nft_payload: add VLAN offload support") Signed-off-by: Pablo Neira Ayuso Signed-off-by: Sasha Levin --- net/netfilter/nf_tables_offload.c | 44 +++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/net/netfilter/nf_tables_offload.c b/net/netfilter/nf_tables_offload.c index 9ae14270c543..2b00f7f47693 100644 --- a/net/netfilter/nf_tables_offload.c +++ b/net/netfilter/nf_tables_offload.c @@ -45,6 +45,48 @@ void nft_flow_rule_set_addr_type(struct nft_flow_rule *flow, offsetof(struct nft_flow_key, control); } +struct nft_offload_ethertype { + __be16 value; + __be16 mask; +}; + +static void nft_flow_rule_transfer_vlan(struct nft_offload_ctx *ctx, + struct nft_flow_rule *flow) +{ + struct nft_flow_match *match = &flow->match; + struct nft_offload_ethertype ethertype; + + if (match->dissector.used_keys & BIT(FLOW_DISSECTOR_KEY_CONTROL) && + match->key.basic.n_proto != htons(ETH_P_8021Q) && + match->key.basic.n_proto != htons(ETH_P_8021AD)) + return; + + ethertype.value = match->key.basic.n_proto; + ethertype.mask = match->mask.basic.n_proto; + + if (match->dissector.used_keys & BIT(FLOW_DISSECTOR_KEY_VLAN) && + (match->key.vlan.vlan_tpid == htons(ETH_P_8021Q) || + match->key.vlan.vlan_tpid == htons(ETH_P_8021AD))) { + match->key.basic.n_proto = match->key.cvlan.vlan_tpid; + match->mask.basic.n_proto = match->mask.cvlan.vlan_tpid; + match->key.cvlan.vlan_tpid = match->key.vlan.vlan_tpid; + match->mask.cvlan.vlan_tpid = match->mask.vlan.vlan_tpid; + match->key.vlan.vlan_tpid = ethertype.value; + match->mask.vlan.vlan_tpid = ethertype.mask; + match->dissector.offset[FLOW_DISSECTOR_KEY_CVLAN] = + offsetof(struct nft_flow_key, cvlan); + match->dissector.used_keys |= BIT(FLOW_DISSECTOR_KEY_CVLAN); + } else { + match->key.basic.n_proto = match->key.vlan.vlan_tpid; + match->mask.basic.n_proto = match->mask.vlan.vlan_tpid; + match->key.vlan.vlan_tpid = ethertype.value; + match->mask.vlan.vlan_tpid = ethertype.mask; + match->dissector.offset[FLOW_DISSECTOR_KEY_VLAN] = + offsetof(struct nft_flow_key, vlan); + match->dissector.used_keys |= BIT(FLOW_DISSECTOR_KEY_VLAN); + } +} + struct nft_flow_rule *nft_flow_rule_create(struct net *net, const struct nft_rule *rule) { @@ -89,6 +131,8 @@ struct nft_flow_rule *nft_flow_rule_create(struct net *net, expr = nft_expr_next(expr); } + nft_flow_rule_transfer_vlan(ctx, flow); + flow->proto = ctx->dep.l3num; kfree(ctx); -- 2.30.2