Skip to content

Commit

Permalink
ipv6: Optimize ipv6_change_dsfield().
Browse files Browse the repository at this point in the history
Do not convert endian back and forth.
If the caller uses contant "mask" argument (and most callers do),
we can omit runtime endian conversion here.

Signed-off-by: YOSHIFUJI Hideaki <yoshfuji@linux-ipv6.org>
Signed-off-by: David S. Miller <davem@davemloft.net>
  • Loading branch information
YOSHIFUJI Hideaki / 吉藤英明 authored and David S. Miller committed Jan 10, 2013
1 parent 6c40d10 commit a0376db
Showing 1 changed file with 2 additions and 4 deletions.
6 changes: 2 additions & 4 deletions include/net/dsfield.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,9 @@ static inline void ipv4_change_dsfield(struct iphdr *iph,__u8 mask,
static inline void ipv6_change_dsfield(struct ipv6hdr *ipv6h,__u8 mask,
__u8 value)
{
__u16 tmp;
__be16 *p = (__force __be16 *)ipv6h;

tmp = ntohs(*(__be16 *) ipv6h);
tmp = (tmp & ((mask << 4) | 0xf00f)) | (value << 4);
*(__be16 *) ipv6h = htons(tmp);
*p = (*p & htons((((u16)mask << 4) | 0xf00f))) | htons((u16)value << 4);
}


Expand Down

0 comments on commit a0376db

Please sign in to comment.