2 * OSPF Flooding -- RFC2328 Section 13.
3 * Copyright (C) 1999, 2000 Toshiaki Takada
5 * This file is part of GNU Zebra.
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.
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.
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.
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"
51 extern struct zclient
*zclient
;
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
57 ospf_flood_delayed_lsa_ack (struct ospf_neighbor
*inbr
, struct ospf_lsa
*lsa
)
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 */
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 */
70 /* Deal with router as BDR */
71 if (inbr
->oi
->state
== ISM_Backup
&& ! NBR_IS_DR (inbr
))
74 /* Schedule a delayed LSA Ack to be sent */
75 listnode_add (inbr
->oi
->ls_ack
, ospf_lsa_lock (lsa
));
78 /* Check LSA is related to external info. */
79 struct external_info
*
80 ospf_external_info_check (struct ospf_lsa
*lsa
)
82 struct as_external_lsa
*al
;
84 struct route_node
*rn
;
87 al
= (struct as_external_lsa
*) lsa
->data
;
90 p
.prefix
= lsa
->data
->id
;
91 p
.prefixlen
= ip_masklen (al
->mask
);
93 for (type
= 0; type
<= ZEBRA_ROUTE_MAX
; type
++)
95 int redist_type
= is_prefix_default (&p
) ? DEFAULT_ROUTE
: type
;
96 if (ospf_is_type_redistributed (redist_type
))
97 if (EXTERNAL_INFO (type
))
99 rn
= route_node_lookup (EXTERNAL_INFO (type
),
100 (struct prefix
*) &p
);
103 route_unlock_node (rn
);
104 if (rn
->info
!= NULL
)
105 return (struct external_info
*) rn
->info
;
114 ospf_process_self_originated_lsa (struct ospf_lsa
*new, struct ospf_area
*area
)
116 struct ospf_interface
*oi
;
117 struct external_info
*ei
;
120 if (IS_DEBUG_OSPF_EVENT
)
121 zlog_info ("LSA[Type%d:%s]: Process self-originated LSA",
122 new->data
->type
, inet_ntoa (new->data
->id
));
124 /* If we're here, we installed a self-originated LSA that we received
125 from a neighbor, i.e. it's more recent. We must see whether we want
127 If yes, we should use this LSA's sequence number and reoriginate
129 if not --- we must flush this LSA from the domain. */
130 switch (new->data
->type
)
132 case OSPF_ROUTER_LSA
:
133 /* Originate a new instance and schedule flooding */
134 /* It shouldn't be necessary, but anyway */
135 ospf_lsa_unlock (area
->router_lsa_self
);
136 area
->router_lsa_self
= ospf_lsa_lock (new);
138 ospf_router_lsa_timer_add (area
);
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. */
149 /* Look through all interfaces, not just area, since interface
150 could be moved from one area to another. */
151 for (node
= listhead (ospf_top
->oiflist
); node
; nextnode (node
))
152 /* These are sanity check. */
153 if ((oi
= getdata (node
)) != NULL
)
154 if (IPV4_ADDR_SAME (&oi
->address
->u
.prefix4
, &new->data
->id
))
156 if (oi
->area
!= area
||
157 oi
->type
!= OSPF_IFTYPE_BROADCAST
||
158 !IPV4_ADDR_SAME (&oi
->address
->u
.prefix4
, &DR (oi
)))
160 ospf_schedule_lsa_flush_area (area
, new);
164 #ifdef HAVE_OPAQUE_LSA
165 if (new->data
->type
== OSPF_OPAQUE_LINK_LSA
)
167 ospf_opaque_lsa_refresh (new);
170 #endif /* HAVE_OPAQUE_LSA */
172 ospf_lsa_unlock (oi
->network_lsa_self
);
173 oi
->network_lsa_self
= ospf_lsa_lock (new);
175 /* Schedule network-LSA origination. */
176 ospf_network_lsa_timer_add (oi
);
180 case OSPF_SUMMARY_LSA
:
181 case OSPF_ASBR_SUMMARY_LSA
:
182 ospf_schedule_abr_task ();
184 case OSPF_AS_EXTERNAL_LSA
:
186 case OSPF_AS_NSSA_LSA
:
187 #endif /* HAVE_NSSA */
188 ei
= ospf_external_info_check (new);
190 ospf_external_lsa_refresh (new, ei
, LSA_REFRESH_FORCE
);
192 ospf_lsa_flush_as (new);
194 #ifdef HAVE_OPAQUE_LSA
195 case OSPF_OPAQUE_AREA_LSA
:
196 ospf_opaque_lsa_refresh (new);
198 case OSPF_OPAQUE_AS_LSA
:
199 ospf_opaque_lsa_refresh (new); /* Reconsideration may needed. *//* XXX */
201 #endif /* HAVE_OPAQUE_LSA */
207 /* OSPF LSA flooding -- RFC2328 Section 13.(5). */
209 /* Now Updated for NSSA operation, as follows:
212 Type-5's have no change. Blocked to STUB or NSSA.
214 Type-7's can be received, and if a DR
215 they will also flood the local NSSA Area as Type-7's
217 If a Self-Originated LSA (now an ASBR),
218 The LSDB will be updated as Type-5's, (for continual re-fresh)
220 If an NSSA-IR it is installed/flooded as Type-7, P-bit on.
221 if an NSSA-ABR it is installed/flooded as Type-7, P-bit off.
223 Later, during the ABR TASK, if the ABR is the Elected NSSA
224 translator, then All Type-7s (with P-bit ON) are Translated to
225 Type-5's and flooded to all non-NSSA/STUB areas.
227 During ASE Calculations,
228 non-ABRs calculate external routes from Type-7's
229 ABRs calculate external routes from Type-5's and non-self Type-7s
232 ospf_flood (struct ospf_neighbor
*nbr
, struct ospf_lsa
*current
,
233 struct ospf_lsa
*new)
235 struct ospf_interface
*oi
;
239 /* Type-7 LSA's will be flooded throughout their native NSSA area,
240 but will also be flooded as Type-5's into ABR capable links. */
242 if (IS_DEBUG_OSPF_EVENT
)
243 zlog_info ("LSA[Flooding]: start, NBR %s (%s), cur(%p), New-LSA[%s]",
244 inet_ntoa (nbr
->router_id
),
245 LOOKUP (ospf_nsm_state_msg
, nbr
->state
),
252 /* Get current time. */
253 gettimeofday (&now
, NULL
);
255 /* If there is already a database copy, and if the
256 database copy was received via flooding and installed less
257 than MinLSArrival seconds ago, discard the new LSA
258 (without acknowledging it). */
259 if (current
!= NULL
) /* -- endo. */
261 if (IS_LSA_SELF (current
)
262 && (ntohs (current
->data
->ls_age
) == 0
263 && ntohl (current
->data
->ls_seqnum
) == OSPF_INITIAL_SEQUENCE_NUMBER
))
265 if (IS_DEBUG_OSPF_EVENT
)
266 zlog_info ("LSA[Flooding]: Got a self-originated LSA, "
267 "while local one is initial instance.");
268 ; /* Accept this LSA for quick LSDB resynchronization. */
270 else if (tv_cmp (tv_sub (now
, current
->tv_recv
),
271 int2tv (OSPF_MIN_LS_ARRIVAL
)) < 0)
273 if (IS_DEBUG_OSPF_EVENT
)
274 zlog_info ("LSA[Flooding]: LSA is received recently.");
279 /* Flood the new LSA out some subset of the router's interfaces.
280 In some cases (e.g., the state of the receiving interface is
281 DR and the LSA was received from a router other than the
282 Backup DR) the LSA will be flooded back out the receiving
284 lsa_ack_flag
= ospf_flood_through (nbr
, new);
286 #ifdef HAVE_OPAQUE_LSA
287 /* Remove the current database copy from all neighbors' Link state
288 retransmission lists. AS_EXTERNAL and AS_EXTERNAL_OPAQUE does
289 ^^^^^^^^^^^^^^^^^^^^^^^
291 All other (even NSSA's) do have area ID. */
292 #else /* HAVE_OPAQUE_LSA */
293 /* Remove the current database copy from all neighbors' Link state
294 retransmission lists. Only AS_EXTERNAL does not have area ID.
295 All other (even NSSA's) do have area ID. */
296 #endif /* HAVE_OPAQUE_LSA */
299 switch (current
->data
->type
)
301 case OSPF_AS_EXTERNAL_LSA
:
302 #ifdef HAVE_OPAQUE_LSA
303 case OSPF_OPAQUE_AS_LSA
:
304 #endif /* HAVE_OPAQUE_LSA */
305 ospf_ls_retransmit_delete_nbr_all (NULL
, current
);
308 ospf_ls_retransmit_delete_nbr_all (nbr
->oi
->area
, current
);
313 /* Do some internal house keeping that is needed here */
314 SET_FLAG (new->flags
, OSPF_LSA_RECEIVED
);
315 ospf_lsa_is_self_originated (new); /* Let it set the flag */
317 /* Install the new LSA in the link state database
318 (replacing the current database copy). This may cause the
319 routing table calculation to be scheduled. In addition,
320 timestamp the new LSA with the current time. The flooding
321 procedure cannot overwrite the newly installed LSA until
322 MinLSArrival seconds have elapsed. */
324 new = ospf_lsa_install (nbr
->oi
, new);
327 if (IS_DEBUG_OSPF_NSSA
)
328 zlog_info ("LSA[Flooding]: Type-%d installed", new->data
->type
);
330 /* if (new->data->type == OSPF_AS_NSSA_LSA )
332 #endif /* HAVE_NSSA */
334 /* Acknowledge the receipt of the LSA by sending a Link State
335 Acknowledgment packet back out the receiving interface. */
337 ospf_flood_delayed_lsa_ack (nbr
, new);
339 /* If this new LSA indicates that it was originated by the
340 receiving router itself, the router must take special action,
341 either updating the LSA or in some cases flushing it from
342 the routing domain. */
343 if (ospf_lsa_is_self_originated (new))
344 ospf_process_self_originated_lsa (new, oi
->area
);
346 /* Update statistics value for OSPF-MIB. */
347 ospf_top
->rx_lsa_count
++;
352 /* OSPF LSA flooding -- RFC2328 Section 13.3. */
354 ospf_flood_through_interface (struct ospf_interface
*oi
,
355 struct ospf_neighbor
*inbr
,
356 struct ospf_lsa
*lsa
)
358 struct ospf_neighbor
*onbr
;
359 struct route_node
*rn
;
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",
368 if (!ospf_if_is_enable (oi
))
371 /* Remember if new LSA is aded to a retransmit list. */
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
))
379 struct ospf_lsa
*ls_req
;
381 if (rn
->info
== NULL
)
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
));
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
)
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
)
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
);
411 ret
= ospf_lsa_more_recent (ls_req
, lsa
);
412 /* The new LSA is less recent. */
415 /* The two copies are the same instance, then delete
416 the LSA from the Link state request list. */
419 ospf_ls_request_delete (onbr
, ls_req
);
420 ospf_check_nbr_loading (onbr
);
423 /* The new LSA is more recent. Delete the LSA
424 from the Link state request list. */
427 ospf_ls_request_delete (onbr
, ls_req
);
428 ospf_check_nbr_loading (onbr
);
433 #ifdef HAVE_OPAQUE_LSA
434 if (IS_OPAQUE_LSA (lsa
->data
->type
))
436 if (! CHECK_FLAG (onbr
->options
, OSPF_OPTION_O
))
438 if (IS_DEBUG_OSPF (lsa
, LSA_FLOODING
))
439 zlog_info ("Skip this neighbor: Not Opaque-capable.");
443 if (IS_OPAQUE_LSA_ORIGINATION_BLOCKED (ospf_top
->opaque
)
445 && onbr
->state
== NSM_Full
)
447 /* Small attempt to reduce unnecessary retransmission. */
448 if (IS_DEBUG_OSPF (lsa
, LSA_FLOODING
))
449 zlog_info ("Skip this neighbor: Initial flushing done.");
453 #endif /* HAVE_OPAQUE_LSA */
455 /* If the new LSA was received from this neighbor,
456 examine the next neighbor. */
457 #ifdef ORIGINAL_CODING
459 if (IPV4_ADDR_SAME (&inbr
->router_id
, &onbr
->router_id
))
461 #else /* ORIGINAL_CODING */
465 * Triggered by LSUpd message parser "ospf_ls_upd ()".
466 * E.g., all LSAs handling here is received via network.
468 if (IPV4_ADDR_SAME (&inbr
->router_id
, &onbr
->router_id
))
470 if (IS_DEBUG_OSPF (lsa
, LSA_FLOODING
))
471 zlog_info ("Skip this neighbor: inbr == onbr");
478 * Triggered by MaxAge remover, so far.
479 * NULL "inbr" means flooding starts from this node.
481 if (IPV4_ADDR_SAME (&lsa
->data
->adv_router
, &onbr
->router_id
))
483 if (IS_DEBUG_OSPF (lsa
, LSA_FLOODING
))
484 zlog_info ("Skip this neighbor: lsah->adv_router == onbr");
488 #endif /* ORIGINAL_CODING */
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
494 ospf_ls_retransmit_add (onbr
, lsa
);
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. */
503 return (inbr
&& inbr
->oi
== oi
);
506 /* if we've received the lsa on this interface we need to perform
507 additional checking */
508 if (inbr
&& (inbr
->oi
== oi
))
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
))
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 */
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. */
530 if (oi
->state
== ISM_Backup
)
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 */
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
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 */
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 */
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
565 if (oi
->type
== OSPF_IFTYPE_NBMA
)
567 struct route_node
*rn
;
568 struct ospf_neighbor
*nbr
;
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
);
576 ospf_ls_upd_send_lsa (oi
->nbr_self
, lsa
, OSPF_SEND_PACKET_INDIRECT
);
582 ospf_flood_through_area (struct ospf_area
* area
,struct ospf_neighbor
*inbr
,
583 struct ospf_lsa
*lsa
)
586 int lsa_ack_flag
= 0;
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
592 for (node
= listhead (area
->oiflist
); node
; nextnode (node
))
594 struct ospf_interface
*oi
= getdata (node
);
596 if (area
->area_id
.s_addr
!= OSPF_AREA_BACKBONE
&&
597 oi
->type
== OSPF_IFTYPE_VIRTUALLINK
)
600 #ifdef HAVE_OPAQUE_LSA
601 if ((lsa
->data
->type
== OSPF_OPAQUE_LINK_LSA
) && (lsa
->oi
!= oi
))
604 * Link local scoped Opaque-LSA should only be flooded
605 * for the link on which the LSA has received.
607 if (IS_DEBUG_OSPF (lsa
, LSA_FLOODING
))
608 zlog_info ("Type-9 Opaque-LSA: lsa->oi(%p) != oi(%p)", lsa
->oi
, oi
);
611 #endif /* HAVE_OPAQUE_LSA */
613 if (ospf_flood_through_interface (oi
, inbr
, lsa
))
617 return (lsa_ack_flag
);
621 ospf_flood_through_as (struct ospf_neighbor
*inbr
, struct ospf_lsa
*lsa
)
628 /* The incoming LSA is type 5 or type 7 (AS-EXTERNAL or AS-NSSA )
630 Divert the Type-5 LSA's to all non-NSSA/STUB areas
632 Divert the Type-7 LSA's to all NSSA areas
634 AS-external-LSAs are flooded throughout the entire AS, with the
635 exception of stub areas (see Section 3.6). The eligible
636 interfaces are all the router's interfaces, excluding virtual
637 links and those interfaces attaching to stub areas. */
640 if (CHECK_FLAG (lsa
->flags
, OSPF_LSA_LOCAL_XLT
)) /* Translated from 7 */
641 if (IS_DEBUG_OSPF_NSSA
)
642 zlog_info ("Flood/AS: NSSA TRANSLATED LSA");
643 #endif /* HAVE_NSSA */
645 for (node
= listhead (ospf_top
->areas
); node
; nextnode (node
))
647 int continue_flag
= 0;
648 struct ospf_area
*area
= getdata (node
);
651 switch (area
->external_routing
)
653 /* Don't send AS externals into stub areas. Various types
654 of support for partial stub areas can be implemented
655 here. NSSA's will receive Type-7's that have areas
656 matching the originl LSA. */
657 case OSPF_AREA_NSSA
: /* Sending Type 5 or 7 into NSSA area */
659 /* Type-7, flood NSSA area */
660 if (lsa
->data
->type
== OSPF_AS_NSSA_LSA
)
661 /* We will send it. */
664 continue_flag
= 1; /* Skip this NSSA area for Type-5's et al */
666 #endif /* HAVE_NSSA */
668 case OSPF_AREA_TYPE_MAX
:
670 continue_flag
= 1; /* Skip this area. */
673 case OSPF_AREA_DEFAULT
:
676 /* No Type-7 into normal area */
677 if (lsa
->data
->type
== OSPF_AS_NSSA_LSA
)
678 continue_flag
= 1; /* skip Type-7 */
680 #endif /* HAVE_NSSA */
681 continue_flag
= 0; /* Do this area. */
685 /* Do continue for above switch. Saves a big if then mess */
687 continue; /* main for-loop */
689 /* send to every interface in this area */
691 for (if_node
= listhead (area
->oiflist
); if_node
; nextnode (if_node
))
693 struct ospf_interface
*oi
= getdata (if_node
);
695 /* Skip virtual links */
696 if (oi
->type
!= OSPF_IFTYPE_VIRTUALLINK
)
697 if (ospf_flood_through_interface (oi
, inbr
, lsa
)) /* lsa */
700 } /* main area for-loop */
702 return (lsa_ack_flag
);
706 ospf_flood_through (struct ospf_neighbor
*inbr
, struct ospf_lsa
*lsa
)
708 int lsa_ack_flag
= 0;
710 /* Type-7 LSA's for NSSA are flooded throughout the AS here, and
711 upon return are updated in the LSDB for Type-7's. Later,
712 re-fresh will re-send them (and also, if ABR, packet code will
713 translate to Type-5's)
715 As usual, Type-5 LSA's (if not DISCARDED because we are STUB or
716 NSSA) are flooded throughout the AS, and are updated in the
718 #ifdef ORIGINAL_CODING
719 switch (lsa
->data
->type
)
721 case OSPF_ROUTER_LSA
:
722 case OSPF_NETWORK_LSA
:
723 case OSPF_SUMMARY_LSA
:
724 case OSPF_ASBR_SUMMARY_LSA
:
725 #ifdef HAVE_OPAQUE_LSA
726 case OSPF_OPAQUE_LINK_LSA
: /* ospf_flood_through_interface ? */
727 case OSPF_OPAQUE_AREA_LSA
:
728 #endif /* HAVE_OPAQUE_LSA */
729 lsa_ack_flag
= ospf_flood_through_area (inbr
->oi
->area
, inbr
, lsa
);
731 case OSPF_AS_EXTERNAL_LSA
: /* Type-5 */
732 #ifdef HAVE_OPAQUE_LSA
733 case OSPF_OPAQUE_AS_LSA
:
734 #endif /* HAVE_OPAQUE_LSA */
735 lsa_ack_flag
= ospf_flood_through_as (inbr
, lsa
);
738 /* Type-7 Only received within NSSA, then flooded */
739 case OSPF_AS_NSSA_LSA
:
740 /* Any P-bit was installed with the Type-7. */
741 lsa_ack_flag
= ospf_flood_through_area (inbr
->oi
->area
, inbr
, lsa
);
743 if (IS_DEBUG_OSPF_NSSA
)
744 zlog_info ("ospf_flood_through: LOCAL NSSA FLOOD of Type-7.");
746 #endif /* HAVE_NSSA */
750 #else /* ORIGINAL_CODING */
752 * At the common sub-sub-function "ospf_flood_through_interface()",
753 * a parameter "inbr" will be used to distinguish the called context
754 * whether the given LSA was received from the neighbor, or the
755 * flooding for the LSA starts from this node (e.g. the LSA was self-
756 * originated, or the LSA is going to be flushed from routing domain).
758 * So, for consistency reasons, this function "ospf_flood_through()"
759 * should also allow the usage that the given "inbr" parameter to be
760 * NULL. If we do so, corresponding AREA parameter should be referred
761 * by "lsa->area", instead of "inbr->oi->area".
763 switch (lsa
->data
->type
)
765 case OSPF_AS_EXTERNAL_LSA
: /* Type-5 */
766 #ifdef HAVE_OPAQUE_LSA
767 case OSPF_OPAQUE_AS_LSA
:
768 #endif /* HAVE_OPAQUE_LSA */
769 lsa_ack_flag
= ospf_flood_through_as (inbr
, lsa
);
772 /* Type-7 Only received within NSSA, then flooded */
773 case OSPF_AS_NSSA_LSA
:
774 /* Any P-bit was installed with the Type-7. */
776 if (IS_DEBUG_OSPF_NSSA
)
777 zlog_info ("ospf_flood_through: LOCAL NSSA FLOOD of Type-7.");
779 #endif /* HAVE_NSSA */
781 lsa_ack_flag
= ospf_flood_through_area (lsa
->area
, inbr
, lsa
);
784 #endif /* ORIGINAL_CODING */
786 return (lsa_ack_flag
);
791 /* Management functions for neighbor's Link State Request list. */
793 ospf_ls_request_add (struct ospf_neighbor
*nbr
, struct ospf_lsa
*lsa
)
796 * We cannot make use of the newly introduced callback function
797 * "lsdb->new_lsa_hook" to replace debug output below, just because
798 * it seems no simple and smart way to pass neighbor information to
799 * the common function "ospf_lsdb_add()" -- endo.
801 if (IS_DEBUG_OSPF (lsa
, LSA_FLOODING
))
802 zlog_info ("RqstL(%lu)++, NBR(%s), LSA[%s]",
803 ospf_ls_request_count (nbr
),
804 inet_ntoa (nbr
->router_id
), dump_lsa_key (lsa
));
806 ospf_lsdb_add (&nbr
->ls_req
, lsa
);
810 ospf_ls_request_count (struct ospf_neighbor
*nbr
)
812 return ospf_lsdb_count_all (&nbr
->ls_req
);
816 ospf_ls_request_isempty (struct ospf_neighbor
*nbr
)
818 return ospf_lsdb_isempty (&nbr
->ls_req
);
821 /* Remove LSA from neighbor's ls-request list. */
823 ospf_ls_request_delete (struct ospf_neighbor
*nbr
, struct ospf_lsa
*lsa
)
825 if (nbr
->ls_req_last
== lsa
)
827 ospf_lsa_unlock (nbr
->ls_req_last
);
828 nbr
->ls_req_last
= NULL
;
831 if (IS_DEBUG_OSPF (lsa
, LSA_FLOODING
)) /* -- endo. */
832 zlog_info ("RqstL(%lu)--, NBR(%s), LSA[%s]",
833 ospf_ls_request_count (nbr
),
834 inet_ntoa (nbr
->router_id
), dump_lsa_key (lsa
));
836 ospf_lsdb_delete (&nbr
->ls_req
, lsa
);
839 /* Remove all LSA from neighbor's ls-requenst list. */
841 ospf_ls_request_delete_all (struct ospf_neighbor
*nbr
)
843 ospf_lsa_unlock (nbr
->ls_req_last
);
844 nbr
->ls_req_last
= NULL
;
845 ospf_lsdb_delete_all (&nbr
->ls_req
);
848 /* Lookup LSA from neighbor's ls-request list. */
850 ospf_ls_request_lookup (struct ospf_neighbor
*nbr
, struct ospf_lsa
*lsa
)
852 return ospf_lsdb_lookup (&nbr
->ls_req
, lsa
);
856 ospf_ls_request_new (struct lsa_header
*lsah
)
858 struct ospf_lsa
*new;
860 new = ospf_lsa_new ();
861 new->data
= ospf_lsa_data_new (OSPF_LSA_HEADER_SIZE
);
862 memcpy (new->data
, lsah
, OSPF_LSA_HEADER_SIZE
);
868 /* Management functions for neighbor's ls-retransmit list. */
870 ospf_ls_retransmit_count (struct ospf_neighbor
*nbr
)
872 return ospf_lsdb_count_all (&nbr
->ls_rxmt
);
876 ospf_ls_retransmit_count_self (struct ospf_neighbor
*nbr
, int lsa_type
)
878 return ospf_lsdb_count_self (&nbr
->ls_rxmt
, lsa_type
);
882 ospf_ls_retransmit_isempty (struct ospf_neighbor
*nbr
)
884 return ospf_lsdb_isempty (&nbr
->ls_rxmt
);
887 /* Add LSA to be retransmitted to neighbor's ls-retransmit list. */
889 ospf_ls_retransmit_add (struct ospf_neighbor
*nbr
, struct ospf_lsa
*lsa
)
891 struct ospf_lsa
*old
;
893 old
= ospf_ls_retransmit_lookup (nbr
, lsa
);
895 if (ospf_lsa_more_recent (old
, lsa
) < 0)
899 old
->retransmit_counter
--;
900 ospf_lsdb_delete (&nbr
->ls_rxmt
, old
);
902 lsa
->retransmit_counter
++;
904 * We cannot make use of the newly introduced callback function
905 * "lsdb->new_lsa_hook" to replace debug output below, just because
906 * it seems no simple and smart way to pass neighbor information to
907 * the common function "ospf_lsdb_add()" -- endo.
909 if (IS_DEBUG_OSPF (lsa
, LSA_FLOODING
))
910 zlog_info ("RXmtL(%lu)++, NBR(%s), LSA[%s]",
911 ospf_ls_retransmit_count (nbr
),
912 inet_ntoa (nbr
->router_id
), dump_lsa_key (lsa
));
913 ospf_lsdb_add (&nbr
->ls_rxmt
, lsa
);
917 /* Remove LSA from neibghbor's ls-retransmit list. */
919 ospf_ls_retransmit_delete (struct ospf_neighbor
*nbr
, struct ospf_lsa
*lsa
)
921 if (ospf_ls_retransmit_lookup (nbr
, lsa
))
923 lsa
->retransmit_counter
--;
924 if (IS_DEBUG_OSPF (lsa
, LSA_FLOODING
)) /* -- endo. */
925 zlog_info ("RXmtL(%lu)--, NBR(%s), LSA[%s]",
926 ospf_ls_retransmit_count (nbr
),
927 inet_ntoa (nbr
->router_id
), dump_lsa_key (lsa
));
928 ospf_lsdb_delete (&nbr
->ls_rxmt
, lsa
);
932 /* Clear neighbor's ls-retransmit list. */
934 ospf_ls_retransmit_clear (struct ospf_neighbor
*nbr
)
936 struct ospf_lsdb
*lsdb
;
939 lsdb
= &nbr
->ls_rxmt
;
941 for (i
= OSPF_MIN_LSA
; i
< OSPF_MAX_LSA
; i
++)
943 struct route_table
*table
= lsdb
->type
[i
].db
;
944 struct route_node
*rn
;
945 struct ospf_lsa
*lsa
;
947 for (rn
= route_top (table
); rn
; rn
= route_next (rn
))
948 if ((lsa
= rn
->info
) != NULL
)
949 ospf_ls_retransmit_delete (nbr
, lsa
);
952 ospf_lsa_unlock (nbr
->ls_req_last
);
953 nbr
->ls_req_last
= NULL
;
956 /* Lookup LSA from neighbor's ls-retransmit list. */
958 ospf_ls_retransmit_lookup (struct ospf_neighbor
*nbr
, struct ospf_lsa
*lsa
)
960 return ospf_lsdb_lookup (&nbr
->ls_rxmt
, lsa
);
963 /* Remove All neighbor/interface's Link State Retransmit list in area. */
965 ospf_ls_retransmit_delete_nbr_all (struct ospf_area
*area
,
966 struct ospf_lsa
*lsa
)
969 list oiflist
= area
? area
->oiflist
: ospf_top
->oiflist
;
971 for (node
= listhead (oiflist
); node
; nextnode (node
))
973 struct ospf_interface
*oi
= getdata (node
);
974 struct route_node
*rn
;
975 struct ospf_neighbor
*nbr
;
976 struct ospf_lsa
*lsr
;
978 if (ospf_if_is_enable (oi
))
979 for (rn
= route_top (oi
->nbrs
); rn
; rn
= route_next (rn
))
980 /* If LSA find in LS-retransmit list, then remove it. */
981 if ((nbr
= rn
->info
) != NULL
)
983 lsr
= ospf_ls_retransmit_lookup (nbr
, lsa
);
985 /* If LSA find in ls-retransmit list, remove it. */
986 if (lsr
!= NULL
&& lsr
->data
->ls_seqnum
== lsa
->data
->ls_seqnum
)
987 ospf_ls_retransmit_delete (nbr
, lsr
);
992 /* Add LSA to the current database copy of all neighbors'
993 Link state retransmission lists. */
995 ospf_ls_retransmit_add_nbr_all (struct ospf_interface
*ospfi
,
996 struct ospf_lsa
*lsa
)
1000 for (node
= listhead (ospf_top
->oiflist
); node
; nextnode (node
))
1002 struct ospf_interface
*oi
= getdata (node
);
1003 struct route_node
*rn
;
1004 struct ospf_neighbor
*nbr
;
1005 struct ospf_lsa
*old
;
1007 if (ospf_if_is_enable (oi
))
1008 if (OSPF_AREA_SAME (&ospfi
->area
, &oi
->area
))
1009 for (rn
= route_top (oi
->nbrs
); rn
; rn
= route_next (rn
))
1010 if ((nbr
= rn
->info
) != NULL
)
1011 if (nbr
->state
== NSM_Full
)
1013 if ((old
= ospf_ls_retransmit_lookup (nbr
, lsa
)))
1014 ospf_ls_retransmit_delete (nbr
, old
);
1016 ospf_ls_retransmit_add (nbr
, lsa
);
1022 /* Sets ls_age to MaxAge and floods throu the area.
1023 When we implement ASE routing, there will be anothe function
1024 flushing an LSA from the whole domain. */
1026 ospf_lsa_flush_area (struct ospf_lsa
*lsa
, struct ospf_area
*area
)
1028 lsa
->data
->ls_age
= htons (OSPF_LSA_MAXAGE
);
1029 ospf_flood_through_area (area
, NULL
, lsa
);
1030 ospf_lsa_maxage (lsa
);
1034 ospf_lsa_flush_as (struct ospf_lsa
*lsa
)
1036 lsa
->data
->ls_age
= htons (OSPF_LSA_MAXAGE
);
1037 ospf_flood_through_as (NULL
, lsa
);
1038 ospf_lsa_maxage (lsa
);
1041 /* Flush LSA through AS -- used for AS-external-LSAs. */
1043 ospf_flush_through_as (struct ospf_lsa
*lsa
)
1045 lsa
->data
->ls_age
= htons (OSPF_LSA_MAXAGE
);
1046 ospf_flood_through_as (NULL
, lsa
);
1047 ospf_lsa_maxage (lsa
);