blob: 592aad9bc80a6fb6d0b24b9b36ffcae7707974a1 [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 Dutt09df4572013-08-24 07:54:31 +000077 "unknown",
hasso1e058382004-09-01 21:36:14 +000078 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);
Dinesh Dutt8551e6d2013-10-22 17:42:18 -0700142 if (ntohs (lsa1->header->age) == OSPF_LSA_MAXAGE &&
143 ntohs (lsa2->header->age) != OSPF_LSA_MAXAGE)
paul718e3742002-12-13 20:15:29 +0000144 return 1;
Dinesh Dutt8551e6d2013-10-22 17:42:18 -0700145 if (ntohs (lsa1->header->age) != OSPF_LSA_MAXAGE &&
146 ntohs (lsa2->header->age) == OSPF_LSA_MAXAGE)
paul718e3742002-12-13 20:15:29 +0000147 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
Dinesh Dutt8551e6d2013-10-22 17:42:18 -0700221 if (ntohs (lsa->header->age) >= OSPF_LSA_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. */
Dinesh Dutt8551e6d2013-10-22 17:42:18 -0700226 lsa->header->age = htons (OSPF_LSA_MAXAGE);
227 return OSPF_LSA_MAXAGE;
Tom Henderson9b4ef252009-07-16 17:20:37 +0100228 }
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 */
Dinesh Dutt8551e6d2013-10-22 17:42:18 -0700233 age = (ulage > OSPF_LSA_MAXAGE ? OSPF_LSA_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;
Dinesh Dutt8551e6d2013-10-22 17:42:18 -0700246 if (age > OSPF_LSA_MAXAGE)
247 age = OSPF_LSA_MAXAGE;
paul718e3742002-12-13 20:15:29 +0000248 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
Dinesh Duttac58e142013-08-24 07:54:24 +0000261 /*
262 * We clear the LSA from the neighbor retx lists now because it
263 * will not get deleted later. Essentially, changing the age to
264 * MaxAge will prevent this LSA from being matched with its
265 * existing entries in the retx list thereby causing those entries
266 * to be silently replaced with its MaxAged version, but with ever
267 * increasing retx count causing this LSA to remain forever and
268 * for the MaxAge remover thread to be called forever too.
269 *
270 * The reason the previous entry silently disappears is that when
271 * entry is added to a neighbor's retx list, it replaces the existing
272 * entry. But since the ospf6_lsdb_add() routine is generic and not aware
273 * of the special semantics of retx count, the retx count is not
274 * decremented when its replaced. Attempting to add the incr and decr
275 * retx count routines as the hook_add and hook_remove for the retx lists
276 * have a problem because the hook_remove routine is called for MaxAge
277 * entries (as will be the case in a traditional LSDB, unlike in this case
278 * where an LSDB is used as an efficient tree structure to store all kinds
279 * of data) that are added instead of calling the hook_add routine.
280 */
281
282 ospf6_flood_clear (lsa);
283
Dinesh Dutt8551e6d2013-10-22 17:42:18 -0700284 lsa->header->age = htons (OSPF_LSA_MAXAGE);
paul718e3742002-12-13 20:15:29 +0000285 thread_execute (master, ospf6_lsa_expire, lsa, 0);
286}
287
288/* check which is more recent. if a is more recent, return -1;
289 if the same, return 0; otherwise(b is more recent), return 1 */
290int
hasso508e53e2004-05-18 18:57:06 +0000291ospf6_lsa_compare (struct ospf6_lsa *a, struct ospf6_lsa *b)
paul718e3742002-12-13 20:15:29 +0000292{
Ondrej Zajicek64bf3ab2009-12-07 12:33:20 +0300293 int seqnuma, seqnumb;
paul718e3742002-12-13 20:15:29 +0000294 u_int16_t cksuma, cksumb;
295 u_int16_t agea, ageb;
296
297 assert (a && a->header);
298 assert (b && b->header);
hasso508e53e2004-05-18 18:57:06 +0000299 assert (OSPF6_LSA_IS_SAME (a, b));
paul718e3742002-12-13 20:15:29 +0000300
Ondrej Zajicek64bf3ab2009-12-07 12:33:20 +0300301 seqnuma = (int) ntohl (a->header->seqnum);
302 seqnumb = (int) ntohl (b->header->seqnum);
paul718e3742002-12-13 20:15:29 +0000303
304 /* compare by sequence number */
paul718e3742002-12-13 20:15:29 +0000305 if (seqnuma > seqnumb)
306 return -1;
Ondrej Zajicek64bf3ab2009-12-07 12:33:20 +0300307 if (seqnuma < seqnumb)
paul718e3742002-12-13 20:15:29 +0000308 return 1;
309
310 /* Checksum */
311 cksuma = ntohs (a->header->checksum);
312 cksumb = ntohs (b->header->checksum);
313 if (cksuma > cksumb)
314 return -1;
315 if (cksuma < cksumb)
316 return 0;
317
hasso508e53e2004-05-18 18:57:06 +0000318 /* Update Age */
paul718e3742002-12-13 20:15:29 +0000319 agea = ospf6_lsa_age_current (a);
320 ageb = ospf6_lsa_age_current (b);
321
hasso508e53e2004-05-18 18:57:06 +0000322 /* MaxAge check */
Dinesh Dutt8551e6d2013-10-22 17:42:18 -0700323 if (agea == OSPF_LSA_MAXAGE && ageb != OSPF_LSA_MAXAGE)
paul718e3742002-12-13 20:15:29 +0000324 return -1;
Dinesh Dutt8551e6d2013-10-22 17:42:18 -0700325 else if (agea != OSPF_LSA_MAXAGE && ageb == OSPF_LSA_MAXAGE)
paul718e3742002-12-13 20:15:29 +0000326 return 1;
327
hasso508e53e2004-05-18 18:57:06 +0000328 /* Age check */
Dinesh Dutt8551e6d2013-10-22 17:42:18 -0700329 if (agea > ageb && agea - ageb >= OSPF_LSA_MAXAGE_DIFF)
paul718e3742002-12-13 20:15:29 +0000330 return 1;
Dinesh Dutt8551e6d2013-10-22 17:42:18 -0700331 else if (agea < ageb && ageb - agea >= OSPF_LSA_MAXAGE_DIFF)
paul718e3742002-12-13 20:15:29 +0000332 return -1;
333
334 /* neither recent */
paul718e3742002-12-13 20:15:29 +0000335 return 0;
336}
337
hasso508e53e2004-05-18 18:57:06 +0000338char *
339ospf6_lsa_printbuf (struct ospf6_lsa *lsa, char *buf, int size)
paul718e3742002-12-13 20:15:29 +0000340{
hasso508e53e2004-05-18 18:57:06 +0000341 char id[16], adv_router[16];
342 inet_ntop (AF_INET, &lsa->header->id, id, sizeof (id));
343 inet_ntop (AF_INET, &lsa->header->adv_router, adv_router,
344 sizeof (adv_router));
345 snprintf (buf, size, "[%s Id:%s Adv:%s]",
hasso1e058382004-09-01 21:36:14 +0000346 ospf6_lstype_name (lsa->header->type), id, adv_router);
hasso508e53e2004-05-18 18:57:06 +0000347 return buf;
paul718e3742002-12-13 20:15:29 +0000348}
349
hasso508e53e2004-05-18 18:57:06 +0000350void
351ospf6_lsa_header_print_raw (struct ospf6_lsa_header *header)
paul718e3742002-12-13 20:15:29 +0000352{
hasso508e53e2004-05-18 18:57:06 +0000353 char id[16], adv_router[16];
354 inet_ntop (AF_INET, &header->id, id, sizeof (id));
355 inet_ntop (AF_INET, &header->adv_router, adv_router,
356 sizeof (adv_router));
hassoc6487d62004-12-24 06:00:11 +0000357 zlog_debug (" [%s Id:%s Adv:%s]",
358 ospf6_lstype_name (header->type), id, adv_router);
359 zlog_debug (" Age: %4hu SeqNum: %#08lx Cksum: %04hx Len: %d",
360 ntohs (header->age), (u_long) ntohl (header->seqnum),
361 ntohs (header->checksum), ntohs (header->length));
paul718e3742002-12-13 20:15:29 +0000362}
363
hasso508e53e2004-05-18 18:57:06 +0000364void
365ospf6_lsa_header_print (struct ospf6_lsa *lsa)
paul718e3742002-12-13 20:15:29 +0000366{
hasso508e53e2004-05-18 18:57:06 +0000367 ospf6_lsa_age_current (lsa);
368 ospf6_lsa_header_print_raw (lsa->header);
paul718e3742002-12-13 20:15:29 +0000369}
370
371void
paul718e3742002-12-13 20:15:29 +0000372ospf6_lsa_show_summary_header (struct vty *vty)
373{
374 vty_out (vty, "%-12s %-15s %-15s %4s %8s %4s %4s %-8s%s",
375 "Type", "LSId", "AdvRouter", "Age", "SeqNum",
hasso049207c2004-08-04 20:02:13 +0000376 "Cksm", "Len", "Duration", VNL);
paul718e3742002-12-13 20:15:29 +0000377}
378
379void
380ospf6_lsa_show_summary (struct vty *vty, struct ospf6_lsa *lsa)
381{
hasso508e53e2004-05-18 18:57:06 +0000382 char adv_router[16], id[16];
paul718e3742002-12-13 20:15:29 +0000383 struct timeval now, res;
384 char duration[16];
385
386 assert (lsa);
387 assert (lsa->header);
388
paul718e3742002-12-13 20:15:29 +0000389 inet_ntop (AF_INET, &lsa->header->id, id, sizeof (id));
390 inet_ntop (AF_INET, &lsa->header->adv_router, adv_router,
391 sizeof (adv_router));
392
Takashi Sogabe86f72dc2009-06-22 13:07:02 +0900393 quagga_gettime (QUAGGA_CLK_MONOTONIC, &now);
hasso508e53e2004-05-18 18:57:06 +0000394 timersub (&now, &lsa->installed, &res);
395 timerstring (&res, duration, sizeof (duration));
paul718e3742002-12-13 20:15:29 +0000396
397 vty_out (vty, "%-12s %-15s %-15s %4hu %8lx %04hx %4hu %8s%s",
hasso1e058382004-09-01 21:36:14 +0000398 ospf6_lstype_name (lsa->header->type),
hasso508e53e2004-05-18 18:57:06 +0000399 id, adv_router, ospf6_lsa_age_current (lsa),
paul718e3742002-12-13 20:15:29 +0000400 (u_long) ntohl (lsa->header->seqnum),
401 ntohs (lsa->header->checksum), ntohs (lsa->header->length),
hasso049207c2004-08-04 20:02:13 +0000402 duration, VNL);
paul718e3742002-12-13 20:15:29 +0000403}
404
405void
406ospf6_lsa_show_dump (struct vty *vty, struct ospf6_lsa *lsa)
407{
408 u_char *start, *end, *current;
409 char byte[4];
410
hasso03d52f82004-09-29 00:26:19 +0000411 start = (u_char *) lsa->header;
412 end = (u_char *) lsa->header + ntohs (lsa->header->length);
paul718e3742002-12-13 20:15:29 +0000413
hasso049207c2004-08-04 20:02:13 +0000414 vty_out (vty, "%s", VNL);
415 vty_out (vty, "%s:%s", lsa->name, VNL);
paul718e3742002-12-13 20:15:29 +0000416
417 for (current = start; current < end; current ++)
418 {
419 if ((current - start) % 16 == 0)
hasso049207c2004-08-04 20:02:13 +0000420 vty_out (vty, "%s ", VNL);
paul718e3742002-12-13 20:15:29 +0000421 else if ((current - start) % 4 == 0)
422 vty_out (vty, " ");
423
424 snprintf (byte, sizeof (byte), "%02x", *current);
425 vty_out (vty, "%s", byte);
426 }
427
hasso049207c2004-08-04 20:02:13 +0000428 vty_out (vty, "%s%s", VNL, VNL);
hasso6452df02004-08-15 05:52:07 +0000429 return;
paul718e3742002-12-13 20:15:29 +0000430}
431
hasso508e53e2004-05-18 18:57:06 +0000432void
433ospf6_lsa_show_internal (struct vty *vty, struct ospf6_lsa *lsa)
434{
435 char adv_router[64], id[64];
436
437 assert (lsa && lsa->header);
438
439 inet_ntop (AF_INET, &lsa->header->id, id, sizeof (id));
440 inet_ntop (AF_INET, &lsa->header->adv_router,
441 adv_router, sizeof (adv_router));
442
hasso049207c2004-08-04 20:02:13 +0000443 vty_out (vty, "%s", VNL);
hasso508e53e2004-05-18 18:57:06 +0000444 vty_out (vty, "Age: %4hu Type: %s%s", ospf6_lsa_age_current (lsa),
hasso1e058382004-09-01 21:36:14 +0000445 ospf6_lstype_name (lsa->header->type), VNL);
hasso049207c2004-08-04 20:02:13 +0000446 vty_out (vty, "Link State ID: %s%s", id, VNL);
447 vty_out (vty, "Advertising Router: %s%s", adv_router, VNL);
hasso508e53e2004-05-18 18:57:06 +0000448 vty_out (vty, "LS Sequence Number: %#010lx%s",
hasso049207c2004-08-04 20:02:13 +0000449 (u_long) ntohl (lsa->header->seqnum), VNL);
hasso508e53e2004-05-18 18:57:06 +0000450 vty_out (vty, "CheckSum: %#06hx Length: %hu%s",
451 ntohs (lsa->header->checksum),
hasso049207c2004-08-04 20:02:13 +0000452 ntohs (lsa->header->length), VNL);
Dinesh Dutt8ae454e2013-08-24 07:54:41 +0000453 vty_out (vty, "Flag: %x %s", lsa->flag, VNL);
454 vty_out (vty, "Lock: %d %s", lsa->lock, VNL);
455 vty_out (vty, "ReTx Count: %d%s", lsa->retrans_count, VNL);
456 vty_out (vty, "Threads: Expire: %x, Refresh: %x %s",
457 lsa->expire, lsa->refresh, VNL);
hasso049207c2004-08-04 20:02:13 +0000458 vty_out (vty, "%s", VNL);
hasso6452df02004-08-15 05:52:07 +0000459 return;
460}
461
462void
463ospf6_lsa_show (struct vty *vty, struct ospf6_lsa *lsa)
464{
465 char adv_router[64], id[64];
hasso1e058382004-09-01 21:36:14 +0000466 struct ospf6_lsa_handler *handler;
hasso6452df02004-08-15 05:52:07 +0000467
468 assert (lsa && lsa->header);
469
470 inet_ntop (AF_INET, &lsa->header->id, id, sizeof (id));
471 inet_ntop (AF_INET, &lsa->header->adv_router,
472 adv_router, sizeof (adv_router));
473
474 vty_out (vty, "Age: %4hu Type: %s%s", ospf6_lsa_age_current (lsa),
hasso1e058382004-09-01 21:36:14 +0000475 ospf6_lstype_name (lsa->header->type), VNL);
hasso6452df02004-08-15 05:52:07 +0000476 vty_out (vty, "Link State ID: %s%s", id, VNL);
477 vty_out (vty, "Advertising Router: %s%s", adv_router, VNL);
478 vty_out (vty, "LS Sequence Number: %#010lx%s",
479 (u_long) ntohl (lsa->header->seqnum), VNL);
480 vty_out (vty, "CheckSum: %#06hx Length: %hu%s",
481 ntohs (lsa->header->checksum),
482 ntohs (lsa->header->length), VNL);
483
hasso1e058382004-09-01 21:36:14 +0000484 handler = ospf6_get_lsa_handler (lsa->header->type);
485 if (handler->show == NULL)
486 handler = &unknown_handler;
487 (*handler->show) (vty, lsa);
hasso6452df02004-08-15 05:52:07 +0000488
489 vty_out (vty, "%s", VNL);
hasso508e53e2004-05-18 18:57:06 +0000490}
491
paul718e3742002-12-13 20:15:29 +0000492/* OSPFv3 LSA creation/deletion function */
paul718e3742002-12-13 20:15:29 +0000493struct ospf6_lsa *
hasso508e53e2004-05-18 18:57:06 +0000494ospf6_lsa_create (struct ospf6_lsa_header *header)
paul718e3742002-12-13 20:15:29 +0000495{
496 struct ospf6_lsa *lsa = NULL;
hasso508e53e2004-05-18 18:57:06 +0000497 struct ospf6_lsa_header *new_header = NULL;
paul718e3742002-12-13 20:15:29 +0000498 u_int16_t lsa_size = 0;
paul718e3742002-12-13 20:15:29 +0000499
hasso508e53e2004-05-18 18:57:06 +0000500 /* size of the entire LSA */
501 lsa_size = ntohs (header->length); /* XXX vulnerable */
paul718e3742002-12-13 20:15:29 +0000502
503 /* allocate memory for this LSA */
hasso508e53e2004-05-18 18:57:06 +0000504 new_header = (struct ospf6_lsa_header *)
paul718e3742002-12-13 20:15:29 +0000505 XMALLOC (MTYPE_OSPF6_LSA, lsa_size);
paul718e3742002-12-13 20:15:29 +0000506
hasso508e53e2004-05-18 18:57:06 +0000507 /* copy LSA from original header */
508 memcpy (new_header, header, lsa_size);
paul718e3742002-12-13 20:15:29 +0000509
510 /* LSA information structure */
511 /* allocate memory */
512 lsa = (struct ospf6_lsa *)
Stephen Hemminger393deb92008-08-18 14:13:29 -0700513 XCALLOC (MTYPE_OSPF6_LSA, sizeof (struct ospf6_lsa));
paul718e3742002-12-13 20:15:29 +0000514
hasso508e53e2004-05-18 18:57:06 +0000515 lsa->header = (struct ospf6_lsa_header *) new_header;
paul718e3742002-12-13 20:15:29 +0000516
517 /* dump string */
hasso508e53e2004-05-18 18:57:06 +0000518 ospf6_lsa_printbuf (lsa, lsa->name, sizeof (lsa->name));
paul718e3742002-12-13 20:15:29 +0000519
hasso3b687352004-08-19 06:56:53 +0000520 /* calculate birth of this lsa */
paul718e3742002-12-13 20:15:29 +0000521 ospf6_lsa_age_set (lsa);
522
paul718e3742002-12-13 20:15:29 +0000523 return lsa;
524}
525
526struct ospf6_lsa *
hasso508e53e2004-05-18 18:57:06 +0000527ospf6_lsa_create_headeronly (struct ospf6_lsa_header *header)
paul718e3742002-12-13 20:15:29 +0000528{
529 struct ospf6_lsa *lsa = NULL;
hasso508e53e2004-05-18 18:57:06 +0000530 struct ospf6_lsa_header *new_header = NULL;
paul718e3742002-12-13 20:15:29 +0000531
532 /* allocate memory for this LSA */
hasso508e53e2004-05-18 18:57:06 +0000533 new_header = (struct ospf6_lsa_header *)
534 XMALLOC (MTYPE_OSPF6_LSA, sizeof (struct ospf6_lsa_header));
paul718e3742002-12-13 20:15:29 +0000535
hasso508e53e2004-05-18 18:57:06 +0000536 /* copy LSA from original header */
537 memcpy (new_header, header, sizeof (struct ospf6_lsa_header));
paul718e3742002-12-13 20:15:29 +0000538
539 /* LSA information structure */
540 /* allocate memory */
541 lsa = (struct ospf6_lsa *)
Stephen Hemminger393deb92008-08-18 14:13:29 -0700542 XCALLOC (MTYPE_OSPF6_LSA, sizeof (struct ospf6_lsa));
paul718e3742002-12-13 20:15:29 +0000543
hasso508e53e2004-05-18 18:57:06 +0000544 lsa->header = (struct ospf6_lsa_header *) new_header;
hasso6452df02004-08-15 05:52:07 +0000545 SET_FLAG (lsa->flag, OSPF6_LSA_HEADERONLY);
paul718e3742002-12-13 20:15:29 +0000546
547 /* dump string */
hasso508e53e2004-05-18 18:57:06 +0000548 ospf6_lsa_printbuf (lsa, lsa->name, sizeof (lsa->name));
paul718e3742002-12-13 20:15:29 +0000549
hasso3b687352004-08-19 06:56:53 +0000550 /* calculate birth of this lsa */
paul718e3742002-12-13 20:15:29 +0000551 ospf6_lsa_age_set (lsa);
552
paul718e3742002-12-13 20:15:29 +0000553 return lsa;
554}
555
556void
557ospf6_lsa_delete (struct ospf6_lsa *lsa)
558{
hasso508e53e2004-05-18 18:57:06 +0000559 assert (lsa->lock == 0);
paul718e3742002-12-13 20:15:29 +0000560
561 /* cancel threads */
hasso508e53e2004-05-18 18:57:06 +0000562 THREAD_OFF (lsa->expire);
563 THREAD_OFF (lsa->refresh);
paul718e3742002-12-13 20:15:29 +0000564
paul718e3742002-12-13 20:15:29 +0000565 /* do free */
hasso508e53e2004-05-18 18:57:06 +0000566 XFREE (MTYPE_OSPF6_LSA, lsa->header);
567 XFREE (MTYPE_OSPF6_LSA, lsa);
paul718e3742002-12-13 20:15:29 +0000568}
569
hasso508e53e2004-05-18 18:57:06 +0000570struct ospf6_lsa *
571ospf6_lsa_copy (struct ospf6_lsa *lsa)
572{
573 struct ospf6_lsa *copy = NULL;
574
hasso508e53e2004-05-18 18:57:06 +0000575 ospf6_lsa_age_current (lsa);
hasso6452df02004-08-15 05:52:07 +0000576 if (CHECK_FLAG (lsa->flag, OSPF6_LSA_HEADERONLY))
hasso508e53e2004-05-18 18:57:06 +0000577 copy = ospf6_lsa_create_headeronly (lsa->header);
578 else
579 copy = ospf6_lsa_create (lsa->header);
580 assert (copy->lock == 0);
581
hasso3b687352004-08-19 06:56:53 +0000582 copy->birth = lsa->birth;
hasso508e53e2004-05-18 18:57:06 +0000583 copy->originated = lsa->originated;
hassoccb59b12004-08-25 09:10:37 +0000584 copy->received = lsa->received;
585 copy->installed = lsa->installed;
hasso6452df02004-08-15 05:52:07 +0000586 copy->lsdb = lsa->lsdb;
Dinesh Dutta765eb92013-08-24 07:55:14 +0000587 copy->rn = NULL;
hasso508e53e2004-05-18 18:57:06 +0000588
hasso508e53e2004-05-18 18:57:06 +0000589 return copy;
590}
591
592/* increment reference counter of struct ospf6_lsa */
paul718e3742002-12-13 20:15:29 +0000593void
594ospf6_lsa_lock (struct ospf6_lsa *lsa)
595{
596 lsa->lock++;
597 return;
598}
599
hasso508e53e2004-05-18 18:57:06 +0000600/* decrement reference counter of struct ospf6_lsa */
paul718e3742002-12-13 20:15:29 +0000601void
602ospf6_lsa_unlock (struct ospf6_lsa *lsa)
603{
604 /* decrement reference counter */
hasso508e53e2004-05-18 18:57:06 +0000605 assert (lsa->lock > 0);
606 lsa->lock--;
paul718e3742002-12-13 20:15:29 +0000607
hasso508e53e2004-05-18 18:57:06 +0000608 if (lsa->lock != 0)
609 return;
610
hasso508e53e2004-05-18 18:57:06 +0000611 ospf6_lsa_delete (lsa);
paul718e3742002-12-13 20:15:29 +0000612}
613
paul718e3742002-12-13 20:15:29 +0000614
hasso508e53e2004-05-18 18:57:06 +0000615/* ospf6 lsa expiry */
paul718e3742002-12-13 20:15:29 +0000616int
617ospf6_lsa_expire (struct thread *thread)
618{
619 struct ospf6_lsa *lsa;
paul718e3742002-12-13 20:15:29 +0000620
621 lsa = (struct ospf6_lsa *) THREAD_ARG (thread);
paul718e3742002-12-13 20:15:29 +0000622
hasso508e53e2004-05-18 18:57:06 +0000623 assert (lsa && lsa->header);
624 assert (OSPF6_LSA_IS_MAXAGE (lsa));
625 assert (! lsa->refresh);
paul718e3742002-12-13 20:15:29 +0000626
627 lsa->expire = (struct thread *) NULL;
628
hasso1e058382004-09-01 21:36:14 +0000629 if (IS_OSPF6_DEBUG_LSA_TYPE (lsa->header->type))
paul718e3742002-12-13 20:15:29 +0000630 {
hassoc6487d62004-12-24 06:00:11 +0000631 zlog_debug ("LSA Expire:");
hasso508e53e2004-05-18 18:57:06 +0000632 ospf6_lsa_header_print (lsa);
paul718e3742002-12-13 20:15:29 +0000633 }
634
hasso6452df02004-08-15 05:52:07 +0000635 if (CHECK_FLAG (lsa->flag, OSPF6_LSA_HEADERONLY))
hasso508e53e2004-05-18 18:57:06 +0000636 return 0; /* dbexchange will do something ... */
637
hasso508e53e2004-05-18 18:57:06 +0000638 /* reinstall lsa */
hasso3b687352004-08-19 06:56:53 +0000639 ospf6_install_lsa (lsa);
hasso508e53e2004-05-18 18:57:06 +0000640
Dinesh Duttbf986da2013-08-24 07:54:50 +0000641 /* reflood lsa */
642 ospf6_flood (NULL, lsa);
643
hasso508e53e2004-05-18 18:57:06 +0000644 /* schedule maxage remover */
645 ospf6_maxage_remove (ospf6);
646
paul718e3742002-12-13 20:15:29 +0000647 return 0;
648}
649
650int
651ospf6_lsa_refresh (struct thread *thread)
652{
hasso6452df02004-08-15 05:52:07 +0000653 struct ospf6_lsa *old, *self, *new;
654 struct ospf6_lsdb *lsdb_self;
paul718e3742002-12-13 20:15:29 +0000655
656 assert (thread);
hasso6452df02004-08-15 05:52:07 +0000657 old = (struct ospf6_lsa *) THREAD_ARG (thread);
658 assert (old && old->header);
paul718e3742002-12-13 20:15:29 +0000659
hasso6452df02004-08-15 05:52:07 +0000660 old->refresh = (struct thread *) NULL;
paul718e3742002-12-13 20:15:29 +0000661
hasso6452df02004-08-15 05:52:07 +0000662 lsdb_self = ospf6_get_scoped_lsdb_self (old);
663 self = ospf6_lsdb_lookup (old->header->type, old->header->id,
664 old->header->adv_router, lsdb_self);
665 if (self == NULL)
666 {
hasso1e058382004-09-01 21:36:14 +0000667 if (IS_OSPF6_DEBUG_LSA_TYPE (old->header->type))
hassoc6487d62004-12-24 06:00:11 +0000668 zlog_debug ("Refresh: could not find self LSA, flush %s", old->name);
hasso6452df02004-08-15 05:52:07 +0000669 ospf6_lsa_premature_aging (old);
670 return 0;
671 }
672
673 /* Reset age, increment LS sequence number. */
674 self->header->age = htons (0);
675 self->header->seqnum =
676 ospf6_new_ls_seqnum (self->header->type, self->header->id,
677 self->header->adv_router, old->lsdb);
678 ospf6_lsa_checksum (self->header);
679
680 new = ospf6_lsa_create (self->header);
681 new->lsdb = old->lsdb;
682 new->refresh = thread_add_timer (master, ospf6_lsa_refresh, new,
Dinesh Dutt8551e6d2013-10-22 17:42:18 -0700683 OSPF_LS_REFRESH_TIME);
hasso6452df02004-08-15 05:52:07 +0000684
685 /* store it in the LSDB for self-originated LSAs */
686 ospf6_lsdb_add (ospf6_lsa_copy (new), lsdb_self);
paul718e3742002-12-13 20:15:29 +0000687
hasso1e058382004-09-01 21:36:14 +0000688 if (IS_OSPF6_DEBUG_LSA_TYPE (new->header->type))
paul718e3742002-12-13 20:15:29 +0000689 {
hassoc6487d62004-12-24 06:00:11 +0000690 zlog_debug ("LSA Refresh:");
hasso6452df02004-08-15 05:52:07 +0000691 ospf6_lsa_header_print (new);
paul718e3742002-12-13 20:15:29 +0000692 }
693
hasso6452df02004-08-15 05:52:07 +0000694 ospf6_install_lsa (new);
Dinesh Duttbf986da2013-08-24 07:54:50 +0000695 ospf6_flood (NULL, new);
hasso6452df02004-08-15 05:52:07 +0000696
hasso508e53e2004-05-18 18:57:06 +0000697 return 0;
paul718e3742002-12-13 20:15:29 +0000698}
699
700
701
JR Riversd8a4e422012-09-13 17:17:36 +0000702/* Fletcher Checksum -- Refer to RFC1008. */
paul718e3742002-12-13 20:15:29 +0000703
JR Riversd8a4e422012-09-13 17:17:36 +0000704/* All the offsets are zero-based. The offsets in the RFC1008 are
705 one-based. */
paul718e3742002-12-13 20:15:29 +0000706unsigned short
707ospf6_lsa_checksum (struct ospf6_lsa_header *lsa_header)
708{
JR Riversd8a4e422012-09-13 17:17:36 +0000709 u_char *buffer = (u_char *) &lsa_header->type;
710 int type_offset = buffer - (u_char *) &lsa_header->age; /* should be 2 */
paul718e3742002-12-13 20:15:29 +0000711
JR Riversd8a4e422012-09-13 17:17:36 +0000712 /* Skip the AGE field */
713 u_int16_t len = ntohs(lsa_header->length) - type_offset;
paul718e3742002-12-13 20:15:29 +0000714
JR Riversd8a4e422012-09-13 17:17:36 +0000715 /* Checksum offset starts from "type" field, not the beginning of the
716 lsa_header struct. The offset is 14, rather than 16. */
717 int checksum_offset = (u_char *) &lsa_header->checksum - buffer;
paul718e3742002-12-13 20:15:29 +0000718
JR Riversd8a4e422012-09-13 17:17:36 +0000719 return (unsigned short)fletcher_checksum(buffer, len, checksum_offset);
720}
paul718e3742002-12-13 20:15:29 +0000721
JR Riversd8a4e422012-09-13 17:17:36 +0000722int
723ospf6_lsa_checksum_valid (struct ospf6_lsa_header *lsa_header)
724{
725 u_char *buffer = (u_char *) &lsa_header->type;
726 int type_offset = buffer - (u_char *) &lsa_header->age; /* should be 2 */
paul718e3742002-12-13 20:15:29 +0000727
JR Riversd8a4e422012-09-13 17:17:36 +0000728 /* Skip the AGE field */
729 u_int16_t len = ntohs(lsa_header->length) - type_offset;
730
731 return (fletcher_checksum(buffer, len, FLETCHER_CHECKSUM_VALIDATE) == 0);
paul718e3742002-12-13 20:15:29 +0000732}
733
hasso6452df02004-08-15 05:52:07 +0000734void
Paul Jakma6ac29a52008-08-15 13:45:30 +0100735ospf6_lsa_init (void)
paul718e3742002-12-13 20:15:29 +0000736{
hasso1e058382004-09-01 21:36:14 +0000737 ospf6_lsa_handler_vector = vector_init (0);
hasso6452df02004-08-15 05:52:07 +0000738 ospf6_install_lsa_handler (&unknown_handler);
paul718e3742002-12-13 20:15:29 +0000739}
740
Tom Goffae2254a2010-11-10 13:01:41 -0800741void
742ospf6_lsa_terminate (void)
743{
744 vector_free (ospf6_lsa_handler_vector);
745}
hasso508e53e2004-05-18 18:57:06 +0000746
Paul Jakma6ac29a52008-08-15 13:45:30 +0100747static char *
hasso1e058382004-09-01 21:36:14 +0000748ospf6_lsa_handler_name (struct ospf6_lsa_handler *h)
hasso508e53e2004-05-18 18:57:06 +0000749{
hasso1e058382004-09-01 21:36:14 +0000750 static char buf[64];
paul0c083ee2004-10-10 12:54:58 +0000751 unsigned int i;
752 unsigned int size = strlen (h->name);
hasso508e53e2004-05-18 18:57:06 +0000753
Dinesh Dutt09df4572013-08-24 07:54:31 +0000754 if (!strcmp(h->name, "unknown") &&
hasso1e058382004-09-01 21:36:14 +0000755 h->type != OSPF6_LSTYPE_UNKNOWN)
hasso508e53e2004-05-18 18:57:06 +0000756 {
hasso1e058382004-09-01 21:36:14 +0000757 snprintf (buf, sizeof (buf), "%#04hx", h->type);
758 return buf;
hasso508e53e2004-05-18 18:57:06 +0000759 }
760
hasso1e058382004-09-01 21:36:14 +0000761 for (i = 0; i < MIN (size, sizeof (buf)); i++)
hasso508e53e2004-05-18 18:57:06 +0000762 {
hasso1e058382004-09-01 21:36:14 +0000763 if (! islower (h->name[i]))
764 buf[i] = tolower (h->name[i]);
hasso508e53e2004-05-18 18:57:06 +0000765 else
hasso1e058382004-09-01 21:36:14 +0000766 buf[i] = h->name[i];
767 }
768 buf[size] = '\0';
769 return buf;
770}
hasso508e53e2004-05-18 18:57:06 +0000771
hasso1e058382004-09-01 21:36:14 +0000772DEFUN (debug_ospf6_lsa_type,
773 debug_ospf6_lsa_hex_cmd,
Dinesh Dutt09df4572013-08-24 07:54:31 +0000774 "debug ospf6 lsa (router|network|inter-prefix|inter-router|as-ext|grp-mbr|type7|link|intra-prefix|unknown)",
hasso1e058382004-09-01 21:36:14 +0000775 DEBUG_STR
776 OSPF6_STR
777 "Debug Link State Advertisements (LSAs)\n"
778 "Specify LS type as Hexadecimal\n"
779 )
780{
paul0c083ee2004-10-10 12:54:58 +0000781 unsigned int i;
hasso1e058382004-09-01 21:36:14 +0000782 struct ospf6_lsa_handler *handler = NULL;
hasso1e058382004-09-01 21:36:14 +0000783
784 assert (argc);
785
paul55468c82005-03-14 20:19:01 +0000786 for (i = 0; i < vector_active (ospf6_lsa_handler_vector); i++)
hasso1e058382004-09-01 21:36:14 +0000787 {
788 handler = vector_slot (ospf6_lsa_handler_vector, i);
789 if (handler == NULL)
790 continue;
Dinesh Dutt09df4572013-08-24 07:54:31 +0000791 if (strncmp (argv[0], ospf6_lsa_handler_name(handler), strlen(argv[0])) == 0)
hasso1e058382004-09-01 21:36:14 +0000792 break;
793 if (! strcasecmp (argv[0], handler->name))
794 break;
795 handler = NULL;
796 }
797
hasso1e058382004-09-01 21:36:14 +0000798 if (handler == NULL)
799 handler = &unknown_handler;
800
801 if (argc >= 2)
802 {
803 if (! strcmp (argv[1], "originate"))
804 SET_FLAG (handler->debug, OSPF6_LSA_DEBUG_ORIGINATE);
Dinesh Dutt09df4572013-08-24 07:54:31 +0000805 if (! strcmp (argv[1], "examine"))
hasso1e058382004-09-01 21:36:14 +0000806 SET_FLAG (handler->debug, OSPF6_LSA_DEBUG_EXAMIN);
807 if (! strcmp (argv[1], "flooding"))
808 SET_FLAG (handler->debug, OSPF6_LSA_DEBUG_FLOOD);
809 }
810 else
811 SET_FLAG (handler->debug, OSPF6_LSA_DEBUG);
812
813 return CMD_SUCCESS;
hasso508e53e2004-05-18 18:57:06 +0000814}
815
Dinesh Dutt09df4572013-08-24 07:54:31 +0000816ALIAS (debug_ospf6_lsa_type,
817 debug_ospf6_lsa_hex_detail_cmd,
818 "debug ospf6 lsa (router|network|inter-prefix|inter-router|as-ext|grp-mbr|type7|link|intra-prefix|unknown) (originate|examine|flooding)",
819 DEBUG_STR
820 OSPF6_STR
821 "Debug Link State Advertisements (LSAs)\n"
822 "Specify LS type as Hexadecimal\n"
823 )
824
hasso1e058382004-09-01 21:36:14 +0000825DEFUN (no_debug_ospf6_lsa_type,
826 no_debug_ospf6_lsa_hex_cmd,
Dinesh Dutt09df4572013-08-24 07:54:31 +0000827 "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 +0000828 NO_STR
829 DEBUG_STR
830 OSPF6_STR
831 "Debug Link State Advertisements (LSAs)\n"
832 "Specify LS type as Hexadecimal\n"
833 )
834{
paul0c083ee2004-10-10 12:54:58 +0000835 u_int i;
hasso1e058382004-09-01 21:36:14 +0000836 struct ospf6_lsa_handler *handler = NULL;
hasso1e058382004-09-01 21:36:14 +0000837
838 assert (argc);
839
paul55468c82005-03-14 20:19:01 +0000840 for (i = 0; i < vector_active (ospf6_lsa_handler_vector); i++)
hasso1e058382004-09-01 21:36:14 +0000841 {
842 handler = vector_slot (ospf6_lsa_handler_vector, i);
843 if (handler == NULL)
844 continue;
Dinesh Dutt09df4572013-08-24 07:54:31 +0000845 if (strncmp (argv[0], ospf6_lsa_handler_name(handler), strlen(argv[0])) == 0)
hasso1e058382004-09-01 21:36:14 +0000846 break;
847 if (! strcasecmp (argv[0], handler->name))
848 break;
849 }
850
851 if (handler == NULL)
852 return CMD_SUCCESS;
853
854 if (argc >= 2)
855 {
856 if (! strcmp (argv[1], "originate"))
857 UNSET_FLAG (handler->debug, OSPF6_LSA_DEBUG_ORIGINATE);
Dinesh Dutt09df4572013-08-24 07:54:31 +0000858 if (! strcmp (argv[1], "examine"))
hasso1e058382004-09-01 21:36:14 +0000859 UNSET_FLAG (handler->debug, OSPF6_LSA_DEBUG_EXAMIN);
860 if (! strcmp (argv[1], "flooding"))
861 UNSET_FLAG (handler->debug, OSPF6_LSA_DEBUG_FLOOD);
862 }
863 else
864 UNSET_FLAG (handler->debug, OSPF6_LSA_DEBUG);
865
hasso1e058382004-09-01 21:36:14 +0000866 return CMD_SUCCESS;
867}
868
Dinesh Dutt09df4572013-08-24 07:54:31 +0000869ALIAS (no_debug_ospf6_lsa_type,
870 no_debug_ospf6_lsa_hex_detail_cmd,
871 "no debug ospf6 lsa (router|network|inter-prefix|inter-router|as-ext|grp-mbr|type7|link|intra-prefix) (originate|examine|flooding)",
872 NO_STR
873 DEBUG_STR
874 OSPF6_STR
875 "Debug Link State Advertisements (LSAs)\n"
876 "Specify LS type as Hexadecimal\n"
877 )
hasso1e058382004-09-01 21:36:14 +0000878
hasso508e53e2004-05-18 18:57:06 +0000879void
Paul Jakma6ac29a52008-08-15 13:45:30 +0100880install_element_ospf6_debug_lsa (void)
hasso508e53e2004-05-18 18:57:06 +0000881{
hasso1e058382004-09-01 21:36:14 +0000882 install_element (ENABLE_NODE, &debug_ospf6_lsa_hex_cmd);
Dinesh Dutt09df4572013-08-24 07:54:31 +0000883 install_element (ENABLE_NODE, &debug_ospf6_lsa_hex_detail_cmd);
hasso1e058382004-09-01 21:36:14 +0000884 install_element (ENABLE_NODE, &no_debug_ospf6_lsa_hex_cmd);
Dinesh Dutt09df4572013-08-24 07:54:31 +0000885 install_element (ENABLE_NODE, &no_debug_ospf6_lsa_hex_detail_cmd);
hasso1e058382004-09-01 21:36:14 +0000886 install_element (CONFIG_NODE, &debug_ospf6_lsa_hex_cmd);
Dinesh Dutt09df4572013-08-24 07:54:31 +0000887 install_element (CONFIG_NODE, &debug_ospf6_lsa_hex_detail_cmd);
hasso1e058382004-09-01 21:36:14 +0000888 install_element (CONFIG_NODE, &no_debug_ospf6_lsa_hex_cmd);
Dinesh Dutt09df4572013-08-24 07:54:31 +0000889 install_element (CONFIG_NODE, &no_debug_ospf6_lsa_hex_detail_cmd);
hasso1e058382004-09-01 21:36:14 +0000890}
891
892int
893config_write_ospf6_debug_lsa (struct vty *vty)
894{
paul0c083ee2004-10-10 12:54:58 +0000895 u_int i;
hasso1e058382004-09-01 21:36:14 +0000896 struct ospf6_lsa_handler *handler;
897
paul55468c82005-03-14 20:19:01 +0000898 for (i = 0; i < vector_active (ospf6_lsa_handler_vector); i++)
hasso1e058382004-09-01 21:36:14 +0000899 {
900 handler = vector_slot (ospf6_lsa_handler_vector, i);
901 if (handler == NULL)
902 continue;
903 if (CHECK_FLAG (handler->debug, OSPF6_LSA_DEBUG))
904 vty_out (vty, "debug ospf6 lsa %s%s",
905 ospf6_lsa_handler_name (handler), VNL);
906 if (CHECK_FLAG (handler->debug, OSPF6_LSA_DEBUG_ORIGINATE))
907 vty_out (vty, "debug ospf6 lsa %s originate%s",
908 ospf6_lsa_handler_name (handler), VNL);
909 if (CHECK_FLAG (handler->debug, OSPF6_LSA_DEBUG_EXAMIN))
Dinesh Dutt09df4572013-08-24 07:54:31 +0000910 vty_out (vty, "debug ospf6 lsa %s examine%s",
hasso1e058382004-09-01 21:36:14 +0000911 ospf6_lsa_handler_name (handler), VNL);
912 if (CHECK_FLAG (handler->debug, OSPF6_LSA_DEBUG_FLOOD))
913 vty_out (vty, "debug ospf6 lsa %s flooding%s",
914 ospf6_lsa_handler_name (handler), VNL);
915 }
916
917 return 0;
hasso508e53e2004-05-18 18:57:06 +0000918}
919
920