netfilter: xt_multiport: Use switch case instead of multiple condition checks
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>
This commit is contained in:
parent
432490f9d4
commit
dd2602d00f
|
@ -42,29 +42,31 @@ ports_match_v1(const struct xt_multiport_v1 *minfo,
|
||||||
e = minfo->ports[++i];
|
e = minfo->ports[++i];
|
||||||
pr_debug("src or dst matches with %d-%d?\n", s, e);
|
pr_debug("src or dst matches with %d-%d?\n", s, e);
|
||||||
|
|
||||||
if (minfo->flags == XT_MULTIPORT_SOURCE
|
switch (minfo->flags) {
|
||||||
&& src >= s && src <= e)
|
case XT_MULTIPORT_SOURCE:
|
||||||
return true ^ minfo->invert;
|
return (src >= s && src <= e) ^ minfo->invert;
|
||||||
if (minfo->flags == XT_MULTIPORT_DESTINATION
|
case XT_MULTIPORT_DESTINATION:
|
||||||
&& dst >= s && dst <= e)
|
return (dst >= s && dst <= e) ^ minfo->invert;
|
||||||
return true ^ minfo->invert;
|
case XT_MULTIPORT_EITHER:
|
||||||
if (minfo->flags == XT_MULTIPORT_EITHER
|
return ((dst >= s && dst <= e) ||
|
||||||
&& ((dst >= s && dst <= e)
|
(src >= s && src <= e)) ^ minfo->invert;
|
||||||
|| (src >= s && src <= e)))
|
default:
|
||||||
return true ^ minfo->invert;
|
break;
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
/* exact port matching */
|
/* exact port matching */
|
||||||
pr_debug("src or dst matches with %d?\n", s);
|
pr_debug("src or dst matches with %d?\n", s);
|
||||||
|
|
||||||
if (minfo->flags == XT_MULTIPORT_SOURCE
|
switch (minfo->flags) {
|
||||||
&& src == s)
|
case XT_MULTIPORT_SOURCE:
|
||||||
return true ^ minfo->invert;
|
return (src == s) ^ minfo->invert;
|
||||||
if (minfo->flags == XT_MULTIPORT_DESTINATION
|
case XT_MULTIPORT_DESTINATION:
|
||||||
&& dst == s)
|
return (dst == s) ^ minfo->invert;
|
||||||
return true ^ minfo->invert;
|
case XT_MULTIPORT_EITHER:
|
||||||
if (minfo->flags == XT_MULTIPORT_EITHER
|
return (src == s || dst == s) ^ minfo->invert;
|
||||||
&& (src == s || dst == s))
|
default:
|
||||||
return true ^ minfo->invert;
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue