Tomato 1.24
[tomato.git] / release / src / router / zebra / ospfd / ospf_flood.c
blob8ae1d14e89b509e76abe882815cdf1c02b41f54d
1 /*
2 * OSPF Flooding -- RFC2328 Section 13.
3 * Copyright (C) 1999, 2000 Toshiaki Takada
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.
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.
23 #include <zebra.h>
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"
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
55 * for speed. */
56 static void
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->status == ISM_Backup && ! NBR_IS_DR (inbr))
72 return;
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;
83 struct prefix_ipv4 p;
84 struct route_node *rn;
85 int type;
87 al = (struct as_external_lsa *) lsa->data;
89 p.family = AF_INET;
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);
101 if (rn != NULL)
103 route_unlock_node (rn);
104 if (rn->info != NULL)
105 return (struct external_info *) rn->info;
110 return NULL;
113 void
114 ospf_process_self_originated_lsa (struct ospf_lsa *new, struct ospf_area *area)
116 struct network_lsa *nlsa;
117 listnode node;
118 struct ospf_interface *oi;
119 struct external_info *ei;
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));
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)
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);
139 ospf_router_lsa_timer_add (area);
140 return;
141 case OSPF_NETWORK_LSA:
142 /* We must find the interface the LSA could belong to.
143 If the interface is no more a broadcast type or we are no more
144 the DR, we flush the LSA otherwise -- create the new instance and
145 schedule flooding. */
146 nlsa = (struct network_lsa *) new->data;
148 /* Look through all interfaces, not just area, since interface
149 could be moved from one area to another. */
150 for (node = listhead (ospf_top->oiflist); node; nextnode (node))
151 /* These are sanity check. */
152 if ((oi = getdata (node)) != NULL)
153 if (IPV4_ADDR_SAME (&oi->address->u.prefix4, &new->data->id))
155 if (oi->area != area ||
156 oi->type != OSPF_IFTYPE_BROADCAST ||
157 !IPV4_ADDR_SAME (&oi->address->u.prefix4, &DR (oi)))
159 ospf_schedule_lsa_flush_area (area, new);
160 return;
163 ospf_lsa_unlock (oi->network_lsa_self);
164 oi->network_lsa_self = ospf_lsa_lock (new);
166 /* Schedule network-LSA origination. */
167 ospf_network_lsa_timer_add (oi);
168 return;
170 case OSPF_SUMMARY_LSA:
171 case OSPF_SUMMARY_LSA_ASBR:
172 ospf_schedule_abr_task ();
173 break;
174 case OSPF_AS_EXTERNAL_LSA :
175 #ifdef HAVE_NSSA
176 case OSPF_AS_NSSA_LSA:
177 #endif /* HAVE_NSSA */
178 ei = ospf_external_info_check (new);
179 if (ei)
180 ospf_external_lsa_refresh (new, ei, LSA_REFRESH_FORCE);
181 else
182 ospf_lsa_flush_as (new);
183 break;
184 default:
185 break;
189 /* OSPF LSA flooding -- RFC2328 Section 13.(5). */
191 /* Now Updated for NSSA operation, as follows:
194 Type-5's have no change. Blocked to STUB or NSSA.
196 Type-7's can be received, and if a DR
197 they will also flood the local NSSA Area as Type-7's
199 If a Self-Originated LSA (now an ASBR),
200 The LSDB will be updated as Type-5's, (for continual re-fresh)
202 If an NSSA-IR it is installed/flooded as Type-7, P-bit on.
203 if an NSSA-ABR it is installed/flooded as Type-7, P-bit off.
205 Later, during the ABR TASK, if the ABR is the Elected NSSA
206 translator, then All Type-7s (with P-bit ON) are Translated to
207 Type-5's and flooded to all non-NSSA/STUB areas.
209 During ASE Calculations,
210 non-ABRs calculate external routes from Type-7's
211 ABRs calculate external routes from Type-5's and non-self Type-7s
214 ospf_flood (struct ospf_neighbor *nbr, struct ospf_lsa *current,
215 struct ospf_lsa *new)
217 struct ospf_interface *oi;
218 struct timeval now;
219 int lsa_ack_flag;
221 /* Type-7 LSA's will be flooded throughout their native NSSA area,
222 but will also be flooded as Type-5's into ABR capable links. */
224 if (IS_DEBUG_OSPF_EVENT)
225 zlog_info ("LSA[Flooding]: start");
227 lsa_ack_flag = 0;
228 oi = nbr->oi;
230 /* Get current time. */
231 gettimeofday (&now, NULL);
233 /* If there is already a database copy, and if the
234 database copy was received via flooding and installed less
235 than MinLSArrival seconds ago, discard the new LSA
236 (without acknowledging it). */
237 /* if (current && (ts - current->tv_recv) < OSPF_MIN_LS_ARRIVAL) */
238 if (current != NULL &&
239 tv_cmp (tv_sub (now, current->tv_recv),
240 int2tv (OSPF_MIN_LS_ARRIVAL)) < 0)
242 if (IS_DEBUG_OSPF_EVENT)
243 zlog_info ("LSA[Flooding]: LSA is received recently.");
244 return -1;
247 /* Flood the new LSA out some subset of the router's interfaces.
248 In some cases (e.g., the state of the receiving interface is
249 DR and the LSA was received from a router other than the
250 Backup DR) the LSA will be flooded back out the receiving
251 interface. */
252 lsa_ack_flag = ospf_flood_through (nbr, new);
254 /* Remove the current database copy from all neighbors' Link state
255 retransmission lists. Only AS_EXTERNAL does not have area ID.
256 All other (even NSSA's) do have area ID. */
257 if (current)
259 if (current->data->type != OSPF_AS_EXTERNAL_LSA)
260 ospf_ls_retransmit_delete_nbr_all (nbr->oi->area, current);
261 else
262 ospf_ls_retransmit_delete_nbr_all (NULL, current);
265 /* Do some internal house keeping that is needed here */
266 SET_FLAG (new->flags, OSPF_LSA_RECEIVED);
267 ospf_lsa_is_self_originated (new); /* Let it set the flag */
269 /* Install the new LSA in the link state database
270 (replacing the current database copy). This may cause the
271 routing table calculation to be scheduled. In addition,
272 timestamp the new LSA with the current time. The flooding
273 procedure cannot overwrite the newly installed LSA until
274 MinLSArrival seconds have elapsed. */
276 new = ospf_lsa_install (nbr->oi, new);
278 #ifdef HAVE_NSSA
279 if (IS_DEBUG_OSPF_NSSA)
280 zlog_info ("LSA[Flooding]: Type-%d installed", new->data->type);
282 /* if (new->data->type == OSPF_AS_NSSA_LSA )
283 return 0; */
284 #endif /* HAVE_NSSA */
286 /* Acknowledge the receipt of the LSA by sending a Link State
287 Acknowledgment packet back out the receiving interface. */
288 if (lsa_ack_flag)
289 ospf_flood_delayed_lsa_ack (nbr, new);
291 /* If this new LSA indicates that it was originated by the
292 receiving router itself, the router must take special action,
293 either updating the LSA or in some cases flushing it from
294 the routing domain. */
295 if (ospf_lsa_is_self_originated (new))
296 ospf_process_self_originated_lsa (new, oi->area);
297 else
298 /* Update statistics value for OSPF-MIB. */
299 ospf_top->rx_lsa_count++;
301 return 0;
304 /* OSPF LSA flooding -- RFC2328 Section 13.3. */
306 ospf_flood_through_interface (struct ospf_interface *oi,
307 struct ospf_neighbor *inbr,
308 struct ospf_lsa *lsa)
310 struct ospf_neighbor *onbr;
311 struct route_node *rn;
312 int retx_flag;
314 if (IS_DEBUG_OSPF_EVENT)
315 zlog_info ("ospf_flood_through_interface(): considering int %s",
316 IF_NAME (oi));
318 if (!ospf_if_is_enable (oi))
319 return 0;
321 /* Remember if new LSA is aded to a retransmit list. */
322 retx_flag = 0;
324 /* Each of the neighbors attached to this interface are examined,
325 to determine whether they must receive the new LSA. The following
326 steps are executed for each neighbor: */
327 for (rn = route_top (oi->nbrs); rn; rn = route_next (rn))
329 struct ospf_lsa *ls_req;
331 if (rn->info == NULL)
332 continue;
334 onbr = rn->info;
335 if (IS_DEBUG_OSPF_EVENT)
336 zlog_info ("ospf_flood_through_interface(): considering nbr %s",
337 inet_ntoa (onbr->router_id));
339 /* If the neighbor is in a lesser state than Exchange, it
340 does not participate in flooding, and the next neighbor
341 should be examined. */
342 if (onbr->status < NSM_Exchange)
343 continue;
345 /* If the adjacency is not yet full (neighbor state is
346 Exchange or Loading), examine the Link state request
347 list associated with this adjacency. If there is an
348 instance of the new LSA on the list, it indicates that
349 the neighboring router has an instance of the LSA
350 already. Compare the new LSA to the neighbor's copy: */
351 if (onbr->status < NSM_Full)
353 if (IS_DEBUG_OSPF_EVENT)
354 zlog_info ("ospf_flood_through_interface(): nbr adj is not Full");
355 ls_req = ospf_ls_request_lookup (onbr, lsa);
356 if (ls_req != NULL)
358 int ret;
360 ret = ospf_lsa_more_recent (ls_req, lsa);
361 /* The new LSA is less recent. */
362 if (ret > 0)
363 continue;
364 /* The two copies are the same instance, then delete
365 the LSA from the Link state request list. */
366 else if (ret == 0)
368 ospf_ls_request_delete (onbr, ls_req);
369 ospf_check_nbr_loading (onbr);
370 continue;
372 /* The new LSA is more recent. Delete the LSA
373 from the Link state request list. */
374 else
376 ospf_ls_request_delete (onbr, ls_req);
377 ospf_check_nbr_loading (onbr);
382 /* If the new LSA was received from this neighbor,
383 examine the next neighbor. */
384 if (inbr)
385 if (IPV4_ADDR_SAME (&inbr->router_id, &onbr->router_id))
386 continue;
388 /* Add the new LSA to the Link state retransmission list
389 for the adjacency. The LSA will be retransmitted
390 at intervals until an acknowledgment is seen from
391 the neighbor. */
392 ospf_ls_retransmit_add (onbr, lsa);
393 retx_flag = 1;
396 /* If in the previous step, the LSA was NOT added to any of
397 the Link state retransmission lists, there is no need to
398 flood the LSA out the interface. */
399 if (retx_flag == 0)
401 return (inbr && inbr->oi == oi);
404 /* if we've received the lsa on this interface we need to perform
405 additional checking */
406 if (inbr && (inbr->oi == oi))
408 /* If the new LSA was received on this interface, and it was
409 received from either the Designated Router or the Backup
410 Designated Router, chances are that all the neighbors have
411 received the LSA already. */
412 if (NBR_IS_DR (inbr) || NBR_IS_BDR (inbr))
414 #ifdef HAVE_NSSA
415 if (IS_DEBUG_OSPF_NSSA)
416 zlog_info ("ospf_flood_through_interface(): "
417 "DR/BDR NOT SEND to int %s", IF_NAME (oi));
418 #endif /* HAVE_NSSA */
419 return 1;
422 /* If the new LSA was received on this interface, and the
423 interface state is Backup, examine the next interface. The
424 Designated Router will do the flooding on this interface.
425 However, if the Designated Router fails the router will
426 end up retransmitting the updates. */
428 if (oi->status == ISM_Backup)
430 #ifdef HAVE_NSSA
431 if (IS_DEBUG_OSPF_NSSA)
432 zlog_info ("ospf_flood_through_interface(): "
433 "ISM_Backup NOT SEND to int %s", IF_NAME (oi));
434 #endif /* HAVE_NSSA */
435 return 1;
439 /* The LSA must be flooded out the interface. Send a Link State
440 Update packet (including the new LSA as contents) out the
441 interface. The LSA's LS age must be incremented by InfTransDelay
442 (which must be > 0) when it is copied into the outgoing Link
443 State Update packet (until the LS age field reaches the maximum
444 value of MaxAge). */
446 #ifdef HAVE_NSSA
447 if (IS_DEBUG_OSPF_NSSA)
448 zlog_info ("ospf_flood_through_interface(): "
449 "DR/BDR sending upd to int %s", IF_NAME (oi));
450 #else /* ! HAVE_NSSA */
452 if (IS_DEBUG_OSPF_EVENT)
453 zlog_info ("ospf_flood_through_interface(): "
454 "sending upd to int %s", IF_NAME (oi));
455 #endif /* HAVE_NSSA */
457 /* RFC2328 Section 13.3
458 On non-broadcast networks, separate Link State Update
459 packets must be sent, as unicasts, to each adjacent neighbor
460 (i.e., those in state Exchange or greater). The destination
461 IP addresses for these packets are the neighbors' IP
462 addresses. */
463 if (oi->type == OSPF_IFTYPE_NBMA)
465 struct route_node *rn;
466 struct ospf_neighbor *nbr;
468 for (rn = route_top (oi->nbrs); rn; rn = route_next (rn))
469 if ((nbr = rn->info) != NULL)
470 if (nbr != oi->nbr_self && nbr->status >= NSM_Exchange)
471 ospf_ls_upd_send_lsa (nbr, lsa, OSPF_SEND_PACKET_DIRECT);
473 else
474 ospf_ls_upd_send_lsa (oi->nbr_self, lsa, OSPF_SEND_PACKET_INDIRECT);
476 return 0;
480 ospf_flood_through_area (struct ospf_area * area,struct ospf_neighbor *inbr,
481 struct ospf_lsa *lsa)
483 listnode node;
484 int lsa_ack_flag = 0;
486 /* All other types are specific to a single area (Area A). The
487 eligible interfaces are all those interfaces attaching to the
488 Area A. If Area A is the backbone, this includes all the virtual
489 links. */
490 for (node = listhead (area->oiflist); node; nextnode (node))
492 struct ospf_interface *oi = getdata (node);
494 if (area->area_id.s_addr != OSPF_AREA_BACKBONE &&
495 oi->type == OSPF_IFTYPE_VIRTUALLINK)
496 continue;
498 if (ospf_flood_through_interface (oi, inbr, lsa))
499 lsa_ack_flag = 1;
502 return (lsa_ack_flag);
506 ospf_flood_through_as (struct ospf_neighbor *inbr, struct ospf_lsa *lsa)
508 listnode node;
509 int lsa_ack_flag;
511 lsa_ack_flag = 0;
513 /* The incoming LSA is type 5 or type 7 (AS-EXTERNAL or AS-NSSA )
515 Divert the Type-5 LSA's to all non-NSSA/STUB areas
517 Divert the Type-7 LSA's to all NSSA areas
519 AS-external-LSAs are flooded throughout the entire AS, with the
520 exception of stub areas (see Section 3.6). The eligible
521 interfaces are all the router's interfaces, excluding virtual
522 links and those interfaces attaching to stub areas. */
524 #ifdef HAVE_NSSA
525 if (CHECK_FLAG (lsa->flags, OSPF_LSA_LOCAL_XLT)) /* Translated from 7 */
526 if (IS_DEBUG_OSPF_NSSA)
527 zlog_info ("Flood/AS: NSSA TRANSLATED LSA");
528 #endif /* HAVE_NSSA */
530 for (node = listhead (ospf_top->areas); node; nextnode (node))
532 int continue_flag = 0;
533 struct ospf_area *area = getdata (node);
534 listnode if_node;
536 switch (area->external_routing)
538 /* Don't send AS externals into stub areas. Various types
539 of support for partial stub areas can be implemented
540 here. NSSA's will receive Type-7's that have areas
541 matching the originl LSA. */
542 case OSPF_AREA_NSSA: /* Sending Type 5 or 7 into NSSA area */
543 #ifdef HAVE_NSSA
544 /* Type-7, flood NSSA area */
545 if (lsa->data->type == OSPF_AS_NSSA_LSA)
546 /* We will send it. */
547 continue_flag = 0;
548 else
549 continue_flag = 1; /* Skip this NSSA area for Type-5's et al */
550 break;
551 #endif /* HAVE_NSSA */
553 case OSPF_AREA_TYPE_MAX:
554 case OSPF_AREA_STUB:
555 continue_flag = 1; /* Skip this area. */
556 break;
558 case OSPF_AREA_DEFAULT:
559 default:
560 #ifdef HAVE_NSSA
561 /* No Type-7 into normal area */
562 if (lsa->data->type == OSPF_AS_NSSA_LSA)
563 continue_flag = 1; /* skip Type-7 */
564 else
565 #endif /* HAVE_NSSA */
566 continue_flag = 0; /* Do this area. */
567 break;
570 /* Do continue for above switch. Saves a big if then mess */
571 if (continue_flag)
572 continue; /* main for-loop */
574 /* send to every interface in this area */
576 for (if_node = listhead (area->oiflist); if_node; nextnode (if_node))
578 struct ospf_interface *oi = getdata (if_node);
580 /* Skip virtual links */
581 if (oi->type != OSPF_IFTYPE_VIRTUALLINK)
582 if (ospf_flood_through_interface (oi, inbr, lsa)) /* lsa */
583 lsa_ack_flag = 1;
585 } /* main area for-loop */
587 return (lsa_ack_flag);
591 ospf_flood_through (struct ospf_neighbor *inbr, struct ospf_lsa *lsa)
593 int lsa_ack_flag = 0;
595 /* Type-7 LSA's for NSSA are flooded throughout the AS here, and
596 upon return are updated in the LSDB for Type-7's. Later,
597 re-fresh will re-send them (and also, if ABR, packet code will
598 translate to Type-5's)
600 As usual, Type-5 LSA's (if not DISCARDED because we are STUB or
601 NSSA) are flooded throughout the AS, and are updated in the
602 global table. */
603 switch (lsa->data->type)
605 case OSPF_ROUTER_LSA:
606 case OSPF_NETWORK_LSA:
607 case OSPF_SUMMARY_LSA:
608 case OSPF_SUMMARY_LSA_ASBR:
609 lsa_ack_flag = ospf_flood_through_area (inbr->oi->area, inbr, lsa);
610 break;
611 case OSPF_AS_EXTERNAL_LSA: /* Type-5 */
612 lsa_ack_flag = ospf_flood_through_as (inbr, lsa);
613 break;
614 #ifdef HAVE_NSSA
615 /* Type-7 Only received within NSSA, then flooded */
616 case OSPF_AS_NSSA_LSA:
617 /* Any P-bit was installed with the Type-7. */
618 lsa_ack_flag = ospf_flood_through_area (inbr->oi->area, inbr, lsa);
620 if (IS_DEBUG_OSPF_NSSA)
621 zlog_info ("ospf_flood_through: LOCAL NSSA FLOOD of Type-7.");
622 break;
623 #endif /* HAVE_NSSA */
624 default:
625 break;
628 return (lsa_ack_flag);
632 /* Management functions for neighbor's Link State Request list. */
633 void
634 ospf_ls_request_add (struct ospf_neighbor *nbr, struct ospf_lsa *lsa)
636 ospf_lsdb_add (&nbr->ls_req, lsa);
639 unsigned long
640 ospf_ls_request_count (struct ospf_neighbor *nbr)
642 return ospf_lsdb_count_all (&nbr->ls_req);
646 ospf_ls_request_isempty (struct ospf_neighbor *nbr)
648 return ospf_lsdb_isempty (&nbr->ls_req);
651 /* Remove LSA from neighbor's ls-request list. */
652 void
653 ospf_ls_request_delete (struct ospf_neighbor *nbr, struct ospf_lsa *lsa)
655 if (nbr->ls_req_last == lsa)
657 ospf_lsa_unlock (nbr->ls_req_last);
658 nbr->ls_req_last = NULL;
660 ospf_lsdb_delete (&nbr->ls_req, lsa);
663 /* Remove all LSA from neighbor's ls-requenst list. */
664 void
665 ospf_ls_request_delete_all (struct ospf_neighbor *nbr)
667 ospf_lsa_unlock (nbr->ls_req_last);
668 nbr->ls_req_last = NULL;
669 ospf_lsdb_delete_all (&nbr->ls_req);
672 /* Lookup LSA from neighbor's ls-request list. */
673 struct ospf_lsa *
674 ospf_ls_request_lookup (struct ospf_neighbor *nbr, struct ospf_lsa *lsa)
676 return ospf_lsdb_lookup (&nbr->ls_req, lsa);
679 struct ospf_lsa *
680 ospf_ls_request_new (struct lsa_header *lsah)
682 struct ospf_lsa *new;
684 new = ospf_lsa_new ();
685 new->data = ospf_lsa_data_new (OSPF_LSA_HEADER_SIZE);
686 memcpy (new->data, lsah, OSPF_LSA_HEADER_SIZE);
688 return new;
692 /* Management functions for neighbor's ls-retransmit list. */
693 unsigned long
694 ospf_ls_retransmit_count (struct ospf_neighbor *nbr)
696 return ospf_lsdb_count_all (&nbr->ls_rxmt);
700 ospf_ls_retransmit_isempty (struct ospf_neighbor *nbr)
702 return ospf_lsdb_isempty (&nbr->ls_rxmt);
705 /* Add LSA to be retransmitted to neighbor's ls-retransmit list. */
706 void
707 ospf_ls_retransmit_add (struct ospf_neighbor *nbr, struct ospf_lsa *lsa)
709 struct ospf_lsa *old;
711 old = ospf_ls_retransmit_lookup (nbr, lsa);
713 if (ospf_lsa_more_recent (old, lsa) < 0)
715 if (old)
717 old->retransmit_counter--;
718 ospf_lsdb_delete (&nbr->ls_rxmt, old);
720 lsa->retransmit_counter++;
721 ospf_lsdb_add (&nbr->ls_rxmt, lsa);
724 if (!ospf_ls_retransmit_lookup (nbr, lsa))
726 lsa->retransmit_counter++;
727 ospf_lsdb_add (&nbr->ls_rxmt, lsa);
732 /* Remove LSA from neibghbor's ls-retransmit list. */
733 void
734 ospf_ls_retransmit_delete (struct ospf_neighbor *nbr, struct ospf_lsa *lsa)
736 if (ospf_ls_retransmit_lookup (nbr, lsa))
738 lsa->retransmit_counter--;
739 ospf_lsdb_delete (&nbr->ls_rxmt, lsa);
743 /* Clear neighbor's ls-retransmit list. */
744 void
745 ospf_ls_retransmit_clear (struct ospf_neighbor *nbr)
747 struct ospf_lsdb *lsdb;
748 int i;
750 lsdb = &nbr->ls_rxmt;
752 for (i = OSPF_MIN_LSA; i < OSPF_MAX_LSA; i++)
754 struct route_table *table = lsdb->type[i].db;
755 struct route_node *rn;
756 struct ospf_lsa *lsa;
758 for (rn = route_top (table); rn; rn = route_next (rn))
759 if ((lsa = rn->info) != NULL)
760 ospf_ls_retransmit_delete (nbr, lsa);
763 ospf_lsa_unlock (nbr->ls_req_last);
764 nbr->ls_req_last = NULL;
767 /* Lookup LSA from neighbor's ls-retransmit list. */
768 struct ospf_lsa *
769 ospf_ls_retransmit_lookup (struct ospf_neighbor *nbr, struct ospf_lsa *lsa)
771 return ospf_lsdb_lookup (&nbr->ls_rxmt, lsa);
774 /* Remove All neighbor/interface's Link State Retransmit list in area. */
775 void
776 ospf_ls_retransmit_delete_nbr_all (struct ospf_area *area,
777 struct ospf_lsa *lsa)
779 listnode node;
780 list oiflist = area ? area->oiflist : ospf_top->oiflist;
782 for (node = listhead (oiflist); node; nextnode (node))
784 struct ospf_interface *oi = getdata (node);
785 struct route_node *rn;
786 struct ospf_neighbor *nbr;
787 struct ospf_lsa *lsr;
789 if (ospf_if_is_enable (oi))
790 for (rn = route_top (oi->nbrs); rn; rn = route_next (rn))
791 /* If LSA find in LS-retransmit list, then remove it. */
792 if ((nbr = rn->info) != NULL)
794 lsr = ospf_ls_retransmit_lookup (nbr, lsa);
796 /* If LSA find in ls-retransmit list, remove it. */
797 if (lsr != NULL && lsr->data->ls_seqnum == lsa->data->ls_seqnum)
798 ospf_ls_retransmit_delete (nbr, lsr);
803 /* Add LSA to the current database copy of all neighbors'
804 Link state retransmission lists. */
805 void
806 ospf_ls_retransmit_add_nbr_all (struct ospf_interface *ospfi,
807 struct ospf_lsa *lsa)
809 listnode node;
811 for (node = listhead (ospf_top->oiflist); node; nextnode (node))
813 struct ospf_interface *oi = getdata (node);
814 struct route_node *rn;
815 struct ospf_neighbor *nbr;
816 struct ospf_lsa *old;
818 if (ospf_if_is_enable (oi))
819 if (OSPF_AREA_SAME (&ospfi->area, &oi->area))
820 for (rn = route_top (oi->nbrs); rn; rn = route_next (rn))
821 if ((nbr = rn->info) != NULL)
822 if (nbr->status == NSM_Full)
824 if ((old = ospf_ls_retransmit_lookup (nbr, lsa)))
825 ospf_ls_retransmit_delete (nbr, old);
827 ospf_ls_retransmit_add (nbr, lsa);
833 /* Sets ls_age to MaxAge and floods throu the area.
834 When we implement ASE routing, there will be anothe function
835 flushing an LSA from the whole domain. */
836 void
837 ospf_lsa_flush_area (struct ospf_lsa *lsa, struct ospf_area *area)
839 lsa->data->ls_age = htons (OSPF_LSA_MAXAGE);
840 ospf_flood_through_area (area, NULL, lsa);
841 ospf_lsa_maxage (lsa);
844 void
845 ospf_lsa_flush_as (struct ospf_lsa *lsa)
847 lsa->data->ls_age = htons (OSPF_LSA_MAXAGE);
848 ospf_flood_through_as (NULL, lsa);
849 ospf_lsa_maxage (lsa);
852 /* Flush LSA through AS -- used for AS-external-LSAs. */
853 void
854 ospf_flush_through_as (struct ospf_lsa *lsa)
856 lsa->data->ls_age = htons (OSPF_LSA_MAXAGE);
857 ospf_flood_through_as (NULL, lsa);
858 ospf_lsa_maxage (lsa);