paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1 | /* |
| 2 | * OSPF AS external route calculation. |
| 3 | * Copyright (C) 1999, 2000 Alex Zinin, Toshiaki Takada |
| 4 | * |
| 5 | * This file is part of GNU Zebra. |
| 6 | * |
| 7 | * GNU Zebra is free software; you can redistribute it and/or modify it |
| 8 | * under the terms of the GNU General Public License as published by the |
| 9 | * Free Software Foundation; either version 2, or (at your option) any |
| 10 | * later version. |
| 11 | * |
| 12 | * GNU Zebra is distributed in the hope that it will be useful, but |
| 13 | * WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 15 | * General Public License for more details. |
| 16 | * |
| 17 | * You should have received a copy of the GNU General Public License |
| 18 | * along with GNU Zebra; see the file COPYING. If not, write to the Free |
| 19 | * Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA |
| 20 | * 02111-1307, USA. |
| 21 | */ |
| 22 | |
| 23 | #include <zebra.h> |
| 24 | |
| 25 | #include "thread.h" |
| 26 | #include "memory.h" |
| 27 | #include "hash.h" |
| 28 | #include "linklist.h" |
| 29 | #include "prefix.h" |
| 30 | #include "if.h" |
| 31 | #include "table.h" |
| 32 | #include "vty.h" |
| 33 | #include "log.h" |
| 34 | |
| 35 | #include "ospfd/ospfd.h" |
| 36 | #include "ospfd/ospf_interface.h" |
| 37 | #include "ospfd/ospf_ism.h" |
| 38 | #include "ospfd/ospf_asbr.h" |
| 39 | #include "ospfd/ospf_lsa.h" |
| 40 | #include "ospfd/ospf_lsdb.h" |
| 41 | #include "ospfd/ospf_neighbor.h" |
| 42 | #include "ospfd/ospf_nsm.h" |
| 43 | #include "ospfd/ospf_spf.h" |
| 44 | #include "ospfd/ospf_route.h" |
| 45 | #include "ospfd/ospf_ase.h" |
| 46 | #include "ospfd/ospf_zebra.h" |
| 47 | #include "ospfd/ospf_dump.h" |
| 48 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 49 | struct ospf_route * |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 50 | ospf_find_asbr_route (struct ospf *ospf, |
| 51 | struct route_table *rtrs, struct prefix_ipv4 *asbr) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 52 | { |
| 53 | struct route_node *rn; |
| 54 | struct ospf_route *or, *best = NULL; |
hasso | 52dc7ee | 2004-09-23 19:18:23 +0000 | [diff] [blame] | 55 | struct listnode *node; |
| 56 | struct list *chosen; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 57 | |
| 58 | /* Sanity check. */ |
| 59 | if (rtrs == NULL) |
| 60 | return NULL; |
| 61 | |
| 62 | rn = route_node_lookup (rtrs, (struct prefix *) asbr); |
| 63 | if (! rn) |
| 64 | return NULL; |
| 65 | |
| 66 | route_unlock_node (rn); |
| 67 | |
| 68 | chosen = list_new (); |
| 69 | |
| 70 | /* First try to find intra-area non-bb paths. */ |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 71 | if (!CHECK_FLAG (ospf->config, OSPF_RFC1583_COMPATIBLE)) |
paul | 1eb8ef2 | 2005-04-07 07:30:20 +0000 | [diff] [blame] | 72 | for (ALL_LIST_ELEMENTS_RO ((struct list *) rn->info, node, or)) |
| 73 | if (or->cost < OSPF_LS_INFINITY) |
| 74 | if (!OSPF_IS_AREA_ID_BACKBONE (or->u.std.area_id) && |
| 75 | or->path_type == OSPF_PATH_INTRA_AREA) |
| 76 | listnode_add (chosen, or); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 77 | |
| 78 | /* If none is found -- look through all. */ |
| 79 | if (listcount (chosen) == 0) |
| 80 | { |
| 81 | list_free (chosen); |
| 82 | chosen = rn->info; |
| 83 | } |
| 84 | |
| 85 | /* Now find the route with least cost. */ |
paul | 1eb8ef2 | 2005-04-07 07:30:20 +0000 | [diff] [blame] | 86 | for (ALL_LIST_ELEMENTS_RO (chosen, node, or)) |
| 87 | if (or->cost < OSPF_LS_INFINITY) |
| 88 | { |
| 89 | if (best == NULL) |
| 90 | best = or; |
| 91 | else if (best->cost > or->cost) |
| 92 | best = or; |
| 93 | else if (best->cost == or->cost && |
| 94 | IPV4_ADDR_CMP (&best->u.std.area_id, |
| 95 | &or->u.std.area_id) < 0) |
| 96 | best = or; |
| 97 | } |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 98 | |
| 99 | if (chosen != rn->info) |
| 100 | list_delete (chosen); |
| 101 | |
| 102 | return best; |
| 103 | } |
| 104 | |
| 105 | struct ospf_route * |
| 106 | ospf_find_asbr_route_through_area (struct route_table *rtrs, |
| 107 | struct prefix_ipv4 *asbr, |
| 108 | struct ospf_area *area) |
| 109 | { |
| 110 | struct route_node *rn; |
| 111 | |
| 112 | /* Sanity check. */ |
| 113 | if (rtrs == NULL) |
| 114 | return NULL; |
| 115 | |
| 116 | rn = route_node_lookup (rtrs, (struct prefix *) asbr); |
| 117 | |
| 118 | if (rn) |
| 119 | { |
hasso | 52dc7ee | 2004-09-23 19:18:23 +0000 | [diff] [blame] | 120 | struct listnode *node; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 121 | struct ospf_route *or; |
| 122 | |
| 123 | route_unlock_node (rn); |
| 124 | |
paul | 1eb8ef2 | 2005-04-07 07:30:20 +0000 | [diff] [blame] | 125 | for (ALL_LIST_ELEMENTS_RO ((struct list *) rn->info, node, or)) |
| 126 | if (IPV4_ADDR_SAME (&or->u.std.area_id, &area->area_id)) |
| 127 | return or; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 128 | } |
| 129 | |
| 130 | return NULL; |
| 131 | } |
| 132 | |
paul | 4dadc29 | 2005-05-06 21:37:42 +0000 | [diff] [blame] | 133 | static void |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 134 | ospf_ase_complete_direct_routes (struct ospf_route *ro, struct in_addr nexthop) |
| 135 | { |
hasso | 52dc7ee | 2004-09-23 19:18:23 +0000 | [diff] [blame] | 136 | struct listnode *node; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 137 | struct ospf_path *op; |
| 138 | |
paul | 1eb8ef2 | 2005-04-07 07:30:20 +0000 | [diff] [blame] | 139 | for (ALL_LIST_ELEMENTS_RO (ro->paths, node, op)) |
| 140 | if (op->nexthop.s_addr == 0) |
| 141 | op->nexthop.s_addr = nexthop.s_addr; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 142 | } |
| 143 | |
paul | 4dadc29 | 2005-05-06 21:37:42 +0000 | [diff] [blame] | 144 | static int |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 145 | ospf_ase_forward_address_check (struct ospf *ospf, struct in_addr fwd_addr) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 146 | { |
hasso | 52dc7ee | 2004-09-23 19:18:23 +0000 | [diff] [blame] | 147 | struct listnode *ifn; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 148 | struct ospf_interface *oi; |
| 149 | |
paul | 1eb8ef2 | 2005-04-07 07:30:20 +0000 | [diff] [blame] | 150 | for (ALL_LIST_ELEMENTS_RO (ospf->oiflist, ifn, oi)) |
| 151 | if (if_is_operative (oi->ifp)) |
| 152 | if (oi->type != OSPF_IFTYPE_VIRTUALLINK) |
| 153 | if (IPV4_ADDR_SAME (&oi->address->u.prefix4, &fwd_addr)) |
| 154 | return 0; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 155 | |
| 156 | return 1; |
| 157 | } |
| 158 | |
| 159 | /* Calculate ASBR route. */ |
paul | 4dadc29 | 2005-05-06 21:37:42 +0000 | [diff] [blame] | 160 | static struct ospf_route * |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 161 | ospf_ase_calculate_asbr_route (struct ospf *ospf, |
| 162 | struct route_table *rt_network, |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 163 | struct route_table *rt_router, |
| 164 | struct as_external_lsa *al) |
| 165 | { |
| 166 | struct prefix_ipv4 asbr; |
| 167 | struct ospf_route *asbr_route; |
| 168 | struct route_node *rn; |
| 169 | |
| 170 | /* Find ASBR route from Router routing table. */ |
| 171 | asbr.family = AF_INET; |
| 172 | asbr.prefix = al->header.adv_router; |
| 173 | asbr.prefixlen = IPV4_MAX_BITLEN; |
| 174 | apply_mask_ipv4 (&asbr); |
| 175 | |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 176 | asbr_route = ospf_find_asbr_route (ospf, rt_router, &asbr); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 177 | |
| 178 | if (asbr_route == NULL) |
| 179 | { |
hasso | e40dcce | 2005-02-21 14:58:42 +0000 | [diff] [blame] | 180 | if (IS_DEBUG_OSPF (lsa, LSA)) |
| 181 | zlog_debug ("ospf_ase_calculate(): Route to ASBR %s not found", |
| 182 | inet_ntoa (asbr.prefix)); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 183 | return NULL; |
| 184 | } |
| 185 | |
| 186 | if (!(asbr_route->u.std.flags & ROUTER_LSA_EXTERNAL)) |
| 187 | { |
hasso | e40dcce | 2005-02-21 14:58:42 +0000 | [diff] [blame] | 188 | if (IS_DEBUG_OSPF (lsa, LSA)) |
| 189 | zlog_debug ("ospf_ase_calculate(): Originating router is not an ASBR"); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 190 | return NULL; |
| 191 | } |
| 192 | |
| 193 | if (al->e[0].fwd_addr.s_addr != 0) |
| 194 | { |
hasso | e40dcce | 2005-02-21 14:58:42 +0000 | [diff] [blame] | 195 | if (IS_DEBUG_OSPF (lsa, LSA)) |
| 196 | zlog_debug ("ospf_ase_calculate(): " |
| 197 | "Forwarding address is not 0.0.0.0."); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 198 | |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 199 | if (! ospf_ase_forward_address_check (ospf, al->e[0].fwd_addr)) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 200 | { |
hasso | e40dcce | 2005-02-21 14:58:42 +0000 | [diff] [blame] | 201 | if (IS_DEBUG_OSPF (lsa, LSA)) |
| 202 | zlog_debug ("ospf_ase_calculate(): " |
| 203 | "Forwarding address is one of our addresses, Ignore."); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 204 | return NULL; |
| 205 | } |
| 206 | |
hasso | e40dcce | 2005-02-21 14:58:42 +0000 | [diff] [blame] | 207 | if (IS_DEBUG_OSPF (lsa, LSA)) |
| 208 | zlog_debug ("ospf_ase_calculate(): " |
| 209 | "Looking up in the Network Routing Table."); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 210 | |
| 211 | /* Looking up the path to the fwd_addr from Network route. */ |
| 212 | asbr.family = AF_INET; |
| 213 | asbr.prefix = al->e[0].fwd_addr; |
| 214 | asbr.prefixlen = IPV4_MAX_BITLEN; |
| 215 | |
| 216 | rn = route_node_match (rt_network, (struct prefix *) &asbr); |
| 217 | |
| 218 | if (rn == NULL) |
| 219 | { |
hasso | e40dcce | 2005-02-21 14:58:42 +0000 | [diff] [blame] | 220 | if (IS_DEBUG_OSPF (lsa, LSA)) |
| 221 | zlog_debug ("ospf_ase_calculate(): " |
| 222 | "Couldn't find a route to the forwarding address."); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 223 | return NULL; |
| 224 | } |
| 225 | |
| 226 | route_unlock_node (rn); |
| 227 | |
| 228 | if ((asbr_route = rn->info) == NULL) |
| 229 | { |
hasso | e40dcce | 2005-02-21 14:58:42 +0000 | [diff] [blame] | 230 | if (IS_DEBUG_OSPF (lsa, LSA)) |
| 231 | zlog_debug ("ospf_ase_calculate(): " |
| 232 | "Somehow OSPF route to ASBR is lost"); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 233 | return NULL; |
| 234 | } |
| 235 | } |
| 236 | |
| 237 | return asbr_route; |
| 238 | } |
| 239 | |
paul | 4dadc29 | 2005-05-06 21:37:42 +0000 | [diff] [blame] | 240 | static struct ospf_route * |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 241 | ospf_ase_calculate_new_route (struct ospf_lsa *lsa, |
| 242 | struct ospf_route *asbr_route, u_int32_t metric) |
| 243 | { |
| 244 | struct as_external_lsa *al; |
| 245 | struct ospf_route *new; |
| 246 | |
| 247 | al = (struct as_external_lsa *) lsa->data; |
| 248 | |
| 249 | new = ospf_route_new (); |
| 250 | |
| 251 | /* Set redistributed type -- does make sense? */ |
| 252 | /* new->type = type; */ |
| 253 | new->id = al->header.id; |
| 254 | new->mask = al->mask; |
| 255 | |
| 256 | if (!IS_EXTERNAL_METRIC (al->e[0].tos)) |
| 257 | { |
hasso | e40dcce | 2005-02-21 14:58:42 +0000 | [diff] [blame] | 258 | if (IS_DEBUG_OSPF (lsa, LSA)) |
| 259 | zlog_debug ("Route[External]: type-1 created."); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 260 | new->path_type = OSPF_PATH_TYPE1_EXTERNAL; |
| 261 | new->cost = asbr_route->cost + metric; /* X + Y */ |
| 262 | } |
| 263 | else |
| 264 | { |
hasso | e40dcce | 2005-02-21 14:58:42 +0000 | [diff] [blame] | 265 | if (IS_DEBUG_OSPF (lsa, LSA)) |
| 266 | zlog_debug ("Route[External]: type-2 created."); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 267 | new->path_type = OSPF_PATH_TYPE2_EXTERNAL; |
| 268 | new->cost = asbr_route->cost; /* X */ |
| 269 | new->u.ext.type2_cost = metric; /* Y */ |
| 270 | } |
| 271 | |
| 272 | new->type = OSPF_DESTINATION_NETWORK; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 273 | new->u.ext.origin = lsa; |
| 274 | new->u.ext.tag = ntohl (al->e[0].route_tag); |
| 275 | new->u.ext.asbr = asbr_route; |
| 276 | |
| 277 | assert (new != asbr_route); |
| 278 | |
| 279 | return new; |
| 280 | } |
| 281 | |
| 282 | #define OSPF_ASE_CALC_INTERVAL 1 |
| 283 | |
| 284 | int |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 285 | ospf_ase_calculate_route (struct ospf *ospf, struct ospf_lsa * lsa) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 286 | { |
| 287 | u_int32_t metric; |
| 288 | struct as_external_lsa *al; |
| 289 | struct ospf_route *asbr_route; |
| 290 | struct prefix_ipv4 asbr, p; |
| 291 | struct route_node *rn; |
| 292 | struct ospf_route *new, *or; |
| 293 | int ret; |
| 294 | |
| 295 | assert (lsa); |
| 296 | al = (struct as_external_lsa *) lsa->data; |
| 297 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 298 | if (lsa->data->type == OSPF_AS_NSSA_LSA) |
| 299 | if (IS_DEBUG_OSPF_NSSA) |
ajs | e84cc64 | 2004-12-08 17:28:56 +0000 | [diff] [blame] | 300 | zlog_debug ("ospf_ase_calc(): Processing Type-7"); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 301 | |
| 302 | /* Stay away from any Local Translated Type-7 LSAs */ |
| 303 | if (CHECK_FLAG (lsa->flags, OSPF_LSA_LOCAL_XLT)) |
| 304 | { |
| 305 | if (IS_DEBUG_OSPF_NSSA) |
ajs | e84cc64 | 2004-12-08 17:28:56 +0000 | [diff] [blame] | 306 | zlog_debug ("ospf_ase_calc(): Rejecting Local Xlt'd"); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 307 | return 0; |
| 308 | } |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 309 | |
hasso | e40dcce | 2005-02-21 14:58:42 +0000 | [diff] [blame] | 310 | if (IS_DEBUG_OSPF (lsa, LSA)) |
| 311 | zlog_debug ("Route[External]: Calculate AS-external-LSA to %s/%d", |
| 312 | inet_ntoa (al->header.id), ip_masklen (al->mask)); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 313 | /* (1) If the cost specified by the LSA is LSInfinity, or if the |
| 314 | LSA's LS age is equal to MaxAge, then examine the next LSA. */ |
| 315 | if ((metric = GET_METRIC (al->e[0].metric)) >= OSPF_LS_INFINITY) |
| 316 | { |
hasso | e40dcce | 2005-02-21 14:58:42 +0000 | [diff] [blame] | 317 | if (IS_DEBUG_OSPF (lsa, LSA)) |
| 318 | zlog_debug ("Route[External]: Metric is OSPF_LS_INFINITY"); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 319 | return 0; |
| 320 | } |
| 321 | if (IS_LSA_MAXAGE (lsa)) |
| 322 | { |
hasso | e40dcce | 2005-02-21 14:58:42 +0000 | [diff] [blame] | 323 | if (IS_DEBUG_OSPF (lsa, LSA)) |
| 324 | zlog_debug ("Route[External]: AS-external-LSA is MAXAGE"); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 325 | return 0; |
| 326 | } |
| 327 | |
| 328 | /* (2) If the LSA was originated by the calculating router itself, |
| 329 | examine the next LSA. */ |
| 330 | if (IS_LSA_SELF (lsa)) |
| 331 | { |
hasso | e40dcce | 2005-02-21 14:58:42 +0000 | [diff] [blame] | 332 | if (IS_DEBUG_OSPF (lsa, LSA)) |
| 333 | zlog_debug ("Route[External]: AS-external-LSA is self originated"); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 334 | return 0; |
| 335 | } |
| 336 | |
| 337 | /* (3) Call the destination described by the LSA N. N's address is |
| 338 | obtained by masking the LSA's Link State ID with the |
| 339 | network/subnet mask contained in the body of the LSA. Look |
| 340 | up the routing table entries (potentially one per attached |
| 341 | area) for the AS boundary router (ASBR) that originated the |
| 342 | LSA. If no entries exist for router ASBR (i.e., ASBR is |
| 343 | unreachable), do nothing with this LSA and consider the next |
| 344 | in the list. */ |
| 345 | |
| 346 | asbr.family = AF_INET; |
| 347 | asbr.prefix = al->header.adv_router; |
| 348 | asbr.prefixlen = IPV4_MAX_BITLEN; |
| 349 | apply_mask_ipv4 (&asbr); |
| 350 | |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 351 | asbr_route = ospf_find_asbr_route (ospf, ospf->new_rtrs, &asbr); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 352 | if (asbr_route == NULL) |
| 353 | { |
hasso | e40dcce | 2005-02-21 14:58:42 +0000 | [diff] [blame] | 354 | if (IS_DEBUG_OSPF (lsa, LSA)) |
| 355 | zlog_debug ("Route[External]: Can't find originating ASBR route"); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 356 | return 0; |
| 357 | } |
| 358 | if (!(asbr_route->u.std.flags & ROUTER_LSA_EXTERNAL)) |
| 359 | { |
hasso | e40dcce | 2005-02-21 14:58:42 +0000 | [diff] [blame] | 360 | if (IS_DEBUG_OSPF (lsa, LSA)) |
| 361 | zlog_debug ("Route[External]: Originating router is not an ASBR"); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 362 | return 0; |
| 363 | } |
| 364 | |
| 365 | /* Else, this LSA describes an AS external path to destination |
| 366 | N. Examine the forwarding address specified in the AS- |
| 367 | external-LSA. This indicates the IP address to which |
| 368 | packets for the destination should be forwarded. */ |
| 369 | |
| 370 | if (al->e[0].fwd_addr.s_addr == 0) |
| 371 | { |
| 372 | /* If the forwarding address is set to 0.0.0.0, packets should |
| 373 | be sent to the ASBR itself. Among the multiple routing table |
| 374 | entries for the ASBR, select the preferred entry as follows. |
| 375 | If RFC1583Compatibility is set to "disabled", prune the set |
| 376 | of routing table entries for the ASBR as described in |
| 377 | Section 16.4.1. In any case, among the remaining routing |
| 378 | table entries, select the routing table entry with the least |
| 379 | cost; when there are multiple least cost routing table |
| 380 | entries the entry whose associated area has the largest OSPF |
| 381 | Area ID (when considered as an unsigned 32-bit integer) is |
| 382 | chosen. */ |
| 383 | |
| 384 | /* asbr_route already contains the requested route */ |
| 385 | } |
| 386 | else |
| 387 | { |
| 388 | /* If the forwarding address is non-zero, look up the |
| 389 | forwarding address in the routing table.[24] The matching |
| 390 | routing table entry must specify an intra-area or inter-area |
| 391 | path; if no such path exists, do nothing with the LSA and |
| 392 | consider the next in the list. */ |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 393 | if (! ospf_ase_forward_address_check (ospf, al->e[0].fwd_addr)) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 394 | { |
hasso | e40dcce | 2005-02-21 14:58:42 +0000 | [diff] [blame] | 395 | if (IS_DEBUG_OSPF (lsa, LSA)) |
| 396 | zlog_debug ("Route[External]: Forwarding address is our router " |
| 397 | "address"); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 398 | return 0; |
| 399 | } |
| 400 | |
| 401 | asbr.family = AF_INET; |
| 402 | asbr.prefix = al->e[0].fwd_addr; |
| 403 | asbr.prefixlen = IPV4_MAX_BITLEN; |
| 404 | |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 405 | rn = route_node_match (ospf->new_table, (struct prefix *) &asbr); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 406 | |
| 407 | if (rn == NULL || (asbr_route = rn->info) == NULL) |
| 408 | { |
hasso | e40dcce | 2005-02-21 14:58:42 +0000 | [diff] [blame] | 409 | if (IS_DEBUG_OSPF (lsa, LSA)) |
| 410 | zlog_debug ("Route[External]: Can't find route to forwarding " |
| 411 | "address"); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 412 | if (rn) |
| 413 | route_unlock_node (rn); |
| 414 | return 0; |
| 415 | } |
| 416 | |
| 417 | route_unlock_node (rn); |
| 418 | } |
| 419 | |
| 420 | /* (4) Let X be the cost specified by the preferred routing table |
| 421 | entry for the ASBR/forwarding address, and Y the cost |
| 422 | specified in the LSA. X is in terms of the link state |
| 423 | metric, and Y is a type 1 or 2 external metric. */ |
| 424 | |
| 425 | |
| 426 | /* (5) Look up the routing table entry for the destination N. If |
| 427 | no entry exists for N, install the AS external path to N, |
| 428 | with next hop equal to the list of next hops to the |
| 429 | forwarding address, and advertising router equal to ASBR. |
| 430 | If the external metric type is 1, then the path-type is set |
| 431 | to type 1 external and the cost is equal to X+Y. If the |
| 432 | external metric type is 2, the path-type is set to type 2 |
| 433 | external, the link state component of the route's cost is X, |
| 434 | and the type 2 cost is Y. */ |
| 435 | new = ospf_ase_calculate_new_route (lsa, asbr_route, metric); |
| 436 | |
| 437 | /* (6) Compare the AS external path described by the LSA with the |
| 438 | existing paths in N's routing table entry, as follows. If |
| 439 | the new path is preferred, it replaces the present paths in |
| 440 | N's routing table entry. If the new path is of equal |
| 441 | preference, it is added to N's routing table entry's list of |
| 442 | paths. */ |
| 443 | |
| 444 | /* Set prefix. */ |
| 445 | p.family = AF_INET; |
| 446 | p.prefix = al->header.id; |
| 447 | p.prefixlen = ip_masklen (al->mask); |
| 448 | |
| 449 | /* if there is a Intra/Inter area route to the N |
| 450 | do not install external route */ |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 451 | if ((rn = route_node_lookup (ospf->new_table, |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 452 | (struct prefix *) &p)) != NULL |
| 453 | && (rn->info != NULL)) |
| 454 | { |
| 455 | if (new) |
| 456 | ospf_route_free (new); |
| 457 | return 0; |
| 458 | } |
| 459 | |
| 460 | /* Find a route to the same dest */ |
| 461 | /* If there is no route, create new one. */ |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 462 | if ((rn = route_node_lookup (ospf->new_external_route, |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 463 | (struct prefix *) &p)) == NULL |
| 464 | || (or = rn->info) == NULL) |
| 465 | { |
hasso | e40dcce | 2005-02-21 14:58:42 +0000 | [diff] [blame] | 466 | if (IS_DEBUG_OSPF (lsa, LSA)) |
| 467 | zlog_debug ("Route[External]: Adding a new route %s/%d", |
| 468 | inet_ntoa (p.prefix), p.prefixlen); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 469 | |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 470 | ospf_route_add (ospf->new_external_route, &p, new, asbr_route); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 471 | |
| 472 | if (al->e[0].fwd_addr.s_addr) |
| 473 | ospf_ase_complete_direct_routes (new, al->e[0].fwd_addr); |
| 474 | return 0; |
| 475 | } |
| 476 | else |
| 477 | { |
| 478 | /* (a) Intra-area and inter-area paths are always preferred |
| 479 | over AS external paths. |
| 480 | |
| 481 | (b) Type 1 external paths are always preferred over type 2 |
| 482 | external paths. When all paths are type 2 external |
| 483 | paths, the paths with the smallest advertised type 2 |
| 484 | metric are always preferred. */ |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 485 | ret = ospf_route_cmp (ospf, new, or); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 486 | |
| 487 | /* (c) If the new AS external path is still indistinguishable |
| 488 | from the current paths in the N's routing table entry, |
| 489 | and RFC1583Compatibility is set to "disabled", select |
| 490 | the preferred paths based on the intra-AS paths to the |
| 491 | ASBR/forwarding addresses, as specified in Section |
| 492 | 16.4.1. |
| 493 | |
| 494 | (d) If the new AS external path is still indistinguishable |
| 495 | from the current paths in the N's routing table entry, |
| 496 | select the preferred path based on a least cost |
| 497 | comparison. Type 1 external paths are compared by |
| 498 | looking at the sum of the distance to the forwarding |
| 499 | address and the advertised type 1 metric (X+Y). Type 2 |
| 500 | external paths advertising equal type 2 metrics are |
| 501 | compared by looking at the distance to the forwarding |
| 502 | addresses. |
| 503 | */ |
| 504 | /* New route is better */ |
| 505 | if (ret < 0) |
| 506 | { |
hasso | e40dcce | 2005-02-21 14:58:42 +0000 | [diff] [blame] | 507 | if (IS_DEBUG_OSPF (lsa, LSA)) |
| 508 | zlog_debug ("Route[External]: New route is better"); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 509 | ospf_route_subst (rn, new, asbr_route); |
| 510 | if (al->e[0].fwd_addr.s_addr) |
| 511 | ospf_ase_complete_direct_routes (new, al->e[0].fwd_addr); |
| 512 | or = new; |
| 513 | new = NULL; |
| 514 | } |
| 515 | /* Old route is better */ |
| 516 | else if (ret > 0) |
| 517 | { |
hasso | e40dcce | 2005-02-21 14:58:42 +0000 | [diff] [blame] | 518 | if (IS_DEBUG_OSPF (lsa, LSA)) |
| 519 | zlog_debug ("Route[External]: Old route is better"); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 520 | /* do nothing */ |
| 521 | } |
| 522 | /* Routes are equal */ |
| 523 | else |
| 524 | { |
hasso | e40dcce | 2005-02-21 14:58:42 +0000 | [diff] [blame] | 525 | if (IS_DEBUG_OSPF (lsa, LSA)) |
| 526 | zlog_debug ("Route[External]: Routes are equal"); |
paul | 96735ee | 2003-08-10 02:51:22 +0000 | [diff] [blame] | 527 | ospf_route_copy_nexthops (or, asbr_route->paths); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 528 | if (al->e[0].fwd_addr.s_addr) |
| 529 | ospf_ase_complete_direct_routes (or, al->e[0].fwd_addr); |
| 530 | } |
| 531 | } |
| 532 | /* Make sure setting newly calculated ASBR route.*/ |
| 533 | or->u.ext.asbr = asbr_route; |
| 534 | if (new) |
| 535 | ospf_route_free (new); |
| 536 | |
| 537 | lsa->route = or; |
| 538 | return 0; |
| 539 | } |
| 540 | |
paul | 4dadc29 | 2005-05-06 21:37:42 +0000 | [diff] [blame] | 541 | static int |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 542 | ospf_ase_route_match_same (struct route_table *rt, struct prefix *prefix, |
| 543 | struct ospf_route *newor) |
| 544 | { |
| 545 | struct route_node *rn; |
| 546 | struct ospf_route *or; |
| 547 | struct ospf_path *op; |
| 548 | struct ospf_path *newop; |
hasso | 52dc7ee | 2004-09-23 19:18:23 +0000 | [diff] [blame] | 549 | struct listnode *n1; |
| 550 | struct listnode *n2; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 551 | |
| 552 | if (! rt || ! prefix) |
| 553 | return 0; |
| 554 | |
| 555 | rn = route_node_lookup (rt, prefix); |
| 556 | if (! rn) |
| 557 | return 0; |
| 558 | |
| 559 | route_unlock_node (rn); |
| 560 | |
| 561 | or = rn->info; |
| 562 | if (or->path_type != newor->path_type) |
| 563 | return 0; |
| 564 | |
| 565 | switch (or->path_type) |
| 566 | { |
| 567 | case OSPF_PATH_TYPE1_EXTERNAL: |
| 568 | if (or->cost != newor->cost) |
| 569 | return 0; |
| 570 | break; |
| 571 | case OSPF_PATH_TYPE2_EXTERNAL: |
| 572 | if ((or->cost != newor->cost) || |
| 573 | (or->u.ext.type2_cost != newor->u.ext.type2_cost)) |
| 574 | return 0; |
| 575 | break; |
| 576 | default: |
| 577 | assert (0); |
| 578 | return 0; |
| 579 | } |
| 580 | |
paul | 96735ee | 2003-08-10 02:51:22 +0000 | [diff] [blame] | 581 | if (or->paths->count != newor->paths->count) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 582 | return 0; |
| 583 | |
| 584 | /* Check each path. */ |
paul | 96735ee | 2003-08-10 02:51:22 +0000 | [diff] [blame] | 585 | for (n1 = listhead (or->paths), n2 = listhead (newor->paths); |
paul | 1eb8ef2 | 2005-04-07 07:30:20 +0000 | [diff] [blame] | 586 | n1 && n2; n1 = listnextnode (n1), n2 = listnextnode (n2)) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 587 | { |
paul | 1eb8ef2 | 2005-04-07 07:30:20 +0000 | [diff] [blame] | 588 | op = listgetdata (n1); |
| 589 | newop = listgetdata (n2); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 590 | |
| 591 | if (! IPV4_ADDR_SAME (&op->nexthop, &newop->nexthop)) |
| 592 | return 0; |
| 593 | } |
| 594 | return 1; |
| 595 | } |
| 596 | |
paul | 4dadc29 | 2005-05-06 21:37:42 +0000 | [diff] [blame] | 597 | static int |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 598 | ospf_ase_compare_tables (struct route_table *new_external_route, |
| 599 | struct route_table *old_external_route) |
| 600 | { |
| 601 | struct route_node *rn, *new_rn; |
| 602 | struct ospf_route *or; |
| 603 | |
| 604 | /* Remove deleted routes */ |
| 605 | for (rn = route_top (old_external_route); rn; rn = route_next (rn)) |
| 606 | if ((or = rn->info)) |
| 607 | { |
| 608 | if (! (new_rn = route_node_lookup (new_external_route, &rn->p))) |
| 609 | ospf_zebra_delete ((struct prefix_ipv4 *) &rn->p, or); |
| 610 | else |
| 611 | route_unlock_node (new_rn); |
| 612 | } |
| 613 | |
| 614 | |
| 615 | /* Install new routes */ |
| 616 | for (rn = route_top (new_external_route); rn; rn = route_next (rn)) |
| 617 | if ((or = rn->info) != NULL) |
| 618 | if (! ospf_ase_route_match_same (old_external_route, &rn->p, or)) |
| 619 | ospf_zebra_add ((struct prefix_ipv4 *) &rn->p, or); |
| 620 | |
| 621 | return 0; |
| 622 | } |
| 623 | |
paul | 4dadc29 | 2005-05-06 21:37:42 +0000 | [diff] [blame] | 624 | static int |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 625 | ospf_ase_calculate_timer (struct thread *t) |
| 626 | { |
| 627 | struct ospf *ospf; |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 628 | struct ospf_lsa *lsa; |
| 629 | struct route_node *rn; |
hasso | 52dc7ee | 2004-09-23 19:18:23 +0000 | [diff] [blame] | 630 | struct listnode *node; |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 631 | struct ospf_area *area; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 632 | |
| 633 | ospf = THREAD_ARG (t); |
| 634 | ospf->t_ase_calc = NULL; |
| 635 | |
| 636 | if (ospf->ase_calc) |
| 637 | { |
| 638 | ospf->ase_calc = 0; |
| 639 | |
| 640 | /* Calculate external route for each AS-external-LSA */ |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 641 | LSDB_LOOP (EXTERNAL_LSDB (ospf), rn, lsa) |
| 642 | ospf_ase_calculate_route (ospf, lsa); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 643 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 644 | /* This version simple adds to the table all NSSA areas */ |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 645 | if (ospf->anyNSSA) |
paul | 1eb8ef2 | 2005-04-07 07:30:20 +0000 | [diff] [blame] | 646 | for (ALL_LIST_ELEMENTS_RO (ospf->areas, node, area)) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 647 | { |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 648 | if (IS_DEBUG_OSPF_NSSA) |
ajs | e84cc64 | 2004-12-08 17:28:56 +0000 | [diff] [blame] | 649 | zlog_debug ("ospf_ase_calculate_timer(): looking at area %s", |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 650 | inet_ntoa (area->area_id)); |
| 651 | |
| 652 | if (area->external_routing == OSPF_AREA_NSSA) |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 653 | LSDB_LOOP (NSSA_LSDB (area), rn, lsa) |
| 654 | ospf_ase_calculate_route (ospf, lsa); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 655 | } |
paul | f2c8065 | 2002-12-13 21:44:27 +0000 | [diff] [blame] | 656 | /* kevinm: And add the NSSA routes in ospf_top */ |
paul | f6386ee | 2003-04-07 04:29:27 +0000 | [diff] [blame] | 657 | LSDB_LOOP (NSSA_LSDB (ospf),rn,lsa) |
| 658 | ospf_ase_calculate_route(ospf,lsa); |
paul | f2c8065 | 2002-12-13 21:44:27 +0000 | [diff] [blame] | 659 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 660 | /* Compare old and new external routing table and install the |
| 661 | difference info zebra/kernel */ |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 662 | ospf_ase_compare_tables (ospf->new_external_route, |
| 663 | ospf->old_external_route); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 664 | |
| 665 | /* Delete old external routing table */ |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 666 | ospf_route_table_free (ospf->old_external_route); |
| 667 | ospf->old_external_route = ospf->new_external_route; |
| 668 | ospf->new_external_route = route_table_init (); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 669 | } |
| 670 | return 0; |
| 671 | } |
| 672 | |
| 673 | void |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 674 | ospf_ase_calculate_schedule (struct ospf *ospf) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 675 | { |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 676 | if (ospf == NULL) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 677 | return; |
| 678 | |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 679 | ospf->ase_calc = 1; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 680 | } |
| 681 | |
| 682 | void |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 683 | ospf_ase_calculate_timer_add (struct ospf *ospf) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 684 | { |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 685 | if (ospf == NULL) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 686 | return; |
| 687 | |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 688 | if (! ospf->t_ase_calc) |
| 689 | ospf->t_ase_calc = thread_add_timer (master, ospf_ase_calculate_timer, |
| 690 | ospf, OSPF_ASE_CALC_INTERVAL); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 691 | } |
| 692 | |
| 693 | void |
| 694 | ospf_ase_register_external_lsa (struct ospf_lsa *lsa, struct ospf *top) |
| 695 | { |
| 696 | struct route_node *rn; |
| 697 | struct prefix_ipv4 p; |
hasso | 52dc7ee | 2004-09-23 19:18:23 +0000 | [diff] [blame] | 698 | struct list *lst; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 699 | struct as_external_lsa *al; |
| 700 | |
| 701 | al = (struct as_external_lsa *) lsa->data; |
| 702 | p.family = AF_INET; |
| 703 | p.prefix = lsa->data->id; |
| 704 | p.prefixlen = ip_masklen (al->mask); |
| 705 | apply_mask_ipv4 (&p); |
| 706 | |
| 707 | rn = route_node_get (top->external_lsas, (struct prefix *) &p); |
| 708 | if ((lst = rn->info) == NULL) |
| 709 | rn->info = lst = list_new(); |
| 710 | |
| 711 | /* We assume that if LSA is deleted from DB |
| 712 | is is also deleted from this RT */ |
| 713 | |
Paul Jakma | 1fe6ed3 | 2006-07-26 09:37:26 +0000 | [diff] [blame] | 714 | listnode_add (lst, ospf_lsa_lock (lsa)); /* external_lsas lst */ |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 715 | } |
| 716 | |
| 717 | void |
| 718 | ospf_ase_unregister_external_lsa (struct ospf_lsa *lsa, struct ospf *top) |
| 719 | { |
| 720 | struct route_node *rn; |
| 721 | struct prefix_ipv4 p; |
hasso | 52dc7ee | 2004-09-23 19:18:23 +0000 | [diff] [blame] | 722 | struct list *lst; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 723 | struct as_external_lsa *al; |
| 724 | |
| 725 | al = (struct as_external_lsa *) lsa->data; |
| 726 | p.family = AF_INET; |
| 727 | p.prefix = lsa->data->id; |
| 728 | p.prefixlen = ip_masklen (al->mask); |
| 729 | apply_mask_ipv4 (&p); |
| 730 | |
| 731 | rn = route_node_get (top->external_lsas, (struct prefix *) &p); |
| 732 | lst = rn->info; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 733 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 734 | /* XXX lst can be NULL */ |
| 735 | if (lst) { |
| 736 | listnode_delete (lst, lsa); |
Paul Jakma | 1fe6ed3 | 2006-07-26 09:37:26 +0000 | [diff] [blame] | 737 | ospf_lsa_unlock (&lsa); /* external_lsas list */ |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 738 | } |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 739 | } |
| 740 | |
| 741 | void |
| 742 | ospf_ase_external_lsas_finish (struct route_table *rt) |
| 743 | { |
| 744 | struct route_node *rn; |
| 745 | struct ospf_lsa *lsa; |
hasso | 52dc7ee | 2004-09-23 19:18:23 +0000 | [diff] [blame] | 746 | struct list *lst; |
paul | 1eb8ef2 | 2005-04-07 07:30:20 +0000 | [diff] [blame] | 747 | struct listnode *node, *nnode; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 748 | |
| 749 | for (rn = route_top (rt); rn; rn = route_next (rn)) |
| 750 | if ((lst = rn->info) != NULL) |
| 751 | { |
paul | 1eb8ef2 | 2005-04-07 07:30:20 +0000 | [diff] [blame] | 752 | for (ALL_LIST_ELEMENTS (lst, node, nnode, lsa)) |
Paul Jakma | 1fe6ed3 | 2006-07-26 09:37:26 +0000 | [diff] [blame] | 753 | ospf_lsa_unlock (&lsa); /* external_lsas lst */ |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 754 | list_delete (lst); |
| 755 | } |
paul | 1eb8ef2 | 2005-04-07 07:30:20 +0000 | [diff] [blame] | 756 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 757 | route_table_finish (rt); |
| 758 | } |
| 759 | |
| 760 | void |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 761 | ospf_ase_incremental_update (struct ospf *ospf, struct ospf_lsa *lsa) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 762 | { |
hasso | 52dc7ee | 2004-09-23 19:18:23 +0000 | [diff] [blame] | 763 | struct list *lsas; |
| 764 | struct listnode *node; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 765 | struct route_node *rn, *rn2; |
| 766 | struct prefix_ipv4 p; |
| 767 | struct route_table *tmp_old; |
| 768 | struct as_external_lsa *al; |
| 769 | |
| 770 | al = (struct as_external_lsa *) lsa->data; |
| 771 | p.family = AF_INET; |
| 772 | p.prefix = lsa->data->id; |
| 773 | p.prefixlen = ip_masklen (al->mask); |
| 774 | apply_mask_ipv4 (&p); |
| 775 | |
| 776 | /* if new_table is NULL, there was no spf calculation, thus |
| 777 | incremental update is unneeded */ |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 778 | if (!ospf->new_table) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 779 | return; |
| 780 | |
| 781 | /* If there is already an intra-area or inter-area route |
| 782 | to the destination, no recalculation is necessary |
| 783 | (internal routes take precedence). */ |
| 784 | |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 785 | rn = route_node_lookup (ospf->new_table, (struct prefix *) &p); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 786 | if (rn && rn->info) |
| 787 | { |
| 788 | route_unlock_node (rn); |
| 789 | return; |
| 790 | } |
| 791 | |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 792 | rn = route_node_lookup (ospf->external_lsas, (struct prefix *) &p); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 793 | assert (rn && rn->info); |
| 794 | lsas = rn->info; |
| 795 | |
paul | 1eb8ef2 | 2005-04-07 07:30:20 +0000 | [diff] [blame] | 796 | for (ALL_LIST_ELEMENTS_RO (lsas, node, lsa)) |
| 797 | ospf_ase_calculate_route (ospf, lsa); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 798 | |
| 799 | /* prepare temporary old routing table for compare */ |
| 800 | tmp_old = route_table_init (); |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 801 | rn = route_node_lookup (ospf->old_external_route, (struct prefix *) &p); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 802 | if (rn && rn->info) |
| 803 | { |
| 804 | rn2 = route_node_get (tmp_old, (struct prefix *) &p); |
| 805 | rn2->info = rn->info; |
| 806 | } |
| 807 | |
| 808 | /* install changes to zebra */ |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 809 | ospf_ase_compare_tables (ospf->new_external_route, tmp_old); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 810 | |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 811 | /* update ospf->old_external_route table */ |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 812 | if (rn && rn->info) |
| 813 | ospf_route_free ((struct ospf_route *) rn->info); |
| 814 | |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 815 | rn2 = route_node_lookup (ospf->new_external_route, (struct prefix *) &p); |
| 816 | /* if new route exists, install it to ospf->old_external_route */ |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 817 | if (rn2 && rn2->info) |
| 818 | { |
| 819 | if (!rn) |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 820 | rn = route_node_get (ospf->old_external_route, (struct prefix *) &p); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 821 | rn->info = rn2->info; |
| 822 | } |
| 823 | else |
| 824 | { |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 825 | /* remove route node from ospf->old_external_route */ |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 826 | if (rn) |
| 827 | { |
| 828 | rn->info = NULL; |
| 829 | route_unlock_node (rn); |
| 830 | route_unlock_node (rn); |
| 831 | } |
| 832 | } |
| 833 | |
| 834 | if (rn2) |
| 835 | { |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 836 | /* rn2->info is stored in route node of ospf->old_external_route */ |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 837 | rn2->info = NULL; |
| 838 | route_unlock_node (rn2); |
| 839 | route_unlock_node (rn2); |
| 840 | } |
| 841 | |
| 842 | route_table_finish (tmp_old); |
| 843 | } |