2 * OSPF Link State Advertisement
3 * Copyright (C) 1999, 2000 Toshiaki Takada
5 * This file is part of GNU Zebra.
7 * GNU Zebra is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU General Public License as published by the
9 * Free Software Foundation; either version 2, or (at your option) any
12 * GNU Zebra is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with GNU Zebra; see the file COPYING. If not, write to the Free
19 * Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
34 #include "sockunion.h" /* for inet_aton() */
36 #include "ospfd/ospfd.h"
37 #include "ospfd/ospf_interface.h"
38 #include "ospfd/ospf_ism.h"
39 #include "ospfd/ospf_asbr.h"
40 #include "ospfd/ospf_lsa.h"
41 #include "ospfd/ospf_lsdb.h"
42 #include "ospfd/ospf_neighbor.h"
43 #include "ospfd/ospf_nsm.h"
44 #include "ospfd/ospf_flood.h"
45 #include "ospfd/ospf_packet.h"
46 #include "ospfd/ospf_spf.h"
47 #include "ospfd/ospf_dump.h"
48 #include "ospfd/ospf_route.h"
49 #include "ospfd/ospf_ase.h"
50 #include "ospfd/ospf_zebra.h"
54 get_metric (u_char
*metric
)
58 m
= (m
<< 8) + metric
[1];
59 m
= (m
<< 8) + metric
[2];
65 tv_adjust (struct timeval a
)
67 while (a
.tv_usec
>= 1000000)
83 tv_ceil (struct timeval a
)
87 return (a
.tv_usec
? a
.tv_sec
+ 1 : a
.tv_sec
);
91 tv_floor (struct timeval a
)
110 tv_add (struct timeval a
, struct timeval b
)
114 ret
.tv_sec
= a
.tv_sec
+ b
.tv_sec
;
115 ret
.tv_usec
= a
.tv_usec
+ b
.tv_usec
;
117 return tv_adjust (ret
);
121 tv_sub (struct timeval a
, struct timeval b
)
125 ret
.tv_sec
= a
.tv_sec
- b
.tv_sec
;
126 ret
.tv_usec
= a
.tv_usec
- b
.tv_usec
;
128 return tv_adjust (ret
);
132 tv_cmp (struct timeval a
, struct timeval b
)
134 return (a
.tv_sec
== b
.tv_sec
?
135 a
.tv_usec
- b
.tv_usec
: a
.tv_sec
- b
.tv_sec
);
139 ospf_lsa_refresh_delay (struct ospf_lsa
*lsa
)
141 struct timeval delta
, now
;
144 quagga_gettime (QUAGGA_CLK_MONOTONIC
, &now
);
145 delta
= tv_sub (now
, lsa
->tv_orig
);
147 if (tv_cmp (delta
, int2tv (OSPF_MIN_LS_INTERVAL
)) < 0)
149 delay
= tv_ceil (tv_sub (int2tv (OSPF_MIN_LS_INTERVAL
), delta
));
151 if (IS_DEBUG_OSPF (lsa
, LSA_GENERATE
))
152 zlog_debug ("LSA[Type%d:%s]: Refresh timer delay %d seconds",
153 lsa
->data
->type
, inet_ntoa (lsa
->data
->id
), delay
);
163 get_age (struct ospf_lsa
*lsa
)
167 age
= ntohs (lsa
->data
->ls_age
)
168 + tv_floor (tv_sub (recent_relative_time (), lsa
->tv_recv
));
174 /* Fletcher Checksum -- Refer to RFC1008. */
176 #define LSA_CHECKSUM_OFFSET 15
179 ospf_lsa_checksum (struct lsa_header
*lsa
)
181 u_char
*sp
, *ep
, *p
, *q
;
187 length
= ntohs (lsa
->length
) - 2;
188 sp
= (u_char
*) &lsa
->options
;
190 for (ep
= sp
+ length
; sp
< ep
; sp
= q
)
195 for (p
= sp
; p
< q
; p
++)
204 x
= (((int)length
- LSA_CHECKSUM_OFFSET
) * c0
- c1
) % 255;
211 /* take care endian issue. */
212 lsa
->checksum
= htons ((x
<< 8) + y
);
214 return (lsa
->checksum
);
219 /* Create OSPF LSA. */
223 struct ospf_lsa
*new;
225 new = XCALLOC (MTYPE_OSPF_LSA
, sizeof (struct ospf_lsa
));
226 memset (new, 0, sizeof (struct ospf_lsa
));
230 new->retransmit_counter
= 0;
231 new->tv_recv
= recent_relative_time ();
232 new->tv_orig
= new->tv_recv
;
233 new->refresh_list
= -1;
238 /* Duplicate OSPF LSA. */
240 ospf_lsa_dup (struct ospf_lsa
*lsa
)
242 struct ospf_lsa
*new;
247 new = XCALLOC (MTYPE_OSPF_LSA
, sizeof (struct ospf_lsa
));
249 memcpy (new, lsa
, sizeof (struct ospf_lsa
));
250 UNSET_FLAG (new->flags
, OSPF_LSA_DISCARD
);
252 new->retransmit_counter
= 0;
253 new->data
= ospf_lsa_data_dup (lsa
->data
);
255 /* kevinm: Clear the refresh_list, otherwise there are going
256 to be problems when we try to remove the LSA from the
257 queue (which it's not a member of.)
258 XXX: Should we add the LSA to the refresh_list queue? */
259 new->refresh_list
= -1;
261 if (IS_DEBUG_OSPF (lsa
, LSA
))
262 zlog_debug ("LSA: duplicated %p (new: %p)", lsa
, new);
269 ospf_lsa_free (struct ospf_lsa
*lsa
)
271 assert (lsa
->lock
== 0);
273 if (IS_DEBUG_OSPF (lsa
, LSA
))
274 zlog_debug ("LSA: freed %p", lsa
);
276 /* Delete LSA data. */
277 if (lsa
->data
!= NULL
)
278 ospf_lsa_data_free (lsa
->data
);
280 assert (lsa
->refresh_list
< 0);
282 memset (lsa
, 0, sizeof (struct ospf_lsa
));
283 XFREE (MTYPE_OSPF_LSA
, lsa
);
288 ospf_lsa_lock (struct ospf_lsa
*lsa
)
296 ospf_lsa_unlock (struct ospf_lsa
**lsa
)
298 /* This is sanity check. */
304 assert ((*lsa
)->lock
>= 0);
306 if ((*lsa
)->lock
== 0)
308 assert (CHECK_FLAG ((*lsa
)->flags
, OSPF_LSA_DISCARD
));
309 ospf_lsa_free (*lsa
);
314 /* Check discard flag. */
316 ospf_lsa_discard (struct ospf_lsa
*lsa
)
318 if (!CHECK_FLAG (lsa
->flags
, OSPF_LSA_DISCARD
))
320 SET_FLAG (lsa
->flags
, OSPF_LSA_DISCARD
);
321 ospf_lsa_unlock (&lsa
);
325 /* Create LSA data. */
327 ospf_lsa_data_new (size_t size
)
329 struct lsa_header
*new;
331 new = (struct lsa_header
*) XMALLOC (MTYPE_OSPF_LSA_DATA
, size
);
332 memset (new, 0, size
);
337 /* Duplicate LSA data. */
339 ospf_lsa_data_dup (struct lsa_header
*lsah
)
341 struct lsa_header
*new;
343 new = ospf_lsa_data_new (ntohs (lsah
->length
));
344 memcpy (new, lsah
, ntohs (lsah
->length
));
351 ospf_lsa_data_free (struct lsa_header
*lsah
)
353 if (IS_DEBUG_OSPF (lsa
, LSA
))
354 zlog_debug ("LSA[Type%d:%s]: data freed %p",
355 lsah
->type
, inet_ntoa (lsah
->id
), lsah
);
357 XFREE (MTYPE_OSPF_LSA_DATA
, lsah
);
361 /* LSA general functions. */
364 dump_lsa_key (struct ospf_lsa
*lsa
)
366 static char buf
[] = {
367 "Type255,id(255.255.255.255),ar(255.255.255.255)"
369 struct lsa_header
*lsah
;
371 if (lsa
!= NULL
&& (lsah
= lsa
->data
) != NULL
)
373 char id
[INET_ADDRSTRLEN
], ar
[INET_ADDRSTRLEN
];
374 strcpy (id
, inet_ntoa (lsah
->id
));
375 strcpy (ar
, inet_ntoa (lsah
->adv_router
));
377 sprintf (buf
, "Type%d,id(%s),ar(%s)", lsah
->type
, id
, ar
);
380 strcpy (buf
, "NULL");
386 lsa_seqnum_increment (struct ospf_lsa
*lsa
)
390 seqnum
= ntohl (lsa
->data
->ls_seqnum
) + 1;
392 return htonl (seqnum
);
396 lsa_header_set (struct stream
*s
, u_char options
,
397 u_char type
, struct in_addr id
, struct in_addr router_id
)
399 struct lsa_header
*lsah
;
401 lsah
= (struct lsa_header
*) STREAM_DATA (s
);
403 lsah
->ls_age
= htons (0);
404 lsah
->options
= options
;
407 lsah
->adv_router
= router_id
;
408 lsah
->ls_seqnum
= htonl (OSPF_INITIAL_SEQUENCE_NUMBER
);
410 stream_forward_endp (s
, OSPF_LSA_HEADER_SIZE
);
414 /* router-LSA related functions. */
415 /* Get router-LSA flags. */
417 router_lsa_flags (struct ospf_area
*area
)
421 flags
= area
->ospf
->flags
;
423 /* Set virtual link flag. */
424 if (ospf_full_virtual_nbrs (area
))
425 SET_FLAG (flags
, ROUTER_LSA_VIRTUAL
);
427 /* Just sanity check */
428 UNSET_FLAG (flags
, ROUTER_LSA_VIRTUAL
);
430 /* Set Shortcut ABR behabiour flag. */
431 UNSET_FLAG (flags
, ROUTER_LSA_SHORTCUT
);
432 if (area
->ospf
->abr_type
== OSPF_ABR_SHORTCUT
)
433 if (!OSPF_IS_AREA_BACKBONE (area
))
434 if ((area
->shortcut_configured
== OSPF_SHORTCUT_DEFAULT
&&
435 area
->ospf
->backbone
== NULL
) ||
436 area
->shortcut_configured
== OSPF_SHORTCUT_ENABLE
)
437 SET_FLAG (flags
, ROUTER_LSA_SHORTCUT
);
439 /* ASBR can't exit in stub area. */
440 if (area
->external_routing
== OSPF_AREA_STUB
)
441 UNSET_FLAG (flags
, ROUTER_LSA_EXTERNAL
);
442 /* If ASBR set External flag */
443 else if (IS_OSPF_ASBR (area
->ospf
))
444 SET_FLAG (flags
, ROUTER_LSA_EXTERNAL
);
446 /* Set ABR dependent flags */
447 if (IS_OSPF_ABR (area
->ospf
))
449 SET_FLAG (flags
, ROUTER_LSA_BORDER
);
450 /* If Area is NSSA and we are both ABR and unconditional translator,
451 * set Nt bit to inform other routers.
453 if ( (area
->external_routing
== OSPF_AREA_NSSA
)
454 && (area
->NSSATranslatorRole
== OSPF_NSSA_ROLE_ALWAYS
))
455 SET_FLAG (flags
, ROUTER_LSA_NT
);
460 /* Lookup neighbor other than myself.
461 And check neighbor count,
462 Point-to-Point link must have only 1 neighbor. */
463 struct ospf_neighbor
*
464 ospf_nbr_lookup_ptop (struct ospf_interface
*oi
)
466 struct ospf_neighbor
*nbr
= NULL
;
467 struct route_node
*rn
;
469 /* Search neighbor, there must be one of two nbrs. */
470 for (rn
= route_top (oi
->nbrs
); rn
; rn
= route_next (rn
))
471 if ((nbr
= rn
->info
))
472 if (!IPV4_ADDR_SAME (&nbr
->router_id
, &oi
->ospf
->router_id
))
473 if (nbr
->state
== NSM_Full
)
475 route_unlock_node (rn
);
479 /* PtoP link must have only 1 neighbor. */
480 if (ospf_nbr_count (oi
, 0) > 1)
481 zlog_warn ("Point-to-Point link has more than 1 neighobrs.");
486 /* Determine cost of link, taking RFC3137 stub-router support into
490 ospf_link_cost (struct ospf_interface
*oi
)
492 /* RFC3137 stub router support */
493 if (!CHECK_FLAG (oi
->area
->stub_router_state
, OSPF_AREA_IS_STUB_ROUTED
))
494 return oi
->output_cost
;
496 return OSPF_OUTPUT_COST_INFINITE
;
499 /* Set a link information. */
501 link_info_set (struct stream
*s
, struct in_addr id
,
502 struct in_addr data
, u_char type
, u_char tos
, u_int16_t cost
)
504 /* LSA stream is initially allocated to OSPF_MAX_LSA_SIZE, suits
505 * vast majority of cases. Some rare routers with lots of links need more.
506 * we try accomodate those here.
508 if (STREAM_WRITEABLE(s
) < OSPF_ROUTER_LSA_LINK_SIZE
)
510 size_t ret
= OSPF_MAX_LSA_SIZE
;
512 /* Can we enlarge the stream still? */
513 if (STREAM_SIZE(s
) == OSPF_MAX_LSA_SIZE
)
515 /* we futz the size here for simplicity, really we need to account
517 * IP Header - (sizeof (struct ip))
518 * OSPF Header - OSPF_HEADER_SIZE
519 * LSA Header - OSPF_LSA_HEADER_SIZE
520 * MD5 auth data, if MD5 is configured - OSPF_AUTH_MD5_SIZE.
522 * Simpler just to subtract OSPF_MAX_LSA_SIZE though.
524 ret
= stream_resize (s
, OSPF_MAX_PACKET_SIZE
- OSPF_MAX_LSA_SIZE
);
527 if (ret
== OSPF_MAX_LSA_SIZE
)
529 zlog_warn ("%s: Out of space in LSA stream, left %ld, size %ld",
530 __func__
, STREAM_REMAIN (s
), STREAM_SIZE (s
));
535 /* TOS based routing is not supported. */
536 stream_put_ipv4 (s
, id
.s_addr
); /* Link ID. */
537 stream_put_ipv4 (s
, data
.s_addr
); /* Link Data. */
538 stream_putc (s
, type
); /* Link Type. */
539 stream_putc (s
, tos
); /* TOS = 0. */
540 stream_putw (s
, cost
); /* Link Cost. */
545 /* Describe Point-to-Point link (Section 12.4.1.1). */
547 lsa_link_ptop_set (struct stream
*s
, struct ospf_interface
*oi
)
550 struct ospf_neighbor
*nbr
;
551 struct in_addr id
, mask
;
552 u_int16_t cost
= ospf_link_cost (oi
);
554 if (IS_DEBUG_OSPF (lsa
, LSA_GENERATE
))
555 zlog_debug ("LSA[Type1]: Set link Point-to-Point");
557 if ((nbr
= ospf_nbr_lookup_ptop (oi
)))
558 if (nbr
->state
== NSM_Full
)
560 /* For unnumbered point-to-point networks, the Link Data field
561 should specify the interface's MIB-II ifIndex value. */
562 links
+= link_info_set (s
, nbr
->router_id
, oi
->address
->u
.prefix4
,
563 LSA_LINK_TYPE_POINTOPOINT
, 0, cost
);
566 /* Regardless of the state of the neighboring router, we must
567 add a Type 3 link (stub network).
568 N.B. Options 1 & 2 share basically the same logic. */
569 masklen2ip (oi
->address
->prefixlen
, &mask
);
570 id
.s_addr
= CONNECTED_PREFIX(oi
->connected
)->u
.prefix4
.s_addr
& mask
.s_addr
;
571 links
+= link_info_set (s
, id
, mask
, LSA_LINK_TYPE_STUB
, 0,
576 /* Describe Broadcast Link. */
578 lsa_link_broadcast_set (struct stream
*s
, struct ospf_interface
*oi
)
580 struct ospf_neighbor
*dr
;
581 struct in_addr id
, mask
;
582 u_int16_t cost
= ospf_link_cost (oi
);
584 /* Describe Type 3 Link. */
585 if (oi
->state
== ISM_Waiting
)
587 masklen2ip (oi
->address
->prefixlen
, &mask
);
588 id
.s_addr
= oi
->address
->u
.prefix4
.s_addr
& mask
.s_addr
;
589 return link_info_set (s
, id
, mask
, LSA_LINK_TYPE_STUB
, 0,
593 dr
= ospf_nbr_lookup_by_addr (oi
->nbrs
, &DR (oi
));
594 /* Describe Type 2 link. */
595 if (dr
&& (dr
->state
== NSM_Full
||
596 IPV4_ADDR_SAME (&oi
->address
->u
.prefix4
, &DR (oi
))) &&
597 ospf_nbr_count (oi
, NSM_Full
) > 0)
599 return link_info_set (s
, DR (oi
), oi
->address
->u
.prefix4
,
600 LSA_LINK_TYPE_TRANSIT
, 0, cost
);
602 /* Describe type 3 link. */
605 masklen2ip (oi
->address
->prefixlen
, &mask
);
606 id
.s_addr
= oi
->address
->u
.prefix4
.s_addr
& mask
.s_addr
;
607 return link_info_set (s
, id
, mask
, LSA_LINK_TYPE_STUB
, 0,
613 lsa_link_loopback_set (struct stream
*s
, struct ospf_interface
*oi
)
615 struct in_addr id
, mask
;
617 /* Describe Type 3 Link. */
618 if (oi
->state
!= ISM_Loopback
)
621 mask
.s_addr
= 0xffffffff;
622 id
.s_addr
= oi
->address
->u
.prefix4
.s_addr
;
623 return link_info_set (s
, id
, mask
, LSA_LINK_TYPE_STUB
, 0, oi
->output_cost
);
626 /* Describe Virtual Link. */
628 lsa_link_virtuallink_set (struct stream
*s
, struct ospf_interface
*oi
)
630 struct ospf_neighbor
*nbr
;
631 u_int16_t cost
= ospf_link_cost (oi
);
633 if (oi
->state
== ISM_PointToPoint
)
634 if ((nbr
= ospf_nbr_lookup_ptop (oi
)))
635 if (nbr
->state
== NSM_Full
)
637 return link_info_set (s
, nbr
->router_id
, oi
->address
->u
.prefix4
,
638 LSA_LINK_TYPE_VIRTUALLINK
, 0, cost
);
644 #define lsa_link_nbma_set(S,O) lsa_link_broadcast_set (S, O)
646 /* this function add for support point-to-multipoint ,see rfc2328
648 /* from "edward rrr" <edward_rrr@hotmail.com>
649 http://marc.theaimsgroup.com/?l=zebra&m=100739222210507&w=2 */
651 lsa_link_ptomp_set (struct stream
*s
, struct ospf_interface
*oi
)
654 struct route_node
*rn
;
655 struct ospf_neighbor
*nbr
= NULL
;
656 struct in_addr id
, mask
;
657 u_int16_t cost
= ospf_link_cost (oi
);
659 mask
.s_addr
= 0xffffffff;
660 id
.s_addr
= oi
->address
->u
.prefix4
.s_addr
;
661 links
+= link_info_set (s
, id
, mask
, LSA_LINK_TYPE_STUB
, 0, 0);
663 if (IS_DEBUG_OSPF (lsa
, LSA_GENERATE
))
664 zlog_debug ("PointToMultipoint: running ptomultip_set");
666 /* Search neighbor, */
667 for (rn
= route_top (oi
->nbrs
); rn
; rn
= route_next (rn
))
668 if ((nbr
= rn
->info
) != NULL
)
670 if (!IPV4_ADDR_SAME (&nbr
->router_id
, &oi
->ospf
->router_id
))
671 if (nbr
->state
== NSM_Full
)
674 links
+= link_info_set (s
, nbr
->router_id
, oi
->address
->u
.prefix4
,
675 LSA_LINK_TYPE_POINTOPOINT
, 0, cost
);
676 if (IS_DEBUG_OSPF (lsa
, LSA_GENERATE
))
677 zlog_debug ("PointToMultipoint: set link to %s",
678 inet_ntoa(oi
->address
->u
.prefix4
));
684 /* Set router-LSA link information. */
686 router_lsa_link_set (struct stream
*s
, struct ospf_area
*area
)
688 struct listnode
*node
;
689 struct ospf_interface
*oi
;
692 for (ALL_LIST_ELEMENTS_RO (area
->oiflist
, node
, oi
))
694 struct interface
*ifp
= oi
->ifp
;
696 /* Check interface is up, OSPF is enable. */
697 if (if_is_operative (ifp
))
699 if (oi
->state
!= ISM_Down
)
701 /* Describe each link. */
704 case OSPF_IFTYPE_POINTOPOINT
:
705 links
+= lsa_link_ptop_set (s
, oi
);
707 case OSPF_IFTYPE_BROADCAST
:
708 links
+= lsa_link_broadcast_set (s
, oi
);
710 case OSPF_IFTYPE_NBMA
:
711 links
+= lsa_link_nbma_set (s
, oi
);
713 case OSPF_IFTYPE_POINTOMULTIPOINT
:
714 links
+= lsa_link_ptomp_set (s
, oi
);
716 case OSPF_IFTYPE_VIRTUALLINK
:
717 links
+= lsa_link_virtuallink_set (s
, oi
);
719 case OSPF_IFTYPE_LOOPBACK
:
720 links
+= lsa_link_loopback_set (s
, oi
);
729 /* Set router-LSA body. */
731 ospf_router_lsa_body_set (struct stream
*s
, struct ospf_area
*area
)
737 stream_putc (s
, router_lsa_flags (area
));
739 /* Set Zero fields. */
742 /* Keep pointer to # links. */
743 putp
= stream_get_endp(s
);
748 /* Set all link information. */
749 cnt
= router_lsa_link_set (s
, area
);
751 /* Set # of links here. */
752 stream_putw_at (s
, putp
, cnt
);
756 ospf_stub_router_timer (struct thread
*t
)
758 struct ospf_area
*area
= THREAD_ARG (t
);
760 area
->t_stub_router
= NULL
;
762 SET_FLAG (area
->stub_router_state
, OSPF_AREA_WAS_START_STUB_ROUTED
);
764 /* clear stub route state and generate router-lsa refresh, don't
765 * clobber an administratively set stub-router state though.
767 if (CHECK_FLAG (area
->stub_router_state
, OSPF_AREA_ADMIN_STUB_ROUTED
))
770 UNSET_FLAG (area
->stub_router_state
, OSPF_AREA_IS_STUB_ROUTED
);
772 ospf_router_lsa_timer_add (area
);
778 ospf_stub_router_check (struct ospf_area
*area
)
780 /* area must either be administratively configured to be stub
781 * or startup-time stub-router must be configured and we must in a pre-stub
784 if (CHECK_FLAG (area
->stub_router_state
, OSPF_AREA_ADMIN_STUB_ROUTED
))
786 SET_FLAG (area
->stub_router_state
, OSPF_AREA_IS_STUB_ROUTED
);
790 /* not admin-stubbed, check whether startup stubbing is configured and
791 * whether it's not been done yet
793 if (CHECK_FLAG (area
->stub_router_state
, OSPF_AREA_WAS_START_STUB_ROUTED
))
796 if (area
->ospf
->stub_router_startup_time
== OSPF_STUB_ROUTER_UNCONFIGURED
)
798 /* stub-router is hence done forever for this area, even if someone
799 * tries configure it (take effect next restart).
801 SET_FLAG (area
->stub_router_state
, OSPF_AREA_WAS_START_STUB_ROUTED
);
805 /* startup stub-router configured and not yet done */
806 SET_FLAG (area
->stub_router_state
, OSPF_AREA_IS_STUB_ROUTED
);
808 OSPF_AREA_TIMER_ON (area
->t_stub_router
, ospf_stub_router_timer
,
809 area
->ospf
->stub_router_startup_time
);
812 /* Create new router-LSA. */
813 static struct ospf_lsa
*
814 ospf_router_lsa_new (struct ospf_area
*area
)
816 struct ospf
*ospf
= area
->ospf
;
818 struct lsa_header
*lsah
;
819 struct ospf_lsa
*new;
822 if (IS_DEBUG_OSPF (lsa
, LSA_GENERATE
))
823 zlog_debug ("LSA[Type1]: Create router-LSA instance");
825 /* check whether stub-router is desired, and if this is the first
828 ospf_stub_router_check (area
);
830 /* Create a stream for LSA. */
831 s
= stream_new (OSPF_MAX_LSA_SIZE
);
832 /* Set LSA common header fields. */
833 lsa_header_set (s
, LSA_OPTIONS_GET (area
) | LSA_OPTIONS_NSSA_GET (area
),
834 OSPF_ROUTER_LSA
, ospf
->router_id
, ospf
->router_id
);
836 /* Set router-LSA body fields. */
837 ospf_router_lsa_body_set (s
, area
);
840 length
= stream_get_endp (s
);
841 lsah
= (struct lsa_header
*) STREAM_DATA (s
);
842 lsah
->length
= htons (length
);
844 /* Now, create OSPF LSA instance. */
845 if ( (new = ospf_lsa_new ()) == NULL
)
847 zlog_err ("%s: Unable to create new lsa", __func__
);
852 SET_FLAG (new->flags
, OSPF_LSA_SELF
);
854 /* Copy LSA data to store, discard stream. */
855 new->data
= ospf_lsa_data_new (length
);
856 memcpy (new->data
, lsah
, length
);
862 /* Originate Router-LSA. */
863 static struct ospf_lsa
*
864 ospf_router_lsa_originate (struct ospf_area
*area
)
866 struct ospf_lsa
*new;
868 /* Create new router-LSA instance. */
869 if ( (new = ospf_router_lsa_new (area
)) == NULL
)
871 zlog_err ("%s: ospf_router_lsa_new returned NULL", __func__
);
876 if (new->data
->adv_router
.s_addr
== 0)
878 if (IS_DEBUG_OSPF_EVENT
)
879 zlog_debug ("LSA[Type1]: AdvRouter is 0, discard");
880 ospf_lsa_discard (new);
884 /* Install LSA to LSDB. */
885 new = ospf_lsa_install (area
->ospf
, NULL
, new);
887 /* Update LSA origination count. */
888 area
->ospf
->lsa_originate_count
++;
890 /* Flooding new LSA through area. */
891 ospf_flood_through_area (area
, NULL
, new);
893 if (IS_DEBUG_OSPF (lsa
, LSA_GENERATE
))
895 zlog_debug ("LSA[Type%d:%s]: Originate router-LSA %p",
896 new->data
->type
, inet_ntoa (new->data
->id
), new);
897 ospf_lsa_header_dump (new->data
);
903 /* Refresh router-LSA. */
904 static struct ospf_lsa
*
905 ospf_router_lsa_refresh (struct ospf_lsa
*lsa
)
907 struct ospf_area
*area
= lsa
->area
;
908 struct ospf_lsa
*new;
913 /* Delete LSA from neighbor retransmit-list. */
914 ospf_ls_retransmit_delete_nbr_area (area
, lsa
);
916 /* Create new router-LSA instance. */
917 if ( (new = ospf_router_lsa_new (area
)) == NULL
)
919 zlog_err ("%s: ospf_router_lsa_new returned NULL", __func__
);
923 new->data
->ls_seqnum
= lsa_seqnum_increment (lsa
);
925 ospf_lsa_install (area
->ospf
, NULL
, new);
927 /* Flood LSA through area. */
928 ospf_flood_through_area (area
, NULL
, new);
931 if (IS_DEBUG_OSPF (lsa
, LSA_GENERATE
))
933 zlog_debug ("LSA[Type%d:%s]: router-LSA refresh",
934 new->data
->type
, inet_ntoa (new->data
->id
));
935 ospf_lsa_header_dump (new->data
);
942 ospf_router_lsa_timer (struct thread
*t
)
944 struct ospf_area
*area
;
946 if (IS_DEBUG_OSPF_EVENT
)
947 zlog_debug ("Timer[router-LSA]: (router-LSA Refresh expire)");
949 area
= THREAD_ARG (t
);
950 area
->t_router_lsa_self
= NULL
;
952 /* Now refresh router-LSA. */
953 if (area
->router_lsa_self
)
954 ospf_router_lsa_refresh (area
->router_lsa_self
);
955 /* Newly originate router-LSA. */
957 ospf_router_lsa_originate (area
);
963 ospf_router_lsa_timer_add (struct ospf_area
*area
)
965 /* Keep area's self-originated router-LSA. */
966 struct ospf_lsa
*lsa
= area
->router_lsa_self
;
968 /* Cancel previously scheduled router-LSA timer. */
969 if (area
->t_router_lsa_self
)
970 if (IS_DEBUG_OSPF (lsa
, LSA_GENERATE
))
971 zlog_debug ("LSA[Type1]: Cancel previous router-LSA timer");
973 OSPF_TIMER_OFF (area
->t_router_lsa_self
);
975 /* If router-LSA is originated previously, check the interval time. */
979 if ((delay
= ospf_lsa_refresh_delay (lsa
)) > 0)
981 OSPF_AREA_TIMER_ON (area
->t_router_lsa_self
,
982 ospf_router_lsa_timer
, delay
);
987 if (IS_DEBUG_OSPF (lsa
, LSA_GENERATE
))
988 zlog_debug ("LSA[Type1]: Scheduling router-LSA origination right away");
990 /* Immediately refresh router-LSA. */
991 OSPF_AREA_TIMER_ON (area
->t_router_lsa_self
, ospf_router_lsa_timer
, 0);
995 ospf_router_lsa_update_timer (struct thread
*thread
)
997 struct ospf
*ospf
= THREAD_ARG (thread
);
998 struct listnode
*node
, *nnode
;
999 struct ospf_area
*area
;
1001 if (IS_DEBUG_OSPF (lsa
, LSA_GENERATE
))
1002 zlog_debug ("Timer[router-LSA Update]: (timer expire)");
1004 ospf
->t_router_lsa_update
= NULL
;
1006 for (ALL_LIST_ELEMENTS (ospf
->areas
, node
, nnode
, area
))
1008 struct ospf_lsa
*lsa
= area
->router_lsa_self
;
1009 struct router_lsa
*rl
;
1010 const char *area_str
;
1012 /* Keep Area ID string. */
1013 area_str
= AREA_NAME (area
);
1015 /* If LSA not exist in this Area, originate new. */
1018 if (IS_DEBUG_OSPF (lsa
, LSA_GENERATE
))
1019 zlog_debug("LSA[Type1]: Create router-LSA for Area %s", area_str
);
1021 ospf_router_lsa_originate (area
);
1023 /* If router-ID is changed, Link ID must change.
1024 First flush old LSA, then originate new. */
1025 else if (!IPV4_ADDR_SAME (&lsa
->data
->id
, &ospf
->router_id
))
1027 if (IS_DEBUG_OSPF (lsa
, LSA_GENERATE
))
1028 zlog_debug("LSA[Type%d:%s]: Refresh router-LSA for Area %s",
1029 lsa
->data
->type
, inet_ntoa (lsa
->data
->id
), area_str
);
1030 ospf_lsa_flush_area (lsa
, area
);
1031 ospf_lsa_unlock (&area
->router_lsa_self
);
1032 area
->router_lsa_self
= NULL
;
1034 /* Refresh router-LSA, (not install) and flood through area. */
1035 ospf_router_lsa_timer_add (area
);
1039 rl
= (struct router_lsa
*) lsa
->data
;
1040 /* Refresh router-LSA, (not install) and flood through area. */
1041 if (rl
->flags
!= ospf
->flags
)
1042 ospf_router_lsa_timer_add (area
);
1050 /* network-LSA related functions. */
1051 /* Originate Network-LSA. */
1053 ospf_network_lsa_body_set (struct stream
*s
, struct ospf_interface
*oi
)
1055 struct in_addr mask
;
1056 struct route_node
*rn
;
1057 struct ospf_neighbor
*nbr
;
1059 masklen2ip (oi
->address
->prefixlen
, &mask
);
1060 stream_put_ipv4 (s
, mask
.s_addr
);
1062 /* The network-LSA lists those routers that are fully adjacent to
1063 the Designated Router; each fully adjacent router is identified by
1064 its OSPF Router ID. The Designated Router includes itself in this
1065 list. RFC2328, Section 12.4.2 */
1067 for (rn
= route_top (oi
->nbrs
); rn
; rn
= route_next (rn
))
1068 if ((nbr
= rn
->info
) != NULL
)
1069 if (nbr
->state
== NSM_Full
|| nbr
== oi
->nbr_self
)
1070 stream_put_ipv4 (s
, nbr
->router_id
.s_addr
);
1073 static struct ospf_lsa
*
1074 ospf_network_lsa_new (struct ospf_interface
*oi
)
1077 struct ospf_lsa
*new;
1078 struct lsa_header
*lsah
;
1081 /* If there are no neighbours on this network (the net is stub),
1082 the router does not originate network-LSA (see RFC 12.4.2) */
1083 if (oi
->full_nbrs
== 0)
1086 if (IS_DEBUG_OSPF (lsa
, LSA_GENERATE
))
1087 zlog_debug ("LSA[Type2]: Create network-LSA instance");
1089 /* Create new stream for LSA. */
1090 s
= stream_new (OSPF_MAX_LSA_SIZE
);
1091 lsah
= (struct lsa_header
*) STREAM_DATA (s
);
1093 lsa_header_set (s
, (OPTIONS (oi
) | LSA_OPTIONS_GET (oi
->area
)),
1094 OSPF_NETWORK_LSA
, DR (oi
), oi
->ospf
->router_id
);
1096 /* Set network-LSA body fields. */
1097 ospf_network_lsa_body_set (s
, oi
);
1100 length
= stream_get_endp (s
);
1101 lsah
->length
= htons (length
);
1103 /* Create OSPF LSA instance. */
1104 if ( (new = ospf_lsa_new ()) == NULL
)
1106 zlog_err ("%s: ospf_lsa_new returned NULL", __func__
);
1110 new->area
= oi
->area
;
1111 SET_FLAG (new->flags
, OSPF_LSA_SELF
);
1113 /* Copy LSA to store. */
1114 new->data
= ospf_lsa_data_new (length
);
1115 memcpy (new->data
, lsah
, length
);
1121 /* Originate network-LSA. */
1122 static struct ospf_lsa
*
1123 ospf_network_lsa_originate (struct ospf_interface
*oi
)
1125 struct ospf_lsa
*new;
1127 /* Create new network-LSA instance. */
1128 new = ospf_network_lsa_new (oi
);
1132 /* Install LSA to LSDB. */
1133 new = ospf_lsa_install (oi
->ospf
, oi
, new);
1135 /* Update LSA origination count. */
1136 oi
->ospf
->lsa_originate_count
++;
1138 /* Flooding new LSA through area. */
1139 ospf_flood_through_area (oi
->area
, NULL
, new);
1141 if (IS_DEBUG_OSPF (lsa
, LSA_GENERATE
))
1143 zlog_debug ("LSA[Type%d:%s]: Originate network-LSA %p",
1144 new->data
->type
, inet_ntoa (new->data
->id
), new);
1145 ospf_lsa_header_dump (new->data
);
1152 ospf_network_lsa_refresh (struct ospf_lsa
*lsa
, struct ospf_interface
*oi
)
1154 struct ospf_area
*area
= lsa
->area
;
1155 struct ospf_lsa
*new;
1159 /* Delete LSA from neighbor retransmit-list. */
1160 ospf_ls_retransmit_delete_nbr_area (area
, lsa
);
1162 /* Create new network-LSA instance. */
1163 new = ospf_network_lsa_new (oi
);
1166 new->data
->ls_seqnum
= lsa_seqnum_increment (lsa
);
1168 ospf_lsa_install (area
->ospf
, oi
, new);
1170 /* Flood LSA through aera. */
1171 ospf_flood_through_area (area
, NULL
, new);
1173 if (IS_DEBUG_OSPF (lsa
, LSA_GENERATE
))
1175 zlog_debug ("LSA[Type%d:%s]: network-LSA refresh",
1176 new->data
->type
, inet_ntoa (new->data
->id
));
1177 ospf_lsa_header_dump (new->data
);
1184 ospf_network_lsa_refresh_timer (struct thread
*t
)
1186 struct ospf_interface
*oi
;
1188 oi
= THREAD_ARG (t
);
1189 oi
->t_network_lsa_self
= NULL
;
1191 if (oi
->network_lsa_self
)
1192 /* Now refresh network-LSA. */
1193 ospf_network_lsa_refresh (oi
->network_lsa_self
, oi
);
1195 /* Newly create network-LSA. */
1196 ospf_network_lsa_originate (oi
);
1202 ospf_network_lsa_timer_add (struct ospf_interface
*oi
)
1204 /* Keep interface's self-originated network-LSA. */
1205 struct ospf_lsa
*lsa
= oi
->network_lsa_self
;
1207 /* Cancel previously schedules network-LSA timer. */
1208 if (oi
->t_network_lsa_self
)
1209 if (IS_DEBUG_OSPF (lsa
, LSA_GENERATE
))
1210 zlog_debug ("LSA[Type2]: Cancel previous network-LSA timer");
1211 OSPF_TIMER_OFF (oi
->t_network_lsa_self
);
1213 /* If network-LSA is originated previously, check the interval time. */
1217 if ((delay
= ospf_lsa_refresh_delay (lsa
)) > 0)
1219 oi
->t_network_lsa_self
=
1220 thread_add_timer (master
, ospf_network_lsa_refresh_timer
,
1226 if (IS_DEBUG_OSPF (lsa
, LSA_GENERATE
))
1227 zlog_debug ("Scheduling network-LSA origination right away");
1229 /* Immediately refresh network-LSA. */
1230 oi
->t_network_lsa_self
=
1231 thread_add_event (master
, ospf_network_lsa_refresh_timer
, oi
, 0);
1236 stream_put_ospf_metric (struct stream
*s
, u_int32_t metric_value
)
1241 /* Put 0 metric. TOS metric is not supported. */
1242 metric
= htonl (metric_value
);
1243 mp
= (char *) &metric
;
1245 stream_put (s
, mp
, 3);
1248 /* summary-LSA related functions. */
1250 ospf_summary_lsa_body_set (struct stream
*s
, struct prefix
*p
,
1253 struct in_addr mask
;
1255 masklen2ip (p
->prefixlen
, &mask
);
1257 /* Put Network Mask. */
1258 stream_put_ipv4 (s
, mask
.s_addr
);
1261 stream_putc (s
, (u_char
) 0);
1264 stream_put_ospf_metric (s
, metric
);
1267 static struct ospf_lsa
*
1268 ospf_summary_lsa_new (struct ospf_area
*area
, struct prefix
*p
,
1269 u_int32_t metric
, struct in_addr id
)
1272 struct ospf_lsa
*new;
1273 struct lsa_header
*lsah
;
1276 if (id
.s_addr
== 0xffffffff)
1278 /* Maybe Link State ID not available. */
1279 if (IS_DEBUG_OSPF (lsa
, LSA_GENERATE
))
1280 zlog_debug ("LSA[Type%d]: Link ID not available, can't originate",
1285 if (IS_DEBUG_OSPF (lsa
, LSA_GENERATE
))
1286 zlog_debug ("LSA[Type3]: Create summary-LSA instance");
1288 /* Create new stream for LSA. */
1289 s
= stream_new (OSPF_MAX_LSA_SIZE
);
1290 lsah
= (struct lsa_header
*) STREAM_DATA (s
);
1292 lsa_header_set (s
, LSA_OPTIONS_GET (area
), OSPF_SUMMARY_LSA
,
1293 id
, area
->ospf
->router_id
);
1295 /* Set summary-LSA body fields. */
1296 ospf_summary_lsa_body_set (s
, p
, metric
);
1299 length
= stream_get_endp (s
);
1300 lsah
->length
= htons (length
);
1302 /* Create OSPF LSA instance. */
1303 new = ospf_lsa_new ();
1305 SET_FLAG (new->flags
, OSPF_LSA_SELF
);
1307 /* Copy LSA to store. */
1308 new->data
= ospf_lsa_data_new (length
);
1309 memcpy (new->data
, lsah
, length
);
1315 /* Originate Summary-LSA. */
1317 ospf_summary_lsa_originate (struct prefix_ipv4
*p
, u_int32_t metric
,
1318 struct ospf_area
*area
)
1320 struct ospf_lsa
*new;
1323 id
= ospf_lsa_unique_id (area
->ospf
, area
->lsdb
, OSPF_SUMMARY_LSA
, p
);
1325 if (id
.s_addr
== 0xffffffff)
1327 /* Maybe Link State ID not available. */
1328 if (IS_DEBUG_OSPF (lsa
, LSA_GENERATE
))
1329 zlog_debug ("LSA[Type%d]: Link ID not available, can't originate",
1334 /* Create new summary-LSA instance. */
1335 if ( !(new = ospf_summary_lsa_new (area
, (struct prefix
*) p
, metric
, id
)))
1338 /* Instlal LSA to LSDB. */
1339 new = ospf_lsa_install (area
->ospf
, NULL
, new);
1341 /* Update LSA origination count. */
1342 area
->ospf
->lsa_originate_count
++;
1344 /* Flooding new LSA through area. */
1345 ospf_flood_through_area (area
, NULL
, new);
1347 if (IS_DEBUG_OSPF (lsa
, LSA_GENERATE
))
1349 zlog_debug ("LSA[Type%d:%s]: Originate summary-LSA %p",
1350 new->data
->type
, inet_ntoa (new->data
->id
), new);
1351 ospf_lsa_header_dump (new->data
);
1358 ospf_summary_lsa_refresh (struct ospf
*ospf
, struct ospf_lsa
*lsa
)
1360 struct ospf_lsa
*new;
1361 struct summary_lsa
*sl
;
1367 sl
= (struct summary_lsa
*)lsa
->data
;
1368 p
.prefixlen
= ip_masklen (sl
->mask
);
1369 new = ospf_summary_lsa_new (lsa
->area
, &p
, GET_METRIC (sl
->metric
),
1375 new->data
->ls_seqnum
= lsa_seqnum_increment (lsa
);
1377 /* Re-calculate checksum. */
1378 ospf_lsa_checksum (new->data
);
1380 ospf_lsa_install (ospf
, NULL
, new);
1382 /* Flood LSA through AS. */
1383 ospf_flood_through_area (new->area
, NULL
, new);
1385 /* Debug logging. */
1386 if (IS_DEBUG_OSPF (lsa
, LSA_GENERATE
))
1388 zlog_debug ("LSA[Type%d:%s]: summary-LSA refresh",
1389 new->data
->type
, inet_ntoa (new->data
->id
));
1390 ospf_lsa_header_dump (new->data
);
1397 /* summary-ASBR-LSA related functions. */
1399 ospf_summary_asbr_lsa_body_set (struct stream
*s
, struct prefix
*p
,
1402 struct in_addr mask
;
1404 masklen2ip (p
->prefixlen
, &mask
);
1406 /* Put Network Mask. */
1407 stream_put_ipv4 (s
, mask
.s_addr
);
1410 stream_putc (s
, (u_char
) 0);
1413 stream_put_ospf_metric (s
, metric
);
1416 static struct ospf_lsa
*
1417 ospf_summary_asbr_lsa_new (struct ospf_area
*area
, struct prefix
*p
,
1418 u_int32_t metric
, struct in_addr id
)
1421 struct ospf_lsa
*new;
1422 struct lsa_header
*lsah
;
1425 if (id
.s_addr
== 0xffffffff)
1427 /* Maybe Link State ID not available. */
1428 if (IS_DEBUG_OSPF (lsa
, LSA_GENERATE
))
1429 zlog_debug ("LSA[Type%d]: Link ID not available, can't originate",
1430 OSPF_ASBR_SUMMARY_LSA
);
1434 if (IS_DEBUG_OSPF (lsa
, LSA_GENERATE
))
1435 zlog_debug ("LSA[Type3]: Create summary-LSA instance");
1437 /* Create new stream for LSA. */
1438 s
= stream_new (OSPF_MAX_LSA_SIZE
);
1439 lsah
= (struct lsa_header
*) STREAM_DATA (s
);
1441 lsa_header_set (s
, LSA_OPTIONS_GET (area
), OSPF_ASBR_SUMMARY_LSA
,
1442 id
, area
->ospf
->router_id
);
1444 /* Set summary-LSA body fields. */
1445 ospf_summary_asbr_lsa_body_set (s
, p
, metric
);
1448 length
= stream_get_endp (s
);
1449 lsah
->length
= htons (length
);
1451 /* Create OSPF LSA instance. */
1452 new = ospf_lsa_new ();
1454 SET_FLAG (new->flags
, OSPF_LSA_SELF
);
1456 /* Copy LSA to store. */
1457 new->data
= ospf_lsa_data_new (length
);
1458 memcpy (new->data
, lsah
, length
);
1464 /* Originate summary-ASBR-LSA. */
1466 ospf_summary_asbr_lsa_originate (struct prefix_ipv4
*p
, u_int32_t metric
,
1467 struct ospf_area
*area
)
1469 struct ospf_lsa
*new;
1472 id
= ospf_lsa_unique_id (area
->ospf
, area
->lsdb
, OSPF_ASBR_SUMMARY_LSA
, p
);
1474 if (id
.s_addr
== 0xffffffff)
1476 /* Maybe Link State ID not available. */
1477 if (IS_DEBUG_OSPF (lsa
, LSA_GENERATE
))
1478 zlog_debug ("LSA[Type%d]: Link ID not available, can't originate",
1479 OSPF_ASBR_SUMMARY_LSA
);
1483 /* Create new summary-LSA instance. */
1484 new = ospf_summary_asbr_lsa_new (area
, (struct prefix
*) p
, metric
, id
);
1488 /* Install LSA to LSDB. */
1489 new = ospf_lsa_install (area
->ospf
, NULL
, new);
1491 /* Update LSA origination count. */
1492 area
->ospf
->lsa_originate_count
++;
1494 /* Flooding new LSA through area. */
1495 ospf_flood_through_area (area
, NULL
, new);
1497 if (IS_DEBUG_OSPF (lsa
, LSA_GENERATE
))
1499 zlog_debug ("LSA[Type%d:%s]: Originate summary-ASBR-LSA %p",
1500 new->data
->type
, inet_ntoa (new->data
->id
), new);
1501 ospf_lsa_header_dump (new->data
);
1508 ospf_summary_asbr_lsa_refresh (struct ospf
*ospf
, struct ospf_lsa
*lsa
)
1510 struct ospf_lsa
*new;
1511 struct summary_lsa
*sl
;
1517 sl
= (struct summary_lsa
*)lsa
->data
;
1518 p
.prefixlen
= ip_masklen (sl
->mask
);
1519 new = ospf_summary_asbr_lsa_new (lsa
->area
, &p
, GET_METRIC (sl
->metric
),
1524 new->data
->ls_seqnum
= lsa_seqnum_increment (lsa
);
1526 /* Re-calculate checksum. */
1527 ospf_lsa_checksum (new->data
);
1529 ospf_lsa_install (ospf
, NULL
, new);
1531 /* Flood LSA through area. */
1532 ospf_flood_through_area (new->area
, NULL
, new);
1534 if (IS_DEBUG_OSPF (lsa
, LSA_GENERATE
))
1536 zlog_debug ("LSA[Type%d:%s]: summary-ASBR-LSA refresh",
1537 new->data
->type
, inet_ntoa (new->data
->id
));
1538 ospf_lsa_header_dump (new->data
);
1544 /* AS-external-LSA related functions. */
1546 /* Get nexthop for AS-external-LSAs. Return nexthop if its interface
1547 is connected, else 0*/
1548 static struct in_addr
1549 ospf_external_lsa_nexthop_get (struct ospf
*ospf
, struct in_addr nexthop
)
1553 struct listnode
*node
;
1554 struct ospf_interface
*oi
;
1558 if (!nexthop
.s_addr
)
1561 /* Check whether nexthop is covered by OSPF network. */
1562 nh
.family
= AF_INET
;
1563 nh
.u
.prefix4
= nexthop
;
1564 nh
.prefixlen
= IPV4_MAX_BITLEN
;
1566 for (ALL_LIST_ELEMENTS_RO (ospf
->oiflist
, node
, oi
))
1567 if (if_is_operative (oi
->ifp
))
1568 if (oi
->address
->family
== AF_INET
)
1569 if (prefix_match (oi
->address
, &nh
))
1575 /* NSSA-external-LSA related functions. */
1577 /* Get 1st IP connection for Forward Addr */
1580 ospf_get_ip_from_ifp (struct ospf_interface
*oi
)
1586 if (if_is_operative (oi
->ifp
))
1587 return oi
->address
->u
.prefix4
;
1592 /* Get 1st IP connection for Forward Addr */
1594 ospf_get_nssa_ip (struct ospf_area
*area
)
1597 struct in_addr best_default
;
1598 struct listnode
*node
;
1599 struct ospf_interface
*oi
;
1602 best_default
.s_addr
= 0;
1604 for (ALL_LIST_ELEMENTS_RO (area
->ospf
->oiflist
, node
, oi
))
1606 if (if_is_operative (oi
->ifp
))
1607 if (oi
->area
->external_routing
== OSPF_AREA_NSSA
)
1608 if (oi
->address
&& oi
->address
->family
== AF_INET
)
1610 if (best_default
.s_addr
== 0)
1611 best_default
= oi
->address
->u
.prefix4
;
1612 if (oi
->area
== area
)
1613 return oi
->address
->u
.prefix4
;
1616 if (best_default
.s_addr
!= 0)
1617 return best_default
;
1619 if (best_default
.s_addr
!= 0)
1620 return best_default
;
1625 #define DEFAULT_DEFAULT_METRIC 20
1626 #define DEFAULT_DEFAULT_ORIGINATE_METRIC 10
1627 #define DEFAULT_DEFAULT_ALWAYS_METRIC 1
1629 #define DEFAULT_METRIC_TYPE EXTERNAL_METRIC_TYPE_2
1632 metric_type (struct ospf
*ospf
, u_char src
)
1634 return (ospf
->dmetric
[src
].type
< 0 ?
1635 DEFAULT_METRIC_TYPE
: ospf
->dmetric
[src
].type
);
1639 metric_value (struct ospf
*ospf
, u_char src
)
1641 if (ospf
->dmetric
[src
].value
< 0)
1643 if (src
== DEFAULT_ROUTE
)
1645 if (ospf
->default_originate
== DEFAULT_ORIGINATE_ZEBRA
)
1646 return DEFAULT_DEFAULT_ORIGINATE_METRIC
;
1648 return DEFAULT_DEFAULT_ALWAYS_METRIC
;
1650 else if (ospf
->default_metric
< 0)
1651 return DEFAULT_DEFAULT_METRIC
;
1653 return ospf
->default_metric
;
1656 return ospf
->dmetric
[src
].value
;
1659 /* Set AS-external-LSA body. */
1661 ospf_external_lsa_body_set (struct stream
*s
, struct external_info
*ei
,
1664 struct prefix_ipv4
*p
= &ei
->p
;
1665 struct in_addr mask
, fwd_addr
;
1670 /* Put Network Mask. */
1671 masklen2ip (p
->prefixlen
, &mask
);
1672 stream_put_ipv4 (s
, mask
.s_addr
);
1674 /* If prefix is default, specify DEFAULT_ROUTE. */
1675 type
= is_prefix_default (&ei
->p
) ? DEFAULT_ROUTE
: ei
->type
;
1677 mtype
= (ROUTEMAP_METRIC_TYPE (ei
) != -1) ?
1678 ROUTEMAP_METRIC_TYPE (ei
) : metric_type (ospf
, type
);
1680 mvalue
= (ROUTEMAP_METRIC (ei
) != -1) ?
1681 ROUTEMAP_METRIC (ei
) : metric_value (ospf
, type
);
1683 /* Put type of external metric. */
1684 stream_putc (s
, (mtype
== EXTERNAL_METRIC_TYPE_2
? 0x80 : 0));
1686 /* Put 0 metric. TOS metric is not supported. */
1687 stream_put_ospf_metric (s
, mvalue
);
1689 /* Get forwarding address to nexthop if on the Connection List, else 0. */
1690 fwd_addr
= ospf_external_lsa_nexthop_get (ospf
, ei
->nexthop
);
1692 /* Put forwarding address. */
1693 stream_put_ipv4 (s
, fwd_addr
.s_addr
);
1695 /* Put route tag -- This value should be introduced from configuration. */
1699 /* Create new external-LSA. */
1700 static struct ospf_lsa
*
1701 ospf_external_lsa_new (struct ospf
*ospf
,
1702 struct external_info
*ei
, struct in_addr
*old_id
)
1705 struct lsa_header
*lsah
;
1706 struct ospf_lsa
*new;
1712 if (IS_DEBUG_OSPF (lsa
, LSA_GENERATE
))
1713 zlog_debug ("LSA[Type5]: External info is NULL, could not originated");
1717 if (IS_DEBUG_OSPF (lsa
, LSA_GENERATE
))
1718 zlog_debug ("LSA[Type5]: Originate AS-external-LSA instance");
1720 /* If old Link State ID is specified, refresh LSA with same ID. */
1723 /* Get Link State with unique ID. */
1726 id
= ospf_lsa_unique_id (ospf
, ospf
->lsdb
, OSPF_AS_EXTERNAL_LSA
, &ei
->p
);
1727 if (id
.s_addr
== 0xffffffff)
1729 /* Maybe Link State ID not available. */
1730 if (IS_DEBUG_OSPF (lsa
, LSA_GENERATE
))
1731 zlog_debug ("LSA[Type5]: Link ID not available, can't originate");
1736 /* Create new stream for LSA. */
1737 s
= stream_new (OSPF_MAX_LSA_SIZE
);
1738 lsah
= (struct lsa_header
*) STREAM_DATA (s
);
1740 /* Set LSA common header fields. */
1741 lsa_header_set (s
, OSPF_OPTION_E
, OSPF_AS_EXTERNAL_LSA
,
1742 id
, ospf
->router_id
);
1744 /* Set AS-external-LSA body fields. */
1745 ospf_external_lsa_body_set (s
, ei
, ospf
);
1748 length
= stream_get_endp (s
);
1749 lsah
->length
= htons (length
);
1751 /* Now, create OSPF LSA instance. */
1752 new = ospf_lsa_new ();
1754 SET_FLAG (new->flags
, OSPF_LSA_SELF
|OSPF_LSA_APPROVED
);
1756 /* Copy LSA data to store, discard stream. */
1757 new->data
= ospf_lsa_data_new (length
);
1758 memcpy (new->data
, lsah
, length
);
1766 ospf_install_flood_nssa (struct ospf
*ospf
,
1767 struct ospf_lsa
*lsa
, struct external_info
*ei
)
1769 struct ospf_lsa
*new;
1770 struct as_external_lsa
*extlsa
;
1771 struct ospf_area
*area
;
1772 struct listnode
*node
, *nnode
;
1774 /* LSA may be a Type-5 originated via translation of a Type-7 LSA
1775 * which originated from an NSSA area. In which case it should not be
1776 * flooded back to NSSA areas.
1778 if (CHECK_FLAG (lsa
->flags
, OSPF_LSA_LOCAL_XLT
))
1781 /* NSSA Originate or Refresh (If anyNSSA)
1783 LSA is self-originated. And just installed as Type-5.
1784 Additionally, install as Type-7 LSDB for every attached NSSA.
1786 P-Bit controls which ABR performs translation to outside world; If
1787 we are an ABR....do not set the P-bit, because we send the Type-5,
1788 not as the ABR Translator, but as the ASBR owner within the AS!
1790 If we are NOT ABR, Flood through NSSA as Type-7 w/P-bit set. The
1791 elected ABR Translator will see the P-bit, Translate, and re-flood.
1793 Later, ABR_TASK and P-bit will scan Type-7 LSDB and translate to
1794 Type-5's to non-NSSA Areas. (it will also attempt a re-install) */
1796 for (ALL_LIST_ELEMENTS (ospf
->areas
, node
, nnode
, area
))
1798 /* Don't install Type-7 LSA's into nonNSSA area */
1799 if (area
->external_routing
!= OSPF_AREA_NSSA
)
1802 /* make lsa duplicate, lock=1 */
1803 new = ospf_lsa_dup (lsa
);
1805 new->data
->type
= OSPF_AS_NSSA_LSA
;
1807 /* set P-bit if not ABR */
1808 if (! IS_OSPF_ABR (ospf
))
1810 SET_FLAG(new->data
->options
, OSPF_OPTION_NP
);
1812 /* set non-zero FWD ADDR
1814 draft-ietf-ospf-nssa-update-09.txt
1816 if the network between the NSSA AS boundary router and the
1817 adjacent AS is advertised into OSPF as an internal OSPF route,
1818 the forwarding address should be the next op address as is cu
1819 currently done with type-5 LSAs. If the intervening network is
1820 not adversited into OSPF as an internal OSPF route and the
1821 type-7 LSA's P-bit is set a forwarding address should be
1822 selected from one of the router's active OSPF inteface addresses
1823 which belong to the NSSA. If no such addresses exist, then
1824 no type-7 LSA's with the P-bit set should originate from this
1827 /* kevinm: not updating lsa anymore, just new */
1828 extlsa
= (struct as_external_lsa
*)(new->data
);
1830 if (extlsa
->e
[0].fwd_addr
.s_addr
== 0)
1831 extlsa
->e
[0].fwd_addr
= ospf_get_nssa_ip(area
); /* this NSSA area in ifp */
1833 if (extlsa
->e
[0].fwd_addr
.s_addr
== 0)
1835 if (IS_DEBUG_OSPF_NSSA
)
1836 zlog_debug ("LSA[Type-7]: Could not build FWD-ADDR");
1837 ospf_lsa_discard (new);
1841 /* Re-calculate checksum. */
1842 ospf_lsa_checksum (new->data
);
1844 /* install also as Type-7 */
1845 ospf_lsa_install (ospf
, NULL
, new); /* Remove Old, Lock New = 2 */
1847 /* will send each copy, lock=2+n */
1848 ospf_flood_through_as (ospf
, NULL
, new); /* all attached NSSA's, no AS/STUBs */
1852 static struct ospf_lsa
*
1853 ospf_lsa_translated_nssa_new (struct ospf
*ospf
,
1854 struct ospf_lsa
*type7
)
1857 struct ospf_lsa
*new;
1858 struct as_external_lsa
*ext
, *extnew
;
1859 struct external_info ei
;
1861 ext
= (struct as_external_lsa
*)(type7
->data
);
1863 /* need external_info struct, fill in bare minimum */
1864 ei
.p
.family
= AF_INET
;
1865 ei
.p
.prefix
= type7
->data
->id
;
1866 ei
.p
.prefixlen
= ip_masklen (ext
->mask
);
1867 ei
.type
= ZEBRA_ROUTE_OSPF
;
1868 ei
.nexthop
= ext
->header
.adv_router
;
1869 ei
.route_map_set
.metric
= -1;
1870 ei
.route_map_set
.metric_type
= -1;
1873 if ( (new = ospf_external_lsa_new (ospf
, &ei
, &type7
->data
->id
)) == NULL
)
1875 if (IS_DEBUG_OSPF_NSSA
)
1876 zlog_debug ("ospf_nssa_translate_originate(): Could not originate "
1877 "Translated Type-5 for %s",
1878 inet_ntoa (ei
.p
.prefix
));
1882 extnew
= (struct as_external_lsa
*)(new->data
);
1884 /* copy over Type-7 data to new */
1885 extnew
->e
[0].tos
= ext
->e
[0].tos
;
1886 extnew
->e
[0].route_tag
= ext
->e
[0].route_tag
;
1887 extnew
->e
[0].fwd_addr
.s_addr
= ext
->e
[0].fwd_addr
.s_addr
;
1888 new->data
->ls_seqnum
= type7
->data
->ls_seqnum
;
1890 /* add translated flag, checksum and lock new lsa */
1891 SET_FLAG (new->flags
, OSPF_LSA_LOCAL_XLT
); /* Translated from 7 */
1892 ospf_lsa_checksum (new->data
);
1893 new = ospf_lsa_lock (new);
1898 /* compare type-5 to type-7
1899 * -1: err, 0: same, 1: different
1902 ospf_lsa_translated_nssa_compare (struct ospf_lsa
*t7
, struct ospf_lsa
*t5
)
1905 struct as_external_lsa
*e5
= (struct as_external_lsa
*)t5
,
1906 *e7
= (struct as_external_lsa
*)t7
;
1910 if (! ((t5
->data
->type
== OSPF_AS_EXTERNAL_LSA
)
1911 && (t7
->data
->type
== OSPF_AS_NSSA_LSA
)))
1914 if (t5
->data
->id
.s_addr
!= t7
->data
->id
.s_addr
)
1917 if (t5
->data
->ls_seqnum
!= t7
->data
->ls_seqnum
)
1918 return LSA_REFRESH_FORCE
;
1920 if (e5
->mask
.s_addr
!= e7
->mask
.s_addr
)
1921 return LSA_REFRESH_FORCE
;
1923 if (e5
->e
[0].fwd_addr
.s_addr
!= e7
->e
[0].fwd_addr
.s_addr
)
1924 return LSA_REFRESH_FORCE
;
1926 if (e5
->e
[0].route_tag
!= e7
->e
[0].route_tag
)
1927 return LSA_REFRESH_FORCE
;
1929 if (GET_METRIC (e5
->e
[0].metric
) != GET_METRIC (e7
->e
[0].metric
))
1930 return LSA_REFRESH_FORCE
;
1932 return LSA_REFRESH_IF_CHANGED
;
1935 /* Originate Translated Type-5 for supplied Type-7 NSSA LSA */
1937 ospf_translated_nssa_originate (struct ospf
*ospf
, struct ospf_lsa
*type7
)
1939 struct ospf_lsa
*new;
1940 struct as_external_lsa
*extnew
;
1942 /* we cant use ospf_external_lsa_originate() as we need to set
1943 * the OSPF_LSA_LOCAL_XLT flag, must originate by hand
1946 if ( (new = ospf_lsa_translated_nssa_new (ospf
, type7
)) == NULL
)
1948 if (IS_DEBUG_OSPF_NSSA
)
1949 zlog_debug ("ospf_translated_nssa_originate(): Could not translate "
1950 "Type-7, Id %s, to Type-5",
1951 inet_ntoa (type7
->data
->id
));
1955 extnew
= (struct as_external_lsa
*)new;
1957 if (IS_DEBUG_OSPF_NSSA
)
1959 zlog_debug ("ospf_translated_nssa_originate(): "
1960 "translated Type 7, installed:");
1961 ospf_lsa_header_dump (new->data
);
1962 zlog_debug (" Network mask: %d",ip_masklen (extnew
->mask
));
1963 zlog_debug (" Forward addr: %s", inet_ntoa (extnew
->e
[0].fwd_addr
));
1966 if ( (new = ospf_lsa_install (ospf
, NULL
, new)) == NULL
)
1968 if (IS_DEBUG_OSPF_NSSA
);
1969 zlog_debug ("ospf_lsa_translated_nssa_originate(): "
1970 "Could not install LSA "
1971 "id %s", inet_ntoa (type7
->data
->id
));
1975 ospf
->lsa_originate_count
++;
1976 ospf_flood_through_as (ospf
, NULL
, new);
1981 /* Refresh Translated from NSSA AS-external-LSA. */
1983 ospf_translated_nssa_refresh (struct ospf
*ospf
, struct ospf_lsa
*type7
,
1984 struct ospf_lsa
*type5
)
1986 struct ospf_lsa
*new = NULL
;
1988 /* Sanity checks. */
1989 assert (type7
|| type5
);
1990 if (!(type7
|| type5
))
1993 assert (type7
->data
);
1995 assert (type5
->data
);
1996 assert (ospf
->anyNSSA
);
1998 /* get required data according to what has been given */
1999 if (type7
&& type5
== NULL
)
2001 /* find the translated Type-5 for this Type-7 */
2002 struct as_external_lsa
*ext
= (struct as_external_lsa
*)(type7
->data
);
2003 struct prefix_ipv4 p
=
2005 .prefix
= type7
->data
->id
,
2006 .prefixlen
= ip_masklen (ext
->mask
),
2010 type5
= ospf_external_info_find_lsa (ospf
, &p
);
2012 else if (type5
&& type7
== NULL
)
2014 /* find the type-7 from which supplied type-5 was translated,
2015 * ie find first type-7 with same LSA Id.
2017 struct listnode
*ln
, *lnn
;
2018 struct route_node
*rn
;
2019 struct ospf_lsa
*lsa
;
2020 struct ospf_area
*area
;
2022 for (ALL_LIST_ELEMENTS (ospf
->areas
, ln
, lnn
, area
))
2024 if (area
->external_routing
!= OSPF_AREA_NSSA
2028 LSDB_LOOP (NSSA_LSDB(area
), rn
, lsa
)
2030 if (lsa
->data
->id
.s_addr
== type5
->data
->id
.s_addr
)
2039 /* do we have type7? */
2042 if (IS_DEBUG_OSPF_NSSA
)
2043 zlog_debug ("ospf_translated_nssa_refresh(): no Type-7 found for "
2045 inet_ntoa (type5
->data
->id
));
2049 /* do we have valid translated type5? */
2050 if (type5
== NULL
|| !CHECK_FLAG (type5
->flags
, OSPF_LSA_LOCAL_XLT
) )
2052 if (IS_DEBUG_OSPF_NSSA
)
2053 zlog_debug ("ospf_translated_nssa_refresh(): No translated Type-5 "
2054 "found for Type-7 with Id %s",
2055 inet_ntoa (type7
->data
->id
));
2059 /* Delete LSA from neighbor retransmit-list. */
2060 ospf_ls_retransmit_delete_nbr_as (ospf
, type5
);
2062 /* create new translated LSA */
2063 if ( (new = ospf_lsa_translated_nssa_new (ospf
, type7
)) == NULL
)
2065 if (IS_DEBUG_OSPF_NSSA
)
2066 zlog_debug ("ospf_translated_nssa_refresh(): Could not translate "
2067 "Type-7 for %s to Type-5",
2068 inet_ntoa (type7
->data
->id
));
2072 if ( !(new = ospf_lsa_install (ospf
, NULL
, new)) )
2074 if (IS_DEBUG_OSPF_NSSA
)
2075 zlog_debug ("ospf_translated_nssa_refresh(): Could not install "
2076 "translated LSA, Id %s",
2077 inet_ntoa (type7
->data
->id
));
2081 /* Flood LSA through area. */
2082 ospf_flood_through_as (ospf
, NULL
, new);
2088 is_prefix_default (struct prefix_ipv4
*p
)
2090 struct prefix_ipv4 q
;
2093 q
.prefix
.s_addr
= 0;
2096 return prefix_same ((struct prefix
*) p
, (struct prefix
*) &q
);
2099 /* Originate an AS-external-LSA, install and flood. */
2101 ospf_external_lsa_originate (struct ospf
*ospf
, struct external_info
*ei
)
2103 struct ospf_lsa
*new;
2105 /* Added for NSSA project....
2107 External LSAs are originated in ASBRs as usual, but for NSSA systems.
2108 there is the global Type-5 LSDB and a Type-7 LSDB installed for
2109 every area. The Type-7's are flooded to every IR and every ABR; We
2110 install the Type-5 LSDB so that the normal "refresh" code operates
2111 as usual, and flag them as not used during ASE calculations. The
2112 Type-7 LSDB is used for calculations. Each Type-7 has a Forwarding
2113 Address of non-zero.
2115 If an ABR is the elected NSSA translator, following SPF and during
2116 the ABR task it will translate all the scanned Type-7's, with P-bit
2117 ON and not-self generated, and translate to Type-5's throughout the
2120 A difference in operation depends whether this ASBR is an ABR
2121 or not. If not an ABR, the P-bit is ON, to indicate that any
2122 elected NSSA-ABR can perform its translation.
2124 If an ABR, the P-bit is OFF; No ABR will perform translation and
2125 this ASBR will flood the Type-5 LSA as usual.
2127 For the case where this ASBR is not an ABR, the ASE calculations
2128 are based on the Type-5 LSDB; The Type-7 LSDB exists just to
2129 demonstrate to the user that there are LSA's that belong to any
2132 Finally, it just so happens that when the ABR is translating every
2133 Type-7 into Type-5, it installs it into the Type-5 LSDB as an
2134 approved Type-5 (translated from Type-7); at the end of translation
2135 if any Translated Type-5's remain unapproved, then they must be
2136 flushed from the AS.
2140 /* Check the AS-external-LSA should be originated. */
2141 if (!ospf_redistribute_check (ospf
, ei
, NULL
))
2144 /* Create new AS-external-LSA instance. */
2145 if ((new = ospf_external_lsa_new (ospf
, ei
, NULL
)) == NULL
)
2147 if (IS_DEBUG_OSPF_EVENT
)
2148 zlog_debug ("LSA[Type5:%s]: Could not originate AS-external-LSA",
2149 inet_ntoa (ei
->p
.prefix
));
2153 /* Install newly created LSA into Type-5 LSDB, lock = 1. */
2154 ospf_lsa_install (ospf
, NULL
, new);
2156 /* Update LSA origination count. */
2157 ospf
->lsa_originate_count
++;
2159 /* Flooding new LSA. only to AS (non-NSSA/STUB) */
2160 ospf_flood_through_as (ospf
, NULL
, new);
2162 /* If there is any attached NSSA, do special handling */
2163 if (ospf
->anyNSSA
&&
2164 /* stay away from translated LSAs! */
2165 !(CHECK_FLAG (new->flags
, OSPF_LSA_LOCAL_XLT
)))
2166 ospf_install_flood_nssa (ospf
, new, ei
); /* Install/Flood Type-7 to all NSSAs */
2168 /* Debug logging. */
2169 if (IS_DEBUG_OSPF (lsa
, LSA_GENERATE
))
2171 zlog_debug ("LSA[Type%d:%s]: Originate AS-external-LSA %p",
2172 new->data
->type
, inet_ntoa (new->data
->id
), new);
2173 ospf_lsa_header_dump (new->data
);
2179 /* Originate AS-external-LSA from external info with initial flag. */
2181 ospf_external_lsa_originate_timer (struct thread
*thread
)
2183 struct ospf
*ospf
= THREAD_ARG (thread
);
2184 struct route_node
*rn
;
2185 struct external_info
*ei
;
2186 struct route_table
*rt
;
2187 int type
= THREAD_VAL (thread
);
2189 ospf
->t_external_lsa
= NULL
;
2191 /* Originate As-external-LSA from all type of distribute source. */
2192 if ((rt
= EXTERNAL_INFO (type
)))
2193 for (rn
= route_top (rt
); rn
; rn
= route_next (rn
))
2194 if ((ei
= rn
->info
) != NULL
)
2195 if (!is_prefix_default ((struct prefix_ipv4
*)&ei
->p
))
2196 if (!ospf_external_lsa_originate (ospf
, ei
))
2197 zlog_warn ("LSA: AS-external-LSA was not originated.");
2202 static struct external_info
*
2203 ospf_default_external_info (struct ospf
*ospf
)
2206 struct route_node
*rn
;
2207 struct prefix_ipv4 p
;
2210 p
.prefix
.s_addr
= 0;
2213 /* First, lookup redistributed default route. */
2214 for (type
= 0; type
<= ZEBRA_ROUTE_MAX
; type
++)
2215 if (EXTERNAL_INFO (type
) && type
!= ZEBRA_ROUTE_OSPF
)
2217 rn
= route_node_lookup (EXTERNAL_INFO (type
), (struct prefix
*) &p
);
2220 route_unlock_node (rn
);
2222 if (ospf_redistribute_check (ospf
, rn
->info
, NULL
))
2231 ospf_default_originate_timer (struct thread
*thread
)
2233 struct prefix_ipv4 p
;
2234 struct in_addr nexthop
;
2235 struct external_info
*ei
;
2238 ospf
= THREAD_ARG (thread
);
2241 p
.prefix
.s_addr
= 0;
2244 if (ospf
->default_originate
== DEFAULT_ORIGINATE_ALWAYS
)
2246 /* If there is no default route via redistribute,
2247 then originate AS-external-LSA with nexthop 0 (self). */
2249 ospf_external_info_add (DEFAULT_ROUTE
, p
, 0, nexthop
);
2252 if ((ei
= ospf_default_external_info (ospf
)))
2253 ospf_external_lsa_originate (ospf
, ei
);
2258 /* Flush any NSSA LSAs for given prefix */
2260 ospf_nssa_lsa_flush (struct ospf
*ospf
, struct prefix_ipv4
*p
)
2262 struct listnode
*node
, *nnode
;
2263 struct ospf_lsa
*lsa
;
2264 struct ospf_area
*area
;
2266 for (ALL_LIST_ELEMENTS (ospf
->areas
, node
, nnode
, area
))
2268 if (area
->external_routing
== OSPF_AREA_NSSA
)
2270 if (!(lsa
= ospf_lsa_lookup (area
, OSPF_AS_NSSA_LSA
, p
->prefix
,
2273 if (IS_DEBUG_OSPF (lsa
, LSA_FLOODING
))
2274 zlog_debug ("LSA: There is no such AS-NSSA-LSA %s/%d in LSDB",
2275 inet_ntoa (p
->prefix
), p
->prefixlen
);
2278 ospf_ls_retransmit_delete_nbr_area (area
, lsa
);
2279 if (!IS_LSA_MAXAGE (lsa
))
2281 ospf_refresher_unregister_lsa (ospf
, lsa
);
2282 ospf_lsa_flush_area (lsa
, area
);
2288 /* Flush an AS-external-LSA from LSDB and routing domain. */
2290 ospf_external_lsa_flush (struct ospf
*ospf
,
2291 u_char type
, struct prefix_ipv4
*p
,
2292 unsigned int ifindex
/*, struct in_addr nexthop */)
2294 struct ospf_lsa
*lsa
;
2296 if (IS_DEBUG_OSPF (lsa
, LSA_FLOODING
))
2297 zlog_debug ("LSA: Flushing AS-external-LSA %s/%d",
2298 inet_ntoa (p
->prefix
), p
->prefixlen
);
2300 /* First lookup LSA from LSDB. */
2301 if (!(lsa
= ospf_external_info_find_lsa (ospf
, p
)))
2303 if (IS_DEBUG_OSPF (lsa
, LSA_FLOODING
))
2304 zlog_debug ("LSA: There is no such AS-external-LSA %s/%d in LSDB",
2305 inet_ntoa (p
->prefix
), p
->prefixlen
);
2309 /* If LSA is selforiginated, not a translated LSA, and there is
2310 * NSSA area, flush Type-7 LSA's at first.
2312 if (IS_LSA_SELF(lsa
) && (ospf
->anyNSSA
)
2313 && !(CHECK_FLAG (lsa
->flags
, OSPF_LSA_LOCAL_XLT
)))
2314 ospf_nssa_lsa_flush (ospf
, p
);
2316 /* Sweep LSA from Link State Retransmit List. */
2317 ospf_ls_retransmit_delete_nbr_as (ospf
, lsa
);
2319 /* There must be no self-originated LSA in rtrs_external. */
2321 /* Remove External route from Zebra. */
2322 ospf_zebra_delete ((struct prefix_ipv4
*) p
, &nexthop
);
2325 if (!IS_LSA_MAXAGE (lsa
))
2327 /* Unregister LSA from Refresh queue. */
2328 ospf_refresher_unregister_lsa (ospf
, lsa
);
2330 /* Flush AS-external-LSA through AS. */
2331 ospf_lsa_flush_as (ospf
, lsa
);
2334 if (IS_DEBUG_OSPF (lsa
, LSA_FLOODING
))
2335 zlog_debug ("ospf_external_lsa_flush(): stop");
2339 ospf_external_lsa_refresh_default (struct ospf
*ospf
)
2341 struct prefix_ipv4 p
;
2342 struct external_info
*ei
;
2343 struct ospf_lsa
*lsa
;
2347 p
.prefix
.s_addr
= 0;
2349 ei
= ospf_default_external_info (ospf
);
2350 lsa
= ospf_external_info_find_lsa (ospf
, &p
);
2356 if (IS_DEBUG_OSPF_EVENT
)
2357 zlog_debug ("LSA[Type5:0.0.0.0]: Refresh AS-external-LSA %p", lsa
);
2358 ospf_external_lsa_refresh (ospf
, lsa
, ei
, LSA_REFRESH_FORCE
);
2362 if (IS_DEBUG_OSPF_EVENT
)
2363 zlog_debug ("LSA[Type5:0.0.0.0]: Originate AS-external-LSA");
2364 ospf_external_lsa_originate (ospf
, ei
);
2371 if (IS_DEBUG_OSPF_EVENT
)
2372 zlog_debug ("LSA[Type5:0.0.0.0]: Flush AS-external-LSA");
2373 ospf_lsa_flush_as (ospf
, lsa
);
2379 ospf_external_lsa_refresh_type (struct ospf
*ospf
, u_char type
, int force
)
2381 struct route_node
*rn
;
2382 struct external_info
*ei
;
2384 if (type
!= DEFAULT_ROUTE
)
2385 if (EXTERNAL_INFO(type
))
2386 /* Refresh each redistributed AS-external-LSAs. */
2387 for (rn
= route_top (EXTERNAL_INFO (type
)); rn
; rn
= route_next (rn
))
2388 if ((ei
= rn
->info
))
2389 if (!is_prefix_default (&ei
->p
))
2391 struct ospf_lsa
*lsa
;
2393 if ((lsa
= ospf_external_info_find_lsa (ospf
, &ei
->p
)))
2394 ospf_external_lsa_refresh (ospf
, lsa
, ei
, force
);
2396 ospf_external_lsa_originate (ospf
, ei
);
2400 /* Refresh AS-external-LSA. */
2402 ospf_external_lsa_refresh (struct ospf
*ospf
, struct ospf_lsa
*lsa
,
2403 struct external_info
*ei
, int force
)
2405 struct ospf_lsa
*new;
2408 /* Check the AS-external-LSA should be originated. */
2409 if (!ospf_redistribute_check (ospf
, ei
, &changed
))
2411 if (IS_DEBUG_OSPF (lsa
, LSA_GENERATE
))
2412 zlog_debug ("LSA[Type%d:%s]: Could not be refreshed, "
2413 "redist check fail",
2414 lsa
->data
->type
, inet_ntoa (lsa
->data
->id
));
2415 ospf_external_lsa_flush (ospf
, ei
->type
, &ei
->p
,
2416 ei
->ifindex
/*, ei->nexthop */);
2420 if (!changed
&& !force
)
2422 if (IS_DEBUG_OSPF (lsa
, LSA_GENERATE
))
2423 zlog_debug ("LSA[Type%d:%s]: Not refreshed, not changed/forced",
2424 lsa
->data
->type
, inet_ntoa (lsa
->data
->id
));
2428 /* Delete LSA from neighbor retransmit-list. */
2429 ospf_ls_retransmit_delete_nbr_as (ospf
, lsa
);
2431 /* Unregister AS-external-LSA from refresh-list. */
2432 ospf_refresher_unregister_lsa (ospf
, lsa
);
2434 new = ospf_external_lsa_new (ospf
, ei
, &lsa
->data
->id
);
2438 if (IS_DEBUG_OSPF (lsa
, LSA_GENERATE
))
2439 zlog_debug ("LSA[Type%d:%s]: Could not be refreshed", lsa
->data
->type
,
2440 inet_ntoa (lsa
->data
->id
));
2444 new->data
->ls_seqnum
= lsa_seqnum_increment (lsa
);
2446 /* Re-calculate checksum. */
2447 ospf_lsa_checksum (new->data
);
2449 ospf_lsa_install (ospf
, NULL
, new); /* As type-5. */
2451 /* Flood LSA through AS. */
2452 ospf_flood_through_as (ospf
, NULL
, new);
2454 /* If any attached NSSA, install as Type-7, flood to all NSSA Areas */
2455 if (ospf
->anyNSSA
&& !(CHECK_FLAG (new->flags
, OSPF_LSA_LOCAL_XLT
)))
2456 ospf_install_flood_nssa (ospf
, new, ei
); /* Install/Flood per new rules */
2458 /* Register self-originated LSA to refresh queue.
2459 * Translated LSAs should not be registered, but refreshed upon
2460 * refresh of the Type-7
2462 if ( !CHECK_FLAG (new->flags
, OSPF_LSA_LOCAL_XLT
) )
2463 ospf_refresher_register_lsa (ospf
, new);
2465 /* Debug logging. */
2466 if (IS_DEBUG_OSPF (lsa
, LSA_GENERATE
))
2468 zlog_debug ("LSA[Type%d:%s]: AS-external-LSA refresh",
2469 new->data
->type
, inet_ntoa (new->data
->id
));
2470 ospf_lsa_header_dump (new->data
);
2477 /* LSA installation functions. */
2479 /* Install router-LSA to an area. */
2480 static struct ospf_lsa
*
2481 ospf_router_lsa_install (struct ospf
*ospf
,
2482 struct ospf_lsa
*new, int rt_recalc
)
2484 struct ospf_area
*area
= new->area
;
2486 /* RFC 2328 Section 13.2 Router-LSAs and network-LSAs
2487 The entire routing table must be recalculated, starting with
2488 the shortest path calculations for each area (not just the
2489 area whose link-state database has changed).
2492 ospf_spf_calculate_schedule (ospf
);
2494 if (IS_LSA_SELF (new))
2496 /* Set router-LSA refresh timer. */
2497 OSPF_TIMER_OFF (area
->t_router_lsa_self
);
2498 OSPF_AREA_TIMER_ON (area
->t_router_lsa_self
,
2499 ospf_router_lsa_timer
, OSPF_LS_REFRESH_TIME
);
2501 /* Set self-originated router-LSA. */
2502 ospf_lsa_unlock (&area
->router_lsa_self
);
2503 area
->router_lsa_self
= ospf_lsa_lock (new);
2505 if (IS_DEBUG_OSPF (lsa
, LSA_INSTALL
))
2506 zlog_debug("LSA[Type%d]: ID %s seq 0x%x is self-originated",
2507 new->data
->type
, inet_ntoa (new->data
->id
),
2508 ntohl(new->data
->ls_seqnum
));
2514 #define OSPF_INTERFACE_TIMER_ON(T,F,V) \
2516 (T) = thread_add_timer (master, (F), oi, (V))
2518 /* Install network-LSA to an area. */
2519 static struct ospf_lsa
*
2520 ospf_network_lsa_install (struct ospf
*ospf
,
2521 struct ospf_interface
*oi
,
2522 struct ospf_lsa
*new,
2526 /* RFC 2328 Section 13.2 Router-LSAs and network-LSAs
2527 The entire routing table must be recalculated, starting with
2528 the shortest path calculations for each area (not just the
2529 area whose link-state database has changed).
2532 ospf_spf_calculate_schedule (ospf
);
2534 /* We supposed that when LSA is originated by us, we pass the int
2535 for which it was originated. If LSA was received by flooding,
2536 the RECEIVED flag is set, so we do not link the LSA to the int. */
2537 if (IS_LSA_SELF (new) && !CHECK_FLAG (new->flags
, OSPF_LSA_RECEIVED
))
2539 /* Set LSRefresh timer. */
2540 OSPF_TIMER_OFF (oi
->t_network_lsa_self
);
2542 OSPF_INTERFACE_TIMER_ON (oi
->t_network_lsa_self
,
2543 ospf_network_lsa_refresh_timer
,
2544 OSPF_LS_REFRESH_TIME
);
2546 ospf_lsa_unlock (&oi
->network_lsa_self
);
2547 oi
->network_lsa_self
= ospf_lsa_lock (new);
2553 /* Install summary-LSA to an area. */
2554 static struct ospf_lsa
*
2555 ospf_summary_lsa_install (struct ospf
*ospf
, struct ospf_lsa
*new,
2558 if (rt_recalc
&& !IS_LSA_SELF (new))
2560 /* RFC 2328 Section 13.2 Summary-LSAs
2561 The best route to the destination described by the summary-
2562 LSA must be recalculated (see Section 16.5). If this
2563 destination is an AS boundary router, it may also be
2564 necessary to re-examine all the AS-external-LSAs.
2568 /* This doesn't exist yet... */
2569 ospf_summary_incremental_update(new); */
2571 ospf_spf_calculate_schedule (ospf
);
2574 if (IS_DEBUG_OSPF (lsa
, LSA_INSTALL
))
2575 zlog_debug ("ospf_summary_lsa_install(): SPF scheduled");
2578 if (IS_LSA_SELF (new))
2579 ospf_refresher_register_lsa (ospf
, new);
2584 /* Install ASBR-summary-LSA to an area. */
2585 static struct ospf_lsa
*
2586 ospf_summary_asbr_lsa_install (struct ospf
*ospf
, struct ospf_lsa
*new,
2589 if (rt_recalc
&& !IS_LSA_SELF (new))
2591 /* RFC 2328 Section 13.2 Summary-LSAs
2592 The best route to the destination described by the summary-
2593 LSA must be recalculated (see Section 16.5). If this
2594 destination is an AS boundary router, it may also be
2595 necessary to re-examine all the AS-external-LSAs.
2598 /* These don't exist yet... */
2599 ospf_summary_incremental_update(new);
2600 /* Isn't this done by the above call?
2601 - RFC 2328 Section 16.5 implies it should be */
2602 /* ospf_ase_calculate_schedule(); */
2604 ospf_spf_calculate_schedule (ospf
);
2608 /* register LSA to refresh-list. */
2609 if (IS_LSA_SELF (new))
2610 ospf_refresher_register_lsa (ospf
, new);
2615 /* Install AS-external-LSA. */
2616 static struct ospf_lsa
*
2617 ospf_external_lsa_install (struct ospf
*ospf
, struct ospf_lsa
*new,
2620 ospf_ase_register_external_lsa (new, ospf
);
2621 /* If LSA is not self-originated, calculate an external route. */
2624 /* RFC 2328 Section 13.2 AS-external-LSAs
2625 The best route to the destination described by the AS-
2626 external-LSA must be recalculated (see Section 16.6).
2629 if (!IS_LSA_SELF (new))
2630 ospf_ase_incremental_update (ospf
, new);
2633 if (new->data
->type
== OSPF_AS_NSSA_LSA
)
2635 /* There is no point to register selforiginate Type-7 LSA for
2636 * refreshing. We rely on refreshing Type-5 LSA's
2638 if (IS_LSA_SELF (new))
2642 /* Try refresh type-5 translated LSA for this LSA, if one exists.
2643 * New translations will be taken care of by the abr_task.
2645 ospf_translated_nssa_refresh (ospf
, new, NULL
);
2649 /* Register self-originated LSA to refresh queue.
2650 * Leave Translated LSAs alone if NSSA is enabled
2652 if (IS_LSA_SELF (new) && !CHECK_FLAG (new->flags
, OSPF_LSA_LOCAL_XLT
) )
2653 ospf_refresher_register_lsa (ospf
, new);
2659 ospf_discard_from_db (struct ospf
*ospf
,
2660 struct ospf_lsdb
*lsdb
, struct ospf_lsa
*lsa
)
2662 struct ospf_lsa
*old
;
2666 zlog_warn ("%s: Called with NULL lsdb!", __func__
);
2668 zlog_warn ("%s: and NULL LSA!", __func__
);
2670 zlog_warn ("LSA[Type%d:%s]: not associated with LSDB!",
2671 lsa
->data
->type
, inet_ntoa (lsa
->data
->id
));
2675 old
= ospf_lsdb_lookup (lsdb
, lsa
);
2680 if (old
->refresh_list
>= 0)
2681 ospf_refresher_unregister_lsa (ospf
, old
);
2683 switch (old
->data
->type
)
2685 case OSPF_AS_EXTERNAL_LSA
:
2686 ospf_ase_unregister_external_lsa (old
, ospf
);
2687 ospf_ls_retransmit_delete_nbr_as (ospf
, old
);
2689 #ifdef HAVE_OPAQUE_LSA
2690 case OSPF_OPAQUE_AS_LSA
:
2691 ospf_ls_retransmit_delete_nbr_as (ospf
, old
);
2693 #endif /* HAVE_OPAQUE_LSA */
2694 case OSPF_AS_NSSA_LSA
:
2695 ospf_ls_retransmit_delete_nbr_area (old
->area
, old
);
2696 ospf_ase_unregister_external_lsa (old
, ospf
);
2699 ospf_ls_retransmit_delete_nbr_area (old
->area
, old
);
2703 ospf_lsa_maxage_delete (ospf
, old
);
2704 ospf_lsa_discard (old
);
2708 ospf_lsa_install (struct ospf
*ospf
, struct ospf_interface
*oi
,
2709 struct ospf_lsa
*lsa
)
2711 struct ospf_lsa
*new = NULL
;
2712 struct ospf_lsa
*old
= NULL
;
2713 struct ospf_lsdb
*lsdb
= NULL
;
2717 switch (lsa
->data
->type
)
2720 case OSPF_AS_NSSA_LSA
:
2722 lsdb
= lsa
->area
->lsdb
;
2726 case OSPF_AS_EXTERNAL_LSA
:
2727 #ifdef HAVE_OPAQUE_LSA
2728 case OSPF_OPAQUE_AS_LSA
:
2729 #endif /* HAVE_OPAQUE_LSA */
2733 lsdb
= lsa
->area
->lsdb
;
2739 /* RFC 2328 13.2. Installing LSAs in the database
2741 Installing a new LSA in the database, either as the result of
2742 flooding or a newly self-originated LSA, may cause the OSPF
2743 routing table structure to be recalculated. The contents of the
2744 new LSA should be compared to the old instance, if present. If
2745 there is no difference, there is no need to recalculate the
2746 routing table. When comparing an LSA to its previous instance,
2747 the following are all considered to be differences in contents:
2749 o The LSA's Options field has changed.
2751 o One of the LSA instances has LS age set to MaxAge, and
2754 o The length field in the LSA header has changed.
2756 o The body of the LSA (i.e., anything outside the 20-byte
2757 LSA header) has changed. Note that this excludes changes
2758 in LS Sequence Number and LS Checksum.
2761 /* Look up old LSA and determine if any SPF calculation or incremental
2763 old
= ospf_lsdb_lookup (lsdb
, lsa
);
2765 /* Do comparision and record if recalc needed. */
2767 if ( old
== NULL
|| ospf_lsa_different(old
, lsa
))
2771 Sequence number check (Section 14.1 of rfc 2328)
2772 "Premature aging is used when it is time for a self-originated
2773 LSA's sequence number field to wrap. At this point, the current
2774 LSA instance (having LS sequence number MaxSequenceNumber) must
2775 be prematurely aged and flushed from the routing domain before a
2776 new instance with sequence number equal to InitialSequenceNumber
2777 can be originated. "
2780 if (ntohl(lsa
->data
->ls_seqnum
) - 1 == OSPF_MAX_SEQUENCE_NUMBER
)
2782 if (ospf_lsa_is_self_originated(ospf
, lsa
))
2784 lsa
->data
->ls_seqnum
= htonl(OSPF_MAX_SEQUENCE_NUMBER
);
2786 if (!IS_LSA_MAXAGE(lsa
))
2787 lsa
->flags
|= OSPF_LSA_PREMATURE_AGE
;
2788 lsa
->data
->ls_age
= htons (OSPF_LSA_MAXAGE
);
2790 if (IS_DEBUG_OSPF (lsa
, LSA_REFRESH
))
2792 zlog_debug ("ospf_lsa_install() Premature Aging "
2793 "lsa 0x%lx", (u_long
)lsa
);
2794 ospf_lsa_header_dump (lsa
->data
);
2799 if (IS_DEBUG_OSPF (lsa
, LSA_GENERATE
))
2801 zlog_debug ("ospf_lsa_install() got an lsa with seq 0x80000000 "
2802 "that was not self originated. Ignoring\n");
2803 ospf_lsa_header_dump (lsa
->data
);
2809 /* discard old LSA from LSDB */
2811 ospf_discard_from_db (ospf
, lsdb
, lsa
);
2813 /* Calculate Checksum if self-originated?. */
2814 if (IS_LSA_SELF (lsa
))
2815 ospf_lsa_checksum (lsa
->data
);
2817 /* Insert LSA to LSDB. */
2818 ospf_lsdb_add (lsdb
, lsa
);
2821 /* Do LSA specific installation process. */
2822 switch (lsa
->data
->type
)
2824 case OSPF_ROUTER_LSA
:
2825 new = ospf_router_lsa_install (ospf
, lsa
, rt_recalc
);
2827 case OSPF_NETWORK_LSA
:
2829 new = ospf_network_lsa_install (ospf
, oi
, lsa
, rt_recalc
);
2831 case OSPF_SUMMARY_LSA
:
2832 new = ospf_summary_lsa_install (ospf
, lsa
, rt_recalc
);
2834 case OSPF_ASBR_SUMMARY_LSA
:
2835 new = ospf_summary_asbr_lsa_install (ospf
, lsa
, rt_recalc
);
2837 case OSPF_AS_EXTERNAL_LSA
:
2838 new = ospf_external_lsa_install (ospf
, lsa
, rt_recalc
);
2840 #ifdef HAVE_OPAQUE_LSA
2841 case OSPF_OPAQUE_LINK_LSA
:
2842 if (IS_LSA_SELF (lsa
))
2843 lsa
->oi
= oi
; /* Specify outgoing ospf-interface for this LSA. */
2845 ; /* Incoming "oi" for this LSA has set at LSUpd reception. */
2847 case OSPF_OPAQUE_AREA_LSA
:
2848 case OSPF_OPAQUE_AS_LSA
:
2849 new = ospf_opaque_lsa_install (lsa
, rt_recalc
);
2851 #endif /* HAVE_OPAQUE_LSA */
2852 case OSPF_AS_NSSA_LSA
:
2853 new = ospf_external_lsa_install (ospf
, lsa
, rt_recalc
);
2854 default: /* type-6,8,9....nothing special */
2859 return new; /* Installation failed, cannot proceed further -- endo. */
2862 if (IS_DEBUG_OSPF (lsa
, LSA_INSTALL
))
2864 char area_str
[INET_ADDRSTRLEN
];
2866 switch (lsa
->data
->type
)
2868 case OSPF_AS_EXTERNAL_LSA
:
2869 #ifdef HAVE_OPAQUE_LSA
2870 case OSPF_OPAQUE_AS_LSA
:
2871 #endif /* HAVE_OPAQUE_LSA */
2872 case OSPF_AS_NSSA_LSA
:
2873 zlog_debug ("LSA[%s]: Install %s",
2875 LOOKUP (ospf_lsa_type_msg
, new->data
->type
));
2878 strcpy (area_str
, inet_ntoa (new->area
->area_id
));
2879 zlog_debug ("LSA[%s]: Install %s to Area %s",
2881 LOOKUP (ospf_lsa_type_msg
, new->data
->type
), area_str
);
2887 If received LSA' ls_age is MaxAge, or lsa is being prematurely aged
2888 (it's getting flushed out of the area), set LSA on MaxAge LSA list.
2890 if ((lsa
->flags
& OSPF_LSA_PREMATURE_AGE
) ||
2891 (IS_LSA_MAXAGE (new) && !IS_LSA_SELF (new)))
2893 if (IS_DEBUG_OSPF (lsa
, LSA_INSTALL
))
2894 zlog_debug ("LSA[Type%d:%s]: Install LSA 0x%p, MaxAge",
2896 inet_ntoa (new->data
->id
),
2898 ospf_lsa_maxage (ospf
, lsa
);
2906 ospf_check_nbr_status (struct ospf
*ospf
)
2908 struct listnode
*node
, *nnode
;
2909 struct ospf_interface
*oi
;
2911 for (ALL_LIST_ELEMENTS (ospf
->oiflist
, node
, nnode
, oi
))
2913 struct route_node
*rn
;
2914 struct ospf_neighbor
*nbr
;
2916 if (ospf_if_is_enable (oi
))
2917 for (rn
= route_top (oi
->nbrs
); rn
; rn
= route_next (rn
))
2918 if ((nbr
= rn
->info
) != NULL
)
2919 if (nbr
->state
== NSM_Exchange
|| nbr
->state
== NSM_Loading
)
2921 route_unlock_node (rn
);
2930 #ifdef ORIGINAL_CODING
2931 /* This function flood the maxaged LSA to DR. */
2933 ospf_maxage_flood (struct ospf_lsa
*lsa
)
2935 switch (lsa
->data
->type
)
2937 case OSPF_ROUTER_LSA
:
2938 case OSPF_NETWORK_LSA
:
2939 case OSPF_SUMMARY_LSA
:
2940 case OSPF_ASBR_SUMMARY_LSA
:
2941 case OSPF_AS_NSSA_LSA
:
2942 #ifdef HAVE_OPAQUE_LSA
2943 case OSPF_OPAQUE_LINK_LSA
:
2944 case OSPF_OPAQUE_AREA_LSA
:
2945 #endif /* HAVE_OPAQUE_LSA */
2946 ospf_flood_through_area (lsa
->area
, NULL
, lsa
);
2948 case OSPF_AS_EXTERNAL_LSA
:
2949 #ifdef HAVE_OPAQUE_LSA
2950 case OSPF_OPAQUE_AS_LSA
:
2951 #endif /* HAVE_OPAQUE_LSA */
2952 ospf_flood_through_as (NULL
, lsa
);
2958 #endif /* ORIGINAL_CODING */
2961 ospf_maxage_lsa_remover (struct thread
*thread
)
2963 struct ospf
*ospf
= THREAD_ARG (thread
);
2964 struct ospf_lsa
*lsa
;
2965 struct listnode
*node
, *nnode
;
2968 ospf
->t_maxage
= NULL
;
2970 if (IS_DEBUG_OSPF (lsa
, LSA_FLOODING
))
2971 zlog_debug ("LSA[MaxAge]: remover Start");
2973 reschedule
= !ospf_check_nbr_status (ospf
);
2976 for (ALL_LIST_ELEMENTS (ospf
->maxage_lsa
, node
, nnode
, lsa
))
2978 if (lsa
->retransmit_counter
> 0)
2984 /* Remove LSA from the LSDB */
2985 if (CHECK_FLAG (lsa
->flags
, OSPF_LSA_SELF
))
2986 if (IS_DEBUG_OSPF (lsa
, LSA_FLOODING
))
2987 zlog_debug ("LSA[Type%d:%s]: LSA 0x%lx is self-oririnated: ",
2988 lsa
->data
->type
, inet_ntoa (lsa
->data
->id
), (u_long
)lsa
);
2990 if (IS_DEBUG_OSPF (lsa
, LSA_FLOODING
))
2991 zlog_debug ("LSA[Type%d:%s]: MaxAge LSA removed from list",
2992 lsa
->data
->type
, inet_ntoa (lsa
->data
->id
));
2994 /* Flood max age LSA. */
2995 #ifdef ORIGINAL_CODING
2996 ospf_maxage_flood (lsa
);
2997 #else /* ORIGINAL_CODING */
2998 ospf_flood_through (ospf
, NULL
, lsa
);
2999 #endif /* ORIGINAL_CODING */
3001 if (lsa
->flags
& OSPF_LSA_PREMATURE_AGE
)
3003 if (IS_DEBUG_OSPF (lsa
, LSA_FLOODING
))
3004 zlog_debug ("originating new router lsa for lsa 0x%lx \n",
3006 ospf_router_lsa_originate(lsa
->area
);
3009 /* Remove from lsdb. */
3012 ospf_discard_from_db (ospf
, lsa
->lsdb
, lsa
);
3013 ospf_lsdb_delete (lsa
->lsdb
, lsa
);
3016 zlog_warn ("%s: LSA[Type%d:%s]: No associated LSDB!", __func__
,
3017 lsa
->data
->type
, inet_ntoa (lsa
->data
->id
));
3020 /* A MaxAge LSA must be removed immediately from the router's link
3021 state database as soon as both a) it is no longer contained on any
3022 neighbor Link state retransmission lists and b) none of the router's
3023 neighbors are in states Exchange or Loading. */
3025 OSPF_TIMER_ON (ospf
->t_maxage
, ospf_maxage_lsa_remover
, 2);
3031 ospf_lsa_maxage_exist (struct ospf
*ospf
, struct ospf_lsa
*new)
3033 struct listnode
*node
;
3034 struct ospf_lsa
*lsa
;
3036 for (ALL_LIST_ELEMENTS_RO (ospf
->maxage_lsa
, node
, lsa
))
3044 ospf_lsa_maxage_delete (struct ospf
*ospf
, struct ospf_lsa
*lsa
)
3048 if ((n
= listnode_lookup (ospf
->maxage_lsa
, lsa
)))
3050 list_delete_node (ospf
->maxage_lsa
, n
);
3051 ospf_lsa_unlock (&lsa
); /* maxage_lsa */
3056 ospf_lsa_maxage (struct ospf
*ospf
, struct ospf_lsa
*lsa
)
3058 /* When we saw a MaxAge LSA flooded to us, we put it on the list
3059 and schedule the MaxAge LSA remover. */
3060 if (ospf_lsa_maxage_exist (ospf
, lsa
))
3062 if (IS_DEBUG_OSPF (lsa
, LSA_FLOODING
))
3063 zlog_debug ("LSA[Type%d:%s]: %p already exists on MaxAge LSA list",
3064 lsa
->data
->type
, inet_ntoa (lsa
->data
->id
), lsa
);
3068 listnode_add (ospf
->maxage_lsa
, ospf_lsa_lock (lsa
));
3070 if (IS_DEBUG_OSPF (lsa
, LSA_FLOODING
))
3071 zlog_debug ("LSA[%s]: MaxAge LSA remover scheduled.", dump_lsa_key (lsa
));
3073 OSPF_TIMER_ON (ospf
->t_maxage
, ospf_maxage_lsa_remover
, 2);
3077 ospf_lsa_maxage_walker_remover (struct ospf
*ospf
, struct ospf_lsa
*lsa
)
3079 /* Stay away from any Local Translated Type-7 LSAs */
3080 if (CHECK_FLAG (lsa
->flags
, OSPF_LSA_LOCAL_XLT
))
3083 if (IS_LSA_MAXAGE (lsa
))
3084 /* Self-originated LSAs should NOT time-out instead,
3085 they're flushed and submitted to the max_age list explicitly. */
3086 if (!ospf_lsa_is_self_originated (ospf
, lsa
))
3088 if (IS_DEBUG_OSPF (lsa
, LSA_FLOODING
))
3089 zlog_debug("LSA[%s]: is MaxAge", dump_lsa_key (lsa
));
3091 switch (lsa
->data
->type
)
3093 #ifdef HAVE_OPAQUE_LSA
3094 case OSPF_OPAQUE_LINK_LSA
:
3095 case OSPF_OPAQUE_AREA_LSA
:
3096 case OSPF_OPAQUE_AS_LSA
:
3098 * As a general rule, whenever network topology has changed
3099 * (due to an LSA removal in this case), routing recalculation
3100 * should be triggered. However, this is not true for opaque
3101 * LSAs. Even if an opaque LSA instance is going to be removed
3102 * from the routing domain, it does not mean a change in network
3103 * topology, and thus, routing recalculation is not needed here.
3106 #endif /* HAVE_OPAQUE_LSA */
3107 case OSPF_AS_EXTERNAL_LSA
:
3108 case OSPF_AS_NSSA_LSA
:
3109 ospf_ase_incremental_update (ospf
, lsa
);
3112 ospf_spf_calculate_schedule (ospf
);
3115 ospf_lsa_maxage (ospf
, lsa
);
3121 /* Periodical check of MaxAge LSA. */
3123 ospf_lsa_maxage_walker (struct thread
*thread
)
3125 struct ospf
*ospf
= THREAD_ARG (thread
);
3126 struct route_node
*rn
;
3127 struct ospf_lsa
*lsa
;
3128 struct ospf_area
*area
;
3129 struct listnode
*node
, *nnode
;
3131 ospf
->t_maxage_walker
= NULL
;
3133 for (ALL_LIST_ELEMENTS (ospf
->areas
, node
, nnode
, area
))
3135 LSDB_LOOP (ROUTER_LSDB (area
), rn
, lsa
)
3136 ospf_lsa_maxage_walker_remover (ospf
, lsa
);
3137 LSDB_LOOP (NETWORK_LSDB (area
), rn
, lsa
)
3138 ospf_lsa_maxage_walker_remover (ospf
, lsa
);
3139 LSDB_LOOP (SUMMARY_LSDB (area
), rn
, lsa
)
3140 ospf_lsa_maxage_walker_remover (ospf
, lsa
);
3141 LSDB_LOOP (ASBR_SUMMARY_LSDB (area
), rn
, lsa
)
3142 ospf_lsa_maxage_walker_remover (ospf
, lsa
);
3143 #ifdef HAVE_OPAQUE_LSA
3144 LSDB_LOOP (OPAQUE_AREA_LSDB (area
), rn
, lsa
)
3145 ospf_lsa_maxage_walker_remover (ospf
, lsa
);
3146 LSDB_LOOP (OPAQUE_LINK_LSDB (area
), rn
, lsa
)
3147 ospf_lsa_maxage_walker_remover (ospf
, lsa
);
3148 #endif /* HAVE_OPAQUE_LSA */
3149 LSDB_LOOP (NSSA_LSDB (area
), rn
, lsa
)
3150 ospf_lsa_maxage_walker_remover (ospf
, lsa
);
3153 /* for AS-external-LSAs. */
3156 LSDB_LOOP (EXTERNAL_LSDB (ospf
), rn
, lsa
)
3157 ospf_lsa_maxage_walker_remover (ospf
, lsa
);
3158 #ifdef HAVE_OPAQUE_LSA
3159 LSDB_LOOP (OPAQUE_AS_LSDB (ospf
), rn
, lsa
)
3160 ospf_lsa_maxage_walker_remover (ospf
, lsa
);
3161 #endif /* HAVE_OPAQUE_LSA */
3164 OSPF_TIMER_ON (ospf
->t_maxage_walker
, ospf_lsa_maxage_walker
,
3165 OSPF_LSA_MAXAGE_CHECK_INTERVAL
);
3170 ospf_lsa_lookup_by_prefix (struct ospf_lsdb
*lsdb
, u_char type
,
3171 struct prefix_ipv4
*p
, struct in_addr router_id
)
3173 struct ospf_lsa
*lsa
;
3174 struct in_addr mask
, id
;
3175 struct lsa_header_mask
3177 struct lsa_header header
;
3178 struct in_addr mask
;
3181 lsa
= ospf_lsdb_lookup_by_id (lsdb
, type
, p
->prefix
, router_id
);
3185 masklen2ip (p
->prefixlen
, &mask
);
3187 hmask
= (struct lsa_header_mask
*) lsa
->data
;
3189 if (mask
.s_addr
!= hmask
->mask
.s_addr
)
3191 id
.s_addr
= p
->prefix
.s_addr
| (~mask
.s_addr
);
3192 lsa
= ospf_lsdb_lookup_by_id (lsdb
, type
, id
, router_id
);
3201 ospf_lsa_lookup (struct ospf_area
*area
, u_int32_t type
,
3202 struct in_addr id
, struct in_addr adv_router
)
3204 struct ospf
*ospf
= ospf_lookup();
3209 case OSPF_ROUTER_LSA
:
3210 case OSPF_NETWORK_LSA
:
3211 case OSPF_SUMMARY_LSA
:
3212 case OSPF_ASBR_SUMMARY_LSA
:
3213 case OSPF_AS_NSSA_LSA
:
3214 #ifdef HAVE_OPAQUE_LSA
3215 case OSPF_OPAQUE_LINK_LSA
:
3216 case OSPF_OPAQUE_AREA_LSA
:
3217 #endif /* HAVE_OPAQUE_LSA */
3218 return ospf_lsdb_lookup_by_id (area
->lsdb
, type
, id
, adv_router
);
3219 case OSPF_AS_EXTERNAL_LSA
:
3220 #ifdef HAVE_OPAQUE_LSA
3221 case OSPF_OPAQUE_AS_LSA
:
3222 #endif /* HAVE_OPAQUE_LSA */
3223 return ospf_lsdb_lookup_by_id (ospf
->lsdb
, type
, id
, adv_router
);
3232 ospf_lsa_lookup_by_id (struct ospf_area
*area
, u_int32_t type
,
3235 struct ospf_lsa
*lsa
;
3236 struct route_node
*rn
;
3240 case OSPF_ROUTER_LSA
:
3241 return ospf_lsdb_lookup_by_id (area
->lsdb
, type
, id
, id
);
3242 case OSPF_NETWORK_LSA
:
3243 for (rn
= route_top (NETWORK_LSDB (area
)); rn
; rn
= route_next (rn
))
3244 if ((lsa
= rn
->info
))
3245 if (IPV4_ADDR_SAME (&lsa
->data
->id
, &id
))
3247 route_unlock_node (rn
);
3251 case OSPF_SUMMARY_LSA
:
3252 case OSPF_ASBR_SUMMARY_LSA
:
3253 /* Currently not used. */
3255 return ospf_lsdb_lookup_by_id (area
->lsdb
, type
, id
, id
);
3256 case OSPF_AS_EXTERNAL_LSA
:
3257 case OSPF_AS_NSSA_LSA
:
3258 #ifdef HAVE_OPAQUE_LSA
3259 case OSPF_OPAQUE_LINK_LSA
:
3260 case OSPF_OPAQUE_AREA_LSA
:
3261 case OSPF_OPAQUE_AS_LSA
:
3262 /* Currently not used. */
3264 #endif /* HAVE_OPAQUE_LSA */
3273 ospf_lsa_lookup_by_header (struct ospf_area
*area
, struct lsa_header
*lsah
)
3275 struct ospf_lsa
*match
;
3277 #ifdef HAVE_OPAQUE_LSA
3279 * Strictly speaking, the LSA-ID field for Opaque-LSAs (type-9/10/11)
3280 * is redefined to have two subfields; opaque-type and opaque-id.
3281 * However, it is harmless to treat the two sub fields together, as if
3282 * they two were forming a unique LSA-ID.
3284 #endif /* HAVE_OPAQUE_LSA */
3286 match
= ospf_lsa_lookup (area
, lsah
->type
, lsah
->id
, lsah
->adv_router
);
3289 if (IS_DEBUG_OSPF (lsa
, LSA
) == OSPF_DEBUG_LSA
)
3290 zlog_debug ("LSA[Type%d:%s]: Lookup by header, NO MATCH",
3291 lsah
->type
, inet_ntoa (lsah
->id
));
3296 /* return +n, l1 is more recent.
3297 return -n, l2 is more recent.
3298 return 0, l1 and l2 is identical. */
3300 ospf_lsa_more_recent (struct ospf_lsa
*l1
, struct ospf_lsa
*l2
)
3305 if (l1
== NULL
&& l2
== NULL
)
3312 /* compare LS sequence number. */
3313 x
= (int) ntohl (l1
->data
->ls_seqnum
);
3314 y
= (int) ntohl (l2
->data
->ls_seqnum
);
3320 /* compare LS checksum. */
3321 r
= ntohs (l1
->data
->checksum
) - ntohs (l2
->data
->checksum
);
3325 /* compare LS age. */
3326 if (IS_LSA_MAXAGE (l1
) && !IS_LSA_MAXAGE (l2
))
3328 else if (!IS_LSA_MAXAGE (l1
) && IS_LSA_MAXAGE (l2
))
3331 /* compare LS age with MaxAgeDiff. */
3332 if (LS_AGE (l1
) - LS_AGE (l2
) > OSPF_LSA_MAXAGE_DIFF
)
3334 else if (LS_AGE (l2
) - LS_AGE (l1
) > OSPF_LSA_MAXAGE_DIFF
)
3337 /* LSAs are identical. */
3341 /* If two LSAs are different, return 1, otherwise return 0. */
3343 ospf_lsa_different (struct ospf_lsa
*l1
, struct ospf_lsa
*l2
)
3351 if (l1
->data
->options
!= l2
->data
->options
)
3354 if (IS_LSA_MAXAGE (l1
) && !IS_LSA_MAXAGE (l2
))
3357 if (IS_LSA_MAXAGE (l2
) && !IS_LSA_MAXAGE (l1
))
3360 if (l1
->data
->length
!= l2
->data
->length
)
3363 if (l1
->data
->length
== 0)
3366 assert ( ntohs(l1
->data
->length
) > OSPF_LSA_HEADER_SIZE
);
3368 p1
= (char *) l1
->data
;
3369 p2
= (char *) l2
->data
;
3371 if (memcmp (p1
+ OSPF_LSA_HEADER_SIZE
, p2
+ OSPF_LSA_HEADER_SIZE
,
3372 ntohs( l1
->data
->length
) - OSPF_LSA_HEADER_SIZE
) != 0)
3378 #ifdef ORIGINAL_CODING
3380 ospf_lsa_flush_self_originated (struct ospf_neighbor
*nbr
,
3381 struct ospf_lsa
*self
,
3382 struct ospf_lsa
*new)
3386 /* Adjust LS Sequence Number. */
3387 seqnum
= ntohl (new->data
->ls_seqnum
) + 1;
3388 self
->data
->ls_seqnum
= htonl (seqnum
);
3390 /* Recalculate LSA checksum. */
3391 ospf_lsa_checksum (self
->data
);
3393 /* Reflooding LSA. */
3394 /* RFC2328 Section 13.3
3395 On non-broadcast networks, separate Link State Update
3396 packets must be sent, as unicasts, to each adjacent neighbor
3397 (i.e., those in state Exchange or greater). The destination
3398 IP addresses for these packets are the neighbors' IP
3400 if (nbr
->oi
->type
== OSPF_IFTYPE_NBMA
)
3402 struct route_node
*rn
;
3403 struct ospf_neighbor
*onbr
;
3405 for (rn
= route_top (nbr
->oi
->nbrs
); rn
; rn
= route_next (rn
))
3406 if ((onbr
= rn
->info
) != NULL
)
3407 if (onbr
!= nbr
->oi
->nbr_self
&& onbr
->status
>= NSM_Exchange
)
3408 ospf_ls_upd_send_lsa (onbr
, self
, OSPF_SEND_PACKET_DIRECT
);
3411 ospf_ls_upd_send_lsa (nbr
, self
, OSPF_SEND_PACKET_INDIRECT
);
3413 if (IS_DEBUG_OSPF (lsa
, LSA_GENERATE
))
3414 zlog_debug ("LSA[Type%d:%s]: Flush self-originated LSA",
3415 self
->data
->type
, inet_ntoa (self
->data
->id
));
3417 #else /* ORIGINAL_CODING */
3419 ospf_lsa_flush_schedule (struct ospf
*ospf
, struct ospf_lsa
*lsa
)
3421 if (lsa
== NULL
|| !IS_LSA_SELF (lsa
))
3424 if (IS_DEBUG_OSPF_EVENT
)
3425 zlog_debug ("LSA[Type%d:%s]: Schedule self-originated LSA to FLUSH", lsa
->data
->type
, inet_ntoa (lsa
->data
->id
));
3427 /* Force given lsa's age to MaxAge. */
3428 lsa
->data
->ls_age
= htons (OSPF_LSA_MAXAGE
);
3430 switch (lsa
->data
->type
)
3432 #ifdef HAVE_OPAQUE_LSA
3433 case OSPF_OPAQUE_LINK_LSA
:
3434 case OSPF_OPAQUE_AREA_LSA
:
3435 case OSPF_OPAQUE_AS_LSA
:
3436 ospf_opaque_lsa_refresh (lsa
);
3438 #endif /* HAVE_OPAQUE_LSA */
3440 ospf_lsa_maxage (ospf
, lsa
);
3448 ospf_flush_self_originated_lsas_now (struct ospf
*ospf
)
3450 struct listnode
*node
, *nnode
;
3451 struct listnode
*node2
, *nnode2
;
3452 struct ospf_area
*area
;
3453 struct ospf_interface
*oi
;
3454 struct ospf_lsa
*lsa
;
3455 struct route_node
*rn
;
3456 int need_to_flush_ase
= 0;
3458 for (ALL_LIST_ELEMENTS (ospf
->areas
, node
, nnode
, area
))
3460 if ((lsa
= area
->router_lsa_self
) != NULL
)
3462 if (IS_DEBUG_OSPF_EVENT
)
3463 zlog_debug ("LSA[Type%d:%s]: Schedule self-originated LSA to FLUSH", lsa
->data
->type
, inet_ntoa (lsa
->data
->id
));
3465 ospf_lsa_flush_area (lsa
, area
);
3466 ospf_lsa_unlock (&area
->router_lsa_self
);
3467 area
->router_lsa_self
= NULL
;
3468 OSPF_TIMER_OFF (area
->t_router_lsa_self
);
3471 for (ALL_LIST_ELEMENTS (area
->oiflist
, node2
, nnode2
, oi
))
3473 if ((lsa
= oi
->network_lsa_self
) != NULL
3474 && oi
->state
== ISM_DR
3475 && oi
->full_nbrs
> 0)
3477 if (IS_DEBUG_OSPF_EVENT
)
3478 zlog_debug ("LSA[Type%d:%s]: Schedule self-originated LSA to FLUSH", lsa
->data
->type
, inet_ntoa (lsa
->data
->id
));
3480 ospf_lsa_flush_area (oi
->network_lsa_self
, area
);
3481 ospf_lsa_unlock (&oi
->network_lsa_self
);
3482 oi
->network_lsa_self
= NULL
;
3483 OSPF_TIMER_OFF (oi
->t_network_lsa_self
);
3486 if (oi
->type
!= OSPF_IFTYPE_VIRTUALLINK
3487 && area
->external_routing
== OSPF_AREA_DEFAULT
)
3488 need_to_flush_ase
= 1;
3491 LSDB_LOOP (SUMMARY_LSDB (area
), rn
, lsa
)
3492 ospf_lsa_flush_schedule (ospf
, lsa
);
3493 LSDB_LOOP (ASBR_SUMMARY_LSDB (area
), rn
, lsa
)
3494 ospf_lsa_flush_schedule (ospf
, lsa
);
3495 #ifdef HAVE_OPAQUE_LSA
3496 LSDB_LOOP (OPAQUE_LINK_LSDB (area
), rn
, lsa
)
3497 ospf_lsa_flush_schedule (ospf
, lsa
);
3498 LSDB_LOOP (OPAQUE_AREA_LSDB (area
), rn
, lsa
)
3499 ospf_lsa_flush_schedule (ospf
, lsa
);
3500 #endif /* HAVE_OPAQUE_LSA */
3503 if (need_to_flush_ase
)
3505 LSDB_LOOP (EXTERNAL_LSDB (ospf
), rn
, lsa
)
3506 ospf_lsa_flush_schedule (ospf
, lsa
);
3507 #ifdef HAVE_OPAQUE_LSA
3508 LSDB_LOOP (OPAQUE_AS_LSDB (ospf
), rn
, lsa
)
3509 ospf_lsa_flush_schedule (ospf
, lsa
);
3510 #endif /* HAVE_OPAQUE_LSA */
3514 * Make sure that the MaxAge LSA remover is executed immediately,
3515 * without conflicting to other threads.
3517 if (ospf
->t_maxage
!= NULL
)
3519 OSPF_TIMER_OFF (ospf
->t_maxage
);
3520 thread_execute (master
, ospf_maxage_lsa_remover
, ospf
, 0);
3525 #endif /* ORIGINAL_CODING */
3527 /* If there is self-originated LSA, then return 1, otherwise return 0. */
3528 /* An interface-independent version of ospf_lsa_is_self_originated */
3530 ospf_lsa_is_self_originated (struct ospf
*ospf
, struct ospf_lsa
*lsa
)
3532 struct listnode
*node
;
3533 struct ospf_interface
*oi
;
3535 /* This LSA is already checked. */
3536 if (CHECK_FLAG (lsa
->flags
, OSPF_LSA_SELF_CHECKED
))
3537 return CHECK_FLAG (lsa
->flags
, OSPF_LSA_SELF
);
3539 /* Make sure LSA is self-checked. */
3540 SET_FLAG (lsa
->flags
, OSPF_LSA_SELF_CHECKED
);
3542 /* AdvRouter and Router ID is the same. */
3543 if (IPV4_ADDR_SAME (&lsa
->data
->adv_router
, &ospf
->router_id
))
3544 SET_FLAG (lsa
->flags
, OSPF_LSA_SELF
);
3546 /* LSA is router-LSA. */
3547 else if (lsa
->data
->type
== OSPF_ROUTER_LSA
&&
3548 IPV4_ADDR_SAME (&lsa
->data
->id
, &ospf
->router_id
))
3549 SET_FLAG (lsa
->flags
, OSPF_LSA_SELF
);
3551 /* LSA is network-LSA. Compare Link ID with all interfaces. */
3552 else if (lsa
->data
->type
== OSPF_NETWORK_LSA
)
3553 for (ALL_LIST_ELEMENTS_RO (ospf
->oiflist
, node
, oi
))
3555 /* Ignore virtual link. */
3556 if (oi
->type
!= OSPF_IFTYPE_VIRTUALLINK
)
3557 if (oi
->address
->family
== AF_INET
)
3558 if (IPV4_ADDR_SAME (&lsa
->data
->id
, &oi
->address
->u
.prefix4
))
3560 /* to make it easier later */
3561 SET_FLAG (lsa
->flags
, OSPF_LSA_SELF
);
3562 return CHECK_FLAG (lsa
->flags
, OSPF_LSA_SELF
);
3566 return CHECK_FLAG (lsa
->flags
, OSPF_LSA_SELF
);
3569 /* Get unique Link State ID. */
3571 ospf_lsa_unique_id (struct ospf
*ospf
,
3572 struct ospf_lsdb
*lsdb
, u_char type
, struct prefix_ipv4
*p
)
3574 struct ospf_lsa
*lsa
;
3575 struct in_addr mask
, id
;
3579 /* Check existence of LSA instance. */
3580 lsa
= ospf_lsdb_lookup_by_id (lsdb
, type
, id
, ospf
->router_id
);
3583 struct as_external_lsa
*al
= (struct as_external_lsa
*) lsa
->data
;
3584 if (ip_masklen (al
->mask
) == p
->prefixlen
)
3586 if (IS_DEBUG_OSPF (lsa
, LSA_GENERATE
))
3587 zlog_debug ("ospf_lsa_unique_id(): "
3588 "Can't get Link State ID for %s/%d",
3589 inet_ntoa (p
->prefix
), p
->prefixlen
);
3590 /* id.s_addr = 0; */
3591 id
.s_addr
= 0xffffffff;
3594 /* Masklen differs, then apply wildcard mask to Link State ID. */
3597 masklen2ip (p
->prefixlen
, &mask
);
3599 id
.s_addr
= p
->prefix
.s_addr
| (~mask
.s_addr
);
3600 lsa
= ospf_lsdb_lookup_by_id (ospf
->lsdb
, type
,
3601 id
, ospf
->router_id
);
3604 if (IS_DEBUG_OSPF (lsa
, LSA_GENERATE
))
3605 zlog_debug ("ospf_lsa_unique_id(): "
3606 "Can't get Link State ID for %s/%d",
3607 inet_ntoa (p
->prefix
), p
->prefixlen
);
3608 /* id.s_addr = 0; */
3609 id
.s_addr
= 0xffffffff;
3619 #define LSA_ACTION_FLOOD_AREA 1
3620 #define LSA_ACTION_FLUSH_AREA 2
3625 struct ospf_area
*area
;
3626 struct ospf_lsa
*lsa
;
3630 ospf_lsa_action (struct thread
*t
)
3632 struct lsa_action
*data
;
3634 data
= THREAD_ARG (t
);
3636 if (IS_DEBUG_OSPF (lsa
, LSA
) == OSPF_DEBUG_LSA
)
3637 zlog_debug ("LSA[Action]: Performing scheduled LSA action: %d",
3640 switch (data
->action
)
3642 case LSA_ACTION_FLOOD_AREA
:
3643 ospf_flood_through_area (data
->area
, NULL
, data
->lsa
);
3645 case LSA_ACTION_FLUSH_AREA
:
3646 ospf_lsa_flush_area (data
->lsa
, data
->area
);
3650 ospf_lsa_unlock (&data
->lsa
); /* Message */
3651 XFREE (MTYPE_OSPF_MESSAGE
, data
);
3656 ospf_schedule_lsa_flood_area (struct ospf_area
*area
, struct ospf_lsa
*lsa
)
3658 struct lsa_action
*data
;
3660 data
= XMALLOC (MTYPE_OSPF_MESSAGE
, sizeof (struct lsa_action
));
3661 memset (data
, 0, sizeof (struct lsa_action
));
3663 data
->action
= LSA_ACTION_FLOOD_AREA
;
3665 data
->lsa
= ospf_lsa_lock (lsa
); /* Message / Flood area */
3667 thread_add_event (master
, ospf_lsa_action
, data
, 0);
3671 ospf_schedule_lsa_flush_area (struct ospf_area
*area
, struct ospf_lsa
*lsa
)
3673 struct lsa_action
*data
;
3675 data
= XMALLOC (MTYPE_OSPF_MESSAGE
, sizeof (struct lsa_action
));
3676 memset (data
, 0, sizeof (struct lsa_action
));
3678 data
->action
= LSA_ACTION_FLUSH_AREA
;
3680 data
->lsa
= ospf_lsa_lock (lsa
); /* Message / Flush area */
3682 thread_add_event (master
, ospf_lsa_action
, data
, 0);
3686 /* LSA Refreshment functions. */
3688 ospf_lsa_refresh (struct ospf
*ospf
, struct ospf_lsa
*lsa
)
3690 struct external_info
*ei
;
3691 assert (CHECK_FLAG (lsa
->flags
, OSPF_LSA_SELF
));
3693 switch (lsa
->data
->type
)
3695 /* Router and Network LSAs are processed differently. */
3696 case OSPF_ROUTER_LSA
:
3697 case OSPF_NETWORK_LSA
:
3699 case OSPF_SUMMARY_LSA
:
3700 ospf_summary_lsa_refresh (ospf
, lsa
);
3702 case OSPF_ASBR_SUMMARY_LSA
:
3703 ospf_summary_asbr_lsa_refresh (ospf
, lsa
);
3705 case OSPF_AS_EXTERNAL_LSA
:
3706 /* Translated from NSSA Type-5s are refreshed when
3707 * from refresh of Type-7 - do not refresh these directly.
3709 if (CHECK_FLAG (lsa
->flags
, OSPF_LSA_LOCAL_XLT
))
3711 ei
= ospf_external_info_check (lsa
);
3713 ospf_external_lsa_refresh (ospf
, lsa
, ei
, LSA_REFRESH_FORCE
);
3715 ospf_lsa_flush_as (ospf
, lsa
);
3717 #ifdef HAVE_OPAQUE_LSA
3718 case OSPF_OPAQUE_LINK_LSA
:
3719 case OSPF_OPAQUE_AREA_LSA
:
3720 case OSPF_OPAQUE_AS_LSA
:
3721 ospf_opaque_lsa_refresh (lsa
);
3723 #endif /* HAVE_OPAQUE_LSA */
3730 ospf_refresher_register_lsa (struct ospf
*ospf
, struct ospf_lsa
*lsa
)
3732 u_int16_t index
, current_index
;
3734 assert (CHECK_FLAG (lsa
->flags
, OSPF_LSA_SELF
));
3736 if (lsa
->refresh_list
< 0)
3740 if (LS_AGE (lsa
) == 0 &&
3741 ntohl (lsa
->data
->ls_seqnum
) == OSPF_INITIAL_SEQUENCE_NUMBER
)
3742 /* Randomize first update by OSPF_LS_REFRESH_SHIFT factor */
3743 delay
= OSPF_LS_REFRESH_SHIFT
+ (random () % OSPF_LS_REFRESH_TIME
);
3745 /* Randomize another updates by +-OSPF_LS_REFRESH_JITTER factor */
3746 delay
= OSPF_LS_REFRESH_TIME
- LS_AGE (lsa
) - OSPF_LS_REFRESH_JITTER
3747 + (random () % (2*OSPF_LS_REFRESH_JITTER
));
3752 current_index
= ospf
->lsa_refresh_queue
.index
+
3753 (quagga_time (NULL
) - ospf
->lsa_refresher_started
)/OSPF_LSA_REFRESHER_GRANULARITY
;
3755 index
= (current_index
+ delay
/OSPF_LSA_REFRESHER_GRANULARITY
)
3756 % (OSPF_LSA_REFRESHER_SLOTS
);
3758 if (IS_DEBUG_OSPF (lsa
, LSA_REFRESH
))
3759 zlog_debug ("LSA[Refresh]: lsa %s with age %d added to index %d",
3760 inet_ntoa (lsa
->data
->id
), LS_AGE (lsa
), index
);
3761 if (!ospf
->lsa_refresh_queue
.qs
[index
])
3762 ospf
->lsa_refresh_queue
.qs
[index
] = list_new ();
3763 listnode_add (ospf
->lsa_refresh_queue
.qs
[index
],
3764 ospf_lsa_lock (lsa
)); /* lsa_refresh_queue */
3765 lsa
->refresh_list
= index
;
3766 if (IS_DEBUG_OSPF (lsa
, LSA_REFRESH
))
3767 zlog_debug ("LSA[Refresh:%s]: ospf_refresher_register_lsa(): "
3768 "setting refresh_list on lsa %p (slod %d)",
3769 inet_ntoa (lsa
->data
->id
), lsa
, index
);
3774 ospf_refresher_unregister_lsa (struct ospf
*ospf
, struct ospf_lsa
*lsa
)
3776 assert (CHECK_FLAG (lsa
->flags
, OSPF_LSA_SELF
));
3777 if (lsa
->refresh_list
>= 0)
3779 struct list
*refresh_list
= ospf
->lsa_refresh_queue
.qs
[lsa
->refresh_list
];
3780 listnode_delete (refresh_list
, lsa
);
3781 if (!listcount (refresh_list
))
3783 list_free (refresh_list
);
3784 ospf
->lsa_refresh_queue
.qs
[lsa
->refresh_list
] = NULL
;
3786 ospf_lsa_unlock (&lsa
); /* lsa_refresh_queue */
3787 lsa
->refresh_list
= -1;
3792 ospf_lsa_refresh_walker (struct thread
*t
)
3794 struct list
*refresh_list
;
3795 struct listnode
*node
, *nnode
;
3796 struct ospf
*ospf
= THREAD_ARG (t
);
3797 struct ospf_lsa
*lsa
;
3799 struct list
*lsa_to_refresh
= list_new ();
3801 if (IS_DEBUG_OSPF (lsa
, LSA_REFRESH
))
3802 zlog_debug ("LSA[Refresh]:ospf_lsa_refresh_walker(): start");
3805 i
= ospf
->lsa_refresh_queue
.index
;
3807 /* Note: if clock has jumped backwards, then time change could be negative,
3808 so we are careful to cast the expression to unsigned before taking
3810 ospf
->lsa_refresh_queue
.index
=
3811 ((unsigned long)(ospf
->lsa_refresh_queue
.index
+
3812 (quagga_time (NULL
) - ospf
->lsa_refresher_started
) /
3813 OSPF_LSA_REFRESHER_GRANULARITY
)) % OSPF_LSA_REFRESHER_SLOTS
;
3815 if (IS_DEBUG_OSPF (lsa
, LSA_REFRESH
))
3816 zlog_debug ("LSA[Refresh]: ospf_lsa_refresh_walker(): next index %d",
3817 ospf
->lsa_refresh_queue
.index
);
3819 for (;i
!= ospf
->lsa_refresh_queue
.index
;
3820 i
= (i
+ 1) % OSPF_LSA_REFRESHER_SLOTS
)
3822 if (IS_DEBUG_OSPF (lsa
, LSA_REFRESH
))
3823 zlog_debug ("LSA[Refresh]: ospf_lsa_refresh_walker(): "
3824 "refresh index %d", i
);
3826 refresh_list
= ospf
->lsa_refresh_queue
.qs
[i
];
3828 ospf
->lsa_refresh_queue
.qs
[i
] = NULL
;
3832 for (ALL_LIST_ELEMENTS (refresh_list
, node
, nnode
, lsa
))
3834 if (IS_DEBUG_OSPF (lsa
, LSA_REFRESH
))
3835 zlog_debug ("LSA[Refresh:%s]: ospf_lsa_refresh_walker(): "
3836 "refresh lsa %p (slot %d)",
3837 inet_ntoa (lsa
->data
->id
), lsa
, i
);
3839 list_delete_node (refresh_list
, node
);
3840 ospf_lsa_unlock (&lsa
); /* lsa_refresh_queue */
3841 lsa
->refresh_list
= -1;
3842 listnode_add (lsa_to_refresh
, lsa
);
3844 list_free (refresh_list
);
3848 ospf
->t_lsa_refresher
= thread_add_timer (master
, ospf_lsa_refresh_walker
,
3849 ospf
, ospf
->lsa_refresh_interval
);
3850 ospf
->lsa_refresher_started
= quagga_time (NULL
);
3852 for (ALL_LIST_ELEMENTS (lsa_to_refresh
, node
, nnode
, lsa
))
3853 ospf_lsa_refresh (ospf
, lsa
);
3855 list_delete (lsa_to_refresh
);
3857 if (IS_DEBUG_OSPF (lsa
, LSA_REFRESH
))
3858 zlog_debug ("LSA[Refresh]: ospf_lsa_refresh_walker(): end");