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,
615 /* Describe Virtual Link. */
616 static int lsa_link_virtuallink_set(struct stream
**s
,
617 struct ospf_interface
*oi
)
619 struct ospf_neighbor
*nbr
;
620 uint16_t cost
= ospf_link_cost(oi
);
622 if (oi
->state
== ISM_PointToPoint
)
623 if ((nbr
= ospf_nbr_lookup_ptop(oi
)))
624 if (nbr
->state
== NSM_Full
) {
625 return link_info_set(s
, nbr
->router_id
,
626 oi
->address
->u
.prefix4
,
627 LSA_LINK_TYPE_VIRTUALLINK
,
634 #define lsa_link_nbma_set(S,O) lsa_link_broadcast_set (S, O)
636 /* this function add for support point-to-multipoint ,see rfc2328
638 /* from "edward rrr" <edward_rrr@hotmail.com>
639 http://marc.theaimsgroup.com/?l=zebra&m=100739222210507&w=2 */
640 static int lsa_link_ptomp_set(struct stream
**s
, struct ospf_interface
*oi
)
643 struct route_node
*rn
;
644 struct ospf_neighbor
*nbr
= NULL
;
645 struct in_addr id
, mask
;
646 uint16_t cost
= ospf_link_cost(oi
);
648 mask
.s_addr
= 0xffffffff;
649 id
.s_addr
= oi
->address
->u
.prefix4
.s_addr
;
650 links
+= link_info_set(s
, id
, mask
, LSA_LINK_TYPE_STUB
, 0, 0);
652 if (IS_DEBUG_OSPF(lsa
, LSA_GENERATE
))
653 zlog_debug("PointToMultipoint: running ptomultip_set");
655 /* Search neighbor, */
656 for (rn
= route_top(oi
->nbrs
); rn
; rn
= route_next(rn
))
657 if ((nbr
= rn
->info
) != NULL
)
659 if (!IPV4_ADDR_SAME(&nbr
->router_id
,
660 &oi
->ospf
->router_id
))
661 if (nbr
->state
== NSM_Full
)
664 links
+= link_info_set(
666 oi
->address
->u
.prefix4
,
667 LSA_LINK_TYPE_POINTOPOINT
, 0,
669 if (IS_DEBUG_OSPF(lsa
, LSA_GENERATE
))
671 "PointToMultipoint: set link to %pI4",
672 &oi
->address
->u
.prefix4
);
678 /* Set router-LSA link information. */
679 static int router_lsa_link_set(struct stream
**s
, struct ospf_area
*area
)
681 struct listnode
*node
;
682 struct ospf_interface
*oi
;
685 for (ALL_LIST_ELEMENTS_RO(area
->oiflist
, node
, oi
)) {
686 struct interface
*ifp
= oi
->ifp
;
688 /* Check interface is up, OSPF is enable. */
689 if (if_is_operative(ifp
)) {
690 if (oi
->state
!= ISM_Down
) {
691 oi
->lsa_pos_beg
= links
;
692 /* Describe each link. */
694 case OSPF_IFTYPE_POINTOPOINT
:
695 links
+= lsa_link_ptop_set(s
, oi
);
697 case OSPF_IFTYPE_BROADCAST
:
698 links
+= lsa_link_broadcast_set(s
, oi
);
700 case OSPF_IFTYPE_NBMA
:
701 links
+= lsa_link_nbma_set(s
, oi
);
703 case OSPF_IFTYPE_POINTOMULTIPOINT
:
704 links
+= lsa_link_ptomp_set(s
, oi
);
706 case OSPF_IFTYPE_VIRTUALLINK
:
708 lsa_link_virtuallink_set(s
, oi
);
710 case OSPF_IFTYPE_LOOPBACK
:
711 links
+= lsa_link_loopback_set(s
, oi
);
713 oi
->lsa_pos_end
= links
;
721 /* Set router-LSA body. */
722 void ospf_router_lsa_body_set(struct stream
**s
, struct ospf_area
*area
)
728 stream_putc(*s
, router_lsa_flags(area
));
730 /* Set Zero fields. */
733 /* Keep pointer to # links. */
734 putp
= stream_get_endp(*s
);
739 /* Set all link information. */
740 cnt
= router_lsa_link_set(s
, area
);
742 /* Set # of links here. */
743 stream_putw_at(*s
, putp
, cnt
);
746 static void ospf_stub_router_timer(struct event
*t
)
748 struct ospf_area
*area
= EVENT_ARG(t
);
750 area
->t_stub_router
= NULL
;
752 SET_FLAG(area
->stub_router_state
, OSPF_AREA_WAS_START_STUB_ROUTED
);
754 /* clear stub route state and generate router-lsa refresh, don't
755 * clobber an administratively set stub-router state though.
757 if (CHECK_FLAG(area
->stub_router_state
, OSPF_AREA_ADMIN_STUB_ROUTED
))
760 UNSET_FLAG(area
->stub_router_state
, OSPF_AREA_IS_STUB_ROUTED
);
762 ospf_router_lsa_update_area(area
);
765 static void ospf_stub_router_check(struct ospf_area
*area
)
767 /* area must either be administratively configured to be stub
768 * or startup-time stub-router must be configured and we must in a
772 if (CHECK_FLAG(area
->stub_router_state
, OSPF_AREA_ADMIN_STUB_ROUTED
)) {
773 SET_FLAG(area
->stub_router_state
, OSPF_AREA_IS_STUB_ROUTED
);
777 /* not admin-stubbed, check whether startup stubbing is configured and
778 * whether it's not been done yet
780 if (CHECK_FLAG(area
->stub_router_state
,
781 OSPF_AREA_WAS_START_STUB_ROUTED
))
784 if (area
->ospf
->stub_router_startup_time
785 == OSPF_STUB_ROUTER_UNCONFIGURED
) {
786 /* stub-router is hence done forever for this area, even if
788 * tries configure it (take effect next restart).
790 SET_FLAG(area
->stub_router_state
,
791 OSPF_AREA_WAS_START_STUB_ROUTED
);
795 /* startup stub-router configured and not yet done */
796 SET_FLAG(area
->stub_router_state
, OSPF_AREA_IS_STUB_ROUTED
);
798 OSPF_AREA_TIMER_ON(area
->t_stub_router
, ospf_stub_router_timer
,
799 area
->ospf
->stub_router_startup_time
);
802 /* Create new router-LSA. */
803 static struct ospf_lsa
*ospf_router_lsa_new(struct ospf_area
*area
)
805 struct ospf
*ospf
= area
->ospf
;
807 struct lsa_header
*lsah
;
808 struct ospf_lsa
*new;
811 if (IS_DEBUG_OSPF(lsa
, LSA_GENERATE
))
812 zlog_debug("LSA[Type1]: Create router-LSA instance");
814 /* check whether stub-router is desired, and if this is the first
817 ospf_stub_router_check(area
);
819 /* Create a stream for LSA. */
820 s
= stream_new(OSPF_MAX_LSA_SIZE
);
821 /* Set LSA common header fields. */
822 lsa_header_set(s
, LSA_OPTIONS_GET(area
) | LSA_OPTIONS_NSSA_GET(area
),
823 OSPF_ROUTER_LSA
, ospf
->router_id
, ospf
->router_id
);
825 /* Set router-LSA body fields. */
826 ospf_router_lsa_body_set(&s
, area
);
829 length
= stream_get_endp(s
);
830 lsah
= (struct lsa_header
*)STREAM_DATA(s
);
831 lsah
->length
= htons(length
);
833 /* Now, create OSPF LSA instance. */
834 new = ospf_lsa_new_and_data(length
);
837 SET_FLAG(new->flags
, OSPF_LSA_SELF
| OSPF_LSA_SELF_CHECKED
);
838 new->vrf_id
= area
->ospf
->vrf_id
;
840 /* Copy LSA data to store, discard stream. */
841 memcpy(new->data
, lsah
, length
);
847 /* Originate Router-LSA. */
848 static struct ospf_lsa
*ospf_router_lsa_originate(struct ospf_area
*area
)
850 struct ospf_lsa
*new;
852 if (area
->ospf
->gr_info
.restart_in_progress
) {
853 if (IS_DEBUG_OSPF(lsa
, LSA_GENERATE
))
855 "LSA[Type%d]: Graceful Restart in progress, don't originate",
860 /* Create new router-LSA instance. */
861 if ((new = ospf_router_lsa_new(area
)) == NULL
) {
862 zlog_err("%s: ospf_router_lsa_new returned NULL", __func__
);
867 if (new->data
->adv_router
.s_addr
== INADDR_ANY
) {
868 if (IS_DEBUG_OSPF_EVENT
)
869 zlog_debug("LSA[Type1]: AdvRouter is 0, discard");
870 ospf_lsa_discard(new);
874 /* Install LSA to LSDB. */
875 new = ospf_lsa_install(area
->ospf
, NULL
, new);
877 /* Update LSA origination count. */
878 area
->ospf
->lsa_originate_count
++;
880 /* Flooding new LSA through area. */
881 ospf_flood_through_area(area
, NULL
, new);
883 if (IS_DEBUG_OSPF(lsa
, LSA_GENERATE
)) {
884 zlog_debug("LSA[Type%d:%pI4]: Originate router-LSA %p",
885 new->data
->type
, &new->data
->id
,
887 ospf_lsa_header_dump(new->data
);
893 /* Refresh router-LSA. */
894 static struct ospf_lsa
*ospf_router_lsa_refresh(struct ospf_lsa
*lsa
)
896 struct ospf_area
*area
= lsa
->area
;
897 struct ospf_lsa
*new;
902 /* Delete LSA from neighbor retransmit-list. */
903 ospf_ls_retransmit_delete_nbr_area(area
, lsa
);
905 /* Unregister LSA from refresh-list */
906 ospf_refresher_unregister_lsa(area
->ospf
, lsa
);
908 /* Create new router-LSA instance. */
909 if ((new = ospf_router_lsa_new(area
)) == NULL
) {
910 zlog_err("%s: ospf_router_lsa_new returned NULL", __func__
);
914 new->data
->ls_seqnum
= lsa_seqnum_increment(lsa
);
916 ospf_lsa_install(area
->ospf
, NULL
, new);
918 /* Flood LSA through area. */
919 ospf_flood_through_area(area
, NULL
, new);
922 if (IS_DEBUG_OSPF(lsa
, LSA_GENERATE
)) {
923 zlog_debug("LSA[Type%d:%pI4]: router-LSA refresh",
924 new->data
->type
, &new->data
->id
);
925 ospf_lsa_header_dump(new->data
);
931 int ospf_router_lsa_update_area(struct ospf_area
*area
)
933 if (IS_DEBUG_OSPF_EVENT
)
934 zlog_debug("[router-LSA]: (router-LSA area update)");
936 /* Now refresh router-LSA. */
937 if (area
->router_lsa_self
)
938 ospf_lsa_refresh(area
->ospf
, area
->router_lsa_self
);
939 /* Newly originate router-LSA. */
941 ospf_router_lsa_originate(area
);
946 int ospf_router_lsa_update(struct ospf
*ospf
)
948 struct listnode
*node
, *nnode
;
949 struct ospf_area
*area
;
951 if (IS_DEBUG_OSPF(lsa
, LSA_GENERATE
))
952 zlog_debug("Timer[router-LSA Update]: (timer expire)");
954 for (ALL_LIST_ELEMENTS(ospf
->areas
, node
, nnode
, area
)) {
955 struct ospf_lsa
*lsa
= area
->router_lsa_self
;
956 struct router_lsa
*rl
;
957 const char *area_str
;
959 /* Keep Area ID string. */
960 area_str
= AREA_NAME(area
);
962 /* If LSA not exist in this Area, originate new. */
964 if (IS_DEBUG_OSPF(lsa
, LSA_GENERATE
))
966 "LSA[Type1]: Create router-LSA for Area %s",
969 ospf_router_lsa_originate(area
);
971 /* If router-ID is changed, Link ID must change.
972 First flush old LSA, then originate new. */
973 else if (!IPV4_ADDR_SAME(&lsa
->data
->id
, &ospf
->router_id
)) {
974 if (IS_DEBUG_OSPF(lsa
, LSA_GENERATE
))
976 "LSA[Type%d:%pI4]: Refresh router-LSA for Area %s",
978 &lsa
->data
->id
, area_str
);
979 ospf_refresher_unregister_lsa(ospf
, lsa
);
980 ospf_lsa_flush_area(lsa
, area
);
981 ospf_lsa_unlock(&area
->router_lsa_self
);
982 area
->router_lsa_self
= NULL
;
984 /* Refresh router-LSA, (not install) and flood through
986 ospf_router_lsa_update_area(area
);
988 rl
= (struct router_lsa
*)lsa
->data
;
989 /* Refresh router-LSA, (not install) and flood through
991 if (rl
->flags
!= ospf
->flags
)
992 ospf_router_lsa_update_area(area
);
1000 /* network-LSA related functions. */
1001 /* Originate Network-LSA. */
1002 static void ospf_network_lsa_body_set(struct stream
*s
,
1003 struct ospf_interface
*oi
)
1005 struct in_addr mask
;
1006 struct route_node
*rn
;
1007 struct ospf_neighbor
*nbr
;
1009 masklen2ip(oi
->address
->prefixlen
, &mask
);
1010 stream_put_ipv4(s
, mask
.s_addr
);
1012 /* The network-LSA lists those routers that are fully adjacent to
1013 the Designated Router; each fully adjacent router is identified by
1014 its OSPF Router ID. The Designated Router includes itself in this
1015 list. RFC2328, Section 12.4.2 */
1017 for (rn
= route_top(oi
->nbrs
); rn
; rn
= route_next(rn
))
1018 if ((nbr
= rn
->info
) != NULL
)
1019 if (nbr
->state
== NSM_Full
|| nbr
== oi
->nbr_self
)
1020 stream_put_ipv4(s
, nbr
->router_id
.s_addr
);
1023 static struct ospf_lsa
*ospf_network_lsa_new(struct ospf_interface
*oi
)
1026 struct ospf_lsa
*new;
1027 struct lsa_header
*lsah
;
1028 struct ospf_if_params
*oip
;
1031 /* If there are no neighbours on this network (the net is stub),
1032 the router does not originate network-LSA (see RFC 12.4.2) */
1033 if (oi
->full_nbrs
== 0)
1036 if (IS_DEBUG_OSPF(lsa
, LSA_GENERATE
))
1037 zlog_debug("LSA[Type2]: Create network-LSA instance");
1039 /* Create new stream for LSA. */
1040 s
= stream_new(OSPF_MAX_LSA_SIZE
);
1041 lsah
= (struct lsa_header
*)STREAM_DATA(s
);
1043 lsa_header_set(s
, (OPTIONS(oi
) | LSA_OPTIONS_GET(oi
->area
)),
1044 OSPF_NETWORK_LSA
, DR(oi
), oi
->ospf
->router_id
);
1046 /* Set network-LSA body fields. */
1047 ospf_network_lsa_body_set(s
, oi
);
1050 length
= stream_get_endp(s
);
1051 lsah
->length
= htons(length
);
1053 /* Create OSPF LSA instance. */
1054 new = ospf_lsa_new_and_data(length
);
1056 new->area
= oi
->area
;
1057 SET_FLAG(new->flags
, OSPF_LSA_SELF
| OSPF_LSA_SELF_CHECKED
);
1058 new->vrf_id
= oi
->ospf
->vrf_id
;
1060 /* Copy LSA to store. */
1061 memcpy(new->data
, lsah
, length
);
1064 /* Remember prior network LSA sequence numbers, even if we stop
1065 * originating one for this oi, to try avoid re-originating LSAs with a
1066 * prior sequence number, and thus speed up adjency forming &
1069 if ((oip
= ospf_lookup_if_params(oi
->ifp
, oi
->address
->u
.prefix4
))) {
1070 new->data
->ls_seqnum
= oip
->network_lsa_seqnum
;
1071 new->data
->ls_seqnum
= lsa_seqnum_increment(new);
1073 oip
= ospf_get_if_params(oi
->ifp
, oi
->address
->u
.prefix4
);
1074 ospf_if_update_params(oi
->ifp
, oi
->address
->u
.prefix4
);
1076 oip
->network_lsa_seqnum
= new->data
->ls_seqnum
;
1081 /* Originate network-LSA. */
1082 void ospf_network_lsa_update(struct ospf_interface
*oi
)
1084 struct ospf_lsa
*new;
1086 if (oi
->area
->ospf
->gr_info
.restart_in_progress
) {
1087 if (IS_DEBUG_OSPF(lsa
, LSA_GENERATE
))
1089 "LSA[Type%d]: Graceful Restart in progress, don't originate",
1094 if (oi
->network_lsa_self
!= NULL
) {
1095 ospf_lsa_refresh(oi
->ospf
, oi
->network_lsa_self
);
1099 /* Create new network-LSA instance. */
1100 new = ospf_network_lsa_new(oi
);
1104 /* Install LSA to LSDB. */
1105 new = ospf_lsa_install(oi
->ospf
, oi
, new);
1107 /* Update LSA origination count. */
1108 oi
->ospf
->lsa_originate_count
++;
1110 /* Flooding new LSA through area. */
1111 ospf_flood_through_area(oi
->area
, NULL
, new);
1113 if (IS_DEBUG_OSPF(lsa
, LSA_GENERATE
)) {
1114 zlog_debug("LSA[Type%d:%pI4]: Originate network-LSA %p",
1115 new->data
->type
, &new->data
->id
,
1117 ospf_lsa_header_dump(new->data
);
1123 static struct ospf_lsa
*ospf_network_lsa_refresh(struct ospf_lsa
*lsa
)
1125 struct ospf_area
*area
= lsa
->area
;
1126 struct ospf_lsa
*new, *new2
;
1127 struct ospf_if_params
*oip
;
1128 struct ospf_interface
*oi
;
1132 /* Retrieve the oi for the network LSA */
1133 oi
= ospf_if_lookup_by_local_addr(area
->ospf
, NULL
, lsa
->data
->id
);
1135 if (IS_DEBUG_OSPF(lsa
, LSA_GENERATE
)) {
1137 "LSA[Type%d:%pI4]: network-LSA refresh: no oi found, ick, ignoring.",
1138 lsa
->data
->type
, &lsa
->data
->id
);
1139 ospf_lsa_header_dump(lsa
->data
);
1144 if (oi
->state
!= ISM_DR
)
1147 /* Delete LSA from neighbor retransmit-list. */
1148 ospf_ls_retransmit_delete_nbr_area(area
, lsa
);
1150 /* Unregister LSA from refresh-list */
1151 ospf_refresher_unregister_lsa(area
->ospf
, lsa
);
1153 /* Create new network-LSA instance. */
1154 new = ospf_network_lsa_new(oi
);
1158 oip
= ospf_lookup_if_params(oi
->ifp
, oi
->address
->u
.prefix4
);
1159 assert(oip
!= NULL
);
1160 oip
->network_lsa_seqnum
= new->data
->ls_seqnum
=
1161 lsa_seqnum_increment(lsa
);
1163 new2
= ospf_lsa_install(area
->ospf
, oi
, new);
1165 assert(new2
== new);
1167 /* Flood LSA through aera. */
1168 ospf_flood_through_area(area
, NULL
, new);
1170 if (IS_DEBUG_OSPF(lsa
, LSA_GENERATE
)) {
1171 zlog_debug("LSA[Type%d:%pI4]: network-LSA refresh",
1172 new->data
->type
, &new->data
->id
);
1173 ospf_lsa_header_dump(new->data
);
1179 static void stream_put_ospf_metric(struct stream
*s
, uint32_t metric_value
)
1184 /* Put 0 metric. TOS metric is not supported. */
1185 metric
= htonl(metric_value
);
1186 mp
= (char *)&metric
;
1188 stream_put(s
, mp
, 3);
1191 /* summary-LSA related functions. */
1192 static void ospf_summary_lsa_body_set(struct stream
*s
, struct prefix
*p
,
1195 struct in_addr mask
;
1197 masklen2ip(p
->prefixlen
, &mask
);
1199 /* Put Network Mask. */
1200 stream_put_ipv4(s
, mask
.s_addr
);
1203 stream_putc(s
, (uint8_t)0);
1206 stream_put_ospf_metric(s
, metric
);
1209 static struct ospf_lsa
*ospf_summary_lsa_new(struct ospf_area
*area
,
1210 struct prefix
*p
, uint32_t metric
,
1214 struct ospf_lsa
*new;
1215 struct lsa_header
*lsah
;
1218 if (id
.s_addr
== 0xffffffff) {
1219 /* Maybe Link State ID not available. */
1220 if (IS_DEBUG_OSPF(lsa
, LSA_GENERATE
))
1222 "LSA[Type%d]: Link ID not available, can't originate",
1227 if (IS_DEBUG_OSPF(lsa
, LSA_GENERATE
))
1228 zlog_debug("LSA[Type3]: Create summary-LSA instance");
1230 /* Create new stream for LSA. */
1231 s
= stream_new(OSPF_MAX_LSA_SIZE
);
1232 lsah
= (struct lsa_header
*)STREAM_DATA(s
);
1234 lsa_header_set(s
, LSA_OPTIONS_GET(area
), OSPF_SUMMARY_LSA
, id
,
1235 area
->ospf
->router_id
);
1237 /* Set summary-LSA body fields. */
1238 ospf_summary_lsa_body_set(s
, p
, metric
);
1241 length
= stream_get_endp(s
);
1242 lsah
->length
= htons(length
);
1244 /* Create OSPF LSA instance. */
1245 new = ospf_lsa_new_and_data(length
);
1247 SET_FLAG(new->flags
, OSPF_LSA_SELF
| OSPF_LSA_SELF_CHECKED
);
1248 new->vrf_id
= area
->ospf
->vrf_id
;
1250 /* Copy LSA to store. */
1251 memcpy(new->data
, lsah
, length
);
1257 /* Originate Summary-LSA. */
1258 static struct ospf_lsa
*
1259 ospf_summary_lsa_prepare_and_flood(struct prefix_ipv4
*p
, uint32_t metric
,
1260 struct ospf_area
*area
, struct in_addr id
)
1262 struct ospf_lsa
*new;
1264 /* Create new summary-LSA instance. */
1265 if (!(new = ospf_summary_lsa_new(area
, (struct prefix
*)p
, metric
, id
)))
1268 /* Instlal LSA to LSDB. */
1269 new = ospf_lsa_install(area
->ospf
, NULL
, new);
1271 /* Update LSA origination count. */
1272 area
->ospf
->lsa_originate_count
++;
1274 /* Flooding new LSA through area. */
1275 ospf_flood_through_area(area
, NULL
, new);
1277 if (IS_DEBUG_OSPF(lsa
, LSA_GENERATE
)) {
1278 zlog_debug("LSA[Type%d:%pI4]: Originate summary-LSA %p",
1279 new->data
->type
, &new->data
->id
,
1281 ospf_lsa_header_dump(new->data
);
1287 static struct ospf_lsa
*ospf_handle_summarylsa_lsId_chg(struct ospf_area
*area
,
1288 struct prefix_ipv4
*p
,
1291 struct in_addr old_id
)
1293 struct ospf_lsa
*lsa
= NULL
;
1294 struct ospf_lsa
*summary_lsa
= NULL
;
1295 struct summary_lsa
*sl
= NULL
;
1296 struct ospf_area
*old_area
= NULL
;
1297 struct ospf
*ospf
= area
->ospf
;
1298 struct prefix_ipv4 old_prefix
;
1299 uint32_t old_metric
;
1300 struct in_addr mask
;
1301 uint32_t metric_val
;
1304 lsa
= ospf_lsdb_lookup_by_id(area
->lsdb
, type
, p
->prefix
,
1308 flog_warn(EC_OSPF_LSA_NULL
, "(%s): LSA not found", __func__
);
1312 sl
= (struct summary_lsa
*)lsa
->data
;
1314 old_area
= lsa
->area
;
1315 old_metric
= GET_METRIC(sl
->metric
);
1316 old_prefix
.prefix
= sl
->header
.id
;
1317 old_prefix
.prefixlen
= ip_masklen(sl
->mask
);
1318 old_prefix
.family
= AF_INET
;
1321 /* change the mask */
1322 masklen2ip(p
->prefixlen
, &mask
);
1323 sl
->mask
.s_addr
= mask
.s_addr
;
1325 /* Copy the metric*/
1326 metric_val
= htonl(metric
);
1327 metric_buf
= (char *)&metric_val
;
1328 memcpy(sl
->metric
, metric_buf
, sizeof(metric_val
));
1330 if (type
== OSPF_SUMMARY_LSA
) {
1331 /*Refresh the LSA with new LSA*/
1332 summary_lsa
= ospf_summary_lsa_refresh(ospf
, lsa
);
1334 ospf_summary_lsa_prepare_and_flood(&old_prefix
, old_metric
,
1337 /*Refresh the LSA with new LSA*/
1338 summary_lsa
= ospf_summary_asbr_lsa_refresh(ospf
, lsa
);
1340 ospf_asbr_summary_lsa_prepare_and_flood(&old_prefix
, old_metric
,
1347 /* Originate Summary-LSA. */
1348 struct ospf_lsa
*ospf_summary_lsa_originate(struct prefix_ipv4
*p
,
1350 struct ospf_area
*area
)
1353 enum lsid_status status
;
1354 struct ospf_lsa
*new = NULL
;
1356 status
= ospf_lsa_unique_id(area
->ospf
, area
->lsdb
, OSPF_SUMMARY_LSA
, p
,
1359 if (status
== LSID_CHANGE
) {
1360 if (IS_DEBUG_OSPF(lsa
, LSA_GENERATE
))
1361 zlog_debug("Link ID has to be changed.");
1363 new = ospf_handle_summarylsa_lsId_chg(area
, p
, OSPF_SUMMARY_LSA
,
1366 } else if (status
== LSID_NOT_AVAILABLE
) {
1367 /* Link State ID not available. */
1368 if (IS_DEBUG_OSPF(lsa
, LSA_GENERATE
))
1370 "LSA[Type5]: Link ID not available, can't originate");
1375 new = ospf_summary_lsa_prepare_and_flood(p
, metric
, area
, id
);
1379 static struct ospf_lsa
*ospf_summary_lsa_refresh(struct ospf
*ospf
,
1380 struct ospf_lsa
*lsa
)
1382 struct ospf_lsa
*new;
1383 struct summary_lsa
*sl
;
1389 sl
= (struct summary_lsa
*)lsa
->data
;
1390 p
.prefixlen
= ip_masklen(sl
->mask
);
1391 new = ospf_summary_lsa_new(lsa
->area
, &p
, GET_METRIC(sl
->metric
),
1397 new->data
->ls_seqnum
= lsa_seqnum_increment(lsa
);
1399 ospf_lsa_install(ospf
, NULL
, new);
1401 /* Flood LSA through AS. */
1402 ospf_flood_through_area(new->area
, NULL
, new);
1404 /* Debug logging. */
1405 if (IS_DEBUG_OSPF(lsa
, LSA_GENERATE
)) {
1406 zlog_debug("LSA[Type%d:%pI4]: summary-LSA refresh",
1407 new->data
->type
, &new->data
->id
);
1408 ospf_lsa_header_dump(new->data
);
1415 /* summary-ASBR-LSA related functions. */
1416 static void ospf_summary_asbr_lsa_body_set(struct stream
*s
, struct prefix
*p
,
1419 /* Put Network Mask. */
1420 stream_put_ipv4(s
, (uint32_t)0);
1423 stream_putc(s
, (uint8_t)0);
1426 stream_put_ospf_metric(s
, metric
);
1429 static struct ospf_lsa
*ospf_summary_asbr_lsa_new(struct ospf_area
*area
,
1435 struct ospf_lsa
*new;
1436 struct lsa_header
*lsah
;
1439 if (id
.s_addr
== 0xffffffff) {
1440 /* Maybe Link State ID not available. */
1441 if (IS_DEBUG_OSPF(lsa
, LSA_GENERATE
))
1443 "LSA[Type%d]: Link ID not available, can't originate",
1444 OSPF_ASBR_SUMMARY_LSA
);
1448 if (IS_DEBUG_OSPF(lsa
, LSA_GENERATE
))
1449 zlog_debug("LSA[Type3]: Create summary-LSA instance");
1451 /* Create new stream for LSA. */
1452 s
= stream_new(OSPF_MAX_LSA_SIZE
);
1453 lsah
= (struct lsa_header
*)STREAM_DATA(s
);
1455 lsa_header_set(s
, LSA_OPTIONS_GET(area
), OSPF_ASBR_SUMMARY_LSA
, id
,
1456 area
->ospf
->router_id
);
1458 /* Set summary-LSA body fields. */
1459 ospf_summary_asbr_lsa_body_set(s
, p
, metric
);
1462 length
= stream_get_endp(s
);
1463 lsah
->length
= htons(length
);
1465 /* Create OSPF LSA instance. */
1466 new = ospf_lsa_new_and_data(length
);
1468 SET_FLAG(new->flags
, OSPF_LSA_SELF
| OSPF_LSA_SELF_CHECKED
);
1469 new->vrf_id
= area
->ospf
->vrf_id
;
1471 /* Copy LSA to store. */
1472 memcpy(new->data
, lsah
, length
);
1478 /* Originate summary-ASBR-LSA. */
1479 static struct ospf_lsa
*
1480 ospf_asbr_summary_lsa_prepare_and_flood(struct prefix_ipv4
*p
, uint32_t metric
,
1481 struct ospf_area
*area
,
1484 struct ospf_lsa
*new;
1486 /* Create new summary-LSA instance. */
1487 new = ospf_summary_asbr_lsa_new(area
, (struct prefix
*)p
, metric
, id
);
1491 /* Install LSA to LSDB. */
1492 new = ospf_lsa_install(area
->ospf
, NULL
, new);
1494 /* Update LSA origination count. */
1495 area
->ospf
->lsa_originate_count
++;
1497 /* Flooding new LSA through area. */
1498 ospf_flood_through_area(area
, NULL
, new);
1500 if (IS_DEBUG_OSPF(lsa
, LSA_GENERATE
)) {
1501 zlog_debug("LSA[Type%d:%pI4]: Originate summary-ASBR-LSA %p",
1502 new->data
->type
, &new->data
->id
,
1504 ospf_lsa_header_dump(new->data
);
1510 struct ospf_lsa
*ospf_summary_asbr_lsa_originate(struct prefix_ipv4
*p
,
1512 struct ospf_area
*area
)
1514 struct ospf_lsa
*new;
1516 enum lsid_status status
;
1518 status
= ospf_lsa_unique_id(area
->ospf
, area
->lsdb
,
1519 OSPF_ASBR_SUMMARY_LSA
, p
, &id
);
1521 if (status
== LSID_CHANGE
) {
1522 if (IS_DEBUG_OSPF(lsa
, LSA_GENERATE
))
1523 zlog_debug("Link ID has to be changed.");
1525 new = ospf_handle_summarylsa_lsId_chg(
1526 area
, p
, OSPF_ASBR_SUMMARY_LSA
, metric
, id
);
1528 } else if (status
== LSID_NOT_AVAILABLE
) {
1529 /* Link State ID not available. */
1530 if (IS_DEBUG_OSPF(lsa
, LSA_GENERATE
))
1532 "LSA[Type5]: Link ID not available, can't originate");
1537 new = ospf_asbr_summary_lsa_prepare_and_flood(p
, metric
, area
, id
);
1541 static struct ospf_lsa
*ospf_summary_asbr_lsa_refresh(struct ospf
*ospf
,
1542 struct ospf_lsa
*lsa
)
1544 struct ospf_lsa
*new;
1545 struct summary_lsa
*sl
;
1547 bool ind_lsa
= false;
1552 if (lsa
->area
->fr_info
.indication_lsa_self
&&
1553 (lsa
->area
->fr_info
.indication_lsa_self
== lsa
))
1556 sl
= (struct summary_lsa
*)lsa
->data
;
1557 p
.prefixlen
= ip_masklen(sl
->mask
);
1558 new = ospf_summary_asbr_lsa_new(lsa
->area
, &p
, GET_METRIC(sl
->metric
),
1563 new->data
->ls_seqnum
= lsa_seqnum_increment(lsa
);
1565 ospf_lsa_install(ospf
, NULL
, new);
1567 /* Flood LSA through area. */
1568 ospf_flood_through_area(new->area
, NULL
, new);
1571 new->area
->fr_info
.indication_lsa_self
= new;
1573 if (IS_DEBUG_OSPF(lsa
, LSA_GENERATE
)) {
1574 zlog_debug("LSA[Type%d:%pI4]: summary-ASBR-LSA refresh",
1575 new->data
->type
, &new->data
->id
);
1576 ospf_lsa_header_dump(new->data
);
1582 /* AS-external-LSA related functions. */
1584 /* Get nexthop for AS-external-LSAs. Return nexthop if its interface
1585 is connected, else 0*/
1586 static struct in_addr
ospf_external_lsa_nexthop_get(struct ospf
*ospf
,
1587 struct in_addr nexthop
)
1591 struct listnode
*node
;
1592 struct ospf_interface
*oi
;
1596 if (!nexthop
.s_addr
)
1599 /* Check whether nexthop is covered by OSPF network. */
1600 nh
.family
= AF_INET
;
1601 nh
.u
.prefix4
= nexthop
;
1602 nh
.prefixlen
= IPV4_MAX_BITLEN
;
1604 /* XXX/SCALE: If there were a lot of oi's on an ifp, then it'd be
1605 * better to make use of the per-ifp table of ois.
1607 for (ALL_LIST_ELEMENTS_RO(ospf
->oiflist
, node
, oi
))
1608 if (if_is_operative(oi
->ifp
))
1609 if (oi
->address
->family
== AF_INET
)
1610 if (prefix_match(oi
->address
, &nh
))
1616 /* NSSA-external-LSA related functions. */
1618 /* Get 1st IP connection for Forward Addr */
1620 struct in_addr
ospf_get_ip_from_ifp(struct ospf_interface
*oi
)
1624 fwd
.s_addr
= INADDR_ANY
;
1626 if (if_is_operative(oi
->ifp
))
1627 return oi
->address
->u
.prefix4
;
1632 /* Get 1st IP connection for Forward Addr */
1633 struct in_addr
ospf_get_nssa_ip(struct ospf_area
*area
)
1636 struct in_addr best_default
;
1637 struct listnode
*node
;
1638 struct ospf_interface
*oi
;
1641 best_default
.s_addr
= 0;
1643 for (ALL_LIST_ELEMENTS_RO(area
->ospf
->oiflist
, node
, oi
)) {
1644 if (if_is_operative(oi
->ifp
))
1645 if (oi
->area
->external_routing
== OSPF_AREA_NSSA
)
1647 && oi
->address
->family
== AF_INET
) {
1648 if (best_default
.s_addr
== INADDR_ANY
)
1650 oi
->address
->u
.prefix4
;
1651 if (oi
->area
== area
)
1652 return oi
->address
->u
.prefix4
;
1655 if (best_default
.s_addr
!= INADDR_ANY
)
1656 return best_default
;
1661 int metric_type(struct ospf
*ospf
, uint8_t src
, unsigned short instance
)
1663 struct ospf_redist
*red
;
1665 red
= ospf_redist_lookup(ospf
, src
, instance
);
1667 return ((!red
|| red
->dmetric
.type
< 0) ? DEFAULT_METRIC_TYPE
1668 : red
->dmetric
.type
);
1671 int metric_value(struct ospf
*ospf
, uint8_t src
, unsigned short instance
)
1673 struct ospf_redist
*red
;
1675 red
= ospf_redist_lookup(ospf
, src
, instance
);
1676 if (!red
|| red
->dmetric
.value
< 0) {
1677 if (src
== DEFAULT_ROUTE
) {
1678 if (ospf
->default_originate
== DEFAULT_ORIGINATE_ZEBRA
)
1679 return DEFAULT_DEFAULT_ORIGINATE_METRIC
;
1681 return DEFAULT_DEFAULT_ALWAYS_METRIC
;
1682 } else if (ospf
->default_metric
< 0)
1683 return DEFAULT_DEFAULT_METRIC
;
1685 return ospf
->default_metric
;
1688 return red
->dmetric
.value
;
1691 /* Set AS-external-LSA body. */
1692 static void ospf_external_lsa_body_set(struct stream
*s
,
1693 struct external_info
*ei
,
1696 struct prefix_ipv4
*p
= &ei
->p
;
1697 struct in_addr mask
, fwd_addr
;
1701 unsigned short instance
;
1703 /* Put Network Mask. */
1704 masklen2ip(p
->prefixlen
, &mask
);
1705 stream_put_ipv4(s
, mask
.s_addr
);
1707 /* If prefix is default, specify DEFAULT_ROUTE. */
1708 type
= is_default_prefix4(&ei
->p
) ? DEFAULT_ROUTE
: ei
->type
;
1709 instance
= is_default_prefix4(&ei
->p
) ? 0 : ei
->instance
;
1711 mtype
= (ROUTEMAP_METRIC_TYPE(ei
) != -1)
1712 ? ROUTEMAP_METRIC_TYPE(ei
)
1713 : metric_type(ospf
, type
, instance
);
1715 mvalue
= (ROUTEMAP_METRIC(ei
) != -1)
1716 ? ROUTEMAP_METRIC(ei
)
1717 : metric_value(ospf
, type
, instance
);
1719 /* Put type of external metric. */
1720 stream_putc(s
, (mtype
== EXTERNAL_METRIC_TYPE_2
? 0x80 : 0));
1722 /* Put 0 metric. TOS metric is not supported. */
1723 stream_put_ospf_metric(s
, mvalue
);
1725 /* Get forwarding address to nexthop if on the Connection List, else 0.
1727 fwd_addr
= ospf_external_lsa_nexthop_get(ospf
, ei
->nexthop
);
1729 /* Put forwarding address. */
1730 stream_put_ipv4(s
, fwd_addr
.s_addr
);
1733 stream_putl(s
, ei
->tag
);
1736 /* Create new external-LSA. */
1737 static struct ospf_lsa
*
1738 ospf_exnl_lsa_prepare_and_flood(struct ospf
*ospf
, struct external_info
*ei
,
1742 struct lsa_header
*lsah
;
1743 struct ospf_lsa
*new;
1746 /* Create new stream for LSA. */
1747 s
= stream_new(OSPF_MAX_LSA_SIZE
);
1748 lsah
= (struct lsa_header
*)STREAM_DATA(s
);
1750 /* Set LSA common header fields. */
1751 lsa_header_set(s
, OSPF_OPTION_E
, OSPF_AS_EXTERNAL_LSA
, id
,
1754 /* Set AS-external-LSA body fields. */
1755 ospf_external_lsa_body_set(s
, ei
, ospf
);
1758 length
= stream_get_endp(s
);
1759 lsah
->length
= htons(length
);
1761 /* Now, create OSPF LSA instance. */
1762 new = ospf_lsa_new_and_data(length
);
1764 SET_FLAG(new->flags
,
1765 OSPF_LSA_SELF
| OSPF_LSA_APPROVED
| OSPF_LSA_SELF_CHECKED
);
1766 new->vrf_id
= ospf
->vrf_id
;
1768 /* Copy LSA data to store, discard stream. */
1769 memcpy(new->data
, lsah
, length
);
1775 static struct ospf_lsa
*ospf_handle_exnl_lsa_lsId_chg(struct ospf
*ospf
,
1776 struct external_info
*ei
,
1779 struct ospf_lsa
*lsa
;
1780 struct as_external_lsa
*al
;
1781 struct in_addr mask
;
1782 struct ospf_lsa
*new;
1783 struct external_info ei_summary
= {};
1784 struct external_info
*ei_old
;
1786 lsa
= ospf_lsdb_lookup_by_id(ospf
->lsdb
, OSPF_AS_EXTERNAL_LSA
,
1787 ei
->p
.prefix
, ospf
->router_id
);
1790 flog_warn(EC_OSPF_LSA_NULL
, "(%s): LSA not found", __func__
);
1794 ei_old
= ospf_external_info_check(ospf
, lsa
);
1796 al
= (struct as_external_lsa
*)lsa
->data
;
1799 /* eii_old pointer of LSA is NULL, this
1800 * must be external aggregate route.
1802 ei_summary
.p
.family
= AF_INET
;
1803 ei_summary
.p
.prefix
= al
->header
.id
;
1804 ei_summary
.p
.prefixlen
= ip_masklen(al
->mask
);
1805 ei_summary
.tag
= (unsigned long)ntohl(al
->e
[0].route_tag
);
1806 ei_old
= &ei_summary
;
1809 /* change the mask */
1810 masklen2ip(ei
->p
.prefixlen
, &mask
);
1811 al
->mask
.s_addr
= mask
.s_addr
;
1813 /*Refresh the LSA with new LSA*/
1814 ospf_external_lsa_refresh(ospf
, lsa
, ei
, LSA_REFRESH_FORCE
, 0);
1816 /*Originate the old LSA with changed LSID*/
1817 new = ospf_exnl_lsa_prepare_and_flood(ospf
, ei_old
, id
);
1822 static struct ospf_lsa
*ospf_external_lsa_new(struct ospf
*ospf
,
1823 struct external_info
*ei
,
1824 struct in_addr
*old_id
)
1826 struct ospf_lsa
*new;
1828 enum lsid_status status
;
1831 if (IS_DEBUG_OSPF(lsa
, LSA_GENERATE
))
1833 "LSA[Type5]: External info is NULL, can't originate");
1837 if (IS_DEBUG_OSPF(lsa
, LSA_GENERATE
))
1838 zlog_debug("LSA[Type5]: Originate AS-external-LSA instance");
1840 /* If old Link State ID is specified, refresh LSA with same ID. */
1843 /* Get Link State with unique ID. */
1845 status
= ospf_lsa_unique_id(ospf
, ospf
->lsdb
,
1846 OSPF_AS_EXTERNAL_LSA
, &ei
->p
, &id
);
1848 if (status
== LSID_CHANGE
) {
1849 if (IS_DEBUG_OSPF(lsa
, LSA_GENERATE
))
1850 zlog_debug("Link ID has to be changed.");
1852 new = ospf_handle_exnl_lsa_lsId_chg(ospf
, ei
, id
);
1854 } else if (status
== LSID_NOT_AVAILABLE
) {
1855 /* Link State ID not available. */
1856 if (IS_DEBUG_OSPF(lsa
, LSA_GENERATE
))
1858 "LSA[Type5]: Link ID not available, can't originate");
1863 new = ospf_exnl_lsa_prepare_and_flood(ospf
, ei
, id
);
1869 static void ospf_install_flood_nssa(struct ospf
*ospf
, struct ospf_lsa
*lsa
)
1871 struct ospf_lsa
*new;
1872 struct as_external_lsa
*extlsa
;
1873 struct ospf_area
*area
;
1874 struct listnode
*node
, *nnode
;
1876 /* LSA may be a Type-5 originated via translation of a Type-7 LSA
1877 * which originated from an NSSA area. In which case it should not be
1878 * flooded back to NSSA areas.
1880 if (CHECK_FLAG(lsa
->flags
, OSPF_LSA_LOCAL_XLT
))
1883 /* NSSA Originate or Refresh (If anyNSSA)
1885 LSA is self-originated. And just installed as Type-5.
1886 Additionally, install as Type-7 LSDB for every attached NSSA.
1888 P-Bit controls which ABR performs translation to outside world; If
1889 we are an ABR....do not set the P-bit, because we send the Type-5,
1890 not as the ABR Translator, but as the ASBR owner within the AS!
1892 If we are NOT ABR, Flood through NSSA as Type-7 w/P-bit set. The
1893 elected ABR Translator will see the P-bit, Translate, and re-flood.
1895 Later, ABR_TASK and P-bit will scan Type-7 LSDB and translate to
1896 Type-5's to non-NSSA Areas. (it will also attempt a re-install) */
1898 for (ALL_LIST_ELEMENTS(ospf
->areas
, node
, nnode
, area
)) {
1899 /* Don't install Type-7 LSA's into nonNSSA area */
1900 if (area
->external_routing
!= OSPF_AREA_NSSA
)
1903 /* make lsa duplicate, lock=1 */
1904 new = ospf_lsa_dup(lsa
);
1906 new->data
->type
= OSPF_AS_NSSA_LSA
;
1908 /* set P-bit if not ABR */
1909 if (!IS_OSPF_ABR(ospf
)) {
1910 SET_FLAG(new->data
->options
, OSPF_OPTION_NP
);
1912 /* set non-zero FWD ADDR
1914 draft-ietf-ospf-nssa-update-09.txt
1916 if the network between the NSSA AS boundary router and
1918 adjacent AS is advertised into OSPF as an internal OSPF
1920 the forwarding address should be the next op address as
1922 currently done with type-5 LSAs. If the intervening
1924 not adversited into OSPF as an internal OSPF route and
1926 type-7 LSA's P-bit is set a forwarding address should be
1927 selected from one of the router's active OSPF interface
1929 which belong to the NSSA. If no such addresses exist,
1931 no type-7 LSA's with the P-bit set should originate from
1935 /* kevinm: not updating lsa anymore, just new */
1936 extlsa
= (struct as_external_lsa
*)(new->data
);
1938 if (extlsa
->e
[0].fwd_addr
.s_addr
== INADDR_ANY
)
1939 extlsa
->e
[0].fwd_addr
= ospf_get_nssa_ip(
1940 area
); /* this NSSA area in ifp */
1942 if (extlsa
->e
[0].fwd_addr
.s_addr
== INADDR_ANY
) {
1943 if (IS_DEBUG_OSPF_NSSA
)
1945 "LSA[Type-7]: Could not build FWD-ADDR");
1946 ospf_lsa_discard(new);
1951 /* install also as Type-7 */
1952 ospf_lsa_install(ospf
, NULL
,
1953 new); /* Remove Old, Lock New = 2 */
1955 /* will send each copy, lock=2+n */
1956 ospf_flood_through_as(
1957 ospf
, NULL
, new); /* all attached NSSA's, no AS/STUBs */
1961 static struct ospf_lsa
*ospf_lsa_translated_nssa_new(struct ospf
*ospf
,
1962 struct ospf_lsa
*type7
)
1965 struct ospf_lsa
*new;
1966 struct as_external_lsa
*ext
, *extnew
;
1967 struct external_info ei
;
1969 ext
= (struct as_external_lsa
*)(type7
->data
);
1971 /* need external_info struct, fill in bare minimum */
1972 ei
.p
.family
= AF_INET
;
1973 ei
.p
.prefix
= type7
->data
->id
;
1974 ei
.p
.prefixlen
= ip_masklen(ext
->mask
);
1975 ei
.type
= ZEBRA_ROUTE_OSPF
;
1976 ei
.nexthop
= ext
->header
.adv_router
;
1977 ei
.route_map_set
.metric
= -1;
1978 ei
.route_map_set
.metric_type
= -1;
1979 ei
.metric
= DEFAULT_DEFAULT_METRIC
;
1980 ei
.max_metric
= OSPF_LS_INFINITY
;
1985 if ((new = ospf_external_lsa_new(ospf
, &ei
, &type7
->data
->id
))
1987 if (IS_DEBUG_OSPF_NSSA
)
1989 "%s: Could not originate Translated Type-5 for %pI4",
1990 __func__
, &ei
.p
.prefix
);
1994 extnew
= (struct as_external_lsa
*)(new->data
);
1996 /* copy over Type-7 data to new */
1997 extnew
->e
[0].tos
= ext
->e
[0].tos
;
1998 extnew
->e
[0].route_tag
= ext
->e
[0].route_tag
;
1999 if (type7
->area
->suppress_fa
) {
2000 extnew
->e
[0].fwd_addr
.s_addr
= 0;
2001 if (IS_DEBUG_OSPF_NSSA
)
2002 zlog_debug("%s: Suppress forwarding address for %pI4",
2003 __func__
, &ei
.p
.prefix
);
2005 extnew
->e
[0].fwd_addr
.s_addr
= ext
->e
[0].fwd_addr
.s_addr
;
2006 new->data
->ls_seqnum
= type7
->data
->ls_seqnum
;
2008 /* add translated flag, checksum and lock new lsa */
2009 SET_FLAG(new->flags
, OSPF_LSA_LOCAL_XLT
); /* Translated from 7 */
2010 new = ospf_lsa_lock(new);
2015 /* Originate Translated Type-5 for supplied Type-7 NSSA LSA */
2016 struct ospf_lsa
*ospf_translated_nssa_originate(struct ospf
*ospf
,
2017 struct ospf_lsa
*type7
,
2018 struct ospf_lsa
*type5
)
2020 struct ospf_lsa
*new, *translated_lsa
;
2021 struct as_external_lsa
*extnew
;
2023 if (ospf
->gr_info
.restart_in_progress
) {
2024 if (IS_DEBUG_OSPF(lsa
, LSA_GENERATE
))
2026 "LSA[Translated Type5]: Graceful Restart in progress, don't originate");
2030 /* we cant use ospf_external_lsa_originate() as we need to set
2031 * the OSPF_LSA_LOCAL_XLT flag, must originate by hand
2034 if ((translated_lsa
= ospf_lsa_translated_nssa_new(ospf
, type7
)) ==
2036 if (IS_DEBUG_OSPF_NSSA
)
2038 "%s: Could not translate Type-7, Id %pI4, to Type-5",
2039 __func__
, &type7
->data
->id
);
2043 extnew
= (struct as_external_lsa
*)translated_lsa
->data
;
2045 /* Update LSA sequence number from translated Type-5 LSA */
2047 translated_lsa
->data
->ls_seqnum
= lsa_seqnum_increment(type5
);
2049 if ((new = ospf_lsa_install(ospf
, NULL
, translated_lsa
)) == NULL
) {
2050 flog_warn(EC_OSPF_LSA_INSTALL_FAILURE
,
2051 "%s: Could not install LSA id %pI4", __func__
,
2053 ospf_lsa_free(translated_lsa
);
2057 if (IS_DEBUG_OSPF_NSSA
) {
2058 zlog_debug("%s: translated Type 7, installed", __func__
);
2059 ospf_lsa_header_dump(new->data
);
2060 zlog_debug(" Network mask: %d", ip_masklen(extnew
->mask
));
2061 zlog_debug(" Forward addr: %pI4",
2062 &extnew
->e
[0].fwd_addr
);
2065 ospf
->lsa_originate_count
++;
2066 ospf_flood_through_as(ospf
, NULL
, new);
2071 /* Refresh Translated from NSSA AS-external-LSA. */
2072 struct ospf_lsa
*ospf_translated_nssa_refresh(struct ospf
*ospf
,
2073 struct ospf_lsa
*type7
,
2074 struct ospf_lsa
*type5
)
2076 struct ospf_lsa
*new = NULL
, *translated_lsa
= NULL
;
2077 struct as_external_lsa
*extold
= NULL
;
2078 uint32_t ls_seqnum
= 0;
2080 /* Sanity checks. */
2081 assert(type7
|| type5
);
2082 if (!(type7
|| type5
))
2085 assert(type7
->data
);
2087 assert(type5
->data
);
2088 assert(ospf
->anyNSSA
);
2090 /* get required data according to what has been given */
2091 if (type7
&& type5
== NULL
) {
2092 /* find the translated Type-5 for this Type-7 */
2093 struct as_external_lsa
*ext
=
2094 (struct as_external_lsa
*)(type7
->data
);
2095 struct prefix_ipv4 p
= {
2096 .prefix
= type7
->data
->id
,
2097 .prefixlen
= ip_masklen(ext
->mask
),
2101 type5
= ospf_external_info_find_lsa(ospf
, &p
);
2102 } else if (type5
&& type7
== NULL
) {
2103 /* find the type-7 from which supplied type-5 was translated,
2104 * ie find first type-7 with same LSA Id.
2106 struct listnode
*ln
, *lnn
;
2107 struct route_node
*rn
;
2108 struct ospf_lsa
*lsa
;
2109 struct ospf_area
*area
;
2111 for (ALL_LIST_ELEMENTS(ospf
->areas
, ln
, lnn
, area
)) {
2112 if (area
->external_routing
!= OSPF_AREA_NSSA
&& !type7
)
2115 LSDB_LOOP (NSSA_LSDB(area
), rn
, lsa
) {
2116 if (lsa
->data
->id
.s_addr
2117 == type5
->data
->id
.s_addr
) {
2125 /* do we have type7? */
2127 if (IS_DEBUG_OSPF_NSSA
)
2128 zlog_debug("%s: no Type-7 found for Type-5 LSA Id %pI4",
2129 __func__
, &type5
->data
->id
);
2133 /* do we have valid translated type5? */
2134 if (type5
== NULL
|| !CHECK_FLAG(type5
->flags
, OSPF_LSA_LOCAL_XLT
)) {
2135 if (IS_DEBUG_OSPF_NSSA
)
2137 "%s: No translated Type-5 found for Type-7 with Id %pI4",
2138 __func__
, &type7
->data
->id
);
2142 extold
= (struct as_external_lsa
*)type5
->data
;
2143 if (type7
->area
->suppress_fa
== 1) {
2144 if (extold
->e
[0].fwd_addr
.s_addr
== 0)
2145 ls_seqnum
= ntohl(type5
->data
->ls_seqnum
);
2148 /* Delete LSA from neighbor retransmit-list. */
2149 ospf_ls_retransmit_delete_nbr_as(ospf
, type5
);
2151 /* create new translated LSA */
2152 if ((translated_lsa
= ospf_lsa_translated_nssa_new(ospf
, type7
)) ==
2154 if (IS_DEBUG_OSPF_NSSA
)
2156 "%s: Could not translate Type-7 for %pI4 to Type-5",
2157 __func__
, &type7
->data
->id
);
2161 if (type7
->area
->suppress_fa
== 1) {
2162 if (extold
->e
[0].fwd_addr
.s_addr
== 0)
2163 translated_lsa
->data
->ls_seqnum
= htonl(ls_seqnum
+ 1);
2166 if (!(new = ospf_lsa_install(ospf
, NULL
, translated_lsa
))) {
2167 flog_warn(EC_OSPF_LSA_INSTALL_FAILURE
,
2168 "%s: Could not install translated LSA, Id %pI4",
2169 __func__
, &type7
->data
->id
);
2170 ospf_lsa_free(translated_lsa
);
2174 /* Flood LSA through area. */
2175 ospf_flood_through_as(ospf
, NULL
, new);
2180 /* Originate an AS-external-LSA, install and flood. */
2181 struct ospf_lsa
*ospf_external_lsa_originate(struct ospf
*ospf
,
2182 struct external_info
*ei
)
2184 struct ospf_lsa
*new;
2186 if (ospf
->gr_info
.restart_in_progress
) {
2187 if (IS_DEBUG_OSPF(lsa
, LSA_GENERATE
))
2189 "LSA[Type5]: Graceful Restart in progress, don't originate");
2193 /* Added for NSSA project....
2195 External LSAs are originated in ASBRs as usual, but for NSSA
2197 there is the global Type-5 LSDB and a Type-7 LSDB installed for
2198 every area. The Type-7's are flooded to every IR and every ABR; We
2199 install the Type-5 LSDB so that the normal "refresh" code operates
2200 as usual, and flag them as not used during ASE calculations. The
2201 Type-7 LSDB is used for calculations. Each Type-7 has a Forwarding
2202 Address of non-zero.
2204 If an ABR is the elected NSSA translator, following SPF and during
2205 the ABR task it will translate all the scanned Type-7's, with P-bit
2206 ON and not-self generated, and translate to Type-5's throughout the
2209 A difference in operation depends whether this ASBR is an ABR
2210 or not. If not an ABR, the P-bit is ON, to indicate that any
2211 elected NSSA-ABR can perform its translation.
2213 If an ABR, the P-bit is OFF; No ABR will perform translation and
2214 this ASBR will flood the Type-5 LSA as usual.
2216 For the case where this ASBR is not an ABR, the ASE calculations
2217 are based on the Type-5 LSDB; The Type-7 LSDB exists just to
2218 demonstrate to the user that there are LSA's that belong to any
2221 Finally, it just so happens that when the ABR is translating every
2222 Type-7 into Type-5, it installs it into the Type-5 LSDB as an
2223 approved Type-5 (translated from Type-7); at the end of translation
2224 if any Translated Type-5's remain unapproved, then they must be
2225 flushed from the AS.
2229 if (ospf
->router_id
.s_addr
== INADDR_ANY
) {
2230 if (ei
&& IS_DEBUG_OSPF_EVENT
)
2232 "LSA[Type5:%pI4]: deferring AS-external-LSA origination, router ID is zero",
2237 /* Create new AS-external-LSA instance. */
2238 if ((new = ospf_external_lsa_new(ospf
, ei
, NULL
)) == NULL
) {
2239 if (ei
&& IS_DEBUG_OSPF_EVENT
)
2241 "LSA[Type5:%pI4]: Could not originate AS-external-LSA",
2246 /* Install newly created LSA into Type-5 LSDB, lock = 1. */
2247 ospf_lsa_install(ospf
, NULL
, new);
2249 /* Update LSA origination count. */
2250 ospf
->lsa_originate_count
++;
2252 /* Flooding new LSA. only to AS (non-NSSA/STUB) */
2253 ospf_flood_through_as(ospf
, NULL
, new);
2255 /* If there is any attached NSSA, do special handling */
2256 if (ospf
->anyNSSA
&&
2257 /* stay away from translated LSAs! */
2258 !(CHECK_FLAG(new->flags
, OSPF_LSA_LOCAL_XLT
)))
2259 ospf_install_flood_nssa(
2260 ospf
, new); /* Install/Flood Type-7 to all NSSAs */
2262 /* Debug logging. */
2263 if (IS_DEBUG_OSPF(lsa
, LSA_GENERATE
)) {
2264 zlog_debug("LSA[Type%d:%pI4]: Originate AS-external-LSA %p",
2265 new->data
->type
, &new->data
->id
,
2267 ospf_lsa_header_dump(new->data
);
2273 /* Originate an NSSA-LSA, install and flood. */
2274 struct ospf_lsa
*ospf_nssa_lsa_originate(struct ospf_area
*area
,
2275 struct external_info
*ei
)
2277 struct ospf
*ospf
= area
->ospf
;
2278 struct ospf_lsa
*new;
2280 if (ospf
->gr_info
.restart_in_progress
) {
2281 if (IS_DEBUG_OSPF(lsa
, LSA_GENERATE
))
2283 "LSA[Type7]: Graceful Restart in progress, don't originate");
2287 if (ospf
->router_id
.s_addr
== INADDR_ANY
) {
2288 if (IS_DEBUG_OSPF_EVENT
)
2290 "LSA[Type7:%pI4]: deferring NSSA-LSA origination, router ID is zero",
2295 /* Create new NSSA-LSA instance. */
2296 if ((new = ospf_external_lsa_new(ospf
, ei
, NULL
)) == NULL
) {
2297 if (IS_DEBUG_OSPF_EVENT
)
2299 "LSA[Type7:%pI4]: Could not originate NSSA-LSA",
2303 new->data
->type
= OSPF_AS_NSSA_LSA
;
2306 /* Install newly created LSA into Type-7 LSDB. */
2307 ospf_lsa_install(ospf
, NULL
, new);
2309 /* Update LSA origination count. */
2310 ospf
->lsa_originate_count
++;
2312 /* Flooding new LSA */
2313 ospf_flood_through_area(area
, NULL
, new);
2315 /* Debug logging. */
2316 if (IS_DEBUG_OSPF(lsa
, LSA_GENERATE
)) {
2317 zlog_debug("LSA[Type%d:%pI4]: Originate NSSA-LSA %p",
2318 new->data
->type
, &new->data
->id
, (void *)new);
2319 ospf_lsa_header_dump(new->data
);
2325 /* Refresh NSSA-LSA. */
2326 struct ospf_lsa
*ospf_nssa_lsa_refresh(struct ospf_area
*area
,
2327 struct ospf_lsa
*lsa
,
2328 struct external_info
*ei
)
2330 struct ospf
*ospf
= area
->ospf
;
2331 struct ospf_lsa
*new;
2333 /* Delete LSA from neighbor retransmit-list. */
2334 ospf_ls_retransmit_delete_nbr_as(ospf
, lsa
);
2336 /* Unregister AS-external-LSA from refresh-list. */
2337 ospf_refresher_unregister_lsa(ospf
, lsa
);
2339 /* Create new NSSA-LSA instance. */
2340 if ((new = ospf_external_lsa_new(ospf
, ei
, NULL
)) == NULL
) {
2341 if (IS_DEBUG_OSPF_EVENT
)
2343 "LSA[Type7:%pI4]: Could not originate NSSA-LSA",
2347 new->data
->type
= OSPF_AS_NSSA_LSA
;
2348 new->data
->ls_seqnum
= lsa_seqnum_increment(lsa
);
2351 /* Install newly created LSA into Type-7 LSDB. */
2352 ospf_lsa_install(ospf
, NULL
, new);
2354 /* Flooding new LSA */
2355 ospf_flood_through_area(area
, NULL
, new);
2357 /* Debug logging. */
2358 if (IS_DEBUG_OSPF(lsa
, LSA_GENERATE
)) {
2359 zlog_debug("LSA[Type%d:%pI4]: NSSA-LSA refresh",
2360 new->data
->type
, &new->data
->id
);
2361 ospf_lsa_header_dump(new->data
);
2367 static struct external_info
*ospf_default_external_info(struct ospf
*ospf
)
2370 struct prefix_ipv4 p
;
2371 struct external_info
*default_ei
;
2375 p
.prefix
.s_addr
= 0;
2378 default_ei
= ospf_external_info_lookup(ospf
, DEFAULT_ROUTE
, 0, &p
);
2382 /* First, lookup redistributed default route. */
2383 for (type
= 0; type
<= ZEBRA_ROUTE_MAX
; type
++) {
2384 struct list
*ext_list
;
2386 if (type
== ZEBRA_ROUTE_OSPF
)
2389 ext_list
= ospf
->external
[type
];
2393 ret
= ospf_external_default_routemap_apply_walk(ospf
, ext_list
,
2402 void ospf_external_lsa_rid_change(struct ospf
*ospf
)
2404 struct external_info
*ei
;
2405 struct ospf_external_aggr_rt
*aggr
;
2406 struct ospf_lsa
*lsa
= NULL
;
2410 for (type
= 0; type
< ZEBRA_ROUTE_MAX
; type
++) {
2411 struct route_node
*rn
;
2412 struct route_table
*rt
;
2413 struct list
*ext_list
;
2414 struct listnode
*node
;
2415 struct ospf_external
*ext
;
2417 ext_list
= ospf
->external
[type
];
2421 for (ALL_LIST_ELEMENTS_RO(ext_list
, node
, ext
)) {
2422 /* Originate As-external-LSA from all type of
2423 * distribute source.
2425 rt
= ext
->external_info
;
2429 for (rn
= route_top(rt
); rn
; rn
= route_next(rn
)) {
2435 if (is_default_prefix4(&ei
->p
))
2438 lsa
= ospf_external_info_find_lsa(ospf
, &ei
->p
);
2440 aggr
= ospf_external_aggr_match(ospf
, &ei
->p
);
2443 if (!ospf_redistribute_check(ospf
, ei
,
2447 if (IS_DEBUG_OSPF(lsa
, EXTNL_LSA_AGGR
))
2449 "Originate Summary LSA after reset/router-ID change");
2451 /* Here the LSA is originated as new */
2452 ospf_originate_summary_lsa(ospf
, aggr
,
2455 /* LSA needs to be refreshed even if
2456 * there is no change in the route
2457 * params if the LSA is in maxage.
2459 if (IS_LSA_MAXAGE(lsa
))
2460 force
= LSA_REFRESH_FORCE
;
2462 force
= LSA_REFRESH_IF_CHANGED
;
2464 ospf_external_lsa_refresh(ospf
, lsa
,
2467 if (!ospf_redistribute_check(ospf
, ei
,
2471 if (!ospf_external_lsa_originate(ospf
,
2474 EC_OSPF_LSA_INSTALL_FAILURE
,
2475 "LSA: AS-external-LSA was not originated.");
2481 ei
= ospf_default_external_info(ospf
);
2482 if (ei
&& !ospf_external_lsa_originate(ospf
, ei
)) {
2483 flog_warn(EC_OSPF_LSA_INSTALL_FAILURE
,
2484 "LSA: AS-external-LSA for default route was not originated.");
2488 /* Flush any NSSA LSAs for given prefix */
2489 void ospf_nssa_lsa_flush(struct ospf
*ospf
, struct prefix_ipv4
*p
)
2491 struct listnode
*node
, *nnode
;
2492 struct ospf_lsa
*lsa
= NULL
;
2493 struct ospf_area
*area
;
2495 for (ALL_LIST_ELEMENTS(ospf
->areas
, node
, nnode
, area
)) {
2496 if (area
->external_routing
== OSPF_AREA_NSSA
) {
2497 lsa
= ospf_lsa_lookup(ospf
, area
, OSPF_AS_NSSA_LSA
,
2498 p
->prefix
, ospf
->router_id
);
2500 if (IS_DEBUG_OSPF(lsa
, LSA_FLOODING
))
2502 "LSA: There is no such AS-NSSA-LSA %pFX in LSDB",
2506 ospf_ls_retransmit_delete_nbr_area(area
, lsa
);
2507 if (!IS_LSA_MAXAGE(lsa
)) {
2508 ospf_refresher_unregister_lsa(ospf
, lsa
);
2509 ospf_lsa_flush_area(lsa
, area
);
2515 /* Flush an AS-external-LSA from LSDB and routing domain. */
2516 void ospf_external_lsa_flush(struct ospf
*ospf
, uint8_t type
,
2517 struct prefix_ipv4
*p
,
2518 ifindex_t ifindex
/*, struct in_addr nexthop */)
2520 struct ospf_lsa
*lsa
;
2522 if (IS_DEBUG_OSPF(lsa
, LSA_FLOODING
))
2523 zlog_debug("LSA: Flushing AS-external-LSA %pFX", p
);
2525 /* First lookup LSA from LSDB. */
2526 if (!(lsa
= ospf_external_info_find_lsa(ospf
, p
))) {
2527 if (IS_DEBUG_OSPF(lsa
, LSA_FLOODING
))
2529 "LSA: There is no such AS-external-LSA %pFX in LSDB",
2534 /* If LSA is selforiginated, not a translated LSA, and there is
2535 * NSSA area, flush Type-7 LSA's at first.
2537 if (IS_LSA_SELF(lsa
) && (ospf
->anyNSSA
)
2538 && !(CHECK_FLAG(lsa
->flags
, OSPF_LSA_LOCAL_XLT
)))
2539 ospf_nssa_lsa_flush(ospf
, p
);
2541 if (!IS_LSA_MAXAGE(lsa
)) {
2542 /* Sweep LSA from Link State Retransmit List. */
2543 ospf_ls_retransmit_delete_nbr_as(ospf
, lsa
);
2545 /* Unregister LSA from Refresh queue. */
2546 ospf_refresher_unregister_lsa(ospf
, lsa
);
2548 /* Flush AS-external-LSA through AS. */
2549 ospf_lsa_flush_as(ospf
, lsa
);
2552 if (IS_DEBUG_OSPF(lsa
, LSA_FLOODING
))
2553 zlog_debug("%s: stop", __func__
);
2556 void ospf_external_lsa_refresh_default(struct ospf
*ospf
)
2558 struct prefix_ipv4 p
;
2559 struct external_info
*ei
;
2560 struct ospf_lsa
*lsa
;
2564 p
.prefix
.s_addr
= INADDR_ANY
;
2566 ei
= ospf_default_external_info(ospf
);
2567 lsa
= ospf_external_info_find_lsa(ospf
, &p
);
2570 if (IS_DEBUG_OSPF_EVENT
)
2571 zlog_debug("LSA[Type5:0.0.0.0]: Refresh AS-external-LSA %p",
2573 ospf_external_lsa_refresh(ospf
, lsa
, ei
, LSA_REFRESH_FORCE
,
2575 } else if (ei
&& !lsa
) {
2576 if (IS_DEBUG_OSPF_EVENT
)
2578 "LSA[Type5:0.0.0.0]: Originate AS-external-LSA");
2579 ospf_external_lsa_originate(ospf
, ei
);
2581 if (IS_DEBUG_OSPF_EVENT
)
2582 zlog_debug("LSA[Type5:0.0.0.0]: Flush AS-external-LSA");
2583 ospf_external_lsa_flush(ospf
, DEFAULT_ROUTE
, &p
, 0);
2587 void ospf_external_lsa_refresh_type(struct ospf
*ospf
, uint8_t type
,
2588 unsigned short instance
, int force
)
2590 struct route_node
*rn
;
2591 struct external_info
*ei
;
2592 struct ospf_external
*ext
;
2594 if (type
== DEFAULT_ROUTE
)
2597 ext
= ospf_external_lookup(ospf
, type
, instance
);
2599 if (ext
&& EXTERNAL_INFO(ext
)) {
2600 /* Refresh each redistributed AS-external-LSAs. */
2601 for (rn
= route_top(EXTERNAL_INFO(ext
)); rn
;
2602 rn
= route_next(rn
)) {
2605 if (!is_default_prefix4(&ei
->p
)) {
2606 struct ospf_lsa
*lsa
;
2607 struct ospf_external_aggr_rt
*aggr
;
2609 aggr
= ospf_external_aggr_match(ospf
,
2611 lsa
= ospf_external_info_find_lsa(
2614 /* Check the AS-external-LSA
2615 * should be originated.
2617 if (!ospf_redistribute_check(
2620 ospf_unlink_ei_from_aggr(
2629 "%s: Send Aggreate LSA (%pFX)",
2633 ospf_originate_summary_lsa(
2638 if (IS_LSA_MAXAGE(lsa
))
2639 force
= LSA_REFRESH_FORCE
;
2641 ospf_external_lsa_refresh(
2642 ospf
, lsa
, ei
, force
,
2645 if (!ospf_redistribute_check(
2648 ospf_external_lsa_originate(
2657 /* Refresh AS-external-LSA. */
2658 struct ospf_lsa
*ospf_external_lsa_refresh(struct ospf
*ospf
,
2659 struct ospf_lsa
*lsa
,
2660 struct external_info
*ei
, int force
,
2663 struct ospf_lsa
*new;
2666 /* Check the AS-external-LSA should be originated. */
2668 if (!ospf_redistribute_check(ospf
, ei
, &changed
)) {
2669 if (IS_DEBUG_OSPF(lsa
, LSA_GENERATE
))
2671 "LSA[Type%d:%pI4] Could not be refreshed, redist check fail",
2675 ospf_external_lsa_flush(ospf
, ei
->type
, &ei
->p
,
2676 ei
->ifindex
/*, ei->nexthop */);
2680 if (!changed
&& !force
) {
2681 if (IS_DEBUG_OSPF(lsa
, LSA_GENERATE
))
2683 "LSA[Type%d:%pI4]: Not refreshed, not changed/forced",
2684 lsa
->data
->type
, &lsa
->data
->id
);
2688 /* Delete LSA from neighbor retransmit-list. */
2689 ospf_ls_retransmit_delete_nbr_as(ospf
, lsa
);
2691 /* Unregister AS-external-LSA from refresh-list. */
2692 ospf_refresher_unregister_lsa(ospf
, lsa
);
2694 new = ospf_external_lsa_new(ospf
, ei
, &lsa
->data
->id
);
2697 if (IS_DEBUG_OSPF(lsa
, LSA_GENERATE
))
2698 zlog_debug("LSA[Type%d:%pI4]: Could not be refreshed",
2699 lsa
->data
->type
, &lsa
->data
->id
);
2703 new->data
->ls_seqnum
= lsa_seqnum_increment(lsa
);
2705 ospf_lsa_install(ospf
, NULL
, new); /* As type-5. */
2707 /* Flood LSA through AS. */
2708 ospf_flood_through_as(ospf
, NULL
, new);
2710 /* If any attached NSSA, install as Type-7, flood to all NSSA Areas */
2711 if (ospf
->anyNSSA
&& !(CHECK_FLAG(new->flags
, OSPF_LSA_LOCAL_XLT
)))
2712 ospf_install_flood_nssa(ospf
,
2713 new); /* Install/Flood per new rules */
2715 /* Register self-originated LSA to refresh queue.
2716 * Translated LSAs should not be registered, but refreshed upon
2717 * refresh of the Type-7
2719 if (!CHECK_FLAG(new->flags
, OSPF_LSA_LOCAL_XLT
))
2720 ospf_refresher_register_lsa(ospf
, new);
2722 /* Debug logging. */
2723 if (IS_DEBUG_OSPF(lsa
, LSA_GENERATE
)) {
2724 zlog_debug("LSA[Type%d:%pI4]: AS-external-LSA refresh",
2725 new->data
->type
, &new->data
->id
);
2726 ospf_lsa_header_dump(new->data
);
2733 /* LSA installation functions. */
2735 /* Install router-LSA to an area. */
2736 static struct ospf_lsa
*
2737 ospf_router_lsa_install(struct ospf
*ospf
, struct ospf_lsa
*new, int rt_recalc
)
2739 struct ospf_area
*area
= new->area
;
2741 /* RFC 2328 Section 13.2 Router-LSAs and network-LSAs
2742 The entire routing table must be recalculated, starting with
2743 the shortest path calculations for each area (not just the
2744 area whose link-state database has changed).
2747 if (IS_LSA_SELF(new)) {
2749 /* Only install LSA if it is originated/refreshed by us.
2750 * If LSA was received by flooding, the RECEIVED flag is set so
2752 * not link the LSA */
2753 if (CHECK_FLAG(new->flags
, OSPF_LSA_RECEIVED
))
2754 return new; /* ignore stale LSA */
2756 /* Set self-originated router-LSA. */
2757 ospf_lsa_unlock(&area
->router_lsa_self
);
2758 area
->router_lsa_self
= ospf_lsa_lock(new);
2760 ospf_refresher_register_lsa(ospf
, new);
2763 ospf_spf_calculate_schedule(ospf
, SPF_FLAG_ROUTER_LSA_INSTALL
);
2767 /* Install network-LSA to an area. */
2768 static struct ospf_lsa
*ospf_network_lsa_install(struct ospf
*ospf
,
2769 struct ospf_interface
*oi
,
2770 struct ospf_lsa
*new,
2774 /* RFC 2328 Section 13.2 Router-LSAs and network-LSAs
2775 The entire routing table must be recalculated, starting with
2776 the shortest path calculations for each area (not just the
2777 area whose link-state database has changed).
2779 if (IS_LSA_SELF(new)) {
2780 /* We supposed that when LSA is originated by us, we pass the
2782 for which it was originated. If LSA was received by flooding,
2783 the RECEIVED flag is set, so we do not link the LSA to the
2785 if (CHECK_FLAG(new->flags
, OSPF_LSA_RECEIVED
))
2786 return new; /* ignore stale LSA */
2788 ospf_lsa_unlock(&oi
->network_lsa_self
);
2789 oi
->network_lsa_self
= ospf_lsa_lock(new);
2790 ospf_refresher_register_lsa(ospf
, new);
2793 ospf_spf_calculate_schedule(ospf
, SPF_FLAG_NETWORK_LSA_INSTALL
);
2798 /* Install summary-LSA to an area. */
2799 static struct ospf_lsa
*
2800 ospf_summary_lsa_install(struct ospf
*ospf
, struct ospf_lsa
*new, int rt_recalc
)
2802 if (rt_recalc
&& !IS_LSA_SELF(new)) {
2803 /* RFC 2328 Section 13.2 Summary-LSAs
2804 The best route to the destination described by the summary-
2805 LSA must be recalculated (see Section 16.5). If this
2806 destination is an AS boundary router, it may also be
2807 necessary to re-examine all the AS-external-LSAs.
2810 ospf_spf_calculate_schedule(ospf
, SPF_FLAG_SUMMARY_LSA_INSTALL
);
2813 if (IS_LSA_SELF(new))
2814 ospf_refresher_register_lsa(ospf
, new);
2819 /* Install ASBR-summary-LSA to an area. */
2820 static struct ospf_lsa
*ospf_summary_asbr_lsa_install(struct ospf
*ospf
,
2821 struct ospf_lsa
*new,
2824 if (rt_recalc
&& !IS_LSA_SELF(new)) {
2825 /* RFC 2328 Section 13.2 Summary-LSAs
2826 The best route to the destination described by the summary-
2827 LSA must be recalculated (see Section 16.5). If this
2828 destination is an AS boundary router, it may also be
2829 necessary to re-examine all the AS-external-LSAs.
2831 ospf_spf_calculate_schedule(ospf
,
2832 SPF_FLAG_ASBR_SUMMARY_LSA_INSTALL
);
2835 /* register LSA to refresh-list. */
2836 if (IS_LSA_SELF(new))
2837 ospf_refresher_register_lsa(ospf
, new);
2842 /* Install AS-external-LSA. */
2843 static struct ospf_lsa
*ospf_external_lsa_install(struct ospf
*ospf
,
2844 struct ospf_lsa
*new,
2847 ospf_ase_register_external_lsa(new, ospf
);
2848 /* If LSA is not self-originated, calculate an external route. */
2850 /* RFC 2328 Section 13.2 AS-external-LSAs
2851 The best route to the destination described by the AS-
2852 external-LSA must be recalculated (see Section 16.6).
2855 if (!IS_LSA_SELF(new))
2856 ospf_ase_incremental_update(ospf
, new);
2859 if (new->data
->type
== OSPF_AS_NSSA_LSA
) {
2860 /* There is no point to register selforiginate Type-7 LSA for
2861 * refreshing. We rely on refreshing Type-5 LSA's
2863 if (IS_LSA_SELF(new))
2866 /* Try refresh type-5 translated LSA for this LSA, if
2868 * New translations will be taken care of by the
2871 ospf_translated_nssa_refresh(ospf
, new, NULL
);
2872 ospf_schedule_abr_task(ospf
);
2876 /* Register self-originated LSA to refresh queue.
2877 * Leave Translated LSAs alone if NSSA is enabled
2879 if (IS_LSA_SELF(new) && !CHECK_FLAG(new->flags
, OSPF_LSA_LOCAL_XLT
))
2880 ospf_refresher_register_lsa(ospf
, new);
2885 void ospf_discard_from_db(struct ospf
*ospf
, struct ospf_lsdb
*lsdb
,
2886 struct ospf_lsa
*lsa
)
2888 struct ospf_lsa
*old
;
2893 old
= ospf_lsdb_lookup(lsdb
, lsa
);
2898 if (old
->refresh_list
>= 0)
2899 ospf_refresher_unregister_lsa(ospf
, old
);
2901 switch (old
->data
->type
) {
2902 case OSPF_AS_EXTERNAL_LSA
:
2903 ospf_ase_unregister_external_lsa(old
, ospf
);
2904 ospf_ls_retransmit_delete_nbr_as(ospf
, old
);
2906 case OSPF_OPAQUE_AS_LSA
:
2907 ospf_ls_retransmit_delete_nbr_as(ospf
, old
);
2909 case OSPF_AS_NSSA_LSA
:
2910 ospf_ls_retransmit_delete_nbr_area(old
->area
, old
);
2911 ospf_ase_unregister_external_lsa(old
, ospf
);
2914 ospf_ls_retransmit_delete_nbr_area(old
->area
, old
);
2918 ospf_lsa_maxage_delete(ospf
, old
);
2919 ospf_lsa_discard(old
);
2922 struct ospf_lsa
*ospf_lsa_install(struct ospf
*ospf
, struct ospf_interface
*oi
,
2923 struct ospf_lsa
*lsa
)
2925 struct ospf_lsa
*new = NULL
;
2926 struct ospf_lsa
*old
= NULL
;
2927 struct ospf_lsdb
*lsdb
= NULL
;
2931 switch (lsa
->data
->type
) {
2933 case OSPF_AS_NSSA_LSA
:
2935 lsdb
= lsa
->area
->lsdb
;
2939 case OSPF_AS_EXTERNAL_LSA
:
2940 case OSPF_OPAQUE_AS_LSA
:
2945 lsdb
= lsa
->area
->lsdb
;
2951 /* RFC 2328 13.2. Installing LSAs in the database
2953 Installing a new LSA in the database, either as the result of
2954 flooding or a newly self-originated LSA, may cause the OSPF
2955 routing table structure to be recalculated. The contents of the
2956 new LSA should be compared to the old instance, if present. If
2957 there is no difference, there is no need to recalculate the
2958 routing table. When comparing an LSA to its previous instance,
2959 the following are all considered to be differences in contents:
2961 o The LSA's Options field has changed.
2963 o One of the LSA instances has LS age set to MaxAge, and
2966 o The length field in the LSA header has changed.
2968 o The body of the LSA (i.e., anything outside the 20-byte
2969 LSA header) has changed. Note that this excludes changes
2970 in LS Sequence Number and LS Checksum.
2973 /* Look up old LSA and determine if any SPF calculation or incremental
2975 old
= ospf_lsdb_lookup(lsdb
, lsa
);
2977 /* Do comparison and record if recalc needed. */
2979 if (old
== NULL
|| ospf_lsa_different(old
, lsa
, false)) {
2980 /* Ref rfc3623 section 3.2.3
2981 * Installing new lsa or change in the existing LSA
2982 * or flushing existing LSA leads to topo change
2983 * and trigger SPF caculation.
2984 * So, router should be aborted from HELPER role
2985 * if it is detected as TOPO change.
2987 if (ospf
->active_restarter_cnt
&&
2988 CHECK_LSA_TYPE_1_TO_5_OR_7(lsa
->data
->type
)) {
2989 if (old
== NULL
|| ospf_lsa_different(old
, lsa
, true))
2990 ospf_helper_handle_topo_chg(ospf
, lsa
);
2997 Sequence number check (Section 14.1 of rfc 2328)
2998 "Premature aging is used when it is time for a self-originated
2999 LSA's sequence number field to wrap. At this point, the current
3000 LSA instance (having LS sequence number MaxSequenceNumber) must
3001 be prematurely aged and flushed from the routing domain before a
3002 new instance with sequence number equal to InitialSequenceNumber
3003 can be originated. "
3006 if (ntohl(lsa
->data
->ls_seqnum
) - 1 == OSPF_MAX_SEQUENCE_NUMBER
) {
3007 if (ospf_lsa_is_self_originated(ospf
, lsa
)) {
3008 lsa
->data
->ls_seqnum
= htonl(OSPF_MAX_SEQUENCE_NUMBER
);
3010 if (!IS_LSA_MAXAGE(lsa
))
3011 lsa
->flags
|= OSPF_LSA_PREMATURE_AGE
;
3012 lsa
->data
->ls_age
= htons(OSPF_LSA_MAXAGE
);
3014 if (IS_DEBUG_OSPF(lsa
, LSA_REFRESH
)) {
3016 "%s() Premature Aging lsa %p, seqnum 0x%x",
3018 ntohl(lsa
->data
->ls_seqnum
));
3019 ospf_lsa_header_dump(lsa
->data
);
3022 if (IS_DEBUG_OSPF(lsa
, LSA_GENERATE
)) {
3024 "%s() got an lsa with seq 0x80000000 that was not self originated. Ignoring",
3026 ospf_lsa_header_dump(lsa
->data
);
3032 /* discard old LSA from LSDB */
3034 ospf_discard_from_db(ospf
, lsdb
, lsa
);
3036 /* Calculate Checksum if self-originated?. */
3037 if (IS_LSA_SELF(lsa
))
3038 ospf_lsa_checksum(lsa
->data
);
3040 /* Insert LSA to LSDB. */
3041 ospf_lsdb_add(lsdb
, lsa
);
3044 /* Do LSA specific installation process. */
3045 switch (lsa
->data
->type
) {
3046 case OSPF_ROUTER_LSA
:
3047 new = ospf_router_lsa_install(ospf
, lsa
, rt_recalc
);
3049 case OSPF_NETWORK_LSA
:
3051 new = ospf_network_lsa_install(ospf
, oi
, lsa
, rt_recalc
);
3053 case OSPF_SUMMARY_LSA
:
3054 new = ospf_summary_lsa_install(ospf
, lsa
, rt_recalc
);
3056 case OSPF_ASBR_SUMMARY_LSA
:
3057 new = ospf_summary_asbr_lsa_install(ospf
, lsa
, rt_recalc
);
3059 case OSPF_AS_EXTERNAL_LSA
:
3060 new = ospf_external_lsa_install(ospf
, lsa
, rt_recalc
);
3062 case OSPF_OPAQUE_LINK_LSA
:
3063 if (IS_LSA_SELF(lsa
))
3064 lsa
->oi
= oi
; /* Specify outgoing ospf-interface for
3067 /* Incoming "oi" for this LSA has set at LSUpd
3071 case OSPF_OPAQUE_AREA_LSA
:
3072 case OSPF_OPAQUE_AS_LSA
:
3073 new = ospf_opaque_lsa_install(lsa
, rt_recalc
);
3075 case OSPF_AS_NSSA_LSA
:
3076 new = ospf_external_lsa_install(ospf
, lsa
, rt_recalc
);
3077 default: /* type-6,8,9....nothing special */
3082 return new; /* Installation failed, cannot proceed further --
3086 if (IS_DEBUG_OSPF(lsa
, LSA_INSTALL
)) {
3087 switch (lsa
->data
->type
) {
3088 case OSPF_AS_EXTERNAL_LSA
:
3089 case OSPF_OPAQUE_AS_LSA
:
3090 case OSPF_AS_NSSA_LSA
:
3091 zlog_debug("LSA[%s]: Install %s", dump_lsa_key(new),
3092 lookup_msg(ospf_lsa_type_msg
,
3093 new->data
->type
, NULL
));
3096 zlog_debug("LSA[%s]: Install %s to Area %pI4",
3098 lookup_msg(ospf_lsa_type_msg
,
3099 new->data
->type
, NULL
),
3100 &new->area
->area_id
);
3106 If received LSA' ls_age is MaxAge, or lsa is being prematurely aged
3107 (it's getting flushed out of the area), set LSA on MaxAge LSA list.
3109 if (IS_LSA_MAXAGE(new)) {
3110 if (IS_DEBUG_OSPF(lsa
, LSA_INSTALL
))
3111 zlog_debug("LSA[%s]: Install LSA %p, MaxAge",
3112 dump_lsa_key(new), lsa
);
3113 ospf_lsa_maxage(ospf
, lsa
);
3120 int ospf_check_nbr_status(struct ospf
*ospf
)
3122 struct listnode
*node
, *nnode
;
3123 struct ospf_interface
*oi
;
3125 for (ALL_LIST_ELEMENTS(ospf
->oiflist
, node
, nnode
, oi
)) {
3126 struct route_node
*rn
;
3127 struct ospf_neighbor
*nbr
;
3129 if (ospf_if_is_enable(oi
))
3130 for (rn
= route_top(oi
->nbrs
); rn
; rn
= route_next(rn
))
3131 if ((nbr
= rn
->info
) != NULL
)
3132 if (nbr
->state
== NSM_Exchange
3133 || nbr
->state
== NSM_Loading
) {
3134 route_unlock_node(rn
);
3143 void ospf_maxage_lsa_remover(struct event
*thread
)
3145 struct ospf
*ospf
= EVENT_ARG(thread
);
3146 struct ospf_lsa
*lsa
, *old
;
3147 struct route_node
*rn
;
3150 ospf
->t_maxage
= NULL
;
3152 if (IS_DEBUG_OSPF(lsa
, LSA_FLOODING
))
3153 zlog_debug("LSA[MaxAge]: remover Start");
3155 reschedule
= !ospf_check_nbr_status(ospf
);
3158 for (rn
= route_top(ospf
->maxage_lsa
); rn
;
3159 rn
= route_next(rn
)) {
3160 if ((lsa
= rn
->info
) == NULL
) {
3164 /* There is at least one neighbor from which we still
3166 * for that LSA, so we are not allowed to remove it from
3168 * as per RFC 2328 section 14 para 4 a) */
3169 if (lsa
->retransmit_counter
> 0) {
3174 /* TODO: maybe convert this function to a work-queue */
3175 if (event_should_yield(thread
)) {
3176 OSPF_TIMER_ON(ospf
->t_maxage
,
3177 ospf_maxage_lsa_remover
, 0);
3179 rn
); /* route_top/route_next */
3183 /* Remove LSA from the LSDB */
3184 if (IS_LSA_SELF(lsa
))
3185 if (IS_DEBUG_OSPF(lsa
, LSA_FLOODING
))
3187 "LSA[Type%d:%pI4]: LSA 0x%lx is self-originated: ",
3190 (unsigned long)lsa
);
3192 if (IS_DEBUG_OSPF(lsa
, LSA_FLOODING
))
3194 "LSA[%s]: MaxAge LSA removed from list",
3197 if (CHECK_FLAG(lsa
->flags
, OSPF_LSA_PREMATURE_AGE
)) {
3198 if (IS_DEBUG_OSPF(lsa
, LSA_FLOODING
))
3200 "originating new lsa for lsa %p",
3202 ospf_lsa_refresh(ospf
, lsa
);
3205 /* Remove from lsdb. */
3207 old
= ospf_lsdb_lookup(lsa
->lsdb
, lsa
);
3208 /* The max age LSA here must be the same
3209 * as the LSA in LSDB
3212 flog_err(EC_OSPF_LSA_MISSING
,
3213 "%s: LSA[%s]: LSA not in LSDB",
3214 __func__
, dump_lsa_key(lsa
));
3218 ospf_discard_from_db(ospf
, lsa
->lsdb
, lsa
);
3219 ospf_lsdb_delete(lsa
->lsdb
, lsa
);
3221 if (IS_DEBUG_OSPF(lsa
, LSA_FLOODING
))
3223 "%s: LSA[%s]: No associated LSDB!",
3224 __func__
, dump_lsa_key(lsa
));
3228 /* A MaxAge LSA must be removed immediately from the router's link
3229 state database as soon as both a) it is no longer contained on any
3230 neighbor Link state retransmission lists and b) none of the
3232 neighbors are in states Exchange or Loading. */
3234 OSPF_TIMER_ON(ospf
->t_maxage
, ospf_maxage_lsa_remover
,
3235 ospf
->maxage_delay
);
3238 /* This function checks whether an LSA with initial sequence number should be
3239 * originated after a wrap in sequence number
3241 void ospf_check_and_gen_init_seq_lsa(struct ospf_interface
*oi
,
3242 struct ospf_lsa
*recv_lsa
)
3244 struct ospf_lsa
*lsa
= NULL
;
3245 struct ospf
*ospf
= oi
->ospf
;
3247 lsa
= ospf_lsa_lookup_by_header(oi
->area
, recv_lsa
->data
);
3249 if ((lsa
== NULL
) || (!CHECK_FLAG(lsa
->flags
, OSPF_LSA_PREMATURE_AGE
))
3250 || (lsa
->retransmit_counter
!= 0)) {
3251 if (IS_DEBUG_OSPF(lsa
, LSA
))
3253 "Do not generate LSA with initial seqence number.");
3257 ospf_lsa_maxage_delete(ospf
, lsa
);
3259 lsa
->data
->ls_seqnum
= lsa_seqnum_increment(lsa
);
3261 ospf_lsa_refresh(ospf
, lsa
);
3264 void ospf_lsa_maxage_delete(struct ospf
*ospf
, struct ospf_lsa
*lsa
)
3266 struct route_node
*rn
;
3267 struct prefix lsa_prefix
;
3269 memset(&lsa_prefix
, 0, sizeof(lsa_prefix
));
3270 lsa_prefix
.family
= AF_UNSPEC
;
3271 lsa_prefix
.prefixlen
= sizeof(lsa_prefix
.u
.ptr
) * CHAR_BIT
;
3272 lsa_prefix
.u
.ptr
= (uintptr_t)lsa
;
3274 if ((rn
= route_node_lookup(ospf
->maxage_lsa
, &lsa_prefix
))) {
3275 if (rn
->info
== lsa
) {
3276 UNSET_FLAG(lsa
->flags
, OSPF_LSA_IN_MAXAGE
);
3277 ospf_lsa_unlock(&lsa
); /* maxage_lsa */
3280 rn
); /* unlock node because lsa is deleted */
3282 route_unlock_node(rn
); /* route_node_lookup */
3284 if (IS_DEBUG_OSPF_EVENT
)
3285 zlog_debug("%s: lsa %s is not found in maxage db.",
3286 __func__
, dump_lsa_key(lsa
));
3290 /* Add LSA onto the MaxAge list, and schedule for removal.
3291 * This does *not* lead to the LSA being flooded, that must be taken
3292 * care of elsewhere, see, e.g., ospf_lsa_flush* (which are callers of this
3295 void ospf_lsa_maxage(struct ospf
*ospf
, struct ospf_lsa
*lsa
)
3297 struct prefix lsa_prefix
;
3298 struct route_node
*rn
;
3300 /* When we saw a MaxAge LSA flooded to us, we put it on the list
3301 and schedule the MaxAge LSA remover. */
3302 if (CHECK_FLAG(lsa
->flags
, OSPF_LSA_IN_MAXAGE
)) {
3303 if (IS_DEBUG_OSPF(lsa
, LSA_FLOODING
))
3305 "LSA[%s]: %p already exists on MaxAge LSA list",
3306 dump_lsa_key(lsa
), lsa
);
3310 memset(&lsa_prefix
, 0, sizeof(lsa_prefix
));
3311 lsa_prefix
.family
= AF_UNSPEC
;
3312 lsa_prefix
.prefixlen
= sizeof(lsa_prefix
.u
.ptr
) * CHAR_BIT
;
3313 lsa_prefix
.u
.ptr
= (uintptr_t)lsa
;
3315 rn
= route_node_get(ospf
->maxage_lsa
, &lsa_prefix
);
3316 if (rn
->info
!= NULL
) {
3317 if (IS_DEBUG_OSPF(lsa
, LSA_FLOODING
))
3319 "LSA[%s]: found LSA (%p) in table for LSA %p %d",
3320 dump_lsa_key(lsa
), rn
->info
,
3321 (void *)lsa
, lsa_prefix
.prefixlen
);
3322 route_unlock_node(rn
);
3324 rn
->info
= ospf_lsa_lock(lsa
);
3325 SET_FLAG(lsa
->flags
, OSPF_LSA_IN_MAXAGE
);
3328 if (IS_DEBUG_OSPF(lsa
, LSA_FLOODING
))
3329 zlog_debug("LSA[%s]: MaxAge LSA remover scheduled.",
3332 OSPF_TIMER_ON(ospf
->t_maxage
, ospf_maxage_lsa_remover
,
3333 ospf
->maxage_delay
);
3336 static int ospf_lsa_maxage_walker_remover(struct ospf
*ospf
,
3337 struct ospf_lsa
*lsa
)
3339 /* Stay away from any Local Translated Type-7 LSAs */
3340 if (CHECK_FLAG(lsa
->flags
, OSPF_LSA_LOCAL_XLT
))
3343 if (IS_LSA_MAXAGE(lsa
))
3344 /* Self-originated LSAs should NOT time-out instead,
3345 they're flushed and submitted to the max_age list explicitly.
3347 if (!ospf_lsa_is_self_originated(ospf
, lsa
)) {
3348 if (IS_DEBUG_OSPF(lsa
, LSA_FLOODING
))
3349 zlog_debug("LSA[%s]: is MaxAge",
3352 switch (lsa
->data
->type
) {
3353 case OSPF_OPAQUE_LINK_LSA
:
3354 case OSPF_OPAQUE_AREA_LSA
:
3355 case OSPF_OPAQUE_AS_LSA
:
3357 * As a general rule, whenever network topology
3359 * (due to an LSA removal in this case), routing
3361 * should be triggered. However, this is not
3363 * LSAs. Even if an opaque LSA instance is going
3365 * from the routing domain, it does not mean a
3367 * topology, and thus, routing recalculation is
3371 case OSPF_AS_EXTERNAL_LSA
:
3372 case OSPF_AS_NSSA_LSA
:
3373 ospf_ase_incremental_update(ospf
, lsa
);
3376 ospf_spf_calculate_schedule(ospf
,
3380 ospf_lsa_maxage(ospf
, lsa
);
3383 if (IS_LSA_MAXAGE(lsa
) && !ospf_lsa_is_self_originated(ospf
, lsa
))
3384 if (LS_AGE(lsa
) > OSPF_LSA_MAXAGE
+ 30)
3385 printf("Eek! Shouldn't happen!\n");
3390 /* Periodical check of MaxAge LSA. */
3391 void ospf_lsa_maxage_walker(struct event
*thread
)
3393 struct ospf
*ospf
= EVENT_ARG(thread
);
3394 struct route_node
*rn
;
3395 struct ospf_lsa
*lsa
;
3396 struct ospf_area
*area
;
3397 struct listnode
*node
, *nnode
;
3399 ospf
->t_maxage_walker
= NULL
;
3401 for (ALL_LIST_ELEMENTS(ospf
->areas
, node
, nnode
, area
)) {
3402 LSDB_LOOP (ROUTER_LSDB(area
), rn
, lsa
)
3403 ospf_lsa_maxage_walker_remover(ospf
, lsa
);
3404 LSDB_LOOP (NETWORK_LSDB(area
), rn
, lsa
)
3405 ospf_lsa_maxage_walker_remover(ospf
, lsa
);
3406 LSDB_LOOP (SUMMARY_LSDB(area
), rn
, lsa
)
3407 ospf_lsa_maxage_walker_remover(ospf
, lsa
);
3408 LSDB_LOOP (ASBR_SUMMARY_LSDB(area
), rn
, lsa
)
3409 ospf_lsa_maxage_walker_remover(ospf
, lsa
);
3410 LSDB_LOOP (OPAQUE_AREA_LSDB(area
), rn
, lsa
)
3411 ospf_lsa_maxage_walker_remover(ospf
, lsa
);
3412 LSDB_LOOP (OPAQUE_LINK_LSDB(area
), rn
, lsa
)
3413 ospf_lsa_maxage_walker_remover(ospf
, lsa
);
3414 LSDB_LOOP (NSSA_LSDB(area
), rn
, lsa
)
3415 ospf_lsa_maxage_walker_remover(ospf
, lsa
);
3418 /* for AS-external-LSAs. */
3420 LSDB_LOOP (EXTERNAL_LSDB(ospf
), rn
, lsa
)
3421 ospf_lsa_maxage_walker_remover(ospf
, lsa
);
3422 LSDB_LOOP (OPAQUE_AS_LSDB(ospf
), rn
, lsa
)
3423 ospf_lsa_maxage_walker_remover(ospf
, lsa
);
3426 OSPF_TIMER_ON(ospf
->t_maxage_walker
, ospf_lsa_maxage_walker
,
3427 OSPF_LSA_MAXAGE_CHECK_INTERVAL
);
3430 struct ospf_lsa
*ospf_lsa_lookup_by_prefix(struct ospf_lsdb
*lsdb
, uint8_t type
,
3431 struct prefix_ipv4
*p
,
3432 struct in_addr router_id
)
3434 struct ospf_lsa
*lsa
;
3435 struct in_addr mask
, id
;
3436 struct lsa_header_mask
{
3437 struct lsa_header header
;
3438 struct in_addr mask
;
3441 lsa
= ospf_lsdb_lookup_by_id(lsdb
, type
, p
->prefix
, router_id
);
3445 masklen2ip(p
->prefixlen
, &mask
);
3447 hmask
= (struct lsa_header_mask
*)lsa
->data
;
3449 if (mask
.s_addr
!= hmask
->mask
.s_addr
) {
3450 id
.s_addr
= p
->prefix
.s_addr
| (~mask
.s_addr
);
3451 lsa
= ospf_lsdb_lookup_by_id(lsdb
, type
, id
, router_id
);
3459 struct ospf_lsa
*ospf_lsa_lookup(struct ospf
*ospf
, struct ospf_area
*area
,
3460 uint32_t type
, struct in_addr id
,
3461 struct in_addr adv_router
)
3467 case OSPF_ROUTER_LSA
:
3468 case OSPF_NETWORK_LSA
:
3469 case OSPF_SUMMARY_LSA
:
3470 case OSPF_ASBR_SUMMARY_LSA
:
3471 case OSPF_AS_NSSA_LSA
:
3472 case OSPF_OPAQUE_LINK_LSA
:
3473 case OSPF_OPAQUE_AREA_LSA
:
3474 return ospf_lsdb_lookup_by_id(area
->lsdb
, type
, id
, adv_router
);
3475 case OSPF_AS_EXTERNAL_LSA
:
3476 case OSPF_OPAQUE_AS_LSA
:
3477 return ospf_lsdb_lookup_by_id(ospf
->lsdb
, type
, id
, adv_router
);
3485 struct ospf_lsa
*ospf_lsa_lookup_by_id(struct ospf_area
*area
, uint32_t type
,
3488 struct ospf_lsa
*lsa
;
3489 struct route_node
*rn
;
3492 case OSPF_ROUTER_LSA
:
3493 return ospf_lsdb_lookup_by_id(area
->lsdb
, type
, id
, id
);
3494 case OSPF_NETWORK_LSA
:
3495 for (rn
= route_top(NETWORK_LSDB(area
)); rn
;
3496 rn
= route_next(rn
))
3497 if ((lsa
= rn
->info
))
3498 if (IPV4_ADDR_SAME(&lsa
->data
->id
, &id
)) {
3499 route_unlock_node(rn
);
3503 case OSPF_SUMMARY_LSA
:
3504 case OSPF_ASBR_SUMMARY_LSA
:
3505 /* Currently not used. */
3507 return ospf_lsdb_lookup_by_id(area
->lsdb
, type
, id
, id
);
3508 case OSPF_AS_EXTERNAL_LSA
:
3509 case OSPF_AS_NSSA_LSA
:
3510 case OSPF_OPAQUE_LINK_LSA
:
3511 case OSPF_OPAQUE_AREA_LSA
:
3512 case OSPF_OPAQUE_AS_LSA
:
3513 /* Currently not used. */
3522 struct ospf_lsa
*ospf_lsa_lookup_by_header(struct ospf_area
*area
,
3523 struct lsa_header
*lsah
)
3525 struct ospf_lsa
*match
;
3528 * Strictly speaking, the LSA-ID field for Opaque-LSAs (type-9/10/11)
3529 * is redefined to have two subfields; opaque-type and opaque-id.
3530 * However, it is harmless to treat the two sub fields together, as if
3531 * they two were forming a unique LSA-ID.
3534 match
= ospf_lsa_lookup(area
->ospf
, area
, lsah
->type
, lsah
->id
,
3538 if (IS_DEBUG_OSPF(lsa
, LSA
) == OSPF_DEBUG_LSA
)
3539 zlog_debug("LSA[Type%d:%pI4]: Lookup by header, NO MATCH",
3540 lsah
->type
, &lsah
->id
);
3545 /* return +n, l1 is more recent.
3546 return -n, l2 is more recent.
3547 return 0, l1 and l2 is identical. */
3548 int ospf_lsa_more_recent(struct ospf_lsa
*l1
, struct ospf_lsa
*l2
)
3553 if (l1
== NULL
&& l2
== NULL
)
3560 /* compare LS sequence number. */
3561 x
= (int)ntohl(l1
->data
->ls_seqnum
);
3562 y
= (int)ntohl(l2
->data
->ls_seqnum
);
3568 /* compare LS checksum. */
3569 r
= ntohs(l1
->data
->checksum
) - ntohs(l2
->data
->checksum
);
3573 /* compare LS age. */
3574 if (IS_LSA_MAXAGE(l1
) && !IS_LSA_MAXAGE(l2
))
3576 else if (!IS_LSA_MAXAGE(l1
) && IS_LSA_MAXAGE(l2
))
3579 /* compare LS age with MaxAgeDiff. */
3580 if (LS_AGE(l1
) - LS_AGE(l2
) > OSPF_LSA_MAXAGE_DIFF
)
3582 else if (LS_AGE(l2
) - LS_AGE(l1
) > OSPF_LSA_MAXAGE_DIFF
)
3585 /* LSAs are identical. */
3590 * Check if two LSAs are different.
3593 * The first LSA to compare.
3596 * The second LSA to compare.
3599 * When set to true, ignore whether the LSAs were received from the network
3600 * or not. This parameter should be set to true when checking for topology
3601 * changes as part of the Graceful Restart helper neighbor procedures.
3604 * true if the LSAs are different, false otherwise.
3606 int ospf_lsa_different(struct ospf_lsa
*l1
, struct ospf_lsa
*l2
,
3607 bool ignore_rcvd_flag
)
3615 if (l1
->data
->options
!= l2
->data
->options
)
3618 if (IS_LSA_MAXAGE(l1
) && !IS_LSA_MAXAGE(l2
))
3621 if (IS_LSA_MAXAGE(l2
) && !IS_LSA_MAXAGE(l1
))
3624 if (l1
->size
!= l2
->size
)
3630 if (!ignore_rcvd_flag
3631 && CHECK_FLAG((l1
->flags
^ l2
->flags
), OSPF_LSA_RECEIVED
))
3632 return 1; /* May be a stale LSA in the LSBD */
3634 if (l1
->size
== OSPF_LSA_HEADER_SIZE
)
3635 return 0; /* nothing to compare */
3637 p1
= (char *)l1
->data
;
3638 p2
= (char *)l2
->data
;
3640 if (memcmp(p1
+ OSPF_LSA_HEADER_SIZE
, p2
+ OSPF_LSA_HEADER_SIZE
,
3641 l1
->size
- OSPF_LSA_HEADER_SIZE
)
3648 int ospf_lsa_flush_schedule(struct ospf
*ospf
, struct ospf_lsa
*lsa
)
3650 if (lsa
== NULL
|| !IS_LSA_SELF(lsa
))
3653 if (IS_DEBUG_OSPF_EVENT
)
3655 "LSA[Type%d:%pI4]: Schedule self-originated LSA to FLUSH",
3656 lsa
->data
->type
, &lsa
->data
->id
);
3658 /* Force given lsa's age to MaxAge. */
3659 lsa
->data
->ls_age
= htons(OSPF_LSA_MAXAGE
);
3661 switch (lsa
->data
->type
) {
3662 /* Opaque wants to be notified of flushes */
3663 case OSPF_OPAQUE_LINK_LSA
:
3664 case OSPF_OPAQUE_AREA_LSA
:
3665 case OSPF_OPAQUE_AS_LSA
:
3666 ospf_opaque_lsa_refresh(lsa
);
3669 ospf_refresher_unregister_lsa(ospf
, lsa
);
3670 ospf_lsa_flush(ospf
, lsa
);
3677 void ospf_flush_self_originated_lsas_now(struct ospf
*ospf
)
3679 struct listnode
*node
, *nnode
;
3680 struct listnode
*node2
, *nnode2
;
3681 struct ospf_area
*area
;
3682 struct ospf_interface
*oi
;
3683 struct ospf_lsa
*lsa
;
3684 struct route_node
*rn
;
3685 struct ospf_if_params
*oip
;
3686 int need_to_flush_ase
= 0;
3688 ospf
->inst_shutdown
= 1;
3690 for (ALL_LIST_ELEMENTS(ospf
->areas
, node
, nnode
, area
)) {
3691 if ((lsa
= area
->router_lsa_self
) != NULL
) {
3692 if (IS_DEBUG_OSPF_EVENT
)
3694 "LSA[Type%d:%pI4]: Schedule self-originated LSA to FLUSH",
3698 ospf_refresher_unregister_lsa(ospf
, lsa
);
3699 ospf_lsa_flush_area(lsa
, area
);
3700 ospf_lsa_unlock(&area
->router_lsa_self
);
3701 area
->router_lsa_self
= NULL
;
3704 for (ALL_LIST_ELEMENTS(area
->oiflist
, node2
, nnode2
, oi
)) {
3705 if ((lsa
= oi
->network_lsa_self
) != NULL
3706 && oi
->state
== ISM_DR
&& oi
->full_nbrs
> 0) {
3707 if (IS_DEBUG_OSPF_EVENT
)
3709 "LSA[Type%d:%pI4]: Schedule self-originated LSA to FLUSH",
3713 ospf_refresher_unregister_lsa(
3714 ospf
, oi
->network_lsa_self
);
3715 ospf_lsa_flush_area(oi
->network_lsa_self
, area
);
3716 ospf_lsa_unlock(&oi
->network_lsa_self
);
3717 oi
->network_lsa_self
= NULL
;
3719 oip
= ospf_lookup_if_params(
3720 oi
->ifp
, oi
->address
->u
.prefix4
);
3722 oip
->network_lsa_seqnum
= htonl(
3723 OSPF_INVALID_SEQUENCE_NUMBER
);
3726 if (oi
->type
!= OSPF_IFTYPE_VIRTUALLINK
3727 && area
->external_routing
== OSPF_AREA_DEFAULT
)
3728 need_to_flush_ase
= 1;
3731 LSDB_LOOP (SUMMARY_LSDB(area
), rn
, lsa
)
3732 ospf_lsa_flush_schedule(ospf
, lsa
);
3733 LSDB_LOOP (ASBR_SUMMARY_LSDB(area
), rn
, lsa
)
3734 ospf_lsa_flush_schedule(ospf
, lsa
);
3735 LSDB_LOOP (OPAQUE_LINK_LSDB(area
), rn
, lsa
)
3736 ospf_lsa_flush_schedule(ospf
, lsa
);
3737 LSDB_LOOP (OPAQUE_AREA_LSDB(area
), rn
, lsa
)
3738 ospf_lsa_flush_schedule(ospf
, lsa
);
3741 if (need_to_flush_ase
) {
3742 LSDB_LOOP (EXTERNAL_LSDB(ospf
), rn
, lsa
)
3743 ospf_lsa_flush_schedule(ospf
, lsa
);
3744 LSDB_LOOP (OPAQUE_AS_LSDB(ospf
), rn
, lsa
)
3745 ospf_lsa_flush_schedule(ospf
, lsa
);
3749 * Make sure that the MaxAge LSA remover is executed immediately,
3750 * without conflicting to other threads.
3752 if (ospf
->t_maxage
!= NULL
) {
3753 EVENT_OFF(ospf
->t_maxage
);
3754 event_execute(master
, ospf_maxage_lsa_remover
, ospf
, 0);
3760 /** @brief Function to refresh all the self originated
3761 * LSAs for area, when FR state change happens.
3762 * @param area pointer.
3765 void ospf_refresh_area_self_lsas(struct ospf_area
*area
)
3767 struct listnode
*node2
;
3768 struct listnode
*nnode2
;
3769 struct ospf_interface
*oi
;
3770 struct route_node
*rn
;
3771 struct ospf_lsa
*lsa
;
3776 if (area
->router_lsa_self
)
3777 ospf_lsa_refresh(area
->ospf
, area
->router_lsa_self
);
3779 for (ALL_LIST_ELEMENTS(area
->oiflist
, node2
, nnode2
, oi
))
3780 if (oi
->network_lsa_self
)
3781 ospf_lsa_refresh(oi
->ospf
, oi
->network_lsa_self
);
3783 LSDB_LOOP (SUMMARY_LSDB(area
), rn
, lsa
)
3784 if (IS_LSA_SELF(lsa
))
3785 ospf_lsa_refresh(area
->ospf
, lsa
);
3786 LSDB_LOOP (ASBR_SUMMARY_LSDB(area
), rn
, lsa
)
3787 if (IS_LSA_SELF(lsa
))
3788 ospf_lsa_refresh(area
->ospf
, lsa
);
3789 LSDB_LOOP (OPAQUE_LINK_LSDB(area
), rn
, lsa
)
3790 if (IS_LSA_SELF(lsa
))
3791 ospf_lsa_refresh(area
->ospf
, lsa
);
3792 LSDB_LOOP (OPAQUE_AREA_LSDB(area
), rn
, lsa
)
3793 if (IS_LSA_SELF(lsa
))
3794 ospf_lsa_refresh(area
->ospf
, lsa
);
3795 LSDB_LOOP (EXTERNAL_LSDB(area
->ospf
), rn
, lsa
)
3796 if (IS_LSA_SELF(lsa
))
3797 ospf_lsa_refresh(area
->ospf
, lsa
);
3798 LSDB_LOOP (OPAQUE_AS_LSDB(area
->ospf
), rn
, lsa
)
3799 if (IS_LSA_SELF(lsa
))
3800 ospf_lsa_refresh(area
->ospf
, lsa
);
3803 /* If there is self-originated LSA, then return 1, otherwise return 0. */
3804 /* An interface-independent version of ospf_lsa_is_self_originated */
3805 int ospf_lsa_is_self_originated(struct ospf
*ospf
, struct ospf_lsa
*lsa
)
3807 struct listnode
*node
;
3808 struct ospf_interface
*oi
;
3810 /* This LSA is already checked. */
3811 if (CHECK_FLAG(lsa
->flags
, OSPF_LSA_SELF_CHECKED
))
3812 return IS_LSA_SELF(lsa
);
3814 /* Make sure LSA is self-checked. */
3815 SET_FLAG(lsa
->flags
, OSPF_LSA_SELF_CHECKED
);
3817 /* AdvRouter and Router ID is the same. */
3818 if (IPV4_ADDR_SAME(&lsa
->data
->adv_router
, &ospf
->router_id
))
3819 SET_FLAG(lsa
->flags
, OSPF_LSA_SELF
);
3821 /* LSA is router-LSA. */
3822 else if (lsa
->data
->type
== OSPF_ROUTER_LSA
3823 && IPV4_ADDR_SAME(&lsa
->data
->id
, &ospf
->router_id
))
3824 SET_FLAG(lsa
->flags
, OSPF_LSA_SELF
);
3826 /* LSA is network-LSA. Compare Link ID with all interfaces. */
3827 else if (lsa
->data
->type
== OSPF_NETWORK_LSA
)
3828 for (ALL_LIST_ELEMENTS_RO(ospf
->oiflist
, node
, oi
)) {
3829 /* Ignore virtual link. */
3830 if (oi
->type
!= OSPF_IFTYPE_VIRTUALLINK
)
3831 if (oi
->address
->family
== AF_INET
)
3834 &oi
->address
->u
.prefix4
)) {
3835 /* to make it easier later */
3836 SET_FLAG(lsa
->flags
,
3838 return IS_LSA_SELF(lsa
);
3842 return IS_LSA_SELF(lsa
);
3845 /* Get unique Link State ID. */
3846 enum lsid_status
ospf_lsa_unique_id(struct ospf
*ospf
, struct ospf_lsdb
*lsdb
,
3847 uint8_t type
, struct prefix_ipv4
*p
,
3850 struct ospf_lsa
*lsa
;
3851 struct in_addr mask
;
3855 /* Check existence of LSA instance. */
3856 lsa
= ospf_lsdb_lookup_by_id(lsdb
, type
, *id
, ospf
->router_id
);
3858 struct as_external_lsa
*al
=
3859 (struct as_external_lsa
*)lsa
->data
;
3860 /* Ref rfc2328,Appendex E.1
3861 * If router already originated the external lsa with lsid
3862 * as the current prefix, and the masklens are same then
3863 * terminate the LSID algorithem.
3865 if (ip_masklen(al
->mask
) == p
->prefixlen
) {
3866 if (IS_DEBUG_OSPF(lsa
, LSA_GENERATE
))
3868 "%s: Can't get Link State ID for %pFX",
3870 /* id.s_addr = 0; */
3871 id
->s_addr
= 0xffffffff;
3872 return LSID_NOT_AVAILABLE
;
3873 } else if (ip_masklen(al
->mask
) < p
->prefixlen
) {
3874 /* Ref rfc2328,Appendex E.2
3875 * the current prefix masklen is greater than the
3876 * existing LSA, then generate the Link state ID,
3877 * by setting all host bits in prefix addressa and
3880 * Eg: 1st Route : 10.0.0.0/16 - LSID:10.0.0.0
3881 * 2nd Route : 10.0.0.0/24 - LSID:10.0.0.255
3883 masklen2ip(p
->prefixlen
, &mask
);
3885 id
->s_addr
= p
->prefix
.s_addr
| (~mask
.s_addr
);
3886 lsa
= ospf_lsdb_lookup_by_id(ospf
->lsdb
, type
, *id
,
3889 if (IS_DEBUG_OSPF(lsa
, LSA_GENERATE
))
3891 "%s: Can't get Link State ID for %pFX",
3893 id
->s_addr
= 0xffffffff;
3894 return LSID_NOT_AVAILABLE
;
3897 /* Ref rfc2328,Appendex E.3
3898 * the current prefix masklen is lesser than the
3899 * existing LSA,then the originated LSA has to be
3900 * refreshed by modifying masklen, cost and tag.
3901 * Originate the old route info with new LSID by
3902 * setting the host bits in prefix address.
3904 * Eg: 1st Route : 10.0.0.0/24 - LSID:10.0.0.0
3905 * 2nd Route : 10.0.0.0/16 - ?
3906 * Since 2nd route mask len is less than firstone
3907 * LSID has to be changed.
3908 * 1st route LSID:10.0.0.255
3909 * 2nd route LSID:10.0.0.0
3911 id
->s_addr
= lsa
->data
->id
.s_addr
| (~al
->mask
.s_addr
);
3912 lsa
= ospf_lsdb_lookup_by_id(ospf
->lsdb
, type
, *id
,
3914 if (lsa
&& (ip_masklen(al
->mask
) != IPV4_MAX_BITLEN
)) {
3915 if (IS_DEBUG_OSPF(lsa
, LSA_GENERATE
))
3917 "%s: Can't get Link State ID for %pFX",
3919 id
->s_addr
= 0xffffffff;
3920 return LSID_NOT_AVAILABLE
;
3926 return LSID_AVAILABLE
;
3930 #define LSA_ACTION_FLOOD_AREA 1
3931 #define LSA_ACTION_FLUSH_AREA 2
3935 struct ospf_area
*area
;
3936 struct ospf_lsa
*lsa
;
3939 static void ospf_lsa_action(struct event
*t
)
3941 struct lsa_action
*data
;
3943 data
= EVENT_ARG(t
);
3945 if (IS_DEBUG_OSPF(lsa
, LSA
) == OSPF_DEBUG_LSA
)
3946 zlog_debug("LSA[Action]: Performing scheduled LSA action: %d",
3949 switch (data
->action
) {
3950 case LSA_ACTION_FLOOD_AREA
:
3951 ospf_flood_through_area(data
->area
, NULL
, data
->lsa
);
3953 case LSA_ACTION_FLUSH_AREA
:
3954 ospf_lsa_flush_area(data
->lsa
, data
->area
);
3958 ospf_lsa_unlock(&data
->lsa
); /* Message */
3959 XFREE(MTYPE_OSPF_MESSAGE
, data
);
3962 void ospf_schedule_lsa_flood_area(struct ospf_area
*area
, struct ospf_lsa
*lsa
)
3964 struct lsa_action
*data
;
3966 data
= XCALLOC(MTYPE_OSPF_MESSAGE
, sizeof(struct lsa_action
));
3967 data
->action
= LSA_ACTION_FLOOD_AREA
;
3969 data
->lsa
= ospf_lsa_lock(lsa
); /* Message / Flood area */
3971 event_add_event(master
, ospf_lsa_action
, data
, 0, NULL
);
3974 void ospf_schedule_lsa_flush_area(struct ospf_area
*area
, struct ospf_lsa
*lsa
)
3976 struct lsa_action
*data
;
3978 data
= XCALLOC(MTYPE_OSPF_MESSAGE
, sizeof(struct lsa_action
));
3979 data
->action
= LSA_ACTION_FLUSH_AREA
;
3981 data
->lsa
= ospf_lsa_lock(lsa
); /* Message / Flush area */
3983 event_add_event(master
, ospf_lsa_action
, data
, 0, NULL
);
3987 /* LSA Refreshment functions. */
3988 struct ospf_lsa
*ospf_lsa_refresh(struct ospf
*ospf
, struct ospf_lsa
*lsa
)
3990 struct external_info
*ei
;
3991 struct ospf_external_aggr_rt
*aggr
;
3992 struct ospf_lsa
*new = NULL
;
3993 struct as_external_lsa
*al
;
3994 struct prefix_ipv4 p
;
3996 assert(CHECK_FLAG(lsa
->flags
, OSPF_LSA_SELF
));
3997 assert(IS_LSA_SELF(lsa
));
3998 assert(lsa
->lock
> 0);
4000 switch (lsa
->data
->type
) {
4001 /* Router and Network LSAs are processed differently. */
4002 case OSPF_ROUTER_LSA
:
4003 new = ospf_router_lsa_refresh(lsa
);
4005 case OSPF_NETWORK_LSA
:
4006 new = ospf_network_lsa_refresh(lsa
);
4008 case OSPF_SUMMARY_LSA
:
4009 new = ospf_summary_lsa_refresh(ospf
, lsa
);
4011 case OSPF_ASBR_SUMMARY_LSA
:
4012 new = ospf_summary_asbr_lsa_refresh(ospf
, lsa
);
4014 case OSPF_AS_EXTERNAL_LSA
:
4015 /* Translated from NSSA Type-5s are refreshed when
4016 * from refresh of Type-7 - do not refresh these directly.
4019 al
= (struct as_external_lsa
*)lsa
->data
;
4021 p
.prefixlen
= ip_masklen(al
->mask
);
4022 p
.prefix
= lsa
->data
->id
;
4024 if (CHECK_FLAG(lsa
->flags
, OSPF_LSA_LOCAL_XLT
))
4026 ei
= ospf_external_info_check(ospf
, lsa
);
4028 new = ospf_external_lsa_refresh(
4029 ospf
, lsa
, ei
, LSA_REFRESH_FORCE
, false);
4031 aggr
= (struct ospf_external_aggr_rt
*)
4032 ospf_extrenal_aggregator_lookup(ospf
, &p
);
4034 struct external_info ei_aggr
;
4036 memset(&ei_aggr
, 0, sizeof(ei_aggr
));
4037 ei_aggr
.p
= aggr
->p
;
4038 ei_aggr
.tag
= aggr
->tag
;
4039 ei_aggr
.instance
= ospf
->instance
;
4040 ei_aggr
.route_map_set
.metric
= -1;
4041 ei_aggr
.route_map_set
.metric_type
= -1;
4043 ospf_external_lsa_refresh(ospf
, lsa
, &ei_aggr
,
4044 LSA_REFRESH_FORCE
, true);
4045 SET_FLAG(aggr
->flags
,
4046 OSPF_EXTERNAL_AGGRT_ORIGINATED
);
4048 ospf_lsa_flush_as(ospf
, lsa
);
4051 case OSPF_OPAQUE_LINK_LSA
:
4052 case OSPF_OPAQUE_AREA_LSA
:
4053 case OSPF_OPAQUE_AS_LSA
:
4054 new = ospf_opaque_lsa_refresh(lsa
);
4062 void ospf_refresher_register_lsa(struct ospf
*ospf
, struct ospf_lsa
*lsa
)
4064 uint16_t index
, current_index
;
4066 assert(lsa
->lock
> 0);
4067 assert(IS_LSA_SELF(lsa
));
4069 if (lsa
->refresh_list
< 0) {
4072 ospf
->lsa_refresh_timer
- (2 * OSPF_LS_REFRESH_JITTER
);
4074 ospf
->lsa_refresh_timer
- OSPF_LS_REFRESH_JITTER
;
4076 /* We want to refresh the LSA within OSPF_LS_REFRESH_TIME which
4078 * 1800s. Use jitter so that we send the LSA sometime between
4082 delay
= (frr_weak_random() % (max_delay
- min_delay
))
4085 current_index
= ospf
->lsa_refresh_queue
.index
4086 + (monotime(NULL
) - ospf
->lsa_refresher_started
)
4087 / OSPF_LSA_REFRESHER_GRANULARITY
;
4089 index
= (current_index
+ delay
/ OSPF_LSA_REFRESHER_GRANULARITY
)
4090 % (OSPF_LSA_REFRESHER_SLOTS
);
4092 if (IS_DEBUG_OSPF(lsa
, LSA_REFRESH
))
4094 "LSA[Refresh:Type%d:%pI4]: age %d, added to index %d",
4095 lsa
->data
->type
, &lsa
->data
->id
,
4096 LS_AGE(lsa
), index
);
4098 if (!ospf
->lsa_refresh_queue
.qs
[index
])
4099 ospf
->lsa_refresh_queue
.qs
[index
] = list_new();
4101 listnode_add(ospf
->lsa_refresh_queue
.qs
[index
],
4102 ospf_lsa_lock(lsa
)); /* lsa_refresh_queue */
4103 lsa
->refresh_list
= index
;
4105 if (IS_DEBUG_OSPF(lsa
, LSA_REFRESH
))
4107 "LSA[Refresh:Type%d:%pI4]: %s: setting refresh_list on lsa %p (slot %d)",
4108 lsa
->data
->type
, &lsa
->data
->id
, __func__
,
4109 (void *)lsa
, index
);
4113 void ospf_refresher_unregister_lsa(struct ospf
*ospf
, struct ospf_lsa
*lsa
)
4115 assert(lsa
->lock
> 0);
4116 assert(IS_LSA_SELF(lsa
));
4117 if (lsa
->refresh_list
>= 0) {
4118 struct list
*refresh_list
=
4119 ospf
->lsa_refresh_queue
.qs
[lsa
->refresh_list
];
4120 listnode_delete(refresh_list
, lsa
);
4121 if (!listcount(refresh_list
)) {
4122 list_delete(&refresh_list
);
4123 ospf
->lsa_refresh_queue
.qs
[lsa
->refresh_list
] = NULL
;
4125 lsa
->refresh_list
= -1;
4126 ospf_lsa_unlock(&lsa
); /* lsa_refresh_queue */
4130 void ospf_lsa_refresh_walker(struct event
*t
)
4132 struct list
*refresh_list
;
4133 struct listnode
*node
, *nnode
;
4134 struct ospf
*ospf
= EVENT_ARG(t
);
4135 struct ospf_lsa
*lsa
;
4137 struct list
*lsa_to_refresh
= list_new();
4140 if (IS_DEBUG_OSPF(lsa
, LSA_REFRESH
))
4141 zlog_debug("LSA[Refresh]: %s: start", __func__
);
4144 i
= ospf
->lsa_refresh_queue
.index
;
4146 /* Note: if clock has jumped backwards, then time change could be
4148 so we are careful to cast the expression to unsigned before taking
4150 ospf
->lsa_refresh_queue
.index
=
4151 ((unsigned long)(ospf
->lsa_refresh_queue
.index
4153 - ospf
->lsa_refresher_started
)
4154 / OSPF_LSA_REFRESHER_GRANULARITY
))
4155 % OSPF_LSA_REFRESHER_SLOTS
;
4157 if (IS_DEBUG_OSPF(lsa
, LSA_REFRESH
))
4158 zlog_debug("LSA[Refresh]: %s: next index %d", __func__
,
4159 ospf
->lsa_refresh_queue
.index
);
4161 for (; i
!= ospf
->lsa_refresh_queue
.index
;
4162 i
= (i
+ 1) % OSPF_LSA_REFRESHER_SLOTS
) {
4163 if (IS_DEBUG_OSPF(lsa
, LSA_REFRESH
))
4164 zlog_debug("LSA[Refresh]: %s: refresh index %d",
4167 refresh_list
= ospf
->lsa_refresh_queue
.qs
[i
];
4171 ospf
->lsa_refresh_queue
.qs
[i
] = NULL
;
4174 for (ALL_LIST_ELEMENTS(refresh_list
, node
, nnode
,
4176 if (IS_DEBUG_OSPF(lsa
, LSA_REFRESH
))
4178 "LSA[Refresh:Type%d:%pI4]: %s: refresh lsa %p (slot %d)",
4179 lsa
->data
->type
, &lsa
->data
->id
,
4180 __func__
, (void *)lsa
, i
);
4182 assert(lsa
->lock
> 0);
4183 list_delete_node(refresh_list
, node
);
4184 lsa
->refresh_list
= -1;
4185 listnode_add(lsa_to_refresh
, lsa
);
4187 list_delete(&refresh_list
);
4191 ospf
->t_lsa_refresher
= NULL
;
4192 event_add_timer(master
, ospf_lsa_refresh_walker
, ospf
,
4193 ospf
->lsa_refresh_interval
, &ospf
->t_lsa_refresher
);
4194 ospf
->lsa_refresher_started
= monotime(NULL
);
4196 for (ALL_LIST_ELEMENTS(lsa_to_refresh
, node
, nnode
, lsa
)) {
4197 dna_lsa
= ospf_check_dna_lsa(lsa
);
4198 if (!dna_lsa
) { /* refresh only non-DNA LSAs */
4199 ospf_lsa_refresh(ospf
, lsa
);
4201 assert(lsa
->lock
> 0);
4202 ospf_lsa_unlock(&lsa
); /* lsa_refresh_queue & temp for
4207 list_delete(&lsa_to_refresh
);
4209 if (IS_DEBUG_OSPF(lsa
, LSA_REFRESH
))
4210 zlog_debug("LSA[Refresh]: %s: end", __func__
);
4213 /* Flush the LSAs for the specific area */
4214 void ospf_flush_lsa_from_area(struct ospf
*ospf
, struct in_addr area_id
,
4217 struct ospf_area
*area
;
4218 struct route_node
*rn
;
4219 struct ospf_lsa
*lsa
;
4221 area
= ospf_area_get(ospf
, area_id
);
4224 case OSPF_AS_EXTERNAL_LSA
:
4225 if ((area
->external_routing
== OSPF_AREA_NSSA
) ||
4226 (area
->external_routing
== OSPF_AREA_STUB
)) {
4227 LSDB_LOOP (EXTERNAL_LSDB(ospf
), rn
, lsa
)
4228 if (IS_LSA_SELF(lsa
) &&
4229 !(CHECK_FLAG(lsa
->flags
,
4230 OSPF_LSA_LOCAL_XLT
)))
4231 ospf_lsa_flush_area(lsa
, area
);
4234 case OSPF_AS_NSSA_LSA
:
4235 LSDB_LOOP (NSSA_LSDB(area
), rn
, lsa
)
4236 if (IS_LSA_SELF(lsa
))
4237 ospf_lsa_flush_area(lsa
, area
);