2 * Copyright (C) 2003 Yasuhiro Ohara
4 * This file is part of GNU Zebra.
6 * GNU Zebra is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License as published by the
8 * Free Software Foundation; either version 2, or (at your option) any
11 * GNU Zebra is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with GNU Zebra; see the file COPYING. If not, write to the
18 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19 * Boston, MA 02111-1307, USA.
31 #include "ospf6_proto.h"
32 #include "ospf6_lsa.h"
33 #include "ospf6_lsdb.h"
34 #include "ospf6_message.h"
35 #include "ospf6_route.h"
36 #include "ospf6_spf.h"
38 #include "ospf6_top.h"
39 #include "ospf6_area.h"
40 #include "ospf6_interface.h"
41 #include "ospf6_neighbor.h"
43 #include "ospf6_flood.h"
45 unsigned char conf_debug_ospf6_flooding
;
48 ospf6_get_scoped_lsdb (struct ospf6_lsa
*lsa
)
50 struct ospf6_lsdb
*lsdb
= NULL
;
51 switch (OSPF6_LSA_SCOPE (lsa
->header
->type
))
53 case OSPF6_SCOPE_LINKLOCAL
:
54 lsdb
= OSPF6_INTERFACE (lsa
->lsdb
->data
)->lsdb
;
56 case OSPF6_SCOPE_AREA
:
57 lsdb
= OSPF6_AREA (lsa
->lsdb
->data
)->lsdb
;
60 lsdb
= OSPF6_PROCESS (lsa
->lsdb
->data
)->lsdb
;
70 ospf6_get_scoped_lsdb_self (struct ospf6_lsa
*lsa
)
72 struct ospf6_lsdb
*lsdb_self
= NULL
;
73 switch (OSPF6_LSA_SCOPE (lsa
->header
->type
))
75 case OSPF6_SCOPE_LINKLOCAL
:
76 lsdb_self
= OSPF6_INTERFACE (lsa
->lsdb
->data
)->lsdb_self
;
78 case OSPF6_SCOPE_AREA
:
79 lsdb_self
= OSPF6_AREA (lsa
->lsdb
->data
)->lsdb_self
;
82 lsdb_self
= OSPF6_PROCESS (lsa
->lsdb
->data
)->lsdb_self
;
92 ospf6_lsa_originate (struct ospf6_lsa
*lsa
)
94 struct ospf6_lsa
*old
;
95 struct ospf6_lsdb
*lsdb_self
;
97 /* find previous LSA */
98 old
= ospf6_lsdb_lookup (lsa
->header
->type
, lsa
->header
->id
,
99 lsa
->header
->adv_router
, lsa
->lsdb
);
101 /* if the new LSA does not differ from previous,
102 suppress this update of the LSA */
103 if (old
&& ! OSPF6_LSA_IS_DIFFER (lsa
, old
))
105 if (IS_OSPF6_DEBUG_ORIGINATE_TYPE (lsa
->header
->type
))
106 zlog_debug ("Suppress updating LSA: %s", lsa
->name
);
107 ospf6_lsa_delete (lsa
);
111 /* store it in the LSDB for self-originated LSAs */
112 lsdb_self
= ospf6_get_scoped_lsdb_self (lsa
);
113 ospf6_lsdb_add (ospf6_lsa_copy (lsa
), lsdb_self
);
116 thread_add_timer(master
, ospf6_lsa_refresh
, lsa
, OSPF_LS_REFRESH_TIME
,
119 if (IS_OSPF6_DEBUG_LSA_TYPE (lsa
->header
->type
) ||
120 IS_OSPF6_DEBUG_ORIGINATE_TYPE (lsa
->header
->type
))
122 zlog_debug ("LSA Originate:");
123 ospf6_lsa_header_print (lsa
);
126 ospf6_install_lsa (lsa
);
127 ospf6_flood (NULL
, lsa
);
131 ospf6_lsa_originate_process (struct ospf6_lsa
*lsa
,
132 struct ospf6
*process
)
134 lsa
->lsdb
= process
->lsdb
;
135 ospf6_lsa_originate (lsa
);
139 ospf6_lsa_originate_area (struct ospf6_lsa
*lsa
,
140 struct ospf6_area
*oa
)
142 lsa
->lsdb
= oa
->lsdb
;
143 ospf6_lsa_originate (lsa
);
147 ospf6_lsa_originate_interface (struct ospf6_lsa
*lsa
,
148 struct ospf6_interface
*oi
)
150 lsa
->lsdb
= oi
->lsdb
;
151 ospf6_lsa_originate (lsa
);
155 ospf6_lsa_purge (struct ospf6_lsa
*lsa
)
157 struct ospf6_lsa
*self
;
158 struct ospf6_lsdb
*lsdb_self
;
160 /* remove it from the LSDB for self-originated LSAs */
161 lsdb_self
= ospf6_get_scoped_lsdb_self (lsa
);
162 self
= ospf6_lsdb_lookup (lsa
->header
->type
, lsa
->header
->id
,
163 lsa
->header
->adv_router
, lsdb_self
);
166 THREAD_OFF (self
->expire
);
167 THREAD_OFF (self
->refresh
);
168 ospf6_lsdb_remove (self
, lsdb_self
);
171 ospf6_lsa_premature_aging (lsa
);
176 ospf6_increment_retrans_count (struct ospf6_lsa
*lsa
)
178 /* The LSA must be the original one (see the description
179 in ospf6_decrement_retrans_count () below) */
180 lsa
->retrans_count
++;
184 ospf6_decrement_retrans_count (struct ospf6_lsa
*lsa
)
186 struct ospf6_lsdb
*lsdb
;
187 struct ospf6_lsa
*orig
;
189 /* The LSA must be on the retrans-list of a neighbor. It means
190 the "lsa" is a copied one, and we have to decrement the
191 retransmission count of the original one (instead of this "lsa"'s).
192 In order to find the original LSA, first we have to find
193 appropriate LSDB that have the original LSA. */
194 lsdb
= ospf6_get_scoped_lsdb (lsa
);
196 /* Find the original LSA of which the retrans_count should be decremented */
197 orig
= ospf6_lsdb_lookup (lsa
->header
->type
, lsa
->header
->id
,
198 lsa
->header
->adv_router
, lsdb
);
201 orig
->retrans_count
--;
202 assert (orig
->retrans_count
>= 0);
206 /* RFC2328 section 13.2 Installing LSAs in the database */
208 ospf6_install_lsa (struct ospf6_lsa
*lsa
)
211 struct ospf6_lsa
*old
;
213 if (IS_OSPF6_DEBUG_LSA_TYPE (lsa
->header
->type
) ||
214 IS_OSPF6_DEBUG_EXAMIN_TYPE (lsa
->header
->type
))
215 zlog_debug ("Install LSA: %s", lsa
->name
);
217 /* Remove the old instance from all neighbors' Link state
218 retransmission list (RFC2328 13.2 last paragraph) */
219 old
= ospf6_lsdb_lookup (lsa
->header
->type
, lsa
->header
->id
,
220 lsa
->header
->adv_router
, lsa
->lsdb
);
223 THREAD_OFF (old
->expire
);
224 THREAD_OFF (old
->refresh
);
225 ospf6_flood_clear (old
);
229 if (! OSPF6_LSA_IS_MAXAGE (lsa
)) {
231 thread_add_timer(master
, ospf6_lsa_expire
, lsa
, OSPF_LSA_MAXAGE
+ lsa
->birth
.tv_sec
- now
.tv_sec
,
237 if (OSPF6_LSA_IS_SEQWRAP(lsa
) &&
238 ! (CHECK_FLAG(lsa
->flag
,OSPF6_LSA_SEQWRAPPED
) &&
239 lsa
->header
->seqnum
== htonl(OSPF_MAX_SEQUENCE_NUMBER
)))
241 if (IS_OSPF6_DEBUG_EXAMIN_TYPE (lsa
->header
->type
))
242 zlog_debug("lsa install wrapping: sequence 0x%x",
243 ntohl(lsa
->header
->seqnum
));
244 SET_FLAG(lsa
->flag
, OSPF6_LSA_SEQWRAPPED
);
245 /* in lieu of premature_aging, since we do not want to recreate this lsa
246 * and/or mess with timers etc, we just want to wrap the sequence number
247 * and reflood the lsa before continuing.
248 * NOTE: Flood needs to be called right after this function call, by the
251 lsa
->header
->seqnum
= htonl (OSPF_MAX_SEQUENCE_NUMBER
);
252 lsa
->header
->age
= htons (OSPF_LSA_MAXAGE
);
253 ospf6_lsa_checksum (lsa
->header
);
256 /* actually install */
257 lsa
->installed
= now
;
258 ospf6_lsdb_add (lsa
, lsa
->lsdb
);
263 /* RFC2740 section 3.5.2. Sending Link State Update packets */
264 /* RFC2328 section 13.3 Next step in the flooding procedure */
266 ospf6_flood_interface (struct ospf6_neighbor
*from
,
267 struct ospf6_lsa
*lsa
, struct ospf6_interface
*oi
)
269 struct listnode
*node
, *nnode
;
270 struct ospf6_neighbor
*on
;
271 struct ospf6_lsa
*req
;
272 int retrans_added
= 0;
275 if (IS_OSPF6_DEBUG_FLOODING
||
276 IS_OSPF6_DEBUG_FLOOD_TYPE (lsa
->header
->type
))
279 zlog_debug ("Flooding on %s: %s", oi
->interface
->name
, lsa
->name
);
282 /* (1) For each neighbor */
283 for (ALL_LIST_ELEMENTS (oi
->neighbor_list
, node
, nnode
, on
))
286 zlog_debug ("To neighbor %s", on
->name
);
288 /* (a) if neighbor state < Exchange, examin next */
289 if (on
->state
< OSPF6_NEIGHBOR_EXCHANGE
)
292 zlog_debug ("Neighbor state less than ExChange, next neighbor");
296 /* (b) if neighbor not yet Full, check request-list */
297 if (on
->state
!= OSPF6_NEIGHBOR_FULL
)
300 zlog_debug ("Neighbor not yet Full");
302 req
= ospf6_lsdb_lookup (lsa
->header
->type
, lsa
->header
->id
,
303 lsa
->header
->adv_router
, on
->request_list
);
307 zlog_debug ("Not on request-list for this neighbor");
312 /* If new LSA less recent, examin next neighbor */
313 if (ospf6_lsa_compare (lsa
, req
) > 0)
316 zlog_debug ("Requesting is older, next neighbor");
320 /* If the same instance, delete from request-list and
321 examin next neighbor */
322 if (ospf6_lsa_compare (lsa
, req
) == 0)
325 zlog_debug ("Requesting the same, remove it, next neighbor");
326 if (req
== on
->last_ls_req
)
328 ospf6_lsa_unlock (req
);
329 on
->last_ls_req
= NULL
;
331 ospf6_lsdb_remove (req
, on
->request_list
);
332 ospf6_check_nbr_loading (on
);
336 /* If the new LSA is more recent, delete from request-list */
337 if (ospf6_lsa_compare (lsa
, req
) < 0)
340 zlog_debug ("Received is newer, remove requesting");
341 if (req
== on
->last_ls_req
)
343 ospf6_lsa_unlock (req
);
344 on
->last_ls_req
= NULL
;
346 ospf6_lsdb_remove (req
, on
->request_list
);
347 ospf6_check_nbr_loading (on
);
353 /* (c) If the new LSA was received from this neighbor,
354 examin next neighbor */
358 zlog_debug ("Received is from the neighbor, next neighbor");
362 /* (d) add retrans-list, schedule retransmission */
364 zlog_debug ("Add retrans-list of this neighbor");
365 ospf6_increment_retrans_count (lsa
);
366 ospf6_lsdb_add (ospf6_lsa_copy (lsa
), on
->retrans_list
);
367 thread_add_timer(master
, ospf6_lsupdate_send_neighbor
, on
, on
->ospf6_if
->rxmt_interval
,
368 &on
->thread_send_lsupdate
);
372 /* (2) examin next interface if not added to retrans-list */
373 if (retrans_added
== 0)
376 zlog_debug ("No retransmission scheduled, next interface");
380 /* (3) If the new LSA was received on this interface,
381 and it was from DR or BDR, examin next interface */
382 if (from
&& from
->ospf6_if
== oi
&&
383 (from
->router_id
== oi
->drouter
|| from
->router_id
== oi
->bdrouter
))
386 zlog_debug ("Received is from the I/F's DR or BDR, next interface");
390 /* (4) If the new LSA was received on this interface,
391 and the interface state is BDR, examin next interface */
392 if (from
&& from
->ospf6_if
== oi
)
394 if (oi
->state
== OSPF6_INTERFACE_BDR
)
397 zlog_debug ("Received is from the I/F, itself BDR, next interface");
400 SET_FLAG(lsa
->flag
, OSPF6_LSA_FLOODBACK
);
403 /* (5) flood the LSA out the interface. */
405 zlog_debug ("Schedule flooding for the interface");
406 if ((oi
->type
== OSPF_IFTYPE_BROADCAST
) ||
407 (oi
->type
== OSPF_IFTYPE_POINTOPOINT
))
409 ospf6_lsdb_add (ospf6_lsa_copy (lsa
), oi
->lsupdate_list
);
410 thread_add_event(master
, ospf6_lsupdate_send_interface
, oi
, 0,
411 &oi
->thread_send_lsupdate
);
415 /* reschedule retransmissions to all neighbors */
416 for (ALL_LIST_ELEMENTS (oi
->neighbor_list
, node
, nnode
, on
))
418 THREAD_OFF (on
->thread_send_lsupdate
);
419 on
->thread_send_lsupdate
= NULL
;
420 thread_add_event(master
, ospf6_lsupdate_send_neighbor
, on
, 0,
421 &on
->thread_send_lsupdate
);
427 ospf6_flood_area (struct ospf6_neighbor
*from
,
428 struct ospf6_lsa
*lsa
, struct ospf6_area
*oa
)
430 struct listnode
*node
, *nnode
;
431 struct ospf6_interface
*oi
;
433 for (ALL_LIST_ELEMENTS (oa
->if_list
, node
, nnode
, oi
))
435 if (OSPF6_LSA_SCOPE (lsa
->header
->type
) == OSPF6_SCOPE_LINKLOCAL
&&
436 oi
!= OSPF6_INTERFACE (lsa
->lsdb
->data
))
440 if (OSPF6_LSA_SCOPE (lsa
->header
->type
) == OSPF6_SCOPE_AS
&&
441 ospf6_is_interface_virtual_link (oi
))
445 ospf6_flood_interface (from
, lsa
, oi
);
450 ospf6_flood_process (struct ospf6_neighbor
*from
,
451 struct ospf6_lsa
*lsa
, struct ospf6
*process
)
453 struct listnode
*node
, *nnode
;
454 struct ospf6_area
*oa
;
456 for (ALL_LIST_ELEMENTS (process
->area_list
, node
, nnode
, oa
))
458 if (OSPF6_LSA_SCOPE (lsa
->header
->type
) == OSPF6_SCOPE_AREA
&&
459 oa
!= OSPF6_AREA (lsa
->lsdb
->data
))
461 if (OSPF6_LSA_SCOPE (lsa
->header
->type
) == OSPF6_SCOPE_LINKLOCAL
&&
462 oa
!= OSPF6_INTERFACE (lsa
->lsdb
->data
)->area
)
465 if (ntohs (lsa
->header
->type
) == OSPF6_LSTYPE_AS_EXTERNAL
&&
469 ospf6_flood_area (from
, lsa
, oa
);
474 ospf6_flood (struct ospf6_neighbor
*from
, struct ospf6_lsa
*lsa
)
476 ospf6_flood_process (from
, lsa
, ospf6
);
480 ospf6_flood_clear_interface (struct ospf6_lsa
*lsa
, struct ospf6_interface
*oi
)
482 struct listnode
*node
, *nnode
;
483 struct ospf6_neighbor
*on
;
484 struct ospf6_lsa
*rem
;
486 for (ALL_LIST_ELEMENTS (oi
->neighbor_list
, node
, nnode
, on
))
488 rem
= ospf6_lsdb_lookup (lsa
->header
->type
, lsa
->header
->id
,
489 lsa
->header
->adv_router
, on
->retrans_list
);
490 if (rem
&& ! ospf6_lsa_compare (rem
, lsa
))
492 if (IS_OSPF6_DEBUG_FLOODING
||
493 IS_OSPF6_DEBUG_FLOOD_TYPE (lsa
->header
->type
))
494 zlog_debug ("Remove %s from retrans_list of %s",
495 rem
->name
, on
->name
);
496 ospf6_decrement_retrans_count (rem
);
497 ospf6_lsdb_remove (rem
, on
->retrans_list
);
503 ospf6_flood_clear_area (struct ospf6_lsa
*lsa
, struct ospf6_area
*oa
)
505 struct listnode
*node
, *nnode
;
506 struct ospf6_interface
*oi
;
508 for (ALL_LIST_ELEMENTS (oa
->if_list
, node
, nnode
, oi
))
510 if (OSPF6_LSA_SCOPE (lsa
->header
->type
) == OSPF6_SCOPE_LINKLOCAL
&&
511 oi
!= OSPF6_INTERFACE (lsa
->lsdb
->data
))
515 if (OSPF6_LSA_SCOPE (lsa
->header
->type
) == OSPF6_SCOPE_AS
&&
516 ospf6_is_interface_virtual_link (oi
))
520 ospf6_flood_clear_interface (lsa
, oi
);
525 ospf6_flood_clear_process (struct ospf6_lsa
*lsa
, struct ospf6
*process
)
527 struct listnode
*node
, *nnode
;
528 struct ospf6_area
*oa
;
530 for (ALL_LIST_ELEMENTS (process
->area_list
, node
, nnode
, oa
))
532 if (OSPF6_LSA_SCOPE (lsa
->header
->type
) == OSPF6_SCOPE_AREA
&&
533 oa
!= OSPF6_AREA (lsa
->lsdb
->data
))
535 if (OSPF6_LSA_SCOPE (lsa
->header
->type
) == OSPF6_SCOPE_LINKLOCAL
&&
536 oa
!= OSPF6_INTERFACE (lsa
->lsdb
->data
)->area
)
539 if (ntohs (lsa
->header
->type
) == OSPF6_LSTYPE_AS_EXTERNAL
&&
543 ospf6_flood_clear_area (lsa
, oa
);
548 ospf6_flood_clear (struct ospf6_lsa
*lsa
)
550 ospf6_flood_clear_process (lsa
, ospf6
);
554 /* RFC2328 13.5 (Table 19): Sending link state acknowledgements. */
556 ospf6_acknowledge_lsa_bdrouter (struct ospf6_lsa
*lsa
, int ismore_recent
,
557 struct ospf6_neighbor
*from
)
559 struct ospf6_interface
*oi
;
562 if (IS_OSPF6_DEBUG_FLOODING
||
563 IS_OSPF6_DEBUG_FLOOD_TYPE (lsa
->header
->type
))
566 assert (from
&& from
->ospf6_if
);
569 /* LSA is more recent than database copy, but was not flooded
570 back out receiving interface. Delayed acknowledgement sent
571 if advertisement received from Designated Router,
572 otherwide do nothing. */
573 if (ismore_recent
< 0)
575 if (oi
->drouter
== from
->router_id
)
578 zlog_debug ("Delayed acknowledgement (BDR & MoreRecent & from DR)");
579 /* Delayed acknowledgement */
580 ospf6_lsdb_add (ospf6_lsa_copy (lsa
), oi
->lsack_list
);
581 thread_add_timer(master
, ospf6_lsack_send_interface
, oi
, 3,
582 &oi
->thread_send_lsack
);
587 zlog_debug ("No acknowledgement (BDR & MoreRecent & ! from DR)");
592 /* LSA is a duplicate, and was treated as an implied acknowledgement.
593 Delayed acknowledgement sent if advertisement received from
594 Designated Router, otherwise do nothing */
595 if (CHECK_FLAG (lsa
->flag
, OSPF6_LSA_DUPLICATE
) &&
596 CHECK_FLAG (lsa
->flag
, OSPF6_LSA_IMPLIEDACK
))
598 if (oi
->drouter
== from
->router_id
)
601 zlog_debug ("Delayed acknowledgement (BDR & Duplicate & ImpliedAck & from DR)");
602 /* Delayed acknowledgement */
603 ospf6_lsdb_add (ospf6_lsa_copy (lsa
), oi
->lsack_list
);
604 thread_add_timer(master
, ospf6_lsack_send_interface
, oi
, 3,
605 &oi
->thread_send_lsack
);
610 zlog_debug ("No acknowledgement (BDR & Duplicate & ImpliedAck & ! from DR)");
615 /* LSA is a duplicate, and was not treated as an implied acknowledgement.
616 Direct acknowledgement sent */
617 if (CHECK_FLAG (lsa
->flag
, OSPF6_LSA_DUPLICATE
) &&
618 ! CHECK_FLAG (lsa
->flag
, OSPF6_LSA_IMPLIEDACK
))
621 zlog_debug ("Direct acknowledgement (BDR & Duplicate)");
622 ospf6_lsdb_add (ospf6_lsa_copy (lsa
), from
->lsack_list
);
623 thread_add_event(master
, ospf6_lsack_send_neighbor
, from
, 0,
624 &from
->thread_send_lsack
);
628 /* LSA's LS age is equal to Maxage, and there is no current instance
629 of the LSA in the link state database, and none of router's
630 neighbors are in states Exchange or Loading */
631 /* Direct acknowledgement sent, but this case is handled in
632 early of ospf6_receive_lsa () */
636 ospf6_acknowledge_lsa_allother (struct ospf6_lsa
*lsa
, int ismore_recent
,
637 struct ospf6_neighbor
*from
)
639 struct ospf6_interface
*oi
;
642 if (IS_OSPF6_DEBUG_FLOODING
||
643 IS_OSPF6_DEBUG_FLOOD_TYPE (lsa
->header
->type
))
646 assert (from
&& from
->ospf6_if
);
649 /* LSA has been flood back out receiving interface.
650 No acknowledgement sent. */
651 if (CHECK_FLAG (lsa
->flag
, OSPF6_LSA_FLOODBACK
))
654 zlog_debug ("No acknowledgement (AllOther & FloodBack)");
658 /* LSA is more recent than database copy, but was not flooded
659 back out receiving interface. Delayed acknowledgement sent. */
660 if (ismore_recent
< 0)
663 zlog_debug ("Delayed acknowledgement (AllOther & MoreRecent)");
664 /* Delayed acknowledgement */
665 ospf6_lsdb_add (ospf6_lsa_copy (lsa
), oi
->lsack_list
);
666 thread_add_timer(master
, ospf6_lsack_send_interface
, oi
, 3,
667 &oi
->thread_send_lsack
);
671 /* LSA is a duplicate, and was treated as an implied acknowledgement.
672 No acknowledgement sent. */
673 if (CHECK_FLAG (lsa
->flag
, OSPF6_LSA_DUPLICATE
) &&
674 CHECK_FLAG (lsa
->flag
, OSPF6_LSA_IMPLIEDACK
))
677 zlog_debug ("No acknowledgement (AllOther & Duplicate & ImpliedAck)");
681 /* LSA is a duplicate, and was not treated as an implied acknowledgement.
682 Direct acknowledgement sent */
683 if (CHECK_FLAG (lsa
->flag
, OSPF6_LSA_DUPLICATE
) &&
684 ! CHECK_FLAG (lsa
->flag
, OSPF6_LSA_IMPLIEDACK
))
687 zlog_debug ("Direct acknowledgement (AllOther & Duplicate)");
688 ospf6_lsdb_add (ospf6_lsa_copy (lsa
), from
->lsack_list
);
689 thread_add_event(master
, ospf6_lsack_send_neighbor
, from
, 0,
690 &from
->thread_send_lsack
);
694 /* LSA's LS age is equal to Maxage, and there is no current instance
695 of the LSA in the link state database, and none of router's
696 neighbors are in states Exchange or Loading */
697 /* Direct acknowledgement sent, but this case is handled in
698 early of ospf6_receive_lsa () */
702 ospf6_acknowledge_lsa (struct ospf6_lsa
*lsa
, int ismore_recent
,
703 struct ospf6_neighbor
*from
)
705 struct ospf6_interface
*oi
;
707 assert (from
&& from
->ospf6_if
);
710 if (oi
->state
== OSPF6_INTERFACE_BDR
)
711 ospf6_acknowledge_lsa_bdrouter (lsa
, ismore_recent
, from
);
713 ospf6_acknowledge_lsa_allother (lsa
, ismore_recent
, from
);
716 /* RFC2328 section 13 (4):
717 if MaxAge LSA and if we have no instance, and no neighbor
718 is in states Exchange or Loading
719 returns 1 if match this case, else returns 0 */
721 ospf6_is_maxage_lsa_drop (struct ospf6_lsa
*lsa
, struct ospf6_neighbor
*from
)
723 struct ospf6_neighbor
*on
;
724 struct ospf6_interface
*oi
;
725 struct ospf6_area
*oa
;
726 struct ospf6
*process
= NULL
;
727 struct listnode
*i
, *j
, *k
;
730 if (! OSPF6_LSA_IS_MAXAGE (lsa
))
733 if (ospf6_lsdb_lookup (lsa
->header
->type
, lsa
->header
->id
,
734 lsa
->header
->adv_router
, lsa
->lsdb
))
737 process
= from
->ospf6_if
->area
->ospf6
;
739 for (ALL_LIST_ELEMENTS_RO (process
->area_list
, i
, oa
))
740 for (ALL_LIST_ELEMENTS_RO (oa
->if_list
, j
, oi
))
741 for (ALL_LIST_ELEMENTS_RO (oi
->neighbor_list
, k
, on
))
742 if (on
->state
== OSPF6_NEIGHBOR_EXCHANGE
||
743 on
->state
== OSPF6_NEIGHBOR_LOADING
)
751 /* RFC2328 section 13 The Flooding Procedure */
753 ospf6_receive_lsa (struct ospf6_neighbor
*from
,
754 struct ospf6_lsa_header
*lsa_header
)
756 struct ospf6_lsa
*new = NULL
, *old
= NULL
, *rem
= NULL
;
759 unsigned int time_delta_ms
;
764 /* make lsa structure for received lsa */
765 new = ospf6_lsa_create (lsa_header
);
767 if (IS_OSPF6_DEBUG_FLOODING
||
768 IS_OSPF6_DEBUG_FLOOD_TYPE (new->header
->type
))
771 zlog_debug ("LSA Receive from %s", from
->name
);
772 ospf6_lsa_header_print (new);
775 /* (1) LSA Checksum */
776 if (! ospf6_lsa_checksum_valid (new->header
))
779 zlog_debug ("Wrong LSA Checksum, discard");
780 ospf6_lsa_delete (new);
784 /* (2) Examine the LSA's LS type.
785 RFC2470 3.5.1. Receiving Link State Update packets */
786 if (IS_AREA_STUB (from
->ospf6_if
->area
) &&
787 OSPF6_LSA_SCOPE (new->header
->type
) == OSPF6_SCOPE_AS
)
790 zlog_debug ("AS-External-LSA (or AS-scope LSA) in stub area, discard");
791 ospf6_lsa_delete (new);
795 /* (3) LSA which have reserved scope is discarded
796 RFC2470 3.5.1. Receiving Link State Update packets */
797 /* Flooding scope check. LSAs with unknown scope are discarded here.
798 Set appropriate LSDB for the LSA */
799 switch (OSPF6_LSA_SCOPE (new->header
->type
))
801 case OSPF6_SCOPE_LINKLOCAL
:
802 new->lsdb
= from
->ospf6_if
->lsdb
;
804 case OSPF6_SCOPE_AREA
:
805 new->lsdb
= from
->ospf6_if
->area
->lsdb
;
808 new->lsdb
= from
->ospf6_if
->area
->ospf6
->lsdb
;
812 zlog_debug ("LSA has reserved scope, discard");
813 ospf6_lsa_delete (new);
817 /* (4) if MaxAge LSA and if we have no instance, and no neighbor
818 is in states Exchange or Loading */
819 if (ospf6_is_maxage_lsa_drop (new, from
))
823 zlog_debug ("Drop MaxAge LSA with direct acknowledgement.");
825 /* a) Acknowledge back to neighbor (Direct acknowledgement, 13.5) */
826 ospf6_lsdb_add (ospf6_lsa_copy (new), from
->lsack_list
);
827 thread_add_event(master
, ospf6_lsack_send_neighbor
, from
, 0,
828 &from
->thread_send_lsack
);
831 ospf6_lsa_delete (new);
836 /* lookup the same database copy in lsdb */
837 old
= ospf6_lsdb_lookup (new->header
->type
, new->header
->id
,
838 new->header
->adv_router
, new->lsdb
);
841 ismore_recent
= ospf6_lsa_compare (new, old
);
842 if (ntohl (new->header
->seqnum
) == ntohl (old
->header
->seqnum
))
845 zlog_debug ("Received is duplicated LSA");
846 SET_FLAG (new->flag
, OSPF6_LSA_DUPLICATE
);
850 /* if no database copy or received is more recent */
851 if (old
== NULL
|| ismore_recent
< 0)
853 /* in case we have no database copy */
856 /* (a) MinLSArrival check */
859 struct timeval now
, res
;
861 timersub (&now
, &old
->installed
, &res
);
862 time_delta_ms
= (res
.tv_sec
* 1000) + (int)(res
.tv_usec
/1000);
863 if (time_delta_ms
< from
->ospf6_if
->area
->ospf6
->lsa_minarrival
)
866 zlog_debug ("LSA can't be updated within MinLSArrival, %dms < %dms, discard",
867 time_delta_ms
, from
->ospf6_if
->area
->ospf6
->lsa_minarrival
);
868 ospf6_lsa_delete (new);
869 return; /* examin next lsa */
873 monotime(&new->received
);
876 zlog_debug ("Install, Flood, Possibly acknowledge the received LSA");
878 /* Remove older copies of this LSA from retx lists */
880 ospf6_flood_clear (old
);
882 /* (b) immediately flood and (c) remove from all retrans-list */
883 /* Prevent self-originated LSA to be flooded. this is to make
884 reoriginated instance of the LSA not to be rejected by other routers
885 due to MinLSArrival. */
886 if (new->header
->adv_router
!= from
->ospf6_if
->area
->ospf6
->router_id
)
887 ospf6_flood (from
, new);
889 /* (d), installing lsdb, which may cause routing
890 table calculation (replacing database copy) */
891 ospf6_install_lsa (new);
893 if (OSPF6_LSA_IS_MAXAGE (new))
894 ospf6_maxage_remove (from
->ospf6_if
->area
->ospf6
);
896 /* (e) possibly acknowledge */
897 ospf6_acknowledge_lsa (new, ismore_recent
, from
);
899 /* (f) Self Originated LSA, section 13.4 */
900 if (new->header
->adv_router
== from
->ospf6_if
->area
->ospf6
->router_id
)
902 /* Self-originated LSA (newer than ours) is received from
903 another router. We have to make a new instance of the LSA
904 or have to flush this LSA. */
907 zlog_debug ("Newer instance of the self-originated LSA");
908 zlog_debug ("Schedule reorigination");
911 thread_add_event(master
, ospf6_lsa_refresh
, new, 0, &new->refresh
);
917 /* (6) if there is instance on sending neighbor's request list */
918 if (ospf6_lsdb_lookup (new->header
->type
, new->header
->id
,
919 new->header
->adv_router
, from
->request_list
))
921 /* if no database copy, should go above state (5) */
926 zlog_debug ("Received is not newer, on the neighbor's request-list");
927 zlog_debug ("BadLSReq, discard the received LSA");
931 thread_add_event(master
, bad_lsreq
, from
, 0, NULL
);
933 ospf6_lsa_delete (new);
937 /* (7) if neither one is more recent */
938 if (ismore_recent
== 0)
941 zlog_debug ("The same instance as database copy (neither recent)");
943 /* (a) if on retrans-list, Treat this LSA as an Ack: Implied Ack */
944 rem
= ospf6_lsdb_lookup (new->header
->type
, new->header
->id
,
945 new->header
->adv_router
, from
->retrans_list
);
950 zlog_debug ("It is on the neighbor's retrans-list.");
951 zlog_debug ("Treat as an Implied acknowledgement");
953 SET_FLAG (new->flag
, OSPF6_LSA_IMPLIEDACK
);
954 ospf6_decrement_retrans_count (rem
);
955 ospf6_lsdb_remove (rem
, from
->retrans_list
);
959 zlog_debug ("Possibly acknowledge and then discard");
961 /* (b) possibly acknowledge */
962 ospf6_acknowledge_lsa (new, ismore_recent
, from
);
964 ospf6_lsa_delete (new);
968 /* (8) previous database copy is more recent */
972 /* If database copy is in 'Seqnumber Wrapping',
973 simply discard the received LSA */
974 if (OSPF6_LSA_IS_MAXAGE (old
) &&
975 old
->header
->seqnum
== htonl (OSPF_MAX_SEQUENCE_NUMBER
))
979 zlog_debug ("The LSA is in Seqnumber Wrapping");
980 zlog_debug ("MaxAge & MaxSeqNum, discard");
982 ospf6_lsa_delete (new);
986 /* Otherwise, Send database copy of this LSA to this neighbor */
990 zlog_debug ("Database copy is more recent.");
991 zlog_debug ("Send back directly and then discard");
994 /* XXX, MinLSArrival check !? RFC 2328 13 (8) */
996 ospf6_lsdb_add (ospf6_lsa_copy (old
), from
->lsupdate_list
);
997 thread_add_event(master
, ospf6_lsupdate_send_neighbor
, from
, 0,
998 &from
->thread_send_lsupdate
);
999 ospf6_lsa_delete (new);
1007 DEFUN (debug_ospf6_flooding
,
1008 debug_ospf6_flooding_cmd
,
1009 "debug ospf6 flooding",
1012 "Debug OSPFv3 flooding function\n"
1015 OSPF6_DEBUG_FLOODING_ON ();
1019 DEFUN (no_debug_ospf6_flooding
,
1020 no_debug_ospf6_flooding_cmd
,
1021 "no debug ospf6 flooding",
1025 "Debug OSPFv3 flooding function\n"
1028 OSPF6_DEBUG_FLOODING_OFF ();
1033 config_write_ospf6_debug_flood (struct vty
*vty
)
1035 if (IS_OSPF6_DEBUG_FLOODING
)
1036 vty_out (vty
, "debug ospf6 flooding%s", VNL
);
1041 install_element_ospf6_debug_flood (void)
1043 install_element (ENABLE_NODE
, &debug_ospf6_flooding_cmd
);
1044 install_element (ENABLE_NODE
, &no_debug_ospf6_flooding_cmd
);
1045 install_element (CONFIG_NODE
, &debug_ospf6_flooding_cmd
);
1046 install_element (CONFIG_NODE
, &no_debug_ospf6_flooding_cmd
);