blob: 34040b84b4341520871a678f6a3e8b7d3ac924e6 [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;
paul718e3742002-12-13 20:15:29 +0000166
hasso508e53e2004-05-18 18:57:06 +0000167 length = OSPF6_LSA_SIZE (lsa1->header) - sizeof (struct ospf6_lsa_header);
168 assert (length > 0);
paul718e3742002-12-13 20:15:29 +0000169
hasso508e53e2004-05-18 18:57:06 +0000170 return memcmp (OSPF6_LSA_HEADER_END (lsa1->header),
171 OSPF6_LSA_HEADER_END (lsa2->header), length);
paul718e3742002-12-13 20:15:29 +0000172}
173
174/* ospf6 age functions */
hasso3b687352004-08-19 06:56:53 +0000175/* calculate birth */
paul718e3742002-12-13 20:15:29 +0000176static void
177ospf6_lsa_age_set (struct ospf6_lsa *lsa)
178{
179 struct timeval now;
180
181 assert (lsa && lsa->header);
182
Takashi Sogabe86f72dc2009-06-22 13:07:02 +0900183 if (quagga_gettime (QUAGGA_CLK_MONOTONIC, &now) < 0)
184 zlog_warn ("LSA: quagga_gettime failed, may fail LSA AGEs: %s",
ajs6099b3b2004-11-20 02:06:59 +0000185 safe_strerror (errno));
paul718e3742002-12-13 20:15:29 +0000186
187 lsa->birth.tv_sec = now.tv_sec - ntohs (lsa->header->age);
188 lsa->birth.tv_usec = now.tv_usec;
hasso3b687352004-08-19 06:56:53 +0000189
paul718e3742002-12-13 20:15:29 +0000190 return;
191}
192
193/* this function calculates current age from its birth,
194 then update age field of LSA header. return value is current age */
195u_int16_t
196ospf6_lsa_age_current (struct ospf6_lsa *lsa)
197{
198 struct timeval now;
199 u_int32_t ulage;
200 u_int16_t age;
201
202 assert (lsa);
203 assert (lsa->header);
204
205 /* current time */
Takashi Sogabe86f72dc2009-06-22 13:07:02 +0900206 if (quagga_gettime (QUAGGA_CLK_MONOTONIC, &now) < 0)
207 zlog_warn ("LSA: quagga_gettime failed, may fail LSA AGEs: %s",
ajs6099b3b2004-11-20 02:06:59 +0000208 safe_strerror (errno));
paul718e3742002-12-13 20:15:29 +0000209
Tom Henderson9b4ef252009-07-16 17:20:37 +0100210 if (lsa->header->age >= htons (MAXAGE))
211 {
212 /* LSA may have been prematurely aged */
213 lsa->header->age = htons (MAXAGE);
214 return MAXAGE;
215 }
paul718e3742002-12-13 20:15:29 +0000216 /* calculate age */
217 ulage = now.tv_sec - lsa->birth.tv_sec;
218
219 /* if over MAXAGE, set to it */
hasso508e53e2004-05-18 18:57:06 +0000220 age = (ulage > MAXAGE ? MAXAGE : ulage);
paul718e3742002-12-13 20:15:29 +0000221
222 lsa->header->age = htons (age);
223 return age;
224}
225
226/* update age field of LSA header with adding InfTransDelay */
227void
228ospf6_lsa_age_update_to_send (struct ospf6_lsa *lsa, u_int32_t transdelay)
229{
230 unsigned short age;
231
232 age = ospf6_lsa_age_current (lsa) + transdelay;
233 if (age > MAXAGE)
234 age = MAXAGE;
235 lsa->header->age = htons (age);
paul718e3742002-12-13 20:15:29 +0000236}
237
238void
239ospf6_lsa_premature_aging (struct ospf6_lsa *lsa)
240{
241 /* log */
hasso1e058382004-09-01 21:36:14 +0000242 if (IS_OSPF6_DEBUG_LSA_TYPE (lsa->header->type))
hassoc6487d62004-12-24 06:00:11 +0000243 zlog_debug ("LSA: Premature aging: %s", lsa->name);
paul718e3742002-12-13 20:15:29 +0000244
hasso508e53e2004-05-18 18:57:06 +0000245 THREAD_OFF (lsa->expire);
246 THREAD_OFF (lsa->refresh);
paul718e3742002-12-13 20:15:29 +0000247
Tom Henderson9b4ef252009-07-16 17:20:37 +0100248 /*
249 * The below technique to age out LSA does not work when using relative time
250 *
paul718e3742002-12-13 20:15:29 +0000251 memset (&lsa->birth, 0, sizeof (struct timeval));
Tom Henderson9b4ef252009-07-16 17:20:37 +0100252 */
253 lsa->header->age = htons (MAXAGE);
paul718e3742002-12-13 20:15:29 +0000254 thread_execute (master, ospf6_lsa_expire, lsa, 0);
255}
256
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 */
259int
hasso508e53e2004-05-18 18:57:06 +0000260ospf6_lsa_compare (struct ospf6_lsa *a, struct ospf6_lsa *b)
paul718e3742002-12-13 20:15:29 +0000261{
262 signed long seqnuma, seqnumb;
263 u_int16_t cksuma, cksumb;
264 u_int16_t agea, ageb;
265
266 assert (a && a->header);
267 assert (b && b->header);
hasso508e53e2004-05-18 18:57:06 +0000268 assert (OSPF6_LSA_IS_SAME (a, b));
paul718e3742002-12-13 20:15:29 +0000269
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;
274
275 /* compare by sequence number */
hasso508e53e2004-05-18 18:57:06 +0000276 /* XXX, LS sequence number wrapping */
paul718e3742002-12-13 20:15:29 +0000277 if (seqnuma > seqnumb)
278 return -1;
279 else if (seqnuma < seqnumb)
280 return 1;
281
282 /* Checksum */
283 cksuma = ntohs (a->header->checksum);
284 cksumb = ntohs (b->header->checksum);
285 if (cksuma > cksumb)
286 return -1;
287 if (cksuma < cksumb)
288 return 0;
289
hasso508e53e2004-05-18 18:57:06 +0000290 /* Update Age */
paul718e3742002-12-13 20:15:29 +0000291 agea = ospf6_lsa_age_current (a);
292 ageb = ospf6_lsa_age_current (b);
293
hasso508e53e2004-05-18 18:57:06 +0000294 /* MaxAge check */
295 if (agea == MAXAGE && ageb != MAXAGE)
paul718e3742002-12-13 20:15:29 +0000296 return -1;
hasso508e53e2004-05-18 18:57:06 +0000297 else if (agea != MAXAGE && ageb == MAXAGE)
paul718e3742002-12-13 20:15:29 +0000298 return 1;
299
hasso508e53e2004-05-18 18:57:06 +0000300 /* Age check */
301 if (agea > ageb && agea - ageb >= MAX_AGE_DIFF)
paul718e3742002-12-13 20:15:29 +0000302 return 1;
hasso508e53e2004-05-18 18:57:06 +0000303 else if (agea < ageb && ageb - agea >= MAX_AGE_DIFF)
paul718e3742002-12-13 20:15:29 +0000304 return -1;
305
306 /* neither recent */
paul718e3742002-12-13 20:15:29 +0000307 return 0;
308}
309
hasso508e53e2004-05-18 18:57:06 +0000310char *
311ospf6_lsa_printbuf (struct ospf6_lsa *lsa, char *buf, int size)
paul718e3742002-12-13 20:15:29 +0000312{
hasso508e53e2004-05-18 18:57:06 +0000313 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]",
hasso1e058382004-09-01 21:36:14 +0000318 ospf6_lstype_name (lsa->header->type), id, adv_router);
hasso508e53e2004-05-18 18:57:06 +0000319 return buf;
paul718e3742002-12-13 20:15:29 +0000320}
321
hasso508e53e2004-05-18 18:57:06 +0000322void
323ospf6_lsa_header_print_raw (struct ospf6_lsa_header *header)
paul718e3742002-12-13 20:15:29 +0000324{
hasso508e53e2004-05-18 18:57:06 +0000325 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));
hassoc6487d62004-12-24 06:00:11 +0000329 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));
paul718e3742002-12-13 20:15:29 +0000334}
335
hasso508e53e2004-05-18 18:57:06 +0000336void
337ospf6_lsa_header_print (struct ospf6_lsa *lsa)
paul718e3742002-12-13 20:15:29 +0000338{
hasso508e53e2004-05-18 18:57:06 +0000339 ospf6_lsa_age_current (lsa);
340 ospf6_lsa_header_print_raw (lsa->header);
paul718e3742002-12-13 20:15:29 +0000341}
342
343void
paul718e3742002-12-13 20:15:29 +0000344ospf6_lsa_show_summary_header (struct vty *vty)
345{
346 vty_out (vty, "%-12s %-15s %-15s %4s %8s %4s %4s %-8s%s",
347 "Type", "LSId", "AdvRouter", "Age", "SeqNum",
hasso049207c2004-08-04 20:02:13 +0000348 "Cksm", "Len", "Duration", VNL);
paul718e3742002-12-13 20:15:29 +0000349}
350
351void
352ospf6_lsa_show_summary (struct vty *vty, struct ospf6_lsa *lsa)
353{
hasso508e53e2004-05-18 18:57:06 +0000354 char adv_router[16], id[16];
paul718e3742002-12-13 20:15:29 +0000355 struct timeval now, res;
356 char duration[16];
357
358 assert (lsa);
359 assert (lsa->header);
360
paul718e3742002-12-13 20:15:29 +0000361 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));
364
Takashi Sogabe86f72dc2009-06-22 13:07:02 +0900365 quagga_gettime (QUAGGA_CLK_MONOTONIC, &now);
hasso508e53e2004-05-18 18:57:06 +0000366 timersub (&now, &lsa->installed, &res);
367 timerstring (&res, duration, sizeof (duration));
paul718e3742002-12-13 20:15:29 +0000368
369 vty_out (vty, "%-12s %-15s %-15s %4hu %8lx %04hx %4hu %8s%s",
hasso1e058382004-09-01 21:36:14 +0000370 ospf6_lstype_name (lsa->header->type),
hasso508e53e2004-05-18 18:57:06 +0000371 id, adv_router, ospf6_lsa_age_current (lsa),
paul718e3742002-12-13 20:15:29 +0000372 (u_long) ntohl (lsa->header->seqnum),
373 ntohs (lsa->header->checksum), ntohs (lsa->header->length),
hasso049207c2004-08-04 20:02:13 +0000374 duration, VNL);
paul718e3742002-12-13 20:15:29 +0000375}
376
377void
378ospf6_lsa_show_dump (struct vty *vty, struct ospf6_lsa *lsa)
379{
380 u_char *start, *end, *current;
381 char byte[4];
382
hasso03d52f82004-09-29 00:26:19 +0000383 start = (u_char *) lsa->header;
384 end = (u_char *) lsa->header + ntohs (lsa->header->length);
paul718e3742002-12-13 20:15:29 +0000385
hasso049207c2004-08-04 20:02:13 +0000386 vty_out (vty, "%s", VNL);
387 vty_out (vty, "%s:%s", lsa->name, VNL);
paul718e3742002-12-13 20:15:29 +0000388
389 for (current = start; current < end; current ++)
390 {
391 if ((current - start) % 16 == 0)
hasso049207c2004-08-04 20:02:13 +0000392 vty_out (vty, "%s ", VNL);
paul718e3742002-12-13 20:15:29 +0000393 else if ((current - start) % 4 == 0)
394 vty_out (vty, " ");
395
396 snprintf (byte, sizeof (byte), "%02x", *current);
397 vty_out (vty, "%s", byte);
398 }
399
hasso049207c2004-08-04 20:02:13 +0000400 vty_out (vty, "%s%s", VNL, VNL);
hasso6452df02004-08-15 05:52:07 +0000401 return;
paul718e3742002-12-13 20:15:29 +0000402}
403
hasso508e53e2004-05-18 18:57:06 +0000404void
405ospf6_lsa_show_internal (struct vty *vty, struct ospf6_lsa *lsa)
406{
407 char adv_router[64], id[64];
408
409 assert (lsa && lsa->header);
410
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));
414
hasso049207c2004-08-04 20:02:13 +0000415 vty_out (vty, "%s", VNL);
hasso508e53e2004-05-18 18:57:06 +0000416 vty_out (vty, "Age: %4hu Type: %s%s", ospf6_lsa_age_current (lsa),
hasso1e058382004-09-01 21:36:14 +0000417 ospf6_lstype_name (lsa->header->type), VNL);
hasso049207c2004-08-04 20:02:13 +0000418 vty_out (vty, "Link State ID: %s%s", id, VNL);
419 vty_out (vty, "Advertising Router: %s%s", adv_router, VNL);
hasso508e53e2004-05-18 18:57:06 +0000420 vty_out (vty, "LS Sequence Number: %#010lx%s",
hasso049207c2004-08-04 20:02:13 +0000421 (u_long) ntohl (lsa->header->seqnum), VNL);
hasso508e53e2004-05-18 18:57:06 +0000422 vty_out (vty, "CheckSum: %#06hx Length: %hu%s",
423 ntohs (lsa->header->checksum),
hasso049207c2004-08-04 20:02:13 +0000424 ntohs (lsa->header->length), VNL);
hasso508e53e2004-05-18 18:57:06 +0000425 vty_out (vty, " Prev: %p This: %p Next: %p%s",
hasso049207c2004-08-04 20:02:13 +0000426 lsa->prev, lsa, lsa->next, VNL);
427 vty_out (vty, "%s", VNL);
hasso6452df02004-08-15 05:52:07 +0000428 return;
429}
430
431void
432ospf6_lsa_show (struct vty *vty, struct ospf6_lsa *lsa)
433{
434 char adv_router[64], id[64];
hasso1e058382004-09-01 21:36:14 +0000435 struct ospf6_lsa_handler *handler;
hasso6452df02004-08-15 05:52:07 +0000436
437 assert (lsa && lsa->header);
438
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));
442
443 vty_out (vty, "Age: %4hu Type: %s%s", ospf6_lsa_age_current (lsa),
hasso1e058382004-09-01 21:36:14 +0000444 ospf6_lstype_name (lsa->header->type), VNL);
hasso6452df02004-08-15 05:52:07 +0000445 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);
452
hasso1e058382004-09-01 21:36:14 +0000453 handler = ospf6_get_lsa_handler (lsa->header->type);
454 if (handler->show == NULL)
455 handler = &unknown_handler;
456 (*handler->show) (vty, lsa);
hasso6452df02004-08-15 05:52:07 +0000457
458 vty_out (vty, "%s", VNL);
hasso508e53e2004-05-18 18:57:06 +0000459}
460
paul718e3742002-12-13 20:15:29 +0000461/* OSPFv3 LSA creation/deletion function */
paul718e3742002-12-13 20:15:29 +0000462struct ospf6_lsa *
hasso508e53e2004-05-18 18:57:06 +0000463ospf6_lsa_create (struct ospf6_lsa_header *header)
paul718e3742002-12-13 20:15:29 +0000464{
465 struct ospf6_lsa *lsa = NULL;
hasso508e53e2004-05-18 18:57:06 +0000466 struct ospf6_lsa_header *new_header = NULL;
paul718e3742002-12-13 20:15:29 +0000467 u_int16_t lsa_size = 0;
paul718e3742002-12-13 20:15:29 +0000468
hasso508e53e2004-05-18 18:57:06 +0000469 /* size of the entire LSA */
470 lsa_size = ntohs (header->length); /* XXX vulnerable */
paul718e3742002-12-13 20:15:29 +0000471
472 /* allocate memory for this LSA */
hasso508e53e2004-05-18 18:57:06 +0000473 new_header = (struct ospf6_lsa_header *)
paul718e3742002-12-13 20:15:29 +0000474 XMALLOC (MTYPE_OSPF6_LSA, lsa_size);
paul718e3742002-12-13 20:15:29 +0000475
hasso508e53e2004-05-18 18:57:06 +0000476 /* copy LSA from original header */
477 memcpy (new_header, header, lsa_size);
paul718e3742002-12-13 20:15:29 +0000478
479 /* LSA information structure */
480 /* allocate memory */
481 lsa = (struct ospf6_lsa *)
Stephen Hemminger393deb92008-08-18 14:13:29 -0700482 XCALLOC (MTYPE_OSPF6_LSA, sizeof (struct ospf6_lsa));
paul718e3742002-12-13 20:15:29 +0000483
hasso508e53e2004-05-18 18:57:06 +0000484 lsa->header = (struct ospf6_lsa_header *) new_header;
paul718e3742002-12-13 20:15:29 +0000485
486 /* dump string */
hasso508e53e2004-05-18 18:57:06 +0000487 ospf6_lsa_printbuf (lsa, lsa->name, sizeof (lsa->name));
paul718e3742002-12-13 20:15:29 +0000488
hasso3b687352004-08-19 06:56:53 +0000489 /* calculate birth of this lsa */
paul718e3742002-12-13 20:15:29 +0000490 ospf6_lsa_age_set (lsa);
491
paul718e3742002-12-13 20:15:29 +0000492 return lsa;
493}
494
495struct ospf6_lsa *
hasso508e53e2004-05-18 18:57:06 +0000496ospf6_lsa_create_headeronly (struct ospf6_lsa_header *header)
paul718e3742002-12-13 20:15:29 +0000497{
498 struct ospf6_lsa *lsa = NULL;
hasso508e53e2004-05-18 18:57:06 +0000499 struct ospf6_lsa_header *new_header = NULL;
paul718e3742002-12-13 20:15:29 +0000500
501 /* allocate memory for this LSA */
hasso508e53e2004-05-18 18:57:06 +0000502 new_header = (struct ospf6_lsa_header *)
503 XMALLOC (MTYPE_OSPF6_LSA, sizeof (struct ospf6_lsa_header));
paul718e3742002-12-13 20:15:29 +0000504
hasso508e53e2004-05-18 18:57:06 +0000505 /* copy LSA from original header */
506 memcpy (new_header, header, sizeof (struct ospf6_lsa_header));
paul718e3742002-12-13 20:15:29 +0000507
508 /* LSA information structure */
509 /* allocate memory */
510 lsa = (struct ospf6_lsa *)
Stephen Hemminger393deb92008-08-18 14:13:29 -0700511 XCALLOC (MTYPE_OSPF6_LSA, sizeof (struct ospf6_lsa));
paul718e3742002-12-13 20:15:29 +0000512
hasso508e53e2004-05-18 18:57:06 +0000513 lsa->header = (struct ospf6_lsa_header *) new_header;
hasso6452df02004-08-15 05:52:07 +0000514 SET_FLAG (lsa->flag, OSPF6_LSA_HEADERONLY);
paul718e3742002-12-13 20:15:29 +0000515
516 /* dump string */
hasso508e53e2004-05-18 18:57:06 +0000517 ospf6_lsa_printbuf (lsa, lsa->name, sizeof (lsa->name));
paul718e3742002-12-13 20:15:29 +0000518
hasso3b687352004-08-19 06:56:53 +0000519 /* calculate birth of this lsa */
paul718e3742002-12-13 20:15:29 +0000520 ospf6_lsa_age_set (lsa);
521
paul718e3742002-12-13 20:15:29 +0000522 return lsa;
523}
524
525void
526ospf6_lsa_delete (struct ospf6_lsa *lsa)
527{
hasso508e53e2004-05-18 18:57:06 +0000528 assert (lsa->lock == 0);
paul718e3742002-12-13 20:15:29 +0000529
530 /* cancel threads */
hasso508e53e2004-05-18 18:57:06 +0000531 THREAD_OFF (lsa->expire);
532 THREAD_OFF (lsa->refresh);
paul718e3742002-12-13 20:15:29 +0000533
paul718e3742002-12-13 20:15:29 +0000534 /* do free */
hasso508e53e2004-05-18 18:57:06 +0000535 XFREE (MTYPE_OSPF6_LSA, lsa->header);
536 XFREE (MTYPE_OSPF6_LSA, lsa);
paul718e3742002-12-13 20:15:29 +0000537}
538
hasso508e53e2004-05-18 18:57:06 +0000539struct ospf6_lsa *
540ospf6_lsa_copy (struct ospf6_lsa *lsa)
541{
542 struct ospf6_lsa *copy = NULL;
543
hasso508e53e2004-05-18 18:57:06 +0000544 ospf6_lsa_age_current (lsa);
hasso6452df02004-08-15 05:52:07 +0000545 if (CHECK_FLAG (lsa->flag, OSPF6_LSA_HEADERONLY))
hasso508e53e2004-05-18 18:57:06 +0000546 copy = ospf6_lsa_create_headeronly (lsa->header);
547 else
548 copy = ospf6_lsa_create (lsa->header);
549 assert (copy->lock == 0);
550
hasso3b687352004-08-19 06:56:53 +0000551 copy->birth = lsa->birth;
hasso508e53e2004-05-18 18:57:06 +0000552 copy->originated = lsa->originated;
hassoccb59b12004-08-25 09:10:37 +0000553 copy->received = lsa->received;
554 copy->installed = lsa->installed;
hasso6452df02004-08-15 05:52:07 +0000555 copy->lsdb = lsa->lsdb;
hasso508e53e2004-05-18 18:57:06 +0000556
hasso508e53e2004-05-18 18:57:06 +0000557 return copy;
558}
559
560/* increment reference counter of struct ospf6_lsa */
paul718e3742002-12-13 20:15:29 +0000561void
562ospf6_lsa_lock (struct ospf6_lsa *lsa)
563{
564 lsa->lock++;
565 return;
566}
567
hasso508e53e2004-05-18 18:57:06 +0000568/* decrement reference counter of struct ospf6_lsa */
paul718e3742002-12-13 20:15:29 +0000569void
570ospf6_lsa_unlock (struct ospf6_lsa *lsa)
571{
572 /* decrement reference counter */
hasso508e53e2004-05-18 18:57:06 +0000573 assert (lsa->lock > 0);
574 lsa->lock--;
paul718e3742002-12-13 20:15:29 +0000575
hasso508e53e2004-05-18 18:57:06 +0000576 if (lsa->lock != 0)
577 return;
578
hasso508e53e2004-05-18 18:57:06 +0000579 ospf6_lsa_delete (lsa);
paul718e3742002-12-13 20:15:29 +0000580}
581
paul718e3742002-12-13 20:15:29 +0000582
hasso508e53e2004-05-18 18:57:06 +0000583/* ospf6 lsa expiry */
paul718e3742002-12-13 20:15:29 +0000584int
585ospf6_lsa_expire (struct thread *thread)
586{
587 struct ospf6_lsa *lsa;
paul718e3742002-12-13 20:15:29 +0000588
589 lsa = (struct ospf6_lsa *) THREAD_ARG (thread);
paul718e3742002-12-13 20:15:29 +0000590
hasso508e53e2004-05-18 18:57:06 +0000591 assert (lsa && lsa->header);
592 assert (OSPF6_LSA_IS_MAXAGE (lsa));
593 assert (! lsa->refresh);
paul718e3742002-12-13 20:15:29 +0000594
595 lsa->expire = (struct thread *) NULL;
596
hasso1e058382004-09-01 21:36:14 +0000597 if (IS_OSPF6_DEBUG_LSA_TYPE (lsa->header->type))
paul718e3742002-12-13 20:15:29 +0000598 {
hassoc6487d62004-12-24 06:00:11 +0000599 zlog_debug ("LSA Expire:");
hasso508e53e2004-05-18 18:57:06 +0000600 ospf6_lsa_header_print (lsa);
paul718e3742002-12-13 20:15:29 +0000601 }
602
hasso6452df02004-08-15 05:52:07 +0000603 if (CHECK_FLAG (lsa->flag, OSPF6_LSA_HEADERONLY))
hasso508e53e2004-05-18 18:57:06 +0000604 return 0; /* dbexchange will do something ... */
605
606 /* reflood lsa */
hasso6452df02004-08-15 05:52:07 +0000607 ospf6_flood (NULL, lsa);
hasso508e53e2004-05-18 18:57:06 +0000608
609 /* reinstall lsa */
hasso3b687352004-08-19 06:56:53 +0000610 ospf6_install_lsa (lsa);
hasso508e53e2004-05-18 18:57:06 +0000611
612 /* schedule maxage remover */
613 ospf6_maxage_remove (ospf6);
614
paul718e3742002-12-13 20:15:29 +0000615 return 0;
616}
617
618int
619ospf6_lsa_refresh (struct thread *thread)
620{
hasso6452df02004-08-15 05:52:07 +0000621 struct ospf6_lsa *old, *self, *new;
622 struct ospf6_lsdb *lsdb_self;
paul718e3742002-12-13 20:15:29 +0000623
624 assert (thread);
hasso6452df02004-08-15 05:52:07 +0000625 old = (struct ospf6_lsa *) THREAD_ARG (thread);
626 assert (old && old->header);
paul718e3742002-12-13 20:15:29 +0000627
hasso6452df02004-08-15 05:52:07 +0000628 old->refresh = (struct thread *) NULL;
paul718e3742002-12-13 20:15:29 +0000629
hasso6452df02004-08-15 05:52:07 +0000630 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);
633 if (self == NULL)
634 {
hasso1e058382004-09-01 21:36:14 +0000635 if (IS_OSPF6_DEBUG_LSA_TYPE (old->header->type))
hassoc6487d62004-12-24 06:00:11 +0000636 zlog_debug ("Refresh: could not find self LSA, flush %s", old->name);
hasso6452df02004-08-15 05:52:07 +0000637 ospf6_lsa_premature_aging (old);
638 return 0;
639 }
640
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);
647
648 new = ospf6_lsa_create (self->header);
649 new->lsdb = old->lsdb;
650 new->refresh = thread_add_timer (master, ospf6_lsa_refresh, new,
651 LS_REFRESH_TIME);
652
653 /* store it in the LSDB for self-originated LSAs */
654 ospf6_lsdb_add (ospf6_lsa_copy (new), lsdb_self);
paul718e3742002-12-13 20:15:29 +0000655
hasso1e058382004-09-01 21:36:14 +0000656 if (IS_OSPF6_DEBUG_LSA_TYPE (new->header->type))
paul718e3742002-12-13 20:15:29 +0000657 {
hassoc6487d62004-12-24 06:00:11 +0000658 zlog_debug ("LSA Refresh:");
hasso6452df02004-08-15 05:52:07 +0000659 ospf6_lsa_header_print (new);
paul718e3742002-12-13 20:15:29 +0000660 }
661
hasso6452df02004-08-15 05:52:07 +0000662 ospf6_flood_clear (old);
663 ospf6_flood (NULL, new);
664 ospf6_install_lsa (new);
665
hasso508e53e2004-05-18 18:57:06 +0000666 return 0;
paul718e3742002-12-13 20:15:29 +0000667}
668
669
670
671/* enhanced Fletcher checksum algorithm, RFC1008 7.2 */
672#define MODX 4102
673#define LSA_CHECKSUM_OFFSET 15
674
675unsigned short
676ospf6_lsa_checksum (struct ospf6_lsa_header *lsa_header)
677{
678 u_char *sp, *ep, *p, *q;
679 int c0 = 0, c1 = 0;
680 int x, y;
681 u_int16_t length;
682
683 lsa_header->checksum = 0;
684 length = ntohs (lsa_header->length) - 2;
hasso03d52f82004-09-29 00:26:19 +0000685 sp = (u_char *) &lsa_header->type;
paul718e3742002-12-13 20:15:29 +0000686
687 for (ep = sp + length; sp < ep; sp = q)
688 {
689 q = sp + MODX;
690 if (q > ep)
691 q = ep;
692 for (p = sp; p < q; p++)
693 {
694 c0 += *p;
695 c1 += c0;
696 }
697 c0 %= 255;
698 c1 %= 255;
699 }
700
701 /* r = (c1 << 8) + c0; */
702 x = ((length - LSA_CHECKSUM_OFFSET) * c0 - c1) % 255;
703 if (x <= 0)
704 x += 255;
705 y = 510 - c0 - x;
706 if (y > 255)
707 y -= 255;
708
709 lsa_header->checksum = htons ((x << 8) + y);
710
711 return (lsa_header->checksum);
712}
713
hasso6452df02004-08-15 05:52:07 +0000714void
Paul Jakma6ac29a52008-08-15 13:45:30 +0100715ospf6_lsa_init (void)
paul718e3742002-12-13 20:15:29 +0000716{
hasso1e058382004-09-01 21:36:14 +0000717 ospf6_lsa_handler_vector = vector_init (0);
hasso6452df02004-08-15 05:52:07 +0000718 ospf6_install_lsa_handler (&unknown_handler);
paul718e3742002-12-13 20:15:29 +0000719}
720
hasso508e53e2004-05-18 18:57:06 +0000721
Paul Jakma6ac29a52008-08-15 13:45:30 +0100722static char *
hasso1e058382004-09-01 21:36:14 +0000723ospf6_lsa_handler_name (struct ospf6_lsa_handler *h)
hasso508e53e2004-05-18 18:57:06 +0000724{
hasso1e058382004-09-01 21:36:14 +0000725 static char buf[64];
paul0c083ee2004-10-10 12:54:58 +0000726 unsigned int i;
727 unsigned int size = strlen (h->name);
hasso508e53e2004-05-18 18:57:06 +0000728
Andrew J. Schorrc32d28b2007-02-27 15:24:36 +0000729 if (!strcmp(h->name, "Unknown") &&
hasso1e058382004-09-01 21:36:14 +0000730 h->type != OSPF6_LSTYPE_UNKNOWN)
hasso508e53e2004-05-18 18:57:06 +0000731 {
hasso1e058382004-09-01 21:36:14 +0000732 snprintf (buf, sizeof (buf), "%#04hx", h->type);
733 return buf;
hasso508e53e2004-05-18 18:57:06 +0000734 }
735
hasso1e058382004-09-01 21:36:14 +0000736 for (i = 0; i < MIN (size, sizeof (buf)); i++)
hasso508e53e2004-05-18 18:57:06 +0000737 {
hasso1e058382004-09-01 21:36:14 +0000738 if (! islower (h->name[i]))
739 buf[i] = tolower (h->name[i]);
hasso508e53e2004-05-18 18:57:06 +0000740 else
hasso1e058382004-09-01 21:36:14 +0000741 buf[i] = h->name[i];
742 }
743 buf[size] = '\0';
744 return buf;
745}
hasso508e53e2004-05-18 18:57:06 +0000746
hasso1e058382004-09-01 21:36:14 +0000747DEFUN (debug_ospf6_lsa_type,
748 debug_ospf6_lsa_hex_cmd,
749 "debug ospf6 lsa XXXX/0xXXXX",
750 DEBUG_STR
751 OSPF6_STR
752 "Debug Link State Advertisements (LSAs)\n"
753 "Specify LS type as Hexadecimal\n"
754 )
755{
paul0c083ee2004-10-10 12:54:58 +0000756 unsigned int i;
hasso1e058382004-09-01 21:36:14 +0000757 struct ospf6_lsa_handler *handler = NULL;
758 unsigned long val;
759 char *endptr = NULL;
760 u_int16_t type = 0;
761
762 assert (argc);
763
764 if ((strlen (argv[0]) == 6 && ! strncmp (argv[0], "0x", 2)) ||
765 (strlen (argv[0]) == 4))
766 {
767 val = strtoul (argv[0], &endptr, 16);
768 if (*endptr == '\0')
769 type = val;
hasso508e53e2004-05-18 18:57:06 +0000770 }
771
paul55468c82005-03-14 20:19:01 +0000772 for (i = 0; i < vector_active (ospf6_lsa_handler_vector); i++)
hasso1e058382004-09-01 21:36:14 +0000773 {
774 handler = vector_slot (ospf6_lsa_handler_vector, i);
775 if (handler == NULL)
776 continue;
777 if (type && handler->type == type)
778 break;
779 if (! strcasecmp (argv[0], handler->name))
780 break;
781 handler = NULL;
782 }
783
784 if (type && handler == NULL)
785 {
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);
794 }
795
796 if (handler == NULL)
797 handler = &unknown_handler;
798
799 if (argc >= 2)
800 {
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);
807 }
808 else
809 SET_FLAG (handler->debug, OSPF6_LSA_DEBUG);
810
811 return CMD_SUCCESS;
hasso508e53e2004-05-18 18:57:06 +0000812}
813
hasso1e058382004-09-01 21:36:14 +0000814DEFUN (no_debug_ospf6_lsa_type,
815 no_debug_ospf6_lsa_hex_cmd,
816 "no debug ospf6 lsa XXXX/0xXXXX",
817 NO_STR
818 DEBUG_STR
819 OSPF6_STR
820 "Debug Link State Advertisements (LSAs)\n"
821 "Specify LS type as Hexadecimal\n"
822 )
823{
paul0c083ee2004-10-10 12:54:58 +0000824 u_int i;
hasso1e058382004-09-01 21:36:14 +0000825 struct ospf6_lsa_handler *handler = NULL;
826 unsigned long val;
827 char *endptr = NULL;
828 u_int16_t type = 0;
829
830 assert (argc);
831
832 if ((strlen (argv[0]) == 6 && ! strncmp (argv[0], "0x", 2)) ||
833 (strlen (argv[0]) == 4))
834 {
835 val = strtoul (argv[0], &endptr, 16);
836 if (*endptr == '\0')
837 type = val;
838 }
839
paul55468c82005-03-14 20:19:01 +0000840 for (i = 0; i < vector_active (ospf6_lsa_handler_vector); i++)
hasso1e058382004-09-01 21:36:14 +0000841 {
842 handler = vector_slot (ospf6_lsa_handler_vector, i);
843 if (handler == NULL)
844 continue;
845 if (type && handler->type == type)
846 break;
847 if (! strcasecmp (argv[0], handler->name))
848 break;
849 }
850
851 if (handler == NULL)
852 return CMD_SUCCESS;
853
854 if (argc >= 2)
855 {
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);
862 }
863 else
864 UNSET_FLAG (handler->debug, OSPF6_LSA_DEBUG);
865
866 if (handler->debug == 0 &&
Andrew J. Schorre733f942007-06-07 13:11:58 +0000867 !strcmp(handler->name, "Unknown") && type != OSPF6_LSTYPE_UNKNOWN)
hasso1e058382004-09-01 21:36:14 +0000868 {
869 free (handler);
870 vector_slot (ospf6_lsa_handler_vector, i) = NULL;
871 }
872
873 return CMD_SUCCESS;
874}
875
876struct cmd_element debug_ospf6_lsa_type_cmd;
877struct cmd_element debug_ospf6_lsa_type_detail_cmd;
878struct cmd_element no_debug_ospf6_lsa_type_cmd;
879struct cmd_element no_debug_ospf6_lsa_type_detail_cmd;
880
hasso508e53e2004-05-18 18:57:06 +0000881void
Paul Jakma6ac29a52008-08-15 13:45:30 +0100882install_element_ospf6_debug_lsa (void)
hasso508e53e2004-05-18 18:57:06 +0000883{
paul0c083ee2004-10-10 12:54:58 +0000884 u_int i;
hasso1e058382004-09-01 21:36:14 +0000885 struct ospf6_lsa_handler *handler;
886#define STRSIZE 256
887#define DOCSIZE 1024
888 static char strbuf[STRSIZE];
889 static char docbuf[DOCSIZE];
890 static char detail_strbuf[STRSIZE];
891 static char detail_docbuf[DOCSIZE];
892 char *str, *no_str;
893 char *doc, *no_doc;
894
895 strbuf[0] = '\0';
896 no_str = &strbuf[strlen (strbuf)];
897 strncat (strbuf, "no ", STRSIZE - strlen (strbuf));
898 str = &strbuf[strlen (strbuf)];
899
900 strncat (strbuf, "debug ospf6 lsa (", STRSIZE - strlen (strbuf));
paul55468c82005-03-14 20:19:01 +0000901 for (i = 0; i < vector_active (ospf6_lsa_handler_vector); i++)
hasso1e058382004-09-01 21:36:14 +0000902 {
903 handler = vector_slot (ospf6_lsa_handler_vector, i);
904 if (handler == NULL)
905 continue;
906 strncat (strbuf, ospf6_lsa_handler_name (handler),
907 STRSIZE - strlen (strbuf));
908 strncat (strbuf, "|", STRSIZE - strlen (strbuf));
909 }
910 strbuf[strlen (strbuf) - 1] = ')';
911 strbuf[strlen (strbuf)] = '\0';
912
913 docbuf[0] = '\0';
914 no_doc = &docbuf[strlen (docbuf)];
915 strncat (docbuf, NO_STR, DOCSIZE - strlen (docbuf));
916 doc = &docbuf[strlen (docbuf)];
917
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));
922
paul55468c82005-03-14 20:19:01 +0000923 for (i = 0; i < vector_active (ospf6_lsa_handler_vector); i++)
hasso1e058382004-09-01 21:36:14 +0000924 {
925 handler = vector_slot (ospf6_lsa_handler_vector, i);
926 if (handler == NULL)
927 continue;
928 strncat (docbuf, "Debug ", DOCSIZE - strlen (docbuf));
929 strncat (docbuf, handler->name, DOCSIZE - strlen (docbuf));
930 strncat (docbuf, "-LSA\n", DOCSIZE - strlen (docbuf));
931 }
932 docbuf[strlen (docbuf)] = '\0';
933
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;
937
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;
941
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 ")];
948
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)];
959
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;
963
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;
967
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);
980}
981
982int
983config_write_ospf6_debug_lsa (struct vty *vty)
984{
paul0c083ee2004-10-10 12:54:58 +0000985 u_int i;
hasso1e058382004-09-01 21:36:14 +0000986 struct ospf6_lsa_handler *handler;
987
paul55468c82005-03-14 20:19:01 +0000988 for (i = 0; i < vector_active (ospf6_lsa_handler_vector); i++)
hasso1e058382004-09-01 21:36:14 +0000989 {
990 handler = vector_slot (ospf6_lsa_handler_vector, i);
991 if (handler == NULL)
992 continue;
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);
1005 }
1006
1007 return 0;
hasso508e53e2004-05-18 18:57:06 +00001008}
1009
1010