]> git.karo-electronics.de Git - linux-beck.git/commitdiff
netfilter: xt_multiport: Use switch case instead of multiple condition checks
authorGao Feng <fgao@ikuai8.com>
Mon, 26 Sep 2016 13:23:37 +0000 (21:23 +0800)
committerPablo Neira Ayuso <pablo@netfilter.org>
Wed, 26 Oct 2016 14:35:15 +0000 (16:35 +0200)
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

index ac1d3c3d09e72dbbfbf49f4dcdad6fc7600dcded..ec06fb1cb16fccd2bfe2bcb9698316a69780e50b 100644 (file)
@@ -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;
+                       }
                }
        }