2 * Copyright (C) 2003 Yasuhiro Ohara
4 * This file is part of GNU Zebra.
6 * GNU Zebra is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License as published by the
8 * Free Software Foundation; either version 2, or (at your option) any
11 * GNU Zebra is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * General Public License for more details.
16 * You should have received a copy of the GNU General Public License along
17 * with this program; see the file COPYING; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
34 #include "ospf6_proto.h"
35 #include "ospf6_message.h"
36 #include "ospf6_route.h"
37 #include "ospf6_lsa.h"
38 #include "ospf6_lsdb.h"
40 #include "ospf6_top.h"
41 #include "ospf6_area.h"
42 #include "ospf6_interface.h"
43 #include "ospf6_neighbor.h"
44 #include "ospf6_intra.h"
45 #include "ospf6_asbr.h"
46 #include "ospf6_abr.h"
47 #include "ospf6_flood.h"
49 #include "ospf6_spf.h"
51 unsigned char conf_debug_ospf6_brouter
= 0;
52 u_int32_t conf_debug_ospf6_brouter_specific_router_id
;
53 u_int32_t conf_debug_ospf6_brouter_specific_area_id
;
55 /******************************/
56 /* RFC2740 3.4.3.1 Router-LSA */
57 /******************************/
60 ospf6_router_lsa_get_nbr_id (struct ospf6_lsa
*lsa
, char *buf
, int buflen
,
63 struct ospf6_router_lsa
*router_lsa
;
64 struct ospf6_router_lsdesc
*lsdesc
;
66 char buf1
[INET_ADDRSTRLEN
], buf2
[INET_ADDRSTRLEN
];
70 router_lsa
= (struct ospf6_router_lsa
*)
71 ((char *) lsa
->header
+ sizeof (struct ospf6_lsa_header
));
72 start
= (char *) router_lsa
+ sizeof (struct ospf6_router_lsa
);
73 end
= (char *) lsa
->header
+ ntohs (lsa
->header
->length
);
75 lsdesc
= (struct ospf6_router_lsdesc
*)
76 (start
+ pos
*(sizeof (struct ospf6_router_lsdesc
)));
77 if ((char *)lsdesc
< end
)
79 if (buf
&& (buflen
> INET_ADDRSTRLEN
*2))
81 inet_ntop (AF_INET
, &lsdesc
->neighbor_interface_id
,
83 inet_ntop (AF_INET
, &lsdesc
->neighbor_router_id
,
85 sprintf (buf
, "%s/%s", buf2
, buf1
);
96 ospf6_router_lsa_show (struct vty
*vty
, struct ospf6_lsa
*lsa
)
98 char *start
, *end
, *current
;
99 char buf
[32], name
[32], bits
[16], options
[32];
100 struct ospf6_router_lsa
*router_lsa
;
101 struct ospf6_router_lsdesc
*lsdesc
;
103 router_lsa
= (struct ospf6_router_lsa
*)
104 ((char *) lsa
->header
+ sizeof (struct ospf6_lsa_header
));
106 ospf6_capability_printbuf (router_lsa
->bits
, bits
, sizeof (bits
));
107 ospf6_options_printbuf (router_lsa
->options
, options
, sizeof (options
));
108 vty_out (vty
, " Bits: %s Options: %s\n", bits
, options
);
110 start
= (char *) router_lsa
+ sizeof (struct ospf6_router_lsa
);
111 end
= (char *) lsa
->header
+ ntohs (lsa
->header
->length
);
112 for (current
= start
; current
+ sizeof (struct ospf6_router_lsdesc
) <= end
;
113 current
+= sizeof (struct ospf6_router_lsdesc
))
115 lsdesc
= (struct ospf6_router_lsdesc
*) current
;
117 if (lsdesc
->type
== OSPF6_ROUTER_LSDESC_POINTTOPOINT
)
118 snprintf (name
, sizeof (name
), "Point-To-Point");
119 else if (lsdesc
->type
== OSPF6_ROUTER_LSDESC_TRANSIT_NETWORK
)
120 snprintf (name
, sizeof (name
), "Transit-Network");
121 else if (lsdesc
->type
== OSPF6_ROUTER_LSDESC_STUB_NETWORK
)
122 snprintf (name
, sizeof (name
), "Stub-Network");
123 else if (lsdesc
->type
== OSPF6_ROUTER_LSDESC_VIRTUAL_LINK
)
124 snprintf (name
, sizeof (name
), "Virtual-Link");
126 snprintf (name
, sizeof (name
), "Unknown (%#x)", lsdesc
->type
);
128 vty_out (vty
, " Type: %s Metric: %d\n",
129 name
, ntohs (lsdesc
->metric
));
130 vty_out (vty
, " Interface ID: %s\n",
131 inet_ntop (AF_INET
, &lsdesc
->interface_id
,
133 vty_out (vty
, " Neighbor Interface ID: %s\n",
134 inet_ntop (AF_INET
, &lsdesc
->neighbor_interface_id
,
136 vty_out (vty
, " Neighbor Router ID: %s\n",
137 inet_ntop (AF_INET
, &lsdesc
->neighbor_router_id
,
144 ospf6_router_lsa_options_set (struct ospf6_area
*oa
,
145 struct ospf6_router_lsa
*router_lsa
)
147 OSPF6_OPT_CLEAR_ALL (router_lsa
->options
);
148 memcpy (router_lsa
->options
, oa
->options
, 3);
150 if (ospf6_is_router_abr (ospf6
))
151 SET_FLAG (router_lsa
->bits
, OSPF6_ROUTER_BIT_B
);
153 UNSET_FLAG (router_lsa
->bits
, OSPF6_ROUTER_BIT_B
);
155 if (!IS_AREA_STUB (oa
) && ospf6_asbr_is_asbr (oa
->ospf6
))
157 SET_FLAG (router_lsa
->bits
, OSPF6_ROUTER_BIT_E
);
161 UNSET_FLAG (router_lsa
->bits
, OSPF6_ROUTER_BIT_E
);
164 UNSET_FLAG (router_lsa
->bits
, OSPF6_ROUTER_BIT_V
);
165 UNSET_FLAG (router_lsa
->bits
, OSPF6_ROUTER_BIT_W
);
169 ospf6_router_is_stub_router (struct ospf6_lsa
*lsa
)
171 struct ospf6_router_lsa
*rtr_lsa
;
173 if (lsa
!= NULL
&& OSPF6_LSA_IS_TYPE (ROUTER
, lsa
))
175 rtr_lsa
= (struct ospf6_router_lsa
*)
176 ((caddr_t
) lsa
->header
+ sizeof (struct ospf6_lsa_header
));
178 if (!OSPF6_OPT_ISSET (rtr_lsa
->options
, OSPF6_OPT_R
))
180 return (OSPF6_IS_STUB_ROUTER
);
182 else if (!OSPF6_OPT_ISSET (rtr_lsa
->options
, OSPF6_OPT_V6
))
184 return (OSPF6_IS_STUB_ROUTER_V6
);
188 return (OSPF6_NOT_STUB_ROUTER
);
192 ospf6_router_lsa_originate (struct thread
*thread
)
194 struct ospf6_area
*oa
;
196 char buffer
[OSPF6_MAX_LSASIZE
];
197 struct ospf6_lsa_header
*lsa_header
;
198 struct ospf6_lsa
*lsa
;
200 u_int32_t link_state_id
= 0;
201 struct listnode
*node
, *nnode
;
203 struct ospf6_interface
*oi
;
204 struct ospf6_neighbor
*on
, *drouter
= NULL
;
205 struct ospf6_router_lsa
*router_lsa
;
206 struct ospf6_router_lsdesc
*lsdesc
;
211 oa
= (struct ospf6_area
*) THREAD_ARG (thread
);
212 oa
->thread_router_lsa
= NULL
;
214 if (IS_OSPF6_DEBUG_ORIGINATE (ROUTER
))
215 zlog_debug ("Originate Router-LSA for Area %s", oa
->name
);
217 memset (buffer
, 0, sizeof (buffer
));
218 lsa_header
= (struct ospf6_lsa_header
*) buffer
;
219 router_lsa
= (struct ospf6_router_lsa
*)
220 ((caddr_t
) lsa_header
+ sizeof (struct ospf6_lsa_header
));
222 ospf6_router_lsa_options_set (oa
, router_lsa
);
224 /* describe links for each interfaces */
225 lsdesc
= (struct ospf6_router_lsdesc
*)
226 ((caddr_t
) router_lsa
+ sizeof (struct ospf6_router_lsa
));
228 for (ALL_LIST_ELEMENTS (oa
->if_list
, node
, nnode
, oi
))
230 /* Interfaces in state Down or Loopback are not described */
231 if (oi
->state
== OSPF6_INTERFACE_DOWN
||
232 oi
->state
== OSPF6_INTERFACE_LOOPBACK
)
235 /* Nor are interfaces without any full adjacencies described */
237 for (ALL_LIST_ELEMENTS_RO (oi
->neighbor_list
, j
, on
))
238 if (on
->state
== OSPF6_NEIGHBOR_FULL
)
244 /* Multiple Router-LSA instance according to size limit setting */
245 if ( (oa
->router_lsa_size_limit
!= 0)
246 && ((size_t)((char *)lsdesc
- buffer
)
247 + sizeof (struct ospf6_router_lsdesc
)
248 > oa
->router_lsa_size_limit
))
250 if ((caddr_t
) lsdesc
== (caddr_t
) router_lsa
+
251 sizeof (struct ospf6_router_lsa
))
253 if (IS_OSPF6_DEBUG_ORIGINATE (ROUTER
))
254 zlog_debug ("Size limit setting for Router-LSA too short");
261 /* Point-to-Point interfaces */
262 if (oi
->type
== OSPF_IFTYPE_POINTOPOINT
)
264 for (ALL_LIST_ELEMENTS_RO (oi
->neighbor_list
, j
, on
))
266 if (on
->state
!= OSPF6_NEIGHBOR_FULL
)
269 lsdesc
->type
= OSPF6_ROUTER_LSDESC_POINTTOPOINT
;
270 lsdesc
->metric
= htons (oi
->cost
);
271 lsdesc
->interface_id
= htonl (oi
->interface
->ifindex
);
272 lsdesc
->neighbor_interface_id
= htonl (on
->ifindex
);
273 lsdesc
->neighbor_router_id
= on
->router_id
;
279 /* Broadcast and NBMA interfaces */
280 else if (oi
->type
== OSPF_IFTYPE_BROADCAST
)
282 /* If this router is not DR,
283 and If this router not fully adjacent with DR,
284 this interface is not transit yet: ignore. */
285 if (oi
->state
!= OSPF6_INTERFACE_DR
)
287 drouter
= ospf6_neighbor_lookup (oi
->drouter
, oi
);
288 if (drouter
== NULL
|| drouter
->state
!= OSPF6_NEIGHBOR_FULL
)
292 lsdesc
->type
= OSPF6_ROUTER_LSDESC_TRANSIT_NETWORK
;
293 lsdesc
->metric
= htons (oi
->cost
);
294 lsdesc
->interface_id
= htonl (oi
->interface
->ifindex
);
295 if (oi
->state
!= OSPF6_INTERFACE_DR
)
297 lsdesc
->neighbor_interface_id
= htonl (drouter
->ifindex
);
298 lsdesc
->neighbor_router_id
= drouter
->router_id
;
302 lsdesc
->neighbor_interface_id
= htonl (oi
->interface
->ifindex
);
303 lsdesc
->neighbor_router_id
= oi
->area
->ospf6
->router_id
;
310 assert (0); /* Unknown interface type */
315 /* Point-to-Multipoint interfaces */
319 /* Fill LSA Header */
321 lsa_header
->type
= htons (OSPF6_LSTYPE_ROUTER
);
322 lsa_header
->id
= htonl (link_state_id
);
323 lsa_header
->adv_router
= oa
->ospf6
->router_id
;
325 ospf6_new_ls_seqnum (lsa_header
->type
, lsa_header
->id
,
326 lsa_header
->adv_router
, oa
->lsdb
);
327 lsa_header
->length
= htons ((caddr_t
) lsdesc
- (caddr_t
) buffer
);
330 ospf6_lsa_checksum (lsa_header
);
333 lsa
= ospf6_lsa_create (lsa_header
);
336 ospf6_lsa_originate_area (lsa
, oa
);
340 /* Do premature-aging of rest, undesired Router-LSAs */
341 type
= ntohs (OSPF6_LSTYPE_ROUTER
);
342 router
= oa
->ospf6
->router_id
;
344 for (ALL_LSDB_TYPED_ADVRTR(oa
->lsdb
, type
, router
, lsa
))
346 if (ntohl (lsa
->header
->id
) < link_state_id
)
348 ospf6_lsa_purge (lsa
);
353 * Waiting till the LSA is actually removed from the database to trigger
354 * SPF delays network convergence. Unlike IPv4, for an ABR, when all
355 * interfaces associated with an area are gone, triggering an SPF right away
356 * helps convergence with inter-area routes.
358 if (count
&& !link_state_id
)
359 ospf6_spf_schedule (oa
->ospf6
, OSPF6_SPF_FLAGS_ROUTER_LSA_ORIGINATED
);
364 /*******************************/
365 /* RFC2740 3.4.3.2 Network-LSA */
366 /*******************************/
369 ospf6_network_lsa_get_ar_id (struct ospf6_lsa
*lsa
, char *buf
, int buflen
,
372 char *start
, *end
, *current
;
373 struct ospf6_network_lsa
*network_lsa
;
374 struct ospf6_network_lsdesc
*lsdesc
;
378 network_lsa
= (struct ospf6_network_lsa
*)
379 ((caddr_t
) lsa
->header
+ sizeof (struct ospf6_lsa_header
));
381 start
= (char *) network_lsa
+ sizeof (struct ospf6_network_lsa
);
382 end
= (char *) lsa
->header
+ ntohs (lsa
->header
->length
);
383 current
= start
+ pos
*(sizeof (struct ospf6_network_lsdesc
));
385 if ((current
+ sizeof(struct ospf6_network_lsdesc
)) <= end
)
387 lsdesc
= (struct ospf6_network_lsdesc
*)current
;
389 inet_ntop (AF_INET
, &lsdesc
->router_id
, buf
, buflen
);
399 ospf6_network_lsa_show (struct vty
*vty
, struct ospf6_lsa
*lsa
)
401 char *start
, *end
, *current
;
402 struct ospf6_network_lsa
*network_lsa
;
403 struct ospf6_network_lsdesc
*lsdesc
;
404 char buf
[128], options
[32];
406 network_lsa
= (struct ospf6_network_lsa
*)
407 ((caddr_t
) lsa
->header
+ sizeof (struct ospf6_lsa_header
));
409 ospf6_options_printbuf (network_lsa
->options
, options
, sizeof (options
));
410 vty_out (vty
, " Options: %s\n", options
);
412 start
= (char *) network_lsa
+ sizeof (struct ospf6_network_lsa
);
413 end
= (char *) lsa
->header
+ ntohs (lsa
->header
->length
);
414 for (current
= start
; current
+ sizeof (struct ospf6_network_lsdesc
) <= end
;
415 current
+= sizeof (struct ospf6_network_lsdesc
))
417 lsdesc
= (struct ospf6_network_lsdesc
*) current
;
418 inet_ntop (AF_INET
, &lsdesc
->router_id
, buf
, sizeof (buf
));
419 vty_out (vty
, " Attached Router: %s\n", buf
);
425 ospf6_network_lsa_originate (struct thread
*thread
)
427 struct ospf6_interface
*oi
;
429 char buffer
[OSPF6_MAX_LSASIZE
];
430 struct ospf6_lsa_header
*lsa_header
;
433 struct ospf6_lsa
*old
, *lsa
;
434 struct ospf6_network_lsa
*network_lsa
;
435 struct ospf6_network_lsdesc
*lsdesc
;
436 struct ospf6_neighbor
*on
;
437 struct ospf6_link_lsa
*link_lsa
;
441 oi
= (struct ospf6_interface
*) THREAD_ARG (thread
);
442 oi
->thread_network_lsa
= NULL
;
444 /* The interface must be enabled until here. A Network-LSA of a
445 disabled interface (but was once enabled) should be flushed
446 by ospf6_lsa_refresh (), and does not come here. */
449 old
= ospf6_lsdb_lookup (htons (OSPF6_LSTYPE_NETWORK
),
450 htonl (oi
->interface
->ifindex
),
451 oi
->area
->ospf6
->router_id
, oi
->area
->lsdb
);
453 /* Do not originate Network-LSA if not DR */
454 if (oi
->state
!= OSPF6_INTERFACE_DR
)
458 ospf6_lsa_purge (old
);
460 * Waiting till the LSA is actually removed from the database to
461 * trigger SPF delays network convergence.
463 ospf6_spf_schedule (oi
->area
->ospf6
,
464 OSPF6_SPF_FLAGS_NETWORK_LSA_ORIGINATED
);
469 if (IS_OSPF6_DEBUG_ORIGINATE (NETWORK
))
470 zlog_debug ("Originate Network-LSA for Interface %s", oi
->interface
->name
);
472 /* If none of neighbor is adjacent to us */
475 for (ALL_LIST_ELEMENTS_RO (oi
->neighbor_list
, i
, on
))
476 if (on
->state
== OSPF6_NEIGHBOR_FULL
)
481 if (IS_OSPF6_DEBUG_ORIGINATE (NETWORK
))
482 zlog_debug ("Interface stub, ignore");
484 ospf6_lsa_purge (old
);
489 memset (buffer
, 0, sizeof (buffer
));
490 lsa_header
= (struct ospf6_lsa_header
*) buffer
;
491 network_lsa
= (struct ospf6_network_lsa
*)
492 ((caddr_t
) lsa_header
+ sizeof (struct ospf6_lsa_header
));
494 /* Collect the interface's Link-LSAs to describe
495 network's optional capabilities */
496 type
= htons (OSPF6_LSTYPE_LINK
);
497 for (ALL_LSDB_TYPED(oi
->lsdb
, type
, lsa
))
499 link_lsa
= (struct ospf6_link_lsa
*)
500 ((caddr_t
) lsa
->header
+ sizeof (struct ospf6_lsa_header
));
501 network_lsa
->options
[0] |= link_lsa
->options
[0];
502 network_lsa
->options
[1] |= link_lsa
->options
[1];
503 network_lsa
->options
[2] |= link_lsa
->options
[2];
506 lsdesc
= (struct ospf6_network_lsdesc
*)
507 ((caddr_t
) network_lsa
+ sizeof (struct ospf6_network_lsa
));
509 /* set Link Description to the router itself */
510 lsdesc
->router_id
= oi
->area
->ospf6
->router_id
;
513 /* Walk through the neighbors */
514 for (ALL_LIST_ELEMENTS_RO (oi
->neighbor_list
, i
, on
))
516 if (on
->state
!= OSPF6_NEIGHBOR_FULL
)
519 /* set this neighbor's Router-ID to LSA */
520 lsdesc
->router_id
= on
->router_id
;
524 /* Fill LSA Header */
526 lsa_header
->type
= htons (OSPF6_LSTYPE_NETWORK
);
527 lsa_header
->id
= htonl (oi
->interface
->ifindex
);
528 lsa_header
->adv_router
= oi
->area
->ospf6
->router_id
;
530 ospf6_new_ls_seqnum (lsa_header
->type
, lsa_header
->id
,
531 lsa_header
->adv_router
, oi
->area
->lsdb
);
532 lsa_header
->length
= htons ((caddr_t
) lsdesc
- (caddr_t
) buffer
);
535 ospf6_lsa_checksum (lsa_header
);
538 lsa
= ospf6_lsa_create (lsa_header
);
541 ospf6_lsa_originate_area (lsa
, oi
->area
);
547 /****************************/
548 /* RFC2740 3.4.3.6 Link-LSA */
549 /****************************/
552 ospf6_link_lsa_get_prefix_str (struct ospf6_lsa
*lsa
, char *buf
, int buflen
,
555 char *start
, *end
, *current
;
556 struct ospf6_link_lsa
*link_lsa
;
558 struct ospf6_prefix
*prefix
;
559 int cnt
= 0, prefixnum
;
563 link_lsa
= (struct ospf6_link_lsa
*)
564 ((caddr_t
) lsa
->header
+ sizeof (struct ospf6_lsa_header
));
567 inet_ntop (AF_INET6
, &link_lsa
->linklocal_addr
, buf
, buflen
);
571 prefixnum
= ntohl (link_lsa
->prefix_num
);
575 start
= (char *) link_lsa
+ sizeof (struct ospf6_link_lsa
);
576 end
= (char *) lsa
->header
+ ntohs (lsa
->header
->length
);
581 prefix
= (struct ospf6_prefix
*) current
;
582 if (prefix
->prefix_length
== 0 ||
583 current
+ OSPF6_PREFIX_SIZE (prefix
) > end
)
590 current
= start
+ pos
*OSPF6_PREFIX_SIZE(prefix
);
595 memset (&in6
, 0, sizeof (in6
));
596 memcpy (&in6
, OSPF6_PREFIX_BODY (prefix
),
597 OSPF6_PREFIX_SPACE (prefix
->prefix_length
));
598 inet_ntop (AF_INET6
, &in6
, buf
, buflen
);
601 } while (current
<= end
);
607 ospf6_link_lsa_show (struct vty
*vty
, struct ospf6_lsa
*lsa
)
609 char *start
, *end
, *current
;
610 struct ospf6_link_lsa
*link_lsa
;
612 char buf
[128], options
[32];
613 struct ospf6_prefix
*prefix
;
614 const char *p
, *mc
, *la
, *nu
;
617 link_lsa
= (struct ospf6_link_lsa
*)
618 ((caddr_t
) lsa
->header
+ sizeof (struct ospf6_lsa_header
));
620 ospf6_options_printbuf (link_lsa
->options
, options
, sizeof (options
));
621 inet_ntop (AF_INET6
, &link_lsa
->linklocal_addr
, buf
, sizeof (buf
));
622 prefixnum
= ntohl (link_lsa
->prefix_num
);
624 vty_out (vty
, " Priority: %d Options: %s\n",
625 link_lsa
->priority
, options
);
626 vty_out (vty
, " LinkLocal Address: %s\n", buf
);
627 vty_out (vty
, " Number of Prefix: %d\n", prefixnum
);
629 start
= (char *) link_lsa
+ sizeof (struct ospf6_link_lsa
);
630 end
= (char *) lsa
->header
+ ntohs (lsa
->header
->length
);
631 for (current
= start
; current
< end
; current
+= OSPF6_PREFIX_SIZE (prefix
))
633 prefix
= (struct ospf6_prefix
*) current
;
634 if (prefix
->prefix_length
== 0 ||
635 current
+ OSPF6_PREFIX_SIZE (prefix
) > end
)
638 p
= (CHECK_FLAG (prefix
->prefix_options
, OSPF6_PREFIX_OPTION_P
) ?
640 mc
= (CHECK_FLAG (prefix
->prefix_options
, OSPF6_PREFIX_OPTION_MC
) ?
642 la
= (CHECK_FLAG (prefix
->prefix_options
, OSPF6_PREFIX_OPTION_LA
) ?
644 nu
= (CHECK_FLAG (prefix
->prefix_options
, OSPF6_PREFIX_OPTION_NU
) ?
646 vty_out (vty
, " Prefix Options: %s|%s|%s|%s\n",
649 memset (&in6
, 0, sizeof (in6
));
650 memcpy (&in6
, OSPF6_PREFIX_BODY (prefix
),
651 OSPF6_PREFIX_SPACE (prefix
->prefix_length
));
652 inet_ntop (AF_INET6
, &in6
, buf
, sizeof (buf
));
653 vty_out (vty
, " Prefix: %s/%d\n",
654 buf
, prefix
->prefix_length
);
661 ospf6_link_lsa_originate (struct thread
*thread
)
663 struct ospf6_interface
*oi
;
665 char buffer
[OSPF6_MAX_LSASIZE
];
666 struct ospf6_lsa_header
*lsa_header
;
667 struct ospf6_lsa
*old
, *lsa
;
669 struct ospf6_link_lsa
*link_lsa
;
670 struct ospf6_route
*route
;
671 struct ospf6_prefix
*op
;
673 oi
= (struct ospf6_interface
*) THREAD_ARG (thread
);
674 oi
->thread_link_lsa
= NULL
;
678 /* find previous LSA */
679 old
= ospf6_lsdb_lookup (htons (OSPF6_LSTYPE_LINK
),
680 htonl (oi
->interface
->ifindex
),
681 oi
->area
->ospf6
->router_id
, oi
->lsdb
);
683 if (CHECK_FLAG (oi
->flag
, OSPF6_INTERFACE_DISABLE
))
686 ospf6_lsa_purge (old
);
690 if (IS_OSPF6_DEBUG_ORIGINATE (LINK
))
691 zlog_debug ("Originate Link-LSA for Interface %s", oi
->interface
->name
);
693 /* can't make Link-LSA if linklocal address not set */
694 if (oi
->linklocal_addr
== NULL
)
696 if (IS_OSPF6_DEBUG_ORIGINATE (LINK
))
697 zlog_debug ("No Linklocal address on %s, defer originating",
698 oi
->interface
->name
);
700 ospf6_lsa_purge (old
);
705 memset (buffer
, 0, sizeof (buffer
));
706 lsa_header
= (struct ospf6_lsa_header
*) buffer
;
707 link_lsa
= (struct ospf6_link_lsa
*)
708 ((caddr_t
) lsa_header
+ sizeof (struct ospf6_lsa_header
));
711 link_lsa
->priority
= oi
->priority
;
712 memcpy (link_lsa
->options
, oi
->area
->options
, 3);
713 memcpy (&link_lsa
->linklocal_addr
, oi
->linklocal_addr
,
714 sizeof (struct in6_addr
));
715 link_lsa
->prefix_num
= htonl (oi
->route_connected
->count
);
717 op
= (struct ospf6_prefix
*)
718 ((caddr_t
) link_lsa
+ sizeof (struct ospf6_link_lsa
));
720 /* connected prefix to advertise */
721 for (route
= ospf6_route_head (oi
->route_connected
); route
;
722 route
= ospf6_route_next (route
))
724 op
->prefix_length
= route
->prefix
.prefixlen
;
725 op
->prefix_options
= route
->path
.prefix_options
;
726 op
->prefix_metric
= htons (0);
727 memcpy (OSPF6_PREFIX_BODY (op
), &route
->prefix
.u
.prefix6
,
728 OSPF6_PREFIX_SPACE (op
->prefix_length
));
729 op
= OSPF6_PREFIX_NEXT (op
);
732 /* Fill LSA Header */
734 lsa_header
->type
= htons (OSPF6_LSTYPE_LINK
);
735 lsa_header
->id
= htonl (oi
->interface
->ifindex
);
736 lsa_header
->adv_router
= oi
->area
->ospf6
->router_id
;
738 ospf6_new_ls_seqnum (lsa_header
->type
, lsa_header
->id
,
739 lsa_header
->adv_router
, oi
->lsdb
);
740 lsa_header
->length
= htons ((caddr_t
) op
- (caddr_t
) buffer
);
743 ospf6_lsa_checksum (lsa_header
);
746 lsa
= ospf6_lsa_create (lsa_header
);
749 ospf6_lsa_originate_interface (lsa
, oi
);
755 /*****************************************/
756 /* RFC2740 3.4.3.7 Intra-Area-Prefix-LSA */
757 /*****************************************/
759 ospf6_intra_prefix_lsa_get_prefix_str (struct ospf6_lsa
*lsa
, char *buf
,
762 char *start
, *end
, *current
;
763 struct ospf6_intra_prefix_lsa
*intra_prefix_lsa
;
765 int prefixnum
, cnt
= 0;
766 struct ospf6_prefix
*prefix
;
770 intra_prefix_lsa
= (struct ospf6_intra_prefix_lsa
*)
771 ((caddr_t
) lsa
->header
+ sizeof (struct ospf6_lsa_header
));
773 prefixnum
= ntohs (intra_prefix_lsa
->prefix_num
);
777 start
= (char *) intra_prefix_lsa
+ sizeof (struct ospf6_intra_prefix_lsa
);
778 end
= (char *) lsa
->header
+ ntohs (lsa
->header
->length
);
783 prefix
= (struct ospf6_prefix
*) current
;
784 if (prefix
->prefix_length
== 0 ||
785 current
+ OSPF6_PREFIX_SIZE (prefix
) > end
)
792 current
= start
+ pos
*OSPF6_PREFIX_SIZE(prefix
);
797 memset (&in6
, 0, sizeof (in6
));
798 memcpy (&in6
, OSPF6_PREFIX_BODY (prefix
),
799 OSPF6_PREFIX_SPACE (prefix
->prefix_length
));
800 inet_ntop (AF_INET6
, &in6
, buf
, buflen
);
801 sprintf(&buf
[strlen(buf
)], "/%d", prefix
->prefix_length
);
804 } while (current
<= end
);
810 ospf6_intra_prefix_lsa_show (struct vty
*vty
, struct ospf6_lsa
*lsa
)
812 char *start
, *end
, *current
;
813 struct ospf6_intra_prefix_lsa
*intra_prefix_lsa
;
816 struct ospf6_prefix
*prefix
;
817 char id
[16], adv_router
[16];
818 const char *p
, *mc
, *la
, *nu
;
821 intra_prefix_lsa
= (struct ospf6_intra_prefix_lsa
*)
822 ((caddr_t
) lsa
->header
+ sizeof (struct ospf6_lsa_header
));
824 prefixnum
= ntohs (intra_prefix_lsa
->prefix_num
);
826 vty_out (vty
, " Number of Prefix: %d\n", prefixnum
);
828 inet_ntop (AF_INET
, &intra_prefix_lsa
->ref_id
, id
, sizeof (id
));
829 inet_ntop (AF_INET
, &intra_prefix_lsa
->ref_adv_router
,
830 adv_router
, sizeof (adv_router
));
831 vty_out (vty
, " Reference: %s Id: %s Adv: %s\n",
832 ospf6_lstype_name (intra_prefix_lsa
->ref_type
), id
, adv_router
);
834 start
= (char *) intra_prefix_lsa
+ sizeof (struct ospf6_intra_prefix_lsa
);
835 end
= (char *) lsa
->header
+ ntohs (lsa
->header
->length
);
836 for (current
= start
; current
< end
; current
+= OSPF6_PREFIX_SIZE (prefix
))
838 prefix
= (struct ospf6_prefix
*) current
;
839 if (prefix
->prefix_length
== 0 ||
840 current
+ OSPF6_PREFIX_SIZE (prefix
) > end
)
843 p
= (CHECK_FLAG (prefix
->prefix_options
, OSPF6_PREFIX_OPTION_P
) ?
845 mc
= (CHECK_FLAG (prefix
->prefix_options
, OSPF6_PREFIX_OPTION_MC
) ?
847 la
= (CHECK_FLAG (prefix
->prefix_options
, OSPF6_PREFIX_OPTION_LA
) ?
849 nu
= (CHECK_FLAG (prefix
->prefix_options
, OSPF6_PREFIX_OPTION_NU
) ?
851 vty_out (vty
, " Prefix Options: %s|%s|%s|%s\n",
854 memset (&in6
, 0, sizeof (in6
));
855 memcpy (&in6
, OSPF6_PREFIX_BODY (prefix
),
856 OSPF6_PREFIX_SPACE (prefix
->prefix_length
));
857 inet_ntop (AF_INET6
, &in6
, buf
, sizeof (buf
));
858 vty_out (vty
, " Prefix: %s/%d\n",
859 buf
, prefix
->prefix_length
);
866 ospf6_intra_prefix_lsa_originate_stub (struct thread
*thread
)
868 struct ospf6_area
*oa
;
870 char buffer
[OSPF6_MAX_LSASIZE
];
871 struct ospf6_lsa_header
*lsa_header
;
872 struct ospf6_lsa
*old
, *lsa
;
874 struct ospf6_intra_prefix_lsa
*intra_prefix_lsa
;
875 struct ospf6_interface
*oi
;
876 struct ospf6_neighbor
*on
;
877 struct ospf6_route
*route
;
878 struct ospf6_prefix
*op
;
879 struct listnode
*i
, *j
;
881 unsigned short prefix_num
= 0;
882 char buf
[PREFIX2STR_BUFFER
];
883 struct ospf6_route_table
*route_advertise
;
885 oa
= (struct ospf6_area
*) THREAD_ARG (thread
);
886 oa
->thread_intra_prefix_lsa
= NULL
;
888 /* find previous LSA */
889 old
= ospf6_lsdb_lookup (htons (OSPF6_LSTYPE_INTRA_PREFIX
),
890 htonl (0), oa
->ospf6
->router_id
, oa
->lsdb
);
892 if (! IS_AREA_ENABLED (oa
))
895 ospf6_lsa_purge (old
);
899 if (IS_OSPF6_DEBUG_ORIGINATE (INTRA_PREFIX
))
900 zlog_debug ("Originate Intra-Area-Prefix-LSA for area %s's stub prefix",
904 memset (buffer
, 0, sizeof (buffer
));
905 lsa_header
= (struct ospf6_lsa_header
*) buffer
;
906 intra_prefix_lsa
= (struct ospf6_intra_prefix_lsa
*)
907 ((caddr_t
) lsa_header
+ sizeof (struct ospf6_lsa_header
));
909 /* Fill Intra-Area-Prefix-LSA */
910 intra_prefix_lsa
->ref_type
= htons (OSPF6_LSTYPE_ROUTER
);
911 intra_prefix_lsa
->ref_id
= htonl (0);
912 intra_prefix_lsa
->ref_adv_router
= oa
->ospf6
->router_id
;
914 route_advertise
= ospf6_route_table_create (0, 0);
916 for (ALL_LIST_ELEMENTS_RO (oa
->if_list
, i
, oi
))
918 if (oi
->state
== OSPF6_INTERFACE_DOWN
)
920 if (IS_OSPF6_DEBUG_ORIGINATE (INTRA_PREFIX
))
921 zlog_debug (" Interface %s is down, ignore", oi
->interface
->name
);
927 for (ALL_LIST_ELEMENTS_RO (oi
->neighbor_list
, j
, on
))
928 if (on
->state
== OSPF6_NEIGHBOR_FULL
)
931 if (oi
->state
!= OSPF6_INTERFACE_LOOPBACK
&&
932 oi
->state
!= OSPF6_INTERFACE_POINTTOPOINT
&&
935 if (IS_OSPF6_DEBUG_ORIGINATE (INTRA_PREFIX
))
936 zlog_debug (" Interface %s is not stub, ignore",
937 oi
->interface
->name
);
941 if (IS_OSPF6_DEBUG_ORIGINATE (INTRA_PREFIX
))
942 zlog_debug (" Interface %s:", oi
->interface
->name
);
944 /* connected prefix to advertise */
945 for (route
= ospf6_route_head (oi
->route_connected
); route
;
946 route
= ospf6_route_best_next (route
))
948 if (IS_OSPF6_DEBUG_ORIGINATE (INTRA_PREFIX
))
950 prefix2str (&route
->prefix
, buf
, sizeof (buf
));
951 zlog_debug (" include %s", buf
);
953 ospf6_route_add (ospf6_route_copy (route
), route_advertise
);
957 if (route_advertise
->count
== 0)
960 ospf6_lsa_purge (old
);
961 ospf6_route_table_delete (route_advertise
);
965 /* put prefixes to advertise */
967 op
= (struct ospf6_prefix
*)
968 ((caddr_t
) intra_prefix_lsa
+ sizeof (struct ospf6_intra_prefix_lsa
));
969 for (route
= ospf6_route_head (route_advertise
); route
;
970 route
= ospf6_route_best_next (route
))
972 op
->prefix_length
= route
->prefix
.prefixlen
;
973 op
->prefix_options
= route
->path
.prefix_options
;
974 op
->prefix_metric
= htons (route
->path
.cost
);
975 memcpy (OSPF6_PREFIX_BODY (op
), &route
->prefix
.u
.prefix6
,
976 OSPF6_PREFIX_SPACE (op
->prefix_length
));
977 op
= OSPF6_PREFIX_NEXT (op
);
981 ospf6_route_table_delete (route_advertise
);
985 if (IS_OSPF6_DEBUG_ORIGINATE (INTRA_PREFIX
))
986 zlog_debug ("Quit to Advertise Intra-Prefix: no route to advertise");
990 intra_prefix_lsa
->prefix_num
= htons (prefix_num
);
992 /* Fill LSA Header */
994 lsa_header
->type
= htons (OSPF6_LSTYPE_INTRA_PREFIX
);
995 lsa_header
->id
= htonl (0);
996 lsa_header
->adv_router
= oa
->ospf6
->router_id
;
998 ospf6_new_ls_seqnum (lsa_header
->type
, lsa_header
->id
,
999 lsa_header
->adv_router
, oa
->lsdb
);
1000 lsa_header
->length
= htons ((caddr_t
) op
- (caddr_t
) lsa_header
);
1003 ospf6_lsa_checksum (lsa_header
);
1006 lsa
= ospf6_lsa_create (lsa_header
);
1009 ospf6_lsa_originate_area (lsa
, oa
);
1016 ospf6_intra_prefix_lsa_originate_transit (struct thread
*thread
)
1018 struct ospf6_interface
*oi
;
1020 char buffer
[OSPF6_MAX_LSASIZE
];
1021 struct ospf6_lsa_header
*lsa_header
;
1022 struct ospf6_lsa
*old
, *lsa
;
1024 struct ospf6_intra_prefix_lsa
*intra_prefix_lsa
;
1025 struct ospf6_neighbor
*on
;
1026 struct ospf6_route
*route
;
1027 struct ospf6_prefix
*op
;
1030 unsigned short prefix_num
= 0;
1031 struct ospf6_route_table
*route_advertise
;
1032 struct ospf6_link_lsa
*link_lsa
;
1033 char *start
, *end
, *current
;
1035 char buf
[PREFIX2STR_BUFFER
];
1037 oi
= (struct ospf6_interface
*) THREAD_ARG (thread
);
1038 oi
->thread_intra_prefix_lsa
= NULL
;
1042 /* find previous LSA */
1043 old
= ospf6_lsdb_lookup (htons (OSPF6_LSTYPE_INTRA_PREFIX
),
1044 htonl (oi
->interface
->ifindex
),
1045 oi
->area
->ospf6
->router_id
, oi
->area
->lsdb
);
1047 if (CHECK_FLAG (oi
->flag
, OSPF6_INTERFACE_DISABLE
))
1050 ospf6_lsa_purge (old
);
1054 if (IS_OSPF6_DEBUG_ORIGINATE (INTRA_PREFIX
))
1055 zlog_debug ("Originate Intra-Area-Prefix-LSA for interface %s's prefix",
1056 oi
->interface
->name
);
1058 /* prepare buffer */
1059 memset (buffer
, 0, sizeof (buffer
));
1060 lsa_header
= (struct ospf6_lsa_header
*) buffer
;
1061 intra_prefix_lsa
= (struct ospf6_intra_prefix_lsa
*)
1062 ((caddr_t
) lsa_header
+ sizeof (struct ospf6_lsa_header
));
1064 /* Fill Intra-Area-Prefix-LSA */
1065 intra_prefix_lsa
->ref_type
= htons (OSPF6_LSTYPE_NETWORK
);
1066 intra_prefix_lsa
->ref_id
= htonl (oi
->interface
->ifindex
);
1067 intra_prefix_lsa
->ref_adv_router
= oi
->area
->ospf6
->router_id
;
1069 if (oi
->state
!= OSPF6_INTERFACE_DR
)
1071 if (IS_OSPF6_DEBUG_ORIGINATE (INTRA_PREFIX
))
1072 zlog_debug (" Interface is not DR");
1074 ospf6_lsa_purge (old
);
1079 for (ALL_LIST_ELEMENTS_RO (oi
->neighbor_list
, i
, on
))
1080 if (on
->state
== OSPF6_NEIGHBOR_FULL
)
1083 if (full_count
== 0)
1085 if (IS_OSPF6_DEBUG_ORIGINATE (INTRA_PREFIX
))
1086 zlog_debug (" Interface is stub");
1088 ospf6_lsa_purge (old
);
1092 /* connected prefix to advertise */
1093 route_advertise
= ospf6_route_table_create (0, 0);
1095 type
= ntohs (OSPF6_LSTYPE_LINK
);
1096 for (ALL_LSDB_TYPED(oi
->lsdb
, type
, lsa
))
1098 if (OSPF6_LSA_IS_MAXAGE (lsa
))
1101 if (IS_OSPF6_DEBUG_ORIGINATE (INTRA_PREFIX
))
1102 zlog_debug (" include prefix from %s", lsa
->name
);
1104 if (lsa
->header
->adv_router
!= oi
->area
->ospf6
->router_id
)
1106 on
= ospf6_neighbor_lookup (lsa
->header
->adv_router
, oi
);
1107 if (on
== NULL
|| on
->state
!= OSPF6_NEIGHBOR_FULL
)
1109 if (IS_OSPF6_DEBUG_ORIGINATE (INTRA_PREFIX
))
1110 zlog_debug (" Neighbor not found or not Full, ignore");
1115 link_lsa
= (struct ospf6_link_lsa
*)
1116 ((caddr_t
) lsa
->header
+ sizeof (struct ospf6_lsa_header
));
1118 prefix_num
= (unsigned short) ntohl (link_lsa
->prefix_num
);
1119 start
= (char *) link_lsa
+ sizeof (struct ospf6_link_lsa
);
1120 end
= (char *) lsa
->header
+ ntohs (lsa
->header
->length
);
1121 for (current
= start
; current
< end
&& prefix_num
;
1122 current
+= OSPF6_PREFIX_SIZE (op
))
1124 op
= (struct ospf6_prefix
*) current
;
1125 if (op
->prefix_length
== 0 ||
1126 current
+ OSPF6_PREFIX_SIZE (op
) > end
)
1129 route
= ospf6_route_create ();
1131 route
->type
= OSPF6_DEST_TYPE_NETWORK
;
1132 route
->prefix
.family
= AF_INET6
;
1133 route
->prefix
.prefixlen
= op
->prefix_length
;
1134 memset (&route
->prefix
.u
.prefix6
, 0, sizeof (struct in6_addr
));
1135 memcpy (&route
->prefix
.u
.prefix6
, OSPF6_PREFIX_BODY (op
),
1136 OSPF6_PREFIX_SPACE (op
->prefix_length
));
1138 route
->path
.origin
.type
= lsa
->header
->type
;
1139 route
->path
.origin
.id
= lsa
->header
->id
;
1140 route
->path
.origin
.adv_router
= lsa
->header
->adv_router
;
1141 route
->path
.options
[0] = link_lsa
->options
[0];
1142 route
->path
.options
[1] = link_lsa
->options
[1];
1143 route
->path
.options
[2] = link_lsa
->options
[2];
1144 route
->path
.prefix_options
= op
->prefix_options
;
1145 route
->path
.area_id
= oi
->area
->area_id
;
1146 route
->path
.type
= OSPF6_PATH_TYPE_INTRA
;
1148 if (IS_OSPF6_DEBUG_ORIGINATE (INTRA_PREFIX
))
1150 prefix2str (&route
->prefix
, buf
, sizeof (buf
));
1151 zlog_debug (" include %s", buf
);
1154 ospf6_route_add (route
, route_advertise
);
1157 if (current
!= end
&& IS_OSPF6_DEBUG_ORIGINATE (INTRA_PREFIX
))
1158 zlog_debug ("Trailing garbage in %s", lsa
->name
);
1161 op
= (struct ospf6_prefix
*)
1162 ((caddr_t
) intra_prefix_lsa
+ sizeof (struct ospf6_intra_prefix_lsa
));
1165 for (route
= ospf6_route_head (route_advertise
); route
;
1166 route
= ospf6_route_best_next (route
))
1168 op
->prefix_length
= route
->prefix
.prefixlen
;
1169 op
->prefix_options
= route
->path
.prefix_options
;
1170 op
->prefix_metric
= htons (0);
1171 memcpy (OSPF6_PREFIX_BODY (op
), &route
->prefix
.u
.prefix6
,
1172 OSPF6_PREFIX_SPACE (op
->prefix_length
));
1173 op
= OSPF6_PREFIX_NEXT (op
);
1177 ospf6_route_table_delete (route_advertise
);
1179 if (prefix_num
== 0)
1181 if (IS_OSPF6_DEBUG_ORIGINATE (INTRA_PREFIX
))
1182 zlog_debug ("Quit to Advertise Intra-Prefix: no route to advertise");
1186 intra_prefix_lsa
->prefix_num
= htons (prefix_num
);
1188 /* Fill LSA Header */
1189 lsa_header
->age
= 0;
1190 lsa_header
->type
= htons (OSPF6_LSTYPE_INTRA_PREFIX
);
1191 lsa_header
->id
= htonl (oi
->interface
->ifindex
);
1192 lsa_header
->adv_router
= oi
->area
->ospf6
->router_id
;
1193 lsa_header
->seqnum
=
1194 ospf6_new_ls_seqnum (lsa_header
->type
, lsa_header
->id
,
1195 lsa_header
->adv_router
, oi
->area
->lsdb
);
1196 lsa_header
->length
= htons ((caddr_t
) op
- (caddr_t
) lsa_header
);
1199 ospf6_lsa_checksum (lsa_header
);
1202 lsa
= ospf6_lsa_create (lsa_header
);
1205 ospf6_lsa_originate_area (lsa
, oi
->area
);
1211 ospf6_intra_prefix_lsa_add (struct ospf6_lsa
*lsa
)
1213 struct ospf6_area
*oa
;
1214 struct ospf6_intra_prefix_lsa
*intra_prefix_lsa
;
1215 struct prefix ls_prefix
;
1216 struct ospf6_route
*route
, *ls_entry
;
1218 struct ospf6_prefix
*op
;
1219 char *start
, *current
, *end
;
1220 char buf
[PREFIX2STR_BUFFER
];
1221 struct interface
*ifp
;
1222 int direct_connect
= 0;
1224 if (OSPF6_LSA_IS_MAXAGE (lsa
))
1227 if (IS_OSPF6_DEBUG_EXAMIN (INTRA_PREFIX
))
1228 zlog_debug ("%s found", lsa
->name
);
1230 oa
= OSPF6_AREA (lsa
->lsdb
->data
);
1232 intra_prefix_lsa
= (struct ospf6_intra_prefix_lsa
*)
1233 OSPF6_LSA_HEADER_END (lsa
->header
);
1234 if (intra_prefix_lsa
->ref_type
== htons (OSPF6_LSTYPE_ROUTER
))
1235 ospf6_linkstate_prefix (intra_prefix_lsa
->ref_adv_router
,
1236 htonl (0), &ls_prefix
);
1237 else if (intra_prefix_lsa
->ref_type
== htons (OSPF6_LSTYPE_NETWORK
))
1238 ospf6_linkstate_prefix (intra_prefix_lsa
->ref_adv_router
,
1239 intra_prefix_lsa
->ref_id
, &ls_prefix
);
1242 if (IS_OSPF6_DEBUG_EXAMIN (INTRA_PREFIX
))
1243 zlog_debug ("Unknown reference LS-type: %#hx",
1244 ntohs (intra_prefix_lsa
->ref_type
));
1248 ls_entry
= ospf6_route_lookup (&ls_prefix
, oa
->spf_table
);
1249 if (ls_entry
== NULL
)
1251 if (IS_OSPF6_DEBUG_EXAMIN (INTRA_PREFIX
))
1253 ospf6_linkstate_prefix2str (&ls_prefix
, buf
, sizeof (buf
));
1254 zlog_debug ("LS entry does not exist: %s", buf
);
1259 if (intra_prefix_lsa
->ref_adv_router
== oa
->ospf6
->router_id
)
1261 /* the intra-prefix are directly connected */
1265 prefix_num
= ntohs (intra_prefix_lsa
->prefix_num
);
1266 start
= (caddr_t
) intra_prefix_lsa
+
1267 sizeof (struct ospf6_intra_prefix_lsa
);
1268 end
= OSPF6_LSA_END (lsa
->header
);
1269 for (current
= start
; current
< end
; current
+= OSPF6_PREFIX_SIZE (op
))
1271 op
= (struct ospf6_prefix
*) current
;
1272 if (prefix_num
== 0)
1274 if (end
< current
+ OSPF6_PREFIX_SIZE (op
))
1277 /* Appendix A.4.1.1 */
1278 if (CHECK_FLAG(op
->prefix_options
, OSPF6_PREFIX_OPTION_NU
))
1280 if (IS_OSPF6_DEBUG_EXAMIN (INTRA_PREFIX
))
1282 ospf6_linkstate_prefix2str ((struct prefix
*)OSPF6_PREFIX_BODY(op
),
1284 zlog_debug ("%s: Skipping Prefix %s has NU option set",
1290 route
= ospf6_route_create ();
1292 memset (&route
->prefix
, 0, sizeof (struct prefix
));
1293 route
->prefix
.family
= AF_INET6
;
1294 route
->prefix
.prefixlen
= op
->prefix_length
;
1295 ospf6_prefix_in6_addr (&route
->prefix
.u
.prefix6
, op
);
1297 route
->type
= OSPF6_DEST_TYPE_NETWORK
;
1298 route
->path
.origin
.type
= lsa
->header
->type
;
1299 route
->path
.origin
.id
= lsa
->header
->id
;
1300 route
->path
.origin
.adv_router
= lsa
->header
->adv_router
;
1301 route
->path
.prefix_options
= op
->prefix_options
;
1302 route
->path
.area_id
= oa
->area_id
;
1303 route
->path
.type
= OSPF6_PATH_TYPE_INTRA
;
1304 route
->path
.metric_type
= 1;
1305 route
->path
.cost
= ls_entry
->path
.cost
+
1306 ntohs (op
->prefix_metric
);
1310 ifp
= if_lookup_prefix(&route
->prefix
, VRF_DEFAULT
);
1312 ospf6_route_add_nexthop (route
, ifp
->ifindex
, NULL
);
1316 ospf6_route_copy_nexthops (route
, ls_entry
);
1319 if (IS_OSPF6_DEBUG_EXAMIN (INTRA_PREFIX
))
1321 prefix2str (&route
->prefix
, buf
, sizeof (buf
));
1322 zlog_debug (" add %s", buf
);
1325 ospf6_route_add (route
, oa
->route_table
);
1329 if (current
!= end
&& IS_OSPF6_DEBUG_EXAMIN (INTRA_PREFIX
))
1330 zlog_debug ("Trailing garbage ignored");
1334 ospf6_intra_prefix_lsa_remove (struct ospf6_lsa
*lsa
)
1336 struct ospf6_area
*oa
;
1337 struct ospf6_intra_prefix_lsa
*intra_prefix_lsa
;
1338 struct prefix prefix
;
1339 struct ospf6_route
*route
, *nroute
;
1341 struct ospf6_prefix
*op
;
1342 char *start
, *current
, *end
;
1343 char buf
[PREFIX2STR_BUFFER
];
1345 if (IS_OSPF6_DEBUG_EXAMIN (INTRA_PREFIX
))
1346 zlog_debug ("%s disappearing", lsa
->name
);
1348 oa
= OSPF6_AREA (lsa
->lsdb
->data
);
1350 intra_prefix_lsa
= (struct ospf6_intra_prefix_lsa
*)
1351 OSPF6_LSA_HEADER_END (lsa
->header
);
1353 prefix_num
= ntohs (intra_prefix_lsa
->prefix_num
);
1354 start
= (caddr_t
) intra_prefix_lsa
+
1355 sizeof (struct ospf6_intra_prefix_lsa
);
1356 end
= OSPF6_LSA_END (lsa
->header
);
1357 for (current
= start
; current
< end
; current
+= OSPF6_PREFIX_SIZE (op
))
1359 op
= (struct ospf6_prefix
*) current
;
1360 if (prefix_num
== 0)
1362 if (end
< current
+ OSPF6_PREFIX_SIZE (op
))
1366 memset (&prefix
, 0, sizeof (struct prefix
));
1367 prefix
.family
= AF_INET6
;
1368 prefix
.prefixlen
= op
->prefix_length
;
1369 ospf6_prefix_in6_addr (&prefix
.u
.prefix6
, op
);
1371 route
= ospf6_route_lookup (&prefix
, oa
->route_table
);
1375 for (ospf6_route_lock (route
);
1376 route
&& ospf6_route_is_prefix (&prefix
, route
);
1379 nroute
= ospf6_route_next (route
);
1380 if (route
->type
!= OSPF6_DEST_TYPE_NETWORK
)
1382 if (route
->path
.area_id
!= oa
->area_id
)
1384 if (route
->path
.type
!= OSPF6_PATH_TYPE_INTRA
)
1386 if (route
->path
.origin
.type
!= lsa
->header
->type
||
1387 route
->path
.origin
.id
!= lsa
->header
->id
||
1388 route
->path
.origin
.adv_router
!= lsa
->header
->adv_router
)
1391 if (IS_OSPF6_DEBUG_EXAMIN (INTRA_PREFIX
))
1393 prefix2str (&route
->prefix
, buf
, sizeof (buf
));
1394 zlog_debug ("remove %s", buf
);
1396 ospf6_route_remove (route
, oa
->route_table
);
1399 ospf6_route_unlock (route
);
1402 if (current
!= end
&& IS_OSPF6_DEBUG_EXAMIN (INTRA_PREFIX
))
1403 zlog_debug ("Trailing garbage ignored");
1407 ospf6_intra_route_calculation (struct ospf6_area
*oa
)
1409 struct ospf6_route
*route
, *nroute
;
1411 struct ospf6_lsa
*lsa
;
1412 void (*hook_add
) (struct ospf6_route
*) = NULL
;
1413 void (*hook_remove
) (struct ospf6_route
*) = NULL
;
1415 if (IS_OSPF6_DEBUG_EXAMIN (INTRA_PREFIX
))
1416 zlog_debug ("Re-examin intra-routes for area %s", oa
->name
);
1418 hook_add
= oa
->route_table
->hook_add
;
1419 hook_remove
= oa
->route_table
->hook_remove
;
1420 oa
->route_table
->hook_add
= NULL
;
1421 oa
->route_table
->hook_remove
= NULL
;
1423 for (route
= ospf6_route_head (oa
->route_table
); route
;
1424 route
= ospf6_route_next (route
))
1425 route
->flag
= OSPF6_ROUTE_REMOVE
;
1427 type
= htons (OSPF6_LSTYPE_INTRA_PREFIX
);
1428 for (ALL_LSDB_TYPED(oa
->lsdb
, type
, lsa
))
1429 ospf6_intra_prefix_lsa_add (lsa
);
1431 oa
->route_table
->hook_add
= hook_add
;
1432 oa
->route_table
->hook_remove
= hook_remove
;
1434 for (route
= ospf6_route_head (oa
->route_table
); route
;
1437 nroute
= ospf6_route_next (route
);
1438 if (CHECK_FLAG (route
->flag
, OSPF6_ROUTE_REMOVE
) &&
1439 CHECK_FLAG (route
->flag
, OSPF6_ROUTE_ADD
))
1441 UNSET_FLAG (route
->flag
, OSPF6_ROUTE_REMOVE
);
1442 UNSET_FLAG (route
->flag
, OSPF6_ROUTE_ADD
);
1445 if (CHECK_FLAG (route
->flag
, OSPF6_ROUTE_REMOVE
))
1446 ospf6_route_remove (route
, oa
->route_table
);
1447 else if (CHECK_FLAG (route
->flag
, OSPF6_ROUTE_ADD
) ||
1448 CHECK_FLAG (route
->flag
, OSPF6_ROUTE_CHANGE
))
1451 (*hook_add
) (route
);
1456 /* Redo the summaries as things might have changed */
1457 ospf6_abr_originate_summary (route
);
1462 if (IS_OSPF6_DEBUG_EXAMIN (INTRA_PREFIX
))
1463 zlog_debug ("Re-examin intra-routes for area %s: Done", oa
->name
);
1467 ospf6_brouter_debug_print (struct ospf6_route
*brouter
)
1469 u_int32_t brouter_id
;
1470 char brouter_name
[16];
1472 char destination
[64];
1473 char installed
[16], changed
[16];
1474 struct timeval now
, res
;
1475 char id
[16], adv_router
[16];
1476 char capa
[16], options
[16];
1478 brouter_id
= ADV_ROUTER_IN_PREFIX (&brouter
->prefix
);
1479 inet_ntop (AF_INET
, &brouter_id
, brouter_name
, sizeof (brouter_name
));
1480 inet_ntop (AF_INET
, &brouter
->path
.area_id
, area_name
, sizeof (area_name
));
1481 ospf6_linkstate_prefix2str (&brouter
->prefix
, destination
,
1482 sizeof (destination
));
1485 timersub (&now
, &brouter
->installed
, &res
);
1486 timerstring (&res
, installed
, sizeof (installed
));
1489 timersub (&now
, &brouter
->changed
, &res
);
1490 timerstring (&res
, changed
, sizeof (changed
));
1492 inet_ntop (AF_INET
, &brouter
->path
.origin
.id
, id
, sizeof (id
));
1493 inet_ntop (AF_INET
, &brouter
->path
.origin
.adv_router
, adv_router
,
1494 sizeof (adv_router
));
1496 ospf6_options_printbuf (brouter
->path
.options
, options
, sizeof (options
));
1497 ospf6_capability_printbuf (brouter
->path
.router_bits
, capa
, sizeof (capa
));
1499 zlog_info ("Brouter: %s via area %s", brouter_name
, area_name
);
1500 zlog_info (" memory: prev: %p this: %p next: %p parent rnode: %p",
1501 (void *)brouter
->prev
, (void *)brouter
, (void *)brouter
->next
,
1502 (void *)brouter
->rnode
);
1503 zlog_info (" type: %d prefix: %s installed: %s changed: %s",
1504 brouter
->type
, destination
, installed
, changed
);
1505 zlog_info (" lock: %d flags: %s%s%s%s", brouter
->lock
,
1506 (CHECK_FLAG (brouter
->flag
, OSPF6_ROUTE_BEST
) ? "B" : "-"),
1507 (CHECK_FLAG (brouter
->flag
, OSPF6_ROUTE_ADD
) ? "A" : "-"),
1508 (CHECK_FLAG (brouter
->flag
, OSPF6_ROUTE_REMOVE
) ? "R" : "-"),
1509 (CHECK_FLAG (brouter
->flag
, OSPF6_ROUTE_CHANGE
) ? "C" : "-"));
1510 zlog_info (" path type: %s ls-origin %s id: %s adv-router %s",
1511 OSPF6_PATH_TYPE_NAME (brouter
->path
.type
),
1512 ospf6_lstype_name (brouter
->path
.origin
.type
),
1514 zlog_info (" options: %s router-bits: %s metric-type: %d metric: %d/%d",
1515 options
, capa
, brouter
->path
.metric_type
,
1516 brouter
->path
.cost
, brouter
->path
.u
.cost_e2
);
1520 ospf6_intra_brouter_calculation (struct ospf6_area
*oa
)
1522 struct ospf6_route
*brouter
, *nbrouter
, *copy
;
1523 void (*hook_add
) (struct ospf6_route
*) = NULL
;
1524 void (*hook_remove
) (struct ospf6_route
*) = NULL
;
1525 u_int32_t brouter_id
;
1526 char brouter_name
[16];
1528 if (IS_OSPF6_DEBUG_BROUTER_SPECIFIC_AREA_ID (oa
->area_id
))
1529 zlog_info ("border-router calculation for area %s", oa
->name
);
1531 hook_add
= oa
->ospf6
->brouter_table
->hook_add
;
1532 hook_remove
= oa
->ospf6
->brouter_table
->hook_remove
;
1533 oa
->ospf6
->brouter_table
->hook_add
= NULL
;
1534 oa
->ospf6
->brouter_table
->hook_remove
= NULL
;
1536 /* withdraw the previous router entries for the area */
1537 for (brouter
= ospf6_route_head (oa
->ospf6
->brouter_table
); brouter
;
1538 brouter
= ospf6_route_next (brouter
))
1540 brouter_id
= ADV_ROUTER_IN_PREFIX (&brouter
->prefix
);
1541 inet_ntop (AF_INET
, &brouter_id
, brouter_name
, sizeof (brouter_name
));
1542 if (brouter
->path
.area_id
!= oa
->area_id
)
1544 SET_FLAG (brouter
->flag
, OSPF6_ROUTE_REMOVE
);
1546 if (IS_OSPF6_DEBUG_BROUTER_SPECIFIC_ROUTER_ID (brouter_id
) ||
1547 IS_OSPF6_DEBUG_ROUTE (MEMORY
))
1549 zlog_info ("%p: mark as removing: area %s brouter %s",
1550 (void *)brouter
, oa
->name
, brouter_name
);
1551 ospf6_brouter_debug_print (brouter
);
1555 for (brouter
= ospf6_route_head (oa
->spf_table
); brouter
;
1556 brouter
= ospf6_route_next (brouter
))
1558 brouter_id
= ADV_ROUTER_IN_PREFIX (&brouter
->prefix
);
1559 inet_ntop (AF_INET
, &brouter_id
, brouter_name
, sizeof (brouter_name
));
1561 if (brouter
->type
!= OSPF6_DEST_TYPE_LINKSTATE
)
1563 if (ospf6_linkstate_prefix_id (&brouter
->prefix
) != htonl (0))
1565 if (! CHECK_FLAG (brouter
->path
.router_bits
, OSPF6_ROUTER_BIT_E
) &&
1566 ! CHECK_FLAG (brouter
->path
.router_bits
, OSPF6_ROUTER_BIT_B
))
1569 if (! OSPF6_OPT_ISSET (brouter
->path
.options
, OSPF6_OPT_V6
) ||
1570 ! OSPF6_OPT_ISSET (brouter
->path
.options
, OSPF6_OPT_R
))
1573 copy
= ospf6_route_copy (brouter
);
1574 copy
->type
= OSPF6_DEST_TYPE_ROUTER
;
1575 copy
->path
.area_id
= oa
->area_id
;
1576 ospf6_route_add (copy
, oa
->ospf6
->brouter_table
);
1578 if (IS_OSPF6_DEBUG_BROUTER_SPECIFIC_ROUTER_ID (brouter_id
) ||
1579 IS_OSPF6_DEBUG_ROUTE (MEMORY
))
1581 zlog_info ("%p: transfer: area %s brouter %s",
1582 (void *)brouter
, oa
->name
, brouter_name
);
1583 ospf6_brouter_debug_print (brouter
);
1587 oa
->ospf6
->brouter_table
->hook_add
= hook_add
;
1588 oa
->ospf6
->brouter_table
->hook_remove
= hook_remove
;
1590 for (brouter
= ospf6_route_head (oa
->ospf6
->brouter_table
); brouter
;
1593 nbrouter
= ospf6_route_next (brouter
);
1594 brouter_id
= ADV_ROUTER_IN_PREFIX (&brouter
->prefix
);
1595 inet_ntop (AF_INET
, &brouter_id
, brouter_name
, sizeof (brouter_name
));
1597 if (brouter
->path
.area_id
!= oa
->area_id
)
1600 if (CHECK_FLAG (brouter
->flag
, OSPF6_ROUTE_WAS_REMOVED
))
1603 if (CHECK_FLAG (brouter
->flag
, OSPF6_ROUTE_REMOVE
) &&
1604 CHECK_FLAG (brouter
->flag
, OSPF6_ROUTE_ADD
))
1606 UNSET_FLAG (brouter
->flag
, OSPF6_ROUTE_REMOVE
);
1607 UNSET_FLAG (brouter
->flag
, OSPF6_ROUTE_ADD
);
1610 if (CHECK_FLAG (brouter
->flag
, OSPF6_ROUTE_REMOVE
))
1612 if (IS_OSPF6_DEBUG_BROUTER
||
1613 IS_OSPF6_DEBUG_BROUTER_SPECIFIC_ROUTER_ID (brouter_id
) ||
1614 IS_OSPF6_DEBUG_BROUTER_SPECIFIC_AREA_ID (oa
->area_id
))
1615 zlog_info ("brouter %s disappears via area %s",
1616 brouter_name
, oa
->name
);
1617 ospf6_route_remove (brouter
, oa
->ospf6
->brouter_table
);
1620 else if (CHECK_FLAG (brouter
->flag
, OSPF6_ROUTE_ADD
) ||
1621 CHECK_FLAG (brouter
->flag
, OSPF6_ROUTE_CHANGE
))
1623 if (IS_OSPF6_DEBUG_BROUTER
||
1624 IS_OSPF6_DEBUG_BROUTER_SPECIFIC_ROUTER_ID (brouter_id
) ||
1625 IS_OSPF6_DEBUG_BROUTER_SPECIFIC_AREA_ID (oa
->area_id
))
1626 zlog_info ("brouter %s appears via area %s",
1627 brouter_name
, oa
->name
);
1631 (*hook_add
) (brouter
);
1635 if (IS_OSPF6_DEBUG_BROUTER_SPECIFIC_ROUTER_ID (brouter_id
) ||
1636 IS_OSPF6_DEBUG_BROUTER_SPECIFIC_AREA_ID (oa
->area_id
))
1637 zlog_info ("brouter %s still exists via area %s",
1638 brouter_name
, oa
->name
);
1639 /* But re-originate summaries */
1640 ospf6_abr_originate_summary (brouter
);
1645 UNSET_FLAG (brouter
->flag
, OSPF6_ROUTE_ADD
);
1646 UNSET_FLAG (brouter
->flag
, OSPF6_ROUTE_CHANGE
);
1650 if (IS_OSPF6_DEBUG_BROUTER_SPECIFIC_AREA_ID (oa
->area_id
))
1651 zlog_info ("border-router calculation for area %s: done", oa
->name
);
1654 struct ospf6_lsa_handler router_handler
=
1656 OSPF6_LSTYPE_ROUTER
,
1659 ospf6_router_lsa_show
,
1660 ospf6_router_lsa_get_nbr_id
1663 struct ospf6_lsa_handler network_handler
=
1665 OSPF6_LSTYPE_NETWORK
,
1668 ospf6_network_lsa_show
,
1669 ospf6_network_lsa_get_ar_id
1672 struct ospf6_lsa_handler link_handler
=
1677 ospf6_link_lsa_show
,
1678 ospf6_link_lsa_get_prefix_str
1681 struct ospf6_lsa_handler intra_prefix_handler
=
1683 OSPF6_LSTYPE_INTRA_PREFIX
,
1686 ospf6_intra_prefix_lsa_show
,
1687 ospf6_intra_prefix_lsa_get_prefix_str
1691 ospf6_intra_init (void)
1693 ospf6_install_lsa_handler (&router_handler
);
1694 ospf6_install_lsa_handler (&network_handler
);
1695 ospf6_install_lsa_handler (&link_handler
);
1696 ospf6_install_lsa_handler (&intra_prefix_handler
);
1699 DEFUN (debug_ospf6_brouter
,
1700 debug_ospf6_brouter_cmd
,
1701 "debug ospf6 border-routers",
1704 "Debug border router\n"
1707 OSPF6_DEBUG_BROUTER_ON ();
1711 DEFUN (no_debug_ospf6_brouter
,
1712 no_debug_ospf6_brouter_cmd
,
1713 "no debug ospf6 border-routers",
1717 "Debug border router\n"
1720 OSPF6_DEBUG_BROUTER_OFF ();
1724 DEFUN (debug_ospf6_brouter_router
,
1725 debug_ospf6_brouter_router_cmd
,
1726 "debug ospf6 border-routers router-id A.B.C.D",
1729 "Debug border router\n"
1730 "Debug specific border router\n"
1731 "Specify border-router's router-id\n"
1735 u_int32_t router_id
;
1736 inet_pton (AF_INET
, argv
[idx_ipv4
]->arg
, &router_id
);
1737 OSPF6_DEBUG_BROUTER_SPECIFIC_ROUTER_ON (router_id
);
1741 DEFUN (no_debug_ospf6_brouter_router
,
1742 no_debug_ospf6_brouter_router_cmd
,
1743 "no debug ospf6 border-routers router-id",
1747 "Debug border router\n"
1748 "Debug specific border router\n"
1751 OSPF6_DEBUG_BROUTER_SPECIFIC_ROUTER_OFF ();
1755 DEFUN (debug_ospf6_brouter_area
,
1756 debug_ospf6_brouter_area_cmd
,
1757 "debug ospf6 border-routers area-id A.B.C.D",
1760 "Debug border router\n"
1761 "Debug border routers in specific Area\n"
1767 inet_pton (AF_INET
, argv
[idx_ipv4
]->arg
, &area_id
);
1768 OSPF6_DEBUG_BROUTER_SPECIFIC_AREA_ON (area_id
);
1772 DEFUN (no_debug_ospf6_brouter_area
,
1773 no_debug_ospf6_brouter_area_cmd
,
1774 "no debug ospf6 border-routers area-id",
1778 "Debug border router\n"
1779 "Debug border routers in specific Area\n"
1782 OSPF6_DEBUG_BROUTER_SPECIFIC_AREA_OFF ();
1787 config_write_ospf6_debug_brouter (struct vty
*vty
)
1790 if (IS_OSPF6_DEBUG_BROUTER
)
1791 vty_out (vty
, "debug ospf6 border-routers\n");
1792 if (IS_OSPF6_DEBUG_BROUTER_SPECIFIC_ROUTER
)
1794 inet_ntop (AF_INET
, &conf_debug_ospf6_brouter_specific_router_id
,
1796 vty_out (vty
, "debug ospf6 border-routers router-id %s\n", buf
);
1798 if (IS_OSPF6_DEBUG_BROUTER_SPECIFIC_AREA
)
1800 inet_ntop (AF_INET
, &conf_debug_ospf6_brouter_specific_area_id
,
1802 vty_out (vty
, "debug ospf6 border-routers area-id %s\n", buf
);
1808 install_element_ospf6_debug_brouter (void)
1810 install_element (ENABLE_NODE
, &debug_ospf6_brouter_cmd
);
1811 install_element (ENABLE_NODE
, &debug_ospf6_brouter_router_cmd
);
1812 install_element (ENABLE_NODE
, &debug_ospf6_brouter_area_cmd
);
1813 install_element (ENABLE_NODE
, &no_debug_ospf6_brouter_cmd
);
1814 install_element (ENABLE_NODE
, &no_debug_ospf6_brouter_router_cmd
);
1815 install_element (ENABLE_NODE
, &no_debug_ospf6_brouter_area_cmd
);
1816 install_element (CONFIG_NODE
, &debug_ospf6_brouter_cmd
);
1817 install_element (CONFIG_NODE
, &debug_ospf6_brouter_router_cmd
);
1818 install_element (CONFIG_NODE
, &debug_ospf6_brouter_area_cmd
);
1819 install_element (CONFIG_NODE
, &no_debug_ospf6_brouter_cmd
);
1820 install_element (CONFIG_NODE
, &no_debug_ospf6_brouter_router_cmd
);
1821 install_element (CONFIG_NODE
, &no_debug_ospf6_brouter_area_cmd
);