Received: by 2002:a05:6a10:eb17:0:0:0:0 with SMTP id hx23csp3858974pxb; Tue, 7 Sep 2021 09:03:43 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzRbC3uvZESt7A1Ju1Kojn/QLOMgFN/OZ2bG2cTyXtdFE2HU7wqpNajKHVbyaBmYrcqr4w9 X-Received: by 2002:a17:906:2649:: with SMTP id i9mr1680096ejc.1.1631030623257; Tue, 07 Sep 2021 09:03:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1631030623; cv=none; d=google.com; s=arc-20160816; b=cfoA72C4d+5HDYc1pODnlloink26iHNmoP4HGZrmxX5BMURx8OvepPlqDN3xRgLPBJ T3LaXXp+zICErSGbcRFaPMnhkyH2pdl948MHXIJUtjF/gpcYjPKt81lIr4hlacGm8RBO 37bzwcODtK7YtwfTIqiq3OY+BUZl4cvgEfMi7Wn2ybVfpNjnTPJXHX/qctZ9qzVVncz1 L+I05Nx+ZkR5f21e6ilyOrxglgIBF3xlVB58TZG77Hkhzmf1dHemmJ6wRNJzutTMC3i5 /P4V5fLKujYhDxkc9oAGUKglZUqkfr8Ho9tUG3wzHAtlEGv9QvWxQtPORlaKvNgKLUZL UiZQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:user-agent:references:message-id :in-reply-to:subject:cc:to:from:date; bh=l09jp5HpjzRilNapwBaQmKbECqJ//qDWY097ZQJWbco=; b=qDYIP8qlUoYFPtuMAb2mwX4A1ZOq0DIHS8Y4KmNmGuETD2zp/ReMvIXOoIz0DyN7qr YX2HFzasH/gudAvaT7kWrVMFsezr10M0blu7FrAkE/KOm47mGSF3p1qAE3axewE9HW61 2S/vPqoZ8ttOjOCKONWor21tNZ63q0cbktpSZNM030cZPIkZETpEr7OZQXn4oSJWXtqO fQ6MN15nLrhI30pHG1/KrcGJ6/NFRzK5ORUZmi/MPyszft2SgKTkHzva0f31hNHMTmkc 2eM/oSQCqee01/FUoE7JUrRrU4dOdxmVu87veGLtHCbx9GYEOSoMfsMl4v1HY6VM1VUe T83g== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id bi16si10708442edb.381.2021.09.07.09.03.16; Tue, 07 Sep 2021 09:03:43 -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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1345132AbhIGPSs (ORCPT + 99 others); Tue, 7 Sep 2021 11:18:48 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54248 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1345119AbhIGPSr (ORCPT ); Tue, 7 Sep 2021 11:18:47 -0400 X-Greylist: delayed 356 seconds by postgrey-1.37 at lindbergh.monkeyblade.net; Tue, 07 Sep 2021 08:17:40 PDT Received: from a3.inai.de (a3.inai.de [IPv6:2a01:4f8:10b:45d8::f5]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D1B5EC06175F for ; Tue, 7 Sep 2021 08:17:40 -0700 (PDT) Received: by a3.inai.de (Postfix, from userid 25121) id 2B9DF59F6BDB2; Tue, 7 Sep 2021 17:11:42 +0200 (CEST) Received: from localhost (localhost [127.0.0.1]) by a3.inai.de (Postfix) with ESMTP id 288A36168CF3D; Tue, 7 Sep 2021 17:11:42 +0200 (CEST) Date: Tue, 7 Sep 2021 17:11:42 +0200 (CEST) From: Jan Engelhardt To: Florian Westphal cc: Cole Dishington , pablo@netfilter.org, kadlec@netfilter.org, davem@davemloft.net, kuba@kernel.org, shuah@kernel.org, linux-kernel@vger.kernel.org, netfilter-devel@vger.kernel.org, coreteam@netfilter.org, netdev@vger.kernel.org, Anthony Lineham , Scott Parlane , Blair Steven Subject: Re: [PATCH net v2] net: netfilter: Fix port selection of FTP for NF_NAT_RANGE_PROTO_SPECIFIED In-Reply-To: <20210907135458.GF23554@breakpoint.cc> Message-ID: References: <20210907021415.962-1-Cole.Dishington@alliedtelesis.co.nz> <20210907135458.GF23554@breakpoint.cc> User-Agent: Alpine 2.24 (LSU 510 2020-10-10) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tuesday 2021-09-07 15:54, Florian Westphal wrote: >> - /* Try to get same port: if not, try to change it. */ >> - for (port = ntohs(exp->saved_proto.tcp.port); port != 0; port++) { >> - int ret; >> + if (htons(nat->range_info.min_proto.all) == 0 || >> + htons(nat->range_info.max_proto.all) == 0) { > >Either use if (nat->range_info.min_proto.all || ... > >or use ntohs(). I will leave it up to you if you prefer >ntohs(nat->range_info.min_proto.all) == 0 or >nat->range_info.min_proto.all == ntohs(0). If one has the option, one should always prefer to put htons/htonl on the side with the constant literal; Propagation of constants and compile-time evaluation is the target. That works for some other functions as well (e.g. strlen("fixedstring")).