blob: 07d9f91eb6336422528910d28f9fef10a69d810d [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 Hendersonaabbb1a2009-08-28 15:10:00 +0100210 if (ntohs (lsa->header->age) >= MAXAGE)
Tom Henderson9b4ef252009-07-16 17:20:37 +0100211 {
Tom Hendersonaabbb1a2009-08-28 15:10:00 +0100212 /* 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. */
Tom Henderson9b4ef252009-07-16 17:20:37 +0100215 lsa->header->age = htons (MAXAGE);
216 return MAXAGE;
217 }
paul718e3742002-12-13 20:15:29 +0000218 /* calculate age */
219 ulage = now.tv_sec - lsa->birth.tv_sec;
220
221 /* if over MAXAGE, set to it */
hasso508e53e2004-05-18 18:57:06 +0000222 age = (ulage > MAXAGE ? MAXAGE : ulage);
paul718e3742002-12-13 20:15:29 +0000223
224 lsa->header->age = htons (age);
225 return age;
226}
227
228/* update age field of LSA header with adding InfTransDelay */
229void
230ospf6_lsa_age_update_to_send (struct ospf6_lsa *lsa, u_int32_t transdelay)
231{
232 unsigned short age;
233
234 age = ospf6_lsa_age_current (lsa) + transdelay;
235 if (age > MAXAGE)
236 age = MAXAGE;
237 lsa->header->age = htons (age);
paul718e3742002-12-13 20:15:29 +0000238}
239
240void
241ospf6_lsa_premature_aging (struct ospf6_lsa *lsa)
242{
243 /* log */
hasso1e058382004-09-01 21:36:14 +0000244 if (IS_OSPF6_DEBUG_LSA_TYPE (lsa->header->type))
hassoc6487d62004-12-24 06:00:11 +0000245 zlog_debug ("LSA: Premature aging: %s", lsa->name);
paul718e3742002-12-13 20:15:29 +0000246
hasso508e53e2004-05-18 18:57:06 +0000247 THREAD_OFF (lsa->expire);
248 THREAD_OFF (lsa->refresh);
paul718e3742002-12-13 20:15:29 +0000249
Tom Henderson9b4ef252009-07-16 17:20:37 +0100250 lsa->header->age = htons (MAXAGE);
paul718e3742002-12-13 20:15:29 +0000251 thread_execute (master, ospf6_lsa_expire, lsa, 0);
252}
253
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 */
256int
hasso508e53e2004-05-18 18:57:06 +0000257ospf6_lsa_compare (struct ospf6_lsa *a, struct ospf6_lsa *b)
paul718e3742002-12-13 20:15:29 +0000258{
259 signed long seqnuma, seqnumb;
260 u_int16_t cksuma, cksumb;
261 u_int16_t agea, ageb;
262
263 assert (a && a->header);
264 assert (b && b->header);
hasso508e53e2004-05-18 18:57:06 +0000265 assert (OSPF6_LSA_IS_SAME (a, b));
paul718e3742002-12-13 20:15:29 +0000266
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;
271
272 /* compare by sequence number */
hasso508e53e2004-05-18 18:57:06 +0000273 /* XXX, LS sequence number wrapping */
paul718e3742002-12-13 20:15:29 +0000274 if (seqnuma > seqnumb)
275 return -1;
276 else if (seqnuma < seqnumb)
277 return 1;
278
279 /* Checksum */
280 cksuma = ntohs (a->header->checksum);
281 cksumb = ntohs (b->header->checksum);
282 if (cksuma > cksumb)
283 return -1;
284 if (cksuma < cksumb)
285 return 0;
286
hasso508e53e2004-05-18 18:57:06 +0000287 /* Update Age */
paul718e3742002-12-13 20:15:29 +0000288 agea = ospf6_lsa_age_current (a);
289 ageb = ospf6_lsa_age_current (b);
290
hasso508e53e2004-05-18 18:57:06 +0000291 /* MaxAge check */
292 if (agea == MAXAGE && ageb != MAXAGE)
paul718e3742002-12-13 20:15:29 +0000293 return -1;
hasso508e53e2004-05-18 18:57:06 +0000294 else if (agea != MAXAGE && ageb == MAXAGE)
paul718e3742002-12-13 20:15:29 +0000295 return 1;
296
hasso508e53e2004-05-18 18:57:06 +0000297 /* Age check */
298 if (agea > ageb && agea - ageb >= MAX_AGE_DIFF)
paul718e3742002-12-13 20:15:29 +0000299 return 1;
hasso508e53e2004-05-18 18:57:06 +0000300 else if (agea < ageb && ageb - agea >= MAX_AGE_DIFF)
paul718e3742002-12-13 20:15:29 +0000301 return -1;
302
303 /* neither recent */
paul718e3742002-12-13 20:15:29 +0000304 return 0;
305}
306
hasso508e53e2004-05-18 18:57:06 +0000307char *
308ospf6_lsa_printbuf (struct ospf6_lsa *lsa, char *buf, int size)
paul718e3742002-12-13 20:15:29 +0000309{
hasso508e53e2004-05-18 18:57:06 +0000310 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]",
hasso1e058382004-09-01 21:36:14 +0000315 ospf6_lstype_name (lsa->header->type), id, adv_router);
hasso508e53e2004-05-18 18:57:06 +0000316 return buf;
paul718e3742002-12-13 20:15:29 +0000317}
318
hasso508e53e2004-05-18 18:57:06 +0000319void
320ospf6_lsa_header_print_raw (struct ospf6_lsa_header *header)
paul718e3742002-12-13 20:15:29 +0000321{
hasso508e53e2004-05-18 18:57:06 +0000322 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));
hassoc6487d62004-12-24 06:00:11 +0000326 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));
paul718e3742002-12-13 20:15:29 +0000331}
332
hasso508e53e2004-05-18 18:57:06 +0000333void
334ospf6_lsa_header_print (struct ospf6_lsa *lsa)
paul718e3742002-12-13 20:15:29 +0000335{
hasso508e53e2004-05-18 18:57:06 +0000336 ospf6_lsa_age_current (lsa);
337 ospf6_lsa_header_print_raw (lsa->header);
paul718e3742002-12-13 20:15:29 +0000338}
339
340void
paul718e3742002-12-13 20:15:29 +0000341ospf6_lsa_show_summary_header (struct vty *vty)
342{
343 vty_out (vty, "%-12s %-15s %-15s %4s %8s %4s %4s %-8s%s",
344 "Type", "LSId", "AdvRouter", "Age", "SeqNum",
hasso049207c2004-08-04 20:02:13 +0000345 "Cksm", "Len", "Duration", VNL);
paul718e3742002-12-13 20:15:29 +0000346}
347
348void
349ospf6_lsa_show_summary (struct vty *vty, struct ospf6_lsa *lsa)
350{
hasso508e53e2004-05-18 18:57:06 +0000351 char adv_router[16], id[16];
paul718e3742002-12-13 20:15:29 +0000352 struct timeval now, res;
353 char duration[16];
354
355 assert (lsa);
356 assert (lsa->header);
357
paul718e3742002-12-13 20:15:29 +0000358 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));
361
Takashi Sogabe86f72dc2009-06-22 13:07:02 +0900362 quagga_gettime (QUAGGA_CLK_MONOTONIC, &now);
hasso508e53e2004-05-18 18:57:06 +0000363 timersub (&now, &lsa->installed, &res);
364 timerstring (&res, duration, sizeof (duration));
paul718e3742002-12-13 20:15:29 +0000365
366 vty_out (vty, "%-12s %-15s %-15s %4hu %8lx %04hx %4hu %8s%s",
hasso1e058382004-09-01 21:36:14 +0000367 ospf6_lstype_name (lsa->header->type),
hasso508e53e2004-05-18 18:57:06 +0000368 id, adv_router, ospf6_lsa_age_current (lsa),
paul718e3742002-12-13 20:15:29 +0000369 (u_long) ntohl (lsa->header->seqnum),
370 ntohs (lsa->header->checksum), ntohs (lsa->header->length),
hasso049207c2004-08-04 20:02:13 +0000371 duration, VNL);
paul718e3742002-12-13 20:15:29 +0000372}
373
374void
375ospf6_lsa_show_dump (struct vty *vty, struct ospf6_lsa *lsa)
376{
377 u_char *start, *end, *current;
378 char byte[4];
379
hasso03d52f82004-09-29 00:26:19 +0000380 start = (u_char *) lsa->header;
381 end = (u_char *) lsa->header + ntohs (lsa->header->length);
paul718e3742002-12-13 20:15:29 +0000382
hasso049207c2004-08-04 20:02:13 +0000383 vty_out (vty, "%s", VNL);
384 vty_out (vty, "%s:%s", lsa->name, VNL);
paul718e3742002-12-13 20:15:29 +0000385
386 for (current = start; current < end; current ++)
387 {
388 if ((current - start) % 16 == 0)
hasso049207c2004-08-04 20:02:13 +0000389 vty_out (vty, "%s ", VNL);
paul718e3742002-12-13 20:15:29 +0000390 else if ((current - start) % 4 == 0)
391 vty_out (vty, " ");
392
393 snprintf (byte, sizeof (byte), "%02x", *current);
394 vty_out (vty, "%s", byte);
395 }
396
hasso049207c2004-08-04 20:02:13 +0000397 vty_out (vty, "%s%s", VNL, VNL);
hasso6452df02004-08-15 05:52:07 +0000398 return;
paul718e3742002-12-13 20:15:29 +0000399}
400
hasso508e53e2004-05-18 18:57:06 +0000401void
402ospf6_lsa_show_internal (struct vty *vty, struct ospf6_lsa *lsa)
403{
404 char adv_router[64], id[64];
405
406 assert (lsa && lsa->header);
407
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));
411
hasso049207c2004-08-04 20:02:13 +0000412 vty_out (vty, "%s", VNL);
hasso508e53e2004-05-18 18:57:06 +0000413 vty_out (vty, "Age: %4hu Type: %s%s", ospf6_lsa_age_current (lsa),
hasso1e058382004-09-01 21:36:14 +0000414 ospf6_lstype_name (lsa->header->type), VNL);
hasso049207c2004-08-04 20:02:13 +0000415 vty_out (vty, "Link State ID: %s%s", id, VNL);
416 vty_out (vty, "Advertising Router: %s%s", adv_router, VNL);
hasso508e53e2004-05-18 18:57:06 +0000417 vty_out (vty, "LS Sequence Number: %#010lx%s",
hasso049207c2004-08-04 20:02:13 +0000418 (u_long) ntohl (lsa->header->seqnum), VNL);
hasso508e53e2004-05-18 18:57:06 +0000419 vty_out (vty, "CheckSum: %#06hx Length: %hu%s",
420 ntohs (lsa->header->checksum),
hasso049207c2004-08-04 20:02:13 +0000421 ntohs (lsa->header->length), VNL);
hasso508e53e2004-05-18 18:57:06 +0000422 vty_out (vty, " Prev: %p This: %p Next: %p%s",
hasso049207c2004-08-04 20:02:13 +0000423 lsa->prev, lsa, lsa->next, VNL);
424 vty_out (vty, "%s", VNL);
hasso6452df02004-08-15 05:52:07 +0000425 return;
426}
427
428void
429ospf6_lsa_show (struct vty *vty, struct ospf6_lsa *lsa)
430{
431 char adv_router[64], id[64];
hasso1e058382004-09-01 21:36:14 +0000432 struct ospf6_lsa_handler *handler;
hasso6452df02004-08-15 05:52:07 +0000433
434 assert (lsa && lsa->header);
435
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));
439
440 vty_out (vty, "Age: %4hu Type: %s%s", ospf6_lsa_age_current (lsa),
hasso1e058382004-09-01 21:36:14 +0000441 ospf6_lstype_name (lsa->header->type), VNL);
hasso6452df02004-08-15 05:52:07 +0000442 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);
449
hasso1e058382004-09-01 21:36:14 +0000450 handler = ospf6_get_lsa_handler (lsa->header->type);
451 if (handler->show == NULL)
452 handler = &unknown_handler;
453 (*handler->show) (vty, lsa);
hasso6452df02004-08-15 05:52:07 +0000454
455 vty_out (vty, "%s", VNL);
hasso508e53e2004-05-18 18:57:06 +0000456}
457
paul718e3742002-12-13 20:15:29 +0000458/* OSPFv3 LSA creation/deletion function */
paul718e3742002-12-13 20:15:29 +0000459struct ospf6_lsa *
hasso508e53e2004-05-18 18:57:06 +0000460ospf6_lsa_create (struct ospf6_lsa_header *header)
paul718e3742002-12-13 20:15:29 +0000461{
462 struct ospf6_lsa *lsa = NULL;
hasso508e53e2004-05-18 18:57:06 +0000463 struct ospf6_lsa_header *new_header = NULL;
paul718e3742002-12-13 20:15:29 +0000464 u_int16_t lsa_size = 0;
paul718e3742002-12-13 20:15:29 +0000465
hasso508e53e2004-05-18 18:57:06 +0000466 /* size of the entire LSA */
467 lsa_size = ntohs (header->length); /* XXX vulnerable */
paul718e3742002-12-13 20:15:29 +0000468
469 /* allocate memory for this LSA */
hasso508e53e2004-05-18 18:57:06 +0000470 new_header = (struct ospf6_lsa_header *)
paul718e3742002-12-13 20:15:29 +0000471 XMALLOC (MTYPE_OSPF6_LSA, lsa_size);
paul718e3742002-12-13 20:15:29 +0000472
hasso508e53e2004-05-18 18:57:06 +0000473 /* copy LSA from original header */
474 memcpy (new_header, header, lsa_size);
paul718e3742002-12-13 20:15:29 +0000475
476 /* LSA information structure */
477 /* allocate memory */
478 lsa = (struct ospf6_lsa *)
Stephen Hemminger393deb92008-08-18 14:13:29 -0700479 XCALLOC (MTYPE_OSPF6_LSA, sizeof (struct ospf6_lsa));
paul718e3742002-12-13 20:15:29 +0000480
hasso508e53e2004-05-18 18:57:06 +0000481 lsa->header = (struct ospf6_lsa_header *) new_header;
paul718e3742002-12-13 20:15:29 +0000482
483 /* dump string */
hasso508e53e2004-05-18 18:57:06 +0000484 ospf6_lsa_printbuf (lsa, lsa->name, sizeof (lsa->name));
paul718e3742002-12-13 20:15:29 +0000485
hasso3b687352004-08-19 06:56:53 +0000486 /* calculate birth of this lsa */
paul718e3742002-12-13 20:15:29 +0000487 ospf6_lsa_age_set (lsa);
488
paul718e3742002-12-13 20:15:29 +0000489 return lsa;
490}
491
492struct ospf6_lsa *
hasso508e53e2004-05-18 18:57:06 +0000493ospf6_lsa_create_headeronly (struct ospf6_lsa_header *header)
paul718e3742002-12-13 20:15:29 +0000494{
495 struct ospf6_lsa *lsa = NULL;
hasso508e53e2004-05-18 18:57:06 +0000496 struct ospf6_lsa_header *new_header = NULL;
paul718e3742002-12-13 20:15:29 +0000497
498 /* allocate memory for this LSA */
hasso508e53e2004-05-18 18:57:06 +0000499 new_header = (struct ospf6_lsa_header *)
500 XMALLOC (MTYPE_OSPF6_LSA, sizeof (struct ospf6_lsa_header));
paul718e3742002-12-13 20:15:29 +0000501
hasso508e53e2004-05-18 18:57:06 +0000502 /* copy LSA from original header */
503 memcpy (new_header, header, sizeof (struct ospf6_lsa_header));
paul718e3742002-12-13 20:15:29 +0000504
505 /* LSA information structure */
506 /* allocate memory */
507 lsa = (struct ospf6_lsa *)
Stephen Hemminger393deb92008-08-18 14:13:29 -0700508 XCALLOC (MTYPE_OSPF6_LSA, sizeof (struct ospf6_lsa));
paul718e3742002-12-13 20:15:29 +0000509
hasso508e53e2004-05-18 18:57:06 +0000510 lsa->header = (struct ospf6_lsa_header *) new_header;
hasso6452df02004-08-15 05:52:07 +0000511 SET_FLAG (lsa->flag, OSPF6_LSA_HEADERONLY);
paul718e3742002-12-13 20:15:29 +0000512
513 /* dump string */
hasso508e53e2004-05-18 18:57:06 +0000514 ospf6_lsa_printbuf (lsa, lsa->name, sizeof (lsa->name));
paul718e3742002-12-13 20:15:29 +0000515
hasso3b687352004-08-19 06:56:53 +0000516 /* calculate birth of this lsa */
paul718e3742002-12-13 20:15:29 +0000517 ospf6_lsa_age_set (lsa);
518
paul718e3742002-12-13 20:15:29 +0000519 return lsa;
520}
521
522void
523ospf6_lsa_delete (struct ospf6_lsa *lsa)
524{
hasso508e53e2004-05-18 18:57:06 +0000525 assert (lsa->lock == 0);
paul718e3742002-12-13 20:15:29 +0000526
527 /* cancel threads */
hasso508e53e2004-05-18 18:57:06 +0000528 THREAD_OFF (lsa->expire);
529 THREAD_OFF (lsa->refresh);
paul718e3742002-12-13 20:15:29 +0000530
paul718e3742002-12-13 20:15:29 +0000531 /* do free */
hasso508e53e2004-05-18 18:57:06 +0000532 XFREE (MTYPE_OSPF6_LSA, lsa->header);
533 XFREE (MTYPE_OSPF6_LSA, lsa);
paul718e3742002-12-13 20:15:29 +0000534}
535
hasso508e53e2004-05-18 18:57:06 +0000536struct ospf6_lsa *
537ospf6_lsa_copy (struct ospf6_lsa *lsa)
538{
539 struct ospf6_lsa *copy = NULL;
540
hasso508e53e2004-05-18 18:57:06 +0000541 ospf6_lsa_age_current (lsa);
hasso6452df02004-08-15 05:52:07 +0000542 if (CHECK_FLAG (lsa->flag, OSPF6_LSA_HEADERONLY))
hasso508e53e2004-05-18 18:57:06 +0000543 copy = ospf6_lsa_create_headeronly (lsa->header);
544 else
545 copy = ospf6_lsa_create (lsa->header);
546 assert (copy->lock == 0);
547
hasso3b687352004-08-19 06:56:53 +0000548 copy->birth = lsa->birth;
hasso508e53e2004-05-18 18:57:06 +0000549 copy->originated = lsa->originated;
hassoccb59b12004-08-25 09:10:37 +0000550 copy->received = lsa->received;
551 copy->installed = lsa->installed;
hasso6452df02004-08-15 05:52:07 +0000552 copy->lsdb = lsa->lsdb;
hasso508e53e2004-05-18 18:57:06 +0000553
hasso508e53e2004-05-18 18:57:06 +0000554 return copy;
555}
556
557/* increment reference counter of struct ospf6_lsa */
paul718e3742002-12-13 20:15:29 +0000558void
559ospf6_lsa_lock (struct ospf6_lsa *lsa)
560{
561 lsa->lock++;
562 return;
563}
564
hasso508e53e2004-05-18 18:57:06 +0000565/* decrement reference counter of struct ospf6_lsa */
paul718e3742002-12-13 20:15:29 +0000566void
567ospf6_lsa_unlock (struct ospf6_lsa *lsa)
568{
569 /* decrement reference counter */
hasso508e53e2004-05-18 18:57:06 +0000570 assert (lsa->lock > 0);
571 lsa->lock--;
paul718e3742002-12-13 20:15:29 +0000572
hasso508e53e2004-05-18 18:57:06 +0000573 if (lsa->lock != 0)
574 return;
575
hasso508e53e2004-05-18 18:57:06 +0000576 ospf6_lsa_delete (lsa);
paul718e3742002-12-13 20:15:29 +0000577}
578
paul718e3742002-12-13 20:15:29 +0000579
hasso508e53e2004-05-18 18:57:06 +0000580/* ospf6 lsa expiry */
paul718e3742002-12-13 20:15:29 +0000581int
582ospf6_lsa_expire (struct thread *thread)
583{
584 struct ospf6_lsa *lsa;
paul718e3742002-12-13 20:15:29 +0000585
586 lsa = (struct ospf6_lsa *) THREAD_ARG (thread);
paul718e3742002-12-13 20:15:29 +0000587
hasso508e53e2004-05-18 18:57:06 +0000588 assert (lsa && lsa->header);
589 assert (OSPF6_LSA_IS_MAXAGE (lsa));
590 assert (! lsa->refresh);
paul718e3742002-12-13 20:15:29 +0000591
592 lsa->expire = (struct thread *) NULL;
593
hasso1e058382004-09-01 21:36:14 +0000594 if (IS_OSPF6_DEBUG_LSA_TYPE (lsa->header->type))
paul718e3742002-12-13 20:15:29 +0000595 {
hassoc6487d62004-12-24 06:00:11 +0000596 zlog_debug ("LSA Expire:");
hasso508e53e2004-05-18 18:57:06 +0000597 ospf6_lsa_header_print (lsa);
paul718e3742002-12-13 20:15:29 +0000598 }
599
hasso6452df02004-08-15 05:52:07 +0000600 if (CHECK_FLAG (lsa->flag, OSPF6_LSA_HEADERONLY))
hasso508e53e2004-05-18 18:57:06 +0000601 return 0; /* dbexchange will do something ... */
602
603 /* reflood lsa */
hasso6452df02004-08-15 05:52:07 +0000604 ospf6_flood (NULL, lsa);
hasso508e53e2004-05-18 18:57:06 +0000605
606 /* reinstall lsa */
hasso3b687352004-08-19 06:56:53 +0000607 ospf6_install_lsa (lsa);
hasso508e53e2004-05-18 18:57:06 +0000608
609 /* schedule maxage remover */
610 ospf6_maxage_remove (ospf6);
611
paul718e3742002-12-13 20:15:29 +0000612 return 0;
613}
614
615int
616ospf6_lsa_refresh (struct thread *thread)
617{
hasso6452df02004-08-15 05:52:07 +0000618 struct ospf6_lsa *old, *self, *new;
619 struct ospf6_lsdb *lsdb_self;
paul718e3742002-12-13 20:15:29 +0000620
621 assert (thread);
hasso6452df02004-08-15 05:52:07 +0000622 old = (struct ospf6_lsa *) THREAD_ARG (thread);
623 assert (old && old->header);
paul718e3742002-12-13 20:15:29 +0000624
hasso6452df02004-08-15 05:52:07 +0000625 old->refresh = (struct thread *) NULL;
paul718e3742002-12-13 20:15:29 +0000626
hasso6452df02004-08-15 05:52:07 +0000627 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);
630 if (self == NULL)
631 {
hasso1e058382004-09-01 21:36:14 +0000632 if (IS_OSPF6_DEBUG_LSA_TYPE (old->header->type))
hassoc6487d62004-12-24 06:00:11 +0000633 zlog_debug ("Refresh: could not find self LSA, flush %s", old->name);
hasso6452df02004-08-15 05:52:07 +0000634 ospf6_lsa_premature_aging (old);
635 return 0;
636 }
637
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);
644
645 new = ospf6_lsa_create (self->header);
646 new->lsdb = old->lsdb;
647 new->refresh = thread_add_timer (master, ospf6_lsa_refresh, new,
648 LS_REFRESH_TIME);
649
650 /* store it in the LSDB for self-originated LSAs */
651 ospf6_lsdb_add (ospf6_lsa_copy (new), lsdb_self);
paul718e3742002-12-13 20:15:29 +0000652
hasso1e058382004-09-01 21:36:14 +0000653 if (IS_OSPF6_DEBUG_LSA_TYPE (new->header->type))
paul718e3742002-12-13 20:15:29 +0000654 {
hassoc6487d62004-12-24 06:00:11 +0000655 zlog_debug ("LSA Refresh:");
hasso6452df02004-08-15 05:52:07 +0000656 ospf6_lsa_header_print (new);
paul718e3742002-12-13 20:15:29 +0000657 }
658
hasso6452df02004-08-15 05:52:07 +0000659 ospf6_flood_clear (old);
660 ospf6_flood (NULL, new);
661 ospf6_install_lsa (new);
662
hasso508e53e2004-05-18 18:57:06 +0000663 return 0;
paul718e3742002-12-13 20:15:29 +0000664}
665
666
667
668/* enhanced Fletcher checksum algorithm, RFC1008 7.2 */
669#define MODX 4102
670#define LSA_CHECKSUM_OFFSET 15
671
672unsigned short
673ospf6_lsa_checksum (struct ospf6_lsa_header *lsa_header)
674{
675 u_char *sp, *ep, *p, *q;
676 int c0 = 0, c1 = 0;
677 int x, y;
678 u_int16_t length;
679
680 lsa_header->checksum = 0;
681 length = ntohs (lsa_header->length) - 2;
hasso03d52f82004-09-29 00:26:19 +0000682 sp = (u_char *) &lsa_header->type;
paul718e3742002-12-13 20:15:29 +0000683
684 for (ep = sp + length; sp < ep; sp = q)
685 {
686 q = sp + MODX;
687 if (q > ep)
688 q = ep;
689 for (p = sp; p < q; p++)
690 {
691 c0 += *p;
692 c1 += c0;
693 }
694 c0 %= 255;
695 c1 %= 255;
696 }
697
698 /* r = (c1 << 8) + c0; */
699 x = ((length - LSA_CHECKSUM_OFFSET) * c0 - c1) % 255;
700 if (x <= 0)
701 x += 255;
702 y = 510 - c0 - x;
703 if (y > 255)
704 y -= 255;
705
706 lsa_header->checksum = htons ((x << 8) + y);
707
708 return (lsa_header->checksum);
709}
710
hasso6452df02004-08-15 05:52:07 +0000711void
Paul Jakma6ac29a52008-08-15 13:45:30 +0100712ospf6_lsa_init (void)
paul718e3742002-12-13 20:15:29 +0000713{
hasso1e058382004-09-01 21:36:14 +0000714 ospf6_lsa_handler_vector = vector_init (0);
hasso6452df02004-08-15 05:52:07 +0000715 ospf6_install_lsa_handler (&unknown_handler);
paul718e3742002-12-13 20:15:29 +0000716}
717
hasso508e53e2004-05-18 18:57:06 +0000718
Paul Jakma6ac29a52008-08-15 13:45:30 +0100719static char *
hasso1e058382004-09-01 21:36:14 +0000720ospf6_lsa_handler_name (struct ospf6_lsa_handler *h)
hasso508e53e2004-05-18 18:57:06 +0000721{
hasso1e058382004-09-01 21:36:14 +0000722 static char buf[64];
paul0c083ee2004-10-10 12:54:58 +0000723 unsigned int i;
724 unsigned int size = strlen (h->name);
hasso508e53e2004-05-18 18:57:06 +0000725
Andrew J. Schorrc32d28b2007-02-27 15:24:36 +0000726 if (!strcmp(h->name, "Unknown") &&
hasso1e058382004-09-01 21:36:14 +0000727 h->type != OSPF6_LSTYPE_UNKNOWN)
hasso508e53e2004-05-18 18:57:06 +0000728 {
hasso1e058382004-09-01 21:36:14 +0000729 snprintf (buf, sizeof (buf), "%#04hx", h->type);
730 return buf;
hasso508e53e2004-05-18 18:57:06 +0000731 }
732
hasso1e058382004-09-01 21:36:14 +0000733 for (i = 0; i < MIN (size, sizeof (buf)); i++)
hasso508e53e2004-05-18 18:57:06 +0000734 {
hasso1e058382004-09-01 21:36:14 +0000735 if (! islower (h->name[i]))
736 buf[i] = tolower (h->name[i]);
hasso508e53e2004-05-18 18:57:06 +0000737 else
hasso1e058382004-09-01 21:36:14 +0000738 buf[i] = h->name[i];
739 }
740 buf[size] = '\0';
741 return buf;
742}
hasso508e53e2004-05-18 18:57:06 +0000743
hasso1e058382004-09-01 21:36:14 +0000744DEFUN (debug_ospf6_lsa_type,
745 debug_ospf6_lsa_hex_cmd,
746 "debug ospf6 lsa XXXX/0xXXXX",
747 DEBUG_STR
748 OSPF6_STR
749 "Debug Link State Advertisements (LSAs)\n"
750 "Specify LS type as Hexadecimal\n"
751 )
752{
paul0c083ee2004-10-10 12:54:58 +0000753 unsigned int i;
hasso1e058382004-09-01 21:36:14 +0000754 struct ospf6_lsa_handler *handler = NULL;
755 unsigned long val;
756 char *endptr = NULL;
757 u_int16_t type = 0;
758
759 assert (argc);
760
761 if ((strlen (argv[0]) == 6 && ! strncmp (argv[0], "0x", 2)) ||
762 (strlen (argv[0]) == 4))
763 {
764 val = strtoul (argv[0], &endptr, 16);
765 if (*endptr == '\0')
766 type = val;
hasso508e53e2004-05-18 18:57:06 +0000767 }
768
paul55468c82005-03-14 20:19:01 +0000769 for (i = 0; i < vector_active (ospf6_lsa_handler_vector); i++)
hasso1e058382004-09-01 21:36:14 +0000770 {
771 handler = vector_slot (ospf6_lsa_handler_vector, i);
772 if (handler == NULL)
773 continue;
774 if (type && handler->type == type)
775 break;
776 if (! strcasecmp (argv[0], handler->name))
777 break;
778 handler = NULL;
779 }
780
781 if (type && handler == NULL)
782 {
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);
791 }
792
793 if (handler == NULL)
794 handler = &unknown_handler;
795
796 if (argc >= 2)
797 {
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);
804 }
805 else
806 SET_FLAG (handler->debug, OSPF6_LSA_DEBUG);
807
808 return CMD_SUCCESS;
hasso508e53e2004-05-18 18:57:06 +0000809}
810
hasso1e058382004-09-01 21:36:14 +0000811DEFUN (no_debug_ospf6_lsa_type,
812 no_debug_ospf6_lsa_hex_cmd,
813 "no debug ospf6 lsa XXXX/0xXXXX",
814 NO_STR
815 DEBUG_STR
816 OSPF6_STR
817 "Debug Link State Advertisements (LSAs)\n"
818 "Specify LS type as Hexadecimal\n"
819 )
820{
paul0c083ee2004-10-10 12:54:58 +0000821 u_int i;
hasso1e058382004-09-01 21:36:14 +0000822 struct ospf6_lsa_handler *handler = NULL;
823 unsigned long val;
824 char *endptr = NULL;
825 u_int16_t type = 0;
826
827 assert (argc);
828
829 if ((strlen (argv[0]) == 6 && ! strncmp (argv[0], "0x", 2)) ||
830 (strlen (argv[0]) == 4))
831 {
832 val = strtoul (argv[0], &endptr, 16);
833 if (*endptr == '\0')
834 type = val;
835 }
836
paul55468c82005-03-14 20:19:01 +0000837 for (i = 0; i < vector_active (ospf6_lsa_handler_vector); i++)
hasso1e058382004-09-01 21:36:14 +0000838 {
839 handler = vector_slot (ospf6_lsa_handler_vector, i);
840 if (handler == NULL)
841 continue;
842 if (type && handler->type == type)
843 break;
844 if (! strcasecmp (argv[0], handler->name))
845 break;
846 }
847
848 if (handler == NULL)
849 return CMD_SUCCESS;
850
851 if (argc >= 2)
852 {
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);
859 }
860 else
861 UNSET_FLAG (handler->debug, OSPF6_LSA_DEBUG);
862
863 if (handler->debug == 0 &&
Andrew J. Schorre733f942007-06-07 13:11:58 +0000864 !strcmp(handler->name, "Unknown") && type != OSPF6_LSTYPE_UNKNOWN)
hasso1e058382004-09-01 21:36:14 +0000865 {
866 free (handler);
867 vector_slot (ospf6_lsa_handler_vector, i) = NULL;
868 }
869
870 return CMD_SUCCESS;
871}
872
873struct cmd_element debug_ospf6_lsa_type_cmd;
874struct cmd_element debug_ospf6_lsa_type_detail_cmd;
875struct cmd_element no_debug_ospf6_lsa_type_cmd;
876struct cmd_element no_debug_ospf6_lsa_type_detail_cmd;
877
hasso508e53e2004-05-18 18:57:06 +0000878void
Paul Jakma6ac29a52008-08-15 13:45:30 +0100879install_element_ospf6_debug_lsa (void)
hasso508e53e2004-05-18 18:57:06 +0000880{
paul0c083ee2004-10-10 12:54:58 +0000881 u_int i;
hasso1e058382004-09-01 21:36:14 +0000882 struct ospf6_lsa_handler *handler;
883#define STRSIZE 256
884#define DOCSIZE 1024
885 static char strbuf[STRSIZE];
886 static char docbuf[DOCSIZE];
887 static char detail_strbuf[STRSIZE];
888 static char detail_docbuf[DOCSIZE];
889 char *str, *no_str;
890 char *doc, *no_doc;
891
892 strbuf[0] = '\0';
893 no_str = &strbuf[strlen (strbuf)];
894 strncat (strbuf, "no ", STRSIZE - strlen (strbuf));
895 str = &strbuf[strlen (strbuf)];
896
897 strncat (strbuf, "debug ospf6 lsa (", STRSIZE - strlen (strbuf));
paul55468c82005-03-14 20:19:01 +0000898 for (i = 0; i < vector_active (ospf6_lsa_handler_vector); i++)
hasso1e058382004-09-01 21:36:14 +0000899 {
900 handler = vector_slot (ospf6_lsa_handler_vector, i);
901 if (handler == NULL)
902 continue;
903 strncat (strbuf, ospf6_lsa_handler_name (handler),
904 STRSIZE - strlen (strbuf));
905 strncat (strbuf, "|", STRSIZE - strlen (strbuf));
906 }
907 strbuf[strlen (strbuf) - 1] = ')';
908 strbuf[strlen (strbuf)] = '\0';
909
910 docbuf[0] = '\0';
911 no_doc = &docbuf[strlen (docbuf)];
912 strncat (docbuf, NO_STR, DOCSIZE - strlen (docbuf));
913 doc = &docbuf[strlen (docbuf)];
914
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));
919
paul55468c82005-03-14 20:19:01 +0000920 for (i = 0; i < vector_active (ospf6_lsa_handler_vector); i++)
hasso1e058382004-09-01 21:36:14 +0000921 {
922 handler = vector_slot (ospf6_lsa_handler_vector, i);
923 if (handler == NULL)
924 continue;
925 strncat (docbuf, "Debug ", DOCSIZE - strlen (docbuf));
926 strncat (docbuf, handler->name, DOCSIZE - strlen (docbuf));
927 strncat (docbuf, "-LSA\n", DOCSIZE - strlen (docbuf));
928 }
929 docbuf[strlen (docbuf)] = '\0';
930
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;
934
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;
938
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 ")];
945
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)];
956
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;
960
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;
964
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);
977}
978
979int
980config_write_ospf6_debug_lsa (struct vty *vty)
981{
paul0c083ee2004-10-10 12:54:58 +0000982 u_int i;
hasso1e058382004-09-01 21:36:14 +0000983 struct ospf6_lsa_handler *handler;
984
paul55468c82005-03-14 20:19:01 +0000985 for (i = 0; i < vector_active (ospf6_lsa_handler_vector); i++)
hasso1e058382004-09-01 21:36:14 +0000986 {
987 handler = vector_slot (ospf6_lsa_handler_vector, i);
988 if (handler == NULL)
989 continue;
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);
1002 }
1003
1004 return 0;
hasso508e53e2004-05-18 18:57:06 +00001005}
1006
1007