blob: e65752d8cd19a8d8154ae1693e17e87861653a8f [file] [log] [blame]
paul718e3742002-12-13 20:15:29 +00001/*
hasso508e53e2004-05-18 18:57:06 +00002 * Copyright (C) 2003 Yasuhiro Ohara
paul718e3742002-12-13 20:15:29 +00003 *
4 * This file is part of GNU Zebra.
5 *
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
9 * later version.
10 *
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.
15 *
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.
20 */
21
22#include <zebra.h>
23
24/* Include other stuffs */
paul718e3742002-12-13 20:15:29 +000025#include "log.h"
paul718e3742002-12-13 20:15:29 +000026#include "linklist.h"
hasso1e058382004-09-01 21:36:14 +000027#include "vector.h"
28#include "vty.h"
paul718e3742002-12-13 20:15:29 +000029#include "command.h"
30#include "memory.h"
paul718e3742002-12-13 20:15:29 +000031#include "thread.h"
paul718e3742002-12-13 20:15:29 +000032
33#include "ospf6_proto.h"
paul718e3742002-12-13 20:15:29 +000034#include "ospf6_lsa.h"
35#include "ospf6_lsdb.h"
36#include "ospf6_message.h"
paul718e3742002-12-13 20:15:29 +000037
38#include "ospf6_top.h"
39#include "ospf6_area.h"
40#include "ospf6_interface.h"
41#include "ospf6_neighbor.h"
paul718e3742002-12-13 20:15:29 +000042
hasso508e53e2004-05-18 18:57:06 +000043#include "ospf6_flood.h"
hasso049207c2004-08-04 20:02:13 +000044#include "ospf6d.h"
paul718e3742002-12-13 20:15:29 +000045
hasso1e058382004-09-01 21:36:14 +000046vector ospf6_lsa_handler_vector;
hasso508e53e2004-05-18 18:57:06 +000047
Paul Jakma6ac29a52008-08-15 13:45:30 +010048static int
hasso1e058382004-09-01 21:36:14 +000049ospf6_unknown_lsa_show (struct vty *vty, struct ospf6_lsa *lsa)
50{
51 u_char *start, *end, *current;
52 char byte[4];
hasso508e53e2004-05-18 18:57:06 +000053
hasso03d52f82004-09-29 00:26:19 +000054 start = (u_char *) lsa->header + sizeof (struct ospf6_lsa_header);
55 end = (u_char *) lsa->header + ntohs (lsa->header->length);
hasso1e058382004-09-01 21:36:14 +000056
57 vty_out (vty, " Unknown contents:%s", VNL);
58 for (current = start; current < end; current ++)
59 {
60 if ((current - start) % 16 == 0)
61 vty_out (vty, "%s ", VNL);
62 else if ((current - start) % 4 == 0)
63 vty_out (vty, " ");
64
65 snprintf (byte, sizeof (byte), "%02x", *current);
66 vty_out (vty, "%s", byte);
67 }
68
69 vty_out (vty, "%s%s", VNL, VNL);
70 return 0;
71}
72
73struct ospf6_lsa_handler unknown_handler =
74{
75 OSPF6_LSTYPE_UNKNOWN,
76 "Unknown",
77 ospf6_unknown_lsa_show,
78 OSPF6_LSA_DEBUG,
79};
80
81void
82ospf6_install_lsa_handler (struct ospf6_lsa_handler *handler)
83{
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);
87}
88
89struct ospf6_lsa_handler *
90ospf6_get_lsa_handler (u_int16_t type)
91{
92 struct ospf6_lsa_handler *handler = NULL;
paul0c083ee2004-10-10 12:54:58 +000093 unsigned int index = ntohs (type) & OSPF6_LSTYPE_FCODE_MASK;
hasso1e058382004-09-01 21:36:14 +000094
paul55468c82005-03-14 20:19:01 +000095 if (index >= vector_active (ospf6_lsa_handler_vector))
hasso1e058382004-09-01 21:36:14 +000096 handler = &unknown_handler;
97 else
98 handler = vector_slot (ospf6_lsa_handler_vector, index);
99
hasso2680aa22004-11-25 20:54:46 +0000100 if (handler == NULL)
101 handler = &unknown_handler;
102
hasso1e058382004-09-01 21:36:14 +0000103 return handler;
104}
hasso508e53e2004-05-18 18:57:06 +0000105
paul0c083ee2004-10-10 12:54:58 +0000106const char *
hasso508e53e2004-05-18 18:57:06 +0000107ospf6_lstype_name (u_int16_t type)
paul718e3742002-12-13 20:15:29 +0000108{
hasso508e53e2004-05-18 18:57:06 +0000109 static char buf[8];
hasso1e058382004-09-01 21:36:14 +0000110 struct ospf6_lsa_handler *handler;
paul718e3742002-12-13 20:15:29 +0000111
hasso1e058382004-09-01 21:36:14 +0000112 handler = ospf6_get_lsa_handler (type);
113 if (handler && handler != &unknown_handler)
114 return handler->name;
paul718e3742002-12-13 20:15:29 +0000115
hasso508e53e2004-05-18 18:57:06 +0000116 snprintf (buf, sizeof (buf), "0x%04hx", ntohs (type));
117 return buf;
paul718e3742002-12-13 20:15:29 +0000118}
119
hasso1e058382004-09-01 21:36:14 +0000120u_char
121ospf6_lstype_debug (u_int16_t type)
122{
123 struct ospf6_lsa_handler *handler;
124 handler = ospf6_get_lsa_handler (type);
125 return handler->debug;
126}
127
paul718e3742002-12-13 20:15:29 +0000128/* RFC2328: Section 13.2 */
129int
hasso508e53e2004-05-18 18:57:06 +0000130ospf6_lsa_is_differ (struct ospf6_lsa *lsa1,
131 struct ospf6_lsa *lsa2)
paul718e3742002-12-13 20:15:29 +0000132{
hasso508e53e2004-05-18 18:57:06 +0000133 int len;
paul718e3742002-12-13 20:15:29 +0000134
hasso508e53e2004-05-18 18:57:06 +0000135 assert (OSPF6_LSA_IS_SAME (lsa1, lsa2));
paul718e3742002-12-13 20:15:29 +0000136
hasso508e53e2004-05-18 18:57:06 +0000137 /* XXX, Options ??? */
paul718e3742002-12-13 20:15:29 +0000138
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)
143 return 1;
144 if (ntohs (lsa1->header->age) != MAXAGE &&
145 ntohs (lsa2->header->age) == MAXAGE)
146 return 1;
147
148 /* compare body */
149 if (ntohs (lsa1->header->length) != ntohs (lsa2->header->length))
150 return 1;
151
hasso508e53e2004-05-18 18:57:06 +0000152 len = ntohs (lsa1->header->length) - sizeof (struct ospf6_lsa_header);
153 return memcmp (lsa1->header + 1, lsa2->header + 1, len);
paul718e3742002-12-13 20:15:29 +0000154}
155
156int
hasso508e53e2004-05-18 18:57:06 +0000157ospf6_lsa_is_changed (struct ospf6_lsa *lsa1,
158 struct ospf6_lsa *lsa2)
paul718e3742002-12-13 20:15:29 +0000159{
hasso508e53e2004-05-18 18:57:06 +0000160 int length;
paul718e3742002-12-13 20:15:29 +0000161
hasso508e53e2004-05-18 18:57:06 +0000162 if (OSPF6_LSA_IS_MAXAGE (lsa1) ^ OSPF6_LSA_IS_MAXAGE (lsa2))
163 return 1;
164 if (ntohs (lsa1->header->length) != ntohs (lsa2->header->length))
165 return 1;
Denis Ovsienko09395e22011-09-26 13:18:36 +0400166 /* Going beyond LSA headers to compare the payload only makes sense, when both LSAs aren't header-only. */
167 if (CHECK_FLAG (lsa1->flag, OSPF6_LSA_HEADERONLY) != CHECK_FLAG (lsa2->flag, OSPF6_LSA_HEADERONLY))
168 {
169 zlog_warn ("%s: only one of two (%s, %s) LSAs compared is header-only", __func__, lsa1->name, lsa2->name);
170 return 1;
171 }
172 if (CHECK_FLAG (lsa1->flag, OSPF6_LSA_HEADERONLY))
173 return 0;
paul718e3742002-12-13 20:15:29 +0000174
hasso508e53e2004-05-18 18:57:06 +0000175 length = OSPF6_LSA_SIZE (lsa1->header) - sizeof (struct ospf6_lsa_header);
Denis Ovsienko09395e22011-09-26 13:18:36 +0400176 /* Once upper layer verifies LSAs received, length underrun should become a warning. */
177 if (length <= 0)
178 return 0;
paul718e3742002-12-13 20:15:29 +0000179
hasso508e53e2004-05-18 18:57:06 +0000180 return memcmp (OSPF6_LSA_HEADER_END (lsa1->header),
181 OSPF6_LSA_HEADER_END (lsa2->header), length);
paul718e3742002-12-13 20:15:29 +0000182}
183
184/* ospf6 age functions */
hasso3b687352004-08-19 06:56:53 +0000185/* calculate birth */
paul718e3742002-12-13 20:15:29 +0000186static void
187ospf6_lsa_age_set (struct ospf6_lsa *lsa)
188{
189 struct timeval now;
190
191 assert (lsa && lsa->header);
192
Takashi Sogabe86f72dc2009-06-22 13:07:02 +0900193 if (quagga_gettime (QUAGGA_CLK_MONOTONIC, &now) < 0)
194 zlog_warn ("LSA: quagga_gettime failed, may fail LSA AGEs: %s",
ajs6099b3b2004-11-20 02:06:59 +0000195 safe_strerror (errno));
paul718e3742002-12-13 20:15:29 +0000196
197 lsa->birth.tv_sec = now.tv_sec - ntohs (lsa->header->age);
198 lsa->birth.tv_usec = now.tv_usec;
hasso3b687352004-08-19 06:56:53 +0000199
paul718e3742002-12-13 20:15:29 +0000200 return;
201}
202
203/* this function calculates current age from its birth,
204 then update age field of LSA header. return value is current age */
205u_int16_t
206ospf6_lsa_age_current (struct ospf6_lsa *lsa)
207{
208 struct timeval now;
209 u_int32_t ulage;
210 u_int16_t age;
211
212 assert (lsa);
213 assert (lsa->header);
214
215 /* current time */
Takashi Sogabe86f72dc2009-06-22 13:07:02 +0900216 if (quagga_gettime (QUAGGA_CLK_MONOTONIC, &now) < 0)
217 zlog_warn ("LSA: quagga_gettime failed, may fail LSA AGEs: %s",
ajs6099b3b2004-11-20 02:06:59 +0000218 safe_strerror (errno));
paul718e3742002-12-13 20:15:29 +0000219
Tom Hendersonaabbb1a2009-08-28 15:10:00 +0100220 if (ntohs (lsa->header->age) >= MAXAGE)
Tom Henderson9b4ef252009-07-16 17:20:37 +0100221 {
Tom Hendersonaabbb1a2009-08-28 15:10:00 +0100222 /* ospf6_lsa_premature_aging () sets age to MAXAGE; when using
223 relative time, we cannot compare against lsa birth time, so
224 we catch this special case here. */
Tom Henderson9b4ef252009-07-16 17:20:37 +0100225 lsa->header->age = htons (MAXAGE);
226 return MAXAGE;
227 }
paul718e3742002-12-13 20:15:29 +0000228 /* calculate age */
229 ulage = now.tv_sec - lsa->birth.tv_sec;
230
231 /* if over MAXAGE, set to it */
hasso508e53e2004-05-18 18:57:06 +0000232 age = (ulage > MAXAGE ? MAXAGE : ulage);
paul718e3742002-12-13 20:15:29 +0000233
234 lsa->header->age = htons (age);
235 return age;
236}
237
238/* update age field of LSA header with adding InfTransDelay */
239void
240ospf6_lsa_age_update_to_send (struct ospf6_lsa *lsa, u_int32_t transdelay)
241{
242 unsigned short age;
243
244 age = ospf6_lsa_age_current (lsa) + transdelay;
245 if (age > MAXAGE)
246 age = MAXAGE;
247 lsa->header->age = htons (age);
paul718e3742002-12-13 20:15:29 +0000248}
249
250void
251ospf6_lsa_premature_aging (struct ospf6_lsa *lsa)
252{
253 /* log */
hasso1e058382004-09-01 21:36:14 +0000254 if (IS_OSPF6_DEBUG_LSA_TYPE (lsa->header->type))
hassoc6487d62004-12-24 06:00:11 +0000255 zlog_debug ("LSA: Premature aging: %s", lsa->name);
paul718e3742002-12-13 20:15:29 +0000256
hasso508e53e2004-05-18 18:57:06 +0000257 THREAD_OFF (lsa->expire);
258 THREAD_OFF (lsa->refresh);
paul718e3742002-12-13 20:15:29 +0000259
Tom Henderson9b4ef252009-07-16 17:20:37 +0100260 lsa->header->age = htons (MAXAGE);
paul718e3742002-12-13 20:15:29 +0000261 thread_execute (master, ospf6_lsa_expire, lsa, 0);
262}
263
264/* check which is more recent. if a is more recent, return -1;
265 if the same, return 0; otherwise(b is more recent), return 1 */
266int
hasso508e53e2004-05-18 18:57:06 +0000267ospf6_lsa_compare (struct ospf6_lsa *a, struct ospf6_lsa *b)
paul718e3742002-12-13 20:15:29 +0000268{
Ondrej Zajicek64bf3ab2009-12-07 12:33:20 +0300269 int seqnuma, seqnumb;
paul718e3742002-12-13 20:15:29 +0000270 u_int16_t cksuma, cksumb;
271 u_int16_t agea, ageb;
272
273 assert (a && a->header);
274 assert (b && b->header);
hasso508e53e2004-05-18 18:57:06 +0000275 assert (OSPF6_LSA_IS_SAME (a, b));
paul718e3742002-12-13 20:15:29 +0000276
Ondrej Zajicek64bf3ab2009-12-07 12:33:20 +0300277 seqnuma = (int) ntohl (a->header->seqnum);
278 seqnumb = (int) ntohl (b->header->seqnum);
paul718e3742002-12-13 20:15:29 +0000279
280 /* compare by sequence number */
paul718e3742002-12-13 20:15:29 +0000281 if (seqnuma > seqnumb)
282 return -1;
Ondrej Zajicek64bf3ab2009-12-07 12:33:20 +0300283 if (seqnuma < seqnumb)
paul718e3742002-12-13 20:15:29 +0000284 return 1;
285
286 /* Checksum */
287 cksuma = ntohs (a->header->checksum);
288 cksumb = ntohs (b->header->checksum);
289 if (cksuma > cksumb)
290 return -1;
291 if (cksuma < cksumb)
292 return 0;
293
hasso508e53e2004-05-18 18:57:06 +0000294 /* Update Age */
paul718e3742002-12-13 20:15:29 +0000295 agea = ospf6_lsa_age_current (a);
296 ageb = ospf6_lsa_age_current (b);
297
hasso508e53e2004-05-18 18:57:06 +0000298 /* MaxAge check */
299 if (agea == MAXAGE && ageb != MAXAGE)
paul718e3742002-12-13 20:15:29 +0000300 return -1;
hasso508e53e2004-05-18 18:57:06 +0000301 else if (agea != MAXAGE && ageb == MAXAGE)
paul718e3742002-12-13 20:15:29 +0000302 return 1;
303
hasso508e53e2004-05-18 18:57:06 +0000304 /* Age check */
305 if (agea > ageb && agea - ageb >= MAX_AGE_DIFF)
paul718e3742002-12-13 20:15:29 +0000306 return 1;
hasso508e53e2004-05-18 18:57:06 +0000307 else if (agea < ageb && ageb - agea >= MAX_AGE_DIFF)
paul718e3742002-12-13 20:15:29 +0000308 return -1;
309
310 /* neither recent */
paul718e3742002-12-13 20:15:29 +0000311 return 0;
312}
313
hasso508e53e2004-05-18 18:57:06 +0000314char *
315ospf6_lsa_printbuf (struct ospf6_lsa *lsa, char *buf, int size)
paul718e3742002-12-13 20:15:29 +0000316{
hasso508e53e2004-05-18 18:57:06 +0000317 char id[16], adv_router[16];
318 inet_ntop (AF_INET, &lsa->header->id, id, sizeof (id));
319 inet_ntop (AF_INET, &lsa->header->adv_router, adv_router,
320 sizeof (adv_router));
321 snprintf (buf, size, "[%s Id:%s Adv:%s]",
hasso1e058382004-09-01 21:36:14 +0000322 ospf6_lstype_name (lsa->header->type), id, adv_router);
hasso508e53e2004-05-18 18:57:06 +0000323 return buf;
paul718e3742002-12-13 20:15:29 +0000324}
325
hasso508e53e2004-05-18 18:57:06 +0000326void
327ospf6_lsa_header_print_raw (struct ospf6_lsa_header *header)
paul718e3742002-12-13 20:15:29 +0000328{
hasso508e53e2004-05-18 18:57:06 +0000329 char id[16], adv_router[16];
330 inet_ntop (AF_INET, &header->id, id, sizeof (id));
331 inet_ntop (AF_INET, &header->adv_router, adv_router,
332 sizeof (adv_router));
hassoc6487d62004-12-24 06:00:11 +0000333 zlog_debug (" [%s Id:%s Adv:%s]",
334 ospf6_lstype_name (header->type), id, adv_router);
335 zlog_debug (" Age: %4hu SeqNum: %#08lx Cksum: %04hx Len: %d",
336 ntohs (header->age), (u_long) ntohl (header->seqnum),
337 ntohs (header->checksum), ntohs (header->length));
paul718e3742002-12-13 20:15:29 +0000338}
339
hasso508e53e2004-05-18 18:57:06 +0000340void
341ospf6_lsa_header_print (struct ospf6_lsa *lsa)
paul718e3742002-12-13 20:15:29 +0000342{
hasso508e53e2004-05-18 18:57:06 +0000343 ospf6_lsa_age_current (lsa);
344 ospf6_lsa_header_print_raw (lsa->header);
paul718e3742002-12-13 20:15:29 +0000345}
346
347void
paul718e3742002-12-13 20:15:29 +0000348ospf6_lsa_show_summary_header (struct vty *vty)
349{
350 vty_out (vty, "%-12s %-15s %-15s %4s %8s %4s %4s %-8s%s",
351 "Type", "LSId", "AdvRouter", "Age", "SeqNum",
hasso049207c2004-08-04 20:02:13 +0000352 "Cksm", "Len", "Duration", VNL);
paul718e3742002-12-13 20:15:29 +0000353}
354
355void
356ospf6_lsa_show_summary (struct vty *vty, struct ospf6_lsa *lsa)
357{
hasso508e53e2004-05-18 18:57:06 +0000358 char adv_router[16], id[16];
paul718e3742002-12-13 20:15:29 +0000359 struct timeval now, res;
360 char duration[16];
361
362 assert (lsa);
363 assert (lsa->header);
364
paul718e3742002-12-13 20:15:29 +0000365 inet_ntop (AF_INET, &lsa->header->id, id, sizeof (id));
366 inet_ntop (AF_INET, &lsa->header->adv_router, adv_router,
367 sizeof (adv_router));
368
Takashi Sogabe86f72dc2009-06-22 13:07:02 +0900369 quagga_gettime (QUAGGA_CLK_MONOTONIC, &now);
hasso508e53e2004-05-18 18:57:06 +0000370 timersub (&now, &lsa->installed, &res);
371 timerstring (&res, duration, sizeof (duration));
paul718e3742002-12-13 20:15:29 +0000372
373 vty_out (vty, "%-12s %-15s %-15s %4hu %8lx %04hx %4hu %8s%s",
hasso1e058382004-09-01 21:36:14 +0000374 ospf6_lstype_name (lsa->header->type),
hasso508e53e2004-05-18 18:57:06 +0000375 id, adv_router, ospf6_lsa_age_current (lsa),
paul718e3742002-12-13 20:15:29 +0000376 (u_long) ntohl (lsa->header->seqnum),
377 ntohs (lsa->header->checksum), ntohs (lsa->header->length),
hasso049207c2004-08-04 20:02:13 +0000378 duration, VNL);
paul718e3742002-12-13 20:15:29 +0000379}
380
381void
382ospf6_lsa_show_dump (struct vty *vty, struct ospf6_lsa *lsa)
383{
384 u_char *start, *end, *current;
385 char byte[4];
386
hasso03d52f82004-09-29 00:26:19 +0000387 start = (u_char *) lsa->header;
388 end = (u_char *) lsa->header + ntohs (lsa->header->length);
paul718e3742002-12-13 20:15:29 +0000389
hasso049207c2004-08-04 20:02:13 +0000390 vty_out (vty, "%s", VNL);
391 vty_out (vty, "%s:%s", lsa->name, VNL);
paul718e3742002-12-13 20:15:29 +0000392
393 for (current = start; current < end; current ++)
394 {
395 if ((current - start) % 16 == 0)
hasso049207c2004-08-04 20:02:13 +0000396 vty_out (vty, "%s ", VNL);
paul718e3742002-12-13 20:15:29 +0000397 else if ((current - start) % 4 == 0)
398 vty_out (vty, " ");
399
400 snprintf (byte, sizeof (byte), "%02x", *current);
401 vty_out (vty, "%s", byte);
402 }
403
hasso049207c2004-08-04 20:02:13 +0000404 vty_out (vty, "%s%s", VNL, VNL);
hasso6452df02004-08-15 05:52:07 +0000405 return;
paul718e3742002-12-13 20:15:29 +0000406}
407
hasso508e53e2004-05-18 18:57:06 +0000408void
409ospf6_lsa_show_internal (struct vty *vty, struct ospf6_lsa *lsa)
410{
411 char adv_router[64], id[64];
412
413 assert (lsa && lsa->header);
414
415 inet_ntop (AF_INET, &lsa->header->id, id, sizeof (id));
416 inet_ntop (AF_INET, &lsa->header->adv_router,
417 adv_router, sizeof (adv_router));
418
hasso049207c2004-08-04 20:02:13 +0000419 vty_out (vty, "%s", VNL);
hasso508e53e2004-05-18 18:57:06 +0000420 vty_out (vty, "Age: %4hu Type: %s%s", ospf6_lsa_age_current (lsa),
hasso1e058382004-09-01 21:36:14 +0000421 ospf6_lstype_name (lsa->header->type), VNL);
hasso049207c2004-08-04 20:02:13 +0000422 vty_out (vty, "Link State ID: %s%s", id, VNL);
423 vty_out (vty, "Advertising Router: %s%s", adv_router, VNL);
hasso508e53e2004-05-18 18:57:06 +0000424 vty_out (vty, "LS Sequence Number: %#010lx%s",
hasso049207c2004-08-04 20:02:13 +0000425 (u_long) ntohl (lsa->header->seqnum), VNL);
hasso508e53e2004-05-18 18:57:06 +0000426 vty_out (vty, "CheckSum: %#06hx Length: %hu%s",
427 ntohs (lsa->header->checksum),
hasso049207c2004-08-04 20:02:13 +0000428 ntohs (lsa->header->length), VNL);
hasso508e53e2004-05-18 18:57:06 +0000429 vty_out (vty, " Prev: %p This: %p Next: %p%s",
hasso049207c2004-08-04 20:02:13 +0000430 lsa->prev, lsa, lsa->next, VNL);
431 vty_out (vty, "%s", VNL);
hasso6452df02004-08-15 05:52:07 +0000432 return;
433}
434
435void
436ospf6_lsa_show (struct vty *vty, struct ospf6_lsa *lsa)
437{
438 char adv_router[64], id[64];
hasso1e058382004-09-01 21:36:14 +0000439 struct ospf6_lsa_handler *handler;
hasso6452df02004-08-15 05:52:07 +0000440
441 assert (lsa && lsa->header);
442
443 inet_ntop (AF_INET, &lsa->header->id, id, sizeof (id));
444 inet_ntop (AF_INET, &lsa->header->adv_router,
445 adv_router, sizeof (adv_router));
446
447 vty_out (vty, "Age: %4hu Type: %s%s", ospf6_lsa_age_current (lsa),
hasso1e058382004-09-01 21:36:14 +0000448 ospf6_lstype_name (lsa->header->type), VNL);
hasso6452df02004-08-15 05:52:07 +0000449 vty_out (vty, "Link State ID: %s%s", id, VNL);
450 vty_out (vty, "Advertising Router: %s%s", adv_router, VNL);
451 vty_out (vty, "LS Sequence Number: %#010lx%s",
452 (u_long) ntohl (lsa->header->seqnum), VNL);
453 vty_out (vty, "CheckSum: %#06hx Length: %hu%s",
454 ntohs (lsa->header->checksum),
455 ntohs (lsa->header->length), VNL);
456
hasso1e058382004-09-01 21:36:14 +0000457 handler = ospf6_get_lsa_handler (lsa->header->type);
458 if (handler->show == NULL)
459 handler = &unknown_handler;
460 (*handler->show) (vty, lsa);
hasso6452df02004-08-15 05:52:07 +0000461
462 vty_out (vty, "%s", VNL);
hasso508e53e2004-05-18 18:57:06 +0000463}
464
paul718e3742002-12-13 20:15:29 +0000465/* OSPFv3 LSA creation/deletion function */
paul718e3742002-12-13 20:15:29 +0000466struct ospf6_lsa *
hasso508e53e2004-05-18 18:57:06 +0000467ospf6_lsa_create (struct ospf6_lsa_header *header)
paul718e3742002-12-13 20:15:29 +0000468{
469 struct ospf6_lsa *lsa = NULL;
hasso508e53e2004-05-18 18:57:06 +0000470 struct ospf6_lsa_header *new_header = NULL;
paul718e3742002-12-13 20:15:29 +0000471 u_int16_t lsa_size = 0;
paul718e3742002-12-13 20:15:29 +0000472
hasso508e53e2004-05-18 18:57:06 +0000473 /* size of the entire LSA */
474 lsa_size = ntohs (header->length); /* XXX vulnerable */
paul718e3742002-12-13 20:15:29 +0000475
476 /* allocate memory for this LSA */
hasso508e53e2004-05-18 18:57:06 +0000477 new_header = (struct ospf6_lsa_header *)
paul718e3742002-12-13 20:15:29 +0000478 XMALLOC (MTYPE_OSPF6_LSA, lsa_size);
paul718e3742002-12-13 20:15:29 +0000479
hasso508e53e2004-05-18 18:57:06 +0000480 /* copy LSA from original header */
481 memcpy (new_header, header, lsa_size);
paul718e3742002-12-13 20:15:29 +0000482
483 /* LSA information structure */
484 /* allocate memory */
485 lsa = (struct ospf6_lsa *)
Stephen Hemminger393deb92008-08-18 14:13:29 -0700486 XCALLOC (MTYPE_OSPF6_LSA, sizeof (struct ospf6_lsa));
paul718e3742002-12-13 20:15:29 +0000487
hasso508e53e2004-05-18 18:57:06 +0000488 lsa->header = (struct ospf6_lsa_header *) new_header;
paul718e3742002-12-13 20:15:29 +0000489
490 /* dump string */
hasso508e53e2004-05-18 18:57:06 +0000491 ospf6_lsa_printbuf (lsa, lsa->name, sizeof (lsa->name));
paul718e3742002-12-13 20:15:29 +0000492
hasso3b687352004-08-19 06:56:53 +0000493 /* calculate birth of this lsa */
paul718e3742002-12-13 20:15:29 +0000494 ospf6_lsa_age_set (lsa);
495
paul718e3742002-12-13 20:15:29 +0000496 return lsa;
497}
498
499struct ospf6_lsa *
hasso508e53e2004-05-18 18:57:06 +0000500ospf6_lsa_create_headeronly (struct ospf6_lsa_header *header)
paul718e3742002-12-13 20:15:29 +0000501{
502 struct ospf6_lsa *lsa = NULL;
hasso508e53e2004-05-18 18:57:06 +0000503 struct ospf6_lsa_header *new_header = NULL;
paul718e3742002-12-13 20:15:29 +0000504
505 /* allocate memory for this LSA */
hasso508e53e2004-05-18 18:57:06 +0000506 new_header = (struct ospf6_lsa_header *)
507 XMALLOC (MTYPE_OSPF6_LSA, sizeof (struct ospf6_lsa_header));
paul718e3742002-12-13 20:15:29 +0000508
hasso508e53e2004-05-18 18:57:06 +0000509 /* copy LSA from original header */
510 memcpy (new_header, header, sizeof (struct ospf6_lsa_header));
paul718e3742002-12-13 20:15:29 +0000511
512 /* LSA information structure */
513 /* allocate memory */
514 lsa = (struct ospf6_lsa *)
Stephen Hemminger393deb92008-08-18 14:13:29 -0700515 XCALLOC (MTYPE_OSPF6_LSA, sizeof (struct ospf6_lsa));
paul718e3742002-12-13 20:15:29 +0000516
hasso508e53e2004-05-18 18:57:06 +0000517 lsa->header = (struct ospf6_lsa_header *) new_header;
hasso6452df02004-08-15 05:52:07 +0000518 SET_FLAG (lsa->flag, OSPF6_LSA_HEADERONLY);
paul718e3742002-12-13 20:15:29 +0000519
520 /* dump string */
hasso508e53e2004-05-18 18:57:06 +0000521 ospf6_lsa_printbuf (lsa, lsa->name, sizeof (lsa->name));
paul718e3742002-12-13 20:15:29 +0000522
hasso3b687352004-08-19 06:56:53 +0000523 /* calculate birth of this lsa */
paul718e3742002-12-13 20:15:29 +0000524 ospf6_lsa_age_set (lsa);
525
paul718e3742002-12-13 20:15:29 +0000526 return lsa;
527}
528
529void
530ospf6_lsa_delete (struct ospf6_lsa *lsa)
531{
hasso508e53e2004-05-18 18:57:06 +0000532 assert (lsa->lock == 0);
paul718e3742002-12-13 20:15:29 +0000533
534 /* cancel threads */
hasso508e53e2004-05-18 18:57:06 +0000535 THREAD_OFF (lsa->expire);
536 THREAD_OFF (lsa->refresh);
paul718e3742002-12-13 20:15:29 +0000537
paul718e3742002-12-13 20:15:29 +0000538 /* do free */
hasso508e53e2004-05-18 18:57:06 +0000539 XFREE (MTYPE_OSPF6_LSA, lsa->header);
540 XFREE (MTYPE_OSPF6_LSA, lsa);
paul718e3742002-12-13 20:15:29 +0000541}
542
hasso508e53e2004-05-18 18:57:06 +0000543struct ospf6_lsa *
544ospf6_lsa_copy (struct ospf6_lsa *lsa)
545{
546 struct ospf6_lsa *copy = NULL;
547
hasso508e53e2004-05-18 18:57:06 +0000548 ospf6_lsa_age_current (lsa);
hasso6452df02004-08-15 05:52:07 +0000549 if (CHECK_FLAG (lsa->flag, OSPF6_LSA_HEADERONLY))
hasso508e53e2004-05-18 18:57:06 +0000550 copy = ospf6_lsa_create_headeronly (lsa->header);
551 else
552 copy = ospf6_lsa_create (lsa->header);
553 assert (copy->lock == 0);
554
hasso3b687352004-08-19 06:56:53 +0000555 copy->birth = lsa->birth;
hasso508e53e2004-05-18 18:57:06 +0000556 copy->originated = lsa->originated;
hassoccb59b12004-08-25 09:10:37 +0000557 copy->received = lsa->received;
558 copy->installed = lsa->installed;
hasso6452df02004-08-15 05:52:07 +0000559 copy->lsdb = lsa->lsdb;
hasso508e53e2004-05-18 18:57:06 +0000560
hasso508e53e2004-05-18 18:57:06 +0000561 return copy;
562}
563
564/* increment reference counter of struct ospf6_lsa */
paul718e3742002-12-13 20:15:29 +0000565void
566ospf6_lsa_lock (struct ospf6_lsa *lsa)
567{
568 lsa->lock++;
569 return;
570}
571
hasso508e53e2004-05-18 18:57:06 +0000572/* decrement reference counter of struct ospf6_lsa */
paul718e3742002-12-13 20:15:29 +0000573void
574ospf6_lsa_unlock (struct ospf6_lsa *lsa)
575{
576 /* decrement reference counter */
hasso508e53e2004-05-18 18:57:06 +0000577 assert (lsa->lock > 0);
578 lsa->lock--;
paul718e3742002-12-13 20:15:29 +0000579
hasso508e53e2004-05-18 18:57:06 +0000580 if (lsa->lock != 0)
581 return;
582
hasso508e53e2004-05-18 18:57:06 +0000583 ospf6_lsa_delete (lsa);
paul718e3742002-12-13 20:15:29 +0000584}
585
paul718e3742002-12-13 20:15:29 +0000586
hasso508e53e2004-05-18 18:57:06 +0000587/* ospf6 lsa expiry */
paul718e3742002-12-13 20:15:29 +0000588int
589ospf6_lsa_expire (struct thread *thread)
590{
591 struct ospf6_lsa *lsa;
paul718e3742002-12-13 20:15:29 +0000592
593 lsa = (struct ospf6_lsa *) THREAD_ARG (thread);
paul718e3742002-12-13 20:15:29 +0000594
hasso508e53e2004-05-18 18:57:06 +0000595 assert (lsa && lsa->header);
596 assert (OSPF6_LSA_IS_MAXAGE (lsa));
597 assert (! lsa->refresh);
paul718e3742002-12-13 20:15:29 +0000598
599 lsa->expire = (struct thread *) NULL;
600
hasso1e058382004-09-01 21:36:14 +0000601 if (IS_OSPF6_DEBUG_LSA_TYPE (lsa->header->type))
paul718e3742002-12-13 20:15:29 +0000602 {
hassoc6487d62004-12-24 06:00:11 +0000603 zlog_debug ("LSA Expire:");
hasso508e53e2004-05-18 18:57:06 +0000604 ospf6_lsa_header_print (lsa);
paul718e3742002-12-13 20:15:29 +0000605 }
606
hasso6452df02004-08-15 05:52:07 +0000607 if (CHECK_FLAG (lsa->flag, OSPF6_LSA_HEADERONLY))
hasso508e53e2004-05-18 18:57:06 +0000608 return 0; /* dbexchange will do something ... */
609
610 /* reflood lsa */
hasso6452df02004-08-15 05:52:07 +0000611 ospf6_flood (NULL, lsa);
hasso508e53e2004-05-18 18:57:06 +0000612
613 /* reinstall lsa */
hasso3b687352004-08-19 06:56:53 +0000614 ospf6_install_lsa (lsa);
hasso508e53e2004-05-18 18:57:06 +0000615
616 /* schedule maxage remover */
617 ospf6_maxage_remove (ospf6);
618
paul718e3742002-12-13 20:15:29 +0000619 return 0;
620}
621
622int
623ospf6_lsa_refresh (struct thread *thread)
624{
hasso6452df02004-08-15 05:52:07 +0000625 struct ospf6_lsa *old, *self, *new;
626 struct ospf6_lsdb *lsdb_self;
paul718e3742002-12-13 20:15:29 +0000627
628 assert (thread);
hasso6452df02004-08-15 05:52:07 +0000629 old = (struct ospf6_lsa *) THREAD_ARG (thread);
630 assert (old && old->header);
paul718e3742002-12-13 20:15:29 +0000631
hasso6452df02004-08-15 05:52:07 +0000632 old->refresh = (struct thread *) NULL;
paul718e3742002-12-13 20:15:29 +0000633
hasso6452df02004-08-15 05:52:07 +0000634 lsdb_self = ospf6_get_scoped_lsdb_self (old);
635 self = ospf6_lsdb_lookup (old->header->type, old->header->id,
636 old->header->adv_router, lsdb_self);
637 if (self == NULL)
638 {
hasso1e058382004-09-01 21:36:14 +0000639 if (IS_OSPF6_DEBUG_LSA_TYPE (old->header->type))
hassoc6487d62004-12-24 06:00:11 +0000640 zlog_debug ("Refresh: could not find self LSA, flush %s", old->name);
hasso6452df02004-08-15 05:52:07 +0000641 ospf6_lsa_premature_aging (old);
642 return 0;
643 }
644
645 /* Reset age, increment LS sequence number. */
646 self->header->age = htons (0);
647 self->header->seqnum =
648 ospf6_new_ls_seqnum (self->header->type, self->header->id,
649 self->header->adv_router, old->lsdb);
650 ospf6_lsa_checksum (self->header);
651
652 new = ospf6_lsa_create (self->header);
653 new->lsdb = old->lsdb;
654 new->refresh = thread_add_timer (master, ospf6_lsa_refresh, new,
655 LS_REFRESH_TIME);
656
657 /* store it in the LSDB for self-originated LSAs */
658 ospf6_lsdb_add (ospf6_lsa_copy (new), lsdb_self);
paul718e3742002-12-13 20:15:29 +0000659
hasso1e058382004-09-01 21:36:14 +0000660 if (IS_OSPF6_DEBUG_LSA_TYPE (new->header->type))
paul718e3742002-12-13 20:15:29 +0000661 {
hassoc6487d62004-12-24 06:00:11 +0000662 zlog_debug ("LSA Refresh:");
hasso6452df02004-08-15 05:52:07 +0000663 ospf6_lsa_header_print (new);
paul718e3742002-12-13 20:15:29 +0000664 }
665
hasso6452df02004-08-15 05:52:07 +0000666 ospf6_flood_clear (old);
667 ospf6_flood (NULL, new);
668 ospf6_install_lsa (new);
669
hasso508e53e2004-05-18 18:57:06 +0000670 return 0;
paul718e3742002-12-13 20:15:29 +0000671}
672
673
674
675/* enhanced Fletcher checksum algorithm, RFC1008 7.2 */
676#define MODX 4102
677#define LSA_CHECKSUM_OFFSET 15
678
679unsigned short
680ospf6_lsa_checksum (struct ospf6_lsa_header *lsa_header)
681{
682 u_char *sp, *ep, *p, *q;
683 int c0 = 0, c1 = 0;
684 int x, y;
685 u_int16_t length;
686
687 lsa_header->checksum = 0;
688 length = ntohs (lsa_header->length) - 2;
hasso03d52f82004-09-29 00:26:19 +0000689 sp = (u_char *) &lsa_header->type;
paul718e3742002-12-13 20:15:29 +0000690
691 for (ep = sp + length; sp < ep; sp = q)
692 {
693 q = sp + MODX;
694 if (q > ep)
695 q = ep;
696 for (p = sp; p < q; p++)
697 {
698 c0 += *p;
699 c1 += c0;
700 }
701 c0 %= 255;
702 c1 %= 255;
703 }
704
705 /* r = (c1 << 8) + c0; */
706 x = ((length - LSA_CHECKSUM_OFFSET) * c0 - c1) % 255;
707 if (x <= 0)
708 x += 255;
709 y = 510 - c0 - x;
710 if (y > 255)
711 y -= 255;
712
713 lsa_header->checksum = htons ((x << 8) + y);
714
715 return (lsa_header->checksum);
716}
717
hasso6452df02004-08-15 05:52:07 +0000718void
Paul Jakma6ac29a52008-08-15 13:45:30 +0100719ospf6_lsa_init (void)
paul718e3742002-12-13 20:15:29 +0000720{
hasso1e058382004-09-01 21:36:14 +0000721 ospf6_lsa_handler_vector = vector_init (0);
hasso6452df02004-08-15 05:52:07 +0000722 ospf6_install_lsa_handler (&unknown_handler);
paul718e3742002-12-13 20:15:29 +0000723}
724
Tom Goffae2254a2010-11-10 13:01:41 -0800725void
726ospf6_lsa_terminate (void)
727{
728 vector_free (ospf6_lsa_handler_vector);
729}
hasso508e53e2004-05-18 18:57:06 +0000730
Paul Jakma6ac29a52008-08-15 13:45:30 +0100731static char *
hasso1e058382004-09-01 21:36:14 +0000732ospf6_lsa_handler_name (struct ospf6_lsa_handler *h)
hasso508e53e2004-05-18 18:57:06 +0000733{
hasso1e058382004-09-01 21:36:14 +0000734 static char buf[64];
paul0c083ee2004-10-10 12:54:58 +0000735 unsigned int i;
736 unsigned int size = strlen (h->name);
hasso508e53e2004-05-18 18:57:06 +0000737
Andrew J. Schorrc32d28b2007-02-27 15:24:36 +0000738 if (!strcmp(h->name, "Unknown") &&
hasso1e058382004-09-01 21:36:14 +0000739 h->type != OSPF6_LSTYPE_UNKNOWN)
hasso508e53e2004-05-18 18:57:06 +0000740 {
hasso1e058382004-09-01 21:36:14 +0000741 snprintf (buf, sizeof (buf), "%#04hx", h->type);
742 return buf;
hasso508e53e2004-05-18 18:57:06 +0000743 }
744
hasso1e058382004-09-01 21:36:14 +0000745 for (i = 0; i < MIN (size, sizeof (buf)); i++)
hasso508e53e2004-05-18 18:57:06 +0000746 {
hasso1e058382004-09-01 21:36:14 +0000747 if (! islower (h->name[i]))
748 buf[i] = tolower (h->name[i]);
hasso508e53e2004-05-18 18:57:06 +0000749 else
hasso1e058382004-09-01 21:36:14 +0000750 buf[i] = h->name[i];
751 }
752 buf[size] = '\0';
753 return buf;
754}
hasso508e53e2004-05-18 18:57:06 +0000755
hasso1e058382004-09-01 21:36:14 +0000756DEFUN (debug_ospf6_lsa_type,
757 debug_ospf6_lsa_hex_cmd,
758 "debug ospf6 lsa XXXX/0xXXXX",
759 DEBUG_STR
760 OSPF6_STR
761 "Debug Link State Advertisements (LSAs)\n"
762 "Specify LS type as Hexadecimal\n"
763 )
764{
paul0c083ee2004-10-10 12:54:58 +0000765 unsigned int i;
hasso1e058382004-09-01 21:36:14 +0000766 struct ospf6_lsa_handler *handler = NULL;
767 unsigned long val;
768 char *endptr = NULL;
769 u_int16_t type = 0;
770
771 assert (argc);
772
773 if ((strlen (argv[0]) == 6 && ! strncmp (argv[0], "0x", 2)) ||
774 (strlen (argv[0]) == 4))
775 {
776 val = strtoul (argv[0], &endptr, 16);
777 if (*endptr == '\0')
778 type = val;
hasso508e53e2004-05-18 18:57:06 +0000779 }
780
paul55468c82005-03-14 20:19:01 +0000781 for (i = 0; i < vector_active (ospf6_lsa_handler_vector); i++)
hasso1e058382004-09-01 21:36:14 +0000782 {
783 handler = vector_slot (ospf6_lsa_handler_vector, i);
784 if (handler == NULL)
785 continue;
786 if (type && handler->type == type)
787 break;
788 if (! strcasecmp (argv[0], handler->name))
789 break;
790 handler = NULL;
791 }
792
793 if (type && handler == NULL)
794 {
795 handler = (struct ospf6_lsa_handler *)
796 malloc (sizeof (struct ospf6_lsa_handler));
797 memset (handler, 0, sizeof (struct ospf6_lsa_handler));
798 handler->type = type;
799 handler->name = "Unknown";
800 handler->show = ospf6_unknown_lsa_show;
801 vector_set_index (ospf6_lsa_handler_vector,
802 handler->type & OSPF6_LSTYPE_FCODE_MASK, handler);
803 }
804
805 if (handler == NULL)
806 handler = &unknown_handler;
807
808 if (argc >= 2)
809 {
810 if (! strcmp (argv[1], "originate"))
811 SET_FLAG (handler->debug, OSPF6_LSA_DEBUG_ORIGINATE);
812 if (! strcmp (argv[1], "examin"))
813 SET_FLAG (handler->debug, OSPF6_LSA_DEBUG_EXAMIN);
814 if (! strcmp (argv[1], "flooding"))
815 SET_FLAG (handler->debug, OSPF6_LSA_DEBUG_FLOOD);
816 }
817 else
818 SET_FLAG (handler->debug, OSPF6_LSA_DEBUG);
819
820 return CMD_SUCCESS;
hasso508e53e2004-05-18 18:57:06 +0000821}
822
hasso1e058382004-09-01 21:36:14 +0000823DEFUN (no_debug_ospf6_lsa_type,
824 no_debug_ospf6_lsa_hex_cmd,
825 "no debug ospf6 lsa XXXX/0xXXXX",
826 NO_STR
827 DEBUG_STR
828 OSPF6_STR
829 "Debug Link State Advertisements (LSAs)\n"
830 "Specify LS type as Hexadecimal\n"
831 )
832{
paul0c083ee2004-10-10 12:54:58 +0000833 u_int i;
hasso1e058382004-09-01 21:36:14 +0000834 struct ospf6_lsa_handler *handler = NULL;
835 unsigned long val;
836 char *endptr = NULL;
837 u_int16_t type = 0;
838
839 assert (argc);
840
841 if ((strlen (argv[0]) == 6 && ! strncmp (argv[0], "0x", 2)) ||
842 (strlen (argv[0]) == 4))
843 {
844 val = strtoul (argv[0], &endptr, 16);
845 if (*endptr == '\0')
846 type = val;
847 }
848
paul55468c82005-03-14 20:19:01 +0000849 for (i = 0; i < vector_active (ospf6_lsa_handler_vector); i++)
hasso1e058382004-09-01 21:36:14 +0000850 {
851 handler = vector_slot (ospf6_lsa_handler_vector, i);
852 if (handler == NULL)
853 continue;
854 if (type && handler->type == type)
855 break;
856 if (! strcasecmp (argv[0], handler->name))
857 break;
858 }
859
860 if (handler == NULL)
861 return CMD_SUCCESS;
862
863 if (argc >= 2)
864 {
865 if (! strcmp (argv[1], "originate"))
866 UNSET_FLAG (handler->debug, OSPF6_LSA_DEBUG_ORIGINATE);
867 if (! strcmp (argv[1], "examin"))
868 UNSET_FLAG (handler->debug, OSPF6_LSA_DEBUG_EXAMIN);
869 if (! strcmp (argv[1], "flooding"))
870 UNSET_FLAG (handler->debug, OSPF6_LSA_DEBUG_FLOOD);
871 }
872 else
873 UNSET_FLAG (handler->debug, OSPF6_LSA_DEBUG);
874
875 if (handler->debug == 0 &&
Andrew J. Schorre733f942007-06-07 13:11:58 +0000876 !strcmp(handler->name, "Unknown") && type != OSPF6_LSTYPE_UNKNOWN)
hasso1e058382004-09-01 21:36:14 +0000877 {
878 free (handler);
879 vector_slot (ospf6_lsa_handler_vector, i) = NULL;
880 }
881
882 return CMD_SUCCESS;
883}
884
885struct cmd_element debug_ospf6_lsa_type_cmd;
886struct cmd_element debug_ospf6_lsa_type_detail_cmd;
887struct cmd_element no_debug_ospf6_lsa_type_cmd;
888struct cmd_element no_debug_ospf6_lsa_type_detail_cmd;
889
hasso508e53e2004-05-18 18:57:06 +0000890void
Paul Jakma6ac29a52008-08-15 13:45:30 +0100891install_element_ospf6_debug_lsa (void)
hasso508e53e2004-05-18 18:57:06 +0000892{
paul0c083ee2004-10-10 12:54:58 +0000893 u_int i;
hasso1e058382004-09-01 21:36:14 +0000894 struct ospf6_lsa_handler *handler;
895#define STRSIZE 256
896#define DOCSIZE 1024
897 static char strbuf[STRSIZE];
898 static char docbuf[DOCSIZE];
899 static char detail_strbuf[STRSIZE];
900 static char detail_docbuf[DOCSIZE];
901 char *str, *no_str;
902 char *doc, *no_doc;
903
904 strbuf[0] = '\0';
905 no_str = &strbuf[strlen (strbuf)];
906 strncat (strbuf, "no ", STRSIZE - strlen (strbuf));
907 str = &strbuf[strlen (strbuf)];
908
909 strncat (strbuf, "debug ospf6 lsa (", STRSIZE - strlen (strbuf));
paul55468c82005-03-14 20:19:01 +0000910 for (i = 0; i < vector_active (ospf6_lsa_handler_vector); i++)
hasso1e058382004-09-01 21:36:14 +0000911 {
912 handler = vector_slot (ospf6_lsa_handler_vector, i);
913 if (handler == NULL)
914 continue;
915 strncat (strbuf, ospf6_lsa_handler_name (handler),
916 STRSIZE - strlen (strbuf));
917 strncat (strbuf, "|", STRSIZE - strlen (strbuf));
918 }
919 strbuf[strlen (strbuf) - 1] = ')';
920 strbuf[strlen (strbuf)] = '\0';
921
922 docbuf[0] = '\0';
923 no_doc = &docbuf[strlen (docbuf)];
924 strncat (docbuf, NO_STR, DOCSIZE - strlen (docbuf));
925 doc = &docbuf[strlen (docbuf)];
926
927 strncat (docbuf, DEBUG_STR, DOCSIZE - strlen (docbuf));
928 strncat (docbuf, OSPF6_STR, DOCSIZE - strlen (docbuf));
929 strncat (docbuf, "Debug Link State Advertisements (LSAs)\n",
930 DOCSIZE - strlen (docbuf));
931
paul55468c82005-03-14 20:19:01 +0000932 for (i = 0; i < vector_active (ospf6_lsa_handler_vector); i++)
hasso1e058382004-09-01 21:36:14 +0000933 {
934 handler = vector_slot (ospf6_lsa_handler_vector, i);
935 if (handler == NULL)
936 continue;
937 strncat (docbuf, "Debug ", DOCSIZE - strlen (docbuf));
938 strncat (docbuf, handler->name, DOCSIZE - strlen (docbuf));
939 strncat (docbuf, "-LSA\n", DOCSIZE - strlen (docbuf));
940 }
941 docbuf[strlen (docbuf)] = '\0';
942
943 debug_ospf6_lsa_type_cmd.string = str;
944 debug_ospf6_lsa_type_cmd.func = debug_ospf6_lsa_type;
945 debug_ospf6_lsa_type_cmd.doc = doc;
946
947 no_debug_ospf6_lsa_type_cmd.string = no_str;
948 no_debug_ospf6_lsa_type_cmd.func = no_debug_ospf6_lsa_type;
949 no_debug_ospf6_lsa_type_cmd.doc = no_doc;
950
951 strncpy (detail_strbuf, strbuf, STRSIZE);
952 strncat (detail_strbuf, " (originate|examin|flooding)",
953 STRSIZE - strlen (detail_strbuf));
954 detail_strbuf[strlen (detail_strbuf)] = '\0';
955 no_str = &detail_strbuf[0];
956 str = &detail_strbuf[strlen ("no ")];
957
958 strncpy (detail_docbuf, docbuf, DOCSIZE);
959 strncat (detail_docbuf, "Debug Originating LSA\n",
960 DOCSIZE - strlen (detail_docbuf));
961 strncat (detail_docbuf, "Debug Examining LSA\n",
962 DOCSIZE - strlen (detail_docbuf));
963 strncat (detail_docbuf, "Debug Flooding LSA\n",
964 DOCSIZE - strlen (detail_docbuf));
965 detail_docbuf[strlen (detail_docbuf)] = '\0';
966 no_doc = &detail_docbuf[0];
967 doc = &detail_docbuf[strlen (NO_STR)];
968
969 debug_ospf6_lsa_type_detail_cmd.string = str;
970 debug_ospf6_lsa_type_detail_cmd.func = debug_ospf6_lsa_type;
971 debug_ospf6_lsa_type_detail_cmd.doc = doc;
972
973 no_debug_ospf6_lsa_type_detail_cmd.string = no_str;
974 no_debug_ospf6_lsa_type_detail_cmd.func = no_debug_ospf6_lsa_type;
975 no_debug_ospf6_lsa_type_detail_cmd.doc = no_doc;
976
977 install_element (ENABLE_NODE, &debug_ospf6_lsa_hex_cmd);
978 install_element (ENABLE_NODE, &debug_ospf6_lsa_type_cmd);
979 install_element (ENABLE_NODE, &debug_ospf6_lsa_type_detail_cmd);
980 install_element (ENABLE_NODE, &no_debug_ospf6_lsa_hex_cmd);
981 install_element (ENABLE_NODE, &no_debug_ospf6_lsa_type_cmd);
982 install_element (ENABLE_NODE, &no_debug_ospf6_lsa_type_detail_cmd);
983 install_element (CONFIG_NODE, &debug_ospf6_lsa_hex_cmd);
984 install_element (CONFIG_NODE, &debug_ospf6_lsa_type_cmd);
985 install_element (CONFIG_NODE, &debug_ospf6_lsa_type_detail_cmd);
986 install_element (CONFIG_NODE, &no_debug_ospf6_lsa_hex_cmd);
987 install_element (CONFIG_NODE, &no_debug_ospf6_lsa_type_cmd);
988 install_element (CONFIG_NODE, &no_debug_ospf6_lsa_type_detail_cmd);
989}
990
991int
992config_write_ospf6_debug_lsa (struct vty *vty)
993{
paul0c083ee2004-10-10 12:54:58 +0000994 u_int i;
hasso1e058382004-09-01 21:36:14 +0000995 struct ospf6_lsa_handler *handler;
996
paul55468c82005-03-14 20:19:01 +0000997 for (i = 0; i < vector_active (ospf6_lsa_handler_vector); i++)
hasso1e058382004-09-01 21:36:14 +0000998 {
999 handler = vector_slot (ospf6_lsa_handler_vector, i);
1000 if (handler == NULL)
1001 continue;
1002 if (CHECK_FLAG (handler->debug, OSPF6_LSA_DEBUG))
1003 vty_out (vty, "debug ospf6 lsa %s%s",
1004 ospf6_lsa_handler_name (handler), VNL);
1005 if (CHECK_FLAG (handler->debug, OSPF6_LSA_DEBUG_ORIGINATE))
1006 vty_out (vty, "debug ospf6 lsa %s originate%s",
1007 ospf6_lsa_handler_name (handler), VNL);
1008 if (CHECK_FLAG (handler->debug, OSPF6_LSA_DEBUG_EXAMIN))
1009 vty_out (vty, "debug ospf6 lsa %s examin%s",
1010 ospf6_lsa_handler_name (handler), VNL);
1011 if (CHECK_FLAG (handler->debug, OSPF6_LSA_DEBUG_FLOOD))
1012 vty_out (vty, "debug ospf6 lsa %s flooding%s",
1013 ospf6_lsa_handler_name (handler), VNL);
1014 }
1015
1016 return 0;
hasso508e53e2004-05-18 18:57:06 +00001017}
1018
1019