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