paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1 | /* |
| 2 | * OSPF Flooding -- RFC2328 Section 13. |
| 3 | * Copyright (C) 1999, 2000 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 |
| 8 | * it under the terms of the GNU General Public License as published |
| 9 | * by the Free Software Foundation; either version 2, or (at your |
| 10 | * option) any 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 |
| 19 | * Free Software Foundation, Inc., 59 Temple Place - Suite 330, |
| 20 | * Boston, MA 02111-1307, USA. |
| 21 | */ |
| 22 | |
| 23 | #include <zebra.h> |
| 24 | |
| 25 | #include "linklist.h" |
| 26 | #include "prefix.h" |
| 27 | #include "if.h" |
| 28 | #include "command.h" |
| 29 | #include "table.h" |
| 30 | #include "thread.h" |
| 31 | #include "memory.h" |
| 32 | #include "log.h" |
| 33 | #include "zclient.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_flood.h" |
| 45 | #include "ospfd/ospf_packet.h" |
| 46 | #include "ospfd/ospf_abr.h" |
| 47 | #include "ospfd/ospf_route.h" |
| 48 | #include "ospfd/ospf_zebra.h" |
| 49 | #include "ospfd/ospf_dump.h" |
| 50 | |
| 51 | extern struct zclient *zclient; |
| 52 | |
| 53 | /* Do the LSA acking specified in table 19, Section 13.5, row 2 |
| 54 | * This get called from ospf_flood_out_interface. Declared inline |
| 55 | * for speed. */ |
| 56 | static void |
| 57 | ospf_flood_delayed_lsa_ack (struct ospf_neighbor *inbr, struct ospf_lsa *lsa) |
| 58 | { |
| 59 | /* LSA is more recent than database copy, but was not |
| 60 | flooded back out receiving interface. Delayed |
| 61 | acknowledgment sent. If interface is in Backup state |
| 62 | delayed acknowledgment sent only if advertisement |
| 63 | received from Designated Router, otherwise do nothing See |
| 64 | RFC 2328 Section 13.5 */ |
| 65 | |
| 66 | /* Whether LSA is more recent or not, and whether this is in |
| 67 | response to the LSA being sent out recieving interface has been |
| 68 | worked out previously */ |
| 69 | |
| 70 | /* Deal with router as BDR */ |
| 71 | if (inbr->oi->state == ISM_Backup && ! NBR_IS_DR (inbr)) |
| 72 | return; |
| 73 | |
| 74 | /* Schedule a delayed LSA Ack to be sent */ |
| 75 | listnode_add (inbr->oi->ls_ack, ospf_lsa_lock (lsa)); |
| 76 | } |
| 77 | |
| 78 | /* Check LSA is related to external info. */ |
| 79 | struct external_info * |
| 80 | ospf_external_info_check (struct ospf_lsa *lsa) |
| 81 | { |
| 82 | struct as_external_lsa *al; |
| 83 | struct prefix_ipv4 p; |
| 84 | struct route_node *rn; |
| 85 | int type; |
| 86 | |
| 87 | al = (struct as_external_lsa *) lsa->data; |
| 88 | |
| 89 | p.family = AF_INET; |
| 90 | p.prefix = lsa->data->id; |
| 91 | p.prefixlen = ip_masklen (al->mask); |
| 92 | |
| 93 | for (type = 0; type <= ZEBRA_ROUTE_MAX; type++) |
| 94 | { |
| 95 | int redist_type = is_prefix_default (&p) ? DEFAULT_ROUTE : type; |
| 96 | if (ospf_is_type_redistributed (redist_type)) |
| 97 | if (EXTERNAL_INFO (type)) |
| 98 | { |
| 99 | rn = route_node_lookup (EXTERNAL_INFO (type), |
| 100 | (struct prefix *) &p); |
| 101 | if (rn) |
| 102 | { |
| 103 | route_unlock_node (rn); |
| 104 | if (rn->info != NULL) |
| 105 | return (struct external_info *) rn->info; |
| 106 | } |
| 107 | } |
| 108 | } |
| 109 | |
| 110 | return NULL; |
| 111 | } |
| 112 | |
| 113 | void |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 114 | ospf_process_self_originated_lsa (struct ospf *ospf, |
| 115 | struct ospf_lsa *new, struct ospf_area *area) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 116 | { |
| 117 | struct ospf_interface *oi; |
| 118 | struct external_info *ei; |
| 119 | listnode node; |
| 120 | |
| 121 | if (IS_DEBUG_OSPF_EVENT) |
paul | 7ddf1d6 | 2003-10-13 09:06:46 +0000 | [diff] [blame] | 122 | zlog_info ("LSA[Type%d:%s]: Process self-originated LSA seq 0x%lx", |
| 123 | new->data->type, inet_ntoa (new->data->id), |
| 124 | (u_long)new->data->ls_seqnum); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 125 | |
| 126 | /* If we're here, we installed a self-originated LSA that we received |
| 127 | from a neighbor, i.e. it's more recent. We must see whether we want |
| 128 | to originate it. |
| 129 | If yes, we should use this LSA's sequence number and reoriginate |
| 130 | a new instance. |
| 131 | if not --- we must flush this LSA from the domain. */ |
| 132 | switch (new->data->type) |
| 133 | { |
| 134 | case OSPF_ROUTER_LSA: |
| 135 | /* Originate a new instance and schedule flooding */ |
| 136 | /* It shouldn't be necessary, but anyway */ |
| 137 | ospf_lsa_unlock (area->router_lsa_self); |
| 138 | area->router_lsa_self = ospf_lsa_lock (new); |
| 139 | |
| 140 | ospf_router_lsa_timer_add (area); |
| 141 | return; |
| 142 | case OSPF_NETWORK_LSA: |
| 143 | #ifdef HAVE_OPAQUE_LSA |
| 144 | case OSPF_OPAQUE_LINK_LSA: |
| 145 | #endif /* HAVE_OPAQUE_LSA */ |
| 146 | /* We must find the interface the LSA could belong to. |
| 147 | If the interface is no more a broadcast type or we are no more |
| 148 | the DR, we flush the LSA otherwise -- create the new instance and |
| 149 | schedule flooding. */ |
| 150 | |
| 151 | /* Look through all interfaces, not just area, since interface |
| 152 | could be moved from one area to another. */ |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 153 | for (node = listhead (ospf->oiflist); node; nextnode (node)) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 154 | /* These are sanity check. */ |
| 155 | if ((oi = getdata (node)) != NULL) |
| 156 | if (IPV4_ADDR_SAME (&oi->address->u.prefix4, &new->data->id)) |
| 157 | { |
| 158 | if (oi->area != area || |
| 159 | oi->type != OSPF_IFTYPE_BROADCAST || |
| 160 | !IPV4_ADDR_SAME (&oi->address->u.prefix4, &DR (oi))) |
| 161 | { |
| 162 | ospf_schedule_lsa_flush_area (area, new); |
| 163 | return; |
| 164 | } |
| 165 | |
| 166 | #ifdef HAVE_OPAQUE_LSA |
| 167 | if (new->data->type == OSPF_OPAQUE_LINK_LSA) |
| 168 | { |
| 169 | ospf_opaque_lsa_refresh (new); |
| 170 | return; |
| 171 | } |
| 172 | #endif /* HAVE_OPAQUE_LSA */ |
| 173 | |
| 174 | ospf_lsa_unlock (oi->network_lsa_self); |
| 175 | oi->network_lsa_self = ospf_lsa_lock (new); |
| 176 | |
| 177 | /* Schedule network-LSA origination. */ |
| 178 | ospf_network_lsa_timer_add (oi); |
| 179 | return; |
| 180 | } |
| 181 | break; |
| 182 | case OSPF_SUMMARY_LSA: |
| 183 | case OSPF_ASBR_SUMMARY_LSA: |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 184 | ospf_schedule_abr_task (ospf); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 185 | break; |
| 186 | case OSPF_AS_EXTERNAL_LSA : |
| 187 | #ifdef HAVE_NSSA |
| 188 | case OSPF_AS_NSSA_LSA: |
paul | d4a53d5 | 2003-07-12 21:30:57 +0000 | [diff] [blame] | 189 | if ( (new->data->type == OSPF_AS_EXTERNAL_LSA) |
| 190 | && CHECK_FLAG (new->flags, OSPF_LSA_LOCAL_XLT)) |
| 191 | { |
| 192 | ospf_translated_nssa_refresh (ospf, NULL, new); |
| 193 | return; |
| 194 | } |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 195 | #endif /* HAVE_NSSA */ |
| 196 | ei = ospf_external_info_check (new); |
| 197 | if (ei) |
paul | d4a53d5 | 2003-07-12 21:30:57 +0000 | [diff] [blame] | 198 | ospf_external_lsa_refresh (ospf, new, ei, LSA_REFRESH_FORCE); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 199 | else |
paul | d4a53d5 | 2003-07-12 21:30:57 +0000 | [diff] [blame] | 200 | ospf_lsa_flush_as (ospf, new); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 201 | break; |
| 202 | #ifdef HAVE_OPAQUE_LSA |
| 203 | case OSPF_OPAQUE_AREA_LSA: |
| 204 | ospf_opaque_lsa_refresh (new); |
| 205 | break; |
| 206 | case OSPF_OPAQUE_AS_LSA: |
| 207 | ospf_opaque_lsa_refresh (new); /* Reconsideration may needed. *//* XXX */ |
| 208 | break; |
| 209 | #endif /* HAVE_OPAQUE_LSA */ |
| 210 | default: |
| 211 | break; |
| 212 | } |
| 213 | } |
| 214 | |
| 215 | /* OSPF LSA flooding -- RFC2328 Section 13.(5). */ |
| 216 | |
| 217 | /* Now Updated for NSSA operation, as follows: |
| 218 | |
| 219 | |
| 220 | Type-5's have no change. Blocked to STUB or NSSA. |
| 221 | |
| 222 | Type-7's can be received, and if a DR |
| 223 | they will also flood the local NSSA Area as Type-7's |
| 224 | |
| 225 | If a Self-Originated LSA (now an ASBR), |
| 226 | The LSDB will be updated as Type-5's, (for continual re-fresh) |
| 227 | |
| 228 | If an NSSA-IR it is installed/flooded as Type-7, P-bit on. |
| 229 | if an NSSA-ABR it is installed/flooded as Type-7, P-bit off. |
| 230 | |
| 231 | Later, during the ABR TASK, if the ABR is the Elected NSSA |
| 232 | translator, then All Type-7s (with P-bit ON) are Translated to |
| 233 | Type-5's and flooded to all non-NSSA/STUB areas. |
| 234 | |
| 235 | During ASE Calculations, |
| 236 | non-ABRs calculate external routes from Type-7's |
| 237 | ABRs calculate external routes from Type-5's and non-self Type-7s |
| 238 | */ |
| 239 | int |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 240 | ospf_flood (struct ospf *ospf, struct ospf_neighbor *nbr, |
| 241 | struct ospf_lsa *current, struct ospf_lsa *new) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 242 | { |
| 243 | struct ospf_interface *oi; |
| 244 | struct timeval now; |
| 245 | int lsa_ack_flag; |
| 246 | |
| 247 | /* Type-7 LSA's will be flooded throughout their native NSSA area, |
| 248 | but will also be flooded as Type-5's into ABR capable links. */ |
| 249 | |
| 250 | if (IS_DEBUG_OSPF_EVENT) |
| 251 | zlog_info ("LSA[Flooding]: start, NBR %s (%s), cur(%p), New-LSA[%s]", |
| 252 | inet_ntoa (nbr->router_id), |
| 253 | LOOKUP (ospf_nsm_state_msg, nbr->state), |
| 254 | current, |
| 255 | dump_lsa_key (new)); |
| 256 | |
| 257 | lsa_ack_flag = 0; |
| 258 | oi = nbr->oi; |
| 259 | |
| 260 | /* Get current time. */ |
| 261 | gettimeofday (&now, NULL); |
| 262 | |
| 263 | /* If there is already a database copy, and if the |
| 264 | database copy was received via flooding and installed less |
| 265 | than MinLSArrival seconds ago, discard the new LSA |
| 266 | (without acknowledging it). */ |
| 267 | if (current != NULL) /* -- endo. */ |
| 268 | { |
| 269 | if (IS_LSA_SELF (current) |
| 270 | && (ntohs (current->data->ls_age) == 0 |
| 271 | && ntohl (current->data->ls_seqnum) == OSPF_INITIAL_SEQUENCE_NUMBER)) |
| 272 | { |
| 273 | if (IS_DEBUG_OSPF_EVENT) |
| 274 | zlog_info ("LSA[Flooding]: Got a self-originated LSA, " |
| 275 | "while local one is initial instance."); |
| 276 | ; /* Accept this LSA for quick LSDB resynchronization. */ |
| 277 | } |
| 278 | else if (tv_cmp (tv_sub (now, current->tv_recv), |
| 279 | int2tv (OSPF_MIN_LS_ARRIVAL)) < 0) |
| 280 | { |
| 281 | if (IS_DEBUG_OSPF_EVENT) |
| 282 | zlog_info ("LSA[Flooding]: LSA is received recently."); |
| 283 | return -1; |
| 284 | } |
| 285 | } |
| 286 | |
| 287 | /* Flood the new LSA out some subset of the router's interfaces. |
| 288 | In some cases (e.g., the state of the receiving interface is |
| 289 | DR and the LSA was received from a router other than the |
| 290 | Backup DR) the LSA will be flooded back out the receiving |
| 291 | interface. */ |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 292 | lsa_ack_flag = ospf_flood_through (ospf, nbr, new); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 293 | |
| 294 | #ifdef HAVE_OPAQUE_LSA |
| 295 | /* Remove the current database copy from all neighbors' Link state |
| 296 | retransmission lists. AS_EXTERNAL and AS_EXTERNAL_OPAQUE does |
| 297 | ^^^^^^^^^^^^^^^^^^^^^^^ |
| 298 | not have area ID. |
| 299 | All other (even NSSA's) do have area ID. */ |
| 300 | #else /* HAVE_OPAQUE_LSA */ |
| 301 | /* Remove the current database copy from all neighbors' Link state |
| 302 | retransmission lists. Only AS_EXTERNAL does not have area ID. |
| 303 | All other (even NSSA's) do have area ID. */ |
| 304 | #endif /* HAVE_OPAQUE_LSA */ |
| 305 | if (current) |
| 306 | { |
| 307 | switch (current->data->type) |
| 308 | { |
| 309 | case OSPF_AS_EXTERNAL_LSA: |
| 310 | #ifdef HAVE_OPAQUE_LSA |
| 311 | case OSPF_OPAQUE_AS_LSA: |
| 312 | #endif /* HAVE_OPAQUE_LSA */ |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 313 | ospf_ls_retransmit_delete_nbr_as (ospf, current); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 314 | break; |
| 315 | default: |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 316 | ospf_ls_retransmit_delete_nbr_area (nbr->oi->area, current); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 317 | break; |
| 318 | } |
| 319 | } |
| 320 | |
| 321 | /* Do some internal house keeping that is needed here */ |
| 322 | SET_FLAG (new->flags, OSPF_LSA_RECEIVED); |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 323 | ospf_lsa_is_self_originated (ospf, new); /* Let it set the flag */ |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 324 | |
| 325 | /* Install the new LSA in the link state database |
| 326 | (replacing the current database copy). This may cause the |
| 327 | routing table calculation to be scheduled. In addition, |
| 328 | timestamp the new LSA with the current time. The flooding |
| 329 | procedure cannot overwrite the newly installed LSA until |
| 330 | MinLSArrival seconds have elapsed. */ |
| 331 | |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 332 | new = ospf_lsa_install (ospf, nbr->oi, new); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 333 | |
| 334 | /* Acknowledge the receipt of the LSA by sending a Link State |
| 335 | Acknowledgment packet back out the receiving interface. */ |
| 336 | if (lsa_ack_flag) |
| 337 | ospf_flood_delayed_lsa_ack (nbr, new); |
| 338 | |
| 339 | /* If this new LSA indicates that it was originated by the |
| 340 | receiving router itself, the router must take special action, |
| 341 | either updating the LSA or in some cases flushing it from |
| 342 | the routing domain. */ |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 343 | if (ospf_lsa_is_self_originated (ospf, new)) |
| 344 | ospf_process_self_originated_lsa (ospf, new, oi->area); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 345 | else |
| 346 | /* Update statistics value for OSPF-MIB. */ |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 347 | ospf->rx_lsa_count++; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 348 | |
| 349 | return 0; |
| 350 | } |
| 351 | |
| 352 | /* OSPF LSA flooding -- RFC2328 Section 13.3. */ |
| 353 | int |
| 354 | ospf_flood_through_interface (struct ospf_interface *oi, |
| 355 | struct ospf_neighbor *inbr, |
| 356 | struct ospf_lsa *lsa) |
| 357 | { |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 358 | struct ospf *ospf = oi->ospf; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 359 | struct ospf_neighbor *onbr; |
| 360 | struct route_node *rn; |
| 361 | int retx_flag; |
| 362 | |
| 363 | if (IS_DEBUG_OSPF_EVENT) |
| 364 | zlog_info ("ospf_flood_through_interface(): " |
| 365 | "considering int %s, INBR(%s), LSA[%s]", |
| 366 | IF_NAME (oi), inbr ? inet_ntoa (inbr->router_id) : "NULL", |
| 367 | dump_lsa_key (lsa)); |
| 368 | |
| 369 | if (!ospf_if_is_enable (oi)) |
| 370 | return 0; |
| 371 | |
| 372 | /* Remember if new LSA is aded to a retransmit list. */ |
| 373 | retx_flag = 0; |
| 374 | |
| 375 | /* Each of the neighbors attached to this interface are examined, |
| 376 | to determine whether they must receive the new LSA. The following |
| 377 | steps are executed for each neighbor: */ |
| 378 | for (rn = route_top (oi->nbrs); rn; rn = route_next (rn)) |
| 379 | { |
| 380 | struct ospf_lsa *ls_req; |
| 381 | |
| 382 | if (rn->info == NULL) |
| 383 | continue; |
| 384 | |
| 385 | onbr = rn->info; |
| 386 | if (IS_DEBUG_OSPF_EVENT) |
| 387 | zlog_info ("ospf_flood_through_interface(): considering nbr %s (%s)", |
| 388 | inet_ntoa (onbr->router_id), |
| 389 | LOOKUP (ospf_nsm_state_msg, onbr->state)); |
| 390 | |
| 391 | /* If the neighbor is in a lesser state than Exchange, it |
| 392 | does not participate in flooding, and the next neighbor |
| 393 | should be examined. */ |
| 394 | if (onbr->state < NSM_Exchange) |
| 395 | continue; |
| 396 | |
| 397 | /* If the adjacency is not yet full (neighbor state is |
| 398 | Exchange or Loading), examine the Link state request |
| 399 | list associated with this adjacency. If there is an |
| 400 | instance of the new LSA on the list, it indicates that |
| 401 | the neighboring router has an instance of the LSA |
| 402 | already. Compare the new LSA to the neighbor's copy: */ |
| 403 | if (onbr->state < NSM_Full) |
| 404 | { |
| 405 | if (IS_DEBUG_OSPF_EVENT) |
| 406 | zlog_info ("ospf_flood_through_interface(): nbr adj is not Full"); |
| 407 | ls_req = ospf_ls_request_lookup (onbr, lsa); |
| 408 | if (ls_req != NULL) |
| 409 | { |
| 410 | int ret; |
| 411 | |
| 412 | ret = ospf_lsa_more_recent (ls_req, lsa); |
| 413 | /* The new LSA is less recent. */ |
| 414 | if (ret > 0) |
| 415 | continue; |
| 416 | /* The two copies are the same instance, then delete |
| 417 | the LSA from the Link state request list. */ |
| 418 | else if (ret == 0) |
| 419 | { |
| 420 | ospf_ls_request_delete (onbr, ls_req); |
| 421 | ospf_check_nbr_loading (onbr); |
| 422 | continue; |
| 423 | } |
| 424 | /* The new LSA is more recent. Delete the LSA |
| 425 | from the Link state request list. */ |
| 426 | else |
| 427 | { |
| 428 | ospf_ls_request_delete (onbr, ls_req); |
| 429 | ospf_check_nbr_loading (onbr); |
| 430 | } |
| 431 | } |
| 432 | } |
| 433 | |
| 434 | #ifdef HAVE_OPAQUE_LSA |
| 435 | if (IS_OPAQUE_LSA (lsa->data->type)) |
| 436 | { |
| 437 | if (! CHECK_FLAG (onbr->options, OSPF_OPTION_O)) |
| 438 | { |
| 439 | if (IS_DEBUG_OSPF (lsa, LSA_FLOODING)) |
| 440 | zlog_info ("Skip this neighbor: Not Opaque-capable."); |
| 441 | continue; |
| 442 | } |
| 443 | |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 444 | if (IS_OPAQUE_LSA_ORIGINATION_BLOCKED (ospf->opaque) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 445 | && IS_LSA_SELF (lsa) |
| 446 | && onbr->state == NSM_Full) |
| 447 | { |
| 448 | /* Small attempt to reduce unnecessary retransmission. */ |
| 449 | if (IS_DEBUG_OSPF (lsa, LSA_FLOODING)) |
| 450 | zlog_info ("Skip this neighbor: Initial flushing done."); |
| 451 | continue; |
| 452 | } |
| 453 | } |
| 454 | #endif /* HAVE_OPAQUE_LSA */ |
| 455 | |
| 456 | /* If the new LSA was received from this neighbor, |
| 457 | examine the next neighbor. */ |
| 458 | #ifdef ORIGINAL_CODING |
| 459 | if (inbr) |
| 460 | if (IPV4_ADDR_SAME (&inbr->router_id, &onbr->router_id)) |
| 461 | continue; |
| 462 | #else /* ORIGINAL_CODING */ |
| 463 | if (inbr) |
| 464 | { |
| 465 | /* |
| 466 | * Triggered by LSUpd message parser "ospf_ls_upd ()". |
| 467 | * E.g., all LSAs handling here is received via network. |
| 468 | */ |
| 469 | if (IPV4_ADDR_SAME (&inbr->router_id, &onbr->router_id)) |
| 470 | { |
| 471 | if (IS_DEBUG_OSPF (lsa, LSA_FLOODING)) |
| 472 | zlog_info ("Skip this neighbor: inbr == onbr"); |
| 473 | continue; |
| 474 | } |
| 475 | } |
| 476 | else |
| 477 | { |
| 478 | /* |
| 479 | * Triggered by MaxAge remover, so far. |
| 480 | * NULL "inbr" means flooding starts from this node. |
| 481 | */ |
| 482 | if (IPV4_ADDR_SAME (&lsa->data->adv_router, &onbr->router_id)) |
| 483 | { |
| 484 | if (IS_DEBUG_OSPF (lsa, LSA_FLOODING)) |
| 485 | zlog_info ("Skip this neighbor: lsah->adv_router == onbr"); |
| 486 | continue; |
| 487 | } |
| 488 | } |
| 489 | #endif /* ORIGINAL_CODING */ |
| 490 | |
| 491 | /* Add the new LSA to the Link state retransmission list |
| 492 | for the adjacency. The LSA will be retransmitted |
| 493 | at intervals until an acknowledgment is seen from |
| 494 | the neighbor. */ |
| 495 | ospf_ls_retransmit_add (onbr, lsa); |
| 496 | retx_flag = 1; |
| 497 | } |
| 498 | |
| 499 | /* If in the previous step, the LSA was NOT added to any of |
| 500 | the Link state retransmission lists, there is no need to |
| 501 | flood the LSA out the interface. */ |
| 502 | if (retx_flag == 0) |
| 503 | { |
| 504 | return (inbr && inbr->oi == oi); |
| 505 | } |
| 506 | |
| 507 | /* if we've received the lsa on this interface we need to perform |
| 508 | additional checking */ |
| 509 | if (inbr && (inbr->oi == oi)) |
| 510 | { |
| 511 | /* If the new LSA was received on this interface, and it was |
| 512 | received from either the Designated Router or the Backup |
| 513 | Designated Router, chances are that all the neighbors have |
| 514 | received the LSA already. */ |
| 515 | if (NBR_IS_DR (inbr) || NBR_IS_BDR (inbr)) |
| 516 | { |
| 517 | #ifdef HAVE_NSSA |
| 518 | if (IS_DEBUG_OSPF_NSSA) |
| 519 | zlog_info ("ospf_flood_through_interface(): " |
| 520 | "DR/BDR NOT SEND to int %s", IF_NAME (oi)); |
| 521 | #endif /* HAVE_NSSA */ |
| 522 | return 1; |
| 523 | } |
| 524 | |
| 525 | /* If the new LSA was received on this interface, and the |
| 526 | interface state is Backup, examine the next interface. The |
| 527 | Designated Router will do the flooding on this interface. |
| 528 | However, if the Designated Router fails the router will |
| 529 | end up retransmitting the updates. */ |
| 530 | |
| 531 | if (oi->state == ISM_Backup) |
| 532 | { |
| 533 | #ifdef HAVE_NSSA |
| 534 | if (IS_DEBUG_OSPF_NSSA) |
| 535 | zlog_info ("ospf_flood_through_interface(): " |
| 536 | "ISM_Backup NOT SEND to int %s", IF_NAME (oi)); |
| 537 | #endif /* HAVE_NSSA */ |
| 538 | return 1; |
| 539 | } |
| 540 | } |
| 541 | |
| 542 | /* The LSA must be flooded out the interface. Send a Link State |
| 543 | Update packet (including the new LSA as contents) out the |
| 544 | interface. The LSA's LS age must be incremented by InfTransDelay |
| 545 | (which must be > 0) when it is copied into the outgoing Link |
| 546 | State Update packet (until the LS age field reaches the maximum |
| 547 | value of MaxAge). */ |
| 548 | |
| 549 | #ifdef HAVE_NSSA |
| 550 | if (IS_DEBUG_OSPF_NSSA) |
| 551 | zlog_info ("ospf_flood_through_interface(): " |
| 552 | "DR/BDR sending upd to int %s", IF_NAME (oi)); |
| 553 | #else /* ! HAVE_NSSA */ |
| 554 | |
| 555 | if (IS_DEBUG_OSPF_EVENT) |
| 556 | zlog_info ("ospf_flood_through_interface(): " |
| 557 | "sending upd to int %s", IF_NAME (oi)); |
| 558 | #endif /* HAVE_NSSA */ |
| 559 | |
| 560 | /* RFC2328 Section 13.3 |
| 561 | On non-broadcast networks, separate Link State Update |
| 562 | packets must be sent, as unicasts, to each adjacent neighbor |
| 563 | (i.e., those in state Exchange or greater). The destination |
| 564 | IP addresses for these packets are the neighbors' IP |
| 565 | addresses. */ |
| 566 | if (oi->type == OSPF_IFTYPE_NBMA) |
| 567 | { |
| 568 | struct route_node *rn; |
| 569 | struct ospf_neighbor *nbr; |
| 570 | |
| 571 | for (rn = route_top (oi->nbrs); rn; rn = route_next (rn)) |
| 572 | if ((nbr = rn->info) != NULL) |
| 573 | if (nbr != oi->nbr_self && nbr->state >= NSM_Exchange) |
| 574 | ospf_ls_upd_send_lsa (nbr, lsa, OSPF_SEND_PACKET_DIRECT); |
| 575 | } |
| 576 | else |
| 577 | ospf_ls_upd_send_lsa (oi->nbr_self, lsa, OSPF_SEND_PACKET_INDIRECT); |
| 578 | |
| 579 | return 0; |
| 580 | } |
| 581 | |
| 582 | int |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 583 | ospf_flood_through_area (struct ospf_area *area, |
| 584 | struct ospf_neighbor *inbr, struct ospf_lsa *lsa) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 585 | { |
| 586 | listnode node; |
| 587 | int lsa_ack_flag = 0; |
| 588 | |
| 589 | /* All other types are specific to a single area (Area A). The |
| 590 | eligible interfaces are all those interfaces attaching to the |
| 591 | Area A. If Area A is the backbone, this includes all the virtual |
| 592 | links. */ |
| 593 | for (node = listhead (area->oiflist); node; nextnode (node)) |
| 594 | { |
| 595 | struct ospf_interface *oi = getdata (node); |
| 596 | |
| 597 | if (area->area_id.s_addr != OSPF_AREA_BACKBONE && |
| 598 | oi->type == OSPF_IFTYPE_VIRTUALLINK) |
| 599 | continue; |
| 600 | |
| 601 | #ifdef HAVE_OPAQUE_LSA |
| 602 | if ((lsa->data->type == OSPF_OPAQUE_LINK_LSA) && (lsa->oi != oi)) |
| 603 | { |
| 604 | /* |
| 605 | * Link local scoped Opaque-LSA should only be flooded |
| 606 | * for the link on which the LSA has received. |
| 607 | */ |
| 608 | if (IS_DEBUG_OSPF (lsa, LSA_FLOODING)) |
| 609 | zlog_info ("Type-9 Opaque-LSA: lsa->oi(%p) != oi(%p)", lsa->oi, oi); |
| 610 | continue; |
| 611 | } |
| 612 | #endif /* HAVE_OPAQUE_LSA */ |
| 613 | |
| 614 | if (ospf_flood_through_interface (oi, inbr, lsa)) |
| 615 | lsa_ack_flag = 1; |
| 616 | } |
| 617 | |
| 618 | return (lsa_ack_flag); |
| 619 | } |
| 620 | |
| 621 | int |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 622 | ospf_flood_through_as (struct ospf *ospf, struct ospf_neighbor *inbr, |
| 623 | struct ospf_lsa *lsa) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 624 | { |
| 625 | listnode node; |
| 626 | int lsa_ack_flag; |
| 627 | |
| 628 | lsa_ack_flag = 0; |
| 629 | |
| 630 | /* The incoming LSA is type 5 or type 7 (AS-EXTERNAL or AS-NSSA ) |
| 631 | |
| 632 | Divert the Type-5 LSA's to all non-NSSA/STUB areas |
| 633 | |
| 634 | Divert the Type-7 LSA's to all NSSA areas |
| 635 | |
| 636 | AS-external-LSAs are flooded throughout the entire AS, with the |
| 637 | exception of stub areas (see Section 3.6). The eligible |
| 638 | interfaces are all the router's interfaces, excluding virtual |
| 639 | links and those interfaces attaching to stub areas. */ |
| 640 | |
| 641 | #ifdef HAVE_NSSA |
| 642 | if (CHECK_FLAG (lsa->flags, OSPF_LSA_LOCAL_XLT)) /* Translated from 7 */ |
| 643 | if (IS_DEBUG_OSPF_NSSA) |
| 644 | zlog_info ("Flood/AS: NSSA TRANSLATED LSA"); |
| 645 | #endif /* HAVE_NSSA */ |
| 646 | |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 647 | for (node = listhead (ospf->areas); node; nextnode (node)) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 648 | { |
| 649 | int continue_flag = 0; |
| 650 | struct ospf_area *area = getdata (node); |
| 651 | listnode if_node; |
| 652 | |
| 653 | switch (area->external_routing) |
| 654 | { |
| 655 | /* Don't send AS externals into stub areas. Various types |
| 656 | of support for partial stub areas can be implemented |
| 657 | here. NSSA's will receive Type-7's that have areas |
| 658 | matching the originl LSA. */ |
| 659 | case OSPF_AREA_NSSA: /* Sending Type 5 or 7 into NSSA area */ |
| 660 | #ifdef HAVE_NSSA |
| 661 | /* Type-7, flood NSSA area */ |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 662 | if (lsa->data->type == OSPF_AS_NSSA_LSA |
| 663 | && area == lsa->area) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 664 | /* We will send it. */ |
| 665 | continue_flag = 0; |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 666 | else |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 667 | continue_flag = 1; /* Skip this NSSA area for Type-5's et al */ |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 668 | break; |
| 669 | #endif /* HAVE_NSSA */ |
| 670 | |
| 671 | case OSPF_AREA_TYPE_MAX: |
| 672 | case OSPF_AREA_STUB: |
| 673 | continue_flag = 1; /* Skip this area. */ |
| 674 | break; |
| 675 | |
| 676 | case OSPF_AREA_DEFAULT: |
| 677 | default: |
| 678 | #ifdef HAVE_NSSA |
| 679 | /* No Type-7 into normal area */ |
| 680 | if (lsa->data->type == OSPF_AS_NSSA_LSA) |
| 681 | continue_flag = 1; /* skip Type-7 */ |
| 682 | else |
| 683 | #endif /* HAVE_NSSA */ |
| 684 | continue_flag = 0; /* Do this area. */ |
| 685 | break; |
| 686 | } |
| 687 | |
| 688 | /* Do continue for above switch. Saves a big if then mess */ |
| 689 | if (continue_flag) |
| 690 | continue; /* main for-loop */ |
| 691 | |
| 692 | /* send to every interface in this area */ |
| 693 | |
| 694 | for (if_node = listhead (area->oiflist); if_node; nextnode (if_node)) |
| 695 | { |
| 696 | struct ospf_interface *oi = getdata (if_node); |
| 697 | |
| 698 | /* Skip virtual links */ |
| 699 | if (oi->type != OSPF_IFTYPE_VIRTUALLINK) |
| 700 | if (ospf_flood_through_interface (oi, inbr, lsa)) /* lsa */ |
| 701 | lsa_ack_flag = 1; |
| 702 | } |
| 703 | } /* main area for-loop */ |
| 704 | |
| 705 | return (lsa_ack_flag); |
| 706 | } |
| 707 | |
| 708 | int |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 709 | ospf_flood_through (struct ospf *ospf, |
| 710 | struct ospf_neighbor *inbr, struct ospf_lsa *lsa) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 711 | { |
| 712 | int lsa_ack_flag = 0; |
| 713 | |
| 714 | /* Type-7 LSA's for NSSA are flooded throughout the AS here, and |
| 715 | upon return are updated in the LSDB for Type-7's. Later, |
| 716 | re-fresh will re-send them (and also, if ABR, packet code will |
| 717 | translate to Type-5's) |
| 718 | |
| 719 | As usual, Type-5 LSA's (if not DISCARDED because we are STUB or |
| 720 | NSSA) are flooded throughout the AS, and are updated in the |
| 721 | global table. */ |
| 722 | #ifdef ORIGINAL_CODING |
| 723 | switch (lsa->data->type) |
| 724 | { |
| 725 | case OSPF_ROUTER_LSA: |
| 726 | case OSPF_NETWORK_LSA: |
| 727 | case OSPF_SUMMARY_LSA: |
| 728 | case OSPF_ASBR_SUMMARY_LSA: |
| 729 | #ifdef HAVE_OPAQUE_LSA |
| 730 | case OSPF_OPAQUE_LINK_LSA: /* ospf_flood_through_interface ? */ |
| 731 | case OSPF_OPAQUE_AREA_LSA: |
| 732 | #endif /* HAVE_OPAQUE_LSA */ |
| 733 | lsa_ack_flag = ospf_flood_through_area (inbr->oi->area, inbr, lsa); |
| 734 | break; |
| 735 | case OSPF_AS_EXTERNAL_LSA: /* Type-5 */ |
| 736 | #ifdef HAVE_OPAQUE_LSA |
| 737 | case OSPF_OPAQUE_AS_LSA: |
| 738 | #endif /* HAVE_OPAQUE_LSA */ |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 739 | lsa_ack_flag = ospf_flood_through_as (ospf, inbr, lsa); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 740 | break; |
| 741 | #ifdef HAVE_NSSA |
| 742 | /* Type-7 Only received within NSSA, then flooded */ |
| 743 | case OSPF_AS_NSSA_LSA: |
| 744 | /* Any P-bit was installed with the Type-7. */ |
| 745 | lsa_ack_flag = ospf_flood_through_area (inbr->oi->area, inbr, lsa); |
| 746 | |
| 747 | if (IS_DEBUG_OSPF_NSSA) |
| 748 | zlog_info ("ospf_flood_through: LOCAL NSSA FLOOD of Type-7."); |
| 749 | break; |
| 750 | #endif /* HAVE_NSSA */ |
| 751 | default: |
| 752 | break; |
| 753 | } |
| 754 | #else /* ORIGINAL_CODING */ |
| 755 | /* |
| 756 | * At the common sub-sub-function "ospf_flood_through_interface()", |
| 757 | * a parameter "inbr" will be used to distinguish the called context |
| 758 | * whether the given LSA was received from the neighbor, or the |
| 759 | * flooding for the LSA starts from this node (e.g. the LSA was self- |
| 760 | * originated, or the LSA is going to be flushed from routing domain). |
| 761 | * |
| 762 | * So, for consistency reasons, this function "ospf_flood_through()" |
| 763 | * should also allow the usage that the given "inbr" parameter to be |
| 764 | * NULL. If we do so, corresponding AREA parameter should be referred |
| 765 | * by "lsa->area", instead of "inbr->oi->area". |
| 766 | */ |
| 767 | switch (lsa->data->type) |
| 768 | { |
| 769 | case OSPF_AS_EXTERNAL_LSA: /* Type-5 */ |
| 770 | #ifdef HAVE_OPAQUE_LSA |
| 771 | case OSPF_OPAQUE_AS_LSA: |
| 772 | #endif /* HAVE_OPAQUE_LSA */ |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 773 | lsa_ack_flag = ospf_flood_through_as (ospf, inbr, lsa); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 774 | break; |
| 775 | #ifdef HAVE_NSSA |
| 776 | /* Type-7 Only received within NSSA, then flooded */ |
| 777 | case OSPF_AS_NSSA_LSA: |
| 778 | /* Any P-bit was installed with the Type-7. */ |
| 779 | |
| 780 | if (IS_DEBUG_OSPF_NSSA) |
| 781 | zlog_info ("ospf_flood_through: LOCAL NSSA FLOOD of Type-7."); |
| 782 | /* Fallthrough */ |
| 783 | #endif /* HAVE_NSSA */ |
| 784 | default: |
| 785 | lsa_ack_flag = ospf_flood_through_area (lsa->area, inbr, lsa); |
| 786 | break; |
| 787 | } |
| 788 | #endif /* ORIGINAL_CODING */ |
| 789 | |
| 790 | return (lsa_ack_flag); |
| 791 | } |
| 792 | |
| 793 | |
| 794 | |
| 795 | /* Management functions for neighbor's Link State Request list. */ |
| 796 | void |
| 797 | ospf_ls_request_add (struct ospf_neighbor *nbr, struct ospf_lsa *lsa) |
| 798 | { |
| 799 | /* |
| 800 | * We cannot make use of the newly introduced callback function |
| 801 | * "lsdb->new_lsa_hook" to replace debug output below, just because |
| 802 | * it seems no simple and smart way to pass neighbor information to |
| 803 | * the common function "ospf_lsdb_add()" -- endo. |
| 804 | */ |
| 805 | if (IS_DEBUG_OSPF (lsa, LSA_FLOODING)) |
| 806 | zlog_info ("RqstL(%lu)++, NBR(%s), LSA[%s]", |
| 807 | ospf_ls_request_count (nbr), |
| 808 | inet_ntoa (nbr->router_id), dump_lsa_key (lsa)); |
| 809 | |
| 810 | ospf_lsdb_add (&nbr->ls_req, lsa); |
| 811 | } |
| 812 | |
| 813 | unsigned long |
| 814 | ospf_ls_request_count (struct ospf_neighbor *nbr) |
| 815 | { |
| 816 | return ospf_lsdb_count_all (&nbr->ls_req); |
| 817 | } |
| 818 | |
| 819 | int |
| 820 | ospf_ls_request_isempty (struct ospf_neighbor *nbr) |
| 821 | { |
| 822 | return ospf_lsdb_isempty (&nbr->ls_req); |
| 823 | } |
| 824 | |
| 825 | /* Remove LSA from neighbor's ls-request list. */ |
| 826 | void |
| 827 | ospf_ls_request_delete (struct ospf_neighbor *nbr, struct ospf_lsa *lsa) |
| 828 | { |
| 829 | if (nbr->ls_req_last == lsa) |
| 830 | { |
| 831 | ospf_lsa_unlock (nbr->ls_req_last); |
| 832 | nbr->ls_req_last = NULL; |
| 833 | } |
| 834 | |
| 835 | if (IS_DEBUG_OSPF (lsa, LSA_FLOODING)) /* -- endo. */ |
| 836 | zlog_info ("RqstL(%lu)--, NBR(%s), LSA[%s]", |
| 837 | ospf_ls_request_count (nbr), |
| 838 | inet_ntoa (nbr->router_id), dump_lsa_key (lsa)); |
| 839 | |
| 840 | ospf_lsdb_delete (&nbr->ls_req, lsa); |
| 841 | } |
| 842 | |
| 843 | /* Remove all LSA from neighbor's ls-requenst list. */ |
| 844 | void |
| 845 | ospf_ls_request_delete_all (struct ospf_neighbor *nbr) |
| 846 | { |
| 847 | ospf_lsa_unlock (nbr->ls_req_last); |
| 848 | nbr->ls_req_last = NULL; |
| 849 | ospf_lsdb_delete_all (&nbr->ls_req); |
| 850 | } |
| 851 | |
| 852 | /* Lookup LSA from neighbor's ls-request list. */ |
| 853 | struct ospf_lsa * |
| 854 | ospf_ls_request_lookup (struct ospf_neighbor *nbr, struct ospf_lsa *lsa) |
| 855 | { |
| 856 | return ospf_lsdb_lookup (&nbr->ls_req, lsa); |
| 857 | } |
| 858 | |
| 859 | struct ospf_lsa * |
| 860 | ospf_ls_request_new (struct lsa_header *lsah) |
| 861 | { |
| 862 | struct ospf_lsa *new; |
| 863 | |
| 864 | new = ospf_lsa_new (); |
| 865 | new->data = ospf_lsa_data_new (OSPF_LSA_HEADER_SIZE); |
| 866 | memcpy (new->data, lsah, OSPF_LSA_HEADER_SIZE); |
| 867 | |
| 868 | return new; |
| 869 | } |
| 870 | |
| 871 | |
| 872 | /* Management functions for neighbor's ls-retransmit list. */ |
| 873 | unsigned long |
| 874 | ospf_ls_retransmit_count (struct ospf_neighbor *nbr) |
| 875 | { |
| 876 | return ospf_lsdb_count_all (&nbr->ls_rxmt); |
| 877 | } |
| 878 | |
| 879 | unsigned long |
| 880 | ospf_ls_retransmit_count_self (struct ospf_neighbor *nbr, int lsa_type) |
| 881 | { |
| 882 | return ospf_lsdb_count_self (&nbr->ls_rxmt, lsa_type); |
| 883 | } |
| 884 | |
| 885 | int |
| 886 | ospf_ls_retransmit_isempty (struct ospf_neighbor *nbr) |
| 887 | { |
| 888 | return ospf_lsdb_isempty (&nbr->ls_rxmt); |
| 889 | } |
| 890 | |
| 891 | /* Add LSA to be retransmitted to neighbor's ls-retransmit list. */ |
| 892 | void |
| 893 | ospf_ls_retransmit_add (struct ospf_neighbor *nbr, struct ospf_lsa *lsa) |
| 894 | { |
| 895 | struct ospf_lsa *old; |
| 896 | |
| 897 | old = ospf_ls_retransmit_lookup (nbr, lsa); |
| 898 | |
| 899 | if (ospf_lsa_more_recent (old, lsa) < 0) |
| 900 | { |
| 901 | if (old) |
| 902 | { |
| 903 | old->retransmit_counter--; |
| 904 | ospf_lsdb_delete (&nbr->ls_rxmt, old); |
| 905 | } |
| 906 | lsa->retransmit_counter++; |
| 907 | /* |
| 908 | * We cannot make use of the newly introduced callback function |
| 909 | * "lsdb->new_lsa_hook" to replace debug output below, just because |
| 910 | * it seems no simple and smart way to pass neighbor information to |
| 911 | * the common function "ospf_lsdb_add()" -- endo. |
| 912 | */ |
| 913 | if (IS_DEBUG_OSPF (lsa, LSA_FLOODING)) |
| 914 | zlog_info ("RXmtL(%lu)++, NBR(%s), LSA[%s]", |
| 915 | ospf_ls_retransmit_count (nbr), |
| 916 | inet_ntoa (nbr->router_id), dump_lsa_key (lsa)); |
| 917 | ospf_lsdb_add (&nbr->ls_rxmt, lsa); |
| 918 | } |
| 919 | } |
| 920 | |
| 921 | /* Remove LSA from neibghbor's ls-retransmit list. */ |
| 922 | void |
| 923 | ospf_ls_retransmit_delete (struct ospf_neighbor *nbr, struct ospf_lsa *lsa) |
| 924 | { |
| 925 | if (ospf_ls_retransmit_lookup (nbr, lsa)) |
| 926 | { |
| 927 | lsa->retransmit_counter--; |
| 928 | if (IS_DEBUG_OSPF (lsa, LSA_FLOODING)) /* -- endo. */ |
| 929 | zlog_info ("RXmtL(%lu)--, NBR(%s), LSA[%s]", |
| 930 | ospf_ls_retransmit_count (nbr), |
| 931 | inet_ntoa (nbr->router_id), dump_lsa_key (lsa)); |
| 932 | ospf_lsdb_delete (&nbr->ls_rxmt, lsa); |
| 933 | } |
| 934 | } |
| 935 | |
| 936 | /* Clear neighbor's ls-retransmit list. */ |
| 937 | void |
| 938 | ospf_ls_retransmit_clear (struct ospf_neighbor *nbr) |
| 939 | { |
| 940 | struct ospf_lsdb *lsdb; |
| 941 | int i; |
| 942 | |
| 943 | lsdb = &nbr->ls_rxmt; |
| 944 | |
| 945 | for (i = OSPF_MIN_LSA; i < OSPF_MAX_LSA; i++) |
| 946 | { |
| 947 | struct route_table *table = lsdb->type[i].db; |
| 948 | struct route_node *rn; |
| 949 | struct ospf_lsa *lsa; |
| 950 | |
| 951 | for (rn = route_top (table); rn; rn = route_next (rn)) |
| 952 | if ((lsa = rn->info) != NULL) |
| 953 | ospf_ls_retransmit_delete (nbr, lsa); |
| 954 | } |
| 955 | |
| 956 | ospf_lsa_unlock (nbr->ls_req_last); |
| 957 | nbr->ls_req_last = NULL; |
| 958 | } |
| 959 | |
| 960 | /* Lookup LSA from neighbor's ls-retransmit list. */ |
| 961 | struct ospf_lsa * |
| 962 | ospf_ls_retransmit_lookup (struct ospf_neighbor *nbr, struct ospf_lsa *lsa) |
| 963 | { |
| 964 | return ospf_lsdb_lookup (&nbr->ls_rxmt, lsa); |
| 965 | } |
| 966 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 967 | void |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 968 | ospf_ls_retransmit_delete_nbr_if (struct ospf_interface *oi, |
| 969 | struct ospf_lsa *lsa) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 970 | { |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 971 | struct route_node *rn; |
| 972 | struct ospf_neighbor *nbr; |
| 973 | struct ospf_lsa *lsr; |
| 974 | |
| 975 | if (ospf_if_is_enable (oi)) |
| 976 | for (rn = route_top (oi->nbrs); rn; rn = route_next (rn)) |
| 977 | /* If LSA find in LS-retransmit list, then remove it. */ |
| 978 | if ((nbr = rn->info) != NULL) |
| 979 | { |
| 980 | lsr = ospf_ls_retransmit_lookup (nbr, lsa); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 981 | |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 982 | /* If LSA find in ls-retransmit list, remove it. */ |
| 983 | if (lsr != NULL && lsr->data->ls_seqnum == lsa->data->ls_seqnum) |
| 984 | ospf_ls_retransmit_delete (nbr, lsr); |
| 985 | } |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 986 | } |
| 987 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 988 | void |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 989 | ospf_ls_retransmit_delete_nbr_area (struct ospf_area *area, |
| 990 | struct ospf_lsa *lsa) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 991 | { |
| 992 | listnode node; |
| 993 | |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 994 | for (node = listhead (area->oiflist); node; nextnode (node)) |
| 995 | ospf_ls_retransmit_delete_nbr_if (getdata (node), lsa); |
| 996 | } |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 997 | |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 998 | void |
| 999 | ospf_ls_retransmit_delete_nbr_as (struct ospf *ospf, struct ospf_lsa *lsa) |
| 1000 | { |
| 1001 | listnode node; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1002 | |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 1003 | for (node = listhead (ospf->oiflist); node; nextnode (node)) |
| 1004 | ospf_ls_retransmit_delete_nbr_if (getdata (node), lsa); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1005 | } |
| 1006 | |
| 1007 | |
| 1008 | /* Sets ls_age to MaxAge and floods throu the area. |
| 1009 | When we implement ASE routing, there will be anothe function |
| 1010 | flushing an LSA from the whole domain. */ |
| 1011 | void |
| 1012 | ospf_lsa_flush_area (struct ospf_lsa *lsa, struct ospf_area *area) |
| 1013 | { |
| 1014 | lsa->data->ls_age = htons (OSPF_LSA_MAXAGE); |
| 1015 | ospf_flood_through_area (area, NULL, lsa); |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 1016 | ospf_lsa_maxage (area->ospf, lsa); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1017 | } |
| 1018 | |
| 1019 | void |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 1020 | ospf_lsa_flush_as (struct ospf *ospf, struct ospf_lsa *lsa) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1021 | { |
| 1022 | lsa->data->ls_age = htons (OSPF_LSA_MAXAGE); |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 1023 | ospf_flood_through_as (ospf, NULL, lsa); |
| 1024 | ospf_lsa_maxage (ospf, lsa); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1025 | } |