/** * Update a HNA entry. If it does not exist it * is created. * This is the only function that should be called * from outside concerning creation of HNA entries. * *@param gw address of the gateway *@param net address of the network *@param prefixlen the prefix length *@param vtime the validitytime of the entry */ void olsr_update_hna_entry(const union olsr_ip_addr *gw, const union olsr_ip_addr *net, uint8_t prefixlen, olsr_reltime vtime) { struct hna_entry *gw_entry; struct hna_net *net_entry; gw_entry = olsr_lookup_hna_gw(gw); if (!gw_entry) { /* Need to add the entry */ gw_entry = olsr_add_hna_entry(gw); } net_entry = olsr_lookup_hna_net(&gw_entry->networks, net, prefixlen); if (net_entry == NULL) { /* Need to add the net */ net_entry = olsr_add_hna_net(gw_entry, net, prefixlen); changes_hna = true; } /* * Add the rt_path for the entry. */ olsr_insert_routing_table(&net_entry->hna_prefix.prefix, net_entry->hna_prefix.prefix_len, &gw_entry->A_gateway_addr, OLSR_RT_ORIGIN_HNA); /* * Start, or refresh the timer, whatever is appropriate. */ olsr_set_timer(&net_entry->hna_net_timer, vtime, OLSR_HNA_NET_JITTER, OLSR_TIMER_ONESHOT, &olsr_expire_hna_net_entry, net_entry, hna_net_timer_cookie); }
/** * Add a new tc_entry to the tc tree * * @param (last)adr address of the entry * @return a pointer to the created entry */ static struct tc_entry * olsr_add_tc_entry(const union olsr_ip_addr *adr) { #if !defined REMOVE_LOG_DEBUG struct ipaddr_str buf; #endif struct tc_entry *tc; /* * Safety net against loss of the last main IP address. */ if (olsr_ipcmp(&olsr_cnf->router_id, &all_zero) == 0) { return NULL; } OLSR_DEBUG(LOG_TC, "TC: add entry %s\n", olsr_ip_to_string(&buf, adr)); tc = olsr_memcookie_malloc(tc_mem_cookie); if (!tc) { return NULL; } /* Fill entry */ tc->addr = *adr; tc->vertex_node.key = &tc->addr; tc->mid_seq = -1; tc->hna_seq = -1; tc->tc_seq = -1; /* * Insert into the global tc tree. */ avl_insert(&tc_tree, &tc->vertex_node); /* * Initialize subtrees for edges, prefixes, HNAs and MIDs. */ avl_init(&tc->edge_tree, avl_comp_default, true, NULL); avl_init(&tc->prefix_tree, avl_comp_prefix_origin_default, false, NULL); avl_init(&tc->mid_tree, avl_comp_default, false, NULL); avl_init(&tc->hna_tree, avl_comp_prefix_default, false, NULL); /* * Add a rt_path for ourselves. */ olsr_insert_routing_table(adr, 8 * olsr_cnf->ipsize, adr, OLSR_RT_ORIGIN_TC); return tc; }
/** * Add a new tc_entry to the tc tree * * @param adr (last)adr address of the entry * @return a pointer to the created entry */ static struct tc_entry * olsr_add_tc_entry(union olsr_ip_addr *adr) { #ifdef DEBUG struct ipaddr_str buf; #endif /* DEBUG */ struct tc_entry *tc; /* * Safety net against loss of the last main IP address. */ if (ipequal(&olsr_cnf->main_addr, &all_zero)) { return NULL; } #ifdef DEBUG OLSR_PRINTF(1, "TC: add entry %s\n", olsr_ip_to_string(&buf, adr)); #endif /* DEBUG */ tc = olsr_cookie_malloc(tc_mem_cookie); if (!tc) { return NULL; } /* Fill entry */ tc->addr = *adr; tc->vertex_node.key = &tc->addr; /* * Insert into the global tc tree. */ avl_insert(&tc_tree, &tc->vertex_node, AVL_DUP_NO); olsr_lock_tc_entry(tc); /* * Initialize subtrees for edges and prefixes. */ avl_init(&tc->edge_tree, avl_comp_default); avl_init(&tc->prefix_tree, avl_comp_prefix_default); /* * Add a rt_path for ourselves. */ olsr_insert_routing_table(adr, olsr_cnf->maxplen, adr, OLSR_RT_ORIGIN_INT); return tc; }