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); |
Dinesh Dutt | 8ae454e | 2013-08-24 07:54:41 +0000 | [diff] [blame] | 453 | vty_out (vty, "Flag: %x %s", lsa->flag, VNL); |
| 454 | vty_out (vty, "Lock: %d %s", lsa->lock, VNL); |
| 455 | vty_out (vty, "ReTx Count: %d%s", lsa->retrans_count, VNL); |
| 456 | vty_out (vty, "Threads: Expire: %x, Refresh: %x %s", |
| 457 | lsa->expire, lsa->refresh, VNL); |
hasso | 049207c | 2004-08-04 20:02:13 +0000 | [diff] [blame] | 458 | vty_out (vty, "%s", VNL); |
hasso | 6452df0 | 2004-08-15 05:52:07 +0000 | [diff] [blame] | 459 | return; |
| 460 | } |
| 461 | |
| 462 | void |
| 463 | ospf6_lsa_show (struct vty *vty, struct ospf6_lsa *lsa) |
| 464 | { |
| 465 | char adv_router[64], id[64]; |
hasso | 1e05838 | 2004-09-01 21:36:14 +0000 | [diff] [blame] | 466 | struct ospf6_lsa_handler *handler; |
hasso | 6452df0 | 2004-08-15 05:52:07 +0000 | [diff] [blame] | 467 | |
| 468 | assert (lsa && lsa->header); |
| 469 | |
| 470 | inet_ntop (AF_INET, &lsa->header->id, id, sizeof (id)); |
| 471 | inet_ntop (AF_INET, &lsa->header->adv_router, |
| 472 | adv_router, sizeof (adv_router)); |
| 473 | |
| 474 | vty_out (vty, "Age: %4hu Type: %s%s", ospf6_lsa_age_current (lsa), |
hasso | 1e05838 | 2004-09-01 21:36:14 +0000 | [diff] [blame] | 475 | ospf6_lstype_name (lsa->header->type), VNL); |
hasso | 6452df0 | 2004-08-15 05:52:07 +0000 | [diff] [blame] | 476 | vty_out (vty, "Link State ID: %s%s", id, VNL); |
| 477 | vty_out (vty, "Advertising Router: %s%s", adv_router, VNL); |
| 478 | vty_out (vty, "LS Sequence Number: %#010lx%s", |
| 479 | (u_long) ntohl (lsa->header->seqnum), VNL); |
| 480 | vty_out (vty, "CheckSum: %#06hx Length: %hu%s", |
| 481 | ntohs (lsa->header->checksum), |
| 482 | ntohs (lsa->header->length), VNL); |
| 483 | |
hasso | 1e05838 | 2004-09-01 21:36:14 +0000 | [diff] [blame] | 484 | handler = ospf6_get_lsa_handler (lsa->header->type); |
| 485 | if (handler->show == NULL) |
| 486 | handler = &unknown_handler; |
| 487 | (*handler->show) (vty, lsa); |
hasso | 6452df0 | 2004-08-15 05:52:07 +0000 | [diff] [blame] | 488 | |
| 489 | vty_out (vty, "%s", VNL); |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 490 | } |
| 491 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 492 | /* OSPFv3 LSA creation/deletion function */ |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 493 | struct ospf6_lsa * |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 494 | ospf6_lsa_create (struct ospf6_lsa_header *header) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 495 | { |
| 496 | struct ospf6_lsa *lsa = NULL; |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 497 | struct ospf6_lsa_header *new_header = NULL; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 498 | u_int16_t lsa_size = 0; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 499 | |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 500 | /* size of the entire LSA */ |
| 501 | lsa_size = ntohs (header->length); /* XXX vulnerable */ |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 502 | |
| 503 | /* allocate memory for this LSA */ |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 504 | new_header = (struct ospf6_lsa_header *) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 505 | XMALLOC (MTYPE_OSPF6_LSA, lsa_size); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 506 | |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 507 | /* copy LSA from original header */ |
| 508 | memcpy (new_header, header, lsa_size); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 509 | |
| 510 | /* LSA information structure */ |
| 511 | /* allocate memory */ |
| 512 | lsa = (struct ospf6_lsa *) |
Stephen Hemminger | 393deb9 | 2008-08-18 14:13:29 -0700 | [diff] [blame] | 513 | XCALLOC (MTYPE_OSPF6_LSA, sizeof (struct ospf6_lsa)); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 514 | |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 515 | lsa->header = (struct ospf6_lsa_header *) new_header; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 516 | |
| 517 | /* dump string */ |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 518 | ospf6_lsa_printbuf (lsa, lsa->name, sizeof (lsa->name)); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 519 | |
hasso | 3b68735 | 2004-08-19 06:56:53 +0000 | [diff] [blame] | 520 | /* calculate birth of this lsa */ |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 521 | ospf6_lsa_age_set (lsa); |
| 522 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 523 | return lsa; |
| 524 | } |
| 525 | |
| 526 | struct ospf6_lsa * |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 527 | ospf6_lsa_create_headeronly (struct ospf6_lsa_header *header) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 528 | { |
| 529 | struct ospf6_lsa *lsa = NULL; |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 530 | struct ospf6_lsa_header *new_header = NULL; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 531 | |
| 532 | /* allocate memory for this LSA */ |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 533 | new_header = (struct ospf6_lsa_header *) |
| 534 | XMALLOC (MTYPE_OSPF6_LSA, sizeof (struct ospf6_lsa_header)); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 535 | |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 536 | /* copy LSA from original header */ |
| 537 | memcpy (new_header, header, sizeof (struct ospf6_lsa_header)); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 538 | |
| 539 | /* LSA information structure */ |
| 540 | /* allocate memory */ |
| 541 | lsa = (struct ospf6_lsa *) |
Stephen Hemminger | 393deb9 | 2008-08-18 14:13:29 -0700 | [diff] [blame] | 542 | XCALLOC (MTYPE_OSPF6_LSA, sizeof (struct ospf6_lsa)); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 543 | |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 544 | lsa->header = (struct ospf6_lsa_header *) new_header; |
hasso | 6452df0 | 2004-08-15 05:52:07 +0000 | [diff] [blame] | 545 | SET_FLAG (lsa->flag, OSPF6_LSA_HEADERONLY); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 546 | |
| 547 | /* dump string */ |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 548 | ospf6_lsa_printbuf (lsa, lsa->name, sizeof (lsa->name)); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 549 | |
hasso | 3b68735 | 2004-08-19 06:56:53 +0000 | [diff] [blame] | 550 | /* calculate birth of this lsa */ |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 551 | ospf6_lsa_age_set (lsa); |
| 552 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 553 | return lsa; |
| 554 | } |
| 555 | |
| 556 | void |
| 557 | ospf6_lsa_delete (struct ospf6_lsa *lsa) |
| 558 | { |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 559 | assert (lsa->lock == 0); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 560 | |
| 561 | /* cancel threads */ |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 562 | THREAD_OFF (lsa->expire); |
| 563 | THREAD_OFF (lsa->refresh); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 564 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 565 | /* do free */ |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 566 | XFREE (MTYPE_OSPF6_LSA, lsa->header); |
| 567 | XFREE (MTYPE_OSPF6_LSA, lsa); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 568 | } |
| 569 | |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 570 | struct ospf6_lsa * |
| 571 | ospf6_lsa_copy (struct ospf6_lsa *lsa) |
| 572 | { |
| 573 | struct ospf6_lsa *copy = NULL; |
| 574 | |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 575 | ospf6_lsa_age_current (lsa); |
hasso | 6452df0 | 2004-08-15 05:52:07 +0000 | [diff] [blame] | 576 | if (CHECK_FLAG (lsa->flag, OSPF6_LSA_HEADERONLY)) |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 577 | copy = ospf6_lsa_create_headeronly (lsa->header); |
| 578 | else |
| 579 | copy = ospf6_lsa_create (lsa->header); |
| 580 | assert (copy->lock == 0); |
| 581 | |
hasso | 3b68735 | 2004-08-19 06:56:53 +0000 | [diff] [blame] | 582 | copy->birth = lsa->birth; |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 583 | copy->originated = lsa->originated; |
hasso | ccb59b1 | 2004-08-25 09:10:37 +0000 | [diff] [blame] | 584 | copy->received = lsa->received; |
| 585 | copy->installed = lsa->installed; |
hasso | 6452df0 | 2004-08-15 05:52:07 +0000 | [diff] [blame] | 586 | copy->lsdb = lsa->lsdb; |
Dinesh Dutt | a765eb9 | 2013-08-24 07:55:14 +0000 | [diff] [blame] | 587 | copy->rn = NULL; |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 588 | |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 589 | return copy; |
| 590 | } |
| 591 | |
| 592 | /* increment reference counter of struct ospf6_lsa */ |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 593 | void |
| 594 | ospf6_lsa_lock (struct ospf6_lsa *lsa) |
| 595 | { |
| 596 | lsa->lock++; |
| 597 | return; |
| 598 | } |
| 599 | |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 600 | /* decrement reference counter of struct ospf6_lsa */ |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 601 | void |
| 602 | ospf6_lsa_unlock (struct ospf6_lsa *lsa) |
| 603 | { |
| 604 | /* decrement reference counter */ |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 605 | assert (lsa->lock > 0); |
| 606 | lsa->lock--; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 607 | |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 608 | if (lsa->lock != 0) |
| 609 | return; |
| 610 | |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 611 | ospf6_lsa_delete (lsa); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 612 | } |
| 613 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 614 | |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 615 | /* ospf6 lsa expiry */ |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 616 | int |
| 617 | ospf6_lsa_expire (struct thread *thread) |
| 618 | { |
| 619 | struct ospf6_lsa *lsa; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 620 | |
| 621 | lsa = (struct ospf6_lsa *) THREAD_ARG (thread); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 622 | |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 623 | assert (lsa && lsa->header); |
| 624 | assert (OSPF6_LSA_IS_MAXAGE (lsa)); |
| 625 | assert (! lsa->refresh); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 626 | |
| 627 | lsa->expire = (struct thread *) NULL; |
| 628 | |
hasso | 1e05838 | 2004-09-01 21:36:14 +0000 | [diff] [blame] | 629 | if (IS_OSPF6_DEBUG_LSA_TYPE (lsa->header->type)) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 630 | { |
hasso | c6487d6 | 2004-12-24 06:00:11 +0000 | [diff] [blame] | 631 | zlog_debug ("LSA Expire:"); |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 632 | ospf6_lsa_header_print (lsa); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 633 | } |
| 634 | |
hasso | 6452df0 | 2004-08-15 05:52:07 +0000 | [diff] [blame] | 635 | if (CHECK_FLAG (lsa->flag, OSPF6_LSA_HEADERONLY)) |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 636 | return 0; /* dbexchange will do something ... */ |
| 637 | |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 638 | /* reinstall lsa */ |
hasso | 3b68735 | 2004-08-19 06:56:53 +0000 | [diff] [blame] | 639 | ospf6_install_lsa (lsa); |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 640 | |
Dinesh Dutt | bf986da | 2013-08-24 07:54:50 +0000 | [diff] [blame] | 641 | /* reflood lsa */ |
| 642 | ospf6_flood (NULL, lsa); |
| 643 | |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 644 | /* schedule maxage remover */ |
| 645 | ospf6_maxage_remove (ospf6); |
| 646 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 647 | return 0; |
| 648 | } |
| 649 | |
| 650 | int |
| 651 | ospf6_lsa_refresh (struct thread *thread) |
| 652 | { |
hasso | 6452df0 | 2004-08-15 05:52:07 +0000 | [diff] [blame] | 653 | struct ospf6_lsa *old, *self, *new; |
| 654 | struct ospf6_lsdb *lsdb_self; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 655 | |
| 656 | assert (thread); |
hasso | 6452df0 | 2004-08-15 05:52:07 +0000 | [diff] [blame] | 657 | old = (struct ospf6_lsa *) THREAD_ARG (thread); |
| 658 | assert (old && old->header); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 659 | |
hasso | 6452df0 | 2004-08-15 05:52:07 +0000 | [diff] [blame] | 660 | old->refresh = (struct thread *) NULL; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 661 | |
hasso | 6452df0 | 2004-08-15 05:52:07 +0000 | [diff] [blame] | 662 | lsdb_self = ospf6_get_scoped_lsdb_self (old); |
| 663 | self = ospf6_lsdb_lookup (old->header->type, old->header->id, |
| 664 | old->header->adv_router, lsdb_self); |
| 665 | if (self == NULL) |
| 666 | { |
hasso | 1e05838 | 2004-09-01 21:36:14 +0000 | [diff] [blame] | 667 | if (IS_OSPF6_DEBUG_LSA_TYPE (old->header->type)) |
hasso | c6487d6 | 2004-12-24 06:00:11 +0000 | [diff] [blame] | 668 | zlog_debug ("Refresh: could not find self LSA, flush %s", old->name); |
hasso | 6452df0 | 2004-08-15 05:52:07 +0000 | [diff] [blame] | 669 | ospf6_lsa_premature_aging (old); |
| 670 | return 0; |
| 671 | } |
| 672 | |
| 673 | /* Reset age, increment LS sequence number. */ |
| 674 | self->header->age = htons (0); |
| 675 | self->header->seqnum = |
| 676 | ospf6_new_ls_seqnum (self->header->type, self->header->id, |
| 677 | self->header->adv_router, old->lsdb); |
| 678 | ospf6_lsa_checksum (self->header); |
| 679 | |
| 680 | new = ospf6_lsa_create (self->header); |
| 681 | new->lsdb = old->lsdb; |
| 682 | new->refresh = thread_add_timer (master, ospf6_lsa_refresh, new, |
Dinesh Dutt | 8551e6d | 2013-10-22 17:42:18 -0700 | [diff] [blame] | 683 | OSPF_LS_REFRESH_TIME); |
hasso | 6452df0 | 2004-08-15 05:52:07 +0000 | [diff] [blame] | 684 | |
| 685 | /* store it in the LSDB for self-originated LSAs */ |
| 686 | ospf6_lsdb_add (ospf6_lsa_copy (new), lsdb_self); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 687 | |
hasso | 1e05838 | 2004-09-01 21:36:14 +0000 | [diff] [blame] | 688 | if (IS_OSPF6_DEBUG_LSA_TYPE (new->header->type)) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 689 | { |
hasso | c6487d6 | 2004-12-24 06:00:11 +0000 | [diff] [blame] | 690 | zlog_debug ("LSA Refresh:"); |
hasso | 6452df0 | 2004-08-15 05:52:07 +0000 | [diff] [blame] | 691 | ospf6_lsa_header_print (new); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 692 | } |
| 693 | |
hasso | 6452df0 | 2004-08-15 05:52:07 +0000 | [diff] [blame] | 694 | ospf6_install_lsa (new); |
Dinesh Dutt | bf986da | 2013-08-24 07:54:50 +0000 | [diff] [blame] | 695 | ospf6_flood (NULL, new); |
hasso | 6452df0 | 2004-08-15 05:52:07 +0000 | [diff] [blame] | 696 | |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 697 | return 0; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 698 | } |
| 699 | |
| 700 | |
| 701 | |
JR Rivers | d8a4e42 | 2012-09-13 17:17:36 +0000 | [diff] [blame] | 702 | /* Fletcher Checksum -- Refer to RFC1008. */ |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 703 | |
JR Rivers | d8a4e42 | 2012-09-13 17:17:36 +0000 | [diff] [blame] | 704 | /* All the offsets are zero-based. The offsets in the RFC1008 are |
| 705 | one-based. */ |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 706 | unsigned short |
| 707 | ospf6_lsa_checksum (struct ospf6_lsa_header *lsa_header) |
| 708 | { |
JR Rivers | d8a4e42 | 2012-09-13 17:17:36 +0000 | [diff] [blame] | 709 | u_char *buffer = (u_char *) &lsa_header->type; |
| 710 | int type_offset = buffer - (u_char *) &lsa_header->age; /* should be 2 */ |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 711 | |
JR Rivers | d8a4e42 | 2012-09-13 17:17:36 +0000 | [diff] [blame] | 712 | /* Skip the AGE field */ |
| 713 | u_int16_t len = ntohs(lsa_header->length) - type_offset; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 714 | |
JR Rivers | d8a4e42 | 2012-09-13 17:17:36 +0000 | [diff] [blame] | 715 | /* Checksum offset starts from "type" field, not the beginning of the |
| 716 | lsa_header struct. The offset is 14, rather than 16. */ |
| 717 | int checksum_offset = (u_char *) &lsa_header->checksum - buffer; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 718 | |
JR Rivers | d8a4e42 | 2012-09-13 17:17:36 +0000 | [diff] [blame] | 719 | return (unsigned short)fletcher_checksum(buffer, len, checksum_offset); |
| 720 | } |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 721 | |
JR Rivers | d8a4e42 | 2012-09-13 17:17:36 +0000 | [diff] [blame] | 722 | int |
| 723 | ospf6_lsa_checksum_valid (struct ospf6_lsa_header *lsa_header) |
| 724 | { |
| 725 | u_char *buffer = (u_char *) &lsa_header->type; |
| 726 | int type_offset = buffer - (u_char *) &lsa_header->age; /* should be 2 */ |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 727 | |
JR Rivers | d8a4e42 | 2012-09-13 17:17:36 +0000 | [diff] [blame] | 728 | /* Skip the AGE field */ |
| 729 | u_int16_t len = ntohs(lsa_header->length) - type_offset; |
| 730 | |
| 731 | return (fletcher_checksum(buffer, len, FLETCHER_CHECKSUM_VALIDATE) == 0); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 732 | } |
| 733 | |
hasso | 6452df0 | 2004-08-15 05:52:07 +0000 | [diff] [blame] | 734 | void |
Paul Jakma | 6ac29a5 | 2008-08-15 13:45:30 +0100 | [diff] [blame] | 735 | ospf6_lsa_init (void) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 736 | { |
hasso | 1e05838 | 2004-09-01 21:36:14 +0000 | [diff] [blame] | 737 | ospf6_lsa_handler_vector = vector_init (0); |
hasso | 6452df0 | 2004-08-15 05:52:07 +0000 | [diff] [blame] | 738 | ospf6_install_lsa_handler (&unknown_handler); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 739 | } |
| 740 | |
Tom Goff | ae2254a | 2010-11-10 13:01:41 -0800 | [diff] [blame] | 741 | void |
| 742 | ospf6_lsa_terminate (void) |
| 743 | { |
| 744 | vector_free (ospf6_lsa_handler_vector); |
| 745 | } |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 746 | |
Paul Jakma | 6ac29a5 | 2008-08-15 13:45:30 +0100 | [diff] [blame] | 747 | static char * |
hasso | 1e05838 | 2004-09-01 21:36:14 +0000 | [diff] [blame] | 748 | ospf6_lsa_handler_name (struct ospf6_lsa_handler *h) |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 749 | { |
hasso | 1e05838 | 2004-09-01 21:36:14 +0000 | [diff] [blame] | 750 | static char buf[64]; |
paul | 0c083ee | 2004-10-10 12:54:58 +0000 | [diff] [blame] | 751 | unsigned int i; |
| 752 | unsigned int size = strlen (h->name); |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 753 | |
Dinesh Dutt | 09df457 | 2013-08-24 07:54:31 +0000 | [diff] [blame] | 754 | if (!strcmp(h->name, "unknown") && |
hasso | 1e05838 | 2004-09-01 21:36:14 +0000 | [diff] [blame] | 755 | h->type != OSPF6_LSTYPE_UNKNOWN) |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 756 | { |
hasso | 1e05838 | 2004-09-01 21:36:14 +0000 | [diff] [blame] | 757 | snprintf (buf, sizeof (buf), "%#04hx", h->type); |
| 758 | return buf; |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 759 | } |
| 760 | |
hasso | 1e05838 | 2004-09-01 21:36:14 +0000 | [diff] [blame] | 761 | for (i = 0; i < MIN (size, sizeof (buf)); i++) |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 762 | { |
hasso | 1e05838 | 2004-09-01 21:36:14 +0000 | [diff] [blame] | 763 | if (! islower (h->name[i])) |
| 764 | buf[i] = tolower (h->name[i]); |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 765 | else |
hasso | 1e05838 | 2004-09-01 21:36:14 +0000 | [diff] [blame] | 766 | buf[i] = h->name[i]; |
| 767 | } |
| 768 | buf[size] = '\0'; |
| 769 | return buf; |
| 770 | } |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 771 | |
hasso | 1e05838 | 2004-09-01 21:36:14 +0000 | [diff] [blame] | 772 | DEFUN (debug_ospf6_lsa_type, |
| 773 | debug_ospf6_lsa_hex_cmd, |
Dinesh Dutt | 09df457 | 2013-08-24 07:54:31 +0000 | [diff] [blame] | 774 | "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] | 775 | DEBUG_STR |
| 776 | OSPF6_STR |
| 777 | "Debug Link State Advertisements (LSAs)\n" |
| 778 | "Specify LS type as Hexadecimal\n" |
| 779 | ) |
| 780 | { |
paul | 0c083ee | 2004-10-10 12:54:58 +0000 | [diff] [blame] | 781 | unsigned int i; |
hasso | 1e05838 | 2004-09-01 21:36:14 +0000 | [diff] [blame] | 782 | struct ospf6_lsa_handler *handler = NULL; |
hasso | 1e05838 | 2004-09-01 21:36:14 +0000 | [diff] [blame] | 783 | |
| 784 | assert (argc); |
| 785 | |
paul | 55468c8 | 2005-03-14 20:19:01 +0000 | [diff] [blame] | 786 | for (i = 0; i < vector_active (ospf6_lsa_handler_vector); i++) |
hasso | 1e05838 | 2004-09-01 21:36:14 +0000 | [diff] [blame] | 787 | { |
| 788 | handler = vector_slot (ospf6_lsa_handler_vector, i); |
| 789 | if (handler == NULL) |
| 790 | continue; |
Dinesh Dutt | 09df457 | 2013-08-24 07:54:31 +0000 | [diff] [blame] | 791 | if (strncmp (argv[0], ospf6_lsa_handler_name(handler), strlen(argv[0])) == 0) |
hasso | 1e05838 | 2004-09-01 21:36:14 +0000 | [diff] [blame] | 792 | break; |
| 793 | if (! strcasecmp (argv[0], handler->name)) |
| 794 | break; |
| 795 | handler = NULL; |
| 796 | } |
| 797 | |
hasso | 1e05838 | 2004-09-01 21:36:14 +0000 | [diff] [blame] | 798 | if (handler == NULL) |
| 799 | handler = &unknown_handler; |
| 800 | |
| 801 | if (argc >= 2) |
| 802 | { |
| 803 | if (! strcmp (argv[1], "originate")) |
| 804 | SET_FLAG (handler->debug, OSPF6_LSA_DEBUG_ORIGINATE); |
Dinesh Dutt | 09df457 | 2013-08-24 07:54:31 +0000 | [diff] [blame] | 805 | if (! strcmp (argv[1], "examine")) |
hasso | 1e05838 | 2004-09-01 21:36:14 +0000 | [diff] [blame] | 806 | SET_FLAG (handler->debug, OSPF6_LSA_DEBUG_EXAMIN); |
| 807 | if (! strcmp (argv[1], "flooding")) |
| 808 | SET_FLAG (handler->debug, OSPF6_LSA_DEBUG_FLOOD); |
| 809 | } |
| 810 | else |
| 811 | SET_FLAG (handler->debug, OSPF6_LSA_DEBUG); |
| 812 | |
| 813 | return CMD_SUCCESS; |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 814 | } |
| 815 | |
Dinesh Dutt | 09df457 | 2013-08-24 07:54:31 +0000 | [diff] [blame] | 816 | ALIAS (debug_ospf6_lsa_type, |
| 817 | debug_ospf6_lsa_hex_detail_cmd, |
| 818 | "debug ospf6 lsa (router|network|inter-prefix|inter-router|as-ext|grp-mbr|type7|link|intra-prefix|unknown) (originate|examine|flooding)", |
| 819 | DEBUG_STR |
| 820 | OSPF6_STR |
| 821 | "Debug Link State Advertisements (LSAs)\n" |
| 822 | "Specify LS type as Hexadecimal\n" |
| 823 | ) |
| 824 | |
hasso | 1e05838 | 2004-09-01 21:36:14 +0000 | [diff] [blame] | 825 | DEFUN (no_debug_ospf6_lsa_type, |
| 826 | no_debug_ospf6_lsa_hex_cmd, |
Dinesh Dutt | 09df457 | 2013-08-24 07:54:31 +0000 | [diff] [blame] | 827 | "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] | 828 | NO_STR |
| 829 | DEBUG_STR |
| 830 | OSPF6_STR |
| 831 | "Debug Link State Advertisements (LSAs)\n" |
| 832 | "Specify LS type as Hexadecimal\n" |
| 833 | ) |
| 834 | { |
paul | 0c083ee | 2004-10-10 12:54:58 +0000 | [diff] [blame] | 835 | u_int i; |
hasso | 1e05838 | 2004-09-01 21:36:14 +0000 | [diff] [blame] | 836 | struct ospf6_lsa_handler *handler = NULL; |
hasso | 1e05838 | 2004-09-01 21:36:14 +0000 | [diff] [blame] | 837 | |
| 838 | assert (argc); |
| 839 | |
paul | 55468c8 | 2005-03-14 20:19:01 +0000 | [diff] [blame] | 840 | for (i = 0; i < vector_active (ospf6_lsa_handler_vector); i++) |
hasso | 1e05838 | 2004-09-01 21:36:14 +0000 | [diff] [blame] | 841 | { |
| 842 | handler = vector_slot (ospf6_lsa_handler_vector, i); |
| 843 | if (handler == NULL) |
| 844 | continue; |
Dinesh Dutt | 09df457 | 2013-08-24 07:54:31 +0000 | [diff] [blame] | 845 | if (strncmp (argv[0], ospf6_lsa_handler_name(handler), strlen(argv[0])) == 0) |
hasso | 1e05838 | 2004-09-01 21:36:14 +0000 | [diff] [blame] | 846 | break; |
| 847 | if (! strcasecmp (argv[0], handler->name)) |
| 848 | break; |
| 849 | } |
| 850 | |
| 851 | if (handler == NULL) |
| 852 | return CMD_SUCCESS; |
| 853 | |
| 854 | if (argc >= 2) |
| 855 | { |
| 856 | if (! strcmp (argv[1], "originate")) |
| 857 | UNSET_FLAG (handler->debug, OSPF6_LSA_DEBUG_ORIGINATE); |
Dinesh Dutt | 09df457 | 2013-08-24 07:54:31 +0000 | [diff] [blame] | 858 | if (! strcmp (argv[1], "examine")) |
hasso | 1e05838 | 2004-09-01 21:36:14 +0000 | [diff] [blame] | 859 | UNSET_FLAG (handler->debug, OSPF6_LSA_DEBUG_EXAMIN); |
| 860 | if (! strcmp (argv[1], "flooding")) |
| 861 | UNSET_FLAG (handler->debug, OSPF6_LSA_DEBUG_FLOOD); |
| 862 | } |
| 863 | else |
| 864 | UNSET_FLAG (handler->debug, OSPF6_LSA_DEBUG); |
| 865 | |
hasso | 1e05838 | 2004-09-01 21:36:14 +0000 | [diff] [blame] | 866 | return CMD_SUCCESS; |
| 867 | } |
| 868 | |
Dinesh Dutt | 09df457 | 2013-08-24 07:54:31 +0000 | [diff] [blame] | 869 | ALIAS (no_debug_ospf6_lsa_type, |
| 870 | no_debug_ospf6_lsa_hex_detail_cmd, |
| 871 | "no debug ospf6 lsa (router|network|inter-prefix|inter-router|as-ext|grp-mbr|type7|link|intra-prefix) (originate|examine|flooding)", |
| 872 | NO_STR |
| 873 | DEBUG_STR |
| 874 | OSPF6_STR |
| 875 | "Debug Link State Advertisements (LSAs)\n" |
| 876 | "Specify LS type as Hexadecimal\n" |
| 877 | ) |
hasso | 1e05838 | 2004-09-01 21:36:14 +0000 | [diff] [blame] | 878 | |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 879 | void |
Paul Jakma | 6ac29a5 | 2008-08-15 13:45:30 +0100 | [diff] [blame] | 880 | install_element_ospf6_debug_lsa (void) |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 881 | { |
hasso | 1e05838 | 2004-09-01 21:36:14 +0000 | [diff] [blame] | 882 | install_element (ENABLE_NODE, &debug_ospf6_lsa_hex_cmd); |
Dinesh Dutt | 09df457 | 2013-08-24 07:54:31 +0000 | [diff] [blame] | 883 | install_element (ENABLE_NODE, &debug_ospf6_lsa_hex_detail_cmd); |
hasso | 1e05838 | 2004-09-01 21:36:14 +0000 | [diff] [blame] | 884 | install_element (ENABLE_NODE, &no_debug_ospf6_lsa_hex_cmd); |
Dinesh Dutt | 09df457 | 2013-08-24 07:54:31 +0000 | [diff] [blame] | 885 | install_element (ENABLE_NODE, &no_debug_ospf6_lsa_hex_detail_cmd); |
hasso | 1e05838 | 2004-09-01 21:36:14 +0000 | [diff] [blame] | 886 | install_element (CONFIG_NODE, &debug_ospf6_lsa_hex_cmd); |
Dinesh Dutt | 09df457 | 2013-08-24 07:54:31 +0000 | [diff] [blame] | 887 | install_element (CONFIG_NODE, &debug_ospf6_lsa_hex_detail_cmd); |
hasso | 1e05838 | 2004-09-01 21:36:14 +0000 | [diff] [blame] | 888 | install_element (CONFIG_NODE, &no_debug_ospf6_lsa_hex_cmd); |
Dinesh Dutt | 09df457 | 2013-08-24 07:54:31 +0000 | [diff] [blame] | 889 | install_element (CONFIG_NODE, &no_debug_ospf6_lsa_hex_detail_cmd); |
hasso | 1e05838 | 2004-09-01 21:36:14 +0000 | [diff] [blame] | 890 | } |
| 891 | |
| 892 | int |
| 893 | config_write_ospf6_debug_lsa (struct vty *vty) |
| 894 | { |
paul | 0c083ee | 2004-10-10 12:54:58 +0000 | [diff] [blame] | 895 | u_int i; |
hasso | 1e05838 | 2004-09-01 21:36:14 +0000 | [diff] [blame] | 896 | struct ospf6_lsa_handler *handler; |
| 897 | |
paul | 55468c8 | 2005-03-14 20:19:01 +0000 | [diff] [blame] | 898 | for (i = 0; i < vector_active (ospf6_lsa_handler_vector); i++) |
hasso | 1e05838 | 2004-09-01 21:36:14 +0000 | [diff] [blame] | 899 | { |
| 900 | handler = vector_slot (ospf6_lsa_handler_vector, i); |
| 901 | if (handler == NULL) |
| 902 | continue; |
| 903 | if (CHECK_FLAG (handler->debug, OSPF6_LSA_DEBUG)) |
| 904 | vty_out (vty, "debug ospf6 lsa %s%s", |
| 905 | ospf6_lsa_handler_name (handler), VNL); |
| 906 | if (CHECK_FLAG (handler->debug, OSPF6_LSA_DEBUG_ORIGINATE)) |
| 907 | vty_out (vty, "debug ospf6 lsa %s originate%s", |
| 908 | ospf6_lsa_handler_name (handler), VNL); |
| 909 | if (CHECK_FLAG (handler->debug, OSPF6_LSA_DEBUG_EXAMIN)) |
Dinesh Dutt | 09df457 | 2013-08-24 07:54:31 +0000 | [diff] [blame] | 910 | vty_out (vty, "debug ospf6 lsa %s examine%s", |
hasso | 1e05838 | 2004-09-01 21:36:14 +0000 | [diff] [blame] | 911 | ospf6_lsa_handler_name (handler), VNL); |
| 912 | if (CHECK_FLAG (handler->debug, OSPF6_LSA_DEBUG_FLOOD)) |
| 913 | vty_out (vty, "debug ospf6 lsa %s flooding%s", |
| 914 | ospf6_lsa_handler_name (handler), VNL); |
| 915 | } |
| 916 | |
| 917 | return 0; |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 918 | } |
| 919 | |
| 920 | |