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