Change the way of accessing the default v6 prefix
This commit changes the method of accessing the default v6 prefix. Instead of always using `UIP_DS6_DEFAULT_PREFIX`, we store the default prefix in a variable. We subsequently retrieve the prefix by calling `uip_ds6_default_prefix()`. `uip_ds6_init()` will set this variable to the value of `UIP_DS6_DEFAULT_PREFIX`, but only if the startup code has not set a different default prefix before `uip_ds6_init()` gets called. This approach has the following benefits: * It allows us to change the default prefix at run time. * It allows the startup code to set a prefix different than the one specified by `UIP_DS6_DEFAULT_PREFIX`, which can be useful if the default prefix comes from a different source (e.g. the command line for native, or a configuration stored on a node's flash) * In many places the current code assumes that the prefix contains 6 bytes of zeros (e.g. `FDxx::/64`). Changing to a different prefix (e.g. `FD00:ABCD::`) would need extensive code changes. This change here makes it easy to use a prefix of any length.
This commit is contained in:
parent
057dbebb24
commit
15f6e1d7a3
@ -196,11 +196,12 @@ set_lladdr(void)
|
||||
static void
|
||||
set_global_address(void)
|
||||
{
|
||||
static uip_ipaddr_t ipaddr;
|
||||
uip_ipaddr_t ipaddr;
|
||||
const uip_ipaddr_t *default_prefix = uip_ds6_default_prefix();
|
||||
|
||||
/* Assign a unique local address (RFC4193,
|
||||
http://tools.ietf.org/html/rfc4193). */
|
||||
uip_ip6addr(&ipaddr, UIP_DS6_DEFAULT_PREFIX, 0, 0, 0, 0, 0, 0, 0);
|
||||
uip_ip6addr_copy(&ipaddr, default_prefix);
|
||||
|
||||
/* Assumes that the uip_lladdr is set */
|
||||
uip_ds6_set_addr_iid(&ipaddr, &uip_lladdr);
|
||||
@ -211,7 +212,8 @@ set_global_address(void)
|
||||
LOG_INFO_("\n");
|
||||
|
||||
/* set the PREFIX::1 address to the IF */
|
||||
uip_ip6addr(&ipaddr, UIP_DS6_DEFAULT_PREFIX, 0, 0, 0, 0, 0, 0, 1);
|
||||
uip_ip6addr_copy(&ipaddr, default_prefix);
|
||||
ipaddr.u8[15] = 1;
|
||||
uip_ds6_defrt_add(&ipaddr, 0);
|
||||
}
|
||||
#endif
|
||||
|
@ -80,9 +80,10 @@ join_mcast_group(void)
|
||||
{
|
||||
uip_ipaddr_t addr;
|
||||
uip_ds6_maddr_t *rv;
|
||||
const uip_ipaddr_t *default_prefix = uip_ds6_default_prefix();
|
||||
|
||||
/* First, set our v6 global */
|
||||
uip_ip6addr(&addr, UIP_DS6_DEFAULT_PREFIX, 0, 0, 0, 0, 0, 0, 0);
|
||||
uip_ip6addr_copy(&addr, default_prefix);
|
||||
uip_ds6_set_addr_iid(&addr, &uip_lladdr);
|
||||
uip_ds6_addr_add(&addr, 0, ADDR_AUTOCONF);
|
||||
|
||||
|
@ -95,10 +95,29 @@ static uip_ds6_prefix_t *locprefix;
|
||||
static const uint8_t iid_prefix[] = { 0x00, 0x00 , 0x00 , 0xff , 0xfe , 0x00 };
|
||||
#endif /* (UIP_LLADDR_LEN == 2) */
|
||||
|
||||
/* The default prefix */
|
||||
static uip_ip6addr_t default_prefix = {
|
||||
.u16 = { 0, 0, 0, 0, 0, 0, 0, 0 }
|
||||
};
|
||||
/*---------------------------------------------------------------------------*/
|
||||
const uip_ip6addr_t *
|
||||
uip_ds6_default_prefix()
|
||||
{
|
||||
return &default_prefix;
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
void
|
||||
uip_ds6_set_default_prefix(const uip_ip6addr_t *prefix)
|
||||
{
|
||||
uip_ip6addr_copy(&default_prefix, prefix);
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
void
|
||||
uip_ds6_init(void)
|
||||
{
|
||||
if(uip_is_addr_unspecified(&default_prefix)) {
|
||||
uip_ip6addr(&default_prefix, UIP_DS6_DEFAULT_PREFIX, 0, 0, 0, 0, 0, 0, 0);
|
||||
}
|
||||
|
||||
uip_ds6_neighbors_init();
|
||||
uip_ds6_route_init();
|
||||
|
@ -296,6 +296,22 @@ uip_ds6_prefix_t *uip_ds6_prefix_lookup(uip_ipaddr_t *ipaddr,
|
||||
uint8_t ipaddrlen);
|
||||
uint8_t uip_ds6_is_addr_onlink(uip_ipaddr_t *ipaddr);
|
||||
|
||||
/**
|
||||
* \brief Retrieve the Default IPv6 prefix
|
||||
* \retval A pointer to the default prefix
|
||||
*/
|
||||
const uip_ip6addr_t *uip_ds6_default_prefix(void);
|
||||
|
||||
/**
|
||||
* \brief Set the Default IPv6 prefix
|
||||
* \param prefix A pointer to the new default prefix
|
||||
*
|
||||
* uip_ds6_init() will set the default prefix to UIP_DS6_DEFAULT_PREFIX
|
||||
* unless this function here has been called beforehand to set a new default
|
||||
* prefix.
|
||||
*/
|
||||
void uip_ds6_set_default_prefix(const uip_ip6addr_t *prefix);
|
||||
|
||||
/** @} */
|
||||
|
||||
/** \name Unicast address list basic routines */
|
||||
|
@ -57,7 +57,7 @@ struct routing_driver {
|
||||
/**
|
||||
* Set the prefix, for nodes that will operate as root
|
||||
*
|
||||
* \param prefix The prefix. If NULL, UIP_DS6_DEFAULT_PREFIX is used instead
|
||||
* \param prefix The prefix. If NULL, uip_ds6_default_prefix() is used instead
|
||||
* \param iid The IID. If NULL, it will be built from uip_ds6_set_addr_iid.
|
||||
*/
|
||||
void (* root_set_prefix)(uip_ipaddr_t *prefix, uip_ipaddr_t *iid);
|
||||
|
@ -48,12 +48,15 @@ static void
|
||||
set_global_address(uip_ipaddr_t *prefix, uip_ipaddr_t *iid)
|
||||
{
|
||||
static uip_ipaddr_t root_ipaddr;
|
||||
const uip_ipaddr_t *default_prefix;
|
||||
int i;
|
||||
|
||||
default_prefix = uip_ds6_default_prefix();
|
||||
|
||||
/* Assign a unique local address (RFC4193,
|
||||
http://tools.ietf.org/html/rfc4193). */
|
||||
if(prefix == NULL) {
|
||||
uip_ip6addr(&root_ipaddr, UIP_DS6_DEFAULT_PREFIX, 0, 0, 0, 0, 0, 0, 0);
|
||||
uip_ip6addr_copy(&root_ipaddr, default_prefix);
|
||||
} else {
|
||||
memcpy(&root_ipaddr, prefix, 8);
|
||||
}
|
||||
@ -115,9 +118,11 @@ rpl_dag_root_start(void)
|
||||
if(root_if != NULL) {
|
||||
rpl_dag_t *dag;
|
||||
uip_ipaddr_t prefix;
|
||||
const uip_ipaddr_t *default_prefix;
|
||||
|
||||
rpl_set_root(RPL_DEFAULT_INSTANCE, ipaddr);
|
||||
dag = rpl_get_any_dag();
|
||||
default_prefix = uip_ds6_default_prefix();
|
||||
|
||||
/* If there are routes in this dag, we remove them all as we are
|
||||
from now on the new dag root and the old routes are wrong */
|
||||
@ -129,7 +134,7 @@ rpl_dag_root_start(void)
|
||||
dag->instance->def_route = NULL;
|
||||
}
|
||||
|
||||
uip_ip6addr(&prefix, UIP_DS6_DEFAULT_PREFIX, 0, 0, 0, 0, 0, 0, 0);
|
||||
uip_ip6addr_copy(&prefix, default_prefix);
|
||||
rpl_set_prefix(dag, &prefix, 64);
|
||||
LOG_INFO("root_set_prefix: created a new RPL dag\n");
|
||||
return 0;
|
||||
|
@ -76,13 +76,16 @@ static void
|
||||
set_global_address(uip_ipaddr_t *prefix, uip_ipaddr_t *iid)
|
||||
{
|
||||
static uip_ipaddr_t root_ipaddr;
|
||||
const uip_ipaddr_t *default_prefix;
|
||||
int i;
|
||||
uint8_t state;
|
||||
|
||||
default_prefix = uip_ds6_default_prefix();
|
||||
|
||||
/* Assign a unique local address (RFC4193,
|
||||
http://tools.ietf.org/html/rfc4193). */
|
||||
if(prefix == NULL) {
|
||||
uip_ip6addr(&root_ipaddr, UIP_DS6_DEFAULT_PREFIX, 0, 0, 0, 0, 0, 0, 0);
|
||||
uip_ip6addr_copy(&root_ipaddr, default_prefix);
|
||||
} else {
|
||||
memcpy(&root_ipaddr, prefix, 8);
|
||||
}
|
||||
|
@ -45,7 +45,7 @@
|
||||
/**
|
||||
* Set a prefix in case the node is later set as dag root.
|
||||
*
|
||||
* \param prefix The prefix. If NULL, UIP_DS6_DEFAULT_PREFIX is used instead
|
||||
* \param prefix The prefix. If NULL, uip_ds6_default_prefix() is used instead
|
||||
* \param iid The IID. If NULL, it will be built from uip_ds6_set_addr_iid.
|
||||
*/
|
||||
void rpl_dag_root_set_prefix(uip_ipaddr_t *prefix, uip_ipaddr_t *iid);
|
||||
|
@ -397,7 +397,8 @@ PT_THREAD(cmd_rpl_set_root(struct pt *pt, shell_output_func output, char *args))
|
||||
PT_EXIT(pt);
|
||||
}
|
||||
} else {
|
||||
uip_ip6addr(&prefix, UIP_DS6_DEFAULT_PREFIX, 0, 0, 0, 0, 0, 0, 0);
|
||||
const uip_ipaddr_t *default_prefix = uip_ds6_default_prefix();
|
||||
uip_ip6addr_copy(&prefix, default_prefix);
|
||||
}
|
||||
|
||||
if(is_on) {
|
||||
|
@ -36,10 +36,13 @@ PROCESS_THREAD(udp_process, ev, data)
|
||||
static struct etimer send_timer;
|
||||
uip_ipaddr_t addr;
|
||||
static int alive;
|
||||
const uip_ipaddr_t *default_prefix;
|
||||
|
||||
PROCESS_BEGIN();
|
||||
|
||||
uip_ip6addr(&addr, UIP_DS6_DEFAULT_PREFIX, 0, 0, 0, 0, 0, 0, 2);
|
||||
default_prefix = uip_ds6_default_prefix();
|
||||
uip_ip6addr_copy(&addr, default_prefix);
|
||||
addr.u16[7] = UIP_HTONS(2);
|
||||
uip_ds6_addr_add(&addr, 0, ADDR_AUTOCONF);
|
||||
|
||||
simple_udp_register(&broadcast_connection, UDP_PORT,
|
||||
|
@ -51,12 +51,15 @@ PROCESS_THREAD(udp_process, ev, data)
|
||||
etimer_set(&periodic_timer, SEND_INTERVAL);
|
||||
|
||||
while(1) {
|
||||
const uip_ipaddr_t *default_prefix;
|
||||
uint8_t buf[SIZE];
|
||||
PROCESS_WAIT_EVENT_UNTIL(etimer_expired(&periodic_timer));
|
||||
etimer_reset(&periodic_timer);
|
||||
|
||||
printf("Sending unicast\n");
|
||||
uip_ip6addr(&addr, UIP_DS6_DEFAULT_PREFIX, 0, 0, 0, 0, 0, 0, 2);
|
||||
default_prefix = uip_ds6_default_prefix();
|
||||
uip_ip6addr_copy(&addr, default_prefix);
|
||||
addr.u16[7] = UIP_HTONS(2);
|
||||
simple_udp_sendto(&broadcast_connection, buf, sizeof(buf), &addr);
|
||||
}
|
||||
|
||||
|
@ -44,6 +44,7 @@ PROCESS_THREAD(node_process, ev, data)
|
||||
static struct etimer et;
|
||||
#if WITH_ULA
|
||||
static uip_ipaddr_t ipaddr;
|
||||
const uip_ipaddr_t *default_prefix;
|
||||
#endif /* WITH_ULA */
|
||||
|
||||
#if WITH_TSCH
|
||||
@ -60,7 +61,8 @@ PROCESS_THREAD(node_process, ev, data)
|
||||
#endif /* WITH_TSCH */
|
||||
|
||||
#if WITH_ULA
|
||||
uip_ip6addr(&ipaddr, UIP_DS6_DEFAULT_PREFIX, 0, 0, 0, 0, 0, 0, 0);
|
||||
default_prefix = uip_ds6_default_prefix();
|
||||
uip_ip6addr_copy(&ipaddr, default_prefix);
|
||||
uip_ds6_prefix_add(&ipaddr, UIP_DEFAULT_PREFIX_LEN, 0, 0, 0, 0);
|
||||
uip_ds6_set_addr_iid(&ipaddr, &uip_lladdr);
|
||||
uip_ds6_addr_add(&ipaddr, 0, ADDR_AUTOCONF);
|
||||
|
@ -73,8 +73,9 @@ set_global_address(void)
|
||||
static uip_ipaddr_t ipaddr;
|
||||
int i;
|
||||
uint8_t state;
|
||||
const uip_ipaddr_t *default_prefix = uip_ds6_default_prefix();
|
||||
|
||||
uip_ip6addr(&ipaddr, UIP_DS6_DEFAULT_PREFIX, 0, 0, 0, 0, 0, 0, 0);
|
||||
uip_ip6addr_copy(&ipaddr, default_prefix);
|
||||
uip_ds6_set_addr_iid(&ipaddr, &uip_lladdr);
|
||||
uip_ds6_addr_add(&ipaddr, 0, ADDR_AUTOCONF);
|
||||
|
||||
|
@ -71,8 +71,9 @@ set_global_address(void)
|
||||
uip_ipaddr_t ipaddr;
|
||||
int i;
|
||||
uint8_t state;
|
||||
const uip_ipaddr_t *default_prefix = uip_ds6_default_prefix();
|
||||
|
||||
uip_ip6addr(&ipaddr, UIP_DS6_DEFAULT_PREFIX, 0, 0, 0, 0, 0, 0, 0);
|
||||
uip_ip6addr_copy(&ipaddr, default_prefix);
|
||||
uip_ds6_set_addr_iid(&ipaddr, &uip_lladdr);
|
||||
uip_ds6_addr_add(&ipaddr, 0, ADDR_AUTOCONF);
|
||||
|
||||
@ -92,6 +93,7 @@ PROCESS_THREAD(sender_node_process, ev, data)
|
||||
static struct etimer periodic_timer;
|
||||
static struct etimer send_timer;
|
||||
uip_ipaddr_t addr;
|
||||
const uip_ipaddr_t *default_prefix;
|
||||
|
||||
PROCESS_BEGIN();
|
||||
|
||||
@ -109,7 +111,13 @@ PROCESS_THREAD(sender_node_process, ev, data)
|
||||
|
||||
PROCESS_WAIT_EVENT_UNTIL(etimer_expired(&send_timer));
|
||||
|
||||
uip_ip6addr(&addr, UIP_DS6_DEFAULT_PREFIX, 0, 0, 0, 0x0201, 0x001, 0x001, 0x001);
|
||||
default_prefix = uip_ds6_default_prefix();
|
||||
uip_ip6addr_copy(&addr, default_prefix);
|
||||
|
||||
addr.u16[4] = UIP_HTONS(0x0201);
|
||||
addr.u16[5] = UIP_HTONS(0x0001);
|
||||
addr.u16[6] = UIP_HTONS(0x0001);
|
||||
addr.u16[7] = UIP_HTONS(0x0001);
|
||||
|
||||
{
|
||||
static unsigned int message_number;
|
||||
|
@ -73,8 +73,9 @@ set_global_address(void)
|
||||
static uip_ipaddr_t ipaddr;
|
||||
int i;
|
||||
uint8_t state;
|
||||
const uip_ipaddr_t *default_prefix = uip_ds6_default_prefix();
|
||||
|
||||
uip_ip6addr(&ipaddr, UIP_DS6_DEFAULT_PREFIX, 0, 0, 0, 0, 0, 0, 0);
|
||||
uip_ip6addr_copy(&ipaddr, default_prefix);
|
||||
uip_ds6_set_addr_iid(&ipaddr, &uip_lladdr);
|
||||
uip_ds6_addr_add(&ipaddr, 0, ADDR_AUTOCONF);
|
||||
|
||||
|
@ -71,8 +71,9 @@ set_global_address(void)
|
||||
uip_ipaddr_t ipaddr;
|
||||
int i;
|
||||
uint8_t state;
|
||||
const uip_ipaddr_t *default_prefix = uip_ds6_default_prefix();
|
||||
|
||||
uip_ip6addr(&ipaddr, UIP_DS6_DEFAULT_PREFIX, 0, 0, 0, 0, 0, 0, 0);
|
||||
uip_ip6addr_copy(&ipaddr, default_prefix);
|
||||
uip_ds6_set_addr_iid(&ipaddr, &uip_lladdr);
|
||||
uip_ds6_addr_add(&ipaddr, 0, ADDR_AUTOCONF);
|
||||
|
||||
@ -92,6 +93,7 @@ PROCESS_THREAD(sender_node_process, ev, data)
|
||||
static struct etimer periodic_timer;
|
||||
static struct etimer send_timer;
|
||||
uip_ipaddr_t addr;
|
||||
const uip_ipaddr_t *default_prefix;
|
||||
|
||||
PROCESS_BEGIN();
|
||||
|
||||
@ -109,7 +111,13 @@ PROCESS_THREAD(sender_node_process, ev, data)
|
||||
|
||||
PROCESS_WAIT_EVENT_UNTIL(etimer_expired(&send_timer));
|
||||
|
||||
uip_ip6addr(&addr, UIP_DS6_DEFAULT_PREFIX, 0, 0, 0, 0x0201, 0x001, 0x001, 0x001);
|
||||
default_prefix = uip_ds6_default_prefix();
|
||||
uip_ip6addr_copy(&addr, default_prefix);
|
||||
|
||||
addr.u16[4] = UIP_HTONS(0x0201);
|
||||
addr.u16[5] = UIP_HTONS(0x0001);
|
||||
addr.u16[6] = UIP_HTONS(0x0001);
|
||||
addr.u16[7] = UIP_HTONS(0x0001);
|
||||
|
||||
{
|
||||
static unsigned int message_number;
|
||||
|
Loading…
Reference in New Issue
Block a user