Thread (7 messages) flat view 7 messages, 5 authors, 2021-09-08

Re: [PATCH net v2] net: netfilter: Fix port selection of FTP for NF_NAT_RANGE_PROTO_SPECIFIED

From: Duncan Roe <hidden>
Date: 2021-09-08 02:22:58
Also in: lkml, netfilter-devel

On Tue, Sep 07, 2021 at 05:11:42PM +0200, Jan Engelhardt wrote:
On Tuesday 2021-09-07 15:54, Florian Westphal wrote:
quoted
quoted
-	/* 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")).
When comparing against constant zero, why use htons/htonl at all?

Cheers ... Duncan.
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help