paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1 | /* |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 2 | * Copyright (C) 2003 Yasuhiro Ohara |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 3 | * |
| 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 */ |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 25 | #include "log.h" |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 26 | #include "linklist.h" |
hasso | 1e05838 | 2004-09-01 21:36:14 +0000 | [diff] [blame] | 27 | #include "vector.h" |
| 28 | #include "vty.h" |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 29 | #include "command.h" |
| 30 | #include "memory.h" |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 31 | #include "thread.h" |
JR Rivers | d8a4e42 | 2012-09-13 17:17:36 +0000 | [diff] [blame] | 32 | #include "checksum.h" |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 33 | |
| 34 | #include "ospf6_proto.h" |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 35 | #include "ospf6_lsa.h" |
| 36 | #include "ospf6_lsdb.h" |
| 37 | #include "ospf6_message.h" |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 38 | |
| 39 | #include "ospf6_top.h" |
| 40 | #include "ospf6_area.h" |
| 41 | #include "ospf6_interface.h" |
| 42 | #include "ospf6_neighbor.h" |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 43 | |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 44 | #include "ospf6_flood.h" |
hasso | 049207c | 2004-08-04 20:02:13 +0000 | [diff] [blame] | 45 | #include "ospf6d.h" |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 46 | |
hasso | 1e05838 | 2004-09-01 21:36:14 +0000 | [diff] [blame] | 47 | vector ospf6_lsa_handler_vector; |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 48 | |
Paul Jakma | 6ac29a5 | 2008-08-15 13:45:30 +0100 | [diff] [blame] | 49 | static int |
hasso | 1e05838 | 2004-09-01 21:36:14 +0000 | [diff] [blame] | 50 | ospf6_unknown_lsa_show (struct vty *vty, struct ospf6_lsa *lsa) |
| 51 | { |
| 52 | u_char *start, *end, *current; |
| 53 | char byte[4]; |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 54 | |
hasso | 03d52f8 | 2004-09-29 00:26:19 +0000 | [diff] [blame] | 55 | start = (u_char *) lsa->header + sizeof (struct ospf6_lsa_header); |
| 56 | end = (u_char *) lsa->header + ntohs (lsa->header->length); |
hasso | 1e05838 | 2004-09-01 21:36:14 +0000 | [diff] [blame] | 57 | |
| 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 | |
| 74 | struct ospf6_lsa_handler unknown_handler = |
| 75 | { |
| 76 | OSPF6_LSTYPE_UNKNOWN, |
Dinesh Dutt | 09df457 | 2013-08-24 07:54:31 +0000 | [diff] [blame] | 77 | "unknown", |
hasso | 1e05838 | 2004-09-01 21:36:14 +0000 | [diff] [blame] | 78 | ospf6_unknown_lsa_show, |
| 79 | OSPF6_LSA_DEBUG, |
| 80 | }; |
| 81 | |
| 82 | void |
| 83 | ospf6_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 | |
| 90 | struct ospf6_lsa_handler * |
| 91 | ospf6_get_lsa_handler (u_int16_t type) |
| 92 | { |
| 93 | struct ospf6_lsa_handler *handler = NULL; |
paul | 0c083ee | 2004-10-10 12:54:58 +0000 | [diff] [blame] | 94 | unsigned int index = ntohs (type) & OSPF6_LSTYPE_FCODE_MASK; |
hasso | 1e05838 | 2004-09-01 21:36:14 +0000 | [diff] [blame] | 95 | |
paul | 55468c8 | 2005-03-14 20:19:01 +0000 | [diff] [blame] | 96 | if (index >= vector_active (ospf6_lsa_handler_vector)) |
hasso | 1e05838 | 2004-09-01 21:36:14 +0000 | [diff] [blame] | 97 | handler = &unknown_handler; |
| 98 | else |
| 99 | handler = vector_slot (ospf6_lsa_handler_vector, index); |
| 100 | |
hasso | 2680aa2 | 2004-11-25 20:54:46 +0000 | [diff] [blame] | 101 | if (handler == NULL) |
| 102 | handler = &unknown_handler; |
| 103 | |
hasso | 1e05838 | 2004-09-01 21:36:14 +0000 | [diff] [blame] | 104 | return handler; |
| 105 | } |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 106 | |
paul | 0c083ee | 2004-10-10 12:54:58 +0000 | [diff] [blame] | 107 | const char * |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 108 | ospf6_lstype_name (u_int16_t type) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 109 | { |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 110 | static char buf[8]; |
hasso | 1e05838 | 2004-09-01 21:36:14 +0000 | [diff] [blame] | 111 | struct ospf6_lsa_handler *handler; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 112 | |
hasso | 1e05838 | 2004-09-01 21:36:14 +0000 | [diff] [blame] | 113 | handler = ospf6_get_lsa_handler (type); |
| 114 | if (handler && handler != &unknown_handler) |
| 115 | return handler->name; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 116 | |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 117 | snprintf (buf, sizeof (buf), "0x%04hx", ntohs (type)); |
| 118 | return buf; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 119 | } |
| 120 | |
hasso | 1e05838 | 2004-09-01 21:36:14 +0000 | [diff] [blame] | 121 | u_char |
| 122 | ospf6_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 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 129 | /* RFC2328: Section 13.2 */ |
| 130 | int |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 131 | ospf6_lsa_is_differ (struct ospf6_lsa *lsa1, |
| 132 | struct ospf6_lsa *lsa2) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 133 | { |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 134 | int len; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 135 | |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 136 | assert (OSPF6_LSA_IS_SAME (lsa1, lsa2)); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 137 | |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 138 | /* XXX, Options ??? */ |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 139 | |
| 140 | ospf6_lsa_age_current (lsa1); |
| 141 | ospf6_lsa_age_current (lsa2); |
Dinesh Dutt | 8551e6d | 2013-10-22 17:42:18 -0700 | [diff] [blame] | 142 | if (ntohs (lsa1->header->age) == OSPF_LSA_MAXAGE && |
| 143 | ntohs (lsa2->header->age) != OSPF_LSA_MAXAGE) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 144 | return 1; |
Dinesh Dutt | 8551e6d | 2013-10-22 17:42:18 -0700 | [diff] [blame] | 145 | if (ntohs (lsa1->header->age) != OSPF_LSA_MAXAGE && |
| 146 | ntohs (lsa2->header->age) == OSPF_LSA_MAXAGE) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 147 | return 1; |
| 148 | |
| 149 | /* compare body */ |
| 150 | if (ntohs (lsa1->header->length) != ntohs (lsa2->header->length)) |
| 151 | return 1; |
| 152 | |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 153 | len = ntohs (lsa1->header->length) - sizeof (struct ospf6_lsa_header); |
| 154 | return memcmp (lsa1->header + 1, lsa2->header + 1, len); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 155 | } |
| 156 | |
| 157 | int |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 158 | ospf6_lsa_is_changed (struct ospf6_lsa *lsa1, |
| 159 | struct ospf6_lsa *lsa2) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 160 | { |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 161 | int length; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 162 | |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 163 | 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 Ovsienko | 09395e2 | 2011-09-26 13:18:36 +0400 | [diff] [blame] | 167 | /* 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; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 175 | |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 176 | length = OSPF6_LSA_SIZE (lsa1->header) - sizeof (struct ospf6_lsa_header); |
Denis Ovsienko | 09395e2 | 2011-09-26 13:18:36 +0400 | [diff] [blame] | 177 | /* Once upper layer verifies LSAs received, length underrun should become a warning. */ |
| 178 | if (length <= 0) |
| 179 | return 0; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 180 | |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 181 | return memcmp (OSPF6_LSA_HEADER_END (lsa1->header), |
| 182 | OSPF6_LSA_HEADER_END (lsa2->header), length); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 183 | } |
| 184 | |
| 185 | /* ospf6 age functions */ |
hasso | 3b68735 | 2004-08-19 06:56:53 +0000 | [diff] [blame] | 186 | /* calculate birth */ |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 187 | static void |
| 188 | ospf6_lsa_age_set (struct ospf6_lsa *lsa) |
| 189 | { |
| 190 | struct timeval now; |
| 191 | |
| 192 | assert (lsa && lsa->header); |
| 193 | |
Takashi Sogabe | 86f72dc | 2009-06-22 13:07:02 +0900 | [diff] [blame] | 194 | if (quagga_gettime (QUAGGA_CLK_MONOTONIC, &now) < 0) |
| 195 | zlog_warn ("LSA: quagga_gettime failed, may fail LSA AGEs: %s", |
ajs | 6099b3b | 2004-11-20 02:06:59 +0000 | [diff] [blame] | 196 | safe_strerror (errno)); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 197 | |
| 198 | lsa->birth.tv_sec = now.tv_sec - ntohs (lsa->header->age); |
| 199 | lsa->birth.tv_usec = now.tv_usec; |
hasso | 3b68735 | 2004-08-19 06:56:53 +0000 | [diff] [blame] | 200 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 201 | 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 */ |
| 206 | u_int16_t |
| 207 | ospf6_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 Sogabe | 86f72dc | 2009-06-22 13:07:02 +0900 | [diff] [blame] | 217 | if (quagga_gettime (QUAGGA_CLK_MONOTONIC, &now) < 0) |
| 218 | zlog_warn ("LSA: quagga_gettime failed, may fail LSA AGEs: %s", |
ajs | 6099b3b | 2004-11-20 02:06:59 +0000 | [diff] [blame] | 219 | safe_strerror (errno)); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 220 | |
Dinesh Dutt | 8551e6d | 2013-10-22 17:42:18 -0700 | [diff] [blame] | 221 | if (ntohs (lsa->header->age) >= OSPF_LSA_MAXAGE) |
Tom Henderson | 9b4ef25 | 2009-07-16 17:20:37 +0100 | [diff] [blame] | 222 | { |
Tom Henderson | aabbb1a | 2009-08-28 15:10:00 +0100 | [diff] [blame] | 223 | /* 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 Dutt | 8551e6d | 2013-10-22 17:42:18 -0700 | [diff] [blame] | 226 | lsa->header->age = htons (OSPF_LSA_MAXAGE); |
| 227 | return OSPF_LSA_MAXAGE; |
Tom Henderson | 9b4ef25 | 2009-07-16 17:20:37 +0100 | [diff] [blame] | 228 | } |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 229 | /* calculate age */ |
| 230 | ulage = now.tv_sec - lsa->birth.tv_sec; |
| 231 | |
| 232 | /* if over MAXAGE, set to it */ |
Dinesh Dutt | 8551e6d | 2013-10-22 17:42:18 -0700 | [diff] [blame] | 233 | age = (ulage > OSPF_LSA_MAXAGE ? OSPF_LSA_MAXAGE : ulage); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 234 | |
| 235 | lsa->header->age = htons (age); |
| 236 | return age; |
| 237 | } |
| 238 | |
| 239 | /* update age field of LSA header with adding InfTransDelay */ |
| 240 | void |
| 241 | ospf6_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 Dutt | 8551e6d | 2013-10-22 17:42:18 -0700 | [diff] [blame] | 246 | if (age > OSPF_LSA_MAXAGE) |
| 247 | age = OSPF_LSA_MAXAGE; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 248 | lsa->header->age = htons (age); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 249 | } |
| 250 | |
| 251 | void |
| 252 | ospf6_lsa_premature_aging (struct ospf6_lsa *lsa) |
| 253 | { |
| 254 | /* log */ |
hasso | 1e05838 | 2004-09-01 21:36:14 +0000 | [diff] [blame] | 255 | if (IS_OSPF6_DEBUG_LSA_TYPE (lsa->header->type)) |
hasso | c6487d6 | 2004-12-24 06:00:11 +0000 | [diff] [blame] | 256 | zlog_debug ("LSA: Premature aging: %s", lsa->name); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 257 | |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 258 | THREAD_OFF (lsa->expire); |
| 259 | THREAD_OFF (lsa->refresh); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 260 | |
Dinesh Dutt | ac58e14 | 2013-08-24 07:54:24 +0000 | [diff] [blame] | 261 | /* |
| 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 Dutt | 8551e6d | 2013-10-22 17:42:18 -0700 | [diff] [blame] | 284 | lsa->header->age = htons (OSPF_LSA_MAXAGE); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 285 | 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 */ |
| 290 | int |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 291 | ospf6_lsa_compare (struct ospf6_lsa *a, struct ospf6_lsa *b) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 292 | { |
Ondrej Zajicek | 64bf3ab | 2009-12-07 12:33:20 +0300 | [diff] [blame] | 293 | int seqnuma, seqnumb; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 294 | u_int16_t cksuma, cksumb; |
| 295 | u_int16_t agea, ageb; |
| 296 | |
| 297 | assert (a && a->header); |
| 298 | assert (b && b->header); |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 299 | assert (OSPF6_LSA_IS_SAME (a, b)); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 300 | |
Ondrej Zajicek | 64bf3ab | 2009-12-07 12:33:20 +0300 | [diff] [blame] | 301 | seqnuma = (int) ntohl (a->header->seqnum); |
| 302 | seqnumb = (int) ntohl (b->header->seqnum); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 303 | |
| 304 | /* compare by sequence number */ |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 305 | if (seqnuma > seqnumb) |
| 306 | return -1; |
Ondrej Zajicek | 64bf3ab | 2009-12-07 12:33:20 +0300 | [diff] [blame] | 307 | if (seqnuma < seqnumb) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 308 | 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 | |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 318 | /* Update Age */ |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 319 | agea = ospf6_lsa_age_current (a); |
| 320 | ageb = ospf6_lsa_age_current (b); |
| 321 | |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 322 | /* MaxAge check */ |
Dinesh Dutt | 8551e6d | 2013-10-22 17:42:18 -0700 | [diff] [blame] | 323 | if (agea == OSPF_LSA_MAXAGE && ageb != OSPF_LSA_MAXAGE) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 324 | return -1; |
Dinesh Dutt | 8551e6d | 2013-10-22 17:42:18 -0700 | [diff] [blame] | 325 | else if (agea != OSPF_LSA_MAXAGE && ageb == OSPF_LSA_MAXAGE) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 326 | return 1; |
| 327 | |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 328 | /* Age check */ |
Dinesh Dutt | 8551e6d | 2013-10-22 17:42:18 -0700 | [diff] [blame] | 329 | if (agea > ageb && agea - ageb >= OSPF_LSA_MAXAGE_DIFF) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 330 | return 1; |
Dinesh Dutt | 8551e6d | 2013-10-22 17:42:18 -0700 | [diff] [blame] | 331 | else if (agea < ageb && ageb - agea >= OSPF_LSA_MAXAGE_DIFF) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 332 | return -1; |
| 333 | |
| 334 | /* neither recent */ |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 335 | return 0; |
| 336 | } |
| 337 | |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 338 | char * |
| 339 | ospf6_lsa_printbuf (struct ospf6_lsa *lsa, char *buf, int size) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 340 | { |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 341 | 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]", |
hasso | 1e05838 | 2004-09-01 21:36:14 +0000 | [diff] [blame] | 346 | ospf6_lstype_name (lsa->header->type), id, adv_router); |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 347 | return buf; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 348 | } |
| 349 | |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 350 | void |
| 351 | ospf6_lsa_header_print_raw (struct ospf6_lsa_header *header) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 352 | { |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 353 | 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)); |
hasso | c6487d6 | 2004-12-24 06:00:11 +0000 | [diff] [blame] | 357 | 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)); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 362 | } |
| 363 | |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 364 | void |
| 365 | ospf6_lsa_header_print (struct ospf6_lsa *lsa) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 366 | { |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 367 | ospf6_lsa_age_current (lsa); |
| 368 | ospf6_lsa_header_print_raw (lsa->header); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 369 | } |
| 370 | |
| 371 | void |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 372 | ospf6_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", |
hasso | 049207c | 2004-08-04 20:02:13 +0000 | [diff] [blame] | 376 | "Cksm", "Len", "Duration", VNL); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 377 | } |
| 378 | |
| 379 | void |
| 380 | ospf6_lsa_show_summary (struct vty *vty, struct ospf6_lsa *lsa) |
| 381 | { |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 382 | char adv_router[16], id[16]; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 383 | struct timeval now, res; |
| 384 | char duration[16]; |
| 385 | |
| 386 | assert (lsa); |
| 387 | assert (lsa->header); |
| 388 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 389 | 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 Sogabe | 86f72dc | 2009-06-22 13:07:02 +0900 | [diff] [blame] | 393 | quagga_gettime (QUAGGA_CLK_MONOTONIC, &now); |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 394 | timersub (&now, &lsa->installed, &res); |
| 395 | timerstring (&res, duration, sizeof (duration)); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 396 | |
| 397 | vty_out (vty, "%-12s %-15s %-15s %4hu %8lx %04hx %4hu %8s%s", |
hasso | 1e05838 | 2004-09-01 21:36:14 +0000 | [diff] [blame] | 398 | ospf6_lstype_name (lsa->header->type), |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 399 | id, adv_router, ospf6_lsa_age_current (lsa), |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 400 | (u_long) ntohl (lsa->header->seqnum), |
| 401 | ntohs (lsa->header->checksum), ntohs (lsa->header->length), |
hasso | 049207c | 2004-08-04 20:02:13 +0000 | [diff] [blame] | 402 | duration, VNL); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 403 | } |
| 404 | |
| 405 | void |
| 406 | ospf6_lsa_show_dump (struct vty *vty, struct ospf6_lsa *lsa) |
| 407 | { |
| 408 | u_char *start, *end, *current; |
| 409 | char byte[4]; |
| 410 | |
hasso | 03d52f8 | 2004-09-29 00:26:19 +0000 | [diff] [blame] | 411 | start = (u_char *) lsa->header; |
| 412 | end = (u_char *) lsa->header + ntohs (lsa->header->length); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 413 | |
hasso | 049207c | 2004-08-04 20:02:13 +0000 | [diff] [blame] | 414 | vty_out (vty, "%s", VNL); |
| 415 | vty_out (vty, "%s:%s", lsa->name, VNL); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 416 | |
| 417 | for (current = start; current < end; current ++) |
| 418 | { |
| 419 | if ((current - start) % 16 == 0) |
hasso | 049207c | 2004-08-04 20:02:13 +0000 | [diff] [blame] | 420 | vty_out (vty, "%s ", VNL); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 421 | 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 | |
hasso | 049207c | 2004-08-04 20:02:13 +0000 | [diff] [blame] | 428 | vty_out (vty, "%s%s", VNL, VNL); |
hasso | 6452df0 | 2004-08-15 05:52:07 +0000 | [diff] [blame] | 429 | return; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 430 | } |
| 431 | |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 432 | void |
| 433 | ospf6_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 | |
hasso | 049207c | 2004-08-04 20:02:13 +0000 | [diff] [blame] | 443 | vty_out (vty, "%s", VNL); |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 444 | vty_out (vty, "Age: %4hu Type: %s%s", ospf6_lsa_age_current (lsa), |
hasso | 1e05838 | 2004-09-01 21:36:14 +0000 | [diff] [blame] | 445 | ospf6_lstype_name (lsa->header->type), VNL); |
hasso | 049207c | 2004-08-04 20:02:13 +0000 | [diff] [blame] | 446 | vty_out (vty, "Link State ID: %s%s", id, VNL); |
| 447 | vty_out (vty, "Advertising Router: %s%s", adv_router, VNL); |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 448 | vty_out (vty, "LS Sequence Number: %#010lx%s", |
hasso | 049207c | 2004-08-04 20:02:13 +0000 | [diff] [blame] | 449 | (u_long) ntohl (lsa->header->seqnum), VNL); |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 450 | vty_out (vty, "CheckSum: %#06hx Length: %hu%s", |
| 451 | ntohs (lsa->header->checksum), |
hasso | 049207c | 2004-08-04 20:02:13 +0000 | [diff] [blame] | 452 | ntohs (lsa->header->length), VNL); |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 453 | vty_out (vty, " Prev: %p This: %p Next: %p%s", |
hasso | 049207c | 2004-08-04 20:02:13 +0000 | [diff] [blame] | 454 | lsa->prev, lsa, lsa->next, VNL); |
Dinesh Dutt | 8ae454e | 2013-08-24 07:54:41 +0000 | [diff] [blame] | 455 | 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); |
hasso | 049207c | 2004-08-04 20:02:13 +0000 | [diff] [blame] | 460 | vty_out (vty, "%s", VNL); |
hasso | 6452df0 | 2004-08-15 05:52:07 +0000 | [diff] [blame] | 461 | return; |
| 462 | } |
| 463 | |
| 464 | void |
| 465 | ospf6_lsa_show (struct vty *vty, struct ospf6_lsa *lsa) |
| 466 | { |
| 467 | char adv_router[64], id[64]; |
hasso | 1e05838 | 2004-09-01 21:36:14 +0000 | [diff] [blame] | 468 | struct ospf6_lsa_handler *handler; |
hasso | 6452df0 | 2004-08-15 05:52:07 +0000 | [diff] [blame] | 469 | |
| 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), |
hasso | 1e05838 | 2004-09-01 21:36:14 +0000 | [diff] [blame] | 477 | ospf6_lstype_name (lsa->header->type), VNL); |
hasso | 6452df0 | 2004-08-15 05:52:07 +0000 | [diff] [blame] | 478 | 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 | |
hasso | 1e05838 | 2004-09-01 21:36:14 +0000 | [diff] [blame] | 486 | handler = ospf6_get_lsa_handler (lsa->header->type); |
| 487 | if (handler->show == NULL) |
| 488 | handler = &unknown_handler; |
| 489 | (*handler->show) (vty, lsa); |
hasso | 6452df0 | 2004-08-15 05:52:07 +0000 | [diff] [blame] | 490 | |
| 491 | vty_out (vty, "%s", VNL); |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 492 | } |
| 493 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 494 | /* OSPFv3 LSA creation/deletion function */ |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 495 | struct ospf6_lsa * |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 496 | ospf6_lsa_create (struct ospf6_lsa_header *header) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 497 | { |
| 498 | struct ospf6_lsa *lsa = NULL; |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 499 | struct ospf6_lsa_header *new_header = NULL; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 500 | u_int16_t lsa_size = 0; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 501 | |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 502 | /* size of the entire LSA */ |
| 503 | lsa_size = ntohs (header->length); /* XXX vulnerable */ |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 504 | |
| 505 | /* allocate memory for this LSA */ |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 506 | new_header = (struct ospf6_lsa_header *) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 507 | XMALLOC (MTYPE_OSPF6_LSA, lsa_size); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 508 | |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 509 | /* copy LSA from original header */ |
| 510 | memcpy (new_header, header, lsa_size); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 511 | |
| 512 | /* LSA information structure */ |
| 513 | /* allocate memory */ |
| 514 | lsa = (struct ospf6_lsa *) |
Stephen Hemminger | 393deb9 | 2008-08-18 14:13:29 -0700 | [diff] [blame] | 515 | XCALLOC (MTYPE_OSPF6_LSA, sizeof (struct ospf6_lsa)); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 516 | |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 517 | lsa->header = (struct ospf6_lsa_header *) new_header; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 518 | |
| 519 | /* dump string */ |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 520 | ospf6_lsa_printbuf (lsa, lsa->name, sizeof (lsa->name)); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 521 | |
hasso | 3b68735 | 2004-08-19 06:56:53 +0000 | [diff] [blame] | 522 | /* calculate birth of this lsa */ |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 523 | ospf6_lsa_age_set (lsa); |
| 524 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 525 | return lsa; |
| 526 | } |
| 527 | |
| 528 | struct ospf6_lsa * |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 529 | ospf6_lsa_create_headeronly (struct ospf6_lsa_header *header) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 530 | { |
| 531 | struct ospf6_lsa *lsa = NULL; |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 532 | struct ospf6_lsa_header *new_header = NULL; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 533 | |
| 534 | /* allocate memory for this LSA */ |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 535 | new_header = (struct ospf6_lsa_header *) |
| 536 | XMALLOC (MTYPE_OSPF6_LSA, sizeof (struct ospf6_lsa_header)); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 537 | |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 538 | /* copy LSA from original header */ |
| 539 | memcpy (new_header, header, sizeof (struct ospf6_lsa_header)); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 540 | |
| 541 | /* LSA information structure */ |
| 542 | /* allocate memory */ |
| 543 | lsa = (struct ospf6_lsa *) |
Stephen Hemminger | 393deb9 | 2008-08-18 14:13:29 -0700 | [diff] [blame] | 544 | XCALLOC (MTYPE_OSPF6_LSA, sizeof (struct ospf6_lsa)); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 545 | |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 546 | lsa->header = (struct ospf6_lsa_header *) new_header; |
hasso | 6452df0 | 2004-08-15 05:52:07 +0000 | [diff] [blame] | 547 | SET_FLAG (lsa->flag, OSPF6_LSA_HEADERONLY); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 548 | |
| 549 | /* dump string */ |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 550 | ospf6_lsa_printbuf (lsa, lsa->name, sizeof (lsa->name)); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 551 | |
hasso | 3b68735 | 2004-08-19 06:56:53 +0000 | [diff] [blame] | 552 | /* calculate birth of this lsa */ |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 553 | ospf6_lsa_age_set (lsa); |
| 554 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 555 | return lsa; |
| 556 | } |
| 557 | |
| 558 | void |
| 559 | ospf6_lsa_delete (struct ospf6_lsa *lsa) |
| 560 | { |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 561 | assert (lsa->lock == 0); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 562 | |
| 563 | /* cancel threads */ |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 564 | THREAD_OFF (lsa->expire); |
| 565 | THREAD_OFF (lsa->refresh); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 566 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 567 | /* do free */ |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 568 | XFREE (MTYPE_OSPF6_LSA, lsa->header); |
| 569 | XFREE (MTYPE_OSPF6_LSA, lsa); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 570 | } |
| 571 | |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 572 | struct ospf6_lsa * |
| 573 | ospf6_lsa_copy (struct ospf6_lsa *lsa) |
| 574 | { |
| 575 | struct ospf6_lsa *copy = NULL; |
| 576 | |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 577 | ospf6_lsa_age_current (lsa); |
hasso | 6452df0 | 2004-08-15 05:52:07 +0000 | [diff] [blame] | 578 | if (CHECK_FLAG (lsa->flag, OSPF6_LSA_HEADERONLY)) |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 579 | copy = ospf6_lsa_create_headeronly (lsa->header); |
| 580 | else |
| 581 | copy = ospf6_lsa_create (lsa->header); |
| 582 | assert (copy->lock == 0); |
| 583 | |
hasso | 3b68735 | 2004-08-19 06:56:53 +0000 | [diff] [blame] | 584 | copy->birth = lsa->birth; |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 585 | copy->originated = lsa->originated; |
hasso | ccb59b1 | 2004-08-25 09:10:37 +0000 | [diff] [blame] | 586 | copy->received = lsa->received; |
| 587 | copy->installed = lsa->installed; |
hasso | 6452df0 | 2004-08-15 05:52:07 +0000 | [diff] [blame] | 588 | copy->lsdb = lsa->lsdb; |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 589 | |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 590 | return copy; |
| 591 | } |
| 592 | |
| 593 | /* increment reference counter of struct ospf6_lsa */ |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 594 | void |
| 595 | ospf6_lsa_lock (struct ospf6_lsa *lsa) |
| 596 | { |
| 597 | lsa->lock++; |
| 598 | return; |
| 599 | } |
| 600 | |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 601 | /* decrement reference counter of struct ospf6_lsa */ |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 602 | void |
| 603 | ospf6_lsa_unlock (struct ospf6_lsa *lsa) |
| 604 | { |
| 605 | /* decrement reference counter */ |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 606 | assert (lsa->lock > 0); |
| 607 | lsa->lock--; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 608 | |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 609 | if (lsa->lock != 0) |
| 610 | return; |
| 611 | |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 612 | ospf6_lsa_delete (lsa); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 613 | } |
| 614 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 615 | |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 616 | /* ospf6 lsa expiry */ |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 617 | int |
| 618 | ospf6_lsa_expire (struct thread *thread) |
| 619 | { |
| 620 | struct ospf6_lsa *lsa; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 621 | |
| 622 | lsa = (struct ospf6_lsa *) THREAD_ARG (thread); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 623 | |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 624 | assert (lsa && lsa->header); |
| 625 | assert (OSPF6_LSA_IS_MAXAGE (lsa)); |
| 626 | assert (! lsa->refresh); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 627 | |
| 628 | lsa->expire = (struct thread *) NULL; |
| 629 | |
hasso | 1e05838 | 2004-09-01 21:36:14 +0000 | [diff] [blame] | 630 | if (IS_OSPF6_DEBUG_LSA_TYPE (lsa->header->type)) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 631 | { |
hasso | c6487d6 | 2004-12-24 06:00:11 +0000 | [diff] [blame] | 632 | zlog_debug ("LSA Expire:"); |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 633 | ospf6_lsa_header_print (lsa); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 634 | } |
| 635 | |
hasso | 6452df0 | 2004-08-15 05:52:07 +0000 | [diff] [blame] | 636 | if (CHECK_FLAG (lsa->flag, OSPF6_LSA_HEADERONLY)) |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 637 | return 0; /* dbexchange will do something ... */ |
| 638 | |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 639 | /* reinstall lsa */ |
hasso | 3b68735 | 2004-08-19 06:56:53 +0000 | [diff] [blame] | 640 | ospf6_install_lsa (lsa); |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 641 | |
Dinesh Dutt | bf986da | 2013-08-24 07:54:50 +0000 | [diff] [blame^] | 642 | /* reflood lsa */ |
| 643 | ospf6_flood (NULL, lsa); |
| 644 | |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 645 | /* schedule maxage remover */ |
| 646 | ospf6_maxage_remove (ospf6); |
| 647 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 648 | return 0; |
| 649 | } |
| 650 | |
| 651 | int |
| 652 | ospf6_lsa_refresh (struct thread *thread) |
| 653 | { |
hasso | 6452df0 | 2004-08-15 05:52:07 +0000 | [diff] [blame] | 654 | struct ospf6_lsa *old, *self, *new; |
| 655 | struct ospf6_lsdb *lsdb_self; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 656 | |
| 657 | assert (thread); |
hasso | 6452df0 | 2004-08-15 05:52:07 +0000 | [diff] [blame] | 658 | old = (struct ospf6_lsa *) THREAD_ARG (thread); |
| 659 | assert (old && old->header); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 660 | |
hasso | 6452df0 | 2004-08-15 05:52:07 +0000 | [diff] [blame] | 661 | old->refresh = (struct thread *) NULL; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 662 | |
hasso | 6452df0 | 2004-08-15 05:52:07 +0000 | [diff] [blame] | 663 | 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 | { |
hasso | 1e05838 | 2004-09-01 21:36:14 +0000 | [diff] [blame] | 668 | if (IS_OSPF6_DEBUG_LSA_TYPE (old->header->type)) |
hasso | c6487d6 | 2004-12-24 06:00:11 +0000 | [diff] [blame] | 669 | zlog_debug ("Refresh: could not find self LSA, flush %s", old->name); |
hasso | 6452df0 | 2004-08-15 05:52:07 +0000 | [diff] [blame] | 670 | 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 Dutt | 8551e6d | 2013-10-22 17:42:18 -0700 | [diff] [blame] | 684 | OSPF_LS_REFRESH_TIME); |
hasso | 6452df0 | 2004-08-15 05:52:07 +0000 | [diff] [blame] | 685 | |
| 686 | /* store it in the LSDB for self-originated LSAs */ |
| 687 | ospf6_lsdb_add (ospf6_lsa_copy (new), lsdb_self); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 688 | |
hasso | 1e05838 | 2004-09-01 21:36:14 +0000 | [diff] [blame] | 689 | if (IS_OSPF6_DEBUG_LSA_TYPE (new->header->type)) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 690 | { |
hasso | c6487d6 | 2004-12-24 06:00:11 +0000 | [diff] [blame] | 691 | zlog_debug ("LSA Refresh:"); |
hasso | 6452df0 | 2004-08-15 05:52:07 +0000 | [diff] [blame] | 692 | ospf6_lsa_header_print (new); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 693 | } |
| 694 | |
hasso | 6452df0 | 2004-08-15 05:52:07 +0000 | [diff] [blame] | 695 | ospf6_install_lsa (new); |
Dinesh Dutt | bf986da | 2013-08-24 07:54:50 +0000 | [diff] [blame^] | 696 | ospf6_flood (NULL, new); |
hasso | 6452df0 | 2004-08-15 05:52:07 +0000 | [diff] [blame] | 697 | |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 698 | return 0; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 699 | } |
| 700 | |
| 701 | |
| 702 | |
JR Rivers | d8a4e42 | 2012-09-13 17:17:36 +0000 | [diff] [blame] | 703 | /* Fletcher Checksum -- Refer to RFC1008. */ |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 704 | |
JR Rivers | d8a4e42 | 2012-09-13 17:17:36 +0000 | [diff] [blame] | 705 | /* All the offsets are zero-based. The offsets in the RFC1008 are |
| 706 | one-based. */ |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 707 | unsigned short |
| 708 | ospf6_lsa_checksum (struct ospf6_lsa_header *lsa_header) |
| 709 | { |
JR Rivers | d8a4e42 | 2012-09-13 17:17:36 +0000 | [diff] [blame] | 710 | u_char *buffer = (u_char *) &lsa_header->type; |
| 711 | int type_offset = buffer - (u_char *) &lsa_header->age; /* should be 2 */ |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 712 | |
JR Rivers | d8a4e42 | 2012-09-13 17:17:36 +0000 | [diff] [blame] | 713 | /* Skip the AGE field */ |
| 714 | u_int16_t len = ntohs(lsa_header->length) - type_offset; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 715 | |
JR Rivers | d8a4e42 | 2012-09-13 17:17:36 +0000 | [diff] [blame] | 716 | /* 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; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 719 | |
JR Rivers | d8a4e42 | 2012-09-13 17:17:36 +0000 | [diff] [blame] | 720 | return (unsigned short)fletcher_checksum(buffer, len, checksum_offset); |
| 721 | } |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 722 | |
JR Rivers | d8a4e42 | 2012-09-13 17:17:36 +0000 | [diff] [blame] | 723 | int |
| 724 | ospf6_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 */ |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 728 | |
JR Rivers | d8a4e42 | 2012-09-13 17:17:36 +0000 | [diff] [blame] | 729 | /* 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); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 733 | } |
| 734 | |
hasso | 6452df0 | 2004-08-15 05:52:07 +0000 | [diff] [blame] | 735 | void |
Paul Jakma | 6ac29a5 | 2008-08-15 13:45:30 +0100 | [diff] [blame] | 736 | ospf6_lsa_init (void) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 737 | { |
hasso | 1e05838 | 2004-09-01 21:36:14 +0000 | [diff] [blame] | 738 | ospf6_lsa_handler_vector = vector_init (0); |
hasso | 6452df0 | 2004-08-15 05:52:07 +0000 | [diff] [blame] | 739 | ospf6_install_lsa_handler (&unknown_handler); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 740 | } |
| 741 | |
Tom Goff | ae2254a | 2010-11-10 13:01:41 -0800 | [diff] [blame] | 742 | void |
| 743 | ospf6_lsa_terminate (void) |
| 744 | { |
| 745 | vector_free (ospf6_lsa_handler_vector); |
| 746 | } |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 747 | |
Paul Jakma | 6ac29a5 | 2008-08-15 13:45:30 +0100 | [diff] [blame] | 748 | static char * |
hasso | 1e05838 | 2004-09-01 21:36:14 +0000 | [diff] [blame] | 749 | ospf6_lsa_handler_name (struct ospf6_lsa_handler *h) |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 750 | { |
hasso | 1e05838 | 2004-09-01 21:36:14 +0000 | [diff] [blame] | 751 | static char buf[64]; |
paul | 0c083ee | 2004-10-10 12:54:58 +0000 | [diff] [blame] | 752 | unsigned int i; |
| 753 | unsigned int size = strlen (h->name); |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 754 | |
Dinesh Dutt | 09df457 | 2013-08-24 07:54:31 +0000 | [diff] [blame] | 755 | if (!strcmp(h->name, "unknown") && |
hasso | 1e05838 | 2004-09-01 21:36:14 +0000 | [diff] [blame] | 756 | h->type != OSPF6_LSTYPE_UNKNOWN) |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 757 | { |
hasso | 1e05838 | 2004-09-01 21:36:14 +0000 | [diff] [blame] | 758 | snprintf (buf, sizeof (buf), "%#04hx", h->type); |
| 759 | return buf; |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 760 | } |
| 761 | |
hasso | 1e05838 | 2004-09-01 21:36:14 +0000 | [diff] [blame] | 762 | for (i = 0; i < MIN (size, sizeof (buf)); i++) |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 763 | { |
hasso | 1e05838 | 2004-09-01 21:36:14 +0000 | [diff] [blame] | 764 | if (! islower (h->name[i])) |
| 765 | buf[i] = tolower (h->name[i]); |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 766 | else |
hasso | 1e05838 | 2004-09-01 21:36:14 +0000 | [diff] [blame] | 767 | buf[i] = h->name[i]; |
| 768 | } |
| 769 | buf[size] = '\0'; |
| 770 | return buf; |
| 771 | } |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 772 | |
hasso | 1e05838 | 2004-09-01 21:36:14 +0000 | [diff] [blame] | 773 | DEFUN (debug_ospf6_lsa_type, |
| 774 | debug_ospf6_lsa_hex_cmd, |
Dinesh Dutt | 09df457 | 2013-08-24 07:54:31 +0000 | [diff] [blame] | 775 | "debug ospf6 lsa (router|network|inter-prefix|inter-router|as-ext|grp-mbr|type7|link|intra-prefix|unknown)", |
hasso | 1e05838 | 2004-09-01 21:36:14 +0000 | [diff] [blame] | 776 | DEBUG_STR |
| 777 | OSPF6_STR |
| 778 | "Debug Link State Advertisements (LSAs)\n" |
| 779 | "Specify LS type as Hexadecimal\n" |
| 780 | ) |
| 781 | { |
paul | 0c083ee | 2004-10-10 12:54:58 +0000 | [diff] [blame] | 782 | unsigned int i; |
hasso | 1e05838 | 2004-09-01 21:36:14 +0000 | [diff] [blame] | 783 | struct ospf6_lsa_handler *handler = NULL; |
hasso | 1e05838 | 2004-09-01 21:36:14 +0000 | [diff] [blame] | 784 | |
| 785 | assert (argc); |
| 786 | |
paul | 55468c8 | 2005-03-14 20:19:01 +0000 | [diff] [blame] | 787 | for (i = 0; i < vector_active (ospf6_lsa_handler_vector); i++) |
hasso | 1e05838 | 2004-09-01 21:36:14 +0000 | [diff] [blame] | 788 | { |
| 789 | handler = vector_slot (ospf6_lsa_handler_vector, i); |
| 790 | if (handler == NULL) |
| 791 | continue; |
Dinesh Dutt | 09df457 | 2013-08-24 07:54:31 +0000 | [diff] [blame] | 792 | if (strncmp (argv[0], ospf6_lsa_handler_name(handler), strlen(argv[0])) == 0) |
hasso | 1e05838 | 2004-09-01 21:36:14 +0000 | [diff] [blame] | 793 | break; |
| 794 | if (! strcasecmp (argv[0], handler->name)) |
| 795 | break; |
| 796 | handler = NULL; |
| 797 | } |
| 798 | |
hasso | 1e05838 | 2004-09-01 21:36:14 +0000 | [diff] [blame] | 799 | 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 Dutt | 09df457 | 2013-08-24 07:54:31 +0000 | [diff] [blame] | 806 | if (! strcmp (argv[1], "examine")) |
hasso | 1e05838 | 2004-09-01 21:36:14 +0000 | [diff] [blame] | 807 | 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; |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 815 | } |
| 816 | |
Dinesh Dutt | 09df457 | 2013-08-24 07:54:31 +0000 | [diff] [blame] | 817 | ALIAS (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 | |
hasso | 1e05838 | 2004-09-01 21:36:14 +0000 | [diff] [blame] | 826 | DEFUN (no_debug_ospf6_lsa_type, |
| 827 | no_debug_ospf6_lsa_hex_cmd, |
Dinesh Dutt | 09df457 | 2013-08-24 07:54:31 +0000 | [diff] [blame] | 828 | "no debug ospf6 lsa (router|network|inter-prefix|inter-router|as-ext|grp-mbr|type7|link|intra-prefix|unknown)", |
hasso | 1e05838 | 2004-09-01 21:36:14 +0000 | [diff] [blame] | 829 | NO_STR |
| 830 | DEBUG_STR |
| 831 | OSPF6_STR |
| 832 | "Debug Link State Advertisements (LSAs)\n" |
| 833 | "Specify LS type as Hexadecimal\n" |
| 834 | ) |
| 835 | { |
paul | 0c083ee | 2004-10-10 12:54:58 +0000 | [diff] [blame] | 836 | u_int i; |
hasso | 1e05838 | 2004-09-01 21:36:14 +0000 | [diff] [blame] | 837 | struct ospf6_lsa_handler *handler = NULL; |
hasso | 1e05838 | 2004-09-01 21:36:14 +0000 | [diff] [blame] | 838 | |
| 839 | assert (argc); |
| 840 | |
paul | 55468c8 | 2005-03-14 20:19:01 +0000 | [diff] [blame] | 841 | for (i = 0; i < vector_active (ospf6_lsa_handler_vector); i++) |
hasso | 1e05838 | 2004-09-01 21:36:14 +0000 | [diff] [blame] | 842 | { |
| 843 | handler = vector_slot (ospf6_lsa_handler_vector, i); |
| 844 | if (handler == NULL) |
| 845 | continue; |
Dinesh Dutt | 09df457 | 2013-08-24 07:54:31 +0000 | [diff] [blame] | 846 | if (strncmp (argv[0], ospf6_lsa_handler_name(handler), strlen(argv[0])) == 0) |
hasso | 1e05838 | 2004-09-01 21:36:14 +0000 | [diff] [blame] | 847 | 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 Dutt | 09df457 | 2013-08-24 07:54:31 +0000 | [diff] [blame] | 859 | if (! strcmp (argv[1], "examine")) |
hasso | 1e05838 | 2004-09-01 21:36:14 +0000 | [diff] [blame] | 860 | 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 | |
hasso | 1e05838 | 2004-09-01 21:36:14 +0000 | [diff] [blame] | 867 | return CMD_SUCCESS; |
| 868 | } |
| 869 | |
Dinesh Dutt | 09df457 | 2013-08-24 07:54:31 +0000 | [diff] [blame] | 870 | ALIAS (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 | ) |
hasso | 1e05838 | 2004-09-01 21:36:14 +0000 | [diff] [blame] | 879 | |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 880 | void |
Paul Jakma | 6ac29a5 | 2008-08-15 13:45:30 +0100 | [diff] [blame] | 881 | install_element_ospf6_debug_lsa (void) |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 882 | { |
hasso | 1e05838 | 2004-09-01 21:36:14 +0000 | [diff] [blame] | 883 | install_element (ENABLE_NODE, &debug_ospf6_lsa_hex_cmd); |
Dinesh Dutt | 09df457 | 2013-08-24 07:54:31 +0000 | [diff] [blame] | 884 | install_element (ENABLE_NODE, &debug_ospf6_lsa_hex_detail_cmd); |
hasso | 1e05838 | 2004-09-01 21:36:14 +0000 | [diff] [blame] | 885 | install_element (ENABLE_NODE, &no_debug_ospf6_lsa_hex_cmd); |
Dinesh Dutt | 09df457 | 2013-08-24 07:54:31 +0000 | [diff] [blame] | 886 | install_element (ENABLE_NODE, &no_debug_ospf6_lsa_hex_detail_cmd); |
hasso | 1e05838 | 2004-09-01 21:36:14 +0000 | [diff] [blame] | 887 | install_element (CONFIG_NODE, &debug_ospf6_lsa_hex_cmd); |
Dinesh Dutt | 09df457 | 2013-08-24 07:54:31 +0000 | [diff] [blame] | 888 | install_element (CONFIG_NODE, &debug_ospf6_lsa_hex_detail_cmd); |
hasso | 1e05838 | 2004-09-01 21:36:14 +0000 | [diff] [blame] | 889 | install_element (CONFIG_NODE, &no_debug_ospf6_lsa_hex_cmd); |
Dinesh Dutt | 09df457 | 2013-08-24 07:54:31 +0000 | [diff] [blame] | 890 | install_element (CONFIG_NODE, &no_debug_ospf6_lsa_hex_detail_cmd); |
hasso | 1e05838 | 2004-09-01 21:36:14 +0000 | [diff] [blame] | 891 | } |
| 892 | |
| 893 | int |
| 894 | config_write_ospf6_debug_lsa (struct vty *vty) |
| 895 | { |
paul | 0c083ee | 2004-10-10 12:54:58 +0000 | [diff] [blame] | 896 | u_int i; |
hasso | 1e05838 | 2004-09-01 21:36:14 +0000 | [diff] [blame] | 897 | struct ospf6_lsa_handler *handler; |
| 898 | |
paul | 55468c8 | 2005-03-14 20:19:01 +0000 | [diff] [blame] | 899 | for (i = 0; i < vector_active (ospf6_lsa_handler_vector); i++) |
hasso | 1e05838 | 2004-09-01 21:36:14 +0000 | [diff] [blame] | 900 | { |
| 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 Dutt | 09df457 | 2013-08-24 07:54:31 +0000 | [diff] [blame] | 911 | vty_out (vty, "debug ospf6 lsa %s examine%s", |
hasso | 1e05838 | 2004-09-01 21:36:14 +0000 | [diff] [blame] | 912 | 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; |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 919 | } |
| 920 | |
| 921 | |