Received: by 2002:a6b:fb09:0:0:0:0:0 with SMTP id h9csp569394iog; Mon, 13 Jun 2022 08:19:06 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzUF7H/y2xk9cmb0RYm7KHQ03vlvexmimBLQYbFr8STUpLxPSyasN1tbrB+4fUN2yUpdWBY X-Received: by 2002:a17:902:c411:b0:165:11ed:9287 with SMTP id k17-20020a170902c41100b0016511ed9287mr59013332plk.110.1655133546670; Mon, 13 Jun 2022 08:19:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1655133546; cv=none; d=google.com; s=arc-20160816; b=BaazydYRtEIeXcxRD/e35/1EnshwwM9V/n8jNBzm8AV7MG3JKspuWlq7ZzD/UUAYnp BsLCtGiPk5RB4zOT/sWfldosAsIeq5u4toTtxp/Ul9sVKLnG9yi88voTVouwgZaigO9f Tz+QrqHYK2q6DberG+RwEXJaMtOvxBZJ9zU+3Fcs1ZMdxme1mvAes6p6/1BYUcuDKJSw vxSRPuwBxYkVtlKGqK8nxf1drl23g76qpAfSUdC0M7BJhJh1PK9BjooMEj5PtrneSC+L FfCA77eGnBkVh+jIaIkvStwHbeH+OubfaEdGx0x5huRD/rcuyymDsHaHKpf/qdowJMms KL0w== 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=i+XZWq3qLMFk41MDXY8W1ZgOozo2lOhtvO7+WtOG7g8=; b=0hgqafBpDghswrDLJHnDsZ5QfdDpRmikJ1vhode9aLA9LC+Kw/xML1cyy9euDbdjaF qaN/3/yMobs2pwROZMe3fRwGLPBea+LBtriNaQH+x18AWcgCnJj02kJsSxdj8vVWyMjm zsz4adyn/IFgEPf1PVZF70J9aMAFqcQVaVD2aufAVzrfNnxM1pJxOje1tl6vWLMGsD8A IeXIEPIR0wLssUol+0p+yK7hw4f4zw7fMTezZBnGje1JzjkrdzBsQXrp7WuhqL8mtRSQ 5i+CLWIFGOnxAk2hzEfKDGfKdqu7mp8weUkWr/VPfOLYKo04FrPgkJC/ZKIEJiZuaqsi EhDA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b="hvV+/L/Y"; 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 a14-20020a170902b58e00b00153b2d165d8si8770029pls.480.2022.06.13.08.18.53; Mon, 13 Jun 2022 08:19:06 -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="hvV+/L/Y"; 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 S1355892AbiFMLmU (ORCPT + 99 others); Mon, 13 Jun 2022 07:42:20 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43076 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1354766AbiFMLfn (ORCPT ); Mon, 13 Jun 2022 07:35:43 -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 23D2544762; Mon, 13 Jun 2022 03:48:02 -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 544F1612C4; Mon, 13 Jun 2022 10:48:02 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 65103C34114; Mon, 13 Jun 2022 10:48:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1655117281; bh=IL8GKhdc3Wo8si//BsdbnCBSVkgPlm8kJ4ZPIEMR9HI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=hvV+/L/Ya6w+D5OlqztKr355tI1pepFa/wKGKo1eyBGq5BUWxhxYkOf0qC8PjA/CR mUSU1rhWJk8wnt55mHR8byeNnza9HoNPv+J9XpNAMdjcpxyTQ1nVzVPe0SLoSjQ14x IdSysnBQABFb7ow6GaiFA4VNqsq9dDi9+Ws7YJ4s= 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.4 348/411] netfilter: nat: really support inet nat without l3 address Date: Mon, 13 Jun 2022 12:10:21 +0200 Message-Id: <20220613094939.142947044@linuxfoundation.org> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220613094928.482772422@linuxfoundation.org> References: <20220613094928.482772422@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 17c0f75dfcdb..0c5bc3c37ecf 100644 --- a/net/netfilter/nft_nat.c +++ b/net/netfilter/nft_nat.c @@ -283,7 +283,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 d7e07f4c3d7f..4e15e8167310 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 <