From 15290c897f9b788df9cd8aa6924aecfed4584798 Mon Sep 17 00:00:00 2001 From: authmillenon Date: Wed, 14 Aug 2013 17:04:17 +0200 Subject: [PATCH] Make NCE type and status types publicly available --- sys/net/sixlowpan/icmp.c | 57 ++++++++++------------- sys/net/sixlowpan/icmp.h | 2 +- sys/net/sixlowpan/include/sixlowpan/ip.h | 2 +- sys/net/sixlowpan/include/sixlowpan/ndp.h | 30 +++++++++++- sys/net/sixlowpan/ip.c | 2 +- 5 files changed, 56 insertions(+), 37 deletions(-) diff --git a/sys/net/sixlowpan/icmp.c b/sys/net/sixlowpan/icmp.c index 1e03d47291..d9b3245069 100644 --- a/sys/net/sixlowpan/icmp.c +++ b/sys/net/sixlowpan/icmp.c @@ -88,16 +88,7 @@ #define ABR_CACHE_SIZE (2) /* neighbor cache size */ #define NBR_CACHE_SIZE (8) -#define NBR_CACHE_TYPE_GC (1) -#define NBR_CACHE_TYPE_REG (2) -#define NBR_CACHE_TYPE_TEN (3) #define NBR_CACHE_LTIME_TEN (20) -/* neighbor status values */ -#define NBR_STATUS_INCOMPLETE (0) -#define NBR_STATUS_REACHABLE (1) -#define NBR_STATUS_STALE (2) -#define NBR_STATUS_DELAY (3) -#define NBR_STATUS_PROBE (4) /* default router list size */ #define DEF_RTR_LST_SIZE (3) /* geeigneten wert finden */ @@ -150,8 +141,9 @@ uint8_t recvd_pref_len = 0; void def_rtr_lst_add(ipv6_addr_t *ipaddr, uint32_t rtr_ltime); void def_rtr_lst_rem(ndp_default_router_list_t *entry); uint8_t nbr_cache_add(ipv6_addr_t *ipaddr, ieee_802154_long_t *laddr, - uint8_t isrouter, uint8_t state, uint8_t type, - uint16_t ltime, ieee_802154_short_t *saddr); + uint8_t isrouter, ndp_nce_state_t state, + ndp_nce_type_t type, uint16_t ltime, + ieee_802154_short_t *saddr); void nbr_cache_rem(ipv6_addr_t *addr); int min(int a, int b) @@ -447,14 +439,14 @@ void recv_rtr_sol(void) else { /* new long addr found, update */ memcpy(&nbr_entry->laddr, &llao[2], 8); - nbr_entry->state = NBR_STATUS_STALE; + nbr_entry->state = NDP_NCE_STATUS_STALE; nbr_entry->isrouter = 0; } } else { /* nothing found, add neigbor into cache*/ nbr_cache_add(&ipv6_buf->srcaddr, (ieee_802154_long_t *)&llao[2], - 0, NBR_STATUS_STALE, NBR_CACHE_TYPE_TEN, + 0, NDP_NCE_STATUS_STALE, NDP_NCE_TYPE_TENTATIVE, NBR_CACHE_LTIME_TEN, NULL); } } @@ -981,7 +973,7 @@ void recv_nbr_sol(void) } else { memcpy(&nbr_entry->saddr, &llao[2], 2); - nbr_entry->state = NBR_STATUS_STALE; + nbr_entry->state = NDP_NCE_STATUS_STALE; nbr_entry->isrouter = 0; } @@ -994,7 +986,7 @@ void recv_nbr_sol(void) } else { memcpy(&nbr_entry->laddr, &llao[2], 8); - nbr_entry->state = NBR_STATUS_STALE; + nbr_entry->state = NDP_NCE_STATUS_STALE; nbr_entry->isrouter = 0; } @@ -1009,8 +1001,8 @@ void recv_nbr_sol(void) switch (opt_stllao_buf->length) { case (1): { nbr_cache_add(&ipv6_buf->srcaddr, - NULL , 0, NBR_STATUS_STALE, - NBR_CACHE_TYPE_TEN, + NULL , 0, NDP_NCE_STATUS_STALE, + NDP_NCE_TYPE_TENTATIVE, NBR_CACHE_LTIME_TEN, (ieee_802154_short_t *)&llao[2]); @@ -1020,8 +1012,8 @@ void recv_nbr_sol(void) case (2): { nbr_cache_add(&ipv6_buf->srcaddr, (ieee_802154_long_t *)&llao[2], 0, - NBR_STATUS_STALE, - NBR_CACHE_TYPE_TEN, + NDP_NCE_STATUS_STALE, + NDP_NCE_TYPE_TENTATIVE, NBR_CACHE_LTIME_TEN, NULL); break; } @@ -1052,7 +1044,7 @@ void recv_nbr_sol(void) /* create neighbor cache */ aro_state = nbr_cache_add(&ipv6_buf->srcaddr, &(opt_aro_buf->eui64), 0, - NBR_STATUS_STALE, NBR_CACHE_TYPE_TEN, + NDP_NCE_STATUS_STALE, NDP_NCE_TYPE_TENTATIVE, opt_aro_buf->reg_ltime, NULL); } else { @@ -1065,7 +1057,7 @@ void recv_nbr_sol(void) } else { set_remaining_time(&(nbr_entry->ltime), (uint32_t)opt_aro_buf->reg_ltime); - nbr_entry->state = NBR_STATUS_STALE; + nbr_entry->state = NDP_NCE_STATUS_STALE; nbr_entry->isrouter = 0; memcpy(&(nbr_entry->addr.uint8[0]), &(ipv6_buf->srcaddr.uint8[0]), 16); @@ -1223,7 +1215,7 @@ void recv_nbr_adv(void) new_ll = memcmp(&llao[2], &(nbr_entry->laddr), 8); } - if (nbr_entry->state == NBR_STATUS_INCOMPLETE) { + if (nbr_entry->state == NDP_NCE_STATUS_INCOMPLETE) { if (llao == NULL) { return; } @@ -1232,19 +1224,19 @@ void recv_nbr_adv(void) memcpy(&nbr_entry->laddr, &llao[2], 8); if (nbr_adv_buf->rso & ICMPV6_NEIGHBOR_ADV_FLAG_SOLICITED) { - nbr_entry->state = NBR_STATUS_REACHABLE; + nbr_entry->state = NDP_NCE_STATUS_REACHABLE; /* TODO: set rechability */ } else { - nbr_entry->state = NBR_STATUS_STALE; + nbr_entry->state = NDP_NCE_STATUS_STALE; } nbr_entry->isrouter = nbr_adv_buf->rso & ICMPV6_NEIGHBOR_ADV_FLAG_ROUTER; } else { if (new_ll && !(nbr_adv_buf->rso & ICMPV6_NEIGHBOR_ADV_FLAG_OVERRIDE)) { - if (nbr_entry->state == NBR_STATUS_REACHABLE) { - nbr_entry->state = NBR_STATUS_STALE; + if (nbr_entry->state == NDP_NCE_STATUS_REACHABLE) { + nbr_entry->state = NDP_NCE_STATUS_STALE; } return; @@ -1258,12 +1250,12 @@ void recv_nbr_adv(void) } if (nbr_adv_buf->rso & ICMPV6_NEIGHBOR_ADV_FLAG_SOLICITED) { - nbr_entry->state = NBR_STATUS_REACHABLE; + nbr_entry->state = NDP_NCE_STATUS_REACHABLE; /* TODO: set rechablility */ } else { if (llao != 0 && new_ll) { - nbr_entry->state = NBR_STATUS_STALE; + nbr_entry->state = NDP_NCE_STATUS_STALE; } } } @@ -1367,8 +1359,9 @@ ndp_neighbor_cache_t *ndp_neighbor_cache_search(ipv6_addr_t *ipaddr) } uint8_t nbr_cache_add(ipv6_addr_t *ipaddr, ieee_802154_long_t *laddr, - uint8_t isrouter, uint8_t state, uint8_t type, - uint16_t ltime, ieee_802154_short_t *saddr) + uint8_t isrouter, ndp_nce_state_t state, + ndp_nce_type_t type, uint16_t ltime, + ieee_802154_short_t *saddr) { if (nbr_count == NBR_CACHE_SIZE) { printf("ERROR: neighbor cache full\n"); @@ -1395,7 +1388,7 @@ void nbr_cache_auto_rem(void) for (i = 0; i < NBR_CACHE_SIZE; i++) { if (get_remaining_time(&(nbr_cache[i].ltime)) == 0 && - nbr_cache[i].type == NBR_CACHE_TYPE_TEN) { + nbr_cache[i].type == NDP_NCE_TYPE_TENTATIVE) { memmove(&(nbr_cache[i]), &(nbr_cache[nbr_count]), sizeof(ndp_neighbor_cache_t)); memset(&(nbr_cache[nbr_count]), 0, sizeof(ndp_neighbor_cache_t)); @@ -1485,7 +1478,7 @@ lowpan_context_t *abr_get_context(ndp_a6br_cache_t *abr, uint8_t cid) } ndp_a6br_cache_t *abr_add_context(uint16_t version, ipv6_addr_t *abr_addr, - uint8_t cid) + uint8_t cid) { ndp_a6br_cache_t *abr = abr_get_version(version, abr_addr); diff --git a/sys/net/sixlowpan/icmp.h b/sys/net/sixlowpan/icmp.h index 7cd074f225..37babfe86b 100644 --- a/sys/net/sixlowpan/icmp.h +++ b/sys/net/sixlowpan/icmp.h @@ -57,7 +57,7 @@ int8_t plist_add(ipv6_addr_t *addr, uint8_t size, uint32_t val_ltime, uint32_t pref_ltime, uint8_t adv_opt, uint8_t l_a_reserved1); ndp_a6br_cache_t *abr_add_context(uint16_t version, ipv6_addr_t *abr_addr, - uint8_t cid); + uint8_t cid); void abr_remove_context(uint8_t cid); uint16_t icmpv6_csum(uint8_t proto); diff --git a/sys/net/sixlowpan/include/sixlowpan/ip.h b/sys/net/sixlowpan/include/sixlowpan/ip.h index 26c71a1a36..e486e103a0 100644 --- a/sys/net/sixlowpan/include/sixlowpan/ip.h +++ b/sys/net/sixlowpan/include/sixlowpan/ip.h @@ -273,7 +273,7 @@ int ipv6_addr_is_link_local(const ipv6_addr_t *ipv6_addr); * * @param[in] ipv6_addr An IPv6 address. * - * @return 1 if *ipv6_addr* is unique local unicast address, + * @return 1 if *ipv6_addr* is unique local unicast address, * 0 otherwise. */ int ipv6_addr_is_unique_local_unicast(const ipv6_addr_t *addr); diff --git a/sys/net/sixlowpan/include/sixlowpan/ndp.h b/sys/net/sixlowpan/include/sixlowpan/ndp.h index 858482b227..43f7854e56 100644 --- a/sys/net/sixlowpan/include/sixlowpan/ndp.h +++ b/sys/net/sixlowpan/include/sixlowpan/ndp.h @@ -35,6 +35,32 @@ #define NDP_OPT_ARO_STATE_DUP_ADDR (1) #define NDP_OPT_ARO_STATE_NBR_CACHE_FULL (2) +/** + * @brief Neighbor cache entry state according to + * + * RFC 4861, section 7.3.2 + * . + */ +typedef enum __attribute__((packed)) { + NDP_NCE_STATUS_INCOMPLETE, + NDP_NCE_STATUS_REACHABLE, + NDP_NCE_STATUS_STALE, + NDP_NCE_STATUS_DELAY, + NDP_NCE_STATUS_PROBE, +} ndp_nce_state_t; + +/** + * @brief Neighbor cache entry type according to + * + * RFC 6775, section 3.5 + * . + */ +typedef enum __attribute__((packed)) { + NDP_NCE_TYPE_GC = 1, ///< Garbage-collectible. + NDP_NCE_TYPE_REGISTERED, ///< Registered. + NDP_NCE_TYPE_TENTATIVE ///< Tentetive. +} ndp_nce_type_t; + typedef struct __attribute__((packed)) { uint8_t inuse; uint8_t adv; @@ -54,8 +80,8 @@ typedef struct __attribute__((packed)) { /* neighbor cache - rfc4861 5.1. */ typedef struct __attribute__((packed)) { - uint8_t type; - uint8_t state; + ndp_nce_type_t type; + ndp_nce_state_t state; uint8_t isrouter; ipv6_addr_t addr; ieee_802154_long_t laddr; diff --git a/sys/net/sixlowpan/ip.c b/sys/net/sixlowpan/ip.c index 9c6911451e..afae120986 100644 --- a/sys/net/sixlowpan/ip.c +++ b/sys/net/sixlowpan/ip.c @@ -483,7 +483,7 @@ void ipv6_iface_get_best_src_addr(ipv6_addr_t *src, const ipv6_addr_t *dest) if (!(ipv6_addr_is_link_local(dest)) && !(ipv6_addr_is_multicast(dest))) { for (int i = 0; i < IFACE_ADDR_LIST_LEN; i++) { if (iface.addr_list[i].state == NDP_ADDR_STATE_PREFERRED) { - if (!ipv6_addr_is_link_local(&(iface.addr_list[i].addr)) && + if (!ipv6_addr_is_link_local(&(iface.addr_list[i].addr)) && !ipv6_addr_is_multicast(&(iface.addr_list[i].addr)) && !ipv6_addr_is_unique_local_unicast(&(iface.addr_list[i].addr))) { tmp = ipv6_get_addr_match(dest, &(iface.addr_list[i].addr));