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 (ntohs (lsa
->header
->age
) >= MAXAGE
)
212 /* ospf6_lsa_premature_aging () sets age to MAXAGE; when using
213 relative time, we cannot compare against lsa birth time, so
214 we catch this special case here. */
215 lsa
->header
->age
= htons (MAXAGE
);
219 ulage
= now
.tv_sec
- lsa
->birth
.tv_sec
;
221 /* if over MAXAGE, set to it */
222 age
= (ulage
> MAXAGE
? MAXAGE
: ulage
);
224 lsa
->header
->age
= htons (age
);
228 /* update age field of LSA header with adding InfTransDelay */
230 ospf6_lsa_age_update_to_send (struct ospf6_lsa
*lsa
, u_int32_t transdelay
)
234 age
= ospf6_lsa_age_current (lsa
) + transdelay
;
237 lsa
->header
->age
= htons (age
);
241 ospf6_lsa_premature_aging (struct ospf6_lsa
*lsa
)
244 if (IS_OSPF6_DEBUG_LSA_TYPE (lsa
->header
->type
))
245 zlog_debug ("LSA: Premature aging: %s", lsa
->name
);
247 THREAD_OFF (lsa
->expire
);
248 THREAD_OFF (lsa
->refresh
);
250 lsa
->header
->age
= htons (MAXAGE
);
251 thread_execute (master
, ospf6_lsa_expire
, lsa
, 0);
254 /* check which is more recent. if a is more recent, return -1;
255 if the same, return 0; otherwise(b is more recent), return 1 */
257 ospf6_lsa_compare (struct ospf6_lsa
*a
, struct ospf6_lsa
*b
)
259 signed long seqnuma
, seqnumb
;
260 u_int16_t cksuma
, cksumb
;
261 u_int16_t agea
, ageb
;
263 assert (a
&& a
->header
);
264 assert (b
&& b
->header
);
265 assert (OSPF6_LSA_IS_SAME (a
, b
));
267 seqnuma
= ((signed long) ntohl (a
->header
->seqnum
))
268 - (signed long) INITIAL_SEQUENCE_NUMBER
;
269 seqnumb
= ((signed long) ntohl (b
->header
->seqnum
))
270 - (signed long) INITIAL_SEQUENCE_NUMBER
;
272 /* compare by sequence number */
273 /* XXX, LS sequence number wrapping */
274 if (seqnuma
> seqnumb
)
276 else if (seqnuma
< seqnumb
)
280 cksuma
= ntohs (a
->header
->checksum
);
281 cksumb
= ntohs (b
->header
->checksum
);
288 agea
= ospf6_lsa_age_current (a
);
289 ageb
= ospf6_lsa_age_current (b
);
292 if (agea
== MAXAGE
&& ageb
!= MAXAGE
)
294 else if (agea
!= MAXAGE
&& ageb
== MAXAGE
)
298 if (agea
> ageb
&& agea
- ageb
>= MAX_AGE_DIFF
)
300 else if (agea
< ageb
&& ageb
- agea
>= MAX_AGE_DIFF
)
308 ospf6_lsa_printbuf (struct ospf6_lsa
*lsa
, char *buf
, int size
)
310 char id
[16], adv_router
[16];
311 inet_ntop (AF_INET
, &lsa
->header
->id
, id
, sizeof (id
));
312 inet_ntop (AF_INET
, &lsa
->header
->adv_router
, adv_router
,
313 sizeof (adv_router
));
314 snprintf (buf
, size
, "[%s Id:%s Adv:%s]",
315 ospf6_lstype_name (lsa
->header
->type
), id
, adv_router
);
320 ospf6_lsa_header_print_raw (struct ospf6_lsa_header
*header
)
322 char id
[16], adv_router
[16];
323 inet_ntop (AF_INET
, &header
->id
, id
, sizeof (id
));
324 inet_ntop (AF_INET
, &header
->adv_router
, adv_router
,
325 sizeof (adv_router
));
326 zlog_debug (" [%s Id:%s Adv:%s]",
327 ospf6_lstype_name (header
->type
), id
, adv_router
);
328 zlog_debug (" Age: %4hu SeqNum: %#08lx Cksum: %04hx Len: %d",
329 ntohs (header
->age
), (u_long
) ntohl (header
->seqnum
),
330 ntohs (header
->checksum
), ntohs (header
->length
));
334 ospf6_lsa_header_print (struct ospf6_lsa
*lsa
)
336 ospf6_lsa_age_current (lsa
);
337 ospf6_lsa_header_print_raw (lsa
->header
);
341 ospf6_lsa_show_summary_header (struct vty
*vty
)
343 vty_out (vty
, "%-12s %-15s %-15s %4s %8s %4s %4s %-8s%s",
344 "Type", "LSId", "AdvRouter", "Age", "SeqNum",
345 "Cksm", "Len", "Duration", VNL
);
349 ospf6_lsa_show_summary (struct vty
*vty
, struct ospf6_lsa
*lsa
)
351 char adv_router
[16], id
[16];
352 struct timeval now
, res
;
356 assert (lsa
->header
);
358 inet_ntop (AF_INET
, &lsa
->header
->id
, id
, sizeof (id
));
359 inet_ntop (AF_INET
, &lsa
->header
->adv_router
, adv_router
,
360 sizeof (adv_router
));
362 quagga_gettime (QUAGGA_CLK_MONOTONIC
, &now
);
363 timersub (&now
, &lsa
->installed
, &res
);
364 timerstring (&res
, duration
, sizeof (duration
));
366 vty_out (vty
, "%-12s %-15s %-15s %4hu %8lx %04hx %4hu %8s%s",
367 ospf6_lstype_name (lsa
->header
->type
),
368 id
, adv_router
, ospf6_lsa_age_current (lsa
),
369 (u_long
) ntohl (lsa
->header
->seqnum
),
370 ntohs (lsa
->header
->checksum
), ntohs (lsa
->header
->length
),
375 ospf6_lsa_show_dump (struct vty
*vty
, struct ospf6_lsa
*lsa
)
377 u_char
*start
, *end
, *current
;
380 start
= (u_char
*) lsa
->header
;
381 end
= (u_char
*) lsa
->header
+ ntohs (lsa
->header
->length
);
383 vty_out (vty
, "%s", VNL
);
384 vty_out (vty
, "%s:%s", lsa
->name
, VNL
);
386 for (current
= start
; current
< end
; current
++)
388 if ((current
- start
) % 16 == 0)
389 vty_out (vty
, "%s ", VNL
);
390 else if ((current
- start
) % 4 == 0)
393 snprintf (byte
, sizeof (byte
), "%02x", *current
);
394 vty_out (vty
, "%s", byte
);
397 vty_out (vty
, "%s%s", VNL
, VNL
);
402 ospf6_lsa_show_internal (struct vty
*vty
, struct ospf6_lsa
*lsa
)
404 char adv_router
[64], id
[64];
406 assert (lsa
&& lsa
->header
);
408 inet_ntop (AF_INET
, &lsa
->header
->id
, id
, sizeof (id
));
409 inet_ntop (AF_INET
, &lsa
->header
->adv_router
,
410 adv_router
, sizeof (adv_router
));
412 vty_out (vty
, "%s", VNL
);
413 vty_out (vty
, "Age: %4hu Type: %s%s", ospf6_lsa_age_current (lsa
),
414 ospf6_lstype_name (lsa
->header
->type
), VNL
);
415 vty_out (vty
, "Link State ID: %s%s", id
, VNL
);
416 vty_out (vty
, "Advertising Router: %s%s", adv_router
, VNL
);
417 vty_out (vty
, "LS Sequence Number: %#010lx%s",
418 (u_long
) ntohl (lsa
->header
->seqnum
), VNL
);
419 vty_out (vty
, "CheckSum: %#06hx Length: %hu%s",
420 ntohs (lsa
->header
->checksum
),
421 ntohs (lsa
->header
->length
), VNL
);
422 vty_out (vty
, " Prev: %p This: %p Next: %p%s",
423 lsa
->prev
, lsa
, lsa
->next
, VNL
);
424 vty_out (vty
, "%s", VNL
);
429 ospf6_lsa_show (struct vty
*vty
, struct ospf6_lsa
*lsa
)
431 char adv_router
[64], id
[64];
432 struct ospf6_lsa_handler
*handler
;
434 assert (lsa
&& lsa
->header
);
436 inet_ntop (AF_INET
, &lsa
->header
->id
, id
, sizeof (id
));
437 inet_ntop (AF_INET
, &lsa
->header
->adv_router
,
438 adv_router
, sizeof (adv_router
));
440 vty_out (vty
, "Age: %4hu Type: %s%s", ospf6_lsa_age_current (lsa
),
441 ospf6_lstype_name (lsa
->header
->type
), VNL
);
442 vty_out (vty
, "Link State ID: %s%s", id
, VNL
);
443 vty_out (vty
, "Advertising Router: %s%s", adv_router
, VNL
);
444 vty_out (vty
, "LS Sequence Number: %#010lx%s",
445 (u_long
) ntohl (lsa
->header
->seqnum
), VNL
);
446 vty_out (vty
, "CheckSum: %#06hx Length: %hu%s",
447 ntohs (lsa
->header
->checksum
),
448 ntohs (lsa
->header
->length
), VNL
);
450 handler
= ospf6_get_lsa_handler (lsa
->header
->type
);
451 if (handler
->show
== NULL
)
452 handler
= &unknown_handler
;
453 (*handler
->show
) (vty
, lsa
);
455 vty_out (vty
, "%s", VNL
);
458 /* OSPFv3 LSA creation/deletion function */
460 ospf6_lsa_create (struct ospf6_lsa_header
*header
)
462 struct ospf6_lsa
*lsa
= NULL
;
463 struct ospf6_lsa_header
*new_header
= NULL
;
464 u_int16_t lsa_size
= 0;
466 /* size of the entire LSA */
467 lsa_size
= ntohs (header
->length
); /* XXX vulnerable */
469 /* allocate memory for this LSA */
470 new_header
= (struct ospf6_lsa_header
*)
471 XMALLOC (MTYPE_OSPF6_LSA
, lsa_size
);
473 /* copy LSA from original header */
474 memcpy (new_header
, header
, lsa_size
);
476 /* LSA information structure */
477 /* allocate memory */
478 lsa
= (struct ospf6_lsa
*)
479 XCALLOC (MTYPE_OSPF6_LSA
, sizeof (struct ospf6_lsa
));
481 lsa
->header
= (struct ospf6_lsa_header
*) new_header
;
484 ospf6_lsa_printbuf (lsa
, lsa
->name
, sizeof (lsa
->name
));
486 /* calculate birth of this lsa */
487 ospf6_lsa_age_set (lsa
);
493 ospf6_lsa_create_headeronly (struct ospf6_lsa_header
*header
)
495 struct ospf6_lsa
*lsa
= NULL
;
496 struct ospf6_lsa_header
*new_header
= NULL
;
498 /* allocate memory for this LSA */
499 new_header
= (struct ospf6_lsa_header
*)
500 XMALLOC (MTYPE_OSPF6_LSA
, sizeof (struct ospf6_lsa_header
));
502 /* copy LSA from original header */
503 memcpy (new_header
, header
, sizeof (struct ospf6_lsa_header
));
505 /* LSA information structure */
506 /* allocate memory */
507 lsa
= (struct ospf6_lsa
*)
508 XCALLOC (MTYPE_OSPF6_LSA
, sizeof (struct ospf6_lsa
));
510 lsa
->header
= (struct ospf6_lsa_header
*) new_header
;
511 SET_FLAG (lsa
->flag
, OSPF6_LSA_HEADERONLY
);
514 ospf6_lsa_printbuf (lsa
, lsa
->name
, sizeof (lsa
->name
));
516 /* calculate birth of this lsa */
517 ospf6_lsa_age_set (lsa
);
523 ospf6_lsa_delete (struct ospf6_lsa
*lsa
)
525 assert (lsa
->lock
== 0);
528 THREAD_OFF (lsa
->expire
);
529 THREAD_OFF (lsa
->refresh
);
532 XFREE (MTYPE_OSPF6_LSA
, lsa
->header
);
533 XFREE (MTYPE_OSPF6_LSA
, lsa
);
537 ospf6_lsa_copy (struct ospf6_lsa
*lsa
)
539 struct ospf6_lsa
*copy
= NULL
;
541 ospf6_lsa_age_current (lsa
);
542 if (CHECK_FLAG (lsa
->flag
, OSPF6_LSA_HEADERONLY
))
543 copy
= ospf6_lsa_create_headeronly (lsa
->header
);
545 copy
= ospf6_lsa_create (lsa
->header
);
546 assert (copy
->lock
== 0);
548 copy
->birth
= lsa
->birth
;
549 copy
->originated
= lsa
->originated
;
550 copy
->received
= lsa
->received
;
551 copy
->installed
= lsa
->installed
;
552 copy
->lsdb
= lsa
->lsdb
;
557 /* increment reference counter of struct ospf6_lsa */
559 ospf6_lsa_lock (struct ospf6_lsa
*lsa
)
565 /* decrement reference counter of struct ospf6_lsa */
567 ospf6_lsa_unlock (struct ospf6_lsa
*lsa
)
569 /* decrement reference counter */
570 assert (lsa
->lock
> 0);
576 ospf6_lsa_delete (lsa
);
580 /* ospf6 lsa expiry */
582 ospf6_lsa_expire (struct thread
*thread
)
584 struct ospf6_lsa
*lsa
;
586 lsa
= (struct ospf6_lsa
*) THREAD_ARG (thread
);
588 assert (lsa
&& lsa
->header
);
589 assert (OSPF6_LSA_IS_MAXAGE (lsa
));
590 assert (! lsa
->refresh
);
592 lsa
->expire
= (struct thread
*) NULL
;
594 if (IS_OSPF6_DEBUG_LSA_TYPE (lsa
->header
->type
))
596 zlog_debug ("LSA Expire:");
597 ospf6_lsa_header_print (lsa
);
600 if (CHECK_FLAG (lsa
->flag
, OSPF6_LSA_HEADERONLY
))
601 return 0; /* dbexchange will do something ... */
604 ospf6_flood (NULL
, lsa
);
607 ospf6_install_lsa (lsa
);
609 /* schedule maxage remover */
610 ospf6_maxage_remove (ospf6
);
616 ospf6_lsa_refresh (struct thread
*thread
)
618 struct ospf6_lsa
*old
, *self
, *new;
619 struct ospf6_lsdb
*lsdb_self
;
622 old
= (struct ospf6_lsa
*) THREAD_ARG (thread
);
623 assert (old
&& old
->header
);
625 old
->refresh
= (struct thread
*) NULL
;
627 lsdb_self
= ospf6_get_scoped_lsdb_self (old
);
628 self
= ospf6_lsdb_lookup (old
->header
->type
, old
->header
->id
,
629 old
->header
->adv_router
, lsdb_self
);
632 if (IS_OSPF6_DEBUG_LSA_TYPE (old
->header
->type
))
633 zlog_debug ("Refresh: could not find self LSA, flush %s", old
->name
);
634 ospf6_lsa_premature_aging (old
);
638 /* Reset age, increment LS sequence number. */
639 self
->header
->age
= htons (0);
640 self
->header
->seqnum
=
641 ospf6_new_ls_seqnum (self
->header
->type
, self
->header
->id
,
642 self
->header
->adv_router
, old
->lsdb
);
643 ospf6_lsa_checksum (self
->header
);
645 new = ospf6_lsa_create (self
->header
);
646 new->lsdb
= old
->lsdb
;
647 new->refresh
= thread_add_timer (master
, ospf6_lsa_refresh
, new,
650 /* store it in the LSDB for self-originated LSAs */
651 ospf6_lsdb_add (ospf6_lsa_copy (new), lsdb_self
);
653 if (IS_OSPF6_DEBUG_LSA_TYPE (new->header
->type
))
655 zlog_debug ("LSA Refresh:");
656 ospf6_lsa_header_print (new);
659 ospf6_flood_clear (old
);
660 ospf6_flood (NULL
, new);
661 ospf6_install_lsa (new);
668 /* enhanced Fletcher checksum algorithm, RFC1008 7.2 */
670 #define LSA_CHECKSUM_OFFSET 15
673 ospf6_lsa_checksum (struct ospf6_lsa_header
*lsa_header
)
675 u_char
*sp
, *ep
, *p
, *q
;
680 lsa_header
->checksum
= 0;
681 length
= ntohs (lsa_header
->length
) - 2;
682 sp
= (u_char
*) &lsa_header
->type
;
684 for (ep
= sp
+ length
; sp
< ep
; sp
= q
)
689 for (p
= sp
; p
< q
; p
++)
698 /* r = (c1 << 8) + c0; */
699 x
= ((length
- LSA_CHECKSUM_OFFSET
) * c0
- c1
) % 255;
706 lsa_header
->checksum
= htons ((x
<< 8) + y
);
708 return (lsa_header
->checksum
);
712 ospf6_lsa_init (void)
714 ospf6_lsa_handler_vector
= vector_init (0);
715 ospf6_install_lsa_handler (&unknown_handler
);
720 ospf6_lsa_handler_name (struct ospf6_lsa_handler
*h
)
724 unsigned int size
= strlen (h
->name
);
726 if (!strcmp(h
->name
, "Unknown") &&
727 h
->type
!= OSPF6_LSTYPE_UNKNOWN
)
729 snprintf (buf
, sizeof (buf
), "%#04hx", h
->type
);
733 for (i
= 0; i
< MIN (size
, sizeof (buf
)); i
++)
735 if (! islower (h
->name
[i
]))
736 buf
[i
] = tolower (h
->name
[i
]);
744 DEFUN (debug_ospf6_lsa_type
,
745 debug_ospf6_lsa_hex_cmd
,
746 "debug ospf6 lsa XXXX/0xXXXX",
749 "Debug Link State Advertisements (LSAs)\n"
750 "Specify LS type as Hexadecimal\n"
754 struct ospf6_lsa_handler
*handler
= NULL
;
761 if ((strlen (argv
[0]) == 6 && ! strncmp (argv
[0], "0x", 2)) ||
762 (strlen (argv
[0]) == 4))
764 val
= strtoul (argv
[0], &endptr
, 16);
769 for (i
= 0; i
< vector_active (ospf6_lsa_handler_vector
); i
++)
771 handler
= vector_slot (ospf6_lsa_handler_vector
, i
);
774 if (type
&& handler
->type
== type
)
776 if (! strcasecmp (argv
[0], handler
->name
))
781 if (type
&& handler
== NULL
)
783 handler
= (struct ospf6_lsa_handler
*)
784 malloc (sizeof (struct ospf6_lsa_handler
));
785 memset (handler
, 0, sizeof (struct ospf6_lsa_handler
));
786 handler
->type
= type
;
787 handler
->name
= "Unknown";
788 handler
->show
= ospf6_unknown_lsa_show
;
789 vector_set_index (ospf6_lsa_handler_vector
,
790 handler
->type
& OSPF6_LSTYPE_FCODE_MASK
, handler
);
794 handler
= &unknown_handler
;
798 if (! strcmp (argv
[1], "originate"))
799 SET_FLAG (handler
->debug
, OSPF6_LSA_DEBUG_ORIGINATE
);
800 if (! strcmp (argv
[1], "examin"))
801 SET_FLAG (handler
->debug
, OSPF6_LSA_DEBUG_EXAMIN
);
802 if (! strcmp (argv
[1], "flooding"))
803 SET_FLAG (handler
->debug
, OSPF6_LSA_DEBUG_FLOOD
);
806 SET_FLAG (handler
->debug
, OSPF6_LSA_DEBUG
);
811 DEFUN (no_debug_ospf6_lsa_type
,
812 no_debug_ospf6_lsa_hex_cmd
,
813 "no debug ospf6 lsa XXXX/0xXXXX",
817 "Debug Link State Advertisements (LSAs)\n"
818 "Specify LS type as Hexadecimal\n"
822 struct ospf6_lsa_handler
*handler
= NULL
;
829 if ((strlen (argv
[0]) == 6 && ! strncmp (argv
[0], "0x", 2)) ||
830 (strlen (argv
[0]) == 4))
832 val
= strtoul (argv
[0], &endptr
, 16);
837 for (i
= 0; i
< vector_active (ospf6_lsa_handler_vector
); i
++)
839 handler
= vector_slot (ospf6_lsa_handler_vector
, i
);
842 if (type
&& handler
->type
== type
)
844 if (! strcasecmp (argv
[0], handler
->name
))
853 if (! strcmp (argv
[1], "originate"))
854 UNSET_FLAG (handler
->debug
, OSPF6_LSA_DEBUG_ORIGINATE
);
855 if (! strcmp (argv
[1], "examin"))
856 UNSET_FLAG (handler
->debug
, OSPF6_LSA_DEBUG_EXAMIN
);
857 if (! strcmp (argv
[1], "flooding"))
858 UNSET_FLAG (handler
->debug
, OSPF6_LSA_DEBUG_FLOOD
);
861 UNSET_FLAG (handler
->debug
, OSPF6_LSA_DEBUG
);
863 if (handler
->debug
== 0 &&
864 !strcmp(handler
->name
, "Unknown") && type
!= OSPF6_LSTYPE_UNKNOWN
)
867 vector_slot (ospf6_lsa_handler_vector
, i
) = NULL
;
873 struct cmd_element debug_ospf6_lsa_type_cmd
;
874 struct cmd_element debug_ospf6_lsa_type_detail_cmd
;
875 struct cmd_element no_debug_ospf6_lsa_type_cmd
;
876 struct cmd_element no_debug_ospf6_lsa_type_detail_cmd
;
879 install_element_ospf6_debug_lsa (void)
882 struct ospf6_lsa_handler
*handler
;
885 static char strbuf
[STRSIZE
];
886 static char docbuf
[DOCSIZE
];
887 static char detail_strbuf
[STRSIZE
];
888 static char detail_docbuf
[DOCSIZE
];
893 no_str
= &strbuf
[strlen (strbuf
)];
894 strncat (strbuf
, "no ", STRSIZE
- strlen (strbuf
));
895 str
= &strbuf
[strlen (strbuf
)];
897 strncat (strbuf
, "debug ospf6 lsa (", STRSIZE
- strlen (strbuf
));
898 for (i
= 0; i
< vector_active (ospf6_lsa_handler_vector
); i
++)
900 handler
= vector_slot (ospf6_lsa_handler_vector
, i
);
903 strncat (strbuf
, ospf6_lsa_handler_name (handler
),
904 STRSIZE
- strlen (strbuf
));
905 strncat (strbuf
, "|", STRSIZE
- strlen (strbuf
));
907 strbuf
[strlen (strbuf
) - 1] = ')';
908 strbuf
[strlen (strbuf
)] = '\0';
911 no_doc
= &docbuf
[strlen (docbuf
)];
912 strncat (docbuf
, NO_STR
, DOCSIZE
- strlen (docbuf
));
913 doc
= &docbuf
[strlen (docbuf
)];
915 strncat (docbuf
, DEBUG_STR
, DOCSIZE
- strlen (docbuf
));
916 strncat (docbuf
, OSPF6_STR
, DOCSIZE
- strlen (docbuf
));
917 strncat (docbuf
, "Debug Link State Advertisements (LSAs)\n",
918 DOCSIZE
- strlen (docbuf
));
920 for (i
= 0; i
< vector_active (ospf6_lsa_handler_vector
); i
++)
922 handler
= vector_slot (ospf6_lsa_handler_vector
, i
);
925 strncat (docbuf
, "Debug ", DOCSIZE
- strlen (docbuf
));
926 strncat (docbuf
, handler
->name
, DOCSIZE
- strlen (docbuf
));
927 strncat (docbuf
, "-LSA\n", DOCSIZE
- strlen (docbuf
));
929 docbuf
[strlen (docbuf
)] = '\0';
931 debug_ospf6_lsa_type_cmd
.string
= str
;
932 debug_ospf6_lsa_type_cmd
.func
= debug_ospf6_lsa_type
;
933 debug_ospf6_lsa_type_cmd
.doc
= doc
;
935 no_debug_ospf6_lsa_type_cmd
.string
= no_str
;
936 no_debug_ospf6_lsa_type_cmd
.func
= no_debug_ospf6_lsa_type
;
937 no_debug_ospf6_lsa_type_cmd
.doc
= no_doc
;
939 strncpy (detail_strbuf
, strbuf
, STRSIZE
);
940 strncat (detail_strbuf
, " (originate|examin|flooding)",
941 STRSIZE
- strlen (detail_strbuf
));
942 detail_strbuf
[strlen (detail_strbuf
)] = '\0';
943 no_str
= &detail_strbuf
[0];
944 str
= &detail_strbuf
[strlen ("no ")];
946 strncpy (detail_docbuf
, docbuf
, DOCSIZE
);
947 strncat (detail_docbuf
, "Debug Originating LSA\n",
948 DOCSIZE
- strlen (detail_docbuf
));
949 strncat (detail_docbuf
, "Debug Examining LSA\n",
950 DOCSIZE
- strlen (detail_docbuf
));
951 strncat (detail_docbuf
, "Debug Flooding LSA\n",
952 DOCSIZE
- strlen (detail_docbuf
));
953 detail_docbuf
[strlen (detail_docbuf
)] = '\0';
954 no_doc
= &detail_docbuf
[0];
955 doc
= &detail_docbuf
[strlen (NO_STR
)];
957 debug_ospf6_lsa_type_detail_cmd
.string
= str
;
958 debug_ospf6_lsa_type_detail_cmd
.func
= debug_ospf6_lsa_type
;
959 debug_ospf6_lsa_type_detail_cmd
.doc
= doc
;
961 no_debug_ospf6_lsa_type_detail_cmd
.string
= no_str
;
962 no_debug_ospf6_lsa_type_detail_cmd
.func
= no_debug_ospf6_lsa_type
;
963 no_debug_ospf6_lsa_type_detail_cmd
.doc
= no_doc
;
965 install_element (ENABLE_NODE
, &debug_ospf6_lsa_hex_cmd
);
966 install_element (ENABLE_NODE
, &debug_ospf6_lsa_type_cmd
);
967 install_element (ENABLE_NODE
, &debug_ospf6_lsa_type_detail_cmd
);
968 install_element (ENABLE_NODE
, &no_debug_ospf6_lsa_hex_cmd
);
969 install_element (ENABLE_NODE
, &no_debug_ospf6_lsa_type_cmd
);
970 install_element (ENABLE_NODE
, &no_debug_ospf6_lsa_type_detail_cmd
);
971 install_element (CONFIG_NODE
, &debug_ospf6_lsa_hex_cmd
);
972 install_element (CONFIG_NODE
, &debug_ospf6_lsa_type_cmd
);
973 install_element (CONFIG_NODE
, &debug_ospf6_lsa_type_detail_cmd
);
974 install_element (CONFIG_NODE
, &no_debug_ospf6_lsa_hex_cmd
);
975 install_element (CONFIG_NODE
, &no_debug_ospf6_lsa_type_cmd
);
976 install_element (CONFIG_NODE
, &no_debug_ospf6_lsa_type_detail_cmd
);
980 config_write_ospf6_debug_lsa (struct vty
*vty
)
983 struct ospf6_lsa_handler
*handler
;
985 for (i
= 0; i
< vector_active (ospf6_lsa_handler_vector
); i
++)
987 handler
= vector_slot (ospf6_lsa_handler_vector
, i
);
990 if (CHECK_FLAG (handler
->debug
, OSPF6_LSA_DEBUG
))
991 vty_out (vty
, "debug ospf6 lsa %s%s",
992 ospf6_lsa_handler_name (handler
), VNL
);
993 if (CHECK_FLAG (handler
->debug
, OSPF6_LSA_DEBUG_ORIGINATE
))
994 vty_out (vty
, "debug ospf6 lsa %s originate%s",
995 ospf6_lsa_handler_name (handler
), VNL
);
996 if (CHECK_FLAG (handler
->debug
, OSPF6_LSA_DEBUG_EXAMIN
))
997 vty_out (vty
, "debug ospf6 lsa %s examin%s",
998 ospf6_lsa_handler_name (handler
), VNL
);
999 if (CHECK_FLAG (handler
->debug
, OSPF6_LSA_DEBUG_FLOOD
))
1000 vty_out (vty
, "debug ospf6 lsa %s flooding%s",
1001 ospf6_lsa_handler_name (handler
), VNL
);