📄 ip_cmn_rte_table.ex.c
字号:
}
/* No matching route could be found. Return failure. */
#ifndef OPD_NO_DEBUG
if (op_prg_odb_ltrace_active ("ip_cmn_rte_table"))
{
op_prg_odb_print_minor ("Could not find a matching entry.", OPC_NIL);
}
#endif
FRET (OPC_COMPCODE_FAILURE);
}
static Compcode
ip_cmn_rte_default_route_next_hop_delete (IpT_Cmn_Rte_Table* cmn_rte_table,
InetT_Address next_hop, IpT_Rte_Proc_Id proto)
{
IpT_Cmn_Rte_Table_Entry* default_route_ptr;
int index;
/** A dynamic routing protocol is withdrawing a next **/
/** hop of a 0/0 route from the common route table. **/
FIN (ip_cmn_rte_default_route_next_hop_delete (cmn_rte_table, next_hop, proto));
/* Print trace information. */
#ifndef OPD_NO_DEBUG
if (op_prg_odb_ltrace_active ("ip_cmn_rte_table"))
{
char trace_msg [256];
char src_proto_str [64];
char nh_str [INETC_ADDR_STR_LEN];
ip_cmn_rte_proto_name_print (src_proto_str, proto);
inet_address_print (nh_str, next_hop);
/* And now the full message. */
sprintf (trace_msg, "Deleting NH (%s) of the default route inserted by \"%s\".", nh_str, src_proto_str);
op_prg_odb_print_major (trace_msg, OPC_NIL);
}
#endif
/* Search for a default route inserted by the specified */
/* protocol in the list of resolved default routes. */
default_route_ptr = ip_cmn_rte_default_route_list_find
(cmn_rte_table->resolved_default_routes, proto, &index);
/* If we found a route, remove the specified next hop. */
if (OPC_NIL != default_route_ptr)
{
/* Call the function that will delete the next hop. */
/* If the specified next hop could not be found, the*/
/* function will return 0. */
if (0 != ip_cmn_rte_next_hop_delete (cmn_rte_table, default_route_ptr, next_hop))
{
/* We found a matching next hop. */
#ifndef OPD_NO_DEBUG
if (op_prg_odb_ltrace_active ("ip_cmn_rte_table"))
{
op_prg_odb_print_minor ("Found a matching entry in the list of resolved default routes.", OPC_NIL);
}
#endif
/* If we deleted the last next hop. Remove the entry*/
/* altogether. */
if (0 == op_prg_list_size (default_route_ptr->next_hop_list))
{
ip_cmn_rte_default_route_delete (cmn_rte_table, proto, OPC_NIL);
}
/* If this is the current best default route, check */
/* if the gateway of last resort or the best default*/
/* route needs to be updated. */
else if (default_route_ptr == cmn_rte_table->best_default_route)
{
/* Update statistics for this route table. */
op_stat_write (cmn_rte_table->update_stathandle [IpC_Rte_Table_Any_Update], 1.0);
op_stat_write (cmn_rte_table->update_stathandle [IpC_Rte_Table_Next_Hop_Update], 1.0);
if (oms_routing_convergence_status_check (cmn_rte_table->convg_handle) == OmsC_Convergence_Reached)
{
char dest_str [INETC_ADDR_STR_LEN];
char src_proto_str [16];
char convergence_reason [256];
ip_cmn_rte_table_dest_prefix_print (dest_str, default_route_ptr->dest_prefix);
ip_cmn_rte_proto_name_print (src_proto_str, proto);
sprintf(convergence_reason,
"Updated %s route to destination %s", src_proto_str, dest_str);
ip_cmn_rte_table_last_update_time_set (cmn_rte_table, convergence_reason);
}
else
{
ip_cmn_rte_table_last_update_time_set (cmn_rte_table, OPC_NIL);
}
/* Update the gateway of last resort and the */
/* best default route. */
ip_cmn_rte_gateway_of_last_resort_update (cmn_rte_table);
/* If the best default route changed, send an */
/* UPDATE redistribution interrupt. */
if (default_route_ptr != cmn_rte_table->best_default_route)
{
/* Send an update interrupt to other */
/* protocols. */
ip_cmn_rte_table_entry_redistribute (cmn_rte_table, cmn_rte_table->best_default_route,
IPC_REDIST_TYPE_UPDATE, proto);
}
else
{
/* The BDR has not changed, but it has lost */
/* a next hop. Send an update interrupt. */
ip_cmn_rte_table_entry_redistribute (cmn_rte_table, default_route_ptr,
IPC_REDIST_TYPE_UPDATE, IpC_Dyn_Rte_Invalid);
}
}
/* Return success to indicate that a matching route */
/* was found. */
FRET (OPC_COMPCODE_SUCCESS);
}
}
/* We did not find a match in the list of resolved */
/* default routes. Try the list of unresolved default */
/* routes. */
default_route_ptr = ip_cmn_rte_default_route_list_find
(cmn_rte_table->unresolved_default_routes, proto, &index);
/* If we found a route, remove the specified next hop. */
if (OPC_NIL != default_route_ptr)
{
/* Call the function that will delete the next hop. */
/* If the specified next hop could not be found, the*/
/* function will return 0. */
if (0 == ip_cmn_rte_next_hop_delete (cmn_rte_table, default_route_ptr, next_hop))
{
/* Invalid next hop. Return failure. */
FRET (OPC_COMPCODE_FAILURE);
}
#ifndef OPD_NO_DEBUG
if (op_prg_odb_ltrace_active ("ip_cmn_rte_table"))
{
op_prg_odb_print_minor ("Found a matching entry in the list of unresolved default routes.", OPC_NIL);
}
#endif
/* If we deleted the last next hop. Remove the entry*/
/* altogether. */
if (0 == op_prg_list_size (default_route_ptr->next_hop_list))
{
op_prg_list_remove (cmn_rte_table->unresolved_default_routes, index);
/* Free the memory allocated to the entry. */
ip_cmn_rte_table_entry_free (default_route_ptr, cmn_rte_table);
}
/* Return success to indicate that a matching route */
/* was found. */
FRET (OPC_COMPCODE_SUCCESS);
}
/* We did not find a matching route. Return failure. */
FRET (OPC_COMPCODE_FAILURE);
}
static Compcode
ip_cmn_rte_table_default_route_update (IpT_Cmn_Rte_Table* route_table,
InetT_Address next_hop, IpT_Rte_Proc_Id proto, InetT_Address new_next_hop,
IpT_Port_Info new_port_info, int new_metric, void* src_obj_ptr)
{
IpT_Cmn_Rte_Table_Entry* rte_entry_ptr;
IpT_Cmn_Rte_Table_Entry* old_best_default_route;
int index;
int admin_distance;
Compcode status;
int changed;
/** Update the next hop and/or metric of a 0.0.0.0/0 route **/
FIN (ip_cmn_rte_table_default_route_update (route_table, next_hop, ...));
/* If the new next hop specified is valid, it means that */
/* we need to update the next hop also. */
if (inet_address_valid (new_next_hop))
{
/* Just delete the existing route and add a new one. */
/* TODO: Do a proper update rather than a delete and add*/
#ifndef OPD_NO_DEBUG
if (op_prg_odb_ltrace_active ("ip_cmn_rte_table"))
{
char trace_msg [256];
char src_proto_str [64];
char old_nh_str [INETC_ADDR_STR_LEN];
char new_nh_str [INETC_ADDR_STR_LEN];
/* Print src_proto, next hop etc. */
ip_cmn_rte_proto_name_print (src_proto_str, proto);
inet_address_print (old_nh_str, next_hop);
inet_address_print (new_nh_str, new_next_hop);
sprintf (trace_msg,
"Old Next Hop |%s|, New Next Hop |%s|, O/P Intf. |%d|, Metric |%d| and Src. Proto. |%s|.",
old_nh_str, new_nh_str, ip_rte_intf_tbl_index_from_port_info_get (route_table->iprmd_ptr, new_port_info),
new_metric, src_proto_str);
/* And now the full message. */
op_prg_odb_print_major ("Changing the next hop of a default route", OPC_NIL);
op_prg_odb_print_minor (trace_msg, OPC_NIL);
}
#endif
/* Delete the old route. */
status = ip_cmn_rte_default_route_delete (route_table, proto, &admin_distance);
/* Make sure that there was a matching route. */
if (OPC_COMPCODE_SUCCESS == status)
{
/* We have successfully deleted the old route. */
/* Add the new route. */
ip_cmn_rte_default_route_add (route_table, src_obj_ptr,
new_next_hop, new_port_info, new_metric, proto, admin_distance);
}
/* Return the status. */
FRET (status);
}
/* The new next hop is invalid. So we only need to update */
/* the metric. */
#ifndef OPD_NO_DEBUG
if (op_prg_odb_ltrace_active ("ip_cmn_rte_table"))
{
char trace_msg [256];
char src_proto_str [64];
char nh_str [INETC_ADDR_STR_LEN];
/* Print src_proto, next hop etc. */
ip_cmn_rte_proto_name_print (src_proto_str, proto);
inet_address_print (nh_str, next_hop);
sprintf (trace_msg,
"Next Hop |%s|, Metric |%d| and Src. Proto. |%s|.",
nh_str, new_metric, src_proto_str);
/* And now the full message. */
op_prg_odb_print_major ("Changing the metric of a default route", OPC_NIL);
op_prg_odb_print_minor (trace_msg, OPC_NIL);
}
#endif
/* Cache the current best default route. */
old_best_default_route = route_table->best_default_route;
/* Search for a default route inserted by the specified */
/* protocol in the list of resolved default routes. */
rte_entry_ptr = ip_cmn_rte_default_route_list_find
(route_table->resolved_default_routes, proto, &index);
/* Did we find a matching entry? */
if (OPC_NIL != rte_entry_ptr)
{
/* A resolved default route is being updated. Update the*/
/* metric of the specified next hop. */
changed = ip_cmn_rte_next_hop_update (rte_entry_ptr, next_hop, INETC_ADDRESS_INVALID,
new_port_info, new_metric, route_table);
/* If the entry was changed, update the gateway of */
/* last resort. */
if (changed)
{
/* Update the gateway of last resort and the best */
/* default route. */
ip_cmn_rte_gateway_of_last_resort_update (route_table);
/* Update statistics for this route table. */
op_stat_write (route_table->update_stathandle [IpC_Rte_Table_Any_Update], 1.0);
if (oms_routing_convergence_status_check (route_table->convg_handle) == OmsC_Convergence_Reached)
{
char dest_str [INETC_ADDR_STR_LEN];
char src_proto_str [16];
char convergence_reason [256];
ip_cmn_rte_table_dest_prefix_print (dest_str, rte_entry_ptr->dest_prefix);
ip_cmn_rte_proto_name_print (src_proto_str, proto);
if (!strcmp (src_proto_str, "Direct"))
strcpy (src_proto_str, "Local");
sprintf(convergence_reason,
"Updated %s route to destination %s", src_proto_str, dest_str);
ip_cmn_rte_table_last_update_time_set (route_table, convergence_reason);
}
else
{
ip_cmn_rte_table_last_update_time_set (route_table, OPC_NIL);
}
/* Redistribute the changed route to other protocols*/
/* if necessary. */
/* Did the best default route change. */
if (old_best_default_route != route_table->best_default_route)
{
/* The BDR is now a different route, send an */
/* update interrupt. */
ip_cmn_rte_table_entry_redistribute (route_table, route_table->best_default_route,
IPC_REDIST_TYPE_UPDATE, old_best_default_route->route_src_proto);
}
/* The BDR is still the same entry. But it is the */
/* entry whose metric we updated, we still need to */
/* send an UPDATE redistribution interrupt. */
else if (old_best_default_route == rte_entry_ptr)
{
/* The metric of the BDR has changed. */
ip_cmn_rte_table_entry_redistribute (route_table, rte_entry_ptr,
IPC_REDIST_TYPE_UPDATE, IpC_Dyn_Rte_Invalid);
}
/*
else
{
The entry that we updated was not the BDR and it
did not become the BDR. No redistribution needed
}
*/
}
}
else
{
/* We did not find a matching route in the list of */
/* resolved default routes. Try the list of unresolved */
/* default_routes. */
rte_entry_ptr = ip_cmn_rte_default_route_list_find
(route_table->unresolved_default_routes, proto, &index);
/* If we found a matching route, update its metric. */
if (OPC_
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -