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 */
34 #include "ospf6_proto.h"
35 #include "ospf6_lsa.h"
36 #include "ospf6_lsdb.h"
37 #include "ospf6_message.h"
39 #include "ospf6_top.h"
40 #include "ospf6_area.h"
41 #include "ospf6_interface.h"
42 #include "ospf6_neighbor.h"
44 #include "ospf6_flood.h"
47 vector ospf6_lsa_handler_vector
;
50 ospf6_unknown_lsa_show (struct vty
*vty
, struct ospf6_lsa
*lsa
)
52 u_char
*start
, *end
, *current
;
55 start
= (u_char
*) lsa
->header
+ sizeof (struct ospf6_lsa_header
);
56 end
= (u_char
*) lsa
->header
+ ntohs (lsa
->header
->length
);
58 vty_out (vty
, " Unknown contents:%s", VNL
);
59 for (current
= start
; current
< end
; current
++)
61 if ((current
- start
) % 16 == 0)
62 vty_out (vty
, "%s ", VNL
);
63 else if ((current
- start
) % 4 == 0)
66 snprintf (byte
, sizeof (byte
), "%02x", *current
);
67 vty_out (vty
, "%s", byte
);
70 vty_out (vty
, "%s%s", VNL
, VNL
);
74 struct ospf6_lsa_handler unknown_handler
=
78 ospf6_unknown_lsa_show
,
83 ospf6_install_lsa_handler (struct ospf6_lsa_handler
*handler
)
85 /* type in handler is host byte order */
86 int index
= handler
->type
& OSPF6_LSTYPE_FCODE_MASK
;
87 vector_set_index (ospf6_lsa_handler_vector
, index
, handler
);
90 struct ospf6_lsa_handler
*
91 ospf6_get_lsa_handler (u_int16_t type
)
93 struct ospf6_lsa_handler
*handler
= NULL
;
94 unsigned int index
= ntohs (type
) & OSPF6_LSTYPE_FCODE_MASK
;
96 if (index
>= vector_active (ospf6_lsa_handler_vector
))
97 handler
= &unknown_handler
;
99 handler
= vector_slot (ospf6_lsa_handler_vector
, index
);
102 handler
= &unknown_handler
;
108 ospf6_lstype_name (u_int16_t type
)
111 struct ospf6_lsa_handler
*handler
;
113 handler
= ospf6_get_lsa_handler (type
);
114 if (handler
&& handler
!= &unknown_handler
)
115 return handler
->name
;
117 snprintf (buf
, sizeof (buf
), "0x%04hx", ntohs (type
));
122 ospf6_lstype_debug (u_int16_t type
)
124 struct ospf6_lsa_handler
*handler
;
125 handler
= ospf6_get_lsa_handler (type
);
126 return handler
->debug
;
129 /* RFC2328: Section 13.2 */
131 ospf6_lsa_is_differ (struct ospf6_lsa
*lsa1
,
132 struct ospf6_lsa
*lsa2
)
136 assert (OSPF6_LSA_IS_SAME (lsa1
, lsa2
));
138 /* XXX, Options ??? */
140 ospf6_lsa_age_current (lsa1
);
141 ospf6_lsa_age_current (lsa2
);
142 if (ntohs (lsa1
->header
->age
) == MAXAGE
&&
143 ntohs (lsa2
->header
->age
) != MAXAGE
)
145 if (ntohs (lsa1
->header
->age
) != MAXAGE
&&
146 ntohs (lsa2
->header
->age
) == MAXAGE
)
150 if (ntohs (lsa1
->header
->length
) != ntohs (lsa2
->header
->length
))
153 len
= ntohs (lsa1
->header
->length
) - sizeof (struct ospf6_lsa_header
);
154 return memcmp (lsa1
->header
+ 1, lsa2
->header
+ 1, len
);
158 ospf6_lsa_is_changed (struct ospf6_lsa
*lsa1
,
159 struct ospf6_lsa
*lsa2
)
163 if (OSPF6_LSA_IS_MAXAGE (lsa1
) ^ OSPF6_LSA_IS_MAXAGE (lsa2
))
165 if (ntohs (lsa1
->header
->length
) != ntohs (lsa2
->header
->length
))
167 /* Going beyond LSA headers to compare the payload only makes sense, when both LSAs aren't header-only. */
168 if (CHECK_FLAG (lsa1
->flag
, OSPF6_LSA_HEADERONLY
) != CHECK_FLAG (lsa2
->flag
, OSPF6_LSA_HEADERONLY
))
170 zlog_warn ("%s: only one of two (%s, %s) LSAs compared is header-only", __func__
, lsa1
->name
, lsa2
->name
);
173 if (CHECK_FLAG (lsa1
->flag
, OSPF6_LSA_HEADERONLY
))
176 length
= OSPF6_LSA_SIZE (lsa1
->header
) - sizeof (struct ospf6_lsa_header
);
177 /* Once upper layer verifies LSAs received, length underrun should become a warning. */
181 return memcmp (OSPF6_LSA_HEADER_END (lsa1
->header
),
182 OSPF6_LSA_HEADER_END (lsa2
->header
), length
);
185 /* ospf6 age functions */
186 /* calculate birth */
188 ospf6_lsa_age_set (struct ospf6_lsa
*lsa
)
192 assert (lsa
&& lsa
->header
);
194 if (quagga_gettime (QUAGGA_CLK_MONOTONIC
, &now
) < 0)
195 zlog_warn ("LSA: quagga_gettime failed, may fail LSA AGEs: %s",
196 safe_strerror (errno
));
198 lsa
->birth
.tv_sec
= now
.tv_sec
- ntohs (lsa
->header
->age
);
199 lsa
->birth
.tv_usec
= now
.tv_usec
;
204 /* this function calculates current age from its birth,
205 then update age field of LSA header. return value is current age */
207 ospf6_lsa_age_current (struct ospf6_lsa
*lsa
)
214 assert (lsa
->header
);
217 if (quagga_gettime (QUAGGA_CLK_MONOTONIC
, &now
) < 0)
218 zlog_warn ("LSA: quagga_gettime failed, may fail LSA AGEs: %s",
219 safe_strerror (errno
));
221 if (ntohs (lsa
->header
->age
) >= MAXAGE
)
223 /* ospf6_lsa_premature_aging () sets age to MAXAGE; when using
224 relative time, we cannot compare against lsa birth time, so
225 we catch this special case here. */
226 lsa
->header
->age
= htons (MAXAGE
);
230 ulage
= now
.tv_sec
- lsa
->birth
.tv_sec
;
232 /* if over MAXAGE, set to it */
233 age
= (ulage
> MAXAGE
? MAXAGE
: ulage
);
235 lsa
->header
->age
= htons (age
);
239 /* update age field of LSA header with adding InfTransDelay */
241 ospf6_lsa_age_update_to_send (struct ospf6_lsa
*lsa
, u_int32_t transdelay
)
245 age
= ospf6_lsa_age_current (lsa
) + transdelay
;
248 lsa
->header
->age
= htons (age
);
252 ospf6_lsa_premature_aging (struct ospf6_lsa
*lsa
)
255 if (IS_OSPF6_DEBUG_LSA_TYPE (lsa
->header
->type
))
256 zlog_debug ("LSA: Premature aging: %s", lsa
->name
);
258 THREAD_OFF (lsa
->expire
);
259 THREAD_OFF (lsa
->refresh
);
261 lsa
->header
->age
= htons (MAXAGE
);
262 thread_execute (master
, ospf6_lsa_expire
, lsa
, 0);
265 /* check which is more recent. if a is more recent, return -1;
266 if the same, return 0; otherwise(b is more recent), return 1 */
268 ospf6_lsa_compare (struct ospf6_lsa
*a
, struct ospf6_lsa
*b
)
270 int seqnuma
, seqnumb
;
271 u_int16_t cksuma
, cksumb
;
272 u_int16_t agea
, ageb
;
274 assert (a
&& a
->header
);
275 assert (b
&& b
->header
);
276 assert (OSPF6_LSA_IS_SAME (a
, b
));
278 seqnuma
= (int) ntohl (a
->header
->seqnum
);
279 seqnumb
= (int) ntohl (b
->header
->seqnum
);
281 /* compare by sequence number */
282 if (seqnuma
> seqnumb
)
284 if (seqnuma
< seqnumb
)
288 cksuma
= ntohs (a
->header
->checksum
);
289 cksumb
= ntohs (b
->header
->checksum
);
296 agea
= ospf6_lsa_age_current (a
);
297 ageb
= ospf6_lsa_age_current (b
);
300 if (agea
== MAXAGE
&& ageb
!= MAXAGE
)
302 else if (agea
!= MAXAGE
&& ageb
== MAXAGE
)
306 if (agea
> ageb
&& agea
- ageb
>= MAX_AGE_DIFF
)
308 else if (agea
< ageb
&& ageb
- agea
>= MAX_AGE_DIFF
)
316 ospf6_lsa_printbuf (struct ospf6_lsa
*lsa
, char *buf
, int size
)
318 char id
[16], adv_router
[16];
319 inet_ntop (AF_INET
, &lsa
->header
->id
, id
, sizeof (id
));
320 inet_ntop (AF_INET
, &lsa
->header
->adv_router
, adv_router
,
321 sizeof (adv_router
));
322 snprintf (buf
, size
, "[%s Id:%s Adv:%s]",
323 ospf6_lstype_name (lsa
->header
->type
), id
, adv_router
);
328 ospf6_lsa_header_print_raw (struct ospf6_lsa_header
*header
)
330 char id
[16], adv_router
[16];
331 inet_ntop (AF_INET
, &header
->id
, id
, sizeof (id
));
332 inet_ntop (AF_INET
, &header
->adv_router
, adv_router
,
333 sizeof (adv_router
));
334 zlog_debug (" [%s Id:%s Adv:%s]",
335 ospf6_lstype_name (header
->type
), id
, adv_router
);
336 zlog_debug (" Age: %4hu SeqNum: %#08lx Cksum: %04hx Len: %d",
337 ntohs (header
->age
), (u_long
) ntohl (header
->seqnum
),
338 ntohs (header
->checksum
), ntohs (header
->length
));
342 ospf6_lsa_header_print (struct ospf6_lsa
*lsa
)
344 ospf6_lsa_age_current (lsa
);
345 ospf6_lsa_header_print_raw (lsa
->header
);
349 ospf6_lsa_show_summary_header (struct vty
*vty
)
351 vty_out (vty
, "%-12s %-15s %-15s %4s %8s %4s %4s %-8s%s",
352 "Type", "LSId", "AdvRouter", "Age", "SeqNum",
353 "Cksm", "Len", "Duration", VNL
);
357 ospf6_lsa_show_summary (struct vty
*vty
, struct ospf6_lsa
*lsa
)
359 char adv_router
[16], id
[16];
360 struct timeval now
, res
;
364 assert (lsa
->header
);
366 inet_ntop (AF_INET
, &lsa
->header
->id
, id
, sizeof (id
));
367 inet_ntop (AF_INET
, &lsa
->header
->adv_router
, adv_router
,
368 sizeof (adv_router
));
370 quagga_gettime (QUAGGA_CLK_MONOTONIC
, &now
);
371 timersub (&now
, &lsa
->installed
, &res
);
372 timerstring (&res
, duration
, sizeof (duration
));
374 vty_out (vty
, "%-12s %-15s %-15s %4hu %8lx %04hx %4hu %8s%s",
375 ospf6_lstype_name (lsa
->header
->type
),
376 id
, adv_router
, ospf6_lsa_age_current (lsa
),
377 (u_long
) ntohl (lsa
->header
->seqnum
),
378 ntohs (lsa
->header
->checksum
), ntohs (lsa
->header
->length
),
383 ospf6_lsa_show_dump (struct vty
*vty
, struct ospf6_lsa
*lsa
)
385 u_char
*start
, *end
, *current
;
388 start
= (u_char
*) lsa
->header
;
389 end
= (u_char
*) lsa
->header
+ ntohs (lsa
->header
->length
);
391 vty_out (vty
, "%s", VNL
);
392 vty_out (vty
, "%s:%s", lsa
->name
, VNL
);
394 for (current
= start
; current
< end
; current
++)
396 if ((current
- start
) % 16 == 0)
397 vty_out (vty
, "%s ", VNL
);
398 else if ((current
- start
) % 4 == 0)
401 snprintf (byte
, sizeof (byte
), "%02x", *current
);
402 vty_out (vty
, "%s", byte
);
405 vty_out (vty
, "%s%s", VNL
, VNL
);
410 ospf6_lsa_show_internal (struct vty
*vty
, struct ospf6_lsa
*lsa
)
412 char adv_router
[64], id
[64];
414 assert (lsa
&& lsa
->header
);
416 inet_ntop (AF_INET
, &lsa
->header
->id
, id
, sizeof (id
));
417 inet_ntop (AF_INET
, &lsa
->header
->adv_router
,
418 adv_router
, sizeof (adv_router
));
420 vty_out (vty
, "%s", VNL
);
421 vty_out (vty
, "Age: %4hu Type: %s%s", ospf6_lsa_age_current (lsa
),
422 ospf6_lstype_name (lsa
->header
->type
), VNL
);
423 vty_out (vty
, "Link State ID: %s%s", id
, VNL
);
424 vty_out (vty
, "Advertising Router: %s%s", adv_router
, VNL
);
425 vty_out (vty
, "LS Sequence Number: %#010lx%s",
426 (u_long
) ntohl (lsa
->header
->seqnum
), VNL
);
427 vty_out (vty
, "CheckSum: %#06hx Length: %hu%s",
428 ntohs (lsa
->header
->checksum
),
429 ntohs (lsa
->header
->length
), VNL
);
430 vty_out (vty
, " Prev: %p This: %p Next: %p%s",
431 lsa
->prev
, lsa
, lsa
->next
, VNL
);
432 vty_out (vty
, "%s", VNL
);
437 ospf6_lsa_show (struct vty
*vty
, struct ospf6_lsa
*lsa
)
439 char adv_router
[64], id
[64];
440 struct ospf6_lsa_handler
*handler
;
442 assert (lsa
&& lsa
->header
);
444 inet_ntop (AF_INET
, &lsa
->header
->id
, id
, sizeof (id
));
445 inet_ntop (AF_INET
, &lsa
->header
->adv_router
,
446 adv_router
, sizeof (adv_router
));
448 vty_out (vty
, "Age: %4hu Type: %s%s", ospf6_lsa_age_current (lsa
),
449 ospf6_lstype_name (lsa
->header
->type
), VNL
);
450 vty_out (vty
, "Link State ID: %s%s", id
, VNL
);
451 vty_out (vty
, "Advertising Router: %s%s", adv_router
, VNL
);
452 vty_out (vty
, "LS Sequence Number: %#010lx%s",
453 (u_long
) ntohl (lsa
->header
->seqnum
), VNL
);
454 vty_out (vty
, "CheckSum: %#06hx Length: %hu%s",
455 ntohs (lsa
->header
->checksum
),
456 ntohs (lsa
->header
->length
), VNL
);
458 handler
= ospf6_get_lsa_handler (lsa
->header
->type
);
459 if (handler
->show
== NULL
)
460 handler
= &unknown_handler
;
461 (*handler
->show
) (vty
, lsa
);
463 vty_out (vty
, "%s", VNL
);
466 /* OSPFv3 LSA creation/deletion function */
468 ospf6_lsa_create (struct ospf6_lsa_header
*header
)
470 struct ospf6_lsa
*lsa
= NULL
;
471 struct ospf6_lsa_header
*new_header
= NULL
;
472 u_int16_t lsa_size
= 0;
474 /* size of the entire LSA */
475 lsa_size
= ntohs (header
->length
); /* XXX vulnerable */
477 /* allocate memory for this LSA */
478 new_header
= (struct ospf6_lsa_header
*)
479 XMALLOC (MTYPE_OSPF6_LSA
, lsa_size
);
481 /* copy LSA from original header */
482 memcpy (new_header
, header
, lsa_size
);
484 /* LSA information structure */
485 /* allocate memory */
486 lsa
= (struct ospf6_lsa
*)
487 XCALLOC (MTYPE_OSPF6_LSA
, sizeof (struct ospf6_lsa
));
489 lsa
->header
= (struct ospf6_lsa_header
*) new_header
;
492 ospf6_lsa_printbuf (lsa
, lsa
->name
, sizeof (lsa
->name
));
494 /* calculate birth of this lsa */
495 ospf6_lsa_age_set (lsa
);
501 ospf6_lsa_create_headeronly (struct ospf6_lsa_header
*header
)
503 struct ospf6_lsa
*lsa
= NULL
;
504 struct ospf6_lsa_header
*new_header
= NULL
;
506 /* allocate memory for this LSA */
507 new_header
= (struct ospf6_lsa_header
*)
508 XMALLOC (MTYPE_OSPF6_LSA
, sizeof (struct ospf6_lsa_header
));
510 /* copy LSA from original header */
511 memcpy (new_header
, header
, sizeof (struct ospf6_lsa_header
));
513 /* LSA information structure */
514 /* allocate memory */
515 lsa
= (struct ospf6_lsa
*)
516 XCALLOC (MTYPE_OSPF6_LSA
, sizeof (struct ospf6_lsa
));
518 lsa
->header
= (struct ospf6_lsa_header
*) new_header
;
519 SET_FLAG (lsa
->flag
, OSPF6_LSA_HEADERONLY
);
522 ospf6_lsa_printbuf (lsa
, lsa
->name
, sizeof (lsa
->name
));
524 /* calculate birth of this lsa */
525 ospf6_lsa_age_set (lsa
);
531 ospf6_lsa_delete (struct ospf6_lsa
*lsa
)
533 assert (lsa
->lock
== 0);
536 THREAD_OFF (lsa
->expire
);
537 THREAD_OFF (lsa
->refresh
);
540 XFREE (MTYPE_OSPF6_LSA
, lsa
->header
);
541 XFREE (MTYPE_OSPF6_LSA
, lsa
);
545 ospf6_lsa_copy (struct ospf6_lsa
*lsa
)
547 struct ospf6_lsa
*copy
= NULL
;
549 ospf6_lsa_age_current (lsa
);
550 if (CHECK_FLAG (lsa
->flag
, OSPF6_LSA_HEADERONLY
))
551 copy
= ospf6_lsa_create_headeronly (lsa
->header
);
553 copy
= ospf6_lsa_create (lsa
->header
);
554 assert (copy
->lock
== 0);
556 copy
->birth
= lsa
->birth
;
557 copy
->originated
= lsa
->originated
;
558 copy
->received
= lsa
->received
;
559 copy
->installed
= lsa
->installed
;
560 copy
->lsdb
= lsa
->lsdb
;
565 /* increment reference counter of struct ospf6_lsa */
567 ospf6_lsa_lock (struct ospf6_lsa
*lsa
)
573 /* decrement reference counter of struct ospf6_lsa */
575 ospf6_lsa_unlock (struct ospf6_lsa
*lsa
)
577 /* decrement reference counter */
578 assert (lsa
->lock
> 0);
584 ospf6_lsa_delete (lsa
);
588 /* ospf6 lsa expiry */
590 ospf6_lsa_expire (struct thread
*thread
)
592 struct ospf6_lsa
*lsa
;
594 lsa
= (struct ospf6_lsa
*) THREAD_ARG (thread
);
596 assert (lsa
&& lsa
->header
);
597 assert (OSPF6_LSA_IS_MAXAGE (lsa
));
598 assert (! lsa
->refresh
);
600 lsa
->expire
= (struct thread
*) NULL
;
602 if (IS_OSPF6_DEBUG_LSA_TYPE (lsa
->header
->type
))
604 zlog_debug ("LSA Expire:");
605 ospf6_lsa_header_print (lsa
);
608 if (CHECK_FLAG (lsa
->flag
, OSPF6_LSA_HEADERONLY
))
609 return 0; /* dbexchange will do something ... */
612 ospf6_flood (NULL
, lsa
);
615 ospf6_install_lsa (lsa
);
617 /* schedule maxage remover */
618 ospf6_maxage_remove (ospf6
);
624 ospf6_lsa_refresh (struct thread
*thread
)
626 struct ospf6_lsa
*old
, *self
, *new;
627 struct ospf6_lsdb
*lsdb_self
;
630 old
= (struct ospf6_lsa
*) THREAD_ARG (thread
);
631 assert (old
&& old
->header
);
633 old
->refresh
= (struct thread
*) NULL
;
635 lsdb_self
= ospf6_get_scoped_lsdb_self (old
);
636 self
= ospf6_lsdb_lookup (old
->header
->type
, old
->header
->id
,
637 old
->header
->adv_router
, lsdb_self
);
640 if (IS_OSPF6_DEBUG_LSA_TYPE (old
->header
->type
))
641 zlog_debug ("Refresh: could not find self LSA, flush %s", old
->name
);
642 ospf6_lsa_premature_aging (old
);
646 /* Reset age, increment LS sequence number. */
647 self
->header
->age
= htons (0);
648 self
->header
->seqnum
=
649 ospf6_new_ls_seqnum (self
->header
->type
, self
->header
->id
,
650 self
->header
->adv_router
, old
->lsdb
);
651 ospf6_lsa_checksum (self
->header
);
653 new = ospf6_lsa_create (self
->header
);
654 new->lsdb
= old
->lsdb
;
655 new->refresh
= thread_add_timer (master
, ospf6_lsa_refresh
, new,
658 /* store it in the LSDB for self-originated LSAs */
659 ospf6_lsdb_add (ospf6_lsa_copy (new), lsdb_self
);
661 if (IS_OSPF6_DEBUG_LSA_TYPE (new->header
->type
))
663 zlog_debug ("LSA Refresh:");
664 ospf6_lsa_header_print (new);
667 ospf6_flood_clear (old
);
668 ospf6_flood (NULL
, new);
669 ospf6_install_lsa (new);
676 /* Fletcher Checksum -- Refer to RFC1008. */
678 /* All the offsets are zero-based. The offsets in the RFC1008 are
681 ospf6_lsa_checksum (struct ospf6_lsa_header
*lsa_header
)
683 u_char
*buffer
= (u_char
*) &lsa_header
->type
;
684 int type_offset
= buffer
- (u_char
*) &lsa_header
->age
; /* should be 2 */
686 /* Skip the AGE field */
687 u_int16_t len
= ntohs(lsa_header
->length
) - type_offset
;
689 /* Checksum offset starts from "type" field, not the beginning of the
690 lsa_header struct. The offset is 14, rather than 16. */
691 int checksum_offset
= (u_char
*) &lsa_header
->checksum
- buffer
;
693 return (unsigned short)fletcher_checksum(buffer
, len
, checksum_offset
);
697 ospf6_lsa_checksum_valid (struct ospf6_lsa_header
*lsa_header
)
699 u_char
*buffer
= (u_char
*) &lsa_header
->type
;
700 int type_offset
= buffer
- (u_char
*) &lsa_header
->age
; /* should be 2 */
702 /* Skip the AGE field */
703 u_int16_t len
= ntohs(lsa_header
->length
) - type_offset
;
705 return (fletcher_checksum(buffer
, len
, FLETCHER_CHECKSUM_VALIDATE
) == 0);
709 ospf6_lsa_init (void)
711 ospf6_lsa_handler_vector
= vector_init (0);
712 ospf6_install_lsa_handler (&unknown_handler
);
716 ospf6_lsa_terminate (void)
718 vector_free (ospf6_lsa_handler_vector
);
722 ospf6_lsa_handler_name (struct ospf6_lsa_handler
*h
)
726 unsigned int size
= strlen (h
->name
);
728 if (!strcmp(h
->name
, "Unknown") &&
729 h
->type
!= OSPF6_LSTYPE_UNKNOWN
)
731 snprintf (buf
, sizeof (buf
), "%#04hx", h
->type
);
735 for (i
= 0; i
< MIN (size
, sizeof (buf
)); i
++)
737 if (! islower (h
->name
[i
]))
738 buf
[i
] = tolower (h
->name
[i
]);
746 DEFUN (debug_ospf6_lsa_type
,
747 debug_ospf6_lsa_hex_cmd
,
748 "debug ospf6 lsa XXXX/0xXXXX",
751 "Debug Link State Advertisements (LSAs)\n"
752 "Specify LS type as Hexadecimal\n"
756 struct ospf6_lsa_handler
*handler
= NULL
;
763 if ((strlen (argv
[0]) == 6 && ! strncmp (argv
[0], "0x", 2)) ||
764 (strlen (argv
[0]) == 4))
766 val
= strtoul (argv
[0], &endptr
, 16);
771 for (i
= 0; i
< vector_active (ospf6_lsa_handler_vector
); i
++)
773 handler
= vector_slot (ospf6_lsa_handler_vector
, i
);
776 if (type
&& handler
->type
== type
)
778 if (! strcasecmp (argv
[0], handler
->name
))
783 if (type
&& handler
== NULL
)
785 handler
= (struct ospf6_lsa_handler
*)
786 malloc (sizeof (struct ospf6_lsa_handler
));
787 memset (handler
, 0, sizeof (struct ospf6_lsa_handler
));
788 handler
->type
= type
;
789 handler
->name
= "Unknown";
790 handler
->show
= ospf6_unknown_lsa_show
;
791 vector_set_index (ospf6_lsa_handler_vector
,
792 handler
->type
& OSPF6_LSTYPE_FCODE_MASK
, handler
);
796 handler
= &unknown_handler
;
800 if (! strcmp (argv
[1], "originate"))
801 SET_FLAG (handler
->debug
, OSPF6_LSA_DEBUG_ORIGINATE
);
802 if (! strcmp (argv
[1], "examin"))
803 SET_FLAG (handler
->debug
, OSPF6_LSA_DEBUG_EXAMIN
);
804 if (! strcmp (argv
[1], "flooding"))
805 SET_FLAG (handler
->debug
, OSPF6_LSA_DEBUG_FLOOD
);
808 SET_FLAG (handler
->debug
, OSPF6_LSA_DEBUG
);
813 DEFUN (no_debug_ospf6_lsa_type
,
814 no_debug_ospf6_lsa_hex_cmd
,
815 "no debug ospf6 lsa XXXX/0xXXXX",
819 "Debug Link State Advertisements (LSAs)\n"
820 "Specify LS type as Hexadecimal\n"
824 struct ospf6_lsa_handler
*handler
= NULL
;
831 if ((strlen (argv
[0]) == 6 && ! strncmp (argv
[0], "0x", 2)) ||
832 (strlen (argv
[0]) == 4))
834 val
= strtoul (argv
[0], &endptr
, 16);
839 for (i
= 0; i
< vector_active (ospf6_lsa_handler_vector
); i
++)
841 handler
= vector_slot (ospf6_lsa_handler_vector
, i
);
844 if (type
&& handler
->type
== type
)
846 if (! strcasecmp (argv
[0], handler
->name
))
855 if (! strcmp (argv
[1], "originate"))
856 UNSET_FLAG (handler
->debug
, OSPF6_LSA_DEBUG_ORIGINATE
);
857 if (! strcmp (argv
[1], "examin"))
858 UNSET_FLAG (handler
->debug
, OSPF6_LSA_DEBUG_EXAMIN
);
859 if (! strcmp (argv
[1], "flooding"))
860 UNSET_FLAG (handler
->debug
, OSPF6_LSA_DEBUG_FLOOD
);
863 UNSET_FLAG (handler
->debug
, OSPF6_LSA_DEBUG
);
865 if (handler
->debug
== 0 &&
866 !strcmp(handler
->name
, "Unknown") && type
!= OSPF6_LSTYPE_UNKNOWN
)
869 vector_slot (ospf6_lsa_handler_vector
, i
) = NULL
;
875 struct cmd_element debug_ospf6_lsa_type_cmd
;
876 struct cmd_element debug_ospf6_lsa_type_detail_cmd
;
877 struct cmd_element no_debug_ospf6_lsa_type_cmd
;
878 struct cmd_element no_debug_ospf6_lsa_type_detail_cmd
;
881 install_element_ospf6_debug_lsa (void)
884 struct ospf6_lsa_handler
*handler
;
887 static char strbuf
[STRSIZE
];
888 static char docbuf
[DOCSIZE
];
889 static char detail_strbuf
[STRSIZE
];
890 static char detail_docbuf
[DOCSIZE
];
895 no_str
= &strbuf
[strlen (strbuf
)];
896 strncat (strbuf
, "no ", STRSIZE
- strlen (strbuf
));
897 str
= &strbuf
[strlen (strbuf
)];
899 strncat (strbuf
, "debug ospf6 lsa (", STRSIZE
- strlen (strbuf
));
900 for (i
= 0; i
< vector_active (ospf6_lsa_handler_vector
); i
++)
902 handler
= vector_slot (ospf6_lsa_handler_vector
, i
);
905 strncat (strbuf
, ospf6_lsa_handler_name (handler
),
906 STRSIZE
- strlen (strbuf
));
907 strncat (strbuf
, "|", STRSIZE
- strlen (strbuf
));
909 strbuf
[strlen (strbuf
) - 1] = ')';
910 strbuf
[strlen (strbuf
)] = '\0';
913 no_doc
= &docbuf
[strlen (docbuf
)];
914 strncat (docbuf
, NO_STR
, DOCSIZE
- strlen (docbuf
));
915 doc
= &docbuf
[strlen (docbuf
)];
917 strncat (docbuf
, DEBUG_STR
, DOCSIZE
- strlen (docbuf
));
918 strncat (docbuf
, OSPF6_STR
, DOCSIZE
- strlen (docbuf
));
919 strncat (docbuf
, "Debug Link State Advertisements (LSAs)\n",
920 DOCSIZE
- strlen (docbuf
));
922 for (i
= 0; i
< vector_active (ospf6_lsa_handler_vector
); i
++)
924 handler
= vector_slot (ospf6_lsa_handler_vector
, i
);
927 strncat (docbuf
, "Debug ", DOCSIZE
- strlen (docbuf
));
928 strncat (docbuf
, handler
->name
, DOCSIZE
- strlen (docbuf
));
929 strncat (docbuf
, "-LSA\n", DOCSIZE
- strlen (docbuf
));
931 docbuf
[strlen (docbuf
)] = '\0';
933 debug_ospf6_lsa_type_cmd
.string
= str
;
934 debug_ospf6_lsa_type_cmd
.func
= debug_ospf6_lsa_type
;
935 debug_ospf6_lsa_type_cmd
.doc
= doc
;
937 no_debug_ospf6_lsa_type_cmd
.string
= no_str
;
938 no_debug_ospf6_lsa_type_cmd
.func
= no_debug_ospf6_lsa_type
;
939 no_debug_ospf6_lsa_type_cmd
.doc
= no_doc
;
941 strncpy (detail_strbuf
, strbuf
, STRSIZE
);
942 strncat (detail_strbuf
, " (originate|examin|flooding)",
943 STRSIZE
- strlen (detail_strbuf
));
944 detail_strbuf
[strlen (detail_strbuf
)] = '\0';
945 no_str
= &detail_strbuf
[0];
946 str
= &detail_strbuf
[strlen ("no ")];
948 strncpy (detail_docbuf
, docbuf
, DOCSIZE
);
949 strncat (detail_docbuf
, "Debug Originating LSA\n",
950 DOCSIZE
- strlen (detail_docbuf
));
951 strncat (detail_docbuf
, "Debug Examining LSA\n",
952 DOCSIZE
- strlen (detail_docbuf
));
953 strncat (detail_docbuf
, "Debug Flooding LSA\n",
954 DOCSIZE
- strlen (detail_docbuf
));
955 detail_docbuf
[strlen (detail_docbuf
)] = '\0';
956 no_doc
= &detail_docbuf
[0];
957 doc
= &detail_docbuf
[strlen (NO_STR
)];
959 debug_ospf6_lsa_type_detail_cmd
.string
= str
;
960 debug_ospf6_lsa_type_detail_cmd
.func
= debug_ospf6_lsa_type
;
961 debug_ospf6_lsa_type_detail_cmd
.doc
= doc
;
963 no_debug_ospf6_lsa_type_detail_cmd
.string
= no_str
;
964 no_debug_ospf6_lsa_type_detail_cmd
.func
= no_debug_ospf6_lsa_type
;
965 no_debug_ospf6_lsa_type_detail_cmd
.doc
= no_doc
;
967 install_element (ENABLE_NODE
, &debug_ospf6_lsa_hex_cmd
);
968 install_element (ENABLE_NODE
, &debug_ospf6_lsa_type_cmd
);
969 install_element (ENABLE_NODE
, &debug_ospf6_lsa_type_detail_cmd
);
970 install_element (ENABLE_NODE
, &no_debug_ospf6_lsa_hex_cmd
);
971 install_element (ENABLE_NODE
, &no_debug_ospf6_lsa_type_cmd
);
972 install_element (ENABLE_NODE
, &no_debug_ospf6_lsa_type_detail_cmd
);
973 install_element (CONFIG_NODE
, &debug_ospf6_lsa_hex_cmd
);
974 install_element (CONFIG_NODE
, &debug_ospf6_lsa_type_cmd
);
975 install_element (CONFIG_NODE
, &debug_ospf6_lsa_type_detail_cmd
);
976 install_element (CONFIG_NODE
, &no_debug_ospf6_lsa_hex_cmd
);
977 install_element (CONFIG_NODE
, &no_debug_ospf6_lsa_type_cmd
);
978 install_element (CONFIG_NODE
, &no_debug_ospf6_lsa_type_detail_cmd
);
982 config_write_ospf6_debug_lsa (struct vty
*vty
)
985 struct ospf6_lsa_handler
*handler
;
987 for (i
= 0; i
< vector_active (ospf6_lsa_handler_vector
); i
++)
989 handler
= vector_slot (ospf6_lsa_handler_vector
, i
);
992 if (CHECK_FLAG (handler
->debug
, OSPF6_LSA_DEBUG
))
993 vty_out (vty
, "debug ospf6 lsa %s%s",
994 ospf6_lsa_handler_name (handler
), VNL
);
995 if (CHECK_FLAG (handler
->debug
, OSPF6_LSA_DEBUG_ORIGINATE
))
996 vty_out (vty
, "debug ospf6 lsa %s originate%s",
997 ospf6_lsa_handler_name (handler
), VNL
);
998 if (CHECK_FLAG (handler
->debug
, OSPF6_LSA_DEBUG_EXAMIN
))
999 vty_out (vty
, "debug ospf6 lsa %s examin%s",
1000 ospf6_lsa_handler_name (handler
), VNL
);
1001 if (CHECK_FLAG (handler
->debug
, OSPF6_LSA_DEBUG_FLOOD
))
1002 vty_out (vty
, "debug ospf6 lsa %s flooding%s",
1003 ospf6_lsa_handler_name (handler
), VNL
);