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" |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 32 | |
| 33 | #include "ospf6_proto.h" |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 34 | #include "ospf6_lsa.h" |
| 35 | #include "ospf6_lsdb.h" |
| 36 | #include "ospf6_message.h" |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 37 | |
| 38 | #include "ospf6_top.h" |
| 39 | #include "ospf6_area.h" |
| 40 | #include "ospf6_interface.h" |
| 41 | #include "ospf6_neighbor.h" |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 42 | |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 43 | #include "ospf6_flood.h" |
hasso | 049207c | 2004-08-04 20:02:13 +0000 | [diff] [blame] | 44 | #include "ospf6d.h" |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 45 | |
hasso | 1e05838 | 2004-09-01 21:36:14 +0000 | [diff] [blame] | 46 | vector ospf6_lsa_handler_vector; |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 47 | |
Paul Jakma | 6ac29a5 | 2008-08-15 13:45:30 +0100 | [diff] [blame] | 48 | static int |
hasso | 1e05838 | 2004-09-01 21:36:14 +0000 | [diff] [blame] | 49 | ospf6_unknown_lsa_show (struct vty *vty, struct ospf6_lsa *lsa) |
| 50 | { |
| 51 | u_char *start, *end, *current; |
| 52 | char byte[4]; |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 53 | |
hasso | 03d52f8 | 2004-09-29 00:26:19 +0000 | [diff] [blame] | 54 | start = (u_char *) lsa->header + sizeof (struct ospf6_lsa_header); |
| 55 | end = (u_char *) lsa->header + ntohs (lsa->header->length); |
hasso | 1e05838 | 2004-09-01 21:36:14 +0000 | [diff] [blame] | 56 | |
| 57 | vty_out (vty, " Unknown contents:%s", VNL); |
| 58 | for (current = start; current < end; current ++) |
| 59 | { |
| 60 | if ((current - start) % 16 == 0) |
| 61 | vty_out (vty, "%s ", VNL); |
| 62 | else if ((current - start) % 4 == 0) |
| 63 | vty_out (vty, " "); |
| 64 | |
| 65 | snprintf (byte, sizeof (byte), "%02x", *current); |
| 66 | vty_out (vty, "%s", byte); |
| 67 | } |
| 68 | |
| 69 | vty_out (vty, "%s%s", VNL, VNL); |
| 70 | return 0; |
| 71 | } |
| 72 | |
| 73 | struct ospf6_lsa_handler unknown_handler = |
| 74 | { |
| 75 | OSPF6_LSTYPE_UNKNOWN, |
| 76 | "Unknown", |
| 77 | ospf6_unknown_lsa_show, |
| 78 | OSPF6_LSA_DEBUG, |
| 79 | }; |
| 80 | |
| 81 | void |
| 82 | ospf6_install_lsa_handler (struct ospf6_lsa_handler *handler) |
| 83 | { |
| 84 | /* type in handler is host byte order */ |
| 85 | int index = handler->type & OSPF6_LSTYPE_FCODE_MASK; |
| 86 | vector_set_index (ospf6_lsa_handler_vector, index, handler); |
| 87 | } |
| 88 | |
| 89 | struct ospf6_lsa_handler * |
| 90 | ospf6_get_lsa_handler (u_int16_t type) |
| 91 | { |
| 92 | struct ospf6_lsa_handler *handler = NULL; |
paul | 0c083ee | 2004-10-10 12:54:58 +0000 | [diff] [blame] | 93 | unsigned int index = ntohs (type) & OSPF6_LSTYPE_FCODE_MASK; |
hasso | 1e05838 | 2004-09-01 21:36:14 +0000 | [diff] [blame] | 94 | |
paul | 55468c8 | 2005-03-14 20:19:01 +0000 | [diff] [blame] | 95 | if (index >= vector_active (ospf6_lsa_handler_vector)) |
hasso | 1e05838 | 2004-09-01 21:36:14 +0000 | [diff] [blame] | 96 | handler = &unknown_handler; |
| 97 | else |
| 98 | handler = vector_slot (ospf6_lsa_handler_vector, index); |
| 99 | |
hasso | 2680aa2 | 2004-11-25 20:54:46 +0000 | [diff] [blame] | 100 | if (handler == NULL) |
| 101 | handler = &unknown_handler; |
| 102 | |
hasso | 1e05838 | 2004-09-01 21:36:14 +0000 | [diff] [blame] | 103 | return handler; |
| 104 | } |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 105 | |
paul | 0c083ee | 2004-10-10 12:54:58 +0000 | [diff] [blame] | 106 | const char * |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 107 | ospf6_lstype_name (u_int16_t type) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 108 | { |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 109 | static char buf[8]; |
hasso | 1e05838 | 2004-09-01 21:36:14 +0000 | [diff] [blame] | 110 | struct ospf6_lsa_handler *handler; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 111 | |
hasso | 1e05838 | 2004-09-01 21:36:14 +0000 | [diff] [blame] | 112 | handler = ospf6_get_lsa_handler (type); |
| 113 | if (handler && handler != &unknown_handler) |
| 114 | return handler->name; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 115 | |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 116 | snprintf (buf, sizeof (buf), "0x%04hx", ntohs (type)); |
| 117 | return buf; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 118 | } |
| 119 | |
hasso | 1e05838 | 2004-09-01 21:36:14 +0000 | [diff] [blame] | 120 | u_char |
| 121 | ospf6_lstype_debug (u_int16_t type) |
| 122 | { |
| 123 | struct ospf6_lsa_handler *handler; |
| 124 | handler = ospf6_get_lsa_handler (type); |
| 125 | return handler->debug; |
| 126 | } |
| 127 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 128 | /* RFC2328: Section 13.2 */ |
| 129 | int |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 130 | ospf6_lsa_is_differ (struct ospf6_lsa *lsa1, |
| 131 | struct ospf6_lsa *lsa2) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 132 | { |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 133 | int len; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 134 | |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 135 | assert (OSPF6_LSA_IS_SAME (lsa1, lsa2)); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 136 | |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 137 | /* XXX, Options ??? */ |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 138 | |
| 139 | ospf6_lsa_age_current (lsa1); |
| 140 | ospf6_lsa_age_current (lsa2); |
| 141 | if (ntohs (lsa1->header->age) == MAXAGE && |
| 142 | ntohs (lsa2->header->age) != MAXAGE) |
| 143 | return 1; |
| 144 | if (ntohs (lsa1->header->age) != MAXAGE && |
| 145 | ntohs (lsa2->header->age) == MAXAGE) |
| 146 | return 1; |
| 147 | |
| 148 | /* compare body */ |
| 149 | if (ntohs (lsa1->header->length) != ntohs (lsa2->header->length)) |
| 150 | return 1; |
| 151 | |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 152 | len = ntohs (lsa1->header->length) - sizeof (struct ospf6_lsa_header); |
| 153 | return memcmp (lsa1->header + 1, lsa2->header + 1, len); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 154 | } |
| 155 | |
| 156 | int |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 157 | ospf6_lsa_is_changed (struct ospf6_lsa *lsa1, |
| 158 | struct ospf6_lsa *lsa2) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 159 | { |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 160 | int length; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 161 | |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 162 | if (OSPF6_LSA_IS_MAXAGE (lsa1) ^ OSPF6_LSA_IS_MAXAGE (lsa2)) |
| 163 | return 1; |
| 164 | if (ntohs (lsa1->header->length) != ntohs (lsa2->header->length)) |
| 165 | return 1; |
Denis Ovsienko | 09395e2 | 2011-09-26 13:18:36 +0400 | [diff] [blame] | 166 | /* Going beyond LSA headers to compare the payload only makes sense, when both LSAs aren't header-only. */ |
| 167 | if (CHECK_FLAG (lsa1->flag, OSPF6_LSA_HEADERONLY) != CHECK_FLAG (lsa2->flag, OSPF6_LSA_HEADERONLY)) |
| 168 | { |
| 169 | zlog_warn ("%s: only one of two (%s, %s) LSAs compared is header-only", __func__, lsa1->name, lsa2->name); |
| 170 | return 1; |
| 171 | } |
| 172 | if (CHECK_FLAG (lsa1->flag, OSPF6_LSA_HEADERONLY)) |
| 173 | return 0; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 174 | |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 175 | length = OSPF6_LSA_SIZE (lsa1->header) - sizeof (struct ospf6_lsa_header); |
Denis Ovsienko | 09395e2 | 2011-09-26 13:18:36 +0400 | [diff] [blame] | 176 | /* Once upper layer verifies LSAs received, length underrun should become a warning. */ |
| 177 | if (length <= 0) |
| 178 | return 0; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 179 | |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 180 | return memcmp (OSPF6_LSA_HEADER_END (lsa1->header), |
| 181 | OSPF6_LSA_HEADER_END (lsa2->header), length); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 182 | } |
| 183 | |
| 184 | /* ospf6 age functions */ |
hasso | 3b68735 | 2004-08-19 06:56:53 +0000 | [diff] [blame] | 185 | /* calculate birth */ |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 186 | static void |
| 187 | ospf6_lsa_age_set (struct ospf6_lsa *lsa) |
| 188 | { |
| 189 | struct timeval now; |
| 190 | |
| 191 | assert (lsa && lsa->header); |
| 192 | |
Takashi Sogabe | 86f72dc | 2009-06-22 13:07:02 +0900 | [diff] [blame] | 193 | if (quagga_gettime (QUAGGA_CLK_MONOTONIC, &now) < 0) |
| 194 | zlog_warn ("LSA: quagga_gettime failed, may fail LSA AGEs: %s", |
ajs | 6099b3b | 2004-11-20 02:06:59 +0000 | [diff] [blame] | 195 | safe_strerror (errno)); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 196 | |
| 197 | lsa->birth.tv_sec = now.tv_sec - ntohs (lsa->header->age); |
| 198 | lsa->birth.tv_usec = now.tv_usec; |
hasso | 3b68735 | 2004-08-19 06:56:53 +0000 | [diff] [blame] | 199 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 200 | return; |
| 201 | } |
| 202 | |
| 203 | /* this function calculates current age from its birth, |
| 204 | then update age field of LSA header. return value is current age */ |
| 205 | u_int16_t |
| 206 | ospf6_lsa_age_current (struct ospf6_lsa *lsa) |
| 207 | { |
| 208 | struct timeval now; |
| 209 | u_int32_t ulage; |
| 210 | u_int16_t age; |
| 211 | |
| 212 | assert (lsa); |
| 213 | assert (lsa->header); |
| 214 | |
| 215 | /* current time */ |
Takashi Sogabe | 86f72dc | 2009-06-22 13:07:02 +0900 | [diff] [blame] | 216 | if (quagga_gettime (QUAGGA_CLK_MONOTONIC, &now) < 0) |
| 217 | zlog_warn ("LSA: quagga_gettime failed, may fail LSA AGEs: %s", |
ajs | 6099b3b | 2004-11-20 02:06:59 +0000 | [diff] [blame] | 218 | safe_strerror (errno)); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 219 | |
Tom Henderson | aabbb1a | 2009-08-28 15:10:00 +0100 | [diff] [blame] | 220 | if (ntohs (lsa->header->age) >= MAXAGE) |
Tom Henderson | 9b4ef25 | 2009-07-16 17:20:37 +0100 | [diff] [blame] | 221 | { |
Tom Henderson | aabbb1a | 2009-08-28 15:10:00 +0100 | [diff] [blame] | 222 | /* ospf6_lsa_premature_aging () sets age to MAXAGE; when using |
| 223 | relative time, we cannot compare against lsa birth time, so |
| 224 | we catch this special case here. */ |
Tom Henderson | 9b4ef25 | 2009-07-16 17:20:37 +0100 | [diff] [blame] | 225 | lsa->header->age = htons (MAXAGE); |
| 226 | return MAXAGE; |
| 227 | } |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 228 | /* calculate age */ |
| 229 | ulage = now.tv_sec - lsa->birth.tv_sec; |
| 230 | |
| 231 | /* if over MAXAGE, set to it */ |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 232 | age = (ulage > MAXAGE ? MAXAGE : ulage); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 233 | |
| 234 | lsa->header->age = htons (age); |
| 235 | return age; |
| 236 | } |
| 237 | |
| 238 | /* update age field of LSA header with adding InfTransDelay */ |
| 239 | void |
| 240 | ospf6_lsa_age_update_to_send (struct ospf6_lsa *lsa, u_int32_t transdelay) |
| 241 | { |
| 242 | unsigned short age; |
| 243 | |
| 244 | age = ospf6_lsa_age_current (lsa) + transdelay; |
| 245 | if (age > MAXAGE) |
| 246 | age = MAXAGE; |
| 247 | lsa->header->age = htons (age); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 248 | } |
| 249 | |
| 250 | void |
| 251 | ospf6_lsa_premature_aging (struct ospf6_lsa *lsa) |
| 252 | { |
| 253 | /* log */ |
hasso | 1e05838 | 2004-09-01 21:36:14 +0000 | [diff] [blame] | 254 | if (IS_OSPF6_DEBUG_LSA_TYPE (lsa->header->type)) |
hasso | c6487d6 | 2004-12-24 06:00:11 +0000 | [diff] [blame] | 255 | zlog_debug ("LSA: Premature aging: %s", lsa->name); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 256 | |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 257 | THREAD_OFF (lsa->expire); |
| 258 | THREAD_OFF (lsa->refresh); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 259 | |
Tom Henderson | 9b4ef25 | 2009-07-16 17:20:37 +0100 | [diff] [blame] | 260 | lsa->header->age = htons (MAXAGE); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 261 | thread_execute (master, ospf6_lsa_expire, lsa, 0); |
| 262 | } |
| 263 | |
| 264 | /* check which is more recent. if a is more recent, return -1; |
| 265 | if the same, return 0; otherwise(b is more recent), return 1 */ |
| 266 | int |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 267 | ospf6_lsa_compare (struct ospf6_lsa *a, struct ospf6_lsa *b) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 268 | { |
Ondrej Zajicek | 64bf3ab | 2009-12-07 12:33:20 +0300 | [diff] [blame] | 269 | int seqnuma, seqnumb; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 270 | u_int16_t cksuma, cksumb; |
| 271 | u_int16_t agea, ageb; |
| 272 | |
| 273 | assert (a && a->header); |
| 274 | assert (b && b->header); |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 275 | assert (OSPF6_LSA_IS_SAME (a, b)); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 276 | |
Ondrej Zajicek | 64bf3ab | 2009-12-07 12:33:20 +0300 | [diff] [blame] | 277 | seqnuma = (int) ntohl (a->header->seqnum); |
| 278 | seqnumb = (int) ntohl (b->header->seqnum); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 279 | |
| 280 | /* compare by sequence number */ |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 281 | if (seqnuma > seqnumb) |
| 282 | return -1; |
Ondrej Zajicek | 64bf3ab | 2009-12-07 12:33:20 +0300 | [diff] [blame] | 283 | if (seqnuma < seqnumb) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 284 | return 1; |
| 285 | |
| 286 | /* Checksum */ |
| 287 | cksuma = ntohs (a->header->checksum); |
| 288 | cksumb = ntohs (b->header->checksum); |
| 289 | if (cksuma > cksumb) |
| 290 | return -1; |
| 291 | if (cksuma < cksumb) |
| 292 | return 0; |
| 293 | |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 294 | /* Update Age */ |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 295 | agea = ospf6_lsa_age_current (a); |
| 296 | ageb = ospf6_lsa_age_current (b); |
| 297 | |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 298 | /* MaxAge check */ |
| 299 | if (agea == MAXAGE && ageb != MAXAGE) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 300 | return -1; |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 301 | else if (agea != MAXAGE && ageb == MAXAGE) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 302 | return 1; |
| 303 | |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 304 | /* Age check */ |
| 305 | if (agea > ageb && agea - ageb >= MAX_AGE_DIFF) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 306 | return 1; |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 307 | else if (agea < ageb && ageb - agea >= MAX_AGE_DIFF) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 308 | return -1; |
| 309 | |
| 310 | /* neither recent */ |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 311 | return 0; |
| 312 | } |
| 313 | |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 314 | char * |
| 315 | ospf6_lsa_printbuf (struct ospf6_lsa *lsa, char *buf, int size) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 316 | { |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 317 | char id[16], adv_router[16]; |
| 318 | inet_ntop (AF_INET, &lsa->header->id, id, sizeof (id)); |
| 319 | inet_ntop (AF_INET, &lsa->header->adv_router, adv_router, |
| 320 | sizeof (adv_router)); |
| 321 | snprintf (buf, size, "[%s Id:%s Adv:%s]", |
hasso | 1e05838 | 2004-09-01 21:36:14 +0000 | [diff] [blame] | 322 | ospf6_lstype_name (lsa->header->type), id, adv_router); |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 323 | return buf; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 324 | } |
| 325 | |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 326 | void |
| 327 | ospf6_lsa_header_print_raw (struct ospf6_lsa_header *header) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 328 | { |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 329 | char id[16], adv_router[16]; |
| 330 | inet_ntop (AF_INET, &header->id, id, sizeof (id)); |
| 331 | inet_ntop (AF_INET, &header->adv_router, adv_router, |
| 332 | sizeof (adv_router)); |
hasso | c6487d6 | 2004-12-24 06:00:11 +0000 | [diff] [blame] | 333 | zlog_debug (" [%s Id:%s Adv:%s]", |
| 334 | ospf6_lstype_name (header->type), id, adv_router); |
| 335 | zlog_debug (" Age: %4hu SeqNum: %#08lx Cksum: %04hx Len: %d", |
| 336 | ntohs (header->age), (u_long) ntohl (header->seqnum), |
| 337 | ntohs (header->checksum), ntohs (header->length)); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 338 | } |
| 339 | |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 340 | void |
| 341 | ospf6_lsa_header_print (struct ospf6_lsa *lsa) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 342 | { |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 343 | ospf6_lsa_age_current (lsa); |
| 344 | ospf6_lsa_header_print_raw (lsa->header); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 345 | } |
| 346 | |
| 347 | void |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 348 | ospf6_lsa_show_summary_header (struct vty *vty) |
| 349 | { |
| 350 | vty_out (vty, "%-12s %-15s %-15s %4s %8s %4s %4s %-8s%s", |
| 351 | "Type", "LSId", "AdvRouter", "Age", "SeqNum", |
hasso | 049207c | 2004-08-04 20:02:13 +0000 | [diff] [blame] | 352 | "Cksm", "Len", "Duration", VNL); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 353 | } |
| 354 | |
| 355 | void |
| 356 | ospf6_lsa_show_summary (struct vty *vty, struct ospf6_lsa *lsa) |
| 357 | { |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 358 | char adv_router[16], id[16]; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 359 | struct timeval now, res; |
| 360 | char duration[16]; |
| 361 | |
| 362 | assert (lsa); |
| 363 | assert (lsa->header); |
| 364 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 365 | inet_ntop (AF_INET, &lsa->header->id, id, sizeof (id)); |
| 366 | inet_ntop (AF_INET, &lsa->header->adv_router, adv_router, |
| 367 | sizeof (adv_router)); |
| 368 | |
Takashi Sogabe | 86f72dc | 2009-06-22 13:07:02 +0900 | [diff] [blame] | 369 | quagga_gettime (QUAGGA_CLK_MONOTONIC, &now); |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 370 | timersub (&now, &lsa->installed, &res); |
| 371 | timerstring (&res, duration, sizeof (duration)); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 372 | |
| 373 | vty_out (vty, "%-12s %-15s %-15s %4hu %8lx %04hx %4hu %8s%s", |
hasso | 1e05838 | 2004-09-01 21:36:14 +0000 | [diff] [blame] | 374 | ospf6_lstype_name (lsa->header->type), |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 375 | id, adv_router, ospf6_lsa_age_current (lsa), |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 376 | (u_long) ntohl (lsa->header->seqnum), |
| 377 | ntohs (lsa->header->checksum), ntohs (lsa->header->length), |
hasso | 049207c | 2004-08-04 20:02:13 +0000 | [diff] [blame] | 378 | duration, VNL); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 379 | } |
| 380 | |
| 381 | void |
| 382 | ospf6_lsa_show_dump (struct vty *vty, struct ospf6_lsa *lsa) |
| 383 | { |
| 384 | u_char *start, *end, *current; |
| 385 | char byte[4]; |
| 386 | |
hasso | 03d52f8 | 2004-09-29 00:26:19 +0000 | [diff] [blame] | 387 | start = (u_char *) lsa->header; |
| 388 | end = (u_char *) lsa->header + ntohs (lsa->header->length); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 389 | |
hasso | 049207c | 2004-08-04 20:02:13 +0000 | [diff] [blame] | 390 | vty_out (vty, "%s", VNL); |
| 391 | vty_out (vty, "%s:%s", lsa->name, VNL); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 392 | |
| 393 | for (current = start; current < end; current ++) |
| 394 | { |
| 395 | if ((current - start) % 16 == 0) |
hasso | 049207c | 2004-08-04 20:02:13 +0000 | [diff] [blame] | 396 | vty_out (vty, "%s ", VNL); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 397 | else if ((current - start) % 4 == 0) |
| 398 | vty_out (vty, " "); |
| 399 | |
| 400 | snprintf (byte, sizeof (byte), "%02x", *current); |
| 401 | vty_out (vty, "%s", byte); |
| 402 | } |
| 403 | |
hasso | 049207c | 2004-08-04 20:02:13 +0000 | [diff] [blame] | 404 | vty_out (vty, "%s%s", VNL, VNL); |
hasso | 6452df0 | 2004-08-15 05:52:07 +0000 | [diff] [blame] | 405 | return; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 406 | } |
| 407 | |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 408 | void |
| 409 | ospf6_lsa_show_internal (struct vty *vty, struct ospf6_lsa *lsa) |
| 410 | { |
| 411 | char adv_router[64], id[64]; |
| 412 | |
| 413 | assert (lsa && lsa->header); |
| 414 | |
| 415 | inet_ntop (AF_INET, &lsa->header->id, id, sizeof (id)); |
| 416 | inet_ntop (AF_INET, &lsa->header->adv_router, |
| 417 | adv_router, sizeof (adv_router)); |
| 418 | |
hasso | 049207c | 2004-08-04 20:02:13 +0000 | [diff] [blame] | 419 | vty_out (vty, "%s", VNL); |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 420 | vty_out (vty, "Age: %4hu Type: %s%s", ospf6_lsa_age_current (lsa), |
hasso | 1e05838 | 2004-09-01 21:36:14 +0000 | [diff] [blame] | 421 | ospf6_lstype_name (lsa->header->type), VNL); |
hasso | 049207c | 2004-08-04 20:02:13 +0000 | [diff] [blame] | 422 | vty_out (vty, "Link State ID: %s%s", id, VNL); |
| 423 | vty_out (vty, "Advertising Router: %s%s", adv_router, VNL); |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 424 | vty_out (vty, "LS Sequence Number: %#010lx%s", |
hasso | 049207c | 2004-08-04 20:02:13 +0000 | [diff] [blame] | 425 | (u_long) ntohl (lsa->header->seqnum), VNL); |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 426 | vty_out (vty, "CheckSum: %#06hx Length: %hu%s", |
| 427 | ntohs (lsa->header->checksum), |
hasso | 049207c | 2004-08-04 20:02:13 +0000 | [diff] [blame] | 428 | ntohs (lsa->header->length), VNL); |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 429 | vty_out (vty, " Prev: %p This: %p Next: %p%s", |
hasso | 049207c | 2004-08-04 20:02:13 +0000 | [diff] [blame] | 430 | lsa->prev, lsa, lsa->next, VNL); |
| 431 | vty_out (vty, "%s", VNL); |
hasso | 6452df0 | 2004-08-15 05:52:07 +0000 | [diff] [blame] | 432 | return; |
| 433 | } |
| 434 | |
| 435 | void |
| 436 | ospf6_lsa_show (struct vty *vty, struct ospf6_lsa *lsa) |
| 437 | { |
| 438 | char adv_router[64], id[64]; |
hasso | 1e05838 | 2004-09-01 21:36:14 +0000 | [diff] [blame] | 439 | struct ospf6_lsa_handler *handler; |
hasso | 6452df0 | 2004-08-15 05:52:07 +0000 | [diff] [blame] | 440 | |
| 441 | assert (lsa && lsa->header); |
| 442 | |
| 443 | inet_ntop (AF_INET, &lsa->header->id, id, sizeof (id)); |
| 444 | inet_ntop (AF_INET, &lsa->header->adv_router, |
| 445 | adv_router, sizeof (adv_router)); |
| 446 | |
| 447 | vty_out (vty, "Age: %4hu Type: %s%s", ospf6_lsa_age_current (lsa), |
hasso | 1e05838 | 2004-09-01 21:36:14 +0000 | [diff] [blame] | 448 | ospf6_lstype_name (lsa->header->type), VNL); |
hasso | 6452df0 | 2004-08-15 05:52:07 +0000 | [diff] [blame] | 449 | vty_out (vty, "Link State ID: %s%s", id, VNL); |
| 450 | vty_out (vty, "Advertising Router: %s%s", adv_router, VNL); |
| 451 | vty_out (vty, "LS Sequence Number: %#010lx%s", |
| 452 | (u_long) ntohl (lsa->header->seqnum), VNL); |
| 453 | vty_out (vty, "CheckSum: %#06hx Length: %hu%s", |
| 454 | ntohs (lsa->header->checksum), |
| 455 | ntohs (lsa->header->length), VNL); |
| 456 | |
hasso | 1e05838 | 2004-09-01 21:36:14 +0000 | [diff] [blame] | 457 | handler = ospf6_get_lsa_handler (lsa->header->type); |
| 458 | if (handler->show == NULL) |
| 459 | handler = &unknown_handler; |
| 460 | (*handler->show) (vty, lsa); |
hasso | 6452df0 | 2004-08-15 05:52:07 +0000 | [diff] [blame] | 461 | |
| 462 | vty_out (vty, "%s", VNL); |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 463 | } |
| 464 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 465 | /* OSPFv3 LSA creation/deletion function */ |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 466 | struct ospf6_lsa * |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 467 | ospf6_lsa_create (struct ospf6_lsa_header *header) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 468 | { |
| 469 | struct ospf6_lsa *lsa = NULL; |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 470 | struct ospf6_lsa_header *new_header = NULL; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 471 | u_int16_t lsa_size = 0; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 472 | |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 473 | /* size of the entire LSA */ |
| 474 | lsa_size = ntohs (header->length); /* XXX vulnerable */ |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 475 | |
| 476 | /* allocate memory for this LSA */ |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 477 | new_header = (struct ospf6_lsa_header *) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 478 | XMALLOC (MTYPE_OSPF6_LSA, lsa_size); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 479 | |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 480 | /* copy LSA from original header */ |
| 481 | memcpy (new_header, header, lsa_size); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 482 | |
| 483 | /* LSA information structure */ |
| 484 | /* allocate memory */ |
| 485 | lsa = (struct ospf6_lsa *) |
Stephen Hemminger | 393deb9 | 2008-08-18 14:13:29 -0700 | [diff] [blame] | 486 | XCALLOC (MTYPE_OSPF6_LSA, sizeof (struct ospf6_lsa)); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 487 | |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 488 | lsa->header = (struct ospf6_lsa_header *) new_header; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 489 | |
| 490 | /* dump string */ |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 491 | ospf6_lsa_printbuf (lsa, lsa->name, sizeof (lsa->name)); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 492 | |
hasso | 3b68735 | 2004-08-19 06:56:53 +0000 | [diff] [blame] | 493 | /* calculate birth of this lsa */ |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 494 | ospf6_lsa_age_set (lsa); |
| 495 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 496 | return lsa; |
| 497 | } |
| 498 | |
| 499 | struct ospf6_lsa * |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 500 | ospf6_lsa_create_headeronly (struct ospf6_lsa_header *header) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 501 | { |
| 502 | struct ospf6_lsa *lsa = NULL; |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 503 | struct ospf6_lsa_header *new_header = NULL; |
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 *) |
| 507 | XMALLOC (MTYPE_OSPF6_LSA, sizeof (struct ospf6_lsa_header)); |
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, sizeof (struct ospf6_lsa_header)); |
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; |
hasso | 6452df0 | 2004-08-15 05:52:07 +0000 | [diff] [blame] | 518 | SET_FLAG (lsa->flag, OSPF6_LSA_HEADERONLY); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 519 | |
| 520 | /* dump string */ |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 521 | ospf6_lsa_printbuf (lsa, lsa->name, sizeof (lsa->name)); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 522 | |
hasso | 3b68735 | 2004-08-19 06:56:53 +0000 | [diff] [blame] | 523 | /* calculate birth of this lsa */ |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 524 | ospf6_lsa_age_set (lsa); |
| 525 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 526 | return lsa; |
| 527 | } |
| 528 | |
| 529 | void |
| 530 | ospf6_lsa_delete (struct ospf6_lsa *lsa) |
| 531 | { |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 532 | assert (lsa->lock == 0); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 533 | |
| 534 | /* cancel threads */ |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 535 | THREAD_OFF (lsa->expire); |
| 536 | THREAD_OFF (lsa->refresh); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 537 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 538 | /* do free */ |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 539 | XFREE (MTYPE_OSPF6_LSA, lsa->header); |
| 540 | XFREE (MTYPE_OSPF6_LSA, lsa); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 541 | } |
| 542 | |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 543 | struct ospf6_lsa * |
| 544 | ospf6_lsa_copy (struct ospf6_lsa *lsa) |
| 545 | { |
| 546 | struct ospf6_lsa *copy = NULL; |
| 547 | |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 548 | ospf6_lsa_age_current (lsa); |
hasso | 6452df0 | 2004-08-15 05:52:07 +0000 | [diff] [blame] | 549 | if (CHECK_FLAG (lsa->flag, OSPF6_LSA_HEADERONLY)) |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 550 | copy = ospf6_lsa_create_headeronly (lsa->header); |
| 551 | else |
| 552 | copy = ospf6_lsa_create (lsa->header); |
| 553 | assert (copy->lock == 0); |
| 554 | |
hasso | 3b68735 | 2004-08-19 06:56:53 +0000 | [diff] [blame] | 555 | copy->birth = lsa->birth; |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 556 | copy->originated = lsa->originated; |
hasso | ccb59b1 | 2004-08-25 09:10:37 +0000 | [diff] [blame] | 557 | copy->received = lsa->received; |
| 558 | copy->installed = lsa->installed; |
hasso | 6452df0 | 2004-08-15 05:52:07 +0000 | [diff] [blame] | 559 | copy->lsdb = lsa->lsdb; |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 560 | |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 561 | return copy; |
| 562 | } |
| 563 | |
| 564 | /* increment reference counter of struct ospf6_lsa */ |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 565 | void |
| 566 | ospf6_lsa_lock (struct ospf6_lsa *lsa) |
| 567 | { |
| 568 | lsa->lock++; |
| 569 | return; |
| 570 | } |
| 571 | |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 572 | /* decrement reference counter of struct ospf6_lsa */ |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 573 | void |
| 574 | ospf6_lsa_unlock (struct ospf6_lsa *lsa) |
| 575 | { |
| 576 | /* decrement reference counter */ |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 577 | assert (lsa->lock > 0); |
| 578 | lsa->lock--; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 579 | |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 580 | if (lsa->lock != 0) |
| 581 | return; |
| 582 | |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 583 | ospf6_lsa_delete (lsa); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 584 | } |
| 585 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 586 | |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 587 | /* ospf6 lsa expiry */ |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 588 | int |
| 589 | ospf6_lsa_expire (struct thread *thread) |
| 590 | { |
| 591 | struct ospf6_lsa *lsa; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 592 | |
| 593 | lsa = (struct ospf6_lsa *) THREAD_ARG (thread); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 594 | |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 595 | assert (lsa && lsa->header); |
| 596 | assert (OSPF6_LSA_IS_MAXAGE (lsa)); |
| 597 | assert (! lsa->refresh); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 598 | |
| 599 | lsa->expire = (struct thread *) NULL; |
| 600 | |
hasso | 1e05838 | 2004-09-01 21:36:14 +0000 | [diff] [blame] | 601 | if (IS_OSPF6_DEBUG_LSA_TYPE (lsa->header->type)) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 602 | { |
hasso | c6487d6 | 2004-12-24 06:00:11 +0000 | [diff] [blame] | 603 | zlog_debug ("LSA Expire:"); |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 604 | ospf6_lsa_header_print (lsa); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 605 | } |
| 606 | |
hasso | 6452df0 | 2004-08-15 05:52:07 +0000 | [diff] [blame] | 607 | if (CHECK_FLAG (lsa->flag, OSPF6_LSA_HEADERONLY)) |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 608 | return 0; /* dbexchange will do something ... */ |
| 609 | |
| 610 | /* reflood lsa */ |
hasso | 6452df0 | 2004-08-15 05:52:07 +0000 | [diff] [blame] | 611 | ospf6_flood (NULL, lsa); |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 612 | |
| 613 | /* reinstall lsa */ |
hasso | 3b68735 | 2004-08-19 06:56:53 +0000 | [diff] [blame] | 614 | ospf6_install_lsa (lsa); |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 615 | |
| 616 | /* schedule maxage remover */ |
| 617 | ospf6_maxage_remove (ospf6); |
| 618 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 619 | return 0; |
| 620 | } |
| 621 | |
| 622 | int |
| 623 | ospf6_lsa_refresh (struct thread *thread) |
| 624 | { |
hasso | 6452df0 | 2004-08-15 05:52:07 +0000 | [diff] [blame] | 625 | struct ospf6_lsa *old, *self, *new; |
| 626 | struct ospf6_lsdb *lsdb_self; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 627 | |
| 628 | assert (thread); |
hasso | 6452df0 | 2004-08-15 05:52:07 +0000 | [diff] [blame] | 629 | old = (struct ospf6_lsa *) THREAD_ARG (thread); |
| 630 | assert (old && old->header); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 631 | |
hasso | 6452df0 | 2004-08-15 05:52:07 +0000 | [diff] [blame] | 632 | old->refresh = (struct thread *) NULL; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 633 | |
hasso | 6452df0 | 2004-08-15 05:52:07 +0000 | [diff] [blame] | 634 | lsdb_self = ospf6_get_scoped_lsdb_self (old); |
| 635 | self = ospf6_lsdb_lookup (old->header->type, old->header->id, |
| 636 | old->header->adv_router, lsdb_self); |
| 637 | if (self == NULL) |
| 638 | { |
hasso | 1e05838 | 2004-09-01 21:36:14 +0000 | [diff] [blame] | 639 | if (IS_OSPF6_DEBUG_LSA_TYPE (old->header->type)) |
hasso | c6487d6 | 2004-12-24 06:00:11 +0000 | [diff] [blame] | 640 | zlog_debug ("Refresh: could not find self LSA, flush %s", old->name); |
hasso | 6452df0 | 2004-08-15 05:52:07 +0000 | [diff] [blame] | 641 | ospf6_lsa_premature_aging (old); |
| 642 | return 0; |
| 643 | } |
| 644 | |
| 645 | /* Reset age, increment LS sequence number. */ |
| 646 | self->header->age = htons (0); |
| 647 | self->header->seqnum = |
| 648 | ospf6_new_ls_seqnum (self->header->type, self->header->id, |
| 649 | self->header->adv_router, old->lsdb); |
| 650 | ospf6_lsa_checksum (self->header); |
| 651 | |
| 652 | new = ospf6_lsa_create (self->header); |
| 653 | new->lsdb = old->lsdb; |
| 654 | new->refresh = thread_add_timer (master, ospf6_lsa_refresh, new, |
| 655 | LS_REFRESH_TIME); |
| 656 | |
| 657 | /* store it in the LSDB for self-originated LSAs */ |
| 658 | ospf6_lsdb_add (ospf6_lsa_copy (new), lsdb_self); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 659 | |
hasso | 1e05838 | 2004-09-01 21:36:14 +0000 | [diff] [blame] | 660 | if (IS_OSPF6_DEBUG_LSA_TYPE (new->header->type)) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 661 | { |
hasso | c6487d6 | 2004-12-24 06:00:11 +0000 | [diff] [blame] | 662 | zlog_debug ("LSA Refresh:"); |
hasso | 6452df0 | 2004-08-15 05:52:07 +0000 | [diff] [blame] | 663 | ospf6_lsa_header_print (new); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 664 | } |
| 665 | |
hasso | 6452df0 | 2004-08-15 05:52:07 +0000 | [diff] [blame] | 666 | ospf6_flood_clear (old); |
| 667 | ospf6_flood (NULL, new); |
| 668 | ospf6_install_lsa (new); |
| 669 | |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 670 | return 0; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 671 | } |
| 672 | |
| 673 | |
| 674 | |
| 675 | /* enhanced Fletcher checksum algorithm, RFC1008 7.2 */ |
| 676 | #define MODX 4102 |
| 677 | #define LSA_CHECKSUM_OFFSET 15 |
| 678 | |
| 679 | unsigned short |
| 680 | ospf6_lsa_checksum (struct ospf6_lsa_header *lsa_header) |
| 681 | { |
| 682 | u_char *sp, *ep, *p, *q; |
| 683 | int c0 = 0, c1 = 0; |
| 684 | int x, y; |
| 685 | u_int16_t length; |
| 686 | |
| 687 | lsa_header->checksum = 0; |
| 688 | length = ntohs (lsa_header->length) - 2; |
hasso | 03d52f8 | 2004-09-29 00:26:19 +0000 | [diff] [blame] | 689 | sp = (u_char *) &lsa_header->type; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 690 | |
| 691 | for (ep = sp + length; sp < ep; sp = q) |
| 692 | { |
| 693 | q = sp + MODX; |
| 694 | if (q > ep) |
| 695 | q = ep; |
| 696 | for (p = sp; p < q; p++) |
| 697 | { |
| 698 | c0 += *p; |
| 699 | c1 += c0; |
| 700 | } |
| 701 | c0 %= 255; |
| 702 | c1 %= 255; |
| 703 | } |
| 704 | |
| 705 | /* r = (c1 << 8) + c0; */ |
| 706 | x = ((length - LSA_CHECKSUM_OFFSET) * c0 - c1) % 255; |
| 707 | if (x <= 0) |
| 708 | x += 255; |
| 709 | y = 510 - c0 - x; |
| 710 | if (y > 255) |
| 711 | y -= 255; |
| 712 | |
| 713 | lsa_header->checksum = htons ((x << 8) + y); |
| 714 | |
| 715 | return (lsa_header->checksum); |
| 716 | } |
| 717 | |
hasso | 6452df0 | 2004-08-15 05:52:07 +0000 | [diff] [blame] | 718 | void |
Paul Jakma | 6ac29a5 | 2008-08-15 13:45:30 +0100 | [diff] [blame] | 719 | ospf6_lsa_init (void) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 720 | { |
hasso | 1e05838 | 2004-09-01 21:36:14 +0000 | [diff] [blame] | 721 | ospf6_lsa_handler_vector = vector_init (0); |
hasso | 6452df0 | 2004-08-15 05:52:07 +0000 | [diff] [blame] | 722 | ospf6_install_lsa_handler (&unknown_handler); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 723 | } |
| 724 | |
Tom Goff | ae2254a | 2010-11-10 13:01:41 -0800 | [diff] [blame] | 725 | void |
| 726 | ospf6_lsa_terminate (void) |
| 727 | { |
| 728 | vector_free (ospf6_lsa_handler_vector); |
| 729 | } |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 730 | |
Paul Jakma | 6ac29a5 | 2008-08-15 13:45:30 +0100 | [diff] [blame] | 731 | static char * |
hasso | 1e05838 | 2004-09-01 21:36:14 +0000 | [diff] [blame] | 732 | ospf6_lsa_handler_name (struct ospf6_lsa_handler *h) |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 733 | { |
hasso | 1e05838 | 2004-09-01 21:36:14 +0000 | [diff] [blame] | 734 | static char buf[64]; |
paul | 0c083ee | 2004-10-10 12:54:58 +0000 | [diff] [blame] | 735 | unsigned int i; |
| 736 | unsigned int size = strlen (h->name); |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 737 | |
Andrew J. Schorr | c32d28b | 2007-02-27 15:24:36 +0000 | [diff] [blame] | 738 | if (!strcmp(h->name, "Unknown") && |
hasso | 1e05838 | 2004-09-01 21:36:14 +0000 | [diff] [blame] | 739 | h->type != OSPF6_LSTYPE_UNKNOWN) |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 740 | { |
hasso | 1e05838 | 2004-09-01 21:36:14 +0000 | [diff] [blame] | 741 | snprintf (buf, sizeof (buf), "%#04hx", h->type); |
| 742 | return buf; |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 743 | } |
| 744 | |
hasso | 1e05838 | 2004-09-01 21:36:14 +0000 | [diff] [blame] | 745 | for (i = 0; i < MIN (size, sizeof (buf)); i++) |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 746 | { |
hasso | 1e05838 | 2004-09-01 21:36:14 +0000 | [diff] [blame] | 747 | if (! islower (h->name[i])) |
| 748 | buf[i] = tolower (h->name[i]); |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 749 | else |
hasso | 1e05838 | 2004-09-01 21:36:14 +0000 | [diff] [blame] | 750 | buf[i] = h->name[i]; |
| 751 | } |
| 752 | buf[size] = '\0'; |
| 753 | return buf; |
| 754 | } |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 755 | |
hasso | 1e05838 | 2004-09-01 21:36:14 +0000 | [diff] [blame] | 756 | DEFUN (debug_ospf6_lsa_type, |
| 757 | debug_ospf6_lsa_hex_cmd, |
| 758 | "debug ospf6 lsa XXXX/0xXXXX", |
| 759 | DEBUG_STR |
| 760 | OSPF6_STR |
| 761 | "Debug Link State Advertisements (LSAs)\n" |
| 762 | "Specify LS type as Hexadecimal\n" |
| 763 | ) |
| 764 | { |
paul | 0c083ee | 2004-10-10 12:54:58 +0000 | [diff] [blame] | 765 | unsigned int i; |
hasso | 1e05838 | 2004-09-01 21:36:14 +0000 | [diff] [blame] | 766 | struct ospf6_lsa_handler *handler = NULL; |
| 767 | unsigned long val; |
| 768 | char *endptr = NULL; |
| 769 | u_int16_t type = 0; |
| 770 | |
| 771 | assert (argc); |
| 772 | |
| 773 | if ((strlen (argv[0]) == 6 && ! strncmp (argv[0], "0x", 2)) || |
| 774 | (strlen (argv[0]) == 4)) |
| 775 | { |
| 776 | val = strtoul (argv[0], &endptr, 16); |
| 777 | if (*endptr == '\0') |
| 778 | type = val; |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 779 | } |
| 780 | |
paul | 55468c8 | 2005-03-14 20:19:01 +0000 | [diff] [blame] | 781 | for (i = 0; i < vector_active (ospf6_lsa_handler_vector); i++) |
hasso | 1e05838 | 2004-09-01 21:36:14 +0000 | [diff] [blame] | 782 | { |
| 783 | handler = vector_slot (ospf6_lsa_handler_vector, i); |
| 784 | if (handler == NULL) |
| 785 | continue; |
| 786 | if (type && handler->type == type) |
| 787 | break; |
| 788 | if (! strcasecmp (argv[0], handler->name)) |
| 789 | break; |
| 790 | handler = NULL; |
| 791 | } |
| 792 | |
| 793 | if (type && handler == NULL) |
| 794 | { |
| 795 | handler = (struct ospf6_lsa_handler *) |
| 796 | malloc (sizeof (struct ospf6_lsa_handler)); |
| 797 | memset (handler, 0, sizeof (struct ospf6_lsa_handler)); |
| 798 | handler->type = type; |
| 799 | handler->name = "Unknown"; |
| 800 | handler->show = ospf6_unknown_lsa_show; |
| 801 | vector_set_index (ospf6_lsa_handler_vector, |
| 802 | handler->type & OSPF6_LSTYPE_FCODE_MASK, handler); |
| 803 | } |
| 804 | |
| 805 | if (handler == NULL) |
| 806 | handler = &unknown_handler; |
| 807 | |
| 808 | if (argc >= 2) |
| 809 | { |
| 810 | if (! strcmp (argv[1], "originate")) |
| 811 | SET_FLAG (handler->debug, OSPF6_LSA_DEBUG_ORIGINATE); |
| 812 | if (! strcmp (argv[1], "examin")) |
| 813 | SET_FLAG (handler->debug, OSPF6_LSA_DEBUG_EXAMIN); |
| 814 | if (! strcmp (argv[1], "flooding")) |
| 815 | SET_FLAG (handler->debug, OSPF6_LSA_DEBUG_FLOOD); |
| 816 | } |
| 817 | else |
| 818 | SET_FLAG (handler->debug, OSPF6_LSA_DEBUG); |
| 819 | |
| 820 | return CMD_SUCCESS; |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 821 | } |
| 822 | |
hasso | 1e05838 | 2004-09-01 21:36:14 +0000 | [diff] [blame] | 823 | DEFUN (no_debug_ospf6_lsa_type, |
| 824 | no_debug_ospf6_lsa_hex_cmd, |
| 825 | "no debug ospf6 lsa XXXX/0xXXXX", |
| 826 | NO_STR |
| 827 | DEBUG_STR |
| 828 | OSPF6_STR |
| 829 | "Debug Link State Advertisements (LSAs)\n" |
| 830 | "Specify LS type as Hexadecimal\n" |
| 831 | ) |
| 832 | { |
paul | 0c083ee | 2004-10-10 12:54:58 +0000 | [diff] [blame] | 833 | u_int i; |
hasso | 1e05838 | 2004-09-01 21:36:14 +0000 | [diff] [blame] | 834 | struct ospf6_lsa_handler *handler = NULL; |
| 835 | unsigned long val; |
| 836 | char *endptr = NULL; |
| 837 | u_int16_t type = 0; |
| 838 | |
| 839 | assert (argc); |
| 840 | |
| 841 | if ((strlen (argv[0]) == 6 && ! strncmp (argv[0], "0x", 2)) || |
| 842 | (strlen (argv[0]) == 4)) |
| 843 | { |
| 844 | val = strtoul (argv[0], &endptr, 16); |
| 845 | if (*endptr == '\0') |
| 846 | type = val; |
| 847 | } |
| 848 | |
paul | 55468c8 | 2005-03-14 20:19:01 +0000 | [diff] [blame] | 849 | for (i = 0; i < vector_active (ospf6_lsa_handler_vector); i++) |
hasso | 1e05838 | 2004-09-01 21:36:14 +0000 | [diff] [blame] | 850 | { |
| 851 | handler = vector_slot (ospf6_lsa_handler_vector, i); |
| 852 | if (handler == NULL) |
| 853 | continue; |
| 854 | if (type && handler->type == type) |
| 855 | break; |
| 856 | if (! strcasecmp (argv[0], handler->name)) |
| 857 | break; |
| 858 | } |
| 859 | |
| 860 | if (handler == NULL) |
| 861 | return CMD_SUCCESS; |
| 862 | |
| 863 | if (argc >= 2) |
| 864 | { |
| 865 | if (! strcmp (argv[1], "originate")) |
| 866 | UNSET_FLAG (handler->debug, OSPF6_LSA_DEBUG_ORIGINATE); |
| 867 | if (! strcmp (argv[1], "examin")) |
| 868 | UNSET_FLAG (handler->debug, OSPF6_LSA_DEBUG_EXAMIN); |
| 869 | if (! strcmp (argv[1], "flooding")) |
| 870 | UNSET_FLAG (handler->debug, OSPF6_LSA_DEBUG_FLOOD); |
| 871 | } |
| 872 | else |
| 873 | UNSET_FLAG (handler->debug, OSPF6_LSA_DEBUG); |
| 874 | |
| 875 | if (handler->debug == 0 && |
Andrew J. Schorr | e733f94 | 2007-06-07 13:11:58 +0000 | [diff] [blame] | 876 | !strcmp(handler->name, "Unknown") && type != OSPF6_LSTYPE_UNKNOWN) |
hasso | 1e05838 | 2004-09-01 21:36:14 +0000 | [diff] [blame] | 877 | { |
| 878 | free (handler); |
| 879 | vector_slot (ospf6_lsa_handler_vector, i) = NULL; |
| 880 | } |
| 881 | |
| 882 | return CMD_SUCCESS; |
| 883 | } |
| 884 | |
| 885 | struct cmd_element debug_ospf6_lsa_type_cmd; |
| 886 | struct cmd_element debug_ospf6_lsa_type_detail_cmd; |
| 887 | struct cmd_element no_debug_ospf6_lsa_type_cmd; |
| 888 | struct cmd_element no_debug_ospf6_lsa_type_detail_cmd; |
| 889 | |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 890 | void |
Paul Jakma | 6ac29a5 | 2008-08-15 13:45:30 +0100 | [diff] [blame] | 891 | install_element_ospf6_debug_lsa (void) |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 892 | { |
paul | 0c083ee | 2004-10-10 12:54:58 +0000 | [diff] [blame] | 893 | u_int i; |
hasso | 1e05838 | 2004-09-01 21:36:14 +0000 | [diff] [blame] | 894 | struct ospf6_lsa_handler *handler; |
| 895 | #define STRSIZE 256 |
| 896 | #define DOCSIZE 1024 |
| 897 | static char strbuf[STRSIZE]; |
| 898 | static char docbuf[DOCSIZE]; |
| 899 | static char detail_strbuf[STRSIZE]; |
| 900 | static char detail_docbuf[DOCSIZE]; |
| 901 | char *str, *no_str; |
| 902 | char *doc, *no_doc; |
| 903 | |
| 904 | strbuf[0] = '\0'; |
| 905 | no_str = &strbuf[strlen (strbuf)]; |
| 906 | strncat (strbuf, "no ", STRSIZE - strlen (strbuf)); |
| 907 | str = &strbuf[strlen (strbuf)]; |
| 908 | |
| 909 | strncat (strbuf, "debug ospf6 lsa (", STRSIZE - strlen (strbuf)); |
paul | 55468c8 | 2005-03-14 20:19:01 +0000 | [diff] [blame] | 910 | for (i = 0; i < vector_active (ospf6_lsa_handler_vector); i++) |
hasso | 1e05838 | 2004-09-01 21:36:14 +0000 | [diff] [blame] | 911 | { |
| 912 | handler = vector_slot (ospf6_lsa_handler_vector, i); |
| 913 | if (handler == NULL) |
| 914 | continue; |
| 915 | strncat (strbuf, ospf6_lsa_handler_name (handler), |
| 916 | STRSIZE - strlen (strbuf)); |
| 917 | strncat (strbuf, "|", STRSIZE - strlen (strbuf)); |
| 918 | } |
| 919 | strbuf[strlen (strbuf) - 1] = ')'; |
| 920 | strbuf[strlen (strbuf)] = '\0'; |
| 921 | |
| 922 | docbuf[0] = '\0'; |
| 923 | no_doc = &docbuf[strlen (docbuf)]; |
| 924 | strncat (docbuf, NO_STR, DOCSIZE - strlen (docbuf)); |
| 925 | doc = &docbuf[strlen (docbuf)]; |
| 926 | |
| 927 | strncat (docbuf, DEBUG_STR, DOCSIZE - strlen (docbuf)); |
| 928 | strncat (docbuf, OSPF6_STR, DOCSIZE - strlen (docbuf)); |
| 929 | strncat (docbuf, "Debug Link State Advertisements (LSAs)\n", |
| 930 | DOCSIZE - strlen (docbuf)); |
| 931 | |
paul | 55468c8 | 2005-03-14 20:19:01 +0000 | [diff] [blame] | 932 | for (i = 0; i < vector_active (ospf6_lsa_handler_vector); i++) |
hasso | 1e05838 | 2004-09-01 21:36:14 +0000 | [diff] [blame] | 933 | { |
| 934 | handler = vector_slot (ospf6_lsa_handler_vector, i); |
| 935 | if (handler == NULL) |
| 936 | continue; |
| 937 | strncat (docbuf, "Debug ", DOCSIZE - strlen (docbuf)); |
| 938 | strncat (docbuf, handler->name, DOCSIZE - strlen (docbuf)); |
| 939 | strncat (docbuf, "-LSA\n", DOCSIZE - strlen (docbuf)); |
| 940 | } |
| 941 | docbuf[strlen (docbuf)] = '\0'; |
| 942 | |
| 943 | debug_ospf6_lsa_type_cmd.string = str; |
| 944 | debug_ospf6_lsa_type_cmd.func = debug_ospf6_lsa_type; |
| 945 | debug_ospf6_lsa_type_cmd.doc = doc; |
| 946 | |
| 947 | no_debug_ospf6_lsa_type_cmd.string = no_str; |
| 948 | no_debug_ospf6_lsa_type_cmd.func = no_debug_ospf6_lsa_type; |
| 949 | no_debug_ospf6_lsa_type_cmd.doc = no_doc; |
| 950 | |
| 951 | strncpy (detail_strbuf, strbuf, STRSIZE); |
| 952 | strncat (detail_strbuf, " (originate|examin|flooding)", |
| 953 | STRSIZE - strlen (detail_strbuf)); |
| 954 | detail_strbuf[strlen (detail_strbuf)] = '\0'; |
| 955 | no_str = &detail_strbuf[0]; |
| 956 | str = &detail_strbuf[strlen ("no ")]; |
| 957 | |
| 958 | strncpy (detail_docbuf, docbuf, DOCSIZE); |
| 959 | strncat (detail_docbuf, "Debug Originating LSA\n", |
| 960 | DOCSIZE - strlen (detail_docbuf)); |
| 961 | strncat (detail_docbuf, "Debug Examining LSA\n", |
| 962 | DOCSIZE - strlen (detail_docbuf)); |
| 963 | strncat (detail_docbuf, "Debug Flooding LSA\n", |
| 964 | DOCSIZE - strlen (detail_docbuf)); |
| 965 | detail_docbuf[strlen (detail_docbuf)] = '\0'; |
| 966 | no_doc = &detail_docbuf[0]; |
| 967 | doc = &detail_docbuf[strlen (NO_STR)]; |
| 968 | |
| 969 | debug_ospf6_lsa_type_detail_cmd.string = str; |
| 970 | debug_ospf6_lsa_type_detail_cmd.func = debug_ospf6_lsa_type; |
| 971 | debug_ospf6_lsa_type_detail_cmd.doc = doc; |
| 972 | |
| 973 | no_debug_ospf6_lsa_type_detail_cmd.string = no_str; |
| 974 | no_debug_ospf6_lsa_type_detail_cmd.func = no_debug_ospf6_lsa_type; |
| 975 | no_debug_ospf6_lsa_type_detail_cmd.doc = no_doc; |
| 976 | |
| 977 | install_element (ENABLE_NODE, &debug_ospf6_lsa_hex_cmd); |
| 978 | install_element (ENABLE_NODE, &debug_ospf6_lsa_type_cmd); |
| 979 | install_element (ENABLE_NODE, &debug_ospf6_lsa_type_detail_cmd); |
| 980 | install_element (ENABLE_NODE, &no_debug_ospf6_lsa_hex_cmd); |
| 981 | install_element (ENABLE_NODE, &no_debug_ospf6_lsa_type_cmd); |
| 982 | install_element (ENABLE_NODE, &no_debug_ospf6_lsa_type_detail_cmd); |
| 983 | install_element (CONFIG_NODE, &debug_ospf6_lsa_hex_cmd); |
| 984 | install_element (CONFIG_NODE, &debug_ospf6_lsa_type_cmd); |
| 985 | install_element (CONFIG_NODE, &debug_ospf6_lsa_type_detail_cmd); |
| 986 | install_element (CONFIG_NODE, &no_debug_ospf6_lsa_hex_cmd); |
| 987 | install_element (CONFIG_NODE, &no_debug_ospf6_lsa_type_cmd); |
| 988 | install_element (CONFIG_NODE, &no_debug_ospf6_lsa_type_detail_cmd); |
| 989 | } |
| 990 | |
| 991 | int |
| 992 | config_write_ospf6_debug_lsa (struct vty *vty) |
| 993 | { |
paul | 0c083ee | 2004-10-10 12:54:58 +0000 | [diff] [blame] | 994 | u_int i; |
hasso | 1e05838 | 2004-09-01 21:36:14 +0000 | [diff] [blame] | 995 | struct ospf6_lsa_handler *handler; |
| 996 | |
paul | 55468c8 | 2005-03-14 20:19:01 +0000 | [diff] [blame] | 997 | for (i = 0; i < vector_active (ospf6_lsa_handler_vector); i++) |
hasso | 1e05838 | 2004-09-01 21:36:14 +0000 | [diff] [blame] | 998 | { |
| 999 | handler = vector_slot (ospf6_lsa_handler_vector, i); |
| 1000 | if (handler == NULL) |
| 1001 | continue; |
| 1002 | if (CHECK_FLAG (handler->debug, OSPF6_LSA_DEBUG)) |
| 1003 | vty_out (vty, "debug ospf6 lsa %s%s", |
| 1004 | ospf6_lsa_handler_name (handler), VNL); |
| 1005 | if (CHECK_FLAG (handler->debug, OSPF6_LSA_DEBUG_ORIGINATE)) |
| 1006 | vty_out (vty, "debug ospf6 lsa %s originate%s", |
| 1007 | ospf6_lsa_handler_name (handler), VNL); |
| 1008 | if (CHECK_FLAG (handler->debug, OSPF6_LSA_DEBUG_EXAMIN)) |
| 1009 | vty_out (vty, "debug ospf6 lsa %s examin%s", |
| 1010 | ospf6_lsa_handler_name (handler), VNL); |
| 1011 | if (CHECK_FLAG (handler->debug, OSPF6_LSA_DEBUG_FLOOD)) |
| 1012 | vty_out (vty, "debug ospf6 lsa %s flooding%s", |
| 1013 | ospf6_lsa_handler_name (handler), VNL); |
| 1014 | } |
| 1015 | |
| 1016 | return 0; |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 1017 | } |
| 1018 | |
| 1019 | |