Merge pull request #752 from g-oikonomou/contrib/default-prefix-as-variable

Change the way of accessing the default v6 prefix
This commit is contained in:
Simon Duquennoy 2019-02-19 17:40:18 +01:00 committed by GitHub
commit e3f1b67096
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
16 changed files with 93 additions and 24 deletions

View File

@ -196,16 +196,13 @@ set_lladdr(void)
static void
set_global_address(void)
{
static uip_ipaddr_t ipaddr;
static uip_ipaddr_t *prefix = NULL;
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). */
if(prefix == NULL) {
uip_ip6addr(&ipaddr, UIP_DS6_DEFAULT_PREFIX, 0, 0, 0, 0, 0, 0, 0);
} else {
memcpy(&ipaddr, prefix, 8);
}
uip_ip6addr_copy(&ipaddr, default_prefix);
/* Assumes that the uip_lladdr is set */
uip_ds6_set_addr_iid(&ipaddr, &uip_lladdr);
uip_ds6_addr_add(&ipaddr, 0, ADDR_AUTOCONF);
@ -215,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

View File

@ -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);

View File

@ -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();

View File

@ -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 */

View File

@ -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);

View File

@ -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;

View File

@ -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);
}

View File

@ -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);

View File

@ -413,7 +413,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) {

View File

@ -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,

View File

@ -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);
}

View File

@ -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);

View File

@ -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);

View File

@ -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;

View File

@ -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);

View File

@ -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;