Skip to content

Commit

Permalink
netfilter: xt_TCPMSS: Refactor the codes to decrease one condition ch…
Browse files Browse the repository at this point in the history
…eck and more readable

The origin codes perform two condition checks with dst_mtu(skb_dst(skb))
and in_mtu. And the last statement is "min(dst_mtu(skb_dst(skb)),
in_mtu) - minlen". It may let reader think about how about the result.
Would it be negative.

Now assign the result of min(dst_mtu(skb_dst(skb)), in_mtu) to a new
variable, then only perform one condition check, and it is more readable.

Signed-off-by: Gao Feng <fgao@ikuai8.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
  • Loading branch information
Gao Feng authored and Pablo Neira Ayuso committed Sep 24, 2016
1 parent 4004d5c commit 50f4c7b
Showing 1 changed file with 4 additions and 8 deletions.
12 changes: 4 additions & 8 deletions net/netfilter/xt_TCPMSS.c
Original file line number Diff line number Diff line change
Expand Up @@ -110,18 +110,14 @@ tcpmss_mangle_packet(struct sk_buff *skb,
if (info->mss == XT_TCPMSS_CLAMP_PMTU) {
struct net *net = par->net;
unsigned int in_mtu = tcpmss_reverse_mtu(net, skb, family);
unsigned int min_mtu = min(dst_mtu(skb_dst(skb)), in_mtu);

if (dst_mtu(skb_dst(skb)) <= minlen) {
if (min_mtu <= minlen) {
net_err_ratelimited("unknown or invalid path-MTU (%u)\n",
dst_mtu(skb_dst(skb)));
min_mtu);
return -1;
}
if (in_mtu <= minlen) {
net_err_ratelimited("unknown or invalid path-MTU (%u)\n",
in_mtu);
return -1;
}
newmss = min(dst_mtu(skb_dst(skb)), in_mtu) - minlen;
newmss = min_mtu - minlen;
} else
newmss = info->mss;

Expand Down

0 comments on commit 50f4c7b

Please sign in to comment.