blob: 3be08ef613d77ab2cfd1bb0a2cc92b43fcc0ce1e [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);
455 vty_out (vty, "%s", VNL);
hasso6452df02004-08-15 05:52:07 +0000456 return;
457}
458
459void
460ospf6_lsa_show (struct vty *vty, struct ospf6_lsa *lsa)
461{
462 char adv_router[64], id[64];
hasso1e058382004-09-01 21:36:14 +0000463 struct ospf6_lsa_handler *handler;
hasso6452df02004-08-15 05:52:07 +0000464
465 assert (lsa && lsa->header);
466
467 inet_ntop (AF_INET, &lsa->header->id, id, sizeof (id));
468 inet_ntop (AF_INET, &lsa->header->adv_router,
469 adv_router, sizeof (adv_router));
470
471 vty_out (vty, "Age: %4hu Type: %s%s", ospf6_lsa_age_current (lsa),
hasso1e058382004-09-01 21:36:14 +0000472 ospf6_lstype_name (lsa->header->type), VNL);
hasso6452df02004-08-15 05:52:07 +0000473 vty_out (vty, "Link State ID: %s%s", id, VNL);
474 vty_out (vty, "Advertising Router: %s%s", adv_router, VNL);
475 vty_out (vty, "LS Sequence Number: %#010lx%s",
476 (u_long) ntohl (lsa->header->seqnum), VNL);
477 vty_out (vty, "CheckSum: %#06hx Length: %hu%s",
478 ntohs (lsa->header->checksum),
479 ntohs (lsa->header->length), VNL);
480
hasso1e058382004-09-01 21:36:14 +0000481 handler = ospf6_get_lsa_handler (lsa->header->type);
482 if (handler->show == NULL)
483 handler = &unknown_handler;
484 (*handler->show) (vty, lsa);
hasso6452df02004-08-15 05:52:07 +0000485
486 vty_out (vty, "%s", VNL);
hasso508e53e2004-05-18 18:57:06 +0000487}
488
paul718e3742002-12-13 20:15:29 +0000489/* OSPFv3 LSA creation/deletion function */
paul718e3742002-12-13 20:15:29 +0000490struct ospf6_lsa *
hasso508e53e2004-05-18 18:57:06 +0000491ospf6_lsa_create (struct ospf6_lsa_header *header)
paul718e3742002-12-13 20:15:29 +0000492{
493 struct ospf6_lsa *lsa = NULL;
hasso508e53e2004-05-18 18:57:06 +0000494 struct ospf6_lsa_header *new_header = NULL;
paul718e3742002-12-13 20:15:29 +0000495 u_int16_t lsa_size = 0;
paul718e3742002-12-13 20:15:29 +0000496
hasso508e53e2004-05-18 18:57:06 +0000497 /* size of the entire LSA */
498 lsa_size = ntohs (header->length); /* XXX vulnerable */
paul718e3742002-12-13 20:15:29 +0000499
500 /* allocate memory for this LSA */
hasso508e53e2004-05-18 18:57:06 +0000501 new_header = (struct ospf6_lsa_header *)
paul718e3742002-12-13 20:15:29 +0000502 XMALLOC (MTYPE_OSPF6_LSA, lsa_size);
paul718e3742002-12-13 20:15:29 +0000503
hasso508e53e2004-05-18 18:57:06 +0000504 /* copy LSA from original header */
505 memcpy (new_header, header, lsa_size);
paul718e3742002-12-13 20:15:29 +0000506
507 /* LSA information structure */
508 /* allocate memory */
509 lsa = (struct ospf6_lsa *)
Stephen Hemminger393deb92008-08-18 14:13:29 -0700510 XCALLOC (MTYPE_OSPF6_LSA, sizeof (struct ospf6_lsa));
paul718e3742002-12-13 20:15:29 +0000511
hasso508e53e2004-05-18 18:57:06 +0000512 lsa->header = (struct ospf6_lsa_header *) new_header;
paul718e3742002-12-13 20:15:29 +0000513
514 /* dump string */
hasso508e53e2004-05-18 18:57:06 +0000515 ospf6_lsa_printbuf (lsa, lsa->name, sizeof (lsa->name));
paul718e3742002-12-13 20:15:29 +0000516
hasso3b687352004-08-19 06:56:53 +0000517 /* calculate birth of this lsa */
paul718e3742002-12-13 20:15:29 +0000518 ospf6_lsa_age_set (lsa);
519
paul718e3742002-12-13 20:15:29 +0000520 return lsa;
521}
522
523struct ospf6_lsa *
hasso508e53e2004-05-18 18:57:06 +0000524ospf6_lsa_create_headeronly (struct ospf6_lsa_header *header)
paul718e3742002-12-13 20:15:29 +0000525{
526 struct ospf6_lsa *lsa = NULL;
hasso508e53e2004-05-18 18:57:06 +0000527 struct ospf6_lsa_header *new_header = NULL;
paul718e3742002-12-13 20:15:29 +0000528
529 /* allocate memory for this LSA */
hasso508e53e2004-05-18 18:57:06 +0000530 new_header = (struct ospf6_lsa_header *)
531 XMALLOC (MTYPE_OSPF6_LSA, sizeof (struct ospf6_lsa_header));
paul718e3742002-12-13 20:15:29 +0000532
hasso508e53e2004-05-18 18:57:06 +0000533 /* copy LSA from original header */
534 memcpy (new_header, header, sizeof (struct ospf6_lsa_header));
paul718e3742002-12-13 20:15:29 +0000535
536 /* LSA information structure */
537 /* allocate memory */
538 lsa = (struct ospf6_lsa *)
Stephen Hemminger393deb92008-08-18 14:13:29 -0700539 XCALLOC (MTYPE_OSPF6_LSA, sizeof (struct ospf6_lsa));
paul718e3742002-12-13 20:15:29 +0000540
hasso508e53e2004-05-18 18:57:06 +0000541 lsa->header = (struct ospf6_lsa_header *) new_header;
hasso6452df02004-08-15 05:52:07 +0000542 SET_FLAG (lsa->flag, OSPF6_LSA_HEADERONLY);
paul718e3742002-12-13 20:15:29 +0000543
544 /* dump string */
hasso508e53e2004-05-18 18:57:06 +0000545 ospf6_lsa_printbuf (lsa, lsa->name, sizeof (lsa->name));
paul718e3742002-12-13 20:15:29 +0000546
hasso3b687352004-08-19 06:56:53 +0000547 /* calculate birth of this lsa */
paul718e3742002-12-13 20:15:29 +0000548 ospf6_lsa_age_set (lsa);
549
paul718e3742002-12-13 20:15:29 +0000550 return lsa;
551}
552
553void
554ospf6_lsa_delete (struct ospf6_lsa *lsa)
555{
hasso508e53e2004-05-18 18:57:06 +0000556 assert (lsa->lock == 0);
paul718e3742002-12-13 20:15:29 +0000557
558 /* cancel threads */
hasso508e53e2004-05-18 18:57:06 +0000559 THREAD_OFF (lsa->expire);
560 THREAD_OFF (lsa->refresh);
paul718e3742002-12-13 20:15:29 +0000561
paul718e3742002-12-13 20:15:29 +0000562 /* do free */
hasso508e53e2004-05-18 18:57:06 +0000563 XFREE (MTYPE_OSPF6_LSA, lsa->header);
564 XFREE (MTYPE_OSPF6_LSA, lsa);
paul718e3742002-12-13 20:15:29 +0000565}
566
hasso508e53e2004-05-18 18:57:06 +0000567struct ospf6_lsa *
568ospf6_lsa_copy (struct ospf6_lsa *lsa)
569{
570 struct ospf6_lsa *copy = NULL;
571
hasso508e53e2004-05-18 18:57:06 +0000572 ospf6_lsa_age_current (lsa);
hasso6452df02004-08-15 05:52:07 +0000573 if (CHECK_FLAG (lsa->flag, OSPF6_LSA_HEADERONLY))
hasso508e53e2004-05-18 18:57:06 +0000574 copy = ospf6_lsa_create_headeronly (lsa->header);
575 else
576 copy = ospf6_lsa_create (lsa->header);
577 assert (copy->lock == 0);
578
hasso3b687352004-08-19 06:56:53 +0000579 copy->birth = lsa->birth;
hasso508e53e2004-05-18 18:57:06 +0000580 copy->originated = lsa->originated;
hassoccb59b12004-08-25 09:10:37 +0000581 copy->received = lsa->received;
582 copy->installed = lsa->installed;
hasso6452df02004-08-15 05:52:07 +0000583 copy->lsdb = lsa->lsdb;
hasso508e53e2004-05-18 18:57:06 +0000584
hasso508e53e2004-05-18 18:57:06 +0000585 return copy;
586}
587
588/* increment reference counter of struct ospf6_lsa */
paul718e3742002-12-13 20:15:29 +0000589void
590ospf6_lsa_lock (struct ospf6_lsa *lsa)
591{
592 lsa->lock++;
593 return;
594}
595
hasso508e53e2004-05-18 18:57:06 +0000596/* decrement reference counter of struct ospf6_lsa */
paul718e3742002-12-13 20:15:29 +0000597void
598ospf6_lsa_unlock (struct ospf6_lsa *lsa)
599{
600 /* decrement reference counter */
hasso508e53e2004-05-18 18:57:06 +0000601 assert (lsa->lock > 0);
602 lsa->lock--;
paul718e3742002-12-13 20:15:29 +0000603
hasso508e53e2004-05-18 18:57:06 +0000604 if (lsa->lock != 0)
605 return;
606
hasso508e53e2004-05-18 18:57:06 +0000607 ospf6_lsa_delete (lsa);
paul718e3742002-12-13 20:15:29 +0000608}
609
paul718e3742002-12-13 20:15:29 +0000610
hasso508e53e2004-05-18 18:57:06 +0000611/* ospf6 lsa expiry */
paul718e3742002-12-13 20:15:29 +0000612int
613ospf6_lsa_expire (struct thread *thread)
614{
615 struct ospf6_lsa *lsa;
paul718e3742002-12-13 20:15:29 +0000616
617 lsa = (struct ospf6_lsa *) THREAD_ARG (thread);
paul718e3742002-12-13 20:15:29 +0000618
hasso508e53e2004-05-18 18:57:06 +0000619 assert (lsa && lsa->header);
620 assert (OSPF6_LSA_IS_MAXAGE (lsa));
621 assert (! lsa->refresh);
paul718e3742002-12-13 20:15:29 +0000622
623 lsa->expire = (struct thread *) NULL;
624
hasso1e058382004-09-01 21:36:14 +0000625 if (IS_OSPF6_DEBUG_LSA_TYPE (lsa->header->type))
paul718e3742002-12-13 20:15:29 +0000626 {
hassoc6487d62004-12-24 06:00:11 +0000627 zlog_debug ("LSA Expire:");
hasso508e53e2004-05-18 18:57:06 +0000628 ospf6_lsa_header_print (lsa);
paul718e3742002-12-13 20:15:29 +0000629 }
630
hasso6452df02004-08-15 05:52:07 +0000631 if (CHECK_FLAG (lsa->flag, OSPF6_LSA_HEADERONLY))
hasso508e53e2004-05-18 18:57:06 +0000632 return 0; /* dbexchange will do something ... */
633
634 /* reflood lsa */
hasso6452df02004-08-15 05:52:07 +0000635 ospf6_flood (NULL, lsa);
hasso508e53e2004-05-18 18:57:06 +0000636
637 /* reinstall lsa */
hasso3b687352004-08-19 06:56:53 +0000638 ospf6_install_lsa (lsa);
hasso508e53e2004-05-18 18:57:06 +0000639
640 /* schedule maxage remover */
641 ospf6_maxage_remove (ospf6);
642
paul718e3742002-12-13 20:15:29 +0000643 return 0;
644}
645
646int
647ospf6_lsa_refresh (struct thread *thread)
648{
hasso6452df02004-08-15 05:52:07 +0000649 struct ospf6_lsa *old, *self, *new;
650 struct ospf6_lsdb *lsdb_self;
paul718e3742002-12-13 20:15:29 +0000651
652 assert (thread);
hasso6452df02004-08-15 05:52:07 +0000653 old = (struct ospf6_lsa *) THREAD_ARG (thread);
654 assert (old && old->header);
paul718e3742002-12-13 20:15:29 +0000655
hasso6452df02004-08-15 05:52:07 +0000656 old->refresh = (struct thread *) NULL;
paul718e3742002-12-13 20:15:29 +0000657
hasso6452df02004-08-15 05:52:07 +0000658 lsdb_self = ospf6_get_scoped_lsdb_self (old);
659 self = ospf6_lsdb_lookup (old->header->type, old->header->id,
660 old->header->adv_router, lsdb_self);
661 if (self == NULL)
662 {
hasso1e058382004-09-01 21:36:14 +0000663 if (IS_OSPF6_DEBUG_LSA_TYPE (old->header->type))
hassoc6487d62004-12-24 06:00:11 +0000664 zlog_debug ("Refresh: could not find self LSA, flush %s", old->name);
hasso6452df02004-08-15 05:52:07 +0000665 ospf6_lsa_premature_aging (old);
666 return 0;
667 }
668
669 /* Reset age, increment LS sequence number. */
670 self->header->age = htons (0);
671 self->header->seqnum =
672 ospf6_new_ls_seqnum (self->header->type, self->header->id,
673 self->header->adv_router, old->lsdb);
674 ospf6_lsa_checksum (self->header);
675
676 new = ospf6_lsa_create (self->header);
677 new->lsdb = old->lsdb;
678 new->refresh = thread_add_timer (master, ospf6_lsa_refresh, new,
Dinesh Dutt8551e6d2013-10-22 17:42:18 -0700679 OSPF_LS_REFRESH_TIME);
hasso6452df02004-08-15 05:52:07 +0000680
681 /* store it in the LSDB for self-originated LSAs */
682 ospf6_lsdb_add (ospf6_lsa_copy (new), lsdb_self);
paul718e3742002-12-13 20:15:29 +0000683
hasso1e058382004-09-01 21:36:14 +0000684 if (IS_OSPF6_DEBUG_LSA_TYPE (new->header->type))
paul718e3742002-12-13 20:15:29 +0000685 {
hassoc6487d62004-12-24 06:00:11 +0000686 zlog_debug ("LSA Refresh:");
hasso6452df02004-08-15 05:52:07 +0000687 ospf6_lsa_header_print (new);
paul718e3742002-12-13 20:15:29 +0000688 }
689
hasso6452df02004-08-15 05:52:07 +0000690 ospf6_flood_clear (old);
691 ospf6_flood (NULL, new);
692 ospf6_install_lsa (new);
693
hasso508e53e2004-05-18 18:57:06 +0000694 return 0;
paul718e3742002-12-13 20:15:29 +0000695}
696
697
698
JR Riversd8a4e422012-09-13 17:17:36 +0000699/* Fletcher Checksum -- Refer to RFC1008. */
paul718e3742002-12-13 20:15:29 +0000700
JR Riversd8a4e422012-09-13 17:17:36 +0000701/* All the offsets are zero-based. The offsets in the RFC1008 are
702 one-based. */
paul718e3742002-12-13 20:15:29 +0000703unsigned short
704ospf6_lsa_checksum (struct ospf6_lsa_header *lsa_header)
705{
JR Riversd8a4e422012-09-13 17:17:36 +0000706 u_char *buffer = (u_char *) &lsa_header->type;
707 int type_offset = buffer - (u_char *) &lsa_header->age; /* should be 2 */
paul718e3742002-12-13 20:15:29 +0000708
JR Riversd8a4e422012-09-13 17:17:36 +0000709 /* Skip the AGE field */
710 u_int16_t len = ntohs(lsa_header->length) - type_offset;
paul718e3742002-12-13 20:15:29 +0000711
JR Riversd8a4e422012-09-13 17:17:36 +0000712 /* Checksum offset starts from "type" field, not the beginning of the
713 lsa_header struct. The offset is 14, rather than 16. */
714 int checksum_offset = (u_char *) &lsa_header->checksum - buffer;
paul718e3742002-12-13 20:15:29 +0000715
JR Riversd8a4e422012-09-13 17:17:36 +0000716 return (unsigned short)fletcher_checksum(buffer, len, checksum_offset);
717}
paul718e3742002-12-13 20:15:29 +0000718
JR Riversd8a4e422012-09-13 17:17:36 +0000719int
720ospf6_lsa_checksum_valid (struct ospf6_lsa_header *lsa_header)
721{
722 u_char *buffer = (u_char *) &lsa_header->type;
723 int type_offset = buffer - (u_char *) &lsa_header->age; /* should be 2 */
paul718e3742002-12-13 20:15:29 +0000724
JR Riversd8a4e422012-09-13 17:17:36 +0000725 /* Skip the AGE field */
726 u_int16_t len = ntohs(lsa_header->length) - type_offset;
727
728 return (fletcher_checksum(buffer, len, FLETCHER_CHECKSUM_VALIDATE) == 0);
paul718e3742002-12-13 20:15:29 +0000729}
730
hasso6452df02004-08-15 05:52:07 +0000731void
Paul Jakma6ac29a52008-08-15 13:45:30 +0100732ospf6_lsa_init (void)
paul718e3742002-12-13 20:15:29 +0000733{
hasso1e058382004-09-01 21:36:14 +0000734 ospf6_lsa_handler_vector = vector_init (0);
hasso6452df02004-08-15 05:52:07 +0000735 ospf6_install_lsa_handler (&unknown_handler);
paul718e3742002-12-13 20:15:29 +0000736}
737
Tom Goffae2254a2010-11-10 13:01:41 -0800738void
739ospf6_lsa_terminate (void)
740{
741 vector_free (ospf6_lsa_handler_vector);
742}
hasso508e53e2004-05-18 18:57:06 +0000743
Paul Jakma6ac29a52008-08-15 13:45:30 +0100744static char *
hasso1e058382004-09-01 21:36:14 +0000745ospf6_lsa_handler_name (struct ospf6_lsa_handler *h)
hasso508e53e2004-05-18 18:57:06 +0000746{
hasso1e058382004-09-01 21:36:14 +0000747 static char buf[64];
paul0c083ee2004-10-10 12:54:58 +0000748 unsigned int i;
749 unsigned int size = strlen (h->name);
hasso508e53e2004-05-18 18:57:06 +0000750
Dinesh Dutt09df4572013-08-24 07:54:31 +0000751 if (!strcmp(h->name, "unknown") &&
hasso1e058382004-09-01 21:36:14 +0000752 h->type != OSPF6_LSTYPE_UNKNOWN)
hasso508e53e2004-05-18 18:57:06 +0000753 {
hasso1e058382004-09-01 21:36:14 +0000754 snprintf (buf, sizeof (buf), "%#04hx", h->type);
755 return buf;
hasso508e53e2004-05-18 18:57:06 +0000756 }
757
hasso1e058382004-09-01 21:36:14 +0000758 for (i = 0; i < MIN (size, sizeof (buf)); i++)
hasso508e53e2004-05-18 18:57:06 +0000759 {
hasso1e058382004-09-01 21:36:14 +0000760 if (! islower (h->name[i]))
761 buf[i] = tolower (h->name[i]);
hasso508e53e2004-05-18 18:57:06 +0000762 else
hasso1e058382004-09-01 21:36:14 +0000763 buf[i] = h->name[i];
764 }
765 buf[size] = '\0';
766 return buf;
767}
hasso508e53e2004-05-18 18:57:06 +0000768
hasso1e058382004-09-01 21:36:14 +0000769DEFUN (debug_ospf6_lsa_type,
770 debug_ospf6_lsa_hex_cmd,
Dinesh Dutt09df4572013-08-24 07:54:31 +0000771 "debug ospf6 lsa (router|network|inter-prefix|inter-router|as-ext|grp-mbr|type7|link|intra-prefix|unknown)",
hasso1e058382004-09-01 21:36:14 +0000772 DEBUG_STR
773 OSPF6_STR
774 "Debug Link State Advertisements (LSAs)\n"
775 "Specify LS type as Hexadecimal\n"
776 )
777{
paul0c083ee2004-10-10 12:54:58 +0000778 unsigned int i;
hasso1e058382004-09-01 21:36:14 +0000779 struct ospf6_lsa_handler *handler = NULL;
hasso1e058382004-09-01 21:36:14 +0000780
781 assert (argc);
782
paul55468c82005-03-14 20:19:01 +0000783 for (i = 0; i < vector_active (ospf6_lsa_handler_vector); i++)
hasso1e058382004-09-01 21:36:14 +0000784 {
785 handler = vector_slot (ospf6_lsa_handler_vector, i);
786 if (handler == NULL)
787 continue;
Dinesh Dutt09df4572013-08-24 07:54:31 +0000788 if (strncmp (argv[0], ospf6_lsa_handler_name(handler), strlen(argv[0])) == 0)
hasso1e058382004-09-01 21:36:14 +0000789 break;
790 if (! strcasecmp (argv[0], handler->name))
791 break;
792 handler = NULL;
793 }
794
hasso1e058382004-09-01 21:36:14 +0000795 if (handler == NULL)
796 handler = &unknown_handler;
797
798 if (argc >= 2)
799 {
800 if (! strcmp (argv[1], "originate"))
801 SET_FLAG (handler->debug, OSPF6_LSA_DEBUG_ORIGINATE);
Dinesh Dutt09df4572013-08-24 07:54:31 +0000802 if (! strcmp (argv[1], "examine"))
hasso1e058382004-09-01 21:36:14 +0000803 SET_FLAG (handler->debug, OSPF6_LSA_DEBUG_EXAMIN);
804 if (! strcmp (argv[1], "flooding"))
805 SET_FLAG (handler->debug, OSPF6_LSA_DEBUG_FLOOD);
806 }
807 else
808 SET_FLAG (handler->debug, OSPF6_LSA_DEBUG);
809
810 return CMD_SUCCESS;
hasso508e53e2004-05-18 18:57:06 +0000811}
812
Dinesh Dutt09df4572013-08-24 07:54:31 +0000813ALIAS (debug_ospf6_lsa_type,
814 debug_ospf6_lsa_hex_detail_cmd,
815 "debug ospf6 lsa (router|network|inter-prefix|inter-router|as-ext|grp-mbr|type7|link|intra-prefix|unknown) (originate|examine|flooding)",
816 DEBUG_STR
817 OSPF6_STR
818 "Debug Link State Advertisements (LSAs)\n"
819 "Specify LS type as Hexadecimal\n"
820 )
821
hasso1e058382004-09-01 21:36:14 +0000822DEFUN (no_debug_ospf6_lsa_type,
823 no_debug_ospf6_lsa_hex_cmd,
Dinesh Dutt09df4572013-08-24 07:54:31 +0000824 "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 +0000825 NO_STR
826 DEBUG_STR
827 OSPF6_STR
828 "Debug Link State Advertisements (LSAs)\n"
829 "Specify LS type as Hexadecimal\n"
830 )
831{
paul0c083ee2004-10-10 12:54:58 +0000832 u_int i;
hasso1e058382004-09-01 21:36:14 +0000833 struct ospf6_lsa_handler *handler = NULL;
hasso1e058382004-09-01 21:36:14 +0000834
835 assert (argc);
836
paul55468c82005-03-14 20:19:01 +0000837 for (i = 0; i < vector_active (ospf6_lsa_handler_vector); i++)
hasso1e058382004-09-01 21:36:14 +0000838 {
839 handler = vector_slot (ospf6_lsa_handler_vector, i);
840 if (handler == NULL)
841 continue;
Dinesh Dutt09df4572013-08-24 07:54:31 +0000842 if (strncmp (argv[0], ospf6_lsa_handler_name(handler), strlen(argv[0])) == 0)
hasso1e058382004-09-01 21:36:14 +0000843 break;
844 if (! strcasecmp (argv[0], handler->name))
845 break;
846 }
847
848 if (handler == NULL)
849 return CMD_SUCCESS;
850
851 if (argc >= 2)
852 {
853 if (! strcmp (argv[1], "originate"))
854 UNSET_FLAG (handler->debug, OSPF6_LSA_DEBUG_ORIGINATE);
Dinesh Dutt09df4572013-08-24 07:54:31 +0000855 if (! strcmp (argv[1], "examine"))
hasso1e058382004-09-01 21:36:14 +0000856 UNSET_FLAG (handler->debug, OSPF6_LSA_DEBUG_EXAMIN);
857 if (! strcmp (argv[1], "flooding"))
858 UNSET_FLAG (handler->debug, OSPF6_LSA_DEBUG_FLOOD);
859 }
860 else
861 UNSET_FLAG (handler->debug, OSPF6_LSA_DEBUG);
862
hasso1e058382004-09-01 21:36:14 +0000863 return CMD_SUCCESS;
864}
865
Dinesh Dutt09df4572013-08-24 07:54:31 +0000866ALIAS (no_debug_ospf6_lsa_type,
867 no_debug_ospf6_lsa_hex_detail_cmd,
868 "no debug ospf6 lsa (router|network|inter-prefix|inter-router|as-ext|grp-mbr|type7|link|intra-prefix) (originate|examine|flooding)",
869 NO_STR
870 DEBUG_STR
871 OSPF6_STR
872 "Debug Link State Advertisements (LSAs)\n"
873 "Specify LS type as Hexadecimal\n"
874 )
hasso1e058382004-09-01 21:36:14 +0000875
hasso508e53e2004-05-18 18:57:06 +0000876void
Paul Jakma6ac29a52008-08-15 13:45:30 +0100877install_element_ospf6_debug_lsa (void)
hasso508e53e2004-05-18 18:57:06 +0000878{
hasso1e058382004-09-01 21:36:14 +0000879 install_element (ENABLE_NODE, &debug_ospf6_lsa_hex_cmd);
Dinesh Dutt09df4572013-08-24 07:54:31 +0000880 install_element (ENABLE_NODE, &debug_ospf6_lsa_hex_detail_cmd);
hasso1e058382004-09-01 21:36:14 +0000881 install_element (ENABLE_NODE, &no_debug_ospf6_lsa_hex_cmd);
Dinesh Dutt09df4572013-08-24 07:54:31 +0000882 install_element (ENABLE_NODE, &no_debug_ospf6_lsa_hex_detail_cmd);
hasso1e058382004-09-01 21:36:14 +0000883 install_element (CONFIG_NODE, &debug_ospf6_lsa_hex_cmd);
Dinesh Dutt09df4572013-08-24 07:54:31 +0000884 install_element (CONFIG_NODE, &debug_ospf6_lsa_hex_detail_cmd);
hasso1e058382004-09-01 21:36:14 +0000885 install_element (CONFIG_NODE, &no_debug_ospf6_lsa_hex_cmd);
Dinesh Dutt09df4572013-08-24 07:54:31 +0000886 install_element (CONFIG_NODE, &no_debug_ospf6_lsa_hex_detail_cmd);
hasso1e058382004-09-01 21:36:14 +0000887}
888
889int
890config_write_ospf6_debug_lsa (struct vty *vty)
891{
paul0c083ee2004-10-10 12:54:58 +0000892 u_int i;
hasso1e058382004-09-01 21:36:14 +0000893 struct ospf6_lsa_handler *handler;
894
paul55468c82005-03-14 20:19:01 +0000895 for (i = 0; i < vector_active (ospf6_lsa_handler_vector); i++)
hasso1e058382004-09-01 21:36:14 +0000896 {
897 handler = vector_slot (ospf6_lsa_handler_vector, i);
898 if (handler == NULL)
899 continue;
900 if (CHECK_FLAG (handler->debug, OSPF6_LSA_DEBUG))
901 vty_out (vty, "debug ospf6 lsa %s%s",
902 ospf6_lsa_handler_name (handler), VNL);
903 if (CHECK_FLAG (handler->debug, OSPF6_LSA_DEBUG_ORIGINATE))
904 vty_out (vty, "debug ospf6 lsa %s originate%s",
905 ospf6_lsa_handler_name (handler), VNL);
906 if (CHECK_FLAG (handler->debug, OSPF6_LSA_DEBUG_EXAMIN))
Dinesh Dutt09df4572013-08-24 07:54:31 +0000907 vty_out (vty, "debug ospf6 lsa %s examine%s",
hasso1e058382004-09-01 21:36:14 +0000908 ospf6_lsa_handler_name (handler), VNL);
909 if (CHECK_FLAG (handler->debug, OSPF6_LSA_DEBUG_FLOOD))
910 vty_out (vty, "debug ospf6 lsa %s flooding%s",
911 ospf6_lsa_handler_name (handler), VNL);
912 }
913
914 return 0;
hasso508e53e2004-05-18 18:57:06 +0000915}
916
917