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 gettimeofday (&now
, NULL
);
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_info ("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
)
168 gettimeofday (&now
, NULL
);
169 age
= ntohs (lsa
->data
->ls_age
) + tv_floor (tv_sub (now
, lsa
->tv_recv
));
175 /* Fletcher Checksum -- Refer to RFC1008. */
177 #define LSA_CHECKSUM_OFFSET 15
180 ospf_lsa_checksum (struct lsa_header
*lsa
)
182 u_char
*sp
, *ep
, *p
, *q
;
188 length
= ntohs (lsa
->length
) - 2;
189 sp
= (char *) &lsa
->options
;
191 for (ep
= sp
+ length
; sp
< ep
; sp
= q
)
196 for (p
= sp
; p
< q
; p
++)
205 x
= ((length
- LSA_CHECKSUM_OFFSET
) * c0
- c1
) % 255;
212 /* take care endian issue. */
213 lsa
->checksum
= htons ((x
<< 8) + y
);
215 return (lsa
->checksum
);
220 /* Create OSPF LSA. */
224 struct ospf_lsa
*new;
226 new = XCALLOC (MTYPE_OSPF_LSA
, sizeof (struct ospf_lsa
));
227 memset (new, 0, sizeof (struct ospf_lsa
));
231 new->retransmit_counter
= 0;
232 gettimeofday (&new->tv_recv
, NULL
);
233 new->tv_orig
= new->tv_recv
;
234 new->refresh_list
= -1;
239 /* Duplicate OSPF LSA. */
241 ospf_lsa_dup (struct ospf_lsa
*lsa
)
243 struct ospf_lsa
*new;
248 new = XCALLOC (MTYPE_OSPF_LSA
, sizeof (struct ospf_lsa
));
250 memcpy (new, lsa
, sizeof (struct ospf_lsa
));
251 UNSET_FLAG (new->flags
, OSPF_LSA_DISCARD
);
253 new->retransmit_counter
= 0;
254 new->data
= ospf_lsa_data_dup (lsa
->data
);
256 /* kevinm: Clear the refresh_list, otherwise there are going
257 to be problems when we try to remove the LSA from the
258 queue (which it's not a member of.)
259 XXX: Should we add the LSA to the refresh_list queue? */
260 new->refresh_list
= -1;
262 if (IS_DEBUG_OSPF (lsa
, LSA
))
263 zlog_info ("LSA: duplicated %p (new: %p)", lsa
, new);
270 ospf_lsa_free (struct ospf_lsa
*lsa
)
272 assert (lsa
->lock
== 0);
274 if (IS_DEBUG_OSPF (lsa
, LSA
))
275 zlog_info ("LSA: freed %p", lsa
);
277 /* Delete LSA data. */
278 if (lsa
->data
!= NULL
)
279 ospf_lsa_data_free (lsa
->data
);
281 assert (lsa
->refresh_list
< 0);
283 memset (lsa
, 0, sizeof (struct ospf_lsa
));
284 XFREE (MTYPE_OSPF_LSA
, lsa
);
289 ospf_lsa_lock (struct ospf_lsa
*lsa
)
297 ospf_lsa_unlock (struct ospf_lsa
*lsa
)
299 /* This is sanity check. */
305 assert (lsa
->lock
>= 0);
309 assert (CHECK_FLAG (lsa
->flags
, OSPF_LSA_DISCARD
));
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_info ("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 ospf_output_forward (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
, OSPF_FLAG_ASBR
);
446 /* Lookup neighbor other than myself.
447 And check neighbor count,
448 Point-to-Point link must have only 1 neighbor. */
449 struct ospf_neighbor
*
450 ospf_nbr_lookup_ptop (struct ospf_interface
*oi
)
452 struct ospf_neighbor
*nbr
= NULL
;
453 struct route_node
*rn
;
455 /* Search neighbor, there must be one of two nbrs. */
456 for (rn
= route_top (oi
->nbrs
); rn
; rn
= route_next (rn
))
457 if ((nbr
= rn
->info
))
458 if (!IPV4_ADDR_SAME (&nbr
->router_id
, &oi
->ospf
->router_id
))
459 if (nbr
->state
== NSM_Full
)
461 route_unlock_node (rn
);
465 /* PtoP link must have only 1 neighbor. */
466 if (ospf_nbr_count (oi
, 0) > 1)
467 zlog_warn ("Point-to-Point link has more than 1 neighobrs.");
472 /* Set a link information. */
474 link_info_set (struct stream
*s
, struct in_addr id
,
475 struct in_addr data
, u_char type
, u_char tos
, u_int16_t cost
)
477 /* TOS based routing is not supported. */
478 stream_put_ipv4 (s
, id
.s_addr
); /* Link ID. */
479 stream_put_ipv4 (s
, data
.s_addr
); /* Link Data. */
480 stream_putc (s
, type
); /* Link Type. */
481 stream_putc (s
, tos
); /* TOS = 0. */
482 stream_putw (s
, cost
); /* Link Cost. */
485 /* Describe Point-to-Point link. */
487 lsa_link_ptop_set (struct stream
*s
, struct ospf_interface
*oi
)
490 struct ospf_neighbor
*nbr
;
491 struct in_addr id
, mask
;
493 if (IS_DEBUG_OSPF (lsa
, LSA_GENERATE
))
494 zlog_info ("LSA[Type1]: Set link Point-to-Point");
496 if ((nbr
= ospf_nbr_lookup_ptop (oi
)))
497 if (nbr
->state
== NSM_Full
)
499 /* For unnumbered point-to-point networks, the Link Data field
500 should specify the interface's MIB-II ifIndex value. */
501 link_info_set (s
, nbr
->router_id
, oi
->address
->u
.prefix4
,
502 LSA_LINK_TYPE_POINTOPOINT
, 0, oi
->output_cost
);
506 if (oi
->connected
->destination
!= NULL
)
509 link_type = LSA_LINK_TYPE_STUB;
510 link_id = nbr->address.u.prefix4;
511 link_data.s_addr = 0xffffffff;
512 link_cost = o->output_cost; */
514 id
.s_addr
= oi
->connected
->destination
->u
.prefix4
.s_addr
;
515 mask
.s_addr
= 0xffffffff;
516 link_info_set (s
, id
, mask
, LSA_LINK_TYPE_STUB
, 0, oi
->output_cost
);
520 /* Option 2: We need to include link to a stub
521 network regardless of the state of the neighbor */
522 masklen2ip (oi
->address
->prefixlen
, &mask
);
523 id
.s_addr
= oi
->address
->u
.prefix4
.s_addr
& mask
.s_addr
;
524 link_info_set (s
, id
, mask
, LSA_LINK_TYPE_STUB
, 0, oi
->output_cost
);
531 /* Describe Broadcast Link. */
533 lsa_link_broadcast_set (struct stream
*s
, struct ospf_interface
*oi
)
535 struct ospf_neighbor
*dr
;
536 struct in_addr id
, mask
;
538 /* Describe Type 3 Link. */
539 if (oi
->state
== ISM_Waiting
)
541 masklen2ip (oi
->address
->prefixlen
, &mask
);
542 id
.s_addr
= oi
->address
->u
.prefix4
.s_addr
& mask
.s_addr
;
543 link_info_set (s
, id
, mask
, LSA_LINK_TYPE_STUB
, 0, oi
->output_cost
);
547 dr
= ospf_nbr_lookup_by_addr (oi
->nbrs
, &DR (oi
));
548 /* Describe Type 2 link. */
549 if (dr
&& (dr
->state
== NSM_Full
||
550 IPV4_ADDR_SAME (&oi
->address
->u
.prefix4
, &DR (oi
))) &&
551 ospf_nbr_count (oi
, NSM_Full
) > 0)
553 link_info_set (s
, DR (oi
), oi
->address
->u
.prefix4
,
554 LSA_LINK_TYPE_TRANSIT
, 0, oi
->output_cost
);
556 /* Describe type 3 link. */
559 masklen2ip (oi
->address
->prefixlen
, &mask
);
560 id
.s_addr
= oi
->address
->u
.prefix4
.s_addr
& mask
.s_addr
;
561 link_info_set (s
, id
, mask
, LSA_LINK_TYPE_STUB
, 0, oi
->output_cost
);
567 lsa_link_loopback_set (struct stream
*s
, struct ospf_interface
*oi
)
569 struct in_addr id
, mask
;
571 /* Describe Type 3 Link. */
572 if (oi
->state
!= ISM_Loopback
)
575 mask
.s_addr
= 0xffffffff;
576 id
.s_addr
= oi
->address
->u
.prefix4
.s_addr
;
577 link_info_set (s
, id
, mask
, LSA_LINK_TYPE_STUB
, 0, oi
->output_cost
);
581 /* Describe Virtual Link. */
583 lsa_link_virtuallink_set (struct stream
*s
, struct ospf_interface
*oi
)
585 struct ospf_neighbor
*nbr
;
587 if (oi
->state
== ISM_PointToPoint
)
588 if ((nbr
= ospf_nbr_lookup_ptop (oi
)))
589 if (nbr
->state
== NSM_Full
)
591 link_info_set (s
, nbr
->router_id
, oi
->address
->u
.prefix4
,
592 LSA_LINK_TYPE_VIRTUALLINK
, 0, oi
->output_cost
);
599 #define lsa_link_nbma_set(S,O) lsa_link_broadcast_set (S, O)
601 /* This function add for support point-to-multipoint ,see RFC2328
604 lsa_link_ptomp_set (struct stream
*s
, struct ospf_interface
*oi
)
607 struct route_node
*rn
;
608 struct ospf_neighbor
*nbr
= NULL
;
609 struct in_addr id
, mask
;
611 mask
.s_addr
= 0xffffffff;
612 id
.s_addr
= oi
->address
->u
.prefix4
.s_addr
;
613 link_info_set (s
, id
, mask
, LSA_LINK_TYPE_STUB
, 0, 0);
616 zlog_info ("PointToMultipoint: running ptomultip_set");
618 /* Search neighbor, */
619 for (rn
= route_top (oi
->nbrs
); rn
; rn
= route_next (rn
))
620 if ((nbr
= rn
->info
) != NULL
)
622 if (!IPV4_ADDR_SAME (&nbr
->router_id
, &oi
->ospf
->router_id
))
623 if (nbr
->state
== NSM_Full
)
626 link_info_set (s
, nbr
->router_id
, oi
->address
->u
.prefix4
,
627 LSA_LINK_TYPE_POINTOPOINT
, 0, oi
->output_cost
);
629 zlog_info ("PointToMultipoint: set link to %s",
630 inet_ntoa(oi
->address
->u
.prefix4
));
636 /* Set router-LSA link information. */
638 router_lsa_link_set (struct stream
*s
, struct ospf_area
*area
)
643 for (node
= listhead (area
->oiflist
); node
; node
= nextnode (node
))
645 struct ospf_interface
*oi
= node
->data
;
646 struct interface
*ifp
= oi
->ifp
;
648 /* Check interface is up, OSPF is enable. */
651 if (oi
->state
!= ISM_Down
)
653 /* Describe each link. */
656 case OSPF_IFTYPE_POINTOPOINT
:
657 links
+= lsa_link_ptop_set (s
, oi
);
659 case OSPF_IFTYPE_BROADCAST
:
660 links
+= lsa_link_broadcast_set (s
, oi
);
662 case OSPF_IFTYPE_NBMA
:
663 links
+= lsa_link_nbma_set (s
, oi
);
665 case OSPF_IFTYPE_POINTOMULTIPOINT
:
666 links
+= lsa_link_ptomp_set (s
, oi
);
668 case OSPF_IFTYPE_VIRTUALLINK
:
669 links
+= lsa_link_virtuallink_set (s
, oi
);
671 case OSPF_IFTYPE_LOOPBACK
:
672 links
+= lsa_link_loopback_set (s
, oi
);
681 /* Set router-LSA body. */
683 ospf_router_lsa_body_set (struct stream
*s
, struct ospf_area
*area
)
689 stream_putc (s
, router_lsa_flags (area
));
691 /* Set Zero fields. */
694 /* Keep pointer to # links. */
700 /* Set all link information. */
701 cnt
= router_lsa_link_set (s
, area
);
703 /* Set # of links here. */
704 stream_putw_at (s
, putp
, cnt
);
707 /* Create new router-LSA. */
709 ospf_router_lsa_new (struct ospf_area
*area
)
711 struct ospf
*ospf
= area
->ospf
;
713 struct lsa_header
*lsah
;
714 struct ospf_lsa
*new;
717 if (IS_DEBUG_OSPF (lsa
, LSA_GENERATE
))
718 zlog_info ("LSA[Type1]: Create router-LSA instance");
720 /* Create a stream for LSA. */
721 s
= stream_new (OSPF_MAX_LSA_SIZE
);
722 lsah
= (struct lsa_header
*) STREAM_DATA (s
);
725 /* Set LSA common header fields. */
726 lsa_header_set (s
, LSA_OPTIONS_GET (area
) | LSA_NSSA_GET (area
),
727 OSPF_ROUTER_LSA
, ospf
->router_id
, ospf
->router_id
);
728 #else /* ! HAVE_NSSA */
729 /* Set LSA common header fields. */
730 lsa_header_set (s
, LSA_OPTIONS_GET (area
),
731 OSPF_ROUTER_LSA
, ospf
->router_id
, ospf
->router_id
);
732 #endif /* HAVE_NSSA */
734 /* Set router-LSA body fields. */
735 ospf_router_lsa_body_set (s
, area
);
738 length
= stream_get_endp (s
);
739 lsah
->length
= htons (length
);
741 /* Now, create OSPF LSA instance. */
742 new = ospf_lsa_new ();
744 SET_FLAG (new->flags
, OSPF_LSA_SELF
);
746 /* Copy LSA data to store, discard stream. */
747 new->data
= ospf_lsa_data_new (length
);
748 memcpy (new->data
, lsah
, length
);
754 /* Originate Router-LSA. */
756 ospf_router_lsa_originate (struct ospf_area
*area
)
758 struct ospf_lsa
*new;
760 /* Create new router-LSA instance. */
761 new = ospf_router_lsa_new (area
);
764 if (new->data
->adv_router
.s_addr
== 0)
766 if (IS_DEBUG_OSPF_EVENT
)
767 zlog_info ("LSA[Type1]: AdvRouter is 0, discard");
768 ospf_lsa_discard (new);
772 /* Install LSA to LSDB. */
773 new = ospf_lsa_install (area
->ospf
, NULL
, new);
775 /* Update LSA origination count. */
776 area
->ospf
->lsa_originate_count
++;
778 /* Flooding new LSA through area. */
779 ospf_flood_through_area (area
, NULL
, new);
781 if (IS_DEBUG_OSPF (lsa
, LSA_GENERATE
))
783 zlog_info ("LSA[Type%d:%s]: Originate router-LSA %p",
784 new->data
->type
, inet_ntoa (new->data
->id
), new);
785 ospf_lsa_header_dump (new->data
);
791 /* Refresh router-LSA. */
793 ospf_router_lsa_refresh (struct ospf_lsa
*lsa
)
795 struct ospf_area
*area
= lsa
->area
;
796 struct ospf_lsa
*new;
801 /* Delete LSA from neighbor retransmit-list. */
802 ospf_ls_retransmit_delete_nbr_area (area
, lsa
);
804 /* Create new router-LSA instance. */
805 new = ospf_router_lsa_new (area
);
806 new->data
->ls_seqnum
= lsa_seqnum_increment (lsa
);
808 ospf_lsa_install (area
->ospf
, NULL
, new);
810 /* Flood LSA through area. */
811 ospf_flood_through_area (area
, NULL
, new);
814 if (IS_DEBUG_OSPF (lsa
, LSA_GENERATE
))
816 zlog_info ("LSA[Type%d:%s]: router-LSA refresh",
817 new->data
->type
, inet_ntoa (new->data
->id
));
818 ospf_lsa_header_dump (new->data
);
825 ospf_router_lsa_timer (struct thread
*t
)
827 struct ospf_area
*area
;
829 if (IS_DEBUG_OSPF_EVENT
)
830 zlog_info ("Timer[router-LSA]: (router-LSA Refresh expire)");
832 area
= THREAD_ARG (t
);
833 area
->t_router_lsa_self
= NULL
;
835 /* Now refresh router-LSA. */
836 if (area
->router_lsa_self
)
837 ospf_router_lsa_refresh (area
->router_lsa_self
);
838 /* Newly originate router-LSA. */
840 ospf_router_lsa_originate (area
);
846 ospf_router_lsa_timer_add (struct ospf_area
*area
)
848 /* Keep area's self-originated router-LSA. */
849 struct ospf_lsa
*lsa
= area
->router_lsa_self
;
851 /* Cancel previously scheduled router-LSA timer. */
852 if (area
->t_router_lsa_self
)
853 if (IS_DEBUG_OSPF (lsa
, LSA_GENERATE
))
854 zlog_info ("LSA[Type1]: Cancel previous router-LSA timer");
856 OSPF_TIMER_OFF (area
->t_router_lsa_self
);
858 /* If router-LSA is originated previously, check the interval time. */
862 if ((delay
= ospf_lsa_refresh_delay (lsa
)) > 0)
864 OSPF_AREA_TIMER_ON (area
->t_router_lsa_self
,
865 ospf_router_lsa_timer
, delay
);
870 if (IS_DEBUG_OSPF (lsa
, LSA_GENERATE
))
871 zlog_info ("LSA[Type1]: Scheduling router-LSA origination right away");
873 /* Immediately refresh router-LSA. */
874 OSPF_AREA_TIMER_ON (area
->t_router_lsa_self
, ospf_router_lsa_timer
, 0);
878 ospf_router_lsa_update_timer (struct thread
*thread
)
880 struct ospf
*ospf
= THREAD_ARG (thread
);
883 if (IS_DEBUG_OSPF (lsa
, LSA_GENERATE
))
884 zlog_info ("Timer[router-LSA Update]: (timer expire)");
886 ospf
->t_router_lsa_update
= NULL
;
888 for (node
= listhead (ospf
->areas
); node
; nextnode (node
))
890 struct ospf_area
*area
= getdata (node
);
891 struct ospf_lsa
*lsa
= area
->router_lsa_self
;
892 struct router_lsa
*rl
;
895 /* Keep Area ID string. */
896 area_str
= AREA_NAME (area
);
898 /* If LSA not exist in this Area, originate new. */
901 if (IS_DEBUG_OSPF (lsa
, LSA_GENERATE
))
902 zlog_info("LSA[Type1]: Create router-LSA for Area %s", area_str
);
904 ospf_router_lsa_originate (area
);
906 /* If router-ID is changed, Link ID must change.
907 First flush old LSA, then originate new. */
908 else if (!IPV4_ADDR_SAME (&lsa
->data
->id
, &ospf
->router_id
))
910 if (IS_DEBUG_OSPF (lsa
, LSA_GENERATE
))
911 zlog_info("LSA[Type%d:%s]: Refresh router-LSA for Area %s",
912 lsa
->data
->type
, inet_ntoa (lsa
->data
->id
), area_str
);
913 ospf_lsa_flush_area (lsa
, area
);
914 ospf_lsa_unlock (area
->router_lsa_self
);
915 area
->router_lsa_self
= NULL
;
917 /* Refresh router-LSA, (not install) and flood through area. */
918 ospf_router_lsa_timer_add (area
);
922 rl
= (struct router_lsa
*) lsa
->data
;
923 /* Refresh router-LSA, (not install) and flood through area. */
924 if (rl
->flags
!= ospf
->flags
)
925 ospf_router_lsa_timer_add (area
);
933 /* network-LSA related functions. */
934 /* Originate Network-LSA. */
936 ospf_network_lsa_body_set (struct stream
*s
, struct ospf_interface
*oi
)
939 struct route_node
*rn
;
940 struct ospf_neighbor
*nbr
;
942 masklen2ip (oi
->address
->prefixlen
, &mask
);
943 stream_put_ipv4 (s
, mask
.s_addr
);
945 /* The network-LSA lists those routers that are fully adjacent to
946 the Designated Router; each fully adjacent router is identified by
947 its OSPF Router ID. The Designated Router includes itself in this
948 list. RFC2328, Section 12.4.2 */
950 for (rn
= route_top (oi
->nbrs
); rn
; rn
= route_next (rn
))
951 if ((nbr
= rn
->info
) != NULL
)
952 if (nbr
->state
== NSM_Full
|| nbr
== oi
->nbr_self
)
953 stream_put_ipv4 (s
, nbr
->router_id
.s_addr
);
957 ospf_network_lsa_new (struct ospf_interface
*oi
)
960 struct ospf_lsa
*new;
961 struct lsa_header
*lsah
;
964 /* If there are no neighbours on this network (the net is stub),
965 the router does not originate network-LSA (see RFC 12.4.2) */
966 if (oi
->full_nbrs
== 0)
969 if (IS_DEBUG_OSPF (lsa
, LSA_GENERATE
))
970 zlog_info ("LSA[Type2]: Create network-LSA instance");
972 /* Create new stream for LSA. */
973 s
= stream_new (OSPF_MAX_LSA_SIZE
);
974 lsah
= (struct lsa_header
*) STREAM_DATA (s
);
976 lsa_header_set (s
, (OPTIONS (oi
) | LSA_OPTIONS_GET (oi
->area
)),
977 OSPF_NETWORK_LSA
, DR (oi
), oi
->ospf
->router_id
);
979 /* Set network-LSA body fields. */
980 ospf_network_lsa_body_set (s
, oi
);
983 length
= stream_get_endp (s
);
984 lsah
->length
= htons (length
);
986 /* Create OSPF LSA instance. */
987 new = ospf_lsa_new ();
988 new->area
= oi
->area
;
989 SET_FLAG (new->flags
, OSPF_LSA_SELF
);
991 /* Copy LSA to store. */
992 new->data
= ospf_lsa_data_new (length
);
993 memcpy (new->data
, lsah
, length
);
999 /* Originate network-LSA. */
1001 ospf_network_lsa_originate (struct ospf_interface
*oi
)
1003 struct ospf_lsa
*new;
1005 /* Create new network-LSA instance. */
1006 new = ospf_network_lsa_new (oi
);
1010 /* Install LSA to LSDB. */
1011 new = ospf_lsa_install (oi
->ospf
, oi
, new);
1013 /* Update LSA origination count. */
1014 oi
->ospf
->lsa_originate_count
++;
1016 /* Flooding new LSA through area. */
1017 ospf_flood_through_area (oi
->area
, NULL
, new);
1019 if (IS_DEBUG_OSPF (lsa
, LSA_GENERATE
))
1021 zlog_info ("LSA[Type%d:%s]: Originate network-LSA %p",
1022 new->data
->type
, inet_ntoa (new->data
->id
), new);
1023 ospf_lsa_header_dump (new->data
);
1030 ospf_network_lsa_refresh (struct ospf_lsa
*lsa
, struct ospf_interface
*oi
)
1032 struct ospf_area
*area
= lsa
->area
;
1033 struct ospf_lsa
*new;
1037 /* Delete LSA from neighbor retransmit-list. */
1038 ospf_ls_retransmit_delete_nbr_area (area
, lsa
);
1040 /* Create new network-LSA instance. */
1041 new = ospf_network_lsa_new (oi
);
1044 new->data
->ls_seqnum
= lsa_seqnum_increment (lsa
);
1046 ospf_lsa_install (area
->ospf
, oi
, new);
1048 /* Flood LSA through aera. */
1049 ospf_flood_through_area (area
, NULL
, new);
1051 if (IS_DEBUG_OSPF (lsa
, LSA_GENERATE
))
1053 zlog_info ("LSA[Type%d:%s]: network-LSA refresh",
1054 new->data
->type
, inet_ntoa (new->data
->id
));
1055 ospf_lsa_header_dump (new->data
);
1062 ospf_network_lsa_refresh_timer (struct thread
*t
)
1064 struct ospf_interface
*oi
;
1066 oi
= THREAD_ARG (t
);
1067 oi
->t_network_lsa_self
= NULL
;
1069 if (oi
->network_lsa_self
)
1070 /* Now refresh network-LSA. */
1071 ospf_network_lsa_refresh (oi
->network_lsa_self
, oi
);
1073 /* Newly create network-LSA. */
1074 ospf_network_lsa_originate (oi
);
1080 ospf_network_lsa_timer_add (struct ospf_interface
*oi
)
1082 /* Keep interface's self-originated network-LSA. */
1083 struct ospf_lsa
*lsa
= oi
->network_lsa_self
;
1085 /* Cancel previously schedules network-LSA timer. */
1086 if (oi
->t_network_lsa_self
)
1087 if (IS_DEBUG_OSPF (lsa
, LSA_GENERATE
))
1088 zlog_info ("LSA[Type2]: Cancel previous network-LSA timer");
1089 OSPF_TIMER_OFF (oi
->t_network_lsa_self
);
1091 /* If network-LSA is originated previously, check the interval time. */
1095 if ((delay
= ospf_lsa_refresh_delay (lsa
)) > 0)
1097 oi
->t_network_lsa_self
=
1098 thread_add_timer (master
, ospf_network_lsa_refresh_timer
,
1104 if (IS_DEBUG_OSPF (lsa
, LSA_GENERATE
))
1105 zlog_info ("Scheduling network-LSA origination right away");
1107 /* Immediately refresh network-LSA. */
1108 oi
->t_network_lsa_self
=
1109 thread_add_event (master
, ospf_network_lsa_refresh_timer
, oi
, 0);
1114 stream_put_ospf_metric (struct stream
*s
, u_int32_t metric_value
)
1119 /* Put 0 metric. TOS metric is not supported. */
1120 metric
= htonl (metric_value
);
1121 mp
= (char *) &metric
;
1123 stream_put (s
, mp
, 3);
1126 /* summary-LSA related functions. */
1128 ospf_summary_lsa_body_set (struct stream
*s
, struct prefix
*p
,
1131 struct in_addr mask
;
1133 masklen2ip (p
->prefixlen
, &mask
);
1135 /* Put Network Mask. */
1136 stream_put_ipv4 (s
, mask
.s_addr
);
1139 stream_putc (s
, (u_char
) 0);
1142 stream_put_ospf_metric (s
, metric
);
1146 ospf_summary_lsa_new (struct ospf_area
*area
, struct prefix
*p
,
1147 u_int32_t metric
, struct in_addr id
)
1150 struct ospf_lsa
*new;
1151 struct lsa_header
*lsah
;
1154 if (IS_DEBUG_OSPF (lsa
, LSA_GENERATE
))
1155 zlog_info ("LSA[Type3]: Create summary-LSA instance");
1157 /* Create new stream for LSA. */
1158 s
= stream_new (OSPF_MAX_LSA_SIZE
);
1159 lsah
= (struct lsa_header
*) STREAM_DATA (s
);
1161 lsa_header_set (s
, LSA_OPTIONS_GET (area
), OSPF_SUMMARY_LSA
,
1162 id
, area
->ospf
->router_id
);
1164 /* Set summary-LSA body fields. */
1165 ospf_summary_lsa_body_set (s
, p
, metric
);
1168 length
= stream_get_endp (s
);
1169 lsah
->length
= htons (length
);
1171 /* Create OSPF LSA instance. */
1172 new = ospf_lsa_new ();
1174 SET_FLAG (new->flags
, OSPF_LSA_SELF
);
1176 /* Copy LSA to store. */
1177 new->data
= ospf_lsa_data_new (length
);
1178 memcpy (new->data
, lsah
, length
);
1184 /* Originate Summary-LSA. */
1186 ospf_summary_lsa_originate (struct prefix_ipv4
*p
, u_int32_t metric
,
1187 struct ospf_area
*area
)
1189 struct ospf_lsa
*new;
1192 id
= ospf_lsa_unique_id (area
->ospf
, area
->lsdb
, OSPF_SUMMARY_LSA
, p
);
1194 /* Create new summary-LSA instance. */
1195 new = ospf_summary_lsa_new (area
, (struct prefix
*) p
, metric
, id
);
1197 /* Instlal LSA to LSDB. */
1198 new = ospf_lsa_install (area
->ospf
, NULL
, new);
1200 /* Update LSA origination count. */
1201 area
->ospf
->lsa_originate_count
++;
1203 /* Flooding new LSA through area. */
1204 ospf_flood_through_area (area
, NULL
, new);
1206 if (IS_DEBUG_OSPF (lsa
, LSA_GENERATE
))
1208 zlog_info ("LSA[Type%d:%s]: Originate summary-LSA %p",
1209 new->data
->type
, inet_ntoa (new->data
->id
), new);
1210 ospf_lsa_header_dump (new->data
);
1217 ospf_summary_lsa_refresh (struct ospf
*ospf
, struct ospf_lsa
*lsa
)
1219 struct ospf_lsa
*new;
1220 struct summary_lsa
*sl
;
1226 sl
= (struct summary_lsa
*)lsa
->data
;
1227 p
.prefixlen
= ip_masklen (sl
->mask
);
1228 new = ospf_summary_lsa_new (lsa
->area
, &p
, GET_METRIC (sl
->metric
),
1231 new->data
->ls_seqnum
= lsa_seqnum_increment (lsa
);
1233 /* Re-calculate checksum. */
1234 ospf_lsa_checksum (new->data
);
1236 ospf_lsa_install (ospf
, NULL
, new);
1238 /* Flood LSA through AS. */
1239 ospf_flood_through_area (new->area
, NULL
, new);
1241 /* Debug logging. */
1242 if (IS_DEBUG_OSPF (lsa
, LSA_GENERATE
))
1244 zlog_info ("LSA[Type%d:%s]: summary-LSA refresh",
1245 new->data
->type
, inet_ntoa (new->data
->id
));
1246 ospf_lsa_header_dump (new->data
);
1253 /* summary-ASBR-LSA related functions. */
1255 ospf_summary_asbr_lsa_body_set (struct stream
*s
, struct prefix
*p
,
1258 struct in_addr mask
;
1260 masklen2ip (p
->prefixlen
, &mask
);
1262 /* Put Network Mask. */
1263 stream_put_ipv4 (s
, mask
.s_addr
);
1266 stream_putc (s
, (u_char
) 0);
1269 stream_put_ospf_metric (s
, metric
);
1273 ospf_summary_asbr_lsa_new (struct ospf_area
*area
, struct prefix
*p
,
1274 u_int32_t metric
, struct in_addr id
)
1277 struct ospf_lsa
*new;
1278 struct lsa_header
*lsah
;
1281 if (IS_DEBUG_OSPF (lsa
, LSA_GENERATE
))
1282 zlog_info ("LSA[Type3]: Create summary-LSA instance");
1284 /* Create new stream for LSA. */
1285 s
= stream_new (OSPF_MAX_LSA_SIZE
);
1286 lsah
= (struct lsa_header
*) STREAM_DATA (s
);
1288 lsa_header_set (s
, LSA_OPTIONS_GET (area
), OSPF_ASBR_SUMMARY_LSA
,
1289 id
, area
->ospf
->router_id
);
1291 /* Set summary-LSA body fields. */
1292 ospf_summary_asbr_lsa_body_set (s
, p
, metric
);
1295 length
= stream_get_endp (s
);
1296 lsah
->length
= htons (length
);
1298 /* Create OSPF LSA instance. */
1299 new = ospf_lsa_new ();
1301 SET_FLAG (new->flags
, OSPF_LSA_SELF
);
1303 /* Copy LSA to store. */
1304 new->data
= ospf_lsa_data_new (length
);
1305 memcpy (new->data
, lsah
, length
);
1311 /* Originate summary-ASBR-LSA. */
1313 ospf_summary_asbr_lsa_originate (struct prefix_ipv4
*p
, u_int32_t metric
,
1314 struct ospf_area
*area
)
1316 struct ospf_lsa
*new;
1319 id
= ospf_lsa_unique_id (area
->ospf
, area
->lsdb
, OSPF_ASBR_SUMMARY_LSA
, p
);
1321 /* Create new summary-LSA instance. */
1322 new = ospf_summary_asbr_lsa_new (area
, (struct prefix
*) p
, metric
, id
);
1324 /* Install LSA to LSDB. */
1325 new = ospf_lsa_install (area
->ospf
, NULL
, new);
1327 /* Update LSA origination count. */
1328 area
->ospf
->lsa_originate_count
++;
1330 /* Flooding new LSA through area. */
1331 ospf_flood_through_area (area
, NULL
, new);
1333 if (IS_DEBUG_OSPF (lsa
, LSA_GENERATE
))
1335 zlog_info ("LSA[Type%d:%s]: Originate summary-ASBR-LSA %p",
1336 new->data
->type
, inet_ntoa (new->data
->id
), new);
1337 ospf_lsa_header_dump (new->data
);
1344 ospf_summary_asbr_lsa_refresh (struct ospf
*ospf
, struct ospf_lsa
*lsa
)
1346 struct ospf_lsa
*new;
1347 struct summary_lsa
*sl
;
1353 sl
= (struct summary_lsa
*)lsa
->data
;
1354 p
.prefixlen
= ip_masklen (sl
->mask
);
1355 new = ospf_summary_asbr_lsa_new (lsa
->area
, &p
, GET_METRIC (sl
->metric
),
1358 new->data
->ls_seqnum
= lsa_seqnum_increment (lsa
);
1360 /* Re-calculate checksum. */
1361 ospf_lsa_checksum (new->data
);
1363 ospf_lsa_install (ospf
, NULL
, new);
1365 /* Flood LSA through area. */
1366 ospf_flood_through_area (new->area
, NULL
, new);
1368 if (IS_DEBUG_OSPF (lsa
, LSA_GENERATE
))
1370 zlog_info ("LSA[Type%d:%s]: summary-ASBR-LSA refresh",
1371 new->data
->type
, inet_ntoa (new->data
->id
));
1372 ospf_lsa_header_dump (new->data
);
1378 /* AS-external-LSA related functions. */
1380 /* Get nexthop for AS-external-LSAs. Return nexthop if its interface
1381 is connected, else 0*/
1383 ospf_external_lsa_nexthop_get (struct ospf
*ospf
, struct in_addr nexthop
)
1391 if (!nexthop
.s_addr
)
1394 /* Check whether nexthop is covered by OSPF network. */
1395 nh
.family
= AF_INET
;
1396 nh
.u
.prefix4
= nexthop
;
1397 nh
.prefixlen
= IPV4_MAX_BITLEN
;
1399 for (n1
= listhead (ospf
->oiflist
); n1
; nextnode (n1
))
1401 struct ospf_interface
*oi
= getdata (n1
);
1403 if (if_is_up (oi
->ifp
))
1404 if (oi
->address
->family
== AF_INET
)
1405 if (prefix_match (oi
->address
, &nh
))
1413 /* NSSA-external-LSA related functions. */
1415 /* Get 1st IP connection for Forward Addr */
1418 ospf_get_ip_from_ifp (struct ospf_interface
*oi
)
1424 if (if_is_up (oi
->ifp
))
1425 return oi
->address
->u
.prefix4
;
1430 /* Get 1st IP connection for Forward Addr */
1432 ospf_get_nssa_ip (struct ospf_area
*area
)
1435 struct in_addr best_default
;
1439 best_default
.s_addr
= 0;
1441 for (n1
= listhead (area
->ospf
->oiflist
); n1
; nextnode (n1
))
1443 struct ospf_interface
*oi
= getdata (n1
);
1445 if (if_is_up (oi
->ifp
))
1446 if (oi
->area
->external_routing
== OSPF_AREA_NSSA
)
1447 if (oi
->address
&& oi
->address
->family
== AF_INET
)
1449 if (best_default
.s_addr
== 0)
1450 best_default
= oi
->address
->u
.prefix4
;
1451 if (oi
->area
== area
)
1452 return oi
->address
->u
.prefix4
;
1456 if (best_default
.s_addr
!= 0)
1457 return best_default
;
1461 #endif /* HAVE_NSSA */
1463 #define DEFAULT_DEFAULT_METRIC 20
1464 #define DEFAULT_DEFAULT_ORIGINATE_METRIC 10
1465 #define DEFAULT_DEFAULT_ALWAYS_METRIC 1
1467 #define DEFAULT_METRIC_TYPE EXTERNAL_METRIC_TYPE_2
1470 metric_type (struct ospf
*ospf
, u_char src
)
1472 return (ospf
->dmetric
[src
].type
< 0 ?
1473 DEFAULT_METRIC_TYPE
: ospf
->dmetric
[src
].type
);
1477 metric_value (struct ospf
*ospf
, u_char src
)
1479 if (ospf
->dmetric
[src
].value
< 0)
1481 if (src
== DEFAULT_ROUTE
)
1483 if (ospf
->default_originate
== DEFAULT_ORIGINATE_ZEBRA
)
1484 return DEFAULT_DEFAULT_ORIGINATE_METRIC
;
1486 return DEFAULT_DEFAULT_ALWAYS_METRIC
;
1488 else if (ospf
->default_metric
< 0)
1489 return DEFAULT_DEFAULT_METRIC
;
1491 return ospf
->default_metric
;
1494 return ospf
->dmetric
[src
].value
;
1497 /* Set AS-external-LSA body. */
1499 ospf_external_lsa_body_set (struct stream
*s
, struct external_info
*ei
,
1502 struct prefix_ipv4
*p
= &ei
->p
;
1503 struct in_addr mask
, fwd_addr
;
1508 /* Put Network Mask. */
1509 masklen2ip (p
->prefixlen
, &mask
);
1510 stream_put_ipv4 (s
, mask
.s_addr
);
1512 /* If prefix is default, specify DEFAULT_ROUTE. */
1513 type
= is_prefix_default (&ei
->p
) ? DEFAULT_ROUTE
: ei
->type
;
1515 mtype
= (ROUTEMAP_METRIC_TYPE (ei
) != -1) ?
1516 ROUTEMAP_METRIC_TYPE (ei
) : metric_type (ospf
, type
);
1518 mvalue
= (ROUTEMAP_METRIC (ei
) != -1) ?
1519 ROUTEMAP_METRIC (ei
) : metric_value (ospf
, type
);
1521 /* Put type of external metric. */
1522 stream_putc (s
, (mtype
== EXTERNAL_METRIC_TYPE_2
? 0x80 : 0));
1524 /* Put 0 metric. TOS metric is not supported. */
1525 stream_put_ospf_metric (s
, mvalue
);
1527 /* Get forwarding address to nexthop if on the Connection List, else 0. */
1528 fwd_addr
= ospf_external_lsa_nexthop_get (ospf
, ei
->nexthop
);
1530 /* Put forwarding address. */
1531 stream_put_ipv4 (s
, fwd_addr
.s_addr
);
1533 /* Put route tag -- This value should be introduced from configuration. */
1537 /* Create new external-LSA. */
1539 ospf_external_lsa_new (struct ospf
*ospf
,
1540 struct external_info
*ei
, struct in_addr
*old_id
)
1543 struct lsa_header
*lsah
;
1544 struct ospf_lsa
*new;
1550 if (IS_DEBUG_OSPF (lsa
, LSA_GENERATE
))
1551 zlog_warn ("LSA[Type5]: External info is NULL, could not originated");
1555 if (IS_DEBUG_OSPF (lsa
, LSA_GENERATE
))
1556 zlog_info ("LSA[Type5]: Originate AS-external-LSA instance");
1558 /* If old Link State ID is specified, refresh LSA with same ID. */
1561 /* Get Link State with unique ID. */
1564 id
= ospf_lsa_unique_id (ospf
, ospf
->lsdb
, OSPF_AS_EXTERNAL_LSA
, &ei
->p
);
1565 if (id
.s_addr
== 0xffffffff)
1567 /* Maybe Link State ID not available. */
1568 if (IS_DEBUG_OSPF (lsa
, LSA_GENERATE
))
1569 zlog_info ("LSA[Type5]: Link ID not available, can't originate");
1574 /* Create new stream for LSA. */
1575 s
= stream_new (OSPF_MAX_LSA_SIZE
);
1576 lsah
= (struct lsa_header
*) STREAM_DATA (s
);
1578 /* Set LSA common header fields. */
1579 lsa_header_set (s
, OSPF_OPTION_E
, OSPF_AS_EXTERNAL_LSA
,
1580 id
, ospf
->router_id
);
1582 /* Set AS-external-LSA body fields. */
1583 ospf_external_lsa_body_set (s
, ei
, ospf
);
1586 length
= stream_get_endp (s
);
1587 lsah
->length
= htons (length
);
1589 /* Now, create OSPF LSA instance. */
1590 new = ospf_lsa_new ();
1592 SET_FLAG (new->flags
, OSPF_LSA_SELF
|OSPF_LSA_APPROVED
);
1594 /* Copy LSA data to store, discard stream. */
1595 new->data
= ospf_lsa_data_new (length
);
1596 memcpy (new->data
, lsah
, length
);
1605 ospf_install_flood_nssa (struct ospf
*ospf
,
1606 struct ospf_lsa
*lsa
, struct external_info
*ei
)
1608 struct ospf_lsa
*new2
;
1609 struct as_external_lsa
*extlsa
;
1612 /* NSSA Originate or Refresh (If anyNSSA)
1614 LSA is self-originated. And just installed as Type-5.
1615 Additionally, install as Type-7 LSDB for every attached NSSA.
1617 P-Bit controls which ABR performs translation to outside world; If
1618 we are an ABR....do not set the P-bit, because we send the Type-5,
1619 not as the ABR Translator, but as the ASBR owner within the AS!
1621 If we are NOT ABR, Flood through NSSA as Type-7 w/P-bit set. The
1622 elected ABR Translator will see the P-bit, Translate, and re-flood.
1624 Later, ABR_TASK and P-bit will scan Type-7 LSDB and translate to
1625 Type-5's to non-NSSA Areas. (it will also attempt a re-install) */
1627 for (node
= listhead (ospf
->areas
); node
; nextnode (node
))
1629 struct ospf_area
*area
= getdata (node
);
1631 /* make lsa duplicate, lock=1 */
1632 new2
= ospf_lsa_dup (lsa
);
1635 new2
->data
->type
= OSPF_AS_NSSA_LSA
;
1637 /* set P-bit if not ABR */
1638 if (! IS_OSPF_ABR (ospf
))
1640 SET_FLAG(new2
->data
->options
, OSPF_OPTION_NP
);
1642 /* set non-zero FWD ADDR
1644 draft-ietf-ospf-nssa-update-09.txt
1646 if the network between the NSSA AS boundary router and the
1647 adjacent AS is advertised into OSPF as an internal OSPF route,
1648 the forwarding address should be the next op address as is cu
1649 currently done with type-5 LSAs. If the intervening network is
1650 not adversited into OSPF as an internal OSPF route and the
1651 type-7 LSA's P-bit is set a forwarding address should be
1652 selected from one of the router's active OSPF inteface addresses
1653 which belong to the NSSA. If no such addresses exist, then
1654 no type-7 LSA's with the P-bit set should originate from this
1657 /* kevinm: not updating lsa anymore, just new2 */
1658 extlsa
= (struct as_external_lsa
*)(new2
->data
);
1660 if (extlsa
->e
[0].fwd_addr
.s_addr
== 0)
1661 extlsa
->e
[0].fwd_addr
= ospf_get_nssa_ip(area
); /* this NSSA area in ifp */
1663 if (extlsa
->e
[0].fwd_addr
.s_addr
== 0)
1665 if (IS_DEBUG_OSPF_NSSA
)
1666 zlog_info ("LSA[Type-7]: Could not build FWD-ADDR");
1667 ospf_lsa_discard(new2
);
1671 /* Re-calculate checksum. */
1672 ospf_lsa_checksum (new2
->data
);
1674 /* install also as Type-7 */
1675 ospf_lsa_install (ospf
, NULL
, new2
); /* Remove Old, Lock New = 2 */
1677 /* will send each copy, lock=2+n */
1678 ospf_flood_through_as (ospf
, NULL
, new2
); /* all attached NSSA's, no AS/STUBs */
1681 #endif /* HAVE_NSSA */
1684 is_prefix_default (struct prefix_ipv4
*p
)
1686 struct prefix_ipv4 q
;
1689 q
.prefix
.s_addr
= 0;
1692 return prefix_same ((struct prefix
*) p
, (struct prefix
*) &q
);
1695 /* Originate an AS-external-LSA, install and flood. */
1697 ospf_external_lsa_originate (struct ospf
*ospf
, struct external_info
*ei
)
1699 struct ospf_lsa
*new;
1701 /* Added for NSSA project....
1703 External LSAs are originated in ASBRs as usual, but for NSSA systems.
1704 there is the global Type-5 LSDB and a Type-7 LSDB installed for
1705 every area. The Type-7's are flooded to every IR and every ABR; We
1706 install the Type-5 LSDB so that the normal "refresh" code operates
1707 as usual, and flag them as not used during ASE calculations. The
1708 Type-7 LSDB is used for calculations. Each Type-7 has a Forwarding
1709 Address of non-zero.
1711 If an ABR is the elected NSSA translator, following SPF and during
1712 the ABR task it will translate all the scanned Type-7's, with P-bit
1713 ON and not-self generated, and translate to Type-5's throughout the
1716 A difference in operation depends whether this ASBR is an ABR
1717 or not. If not an ABR, the P-bit is ON, to indicate that any
1718 elected NSSA-ABR can perform its translation.
1720 If an ABR, the P-bit is OFF; No ABR will perform translation and
1721 this ASBR will flood the Type-5 LSA as usual.
1723 For the case where this ASBR is not an ABR, the ASE calculations
1724 are based on the Type-5 LSDB; The Type-7 LSDB exists just to
1725 demonstrate to the user that there are LSA's that belong to any
1728 Finally, it just so happens that when the ABR is translating every
1729 Type-7 into Type-5, it installs it into the Type-5 LSDB as an
1730 approved Type-5 (translated from Type-7); at the end of translation
1731 if any Translated Type-5's remain unapproved, then they must be
1732 flushed from the AS.
1736 /* Check the AS-external-LSA should be originated. */
1737 if (!ospf_redistribute_check (ospf
, ei
, NULL
))
1740 /* Create new AS-external-LSA instance. */
1741 if ((new = ospf_external_lsa_new (ospf
, ei
, NULL
)) == NULL
)
1743 if (IS_DEBUG_OSPF_EVENT
)
1744 zlog_info ("LSA[Type5:%s]: Could not originate AS-external-LSA",
1745 inet_ntoa (ei
->p
.prefix
));
1749 /* Install newly created LSA into Type-5 LSDB, lock = 1. */
1750 ospf_lsa_install (ospf
, NULL
, new);
1752 /* Update LSA origination count. */
1753 ospf
->lsa_originate_count
++;
1755 /* Flooding new LSA. only to AS (non-NSSA/STUB) */
1756 ospf_flood_through_as (ospf
, NULL
, new);
1759 /* If there is any attached NSSA, do special handling */
1761 ospf_install_flood_nssa (ospf
, new, ei
); /* Install/Flood Type-7 to all NSSAs */
1762 #endif /* HAVE_NSSA */
1764 /* Debug logging. */
1765 if (IS_DEBUG_OSPF (lsa
, LSA_GENERATE
))
1767 zlog_info ("LSA[Type%d:%s]: Originate AS-external-LSA %p",
1768 new->data
->type
, inet_ntoa (new->data
->id
), new);
1769 ospf_lsa_header_dump (new->data
);
1775 /* Originate AS-external-LSA from external info with initial flag. */
1777 ospf_external_lsa_originate_timer (struct thread
*thread
)
1779 struct ospf
*ospf
= THREAD_ARG (thread
);
1780 struct route_node
*rn
;
1781 struct external_info
*ei
;
1782 struct route_table
*rt
;
1783 int type
= THREAD_VAL (thread
);
1785 ospf
->t_external_lsa
= NULL
;
1787 /* Originate As-external-LSA from all type of distribute source. */
1788 if ((rt
= EXTERNAL_INFO (type
)))
1789 for (rn
= route_top (rt
); rn
; rn
= route_next (rn
))
1790 if ((ei
= rn
->info
) != NULL
)
1791 if (!is_prefix_default ((struct prefix_ipv4
*)&ei
->p
))
1792 if (!ospf_external_lsa_originate (ospf
, ei
))
1793 zlog_warn ("LSA: AS-external-LSA was not originated.");
1798 struct external_info
*
1799 ospf_default_external_info (struct ospf
*ospf
)
1802 struct route_node
*rn
;
1803 struct prefix_ipv4 p
;
1806 p
.prefix
.s_addr
= 0;
1809 /* First, lookup redistributed default route. */
1810 for (type
= 0; type
<= ZEBRA_ROUTE_MAX
; type
++)
1811 if (EXTERNAL_INFO (type
) && type
!= ZEBRA_ROUTE_OSPF
)
1813 rn
= route_node_lookup (EXTERNAL_INFO (type
), (struct prefix
*) &p
);
1816 route_unlock_node (rn
);
1818 if (ospf_redistribute_check (ospf
, rn
->info
, NULL
))
1827 ospf_default_originate_timer (struct thread
*thread
)
1830 struct prefix_ipv4 p
;
1831 struct in_addr nexthop
;
1832 struct external_info
*ei
;
1835 ospf
= ospf_lookup ();
1837 /* Get originate flags. */
1838 origin
= THREAD_ARG (thread
);
1841 p
.prefix
.s_addr
= 0;
1844 if (*origin
== DEFAULT_ORIGINATE_ALWAYS
)
1846 /* If there is no default route via redistribute,
1847 then originate AS-external-LSA with nexthop 0 (self). */
1849 ospf_external_info_add (DEFAULT_ROUTE
, p
, 0, nexthop
);
1852 if ((ei
= ospf_default_external_info (ospf
)))
1853 ospf_external_lsa_originate (ospf
, ei
);
1859 /* Flush any NSSA LSAs for given prefix */
1861 ospf_nssa_lsa_flush (struct ospf
*ospf
, struct prefix_ipv4
*p
)
1863 struct listnode
*node
;
1864 struct ospf_lsa
*lsa
;
1865 struct ospf_area
*area
;
1867 for (node
= listhead (ospf
->areas
); node
; nextnode (node
))
1869 if (((area
= getdata (node
)) != NULL
)
1870 && (area
->external_routing
== OSPF_AREA_NSSA
))
1872 if (!(lsa
= ospf_lsa_lookup (area
, OSPF_AS_NSSA_LSA
, p
->prefix
,
1875 if (IS_DEBUG_OSPF (lsa
, LSA_FLOODING
))
1876 zlog_warn ("LSA: There is no such AS-NSSA-LSA %s/%d in LSDB",
1877 inet_ntoa (p
->prefix
), p
->prefixlen
);
1880 ospf_ls_retransmit_delete_nbr_area (area
, lsa
);
1881 if (!IS_LSA_MAXAGE (lsa
))
1883 ospf_refresher_unregister_lsa (ospf
, lsa
);
1884 ospf_lsa_flush_area (lsa
, area
);
1889 #endif /* HAVE_NSSA */
1891 /* Flush an AS-external-LSA from LSDB and routing domain. */
1893 ospf_external_lsa_flush (struct ospf
*ospf
,
1894 u_char type
, struct prefix_ipv4
*p
,
1895 unsigned int ifindex
, struct in_addr nexthop
)
1897 struct ospf_lsa
*lsa
;
1899 if (IS_DEBUG_OSPF (lsa
, LSA_FLOODING
))
1900 zlog_info ("LSA: Flushing AS-external-LSA %s/%d",
1901 inet_ntoa (p
->prefix
), p
->prefixlen
);
1903 /* First lookup LSA from LSDB. */
1904 if (!(lsa
= ospf_external_info_find_lsa (ospf
, p
)))
1906 if (IS_DEBUG_OSPF (lsa
, LSA_FLOODING
))
1907 zlog_warn ("LSA: There is no such AS-external-LSA %s/%d in LSDB",
1908 inet_ntoa (p
->prefix
), p
->prefixlen
);
1912 /* If LSA is selforiginated and there is NSSA area, flush
1913 * Type-7 LSA's at first. */
1915 if (IS_LSA_SELF(lsa
) && (ospf
->anyNSSA
))
1916 ospf_nssa_lsa_flush (ospf
, p
);
1917 #endif /* HAVE_NSSA */
1919 /* Sweep LSA from Link State Retransmit List. */
1920 ospf_ls_retransmit_delete_nbr_as (ospf
, lsa
);
1922 if (!IS_LSA_MAXAGE (lsa
))
1924 /* Unregister LSA from Refresh queue. */
1925 ospf_refresher_unregister_lsa (ospf
, lsa
);
1927 /* Flush AS-external-LSA through AS. */
1928 ospf_lsa_flush_as (ospf
, lsa
);
1931 if (IS_DEBUG_OSPF (lsa
, LSA_FLOODING
))
1932 zlog_info ("ospf_external_lsa_flush(): stop");
1936 ospf_external_lsa_refresh_default (struct ospf
*ospf
)
1938 struct prefix_ipv4 p
;
1939 struct external_info
*ei
;
1940 struct ospf_lsa
*lsa
;
1944 p
.prefix
.s_addr
= 0;
1946 ei
= ospf_default_external_info (ospf
);
1947 lsa
= ospf_external_info_find_lsa (ospf
, &p
);
1953 if (IS_DEBUG_OSPF_EVENT
)
1954 zlog_info ("LSA[Type5:0.0.0.0]: Refresh AS-external-LSA %p", lsa
);
1955 ospf_external_lsa_refresh (ospf
, lsa
, ei
, LSA_REFRESH_FORCE
);
1959 if (IS_DEBUG_OSPF_EVENT
)
1960 zlog_info ("LSA[Type5:0.0.0.0]: Originate AS-external-LSA");
1961 ospf_external_lsa_originate (ospf
, ei
);
1968 if (IS_DEBUG_OSPF_EVENT
)
1969 zlog_info ("LSA[Type5:0.0.0.0]: Flush AS-external-LSA");
1970 ospf_lsa_flush_as (ospf
, lsa
);
1976 ospf_external_lsa_refresh_type (struct ospf
*ospf
, u_char type
, int force
)
1978 struct route_node
*rn
;
1979 struct external_info
*ei
;
1981 if (type
!= DEFAULT_ROUTE
)
1982 if (EXTERNAL_INFO(type
))
1983 /* Refresh each redistributed AS-external-LSAs. */
1984 for (rn
= route_top (EXTERNAL_INFO (type
)); rn
; rn
= route_next (rn
))
1985 if ((ei
= rn
->info
))
1986 if (!is_prefix_default (&ei
->p
))
1988 struct ospf_lsa
*lsa
;
1990 if ((lsa
= ospf_external_info_find_lsa (ospf
, &ei
->p
)))
1991 ospf_external_lsa_refresh (ospf
, lsa
, ei
, force
);
1993 ospf_external_lsa_originate (ospf
, ei
);
1997 /* Refresh AS-external-LSA. */
1999 ospf_external_lsa_refresh (struct ospf
*ospf
, struct ospf_lsa
*lsa
,
2000 struct external_info
*ei
, int force
)
2002 struct ospf_lsa
*new;
2005 /* Check the AS-external-LSA should be originated. */
2006 if (!ospf_redistribute_check (ospf
, ei
, &changed
))
2008 ospf_external_lsa_flush (ospf
, ei
->type
, &ei
->p
,
2009 ei
->ifindex
, ei
->nexthop
);
2013 if (!changed
&& !force
)
2016 /* Delete LSA from neighbor retransmit-list. */
2017 ospf_ls_retransmit_delete_nbr_as (ospf
, lsa
);
2019 /* Unregister AS-external-LSA from refresh-list. */
2020 ospf_refresher_unregister_lsa (ospf
, lsa
);
2022 new = ospf_external_lsa_new (ospf
, ei
, &lsa
->data
->id
);
2026 if (IS_DEBUG_OSPF (lsa
, LSA_GENERATE
))
2027 zlog_warn ("LSA[Type%d:%s]: Could not be refreshed", lsa
->data
->type
,
2028 inet_ntoa (lsa
->data
->id
));
2032 new->data
->ls_seqnum
= lsa_seqnum_increment (lsa
);
2034 /* Record timestamp. */
2035 gettimeofday (&new->tv_orig
, NULL
);
2037 /* Re-calculate checksum. */
2038 ospf_lsa_checksum (new->data
);
2040 ospf_lsa_install (ospf
, NULL
, new); /* As type-5. */
2042 /* Flood LSA through AS. */
2043 ospf_flood_through_as (ospf
, NULL
, new);
2046 /* If any attached NSSA, install as Type-7, flood to all NSSA Areas */
2048 ospf_install_flood_nssa (ospf
, new, ei
); /* Install/Flood per new rules */
2049 #endif /* HAVE_NSSA */
2051 /* Register slef-originated LSA to refresh queue. */
2052 ospf_refresher_register_lsa (ospf
, new);
2054 /* Debug logging. */
2055 if (IS_DEBUG_OSPF (lsa
, LSA_GENERATE
))
2057 zlog_info ("LSA[Type%d:%s]: AS-external-LSA refresh",
2058 new->data
->type
, inet_ntoa (new->data
->id
));
2059 ospf_lsa_header_dump (new->data
);
2066 /* LSA installation functions. */
2068 /* Install router-LSA to an area. */
2070 ospf_router_lsa_install (struct ospf
*ospf
,
2071 struct ospf_lsa
*new, int rt_recalc
)
2073 struct ospf_area
*area
= new->area
;
2075 /* RFC 2328 Section 13.2 Router-LSAs and network-LSAs
2076 The entire routing table must be recalculated, starting with
2077 the shortest path calculations for each area (not just the
2078 area whose link-state database has changed).
2081 ospf_spf_calculate_schedule (ospf
);
2083 if (IS_LSA_SELF (new))
2085 /* Set router-LSA refresh timer. */
2086 OSPF_TIMER_OFF (area
->t_router_lsa_self
);
2087 OSPF_AREA_TIMER_ON (area
->t_router_lsa_self
,
2088 ospf_router_lsa_timer
, OSPF_LS_REFRESH_TIME
);
2090 /* Set self-originated router-LSA. */
2091 ospf_lsa_unlock (area
->router_lsa_self
);
2092 area
->router_lsa_self
= ospf_lsa_lock (new);
2094 if (IS_DEBUG_OSPF (lsa
, LSA_INSTALL
))
2095 zlog_info("LSA[Type%d]: ID %s is self-originated",
2096 new->data
->type
, inet_ntoa (new->data
->id
));
2102 #define OSPF_INTERFACE_TIMER_ON(T,F,V) \
2104 (T) = thread_add_timer (master, (F), oi, (V))
2106 /* Install network-LSA to an area. */
2108 ospf_network_lsa_install (struct ospf
*ospf
,
2109 struct ospf_interface
*oi
,
2110 struct ospf_lsa
*new,
2114 /* RFC 2328 Section 13.2 Router-LSAs and network-LSAs
2115 The entire routing table must be recalculated, starting with
2116 the shortest path calculations for each area (not just the
2117 area whose link-state database has changed).
2120 ospf_spf_calculate_schedule (ospf
);
2122 /* We supposed that when LSA is originated by us, we pass the int
2123 for which it was originated. If LSA was received by flooding,
2124 the RECEIVED flag is set, so we do not link the LSA to the int. */
2125 if (IS_LSA_SELF (new) && !CHECK_FLAG (new->flags
, OSPF_LSA_RECEIVED
))
2127 /* Set LSRefresh timer. */
2128 OSPF_TIMER_OFF (oi
->t_network_lsa_self
);
2130 OSPF_INTERFACE_TIMER_ON (oi
->t_network_lsa_self
,
2131 ospf_network_lsa_refresh_timer
,
2132 OSPF_LS_REFRESH_TIME
);
2134 ospf_lsa_unlock (oi
->network_lsa_self
);
2135 oi
->network_lsa_self
= ospf_lsa_lock (new);
2141 /* Install summary-LSA to an area. */
2143 ospf_summary_lsa_install (struct ospf
*ospf
, struct ospf_lsa
*new,
2146 if (rt_recalc
&& !IS_LSA_SELF (new))
2148 /* RFC 2328 Section 13.2 Summary-LSAs
2149 The best route to the destination described by the summary-
2150 LSA must be recalculated (see Section 16.5). If this
2151 destination is an AS boundary router, it may also be
2152 necessary to re-examine all the AS-external-LSAs.
2154 ospf_spf_calculate_schedule (ospf
);
2156 if (IS_DEBUG_OSPF (lsa
, LSA_INSTALL
))
2157 zlog_info ("ospf_summary_lsa_install(): SPF scheduled");
2160 if (IS_LSA_SELF (new))
2161 ospf_refresher_register_lsa (ospf
, new);
2166 /* Install ASBR-summary-LSA to an area. */
2168 ospf_summary_asbr_lsa_install (struct ospf
*ospf
, struct ospf_lsa
*new,
2171 if (rt_recalc
&& !IS_LSA_SELF (new))
2173 /* RFC 2328 Section 13.2 Summary-LSAs
2174 The best route to the destination described by the summary-
2175 LSA must be recalculated (see Section 16.5). If this
2176 destination is an AS boundary router, it may also be
2177 necessary to re-examine all the AS-external-LSAs.
2179 ospf_spf_calculate_schedule (ospf
);
2182 /* register LSA to refresh-list. */
2183 if (IS_LSA_SELF (new))
2184 ospf_refresher_register_lsa (ospf
, new);
2189 /* Install AS-external-LSA. */
2191 ospf_external_lsa_install (struct ospf
*ospf
, struct ospf_lsa
*new,
2194 ospf_ase_register_external_lsa (new, ospf
);
2195 /* If LSA is not self-originated, calculate an external route. */
2198 /* RFC 2328 Section 13.2 AS-external-LSAs
2199 The best route to the destination described by the AS-
2200 external-LSA must be recalculated (see Section 16.6).
2203 if (!IS_LSA_SELF (new))
2204 ospf_ase_incremental_update (ospf
, new);
2208 /* There is no point to register selforiginate Type-7 LSA for
2209 * refreshing. We rely on refreshing Type-5 LSA's */
2210 if (IS_LSA_SELF (new) && (new->data
->type
== OSPF_AS_NSSA_LSA
))
2212 #endif /* HAVE_NSSA */
2214 /* Register self-originated LSA to refresh queue. */
2215 if (IS_LSA_SELF (new))
2216 ospf_refresher_register_lsa (ospf
, new);
2222 ospf_discard_from_db (struct ospf
*ospf
,
2223 struct ospf_lsdb
*lsdb
, struct ospf_lsa
*lsa
)
2225 struct ospf_lsa
*old
;
2227 old
= ospf_lsdb_lookup (lsdb
, lsa
);
2232 if (old
->refresh_list
>= 0)
2233 ospf_refresher_unregister_lsa (ospf
, old
);
2235 switch (old
->data
->type
)
2237 case OSPF_AS_EXTERNAL_LSA
:
2238 #ifdef HAVE_OPAQUE_LSA
2239 case OSPF_OPAQUE_AS_LSA
:
2240 #endif /* HAVE_OPAQUE_LSA */
2241 ospf_ls_retransmit_delete_nbr_as (ospf
, old
);
2242 ospf_ase_unregister_external_lsa (old
, ospf
);
2245 case OSPF_AS_NSSA_LSA
:
2246 ospf_ls_retransmit_delete_nbr_area (old
->area
, old
);
2247 ospf_ase_unregister_external_lsa (old
, ospf
);
2249 #endif /* HAVE_NSSA */
2251 ospf_ls_retransmit_delete_nbr_area (old
->area
, old
);
2255 ospf_lsa_maxage_delete (ospf
, old
);
2256 ospf_lsa_discard (old
);
2260 ospf_lsa_install (struct ospf
*ospf
, struct ospf_interface
*oi
,
2261 struct ospf_lsa
*lsa
)
2263 struct ospf_lsa
*new = NULL
;
2264 struct ospf_lsa
*old
= NULL
;
2265 struct ospf_lsdb
*lsdb
= NULL
;
2269 switch (lsa
->data
->type
)
2273 case OSPF_AS_NSSA_LSA
:
2275 lsdb
= lsa
->area
->lsdb
;
2279 #endif /* HAVE_NSSA */
2280 case OSPF_AS_EXTERNAL_LSA
:
2281 #ifdef HAVE_OPAQUE_LSA
2282 case OSPF_OPAQUE_AS_LSA
:
2283 #endif /* HAVE_OPAQUE_LSA */
2287 lsdb
= lsa
->area
->lsdb
;
2293 /* RFC 2328 13.2. Installing LSAs in the database
2295 Installing a new LSA in the database, either as the result of
2296 flooding or a newly self-originated LSA, may cause the OSPF
2297 routing table structure to be recalculated. The contents of the
2298 new LSA should be compared to the old instance, if present. If
2299 there is no difference, there is no need to recalculate the
2300 routing table. When comparing an LSA to its previous instance,
2301 the following are all considered to be differences in contents:
2303 o The LSA's Options field has changed.
2305 o One of the LSA instances has LS age set to MaxAge, and
2308 o The length field in the LSA header has changed.
2310 o The body of the LSA (i.e., anything outside the 20-byte
2311 LSA header) has changed. Note that this excludes changes
2312 in LS Sequence Number and LS Checksum.
2315 /* Look up old LSA and determine if any SPF calculation or incremental
2317 old
= ospf_lsdb_lookup (lsdb
, lsa
);
2319 /* Do comparision and record if recalc needed. */
2321 if ( old
== NULL
|| ospf_lsa_different(old
, lsa
))
2324 /* discard old LSA from LSDB */
2326 ospf_discard_from_db (ospf
, lsdb
, lsa
);
2328 /* Insert LSA to LSDB. */
2329 ospf_lsdb_add (lsdb
, lsa
);
2332 /* Calculate Checksum if self-originated?. */
2333 if (IS_LSA_SELF (lsa
))
2334 ospf_lsa_checksum (lsa
->data
);
2336 /* Do LSA specific installation process. */
2337 switch (lsa
->data
->type
)
2339 case OSPF_ROUTER_LSA
:
2340 new = ospf_router_lsa_install (ospf
, lsa
, rt_recalc
);
2342 case OSPF_NETWORK_LSA
:
2344 new = ospf_network_lsa_install (ospf
, oi
, lsa
, rt_recalc
);
2346 case OSPF_SUMMARY_LSA
:
2347 new = ospf_summary_lsa_install (ospf
, lsa
, rt_recalc
);
2349 case OSPF_ASBR_SUMMARY_LSA
:
2350 new = ospf_summary_asbr_lsa_install (ospf
, lsa
, rt_recalc
);
2352 case OSPF_AS_EXTERNAL_LSA
:
2353 new = ospf_external_lsa_install (ospf
, lsa
, rt_recalc
);
2355 #ifdef HAVE_OPAQUE_LSA
2356 case OSPF_OPAQUE_LINK_LSA
:
2357 if (IS_LSA_SELF (lsa
))
2358 lsa
->oi
= oi
; /* Specify outgoing ospf-interface for this LSA. */
2360 ; /* Incoming "oi" for this LSA has set at LSUpd reception. */
2362 case OSPF_OPAQUE_AREA_LSA
:
2363 case OSPF_OPAQUE_AS_LSA
:
2364 new = ospf_opaque_lsa_install (lsa
, rt_recalc
);
2366 #endif /* HAVE_OPAQUE_LSA */
2367 default: /* NSSA, or type-6,8,9....nothing special */
2369 new = ospf_external_lsa_install (ospf
, lsa
, rt_recalc
);
2370 #endif /* HAVE_NSSA */
2375 return new; /* Installation failed, cannot proceed further -- endo. */
2378 if (IS_DEBUG_OSPF (lsa
, LSA_INSTALL
))
2380 char area_str
[INET_ADDRSTRLEN
];
2382 switch (lsa
->data
->type
)
2384 case OSPF_AS_EXTERNAL_LSA
:
2385 #ifdef HAVE_OPAQUE_LSA
2386 case OSPF_OPAQUE_AS_LSA
:
2387 #endif /* HAVE_OPAQUE_LSA */
2389 case OSPF_AS_NSSA_LSA
:
2390 #endif /* HAVE_NSSA */
2391 zlog_info ("LSA[%s]: Install %s",
2393 LOOKUP (ospf_lsa_type_msg
, new->data
->type
));
2396 strcpy (area_str
, inet_ntoa (new->area
->area_id
));
2397 zlog_info ("LSA[%s]: Install %s to Area %s",
2399 LOOKUP (ospf_lsa_type_msg
, new->data
->type
), area_str
);
2404 /* If received LSA' ls_age is MaxAge, set LSA on MaxAge LSA list. */
2405 if (IS_LSA_MAXAGE (new) && !IS_LSA_SELF (new))
2407 if (IS_DEBUG_OSPF (lsa
, LSA_FLOODING
))
2408 zlog_info ("LSA[Type%d:%s]: Install LSA, MaxAge",
2409 new->data
->type
, inet_ntoa (new->data
->id
));
2410 ospf_lsa_maxage (ospf
, lsa
);
2418 ospf_check_nbr_status (struct ospf
*ospf
)
2422 for (node
= listhead (ospf
->oiflist
); node
; node
= nextnode (node
))
2424 struct ospf_interface
*oi
= getdata (node
);
2425 struct route_node
*rn
;
2426 struct ospf_neighbor
*nbr
;
2428 if (ospf_if_is_enable (oi
))
2429 for (rn
= route_top (oi
->nbrs
); rn
; rn
= route_next (rn
))
2430 if ((nbr
= rn
->info
) != NULL
)
2431 if (nbr
->state
== NSM_Exchange
|| nbr
->state
== NSM_Loading
)
2433 route_unlock_node (rn
);
2443 ospf_maxage_lsa_remover (struct thread
*thread
)
2445 struct ospf
*ospf
= THREAD_ARG (thread
);
2450 ospf
->t_maxage
= NULL
;
2452 if (IS_DEBUG_OSPF (lsa
, LSA_FLOODING
))
2453 zlog_info ("LSA[MaxAge]: remover Start");
2455 reschedule
= !ospf_check_nbr_status (ospf
);
2458 for (node
= listhead (ospf
->maxage_lsa
); node
; node
= next
)
2460 struct ospf_lsa
*lsa
= getdata (node
);
2463 if (lsa
->retransmit_counter
> 0)
2469 /* Remove LSA from the LSDB */
2470 if (CHECK_FLAG (lsa
->flags
, OSPF_LSA_SELF
))
2471 if (IS_DEBUG_OSPF (lsa
, LSA_FLOODING
))
2472 zlog_info ("LSA[Type%d:%s]: This LSA is self-originated: ",
2473 lsa
->data
->type
, inet_ntoa (lsa
->data
->id
));
2475 if (IS_DEBUG_OSPF (lsa
, LSA_FLOODING
))
2476 zlog_info ("LSA[Type%d:%s]: MaxAge LSA removed from list",
2477 lsa
->data
->type
, inet_ntoa (lsa
->data
->id
));
2479 /* Flood max age LSA. */
2480 ospf_flood_through (ospf
, NULL
, lsa
);
2482 /* Remove from lsdb. */
2483 ospf_discard_from_db (ospf
, lsa
->lsdb
, lsa
);
2484 ospf_lsdb_delete (lsa
->lsdb
, lsa
);
2487 /* A MaxAge LSA must be removed immediately from the router's link
2488 state database as soon as both a) it is no longer contained on any
2489 neighbor Link state retransmission lists and b) none of the router's
2490 neighbors are in states Exchange or Loading. */
2492 OSPF_TIMER_ON (ospf
->t_maxage
, ospf_maxage_lsa_remover
, 2);
2498 ospf_lsa_maxage_exist (struct ospf
*ospf
, struct ospf_lsa
*new)
2502 for (node
= listhead (ospf
->maxage_lsa
); node
; nextnode (node
))
2503 if (((struct ospf_lsa
*) node
->data
) == new)
2510 ospf_lsa_maxage_delete (struct ospf
*ospf
, struct ospf_lsa
*lsa
)
2514 if ((n
= listnode_lookup (ospf
->maxage_lsa
, lsa
)))
2516 list_delete_node (ospf
->maxage_lsa
, n
);
2517 ospf_lsa_unlock (lsa
);
2522 ospf_lsa_maxage (struct ospf
*ospf
, struct ospf_lsa
*lsa
)
2524 /* When we saw a MaxAge LSA flooded to us, we put it on the list
2525 and schedule the MaxAge LSA remover. */
2526 if (ospf_lsa_maxage_exist (ospf
, lsa
))
2528 if (IS_DEBUG_OSPF (lsa
, LSA_FLOODING
))
2529 zlog_info ("LSA[Type%d:%s]: %p already exists on MaxAge LSA list",
2530 lsa
->data
->type
, inet_ntoa (lsa
->data
->id
), lsa
);
2534 listnode_add (ospf
->maxage_lsa
, ospf_lsa_lock (lsa
));
2536 if (IS_DEBUG_OSPF (lsa
, LSA_FLOODING
))
2537 zlog_info ("LSA[%s]: MaxAge LSA remover scheduled.", dump_lsa_key (lsa
));
2539 OSPF_TIMER_ON (ospf
->t_maxage
, ospf_maxage_lsa_remover
, 2);
2543 ospf_lsa_maxage_walker_remover (struct ospf
*ospf
, struct ospf_lsa
*lsa
)
2546 /* Stay away from any Local Translated Type-7 LSAs */
2547 if (CHECK_FLAG (lsa
->flags
, OSPF_LSA_LOCAL_XLT
))
2549 #endif /* HAVE_NSSA */
2551 if (IS_LSA_MAXAGE (lsa
))
2552 /* Self-originated LSAs should NOT time-out instead,
2553 they're flushed and submitted to the max_age list explicitly. */
2554 if (!ospf_lsa_is_self_originated (ospf
, lsa
))
2556 if (IS_DEBUG_OSPF (lsa
, LSA_FLOODING
))
2557 zlog_info("LSA[%s]: is MaxAge", dump_lsa_key (lsa
));
2559 switch (lsa
->data
->type
)
2561 #ifdef HAVE_OPAQUE_LSA
2562 case OSPF_OPAQUE_LINK_LSA
:
2563 case OSPF_OPAQUE_AREA_LSA
:
2564 case OSPF_OPAQUE_AS_LSA
:
2566 * As a general rule, whenever network topology has changed
2567 * (due to an LSA removal in this case), routing recalculation
2568 * should be triggered. However, this is not true for opaque
2569 * LSAs. Even if an opaque LSA instance is going to be removed
2570 * from the routing domain, it does not mean a change in network
2571 * topology, and thus, routing recalculation is not needed here.
2574 #endif /* HAVE_OPAQUE_LSA */
2575 case OSPF_AS_EXTERNAL_LSA
:
2577 case OSPF_AS_NSSA_LSA
:
2578 #endif /* HAVE_NSSA */
2579 ospf_ase_incremental_update (ospf
, lsa
);
2582 ospf_spf_calculate_schedule (ospf
);
2586 ospf_lsa_maxage (ospf
, lsa
);
2592 /* Periodical check of MaxAge LSA. */
2594 ospf_lsa_maxage_walker (struct thread
*thread
)
2596 struct ospf
*ospf
= THREAD_ARG (thread
);
2597 struct route_node
*rn
;
2598 struct ospf_lsa
*lsa
;
2601 ospf
->t_maxage_walker
= NULL
;
2603 for (node
= listhead (ospf
->areas
); node
; nextnode (node
))
2605 struct ospf_area
*area
= node
->data
;
2607 LSDB_LOOP (ROUTER_LSDB (area
), rn
, lsa
)
2608 ospf_lsa_maxage_walker_remover (ospf
, lsa
);
2609 LSDB_LOOP (NETWORK_LSDB (area
), rn
, lsa
)
2610 ospf_lsa_maxage_walker_remover (ospf
, lsa
);
2611 LSDB_LOOP (SUMMARY_LSDB (area
), rn
, lsa
)
2612 ospf_lsa_maxage_walker_remover (ospf
, lsa
);
2613 LSDB_LOOP (ASBR_SUMMARY_LSDB (area
), rn
, lsa
)
2614 ospf_lsa_maxage_walker_remover (ospf
, lsa
);
2615 #ifdef HAVE_OPAQUE_LSA
2616 LSDB_LOOP (OPAQUE_AREA_LSDB (area
), rn
, lsa
)
2617 ospf_lsa_maxage_walker_remover (ospf
, lsa
);
2618 LSDB_LOOP (OPAQUE_LINK_LSDB (area
), rn
, lsa
)
2619 ospf_lsa_maxage_walker_remover (ospf
, lsa
);
2620 #endif /* HAVE_OPAQUE_LSA */
2622 LSDB_LOOP (NSSA_LSDB (area
), rn
, lsa
)
2623 ospf_lsa_maxage_walker_remover (ospf
, lsa
);
2624 #endif /* HAVE_NSSA */
2628 /* for AS-eternal-LSAs. */
2631 LSDB_LOOP (EXTERNAL_LSDB (ospf
), rn
, lsa
)
2632 ospf_lsa_maxage_walker_remover (ospf
, lsa
);
2633 #ifdef HAVE_OPAQUE_LSA
2634 LSDB_LOOP (OPAQUE_AS_LSDB (ospf
), rn
, lsa
)
2635 ospf_lsa_maxage_walker_remover (ospf
, lsa
);
2636 #endif /* HAVE_OPAQUE_LSA */
2639 OSPF_TIMER_ON (ospf
->t_maxage_walker
, ospf_lsa_maxage_walker
,
2640 OSPF_LSA_MAXAGE_CHECK_INTERVAL
);
2645 ospf_lsa_lookup_by_prefix (struct ospf_lsdb
*lsdb
, u_char type
,
2646 struct prefix_ipv4
*p
, struct in_addr router_id
)
2648 struct ospf_lsa
*lsa
;
2649 struct in_addr mask
, id
;
2650 struct lsa_header_mask
2652 struct lsa_header header
;
2653 struct in_addr mask
;
2656 lsa
= ospf_lsdb_lookup_by_id (lsdb
, type
, p
->prefix
, router_id
);
2660 masklen2ip (p
->prefixlen
, &mask
);
2662 hmask
= (struct lsa_header_mask
*) lsa
->data
;
2664 if (mask
.s_addr
!= hmask
->mask
.s_addr
)
2666 id
.s_addr
= p
->prefix
.s_addr
| (~mask
.s_addr
);
2667 lsa
= ospf_lsdb_lookup_by_id (lsdb
, type
, id
, router_id
);
2676 ospf_lsa_lookup (struct ospf_area
*area
, u_int32_t type
,
2677 struct in_addr id
, struct in_addr adv_router
)
2681 case OSPF_ROUTER_LSA
:
2682 case OSPF_NETWORK_LSA
:
2683 case OSPF_SUMMARY_LSA
:
2684 case OSPF_ASBR_SUMMARY_LSA
:
2686 case OSPF_AS_NSSA_LSA
:
2687 #endif /* HAVE_NSSA */
2688 #ifdef HAVE_OPAQUE_LSA
2689 case OSPF_OPAQUE_LINK_LSA
:
2690 case OSPF_OPAQUE_AREA_LSA
:
2691 #endif /* HAVE_OPAQUE_LSA */
2692 return ospf_lsdb_lookup_by_id (area
->lsdb
, type
, id
, adv_router
);
2694 case OSPF_AS_EXTERNAL_LSA
:
2695 #ifdef HAVE_OPAQUE_LSA
2696 case OSPF_OPAQUE_AS_LSA
:
2697 #endif /* HAVE_OPAQUE_LSA */
2698 return ospf_lsdb_lookup_by_id (area
->ospf
->lsdb
, type
, id
, adv_router
);
2708 ospf_lsa_lookup_by_id (struct ospf_area
*area
, u_int32_t type
,
2711 struct ospf_lsa
*lsa
;
2712 struct route_node
*rn
;
2716 case OSPF_ROUTER_LSA
:
2717 return ospf_lsdb_lookup_by_id (area
->lsdb
, type
, id
, id
);
2719 case OSPF_NETWORK_LSA
:
2720 for (rn
= route_top (NETWORK_LSDB (area
)); rn
; rn
= route_next (rn
))
2721 if ((lsa
= rn
->info
))
2722 if (IPV4_ADDR_SAME (&lsa
->data
->id
, &id
))
2724 route_unlock_node (rn
);
2728 case OSPF_SUMMARY_LSA
:
2729 case OSPF_ASBR_SUMMARY_LSA
:
2730 /* Currently not used. */
2732 return ospf_lsdb_lookup_by_id (area
->lsdb
, type
, id
, id
);
2734 case OSPF_AS_EXTERNAL_LSA
:
2735 #ifdef HAVE_OPAQUE_LSA
2736 case OSPF_OPAQUE_LINK_LSA
:
2737 case OSPF_OPAQUE_AREA_LSA
:
2738 case OSPF_OPAQUE_AS_LSA
:
2739 /* Currently not used. */
2741 #endif /* HAVE_OPAQUE_LSA */
2750 ospf_lsa_lookup_by_header (struct ospf_area
*area
, struct lsa_header
*lsah
)
2752 struct ospf_lsa
*match
;
2754 #ifdef HAVE_OPAQUE_LSA
2756 * Strictly speaking, the LSA-ID field for Opaque-LSAs (type-9/10/11)
2757 * is redefined to have two subfields; opaque-type and opaque-id.
2758 * However, it is harmless to treat the two sub fields together, as if
2759 * they two were forming a unique LSA-ID.
2761 #endif /* HAVE_OPAQUE_LSA */
2763 match
= ospf_lsa_lookup (area
, lsah
->type
, lsah
->id
, lsah
->adv_router
);
2766 if (IS_DEBUG_OSPF (lsa
, LSA
) == OSPF_DEBUG_LSA
)
2767 zlog_info ("LSA[Type%d:%s]: Lookup by header, NO MATCH",
2768 lsah
->type
, inet_ntoa (lsah
->id
));
2773 /* return +n, l1 is more recent.
2774 return -n, l2 is more recent.
2775 return 0, l1 and l2 is identical. */
2777 ospf_lsa_more_recent (struct ospf_lsa
*l1
, struct ospf_lsa
*l2
)
2782 if (l1
== NULL
&& l2
== NULL
)
2789 /* compare LS sequence number. */
2790 x
= (int) ntohl (l1
->data
->ls_seqnum
);
2791 y
= (int) ntohl (l2
->data
->ls_seqnum
);
2797 /* compare LS checksum. */
2798 r
= ntohs (l1
->data
->checksum
) - ntohs (l2
->data
->checksum
);
2802 /* compare LS age. */
2803 if (IS_LSA_MAXAGE (l1
) && !IS_LSA_MAXAGE (l2
))
2805 else if (!IS_LSA_MAXAGE (l1
) && IS_LSA_MAXAGE (l2
))
2808 /* compare LS age with MaxAgeDiff. */
2809 if (LS_AGE (l1
) - LS_AGE (l2
) > OSPF_LSA_MAXAGE_DIFF
)
2811 else if (LS_AGE (l2
) - LS_AGE (l1
) > OSPF_LSA_MAXAGE_DIFF
)
2814 /* LSAs are identical. */
2818 /* If two LSAs are different, return 1, otherwise return 0. */
2820 ospf_lsa_different (struct ospf_lsa
*l1
, struct ospf_lsa
*l2
)
2828 if (l1
->data
->options
!= l2
->data
->options
)
2831 if (IS_LSA_MAXAGE (l1
) && !IS_LSA_MAXAGE (l2
))
2834 if (IS_LSA_MAXAGE (l2
) && !IS_LSA_MAXAGE (l1
))
2837 if (l1
->data
->length
!= l2
->data
->length
)
2840 if (l1
->data
->length
== 0)
2843 assert (ntohs (l1
->data
->length
) > OSPF_LSA_HEADER_SIZE
);
2845 p1
= (char *) l1
->data
;
2846 p2
= (char *) l2
->data
;
2848 if (memcmp (p1
+ OSPF_LSA_HEADER_SIZE
, p2
+ OSPF_LSA_HEADER_SIZE
,
2849 ntohs (l1
->data
->length
) - OSPF_LSA_HEADER_SIZE
) != 0)
2856 ospf_lsa_flush_schedule (struct ospf
*ospf
, struct ospf_lsa
*lsa
)
2858 if (lsa
== NULL
|| !IS_LSA_SELF (lsa
))
2861 if (IS_DEBUG_OSPF_EVENT
)
2862 zlog_info ("LSA[Type%d:%s]: Schedule self-originated LSA to FLUSH", lsa
->data
->type
, inet_ntoa (lsa
->data
->id
));
2864 /* Force given lsa's age to MaxAge. */
2865 lsa
->data
->ls_age
= htons (OSPF_LSA_MAXAGE
);
2867 switch (lsa
->data
->type
)
2869 #ifdef HAVE_OPAQUE_LSA
2870 case OSPF_OPAQUE_LINK_LSA
:
2871 case OSPF_OPAQUE_AREA_LSA
:
2872 case OSPF_OPAQUE_AS_LSA
:
2873 ospf_opaque_lsa_refresh (lsa
);
2875 #endif /* HAVE_OPAQUE_LSA */
2877 ospf_lsa_maxage (ospf
, lsa
);
2885 ospf_flush_self_originated_lsas_now (struct ospf
*ospf
)
2888 struct ospf_area
*area
;
2889 struct ospf_interface
*oi
;
2890 struct ospf_lsa
*lsa
;
2891 struct route_node
*rn
;
2892 int need_to_flush_ase
= 0;
2894 for (n1
= listhead (ospf
->areas
); n1
; nextnode (n1
))
2896 if ((area
= getdata (n1
)) == NULL
)
2899 if ((lsa
= area
->router_lsa_self
) != NULL
)
2901 if (IS_DEBUG_OSPF_EVENT
)
2902 zlog_info ("LSA[Type%d:%s]: Schedule self-originated LSA to FLUSH", lsa
->data
->type
, inet_ntoa (lsa
->data
->id
));
2904 ospf_lsa_flush_area (lsa
, area
);
2905 ospf_lsa_unlock (area
->router_lsa_self
);
2906 area
->router_lsa_self
= NULL
;
2907 OSPF_TIMER_OFF (area
->t_router_lsa_self
);
2910 for (n2
= listhead (area
->oiflist
); n2
; nextnode (n2
))
2912 if ((oi
= getdata (n2
)) == NULL
)
2915 if ((lsa
= oi
->network_lsa_self
) != NULL
2916 && oi
->state
== ISM_DR
2917 && oi
->full_nbrs
> 0)
2919 if (IS_DEBUG_OSPF_EVENT
)
2920 zlog_info ("LSA[Type%d:%s]: Schedule self-originated LSA to FLUSH", lsa
->data
->type
, inet_ntoa (lsa
->data
->id
));
2922 ospf_lsa_flush_area (oi
->network_lsa_self
, area
);
2923 ospf_lsa_unlock (oi
->network_lsa_self
);
2924 oi
->network_lsa_self
= NULL
;
2925 OSPF_TIMER_OFF (oi
->t_network_lsa_self
);
2928 if (oi
->type
!= OSPF_IFTYPE_VIRTUALLINK
2929 && area
->external_routing
== OSPF_AREA_DEFAULT
)
2930 need_to_flush_ase
= 1;
2933 LSDB_LOOP (SUMMARY_LSDB (area
), rn
, lsa
)
2934 ospf_lsa_flush_schedule (ospf
, lsa
);
2935 LSDB_LOOP (ASBR_SUMMARY_LSDB (area
), rn
, lsa
)
2936 ospf_lsa_flush_schedule (ospf
, lsa
);
2937 #ifdef HAVE_OPAQUE_LSA
2938 LSDB_LOOP (OPAQUE_LINK_LSDB (area
), rn
, lsa
)
2939 ospf_lsa_flush_schedule (ospf
, lsa
);
2940 LSDB_LOOP (OPAQUE_AREA_LSDB (area
), rn
, lsa
)
2941 ospf_lsa_flush_schedule (ospf
, lsa
);
2942 #endif /* HAVE_OPAQUE_LSA */
2945 if (need_to_flush_ase
)
2947 LSDB_LOOP (EXTERNAL_LSDB (ospf
), rn
, lsa
)
2948 ospf_lsa_flush_schedule (ospf
, lsa
);
2949 #ifdef HAVE_OPAQUE_LSA
2950 LSDB_LOOP (OPAQUE_AS_LSDB (ospf
), rn
, lsa
)
2951 ospf_lsa_flush_schedule (ospf
, lsa
);
2952 #endif /* HAVE_OPAQUE_LSA */
2956 * Make sure that the MaxAge LSA remover is executed immediately,
2957 * without conflicting to other threads.
2959 if (ospf
->t_maxage
!= NULL
)
2961 OSPF_TIMER_OFF (ospf
->t_maxage
);
2962 thread_execute (master
, ospf_maxage_lsa_remover
, ospf
, 0);
2968 /* If there is self-originated LSA, then return 1, otherwise return 0. */
2969 /* An interface-independent version of ospf_lsa_is_self_originated */
2971 ospf_lsa_is_self_originated (struct ospf
*ospf
, struct ospf_lsa
*lsa
)
2975 /* This LSA is already checked. */
2976 if (CHECK_FLAG (lsa
->flags
, OSPF_LSA_SELF_CHECKED
))
2977 return CHECK_FLAG (lsa
->flags
, OSPF_LSA_SELF
);
2979 /* Make sure LSA is self-checked. */
2980 SET_FLAG (lsa
->flags
, OSPF_LSA_SELF_CHECKED
);
2982 /* AdvRouter and Router ID is the same. */
2983 if (IPV4_ADDR_SAME (&lsa
->data
->adv_router
, &ospf
->router_id
))
2984 SET_FLAG (lsa
->flags
, OSPF_LSA_SELF
);
2986 /* LSA is router-LSA. */
2987 else if (lsa
->data
->type
== OSPF_ROUTER_LSA
&&
2988 IPV4_ADDR_SAME (&lsa
->data
->id
, &ospf
->router_id
))
2989 SET_FLAG (lsa
->flags
, OSPF_LSA_SELF
);
2991 /* LSA is network-LSA. Compare Link ID with all interfaces. */
2992 else if (lsa
->data
->type
== OSPF_NETWORK_LSA
)
2993 for (node
= listhead (ospf
->oiflist
); node
; nextnode (node
))
2995 struct ospf_interface
*oi
= getdata (node
);
2997 /* Ignore virtual link. */
2998 if (oi
->type
!= OSPF_IFTYPE_VIRTUALLINK
)
2999 if (oi
->address
->family
== AF_INET
)
3000 if (IPV4_ADDR_SAME (&lsa
->data
->id
, &oi
->address
->u
.prefix4
))
3002 /* to make it easier later */
3003 SET_FLAG (lsa
->flags
, OSPF_LSA_SELF
);
3004 return CHECK_FLAG (lsa
->flags
, OSPF_LSA_SELF
);
3008 return CHECK_FLAG (lsa
->flags
, OSPF_LSA_SELF
);
3011 /* Get unique Link State ID. */
3013 ospf_lsa_unique_id (struct ospf
*ospf
,
3014 struct ospf_lsdb
*lsdb
, u_char type
, struct prefix_ipv4
*p
)
3016 struct ospf_lsa
*lsa
;
3017 struct in_addr mask
, id
;
3021 /* Check existence of LSA instance. */
3022 lsa
= ospf_lsdb_lookup_by_id (lsdb
, type
, id
, ospf
->router_id
);
3025 struct as_external_lsa
*al
= (struct as_external_lsa
*) lsa
->data
;
3026 if (ip_masklen (al
->mask
) == p
->prefixlen
)
3028 if (IS_DEBUG_OSPF (lsa
, LSA_GENERATE
))
3029 zlog_warn ("ospf_lsa_unique_id(): "
3030 "Can't get Link State ID for %s/%d",
3031 inet_ntoa (p
->prefix
), p
->prefixlen
);
3032 /* id.s_addr = 0; */
3033 id
.s_addr
= 0xffffffff;
3036 /* Masklen differs, then apply wildcard mask to Link State ID. */
3039 masklen2ip (p
->prefixlen
, &mask
);
3041 id
.s_addr
= p
->prefix
.s_addr
| (~mask
.s_addr
);
3042 lsa
= ospf_lsdb_lookup_by_id (ospf
->lsdb
, type
,
3043 id
, ospf
->router_id
);
3046 if (IS_DEBUG_OSPF (lsa
, LSA_GENERATE
))
3047 zlog_warn ("ospf_lsa_unique_id(): "
3048 "Can't get Link State ID for %s/%d",
3049 inet_ntoa (p
->prefix
), p
->prefixlen
);
3050 /* id.s_addr = 0; */
3051 id
.s_addr
= 0xffffffff;
3061 #define LSA_ACTION_ORIGN_RTR 1
3062 #define LSA_ACTION_ORIGN_NET 2
3063 #define LSA_ACTION_FLOOD_AREA 3
3064 #define LSA_ACTION_FLOOD_AS 4
3065 #define LSA_ACTION_FLUSH_AREA 5
3066 #define LSA_ACTION_FLUSH_AS 6
3071 struct ospf_area
*area
;
3072 struct ospf_interface
*oi
;
3073 struct ospf_lsa
*lsa
;
3077 ospf_lsa_action (struct thread
*t
)
3079 struct lsa_action
*data
;
3082 ospf
= ospf_lookup ();
3084 data
= THREAD_ARG (t
);
3086 if (IS_DEBUG_OSPF (lsa
, LSA
) == OSPF_DEBUG_LSA
)
3087 zlog_info ("LSA[Action]: Performing scheduled LSA action: %d",
3090 switch (data
->action
)
3092 case LSA_ACTION_ORIGN_RTR
:
3093 ospf_router_lsa_refresh (data
->area
->router_lsa_self
);
3095 case LSA_ACTION_ORIGN_NET
:
3096 ospf_network_lsa_originate (data
->oi
);
3098 case LSA_ACTION_FLOOD_AREA
:
3099 ospf_flood_through_area (data
->area
, NULL
, data
->lsa
);
3101 case LSA_ACTION_FLOOD_AS
:
3102 ospf_flood_through_as (ospf
, NULL
, data
->lsa
);
3104 case LSA_ACTION_FLUSH_AREA
:
3105 ospf_lsa_flush_area (data
->lsa
, data
->area
);
3107 case LSA_ACTION_FLUSH_AS
:
3108 ospf_lsa_flush_as (ospf
, data
->lsa
);
3112 ospf_lsa_unlock (data
->lsa
);
3113 XFREE (MTYPE_OSPF_MESSAGE
, data
);
3118 ospf_schedule_lsa_flood_area (struct ospf_area
*area
, struct ospf_lsa
*lsa
)
3120 struct lsa_action
*data
;
3122 data
= XMALLOC (MTYPE_OSPF_MESSAGE
, sizeof (struct lsa_action
));
3123 memset (data
, 0, sizeof (struct lsa_action
));
3125 data
->action
= LSA_ACTION_FLOOD_AREA
;
3127 data
->lsa
= ospf_lsa_lock (lsa
);
3129 thread_add_event (master
, ospf_lsa_action
, data
, 0);
3133 ospf_schedule_lsa_flush_area (struct ospf_area
*area
, struct ospf_lsa
*lsa
)
3135 struct lsa_action
*data
;
3137 data
= XMALLOC (MTYPE_OSPF_MESSAGE
, sizeof (struct lsa_action
));
3138 memset (data
, 0, sizeof (struct lsa_action
));
3140 data
->action
= LSA_ACTION_FLUSH_AREA
;
3142 data
->lsa
= ospf_lsa_lock (lsa
);
3144 thread_add_event (master
, ospf_lsa_action
, data
, 0);
3148 /* LSA Refreshment functions. */
3150 ospf_lsa_refresh (struct ospf
*ospf
, struct ospf_lsa
*lsa
)
3152 struct external_info
*ei
;
3153 assert (CHECK_FLAG (lsa
->flags
, OSPF_LSA_SELF
));
3155 switch (lsa
->data
->type
)
3157 /* Router and Network LSAs are processed differently. */
3158 case OSPF_ROUTER_LSA
:
3159 case OSPF_NETWORK_LSA
:
3161 case OSPF_SUMMARY_LSA
:
3162 ospf_summary_lsa_refresh (ospf
, lsa
);
3164 case OSPF_ASBR_SUMMARY_LSA
:
3165 ospf_summary_asbr_lsa_refresh (ospf
, lsa
);
3167 case OSPF_AS_EXTERNAL_LSA
:
3168 ei
= ospf_external_info_check (lsa
);
3170 ospf_external_lsa_refresh (ospf
, lsa
, ei
, LSA_REFRESH_FORCE
);
3172 ospf_lsa_flush_as (ospf
, lsa
);
3174 #ifdef HAVE_OPAQUE_LSA
3175 case OSPF_OPAQUE_LINK_LSA
:
3176 case OSPF_OPAQUE_AREA_LSA
:
3177 case OSPF_OPAQUE_AS_LSA
:
3178 ospf_opaque_lsa_refresh (lsa
);
3180 #endif /* HAVE_OPAQUE_LSA */
3187 ospf_refresher_register_lsa (struct ospf
*ospf
, struct ospf_lsa
*lsa
)
3189 u_int16_t index
, current_index
;
3191 assert (CHECK_FLAG (lsa
->flags
, OSPF_LSA_SELF
));
3193 if (lsa
->refresh_list
< 0)
3197 if (LS_AGE (lsa
) == 0 &&
3198 ntohl (lsa
->data
->ls_seqnum
) == OSPF_INITIAL_SEQUENCE_NUMBER
)
3199 /* Randomize first update by OSPF_LS_REFRESH_SHIFT factor */
3200 delay
= OSPF_LS_REFRESH_SHIFT
+ (random () % OSPF_LS_REFRESH_TIME
);
3202 /* Randomize another updates by +-OSPF_LS_REFRESH_JITTER factor */
3203 delay
= OSPF_LS_REFRESH_TIME
- LS_AGE (lsa
) - OSPF_LS_REFRESH_JITTER
3204 + (random () % (2*OSPF_LS_REFRESH_JITTER
));
3209 current_index
= ospf
->lsa_refresh_queue
.index
+
3210 (time (NULL
) - ospf
->lsa_refresher_started
)/OSPF_LSA_REFRESHER_GRANULARITY
;
3212 index
= (current_index
+ delay
/OSPF_LSA_REFRESHER_GRANULARITY
)
3213 % (OSPF_LSA_REFRESHER_SLOTS
);
3215 if (IS_DEBUG_OSPF (lsa
, LSA_REFRESH
))
3216 zlog_info ("LSA[Refresh]: lsa with age %d added to index %d",
3217 LS_AGE (lsa
), index
);
3218 if (!ospf
->lsa_refresh_queue
.qs
[index
])
3219 ospf
->lsa_refresh_queue
.qs
[index
] = list_new ();
3220 listnode_add (ospf
->lsa_refresh_queue
.qs
[index
], ospf_lsa_lock (lsa
));
3221 lsa
->refresh_list
= index
;
3226 ospf_refresher_unregister_lsa (struct ospf
*ospf
, struct ospf_lsa
*lsa
)
3228 assert (CHECK_FLAG (lsa
->flags
, OSPF_LSA_SELF
));
3229 if (lsa
->refresh_list
>= 0)
3231 list refresh_list
= ospf
->lsa_refresh_queue
.qs
[lsa
->refresh_list
];
3232 listnode_delete (refresh_list
, lsa
);
3233 if (!listcount (refresh_list
))
3235 list_free (refresh_list
);
3236 ospf
->lsa_refresh_queue
.qs
[lsa
->refresh_list
] = NULL
;
3238 ospf_lsa_unlock (lsa
);
3239 lsa
->refresh_list
= -1;
3244 ospf_lsa_refresh_walker (struct thread
*t
)
3248 struct ospf
*ospf
= THREAD_ARG (t
);
3250 list lsa_to_refresh
= list_new ();
3252 if (IS_DEBUG_OSPF (lsa
, LSA_REFRESH
))
3253 zlog_info ("LSA[Refresh]:ospf_lsa_refresh_walker(): start");
3256 i
= ospf
->lsa_refresh_queue
.index
;
3258 ospf
->lsa_refresh_queue
.index
=
3259 (ospf
->lsa_refresh_queue
.index
+
3260 (time (NULL
) - ospf
->lsa_refresher_started
) / OSPF_LSA_REFRESHER_GRANULARITY
)
3261 % OSPF_LSA_REFRESHER_SLOTS
;
3263 if (IS_DEBUG_OSPF (lsa
, LSA_REFRESH
))
3264 zlog_info ("LSA[Refresh]: ospf_lsa_refresh_walker(): next index %d",
3265 ospf
->lsa_refresh_queue
.index
);
3267 for (;i
!= ospf
->lsa_refresh_queue
.index
;
3268 i
= (i
+ 1) % OSPF_LSA_REFRESHER_SLOTS
)
3270 if (IS_DEBUG_OSPF (lsa
, LSA_REFRESH
))
3271 zlog_info ("LSA[Refresh]: ospf_lsa_refresh_walker(): refresh index %d", i
);
3273 refresh_list
= ospf
->lsa_refresh_queue
.qs
[i
];
3275 ospf
->lsa_refresh_queue
.qs
[i
] = NULL
;
3279 for (node
= listhead (refresh_list
); node
;)
3282 struct ospf_lsa
*lsa
= getdata (node
);
3285 if (IS_DEBUG_OSPF (lsa
, LSA_REFRESH
))
3286 zlog_info ("LSA[Refresh]: ospf_lsa_refresh_walker(): refresh lsa %p", lsa
);
3288 list_delete_node (refresh_list
, node
);
3289 ospf_lsa_unlock (lsa
);
3290 lsa
->refresh_list
= -1;
3291 listnode_add (lsa_to_refresh
, lsa
);
3294 list_free (refresh_list
);
3298 ospf
->t_lsa_refresher
= thread_add_timer (master
, ospf_lsa_refresh_walker
,
3299 ospf
, ospf
->lsa_refresh_interval
);
3300 ospf
->lsa_refresher_started
= time (NULL
);
3302 for (node
= listhead (lsa_to_refresh
); node
; nextnode (node
))
3303 ospf_lsa_refresh (ospf
, getdata (node
));
3305 list_delete (lsa_to_refresh
);
3307 if (IS_DEBUG_OSPF (lsa
, LSA_REFRESH
))
3308 zlog_info ("LSA[Refresh]: ospf_lsa_refresh_walker(): end");