/* * @brief filling the FIB with entries and removing an unknown entry * It is expected to have 20 FIB entries and 20 universal address entries after removing */ static void test_fib_08_remove_unknown(void) { size_t add_buf_size = 16; /* includes space for terminating \0 */ char addr_dst[] = "Test address 99"; size_t entries = 20; _fill_FIB_multiple(entries, 11); TEST_ASSERT_EQUAL_INT(20, fib_get_num_used_entries(&test_fib_table)); TEST_ASSERT_EQUAL_INT(20, universal_address_get_num_used_entries()); fib_remove_entry(&test_fib_table, (uint8_t *)addr_dst, add_buf_size - 1); fib_remove_entry(&test_fib_table, (uint8_t *)addr_dst, add_buf_size - 1); fib_remove_entry(&test_fib_table, (uint8_t *)addr_dst, add_buf_size - 1); #if (TEST_FIB_SHOW_OUTPUT == 1) fib_print_fib_table(&test_fib_table); puts(""); universal_address_print_table(); puts(""); #endif TEST_ASSERT_EQUAL_INT(20, fib_get_num_used_entries(&test_fib_table)); TEST_ASSERT_EQUAL_INT(20, universal_address_get_num_used_entries()); fib_deinit(&test_fib_table); }
/* * @brief filling the FIB with entries and removing the upper 1/2 entries (10..19) * It is expected to have 10 FIB entries and 10 universal address entries after remove */ static void test_fib_05_remove_upper_half(void) { size_t add_buf_size = 16; char addr_dst[add_buf_size]; size_t entries = 20; _fill_FIB_multiple(entries, 11); TEST_ASSERT_EQUAL_INT(20, fib_get_num_used_entries()); TEST_ASSERT_EQUAL_INT(20, universal_address_get_num_used_entries()); for (size_t i = 0; i < entries / 2; ++i) { /* construct "addresses" to remove */ snprintf(addr_dst, add_buf_size, "Test address %02d", ((entries / 2) + i)); fib_remove_entry((uint8_t *)addr_dst, add_buf_size - 1); } #if (TEST_FIB_SHOW_OUTPUT == 1) fib_print_fib_table(); puts(""); universal_address_print_table(); puts(""); #endif TEST_ASSERT_EQUAL_INT(10, fib_get_num_used_entries()); TEST_ASSERT_EQUAL_INT(10, universal_address_get_num_used_entries()); fib_deinit(); }
/* * @brief filling the FIB with entries and removing all entries * It is expected to have 0 FIB entries and 0 universal address entries after remove */ static void test_fib_03_removing_all_entries(void) { size_t add_buf_size = 16; char addr_dst[add_buf_size]; size_t entries = 20; _fill_FIB_unique(entries); TEST_ASSERT_EQUAL_INT(20, fib_get_num_used_entries()); TEST_ASSERT_EQUAL_INT(40, universal_address_get_num_used_entries()); for (size_t i = 0; i < entries; ++i) { /* construct "addresses" to remove */ snprintf(addr_dst, add_buf_size, "Test address %02d", (int)i); fib_remove_entry((uint8_t *)addr_dst, add_buf_size - 1); } TEST_ASSERT_EQUAL_INT(0, fib_get_num_used_entries()); TEST_ASSERT_EQUAL_INT(0, universal_address_get_num_used_entries()); #if (TEST_FIB_SHOW_OUTPUT == 1) fib_print_fib_table(); puts(""); universal_address_print_table(); puts(""); #endif fib_deinit(); }
void ng_ndp_retrans_nbr_sol(ng_ipv6_nc_t *nc_entry) { if ((ng_ipv6_nc_get_state(nc_entry) == NG_IPV6_NC_STATE_INCOMPLETE) || (ng_ipv6_nc_get_state(nc_entry) == NG_IPV6_NC_STATE_PROBE)) { if (nc_entry->probes_remaining > 1) { ng_ipv6_addr_t dst; DEBUG("ndp: Retransmit neighbor solicitation for %s\n", ng_ipv6_addr_to_str(addr_str, &nc_entry->ipv6_addr, sizeof(addr_str))); /* retransmit neighbor solicatation */ if (ng_ipv6_nc_get_state(nc_entry) == NG_IPV6_NC_STATE_INCOMPLETE) { ng_ipv6_addr_set_solicited_nodes(&dst, &nc_entry->ipv6_addr); } else { dst.u64[0] = nc_entry->ipv6_addr.u64[0]; dst.u64[1] = nc_entry->ipv6_addr.u64[1]; } nc_entry->probes_remaining--; if (nc_entry->iface == KERNEL_PID_UNDEF) { timex_t t = { 0, NG_NDP_RETRANS_TIMER }; kernel_pid_t ifs[NG_NETIF_NUMOF]; size_t ifnum = ng_netif_get(ifs); for (size_t i = 0; i < ifnum; i++) { _send_nbr_sol(ifs[i], &nc_entry->ipv6_addr, &dst); } vtimer_remove(&nc_entry->nbr_sol_timer); vtimer_set_msg(&nc_entry->nbr_sol_timer, t, ng_ipv6_pid, NG_NDP_MSG_NBR_SOL_RETRANS, nc_entry); } else { ng_ipv6_netif_t *ipv6_iface = ng_ipv6_netif_get(nc_entry->iface); _send_nbr_sol(nc_entry->iface, &nc_entry->ipv6_addr, &dst); mutex_lock(&ipv6_iface->mutex); vtimer_remove(&nc_entry->nbr_sol_timer); vtimer_set_msg(&nc_entry->nbr_sol_timer, ipv6_iface->retrans_timer, ng_ipv6_pid, NG_NDP_MSG_NBR_SOL_RETRANS, nc_entry); mutex_unlock(&ipv6_iface->mutex); } } else if (nc_entry->probes_remaining <= 1) { DEBUG("ndp: Remove nc entry %s for interface %" PRIkernel_pid "\n", ng_ipv6_addr_to_str(addr_str, &nc_entry->ipv6_addr, sizeof(addr_str)), nc_entry->iface); #ifdef MODULE_FIB fib_remove_entry((uint8_t *) & (nc_entry->ipv6_addr), sizeof(ng_ipv6_addr_t)); #endif ng_ipv6_nc_remove(nc_entry->iface, &nc_entry->ipv6_addr); } } }
static enum rfc5444_result _cb_rerr_blocktlv_addresstlvs_okay(struct rfc5444_reader_tlvblock_context *cont) { #if ENABLE_DEBUG /* cppcheck-suppress unusedVariable as nbuf is needed by VDEBUG. */ struct netaddr_str nbuf; #endif struct aodvv2_routing_entry_t *unreachable_entry; struct rfc5444_reader_tlvblock_entry *tlv; VDEBUG("%s()\n", __func__); VDEBUG("\tmessage type: %d\n", cont->type); VDEBUG("\taddr: %s\n", netaddr_to_string(&nbuf, &cont->addr)); /* Out of buffer size for more unreachable nodes. We're screwed, basically. */ if (num_unreachable_nodes == AODVV2_MAX_UNREACHABLE_NODES) { return RFC5444_OKAY; } /* gather packet data */ packet_data.origNode.addr = cont->addr; /* handle this unreachable node's SeqNum TLV */ /* cppcheck: suppress false positive on non-trivially initialized arrays. * this is a known bug: http://trac.cppcheck.net/ticket/5497 */ /* cppcheck-suppress arrayIndexOutOfBounds */ tlv = _rerr_address_consumer_entries[RFC5444_MSGTLV_UNREACHABLE_NODE_SEQNUM].tlv; if (tlv) { VDEBUG("\ttlv RFC5444_MSGTLV_UNREACHABLE_NODE_SEQNUM: %d\n", *tlv->single_value); packet_data.origNode.seqnum = *tlv->single_value; } /* Check if there is an entry for unreachable node in our routing table */ unreachable_entry = routingtable_get_entry(&packet_data.origNode.addr, packet_data.metricType); if (unreachable_entry) { VDEBUG("\t found possibly unreachable entry.\n"); /* check if route to unreachable node has to be marked as broken and RERR has to be forwarded */ if (netaddr_cmp(&unreachable_entry->nextHopAddr, &packet_data.sender) == 0 && (!tlv || seqnum_cmp(unreachable_entry->seqnum, packet_data.origNode.seqnum) == 0)) { unreachable_entry->state = ROUTE_STATE_INVALID; unreachable_nodes[num_unreachable_nodes].addr = packet_data.origNode.addr; unreachable_nodes[num_unreachable_nodes].seqnum = packet_data.origNode.seqnum; num_unreachable_nodes++; } /* remove entry from FIB */ fib_remove_entry(packet_data.origNode.addr._addr, sizeof(ipv6_addr_t)); } return RFC5444_OKAY; }
/* * @brief filling the FIB with entries and removing one entry * It is expected to have 19 FIB entries and still 20 universal address entries * after removing 02 * (the use count for 02 is reduced to 1 after remove) */ static void test_fib_06_remove_one_entry(void) { size_t add_buf_size = 16; char addr_dst[] = "Test address 02"; size_t entries = 20; _fill_FIB_multiple(entries, 11); TEST_ASSERT_EQUAL_INT(20, fib_get_num_used_entries()); TEST_ASSERT_EQUAL_INT(20, universal_address_get_num_used_entries()); fib_remove_entry((uint8_t *)addr_dst, add_buf_size - 1); #if (TEST_FIB_SHOW_OUTPUT == 1) fib_print_fib_table(); puts(""); universal_address_print_table(); puts(""); #endif TEST_ASSERT_EQUAL_INT(19, fib_get_num_used_entries()); TEST_ASSERT_EQUAL_INT(20, universal_address_get_num_used_entries()); fib_deinit(); }
int _fib_route_handler(int argc, char **argv) { /* e.g. fibroute right now dont care about the adress/protocol family */ if (argc == 1) { fib_print_routes(); return 0; } /* e.g. firoute [add|del] */ if (argc == 2) { if ((strcmp("add", argv[1]) == 0)) { _fib_usage(2); } else if ((strcmp("del", argv[1]) == 0)) { _fib_usage(3); } else { puts("\nunrecognized parameter1.\nPlease enter fibroute [add|del] for more information."); } return 1; } if (argc > 2 && !((strcmp("add", argv[1]) == 0) || (strcmp("del", argv[1]) == 0))) { puts("\nunrecognized parameter2.\nPlease enter fibroute [add|del] for more information."); return 1; } /* e.g. fibroute del <destination> */ if (argc == 3) { if (inet_pton(AF_INET6, argv[2], tmp_ipv6_dst)) { fib_remove_entry(tmp_ipv6_dst, IN6ADDRSZ); } else if (inet_pton(AF_INET, argv[2], tmp_ipv4_dst)) { fib_remove_entry(tmp_ipv4_dst, INADDRSZ); } else { fib_remove_entry((uint8_t *)argv[2], (strlen(argv[2]))); } return 0; } #ifdef MODULE_NG_NETIF /* e.g. fibroute add <destination> via <next hop> */ if ((argc == 5) && (strcmp("add", argv[1]) == 0) && (strcmp("via", argv[3]) == 0)) { kernel_pid_t ifs[NG_NETIF_NUMOF]; size_t ifnum = ng_netif_get(ifs); if (ifnum == 1) { _fib_add(argv[2], argv[4], ifs[0], FIB_LIFETIME_NO_EXPIRE); } else { _fib_usage(1); return 1; } return 0; } /* e.g. fibroute add <destination> via <next hop> lifetime <lifetime> */ if ((argc == 7) && (strcmp("add", argv[1]) == 0) && (strcmp("via", argv[3]) == 0) && (strcmp("lifetime", argv[5]) == 0)) { kernel_pid_t ifs[NG_NETIF_NUMOF]; size_t ifnum = ng_netif_get(ifs); if (ifnum == 1) { _fib_add(argv[2], argv[4], ifs[0], (uint32_t)atoi(argv[6])); } else { _fib_usage(1); return 1; } return 0; } #endif /* e.g. fibroute add <destination> via <next hop> dev <device> */ if (argc == 7) { if ((strcmp("add", argv[1]) == 0) && (strcmp("via", argv[3]) == 0) && (strcmp("dev", argv[5]) == 0)) { _fib_add(argv[2], argv[4], (kernel_pid_t)atoi(argv[6]), FIB_LIFETIME_NO_EXPIRE); } else { _fib_usage(1); return 1; } return 0; } /* e.g. fibroute add <destination> via <next hop> dev <device> lifetime <lifetime> */ if (argc == 9) { if ((strcmp("add", argv[1]) == 0) && (strcmp("via", argv[3]) == 0) && (strcmp("dev", argv[5]) == 0) && (strcmp("lifetime", argv[7]) == 0)) { _fib_add(argv[2], argv[4], (kernel_pid_t )atoi(argv[6]), (uint32_t)atoi(argv[8])); } else { _fib_usage(2); return 1; } return 0; } puts("\nunrecognized parameters.\nPlease enter fibroute [add|del] for more information."); return 1; }
int _fib_route_handler(int argc, char **argv) { /* e.g. fibroute right now dont care about the adress/protocol family */ if (argc == 1) { fib_print_routes(&gnrc_ipv6_fib_table); return 0; } /* e.g. firoute [add|del] */ if (argc == 2) { if ((strcmp("add", argv[1]) == 0)) { _fib_usage(2); } else if ((strcmp("del", argv[1]) == 0)) { _fib_usage(3); } else if ((strcmp("flush", argv[1]) == 0)) { fib_flush(&gnrc_ipv6_fib_table, KERNEL_PID_UNDEF); puts("successfully flushed all entries"); } else { _fib_usage(0); } return 1; } if (argc > 2 && !((strcmp("add", argv[1]) == 0) || (strcmp("del", argv[1]) == 0) || (strcmp("flush", argv[1]) == 0))) { puts("\nunrecognized parameter2.\nPlease enter fibroute [add|del] for more information."); return 1; } /* e.g. fibroute del <destination> */ if (argc == 3) { if ((strcmp("flush", argv[1]) == 0)) { kernel_pid_t iface = atoi(argv[2]); if (gnrc_netif_exist(iface)) { fib_flush(&gnrc_ipv6_fib_table, iface); printf("successfully flushed all entries for interface %" PRIu16"\n", iface); } else { printf("interface %" PRIu16" does not exist\n", iface); } } else if (inet_pton(AF_INET6, argv[2], tmp_ipv6_dst)) { fib_remove_entry(&gnrc_ipv6_fib_table, tmp_ipv6_dst, IN6ADDRSZ); } else if (inet_pton(AF_INET, argv[2], tmp_ipv4_dst)) { fib_remove_entry(&gnrc_ipv6_fib_table, tmp_ipv4_dst, INADDRSZ); } else { fib_remove_entry(&gnrc_ipv6_fib_table, (uint8_t *)argv[2], (strlen(argv[2]))); } return 0; } #ifdef MODULE_GNRC_NETIF /* e.g. fibroute add <destination> via <next hop> */ if ((argc == 5) && (strcmp("add", argv[1]) == 0) && (strcmp("via", argv[3]) == 0)) { kernel_pid_t ifs[GNRC_NETIF_NUMOF]; size_t ifnum = gnrc_netif_get(ifs); if (ifnum == 1) { _fib_add(argv[2], argv[4], ifs[0], (uint32_t)FIB_LIFETIME_NO_EXPIRE); } else { _fib_usage(1); return 1; } return 0; } /* e.g. fibroute add <destination> via <next hop> lifetime <lifetime> */ if ((argc == 7) && (strcmp("add", argv[1]) == 0) && (strcmp("via", argv[3]) == 0) && (strcmp("lifetime", argv[5]) == 0)) { kernel_pid_t ifs[GNRC_NETIF_NUMOF]; size_t ifnum = gnrc_netif_get(ifs); if (ifnum == 1) { _fib_add(argv[2], argv[4], ifs[0], (uint32_t)atoi(argv[6])); } else { _fib_usage(1); return 1; } return 0; } #endif /* e.g. fibroute add <destination> via <next hop> dev <device> */ if (argc == 7) { if ((strcmp("add", argv[1]) == 0) && (strcmp("via", argv[3]) == 0) && (strcmp("dev", argv[5]) == 0)) { _fib_add(argv[2], argv[4], (kernel_pid_t)atoi(argv[6]), (uint32_t)FIB_LIFETIME_NO_EXPIRE); } else { _fib_usage(1); return 1; } return 0; } /* e.g. fibroute add <destination> via <next hop> dev <device> lifetime <lifetime> */ if (argc == 9) { if ((strcmp("add", argv[1]) == 0) && (strcmp("via", argv[3]) == 0) && (strcmp("dev", argv[5]) == 0) && (strcmp("lifetime", argv[7]) == 0)) { _fib_add(argv[2], argv[4], (kernel_pid_t )atoi(argv[6]), (uint32_t)atoi(argv[8])); } else { _fib_usage(2); return 1; } return 0; } puts("\nunrecognized parameters.\nPlease enter fibroute [add|del] for more information."); return 1; }
/* * @brief testing prefix entry changing */ static void test_fib_20_replace_prefix(void) { size_t add_buf_size = 16; char addr_dst[add_buf_size]; char addr_nxt_hop[add_buf_size]; char addr_nxt[add_buf_size]; char addr_lookup[add_buf_size]; kernel_pid_t iface_id = KERNEL_PID_UNDEF; uint32_t next_hop_flags = 0; memset(addr_dst, 0, add_buf_size); memset(addr_nxt, 0, add_buf_size); memset(addr_nxt_hop, 0, add_buf_size); memset(addr_lookup, 0, add_buf_size); /* set the bytes to 0x01..0x10 of the next-hop */ for(size_t i = 0; i < add_buf_size; i++) { addr_nxt[i] = i+1; } /* set the bytes to 0x01..0x08 of the destination prefix */ for(size_t i = 0; i < add_buf_size/2; i++) { addr_dst[i] = i+1; } /* set the bytes to 0x01..0x0e of the lookup address */ for(size_t i = 0; i < 14; i++) { addr_lookup[i] = i+1; } /* add a prefix entry */ fib_add_entry(&test_fib_table, 42, (uint8_t *)addr_dst, add_buf_size, 0x123, (uint8_t *)addr_nxt, add_buf_size, 0x23, 100000); /* check if it matches */ int ret = fib_get_next_hop(&test_fib_table, &iface_id, (uint8_t *)addr_nxt_hop, &add_buf_size, &next_hop_flags, (uint8_t *)addr_lookup, add_buf_size, 0x123); TEST_ASSERT_EQUAL_INT(0, ret); TEST_ASSERT_EQUAL_INT(0, memcmp(addr_nxt, addr_nxt_hop, add_buf_size)); fib_remove_entry(&test_fib_table, (uint8_t *)addr_dst, add_buf_size); memset(addr_nxt_hop, 0, add_buf_size); /* set the bytes to 0x02..0x11 of the new next-hop */ for(size_t i = 0; i < add_buf_size; ++i) { addr_nxt[i] = i+2; } /* set the bytes to 0x01..0x0d of the new destination prefix */ for(size_t i = 0; i < 13; i++) { addr_dst[i] = i+1; } /* change the prefix entry */ fib_add_entry(&test_fib_table, 42, (uint8_t *)addr_dst, add_buf_size, 0x123, (uint8_t *)addr_nxt, add_buf_size, 0x24, 100000); /* and check again if it matches */ ret = fib_get_next_hop(&test_fib_table, &iface_id, (uint8_t *)addr_nxt_hop, &add_buf_size, &next_hop_flags, (uint8_t *)addr_lookup, add_buf_size, 0x123); TEST_ASSERT_EQUAL_INT(0, ret); TEST_ASSERT_EQUAL_INT(0, memcmp(addr_nxt, addr_nxt_hop, add_buf_size)); #if (TEST_FIB_SHOW_OUTPUT == 1) fib_print_fib_table(&test_fib_table); puts(""); universal_address_print_table(); puts(""); #endif fib_deinit(&test_fib_table); }