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
603 /* from "edward rrr" <edward_rrr@hotmail.com>
604 http://marc.theaimsgroup.com/?l=zebra&m=100739222210507&w=2 */
606 lsa_link_ptomp_set (struct stream
*s
, struct ospf_interface
*oi
)
609 struct route_node
*rn
;
610 struct ospf_neighbor
*nbr
= NULL
;
611 struct in_addr id
, mask
;
613 mask
.s_addr
= 0xffffffff;
614 id
.s_addr
= oi
->address
->u
.prefix4
.s_addr
;
615 link_info_set (s
, id
, mask
, LSA_LINK_TYPE_STUB
, 0, 0);
618 if (IS_DEBUG_OSPF (lsa
, LSA_GENERATE
))
619 zlog_info ("PointToMultipoint: running ptomultip_set");
621 /* Search neighbor, */
622 for (rn
= route_top (oi
->nbrs
); rn
; rn
= route_next (rn
))
623 if ((nbr
= rn
->info
) != NULL
)
625 if (!IPV4_ADDR_SAME (&nbr
->router_id
, &oi
->ospf
->router_id
))
626 if (nbr
->state
== NSM_Full
)
629 link_info_set (s
, nbr
->router_id
, oi
->address
->u
.prefix4
,
630 LSA_LINK_TYPE_POINTOPOINT
, 0, oi
->output_cost
);
632 if (IS_DEBUG_OSPF (lsa
, LSA_GENERATE
))
633 zlog_info ("PointToMultipoint: set link to %s",
634 inet_ntoa(oi
->address
->u
.prefix4
));
640 /* Set router-LSA link information. */
642 router_lsa_link_set (struct stream
*s
, struct ospf_area
*area
)
647 for (node
= listhead (area
->oiflist
); node
; node
= nextnode (node
))
649 struct ospf_interface
*oi
= node
->data
;
650 struct interface
*ifp
= oi
->ifp
;
652 /* Check interface is up, OSPF is enable. */
653 if (if_is_operative (ifp
))
655 if (oi
->state
!= ISM_Down
)
657 /* Describe each link. */
660 case OSPF_IFTYPE_POINTOPOINT
:
661 links
+= lsa_link_ptop_set (s
, oi
);
663 case OSPF_IFTYPE_BROADCAST
:
664 links
+= lsa_link_broadcast_set (s
, oi
);
666 case OSPF_IFTYPE_NBMA
:
667 links
+= lsa_link_nbma_set (s
, oi
);
669 case OSPF_IFTYPE_POINTOMULTIPOINT
:
670 links
+= lsa_link_ptomp_set (s
, oi
);
672 case OSPF_IFTYPE_VIRTUALLINK
:
673 links
+= lsa_link_virtuallink_set (s
, oi
);
675 case OSPF_IFTYPE_LOOPBACK
:
676 links
+= lsa_link_loopback_set (s
, oi
);
685 /* Set router-LSA body. */
687 ospf_router_lsa_body_set (struct stream
*s
, struct ospf_area
*area
)
693 stream_putc (s
, router_lsa_flags (area
));
695 /* Set Zero fields. */
698 /* Keep pointer to # links. */
704 /* Set all link information. */
705 cnt
= router_lsa_link_set (s
, area
);
707 /* Set # of links here. */
708 stream_putw_at (s
, putp
, cnt
);
711 /* Create new router-LSA. */
713 ospf_router_lsa_new (struct ospf_area
*area
)
715 struct ospf
*ospf
= area
->ospf
;
717 struct lsa_header
*lsah
;
718 struct ospf_lsa
*new;
721 if (IS_DEBUG_OSPF (lsa
, LSA_GENERATE
))
722 zlog_info ("LSA[Type1]: Create router-LSA instance");
724 /* Create a stream for LSA. */
725 s
= stream_new (OSPF_MAX_LSA_SIZE
);
726 lsah
= (struct lsa_header
*) STREAM_DATA (s
);
729 /* Set LSA common header fields. */
730 lsa_header_set (s
, LSA_OPTIONS_GET (area
) | LSA_NSSA_GET (area
),
731 OSPF_ROUTER_LSA
, ospf
->router_id
, ospf
->router_id
);
732 #else /* ! HAVE_NSSA */
733 /* Set LSA common header fields. */
734 lsa_header_set (s
, LSA_OPTIONS_GET (area
),
735 OSPF_ROUTER_LSA
, ospf
->router_id
, ospf
->router_id
);
736 #endif /* HAVE_NSSA */
738 /* Set router-LSA body fields. */
739 ospf_router_lsa_body_set (s
, area
);
742 length
= stream_get_endp (s
);
743 lsah
->length
= htons (length
);
745 /* Now, create OSPF LSA instance. */
746 new = ospf_lsa_new ();
748 SET_FLAG (new->flags
, OSPF_LSA_SELF
);
750 /* Copy LSA data to store, discard stream. */
751 new->data
= ospf_lsa_data_new (length
);
752 memcpy (new->data
, lsah
, length
);
758 /* Originate Router-LSA. */
760 ospf_router_lsa_originate (struct ospf_area
*area
)
762 struct ospf_lsa
*new;
764 /* Create new router-LSA instance. */
765 new = ospf_router_lsa_new (area
);
768 if (new->data
->adv_router
.s_addr
== 0)
770 if (IS_DEBUG_OSPF_EVENT
)
771 zlog_info ("LSA[Type1]: AdvRouter is 0, discard");
772 ospf_lsa_discard (new);
776 /* Install LSA to LSDB. */
777 new = ospf_lsa_install (area
->ospf
, NULL
, new);
779 /* Update LSA origination count. */
780 area
->ospf
->lsa_originate_count
++;
782 /* Flooding new LSA through area. */
783 ospf_flood_through_area (area
, NULL
, new);
785 if (IS_DEBUG_OSPF (lsa
, LSA_GENERATE
))
787 zlog_info ("LSA[Type%d:%s]: Originate router-LSA %p",
788 new->data
->type
, inet_ntoa (new->data
->id
), new);
789 ospf_lsa_header_dump (new->data
);
795 /* Refresh router-LSA. */
797 ospf_router_lsa_refresh (struct ospf_lsa
*lsa
)
799 struct ospf_area
*area
= lsa
->area
;
800 struct ospf_lsa
*new;
805 /* Delete LSA from neighbor retransmit-list. */
806 ospf_ls_retransmit_delete_nbr_area (area
, lsa
);
808 /* Create new router-LSA instance. */
809 new = ospf_router_lsa_new (area
);
810 new->data
->ls_seqnum
= lsa_seqnum_increment (lsa
);
812 ospf_lsa_install (area
->ospf
, NULL
, new);
814 /* Flood LSA through area. */
815 ospf_flood_through_area (area
, NULL
, new);
818 if (IS_DEBUG_OSPF (lsa
, LSA_GENERATE
))
820 zlog_info ("LSA[Type%d:%s]: router-LSA refresh",
821 new->data
->type
, inet_ntoa (new->data
->id
));
822 ospf_lsa_header_dump (new->data
);
829 ospf_router_lsa_timer (struct thread
*t
)
831 struct ospf_area
*area
;
833 if (IS_DEBUG_OSPF_EVENT
)
834 zlog_info ("Timer[router-LSA]: (router-LSA Refresh expire)");
836 area
= THREAD_ARG (t
);
837 area
->t_router_lsa_self
= NULL
;
839 /* Now refresh router-LSA. */
840 if (area
->router_lsa_self
)
841 ospf_router_lsa_refresh (area
->router_lsa_self
);
842 /* Newly originate router-LSA. */
844 ospf_router_lsa_originate (area
);
850 ospf_router_lsa_timer_add (struct ospf_area
*area
)
852 /* Keep area's self-originated router-LSA. */
853 struct ospf_lsa
*lsa
= area
->router_lsa_self
;
855 /* Cancel previously scheduled router-LSA timer. */
856 if (area
->t_router_lsa_self
)
857 if (IS_DEBUG_OSPF (lsa
, LSA_GENERATE
))
858 zlog_info ("LSA[Type1]: Cancel previous router-LSA timer");
860 OSPF_TIMER_OFF (area
->t_router_lsa_self
);
862 /* If router-LSA is originated previously, check the interval time. */
866 if ((delay
= ospf_lsa_refresh_delay (lsa
)) > 0)
868 OSPF_AREA_TIMER_ON (area
->t_router_lsa_self
,
869 ospf_router_lsa_timer
, delay
);
874 if (IS_DEBUG_OSPF (lsa
, LSA_GENERATE
))
875 zlog_info ("LSA[Type1]: Scheduling router-LSA origination right away");
877 /* Immediately refresh router-LSA. */
878 OSPF_AREA_TIMER_ON (area
->t_router_lsa_self
, ospf_router_lsa_timer
, 0);
882 ospf_router_lsa_update_timer (struct thread
*thread
)
884 struct ospf
*ospf
= THREAD_ARG (thread
);
887 if (IS_DEBUG_OSPF (lsa
, LSA_GENERATE
))
888 zlog_info ("Timer[router-LSA Update]: (timer expire)");
890 ospf
->t_router_lsa_update
= NULL
;
892 for (node
= listhead (ospf
->areas
); node
; nextnode (node
))
894 struct ospf_area
*area
= getdata (node
);
895 struct ospf_lsa
*lsa
= area
->router_lsa_self
;
896 struct router_lsa
*rl
;
899 /* Keep Area ID string. */
900 area_str
= AREA_NAME (area
);
902 /* If LSA not exist in this Area, originate new. */
905 if (IS_DEBUG_OSPF (lsa
, LSA_GENERATE
))
906 zlog_info("LSA[Type1]: Create router-LSA for Area %s", area_str
);
908 ospf_router_lsa_originate (area
);
910 /* If router-ID is changed, Link ID must change.
911 First flush old LSA, then originate new. */
912 else if (!IPV4_ADDR_SAME (&lsa
->data
->id
, &ospf
->router_id
))
914 if (IS_DEBUG_OSPF (lsa
, LSA_GENERATE
))
915 zlog_info("LSA[Type%d:%s]: Refresh router-LSA for Area %s",
916 lsa
->data
->type
, inet_ntoa (lsa
->data
->id
), area_str
);
917 ospf_lsa_flush_area (lsa
, area
);
918 ospf_lsa_unlock (area
->router_lsa_self
);
919 area
->router_lsa_self
= NULL
;
921 /* Refresh router-LSA, (not install) and flood through area. */
922 ospf_router_lsa_timer_add (area
);
926 rl
= (struct router_lsa
*) lsa
->data
;
927 /* Refresh router-LSA, (not install) and flood through area. */
928 if (rl
->flags
!= ospf
->flags
)
929 ospf_router_lsa_timer_add (area
);
937 /* network-LSA related functions. */
938 /* Originate Network-LSA. */
940 ospf_network_lsa_body_set (struct stream
*s
, struct ospf_interface
*oi
)
943 struct route_node
*rn
;
944 struct ospf_neighbor
*nbr
;
946 masklen2ip (oi
->address
->prefixlen
, &mask
);
947 stream_put_ipv4 (s
, mask
.s_addr
);
949 /* The network-LSA lists those routers that are fully adjacent to
950 the Designated Router; each fully adjacent router is identified by
951 its OSPF Router ID. The Designated Router includes itself in this
952 list. RFC2328, Section 12.4.2 */
954 for (rn
= route_top (oi
->nbrs
); rn
; rn
= route_next (rn
))
955 if ((nbr
= rn
->info
) != NULL
)
956 if (nbr
->state
== NSM_Full
|| nbr
== oi
->nbr_self
)
957 stream_put_ipv4 (s
, nbr
->router_id
.s_addr
);
961 ospf_network_lsa_new (struct ospf_interface
*oi
)
964 struct ospf_lsa
*new;
965 struct lsa_header
*lsah
;
968 /* If there are no neighbours on this network (the net is stub),
969 the router does not originate network-LSA (see RFC 12.4.2) */
970 if (oi
->full_nbrs
== 0)
973 if (IS_DEBUG_OSPF (lsa
, LSA_GENERATE
))
974 zlog_info ("LSA[Type2]: Create network-LSA instance");
976 /* Create new stream for LSA. */
977 s
= stream_new (OSPF_MAX_LSA_SIZE
);
978 lsah
= (struct lsa_header
*) STREAM_DATA (s
);
980 lsa_header_set (s
, (OPTIONS (oi
) | LSA_OPTIONS_GET (oi
->area
)),
981 OSPF_NETWORK_LSA
, DR (oi
), oi
->ospf
->router_id
);
983 /* Set network-LSA body fields. */
984 ospf_network_lsa_body_set (s
, oi
);
987 length
= stream_get_endp (s
);
988 lsah
->length
= htons (length
);
990 /* Create OSPF LSA instance. */
991 new = ospf_lsa_new ();
992 new->area
= oi
->area
;
993 SET_FLAG (new->flags
, OSPF_LSA_SELF
);
995 /* Copy LSA to store. */
996 new->data
= ospf_lsa_data_new (length
);
997 memcpy (new->data
, lsah
, length
);
1003 /* Originate network-LSA. */
1005 ospf_network_lsa_originate (struct ospf_interface
*oi
)
1007 struct ospf_lsa
*new;
1009 /* Create new network-LSA instance. */
1010 new = ospf_network_lsa_new (oi
);
1014 /* Install LSA to LSDB. */
1015 new = ospf_lsa_install (oi
->ospf
, oi
, new);
1017 /* Update LSA origination count. */
1018 oi
->ospf
->lsa_originate_count
++;
1020 /* Flooding new LSA through area. */
1021 ospf_flood_through_area (oi
->area
, NULL
, new);
1023 if (IS_DEBUG_OSPF (lsa
, LSA_GENERATE
))
1025 zlog_info ("LSA[Type%d:%s]: Originate network-LSA %p",
1026 new->data
->type
, inet_ntoa (new->data
->id
), new);
1027 ospf_lsa_header_dump (new->data
);
1034 ospf_network_lsa_refresh (struct ospf_lsa
*lsa
, struct ospf_interface
*oi
)
1036 struct ospf_area
*area
= lsa
->area
;
1037 struct ospf_lsa
*new;
1041 /* Delete LSA from neighbor retransmit-list. */
1042 ospf_ls_retransmit_delete_nbr_area (area
, lsa
);
1044 /* Create new network-LSA instance. */
1045 new = ospf_network_lsa_new (oi
);
1048 new->data
->ls_seqnum
= lsa_seqnum_increment (lsa
);
1050 ospf_lsa_install (area
->ospf
, oi
, new);
1052 /* Flood LSA through aera. */
1053 ospf_flood_through_area (area
, NULL
, new);
1055 if (IS_DEBUG_OSPF (lsa
, LSA_GENERATE
))
1057 zlog_info ("LSA[Type%d:%s]: network-LSA refresh",
1058 new->data
->type
, inet_ntoa (new->data
->id
));
1059 ospf_lsa_header_dump (new->data
);
1066 ospf_network_lsa_refresh_timer (struct thread
*t
)
1068 struct ospf_interface
*oi
;
1070 oi
= THREAD_ARG (t
);
1071 oi
->t_network_lsa_self
= NULL
;
1073 if (oi
->network_lsa_self
)
1074 /* Now refresh network-LSA. */
1075 ospf_network_lsa_refresh (oi
->network_lsa_self
, oi
);
1077 /* Newly create network-LSA. */
1078 ospf_network_lsa_originate (oi
);
1084 ospf_network_lsa_timer_add (struct ospf_interface
*oi
)
1086 /* Keep interface's self-originated network-LSA. */
1087 struct ospf_lsa
*lsa
= oi
->network_lsa_self
;
1089 /* Cancel previously schedules network-LSA timer. */
1090 if (oi
->t_network_lsa_self
)
1091 if (IS_DEBUG_OSPF (lsa
, LSA_GENERATE
))
1092 zlog_info ("LSA[Type2]: Cancel previous network-LSA timer");
1093 OSPF_TIMER_OFF (oi
->t_network_lsa_self
);
1095 /* If network-LSA is originated previously, check the interval time. */
1099 if ((delay
= ospf_lsa_refresh_delay (lsa
)) > 0)
1101 oi
->t_network_lsa_self
=
1102 thread_add_timer (master
, ospf_network_lsa_refresh_timer
,
1108 if (IS_DEBUG_OSPF (lsa
, LSA_GENERATE
))
1109 zlog_info ("Scheduling network-LSA origination right away");
1111 /* Immediately refresh network-LSA. */
1112 oi
->t_network_lsa_self
=
1113 thread_add_event (master
, ospf_network_lsa_refresh_timer
, oi
, 0);
1118 stream_put_ospf_metric (struct stream
*s
, u_int32_t metric_value
)
1123 /* Put 0 metric. TOS metric is not supported. */
1124 metric
= htonl (metric_value
);
1125 mp
= (char *) &metric
;
1127 stream_put (s
, mp
, 3);
1130 /* summary-LSA related functions. */
1132 ospf_summary_lsa_body_set (struct stream
*s
, struct prefix
*p
,
1135 struct in_addr mask
;
1137 masklen2ip (p
->prefixlen
, &mask
);
1139 /* Put Network Mask. */
1140 stream_put_ipv4 (s
, mask
.s_addr
);
1143 stream_putc (s
, (u_char
) 0);
1146 stream_put_ospf_metric (s
, metric
);
1150 ospf_summary_lsa_new (struct ospf_area
*area
, struct prefix
*p
,
1151 u_int32_t metric
, struct in_addr id
)
1154 struct ospf_lsa
*new;
1155 struct lsa_header
*lsah
;
1158 if (IS_DEBUG_OSPF (lsa
, LSA_GENERATE
))
1159 zlog_info ("LSA[Type3]: Create summary-LSA instance");
1161 /* Create new stream for LSA. */
1162 s
= stream_new (OSPF_MAX_LSA_SIZE
);
1163 lsah
= (struct lsa_header
*) STREAM_DATA (s
);
1165 lsa_header_set (s
, LSA_OPTIONS_GET (area
), OSPF_SUMMARY_LSA
,
1166 id
, area
->ospf
->router_id
);
1168 /* Set summary-LSA body fields. */
1169 ospf_summary_lsa_body_set (s
, p
, metric
);
1172 length
= stream_get_endp (s
);
1173 lsah
->length
= htons (length
);
1175 /* Create OSPF LSA instance. */
1176 new = ospf_lsa_new ();
1178 SET_FLAG (new->flags
, OSPF_LSA_SELF
);
1180 /* Copy LSA to store. */
1181 new->data
= ospf_lsa_data_new (length
);
1182 memcpy (new->data
, lsah
, length
);
1188 /* Originate Summary-LSA. */
1190 ospf_summary_lsa_originate (struct prefix_ipv4
*p
, u_int32_t metric
,
1191 struct ospf_area
*area
)
1193 struct ospf_lsa
*new;
1196 id
= ospf_lsa_unique_id (area
->ospf
, area
->lsdb
, OSPF_SUMMARY_LSA
, p
);
1198 /* Create new summary-LSA instance. */
1199 new = ospf_summary_lsa_new (area
, (struct prefix
*) p
, metric
, id
);
1201 /* Instlal LSA to LSDB. */
1202 new = ospf_lsa_install (area
->ospf
, NULL
, new);
1204 /* Update LSA origination count. */
1205 area
->ospf
->lsa_originate_count
++;
1207 /* Flooding new LSA through area. */
1208 ospf_flood_through_area (area
, NULL
, new);
1210 if (IS_DEBUG_OSPF (lsa
, LSA_GENERATE
))
1212 zlog_info ("LSA[Type%d:%s]: Originate summary-LSA %p",
1213 new->data
->type
, inet_ntoa (new->data
->id
), new);
1214 ospf_lsa_header_dump (new->data
);
1221 ospf_summary_lsa_refresh (struct ospf
*ospf
, struct ospf_lsa
*lsa
)
1223 struct ospf_lsa
*new;
1224 struct summary_lsa
*sl
;
1230 sl
= (struct summary_lsa
*)lsa
->data
;
1231 p
.prefixlen
= ip_masklen (sl
->mask
);
1232 new = ospf_summary_lsa_new (lsa
->area
, &p
, GET_METRIC (sl
->metric
),
1235 new->data
->ls_seqnum
= lsa_seqnum_increment (lsa
);
1237 /* Re-calculate checksum. */
1238 ospf_lsa_checksum (new->data
);
1240 ospf_lsa_install (ospf
, NULL
, new);
1242 /* Flood LSA through AS. */
1243 ospf_flood_through_area (new->area
, NULL
, new);
1245 /* Debug logging. */
1246 if (IS_DEBUG_OSPF (lsa
, LSA_GENERATE
))
1248 zlog_info ("LSA[Type%d:%s]: summary-LSA refresh",
1249 new->data
->type
, inet_ntoa (new->data
->id
));
1250 ospf_lsa_header_dump (new->data
);
1257 /* summary-ASBR-LSA related functions. */
1259 ospf_summary_asbr_lsa_body_set (struct stream
*s
, struct prefix
*p
,
1262 struct in_addr mask
;
1264 masklen2ip (p
->prefixlen
, &mask
);
1266 /* Put Network Mask. */
1267 stream_put_ipv4 (s
, mask
.s_addr
);
1270 stream_putc (s
, (u_char
) 0);
1273 stream_put_ospf_metric (s
, metric
);
1277 ospf_summary_asbr_lsa_new (struct ospf_area
*area
, struct prefix
*p
,
1278 u_int32_t metric
, struct in_addr id
)
1281 struct ospf_lsa
*new;
1282 struct lsa_header
*lsah
;
1285 if (IS_DEBUG_OSPF (lsa
, LSA_GENERATE
))
1286 zlog_info ("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_ASBR_SUMMARY_LSA
,
1293 id
, area
->ospf
->router_id
);
1295 /* Set summary-LSA body fields. */
1296 ospf_summary_asbr_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-ASBR-LSA. */
1317 ospf_summary_asbr_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_ASBR_SUMMARY_LSA
, p
);
1325 /* Create new summary-LSA instance. */
1326 new = ospf_summary_asbr_lsa_new (area
, (struct prefix
*) p
, metric
, id
);
1328 /* Install LSA to LSDB. */
1329 new = ospf_lsa_install (area
->ospf
, NULL
, new);
1331 /* Update LSA origination count. */
1332 area
->ospf
->lsa_originate_count
++;
1334 /* Flooding new LSA through area. */
1335 ospf_flood_through_area (area
, NULL
, new);
1337 if (IS_DEBUG_OSPF (lsa
, LSA_GENERATE
))
1339 zlog_info ("LSA[Type%d:%s]: Originate summary-ASBR-LSA %p",
1340 new->data
->type
, inet_ntoa (new->data
->id
), new);
1341 ospf_lsa_header_dump (new->data
);
1348 ospf_summary_asbr_lsa_refresh (struct ospf
*ospf
, struct ospf_lsa
*lsa
)
1350 struct ospf_lsa
*new;
1351 struct summary_lsa
*sl
;
1357 sl
= (struct summary_lsa
*)lsa
->data
;
1358 p
.prefixlen
= ip_masklen (sl
->mask
);
1359 new = ospf_summary_asbr_lsa_new (lsa
->area
, &p
, GET_METRIC (sl
->metric
),
1362 new->data
->ls_seqnum
= lsa_seqnum_increment (lsa
);
1364 /* Re-calculate checksum. */
1365 ospf_lsa_checksum (new->data
);
1367 ospf_lsa_install (ospf
, NULL
, new);
1369 /* Flood LSA through area. */
1370 ospf_flood_through_area (new->area
, NULL
, new);
1372 if (IS_DEBUG_OSPF (lsa
, LSA_GENERATE
))
1374 zlog_info ("LSA[Type%d:%s]: summary-ASBR-LSA refresh",
1375 new->data
->type
, inet_ntoa (new->data
->id
));
1376 ospf_lsa_header_dump (new->data
);
1382 /* AS-external-LSA related functions. */
1384 /* Get nexthop for AS-external-LSAs. Return nexthop if its interface
1385 is connected, else 0*/
1387 ospf_external_lsa_nexthop_get (struct ospf
*ospf
, struct in_addr nexthop
)
1395 if (!nexthop
.s_addr
)
1398 /* Check whether nexthop is covered by OSPF network. */
1399 nh
.family
= AF_INET
;
1400 nh
.u
.prefix4
= nexthop
;
1401 nh
.prefixlen
= IPV4_MAX_BITLEN
;
1403 for (n1
= listhead (ospf
->oiflist
); n1
; nextnode (n1
))
1405 struct ospf_interface
*oi
= getdata (n1
);
1407 if (if_is_operative (oi
->ifp
))
1408 if (oi
->address
->family
== AF_INET
)
1409 if (prefix_match (oi
->address
, &nh
))
1417 /* NSSA-external-LSA related functions. */
1419 /* Get 1st IP connection for Forward Addr */
1422 ospf_get_ip_from_ifp (struct ospf_interface
*oi
)
1428 if (if_is_operative (oi
->ifp
))
1429 return oi
->address
->u
.prefix4
;
1434 /* Get 1st IP connection for Forward Addr */
1436 ospf_get_nssa_ip (struct ospf_area
*area
)
1439 struct in_addr best_default
;
1443 best_default
.s_addr
= 0;
1445 for (n1
= listhead (area
->ospf
->oiflist
); n1
; nextnode (n1
))
1447 struct ospf_interface
*oi
= getdata (n1
);
1449 if (if_is_operative (oi
->ifp
))
1450 if (oi
->area
->external_routing
== OSPF_AREA_NSSA
)
1451 if (oi
->address
&& oi
->address
->family
== AF_INET
)
1453 if (best_default
.s_addr
== 0)
1454 best_default
= oi
->address
->u
.prefix4
;
1455 if (oi
->area
== area
)
1456 return oi
->address
->u
.prefix4
;
1459 if (best_default
.s_addr
!= 0)
1460 return best_default
;
1462 if (best_default
.s_addr
!= 0)
1463 return best_default
;
1467 #endif /* HAVE_NSSA */
1469 #define DEFAULT_DEFAULT_METRIC 20
1470 #define DEFAULT_DEFAULT_ORIGINATE_METRIC 10
1471 #define DEFAULT_DEFAULT_ALWAYS_METRIC 1
1473 #define DEFAULT_METRIC_TYPE EXTERNAL_METRIC_TYPE_2
1476 metric_type (struct ospf
*ospf
, u_char src
)
1478 return (ospf
->dmetric
[src
].type
< 0 ?
1479 DEFAULT_METRIC_TYPE
: ospf
->dmetric
[src
].type
);
1483 metric_value (struct ospf
*ospf
, u_char src
)
1485 if (ospf
->dmetric
[src
].value
< 0)
1487 if (src
== DEFAULT_ROUTE
)
1489 if (ospf
->default_originate
== DEFAULT_ORIGINATE_ZEBRA
)
1490 return DEFAULT_DEFAULT_ORIGINATE_METRIC
;
1492 return DEFAULT_DEFAULT_ALWAYS_METRIC
;
1494 else if (ospf
->default_metric
< 0)
1495 return DEFAULT_DEFAULT_METRIC
;
1497 return ospf
->default_metric
;
1500 return ospf
->dmetric
[src
].value
;
1503 /* Set AS-external-LSA body. */
1505 ospf_external_lsa_body_set (struct stream
*s
, struct external_info
*ei
,
1508 struct prefix_ipv4
*p
= &ei
->p
;
1509 struct in_addr mask
, fwd_addr
;
1514 /* Put Network Mask. */
1515 masklen2ip (p
->prefixlen
, &mask
);
1516 stream_put_ipv4 (s
, mask
.s_addr
);
1518 /* If prefix is default, specify DEFAULT_ROUTE. */
1519 type
= is_prefix_default (&ei
->p
) ? DEFAULT_ROUTE
: ei
->type
;
1521 mtype
= (ROUTEMAP_METRIC_TYPE (ei
) != -1) ?
1522 ROUTEMAP_METRIC_TYPE (ei
) : metric_type (ospf
, type
);
1524 mvalue
= (ROUTEMAP_METRIC (ei
) != -1) ?
1525 ROUTEMAP_METRIC (ei
) : metric_value (ospf
, type
);
1527 /* Put type of external metric. */
1528 stream_putc (s
, (mtype
== EXTERNAL_METRIC_TYPE_2
? 0x80 : 0));
1530 /* Put 0 metric. TOS metric is not supported. */
1531 stream_put_ospf_metric (s
, mvalue
);
1533 /* Get forwarding address to nexthop if on the Connection List, else 0. */
1534 fwd_addr
= ospf_external_lsa_nexthop_get (ospf
, ei
->nexthop
);
1536 /* Put forwarding address. */
1537 stream_put_ipv4 (s
, fwd_addr
.s_addr
);
1539 /* Put route tag -- This value should be introduced from configuration. */
1543 /* Create new external-LSA. */
1545 ospf_external_lsa_new (struct ospf
*ospf
,
1546 struct external_info
*ei
, struct in_addr
*old_id
)
1549 struct lsa_header
*lsah
;
1550 struct ospf_lsa
*new;
1556 if (IS_DEBUG_OSPF (lsa
, LSA_GENERATE
))
1557 zlog_warn ("LSA[Type5]: External info is NULL, could not originated");
1561 if (IS_DEBUG_OSPF (lsa
, LSA_GENERATE
))
1562 zlog_info ("LSA[Type5]: Originate AS-external-LSA instance");
1564 /* If old Link State ID is specified, refresh LSA with same ID. */
1567 /* Get Link State with unique ID. */
1570 id
= ospf_lsa_unique_id (ospf
, ospf
->lsdb
, OSPF_AS_EXTERNAL_LSA
, &ei
->p
);
1571 if (id
.s_addr
== 0xffffffff)
1573 /* Maybe Link State ID not available. */
1574 if (IS_DEBUG_OSPF (lsa
, LSA_GENERATE
))
1575 zlog_info ("LSA[Type5]: Link ID not available, can't originate");
1580 /* Create new stream for LSA. */
1581 s
= stream_new (OSPF_MAX_LSA_SIZE
);
1582 lsah
= (struct lsa_header
*) STREAM_DATA (s
);
1584 /* Set LSA common header fields. */
1585 lsa_header_set (s
, OSPF_OPTION_E
, OSPF_AS_EXTERNAL_LSA
,
1586 id
, ospf
->router_id
);
1588 /* Set AS-external-LSA body fields. */
1589 ospf_external_lsa_body_set (s
, ei
, ospf
);
1592 length
= stream_get_endp (s
);
1593 lsah
->length
= htons (length
);
1595 /* Now, create OSPF LSA instance. */
1596 new = ospf_lsa_new ();
1598 SET_FLAG (new->flags
, OSPF_LSA_SELF
|OSPF_LSA_APPROVED
);
1600 /* Copy LSA data to store, discard stream. */
1601 new->data
= ospf_lsa_data_new (length
);
1602 memcpy (new->data
, lsah
, length
);
1611 ospf_install_flood_nssa (struct ospf
*ospf
,
1612 struct ospf_lsa
*lsa
, struct external_info
*ei
)
1614 struct ospf_lsa
*new2
;
1615 struct as_external_lsa
*extlsa
;
1618 /* NSSA Originate or Refresh (If anyNSSA)
1620 LSA is self-originated. And just installed as Type-5.
1621 Additionally, install as Type-7 LSDB for every attached NSSA.
1623 P-Bit controls which ABR performs translation to outside world; If
1624 we are an ABR....do not set the P-bit, because we send the Type-5,
1625 not as the ABR Translator, but as the ASBR owner within the AS!
1627 If we are NOT ABR, Flood through NSSA as Type-7 w/P-bit set. The
1628 elected ABR Translator will see the P-bit, Translate, and re-flood.
1630 Later, ABR_TASK and P-bit will scan Type-7 LSDB and translate to
1631 Type-5's to non-NSSA Areas. (it will also attempt a re-install) */
1633 for (node
= listhead (ospf
->areas
); node
; nextnode (node
))
1635 struct ospf_area
*area
= getdata (node
);
1637 /* make lsa duplicate, lock=1 */
1638 new2
= ospf_lsa_dup (lsa
);
1640 new2
->data
->type
= OSPF_AS_NSSA_LSA
;
1642 /* set P-bit if not ABR */
1643 if (! IS_OSPF_ABR (ospf
))
1645 SET_FLAG(new2
->data
->options
, OSPF_OPTION_NP
);
1647 /* set non-zero FWD ADDR
1649 draft-ietf-ospf-nssa-update-09.txt
1651 if the network between the NSSA AS boundary router and the
1652 adjacent AS is advertised into OSPF as an internal OSPF route,
1653 the forwarding address should be the next op address as is cu
1654 currently done with type-5 LSAs. If the intervening network is
1655 not adversited into OSPF as an internal OSPF route and the
1656 type-7 LSA's P-bit is set a forwarding address should be
1657 selected from one of the router's active OSPF inteface addresses
1658 which belong to the NSSA. If no such addresses exist, then
1659 no type-7 LSA's with the P-bit set should originate from this
1662 /* kevinm: not updating lsa anymore, just new2 */
1663 extlsa
= (struct as_external_lsa
*)(new2
->data
);
1665 if (extlsa
->e
[0].fwd_addr
.s_addr
== 0)
1666 extlsa
->e
[0].fwd_addr
= ospf_get_nssa_ip(area
); /* this NSSA area in ifp */
1668 if (IS_DEBUG_OSPF_NSSA
)
1669 if (extlsa
->e
[0].fwd_addr
.s_addr
== 0)
1671 zlog_info ("LSA[Type-7]: Could not build FWD-ADDR");
1672 ospf_lsa_discard(new2
);
1676 /* Re-calculate checksum. */
1677 ospf_lsa_checksum (new2
->data
);
1679 /* install also as Type-7 */
1680 ospf_lsa_install (ospf
, NULL
, new2
); /* Remove Old, Lock New = 2 */
1682 /* will send each copy, lock=2+n */
1683 ospf_flood_through_as (ospf
, NULL
, new2
); /* all attached NSSA's, no AS/STUBs */
1686 #endif /* HAVE_NSSA */
1689 is_prefix_default (struct prefix_ipv4
*p
)
1691 struct prefix_ipv4 q
;
1694 q
.prefix
.s_addr
= 0;
1697 return prefix_same ((struct prefix
*) p
, (struct prefix
*) &q
);
1700 /* Originate an AS-external-LSA, install and flood. */
1702 ospf_external_lsa_originate (struct ospf
*ospf
, struct external_info
*ei
)
1704 struct ospf_lsa
*new;
1706 /* Added for NSSA project....
1708 External LSAs are originated in ASBRs as usual, but for NSSA systems.
1709 there is the global Type-5 LSDB and a Type-7 LSDB installed for
1710 every area. The Type-7's are flooded to every IR and every ABR; We
1711 install the Type-5 LSDB so that the normal "refresh" code operates
1712 as usual, and flag them as not used during ASE calculations. The
1713 Type-7 LSDB is used for calculations. Each Type-7 has a Forwarding
1714 Address of non-zero.
1716 If an ABR is the elected NSSA translator, following SPF and during
1717 the ABR task it will translate all the scanned Type-7's, with P-bit
1718 ON and not-self generated, and translate to Type-5's throughout the
1721 A difference in operation depends whether this ASBR is an ABR
1722 or not. If not an ABR, the P-bit is ON, to indicate that any
1723 elected NSSA-ABR can perform its translation.
1725 If an ABR, the P-bit is OFF; No ABR will perform translation and
1726 this ASBR will flood the Type-5 LSA as usual.
1728 For the case where this ASBR is not an ABR, the ASE calculations
1729 are based on the Type-5 LSDB; The Type-7 LSDB exists just to
1730 demonstrate to the user that there are LSA's that belong to any
1733 Finally, it just so happens that when the ABR is translating every
1734 Type-7 into Type-5, it installs it into the Type-5 LSDB as an
1735 approved Type-5 (translated from Type-7); at the end of translation
1736 if any Translated Type-5's remain unapproved, then they must be
1737 flushed from the AS.
1741 /* Check the AS-external-LSA should be originated. */
1742 if (!ospf_redistribute_check (ospf
, ei
, NULL
))
1745 /* Create new AS-external-LSA instance. */
1746 if ((new = ospf_external_lsa_new (ospf
, ei
, NULL
)) == NULL
)
1748 if (IS_DEBUG_OSPF_EVENT
)
1749 zlog_info ("LSA[Type5:%s]: Could not originate AS-external-LSA",
1750 inet_ntoa (ei
->p
.prefix
));
1754 /* Install newly created LSA into Type-5 LSDB, lock = 1. */
1755 ospf_lsa_install (ospf
, NULL
, new);
1757 /* Update LSA origination count. */
1758 ospf
->lsa_originate_count
++;
1760 /* Flooding new LSA. only to AS (non-NSSA/STUB) */
1761 ospf_flood_through_as (ospf
, NULL
, new);
1764 /* If there is any attached NSSA, do special handling */
1766 ospf_install_flood_nssa (ospf
, new, ei
); /* Install/Flood Type-7 to all NSSAs */
1767 #endif /* HAVE_NSSA */
1769 /* Debug logging. */
1770 if (IS_DEBUG_OSPF (lsa
, LSA_GENERATE
))
1772 zlog_info ("LSA[Type%d:%s]: Originate AS-external-LSA %p",
1773 new->data
->type
, inet_ntoa (new->data
->id
), new);
1774 ospf_lsa_header_dump (new->data
);
1780 /* Originate AS-external-LSA from external info with initial flag. */
1782 ospf_external_lsa_originate_timer (struct thread
*thread
)
1784 struct ospf
*ospf
= THREAD_ARG (thread
);
1785 struct route_node
*rn
;
1786 struct external_info
*ei
;
1787 struct route_table
*rt
;
1788 int type
= THREAD_VAL (thread
);
1790 ospf
->t_external_lsa
= NULL
;
1792 /* Originate As-external-LSA from all type of distribute source. */
1793 if ((rt
= EXTERNAL_INFO (type
)))
1794 for (rn
= route_top (rt
); rn
; rn
= route_next (rn
))
1795 if ((ei
= rn
->info
) != NULL
)
1796 if (!is_prefix_default ((struct prefix_ipv4
*)&ei
->p
))
1797 if (!ospf_external_lsa_originate (ospf
, ei
))
1798 zlog_warn ("LSA: AS-external-LSA was not originated.");
1803 struct external_info
*
1804 ospf_default_external_info (struct ospf
*ospf
)
1807 struct route_node
*rn
;
1808 struct prefix_ipv4 p
;
1811 p
.prefix
.s_addr
= 0;
1814 /* First, lookup redistributed default route. */
1815 for (type
= 0; type
<= ZEBRA_ROUTE_MAX
; type
++)
1816 if (EXTERNAL_INFO (type
) && type
!= ZEBRA_ROUTE_OSPF
)
1818 rn
= route_node_lookup (EXTERNAL_INFO (type
), (struct prefix
*) &p
);
1821 route_unlock_node (rn
);
1823 if (ospf_redistribute_check (ospf
, rn
->info
, NULL
))
1832 ospf_default_originate_timer (struct thread
*thread
)
1835 struct prefix_ipv4 p
;
1836 struct in_addr nexthop
;
1837 struct external_info
*ei
;
1840 ospf
= ospf_lookup ();
1842 /* Get originate flags. */
1843 origin
= THREAD_ARG (thread
);
1846 p
.prefix
.s_addr
= 0;
1849 if (*origin
== DEFAULT_ORIGINATE_ALWAYS
)
1851 /* If there is no default route via redistribute,
1852 then originate AS-external-LSA with nexthop 0 (self). */
1854 ospf_external_info_add (DEFAULT_ROUTE
, p
, 0, nexthop
);
1857 if ((ei
= ospf_default_external_info (ospf
)))
1858 ospf_external_lsa_originate (ospf
, ei
);
1864 /* Flush any NSSA LSAs for given prefix */
1866 ospf_nssa_lsa_flush (struct ospf
*ospf
, struct prefix_ipv4
*p
)
1868 struct listnode
*node
;
1869 struct ospf_lsa
*lsa
;
1870 struct ospf_area
*area
;
1874 for (node
= listhead (ospf
->areas
); node
; nextnode (node
))
1876 if (((area
= getdata (node
)) != NULL
)
1877 && (area
->external_routing
== OSPF_AREA_NSSA
))
1879 if (!(lsa
= ospf_lsa_lookup (area
, OSPF_AS_NSSA_LSA
, p
->prefix
,
1882 if (IS_DEBUG_OSPF (lsa
, LSA_FLOODING
))
1883 zlog_warn ("LSA: There is no such AS-NSSA-LSA %s/%d in LSDB",
1884 inet_ntoa (p
->prefix
), p
->prefixlen
);
1887 ospf_ls_retransmit_delete_nbr_as (ospf
, lsa
);
1888 if (!IS_LSA_MAXAGE (lsa
))
1890 ospf_refresher_unregister_lsa (ospf
, lsa
);
1891 ospf_lsa_flush_as (ospf
, lsa
);
1897 #endif /* HAVE_NSSA */
1899 /* Flush an AS-external-LSA from LSDB and routing domain. */
1901 ospf_external_lsa_flush (struct ospf
*ospf
,
1902 u_char type
, struct prefix_ipv4
*p
,
1903 unsigned int ifindex
, struct in_addr nexthop
)
1905 struct ospf_lsa
*lsa
;
1907 if (IS_DEBUG_OSPF (lsa
, LSA_FLOODING
))
1908 zlog_info ("LSA: Flushing AS-external-LSA %s/%d",
1909 inet_ntoa (p
->prefix
), p
->prefixlen
);
1911 /* First lookup LSA from LSDB. */
1912 if (!(lsa
= ospf_external_info_find_lsa (ospf
, p
)))
1914 if (IS_DEBUG_OSPF (lsa
, LSA_FLOODING
))
1915 zlog_warn ("LSA: There is no such AS-external-LSA %s/%d in LSDB",
1916 inet_ntoa (p
->prefix
), p
->prefixlen
);
1920 /* Sweep LSA from Link State Retransmit List. */
1921 ospf_ls_retransmit_delete_nbr_as (ospf
, lsa
);
1923 /* There must be no self-originated LSA in rtrs_external. */
1925 /* Remove External route from Zebra. */
1926 ospf_zebra_delete ((struct prefix_ipv4
*) p
, &nexthop
);
1929 if (!IS_LSA_MAXAGE (lsa
))
1931 /* Unregister LSA from Refresh queue. */
1932 ospf_refresher_unregister_lsa (ospf
, lsa
);
1934 /* Flush AS-external-LSA through AS. */
1935 ospf_lsa_flush_as (ospf
, lsa
);
1939 /* If there is NSSA area, flush Type-7 lsa's as well */
1940 ospf_nssa_lsa_flush (ospf
, p
);
1941 #endif /* HAVE_NSSA */
1943 if (IS_DEBUG_OSPF (lsa
, LSA_FLOODING
))
1944 zlog_info ("ospf_external_lsa_flush(): stop");
1948 ospf_external_lsa_refresh_default (struct ospf
*ospf
)
1950 struct prefix_ipv4 p
;
1951 struct external_info
*ei
;
1952 struct ospf_lsa
*lsa
;
1956 p
.prefix
.s_addr
= 0;
1958 ei
= ospf_default_external_info (ospf
);
1959 lsa
= ospf_external_info_find_lsa (ospf
, &p
);
1965 if (IS_DEBUG_OSPF_EVENT
)
1966 zlog_info ("LSA[Type5:0.0.0.0]: Refresh AS-external-LSA %p", lsa
);
1967 ospf_external_lsa_refresh (ospf
, lsa
, ei
, LSA_REFRESH_FORCE
);
1971 if (IS_DEBUG_OSPF_EVENT
)
1972 zlog_info ("LSA[Type5:0.0.0.0]: Originate AS-external-LSA");
1973 ospf_external_lsa_originate (ospf
, ei
);
1980 if (IS_DEBUG_OSPF_EVENT
)
1981 zlog_info ("LSA[Type5:0.0.0.0]: Flush AS-external-LSA");
1982 ospf_lsa_flush_as (ospf
, lsa
);
1988 ospf_external_lsa_refresh_type (struct ospf
*ospf
, u_char type
, int force
)
1990 struct route_node
*rn
;
1991 struct external_info
*ei
;
1993 if (type
!= DEFAULT_ROUTE
)
1994 if (EXTERNAL_INFO(type
))
1995 /* Refresh each redistributed AS-external-LSAs. */
1996 for (rn
= route_top (EXTERNAL_INFO (type
)); rn
; rn
= route_next (rn
))
1997 if ((ei
= rn
->info
))
1998 if (!is_prefix_default (&ei
->p
))
2000 struct ospf_lsa
*lsa
;
2002 if ((lsa
= ospf_external_info_find_lsa (ospf
, &ei
->p
)))
2003 ospf_external_lsa_refresh (ospf
, lsa
, ei
, force
);
2005 ospf_external_lsa_originate (ospf
, ei
);
2009 /* Refresh AS-external-LSA. */
2011 ospf_external_lsa_refresh (struct ospf
*ospf
, struct ospf_lsa
*lsa
,
2012 struct external_info
*ei
, int force
)
2014 struct ospf_lsa
*new;
2017 /* Check the AS-external-LSA should be originated. */
2018 if (!ospf_redistribute_check (ospf
, ei
, &changed
))
2020 ospf_external_lsa_flush (ospf
, ei
->type
, &ei
->p
,
2021 ei
->ifindex
, ei
->nexthop
);
2025 if (!changed
&& !force
)
2028 /* Delete LSA from neighbor retransmit-list. */
2029 ospf_ls_retransmit_delete_nbr_as (ospf
, lsa
);
2031 /* Unregister AS-external-LSA from refresh-list. */
2032 ospf_refresher_unregister_lsa (ospf
, lsa
);
2034 new = ospf_external_lsa_new (ospf
, ei
, &lsa
->data
->id
);
2038 if (IS_DEBUG_OSPF (lsa
, LSA_GENERATE
))
2039 zlog_warn ("LSA[Type%d:%s]: Could not be refreshed", lsa
->data
->type
,
2040 inet_ntoa (lsa
->data
->id
));
2044 new->data
->ls_seqnum
= lsa_seqnum_increment (lsa
);
2046 /* Record timestamp. */
2047 gettimeofday (&new->tv_orig
, NULL
);
2049 /* Re-calculate checksum. */
2050 ospf_lsa_checksum (new->data
);
2052 ospf_lsa_install (ospf
, NULL
, new); /* As type-5. */
2054 /* Flood LSA through AS. */
2055 ospf_flood_through_as (ospf
, NULL
, new);
2058 /* If any attached NSSA, install as Type-7, flood to all NSSA Areas */
2060 ospf_install_flood_nssa (ospf
, new, ei
); /* Install/Flood per new rules */
2061 #endif /* HAVE_NSSA */
2063 /* Register slef-originated LSA to refresh queue. */
2064 ospf_refresher_register_lsa (ospf
, new);
2066 /* Debug logging. */
2067 if (IS_DEBUG_OSPF (lsa
, LSA_GENERATE
))
2069 zlog_info ("LSA[Type%d:%s]: AS-external-LSA refresh",
2070 new->data
->type
, inet_ntoa (new->data
->id
));
2071 ospf_lsa_header_dump (new->data
);
2078 /* LSA installation functions. */
2080 /* Install router-LSA to an area. */
2082 ospf_router_lsa_install (struct ospf
*ospf
,
2083 struct ospf_lsa
*new, int rt_recalc
)
2085 struct ospf_area
*area
= new->area
;
2087 /* RFC 2328 Section 13.2 Router-LSAs and network-LSAs
2088 The entire routing table must be recalculated, starting with
2089 the shortest path calculations for each area (not just the
2090 area whose link-state database has changed).
2093 ospf_spf_calculate_schedule (ospf
);
2095 if (IS_LSA_SELF (new))
2097 /* Set router-LSA refresh timer. */
2098 OSPF_TIMER_OFF (area
->t_router_lsa_self
);
2099 OSPF_AREA_TIMER_ON (area
->t_router_lsa_self
,
2100 ospf_router_lsa_timer
, OSPF_LS_REFRESH_TIME
);
2102 /* Set self-originated router-LSA. */
2103 ospf_lsa_unlock (area
->router_lsa_self
);
2104 area
->router_lsa_self
= ospf_lsa_lock (new);
2106 if (IS_DEBUG_OSPF (lsa
, LSA_INSTALL
))
2107 zlog_info("LSA[Type%d]: ID %s is self-originated",
2108 new->data
->type
, inet_ntoa (new->data
->id
));
2114 #define OSPF_INTERFACE_TIMER_ON(T,F,V) \
2116 (T) = thread_add_timer (master, (F), oi, (V))
2118 /* Install network-LSA to an area. */
2120 ospf_network_lsa_install (struct ospf
*ospf
,
2121 struct ospf_interface
*oi
,
2122 struct ospf_lsa
*new,
2126 /* RFC 2328 Section 13.2 Router-LSAs and network-LSAs
2127 The entire routing table must be recalculated, starting with
2128 the shortest path calculations for each area (not just the
2129 area whose link-state database has changed).
2132 ospf_spf_calculate_schedule (ospf
);
2134 /* We supposed that when LSA is originated by us, we pass the int
2135 for which it was originated. If LSA was received by flooding,
2136 the RECEIVED flag is set, so we do not link the LSA to the int. */
2137 if (IS_LSA_SELF (new) && !CHECK_FLAG (new->flags
, OSPF_LSA_RECEIVED
))
2139 /* Set LSRefresh timer. */
2140 OSPF_TIMER_OFF (oi
->t_network_lsa_self
);
2142 OSPF_INTERFACE_TIMER_ON (oi
->t_network_lsa_self
,
2143 ospf_network_lsa_refresh_timer
,
2144 OSPF_LS_REFRESH_TIME
);
2146 ospf_lsa_unlock (oi
->network_lsa_self
);
2147 oi
->network_lsa_self
= ospf_lsa_lock (new);
2153 /* Install summary-LSA to an area. */
2155 ospf_summary_lsa_install (struct ospf
*ospf
, struct ospf_lsa
*new,
2158 if (rt_recalc
&& !IS_LSA_SELF (new))
2160 /* RFC 2328 Section 13.2 Summary-LSAs
2161 The best route to the destination described by the summary-
2162 LSA must be recalculated (see Section 16.5). If this
2163 destination is an AS boundary router, it may also be
2164 necessary to re-examine all the AS-external-LSAs.
2168 /* This doesn't exist yet... */
2169 ospf_summary_incremental_update(new); */
2171 ospf_spf_calculate_schedule (ospf
);
2174 if (IS_DEBUG_OSPF (lsa
, LSA_INSTALL
))
2175 zlog_info ("ospf_summary_lsa_install(): SPF scheduled");
2178 if (IS_LSA_SELF (new))
2179 ospf_refresher_register_lsa (ospf
, new);
2184 /* Install ASBR-summary-LSA to an area. */
2186 ospf_summary_asbr_lsa_install (struct ospf
*ospf
, struct ospf_lsa
*new,
2189 if (rt_recalc
&& !IS_LSA_SELF (new))
2191 /* RFC 2328 Section 13.2 Summary-LSAs
2192 The best route to the destination described by the summary-
2193 LSA must be recalculated (see Section 16.5). If this
2194 destination is an AS boundary router, it may also be
2195 necessary to re-examine all the AS-external-LSAs.
2198 /* These don't exist yet... */
2199 ospf_summary_incremental_update(new);
2200 /* Isn't this done by the above call?
2201 - RFC 2328 Section 16.5 implies it should be */
2202 /* ospf_ase_calculate_schedule(); */
2204 ospf_spf_calculate_schedule (ospf
);
2208 /* register LSA to refresh-list. */
2209 if (IS_LSA_SELF (new))
2210 ospf_refresher_register_lsa (ospf
, new);
2215 /* Install AS-external-LSA. */
2217 ospf_external_lsa_install (struct ospf
*ospf
, struct ospf_lsa
*new,
2220 ospf_ase_register_external_lsa (new, ospf
);
2221 /* If LSA is not self-originated, calculate an external route. */
2224 /* RFC 2328 Section 13.2 AS-external-LSAs
2225 The best route to the destination described by the AS-
2226 external-LSA must be recalculated (see Section 16.6).
2229 if (!IS_LSA_SELF (new))
2230 ospf_ase_incremental_update (ospf
, new);
2233 /* Register self-originated LSA to refresh queue. */
2234 if (IS_LSA_SELF (new))
2235 ospf_refresher_register_lsa (ospf
, new);
2241 ospf_discard_from_db (struct ospf
*ospf
,
2242 struct ospf_lsdb
*lsdb
, struct ospf_lsa
*lsa
)
2244 struct ospf_lsa
*old
;
2246 old
= ospf_lsdb_lookup (lsdb
, lsa
);
2251 if (old
->refresh_list
>= 0)
2252 ospf_refresher_unregister_lsa (ospf
, old
);
2254 switch (old
->data
->type
)
2256 case OSPF_AS_EXTERNAL_LSA
:
2257 #ifdef HAVE_OPAQUE_LSA
2258 case OSPF_OPAQUE_AS_LSA
:
2259 #endif /* HAVE_OPAQUE_LSA */
2260 ospf_ls_retransmit_delete_nbr_as (ospf
, old
);
2261 ospf_ase_unregister_external_lsa (old
, ospf
);
2264 ospf_ls_retransmit_delete_nbr_area (old
->area
, old
);
2268 ospf_lsa_maxage_delete (ospf
, old
);
2269 ospf_lsa_discard (old
);
2273 ospf_lsa_install (struct ospf
*ospf
, struct ospf_interface
*oi
,
2274 struct ospf_lsa
*lsa
)
2276 struct ospf_lsa
*new = NULL
;
2277 struct ospf_lsa
*old
= NULL
;
2278 struct ospf_lsdb
*lsdb
= NULL
;
2282 switch (lsa
->data
->type
)
2286 case OSPF_AS_NSSA_LSA
:
2288 lsdb
= lsa
->area
->lsdb
;
2292 #endif /* HAVE_NSSA */
2293 case OSPF_AS_EXTERNAL_LSA
:
2294 #ifdef HAVE_OPAQUE_LSA
2295 case OSPF_OPAQUE_AS_LSA
:
2296 #endif /* HAVE_OPAQUE_LSA */
2300 lsdb
= lsa
->area
->lsdb
;
2306 /* RFC 2328 13.2. Installing LSAs in the database
2308 Installing a new LSA in the database, either as the result of
2309 flooding or a newly self-originated LSA, may cause the OSPF
2310 routing table structure to be recalculated. The contents of the
2311 new LSA should be compared to the old instance, if present. If
2312 there is no difference, there is no need to recalculate the
2313 routing table. When comparing an LSA to its previous instance,
2314 the following are all considered to be differences in contents:
2316 o The LSA's Options field has changed.
2318 o One of the LSA instances has LS age set to MaxAge, and
2321 o The length field in the LSA header has changed.
2323 o The body of the LSA (i.e., anything outside the 20-byte
2324 LSA header) has changed. Note that this excludes changes
2325 in LS Sequence Number and LS Checksum.
2328 /* Look up old LSA and determine if any SPF calculation or incremental
2330 old
= ospf_lsdb_lookup (lsdb
, lsa
);
2332 /* Do comparision and record if recalc needed. */
2334 if ( old
== NULL
|| ospf_lsa_different(old
, lsa
))
2337 /* discard old LSA from LSDB */
2339 ospf_discard_from_db (ospf
, lsdb
, lsa
);
2341 /* Insert LSA to LSDB. */
2342 ospf_lsdb_add (lsdb
, lsa
);
2345 /* Calculate Checksum if self-originated?. */
2346 if (IS_LSA_SELF (lsa
))
2347 ospf_lsa_checksum (lsa
->data
);
2349 /* Do LSA specific installation process. */
2350 switch (lsa
->data
->type
)
2352 case OSPF_ROUTER_LSA
:
2353 new = ospf_router_lsa_install (ospf
, lsa
, rt_recalc
);
2355 case OSPF_NETWORK_LSA
:
2357 new = ospf_network_lsa_install (ospf
, oi
, lsa
, rt_recalc
);
2359 case OSPF_SUMMARY_LSA
:
2360 new = ospf_summary_lsa_install (ospf
, lsa
, rt_recalc
);
2362 case OSPF_ASBR_SUMMARY_LSA
:
2363 new = ospf_summary_asbr_lsa_install (ospf
, lsa
, rt_recalc
);
2365 case OSPF_AS_EXTERNAL_LSA
:
2366 new = ospf_external_lsa_install (ospf
, lsa
, rt_recalc
);
2368 #ifdef HAVE_OPAQUE_LSA
2369 case OSPF_OPAQUE_LINK_LSA
:
2370 if (IS_LSA_SELF (lsa
))
2371 lsa
->oi
= oi
; /* Specify outgoing ospf-interface for this LSA. */
2373 ; /* Incoming "oi" for this LSA has set at LSUpd reception. */
2375 case OSPF_OPAQUE_AREA_LSA
:
2376 case OSPF_OPAQUE_AS_LSA
:
2377 new = ospf_opaque_lsa_install (lsa
, rt_recalc
);
2379 #endif /* HAVE_OPAQUE_LSA */
2380 default: /* NSSA, or type-6,8,9....nothing special */
2382 new = ospf_external_lsa_install (ospf
, lsa
, rt_recalc
);
2383 #endif /* HAVE_NSSA */
2388 return new; /* Installation failed, cannot proceed further -- endo. */
2391 if (IS_DEBUG_OSPF (lsa
, LSA_INSTALL
))
2393 char area_str
[INET_ADDRSTRLEN
];
2395 switch (lsa
->data
->type
)
2397 case OSPF_AS_EXTERNAL_LSA
:
2398 #ifdef HAVE_OPAQUE_LSA
2399 case OSPF_OPAQUE_AS_LSA
:
2400 #endif /* HAVE_OPAQUE_LSA */
2402 case OSPF_AS_NSSA_LSA
:
2403 #endif /* HAVE_NSSA */
2404 zlog_info ("LSA[%s]: Install %s",
2406 LOOKUP (ospf_lsa_type_msg
, new->data
->type
));
2409 strcpy (area_str
, inet_ntoa (new->area
->area_id
));
2410 zlog_info ("LSA[%s]: Install %s to Area %s",
2412 LOOKUP (ospf_lsa_type_msg
, new->data
->type
), area_str
);
2417 /* If received LSA' ls_age is MaxAge, set LSA on MaxAge LSA list. */
2418 if (IS_LSA_MAXAGE (new) && !IS_LSA_SELF (new))
2420 if (IS_DEBUG_OSPF (lsa
, LSA_FLOODING
))
2421 zlog_info ("LSA[Type%d:%s]: Install LSA, MaxAge",
2422 new->data
->type
, inet_ntoa (new->data
->id
));
2423 ospf_lsa_maxage (ospf
, lsa
);
2431 ospf_check_nbr_status (struct ospf
*ospf
)
2435 for (node
= listhead (ospf
->oiflist
); node
; node
= nextnode (node
))
2437 struct ospf_interface
*oi
= getdata (node
);
2438 struct route_node
*rn
;
2439 struct ospf_neighbor
*nbr
;
2441 if (ospf_if_is_enable (oi
))
2442 for (rn
= route_top (oi
->nbrs
); rn
; rn
= route_next (rn
))
2443 if ((nbr
= rn
->info
) != NULL
)
2444 if (nbr
->state
== NSM_Exchange
|| nbr
->state
== NSM_Loading
)
2446 route_unlock_node (rn
);
2455 #ifdef ORIGINAL_CODING
2456 /* This function flood the maxaged LSA to DR. */
2458 ospf_maxage_flood (struct ospf_lsa
*lsa
)
2460 switch (lsa
->data
->type
)
2462 case OSPF_ROUTER_LSA
:
2463 case OSPF_NETWORK_LSA
:
2464 case OSPF_SUMMARY_LSA
:
2465 case OSPF_ASBR_SUMMARY_LSA
:
2467 case OSPF_AS_NSSA_LSA
:
2468 #endif /* HAVE_NSSA */
2469 #ifdef HAVE_OPAQUE_LSA
2470 case OSPF_OPAQUE_LINK_LSA
:
2471 case OSPF_OPAQUE_AREA_LSA
:
2472 #endif /* HAVE_OPAQUE_LSA */
2473 ospf_flood_through_area (lsa
->area
, NULL
, lsa
);
2475 case OSPF_AS_EXTERNAL_LSA
:
2476 #ifdef HAVE_OPAQUE_LSA
2477 case OSPF_OPAQUE_AS_LSA
:
2478 #endif /* HAVE_OPAQUE_LSA */
2479 ospf_flood_through_as (NULL
, lsa
);
2485 #endif /* ORIGINAL_CODING */
2488 ospf_maxage_lsa_remover (struct thread
*thread
)
2490 struct ospf
*ospf
= THREAD_ARG (thread
);
2495 ospf
->t_maxage
= NULL
;
2497 if (IS_DEBUG_OSPF (lsa
, LSA_FLOODING
))
2498 zlog_info ("LSA[MaxAge]: remover Start");
2500 reschedule
= !ospf_check_nbr_status (ospf
);
2503 for (node
= listhead (ospf
->maxage_lsa
); node
; node
= next
)
2505 struct ospf_lsa
*lsa
= getdata (node
);
2508 if (lsa
->retransmit_counter
> 0)
2514 /* Remove LSA from the LSDB */
2515 if (CHECK_FLAG (lsa
->flags
, OSPF_LSA_SELF
))
2516 if (IS_DEBUG_OSPF (lsa
, LSA_FLOODING
))
2517 zlog_info ("LSA[Type%d:%s]: This LSA is self-originated: ",
2518 lsa
->data
->type
, inet_ntoa (lsa
->data
->id
));
2520 if (IS_DEBUG_OSPF (lsa
, LSA_FLOODING
))
2521 zlog_info ("LSA[Type%d:%s]: MaxAge LSA removed from list",
2522 lsa
->data
->type
, inet_ntoa (lsa
->data
->id
));
2524 /* Flood max age LSA. */
2525 #ifdef ORIGINAL_CODING
2526 ospf_maxage_flood (lsa
);
2527 #else /* ORIGINAL_CODING */
2528 ospf_flood_through (ospf
, NULL
, lsa
);
2529 #endif /* ORIGINAL_CODING */
2531 /* Remove from lsdb. */
2532 ospf_discard_from_db (ospf
, lsa
->lsdb
, lsa
);
2533 ospf_lsdb_delete (lsa
->lsdb
, lsa
);
2536 /* A MaxAge LSA must be removed immediately from the router's link
2537 state database as soon as both a) it is no longer contained on any
2538 neighbor Link state retransmission lists and b) none of the router's
2539 neighbors are in states Exchange or Loading. */
2541 OSPF_TIMER_ON (ospf
->t_maxage
, ospf_maxage_lsa_remover
, 2);
2547 ospf_lsa_maxage_exist (struct ospf
*ospf
, struct ospf_lsa
*new)
2551 for (node
= listhead (ospf
->maxage_lsa
); node
; nextnode (node
))
2552 if (((struct ospf_lsa
*) node
->data
) == new)
2559 ospf_lsa_maxage_delete (struct ospf
*ospf
, struct ospf_lsa
*lsa
)
2563 if ((n
= listnode_lookup (ospf
->maxage_lsa
, lsa
)))
2565 list_delete_node (ospf
->maxage_lsa
, n
);
2566 ospf_lsa_unlock (lsa
);
2571 ospf_lsa_maxage (struct ospf
*ospf
, struct ospf_lsa
*lsa
)
2573 /* When we saw a MaxAge LSA flooded to us, we put it on the list
2574 and schedule the MaxAge LSA remover. */
2575 if (ospf_lsa_maxage_exist (ospf
, lsa
))
2577 if (IS_DEBUG_OSPF (lsa
, LSA_FLOODING
))
2578 zlog_info ("LSA[Type%d:%s]: %p already exists on MaxAge LSA list",
2579 lsa
->data
->type
, inet_ntoa (lsa
->data
->id
), lsa
);
2583 listnode_add (ospf
->maxage_lsa
, ospf_lsa_lock (lsa
));
2585 if (IS_DEBUG_OSPF (lsa
, LSA_FLOODING
))
2586 zlog_info ("LSA[%s]: MaxAge LSA remover scheduled.", dump_lsa_key (lsa
));
2588 OSPF_TIMER_ON (ospf
->t_maxage
, ospf_maxage_lsa_remover
, 2);
2592 ospf_lsa_maxage_walker_remover (struct ospf
*ospf
, struct ospf_lsa
*lsa
)
2595 /* Stay away from any Local Translated Type-7 LSAs */
2596 if (CHECK_FLAG (lsa
->flags
, OSPF_LSA_LOCAL_XLT
))
2598 #endif /* HAVE_NSSA */
2600 if (IS_LSA_MAXAGE (lsa
))
2601 /* Self-originated LSAs should NOT time-out instead,
2602 they're flushed and submitted to the max_age list explicitly. */
2603 if (!ospf_lsa_is_self_originated (ospf
, lsa
))
2605 if (IS_DEBUG_OSPF (lsa
, LSA_FLOODING
))
2606 zlog_info("LSA[%s]: is MaxAge", dump_lsa_key (lsa
));
2608 switch (lsa
->data
->type
)
2610 #ifdef HAVE_OPAQUE_LSA
2611 case OSPF_OPAQUE_LINK_LSA
:
2612 case OSPF_OPAQUE_AREA_LSA
:
2613 case OSPF_OPAQUE_AS_LSA
:
2615 * As a general rule, whenever network topology has changed
2616 * (due to an LSA removal in this case), routing recalculation
2617 * should be triggered. However, this is not true for opaque
2618 * LSAs. Even if an opaque LSA instance is going to be removed
2619 * from the routing domain, it does not mean a change in network
2620 * topology, and thus, routing recalculation is not needed here.
2623 #endif /* HAVE_OPAQUE_LSA */
2624 case OSPF_AS_EXTERNAL_LSA
:
2626 case OSPF_AS_NSSA_LSA
:
2627 #endif /* HAVE_NSSA */
2628 ospf_ase_incremental_update (ospf
, lsa
);
2631 ospf_spf_calculate_schedule (ospf
);
2634 ospf_lsa_maxage (ospf
, lsa
);
2640 /* Periodical check of MaxAge LSA. */
2642 ospf_lsa_maxage_walker (struct thread
*thread
)
2644 struct ospf
*ospf
= THREAD_ARG (thread
);
2645 struct route_node
*rn
;
2646 struct ospf_lsa
*lsa
;
2649 ospf
->t_maxage_walker
= NULL
;
2651 for (node
= listhead (ospf
->areas
); node
; nextnode (node
))
2653 struct ospf_area
*area
= node
->data
;
2655 LSDB_LOOP (ROUTER_LSDB (area
), rn
, lsa
)
2656 ospf_lsa_maxage_walker_remover (ospf
, lsa
);
2657 LSDB_LOOP (NETWORK_LSDB (area
), rn
, lsa
)
2658 ospf_lsa_maxage_walker_remover (ospf
, lsa
);
2659 LSDB_LOOP (SUMMARY_LSDB (area
), rn
, lsa
)
2660 ospf_lsa_maxage_walker_remover (ospf
, lsa
);
2661 LSDB_LOOP (ASBR_SUMMARY_LSDB (area
), rn
, lsa
)
2662 ospf_lsa_maxage_walker_remover (ospf
, lsa
);
2663 #ifdef HAVE_OPAQUE_LSA
2664 LSDB_LOOP (OPAQUE_AREA_LSDB (area
), rn
, lsa
)
2665 ospf_lsa_maxage_walker_remover (ospf
, lsa
);
2666 LSDB_LOOP (OPAQUE_LINK_LSDB (area
), rn
, lsa
)
2667 ospf_lsa_maxage_walker_remover (ospf
, lsa
);
2668 #endif /* HAVE_OPAQUE_LSA */
2671 /* for AS-eternal-LSAs. */
2674 LSDB_LOOP (EXTERNAL_LSDB (ospf
), rn
, lsa
)
2675 ospf_lsa_maxage_walker_remover (ospf
, lsa
);
2676 #ifdef HAVE_OPAQUE_LSA
2677 LSDB_LOOP (OPAQUE_AS_LSDB (ospf
), rn
, lsa
)
2678 ospf_lsa_maxage_walker_remover (ospf
, lsa
);
2679 #endif /* HAVE_OPAQUE_LSA */
2682 OSPF_TIMER_ON (ospf
->t_maxage_walker
, ospf_lsa_maxage_walker
,
2683 OSPF_LSA_MAXAGE_CHECK_INTERVAL
);
2688 ospf_lsa_lookup_by_prefix (struct ospf_lsdb
*lsdb
, u_char type
,
2689 struct prefix_ipv4
*p
, struct in_addr router_id
)
2691 struct ospf_lsa
*lsa
;
2692 struct in_addr mask
, id
;
2693 struct lsa_header_mask
2695 struct lsa_header header
;
2696 struct in_addr mask
;
2699 lsa
= ospf_lsdb_lookup_by_id (lsdb
, type
, p
->prefix
, router_id
);
2703 masklen2ip (p
->prefixlen
, &mask
);
2705 hmask
= (struct lsa_header_mask
*) lsa
->data
;
2707 if (mask
.s_addr
!= hmask
->mask
.s_addr
)
2709 id
.s_addr
= p
->prefix
.s_addr
| (~mask
.s_addr
);
2710 lsa
= ospf_lsdb_lookup_by_id (lsdb
, type
, id
, router_id
);
2719 ospf_lsa_lookup (struct ospf_area
*area
, u_int32_t type
,
2720 struct in_addr id
, struct in_addr adv_router
)
2722 struct ospf
*ospf
= ospf_lookup();
2727 case OSPF_ROUTER_LSA
:
2728 case OSPF_NETWORK_LSA
:
2729 case OSPF_SUMMARY_LSA
:
2730 case OSPF_ASBR_SUMMARY_LSA
:
2732 case OSPF_AS_NSSA_LSA
:
2733 #endif /* HAVE_NSSA */
2734 #ifdef HAVE_OPAQUE_LSA
2735 case OSPF_OPAQUE_LINK_LSA
:
2736 case OSPF_OPAQUE_AREA_LSA
:
2737 #endif /* HAVE_OPAQUE_LSA */
2738 return ospf_lsdb_lookup_by_id (area
->lsdb
, type
, id
, adv_router
);
2740 case OSPF_AS_EXTERNAL_LSA
:
2741 #ifdef HAVE_OPAQUE_LSA
2742 case OSPF_OPAQUE_AS_LSA
:
2743 #endif /* HAVE_OPAQUE_LSA */
2744 return ospf_lsdb_lookup_by_id (ospf
->lsdb
, type
, id
, adv_router
);
2754 ospf_lsa_lookup_by_id (struct ospf_area
*area
, u_int32_t type
,
2757 struct ospf_lsa
*lsa
;
2758 struct route_node
*rn
;
2762 case OSPF_ROUTER_LSA
:
2763 return ospf_lsdb_lookup_by_id (area
->lsdb
, type
, id
, id
);
2765 case OSPF_NETWORK_LSA
:
2766 for (rn
= route_top (NETWORK_LSDB (area
)); rn
; rn
= route_next (rn
))
2767 if ((lsa
= rn
->info
))
2768 if (IPV4_ADDR_SAME (&lsa
->data
->id
, &id
))
2770 route_unlock_node (rn
);
2774 case OSPF_SUMMARY_LSA
:
2775 case OSPF_ASBR_SUMMARY_LSA
:
2776 /* Currently not used. */
2778 return ospf_lsdb_lookup_by_id (area
->lsdb
, type
, id
, id
);
2780 case OSPF_AS_EXTERNAL_LSA
:
2781 #ifdef HAVE_OPAQUE_LSA
2782 case OSPF_OPAQUE_LINK_LSA
:
2783 case OSPF_OPAQUE_AREA_LSA
:
2784 case OSPF_OPAQUE_AS_LSA
:
2785 /* Currently not used. */
2787 #endif /* HAVE_OPAQUE_LSA */
2796 ospf_lsa_lookup_by_header (struct ospf_area
*area
, struct lsa_header
*lsah
)
2798 struct ospf_lsa
*match
;
2800 #ifdef HAVE_OPAQUE_LSA
2802 * Strictly speaking, the LSA-ID field for Opaque-LSAs (type-9/10/11)
2803 * is redefined to have two subfields; opaque-type and opaque-id.
2804 * However, it is harmless to treat the two sub fields together, as if
2805 * they two were forming a unique LSA-ID.
2807 #endif /* HAVE_OPAQUE_LSA */
2809 match
= ospf_lsa_lookup (area
, lsah
->type
, lsah
->id
, lsah
->adv_router
);
2812 if (IS_DEBUG_OSPF (lsa
, LSA
) == OSPF_DEBUG_LSA
)
2813 zlog_info ("LSA[Type%d:%s]: Lookup by header, NO MATCH",
2814 lsah
->type
, inet_ntoa (lsah
->id
));
2819 /* return +n, l1 is more recent.
2820 return -n, l2 is more recent.
2821 return 0, l1 and l2 is identical. */
2823 ospf_lsa_more_recent (struct ospf_lsa
*l1
, struct ospf_lsa
*l2
)
2828 if (l1
== NULL
&& l2
== NULL
)
2835 /* compare LS sequence number. */
2836 x
= (int) ntohl (l1
->data
->ls_seqnum
);
2837 y
= (int) ntohl (l2
->data
->ls_seqnum
);
2843 /* compare LS checksum. */
2844 r
= ntohs (l1
->data
->checksum
) - ntohs (l2
->data
->checksum
);
2848 /* compare LS age. */
2849 if (IS_LSA_MAXAGE (l1
) && !IS_LSA_MAXAGE (l2
))
2851 else if (!IS_LSA_MAXAGE (l1
) && IS_LSA_MAXAGE (l2
))
2854 /* compare LS age with MaxAgeDiff. */
2855 if (LS_AGE (l1
) - LS_AGE (l2
) > OSPF_LSA_MAXAGE_DIFF
)
2857 else if (LS_AGE (l2
) - LS_AGE (l1
) > OSPF_LSA_MAXAGE_DIFF
)
2860 /* LSAs are identical. */
2864 /* If two LSAs are different, return 1, otherwise return 0. */
2866 ospf_lsa_different (struct ospf_lsa
*l1
, struct ospf_lsa
*l2
)
2874 if (l1
->data
->options
!= l2
->data
->options
)
2877 if (IS_LSA_MAXAGE (l1
) && !IS_LSA_MAXAGE (l2
))
2880 if (IS_LSA_MAXAGE (l2
) && !IS_LSA_MAXAGE (l1
))
2883 if (l1
->data
->length
!= l2
->data
->length
)
2886 if (l1
->data
->length
== 0)
2889 assert ( ntohs(l1
->data
->length
) > OSPF_LSA_HEADER_SIZE
);
2891 p1
= (char *) l1
->data
;
2892 p2
= (char *) l2
->data
;
2894 if (memcmp (p1
+ OSPF_LSA_HEADER_SIZE
, p2
+ OSPF_LSA_HEADER_SIZE
,
2895 ntohs( l1
->data
->length
) - OSPF_LSA_HEADER_SIZE
) != 0)
2901 #ifdef ORIGINAL_CODING
2903 ospf_lsa_flush_self_originated (struct ospf_neighbor
*nbr
,
2904 struct ospf_lsa
*self
,
2905 struct ospf_lsa
*new)
2909 /* Adjust LS Sequence Number. */
2910 seqnum
= ntohl (new->data
->ls_seqnum
) + 1;
2911 self
->data
->ls_seqnum
= htonl (seqnum
);
2913 /* Recalculate LSA checksum. */
2914 ospf_lsa_checksum (self
->data
);
2916 /* Reflooding LSA. */
2917 /* RFC2328 Section 13.3
2918 On non-broadcast networks, separate Link State Update
2919 packets must be sent, as unicasts, to each adjacent neighbor
2920 (i.e., those in state Exchange or greater). The destination
2921 IP addresses for these packets are the neighbors' IP
2923 if (nbr
->oi
->type
== OSPF_IFTYPE_NBMA
)
2925 struct route_node
*rn
;
2926 struct ospf_neighbor
*onbr
;
2928 for (rn
= route_top (nbr
->oi
->nbrs
); rn
; rn
= route_next (rn
))
2929 if ((onbr
= rn
->info
) != NULL
)
2930 if (onbr
!= nbr
->oi
->nbr_self
&& onbr
->status
>= NSM_Exchange
)
2931 ospf_ls_upd_send_lsa (onbr
, self
, OSPF_SEND_PACKET_DIRECT
);
2934 ospf_ls_upd_send_lsa (nbr
, self
, OSPF_SEND_PACKET_INDIRECT
);
2936 if (IS_DEBUG_OSPF (lsa
, LSA_GENERATE
))
2937 zlog_info ("LSA[Type%d:%s]: Flush self-originated LSA",
2938 self
->data
->type
, inet_ntoa (self
->data
->id
));
2940 #else /* ORIGINAL_CODING */
2942 ospf_lsa_flush_schedule (struct ospf
*ospf
, struct ospf_lsa
*lsa
)
2944 if (lsa
== NULL
|| !IS_LSA_SELF (lsa
))
2947 if (IS_DEBUG_OSPF_EVENT
)
2948 zlog_info ("LSA[Type%d:%s]: Schedule self-originated LSA to FLUSH", lsa
->data
->type
, inet_ntoa (lsa
->data
->id
));
2950 /* Force given lsa's age to MaxAge. */
2951 lsa
->data
->ls_age
= htons (OSPF_LSA_MAXAGE
);
2953 switch (lsa
->data
->type
)
2955 #ifdef HAVE_OPAQUE_LSA
2956 case OSPF_OPAQUE_LINK_LSA
:
2957 case OSPF_OPAQUE_AREA_LSA
:
2958 case OSPF_OPAQUE_AS_LSA
:
2959 ospf_opaque_lsa_refresh (lsa
);
2961 #endif /* HAVE_OPAQUE_LSA */
2963 ospf_lsa_maxage (ospf
, lsa
);
2971 ospf_flush_self_originated_lsas_now (struct ospf
*ospf
)
2974 struct ospf_area
*area
;
2975 struct ospf_interface
*oi
;
2976 struct ospf_lsa
*lsa
;
2977 struct route_node
*rn
;
2978 int need_to_flush_ase
= 0;
2980 for (n1
= listhead (ospf
->areas
); n1
; nextnode (n1
))
2982 if ((area
= getdata (n1
)) == NULL
)
2985 if ((lsa
= area
->router_lsa_self
) != NULL
)
2987 if (IS_DEBUG_OSPF_EVENT
)
2988 zlog_info ("LSA[Type%d:%s]: Schedule self-originated LSA to FLUSH", lsa
->data
->type
, inet_ntoa (lsa
->data
->id
));
2990 ospf_lsa_flush_area (lsa
, area
);
2991 ospf_lsa_unlock (area
->router_lsa_self
);
2992 area
->router_lsa_self
= NULL
;
2993 OSPF_TIMER_OFF (area
->t_router_lsa_self
);
2996 for (n2
= listhead (area
->oiflist
); n2
; nextnode (n2
))
2998 if ((oi
= getdata (n2
)) == NULL
)
3001 if ((lsa
= oi
->network_lsa_self
) != NULL
3002 && oi
->state
== ISM_DR
3003 && oi
->full_nbrs
> 0)
3005 if (IS_DEBUG_OSPF_EVENT
)
3006 zlog_info ("LSA[Type%d:%s]: Schedule self-originated LSA to FLUSH", lsa
->data
->type
, inet_ntoa (lsa
->data
->id
));
3008 ospf_lsa_flush_area (oi
->network_lsa_self
, area
);
3009 ospf_lsa_unlock (oi
->network_lsa_self
);
3010 oi
->network_lsa_self
= NULL
;
3011 OSPF_TIMER_OFF (oi
->t_network_lsa_self
);
3014 if (oi
->type
!= OSPF_IFTYPE_VIRTUALLINK
3015 && area
->external_routing
== OSPF_AREA_DEFAULT
)
3016 need_to_flush_ase
= 1;
3019 LSDB_LOOP (SUMMARY_LSDB (area
), rn
, lsa
)
3020 ospf_lsa_flush_schedule (ospf
, lsa
);
3021 LSDB_LOOP (ASBR_SUMMARY_LSDB (area
), rn
, lsa
)
3022 ospf_lsa_flush_schedule (ospf
, lsa
);
3023 #ifdef HAVE_OPAQUE_LSA
3024 LSDB_LOOP (OPAQUE_LINK_LSDB (area
), rn
, lsa
)
3025 ospf_lsa_flush_schedule (ospf
, lsa
);
3026 LSDB_LOOP (OPAQUE_AREA_LSDB (area
), rn
, lsa
)
3027 ospf_lsa_flush_schedule (ospf
, lsa
);
3028 #endif /* HAVE_OPAQUE_LSA */
3031 if (need_to_flush_ase
)
3033 LSDB_LOOP (EXTERNAL_LSDB (ospf
), rn
, lsa
)
3034 ospf_lsa_flush_schedule (ospf
, lsa
);
3035 #ifdef HAVE_OPAQUE_LSA
3036 LSDB_LOOP (OPAQUE_AS_LSDB (ospf
), rn
, lsa
)
3037 ospf_lsa_flush_schedule (ospf
, lsa
);
3038 #endif /* HAVE_OPAQUE_LSA */
3042 * Make sure that the MaxAge LSA remover is executed immediately,
3043 * without conflicting to other threads.
3045 if (ospf
->t_maxage
!= NULL
)
3047 OSPF_TIMER_OFF (ospf
->t_maxage
);
3048 thread_execute (master
, ospf_maxage_lsa_remover
, ospf
, 0);
3053 #endif /* ORIGINAL_CODING */
3055 /* If there is self-originated LSA, then return 1, otherwise return 0. */
3056 /* An interface-independent version of ospf_lsa_is_self_originated */
3058 ospf_lsa_is_self_originated (struct ospf
*ospf
, struct ospf_lsa
*lsa
)
3062 /* This LSA is already checked. */
3063 if (CHECK_FLAG (lsa
->flags
, OSPF_LSA_SELF_CHECKED
))
3064 return CHECK_FLAG (lsa
->flags
, OSPF_LSA_SELF
);
3066 /* Make sure LSA is self-checked. */
3067 SET_FLAG (lsa
->flags
, OSPF_LSA_SELF_CHECKED
);
3069 /* AdvRouter and Router ID is the same. */
3070 if (IPV4_ADDR_SAME (&lsa
->data
->adv_router
, &ospf
->router_id
))
3071 SET_FLAG (lsa
->flags
, OSPF_LSA_SELF
);
3073 /* LSA is router-LSA. */
3074 else if (lsa
->data
->type
== OSPF_ROUTER_LSA
&&
3075 IPV4_ADDR_SAME (&lsa
->data
->id
, &ospf
->router_id
))
3076 SET_FLAG (lsa
->flags
, OSPF_LSA_SELF
);
3078 /* LSA is network-LSA. Compare Link ID with all interfaces. */
3079 else if (lsa
->data
->type
== OSPF_NETWORK_LSA
)
3080 for (node
= listhead (ospf
->oiflist
); node
; nextnode (node
))
3082 struct ospf_interface
*oi
= getdata (node
);
3084 /* Ignore virtual link. */
3085 if (oi
->type
!= OSPF_IFTYPE_VIRTUALLINK
)
3086 if (oi
->address
->family
== AF_INET
)
3087 if (IPV4_ADDR_SAME (&lsa
->data
->id
, &oi
->address
->u
.prefix4
))
3089 /* to make it easier later */
3090 SET_FLAG (lsa
->flags
, OSPF_LSA_SELF
);
3091 return CHECK_FLAG (lsa
->flags
, OSPF_LSA_SELF
);
3095 return CHECK_FLAG (lsa
->flags
, OSPF_LSA_SELF
);
3098 /* Get unique Link State ID. */
3100 ospf_lsa_unique_id (struct ospf
*ospf
,
3101 struct ospf_lsdb
*lsdb
, u_char type
, struct prefix_ipv4
*p
)
3103 struct ospf_lsa
*lsa
;
3104 struct in_addr mask
, id
;
3108 /* Check existence of LSA instance. */
3109 lsa
= ospf_lsdb_lookup_by_id (lsdb
, type
, id
, ospf
->router_id
);
3112 struct as_external_lsa
*al
= (struct as_external_lsa
*) lsa
->data
;
3113 if (ip_masklen (al
->mask
) == p
->prefixlen
)
3115 if (IS_DEBUG_OSPF (lsa
, LSA_GENERATE
))
3116 zlog_warn ("ospf_lsa_unique_id(): "
3117 "Can't get Link State ID for %s/%d",
3118 inet_ntoa (p
->prefix
), p
->prefixlen
);
3119 /* id.s_addr = 0; */
3120 id
.s_addr
= 0xffffffff;
3123 /* Masklen differs, then apply wildcard mask to Link State ID. */
3126 masklen2ip (p
->prefixlen
, &mask
);
3128 id
.s_addr
= p
->prefix
.s_addr
| (~mask
.s_addr
);
3129 lsa
= ospf_lsdb_lookup_by_id (ospf
->lsdb
, type
,
3130 id
, ospf
->router_id
);
3133 if (IS_DEBUG_OSPF (lsa
, LSA_GENERATE
))
3134 zlog_warn ("ospf_lsa_unique_id(): "
3135 "Can't get Link State ID for %s/%d",
3136 inet_ntoa (p
->prefix
), p
->prefixlen
);
3137 /* id.s_addr = 0; */
3138 id
.s_addr
= 0xffffffff;
3148 #define LSA_ACTION_ORIGN_RTR 1
3149 #define LSA_ACTION_ORIGN_NET 2
3150 #define LSA_ACTION_FLOOD_AREA 3
3151 #define LSA_ACTION_FLOOD_AS 4
3152 #define LSA_ACTION_FLUSH_AREA 5
3153 #define LSA_ACTION_FLUSH_AS 6
3158 struct ospf_area
*area
;
3159 struct ospf_interface
*oi
;
3160 struct ospf_lsa
*lsa
;
3164 ospf_lsa_action (struct thread
*t
)
3166 struct lsa_action
*data
;
3169 ospf
= ospf_lookup ();
3171 data
= THREAD_ARG (t
);
3173 if (IS_DEBUG_OSPF (lsa
, LSA
) == OSPF_DEBUG_LSA
)
3174 zlog_info ("LSA[Action]: Performing scheduled LSA action: %d",
3177 switch (data
->action
)
3179 case LSA_ACTION_ORIGN_RTR
:
3180 ospf_router_lsa_refresh (data
->area
->router_lsa_self
);
3182 case LSA_ACTION_ORIGN_NET
:
3183 ospf_network_lsa_originate (data
->oi
);
3185 case LSA_ACTION_FLOOD_AREA
:
3186 ospf_flood_through_area (data
->area
, NULL
, data
->lsa
);
3188 case LSA_ACTION_FLOOD_AS
:
3189 ospf_flood_through_as (ospf
, NULL
, data
->lsa
);
3191 case LSA_ACTION_FLUSH_AREA
:
3192 ospf_lsa_flush_area (data
->lsa
, data
->area
);
3194 case LSA_ACTION_FLUSH_AS
:
3195 ospf_lsa_flush_as (ospf
, data
->lsa
);
3199 ospf_lsa_unlock (data
->lsa
);
3200 XFREE (MTYPE_OSPF_MESSAGE
, data
);
3205 ospf_schedule_lsa_flood_area (struct ospf_area
*area
, struct ospf_lsa
*lsa
)
3207 struct lsa_action
*data
;
3209 data
= XMALLOC (MTYPE_OSPF_MESSAGE
, sizeof (struct lsa_action
));
3210 memset (data
, 0, sizeof (struct lsa_action
));
3212 data
->action
= LSA_ACTION_FLOOD_AREA
;
3214 data
->lsa
= ospf_lsa_lock (lsa
);
3216 thread_add_event (master
, ospf_lsa_action
, data
, 0);
3220 ospf_schedule_lsa_flush_area (struct ospf_area
*area
, struct ospf_lsa
*lsa
)
3222 struct lsa_action
*data
;
3224 data
= XMALLOC (MTYPE_OSPF_MESSAGE
, sizeof (struct lsa_action
));
3225 memset (data
, 0, sizeof (struct lsa_action
));
3227 data
->action
= LSA_ACTION_FLUSH_AREA
;
3229 data
->lsa
= ospf_lsa_lock (lsa
);
3231 thread_add_event (master
, ospf_lsa_action
, data
, 0);
3235 /* LSA Refreshment functions. */
3237 ospf_lsa_refresh (struct ospf
*ospf
, struct ospf_lsa
*lsa
)
3239 struct external_info
*ei
;
3240 assert (CHECK_FLAG (lsa
->flags
, OSPF_LSA_SELF
));
3242 switch (lsa
->data
->type
)
3244 /* Router and Network LSAs are processed differently. */
3245 case OSPF_ROUTER_LSA
:
3246 case OSPF_NETWORK_LSA
:
3248 case OSPF_SUMMARY_LSA
:
3249 ospf_summary_lsa_refresh (ospf
, lsa
);
3251 case OSPF_ASBR_SUMMARY_LSA
:
3252 ospf_summary_asbr_lsa_refresh (ospf
, lsa
);
3254 case OSPF_AS_EXTERNAL_LSA
:
3255 ei
= ospf_external_info_check (lsa
);
3257 ospf_external_lsa_refresh (ospf
, lsa
, ei
, LSA_REFRESH_FORCE
);
3259 ospf_lsa_flush_as (ospf
, lsa
);
3261 #ifdef HAVE_OPAQUE_LSA
3262 case OSPF_OPAQUE_LINK_LSA
:
3263 case OSPF_OPAQUE_AREA_LSA
:
3264 case OSPF_OPAQUE_AS_LSA
:
3265 ospf_opaque_lsa_refresh (lsa
);
3269 #endif /* HAVE_OPAQUE_LSA */
3274 ospf_refresher_register_lsa (struct ospf
*ospf
, struct ospf_lsa
*lsa
)
3276 u_int16_t index
, current_index
;
3278 assert (CHECK_FLAG (lsa
->flags
, OSPF_LSA_SELF
));
3280 if (lsa
->refresh_list
< 0)
3284 if (LS_AGE (lsa
) == 0 &&
3285 ntohl (lsa
->data
->ls_seqnum
) == OSPF_INITIAL_SEQUENCE_NUMBER
)
3286 /* Randomize first update by OSPF_LS_REFRESH_SHIFT factor */
3287 delay
= OSPF_LS_REFRESH_SHIFT
+ (random () % OSPF_LS_REFRESH_TIME
);
3289 /* Randomize another updates by +-OSPF_LS_REFRESH_JITTER factor */
3290 delay
= OSPF_LS_REFRESH_TIME
- LS_AGE (lsa
) - OSPF_LS_REFRESH_JITTER
3291 + (random () % (2*OSPF_LS_REFRESH_JITTER
));
3296 current_index
= ospf
->lsa_refresh_queue
.index
+
3297 (time (NULL
) - ospf
->lsa_refresher_started
)/OSPF_LSA_REFRESHER_GRANULARITY
;
3299 index
= (current_index
+ delay
/OSPF_LSA_REFRESHER_GRANULARITY
)
3300 % (OSPF_LSA_REFRESHER_SLOTS
);
3302 if (IS_DEBUG_OSPF (lsa
, LSA_REFRESH
))
3303 zlog_info ("LSA[Refresh]: lsa with age %d added to index %d",
3304 LS_AGE (lsa
), index
);
3305 if (!ospf
->lsa_refresh_queue
.qs
[index
])
3306 ospf
->lsa_refresh_queue
.qs
[index
] = list_new ();
3307 listnode_add (ospf
->lsa_refresh_queue
.qs
[index
], ospf_lsa_lock (lsa
));
3308 lsa
->refresh_list
= index
;
3309 if (IS_DEBUG_OSPF (lsa
, LSA_REFRESH
))
3310 zlog_info ("LSA[Refresh]: ospf_refresher_register_lsa(): setting refresh_list on lsa %p (slod %d)", lsa
, index
);
3315 ospf_refresher_unregister_lsa (struct ospf
*ospf
, struct ospf_lsa
*lsa
)
3317 assert (CHECK_FLAG (lsa
->flags
, OSPF_LSA_SELF
));
3318 if (lsa
->refresh_list
>= 0)
3320 list refresh_list
= ospf
->lsa_refresh_queue
.qs
[lsa
->refresh_list
];
3321 listnode_delete (refresh_list
, lsa
);
3322 if (!listcount (refresh_list
))
3324 list_free (refresh_list
);
3325 ospf
->lsa_refresh_queue
.qs
[lsa
->refresh_list
] = NULL
;
3327 ospf_lsa_unlock (lsa
);
3328 lsa
->refresh_list
= -1;
3333 ospf_lsa_refresh_walker (struct thread
*t
)
3337 struct ospf
*ospf
= THREAD_ARG (t
);
3339 list lsa_to_refresh
= list_new ();
3341 if (IS_DEBUG_OSPF (lsa
, LSA_REFRESH
))
3342 zlog_info ("LSA[Refresh]:ospf_lsa_refresh_walker(): start");
3345 i
= ospf
->lsa_refresh_queue
.index
;
3347 ospf
->lsa_refresh_queue
.index
=
3348 (ospf
->lsa_refresh_queue
.index
+
3349 (time (NULL
) - ospf
->lsa_refresher_started
) / OSPF_LSA_REFRESHER_GRANULARITY
)
3350 % OSPF_LSA_REFRESHER_SLOTS
;
3352 if (IS_DEBUG_OSPF (lsa
, LSA_REFRESH
))
3353 zlog_info ("LSA[Refresh]: ospf_lsa_refresh_walker(): next index %d",
3354 ospf
->lsa_refresh_queue
.index
);
3356 for (;i
!= ospf
->lsa_refresh_queue
.index
;
3357 i
= (i
+ 1) % OSPF_LSA_REFRESHER_SLOTS
)
3359 if (IS_DEBUG_OSPF (lsa
, LSA_REFRESH
))
3360 zlog_info ("LSA[Refresh]: ospf_lsa_refresh_walker(): refresh index %d", i
);
3362 refresh_list
= ospf
->lsa_refresh_queue
.qs
[i
];
3364 ospf
->lsa_refresh_queue
.qs
[i
] = NULL
;
3368 for (node
= listhead (refresh_list
); node
;)
3371 struct ospf_lsa
*lsa
= getdata (node
);
3374 if (IS_DEBUG_OSPF (lsa
, LSA_REFRESH
))
3375 zlog_info ("LSA[Refresh]: ospf_lsa_refresh_walker(): refresh lsa %p (slot %d)", lsa
, i
);
3377 list_delete_node (refresh_list
, node
);
3378 ospf_lsa_unlock (lsa
);
3379 lsa
->refresh_list
= -1;
3380 listnode_add (lsa_to_refresh
, lsa
);
3383 list_free (refresh_list
);
3387 ospf
->t_lsa_refresher
= thread_add_timer (master
, ospf_lsa_refresh_walker
,
3388 ospf
, ospf
->lsa_refresh_interval
);
3389 ospf
->lsa_refresher_started
= time (NULL
);
3391 for (node
= listhead (lsa_to_refresh
); node
; nextnode (node
))
3392 ospf_lsa_refresh (ospf
, getdata (node
));
3394 list_delete (lsa_to_refresh
);
3396 if (IS_DEBUG_OSPF (lsa
, LSA_REFRESH
))
3397 zlog_info ("LSA[Refresh]: ospf_lsa_refresh_walker(): end");