blob: c1db3741bab58c7206ef17d4ae0aeee2e0390ee8 [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{
Ondrej Zajicek64bf3ab2009-12-07 12:33:20 +0300259 int seqnuma, seqnumb;
paul718e3742002-12-13 20:15:29 +0000260 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
Ondrej Zajicek64bf3ab2009-12-07 12:33:20 +0300267 seqnuma = (int) ntohl (a->header->seqnum);
268 seqnumb = (int) ntohl (b->header->seqnum);
paul718e3742002-12-13 20:15:29 +0000269
270 /* compare by sequence number */
paul718e3742002-12-13 20:15:29 +0000271 if (seqnuma > seqnumb)
272 return -1;
Ondrej Zajicek64bf3ab2009-12-07 12:33:20 +0300273 if (seqnuma < seqnumb)
paul718e3742002-12-13 20:15:29 +0000274 return 1;
275
276 /* Checksum */
277 cksuma = ntohs (a->header->checksum);
278 cksumb = ntohs (b->header->checksum);
279 if (cksuma > cksumb)
280 return -1;
281 if (cksuma < cksumb)
282 return 0;
283
hasso508e53e2004-05-18 18:57:06 +0000284 /* Update Age */
paul718e3742002-12-13 20:15:29 +0000285 agea = ospf6_lsa_age_current (a);
286 ageb = ospf6_lsa_age_current (b);
287
hasso508e53e2004-05-18 18:57:06 +0000288 /* MaxAge check */
289 if (agea == MAXAGE && ageb != MAXAGE)
paul718e3742002-12-13 20:15:29 +0000290 return -1;
hasso508e53e2004-05-18 18:57:06 +0000291 else if (agea != MAXAGE && ageb == MAXAGE)
paul718e3742002-12-13 20:15:29 +0000292 return 1;
293
hasso508e53e2004-05-18 18:57:06 +0000294 /* Age check */
295 if (agea > ageb && agea - ageb >= MAX_AGE_DIFF)
paul718e3742002-12-13 20:15:29 +0000296 return 1;
hasso508e53e2004-05-18 18:57:06 +0000297 else if (agea < ageb && ageb - agea >= MAX_AGE_DIFF)
paul718e3742002-12-13 20:15:29 +0000298 return -1;
299
300 /* neither recent */
paul718e3742002-12-13 20:15:29 +0000301 return 0;
302}
303
hasso508e53e2004-05-18 18:57:06 +0000304char *
305ospf6_lsa_printbuf (struct ospf6_lsa *lsa, char *buf, int size)
paul718e3742002-12-13 20:15:29 +0000306{
hasso508e53e2004-05-18 18:57:06 +0000307 char id[16], adv_router[16];
308 inet_ntop (AF_INET, &lsa->header->id, id, sizeof (id));
309 inet_ntop (AF_INET, &lsa->header->adv_router, adv_router,
310 sizeof (adv_router));
311 snprintf (buf, size, "[%s Id:%s Adv:%s]",
hasso1e058382004-09-01 21:36:14 +0000312 ospf6_lstype_name (lsa->header->type), id, adv_router);
hasso508e53e2004-05-18 18:57:06 +0000313 return buf;
paul718e3742002-12-13 20:15:29 +0000314}
315
hasso508e53e2004-05-18 18:57:06 +0000316void
317ospf6_lsa_header_print_raw (struct ospf6_lsa_header *header)
paul718e3742002-12-13 20:15:29 +0000318{
hasso508e53e2004-05-18 18:57:06 +0000319 char id[16], adv_router[16];
320 inet_ntop (AF_INET, &header->id, id, sizeof (id));
321 inet_ntop (AF_INET, &header->adv_router, adv_router,
322 sizeof (adv_router));
hassoc6487d62004-12-24 06:00:11 +0000323 zlog_debug (" [%s Id:%s Adv:%s]",
324 ospf6_lstype_name (header->type), id, adv_router);
325 zlog_debug (" Age: %4hu SeqNum: %#08lx Cksum: %04hx Len: %d",
326 ntohs (header->age), (u_long) ntohl (header->seqnum),
327 ntohs (header->checksum), ntohs (header->length));
paul718e3742002-12-13 20:15:29 +0000328}
329
hasso508e53e2004-05-18 18:57:06 +0000330void
331ospf6_lsa_header_print (struct ospf6_lsa *lsa)
paul718e3742002-12-13 20:15:29 +0000332{
hasso508e53e2004-05-18 18:57:06 +0000333 ospf6_lsa_age_current (lsa);
334 ospf6_lsa_header_print_raw (lsa->header);
paul718e3742002-12-13 20:15:29 +0000335}
336
337void
paul718e3742002-12-13 20:15:29 +0000338ospf6_lsa_show_summary_header (struct vty *vty)
339{
340 vty_out (vty, "%-12s %-15s %-15s %4s %8s %4s %4s %-8s%s",
341 "Type", "LSId", "AdvRouter", "Age", "SeqNum",
hasso049207c2004-08-04 20:02:13 +0000342 "Cksm", "Len", "Duration", VNL);
paul718e3742002-12-13 20:15:29 +0000343}
344
345void
346ospf6_lsa_show_summary (struct vty *vty, struct ospf6_lsa *lsa)
347{
hasso508e53e2004-05-18 18:57:06 +0000348 char adv_router[16], id[16];
paul718e3742002-12-13 20:15:29 +0000349 struct timeval now, res;
350 char duration[16];
351
352 assert (lsa);
353 assert (lsa->header);
354
paul718e3742002-12-13 20:15:29 +0000355 inet_ntop (AF_INET, &lsa->header->id, id, sizeof (id));
356 inet_ntop (AF_INET, &lsa->header->adv_router, adv_router,
357 sizeof (adv_router));
358
Takashi Sogabe86f72dc2009-06-22 13:07:02 +0900359 quagga_gettime (QUAGGA_CLK_MONOTONIC, &now);
hasso508e53e2004-05-18 18:57:06 +0000360 timersub (&now, &lsa->installed, &res);
361 timerstring (&res, duration, sizeof (duration));
paul718e3742002-12-13 20:15:29 +0000362
363 vty_out (vty, "%-12s %-15s %-15s %4hu %8lx %04hx %4hu %8s%s",
hasso1e058382004-09-01 21:36:14 +0000364 ospf6_lstype_name (lsa->header->type),
hasso508e53e2004-05-18 18:57:06 +0000365 id, adv_router, ospf6_lsa_age_current (lsa),
paul718e3742002-12-13 20:15:29 +0000366 (u_long) ntohl (lsa->header->seqnum),
367 ntohs (lsa->header->checksum), ntohs (lsa->header->length),
hasso049207c2004-08-04 20:02:13 +0000368 duration, VNL);
paul718e3742002-12-13 20:15:29 +0000369}
370
371void
372ospf6_lsa_show_dump (struct vty *vty, struct ospf6_lsa *lsa)
373{
374 u_char *start, *end, *current;
375 char byte[4];
376
hasso03d52f82004-09-29 00:26:19 +0000377 start = (u_char *) lsa->header;
378 end = (u_char *) lsa->header + ntohs (lsa->header->length);
paul718e3742002-12-13 20:15:29 +0000379
hasso049207c2004-08-04 20:02:13 +0000380 vty_out (vty, "%s", VNL);
381 vty_out (vty, "%s:%s", lsa->name, VNL);
paul718e3742002-12-13 20:15:29 +0000382
383 for (current = start; current < end; current ++)
384 {
385 if ((current - start) % 16 == 0)
hasso049207c2004-08-04 20:02:13 +0000386 vty_out (vty, "%s ", VNL);
paul718e3742002-12-13 20:15:29 +0000387 else if ((current - start) % 4 == 0)
388 vty_out (vty, " ");
389
390 snprintf (byte, sizeof (byte), "%02x", *current);
391 vty_out (vty, "%s", byte);
392 }
393
hasso049207c2004-08-04 20:02:13 +0000394 vty_out (vty, "%s%s", VNL, VNL);
hasso6452df02004-08-15 05:52:07 +0000395 return;
paul718e3742002-12-13 20:15:29 +0000396}
397
hasso508e53e2004-05-18 18:57:06 +0000398void
399ospf6_lsa_show_internal (struct vty *vty, struct ospf6_lsa *lsa)
400{
401 char adv_router[64], id[64];
402
403 assert (lsa && lsa->header);
404
405 inet_ntop (AF_INET, &lsa->header->id, id, sizeof (id));
406 inet_ntop (AF_INET, &lsa->header->adv_router,
407 adv_router, sizeof (adv_router));
408
hasso049207c2004-08-04 20:02:13 +0000409 vty_out (vty, "%s", VNL);
hasso508e53e2004-05-18 18:57:06 +0000410 vty_out (vty, "Age: %4hu Type: %s%s", ospf6_lsa_age_current (lsa),
hasso1e058382004-09-01 21:36:14 +0000411 ospf6_lstype_name (lsa->header->type), VNL);
hasso049207c2004-08-04 20:02:13 +0000412 vty_out (vty, "Link State ID: %s%s", id, VNL);
413 vty_out (vty, "Advertising Router: %s%s", adv_router, VNL);
hasso508e53e2004-05-18 18:57:06 +0000414 vty_out (vty, "LS Sequence Number: %#010lx%s",
hasso049207c2004-08-04 20:02:13 +0000415 (u_long) ntohl (lsa->header->seqnum), VNL);
hasso508e53e2004-05-18 18:57:06 +0000416 vty_out (vty, "CheckSum: %#06hx Length: %hu%s",
417 ntohs (lsa->header->checksum),
hasso049207c2004-08-04 20:02:13 +0000418 ntohs (lsa->header->length), VNL);
hasso508e53e2004-05-18 18:57:06 +0000419 vty_out (vty, " Prev: %p This: %p Next: %p%s",
hasso049207c2004-08-04 20:02:13 +0000420 lsa->prev, lsa, lsa->next, VNL);
421 vty_out (vty, "%s", VNL);
hasso6452df02004-08-15 05:52:07 +0000422 return;
423}
424
425void
426ospf6_lsa_show (struct vty *vty, struct ospf6_lsa *lsa)
427{
428 char adv_router[64], id[64];
hasso1e058382004-09-01 21:36:14 +0000429 struct ospf6_lsa_handler *handler;
hasso6452df02004-08-15 05:52:07 +0000430
431 assert (lsa && lsa->header);
432
433 inet_ntop (AF_INET, &lsa->header->id, id, sizeof (id));
434 inet_ntop (AF_INET, &lsa->header->adv_router,
435 adv_router, sizeof (adv_router));
436
437 vty_out (vty, "Age: %4hu Type: %s%s", ospf6_lsa_age_current (lsa),
hasso1e058382004-09-01 21:36:14 +0000438 ospf6_lstype_name (lsa->header->type), VNL);
hasso6452df02004-08-15 05:52:07 +0000439 vty_out (vty, "Link State ID: %s%s", id, VNL);
440 vty_out (vty, "Advertising Router: %s%s", adv_router, VNL);
441 vty_out (vty, "LS Sequence Number: %#010lx%s",
442 (u_long) ntohl (lsa->header->seqnum), VNL);
443 vty_out (vty, "CheckSum: %#06hx Length: %hu%s",
444 ntohs (lsa->header->checksum),
445 ntohs (lsa->header->length), VNL);
446
hasso1e058382004-09-01 21:36:14 +0000447 handler = ospf6_get_lsa_handler (lsa->header->type);
448 if (handler->show == NULL)
449 handler = &unknown_handler;
450 (*handler->show) (vty, lsa);
hasso6452df02004-08-15 05:52:07 +0000451
452 vty_out (vty, "%s", VNL);
hasso508e53e2004-05-18 18:57:06 +0000453}
454
paul718e3742002-12-13 20:15:29 +0000455/* OSPFv3 LSA creation/deletion function */
paul718e3742002-12-13 20:15:29 +0000456struct ospf6_lsa *
hasso508e53e2004-05-18 18:57:06 +0000457ospf6_lsa_create (struct ospf6_lsa_header *header)
paul718e3742002-12-13 20:15:29 +0000458{
459 struct ospf6_lsa *lsa = NULL;
hasso508e53e2004-05-18 18:57:06 +0000460 struct ospf6_lsa_header *new_header = NULL;
paul718e3742002-12-13 20:15:29 +0000461 u_int16_t lsa_size = 0;
paul718e3742002-12-13 20:15:29 +0000462
hasso508e53e2004-05-18 18:57:06 +0000463 /* size of the entire LSA */
464 lsa_size = ntohs (header->length); /* XXX vulnerable */
paul718e3742002-12-13 20:15:29 +0000465
466 /* allocate memory for this LSA */
hasso508e53e2004-05-18 18:57:06 +0000467 new_header = (struct ospf6_lsa_header *)
paul718e3742002-12-13 20:15:29 +0000468 XMALLOC (MTYPE_OSPF6_LSA, lsa_size);
paul718e3742002-12-13 20:15:29 +0000469
hasso508e53e2004-05-18 18:57:06 +0000470 /* copy LSA from original header */
471 memcpy (new_header, header, lsa_size);
paul718e3742002-12-13 20:15:29 +0000472
473 /* LSA information structure */
474 /* allocate memory */
475 lsa = (struct ospf6_lsa *)
Stephen Hemminger393deb92008-08-18 14:13:29 -0700476 XCALLOC (MTYPE_OSPF6_LSA, sizeof (struct ospf6_lsa));
paul718e3742002-12-13 20:15:29 +0000477
hasso508e53e2004-05-18 18:57:06 +0000478 lsa->header = (struct ospf6_lsa_header *) new_header;
paul718e3742002-12-13 20:15:29 +0000479
480 /* dump string */
hasso508e53e2004-05-18 18:57:06 +0000481 ospf6_lsa_printbuf (lsa, lsa->name, sizeof (lsa->name));
paul718e3742002-12-13 20:15:29 +0000482
hasso3b687352004-08-19 06:56:53 +0000483 /* calculate birth of this lsa */
paul718e3742002-12-13 20:15:29 +0000484 ospf6_lsa_age_set (lsa);
485
paul718e3742002-12-13 20:15:29 +0000486 return lsa;
487}
488
489struct ospf6_lsa *
hasso508e53e2004-05-18 18:57:06 +0000490ospf6_lsa_create_headeronly (struct ospf6_lsa_header *header)
paul718e3742002-12-13 20:15:29 +0000491{
492 struct ospf6_lsa *lsa = NULL;
hasso508e53e2004-05-18 18:57:06 +0000493 struct ospf6_lsa_header *new_header = NULL;
paul718e3742002-12-13 20:15:29 +0000494
495 /* allocate memory for this LSA */
hasso508e53e2004-05-18 18:57:06 +0000496 new_header = (struct ospf6_lsa_header *)
497 XMALLOC (MTYPE_OSPF6_LSA, sizeof (struct ospf6_lsa_header));
paul718e3742002-12-13 20:15:29 +0000498
hasso508e53e2004-05-18 18:57:06 +0000499 /* copy LSA from original header */
500 memcpy (new_header, header, sizeof (struct ospf6_lsa_header));
paul718e3742002-12-13 20:15:29 +0000501
502 /* LSA information structure */
503 /* allocate memory */
504 lsa = (struct ospf6_lsa *)
Stephen Hemminger393deb92008-08-18 14:13:29 -0700505 XCALLOC (MTYPE_OSPF6_LSA, sizeof (struct ospf6_lsa));
paul718e3742002-12-13 20:15:29 +0000506
hasso508e53e2004-05-18 18:57:06 +0000507 lsa->header = (struct ospf6_lsa_header *) new_header;
hasso6452df02004-08-15 05:52:07 +0000508 SET_FLAG (lsa->flag, OSPF6_LSA_HEADERONLY);
paul718e3742002-12-13 20:15:29 +0000509
510 /* dump string */
hasso508e53e2004-05-18 18:57:06 +0000511 ospf6_lsa_printbuf (lsa, lsa->name, sizeof (lsa->name));
paul718e3742002-12-13 20:15:29 +0000512
hasso3b687352004-08-19 06:56:53 +0000513 /* calculate birth of this lsa */
paul718e3742002-12-13 20:15:29 +0000514 ospf6_lsa_age_set (lsa);
515
paul718e3742002-12-13 20:15:29 +0000516 return lsa;
517}
518
519void
520ospf6_lsa_delete (struct ospf6_lsa *lsa)
521{
hasso508e53e2004-05-18 18:57:06 +0000522 assert (lsa->lock == 0);
paul718e3742002-12-13 20:15:29 +0000523
524 /* cancel threads */
hasso508e53e2004-05-18 18:57:06 +0000525 THREAD_OFF (lsa->expire);
526 THREAD_OFF (lsa->refresh);
paul718e3742002-12-13 20:15:29 +0000527
paul718e3742002-12-13 20:15:29 +0000528 /* do free */
hasso508e53e2004-05-18 18:57:06 +0000529 XFREE (MTYPE_OSPF6_LSA, lsa->header);
530 XFREE (MTYPE_OSPF6_LSA, lsa);
paul718e3742002-12-13 20:15:29 +0000531}
532
hasso508e53e2004-05-18 18:57:06 +0000533struct ospf6_lsa *
534ospf6_lsa_copy (struct ospf6_lsa *lsa)
535{
536 struct ospf6_lsa *copy = NULL;
537
hasso508e53e2004-05-18 18:57:06 +0000538 ospf6_lsa_age_current (lsa);
hasso6452df02004-08-15 05:52:07 +0000539 if (CHECK_FLAG (lsa->flag, OSPF6_LSA_HEADERONLY))
hasso508e53e2004-05-18 18:57:06 +0000540 copy = ospf6_lsa_create_headeronly (lsa->header);
541 else
542 copy = ospf6_lsa_create (lsa->header);
543 assert (copy->lock == 0);
544
hasso3b687352004-08-19 06:56:53 +0000545 copy->birth = lsa->birth;
hasso508e53e2004-05-18 18:57:06 +0000546 copy->originated = lsa->originated;
hassoccb59b12004-08-25 09:10:37 +0000547 copy->received = lsa->received;
548 copy->installed = lsa->installed;
hasso6452df02004-08-15 05:52:07 +0000549 copy->lsdb = lsa->lsdb;
hasso508e53e2004-05-18 18:57:06 +0000550
hasso508e53e2004-05-18 18:57:06 +0000551 return copy;
552}
553
554/* increment reference counter of struct ospf6_lsa */
paul718e3742002-12-13 20:15:29 +0000555void
556ospf6_lsa_lock (struct ospf6_lsa *lsa)
557{
558 lsa->lock++;
559 return;
560}
561
hasso508e53e2004-05-18 18:57:06 +0000562/* decrement reference counter of struct ospf6_lsa */
paul718e3742002-12-13 20:15:29 +0000563void
564ospf6_lsa_unlock (struct ospf6_lsa *lsa)
565{
566 /* decrement reference counter */
hasso508e53e2004-05-18 18:57:06 +0000567 assert (lsa->lock > 0);
568 lsa->lock--;
paul718e3742002-12-13 20:15:29 +0000569
hasso508e53e2004-05-18 18:57:06 +0000570 if (lsa->lock != 0)
571 return;
572
hasso508e53e2004-05-18 18:57:06 +0000573 ospf6_lsa_delete (lsa);
paul718e3742002-12-13 20:15:29 +0000574}
575
paul718e3742002-12-13 20:15:29 +0000576
hasso508e53e2004-05-18 18:57:06 +0000577/* ospf6 lsa expiry */
paul718e3742002-12-13 20:15:29 +0000578int
579ospf6_lsa_expire (struct thread *thread)
580{
581 struct ospf6_lsa *lsa;
paul718e3742002-12-13 20:15:29 +0000582
583 lsa = (struct ospf6_lsa *) THREAD_ARG (thread);
paul718e3742002-12-13 20:15:29 +0000584
hasso508e53e2004-05-18 18:57:06 +0000585 assert (lsa && lsa->header);
586 assert (OSPF6_LSA_IS_MAXAGE (lsa));
587 assert (! lsa->refresh);
paul718e3742002-12-13 20:15:29 +0000588
589 lsa->expire = (struct thread *) NULL;
590
hasso1e058382004-09-01 21:36:14 +0000591 if (IS_OSPF6_DEBUG_LSA_TYPE (lsa->header->type))
paul718e3742002-12-13 20:15:29 +0000592 {
hassoc6487d62004-12-24 06:00:11 +0000593 zlog_debug ("LSA Expire:");
hasso508e53e2004-05-18 18:57:06 +0000594 ospf6_lsa_header_print (lsa);
paul718e3742002-12-13 20:15:29 +0000595 }
596
hasso6452df02004-08-15 05:52:07 +0000597 if (CHECK_FLAG (lsa->flag, OSPF6_LSA_HEADERONLY))
hasso508e53e2004-05-18 18:57:06 +0000598 return 0; /* dbexchange will do something ... */
599
600 /* reflood lsa */
hasso6452df02004-08-15 05:52:07 +0000601 ospf6_flood (NULL, lsa);
hasso508e53e2004-05-18 18:57:06 +0000602
603 /* reinstall lsa */
hasso3b687352004-08-19 06:56:53 +0000604 ospf6_install_lsa (lsa);
hasso508e53e2004-05-18 18:57:06 +0000605
606 /* schedule maxage remover */
607 ospf6_maxage_remove (ospf6);
608
paul718e3742002-12-13 20:15:29 +0000609 return 0;
610}
611
612int
613ospf6_lsa_refresh (struct thread *thread)
614{
hasso6452df02004-08-15 05:52:07 +0000615 struct ospf6_lsa *old, *self, *new;
616 struct ospf6_lsdb *lsdb_self;
paul718e3742002-12-13 20:15:29 +0000617
618 assert (thread);
hasso6452df02004-08-15 05:52:07 +0000619 old = (struct ospf6_lsa *) THREAD_ARG (thread);
620 assert (old && old->header);
paul718e3742002-12-13 20:15:29 +0000621
hasso6452df02004-08-15 05:52:07 +0000622 old->refresh = (struct thread *) NULL;
paul718e3742002-12-13 20:15:29 +0000623
hasso6452df02004-08-15 05:52:07 +0000624 lsdb_self = ospf6_get_scoped_lsdb_self (old);
625 self = ospf6_lsdb_lookup (old->header->type, old->header->id,
626 old->header->adv_router, lsdb_self);
627 if (self == NULL)
628 {
hasso1e058382004-09-01 21:36:14 +0000629 if (IS_OSPF6_DEBUG_LSA_TYPE (old->header->type))
hassoc6487d62004-12-24 06:00:11 +0000630 zlog_debug ("Refresh: could not find self LSA, flush %s", old->name);
hasso6452df02004-08-15 05:52:07 +0000631 ospf6_lsa_premature_aging (old);
632 return 0;
633 }
634
635 /* Reset age, increment LS sequence number. */
636 self->header->age = htons (0);
637 self->header->seqnum =
638 ospf6_new_ls_seqnum (self->header->type, self->header->id,
639 self->header->adv_router, old->lsdb);
640 ospf6_lsa_checksum (self->header);
641
642 new = ospf6_lsa_create (self->header);
643 new->lsdb = old->lsdb;
644 new->refresh = thread_add_timer (master, ospf6_lsa_refresh, new,
645 LS_REFRESH_TIME);
646
647 /* store it in the LSDB for self-originated LSAs */
648 ospf6_lsdb_add (ospf6_lsa_copy (new), lsdb_self);
paul718e3742002-12-13 20:15:29 +0000649
hasso1e058382004-09-01 21:36:14 +0000650 if (IS_OSPF6_DEBUG_LSA_TYPE (new->header->type))
paul718e3742002-12-13 20:15:29 +0000651 {
hassoc6487d62004-12-24 06:00:11 +0000652 zlog_debug ("LSA Refresh:");
hasso6452df02004-08-15 05:52:07 +0000653 ospf6_lsa_header_print (new);
paul718e3742002-12-13 20:15:29 +0000654 }
655
hasso6452df02004-08-15 05:52:07 +0000656 ospf6_flood_clear (old);
657 ospf6_flood (NULL, new);
658 ospf6_install_lsa (new);
659
hasso508e53e2004-05-18 18:57:06 +0000660 return 0;
paul718e3742002-12-13 20:15:29 +0000661}
662
663
664
665/* enhanced Fletcher checksum algorithm, RFC1008 7.2 */
666#define MODX 4102
667#define LSA_CHECKSUM_OFFSET 15
668
669unsigned short
670ospf6_lsa_checksum (struct ospf6_lsa_header *lsa_header)
671{
672 u_char *sp, *ep, *p, *q;
673 int c0 = 0, c1 = 0;
674 int x, y;
675 u_int16_t length;
676
677 lsa_header->checksum = 0;
678 length = ntohs (lsa_header->length) - 2;
hasso03d52f82004-09-29 00:26:19 +0000679 sp = (u_char *) &lsa_header->type;
paul718e3742002-12-13 20:15:29 +0000680
681 for (ep = sp + length; sp < ep; sp = q)
682 {
683 q = sp + MODX;
684 if (q > ep)
685 q = ep;
686 for (p = sp; p < q; p++)
687 {
688 c0 += *p;
689 c1 += c0;
690 }
691 c0 %= 255;
692 c1 %= 255;
693 }
694
695 /* r = (c1 << 8) + c0; */
696 x = ((length - LSA_CHECKSUM_OFFSET) * c0 - c1) % 255;
697 if (x <= 0)
698 x += 255;
699 y = 510 - c0 - x;
700 if (y > 255)
701 y -= 255;
702
703 lsa_header->checksum = htons ((x << 8) + y);
704
705 return (lsa_header->checksum);
706}
707
hasso6452df02004-08-15 05:52:07 +0000708void
Paul Jakma6ac29a52008-08-15 13:45:30 +0100709ospf6_lsa_init (void)
paul718e3742002-12-13 20:15:29 +0000710{
hasso1e058382004-09-01 21:36:14 +0000711 ospf6_lsa_handler_vector = vector_init (0);
hasso6452df02004-08-15 05:52:07 +0000712 ospf6_install_lsa_handler (&unknown_handler);
paul718e3742002-12-13 20:15:29 +0000713}
714
hasso508e53e2004-05-18 18:57:06 +0000715
Paul Jakma6ac29a52008-08-15 13:45:30 +0100716static char *
hasso1e058382004-09-01 21:36:14 +0000717ospf6_lsa_handler_name (struct ospf6_lsa_handler *h)
hasso508e53e2004-05-18 18:57:06 +0000718{
hasso1e058382004-09-01 21:36:14 +0000719 static char buf[64];
paul0c083ee2004-10-10 12:54:58 +0000720 unsigned int i;
721 unsigned int size = strlen (h->name);
hasso508e53e2004-05-18 18:57:06 +0000722
Andrew J. Schorrc32d28b2007-02-27 15:24:36 +0000723 if (!strcmp(h->name, "Unknown") &&
hasso1e058382004-09-01 21:36:14 +0000724 h->type != OSPF6_LSTYPE_UNKNOWN)
hasso508e53e2004-05-18 18:57:06 +0000725 {
hasso1e058382004-09-01 21:36:14 +0000726 snprintf (buf, sizeof (buf), "%#04hx", h->type);
727 return buf;
hasso508e53e2004-05-18 18:57:06 +0000728 }
729
hasso1e058382004-09-01 21:36:14 +0000730 for (i = 0; i < MIN (size, sizeof (buf)); i++)
hasso508e53e2004-05-18 18:57:06 +0000731 {
hasso1e058382004-09-01 21:36:14 +0000732 if (! islower (h->name[i]))
733 buf[i] = tolower (h->name[i]);
hasso508e53e2004-05-18 18:57:06 +0000734 else
hasso1e058382004-09-01 21:36:14 +0000735 buf[i] = h->name[i];
736 }
737 buf[size] = '\0';
738 return buf;
739}
hasso508e53e2004-05-18 18:57:06 +0000740
hasso1e058382004-09-01 21:36:14 +0000741DEFUN (debug_ospf6_lsa_type,
742 debug_ospf6_lsa_hex_cmd,
743 "debug ospf6 lsa XXXX/0xXXXX",
744 DEBUG_STR
745 OSPF6_STR
746 "Debug Link State Advertisements (LSAs)\n"
747 "Specify LS type as Hexadecimal\n"
748 )
749{
paul0c083ee2004-10-10 12:54:58 +0000750 unsigned int i;
hasso1e058382004-09-01 21:36:14 +0000751 struct ospf6_lsa_handler *handler = NULL;
752 unsigned long val;
753 char *endptr = NULL;
754 u_int16_t type = 0;
755
756 assert (argc);
757
758 if ((strlen (argv[0]) == 6 && ! strncmp (argv[0], "0x", 2)) ||
759 (strlen (argv[0]) == 4))
760 {
761 val = strtoul (argv[0], &endptr, 16);
762 if (*endptr == '\0')
763 type = val;
hasso508e53e2004-05-18 18:57:06 +0000764 }
765
paul55468c82005-03-14 20:19:01 +0000766 for (i = 0; i < vector_active (ospf6_lsa_handler_vector); i++)
hasso1e058382004-09-01 21:36:14 +0000767 {
768 handler = vector_slot (ospf6_lsa_handler_vector, i);
769 if (handler == NULL)
770 continue;
771 if (type && handler->type == type)
772 break;
773 if (! strcasecmp (argv[0], handler->name))
774 break;
775 handler = NULL;
776 }
777
778 if (type && handler == NULL)
779 {
780 handler = (struct ospf6_lsa_handler *)
781 malloc (sizeof (struct ospf6_lsa_handler));
782 memset (handler, 0, sizeof (struct ospf6_lsa_handler));
783 handler->type = type;
784 handler->name = "Unknown";
785 handler->show = ospf6_unknown_lsa_show;
786 vector_set_index (ospf6_lsa_handler_vector,
787 handler->type & OSPF6_LSTYPE_FCODE_MASK, handler);
788 }
789
790 if (handler == NULL)
791 handler = &unknown_handler;
792
793 if (argc >= 2)
794 {
795 if (! strcmp (argv[1], "originate"))
796 SET_FLAG (handler->debug, OSPF6_LSA_DEBUG_ORIGINATE);
797 if (! strcmp (argv[1], "examin"))
798 SET_FLAG (handler->debug, OSPF6_LSA_DEBUG_EXAMIN);
799 if (! strcmp (argv[1], "flooding"))
800 SET_FLAG (handler->debug, OSPF6_LSA_DEBUG_FLOOD);
801 }
802 else
803 SET_FLAG (handler->debug, OSPF6_LSA_DEBUG);
804
805 return CMD_SUCCESS;
hasso508e53e2004-05-18 18:57:06 +0000806}
807
hasso1e058382004-09-01 21:36:14 +0000808DEFUN (no_debug_ospf6_lsa_type,
809 no_debug_ospf6_lsa_hex_cmd,
810 "no debug ospf6 lsa XXXX/0xXXXX",
811 NO_STR
812 DEBUG_STR
813 OSPF6_STR
814 "Debug Link State Advertisements (LSAs)\n"
815 "Specify LS type as Hexadecimal\n"
816 )
817{
paul0c083ee2004-10-10 12:54:58 +0000818 u_int i;
hasso1e058382004-09-01 21:36:14 +0000819 struct ospf6_lsa_handler *handler = NULL;
820 unsigned long val;
821 char *endptr = NULL;
822 u_int16_t type = 0;
823
824 assert (argc);
825
826 if ((strlen (argv[0]) == 6 && ! strncmp (argv[0], "0x", 2)) ||
827 (strlen (argv[0]) == 4))
828 {
829 val = strtoul (argv[0], &endptr, 16);
830 if (*endptr == '\0')
831 type = val;
832 }
833
paul55468c82005-03-14 20:19:01 +0000834 for (i = 0; i < vector_active (ospf6_lsa_handler_vector); i++)
hasso1e058382004-09-01 21:36:14 +0000835 {
836 handler = vector_slot (ospf6_lsa_handler_vector, i);
837 if (handler == NULL)
838 continue;
839 if (type && handler->type == type)
840 break;
841 if (! strcasecmp (argv[0], handler->name))
842 break;
843 }
844
845 if (handler == NULL)
846 return CMD_SUCCESS;
847
848 if (argc >= 2)
849 {
850 if (! strcmp (argv[1], "originate"))
851 UNSET_FLAG (handler->debug, OSPF6_LSA_DEBUG_ORIGINATE);
852 if (! strcmp (argv[1], "examin"))
853 UNSET_FLAG (handler->debug, OSPF6_LSA_DEBUG_EXAMIN);
854 if (! strcmp (argv[1], "flooding"))
855 UNSET_FLAG (handler->debug, OSPF6_LSA_DEBUG_FLOOD);
856 }
857 else
858 UNSET_FLAG (handler->debug, OSPF6_LSA_DEBUG);
859
860 if (handler->debug == 0 &&
Andrew J. Schorre733f942007-06-07 13:11:58 +0000861 !strcmp(handler->name, "Unknown") && type != OSPF6_LSTYPE_UNKNOWN)
hasso1e058382004-09-01 21:36:14 +0000862 {
863 free (handler);
864 vector_slot (ospf6_lsa_handler_vector, i) = NULL;
865 }
866
867 return CMD_SUCCESS;
868}
869
870struct cmd_element debug_ospf6_lsa_type_cmd;
871struct cmd_element debug_ospf6_lsa_type_detail_cmd;
872struct cmd_element no_debug_ospf6_lsa_type_cmd;
873struct cmd_element no_debug_ospf6_lsa_type_detail_cmd;
874
hasso508e53e2004-05-18 18:57:06 +0000875void
Paul Jakma6ac29a52008-08-15 13:45:30 +0100876install_element_ospf6_debug_lsa (void)
hasso508e53e2004-05-18 18:57:06 +0000877{
paul0c083ee2004-10-10 12:54:58 +0000878 u_int i;
hasso1e058382004-09-01 21:36:14 +0000879 struct ospf6_lsa_handler *handler;
880#define STRSIZE 256
881#define DOCSIZE 1024
882 static char strbuf[STRSIZE];
883 static char docbuf[DOCSIZE];
884 static char detail_strbuf[STRSIZE];
885 static char detail_docbuf[DOCSIZE];
886 char *str, *no_str;
887 char *doc, *no_doc;
888
889 strbuf[0] = '\0';
890 no_str = &strbuf[strlen (strbuf)];
891 strncat (strbuf, "no ", STRSIZE - strlen (strbuf));
892 str = &strbuf[strlen (strbuf)];
893
894 strncat (strbuf, "debug ospf6 lsa (", STRSIZE - strlen (strbuf));
paul55468c82005-03-14 20:19:01 +0000895 for (i = 0; i < vector_active (ospf6_lsa_handler_vector); i++)
hasso1e058382004-09-01 21:36:14 +0000896 {
897 handler = vector_slot (ospf6_lsa_handler_vector, i);
898 if (handler == NULL)
899 continue;
900 strncat (strbuf, ospf6_lsa_handler_name (handler),
901 STRSIZE - strlen (strbuf));
902 strncat (strbuf, "|", STRSIZE - strlen (strbuf));
903 }
904 strbuf[strlen (strbuf) - 1] = ')';
905 strbuf[strlen (strbuf)] = '\0';
906
907 docbuf[0] = '\0';
908 no_doc = &docbuf[strlen (docbuf)];
909 strncat (docbuf, NO_STR, DOCSIZE - strlen (docbuf));
910 doc = &docbuf[strlen (docbuf)];
911
912 strncat (docbuf, DEBUG_STR, DOCSIZE - strlen (docbuf));
913 strncat (docbuf, OSPF6_STR, DOCSIZE - strlen (docbuf));
914 strncat (docbuf, "Debug Link State Advertisements (LSAs)\n",
915 DOCSIZE - strlen (docbuf));
916
paul55468c82005-03-14 20:19:01 +0000917 for (i = 0; i < vector_active (ospf6_lsa_handler_vector); i++)
hasso1e058382004-09-01 21:36:14 +0000918 {
919 handler = vector_slot (ospf6_lsa_handler_vector, i);
920 if (handler == NULL)
921 continue;
922 strncat (docbuf, "Debug ", DOCSIZE - strlen (docbuf));
923 strncat (docbuf, handler->name, DOCSIZE - strlen (docbuf));
924 strncat (docbuf, "-LSA\n", DOCSIZE - strlen (docbuf));
925 }
926 docbuf[strlen (docbuf)] = '\0';
927
928 debug_ospf6_lsa_type_cmd.string = str;
929 debug_ospf6_lsa_type_cmd.func = debug_ospf6_lsa_type;
930 debug_ospf6_lsa_type_cmd.doc = doc;
931
932 no_debug_ospf6_lsa_type_cmd.string = no_str;
933 no_debug_ospf6_lsa_type_cmd.func = no_debug_ospf6_lsa_type;
934 no_debug_ospf6_lsa_type_cmd.doc = no_doc;
935
936 strncpy (detail_strbuf, strbuf, STRSIZE);
937 strncat (detail_strbuf, " (originate|examin|flooding)",
938 STRSIZE - strlen (detail_strbuf));
939 detail_strbuf[strlen (detail_strbuf)] = '\0';
940 no_str = &detail_strbuf[0];
941 str = &detail_strbuf[strlen ("no ")];
942
943 strncpy (detail_docbuf, docbuf, DOCSIZE);
944 strncat (detail_docbuf, "Debug Originating LSA\n",
945 DOCSIZE - strlen (detail_docbuf));
946 strncat (detail_docbuf, "Debug Examining LSA\n",
947 DOCSIZE - strlen (detail_docbuf));
948 strncat (detail_docbuf, "Debug Flooding LSA\n",
949 DOCSIZE - strlen (detail_docbuf));
950 detail_docbuf[strlen (detail_docbuf)] = '\0';
951 no_doc = &detail_docbuf[0];
952 doc = &detail_docbuf[strlen (NO_STR)];
953
954 debug_ospf6_lsa_type_detail_cmd.string = str;
955 debug_ospf6_lsa_type_detail_cmd.func = debug_ospf6_lsa_type;
956 debug_ospf6_lsa_type_detail_cmd.doc = doc;
957
958 no_debug_ospf6_lsa_type_detail_cmd.string = no_str;
959 no_debug_ospf6_lsa_type_detail_cmd.func = no_debug_ospf6_lsa_type;
960 no_debug_ospf6_lsa_type_detail_cmd.doc = no_doc;
961
962 install_element (ENABLE_NODE, &debug_ospf6_lsa_hex_cmd);
963 install_element (ENABLE_NODE, &debug_ospf6_lsa_type_cmd);
964 install_element (ENABLE_NODE, &debug_ospf6_lsa_type_detail_cmd);
965 install_element (ENABLE_NODE, &no_debug_ospf6_lsa_hex_cmd);
966 install_element (ENABLE_NODE, &no_debug_ospf6_lsa_type_cmd);
967 install_element (ENABLE_NODE, &no_debug_ospf6_lsa_type_detail_cmd);
968 install_element (CONFIG_NODE, &debug_ospf6_lsa_hex_cmd);
969 install_element (CONFIG_NODE, &debug_ospf6_lsa_type_cmd);
970 install_element (CONFIG_NODE, &debug_ospf6_lsa_type_detail_cmd);
971 install_element (CONFIG_NODE, &no_debug_ospf6_lsa_hex_cmd);
972 install_element (CONFIG_NODE, &no_debug_ospf6_lsa_type_cmd);
973 install_element (CONFIG_NODE, &no_debug_ospf6_lsa_type_detail_cmd);
974}
975
976int
977config_write_ospf6_debug_lsa (struct vty *vty)
978{
paul0c083ee2004-10-10 12:54:58 +0000979 u_int i;
hasso1e058382004-09-01 21:36:14 +0000980 struct ospf6_lsa_handler *handler;
981
paul55468c82005-03-14 20:19:01 +0000982 for (i = 0; i < vector_active (ospf6_lsa_handler_vector); i++)
hasso1e058382004-09-01 21:36:14 +0000983 {
984 handler = vector_slot (ospf6_lsa_handler_vector, i);
985 if (handler == NULL)
986 continue;
987 if (CHECK_FLAG (handler->debug, OSPF6_LSA_DEBUG))
988 vty_out (vty, "debug ospf6 lsa %s%s",
989 ospf6_lsa_handler_name (handler), VNL);
990 if (CHECK_FLAG (handler->debug, OSPF6_LSA_DEBUG_ORIGINATE))
991 vty_out (vty, "debug ospf6 lsa %s originate%s",
992 ospf6_lsa_handler_name (handler), VNL);
993 if (CHECK_FLAG (handler->debug, OSPF6_LSA_DEBUG_EXAMIN))
994 vty_out (vty, "debug ospf6 lsa %s examin%s",
995 ospf6_lsa_handler_name (handler), VNL);
996 if (CHECK_FLAG (handler->debug, OSPF6_LSA_DEBUG_FLOOD))
997 vty_out (vty, "debug ospf6 lsa %s flooding%s",
998 ospf6_lsa_handler_name (handler), VNL);
999 }
1000
1001 return 0;
hasso508e53e2004-05-18 18:57:06 +00001002}
1003
1004