📄 ospf_ase.c
字号:
/* * OSPF AS external route calculation. * Copyright (C) 1999, 2000 Alex Zinin, Toshiaki Takada * * This file is part of GNU Zebra. * * GNU Zebra is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License as published by the * Free Software Foundation; either version 2, or (at your option) any * later version. * * GNU Zebra is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * General Public License for more details. * * You should have received a copy of the GNU General Public License * along with GNU Zebra; see the file COPYING. If not, write to the Free * Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA * 02111-1307, USA. */#include <zebra.h>#include "thread.h"#include "memory.h"#include "hash.h"#include "linklist.h"#include "prefix.h"#include "if.h"#include "table.h"#include "vty.h"#include "log.h"#include "ospfd/ospfd.h"#include "ospfd/ospf_interface.h"#include "ospfd/ospf_ism.h"#include "ospfd/ospf_asbr.h"#include "ospfd/ospf_lsa.h"#include "ospfd/ospf_lsdb.h"#include "ospfd/ospf_neighbor.h"#include "ospfd/ospf_nsm.h"#include "ospfd/ospf_spf.h"#include "ospfd/ospf_route.h"#include "ospfd/ospf_ase.h"#include "ospfd/ospf_zebra.h"#include "ospfd/ospf_dump.h"#define DEBUGstruct ospf_route *ospf_find_asbr_route (struct ospf *ospf, struct route_table *rtrs, struct prefix_ipv4 *asbr){ struct route_node *rn; struct ospf_route *or, *best = NULL; listnode node; list chosen; /* Sanity check. */ if (rtrs == NULL) return NULL; rn = route_node_lookup (rtrs, (struct prefix *) asbr); if (! rn) return NULL; route_unlock_node (rn); chosen = list_new (); /* First try to find intra-area non-bb paths. */ if (!CHECK_FLAG (ospf->config, OSPF_RFC1583_COMPATIBLE)) for (node = listhead ((list) rn->info); node; nextnode (node)) if ((or = getdata (node)) != NULL) if (or->cost < OSPF_LS_INFINITY) if (!OSPF_IS_AREA_ID_BACKBONE (or->u.std.area_id) && or->path_type == OSPF_PATH_INTRA_AREA) listnode_add (chosen, or); /* If none is found -- look through all. */ if (listcount (chosen) == 0) { list_free (chosen); chosen = rn->info; } /* Now find the route with least cost. */ for (node = listhead (chosen); node; nextnode (node)) if ((or = getdata (node)) != NULL) if (or->cost < OSPF_LS_INFINITY) { if (best == NULL) best = or; else if (best->cost > or->cost) best = or; else if (best->cost == or->cost && IPV4_ADDR_CMP (&best->u.std.area_id, &or->u.std.area_id) < 0) best = or; } if (chosen != rn->info) list_delete (chosen); return best;}struct ospf_route * ospf_find_asbr_route_through_area (struct route_table *rtrs, struct prefix_ipv4 *asbr, struct ospf_area *area){ struct route_node *rn; /* Sanity check. */ if (rtrs == NULL) return NULL; rn = route_node_lookup (rtrs, (struct prefix *) asbr); if (rn) { listnode node; struct ospf_route *or; route_unlock_node (rn); for (node = listhead ((list) rn->info); node; nextnode (node)) if ((or = getdata (node)) != NULL) if (IPV4_ADDR_SAME (&or->u.std.area_id, &area->area_id)) return or; } return NULL;}voidospf_ase_complete_direct_routes (struct ospf_route *ro, struct in_addr nexthop){ listnode node; struct ospf_path *op; for (node = listhead (ro->path); node; nextnode (node)) if ((op = getdata (node)) != NULL) if (op->nexthop.s_addr == 0) op->nexthop.s_addr = nexthop.s_addr;}intospf_ase_forward_address_check (struct ospf *ospf, struct in_addr fwd_addr){ listnode ifn; struct ospf_interface *oi; for (ifn = listhead (ospf->oiflist); ifn; nextnode (ifn)) if ((oi = getdata (ifn)) != NULL) if (if_is_up (oi->ifp)) if (oi->type != OSPF_IFTYPE_VIRTUALLINK) if (IPV4_ADDR_SAME (&oi->address->u.prefix4, &fwd_addr)) return 0; return 1;}/* Calculate ASBR route. */struct ospf_route *ospf_ase_calculate_asbr_route (struct ospf *ospf, struct route_table *rt_network, struct route_table *rt_router, struct as_external_lsa *al){ struct prefix_ipv4 asbr; struct ospf_route *asbr_route; struct route_node *rn; /* Find ASBR route from Router routing table. */ asbr.family = AF_INET; asbr.prefix = al->header.adv_router; asbr.prefixlen = IPV4_MAX_BITLEN; apply_mask_ipv4 (&asbr); asbr_route = ospf_find_asbr_route (ospf, rt_router, &asbr); if (asbr_route == NULL) { zlog_info ("ospf_ase_calculate(): Route to ASBR %s not found", inet_ntoa (asbr.prefix)); return NULL; } if (!(asbr_route->u.std.flags & ROUTER_LSA_EXTERNAL)) { zlog_info ("ospf_ase_calculate(): Originating router is not an ASBR"); return NULL; } if (al->e[0].fwd_addr.s_addr != 0) { zlog_info ("ospf_ase_calculate(): " "Forwarding address is not 0.0.0.0."); if (! ospf_ase_forward_address_check (ospf, al->e[0].fwd_addr)) { zlog_info ("ospf_ase_calculate(): " "Forwarding address is one of our addresses, Ignore."); return NULL; } zlog_info ("ospf_ase_calculate(): " "Looking up in the Network Routing Table."); /* Looking up the path to the fwd_addr from Network route. */ asbr.family = AF_INET; asbr.prefix = al->e[0].fwd_addr; asbr.prefixlen = IPV4_MAX_BITLEN; rn = route_node_match (rt_network, (struct prefix *) &asbr); if (rn == NULL) { zlog_info ("ospf_ase_calculate(): " "Couldn't find a route to the forwarding address."); return NULL; } route_unlock_node (rn); if ((asbr_route = rn->info) == NULL) { zlog_info ("ospf_ase_calculate(): " "Somehow OSPF route to ASBR is lost"); return NULL; } } return asbr_route;}struct ospf_route *ospf_ase_calculate_new_route (struct ospf_lsa *lsa, struct ospf_route *asbr_route, u_int32_t metric){ struct as_external_lsa *al; struct ospf_route *new; al = (struct as_external_lsa *) lsa->data; new = ospf_route_new (); /* Set redistributed type -- does make sense? */ /* new->type = type; */ new->id = al->header.id; new->mask = al->mask; if (!IS_EXTERNAL_METRIC (al->e[0].tos)) { zlog_info ("Route[External]: type-1 created."); new->path_type = OSPF_PATH_TYPE1_EXTERNAL; new->cost = asbr_route->cost + metric; /* X + Y */ } else { zlog_info ("Route[External]: type-2 created."); new->path_type = OSPF_PATH_TYPE2_EXTERNAL; new->cost = asbr_route->cost; /* X */ new->u.ext.type2_cost = metric; /* Y */ } new->type = OSPF_DESTINATION_NETWORK; new->path = list_new (); new->u.ext.origin = lsa; new->u.ext.tag = ntohl (al->e[0].route_tag); new->u.ext.asbr = asbr_route; assert (new != asbr_route); return new;}#define OSPF_ASE_CALC_INTERVAL 1intospf_ase_calculate_route (struct ospf *ospf, struct ospf_lsa * lsa){ u_int32_t metric; struct as_external_lsa *al; struct ospf_route *asbr_route; struct prefix_ipv4 asbr, p; struct route_node *rn; struct ospf_route *new, *or; int ret; assert (lsa); al = (struct as_external_lsa *) lsa->data;#ifdef HAVE_NSSA if (lsa->data->type == OSPF_AS_NSSA_LSA) if (IS_DEBUG_OSPF_NSSA) zlog_info ("ospf_ase_calc(): Processing Type-7"); /* Stay away from any Local Translated Type-7 LSAs */ if (CHECK_FLAG (lsa->flags, OSPF_LSA_LOCAL_XLT)) { if (IS_DEBUG_OSPF_NSSA) zlog_info ("ospf_ase_calc(): Rejecting Local Xlt'd"); return 0; }#endif /* HAVE_NSSA */ zlog_info ("Route[External]: Calculate AS-external-LSA to %s/%d", inet_ntoa (al->header.id), ip_masklen (al->mask)); /* (1) If the cost specified by the LSA is LSInfinity, or if the LSA's LS age is equal to MaxAge, then examine the next LSA. */ if ((metric = GET_METRIC (al->e[0].metric)) >= OSPF_LS_INFINITY) { zlog_info ("Route[External]: Metric is OSPF_LS_INFINITY"); return 0; } if (IS_LSA_MAXAGE (lsa)) { zlog_info ("Route[External]: AS-external-LSA is MAXAGE"); return 0; } /* (2) If the LSA was originated by the calculating router itself, examine the next LSA. */ if (IS_LSA_SELF (lsa)) { zlog_info ("Route[External]: AS-external-LSA is self originated"); return 0; } /* (3) Call the destination described by the LSA N. N's address is obtained by masking the LSA's Link State ID with the network/subnet mask contained in the body of the LSA. Look up the routing table entries (potentially one per attached area) for the AS boundary router (ASBR) that originated the LSA. If no entries exist for router ASBR (i.e., ASBR is unreachable), do nothing with this LSA and consider the next in the list. */ asbr.family = AF_INET; asbr.prefix = al->header.adv_router; asbr.prefixlen = IPV4_MAX_BITLEN; apply_mask_ipv4 (&asbr); asbr_route = ospf_find_asbr_route (ospf, ospf->new_rtrs, &asbr); if (asbr_route == NULL) { zlog_info ("Route[External]: Can't find originating ASBR route"); return 0; } if (!(asbr_route->u.std.flags & ROUTER_LSA_EXTERNAL)) { zlog_info ("Route[External]: Originating router is not an ASBR"); return 0; } /* Else, this LSA describes an AS external path to destination N. Examine the forwarding address specified in the AS- external-LSA. This indicates the IP address to which packets for the destination should be forwarded. */ if (al->e[0].fwd_addr.s_addr == 0) { /* If the forwarding address is set to 0.0.0.0, packets should be sent to the ASBR itself. Among the multiple routing table entries for the ASBR, select the preferred entry as follows. If RFC1583Compatibility is set to "disabled", prune the set of routing table entries for the ASBR as described in Section 16.4.1. In any case, among the remaining routing table entries, select the routing table entry with the least cost; when there are multiple least cost routing table entries the entry whose associated area has the largest OSPF Area ID (when considered as an unsigned 32-bit integer) is chosen. */ /* asbr_route already contains the requested route */ } else { /* If the forwarding address is non-zero, look up the forwarding address in the routing table.[24] The matching routing table entry must specify an intra-area or inter-area path; if no such path exists, do nothing with the LSA and consider the next in the list. */ if (! ospf_ase_forward_address_check (ospf, al->e[0].fwd_addr)) { zlog_info ("Route[External]: Forwarding address is our router address"); return 0; } asbr.family = AF_INET; asbr.prefix = al->e[0].fwd_addr; asbr.prefixlen = IPV4_MAX_BITLEN; rn = route_node_match (ospf->new_table, (struct prefix *) &asbr); if (rn == NULL || (asbr_route = rn->info) == NULL) { zlog_info ("Route[External]: Can't find route to forwarding address"); if (rn) route_unlock_node (rn); return 0; } route_unlock_node (rn); } /* (4) Let X be the cost specified by the preferred routing table entry for the ASBR/forwarding address, and Y the cost specified in the LSA. X is in terms of the link state metric, and Y is a type 1 or 2 external metric. */ /* (5) Look up the routing table entry for the destination N. If no entry exists for N, install the AS external path to N, with next hop equal to the list of next hops to the forwarding address, and advertising router equal to ASBR. If the external metric type is 1, then the path-type is set
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -