netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Pablo Neira Ayuso <pablo@netfilter.org>
To: netfilter-devel@vger.kernel.org
Cc: davem@davemloft.net, netdev@vger.kernel.org
Subject: [PATCH 01/12] netfilter: xt_multiport: Use switch case instead of multiple condition checks
Date: Tue,  1 Nov 2016 22:26:22 +0100	[thread overview]
Message-ID: <1478035593-1362-2-git-send-email-pablo@netfilter.org> (raw)
In-Reply-To: <1478035593-1362-1-git-send-email-pablo@netfilter.org>

From: Gao Feng <fgao@ikuai8.com>

There are multiple equality condition checks in the original codes, so it
is better to use switch case instead of them.

Signed-off-by: Gao Feng <fgao@ikuai8.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
---
 net/netfilter/xt_multiport.c | 40 +++++++++++++++++++++-------------------
 1 file changed, 21 insertions(+), 19 deletions(-)

diff --git a/net/netfilter/xt_multiport.c b/net/netfilter/xt_multiport.c
index ac1d3c3d09e7..ec06fb1cb16f 100644
--- a/net/netfilter/xt_multiport.c
+++ b/net/netfilter/xt_multiport.c
@@ -42,29 +42,31 @@ ports_match_v1(const struct xt_multiport_v1 *minfo,
 			e = minfo->ports[++i];
 			pr_debug("src or dst matches with %d-%d?\n", s, e);
 
-			if (minfo->flags == XT_MULTIPORT_SOURCE
-			    && src >= s && src <= e)
-				return true ^ minfo->invert;
-			if (minfo->flags == XT_MULTIPORT_DESTINATION
-			    && dst >= s && dst <= e)
-				return true ^ minfo->invert;
-			if (minfo->flags == XT_MULTIPORT_EITHER
-			    && ((dst >= s && dst <= e)
-				|| (src >= s && src <= e)))
-				return true ^ minfo->invert;
+			switch (minfo->flags) {
+			case XT_MULTIPORT_SOURCE:
+				return (src >= s && src <= e) ^ minfo->invert;
+			case XT_MULTIPORT_DESTINATION:
+				return (dst >= s && dst <= e) ^ minfo->invert;
+			case XT_MULTIPORT_EITHER:
+				return ((dst >= s && dst <= e) ||
+					(src >= s && src <= e)) ^ minfo->invert;
+			default:
+				break;
+			}
 		} else {
 			/* exact port matching */
 			pr_debug("src or dst matches with %d?\n", s);
 
-			if (minfo->flags == XT_MULTIPORT_SOURCE
-			    && src == s)
-				return true ^ minfo->invert;
-			if (minfo->flags == XT_MULTIPORT_DESTINATION
-			    && dst == s)
-				return true ^ minfo->invert;
-			if (minfo->flags == XT_MULTIPORT_EITHER
-			    && (src == s || dst == s))
-				return true ^ minfo->invert;
+			switch (minfo->flags) {
+			case XT_MULTIPORT_SOURCE:
+				return (src == s) ^ minfo->invert;
+			case XT_MULTIPORT_DESTINATION:
+				return (dst == s) ^ minfo->invert;
+			case XT_MULTIPORT_EITHER:
+				return (src == s || dst == s) ^ minfo->invert;
+			default:
+				break;
+			}
 		}
 	}
 
-- 
2.1.4


  reply	other threads:[~2016-11-01 21:26 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-11-01 21:26 [PATCH 00/12] Netfilter updates for net-next Pablo Neira Ayuso
2016-11-01 21:26 ` Pablo Neira Ayuso [this message]
2016-11-01 21:26 ` [PATCH 02/12] netfilter: nfnetlink_log: Use GFP_NOWARN for skb allocation Pablo Neira Ayuso
2016-11-01 21:26 ` [PATCH 03/12] netfilter: nf_tables: allow expressions to return STOLEN Pablo Neira Ayuso
2016-11-01 21:26 ` [PATCH 04/12] netfilter: nft_numgen: start round robin from zero Pablo Neira Ayuso
2016-11-01 21:26 ` [PATCH 05/12] netfilter: nft_meta: permit pkttype mangling in ip/ip6 prerouting Pablo Neira Ayuso
2016-11-01 21:26 ` [PATCH 06/12] netfilter: nft_ct: add notrack support Pablo Neira Ayuso
2016-11-01 21:26 ` [PATCH 07/12] netfilter: nf_tables: add fib expression Pablo Neira Ayuso
2016-11-01 21:26 ` [PATCH 08/12] netfilter: nf_log: add packet logging for netdev family Pablo Neira Ayuso
2016-11-01 21:26 ` [PATCH 09/12] netfilter: move socket lookup infrastructure to nf_socket_ipv{4,6}.c Pablo Neira Ayuso
2016-11-01 21:26 ` [PATCH 10/12] netfilter: nf_tables: introduce routing expression Pablo Neira Ayuso
2016-11-01 21:26 ` [PATCH 11/12] netfilter: nf_tables: remove useless U8_MAX validation Pablo Neira Ayuso
2016-11-01 21:26 ` [PATCH 12/12] netfilter: nf_queue: place volatile data in own cacheline Pablo Neira Ayuso
2016-11-02 18:59 ` [PATCH 00/12] Netfilter updates for net-next David Miller

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1478035593-1362-2-git-send-email-pablo@netfilter.org \
    --to=pablo@netfilter.org \
    --cc=davem@davemloft.net \
    --cc=netdev@vger.kernel.org \
    --cc=netfilter-devel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).