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