blob: db14731f4075d4fdbb3fbeaef6cd5e4cc726e3b5 [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);
hasso508e53e2004-05-18 18:57:06 +0000453 vty_out (vty, " Prev: %p This: %p Next: %p%s",
hasso049207c2004-08-04 20:02:13 +0000454 lsa->prev, lsa, lsa->next, VNL);
Dinesh Dutt8ae454e2013-08-24 07:54:41 +0000455 vty_out (vty, "Flag: %x %s", lsa->flag, VNL);
456 vty_out (vty, "Lock: %d %s", lsa->lock, VNL);
457 vty_out (vty, "ReTx Count: %d%s", lsa->retrans_count, VNL);
458 vty_out (vty, "Threads: Expire: %x, Refresh: %x %s",
459 lsa->expire, lsa->refresh, VNL);
hasso049207c2004-08-04 20:02:13 +0000460 vty_out (vty, "%s", VNL);
hasso6452df02004-08-15 05:52:07 +0000461 return;
462}
463
464void
465ospf6_lsa_show (struct vty *vty, struct ospf6_lsa *lsa)
466{
467 char adv_router[64], id[64];
hasso1e058382004-09-01 21:36:14 +0000468 struct ospf6_lsa_handler *handler;
hasso6452df02004-08-15 05:52:07 +0000469
470 assert (lsa && lsa->header);
471
472 inet_ntop (AF_INET, &lsa->header->id, id, sizeof (id));
473 inet_ntop (AF_INET, &lsa->header->adv_router,
474 adv_router, sizeof (adv_router));
475
476 vty_out (vty, "Age: %4hu Type: %s%s", ospf6_lsa_age_current (lsa),
hasso1e058382004-09-01 21:36:14 +0000477 ospf6_lstype_name (lsa->header->type), VNL);
hasso6452df02004-08-15 05:52:07 +0000478 vty_out (vty, "Link State ID: %s%s", id, VNL);
479 vty_out (vty, "Advertising Router: %s%s", adv_router, VNL);
480 vty_out (vty, "LS Sequence Number: %#010lx%s",
481 (u_long) ntohl (lsa->header->seqnum), VNL);
482 vty_out (vty, "CheckSum: %#06hx Length: %hu%s",
483 ntohs (lsa->header->checksum),
484 ntohs (lsa->header->length), VNL);
485
hasso1e058382004-09-01 21:36:14 +0000486 handler = ospf6_get_lsa_handler (lsa->header->type);
487 if (handler->show == NULL)
488 handler = &unknown_handler;
489 (*handler->show) (vty, lsa);
hasso6452df02004-08-15 05:52:07 +0000490
491 vty_out (vty, "%s", VNL);
hasso508e53e2004-05-18 18:57:06 +0000492}
493
paul718e3742002-12-13 20:15:29 +0000494/* OSPFv3 LSA creation/deletion function */
paul718e3742002-12-13 20:15:29 +0000495struct ospf6_lsa *
hasso508e53e2004-05-18 18:57:06 +0000496ospf6_lsa_create (struct ospf6_lsa_header *header)
paul718e3742002-12-13 20:15:29 +0000497{
498 struct ospf6_lsa *lsa = NULL;
hasso508e53e2004-05-18 18:57:06 +0000499 struct ospf6_lsa_header *new_header = NULL;
paul718e3742002-12-13 20:15:29 +0000500 u_int16_t lsa_size = 0;
paul718e3742002-12-13 20:15:29 +0000501
hasso508e53e2004-05-18 18:57:06 +0000502 /* size of the entire LSA */
503 lsa_size = ntohs (header->length); /* XXX vulnerable */
paul718e3742002-12-13 20:15:29 +0000504
505 /* allocate memory for this LSA */
hasso508e53e2004-05-18 18:57:06 +0000506 new_header = (struct ospf6_lsa_header *)
paul718e3742002-12-13 20:15:29 +0000507 XMALLOC (MTYPE_OSPF6_LSA, lsa_size);
paul718e3742002-12-13 20:15:29 +0000508
hasso508e53e2004-05-18 18:57:06 +0000509 /* copy LSA from original header */
510 memcpy (new_header, header, lsa_size);
paul718e3742002-12-13 20:15:29 +0000511
512 /* LSA information structure */
513 /* allocate memory */
514 lsa = (struct ospf6_lsa *)
Stephen Hemminger393deb92008-08-18 14:13:29 -0700515 XCALLOC (MTYPE_OSPF6_LSA, sizeof (struct ospf6_lsa));
paul718e3742002-12-13 20:15:29 +0000516
hasso508e53e2004-05-18 18:57:06 +0000517 lsa->header = (struct ospf6_lsa_header *) new_header;
paul718e3742002-12-13 20:15:29 +0000518
519 /* dump string */
hasso508e53e2004-05-18 18:57:06 +0000520 ospf6_lsa_printbuf (lsa, lsa->name, sizeof (lsa->name));
paul718e3742002-12-13 20:15:29 +0000521
hasso3b687352004-08-19 06:56:53 +0000522 /* calculate birth of this lsa */
paul718e3742002-12-13 20:15:29 +0000523 ospf6_lsa_age_set (lsa);
524
paul718e3742002-12-13 20:15:29 +0000525 return lsa;
526}
527
528struct ospf6_lsa *
hasso508e53e2004-05-18 18:57:06 +0000529ospf6_lsa_create_headeronly (struct ospf6_lsa_header *header)
paul718e3742002-12-13 20:15:29 +0000530{
531 struct ospf6_lsa *lsa = NULL;
hasso508e53e2004-05-18 18:57:06 +0000532 struct ospf6_lsa_header *new_header = NULL;
paul718e3742002-12-13 20:15:29 +0000533
534 /* allocate memory for this LSA */
hasso508e53e2004-05-18 18:57:06 +0000535 new_header = (struct ospf6_lsa_header *)
536 XMALLOC (MTYPE_OSPF6_LSA, sizeof (struct ospf6_lsa_header));
paul718e3742002-12-13 20:15:29 +0000537
hasso508e53e2004-05-18 18:57:06 +0000538 /* copy LSA from original header */
539 memcpy (new_header, header, sizeof (struct ospf6_lsa_header));
paul718e3742002-12-13 20:15:29 +0000540
541 /* LSA information structure */
542 /* allocate memory */
543 lsa = (struct ospf6_lsa *)
Stephen Hemminger393deb92008-08-18 14:13:29 -0700544 XCALLOC (MTYPE_OSPF6_LSA, sizeof (struct ospf6_lsa));
paul718e3742002-12-13 20:15:29 +0000545
hasso508e53e2004-05-18 18:57:06 +0000546 lsa->header = (struct ospf6_lsa_header *) new_header;
hasso6452df02004-08-15 05:52:07 +0000547 SET_FLAG (lsa->flag, OSPF6_LSA_HEADERONLY);
paul718e3742002-12-13 20:15:29 +0000548
549 /* dump string */
hasso508e53e2004-05-18 18:57:06 +0000550 ospf6_lsa_printbuf (lsa, lsa->name, sizeof (lsa->name));
paul718e3742002-12-13 20:15:29 +0000551
hasso3b687352004-08-19 06:56:53 +0000552 /* calculate birth of this lsa */
paul718e3742002-12-13 20:15:29 +0000553 ospf6_lsa_age_set (lsa);
554
paul718e3742002-12-13 20:15:29 +0000555 return lsa;
556}
557
558void
559ospf6_lsa_delete (struct ospf6_lsa *lsa)
560{
hasso508e53e2004-05-18 18:57:06 +0000561 assert (lsa->lock == 0);
paul718e3742002-12-13 20:15:29 +0000562
563 /* cancel threads */
hasso508e53e2004-05-18 18:57:06 +0000564 THREAD_OFF (lsa->expire);
565 THREAD_OFF (lsa->refresh);
paul718e3742002-12-13 20:15:29 +0000566
paul718e3742002-12-13 20:15:29 +0000567 /* do free */
hasso508e53e2004-05-18 18:57:06 +0000568 XFREE (MTYPE_OSPF6_LSA, lsa->header);
569 XFREE (MTYPE_OSPF6_LSA, lsa);
paul718e3742002-12-13 20:15:29 +0000570}
571
hasso508e53e2004-05-18 18:57:06 +0000572struct ospf6_lsa *
573ospf6_lsa_copy (struct ospf6_lsa *lsa)
574{
575 struct ospf6_lsa *copy = NULL;
576
hasso508e53e2004-05-18 18:57:06 +0000577 ospf6_lsa_age_current (lsa);
hasso6452df02004-08-15 05:52:07 +0000578 if (CHECK_FLAG (lsa->flag, OSPF6_LSA_HEADERONLY))
hasso508e53e2004-05-18 18:57:06 +0000579 copy = ospf6_lsa_create_headeronly (lsa->header);
580 else
581 copy = ospf6_lsa_create (lsa->header);
582 assert (copy->lock == 0);
583
hasso3b687352004-08-19 06:56:53 +0000584 copy->birth = lsa->birth;
hasso508e53e2004-05-18 18:57:06 +0000585 copy->originated = lsa->originated;
hassoccb59b12004-08-25 09:10:37 +0000586 copy->received = lsa->received;
587 copy->installed = lsa->installed;
hasso6452df02004-08-15 05:52:07 +0000588 copy->lsdb = lsa->lsdb;
hasso508e53e2004-05-18 18:57:06 +0000589
hasso508e53e2004-05-18 18:57:06 +0000590 return copy;
591}
592
593/* increment reference counter of struct ospf6_lsa */
paul718e3742002-12-13 20:15:29 +0000594void
595ospf6_lsa_lock (struct ospf6_lsa *lsa)
596{
597 lsa->lock++;
598 return;
599}
600
hasso508e53e2004-05-18 18:57:06 +0000601/* decrement reference counter of struct ospf6_lsa */
paul718e3742002-12-13 20:15:29 +0000602void
603ospf6_lsa_unlock (struct ospf6_lsa *lsa)
604{
605 /* decrement reference counter */
hasso508e53e2004-05-18 18:57:06 +0000606 assert (lsa->lock > 0);
607 lsa->lock--;
paul718e3742002-12-13 20:15:29 +0000608
hasso508e53e2004-05-18 18:57:06 +0000609 if (lsa->lock != 0)
610 return;
611
hasso508e53e2004-05-18 18:57:06 +0000612 ospf6_lsa_delete (lsa);
paul718e3742002-12-13 20:15:29 +0000613}
614
paul718e3742002-12-13 20:15:29 +0000615
hasso508e53e2004-05-18 18:57:06 +0000616/* ospf6 lsa expiry */
paul718e3742002-12-13 20:15:29 +0000617int
618ospf6_lsa_expire (struct thread *thread)
619{
620 struct ospf6_lsa *lsa;
paul718e3742002-12-13 20:15:29 +0000621
622 lsa = (struct ospf6_lsa *) THREAD_ARG (thread);
paul718e3742002-12-13 20:15:29 +0000623
hasso508e53e2004-05-18 18:57:06 +0000624 assert (lsa && lsa->header);
625 assert (OSPF6_LSA_IS_MAXAGE (lsa));
626 assert (! lsa->refresh);
paul718e3742002-12-13 20:15:29 +0000627
628 lsa->expire = (struct thread *) NULL;
629
hasso1e058382004-09-01 21:36:14 +0000630 if (IS_OSPF6_DEBUG_LSA_TYPE (lsa->header->type))
paul718e3742002-12-13 20:15:29 +0000631 {
hassoc6487d62004-12-24 06:00:11 +0000632 zlog_debug ("LSA Expire:");
hasso508e53e2004-05-18 18:57:06 +0000633 ospf6_lsa_header_print (lsa);
paul718e3742002-12-13 20:15:29 +0000634 }
635
hasso6452df02004-08-15 05:52:07 +0000636 if (CHECK_FLAG (lsa->flag, OSPF6_LSA_HEADERONLY))
hasso508e53e2004-05-18 18:57:06 +0000637 return 0; /* dbexchange will do something ... */
638
hasso508e53e2004-05-18 18:57:06 +0000639 /* reinstall lsa */
hasso3b687352004-08-19 06:56:53 +0000640 ospf6_install_lsa (lsa);
hasso508e53e2004-05-18 18:57:06 +0000641
Dinesh Duttbf986da2013-08-24 07:54:50 +0000642 /* reflood lsa */
643 ospf6_flood (NULL, lsa);
644
hasso508e53e2004-05-18 18:57:06 +0000645 /* schedule maxage remover */
646 ospf6_maxage_remove (ospf6);
647
paul718e3742002-12-13 20:15:29 +0000648 return 0;
649}
650
651int
652ospf6_lsa_refresh (struct thread *thread)
653{
hasso6452df02004-08-15 05:52:07 +0000654 struct ospf6_lsa *old, *self, *new;
655 struct ospf6_lsdb *lsdb_self;
paul718e3742002-12-13 20:15:29 +0000656
657 assert (thread);
hasso6452df02004-08-15 05:52:07 +0000658 old = (struct ospf6_lsa *) THREAD_ARG (thread);
659 assert (old && old->header);
paul718e3742002-12-13 20:15:29 +0000660
hasso6452df02004-08-15 05:52:07 +0000661 old->refresh = (struct thread *) NULL;
paul718e3742002-12-13 20:15:29 +0000662
hasso6452df02004-08-15 05:52:07 +0000663 lsdb_self = ospf6_get_scoped_lsdb_self (old);
664 self = ospf6_lsdb_lookup (old->header->type, old->header->id,
665 old->header->adv_router, lsdb_self);
666 if (self == NULL)
667 {
hasso1e058382004-09-01 21:36:14 +0000668 if (IS_OSPF6_DEBUG_LSA_TYPE (old->header->type))
hassoc6487d62004-12-24 06:00:11 +0000669 zlog_debug ("Refresh: could not find self LSA, flush %s", old->name);
hasso6452df02004-08-15 05:52:07 +0000670 ospf6_lsa_premature_aging (old);
671 return 0;
672 }
673
674 /* Reset age, increment LS sequence number. */
675 self->header->age = htons (0);
676 self->header->seqnum =
677 ospf6_new_ls_seqnum (self->header->type, self->header->id,
678 self->header->adv_router, old->lsdb);
679 ospf6_lsa_checksum (self->header);
680
681 new = ospf6_lsa_create (self->header);
682 new->lsdb = old->lsdb;
683 new->refresh = thread_add_timer (master, ospf6_lsa_refresh, new,
Dinesh Dutt8551e6d2013-10-22 17:42:18 -0700684 OSPF_LS_REFRESH_TIME);
hasso6452df02004-08-15 05:52:07 +0000685
686 /* store it in the LSDB for self-originated LSAs */
687 ospf6_lsdb_add (ospf6_lsa_copy (new), lsdb_self);
paul718e3742002-12-13 20:15:29 +0000688
hasso1e058382004-09-01 21:36:14 +0000689 if (IS_OSPF6_DEBUG_LSA_TYPE (new->header->type))
paul718e3742002-12-13 20:15:29 +0000690 {
hassoc6487d62004-12-24 06:00:11 +0000691 zlog_debug ("LSA Refresh:");
hasso6452df02004-08-15 05:52:07 +0000692 ospf6_lsa_header_print (new);
paul718e3742002-12-13 20:15:29 +0000693 }
694
hasso6452df02004-08-15 05:52:07 +0000695 ospf6_install_lsa (new);
Dinesh Duttbf986da2013-08-24 07:54:50 +0000696 ospf6_flood (NULL, new);
hasso6452df02004-08-15 05:52:07 +0000697
hasso508e53e2004-05-18 18:57:06 +0000698 return 0;
paul718e3742002-12-13 20:15:29 +0000699}
700
701
702
JR Riversd8a4e422012-09-13 17:17:36 +0000703/* Fletcher Checksum -- Refer to RFC1008. */
paul718e3742002-12-13 20:15:29 +0000704
JR Riversd8a4e422012-09-13 17:17:36 +0000705/* All the offsets are zero-based. The offsets in the RFC1008 are
706 one-based. */
paul718e3742002-12-13 20:15:29 +0000707unsigned short
708ospf6_lsa_checksum (struct ospf6_lsa_header *lsa_header)
709{
JR Riversd8a4e422012-09-13 17:17:36 +0000710 u_char *buffer = (u_char *) &lsa_header->type;
711 int type_offset = buffer - (u_char *) &lsa_header->age; /* should be 2 */
paul718e3742002-12-13 20:15:29 +0000712
JR Riversd8a4e422012-09-13 17:17:36 +0000713 /* Skip the AGE field */
714 u_int16_t len = ntohs(lsa_header->length) - type_offset;
paul718e3742002-12-13 20:15:29 +0000715
JR Riversd8a4e422012-09-13 17:17:36 +0000716 /* Checksum offset starts from "type" field, not the beginning of the
717 lsa_header struct. The offset is 14, rather than 16. */
718 int checksum_offset = (u_char *) &lsa_header->checksum - buffer;
paul718e3742002-12-13 20:15:29 +0000719
JR Riversd8a4e422012-09-13 17:17:36 +0000720 return (unsigned short)fletcher_checksum(buffer, len, checksum_offset);
721}
paul718e3742002-12-13 20:15:29 +0000722
JR Riversd8a4e422012-09-13 17:17:36 +0000723int
724ospf6_lsa_checksum_valid (struct ospf6_lsa_header *lsa_header)
725{
726 u_char *buffer = (u_char *) &lsa_header->type;
727 int type_offset = buffer - (u_char *) &lsa_header->age; /* should be 2 */
paul718e3742002-12-13 20:15:29 +0000728
JR Riversd8a4e422012-09-13 17:17:36 +0000729 /* Skip the AGE field */
730 u_int16_t len = ntohs(lsa_header->length) - type_offset;
731
732 return (fletcher_checksum(buffer, len, FLETCHER_CHECKSUM_VALIDATE) == 0);
paul718e3742002-12-13 20:15:29 +0000733}
734
hasso6452df02004-08-15 05:52:07 +0000735void
Paul Jakma6ac29a52008-08-15 13:45:30 +0100736ospf6_lsa_init (void)
paul718e3742002-12-13 20:15:29 +0000737{
hasso1e058382004-09-01 21:36:14 +0000738 ospf6_lsa_handler_vector = vector_init (0);
hasso6452df02004-08-15 05:52:07 +0000739 ospf6_install_lsa_handler (&unknown_handler);
paul718e3742002-12-13 20:15:29 +0000740}
741
Tom Goffae2254a2010-11-10 13:01:41 -0800742void
743ospf6_lsa_terminate (void)
744{
745 vector_free (ospf6_lsa_handler_vector);
746}
hasso508e53e2004-05-18 18:57:06 +0000747
Paul Jakma6ac29a52008-08-15 13:45:30 +0100748static char *
hasso1e058382004-09-01 21:36:14 +0000749ospf6_lsa_handler_name (struct ospf6_lsa_handler *h)
hasso508e53e2004-05-18 18:57:06 +0000750{
hasso1e058382004-09-01 21:36:14 +0000751 static char buf[64];
paul0c083ee2004-10-10 12:54:58 +0000752 unsigned int i;
753 unsigned int size = strlen (h->name);
hasso508e53e2004-05-18 18:57:06 +0000754
Dinesh Dutt09df4572013-08-24 07:54:31 +0000755 if (!strcmp(h->name, "unknown") &&
hasso1e058382004-09-01 21:36:14 +0000756 h->type != OSPF6_LSTYPE_UNKNOWN)
hasso508e53e2004-05-18 18:57:06 +0000757 {
hasso1e058382004-09-01 21:36:14 +0000758 snprintf (buf, sizeof (buf), "%#04hx", h->type);
759 return buf;
hasso508e53e2004-05-18 18:57:06 +0000760 }
761
hasso1e058382004-09-01 21:36:14 +0000762 for (i = 0; i < MIN (size, sizeof (buf)); i++)
hasso508e53e2004-05-18 18:57:06 +0000763 {
hasso1e058382004-09-01 21:36:14 +0000764 if (! islower (h->name[i]))
765 buf[i] = tolower (h->name[i]);
hasso508e53e2004-05-18 18:57:06 +0000766 else
hasso1e058382004-09-01 21:36:14 +0000767 buf[i] = h->name[i];
768 }
769 buf[size] = '\0';
770 return buf;
771}
hasso508e53e2004-05-18 18:57:06 +0000772
hasso1e058382004-09-01 21:36:14 +0000773DEFUN (debug_ospf6_lsa_type,
774 debug_ospf6_lsa_hex_cmd,
Dinesh Dutt09df4572013-08-24 07:54:31 +0000775 "debug ospf6 lsa (router|network|inter-prefix|inter-router|as-ext|grp-mbr|type7|link|intra-prefix|unknown)",
hasso1e058382004-09-01 21:36:14 +0000776 DEBUG_STR
777 OSPF6_STR
778 "Debug Link State Advertisements (LSAs)\n"
779 "Specify LS type as Hexadecimal\n"
780 )
781{
paul0c083ee2004-10-10 12:54:58 +0000782 unsigned int i;
hasso1e058382004-09-01 21:36:14 +0000783 struct ospf6_lsa_handler *handler = NULL;
hasso1e058382004-09-01 21:36:14 +0000784
785 assert (argc);
786
paul55468c82005-03-14 20:19:01 +0000787 for (i = 0; i < vector_active (ospf6_lsa_handler_vector); i++)
hasso1e058382004-09-01 21:36:14 +0000788 {
789 handler = vector_slot (ospf6_lsa_handler_vector, i);
790 if (handler == NULL)
791 continue;
Dinesh Dutt09df4572013-08-24 07:54:31 +0000792 if (strncmp (argv[0], ospf6_lsa_handler_name(handler), strlen(argv[0])) == 0)
hasso1e058382004-09-01 21:36:14 +0000793 break;
794 if (! strcasecmp (argv[0], handler->name))
795 break;
796 handler = NULL;
797 }
798
hasso1e058382004-09-01 21:36:14 +0000799 if (handler == NULL)
800 handler = &unknown_handler;
801
802 if (argc >= 2)
803 {
804 if (! strcmp (argv[1], "originate"))
805 SET_FLAG (handler->debug, OSPF6_LSA_DEBUG_ORIGINATE);
Dinesh Dutt09df4572013-08-24 07:54:31 +0000806 if (! strcmp (argv[1], "examine"))
hasso1e058382004-09-01 21:36:14 +0000807 SET_FLAG (handler->debug, OSPF6_LSA_DEBUG_EXAMIN);
808 if (! strcmp (argv[1], "flooding"))
809 SET_FLAG (handler->debug, OSPF6_LSA_DEBUG_FLOOD);
810 }
811 else
812 SET_FLAG (handler->debug, OSPF6_LSA_DEBUG);
813
814 return CMD_SUCCESS;
hasso508e53e2004-05-18 18:57:06 +0000815}
816
Dinesh Dutt09df4572013-08-24 07:54:31 +0000817ALIAS (debug_ospf6_lsa_type,
818 debug_ospf6_lsa_hex_detail_cmd,
819 "debug ospf6 lsa (router|network|inter-prefix|inter-router|as-ext|grp-mbr|type7|link|intra-prefix|unknown) (originate|examine|flooding)",
820 DEBUG_STR
821 OSPF6_STR
822 "Debug Link State Advertisements (LSAs)\n"
823 "Specify LS type as Hexadecimal\n"
824 )
825
hasso1e058382004-09-01 21:36:14 +0000826DEFUN (no_debug_ospf6_lsa_type,
827 no_debug_ospf6_lsa_hex_cmd,
Dinesh Dutt09df4572013-08-24 07:54:31 +0000828 "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 +0000829 NO_STR
830 DEBUG_STR
831 OSPF6_STR
832 "Debug Link State Advertisements (LSAs)\n"
833 "Specify LS type as Hexadecimal\n"
834 )
835{
paul0c083ee2004-10-10 12:54:58 +0000836 u_int i;
hasso1e058382004-09-01 21:36:14 +0000837 struct ospf6_lsa_handler *handler = NULL;
hasso1e058382004-09-01 21:36:14 +0000838
839 assert (argc);
840
paul55468c82005-03-14 20:19:01 +0000841 for (i = 0; i < vector_active (ospf6_lsa_handler_vector); i++)
hasso1e058382004-09-01 21:36:14 +0000842 {
843 handler = vector_slot (ospf6_lsa_handler_vector, i);
844 if (handler == NULL)
845 continue;
Dinesh Dutt09df4572013-08-24 07:54:31 +0000846 if (strncmp (argv[0], ospf6_lsa_handler_name(handler), strlen(argv[0])) == 0)
hasso1e058382004-09-01 21:36:14 +0000847 break;
848 if (! strcasecmp (argv[0], handler->name))
849 break;
850 }
851
852 if (handler == NULL)
853 return CMD_SUCCESS;
854
855 if (argc >= 2)
856 {
857 if (! strcmp (argv[1], "originate"))
858 UNSET_FLAG (handler->debug, OSPF6_LSA_DEBUG_ORIGINATE);
Dinesh Dutt09df4572013-08-24 07:54:31 +0000859 if (! strcmp (argv[1], "examine"))
hasso1e058382004-09-01 21:36:14 +0000860 UNSET_FLAG (handler->debug, OSPF6_LSA_DEBUG_EXAMIN);
861 if (! strcmp (argv[1], "flooding"))
862 UNSET_FLAG (handler->debug, OSPF6_LSA_DEBUG_FLOOD);
863 }
864 else
865 UNSET_FLAG (handler->debug, OSPF6_LSA_DEBUG);
866
hasso1e058382004-09-01 21:36:14 +0000867 return CMD_SUCCESS;
868}
869
Dinesh Dutt09df4572013-08-24 07:54:31 +0000870ALIAS (no_debug_ospf6_lsa_type,
871 no_debug_ospf6_lsa_hex_detail_cmd,
872 "no debug ospf6 lsa (router|network|inter-prefix|inter-router|as-ext|grp-mbr|type7|link|intra-prefix) (originate|examine|flooding)",
873 NO_STR
874 DEBUG_STR
875 OSPF6_STR
876 "Debug Link State Advertisements (LSAs)\n"
877 "Specify LS type as Hexadecimal\n"
878 )
hasso1e058382004-09-01 21:36:14 +0000879
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{
hasso1e058382004-09-01 21:36:14 +0000883 install_element (ENABLE_NODE, &debug_ospf6_lsa_hex_cmd);
Dinesh Dutt09df4572013-08-24 07:54:31 +0000884 install_element (ENABLE_NODE, &debug_ospf6_lsa_hex_detail_cmd);
hasso1e058382004-09-01 21:36:14 +0000885 install_element (ENABLE_NODE, &no_debug_ospf6_lsa_hex_cmd);
Dinesh Dutt09df4572013-08-24 07:54:31 +0000886 install_element (ENABLE_NODE, &no_debug_ospf6_lsa_hex_detail_cmd);
hasso1e058382004-09-01 21:36:14 +0000887 install_element (CONFIG_NODE, &debug_ospf6_lsa_hex_cmd);
Dinesh Dutt09df4572013-08-24 07:54:31 +0000888 install_element (CONFIG_NODE, &debug_ospf6_lsa_hex_detail_cmd);
hasso1e058382004-09-01 21:36:14 +0000889 install_element (CONFIG_NODE, &no_debug_ospf6_lsa_hex_cmd);
Dinesh Dutt09df4572013-08-24 07:54:31 +0000890 install_element (CONFIG_NODE, &no_debug_ospf6_lsa_hex_detail_cmd);
hasso1e058382004-09-01 21:36:14 +0000891}
892
893int
894config_write_ospf6_debug_lsa (struct vty *vty)
895{
paul0c083ee2004-10-10 12:54:58 +0000896 u_int i;
hasso1e058382004-09-01 21:36:14 +0000897 struct ospf6_lsa_handler *handler;
898
paul55468c82005-03-14 20:19:01 +0000899 for (i = 0; i < vector_active (ospf6_lsa_handler_vector); i++)
hasso1e058382004-09-01 21:36:14 +0000900 {
901 handler = vector_slot (ospf6_lsa_handler_vector, i);
902 if (handler == NULL)
903 continue;
904 if (CHECK_FLAG (handler->debug, OSPF6_LSA_DEBUG))
905 vty_out (vty, "debug ospf6 lsa %s%s",
906 ospf6_lsa_handler_name (handler), VNL);
907 if (CHECK_FLAG (handler->debug, OSPF6_LSA_DEBUG_ORIGINATE))
908 vty_out (vty, "debug ospf6 lsa %s originate%s",
909 ospf6_lsa_handler_name (handler), VNL);
910 if (CHECK_FLAG (handler->debug, OSPF6_LSA_DEBUG_EXAMIN))
Dinesh Dutt09df4572013-08-24 07:54:31 +0000911 vty_out (vty, "debug ospf6 lsa %s examine%s",
hasso1e058382004-09-01 21:36:14 +0000912 ospf6_lsa_handler_name (handler), VNL);
913 if (CHECK_FLAG (handler->debug, OSPF6_LSA_DEBUG_FLOOD))
914 vty_out (vty, "debug ospf6 lsa %s flooding%s",
915 ospf6_lsa_handler_name (handler), VNL);
916 }
917
918 return 0;
hasso508e53e2004-05-18 18:57:06 +0000919}
920
921