Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp4630950pxj; Wed, 12 May 2021 09:37:25 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw2L+KJoRmkC3tFCuzQ7dS25i+R7K56I+LtyqP3Tof5y68RJCNBinDSqw+ArAA9rOKQqdP4 X-Received: by 2002:a05:6402:17d7:: with SMTP id s23mr44467311edy.66.1620837445580; Wed, 12 May 2021 09:37:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1620837445; cv=none; d=google.com; s=arc-20160816; b=k4Bw2v/wst9ITVv4bBPTLFF2+kSoPhSfrT5ZjlA1//QUqH6J10EHXy/+iXqntNyBXR 8WYkbRUoLEylc266z3WtB+PfwnyN19n+tvoPNgqDt/yJEk7Yd5TZNMD8aumW+4u94U4S t8z5uKaAF5CfEm1vSBBeGOVoL6tXuWODfRjsv80QdwDYa96qan+92yUgt1kf8wKKwlh+ MUyzEYKv7eHZJZxIa9ydXg2qo+dNq9PbPQFlIo2lJktjWi7KB7ilwrfva/eN7SRzEnwZ tVRdVwpnF+/9kWY6Yxm1GZNYPC6bnfzPAR/xJFb7vyRyq+PBuWY8AtrxyPCdCvkIAwN0 64Mg== 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=SIKLOcGteh7Zev+kwpz/qzluTQ+01zupknYT8MrtQABxUc35pBYIUZtDrpwplstLSy 9Q0RE4fMdueqTS7xJ2VQtx2IhI2tJ1z1H7B7GlzvqPDftMTQf3EWSria6sU+RAnm8iMp 8o5fOpk6WDk/skf3JCgSFBANIPD2WmRjYp/2x6effRKpDA+LuiPT2qVFDkAUGv7PV39K TvvA5HMYagcK5loj4yqWYevXOH3GF19rpwe15VrnWcF1pDyhxkynZbcfiAY4Ez7VPaJR RkED/Yi5RTDy93tvYestmt4p5GdzjPHXgtWkxUDL9Uib3eleGUVnEONXtJOM3IZfyyf4 lXdw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=0C2R9jqy; 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 l20si84189ejx.738.2021.05.12.09.37.01; Wed, 12 May 2021 09:37:25 -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=0C2R9jqy; 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 S240306AbhELQdN (ORCPT + 99 others); Wed, 12 May 2021 12:33:13 -0400 Received: from mail.kernel.org ([198.145.29.99]:56528 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233734AbhELPlP (ORCPT ); Wed, 12 May 2021 11:41:15 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 1DA5661429; Wed, 12 May 2021 15:21:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1620832892; bh=ysjtPelP3VLrbcSf0jawYViv8f4OKICeVu5TAjMk2HM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=0C2R9jqy2B0J5NyPXuYU5H9A9643HtcCB9hH7mX2GBIFFFDpU5cPXec5DMBvq2xFO iay062gswRSsYG4dOr/yz5GgCaTS8B1509BIefR/Avg9OSLUnfxh/6hQj79mgLX2vu u0ji1XEhafcYN8zMTD7ptRICzhhtTlDQ4oyRe5+M= 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.10 465/530] netfilter: nftables_offload: special ethertype handling for VLAN Date: Wed, 12 May 2021 16:49:35 +0200 Message-Id: <20210512144835.050586796@linuxfoundation.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210512144819.664462530@linuxfoundation.org> References: <20210512144819.664462530@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