blob: a8b7e37a447c2bef228ec7116e22f5dd0c755330 [file] [log] [blame]
paul718e3742002-12-13 20:15:29 +00001/*
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
51extern 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. */
56static void
57ospf_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. */
79struct external_info *
80ospf_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
paul4dadc292005-05-06 21:37:42 +0000113static void
paul68980082003-03-25 05:07:42 +0000114ospf_process_self_originated_lsa (struct ospf *ospf,
115 struct ospf_lsa *new, struct ospf_area *area)
paul718e3742002-12-13 20:15:29 +0000116{
117 struct ospf_interface *oi;
118 struct external_info *ei;
hasso52dc7ee2004-09-23 19:18:23 +0000119 struct listnode *node;
paul718e3742002-12-13 20:15:29 +0000120
121 if (IS_DEBUG_OSPF_EVENT)
ajs60925302004-12-08 17:45:02 +0000122 zlog_debug ("LSA[Type%d:%s]: Process self-originated LSA seq 0x%x",
paul7ddf1d62003-10-13 09:06:46 +0000123 new->data->type, inet_ntoa (new->data->id),
paul0c2be262004-05-31 14:16:54 +0000124 ntohl(new->data->ls_seqnum));
paul718e3742002-12-13 20:15:29 +0000125
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. */
paul1eb8ef22005-04-07 07:30:20 +0000153 for (ALL_LIST_ELEMENTS_RO (ospf->oiflist, node, oi))
paul718e3742002-12-13 20:15:29 +0000154 /* These are sanity check. */
paul1eb8ef22005-04-07 07:30:20 +0000155 if (IPV4_ADDR_SAME (&oi->address->u.prefix4, &new->data->id))
156 {
157 if (oi->area != area ||
158 oi->type != OSPF_IFTYPE_BROADCAST ||
159 !IPV4_ADDR_SAME (&oi->address->u.prefix4, &DR (oi)))
160 {
161 ospf_schedule_lsa_flush_area (area, new);
162 return;
163 }
164
paul718e3742002-12-13 20:15:29 +0000165#ifdef HAVE_OPAQUE_LSA
paul1eb8ef22005-04-07 07:30:20 +0000166 if (new->data->type == OSPF_OPAQUE_LINK_LSA)
167 {
168 ospf_opaque_lsa_refresh (new);
169 return;
170 }
paul718e3742002-12-13 20:15:29 +0000171#endif /* HAVE_OPAQUE_LSA */
172
paul1eb8ef22005-04-07 07:30:20 +0000173 ospf_lsa_unlock (oi->network_lsa_self);
174 oi->network_lsa_self = ospf_lsa_lock (new);
175
176 /* Schedule network-LSA origination. */
177 ospf_network_lsa_timer_add (oi);
178 return;
179 }
paul718e3742002-12-13 20:15:29 +0000180 break;
181 case OSPF_SUMMARY_LSA:
182 case OSPF_ASBR_SUMMARY_LSA:
paul68980082003-03-25 05:07:42 +0000183 ospf_schedule_abr_task (ospf);
paul718e3742002-12-13 20:15:29 +0000184 break;
185 case OSPF_AS_EXTERNAL_LSA :
paul718e3742002-12-13 20:15:29 +0000186 case OSPF_AS_NSSA_LSA:
pauld4a53d52003-07-12 21:30:57 +0000187 if ( (new->data->type == OSPF_AS_EXTERNAL_LSA)
188 && CHECK_FLAG (new->flags, OSPF_LSA_LOCAL_XLT))
189 {
190 ospf_translated_nssa_refresh (ospf, NULL, new);
191 return;
192 }
paul718e3742002-12-13 20:15:29 +0000193 ei = ospf_external_info_check (new);
194 if (ei)
pauld4a53d52003-07-12 21:30:57 +0000195 ospf_external_lsa_refresh (ospf, new, ei, LSA_REFRESH_FORCE);
paul718e3742002-12-13 20:15:29 +0000196 else
pauld4a53d52003-07-12 21:30:57 +0000197 ospf_lsa_flush_as (ospf, new);
paul718e3742002-12-13 20:15:29 +0000198 break;
199#ifdef HAVE_OPAQUE_LSA
200 case OSPF_OPAQUE_AREA_LSA:
201 ospf_opaque_lsa_refresh (new);
202 break;
203 case OSPF_OPAQUE_AS_LSA:
204 ospf_opaque_lsa_refresh (new); /* Reconsideration may needed. *//* XXX */
205 break;
206#endif /* HAVE_OPAQUE_LSA */
207 default:
208 break;
209 }
210}
211
212/* OSPF LSA flooding -- RFC2328 Section 13.(5). */
213
214/* Now Updated for NSSA operation, as follows:
215
216
217 Type-5's have no change. Blocked to STUB or NSSA.
218
219 Type-7's can be received, and if a DR
220 they will also flood the local NSSA Area as Type-7's
221
222 If a Self-Originated LSA (now an ASBR),
223 The LSDB will be updated as Type-5's, (for continual re-fresh)
224
225 If an NSSA-IR it is installed/flooded as Type-7, P-bit on.
226 if an NSSA-ABR it is installed/flooded as Type-7, P-bit off.
227
228 Later, during the ABR TASK, if the ABR is the Elected NSSA
229 translator, then All Type-7s (with P-bit ON) are Translated to
230 Type-5's and flooded to all non-NSSA/STUB areas.
231
232 During ASE Calculations,
233 non-ABRs calculate external routes from Type-7's
234 ABRs calculate external routes from Type-5's and non-self Type-7s
235*/
236int
paul68980082003-03-25 05:07:42 +0000237ospf_flood (struct ospf *ospf, struct ospf_neighbor *nbr,
238 struct ospf_lsa *current, struct ospf_lsa *new)
paul718e3742002-12-13 20:15:29 +0000239{
240 struct ospf_interface *oi;
241 struct timeval now;
242 int lsa_ack_flag;
243
244 /* Type-7 LSA's will be flooded throughout their native NSSA area,
245 but will also be flooded as Type-5's into ABR capable links. */
246
247 if (IS_DEBUG_OSPF_EVENT)
ajs60925302004-12-08 17:45:02 +0000248 zlog_debug ("LSA[Flooding]: start, NBR %s (%s), cur(%p), New-LSA[%s]",
paul718e3742002-12-13 20:15:29 +0000249 inet_ntoa (nbr->router_id),
250 LOOKUP (ospf_nsm_state_msg, nbr->state),
251 current,
252 dump_lsa_key (new));
253
254 lsa_ack_flag = 0;
255 oi = nbr->oi;
256
257 /* Get current time. */
258 gettimeofday (&now, NULL);
259
260 /* If there is already a database copy, and if the
261 database copy was received via flooding and installed less
262 than MinLSArrival seconds ago, discard the new LSA
263 (without acknowledging it). */
264 if (current != NULL) /* -- endo. */
265 {
266 if (IS_LSA_SELF (current)
267 && (ntohs (current->data->ls_age) == 0
268 && ntohl (current->data->ls_seqnum) == OSPF_INITIAL_SEQUENCE_NUMBER))
269 {
270 if (IS_DEBUG_OSPF_EVENT)
ajs60925302004-12-08 17:45:02 +0000271 zlog_debug ("LSA[Flooding]: Got a self-originated LSA, "
paul718e3742002-12-13 20:15:29 +0000272 "while local one is initial instance.");
273 ; /* Accept this LSA for quick LSDB resynchronization. */
274 }
275 else if (tv_cmp (tv_sub (now, current->tv_recv),
276 int2tv (OSPF_MIN_LS_ARRIVAL)) < 0)
277 {
278 if (IS_DEBUG_OSPF_EVENT)
ajs60925302004-12-08 17:45:02 +0000279 zlog_debug ("LSA[Flooding]: LSA is received recently.");
paul718e3742002-12-13 20:15:29 +0000280 return -1;
281 }
282 }
283
284 /* Flood the new LSA out some subset of the router's interfaces.
285 In some cases (e.g., the state of the receiving interface is
286 DR and the LSA was received from a router other than the
287 Backup DR) the LSA will be flooded back out the receiving
288 interface. */
paul68980082003-03-25 05:07:42 +0000289 lsa_ack_flag = ospf_flood_through (ospf, nbr, new);
paul718e3742002-12-13 20:15:29 +0000290
291#ifdef HAVE_OPAQUE_LSA
292 /* Remove the current database copy from all neighbors' Link state
293 retransmission lists. AS_EXTERNAL and AS_EXTERNAL_OPAQUE does
294 ^^^^^^^^^^^^^^^^^^^^^^^
295 not have area ID.
296 All other (even NSSA's) do have area ID. */
297#else /* HAVE_OPAQUE_LSA */
298 /* Remove the current database copy from all neighbors' Link state
299 retransmission lists. Only AS_EXTERNAL does not have area ID.
300 All other (even NSSA's) do have area ID. */
301#endif /* HAVE_OPAQUE_LSA */
302 if (current)
303 {
304 switch (current->data->type)
305 {
306 case OSPF_AS_EXTERNAL_LSA:
307#ifdef HAVE_OPAQUE_LSA
308 case OSPF_OPAQUE_AS_LSA:
309#endif /* HAVE_OPAQUE_LSA */
paul68980082003-03-25 05:07:42 +0000310 ospf_ls_retransmit_delete_nbr_as (ospf, current);
paul718e3742002-12-13 20:15:29 +0000311 break;
312 default:
paul68980082003-03-25 05:07:42 +0000313 ospf_ls_retransmit_delete_nbr_area (nbr->oi->area, current);
paul718e3742002-12-13 20:15:29 +0000314 break;
315 }
316 }
317
318 /* Do some internal house keeping that is needed here */
319 SET_FLAG (new->flags, OSPF_LSA_RECEIVED);
paul68980082003-03-25 05:07:42 +0000320 ospf_lsa_is_self_originated (ospf, new); /* Let it set the flag */
paul718e3742002-12-13 20:15:29 +0000321
322 /* Install the new LSA in the link state database
323 (replacing the current database copy). This may cause the
324 routing table calculation to be scheduled. In addition,
325 timestamp the new LSA with the current time. The flooding
326 procedure cannot overwrite the newly installed LSA until
327 MinLSArrival seconds have elapsed. */
328
paul68980082003-03-25 05:07:42 +0000329 new = ospf_lsa_install (ospf, nbr->oi, new);
paul718e3742002-12-13 20:15:29 +0000330
331 /* Acknowledge the receipt of the LSA by sending a Link State
332 Acknowledgment packet back out the receiving interface. */
333 if (lsa_ack_flag)
334 ospf_flood_delayed_lsa_ack (nbr, new);
335
336 /* If this new LSA indicates that it was originated by the
337 receiving router itself, the router must take special action,
338 either updating the LSA or in some cases flushing it from
339 the routing domain. */
paul68980082003-03-25 05:07:42 +0000340 if (ospf_lsa_is_self_originated (ospf, new))
341 ospf_process_self_originated_lsa (ospf, new, oi->area);
paul718e3742002-12-13 20:15:29 +0000342 else
343 /* Update statistics value for OSPF-MIB. */
paul68980082003-03-25 05:07:42 +0000344 ospf->rx_lsa_count++;
paul718e3742002-12-13 20:15:29 +0000345
346 return 0;
347}
348
349/* OSPF LSA flooding -- RFC2328 Section 13.3. */
paul4dadc292005-05-06 21:37:42 +0000350static int
paul718e3742002-12-13 20:15:29 +0000351ospf_flood_through_interface (struct ospf_interface *oi,
352 struct ospf_neighbor *inbr,
353 struct ospf_lsa *lsa)
354{
355 struct ospf_neighbor *onbr;
356 struct route_node *rn;
357 int retx_flag;
358
359 if (IS_DEBUG_OSPF_EVENT)
ajs60925302004-12-08 17:45:02 +0000360 zlog_debug ("ospf_flood_through_interface(): "
paul718e3742002-12-13 20:15:29 +0000361 "considering int %s, INBR(%s), LSA[%s]",
362 IF_NAME (oi), inbr ? inet_ntoa (inbr->router_id) : "NULL",
363 dump_lsa_key (lsa));
364
365 if (!ospf_if_is_enable (oi))
366 return 0;
367
368 /* Remember if new LSA is aded to a retransmit list. */
369 retx_flag = 0;
370
371 /* Each of the neighbors attached to this interface are examined,
372 to determine whether they must receive the new LSA. The following
373 steps are executed for each neighbor: */
374 for (rn = route_top (oi->nbrs); rn; rn = route_next (rn))
375 {
376 struct ospf_lsa *ls_req;
377
378 if (rn->info == NULL)
379 continue;
380
381 onbr = rn->info;
382 if (IS_DEBUG_OSPF_EVENT)
ajs60925302004-12-08 17:45:02 +0000383 zlog_debug ("ospf_flood_through_interface(): considering nbr %s (%s)",
paul718e3742002-12-13 20:15:29 +0000384 inet_ntoa (onbr->router_id),
385 LOOKUP (ospf_nsm_state_msg, onbr->state));
386
387 /* If the neighbor is in a lesser state than Exchange, it
388 does not participate in flooding, and the next neighbor
389 should be examined. */
390 if (onbr->state < NSM_Exchange)
391 continue;
392
393 /* If the adjacency is not yet full (neighbor state is
394 Exchange or Loading), examine the Link state request
395 list associated with this adjacency. If there is an
396 instance of the new LSA on the list, it indicates that
397 the neighboring router has an instance of the LSA
398 already. Compare the new LSA to the neighbor's copy: */
399 if (onbr->state < NSM_Full)
400 {
401 if (IS_DEBUG_OSPF_EVENT)
ajs60925302004-12-08 17:45:02 +0000402 zlog_debug ("ospf_flood_through_interface(): nbr adj is not Full");
paul718e3742002-12-13 20:15:29 +0000403 ls_req = ospf_ls_request_lookup (onbr, lsa);
404 if (ls_req != NULL)
405 {
406 int ret;
407
408 ret = ospf_lsa_more_recent (ls_req, lsa);
409 /* The new LSA is less recent. */
410 if (ret > 0)
411 continue;
412 /* The two copies are the same instance, then delete
413 the LSA from the Link state request list. */
414 else if (ret == 0)
415 {
416 ospf_ls_request_delete (onbr, ls_req);
417 ospf_check_nbr_loading (onbr);
418 continue;
419 }
420 /* The new LSA is more recent. Delete the LSA
421 from the Link state request list. */
422 else
423 {
424 ospf_ls_request_delete (onbr, ls_req);
425 ospf_check_nbr_loading (onbr);
426 }
427 }
428 }
429
430#ifdef HAVE_OPAQUE_LSA
431 if (IS_OPAQUE_LSA (lsa->data->type))
432 {
433 if (! CHECK_FLAG (onbr->options, OSPF_OPTION_O))
434 {
435 if (IS_DEBUG_OSPF (lsa, LSA_FLOODING))
ajs60925302004-12-08 17:45:02 +0000436 zlog_debug ("Skip this neighbor: Not Opaque-capable.");
paul718e3742002-12-13 20:15:29 +0000437 continue;
438 }
439
paul29226d42003-12-06 17:10:11 +0000440 if (IS_OPAQUE_LSA_ORIGINATION_BLOCKED (oi->ospf->opaque)
paul718e3742002-12-13 20:15:29 +0000441 && IS_LSA_SELF (lsa)
442 && onbr->state == NSM_Full)
443 {
444 /* Small attempt to reduce unnecessary retransmission. */
445 if (IS_DEBUG_OSPF (lsa, LSA_FLOODING))
ajs60925302004-12-08 17:45:02 +0000446 zlog_debug ("Skip this neighbor: Initial flushing done.");
paul718e3742002-12-13 20:15:29 +0000447 continue;
448 }
449 }
450#endif /* HAVE_OPAQUE_LSA */
451
452 /* If the new LSA was received from this neighbor,
453 examine the next neighbor. */
454#ifdef ORIGINAL_CODING
455 if (inbr)
456 if (IPV4_ADDR_SAME (&inbr->router_id, &onbr->router_id))
457 continue;
458#else /* ORIGINAL_CODING */
459 if (inbr)
460 {
461 /*
462 * Triggered by LSUpd message parser "ospf_ls_upd ()".
463 * E.g., all LSAs handling here is received via network.
464 */
465 if (IPV4_ADDR_SAME (&inbr->router_id, &onbr->router_id))
466 {
467 if (IS_DEBUG_OSPF (lsa, LSA_FLOODING))
ajs60925302004-12-08 17:45:02 +0000468 zlog_debug ("Skip this neighbor: inbr == onbr");
paul718e3742002-12-13 20:15:29 +0000469 continue;
470 }
471 }
472 else
473 {
474 /*
475 * Triggered by MaxAge remover, so far.
476 * NULL "inbr" means flooding starts from this node.
477 */
478 if (IPV4_ADDR_SAME (&lsa->data->adv_router, &onbr->router_id))
479 {
480 if (IS_DEBUG_OSPF (lsa, LSA_FLOODING))
ajs60925302004-12-08 17:45:02 +0000481 zlog_debug ("Skip this neighbor: lsah->adv_router == onbr");
paul718e3742002-12-13 20:15:29 +0000482 continue;
483 }
484 }
485#endif /* ORIGINAL_CODING */
486
487 /* Add the new LSA to the Link state retransmission list
488 for the adjacency. The LSA will be retransmitted
489 at intervals until an acknowledgment is seen from
490 the neighbor. */
491 ospf_ls_retransmit_add (onbr, lsa);
492 retx_flag = 1;
493 }
494
495 /* If in the previous step, the LSA was NOT added to any of
496 the Link state retransmission lists, there is no need to
497 flood the LSA out the interface. */
498 if (retx_flag == 0)
499 {
500 return (inbr && inbr->oi == oi);
501 }
502
503 /* if we've received the lsa on this interface we need to perform
504 additional checking */
505 if (inbr && (inbr->oi == oi))
506 {
507 /* If the new LSA was received on this interface, and it was
508 received from either the Designated Router or the Backup
509 Designated Router, chances are that all the neighbors have
510 received the LSA already. */
511 if (NBR_IS_DR (inbr) || NBR_IS_BDR (inbr))
512 {
paul718e3742002-12-13 20:15:29 +0000513 if (IS_DEBUG_OSPF_NSSA)
ajs60925302004-12-08 17:45:02 +0000514 zlog_debug ("ospf_flood_through_interface(): "
paul718e3742002-12-13 20:15:29 +0000515 "DR/BDR NOT SEND to int %s", IF_NAME (oi));
paul718e3742002-12-13 20:15:29 +0000516 return 1;
517 }
518
519 /* If the new LSA was received on this interface, and the
520 interface state is Backup, examine the next interface. The
521 Designated Router will do the flooding on this interface.
522 However, if the Designated Router fails the router will
523 end up retransmitting the updates. */
524
525 if (oi->state == ISM_Backup)
526 {
paul718e3742002-12-13 20:15:29 +0000527 if (IS_DEBUG_OSPF_NSSA)
ajs60925302004-12-08 17:45:02 +0000528 zlog_debug ("ospf_flood_through_interface(): "
paul718e3742002-12-13 20:15:29 +0000529 "ISM_Backup NOT SEND to int %s", IF_NAME (oi));
paul718e3742002-12-13 20:15:29 +0000530 return 1;
531 }
532 }
533
534 /* The LSA must be flooded out the interface. Send a Link State
535 Update packet (including the new LSA as contents) out the
536 interface. The LSA's LS age must be incremented by InfTransDelay
537 (which must be > 0) when it is copied into the outgoing Link
538 State Update packet (until the LS age field reaches the maximum
539 value of MaxAge). */
hassobeebba72004-06-20 21:00:27 +0000540 /* XXX HASSO: Is this IS_DEBUG_OSPF_NSSA really correct? */
paul718e3742002-12-13 20:15:29 +0000541 if (IS_DEBUG_OSPF_NSSA)
ajs60925302004-12-08 17:45:02 +0000542 zlog_debug ("ospf_flood_through_interface(): "
paul718e3742002-12-13 20:15:29 +0000543 "DR/BDR sending upd to int %s", IF_NAME (oi));
paul718e3742002-12-13 20:15:29 +0000544
545 /* RFC2328 Section 13.3
546 On non-broadcast networks, separate Link State Update
547 packets must be sent, as unicasts, to each adjacent neighbor
548 (i.e., those in state Exchange or greater). The destination
549 IP addresses for these packets are the neighbors' IP
550 addresses. */
551 if (oi->type == OSPF_IFTYPE_NBMA)
552 {
553 struct route_node *rn;
554 struct ospf_neighbor *nbr;
555
556 for (rn = route_top (oi->nbrs); rn; rn = route_next (rn))
557 if ((nbr = rn->info) != NULL)
558 if (nbr != oi->nbr_self && nbr->state >= NSM_Exchange)
559 ospf_ls_upd_send_lsa (nbr, lsa, OSPF_SEND_PACKET_DIRECT);
560 }
561 else
562 ospf_ls_upd_send_lsa (oi->nbr_self, lsa, OSPF_SEND_PACKET_INDIRECT);
563
564 return 0;
565}
566
567int
paul68980082003-03-25 05:07:42 +0000568ospf_flood_through_area (struct ospf_area *area,
569 struct ospf_neighbor *inbr, struct ospf_lsa *lsa)
paul718e3742002-12-13 20:15:29 +0000570{
paul1eb8ef22005-04-07 07:30:20 +0000571 struct listnode *node, *nnode;
572 struct ospf_interface *oi;
paul718e3742002-12-13 20:15:29 +0000573 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. */
paul1eb8ef22005-04-07 07:30:20 +0000579 for (ALL_LIST_ELEMENTS (area->oiflist, node, nnode, oi))
paul718e3742002-12-13 20:15:29 +0000580 {
paul718e3742002-12-13 20:15:29 +0000581 if (area->area_id.s_addr != OSPF_AREA_BACKBONE &&
582 oi->type == OSPF_IFTYPE_VIRTUALLINK)
583 continue;
584
585#ifdef HAVE_OPAQUE_LSA
586 if ((lsa->data->type == OSPF_OPAQUE_LINK_LSA) && (lsa->oi != oi))
587 {
588 /*
589 * Link local scoped Opaque-LSA should only be flooded
590 * for the link on which the LSA has received.
591 */
592 if (IS_DEBUG_OSPF (lsa, LSA_FLOODING))
ajs60925302004-12-08 17:45:02 +0000593 zlog_debug ("Type-9 Opaque-LSA: lsa->oi(%p) != oi(%p)", lsa->oi, oi);
paul718e3742002-12-13 20:15:29 +0000594 continue;
595 }
596#endif /* HAVE_OPAQUE_LSA */
597
598 if (ospf_flood_through_interface (oi, inbr, lsa))
599 lsa_ack_flag = 1;
600 }
601
602 return (lsa_ack_flag);
603}
604
605int
paul68980082003-03-25 05:07:42 +0000606ospf_flood_through_as (struct ospf *ospf, struct ospf_neighbor *inbr,
607 struct ospf_lsa *lsa)
paul718e3742002-12-13 20:15:29 +0000608{
hasso52dc7ee2004-09-23 19:18:23 +0000609 struct listnode *node;
paul1eb8ef22005-04-07 07:30:20 +0000610 struct ospf_area *area;
paul718e3742002-12-13 20:15:29 +0000611 int lsa_ack_flag;
612
613 lsa_ack_flag = 0;
614
615 /* The incoming LSA is type 5 or type 7 (AS-EXTERNAL or AS-NSSA )
616
617 Divert the Type-5 LSA's to all non-NSSA/STUB areas
618
619 Divert the Type-7 LSA's to all NSSA areas
620
621 AS-external-LSAs are flooded throughout the entire AS, with the
622 exception of stub areas (see Section 3.6). The eligible
623 interfaces are all the router's interfaces, excluding virtual
624 links and those interfaces attaching to stub areas. */
625
paul718e3742002-12-13 20:15:29 +0000626 if (CHECK_FLAG (lsa->flags, OSPF_LSA_LOCAL_XLT)) /* Translated from 7 */
627 if (IS_DEBUG_OSPF_NSSA)
ajs60925302004-12-08 17:45:02 +0000628 zlog_debug ("Flood/AS: NSSA TRANSLATED LSA");
paul718e3742002-12-13 20:15:29 +0000629
paul1eb8ef22005-04-07 07:30:20 +0000630 for (ALL_LIST_ELEMENTS_RO (ospf->areas, node, area))
paul718e3742002-12-13 20:15:29 +0000631 {
632 int continue_flag = 0;
hasso52dc7ee2004-09-23 19:18:23 +0000633 struct listnode *if_node;
paul1eb8ef22005-04-07 07:30:20 +0000634 struct ospf_interface *oi;
paul718e3742002-12-13 20:15:29 +0000635
636 switch (area->external_routing)
637 {
638 /* Don't send AS externals into stub areas. Various types
639 of support for partial stub areas can be implemented
640 here. NSSA's will receive Type-7's that have areas
641 matching the originl LSA. */
642 case OSPF_AREA_NSSA: /* Sending Type 5 or 7 into NSSA area */
paul718e3742002-12-13 20:15:29 +0000643 /* Type-7, flood NSSA area */
paul68980082003-03-25 05:07:42 +0000644 if (lsa->data->type == OSPF_AS_NSSA_LSA
645 && area == lsa->area)
paul718e3742002-12-13 20:15:29 +0000646 /* We will send it. */
647 continue_flag = 0;
paul68980082003-03-25 05:07:42 +0000648 else
paul718e3742002-12-13 20:15:29 +0000649 continue_flag = 1; /* Skip this NSSA area for Type-5's et al */
paul718e3742002-12-13 20:15:29 +0000650 break;
paul718e3742002-12-13 20:15:29 +0000651
652 case OSPF_AREA_TYPE_MAX:
653 case OSPF_AREA_STUB:
654 continue_flag = 1; /* Skip this area. */
655 break;
656
657 case OSPF_AREA_DEFAULT:
658 default:
paul718e3742002-12-13 20:15:29 +0000659 /* No Type-7 into normal area */
660 if (lsa->data->type == OSPF_AS_NSSA_LSA)
661 continue_flag = 1; /* skip Type-7 */
662 else
paul718e3742002-12-13 20:15:29 +0000663 continue_flag = 0; /* Do this area. */
664 break;
665 }
666
667 /* Do continue for above switch. Saves a big if then mess */
668 if (continue_flag)
669 continue; /* main for-loop */
670
671 /* send to every interface in this area */
672
paul1eb8ef22005-04-07 07:30:20 +0000673 for (ALL_LIST_ELEMENTS_RO (area->oiflist, if_node, oi))
paul718e3742002-12-13 20:15:29 +0000674 {
paul718e3742002-12-13 20:15:29 +0000675 /* Skip virtual links */
676 if (oi->type != OSPF_IFTYPE_VIRTUALLINK)
677 if (ospf_flood_through_interface (oi, inbr, lsa)) /* lsa */
678 lsa_ack_flag = 1;
679 }
680 } /* main area for-loop */
681
682 return (lsa_ack_flag);
683}
684
685int
paul68980082003-03-25 05:07:42 +0000686ospf_flood_through (struct ospf *ospf,
687 struct ospf_neighbor *inbr, struct ospf_lsa *lsa)
paul718e3742002-12-13 20:15:29 +0000688{
689 int lsa_ack_flag = 0;
690
691 /* Type-7 LSA's for NSSA are flooded throughout the AS here, and
692 upon return are updated in the LSDB for Type-7's. Later,
693 re-fresh will re-send them (and also, if ABR, packet code will
694 translate to Type-5's)
695
696 As usual, Type-5 LSA's (if not DISCARDED because we are STUB or
697 NSSA) are flooded throughout the AS, and are updated in the
698 global table. */
699#ifdef ORIGINAL_CODING
700 switch (lsa->data->type)
701 {
702 case OSPF_ROUTER_LSA:
703 case OSPF_NETWORK_LSA:
704 case OSPF_SUMMARY_LSA:
705 case OSPF_ASBR_SUMMARY_LSA:
706#ifdef HAVE_OPAQUE_LSA
707 case OSPF_OPAQUE_LINK_LSA: /* ospf_flood_through_interface ? */
708 case OSPF_OPAQUE_AREA_LSA:
709#endif /* HAVE_OPAQUE_LSA */
710 lsa_ack_flag = ospf_flood_through_area (inbr->oi->area, inbr, lsa);
711 break;
712 case OSPF_AS_EXTERNAL_LSA: /* Type-5 */
713#ifdef HAVE_OPAQUE_LSA
714 case OSPF_OPAQUE_AS_LSA:
715#endif /* HAVE_OPAQUE_LSA */
paul68980082003-03-25 05:07:42 +0000716 lsa_ack_flag = ospf_flood_through_as (ospf, inbr, lsa);
paul718e3742002-12-13 20:15:29 +0000717 break;
paul718e3742002-12-13 20:15:29 +0000718 /* Type-7 Only received within NSSA, then flooded */
719 case OSPF_AS_NSSA_LSA:
720 /* Any P-bit was installed with the Type-7. */
721 lsa_ack_flag = ospf_flood_through_area (inbr->oi->area, inbr, lsa);
722
723 if (IS_DEBUG_OSPF_NSSA)
ajs60925302004-12-08 17:45:02 +0000724 zlog_debug ("ospf_flood_through: LOCAL NSSA FLOOD of Type-7.");
paul718e3742002-12-13 20:15:29 +0000725 break;
paul718e3742002-12-13 20:15:29 +0000726 default:
727 break;
728 }
729#else /* ORIGINAL_CODING */
730 /*
731 * At the common sub-sub-function "ospf_flood_through_interface()",
732 * a parameter "inbr" will be used to distinguish the called context
733 * whether the given LSA was received from the neighbor, or the
734 * flooding for the LSA starts from this node (e.g. the LSA was self-
735 * originated, or the LSA is going to be flushed from routing domain).
736 *
737 * So, for consistency reasons, this function "ospf_flood_through()"
738 * should also allow the usage that the given "inbr" parameter to be
739 * NULL. If we do so, corresponding AREA parameter should be referred
740 * by "lsa->area", instead of "inbr->oi->area".
741 */
742 switch (lsa->data->type)
743 {
744 case OSPF_AS_EXTERNAL_LSA: /* Type-5 */
745#ifdef HAVE_OPAQUE_LSA
746 case OSPF_OPAQUE_AS_LSA:
747#endif /* HAVE_OPAQUE_LSA */
paul68980082003-03-25 05:07:42 +0000748 lsa_ack_flag = ospf_flood_through_as (ospf, inbr, lsa);
paul718e3742002-12-13 20:15:29 +0000749 break;
paul718e3742002-12-13 20:15:29 +0000750 /* Type-7 Only received within NSSA, then flooded */
751 case OSPF_AS_NSSA_LSA:
752 /* Any P-bit was installed with the Type-7. */
753
754 if (IS_DEBUG_OSPF_NSSA)
ajs60925302004-12-08 17:45:02 +0000755 zlog_debug ("ospf_flood_through: LOCAL NSSA FLOOD of Type-7.");
paul718e3742002-12-13 20:15:29 +0000756 /* Fallthrough */
paul718e3742002-12-13 20:15:29 +0000757 default:
758 lsa_ack_flag = ospf_flood_through_area (lsa->area, inbr, lsa);
759 break;
760 }
761#endif /* ORIGINAL_CODING */
762
763 return (lsa_ack_flag);
764}
765
766
767
768/* Management functions for neighbor's Link State Request list. */
769void
770ospf_ls_request_add (struct ospf_neighbor *nbr, struct ospf_lsa *lsa)
771{
772 /*
773 * We cannot make use of the newly introduced callback function
774 * "lsdb->new_lsa_hook" to replace debug output below, just because
775 * it seems no simple and smart way to pass neighbor information to
776 * the common function "ospf_lsdb_add()" -- endo.
777 */
778 if (IS_DEBUG_OSPF (lsa, LSA_FLOODING))
ajs60925302004-12-08 17:45:02 +0000779 zlog_debug ("RqstL(%lu)++, NBR(%s), LSA[%s]",
paul718e3742002-12-13 20:15:29 +0000780 ospf_ls_request_count (nbr),
781 inet_ntoa (nbr->router_id), dump_lsa_key (lsa));
782
783 ospf_lsdb_add (&nbr->ls_req, lsa);
784}
785
786unsigned long
787ospf_ls_request_count (struct ospf_neighbor *nbr)
788{
789 return ospf_lsdb_count_all (&nbr->ls_req);
790}
791
792int
793ospf_ls_request_isempty (struct ospf_neighbor *nbr)
794{
795 return ospf_lsdb_isempty (&nbr->ls_req);
796}
797
798/* Remove LSA from neighbor's ls-request list. */
799void
800ospf_ls_request_delete (struct ospf_neighbor *nbr, struct ospf_lsa *lsa)
801{
802 if (nbr->ls_req_last == lsa)
803 {
804 ospf_lsa_unlock (nbr->ls_req_last);
805 nbr->ls_req_last = NULL;
806 }
807
808 if (IS_DEBUG_OSPF (lsa, LSA_FLOODING)) /* -- endo. */
ajs60925302004-12-08 17:45:02 +0000809 zlog_debug ("RqstL(%lu)--, NBR(%s), LSA[%s]",
paul718e3742002-12-13 20:15:29 +0000810 ospf_ls_request_count (nbr),
811 inet_ntoa (nbr->router_id), dump_lsa_key (lsa));
812
813 ospf_lsdb_delete (&nbr->ls_req, lsa);
814}
815
816/* Remove all LSA from neighbor's ls-requenst list. */
817void
818ospf_ls_request_delete_all (struct ospf_neighbor *nbr)
819{
820 ospf_lsa_unlock (nbr->ls_req_last);
821 nbr->ls_req_last = NULL;
822 ospf_lsdb_delete_all (&nbr->ls_req);
823}
824
825/* Lookup LSA from neighbor's ls-request list. */
826struct ospf_lsa *
827ospf_ls_request_lookup (struct ospf_neighbor *nbr, struct ospf_lsa *lsa)
828{
829 return ospf_lsdb_lookup (&nbr->ls_req, lsa);
830}
831
832struct ospf_lsa *
833ospf_ls_request_new (struct lsa_header *lsah)
834{
835 struct ospf_lsa *new;
836
837 new = ospf_lsa_new ();
838 new->data = ospf_lsa_data_new (OSPF_LSA_HEADER_SIZE);
839 memcpy (new->data, lsah, OSPF_LSA_HEADER_SIZE);
840
841 return new;
842}
843
844
845/* Management functions for neighbor's ls-retransmit list. */
846unsigned long
847ospf_ls_retransmit_count (struct ospf_neighbor *nbr)
848{
849 return ospf_lsdb_count_all (&nbr->ls_rxmt);
850}
851
852unsigned long
853ospf_ls_retransmit_count_self (struct ospf_neighbor *nbr, int lsa_type)
854{
855 return ospf_lsdb_count_self (&nbr->ls_rxmt, lsa_type);
856}
857
858int
859ospf_ls_retransmit_isempty (struct ospf_neighbor *nbr)
860{
861 return ospf_lsdb_isempty (&nbr->ls_rxmt);
862}
863
864/* Add LSA to be retransmitted to neighbor's ls-retransmit list. */
865void
866ospf_ls_retransmit_add (struct ospf_neighbor *nbr, struct ospf_lsa *lsa)
867{
868 struct ospf_lsa *old;
869
870 old = ospf_ls_retransmit_lookup (nbr, lsa);
871
872 if (ospf_lsa_more_recent (old, lsa) < 0)
873 {
874 if (old)
875 {
876 old->retransmit_counter--;
877 ospf_lsdb_delete (&nbr->ls_rxmt, old);
878 }
879 lsa->retransmit_counter++;
880 /*
881 * We cannot make use of the newly introduced callback function
882 * "lsdb->new_lsa_hook" to replace debug output below, just because
883 * it seems no simple and smart way to pass neighbor information to
884 * the common function "ospf_lsdb_add()" -- endo.
885 */
886 if (IS_DEBUG_OSPF (lsa, LSA_FLOODING))
ajs60925302004-12-08 17:45:02 +0000887 zlog_debug ("RXmtL(%lu)++, NBR(%s), LSA[%s]",
paul718e3742002-12-13 20:15:29 +0000888 ospf_ls_retransmit_count (nbr),
889 inet_ntoa (nbr->router_id), dump_lsa_key (lsa));
890 ospf_lsdb_add (&nbr->ls_rxmt, lsa);
891 }
892}
893
894/* Remove LSA from neibghbor's ls-retransmit list. */
895void
896ospf_ls_retransmit_delete (struct ospf_neighbor *nbr, struct ospf_lsa *lsa)
897{
898 if (ospf_ls_retransmit_lookup (nbr, lsa))
899 {
900 lsa->retransmit_counter--;
901 if (IS_DEBUG_OSPF (lsa, LSA_FLOODING)) /* -- endo. */
ajs60925302004-12-08 17:45:02 +0000902 zlog_debug ("RXmtL(%lu)--, NBR(%s), LSA[%s]",
paul718e3742002-12-13 20:15:29 +0000903 ospf_ls_retransmit_count (nbr),
904 inet_ntoa (nbr->router_id), dump_lsa_key (lsa));
905 ospf_lsdb_delete (&nbr->ls_rxmt, lsa);
906 }
907}
908
909/* Clear neighbor's ls-retransmit list. */
910void
911ospf_ls_retransmit_clear (struct ospf_neighbor *nbr)
912{
913 struct ospf_lsdb *lsdb;
914 int i;
915
916 lsdb = &nbr->ls_rxmt;
917
918 for (i = OSPF_MIN_LSA; i < OSPF_MAX_LSA; i++)
919 {
920 struct route_table *table = lsdb->type[i].db;
921 struct route_node *rn;
922 struct ospf_lsa *lsa;
923
924 for (rn = route_top (table); rn; rn = route_next (rn))
925 if ((lsa = rn->info) != NULL)
926 ospf_ls_retransmit_delete (nbr, lsa);
927 }
928
929 ospf_lsa_unlock (nbr->ls_req_last);
930 nbr->ls_req_last = NULL;
931}
932
933/* Lookup LSA from neighbor's ls-retransmit list. */
934struct ospf_lsa *
935ospf_ls_retransmit_lookup (struct ospf_neighbor *nbr, struct ospf_lsa *lsa)
936{
937 return ospf_lsdb_lookup (&nbr->ls_rxmt, lsa);
938}
939
paul4dadc292005-05-06 21:37:42 +0000940static void
paul68980082003-03-25 05:07:42 +0000941ospf_ls_retransmit_delete_nbr_if (struct ospf_interface *oi,
942 struct ospf_lsa *lsa)
paul718e3742002-12-13 20:15:29 +0000943{
paul68980082003-03-25 05:07:42 +0000944 struct route_node *rn;
945 struct ospf_neighbor *nbr;
946 struct ospf_lsa *lsr;
947
948 if (ospf_if_is_enable (oi))
949 for (rn = route_top (oi->nbrs); rn; rn = route_next (rn))
950 /* If LSA find in LS-retransmit list, then remove it. */
951 if ((nbr = rn->info) != NULL)
952 {
953 lsr = ospf_ls_retransmit_lookup (nbr, lsa);
paul718e3742002-12-13 20:15:29 +0000954
paul68980082003-03-25 05:07:42 +0000955 /* If LSA find in ls-retransmit list, remove it. */
956 if (lsr != NULL && lsr->data->ls_seqnum == lsa->data->ls_seqnum)
957 ospf_ls_retransmit_delete (nbr, lsr);
958 }
paul718e3742002-12-13 20:15:29 +0000959}
960
paul718e3742002-12-13 20:15:29 +0000961void
paul68980082003-03-25 05:07:42 +0000962ospf_ls_retransmit_delete_nbr_area (struct ospf_area *area,
963 struct ospf_lsa *lsa)
paul718e3742002-12-13 20:15:29 +0000964{
paul1eb8ef22005-04-07 07:30:20 +0000965 struct listnode *node, *nnode;
966 struct ospf_interface *oi;
paul718e3742002-12-13 20:15:29 +0000967
paul1eb8ef22005-04-07 07:30:20 +0000968 for (ALL_LIST_ELEMENTS (area->oiflist, node, nnode, oi))
969 ospf_ls_retransmit_delete_nbr_if (oi, lsa);
paul68980082003-03-25 05:07:42 +0000970}
paul718e3742002-12-13 20:15:29 +0000971
paul68980082003-03-25 05:07:42 +0000972void
973ospf_ls_retransmit_delete_nbr_as (struct ospf *ospf, struct ospf_lsa *lsa)
974{
paul1eb8ef22005-04-07 07:30:20 +0000975 struct listnode *node, *nnode;
976 struct ospf_interface *oi;
paul718e3742002-12-13 20:15:29 +0000977
paul1eb8ef22005-04-07 07:30:20 +0000978 for (ALL_LIST_ELEMENTS (ospf->oiflist, node, nnode, oi))
979 ospf_ls_retransmit_delete_nbr_if (oi, lsa);
paul718e3742002-12-13 20:15:29 +0000980}
981
982
983/* Sets ls_age to MaxAge and floods throu the area.
984 When we implement ASE routing, there will be anothe function
985 flushing an LSA from the whole domain. */
986void
987ospf_lsa_flush_area (struct ospf_lsa *lsa, struct ospf_area *area)
988{
989 lsa->data->ls_age = htons (OSPF_LSA_MAXAGE);
990 ospf_flood_through_area (area, NULL, lsa);
paul68980082003-03-25 05:07:42 +0000991 ospf_lsa_maxage (area->ospf, lsa);
paul718e3742002-12-13 20:15:29 +0000992}
993
994void
paul68980082003-03-25 05:07:42 +0000995ospf_lsa_flush_as (struct ospf *ospf, struct ospf_lsa *lsa)
paul718e3742002-12-13 20:15:29 +0000996{
997 lsa->data->ls_age = htons (OSPF_LSA_MAXAGE);
paul68980082003-03-25 05:07:42 +0000998 ospf_flood_through_as (ospf, NULL, lsa);
999 ospf_lsa_maxage (ospf, lsa);
paul718e3742002-12-13 20:15:29 +00001000}