/* * Free memory of lispd_mapping_elt. */ void free_mapping_elt(lispd_mapping_elt *mapping) { if (mapping == NULL){ return; } /* Free the locators list*/ free_locator_list(mapping->head_v4_locators_list); free_locator_list(mapping->head_v6_locators_list); /* Free extended info */ if (mapping->extended_info != NULL){ switch (mapping->mapping_type){ case LOCAL_MAPPING: free_lcl_mapping_extended_info((lcl_mapping_extended_info *)mapping->extended_info); break; case REMOTE_MAPPING: free_rmt_mapping_extended_info((rmt_mapping_extended_info *)mapping->extended_info); break; } } free(mapping); }
int process_map_reply_record(uint8_t **cur_ptr, uint64_t nonce) { lispd_pkt_mapping_record_t *record = NULL; lispd_mapping_elt *mapping = NULL; lispd_map_cache_entry *cache_entry = NULL; lisp_addr_t aux_eid_prefix; int aux_eid_prefix_length = 0; int aux_iid = 0; int ctr = 0; uint8_t is_new_mapping = FALSE; record = (lispd_pkt_mapping_record_t *)(*cur_ptr); mapping = new_map_cache_mapping(aux_eid_prefix,aux_eid_prefix_length,aux_iid); if (mapping == NULL){ return (BAD); } *cur_ptr = (uint8_t *)&(record->eid_prefix_afi); if (!pkt_process_eid_afi(cur_ptr,mapping)){ lispd_log_msg(LISP_LOG_DEBUG_2,"process_map_reply_record: Error processing the EID of the map reply record"); free_mapping_elt(mapping); return (BAD); } mapping->eid_prefix_length = record->eid_prefix_length; /* * Check if the map replay corresponds to a not active map cache */ cache_entry = lookup_nonce_in_no_active_map_caches(mapping->eid_prefix.afi, nonce); if (cache_entry != NULL){ if (cache_entry->mapping->iid != mapping->iid){ lispd_log_msg(LISP_LOG_DEBUG_2,"process_map_reply_record: Instance ID of the map reply doesn't match with the inactive map cache entry"); free_mapping_elt(mapping); return (BAD); } /* * If the eid prefix of the received map reply doesn't match the inactive map cache entry (x.x.x.x/32 or x:x:x:x:x:x:x:x/128),then * we remove the inactie entry from the database and store it again with the correct eix prefix (for instance /24). */ if (cache_entry->mapping->eid_prefix_length != mapping->eid_prefix_length){ if (change_map_cache_prefix_in_db(mapping->eid_prefix, mapping->eid_prefix_length, cache_entry) != GOOD){ free_mapping_elt(mapping); return (BAD); } } cache_entry->active = 1; stop_timer(cache_entry->request_retry_timer); cache_entry->request_retry_timer = NULL; lispd_log_msg(LISP_LOG_DEBUG_2," Activating map cache entry %s/%d", get_char_from_lisp_addr_t(mapping->eid_prefix),mapping->eid_prefix_length); free_mapping_elt(mapping); is_new_mapping = TRUE; } /* If the nonce is not found in the no active cache enties, then it should be an active cache entry */ else { /* Serch map cache entry exist*/ cache_entry = lookup_map_cache_exact(mapping->eid_prefix,mapping->eid_prefix_length); if (cache_entry == NULL){ lispd_log_msg(LISP_LOG_DEBUG_2,"process_map_reply_record: No map cache entry found for %s/%d", get_char_from_lisp_addr_t(mapping->eid_prefix),mapping->eid_prefix_length); free_mapping_elt(mapping); return (BAD); } /* Check the found map cache entry contain the nonce of the map reply*/ if (check_nonce(cache_entry->nonces,nonce)==BAD){ lispd_log_msg(LISP_LOG_DEBUG_2,"process_map_reply_record: The nonce of the Map-Reply doesn't match the nonce of the generated Map-Request. Discarding message ..."); free_mapping_elt(mapping); return (BAD); }else { free(cache_entry->nonces); cache_entry->nonces = NULL; } /* Stop timer of Map Requests retransmits */ if (cache_entry->smr_inv_timer != NULL){ stop_timer(cache_entry->smr_inv_timer); cache_entry->smr_inv_timer = NULL; } /* Check instane id.*/ if (cache_entry->mapping->iid != mapping->iid){ lispd_log_msg(LISP_LOG_DEBUG_2,"process_map_reply_record: Instance ID of the map reply doesn't match with the map cache entry"); free_mapping_elt(mapping); return (BAD); } lispd_log_msg(LISP_LOG_DEBUG_2," A map cache entry already exists for %s/%d, replacing locators list of this entry", get_char_from_lisp_addr_t(cache_entry->mapping->eid_prefix), cache_entry->mapping->eid_prefix_length); free_locator_list(cache_entry->mapping->head_v4_locators_list); free_locator_list(cache_entry->mapping->head_v6_locators_list); cache_entry->mapping->head_v4_locators_list = NULL; cache_entry->mapping->head_v6_locators_list = NULL; free_mapping_elt(mapping); } cache_entry->actions = record->action; cache_entry->ttl = ntohl(record->ttl); cache_entry->active_witin_period = 1; cache_entry->timestamp = time(NULL); //locator_count updated when adding the processed locators /* Generate the locators */ for (ctr=0 ; ctr < record->locator_count ; ctr++){ if ((process_map_reply_locator (cur_ptr, cache_entry->mapping)) != GOOD){ return(BAD); } } if (is_loggable(LISP_LOG_DEBUG_2)){ dump_map_cache_entry(cache_entry, LISP_LOG_DEBUG_2); } /* [re]Calculate balancing locator vectors if it is not a negative map reply*/ if (cache_entry->mapping->locator_count != 0){ calculate_balancing_vectors ( cache_entry->mapping, &(((rmt_mapping_extended_info *)cache_entry->mapping->extended_info)->rmt_balancing_locators_vecs)); } /* * Reprogramming timers */ /* Expiration cache timer */ if (!cache_entry->expiry_cache_timer){ cache_entry->expiry_cache_timer = create_timer (EXPIRE_MAP_CACHE_TIMER); } start_timer(cache_entry->expiry_cache_timer, cache_entry->ttl*60, (timer_callback)map_cache_entry_expiration, (void *)cache_entry); lispd_log_msg(LISP_LOG_DEBUG_1,"The map cache entry %s/%d will expire in %d minutes.", get_char_from_lisp_addr_t(cache_entry->mapping->eid_prefix), cache_entry->mapping->eid_prefix_length, cache_entry->ttl); /* RLOC probing timer */ if (is_new_mapping == TRUE && rloc_probe_interval != 0){ programming_rloc_probing(cache_entry); } return (TRUE); }
/* * Free memory of lcl_mapping_extended_info. */ void free_lcl_mapping_extended_info(lcl_mapping_extended_info *extended_info) { free_locator_list(extended_info->head_not_init_locators_list); free_balancing_locators_vecs(extended_info->outgoing_balancing_locators_vecs); free (extended_info); }