Allow modification of IP64 prefix
This commit is contained in:
parent
10be59cc15
commit
e5a604552e
2 changed files with 22 additions and 29 deletions
|
@ -35,6 +35,10 @@
|
|||
#include <string.h>
|
||||
|
||||
#define printf(...)
|
||||
|
||||
static uip_ip6addr_t ip64_prefix = {{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0xff, 0xff, 0, 0, 0, 0}};
|
||||
static uint8_t ip64_prefix_len = 96;
|
||||
|
||||
/*---------------------------------------------------------------------------*/
|
||||
void
|
||||
ip64_addr_copy4(uip_ip4addr_t *dest, const uip_ip4addr_t *src)
|
||||
|
@ -56,20 +60,7 @@ ip64_addr_4to6(const uip_ip4addr_t *ipv4addr,
|
|||
addresses. It returns 0 if it failed to convert the address and
|
||||
non-zero if it could successfully convert the address. */
|
||||
|
||||
/* The IPv4 address is encoded as an IPv6-encoded IPv4 address in
|
||||
the ::ffff:0000/24 prefix.*/
|
||||
ipv6addr->u8[0] = 0;
|
||||
ipv6addr->u8[1] = 0;
|
||||
ipv6addr->u8[2] = 0;
|
||||
ipv6addr->u8[3] = 0;
|
||||
ipv6addr->u8[4] = 0;
|
||||
ipv6addr->u8[5] = 0;
|
||||
ipv6addr->u8[6] = 0;
|
||||
ipv6addr->u8[7] = 0;
|
||||
ipv6addr->u8[8] = 0;
|
||||
ipv6addr->u8[9] = 0;
|
||||
ipv6addr->u8[10] = 0xff;
|
||||
ipv6addr->u8[11] = 0xff;
|
||||
uip_ipaddr_copy(ipv6addr, &ip64_prefix);
|
||||
ipv6addr->u8[12] = ipv4addr->u8[0];
|
||||
ipv6addr->u8[13] = ipv4addr->u8[1];
|
||||
ipv6addr->u8[14] = ipv4addr->u8[2];
|
||||
|
@ -90,21 +81,7 @@ ip64_addr_6to4(const uip_ip6addr_t *ipv6addr,
|
|||
returns 0 if it failed to convert the address and non-zero if it
|
||||
could successfully convert the address. */
|
||||
|
||||
/* If the IPv6 address is an IPv6-encoded
|
||||
IPv4 address (i.e. in the ::ffff:0/8 prefix), we simply use the
|
||||
IPv4 addresses directly. */
|
||||
if(ipv6addr->u8[0] == 0 &&
|
||||
ipv6addr->u8[1] == 0 &&
|
||||
ipv6addr->u8[2] == 0 &&
|
||||
ipv6addr->u8[3] == 0 &&
|
||||
ipv6addr->u8[4] == 0 &&
|
||||
ipv6addr->u8[5] == 0 &&
|
||||
ipv6addr->u8[6] == 0 &&
|
||||
ipv6addr->u8[7] == 0 &&
|
||||
ipv6addr->u8[8] == 0 &&
|
||||
ipv6addr->u8[9] == 0 &&
|
||||
ipv6addr->u8[10] == 0xff &&
|
||||
ipv6addr->u8[11] == 0xff) {
|
||||
if(ip64_addr_is_ip64(ipv6addr)) {
|
||||
ipv4addr->u8[0] = ipv6addr->u8[12];
|
||||
ipv4addr->u8[1] = ipv6addr->u8[13];
|
||||
ipv4addr->u8[2] = ipv6addr->u8[14];
|
||||
|
@ -121,3 +98,16 @@ ip64_addr_6to4(const uip_ip6addr_t *ipv6addr,
|
|||
return 0;
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
int
|
||||
ip64_addr_is_ip64(const uip_ip6addr_t *ipv6addr)
|
||||
{
|
||||
return uip_ipaddr_prefixcmp(ipv6addr, &ip64_prefix, ip64_prefix_len);
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
void
|
||||
ip64_addr_set_prefix(const uip_ip6addr_t *prefix, uint8_t prefix_len)
|
||||
{
|
||||
uip_ipaddr_copy(&ip64_prefix, prefix);
|
||||
ip64_prefix_len = prefix_len;
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
|
|
|
@ -58,6 +58,9 @@ int ip64_addr_6to4(const uip_ip6addr_t *ipv6addr,
|
|||
int ip64_addr_4to6(const uip_ip4addr_t *ipv4addr,
|
||||
uip_ip6addr_t *ipv6addr);
|
||||
|
||||
int ip64_addr_is_ip64(const uip_ip6addr_t *ipv6addr);
|
||||
|
||||
void ip64_addr_set_prefix(const uip_ip6addr_t *prefix, uint8_t prefix_len);
|
||||
|
||||
#endif /* IP64_ADDR_H */
|
||||
|
||||
|
|
Loading…
Reference in a new issue