Received: by 2002:a6b:fb09:0:0:0:0:0 with SMTP id h9csp586646iog; Mon, 13 Jun 2022 08:38:26 -0700 (PDT) X-Google-Smtp-Source: AGRyM1tmufHfWKNC8DIKXWxcovMjrIlBIe/hDPsdzEMMpiedA7LKlntrQHF09NAiiZE8LKLoOQmk X-Received: by 2002:a17:903:2452:b0:166:4b6c:affb with SMTP id l18-20020a170903245200b001664b6caffbmr389061pls.68.1655134706103; Mon, 13 Jun 2022 08:38:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1655134706; cv=none; d=google.com; s=arc-20160816; b=JnB2HcbhTnFX6KXHEPkdhhas/UhENxPRsBUZT3C7BgUqjU8fyS+HI2NE7nf3gckHBP 9OzTkdJx0Kd+tYhhJtAiCrLwih94i8RabJOacbNzHMMT30YNA7UK0L8KoQZcpztjmlgm yH5CnOZnXc9sWDb8I+C1neG0+59nA2beDPiJU1GVuS8wozM+88DlzjQtyXCvAAj0sRlk rKPHcDiGrcsCPgT6jAJkUpuluVRhuqnxVcDwy26R0zmv79lTkz1Mf/HWlEGTDvy4wnpy J9mneJM5RkqYhNMi+h/HKRczelG+qjhG4ViqikSbC5xlyamWSUMscAdrkMb+E91I+yIP lajA== 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=WGW3nDPUvpFD0P90CqbL9tk/7Z6GWrOMTS9fYfrzpfU=; b=shUMfiD/Pu0zD/Zvls3/5D0JpnuyQBWn7s7BXFxXGXebGHOYYts4ESER7Yb6VA4TwU Zt3KX1ExhxSoi3kLs1jHvnf655OPm7SQ3vUC1JO3Gcv5VUE7VpTm4NPNifRb9DzQ0ure vA6vl8pQUPu8olo4ZK87r9D+nqum55+2kRfQwOaDC6bAyhr0OVFHWe490rC3zVB+7R92 I7fvM0i/XOKdV7GQxfnDZ0iYxtDjUbL22DhZdcYnlajaN529JnriKC6WqsB4WVDgmBJe CdWZoyOAcaXFiN+REBhyYlMy4kqYHnsBCQN1rYdGa2rhHG740wAlIMNh9xOgs6pLCElE NQ/g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=CerFDlW8; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id b38-20020a631b26000000b003dbaa0f5becsi8826630pgb.617.2022.06.13.08.38.13; Mon, 13 Jun 2022 08:38:26 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=CerFDlW8; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 S1359145AbiFMNJd (ORCPT + 99 others); Mon, 13 Jun 2022 09:09:33 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55338 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1357886AbiFMM71 (ORCPT ); Mon, 13 Jun 2022 08:59:27 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 94FBF1D0C1; Mon, 13 Jun 2022 04:18:00 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 17C6E60EF1; Mon, 13 Jun 2022 11:17:59 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 27DABC34114; Mon, 13 Jun 2022 11:17:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1655119078; bh=cBNoKy+IGKV7SgB+Q/JlwdAQKU47fU+zsPcVUFd+UFo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=CerFDlW8O4zeB/dLi2J2DT2DHrLywcRfHURlGhQLETX4hdNIp1FDcNeDGqEe7ee94 21pzpZqOdvoTcDNMAFBAfWk5ozcpae7j3QUNJTlYTJEyPrw3WAfw8E9aai7El2W2S0 p4AedXIBMv0PvlZd54L3w1D2pJOgneYiMW7a4Afc= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Yi Chen , Florian Westphal , Pablo Neira Ayuso , Sasha Levin Subject: [PATCH 5.15 132/247] netfilter: nat: really support inet nat without l3 address Date: Mon, 13 Jun 2022 12:10:34 +0200 Message-Id: <20220613094926.963491832@linuxfoundation.org> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220613094922.843438024@linuxfoundation.org> References: <20220613094922.843438024@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-8.3 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Florian Westphal [ Upstream commit 282e5f8fe907dc3f2fbf9f2103b0e62ffc3a68a5 ] When no l3 address is given, priv->family is set to NFPROTO_INET and the evaluation function isn't called. Call it too so l4-only rewrite can work. Also add a test case for this. Fixes: a33f387ecd5aa ("netfilter: nft_nat: allow to specify layer 4 protocol NAT only") Reported-by: Yi Chen Signed-off-by: Florian Westphal Signed-off-by: Pablo Neira Ayuso Signed-off-by: Sasha Levin --- net/netfilter/nft_nat.c | 3 +- tools/testing/selftests/netfilter/nft_nat.sh | 43 ++++++++++++++++++++ 2 files changed, 45 insertions(+), 1 deletion(-) diff --git a/net/netfilter/nft_nat.c b/net/netfilter/nft_nat.c index be1595d6979d..db8f9116eeb4 100644 --- a/net/netfilter/nft_nat.c +++ b/net/netfilter/nft_nat.c @@ -334,7 +334,8 @@ static void nft_nat_inet_eval(const struct nft_expr *expr, { const struct nft_nat *priv = nft_expr_priv(expr); - if (priv->family == nft_pf(pkt)) + if (priv->family == nft_pf(pkt) || + priv->family == NFPROTO_INET) nft_nat_eval(expr, regs, pkt); } diff --git a/tools/testing/selftests/netfilter/nft_nat.sh b/tools/testing/selftests/netfilter/nft_nat.sh index 781fa2d9ea9d..032f2de6e14e 100755 --- a/tools/testing/selftests/netfilter/nft_nat.sh +++ b/tools/testing/selftests/netfilter/nft_nat.sh @@ -374,6 +374,45 @@ EOF return $lret } +test_local_dnat_portonly() +{ + local family=$1 + local daddr=$2 + local lret=0 + local sr_s + local sr_r + +ip netns exec "$ns0" nft -f /dev/stdin <