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
);
261 ospf_lsa_free (struct ospf_lsa
*lsa
)
263 assert (lsa
->lock
== 0);
265 if (IS_DEBUG_OSPF (lsa
, LSA
))
266 zlog_info ("LSA: freed %p", lsa
);
268 /* Delete LSA data. */
269 if (lsa
->data
!= NULL
)
270 ospf_lsa_data_free (lsa
->data
);
272 assert (lsa
->refresh_list
< 0);
274 memset (lsa
, 0, sizeof (struct ospf_lsa
));
275 XFREE (MTYPE_OSPF_LSA
, lsa
);
280 ospf_lsa_lock (struct ospf_lsa
*lsa
)
288 ospf_lsa_unlock (struct ospf_lsa
*lsa
)
290 /* This is sanity check. */
296 assert (lsa
->lock
>= 0);
300 assert (CHECK_FLAG (lsa
->flags
, OSPF_LSA_DISCARD
));
305 /* Check discard flag. */
307 ospf_lsa_discard (struct ospf_lsa
*lsa
)
309 if (!CHECK_FLAG (lsa
->flags
, OSPF_LSA_DISCARD
))
311 SET_FLAG (lsa
->flags
, OSPF_LSA_DISCARD
);
312 ospf_lsa_unlock (lsa
);
316 /* Create LSA data. */
318 ospf_lsa_data_new (size_t size
)
320 struct lsa_header
*new;
322 new = (struct lsa_header
*) XMALLOC (MTYPE_OSPF_LSA_DATA
, size
);
323 memset (new, 0, size
);
328 /* Duplicate LSA data. */
330 ospf_lsa_data_dup (struct lsa_header
*lsah
)
332 struct lsa_header
*new;
334 new = ospf_lsa_data_new (ntohs (lsah
->length
));
335 memcpy (new, lsah
, ntohs (lsah
->length
));
342 ospf_lsa_data_free (struct lsa_header
*lsah
)
344 if (IS_DEBUG_OSPF (lsa
, LSA
))
345 zlog_info ("LSA[Type%d:%s]: data freed %p",
346 lsah
->type
, inet_ntoa (lsah
->id
), lsah
);
348 XFREE (MTYPE_OSPF_LSA_DATA
, lsah
);
352 /* LSA general functions. */
355 dump_lsa_key (struct ospf_lsa
*lsa
)
357 static char buf
[] = {
358 "Type255,id(255.255.255.255),ar(255.255.255.255)",
360 struct lsa_header
*lsah
;
362 if (lsa
!= NULL
&& (lsah
= lsa
->data
) != NULL
)
364 char id
[INET_ADDRSTRLEN
], ar
[INET_ADDRSTRLEN
];
365 strcpy (id
, inet_ntoa (lsah
->id
));
366 strcpy (ar
, inet_ntoa (lsah
->adv_router
));
368 sprintf (buf
, "Type%d,id(%s),ar(%s)", lsah
->type
, id
, ar
);
371 strcpy (buf
, "NULL");
377 lsa_seqnum_increment (struct ospf_lsa
*lsa
)
381 seqnum
= ntohl (lsa
->data
->ls_seqnum
) + 1;
383 return htonl (seqnum
);
387 lsa_header_set (struct stream
*s
, u_char options
,
388 u_char type
, struct in_addr id
)
390 struct lsa_header
*lsah
;
392 lsah
= (struct lsa_header
*) STREAM_DATA (s
);
394 lsah
->ls_age
= htons (0);
395 lsah
->options
= options
;
398 lsah
->adv_router
= ospf_top
->router_id
;
399 lsah
->ls_seqnum
= htonl (OSPF_INITIAL_SEQUENCE_NUMBER
);
401 ospf_output_forward (s
, OSPF_LSA_HEADER_SIZE
);
404 /* router-LSA related functions. */
405 /* Get router-LSA flags. */
407 router_lsa_flags (struct ospf_area
*area
)
411 flags
= ospf_top
->flags
;
413 /* Set virtual link flag. */
414 if (ospf_full_virtual_nbrs (area
))
415 SET_FLAG (flags
, ROUTER_LSA_VIRTUAL
);
417 /* Just sanity check */
418 UNSET_FLAG (flags
, ROUTER_LSA_VIRTUAL
);
420 /* Set Shortcut ABR behabiour flag. */
421 UNSET_FLAG (flags
, ROUTER_LSA_SHORTCUT
);
422 if (ospf_top
->abr_type
== OSPF_ABR_SHORTCUT
)
423 if (!OSPF_IS_AREA_BACKBONE (area
))
424 if ((area
->shortcut_configured
== OSPF_SHORTCUT_DEFAULT
&&
425 !ospf_top
->backbone
) ||
426 area
->shortcut_configured
== OSPF_SHORTCUT_ENABLE
)
427 SET_FLAG (flags
, ROUTER_LSA_SHORTCUT
);
429 /* ASBR can't exit in stub area. */
430 if (area
->external_routing
== OSPF_AREA_STUB
)
431 UNSET_FLAG (flags
, OSPF_FLAG_ASBR
);
436 /* Lookup neighbor other than myself.
437 And check neighbor count,
438 Point-to-Point link must have only 1 neighbor. */
439 struct ospf_neighbor
*
440 ospf_nbr_lookup_ptop (struct route_table
*nbrs
, struct in_addr router_id
)
442 struct route_node
*rn
;
443 struct ospf_neighbor
*nbr
= NULL
;
445 /* Search neighbor, there must be one of two nbrs. */
446 for (rn
= route_top (nbrs
); rn
; rn
= route_next (rn
))
447 if ((nbr
= rn
->info
) != NULL
)
449 if (!IPV4_ADDR_SAME (&nbr
->router_id
, &ospf_top
->router_id
))
450 if (nbr
->state
== NSM_Full
)
453 /* PtoP link must have only 1 neighbor. */
454 if (ospf_nbr_count (nbrs
, 0) > 1)
455 zlog_warn ("Point-to-Point link has more than 1 neighobrs.");
460 /* Set a link information. */
462 link_info_set (struct stream
*s
, struct in_addr id
,
463 struct in_addr data
, u_char type
, u_char tos
, u_int16_t cost
)
465 /* TOS based routing is not supported. */
466 stream_put_ipv4 (s
, id
.s_addr
); /* Link ID. */
467 stream_put_ipv4 (s
, data
.s_addr
); /* Link Data. */
468 stream_putc (s
, type
); /* Link Type. */
469 stream_putc (s
, tos
); /* TOS = 0. */
470 stream_putw (s
, cost
); /* Link Cost. */
473 /* Describe Point-to-Point link. */
475 lsa_link_ptop_set (struct stream
*s
, struct ospf_interface
*oi
)
478 struct ospf_neighbor
*nbr
;
479 struct in_addr id
, mask
;
481 if (IS_DEBUG_OSPF (lsa
, LSA_GENERATE
))
482 zlog_info ("LSA[Type1]: Set link Point-to-Point");
484 if ((nbr
= ospf_nbr_lookup_ptop (oi
->nbrs
, ospf_top
->router_id
)))
485 if (nbr
->state
== NSM_Full
)
487 /* For unnumbered point-to-point networks, the Link Data field
488 should specify the interface's MIB-II ifIndex value. */
489 link_info_set (s
, nbr
->router_id
, oi
->address
->u
.prefix4
,
490 LSA_LINK_TYPE_POINTOPOINT
, 0, oi
->output_cost
);
494 if (oi
->connected
->destination
!= NULL
)
497 link_type = LSA_LINK_TYPE_STUB;
498 link_id = nbr->address.u.prefix4;
499 link_data.s_addr = 0xffffffff;
500 link_cost = o->output_cost; */
502 id
.s_addr
= oi
->connected
->destination
->u
.prefix4
.s_addr
;
503 mask
.s_addr
= 0xffffffff;
504 link_info_set (s
, id
, mask
, LSA_LINK_TYPE_STUB
, 0, oi
->output_cost
);
508 /* Option 2: We need to include link to a stub
509 network regardless of the state of the neighbor */
510 masklen2ip (oi
->address
->prefixlen
, &mask
);
511 id
.s_addr
= oi
->address
->u
.prefix4
.s_addr
& mask
.s_addr
;
512 link_info_set (s
, id
, mask
, LSA_LINK_TYPE_STUB
, 0, oi
->output_cost
);
519 /* Describe Broadcast Link. */
521 lsa_link_broadcast_set (struct stream
*s
, struct ospf_interface
*oi
)
523 struct ospf_neighbor
*dr
;
524 struct in_addr id
, mask
;
526 /* Describe Type 3 Link. */
527 if (oi
->state
== ISM_Waiting
)
529 masklen2ip (oi
->address
->prefixlen
, &mask
);
530 id
.s_addr
= oi
->address
->u
.prefix4
.s_addr
& mask
.s_addr
;
531 link_info_set (s
, id
, mask
, LSA_LINK_TYPE_STUB
, 0, oi
->output_cost
);
535 dr
= ospf_nbr_lookup_by_addr (oi
->nbrs
, &DR (oi
));
536 /* Describe Type 2 link. */
537 if (dr
&& (dr
->state
== NSM_Full
||
538 IPV4_ADDR_SAME (&oi
->address
->u
.prefix4
, &DR (oi
))) &&
539 ospf_nbr_count (oi
->nbrs
, NSM_Full
) > 0)
541 link_info_set (s
, DR (oi
), oi
->address
->u
.prefix4
,
542 LSA_LINK_TYPE_TRANSIT
, 0, oi
->output_cost
);
544 /* Describe type 3 link. */
547 masklen2ip (oi
->address
->prefixlen
, &mask
);
548 id
.s_addr
= oi
->address
->u
.prefix4
.s_addr
& mask
.s_addr
;
549 link_info_set (s
, id
, mask
, LSA_LINK_TYPE_STUB
, 0, oi
->output_cost
);
555 lsa_link_loopback_set (struct stream
*s
, struct ospf_interface
*oi
)
557 struct in_addr id
, mask
;
559 /* Describe Type 3 Link. */
560 if (oi
->state
!= ISM_Loopback
)
563 mask
.s_addr
= 0xffffffff;
564 id
.s_addr
= oi
->address
->u
.prefix4
.s_addr
;
565 link_info_set (s
, id
, mask
, LSA_LINK_TYPE_STUB
, 0, oi
->output_cost
);
569 /* Describe Virtual Link. */
571 lsa_link_virtuallink_set (struct stream
*s
, struct ospf_interface
*oi
)
573 struct ospf_neighbor
*nbr
;
575 if (IS_DEBUG_OSPF (lsa
, LSA_GENERATE
))
576 zlog_info ("LSA[Type1]: Set link type VL, state %d", oi
->state
);
578 if (oi
->state
== ISM_PointToPoint
)
579 if ((nbr
= ospf_nbr_lookup_ptop (oi
->nbrs
, ospf_top
->router_id
)))
580 if (nbr
->state
== NSM_Full
)
582 link_info_set (s
, nbr
->router_id
, oi
->address
->u
.prefix4
,
583 LSA_LINK_TYPE_VIRTUALLINK
, 0, oi
->output_cost
);
590 #define lsa_link_nbma_set(S,O) lsa_link_broadcast_set (S, O)
592 /* this function add for support point-to-multipoint ,see rfc2328
594 /* from "edward rrr" <edward_rrr@hotmail.com>
595 http://marc.theaimsgroup.com/?l=zebra&m=100739222210507&w=2 */
596 int lsa_link_ptomultip_set (struct stream
*s
, struct ospf_interface
*oi
)
599 struct route_node
*rn
;
600 struct ospf_neighbor
*nbr
= NULL
;
601 struct in_addr id
, mask
;
603 mask
.s_addr
= 0xffffffff;
604 id
.s_addr
= oi
->address
->u
.prefix4
.s_addr
;
605 link_info_set (s
, id
, mask
, LSA_LINK_TYPE_STUB
, 0, 0);
608 zlog_info ("PointToMultipoint: running ptomultip_set");
610 /* Search neighbor, */
611 for (rn
= route_top (oi
->nbrs
); rn
; rn
= route_next (rn
))
612 if ((nbr
= rn
->info
) != NULL
)
614 if (!IPV4_ADDR_SAME (&nbr
->router_id
, &ospf_top
->router_id
))
615 if (nbr
->state
== NSM_Full
)
619 link_info_set (s
, nbr
->router_id
, oi
->address
->u
.prefix4
,
620 LSA_LINK_TYPE_POINTOPOINT
, 0, oi
->output_cost
);
622 zlog_info ("PointToMultipoint: set link to %s",
623 inet_ntoa(oi
->address
->u
.prefix4
));
630 /* Set router-LSA link information. */
632 router_lsa_link_set (struct stream
*s
, struct ospf_area
*area
)
637 for (node
= listhead (area
->oiflist
); node
; node
= nextnode (node
))
639 struct ospf_interface
*oi
= node
->data
;
640 struct interface
*ifp
= oi
->ifp
;
642 /* Check interface is up, OSPF is enable. */
643 if (if_is_operative (ifp
))
645 if (oi
->state
!= ISM_Down
)
647 /* Describe each link. */
650 case OSPF_IFTYPE_POINTOPOINT
:
651 links
+= lsa_link_ptop_set (s
, oi
);
653 case OSPF_IFTYPE_BROADCAST
:
654 links
+= lsa_link_broadcast_set (s
, oi
);
656 case OSPF_IFTYPE_NBMA
:
657 links
+= lsa_link_nbma_set (s
, oi
);
659 case OSPF_IFTYPE_POINTOMULTIPOINT
:
660 links
+= lsa_link_ptomultip_set (s
, oi
);
662 case OSPF_IFTYPE_VIRTUALLINK
:
663 links
+= lsa_link_virtuallink_set (s
, oi
);
665 case OSPF_IFTYPE_LOOPBACK
:
666 links
+= lsa_link_loopback_set (s
, oi
);
675 /* Set router-LSA body. */
677 ospf_router_lsa_body_set (struct stream
*s
, struct ospf_area
*area
)
683 stream_putc (s
, router_lsa_flags (area
));
685 /* Set Zero fields. */
688 /* Keep pointer to # links. */
694 /* Set all link information. */
695 cnt
= router_lsa_link_set (s
, area
);
697 /* Set # of links here. */
698 stream_putw_at (s
, putp
, cnt
);
701 /* Create new router-LSA. */
703 ospf_router_lsa_new (struct ospf_area
*area
)
706 struct lsa_header
*lsah
;
707 struct ospf_lsa
*new;
710 if (IS_DEBUG_OSPF (lsa
, LSA_GENERATE
))
711 zlog_info ("LSA[Type1]: Create router-LSA instance");
713 /* Create a stream for LSA. */
714 s
= stream_new (OSPF_MAX_LSA_SIZE
);
715 lsah
= (struct lsa_header
*) STREAM_DATA (s
);
718 /* Set LSA common header fields. */
719 lsa_header_set (s
, LSA_OPTIONS_GET (area
) | LSA_NSSA_GET (area
),
720 OSPF_ROUTER_LSA
, ospf_top
->router_id
);
721 #else /* ! HAVE_NSSA */
722 /* Set LSA common header fields. */
723 lsa_header_set (s
, LSA_OPTIONS_GET (area
),
724 OSPF_ROUTER_LSA
, ospf_top
->router_id
);
725 #endif /* HAVE_NSSA */
727 /* Set router-LSA body fields. */
728 ospf_router_lsa_body_set (s
, area
);
731 length
= stream_get_endp (s
);
732 lsah
->length
= htons (length
);
734 /* Now, create OSPF LSA instance. */
735 new = ospf_lsa_new ();
737 SET_FLAG (new->flags
, OSPF_LSA_SELF
);
739 /* Copy LSA data to store, discard stream. */
740 new->data
= ospf_lsa_data_new (length
);
741 memcpy (new->data
, lsah
, length
);
747 /* Originate Router-LSA. */
749 ospf_router_lsa_originate (struct ospf_area
*area
)
751 struct ospf_lsa
*new;
753 /* Create new router-LSA instance. */
754 new = ospf_router_lsa_new (area
);
757 if (new->data
->adv_router
.s_addr
== 0)
759 if (IS_DEBUG_OSPF_EVENT
)
760 zlog_info ("LSA[Type1]: AdvRouter is 0, discard");
761 ospf_lsa_discard (new);
765 /* Install LSA to LSDB. */
766 new = ospf_lsa_install (NULL
, new);
768 /* Update LSA origination count. */
769 ospf_top
->lsa_originate_count
++;
771 /* Flooding new LSA through area. */
772 ospf_flood_through_area (area
, NULL
, new);
774 if (IS_DEBUG_OSPF (lsa
, LSA_GENERATE
))
776 zlog_info ("LSA[Type%d:%s]: Originate router-LSA %p",
777 new->data
->type
, inet_ntoa (new->data
->id
), new);
778 ospf_lsa_header_dump (new->data
);
784 /* Refresh router-LSA. */
786 ospf_router_lsa_refresh (struct ospf_lsa
*lsa
)
788 struct ospf_area
*area
= lsa
->area
;
789 struct ospf_lsa
*new;
794 /* Delete LSA from neighbor retransmit-list. */
795 ospf_ls_retransmit_delete_nbr_all (area
, lsa
);
797 /* Create new router-LSA instance. */
798 new = ospf_router_lsa_new (area
);
799 new->data
->ls_seqnum
= lsa_seqnum_increment (lsa
);
801 ospf_lsa_install (NULL
, new);
803 /* Flood LSA through area. */
804 ospf_flood_through_area (area
, NULL
, new);
807 if (IS_DEBUG_OSPF (lsa
, LSA_GENERATE
))
809 zlog_info ("LSA[Type%d:%s]: router-LSA refresh",
810 new->data
->type
, inet_ntoa (new->data
->id
));
811 ospf_lsa_header_dump (new->data
);
818 ospf_router_lsa_timer (struct thread
*t
)
820 struct ospf_area
*area
;
822 if (IS_DEBUG_OSPF_EVENT
)
823 zlog_info ("Timer[router-LSA]: (router-LSA Refresh expire)");
825 area
= THREAD_ARG (t
);
826 area
->t_router_lsa_self
= NULL
;
828 /* Now refresh router-LSA. */
829 if (area
->router_lsa_self
)
830 ospf_router_lsa_refresh (area
->router_lsa_self
);
831 /* Newly originate router-LSA. */
833 ospf_router_lsa_originate (area
);
839 ospf_router_lsa_timer_add (struct ospf_area
*area
)
841 /* Keep area's self-originated router-LSA. */
842 struct ospf_lsa
*lsa
= area
->router_lsa_self
;
844 /* Cancel previously scheduled router-LSA timer. */
845 if (area
->t_router_lsa_self
)
846 if (IS_DEBUG_OSPF (lsa
, LSA_GENERATE
))
847 zlog_info ("LSA[Type1]: Cancel previous router-LSA timer");
849 OSPF_TIMER_OFF (area
->t_router_lsa_self
);
851 /* If router-LSA is originated previously, check the interval time. */
855 if ((delay
= ospf_lsa_refresh_delay (lsa
)) > 0)
857 OSPF_AREA_TIMER_ON (area
->t_router_lsa_self
,
858 ospf_router_lsa_timer
, delay
);
863 if (IS_DEBUG_OSPF (lsa
, LSA_GENERATE
))
864 zlog_info ("LSA[Type1]: Scheduling router-LSA origination right away");
866 /* Immediately refresh router-LSA. */
867 OSPF_AREA_TIMER_ON (area
->t_router_lsa_self
, ospf_router_lsa_timer
, 0);
871 ospf_router_lsa_update_timer (struct thread
*t
)
875 if (IS_DEBUG_OSPF (lsa
, LSA_GENERATE
))
876 zlog_info ("Timer[router-LSA Update]: (timer expire)");
878 ospf_top
->t_router_lsa_update
= NULL
;
880 for (node
= listhead (ospf_top
->areas
); node
; nextnode (node
))
882 struct ospf_area
*area
= getdata (node
);
883 struct ospf_lsa
*lsa
= area
->router_lsa_self
;
884 struct router_lsa
*rl
;
887 /* Keep Area ID string. */
888 area_str
= AREA_NAME (area
);
890 /* If LSA not exist in this Area, originate new. */
893 if (IS_DEBUG_OSPF (lsa
, LSA_GENERATE
))
894 zlog_info("LSA[Type1]: Create router-LSA for Area %s", area_str
);
896 ospf_router_lsa_originate (area
);
898 /* If router-ID is changed, Link ID must change.
899 First flush old LSA, then originate new. */
900 else if (!IPV4_ADDR_SAME (&lsa
->data
->id
, &ospf_top
->router_id
))
902 if (IS_DEBUG_OSPF (lsa
, LSA_GENERATE
))
903 zlog_info("LSA[Type%d:%s]: Refresh router-LSA for Area %s",
904 lsa
->data
->type
, inet_ntoa (lsa
->data
->id
), area_str
);
905 ospf_lsa_flush_area (lsa
, area
);
906 ospf_lsa_unlock (area
->router_lsa_self
);
907 area
->router_lsa_self
= NULL
;
909 /* Refresh router-LSA, (not install) and flood through area. */
910 ospf_router_lsa_timer_add (area
);
914 rl
= (struct router_lsa
*) lsa
->data
;
915 /* Refresh router-LSA, (not install) and flood through area. */
916 if (rl
->flags
!= ospf_top
->flags
)
917 ospf_router_lsa_timer_add (area
);
925 /* network-LSA related functions. */
926 /* Originate Network-LSA. */
928 ospf_network_lsa_body_set (struct stream
*s
, struct ospf_interface
*oi
)
931 struct route_node
*rn
;
932 struct ospf_neighbor
*nbr
;
934 masklen2ip (oi
->address
->prefixlen
, &mask
);
935 stream_put_ipv4 (s
, mask
.s_addr
);
937 /* The network-LSA lists those routers that are fully adjacent to
938 the Designated Router; each fully adjacent router is identified by
939 its OSPF Router ID. The Designated Router includes itself in this
940 list. RFC2328, Section 12.4.2 */
942 for (rn
= route_top (oi
->nbrs
); rn
; rn
= route_next (rn
))
943 if ((nbr
= rn
->info
) != NULL
)
944 if (nbr
->state
== NSM_Full
|| nbr
== oi
->nbr_self
)
945 stream_put_ipv4 (s
, nbr
->router_id
.s_addr
);
949 ospf_network_lsa_new (struct ospf_interface
*oi
)
952 struct ospf_lsa
*new;
953 struct lsa_header
*lsah
;
956 /* If there are no neighbours on this network (the net is stub),
957 the router does not originate network-LSA (see RFC 12.4.2) */
958 if (oi
->full_nbrs
== 0)
961 if (IS_DEBUG_OSPF (lsa
, LSA_GENERATE
))
962 zlog_info ("LSA[Type2]: Create network-LSA instance");
964 /* Create new stream for LSA. */
965 s
= stream_new (OSPF_MAX_LSA_SIZE
);
966 lsah
= (struct lsa_header
*) STREAM_DATA (s
);
968 lsa_header_set (s
, (OPTIONS (oi
) | LSA_OPTIONS_GET (oi
->area
)),
969 OSPF_NETWORK_LSA
, DR (oi
));
971 /* Set network-LSA body fields. */
972 ospf_network_lsa_body_set (s
, oi
);
975 length
= stream_get_endp (s
);
976 lsah
->length
= htons (length
);
978 /* Create OSPF LSA instance. */
979 new = ospf_lsa_new ();
980 new->area
= oi
->area
;
981 SET_FLAG (new->flags
, OSPF_LSA_SELF
);
983 /* Copy LSA to store. */
984 new->data
= ospf_lsa_data_new (length
);
985 memcpy (new->data
, lsah
, length
);
991 /* Originate network-LSA. */
993 ospf_network_lsa_originate (struct ospf_interface
*oi
)
995 struct ospf_lsa
*new;
997 /* Create new network-LSA instance. */
998 new = ospf_network_lsa_new (oi
);
1002 /* Install LSA to LSDB. */
1003 new = ospf_lsa_install (oi
, new);
1005 /* Update LSA origination count. */
1006 ospf_top
->lsa_originate_count
++;
1008 /* Flooding new LSA through area. */
1009 ospf_flood_through_area (oi
->area
, NULL
, new);
1011 if (IS_DEBUG_OSPF (lsa
, LSA_GENERATE
))
1013 zlog_info ("LSA[Type%d:%s]: Originate network-LSA %p",
1014 new->data
->type
, inet_ntoa (new->data
->id
), new);
1015 ospf_lsa_header_dump (new->data
);
1022 ospf_network_lsa_refresh (struct ospf_lsa
*lsa
, struct ospf_interface
*oi
)
1024 struct ospf_area
*area
= lsa
->area
;
1025 struct ospf_lsa
*new;
1029 /* Delete LSA from neighbor retransmit-list. */
1030 ospf_ls_retransmit_delete_nbr_all (area
, lsa
);
1032 /* Create new network-LSA instance. */
1033 new = ospf_network_lsa_new (oi
);
1036 new->data
->ls_seqnum
= lsa_seqnum_increment (lsa
);
1038 ospf_lsa_install (oi
, new);
1040 /* Flood LSA through aera. */
1041 ospf_flood_through_area (area
, NULL
, new);
1043 if (IS_DEBUG_OSPF (lsa
, LSA_GENERATE
))
1045 zlog_info ("LSA[Type%d:%s]: network-LSA refresh",
1046 new->data
->type
, inet_ntoa (new->data
->id
));
1047 ospf_lsa_header_dump (new->data
);
1054 ospf_network_lsa_refresh_timer (struct thread
*t
)
1056 struct ospf_interface
*oi
;
1058 oi
= THREAD_ARG (t
);
1059 oi
->t_network_lsa_self
= NULL
;
1061 if (oi
->network_lsa_self
)
1062 /* Now refresh network-LSA. */
1063 ospf_network_lsa_refresh (oi
->network_lsa_self
, oi
);
1065 /* Newly create network-LSA. */
1066 ospf_network_lsa_originate (oi
);
1072 ospf_network_lsa_timer_add (struct ospf_interface
*oi
)
1074 /* Keep interface's self-originated network-LSA. */
1075 struct ospf_lsa
*lsa
= oi
->network_lsa_self
;
1077 /* Cancel previously schedules network-LSA timer. */
1078 if (oi
->t_network_lsa_self
)
1079 if (IS_DEBUG_OSPF (lsa
, LSA_GENERATE
))
1080 zlog_info ("LSA[Type2]: Cancel previous network-LSA timer");
1081 OSPF_TIMER_OFF (oi
->t_network_lsa_self
);
1083 /* If network-LSA is originated previously, check the interval time. */
1087 if ((delay
= ospf_lsa_refresh_delay (lsa
)) > 0)
1089 oi
->t_network_lsa_self
=
1090 thread_add_timer (master
, ospf_network_lsa_refresh_timer
,
1096 if (IS_DEBUG_OSPF (lsa
, LSA_GENERATE
))
1097 zlog_info ("Scheduling network-LSA origination right away");
1099 /* Immediately refresh network-LSA. */
1100 oi
->t_network_lsa_self
=
1101 thread_add_event (master
, ospf_network_lsa_refresh_timer
, oi
, 0);
1106 stream_put_ospf_metric (struct stream
*s
, u_int32_t metric_value
)
1111 /* Put 0 metric. TOS metric is not supported. */
1112 metric
= htonl (metric_value
);
1113 mp
= (char *) &metric
;
1115 stream_put (s
, mp
, 3);
1118 /* summary-LSA related functions. */
1120 ospf_summary_lsa_body_set (struct stream
*s
, struct prefix
*p
,
1123 struct in_addr mask
;
1125 masklen2ip (p
->prefixlen
, &mask
);
1127 /* Put Network Mask. */
1128 stream_put_ipv4 (s
, mask
.s_addr
);
1131 stream_putc (s
, (u_char
) 0);
1134 stream_put_ospf_metric (s
, metric
);
1138 ospf_summary_lsa_new (struct ospf_area
*area
, struct prefix
*p
,
1139 u_int32_t metric
, struct in_addr id
)
1142 struct ospf_lsa
*new;
1143 struct lsa_header
*lsah
;
1146 if (IS_DEBUG_OSPF (lsa
, LSA_GENERATE
))
1147 zlog_info ("LSA[Type3]: Create summary-LSA instance");
1149 /* Create new stream for LSA. */
1150 s
= stream_new (OSPF_MAX_LSA_SIZE
);
1151 lsah
= (struct lsa_header
*) STREAM_DATA (s
);
1153 lsa_header_set (s
, LSA_OPTIONS_GET (area
), OSPF_SUMMARY_LSA
, id
);
1155 /* Set summary-LSA body fields. */
1156 ospf_summary_lsa_body_set (s
, p
, metric
);
1159 length
= stream_get_endp (s
);
1160 lsah
->length
= htons (length
);
1162 /* Create OSPF LSA instance. */
1163 new = ospf_lsa_new ();
1165 SET_FLAG (new->flags
, OSPF_LSA_SELF
);
1167 /* Copy LSA to store. */
1168 new->data
= ospf_lsa_data_new (length
);
1169 memcpy (new->data
, lsah
, length
);
1175 /* Originate Summary-LSA. */
1177 ospf_summary_lsa_originate (struct prefix_ipv4
*p
, u_int32_t metric
,
1178 struct ospf_area
*area
)
1180 struct ospf_lsa
*new;
1183 id
= ospf_lsa_unique_id (area
->lsdb
, OSPF_SUMMARY_LSA
, p
);
1185 /* Create new summary-LSA instance. */
1186 new = ospf_summary_lsa_new (area
, (struct prefix
*) p
, metric
, id
);
1188 /* Instlal LSA to LSDB. */
1189 new = ospf_lsa_install (NULL
, new);
1191 /* Update LSA origination count. */
1192 ospf_top
->lsa_originate_count
++;
1194 /* Flooding new LSA through area. */
1195 ospf_flood_through_area (area
, NULL
, new);
1197 if (IS_DEBUG_OSPF (lsa
, LSA_GENERATE
))
1199 zlog_info ("LSA[Type%d:%s]: Originate summary-LSA %p",
1200 new->data
->type
, inet_ntoa (new->data
->id
), new);
1201 ospf_lsa_header_dump (new->data
);
1208 ospf_summary_lsa_refresh (struct ospf_lsa
*lsa
)
1210 struct ospf_lsa
*new;
1211 struct summary_lsa
*sl
;
1217 sl
= (struct summary_lsa
*)lsa
->data
;
1218 p
.prefixlen
= ip_masklen (sl
->mask
);
1219 new = ospf_summary_lsa_new (lsa
->area
, &p
, GET_METRIC (sl
->metric
),
1222 new->data
->ls_seqnum
= lsa_seqnum_increment (lsa
);
1224 /* Re-calculate checksum. */
1225 ospf_lsa_checksum (new->data
);
1227 ospf_lsa_install (NULL
, new);
1229 /* Flood LSA through AS. */
1230 ospf_flood_through_area (new->area
, NULL
, new);
1232 /* Debug logging. */
1233 if (IS_DEBUG_OSPF (lsa
, LSA_GENERATE
))
1235 zlog_info ("LSA[Type%d:%s]: summary-LSA refresh",
1236 new->data
->type
, inet_ntoa (new->data
->id
));
1237 ospf_lsa_header_dump (new->data
);
1244 /* summary-ASBR-LSA related functions. */
1246 ospf_summary_asbr_lsa_body_set (struct stream
*s
, struct prefix
*p
,
1249 struct in_addr mask
;
1251 masklen2ip (p
->prefixlen
, &mask
);
1253 /* Put Network Mask. */
1254 stream_put_ipv4 (s
, mask
.s_addr
);
1257 stream_putc (s
, (u_char
) 0);
1260 stream_put_ospf_metric (s
, metric
);
1264 ospf_summary_asbr_lsa_new (struct ospf_area
*area
, struct prefix
*p
,
1265 u_int32_t metric
, struct in_addr id
)
1268 struct ospf_lsa
*new;
1269 struct lsa_header
*lsah
;
1272 if (IS_DEBUG_OSPF (lsa
, LSA_GENERATE
))
1273 zlog_info ("LSA[Type3]: Create summary-LSA instance");
1275 /* Create new stream for LSA. */
1276 s
= stream_new (OSPF_MAX_LSA_SIZE
);
1277 lsah
= (struct lsa_header
*) STREAM_DATA (s
);
1279 lsa_header_set (s
, LSA_OPTIONS_GET (area
), OSPF_ASBR_SUMMARY_LSA
, id
);
1281 /* Set summary-LSA body fields. */
1282 ospf_summary_asbr_lsa_body_set (s
, p
, metric
);
1285 length
= stream_get_endp (s
);
1286 lsah
->length
= htons (length
);
1288 /* Create OSPF LSA instance. */
1289 new = ospf_lsa_new ();
1291 SET_FLAG (new->flags
, OSPF_LSA_SELF
);
1293 /* Copy LSA to store. */
1294 new->data
= ospf_lsa_data_new (length
);
1295 memcpy (new->data
, lsah
, length
);
1301 /* Originate summary-ASBR-LSA. */
1303 ospf_summary_asbr_lsa_originate (struct prefix_ipv4
*p
, u_int32_t metric
,
1304 struct ospf_area
*area
)
1306 struct ospf_lsa
*new;
1309 id
= ospf_lsa_unique_id (area
->lsdb
, OSPF_ASBR_SUMMARY_LSA
, p
);
1311 /* Create new summary-LSA instance. */
1312 new = ospf_summary_asbr_lsa_new (area
, (struct prefix
*) p
, metric
, id
);
1314 /* Install LSA to LSDB. */
1315 new = ospf_lsa_install (NULL
, new);
1317 /* Update LSA origination count. */
1318 ospf_top
->lsa_originate_count
++;
1320 /* Flooding new LSA through area. */
1321 ospf_flood_through_area (area
, NULL
, new);
1323 if (IS_DEBUG_OSPF (lsa
, LSA_GENERATE
))
1325 zlog_info ("LSA[Type%d:%s]: Originate summary-ASBR-LSA %p",
1326 new->data
->type
, inet_ntoa (new->data
->id
), new);
1327 ospf_lsa_header_dump (new->data
);
1334 ospf_summary_asbr_lsa_refresh (struct ospf_lsa
*lsa
)
1336 struct ospf_lsa
*new;
1337 struct summary_lsa
*sl
;
1343 sl
= (struct summary_lsa
*)lsa
->data
;
1344 p
.prefixlen
= ip_masklen (sl
->mask
);
1345 new = ospf_summary_asbr_lsa_new (lsa
->area
, &p
, GET_METRIC (sl
->metric
),
1348 new->data
->ls_seqnum
= lsa_seqnum_increment (lsa
);
1350 /* Re-calculate checksum. */
1351 ospf_lsa_checksum (new->data
);
1353 ospf_lsa_install (NULL
, new);
1355 /* Flood LSA through area. */
1356 ospf_flood_through_area (new->area
, NULL
, new);
1358 if (IS_DEBUG_OSPF (lsa
, LSA_GENERATE
))
1360 zlog_info ("LSA[Type%d:%s]: summary-ASBR-LSA refresh",
1361 new->data
->type
, inet_ntoa (new->data
->id
));
1362 ospf_lsa_header_dump (new->data
);
1368 /* AS-external-LSA related functions. */
1370 /* Get nexthop for AS-external-LSAs. Return nexthop if its interface
1371 is connected, else 0*/
1373 ospf_external_lsa_nexthop_get (struct in_addr nexthop
)
1377 /* struct route_node *rn; */
1382 if (!nexthop
.s_addr
)
1385 /* Check whether nexthop is covered by OSPF network. */
1386 nh
.family
= AF_INET
;
1387 nh
.u
.prefix4
= nexthop
;
1388 nh
.prefixlen
= IPV4_MAX_BITLEN
;
1390 for (n1
= listhead (ospf_top
->oiflist
); n1
; nextnode (n1
))
1392 struct ospf_interface
*oi
= getdata (n1
);
1394 if (if_is_operative (oi
->ifp
))
1395 if (oi
->address
->family
== AF_INET
)
1396 if (prefix_match (oi
->address
, &nh
))
1404 /* NSSA-external-LSA related functions. */
1406 /* Get 1st IP connection for Forward Addr */
1409 ospf_get_ip_from_ifp (struct ospf_interface
*oi
)
1415 if (if_is_operative (oi
->ifp
))
1416 return oi
->address
->u
.prefix4
;
1421 /* Get 1st IP connection for Forward Addr */
1423 ospf_get_nssa_ip (void)
1431 for (n1
= listhead (ospf_top
->oiflist
); n1
; nextnode (n1
))
1433 struct ospf_interface
*oi
= getdata (n1
);
1435 if (if_is_operative (oi
->ifp
))
1436 if (oi
->area
->external_routing
== OSPF_AREA_NSSA
)
1437 if (oi
->address
&& oi
->address
->family
== AF_INET
)
1438 return (oi
->address
->u
.prefix4
);
1443 #endif /* HAVE_NSSA */
1445 #define DEFAULT_DEFAULT_METRIC 20
1446 #define DEFAULT_DEFAULT_ORIGINATE_METRIC 10
1447 #define DEFAULT_DEFAULT_ALWAYS_METRIC 1
1449 #define DEFAULT_METRIC_TYPE EXTERNAL_METRIC_TYPE_2
1452 metric_type (u_char src
)
1454 return (ospf_top
->dmetric
[src
].type
< 0 ?
1455 DEFAULT_METRIC_TYPE
: ospf_top
->dmetric
[src
].type
);
1459 metric_value (u_char src
)
1461 if (ospf_top
->dmetric
[src
].value
< 0)
1463 if (src
== DEFAULT_ROUTE
)
1465 if (ospf_top
->default_originate
== DEFAULT_ORIGINATE_ZEBRA
)
1466 return DEFAULT_DEFAULT_ORIGINATE_METRIC
;
1468 return DEFAULT_DEFAULT_ALWAYS_METRIC
;
1470 else if (ospf_top
->default_metric
< 0)
1471 return DEFAULT_DEFAULT_METRIC
;
1473 return ospf_top
->default_metric
;
1476 return ospf_top
->dmetric
[src
].value
;
1479 /* Set AS-external-LSA body. */
1481 ospf_external_lsa_body_set (struct stream
*s
, struct external_info
*ei
)
1483 struct prefix_ipv4
*p
= &ei
->p
;
1484 struct in_addr mask
, fwd_addr
;
1489 /* Put Network Mask. */
1490 masklen2ip (p
->prefixlen
, &mask
);
1491 stream_put_ipv4 (s
, mask
.s_addr
);
1493 /* If prefix is default, specify DEFAULT_ROUTE. */
1494 type
= is_prefix_default (&ei
->p
) ? DEFAULT_ROUTE
: ei
->type
;
1496 mtype
= (ROUTEMAP_METRIC_TYPE (ei
) != -1) ?
1497 ROUTEMAP_METRIC_TYPE (ei
) : metric_type (type
);
1499 mvalue
= (ROUTEMAP_METRIC (ei
) != -1) ?
1500 ROUTEMAP_METRIC (ei
) : metric_value (type
);
1502 /* Put type of external metric. */
1503 stream_putc (s
, (mtype
== EXTERNAL_METRIC_TYPE_2
? 0x80 : 0));
1505 /* Put 0 metric. TOS metric is not supported. */
1506 stream_put_ospf_metric (s
, mvalue
);
1508 /* Get forwarding address to nexthop if on the Connection List, else 0. */
1509 fwd_addr
= ospf_external_lsa_nexthop_get (ei
->nexthop
);
1511 /* Put forwarding address. */
1512 stream_put_ipv4 (s
, fwd_addr
.s_addr
);
1514 /* Put route tag -- This value should be introduced from configuration. */
1518 /* Create new external-LSA. */
1520 ospf_external_lsa_new (struct external_info
*ei
, struct in_addr
*old_id
)
1523 struct lsa_header
*lsah
;
1524 struct ospf_lsa
*new;
1530 if (IS_DEBUG_OSPF (lsa
, LSA_GENERATE
))
1531 zlog_warn ("LSA[Type5]: External info is NULL, could not originated");
1535 if (IS_DEBUG_OSPF (lsa
, LSA_GENERATE
))
1536 zlog_info ("LSA[Type5]: Originate AS-external-LSA instance");
1538 /* If old Link State ID is specified, refresh LSA with same ID. */
1541 /* Get Link State with unique ID. */
1544 id
= ospf_lsa_unique_id (ospf_top
->lsdb
, OSPF_AS_EXTERNAL_LSA
, &ei
->p
);
1545 if (id
.s_addr
== 0xffffffff)
1547 /* Maybe Link State ID not available. */
1548 if (IS_DEBUG_OSPF (lsa
, LSA_GENERATE
))
1549 zlog_info ("LSA[Type5]: Link ID not available, can't originate");
1554 /* Create new stream for LSA. */
1555 s
= stream_new (OSPF_MAX_LSA_SIZE
);
1556 lsah
= (struct lsa_header
*) STREAM_DATA (s
);
1558 /* Set LSA common header fields. */
1559 lsa_header_set (s
, OSPF_OPTION_E
, OSPF_AS_EXTERNAL_LSA
, id
);
1561 /* Set AS-external-LSA body fields. */
1562 ospf_external_lsa_body_set (s
, ei
);
1565 length
= stream_get_endp (s
);
1566 lsah
->length
= htons (length
);
1568 /* Now, create OSPF LSA instance. */
1569 new = ospf_lsa_new ();
1571 SET_FLAG (new->flags
, OSPF_LSA_SELF
|OSPF_LSA_APPROVED
);
1573 /* Copy LSA data to store, discard stream. */
1574 new->data
= ospf_lsa_data_new (length
);
1575 memcpy (new->data
, lsah
, length
);
1582 /* Set AS-external-LSA body test. */
1584 ospf_external_lsa_body_test (struct stream
*s
)
1586 struct in_addr mask
, fwd_addr
;
1587 u_int32_t mvalue
= 0;
1592 fwd_addr
.s_addr
= 0;
1594 /* Put Network Mask. */
1595 /* masklen2ip (p->prefixlen, &mask); */
1596 stream_put_ipv4 (s
, mask
.s_addr
);
1598 /* If prefix is default, specify DEFAULT_ROUTE. */
1599 /* type = is_prefix_default (&ei->p) ? DEFAULT_ROUTE : ei->type;
1601 mtype = (ROUTEMAP_METRIC_TYPE (ei) != -1) ?
1602 ROUTEMAP_METRIC_TYPE (ei) : metric_type (type);
1604 mvalue = (ROUTEMAP_METRIC (ei) != -1) ?
1605 ROUTEMAP_METRIC (ei) : metric_value (type); */
1607 /* Put type of external metric. */
1610 /* Put 0 metric. TOS metric is not supported. */
1611 stream_put_ospf_metric (s
, mvalue
);
1614 /* fwd_addr = ospf_top->router_id; */
1616 /* OLD == ospf_external_lsa_nexthop_get (ei->nexthop); */
1618 /* Put forwarding address. */
1619 /* stream_put_ipv4 (s, fwd_addr.s_addr); */
1620 stream_put_ipv4 (s
, ospf_top
->router_id
.s_addr
);
1622 /* Put route tag -- This value should be introduced from configuration. */
1628 ospf_install_flood_nssa (struct ospf_lsa
*lsa
, struct external_info
*ei
)
1630 struct ospf_lsa
*new2
;
1631 struct as_external_lsa
*extlsa
;
1633 /* NSSA Originate or Refresh (If anyNSSA)
1635 LSA is self-originated. And just installed as Type-5.
1636 Additionally, install as Type-7 LSDB for every attached NSSA.
1638 P-Bit controls which ABR performs translation to outside world; If
1639 we are an ABR....do not set the P-bit, because we send the Type-5,
1640 not as the ABR Translator, but as the ASBR owner within the AS!
1642 If we are NOT ABR, Flood through NSSA as Type-7 w/P-bit set. The
1643 elected ABR Translator will see the P-bit, Translate, and re-flood.
1645 Later, ABR_TASK and P-bit will scan Type-7 LSDB and translate to
1646 Type-5's to non-NSSA Areas. (it will also attempt a re-install) */
1648 /* make lsa duplicate, lock=1 */
1649 new2
= ospf_lsa_dup(lsa
);
1652 new2
->data
->type
= OSPF_AS_NSSA_LSA
;
1654 /* set P-bit if not ABR */
1657 SET_FLAG(new2
->data
->options
, OSPF_OPTION_NP
);
1659 /* set non-zero FWD ADDR
1661 draft-ietf-ospf-nssa-update-09.txt
1663 if the network between the NSSA AS boundary router and the
1664 adjacent AS is advertised into OSPF as an internal OSPF route,
1665 the forwarding address should be the next op address as is cu
1666 currently done with type-5 LSAs. If the intervening network is
1667 not adversited into OSPF as an internal OSPF route and the
1668 type-7 LSA's P-bit is set a forwarding address should be
1669 selected from one of the router's active OSPF inteface addresses
1670 which belong to the NSSA. If no such addresses exist, then
1671 no type-7 LSA's with the P-bit set should originate from this
1674 extlsa
= (struct as_external_lsa
*)(lsa
->data
);
1676 if (extlsa
->e
[0].fwd_addr
.s_addr
== 0)
1677 extlsa
->e
[0].fwd_addr
= ospf_get_nssa_ip(); /* this NSSA area in ifp */
1679 if (IS_DEBUG_OSPF_NSSA
)
1680 if (extlsa
->e
[0].fwd_addr
.s_addr
== 0)
1682 zlog_info ("LSA[Type-7]: Could not build FWD-ADDR");
1683 ospf_lsa_discard(new2
);
1688 /* Re-calculate checksum. */
1689 ospf_lsa_checksum (new2
->data
);
1691 /* install also as Type-7 */
1692 ospf_lsa_install (NULL
, new2
); /* Remove Old, Lock New = 2 */
1694 /* will send each copy, lock=2+n */
1695 ospf_flood_through_as (NULL
, new2
); /* all attached NSSA's, no AS/STUBs */
1697 /* last send, lock=2 LSA is now permanent in Type-7 LSDB */
1698 /* It has the same ID as it's Type-5 Counter-Part */
1701 #endif /* HAVE_NSSA */
1704 is_prefix_default (struct prefix_ipv4
*p
)
1706 struct prefix_ipv4 q
;
1709 q
.prefix
.s_addr
= 0;
1712 return prefix_same ((struct prefix
*) p
, (struct prefix
*) &q
);
1715 /* Originate an AS-external-LSA, install and flood. */
1717 ospf_external_lsa_originate (struct external_info
*ei
)
1719 struct ospf_lsa
*new;
1721 /* Added for NSSA project....
1723 External LSAs are originated in ASBRs as usual, but for NSSA systems.
1724 there is the global Type-5 LSDB and a Type-7 LSDB installed for
1725 every area. The Type-7's are flooded to every IR and every ABR; We
1726 install the Type-5 LSDB so that the normal "refresh" code operates
1727 as usual, and flag them as not used during ASE calculations. The
1728 Type-7 LSDB is used for calculations. Each Type-7 has a Forwarding
1729 Address of non-zero.
1731 If an ABR is the elected NSSA translator, following SPF and during
1732 the ABR task it will translate all the scanned Type-7's, with P-bit
1733 ON and not-self generated, and translate to Type-5's throughout the
1736 A difference in operation depends whether this ASBR is an ABR
1737 or not. If not an ABR, the P-bit is ON, to indicate that any
1738 elected NSSA-ABR can perform its translation.
1740 If an ABR, the P-bit is OFF; No ABR will perform translation and
1741 this ASBR will flood the Type-5 LSA as usual.
1743 For the case where this ASBR is not an ABR, the ASE calculations
1744 are based on the Type-5 LSDB; The Type-7 LSDB exists just to
1745 demonstrate to the user that there are LSA's that belong to any
1748 Finally, it just so happens that when the ABR is translating every
1749 Type-7 into Type-5, it installs it into the Type-5 LSDB as an
1750 approved Type-5 (translated from Type-7); at the end of translation
1751 if any Translated Type-5's remain unapproved, then they must be
1752 flushed from the AS.
1756 /* Check the AS-external-LSA should be originated. */
1757 if (!ospf_redistribute_check (ei
, NULL
))
1760 /* Create new AS-external-LSA instance. */
1761 if ((new = ospf_external_lsa_new (ei
, NULL
)) == NULL
)
1763 if (IS_DEBUG_OSPF_EVENT
)
1764 zlog_info ("LSA[Type5:%s]: Could not originate AS-external-LSA",
1765 inet_ntoa (ei
->p
.prefix
));
1769 /* Install newly created LSA into Type-5 LSDB, lock = 1. */
1770 ospf_lsa_install (NULL
, new);
1772 /* Update LSA origination count. */
1773 ospf_top
->lsa_originate_count
++;
1775 /* Flooding new LSA. only to AS (non-NSSA/STUB) */
1776 ospf_flood_through_as (NULL
, new);
1779 /* If there is any attached NSSA, do special handling */
1780 if (ospf_top
->anyNSSA
)
1781 ospf_install_flood_nssa (new, ei
); /* Install/Flood Type-7 to all NSSAs */
1782 #endif /* HAVE_NSSA */
1784 /* Debug logging. */
1785 if (IS_DEBUG_OSPF (lsa
, LSA_GENERATE
))
1787 zlog_info ("LSA[Type%d:%s]: Originate AS-external-LSA %p",
1788 new->data
->type
, inet_ntoa (new->data
->id
), new);
1789 ospf_lsa_header_dump (new->data
);
1795 /* Originate AS-external-LSA from external info with initial flag. */
1797 ospf_external_lsa_originate_timer (struct thread
*t
)
1799 struct route_node
*rn
;
1800 struct external_info
*ei
;
1801 struct route_table
*rt
;
1804 ospf_top
->t_external_lsa
= NULL
;
1805 type
= THREAD_VAL (t
);
1807 /* Originate As-external-LSA from all type of distribute source. */
1808 if ((rt
= EXTERNAL_INFO (type
)))
1809 for (rn
= route_top (rt
); rn
; rn
= route_next (rn
))
1810 if ((ei
= rn
->info
) != NULL
)
1811 if (!is_prefix_default ((struct prefix_ipv4
*)&ei
->p
))
1812 if (!ospf_external_lsa_originate (ei
))
1813 zlog_warn ("LSA: AS-external-LSA was not originated.");
1818 struct external_info
*
1819 ospf_default_external_info ()
1822 struct route_node
*rn
;
1823 struct prefix_ipv4 p
;
1826 p
.prefix
.s_addr
= 0;
1829 /* First, lookup redistributed default route. */
1830 for (type
= 0; type
<= ZEBRA_ROUTE_MAX
; type
++)
1831 if (EXTERNAL_INFO (type
) && type
!= ZEBRA_ROUTE_OSPF
)
1833 rn
= route_node_lookup (EXTERNAL_INFO (type
), (struct prefix
*) &p
);
1836 route_unlock_node (rn
);
1838 if (ospf_redistribute_check (rn
->info
, NULL
))
1847 ospf_default_originate_timer (struct thread
*t
)
1850 struct prefix_ipv4 p
;
1851 struct in_addr nexthop
;
1852 struct external_info
*ei
;
1854 /* Get originate flags. */
1855 origin
= THREAD_ARG (t
);
1858 p
.prefix
.s_addr
= 0;
1861 if (*origin
== DEFAULT_ORIGINATE_ALWAYS
)
1863 /* If there is no default route via redistribute,
1864 then originate AS-external-LSA with nexthop 0 (self). */
1866 ospf_external_info_add (DEFAULT_ROUTE
, p
, 0, nexthop
);
1869 if ((ei
= ospf_default_external_info ()))
1870 ospf_external_lsa_originate (ei
);
1875 /* Flush an AS-external-LSA from LSDB and routing domain. */
1877 ospf_external_lsa_flush (u_char type
, struct prefix_ipv4
*p
,
1878 unsigned int ifindex
, struct in_addr nexthop
)
1880 struct ospf_lsa
*lsa
;
1882 if (IS_DEBUG_OSPF (lsa
, LSA_FLOODING
))
1883 zlog_info ("LSA: Flushing AS-external-LSA %s/%d",
1884 inet_ntoa (p
->prefix
), p
->prefixlen
);
1886 /* First lookup LSA from LSDB. */
1887 if (!(lsa
= ospf_external_info_find_lsa (p
)))
1889 if (IS_DEBUG_OSPF (lsa
, LSA_FLOODING
))
1890 zlog_warn ("LSA: There is no such AS-external-LSA %s/%d in LSDB",
1891 inet_ntoa (p
->prefix
), p
->prefixlen
);
1895 /* Sweep LSA from Link State Retransmit List. */
1896 ospf_ls_retransmit_delete_nbr_all (NULL
, lsa
);
1898 /* There must be no self-originated LSA in rtrs_external. */
1900 /* Remove External route from Zebra. */
1901 ospf_zebra_delete ((struct prefix_ipv4
*) p
, &nexthop
);
1904 if (!IS_LSA_MAXAGE (lsa
))
1906 /* Unregister LSA from Refresh queue. */
1907 ospf_refresher_unregister_lsa (ospf_top
, lsa
);
1909 /* Flush AS-external-LSA through AS. */
1910 ospf_flush_through_as (lsa
);
1913 if (IS_DEBUG_OSPF (lsa
, LSA_FLOODING
))
1914 zlog_info ("ospf_external_lsa_flush(): stop");
1918 ospf_external_lsa_refresh_default ()
1920 struct prefix_ipv4 p
;
1921 struct external_info
*ei
;
1922 struct ospf_lsa
*lsa
;
1926 p
.prefix
.s_addr
= 0;
1928 ei
= ospf_default_external_info ();
1929 lsa
= ospf_external_info_find_lsa (&p
);
1935 if (IS_DEBUG_OSPF_EVENT
)
1936 zlog_info ("LSA[Type5:0.0.0.0]: Refresh AS-external-LSA %p", lsa
);
1937 ospf_external_lsa_refresh (lsa
, ei
, LSA_REFRESH_FORCE
);
1941 if (IS_DEBUG_OSPF_EVENT
)
1942 zlog_info ("LSA[Type5:0.0.0.0]: Originate AS-external-LSA");
1943 ospf_external_lsa_originate (ei
);
1950 if (IS_DEBUG_OSPF_EVENT
)
1951 zlog_info ("LSA[Type5:0.0.0.0]: Flush AS-external-LSA");
1952 ospf_lsa_flush_as (lsa
);
1958 ospf_external_lsa_refresh_type (u_char type
, int force
)
1960 struct route_node
*rn
;
1961 struct external_info
*ei
;
1963 if (type
!= DEFAULT_ROUTE
)
1964 if (EXTERNAL_INFO(type
))
1965 /* Refresh each redistributed AS-external-LSAs. */
1966 for (rn
= route_top (EXTERNAL_INFO (type
)); rn
; rn
= route_next (rn
))
1967 if ((ei
= rn
->info
))
1968 if (!is_prefix_default (&ei
->p
))
1970 struct ospf_lsa
*lsa
;
1972 if ((lsa
= ospf_external_info_find_lsa (&ei
->p
)))
1973 ospf_external_lsa_refresh (lsa
, ei
, force
);
1975 ospf_external_lsa_originate (ei
);
1979 /* Refresh AS-external-LSA. */
1981 ospf_external_lsa_refresh (struct ospf_lsa
*lsa
,
1982 struct external_info
*ei
, int force
)
1984 struct ospf_lsa
*new;
1987 /* Check the AS-external-LSA should be originated. */
1988 if (!ospf_redistribute_check (ei
, &changed
))
1990 ospf_external_lsa_flush (ei
->type
, &ei
->p
, ei
->ifindex
, ei
->nexthop
);
1994 if (!changed
&& !force
)
1997 /* Delete LSA from neighbor retransmit-list. */
1998 ospf_ls_retransmit_delete_nbr_all (NULL
, lsa
);
2000 /* Unregister AS-external-LSA from refresh-list. */
2001 ospf_refresher_unregister_lsa (ospf_top
, lsa
);
2003 new = ospf_external_lsa_new (ei
, &lsa
->data
->id
);
2007 if (IS_DEBUG_OSPF (lsa
, LSA_GENERATE
))
2008 zlog_warn ("LSA[Type%d:%s]: Could not be refreshed", lsa
->data
->type
,
2009 inet_ntoa (lsa
->data
->id
));
2013 new->data
->ls_seqnum
= lsa_seqnum_increment (lsa
);
2015 /* Record timestamp. */
2016 gettimeofday (&new->tv_orig
, NULL
);
2018 /* Re-calculate checksum. */
2019 ospf_lsa_checksum (new->data
);
2021 ospf_lsa_install (NULL
, new); /* As type-5. */
2023 /* Flood LSA through AS. */
2024 ospf_flood_through_as (NULL
, new);
2027 /* If any attached NSSA, install as Type-7, flood to all NSSA Areas */
2028 if (ospf_top
->anyNSSA
)
2029 ospf_install_flood_nssa (new, ei
); /* Install/Flood per new rules */
2030 #endif /* HAVE_NSSA */
2032 /* Register slef-originated LSA to refresh queue. */
2033 ospf_refresher_register_lsa (ospf_top
, new);
2035 /* Debug logging. */
2036 if (IS_DEBUG_OSPF (lsa
, LSA_GENERATE
))
2038 zlog_info ("LSA[Type%d:%s]: AS-external-LSA refresh",
2039 new->data
->type
, inet_ntoa (new->data
->id
));
2040 ospf_lsa_header_dump (new->data
);
2047 /* LSA installation functions. */
2049 /* Install router-LSA to an area. */
2051 ospf_router_lsa_install (struct ospf_lsa
*new, int rt_recalc
)
2053 struct ospf_area
*area
= new->area
;
2055 /* RFC 2328 Section 13.2 Router-LSAs and network-LSAs
2056 The entire routing table must be recalculated, starting with
2057 the shortest path calculations for each area (not just the
2058 area whose link-state database has changed).
2061 ospf_spf_calculate_schedule();
2063 if (IS_LSA_SELF (new))
2065 /* Set router-LSA refresh timer. */
2066 OSPF_TIMER_OFF (area
->t_router_lsa_self
);
2067 OSPF_AREA_TIMER_ON (area
->t_router_lsa_self
,
2068 ospf_router_lsa_timer
, OSPF_LS_REFRESH_TIME
);
2070 /* Set self-originated router-LSA. */
2071 ospf_lsa_unlock (area
->router_lsa_self
);
2072 area
->router_lsa_self
= ospf_lsa_lock (new);
2074 if (IS_DEBUG_OSPF (lsa
, LSA_INSTALL
))
2075 zlog_info("LSA[Type%d]: ID %s is self-originated",
2076 new->data
->type
, inet_ntoa (new->data
->id
));
2082 #define OSPF_INTERFACE_TIMER_ON(T,F,V) \
2084 (T) = thread_add_timer (master, (F), oi, (V))
2086 /* Install network-LSA to an area. */
2088 ospf_network_lsa_install (struct ospf_interface
*oi
,
2089 struct ospf_lsa
*new,
2093 /* RFC 2328 Section 13.2 Router-LSAs and network-LSAs
2094 The entire routing table must be recalculated, starting with
2095 the shortest path calculations for each area (not just the
2096 area whose link-state database has changed).
2099 ospf_spf_calculate_schedule();
2101 /* We supposed that when LSA is originated by us, we pass the int
2102 for which it was originated. If LSA was received by flooding,
2103 the RECEIVED flag is set, so we do not link the LSA to the int. */
2104 if (IS_LSA_SELF (new) && !CHECK_FLAG (new->flags
, OSPF_LSA_RECEIVED
))
2106 /* Set LSRefresh timer. */
2107 OSPF_TIMER_OFF (oi
->t_network_lsa_self
);
2109 OSPF_INTERFACE_TIMER_ON (oi
->t_network_lsa_self
,
2110 ospf_network_lsa_refresh_timer
,
2111 OSPF_LS_REFRESH_TIME
);
2113 ospf_lsa_unlock (oi
->network_lsa_self
);
2114 oi
->network_lsa_self
= ospf_lsa_lock (new);
2120 /* Install summary-LSA to an area. */
2122 ospf_summary_lsa_install (struct ospf_lsa
*new, int rt_recalc
)
2125 if (rt_recalc
&& !IS_LSA_SELF (new))
2127 /* RFC 2328 Section 13.2 Summary-LSAs
2128 The best route to the destination described by the summary-
2129 LSA must be recalculated (see Section 16.5). If this
2130 destination is an AS boundary router, it may also be
2131 necessary to re-examine all the AS-external-LSAs.
2135 /* This doesn't exist yet... */
2136 ospf_summary_incremental_update(new); */
2138 ospf_spf_calculate_schedule();
2141 if (IS_DEBUG_OSPF (lsa
, LSA_INSTALL
))
2142 zlog_info ("ospf_summary_lsa_install(): SPF scheduled");
2145 if (IS_LSA_SELF (new))
2146 ospf_refresher_register_lsa (ospf_top
, new);
2151 /* Install ASBR-summary-LSA to an area. */
2153 ospf_summary_asbr_lsa_install (struct ospf_lsa
*new, int rt_recalc
)
2155 if (rt_recalc
&& !IS_LSA_SELF (new))
2157 /* RFC 2328 Section 13.2 Summary-LSAs
2158 The best route to the destination described by the summary-
2159 LSA must be recalculated (see Section 16.5). If this
2160 destination is an AS boundary router, it may also be
2161 necessary to re-examine all the AS-external-LSAs.
2164 /* These don't exist yet... */
2165 ospf_summary_incremental_update(new);
2166 /* Isn't this done by the above call?
2167 - RFC 2328 Section 16.5 implies it should be */
2168 /* ospf_ase_calculate_schedule(); */
2170 ospf_spf_calculate_schedule();
2174 /* register LSA to refresh-list. */
2175 if (IS_LSA_SELF (new))
2176 ospf_refresher_register_lsa (ospf_top
, new);
2181 /* Install AS-external-LSA. */
2183 ospf_external_lsa_install (struct ospf_lsa
*new, int rt_recalc
)
2185 ospf_ase_register_external_lsa (new, ospf_top
);
2186 /* If LSA is not self-originated, calculate an external route. */
2189 /* RFC 2328 Section 13.2 AS-external-LSAs
2190 The best route to the destination described by the AS-
2191 external-LSA must be recalculated (see Section 16.6).
2194 if (!IS_LSA_SELF (new))
2195 ospf_ase_incremental_update (new, ospf_top
);
2198 /* Register self-originated LSA to refresh queue. */
2199 if (IS_LSA_SELF (new))
2200 ospf_refresher_register_lsa (ospf_top
, new);
2206 ospf_discard_from_db (struct ospf_lsdb
*lsdb
, struct ospf_lsa
*lsa
)
2208 struct ospf_lsa
*old
;
2210 old
= ospf_lsdb_lookup (lsdb
, lsa
);
2215 if (old
->refresh_list
>= 0)
2216 ospf_refresher_unregister_lsa (ospf_top
, old
);
2218 ospf_ls_retransmit_delete_nbr_all (old
->area
, old
);
2220 switch (old
->data
->type
)
2222 case OSPF_AS_EXTERNAL_LSA
:
2223 #ifdef HAVE_OPAQUE_LSA
2224 case OSPF_OPAQUE_AS_LSA
:
2225 #endif /* HAVE_OPAQUE_LSA */
2226 ospf_ase_unregister_external_lsa (old
, ospf_top
);
2232 ospf_lsa_maxage_delete (old
);
2233 ospf_lsa_discard (old
);
2236 /* callback for foreach_lsa */
2238 ospf_lsa_discard_callback (struct ospf_lsa
*lsa
, void *p
, int i
)
2241 /* Removed: Stay away from any Local Translated Type-7 LSAs */
2242 /* if (CHECK_FLAG (lsa->flags, OSPF_LSA_LOCAL_XLT))
2244 #endif /* HAVE_NSSA */
2245 ospf_discard_from_db ((struct ospf_lsdb
*)p
, lsa
);
2250 ospf_lsa_install (struct ospf_interface
*oi
, struct ospf_lsa
*lsa
)
2252 struct ospf_lsa
*new = NULL
;
2253 struct ospf_lsa
*old
= NULL
;
2254 struct ospf_lsdb
*lsdb
= NULL
;
2258 switch (lsa
->data
->type
)
2260 case OSPF_AS_EXTERNAL_LSA
:
2261 #ifdef HAVE_OPAQUE_LSA
2262 case OSPF_OPAQUE_AS_LSA
:
2263 #endif /* HAVE_OPAQUE_LSA */
2264 lsdb
= ospf_top
->lsdb
;
2267 lsdb
= lsa
->area
->lsdb
;
2272 if (IS_DEBUG_OSPF_NSSA
)
2274 zlog_info ("LSA[Installing]: Type-%d ", lsa
->data
->type
);
2276 if (lsa
->data
->type
== OSPF_AS_NSSA_LSA
)
2277 zlog_info ("NSSA LSA AREA = %s", inet_ntoa (lsa
->area
->area_id
));
2279 #endif /* HAVE_NSSA */
2283 /* RFC 2328 13.2. Installing LSAs in the database
2285 Installing a new LSA in the database, either as the result of
2286 flooding or a newly self-originated LSA, may cause the OSPF
2287 routing table structure to be recalculated. The contents of the
2288 new LSA should be compared to the old instance, if present. If
2289 there is no difference, there is no need to recalculate the
2290 routing table. When comparing an LSA to its previous instance,
2291 the following are all considered to be differences in contents:
2293 o The LSA's Options field has changed.
2295 o One of the LSA instances has LS age set to MaxAge, and
2298 o The length field in the LSA header has changed.
2300 o The body of the LSA (i.e., anything outside the 20-byte
2301 LSA header) has changed. Note that this excludes changes
2302 in LS Sequence Number and LS Checksum.
2305 /* Look up old LSA and determine if any SPF calculation or incremental
2307 old
= ospf_lsdb_lookup (lsdb
, lsa
);
2309 /* Do comparision and record if recalc needed. */
2311 if ( old
== NULL
|| ospf_lsa_different(old
, lsa
))
2314 /* discard old LSA from LSDB */
2316 ospf_discard_from_db (lsdb
, lsa
);
2318 /* Insert LSA to LSDB. */
2319 ospf_lsdb_add (lsdb
, lsa
);
2322 /* Calculate Checksum if self-originated?. */
2323 if (IS_LSA_SELF (lsa
))
2324 ospf_lsa_checksum (lsa
->data
);
2326 /* Do LSA specific installation process. */
2327 switch (lsa
->data
->type
)
2329 case OSPF_ROUTER_LSA
:
2330 new = ospf_router_lsa_install (lsa
, rt_recalc
);
2332 case OSPF_NETWORK_LSA
:
2334 new = ospf_network_lsa_install (oi
, lsa
, rt_recalc
);
2336 case OSPF_SUMMARY_LSA
:
2337 new = ospf_summary_lsa_install (lsa
, rt_recalc
);
2339 case OSPF_ASBR_SUMMARY_LSA
:
2340 new = ospf_summary_asbr_lsa_install (lsa
, rt_recalc
);
2342 case OSPF_AS_EXTERNAL_LSA
:
2343 new = ospf_external_lsa_install (lsa
, rt_recalc
);
2345 #ifdef HAVE_OPAQUE_LSA
2346 case OSPF_OPAQUE_LINK_LSA
:
2347 case OSPF_OPAQUE_AREA_LSA
:
2348 case OSPF_OPAQUE_AS_LSA
:
2349 new = ospf_opaque_lsa_install (lsa
, rt_recalc
);
2351 #endif /* HAVE_OPAQUE_LSA */
2352 default: /* NSSA, or type-6,8,9....nothing special */
2354 new = ospf_external_lsa_install (lsa
, rt_recalc
);
2355 #endif /* HAVE_NSSA */
2360 return new; /* Installation failed, cannot proceed further -- endo. */
2363 if (IS_DEBUG_OSPF (lsa
, LSA_INSTALL
))
2365 char area_str
[INET_ADDRSTRLEN
];
2367 switch (lsa
->data
->type
)
2369 case OSPF_AS_EXTERNAL_LSA
:
2370 #ifdef HAVE_OPAQUE_LSA
2371 case OSPF_OPAQUE_AS_LSA
:
2372 #endif /* HAVE_OPAQUE_LSA */
2373 zlog_info ("LSA[%s]: Install %s",
2375 LOOKUP (ospf_lsa_type_msg
, new->data
->type
));
2378 strcpy (area_str
, inet_ntoa (new->area
->area_id
));
2379 zlog_info ("LSA[%s]: Install %s to Area %s",
2381 LOOKUP (ospf_lsa_type_msg
, new->data
->type
), area_str
);
2386 /* If received LSA' ls_age is MaxAge, set LSA on MaxAge LSA list. */
2387 if (IS_LSA_MAXAGE (new) && !IS_LSA_SELF (new))
2389 if (IS_DEBUG_OSPF (lsa
, LSA_FLOODING
))
2390 zlog_info ("LSA[Type%d:%s]: Install LSA, MaxAge",
2391 new->data
->type
, inet_ntoa (new->data
->id
));
2392 ospf_lsa_maxage (lsa
);
2400 ospf_check_nbr_status ()
2404 for (node
= listhead (ospf_top
->oiflist
); node
; node
= nextnode (node
))
2406 struct ospf_interface
*oi
= getdata (node
);
2407 struct route_node
*rn
;
2408 struct ospf_neighbor
*nbr
;
2410 if (ospf_if_is_enable (oi
))
2411 for (rn
= route_top (oi
->nbrs
); rn
; rn
= route_next (rn
))
2412 if ((nbr
= rn
->info
) != NULL
)
2413 if (nbr
->state
== NSM_Exchange
|| nbr
->state
== NSM_Loading
)
2415 route_unlock_node (rn
);
2424 #ifdef ORIGINAL_CODING
2425 /* This function flood the maxaged LSA to DR. */
2427 ospf_maxage_flood (struct ospf_lsa
*lsa
)
2429 switch (lsa
->data
->type
)
2431 case OSPF_ROUTER_LSA
:
2432 case OSPF_NETWORK_LSA
:
2433 case OSPF_SUMMARY_LSA
:
2434 case OSPF_ASBR_SUMMARY_LSA
:
2436 case OSPF_AS_NSSA_LSA
:
2437 #endif /* HAVE_NSSA */
2438 #ifdef HAVE_OPAQUE_LSA
2439 case OSPF_OPAQUE_LINK_LSA
:
2440 case OSPF_OPAQUE_AREA_LSA
:
2441 #endif /* HAVE_OPAQUE_LSA */
2442 ospf_flood_through_area (lsa
->area
, NULL
, lsa
);
2444 case OSPF_AS_EXTERNAL_LSA
:
2445 #ifdef HAVE_OPAQUE_LSA
2446 case OSPF_OPAQUE_AS_LSA
:
2447 #endif /* HAVE_OPAQUE_LSA */
2448 ospf_flood_through_as (NULL
, lsa
);
2454 #endif /* ORIGINAL_CODING */
2457 ospf_maxage_lsa_remover (struct thread
*thread
)
2463 ospf_top
->t_maxage
= NULL
;
2465 if (IS_DEBUG_OSPF (lsa
, LSA_FLOODING
))
2466 zlog_info ("LSA[MaxAge]: remover Start");
2468 reschedule
= !ospf_check_nbr_status ();
2471 for (node
= listhead (ospf_top
->maxage_lsa
); node
; node
= next
)
2473 struct ospf_lsa
*lsa
= getdata (node
);
2476 if (lsa
->retransmit_counter
> 0)
2482 /* Remove LSA from the LSDB */
2483 if (CHECK_FLAG (lsa
->flags
, OSPF_LSA_SELF
))
2484 if (IS_DEBUG_OSPF (lsa
, LSA_FLOODING
))
2485 zlog_info ("LSA[Type%d:%s]: This LSA is self-originated: ",
2486 lsa
->data
->type
, inet_ntoa (lsa
->data
->id
));
2488 if (IS_DEBUG_OSPF (lsa
, LSA_FLOODING
))
2489 zlog_info ("LSA[Type%d:%s]: MaxAge LSA removed from list",
2490 lsa
->data
->type
, inet_ntoa (lsa
->data
->id
));
2492 /* Flood max age LSA. */
2493 #ifdef ORIGINAL_CODING
2494 ospf_maxage_flood (lsa
);
2495 #else /* ORIGINAL_CODING */
2496 ospf_flood_through (NULL
, lsa
);
2497 #endif /* ORIGINAL_CODING */
2499 /* Remove from lsdb. */
2500 ospf_discard_from_db (lsa
->lsdb
, lsa
);
2501 ospf_lsdb_delete (lsa
->lsdb
, lsa
);
2504 /* A MaxAge LSA must be removed immediately from the router's link
2505 state database as soon as both a) it is no longer contained on any
2506 neighbor Link state retransmission lists and b) none of the router's
2507 neighbors are in states Exchange or Loading. */
2509 OSPF_SCHEDULE_MAXAGE (ospf_top
->t_maxage
, ospf_maxage_lsa_remover
);
2515 ospf_lsa_maxage_exist (struct ospf_lsa
*new)
2519 for (node
= listhead (ospf_top
->maxage_lsa
); node
; nextnode (node
))
2520 if (((struct ospf_lsa
*) node
->data
) == new)
2527 ospf_lsa_maxage_delete (struct ospf_lsa
*lsa
)
2531 if ((n
= listnode_lookup (ospf_top
->maxage_lsa
, lsa
)))
2533 list_delete_node (ospf_top
->maxage_lsa
, n
);
2534 ospf_lsa_unlock (lsa
);
2539 ospf_lsa_maxage (struct ospf_lsa
*lsa
)
2541 /* When we saw a MaxAge LSA flooded to us, we put it on the list
2542 and schedule the MaxAge LSA remover. */
2543 if (ospf_lsa_maxage_exist (lsa
))
2545 if (IS_DEBUG_OSPF (lsa
, LSA_FLOODING
))
2546 zlog_info ("LSA[Type%d:%s]: %p already exists on MaxAge LSA list",
2547 lsa
->data
->type
, inet_ntoa (lsa
->data
->id
), lsa
);
2551 listnode_add (ospf_top
->maxage_lsa
, ospf_lsa_lock (lsa
));
2553 if (IS_DEBUG_OSPF (lsa
, LSA_FLOODING
))
2554 zlog_info ("LSA[%s]: MaxAge LSA remover scheduled.", dump_lsa_key (lsa
));
2556 OSPF_SCHEDULE_MAXAGE (ospf_top
->t_maxage
, ospf_maxage_lsa_remover
);
2560 ospf_lsa_maxage_walker_remover (struct ospf_lsa
*lsa
, void *p_arg
, int int_arg
)
2563 /* Stay away from any Local Translated Type-7 LSAs */
2564 if (CHECK_FLAG (lsa
->flags
, OSPF_LSA_LOCAL_XLT
))
2566 #endif /* HAVE_NSSA */
2568 if (IS_LSA_MAXAGE (lsa
))
2569 /* Self-originated LSAs should NOT time-out instead,
2570 they're flushed and submitted to the max_age list explicitly. */
2571 if (!ospf_lsa_is_self_originated (lsa
))
2573 if (IS_DEBUG_OSPF (lsa
, LSA_FLOODING
))
2574 zlog_info("LSA[%s]: is MaxAge", dump_lsa_key (lsa
));
2576 switch (lsa
->data
->type
)
2578 case OSPF_AS_EXTERNAL_LSA
:
2579 #ifdef HAVE_OPAQUE_LSA
2580 case OSPF_OPAQUE_AS_LSA
:
2581 #endif /* HAVE_OPAQUE_LSA */
2582 ospf_ase_incremental_update (lsa
, ospf_top
);
2585 ospf_spf_calculate_schedule ();
2589 ospf_lsa_maxage (lsa
);
2595 /* Periodical check of MaxAge LSA. */
2597 ospf_lsa_maxage_walker (struct thread
*t
)
2601 ospf_top
->t_maxage_walker
= NULL
;
2603 for (node
= listhead (ospf_top
->areas
); node
; nextnode (node
))
2605 struct ospf_area
*area
= node
->data
;
2607 foreach_lsa (ROUTER_LSDB (area
), NULL
, 0,
2608 ospf_lsa_maxage_walker_remover
);
2609 foreach_lsa (NETWORK_LSDB (area
), NULL
, 0,
2610 ospf_lsa_maxage_walker_remover
);
2611 foreach_lsa (SUMMARY_LSDB (area
), NULL
, 0,
2612 ospf_lsa_maxage_walker_remover
);
2613 foreach_lsa (ASBR_SUMMARY_LSDB (area
), NULL
, 0,
2614 ospf_lsa_maxage_walker_remover
);
2615 #ifdef HAVE_OPAQUE_LSA
2616 foreach_lsa (OPAQUE_LINK_LSDB (area
), NULL
, 0,
2617 ospf_lsa_maxage_walker_remover
);
2618 foreach_lsa (OPAQUE_AREA_LSDB (area
), NULL
, 0,
2619 ospf_lsa_maxage_walker_remover
);
2620 #endif /* HAVE_OPAQUE_LSA */
2623 /* for AS-eternal-LSAs. */
2625 foreach_lsa (EXTERNAL_LSDB (ospf_top
), NULL
, 0,
2626 ospf_lsa_maxage_walker_remover
);
2628 #ifdef HAVE_OPAQUE_LSA
2630 foreach_lsa (OPAQUE_AS_LSDB (ospf_top
), NULL
, 0,
2631 ospf_lsa_maxage_walker_remover
);
2632 #endif /* HAVE_OPAQUE_LSA */
2634 ospf_top
->t_maxage_walker
=
2635 thread_add_timer (master
, ospf_lsa_maxage_walker
, NULL
,
2636 OSPF_LSA_MAXAGE_CHECK_INTERVAL
);
2641 find_summary (struct ospf_lsa
*lsa
, void * v
, int i
)
2643 struct prefix_ipv4
*p
, pr
;
2645 if ((p
= (struct prefix_ipv4
*) v
) != NULL
)
2647 /* We're looking for self-originated one */
2648 if (ospf_lsa_is_self_originated (lsa
))
2650 struct summary_lsa
*sl
= (struct summary_lsa
*) lsa
->data
;
2652 pr
.family
= AF_INET
;
2653 pr
.prefix
= sl
->header
.id
;
2654 pr
.prefixlen
= ip_masklen (sl
->mask
);
2655 apply_mask_ipv4 (&pr
);
2657 if (prefix_same ((struct prefix
*) &pr
, (struct prefix
*) p
))
2665 find_asbr_summary (struct ospf_lsa
*lsa
, void * v
, int i
)
2667 struct prefix_ipv4
*p
;
2669 if ((p
= (struct prefix_ipv4
*) v
) != NULL
)
2671 /* We're looking for self-originated one */
2672 if (ospf_lsa_is_self_originated (lsa
))
2674 struct summary_lsa
*sl
= (struct summary_lsa
*) lsa
->data
;
2676 if (IPV4_ADDR_SAME (&p
->prefix
, &sl
->header
.id
))
2684 ospf_lsa_lookup (struct ospf_area
*area
, u_int32_t type
,
2685 struct in_addr id
, struct in_addr adv_router
)
2689 case OSPF_ROUTER_LSA
:
2690 case OSPF_NETWORK_LSA
:
2691 case OSPF_SUMMARY_LSA
:
2692 case OSPF_ASBR_SUMMARY_LSA
:
2694 case OSPF_AS_NSSA_LSA
:
2695 #endif /* HAVE_NSSA */
2696 #ifdef HAVE_OPAQUE_LSA
2697 case OSPF_OPAQUE_LINK_LSA
:
2698 case OSPF_OPAQUE_AREA_LSA
:
2699 #endif /* HAVE_OPAQUE_LSA */
2700 return ospf_lsdb_lookup_by_id (area
->lsdb
, type
, id
, adv_router
);
2702 case OSPF_AS_EXTERNAL_LSA
:
2703 #ifdef HAVE_OPAQUE_LSA
2704 case OSPF_OPAQUE_AS_LSA
:
2705 #endif /* HAVE_OPAQUE_LSA */
2706 return ospf_lsdb_lookup_by_id (ospf_top
->lsdb
, type
, id
, adv_router
);
2716 ospf_lsa_lookup_by_id (struct ospf_area
*area
, u_int32_t type
,
2719 struct ospf_lsa
*lsa
;
2720 struct route_node
*rn
;
2724 case OSPF_ROUTER_LSA
:
2725 return ospf_lsdb_lookup_by_id (area
->lsdb
, type
, id
, id
);
2727 case OSPF_NETWORK_LSA
:
2728 for (rn
= route_top (NETWORK_LSDB (area
)); rn
; rn
= route_next (rn
))
2729 if ((lsa
= rn
->info
))
2730 if (IPV4_ADDR_SAME (&lsa
->data
->id
, &id
))
2732 route_unlock_node (rn
);
2736 case OSPF_SUMMARY_LSA
:
2737 case OSPF_ASBR_SUMMARY_LSA
:
2738 /* Currently not used. */
2740 return ospf_lsdb_lookup_by_id (area
->lsdb
, type
, id
, id
);
2742 case OSPF_AS_EXTERNAL_LSA
:
2743 #ifdef HAVE_OPAQUE_LSA
2744 case OSPF_OPAQUE_LINK_LSA
:
2745 case OSPF_OPAQUE_AREA_LSA
:
2746 case OSPF_OPAQUE_AS_LSA
:
2747 /* Currently not used. */
2749 #endif /* HAVE_OPAQUE_LSA */
2758 ospf_lsa_lookup_by_header (struct ospf_area
*area
, struct lsa_header
*lsah
)
2760 struct ospf_lsa
*match
;
2762 #ifdef HAVE_OPAQUE_LSA
2764 * Strictly speaking, the LSA-ID field for Opaque-LSAs (type-9/10/11)
2765 * is redefined to have two subfields; opaque-type and opaque-id.
2766 * However, it is harmless to treat the two sub fields together, as if
2767 * they two were forming a unique LSA-ID.
2769 #endif /* HAVE_OPAQUE_LSA */
2771 match
= ospf_lsa_lookup (area
, lsah
->type
, lsah
->id
, lsah
->adv_router
);
2774 if (IS_DEBUG_OSPF (lsa
, LSA
) == OSPF_DEBUG_LSA
)
2775 zlog_info ("LSA[Type%d:%s]: Lookup by header, NO MATCH",
2776 lsah
->type
, inet_ntoa (lsah
->id
));
2781 /* return +n, l1 is more recent.
2782 return -n, l2 is more recent.
2783 return 0, l1 and l2 is identical. */
2785 ospf_lsa_more_recent (struct ospf_lsa
*l1
, struct ospf_lsa
*l2
)
2790 if (l1
== NULL
&& l2
== NULL
)
2797 /* compare LS sequence number. */
2798 x
= (int) ntohl (l1
->data
->ls_seqnum
);
2799 y
= (int) ntohl (l2
->data
->ls_seqnum
);
2805 /* compare LS checksum. */
2806 r
= ntohs (l1
->data
->checksum
) - ntohs (l2
->data
->checksum
);
2810 /* compare LS age. */
2811 if (IS_LSA_MAXAGE (l1
) && !IS_LSA_MAXAGE (l2
))
2813 else if (!IS_LSA_MAXAGE (l1
) && IS_LSA_MAXAGE (l2
))
2816 /* compare LS age with MaxAgeDiff. */
2817 if (LS_AGE (l1
) - LS_AGE (l2
) > OSPF_LSA_MAXAGE_DIFF
)
2819 else if (LS_AGE (l2
) - LS_AGE (l1
) > OSPF_LSA_MAXAGE_DIFF
)
2822 /* LSAs are identical. */
2826 /* If two LSAs are different, return 1, otherwise return 0. */
2828 ospf_lsa_different (struct ospf_lsa
*l1
, struct ospf_lsa
*l2
)
2836 if (l1
->data
->options
!= l2
->data
->options
)
2839 if (IS_LSA_MAXAGE (l1
) && !IS_LSA_MAXAGE (l2
))
2842 if (IS_LSA_MAXAGE (l2
) && !IS_LSA_MAXAGE (l1
))
2845 if (l1
->data
->length
!= l2
->data
->length
)
2848 if (l1
->data
->length
== 0)
2851 assert (l1
->data
->length
> OSPF_LSA_HEADER_SIZE
);
2853 p1
= (char *) l1
->data
;
2854 p2
= (char *) l2
->data
;
2856 if (memcmp (p1
+ OSPF_LSA_HEADER_SIZE
, p2
+ OSPF_LSA_HEADER_SIZE
,
2857 ntohs( l1
->data
->length
) - OSPF_LSA_HEADER_SIZE
) != 0)
2863 #ifdef ORIGINAL_CODING
2865 ospf_lsa_flush_self_originated (struct ospf_neighbor
*nbr
,
2866 struct ospf_lsa
*self
,
2867 struct ospf_lsa
*new)
2871 /* Adjust LS Sequence Number. */
2872 seqnum
= ntohl (new->data
->ls_seqnum
) + 1;
2873 self
->data
->ls_seqnum
= htonl (seqnum
);
2875 /* Recalculate LSA checksum. */
2876 ospf_lsa_checksum (self
->data
);
2878 /* Reflooding LSA. */
2879 /* RFC2328 Section 13.3
2880 On non-broadcast networks, separate Link State Update
2881 packets must be sent, as unicasts, to each adjacent neighbor
2882 (i.e., those in state Exchange or greater). The destination
2883 IP addresses for these packets are the neighbors' IP
2885 if (nbr
->oi
->type
== OSPF_IFTYPE_NBMA
)
2887 struct route_node
*rn
;
2888 struct ospf_neighbor
*onbr
;
2890 for (rn
= route_top (nbr
->oi
->nbrs
); rn
; rn
= route_next (rn
))
2891 if ((onbr
= rn
->info
) != NULL
)
2892 if (onbr
!= nbr
->oi
->nbr_self
&& onbr
->status
>= NSM_Exchange
)
2893 ospf_ls_upd_send_lsa (onbr
, self
, OSPF_SEND_PACKET_DIRECT
);
2896 ospf_ls_upd_send_lsa (nbr
, self
, OSPF_SEND_PACKET_INDIRECT
);
2898 if (IS_DEBUG_OSPF (lsa
, LSA_GENERATE
))
2899 zlog_info ("LSA[Type%d:%s]: Flush self-originated LSA",
2900 self
->data
->type
, inet_ntoa (self
->data
->id
));
2902 #else /* ORIGINAL_CODING */
2904 ospf_lsa_flush_schedule (struct ospf_lsa
*lsa
, void *v
, int i
)
2906 if (lsa
== NULL
|| !IS_LSA_SELF (lsa
))
2909 if (IS_DEBUG_OSPF_EVENT
)
2910 zlog_info ("LSA[Type%d:%s]: Schedule self-originated LSA to FLUSH", lsa
->data
->type
, inet_ntoa (lsa
->data
->id
));
2912 /* Force given lsa's age to MaxAge. */
2913 lsa
->data
->ls_age
= htons (OSPF_LSA_MAXAGE
);
2915 switch (lsa
->data
->type
)
2917 #ifdef HAVE_OPAQUE_LSA
2918 case OSPF_OPAQUE_LINK_LSA
:
2919 case OSPF_OPAQUE_AREA_LSA
:
2920 case OSPF_OPAQUE_AS_LSA
:
2921 ospf_opaque_lsa_refresh (lsa
);
2923 #endif /* HAVE_OPAQUE_LSA */
2925 ospf_lsa_maxage (lsa
);
2933 ospf_flush_self_originated_lsas_now (struct ospf
*top
)
2936 struct ospf_area
*area
;
2937 struct ospf_interface
*oi
;
2938 struct ospf_lsa
*lsa
;
2939 int need_to_flush_ase
= 0;
2941 for (n1
= listhead (top
->areas
); n1
; nextnode (n1
))
2943 if ((area
= getdata (n1
)) == NULL
)
2946 if ((lsa
= area
->router_lsa_self
) != NULL
)
2948 if (IS_DEBUG_OSPF_EVENT
)
2949 zlog_info ("LSA[Type%d:%s]: Schedule self-originated LSA to FLUSH", lsa
->data
->type
, inet_ntoa (lsa
->data
->id
));
2951 ospf_lsa_flush_area (lsa
, area
);
2952 ospf_lsa_unlock (area
->router_lsa_self
);
2953 area
->router_lsa_self
= NULL
;
2954 OSPF_TIMER_OFF (area
->t_router_lsa_self
);
2957 for (n2
= listhead (area
->oiflist
); n2
; nextnode (n2
))
2959 if ((oi
= getdata (n2
)) == NULL
)
2962 if ((lsa
= oi
->network_lsa_self
) != NULL
2963 && oi
->state
== ISM_DR
2964 && oi
->full_nbrs
> 0)
2966 if (IS_DEBUG_OSPF_EVENT
)
2967 zlog_info ("LSA[Type%d:%s]: Schedule self-originated LSA to FLUSH", lsa
->data
->type
, inet_ntoa (lsa
->data
->id
));
2969 ospf_lsa_flush_area (oi
->network_lsa_self
, area
);
2970 ospf_lsa_unlock (oi
->network_lsa_self
);
2971 oi
->network_lsa_self
= NULL
;
2972 OSPF_TIMER_OFF (oi
->t_network_lsa_self
);
2975 if (oi
->type
!= OSPF_IFTYPE_VIRTUALLINK
2976 && area
->external_routing
== OSPF_AREA_DEFAULT
)
2977 need_to_flush_ase
= 1;
2980 foreach_lsa (SUMMARY_LSDB (area
), NULL
, 0, ospf_lsa_flush_schedule
);
2981 foreach_lsa (ASBR_SUMMARY_LSDB (area
), NULL
, 0, ospf_lsa_flush_schedule
);
2982 #ifdef HAVE_OPAQUE_LSA
2983 foreach_lsa (OPAQUE_LINK_LSDB (area
),
2984 NULL
, 0, ospf_lsa_flush_schedule
);
2985 foreach_lsa (OPAQUE_AREA_LSDB (area
),
2986 NULL
, 0, ospf_lsa_flush_schedule
);
2987 #endif /* HAVE_OPAQUE_LSA */
2990 if (need_to_flush_ase
)
2992 foreach_lsa (EXTERNAL_LSDB (top
), NULL
, 0, ospf_lsa_flush_schedule
);
2993 #ifdef HAVE_OPAQUE_LSA
2994 foreach_lsa (OPAQUE_AS_LSDB (top
),
2995 NULL
, 0, ospf_lsa_flush_schedule
);
2996 #endif /* HAVE_OPAQUE_LSA */
3000 * Make sure that the MaxAge LSA remover is executed immediately,
3001 * without conflicting to other threads.
3003 if (top
->t_maxage
!= NULL
)
3005 OSPF_TIMER_OFF (top
->t_maxage
);
3006 thread_execute (master
, ospf_maxage_lsa_remover
, top
, 0);
3011 #endif /* ORIGINAL_CODING */
3013 /* If there is self-originated LSA, then return 1, otherwise return 0. */
3014 /* An interface-independent version of ospf_lsa_is_self_originated */
3016 ospf_lsa_is_self_originated (struct ospf_lsa
*lsa
)
3020 /* This LSA is already checked. */
3021 if (CHECK_FLAG (lsa
->flags
, OSPF_LSA_SELF_CHECKED
))
3022 return CHECK_FLAG (lsa
->flags
, OSPF_LSA_SELF
);
3024 /* Make sure LSA is self-checked. */
3025 SET_FLAG (lsa
->flags
, OSPF_LSA_SELF_CHECKED
);
3027 /* AdvRouter and Router ID is the same. */
3028 if (IPV4_ADDR_SAME (&lsa
->data
->adv_router
, &ospf_top
->router_id
))
3029 SET_FLAG (lsa
->flags
, OSPF_LSA_SELF
);
3031 /* LSA is router-LSA. */
3032 else if (lsa
->data
->type
== OSPF_ROUTER_LSA
&&
3033 IPV4_ADDR_SAME (&lsa
->data
->id
, &ospf_top
->router_id
))
3034 SET_FLAG (lsa
->flags
, OSPF_LSA_SELF
);
3036 /* LSA is network-LSA. Compare Link ID with all interfaces. */
3037 else if (lsa
->data
->type
== OSPF_NETWORK_LSA
)
3038 for (node
= listhead (ospf_top
->oiflist
); node
; nextnode (node
))
3040 struct ospf_interface
*oi
= getdata (node
);
3042 /* Ignore virtual link. */
3043 if (oi
->type
!= OSPF_IFTYPE_VIRTUALLINK
)
3044 if (oi
->address
->family
== AF_INET
)
3045 if (IPV4_ADDR_SAME (&lsa
->data
->id
, &oi
->address
->u
.prefix4
))
3047 /* to make it easier later */
3048 SET_FLAG (lsa
->flags
, OSPF_LSA_SELF
);
3049 return CHECK_FLAG (lsa
->flags
, OSPF_LSA_SELF
);
3053 return CHECK_FLAG (lsa
->flags
, OSPF_LSA_SELF
);
3056 /* Get unique Link State ID. */
3058 ospf_lsa_unique_id (struct ospf_lsdb
*lsdb
, u_char type
, struct prefix_ipv4
*p
)
3060 struct ospf_lsa
*lsa
;
3061 struct in_addr mask
, id
;
3065 /* Check existence of LSA instance. */
3066 lsa
= ospf_lsdb_lookup_by_id (lsdb
, type
, id
, ospf_top
->router_id
);
3069 struct as_external_lsa
*al
= (struct as_external_lsa
*) lsa
->data
;
3070 if (ip_masklen (al
->mask
) == p
->prefixlen
)
3072 if (IS_DEBUG_OSPF (lsa
, LSA_GENERATE
))
3073 zlog_warn ("ospf_lsa_unique_id(): "
3074 "Can't get Link State ID for %s/%d",
3075 inet_ntoa (p
->prefix
), p
->prefixlen
);
3076 /* id.s_addr = 0; */
3077 id
.s_addr
= 0xffffffff;
3080 /* Masklen differs, then apply wildcard mask to Link State ID. */
3083 masklen2ip (p
->prefixlen
, &mask
);
3085 id
.s_addr
= p
->prefix
.s_addr
| (~mask
.s_addr
);
3086 lsa
= ospf_lsdb_lookup_by_id (ospf_top
->lsdb
, type
,
3087 id
, ospf_top
->router_id
);
3090 if (IS_DEBUG_OSPF (lsa
, LSA_GENERATE
))
3091 zlog_warn ("ospf_lsa_unique_id(): "
3092 "Can't get Link State ID for %s/%d",
3093 inet_ntoa (p
->prefix
), p
->prefixlen
);
3094 /* id.s_addr = 0; */
3095 id
.s_addr
= 0xffffffff;
3105 #define LSA_ACTION_ORIGN_RTR 1
3106 #define LSA_ACTION_ORIGN_NET 2
3107 #define LSA_ACTION_FLOOD_AREA 3
3108 #define LSA_ACTION_FLOOD_AS 4
3109 #define LSA_ACTION_FLUSH_AREA 5
3110 #define LSA_ACTION_FLUSH_AS 6
3115 struct ospf_area
*area
;
3116 struct ospf_interface
*oi
;
3117 struct ospf_lsa
*lsa
;
3121 ospf_lsa_action (struct thread
*t
)
3123 struct lsa_action
*data
;
3125 data
= THREAD_ARG (t
);
3127 if (IS_DEBUG_OSPF (lsa
, LSA
) == OSPF_DEBUG_LSA
)
3128 zlog_info ("LSA[Action]: Performing scheduled LSA action: %d",
3131 switch (data
->action
)
3133 case LSA_ACTION_ORIGN_RTR
:
3134 ospf_router_lsa_refresh (data
->area
->router_lsa_self
);
3136 case LSA_ACTION_ORIGN_NET
:
3137 ospf_network_lsa_originate (data
->oi
);
3139 case LSA_ACTION_FLOOD_AREA
:
3140 ospf_flood_through_area (data
->area
, NULL
, data
->lsa
);
3142 case LSA_ACTION_FLOOD_AS
:
3143 ospf_flood_through_as (NULL
, data
->lsa
);
3145 case LSA_ACTION_FLUSH_AREA
:
3146 ospf_lsa_flush_area (data
->lsa
, data
->area
);
3148 case LSA_ACTION_FLUSH_AS
:
3149 ospf_lsa_flush_as (data
->lsa
);
3153 ospf_lsa_unlock (data
->lsa
);
3154 XFREE (MTYPE_OSPF_MESSAGE
, data
);
3159 ospf_schedule_lsa_flood_area (struct ospf_area
*area
, struct ospf_lsa
*lsa
)
3161 struct lsa_action
*data
;
3163 data
= XMALLOC (MTYPE_OSPF_MESSAGE
, sizeof (struct lsa_action
));
3164 memset (data
, 0, sizeof (struct lsa_action
));
3166 data
->action
= LSA_ACTION_FLOOD_AREA
;
3168 data
->lsa
= ospf_lsa_lock (lsa
);
3170 thread_add_event (master
, ospf_lsa_action
, data
, 0);
3174 ospf_schedule_lsa_flush_area (struct ospf_area
*area
, struct ospf_lsa
*lsa
)
3176 struct lsa_action
*data
;
3178 data
= XMALLOC (MTYPE_OSPF_MESSAGE
, sizeof (struct lsa_action
));
3179 memset (data
, 0, sizeof (struct lsa_action
));
3181 data
->action
= LSA_ACTION_FLUSH_AREA
;
3183 data
->lsa
= ospf_lsa_lock (lsa
);
3185 thread_add_event (master
, ospf_lsa_action
, data
, 0);
3189 /* LSA Refreshment functions. */
3191 ospf_lsa_refresh (struct ospf_lsa
*lsa
)
3193 struct external_info
*ei
;
3194 assert (CHECK_FLAG (lsa
->flags
, OSPF_LSA_SELF
));
3196 switch (lsa
->data
->type
)
3198 /* Router and Network LSAs are processed differently. */
3199 case OSPF_ROUTER_LSA
:
3200 case OSPF_NETWORK_LSA
:
3202 case OSPF_SUMMARY_LSA
:
3203 ospf_summary_lsa_refresh (lsa
);
3205 case OSPF_ASBR_SUMMARY_LSA
:
3206 ospf_summary_asbr_lsa_refresh (lsa
);
3208 case OSPF_AS_EXTERNAL_LSA
:
3209 ei
= ospf_external_info_check (lsa
);
3211 ospf_external_lsa_refresh (lsa
, ei
, LSA_REFRESH_FORCE
);
3213 ospf_lsa_flush_as (lsa
);
3215 #ifdef HAVE_OPAQUE_LSA
3216 case OSPF_OPAQUE_LINK_LSA
:
3217 case OSPF_OPAQUE_AREA_LSA
:
3218 case OSPF_OPAQUE_AS_LSA
:
3219 ospf_opaque_lsa_refresh (lsa
);
3223 #endif /* HAVE_OPAQUE_LSA */
3228 ospf_refresher_register_lsa (struct ospf
*top
, struct ospf_lsa
*lsa
)
3230 u_int16_t index
, current_index
;
3232 assert (CHECK_FLAG (lsa
->flags
, OSPF_LSA_SELF
));
3234 if (lsa
->refresh_list
< 0)
3238 if (LS_AGE (lsa
) == 0 &&
3239 ntohl (lsa
->data
->ls_seqnum
) == OSPF_INITIAL_SEQUENCE_NUMBER
)
3240 /* Randomize first update by OSPF_LS_REFRESH_SHIFT factor */
3241 delay
= OSPF_LS_REFRESH_SHIFT
+ (random () % OSPF_LS_REFRESH_TIME
);
3243 /* Randomize another updates by +-OSPF_LS_REFRESH_JITTER factor */
3244 delay
= OSPF_LS_REFRESH_TIME
- LS_AGE (lsa
) - OSPF_LS_REFRESH_JITTER
3245 + (random () % (2*OSPF_LS_REFRESH_JITTER
));
3250 current_index
= top
->lsa_refresh_queue
.index
+
3251 (time (NULL
) - top
->lsa_refresher_started
)/OSPF_LSA_REFRESHER_GRANULARITY
;
3253 index
= (current_index
+ delay
/OSPF_LSA_REFRESHER_GRANULARITY
)
3254 % (OSPF_LSA_REFRESHER_SLOTS
);
3256 if (IS_DEBUG_OSPF (lsa
, LSA_REFRESH
))
3257 zlog_info ("LSA[Refresh]: lsa with age %d added to index %d",
3258 LS_AGE (lsa
), index
);
3259 if (!top
->lsa_refresh_queue
.qs
[index
])
3260 top
->lsa_refresh_queue
.qs
[index
] = list_new ();
3261 listnode_add (top
->lsa_refresh_queue
.qs
[index
], ospf_lsa_lock (lsa
));
3262 lsa
->refresh_list
= index
;
3267 ospf_refresher_unregister_lsa (struct ospf
*top
, struct ospf_lsa
*lsa
)
3269 assert (CHECK_FLAG (lsa
->flags
, OSPF_LSA_SELF
));
3270 if (lsa
->refresh_list
>= 0)
3272 list refresh_list
= top
->lsa_refresh_queue
.qs
[lsa
->refresh_list
];
3273 listnode_delete (refresh_list
, lsa
);
3274 if (!listcount (refresh_list
))
3276 list_free (refresh_list
);
3277 top
->lsa_refresh_queue
.qs
[lsa
->refresh_list
] = NULL
;
3279 ospf_lsa_unlock (lsa
);
3280 lsa
->refresh_list
= -1;
3285 ospf_lsa_refresh_walker (struct thread
*t
)
3289 struct ospf
*top
= THREAD_ARG (t
);
3291 list lsa_to_refresh
= list_new ();
3293 if (IS_DEBUG_OSPF (lsa
, LSA_REFRESH
))
3294 zlog_info ("LSA[Refresh]:ospf_lsa_refresh_walker(): start");
3297 i
= top
->lsa_refresh_queue
.index
;
3299 top
->lsa_refresh_queue
.index
=
3300 (top
->lsa_refresh_queue
.index
+
3301 (time (NULL
) - top
->lsa_refresher_started
) / OSPF_LSA_REFRESHER_GRANULARITY
)
3302 % OSPF_LSA_REFRESHER_SLOTS
;
3304 if (IS_DEBUG_OSPF (lsa
, LSA_REFRESH
))
3305 zlog_info ("LSA[Refresh]: ospf_lsa_refresh_walker(): next index %d",
3306 top
->lsa_refresh_queue
.index
);
3308 for (;i
!= top
->lsa_refresh_queue
.index
;
3309 i
= (i
+ 1) % OSPF_LSA_REFRESHER_SLOTS
)
3311 if (IS_DEBUG_OSPF (lsa
, LSA_REFRESH
))
3312 zlog_info ("LSA[Refresh]: ospf_lsa_refresh_walker(): refresh index %d", i
);
3314 refresh_list
= top
->lsa_refresh_queue
.qs
[i
];
3316 top
->lsa_refresh_queue
.qs
[i
] = NULL
;
3320 for (node
= listhead (refresh_list
); node
;)
3323 struct ospf_lsa
*lsa
= getdata (node
);
3326 if (IS_DEBUG_OSPF (lsa
, LSA_REFRESH
))
3327 zlog_info ("LSA[Refresh]: ospf_lsa_refresh_walker(): refresh lsa %p", lsa
);
3329 list_delete_node (refresh_list
, node
);
3330 ospf_lsa_unlock (lsa
);
3331 lsa
->refresh_list
= -1;
3332 listnode_add (lsa_to_refresh
, lsa
);
3335 list_free (refresh_list
);
3339 top
->t_lsa_refresher
= thread_add_timer (master
, ospf_lsa_refresh_walker
,
3340 top
, top
->lsa_refresh_interval
);
3341 top
->lsa_refresher_started
= time (NULL
);
3343 for (node
= listhead (lsa_to_refresh
); node
; nextnode (node
))
3344 ospf_lsa_refresh (getdata (node
));
3346 list_delete (lsa_to_refresh
);
3348 if (IS_DEBUG_OSPF (lsa
, LSA_REFRESH
))
3349 zlog_info ("LSA[Refresh]: ospf_lsa_refresh_walker(): end");