paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1 | /* |
| 2 | * OSPF inter-area routing. |
| 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 | |
| 24 | #include <zebra.h> |
| 25 | |
| 26 | #include "thread.h" |
| 27 | #include "memory.h" |
| 28 | #include "hash.h" |
| 29 | #include "linklist.h" |
| 30 | #include "prefix.h" |
| 31 | #include "table.h" |
| 32 | #include "log.h" |
| 33 | |
| 34 | #include "ospfd/ospfd.h" |
| 35 | #include "ospfd/ospf_interface.h" |
| 36 | #include "ospfd/ospf_ism.h" |
| 37 | #include "ospfd/ospf_asbr.h" |
| 38 | #include "ospfd/ospf_lsa.h" |
| 39 | #include "ospfd/ospf_lsdb.h" |
| 40 | #include "ospfd/ospf_neighbor.h" |
| 41 | #include "ospfd/ospf_nsm.h" |
| 42 | #include "ospfd/ospf_spf.h" |
| 43 | #include "ospfd/ospf_route.h" |
| 44 | #include "ospfd/ospf_ase.h" |
| 45 | #include "ospfd/ospf_abr.h" |
| 46 | #include "ospfd/ospf_ia.h" |
| 47 | #include "ospfd/ospf_dump.h" |
| 48 | |
| 49 | #define DEBUG |
| 50 | |
| 51 | struct ospf_route * |
| 52 | ospf_find_abr_route (struct route_table *rtrs, |
| 53 | struct prefix_ipv4 *abr, |
| 54 | struct ospf_area *area) |
| 55 | { |
| 56 | struct route_node *rn; |
| 57 | struct ospf_route *or; |
| 58 | listnode node; |
| 59 | |
| 60 | if ((rn = route_node_lookup (rtrs, (struct prefix *) abr)) == NULL) |
| 61 | return NULL; |
| 62 | |
| 63 | route_unlock_node (rn); |
| 64 | |
| 65 | for (node = listhead ((list) rn->info); node; nextnode (node)) |
| 66 | if ((or = getdata (node)) != NULL) |
| 67 | if (IPV4_ADDR_SAME (&or->u.std.area_id, &area->area_id) && (or->u.std.flags & ROUTER_LSA_BORDER)) |
| 68 | return or; |
| 69 | |
| 70 | return NULL; |
| 71 | } |
| 72 | |
| 73 | void |
paul | 96735ee | 2003-08-10 02:51:22 +0000 | [diff] [blame] | 74 | ospf_ia_network_route (struct ospf *ospf, struct route_table *rt, |
| 75 | struct prefix_ipv4 *p, struct ospf_route *new_or, |
| 76 | struct ospf_route *abr_or) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 77 | { |
| 78 | struct route_node *rn1; |
| 79 | struct ospf_route *or; |
| 80 | |
| 81 | if (IS_DEBUG_OSPF_EVENT) |
| 82 | zlog_info ("ospf_ia_network_route(): processing summary route to %s/%d", |
| 83 | inet_ntoa (p->prefix), p->prefixlen); |
| 84 | |
| 85 | /* Find a route to the same dest */ |
| 86 | if ((rn1 = route_node_lookup (rt, (struct prefix *) p))) |
| 87 | { |
| 88 | int res; |
| 89 | |
| 90 | route_unlock_node (rn1); |
| 91 | |
| 92 | if ((or = rn1->info)) |
| 93 | { |
| 94 | if (IS_DEBUG_OSPF_EVENT) |
| 95 | zlog_info ("ospf_ia_network_route(): " |
| 96 | "Found a route to the same network"); |
| 97 | /* Check the existing route. */ |
paul | 96735ee | 2003-08-10 02:51:22 +0000 | [diff] [blame] | 98 | if ((res = ospf_route_cmp (ospf, new_or, or)) < 0) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 99 | { |
| 100 | /* New route is better, so replace old one. */ |
| 101 | ospf_route_subst (rn1, new_or, abr_or); |
| 102 | } |
| 103 | else if (res == 0) |
| 104 | { |
| 105 | /* New and old route are equal, so next hops can be added. */ |
| 106 | route_lock_node (rn1); |
paul | 96735ee | 2003-08-10 02:51:22 +0000 | [diff] [blame] | 107 | ospf_route_copy_nexthops (or, abr_or->paths); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 108 | route_unlock_node (rn1); |
| 109 | |
| 110 | /* new route can be deleted, because existing route has been updated. */ |
| 111 | ospf_route_free (new_or); |
| 112 | } |
| 113 | else |
| 114 | { |
| 115 | /* New route is worse, so free it. */ |
| 116 | ospf_route_free (new_or); |
| 117 | return; |
| 118 | } |
| 119 | } /* if (or)*/ |
| 120 | } /*if (rn1)*/ |
| 121 | else |
| 122 | { /* no route */ |
| 123 | if (IS_DEBUG_OSPF_EVENT) |
| 124 | zlog_info ("ospf_ia_network_route(): add new route to %s/%d", |
| 125 | inet_ntoa (p->prefix), p->prefixlen); |
| 126 | ospf_route_add (rt, p, new_or, abr_or); |
| 127 | } |
| 128 | } |
| 129 | |
| 130 | void |
paul | 96735ee | 2003-08-10 02:51:22 +0000 | [diff] [blame] | 131 | ospf_ia_router_route (struct ospf *ospf, struct route_table *rtrs, |
| 132 | struct prefix_ipv4 *p, |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 133 | struct ospf_route *new_or, struct ospf_route *abr_or) |
| 134 | { |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 135 | struct ospf_route *or = NULL; |
paul | 96735ee | 2003-08-10 02:51:22 +0000 | [diff] [blame] | 136 | struct route_node *rn; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 137 | int ret; |
| 138 | |
| 139 | if (IS_DEBUG_OSPF_EVENT) |
| 140 | zlog_info ("ospf_ia_router_route(): considering %s/%d", |
| 141 | inet_ntoa (p->prefix), p->prefixlen); |
| 142 | /* Find a route to the same dest */ |
paul | 96735ee | 2003-08-10 02:51:22 +0000 | [diff] [blame] | 143 | rn = route_node_get (rtrs, (struct prefix *) p); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 144 | |
| 145 | if (rn->info == NULL) |
| 146 | /* This is a new route */ |
| 147 | rn->info = list_new (); |
| 148 | else |
| 149 | { |
| 150 | struct ospf_area *or_area; |
paul | 96735ee | 2003-08-10 02:51:22 +0000 | [diff] [blame] | 151 | or_area = ospf_area_lookup_by_area_id (ospf, new_or->u.std.area_id); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 152 | assert (or_area); |
| 153 | /* This is an additional route */ |
| 154 | route_unlock_node (rn); |
paul | 96735ee | 2003-08-10 02:51:22 +0000 | [diff] [blame] | 155 | or = ospf_find_asbr_route_through_area (rtrs, p, or_area); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 156 | } |
| 157 | |
| 158 | if (or) |
| 159 | { |
| 160 | if (IS_DEBUG_OSPF_EVENT) |
| 161 | zlog_info ("ospf_ia_router_route(): " |
| 162 | "a route to the same ABR through the same area exists"); |
| 163 | /* New route is better */ |
paul | 96735ee | 2003-08-10 02:51:22 +0000 | [diff] [blame] | 164 | if ((ret = ospf_route_cmp (ospf, new_or, or)) < 0) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 165 | { |
| 166 | listnode_delete (rn->info, or); |
| 167 | ospf_route_free (or); |
| 168 | /* proceed down */ |
| 169 | } |
| 170 | /* Routes are the same */ |
| 171 | else if (ret == 0) |
| 172 | { |
| 173 | if (IS_DEBUG_OSPF_EVENT) |
| 174 | zlog_info ("ospf_ia_router_route(): merging the new route"); |
| 175 | |
paul | 96735ee | 2003-08-10 02:51:22 +0000 | [diff] [blame] | 176 | ospf_route_copy_nexthops (or, abr_or->paths); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 177 | ospf_route_free (new_or); |
| 178 | return; |
| 179 | } |
| 180 | /* New route is worse */ |
| 181 | else |
| 182 | { |
| 183 | if (IS_DEBUG_OSPF_EVENT) |
| 184 | zlog_info ("ospf_ia_router_route(): skipping the new route"); |
| 185 | ospf_route_free (new_or); |
| 186 | return; |
| 187 | } |
| 188 | } |
| 189 | |
paul | 96735ee | 2003-08-10 02:51:22 +0000 | [diff] [blame] | 190 | ospf_route_copy_nexthops (new_or, abr_or->paths); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 191 | |
| 192 | if (IS_DEBUG_OSPF_EVENT) |
| 193 | zlog_info ("ospf_ia_router_route(): adding the new route"); |
| 194 | |
| 195 | listnode_add (rn->info, new_or); |
| 196 | } |
| 197 | |
| 198 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 199 | int |
paul | 96735ee | 2003-08-10 02:51:22 +0000 | [diff] [blame] | 200 | process_summary_lsa (struct ospf_area *area, struct route_table *rt, |
| 201 | struct route_table *rtrs, struct ospf_lsa *lsa) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 202 | { |
paul | 96735ee | 2003-08-10 02:51:22 +0000 | [diff] [blame] | 203 | struct ospf *ospf = area->ospf; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 204 | struct ospf_area_range *range; |
| 205 | struct ospf_route *abr_or, *new_or; |
| 206 | struct summary_lsa *sl; |
| 207 | struct prefix_ipv4 p, abr; |
| 208 | u_int32_t metric; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 209 | |
paul | 96735ee | 2003-08-10 02:51:22 +0000 | [diff] [blame] | 210 | if (lsa == NULL) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 211 | return 0; |
| 212 | |
paul | 96735ee | 2003-08-10 02:51:22 +0000 | [diff] [blame] | 213 | sl = (struct summary_lsa *) lsa->data; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 214 | |
| 215 | if (IS_DEBUG_OSPF_EVENT) |
| 216 | zlog_info ("process_summary_lsa(): LS ID: %s", inet_ntoa (sl->header.id)); |
| 217 | |
| 218 | metric = GET_METRIC (sl->metric); |
| 219 | |
| 220 | if (metric == OSPF_LS_INFINITY) |
| 221 | return 0; |
| 222 | |
paul | 96735ee | 2003-08-10 02:51:22 +0000 | [diff] [blame] | 223 | if (IS_LSA_MAXAGE (lsa)) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 224 | return 0; |
| 225 | |
paul | 96735ee | 2003-08-10 02:51:22 +0000 | [diff] [blame] | 226 | if (ospf_lsa_is_self_originated (area->ospf, lsa)) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 227 | return 0; |
| 228 | |
| 229 | p.family = AF_INET; |
| 230 | p.prefix = sl->header.id; |
| 231 | |
| 232 | if (sl->header.type == OSPF_SUMMARY_LSA) |
| 233 | p.prefixlen = ip_masklen (sl->mask); |
| 234 | else |
| 235 | p.prefixlen = IPV4_MAX_BITLEN; |
| 236 | |
| 237 | apply_mask_ipv4 (&p); |
| 238 | |
| 239 | if (sl->header.type == OSPF_SUMMARY_LSA && |
paul | 96735ee | 2003-08-10 02:51:22 +0000 | [diff] [blame] | 240 | (range = ospf_area_range_match_any (ospf, &p)) && |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 241 | ospf_area_range_active (range)) |
| 242 | return 0; |
| 243 | |
paul | 96735ee | 2003-08-10 02:51:22 +0000 | [diff] [blame] | 244 | if (ospf->abr_type != OSPF_ABR_STAND && |
| 245 | area->external_routing != OSPF_AREA_DEFAULT && |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 246 | p.prefix.s_addr == OSPF_DEFAULT_DESTINATION && |
| 247 | p.prefixlen == 0) |
| 248 | return 0; /* Ignore summary default from a stub area */ |
| 249 | |
| 250 | abr.family = AF_INET; |
| 251 | abr.prefix = sl->header.adv_router; |
| 252 | abr.prefixlen = IPV4_MAX_BITLEN; |
| 253 | apply_mask_ipv4 (&abr); |
| 254 | |
paul | 96735ee | 2003-08-10 02:51:22 +0000 | [diff] [blame] | 255 | abr_or = ospf_find_abr_route (rtrs, &abr, area); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 256 | |
| 257 | if (abr_or == NULL) |
| 258 | return 0; |
| 259 | |
| 260 | new_or = ospf_route_new (); |
| 261 | new_or->type = OSPF_DESTINATION_NETWORK; |
| 262 | new_or->id = sl->header.id; |
| 263 | new_or->mask = sl->mask; |
| 264 | new_or->u.std.options = sl->header.options; |
| 265 | new_or->u.std.origin = (struct lsa_header *) sl; |
| 266 | new_or->cost = abr_or->cost + metric; |
paul | 96735ee | 2003-08-10 02:51:22 +0000 | [diff] [blame] | 267 | new_or->u.std.area_id = area->area_id; |
paul | 96735ee | 2003-08-10 02:51:22 +0000 | [diff] [blame] | 268 | new_or->u.std.external_routing = area->external_routing; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 269 | new_or->path_type = OSPF_PATH_INTER_AREA; |
| 270 | |
| 271 | if (sl->header.type == OSPF_SUMMARY_LSA) |
paul | 96735ee | 2003-08-10 02:51:22 +0000 | [diff] [blame] | 272 | ospf_ia_network_route (ospf, rt, &p, new_or, abr_or); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 273 | else |
| 274 | { |
| 275 | new_or->type = OSPF_DESTINATION_ROUTER; |
| 276 | new_or->u.std.flags = ROUTER_LSA_EXTERNAL; |
paul | 96735ee | 2003-08-10 02:51:22 +0000 | [diff] [blame] | 277 | ospf_ia_router_route (ospf, rtrs, &p, new_or, abr_or); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 278 | } |
| 279 | |
| 280 | return 0; |
| 281 | } |
| 282 | |
| 283 | void |
paul | 96735ee | 2003-08-10 02:51:22 +0000 | [diff] [blame] | 284 | ospf_examine_summaries (struct ospf_area *area, |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 285 | struct route_table *lsdb_rt, |
| 286 | struct route_table *rt, |
| 287 | struct route_table *rtrs) |
| 288 | { |
paul | 96735ee | 2003-08-10 02:51:22 +0000 | [diff] [blame] | 289 | struct ospf_lsa *lsa; |
| 290 | struct route_node *rn; |
| 291 | |
| 292 | LSDB_LOOP (lsdb_rt, rn, lsa) |
| 293 | process_summary_lsa (area, rt, rtrs, lsa); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 294 | } |
| 295 | |
| 296 | int |
| 297 | ospf_area_is_transit (struct ospf_area *area) |
| 298 | { |
| 299 | return (area->transit == OSPF_TRANSIT_TRUE) || |
| 300 | ospf_full_virtual_nbrs(area); /* Cisco forgets to set the V-bit :( */ |
| 301 | } |
| 302 | |
| 303 | void |
paul | 96735ee | 2003-08-10 02:51:22 +0000 | [diff] [blame] | 304 | ospf_update_network_route (struct ospf *ospf, |
| 305 | struct route_table *rt, |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 306 | struct route_table *rtrs, |
| 307 | struct summary_lsa *lsa, |
| 308 | struct prefix_ipv4 *p, |
| 309 | struct ospf_area *area) |
| 310 | { |
| 311 | struct route_node *rn; |
| 312 | struct ospf_route *or, *abr_or, *new_or; |
| 313 | struct prefix_ipv4 abr; |
| 314 | u_int32_t cost; |
| 315 | |
| 316 | abr.family = AF_INET; |
| 317 | abr.prefix =lsa->header.adv_router; |
| 318 | abr.prefixlen = IPV4_MAX_BITLEN; |
| 319 | apply_mask_ipv4 (&abr); |
| 320 | |
| 321 | abr_or = ospf_find_abr_route (rtrs, &abr, area); |
| 322 | |
| 323 | if (abr_or == NULL) |
| 324 | { |
| 325 | if (IS_DEBUG_OSPF_EVENT) |
| 326 | zlog_info ("ospf_update_network_route(): can't find a route to the ABR"); |
| 327 | return; |
| 328 | } |
| 329 | |
| 330 | cost = abr_or->cost + GET_METRIC (lsa->metric); |
| 331 | |
| 332 | rn = route_node_lookup (rt, (struct prefix *) p); |
| 333 | |
| 334 | if (! rn) |
| 335 | { |
paul | 96735ee | 2003-08-10 02:51:22 +0000 | [diff] [blame] | 336 | if (ospf->abr_type != OSPF_ABR_SHORTCUT) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 337 | return; /* Standard ABR can update only already installed |
| 338 | backbone paths */ |
| 339 | if (IS_DEBUG_OSPF_EVENT) |
| 340 | zlog_info ("ospf_update_network_route(): " |
| 341 | "Allowing Shortcut ABR to add new route"); |
| 342 | new_or = ospf_route_new (); |
| 343 | new_or->type = OSPF_DESTINATION_NETWORK; |
| 344 | new_or->id = lsa->header.id; |
| 345 | new_or->mask = lsa->mask; |
| 346 | new_or->u.std.options = lsa->header.options; |
| 347 | new_or->u.std.origin = (struct lsa_header *) lsa; |
| 348 | new_or->cost = cost; |
| 349 | new_or->u.std.area_id = area->area_id; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 350 | new_or->u.std.external_routing = area->external_routing; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 351 | new_or->path_type = OSPF_PATH_INTER_AREA; |
| 352 | ospf_route_add (rt, p, new_or, abr_or); |
| 353 | |
| 354 | return; |
| 355 | } |
| 356 | else |
| 357 | { |
| 358 | route_unlock_node (rn); |
| 359 | if (rn->info == NULL) |
| 360 | return; |
| 361 | } |
| 362 | |
| 363 | or = rn->info; |
| 364 | |
| 365 | if (or->path_type != OSPF_PATH_INTRA_AREA && |
| 366 | or->path_type != OSPF_PATH_INTER_AREA) |
| 367 | { |
| 368 | if (IS_DEBUG_OSPF_EVENT) |
| 369 | zlog_info ("ospf_update_network_route(): ERR: path type is wrong"); |
| 370 | return; |
| 371 | } |
| 372 | |
paul | 96735ee | 2003-08-10 02:51:22 +0000 | [diff] [blame] | 373 | if (ospf->abr_type == OSPF_ABR_SHORTCUT) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 374 | { |
| 375 | if (or->path_type == OSPF_PATH_INTRA_AREA && |
| 376 | !OSPF_IS_AREA_ID_BACKBONE (or->u.std.area_id)) |
| 377 | { |
| 378 | if (IS_DEBUG_OSPF_EVENT) |
| 379 | zlog_info ("ospf_update_network_route(): Shortcut: " |
| 380 | "this intra-area path is not backbone"); |
| 381 | return; |
| 382 | } |
| 383 | } |
| 384 | else /* Not Shortcut ABR */ |
| 385 | { |
| 386 | if (!OSPF_IS_AREA_ID_BACKBONE (or->u.std.area_id)) |
| 387 | { |
| 388 | if (IS_DEBUG_OSPF_EVENT) |
| 389 | zlog_info ("ospf_update_network_route(): " |
| 390 | "route is not BB-associated"); |
| 391 | return; /* We can update only BB routes */ |
| 392 | } |
| 393 | } |
| 394 | |
| 395 | if (or->cost < cost) |
| 396 | { |
| 397 | if (IS_DEBUG_OSPF_EVENT) |
| 398 | zlog_info ("ospf_update_network_route(): new route is worse"); |
| 399 | return; |
| 400 | } |
| 401 | |
| 402 | if (or->cost == cost) |
| 403 | { |
| 404 | if (IS_DEBUG_OSPF_EVENT) |
| 405 | zlog_info ("ospf_update_network_route(): " |
| 406 | "new route is same distance, adding nexthops"); |
paul | 96735ee | 2003-08-10 02:51:22 +0000 | [diff] [blame] | 407 | ospf_route_copy_nexthops (or, abr_or->paths); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 408 | } |
| 409 | |
| 410 | if (or->cost > cost) |
| 411 | { |
| 412 | if (IS_DEBUG_OSPF_EVENT) |
| 413 | zlog_info ("ospf_update_network_route(): " |
| 414 | "new route is better, overriding nexthops"); |
paul | 96735ee | 2003-08-10 02:51:22 +0000 | [diff] [blame] | 415 | ospf_route_subst_nexthops (or, abr_or->paths); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 416 | or->cost = cost; |
| 417 | |
paul | 96735ee | 2003-08-10 02:51:22 +0000 | [diff] [blame] | 418 | if ((ospf->abr_type == OSPF_ABR_SHORTCUT) && |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 419 | !OSPF_IS_AREA_ID_BACKBONE (or->u.std.area_id)) |
| 420 | { |
| 421 | or->path_type = OSPF_PATH_INTER_AREA; |
| 422 | or->u.std.area_id = area->area_id; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 423 | or->u.std.external_routing = area->external_routing; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 424 | /* Note that we can do this only in Shortcut ABR mode, |
| 425 | because standard ABR must leave the route type and area |
| 426 | unchanged |
| 427 | */ |
| 428 | } |
| 429 | } |
| 430 | } |
| 431 | |
| 432 | void |
paul | 96735ee | 2003-08-10 02:51:22 +0000 | [diff] [blame] | 433 | ospf_update_router_route (struct ospf *ospf, |
| 434 | struct route_table *rtrs, |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 435 | struct summary_lsa *lsa, |
| 436 | struct prefix_ipv4 *p, |
| 437 | struct ospf_area *area) |
| 438 | { |
| 439 | struct ospf_route *or, *abr_or, *new_or; |
| 440 | struct prefix_ipv4 abr; |
| 441 | u_int32_t cost; |
| 442 | |
| 443 | abr.family = AF_INET; |
| 444 | abr.prefix = lsa->header.adv_router; |
| 445 | abr.prefixlen = IPV4_MAX_BITLEN; |
| 446 | apply_mask_ipv4 (&abr); |
| 447 | |
| 448 | abr_or = ospf_find_abr_route (rtrs, &abr, area); |
| 449 | |
| 450 | if (abr_or == NULL) |
| 451 | { |
| 452 | if (IS_DEBUG_OSPF_EVENT) |
| 453 | zlog_info ("ospf_update_router_route(): can't find a route to the ABR"); |
| 454 | return; |
| 455 | } |
| 456 | |
| 457 | cost = abr_or->cost + GET_METRIC (lsa->metric); |
| 458 | |
| 459 | /* First try to find a backbone path, |
| 460 | because standard ABR can update only BB-associated paths */ |
| 461 | |
paul | 96735ee | 2003-08-10 02:51:22 +0000 | [diff] [blame] | 462 | if ((ospf->backbone == NULL) && |
| 463 | (ospf->abr_type != OSPF_ABR_SHORTCUT)) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 464 | |
| 465 | /* no BB area, not Shortcut ABR, exiting */ |
| 466 | return; |
| 467 | |
paul | 96735ee | 2003-08-10 02:51:22 +0000 | [diff] [blame] | 468 | or = ospf_find_asbr_route_through_area (rtrs, p, ospf->backbone); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 469 | |
| 470 | if (or == NULL) |
| 471 | { |
paul | 96735ee | 2003-08-10 02:51:22 +0000 | [diff] [blame] | 472 | if (ospf->abr_type != OSPF_ABR_SHORTCUT) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 473 | |
| 474 | /* route to ASBR through the BB not found |
| 475 | the router is not Shortcut ABR, exiting */ |
| 476 | |
| 477 | return; |
| 478 | else |
| 479 | /* We're a Shortcut ABR*/ |
| 480 | { |
| 481 | /* Let it either add a new router or update the route |
| 482 | through the same (non-BB) area. */ |
| 483 | |
| 484 | new_or = ospf_route_new (); |
| 485 | new_or->type = OSPF_DESTINATION_ROUTER; |
| 486 | new_or->id = lsa->header.id; |
| 487 | new_or->mask = lsa->mask; |
| 488 | new_or->u.std.options = lsa->header.options; |
| 489 | new_or->u.std.origin = (struct lsa_header *)lsa; |
| 490 | new_or->cost = cost; |
| 491 | new_or->u.std.area_id = area->area_id; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 492 | new_or->u.std.external_routing = area->external_routing; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 493 | new_or->path_type = OSPF_PATH_INTER_AREA; |
| 494 | new_or->u.std.flags = ROUTER_LSA_EXTERNAL; |
paul | 96735ee | 2003-08-10 02:51:22 +0000 | [diff] [blame] | 495 | ospf_ia_router_route (ospf, rtrs, p, new_or, abr_or); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 496 | |
| 497 | return; |
| 498 | } |
| 499 | } |
| 500 | |
| 501 | /* At this point the "or" is always bb-associated */ |
| 502 | |
| 503 | if (!(or->u.std.flags & ROUTER_LSA_EXTERNAL)) |
| 504 | { |
| 505 | if (IS_DEBUG_OSPF_EVENT) |
| 506 | zlog_info ("ospf_upd_router_route(): the remote router is not an ASBR"); |
| 507 | return; |
| 508 | } |
| 509 | |
| 510 | if (or->path_type != OSPF_PATH_INTRA_AREA && |
| 511 | or->path_type != OSPF_PATH_INTER_AREA) |
| 512 | return; |
| 513 | |
| 514 | if (or->cost < cost) |
| 515 | return; |
| 516 | |
| 517 | else if (or->cost == cost) |
paul | 96735ee | 2003-08-10 02:51:22 +0000 | [diff] [blame] | 518 | ospf_route_copy_nexthops (or, abr_or->paths); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 519 | |
| 520 | else if (or->cost > cost) |
| 521 | { |
paul | 96735ee | 2003-08-10 02:51:22 +0000 | [diff] [blame] | 522 | ospf_route_subst_nexthops (or, abr_or->paths); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 523 | or->cost = cost; |
| 524 | |
| 525 | /* Even if the ABR runs in Shortcut mode, we can't change |
| 526 | the path type and area, because the "or" is always bb-associated |
| 527 | at this point and even Shortcut ABR can't change these attributes */ |
| 528 | } |
| 529 | } |
| 530 | |
| 531 | int |
paul | 96735ee | 2003-08-10 02:51:22 +0000 | [diff] [blame] | 532 | process_transit_summary_lsa (struct ospf_area *area, struct route_table *rt, |
| 533 | struct route_table *rtrs, struct ospf_lsa *lsa) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 534 | { |
paul | 96735ee | 2003-08-10 02:51:22 +0000 | [diff] [blame] | 535 | struct ospf *ospf = area->ospf; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 536 | struct summary_lsa *sl; |
| 537 | struct prefix_ipv4 p; |
| 538 | u_int32_t metric; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 539 | |
paul | 96735ee | 2003-08-10 02:51:22 +0000 | [diff] [blame] | 540 | if (lsa == NULL) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 541 | return 0; |
| 542 | |
paul | 96735ee | 2003-08-10 02:51:22 +0000 | [diff] [blame] | 543 | sl = (struct summary_lsa *) lsa->data; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 544 | |
| 545 | if (IS_DEBUG_OSPF_EVENT) |
| 546 | zlog_info ("process_transit_summaries(): LS ID: %s", |
paul | 96735ee | 2003-08-10 02:51:22 +0000 | [diff] [blame] | 547 | inet_ntoa (lsa->data->id)); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 548 | metric = GET_METRIC (sl->metric); |
| 549 | |
| 550 | if (metric == OSPF_LS_INFINITY) |
| 551 | { |
| 552 | if (IS_DEBUG_OSPF_EVENT) |
| 553 | zlog_info ("process_transit_summaries(): metric is infinity, skip"); |
| 554 | return 0; |
| 555 | } |
| 556 | |
paul | 96735ee | 2003-08-10 02:51:22 +0000 | [diff] [blame] | 557 | if (IS_LSA_MAXAGE (lsa)) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 558 | { |
| 559 | if (IS_DEBUG_OSPF_EVENT) |
| 560 | zlog_info ("process_transit_summaries(): This LSA is too old"); |
| 561 | return 0; |
| 562 | } |
| 563 | |
paul | 96735ee | 2003-08-10 02:51:22 +0000 | [diff] [blame] | 564 | if (ospf_lsa_is_self_originated (area->ospf, lsa)) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 565 | { |
| 566 | if (IS_DEBUG_OSPF_EVENT) |
| 567 | zlog_info ("process_transit_summaries(): This LSA is mine, skip"); |
| 568 | return 0; |
| 569 | } |
| 570 | |
| 571 | p.family = AF_INET; |
| 572 | p.prefix = sl->header.id; |
| 573 | |
| 574 | if (sl->header.type == OSPF_SUMMARY_LSA) |
| 575 | p.prefixlen = ip_masklen (sl->mask); |
| 576 | else |
| 577 | p.prefixlen = IPV4_MAX_BITLEN; |
| 578 | |
| 579 | apply_mask_ipv4 (&p); |
| 580 | |
| 581 | if (sl->header.type == OSPF_SUMMARY_LSA) |
paul | 96735ee | 2003-08-10 02:51:22 +0000 | [diff] [blame] | 582 | ospf_update_network_route (ospf, rt, rtrs, sl, &p, area); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 583 | else |
paul | 96735ee | 2003-08-10 02:51:22 +0000 | [diff] [blame] | 584 | ospf_update_router_route (ospf, rtrs, sl, &p, area); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 585 | |
| 586 | return 0; |
| 587 | } |
| 588 | |
| 589 | void |
| 590 | ospf_examine_transit_summaries (struct ospf_area *area, |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 591 | struct route_table *lsdb_rt, |
| 592 | struct route_table *rt, |
| 593 | struct route_table *rtrs) |
| 594 | { |
paul | 96735ee | 2003-08-10 02:51:22 +0000 | [diff] [blame] | 595 | struct ospf_lsa *lsa; |
| 596 | struct route_node *rn; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 597 | |
paul | 96735ee | 2003-08-10 02:51:22 +0000 | [diff] [blame] | 598 | LSDB_LOOP (lsdb_rt, rn, lsa) |
| 599 | process_transit_summary_lsa (area, rt, rtrs, lsa); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 600 | } |
| 601 | |
| 602 | void |
paul | 96735ee | 2003-08-10 02:51:22 +0000 | [diff] [blame] | 603 | ospf_ia_routing (struct ospf *ospf, |
| 604 | struct route_table *rt, |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 605 | struct route_table *rtrs) |
| 606 | { |
| 607 | struct ospf_area * area; |
| 608 | |
| 609 | if (IS_DEBUG_OSPF_EVENT) |
| 610 | zlog_info ("ospf_ia_routing():start"); |
| 611 | |
paul | 96735ee | 2003-08-10 02:51:22 +0000 | [diff] [blame] | 612 | if (IS_OSPF_ABR (ospf)) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 613 | { |
| 614 | listnode node; |
| 615 | struct ospf_area *area; |
| 616 | |
paul | 96735ee | 2003-08-10 02:51:22 +0000 | [diff] [blame] | 617 | switch (ospf->abr_type) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 618 | { |
| 619 | case OSPF_ABR_STAND: |
| 620 | if (IS_DEBUG_OSPF_EVENT) |
| 621 | zlog_info ("ospf_ia_routing():Standard ABR"); |
| 622 | |
paul | 96735ee | 2003-08-10 02:51:22 +0000 | [diff] [blame] | 623 | if ((area = ospf->backbone)) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 624 | { |
| 625 | listnode node; |
| 626 | |
| 627 | if (IS_DEBUG_OSPF_EVENT) |
| 628 | { |
| 629 | zlog_info ("ospf_ia_routing():backbone area found"); |
| 630 | zlog_info ("ospf_ia_routing():examining summaries"); |
| 631 | } |
| 632 | |
| 633 | OSPF_EXAMINE_SUMMARIES_ALL (area, rt, rtrs); |
| 634 | |
paul | 96735ee | 2003-08-10 02:51:22 +0000 | [diff] [blame] | 635 | for (node = listhead (ospf->areas); node; nextnode (node)) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 636 | if ((area = getdata (node)) != NULL) |
paul | 96735ee | 2003-08-10 02:51:22 +0000 | [diff] [blame] | 637 | if (area != ospf->backbone) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 638 | if (ospf_area_is_transit (area)) |
| 639 | OSPF_EXAMINE_TRANSIT_SUMMARIES_ALL (area, rt, rtrs); |
| 640 | } |
| 641 | else |
| 642 | if (IS_DEBUG_OSPF_EVENT) |
| 643 | zlog_info ("ospf_ia_routing():backbone area NOT found"); |
| 644 | break; |
| 645 | case OSPF_ABR_IBM: |
| 646 | case OSPF_ABR_CISCO: |
| 647 | if (IS_DEBUG_OSPF_EVENT) |
| 648 | zlog_info ("ospf_ia_routing():Alternative Cisco/IBM ABR"); |
paul | 96735ee | 2003-08-10 02:51:22 +0000 | [diff] [blame] | 649 | area = ospf->backbone; /* Find the BB */ |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 650 | |
| 651 | /* If we have an active BB connection */ |
paul | 96735ee | 2003-08-10 02:51:22 +0000 | [diff] [blame] | 652 | if (area && ospf_act_bb_connection (ospf)) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 653 | { |
| 654 | if (IS_DEBUG_OSPF_EVENT) |
| 655 | { |
| 656 | zlog_info ("ospf_ia_routing(): backbone area found"); |
| 657 | zlog_info ("ospf_ia_routing(): examining BB summaries"); |
| 658 | } |
| 659 | |
| 660 | OSPF_EXAMINE_SUMMARIES_ALL (area, rt, rtrs); |
| 661 | |
paul | 96735ee | 2003-08-10 02:51:22 +0000 | [diff] [blame] | 662 | for (node = listhead (ospf->areas); node; nextnode (node)) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 663 | if ((area = getdata (node)) != NULL) |
paul | 96735ee | 2003-08-10 02:51:22 +0000 | [diff] [blame] | 664 | if (area != ospf->backbone) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 665 | if (ospf_area_is_transit (area)) |
| 666 | OSPF_EXAMINE_TRANSIT_SUMMARIES_ALL (area, rt, rtrs); |
| 667 | } |
| 668 | else |
| 669 | { /* No active BB connection--consider all areas */ |
| 670 | if (IS_DEBUG_OSPF_EVENT) |
| 671 | zlog_info ("ospf_ia_routing(): " |
| 672 | "Active BB connection not found"); |
paul | 96735ee | 2003-08-10 02:51:22 +0000 | [diff] [blame] | 673 | for (node = listhead (ospf->areas); node; nextnode (node)) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 674 | if ((area = getdata (node)) != NULL) |
| 675 | OSPF_EXAMINE_SUMMARIES_ALL (area, rt, rtrs); |
| 676 | } |
| 677 | break; |
| 678 | case OSPF_ABR_SHORTCUT: |
| 679 | if (IS_DEBUG_OSPF_EVENT) |
| 680 | zlog_info ("ospf_ia_routing():Alternative Shortcut"); |
paul | 96735ee | 2003-08-10 02:51:22 +0000 | [diff] [blame] | 681 | area = ospf->backbone; /* Find the BB */ |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 682 | |
| 683 | /* If we have an active BB connection */ |
paul | 96735ee | 2003-08-10 02:51:22 +0000 | [diff] [blame] | 684 | if (area && ospf_act_bb_connection (ospf)) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 685 | { |
| 686 | if (IS_DEBUG_OSPF_EVENT) |
| 687 | { |
| 688 | zlog_info ("ospf_ia_routing(): backbone area found"); |
| 689 | zlog_info ("ospf_ia_routing(): examining BB summaries"); |
| 690 | } |
| 691 | OSPF_EXAMINE_SUMMARIES_ALL (area, rt, rtrs); |
| 692 | } |
| 693 | |
paul | 96735ee | 2003-08-10 02:51:22 +0000 | [diff] [blame] | 694 | for (node = listhead (ospf->areas); node; nextnode (node)) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 695 | if ((area = getdata (node)) != NULL) |
paul | 96735ee | 2003-08-10 02:51:22 +0000 | [diff] [blame] | 696 | if (area != ospf->backbone) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 697 | if (ospf_area_is_transit (area) || |
| 698 | ((area->shortcut_configured != OSPF_SHORTCUT_DISABLE) && |
paul | 96735ee | 2003-08-10 02:51:22 +0000 | [diff] [blame] | 699 | ((ospf->backbone == NULL) || |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 700 | ((area->shortcut_configured == OSPF_SHORTCUT_ENABLE) && |
| 701 | area->shortcut_capability)))) |
| 702 | OSPF_EXAMINE_TRANSIT_SUMMARIES_ALL (area, rt, rtrs); |
| 703 | break; |
| 704 | default: |
| 705 | break; |
| 706 | } |
| 707 | } |
| 708 | else |
| 709 | { |
| 710 | listnode node; |
| 711 | |
| 712 | if (IS_DEBUG_OSPF_EVENT) |
| 713 | zlog_info ("ospf_ia_routing():not ABR, considering all areas"); |
| 714 | |
paul | 96735ee | 2003-08-10 02:51:22 +0000 | [diff] [blame] | 715 | for (node = listhead (ospf->areas); node; nextnode (node)) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 716 | if ((area = getdata (node)) != NULL) |
| 717 | OSPF_EXAMINE_SUMMARIES_ALL (area, rt, rtrs); |
| 718 | } |
| 719 | } |