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