blob: ff061dfb1bd1ce10fa6d9ef14714101b0edc0c3d [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"
JR Riversd8a4e422012-09-13 17:17:36 +000032#include "checksum.h"
paul718e3742002-12-13 20:15:29 +000033
34#include "ospf6_proto.h"
paul718e3742002-12-13 20:15:29 +000035#include "ospf6_lsa.h"
36#include "ospf6_lsdb.h"
37#include "ospf6_message.h"
paul718e3742002-12-13 20:15:29 +000038
39#include "ospf6_top.h"
40#include "ospf6_area.h"
41#include "ospf6_interface.h"
42#include "ospf6_neighbor.h"
paul718e3742002-12-13 20:15:29 +000043
hasso508e53e2004-05-18 18:57:06 +000044#include "ospf6_flood.h"
hasso049207c2004-08-04 20:02:13 +000045#include "ospf6d.h"
paul718e3742002-12-13 20:15:29 +000046
hasso1e058382004-09-01 21:36:14 +000047vector ospf6_lsa_handler_vector;
hasso508e53e2004-05-18 18:57:06 +000048
Paul Jakma6ac29a52008-08-15 13:45:30 +010049static int
hasso1e058382004-09-01 21:36:14 +000050ospf6_unknown_lsa_show (struct vty *vty, struct ospf6_lsa *lsa)
51{
52 u_char *start, *end, *current;
53 char byte[4];
hasso508e53e2004-05-18 18:57:06 +000054
hasso03d52f82004-09-29 00:26:19 +000055 start = (u_char *) lsa->header + sizeof (struct ospf6_lsa_header);
56 end = (u_char *) lsa->header + ntohs (lsa->header->length);
hasso1e058382004-09-01 21:36:14 +000057
58 vty_out (vty, " Unknown contents:%s", VNL);
59 for (current = start; current < end; current ++)
60 {
61 if ((current - start) % 16 == 0)
62 vty_out (vty, "%s ", VNL);
63 else if ((current - start) % 4 == 0)
64 vty_out (vty, " ");
65
66 snprintf (byte, sizeof (byte), "%02x", *current);
67 vty_out (vty, "%s", byte);
68 }
69
70 vty_out (vty, "%s%s", VNL, VNL);
71 return 0;
72}
73
74struct ospf6_lsa_handler unknown_handler =
75{
76 OSPF6_LSTYPE_UNKNOWN,
77 "Unknown",
78 ospf6_unknown_lsa_show,
79 OSPF6_LSA_DEBUG,
80};
81
82void
83ospf6_install_lsa_handler (struct ospf6_lsa_handler *handler)
84{
85 /* type in handler is host byte order */
86 int index = handler->type & OSPF6_LSTYPE_FCODE_MASK;
87 vector_set_index (ospf6_lsa_handler_vector, index, handler);
88}
89
90struct ospf6_lsa_handler *
91ospf6_get_lsa_handler (u_int16_t type)
92{
93 struct ospf6_lsa_handler *handler = NULL;
paul0c083ee2004-10-10 12:54:58 +000094 unsigned int index = ntohs (type) & OSPF6_LSTYPE_FCODE_MASK;
hasso1e058382004-09-01 21:36:14 +000095
paul55468c82005-03-14 20:19:01 +000096 if (index >= vector_active (ospf6_lsa_handler_vector))
hasso1e058382004-09-01 21:36:14 +000097 handler = &unknown_handler;
98 else
99 handler = vector_slot (ospf6_lsa_handler_vector, index);
100
hasso2680aa22004-11-25 20:54:46 +0000101 if (handler == NULL)
102 handler = &unknown_handler;
103
hasso1e058382004-09-01 21:36:14 +0000104 return handler;
105}
hasso508e53e2004-05-18 18:57:06 +0000106
paul0c083ee2004-10-10 12:54:58 +0000107const char *
hasso508e53e2004-05-18 18:57:06 +0000108ospf6_lstype_name (u_int16_t type)
paul718e3742002-12-13 20:15:29 +0000109{
hasso508e53e2004-05-18 18:57:06 +0000110 static char buf[8];
hasso1e058382004-09-01 21:36:14 +0000111 struct ospf6_lsa_handler *handler;
paul718e3742002-12-13 20:15:29 +0000112
hasso1e058382004-09-01 21:36:14 +0000113 handler = ospf6_get_lsa_handler (type);
114 if (handler && handler != &unknown_handler)
115 return handler->name;
paul718e3742002-12-13 20:15:29 +0000116
hasso508e53e2004-05-18 18:57:06 +0000117 snprintf (buf, sizeof (buf), "0x%04hx", ntohs (type));
118 return buf;
paul718e3742002-12-13 20:15:29 +0000119}
120
hasso1e058382004-09-01 21:36:14 +0000121u_char
122ospf6_lstype_debug (u_int16_t type)
123{
124 struct ospf6_lsa_handler *handler;
125 handler = ospf6_get_lsa_handler (type);
126 return handler->debug;
127}
128
paul718e3742002-12-13 20:15:29 +0000129/* RFC2328: Section 13.2 */
130int
hasso508e53e2004-05-18 18:57:06 +0000131ospf6_lsa_is_differ (struct ospf6_lsa *lsa1,
132 struct ospf6_lsa *lsa2)
paul718e3742002-12-13 20:15:29 +0000133{
hasso508e53e2004-05-18 18:57:06 +0000134 int len;
paul718e3742002-12-13 20:15:29 +0000135
hasso508e53e2004-05-18 18:57:06 +0000136 assert (OSPF6_LSA_IS_SAME (lsa1, lsa2));
paul718e3742002-12-13 20:15:29 +0000137
hasso508e53e2004-05-18 18:57:06 +0000138 /* XXX, Options ??? */
paul718e3742002-12-13 20:15:29 +0000139
140 ospf6_lsa_age_current (lsa1);
141 ospf6_lsa_age_current (lsa2);
142 if (ntohs (lsa1->header->age) == MAXAGE &&
143 ntohs (lsa2->header->age) != MAXAGE)
144 return 1;
145 if (ntohs (lsa1->header->age) != MAXAGE &&
146 ntohs (lsa2->header->age) == MAXAGE)
147 return 1;
148
149 /* compare body */
150 if (ntohs (lsa1->header->length) != ntohs (lsa2->header->length))
151 return 1;
152
hasso508e53e2004-05-18 18:57:06 +0000153 len = ntohs (lsa1->header->length) - sizeof (struct ospf6_lsa_header);
154 return memcmp (lsa1->header + 1, lsa2->header + 1, len);
paul718e3742002-12-13 20:15:29 +0000155}
156
157int
hasso508e53e2004-05-18 18:57:06 +0000158ospf6_lsa_is_changed (struct ospf6_lsa *lsa1,
159 struct ospf6_lsa *lsa2)
paul718e3742002-12-13 20:15:29 +0000160{
hasso508e53e2004-05-18 18:57:06 +0000161 int length;
paul718e3742002-12-13 20:15:29 +0000162
hasso508e53e2004-05-18 18:57:06 +0000163 if (OSPF6_LSA_IS_MAXAGE (lsa1) ^ OSPF6_LSA_IS_MAXAGE (lsa2))
164 return 1;
165 if (ntohs (lsa1->header->length) != ntohs (lsa2->header->length))
166 return 1;
Denis Ovsienko09395e22011-09-26 13:18:36 +0400167 /* Going beyond LSA headers to compare the payload only makes sense, when both LSAs aren't header-only. */
168 if (CHECK_FLAG (lsa1->flag, OSPF6_LSA_HEADERONLY) != CHECK_FLAG (lsa2->flag, OSPF6_LSA_HEADERONLY))
169 {
170 zlog_warn ("%s: only one of two (%s, %s) LSAs compared is header-only", __func__, lsa1->name, lsa2->name);
171 return 1;
172 }
173 if (CHECK_FLAG (lsa1->flag, OSPF6_LSA_HEADERONLY))
174 return 0;
paul718e3742002-12-13 20:15:29 +0000175
hasso508e53e2004-05-18 18:57:06 +0000176 length = OSPF6_LSA_SIZE (lsa1->header) - sizeof (struct ospf6_lsa_header);
Denis Ovsienko09395e22011-09-26 13:18:36 +0400177 /* Once upper layer verifies LSAs received, length underrun should become a warning. */
178 if (length <= 0)
179 return 0;
paul718e3742002-12-13 20:15:29 +0000180
hasso508e53e2004-05-18 18:57:06 +0000181 return memcmp (OSPF6_LSA_HEADER_END (lsa1->header),
182 OSPF6_LSA_HEADER_END (lsa2->header), length);
paul718e3742002-12-13 20:15:29 +0000183}
184
185/* ospf6 age functions */
hasso3b687352004-08-19 06:56:53 +0000186/* calculate birth */
paul718e3742002-12-13 20:15:29 +0000187static void
188ospf6_lsa_age_set (struct ospf6_lsa *lsa)
189{
190 struct timeval now;
191
192 assert (lsa && lsa->header);
193
Takashi Sogabe86f72dc2009-06-22 13:07:02 +0900194 if (quagga_gettime (QUAGGA_CLK_MONOTONIC, &now) < 0)
195 zlog_warn ("LSA: quagga_gettime failed, may fail LSA AGEs: %s",
ajs6099b3b2004-11-20 02:06:59 +0000196 safe_strerror (errno));
paul718e3742002-12-13 20:15:29 +0000197
198 lsa->birth.tv_sec = now.tv_sec - ntohs (lsa->header->age);
199 lsa->birth.tv_usec = now.tv_usec;
hasso3b687352004-08-19 06:56:53 +0000200
paul718e3742002-12-13 20:15:29 +0000201 return;
202}
203
204/* this function calculates current age from its birth,
205 then update age field of LSA header. return value is current age */
206u_int16_t
207ospf6_lsa_age_current (struct ospf6_lsa *lsa)
208{
209 struct timeval now;
210 u_int32_t ulage;
211 u_int16_t age;
212
213 assert (lsa);
214 assert (lsa->header);
215
216 /* current time */
Takashi Sogabe86f72dc2009-06-22 13:07:02 +0900217 if (quagga_gettime (QUAGGA_CLK_MONOTONIC, &now) < 0)
218 zlog_warn ("LSA: quagga_gettime failed, may fail LSA AGEs: %s",
ajs6099b3b2004-11-20 02:06:59 +0000219 safe_strerror (errno));
paul718e3742002-12-13 20:15:29 +0000220
Tom Hendersonaabbb1a2009-08-28 15:10:00 +0100221 if (ntohs (lsa->header->age) >= MAXAGE)
Tom Henderson9b4ef252009-07-16 17:20:37 +0100222 {
Tom Hendersonaabbb1a2009-08-28 15:10:00 +0100223 /* ospf6_lsa_premature_aging () sets age to MAXAGE; when using
224 relative time, we cannot compare against lsa birth time, so
225 we catch this special case here. */
Tom Henderson9b4ef252009-07-16 17:20:37 +0100226 lsa->header->age = htons (MAXAGE);
227 return MAXAGE;
228 }
paul718e3742002-12-13 20:15:29 +0000229 /* calculate age */
230 ulage = now.tv_sec - lsa->birth.tv_sec;
231
232 /* if over MAXAGE, set to it */
hasso508e53e2004-05-18 18:57:06 +0000233 age = (ulage > MAXAGE ? MAXAGE : ulage);
paul718e3742002-12-13 20:15:29 +0000234
235 lsa->header->age = htons (age);
236 return age;
237}
238
239/* update age field of LSA header with adding InfTransDelay */
240void
241ospf6_lsa_age_update_to_send (struct ospf6_lsa *lsa, u_int32_t transdelay)
242{
243 unsigned short age;
244
245 age = ospf6_lsa_age_current (lsa) + transdelay;
246 if (age > MAXAGE)
247 age = MAXAGE;
248 lsa->header->age = htons (age);
paul718e3742002-12-13 20:15:29 +0000249}
250
251void
252ospf6_lsa_premature_aging (struct ospf6_lsa *lsa)
253{
254 /* log */
hasso1e058382004-09-01 21:36:14 +0000255 if (IS_OSPF6_DEBUG_LSA_TYPE (lsa->header->type))
hassoc6487d62004-12-24 06:00:11 +0000256 zlog_debug ("LSA: Premature aging: %s", lsa->name);
paul718e3742002-12-13 20:15:29 +0000257
hasso508e53e2004-05-18 18:57:06 +0000258 THREAD_OFF (lsa->expire);
259 THREAD_OFF (lsa->refresh);
paul718e3742002-12-13 20:15:29 +0000260
Tom Henderson9b4ef252009-07-16 17:20:37 +0100261 lsa->header->age = htons (MAXAGE);
paul718e3742002-12-13 20:15:29 +0000262 thread_execute (master, ospf6_lsa_expire, lsa, 0);
263}
264
265/* check which is more recent. if a is more recent, return -1;
266 if the same, return 0; otherwise(b is more recent), return 1 */
267int
hasso508e53e2004-05-18 18:57:06 +0000268ospf6_lsa_compare (struct ospf6_lsa *a, struct ospf6_lsa *b)
paul718e3742002-12-13 20:15:29 +0000269{
Ondrej Zajicek64bf3ab2009-12-07 12:33:20 +0300270 int seqnuma, seqnumb;
paul718e3742002-12-13 20:15:29 +0000271 u_int16_t cksuma, cksumb;
272 u_int16_t agea, ageb;
273
274 assert (a && a->header);
275 assert (b && b->header);
hasso508e53e2004-05-18 18:57:06 +0000276 assert (OSPF6_LSA_IS_SAME (a, b));
paul718e3742002-12-13 20:15:29 +0000277
Ondrej Zajicek64bf3ab2009-12-07 12:33:20 +0300278 seqnuma = (int) ntohl (a->header->seqnum);
279 seqnumb = (int) ntohl (b->header->seqnum);
paul718e3742002-12-13 20:15:29 +0000280
281 /* compare by sequence number */
paul718e3742002-12-13 20:15:29 +0000282 if (seqnuma > seqnumb)
283 return -1;
Ondrej Zajicek64bf3ab2009-12-07 12:33:20 +0300284 if (seqnuma < seqnumb)
paul718e3742002-12-13 20:15:29 +0000285 return 1;
286
287 /* Checksum */
288 cksuma = ntohs (a->header->checksum);
289 cksumb = ntohs (b->header->checksum);
290 if (cksuma > cksumb)
291 return -1;
292 if (cksuma < cksumb)
293 return 0;
294
hasso508e53e2004-05-18 18:57:06 +0000295 /* Update Age */
paul718e3742002-12-13 20:15:29 +0000296 agea = ospf6_lsa_age_current (a);
297 ageb = ospf6_lsa_age_current (b);
298
hasso508e53e2004-05-18 18:57:06 +0000299 /* MaxAge check */
300 if (agea == MAXAGE && ageb != MAXAGE)
paul718e3742002-12-13 20:15:29 +0000301 return -1;
hasso508e53e2004-05-18 18:57:06 +0000302 else if (agea != MAXAGE && ageb == MAXAGE)
paul718e3742002-12-13 20:15:29 +0000303 return 1;
304
hasso508e53e2004-05-18 18:57:06 +0000305 /* Age check */
306 if (agea > ageb && agea - ageb >= MAX_AGE_DIFF)
paul718e3742002-12-13 20:15:29 +0000307 return 1;
hasso508e53e2004-05-18 18:57:06 +0000308 else if (agea < ageb && ageb - agea >= MAX_AGE_DIFF)
paul718e3742002-12-13 20:15:29 +0000309 return -1;
310
311 /* neither recent */
paul718e3742002-12-13 20:15:29 +0000312 return 0;
313}
314
hasso508e53e2004-05-18 18:57:06 +0000315char *
316ospf6_lsa_printbuf (struct ospf6_lsa *lsa, char *buf, int size)
paul718e3742002-12-13 20:15:29 +0000317{
hasso508e53e2004-05-18 18:57:06 +0000318 char id[16], adv_router[16];
319 inet_ntop (AF_INET, &lsa->header->id, id, sizeof (id));
320 inet_ntop (AF_INET, &lsa->header->adv_router, adv_router,
321 sizeof (adv_router));
322 snprintf (buf, size, "[%s Id:%s Adv:%s]",
hasso1e058382004-09-01 21:36:14 +0000323 ospf6_lstype_name (lsa->header->type), id, adv_router);
hasso508e53e2004-05-18 18:57:06 +0000324 return buf;
paul718e3742002-12-13 20:15:29 +0000325}
326
hasso508e53e2004-05-18 18:57:06 +0000327void
328ospf6_lsa_header_print_raw (struct ospf6_lsa_header *header)
paul718e3742002-12-13 20:15:29 +0000329{
hasso508e53e2004-05-18 18:57:06 +0000330 char id[16], adv_router[16];
331 inet_ntop (AF_INET, &header->id, id, sizeof (id));
332 inet_ntop (AF_INET, &header->adv_router, adv_router,
333 sizeof (adv_router));
hassoc6487d62004-12-24 06:00:11 +0000334 zlog_debug (" [%s Id:%s Adv:%s]",
335 ospf6_lstype_name (header->type), id, adv_router);
336 zlog_debug (" Age: %4hu SeqNum: %#08lx Cksum: %04hx Len: %d",
337 ntohs (header->age), (u_long) ntohl (header->seqnum),
338 ntohs (header->checksum), ntohs (header->length));
paul718e3742002-12-13 20:15:29 +0000339}
340
hasso508e53e2004-05-18 18:57:06 +0000341void
342ospf6_lsa_header_print (struct ospf6_lsa *lsa)
paul718e3742002-12-13 20:15:29 +0000343{
hasso508e53e2004-05-18 18:57:06 +0000344 ospf6_lsa_age_current (lsa);
345 ospf6_lsa_header_print_raw (lsa->header);
paul718e3742002-12-13 20:15:29 +0000346}
347
348void
paul718e3742002-12-13 20:15:29 +0000349ospf6_lsa_show_summary_header (struct vty *vty)
350{
351 vty_out (vty, "%-12s %-15s %-15s %4s %8s %4s %4s %-8s%s",
352 "Type", "LSId", "AdvRouter", "Age", "SeqNum",
hasso049207c2004-08-04 20:02:13 +0000353 "Cksm", "Len", "Duration", VNL);
paul718e3742002-12-13 20:15:29 +0000354}
355
356void
357ospf6_lsa_show_summary (struct vty *vty, struct ospf6_lsa *lsa)
358{
hasso508e53e2004-05-18 18:57:06 +0000359 char adv_router[16], id[16];
paul718e3742002-12-13 20:15:29 +0000360 struct timeval now, res;
361 char duration[16];
362
363 assert (lsa);
364 assert (lsa->header);
365
paul718e3742002-12-13 20:15:29 +0000366 inet_ntop (AF_INET, &lsa->header->id, id, sizeof (id));
367 inet_ntop (AF_INET, &lsa->header->adv_router, adv_router,
368 sizeof (adv_router));
369
Takashi Sogabe86f72dc2009-06-22 13:07:02 +0900370 quagga_gettime (QUAGGA_CLK_MONOTONIC, &now);
hasso508e53e2004-05-18 18:57:06 +0000371 timersub (&now, &lsa->installed, &res);
372 timerstring (&res, duration, sizeof (duration));
paul718e3742002-12-13 20:15:29 +0000373
374 vty_out (vty, "%-12s %-15s %-15s %4hu %8lx %04hx %4hu %8s%s",
hasso1e058382004-09-01 21:36:14 +0000375 ospf6_lstype_name (lsa->header->type),
hasso508e53e2004-05-18 18:57:06 +0000376 id, adv_router, ospf6_lsa_age_current (lsa),
paul718e3742002-12-13 20:15:29 +0000377 (u_long) ntohl (lsa->header->seqnum),
378 ntohs (lsa->header->checksum), ntohs (lsa->header->length),
hasso049207c2004-08-04 20:02:13 +0000379 duration, VNL);
paul718e3742002-12-13 20:15:29 +0000380}
381
382void
383ospf6_lsa_show_dump (struct vty *vty, struct ospf6_lsa *lsa)
384{
385 u_char *start, *end, *current;
386 char byte[4];
387
hasso03d52f82004-09-29 00:26:19 +0000388 start = (u_char *) lsa->header;
389 end = (u_char *) lsa->header + ntohs (lsa->header->length);
paul718e3742002-12-13 20:15:29 +0000390
hasso049207c2004-08-04 20:02:13 +0000391 vty_out (vty, "%s", VNL);
392 vty_out (vty, "%s:%s", lsa->name, VNL);
paul718e3742002-12-13 20:15:29 +0000393
394 for (current = start; current < end; current ++)
395 {
396 if ((current - start) % 16 == 0)
hasso049207c2004-08-04 20:02:13 +0000397 vty_out (vty, "%s ", VNL);
paul718e3742002-12-13 20:15:29 +0000398 else if ((current - start) % 4 == 0)
399 vty_out (vty, " ");
400
401 snprintf (byte, sizeof (byte), "%02x", *current);
402 vty_out (vty, "%s", byte);
403 }
404
hasso049207c2004-08-04 20:02:13 +0000405 vty_out (vty, "%s%s", VNL, VNL);
hasso6452df02004-08-15 05:52:07 +0000406 return;
paul718e3742002-12-13 20:15:29 +0000407}
408
hasso508e53e2004-05-18 18:57:06 +0000409void
410ospf6_lsa_show_internal (struct vty *vty, struct ospf6_lsa *lsa)
411{
412 char adv_router[64], id[64];
413
414 assert (lsa && lsa->header);
415
416 inet_ntop (AF_INET, &lsa->header->id, id, sizeof (id));
417 inet_ntop (AF_INET, &lsa->header->adv_router,
418 adv_router, sizeof (adv_router));
419
hasso049207c2004-08-04 20:02:13 +0000420 vty_out (vty, "%s", VNL);
hasso508e53e2004-05-18 18:57:06 +0000421 vty_out (vty, "Age: %4hu Type: %s%s", ospf6_lsa_age_current (lsa),
hasso1e058382004-09-01 21:36:14 +0000422 ospf6_lstype_name (lsa->header->type), VNL);
hasso049207c2004-08-04 20:02:13 +0000423 vty_out (vty, "Link State ID: %s%s", id, VNL);
424 vty_out (vty, "Advertising Router: %s%s", adv_router, VNL);
hasso508e53e2004-05-18 18:57:06 +0000425 vty_out (vty, "LS Sequence Number: %#010lx%s",
hasso049207c2004-08-04 20:02:13 +0000426 (u_long) ntohl (lsa->header->seqnum), VNL);
hasso508e53e2004-05-18 18:57:06 +0000427 vty_out (vty, "CheckSum: %#06hx Length: %hu%s",
428 ntohs (lsa->header->checksum),
hasso049207c2004-08-04 20:02:13 +0000429 ntohs (lsa->header->length), VNL);
hasso508e53e2004-05-18 18:57:06 +0000430 vty_out (vty, " Prev: %p This: %p Next: %p%s",
hasso049207c2004-08-04 20:02:13 +0000431 lsa->prev, lsa, lsa->next, VNL);
432 vty_out (vty, "%s", VNL);
hasso6452df02004-08-15 05:52:07 +0000433 return;
434}
435
436void
437ospf6_lsa_show (struct vty *vty, struct ospf6_lsa *lsa)
438{
439 char adv_router[64], id[64];
hasso1e058382004-09-01 21:36:14 +0000440 struct ospf6_lsa_handler *handler;
hasso6452df02004-08-15 05:52:07 +0000441
442 assert (lsa && lsa->header);
443
444 inet_ntop (AF_INET, &lsa->header->id, id, sizeof (id));
445 inet_ntop (AF_INET, &lsa->header->adv_router,
446 adv_router, sizeof (adv_router));
447
448 vty_out (vty, "Age: %4hu Type: %s%s", ospf6_lsa_age_current (lsa),
hasso1e058382004-09-01 21:36:14 +0000449 ospf6_lstype_name (lsa->header->type), VNL);
hasso6452df02004-08-15 05:52:07 +0000450 vty_out (vty, "Link State ID: %s%s", id, VNL);
451 vty_out (vty, "Advertising Router: %s%s", adv_router, VNL);
452 vty_out (vty, "LS Sequence Number: %#010lx%s",
453 (u_long) ntohl (lsa->header->seqnum), VNL);
454 vty_out (vty, "CheckSum: %#06hx Length: %hu%s",
455 ntohs (lsa->header->checksum),
456 ntohs (lsa->header->length), VNL);
457
hasso1e058382004-09-01 21:36:14 +0000458 handler = ospf6_get_lsa_handler (lsa->header->type);
459 if (handler->show == NULL)
460 handler = &unknown_handler;
461 (*handler->show) (vty, lsa);
hasso6452df02004-08-15 05:52:07 +0000462
463 vty_out (vty, "%s", VNL);
hasso508e53e2004-05-18 18:57:06 +0000464}
465
paul718e3742002-12-13 20:15:29 +0000466/* OSPFv3 LSA creation/deletion function */
paul718e3742002-12-13 20:15:29 +0000467struct ospf6_lsa *
hasso508e53e2004-05-18 18:57:06 +0000468ospf6_lsa_create (struct ospf6_lsa_header *header)
paul718e3742002-12-13 20:15:29 +0000469{
470 struct ospf6_lsa *lsa = NULL;
hasso508e53e2004-05-18 18:57:06 +0000471 struct ospf6_lsa_header *new_header = NULL;
paul718e3742002-12-13 20:15:29 +0000472 u_int16_t lsa_size = 0;
paul718e3742002-12-13 20:15:29 +0000473
hasso508e53e2004-05-18 18:57:06 +0000474 /* size of the entire LSA */
475 lsa_size = ntohs (header->length); /* XXX vulnerable */
paul718e3742002-12-13 20:15:29 +0000476
477 /* allocate memory for this LSA */
hasso508e53e2004-05-18 18:57:06 +0000478 new_header = (struct ospf6_lsa_header *)
paul718e3742002-12-13 20:15:29 +0000479 XMALLOC (MTYPE_OSPF6_LSA, lsa_size);
paul718e3742002-12-13 20:15:29 +0000480
hasso508e53e2004-05-18 18:57:06 +0000481 /* copy LSA from original header */
482 memcpy (new_header, header, lsa_size);
paul718e3742002-12-13 20:15:29 +0000483
484 /* LSA information structure */
485 /* allocate memory */
486 lsa = (struct ospf6_lsa *)
Stephen Hemminger393deb92008-08-18 14:13:29 -0700487 XCALLOC (MTYPE_OSPF6_LSA, sizeof (struct ospf6_lsa));
paul718e3742002-12-13 20:15:29 +0000488
hasso508e53e2004-05-18 18:57:06 +0000489 lsa->header = (struct ospf6_lsa_header *) new_header;
paul718e3742002-12-13 20:15:29 +0000490
491 /* dump string */
hasso508e53e2004-05-18 18:57:06 +0000492 ospf6_lsa_printbuf (lsa, lsa->name, sizeof (lsa->name));
paul718e3742002-12-13 20:15:29 +0000493
hasso3b687352004-08-19 06:56:53 +0000494 /* calculate birth of this lsa */
paul718e3742002-12-13 20:15:29 +0000495 ospf6_lsa_age_set (lsa);
496
paul718e3742002-12-13 20:15:29 +0000497 return lsa;
498}
499
500struct ospf6_lsa *
hasso508e53e2004-05-18 18:57:06 +0000501ospf6_lsa_create_headeronly (struct ospf6_lsa_header *header)
paul718e3742002-12-13 20:15:29 +0000502{
503 struct ospf6_lsa *lsa = NULL;
hasso508e53e2004-05-18 18:57:06 +0000504 struct ospf6_lsa_header *new_header = NULL;
paul718e3742002-12-13 20:15:29 +0000505
506 /* allocate memory for this LSA */
hasso508e53e2004-05-18 18:57:06 +0000507 new_header = (struct ospf6_lsa_header *)
508 XMALLOC (MTYPE_OSPF6_LSA, sizeof (struct ospf6_lsa_header));
paul718e3742002-12-13 20:15:29 +0000509
hasso508e53e2004-05-18 18:57:06 +0000510 /* copy LSA from original header */
511 memcpy (new_header, header, sizeof (struct ospf6_lsa_header));
paul718e3742002-12-13 20:15:29 +0000512
513 /* LSA information structure */
514 /* allocate memory */
515 lsa = (struct ospf6_lsa *)
Stephen Hemminger393deb92008-08-18 14:13:29 -0700516 XCALLOC (MTYPE_OSPF6_LSA, sizeof (struct ospf6_lsa));
paul718e3742002-12-13 20:15:29 +0000517
hasso508e53e2004-05-18 18:57:06 +0000518 lsa->header = (struct ospf6_lsa_header *) new_header;
hasso6452df02004-08-15 05:52:07 +0000519 SET_FLAG (lsa->flag, OSPF6_LSA_HEADERONLY);
paul718e3742002-12-13 20:15:29 +0000520
521 /* dump string */
hasso508e53e2004-05-18 18:57:06 +0000522 ospf6_lsa_printbuf (lsa, lsa->name, sizeof (lsa->name));
paul718e3742002-12-13 20:15:29 +0000523
hasso3b687352004-08-19 06:56:53 +0000524 /* calculate birth of this lsa */
paul718e3742002-12-13 20:15:29 +0000525 ospf6_lsa_age_set (lsa);
526
paul718e3742002-12-13 20:15:29 +0000527 return lsa;
528}
529
530void
531ospf6_lsa_delete (struct ospf6_lsa *lsa)
532{
hasso508e53e2004-05-18 18:57:06 +0000533 assert (lsa->lock == 0);
paul718e3742002-12-13 20:15:29 +0000534
535 /* cancel threads */
hasso508e53e2004-05-18 18:57:06 +0000536 THREAD_OFF (lsa->expire);
537 THREAD_OFF (lsa->refresh);
paul718e3742002-12-13 20:15:29 +0000538
paul718e3742002-12-13 20:15:29 +0000539 /* do free */
hasso508e53e2004-05-18 18:57:06 +0000540 XFREE (MTYPE_OSPF6_LSA, lsa->header);
541 XFREE (MTYPE_OSPF6_LSA, lsa);
paul718e3742002-12-13 20:15:29 +0000542}
543
hasso508e53e2004-05-18 18:57:06 +0000544struct ospf6_lsa *
545ospf6_lsa_copy (struct ospf6_lsa *lsa)
546{
547 struct ospf6_lsa *copy = NULL;
548
hasso508e53e2004-05-18 18:57:06 +0000549 ospf6_lsa_age_current (lsa);
hasso6452df02004-08-15 05:52:07 +0000550 if (CHECK_FLAG (lsa->flag, OSPF6_LSA_HEADERONLY))
hasso508e53e2004-05-18 18:57:06 +0000551 copy = ospf6_lsa_create_headeronly (lsa->header);
552 else
553 copy = ospf6_lsa_create (lsa->header);
554 assert (copy->lock == 0);
555
hasso3b687352004-08-19 06:56:53 +0000556 copy->birth = lsa->birth;
hasso508e53e2004-05-18 18:57:06 +0000557 copy->originated = lsa->originated;
hassoccb59b12004-08-25 09:10:37 +0000558 copy->received = lsa->received;
559 copy->installed = lsa->installed;
hasso6452df02004-08-15 05:52:07 +0000560 copy->lsdb = lsa->lsdb;
hasso508e53e2004-05-18 18:57:06 +0000561
hasso508e53e2004-05-18 18:57:06 +0000562 return copy;
563}
564
565/* increment reference counter of struct ospf6_lsa */
paul718e3742002-12-13 20:15:29 +0000566void
567ospf6_lsa_lock (struct ospf6_lsa *lsa)
568{
569 lsa->lock++;
570 return;
571}
572
hasso508e53e2004-05-18 18:57:06 +0000573/* decrement reference counter of struct ospf6_lsa */
paul718e3742002-12-13 20:15:29 +0000574void
575ospf6_lsa_unlock (struct ospf6_lsa *lsa)
576{
577 /* decrement reference counter */
hasso508e53e2004-05-18 18:57:06 +0000578 assert (lsa->lock > 0);
579 lsa->lock--;
paul718e3742002-12-13 20:15:29 +0000580
hasso508e53e2004-05-18 18:57:06 +0000581 if (lsa->lock != 0)
582 return;
583
hasso508e53e2004-05-18 18:57:06 +0000584 ospf6_lsa_delete (lsa);
paul718e3742002-12-13 20:15:29 +0000585}
586
paul718e3742002-12-13 20:15:29 +0000587
hasso508e53e2004-05-18 18:57:06 +0000588/* ospf6 lsa expiry */
paul718e3742002-12-13 20:15:29 +0000589int
590ospf6_lsa_expire (struct thread *thread)
591{
592 struct ospf6_lsa *lsa;
paul718e3742002-12-13 20:15:29 +0000593
594 lsa = (struct ospf6_lsa *) THREAD_ARG (thread);
paul718e3742002-12-13 20:15:29 +0000595
hasso508e53e2004-05-18 18:57:06 +0000596 assert (lsa && lsa->header);
597 assert (OSPF6_LSA_IS_MAXAGE (lsa));
598 assert (! lsa->refresh);
paul718e3742002-12-13 20:15:29 +0000599
600 lsa->expire = (struct thread *) NULL;
601
hasso1e058382004-09-01 21:36:14 +0000602 if (IS_OSPF6_DEBUG_LSA_TYPE (lsa->header->type))
paul718e3742002-12-13 20:15:29 +0000603 {
hassoc6487d62004-12-24 06:00:11 +0000604 zlog_debug ("LSA Expire:");
hasso508e53e2004-05-18 18:57:06 +0000605 ospf6_lsa_header_print (lsa);
paul718e3742002-12-13 20:15:29 +0000606 }
607
hasso6452df02004-08-15 05:52:07 +0000608 if (CHECK_FLAG (lsa->flag, OSPF6_LSA_HEADERONLY))
hasso508e53e2004-05-18 18:57:06 +0000609 return 0; /* dbexchange will do something ... */
610
611 /* reflood lsa */
hasso6452df02004-08-15 05:52:07 +0000612 ospf6_flood (NULL, lsa);
hasso508e53e2004-05-18 18:57:06 +0000613
614 /* reinstall lsa */
hasso3b687352004-08-19 06:56:53 +0000615 ospf6_install_lsa (lsa);
hasso508e53e2004-05-18 18:57:06 +0000616
617 /* schedule maxage remover */
618 ospf6_maxage_remove (ospf6);
619
paul718e3742002-12-13 20:15:29 +0000620 return 0;
621}
622
623int
624ospf6_lsa_refresh (struct thread *thread)
625{
hasso6452df02004-08-15 05:52:07 +0000626 struct ospf6_lsa *old, *self, *new;
627 struct ospf6_lsdb *lsdb_self;
paul718e3742002-12-13 20:15:29 +0000628
629 assert (thread);
hasso6452df02004-08-15 05:52:07 +0000630 old = (struct ospf6_lsa *) THREAD_ARG (thread);
631 assert (old && old->header);
paul718e3742002-12-13 20:15:29 +0000632
hasso6452df02004-08-15 05:52:07 +0000633 old->refresh = (struct thread *) NULL;
paul718e3742002-12-13 20:15:29 +0000634
hasso6452df02004-08-15 05:52:07 +0000635 lsdb_self = ospf6_get_scoped_lsdb_self (old);
636 self = ospf6_lsdb_lookup (old->header->type, old->header->id,
637 old->header->adv_router, lsdb_self);
638 if (self == NULL)
639 {
hasso1e058382004-09-01 21:36:14 +0000640 if (IS_OSPF6_DEBUG_LSA_TYPE (old->header->type))
hassoc6487d62004-12-24 06:00:11 +0000641 zlog_debug ("Refresh: could not find self LSA, flush %s", old->name);
hasso6452df02004-08-15 05:52:07 +0000642 ospf6_lsa_premature_aging (old);
643 return 0;
644 }
645
646 /* Reset age, increment LS sequence number. */
647 self->header->age = htons (0);
648 self->header->seqnum =
649 ospf6_new_ls_seqnum (self->header->type, self->header->id,
650 self->header->adv_router, old->lsdb);
651 ospf6_lsa_checksum (self->header);
652
653 new = ospf6_lsa_create (self->header);
654 new->lsdb = old->lsdb;
655 new->refresh = thread_add_timer (master, ospf6_lsa_refresh, new,
656 LS_REFRESH_TIME);
657
658 /* store it in the LSDB for self-originated LSAs */
659 ospf6_lsdb_add (ospf6_lsa_copy (new), lsdb_self);
paul718e3742002-12-13 20:15:29 +0000660
hasso1e058382004-09-01 21:36:14 +0000661 if (IS_OSPF6_DEBUG_LSA_TYPE (new->header->type))
paul718e3742002-12-13 20:15:29 +0000662 {
hassoc6487d62004-12-24 06:00:11 +0000663 zlog_debug ("LSA Refresh:");
hasso6452df02004-08-15 05:52:07 +0000664 ospf6_lsa_header_print (new);
paul718e3742002-12-13 20:15:29 +0000665 }
666
hasso6452df02004-08-15 05:52:07 +0000667 ospf6_flood_clear (old);
668 ospf6_flood (NULL, new);
669 ospf6_install_lsa (new);
670
hasso508e53e2004-05-18 18:57:06 +0000671 return 0;
paul718e3742002-12-13 20:15:29 +0000672}
673
674
675
JR Riversd8a4e422012-09-13 17:17:36 +0000676/* Fletcher Checksum -- Refer to RFC1008. */
paul718e3742002-12-13 20:15:29 +0000677
JR Riversd8a4e422012-09-13 17:17:36 +0000678/* All the offsets are zero-based. The offsets in the RFC1008 are
679 one-based. */
paul718e3742002-12-13 20:15:29 +0000680unsigned short
681ospf6_lsa_checksum (struct ospf6_lsa_header *lsa_header)
682{
JR Riversd8a4e422012-09-13 17:17:36 +0000683 u_char *buffer = (u_char *) &lsa_header->type;
684 int type_offset = buffer - (u_char *) &lsa_header->age; /* should be 2 */
paul718e3742002-12-13 20:15:29 +0000685
JR Riversd8a4e422012-09-13 17:17:36 +0000686 /* Skip the AGE field */
687 u_int16_t len = ntohs(lsa_header->length) - type_offset;
paul718e3742002-12-13 20:15:29 +0000688
JR Riversd8a4e422012-09-13 17:17:36 +0000689 /* Checksum offset starts from "type" field, not the beginning of the
690 lsa_header struct. The offset is 14, rather than 16. */
691 int checksum_offset = (u_char *) &lsa_header->checksum - buffer;
paul718e3742002-12-13 20:15:29 +0000692
JR Riversd8a4e422012-09-13 17:17:36 +0000693 return (unsigned short)fletcher_checksum(buffer, len, checksum_offset);
694}
paul718e3742002-12-13 20:15:29 +0000695
JR Riversd8a4e422012-09-13 17:17:36 +0000696int
697ospf6_lsa_checksum_valid (struct ospf6_lsa_header *lsa_header)
698{
699 u_char *buffer = (u_char *) &lsa_header->type;
700 int type_offset = buffer - (u_char *) &lsa_header->age; /* should be 2 */
paul718e3742002-12-13 20:15:29 +0000701
JR Riversd8a4e422012-09-13 17:17:36 +0000702 /* Skip the AGE field */
703 u_int16_t len = ntohs(lsa_header->length) - type_offset;
704
705 return (fletcher_checksum(buffer, len, FLETCHER_CHECKSUM_VALIDATE) == 0);
paul718e3742002-12-13 20:15:29 +0000706}
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
Tom Goffae2254a2010-11-10 13:01:41 -0800715void
716ospf6_lsa_terminate (void)
717{
718 vector_free (ospf6_lsa_handler_vector);
719}
hasso508e53e2004-05-18 18:57:06 +0000720
Paul Jakma6ac29a52008-08-15 13:45:30 +0100721static char *
hasso1e058382004-09-01 21:36:14 +0000722ospf6_lsa_handler_name (struct ospf6_lsa_handler *h)
hasso508e53e2004-05-18 18:57:06 +0000723{
hasso1e058382004-09-01 21:36:14 +0000724 static char buf[64];
paul0c083ee2004-10-10 12:54:58 +0000725 unsigned int i;
726 unsigned int size = strlen (h->name);
hasso508e53e2004-05-18 18:57:06 +0000727
Andrew J. Schorrc32d28b2007-02-27 15:24:36 +0000728 if (!strcmp(h->name, "Unknown") &&
hasso1e058382004-09-01 21:36:14 +0000729 h->type != OSPF6_LSTYPE_UNKNOWN)
hasso508e53e2004-05-18 18:57:06 +0000730 {
hasso1e058382004-09-01 21:36:14 +0000731 snprintf (buf, sizeof (buf), "%#04hx", h->type);
732 return buf;
hasso508e53e2004-05-18 18:57:06 +0000733 }
734
hasso1e058382004-09-01 21:36:14 +0000735 for (i = 0; i < MIN (size, sizeof (buf)); i++)
hasso508e53e2004-05-18 18:57:06 +0000736 {
hasso1e058382004-09-01 21:36:14 +0000737 if (! islower (h->name[i]))
738 buf[i] = tolower (h->name[i]);
hasso508e53e2004-05-18 18:57:06 +0000739 else
hasso1e058382004-09-01 21:36:14 +0000740 buf[i] = h->name[i];
741 }
742 buf[size] = '\0';
743 return buf;
744}
hasso508e53e2004-05-18 18:57:06 +0000745
hasso1e058382004-09-01 21:36:14 +0000746DEFUN (debug_ospf6_lsa_type,
747 debug_ospf6_lsa_hex_cmd,
748 "debug ospf6 lsa XXXX/0xXXXX",
749 DEBUG_STR
750 OSPF6_STR
751 "Debug Link State Advertisements (LSAs)\n"
752 "Specify LS type as Hexadecimal\n"
753 )
754{
paul0c083ee2004-10-10 12:54:58 +0000755 unsigned int i;
hasso1e058382004-09-01 21:36:14 +0000756 struct ospf6_lsa_handler *handler = NULL;
757 unsigned long val;
758 char *endptr = NULL;
759 u_int16_t type = 0;
760
761 assert (argc);
762
763 if ((strlen (argv[0]) == 6 && ! strncmp (argv[0], "0x", 2)) ||
764 (strlen (argv[0]) == 4))
765 {
766 val = strtoul (argv[0], &endptr, 16);
767 if (*endptr == '\0')
768 type = val;
hasso508e53e2004-05-18 18:57:06 +0000769 }
770
paul55468c82005-03-14 20:19:01 +0000771 for (i = 0; i < vector_active (ospf6_lsa_handler_vector); i++)
hasso1e058382004-09-01 21:36:14 +0000772 {
773 handler = vector_slot (ospf6_lsa_handler_vector, i);
774 if (handler == NULL)
775 continue;
776 if (type && handler->type == type)
777 break;
778 if (! strcasecmp (argv[0], handler->name))
779 break;
780 handler = NULL;
781 }
782
783 if (type && handler == NULL)
784 {
785 handler = (struct ospf6_lsa_handler *)
786 malloc (sizeof (struct ospf6_lsa_handler));
787 memset (handler, 0, sizeof (struct ospf6_lsa_handler));
788 handler->type = type;
789 handler->name = "Unknown";
790 handler->show = ospf6_unknown_lsa_show;
791 vector_set_index (ospf6_lsa_handler_vector,
792 handler->type & OSPF6_LSTYPE_FCODE_MASK, handler);
793 }
794
795 if (handler == NULL)
796 handler = &unknown_handler;
797
798 if (argc >= 2)
799 {
800 if (! strcmp (argv[1], "originate"))
801 SET_FLAG (handler->debug, OSPF6_LSA_DEBUG_ORIGINATE);
802 if (! strcmp (argv[1], "examin"))
803 SET_FLAG (handler->debug, OSPF6_LSA_DEBUG_EXAMIN);
804 if (! strcmp (argv[1], "flooding"))
805 SET_FLAG (handler->debug, OSPF6_LSA_DEBUG_FLOOD);
806 }
807 else
808 SET_FLAG (handler->debug, OSPF6_LSA_DEBUG);
809
810 return CMD_SUCCESS;
hasso508e53e2004-05-18 18:57:06 +0000811}
812
hasso1e058382004-09-01 21:36:14 +0000813DEFUN (no_debug_ospf6_lsa_type,
814 no_debug_ospf6_lsa_hex_cmd,
815 "no debug ospf6 lsa XXXX/0xXXXX",
816 NO_STR
817 DEBUG_STR
818 OSPF6_STR
819 "Debug Link State Advertisements (LSAs)\n"
820 "Specify LS type as Hexadecimal\n"
821 )
822{
paul0c083ee2004-10-10 12:54:58 +0000823 u_int i;
hasso1e058382004-09-01 21:36:14 +0000824 struct ospf6_lsa_handler *handler = NULL;
825 unsigned long val;
826 char *endptr = NULL;
827 u_int16_t type = 0;
828
829 assert (argc);
830
831 if ((strlen (argv[0]) == 6 && ! strncmp (argv[0], "0x", 2)) ||
832 (strlen (argv[0]) == 4))
833 {
834 val = strtoul (argv[0], &endptr, 16);
835 if (*endptr == '\0')
836 type = val;
837 }
838
paul55468c82005-03-14 20:19:01 +0000839 for (i = 0; i < vector_active (ospf6_lsa_handler_vector); i++)
hasso1e058382004-09-01 21:36:14 +0000840 {
841 handler = vector_slot (ospf6_lsa_handler_vector, i);
842 if (handler == NULL)
843 continue;
844 if (type && handler->type == type)
845 break;
846 if (! strcasecmp (argv[0], handler->name))
847 break;
848 }
849
850 if (handler == NULL)
851 return CMD_SUCCESS;
852
853 if (argc >= 2)
854 {
855 if (! strcmp (argv[1], "originate"))
856 UNSET_FLAG (handler->debug, OSPF6_LSA_DEBUG_ORIGINATE);
857 if (! strcmp (argv[1], "examin"))
858 UNSET_FLAG (handler->debug, OSPF6_LSA_DEBUG_EXAMIN);
859 if (! strcmp (argv[1], "flooding"))
860 UNSET_FLAG (handler->debug, OSPF6_LSA_DEBUG_FLOOD);
861 }
862 else
863 UNSET_FLAG (handler->debug, OSPF6_LSA_DEBUG);
864
865 if (handler->debug == 0 &&
Andrew J. Schorre733f942007-06-07 13:11:58 +0000866 !strcmp(handler->name, "Unknown") && type != OSPF6_LSTYPE_UNKNOWN)
hasso1e058382004-09-01 21:36:14 +0000867 {
868 free (handler);
869 vector_slot (ospf6_lsa_handler_vector, i) = NULL;
870 }
871
872 return CMD_SUCCESS;
873}
874
875struct cmd_element debug_ospf6_lsa_type_cmd;
876struct cmd_element debug_ospf6_lsa_type_detail_cmd;
877struct cmd_element no_debug_ospf6_lsa_type_cmd;
878struct cmd_element no_debug_ospf6_lsa_type_detail_cmd;
879
hasso508e53e2004-05-18 18:57:06 +0000880void
Paul Jakma6ac29a52008-08-15 13:45:30 +0100881install_element_ospf6_debug_lsa (void)
hasso508e53e2004-05-18 18:57:06 +0000882{
paul0c083ee2004-10-10 12:54:58 +0000883 u_int i;
hasso1e058382004-09-01 21:36:14 +0000884 struct ospf6_lsa_handler *handler;
885#define STRSIZE 256
886#define DOCSIZE 1024
887 static char strbuf[STRSIZE];
888 static char docbuf[DOCSIZE];
889 static char detail_strbuf[STRSIZE];
890 static char detail_docbuf[DOCSIZE];
891 char *str, *no_str;
892 char *doc, *no_doc;
893
894 strbuf[0] = '\0';
895 no_str = &strbuf[strlen (strbuf)];
896 strncat (strbuf, "no ", STRSIZE - strlen (strbuf));
897 str = &strbuf[strlen (strbuf)];
898
899 strncat (strbuf, "debug ospf6 lsa (", STRSIZE - strlen (strbuf));
paul55468c82005-03-14 20:19:01 +0000900 for (i = 0; i < vector_active (ospf6_lsa_handler_vector); i++)
hasso1e058382004-09-01 21:36:14 +0000901 {
902 handler = vector_slot (ospf6_lsa_handler_vector, i);
903 if (handler == NULL)
904 continue;
905 strncat (strbuf, ospf6_lsa_handler_name (handler),
906 STRSIZE - strlen (strbuf));
907 strncat (strbuf, "|", STRSIZE - strlen (strbuf));
908 }
909 strbuf[strlen (strbuf) - 1] = ')';
910 strbuf[strlen (strbuf)] = '\0';
911
912 docbuf[0] = '\0';
913 no_doc = &docbuf[strlen (docbuf)];
914 strncat (docbuf, NO_STR, DOCSIZE - strlen (docbuf));
915 doc = &docbuf[strlen (docbuf)];
916
917 strncat (docbuf, DEBUG_STR, DOCSIZE - strlen (docbuf));
918 strncat (docbuf, OSPF6_STR, DOCSIZE - strlen (docbuf));
919 strncat (docbuf, "Debug Link State Advertisements (LSAs)\n",
920 DOCSIZE - strlen (docbuf));
921
paul55468c82005-03-14 20:19:01 +0000922 for (i = 0; i < vector_active (ospf6_lsa_handler_vector); i++)
hasso1e058382004-09-01 21:36:14 +0000923 {
924 handler = vector_slot (ospf6_lsa_handler_vector, i);
925 if (handler == NULL)
926 continue;
927 strncat (docbuf, "Debug ", DOCSIZE - strlen (docbuf));
928 strncat (docbuf, handler->name, DOCSIZE - strlen (docbuf));
929 strncat (docbuf, "-LSA\n", DOCSIZE - strlen (docbuf));
930 }
931 docbuf[strlen (docbuf)] = '\0';
932
933 debug_ospf6_lsa_type_cmd.string = str;
934 debug_ospf6_lsa_type_cmd.func = debug_ospf6_lsa_type;
935 debug_ospf6_lsa_type_cmd.doc = doc;
936
937 no_debug_ospf6_lsa_type_cmd.string = no_str;
938 no_debug_ospf6_lsa_type_cmd.func = no_debug_ospf6_lsa_type;
939 no_debug_ospf6_lsa_type_cmd.doc = no_doc;
940
941 strncpy (detail_strbuf, strbuf, STRSIZE);
942 strncat (detail_strbuf, " (originate|examin|flooding)",
943 STRSIZE - strlen (detail_strbuf));
944 detail_strbuf[strlen (detail_strbuf)] = '\0';
945 no_str = &detail_strbuf[0];
946 str = &detail_strbuf[strlen ("no ")];
947
948 strncpy (detail_docbuf, docbuf, DOCSIZE);
949 strncat (detail_docbuf, "Debug Originating LSA\n",
950 DOCSIZE - strlen (detail_docbuf));
951 strncat (detail_docbuf, "Debug Examining LSA\n",
952 DOCSIZE - strlen (detail_docbuf));
953 strncat (detail_docbuf, "Debug Flooding LSA\n",
954 DOCSIZE - strlen (detail_docbuf));
955 detail_docbuf[strlen (detail_docbuf)] = '\0';
956 no_doc = &detail_docbuf[0];
957 doc = &detail_docbuf[strlen (NO_STR)];
958
959 debug_ospf6_lsa_type_detail_cmd.string = str;
960 debug_ospf6_lsa_type_detail_cmd.func = debug_ospf6_lsa_type;
961 debug_ospf6_lsa_type_detail_cmd.doc = doc;
962
963 no_debug_ospf6_lsa_type_detail_cmd.string = no_str;
964 no_debug_ospf6_lsa_type_detail_cmd.func = no_debug_ospf6_lsa_type;
965 no_debug_ospf6_lsa_type_detail_cmd.doc = no_doc;
966
967 install_element (ENABLE_NODE, &debug_ospf6_lsa_hex_cmd);
968 install_element (ENABLE_NODE, &debug_ospf6_lsa_type_cmd);
969 install_element (ENABLE_NODE, &debug_ospf6_lsa_type_detail_cmd);
970 install_element (ENABLE_NODE, &no_debug_ospf6_lsa_hex_cmd);
971 install_element (ENABLE_NODE, &no_debug_ospf6_lsa_type_cmd);
972 install_element (ENABLE_NODE, &no_debug_ospf6_lsa_type_detail_cmd);
973 install_element (CONFIG_NODE, &debug_ospf6_lsa_hex_cmd);
974 install_element (CONFIG_NODE, &debug_ospf6_lsa_type_cmd);
975 install_element (CONFIG_NODE, &debug_ospf6_lsa_type_detail_cmd);
976 install_element (CONFIG_NODE, &no_debug_ospf6_lsa_hex_cmd);
977 install_element (CONFIG_NODE, &no_debug_ospf6_lsa_type_cmd);
978 install_element (CONFIG_NODE, &no_debug_ospf6_lsa_type_detail_cmd);
979}
980
981int
982config_write_ospf6_debug_lsa (struct vty *vty)
983{
paul0c083ee2004-10-10 12:54:58 +0000984 u_int i;
hasso1e058382004-09-01 21:36:14 +0000985 struct ospf6_lsa_handler *handler;
986
paul55468c82005-03-14 20:19:01 +0000987 for (i = 0; i < vector_active (ospf6_lsa_handler_vector); i++)
hasso1e058382004-09-01 21:36:14 +0000988 {
989 handler = vector_slot (ospf6_lsa_handler_vector, i);
990 if (handler == NULL)
991 continue;
992 if (CHECK_FLAG (handler->debug, OSPF6_LSA_DEBUG))
993 vty_out (vty, "debug ospf6 lsa %s%s",
994 ospf6_lsa_handler_name (handler), VNL);
995 if (CHECK_FLAG (handler->debug, OSPF6_LSA_DEBUG_ORIGINATE))
996 vty_out (vty, "debug ospf6 lsa %s originate%s",
997 ospf6_lsa_handler_name (handler), VNL);
998 if (CHECK_FLAG (handler->debug, OSPF6_LSA_DEBUG_EXAMIN))
999 vty_out (vty, "debug ospf6 lsa %s examin%s",
1000 ospf6_lsa_handler_name (handler), VNL);
1001 if (CHECK_FLAG (handler->debug, OSPF6_LSA_DEBUG_FLOOD))
1002 vty_out (vty, "debug ospf6 lsa %s flooding%s",
1003 ospf6_lsa_handler_name (handler), VNL);
1004 }
1005
1006 return 0;
hasso508e53e2004-05-18 18:57:06 +00001007}
1008
1009