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