]> git.proxmox.com Git - mirror_frr.git/blame - ospfd/ospf_flood.c
Merge pull request #4743 from opensourcerouting/7.1/ospfd-default-originate
[mirror_frr.git] / ospfd / ospf_flood.c
CommitLineData
718e3744 1/*
2 * OSPF Flooding -- RFC2328 Section 13.
3 * Copyright (C) 1999, 2000 Toshiaki Takada
4 *
5 * This file is part of GNU Zebra.
896014f4 6 *
718e3744 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 *
896014f4
DL
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
718e3744 20 */
21
22#include <zebra.h>
23
cbf3e3eb 24#include "monotime.h"
718e3744 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
51extern struct zclient *zclient;
6b0655a2 52
718e3744 53/* Do the LSA acking specified in table 19, Section 13.5, row 2
d62a17ae 54 * This get called from ospf_flood_out_interface. Declared inline
718e3744 55 * for speed. */
d62a17ae 56static void ospf_flood_delayed_lsa_ack(struct ospf_neighbor *inbr,
57 struct ospf_lsa *lsa)
718e3744 58{
d62a17ae 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 */
718e3744 77}
78
79/* Check LSA is related to external info. */
b5a8894d
CS
80struct external_info *ospf_external_info_check(struct ospf *ospf,
81 struct ospf_lsa *lsa)
718e3744 82{
d62a17ae 83 struct as_external_lsa *al;
84 struct prefix_ipv4 p;
85 struct route_node *rn;
5353782f
DL
86 struct list *ext_list;
87 struct listnode *node;
88 struct ospf_external *ext;
d62a17ae 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
d1ba29e8 97 for (type = 0; type < ZEBRA_ROUTE_MAX; type++) {
d62a17ae 98 int redist_on = 0;
99
100 redist_on =
101 is_prefix_default(&p)
49db7a7b
RW
102 ? vrf_bitmap_check(
103 zclient->default_information[AFI_IP],
104 ospf->vrf_id)
d62a17ae 105 : (zclient->mi_redist[AFI_IP][type].enabled
106 || vrf_bitmap_check(
107 zclient->redist[AFI_IP][type],
b5a8894d 108 ospf->vrf_id));
d62a17ae 109 // Pending: check for MI above.
110 if (redist_on) {
de1ac5fd 111 ext_list = ospf->external[type];
d62a17ae 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
5353782f
DL
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 }
d62a17ae 147 return NULL;
718e3744 148}
149
d62a17ae 150static void ospf_process_self_originated_lsa(struct ospf *ospf,
151 struct ospf_lsa *new,
152 struct ospf_area *area)
718e3744 153{
d62a17ae 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 "LSA[Type%d:%s]: Process self-originated LSA seq 0x%x",
161 new->data->type, inet_ntoa(new->data->id),
162 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 }
b5a8894d 225 ei = ospf_external_info_check(ospf, new);
d62a17ae 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);
996c9314 237 /* Reconsideration may needed. */ /* XXX */
d62a17ae 238 break;
239 default:
240 break;
241 }
718e3744 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
d62a17ae 254 If a Self-Originated LSA (now an ASBR),
718e3744 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
d62a17ae 264 During ASE Calculations,
718e3744 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*/
d62a17ae 268int ospf_flood(struct ospf *ospf, struct ospf_neighbor *nbr,
269 struct ospf_lsa *current, struct ospf_lsa *new)
718e3744 270{
d62a17ae 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 "LSA[Flooding]: start, NBR %s (%s), cur(%p), New-LSA[%s]",
280 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 "LSA[Flooding]: Got a self-originated LSA, "
299 "while local one is initial instance.");
300 ; /* Accept this LSA for quick LSDB resynchronization.
9d303b37 301 */
d62a17ae 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 "LSA[Flooding]: LSA is received recently.");
307 return -1;
308 }
309 }
310
311 /* Flood the new LSA out some subset of the router's interfaces.
312 In some cases (e.g., the state of the receiving interface is
313 DR and the LSA was received from a router other than the
314 Backup DR) the LSA will be flooded back out the receiving
315 interface. */
316 lsa_ack_flag = ospf_flood_through(ospf, nbr, new);
317
318 /* Remove the current database copy from all neighbors' Link state
319 retransmission lists. AS_EXTERNAL and AS_EXTERNAL_OPAQUE does
320 ^^^^^^^^^^^^^^^^^^^^^^^
321 not have area ID.
322 All other (even NSSA's) do have area ID. */
323 if (current) {
324 switch (current->data->type) {
325 case OSPF_AS_EXTERNAL_LSA:
326 case OSPF_OPAQUE_AS_LSA:
327 ospf_ls_retransmit_delete_nbr_as(ospf, current);
328 break;
329 default:
330 ospf_ls_retransmit_delete_nbr_area(nbr->oi->area,
331 current);
332 break;
333 }
334 }
335
336 /* Do some internal house keeping that is needed here */
337 SET_FLAG(new->flags, OSPF_LSA_RECEIVED);
752ee70b 338 (void)ospf_lsa_is_self_originated(ospf, new); /* Let it set the flag */
d62a17ae 339
340 /* Install the new LSA in the link state database
341 (replacing the current database copy). This may cause the
342 routing table calculation to be scheduled. In addition,
343 timestamp the new LSA with the current time. The flooding
344 procedure cannot overwrite the newly installed LSA until
345 MinLSArrival seconds have elapsed. */
346
347 if (!(new = ospf_lsa_install(ospf, nbr->oi, new)))
348 return -1; /* unknown LSA type or any other error condition */
349
350 /* Acknowledge the receipt of the LSA by sending a Link State
351 Acknowledgment packet back out the receiving interface. */
352 if (lsa_ack_flag)
353 ospf_flood_delayed_lsa_ack(nbr, new);
354
355 /* If this new LSA indicates that it was originated by the
356 receiving router itself, the router must take special action,
357 either updating the LSA or in some cases flushing it from
358 the routing domain. */
359 if (ospf_lsa_is_self_originated(ospf, new))
360 ospf_process_self_originated_lsa(ospf, new, oi->area);
361 else
362 /* Update statistics value for OSPF-MIB. */
363 ospf->rx_lsa_count++;
364
365 return 0;
718e3744 366}
367
368/* OSPF LSA flooding -- RFC2328 Section 13.3. */
d62a17ae 369static int ospf_flood_through_interface(struct ospf_interface *oi,
370 struct ospf_neighbor *inbr,
371 struct ospf_lsa *lsa)
718e3744 372{
d62a17ae 373 struct ospf_neighbor *onbr;
374 struct route_node *rn;
375 int retx_flag;
376
377 if (IS_DEBUG_OSPF_EVENT)
378 zlog_debug(
379 "ospf_flood_through_interface(): "
046460a1 380 "considering int %s, INBR(%s), LSA[%s] AGE %u",
d62a17ae 381 IF_NAME(oi), inbr ? inet_ntoa(inbr->router_id) : "NULL",
046460a1 382 dump_lsa_key(lsa), ntohs(lsa->data->ls_age));
d62a17ae 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)",
403 inet_ntoa(onbr->router_id),
404 lookup_msg(ospf_nsm_state_msg, onbr->state,
405 NULL));
406
407 /* If the neighbor is in a lesser state than Exchange, it
408 does not participate in flooding, and the next neighbor
409 should be examined. */
410 if (onbr->state < NSM_Exchange)
411 continue;
412
413 /* If the adjacency is not yet full (neighbor state is
414 Exchange or Loading), examine the Link state request
415 list associated with this adjacency. If there is an
416 instance of the new LSA on the list, it indicates that
417 the neighboring router has an instance of the LSA
418 already. Compare the new LSA to the neighbor's copy: */
419 if (onbr->state < NSM_Full) {
420 if (IS_DEBUG_OSPF_EVENT)
421 zlog_debug(
422 "ospf_flood_through_interface(): nbr adj is not Full");
423 ls_req = ospf_ls_request_lookup(onbr, lsa);
424 if (ls_req != NULL) {
425 int ret;
426
427 ret = ospf_lsa_more_recent(ls_req, lsa);
428 /* The new LSA is less recent. */
429 if (ret > 0)
430 continue;
431 /* The two copies are the same instance, then
432 delete
433 the LSA from the Link state request list. */
434 else if (ret == 0) {
435 ospf_ls_request_delete(onbr, ls_req);
436 ospf_check_nbr_loading(onbr);
437 continue;
438 }
439 /* The new LSA is more recent. Delete the LSA
440 from the Link state request list. */
441 else {
442 ospf_ls_request_delete(onbr, ls_req);
443 ospf_check_nbr_loading(onbr);
444 }
445 }
718e3744 446 }
d62a17ae 447
448 if (IS_OPAQUE_LSA(lsa->data->type)) {
449 if (!CHECK_FLAG(onbr->options, OSPF_OPTION_O)) {
450 if (IS_DEBUG_OSPF(lsa, LSA_FLOODING))
451 zlog_debug(
452 "Skip this neighbor: Not Opaque-capable.");
453 continue;
454 }
718e3744 455 }
718e3744 456
d62a17ae 457/* If the new LSA was received from this neighbor,
458 examine the next neighbor. */
718e3744 459#ifdef ORIGINAL_CODING
d62a17ae 460 if (inbr)
461 if (IPV4_ADDR_SAME(&inbr->router_id, &onbr->router_id))
462 continue;
463#else /* ORIGINAL_CODING */
464 if (inbr) {
465 /*
466 * Triggered by LSUpd message parser "ospf_ls_upd ()".
467 * E.g., all LSAs handling here is received via network.
468 */
469 if (IPV4_ADDR_SAME(&inbr->router_id,
470 &onbr->router_id)) {
471 if (IS_DEBUG_OSPF(lsa, LSA_FLOODING))
472 zlog_debug(
473 "Skip this neighbor: inbr == onbr");
474 continue;
475 }
476 } else {
477 /*
478 * Triggered by MaxAge remover, so far.
479 * NULL "inbr" means flooding starts from this node.
480 */
481 if (IPV4_ADDR_SAME(&lsa->data->adv_router,
482 &onbr->router_id)) {
483 if (IS_DEBUG_OSPF(lsa, LSA_FLOODING))
484 zlog_debug(
485 "Skip this neighbor: lsah->adv_router == onbr");
486 continue;
487 }
488 }
718e3744 489#endif /* ORIGINAL_CODING */
490
d62a17ae 491 /* Add the new LSA to the Link state retransmission list
492 for the adjacency. The LSA will be retransmitted
493 at intervals until an acknowledgment is seen from
494 the neighbor. */
495 ospf_ls_retransmit_add(onbr, lsa);
496 retx_flag = 1;
718e3744 497 }
d62a17ae 498
499 /* If in the previous step, the LSA was NOT added to any of
500 the Link state retransmission lists, there is no need to
501 flood the LSA out the interface. */
502 if (retx_flag == 0) {
503 return (inbr && inbr->oi == oi);
504 }
505
506 /* if we've received the lsa on this interface we need to perform
507 additional checking */
508 if (inbr && (inbr->oi == oi)) {
509 /* If the new LSA was received on this interface, and it was
510 received from either the Designated Router or the Backup
511 Designated Router, chances are that all the neighbors have
512 received the LSA already. */
513 if (NBR_IS_DR(inbr) || NBR_IS_BDR(inbr)) {
514 if (IS_DEBUG_OSPF_NSSA)
515 zlog_debug(
516 "ospf_flood_through_interface(): "
517 "DR/BDR NOT SEND to int %s",
518 IF_NAME(oi));
519 return 1;
520 }
521
522 /* If the new LSA was received on this interface, and the
523 interface state is Backup, examine the next interface. The
524 Designated Router will do the flooding on this interface.
525 However, if the Designated Router fails the router will
526 end up retransmitting the updates. */
527
528 if (oi->state == ISM_Backup) {
529 if (IS_DEBUG_OSPF_NSSA)
530 zlog_debug(
531 "ospf_flood_through_interface(): "
532 "ISM_Backup NOT SEND to int %s",
533 IF_NAME(oi));
534 return 1;
535 }
718e3744 536 }
d62a17ae 537
538 /* The LSA must be flooded out the interface. Send a Link State
539 Update packet (including the new LSA as contents) out the
540 interface. The LSA's LS age must be incremented by InfTransDelay
541 (which must be > 0) when it is copied into the outgoing Link
542 State Update packet (until the LS age field reaches the maximum
543 value of MaxAge). */
544 /* XXX HASSO: Is this IS_DEBUG_OSPF_NSSA really correct? */
545 if (IS_DEBUG_OSPF_NSSA)
546 zlog_debug(
547 "ospf_flood_through_interface(): "
548 "DR/BDR sending upd to int %s",
549 IF_NAME(oi));
550
551 /* RFC2328 Section 13.3
552 On non-broadcast networks, separate Link State Update
553 packets must be sent, as unicasts, to each adjacent neighbor
554 (i.e., those in state Exchange or greater). The destination
555 IP addresses for these packets are the neighbors' IP
556 addresses. */
557 if (oi->type == OSPF_IFTYPE_NBMA) {
d62a17ae 558 struct ospf_neighbor *nbr;
559
560 for (rn = route_top(oi->nbrs); rn; rn = route_next(rn))
561 if ((nbr = rn->info) != NULL)
562 if (nbr != oi->nbr_self
563 && nbr->state >= NSM_Exchange)
564 ospf_ls_upd_send_lsa(
565 nbr, lsa,
566 OSPF_SEND_PACKET_DIRECT);
567 } else
568 ospf_ls_upd_send_lsa(oi->nbr_self, lsa,
569 OSPF_SEND_PACKET_INDIRECT);
570
571 return 0;
718e3744 572}
573
d62a17ae 574int ospf_flood_through_area(struct ospf_area *area, struct ospf_neighbor *inbr,
575 struct ospf_lsa *lsa)
718e3744 576{
d62a17ae 577 struct listnode *node, *nnode;
578 struct ospf_interface *oi;
579 int lsa_ack_flag = 0;
580
9b50aa1f 581 assert(area);
d62a17ae 582 /* All other types are specific to a single area (Area A). The
583 eligible interfaces are all those interfaces attaching to the
584 Area A. If Area A is the backbone, this includes all the virtual
585 links. */
586 for (ALL_LIST_ELEMENTS(area->oiflist, node, nnode, oi)) {
587 if (area->area_id.s_addr != OSPF_AREA_BACKBONE
588 && oi->type == OSPF_IFTYPE_VIRTUALLINK)
589 continue;
590
591 if ((lsa->data->type == OSPF_OPAQUE_LINK_LSA)
592 && (lsa->oi != oi)) {
593 /*
594 * Link local scoped Opaque-LSA should only be flooded
595 * for the link on which the LSA has received.
596 */
597 if (IS_DEBUG_OSPF(lsa, LSA_FLOODING))
598 zlog_debug(
599 "Type-9 Opaque-LSA: lsa->oi(%p) != oi(%p)",
600 (void *)lsa->oi, (void *)oi);
601 continue;
602 }
603
604 if (ospf_flood_through_interface(oi, inbr, lsa))
605 lsa_ack_flag = 1;
606 }
607
608 return (lsa_ack_flag);
718e3744 609}
610
d62a17ae 611int ospf_flood_through_as(struct ospf *ospf, struct ospf_neighbor *inbr,
612 struct ospf_lsa *lsa)
718e3744 613{
d62a17ae 614 struct listnode *node;
615 struct ospf_area *area;
616 int lsa_ack_flag;
617
618 lsa_ack_flag = 0;
619
620 /* The incoming LSA is type 5 or type 7 (AS-EXTERNAL or AS-NSSA )
621
622 Divert the Type-5 LSA's to all non-NSSA/STUB areas
623
624 Divert the Type-7 LSA's to all NSSA areas
625
626 AS-external-LSAs are flooded throughout the entire AS, with the
627 exception of stub areas (see Section 3.6). The eligible
628 interfaces are all the router's interfaces, excluding virtual
629 links and those interfaces attaching to stub areas. */
630
631 if (CHECK_FLAG(lsa->flags, OSPF_LSA_LOCAL_XLT)) /* Translated from 7 */
632 if (IS_DEBUG_OSPF_NSSA)
633 zlog_debug("Flood/AS: NSSA TRANSLATED LSA");
634
635 for (ALL_LIST_ELEMENTS_RO(ospf->areas, node, area)) {
636 int continue_flag = 0;
637 struct listnode *if_node;
638 struct ospf_interface *oi;
639
640 switch (area->external_routing) {
641 /* Don't send AS externals into stub areas. Various types
642 of support for partial stub areas can be implemented
643 here. NSSA's will receive Type-7's that have areas
644 matching the originl LSA. */
645 case OSPF_AREA_NSSA: /* Sending Type 5 or 7 into NSSA area */
646 /* Type-7, flood NSSA area */
647 if (lsa->data->type == OSPF_AS_NSSA_LSA
648 && area == lsa->area)
649 /* We will send it. */
650 continue_flag = 0;
651 else
652 continue_flag = 1; /* Skip this NSSA area for
653 Type-5's et al */
654 break;
655
656 case OSPF_AREA_TYPE_MAX:
657 case OSPF_AREA_STUB:
658 continue_flag = 1; /* Skip this area. */
659 break;
660
661 case OSPF_AREA_DEFAULT:
662 default:
663 /* No Type-7 into normal area */
664 if (lsa->data->type == OSPF_AS_NSSA_LSA)
665 continue_flag = 1; /* skip Type-7 */
666 else
667 continue_flag = 0; /* Do this area. */
668 break;
669 }
718e3744 670
d62a17ae 671 /* Do continue for above switch. Saves a big if then mess */
672 if (continue_flag)
673 continue; /* main for-loop */
718e3744 674
d62a17ae 675 /* send to every interface in this area */
718e3744 676
d62a17ae 677 for (ALL_LIST_ELEMENTS_RO(area->oiflist, if_node, oi)) {
678 /* Skip virtual links */
679 if (oi->type != OSPF_IFTYPE_VIRTUALLINK)
680 if (ospf_flood_through_interface(oi, inbr,
681 lsa)) /* lsa */
682 lsa_ack_flag = 1;
683 }
684 } /* main area for-loop */
718e3744 685
d62a17ae 686 return (lsa_ack_flag);
687}
718e3744 688
d62a17ae 689int ospf_flood_through(struct ospf *ospf, struct ospf_neighbor *inbr,
690 struct ospf_lsa *lsa)
691{
692 int lsa_ack_flag = 0;
718e3744 693
d62a17ae 694/* Type-7 LSA's for NSSA are flooded throughout the AS here, and
695 upon return are updated in the LSDB for Type-7's. Later,
696 re-fresh will re-send them (and also, if ABR, packet code will
697 translate to Type-5's)
718e3744 698
d62a17ae 699 As usual, Type-5 LSA's (if not DISCARDED because we are STUB or
700 NSSA) are flooded throughout the AS, and are updated in the
701 global table. */
702#ifdef ORIGINAL_CODING
703 switch (lsa->data->type) {
704 case OSPF_ROUTER_LSA:
705 case OSPF_NETWORK_LSA:
706 case OSPF_SUMMARY_LSA:
707 case OSPF_ASBR_SUMMARY_LSA:
708 case OSPF_OPAQUE_LINK_LSA: /* ospf_flood_through_interface ? */
709 case OSPF_OPAQUE_AREA_LSA:
710 lsa_ack_flag =
711 ospf_flood_through_area(inbr->oi->area, inbr, lsa);
712 break;
713 case OSPF_AS_EXTERNAL_LSA: /* Type-5 */
714 case OSPF_OPAQUE_AS_LSA:
715 lsa_ack_flag = ospf_flood_through_as(ospf, inbr, lsa);
716 break;
717 /* Type-7 Only received within NSSA, then flooded */
718 case OSPF_AS_NSSA_LSA:
719 /* Any P-bit was installed with the Type-7. */
720 lsa_ack_flag =
721 ospf_flood_through_area(inbr->oi->area, inbr, lsa);
722
723 if (IS_DEBUG_OSPF_NSSA)
724 zlog_debug(
725 "ospf_flood_through: LOCAL NSSA FLOOD of Type-7.");
726 break;
718e3744 727 default:
d62a17ae 728 break;
718e3744 729 }
d62a17ae 730#else /* ORIGINAL_CODING */
731 /*
732 * At the common sub-sub-function "ospf_flood_through_interface()",
733 * a parameter "inbr" will be used to distinguish the called context
734 * whether the given LSA was received from the neighbor, or the
735 * flooding for the LSA starts from this node (e.g. the LSA was self-
736 * originated, or the LSA is going to be flushed from routing domain).
737 *
738 * So, for consistency reasons, this function "ospf_flood_through()"
739 * should also allow the usage that the given "inbr" parameter to be
740 * NULL. If we do so, corresponding AREA parameter should be referred
741 * by "lsa->area", instead of "inbr->oi->area".
742 */
743 switch (lsa->data->type) {
744 case OSPF_AS_EXTERNAL_LSA: /* Type-5 */
745 case OSPF_OPAQUE_AS_LSA:
746 lsa_ack_flag = ospf_flood_through_as(ospf, inbr, lsa);
747 break;
748 /* Type-7 Only received within NSSA, then flooded */
749 case OSPF_AS_NSSA_LSA:
750 /* Any P-bit was installed with the Type-7. */
751
752 if (IS_DEBUG_OSPF_NSSA)
753 zlog_debug(
754 "ospf_flood_through: LOCAL NSSA FLOOD of Type-7.");
755 /* Fallthrough */
756 default:
757 lsa_ack_flag = ospf_flood_through_area(lsa->area, inbr, lsa);
758 break;
718e3744 759 }
718e3744 760#endif /* ORIGINAL_CODING */
718e3744 761
d62a17ae 762 return (lsa_ack_flag);
763}
6b0655a2 764
718e3744 765
766/* Management functions for neighbor's Link State Request list. */
d62a17ae 767void ospf_ls_request_add(struct ospf_neighbor *nbr, struct ospf_lsa *lsa)
718e3744 768{
d62a17ae 769 /*
770 * We cannot make use of the newly introduced callback function
771 * "lsdb->new_lsa_hook" to replace debug output below, just because
772 * it seems no simple and smart way to pass neighbor information to
773 * the common function "ospf_lsdb_add()" -- endo.
774 */
775 if (IS_DEBUG_OSPF(lsa, LSA_FLOODING))
776 zlog_debug("RqstL(%lu)++, NBR(%s), LSA[%s]",
777 ospf_ls_request_count(nbr),
778 inet_ntoa(nbr->router_id), dump_lsa_key(lsa));
779
780 ospf_lsdb_add(&nbr->ls_req, lsa);
718e3744 781}
782
d62a17ae 783unsigned long ospf_ls_request_count(struct ospf_neighbor *nbr)
718e3744 784{
d62a17ae 785 return ospf_lsdb_count_all(&nbr->ls_req);
718e3744 786}
787
d62a17ae 788int ospf_ls_request_isempty(struct ospf_neighbor *nbr)
718e3744 789{
d62a17ae 790 return ospf_lsdb_isempty(&nbr->ls_req);
718e3744 791}
792
793/* Remove LSA from neighbor's ls-request list. */
d62a17ae 794void ospf_ls_request_delete(struct ospf_neighbor *nbr, struct ospf_lsa *lsa)
718e3744 795{
d62a17ae 796 if (nbr->ls_req_last == lsa) {
797 ospf_lsa_unlock(&nbr->ls_req_last);
798 nbr->ls_req_last = NULL;
799 }
800
801 if (IS_DEBUG_OSPF(lsa, LSA_FLOODING)) /* -- endo. */
802 zlog_debug("RqstL(%lu)--, NBR(%s), LSA[%s]",
803 ospf_ls_request_count(nbr),
804 inet_ntoa(nbr->router_id), dump_lsa_key(lsa));
805
806 ospf_lsdb_delete(&nbr->ls_req, lsa);
718e3744 807}
808
809/* Remove all LSA from neighbor's ls-requenst list. */
d62a17ae 810void ospf_ls_request_delete_all(struct ospf_neighbor *nbr)
718e3744 811{
d62a17ae 812 ospf_lsa_unlock(&nbr->ls_req_last);
813 nbr->ls_req_last = NULL;
814 ospf_lsdb_delete_all(&nbr->ls_req);
718e3744 815}
816
817/* Lookup LSA from neighbor's ls-request list. */
d62a17ae 818struct ospf_lsa *ospf_ls_request_lookup(struct ospf_neighbor *nbr,
819 struct ospf_lsa *lsa)
718e3744 820{
d62a17ae 821 return ospf_lsdb_lookup(&nbr->ls_req, lsa);
718e3744 822}
823
d62a17ae 824struct ospf_lsa *ospf_ls_request_new(struct lsa_header *lsah)
718e3744 825{
d62a17ae 826 struct ospf_lsa *new;
718e3744 827
5b3d4186 828 new = ospf_lsa_new_and_data(OSPF_LSA_HEADER_SIZE);
d62a17ae 829 memcpy(new->data, lsah, OSPF_LSA_HEADER_SIZE);
718e3744 830
d62a17ae 831 return new;
718e3744 832}
833
6b0655a2 834
718e3744 835/* Management functions for neighbor's ls-retransmit list. */
d62a17ae 836unsigned long ospf_ls_retransmit_count(struct ospf_neighbor *nbr)
718e3744 837{
d62a17ae 838 return ospf_lsdb_count_all(&nbr->ls_rxmt);
718e3744 839}
840
d62a17ae 841unsigned long ospf_ls_retransmit_count_self(struct ospf_neighbor *nbr,
842 int lsa_type)
718e3744 843{
d62a17ae 844 return ospf_lsdb_count_self(&nbr->ls_rxmt, lsa_type);
718e3744 845}
846
d62a17ae 847int ospf_ls_retransmit_isempty(struct ospf_neighbor *nbr)
718e3744 848{
d62a17ae 849 return ospf_lsdb_isempty(&nbr->ls_rxmt);
718e3744 850}
851
852/* Add LSA to be retransmitted to neighbor's ls-retransmit list. */
d62a17ae 853void ospf_ls_retransmit_add(struct ospf_neighbor *nbr, struct ospf_lsa *lsa)
718e3744 854{
d62a17ae 855 struct ospf_lsa *old;
718e3744 856
d62a17ae 857 old = ospf_ls_retransmit_lookup(nbr, lsa);
718e3744 858
d62a17ae 859 if (ospf_lsa_more_recent(old, lsa) < 0) {
860 if (old) {
861 old->retransmit_counter--;
862 ospf_lsdb_delete(&nbr->ls_rxmt, old);
863 }
864 lsa->retransmit_counter++;
865 /*
866 * We cannot make use of the newly introduced callback function
867 * "lsdb->new_lsa_hook" to replace debug output below, just
868 * because
869 * it seems no simple and smart way to pass neighbor information
870 * to
871 * the common function "ospf_lsdb_add()" -- endo.
872 */
873 if (IS_DEBUG_OSPF(lsa, LSA_FLOODING))
874 zlog_debug("RXmtL(%lu)++, NBR(%s), LSA[%s]",
875 ospf_ls_retransmit_count(nbr),
876 inet_ntoa(nbr->router_id),
877 dump_lsa_key(lsa));
878 ospf_lsdb_add(&nbr->ls_rxmt, lsa);
718e3744 879 }
718e3744 880}
881
882/* Remove LSA from neibghbor's ls-retransmit list. */
d62a17ae 883void ospf_ls_retransmit_delete(struct ospf_neighbor *nbr, struct ospf_lsa *lsa)
718e3744 884{
d62a17ae 885 if (ospf_ls_retransmit_lookup(nbr, lsa)) {
886 lsa->retransmit_counter--;
887 if (IS_DEBUG_OSPF(lsa, LSA_FLOODING)) /* -- endo. */
888 zlog_debug("RXmtL(%lu)--, NBR(%s), LSA[%s]",
889 ospf_ls_retransmit_count(nbr),
890 inet_ntoa(nbr->router_id),
891 dump_lsa_key(lsa));
892 ospf_lsdb_delete(&nbr->ls_rxmt, lsa);
893 }
718e3744 894}
895
896/* Clear neighbor's ls-retransmit list. */
d62a17ae 897void ospf_ls_retransmit_clear(struct ospf_neighbor *nbr)
718e3744 898{
d62a17ae 899 struct ospf_lsdb *lsdb;
900 int i;
718e3744 901
d62a17ae 902 lsdb = &nbr->ls_rxmt;
718e3744 903
d62a17ae 904 for (i = OSPF_MIN_LSA; i < OSPF_MAX_LSA; i++) {
905 struct route_table *table = lsdb->type[i].db;
906 struct route_node *rn;
907 struct ospf_lsa *lsa;
718e3744 908
d62a17ae 909 for (rn = route_top(table); rn; rn = route_next(rn))
910 if ((lsa = rn->info) != NULL)
911 ospf_ls_retransmit_delete(nbr, lsa);
912 }
718e3744 913
d62a17ae 914 ospf_lsa_unlock(&nbr->ls_req_last);
915 nbr->ls_req_last = NULL;
718e3744 916}
917
918/* Lookup LSA from neighbor's ls-retransmit list. */
d62a17ae 919struct ospf_lsa *ospf_ls_retransmit_lookup(struct ospf_neighbor *nbr,
920 struct ospf_lsa *lsa)
718e3744 921{
d62a17ae 922 return ospf_lsdb_lookup(&nbr->ls_rxmt, lsa);
718e3744 923}
924
d62a17ae 925static void ospf_ls_retransmit_delete_nbr_if(struct ospf_interface *oi,
926 struct ospf_lsa *lsa)
718e3744 927{
d62a17ae 928 struct route_node *rn;
929 struct ospf_neighbor *nbr;
930 struct ospf_lsa *lsr;
931
932 if (ospf_if_is_enable(oi))
933 for (rn = route_top(oi->nbrs); rn; rn = route_next(rn))
934 /* If LSA find in LS-retransmit list, then remove it. */
935 if ((nbr = rn->info) != NULL) {
936 lsr = ospf_ls_retransmit_lookup(nbr, lsa);
937
938 /* If LSA find in ls-retransmit list, remove it.
939 */
940 if (lsr != NULL
941 && lsr->data->ls_seqnum
942 == lsa->data->ls_seqnum)
943 ospf_ls_retransmit_delete(nbr, lsr);
944 }
718e3744 945}
946
d62a17ae 947void ospf_ls_retransmit_delete_nbr_area(struct ospf_area *area,
948 struct ospf_lsa *lsa)
718e3744 949{
d62a17ae 950 struct listnode *node, *nnode;
951 struct ospf_interface *oi;
718e3744 952
d62a17ae 953 for (ALL_LIST_ELEMENTS(area->oiflist, node, nnode, oi))
954 ospf_ls_retransmit_delete_nbr_if(oi, lsa);
68980084 955}
718e3744 956
d62a17ae 957void ospf_ls_retransmit_delete_nbr_as(struct ospf *ospf, struct ospf_lsa *lsa)
68980084 958{
d62a17ae 959 struct listnode *node, *nnode;
960 struct ospf_interface *oi;
718e3744 961
d62a17ae 962 for (ALL_LIST_ELEMENTS(ospf->oiflist, node, nnode, oi))
963 ospf_ls_retransmit_delete_nbr_if(oi, lsa);
718e3744 964}
965
6b0655a2 966
d62a17ae 967/* Sets ls_age to MaxAge and floods throu the area.
718e3744 968 When we implement ASE routing, there will be anothe function
969 flushing an LSA from the whole domain. */
d62a17ae 970void ospf_lsa_flush_area(struct ospf_lsa *lsa, struct ospf_area *area)
718e3744 971{
d62a17ae 972 /* Reset the lsa origination time such that it gives
973 more time for the ACK to be received and avoid
974 retransmissions */
975 lsa->data->ls_age = htons(OSPF_LSA_MAXAGE);
046460a1
CS
976 if (IS_DEBUG_OSPF_EVENT)
977 zlog_debug("%s: MAXAGE set to LSA %s", __PRETTY_FUNCTION__,
978 inet_ntoa(lsa->data->id));
d62a17ae 979 monotime(&lsa->tv_recv);
980 lsa->tv_orig = lsa->tv_recv;
981 ospf_flood_through_area(area, NULL, lsa);
982 ospf_lsa_maxage(area->ospf, lsa);
718e3744 983}
984
d62a17ae 985void ospf_lsa_flush_as(struct ospf *ospf, struct ospf_lsa *lsa)
718e3744 986{
d62a17ae 987 /* Reset the lsa origination time such that it gives
988 more time for the ACK to be received and avoid
989 retransmissions */
990 lsa->data->ls_age = htons(OSPF_LSA_MAXAGE);
991 monotime(&lsa->tv_recv);
992 lsa->tv_orig = lsa->tv_recv;
993 ospf_flood_through_as(ospf, NULL, lsa);
994 ospf_lsa_maxage(ospf, lsa);
718e3744 995}
02d942c9 996
d62a17ae 997void ospf_lsa_flush(struct ospf *ospf, struct ospf_lsa *lsa)
02d942c9 998{
d62a17ae 999 lsa->data->ls_age = htons(OSPF_LSA_MAXAGE);
1000
1001 switch (lsa->data->type) {
1002 case OSPF_ROUTER_LSA:
1003 case OSPF_NETWORK_LSA:
1004 case OSPF_SUMMARY_LSA:
1005 case OSPF_ASBR_SUMMARY_LSA:
1006 case OSPF_AS_NSSA_LSA:
1007 case OSPF_OPAQUE_LINK_LSA:
1008 case OSPF_OPAQUE_AREA_LSA:
1009 ospf_lsa_flush_area(lsa, lsa->area);
1010 break;
1011 case OSPF_AS_EXTERNAL_LSA:
1012 case OSPF_OPAQUE_AS_LSA:
1013 ospf_lsa_flush_as(ospf, lsa);
1014 break;
1015 default:
1016 zlog_info("%s: Unknown LSA type %u", __func__, lsa->data->type);
1017 break;
1018 }
02d942c9 1019}