Commit 3984b018 authored by Herbert Xu's avatar Herbert Xu Committed by David S. Miller

[IPV4]: Simplify IP_ECN_set_ce.

Optimize away a branch and clean up the logic.
Signed-off-by: default avatarHerbert Xu <herbert@gondor.apana.org.au>
Signed-off-by: default avatarHideaki YOSHIFUJI <yoshfuji@linux-ipv6.org>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 07bf33d6
...@@ -49,19 +49,25 @@ static inline __u8 INET_ECN_encapsulate(__u8 outer, __u8 inner) ...@@ -49,19 +49,25 @@ static inline __u8 INET_ECN_encapsulate(__u8 outer, __u8 inner)
static inline void IP_ECN_set_ce(struct iphdr *iph) static inline void IP_ECN_set_ce(struct iphdr *iph)
{ {
u32 check = iph->check; u32 check = iph->check;
u32 ecn = (iph->tos + 1) & INET_ECN_MASK;
switch (iph->tos & INET_ECN_MASK) {
default: /*
case INET_ECN_NOT_ECT: * After the last operation we have (in binary):
case INET_ECN_CE: * INET_ECN_NOT_ECT => 01
* INET_ECN_ECT_1 => 10
* INET_ECN_ECT_0 => 11
* INET_ECN_CE => 00
*/
if (!(ecn & 2))
return; return;
case INET_ECN_ECT_1:
check += __constant_htons(0xFFFD); /*
break; * The following gives us:
case INET_ECN_ECT_0: * INET_ECN_ECT_1 => check += htons(0xFFFD)
check += __constant_htons(0xFFFE); * INET_ECN_ECT_0 => check += htons(0xFFFE)
break; */
} check += htons(0xFFFB) + htons(ecn);
iph->check = check + (check>=0xFFFF); iph->check = check + (check>=0xFFFF);
iph->tos |= INET_ECN_CE; iph->tos |= INET_ECN_CE;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment