📄 ospf_routing_table_lookups.c
字号:
table_free ((void *) sptr_node); sptr_node = NULL; --(*usptr_number_of_entries); *ptr_to_sptr_first_node = sptr_would_be_first_node; } else { /* we found a more specific mask, so remove all nodes so far from the list and start with this one */ most_specific_address_mask = sptr_node->sptr_routing_table_entry->address_mask; while (*ptr_to_sptr_first_node != sptr_node) { sptr_would_be_first_node = *ptr_to_sptr_first_node; ospf_remove_node_from_list ((OSPF_GENERIC_NODE **) &sptr_would_be_first_node, (OSPF_GENERIC_NODE *) *ptr_to_sptr_first_node); table_free ((void *) *ptr_to_sptr_first_node); *ptr_to_sptr_first_node = NULL; --(*usptr_number_of_entries); /* The new first node will be forward pointer of the prev first node also the back pointer of first node * must point to last node in list. This is done in ospf_remove_node_from_list */ *ptr_to_sptr_first_node = sptr_would_be_first_node; } } } return;}/*******************************************************************************************************************************/static void ospf_insert_discard_entries_into_the_routing_table (OSPF_ROUTING_TABLE_NODE *sptr_discard_entries){ OSPF_ROUTING_TABLE_NODE *sptr_discard_entry; OSPF_ROUTING_TABLE_NODE *sptr_routing_table_node; sptr_discard_entry = NULL; sptr_routing_table_node = NULL; PARAMETER_NOT_USED (sptr_discard_entry); PARAMETER_NOT_USED (sptr_routing_table_node); PARAMETER_NOT_USED (sptr_discard_entries); OSPF_PRINTF_DEBUG (OSPF_DEBUG_PRINTF, "OSPF: Entering ospf_insert_discard_entries_into_the_routing_table\r\n"); for (sptr_discard_entry = sptr_discard_entries; sptr_discard_entry != NULL; sptr_discard_entry = sptr_discard_entry->sptr_forward_link) { sptr_routing_table_node = (OSPF_ROUTING_TABLE_NODE *) table_malloc (1, sizeof (OSPF_ROUTING_TABLE_NODE)); if (sptr_routing_table_node == NULL) { ospf_print_memory_error_message_and_free_buffer_if_necessary ((void *) NULL, "OSPF_ROUTING_TABLE_NODE"); return; } memset (sptr_routing_table_node, 0x00, sizeof (OSPF_ROUTING_TABLE_NODE)); sptr_routing_table_node->sptr_forward_link = NULL; sptr_routing_table_node->sptr_backward_link = NULL; sptr_routing_table_node->active_areas_discarded_entry = TRUE; sptr_routing_table_node->sptr_routing_table_entry = sptr_discard_entry->sptr_routing_table_entry; ospf_add_routing_table_node (sptr_routing_table_node); } return;}/*******************************************************************************************************************************/static void ospf_remove_discard_entries_from_the_routing_table (void){ OSPF_ROUTING_TABLE_NODE *sptr_routing_table_node; OSPF_ROUTING_TABLE_NODE *sptr_next_routing_table_node; ULONG index; sptr_routing_table_node = NULL; PARAMETER_NOT_USED (sptr_routing_table_node); OSPF_PRINTF_DEBUG (OSPF_DEBUG_PRINTF, "OSPF: Entering ospf_remove_discard_entries_from_the_routing_table\r\n"); for(index = 0x00000000L; index < OSPF_RT_HASH_TABLE_SIZE; index++) { for (sptr_routing_table_node = ospf.sptr_routing_table_head[OSPF_ROUTE_TABLE_NETWORK][index]; sptr_routing_table_node != NULL; /* NEWRT DISCARDED ENTRIES MANAGEMENT ### */ sptr_routing_table_node = sptr_next_routing_table_node) { sptr_next_routing_table_node = sptr_routing_table_node->sptr_forward_link; if (sptr_routing_table_node->active_areas_discarded_entry /* sptr_routing_table_node->discard_entry*/ == TRUE || sptr_routing_table_node->route_node_status == OSPF_ROUTE_IS_NOT_AVAILABLE_NOW) /* JACK ### */ { ospf_delete_routing_table_node (sptr_routing_table_node); table_free ((void *) sptr_routing_table_node); sptr_routing_table_node = NULL; } } } return;}/*******************************************************************************************************************************/OSPF_ROUTING_TABLE_ENTRY *ospf_find_routing_table_entry (ULONG destination_id_to_look,enum OSPF_ROUTE_DESTINATION_TYPE destination_type, enum OSPF_ROUTE_PATH_TYPE path_type,OSPF_AREA_ENTRY *sptr_area) /* NEWRT LOOKUP */{ OSPF_ROUTING_TABLE_NODE *sptr_routing_table_node; OSPF_ROUTING_TABLE_NODE *best_sptr_routing_table_node = NULL; enum BOOLEAN first_pass = TRUE; ULONG hash_id; enum OSPF_ROUTE_TABLE_TYPE table_type; OSPF_PRINTF_DEBUG (OSPF_DEBUG_PRINTF, "OSPF: Entering ospf_find_routing_table_entry\r\n"); switch(destination_type) { case OSPF_DESTINATION_TYPE_ASBR: case OSPF_DESTINATION_TYPE_ABR: table_type = OSPF_ROUTE_TABLE_ROUTER; break; default: table_type = OSPF_ROUTE_TABLE_NETWORK; break; } hash_id = destination_id_to_look; hash_id = hash_id & OSPF_RT_HASH_MASK; if(destination_type == OSPF_DESTINATION_TYPE_WILDCARD) { /* Search both router and network tables for wild destination type */ for(table_type = OSPF_ROUTE_TABLE_NETWORK; table_type < OSPF_ROUTE_TABLE_MAX; table_type++) { for(sptr_routing_table_node = ospf.sptr_routing_table_head[table_type][hash_id]; sptr_routing_table_node != NULL; sptr_routing_table_node = sptr_routing_table_node->sptr_forward_link) { if (((sptr_routing_table_node->sptr_routing_table_entry->destination_id == destination_id_to_look) || ((sptr_routing_table_node->sptr_routing_table_entry->destination_type == OSPF_DESTINATION_TYPE_NETWORK) && ((sptr_routing_table_node->sptr_routing_table_entry->destination_id & sptr_routing_table_node->sptr_routing_table_entry->address_mask) == (destination_id_to_look & sptr_routing_table_node->sptr_routing_table_entry->address_mask)))) && ((sptr_routing_table_node->sptr_routing_table_entry->path_type == path_type) || (path_type == OSPF_ROUTE_PATH_TYPE_WILDCARD)) && ((sptr_routing_table_node->sptr_routing_table_entry->sptr_area == sptr_area) || (sptr_area == NULL) || (destination_type == OSPF_DESTINATION_TYPE_ABR ))) { if (sptr_routing_table_node->route_node_status != OSPF_ROUTE_IS_NOT_AVAILABLE_NOW) { if (first_pass) { best_sptr_routing_table_node = sptr_routing_table_node; first_pass = FALSE; } else {#if defined (__RFC_2328__) if (sptr_routing_table_node->sptr_routing_table_entry->path_cost > best_sptr_routing_table_node->sptr_routing_table_entry->path_cost)#else if (sptr_routing_table_node->sptr_routing_table_entry->path_cost < best_sptr_routing_table_node->sptr_routing_table_entry->path_cost)#endif { best_sptr_routing_table_node = sptr_routing_table_node; } } } } } } } else if(table_type == OSPF_ROUTE_TABLE_ROUTER) { for(sptr_routing_table_node = ospf.sptr_routing_table_head[table_type][hash_id]; sptr_routing_table_node != NULL; sptr_routing_table_node = sptr_routing_table_node->sptr_forward_link) { /* Search only the router table */ if ((sptr_routing_table_node->sptr_routing_table_entry->destination_type == destination_type) && (sptr_routing_table_node->sptr_routing_table_entry->destination_id == destination_id_to_look) && ((sptr_routing_table_node->sptr_routing_table_entry->path_type == path_type) || (path_type == OSPF_ROUTE_PATH_TYPE_WILDCARD)) && ((sptr_routing_table_node->sptr_routing_table_entry->sptr_area == sptr_area) || (sptr_area == NULL) || (destination_type == OSPF_DESTINATION_TYPE_ABR ))) { if (sptr_routing_table_node->route_node_status != OSPF_ROUTE_IS_NOT_AVAILABLE_NOW) /* Jack July ### */ { if (first_pass) { best_sptr_routing_table_node = sptr_routing_table_node; first_pass = FALSE; } else {#if defined (__RFC_2328__) if (sptr_routing_table_node->sptr_routing_table_entry->path_cost > best_sptr_routing_table_node->sptr_routing_table_entry->path_cost)#else if (sptr_routing_table_node->sptr_routing_table_entry->path_cost < best_sptr_routing_table_node->sptr_routing_table_entry->path_cost)#endif { best_sptr_routing_table_node = sptr_routing_table_node; } } } } } } else { /* Search only the network table */ for(sptr_routing_table_node = ospf.sptr_routing_table_head[table_type][hash_id]; sptr_routing_table_node != NULL; sptr_routing_table_node = sptr_routing_table_node->sptr_forward_link) { if ((sptr_routing_table_node->sptr_routing_table_entry->destination_type == destination_type) && ((sptr_routing_table_node->sptr_routing_table_entry->destination_id == destination_id_to_look) || ((sptr_routing_table_node->sptr_routing_table_entry->destination_type == OSPF_DESTINATION_TYPE_NETWORK) && ((sptr_routing_table_node->sptr_routing_table_entry->destination_id & sptr_routing_table_node->sptr_routing_table_entry->address_mask) == (destination_id_to_look & sptr_routing_table_node->sptr_routing_table_entry->address_mask)))) && ((sptr_routing_table_node->sptr_routing_table_entry->path_type == path_type) || (path_type == OSPF_ROUTE_PATH_TYPE_WILDCARD)) && ((sptr_routing_table_node->sptr_routing_table_entry->sptr_area == sptr_area) || (sptr_area == NULL))) { if (sptr_routing_table_node->route_node_status != OSPF_ROUTE_IS_NOT_AVAILABLE_NOW) { if (first_pass) { best_sptr_routing_table_node = sptr_routing_table_node; first_pass = FALSE; } else {#if defined (__RFC_2328__) if (sptr_routing_table_node->sptr_routing_table_entry->path_cost > best_sptr_routing_table_node->sptr_routing_table_entry->path_cost)#else if (sptr_routing_table_node->sptr_routing_table_entry->path_cost < best_sptr_routing_table_node->sptr_routing_table_entry->path_cost)#endif { best_sptr_routing_table_node = sptr_routing_table_node; } } } } } } if (best_sptr_routing_table_node != NULL) { return (best_sptr_routing_table_node->sptr_routing_table_entry); } return (NULL);}/*******************************************************************************************************************************/OSPF_ROUTING_TABLE_ENTRY *ospf_find_routing_table_entry_1583_asbr (ULONG destination_id_to_look){ OSPF_ROUTING_TABLE_NODE *sptr_routing_table_node; OSPF_ROUTING_TABLE_NODE *best_sptr_routing_table_node = NULL; ULONG hash_id; enum BOOLEAN first_pass = TRUE; OSPF_PRINTF_DEBUG (OSPF_DEBUG_PRINTF, "OSPF: Entering ospf_find_routing_table_entry_1583_asbr\r\n"); hash_id = destination_id_to_look; hash_id = hash_id & OSPF_RT_HASH_MASK; for(sptr_routing_table_node = ospf.sptr_routing_table_head[OSPF_ROUTE_TABLE_ROUTER][hash_id]; sptr_routing_table_node != NULL; sptr_routing_table_node = sptr_routing_table_node->sptr_forward_link) { if ((sptr_routing_table_node->sptr_routing_table_entry->destination_type == OSPF_DESTINATION_TYPE_ASBR) && (sptr_routing_table_node->sptr_routing_table_entry->destination_id == destination_id_to_look)) { if (sptr_routing_table_node->route_node_status != OSPF_ROUTE_IS_NOT_AVAILABLE_NOW) /* Jack July ### */ { if (first_pass) { best_sptr_routing_table_node = sptr_routing_table_node; first_pass = FALSE; } else { if (ospf.ospf_rfc1583_compatibility == FALSE) { /* non rfc1583 compliance search */ if (((sptr_routing_table_node->sptr_routing_table_entry->path_type == OSPF_ROUTE_PATH_TYPE_INTRA) && (sptr_routing_table_node->sptr_routing_table_entry->sptr_area->area_id != OSPF_BACKBONE)) && ((best_sptr_routing_table_node->sptr_routing_table_entry->path_type == OSPF_ROUTE_PATH_TYPE_INTRA) && (best_sptr_routing_table_node->sptr_routing_table_entry->sptr_area->area_id != OSPF_BACKBONE)))
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -