paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1 | /* |
| 2 | * OSPF Link State Advertisement |
| 3 | * Copyright (C) 1999, 2000 Toshiaki Takada |
| 4 | * |
| 5 | * This file is part of GNU Zebra. |
| 6 | * |
| 7 | * GNU Zebra is free software; you can redistribute it and/or modify it |
| 8 | * under the terms of the GNU General Public License as published by the |
| 9 | * Free Software Foundation; either version 2, or (at your option) any |
| 10 | * later version. |
| 11 | * |
| 12 | * GNU Zebra is distributed in the hope that it will be useful, but |
| 13 | * WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 15 | * General Public License for more details. |
| 16 | * |
| 17 | * You should have received a copy of the GNU General Public License |
| 18 | * along with GNU Zebra; see the file COPYING. If not, write to the Free |
| 19 | * Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA |
| 20 | * 02111-1307, USA. |
| 21 | */ |
| 22 | |
| 23 | #include <zebra.h> |
| 24 | |
| 25 | #include "linklist.h" |
| 26 | #include "prefix.h" |
| 27 | #include "if.h" |
| 28 | #include "table.h" |
| 29 | #include "memory.h" |
| 30 | #include "stream.h" |
| 31 | #include "log.h" |
| 32 | #include "thread.h" |
| 33 | #include "hash.h" |
| 34 | #include "sockunion.h" /* for inet_aton() */ |
| 35 | |
| 36 | #include "ospfd/ospfd.h" |
| 37 | #include "ospfd/ospf_interface.h" |
| 38 | #include "ospfd/ospf_ism.h" |
| 39 | #include "ospfd/ospf_asbr.h" |
| 40 | #include "ospfd/ospf_lsa.h" |
| 41 | #include "ospfd/ospf_lsdb.h" |
| 42 | #include "ospfd/ospf_neighbor.h" |
| 43 | #include "ospfd/ospf_nsm.h" |
| 44 | #include "ospfd/ospf_flood.h" |
| 45 | #include "ospfd/ospf_packet.h" |
| 46 | #include "ospfd/ospf_spf.h" |
| 47 | #include "ospfd/ospf_dump.h" |
| 48 | #include "ospfd/ospf_route.h" |
| 49 | #include "ospfd/ospf_ase.h" |
| 50 | #include "ospfd/ospf_zebra.h" |
| 51 | |
| 52 | |
| 53 | u_int32_t |
| 54 | get_metric (u_char *metric) |
| 55 | { |
| 56 | u_int32_t m; |
| 57 | m = metric[0]; |
| 58 | m = (m << 8) + metric[1]; |
| 59 | m = (m << 8) + metric[2]; |
| 60 | return m; |
| 61 | } |
| 62 | |
| 63 | |
| 64 | struct timeval |
| 65 | tv_adjust (struct timeval a) |
| 66 | { |
| 67 | while (a.tv_usec >= 1000000) |
| 68 | { |
| 69 | a.tv_usec -= 1000000; |
| 70 | a.tv_sec++; |
| 71 | } |
| 72 | |
| 73 | while (a.tv_usec < 0) |
| 74 | { |
| 75 | a.tv_usec += 1000000; |
| 76 | a.tv_sec--; |
| 77 | } |
| 78 | |
| 79 | return a; |
| 80 | } |
| 81 | |
| 82 | int |
| 83 | tv_ceil (struct timeval a) |
| 84 | { |
| 85 | a = tv_adjust (a); |
| 86 | |
| 87 | return (a.tv_usec ? a.tv_sec + 1 : a.tv_sec); |
| 88 | } |
| 89 | |
| 90 | int |
| 91 | tv_floor (struct timeval a) |
| 92 | { |
| 93 | a = tv_adjust (a); |
| 94 | |
| 95 | return a.tv_sec; |
| 96 | } |
| 97 | |
| 98 | struct timeval |
| 99 | int2tv (int a) |
| 100 | { |
| 101 | struct timeval ret; |
| 102 | |
| 103 | ret.tv_sec = a; |
| 104 | ret.tv_usec = 0; |
| 105 | |
| 106 | return ret; |
| 107 | } |
| 108 | |
| 109 | struct timeval |
| 110 | tv_add (struct timeval a, struct timeval b) |
| 111 | { |
| 112 | struct timeval ret; |
| 113 | |
| 114 | ret.tv_sec = a.tv_sec + b.tv_sec; |
| 115 | ret.tv_usec = a.tv_usec + b.tv_usec; |
| 116 | |
| 117 | return tv_adjust (ret); |
| 118 | } |
| 119 | |
| 120 | struct timeval |
| 121 | tv_sub (struct timeval a, struct timeval b) |
| 122 | { |
| 123 | struct timeval ret; |
| 124 | |
| 125 | ret.tv_sec = a.tv_sec - b.tv_sec; |
| 126 | ret.tv_usec = a.tv_usec - b.tv_usec; |
| 127 | |
| 128 | return tv_adjust (ret); |
| 129 | } |
| 130 | |
| 131 | int |
| 132 | tv_cmp (struct timeval a, struct timeval b) |
| 133 | { |
| 134 | return (a.tv_sec == b.tv_sec ? |
| 135 | a.tv_usec - b.tv_usec : a.tv_sec - b.tv_sec); |
| 136 | } |
| 137 | |
| 138 | int |
| 139 | ospf_lsa_refresh_delay (struct ospf_lsa *lsa) |
| 140 | { |
| 141 | struct timeval delta, now; |
| 142 | int delay = 0; |
| 143 | |
| 144 | gettimeofday (&now, NULL); |
| 145 | delta = tv_sub (now, lsa->tv_orig); |
| 146 | |
| 147 | if (tv_cmp (delta, int2tv (OSPF_MIN_LS_INTERVAL)) < 0) |
| 148 | { |
| 149 | delay = tv_ceil (tv_sub (int2tv (OSPF_MIN_LS_INTERVAL), delta)); |
| 150 | |
| 151 | if (IS_DEBUG_OSPF (lsa, LSA_GENERATE)) |
| 152 | zlog_info ("LSA[Type%d:%s]: Refresh timer delay %d seconds", |
| 153 | lsa->data->type, inet_ntoa (lsa->data->id), delay); |
| 154 | |
| 155 | assert (delay > 0); |
| 156 | } |
| 157 | |
| 158 | return delay; |
| 159 | } |
| 160 | |
| 161 | |
| 162 | int |
| 163 | get_age (struct ospf_lsa *lsa) |
| 164 | { |
| 165 | int age; |
| 166 | struct timeval now; |
| 167 | |
| 168 | gettimeofday (&now, NULL); |
| 169 | age = ntohs (lsa->data->ls_age) + tv_floor (tv_sub (now, lsa->tv_recv)); |
| 170 | |
| 171 | return age; |
| 172 | } |
| 173 | |
| 174 | |
| 175 | /* Fletcher Checksum -- Refer to RFC1008. */ |
| 176 | #define MODX 4102 |
| 177 | #define LSA_CHECKSUM_OFFSET 15 |
| 178 | |
| 179 | u_int16_t |
| 180 | ospf_lsa_checksum (struct lsa_header *lsa) |
| 181 | { |
| 182 | u_char *sp, *ep, *p, *q; |
| 183 | int c0 = 0, c1 = 0; |
| 184 | int x, y; |
| 185 | u_int16_t length; |
| 186 | |
| 187 | lsa->checksum = 0; |
| 188 | length = ntohs (lsa->length) - 2; |
| 189 | sp = (char *) &lsa->options; |
| 190 | |
| 191 | for (ep = sp + length; sp < ep; sp = q) |
| 192 | { |
| 193 | q = sp + MODX; |
| 194 | if (q > ep) |
| 195 | q = ep; |
| 196 | for (p = sp; p < q; p++) |
| 197 | { |
| 198 | c0 += *p; |
| 199 | c1 += c0; |
| 200 | } |
| 201 | c0 %= 255; |
| 202 | c1 %= 255; |
| 203 | } |
| 204 | |
| 205 | x = ((length - LSA_CHECKSUM_OFFSET) * c0 - c1) % 255; |
| 206 | if (x <= 0) |
| 207 | x += 255; |
| 208 | y = 510 - c0 - x; |
| 209 | if (y > 255) |
| 210 | y -= 255; |
| 211 | |
| 212 | /* take care endian issue. */ |
| 213 | lsa->checksum = htons ((x << 8) + y); |
| 214 | |
| 215 | return (lsa->checksum); |
| 216 | } |
| 217 | |
| 218 | |
| 219 | |
| 220 | /* Create OSPF LSA. */ |
| 221 | struct ospf_lsa * |
| 222 | ospf_lsa_new () |
| 223 | { |
| 224 | struct ospf_lsa *new; |
| 225 | |
| 226 | new = XCALLOC (MTYPE_OSPF_LSA, sizeof (struct ospf_lsa)); |
| 227 | memset (new, 0, sizeof (struct ospf_lsa)); |
| 228 | |
| 229 | new->flags = 0; |
| 230 | new->lock = 1; |
| 231 | new->retransmit_counter = 0; |
| 232 | gettimeofday (&new->tv_recv, NULL); |
| 233 | new->tv_orig = new->tv_recv; |
| 234 | new->refresh_list = -1; |
| 235 | |
| 236 | return new; |
| 237 | } |
| 238 | |
| 239 | /* Duplicate OSPF LSA. */ |
| 240 | struct ospf_lsa * |
| 241 | ospf_lsa_dup (struct ospf_lsa *lsa) |
| 242 | { |
| 243 | struct ospf_lsa *new; |
| 244 | |
| 245 | if (lsa == NULL) |
| 246 | return NULL; |
| 247 | |
| 248 | new = XCALLOC (MTYPE_OSPF_LSA, sizeof (struct ospf_lsa)); |
| 249 | |
| 250 | memcpy (new, lsa, sizeof (struct ospf_lsa)); |
| 251 | UNSET_FLAG (new->flags, OSPF_LSA_DISCARD); |
| 252 | new->lock = 1; |
| 253 | new->retransmit_counter = 0; |
| 254 | new->data = ospf_lsa_data_dup (lsa->data); |
| 255 | |
paul | f2c8065 | 2002-12-13 21:44:27 +0000 | [diff] [blame] | 256 | /* kevinm: Clear the refresh_list, otherwise there are going |
| 257 | to be problems when we try to remove the LSA from the |
| 258 | queue (which it's not a member of.) |
| 259 | XXX: Should we add the LSA to the refresh_list queue? */ |
| 260 | new->refresh_list = -1; |
| 261 | |
| 262 | if (IS_DEBUG_OSPF (lsa, LSA)) |
| 263 | zlog_info ("LSA: duplicated %p (new: %p)", lsa, new); |
| 264 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 265 | return new; |
| 266 | } |
| 267 | |
| 268 | /* Free OSPF LSA. */ |
| 269 | void |
| 270 | ospf_lsa_free (struct ospf_lsa *lsa) |
| 271 | { |
| 272 | assert (lsa->lock == 0); |
| 273 | |
| 274 | if (IS_DEBUG_OSPF (lsa, LSA)) |
| 275 | zlog_info ("LSA: freed %p", lsa); |
| 276 | |
| 277 | /* Delete LSA data. */ |
| 278 | if (lsa->data != NULL) |
| 279 | ospf_lsa_data_free (lsa->data); |
| 280 | |
| 281 | assert (lsa->refresh_list < 0); |
| 282 | |
| 283 | memset (lsa, 0, sizeof (struct ospf_lsa)); |
| 284 | XFREE (MTYPE_OSPF_LSA, lsa); |
| 285 | } |
| 286 | |
| 287 | /* Lock LSA. */ |
| 288 | struct ospf_lsa * |
| 289 | ospf_lsa_lock (struct ospf_lsa *lsa) |
| 290 | { |
| 291 | lsa->lock++; |
| 292 | return lsa; |
| 293 | } |
| 294 | |
| 295 | /* Unlock LSA. */ |
| 296 | void |
| 297 | ospf_lsa_unlock (struct ospf_lsa *lsa) |
| 298 | { |
| 299 | /* This is sanity check. */ |
| 300 | if (!lsa) |
| 301 | return; |
| 302 | |
| 303 | lsa->lock--; |
| 304 | |
| 305 | assert (lsa->lock >= 0); |
| 306 | |
| 307 | if (lsa->lock == 0) |
| 308 | { |
| 309 | assert (CHECK_FLAG (lsa->flags, OSPF_LSA_DISCARD)); |
| 310 | ospf_lsa_free (lsa); |
| 311 | } |
| 312 | } |
| 313 | |
| 314 | /* Check discard flag. */ |
| 315 | void |
| 316 | ospf_lsa_discard (struct ospf_lsa *lsa) |
| 317 | { |
| 318 | if (!CHECK_FLAG (lsa->flags, OSPF_LSA_DISCARD)) |
| 319 | { |
| 320 | SET_FLAG (lsa->flags, OSPF_LSA_DISCARD); |
| 321 | ospf_lsa_unlock (lsa); |
| 322 | } |
| 323 | } |
| 324 | |
| 325 | /* Create LSA data. */ |
| 326 | struct lsa_header * |
| 327 | ospf_lsa_data_new (size_t size) |
| 328 | { |
| 329 | struct lsa_header *new; |
| 330 | |
| 331 | new = (struct lsa_header *) XMALLOC (MTYPE_OSPF_LSA_DATA, size); |
| 332 | memset (new, 0, size); |
| 333 | |
| 334 | return new; |
| 335 | } |
| 336 | |
| 337 | /* Duplicate LSA data. */ |
| 338 | struct lsa_header * |
| 339 | ospf_lsa_data_dup (struct lsa_header *lsah) |
| 340 | { |
| 341 | struct lsa_header *new; |
| 342 | |
| 343 | new = ospf_lsa_data_new (ntohs (lsah->length)); |
| 344 | memcpy (new, lsah, ntohs (lsah->length)); |
| 345 | |
| 346 | return new; |
| 347 | } |
| 348 | |
| 349 | /* Free LSA data. */ |
| 350 | void |
| 351 | ospf_lsa_data_free (struct lsa_header *lsah) |
| 352 | { |
| 353 | if (IS_DEBUG_OSPF (lsa, LSA)) |
| 354 | zlog_info ("LSA[Type%d:%s]: data freed %p", |
| 355 | lsah->type, inet_ntoa (lsah->id), lsah); |
| 356 | |
| 357 | XFREE (MTYPE_OSPF_LSA_DATA, lsah); |
| 358 | } |
| 359 | |
| 360 | |
| 361 | /* LSA general functions. */ |
| 362 | |
| 363 | const char * |
| 364 | dump_lsa_key (struct ospf_lsa *lsa) |
| 365 | { |
| 366 | static char buf[] = { |
| 367 | "Type255,id(255.255.255.255),ar(255.255.255.255)", |
| 368 | }; |
| 369 | struct lsa_header *lsah; |
| 370 | |
| 371 | if (lsa != NULL && (lsah = lsa->data) != NULL) |
| 372 | { |
| 373 | char id[INET_ADDRSTRLEN], ar[INET_ADDRSTRLEN]; |
| 374 | strcpy (id, inet_ntoa (lsah->id)); |
| 375 | strcpy (ar, inet_ntoa (lsah->adv_router)); |
| 376 | |
| 377 | sprintf (buf, "Type%d,id(%s),ar(%s)", lsah->type, id, ar); |
| 378 | } |
| 379 | else |
| 380 | strcpy (buf, "NULL"); |
| 381 | |
| 382 | return buf; |
| 383 | } |
| 384 | |
| 385 | u_int32_t |
| 386 | lsa_seqnum_increment (struct ospf_lsa *lsa) |
| 387 | { |
| 388 | u_int32_t seqnum; |
| 389 | |
| 390 | seqnum = ntohl (lsa->data->ls_seqnum) + 1; |
| 391 | |
| 392 | return htonl (seqnum); |
| 393 | } |
| 394 | |
| 395 | void |
| 396 | lsa_header_set (struct stream *s, u_char options, |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 397 | u_char type, struct in_addr id, struct in_addr router_id) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 398 | { |
| 399 | struct lsa_header *lsah; |
| 400 | |
| 401 | lsah = (struct lsa_header *) STREAM_DATA (s); |
| 402 | |
| 403 | lsah->ls_age = htons (0); |
| 404 | lsah->options = options; |
| 405 | lsah->type = type; |
| 406 | lsah->id = id; |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 407 | lsah->adv_router = router_id; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 408 | lsah->ls_seqnum = htonl (OSPF_INITIAL_SEQUENCE_NUMBER); |
| 409 | |
| 410 | ospf_output_forward (s, OSPF_LSA_HEADER_SIZE); |
| 411 | } |
| 412 | |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 413 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 414 | /* router-LSA related functions. */ |
| 415 | /* Get router-LSA flags. */ |
| 416 | u_char |
| 417 | router_lsa_flags (struct ospf_area *area) |
| 418 | { |
| 419 | u_char flags; |
| 420 | |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 421 | flags = area->ospf->flags; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 422 | |
| 423 | /* Set virtual link flag. */ |
| 424 | if (ospf_full_virtual_nbrs (area)) |
| 425 | SET_FLAG (flags, ROUTER_LSA_VIRTUAL); |
| 426 | else |
| 427 | /* Just sanity check */ |
| 428 | UNSET_FLAG (flags, ROUTER_LSA_VIRTUAL); |
| 429 | |
| 430 | /* Set Shortcut ABR behabiour flag. */ |
| 431 | UNSET_FLAG (flags, ROUTER_LSA_SHORTCUT); |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 432 | if (area->ospf->abr_type == OSPF_ABR_SHORTCUT) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 433 | if (!OSPF_IS_AREA_BACKBONE (area)) |
| 434 | if ((area->shortcut_configured == OSPF_SHORTCUT_DEFAULT && |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 435 | area->ospf->backbone == NULL) || |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 436 | area->shortcut_configured == OSPF_SHORTCUT_ENABLE) |
| 437 | SET_FLAG (flags, ROUTER_LSA_SHORTCUT); |
| 438 | |
| 439 | /* ASBR can't exit in stub area. */ |
| 440 | if (area->external_routing == OSPF_AREA_STUB) |
paul | 942b6c1 | 2003-06-22 08:22:18 +0000 | [diff] [blame] | 441 | UNSET_FLAG (flags, ROUTER_LSA_EXTERNAL); |
| 442 | /* If ASBR set External flag */ |
| 443 | else if (IS_OSPF_ASBR (area->ospf)) |
| 444 | SET_FLAG (flags, ROUTER_LSA_EXTERNAL); |
| 445 | |
| 446 | /* Set ABR dependent flags */ |
| 447 | if (IS_OSPF_ABR (area->ospf)) |
| 448 | { |
| 449 | SET_FLAG (flags, ROUTER_LSA_BORDER); |
| 450 | #ifdef HAVE_NSSA |
| 451 | /* If Area is NSSA and we are both ABR and unconditional translator, |
paul | d4a53d5 | 2003-07-12 21:30:57 +0000 | [diff] [blame] | 452 | * set Nt bit to inform other routers. |
paul | 942b6c1 | 2003-06-22 08:22:18 +0000 | [diff] [blame] | 453 | */ |
paul | d4a53d5 | 2003-07-12 21:30:57 +0000 | [diff] [blame] | 454 | if ( (area->external_routing == OSPF_AREA_NSSA) |
| 455 | && (area->NSSATranslatorRole == OSPF_NSSA_ROLE_ALWAYS)) |
| 456 | SET_FLAG (flags, ROUTER_LSA_NT); |
paul | 942b6c1 | 2003-06-22 08:22:18 +0000 | [diff] [blame] | 457 | #endif /* HAVE_NSSA */ |
| 458 | } |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 459 | return flags; |
| 460 | } |
| 461 | |
| 462 | /* Lookup neighbor other than myself. |
| 463 | And check neighbor count, |
| 464 | Point-to-Point link must have only 1 neighbor. */ |
| 465 | struct ospf_neighbor * |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 466 | ospf_nbr_lookup_ptop (struct ospf_interface *oi) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 467 | { |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 468 | struct ospf_neighbor *nbr = NULL; |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 469 | struct route_node *rn; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 470 | |
| 471 | /* Search neighbor, there must be one of two nbrs. */ |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 472 | for (rn = route_top (oi->nbrs); rn; rn = route_next (rn)) |
| 473 | if ((nbr = rn->info)) |
| 474 | if (!IPV4_ADDR_SAME (&nbr->router_id, &oi->ospf->router_id)) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 475 | if (nbr->state == NSM_Full) |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 476 | { |
| 477 | route_unlock_node (rn); |
| 478 | break; |
| 479 | } |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 480 | |
| 481 | /* PtoP link must have only 1 neighbor. */ |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 482 | if (ospf_nbr_count (oi, 0) > 1) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 483 | zlog_warn ("Point-to-Point link has more than 1 neighobrs."); |
| 484 | |
| 485 | return nbr; |
| 486 | } |
| 487 | |
| 488 | /* Set a link information. */ |
| 489 | void |
| 490 | link_info_set (struct stream *s, struct in_addr id, |
| 491 | struct in_addr data, u_char type, u_char tos, u_int16_t cost) |
| 492 | { |
| 493 | /* TOS based routing is not supported. */ |
| 494 | stream_put_ipv4 (s, id.s_addr); /* Link ID. */ |
| 495 | stream_put_ipv4 (s, data.s_addr); /* Link Data. */ |
| 496 | stream_putc (s, type); /* Link Type. */ |
| 497 | stream_putc (s, tos); /* TOS = 0. */ |
| 498 | stream_putw (s, cost); /* Link Cost. */ |
| 499 | } |
| 500 | |
| 501 | /* Describe Point-to-Point link. */ |
| 502 | int |
| 503 | lsa_link_ptop_set (struct stream *s, struct ospf_interface *oi) |
| 504 | { |
| 505 | int links = 0; |
| 506 | struct ospf_neighbor *nbr; |
| 507 | struct in_addr id, mask; |
| 508 | |
| 509 | if (IS_DEBUG_OSPF (lsa, LSA_GENERATE)) |
| 510 | zlog_info ("LSA[Type1]: Set link Point-to-Point"); |
| 511 | |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 512 | if ((nbr = ospf_nbr_lookup_ptop (oi))) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 513 | if (nbr->state == NSM_Full) |
| 514 | { |
| 515 | /* For unnumbered point-to-point networks, the Link Data field |
| 516 | should specify the interface's MIB-II ifIndex value. */ |
| 517 | link_info_set (s, nbr->router_id, oi->address->u.prefix4, |
| 518 | LSA_LINK_TYPE_POINTOPOINT, 0, oi->output_cost); |
| 519 | links++; |
| 520 | } |
| 521 | |
| 522 | if (oi->connected->destination != NULL) |
| 523 | { |
| 524 | /* Option 1: |
| 525 | link_type = LSA_LINK_TYPE_STUB; |
| 526 | link_id = nbr->address.u.prefix4; |
| 527 | link_data.s_addr = 0xffffffff; |
| 528 | link_cost = o->output_cost; */ |
| 529 | |
| 530 | id.s_addr = oi->connected->destination->u.prefix4.s_addr; |
| 531 | mask.s_addr = 0xffffffff; |
| 532 | link_info_set (s, id, mask, LSA_LINK_TYPE_STUB, 0, oi->output_cost); |
| 533 | } |
| 534 | else |
| 535 | { |
| 536 | /* Option 2: We need to include link to a stub |
| 537 | network regardless of the state of the neighbor */ |
| 538 | masklen2ip (oi->address->prefixlen, &mask); |
| 539 | id.s_addr = oi->address->u.prefix4.s_addr & mask.s_addr; |
| 540 | link_info_set (s, id, mask, LSA_LINK_TYPE_STUB, 0, oi->output_cost); |
| 541 | } |
| 542 | links++; |
| 543 | |
| 544 | return links; |
| 545 | } |
| 546 | |
| 547 | /* Describe Broadcast Link. */ |
| 548 | int |
| 549 | lsa_link_broadcast_set (struct stream *s, struct ospf_interface *oi) |
| 550 | { |
| 551 | struct ospf_neighbor *dr; |
| 552 | struct in_addr id, mask; |
| 553 | |
| 554 | /* Describe Type 3 Link. */ |
| 555 | if (oi->state == ISM_Waiting) |
| 556 | { |
| 557 | masklen2ip (oi->address->prefixlen, &mask); |
| 558 | id.s_addr = oi->address->u.prefix4.s_addr & mask.s_addr; |
| 559 | link_info_set (s, id, mask, LSA_LINK_TYPE_STUB, 0, oi->output_cost); |
| 560 | return 1; |
| 561 | } |
| 562 | |
| 563 | dr = ospf_nbr_lookup_by_addr (oi->nbrs, &DR (oi)); |
| 564 | /* Describe Type 2 link. */ |
| 565 | if (dr && (dr->state == NSM_Full || |
| 566 | IPV4_ADDR_SAME (&oi->address->u.prefix4, &DR (oi))) && |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 567 | ospf_nbr_count (oi, NSM_Full) > 0) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 568 | { |
| 569 | link_info_set (s, DR (oi), oi->address->u.prefix4, |
| 570 | LSA_LINK_TYPE_TRANSIT, 0, oi->output_cost); |
| 571 | } |
| 572 | /* Describe type 3 link. */ |
| 573 | else |
| 574 | { |
| 575 | masklen2ip (oi->address->prefixlen, &mask); |
| 576 | id.s_addr = oi->address->u.prefix4.s_addr & mask.s_addr; |
| 577 | link_info_set (s, id, mask, LSA_LINK_TYPE_STUB, 0, oi->output_cost); |
| 578 | } |
| 579 | return 1; |
| 580 | } |
| 581 | |
| 582 | int |
| 583 | lsa_link_loopback_set (struct stream *s, struct ospf_interface *oi) |
| 584 | { |
| 585 | struct in_addr id, mask; |
| 586 | |
| 587 | /* Describe Type 3 Link. */ |
| 588 | if (oi->state != ISM_Loopback) |
| 589 | return 0; |
| 590 | |
| 591 | mask.s_addr = 0xffffffff; |
| 592 | id.s_addr = oi->address->u.prefix4.s_addr; |
| 593 | link_info_set (s, id, mask, LSA_LINK_TYPE_STUB, 0, oi->output_cost); |
| 594 | return 1; |
| 595 | } |
| 596 | |
| 597 | /* Describe Virtual Link. */ |
| 598 | int |
| 599 | lsa_link_virtuallink_set (struct stream *s, struct ospf_interface *oi) |
| 600 | { |
| 601 | struct ospf_neighbor *nbr; |
| 602 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 603 | if (oi->state == ISM_PointToPoint) |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 604 | if ((nbr = ospf_nbr_lookup_ptop (oi))) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 605 | if (nbr->state == NSM_Full) |
| 606 | { |
| 607 | link_info_set (s, nbr->router_id, oi->address->u.prefix4, |
| 608 | LSA_LINK_TYPE_VIRTUALLINK, 0, oi->output_cost); |
| 609 | return 1; |
| 610 | } |
| 611 | |
| 612 | return 0; |
| 613 | } |
| 614 | |
| 615 | #define lsa_link_nbma_set(S,O) lsa_link_broadcast_set (S, O) |
| 616 | |
paul | 7afa08d | 2002-12-13 20:59:45 +0000 | [diff] [blame] | 617 | /* this function add for support point-to-multipoint ,see rfc2328 |
| 618 | 12.4.1.4.*/ |
| 619 | /* from "edward rrr" <edward_rrr@hotmail.com> |
| 620 | http://marc.theaimsgroup.com/?l=zebra&m=100739222210507&w=2 */ |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 621 | int |
| 622 | lsa_link_ptomp_set (struct stream *s, struct ospf_interface *oi) |
paul | 7afa08d | 2002-12-13 20:59:45 +0000 | [diff] [blame] | 623 | { |
| 624 | int links = 0; |
| 625 | struct route_node *rn; |
| 626 | struct ospf_neighbor *nbr = NULL; |
| 627 | struct in_addr id, mask; |
| 628 | |
| 629 | mask.s_addr = 0xffffffff; |
| 630 | id.s_addr = oi->address->u.prefix4.s_addr; |
| 631 | link_info_set (s, id, mask, LSA_LINK_TYPE_STUB, 0, 0); |
| 632 | links++; |
| 633 | |
paul | 1cc8f76 | 2003-04-05 19:34:32 +0000 | [diff] [blame] | 634 | if (IS_DEBUG_OSPF (lsa, LSA_GENERATE)) |
| 635 | zlog_info ("PointToMultipoint: running ptomultip_set"); |
paul | 7afa08d | 2002-12-13 20:59:45 +0000 | [diff] [blame] | 636 | |
| 637 | /* Search neighbor, */ |
| 638 | for (rn = route_top (oi->nbrs); rn; rn = route_next (rn)) |
| 639 | if ((nbr = rn->info) != NULL) |
| 640 | /* Ignore myself. */ |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 641 | if (!IPV4_ADDR_SAME (&nbr->router_id, &oi->ospf->router_id)) |
paul | 7afa08d | 2002-12-13 20:59:45 +0000 | [diff] [blame] | 642 | if (nbr->state == NSM_Full) |
| 643 | |
| 644 | { |
paul | 7afa08d | 2002-12-13 20:59:45 +0000 | [diff] [blame] | 645 | link_info_set (s, nbr->router_id, oi->address->u.prefix4, |
| 646 | LSA_LINK_TYPE_POINTOPOINT, 0, oi->output_cost); |
| 647 | links++; |
paul | 1cc8f76 | 2003-04-05 19:34:32 +0000 | [diff] [blame] | 648 | if (IS_DEBUG_OSPF (lsa, LSA_GENERATE)) |
| 649 | zlog_info ("PointToMultipoint: set link to %s", |
| 650 | inet_ntoa(oi->address->u.prefix4)); |
paul | 7afa08d | 2002-12-13 20:59:45 +0000 | [diff] [blame] | 651 | } |
| 652 | |
| 653 | return links; |
paul | 7afa08d | 2002-12-13 20:59:45 +0000 | [diff] [blame] | 654 | } |
| 655 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 656 | /* Set router-LSA link information. */ |
| 657 | int |
| 658 | router_lsa_link_set (struct stream *s, struct ospf_area *area) |
| 659 | { |
| 660 | listnode node; |
| 661 | int links = 0; |
| 662 | |
| 663 | for (node = listhead (area->oiflist); node; node = nextnode (node)) |
| 664 | { |
| 665 | struct ospf_interface *oi = node->data; |
| 666 | struct interface *ifp = oi->ifp; |
| 667 | |
| 668 | /* Check interface is up, OSPF is enable. */ |
paul | 2e3b2e4 | 2002-12-13 21:03:13 +0000 | [diff] [blame] | 669 | if (if_is_operative (ifp)) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 670 | { |
| 671 | if (oi->state != ISM_Down) |
| 672 | { |
| 673 | /* Describe each link. */ |
| 674 | switch (oi->type) |
| 675 | { |
| 676 | case OSPF_IFTYPE_POINTOPOINT: |
| 677 | links += lsa_link_ptop_set (s, oi); |
| 678 | break; |
| 679 | case OSPF_IFTYPE_BROADCAST: |
| 680 | links += lsa_link_broadcast_set (s, oi); |
| 681 | break; |
| 682 | case OSPF_IFTYPE_NBMA: |
| 683 | links += lsa_link_nbma_set (s, oi); |
| 684 | break; |
| 685 | case OSPF_IFTYPE_POINTOMULTIPOINT: |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 686 | links += lsa_link_ptomp_set (s, oi); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 687 | break; |
| 688 | case OSPF_IFTYPE_VIRTUALLINK: |
| 689 | links += lsa_link_virtuallink_set (s, oi); |
| 690 | break; |
| 691 | case OSPF_IFTYPE_LOOPBACK: |
| 692 | links += lsa_link_loopback_set (s, oi); |
| 693 | } |
| 694 | } |
| 695 | } |
| 696 | } |
| 697 | |
| 698 | return links; |
| 699 | } |
| 700 | |
| 701 | /* Set router-LSA body. */ |
| 702 | void |
| 703 | ospf_router_lsa_body_set (struct stream *s, struct ospf_area *area) |
| 704 | { |
| 705 | unsigned long putp; |
| 706 | u_int16_t cnt; |
| 707 | |
| 708 | /* Set flags. */ |
| 709 | stream_putc (s, router_lsa_flags (area)); |
| 710 | |
| 711 | /* Set Zero fields. */ |
| 712 | stream_putc (s, 0); |
| 713 | |
| 714 | /* Keep pointer to # links. */ |
| 715 | putp = s->putp; |
| 716 | |
| 717 | /* Forward word */ |
| 718 | stream_putw(s, 0); |
| 719 | |
| 720 | /* Set all link information. */ |
| 721 | cnt = router_lsa_link_set (s, area); |
| 722 | |
| 723 | /* Set # of links here. */ |
| 724 | stream_putw_at (s, putp, cnt); |
| 725 | } |
| 726 | |
| 727 | /* Create new router-LSA. */ |
| 728 | struct ospf_lsa * |
| 729 | ospf_router_lsa_new (struct ospf_area *area) |
| 730 | { |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 731 | struct ospf *ospf = area->ospf; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 732 | struct stream *s; |
| 733 | struct lsa_header *lsah; |
| 734 | struct ospf_lsa *new; |
| 735 | int length; |
| 736 | |
| 737 | if (IS_DEBUG_OSPF (lsa, LSA_GENERATE)) |
| 738 | zlog_info ("LSA[Type1]: Create router-LSA instance"); |
| 739 | |
| 740 | /* Create a stream for LSA. */ |
| 741 | s = stream_new (OSPF_MAX_LSA_SIZE); |
| 742 | lsah = (struct lsa_header *) STREAM_DATA (s); |
| 743 | |
| 744 | #ifdef HAVE_NSSA |
| 745 | /* Set LSA common header fields. */ |
paul | d4a53d5 | 2003-07-12 21:30:57 +0000 | [diff] [blame] | 746 | lsa_header_set (s, LSA_OPTIONS_GET (area) | LSA_OPTIONS_NSSA_GET (area), |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 747 | #else /* ! HAVE_NSSA */ |
| 748 | /* Set LSA common header fields. */ |
| 749 | lsa_header_set (s, LSA_OPTIONS_GET (area), |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 750 | #endif /* HAVE_NSSA */ |
paul | d4a53d5 | 2003-07-12 21:30:57 +0000 | [diff] [blame] | 751 | OSPF_ROUTER_LSA, ospf->router_id, ospf->router_id); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 752 | |
| 753 | /* Set router-LSA body fields. */ |
| 754 | ospf_router_lsa_body_set (s, area); |
| 755 | |
| 756 | /* Set length. */ |
| 757 | length = stream_get_endp (s); |
| 758 | lsah->length = htons (length); |
| 759 | |
| 760 | /* Now, create OSPF LSA instance. */ |
| 761 | new = ospf_lsa_new (); |
| 762 | new->area = area; |
| 763 | SET_FLAG (new->flags, OSPF_LSA_SELF); |
| 764 | |
| 765 | /* Copy LSA data to store, discard stream. */ |
| 766 | new->data = ospf_lsa_data_new (length); |
| 767 | memcpy (new->data, lsah, length); |
| 768 | stream_free (s); |
| 769 | |
| 770 | return new; |
| 771 | } |
| 772 | |
| 773 | /* Originate Router-LSA. */ |
| 774 | struct ospf_lsa * |
| 775 | ospf_router_lsa_originate (struct ospf_area *area) |
| 776 | { |
| 777 | struct ospf_lsa *new; |
| 778 | |
| 779 | /* Create new router-LSA instance. */ |
| 780 | new = ospf_router_lsa_new (area); |
| 781 | |
| 782 | /* Sanity check. */ |
| 783 | if (new->data->adv_router.s_addr == 0) |
| 784 | { |
| 785 | if (IS_DEBUG_OSPF_EVENT) |
| 786 | zlog_info ("LSA[Type1]: AdvRouter is 0, discard"); |
| 787 | ospf_lsa_discard (new); |
| 788 | return NULL; |
| 789 | } |
| 790 | |
| 791 | /* Install LSA to LSDB. */ |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 792 | new = ospf_lsa_install (area->ospf, NULL, new); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 793 | |
| 794 | /* Update LSA origination count. */ |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 795 | area->ospf->lsa_originate_count++; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 796 | |
| 797 | /* Flooding new LSA through area. */ |
| 798 | ospf_flood_through_area (area, NULL, new); |
| 799 | |
| 800 | if (IS_DEBUG_OSPF (lsa, LSA_GENERATE)) |
| 801 | { |
| 802 | zlog_info ("LSA[Type%d:%s]: Originate router-LSA %p", |
| 803 | new->data->type, inet_ntoa (new->data->id), new); |
| 804 | ospf_lsa_header_dump (new->data); |
| 805 | } |
| 806 | |
| 807 | return new; |
| 808 | } |
| 809 | |
| 810 | /* Refresh router-LSA. */ |
| 811 | struct ospf_lsa * |
| 812 | ospf_router_lsa_refresh (struct ospf_lsa *lsa) |
| 813 | { |
| 814 | struct ospf_area *area = lsa->area; |
| 815 | struct ospf_lsa *new; |
| 816 | |
| 817 | /* Sanity check. */ |
| 818 | assert (lsa->data); |
| 819 | |
| 820 | /* Delete LSA from neighbor retransmit-list. */ |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 821 | ospf_ls_retransmit_delete_nbr_area (area, lsa); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 822 | |
| 823 | /* Create new router-LSA instance. */ |
| 824 | new = ospf_router_lsa_new (area); |
| 825 | new->data->ls_seqnum = lsa_seqnum_increment (lsa); |
| 826 | |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 827 | ospf_lsa_install (area->ospf, NULL, new); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 828 | |
| 829 | /* Flood LSA through area. */ |
| 830 | ospf_flood_through_area (area, NULL, new); |
| 831 | |
| 832 | /* Debug logging. */ |
| 833 | if (IS_DEBUG_OSPF (lsa, LSA_GENERATE)) |
| 834 | { |
| 835 | zlog_info ("LSA[Type%d:%s]: router-LSA refresh", |
| 836 | new->data->type, inet_ntoa (new->data->id)); |
| 837 | ospf_lsa_header_dump (new->data); |
| 838 | } |
| 839 | |
| 840 | return NULL; |
| 841 | } |
| 842 | |
| 843 | int |
| 844 | ospf_router_lsa_timer (struct thread *t) |
| 845 | { |
| 846 | struct ospf_area *area; |
| 847 | |
| 848 | if (IS_DEBUG_OSPF_EVENT) |
| 849 | zlog_info ("Timer[router-LSA]: (router-LSA Refresh expire)"); |
| 850 | |
| 851 | area = THREAD_ARG (t); |
| 852 | area->t_router_lsa_self = NULL; |
| 853 | |
| 854 | /* Now refresh router-LSA. */ |
| 855 | if (area->router_lsa_self) |
| 856 | ospf_router_lsa_refresh (area->router_lsa_self); |
| 857 | /* Newly originate router-LSA. */ |
| 858 | else |
| 859 | ospf_router_lsa_originate (area); |
| 860 | |
| 861 | return 0; |
| 862 | } |
| 863 | |
| 864 | void |
| 865 | ospf_router_lsa_timer_add (struct ospf_area *area) |
| 866 | { |
| 867 | /* Keep area's self-originated router-LSA. */ |
| 868 | struct ospf_lsa *lsa = area->router_lsa_self; |
| 869 | |
| 870 | /* Cancel previously scheduled router-LSA timer. */ |
| 871 | if (area->t_router_lsa_self) |
| 872 | if (IS_DEBUG_OSPF (lsa, LSA_GENERATE)) |
| 873 | zlog_info ("LSA[Type1]: Cancel previous router-LSA timer"); |
| 874 | |
| 875 | OSPF_TIMER_OFF (area->t_router_lsa_self); |
| 876 | |
| 877 | /* If router-LSA is originated previously, check the interval time. */ |
| 878 | if (lsa) |
| 879 | { |
| 880 | int delay; |
| 881 | if ((delay = ospf_lsa_refresh_delay (lsa)) > 0) |
| 882 | { |
| 883 | OSPF_AREA_TIMER_ON (area->t_router_lsa_self, |
| 884 | ospf_router_lsa_timer, delay); |
| 885 | return; |
| 886 | } |
| 887 | } |
| 888 | |
| 889 | if (IS_DEBUG_OSPF (lsa, LSA_GENERATE)) |
| 890 | zlog_info ("LSA[Type1]: Scheduling router-LSA origination right away"); |
| 891 | |
| 892 | /* Immediately refresh router-LSA. */ |
| 893 | OSPF_AREA_TIMER_ON (area->t_router_lsa_self, ospf_router_lsa_timer, 0); |
| 894 | } |
| 895 | |
| 896 | int |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 897 | ospf_router_lsa_update_timer (struct thread *thread) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 898 | { |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 899 | struct ospf *ospf = THREAD_ARG (thread); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 900 | listnode node; |
| 901 | |
| 902 | if (IS_DEBUG_OSPF (lsa, LSA_GENERATE)) |
| 903 | zlog_info ("Timer[router-LSA Update]: (timer expire)"); |
| 904 | |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 905 | ospf->t_router_lsa_update = NULL; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 906 | |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 907 | for (node = listhead (ospf->areas); node; nextnode (node)) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 908 | { |
| 909 | struct ospf_area *area = getdata (node); |
| 910 | struct ospf_lsa *lsa = area->router_lsa_self; |
| 911 | struct router_lsa *rl; |
| 912 | char *area_str; |
| 913 | |
| 914 | /* Keep Area ID string. */ |
| 915 | area_str = AREA_NAME (area); |
| 916 | |
| 917 | /* If LSA not exist in this Area, originate new. */ |
| 918 | if (lsa == NULL) |
| 919 | { |
| 920 | if (IS_DEBUG_OSPF (lsa, LSA_GENERATE)) |
| 921 | zlog_info("LSA[Type1]: Create router-LSA for Area %s", area_str); |
| 922 | |
| 923 | ospf_router_lsa_originate (area); |
| 924 | } |
| 925 | /* If router-ID is changed, Link ID must change. |
| 926 | First flush old LSA, then originate new. */ |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 927 | else if (!IPV4_ADDR_SAME (&lsa->data->id, &ospf->router_id)) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 928 | { |
| 929 | if (IS_DEBUG_OSPF (lsa, LSA_GENERATE)) |
| 930 | zlog_info("LSA[Type%d:%s]: Refresh router-LSA for Area %s", |
| 931 | lsa->data->type, inet_ntoa (lsa->data->id), area_str); |
| 932 | ospf_lsa_flush_area (lsa, area); |
| 933 | ospf_lsa_unlock (area->router_lsa_self); |
| 934 | area->router_lsa_self = NULL; |
| 935 | |
| 936 | /* Refresh router-LSA, (not install) and flood through area. */ |
| 937 | ospf_router_lsa_timer_add (area); |
| 938 | } |
| 939 | else |
| 940 | { |
| 941 | rl = (struct router_lsa *) lsa->data; |
| 942 | /* Refresh router-LSA, (not install) and flood through area. */ |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 943 | if (rl->flags != ospf->flags) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 944 | ospf_router_lsa_timer_add (area); |
| 945 | } |
| 946 | } |
| 947 | |
| 948 | return 0; |
| 949 | } |
| 950 | |
| 951 | |
| 952 | /* network-LSA related functions. */ |
| 953 | /* Originate Network-LSA. */ |
| 954 | void |
| 955 | ospf_network_lsa_body_set (struct stream *s, struct ospf_interface *oi) |
| 956 | { |
| 957 | struct in_addr mask; |
| 958 | struct route_node *rn; |
| 959 | struct ospf_neighbor *nbr; |
| 960 | |
| 961 | masklen2ip (oi->address->prefixlen, &mask); |
| 962 | stream_put_ipv4 (s, mask.s_addr); |
| 963 | |
| 964 | /* The network-LSA lists those routers that are fully adjacent to |
| 965 | the Designated Router; each fully adjacent router is identified by |
| 966 | its OSPF Router ID. The Designated Router includes itself in this |
| 967 | list. RFC2328, Section 12.4.2 */ |
| 968 | |
| 969 | for (rn = route_top (oi->nbrs); rn; rn = route_next (rn)) |
| 970 | if ((nbr = rn->info) != NULL) |
| 971 | if (nbr->state == NSM_Full || nbr == oi->nbr_self) |
| 972 | stream_put_ipv4 (s, nbr->router_id.s_addr); |
| 973 | } |
| 974 | |
| 975 | struct ospf_lsa * |
| 976 | ospf_network_lsa_new (struct ospf_interface *oi) |
| 977 | { |
| 978 | struct stream *s; |
| 979 | struct ospf_lsa *new; |
| 980 | struct lsa_header *lsah; |
| 981 | int length; |
| 982 | |
| 983 | /* If there are no neighbours on this network (the net is stub), |
| 984 | the router does not originate network-LSA (see RFC 12.4.2) */ |
| 985 | if (oi->full_nbrs == 0) |
| 986 | return NULL; |
| 987 | |
| 988 | if (IS_DEBUG_OSPF (lsa, LSA_GENERATE)) |
| 989 | zlog_info ("LSA[Type2]: Create network-LSA instance"); |
| 990 | |
| 991 | /* Create new stream for LSA. */ |
| 992 | s = stream_new (OSPF_MAX_LSA_SIZE); |
| 993 | lsah = (struct lsa_header *) STREAM_DATA (s); |
| 994 | |
| 995 | lsa_header_set (s, (OPTIONS (oi) | LSA_OPTIONS_GET (oi->area)), |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 996 | OSPF_NETWORK_LSA, DR (oi), oi->ospf->router_id); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 997 | |
| 998 | /* Set network-LSA body fields. */ |
| 999 | ospf_network_lsa_body_set (s, oi); |
| 1000 | |
| 1001 | /* Set length. */ |
| 1002 | length = stream_get_endp (s); |
| 1003 | lsah->length = htons (length); |
| 1004 | |
| 1005 | /* Create OSPF LSA instance. */ |
| 1006 | new = ospf_lsa_new (); |
| 1007 | new->area = oi->area; |
| 1008 | SET_FLAG (new->flags, OSPF_LSA_SELF); |
| 1009 | |
| 1010 | /* Copy LSA to store. */ |
| 1011 | new->data = ospf_lsa_data_new (length); |
| 1012 | memcpy (new->data, lsah, length); |
| 1013 | stream_free (s); |
| 1014 | |
| 1015 | return new; |
| 1016 | } |
| 1017 | |
| 1018 | /* Originate network-LSA. */ |
| 1019 | struct ospf_lsa * |
| 1020 | ospf_network_lsa_originate (struct ospf_interface *oi) |
| 1021 | { |
| 1022 | struct ospf_lsa *new; |
| 1023 | |
| 1024 | /* Create new network-LSA instance. */ |
| 1025 | new = ospf_network_lsa_new (oi); |
| 1026 | if (new == NULL) |
| 1027 | return NULL; |
| 1028 | |
| 1029 | /* Install LSA to LSDB. */ |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 1030 | new = ospf_lsa_install (oi->ospf, oi, new); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1031 | |
| 1032 | /* Update LSA origination count. */ |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 1033 | oi->ospf->lsa_originate_count++; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1034 | |
| 1035 | /* Flooding new LSA through area. */ |
| 1036 | ospf_flood_through_area (oi->area, NULL, new); |
| 1037 | |
| 1038 | if (IS_DEBUG_OSPF (lsa, LSA_GENERATE)) |
| 1039 | { |
| 1040 | zlog_info ("LSA[Type%d:%s]: Originate network-LSA %p", |
| 1041 | new->data->type, inet_ntoa (new->data->id), new); |
| 1042 | ospf_lsa_header_dump (new->data); |
| 1043 | } |
| 1044 | |
| 1045 | return new; |
| 1046 | } |
| 1047 | |
| 1048 | int |
| 1049 | ospf_network_lsa_refresh (struct ospf_lsa *lsa, struct ospf_interface *oi) |
| 1050 | { |
| 1051 | struct ospf_area *area = lsa->area; |
| 1052 | struct ospf_lsa *new; |
| 1053 | |
| 1054 | assert (lsa->data); |
| 1055 | |
| 1056 | /* Delete LSA from neighbor retransmit-list. */ |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 1057 | ospf_ls_retransmit_delete_nbr_area (area, lsa); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1058 | |
| 1059 | /* Create new network-LSA instance. */ |
| 1060 | new = ospf_network_lsa_new (oi); |
| 1061 | if (new == NULL) |
| 1062 | return -1; |
| 1063 | new->data->ls_seqnum = lsa_seqnum_increment (lsa); |
| 1064 | |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 1065 | ospf_lsa_install (area->ospf, oi, new); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1066 | |
| 1067 | /* Flood LSA through aera. */ |
| 1068 | ospf_flood_through_area (area, NULL, new); |
| 1069 | |
| 1070 | if (IS_DEBUG_OSPF (lsa, LSA_GENERATE)) |
| 1071 | { |
| 1072 | zlog_info ("LSA[Type%d:%s]: network-LSA refresh", |
| 1073 | new->data->type, inet_ntoa (new->data->id)); |
| 1074 | ospf_lsa_header_dump (new->data); |
| 1075 | } |
| 1076 | |
| 1077 | return 0; |
| 1078 | } |
| 1079 | |
| 1080 | int |
| 1081 | ospf_network_lsa_refresh_timer (struct thread *t) |
| 1082 | { |
| 1083 | struct ospf_interface *oi; |
| 1084 | |
| 1085 | oi = THREAD_ARG (t); |
| 1086 | oi->t_network_lsa_self = NULL; |
| 1087 | |
| 1088 | if (oi->network_lsa_self) |
| 1089 | /* Now refresh network-LSA. */ |
| 1090 | ospf_network_lsa_refresh (oi->network_lsa_self, oi); |
| 1091 | else |
| 1092 | /* Newly create network-LSA. */ |
| 1093 | ospf_network_lsa_originate (oi); |
| 1094 | |
| 1095 | return 0; |
| 1096 | } |
| 1097 | |
| 1098 | void |
| 1099 | ospf_network_lsa_timer_add (struct ospf_interface *oi) |
| 1100 | { |
| 1101 | /* Keep interface's self-originated network-LSA. */ |
| 1102 | struct ospf_lsa *lsa = oi->network_lsa_self; |
| 1103 | |
| 1104 | /* Cancel previously schedules network-LSA timer. */ |
| 1105 | if (oi->t_network_lsa_self) |
| 1106 | if (IS_DEBUG_OSPF (lsa, LSA_GENERATE)) |
| 1107 | zlog_info ("LSA[Type2]: Cancel previous network-LSA timer"); |
| 1108 | OSPF_TIMER_OFF (oi->t_network_lsa_self); |
| 1109 | |
| 1110 | /* If network-LSA is originated previously, check the interval time. */ |
| 1111 | if (lsa) |
| 1112 | { |
| 1113 | int delay; |
| 1114 | if ((delay = ospf_lsa_refresh_delay (lsa)) > 0) |
| 1115 | { |
| 1116 | oi->t_network_lsa_self = |
| 1117 | thread_add_timer (master, ospf_network_lsa_refresh_timer, |
| 1118 | oi, delay); |
| 1119 | return; |
| 1120 | } |
| 1121 | } |
| 1122 | |
| 1123 | if (IS_DEBUG_OSPF (lsa, LSA_GENERATE)) |
| 1124 | zlog_info ("Scheduling network-LSA origination right away"); |
| 1125 | |
| 1126 | /* Immediately refresh network-LSA. */ |
| 1127 | oi->t_network_lsa_self = |
| 1128 | thread_add_event (master, ospf_network_lsa_refresh_timer, oi, 0); |
| 1129 | } |
| 1130 | |
| 1131 | |
| 1132 | void |
| 1133 | stream_put_ospf_metric (struct stream *s, u_int32_t metric_value) |
| 1134 | { |
| 1135 | u_int32_t metric; |
| 1136 | char *mp; |
| 1137 | |
| 1138 | /* Put 0 metric. TOS metric is not supported. */ |
| 1139 | metric = htonl (metric_value); |
| 1140 | mp = (char *) &metric; |
| 1141 | mp++; |
| 1142 | stream_put (s, mp, 3); |
| 1143 | } |
| 1144 | |
| 1145 | /* summary-LSA related functions. */ |
| 1146 | void |
| 1147 | ospf_summary_lsa_body_set (struct stream *s, struct prefix *p, |
| 1148 | u_int32_t metric) |
| 1149 | { |
| 1150 | struct in_addr mask; |
| 1151 | |
| 1152 | masklen2ip (p->prefixlen, &mask); |
| 1153 | |
| 1154 | /* Put Network Mask. */ |
| 1155 | stream_put_ipv4 (s, mask.s_addr); |
| 1156 | |
| 1157 | /* Set # TOS. */ |
| 1158 | stream_putc (s, (u_char) 0); |
| 1159 | |
| 1160 | /* Set metric. */ |
| 1161 | stream_put_ospf_metric (s, metric); |
| 1162 | } |
| 1163 | |
| 1164 | struct ospf_lsa * |
| 1165 | ospf_summary_lsa_new (struct ospf_area *area, struct prefix *p, |
| 1166 | u_int32_t metric, struct in_addr id) |
| 1167 | { |
| 1168 | struct stream *s; |
| 1169 | struct ospf_lsa *new; |
| 1170 | struct lsa_header *lsah; |
| 1171 | int length; |
| 1172 | |
| 1173 | if (IS_DEBUG_OSPF (lsa, LSA_GENERATE)) |
| 1174 | zlog_info ("LSA[Type3]: Create summary-LSA instance"); |
| 1175 | |
| 1176 | /* Create new stream for LSA. */ |
| 1177 | s = stream_new (OSPF_MAX_LSA_SIZE); |
| 1178 | lsah = (struct lsa_header *) STREAM_DATA (s); |
| 1179 | |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 1180 | lsa_header_set (s, LSA_OPTIONS_GET (area), OSPF_SUMMARY_LSA, |
| 1181 | id, area->ospf->router_id); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1182 | |
| 1183 | /* Set summary-LSA body fields. */ |
| 1184 | ospf_summary_lsa_body_set (s, p, metric); |
| 1185 | |
| 1186 | /* Set length. */ |
| 1187 | length = stream_get_endp (s); |
| 1188 | lsah->length = htons (length); |
| 1189 | |
| 1190 | /* Create OSPF LSA instance. */ |
| 1191 | new = ospf_lsa_new (); |
| 1192 | new->area = area; |
| 1193 | SET_FLAG (new->flags, OSPF_LSA_SELF); |
| 1194 | |
| 1195 | /* Copy LSA to store. */ |
| 1196 | new->data = ospf_lsa_data_new (length); |
| 1197 | memcpy (new->data, lsah, length); |
| 1198 | stream_free (s); |
| 1199 | |
| 1200 | return new; |
| 1201 | } |
| 1202 | |
| 1203 | /* Originate Summary-LSA. */ |
| 1204 | struct ospf_lsa * |
| 1205 | ospf_summary_lsa_originate (struct prefix_ipv4 *p, u_int32_t metric, |
| 1206 | struct ospf_area *area) |
| 1207 | { |
| 1208 | struct ospf_lsa *new; |
| 1209 | struct in_addr id; |
| 1210 | |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 1211 | id = ospf_lsa_unique_id (area->ospf, area->lsdb, OSPF_SUMMARY_LSA, p); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1212 | |
| 1213 | /* Create new summary-LSA instance. */ |
| 1214 | new = ospf_summary_lsa_new (area, (struct prefix *) p, metric, id); |
| 1215 | |
| 1216 | /* Instlal LSA to LSDB. */ |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 1217 | new = ospf_lsa_install (area->ospf, NULL, new); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1218 | |
| 1219 | /* Update LSA origination count. */ |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 1220 | area->ospf->lsa_originate_count++; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1221 | |
| 1222 | /* Flooding new LSA through area. */ |
| 1223 | ospf_flood_through_area (area, NULL, new); |
| 1224 | |
| 1225 | if (IS_DEBUG_OSPF (lsa, LSA_GENERATE)) |
| 1226 | { |
| 1227 | zlog_info ("LSA[Type%d:%s]: Originate summary-LSA %p", |
| 1228 | new->data->type, inet_ntoa (new->data->id), new); |
| 1229 | ospf_lsa_header_dump (new->data); |
| 1230 | } |
| 1231 | |
| 1232 | return new; |
| 1233 | } |
| 1234 | |
| 1235 | struct ospf_lsa* |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 1236 | ospf_summary_lsa_refresh (struct ospf *ospf, struct ospf_lsa *lsa) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1237 | { |
| 1238 | struct ospf_lsa *new; |
| 1239 | struct summary_lsa *sl; |
| 1240 | struct prefix p; |
| 1241 | |
| 1242 | /* Sanity check. */ |
| 1243 | assert (lsa->data); |
| 1244 | |
| 1245 | sl = (struct summary_lsa *)lsa->data; |
| 1246 | p.prefixlen = ip_masklen (sl->mask); |
| 1247 | new = ospf_summary_lsa_new (lsa->area, &p, GET_METRIC (sl->metric), |
| 1248 | sl->header.id); |
| 1249 | |
| 1250 | new->data->ls_seqnum = lsa_seqnum_increment (lsa); |
| 1251 | |
| 1252 | /* Re-calculate checksum. */ |
| 1253 | ospf_lsa_checksum (new->data); |
| 1254 | |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 1255 | ospf_lsa_install (ospf, NULL, new); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1256 | |
| 1257 | /* Flood LSA through AS. */ |
| 1258 | ospf_flood_through_area (new->area, NULL, new); |
| 1259 | |
| 1260 | /* Debug logging. */ |
| 1261 | if (IS_DEBUG_OSPF (lsa, LSA_GENERATE)) |
| 1262 | { |
| 1263 | zlog_info ("LSA[Type%d:%s]: summary-LSA refresh", |
| 1264 | new->data->type, inet_ntoa (new->data->id)); |
| 1265 | ospf_lsa_header_dump (new->data); |
| 1266 | } |
| 1267 | |
| 1268 | return new; |
| 1269 | } |
| 1270 | |
| 1271 | |
| 1272 | /* summary-ASBR-LSA related functions. */ |
| 1273 | void |
| 1274 | ospf_summary_asbr_lsa_body_set (struct stream *s, struct prefix *p, |
| 1275 | u_int32_t metric) |
| 1276 | { |
| 1277 | struct in_addr mask; |
| 1278 | |
| 1279 | masklen2ip (p->prefixlen, &mask); |
| 1280 | |
| 1281 | /* Put Network Mask. */ |
| 1282 | stream_put_ipv4 (s, mask.s_addr); |
| 1283 | |
| 1284 | /* Set # TOS. */ |
| 1285 | stream_putc (s, (u_char) 0); |
| 1286 | |
| 1287 | /* Set metric. */ |
| 1288 | stream_put_ospf_metric (s, metric); |
| 1289 | } |
| 1290 | |
| 1291 | struct ospf_lsa * |
| 1292 | ospf_summary_asbr_lsa_new (struct ospf_area *area, struct prefix *p, |
| 1293 | u_int32_t metric, struct in_addr id) |
| 1294 | { |
| 1295 | struct stream *s; |
| 1296 | struct ospf_lsa *new; |
| 1297 | struct lsa_header *lsah; |
| 1298 | int length; |
| 1299 | |
| 1300 | if (IS_DEBUG_OSPF (lsa, LSA_GENERATE)) |
| 1301 | zlog_info ("LSA[Type3]: Create summary-LSA instance"); |
| 1302 | |
| 1303 | /* Create new stream for LSA. */ |
| 1304 | s = stream_new (OSPF_MAX_LSA_SIZE); |
| 1305 | lsah = (struct lsa_header *) STREAM_DATA (s); |
| 1306 | |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 1307 | lsa_header_set (s, LSA_OPTIONS_GET (area), OSPF_ASBR_SUMMARY_LSA, |
| 1308 | id, area->ospf->router_id); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1309 | |
| 1310 | /* Set summary-LSA body fields. */ |
| 1311 | ospf_summary_asbr_lsa_body_set (s, p, metric); |
| 1312 | |
| 1313 | /* Set length. */ |
| 1314 | length = stream_get_endp (s); |
| 1315 | lsah->length = htons (length); |
| 1316 | |
| 1317 | /* Create OSPF LSA instance. */ |
| 1318 | new = ospf_lsa_new (); |
| 1319 | new->area = area; |
| 1320 | SET_FLAG (new->flags, OSPF_LSA_SELF); |
| 1321 | |
| 1322 | /* Copy LSA to store. */ |
| 1323 | new->data = ospf_lsa_data_new (length); |
| 1324 | memcpy (new->data, lsah, length); |
| 1325 | stream_free (s); |
| 1326 | |
| 1327 | return new; |
| 1328 | } |
| 1329 | |
| 1330 | /* Originate summary-ASBR-LSA. */ |
| 1331 | struct ospf_lsa * |
| 1332 | ospf_summary_asbr_lsa_originate (struct prefix_ipv4 *p, u_int32_t metric, |
| 1333 | struct ospf_area *area) |
| 1334 | { |
| 1335 | struct ospf_lsa *new; |
| 1336 | struct in_addr id; |
| 1337 | |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 1338 | id = ospf_lsa_unique_id (area->ospf, area->lsdb, OSPF_ASBR_SUMMARY_LSA, p); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1339 | |
| 1340 | /* Create new summary-LSA instance. */ |
| 1341 | new = ospf_summary_asbr_lsa_new (area, (struct prefix *) p, metric, id); |
| 1342 | |
| 1343 | /* Install LSA to LSDB. */ |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 1344 | new = ospf_lsa_install (area->ospf, NULL, new); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1345 | |
| 1346 | /* Update LSA origination count. */ |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 1347 | area->ospf->lsa_originate_count++; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1348 | |
| 1349 | /* Flooding new LSA through area. */ |
| 1350 | ospf_flood_through_area (area, NULL, new); |
| 1351 | |
| 1352 | if (IS_DEBUG_OSPF (lsa, LSA_GENERATE)) |
| 1353 | { |
| 1354 | zlog_info ("LSA[Type%d:%s]: Originate summary-ASBR-LSA %p", |
| 1355 | new->data->type, inet_ntoa (new->data->id), new); |
| 1356 | ospf_lsa_header_dump (new->data); |
| 1357 | } |
| 1358 | |
| 1359 | return new; |
| 1360 | } |
| 1361 | |
| 1362 | struct ospf_lsa* |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 1363 | ospf_summary_asbr_lsa_refresh (struct ospf *ospf, struct ospf_lsa *lsa) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1364 | { |
| 1365 | struct ospf_lsa *new; |
| 1366 | struct summary_lsa *sl; |
| 1367 | struct prefix p; |
| 1368 | |
| 1369 | /* Sanity check. */ |
| 1370 | assert (lsa->data); |
| 1371 | |
| 1372 | sl = (struct summary_lsa *)lsa->data; |
| 1373 | p.prefixlen = ip_masklen (sl->mask); |
| 1374 | new = ospf_summary_asbr_lsa_new (lsa->area, &p, GET_METRIC (sl->metric), |
| 1375 | sl->header.id); |
| 1376 | |
| 1377 | new->data->ls_seqnum = lsa_seqnum_increment (lsa); |
| 1378 | |
| 1379 | /* Re-calculate checksum. */ |
| 1380 | ospf_lsa_checksum (new->data); |
| 1381 | |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 1382 | ospf_lsa_install (ospf, NULL, new); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1383 | |
| 1384 | /* Flood LSA through area. */ |
| 1385 | ospf_flood_through_area (new->area, NULL, new); |
| 1386 | |
| 1387 | if (IS_DEBUG_OSPF (lsa, LSA_GENERATE)) |
| 1388 | { |
| 1389 | zlog_info ("LSA[Type%d:%s]: summary-ASBR-LSA refresh", |
| 1390 | new->data->type, inet_ntoa (new->data->id)); |
| 1391 | ospf_lsa_header_dump (new->data); |
| 1392 | } |
| 1393 | |
| 1394 | return new; |
| 1395 | } |
| 1396 | |
| 1397 | /* AS-external-LSA related functions. */ |
| 1398 | |
| 1399 | /* Get nexthop for AS-external-LSAs. Return nexthop if its interface |
| 1400 | is connected, else 0*/ |
| 1401 | struct in_addr |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 1402 | ospf_external_lsa_nexthop_get (struct ospf *ospf, struct in_addr nexthop) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1403 | { |
| 1404 | struct in_addr fwd; |
| 1405 | struct prefix nh; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1406 | listnode n1; |
| 1407 | |
| 1408 | fwd.s_addr = 0; |
| 1409 | |
| 1410 | if (!nexthop.s_addr) |
| 1411 | return fwd; |
| 1412 | |
| 1413 | /* Check whether nexthop is covered by OSPF network. */ |
| 1414 | nh.family = AF_INET; |
| 1415 | nh.u.prefix4 = nexthop; |
| 1416 | nh.prefixlen = IPV4_MAX_BITLEN; |
| 1417 | |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 1418 | for (n1 = listhead (ospf->oiflist); n1; nextnode (n1)) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1419 | { |
| 1420 | struct ospf_interface *oi = getdata (n1); |
| 1421 | |
paul | 2e3b2e4 | 2002-12-13 21:03:13 +0000 | [diff] [blame] | 1422 | if (if_is_operative (oi->ifp)) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1423 | if (oi->address->family == AF_INET) |
| 1424 | if (prefix_match (oi->address, &nh)) |
| 1425 | return nexthop; |
| 1426 | } |
| 1427 | |
| 1428 | return fwd; |
| 1429 | } |
| 1430 | |
| 1431 | #ifdef HAVE_NSSA |
| 1432 | /* NSSA-external-LSA related functions. */ |
| 1433 | |
| 1434 | /* Get 1st IP connection for Forward Addr */ |
| 1435 | |
| 1436 | struct in_addr |
| 1437 | ospf_get_ip_from_ifp (struct ospf_interface *oi) |
| 1438 | { |
| 1439 | struct in_addr fwd; |
| 1440 | |
| 1441 | fwd.s_addr = 0; |
| 1442 | |
paul | 2e3b2e4 | 2002-12-13 21:03:13 +0000 | [diff] [blame] | 1443 | if (if_is_operative (oi->ifp)) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1444 | return oi->address->u.prefix4; |
| 1445 | |
| 1446 | return fwd; |
| 1447 | } |
| 1448 | |
| 1449 | /* Get 1st IP connection for Forward Addr */ |
| 1450 | struct in_addr |
paul | f2c8065 | 2002-12-13 21:44:27 +0000 | [diff] [blame] | 1451 | ospf_get_nssa_ip (struct ospf_area *area) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1452 | { |
| 1453 | struct in_addr fwd; |
paul | f2c8065 | 2002-12-13 21:44:27 +0000 | [diff] [blame] | 1454 | struct in_addr best_default; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1455 | listnode n1; |
| 1456 | |
| 1457 | fwd.s_addr = 0; |
paul | f2c8065 | 2002-12-13 21:44:27 +0000 | [diff] [blame] | 1458 | best_default.s_addr = 0; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1459 | |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 1460 | for (n1 = listhead (area->ospf->oiflist); n1; nextnode (n1)) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1461 | { |
| 1462 | struct ospf_interface *oi = getdata (n1); |
| 1463 | |
paul | 2e3b2e4 | 2002-12-13 21:03:13 +0000 | [diff] [blame] | 1464 | if (if_is_operative (oi->ifp)) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1465 | if (oi->area->external_routing == OSPF_AREA_NSSA) |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 1466 | if (oi->address && oi->address->family == AF_INET) |
| 1467 | { |
| 1468 | if (best_default.s_addr == 0) |
| 1469 | best_default = oi->address->u.prefix4; |
| 1470 | if (oi->area == area) |
| 1471 | return oi->address->u.prefix4; |
paul | f2c8065 | 2002-12-13 21:44:27 +0000 | [diff] [blame] | 1472 | } |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1473 | } |
paul | f2c8065 | 2002-12-13 21:44:27 +0000 | [diff] [blame] | 1474 | if (best_default.s_addr != 0) |
| 1475 | return best_default; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1476 | |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 1477 | if (best_default.s_addr != 0) |
| 1478 | return best_default; |
| 1479 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1480 | return fwd; |
| 1481 | } |
| 1482 | #endif /* HAVE_NSSA */ |
| 1483 | |
| 1484 | #define DEFAULT_DEFAULT_METRIC 20 |
| 1485 | #define DEFAULT_DEFAULT_ORIGINATE_METRIC 10 |
| 1486 | #define DEFAULT_DEFAULT_ALWAYS_METRIC 1 |
| 1487 | |
| 1488 | #define DEFAULT_METRIC_TYPE EXTERNAL_METRIC_TYPE_2 |
| 1489 | |
| 1490 | int |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 1491 | metric_type (struct ospf *ospf, u_char src) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1492 | { |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 1493 | return (ospf->dmetric[src].type < 0 ? |
| 1494 | DEFAULT_METRIC_TYPE : ospf->dmetric[src].type); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1495 | } |
| 1496 | |
| 1497 | int |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 1498 | metric_value (struct ospf *ospf, u_char src) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1499 | { |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 1500 | if (ospf->dmetric[src].value < 0) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1501 | { |
| 1502 | if (src == DEFAULT_ROUTE) |
| 1503 | { |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 1504 | if (ospf->default_originate == DEFAULT_ORIGINATE_ZEBRA) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1505 | return DEFAULT_DEFAULT_ORIGINATE_METRIC; |
| 1506 | else |
| 1507 | return DEFAULT_DEFAULT_ALWAYS_METRIC; |
| 1508 | } |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 1509 | else if (ospf->default_metric < 0) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1510 | return DEFAULT_DEFAULT_METRIC; |
| 1511 | else |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 1512 | return ospf->default_metric; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1513 | } |
| 1514 | |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 1515 | return ospf->dmetric[src].value; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1516 | } |
| 1517 | |
| 1518 | /* Set AS-external-LSA body. */ |
| 1519 | void |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 1520 | ospf_external_lsa_body_set (struct stream *s, struct external_info *ei, |
| 1521 | struct ospf *ospf) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1522 | { |
| 1523 | struct prefix_ipv4 *p = &ei->p; |
| 1524 | struct in_addr mask, fwd_addr; |
| 1525 | u_int32_t mvalue; |
| 1526 | int mtype; |
| 1527 | int type; |
| 1528 | |
| 1529 | /* Put Network Mask. */ |
| 1530 | masklen2ip (p->prefixlen, &mask); |
| 1531 | stream_put_ipv4 (s, mask.s_addr); |
| 1532 | |
| 1533 | /* If prefix is default, specify DEFAULT_ROUTE. */ |
| 1534 | type = is_prefix_default (&ei->p) ? DEFAULT_ROUTE : ei->type; |
| 1535 | |
| 1536 | mtype = (ROUTEMAP_METRIC_TYPE (ei) != -1) ? |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 1537 | ROUTEMAP_METRIC_TYPE (ei) : metric_type (ospf, type); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1538 | |
| 1539 | mvalue = (ROUTEMAP_METRIC (ei) != -1) ? |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 1540 | ROUTEMAP_METRIC (ei) : metric_value (ospf, type); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1541 | |
| 1542 | /* Put type of external metric. */ |
| 1543 | stream_putc (s, (mtype == EXTERNAL_METRIC_TYPE_2 ? 0x80 : 0)); |
| 1544 | |
| 1545 | /* Put 0 metric. TOS metric is not supported. */ |
| 1546 | stream_put_ospf_metric (s, mvalue); |
| 1547 | |
| 1548 | /* Get forwarding address to nexthop if on the Connection List, else 0. */ |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 1549 | fwd_addr = ospf_external_lsa_nexthop_get (ospf, ei->nexthop); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1550 | |
| 1551 | /* Put forwarding address. */ |
| 1552 | stream_put_ipv4 (s, fwd_addr.s_addr); |
| 1553 | |
| 1554 | /* Put route tag -- This value should be introduced from configuration. */ |
| 1555 | stream_putl (s, 0); |
| 1556 | } |
| 1557 | |
| 1558 | /* Create new external-LSA. */ |
| 1559 | struct ospf_lsa * |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 1560 | ospf_external_lsa_new (struct ospf *ospf, |
| 1561 | struct external_info *ei, struct in_addr *old_id) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1562 | { |
| 1563 | struct stream *s; |
| 1564 | struct lsa_header *lsah; |
| 1565 | struct ospf_lsa *new; |
| 1566 | struct in_addr id; |
| 1567 | int length; |
| 1568 | |
| 1569 | if (ei == NULL) |
| 1570 | { |
| 1571 | if (IS_DEBUG_OSPF (lsa, LSA_GENERATE)) |
| 1572 | zlog_warn ("LSA[Type5]: External info is NULL, could not originated"); |
| 1573 | return NULL; |
| 1574 | } |
| 1575 | |
| 1576 | if (IS_DEBUG_OSPF (lsa, LSA_GENERATE)) |
| 1577 | zlog_info ("LSA[Type5]: Originate AS-external-LSA instance"); |
| 1578 | |
| 1579 | /* If old Link State ID is specified, refresh LSA with same ID. */ |
| 1580 | if (old_id) |
| 1581 | id = *old_id; |
| 1582 | /* Get Link State with unique ID. */ |
| 1583 | else |
| 1584 | { |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 1585 | id = ospf_lsa_unique_id (ospf, ospf->lsdb, OSPF_AS_EXTERNAL_LSA, &ei->p); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1586 | if (id.s_addr == 0xffffffff) |
| 1587 | { |
| 1588 | /* Maybe Link State ID not available. */ |
| 1589 | if (IS_DEBUG_OSPF (lsa, LSA_GENERATE)) |
| 1590 | zlog_info ("LSA[Type5]: Link ID not available, can't originate"); |
| 1591 | return NULL; |
| 1592 | } |
| 1593 | } |
| 1594 | |
| 1595 | /* Create new stream for LSA. */ |
| 1596 | s = stream_new (OSPF_MAX_LSA_SIZE); |
| 1597 | lsah = (struct lsa_header *) STREAM_DATA (s); |
| 1598 | |
| 1599 | /* Set LSA common header fields. */ |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 1600 | lsa_header_set (s, OSPF_OPTION_E, OSPF_AS_EXTERNAL_LSA, |
| 1601 | id, ospf->router_id); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1602 | |
| 1603 | /* Set AS-external-LSA body fields. */ |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 1604 | ospf_external_lsa_body_set (s, ei, ospf); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1605 | |
| 1606 | /* Set length. */ |
| 1607 | length = stream_get_endp (s); |
| 1608 | lsah->length = htons (length); |
| 1609 | |
| 1610 | /* Now, create OSPF LSA instance. */ |
| 1611 | new = ospf_lsa_new (); |
| 1612 | new->area = NULL; |
| 1613 | SET_FLAG (new->flags, OSPF_LSA_SELF|OSPF_LSA_APPROVED); |
| 1614 | |
| 1615 | /* Copy LSA data to store, discard stream. */ |
| 1616 | new->data = ospf_lsa_data_new (length); |
| 1617 | memcpy (new->data, lsah, length); |
| 1618 | stream_free (s); |
| 1619 | |
| 1620 | return new; |
| 1621 | } |
| 1622 | |
| 1623 | #ifdef HAVE_NSSA |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1624 | /* As Type-7 */ |
| 1625 | void |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 1626 | ospf_install_flood_nssa (struct ospf *ospf, |
| 1627 | struct ospf_lsa *lsa, struct external_info *ei) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1628 | { |
paul | d4a53d5 | 2003-07-12 21:30:57 +0000 | [diff] [blame] | 1629 | struct ospf_lsa *new; |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 1630 | struct as_external_lsa *extlsa; |
paul | f2c8065 | 2002-12-13 21:44:27 +0000 | [diff] [blame] | 1631 | listnode node; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1632 | |
paul | d4a53d5 | 2003-07-12 21:30:57 +0000 | [diff] [blame] | 1633 | /* LSA may be a Type-5 originated via translation of a Type-7 LSA |
| 1634 | * which originated from an NSSA area. In which case it should not be |
| 1635 | * flooded back to NSSA areas. |
| 1636 | */ |
| 1637 | if (CHECK_FLAG (lsa->flags, OSPF_LSA_LOCAL_XLT)) |
| 1638 | return; |
| 1639 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1640 | /* NSSA Originate or Refresh (If anyNSSA) |
| 1641 | |
| 1642 | LSA is self-originated. And just installed as Type-5. |
| 1643 | Additionally, install as Type-7 LSDB for every attached NSSA. |
| 1644 | |
| 1645 | P-Bit controls which ABR performs translation to outside world; If |
| 1646 | we are an ABR....do not set the P-bit, because we send the Type-5, |
| 1647 | not as the ABR Translator, but as the ASBR owner within the AS! |
| 1648 | |
| 1649 | If we are NOT ABR, Flood through NSSA as Type-7 w/P-bit set. The |
| 1650 | elected ABR Translator will see the P-bit, Translate, and re-flood. |
| 1651 | |
| 1652 | Later, ABR_TASK and P-bit will scan Type-7 LSDB and translate to |
| 1653 | Type-5's to non-NSSA Areas. (it will also attempt a re-install) */ |
| 1654 | |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 1655 | for (node = listhead (ospf->areas); node; nextnode (node)) |
| 1656 | { |
| 1657 | struct ospf_area *area = getdata (node); |
hasso | 0c14ad8 | 2003-07-03 08:36:02 +0000 | [diff] [blame] | 1658 | |
| 1659 | /* Don't install Type-7 LSA's into nonNSSA area */ |
| 1660 | if (area->external_routing != OSPF_AREA_NSSA) |
| 1661 | continue; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1662 | |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 1663 | /* make lsa duplicate, lock=1 */ |
paul | d4a53d5 | 2003-07-12 21:30:57 +0000 | [diff] [blame] | 1664 | new = ospf_lsa_dup (lsa); |
| 1665 | new->area = area; |
| 1666 | new->data->type = OSPF_AS_NSSA_LSA; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1667 | |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 1668 | /* set P-bit if not ABR */ |
paul | 020709f | 2003-04-04 02:44:16 +0000 | [diff] [blame] | 1669 | if (! IS_OSPF_ABR (ospf)) |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 1670 | { |
paul | d4a53d5 | 2003-07-12 21:30:57 +0000 | [diff] [blame] | 1671 | SET_FLAG(new->data->options, OSPF_OPTION_NP); |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 1672 | |
| 1673 | /* set non-zero FWD ADDR |
| 1674 | |
| 1675 | draft-ietf-ospf-nssa-update-09.txt |
| 1676 | |
| 1677 | if the network between the NSSA AS boundary router and the |
| 1678 | adjacent AS is advertised into OSPF as an internal OSPF route, |
| 1679 | the forwarding address should be the next op address as is cu |
| 1680 | currently done with type-5 LSAs. If the intervening network is |
| 1681 | not adversited into OSPF as an internal OSPF route and the |
| 1682 | type-7 LSA's P-bit is set a forwarding address should be |
| 1683 | selected from one of the router's active OSPF inteface addresses |
| 1684 | which belong to the NSSA. If no such addresses exist, then |
| 1685 | no type-7 LSA's with the P-bit set should originate from this |
| 1686 | router. */ |
| 1687 | |
paul | d4a53d5 | 2003-07-12 21:30:57 +0000 | [diff] [blame] | 1688 | /* kevinm: not updating lsa anymore, just new */ |
| 1689 | extlsa = (struct as_external_lsa *)(new->data); |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 1690 | |
| 1691 | if (extlsa->e[0].fwd_addr.s_addr == 0) |
| 1692 | extlsa->e[0].fwd_addr = ospf_get_nssa_ip(area); /* this NSSA area in ifp */ |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1693 | |
paul | d748032 | 2003-05-16 17:31:51 +0000 | [diff] [blame] | 1694 | if (extlsa->e[0].fwd_addr.s_addr == 0) |
| 1695 | { |
| 1696 | if (IS_DEBUG_OSPF_NSSA) |
| 1697 | zlog_info ("LSA[Type-7]: Could not build FWD-ADDR"); |
paul | d4a53d5 | 2003-07-12 21:30:57 +0000 | [diff] [blame] | 1698 | ospf_lsa_discard(new); |
paul | d748032 | 2003-05-16 17:31:51 +0000 | [diff] [blame] | 1699 | return; |
| 1700 | } |
paul | f2c8065 | 2002-12-13 21:44:27 +0000 | [diff] [blame] | 1701 | } |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 1702 | /* Re-calculate checksum. */ |
paul | d4a53d5 | 2003-07-12 21:30:57 +0000 | [diff] [blame] | 1703 | ospf_lsa_checksum (new->data); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1704 | |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 1705 | /* install also as Type-7 */ |
paul | d4a53d5 | 2003-07-12 21:30:57 +0000 | [diff] [blame] | 1706 | ospf_lsa_install (ospf, NULL, new); /* Remove Old, Lock New = 2 */ |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 1707 | |
| 1708 | /* will send each copy, lock=2+n */ |
paul | d4a53d5 | 2003-07-12 21:30:57 +0000 | [diff] [blame] | 1709 | ospf_flood_through_as (ospf, NULL, new); /* all attached NSSA's, no AS/STUBs */ |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 1710 | } |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1711 | } |
paul | d4a53d5 | 2003-07-12 21:30:57 +0000 | [diff] [blame] | 1712 | |
| 1713 | struct ospf_lsa * |
| 1714 | ospf_lsa_translated_nssa_new (struct ospf *ospf, |
| 1715 | struct ospf_lsa *type7) |
| 1716 | { |
| 1717 | |
| 1718 | struct ospf_lsa *new; |
| 1719 | struct as_external_lsa *ext, *extnew; |
| 1720 | struct external_info ei; |
| 1721 | |
| 1722 | ext = (struct as_external_lsa *)(type7->data); |
| 1723 | |
| 1724 | /* need external_info struct, fill in bare minimum */ |
| 1725 | ei.p.family = AF_INET; |
| 1726 | ei.p.prefix = type7->data->id; |
| 1727 | ei.p.prefixlen = ip_masklen (ext->mask); |
| 1728 | ei.type = ZEBRA_ROUTE_OSPF; |
| 1729 | ei.nexthop = ext->header.adv_router; |
| 1730 | ei.route_map_set.metric = -1; |
| 1731 | ei.route_map_set.metric_type = -1; |
| 1732 | ei.tag = 0; |
| 1733 | |
| 1734 | if ( (new = ospf_external_lsa_new (ospf, &ei, &type7->data->id)) == NULL) |
| 1735 | { |
| 1736 | if (IS_DEBUG_OSPF_NSSA) |
| 1737 | zlog_info ("ospf_nssa_translate_originate(): Could not originate " |
| 1738 | "Translated Type-5 for %s", |
| 1739 | inet_ntoa (ei.p.prefix)); |
| 1740 | return NULL; |
| 1741 | } |
| 1742 | |
| 1743 | extnew = (struct as_external_lsa *)(new->data); |
| 1744 | |
| 1745 | /* copy over Type-7 data to new */ |
| 1746 | extnew->e[0].tos = ext->e[0].tos; |
| 1747 | extnew->e[0].route_tag = ext->e[0].route_tag; |
| 1748 | extnew->e[0].fwd_addr.s_addr = ext->e[0].fwd_addr.s_addr; |
| 1749 | new->data->ls_seqnum = type7->data->ls_seqnum; |
| 1750 | |
| 1751 | /* add translated flag, checksum and lock new lsa */ |
| 1752 | SET_FLAG (new->flags, OSPF_LSA_LOCAL_XLT); /* Translated from 7 */ |
| 1753 | ospf_lsa_checksum (new->data); |
| 1754 | new = ospf_lsa_lock (new); |
| 1755 | |
| 1756 | return new; |
| 1757 | } |
| 1758 | |
| 1759 | /* compare type-5 to type-7 |
| 1760 | * -1: err, 0: same, 1: different |
| 1761 | */ |
| 1762 | int |
| 1763 | ospf_lsa_translated_nssa_compare (struct ospf_lsa *t7, struct ospf_lsa *t5) |
| 1764 | { |
| 1765 | |
| 1766 | struct as_external_lsa *e5 = (struct as_external_lsa *)t5, |
| 1767 | *e7 = (struct as_external_lsa *)t7; |
| 1768 | |
| 1769 | |
| 1770 | /* sanity checks */ |
| 1771 | if (! ((t5->data->type == OSPF_AS_EXTERNAL_LSA) |
| 1772 | && (t7->data->type == OSPF_AS_NSSA_LSA))) |
| 1773 | return -1; |
| 1774 | |
| 1775 | if (t5->data->id.s_addr != t7->data->id.s_addr) |
| 1776 | return -1; |
| 1777 | |
| 1778 | if (t5->data->ls_seqnum != t7->data->ls_seqnum) |
| 1779 | return LSA_REFRESH_FORCE; |
| 1780 | |
| 1781 | if (e5->mask.s_addr != e7->mask.s_addr) |
| 1782 | return LSA_REFRESH_FORCE; |
| 1783 | |
| 1784 | if (e5->e[0].fwd_addr.s_addr != e7->e[0].fwd_addr.s_addr) |
| 1785 | return LSA_REFRESH_FORCE; |
| 1786 | |
| 1787 | if (e5->e[0].route_tag != e7->e[0].route_tag) |
| 1788 | return LSA_REFRESH_FORCE; |
| 1789 | |
| 1790 | if (GET_METRIC (e5->e[0].metric) != GET_METRIC (e7->e[0].metric)) |
| 1791 | return LSA_REFRESH_FORCE; |
| 1792 | |
| 1793 | return LSA_REFRESH_IF_CHANGED; |
| 1794 | } |
| 1795 | |
| 1796 | /* Originate Translated Type-5 for supplied Type-7 NSSA LSA */ |
| 1797 | struct ospf_lsa * |
| 1798 | ospf_translated_nssa_originate (struct ospf *ospf, struct ospf_lsa *type7) |
| 1799 | { |
| 1800 | struct ospf_lsa *new; |
| 1801 | struct as_external_lsa *extnew; |
| 1802 | |
| 1803 | /* we cant use ospf_external_lsa_originate() as we need to set |
| 1804 | * the OSPF_LSA_LOCAL_XLT flag, must originate by hand |
| 1805 | */ |
| 1806 | |
| 1807 | if ( (new = ospf_lsa_translated_nssa_new (ospf, type7)) == NULL) |
| 1808 | { |
| 1809 | if (IS_DEBUG_OSPF_NSSA) |
| 1810 | zlog_info ("ospf_translated_nssa_originate(): Could not translate " |
| 1811 | "Type-7, Id %s, to Type-5", |
| 1812 | inet_ntoa (type7->data->id)); |
| 1813 | return NULL; |
| 1814 | } |
| 1815 | |
| 1816 | extnew = (struct as_external_lsa *)new; |
| 1817 | |
| 1818 | if (IS_DEBUG_OSPF_NSSA) |
| 1819 | { |
| 1820 | zlog_info ("ospf_translated_nssa_originate(): " |
| 1821 | "translated Type 7, installed:"); |
| 1822 | ospf_lsa_header_dump (new->data); |
| 1823 | zlog_info (" Network mask: %d",ip_masklen (extnew->mask)); |
| 1824 | zlog_info (" Forward addr: %s", inet_ntoa (extnew->e[0].fwd_addr)); |
| 1825 | } |
| 1826 | |
| 1827 | if ( (new = ospf_lsa_install (ospf, NULL, new)) == NULL) |
| 1828 | { |
| 1829 | if (IS_DEBUG_OSPF_NSSA); |
| 1830 | zlog_warn ("ospf_lsa_translated_nssa_originate(): " |
| 1831 | "Could not install LSA " |
| 1832 | "id %s", inet_ntoa (type7->data->id)); |
| 1833 | return NULL; |
| 1834 | } |
| 1835 | |
| 1836 | ospf->lsa_originate_count++; |
| 1837 | ospf_flood_through_as (ospf, NULL, new); |
| 1838 | |
| 1839 | return new; |
| 1840 | } |
| 1841 | |
| 1842 | /* Refresh Translated from NSSA AS-external-LSA. */ |
| 1843 | struct ospf_lsa * |
| 1844 | ospf_translated_nssa_refresh (struct ospf *ospf, struct ospf_lsa *type7, |
| 1845 | struct ospf_lsa *type5) |
| 1846 | { |
| 1847 | struct ospf_lsa *new = NULL; |
| 1848 | |
| 1849 | /* Sanity checks. */ |
| 1850 | assert (type7 || type5); |
| 1851 | if (type7) |
| 1852 | assert (type7->data); |
| 1853 | if (type5) |
| 1854 | assert (type5->data); |
| 1855 | assert (ospf->anyNSSA); |
| 1856 | |
| 1857 | /* get required data according to what has been given */ |
| 1858 | if (type7 && type5 == NULL) |
| 1859 | { |
| 1860 | /* find the translated Type-5 for this Type-7 */ |
| 1861 | struct as_external_lsa *ext = (struct as_external_lsa *)(type7->data); |
| 1862 | struct prefix_ipv4 p = |
| 1863 | { |
| 1864 | .prefix = type7->data->id, |
| 1865 | .prefixlen = ip_masklen (ext->mask), |
| 1866 | .family = AF_INET, |
| 1867 | }; |
| 1868 | |
| 1869 | type5 = ospf_external_info_find_lsa (ospf, &p); |
| 1870 | } |
| 1871 | else if (type5 && type7 == NULL) |
| 1872 | { |
| 1873 | /* find the type-7 from which supplied type-5 was translated, |
| 1874 | * ie find first type-7 with same LSA Id. |
| 1875 | */ |
| 1876 | listnode ln; |
| 1877 | struct route_node *rn; |
| 1878 | struct ospf_lsa *lsa; |
| 1879 | struct ospf_area *area; |
| 1880 | |
| 1881 | LIST_LOOP (ospf->areas, area, ln) |
| 1882 | { |
| 1883 | if (area->external_routing != OSPF_AREA_NSSA |
| 1884 | && !type7) |
| 1885 | continue; |
| 1886 | |
| 1887 | LSDB_LOOP (NSSA_LSDB(area), rn, lsa) |
| 1888 | { |
| 1889 | if (lsa->data->id.s_addr == type5->data->id.s_addr) |
| 1890 | { |
| 1891 | type7 = lsa; |
| 1892 | break; |
| 1893 | } |
| 1894 | } |
| 1895 | } |
| 1896 | } |
| 1897 | |
| 1898 | /* do we have type7? */ |
| 1899 | if (!type7) |
| 1900 | { |
| 1901 | if (IS_DEBUG_OSPF_NSSA) |
| 1902 | zlog_info ("ospf_translated_nssa_refresh(): no Type-7 found for " |
| 1903 | "Type-5 LSA Id %s", |
| 1904 | inet_ntoa (type7->data->id)); |
| 1905 | return NULL; |
| 1906 | } |
| 1907 | |
| 1908 | /* do we have valid translated type5? */ |
| 1909 | if (type5 == NULL || !CHECK_FLAG (type5->flags, OSPF_LSA_LOCAL_XLT) ) |
| 1910 | { |
| 1911 | if (IS_DEBUG_OSPF_NSSA) |
| 1912 | zlog_info ("ospf_translated_nssa_refresh(): No translated Type-5 " |
| 1913 | "found for Type-7 with Id %s", |
| 1914 | inet_ntoa (type7->data->id)); |
| 1915 | return NULL; |
| 1916 | } |
| 1917 | |
| 1918 | /* Delete LSA from neighbor retransmit-list. */ |
| 1919 | ospf_ls_retransmit_delete_nbr_as (ospf, type5); |
| 1920 | |
| 1921 | /* create new translated LSA */ |
| 1922 | if ( (new = ospf_lsa_translated_nssa_new (ospf, type7)) == NULL) |
| 1923 | { |
| 1924 | if (IS_DEBUG_OSPF_NSSA) |
| 1925 | zlog_info ("ospf_translated_nssa_refresh(): Could not translate " |
| 1926 | "Type-7 for %s to Type-5", |
| 1927 | inet_ntoa (type7->data->id)); |
| 1928 | return NULL; |
| 1929 | } |
| 1930 | |
| 1931 | if ( !(new = ospf_lsa_install (ospf, NULL, new)) ) |
| 1932 | { |
| 1933 | if (IS_DEBUG_OSPF_NSSA) |
| 1934 | zlog_info ("ospf_translated_nssa_refresh(): Could not install " |
| 1935 | "translated LSA, Id %s", |
| 1936 | inet_ntoa (new->data->id)); |
| 1937 | return NULL; |
| 1938 | } |
| 1939 | |
| 1940 | /* Flood LSA through area. */ |
| 1941 | ospf_flood_through_as (ospf, NULL, new); |
| 1942 | |
| 1943 | return new; |
| 1944 | } |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1945 | #endif /* HAVE_NSSA */ |
| 1946 | |
| 1947 | int |
| 1948 | is_prefix_default (struct prefix_ipv4 *p) |
| 1949 | { |
| 1950 | struct prefix_ipv4 q; |
| 1951 | |
| 1952 | q.family = AF_INET; |
| 1953 | q.prefix.s_addr = 0; |
| 1954 | q.prefixlen = 0; |
| 1955 | |
| 1956 | return prefix_same ((struct prefix *) p, (struct prefix *) &q); |
| 1957 | } |
| 1958 | |
| 1959 | /* Originate an AS-external-LSA, install and flood. */ |
| 1960 | struct ospf_lsa * |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 1961 | ospf_external_lsa_originate (struct ospf *ospf, struct external_info *ei) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1962 | { |
| 1963 | struct ospf_lsa *new; |
| 1964 | |
| 1965 | /* Added for NSSA project.... |
| 1966 | |
| 1967 | External LSAs are originated in ASBRs as usual, but for NSSA systems. |
| 1968 | there is the global Type-5 LSDB and a Type-7 LSDB installed for |
| 1969 | every area. The Type-7's are flooded to every IR and every ABR; We |
| 1970 | install the Type-5 LSDB so that the normal "refresh" code operates |
| 1971 | as usual, and flag them as not used during ASE calculations. The |
| 1972 | Type-7 LSDB is used for calculations. Each Type-7 has a Forwarding |
| 1973 | Address of non-zero. |
| 1974 | |
| 1975 | If an ABR is the elected NSSA translator, following SPF and during |
| 1976 | the ABR task it will translate all the scanned Type-7's, with P-bit |
| 1977 | ON and not-self generated, and translate to Type-5's throughout the |
| 1978 | non-NSSA/STUB AS. |
| 1979 | |
| 1980 | A difference in operation depends whether this ASBR is an ABR |
| 1981 | or not. If not an ABR, the P-bit is ON, to indicate that any |
| 1982 | elected NSSA-ABR can perform its translation. |
| 1983 | |
| 1984 | If an ABR, the P-bit is OFF; No ABR will perform translation and |
| 1985 | this ASBR will flood the Type-5 LSA as usual. |
| 1986 | |
| 1987 | For the case where this ASBR is not an ABR, the ASE calculations |
| 1988 | are based on the Type-5 LSDB; The Type-7 LSDB exists just to |
| 1989 | demonstrate to the user that there are LSA's that belong to any |
| 1990 | attached NSSA. |
| 1991 | |
| 1992 | Finally, it just so happens that when the ABR is translating every |
| 1993 | Type-7 into Type-5, it installs it into the Type-5 LSDB as an |
| 1994 | approved Type-5 (translated from Type-7); at the end of translation |
| 1995 | if any Translated Type-5's remain unapproved, then they must be |
| 1996 | flushed from the AS. |
| 1997 | |
| 1998 | */ |
| 1999 | |
| 2000 | /* Check the AS-external-LSA should be originated. */ |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 2001 | if (!ospf_redistribute_check (ospf, ei, NULL)) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2002 | return NULL; |
| 2003 | |
| 2004 | /* Create new AS-external-LSA instance. */ |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 2005 | if ((new = ospf_external_lsa_new (ospf, ei, NULL)) == NULL) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2006 | { |
| 2007 | if (IS_DEBUG_OSPF_EVENT) |
| 2008 | zlog_info ("LSA[Type5:%s]: Could not originate AS-external-LSA", |
| 2009 | inet_ntoa (ei->p.prefix)); |
| 2010 | return NULL; |
| 2011 | } |
| 2012 | |
| 2013 | /* Install newly created LSA into Type-5 LSDB, lock = 1. */ |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 2014 | ospf_lsa_install (ospf, NULL, new); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2015 | |
| 2016 | /* Update LSA origination count. */ |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 2017 | ospf->lsa_originate_count++; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2018 | |
| 2019 | /* Flooding new LSA. only to AS (non-NSSA/STUB) */ |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 2020 | ospf_flood_through_as (ospf, NULL, new); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2021 | |
| 2022 | #ifdef HAVE_NSSA |
| 2023 | /* If there is any attached NSSA, do special handling */ |
paul | d4a53d5 | 2003-07-12 21:30:57 +0000 | [diff] [blame] | 2024 | if (ospf->anyNSSA && |
| 2025 | /* stay away from translated LSAs! */ |
| 2026 | !(CHECK_FLAG (new->flags, OSPF_LSA_LOCAL_XLT))) |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 2027 | ospf_install_flood_nssa (ospf, new, ei); /* Install/Flood Type-7 to all NSSAs */ |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2028 | #endif /* HAVE_NSSA */ |
| 2029 | |
| 2030 | /* Debug logging. */ |
| 2031 | if (IS_DEBUG_OSPF (lsa, LSA_GENERATE)) |
| 2032 | { |
| 2033 | zlog_info ("LSA[Type%d:%s]: Originate AS-external-LSA %p", |
| 2034 | new->data->type, inet_ntoa (new->data->id), new); |
| 2035 | ospf_lsa_header_dump (new->data); |
| 2036 | } |
| 2037 | |
| 2038 | return new; |
| 2039 | } |
| 2040 | |
| 2041 | /* Originate AS-external-LSA from external info with initial flag. */ |
| 2042 | int |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 2043 | ospf_external_lsa_originate_timer (struct thread *thread) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2044 | { |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 2045 | struct ospf *ospf = THREAD_ARG (thread); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2046 | struct route_node *rn; |
| 2047 | struct external_info *ei; |
| 2048 | struct route_table *rt; |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 2049 | int type = THREAD_VAL (thread); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2050 | |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 2051 | ospf->t_external_lsa = NULL; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2052 | |
| 2053 | /* Originate As-external-LSA from all type of distribute source. */ |
| 2054 | if ((rt = EXTERNAL_INFO (type))) |
| 2055 | for (rn = route_top (rt); rn; rn = route_next (rn)) |
| 2056 | if ((ei = rn->info) != NULL) |
| 2057 | if (!is_prefix_default ((struct prefix_ipv4 *)&ei->p)) |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 2058 | if (!ospf_external_lsa_originate (ospf, ei)) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2059 | zlog_warn ("LSA: AS-external-LSA was not originated."); |
| 2060 | |
| 2061 | return 0; |
| 2062 | } |
| 2063 | |
| 2064 | struct external_info * |
paul | 020709f | 2003-04-04 02:44:16 +0000 | [diff] [blame] | 2065 | ospf_default_external_info (struct ospf *ospf) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2066 | { |
| 2067 | int type; |
| 2068 | struct route_node *rn; |
| 2069 | struct prefix_ipv4 p; |
| 2070 | |
| 2071 | p.family = AF_INET; |
| 2072 | p.prefix.s_addr = 0; |
| 2073 | p.prefixlen = 0; |
| 2074 | |
| 2075 | /* First, lookup redistributed default route. */ |
| 2076 | for (type = 0; type <= ZEBRA_ROUTE_MAX; type++) |
| 2077 | if (EXTERNAL_INFO (type) && type != ZEBRA_ROUTE_OSPF) |
| 2078 | { |
| 2079 | rn = route_node_lookup (EXTERNAL_INFO (type), (struct prefix *) &p); |
| 2080 | if (rn != NULL) |
| 2081 | { |
| 2082 | route_unlock_node (rn); |
| 2083 | assert (rn->info); |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 2084 | if (ospf_redistribute_check (ospf, rn->info, NULL)) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2085 | return rn->info; |
| 2086 | } |
| 2087 | } |
| 2088 | |
| 2089 | return NULL; |
| 2090 | } |
| 2091 | |
| 2092 | int |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 2093 | ospf_default_originate_timer (struct thread *thread) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2094 | { |
| 2095 | int *origin; |
| 2096 | struct prefix_ipv4 p; |
| 2097 | struct in_addr nexthop; |
| 2098 | struct external_info *ei; |
paul | 020709f | 2003-04-04 02:44:16 +0000 | [diff] [blame] | 2099 | struct ospf *ospf; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2100 | |
paul | 020709f | 2003-04-04 02:44:16 +0000 | [diff] [blame] | 2101 | ospf = ospf_lookup (); |
| 2102 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2103 | /* Get originate flags. */ |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 2104 | origin = THREAD_ARG (thread); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2105 | |
| 2106 | p.family = AF_INET; |
| 2107 | p.prefix.s_addr = 0; |
| 2108 | p.prefixlen = 0; |
| 2109 | |
| 2110 | if (*origin == DEFAULT_ORIGINATE_ALWAYS) |
| 2111 | { |
| 2112 | /* If there is no default route via redistribute, |
| 2113 | then originate AS-external-LSA with nexthop 0 (self). */ |
| 2114 | nexthop.s_addr = 0; |
| 2115 | ospf_external_info_add (DEFAULT_ROUTE, p, 0, nexthop); |
| 2116 | } |
| 2117 | |
paul | 020709f | 2003-04-04 02:44:16 +0000 | [diff] [blame] | 2118 | if ((ei = ospf_default_external_info (ospf))) |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 2119 | ospf_external_lsa_originate (ospf, ei); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2120 | |
| 2121 | return 0; |
| 2122 | } |
| 2123 | |
paul | 645878f | 2003-04-13 21:42:11 +0000 | [diff] [blame] | 2124 | #ifdef HAVE_NSSA |
| 2125 | /* Flush any NSSA LSAs for given prefix */ |
| 2126 | void |
| 2127 | ospf_nssa_lsa_flush (struct ospf *ospf, struct prefix_ipv4 *p) |
| 2128 | { |
| 2129 | struct listnode *node; |
| 2130 | struct ospf_lsa *lsa; |
| 2131 | struct ospf_area *area; |
| 2132 | |
paul | d748032 | 2003-05-16 17:31:51 +0000 | [diff] [blame] | 2133 | for (node = listhead (ospf->areas); node; nextnode (node)) |
paul | 645878f | 2003-04-13 21:42:11 +0000 | [diff] [blame] | 2134 | { |
paul | d748032 | 2003-05-16 17:31:51 +0000 | [diff] [blame] | 2135 | if (((area = getdata (node)) != NULL) |
| 2136 | && (area->external_routing == OSPF_AREA_NSSA)) |
| 2137 | { |
| 2138 | if (!(lsa = ospf_lsa_lookup (area, OSPF_AS_NSSA_LSA, p->prefix, |
| 2139 | ospf->router_id))) |
| 2140 | { |
| 2141 | if (IS_DEBUG_OSPF (lsa, LSA_FLOODING)) |
| 2142 | zlog_warn ("LSA: There is no such AS-NSSA-LSA %s/%d in LSDB", |
| 2143 | inet_ntoa (p->prefix), p->prefixlen); |
| 2144 | continue; |
| 2145 | } |
| 2146 | ospf_ls_retransmit_delete_nbr_area (area, lsa); |
| 2147 | if (!IS_LSA_MAXAGE (lsa)) |
| 2148 | { |
| 2149 | ospf_refresher_unregister_lsa (ospf, lsa); |
| 2150 | ospf_lsa_flush_area (lsa, area); |
| 2151 | } |
| 2152 | } |
paul | 645878f | 2003-04-13 21:42:11 +0000 | [diff] [blame] | 2153 | } |
| 2154 | } |
| 2155 | #endif /* HAVE_NSSA */ |
| 2156 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2157 | /* Flush an AS-external-LSA from LSDB and routing domain. */ |
| 2158 | void |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 2159 | ospf_external_lsa_flush (struct ospf *ospf, |
| 2160 | u_char type, struct prefix_ipv4 *p, |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2161 | unsigned int ifindex, struct in_addr nexthop) |
| 2162 | { |
| 2163 | struct ospf_lsa *lsa; |
| 2164 | |
| 2165 | if (IS_DEBUG_OSPF (lsa, LSA_FLOODING)) |
| 2166 | zlog_info ("LSA: Flushing AS-external-LSA %s/%d", |
| 2167 | inet_ntoa (p->prefix), p->prefixlen); |
| 2168 | |
| 2169 | /* First lookup LSA from LSDB. */ |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 2170 | if (!(lsa = ospf_external_info_find_lsa (ospf, p))) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2171 | { |
| 2172 | if (IS_DEBUG_OSPF (lsa, LSA_FLOODING)) |
| 2173 | zlog_warn ("LSA: There is no such AS-external-LSA %s/%d in LSDB", |
| 2174 | inet_ntoa (p->prefix), p->prefixlen); |
| 2175 | return; |
| 2176 | } |
paul | d748032 | 2003-05-16 17:31:51 +0000 | [diff] [blame] | 2177 | #ifdef HAVE_NSSA |
paul | d4a53d5 | 2003-07-12 21:30:57 +0000 | [diff] [blame] | 2178 | /* If LSA is selforiginated, not a translated LSA, and there is |
| 2179 | * NSSA area, flush Type-7 LSA's at first. |
| 2180 | */ |
| 2181 | if (IS_LSA_SELF(lsa) && (ospf->anyNSSA) |
| 2182 | && !(CHECK_FLAG (lsa->flags, OSPF_LSA_LOCAL_XLT))) |
paul | d748032 | 2003-05-16 17:31:51 +0000 | [diff] [blame] | 2183 | ospf_nssa_lsa_flush (ospf, p); |
| 2184 | #endif /* HAVE_NSSA */ |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2185 | |
| 2186 | /* Sweep LSA from Link State Retransmit List. */ |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 2187 | ospf_ls_retransmit_delete_nbr_as (ospf, lsa); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2188 | |
| 2189 | /* There must be no self-originated LSA in rtrs_external. */ |
| 2190 | #if 0 |
| 2191 | /* Remove External route from Zebra. */ |
| 2192 | ospf_zebra_delete ((struct prefix_ipv4 *) p, &nexthop); |
| 2193 | #endif |
| 2194 | |
| 2195 | if (!IS_LSA_MAXAGE (lsa)) |
| 2196 | { |
| 2197 | /* Unregister LSA from Refresh queue. */ |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 2198 | ospf_refresher_unregister_lsa (ospf, lsa); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2199 | |
| 2200 | /* Flush AS-external-LSA through AS. */ |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 2201 | ospf_lsa_flush_as (ospf, lsa); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2202 | } |
| 2203 | |
| 2204 | if (IS_DEBUG_OSPF (lsa, LSA_FLOODING)) |
| 2205 | zlog_info ("ospf_external_lsa_flush(): stop"); |
| 2206 | } |
| 2207 | |
| 2208 | void |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 2209 | ospf_external_lsa_refresh_default (struct ospf *ospf) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2210 | { |
| 2211 | struct prefix_ipv4 p; |
| 2212 | struct external_info *ei; |
| 2213 | struct ospf_lsa *lsa; |
| 2214 | |
| 2215 | p.family = AF_INET; |
| 2216 | p.prefixlen = 0; |
| 2217 | p.prefix.s_addr = 0; |
| 2218 | |
paul | 020709f | 2003-04-04 02:44:16 +0000 | [diff] [blame] | 2219 | ei = ospf_default_external_info (ospf); |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 2220 | lsa = ospf_external_info_find_lsa (ospf, &p); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2221 | |
| 2222 | if (ei) |
| 2223 | { |
| 2224 | if (lsa) |
| 2225 | { |
| 2226 | if (IS_DEBUG_OSPF_EVENT) |
| 2227 | zlog_info ("LSA[Type5:0.0.0.0]: Refresh AS-external-LSA %p", lsa); |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 2228 | ospf_external_lsa_refresh (ospf, lsa, ei, LSA_REFRESH_FORCE); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2229 | } |
| 2230 | else |
| 2231 | { |
| 2232 | if (IS_DEBUG_OSPF_EVENT) |
| 2233 | zlog_info ("LSA[Type5:0.0.0.0]: Originate AS-external-LSA"); |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 2234 | ospf_external_lsa_originate (ospf, ei); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2235 | } |
| 2236 | } |
| 2237 | else |
| 2238 | { |
| 2239 | if (lsa) |
| 2240 | { |
| 2241 | if (IS_DEBUG_OSPF_EVENT) |
| 2242 | zlog_info ("LSA[Type5:0.0.0.0]: Flush AS-external-LSA"); |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 2243 | ospf_lsa_flush_as (ospf, lsa); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2244 | } |
| 2245 | } |
| 2246 | } |
| 2247 | |
| 2248 | void |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 2249 | ospf_external_lsa_refresh_type (struct ospf *ospf, u_char type, int force) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2250 | { |
| 2251 | struct route_node *rn; |
| 2252 | struct external_info *ei; |
| 2253 | |
| 2254 | if (type != DEFAULT_ROUTE) |
| 2255 | if (EXTERNAL_INFO(type)) |
| 2256 | /* Refresh each redistributed AS-external-LSAs. */ |
| 2257 | for (rn = route_top (EXTERNAL_INFO (type)); rn; rn = route_next (rn)) |
| 2258 | if ((ei = rn->info)) |
| 2259 | if (!is_prefix_default (&ei->p)) |
| 2260 | { |
| 2261 | struct ospf_lsa *lsa; |
| 2262 | |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 2263 | if ((lsa = ospf_external_info_find_lsa (ospf, &ei->p))) |
| 2264 | ospf_external_lsa_refresh (ospf, lsa, ei, force); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2265 | else |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 2266 | ospf_external_lsa_originate (ospf, ei); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2267 | } |
| 2268 | } |
| 2269 | |
| 2270 | /* Refresh AS-external-LSA. */ |
| 2271 | void |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 2272 | ospf_external_lsa_refresh (struct ospf *ospf, struct ospf_lsa *lsa, |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2273 | struct external_info *ei, int force) |
| 2274 | { |
| 2275 | struct ospf_lsa *new; |
| 2276 | int changed; |
| 2277 | |
| 2278 | /* Check the AS-external-LSA should be originated. */ |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 2279 | if (!ospf_redistribute_check (ospf, ei, &changed)) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2280 | { |
paul | d4a53d5 | 2003-07-12 21:30:57 +0000 | [diff] [blame] | 2281 | if (IS_DEBUG_OSPF (lsa, LSA_GENERATE)) |
| 2282 | zlog_warn ("LSA[Type%d:%s]: Could not be refreshed, " |
| 2283 | "redist check fail", |
| 2284 | lsa->data->type, inet_ntoa (lsa->data->id)); |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 2285 | ospf_external_lsa_flush (ospf, ei->type, &ei->p, |
| 2286 | ei->ifindex, ei->nexthop); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2287 | return; |
| 2288 | } |
| 2289 | |
| 2290 | if (!changed && !force) |
paul | d4a53d5 | 2003-07-12 21:30:57 +0000 | [diff] [blame] | 2291 | { |
| 2292 | if (IS_DEBUG_OSPF (lsa, LSA_GENERATE)) |
| 2293 | zlog_info ("LSA[Type%d:%s]: Not refreshed, not changed/forced", |
| 2294 | lsa->data->type, inet_ntoa (lsa->data->id)); |
| 2295 | return; |
| 2296 | } |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2297 | |
| 2298 | /* Delete LSA from neighbor retransmit-list. */ |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 2299 | ospf_ls_retransmit_delete_nbr_as (ospf, lsa); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2300 | |
| 2301 | /* Unregister AS-external-LSA from refresh-list. */ |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 2302 | ospf_refresher_unregister_lsa (ospf, lsa); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2303 | |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 2304 | new = ospf_external_lsa_new (ospf, ei, &lsa->data->id); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2305 | |
| 2306 | if (new == NULL) |
| 2307 | { |
| 2308 | if (IS_DEBUG_OSPF (lsa, LSA_GENERATE)) |
| 2309 | zlog_warn ("LSA[Type%d:%s]: Could not be refreshed", lsa->data->type, |
| 2310 | inet_ntoa (lsa->data->id)); |
| 2311 | return; |
| 2312 | } |
| 2313 | |
| 2314 | new->data->ls_seqnum = lsa_seqnum_increment (lsa); |
| 2315 | |
| 2316 | /* Record timestamp. */ |
| 2317 | gettimeofday (&new->tv_orig, NULL); |
| 2318 | |
| 2319 | /* Re-calculate checksum. */ |
| 2320 | ospf_lsa_checksum (new->data); |
| 2321 | |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 2322 | ospf_lsa_install (ospf, NULL, new); /* As type-5. */ |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2323 | |
| 2324 | /* Flood LSA through AS. */ |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 2325 | ospf_flood_through_as (ospf, NULL, new); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2326 | |
| 2327 | #ifdef HAVE_NSSA |
| 2328 | /* If any attached NSSA, install as Type-7, flood to all NSSA Areas */ |
paul | d4a53d5 | 2003-07-12 21:30:57 +0000 | [diff] [blame] | 2329 | if (ospf->anyNSSA && !(CHECK_FLAG (new->flags, OSPF_LSA_LOCAL_XLT))) |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 2330 | ospf_install_flood_nssa (ospf, new, ei); /* Install/Flood per new rules */ |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2331 | #endif /* HAVE_NSSA */ |
| 2332 | |
paul | d4a53d5 | 2003-07-12 21:30:57 +0000 | [diff] [blame] | 2333 | /* Register self-originated LSA to refresh queue. |
| 2334 | * Translated LSAs should not be registered, but refreshed upon |
| 2335 | * refresh of the Type-7 |
| 2336 | */ |
paul | 8fc0f64 | 2003-07-13 01:36:06 +0000 | [diff] [blame] | 2337 | #ifdef HAVE_NSSA |
paul | d4a53d5 | 2003-07-12 21:30:57 +0000 | [diff] [blame] | 2338 | if ( !CHECK_FLAG (new->flags, OSPF_LSA_LOCAL_XLT) ) |
paul | 8fc0f64 | 2003-07-13 01:36:06 +0000 | [diff] [blame] | 2339 | #endif |
paul | d4a53d5 | 2003-07-12 21:30:57 +0000 | [diff] [blame] | 2340 | ospf_refresher_register_lsa (ospf, new); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2341 | |
| 2342 | /* Debug logging. */ |
| 2343 | if (IS_DEBUG_OSPF (lsa, LSA_GENERATE)) |
| 2344 | { |
| 2345 | zlog_info ("LSA[Type%d:%s]: AS-external-LSA refresh", |
paul | d4a53d5 | 2003-07-12 21:30:57 +0000 | [diff] [blame] | 2346 | new->data->type, inet_ntoa (new->data->id)); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2347 | ospf_lsa_header_dump (new->data); |
| 2348 | } |
| 2349 | |
| 2350 | return; |
| 2351 | } |
| 2352 | |
| 2353 | |
| 2354 | /* LSA installation functions. */ |
| 2355 | |
| 2356 | /* Install router-LSA to an area. */ |
| 2357 | struct ospf_lsa * |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 2358 | ospf_router_lsa_install (struct ospf *ospf, |
| 2359 | struct ospf_lsa *new, int rt_recalc) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2360 | { |
| 2361 | struct ospf_area *area = new->area; |
| 2362 | |
| 2363 | /* RFC 2328 Section 13.2 Router-LSAs and network-LSAs |
| 2364 | The entire routing table must be recalculated, starting with |
| 2365 | the shortest path calculations for each area (not just the |
| 2366 | area whose link-state database has changed). |
| 2367 | */ |
| 2368 | if (rt_recalc) |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 2369 | ospf_spf_calculate_schedule (ospf); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2370 | |
| 2371 | if (IS_LSA_SELF (new)) |
| 2372 | { |
| 2373 | /* Set router-LSA refresh timer. */ |
| 2374 | OSPF_TIMER_OFF (area->t_router_lsa_self); |
| 2375 | OSPF_AREA_TIMER_ON (area->t_router_lsa_self, |
paul | d4a53d5 | 2003-07-12 21:30:57 +0000 | [diff] [blame] | 2376 | ospf_router_lsa_timer, OSPF_LS_REFRESH_TIME); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2377 | |
| 2378 | /* Set self-originated router-LSA. */ |
| 2379 | ospf_lsa_unlock (area->router_lsa_self); |
| 2380 | area->router_lsa_self = ospf_lsa_lock (new); |
| 2381 | |
| 2382 | if (IS_DEBUG_OSPF (lsa, LSA_INSTALL)) |
paul | 7ddf1d6 | 2003-10-13 09:06:46 +0000 | [diff] [blame] | 2383 | zlog_info("LSA[Type%d]: ID %s seq 0x%x is self-originated", |
| 2384 | new->data->type, inet_ntoa (new->data->id), |
| 2385 | new->data->ls_seqnum); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2386 | } |
| 2387 | |
| 2388 | return new; |
| 2389 | } |
| 2390 | |
| 2391 | #define OSPF_INTERFACE_TIMER_ON(T,F,V) \ |
| 2392 | if (!(T)) \ |
| 2393 | (T) = thread_add_timer (master, (F), oi, (V)) |
| 2394 | |
| 2395 | /* Install network-LSA to an area. */ |
| 2396 | struct ospf_lsa * |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 2397 | ospf_network_lsa_install (struct ospf *ospf, |
| 2398 | struct ospf_interface *oi, |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2399 | struct ospf_lsa *new, |
| 2400 | int rt_recalc) |
| 2401 | { |
| 2402 | |
| 2403 | /* RFC 2328 Section 13.2 Router-LSAs and network-LSAs |
| 2404 | The entire routing table must be recalculated, starting with |
| 2405 | the shortest path calculations for each area (not just the |
| 2406 | area whose link-state database has changed). |
| 2407 | */ |
| 2408 | if (rt_recalc) |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 2409 | ospf_spf_calculate_schedule (ospf); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2410 | |
| 2411 | /* We supposed that when LSA is originated by us, we pass the int |
| 2412 | for which it was originated. If LSA was received by flooding, |
| 2413 | the RECEIVED flag is set, so we do not link the LSA to the int. */ |
| 2414 | if (IS_LSA_SELF (new) && !CHECK_FLAG (new->flags, OSPF_LSA_RECEIVED)) |
| 2415 | { |
| 2416 | /* Set LSRefresh timer. */ |
| 2417 | OSPF_TIMER_OFF (oi->t_network_lsa_self); |
| 2418 | |
| 2419 | OSPF_INTERFACE_TIMER_ON (oi->t_network_lsa_self, |
| 2420 | ospf_network_lsa_refresh_timer, |
| 2421 | OSPF_LS_REFRESH_TIME); |
| 2422 | |
| 2423 | ospf_lsa_unlock (oi->network_lsa_self); |
| 2424 | oi->network_lsa_self = ospf_lsa_lock (new); |
| 2425 | } |
| 2426 | |
| 2427 | return new; |
| 2428 | } |
| 2429 | |
| 2430 | /* Install summary-LSA to an area. */ |
| 2431 | struct ospf_lsa * |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 2432 | ospf_summary_lsa_install (struct ospf *ospf, struct ospf_lsa *new, |
| 2433 | int rt_recalc) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2434 | { |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2435 | if (rt_recalc && !IS_LSA_SELF (new)) |
| 2436 | { |
| 2437 | /* RFC 2328 Section 13.2 Summary-LSAs |
| 2438 | The best route to the destination described by the summary- |
| 2439 | LSA must be recalculated (see Section 16.5). If this |
| 2440 | destination is an AS boundary router, it may also be |
| 2441 | necessary to re-examine all the AS-external-LSAs. |
| 2442 | */ |
| 2443 | |
| 2444 | #if 0 |
| 2445 | /* This doesn't exist yet... */ |
| 2446 | ospf_summary_incremental_update(new); */ |
| 2447 | #else /* #if 0 */ |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 2448 | ospf_spf_calculate_schedule (ospf); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2449 | #endif /* #if 0 */ |
| 2450 | |
| 2451 | if (IS_DEBUG_OSPF (lsa, LSA_INSTALL)) |
| 2452 | zlog_info ("ospf_summary_lsa_install(): SPF scheduled"); |
| 2453 | } |
| 2454 | |
| 2455 | if (IS_LSA_SELF (new)) |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 2456 | ospf_refresher_register_lsa (ospf, new); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2457 | |
| 2458 | return new; |
| 2459 | } |
| 2460 | |
| 2461 | /* Install ASBR-summary-LSA to an area. */ |
| 2462 | struct ospf_lsa * |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 2463 | ospf_summary_asbr_lsa_install (struct ospf *ospf, struct ospf_lsa *new, |
| 2464 | int rt_recalc) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2465 | { |
| 2466 | if (rt_recalc && !IS_LSA_SELF (new)) |
| 2467 | { |
| 2468 | /* RFC 2328 Section 13.2 Summary-LSAs |
| 2469 | The best route to the destination described by the summary- |
| 2470 | LSA must be recalculated (see Section 16.5). If this |
| 2471 | destination is an AS boundary router, it may also be |
| 2472 | necessary to re-examine all the AS-external-LSAs. |
| 2473 | */ |
| 2474 | #if 0 |
| 2475 | /* These don't exist yet... */ |
| 2476 | ospf_summary_incremental_update(new); |
| 2477 | /* Isn't this done by the above call? |
| 2478 | - RFC 2328 Section 16.5 implies it should be */ |
| 2479 | /* ospf_ase_calculate_schedule(); */ |
| 2480 | #else /* #if 0 */ |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 2481 | ospf_spf_calculate_schedule (ospf); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2482 | #endif /* #if 0 */ |
| 2483 | } |
| 2484 | |
| 2485 | /* register LSA to refresh-list. */ |
| 2486 | if (IS_LSA_SELF (new)) |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 2487 | ospf_refresher_register_lsa (ospf, new); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2488 | |
| 2489 | return new; |
| 2490 | } |
| 2491 | |
| 2492 | /* Install AS-external-LSA. */ |
| 2493 | struct ospf_lsa * |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 2494 | ospf_external_lsa_install (struct ospf *ospf, struct ospf_lsa *new, |
| 2495 | int rt_recalc) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2496 | { |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 2497 | ospf_ase_register_external_lsa (new, ospf); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2498 | /* If LSA is not self-originated, calculate an external route. */ |
| 2499 | if (rt_recalc) |
| 2500 | { |
| 2501 | /* RFC 2328 Section 13.2 AS-external-LSAs |
| 2502 | The best route to the destination described by the AS- |
| 2503 | external-LSA must be recalculated (see Section 16.6). |
| 2504 | */ |
| 2505 | |
| 2506 | if (!IS_LSA_SELF (new)) |
paul | d4a53d5 | 2003-07-12 21:30:57 +0000 | [diff] [blame] | 2507 | ospf_ase_incremental_update (ospf, new); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2508 | } |
| 2509 | |
paul | d748032 | 2003-05-16 17:31:51 +0000 | [diff] [blame] | 2510 | #ifdef HAVE_NSSA |
paul | d4a53d5 | 2003-07-12 21:30:57 +0000 | [diff] [blame] | 2511 | if (new->data->type == OSPF_AS_NSSA_LSA) |
| 2512 | { |
| 2513 | /* There is no point to register selforiginate Type-7 LSA for |
| 2514 | * refreshing. We rely on refreshing Type-5 LSA's |
| 2515 | */ |
| 2516 | if (IS_LSA_SELF (new)) |
| 2517 | return new; |
| 2518 | else |
| 2519 | { |
| 2520 | /* Try refresh type-5 translated LSA for this LSA, if one exists. |
| 2521 | * New translations will be taken care of by the abr_task. |
| 2522 | */ |
| 2523 | ospf_translated_nssa_refresh (ospf, new, NULL); |
| 2524 | } |
| 2525 | } |
paul | d748032 | 2003-05-16 17:31:51 +0000 | [diff] [blame] | 2526 | #endif /* HAVE_NSSA */ |
| 2527 | |
paul | d4a53d5 | 2003-07-12 21:30:57 +0000 | [diff] [blame] | 2528 | /* Register self-originated LSA to refresh queue. |
paul | 8fc0f64 | 2003-07-13 01:36:06 +0000 | [diff] [blame] | 2529 | * Leave Translated LSAs alone if NSSA is enabled |
paul | d4a53d5 | 2003-07-12 21:30:57 +0000 | [diff] [blame] | 2530 | */ |
paul | 8fc0f64 | 2003-07-13 01:36:06 +0000 | [diff] [blame] | 2531 | if (IS_LSA_SELF (new) |
| 2532 | #ifdef HAVE_NSSA |
| 2533 | && !CHECK_FLAG (new->flags, OSPF_LSA_LOCAL_XLT ) |
| 2534 | #endif /* HAVE_NSSA */ |
| 2535 | ) |
| 2536 | |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 2537 | ospf_refresher_register_lsa (ospf, new); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2538 | |
| 2539 | return new; |
| 2540 | } |
| 2541 | |
| 2542 | void |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 2543 | ospf_discard_from_db (struct ospf *ospf, |
| 2544 | struct ospf_lsdb *lsdb, struct ospf_lsa *lsa) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2545 | { |
| 2546 | struct ospf_lsa *old; |
| 2547 | |
| 2548 | old = ospf_lsdb_lookup (lsdb, lsa); |
| 2549 | |
| 2550 | if (!old) |
| 2551 | return; |
| 2552 | |
| 2553 | if (old->refresh_list >= 0) |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 2554 | ospf_refresher_unregister_lsa (ospf, old); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2555 | |
| 2556 | switch (old->data->type) |
| 2557 | { |
| 2558 | case OSPF_AS_EXTERNAL_LSA: |
| 2559 | #ifdef HAVE_OPAQUE_LSA |
| 2560 | case OSPF_OPAQUE_AS_LSA: |
| 2561 | #endif /* HAVE_OPAQUE_LSA */ |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 2562 | ospf_ls_retransmit_delete_nbr_as (ospf, old); |
| 2563 | ospf_ase_unregister_external_lsa (old, ospf); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2564 | break; |
paul | d748032 | 2003-05-16 17:31:51 +0000 | [diff] [blame] | 2565 | #ifdef HAVE_NSSA |
| 2566 | case OSPF_AS_NSSA_LSA: |
| 2567 | ospf_ls_retransmit_delete_nbr_area (old->area, old); |
| 2568 | ospf_ase_unregister_external_lsa (old, ospf); |
| 2569 | break; |
| 2570 | #endif /* HAVE_NSSA */ |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2571 | default: |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 2572 | ospf_ls_retransmit_delete_nbr_area (old->area, old); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2573 | break; |
| 2574 | } |
| 2575 | |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 2576 | ospf_lsa_maxage_delete (ospf, old); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2577 | ospf_lsa_discard (old); |
| 2578 | } |
| 2579 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2580 | struct ospf_lsa * |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 2581 | ospf_lsa_install (struct ospf *ospf, struct ospf_interface *oi, |
| 2582 | struct ospf_lsa *lsa) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2583 | { |
| 2584 | struct ospf_lsa *new = NULL; |
| 2585 | struct ospf_lsa *old = NULL; |
| 2586 | struct ospf_lsdb *lsdb = NULL; |
| 2587 | int rt_recalc; |
| 2588 | |
| 2589 | /* Set LSDB. */ |
| 2590 | switch (lsa->data->type) |
| 2591 | { |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 2592 | #ifdef HAVE_NSSA |
paul | f2c8065 | 2002-12-13 21:44:27 +0000 | [diff] [blame] | 2593 | /* kevinm */ |
| 2594 | case OSPF_AS_NSSA_LSA: |
| 2595 | if (lsa->area) |
| 2596 | lsdb = lsa->area->lsdb; |
| 2597 | else |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 2598 | lsdb = ospf->lsdb; |
paul | f2c8065 | 2002-12-13 21:44:27 +0000 | [diff] [blame] | 2599 | break; |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 2600 | #endif /* HAVE_NSSA */ |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2601 | case OSPF_AS_EXTERNAL_LSA: |
| 2602 | #ifdef HAVE_OPAQUE_LSA |
| 2603 | case OSPF_OPAQUE_AS_LSA: |
| 2604 | #endif /* HAVE_OPAQUE_LSA */ |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 2605 | lsdb = ospf->lsdb; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2606 | break; |
| 2607 | default: |
| 2608 | lsdb = lsa->area->lsdb; |
| 2609 | break; |
| 2610 | } |
| 2611 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2612 | assert (lsdb); |
| 2613 | |
| 2614 | /* RFC 2328 13.2. Installing LSAs in the database |
| 2615 | |
| 2616 | Installing a new LSA in the database, either as the result of |
| 2617 | flooding or a newly self-originated LSA, may cause the OSPF |
| 2618 | routing table structure to be recalculated. The contents of the |
| 2619 | new LSA should be compared to the old instance, if present. If |
| 2620 | there is no difference, there is no need to recalculate the |
| 2621 | routing table. When comparing an LSA to its previous instance, |
| 2622 | the following are all considered to be differences in contents: |
| 2623 | |
| 2624 | o The LSA's Options field has changed. |
| 2625 | |
| 2626 | o One of the LSA instances has LS age set to MaxAge, and |
| 2627 | the other does not. |
| 2628 | |
| 2629 | o The length field in the LSA header has changed. |
| 2630 | |
| 2631 | o The body of the LSA (i.e., anything outside the 20-byte |
| 2632 | LSA header) has changed. Note that this excludes changes |
| 2633 | in LS Sequence Number and LS Checksum. |
| 2634 | |
| 2635 | */ |
| 2636 | /* Look up old LSA and determine if any SPF calculation or incremental |
| 2637 | update is needed */ |
| 2638 | old = ospf_lsdb_lookup (lsdb, lsa); |
| 2639 | |
| 2640 | /* Do comparision and record if recalc needed. */ |
| 2641 | rt_recalc = 0; |
| 2642 | if ( old == NULL || ospf_lsa_different(old, lsa)) |
| 2643 | rt_recalc = 1; |
| 2644 | |
paul | 7ddf1d6 | 2003-10-13 09:06:46 +0000 | [diff] [blame] | 2645 | /* |
| 2646 | Sequence number check (Section 14.1 of rfc 2328) |
| 2647 | "Premature aging is used when it is time for a self-originated |
| 2648 | LSA's sequence number field to wrap. At this point, the current |
| 2649 | LSA instance (having LS sequence number MaxSequenceNumber) must |
| 2650 | be prematurely aged and flushed from the routing domain before a |
| 2651 | new instance with sequence number equal to InitialSequenceNumber |
| 2652 | can be originated. " |
| 2653 | */ |
| 2654 | |
| 2655 | if (lsa->data->ls_seqnum - 1 == htonl(OSPF_MAX_SEQUENCE_NUMBER)) |
| 2656 | { |
| 2657 | if (ospf_lsa_is_self_originated(ospf, lsa)) |
| 2658 | { |
| 2659 | lsa->data->ls_seqnum = htonl(OSPF_MAX_SEQUENCE_NUMBER); |
| 2660 | if (!IS_LSA_MAXAGE(lsa)) |
| 2661 | lsa->flags |= OSPF_LSA_PREMATURE_AGE; |
| 2662 | lsa->data->ls_age = htons (OSPF_LSA_MAXAGE); |
| 2663 | |
| 2664 | if (IS_DEBUG_OSPF (lsa, LSA_REFRESH)) |
| 2665 | { |
| 2666 | zlog_info ("ospf_lsa_install() Premature Aging " |
| 2667 | "lsa 0x%lx", (u_long)lsa); |
| 2668 | ospf_lsa_header_dump (lsa->data); |
| 2669 | } |
| 2670 | } |
| 2671 | else |
| 2672 | { |
| 2673 | if (IS_DEBUG_OSPF (lsa, LSA_GENERATE)) |
| 2674 | { |
| 2675 | zlog_info ("ospf_lsa_install() got an lsa with seq 0x80000000 " |
| 2676 | "that was not self originated. Ignoring\n"); |
| 2677 | ospf_lsa_header_dump (lsa->data); |
| 2678 | } |
| 2679 | return old; |
| 2680 | } |
| 2681 | } |
| 2682 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2683 | /* discard old LSA from LSDB */ |
| 2684 | if (old != NULL) |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 2685 | ospf_discard_from_db (ospf, lsdb, lsa); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2686 | |
| 2687 | /* Insert LSA to LSDB. */ |
| 2688 | ospf_lsdb_add (lsdb, lsa); |
| 2689 | lsa->lsdb = lsdb; |
| 2690 | |
| 2691 | /* Calculate Checksum if self-originated?. */ |
| 2692 | if (IS_LSA_SELF (lsa)) |
| 2693 | ospf_lsa_checksum (lsa->data); |
| 2694 | |
| 2695 | /* Do LSA specific installation process. */ |
| 2696 | switch (lsa->data->type) |
| 2697 | { |
| 2698 | case OSPF_ROUTER_LSA: |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 2699 | new = ospf_router_lsa_install (ospf, lsa, rt_recalc); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2700 | break; |
| 2701 | case OSPF_NETWORK_LSA: |
| 2702 | assert (oi); |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 2703 | new = ospf_network_lsa_install (ospf, oi, lsa, rt_recalc); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2704 | break; |
| 2705 | case OSPF_SUMMARY_LSA: |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 2706 | new = ospf_summary_lsa_install (ospf, lsa, rt_recalc); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2707 | break; |
| 2708 | case OSPF_ASBR_SUMMARY_LSA: |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 2709 | new = ospf_summary_asbr_lsa_install (ospf, lsa, rt_recalc); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2710 | break; |
| 2711 | case OSPF_AS_EXTERNAL_LSA: |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 2712 | new = ospf_external_lsa_install (ospf, lsa, rt_recalc); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2713 | break; |
| 2714 | #ifdef HAVE_OPAQUE_LSA |
| 2715 | case OSPF_OPAQUE_LINK_LSA: |
paul | 09e4efd | 2003-01-18 00:12:02 +0000 | [diff] [blame] | 2716 | if (IS_LSA_SELF (lsa)) |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 2717 | lsa->oi = oi; /* Specify outgoing ospf-interface for this LSA. */ |
paul | 09e4efd | 2003-01-18 00:12:02 +0000 | [diff] [blame] | 2718 | else |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 2719 | ; /* Incoming "oi" for this LSA has set at LSUpd reception. */ |
paul | 09e4efd | 2003-01-18 00:12:02 +0000 | [diff] [blame] | 2720 | /* Fallthrough */ |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2721 | case OSPF_OPAQUE_AREA_LSA: |
| 2722 | case OSPF_OPAQUE_AS_LSA: |
| 2723 | new = ospf_opaque_lsa_install (lsa, rt_recalc); |
| 2724 | break; |
| 2725 | #endif /* HAVE_OPAQUE_LSA */ |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2726 | #ifdef HAVE_NSSA |
paul | d4a53d5 | 2003-07-12 21:30:57 +0000 | [diff] [blame] | 2727 | case OSPF_AS_NSSA_LSA: |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 2728 | new = ospf_external_lsa_install (ospf, lsa, rt_recalc); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2729 | #endif /* HAVE_NSSA */ |
paul | d4a53d5 | 2003-07-12 21:30:57 +0000 | [diff] [blame] | 2730 | default: /* type-6,8,9....nothing special */ |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2731 | break; |
| 2732 | } |
| 2733 | |
| 2734 | if (new == NULL) |
| 2735 | return new; /* Installation failed, cannot proceed further -- endo. */ |
| 2736 | |
| 2737 | /* Debug logs. */ |
| 2738 | if (IS_DEBUG_OSPF (lsa, LSA_INSTALL)) |
| 2739 | { |
| 2740 | char area_str[INET_ADDRSTRLEN]; |
| 2741 | |
| 2742 | switch (lsa->data->type) |
| 2743 | { |
| 2744 | case OSPF_AS_EXTERNAL_LSA: |
| 2745 | #ifdef HAVE_OPAQUE_LSA |
| 2746 | case OSPF_OPAQUE_AS_LSA: |
| 2747 | #endif /* HAVE_OPAQUE_LSA */ |
paul | f2c8065 | 2002-12-13 21:44:27 +0000 | [diff] [blame] | 2748 | #ifdef HAVE_NSSA |
| 2749 | case OSPF_AS_NSSA_LSA: |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 2750 | #endif /* HAVE_NSSA */ |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2751 | zlog_info ("LSA[%s]: Install %s", |
| 2752 | dump_lsa_key (new), |
| 2753 | LOOKUP (ospf_lsa_type_msg, new->data->type)); |
| 2754 | break; |
| 2755 | default: |
| 2756 | strcpy (area_str, inet_ntoa (new->area->area_id)); |
| 2757 | zlog_info ("LSA[%s]: Install %s to Area %s", |
| 2758 | dump_lsa_key (new), |
| 2759 | LOOKUP (ospf_lsa_type_msg, new->data->type), area_str); |
| 2760 | break; |
| 2761 | } |
| 2762 | } |
| 2763 | |
paul | 7ddf1d6 | 2003-10-13 09:06:46 +0000 | [diff] [blame] | 2764 | /* |
| 2765 | If received LSA' ls_age is MaxAge, or lsa is being prematurely aged |
| 2766 | (it's getting flushed out of the area), set LSA on MaxAge LSA list. |
| 2767 | */ |
| 2768 | if ((lsa->flags & OSPF_LSA_PREMATURE_AGE) || |
| 2769 | (IS_LSA_MAXAGE (new) && !IS_LSA_SELF (new))) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2770 | { |
paul | 7ddf1d6 | 2003-10-13 09:06:46 +0000 | [diff] [blame] | 2771 | if (IS_DEBUG_OSPF (lsa, LSA_INSTALL)) |
| 2772 | zlog_info ("LSA[Type%d:%s]: Install LSA 0x%lx, MaxAge", |
| 2773 | new->data->type, inet_ntoa (new->data->id), (u_long)lsa); |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 2774 | ospf_lsa_maxage (ospf, lsa); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2775 | } |
| 2776 | |
| 2777 | return new; |
| 2778 | } |
| 2779 | |
| 2780 | |
| 2781 | int |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 2782 | ospf_check_nbr_status (struct ospf *ospf) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2783 | { |
| 2784 | listnode node; |
| 2785 | |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 2786 | for (node = listhead (ospf->oiflist); node; node = nextnode (node)) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2787 | { |
| 2788 | struct ospf_interface *oi = getdata (node); |
| 2789 | struct route_node *rn; |
| 2790 | struct ospf_neighbor *nbr; |
| 2791 | |
| 2792 | if (ospf_if_is_enable (oi)) |
| 2793 | for (rn = route_top (oi->nbrs); rn; rn = route_next (rn)) |
| 2794 | if ((nbr = rn->info) != NULL) |
| 2795 | if (nbr->state == NSM_Exchange || nbr->state == NSM_Loading) |
| 2796 | { |
| 2797 | route_unlock_node (rn); |
| 2798 | return 0; |
| 2799 | } |
| 2800 | } |
| 2801 | |
| 2802 | return 1; |
| 2803 | } |
| 2804 | |
| 2805 | |
| 2806 | #ifdef ORIGINAL_CODING |
| 2807 | /* This function flood the maxaged LSA to DR. */ |
| 2808 | void |
| 2809 | ospf_maxage_flood (struct ospf_lsa *lsa) |
| 2810 | { |
| 2811 | switch (lsa->data->type) |
| 2812 | { |
| 2813 | case OSPF_ROUTER_LSA: |
| 2814 | case OSPF_NETWORK_LSA: |
| 2815 | case OSPF_SUMMARY_LSA: |
| 2816 | case OSPF_ASBR_SUMMARY_LSA: |
| 2817 | #ifdef HAVE_NSSA |
| 2818 | case OSPF_AS_NSSA_LSA: |
| 2819 | #endif /* HAVE_NSSA */ |
| 2820 | #ifdef HAVE_OPAQUE_LSA |
| 2821 | case OSPF_OPAQUE_LINK_LSA: |
| 2822 | case OSPF_OPAQUE_AREA_LSA: |
| 2823 | #endif /* HAVE_OPAQUE_LSA */ |
| 2824 | ospf_flood_through_area (lsa->area, NULL, lsa); |
| 2825 | break; |
| 2826 | case OSPF_AS_EXTERNAL_LSA: |
| 2827 | #ifdef HAVE_OPAQUE_LSA |
| 2828 | case OSPF_OPAQUE_AS_LSA: |
| 2829 | #endif /* HAVE_OPAQUE_LSA */ |
| 2830 | ospf_flood_through_as (NULL, lsa); |
| 2831 | break; |
| 2832 | default: |
| 2833 | break; |
| 2834 | } |
| 2835 | } |
| 2836 | #endif /* ORIGINAL_CODING */ |
| 2837 | |
| 2838 | int |
| 2839 | ospf_maxage_lsa_remover (struct thread *thread) |
| 2840 | { |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 2841 | struct ospf *ospf = THREAD_ARG (thread); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2842 | listnode node; |
| 2843 | listnode next; |
| 2844 | int reschedule = 0; |
| 2845 | |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 2846 | ospf->t_maxage = NULL; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2847 | |
| 2848 | if (IS_DEBUG_OSPF (lsa, LSA_FLOODING)) |
| 2849 | zlog_info ("LSA[MaxAge]: remover Start"); |
| 2850 | |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 2851 | reschedule = !ospf_check_nbr_status (ospf); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2852 | |
| 2853 | if (!reschedule) |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 2854 | for (node = listhead (ospf->maxage_lsa); node; node = next) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2855 | { |
| 2856 | struct ospf_lsa *lsa = getdata (node); |
| 2857 | next = node->next; |
| 2858 | |
| 2859 | if (lsa->retransmit_counter > 0) |
| 2860 | { |
| 2861 | reschedule = 1; |
| 2862 | continue; |
| 2863 | } |
| 2864 | |
| 2865 | /* Remove LSA from the LSDB */ |
| 2866 | if (CHECK_FLAG (lsa->flags, OSPF_LSA_SELF)) |
| 2867 | if (IS_DEBUG_OSPF (lsa, LSA_FLOODING)) |
paul | 7ddf1d6 | 2003-10-13 09:06:46 +0000 | [diff] [blame] | 2868 | zlog_info ("LSA[Type%d:%s]: LSA 0x%lx is self-oririnated: ", |
| 2869 | lsa->data->type, inet_ntoa (lsa->data->id), (u_long)lsa); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2870 | |
| 2871 | if (IS_DEBUG_OSPF (lsa, LSA_FLOODING)) |
| 2872 | zlog_info ("LSA[Type%d:%s]: MaxAge LSA removed from list", |
| 2873 | lsa->data->type, inet_ntoa (lsa->data->id)); |
| 2874 | |
| 2875 | /* Flood max age LSA. */ |
| 2876 | #ifdef ORIGINAL_CODING |
| 2877 | ospf_maxage_flood (lsa); |
| 2878 | #else /* ORIGINAL_CODING */ |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 2879 | ospf_flood_through (ospf, NULL, lsa); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2880 | #endif /* ORIGINAL_CODING */ |
| 2881 | |
paul | 7ddf1d6 | 2003-10-13 09:06:46 +0000 | [diff] [blame] | 2882 | if (lsa->flags & OSPF_LSA_PREMATURE_AGE) |
| 2883 | { |
| 2884 | if (IS_DEBUG_OSPF (lsa, LSA_FLOODING)) |
| 2885 | zlog_info ("originating new router lsa for lsa 0x%lx \n", |
| 2886 | (u_long)lsa); |
| 2887 | ospf_router_lsa_originate(lsa->area); |
| 2888 | } |
| 2889 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2890 | /* Remove from lsdb. */ |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 2891 | ospf_discard_from_db (ospf, lsa->lsdb, lsa); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2892 | ospf_lsdb_delete (lsa->lsdb, lsa); |
| 2893 | } |
| 2894 | |
| 2895 | /* A MaxAge LSA must be removed immediately from the router's link |
| 2896 | state database as soon as both a) it is no longer contained on any |
| 2897 | neighbor Link state retransmission lists and b) none of the router's |
| 2898 | neighbors are in states Exchange or Loading. */ |
| 2899 | if (reschedule) |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 2900 | OSPF_TIMER_ON (ospf->t_maxage, ospf_maxage_lsa_remover, 2); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2901 | |
| 2902 | return 0; |
| 2903 | } |
| 2904 | |
| 2905 | int |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 2906 | ospf_lsa_maxage_exist (struct ospf *ospf, struct ospf_lsa *new) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2907 | { |
| 2908 | listnode node; |
| 2909 | |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 2910 | for (node = listhead (ospf->maxage_lsa); node; nextnode (node)) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2911 | if (((struct ospf_lsa *) node->data) == new) |
| 2912 | return 1; |
| 2913 | |
| 2914 | return 0; |
| 2915 | } |
| 2916 | |
| 2917 | void |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 2918 | ospf_lsa_maxage_delete (struct ospf *ospf, struct ospf_lsa *lsa) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2919 | { |
| 2920 | listnode n; |
| 2921 | |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 2922 | if ((n = listnode_lookup (ospf->maxage_lsa, lsa))) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2923 | { |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 2924 | list_delete_node (ospf->maxage_lsa, n); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2925 | ospf_lsa_unlock (lsa); |
| 2926 | } |
| 2927 | } |
| 2928 | |
| 2929 | void |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 2930 | ospf_lsa_maxage (struct ospf *ospf, struct ospf_lsa *lsa) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2931 | { |
| 2932 | /* When we saw a MaxAge LSA flooded to us, we put it on the list |
| 2933 | and schedule the MaxAge LSA remover. */ |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 2934 | if (ospf_lsa_maxage_exist (ospf, lsa)) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2935 | { |
| 2936 | if (IS_DEBUG_OSPF (lsa, LSA_FLOODING)) |
| 2937 | zlog_info ("LSA[Type%d:%s]: %p already exists on MaxAge LSA list", |
| 2938 | lsa->data->type, inet_ntoa (lsa->data->id), lsa); |
| 2939 | return; |
| 2940 | } |
| 2941 | |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 2942 | listnode_add (ospf->maxage_lsa, ospf_lsa_lock (lsa)); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2943 | |
| 2944 | if (IS_DEBUG_OSPF (lsa, LSA_FLOODING)) |
| 2945 | zlog_info ("LSA[%s]: MaxAge LSA remover scheduled.", dump_lsa_key (lsa)); |
| 2946 | |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 2947 | OSPF_TIMER_ON (ospf->t_maxage, ospf_maxage_lsa_remover, 2); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2948 | } |
| 2949 | |
| 2950 | int |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 2951 | ospf_lsa_maxage_walker_remover (struct ospf *ospf, struct ospf_lsa *lsa) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2952 | { |
| 2953 | #ifdef HAVE_NSSA |
| 2954 | /* Stay away from any Local Translated Type-7 LSAs */ |
| 2955 | if (CHECK_FLAG (lsa->flags, OSPF_LSA_LOCAL_XLT)) |
| 2956 | return 0; |
| 2957 | #endif /* HAVE_NSSA */ |
| 2958 | |
| 2959 | if (IS_LSA_MAXAGE (lsa)) |
| 2960 | /* Self-originated LSAs should NOT time-out instead, |
| 2961 | they're flushed and submitted to the max_age list explicitly. */ |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 2962 | if (!ospf_lsa_is_self_originated (ospf, lsa)) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2963 | { |
| 2964 | if (IS_DEBUG_OSPF (lsa, LSA_FLOODING)) |
| 2965 | zlog_info("LSA[%s]: is MaxAge", dump_lsa_key (lsa)); |
| 2966 | |
| 2967 | switch (lsa->data->type) |
| 2968 | { |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2969 | #ifdef HAVE_OPAQUE_LSA |
paul | 37163d6 | 2003-02-03 18:40:56 +0000 | [diff] [blame] | 2970 | case OSPF_OPAQUE_LINK_LSA: |
| 2971 | case OSPF_OPAQUE_AREA_LSA: |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2972 | case OSPF_OPAQUE_AS_LSA: |
paul | 09e4efd | 2003-01-18 00:12:02 +0000 | [diff] [blame] | 2973 | /* |
| 2974 | * As a general rule, whenever network topology has changed |
| 2975 | * (due to an LSA removal in this case), routing recalculation |
| 2976 | * should be triggered. However, this is not true for opaque |
| 2977 | * LSAs. Even if an opaque LSA instance is going to be removed |
| 2978 | * from the routing domain, it does not mean a change in network |
| 2979 | * topology, and thus, routing recalculation is not needed here. |
| 2980 | */ |
| 2981 | break; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2982 | #endif /* HAVE_OPAQUE_LSA */ |
paul | 09e4efd | 2003-01-18 00:12:02 +0000 | [diff] [blame] | 2983 | case OSPF_AS_EXTERNAL_LSA: |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 2984 | #ifdef HAVE_NSSA |
| 2985 | case OSPF_AS_NSSA_LSA: |
| 2986 | #endif /* HAVE_NSSA */ |
| 2987 | ospf_ase_incremental_update (ospf, lsa); |
| 2988 | break; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2989 | default: |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 2990 | ospf_spf_calculate_schedule (ospf); |
| 2991 | break; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2992 | } |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 2993 | ospf_lsa_maxage (ospf, lsa); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2994 | } |
| 2995 | |
| 2996 | return 0; |
| 2997 | } |
| 2998 | |
| 2999 | /* Periodical check of MaxAge LSA. */ |
| 3000 | int |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 3001 | ospf_lsa_maxage_walker (struct thread *thread) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 3002 | { |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 3003 | struct ospf *ospf = THREAD_ARG (thread); |
| 3004 | struct route_node *rn; |
| 3005 | struct ospf_lsa *lsa; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 3006 | listnode node; |
| 3007 | |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 3008 | ospf->t_maxage_walker = NULL; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 3009 | |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 3010 | for (node = listhead (ospf->areas); node; nextnode (node)) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 3011 | { |
| 3012 | struct ospf_area *area = node->data; |
| 3013 | |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 3014 | LSDB_LOOP (ROUTER_LSDB (area), rn, lsa) |
| 3015 | ospf_lsa_maxage_walker_remover (ospf, lsa); |
| 3016 | LSDB_LOOP (NETWORK_LSDB (area), rn, lsa) |
| 3017 | ospf_lsa_maxage_walker_remover (ospf, lsa); |
| 3018 | LSDB_LOOP (SUMMARY_LSDB (area), rn, lsa) |
| 3019 | ospf_lsa_maxage_walker_remover (ospf, lsa); |
| 3020 | LSDB_LOOP (ASBR_SUMMARY_LSDB (area), rn, lsa) |
| 3021 | ospf_lsa_maxage_walker_remover (ospf, lsa); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 3022 | #ifdef HAVE_OPAQUE_LSA |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 3023 | LSDB_LOOP (OPAQUE_AREA_LSDB (area), rn, lsa) |
| 3024 | ospf_lsa_maxage_walker_remover (ospf, lsa); |
| 3025 | LSDB_LOOP (OPAQUE_LINK_LSDB (area), rn, lsa) |
| 3026 | ospf_lsa_maxage_walker_remover (ospf, lsa); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 3027 | #endif /* HAVE_OPAQUE_LSA */ |
paul | 4fb949e | 2003-05-10 20:06:51 +0000 | [diff] [blame] | 3028 | #ifdef HAVE_NSSA |
| 3029 | LSDB_LOOP (NSSA_LSDB (area), rn, lsa) |
| 3030 | ospf_lsa_maxage_walker_remover (ospf, lsa); |
| 3031 | #endif /* HAVE_NSSA */ |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 3032 | } |
| 3033 | |
paul | 4fb949e | 2003-05-10 20:06:51 +0000 | [diff] [blame] | 3034 | /* for AS-external-LSAs. */ |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 3035 | if (ospf->lsdb) |
| 3036 | { |
| 3037 | LSDB_LOOP (EXTERNAL_LSDB (ospf), rn, lsa) |
| 3038 | ospf_lsa_maxage_walker_remover (ospf, lsa); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 3039 | #ifdef HAVE_OPAQUE_LSA |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 3040 | LSDB_LOOP (OPAQUE_AS_LSDB (ospf), rn, lsa) |
| 3041 | ospf_lsa_maxage_walker_remover (ospf, lsa); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 3042 | #endif /* HAVE_OPAQUE_LSA */ |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 3043 | } |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 3044 | |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 3045 | OSPF_TIMER_ON (ospf->t_maxage_walker, ospf_lsa_maxage_walker, |
| 3046 | OSPF_LSA_MAXAGE_CHECK_INTERVAL); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 3047 | return 0; |
| 3048 | } |
| 3049 | |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 3050 | struct ospf_lsa * |
| 3051 | ospf_lsa_lookup_by_prefix (struct ospf_lsdb *lsdb, u_char type, |
| 3052 | struct prefix_ipv4 *p, struct in_addr router_id) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 3053 | { |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 3054 | struct ospf_lsa *lsa; |
| 3055 | struct in_addr mask, id; |
| 3056 | struct lsa_header_mask |
| 3057 | { |
| 3058 | struct lsa_header header; |
| 3059 | struct in_addr mask; |
| 3060 | } *hmask; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 3061 | |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 3062 | lsa = ospf_lsdb_lookup_by_id (lsdb, type, p->prefix, router_id); |
| 3063 | if (lsa == NULL) |
| 3064 | return NULL; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 3065 | |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 3066 | masklen2ip (p->prefixlen, &mask); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 3067 | |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 3068 | hmask = (struct lsa_header_mask *) lsa->data; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 3069 | |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 3070 | if (mask.s_addr != hmask->mask.s_addr) |
| 3071 | { |
| 3072 | id.s_addr = p->prefix.s_addr | (~mask.s_addr); |
| 3073 | lsa = ospf_lsdb_lookup_by_id (lsdb, type, id, router_id); |
| 3074 | if (!lsa) |
| 3075 | return NULL; |
| 3076 | } |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 3077 | |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 3078 | return lsa; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 3079 | } |
| 3080 | |
| 3081 | struct ospf_lsa * |
| 3082 | ospf_lsa_lookup (struct ospf_area *area, u_int32_t type, |
| 3083 | struct in_addr id, struct in_addr adv_router) |
| 3084 | { |
paul | e05fba4 | 2003-04-13 20:20:53 +0000 | [diff] [blame] | 3085 | struct ospf *ospf = ospf_lookup(); |
| 3086 | assert(ospf); |
| 3087 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 3088 | switch (type) |
| 3089 | { |
| 3090 | case OSPF_ROUTER_LSA: |
| 3091 | case OSPF_NETWORK_LSA: |
| 3092 | case OSPF_SUMMARY_LSA: |
| 3093 | case OSPF_ASBR_SUMMARY_LSA: |
| 3094 | #ifdef HAVE_NSSA |
| 3095 | case OSPF_AS_NSSA_LSA: |
| 3096 | #endif /* HAVE_NSSA */ |
| 3097 | #ifdef HAVE_OPAQUE_LSA |
| 3098 | case OSPF_OPAQUE_LINK_LSA: |
| 3099 | case OSPF_OPAQUE_AREA_LSA: |
| 3100 | #endif /* HAVE_OPAQUE_LSA */ |
| 3101 | return ospf_lsdb_lookup_by_id (area->lsdb, type, id, adv_router); |
| 3102 | break; |
| 3103 | case OSPF_AS_EXTERNAL_LSA: |
| 3104 | #ifdef HAVE_OPAQUE_LSA |
| 3105 | case OSPF_OPAQUE_AS_LSA: |
| 3106 | #endif /* HAVE_OPAQUE_LSA */ |
paul | e05fba4 | 2003-04-13 20:20:53 +0000 | [diff] [blame] | 3107 | return ospf_lsdb_lookup_by_id (ospf->lsdb, type, id, adv_router); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 3108 | break; |
| 3109 | default: |
| 3110 | break; |
| 3111 | } |
| 3112 | |
| 3113 | return NULL; |
| 3114 | } |
| 3115 | |
| 3116 | struct ospf_lsa * |
| 3117 | ospf_lsa_lookup_by_id (struct ospf_area *area, u_int32_t type, |
| 3118 | struct in_addr id) |
| 3119 | { |
| 3120 | struct ospf_lsa *lsa; |
| 3121 | struct route_node *rn; |
| 3122 | |
| 3123 | switch (type) |
| 3124 | { |
| 3125 | case OSPF_ROUTER_LSA: |
| 3126 | return ospf_lsdb_lookup_by_id (area->lsdb, type, id, id); |
| 3127 | break; |
| 3128 | case OSPF_NETWORK_LSA: |
| 3129 | for (rn = route_top (NETWORK_LSDB (area)); rn; rn = route_next (rn)) |
| 3130 | if ((lsa = rn->info)) |
| 3131 | if (IPV4_ADDR_SAME (&lsa->data->id, &id)) |
| 3132 | { |
| 3133 | route_unlock_node (rn); |
| 3134 | return lsa; |
| 3135 | } |
| 3136 | break; |
| 3137 | case OSPF_SUMMARY_LSA: |
| 3138 | case OSPF_ASBR_SUMMARY_LSA: |
| 3139 | /* Currently not used. */ |
| 3140 | assert (1); |
| 3141 | return ospf_lsdb_lookup_by_id (area->lsdb, type, id, id); |
| 3142 | break; |
| 3143 | case OSPF_AS_EXTERNAL_LSA: |
paul | d4a53d5 | 2003-07-12 21:30:57 +0000 | [diff] [blame] | 3144 | case OSPF_AS_NSSA_LSA: |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 3145 | #ifdef HAVE_OPAQUE_LSA |
| 3146 | case OSPF_OPAQUE_LINK_LSA: |
| 3147 | case OSPF_OPAQUE_AREA_LSA: |
| 3148 | case OSPF_OPAQUE_AS_LSA: |
| 3149 | /* Currently not used. */ |
| 3150 | break; |
| 3151 | #endif /* HAVE_OPAQUE_LSA */ |
| 3152 | default: |
| 3153 | break; |
| 3154 | } |
| 3155 | |
| 3156 | return NULL; |
| 3157 | } |
| 3158 | |
| 3159 | struct ospf_lsa * |
| 3160 | ospf_lsa_lookup_by_header (struct ospf_area *area, struct lsa_header *lsah) |
| 3161 | { |
| 3162 | struct ospf_lsa *match; |
| 3163 | |
| 3164 | #ifdef HAVE_OPAQUE_LSA |
| 3165 | /* |
| 3166 | * Strictly speaking, the LSA-ID field for Opaque-LSAs (type-9/10/11) |
| 3167 | * is redefined to have two subfields; opaque-type and opaque-id. |
| 3168 | * However, it is harmless to treat the two sub fields together, as if |
| 3169 | * they two were forming a unique LSA-ID. |
| 3170 | */ |
| 3171 | #endif /* HAVE_OPAQUE_LSA */ |
| 3172 | |
| 3173 | match = ospf_lsa_lookup (area, lsah->type, lsah->id, lsah->adv_router); |
| 3174 | |
| 3175 | if (match == NULL) |
| 3176 | if (IS_DEBUG_OSPF (lsa, LSA) == OSPF_DEBUG_LSA) |
| 3177 | zlog_info ("LSA[Type%d:%s]: Lookup by header, NO MATCH", |
| 3178 | lsah->type, inet_ntoa (lsah->id)); |
| 3179 | |
| 3180 | return match; |
| 3181 | } |
| 3182 | |
| 3183 | /* return +n, l1 is more recent. |
| 3184 | return -n, l2 is more recent. |
| 3185 | return 0, l1 and l2 is identical. */ |
| 3186 | int |
| 3187 | ospf_lsa_more_recent (struct ospf_lsa *l1, struct ospf_lsa *l2) |
| 3188 | { |
| 3189 | int r; |
| 3190 | int x, y; |
| 3191 | |
| 3192 | if (l1 == NULL && l2 == NULL) |
| 3193 | return 0; |
| 3194 | if (l1 == NULL) |
| 3195 | return -1; |
| 3196 | if (l2 == NULL) |
| 3197 | return 1; |
| 3198 | |
| 3199 | /* compare LS sequence number. */ |
| 3200 | x = (int) ntohl (l1->data->ls_seqnum); |
| 3201 | y = (int) ntohl (l2->data->ls_seqnum); |
| 3202 | if (x > y) |
| 3203 | return 1; |
| 3204 | if (x < y) |
| 3205 | return -1; |
| 3206 | |
| 3207 | /* compare LS checksum. */ |
| 3208 | r = ntohs (l1->data->checksum) - ntohs (l2->data->checksum); |
| 3209 | if (r) |
| 3210 | return r; |
| 3211 | |
| 3212 | /* compare LS age. */ |
| 3213 | if (IS_LSA_MAXAGE (l1) && !IS_LSA_MAXAGE (l2)) |
| 3214 | return 1; |
| 3215 | else if (!IS_LSA_MAXAGE (l1) && IS_LSA_MAXAGE (l2)) |
| 3216 | return -1; |
| 3217 | |
| 3218 | /* compare LS age with MaxAgeDiff. */ |
| 3219 | if (LS_AGE (l1) - LS_AGE (l2) > OSPF_LSA_MAXAGE_DIFF) |
| 3220 | return -1; |
| 3221 | else if (LS_AGE (l2) - LS_AGE (l1) > OSPF_LSA_MAXAGE_DIFF) |
| 3222 | return 1; |
| 3223 | |
| 3224 | /* LSAs are identical. */ |
| 3225 | return 0; |
| 3226 | } |
| 3227 | |
| 3228 | /* If two LSAs are different, return 1, otherwise return 0. */ |
| 3229 | int |
| 3230 | ospf_lsa_different (struct ospf_lsa *l1, struct ospf_lsa *l2) |
| 3231 | { |
| 3232 | char *p1, *p2; |
| 3233 | assert (l1); |
| 3234 | assert (l2); |
| 3235 | assert (l1->data); |
| 3236 | assert (l2->data); |
| 3237 | |
| 3238 | if (l1->data->options != l2->data->options) |
| 3239 | return 1; |
| 3240 | |
| 3241 | if (IS_LSA_MAXAGE (l1) && !IS_LSA_MAXAGE (l2)) |
| 3242 | return 1; |
| 3243 | |
| 3244 | if (IS_LSA_MAXAGE (l2) && !IS_LSA_MAXAGE (l1)) |
| 3245 | return 1; |
| 3246 | |
| 3247 | if (l1->data->length != l2->data->length) |
| 3248 | return 1; |
| 3249 | |
| 3250 | if (l1->data->length == 0) |
| 3251 | return 1; |
| 3252 | |
paul | d182583 | 2003-04-03 01:27:01 +0000 | [diff] [blame] | 3253 | assert ( ntohs(l1->data->length) > OSPF_LSA_HEADER_SIZE); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 3254 | |
| 3255 | p1 = (char *) l1->data; |
| 3256 | p2 = (char *) l2->data; |
| 3257 | |
| 3258 | if (memcmp (p1 + OSPF_LSA_HEADER_SIZE, p2 + OSPF_LSA_HEADER_SIZE, |
| 3259 | ntohs( l1->data->length ) - OSPF_LSA_HEADER_SIZE) != 0) |
| 3260 | return 1; |
| 3261 | |
| 3262 | return 0; |
| 3263 | } |
| 3264 | |
| 3265 | #ifdef ORIGINAL_CODING |
| 3266 | void |
| 3267 | ospf_lsa_flush_self_originated (struct ospf_neighbor *nbr, |
| 3268 | struct ospf_lsa *self, |
| 3269 | struct ospf_lsa *new) |
| 3270 | { |
| 3271 | u_int32_t seqnum; |
| 3272 | |
| 3273 | /* Adjust LS Sequence Number. */ |
| 3274 | seqnum = ntohl (new->data->ls_seqnum) + 1; |
| 3275 | self->data->ls_seqnum = htonl (seqnum); |
| 3276 | |
| 3277 | /* Recalculate LSA checksum. */ |
| 3278 | ospf_lsa_checksum (self->data); |
| 3279 | |
| 3280 | /* Reflooding LSA. */ |
| 3281 | /* RFC2328 Section 13.3 |
| 3282 | On non-broadcast networks, separate Link State Update |
| 3283 | packets must be sent, as unicasts, to each adjacent neighbor |
| 3284 | (i.e., those in state Exchange or greater). The destination |
| 3285 | IP addresses for these packets are the neighbors' IP |
| 3286 | addresses. */ |
| 3287 | if (nbr->oi->type == OSPF_IFTYPE_NBMA) |
| 3288 | { |
| 3289 | struct route_node *rn; |
| 3290 | struct ospf_neighbor *onbr; |
| 3291 | |
| 3292 | for (rn = route_top (nbr->oi->nbrs); rn; rn = route_next (rn)) |
| 3293 | if ((onbr = rn->info) != NULL) |
| 3294 | if (onbr != nbr->oi->nbr_self && onbr->status >= NSM_Exchange) |
| 3295 | ospf_ls_upd_send_lsa (onbr, self, OSPF_SEND_PACKET_DIRECT); |
| 3296 | } |
| 3297 | else |
| 3298 | ospf_ls_upd_send_lsa (nbr, self, OSPF_SEND_PACKET_INDIRECT); |
| 3299 | |
| 3300 | if (IS_DEBUG_OSPF (lsa, LSA_GENERATE)) |
| 3301 | zlog_info ("LSA[Type%d:%s]: Flush self-originated LSA", |
| 3302 | self->data->type, inet_ntoa (self->data->id)); |
| 3303 | } |
| 3304 | #else /* ORIGINAL_CODING */ |
| 3305 | static int |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 3306 | ospf_lsa_flush_schedule (struct ospf *ospf, struct ospf_lsa *lsa) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 3307 | { |
| 3308 | if (lsa == NULL || !IS_LSA_SELF (lsa)) |
| 3309 | return 0; |
| 3310 | |
| 3311 | if (IS_DEBUG_OSPF_EVENT) |
| 3312 | zlog_info ("LSA[Type%d:%s]: Schedule self-originated LSA to FLUSH", lsa->data->type, inet_ntoa (lsa->data->id)); |
| 3313 | |
| 3314 | /* Force given lsa's age to MaxAge. */ |
| 3315 | lsa->data->ls_age = htons (OSPF_LSA_MAXAGE); |
| 3316 | |
| 3317 | switch (lsa->data->type) |
| 3318 | { |
| 3319 | #ifdef HAVE_OPAQUE_LSA |
| 3320 | case OSPF_OPAQUE_LINK_LSA: |
| 3321 | case OSPF_OPAQUE_AREA_LSA: |
| 3322 | case OSPF_OPAQUE_AS_LSA: |
| 3323 | ospf_opaque_lsa_refresh (lsa); |
| 3324 | break; |
| 3325 | #endif /* HAVE_OPAQUE_LSA */ |
| 3326 | default: |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 3327 | ospf_lsa_maxage (ospf, lsa); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 3328 | break; |
| 3329 | } |
| 3330 | |
| 3331 | return 0; |
| 3332 | } |
| 3333 | |
| 3334 | void |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 3335 | ospf_flush_self_originated_lsas_now (struct ospf *ospf) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 3336 | { |
| 3337 | listnode n1, n2; |
| 3338 | struct ospf_area *area; |
| 3339 | struct ospf_interface *oi; |
| 3340 | struct ospf_lsa *lsa; |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 3341 | struct route_node *rn; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 3342 | int need_to_flush_ase = 0; |
| 3343 | |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 3344 | for (n1 = listhead (ospf->areas); n1; nextnode (n1)) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 3345 | { |
| 3346 | if ((area = getdata (n1)) == NULL) |
| 3347 | continue; |
| 3348 | |
| 3349 | if ((lsa = area->router_lsa_self) != NULL) |
| 3350 | { |
| 3351 | if (IS_DEBUG_OSPF_EVENT) |
| 3352 | zlog_info ("LSA[Type%d:%s]: Schedule self-originated LSA to FLUSH", lsa->data->type, inet_ntoa (lsa->data->id)); |
| 3353 | |
| 3354 | ospf_lsa_flush_area (lsa, area); |
| 3355 | ospf_lsa_unlock (area->router_lsa_self); |
| 3356 | area->router_lsa_self = NULL; |
| 3357 | OSPF_TIMER_OFF (area->t_router_lsa_self); |
| 3358 | } |
| 3359 | |
| 3360 | for (n2 = listhead (area->oiflist); n2; nextnode (n2)) |
| 3361 | { |
| 3362 | if ((oi = getdata (n2)) == NULL) |
| 3363 | continue; |
| 3364 | |
| 3365 | if ((lsa = oi->network_lsa_self) != NULL |
| 3366 | && oi->state == ISM_DR |
| 3367 | && oi->full_nbrs > 0) |
| 3368 | { |
| 3369 | if (IS_DEBUG_OSPF_EVENT) |
| 3370 | zlog_info ("LSA[Type%d:%s]: Schedule self-originated LSA to FLUSH", lsa->data->type, inet_ntoa (lsa->data->id)); |
| 3371 | |
| 3372 | ospf_lsa_flush_area (oi->network_lsa_self, area); |
| 3373 | ospf_lsa_unlock (oi->network_lsa_self); |
| 3374 | oi->network_lsa_self = NULL; |
| 3375 | OSPF_TIMER_OFF (oi->t_network_lsa_self); |
| 3376 | } |
| 3377 | |
| 3378 | if (oi->type != OSPF_IFTYPE_VIRTUALLINK |
| 3379 | && area->external_routing == OSPF_AREA_DEFAULT) |
| 3380 | need_to_flush_ase = 1; |
| 3381 | } |
| 3382 | |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 3383 | LSDB_LOOP (SUMMARY_LSDB (area), rn, lsa) |
| 3384 | ospf_lsa_flush_schedule (ospf, lsa); |
| 3385 | LSDB_LOOP (ASBR_SUMMARY_LSDB (area), rn, lsa) |
| 3386 | ospf_lsa_flush_schedule (ospf, lsa); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 3387 | #ifdef HAVE_OPAQUE_LSA |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 3388 | LSDB_LOOP (OPAQUE_LINK_LSDB (area), rn, lsa) |
| 3389 | ospf_lsa_flush_schedule (ospf, lsa); |
| 3390 | LSDB_LOOP (OPAQUE_AREA_LSDB (area), rn, lsa) |
| 3391 | ospf_lsa_flush_schedule (ospf, lsa); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 3392 | #endif /* HAVE_OPAQUE_LSA */ |
| 3393 | } |
| 3394 | |
| 3395 | if (need_to_flush_ase) |
| 3396 | { |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 3397 | LSDB_LOOP (EXTERNAL_LSDB (ospf), rn, lsa) |
| 3398 | ospf_lsa_flush_schedule (ospf, lsa); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 3399 | #ifdef HAVE_OPAQUE_LSA |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 3400 | LSDB_LOOP (OPAQUE_AS_LSDB (ospf), rn, lsa) |
| 3401 | ospf_lsa_flush_schedule (ospf, lsa); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 3402 | #endif /* HAVE_OPAQUE_LSA */ |
| 3403 | } |
| 3404 | |
| 3405 | /* |
| 3406 | * Make sure that the MaxAge LSA remover is executed immediately, |
| 3407 | * without conflicting to other threads. |
| 3408 | */ |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 3409 | if (ospf->t_maxage != NULL) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 3410 | { |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 3411 | OSPF_TIMER_OFF (ospf->t_maxage); |
| 3412 | thread_execute (master, ospf_maxage_lsa_remover, ospf, 0); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 3413 | } |
| 3414 | |
| 3415 | return; |
| 3416 | } |
| 3417 | #endif /* ORIGINAL_CODING */ |
| 3418 | |
| 3419 | /* If there is self-originated LSA, then return 1, otherwise return 0. */ |
| 3420 | /* An interface-independent version of ospf_lsa_is_self_originated */ |
| 3421 | int |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 3422 | ospf_lsa_is_self_originated (struct ospf *ospf, struct ospf_lsa *lsa) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 3423 | { |
| 3424 | listnode node; |
| 3425 | |
| 3426 | /* This LSA is already checked. */ |
| 3427 | if (CHECK_FLAG (lsa->flags, OSPF_LSA_SELF_CHECKED)) |
| 3428 | return CHECK_FLAG (lsa->flags, OSPF_LSA_SELF); |
| 3429 | |
| 3430 | /* Make sure LSA is self-checked. */ |
| 3431 | SET_FLAG (lsa->flags, OSPF_LSA_SELF_CHECKED); |
| 3432 | |
| 3433 | /* AdvRouter and Router ID is the same. */ |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 3434 | if (IPV4_ADDR_SAME (&lsa->data->adv_router, &ospf->router_id)) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 3435 | SET_FLAG (lsa->flags, OSPF_LSA_SELF); |
| 3436 | |
| 3437 | /* LSA is router-LSA. */ |
| 3438 | else if (lsa->data->type == OSPF_ROUTER_LSA && |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 3439 | IPV4_ADDR_SAME (&lsa->data->id, &ospf->router_id)) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 3440 | SET_FLAG (lsa->flags, OSPF_LSA_SELF); |
| 3441 | |
| 3442 | /* LSA is network-LSA. Compare Link ID with all interfaces. */ |
| 3443 | else if (lsa->data->type == OSPF_NETWORK_LSA) |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 3444 | for (node = listhead (ospf->oiflist); node; nextnode (node)) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 3445 | { |
| 3446 | struct ospf_interface *oi = getdata (node); |
| 3447 | |
| 3448 | /* Ignore virtual link. */ |
| 3449 | if (oi->type != OSPF_IFTYPE_VIRTUALLINK) |
| 3450 | if (oi->address->family == AF_INET) |
| 3451 | if (IPV4_ADDR_SAME (&lsa->data->id, &oi->address->u.prefix4)) |
| 3452 | { |
| 3453 | /* to make it easier later */ |
| 3454 | SET_FLAG (lsa->flags, OSPF_LSA_SELF); |
| 3455 | return CHECK_FLAG (lsa->flags, OSPF_LSA_SELF); |
| 3456 | } |
| 3457 | } |
| 3458 | |
| 3459 | return CHECK_FLAG (lsa->flags, OSPF_LSA_SELF); |
| 3460 | } |
| 3461 | |
| 3462 | /* Get unique Link State ID. */ |
| 3463 | struct in_addr |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 3464 | ospf_lsa_unique_id (struct ospf *ospf, |
| 3465 | struct ospf_lsdb *lsdb, u_char type, struct prefix_ipv4 *p) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 3466 | { |
| 3467 | struct ospf_lsa *lsa; |
| 3468 | struct in_addr mask, id; |
| 3469 | |
| 3470 | id = p->prefix; |
| 3471 | |
| 3472 | /* Check existence of LSA instance. */ |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 3473 | lsa = ospf_lsdb_lookup_by_id (lsdb, type, id, ospf->router_id); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 3474 | if (lsa) |
| 3475 | { |
| 3476 | struct as_external_lsa *al = (struct as_external_lsa *) lsa->data; |
| 3477 | if (ip_masklen (al->mask) == p->prefixlen) |
| 3478 | { |
| 3479 | if (IS_DEBUG_OSPF (lsa, LSA_GENERATE)) |
| 3480 | zlog_warn ("ospf_lsa_unique_id(): " |
| 3481 | "Can't get Link State ID for %s/%d", |
| 3482 | inet_ntoa (p->prefix), p->prefixlen); |
| 3483 | /* id.s_addr = 0; */ |
| 3484 | id.s_addr = 0xffffffff; |
| 3485 | return id; |
| 3486 | } |
| 3487 | /* Masklen differs, then apply wildcard mask to Link State ID. */ |
| 3488 | else |
| 3489 | { |
| 3490 | masklen2ip (p->prefixlen, &mask); |
| 3491 | |
| 3492 | id.s_addr = p->prefix.s_addr | (~mask.s_addr); |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 3493 | lsa = ospf_lsdb_lookup_by_id (ospf->lsdb, type, |
| 3494 | id, ospf->router_id); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 3495 | if (lsa) |
| 3496 | { |
| 3497 | if (IS_DEBUG_OSPF (lsa, LSA_GENERATE)) |
| 3498 | zlog_warn ("ospf_lsa_unique_id(): " |
| 3499 | "Can't get Link State ID for %s/%d", |
| 3500 | inet_ntoa (p->prefix), p->prefixlen); |
| 3501 | /* id.s_addr = 0; */ |
| 3502 | id.s_addr = 0xffffffff; |
| 3503 | return id; |
| 3504 | } |
| 3505 | } |
| 3506 | } |
| 3507 | |
| 3508 | return id; |
| 3509 | } |
| 3510 | |
| 3511 | |
| 3512 | #define LSA_ACTION_ORIGN_RTR 1 |
| 3513 | #define LSA_ACTION_ORIGN_NET 2 |
| 3514 | #define LSA_ACTION_FLOOD_AREA 3 |
| 3515 | #define LSA_ACTION_FLOOD_AS 4 |
| 3516 | #define LSA_ACTION_FLUSH_AREA 5 |
| 3517 | #define LSA_ACTION_FLUSH_AS 6 |
| 3518 | |
| 3519 | struct lsa_action |
| 3520 | { |
| 3521 | u_char action; |
| 3522 | struct ospf_area *area; |
| 3523 | struct ospf_interface *oi; |
| 3524 | struct ospf_lsa *lsa; |
| 3525 | }; |
| 3526 | |
| 3527 | int |
| 3528 | ospf_lsa_action (struct thread *t) |
| 3529 | { |
| 3530 | struct lsa_action *data; |
paul | 020709f | 2003-04-04 02:44:16 +0000 | [diff] [blame] | 3531 | struct ospf *ospf; |
| 3532 | |
| 3533 | ospf = ospf_lookup (); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 3534 | |
| 3535 | data = THREAD_ARG (t); |
| 3536 | |
| 3537 | if (IS_DEBUG_OSPF (lsa, LSA) == OSPF_DEBUG_LSA) |
| 3538 | zlog_info ("LSA[Action]: Performing scheduled LSA action: %d", |
| 3539 | data->action); |
| 3540 | |
| 3541 | switch (data->action) |
| 3542 | { |
| 3543 | case LSA_ACTION_ORIGN_RTR: |
| 3544 | ospf_router_lsa_refresh (data->area->router_lsa_self); |
| 3545 | break; |
| 3546 | case LSA_ACTION_ORIGN_NET: |
| 3547 | ospf_network_lsa_originate (data->oi); |
| 3548 | break; |
| 3549 | case LSA_ACTION_FLOOD_AREA: |
| 3550 | ospf_flood_through_area (data->area, NULL, data->lsa); |
| 3551 | break; |
| 3552 | case LSA_ACTION_FLOOD_AS: |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 3553 | ospf_flood_through_as (ospf, NULL, data->lsa); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 3554 | break; |
| 3555 | case LSA_ACTION_FLUSH_AREA: |
| 3556 | ospf_lsa_flush_area (data->lsa, data->area); |
| 3557 | break; |
| 3558 | case LSA_ACTION_FLUSH_AS: |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 3559 | ospf_lsa_flush_as (ospf, data->lsa); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 3560 | break; |
| 3561 | } |
| 3562 | |
| 3563 | ospf_lsa_unlock (data->lsa); |
| 3564 | XFREE (MTYPE_OSPF_MESSAGE, data); |
| 3565 | return 0; |
| 3566 | } |
| 3567 | |
| 3568 | void |
| 3569 | ospf_schedule_lsa_flood_area (struct ospf_area *area, struct ospf_lsa *lsa) |
| 3570 | { |
| 3571 | struct lsa_action *data; |
| 3572 | |
| 3573 | data = XMALLOC (MTYPE_OSPF_MESSAGE, sizeof (struct lsa_action)); |
| 3574 | memset (data, 0, sizeof (struct lsa_action)); |
| 3575 | |
| 3576 | data->action = LSA_ACTION_FLOOD_AREA; |
| 3577 | data->area = area; |
| 3578 | data->lsa = ospf_lsa_lock (lsa); |
| 3579 | |
| 3580 | thread_add_event (master, ospf_lsa_action, data, 0); |
| 3581 | } |
| 3582 | |
| 3583 | void |
| 3584 | ospf_schedule_lsa_flush_area (struct ospf_area *area, struct ospf_lsa *lsa) |
| 3585 | { |
| 3586 | struct lsa_action *data; |
| 3587 | |
| 3588 | data = XMALLOC (MTYPE_OSPF_MESSAGE, sizeof (struct lsa_action)); |
| 3589 | memset (data, 0, sizeof (struct lsa_action)); |
| 3590 | |
| 3591 | data->action = LSA_ACTION_FLUSH_AREA; |
| 3592 | data->area = area; |
| 3593 | data->lsa = ospf_lsa_lock (lsa); |
| 3594 | |
| 3595 | thread_add_event (master, ospf_lsa_action, data, 0); |
| 3596 | } |
| 3597 | |
| 3598 | |
| 3599 | /* LSA Refreshment functions. */ |
| 3600 | void |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 3601 | ospf_lsa_refresh (struct ospf *ospf, struct ospf_lsa *lsa) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 3602 | { |
| 3603 | struct external_info *ei; |
| 3604 | assert (CHECK_FLAG (lsa->flags, OSPF_LSA_SELF)); |
| 3605 | |
| 3606 | switch (lsa->data->type) |
| 3607 | { |
| 3608 | /* Router and Network LSAs are processed differently. */ |
| 3609 | case OSPF_ROUTER_LSA: |
| 3610 | case OSPF_NETWORK_LSA: |
| 3611 | break; |
| 3612 | case OSPF_SUMMARY_LSA: |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 3613 | ospf_summary_lsa_refresh (ospf, lsa); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 3614 | break; |
| 3615 | case OSPF_ASBR_SUMMARY_LSA: |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 3616 | ospf_summary_asbr_lsa_refresh (ospf, lsa); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 3617 | break; |
| 3618 | case OSPF_AS_EXTERNAL_LSA: |
paul | d4a53d5 | 2003-07-12 21:30:57 +0000 | [diff] [blame] | 3619 | #ifdef HAVE_NSSA |
| 3620 | /* Translated from NSSA Type-5s are refreshed when |
| 3621 | * from refresh of Type-7 - do not refresh these directly. |
| 3622 | */ |
| 3623 | if (CHECK_FLAG (lsa->flags, OSPF_LSA_LOCAL_XLT)) |
| 3624 | break; |
| 3625 | #endif /* HAVE_NSSA */ |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 3626 | ei = ospf_external_info_check (lsa); |
| 3627 | if (ei) |
paul | d4a53d5 | 2003-07-12 21:30:57 +0000 | [diff] [blame] | 3628 | ospf_external_lsa_refresh (ospf, lsa, ei, LSA_REFRESH_FORCE); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 3629 | else |
paul | d4a53d5 | 2003-07-12 21:30:57 +0000 | [diff] [blame] | 3630 | ospf_lsa_flush_as (ospf, lsa); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 3631 | break; |
| 3632 | #ifdef HAVE_OPAQUE_LSA |
| 3633 | case OSPF_OPAQUE_LINK_LSA: |
| 3634 | case OSPF_OPAQUE_AREA_LSA: |
| 3635 | case OSPF_OPAQUE_AS_LSA: |
| 3636 | ospf_opaque_lsa_refresh (lsa); |
| 3637 | break; |
paul | d748032 | 2003-05-16 17:31:51 +0000 | [diff] [blame] | 3638 | #endif /* HAVE_OPAQUE_LSA */ |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 3639 | default: |
| 3640 | break; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 3641 | } |
| 3642 | } |
| 3643 | |
| 3644 | void |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 3645 | ospf_refresher_register_lsa (struct ospf *ospf, struct ospf_lsa *lsa) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 3646 | { |
| 3647 | u_int16_t index, current_index; |
| 3648 | |
| 3649 | assert (CHECK_FLAG (lsa->flags, OSPF_LSA_SELF)); |
| 3650 | |
| 3651 | if (lsa->refresh_list < 0) |
| 3652 | { |
| 3653 | int delay; |
| 3654 | |
| 3655 | if (LS_AGE (lsa) == 0 && |
| 3656 | ntohl (lsa->data->ls_seqnum) == OSPF_INITIAL_SEQUENCE_NUMBER) |
| 3657 | /* Randomize first update by OSPF_LS_REFRESH_SHIFT factor */ |
| 3658 | delay = OSPF_LS_REFRESH_SHIFT + (random () % OSPF_LS_REFRESH_TIME); |
| 3659 | else |
| 3660 | /* Randomize another updates by +-OSPF_LS_REFRESH_JITTER factor */ |
| 3661 | delay = OSPF_LS_REFRESH_TIME - LS_AGE (lsa) - OSPF_LS_REFRESH_JITTER |
| 3662 | + (random () % (2*OSPF_LS_REFRESH_JITTER)); |
| 3663 | |
| 3664 | if (delay < 0) |
| 3665 | delay = 0; |
| 3666 | |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 3667 | current_index = ospf->lsa_refresh_queue.index + |
| 3668 | (time (NULL) - ospf->lsa_refresher_started)/OSPF_LSA_REFRESHER_GRANULARITY; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 3669 | |
| 3670 | index = (current_index + delay/OSPF_LSA_REFRESHER_GRANULARITY) |
| 3671 | % (OSPF_LSA_REFRESHER_SLOTS); |
| 3672 | |
| 3673 | if (IS_DEBUG_OSPF (lsa, LSA_REFRESH)) |
paul | d4a53d5 | 2003-07-12 21:30:57 +0000 | [diff] [blame] | 3674 | zlog_info ("LSA[Refresh]: lsa %s with age %d added to index %d", |
| 3675 | inet_ntoa (lsa->data->id), LS_AGE (lsa), index); |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 3676 | if (!ospf->lsa_refresh_queue.qs[index]) |
| 3677 | ospf->lsa_refresh_queue.qs[index] = list_new (); |
| 3678 | listnode_add (ospf->lsa_refresh_queue.qs[index], ospf_lsa_lock (lsa)); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 3679 | lsa->refresh_list = index; |
paul | f2c8065 | 2002-12-13 21:44:27 +0000 | [diff] [blame] | 3680 | if (IS_DEBUG_OSPF (lsa, LSA_REFRESH)) |
paul | d4a53d5 | 2003-07-12 21:30:57 +0000 | [diff] [blame] | 3681 | zlog_info ("LSA[Refresh:%s]: ospf_refresher_register_lsa(): " |
| 3682 | "setting refresh_list on lsa %p (slod %d)", |
| 3683 | inet_ntoa (lsa->data->id), lsa, index); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 3684 | } |
| 3685 | } |
| 3686 | |
| 3687 | void |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 3688 | ospf_refresher_unregister_lsa (struct ospf *ospf, struct ospf_lsa *lsa) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 3689 | { |
| 3690 | assert (CHECK_FLAG (lsa->flags, OSPF_LSA_SELF)); |
| 3691 | if (lsa->refresh_list >= 0) |
| 3692 | { |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 3693 | list refresh_list = ospf->lsa_refresh_queue.qs[lsa->refresh_list]; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 3694 | listnode_delete (refresh_list, lsa); |
| 3695 | if (!listcount (refresh_list)) |
| 3696 | { |
| 3697 | list_free (refresh_list); |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 3698 | ospf->lsa_refresh_queue.qs[lsa->refresh_list] = NULL; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 3699 | } |
| 3700 | ospf_lsa_unlock (lsa); |
| 3701 | lsa->refresh_list = -1; |
| 3702 | } |
| 3703 | } |
| 3704 | |
| 3705 | int |
| 3706 | ospf_lsa_refresh_walker (struct thread *t) |
| 3707 | { |
| 3708 | list refresh_list; |
| 3709 | listnode node; |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 3710 | struct ospf *ospf = THREAD_ARG (t); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 3711 | int i; |
| 3712 | list lsa_to_refresh = list_new (); |
| 3713 | |
| 3714 | if (IS_DEBUG_OSPF (lsa, LSA_REFRESH)) |
| 3715 | zlog_info ("LSA[Refresh]:ospf_lsa_refresh_walker(): start"); |
| 3716 | |
| 3717 | |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 3718 | i = ospf->lsa_refresh_queue.index; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 3719 | |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 3720 | ospf->lsa_refresh_queue.index = |
| 3721 | (ospf->lsa_refresh_queue.index + |
| 3722 | (time (NULL) - ospf->lsa_refresher_started) / OSPF_LSA_REFRESHER_GRANULARITY) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 3723 | % OSPF_LSA_REFRESHER_SLOTS; |
| 3724 | |
| 3725 | if (IS_DEBUG_OSPF (lsa, LSA_REFRESH)) |
| 3726 | zlog_info ("LSA[Refresh]: ospf_lsa_refresh_walker(): next index %d", |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 3727 | ospf->lsa_refresh_queue.index); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 3728 | |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 3729 | for (;i != ospf->lsa_refresh_queue.index; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 3730 | i = (i + 1) % OSPF_LSA_REFRESHER_SLOTS) |
| 3731 | { |
| 3732 | if (IS_DEBUG_OSPF (lsa, LSA_REFRESH)) |
paul | d4a53d5 | 2003-07-12 21:30:57 +0000 | [diff] [blame] | 3733 | zlog_info ("LSA[Refresh]: ospf_lsa_refresh_walker(): " |
| 3734 | "refresh index %d", i); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 3735 | |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 3736 | refresh_list = ospf->lsa_refresh_queue.qs [i]; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 3737 | |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 3738 | ospf->lsa_refresh_queue.qs [i] = NULL; |
| 3739 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 3740 | if (refresh_list) |
| 3741 | { |
| 3742 | for (node = listhead (refresh_list); node;) |
| 3743 | { |
| 3744 | listnode next; |
| 3745 | struct ospf_lsa *lsa = getdata (node); |
| 3746 | next = node->next; |
| 3747 | |
| 3748 | if (IS_DEBUG_OSPF (lsa, LSA_REFRESH)) |
paul | d4a53d5 | 2003-07-12 21:30:57 +0000 | [diff] [blame] | 3749 | zlog_info ("LSA[Refresh:%s]: ospf_lsa_refresh_walker(): " |
| 3750 | "refresh lsa %p (slot %d)", |
| 3751 | inet_ntoa (lsa->data->id), lsa, i); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 3752 | |
| 3753 | list_delete_node (refresh_list, node); |
| 3754 | ospf_lsa_unlock (lsa); |
| 3755 | lsa->refresh_list = -1; |
| 3756 | listnode_add (lsa_to_refresh, lsa); |
| 3757 | node = next; |
| 3758 | } |
| 3759 | list_free (refresh_list); |
| 3760 | } |
| 3761 | } |
| 3762 | |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 3763 | ospf->t_lsa_refresher = thread_add_timer (master, ospf_lsa_refresh_walker, |
| 3764 | ospf, ospf->lsa_refresh_interval); |
| 3765 | ospf->lsa_refresher_started = time (NULL); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 3766 | |
| 3767 | for (node = listhead (lsa_to_refresh); node; nextnode (node)) |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 3768 | ospf_lsa_refresh (ospf, getdata (node)); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 3769 | |
| 3770 | list_delete (lsa_to_refresh); |
| 3771 | |
| 3772 | if (IS_DEBUG_OSPF (lsa, LSA_REFRESH)) |
| 3773 | zlog_info ("LSA[Refresh]: ospf_lsa_refresh_walker(): end"); |
| 3774 | |
| 3775 | return 0; |
| 3776 | } |
| 3777 | |