Skip to content

Commit a0376db

Browse files
yoshfujidavem330
authored andcommitted
ipv6: Optimize ipv6_change_dsfield().
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>
1 parent 6c40d10 commit a0376db

1 file changed

Lines changed: 2 additions & 4 deletions

File tree

‎include/net/dsfield.h‎

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,11 +43,9 @@ static inline void ipv4_change_dsfield(struct iphdr *iph,__u8 mask,
4343
static inline void ipv6_change_dsfield(struct ipv6hdr *ipv6h,__u8 mask,
4444
__u8 value)
4545
{
46-
__u16 tmp;
46+
__be16 *p = (__force __be16 *)ipv6h;
4747

48-
tmp = ntohs(*(__be16 *) ipv6h);
49-
tmp = (tmp & ((mask << 4) | 0xf00f)) | (value << 4);
50-
*(__be16 *) ipv6h = htons(tmp);
48+
*p = (*p & htons((((u16)mask << 4) | 0xf00f))) | htons((u16)value << 4);
5149
}
5250

5351

0 commit comments

Comments
 (0)