blob: 2e6153557d175cbaf8be3994ce0b5b9de1a64e5d [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,
Dinesh Dutte68a6762013-08-25 03:03:23 +000077 "Unknown",
78 "Unk",
hasso1e058382004-09-01 21:36:14 +000079 ospf6_unknown_lsa_show,
Dinesh Dutte68a6762013-08-25 03:03:23 +000080 NULL,
hasso1e058382004-09-01 21:36:14 +000081 OSPF6_LSA_DEBUG,
82};
83
84void
85ospf6_install_lsa_handler (struct ospf6_lsa_handler *handler)
86{
87 /* type in handler is host byte order */
88 int index = handler->type & OSPF6_LSTYPE_FCODE_MASK;
89 vector_set_index (ospf6_lsa_handler_vector, index, handler);
90}
91
92struct ospf6_lsa_handler *
93ospf6_get_lsa_handler (u_int16_t type)
94{
95 struct ospf6_lsa_handler *handler = NULL;
paul0c083ee2004-10-10 12:54:58 +000096 unsigned int index = ntohs (type) & OSPF6_LSTYPE_FCODE_MASK;
hasso1e058382004-09-01 21:36:14 +000097
paul55468c82005-03-14 20:19:01 +000098 if (index >= vector_active (ospf6_lsa_handler_vector))
hasso1e058382004-09-01 21:36:14 +000099 handler = &unknown_handler;
100 else
101 handler = vector_slot (ospf6_lsa_handler_vector, index);
102
hasso2680aa22004-11-25 20:54:46 +0000103 if (handler == NULL)
104 handler = &unknown_handler;
105
hasso1e058382004-09-01 21:36:14 +0000106 return handler;
107}
hasso508e53e2004-05-18 18:57:06 +0000108
paul0c083ee2004-10-10 12:54:58 +0000109const char *
hasso508e53e2004-05-18 18:57:06 +0000110ospf6_lstype_name (u_int16_t type)
paul718e3742002-12-13 20:15:29 +0000111{
hasso508e53e2004-05-18 18:57:06 +0000112 static char buf[8];
hasso1e058382004-09-01 21:36:14 +0000113 struct ospf6_lsa_handler *handler;
paul718e3742002-12-13 20:15:29 +0000114
hasso1e058382004-09-01 21:36:14 +0000115 handler = ospf6_get_lsa_handler (type);
116 if (handler && handler != &unknown_handler)
117 return handler->name;
paul718e3742002-12-13 20:15:29 +0000118
hasso508e53e2004-05-18 18:57:06 +0000119 snprintf (buf, sizeof (buf), "0x%04hx", ntohs (type));
120 return buf;
paul718e3742002-12-13 20:15:29 +0000121}
122
Dinesh Dutte68a6762013-08-25 03:03:23 +0000123const char *
124ospf6_lstype_short_name (u_int16_t type)
125{
126 static char buf[8];
127 struct ospf6_lsa_handler *handler;
128
129 handler = ospf6_get_lsa_handler (type);
130 if (handler && handler != &unknown_handler)
131 return handler->short_name;
132
133 snprintf (buf, sizeof (buf), "0x%04hx", ntohs (type));
134 return buf;
135}
136
hasso1e058382004-09-01 21:36:14 +0000137u_char
138ospf6_lstype_debug (u_int16_t type)
139{
140 struct ospf6_lsa_handler *handler;
141 handler = ospf6_get_lsa_handler (type);
142 return handler->debug;
143}
144
paul718e3742002-12-13 20:15:29 +0000145/* RFC2328: Section 13.2 */
146int
hasso508e53e2004-05-18 18:57:06 +0000147ospf6_lsa_is_differ (struct ospf6_lsa *lsa1,
148 struct ospf6_lsa *lsa2)
paul718e3742002-12-13 20:15:29 +0000149{
hasso508e53e2004-05-18 18:57:06 +0000150 int len;
paul718e3742002-12-13 20:15:29 +0000151
hasso508e53e2004-05-18 18:57:06 +0000152 assert (OSPF6_LSA_IS_SAME (lsa1, lsa2));
paul718e3742002-12-13 20:15:29 +0000153
hasso508e53e2004-05-18 18:57:06 +0000154 /* XXX, Options ??? */
paul718e3742002-12-13 20:15:29 +0000155
156 ospf6_lsa_age_current (lsa1);
157 ospf6_lsa_age_current (lsa2);
Dinesh Dutt8551e6d2013-10-22 17:42:18 -0700158 if (ntohs (lsa1->header->age) == OSPF_LSA_MAXAGE &&
159 ntohs (lsa2->header->age) != OSPF_LSA_MAXAGE)
paul718e3742002-12-13 20:15:29 +0000160 return 1;
Dinesh Dutt8551e6d2013-10-22 17:42:18 -0700161 if (ntohs (lsa1->header->age) != OSPF_LSA_MAXAGE &&
162 ntohs (lsa2->header->age) == OSPF_LSA_MAXAGE)
paul718e3742002-12-13 20:15:29 +0000163 return 1;
164
165 /* compare body */
166 if (ntohs (lsa1->header->length) != ntohs (lsa2->header->length))
167 return 1;
168
hasso508e53e2004-05-18 18:57:06 +0000169 len = ntohs (lsa1->header->length) - sizeof (struct ospf6_lsa_header);
170 return memcmp (lsa1->header + 1, lsa2->header + 1, len);
paul718e3742002-12-13 20:15:29 +0000171}
172
173int
hasso508e53e2004-05-18 18:57:06 +0000174ospf6_lsa_is_changed (struct ospf6_lsa *lsa1,
175 struct ospf6_lsa *lsa2)
paul718e3742002-12-13 20:15:29 +0000176{
hasso508e53e2004-05-18 18:57:06 +0000177 int length;
paul718e3742002-12-13 20:15:29 +0000178
hasso508e53e2004-05-18 18:57:06 +0000179 if (OSPF6_LSA_IS_MAXAGE (lsa1) ^ OSPF6_LSA_IS_MAXAGE (lsa2))
180 return 1;
181 if (ntohs (lsa1->header->length) != ntohs (lsa2->header->length))
182 return 1;
Denis Ovsienko09395e22011-09-26 13:18:36 +0400183 /* Going beyond LSA headers to compare the payload only makes sense, when both LSAs aren't header-only. */
184 if (CHECK_FLAG (lsa1->flag, OSPF6_LSA_HEADERONLY) != CHECK_FLAG (lsa2->flag, OSPF6_LSA_HEADERONLY))
185 {
186 zlog_warn ("%s: only one of two (%s, %s) LSAs compared is header-only", __func__, lsa1->name, lsa2->name);
187 return 1;
188 }
189 if (CHECK_FLAG (lsa1->flag, OSPF6_LSA_HEADERONLY))
190 return 0;
paul718e3742002-12-13 20:15:29 +0000191
hasso508e53e2004-05-18 18:57:06 +0000192 length = OSPF6_LSA_SIZE (lsa1->header) - sizeof (struct ospf6_lsa_header);
Denis Ovsienko09395e22011-09-26 13:18:36 +0400193 /* Once upper layer verifies LSAs received, length underrun should become a warning. */
194 if (length <= 0)
195 return 0;
paul718e3742002-12-13 20:15:29 +0000196
hasso508e53e2004-05-18 18:57:06 +0000197 return memcmp (OSPF6_LSA_HEADER_END (lsa1->header),
198 OSPF6_LSA_HEADER_END (lsa2->header), length);
paul718e3742002-12-13 20:15:29 +0000199}
200
201/* ospf6 age functions */
hasso3b687352004-08-19 06:56:53 +0000202/* calculate birth */
paul718e3742002-12-13 20:15:29 +0000203static void
204ospf6_lsa_age_set (struct ospf6_lsa *lsa)
205{
206 struct timeval now;
207
208 assert (lsa && lsa->header);
209
Takashi Sogabe86f72dc2009-06-22 13:07:02 +0900210 if (quagga_gettime (QUAGGA_CLK_MONOTONIC, &now) < 0)
211 zlog_warn ("LSA: quagga_gettime failed, may fail LSA AGEs: %s",
ajs6099b3b2004-11-20 02:06:59 +0000212 safe_strerror (errno));
paul718e3742002-12-13 20:15:29 +0000213
214 lsa->birth.tv_sec = now.tv_sec - ntohs (lsa->header->age);
215 lsa->birth.tv_usec = now.tv_usec;
hasso3b687352004-08-19 06:56:53 +0000216
paul718e3742002-12-13 20:15:29 +0000217 return;
218}
219
220/* this function calculates current age from its birth,
221 then update age field of LSA header. return value is current age */
222u_int16_t
223ospf6_lsa_age_current (struct ospf6_lsa *lsa)
224{
225 struct timeval now;
226 u_int32_t ulage;
227 u_int16_t age;
228
229 assert (lsa);
230 assert (lsa->header);
231
232 /* current time */
Takashi Sogabe86f72dc2009-06-22 13:07:02 +0900233 if (quagga_gettime (QUAGGA_CLK_MONOTONIC, &now) < 0)
234 zlog_warn ("LSA: quagga_gettime failed, may fail LSA AGEs: %s",
ajs6099b3b2004-11-20 02:06:59 +0000235 safe_strerror (errno));
paul718e3742002-12-13 20:15:29 +0000236
Dinesh Dutt8551e6d2013-10-22 17:42:18 -0700237 if (ntohs (lsa->header->age) >= OSPF_LSA_MAXAGE)
Tom Henderson9b4ef252009-07-16 17:20:37 +0100238 {
Tom Hendersonaabbb1a2009-08-28 15:10:00 +0100239 /* ospf6_lsa_premature_aging () sets age to MAXAGE; when using
240 relative time, we cannot compare against lsa birth time, so
241 we catch this special case here. */
Dinesh Dutt8551e6d2013-10-22 17:42:18 -0700242 lsa->header->age = htons (OSPF_LSA_MAXAGE);
243 return OSPF_LSA_MAXAGE;
Tom Henderson9b4ef252009-07-16 17:20:37 +0100244 }
paul718e3742002-12-13 20:15:29 +0000245 /* calculate age */
246 ulage = now.tv_sec - lsa->birth.tv_sec;
247
248 /* if over MAXAGE, set to it */
Dinesh Dutt8551e6d2013-10-22 17:42:18 -0700249 age = (ulage > OSPF_LSA_MAXAGE ? OSPF_LSA_MAXAGE : ulage);
paul718e3742002-12-13 20:15:29 +0000250
251 lsa->header->age = htons (age);
252 return age;
253}
254
255/* update age field of LSA header with adding InfTransDelay */
256void
257ospf6_lsa_age_update_to_send (struct ospf6_lsa *lsa, u_int32_t transdelay)
258{
259 unsigned short age;
260
261 age = ospf6_lsa_age_current (lsa) + transdelay;
Dinesh Dutt8551e6d2013-10-22 17:42:18 -0700262 if (age > OSPF_LSA_MAXAGE)
263 age = OSPF_LSA_MAXAGE;
paul718e3742002-12-13 20:15:29 +0000264 lsa->header->age = htons (age);
paul718e3742002-12-13 20:15:29 +0000265}
266
267void
268ospf6_lsa_premature_aging (struct ospf6_lsa *lsa)
269{
270 /* log */
hasso1e058382004-09-01 21:36:14 +0000271 if (IS_OSPF6_DEBUG_LSA_TYPE (lsa->header->type))
hassoc6487d62004-12-24 06:00:11 +0000272 zlog_debug ("LSA: Premature aging: %s", lsa->name);
paul718e3742002-12-13 20:15:29 +0000273
hasso508e53e2004-05-18 18:57:06 +0000274 THREAD_OFF (lsa->expire);
275 THREAD_OFF (lsa->refresh);
paul718e3742002-12-13 20:15:29 +0000276
Dinesh Duttac58e142013-08-24 07:54:24 +0000277 /*
278 * We clear the LSA from the neighbor retx lists now because it
279 * will not get deleted later. Essentially, changing the age to
280 * MaxAge will prevent this LSA from being matched with its
281 * existing entries in the retx list thereby causing those entries
282 * to be silently replaced with its MaxAged version, but with ever
283 * increasing retx count causing this LSA to remain forever and
284 * for the MaxAge remover thread to be called forever too.
285 *
286 * The reason the previous entry silently disappears is that when
287 * entry is added to a neighbor's retx list, it replaces the existing
288 * entry. But since the ospf6_lsdb_add() routine is generic and not aware
289 * of the special semantics of retx count, the retx count is not
290 * decremented when its replaced. Attempting to add the incr and decr
291 * retx count routines as the hook_add and hook_remove for the retx lists
292 * have a problem because the hook_remove routine is called for MaxAge
293 * entries (as will be the case in a traditional LSDB, unlike in this case
294 * where an LSDB is used as an efficient tree structure to store all kinds
295 * of data) that are added instead of calling the hook_add routine.
296 */
297
298 ospf6_flood_clear (lsa);
299
Dinesh Dutt8551e6d2013-10-22 17:42:18 -0700300 lsa->header->age = htons (OSPF_LSA_MAXAGE);
paul718e3742002-12-13 20:15:29 +0000301 thread_execute (master, ospf6_lsa_expire, lsa, 0);
302}
303
304/* check which is more recent. if a is more recent, return -1;
305 if the same, return 0; otherwise(b is more recent), return 1 */
306int
hasso508e53e2004-05-18 18:57:06 +0000307ospf6_lsa_compare (struct ospf6_lsa *a, struct ospf6_lsa *b)
paul718e3742002-12-13 20:15:29 +0000308{
Ondrej Zajicek64bf3ab2009-12-07 12:33:20 +0300309 int seqnuma, seqnumb;
paul718e3742002-12-13 20:15:29 +0000310 u_int16_t cksuma, cksumb;
311 u_int16_t agea, ageb;
312
313 assert (a && a->header);
314 assert (b && b->header);
hasso508e53e2004-05-18 18:57:06 +0000315 assert (OSPF6_LSA_IS_SAME (a, b));
paul718e3742002-12-13 20:15:29 +0000316
Ondrej Zajicek64bf3ab2009-12-07 12:33:20 +0300317 seqnuma = (int) ntohl (a->header->seqnum);
318 seqnumb = (int) ntohl (b->header->seqnum);
paul718e3742002-12-13 20:15:29 +0000319
320 /* compare by sequence number */
paul718e3742002-12-13 20:15:29 +0000321 if (seqnuma > seqnumb)
322 return -1;
Ondrej Zajicek64bf3ab2009-12-07 12:33:20 +0300323 if (seqnuma < seqnumb)
paul718e3742002-12-13 20:15:29 +0000324 return 1;
325
326 /* Checksum */
327 cksuma = ntohs (a->header->checksum);
328 cksumb = ntohs (b->header->checksum);
329 if (cksuma > cksumb)
330 return -1;
331 if (cksuma < cksumb)
332 return 0;
333
hasso508e53e2004-05-18 18:57:06 +0000334 /* Update Age */
paul718e3742002-12-13 20:15:29 +0000335 agea = ospf6_lsa_age_current (a);
336 ageb = ospf6_lsa_age_current (b);
337
hasso508e53e2004-05-18 18:57:06 +0000338 /* MaxAge check */
Dinesh Dutt8551e6d2013-10-22 17:42:18 -0700339 if (agea == OSPF_LSA_MAXAGE && ageb != OSPF_LSA_MAXAGE)
paul718e3742002-12-13 20:15:29 +0000340 return -1;
Dinesh Dutt8551e6d2013-10-22 17:42:18 -0700341 else if (agea != OSPF_LSA_MAXAGE && ageb == OSPF_LSA_MAXAGE)
paul718e3742002-12-13 20:15:29 +0000342 return 1;
343
hasso508e53e2004-05-18 18:57:06 +0000344 /* Age check */
Dinesh Dutt8551e6d2013-10-22 17:42:18 -0700345 if (agea > ageb && agea - ageb >= OSPF_LSA_MAXAGE_DIFF)
paul718e3742002-12-13 20:15:29 +0000346 return 1;
Dinesh Dutt8551e6d2013-10-22 17:42:18 -0700347 else if (agea < ageb && ageb - agea >= OSPF_LSA_MAXAGE_DIFF)
paul718e3742002-12-13 20:15:29 +0000348 return -1;
349
350 /* neither recent */
paul718e3742002-12-13 20:15:29 +0000351 return 0;
352}
353
hasso508e53e2004-05-18 18:57:06 +0000354char *
355ospf6_lsa_printbuf (struct ospf6_lsa *lsa, char *buf, int size)
paul718e3742002-12-13 20:15:29 +0000356{
hasso508e53e2004-05-18 18:57:06 +0000357 char id[16], adv_router[16];
358 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 snprintf (buf, size, "[%s Id:%s Adv:%s]",
hasso1e058382004-09-01 21:36:14 +0000362 ospf6_lstype_name (lsa->header->type), id, adv_router);
hasso508e53e2004-05-18 18:57:06 +0000363 return buf;
paul718e3742002-12-13 20:15:29 +0000364}
365
hasso508e53e2004-05-18 18:57:06 +0000366void
367ospf6_lsa_header_print_raw (struct ospf6_lsa_header *header)
paul718e3742002-12-13 20:15:29 +0000368{
hasso508e53e2004-05-18 18:57:06 +0000369 char id[16], adv_router[16];
370 inet_ntop (AF_INET, &header->id, id, sizeof (id));
371 inet_ntop (AF_INET, &header->adv_router, adv_router,
372 sizeof (adv_router));
hassoc6487d62004-12-24 06:00:11 +0000373 zlog_debug (" [%s Id:%s Adv:%s]",
374 ospf6_lstype_name (header->type), id, adv_router);
375 zlog_debug (" Age: %4hu SeqNum: %#08lx Cksum: %04hx Len: %d",
376 ntohs (header->age), (u_long) ntohl (header->seqnum),
377 ntohs (header->checksum), ntohs (header->length));
paul718e3742002-12-13 20:15:29 +0000378}
379
hasso508e53e2004-05-18 18:57:06 +0000380void
381ospf6_lsa_header_print (struct ospf6_lsa *lsa)
paul718e3742002-12-13 20:15:29 +0000382{
hasso508e53e2004-05-18 18:57:06 +0000383 ospf6_lsa_age_current (lsa);
384 ospf6_lsa_header_print_raw (lsa->header);
paul718e3742002-12-13 20:15:29 +0000385}
386
387void
paul718e3742002-12-13 20:15:29 +0000388ospf6_lsa_show_summary_header (struct vty *vty)
389{
Dinesh Dutte68a6762013-08-25 03:03:23 +0000390 vty_out (vty, "%-4s %-15s%-15s%4s %8s %30s%s",
paul718e3742002-12-13 20:15:29 +0000391 "Type", "LSId", "AdvRouter", "Age", "SeqNum",
Dinesh Dutte68a6762013-08-25 03:03:23 +0000392 "Payload", VNL);
paul718e3742002-12-13 20:15:29 +0000393}
394
395void
396ospf6_lsa_show_summary (struct vty *vty, struct ospf6_lsa *lsa)
397{
hasso508e53e2004-05-18 18:57:06 +0000398 char adv_router[16], id[16];
Dinesh Dutte68a6762013-08-25 03:03:23 +0000399 int type;
400 struct ospf6_lsa_handler *handler;
401 char buf[64], tmpbuf[80];
402 int cnt = 0;
paul718e3742002-12-13 20:15:29 +0000403
404 assert (lsa);
405 assert (lsa->header);
406
paul718e3742002-12-13 20:15:29 +0000407 inet_ntop (AF_INET, &lsa->header->id, id, sizeof (id));
408 inet_ntop (AF_INET, &lsa->header->adv_router, adv_router,
409 sizeof (adv_router));
410
Dinesh Dutte68a6762013-08-25 03:03:23 +0000411 type = ntohs(lsa->header->type);
412 handler = ospf6_get_lsa_handler (lsa->header->type);
413 if ((type == OSPF6_LSTYPE_INTER_PREFIX) ||
414 (type == OSPF6_LSTYPE_INTER_ROUTER) ||
415 (type == OSPF6_LSTYPE_AS_EXTERNAL))
416 {
417 vty_out (vty, "%-4s %-15s%-15s%4hu %8lx %30s%s",
418 ospf6_lstype_short_name (lsa->header->type),
419 id, adv_router, ospf6_lsa_age_current (lsa),
420 (u_long) ntohl (lsa->header->seqnum),
421 handler->get_prefix_str(lsa, buf, sizeof(buf), 0), VNL);
422 }
423 else if (type != OSPF6_LSTYPE_UNKNOWN)
424 {
425 sprintf (tmpbuf, "%-4s %-15s%-15s%4hu %8lx",
426 ospf6_lstype_short_name (lsa->header->type),
427 id, adv_router, ospf6_lsa_age_current (lsa),
428 (u_long) ntohl (lsa->header->seqnum));
paul718e3742002-12-13 20:15:29 +0000429
Dinesh Dutte68a6762013-08-25 03:03:23 +0000430 while (handler->get_prefix_str(lsa, buf, sizeof(buf), cnt) != NULL)
431 {
432 vty_out (vty, "%s %30s%s", tmpbuf, buf, VNL);
433 cnt++;
434 }
435 }
436 else
437 {
438 vty_out (vty, "%-4s %-15s%-15s%4hu %8lx%s",
439 ospf6_lstype_short_name (lsa->header->type),
440 id, adv_router, ospf6_lsa_age_current (lsa),
441 (u_long) ntohl (lsa->header->seqnum), VNL);
442 }
paul718e3742002-12-13 20:15:29 +0000443}
444
445void
446ospf6_lsa_show_dump (struct vty *vty, struct ospf6_lsa *lsa)
447{
448 u_char *start, *end, *current;
449 char byte[4];
450
hasso03d52f82004-09-29 00:26:19 +0000451 start = (u_char *) lsa->header;
452 end = (u_char *) lsa->header + ntohs (lsa->header->length);
paul718e3742002-12-13 20:15:29 +0000453
hasso049207c2004-08-04 20:02:13 +0000454 vty_out (vty, "%s", VNL);
455 vty_out (vty, "%s:%s", lsa->name, VNL);
paul718e3742002-12-13 20:15:29 +0000456
457 for (current = start; current < end; current ++)
458 {
459 if ((current - start) % 16 == 0)
hasso049207c2004-08-04 20:02:13 +0000460 vty_out (vty, "%s ", VNL);
paul718e3742002-12-13 20:15:29 +0000461 else if ((current - start) % 4 == 0)
462 vty_out (vty, " ");
463
464 snprintf (byte, sizeof (byte), "%02x", *current);
465 vty_out (vty, "%s", byte);
466 }
467
hasso049207c2004-08-04 20:02:13 +0000468 vty_out (vty, "%s%s", VNL, VNL);
hasso6452df02004-08-15 05:52:07 +0000469 return;
paul718e3742002-12-13 20:15:29 +0000470}
471
hasso508e53e2004-05-18 18:57:06 +0000472void
473ospf6_lsa_show_internal (struct vty *vty, struct ospf6_lsa *lsa)
474{
475 char adv_router[64], id[64];
476
477 assert (lsa && lsa->header);
478
479 inet_ntop (AF_INET, &lsa->header->id, id, sizeof (id));
480 inet_ntop (AF_INET, &lsa->header->adv_router,
481 adv_router, sizeof (adv_router));
482
hasso049207c2004-08-04 20:02:13 +0000483 vty_out (vty, "%s", VNL);
hasso508e53e2004-05-18 18:57:06 +0000484 vty_out (vty, "Age: %4hu Type: %s%s", ospf6_lsa_age_current (lsa),
hasso1e058382004-09-01 21:36:14 +0000485 ospf6_lstype_name (lsa->header->type), VNL);
hasso049207c2004-08-04 20:02:13 +0000486 vty_out (vty, "Link State ID: %s%s", id, VNL);
487 vty_out (vty, "Advertising Router: %s%s", adv_router, VNL);
hasso508e53e2004-05-18 18:57:06 +0000488 vty_out (vty, "LS Sequence Number: %#010lx%s",
hasso049207c2004-08-04 20:02:13 +0000489 (u_long) ntohl (lsa->header->seqnum), VNL);
hasso508e53e2004-05-18 18:57:06 +0000490 vty_out (vty, "CheckSum: %#06hx Length: %hu%s",
491 ntohs (lsa->header->checksum),
hasso049207c2004-08-04 20:02:13 +0000492 ntohs (lsa->header->length), VNL);
Dinesh Dutt8ae454e2013-08-24 07:54:41 +0000493 vty_out (vty, "Flag: %x %s", lsa->flag, VNL);
494 vty_out (vty, "Lock: %d %s", lsa->lock, VNL);
495 vty_out (vty, "ReTx Count: %d%s", lsa->retrans_count, VNL);
496 vty_out (vty, "Threads: Expire: %x, Refresh: %x %s",
497 lsa->expire, lsa->refresh, VNL);
hasso049207c2004-08-04 20:02:13 +0000498 vty_out (vty, "%s", VNL);
hasso6452df02004-08-15 05:52:07 +0000499 return;
500}
501
502void
503ospf6_lsa_show (struct vty *vty, struct ospf6_lsa *lsa)
504{
505 char adv_router[64], id[64];
hasso1e058382004-09-01 21:36:14 +0000506 struct ospf6_lsa_handler *handler;
Dinesh Dutte68a6762013-08-25 03:03:23 +0000507 struct timeval now, res;
508 char duration[16];
hasso6452df02004-08-15 05:52:07 +0000509
510 assert (lsa && lsa->header);
511
512 inet_ntop (AF_INET, &lsa->header->id, id, sizeof (id));
513 inet_ntop (AF_INET, &lsa->header->adv_router,
514 adv_router, sizeof (adv_router));
515
Dinesh Dutte68a6762013-08-25 03:03:23 +0000516 quagga_gettime (QUAGGA_CLK_MONOTONIC, &now);
517 timersub (&now, &lsa->installed, &res);
518 timerstring (&res, duration, sizeof (duration));
519
hasso6452df02004-08-15 05:52:07 +0000520 vty_out (vty, "Age: %4hu Type: %s%s", ospf6_lsa_age_current (lsa),
hasso1e058382004-09-01 21:36:14 +0000521 ospf6_lstype_name (lsa->header->type), VNL);
hasso6452df02004-08-15 05:52:07 +0000522 vty_out (vty, "Link State ID: %s%s", id, VNL);
523 vty_out (vty, "Advertising Router: %s%s", adv_router, VNL);
524 vty_out (vty, "LS Sequence Number: %#010lx%s",
525 (u_long) ntohl (lsa->header->seqnum), VNL);
526 vty_out (vty, "CheckSum: %#06hx Length: %hu%s",
527 ntohs (lsa->header->checksum),
528 ntohs (lsa->header->length), VNL);
Dinesh Dutte68a6762013-08-25 03:03:23 +0000529 vty_out (vty, "Duration: %s%s", duration, VNL);
hasso6452df02004-08-15 05:52:07 +0000530
hasso1e058382004-09-01 21:36:14 +0000531 handler = ospf6_get_lsa_handler (lsa->header->type);
532 if (handler->show == NULL)
533 handler = &unknown_handler;
534 (*handler->show) (vty, lsa);
hasso6452df02004-08-15 05:52:07 +0000535
536 vty_out (vty, "%s", VNL);
hasso508e53e2004-05-18 18:57:06 +0000537}
538
paul718e3742002-12-13 20:15:29 +0000539/* OSPFv3 LSA creation/deletion function */
paul718e3742002-12-13 20:15:29 +0000540struct ospf6_lsa *
hasso508e53e2004-05-18 18:57:06 +0000541ospf6_lsa_create (struct ospf6_lsa_header *header)
paul718e3742002-12-13 20:15:29 +0000542{
543 struct ospf6_lsa *lsa = NULL;
hasso508e53e2004-05-18 18:57:06 +0000544 struct ospf6_lsa_header *new_header = NULL;
paul718e3742002-12-13 20:15:29 +0000545 u_int16_t lsa_size = 0;
paul718e3742002-12-13 20:15:29 +0000546
hasso508e53e2004-05-18 18:57:06 +0000547 /* size of the entire LSA */
548 lsa_size = ntohs (header->length); /* XXX vulnerable */
paul718e3742002-12-13 20:15:29 +0000549
550 /* allocate memory for this LSA */
hasso508e53e2004-05-18 18:57:06 +0000551 new_header = (struct ospf6_lsa_header *)
paul718e3742002-12-13 20:15:29 +0000552 XMALLOC (MTYPE_OSPF6_LSA, lsa_size);
paul718e3742002-12-13 20:15:29 +0000553
hasso508e53e2004-05-18 18:57:06 +0000554 /* copy LSA from original header */
555 memcpy (new_header, header, lsa_size);
paul718e3742002-12-13 20:15:29 +0000556
557 /* LSA information structure */
558 /* allocate memory */
559 lsa = (struct ospf6_lsa *)
Stephen Hemminger393deb92008-08-18 14:13:29 -0700560 XCALLOC (MTYPE_OSPF6_LSA, sizeof (struct ospf6_lsa));
paul718e3742002-12-13 20:15:29 +0000561
hasso508e53e2004-05-18 18:57:06 +0000562 lsa->header = (struct ospf6_lsa_header *) new_header;
paul718e3742002-12-13 20:15:29 +0000563
564 /* dump string */
hasso508e53e2004-05-18 18:57:06 +0000565 ospf6_lsa_printbuf (lsa, lsa->name, sizeof (lsa->name));
paul718e3742002-12-13 20:15:29 +0000566
hasso3b687352004-08-19 06:56:53 +0000567 /* calculate birth of this lsa */
paul718e3742002-12-13 20:15:29 +0000568 ospf6_lsa_age_set (lsa);
569
paul718e3742002-12-13 20:15:29 +0000570 return lsa;
571}
572
573struct ospf6_lsa *
hasso508e53e2004-05-18 18:57:06 +0000574ospf6_lsa_create_headeronly (struct ospf6_lsa_header *header)
paul718e3742002-12-13 20:15:29 +0000575{
576 struct ospf6_lsa *lsa = NULL;
hasso508e53e2004-05-18 18:57:06 +0000577 struct ospf6_lsa_header *new_header = NULL;
paul718e3742002-12-13 20:15:29 +0000578
579 /* allocate memory for this LSA */
hasso508e53e2004-05-18 18:57:06 +0000580 new_header = (struct ospf6_lsa_header *)
581 XMALLOC (MTYPE_OSPF6_LSA, sizeof (struct ospf6_lsa_header));
paul718e3742002-12-13 20:15:29 +0000582
hasso508e53e2004-05-18 18:57:06 +0000583 /* copy LSA from original header */
584 memcpy (new_header, header, sizeof (struct ospf6_lsa_header));
paul718e3742002-12-13 20:15:29 +0000585
586 /* LSA information structure */
587 /* allocate memory */
588 lsa = (struct ospf6_lsa *)
Stephen Hemminger393deb92008-08-18 14:13:29 -0700589 XCALLOC (MTYPE_OSPF6_LSA, sizeof (struct ospf6_lsa));
paul718e3742002-12-13 20:15:29 +0000590
hasso508e53e2004-05-18 18:57:06 +0000591 lsa->header = (struct ospf6_lsa_header *) new_header;
hasso6452df02004-08-15 05:52:07 +0000592 SET_FLAG (lsa->flag, OSPF6_LSA_HEADERONLY);
paul718e3742002-12-13 20:15:29 +0000593
594 /* dump string */
hasso508e53e2004-05-18 18:57:06 +0000595 ospf6_lsa_printbuf (lsa, lsa->name, sizeof (lsa->name));
paul718e3742002-12-13 20:15:29 +0000596
hasso3b687352004-08-19 06:56:53 +0000597 /* calculate birth of this lsa */
paul718e3742002-12-13 20:15:29 +0000598 ospf6_lsa_age_set (lsa);
599
paul718e3742002-12-13 20:15:29 +0000600 return lsa;
601}
602
603void
604ospf6_lsa_delete (struct ospf6_lsa *lsa)
605{
hasso508e53e2004-05-18 18:57:06 +0000606 assert (lsa->lock == 0);
paul718e3742002-12-13 20:15:29 +0000607
608 /* cancel threads */
hasso508e53e2004-05-18 18:57:06 +0000609 THREAD_OFF (lsa->expire);
610 THREAD_OFF (lsa->refresh);
paul718e3742002-12-13 20:15:29 +0000611
paul718e3742002-12-13 20:15:29 +0000612 /* do free */
hasso508e53e2004-05-18 18:57:06 +0000613 XFREE (MTYPE_OSPF6_LSA, lsa->header);
614 XFREE (MTYPE_OSPF6_LSA, lsa);
paul718e3742002-12-13 20:15:29 +0000615}
616
hasso508e53e2004-05-18 18:57:06 +0000617struct ospf6_lsa *
618ospf6_lsa_copy (struct ospf6_lsa *lsa)
619{
620 struct ospf6_lsa *copy = NULL;
621
hasso508e53e2004-05-18 18:57:06 +0000622 ospf6_lsa_age_current (lsa);
hasso6452df02004-08-15 05:52:07 +0000623 if (CHECK_FLAG (lsa->flag, OSPF6_LSA_HEADERONLY))
hasso508e53e2004-05-18 18:57:06 +0000624 copy = ospf6_lsa_create_headeronly (lsa->header);
625 else
626 copy = ospf6_lsa_create (lsa->header);
627 assert (copy->lock == 0);
628
hasso3b687352004-08-19 06:56:53 +0000629 copy->birth = lsa->birth;
hasso508e53e2004-05-18 18:57:06 +0000630 copy->originated = lsa->originated;
hassoccb59b12004-08-25 09:10:37 +0000631 copy->received = lsa->received;
632 copy->installed = lsa->installed;
hasso6452df02004-08-15 05:52:07 +0000633 copy->lsdb = lsa->lsdb;
Dinesh Dutta765eb92013-08-24 07:55:14 +0000634 copy->rn = NULL;
hasso508e53e2004-05-18 18:57:06 +0000635
hasso508e53e2004-05-18 18:57:06 +0000636 return copy;
637}
638
639/* increment reference counter of struct ospf6_lsa */
paul718e3742002-12-13 20:15:29 +0000640void
641ospf6_lsa_lock (struct ospf6_lsa *lsa)
642{
643 lsa->lock++;
644 return;
645}
646
hasso508e53e2004-05-18 18:57:06 +0000647/* decrement reference counter of struct ospf6_lsa */
paul718e3742002-12-13 20:15:29 +0000648void
649ospf6_lsa_unlock (struct ospf6_lsa *lsa)
650{
651 /* decrement reference counter */
hasso508e53e2004-05-18 18:57:06 +0000652 assert (lsa->lock > 0);
653 lsa->lock--;
paul718e3742002-12-13 20:15:29 +0000654
hasso508e53e2004-05-18 18:57:06 +0000655 if (lsa->lock != 0)
656 return;
657
hasso508e53e2004-05-18 18:57:06 +0000658 ospf6_lsa_delete (lsa);
paul718e3742002-12-13 20:15:29 +0000659}
660
David Lamparter6b0655a2014-06-04 06:53:35 +0200661
hasso508e53e2004-05-18 18:57:06 +0000662/* ospf6 lsa expiry */
paul718e3742002-12-13 20:15:29 +0000663int
664ospf6_lsa_expire (struct thread *thread)
665{
666 struct ospf6_lsa *lsa;
paul718e3742002-12-13 20:15:29 +0000667
668 lsa = (struct ospf6_lsa *) THREAD_ARG (thread);
paul718e3742002-12-13 20:15:29 +0000669
hasso508e53e2004-05-18 18:57:06 +0000670 assert (lsa && lsa->header);
671 assert (OSPF6_LSA_IS_MAXAGE (lsa));
672 assert (! lsa->refresh);
paul718e3742002-12-13 20:15:29 +0000673
674 lsa->expire = (struct thread *) NULL;
675
hasso1e058382004-09-01 21:36:14 +0000676 if (IS_OSPF6_DEBUG_LSA_TYPE (lsa->header->type))
paul718e3742002-12-13 20:15:29 +0000677 {
hassoc6487d62004-12-24 06:00:11 +0000678 zlog_debug ("LSA Expire:");
hasso508e53e2004-05-18 18:57:06 +0000679 ospf6_lsa_header_print (lsa);
paul718e3742002-12-13 20:15:29 +0000680 }
681
hasso6452df02004-08-15 05:52:07 +0000682 if (CHECK_FLAG (lsa->flag, OSPF6_LSA_HEADERONLY))
hasso508e53e2004-05-18 18:57:06 +0000683 return 0; /* dbexchange will do something ... */
684
hasso508e53e2004-05-18 18:57:06 +0000685 /* reinstall lsa */
hasso3b687352004-08-19 06:56:53 +0000686 ospf6_install_lsa (lsa);
hasso508e53e2004-05-18 18:57:06 +0000687
Dinesh Duttbf986da2013-08-24 07:54:50 +0000688 /* reflood lsa */
689 ospf6_flood (NULL, lsa);
690
hasso508e53e2004-05-18 18:57:06 +0000691 /* schedule maxage remover */
692 ospf6_maxage_remove (ospf6);
693
paul718e3742002-12-13 20:15:29 +0000694 return 0;
695}
696
697int
698ospf6_lsa_refresh (struct thread *thread)
699{
hasso6452df02004-08-15 05:52:07 +0000700 struct ospf6_lsa *old, *self, *new;
701 struct ospf6_lsdb *lsdb_self;
paul718e3742002-12-13 20:15:29 +0000702
703 assert (thread);
hasso6452df02004-08-15 05:52:07 +0000704 old = (struct ospf6_lsa *) THREAD_ARG (thread);
705 assert (old && old->header);
paul718e3742002-12-13 20:15:29 +0000706
hasso6452df02004-08-15 05:52:07 +0000707 old->refresh = (struct thread *) NULL;
paul718e3742002-12-13 20:15:29 +0000708
hasso6452df02004-08-15 05:52:07 +0000709 lsdb_self = ospf6_get_scoped_lsdb_self (old);
710 self = ospf6_lsdb_lookup (old->header->type, old->header->id,
711 old->header->adv_router, lsdb_self);
712 if (self == NULL)
713 {
hasso1e058382004-09-01 21:36:14 +0000714 if (IS_OSPF6_DEBUG_LSA_TYPE (old->header->type))
hassoc6487d62004-12-24 06:00:11 +0000715 zlog_debug ("Refresh: could not find self LSA, flush %s", old->name);
hasso6452df02004-08-15 05:52:07 +0000716 ospf6_lsa_premature_aging (old);
717 return 0;
718 }
719
720 /* Reset age, increment LS sequence number. */
721 self->header->age = htons (0);
722 self->header->seqnum =
723 ospf6_new_ls_seqnum (self->header->type, self->header->id,
724 self->header->adv_router, old->lsdb);
725 ospf6_lsa_checksum (self->header);
726
727 new = ospf6_lsa_create (self->header);
728 new->lsdb = old->lsdb;
729 new->refresh = thread_add_timer (master, ospf6_lsa_refresh, new,
Dinesh Dutt8551e6d2013-10-22 17:42:18 -0700730 OSPF_LS_REFRESH_TIME);
hasso6452df02004-08-15 05:52:07 +0000731
732 /* store it in the LSDB for self-originated LSAs */
733 ospf6_lsdb_add (ospf6_lsa_copy (new), lsdb_self);
paul718e3742002-12-13 20:15:29 +0000734
hasso1e058382004-09-01 21:36:14 +0000735 if (IS_OSPF6_DEBUG_LSA_TYPE (new->header->type))
paul718e3742002-12-13 20:15:29 +0000736 {
hassoc6487d62004-12-24 06:00:11 +0000737 zlog_debug ("LSA Refresh:");
hasso6452df02004-08-15 05:52:07 +0000738 ospf6_lsa_header_print (new);
paul718e3742002-12-13 20:15:29 +0000739 }
740
hasso6452df02004-08-15 05:52:07 +0000741 ospf6_install_lsa (new);
Dinesh Duttbf986da2013-08-24 07:54:50 +0000742 ospf6_flood (NULL, new);
hasso6452df02004-08-15 05:52:07 +0000743
hasso508e53e2004-05-18 18:57:06 +0000744 return 0;
paul718e3742002-12-13 20:15:29 +0000745}
746
David Lamparter6b0655a2014-06-04 06:53:35 +0200747
paul718e3742002-12-13 20:15:29 +0000748
JR Riversd8a4e422012-09-13 17:17:36 +0000749/* Fletcher Checksum -- Refer to RFC1008. */
paul718e3742002-12-13 20:15:29 +0000750
JR Riversd8a4e422012-09-13 17:17:36 +0000751/* All the offsets are zero-based. The offsets in the RFC1008 are
752 one-based. */
paul718e3742002-12-13 20:15:29 +0000753unsigned short
754ospf6_lsa_checksum (struct ospf6_lsa_header *lsa_header)
755{
JR Riversd8a4e422012-09-13 17:17:36 +0000756 u_char *buffer = (u_char *) &lsa_header->type;
757 int type_offset = buffer - (u_char *) &lsa_header->age; /* should be 2 */
paul718e3742002-12-13 20:15:29 +0000758
JR Riversd8a4e422012-09-13 17:17:36 +0000759 /* Skip the AGE field */
760 u_int16_t len = ntohs(lsa_header->length) - type_offset;
paul718e3742002-12-13 20:15:29 +0000761
JR Riversd8a4e422012-09-13 17:17:36 +0000762 /* Checksum offset starts from "type" field, not the beginning of the
763 lsa_header struct. The offset is 14, rather than 16. */
764 int checksum_offset = (u_char *) &lsa_header->checksum - buffer;
paul718e3742002-12-13 20:15:29 +0000765
JR Riversd8a4e422012-09-13 17:17:36 +0000766 return (unsigned short)fletcher_checksum(buffer, len, checksum_offset);
767}
paul718e3742002-12-13 20:15:29 +0000768
JR Riversd8a4e422012-09-13 17:17:36 +0000769int
770ospf6_lsa_checksum_valid (struct ospf6_lsa_header *lsa_header)
771{
772 u_char *buffer = (u_char *) &lsa_header->type;
773 int type_offset = buffer - (u_char *) &lsa_header->age; /* should be 2 */
paul718e3742002-12-13 20:15:29 +0000774
JR Riversd8a4e422012-09-13 17:17:36 +0000775 /* Skip the AGE field */
776 u_int16_t len = ntohs(lsa_header->length) - type_offset;
777
778 return (fletcher_checksum(buffer, len, FLETCHER_CHECKSUM_VALIDATE) == 0);
paul718e3742002-12-13 20:15:29 +0000779}
780
hasso6452df02004-08-15 05:52:07 +0000781void
Paul Jakma6ac29a52008-08-15 13:45:30 +0100782ospf6_lsa_init (void)
paul718e3742002-12-13 20:15:29 +0000783{
hasso1e058382004-09-01 21:36:14 +0000784 ospf6_lsa_handler_vector = vector_init (0);
hasso6452df02004-08-15 05:52:07 +0000785 ospf6_install_lsa_handler (&unknown_handler);
paul718e3742002-12-13 20:15:29 +0000786}
787
Tom Goffae2254a2010-11-10 13:01:41 -0800788void
789ospf6_lsa_terminate (void)
790{
791 vector_free (ospf6_lsa_handler_vector);
792}
David Lamparter6b0655a2014-06-04 06:53:35 +0200793
Paul Jakma6ac29a52008-08-15 13:45:30 +0100794static char *
hasso1e058382004-09-01 21:36:14 +0000795ospf6_lsa_handler_name (struct ospf6_lsa_handler *h)
hasso508e53e2004-05-18 18:57:06 +0000796{
hasso1e058382004-09-01 21:36:14 +0000797 static char buf[64];
paul0c083ee2004-10-10 12:54:58 +0000798 unsigned int i;
799 unsigned int size = strlen (h->name);
hasso508e53e2004-05-18 18:57:06 +0000800
Dinesh Dutt09df4572013-08-24 07:54:31 +0000801 if (!strcmp(h->name, "unknown") &&
hasso1e058382004-09-01 21:36:14 +0000802 h->type != OSPF6_LSTYPE_UNKNOWN)
hasso508e53e2004-05-18 18:57:06 +0000803 {
hasso1e058382004-09-01 21:36:14 +0000804 snprintf (buf, sizeof (buf), "%#04hx", h->type);
805 return buf;
hasso508e53e2004-05-18 18:57:06 +0000806 }
807
hasso1e058382004-09-01 21:36:14 +0000808 for (i = 0; i < MIN (size, sizeof (buf)); i++)
hasso508e53e2004-05-18 18:57:06 +0000809 {
hasso1e058382004-09-01 21:36:14 +0000810 if (! islower (h->name[i]))
811 buf[i] = tolower (h->name[i]);
hasso508e53e2004-05-18 18:57:06 +0000812 else
hasso1e058382004-09-01 21:36:14 +0000813 buf[i] = h->name[i];
814 }
815 buf[size] = '\0';
816 return buf;
817}
hasso508e53e2004-05-18 18:57:06 +0000818
hasso1e058382004-09-01 21:36:14 +0000819DEFUN (debug_ospf6_lsa_type,
820 debug_ospf6_lsa_hex_cmd,
Dinesh Dutt09df4572013-08-24 07:54:31 +0000821 "debug ospf6 lsa (router|network|inter-prefix|inter-router|as-ext|grp-mbr|type7|link|intra-prefix|unknown)",
hasso1e058382004-09-01 21:36:14 +0000822 DEBUG_STR
823 OSPF6_STR
824 "Debug Link State Advertisements (LSAs)\n"
825 "Specify LS type as Hexadecimal\n"
826 )
827{
paul0c083ee2004-10-10 12:54:58 +0000828 unsigned int i;
hasso1e058382004-09-01 21:36:14 +0000829 struct ospf6_lsa_handler *handler = NULL;
hasso1e058382004-09-01 21:36:14 +0000830
831 assert (argc);
832
paul55468c82005-03-14 20:19:01 +0000833 for (i = 0; i < vector_active (ospf6_lsa_handler_vector); i++)
hasso1e058382004-09-01 21:36:14 +0000834 {
835 handler = vector_slot (ospf6_lsa_handler_vector, i);
836 if (handler == NULL)
837 continue;
Dinesh Dutt09df4572013-08-24 07:54:31 +0000838 if (strncmp (argv[0], ospf6_lsa_handler_name(handler), strlen(argv[0])) == 0)
hasso1e058382004-09-01 21:36:14 +0000839 break;
840 if (! strcasecmp (argv[0], handler->name))
841 break;
842 handler = NULL;
843 }
844
hasso1e058382004-09-01 21:36:14 +0000845 if (handler == NULL)
846 handler = &unknown_handler;
847
848 if (argc >= 2)
849 {
850 if (! strcmp (argv[1], "originate"))
851 SET_FLAG (handler->debug, OSPF6_LSA_DEBUG_ORIGINATE);
Dinesh Dutt09df4572013-08-24 07:54:31 +0000852 if (! strcmp (argv[1], "examine"))
hasso1e058382004-09-01 21:36:14 +0000853 SET_FLAG (handler->debug, OSPF6_LSA_DEBUG_EXAMIN);
854 if (! strcmp (argv[1], "flooding"))
855 SET_FLAG (handler->debug, OSPF6_LSA_DEBUG_FLOOD);
856 }
857 else
858 SET_FLAG (handler->debug, OSPF6_LSA_DEBUG);
859
860 return CMD_SUCCESS;
hasso508e53e2004-05-18 18:57:06 +0000861}
862
Dinesh Dutt09df4572013-08-24 07:54:31 +0000863ALIAS (debug_ospf6_lsa_type,
864 debug_ospf6_lsa_hex_detail_cmd,
865 "debug ospf6 lsa (router|network|inter-prefix|inter-router|as-ext|grp-mbr|type7|link|intra-prefix|unknown) (originate|examine|flooding)",
866 DEBUG_STR
867 OSPF6_STR
868 "Debug Link State Advertisements (LSAs)\n"
869 "Specify LS type as Hexadecimal\n"
870 )
871
hasso1e058382004-09-01 21:36:14 +0000872DEFUN (no_debug_ospf6_lsa_type,
873 no_debug_ospf6_lsa_hex_cmd,
Dinesh Dutt09df4572013-08-24 07:54:31 +0000874 "no debug ospf6 lsa (router|network|inter-prefix|inter-router|as-ext|grp-mbr|type7|link|intra-prefix|unknown)",
hasso1e058382004-09-01 21:36:14 +0000875 NO_STR
876 DEBUG_STR
877 OSPF6_STR
878 "Debug Link State Advertisements (LSAs)\n"
879 "Specify LS type as Hexadecimal\n"
880 )
881{
paul0c083ee2004-10-10 12:54:58 +0000882 u_int i;
hasso1e058382004-09-01 21:36:14 +0000883 struct ospf6_lsa_handler *handler = NULL;
hasso1e058382004-09-01 21:36:14 +0000884
885 assert (argc);
886
paul55468c82005-03-14 20:19:01 +0000887 for (i = 0; i < vector_active (ospf6_lsa_handler_vector); i++)
hasso1e058382004-09-01 21:36:14 +0000888 {
889 handler = vector_slot (ospf6_lsa_handler_vector, i);
890 if (handler == NULL)
891 continue;
Dinesh Dutt09df4572013-08-24 07:54:31 +0000892 if (strncmp (argv[0], ospf6_lsa_handler_name(handler), strlen(argv[0])) == 0)
hasso1e058382004-09-01 21:36:14 +0000893 break;
894 if (! strcasecmp (argv[0], handler->name))
895 break;
896 }
897
898 if (handler == NULL)
899 return CMD_SUCCESS;
900
901 if (argc >= 2)
902 {
903 if (! strcmp (argv[1], "originate"))
904 UNSET_FLAG (handler->debug, OSPF6_LSA_DEBUG_ORIGINATE);
Dinesh Dutt09df4572013-08-24 07:54:31 +0000905 if (! strcmp (argv[1], "examine"))
hasso1e058382004-09-01 21:36:14 +0000906 UNSET_FLAG (handler->debug, OSPF6_LSA_DEBUG_EXAMIN);
907 if (! strcmp (argv[1], "flooding"))
908 UNSET_FLAG (handler->debug, OSPF6_LSA_DEBUG_FLOOD);
909 }
910 else
911 UNSET_FLAG (handler->debug, OSPF6_LSA_DEBUG);
912
hasso1e058382004-09-01 21:36:14 +0000913 return CMD_SUCCESS;
914}
915
Dinesh Dutt09df4572013-08-24 07:54:31 +0000916ALIAS (no_debug_ospf6_lsa_type,
917 no_debug_ospf6_lsa_hex_detail_cmd,
918 "no debug ospf6 lsa (router|network|inter-prefix|inter-router|as-ext|grp-mbr|type7|link|intra-prefix) (originate|examine|flooding)",
919 NO_STR
920 DEBUG_STR
921 OSPF6_STR
922 "Debug Link State Advertisements (LSAs)\n"
923 "Specify LS type as Hexadecimal\n"
924 )
hasso1e058382004-09-01 21:36:14 +0000925
hasso508e53e2004-05-18 18:57:06 +0000926void
Paul Jakma6ac29a52008-08-15 13:45:30 +0100927install_element_ospf6_debug_lsa (void)
hasso508e53e2004-05-18 18:57:06 +0000928{
hasso1e058382004-09-01 21:36:14 +0000929 install_element (ENABLE_NODE, &debug_ospf6_lsa_hex_cmd);
Dinesh Dutt09df4572013-08-24 07:54:31 +0000930 install_element (ENABLE_NODE, &debug_ospf6_lsa_hex_detail_cmd);
hasso1e058382004-09-01 21:36:14 +0000931 install_element (ENABLE_NODE, &no_debug_ospf6_lsa_hex_cmd);
Dinesh Dutt09df4572013-08-24 07:54:31 +0000932 install_element (ENABLE_NODE, &no_debug_ospf6_lsa_hex_detail_cmd);
hasso1e058382004-09-01 21:36:14 +0000933 install_element (CONFIG_NODE, &debug_ospf6_lsa_hex_cmd);
Dinesh Dutt09df4572013-08-24 07:54:31 +0000934 install_element (CONFIG_NODE, &debug_ospf6_lsa_hex_detail_cmd);
hasso1e058382004-09-01 21:36:14 +0000935 install_element (CONFIG_NODE, &no_debug_ospf6_lsa_hex_cmd);
Dinesh Dutt09df4572013-08-24 07:54:31 +0000936 install_element (CONFIG_NODE, &no_debug_ospf6_lsa_hex_detail_cmd);
hasso1e058382004-09-01 21:36:14 +0000937}
938
939int
940config_write_ospf6_debug_lsa (struct vty *vty)
941{
paul0c083ee2004-10-10 12:54:58 +0000942 u_int i;
hasso1e058382004-09-01 21:36:14 +0000943 struct ospf6_lsa_handler *handler;
944
paul55468c82005-03-14 20:19:01 +0000945 for (i = 0; i < vector_active (ospf6_lsa_handler_vector); i++)
hasso1e058382004-09-01 21:36:14 +0000946 {
947 handler = vector_slot (ospf6_lsa_handler_vector, i);
948 if (handler == NULL)
949 continue;
950 if (CHECK_FLAG (handler->debug, OSPF6_LSA_DEBUG))
951 vty_out (vty, "debug ospf6 lsa %s%s",
952 ospf6_lsa_handler_name (handler), VNL);
953 if (CHECK_FLAG (handler->debug, OSPF6_LSA_DEBUG_ORIGINATE))
954 vty_out (vty, "debug ospf6 lsa %s originate%s",
955 ospf6_lsa_handler_name (handler), VNL);
956 if (CHECK_FLAG (handler->debug, OSPF6_LSA_DEBUG_EXAMIN))
Dinesh Dutt09df4572013-08-24 07:54:31 +0000957 vty_out (vty, "debug ospf6 lsa %s examine%s",
hasso1e058382004-09-01 21:36:14 +0000958 ospf6_lsa_handler_name (handler), VNL);
959 if (CHECK_FLAG (handler->debug, OSPF6_LSA_DEBUG_FLOOD))
960 vty_out (vty, "debug ospf6 lsa %s flooding%s",
961 ospf6_lsa_handler_name (handler), VNL);
962 }
963
964 return 0;
hasso508e53e2004-05-18 18:57:06 +0000965}
966
967