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