1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * OSPF Link State Advertisement
4 * Copyright (C) 1999, 2000 Toshiaki Takada
19 #include "sockunion.h" /* for inet_aton() */
23 #include "ospfd/ospfd.h"
24 #include "ospfd/ospf_interface.h"
25 #include "ospfd/ospf_ism.h"
26 #include "ospfd/ospf_asbr.h"
27 #include "ospfd/ospf_lsa.h"
28 #include "ospfd/ospf_lsdb.h"
29 #include "ospfd/ospf_neighbor.h"
30 #include "ospfd/ospf_nsm.h"
31 #include "ospfd/ospf_flood.h"
32 #include "ospfd/ospf_packet.h"
33 #include "ospfd/ospf_spf.h"
34 #include "ospfd/ospf_dump.h"
35 #include "ospfd/ospf_route.h"
36 #include "ospfd/ospf_ase.h"
37 #include "ospfd/ospf_zebra.h"
38 #include "ospfd/ospf_abr.h"
39 #include "ospfd/ospf_errors.h"
41 static struct ospf_lsa
*ospf_handle_summarylsa_lsId_chg(struct ospf_area
*area
,
42 struct prefix_ipv4
*p
,
45 struct in_addr old_id
);
46 static struct ospf_lsa
*
47 ospf_summary_lsa_prepare_and_flood(struct prefix_ipv4
*p
, uint32_t metric
,
48 struct ospf_area
*area
, struct in_addr id
);
49 static struct ospf_lsa
*ospf_summary_lsa_refresh(struct ospf
*ospf
,
50 struct ospf_lsa
*lsa
);
51 static struct ospf_lsa
*
52 ospf_asbr_summary_lsa_prepare_and_flood(struct prefix_ipv4
*p
, uint32_t metric
,
53 struct ospf_area
*area
,
55 static struct ospf_lsa
*ospf_summary_asbr_lsa_refresh(struct ospf
*ospf
,
56 struct ospf_lsa
*lsa
);
57 static struct ospf_lsa
*ospf_handle_exnl_lsa_lsId_chg(struct ospf
*ospf
,
58 struct external_info
*ei
,
60 static struct ospf_lsa
*
61 ospf_exnl_lsa_prepare_and_flood(struct ospf
*ospf
, struct external_info
*ei
,
64 uint32_t get_metric(uint8_t *metric
)
68 m
= (m
<< 8) + metric
[1];
69 m
= (m
<< 8) + metric
[2];
73 /** @brief The Function checks self generated DoNotAge.
75 * @return true or false.
77 bool ospf_check_dna_lsa(const struct ospf_lsa
*lsa
)
79 return ((IS_LSA_SELF(lsa
) && CHECK_FLAG(lsa
->data
->ls_age
, DO_NOT_AGE
))
84 struct timeval
int2tv(int a
)
94 struct timeval
msec2tv(int a
)
98 ret
.tv_sec
= a
/ 1000;
99 ret
.tv_usec
= (a
% 1000) * 1000;
104 int ospf_lsa_refresh_delay(struct ospf_lsa
*lsa
)
106 struct timeval delta
;
109 if (monotime_since(&lsa
->tv_orig
, &delta
)
110 < OSPF_MIN_LS_INTERVAL
* 1000LL) {
111 struct timeval minv
= msec2tv(OSPF_MIN_LS_INTERVAL
);
112 timersub(&minv
, &delta
, &minv
);
114 /* TBD: remove padding to full sec, return timeval instead */
115 delay
= minv
.tv_sec
+ !!minv
.tv_usec
;
117 if (IS_DEBUG_OSPF(lsa
, LSA_GENERATE
))
119 "LSA[Type%d:%pI4]: Refresh timer delay %d seconds",
120 lsa
->data
->type
, &lsa
->data
->id
,
130 int get_age(struct ospf_lsa
*lsa
)
134 /* As per rfc4136, the self-originated LSAs in their
135 * own database keep aging, however rfc doesn't tell
136 * till how long the LSA should be aged, as of now
137 * we are capping it for OSPF_LSA_MAXAGE.
140 /* If LSA is marked as donotage */
141 if (CHECK_FLAG(lsa
->data
->ls_age
, DO_NOT_AGE
) && !IS_LSA_SELF(lsa
))
142 return ntohs(lsa
->data
->ls_age
);
144 monotime_since(&lsa
->tv_recv
, &rel
);
145 return ntohs(lsa
->data
->ls_age
) + rel
.tv_sec
;
149 /* Fletcher Checksum -- Refer to RFC1008. */
151 /* All the offsets are zero-based. The offsets in the RFC1008 are
153 uint16_t ospf_lsa_checksum(struct lsa_header
*lsa
)
155 uint8_t *buffer
= &lsa
->options
;
156 int options_offset
= buffer
- (uint8_t *)&lsa
->ls_age
; /* should be 2 */
158 /* Skip the AGE field */
159 uint16_t len
= ntohs(lsa
->length
) - options_offset
;
161 /* Checksum offset starts from "options" field, not the beginning of the
162 lsa_header struct. The offset is 14, rather than 16. */
163 int checksum_offset
= (uint8_t *)&lsa
->checksum
- buffer
;
165 return fletcher_checksum(buffer
, len
, checksum_offset
);
168 int ospf_lsa_checksum_valid(struct lsa_header
*lsa
)
170 uint8_t *buffer
= &lsa
->options
;
171 int options_offset
= buffer
- (uint8_t *)&lsa
->ls_age
; /* should be 2 */
173 /* Skip the AGE field */
174 uint16_t len
= ntohs(lsa
->length
) - options_offset
;
176 return (fletcher_checksum(buffer
, len
, FLETCHER_CHECKSUM_VALIDATE
)
181 /* Create OSPF LSA. */
182 struct ospf_lsa
*ospf_lsa_new(void)
184 struct ospf_lsa
*new;
186 new = XCALLOC(MTYPE_OSPF_LSA
, sizeof(struct ospf_lsa
));
190 new->retransmit_counter
= 0;
191 monotime(&new->tv_recv
);
192 new->tv_orig
= new->tv_recv
;
193 new->refresh_list
= -1;
194 new->vrf_id
= VRF_DEFAULT
;
195 new->to_be_acknowledged
= 0;
196 new->opaque_zero_len_delete
= 0;
201 struct ospf_lsa
*ospf_lsa_new_and_data(size_t size
)
203 struct ospf_lsa
*new;
205 new = ospf_lsa_new();
206 new->data
= ospf_lsa_data_new(size
);
212 /* Duplicate OSPF LSA. */
213 struct ospf_lsa
*ospf_lsa_dup(struct ospf_lsa
*lsa
)
215 struct ospf_lsa
*new;
220 new = XCALLOC(MTYPE_OSPF_LSA
, sizeof(struct ospf_lsa
));
222 memcpy(new, lsa
, sizeof(struct ospf_lsa
));
223 UNSET_FLAG(new->flags
, OSPF_LSA_DISCARD
);
225 new->retransmit_counter
= 0;
226 new->data
= ospf_lsa_data_dup(lsa
->data
);
228 /* kevinm: Clear the refresh_list, otherwise there are going
229 to be problems when we try to remove the LSA from the
230 queue (which it's not a member of.)
231 XXX: Should we add the LSA to the refresh_list queue? */
232 new->refresh_list
= -1;
234 if (IS_DEBUG_OSPF(lsa
, LSA
))
235 zlog_debug("LSA: duplicated %p (new: %p)", (void *)lsa
,
242 void ospf_lsa_free(struct ospf_lsa
*lsa
)
244 assert(lsa
->lock
== 0);
246 if (IS_DEBUG_OSPF(lsa
, LSA
))
247 zlog_debug("LSA: freed %p", (void *)lsa
);
249 /* Delete LSA data. */
250 if (lsa
->data
!= NULL
)
251 ospf_lsa_data_free(lsa
->data
);
253 assert(lsa
->refresh_list
< 0);
255 memset(lsa
, 0, sizeof(struct ospf_lsa
));
256 XFREE(MTYPE_OSPF_LSA
, lsa
);
260 struct ospf_lsa
*ospf_lsa_lock(struct ospf_lsa
*lsa
)
267 void ospf_lsa_unlock(struct ospf_lsa
**lsa
)
269 /* This is sanity check. */
275 assert((*lsa
)->lock
>= 0);
277 if ((*lsa
)->lock
== 0) {
278 assert(CHECK_FLAG((*lsa
)->flags
, OSPF_LSA_DISCARD
));
284 /* Check discard flag. */
285 void ospf_lsa_discard(struct ospf_lsa
*lsa
)
287 if (!CHECK_FLAG(lsa
->flags
, OSPF_LSA_DISCARD
)) {
288 SET_FLAG(lsa
->flags
, OSPF_LSA_DISCARD
);
289 ospf_lsa_unlock(&lsa
);
293 /* Create LSA data. */
294 struct lsa_header
*ospf_lsa_data_new(size_t size
)
296 return XCALLOC(MTYPE_OSPF_LSA_DATA
, size
);
299 /* Duplicate LSA data. */
300 struct lsa_header
*ospf_lsa_data_dup(struct lsa_header
*lsah
)
302 struct lsa_header
*new;
304 new = ospf_lsa_data_new(ntohs(lsah
->length
));
305 memcpy(new, lsah
, ntohs(lsah
->length
));
311 void ospf_lsa_data_free(struct lsa_header
*lsah
)
313 if (IS_DEBUG_OSPF(lsa
, LSA
))
314 zlog_debug("LSA[Type%d:%pI4]: data freed %p", lsah
->type
,
315 &lsah
->id
, (void *)lsah
);
317 XFREE(MTYPE_OSPF_LSA_DATA
, lsah
);
321 /* LSA general functions. */
323 const char *dump_lsa_key(struct ospf_lsa
*lsa
)
325 static char buf
[sizeof("Type255,id(255.255.255.255),ar(255.255.255.255)")+1];
326 struct lsa_header
*lsah
;
328 if (lsa
!= NULL
&& (lsah
= lsa
->data
) != NULL
) {
329 char id
[INET_ADDRSTRLEN
], ar
[INET_ADDRSTRLEN
];
330 inet_ntop(AF_INET
, &lsah
->id
, id
, sizeof(id
));
331 inet_ntop(AF_INET
, &lsah
->adv_router
, ar
, sizeof(ar
));
333 snprintf(buf
, sizeof(buf
), "Type%d,id(%s),ar(%s)", lsah
->type
,
336 strlcpy(buf
, "NULL", sizeof(buf
));
341 uint32_t lsa_seqnum_increment(struct ospf_lsa
*lsa
)
345 seqnum
= ntohl(lsa
->data
->ls_seqnum
) + 1;
347 return htonl(seqnum
);
350 void lsa_header_set(struct stream
*s
, uint8_t options
, uint8_t type
,
351 struct in_addr id
, struct in_addr router_id
)
353 struct lsa_header
*lsah
;
355 lsah
= (struct lsa_header
*)STREAM_DATA(s
);
357 lsah
->ls_age
= htons(OSPF_LSA_INITIAL_AGE
);
358 lsah
->options
= options
;
361 lsah
->adv_router
= router_id
;
362 lsah
->ls_seqnum
= htonl(OSPF_INITIAL_SEQUENCE_NUMBER
);
364 stream_forward_endp(s
, OSPF_LSA_HEADER_SIZE
);
368 /* router-LSA related functions. */
369 /* Get router-LSA flags. */
370 uint8_t router_lsa_flags(struct ospf_area
*area
)
374 flags
= area
->ospf
->flags
;
376 /* Set virtual link flag. */
377 if (ospf_full_virtual_nbrs(area
))
378 SET_FLAG(flags
, ROUTER_LSA_VIRTUAL
);
380 /* Just sanity check */
381 UNSET_FLAG(flags
, ROUTER_LSA_VIRTUAL
);
383 /* Set Shortcut ABR behabiour flag. */
384 UNSET_FLAG(flags
, ROUTER_LSA_SHORTCUT
);
385 if (area
->ospf
->abr_type
== OSPF_ABR_SHORTCUT
)
386 if (!OSPF_IS_AREA_BACKBONE(area
))
387 if ((area
->shortcut_configured
== OSPF_SHORTCUT_DEFAULT
388 && area
->ospf
->backbone
== NULL
)
389 || area
->shortcut_configured
390 == OSPF_SHORTCUT_ENABLE
)
391 SET_FLAG(flags
, ROUTER_LSA_SHORTCUT
);
393 /* ASBR can't exit in stub area. */
394 if (area
->external_routing
== OSPF_AREA_STUB
)
395 UNSET_FLAG(flags
, ROUTER_LSA_EXTERNAL
);
396 /* If ASBR set External flag */
397 else if (IS_OSPF_ASBR(area
->ospf
))
398 SET_FLAG(flags
, ROUTER_LSA_EXTERNAL
);
400 /* Set ABR dependent flags */
401 if (IS_OSPF_ABR(area
->ospf
)) {
402 SET_FLAG(flags
, ROUTER_LSA_BORDER
);
403 /* If Area is NSSA and we are both ABR and unconditional
405 * set Nt bit to inform other routers.
407 if ((area
->external_routing
== OSPF_AREA_NSSA
)
408 && (area
->NSSATranslatorRole
== OSPF_NSSA_ROLE_ALWAYS
))
409 SET_FLAG(flags
, ROUTER_LSA_NT
);
414 /* Lookup neighbor other than myself.
415 And check neighbor count,
416 Point-to-Point link must have only 1 neighbor. */
417 struct ospf_neighbor
*ospf_nbr_lookup_ptop(struct ospf_interface
*oi
)
419 struct ospf_neighbor
*nbr
= NULL
;
420 struct route_node
*rn
;
422 /* Search neighbor, there must be one of two nbrs. */
423 for (rn
= route_top(oi
->nbrs
); rn
; rn
= route_next(rn
))
424 if ((nbr
= rn
->info
))
425 if (!IPV4_ADDR_SAME(&nbr
->router_id
,
426 &oi
->ospf
->router_id
))
427 if (nbr
->state
== NSM_Full
) {
428 route_unlock_node(rn
);
432 /* PtoP link must have only 1 neighbor. */
433 if (ospf_nbr_count(oi
, 0) > 1)
435 EC_OSPF_PTP_NEIGHBOR
,
436 "Point-to-Point link on interface %s has more than 1 neighbor.",
442 /* Determine cost of link, taking RFC3137 stub-router support into
445 static uint16_t ospf_link_cost(struct ospf_interface
*oi
)
447 /* RFC3137 stub router support */
448 if (!CHECK_FLAG(oi
->area
->stub_router_state
, OSPF_AREA_IS_STUB_ROUTED
))
449 return oi
->output_cost
;
451 return OSPF_OUTPUT_COST_INFINITE
;
454 /* Set a link information. */
455 char link_info_set(struct stream
**s
, struct in_addr id
, struct in_addr data
,
456 uint8_t type
, uint8_t tos
, uint16_t cost
)
458 /* LSA stream is initially allocated to OSPF_MAX_LSA_SIZE, suits
459 * vast majority of cases. Some rare routers with lots of links need
461 * we try accommodate those here.
463 if (STREAM_WRITEABLE(*s
) < OSPF_ROUTER_LSA_LINK_SIZE
) {
464 size_t ret
= OSPF_MAX_LSA_SIZE
;
466 /* Can we enlarge the stream still? */
467 if (STREAM_SIZE(*s
) == OSPF_MAX_LSA_SIZE
) {
468 /* we futz the size here for simplicity, really we need
471 * IP Header - (sizeof(struct ip))
472 * OSPF Header - OSPF_HEADER_SIZE
473 * LSA Header - OSPF_LSA_HEADER_SIZE
474 * MD5 auth data, if MD5 is configured -
475 * OSPF_AUTH_MD5_SIZE.
477 * Simpler just to subtract OSPF_MAX_LSA_SIZE though.
479 ret
= stream_resize_inplace(
480 s
, OSPF_MAX_PACKET_SIZE
- OSPF_MAX_LSA_SIZE
);
483 if (ret
== OSPF_MAX_LSA_SIZE
) {
486 "%s: Out of space in LSA stream, left %zd, size %zd",
487 __func__
, STREAM_WRITEABLE(*s
),
493 /* TOS based routing is not supported. */
494 stream_put_ipv4(*s
, id
.s_addr
); /* Link ID. */
495 stream_put_ipv4(*s
, data
.s_addr
); /* Link Data. */
496 stream_putc(*s
, type
); /* Link Type. */
497 stream_putc(*s
, tos
); /* TOS = 0. */
498 stream_putw(*s
, cost
); /* Link Cost. */
503 /* Describe Point-to-Point link (Section 12.4.1.1). */
505 /* Note: If the interface is configured as point-to-point dmvpn then the other
506 * end of link is dmvpn hub with point-to-multipoint ospf network type. The
507 * hub then expects this router to populate the stub network and also Link Data
508 * Field set to IP Address and not MIB-II ifIndex
510 static int lsa_link_ptop_set(struct stream
**s
, struct ospf_interface
*oi
)
513 struct ospf_neighbor
*nbr
;
514 struct in_addr id
, mask
, data
;
515 uint16_t cost
= ospf_link_cost(oi
);
517 if (IS_DEBUG_OSPF(lsa
, LSA_GENERATE
))
518 zlog_debug("LSA[Type1]: Set link Point-to-Point");
520 if ((nbr
= ospf_nbr_lookup_ptop(oi
)))
521 if (nbr
->state
== NSM_Full
) {
522 if (CHECK_FLAG(oi
->connected
->flags
,
523 ZEBRA_IFA_UNNUMBERED
)
525 /* For unnumbered point-to-point networks, the
527 should specify the interface's MIB-II ifIndex
529 data
.s_addr
= htonl(oi
->ifp
->ifindex
);
530 links
+= link_info_set(
531 s
, nbr
->router_id
, data
,
532 LSA_LINK_TYPE_POINTOPOINT
, 0, cost
);
534 links
+= link_info_set(
536 oi
->address
->u
.prefix4
,
537 LSA_LINK_TYPE_POINTOPOINT
, 0, cost
);
541 /* no need for a stub link for unnumbered interfaces */
543 || !CHECK_FLAG(oi
->connected
->flags
, ZEBRA_IFA_UNNUMBERED
)) {
544 /* Regardless of the state of the neighboring router, we must
545 add a Type 3 link (stub network).
546 N.B. Options 1 & 2 share basically the same logic. */
547 masklen2ip(oi
->address
->prefixlen
, &mask
);
548 id
.s_addr
= CONNECTED_PREFIX(oi
->connected
)->u
.prefix4
.s_addr
550 links
+= link_info_set(s
, id
, mask
, LSA_LINK_TYPE_STUB
, 0,
557 /* Describe Broadcast Link. */
558 static int lsa_link_broadcast_set(struct stream
**s
, struct ospf_interface
*oi
)
560 struct ospf_neighbor
*dr
;
561 struct in_addr id
, mask
;
562 uint16_t cost
= ospf_link_cost(oi
);
564 /* Describe Type 3 Link. */
565 if (oi
->state
== ISM_Waiting
) {
566 if (IS_DEBUG_OSPF(lsa
, LSA_GENERATE
))
568 "LSA[Type1]: Interface %s is in state Waiting. Adding stub interface",
570 masklen2ip(oi
->address
->prefixlen
, &mask
);
571 id
.s_addr
= oi
->address
->u
.prefix4
.s_addr
& mask
.s_addr
;
572 return link_info_set(s
, id
, mask
, LSA_LINK_TYPE_STUB
, 0,
576 dr
= ospf_nbr_lookup_by_addr(oi
->nbrs
, &DR(oi
));
577 /* Describe Type 2 link. */
578 if (dr
&& (dr
->state
== NSM_Full
579 || IPV4_ADDR_SAME(&oi
->address
->u
.prefix4
, &DR(oi
)))
580 && ospf_nbr_count(oi
, NSM_Full
) > 0) {
581 if (IS_DEBUG_OSPF(lsa
, LSA_GENERATE
))
583 "LSA[Type1]: Interface %s has a DR. Adding transit interface",
585 return link_info_set(s
, DR(oi
), oi
->address
->u
.prefix4
,
586 LSA_LINK_TYPE_TRANSIT
, 0, cost
);
588 /* Describe type 3 link. */
590 if (IS_DEBUG_OSPF(lsa
, LSA_GENERATE
))
592 "LSA[Type1]: Interface %s has no DR. Adding stub interface",
594 masklen2ip(oi
->address
->prefixlen
, &mask
);
595 id
.s_addr
= oi
->address
->u
.prefix4
.s_addr
& mask
.s_addr
;
596 return link_info_set(s
, id
, mask
, LSA_LINK_TYPE_STUB
, 0,
601 static int lsa_link_loopback_set(struct stream
**s
, struct ospf_interface
*oi
)
603 struct in_addr id
, mask
;
605 /* Describe Type 3 Link. */
606 if (oi
->state
!= ISM_Loopback
)
609 mask
.s_addr
= 0xffffffff;
610 id
.s_addr
= oi
->address
->u
.prefix4
.s_addr
;
611 return link_info_set(s
, id
, mask
, LSA_LINK_TYPE_STUB
, 0, 0);
614 /* Describe Virtual Link. */
615 static int lsa_link_virtuallink_set(struct stream
**s
,
616 struct ospf_interface
*oi
)
618 struct ospf_neighbor
*nbr
;
619 uint16_t cost
= ospf_link_cost(oi
);
621 if (oi
->state
== ISM_PointToPoint
)
622 if ((nbr
= ospf_nbr_lookup_ptop(oi
)))
623 if (nbr
->state
== NSM_Full
) {
624 return link_info_set(s
, nbr
->router_id
,
625 oi
->address
->u
.prefix4
,
626 LSA_LINK_TYPE_VIRTUALLINK
,
633 #define lsa_link_nbma_set(S,O) lsa_link_broadcast_set (S, O)
635 /* this function add for support point-to-multipoint ,see rfc2328
637 /* from "edward rrr" <edward_rrr@hotmail.com>
638 http://marc.theaimsgroup.com/?l=zebra&m=100739222210507&w=2 */
639 static int lsa_link_ptomp_set(struct stream
**s
, struct ospf_interface
*oi
)
642 struct route_node
*rn
;
643 struct ospf_neighbor
*nbr
= NULL
;
644 struct in_addr id
, mask
;
645 uint16_t cost
= ospf_link_cost(oi
);
647 mask
.s_addr
= 0xffffffff;
648 id
.s_addr
= oi
->address
->u
.prefix4
.s_addr
;
649 links
+= link_info_set(s
, id
, mask
, LSA_LINK_TYPE_STUB
, 0, 0);
651 if (IS_DEBUG_OSPF(lsa
, LSA_GENERATE
))
652 zlog_debug("PointToMultipoint: running ptomultip_set");
654 /* Search neighbor, */
655 for (rn
= route_top(oi
->nbrs
); rn
; rn
= route_next(rn
))
656 if ((nbr
= rn
->info
) != NULL
)
658 if (!IPV4_ADDR_SAME(&nbr
->router_id
,
659 &oi
->ospf
->router_id
))
660 if (nbr
->state
== NSM_Full
)
663 links
+= link_info_set(
665 oi
->address
->u
.prefix4
,
666 LSA_LINK_TYPE_POINTOPOINT
, 0,
668 if (IS_DEBUG_OSPF(lsa
, LSA_GENERATE
))
670 "PointToMultipoint: set link to %pI4",
671 &oi
->address
->u
.prefix4
);
677 /* Set router-LSA link information. */
678 static int router_lsa_link_set(struct stream
**s
, struct ospf_area
*area
)
680 struct listnode
*node
;
681 struct ospf_interface
*oi
;
684 for (ALL_LIST_ELEMENTS_RO(area
->oiflist
, node
, oi
)) {
685 struct interface
*ifp
= oi
->ifp
;
687 /* Check interface is up, OSPF is enable. */
688 if (if_is_operative(ifp
)) {
689 if (oi
->state
!= ISM_Down
) {
690 oi
->lsa_pos_beg
= links
;
691 /* Describe each link. */
693 case OSPF_IFTYPE_POINTOPOINT
:
694 links
+= lsa_link_ptop_set(s
, oi
);
696 case OSPF_IFTYPE_BROADCAST
:
697 links
+= lsa_link_broadcast_set(s
, oi
);
699 case OSPF_IFTYPE_NBMA
:
700 links
+= lsa_link_nbma_set(s
, oi
);
702 case OSPF_IFTYPE_POINTOMULTIPOINT
:
703 links
+= lsa_link_ptomp_set(s
, oi
);
705 case OSPF_IFTYPE_VIRTUALLINK
:
707 lsa_link_virtuallink_set(s
, oi
);
709 case OSPF_IFTYPE_LOOPBACK
:
710 links
+= lsa_link_loopback_set(s
, oi
);
712 oi
->lsa_pos_end
= links
;
720 /* Set router-LSA body. */
721 void ospf_router_lsa_body_set(struct stream
**s
, struct ospf_area
*area
)
727 stream_putc(*s
, router_lsa_flags(area
));
729 /* Set Zero fields. */
732 /* Keep pointer to # links. */
733 putp
= stream_get_endp(*s
);
738 /* Set all link information. */
739 cnt
= router_lsa_link_set(s
, area
);
741 /* Set # of links here. */
742 stream_putw_at(*s
, putp
, cnt
);
745 static void ospf_stub_router_timer(struct event
*t
)
747 struct ospf_area
*area
= EVENT_ARG(t
);
749 area
->t_stub_router
= NULL
;
751 SET_FLAG(area
->stub_router_state
, OSPF_AREA_WAS_START_STUB_ROUTED
);
753 /* clear stub route state and generate router-lsa refresh, don't
754 * clobber an administratively set stub-router state though.
756 if (CHECK_FLAG(area
->stub_router_state
, OSPF_AREA_ADMIN_STUB_ROUTED
))
759 UNSET_FLAG(area
->stub_router_state
, OSPF_AREA_IS_STUB_ROUTED
);
761 ospf_router_lsa_update_area(area
);
764 static void ospf_stub_router_check(struct ospf_area
*area
)
766 /* area must either be administratively configured to be stub
767 * or startup-time stub-router must be configured and we must in a
771 if (CHECK_FLAG(area
->stub_router_state
, OSPF_AREA_ADMIN_STUB_ROUTED
)) {
772 SET_FLAG(area
->stub_router_state
, OSPF_AREA_IS_STUB_ROUTED
);
776 /* not admin-stubbed, check whether startup stubbing is configured and
777 * whether it's not been done yet
779 if (CHECK_FLAG(area
->stub_router_state
,
780 OSPF_AREA_WAS_START_STUB_ROUTED
))
783 if (area
->ospf
->stub_router_startup_time
784 == OSPF_STUB_ROUTER_UNCONFIGURED
) {
785 /* stub-router is hence done forever for this area, even if
787 * tries configure it (take effect next restart).
789 SET_FLAG(area
->stub_router_state
,
790 OSPF_AREA_WAS_START_STUB_ROUTED
);
794 /* startup stub-router configured and not yet done */
795 SET_FLAG(area
->stub_router_state
, OSPF_AREA_IS_STUB_ROUTED
);
797 OSPF_AREA_TIMER_ON(area
->t_stub_router
, ospf_stub_router_timer
,
798 area
->ospf
->stub_router_startup_time
);
801 /* Create new router-LSA. */
802 static struct ospf_lsa
*ospf_router_lsa_new(struct ospf_area
*area
)
804 struct ospf
*ospf
= area
->ospf
;
806 struct lsa_header
*lsah
;
807 struct ospf_lsa
*new;
810 if (IS_DEBUG_OSPF(lsa
, LSA_GENERATE
))
811 zlog_debug("LSA[Type1]: Create router-LSA instance");
813 /* check whether stub-router is desired, and if this is the first
816 ospf_stub_router_check(area
);
818 /* Create a stream for LSA. */
819 s
= stream_new(OSPF_MAX_LSA_SIZE
);
820 /* Set LSA common header fields. */
821 lsa_header_set(s
, LSA_OPTIONS_GET(area
) | LSA_OPTIONS_NSSA_GET(area
),
822 OSPF_ROUTER_LSA
, ospf
->router_id
, ospf
->router_id
);
824 /* Set router-LSA body fields. */
825 ospf_router_lsa_body_set(&s
, area
);
828 length
= stream_get_endp(s
);
829 lsah
= (struct lsa_header
*)STREAM_DATA(s
);
830 lsah
->length
= htons(length
);
832 /* Now, create OSPF LSA instance. */
833 new = ospf_lsa_new_and_data(length
);
836 SET_FLAG(new->flags
, OSPF_LSA_SELF
| OSPF_LSA_SELF_CHECKED
);
837 new->vrf_id
= area
->ospf
->vrf_id
;
839 /* Copy LSA data to store, discard stream. */
840 memcpy(new->data
, lsah
, length
);
846 /* Originate Router-LSA. */
847 static struct ospf_lsa
*ospf_router_lsa_originate(struct ospf_area
*area
)
849 struct ospf_lsa
*new;
851 if (area
->ospf
->gr_info
.restart_in_progress
) {
852 if (IS_DEBUG_OSPF(lsa
, LSA_GENERATE
))
854 "LSA[Type%d]: Graceful Restart in progress, don't originate",
859 /* Create new router-LSA instance. */
860 if ((new = ospf_router_lsa_new(area
)) == NULL
) {
861 zlog_err("%s: ospf_router_lsa_new returned NULL", __func__
);
866 if (new->data
->adv_router
.s_addr
== INADDR_ANY
) {
867 if (IS_DEBUG_OSPF_EVENT
)
868 zlog_debug("LSA[Type1]: AdvRouter is 0, discard");
869 ospf_lsa_discard(new);
873 /* Install LSA to LSDB. */
874 new = ospf_lsa_install(area
->ospf
, NULL
, new);
876 /* Update LSA origination count. */
877 area
->ospf
->lsa_originate_count
++;
879 /* Flooding new LSA through area. */
880 ospf_flood_through_area(area
, NULL
, new);
882 if (IS_DEBUG_OSPF(lsa
, LSA_GENERATE
)) {
883 zlog_debug("LSA[Type%d:%pI4]: Originate router-LSA %p",
884 new->data
->type
, &new->data
->id
,
886 ospf_lsa_header_dump(new->data
);
892 /* Refresh router-LSA. */
893 static struct ospf_lsa
*ospf_router_lsa_refresh(struct ospf_lsa
*lsa
)
895 struct ospf_area
*area
= lsa
->area
;
896 struct ospf_lsa
*new;
901 /* Delete LSA from neighbor retransmit-list. */
902 ospf_ls_retransmit_delete_nbr_area(area
, lsa
);
904 /* Unregister LSA from refresh-list */
905 ospf_refresher_unregister_lsa(area
->ospf
, lsa
);
907 /* Create new router-LSA instance. */
908 if ((new = ospf_router_lsa_new(area
)) == NULL
) {
909 zlog_err("%s: ospf_router_lsa_new returned NULL", __func__
);
913 new->data
->ls_seqnum
= lsa_seqnum_increment(lsa
);
915 ospf_lsa_install(area
->ospf
, NULL
, new);
917 /* Flood LSA through area. */
918 ospf_flood_through_area(area
, NULL
, new);
921 if (IS_DEBUG_OSPF(lsa
, LSA_GENERATE
)) {
922 zlog_debug("LSA[Type%d:%pI4]: router-LSA refresh",
923 new->data
->type
, &new->data
->id
);
924 ospf_lsa_header_dump(new->data
);
930 int ospf_router_lsa_update_area(struct ospf_area
*area
)
932 if (IS_DEBUG_OSPF_EVENT
)
933 zlog_debug("[router-LSA]: (router-LSA area update)");
935 /* Now refresh router-LSA. */
936 if (area
->router_lsa_self
)
937 ospf_lsa_refresh(area
->ospf
, area
->router_lsa_self
);
938 /* Newly originate router-LSA. */
940 ospf_router_lsa_originate(area
);
945 int ospf_router_lsa_update(struct ospf
*ospf
)
947 struct listnode
*node
, *nnode
;
948 struct ospf_area
*area
;
950 if (IS_DEBUG_OSPF(lsa
, LSA_GENERATE
))
951 zlog_debug("Timer[router-LSA Update]: (timer expire)");
953 for (ALL_LIST_ELEMENTS(ospf
->areas
, node
, nnode
, area
)) {
954 struct ospf_lsa
*lsa
= area
->router_lsa_self
;
955 struct router_lsa
*rl
;
956 const char *area_str
;
958 /* Keep Area ID string. */
959 area_str
= AREA_NAME(area
);
961 /* If LSA not exist in this Area, originate new. */
963 if (IS_DEBUG_OSPF(lsa
, LSA_GENERATE
))
965 "LSA[Type1]: Create router-LSA for Area %s",
968 ospf_router_lsa_originate(area
);
970 /* If router-ID is changed, Link ID must change.
971 First flush old LSA, then originate new. */
972 else if (!IPV4_ADDR_SAME(&lsa
->data
->id
, &ospf
->router_id
)) {
973 if (IS_DEBUG_OSPF(lsa
, LSA_GENERATE
))
975 "LSA[Type%d:%pI4]: Refresh router-LSA for Area %s",
977 &lsa
->data
->id
, area_str
);
978 ospf_refresher_unregister_lsa(ospf
, lsa
);
979 ospf_lsa_flush_area(lsa
, area
);
980 ospf_lsa_unlock(&area
->router_lsa_self
);
981 area
->router_lsa_self
= NULL
;
983 /* Refresh router-LSA, (not install) and flood through
985 ospf_router_lsa_update_area(area
);
987 rl
= (struct router_lsa
*)lsa
->data
;
988 /* Refresh router-LSA, (not install) and flood through
990 if (rl
->flags
!= ospf
->flags
)
991 ospf_router_lsa_update_area(area
);
999 /* network-LSA related functions. */
1000 /* Originate Network-LSA. */
1001 static void ospf_network_lsa_body_set(struct stream
*s
,
1002 struct ospf_interface
*oi
)
1004 struct in_addr mask
;
1005 struct route_node
*rn
;
1006 struct ospf_neighbor
*nbr
;
1008 masklen2ip(oi
->address
->prefixlen
, &mask
);
1009 stream_put_ipv4(s
, mask
.s_addr
);
1011 /* The network-LSA lists those routers that are fully adjacent to
1012 the Designated Router; each fully adjacent router is identified by
1013 its OSPF Router ID. The Designated Router includes itself in this
1014 list. RFC2328, Section 12.4.2 */
1016 for (rn
= route_top(oi
->nbrs
); rn
; rn
= route_next(rn
))
1017 if ((nbr
= rn
->info
) != NULL
)
1018 if (nbr
->state
== NSM_Full
|| nbr
== oi
->nbr_self
)
1019 stream_put_ipv4(s
, nbr
->router_id
.s_addr
);
1022 static struct ospf_lsa
*ospf_network_lsa_new(struct ospf_interface
*oi
)
1025 struct ospf_lsa
*new;
1026 struct lsa_header
*lsah
;
1027 struct ospf_if_params
*oip
;
1030 /* If there are no neighbours on this network (the net is stub),
1031 the router does not originate network-LSA (see RFC 12.4.2) */
1032 if (oi
->full_nbrs
== 0)
1035 if (IS_DEBUG_OSPF(lsa
, LSA_GENERATE
))
1036 zlog_debug("LSA[Type2]: Create network-LSA instance");
1038 /* Create new stream for LSA. */
1039 s
= stream_new(OSPF_MAX_LSA_SIZE
);
1040 lsah
= (struct lsa_header
*)STREAM_DATA(s
);
1042 lsa_header_set(s
, (OPTIONS(oi
) | LSA_OPTIONS_GET(oi
->area
)),
1043 OSPF_NETWORK_LSA
, DR(oi
), oi
->ospf
->router_id
);
1045 /* Set network-LSA body fields. */
1046 ospf_network_lsa_body_set(s
, oi
);
1049 length
= stream_get_endp(s
);
1050 lsah
->length
= htons(length
);
1052 /* Create OSPF LSA instance. */
1053 new = ospf_lsa_new_and_data(length
);
1055 new->area
= oi
->area
;
1056 SET_FLAG(new->flags
, OSPF_LSA_SELF
| OSPF_LSA_SELF_CHECKED
);
1057 new->vrf_id
= oi
->ospf
->vrf_id
;
1059 /* Copy LSA to store. */
1060 memcpy(new->data
, lsah
, length
);
1063 /* Remember prior network LSA sequence numbers, even if we stop
1064 * originating one for this oi, to try avoid re-originating LSAs with a
1065 * prior sequence number, and thus speed up adjency forming &
1068 if ((oip
= ospf_lookup_if_params(oi
->ifp
, oi
->address
->u
.prefix4
))) {
1069 new->data
->ls_seqnum
= oip
->network_lsa_seqnum
;
1070 new->data
->ls_seqnum
= lsa_seqnum_increment(new);
1072 oip
= ospf_get_if_params(oi
->ifp
, oi
->address
->u
.prefix4
);
1073 ospf_if_update_params(oi
->ifp
, oi
->address
->u
.prefix4
);
1075 oip
->network_lsa_seqnum
= new->data
->ls_seqnum
;
1080 /* Originate network-LSA. */
1081 void ospf_network_lsa_update(struct ospf_interface
*oi
)
1083 struct ospf_lsa
*new;
1085 if (oi
->area
->ospf
->gr_info
.restart_in_progress
) {
1086 if (IS_DEBUG_OSPF(lsa
, LSA_GENERATE
))
1088 "LSA[Type%d]: Graceful Restart in progress, don't originate",
1093 if (oi
->network_lsa_self
!= NULL
) {
1094 ospf_lsa_refresh(oi
->ospf
, oi
->network_lsa_self
);
1098 /* Create new network-LSA instance. */
1099 new = ospf_network_lsa_new(oi
);
1103 /* Install LSA to LSDB. */
1104 new = ospf_lsa_install(oi
->ospf
, oi
, new);
1106 /* Update LSA origination count. */
1107 oi
->ospf
->lsa_originate_count
++;
1109 /* Flooding new LSA through area. */
1110 ospf_flood_through_area(oi
->area
, NULL
, new);
1112 if (IS_DEBUG_OSPF(lsa
, LSA_GENERATE
)) {
1113 zlog_debug("LSA[Type%d:%pI4]: Originate network-LSA %p",
1114 new->data
->type
, &new->data
->id
,
1116 ospf_lsa_header_dump(new->data
);
1122 static struct ospf_lsa
*ospf_network_lsa_refresh(struct ospf_lsa
*lsa
)
1124 struct ospf_area
*area
= lsa
->area
;
1125 struct ospf_lsa
*new, *new2
;
1126 struct ospf_if_params
*oip
;
1127 struct ospf_interface
*oi
;
1131 /* Retrieve the oi for the network LSA */
1132 oi
= ospf_if_lookup_by_local_addr(area
->ospf
, NULL
, lsa
->data
->id
);
1134 if (IS_DEBUG_OSPF(lsa
, LSA_GENERATE
)) {
1136 "LSA[Type%d:%pI4]: network-LSA refresh: no oi found, ick, ignoring.",
1137 lsa
->data
->type
, &lsa
->data
->id
);
1138 ospf_lsa_header_dump(lsa
->data
);
1143 if (oi
->state
!= ISM_DR
)
1146 /* Delete LSA from neighbor retransmit-list. */
1147 ospf_ls_retransmit_delete_nbr_area(area
, lsa
);
1149 /* Unregister LSA from refresh-list */
1150 ospf_refresher_unregister_lsa(area
->ospf
, lsa
);
1152 /* Create new network-LSA instance. */
1153 new = ospf_network_lsa_new(oi
);
1157 oip
= ospf_lookup_if_params(oi
->ifp
, oi
->address
->u
.prefix4
);
1158 assert(oip
!= NULL
);
1159 oip
->network_lsa_seqnum
= new->data
->ls_seqnum
=
1160 lsa_seqnum_increment(lsa
);
1162 new2
= ospf_lsa_install(area
->ospf
, oi
, new);
1164 assert(new2
== new);
1166 /* Flood LSA through aera. */
1167 ospf_flood_through_area(area
, NULL
, new);
1169 if (IS_DEBUG_OSPF(lsa
, LSA_GENERATE
)) {
1170 zlog_debug("LSA[Type%d:%pI4]: network-LSA refresh",
1171 new->data
->type
, &new->data
->id
);
1172 ospf_lsa_header_dump(new->data
);
1178 static void stream_put_ospf_metric(struct stream
*s
, uint32_t metric_value
)
1183 /* Put 0 metric. TOS metric is not supported. */
1184 metric
= htonl(metric_value
);
1185 mp
= (char *)&metric
;
1187 stream_put(s
, mp
, 3);
1190 /* summary-LSA related functions. */
1191 static void ospf_summary_lsa_body_set(struct stream
*s
, struct prefix
*p
,
1194 struct in_addr mask
;
1196 masklen2ip(p
->prefixlen
, &mask
);
1198 /* Put Network Mask. */
1199 stream_put_ipv4(s
, mask
.s_addr
);
1202 stream_putc(s
, (uint8_t)0);
1205 stream_put_ospf_metric(s
, metric
);
1208 static struct ospf_lsa
*ospf_summary_lsa_new(struct ospf_area
*area
,
1209 struct prefix
*p
, uint32_t metric
,
1213 struct ospf_lsa
*new;
1214 struct lsa_header
*lsah
;
1217 if (id
.s_addr
== 0xffffffff) {
1218 /* Maybe Link State ID not available. */
1219 if (IS_DEBUG_OSPF(lsa
, LSA_GENERATE
))
1221 "LSA[Type%d]: Link ID not available, can't originate",
1226 if (IS_DEBUG_OSPF(lsa
, LSA_GENERATE
))
1227 zlog_debug("LSA[Type3]: Create summary-LSA instance");
1229 /* Create new stream for LSA. */
1230 s
= stream_new(OSPF_MAX_LSA_SIZE
);
1231 lsah
= (struct lsa_header
*)STREAM_DATA(s
);
1233 lsa_header_set(s
, LSA_OPTIONS_GET(area
), OSPF_SUMMARY_LSA
, id
,
1234 area
->ospf
->router_id
);
1236 /* Set summary-LSA body fields. */
1237 ospf_summary_lsa_body_set(s
, p
, metric
);
1240 length
= stream_get_endp(s
);
1241 lsah
->length
= htons(length
);
1243 /* Create OSPF LSA instance. */
1244 new = ospf_lsa_new_and_data(length
);
1246 SET_FLAG(new->flags
, OSPF_LSA_SELF
| OSPF_LSA_SELF_CHECKED
);
1247 new->vrf_id
= area
->ospf
->vrf_id
;
1249 /* Copy LSA to store. */
1250 memcpy(new->data
, lsah
, length
);
1256 /* Originate Summary-LSA. */
1257 static struct ospf_lsa
*
1258 ospf_summary_lsa_prepare_and_flood(struct prefix_ipv4
*p
, uint32_t metric
,
1259 struct ospf_area
*area
, struct in_addr id
)
1261 struct ospf_lsa
*new;
1263 /* Create new summary-LSA instance. */
1264 if (!(new = ospf_summary_lsa_new(area
, (struct prefix
*)p
, metric
, id
)))
1267 /* Instlal LSA to LSDB. */
1268 new = ospf_lsa_install(area
->ospf
, NULL
, new);
1270 /* Update LSA origination count. */
1271 area
->ospf
->lsa_originate_count
++;
1273 /* Flooding new LSA through area. */
1274 ospf_flood_through_area(area
, NULL
, new);
1276 if (IS_DEBUG_OSPF(lsa
, LSA_GENERATE
)) {
1277 zlog_debug("LSA[Type%d:%pI4]: Originate summary-LSA %p",
1278 new->data
->type
, &new->data
->id
,
1280 ospf_lsa_header_dump(new->data
);
1286 static struct ospf_lsa
*ospf_handle_summarylsa_lsId_chg(struct ospf_area
*area
,
1287 struct prefix_ipv4
*p
,
1290 struct in_addr old_id
)
1292 struct ospf_lsa
*lsa
= NULL
;
1293 struct ospf_lsa
*summary_lsa
= NULL
;
1294 struct summary_lsa
*sl
= NULL
;
1295 struct ospf_area
*old_area
= NULL
;
1296 struct ospf
*ospf
= area
->ospf
;
1297 struct prefix_ipv4 old_prefix
;
1298 uint32_t old_metric
;
1299 struct in_addr mask
;
1300 uint32_t metric_val
;
1303 lsa
= ospf_lsdb_lookup_by_id(area
->lsdb
, type
, p
->prefix
,
1307 flog_warn(EC_OSPF_LSA_NULL
, "(%s): LSA not found", __func__
);
1311 sl
= (struct summary_lsa
*)lsa
->data
;
1313 old_area
= lsa
->area
;
1314 old_metric
= GET_METRIC(sl
->metric
);
1315 old_prefix
.prefix
= sl
->header
.id
;
1316 old_prefix
.prefixlen
= ip_masklen(sl
->mask
);
1317 old_prefix
.family
= AF_INET
;
1320 /* change the mask */
1321 masklen2ip(p
->prefixlen
, &mask
);
1322 sl
->mask
.s_addr
= mask
.s_addr
;
1324 /* Copy the metric*/
1325 metric_val
= htonl(metric
);
1326 metric_buf
= (char *)&metric_val
;
1327 memcpy(sl
->metric
, metric_buf
, sizeof(metric_val
));
1329 if (type
== OSPF_SUMMARY_LSA
) {
1330 /*Refresh the LSA with new LSA*/
1331 summary_lsa
= ospf_summary_lsa_refresh(ospf
, lsa
);
1333 ospf_summary_lsa_prepare_and_flood(&old_prefix
, old_metric
,
1336 /*Refresh the LSA with new LSA*/
1337 summary_lsa
= ospf_summary_asbr_lsa_refresh(ospf
, lsa
);
1339 ospf_asbr_summary_lsa_prepare_and_flood(&old_prefix
, old_metric
,
1346 /* Originate Summary-LSA. */
1347 struct ospf_lsa
*ospf_summary_lsa_originate(struct prefix_ipv4
*p
,
1349 struct ospf_area
*area
)
1352 enum lsid_status status
;
1353 struct ospf_lsa
*new = NULL
;
1355 status
= ospf_lsa_unique_id(area
->ospf
, area
->lsdb
, OSPF_SUMMARY_LSA
, p
,
1358 if (status
== LSID_CHANGE
) {
1359 if (IS_DEBUG_OSPF(lsa
, LSA_GENERATE
))
1360 zlog_debug("Link ID has to be changed.");
1362 new = ospf_handle_summarylsa_lsId_chg(area
, p
, OSPF_SUMMARY_LSA
,
1365 } else if (status
== LSID_NOT_AVAILABLE
) {
1366 /* Link State ID not available. */
1367 if (IS_DEBUG_OSPF(lsa
, LSA_GENERATE
))
1369 "LSA[Type5]: Link ID not available, can't originate");
1374 new = ospf_summary_lsa_prepare_and_flood(p
, metric
, area
, id
);
1378 static struct ospf_lsa
*ospf_summary_lsa_refresh(struct ospf
*ospf
,
1379 struct ospf_lsa
*lsa
)
1381 struct ospf_lsa
*new;
1382 struct summary_lsa
*sl
;
1388 sl
= (struct summary_lsa
*)lsa
->data
;
1389 p
.prefixlen
= ip_masklen(sl
->mask
);
1390 new = ospf_summary_lsa_new(lsa
->area
, &p
, GET_METRIC(sl
->metric
),
1396 new->data
->ls_seqnum
= lsa_seqnum_increment(lsa
);
1398 ospf_lsa_install(ospf
, NULL
, new);
1400 /* Flood LSA through AS. */
1401 ospf_flood_through_area(new->area
, NULL
, new);
1403 /* Debug logging. */
1404 if (IS_DEBUG_OSPF(lsa
, LSA_GENERATE
)) {
1405 zlog_debug("LSA[Type%d:%pI4]: summary-LSA refresh",
1406 new->data
->type
, &new->data
->id
);
1407 ospf_lsa_header_dump(new->data
);
1414 /* summary-ASBR-LSA related functions. */
1415 static void ospf_summary_asbr_lsa_body_set(struct stream
*s
, struct prefix
*p
,
1418 /* Put Network Mask. */
1419 stream_put_ipv4(s
, (uint32_t)0);
1422 stream_putc(s
, (uint8_t)0);
1425 stream_put_ospf_metric(s
, metric
);
1428 static struct ospf_lsa
*ospf_summary_asbr_lsa_new(struct ospf_area
*area
,
1434 struct ospf_lsa
*new;
1435 struct lsa_header
*lsah
;
1438 if (id
.s_addr
== 0xffffffff) {
1439 /* Maybe Link State ID not available. */
1440 if (IS_DEBUG_OSPF(lsa
, LSA_GENERATE
))
1442 "LSA[Type%d]: Link ID not available, can't originate",
1443 OSPF_ASBR_SUMMARY_LSA
);
1447 if (IS_DEBUG_OSPF(lsa
, LSA_GENERATE
))
1448 zlog_debug("LSA[Type3]: Create summary-LSA instance");
1450 /* Create new stream for LSA. */
1451 s
= stream_new(OSPF_MAX_LSA_SIZE
);
1452 lsah
= (struct lsa_header
*)STREAM_DATA(s
);
1454 lsa_header_set(s
, LSA_OPTIONS_GET(area
), OSPF_ASBR_SUMMARY_LSA
, id
,
1455 area
->ospf
->router_id
);
1457 /* Set summary-LSA body fields. */
1458 ospf_summary_asbr_lsa_body_set(s
, p
, metric
);
1461 length
= stream_get_endp(s
);
1462 lsah
->length
= htons(length
);
1464 /* Create OSPF LSA instance. */
1465 new = ospf_lsa_new_and_data(length
);
1467 SET_FLAG(new->flags
, OSPF_LSA_SELF
| OSPF_LSA_SELF_CHECKED
);
1468 new->vrf_id
= area
->ospf
->vrf_id
;
1470 /* Copy LSA to store. */
1471 memcpy(new->data
, lsah
, length
);
1477 /* Originate summary-ASBR-LSA. */
1478 static struct ospf_lsa
*
1479 ospf_asbr_summary_lsa_prepare_and_flood(struct prefix_ipv4
*p
, uint32_t metric
,
1480 struct ospf_area
*area
,
1483 struct ospf_lsa
*new;
1485 /* Create new summary-LSA instance. */
1486 new = ospf_summary_asbr_lsa_new(area
, (struct prefix
*)p
, metric
, id
);
1490 /* Install LSA to LSDB. */
1491 new = ospf_lsa_install(area
->ospf
, NULL
, new);
1493 /* Update LSA origination count. */
1494 area
->ospf
->lsa_originate_count
++;
1496 /* Flooding new LSA through area. */
1497 ospf_flood_through_area(area
, NULL
, new);
1499 if (IS_DEBUG_OSPF(lsa
, LSA_GENERATE
)) {
1500 zlog_debug("LSA[Type%d:%pI4]: Originate summary-ASBR-LSA %p",
1501 new->data
->type
, &new->data
->id
,
1503 ospf_lsa_header_dump(new->data
);
1509 struct ospf_lsa
*ospf_summary_asbr_lsa_originate(struct prefix_ipv4
*p
,
1511 struct ospf_area
*area
)
1513 struct ospf_lsa
*new;
1515 enum lsid_status status
;
1517 status
= ospf_lsa_unique_id(area
->ospf
, area
->lsdb
,
1518 OSPF_ASBR_SUMMARY_LSA
, p
, &id
);
1520 if (status
== LSID_CHANGE
) {
1521 if (IS_DEBUG_OSPF(lsa
, LSA_GENERATE
))
1522 zlog_debug("Link ID has to be changed.");
1524 new = ospf_handle_summarylsa_lsId_chg(
1525 area
, p
, OSPF_ASBR_SUMMARY_LSA
, metric
, id
);
1527 } else if (status
== LSID_NOT_AVAILABLE
) {
1528 /* Link State ID not available. */
1529 if (IS_DEBUG_OSPF(lsa
, LSA_GENERATE
))
1531 "LSA[Type5]: Link ID not available, can't originate");
1536 new = ospf_asbr_summary_lsa_prepare_and_flood(p
, metric
, area
, id
);
1540 static struct ospf_lsa
*ospf_summary_asbr_lsa_refresh(struct ospf
*ospf
,
1541 struct ospf_lsa
*lsa
)
1543 struct ospf_lsa
*new;
1544 struct summary_lsa
*sl
;
1546 bool ind_lsa
= false;
1551 if (lsa
->area
->fr_info
.indication_lsa_self
&&
1552 (lsa
->area
->fr_info
.indication_lsa_self
== lsa
))
1555 sl
= (struct summary_lsa
*)lsa
->data
;
1556 p
.prefixlen
= ip_masklen(sl
->mask
);
1557 new = ospf_summary_asbr_lsa_new(lsa
->area
, &p
, GET_METRIC(sl
->metric
),
1562 new->data
->ls_seqnum
= lsa_seqnum_increment(lsa
);
1564 ospf_lsa_install(ospf
, NULL
, new);
1566 /* Flood LSA through area. */
1567 ospf_flood_through_area(new->area
, NULL
, new);
1570 new->area
->fr_info
.indication_lsa_self
= new;
1572 if (IS_DEBUG_OSPF(lsa
, LSA_GENERATE
)) {
1573 zlog_debug("LSA[Type%d:%pI4]: summary-ASBR-LSA refresh",
1574 new->data
->type
, &new->data
->id
);
1575 ospf_lsa_header_dump(new->data
);
1581 /* AS-external-LSA related functions. */
1583 /* Get nexthop for AS-external-LSAs. Return nexthop if its interface
1584 is connected, else 0*/
1585 static struct in_addr
ospf_external_lsa_nexthop_get(struct ospf
*ospf
,
1586 struct in_addr nexthop
)
1590 struct listnode
*node
;
1591 struct ospf_interface
*oi
;
1595 if (!nexthop
.s_addr
)
1598 /* Check whether nexthop is covered by OSPF network. */
1599 nh
.family
= AF_INET
;
1600 nh
.u
.prefix4
= nexthop
;
1601 nh
.prefixlen
= IPV4_MAX_BITLEN
;
1603 /* XXX/SCALE: If there were a lot of oi's on an ifp, then it'd be
1604 * better to make use of the per-ifp table of ois.
1606 for (ALL_LIST_ELEMENTS_RO(ospf
->oiflist
, node
, oi
))
1607 if (if_is_operative(oi
->ifp
))
1608 if (oi
->address
->family
== AF_INET
)
1609 if (prefix_match(oi
->address
, &nh
))
1615 /* NSSA-external-LSA related functions. */
1617 /* Get 1st IP connection for Forward Addr */
1619 struct in_addr
ospf_get_ip_from_ifp(struct ospf_interface
*oi
)
1623 fwd
.s_addr
= INADDR_ANY
;
1625 if (if_is_operative(oi
->ifp
))
1626 return oi
->address
->u
.prefix4
;
1631 /* Get 1st IP connection for Forward Addr */
1632 struct in_addr
ospf_get_nssa_ip(struct ospf_area
*area
)
1635 struct in_addr best_default
;
1636 struct listnode
*node
;
1637 struct ospf_interface
*oi
;
1640 best_default
.s_addr
= 0;
1642 for (ALL_LIST_ELEMENTS_RO(area
->ospf
->oiflist
, node
, oi
)) {
1643 if (if_is_operative(oi
->ifp
))
1644 if (oi
->area
->external_routing
== OSPF_AREA_NSSA
)
1646 && oi
->address
->family
== AF_INET
) {
1647 if (best_default
.s_addr
== INADDR_ANY
)
1649 oi
->address
->u
.prefix4
;
1650 if (oi
->area
== area
)
1651 return oi
->address
->u
.prefix4
;
1654 if (best_default
.s_addr
!= INADDR_ANY
)
1655 return best_default
;
1660 int metric_type(struct ospf
*ospf
, uint8_t src
, unsigned short instance
)
1662 struct ospf_redist
*red
;
1664 red
= ospf_redist_lookup(ospf
, src
, instance
);
1666 return ((!red
|| red
->dmetric
.type
< 0) ? DEFAULT_METRIC_TYPE
1667 : red
->dmetric
.type
);
1670 int metric_value(struct ospf
*ospf
, uint8_t src
, unsigned short instance
)
1672 struct ospf_redist
*red
;
1674 red
= ospf_redist_lookup(ospf
, src
, instance
);
1675 if (!red
|| red
->dmetric
.value
< 0) {
1676 if (src
== DEFAULT_ROUTE
) {
1677 if (ospf
->default_originate
== DEFAULT_ORIGINATE_ZEBRA
)
1678 return DEFAULT_DEFAULT_ORIGINATE_METRIC
;
1680 return DEFAULT_DEFAULT_ALWAYS_METRIC
;
1681 } else if (ospf
->default_metric
< 0)
1682 return DEFAULT_DEFAULT_METRIC
;
1684 return ospf
->default_metric
;
1687 return red
->dmetric
.value
;
1690 /* Set AS-external-LSA body. */
1691 static void ospf_external_lsa_body_set(struct stream
*s
,
1692 struct external_info
*ei
,
1695 struct prefix_ipv4
*p
= &ei
->p
;
1696 struct in_addr mask
, fwd_addr
;
1700 unsigned short instance
;
1702 /* Put Network Mask. */
1703 masklen2ip(p
->prefixlen
, &mask
);
1704 stream_put_ipv4(s
, mask
.s_addr
);
1706 /* If prefix is default, specify DEFAULT_ROUTE. */
1707 type
= is_default_prefix4(&ei
->p
) ? DEFAULT_ROUTE
: ei
->type
;
1708 instance
= is_default_prefix4(&ei
->p
) ? 0 : ei
->instance
;
1710 mtype
= (ROUTEMAP_METRIC_TYPE(ei
) != -1)
1711 ? ROUTEMAP_METRIC_TYPE(ei
)
1712 : metric_type(ospf
, type
, instance
);
1714 mvalue
= (ROUTEMAP_METRIC(ei
) != -1)
1715 ? ROUTEMAP_METRIC(ei
)
1716 : metric_value(ospf
, type
, instance
);
1718 /* Put type of external metric. */
1719 stream_putc(s
, (mtype
== EXTERNAL_METRIC_TYPE_2
? 0x80 : 0));
1721 /* Put 0 metric. TOS metric is not supported. */
1722 stream_put_ospf_metric(s
, mvalue
);
1724 /* Get forwarding address to nexthop if on the Connection List, else 0.
1726 fwd_addr
= ospf_external_lsa_nexthop_get(ospf
, ei
->nexthop
);
1728 /* Put forwarding address. */
1729 stream_put_ipv4(s
, fwd_addr
.s_addr
);
1732 stream_putl(s
, ei
->tag
);
1735 /* Create new external-LSA. */
1736 static struct ospf_lsa
*
1737 ospf_exnl_lsa_prepare_and_flood(struct ospf
*ospf
, struct external_info
*ei
,
1741 struct lsa_header
*lsah
;
1742 struct ospf_lsa
*new;
1745 /* Create new stream for LSA. */
1746 s
= stream_new(OSPF_MAX_LSA_SIZE
);
1747 lsah
= (struct lsa_header
*)STREAM_DATA(s
);
1749 /* Set LSA common header fields. */
1750 lsa_header_set(s
, OSPF_OPTION_E
, OSPF_AS_EXTERNAL_LSA
, id
,
1753 /* Set AS-external-LSA body fields. */
1754 ospf_external_lsa_body_set(s
, ei
, ospf
);
1757 length
= stream_get_endp(s
);
1758 lsah
->length
= htons(length
);
1760 /* Now, create OSPF LSA instance. */
1761 new = ospf_lsa_new_and_data(length
);
1763 SET_FLAG(new->flags
,
1764 OSPF_LSA_SELF
| OSPF_LSA_APPROVED
| OSPF_LSA_SELF_CHECKED
);
1765 new->vrf_id
= ospf
->vrf_id
;
1767 /* Copy LSA data to store, discard stream. */
1768 memcpy(new->data
, lsah
, length
);
1774 static struct ospf_lsa
*ospf_handle_exnl_lsa_lsId_chg(struct ospf
*ospf
,
1775 struct external_info
*ei
,
1778 struct ospf_lsa
*lsa
;
1779 struct as_external_lsa
*al
;
1780 struct in_addr mask
;
1781 struct ospf_lsa
*new;
1782 struct external_info ei_summary
= {};
1783 struct external_info
*ei_old
;
1785 lsa
= ospf_lsdb_lookup_by_id(ospf
->lsdb
, OSPF_AS_EXTERNAL_LSA
,
1786 ei
->p
.prefix
, ospf
->router_id
);
1789 flog_warn(EC_OSPF_LSA_NULL
, "(%s): LSA not found", __func__
);
1793 ei_old
= ospf_external_info_check(ospf
, lsa
);
1795 al
= (struct as_external_lsa
*)lsa
->data
;
1798 /* eii_old pointer of LSA is NULL, this
1799 * must be external aggregate route.
1801 ei_summary
.p
.family
= AF_INET
;
1802 ei_summary
.p
.prefix
= al
->header
.id
;
1803 ei_summary
.p
.prefixlen
= ip_masklen(al
->mask
);
1804 ei_summary
.tag
= (unsigned long)ntohl(al
->e
[0].route_tag
);
1805 ei_old
= &ei_summary
;
1808 /* change the mask */
1809 masklen2ip(ei
->p
.prefixlen
, &mask
);
1810 al
->mask
.s_addr
= mask
.s_addr
;
1812 /*Refresh the LSA with new LSA*/
1813 ospf_external_lsa_refresh(ospf
, lsa
, ei
, LSA_REFRESH_FORCE
, 0);
1815 /*Originate the old LSA with changed LSID*/
1816 new = ospf_exnl_lsa_prepare_and_flood(ospf
, ei_old
, id
);
1821 static struct ospf_lsa
*ospf_external_lsa_new(struct ospf
*ospf
,
1822 struct external_info
*ei
,
1823 struct in_addr
*old_id
)
1825 struct ospf_lsa
*new;
1827 enum lsid_status status
;
1830 if (IS_DEBUG_OSPF(lsa
, LSA_GENERATE
))
1832 "LSA[Type5]: External info is NULL, can't originate");
1836 if (IS_DEBUG_OSPF(lsa
, LSA_GENERATE
))
1837 zlog_debug("LSA[Type5]: Originate AS-external-LSA instance");
1839 /* If old Link State ID is specified, refresh LSA with same ID. */
1842 /* Get Link State with unique ID. */
1844 status
= ospf_lsa_unique_id(ospf
, ospf
->lsdb
,
1845 OSPF_AS_EXTERNAL_LSA
, &ei
->p
, &id
);
1847 if (status
== LSID_CHANGE
) {
1848 if (IS_DEBUG_OSPF(lsa
, LSA_GENERATE
))
1849 zlog_debug("Link ID has to be changed.");
1851 new = ospf_handle_exnl_lsa_lsId_chg(ospf
, ei
, id
);
1853 } else if (status
== LSID_NOT_AVAILABLE
) {
1854 /* Link State ID not available. */
1855 if (IS_DEBUG_OSPF(lsa
, LSA_GENERATE
))
1857 "LSA[Type5]: Link ID not available, can't originate");
1862 new = ospf_exnl_lsa_prepare_and_flood(ospf
, ei
, id
);
1868 static void ospf_install_flood_nssa(struct ospf
*ospf
, struct ospf_lsa
*lsa
)
1870 struct ospf_lsa
*new;
1871 struct as_external_lsa
*extlsa
;
1872 struct ospf_area
*area
;
1873 struct listnode
*node
, *nnode
;
1875 /* LSA may be a Type-5 originated via translation of a Type-7 LSA
1876 * which originated from an NSSA area. In which case it should not be
1877 * flooded back to NSSA areas.
1879 if (CHECK_FLAG(lsa
->flags
, OSPF_LSA_LOCAL_XLT
))
1882 /* NSSA Originate or Refresh (If anyNSSA)
1884 LSA is self-originated. And just installed as Type-5.
1885 Additionally, install as Type-7 LSDB for every attached NSSA.
1887 P-Bit controls which ABR performs translation to outside world; If
1888 we are an ABR....do not set the P-bit, because we send the Type-5,
1889 not as the ABR Translator, but as the ASBR owner within the AS!
1891 If we are NOT ABR, Flood through NSSA as Type-7 w/P-bit set. The
1892 elected ABR Translator will see the P-bit, Translate, and re-flood.
1894 Later, ABR_TASK and P-bit will scan Type-7 LSDB and translate to
1895 Type-5's to non-NSSA Areas. (it will also attempt a re-install) */
1897 for (ALL_LIST_ELEMENTS(ospf
->areas
, node
, nnode
, area
)) {
1898 /* Don't install Type-7 LSA's into nonNSSA area */
1899 if (area
->external_routing
!= OSPF_AREA_NSSA
)
1902 /* make lsa duplicate, lock=1 */
1903 new = ospf_lsa_dup(lsa
);
1905 new->data
->type
= OSPF_AS_NSSA_LSA
;
1907 /* set P-bit if not ABR */
1908 if (!IS_OSPF_ABR(ospf
)) {
1909 SET_FLAG(new->data
->options
, OSPF_OPTION_NP
);
1911 /* set non-zero FWD ADDR
1913 draft-ietf-ospf-nssa-update-09.txt
1915 if the network between the NSSA AS boundary router and
1917 adjacent AS is advertised into OSPF as an internal OSPF
1919 the forwarding address should be the next op address as
1921 currently done with type-5 LSAs. If the intervening
1923 not adversited into OSPF as an internal OSPF route and
1925 type-7 LSA's P-bit is set a forwarding address should be
1926 selected from one of the router's active OSPF interface
1928 which belong to the NSSA. If no such addresses exist,
1930 no type-7 LSA's with the P-bit set should originate from
1934 /* kevinm: not updating lsa anymore, just new */
1935 extlsa
= (struct as_external_lsa
*)(new->data
);
1937 if (extlsa
->e
[0].fwd_addr
.s_addr
== INADDR_ANY
)
1938 extlsa
->e
[0].fwd_addr
= ospf_get_nssa_ip(
1939 area
); /* this NSSA area in ifp */
1941 if (extlsa
->e
[0].fwd_addr
.s_addr
== INADDR_ANY
) {
1942 if (IS_DEBUG_OSPF_NSSA
)
1944 "LSA[Type-7]: Could not build FWD-ADDR");
1945 ospf_lsa_discard(new);
1950 /* install also as Type-7 */
1951 ospf_lsa_install(ospf
, NULL
,
1952 new); /* Remove Old, Lock New = 2 */
1954 /* will send each copy, lock=2+n */
1955 ospf_flood_through_as(
1956 ospf
, NULL
, new); /* all attached NSSA's, no AS/STUBs */
1960 static struct ospf_lsa
*ospf_lsa_translated_nssa_new(struct ospf
*ospf
,
1961 struct ospf_lsa
*type7
)
1964 struct ospf_lsa
*new;
1965 struct as_external_lsa
*ext
, *extnew
;
1966 struct external_info ei
;
1968 ext
= (struct as_external_lsa
*)(type7
->data
);
1970 /* need external_info struct, fill in bare minimum */
1971 ei
.p
.family
= AF_INET
;
1972 ei
.p
.prefix
= type7
->data
->id
;
1973 ei
.p
.prefixlen
= ip_masklen(ext
->mask
);
1974 ei
.type
= ZEBRA_ROUTE_OSPF
;
1975 ei
.nexthop
= ext
->header
.adv_router
;
1976 ei
.route_map_set
.metric
= -1;
1977 ei
.route_map_set
.metric_type
= -1;
1981 if ((new = ospf_external_lsa_new(ospf
, &ei
, &type7
->data
->id
))
1983 if (IS_DEBUG_OSPF_NSSA
)
1985 "%s: Could not originate Translated Type-5 for %pI4",
1986 __func__
, &ei
.p
.prefix
);
1990 extnew
= (struct as_external_lsa
*)(new->data
);
1992 /* copy over Type-7 data to new */
1993 extnew
->e
[0].tos
= ext
->e
[0].tos
;
1994 extnew
->e
[0].route_tag
= ext
->e
[0].route_tag
;
1995 if (type7
->area
->suppress_fa
) {
1996 extnew
->e
[0].fwd_addr
.s_addr
= 0;
1997 if (IS_DEBUG_OSPF_NSSA
)
1998 zlog_debug("%s: Suppress forwarding address for %pI4",
1999 __func__
, &ei
.p
.prefix
);
2001 extnew
->e
[0].fwd_addr
.s_addr
= ext
->e
[0].fwd_addr
.s_addr
;
2002 new->data
->ls_seqnum
= type7
->data
->ls_seqnum
;
2004 /* add translated flag, checksum and lock new lsa */
2005 SET_FLAG(new->flags
, OSPF_LSA_LOCAL_XLT
); /* Translated from 7 */
2006 new = ospf_lsa_lock(new);
2011 /* Originate Translated Type-5 for supplied Type-7 NSSA LSA */
2012 struct ospf_lsa
*ospf_translated_nssa_originate(struct ospf
*ospf
,
2013 struct ospf_lsa
*type7
,
2014 struct ospf_lsa
*type5
)
2016 struct ospf_lsa
*new, *translated_lsa
;
2017 struct as_external_lsa
*extnew
;
2019 if (ospf
->gr_info
.restart_in_progress
) {
2020 if (IS_DEBUG_OSPF(lsa
, LSA_GENERATE
))
2022 "LSA[Translated Type5]: Graceful Restart in progress, don't originate");
2026 /* we cant use ospf_external_lsa_originate() as we need to set
2027 * the OSPF_LSA_LOCAL_XLT flag, must originate by hand
2030 if ((translated_lsa
= ospf_lsa_translated_nssa_new(ospf
, type7
)) ==
2032 if (IS_DEBUG_OSPF_NSSA
)
2034 "%s: Could not translate Type-7, Id %pI4, to Type-5",
2035 __func__
, &type7
->data
->id
);
2039 extnew
= (struct as_external_lsa
*)translated_lsa
->data
;
2041 /* Update LSA sequence number from translated Type-5 LSA */
2043 translated_lsa
->data
->ls_seqnum
= lsa_seqnum_increment(type5
);
2045 if ((new = ospf_lsa_install(ospf
, NULL
, translated_lsa
)) == NULL
) {
2046 flog_warn(EC_OSPF_LSA_INSTALL_FAILURE
,
2047 "%s: Could not install LSA id %pI4", __func__
,
2049 ospf_lsa_free(translated_lsa
);
2053 if (IS_DEBUG_OSPF_NSSA
) {
2054 zlog_debug("%s: translated Type 7, installed", __func__
);
2055 ospf_lsa_header_dump(new->data
);
2056 zlog_debug(" Network mask: %d", ip_masklen(extnew
->mask
));
2057 zlog_debug(" Forward addr: %pI4",
2058 &extnew
->e
[0].fwd_addr
);
2061 ospf
->lsa_originate_count
++;
2062 ospf_flood_through_as(ospf
, NULL
, new);
2067 /* Refresh Translated from NSSA AS-external-LSA. */
2068 struct ospf_lsa
*ospf_translated_nssa_refresh(struct ospf
*ospf
,
2069 struct ospf_lsa
*type7
,
2070 struct ospf_lsa
*type5
)
2072 struct ospf_lsa
*new = NULL
, *translated_lsa
= NULL
;
2073 struct as_external_lsa
*extold
= NULL
;
2074 uint32_t ls_seqnum
= 0;
2076 /* Sanity checks. */
2077 assert(type7
|| type5
);
2078 if (!(type7
|| type5
))
2081 assert(type7
->data
);
2083 assert(type5
->data
);
2084 assert(ospf
->anyNSSA
);
2086 /* get required data according to what has been given */
2087 if (type7
&& type5
== NULL
) {
2088 /* find the translated Type-5 for this Type-7 */
2089 struct as_external_lsa
*ext
=
2090 (struct as_external_lsa
*)(type7
->data
);
2091 struct prefix_ipv4 p
= {
2092 .prefix
= type7
->data
->id
,
2093 .prefixlen
= ip_masklen(ext
->mask
),
2097 type5
= ospf_external_info_find_lsa(ospf
, &p
);
2098 } else if (type5
&& type7
== NULL
) {
2099 /* find the type-7 from which supplied type-5 was translated,
2100 * ie find first type-7 with same LSA Id.
2102 struct listnode
*ln
, *lnn
;
2103 struct route_node
*rn
;
2104 struct ospf_lsa
*lsa
;
2105 struct ospf_area
*area
;
2107 for (ALL_LIST_ELEMENTS(ospf
->areas
, ln
, lnn
, area
)) {
2108 if (area
->external_routing
!= OSPF_AREA_NSSA
&& !type7
)
2111 LSDB_LOOP (NSSA_LSDB(area
), rn
, lsa
) {
2112 if (lsa
->data
->id
.s_addr
2113 == type5
->data
->id
.s_addr
) {
2121 /* do we have type7? */
2123 if (IS_DEBUG_OSPF_NSSA
)
2124 zlog_debug("%s: no Type-7 found for Type-5 LSA Id %pI4",
2125 __func__
, &type5
->data
->id
);
2129 /* do we have valid translated type5? */
2130 if (type5
== NULL
|| !CHECK_FLAG(type5
->flags
, OSPF_LSA_LOCAL_XLT
)) {
2131 if (IS_DEBUG_OSPF_NSSA
)
2133 "%s: No translated Type-5 found for Type-7 with Id %pI4",
2134 __func__
, &type7
->data
->id
);
2138 extold
= (struct as_external_lsa
*)type5
->data
;
2139 if (type7
->area
->suppress_fa
== 1) {
2140 if (extold
->e
[0].fwd_addr
.s_addr
== 0)
2141 ls_seqnum
= ntohl(type5
->data
->ls_seqnum
);
2144 /* Delete LSA from neighbor retransmit-list. */
2145 ospf_ls_retransmit_delete_nbr_as(ospf
, type5
);
2147 /* create new translated LSA */
2148 if ((translated_lsa
= ospf_lsa_translated_nssa_new(ospf
, type7
)) ==
2150 if (IS_DEBUG_OSPF_NSSA
)
2152 "%s: Could not translate Type-7 for %pI4 to Type-5",
2153 __func__
, &type7
->data
->id
);
2157 if (type7
->area
->suppress_fa
== 1) {
2158 if (extold
->e
[0].fwd_addr
.s_addr
== 0)
2159 translated_lsa
->data
->ls_seqnum
= htonl(ls_seqnum
+ 1);
2162 if (!(new = ospf_lsa_install(ospf
, NULL
, translated_lsa
))) {
2163 flog_warn(EC_OSPF_LSA_INSTALL_FAILURE
,
2164 "%s: Could not install translated LSA, Id %pI4",
2165 __func__
, &type7
->data
->id
);
2166 ospf_lsa_free(translated_lsa
);
2170 /* Flood LSA through area. */
2171 ospf_flood_through_as(ospf
, NULL
, new);
2176 /* Originate an AS-external-LSA, install and flood. */
2177 struct ospf_lsa
*ospf_external_lsa_originate(struct ospf
*ospf
,
2178 struct external_info
*ei
)
2180 struct ospf_lsa
*new;
2182 if (ospf
->gr_info
.restart_in_progress
) {
2183 if (IS_DEBUG_OSPF(lsa
, LSA_GENERATE
))
2185 "LSA[Type5]: Graceful Restart in progress, don't originate");
2189 /* Added for NSSA project....
2191 External LSAs are originated in ASBRs as usual, but for NSSA
2193 there is the global Type-5 LSDB and a Type-7 LSDB installed for
2194 every area. The Type-7's are flooded to every IR and every ABR; We
2195 install the Type-5 LSDB so that the normal "refresh" code operates
2196 as usual, and flag them as not used during ASE calculations. The
2197 Type-7 LSDB is used for calculations. Each Type-7 has a Forwarding
2198 Address of non-zero.
2200 If an ABR is the elected NSSA translator, following SPF and during
2201 the ABR task it will translate all the scanned Type-7's, with P-bit
2202 ON and not-self generated, and translate to Type-5's throughout the
2205 A difference in operation depends whether this ASBR is an ABR
2206 or not. If not an ABR, the P-bit is ON, to indicate that any
2207 elected NSSA-ABR can perform its translation.
2209 If an ABR, the P-bit is OFF; No ABR will perform translation and
2210 this ASBR will flood the Type-5 LSA as usual.
2212 For the case where this ASBR is not an ABR, the ASE calculations
2213 are based on the Type-5 LSDB; The Type-7 LSDB exists just to
2214 demonstrate to the user that there are LSA's that belong to any
2217 Finally, it just so happens that when the ABR is translating every
2218 Type-7 into Type-5, it installs it into the Type-5 LSDB as an
2219 approved Type-5 (translated from Type-7); at the end of translation
2220 if any Translated Type-5's remain unapproved, then they must be
2221 flushed from the AS.
2225 if (ospf
->router_id
.s_addr
== INADDR_ANY
) {
2226 if (ei
&& IS_DEBUG_OSPF_EVENT
)
2228 "LSA[Type5:%pI4]: deferring AS-external-LSA origination, router ID is zero",
2233 /* Create new AS-external-LSA instance. */
2234 if ((new = ospf_external_lsa_new(ospf
, ei
, NULL
)) == NULL
) {
2235 if (ei
&& IS_DEBUG_OSPF_EVENT
)
2237 "LSA[Type5:%pI4]: Could not originate AS-external-LSA",
2242 /* Install newly created LSA into Type-5 LSDB, lock = 1. */
2243 ospf_lsa_install(ospf
, NULL
, new);
2245 /* Update LSA origination count. */
2246 ospf
->lsa_originate_count
++;
2248 /* Flooding new LSA. only to AS (non-NSSA/STUB) */
2249 ospf_flood_through_as(ospf
, NULL
, new);
2251 /* If there is any attached NSSA, do special handling */
2252 if (ospf
->anyNSSA
&&
2253 /* stay away from translated LSAs! */
2254 !(CHECK_FLAG(new->flags
, OSPF_LSA_LOCAL_XLT
)))
2255 ospf_install_flood_nssa(
2256 ospf
, new); /* Install/Flood Type-7 to all NSSAs */
2258 /* Debug logging. */
2259 if (IS_DEBUG_OSPF(lsa
, LSA_GENERATE
)) {
2260 zlog_debug("LSA[Type%d:%pI4]: Originate AS-external-LSA %p",
2261 new->data
->type
, &new->data
->id
,
2263 ospf_lsa_header_dump(new->data
);
2269 /* Originate an NSSA-LSA, install and flood. */
2270 struct ospf_lsa
*ospf_nssa_lsa_originate(struct ospf_area
*area
,
2271 struct external_info
*ei
)
2273 struct ospf
*ospf
= area
->ospf
;
2274 struct ospf_lsa
*new;
2276 if (ospf
->gr_info
.restart_in_progress
) {
2277 if (IS_DEBUG_OSPF(lsa
, LSA_GENERATE
))
2279 "LSA[Type7]: Graceful Restart in progress, don't originate");
2283 if (ospf
->router_id
.s_addr
== INADDR_ANY
) {
2284 if (IS_DEBUG_OSPF_EVENT
)
2286 "LSA[Type7:%pI4]: deferring NSSA-LSA origination, router ID is zero",
2291 /* Create new NSSA-LSA instance. */
2292 if ((new = ospf_external_lsa_new(ospf
, ei
, NULL
)) == NULL
) {
2293 if (IS_DEBUG_OSPF_EVENT
)
2295 "LSA[Type7:%pI4]: Could not originate NSSA-LSA",
2299 new->data
->type
= OSPF_AS_NSSA_LSA
;
2302 /* Install newly created LSA into Type-7 LSDB. */
2303 ospf_lsa_install(ospf
, NULL
, new);
2305 /* Update LSA origination count. */
2306 ospf
->lsa_originate_count
++;
2308 /* Flooding new LSA */
2309 ospf_flood_through_area(area
, NULL
, new);
2311 /* Debug logging. */
2312 if (IS_DEBUG_OSPF(lsa
, LSA_GENERATE
)) {
2313 zlog_debug("LSA[Type%d:%pI4]: Originate NSSA-LSA %p",
2314 new->data
->type
, &new->data
->id
, (void *)new);
2315 ospf_lsa_header_dump(new->data
);
2321 /* Refresh NSSA-LSA. */
2322 struct ospf_lsa
*ospf_nssa_lsa_refresh(struct ospf_area
*area
,
2323 struct ospf_lsa
*lsa
,
2324 struct external_info
*ei
)
2326 struct ospf
*ospf
= area
->ospf
;
2327 struct ospf_lsa
*new;
2329 /* Delete LSA from neighbor retransmit-list. */
2330 ospf_ls_retransmit_delete_nbr_as(ospf
, lsa
);
2332 /* Unregister AS-external-LSA from refresh-list. */
2333 ospf_refresher_unregister_lsa(ospf
, lsa
);
2335 /* Create new NSSA-LSA instance. */
2336 if ((new = ospf_external_lsa_new(ospf
, ei
, NULL
)) == NULL
) {
2337 if (IS_DEBUG_OSPF_EVENT
)
2339 "LSA[Type7:%pI4]: Could not originate NSSA-LSA",
2343 new->data
->type
= OSPF_AS_NSSA_LSA
;
2344 new->data
->ls_seqnum
= lsa_seqnum_increment(lsa
);
2347 /* Install newly created LSA into Type-7 LSDB. */
2348 ospf_lsa_install(ospf
, NULL
, new);
2350 /* Flooding new LSA */
2351 ospf_flood_through_area(area
, NULL
, new);
2353 /* Debug logging. */
2354 if (IS_DEBUG_OSPF(lsa
, LSA_GENERATE
)) {
2355 zlog_debug("LSA[Type%d:%pI4]: NSSA-LSA refresh",
2356 new->data
->type
, &new->data
->id
);
2357 ospf_lsa_header_dump(new->data
);
2363 static struct external_info
*ospf_default_external_info(struct ospf
*ospf
)
2366 struct prefix_ipv4 p
;
2367 struct external_info
*default_ei
;
2371 p
.prefix
.s_addr
= 0;
2374 default_ei
= ospf_external_info_lookup(ospf
, DEFAULT_ROUTE
, 0, &p
);
2378 /* First, lookup redistributed default route. */
2379 for (type
= 0; type
<= ZEBRA_ROUTE_MAX
; type
++) {
2380 struct list
*ext_list
;
2382 if (type
== ZEBRA_ROUTE_OSPF
)
2385 ext_list
= ospf
->external
[type
];
2389 ret
= ospf_external_default_routemap_apply_walk(ospf
, ext_list
,
2398 void ospf_external_lsa_rid_change(struct ospf
*ospf
)
2400 struct external_info
*ei
;
2401 struct ospf_external_aggr_rt
*aggr
;
2402 struct ospf_lsa
*lsa
= NULL
;
2406 for (type
= 0; type
< ZEBRA_ROUTE_MAX
; type
++) {
2407 struct route_node
*rn
;
2408 struct route_table
*rt
;
2409 struct list
*ext_list
;
2410 struct listnode
*node
;
2411 struct ospf_external
*ext
;
2413 ext_list
= ospf
->external
[type
];
2417 for (ALL_LIST_ELEMENTS_RO(ext_list
, node
, ext
)) {
2418 /* Originate As-external-LSA from all type of
2419 * distribute source.
2421 rt
= ext
->external_info
;
2425 for (rn
= route_top(rt
); rn
; rn
= route_next(rn
)) {
2431 if (is_default_prefix4(&ei
->p
))
2434 lsa
= ospf_external_info_find_lsa(ospf
, &ei
->p
);
2436 aggr
= ospf_external_aggr_match(ospf
, &ei
->p
);
2439 if (!ospf_redistribute_check(ospf
, ei
,
2443 if (IS_DEBUG_OSPF(lsa
, EXTNL_LSA_AGGR
))
2445 "Originate Summary LSA after reset/router-ID change");
2447 /* Here the LSA is originated as new */
2448 ospf_originate_summary_lsa(ospf
, aggr
,
2451 /* LSA needs to be refreshed even if
2452 * there is no change in the route
2453 * params if the LSA is in maxage.
2455 if (IS_LSA_MAXAGE(lsa
))
2456 force
= LSA_REFRESH_FORCE
;
2458 force
= LSA_REFRESH_IF_CHANGED
;
2460 ospf_external_lsa_refresh(ospf
, lsa
,
2463 if (!ospf_redistribute_check(ospf
, ei
,
2467 if (!ospf_external_lsa_originate(ospf
,
2470 EC_OSPF_LSA_INSTALL_FAILURE
,
2471 "LSA: AS-external-LSA was not originated.");
2477 ei
= ospf_default_external_info(ospf
);
2478 if (ei
&& !ospf_external_lsa_originate(ospf
, ei
)) {
2479 flog_warn(EC_OSPF_LSA_INSTALL_FAILURE
,
2480 "LSA: AS-external-LSA for default route was not originated.");
2484 /* Flush any NSSA LSAs for given prefix */
2485 void ospf_nssa_lsa_flush(struct ospf
*ospf
, struct prefix_ipv4
*p
)
2487 struct listnode
*node
, *nnode
;
2488 struct ospf_lsa
*lsa
= NULL
;
2489 struct ospf_area
*area
;
2491 for (ALL_LIST_ELEMENTS(ospf
->areas
, node
, nnode
, area
)) {
2492 if (area
->external_routing
== OSPF_AREA_NSSA
) {
2493 lsa
= ospf_lsa_lookup(ospf
, area
, OSPF_AS_NSSA_LSA
,
2494 p
->prefix
, ospf
->router_id
);
2496 if (IS_DEBUG_OSPF(lsa
, LSA_FLOODING
))
2498 "LSA: There is no such AS-NSSA-LSA %pFX in LSDB",
2502 ospf_ls_retransmit_delete_nbr_area(area
, lsa
);
2503 if (!IS_LSA_MAXAGE(lsa
)) {
2504 ospf_refresher_unregister_lsa(ospf
, lsa
);
2505 ospf_lsa_flush_area(lsa
, area
);
2511 /* Flush an AS-external-LSA from LSDB and routing domain. */
2512 void ospf_external_lsa_flush(struct ospf
*ospf
, uint8_t type
,
2513 struct prefix_ipv4
*p
,
2514 ifindex_t ifindex
/*, struct in_addr nexthop */)
2516 struct ospf_lsa
*lsa
;
2518 if (IS_DEBUG_OSPF(lsa
, LSA_FLOODING
))
2519 zlog_debug("LSA: Flushing AS-external-LSA %pFX", p
);
2521 /* First lookup LSA from LSDB. */
2522 if (!(lsa
= ospf_external_info_find_lsa(ospf
, p
))) {
2523 if (IS_DEBUG_OSPF(lsa
, LSA_FLOODING
))
2525 "LSA: There is no such AS-external-LSA %pFX in LSDB",
2530 /* If LSA is selforiginated, not a translated LSA, and there is
2531 * NSSA area, flush Type-7 LSA's at first.
2533 if (IS_LSA_SELF(lsa
) && (ospf
->anyNSSA
)
2534 && !(CHECK_FLAG(lsa
->flags
, OSPF_LSA_LOCAL_XLT
)))
2535 ospf_nssa_lsa_flush(ospf
, p
);
2537 if (!IS_LSA_MAXAGE(lsa
)) {
2538 /* Sweep LSA from Link State Retransmit List. */
2539 ospf_ls_retransmit_delete_nbr_as(ospf
, lsa
);
2541 /* Unregister LSA from Refresh queue. */
2542 ospf_refresher_unregister_lsa(ospf
, lsa
);
2544 /* Flush AS-external-LSA through AS. */
2545 ospf_lsa_flush_as(ospf
, lsa
);
2548 if (IS_DEBUG_OSPF(lsa
, LSA_FLOODING
))
2549 zlog_debug("%s: stop", __func__
);
2552 void ospf_external_lsa_refresh_default(struct ospf
*ospf
)
2554 struct prefix_ipv4 p
;
2555 struct external_info
*ei
;
2556 struct ospf_lsa
*lsa
;
2560 p
.prefix
.s_addr
= INADDR_ANY
;
2562 ei
= ospf_default_external_info(ospf
);
2563 lsa
= ospf_external_info_find_lsa(ospf
, &p
);
2566 if (IS_DEBUG_OSPF_EVENT
)
2567 zlog_debug("LSA[Type5:0.0.0.0]: Refresh AS-external-LSA %p",
2569 ospf_external_lsa_refresh(ospf
, lsa
, ei
, LSA_REFRESH_FORCE
,
2571 } else if (ei
&& !lsa
) {
2572 if (IS_DEBUG_OSPF_EVENT
)
2574 "LSA[Type5:0.0.0.0]: Originate AS-external-LSA");
2575 ospf_external_lsa_originate(ospf
, ei
);
2577 if (IS_DEBUG_OSPF_EVENT
)
2578 zlog_debug("LSA[Type5:0.0.0.0]: Flush AS-external-LSA");
2579 ospf_external_lsa_flush(ospf
, DEFAULT_ROUTE
, &p
, 0);
2583 void ospf_external_lsa_refresh_type(struct ospf
*ospf
, uint8_t type
,
2584 unsigned short instance
, int force
)
2586 struct route_node
*rn
;
2587 struct external_info
*ei
;
2588 struct ospf_external
*ext
;
2590 if (type
== DEFAULT_ROUTE
)
2593 ext
= ospf_external_lookup(ospf
, type
, instance
);
2595 if (ext
&& EXTERNAL_INFO(ext
)) {
2596 /* Refresh each redistributed AS-external-LSAs. */
2597 for (rn
= route_top(EXTERNAL_INFO(ext
)); rn
;
2598 rn
= route_next(rn
)) {
2601 if (!is_default_prefix4(&ei
->p
)) {
2602 struct ospf_lsa
*lsa
;
2603 struct ospf_external_aggr_rt
*aggr
;
2605 aggr
= ospf_external_aggr_match(ospf
,
2607 lsa
= ospf_external_info_find_lsa(
2610 /* Check the AS-external-LSA
2611 * should be originated.
2613 if (!ospf_redistribute_check(
2616 ospf_unlink_ei_from_aggr(
2625 "%s: Send Aggreate LSA (%pFX)",
2629 ospf_originate_summary_lsa(
2634 if (IS_LSA_MAXAGE(lsa
))
2635 force
= LSA_REFRESH_FORCE
;
2637 ospf_external_lsa_refresh(
2638 ospf
, lsa
, ei
, force
,
2641 if (!ospf_redistribute_check(
2644 ospf_external_lsa_originate(
2653 /* Refresh AS-external-LSA. */
2654 struct ospf_lsa
*ospf_external_lsa_refresh(struct ospf
*ospf
,
2655 struct ospf_lsa
*lsa
,
2656 struct external_info
*ei
, int force
,
2659 struct ospf_lsa
*new;
2662 /* Check the AS-external-LSA should be originated. */
2664 if (!ospf_redistribute_check(ospf
, ei
, &changed
)) {
2665 if (IS_DEBUG_OSPF(lsa
, LSA_GENERATE
))
2667 "LSA[Type%d:%pI4] Could not be refreshed, redist check fail",
2671 ospf_external_lsa_flush(ospf
, ei
->type
, &ei
->p
,
2672 ei
->ifindex
/*, ei->nexthop */);
2676 if (!changed
&& !force
) {
2677 if (IS_DEBUG_OSPF(lsa
, LSA_GENERATE
))
2679 "LSA[Type%d:%pI4]: Not refreshed, not changed/forced",
2680 lsa
->data
->type
, &lsa
->data
->id
);
2684 /* Delete LSA from neighbor retransmit-list. */
2685 ospf_ls_retransmit_delete_nbr_as(ospf
, lsa
);
2687 /* Unregister AS-external-LSA from refresh-list. */
2688 ospf_refresher_unregister_lsa(ospf
, lsa
);
2690 new = ospf_external_lsa_new(ospf
, ei
, &lsa
->data
->id
);
2693 if (IS_DEBUG_OSPF(lsa
, LSA_GENERATE
))
2694 zlog_debug("LSA[Type%d:%pI4]: Could not be refreshed",
2695 lsa
->data
->type
, &lsa
->data
->id
);
2699 new->data
->ls_seqnum
= lsa_seqnum_increment(lsa
);
2701 ospf_lsa_install(ospf
, NULL
, new); /* As type-5. */
2703 /* Flood LSA through AS. */
2704 ospf_flood_through_as(ospf
, NULL
, new);
2706 /* If any attached NSSA, install as Type-7, flood to all NSSA Areas */
2707 if (ospf
->anyNSSA
&& !(CHECK_FLAG(new->flags
, OSPF_LSA_LOCAL_XLT
)))
2708 ospf_install_flood_nssa(ospf
,
2709 new); /* Install/Flood per new rules */
2711 /* Register self-originated LSA to refresh queue.
2712 * Translated LSAs should not be registered, but refreshed upon
2713 * refresh of the Type-7
2715 if (!CHECK_FLAG(new->flags
, OSPF_LSA_LOCAL_XLT
))
2716 ospf_refresher_register_lsa(ospf
, new);
2718 /* Debug logging. */
2719 if (IS_DEBUG_OSPF(lsa
, LSA_GENERATE
)) {
2720 zlog_debug("LSA[Type%d:%pI4]: AS-external-LSA refresh",
2721 new->data
->type
, &new->data
->id
);
2722 ospf_lsa_header_dump(new->data
);
2729 /* LSA installation functions. */
2731 /* Install router-LSA to an area. */
2732 static struct ospf_lsa
*
2733 ospf_router_lsa_install(struct ospf
*ospf
, struct ospf_lsa
*new, int rt_recalc
)
2735 struct ospf_area
*area
= new->area
;
2737 /* RFC 2328 Section 13.2 Router-LSAs and network-LSAs
2738 The entire routing table must be recalculated, starting with
2739 the shortest path calculations for each area (not just the
2740 area whose link-state database has changed).
2743 if (IS_LSA_SELF(new)) {
2745 /* Only install LSA if it is originated/refreshed by us.
2746 * If LSA was received by flooding, the RECEIVED flag is set so
2748 * not link the LSA */
2749 if (CHECK_FLAG(new->flags
, OSPF_LSA_RECEIVED
))
2750 return new; /* ignore stale LSA */
2752 /* Set self-originated router-LSA. */
2753 ospf_lsa_unlock(&area
->router_lsa_self
);
2754 area
->router_lsa_self
= ospf_lsa_lock(new);
2756 ospf_refresher_register_lsa(ospf
, new);
2759 ospf_spf_calculate_schedule(ospf
, SPF_FLAG_ROUTER_LSA_INSTALL
);
2763 /* Install network-LSA to an area. */
2764 static struct ospf_lsa
*ospf_network_lsa_install(struct ospf
*ospf
,
2765 struct ospf_interface
*oi
,
2766 struct ospf_lsa
*new,
2770 /* RFC 2328 Section 13.2 Router-LSAs and network-LSAs
2771 The entire routing table must be recalculated, starting with
2772 the shortest path calculations for each area (not just the
2773 area whose link-state database has changed).
2775 if (IS_LSA_SELF(new)) {
2776 /* We supposed that when LSA is originated by us, we pass the
2778 for which it was originated. If LSA was received by flooding,
2779 the RECEIVED flag is set, so we do not link the LSA to the
2781 if (CHECK_FLAG(new->flags
, OSPF_LSA_RECEIVED
))
2782 return new; /* ignore stale LSA */
2784 ospf_lsa_unlock(&oi
->network_lsa_self
);
2785 oi
->network_lsa_self
= ospf_lsa_lock(new);
2786 ospf_refresher_register_lsa(ospf
, new);
2789 ospf_spf_calculate_schedule(ospf
, SPF_FLAG_NETWORK_LSA_INSTALL
);
2794 /* Install summary-LSA to an area. */
2795 static struct ospf_lsa
*
2796 ospf_summary_lsa_install(struct ospf
*ospf
, struct ospf_lsa
*new, int rt_recalc
)
2798 if (rt_recalc
&& !IS_LSA_SELF(new)) {
2799 /* RFC 2328 Section 13.2 Summary-LSAs
2800 The best route to the destination described by the summary-
2801 LSA must be recalculated (see Section 16.5). If this
2802 destination is an AS boundary router, it may also be
2803 necessary to re-examine all the AS-external-LSAs.
2806 ospf_spf_calculate_schedule(ospf
, SPF_FLAG_SUMMARY_LSA_INSTALL
);
2809 if (IS_LSA_SELF(new))
2810 ospf_refresher_register_lsa(ospf
, new);
2815 /* Install ASBR-summary-LSA to an area. */
2816 static struct ospf_lsa
*ospf_summary_asbr_lsa_install(struct ospf
*ospf
,
2817 struct ospf_lsa
*new,
2820 if (rt_recalc
&& !IS_LSA_SELF(new)) {
2821 /* RFC 2328 Section 13.2 Summary-LSAs
2822 The best route to the destination described by the summary-
2823 LSA must be recalculated (see Section 16.5). If this
2824 destination is an AS boundary router, it may also be
2825 necessary to re-examine all the AS-external-LSAs.
2827 ospf_spf_calculate_schedule(ospf
,
2828 SPF_FLAG_ASBR_SUMMARY_LSA_INSTALL
);
2831 /* register LSA to refresh-list. */
2832 if (IS_LSA_SELF(new))
2833 ospf_refresher_register_lsa(ospf
, new);
2838 /* Install AS-external-LSA. */
2839 static struct ospf_lsa
*ospf_external_lsa_install(struct ospf
*ospf
,
2840 struct ospf_lsa
*new,
2843 ospf_ase_register_external_lsa(new, ospf
);
2844 /* If LSA is not self-originated, calculate an external route. */
2846 /* RFC 2328 Section 13.2 AS-external-LSAs
2847 The best route to the destination described by the AS-
2848 external-LSA must be recalculated (see Section 16.6).
2851 if (!IS_LSA_SELF(new))
2852 ospf_ase_incremental_update(ospf
, new);
2855 if (new->data
->type
== OSPF_AS_NSSA_LSA
) {
2856 /* There is no point to register selforiginate Type-7 LSA for
2857 * refreshing. We rely on refreshing Type-5 LSA's
2859 if (IS_LSA_SELF(new))
2862 /* Try refresh type-5 translated LSA for this LSA, if
2864 * New translations will be taken care of by the
2867 ospf_translated_nssa_refresh(ospf
, new, NULL
);
2868 ospf_schedule_abr_task(ospf
);
2872 /* Register self-originated LSA to refresh queue.
2873 * Leave Translated LSAs alone if NSSA is enabled
2875 if (IS_LSA_SELF(new) && !CHECK_FLAG(new->flags
, OSPF_LSA_LOCAL_XLT
))
2876 ospf_refresher_register_lsa(ospf
, new);
2881 void ospf_discard_from_db(struct ospf
*ospf
, struct ospf_lsdb
*lsdb
,
2882 struct ospf_lsa
*lsa
)
2884 struct ospf_lsa
*old
;
2889 old
= ospf_lsdb_lookup(lsdb
, lsa
);
2894 if (old
->refresh_list
>= 0)
2895 ospf_refresher_unregister_lsa(ospf
, old
);
2897 switch (old
->data
->type
) {
2898 case OSPF_AS_EXTERNAL_LSA
:
2899 ospf_ase_unregister_external_lsa(old
, ospf
);
2900 ospf_ls_retransmit_delete_nbr_as(ospf
, old
);
2902 case OSPF_OPAQUE_AS_LSA
:
2903 ospf_ls_retransmit_delete_nbr_as(ospf
, old
);
2905 case OSPF_AS_NSSA_LSA
:
2906 ospf_ls_retransmit_delete_nbr_area(old
->area
, old
);
2907 ospf_ase_unregister_external_lsa(old
, ospf
);
2910 ospf_ls_retransmit_delete_nbr_area(old
->area
, old
);
2914 ospf_lsa_maxage_delete(ospf
, old
);
2915 ospf_lsa_discard(old
);
2918 struct ospf_lsa
*ospf_lsa_install(struct ospf
*ospf
, struct ospf_interface
*oi
,
2919 struct ospf_lsa
*lsa
)
2921 struct ospf_lsa
*new = NULL
;
2922 struct ospf_lsa
*old
= NULL
;
2923 struct ospf_lsdb
*lsdb
= NULL
;
2927 switch (lsa
->data
->type
) {
2929 case OSPF_AS_NSSA_LSA
:
2931 lsdb
= lsa
->area
->lsdb
;
2935 case OSPF_AS_EXTERNAL_LSA
:
2936 case OSPF_OPAQUE_AS_LSA
:
2941 lsdb
= lsa
->area
->lsdb
;
2947 /* RFC 2328 13.2. Installing LSAs in the database
2949 Installing a new LSA in the database, either as the result of
2950 flooding or a newly self-originated LSA, may cause the OSPF
2951 routing table structure to be recalculated. The contents of the
2952 new LSA should be compared to the old instance, if present. If
2953 there is no difference, there is no need to recalculate the
2954 routing table. When comparing an LSA to its previous instance,
2955 the following are all considered to be differences in contents:
2957 o The LSA's Options field has changed.
2959 o One of the LSA instances has LS age set to MaxAge, and
2962 o The length field in the LSA header has changed.
2964 o The body of the LSA (i.e., anything outside the 20-byte
2965 LSA header) has changed. Note that this excludes changes
2966 in LS Sequence Number and LS Checksum.
2969 /* Look up old LSA and determine if any SPF calculation or incremental
2971 old
= ospf_lsdb_lookup(lsdb
, lsa
);
2973 /* Do comparison and record if recalc needed. */
2975 if (old
== NULL
|| ospf_lsa_different(old
, lsa
, false)) {
2976 /* Ref rfc3623 section 3.2.3
2977 * Installing new lsa or change in the existing LSA
2978 * or flushing existing LSA leads to topo change
2979 * and trigger SPF caculation.
2980 * So, router should be aborted from HELPER role
2981 * if it is detected as TOPO change.
2983 if (ospf
->active_restarter_cnt
&&
2984 CHECK_LSA_TYPE_1_TO_5_OR_7(lsa
->data
->type
)) {
2985 if (old
== NULL
|| ospf_lsa_different(old
, lsa
, true))
2986 ospf_helper_handle_topo_chg(ospf
, lsa
);
2993 Sequence number check (Section 14.1 of rfc 2328)
2994 "Premature aging is used when it is time for a self-originated
2995 LSA's sequence number field to wrap. At this point, the current
2996 LSA instance (having LS sequence number MaxSequenceNumber) must
2997 be prematurely aged and flushed from the routing domain before a
2998 new instance with sequence number equal to InitialSequenceNumber
2999 can be originated. "
3002 if (ntohl(lsa
->data
->ls_seqnum
) - 1 == OSPF_MAX_SEQUENCE_NUMBER
) {
3003 if (ospf_lsa_is_self_originated(ospf
, lsa
)) {
3004 lsa
->data
->ls_seqnum
= htonl(OSPF_MAX_SEQUENCE_NUMBER
);
3006 if (!IS_LSA_MAXAGE(lsa
))
3007 lsa
->flags
|= OSPF_LSA_PREMATURE_AGE
;
3008 lsa
->data
->ls_age
= htons(OSPF_LSA_MAXAGE
);
3010 if (IS_DEBUG_OSPF(lsa
, LSA_REFRESH
)) {
3012 "%s() Premature Aging lsa %p, seqnum 0x%x",
3014 ntohl(lsa
->data
->ls_seqnum
));
3015 ospf_lsa_header_dump(lsa
->data
);
3018 if (IS_DEBUG_OSPF(lsa
, LSA_GENERATE
)) {
3020 "%s() got an lsa with seq 0x80000000 that was not self originated. Ignoring",
3022 ospf_lsa_header_dump(lsa
->data
);
3028 /* discard old LSA from LSDB */
3030 ospf_discard_from_db(ospf
, lsdb
, lsa
);
3032 /* Calculate Checksum if self-originated?. */
3033 if (IS_LSA_SELF(lsa
))
3034 ospf_lsa_checksum(lsa
->data
);
3036 /* Insert LSA to LSDB. */
3037 ospf_lsdb_add(lsdb
, lsa
);
3040 /* Do LSA specific installation process. */
3041 switch (lsa
->data
->type
) {
3042 case OSPF_ROUTER_LSA
:
3043 new = ospf_router_lsa_install(ospf
, lsa
, rt_recalc
);
3045 case OSPF_NETWORK_LSA
:
3047 new = ospf_network_lsa_install(ospf
, oi
, lsa
, rt_recalc
);
3049 case OSPF_SUMMARY_LSA
:
3050 new = ospf_summary_lsa_install(ospf
, lsa
, rt_recalc
);
3052 case OSPF_ASBR_SUMMARY_LSA
:
3053 new = ospf_summary_asbr_lsa_install(ospf
, lsa
, rt_recalc
);
3055 case OSPF_AS_EXTERNAL_LSA
:
3056 new = ospf_external_lsa_install(ospf
, lsa
, rt_recalc
);
3058 case OSPF_OPAQUE_LINK_LSA
:
3059 if (IS_LSA_SELF(lsa
))
3060 lsa
->oi
= oi
; /* Specify outgoing ospf-interface for
3063 /* Incoming "oi" for this LSA has set at LSUpd
3067 case OSPF_OPAQUE_AREA_LSA
:
3068 case OSPF_OPAQUE_AS_LSA
:
3069 new = ospf_opaque_lsa_install(lsa
, rt_recalc
);
3071 case OSPF_AS_NSSA_LSA
:
3072 new = ospf_external_lsa_install(ospf
, lsa
, rt_recalc
);
3073 default: /* type-6,8,9....nothing special */
3078 return new; /* Installation failed, cannot proceed further --
3082 if (IS_DEBUG_OSPF(lsa
, LSA_INSTALL
)) {
3083 switch (lsa
->data
->type
) {
3084 case OSPF_AS_EXTERNAL_LSA
:
3085 case OSPF_OPAQUE_AS_LSA
:
3086 case OSPF_AS_NSSA_LSA
:
3087 zlog_debug("LSA[%s]: Install %s", dump_lsa_key(new),
3088 lookup_msg(ospf_lsa_type_msg
,
3089 new->data
->type
, NULL
));
3092 zlog_debug("LSA[%s]: Install %s to Area %pI4",
3094 lookup_msg(ospf_lsa_type_msg
,
3095 new->data
->type
, NULL
),
3096 &new->area
->area_id
);
3102 If received LSA' ls_age is MaxAge, or lsa is being prematurely aged
3103 (it's getting flushed out of the area), set LSA on MaxAge LSA list.
3105 if (IS_LSA_MAXAGE(new)) {
3106 if (IS_DEBUG_OSPF(lsa
, LSA_INSTALL
))
3107 zlog_debug("LSA[%s]: Install LSA %p, MaxAge",
3108 dump_lsa_key(new), lsa
);
3109 ospf_lsa_maxage(ospf
, lsa
);
3116 int ospf_check_nbr_status(struct ospf
*ospf
)
3118 struct listnode
*node
, *nnode
;
3119 struct ospf_interface
*oi
;
3121 for (ALL_LIST_ELEMENTS(ospf
->oiflist
, node
, nnode
, oi
)) {
3122 struct route_node
*rn
;
3123 struct ospf_neighbor
*nbr
;
3125 if (ospf_if_is_enable(oi
))
3126 for (rn
= route_top(oi
->nbrs
); rn
; rn
= route_next(rn
))
3127 if ((nbr
= rn
->info
) != NULL
)
3128 if (nbr
->state
== NSM_Exchange
3129 || nbr
->state
== NSM_Loading
) {
3130 route_unlock_node(rn
);
3139 void ospf_maxage_lsa_remover(struct event
*thread
)
3141 struct ospf
*ospf
= EVENT_ARG(thread
);
3142 struct ospf_lsa
*lsa
, *old
;
3143 struct route_node
*rn
;
3146 ospf
->t_maxage
= NULL
;
3148 if (IS_DEBUG_OSPF(lsa
, LSA_FLOODING
))
3149 zlog_debug("LSA[MaxAge]: remover Start");
3151 reschedule
= !ospf_check_nbr_status(ospf
);
3154 for (rn
= route_top(ospf
->maxage_lsa
); rn
;
3155 rn
= route_next(rn
)) {
3156 if ((lsa
= rn
->info
) == NULL
) {
3160 /* There is at least one neighbor from which we still
3162 * for that LSA, so we are not allowed to remove it from
3164 * as per RFC 2328 section 14 para 4 a) */
3165 if (lsa
->retransmit_counter
> 0) {
3170 /* TODO: maybe convert this function to a work-queue */
3171 if (event_should_yield(thread
)) {
3172 OSPF_TIMER_ON(ospf
->t_maxage
,
3173 ospf_maxage_lsa_remover
, 0);
3175 rn
); /* route_top/route_next */
3179 /* Remove LSA from the LSDB */
3180 if (IS_LSA_SELF(lsa
))
3181 if (IS_DEBUG_OSPF(lsa
, LSA_FLOODING
))
3183 "LSA[Type%d:%pI4]: LSA 0x%lx is self-originated: ",
3186 (unsigned long)lsa
);
3188 if (IS_DEBUG_OSPF(lsa
, LSA_FLOODING
))
3190 "LSA[%s]: MaxAge LSA removed from list",
3193 if (CHECK_FLAG(lsa
->flags
, OSPF_LSA_PREMATURE_AGE
)) {
3194 if (IS_DEBUG_OSPF(lsa
, LSA_FLOODING
))
3196 "originating new lsa for lsa %p",
3198 ospf_lsa_refresh(ospf
, lsa
);
3201 /* Remove from lsdb. */
3203 old
= ospf_lsdb_lookup(lsa
->lsdb
, lsa
);
3204 /* The max age LSA here must be the same
3205 * as the LSA in LSDB
3208 flog_err(EC_OSPF_LSA_MISSING
,
3209 "%s: LSA[%s]: LSA not in LSDB",
3210 __func__
, dump_lsa_key(lsa
));
3214 ospf_discard_from_db(ospf
, lsa
->lsdb
, lsa
);
3215 ospf_lsdb_delete(lsa
->lsdb
, lsa
);
3217 if (IS_DEBUG_OSPF(lsa
, LSA_FLOODING
))
3219 "%s: LSA[%s]: No associated LSDB!",
3220 __func__
, dump_lsa_key(lsa
));
3224 /* A MaxAge LSA must be removed immediately from the router's link
3225 state database as soon as both a) it is no longer contained on any
3226 neighbor Link state retransmission lists and b) none of the
3228 neighbors are in states Exchange or Loading. */
3230 OSPF_TIMER_ON(ospf
->t_maxage
, ospf_maxage_lsa_remover
,
3231 ospf
->maxage_delay
);
3234 /* This function checks whether an LSA with initial sequence number should be
3235 * originated after a wrap in sequence number
3237 void ospf_check_and_gen_init_seq_lsa(struct ospf_interface
*oi
,
3238 struct ospf_lsa
*recv_lsa
)
3240 struct ospf_lsa
*lsa
= NULL
;
3241 struct ospf
*ospf
= oi
->ospf
;
3243 lsa
= ospf_lsa_lookup_by_header(oi
->area
, recv_lsa
->data
);
3245 if ((lsa
== NULL
) || (!CHECK_FLAG(lsa
->flags
, OSPF_LSA_PREMATURE_AGE
))
3246 || (lsa
->retransmit_counter
!= 0)) {
3247 if (IS_DEBUG_OSPF(lsa
, LSA
))
3249 "Do not generate LSA with initial seqence number.");
3253 ospf_lsa_maxage_delete(ospf
, lsa
);
3255 lsa
->data
->ls_seqnum
= lsa_seqnum_increment(lsa
);
3257 ospf_lsa_refresh(ospf
, lsa
);
3260 void ospf_lsa_maxage_delete(struct ospf
*ospf
, struct ospf_lsa
*lsa
)
3262 struct route_node
*rn
;
3263 struct prefix lsa_prefix
;
3265 memset(&lsa_prefix
, 0, sizeof(lsa_prefix
));
3266 lsa_prefix
.family
= AF_UNSPEC
;
3267 lsa_prefix
.prefixlen
= sizeof(lsa_prefix
.u
.ptr
) * CHAR_BIT
;
3268 lsa_prefix
.u
.ptr
= (uintptr_t)lsa
;
3270 if ((rn
= route_node_lookup(ospf
->maxage_lsa
, &lsa_prefix
))) {
3271 if (rn
->info
== lsa
) {
3272 UNSET_FLAG(lsa
->flags
, OSPF_LSA_IN_MAXAGE
);
3273 ospf_lsa_unlock(&lsa
); /* maxage_lsa */
3276 rn
); /* unlock node because lsa is deleted */
3278 route_unlock_node(rn
); /* route_node_lookup */
3280 if (IS_DEBUG_OSPF_EVENT
)
3281 zlog_debug("%s: lsa %s is not found in maxage db.",
3282 __func__
, dump_lsa_key(lsa
));
3286 /* Add LSA onto the MaxAge list, and schedule for removal.
3287 * This does *not* lead to the LSA being flooded, that must be taken
3288 * care of elsewhere, see, e.g., ospf_lsa_flush* (which are callers of this
3291 void ospf_lsa_maxage(struct ospf
*ospf
, struct ospf_lsa
*lsa
)
3293 struct prefix lsa_prefix
;
3294 struct route_node
*rn
;
3296 /* When we saw a MaxAge LSA flooded to us, we put it on the list
3297 and schedule the MaxAge LSA remover. */
3298 if (CHECK_FLAG(lsa
->flags
, OSPF_LSA_IN_MAXAGE
)) {
3299 if (IS_DEBUG_OSPF(lsa
, LSA_FLOODING
))
3301 "LSA[%s]: %p already exists on MaxAge LSA list",
3302 dump_lsa_key(lsa
), lsa
);
3306 memset(&lsa_prefix
, 0, sizeof(lsa_prefix
));
3307 lsa_prefix
.family
= AF_UNSPEC
;
3308 lsa_prefix
.prefixlen
= sizeof(lsa_prefix
.u
.ptr
) * CHAR_BIT
;
3309 lsa_prefix
.u
.ptr
= (uintptr_t)lsa
;
3311 rn
= route_node_get(ospf
->maxage_lsa
, &lsa_prefix
);
3312 if (rn
->info
!= NULL
) {
3313 if (IS_DEBUG_OSPF(lsa
, LSA_FLOODING
))
3315 "LSA[%s]: found LSA (%p) in table for LSA %p %d",
3316 dump_lsa_key(lsa
), rn
->info
,
3317 (void *)lsa
, lsa_prefix
.prefixlen
);
3318 route_unlock_node(rn
);
3320 rn
->info
= ospf_lsa_lock(lsa
);
3321 SET_FLAG(lsa
->flags
, OSPF_LSA_IN_MAXAGE
);
3324 if (IS_DEBUG_OSPF(lsa
, LSA_FLOODING
))
3325 zlog_debug("LSA[%s]: MaxAge LSA remover scheduled.",
3328 OSPF_TIMER_ON(ospf
->t_maxage
, ospf_maxage_lsa_remover
,
3329 ospf
->maxage_delay
);
3332 static int ospf_lsa_maxage_walker_remover(struct ospf
*ospf
,
3333 struct ospf_lsa
*lsa
)
3335 /* Stay away from any Local Translated Type-7 LSAs */
3336 if (CHECK_FLAG(lsa
->flags
, OSPF_LSA_LOCAL_XLT
))
3339 if (IS_LSA_MAXAGE(lsa
))
3340 /* Self-originated LSAs should NOT time-out instead,
3341 they're flushed and submitted to the max_age list explicitly.
3343 if (!ospf_lsa_is_self_originated(ospf
, lsa
)) {
3344 if (IS_DEBUG_OSPF(lsa
, LSA_FLOODING
))
3345 zlog_debug("LSA[%s]: is MaxAge",
3348 switch (lsa
->data
->type
) {
3349 case OSPF_OPAQUE_LINK_LSA
:
3350 case OSPF_OPAQUE_AREA_LSA
:
3351 case OSPF_OPAQUE_AS_LSA
:
3353 * As a general rule, whenever network topology
3355 * (due to an LSA removal in this case), routing
3357 * should be triggered. However, this is not
3359 * LSAs. Even if an opaque LSA instance is going
3361 * from the routing domain, it does not mean a
3363 * topology, and thus, routing recalculation is
3367 case OSPF_AS_EXTERNAL_LSA
:
3368 case OSPF_AS_NSSA_LSA
:
3369 ospf_ase_incremental_update(ospf
, lsa
);
3372 ospf_spf_calculate_schedule(ospf
,
3376 ospf_lsa_maxage(ospf
, lsa
);
3379 if (IS_LSA_MAXAGE(lsa
) && !ospf_lsa_is_self_originated(ospf
, lsa
))
3380 if (LS_AGE(lsa
) > OSPF_LSA_MAXAGE
+ 30)
3381 printf("Eek! Shouldn't happen!\n");
3386 /* Periodical check of MaxAge LSA. */
3387 void ospf_lsa_maxage_walker(struct event
*thread
)
3389 struct ospf
*ospf
= EVENT_ARG(thread
);
3390 struct route_node
*rn
;
3391 struct ospf_lsa
*lsa
;
3392 struct ospf_area
*area
;
3393 struct listnode
*node
, *nnode
;
3395 ospf
->t_maxage_walker
= NULL
;
3397 for (ALL_LIST_ELEMENTS(ospf
->areas
, node
, nnode
, area
)) {
3398 LSDB_LOOP (ROUTER_LSDB(area
), rn
, lsa
)
3399 ospf_lsa_maxage_walker_remover(ospf
, lsa
);
3400 LSDB_LOOP (NETWORK_LSDB(area
), rn
, lsa
)
3401 ospf_lsa_maxage_walker_remover(ospf
, lsa
);
3402 LSDB_LOOP (SUMMARY_LSDB(area
), rn
, lsa
)
3403 ospf_lsa_maxage_walker_remover(ospf
, lsa
);
3404 LSDB_LOOP (ASBR_SUMMARY_LSDB(area
), rn
, lsa
)
3405 ospf_lsa_maxage_walker_remover(ospf
, lsa
);
3406 LSDB_LOOP (OPAQUE_AREA_LSDB(area
), rn
, lsa
)
3407 ospf_lsa_maxage_walker_remover(ospf
, lsa
);
3408 LSDB_LOOP (OPAQUE_LINK_LSDB(area
), rn
, lsa
)
3409 ospf_lsa_maxage_walker_remover(ospf
, lsa
);
3410 LSDB_LOOP (NSSA_LSDB(area
), rn
, lsa
)
3411 ospf_lsa_maxage_walker_remover(ospf
, lsa
);
3414 /* for AS-external-LSAs. */
3416 LSDB_LOOP (EXTERNAL_LSDB(ospf
), rn
, lsa
)
3417 ospf_lsa_maxage_walker_remover(ospf
, lsa
);
3418 LSDB_LOOP (OPAQUE_AS_LSDB(ospf
), rn
, lsa
)
3419 ospf_lsa_maxage_walker_remover(ospf
, lsa
);
3422 OSPF_TIMER_ON(ospf
->t_maxage_walker
, ospf_lsa_maxage_walker
,
3423 OSPF_LSA_MAXAGE_CHECK_INTERVAL
);
3426 struct ospf_lsa
*ospf_lsa_lookup_by_prefix(struct ospf_lsdb
*lsdb
, uint8_t type
,
3427 struct prefix_ipv4
*p
,
3428 struct in_addr router_id
)
3430 struct ospf_lsa
*lsa
;
3431 struct in_addr mask
, id
;
3432 struct lsa_header_mask
{
3433 struct lsa_header header
;
3434 struct in_addr mask
;
3437 lsa
= ospf_lsdb_lookup_by_id(lsdb
, type
, p
->prefix
, router_id
);
3441 masklen2ip(p
->prefixlen
, &mask
);
3443 hmask
= (struct lsa_header_mask
*)lsa
->data
;
3445 if (mask
.s_addr
!= hmask
->mask
.s_addr
) {
3446 id
.s_addr
= p
->prefix
.s_addr
| (~mask
.s_addr
);
3447 lsa
= ospf_lsdb_lookup_by_id(lsdb
, type
, id
, router_id
);
3455 struct ospf_lsa
*ospf_lsa_lookup(struct ospf
*ospf
, struct ospf_area
*area
,
3456 uint32_t type
, struct in_addr id
,
3457 struct in_addr adv_router
)
3463 case OSPF_ROUTER_LSA
:
3464 case OSPF_NETWORK_LSA
:
3465 case OSPF_SUMMARY_LSA
:
3466 case OSPF_ASBR_SUMMARY_LSA
:
3467 case OSPF_AS_NSSA_LSA
:
3468 case OSPF_OPAQUE_LINK_LSA
:
3469 case OSPF_OPAQUE_AREA_LSA
:
3470 return ospf_lsdb_lookup_by_id(area
->lsdb
, type
, id
, adv_router
);
3471 case OSPF_AS_EXTERNAL_LSA
:
3472 case OSPF_OPAQUE_AS_LSA
:
3473 return ospf_lsdb_lookup_by_id(ospf
->lsdb
, type
, id
, adv_router
);
3481 struct ospf_lsa
*ospf_lsa_lookup_by_id(struct ospf_area
*area
, uint32_t type
,
3484 struct ospf_lsa
*lsa
;
3485 struct route_node
*rn
;
3488 case OSPF_ROUTER_LSA
:
3489 return ospf_lsdb_lookup_by_id(area
->lsdb
, type
, id
, id
);
3490 case OSPF_NETWORK_LSA
:
3491 for (rn
= route_top(NETWORK_LSDB(area
)); rn
;
3492 rn
= route_next(rn
))
3493 if ((lsa
= rn
->info
))
3494 if (IPV4_ADDR_SAME(&lsa
->data
->id
, &id
)) {
3495 route_unlock_node(rn
);
3499 case OSPF_SUMMARY_LSA
:
3500 case OSPF_ASBR_SUMMARY_LSA
:
3501 /* Currently not used. */
3503 return ospf_lsdb_lookup_by_id(area
->lsdb
, type
, id
, id
);
3504 case OSPF_AS_EXTERNAL_LSA
:
3505 case OSPF_AS_NSSA_LSA
:
3506 case OSPF_OPAQUE_LINK_LSA
:
3507 case OSPF_OPAQUE_AREA_LSA
:
3508 case OSPF_OPAQUE_AS_LSA
:
3509 /* Currently not used. */
3518 struct ospf_lsa
*ospf_lsa_lookup_by_header(struct ospf_area
*area
,
3519 struct lsa_header
*lsah
)
3521 struct ospf_lsa
*match
;
3524 * Strictly speaking, the LSA-ID field for Opaque-LSAs (type-9/10/11)
3525 * is redefined to have two subfields; opaque-type and opaque-id.
3526 * However, it is harmless to treat the two sub fields together, as if
3527 * they two were forming a unique LSA-ID.
3530 match
= ospf_lsa_lookup(area
->ospf
, area
, lsah
->type
, lsah
->id
,
3534 if (IS_DEBUG_OSPF(lsa
, LSA
) == OSPF_DEBUG_LSA
)
3535 zlog_debug("LSA[Type%d:%pI4]: Lookup by header, NO MATCH",
3536 lsah
->type
, &lsah
->id
);
3541 /* return +n, l1 is more recent.
3542 return -n, l2 is more recent.
3543 return 0, l1 and l2 is identical. */
3544 int ospf_lsa_more_recent(struct ospf_lsa
*l1
, struct ospf_lsa
*l2
)
3549 if (l1
== NULL
&& l2
== NULL
)
3556 /* compare LS sequence number. */
3557 x
= (int)ntohl(l1
->data
->ls_seqnum
);
3558 y
= (int)ntohl(l2
->data
->ls_seqnum
);
3564 /* compare LS checksum. */
3565 r
= ntohs(l1
->data
->checksum
) - ntohs(l2
->data
->checksum
);
3569 /* compare LS age. */
3570 if (IS_LSA_MAXAGE(l1
) && !IS_LSA_MAXAGE(l2
))
3572 else if (!IS_LSA_MAXAGE(l1
) && IS_LSA_MAXAGE(l2
))
3575 /* compare LS age with MaxAgeDiff. */
3576 if (LS_AGE(l1
) - LS_AGE(l2
) > OSPF_LSA_MAXAGE_DIFF
)
3578 else if (LS_AGE(l2
) - LS_AGE(l1
) > OSPF_LSA_MAXAGE_DIFF
)
3581 /* LSAs are identical. */
3586 * Check if two LSAs are different.
3589 * The first LSA to compare.
3592 * The second LSA to compare.
3595 * When set to true, ignore whether the LSAs were received from the network
3596 * or not. This parameter should be set to true when checking for topology
3597 * changes as part of the Graceful Restart helper neighbor procedures.
3600 * true if the LSAs are different, false otherwise.
3602 int ospf_lsa_different(struct ospf_lsa
*l1
, struct ospf_lsa
*l2
,
3603 bool ignore_rcvd_flag
)
3611 if (l1
->data
->options
!= l2
->data
->options
)
3614 if (IS_LSA_MAXAGE(l1
) && !IS_LSA_MAXAGE(l2
))
3617 if (IS_LSA_MAXAGE(l2
) && !IS_LSA_MAXAGE(l1
))
3620 if (l1
->size
!= l2
->size
)
3626 if (!ignore_rcvd_flag
3627 && CHECK_FLAG((l1
->flags
^ l2
->flags
), OSPF_LSA_RECEIVED
))
3628 return 1; /* May be a stale LSA in the LSBD */
3630 if (l1
->size
== OSPF_LSA_HEADER_SIZE
)
3631 return 0; /* nothing to compare */
3633 p1
= (char *)l1
->data
;
3634 p2
= (char *)l2
->data
;
3636 if (memcmp(p1
+ OSPF_LSA_HEADER_SIZE
, p2
+ OSPF_LSA_HEADER_SIZE
,
3637 l1
->size
- OSPF_LSA_HEADER_SIZE
)
3644 int ospf_lsa_flush_schedule(struct ospf
*ospf
, struct ospf_lsa
*lsa
)
3646 if (lsa
== NULL
|| !IS_LSA_SELF(lsa
))
3649 if (IS_DEBUG_OSPF_EVENT
)
3651 "LSA[Type%d:%pI4]: Schedule self-originated LSA to FLUSH",
3652 lsa
->data
->type
, &lsa
->data
->id
);
3654 /* Force given lsa's age to MaxAge. */
3655 lsa
->data
->ls_age
= htons(OSPF_LSA_MAXAGE
);
3657 switch (lsa
->data
->type
) {
3658 /* Opaque wants to be notified of flushes */
3659 case OSPF_OPAQUE_LINK_LSA
:
3660 case OSPF_OPAQUE_AREA_LSA
:
3661 case OSPF_OPAQUE_AS_LSA
:
3662 ospf_opaque_lsa_refresh(lsa
);
3665 ospf_refresher_unregister_lsa(ospf
, lsa
);
3666 ospf_lsa_flush(ospf
, lsa
);
3673 void ospf_flush_self_originated_lsas_now(struct ospf
*ospf
)
3675 struct listnode
*node
, *nnode
;
3676 struct listnode
*node2
, *nnode2
;
3677 struct ospf_area
*area
;
3678 struct ospf_interface
*oi
;
3679 struct ospf_lsa
*lsa
;
3680 struct route_node
*rn
;
3681 struct ospf_if_params
*oip
;
3682 int need_to_flush_ase
= 0;
3684 ospf
->inst_shutdown
= 1;
3686 for (ALL_LIST_ELEMENTS(ospf
->areas
, node
, nnode
, area
)) {
3687 if ((lsa
= area
->router_lsa_self
) != NULL
) {
3688 if (IS_DEBUG_OSPF_EVENT
)
3690 "LSA[Type%d:%pI4]: Schedule self-originated LSA to FLUSH",
3694 ospf_refresher_unregister_lsa(ospf
, lsa
);
3695 ospf_lsa_flush_area(lsa
, area
);
3696 ospf_lsa_unlock(&area
->router_lsa_self
);
3697 area
->router_lsa_self
= NULL
;
3700 for (ALL_LIST_ELEMENTS(area
->oiflist
, node2
, nnode2
, oi
)) {
3701 if ((lsa
= oi
->network_lsa_self
) != NULL
3702 && oi
->state
== ISM_DR
&& oi
->full_nbrs
> 0) {
3703 if (IS_DEBUG_OSPF_EVENT
)
3705 "LSA[Type%d:%pI4]: Schedule self-originated LSA to FLUSH",
3709 ospf_refresher_unregister_lsa(
3710 ospf
, oi
->network_lsa_self
);
3711 ospf_lsa_flush_area(oi
->network_lsa_self
, area
);
3712 ospf_lsa_unlock(&oi
->network_lsa_self
);
3713 oi
->network_lsa_self
= NULL
;
3715 oip
= ospf_lookup_if_params(
3716 oi
->ifp
, oi
->address
->u
.prefix4
);
3718 oip
->network_lsa_seqnum
= htonl(
3719 OSPF_INVALID_SEQUENCE_NUMBER
);
3722 if (oi
->type
!= OSPF_IFTYPE_VIRTUALLINK
3723 && area
->external_routing
== OSPF_AREA_DEFAULT
)
3724 need_to_flush_ase
= 1;
3727 LSDB_LOOP (SUMMARY_LSDB(area
), rn
, lsa
)
3728 ospf_lsa_flush_schedule(ospf
, lsa
);
3729 LSDB_LOOP (ASBR_SUMMARY_LSDB(area
), rn
, lsa
)
3730 ospf_lsa_flush_schedule(ospf
, lsa
);
3731 LSDB_LOOP (OPAQUE_LINK_LSDB(area
), rn
, lsa
)
3732 ospf_lsa_flush_schedule(ospf
, lsa
);
3733 LSDB_LOOP (OPAQUE_AREA_LSDB(area
), rn
, lsa
)
3734 ospf_lsa_flush_schedule(ospf
, lsa
);
3737 if (need_to_flush_ase
) {
3738 LSDB_LOOP (EXTERNAL_LSDB(ospf
), rn
, lsa
)
3739 ospf_lsa_flush_schedule(ospf
, lsa
);
3740 LSDB_LOOP (OPAQUE_AS_LSDB(ospf
), rn
, lsa
)
3741 ospf_lsa_flush_schedule(ospf
, lsa
);
3745 * Make sure that the MaxAge LSA remover is executed immediately,
3746 * without conflicting to other threads.
3748 if (ospf
->t_maxage
!= NULL
) {
3749 EVENT_OFF(ospf
->t_maxage
);
3750 event_execute(master
, ospf_maxage_lsa_remover
, ospf
, 0);
3756 /** @brief Function to refresh all the self originated
3757 * LSAs for area, when FR state change happens.
3758 * @param area pointer.
3761 void ospf_refresh_area_self_lsas(struct ospf_area
*area
)
3763 struct listnode
*node2
;
3764 struct listnode
*nnode2
;
3765 struct ospf_interface
*oi
;
3766 struct route_node
*rn
;
3767 struct ospf_lsa
*lsa
;
3772 if (area
->router_lsa_self
)
3773 ospf_lsa_refresh(area
->ospf
, area
->router_lsa_self
);
3775 for (ALL_LIST_ELEMENTS(area
->oiflist
, node2
, nnode2
, oi
))
3776 if (oi
->network_lsa_self
)
3777 ospf_lsa_refresh(oi
->ospf
, oi
->network_lsa_self
);
3779 LSDB_LOOP (SUMMARY_LSDB(area
), rn
, lsa
)
3780 if (IS_LSA_SELF(lsa
))
3781 ospf_lsa_refresh(area
->ospf
, lsa
);
3782 LSDB_LOOP (ASBR_SUMMARY_LSDB(area
), rn
, lsa
)
3783 if (IS_LSA_SELF(lsa
))
3784 ospf_lsa_refresh(area
->ospf
, lsa
);
3785 LSDB_LOOP (OPAQUE_LINK_LSDB(area
), rn
, lsa
)
3786 if (IS_LSA_SELF(lsa
))
3787 ospf_lsa_refresh(area
->ospf
, lsa
);
3788 LSDB_LOOP (OPAQUE_AREA_LSDB(area
), rn
, lsa
)
3789 if (IS_LSA_SELF(lsa
))
3790 ospf_lsa_refresh(area
->ospf
, lsa
);
3791 LSDB_LOOP (EXTERNAL_LSDB(area
->ospf
), rn
, lsa
)
3792 if (IS_LSA_SELF(lsa
))
3793 ospf_lsa_refresh(area
->ospf
, lsa
);
3794 LSDB_LOOP (OPAQUE_AS_LSDB(area
->ospf
), rn
, lsa
)
3795 if (IS_LSA_SELF(lsa
))
3796 ospf_lsa_refresh(area
->ospf
, lsa
);
3799 /* If there is self-originated LSA, then return 1, otherwise return 0. */
3800 /* An interface-independent version of ospf_lsa_is_self_originated */
3801 int ospf_lsa_is_self_originated(struct ospf
*ospf
, struct ospf_lsa
*lsa
)
3803 struct listnode
*node
;
3804 struct ospf_interface
*oi
;
3806 /* This LSA is already checked. */
3807 if (CHECK_FLAG(lsa
->flags
, OSPF_LSA_SELF_CHECKED
))
3808 return IS_LSA_SELF(lsa
);
3810 /* Make sure LSA is self-checked. */
3811 SET_FLAG(lsa
->flags
, OSPF_LSA_SELF_CHECKED
);
3813 /* AdvRouter and Router ID is the same. */
3814 if (IPV4_ADDR_SAME(&lsa
->data
->adv_router
, &ospf
->router_id
))
3815 SET_FLAG(lsa
->flags
, OSPF_LSA_SELF
);
3817 /* LSA is router-LSA. */
3818 else if (lsa
->data
->type
== OSPF_ROUTER_LSA
3819 && IPV4_ADDR_SAME(&lsa
->data
->id
, &ospf
->router_id
))
3820 SET_FLAG(lsa
->flags
, OSPF_LSA_SELF
);
3822 /* LSA is network-LSA. Compare Link ID with all interfaces. */
3823 else if (lsa
->data
->type
== OSPF_NETWORK_LSA
)
3824 for (ALL_LIST_ELEMENTS_RO(ospf
->oiflist
, node
, oi
)) {
3825 /* Ignore virtual link. */
3826 if (oi
->type
!= OSPF_IFTYPE_VIRTUALLINK
)
3827 if (oi
->address
->family
== AF_INET
)
3830 &oi
->address
->u
.prefix4
)) {
3831 /* to make it easier later */
3832 SET_FLAG(lsa
->flags
,
3834 return IS_LSA_SELF(lsa
);
3838 return IS_LSA_SELF(lsa
);
3841 /* Get unique Link State ID. */
3842 enum lsid_status
ospf_lsa_unique_id(struct ospf
*ospf
, struct ospf_lsdb
*lsdb
,
3843 uint8_t type
, struct prefix_ipv4
*p
,
3846 struct ospf_lsa
*lsa
;
3847 struct in_addr mask
;
3851 /* Check existence of LSA instance. */
3852 lsa
= ospf_lsdb_lookup_by_id(lsdb
, type
, *id
, ospf
->router_id
);
3854 struct as_external_lsa
*al
=
3855 (struct as_external_lsa
*)lsa
->data
;
3856 /* Ref rfc2328,Appendex E.1
3857 * If router already originated the external lsa with lsid
3858 * as the current prefix, and the masklens are same then
3859 * terminate the LSID algorithem.
3861 if (ip_masklen(al
->mask
) == p
->prefixlen
) {
3862 if (IS_DEBUG_OSPF(lsa
, LSA_GENERATE
))
3864 "%s: Can't get Link State ID for %pFX",
3866 /* id.s_addr = 0; */
3867 id
->s_addr
= 0xffffffff;
3868 return LSID_NOT_AVAILABLE
;
3869 } else if (ip_masklen(al
->mask
) < p
->prefixlen
) {
3870 /* Ref rfc2328,Appendex E.2
3871 * the current prefix masklen is greater than the
3872 * existing LSA, then generate the Link state ID,
3873 * by setting all host bits in prefix addressa and
3876 * Eg: 1st Route : 10.0.0.0/16 - LSID:10.0.0.0
3877 * 2nd Route : 10.0.0.0/24 - LSID:10.0.0.255
3879 masklen2ip(p
->prefixlen
, &mask
);
3881 id
->s_addr
= p
->prefix
.s_addr
| (~mask
.s_addr
);
3882 lsa
= ospf_lsdb_lookup_by_id(ospf
->lsdb
, type
, *id
,
3885 if (IS_DEBUG_OSPF(lsa
, LSA_GENERATE
))
3887 "%s: Can't get Link State ID for %pFX",
3889 id
->s_addr
= 0xffffffff;
3890 return LSID_NOT_AVAILABLE
;
3893 /* Ref rfc2328,Appendex E.3
3894 * the current prefix masklen is lesser than the
3895 * existing LSA,then the originated LSA has to be
3896 * refreshed by modifying masklen, cost and tag.
3897 * Originate the old route info with new LSID by
3898 * setting the host bits in prefix address.
3900 * Eg: 1st Route : 10.0.0.0/24 - LSID:10.0.0.0
3901 * 2nd Route : 10.0.0.0/16 - ?
3902 * Since 2nd route mask len is less than firstone
3903 * LSID has to be changed.
3904 * 1st route LSID:10.0.0.255
3905 * 2nd route LSID:10.0.0.0
3907 id
->s_addr
= lsa
->data
->id
.s_addr
| (~al
->mask
.s_addr
);
3908 lsa
= ospf_lsdb_lookup_by_id(ospf
->lsdb
, type
, *id
,
3910 if (lsa
&& (ip_masklen(al
->mask
) != IPV4_MAX_BITLEN
)) {
3911 if (IS_DEBUG_OSPF(lsa
, LSA_GENERATE
))
3913 "%s: Can't get Link State ID for %pFX",
3915 id
->s_addr
= 0xffffffff;
3916 return LSID_NOT_AVAILABLE
;
3922 return LSID_AVAILABLE
;
3926 #define LSA_ACTION_FLOOD_AREA 1
3927 #define LSA_ACTION_FLUSH_AREA 2
3931 struct ospf_area
*area
;
3932 struct ospf_lsa
*lsa
;
3935 static void ospf_lsa_action(struct event
*t
)
3937 struct lsa_action
*data
;
3939 data
= EVENT_ARG(t
);
3941 if (IS_DEBUG_OSPF(lsa
, LSA
) == OSPF_DEBUG_LSA
)
3942 zlog_debug("LSA[Action]: Performing scheduled LSA action: %d",
3945 switch (data
->action
) {
3946 case LSA_ACTION_FLOOD_AREA
:
3947 ospf_flood_through_area(data
->area
, NULL
, data
->lsa
);
3949 case LSA_ACTION_FLUSH_AREA
:
3950 ospf_lsa_flush_area(data
->lsa
, data
->area
);
3954 ospf_lsa_unlock(&data
->lsa
); /* Message */
3955 XFREE(MTYPE_OSPF_MESSAGE
, data
);
3958 void ospf_schedule_lsa_flood_area(struct ospf_area
*area
, struct ospf_lsa
*lsa
)
3960 struct lsa_action
*data
;
3962 data
= XCALLOC(MTYPE_OSPF_MESSAGE
, sizeof(struct lsa_action
));
3963 data
->action
= LSA_ACTION_FLOOD_AREA
;
3965 data
->lsa
= ospf_lsa_lock(lsa
); /* Message / Flood area */
3967 event_add_event(master
, ospf_lsa_action
, data
, 0, NULL
);
3970 void ospf_schedule_lsa_flush_area(struct ospf_area
*area
, struct ospf_lsa
*lsa
)
3972 struct lsa_action
*data
;
3974 data
= XCALLOC(MTYPE_OSPF_MESSAGE
, sizeof(struct lsa_action
));
3975 data
->action
= LSA_ACTION_FLUSH_AREA
;
3977 data
->lsa
= ospf_lsa_lock(lsa
); /* Message / Flush area */
3979 event_add_event(master
, ospf_lsa_action
, data
, 0, NULL
);
3983 /* LSA Refreshment functions. */
3984 struct ospf_lsa
*ospf_lsa_refresh(struct ospf
*ospf
, struct ospf_lsa
*lsa
)
3986 struct external_info
*ei
;
3987 struct ospf_external_aggr_rt
*aggr
;
3988 struct ospf_lsa
*new = NULL
;
3989 struct as_external_lsa
*al
;
3990 struct prefix_ipv4 p
;
3992 assert(CHECK_FLAG(lsa
->flags
, OSPF_LSA_SELF
));
3993 assert(IS_LSA_SELF(lsa
));
3994 assert(lsa
->lock
> 0);
3996 switch (lsa
->data
->type
) {
3997 /* Router and Network LSAs are processed differently. */
3998 case OSPF_ROUTER_LSA
:
3999 new = ospf_router_lsa_refresh(lsa
);
4001 case OSPF_NETWORK_LSA
:
4002 new = ospf_network_lsa_refresh(lsa
);
4004 case OSPF_SUMMARY_LSA
:
4005 new = ospf_summary_lsa_refresh(ospf
, lsa
);
4007 case OSPF_ASBR_SUMMARY_LSA
:
4008 new = ospf_summary_asbr_lsa_refresh(ospf
, lsa
);
4010 case OSPF_AS_EXTERNAL_LSA
:
4011 /* Translated from NSSA Type-5s are refreshed when
4012 * from refresh of Type-7 - do not refresh these directly.
4015 al
= (struct as_external_lsa
*)lsa
->data
;
4017 p
.prefixlen
= ip_masklen(al
->mask
);
4018 p
.prefix
= lsa
->data
->id
;
4020 if (CHECK_FLAG(lsa
->flags
, OSPF_LSA_LOCAL_XLT
))
4022 ei
= ospf_external_info_check(ospf
, lsa
);
4024 new = ospf_external_lsa_refresh(
4025 ospf
, lsa
, ei
, LSA_REFRESH_FORCE
, false);
4027 aggr
= (struct ospf_external_aggr_rt
*)
4028 ospf_extrenal_aggregator_lookup(ospf
, &p
);
4030 struct external_info ei_aggr
;
4032 memset(&ei_aggr
, 0, sizeof(ei_aggr
));
4033 ei_aggr
.p
= aggr
->p
;
4034 ei_aggr
.tag
= aggr
->tag
;
4035 ei_aggr
.instance
= ospf
->instance
;
4036 ei_aggr
.route_map_set
.metric
= -1;
4037 ei_aggr
.route_map_set
.metric_type
= -1;
4039 ospf_external_lsa_refresh(ospf
, lsa
, &ei_aggr
,
4040 LSA_REFRESH_FORCE
, true);
4041 SET_FLAG(aggr
->flags
,
4042 OSPF_EXTERNAL_AGGRT_ORIGINATED
);
4044 ospf_lsa_flush_as(ospf
, lsa
);
4047 case OSPF_OPAQUE_LINK_LSA
:
4048 case OSPF_OPAQUE_AREA_LSA
:
4049 case OSPF_OPAQUE_AS_LSA
:
4050 new = ospf_opaque_lsa_refresh(lsa
);
4058 void ospf_refresher_register_lsa(struct ospf
*ospf
, struct ospf_lsa
*lsa
)
4060 uint16_t index
, current_index
;
4062 assert(lsa
->lock
> 0);
4063 assert(IS_LSA_SELF(lsa
));
4065 if (lsa
->refresh_list
< 0) {
4068 ospf
->lsa_refresh_timer
- (2 * OSPF_LS_REFRESH_JITTER
);
4070 ospf
->lsa_refresh_timer
- OSPF_LS_REFRESH_JITTER
;
4072 /* We want to refresh the LSA within OSPF_LS_REFRESH_TIME which
4074 * 1800s. Use jitter so that we send the LSA sometime between
4078 delay
= (frr_weak_random() % (max_delay
- min_delay
))
4081 current_index
= ospf
->lsa_refresh_queue
.index
4082 + (monotime(NULL
) - ospf
->lsa_refresher_started
)
4083 / OSPF_LSA_REFRESHER_GRANULARITY
;
4085 index
= (current_index
+ delay
/ OSPF_LSA_REFRESHER_GRANULARITY
)
4086 % (OSPF_LSA_REFRESHER_SLOTS
);
4088 if (IS_DEBUG_OSPF(lsa
, LSA_REFRESH
))
4090 "LSA[Refresh:Type%d:%pI4]: age %d, added to index %d",
4091 lsa
->data
->type
, &lsa
->data
->id
,
4092 LS_AGE(lsa
), index
);
4094 if (!ospf
->lsa_refresh_queue
.qs
[index
])
4095 ospf
->lsa_refresh_queue
.qs
[index
] = list_new();
4097 listnode_add(ospf
->lsa_refresh_queue
.qs
[index
],
4098 ospf_lsa_lock(lsa
)); /* lsa_refresh_queue */
4099 lsa
->refresh_list
= index
;
4101 if (IS_DEBUG_OSPF(lsa
, LSA_REFRESH
))
4103 "LSA[Refresh:Type%d:%pI4]: %s: setting refresh_list on lsa %p (slot %d)",
4104 lsa
->data
->type
, &lsa
->data
->id
, __func__
,
4105 (void *)lsa
, index
);
4109 void ospf_refresher_unregister_lsa(struct ospf
*ospf
, struct ospf_lsa
*lsa
)
4111 assert(lsa
->lock
> 0);
4112 assert(IS_LSA_SELF(lsa
));
4113 if (lsa
->refresh_list
>= 0) {
4114 struct list
*refresh_list
=
4115 ospf
->lsa_refresh_queue
.qs
[lsa
->refresh_list
];
4116 listnode_delete(refresh_list
, lsa
);
4117 if (!listcount(refresh_list
)) {
4118 list_delete(&refresh_list
);
4119 ospf
->lsa_refresh_queue
.qs
[lsa
->refresh_list
] = NULL
;
4121 lsa
->refresh_list
= -1;
4122 ospf_lsa_unlock(&lsa
); /* lsa_refresh_queue */
4126 void ospf_lsa_refresh_walker(struct event
*t
)
4128 struct list
*refresh_list
;
4129 struct listnode
*node
, *nnode
;
4130 struct ospf
*ospf
= EVENT_ARG(t
);
4131 struct ospf_lsa
*lsa
;
4133 struct list
*lsa_to_refresh
= list_new();
4136 if (IS_DEBUG_OSPF(lsa
, LSA_REFRESH
))
4137 zlog_debug("LSA[Refresh]: %s: start", __func__
);
4140 i
= ospf
->lsa_refresh_queue
.index
;
4142 /* Note: if clock has jumped backwards, then time change could be
4144 so we are careful to cast the expression to unsigned before taking
4146 ospf
->lsa_refresh_queue
.index
=
4147 ((unsigned long)(ospf
->lsa_refresh_queue
.index
4149 - ospf
->lsa_refresher_started
)
4150 / OSPF_LSA_REFRESHER_GRANULARITY
))
4151 % OSPF_LSA_REFRESHER_SLOTS
;
4153 if (IS_DEBUG_OSPF(lsa
, LSA_REFRESH
))
4154 zlog_debug("LSA[Refresh]: %s: next index %d", __func__
,
4155 ospf
->lsa_refresh_queue
.index
);
4157 for (; i
!= ospf
->lsa_refresh_queue
.index
;
4158 i
= (i
+ 1) % OSPF_LSA_REFRESHER_SLOTS
) {
4159 if (IS_DEBUG_OSPF(lsa
, LSA_REFRESH
))
4160 zlog_debug("LSA[Refresh]: %s: refresh index %d",
4163 refresh_list
= ospf
->lsa_refresh_queue
.qs
[i
];
4167 ospf
->lsa_refresh_queue
.qs
[i
] = NULL
;
4170 for (ALL_LIST_ELEMENTS(refresh_list
, node
, nnode
,
4172 if (IS_DEBUG_OSPF(lsa
, LSA_REFRESH
))
4174 "LSA[Refresh:Type%d:%pI4]: %s: refresh lsa %p (slot %d)",
4175 lsa
->data
->type
, &lsa
->data
->id
,
4176 __func__
, (void *)lsa
, i
);
4178 assert(lsa
->lock
> 0);
4179 list_delete_node(refresh_list
, node
);
4180 lsa
->refresh_list
= -1;
4181 listnode_add(lsa_to_refresh
, lsa
);
4183 list_delete(&refresh_list
);
4187 ospf
->t_lsa_refresher
= NULL
;
4188 event_add_timer(master
, ospf_lsa_refresh_walker
, ospf
,
4189 ospf
->lsa_refresh_interval
, &ospf
->t_lsa_refresher
);
4190 ospf
->lsa_refresher_started
= monotime(NULL
);
4192 for (ALL_LIST_ELEMENTS(lsa_to_refresh
, node
, nnode
, lsa
)) {
4193 dna_lsa
= ospf_check_dna_lsa(lsa
);
4194 if (!dna_lsa
) { /* refresh only non-DNA LSAs */
4195 ospf_lsa_refresh(ospf
, lsa
);
4197 assert(lsa
->lock
> 0);
4198 ospf_lsa_unlock(&lsa
); /* lsa_refresh_queue & temp for
4203 list_delete(&lsa_to_refresh
);
4205 if (IS_DEBUG_OSPF(lsa
, LSA_REFRESH
))
4206 zlog_debug("LSA[Refresh]: %s: end", __func__
);
4209 /* Flush the LSAs for the specific area */
4210 void ospf_flush_lsa_from_area(struct ospf
*ospf
, struct in_addr area_id
,
4213 struct ospf_area
*area
;
4214 struct route_node
*rn
;
4215 struct ospf_lsa
*lsa
;
4217 area
= ospf_area_get(ospf
, area_id
);
4220 case OSPF_AS_EXTERNAL_LSA
:
4221 if ((area
->external_routing
== OSPF_AREA_NSSA
) ||
4222 (area
->external_routing
== OSPF_AREA_STUB
)) {
4223 LSDB_LOOP (EXTERNAL_LSDB(ospf
), rn
, lsa
)
4224 if (IS_LSA_SELF(lsa
) &&
4225 !(CHECK_FLAG(lsa
->flags
,
4226 OSPF_LSA_LOCAL_XLT
)))
4227 ospf_lsa_flush_area(lsa
, area
);
4230 case OSPF_AS_NSSA_LSA
:
4231 LSDB_LOOP (NSSA_LSDB(area
), rn
, lsa
)
4232 if (IS_LSA_SELF(lsa
))
4233 ospf_lsa_flush_area(lsa
, area
);