Commit db3459d1 authored by Eric Dumazet's avatar Eric Dumazet Committed by David S. Miller

[IPV6]: Some cleanups in include/net/ipv6.h

1) struct ip6_flowlabel : moves 'users' field to avoid two 32bits
   holes for 64bit arches. Shrinks by 8 bytes sizeof(struct
   ip6_flowlabel)

2) ipv6_addr_cmp() and ipv6_addr_copy() dont need (void *) casts :
   Compiler might take into account natural alignement of in6_addr
   structs to emit better code for memcpy()/memcmp() Casts to (void *)
   force byte accesses.

3) ipv6_addr_prefix() optimization :

Better to clear whole struct, as compiler can emit better code for
memset(addr, 0, 16) (2 stores on x86_64), and avoid some conditional
branches.

# size vmlinux.after vmlinux.before
   text    data     bss     dec     hex filename
5262262  647612  557432 6467306  62aeea vmlinux.after
5262550  647612  557432 6467594  62b00a vmlinux.before

thats 288 bytes saved.
Signed-off-by: default avatarEric Dumazet <dada1@cosmosbay.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent b40b4f79
...@@ -204,9 +204,9 @@ struct ip6_flowlabel ...@@ -204,9 +204,9 @@ struct ip6_flowlabel
{ {
struct ip6_flowlabel *next; struct ip6_flowlabel *next;
__be32 label; __be32 label;
atomic_t users;
struct in6_addr dst; struct in6_addr dst;
struct ipv6_txoptions *opt; struct ipv6_txoptions *opt;
atomic_t users;
unsigned long linger; unsigned long linger;
u8 share; u8 share;
u32 owner; u32 owner;
...@@ -291,7 +291,7 @@ static inline int ipv6_addr_src_scope(const struct in6_addr *addr) ...@@ -291,7 +291,7 @@ static inline int ipv6_addr_src_scope(const struct in6_addr *addr)
static inline int ipv6_addr_cmp(const struct in6_addr *a1, const struct in6_addr *a2) static inline int ipv6_addr_cmp(const struct in6_addr *a1, const struct in6_addr *a2)
{ {
return memcmp((const void *) a1, (const void *) a2, sizeof(struct in6_addr)); return memcmp(a1, a2, sizeof(struct in6_addr));
} }
static inline int static inline int
...@@ -308,7 +308,7 @@ ipv6_masked_addr_cmp(const struct in6_addr *a1, const struct in6_addr *m, ...@@ -308,7 +308,7 @@ ipv6_masked_addr_cmp(const struct in6_addr *a1, const struct in6_addr *m,
static inline void ipv6_addr_copy(struct in6_addr *a1, const struct in6_addr *a2) static inline void ipv6_addr_copy(struct in6_addr *a1, const struct in6_addr *a2)
{ {
memcpy((void *) a1, (const void *) a2, sizeof(struct in6_addr)); memcpy(a1, a2, sizeof(struct in6_addr));
} }
static inline void ipv6_addr_prefix(struct in6_addr *pfx, static inline void ipv6_addr_prefix(struct in6_addr *pfx,
...@@ -319,13 +319,10 @@ static inline void ipv6_addr_prefix(struct in6_addr *pfx, ...@@ -319,13 +319,10 @@ static inline void ipv6_addr_prefix(struct in6_addr *pfx,
int o = plen >> 3, int o = plen >> 3,
b = plen & 0x7; b = plen & 0x7;
memset(pfx->s6_addr, 0, sizeof(pfx->s6_addr));
memcpy(pfx->s6_addr, addr, o); memcpy(pfx->s6_addr, addr, o);
if (b != 0) { if (b != 0)
pfx->s6_addr[o] = addr->s6_addr[o] & (0xff00 >> b); pfx->s6_addr[o] = addr->s6_addr[o] & (0xff00 >> b);
o++;
}
if (o < 16)
memset(pfx->s6_addr + o, 0, 16 - o);
} }
static inline void ipv6_addr_set(struct in6_addr *addr, static inline void ipv6_addr_set(struct in6_addr *addr,
......
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