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
17 * along with GNU Zebra; see the file COPYING. If not, write to the
18 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19 * Boston, MA 02111-1307, USA.
24 /* Include other stuffs */
33 #include "ospf6_proto.h"
34 #include "ospf6_lsa.h"
35 #include "ospf6_lsdb.h"
36 #include "ospf6_message.h"
38 #include "ospf6_top.h"
39 #include "ospf6_area.h"
40 #include "ospf6_interface.h"
41 #include "ospf6_neighbor.h"
43 #include "ospf6_flood.h"
46 vector ospf6_lsa_handler_vector
;
49 ospf6_unknown_lsa_show (struct vty
*vty
, struct ospf6_lsa
*lsa
)
51 u_char
*start
, *end
, *current
;
54 start
= (u_char
*) lsa
->header
+ sizeof (struct ospf6_lsa_header
);
55 end
= (u_char
*) lsa
->header
+ ntohs (lsa
->header
->length
);
57 vty_out (vty
, " Unknown contents:%s", VNL
);
58 for (current
= start
; current
< end
; current
++)
60 if ((current
- start
) % 16 == 0)
61 vty_out (vty
, "%s ", VNL
);
62 else if ((current
- start
) % 4 == 0)
65 snprintf (byte
, sizeof (byte
), "%02x", *current
);
66 vty_out (vty
, "%s", byte
);
69 vty_out (vty
, "%s%s", VNL
, VNL
);
73 struct ospf6_lsa_handler unknown_handler
=
77 ospf6_unknown_lsa_show
,
82 ospf6_install_lsa_handler (struct ospf6_lsa_handler
*handler
)
84 /* type in handler is host byte order */
85 int index
= handler
->type
& OSPF6_LSTYPE_FCODE_MASK
;
86 vector_set_index (ospf6_lsa_handler_vector
, index
, handler
);
89 struct ospf6_lsa_handler
*
90 ospf6_get_lsa_handler (u_int16_t type
)
92 struct ospf6_lsa_handler
*handler
= NULL
;
93 unsigned int index
= ntohs (type
) & OSPF6_LSTYPE_FCODE_MASK
;
95 if (index
>= vector_active (ospf6_lsa_handler_vector
))
96 handler
= &unknown_handler
;
98 handler
= vector_slot (ospf6_lsa_handler_vector
, index
);
101 handler
= &unknown_handler
;
107 ospf6_lstype_name (u_int16_t type
)
110 struct ospf6_lsa_handler
*handler
;
112 handler
= ospf6_get_lsa_handler (type
);
113 if (handler
&& handler
!= &unknown_handler
)
114 return handler
->name
;
116 snprintf (buf
, sizeof (buf
), "0x%04hx", ntohs (type
));
121 ospf6_lstype_debug (u_int16_t type
)
123 struct ospf6_lsa_handler
*handler
;
124 handler
= ospf6_get_lsa_handler (type
);
125 return handler
->debug
;
128 /* RFC2328: Section 13.2 */
130 ospf6_lsa_is_differ (struct ospf6_lsa
*lsa1
,
131 struct ospf6_lsa
*lsa2
)
135 assert (OSPF6_LSA_IS_SAME (lsa1
, lsa2
));
137 /* XXX, Options ??? */
139 ospf6_lsa_age_current (lsa1
);
140 ospf6_lsa_age_current (lsa2
);
141 if (ntohs (lsa1
->header
->age
) == MAXAGE
&&
142 ntohs (lsa2
->header
->age
) != MAXAGE
)
144 if (ntohs (lsa1
->header
->age
) != MAXAGE
&&
145 ntohs (lsa2
->header
->age
) == MAXAGE
)
149 if (ntohs (lsa1
->header
->length
) != ntohs (lsa2
->header
->length
))
152 len
= ntohs (lsa1
->header
->length
) - sizeof (struct ospf6_lsa_header
);
153 return memcmp (lsa1
->header
+ 1, lsa2
->header
+ 1, len
);
157 ospf6_lsa_is_changed (struct ospf6_lsa
*lsa1
,
158 struct ospf6_lsa
*lsa2
)
162 if (OSPF6_LSA_IS_MAXAGE (lsa1
) ^ OSPF6_LSA_IS_MAXAGE (lsa2
))
164 if (ntohs (lsa1
->header
->length
) != ntohs (lsa2
->header
->length
))
167 length
= OSPF6_LSA_SIZE (lsa1
->header
) - sizeof (struct ospf6_lsa_header
);
170 return memcmp (OSPF6_LSA_HEADER_END (lsa1
->header
),
171 OSPF6_LSA_HEADER_END (lsa2
->header
), length
);
174 /* ospf6 age functions */
175 /* calculate birth */
177 ospf6_lsa_age_set (struct ospf6_lsa
*lsa
)
181 assert (lsa
&& lsa
->header
);
183 if (quagga_gettime (QUAGGA_CLK_MONOTONIC
, &now
) < 0)
184 zlog_warn ("LSA: quagga_gettime failed, may fail LSA AGEs: %s",
185 safe_strerror (errno
));
187 lsa
->birth
.tv_sec
= now
.tv_sec
- ntohs (lsa
->header
->age
);
188 lsa
->birth
.tv_usec
= now
.tv_usec
;
193 /* this function calculates current age from its birth,
194 then update age field of LSA header. return value is current age */
196 ospf6_lsa_age_current (struct ospf6_lsa
*lsa
)
203 assert (lsa
->header
);
206 if (quagga_gettime (QUAGGA_CLK_MONOTONIC
, &now
) < 0)
207 zlog_warn ("LSA: quagga_gettime failed, may fail LSA AGEs: %s",
208 safe_strerror (errno
));
210 if (lsa
->header
->age
>= htons (MAXAGE
))
212 /* LSA may have been prematurely aged */
213 lsa
->header
->age
= htons (MAXAGE
);
217 ulage
= now
.tv_sec
- lsa
->birth
.tv_sec
;
219 /* if over MAXAGE, set to it */
220 age
= (ulage
> MAXAGE
? MAXAGE
: ulage
);
222 lsa
->header
->age
= htons (age
);
226 /* update age field of LSA header with adding InfTransDelay */
228 ospf6_lsa_age_update_to_send (struct ospf6_lsa
*lsa
, u_int32_t transdelay
)
232 age
= ospf6_lsa_age_current (lsa
) + transdelay
;
235 lsa
->header
->age
= htons (age
);
239 ospf6_lsa_premature_aging (struct ospf6_lsa
*lsa
)
242 if (IS_OSPF6_DEBUG_LSA_TYPE (lsa
->header
->type
))
243 zlog_debug ("LSA: Premature aging: %s", lsa
->name
);
245 THREAD_OFF (lsa
->expire
);
246 THREAD_OFF (lsa
->refresh
);
249 * The below technique to age out LSA does not work when using relative time
251 memset (&lsa->birth, 0, sizeof (struct timeval));
253 lsa
->header
->age
= htons (MAXAGE
);
254 thread_execute (master
, ospf6_lsa_expire
, lsa
, 0);
257 /* check which is more recent. if a is more recent, return -1;
258 if the same, return 0; otherwise(b is more recent), return 1 */
260 ospf6_lsa_compare (struct ospf6_lsa
*a
, struct ospf6_lsa
*b
)
262 signed long seqnuma
, seqnumb
;
263 u_int16_t cksuma
, cksumb
;
264 u_int16_t agea
, ageb
;
266 assert (a
&& a
->header
);
267 assert (b
&& b
->header
);
268 assert (OSPF6_LSA_IS_SAME (a
, b
));
270 seqnuma
= ((signed long) ntohl (a
->header
->seqnum
))
271 - (signed long) INITIAL_SEQUENCE_NUMBER
;
272 seqnumb
= ((signed long) ntohl (b
->header
->seqnum
))
273 - (signed long) INITIAL_SEQUENCE_NUMBER
;
275 /* compare by sequence number */
276 /* XXX, LS sequence number wrapping */
277 if (seqnuma
> seqnumb
)
279 else if (seqnuma
< seqnumb
)
283 cksuma
= ntohs (a
->header
->checksum
);
284 cksumb
= ntohs (b
->header
->checksum
);
291 agea
= ospf6_lsa_age_current (a
);
292 ageb
= ospf6_lsa_age_current (b
);
295 if (agea
== MAXAGE
&& ageb
!= MAXAGE
)
297 else if (agea
!= MAXAGE
&& ageb
== MAXAGE
)
301 if (agea
> ageb
&& agea
- ageb
>= MAX_AGE_DIFF
)
303 else if (agea
< ageb
&& ageb
- agea
>= MAX_AGE_DIFF
)
311 ospf6_lsa_printbuf (struct ospf6_lsa
*lsa
, char *buf
, int size
)
313 char id
[16], adv_router
[16];
314 inet_ntop (AF_INET
, &lsa
->header
->id
, id
, sizeof (id
));
315 inet_ntop (AF_INET
, &lsa
->header
->adv_router
, adv_router
,
316 sizeof (adv_router
));
317 snprintf (buf
, size
, "[%s Id:%s Adv:%s]",
318 ospf6_lstype_name (lsa
->header
->type
), id
, adv_router
);
323 ospf6_lsa_header_print_raw (struct ospf6_lsa_header
*header
)
325 char id
[16], adv_router
[16];
326 inet_ntop (AF_INET
, &header
->id
, id
, sizeof (id
));
327 inet_ntop (AF_INET
, &header
->adv_router
, adv_router
,
328 sizeof (adv_router
));
329 zlog_debug (" [%s Id:%s Adv:%s]",
330 ospf6_lstype_name (header
->type
), id
, adv_router
);
331 zlog_debug (" Age: %4hu SeqNum: %#08lx Cksum: %04hx Len: %d",
332 ntohs (header
->age
), (u_long
) ntohl (header
->seqnum
),
333 ntohs (header
->checksum
), ntohs (header
->length
));
337 ospf6_lsa_header_print (struct ospf6_lsa
*lsa
)
339 ospf6_lsa_age_current (lsa
);
340 ospf6_lsa_header_print_raw (lsa
->header
);
344 ospf6_lsa_show_summary_header (struct vty
*vty
)
346 vty_out (vty
, "%-12s %-15s %-15s %4s %8s %4s %4s %-8s%s",
347 "Type", "LSId", "AdvRouter", "Age", "SeqNum",
348 "Cksm", "Len", "Duration", VNL
);
352 ospf6_lsa_show_summary (struct vty
*vty
, struct ospf6_lsa
*lsa
)
354 char adv_router
[16], id
[16];
355 struct timeval now
, res
;
359 assert (lsa
->header
);
361 inet_ntop (AF_INET
, &lsa
->header
->id
, id
, sizeof (id
));
362 inet_ntop (AF_INET
, &lsa
->header
->adv_router
, adv_router
,
363 sizeof (adv_router
));
365 quagga_gettime (QUAGGA_CLK_MONOTONIC
, &now
);
366 timersub (&now
, &lsa
->installed
, &res
);
367 timerstring (&res
, duration
, sizeof (duration
));
369 vty_out (vty
, "%-12s %-15s %-15s %4hu %8lx %04hx %4hu %8s%s",
370 ospf6_lstype_name (lsa
->header
->type
),
371 id
, adv_router
, ospf6_lsa_age_current (lsa
),
372 (u_long
) ntohl (lsa
->header
->seqnum
),
373 ntohs (lsa
->header
->checksum
), ntohs (lsa
->header
->length
),
378 ospf6_lsa_show_dump (struct vty
*vty
, struct ospf6_lsa
*lsa
)
380 u_char
*start
, *end
, *current
;
383 start
= (u_char
*) lsa
->header
;
384 end
= (u_char
*) lsa
->header
+ ntohs (lsa
->header
->length
);
386 vty_out (vty
, "%s", VNL
);
387 vty_out (vty
, "%s:%s", lsa
->name
, VNL
);
389 for (current
= start
; current
< end
; current
++)
391 if ((current
- start
) % 16 == 0)
392 vty_out (vty
, "%s ", VNL
);
393 else if ((current
- start
) % 4 == 0)
396 snprintf (byte
, sizeof (byte
), "%02x", *current
);
397 vty_out (vty
, "%s", byte
);
400 vty_out (vty
, "%s%s", VNL
, VNL
);
405 ospf6_lsa_show_internal (struct vty
*vty
, struct ospf6_lsa
*lsa
)
407 char adv_router
[64], id
[64];
409 assert (lsa
&& lsa
->header
);
411 inet_ntop (AF_INET
, &lsa
->header
->id
, id
, sizeof (id
));
412 inet_ntop (AF_INET
, &lsa
->header
->adv_router
,
413 adv_router
, sizeof (adv_router
));
415 vty_out (vty
, "%s", VNL
);
416 vty_out (vty
, "Age: %4hu Type: %s%s", ospf6_lsa_age_current (lsa
),
417 ospf6_lstype_name (lsa
->header
->type
), VNL
);
418 vty_out (vty
, "Link State ID: %s%s", id
, VNL
);
419 vty_out (vty
, "Advertising Router: %s%s", adv_router
, VNL
);
420 vty_out (vty
, "LS Sequence Number: %#010lx%s",
421 (u_long
) ntohl (lsa
->header
->seqnum
), VNL
);
422 vty_out (vty
, "CheckSum: %#06hx Length: %hu%s",
423 ntohs (lsa
->header
->checksum
),
424 ntohs (lsa
->header
->length
), VNL
);
425 vty_out (vty
, " Prev: %p This: %p Next: %p%s",
426 lsa
->prev
, lsa
, lsa
->next
, VNL
);
427 vty_out (vty
, "%s", VNL
);
432 ospf6_lsa_show (struct vty
*vty
, struct ospf6_lsa
*lsa
)
434 char adv_router
[64], id
[64];
435 struct ospf6_lsa_handler
*handler
;
437 assert (lsa
&& lsa
->header
);
439 inet_ntop (AF_INET
, &lsa
->header
->id
, id
, sizeof (id
));
440 inet_ntop (AF_INET
, &lsa
->header
->adv_router
,
441 adv_router
, sizeof (adv_router
));
443 vty_out (vty
, "Age: %4hu Type: %s%s", ospf6_lsa_age_current (lsa
),
444 ospf6_lstype_name (lsa
->header
->type
), VNL
);
445 vty_out (vty
, "Link State ID: %s%s", id
, VNL
);
446 vty_out (vty
, "Advertising Router: %s%s", adv_router
, VNL
);
447 vty_out (vty
, "LS Sequence Number: %#010lx%s",
448 (u_long
) ntohl (lsa
->header
->seqnum
), VNL
);
449 vty_out (vty
, "CheckSum: %#06hx Length: %hu%s",
450 ntohs (lsa
->header
->checksum
),
451 ntohs (lsa
->header
->length
), VNL
);
453 handler
= ospf6_get_lsa_handler (lsa
->header
->type
);
454 if (handler
->show
== NULL
)
455 handler
= &unknown_handler
;
456 (*handler
->show
) (vty
, lsa
);
458 vty_out (vty
, "%s", VNL
);
461 /* OSPFv3 LSA creation/deletion function */
463 ospf6_lsa_create (struct ospf6_lsa_header
*header
)
465 struct ospf6_lsa
*lsa
= NULL
;
466 struct ospf6_lsa_header
*new_header
= NULL
;
467 u_int16_t lsa_size
= 0;
469 /* size of the entire LSA */
470 lsa_size
= ntohs (header
->length
); /* XXX vulnerable */
472 /* allocate memory for this LSA */
473 new_header
= (struct ospf6_lsa_header
*)
474 XMALLOC (MTYPE_OSPF6_LSA
, lsa_size
);
476 /* copy LSA from original header */
477 memcpy (new_header
, header
, lsa_size
);
479 /* LSA information structure */
480 /* allocate memory */
481 lsa
= (struct ospf6_lsa
*)
482 XCALLOC (MTYPE_OSPF6_LSA
, sizeof (struct ospf6_lsa
));
484 lsa
->header
= (struct ospf6_lsa_header
*) new_header
;
487 ospf6_lsa_printbuf (lsa
, lsa
->name
, sizeof (lsa
->name
));
489 /* calculate birth of this lsa */
490 ospf6_lsa_age_set (lsa
);
496 ospf6_lsa_create_headeronly (struct ospf6_lsa_header
*header
)
498 struct ospf6_lsa
*lsa
= NULL
;
499 struct ospf6_lsa_header
*new_header
= NULL
;
501 /* allocate memory for this LSA */
502 new_header
= (struct ospf6_lsa_header
*)
503 XMALLOC (MTYPE_OSPF6_LSA
, sizeof (struct ospf6_lsa_header
));
505 /* copy LSA from original header */
506 memcpy (new_header
, header
, sizeof (struct ospf6_lsa_header
));
508 /* LSA information structure */
509 /* allocate memory */
510 lsa
= (struct ospf6_lsa
*)
511 XCALLOC (MTYPE_OSPF6_LSA
, sizeof (struct ospf6_lsa
));
513 lsa
->header
= (struct ospf6_lsa_header
*) new_header
;
514 SET_FLAG (lsa
->flag
, OSPF6_LSA_HEADERONLY
);
517 ospf6_lsa_printbuf (lsa
, lsa
->name
, sizeof (lsa
->name
));
519 /* calculate birth of this lsa */
520 ospf6_lsa_age_set (lsa
);
526 ospf6_lsa_delete (struct ospf6_lsa
*lsa
)
528 assert (lsa
->lock
== 0);
531 THREAD_OFF (lsa
->expire
);
532 THREAD_OFF (lsa
->refresh
);
535 XFREE (MTYPE_OSPF6_LSA
, lsa
->header
);
536 XFREE (MTYPE_OSPF6_LSA
, lsa
);
540 ospf6_lsa_copy (struct ospf6_lsa
*lsa
)
542 struct ospf6_lsa
*copy
= NULL
;
544 ospf6_lsa_age_current (lsa
);
545 if (CHECK_FLAG (lsa
->flag
, OSPF6_LSA_HEADERONLY
))
546 copy
= ospf6_lsa_create_headeronly (lsa
->header
);
548 copy
= ospf6_lsa_create (lsa
->header
);
549 assert (copy
->lock
== 0);
551 copy
->birth
= lsa
->birth
;
552 copy
->originated
= lsa
->originated
;
553 copy
->received
= lsa
->received
;
554 copy
->installed
= lsa
->installed
;
555 copy
->lsdb
= lsa
->lsdb
;
560 /* increment reference counter of struct ospf6_lsa */
562 ospf6_lsa_lock (struct ospf6_lsa
*lsa
)
568 /* decrement reference counter of struct ospf6_lsa */
570 ospf6_lsa_unlock (struct ospf6_lsa
*lsa
)
572 /* decrement reference counter */
573 assert (lsa
->lock
> 0);
579 ospf6_lsa_delete (lsa
);
583 /* ospf6 lsa expiry */
585 ospf6_lsa_expire (struct thread
*thread
)
587 struct ospf6_lsa
*lsa
;
589 lsa
= (struct ospf6_lsa
*) THREAD_ARG (thread
);
591 assert (lsa
&& lsa
->header
);
592 assert (OSPF6_LSA_IS_MAXAGE (lsa
));
593 assert (! lsa
->refresh
);
595 lsa
->expire
= (struct thread
*) NULL
;
597 if (IS_OSPF6_DEBUG_LSA_TYPE (lsa
->header
->type
))
599 zlog_debug ("LSA Expire:");
600 ospf6_lsa_header_print (lsa
);
603 if (CHECK_FLAG (lsa
->flag
, OSPF6_LSA_HEADERONLY
))
604 return 0; /* dbexchange will do something ... */
607 ospf6_flood (NULL
, lsa
);
610 ospf6_install_lsa (lsa
);
612 /* schedule maxage remover */
613 ospf6_maxage_remove (ospf6
);
619 ospf6_lsa_refresh (struct thread
*thread
)
621 struct ospf6_lsa
*old
, *self
, *new;
622 struct ospf6_lsdb
*lsdb_self
;
625 old
= (struct ospf6_lsa
*) THREAD_ARG (thread
);
626 assert (old
&& old
->header
);
628 old
->refresh
= (struct thread
*) NULL
;
630 lsdb_self
= ospf6_get_scoped_lsdb_self (old
);
631 self
= ospf6_lsdb_lookup (old
->header
->type
, old
->header
->id
,
632 old
->header
->adv_router
, lsdb_self
);
635 if (IS_OSPF6_DEBUG_LSA_TYPE (old
->header
->type
))
636 zlog_debug ("Refresh: could not find self LSA, flush %s", old
->name
);
637 ospf6_lsa_premature_aging (old
);
641 /* Reset age, increment LS sequence number. */
642 self
->header
->age
= htons (0);
643 self
->header
->seqnum
=
644 ospf6_new_ls_seqnum (self
->header
->type
, self
->header
->id
,
645 self
->header
->adv_router
, old
->lsdb
);
646 ospf6_lsa_checksum (self
->header
);
648 new = ospf6_lsa_create (self
->header
);
649 new->lsdb
= old
->lsdb
;
650 new->refresh
= thread_add_timer (master
, ospf6_lsa_refresh
, new,
653 /* store it in the LSDB for self-originated LSAs */
654 ospf6_lsdb_add (ospf6_lsa_copy (new), lsdb_self
);
656 if (IS_OSPF6_DEBUG_LSA_TYPE (new->header
->type
))
658 zlog_debug ("LSA Refresh:");
659 ospf6_lsa_header_print (new);
662 ospf6_flood_clear (old
);
663 ospf6_flood (NULL
, new);
664 ospf6_install_lsa (new);
671 /* enhanced Fletcher checksum algorithm, RFC1008 7.2 */
673 #define LSA_CHECKSUM_OFFSET 15
676 ospf6_lsa_checksum (struct ospf6_lsa_header
*lsa_header
)
678 u_char
*sp
, *ep
, *p
, *q
;
683 lsa_header
->checksum
= 0;
684 length
= ntohs (lsa_header
->length
) - 2;
685 sp
= (u_char
*) &lsa_header
->type
;
687 for (ep
= sp
+ length
; sp
< ep
; sp
= q
)
692 for (p
= sp
; p
< q
; p
++)
701 /* r = (c1 << 8) + c0; */
702 x
= ((length
- LSA_CHECKSUM_OFFSET
) * c0
- c1
) % 255;
709 lsa_header
->checksum
= htons ((x
<< 8) + y
);
711 return (lsa_header
->checksum
);
715 ospf6_lsa_init (void)
717 ospf6_lsa_handler_vector
= vector_init (0);
718 ospf6_install_lsa_handler (&unknown_handler
);
723 ospf6_lsa_handler_name (struct ospf6_lsa_handler
*h
)
727 unsigned int size
= strlen (h
->name
);
729 if (!strcmp(h
->name
, "Unknown") &&
730 h
->type
!= OSPF6_LSTYPE_UNKNOWN
)
732 snprintf (buf
, sizeof (buf
), "%#04hx", h
->type
);
736 for (i
= 0; i
< MIN (size
, sizeof (buf
)); i
++)
738 if (! islower (h
->name
[i
]))
739 buf
[i
] = tolower (h
->name
[i
]);
747 DEFUN (debug_ospf6_lsa_type
,
748 debug_ospf6_lsa_hex_cmd
,
749 "debug ospf6 lsa XXXX/0xXXXX",
752 "Debug Link State Advertisements (LSAs)\n"
753 "Specify LS type as Hexadecimal\n"
757 struct ospf6_lsa_handler
*handler
= NULL
;
764 if ((strlen (argv
[0]) == 6 && ! strncmp (argv
[0], "0x", 2)) ||
765 (strlen (argv
[0]) == 4))
767 val
= strtoul (argv
[0], &endptr
, 16);
772 for (i
= 0; i
< vector_active (ospf6_lsa_handler_vector
); i
++)
774 handler
= vector_slot (ospf6_lsa_handler_vector
, i
);
777 if (type
&& handler
->type
== type
)
779 if (! strcasecmp (argv
[0], handler
->name
))
784 if (type
&& handler
== NULL
)
786 handler
= (struct ospf6_lsa_handler
*)
787 malloc (sizeof (struct ospf6_lsa_handler
));
788 memset (handler
, 0, sizeof (struct ospf6_lsa_handler
));
789 handler
->type
= type
;
790 handler
->name
= "Unknown";
791 handler
->show
= ospf6_unknown_lsa_show
;
792 vector_set_index (ospf6_lsa_handler_vector
,
793 handler
->type
& OSPF6_LSTYPE_FCODE_MASK
, handler
);
797 handler
= &unknown_handler
;
801 if (! strcmp (argv
[1], "originate"))
802 SET_FLAG (handler
->debug
, OSPF6_LSA_DEBUG_ORIGINATE
);
803 if (! strcmp (argv
[1], "examin"))
804 SET_FLAG (handler
->debug
, OSPF6_LSA_DEBUG_EXAMIN
);
805 if (! strcmp (argv
[1], "flooding"))
806 SET_FLAG (handler
->debug
, OSPF6_LSA_DEBUG_FLOOD
);
809 SET_FLAG (handler
->debug
, OSPF6_LSA_DEBUG
);
814 DEFUN (no_debug_ospf6_lsa_type
,
815 no_debug_ospf6_lsa_hex_cmd
,
816 "no debug ospf6 lsa XXXX/0xXXXX",
820 "Debug Link State Advertisements (LSAs)\n"
821 "Specify LS type as Hexadecimal\n"
825 struct ospf6_lsa_handler
*handler
= NULL
;
832 if ((strlen (argv
[0]) == 6 && ! strncmp (argv
[0], "0x", 2)) ||
833 (strlen (argv
[0]) == 4))
835 val
= strtoul (argv
[0], &endptr
, 16);
840 for (i
= 0; i
< vector_active (ospf6_lsa_handler_vector
); i
++)
842 handler
= vector_slot (ospf6_lsa_handler_vector
, i
);
845 if (type
&& handler
->type
== type
)
847 if (! strcasecmp (argv
[0], handler
->name
))
856 if (! strcmp (argv
[1], "originate"))
857 UNSET_FLAG (handler
->debug
, OSPF6_LSA_DEBUG_ORIGINATE
);
858 if (! strcmp (argv
[1], "examin"))
859 UNSET_FLAG (handler
->debug
, OSPF6_LSA_DEBUG_EXAMIN
);
860 if (! strcmp (argv
[1], "flooding"))
861 UNSET_FLAG (handler
->debug
, OSPF6_LSA_DEBUG_FLOOD
);
864 UNSET_FLAG (handler
->debug
, OSPF6_LSA_DEBUG
);
866 if (handler
->debug
== 0 &&
867 !strcmp(handler
->name
, "Unknown") && type
!= OSPF6_LSTYPE_UNKNOWN
)
870 vector_slot (ospf6_lsa_handler_vector
, i
) = NULL
;
876 struct cmd_element debug_ospf6_lsa_type_cmd
;
877 struct cmd_element debug_ospf6_lsa_type_detail_cmd
;
878 struct cmd_element no_debug_ospf6_lsa_type_cmd
;
879 struct cmd_element no_debug_ospf6_lsa_type_detail_cmd
;
882 install_element_ospf6_debug_lsa (void)
885 struct ospf6_lsa_handler
*handler
;
888 static char strbuf
[STRSIZE
];
889 static char docbuf
[DOCSIZE
];
890 static char detail_strbuf
[STRSIZE
];
891 static char detail_docbuf
[DOCSIZE
];
896 no_str
= &strbuf
[strlen (strbuf
)];
897 strncat (strbuf
, "no ", STRSIZE
- strlen (strbuf
));
898 str
= &strbuf
[strlen (strbuf
)];
900 strncat (strbuf
, "debug ospf6 lsa (", STRSIZE
- strlen (strbuf
));
901 for (i
= 0; i
< vector_active (ospf6_lsa_handler_vector
); i
++)
903 handler
= vector_slot (ospf6_lsa_handler_vector
, i
);
906 strncat (strbuf
, ospf6_lsa_handler_name (handler
),
907 STRSIZE
- strlen (strbuf
));
908 strncat (strbuf
, "|", STRSIZE
- strlen (strbuf
));
910 strbuf
[strlen (strbuf
) - 1] = ')';
911 strbuf
[strlen (strbuf
)] = '\0';
914 no_doc
= &docbuf
[strlen (docbuf
)];
915 strncat (docbuf
, NO_STR
, DOCSIZE
- strlen (docbuf
));
916 doc
= &docbuf
[strlen (docbuf
)];
918 strncat (docbuf
, DEBUG_STR
, DOCSIZE
- strlen (docbuf
));
919 strncat (docbuf
, OSPF6_STR
, DOCSIZE
- strlen (docbuf
));
920 strncat (docbuf
, "Debug Link State Advertisements (LSAs)\n",
921 DOCSIZE
- strlen (docbuf
));
923 for (i
= 0; i
< vector_active (ospf6_lsa_handler_vector
); i
++)
925 handler
= vector_slot (ospf6_lsa_handler_vector
, i
);
928 strncat (docbuf
, "Debug ", DOCSIZE
- strlen (docbuf
));
929 strncat (docbuf
, handler
->name
, DOCSIZE
- strlen (docbuf
));
930 strncat (docbuf
, "-LSA\n", DOCSIZE
- strlen (docbuf
));
932 docbuf
[strlen (docbuf
)] = '\0';
934 debug_ospf6_lsa_type_cmd
.string
= str
;
935 debug_ospf6_lsa_type_cmd
.func
= debug_ospf6_lsa_type
;
936 debug_ospf6_lsa_type_cmd
.doc
= doc
;
938 no_debug_ospf6_lsa_type_cmd
.string
= no_str
;
939 no_debug_ospf6_lsa_type_cmd
.func
= no_debug_ospf6_lsa_type
;
940 no_debug_ospf6_lsa_type_cmd
.doc
= no_doc
;
942 strncpy (detail_strbuf
, strbuf
, STRSIZE
);
943 strncat (detail_strbuf
, " (originate|examin|flooding)",
944 STRSIZE
- strlen (detail_strbuf
));
945 detail_strbuf
[strlen (detail_strbuf
)] = '\0';
946 no_str
= &detail_strbuf
[0];
947 str
= &detail_strbuf
[strlen ("no ")];
949 strncpy (detail_docbuf
, docbuf
, DOCSIZE
);
950 strncat (detail_docbuf
, "Debug Originating LSA\n",
951 DOCSIZE
- strlen (detail_docbuf
));
952 strncat (detail_docbuf
, "Debug Examining LSA\n",
953 DOCSIZE
- strlen (detail_docbuf
));
954 strncat (detail_docbuf
, "Debug Flooding LSA\n",
955 DOCSIZE
- strlen (detail_docbuf
));
956 detail_docbuf
[strlen (detail_docbuf
)] = '\0';
957 no_doc
= &detail_docbuf
[0];
958 doc
= &detail_docbuf
[strlen (NO_STR
)];
960 debug_ospf6_lsa_type_detail_cmd
.string
= str
;
961 debug_ospf6_lsa_type_detail_cmd
.func
= debug_ospf6_lsa_type
;
962 debug_ospf6_lsa_type_detail_cmd
.doc
= doc
;
964 no_debug_ospf6_lsa_type_detail_cmd
.string
= no_str
;
965 no_debug_ospf6_lsa_type_detail_cmd
.func
= no_debug_ospf6_lsa_type
;
966 no_debug_ospf6_lsa_type_detail_cmd
.doc
= no_doc
;
968 install_element (ENABLE_NODE
, &debug_ospf6_lsa_hex_cmd
);
969 install_element (ENABLE_NODE
, &debug_ospf6_lsa_type_cmd
);
970 install_element (ENABLE_NODE
, &debug_ospf6_lsa_type_detail_cmd
);
971 install_element (ENABLE_NODE
, &no_debug_ospf6_lsa_hex_cmd
);
972 install_element (ENABLE_NODE
, &no_debug_ospf6_lsa_type_cmd
);
973 install_element (ENABLE_NODE
, &no_debug_ospf6_lsa_type_detail_cmd
);
974 install_element (CONFIG_NODE
, &debug_ospf6_lsa_hex_cmd
);
975 install_element (CONFIG_NODE
, &debug_ospf6_lsa_type_cmd
);
976 install_element (CONFIG_NODE
, &debug_ospf6_lsa_type_detail_cmd
);
977 install_element (CONFIG_NODE
, &no_debug_ospf6_lsa_hex_cmd
);
978 install_element (CONFIG_NODE
, &no_debug_ospf6_lsa_type_cmd
);
979 install_element (CONFIG_NODE
, &no_debug_ospf6_lsa_type_detail_cmd
);
983 config_write_ospf6_debug_lsa (struct vty
*vty
)
986 struct ospf6_lsa_handler
*handler
;
988 for (i
= 0; i
< vector_active (ospf6_lsa_handler_vector
); i
++)
990 handler
= vector_slot (ospf6_lsa_handler_vector
, i
);
993 if (CHECK_FLAG (handler
->debug
, OSPF6_LSA_DEBUG
))
994 vty_out (vty
, "debug ospf6 lsa %s%s",
995 ospf6_lsa_handler_name (handler
), VNL
);
996 if (CHECK_FLAG (handler
->debug
, OSPF6_LSA_DEBUG_ORIGINATE
))
997 vty_out (vty
, "debug ospf6 lsa %s originate%s",
998 ospf6_lsa_handler_name (handler
), VNL
);
999 if (CHECK_FLAG (handler
->debug
, OSPF6_LSA_DEBUG_EXAMIN
))
1000 vty_out (vty
, "debug ospf6 lsa %s examin%s",
1001 ospf6_lsa_handler_name (handler
), VNL
);
1002 if (CHECK_FLAG (handler
->debug
, OSPF6_LSA_DEBUG_FLOOD
))
1003 vty_out (vty
, "debug ospf6 lsa %s flooding%s",
1004 ospf6_lsa_handler_name (handler
), VNL
);