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" |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 27 | #include "command.h" |
| 28 | #include "memory.h" |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 29 | #include "thread.h" |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 30 | |
| 31 | #include "ospf6_proto.h" |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 32 | #include "ospf6_lsa.h" |
| 33 | #include "ospf6_lsdb.h" |
| 34 | #include "ospf6_message.h" |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 35 | |
| 36 | #include "ospf6_top.h" |
| 37 | #include "ospf6_area.h" |
| 38 | #include "ospf6_interface.h" |
| 39 | #include "ospf6_neighbor.h" |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 40 | |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 41 | #include "ospf6_flood.h" |
hasso | 049207c | 2004-08-04 20:02:13 +0000 | [diff] [blame] | 42 | #include "ospf6d.h" |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 43 | |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 44 | unsigned char conf_debug_ospf6_lsa = 0; |
| 45 | |
hasso | 6452df0 | 2004-08-15 05:52:07 +0000 | [diff] [blame] | 46 | struct ospf6_lsa_handler *ospf6_lsa_handler[OSPF6_LSTYPE_SIZE]; |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 47 | |
| 48 | char *ospf6_lstype_str[OSPF6_LSTYPE_SIZE] = |
| 49 | {"Unknown", "Router", "Network", "Inter-Prefix", "Inter-Router", |
| 50 | "AS-External", "Group-Membership", "Type-7", "Link", "Intra-Prefix"}; |
| 51 | |
| 52 | char * |
| 53 | ospf6_lstype_name (u_int16_t type) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 54 | { |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 55 | static char buf[8]; |
hasso | 6452df0 | 2004-08-15 05:52:07 +0000 | [diff] [blame] | 56 | int index = OSPF6_LSTYPE_INDEX (type); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 57 | |
hasso | 6452df0 | 2004-08-15 05:52:07 +0000 | [diff] [blame] | 58 | if (ospf6_lsa_handler[index]) |
| 59 | return ospf6_lsa_handler[index]->name; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 60 | |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 61 | snprintf (buf, sizeof (buf), "0x%04hx", ntohs (type)); |
| 62 | return buf; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 63 | } |
| 64 | |
| 65 | /* RFC2328: Section 13.2 */ |
| 66 | int |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 67 | ospf6_lsa_is_differ (struct ospf6_lsa *lsa1, |
| 68 | struct ospf6_lsa *lsa2) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 69 | { |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 70 | int len; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 71 | |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 72 | assert (OSPF6_LSA_IS_SAME (lsa1, lsa2)); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 73 | |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 74 | /* XXX, Options ??? */ |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 75 | |
| 76 | ospf6_lsa_age_current (lsa1); |
| 77 | ospf6_lsa_age_current (lsa2); |
| 78 | if (ntohs (lsa1->header->age) == MAXAGE && |
| 79 | ntohs (lsa2->header->age) != MAXAGE) |
| 80 | return 1; |
| 81 | if (ntohs (lsa1->header->age) != MAXAGE && |
| 82 | ntohs (lsa2->header->age) == MAXAGE) |
| 83 | return 1; |
| 84 | |
| 85 | /* compare body */ |
| 86 | if (ntohs (lsa1->header->length) != ntohs (lsa2->header->length)) |
| 87 | return 1; |
| 88 | |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 89 | len = ntohs (lsa1->header->length) - sizeof (struct ospf6_lsa_header); |
| 90 | return memcmp (lsa1->header + 1, lsa2->header + 1, len); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 91 | } |
| 92 | |
| 93 | int |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 94 | ospf6_lsa_is_changed (struct ospf6_lsa *lsa1, |
| 95 | struct ospf6_lsa *lsa2) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 96 | { |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 97 | int length; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 98 | |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 99 | if (OSPF6_LSA_IS_MAXAGE (lsa1) ^ OSPF6_LSA_IS_MAXAGE (lsa2)) |
| 100 | return 1; |
| 101 | if (ntohs (lsa1->header->length) != ntohs (lsa2->header->length)) |
| 102 | return 1; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 103 | |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 104 | length = OSPF6_LSA_SIZE (lsa1->header) - sizeof (struct ospf6_lsa_header); |
| 105 | assert (length > 0); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 106 | |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 107 | return memcmp (OSPF6_LSA_HEADER_END (lsa1->header), |
| 108 | OSPF6_LSA_HEADER_END (lsa2->header), length); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 109 | } |
| 110 | |
| 111 | /* ospf6 age functions */ |
hasso | 3b68735 | 2004-08-19 06:56:53 +0000 | [diff] [blame^] | 112 | /* calculate birth */ |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 113 | static void |
| 114 | ospf6_lsa_age_set (struct ospf6_lsa *lsa) |
| 115 | { |
| 116 | struct timeval now; |
| 117 | |
| 118 | assert (lsa && lsa->header); |
| 119 | |
| 120 | if (gettimeofday (&now, (struct timezone *)NULL) < 0) |
| 121 | zlog_warn ("LSA: gettimeofday failed, may fail LSA AGEs: %s", |
| 122 | strerror (errno)); |
| 123 | |
| 124 | lsa->birth.tv_sec = now.tv_sec - ntohs (lsa->header->age); |
| 125 | lsa->birth.tv_usec = now.tv_usec; |
hasso | 3b68735 | 2004-08-19 06:56:53 +0000 | [diff] [blame^] | 126 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 127 | return; |
| 128 | } |
| 129 | |
| 130 | /* this function calculates current age from its birth, |
| 131 | then update age field of LSA header. return value is current age */ |
| 132 | u_int16_t |
| 133 | ospf6_lsa_age_current (struct ospf6_lsa *lsa) |
| 134 | { |
| 135 | struct timeval now; |
| 136 | u_int32_t ulage; |
| 137 | u_int16_t age; |
| 138 | |
| 139 | assert (lsa); |
| 140 | assert (lsa->header); |
| 141 | |
| 142 | /* current time */ |
| 143 | if (gettimeofday (&now, (struct timezone *)NULL) < 0) |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 144 | zlog_warn ("LSA: gettimeofday failed, may fail LSA AGEs: %s", |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 145 | strerror (errno)); |
| 146 | |
| 147 | /* calculate age */ |
| 148 | ulage = now.tv_sec - lsa->birth.tv_sec; |
| 149 | |
| 150 | /* if over MAXAGE, set to it */ |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 151 | age = (ulage > MAXAGE ? MAXAGE : ulage); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 152 | |
| 153 | lsa->header->age = htons (age); |
| 154 | return age; |
| 155 | } |
| 156 | |
| 157 | /* update age field of LSA header with adding InfTransDelay */ |
| 158 | void |
| 159 | ospf6_lsa_age_update_to_send (struct ospf6_lsa *lsa, u_int32_t transdelay) |
| 160 | { |
| 161 | unsigned short age; |
| 162 | |
| 163 | age = ospf6_lsa_age_current (lsa) + transdelay; |
| 164 | if (age > MAXAGE) |
| 165 | age = MAXAGE; |
| 166 | lsa->header->age = htons (age); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 167 | } |
| 168 | |
| 169 | void |
| 170 | ospf6_lsa_premature_aging (struct ospf6_lsa *lsa) |
| 171 | { |
| 172 | /* log */ |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 173 | if (IS_OSPF6_DEBUG_LSA (ORIGINATE)) |
| 174 | zlog_info ("LSA: Premature aging: %s", lsa->name); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 175 | |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 176 | THREAD_OFF (lsa->expire); |
| 177 | THREAD_OFF (lsa->refresh); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 178 | |
| 179 | memset (&lsa->birth, 0, sizeof (struct timeval)); |
| 180 | thread_execute (master, ospf6_lsa_expire, lsa, 0); |
| 181 | } |
| 182 | |
| 183 | /* check which is more recent. if a is more recent, return -1; |
| 184 | if the same, return 0; otherwise(b is more recent), return 1 */ |
| 185 | int |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 186 | ospf6_lsa_compare (struct ospf6_lsa *a, struct ospf6_lsa *b) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 187 | { |
| 188 | signed long seqnuma, seqnumb; |
| 189 | u_int16_t cksuma, cksumb; |
| 190 | u_int16_t agea, ageb; |
| 191 | |
| 192 | assert (a && a->header); |
| 193 | assert (b && b->header); |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 194 | assert (OSPF6_LSA_IS_SAME (a, b)); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 195 | |
| 196 | seqnuma = ((signed long) ntohl (a->header->seqnum)) |
| 197 | - (signed long) INITIAL_SEQUENCE_NUMBER; |
| 198 | seqnumb = ((signed long) ntohl (b->header->seqnum)) |
| 199 | - (signed long) INITIAL_SEQUENCE_NUMBER; |
| 200 | |
| 201 | /* compare by sequence number */ |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 202 | /* XXX, LS sequence number wrapping */ |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 203 | if (seqnuma > seqnumb) |
| 204 | return -1; |
| 205 | else if (seqnuma < seqnumb) |
| 206 | return 1; |
| 207 | |
| 208 | /* Checksum */ |
| 209 | cksuma = ntohs (a->header->checksum); |
| 210 | cksumb = ntohs (b->header->checksum); |
| 211 | if (cksuma > cksumb) |
| 212 | return -1; |
| 213 | if (cksuma < cksumb) |
| 214 | return 0; |
| 215 | |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 216 | /* Update Age */ |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 217 | agea = ospf6_lsa_age_current (a); |
| 218 | ageb = ospf6_lsa_age_current (b); |
| 219 | |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 220 | /* MaxAge check */ |
| 221 | if (agea == MAXAGE && ageb != MAXAGE) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 222 | return -1; |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 223 | else if (agea != MAXAGE && ageb == MAXAGE) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 224 | return 1; |
| 225 | |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 226 | /* Age check */ |
| 227 | if (agea > ageb && agea - ageb >= MAX_AGE_DIFF) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 228 | return 1; |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 229 | else if (agea < ageb && ageb - agea >= MAX_AGE_DIFF) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 230 | return -1; |
| 231 | |
| 232 | /* neither recent */ |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 233 | return 0; |
| 234 | } |
| 235 | |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 236 | char * |
| 237 | ospf6_lsa_printbuf (struct ospf6_lsa *lsa, char *buf, int size) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 238 | { |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 239 | char id[16], adv_router[16]; |
| 240 | inet_ntop (AF_INET, &lsa->header->id, id, sizeof (id)); |
| 241 | inet_ntop (AF_INET, &lsa->header->adv_router, adv_router, |
| 242 | sizeof (adv_router)); |
| 243 | snprintf (buf, size, "[%s Id:%s Adv:%s]", |
| 244 | OSPF6_LSTYPE_NAME (lsa->header->type), id, adv_router); |
| 245 | return buf; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 246 | } |
| 247 | |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 248 | void |
| 249 | ospf6_lsa_header_print_raw (struct ospf6_lsa_header *header) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 250 | { |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 251 | char id[16], adv_router[16]; |
| 252 | inet_ntop (AF_INET, &header->id, id, sizeof (id)); |
| 253 | inet_ntop (AF_INET, &header->adv_router, adv_router, |
| 254 | sizeof (adv_router)); |
| 255 | zlog_info (" [%s Id:%s Adv:%s]", |
| 256 | OSPF6_LSTYPE_NAME (header->type), id, adv_router); |
| 257 | zlog_info (" Age: %4hu SeqNum: %#08lx Cksum: %04hx Len: %d", |
| 258 | ntohs (header->age), (u_long) ntohl (header->seqnum), |
| 259 | ntohs (header->checksum), ntohs (header->length)); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 260 | } |
| 261 | |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 262 | void |
| 263 | ospf6_lsa_header_print (struct ospf6_lsa *lsa) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 264 | { |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 265 | ospf6_lsa_age_current (lsa); |
| 266 | ospf6_lsa_header_print_raw (lsa->header); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 267 | } |
| 268 | |
| 269 | void |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 270 | ospf6_lsa_show_summary_header (struct vty *vty) |
| 271 | { |
| 272 | vty_out (vty, "%-12s %-15s %-15s %4s %8s %4s %4s %-8s%s", |
| 273 | "Type", "LSId", "AdvRouter", "Age", "SeqNum", |
hasso | 049207c | 2004-08-04 20:02:13 +0000 | [diff] [blame] | 274 | "Cksm", "Len", "Duration", VNL); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 275 | } |
| 276 | |
| 277 | void |
| 278 | ospf6_lsa_show_summary (struct vty *vty, struct ospf6_lsa *lsa) |
| 279 | { |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 280 | char adv_router[16], id[16]; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 281 | struct timeval now, res; |
| 282 | char duration[16]; |
| 283 | |
| 284 | assert (lsa); |
| 285 | assert (lsa->header); |
| 286 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 287 | inet_ntop (AF_INET, &lsa->header->id, id, sizeof (id)); |
| 288 | inet_ntop (AF_INET, &lsa->header->adv_router, adv_router, |
| 289 | sizeof (adv_router)); |
| 290 | |
| 291 | gettimeofday (&now, NULL); |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 292 | timersub (&now, &lsa->installed, &res); |
| 293 | timerstring (&res, duration, sizeof (duration)); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 294 | |
| 295 | vty_out (vty, "%-12s %-15s %-15s %4hu %8lx %04hx %4hu %8s%s", |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 296 | OSPF6_LSTYPE_NAME (lsa->header->type), |
| 297 | id, adv_router, ospf6_lsa_age_current (lsa), |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 298 | (u_long) ntohl (lsa->header->seqnum), |
| 299 | ntohs (lsa->header->checksum), ntohs (lsa->header->length), |
hasso | 049207c | 2004-08-04 20:02:13 +0000 | [diff] [blame] | 300 | duration, VNL); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 301 | } |
| 302 | |
| 303 | void |
| 304 | ospf6_lsa_show_dump (struct vty *vty, struct ospf6_lsa *lsa) |
| 305 | { |
| 306 | u_char *start, *end, *current; |
| 307 | char byte[4]; |
| 308 | |
| 309 | start = (char *) lsa->header; |
| 310 | end = (char *) lsa->header + ntohs (lsa->header->length); |
| 311 | |
hasso | 049207c | 2004-08-04 20:02:13 +0000 | [diff] [blame] | 312 | vty_out (vty, "%s", VNL); |
| 313 | vty_out (vty, "%s:%s", lsa->name, VNL); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 314 | |
| 315 | for (current = start; current < end; current ++) |
| 316 | { |
| 317 | if ((current - start) % 16 == 0) |
hasso | 049207c | 2004-08-04 20:02:13 +0000 | [diff] [blame] | 318 | vty_out (vty, "%s ", VNL); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 319 | else if ((current - start) % 4 == 0) |
| 320 | vty_out (vty, " "); |
| 321 | |
| 322 | snprintf (byte, sizeof (byte), "%02x", *current); |
| 323 | vty_out (vty, "%s", byte); |
| 324 | } |
| 325 | |
hasso | 049207c | 2004-08-04 20:02:13 +0000 | [diff] [blame] | 326 | vty_out (vty, "%s%s", VNL, VNL); |
hasso | 6452df0 | 2004-08-15 05:52:07 +0000 | [diff] [blame] | 327 | return; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 328 | } |
| 329 | |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 330 | void |
| 331 | ospf6_lsa_show_internal (struct vty *vty, struct ospf6_lsa *lsa) |
| 332 | { |
| 333 | char adv_router[64], id[64]; |
| 334 | |
| 335 | assert (lsa && lsa->header); |
| 336 | |
| 337 | inet_ntop (AF_INET, &lsa->header->id, id, sizeof (id)); |
| 338 | inet_ntop (AF_INET, &lsa->header->adv_router, |
| 339 | adv_router, sizeof (adv_router)); |
| 340 | |
hasso | 049207c | 2004-08-04 20:02:13 +0000 | [diff] [blame] | 341 | vty_out (vty, "%s", VNL); |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 342 | vty_out (vty, "Age: %4hu Type: %s%s", ospf6_lsa_age_current (lsa), |
hasso | 049207c | 2004-08-04 20:02:13 +0000 | [diff] [blame] | 343 | OSPF6_LSTYPE_NAME (lsa->header->type), VNL); |
| 344 | vty_out (vty, "Link State ID: %s%s", id, VNL); |
| 345 | vty_out (vty, "Advertising Router: %s%s", adv_router, VNL); |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 346 | vty_out (vty, "LS Sequence Number: %#010lx%s", |
hasso | 049207c | 2004-08-04 20:02:13 +0000 | [diff] [blame] | 347 | (u_long) ntohl (lsa->header->seqnum), VNL); |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 348 | vty_out (vty, "CheckSum: %#06hx Length: %hu%s", |
| 349 | ntohs (lsa->header->checksum), |
hasso | 049207c | 2004-08-04 20:02:13 +0000 | [diff] [blame] | 350 | ntohs (lsa->header->length), VNL); |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 351 | vty_out (vty, " Prev: %p This: %p Next: %p%s", |
hasso | 049207c | 2004-08-04 20:02:13 +0000 | [diff] [blame] | 352 | lsa->prev, lsa, lsa->next, VNL); |
| 353 | vty_out (vty, "%s", VNL); |
hasso | 6452df0 | 2004-08-15 05:52:07 +0000 | [diff] [blame] | 354 | return; |
| 355 | } |
| 356 | |
| 357 | void |
| 358 | ospf6_lsa_show (struct vty *vty, struct ospf6_lsa *lsa) |
| 359 | { |
| 360 | char adv_router[64], id[64]; |
| 361 | int index; |
| 362 | |
| 363 | assert (lsa && lsa->header); |
| 364 | |
| 365 | inet_ntop (AF_INET, &lsa->header->id, id, sizeof (id)); |
| 366 | inet_ntop (AF_INET, &lsa->header->adv_router, |
| 367 | adv_router, sizeof (adv_router)); |
| 368 | |
| 369 | vty_out (vty, "Age: %4hu Type: %s%s", ospf6_lsa_age_current (lsa), |
| 370 | OSPF6_LSTYPE_NAME (lsa->header->type), VNL); |
| 371 | vty_out (vty, "Link State ID: %s%s", id, VNL); |
| 372 | vty_out (vty, "Advertising Router: %s%s", adv_router, VNL); |
| 373 | vty_out (vty, "LS Sequence Number: %#010lx%s", |
| 374 | (u_long) ntohl (lsa->header->seqnum), VNL); |
| 375 | vty_out (vty, "CheckSum: %#06hx Length: %hu%s", |
| 376 | ntohs (lsa->header->checksum), |
| 377 | ntohs (lsa->header->length), VNL); |
| 378 | |
| 379 | index = OSPF6_LSTYPE_INDEX (lsa->header->type); |
| 380 | if (ospf6_lsa_handler[index]->show) |
| 381 | (*ospf6_lsa_handler[index]->show) (vty, lsa); |
| 382 | else |
| 383 | { |
| 384 | ospf6_lsa_show_dump (vty, lsa); |
| 385 | vty_out (vty, "%sUnknown LSA type ...%s", VNL, VNL); |
| 386 | } |
| 387 | |
| 388 | vty_out (vty, "%s", VNL); |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 389 | } |
| 390 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 391 | /* OSPFv3 LSA creation/deletion function */ |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 392 | struct ospf6_lsa * |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 393 | ospf6_lsa_create (struct ospf6_lsa_header *header) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 394 | { |
| 395 | struct ospf6_lsa *lsa = NULL; |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 396 | struct ospf6_lsa_header *new_header = NULL; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 397 | u_int16_t lsa_size = 0; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 398 | |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 399 | /* size of the entire LSA */ |
| 400 | lsa_size = ntohs (header->length); /* XXX vulnerable */ |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 401 | |
| 402 | /* allocate memory for this LSA */ |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 403 | new_header = (struct ospf6_lsa_header *) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 404 | XMALLOC (MTYPE_OSPF6_LSA, lsa_size); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 405 | |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 406 | /* copy LSA from original header */ |
| 407 | memcpy (new_header, header, lsa_size); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 408 | |
| 409 | /* LSA information structure */ |
| 410 | /* allocate memory */ |
| 411 | lsa = (struct ospf6_lsa *) |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 412 | XMALLOC (MTYPE_OSPF6_LSA, sizeof (struct ospf6_lsa)); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 413 | memset (lsa, 0, sizeof (struct ospf6_lsa)); |
| 414 | |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 415 | lsa->header = (struct ospf6_lsa_header *) new_header; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 416 | |
| 417 | /* dump string */ |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 418 | ospf6_lsa_printbuf (lsa, lsa->name, sizeof (lsa->name)); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 419 | |
hasso | 3b68735 | 2004-08-19 06:56:53 +0000 | [diff] [blame^] | 420 | /* calculate birth of this lsa */ |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 421 | ospf6_lsa_age_set (lsa); |
| 422 | |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 423 | if (IS_OSPF6_DEBUG_LSA (MEMORY)) |
| 424 | zlog_info ("Create LSA Memory: %s (%p/%p)", |
| 425 | lsa->name, lsa, lsa->header); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 426 | |
| 427 | return lsa; |
| 428 | } |
| 429 | |
| 430 | struct ospf6_lsa * |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 431 | ospf6_lsa_create_headeronly (struct ospf6_lsa_header *header) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 432 | { |
| 433 | struct ospf6_lsa *lsa = NULL; |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 434 | struct ospf6_lsa_header *new_header = NULL; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 435 | |
| 436 | /* allocate memory for this LSA */ |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 437 | new_header = (struct ospf6_lsa_header *) |
| 438 | XMALLOC (MTYPE_OSPF6_LSA, sizeof (struct ospf6_lsa_header)); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 439 | |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 440 | /* copy LSA from original header */ |
| 441 | memcpy (new_header, header, sizeof (struct ospf6_lsa_header)); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 442 | |
| 443 | /* LSA information structure */ |
| 444 | /* allocate memory */ |
| 445 | lsa = (struct ospf6_lsa *) |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 446 | XMALLOC (MTYPE_OSPF6_LSA, sizeof (struct ospf6_lsa)); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 447 | memset (lsa, 0, sizeof (struct ospf6_lsa)); |
| 448 | |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 449 | lsa->header = (struct ospf6_lsa_header *) new_header; |
hasso | 6452df0 | 2004-08-15 05:52:07 +0000 | [diff] [blame] | 450 | SET_FLAG (lsa->flag, OSPF6_LSA_HEADERONLY); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 451 | |
| 452 | /* dump string */ |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 453 | ospf6_lsa_printbuf (lsa, lsa->name, sizeof (lsa->name)); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 454 | |
hasso | 3b68735 | 2004-08-19 06:56:53 +0000 | [diff] [blame^] | 455 | /* calculate birth of this lsa */ |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 456 | ospf6_lsa_age_set (lsa); |
| 457 | |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 458 | if (IS_OSPF6_DEBUG_LSA (MEMORY)) |
| 459 | zlog_info ("Create LSA (Header-only) Memory: %s (%p/%p)", |
| 460 | lsa->name, lsa, lsa->header); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 461 | |
| 462 | return lsa; |
| 463 | } |
| 464 | |
| 465 | void |
| 466 | ospf6_lsa_delete (struct ospf6_lsa *lsa) |
| 467 | { |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 468 | assert (lsa->lock == 0); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 469 | |
| 470 | /* cancel threads */ |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 471 | THREAD_OFF (lsa->expire); |
| 472 | THREAD_OFF (lsa->refresh); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 473 | |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 474 | if (IS_OSPF6_DEBUG_LSA (MEMORY)) |
| 475 | zlog_info ("Delete LSA %s Memory: %s (%p/%p)", |
hasso | 6452df0 | 2004-08-15 05:52:07 +0000 | [diff] [blame] | 476 | (CHECK_FLAG (lsa->flag, OSPF6_LSA_HEADERONLY) ? |
| 477 | "(Header-only) " : ""), lsa->name, lsa, lsa->header); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 478 | |
| 479 | /* do free */ |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 480 | XFREE (MTYPE_OSPF6_LSA, lsa->header); |
| 481 | XFREE (MTYPE_OSPF6_LSA, lsa); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 482 | } |
| 483 | |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 484 | struct ospf6_lsa * |
| 485 | ospf6_lsa_copy (struct ospf6_lsa *lsa) |
| 486 | { |
| 487 | struct ospf6_lsa *copy = NULL; |
| 488 | |
| 489 | if (IS_OSPF6_DEBUG_LSA (MEMORY)) |
| 490 | zlog_info ("Create LSA Copy from %s", lsa->name); |
| 491 | |
| 492 | ospf6_lsa_age_current (lsa); |
hasso | 6452df0 | 2004-08-15 05:52:07 +0000 | [diff] [blame] | 493 | if (CHECK_FLAG (lsa->flag, OSPF6_LSA_HEADERONLY)) |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 494 | copy = ospf6_lsa_create_headeronly (lsa->header); |
| 495 | else |
| 496 | copy = ospf6_lsa_create (lsa->header); |
| 497 | assert (copy->lock == 0); |
| 498 | |
hasso | 3b68735 | 2004-08-19 06:56:53 +0000 | [diff] [blame^] | 499 | copy->birth = lsa->birth; |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 500 | copy->installed = lsa->installed; |
| 501 | copy->originated = lsa->originated; |
hasso | 6452df0 | 2004-08-15 05:52:07 +0000 | [diff] [blame] | 502 | copy->lsdb = lsa->lsdb; |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 503 | |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 504 | return copy; |
| 505 | } |
| 506 | |
| 507 | /* increment reference counter of struct ospf6_lsa */ |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 508 | void |
| 509 | ospf6_lsa_lock (struct ospf6_lsa *lsa) |
| 510 | { |
| 511 | lsa->lock++; |
| 512 | return; |
| 513 | } |
| 514 | |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 515 | /* decrement reference counter of struct ospf6_lsa */ |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 516 | void |
| 517 | ospf6_lsa_unlock (struct ospf6_lsa *lsa) |
| 518 | { |
| 519 | /* decrement reference counter */ |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 520 | assert (lsa->lock > 0); |
| 521 | lsa->lock--; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 522 | |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 523 | if (lsa->lock != 0) |
| 524 | return; |
| 525 | |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 526 | ospf6_lsa_delete (lsa); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 527 | } |
| 528 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 529 | |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 530 | /* ospf6 lsa expiry */ |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 531 | int |
| 532 | ospf6_lsa_expire (struct thread *thread) |
| 533 | { |
| 534 | struct ospf6_lsa *lsa; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 535 | |
| 536 | lsa = (struct ospf6_lsa *) THREAD_ARG (thread); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 537 | |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 538 | assert (lsa && lsa->header); |
| 539 | assert (OSPF6_LSA_IS_MAXAGE (lsa)); |
| 540 | assert (! lsa->refresh); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 541 | |
| 542 | lsa->expire = (struct thread *) NULL; |
| 543 | |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 544 | if (IS_OSPF6_DEBUG_LSA (TIMER)) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 545 | { |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 546 | zlog_info ("LSA Expire:"); |
| 547 | ospf6_lsa_header_print (lsa); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 548 | } |
| 549 | |
hasso | 6452df0 | 2004-08-15 05:52:07 +0000 | [diff] [blame] | 550 | if (CHECK_FLAG (lsa->flag, OSPF6_LSA_HEADERONLY)) |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 551 | return 0; /* dbexchange will do something ... */ |
| 552 | |
| 553 | /* reflood lsa */ |
hasso | 6452df0 | 2004-08-15 05:52:07 +0000 | [diff] [blame] | 554 | ospf6_flood (NULL, lsa); |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 555 | |
| 556 | /* reinstall lsa */ |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 557 | if (IS_OSPF6_DEBUG_LSA (DATABASE)) |
| 558 | zlog_info ("Reinstall MaxAge %s", lsa->name); |
hasso | 3b68735 | 2004-08-19 06:56:53 +0000 | [diff] [blame^] | 559 | ospf6_install_lsa (lsa); |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 560 | |
| 561 | /* schedule maxage remover */ |
| 562 | ospf6_maxage_remove (ospf6); |
| 563 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 564 | return 0; |
| 565 | } |
| 566 | |
| 567 | int |
| 568 | ospf6_lsa_refresh (struct thread *thread) |
| 569 | { |
hasso | 6452df0 | 2004-08-15 05:52:07 +0000 | [diff] [blame] | 570 | struct ospf6_lsa *old, *self, *new; |
| 571 | struct ospf6_lsdb *lsdb_self; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 572 | |
| 573 | assert (thread); |
hasso | 6452df0 | 2004-08-15 05:52:07 +0000 | [diff] [blame] | 574 | old = (struct ospf6_lsa *) THREAD_ARG (thread); |
| 575 | assert (old && old->header); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 576 | |
hasso | 6452df0 | 2004-08-15 05:52:07 +0000 | [diff] [blame] | 577 | old->refresh = (struct thread *) NULL; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 578 | |
hasso | 6452df0 | 2004-08-15 05:52:07 +0000 | [diff] [blame] | 579 | lsdb_self = ospf6_get_scoped_lsdb_self (old); |
| 580 | self = ospf6_lsdb_lookup (old->header->type, old->header->id, |
| 581 | old->header->adv_router, lsdb_self); |
| 582 | if (self == NULL) |
| 583 | { |
hasso | 3b68735 | 2004-08-19 06:56:53 +0000 | [diff] [blame^] | 584 | if (IS_OSPF6_DEBUG_LSA (ORIGINATE)) |
| 585 | zlog_info ("Refresh: could not find self LSA, flush %s", old->name); |
hasso | 6452df0 | 2004-08-15 05:52:07 +0000 | [diff] [blame] | 586 | ospf6_lsa_premature_aging (old); |
| 587 | return 0; |
| 588 | } |
| 589 | |
| 590 | /* Reset age, increment LS sequence number. */ |
| 591 | self->header->age = htons (0); |
| 592 | self->header->seqnum = |
| 593 | ospf6_new_ls_seqnum (self->header->type, self->header->id, |
| 594 | self->header->adv_router, old->lsdb); |
| 595 | ospf6_lsa_checksum (self->header); |
| 596 | |
| 597 | new = ospf6_lsa_create (self->header); |
| 598 | new->lsdb = old->lsdb; |
| 599 | new->refresh = thread_add_timer (master, ospf6_lsa_refresh, new, |
| 600 | LS_REFRESH_TIME); |
| 601 | |
| 602 | /* store it in the LSDB for self-originated LSAs */ |
| 603 | ospf6_lsdb_add (ospf6_lsa_copy (new), lsdb_self); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 604 | |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 605 | if (IS_OSPF6_DEBUG_LSA (ORIGINATE)) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 606 | { |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 607 | zlog_info ("LSA Refresh:"); |
hasso | 6452df0 | 2004-08-15 05:52:07 +0000 | [diff] [blame] | 608 | ospf6_lsa_header_print (new); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 609 | } |
| 610 | |
hasso | 6452df0 | 2004-08-15 05:52:07 +0000 | [diff] [blame] | 611 | ospf6_flood_clear (old); |
| 612 | ospf6_flood (NULL, new); |
| 613 | ospf6_install_lsa (new); |
| 614 | |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 615 | return 0; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 616 | } |
| 617 | |
| 618 | |
| 619 | |
| 620 | /* enhanced Fletcher checksum algorithm, RFC1008 7.2 */ |
| 621 | #define MODX 4102 |
| 622 | #define LSA_CHECKSUM_OFFSET 15 |
| 623 | |
| 624 | unsigned short |
| 625 | ospf6_lsa_checksum (struct ospf6_lsa_header *lsa_header) |
| 626 | { |
| 627 | u_char *sp, *ep, *p, *q; |
| 628 | int c0 = 0, c1 = 0; |
| 629 | int x, y; |
| 630 | u_int16_t length; |
| 631 | |
| 632 | lsa_header->checksum = 0; |
| 633 | length = ntohs (lsa_header->length) - 2; |
| 634 | sp = (char *) &lsa_header->type; |
| 635 | |
| 636 | for (ep = sp + length; sp < ep; sp = q) |
| 637 | { |
| 638 | q = sp + MODX; |
| 639 | if (q > ep) |
| 640 | q = ep; |
| 641 | for (p = sp; p < q; p++) |
| 642 | { |
| 643 | c0 += *p; |
| 644 | c1 += c0; |
| 645 | } |
| 646 | c0 %= 255; |
| 647 | c1 %= 255; |
| 648 | } |
| 649 | |
| 650 | /* r = (c1 << 8) + c0; */ |
| 651 | x = ((length - LSA_CHECKSUM_OFFSET) * c0 - c1) % 255; |
| 652 | if (x <= 0) |
| 653 | x += 255; |
| 654 | y = 510 - c0 - x; |
| 655 | if (y > 255) |
| 656 | y -= 255; |
| 657 | |
| 658 | lsa_header->checksum = htons ((x << 8) + y); |
| 659 | |
| 660 | return (lsa_header->checksum); |
| 661 | } |
| 662 | |
| 663 | int |
hasso | 6452df0 | 2004-08-15 05:52:07 +0000 | [diff] [blame] | 664 | ospf6_unknown_lsa_show (struct vty *vty, struct ospf6_lsa *lsa) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 665 | { |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 666 | u_char *start, *end, *current; |
| 667 | char byte[4]; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 668 | |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 669 | start = (char *) lsa->header + sizeof (struct ospf6_lsa_header); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 670 | end = (char *) lsa->header + ntohs (lsa->header->length); |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 671 | |
hasso | 049207c | 2004-08-04 20:02:13 +0000 | [diff] [blame] | 672 | vty_out (vty, " Unknown contents:%s", VNL); |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 673 | for (current = start; current < end; current ++) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 674 | { |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 675 | if ((current - start) % 16 == 0) |
hasso | 049207c | 2004-08-04 20:02:13 +0000 | [diff] [blame] | 676 | vty_out (vty, "%s ", VNL); |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 677 | else if ((current - start) % 4 == 0) |
| 678 | vty_out (vty, " "); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 679 | |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 680 | snprintf (byte, sizeof (byte), "%02x", *current); |
| 681 | vty_out (vty, "%s", byte); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 682 | } |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 683 | |
hasso | 049207c | 2004-08-04 20:02:13 +0000 | [diff] [blame] | 684 | vty_out (vty, "%s%s", VNL, VNL); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 685 | return 0; |
| 686 | } |
| 687 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 688 | void |
hasso | 6452df0 | 2004-08-15 05:52:07 +0000 | [diff] [blame] | 689 | ospf6_install_lsa_handler (struct ospf6_lsa_handler *handler) |
| 690 | { |
| 691 | /* might need to adjust dynamic array length ... */ |
| 692 | int index = OSPF6_LSTYPE_INDEX (htons (handler->type)); |
| 693 | ospf6_lsa_handler[index] = handler; |
| 694 | } |
| 695 | |
| 696 | struct ospf6_lsa_handler unknown_handler = |
| 697 | { |
| 698 | OSPF6_LSTYPE_UNKNOWN, |
| 699 | "Unknown", |
| 700 | ospf6_unknown_lsa_show |
| 701 | }; |
| 702 | |
| 703 | void |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 704 | ospf6_lsa_init () |
| 705 | { |
hasso | 6452df0 | 2004-08-15 05:52:07 +0000 | [diff] [blame] | 706 | memset (ospf6_lsa_handler, 0, sizeof (ospf6_lsa_handler)); |
| 707 | ospf6_install_lsa_handler (&unknown_handler); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 708 | } |
| 709 | |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 710 | |
| 711 | |
| 712 | DEFUN (debug_ospf6_lsa_sendrecv, |
| 713 | debug_ospf6_lsa_sendrecv_cmd, |
| 714 | "debug ospf6 lsa (send|recv|originate|timer|database|memory|all)", |
| 715 | DEBUG_STR |
| 716 | OSPF6_STR |
| 717 | "Debug Link State Advertisements (LSAs)\n" |
| 718 | "Debug Sending LSAs\n" |
| 719 | "Debug Receiving LSAs\n" |
| 720 | "Debug Originating LSAs\n" |
| 721 | "Debug Timer Event of LSAs\n" |
| 722 | "Debug LSA Database\n" |
| 723 | "Debug Memory of LSAs\n" |
| 724 | "Debug LSAs all\n" |
| 725 | ) |
| 726 | { |
| 727 | unsigned char level = 0; |
| 728 | |
| 729 | if (argc) |
| 730 | { |
| 731 | if (! strncmp (argv[0], "s", 1)) |
| 732 | level = OSPF6_DEBUG_LSA_SEND; |
| 733 | else if (! strncmp (argv[0], "r", 1)) |
| 734 | level = OSPF6_DEBUG_LSA_RECV; |
| 735 | else if (! strncmp (argv[0], "o", 1)) |
| 736 | level = OSPF6_DEBUG_LSA_ORIGINATE; |
| 737 | else if (! strncmp (argv[0], "t", 1)) |
| 738 | level = OSPF6_DEBUG_LSA_TIMER; |
| 739 | else if (! strncmp (argv[0], "d", 1)) |
| 740 | level = OSPF6_DEBUG_LSA_DATABASE; |
| 741 | else if (! strncmp (argv[0], "m", 1)) |
| 742 | level = OSPF6_DEBUG_LSA_MEMORY; |
| 743 | else if (! strncmp (argv[0], "a", 1)) |
| 744 | { |
| 745 | level = OSPF6_DEBUG_LSA_SEND | OSPF6_DEBUG_LSA_RECV | |
| 746 | OSPF6_DEBUG_LSA_ORIGINATE | OSPF6_DEBUG_LSA_TIMER | |
| 747 | OSPF6_DEBUG_LSA_DATABASE | OSPF6_DEBUG_LSA_MEMORY; |
| 748 | } |
| 749 | } |
| 750 | else |
| 751 | { |
| 752 | level = OSPF6_DEBUG_LSA_SEND | OSPF6_DEBUG_LSA_RECV | |
| 753 | OSPF6_DEBUG_LSA_ORIGINATE | OSPF6_DEBUG_LSA_TIMER; |
| 754 | } |
| 755 | |
| 756 | OSPF6_DEBUG_LSA_ON (level); |
| 757 | return CMD_SUCCESS; |
| 758 | } |
| 759 | |
| 760 | ALIAS (debug_ospf6_lsa_sendrecv, |
| 761 | debug_ospf6_lsa_cmd, |
| 762 | "debug ospf6 lsa", |
| 763 | NO_STR |
| 764 | DEBUG_STR |
| 765 | OSPF6_STR |
| 766 | "Debug Link State Advertisements (LSAs)\n" |
| 767 | ); |
| 768 | |
| 769 | DEFUN (no_debug_ospf6_lsa_sendrecv, |
| 770 | no_debug_ospf6_lsa_sendrecv_cmd, |
| 771 | "no debug ospf6 lsa (send|recv|originate|timer|database|memory|all)", |
| 772 | NO_STR |
| 773 | DEBUG_STR |
| 774 | OSPF6_STR |
| 775 | "Debug Link State Advertisements (LSAs)\n" |
| 776 | "Debug Sending LSAs\n" |
| 777 | "Debug Receiving LSAs\n" |
| 778 | "Debug Originating LSAs\n" |
| 779 | "Debug Timer Event of LSAs\n" |
| 780 | "Debug LSA Database\n" |
| 781 | "Debug Memory of LSAs\n" |
| 782 | "Debug LSAs all\n" |
| 783 | ) |
| 784 | { |
| 785 | unsigned char level = 0; |
| 786 | |
| 787 | if (argc) |
| 788 | { |
| 789 | if (! strncmp (argv[0], "s", 1)) |
| 790 | level = OSPF6_DEBUG_LSA_SEND; |
| 791 | else if (! strncmp (argv[0], "r", 1)) |
| 792 | level = OSPF6_DEBUG_LSA_RECV; |
| 793 | else if (! strncmp (argv[0], "o", 1)) |
| 794 | level = OSPF6_DEBUG_LSA_ORIGINATE; |
| 795 | else if (! strncmp (argv[0], "t", 1)) |
| 796 | level = OSPF6_DEBUG_LSA_TIMER; |
| 797 | else if (! strncmp (argv[0], "d", 1)) |
| 798 | level = OSPF6_DEBUG_LSA_DATABASE; |
| 799 | else if (! strncmp (argv[0], "m", 1)) |
| 800 | level = OSPF6_DEBUG_LSA_MEMORY; |
| 801 | else if (! strncmp (argv[0], "a", 1)) |
| 802 | { |
| 803 | level = OSPF6_DEBUG_LSA_SEND | OSPF6_DEBUG_LSA_RECV | |
| 804 | OSPF6_DEBUG_LSA_ORIGINATE | OSPF6_DEBUG_LSA_TIMER | |
| 805 | OSPF6_DEBUG_LSA_DATABASE | OSPF6_DEBUG_LSA_MEMORY; |
| 806 | } |
| 807 | } |
| 808 | else |
| 809 | { |
| 810 | level = OSPF6_DEBUG_LSA_SEND | OSPF6_DEBUG_LSA_RECV | |
| 811 | OSPF6_DEBUG_LSA_ORIGINATE | OSPF6_DEBUG_LSA_TIMER; |
| 812 | } |
| 813 | |
| 814 | OSPF6_DEBUG_LSA_OFF (level); |
| 815 | return CMD_SUCCESS; |
| 816 | } |
| 817 | |
| 818 | ALIAS (no_debug_ospf6_lsa_sendrecv, |
| 819 | no_debug_ospf6_lsa_cmd, |
| 820 | "no debug ospf6 lsa", |
| 821 | NO_STR |
| 822 | DEBUG_STR |
| 823 | OSPF6_STR |
| 824 | "Debug Link State Advertisements (LSAs)\n" |
| 825 | ); |
| 826 | |
| 827 | int |
| 828 | config_write_ospf6_debug_lsa (struct vty *vty) |
| 829 | { |
| 830 | if (conf_debug_ospf6_lsa == OSPF6_DEBUG_LSA_ALL) |
hasso | 049207c | 2004-08-04 20:02:13 +0000 | [diff] [blame] | 831 | vty_out (vty, "debug ospf6 lsa all%s", VNL); |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 832 | else |
| 833 | { |
| 834 | if (conf_debug_ospf6_lsa == OSPF6_DEBUG_LSA_DEFAULT) |
hasso | 049207c | 2004-08-04 20:02:13 +0000 | [diff] [blame] | 835 | vty_out (vty, "debug ospf6 lsa%s", VNL); |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 836 | else |
| 837 | { |
| 838 | if (IS_OSPF6_DEBUG_LSA (SEND)) |
hasso | 049207c | 2004-08-04 20:02:13 +0000 | [diff] [blame] | 839 | vty_out (vty, "debug ospf6 lsa send%s", VNL); |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 840 | if (IS_OSPF6_DEBUG_LSA (RECV)) |
hasso | 049207c | 2004-08-04 20:02:13 +0000 | [diff] [blame] | 841 | vty_out (vty, "debug ospf6 lsa recv%s", VNL); |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 842 | if (IS_OSPF6_DEBUG_LSA (ORIGINATE)) |
hasso | 049207c | 2004-08-04 20:02:13 +0000 | [diff] [blame] | 843 | vty_out (vty, "debug ospf6 lsa originate%s", VNL); |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 844 | if (IS_OSPF6_DEBUG_LSA (TIMER)) |
hasso | 049207c | 2004-08-04 20:02:13 +0000 | [diff] [blame] | 845 | vty_out (vty, "debug ospf6 lsa timer%s", VNL); |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 846 | } |
| 847 | |
| 848 | if (IS_OSPF6_DEBUG_LSA (DATABASE)) |
hasso | 049207c | 2004-08-04 20:02:13 +0000 | [diff] [blame] | 849 | vty_out (vty, "debug ospf6 lsa database%s", VNL); |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 850 | if (IS_OSPF6_DEBUG_LSA (MEMORY)) |
hasso | 049207c | 2004-08-04 20:02:13 +0000 | [diff] [blame] | 851 | vty_out (vty, "debug ospf6 lsa memory%s", VNL); |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 852 | } |
| 853 | |
| 854 | return 0; |
| 855 | } |
| 856 | |
| 857 | void |
| 858 | install_element_ospf6_debug_lsa () |
| 859 | { |
| 860 | install_element (ENABLE_NODE, &debug_ospf6_lsa_cmd); |
| 861 | install_element (ENABLE_NODE, &debug_ospf6_lsa_sendrecv_cmd); |
| 862 | install_element (ENABLE_NODE, &no_debug_ospf6_lsa_cmd); |
| 863 | install_element (ENABLE_NODE, &no_debug_ospf6_lsa_sendrecv_cmd); |
| 864 | install_element (CONFIG_NODE, &debug_ospf6_lsa_cmd); |
| 865 | install_element (CONFIG_NODE, &debug_ospf6_lsa_sendrecv_cmd); |
| 866 | install_element (CONFIG_NODE, &no_debug_ospf6_lsa_cmd); |
| 867 | install_element (CONFIG_NODE, &no_debug_ospf6_lsa_sendrecv_cmd); |
| 868 | } |
| 869 | |
| 870 | |