Commit d01ee8ec authored by Hideaki Yoshifuji's avatar Hideaki Yoshifuji

[IPV6]: ipv6_addr_prefix() cleanup, eliminate duplication.

parent de4aca03
...@@ -263,6 +263,21 @@ static inline void ipv6_addr_copy(struct in6_addr *a1, const struct in6_addr *a2 ...@@ -263,6 +263,21 @@ 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((void *) a1, (const void *) a2, sizeof(struct in6_addr));
} }
static inline void ipv6_addr_prefix(struct in6_addr *pfx,
const struct in6_addr *addr,
int plen)
{
/* caller must guarantee 0 <= plen <= 128 */
int o = plen >> 3,
b = plen & 0x7;
memcpy(pfx->s6_addr, addr, o);
if (b != 0)
pfx->s6_addr[o] = addr->s6_addr[o] & (0xff00 >> b);
if (o < 16)
memset(pfx->s6_addr + o, 0, 16 - o);
}
#ifndef __HAVE_ARCH_ADDR_SET #ifndef __HAVE_ARCH_ADDR_SET
static inline void ipv6_addr_set(struct in6_addr *addr, static inline void ipv6_addr_set(struct in6_addr *addr,
__u32 w1, __u32 w2, __u32 w1, __u32 w2,
......
...@@ -400,38 +400,6 @@ static struct inet6_dev * ipv6_find_idev(struct net_device *dev) ...@@ -400,38 +400,6 @@ static struct inet6_dev * ipv6_find_idev(struct net_device *dev)
return idev; return idev;
} }
void ipv6_addr_prefix(struct in6_addr *prefix,
struct in6_addr *addr, int prefix_len)
{
unsigned long mask;
int ncopy, nbits;
memset(prefix, 0, sizeof(*prefix));
if (prefix_len <= 0)
return;
if (prefix_len > 128)
prefix_len = 128;
ncopy = prefix_len / 32;
switch (ncopy) {
case 4: prefix->s6_addr32[3] = addr->s6_addr32[3];
case 3: prefix->s6_addr32[2] = addr->s6_addr32[2];
case 2: prefix->s6_addr32[1] = addr->s6_addr32[1];
case 1: prefix->s6_addr32[0] = addr->s6_addr32[0];
case 0: break;
}
nbits = prefix_len % 32;
if (nbits == 0)
return;
mask = ~((1 << (32 - nbits)) - 1);
mask = htonl(mask);
prefix->s6_addr32[ncopy] = addr->s6_addr32[ncopy] & mask;
}
static void dev_forward_change(struct inet6_dev *idev) static void dev_forward_change(struct inet6_dev *idev)
{ {
struct net_device *dev; struct net_device *dev;
......
...@@ -587,19 +587,6 @@ static int ip6_dst_gc(void) ...@@ -587,19 +587,6 @@ static int ip6_dst_gc(void)
Remove it only when all the things will work! Remove it only when all the things will work!
*/ */
static void ipv6_addr_prefix(struct in6_addr *pfx,
const struct in6_addr *addr, int plen)
{
int b = plen&0x7;
int o = plen>>3;
memcpy(pfx->s6_addr, addr, o);
if (o < 16)
memset(pfx->s6_addr + o, 0, 16 - o);
if (b != 0)
pfx->s6_addr[o] = addr->s6_addr[o]&(0xff00 >> b);
}
static int ipv6_get_mtu(struct net_device *dev) static int ipv6_get_mtu(struct net_device *dev)
{ {
int mtu = IPV6_MIN_MTU; int mtu = IPV6_MIN_MTU;
......
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