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