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