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, |
| 452 | * set Nt bit |
| 453 | */ |
| 454 | SET_FLAG (flags, ROUTER_LSA_NT); |
| 455 | #endif /* HAVE_NSSA */ |
| 456 | } |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 457 | |
| 458 | return flags; |
| 459 | } |
| 460 | |
| 461 | /* Lookup neighbor other than myself. |
| 462 | And check neighbor count, |
| 463 | Point-to-Point link must have only 1 neighbor. */ |
| 464 | struct ospf_neighbor * |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 465 | ospf_nbr_lookup_ptop (struct ospf_interface *oi) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 466 | { |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 467 | struct ospf_neighbor *nbr = NULL; |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 468 | struct route_node *rn; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 469 | |
| 470 | /* Search neighbor, there must be one of two nbrs. */ |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 471 | for (rn = route_top (oi->nbrs); rn; rn = route_next (rn)) |
| 472 | if ((nbr = rn->info)) |
| 473 | if (!IPV4_ADDR_SAME (&nbr->router_id, &oi->ospf->router_id)) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 474 | if (nbr->state == NSM_Full) |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 475 | { |
| 476 | route_unlock_node (rn); |
| 477 | break; |
| 478 | } |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 479 | |
| 480 | /* PtoP link must have only 1 neighbor. */ |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 481 | if (ospf_nbr_count (oi, 0) > 1) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 482 | zlog_warn ("Point-to-Point link has more than 1 neighobrs."); |
| 483 | |
| 484 | return nbr; |
| 485 | } |
| 486 | |
| 487 | /* Set a link information. */ |
| 488 | void |
| 489 | link_info_set (struct stream *s, struct in_addr id, |
| 490 | struct in_addr data, u_char type, u_char tos, u_int16_t cost) |
| 491 | { |
| 492 | /* TOS based routing is not supported. */ |
| 493 | stream_put_ipv4 (s, id.s_addr); /* Link ID. */ |
| 494 | stream_put_ipv4 (s, data.s_addr); /* Link Data. */ |
| 495 | stream_putc (s, type); /* Link Type. */ |
| 496 | stream_putc (s, tos); /* TOS = 0. */ |
| 497 | stream_putw (s, cost); /* Link Cost. */ |
| 498 | } |
| 499 | |
| 500 | /* Describe Point-to-Point link. */ |
| 501 | int |
| 502 | lsa_link_ptop_set (struct stream *s, struct ospf_interface *oi) |
| 503 | { |
| 504 | int links = 0; |
| 505 | struct ospf_neighbor *nbr; |
| 506 | struct in_addr id, mask; |
| 507 | |
| 508 | if (IS_DEBUG_OSPF (lsa, LSA_GENERATE)) |
| 509 | zlog_info ("LSA[Type1]: Set link Point-to-Point"); |
| 510 | |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 511 | if ((nbr = ospf_nbr_lookup_ptop (oi))) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 512 | if (nbr->state == NSM_Full) |
| 513 | { |
| 514 | /* For unnumbered point-to-point networks, the Link Data field |
| 515 | should specify the interface's MIB-II ifIndex value. */ |
| 516 | link_info_set (s, nbr->router_id, oi->address->u.prefix4, |
| 517 | LSA_LINK_TYPE_POINTOPOINT, 0, oi->output_cost); |
| 518 | links++; |
| 519 | } |
| 520 | |
| 521 | if (oi->connected->destination != NULL) |
| 522 | { |
| 523 | /* Option 1: |
| 524 | link_type = LSA_LINK_TYPE_STUB; |
| 525 | link_id = nbr->address.u.prefix4; |
| 526 | link_data.s_addr = 0xffffffff; |
| 527 | link_cost = o->output_cost; */ |
| 528 | |
| 529 | id.s_addr = oi->connected->destination->u.prefix4.s_addr; |
| 530 | mask.s_addr = 0xffffffff; |
| 531 | link_info_set (s, id, mask, LSA_LINK_TYPE_STUB, 0, oi->output_cost); |
| 532 | } |
| 533 | else |
| 534 | { |
| 535 | /* Option 2: We need to include link to a stub |
| 536 | network regardless of the state of the neighbor */ |
| 537 | masklen2ip (oi->address->prefixlen, &mask); |
| 538 | id.s_addr = oi->address->u.prefix4.s_addr & mask.s_addr; |
| 539 | link_info_set (s, id, mask, LSA_LINK_TYPE_STUB, 0, oi->output_cost); |
| 540 | } |
| 541 | links++; |
| 542 | |
| 543 | return links; |
| 544 | } |
| 545 | |
| 546 | /* Describe Broadcast Link. */ |
| 547 | int |
| 548 | lsa_link_broadcast_set (struct stream *s, struct ospf_interface *oi) |
| 549 | { |
| 550 | struct ospf_neighbor *dr; |
| 551 | struct in_addr id, mask; |
| 552 | |
| 553 | /* Describe Type 3 Link. */ |
| 554 | if (oi->state == ISM_Waiting) |
| 555 | { |
| 556 | masklen2ip (oi->address->prefixlen, &mask); |
| 557 | id.s_addr = oi->address->u.prefix4.s_addr & mask.s_addr; |
| 558 | link_info_set (s, id, mask, LSA_LINK_TYPE_STUB, 0, oi->output_cost); |
| 559 | return 1; |
| 560 | } |
| 561 | |
| 562 | dr = ospf_nbr_lookup_by_addr (oi->nbrs, &DR (oi)); |
| 563 | /* Describe Type 2 link. */ |
| 564 | if (dr && (dr->state == NSM_Full || |
| 565 | IPV4_ADDR_SAME (&oi->address->u.prefix4, &DR (oi))) && |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 566 | ospf_nbr_count (oi, NSM_Full) > 0) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 567 | { |
| 568 | link_info_set (s, DR (oi), oi->address->u.prefix4, |
| 569 | LSA_LINK_TYPE_TRANSIT, 0, oi->output_cost); |
| 570 | } |
| 571 | /* Describe type 3 link. */ |
| 572 | else |
| 573 | { |
| 574 | masklen2ip (oi->address->prefixlen, &mask); |
| 575 | id.s_addr = oi->address->u.prefix4.s_addr & mask.s_addr; |
| 576 | link_info_set (s, id, mask, LSA_LINK_TYPE_STUB, 0, oi->output_cost); |
| 577 | } |
| 578 | return 1; |
| 579 | } |
| 580 | |
| 581 | int |
| 582 | lsa_link_loopback_set (struct stream *s, struct ospf_interface *oi) |
| 583 | { |
| 584 | struct in_addr id, mask; |
| 585 | |
| 586 | /* Describe Type 3 Link. */ |
| 587 | if (oi->state != ISM_Loopback) |
| 588 | return 0; |
| 589 | |
| 590 | mask.s_addr = 0xffffffff; |
| 591 | id.s_addr = oi->address->u.prefix4.s_addr; |
| 592 | link_info_set (s, id, mask, LSA_LINK_TYPE_STUB, 0, oi->output_cost); |
| 593 | return 1; |
| 594 | } |
| 595 | |
| 596 | /* Describe Virtual Link. */ |
| 597 | int |
| 598 | lsa_link_virtuallink_set (struct stream *s, struct ospf_interface *oi) |
| 599 | { |
| 600 | struct ospf_neighbor *nbr; |
| 601 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 602 | if (oi->state == ISM_PointToPoint) |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 603 | if ((nbr = ospf_nbr_lookup_ptop (oi))) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 604 | if (nbr->state == NSM_Full) |
| 605 | { |
| 606 | link_info_set (s, nbr->router_id, oi->address->u.prefix4, |
| 607 | LSA_LINK_TYPE_VIRTUALLINK, 0, oi->output_cost); |
| 608 | return 1; |
| 609 | } |
| 610 | |
| 611 | return 0; |
| 612 | } |
| 613 | |
| 614 | #define lsa_link_nbma_set(S,O) lsa_link_broadcast_set (S, O) |
| 615 | |
paul | 7afa08d | 2002-12-13 20:59:45 +0000 | [diff] [blame] | 616 | /* this function add for support point-to-multipoint ,see rfc2328 |
| 617 | 12.4.1.4.*/ |
| 618 | /* from "edward rrr" <edward_rrr@hotmail.com> |
| 619 | http://marc.theaimsgroup.com/?l=zebra&m=100739222210507&w=2 */ |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 620 | int |
| 621 | lsa_link_ptomp_set (struct stream *s, struct ospf_interface *oi) |
paul | 7afa08d | 2002-12-13 20:59:45 +0000 | [diff] [blame] | 622 | { |
| 623 | int links = 0; |
| 624 | struct route_node *rn; |
| 625 | struct ospf_neighbor *nbr = NULL; |
| 626 | struct in_addr id, mask; |
| 627 | |
| 628 | mask.s_addr = 0xffffffff; |
| 629 | id.s_addr = oi->address->u.prefix4.s_addr; |
| 630 | link_info_set (s, id, mask, LSA_LINK_TYPE_STUB, 0, 0); |
| 631 | links++; |
| 632 | |
paul | 1cc8f76 | 2003-04-05 19:34:32 +0000 | [diff] [blame] | 633 | if (IS_DEBUG_OSPF (lsa, LSA_GENERATE)) |
| 634 | zlog_info ("PointToMultipoint: running ptomultip_set"); |
paul | 7afa08d | 2002-12-13 20:59:45 +0000 | [diff] [blame] | 635 | |
| 636 | /* Search neighbor, */ |
| 637 | for (rn = route_top (oi->nbrs); rn; rn = route_next (rn)) |
| 638 | if ((nbr = rn->info) != NULL) |
| 639 | /* Ignore myself. */ |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 640 | if (!IPV4_ADDR_SAME (&nbr->router_id, &oi->ospf->router_id)) |
paul | 7afa08d | 2002-12-13 20:59:45 +0000 | [diff] [blame] | 641 | if (nbr->state == NSM_Full) |
| 642 | |
| 643 | { |
paul | 7afa08d | 2002-12-13 20:59:45 +0000 | [diff] [blame] | 644 | link_info_set (s, nbr->router_id, oi->address->u.prefix4, |
| 645 | LSA_LINK_TYPE_POINTOPOINT, 0, oi->output_cost); |
| 646 | links++; |
paul | 1cc8f76 | 2003-04-05 19:34:32 +0000 | [diff] [blame] | 647 | if (IS_DEBUG_OSPF (lsa, LSA_GENERATE)) |
| 648 | zlog_info ("PointToMultipoint: set link to %s", |
| 649 | inet_ntoa(oi->address->u.prefix4)); |
paul | 7afa08d | 2002-12-13 20:59:45 +0000 | [diff] [blame] | 650 | } |
| 651 | |
| 652 | return links; |
paul | 7afa08d | 2002-12-13 20:59:45 +0000 | [diff] [blame] | 653 | } |
| 654 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 655 | /* Set router-LSA link information. */ |
| 656 | int |
| 657 | router_lsa_link_set (struct stream *s, struct ospf_area *area) |
| 658 | { |
| 659 | listnode node; |
| 660 | int links = 0; |
| 661 | |
| 662 | for (node = listhead (area->oiflist); node; node = nextnode (node)) |
| 663 | { |
| 664 | struct ospf_interface *oi = node->data; |
| 665 | struct interface *ifp = oi->ifp; |
| 666 | |
| 667 | /* Check interface is up, OSPF is enable. */ |
paul | 2e3b2e4 | 2002-12-13 21:03:13 +0000 | [diff] [blame] | 668 | if (if_is_operative (ifp)) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 669 | { |
| 670 | if (oi->state != ISM_Down) |
| 671 | { |
| 672 | /* Describe each link. */ |
| 673 | switch (oi->type) |
| 674 | { |
| 675 | case OSPF_IFTYPE_POINTOPOINT: |
| 676 | links += lsa_link_ptop_set (s, oi); |
| 677 | break; |
| 678 | case OSPF_IFTYPE_BROADCAST: |
| 679 | links += lsa_link_broadcast_set (s, oi); |
| 680 | break; |
| 681 | case OSPF_IFTYPE_NBMA: |
| 682 | links += lsa_link_nbma_set (s, oi); |
| 683 | break; |
| 684 | case OSPF_IFTYPE_POINTOMULTIPOINT: |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 685 | links += lsa_link_ptomp_set (s, oi); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 686 | break; |
| 687 | case OSPF_IFTYPE_VIRTUALLINK: |
| 688 | links += lsa_link_virtuallink_set (s, oi); |
| 689 | break; |
| 690 | case OSPF_IFTYPE_LOOPBACK: |
| 691 | links += lsa_link_loopback_set (s, oi); |
| 692 | } |
| 693 | } |
| 694 | } |
| 695 | } |
| 696 | |
| 697 | return links; |
| 698 | } |
| 699 | |
| 700 | /* Set router-LSA body. */ |
| 701 | void |
| 702 | ospf_router_lsa_body_set (struct stream *s, struct ospf_area *area) |
| 703 | { |
| 704 | unsigned long putp; |
| 705 | u_int16_t cnt; |
| 706 | |
| 707 | /* Set flags. */ |
| 708 | stream_putc (s, router_lsa_flags (area)); |
| 709 | |
| 710 | /* Set Zero fields. */ |
| 711 | stream_putc (s, 0); |
| 712 | |
| 713 | /* Keep pointer to # links. */ |
| 714 | putp = s->putp; |
| 715 | |
| 716 | /* Forward word */ |
| 717 | stream_putw(s, 0); |
| 718 | |
| 719 | /* Set all link information. */ |
| 720 | cnt = router_lsa_link_set (s, area); |
| 721 | |
| 722 | /* Set # of links here. */ |
| 723 | stream_putw_at (s, putp, cnt); |
| 724 | } |
| 725 | |
| 726 | /* Create new router-LSA. */ |
| 727 | struct ospf_lsa * |
| 728 | ospf_router_lsa_new (struct ospf_area *area) |
| 729 | { |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 730 | struct ospf *ospf = area->ospf; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 731 | struct stream *s; |
| 732 | struct lsa_header *lsah; |
| 733 | struct ospf_lsa *new; |
| 734 | int length; |
| 735 | |
| 736 | if (IS_DEBUG_OSPF (lsa, LSA_GENERATE)) |
| 737 | zlog_info ("LSA[Type1]: Create router-LSA instance"); |
| 738 | |
| 739 | /* Create a stream for LSA. */ |
| 740 | s = stream_new (OSPF_MAX_LSA_SIZE); |
| 741 | lsah = (struct lsa_header *) STREAM_DATA (s); |
| 742 | |
| 743 | #ifdef HAVE_NSSA |
| 744 | /* Set LSA common header fields. */ |
| 745 | lsa_header_set (s, LSA_OPTIONS_GET (area) | LSA_NSSA_GET (area), |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 746 | OSPF_ROUTER_LSA, ospf->router_id, ospf->router_id); |
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 | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 750 | OSPF_ROUTER_LSA, ospf->router_id, ospf->router_id); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 751 | #endif /* HAVE_NSSA */ |
| 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 | { |
| 1629 | struct ospf_lsa *new2; |
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 | |
| 1633 | /* NSSA Originate or Refresh (If anyNSSA) |
| 1634 | |
| 1635 | LSA is self-originated. And just installed as Type-5. |
| 1636 | Additionally, install as Type-7 LSDB for every attached NSSA. |
| 1637 | |
| 1638 | P-Bit controls which ABR performs translation to outside world; If |
| 1639 | we are an ABR....do not set the P-bit, because we send the Type-5, |
| 1640 | not as the ABR Translator, but as the ASBR owner within the AS! |
| 1641 | |
| 1642 | If we are NOT ABR, Flood through NSSA as Type-7 w/P-bit set. The |
| 1643 | elected ABR Translator will see the P-bit, Translate, and re-flood. |
| 1644 | |
| 1645 | Later, ABR_TASK and P-bit will scan Type-7 LSDB and translate to |
| 1646 | Type-5's to non-NSSA Areas. (it will also attempt a re-install) */ |
| 1647 | |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 1648 | for (node = listhead (ospf->areas); node; nextnode (node)) |
| 1649 | { |
| 1650 | struct ospf_area *area = getdata (node); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1651 | |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 1652 | /* make lsa duplicate, lock=1 */ |
| 1653 | new2 = ospf_lsa_dup (lsa); |
| 1654 | new2->area = area; |
| 1655 | new2->data->type = OSPF_AS_NSSA_LSA; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1656 | |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 1657 | /* set P-bit if not ABR */ |
paul | 020709f | 2003-04-04 02:44:16 +0000 | [diff] [blame] | 1658 | if (! IS_OSPF_ABR (ospf)) |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 1659 | { |
| 1660 | SET_FLAG(new2->data->options, OSPF_OPTION_NP); |
| 1661 | |
| 1662 | /* set non-zero FWD ADDR |
| 1663 | |
| 1664 | draft-ietf-ospf-nssa-update-09.txt |
| 1665 | |
| 1666 | if the network between the NSSA AS boundary router and the |
| 1667 | adjacent AS is advertised into OSPF as an internal OSPF route, |
| 1668 | the forwarding address should be the next op address as is cu |
| 1669 | currently done with type-5 LSAs. If the intervening network is |
| 1670 | not adversited into OSPF as an internal OSPF route and the |
| 1671 | type-7 LSA's P-bit is set a forwarding address should be |
| 1672 | selected from one of the router's active OSPF inteface addresses |
| 1673 | which belong to the NSSA. If no such addresses exist, then |
| 1674 | no type-7 LSA's with the P-bit set should originate from this |
| 1675 | router. */ |
| 1676 | |
| 1677 | /* kevinm: not updating lsa anymore, just new2 */ |
| 1678 | extlsa = (struct as_external_lsa *)(new2->data); |
| 1679 | |
| 1680 | if (extlsa->e[0].fwd_addr.s_addr == 0) |
| 1681 | 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] | 1682 | |
paul | d748032 | 2003-05-16 17:31:51 +0000 | [diff] [blame] | 1683 | if (extlsa->e[0].fwd_addr.s_addr == 0) |
| 1684 | { |
| 1685 | if (IS_DEBUG_OSPF_NSSA) |
| 1686 | zlog_info ("LSA[Type-7]: Could not build FWD-ADDR"); |
| 1687 | ospf_lsa_discard(new2); |
| 1688 | return; |
| 1689 | } |
paul | f2c8065 | 2002-12-13 21:44:27 +0000 | [diff] [blame] | 1690 | } |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 1691 | /* Re-calculate checksum. */ |
| 1692 | ospf_lsa_checksum (new2->data); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1693 | |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 1694 | /* install also as Type-7 */ |
| 1695 | ospf_lsa_install (ospf, NULL, new2); /* Remove Old, Lock New = 2 */ |
| 1696 | |
| 1697 | /* will send each copy, lock=2+n */ |
| 1698 | ospf_flood_through_as (ospf, NULL, new2); /* all attached NSSA's, no AS/STUBs */ |
| 1699 | } |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1700 | } |
| 1701 | #endif /* HAVE_NSSA */ |
| 1702 | |
| 1703 | int |
| 1704 | is_prefix_default (struct prefix_ipv4 *p) |
| 1705 | { |
| 1706 | struct prefix_ipv4 q; |
| 1707 | |
| 1708 | q.family = AF_INET; |
| 1709 | q.prefix.s_addr = 0; |
| 1710 | q.prefixlen = 0; |
| 1711 | |
| 1712 | return prefix_same ((struct prefix *) p, (struct prefix *) &q); |
| 1713 | } |
| 1714 | |
| 1715 | /* Originate an AS-external-LSA, install and flood. */ |
| 1716 | struct ospf_lsa * |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 1717 | ospf_external_lsa_originate (struct ospf *ospf, struct external_info *ei) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1718 | { |
| 1719 | struct ospf_lsa *new; |
| 1720 | |
| 1721 | /* Added for NSSA project.... |
| 1722 | |
| 1723 | External LSAs are originated in ASBRs as usual, but for NSSA systems. |
| 1724 | there is the global Type-5 LSDB and a Type-7 LSDB installed for |
| 1725 | every area. The Type-7's are flooded to every IR and every ABR; We |
| 1726 | install the Type-5 LSDB so that the normal "refresh" code operates |
| 1727 | as usual, and flag them as not used during ASE calculations. The |
| 1728 | Type-7 LSDB is used for calculations. Each Type-7 has a Forwarding |
| 1729 | Address of non-zero. |
| 1730 | |
| 1731 | If an ABR is the elected NSSA translator, following SPF and during |
| 1732 | the ABR task it will translate all the scanned Type-7's, with P-bit |
| 1733 | ON and not-self generated, and translate to Type-5's throughout the |
| 1734 | non-NSSA/STUB AS. |
| 1735 | |
| 1736 | A difference in operation depends whether this ASBR is an ABR |
| 1737 | or not. If not an ABR, the P-bit is ON, to indicate that any |
| 1738 | elected NSSA-ABR can perform its translation. |
| 1739 | |
| 1740 | If an ABR, the P-bit is OFF; No ABR will perform translation and |
| 1741 | this ASBR will flood the Type-5 LSA as usual. |
| 1742 | |
| 1743 | For the case where this ASBR is not an ABR, the ASE calculations |
| 1744 | are based on the Type-5 LSDB; The Type-7 LSDB exists just to |
| 1745 | demonstrate to the user that there are LSA's that belong to any |
| 1746 | attached NSSA. |
| 1747 | |
| 1748 | Finally, it just so happens that when the ABR is translating every |
| 1749 | Type-7 into Type-5, it installs it into the Type-5 LSDB as an |
| 1750 | approved Type-5 (translated from Type-7); at the end of translation |
| 1751 | if any Translated Type-5's remain unapproved, then they must be |
| 1752 | flushed from the AS. |
| 1753 | |
| 1754 | */ |
| 1755 | |
| 1756 | /* Check the AS-external-LSA should be originated. */ |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 1757 | if (!ospf_redistribute_check (ospf, ei, NULL)) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1758 | return NULL; |
| 1759 | |
| 1760 | /* Create new AS-external-LSA instance. */ |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 1761 | if ((new = ospf_external_lsa_new (ospf, ei, NULL)) == NULL) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1762 | { |
| 1763 | if (IS_DEBUG_OSPF_EVENT) |
| 1764 | zlog_info ("LSA[Type5:%s]: Could not originate AS-external-LSA", |
| 1765 | inet_ntoa (ei->p.prefix)); |
| 1766 | return NULL; |
| 1767 | } |
| 1768 | |
| 1769 | /* Install newly created LSA into Type-5 LSDB, lock = 1. */ |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 1770 | ospf_lsa_install (ospf, NULL, new); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1771 | |
| 1772 | /* Update LSA origination count. */ |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 1773 | ospf->lsa_originate_count++; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1774 | |
| 1775 | /* Flooding new LSA. only to AS (non-NSSA/STUB) */ |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 1776 | ospf_flood_through_as (ospf, NULL, new); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1777 | |
| 1778 | #ifdef HAVE_NSSA |
| 1779 | /* If there is any attached NSSA, do special handling */ |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 1780 | if (ospf->anyNSSA) |
| 1781 | 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] | 1782 | #endif /* HAVE_NSSA */ |
| 1783 | |
| 1784 | /* Debug logging. */ |
| 1785 | if (IS_DEBUG_OSPF (lsa, LSA_GENERATE)) |
| 1786 | { |
| 1787 | zlog_info ("LSA[Type%d:%s]: Originate AS-external-LSA %p", |
| 1788 | new->data->type, inet_ntoa (new->data->id), new); |
| 1789 | ospf_lsa_header_dump (new->data); |
| 1790 | } |
| 1791 | |
| 1792 | return new; |
| 1793 | } |
| 1794 | |
| 1795 | /* Originate AS-external-LSA from external info with initial flag. */ |
| 1796 | int |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 1797 | ospf_external_lsa_originate_timer (struct thread *thread) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1798 | { |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 1799 | struct ospf *ospf = THREAD_ARG (thread); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1800 | struct route_node *rn; |
| 1801 | struct external_info *ei; |
| 1802 | struct route_table *rt; |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 1803 | int type = THREAD_VAL (thread); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1804 | |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 1805 | ospf->t_external_lsa = NULL; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1806 | |
| 1807 | /* Originate As-external-LSA from all type of distribute source. */ |
| 1808 | if ((rt = EXTERNAL_INFO (type))) |
| 1809 | for (rn = route_top (rt); rn; rn = route_next (rn)) |
| 1810 | if ((ei = rn->info) != NULL) |
| 1811 | if (!is_prefix_default ((struct prefix_ipv4 *)&ei->p)) |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 1812 | if (!ospf_external_lsa_originate (ospf, ei)) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1813 | zlog_warn ("LSA: AS-external-LSA was not originated."); |
| 1814 | |
| 1815 | return 0; |
| 1816 | } |
| 1817 | |
| 1818 | struct external_info * |
paul | 020709f | 2003-04-04 02:44:16 +0000 | [diff] [blame] | 1819 | ospf_default_external_info (struct ospf *ospf) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1820 | { |
| 1821 | int type; |
| 1822 | struct route_node *rn; |
| 1823 | struct prefix_ipv4 p; |
| 1824 | |
| 1825 | p.family = AF_INET; |
| 1826 | p.prefix.s_addr = 0; |
| 1827 | p.prefixlen = 0; |
| 1828 | |
| 1829 | /* First, lookup redistributed default route. */ |
| 1830 | for (type = 0; type <= ZEBRA_ROUTE_MAX; type++) |
| 1831 | if (EXTERNAL_INFO (type) && type != ZEBRA_ROUTE_OSPF) |
| 1832 | { |
| 1833 | rn = route_node_lookup (EXTERNAL_INFO (type), (struct prefix *) &p); |
| 1834 | if (rn != NULL) |
| 1835 | { |
| 1836 | route_unlock_node (rn); |
| 1837 | assert (rn->info); |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 1838 | if (ospf_redistribute_check (ospf, rn->info, NULL)) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1839 | return rn->info; |
| 1840 | } |
| 1841 | } |
| 1842 | |
| 1843 | return NULL; |
| 1844 | } |
| 1845 | |
| 1846 | int |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 1847 | ospf_default_originate_timer (struct thread *thread) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1848 | { |
| 1849 | int *origin; |
| 1850 | struct prefix_ipv4 p; |
| 1851 | struct in_addr nexthop; |
| 1852 | struct external_info *ei; |
paul | 020709f | 2003-04-04 02:44:16 +0000 | [diff] [blame] | 1853 | struct ospf *ospf; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1854 | |
paul | 020709f | 2003-04-04 02:44:16 +0000 | [diff] [blame] | 1855 | ospf = ospf_lookup (); |
| 1856 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1857 | /* Get originate flags. */ |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 1858 | origin = THREAD_ARG (thread); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1859 | |
| 1860 | p.family = AF_INET; |
| 1861 | p.prefix.s_addr = 0; |
| 1862 | p.prefixlen = 0; |
| 1863 | |
| 1864 | if (*origin == DEFAULT_ORIGINATE_ALWAYS) |
| 1865 | { |
| 1866 | /* If there is no default route via redistribute, |
| 1867 | then originate AS-external-LSA with nexthop 0 (self). */ |
| 1868 | nexthop.s_addr = 0; |
| 1869 | ospf_external_info_add (DEFAULT_ROUTE, p, 0, nexthop); |
| 1870 | } |
| 1871 | |
paul | 020709f | 2003-04-04 02:44:16 +0000 | [diff] [blame] | 1872 | if ((ei = ospf_default_external_info (ospf))) |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 1873 | ospf_external_lsa_originate (ospf, ei); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1874 | |
| 1875 | return 0; |
| 1876 | } |
| 1877 | |
paul | 645878f | 2003-04-13 21:42:11 +0000 | [diff] [blame] | 1878 | #ifdef HAVE_NSSA |
| 1879 | /* Flush any NSSA LSAs for given prefix */ |
| 1880 | void |
| 1881 | ospf_nssa_lsa_flush (struct ospf *ospf, struct prefix_ipv4 *p) |
| 1882 | { |
| 1883 | struct listnode *node; |
| 1884 | struct ospf_lsa *lsa; |
| 1885 | struct ospf_area *area; |
| 1886 | |
paul | d748032 | 2003-05-16 17:31:51 +0000 | [diff] [blame] | 1887 | for (node = listhead (ospf->areas); node; nextnode (node)) |
paul | 645878f | 2003-04-13 21:42:11 +0000 | [diff] [blame] | 1888 | { |
paul | d748032 | 2003-05-16 17:31:51 +0000 | [diff] [blame] | 1889 | if (((area = getdata (node)) != NULL) |
| 1890 | && (area->external_routing == OSPF_AREA_NSSA)) |
| 1891 | { |
| 1892 | if (!(lsa = ospf_lsa_lookup (area, OSPF_AS_NSSA_LSA, p->prefix, |
| 1893 | ospf->router_id))) |
| 1894 | { |
| 1895 | if (IS_DEBUG_OSPF (lsa, LSA_FLOODING)) |
| 1896 | zlog_warn ("LSA: There is no such AS-NSSA-LSA %s/%d in LSDB", |
| 1897 | inet_ntoa (p->prefix), p->prefixlen); |
| 1898 | continue; |
| 1899 | } |
| 1900 | ospf_ls_retransmit_delete_nbr_area (area, lsa); |
| 1901 | if (!IS_LSA_MAXAGE (lsa)) |
| 1902 | { |
| 1903 | ospf_refresher_unregister_lsa (ospf, lsa); |
| 1904 | ospf_lsa_flush_area (lsa, area); |
| 1905 | } |
| 1906 | } |
paul | 645878f | 2003-04-13 21:42:11 +0000 | [diff] [blame] | 1907 | } |
| 1908 | } |
| 1909 | #endif /* HAVE_NSSA */ |
| 1910 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1911 | /* Flush an AS-external-LSA from LSDB and routing domain. */ |
| 1912 | void |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 1913 | ospf_external_lsa_flush (struct ospf *ospf, |
| 1914 | u_char type, struct prefix_ipv4 *p, |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1915 | unsigned int ifindex, struct in_addr nexthop) |
| 1916 | { |
| 1917 | struct ospf_lsa *lsa; |
| 1918 | |
| 1919 | if (IS_DEBUG_OSPF (lsa, LSA_FLOODING)) |
| 1920 | zlog_info ("LSA: Flushing AS-external-LSA %s/%d", |
| 1921 | inet_ntoa (p->prefix), p->prefixlen); |
| 1922 | |
| 1923 | /* First lookup LSA from LSDB. */ |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 1924 | if (!(lsa = ospf_external_info_find_lsa (ospf, p))) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1925 | { |
| 1926 | if (IS_DEBUG_OSPF (lsa, LSA_FLOODING)) |
| 1927 | zlog_warn ("LSA: There is no such AS-external-LSA %s/%d in LSDB", |
| 1928 | inet_ntoa (p->prefix), p->prefixlen); |
| 1929 | return; |
| 1930 | } |
paul | d748032 | 2003-05-16 17:31:51 +0000 | [diff] [blame] | 1931 | #ifdef HAVE_NSSA |
| 1932 | /* If LSA is selforiginated and there is NSSA area, flush |
| 1933 | * Type-7 LSA's at first. */ |
| 1934 | |
| 1935 | if (IS_LSA_SELF(lsa) && (ospf->anyNSSA)) |
| 1936 | ospf_nssa_lsa_flush (ospf, p); |
| 1937 | #endif /* HAVE_NSSA */ |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1938 | |
| 1939 | /* Sweep LSA from Link State Retransmit List. */ |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 1940 | ospf_ls_retransmit_delete_nbr_as (ospf, lsa); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1941 | |
| 1942 | /* There must be no self-originated LSA in rtrs_external. */ |
| 1943 | #if 0 |
| 1944 | /* Remove External route from Zebra. */ |
| 1945 | ospf_zebra_delete ((struct prefix_ipv4 *) p, &nexthop); |
| 1946 | #endif |
| 1947 | |
| 1948 | if (!IS_LSA_MAXAGE (lsa)) |
| 1949 | { |
| 1950 | /* Unregister LSA from Refresh queue. */ |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 1951 | ospf_refresher_unregister_lsa (ospf, lsa); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1952 | |
| 1953 | /* Flush AS-external-LSA through AS. */ |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 1954 | ospf_lsa_flush_as (ospf, lsa); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1955 | } |
| 1956 | |
| 1957 | if (IS_DEBUG_OSPF (lsa, LSA_FLOODING)) |
| 1958 | zlog_info ("ospf_external_lsa_flush(): stop"); |
| 1959 | } |
| 1960 | |
| 1961 | void |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 1962 | ospf_external_lsa_refresh_default (struct ospf *ospf) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1963 | { |
| 1964 | struct prefix_ipv4 p; |
| 1965 | struct external_info *ei; |
| 1966 | struct ospf_lsa *lsa; |
| 1967 | |
| 1968 | p.family = AF_INET; |
| 1969 | p.prefixlen = 0; |
| 1970 | p.prefix.s_addr = 0; |
| 1971 | |
paul | 020709f | 2003-04-04 02:44:16 +0000 | [diff] [blame] | 1972 | ei = ospf_default_external_info (ospf); |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 1973 | lsa = ospf_external_info_find_lsa (ospf, &p); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1974 | |
| 1975 | if (ei) |
| 1976 | { |
| 1977 | if (lsa) |
| 1978 | { |
| 1979 | if (IS_DEBUG_OSPF_EVENT) |
| 1980 | 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] | 1981 | ospf_external_lsa_refresh (ospf, lsa, ei, LSA_REFRESH_FORCE); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1982 | } |
| 1983 | else |
| 1984 | { |
| 1985 | if (IS_DEBUG_OSPF_EVENT) |
| 1986 | zlog_info ("LSA[Type5:0.0.0.0]: Originate AS-external-LSA"); |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 1987 | ospf_external_lsa_originate (ospf, ei); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1988 | } |
| 1989 | } |
| 1990 | else |
| 1991 | { |
| 1992 | if (lsa) |
| 1993 | { |
| 1994 | if (IS_DEBUG_OSPF_EVENT) |
| 1995 | zlog_info ("LSA[Type5:0.0.0.0]: Flush AS-external-LSA"); |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 1996 | ospf_lsa_flush_as (ospf, lsa); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1997 | } |
| 1998 | } |
| 1999 | } |
| 2000 | |
| 2001 | void |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 2002 | ospf_external_lsa_refresh_type (struct ospf *ospf, u_char type, int force) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2003 | { |
| 2004 | struct route_node *rn; |
| 2005 | struct external_info *ei; |
| 2006 | |
| 2007 | if (type != DEFAULT_ROUTE) |
| 2008 | if (EXTERNAL_INFO(type)) |
| 2009 | /* Refresh each redistributed AS-external-LSAs. */ |
| 2010 | for (rn = route_top (EXTERNAL_INFO (type)); rn; rn = route_next (rn)) |
| 2011 | if ((ei = rn->info)) |
| 2012 | if (!is_prefix_default (&ei->p)) |
| 2013 | { |
| 2014 | struct ospf_lsa *lsa; |
| 2015 | |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 2016 | if ((lsa = ospf_external_info_find_lsa (ospf, &ei->p))) |
| 2017 | ospf_external_lsa_refresh (ospf, lsa, ei, force); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2018 | else |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 2019 | ospf_external_lsa_originate (ospf, ei); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2020 | } |
| 2021 | } |
| 2022 | |
| 2023 | /* Refresh AS-external-LSA. */ |
| 2024 | void |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 2025 | ospf_external_lsa_refresh (struct ospf *ospf, struct ospf_lsa *lsa, |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2026 | struct external_info *ei, int force) |
| 2027 | { |
| 2028 | struct ospf_lsa *new; |
| 2029 | int changed; |
| 2030 | |
| 2031 | /* Check the AS-external-LSA should be originated. */ |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 2032 | if (!ospf_redistribute_check (ospf, ei, &changed)) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2033 | { |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 2034 | ospf_external_lsa_flush (ospf, ei->type, &ei->p, |
| 2035 | ei->ifindex, ei->nexthop); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2036 | return; |
| 2037 | } |
| 2038 | |
| 2039 | if (!changed && !force) |
| 2040 | return; |
| 2041 | |
| 2042 | /* Delete LSA from neighbor retransmit-list. */ |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 2043 | ospf_ls_retransmit_delete_nbr_as (ospf, lsa); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2044 | |
| 2045 | /* Unregister AS-external-LSA from refresh-list. */ |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 2046 | ospf_refresher_unregister_lsa (ospf, lsa); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2047 | |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 2048 | new = ospf_external_lsa_new (ospf, ei, &lsa->data->id); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2049 | |
| 2050 | if (new == NULL) |
| 2051 | { |
| 2052 | if (IS_DEBUG_OSPF (lsa, LSA_GENERATE)) |
| 2053 | zlog_warn ("LSA[Type%d:%s]: Could not be refreshed", lsa->data->type, |
| 2054 | inet_ntoa (lsa->data->id)); |
| 2055 | return; |
| 2056 | } |
| 2057 | |
| 2058 | new->data->ls_seqnum = lsa_seqnum_increment (lsa); |
| 2059 | |
| 2060 | /* Record timestamp. */ |
| 2061 | gettimeofday (&new->tv_orig, NULL); |
| 2062 | |
| 2063 | /* Re-calculate checksum. */ |
| 2064 | ospf_lsa_checksum (new->data); |
| 2065 | |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 2066 | ospf_lsa_install (ospf, NULL, new); /* As type-5. */ |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2067 | |
| 2068 | /* Flood LSA through AS. */ |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 2069 | ospf_flood_through_as (ospf, NULL, new); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2070 | |
| 2071 | #ifdef HAVE_NSSA |
| 2072 | /* If any attached NSSA, install as Type-7, flood to all NSSA Areas */ |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 2073 | if (ospf->anyNSSA) |
| 2074 | ospf_install_flood_nssa (ospf, new, ei); /* Install/Flood per new rules */ |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2075 | #endif /* HAVE_NSSA */ |
| 2076 | |
| 2077 | /* Register slef-originated LSA to refresh queue. */ |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 2078 | ospf_refresher_register_lsa (ospf, new); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2079 | |
| 2080 | /* Debug logging. */ |
| 2081 | if (IS_DEBUG_OSPF (lsa, LSA_GENERATE)) |
| 2082 | { |
| 2083 | zlog_info ("LSA[Type%d:%s]: AS-external-LSA refresh", |
| 2084 | new->data->type, inet_ntoa (new->data->id)); |
| 2085 | ospf_lsa_header_dump (new->data); |
| 2086 | } |
| 2087 | |
| 2088 | return; |
| 2089 | } |
| 2090 | |
| 2091 | |
| 2092 | /* LSA installation functions. */ |
| 2093 | |
| 2094 | /* Install router-LSA to an area. */ |
| 2095 | struct ospf_lsa * |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 2096 | ospf_router_lsa_install (struct ospf *ospf, |
| 2097 | struct ospf_lsa *new, int rt_recalc) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2098 | { |
| 2099 | struct ospf_area *area = new->area; |
| 2100 | |
| 2101 | /* RFC 2328 Section 13.2 Router-LSAs and network-LSAs |
| 2102 | The entire routing table must be recalculated, starting with |
| 2103 | the shortest path calculations for each area (not just the |
| 2104 | area whose link-state database has changed). |
| 2105 | */ |
| 2106 | if (rt_recalc) |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 2107 | ospf_spf_calculate_schedule (ospf); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2108 | |
| 2109 | if (IS_LSA_SELF (new)) |
| 2110 | { |
| 2111 | /* Set router-LSA refresh timer. */ |
| 2112 | OSPF_TIMER_OFF (area->t_router_lsa_self); |
| 2113 | OSPF_AREA_TIMER_ON (area->t_router_lsa_self, |
| 2114 | ospf_router_lsa_timer, OSPF_LS_REFRESH_TIME); |
| 2115 | |
| 2116 | /* Set self-originated router-LSA. */ |
| 2117 | ospf_lsa_unlock (area->router_lsa_self); |
| 2118 | area->router_lsa_self = ospf_lsa_lock (new); |
| 2119 | |
| 2120 | if (IS_DEBUG_OSPF (lsa, LSA_INSTALL)) |
| 2121 | zlog_info("LSA[Type%d]: ID %s is self-originated", |
| 2122 | new->data->type, inet_ntoa (new->data->id)); |
| 2123 | } |
| 2124 | |
| 2125 | return new; |
| 2126 | } |
| 2127 | |
| 2128 | #define OSPF_INTERFACE_TIMER_ON(T,F,V) \ |
| 2129 | if (!(T)) \ |
| 2130 | (T) = thread_add_timer (master, (F), oi, (V)) |
| 2131 | |
| 2132 | /* Install network-LSA to an area. */ |
| 2133 | struct ospf_lsa * |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 2134 | ospf_network_lsa_install (struct ospf *ospf, |
| 2135 | struct ospf_interface *oi, |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2136 | struct ospf_lsa *new, |
| 2137 | int rt_recalc) |
| 2138 | { |
| 2139 | |
| 2140 | /* RFC 2328 Section 13.2 Router-LSAs and network-LSAs |
| 2141 | The entire routing table must be recalculated, starting with |
| 2142 | the shortest path calculations for each area (not just the |
| 2143 | area whose link-state database has changed). |
| 2144 | */ |
| 2145 | if (rt_recalc) |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 2146 | ospf_spf_calculate_schedule (ospf); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2147 | |
| 2148 | /* We supposed that when LSA is originated by us, we pass the int |
| 2149 | for which it was originated. If LSA was received by flooding, |
| 2150 | the RECEIVED flag is set, so we do not link the LSA to the int. */ |
| 2151 | if (IS_LSA_SELF (new) && !CHECK_FLAG (new->flags, OSPF_LSA_RECEIVED)) |
| 2152 | { |
| 2153 | /* Set LSRefresh timer. */ |
| 2154 | OSPF_TIMER_OFF (oi->t_network_lsa_self); |
| 2155 | |
| 2156 | OSPF_INTERFACE_TIMER_ON (oi->t_network_lsa_self, |
| 2157 | ospf_network_lsa_refresh_timer, |
| 2158 | OSPF_LS_REFRESH_TIME); |
| 2159 | |
| 2160 | ospf_lsa_unlock (oi->network_lsa_self); |
| 2161 | oi->network_lsa_self = ospf_lsa_lock (new); |
| 2162 | } |
| 2163 | |
| 2164 | return new; |
| 2165 | } |
| 2166 | |
| 2167 | /* Install summary-LSA to an area. */ |
| 2168 | struct ospf_lsa * |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 2169 | ospf_summary_lsa_install (struct ospf *ospf, struct ospf_lsa *new, |
| 2170 | int rt_recalc) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2171 | { |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2172 | if (rt_recalc && !IS_LSA_SELF (new)) |
| 2173 | { |
| 2174 | /* RFC 2328 Section 13.2 Summary-LSAs |
| 2175 | The best route to the destination described by the summary- |
| 2176 | LSA must be recalculated (see Section 16.5). If this |
| 2177 | destination is an AS boundary router, it may also be |
| 2178 | necessary to re-examine all the AS-external-LSAs. |
| 2179 | */ |
| 2180 | |
| 2181 | #if 0 |
| 2182 | /* This doesn't exist yet... */ |
| 2183 | ospf_summary_incremental_update(new); */ |
| 2184 | #else /* #if 0 */ |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 2185 | ospf_spf_calculate_schedule (ospf); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2186 | #endif /* #if 0 */ |
| 2187 | |
| 2188 | if (IS_DEBUG_OSPF (lsa, LSA_INSTALL)) |
| 2189 | zlog_info ("ospf_summary_lsa_install(): SPF scheduled"); |
| 2190 | } |
| 2191 | |
| 2192 | if (IS_LSA_SELF (new)) |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 2193 | ospf_refresher_register_lsa (ospf, new); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2194 | |
| 2195 | return new; |
| 2196 | } |
| 2197 | |
| 2198 | /* Install ASBR-summary-LSA to an area. */ |
| 2199 | struct ospf_lsa * |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 2200 | ospf_summary_asbr_lsa_install (struct ospf *ospf, struct ospf_lsa *new, |
| 2201 | int rt_recalc) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2202 | { |
| 2203 | if (rt_recalc && !IS_LSA_SELF (new)) |
| 2204 | { |
| 2205 | /* RFC 2328 Section 13.2 Summary-LSAs |
| 2206 | The best route to the destination described by the summary- |
| 2207 | LSA must be recalculated (see Section 16.5). If this |
| 2208 | destination is an AS boundary router, it may also be |
| 2209 | necessary to re-examine all the AS-external-LSAs. |
| 2210 | */ |
| 2211 | #if 0 |
| 2212 | /* These don't exist yet... */ |
| 2213 | ospf_summary_incremental_update(new); |
| 2214 | /* Isn't this done by the above call? |
| 2215 | - RFC 2328 Section 16.5 implies it should be */ |
| 2216 | /* ospf_ase_calculate_schedule(); */ |
| 2217 | #else /* #if 0 */ |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 2218 | ospf_spf_calculate_schedule (ospf); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2219 | #endif /* #if 0 */ |
| 2220 | } |
| 2221 | |
| 2222 | /* register LSA to refresh-list. */ |
| 2223 | if (IS_LSA_SELF (new)) |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 2224 | ospf_refresher_register_lsa (ospf, new); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2225 | |
| 2226 | return new; |
| 2227 | } |
| 2228 | |
| 2229 | /* Install AS-external-LSA. */ |
| 2230 | struct ospf_lsa * |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 2231 | ospf_external_lsa_install (struct ospf *ospf, struct ospf_lsa *new, |
| 2232 | int rt_recalc) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2233 | { |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 2234 | ospf_ase_register_external_lsa (new, ospf); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2235 | /* If LSA is not self-originated, calculate an external route. */ |
| 2236 | if (rt_recalc) |
| 2237 | { |
| 2238 | /* RFC 2328 Section 13.2 AS-external-LSAs |
| 2239 | The best route to the destination described by the AS- |
| 2240 | external-LSA must be recalculated (see Section 16.6). |
| 2241 | */ |
| 2242 | |
| 2243 | if (!IS_LSA_SELF (new)) |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 2244 | ospf_ase_incremental_update (ospf, new); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2245 | } |
| 2246 | |
paul | d748032 | 2003-05-16 17:31:51 +0000 | [diff] [blame] | 2247 | #ifdef HAVE_NSSA |
| 2248 | /* There is no point to register selforiginate Type-7 LSA for |
| 2249 | * refreshing. We rely on refreshing Type-5 LSA's */ |
| 2250 | if (IS_LSA_SELF (new) && (new->data->type == OSPF_AS_NSSA_LSA)) |
| 2251 | return new; |
| 2252 | #endif /* HAVE_NSSA */ |
| 2253 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2254 | /* Register self-originated LSA to refresh queue. */ |
| 2255 | if (IS_LSA_SELF (new)) |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 2256 | ospf_refresher_register_lsa (ospf, new); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2257 | |
| 2258 | return new; |
| 2259 | } |
| 2260 | |
| 2261 | void |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 2262 | ospf_discard_from_db (struct ospf *ospf, |
| 2263 | struct ospf_lsdb *lsdb, struct ospf_lsa *lsa) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2264 | { |
| 2265 | struct ospf_lsa *old; |
| 2266 | |
| 2267 | old = ospf_lsdb_lookup (lsdb, lsa); |
| 2268 | |
| 2269 | if (!old) |
| 2270 | return; |
| 2271 | |
| 2272 | if (old->refresh_list >= 0) |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 2273 | ospf_refresher_unregister_lsa (ospf, old); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2274 | |
| 2275 | switch (old->data->type) |
| 2276 | { |
| 2277 | case OSPF_AS_EXTERNAL_LSA: |
| 2278 | #ifdef HAVE_OPAQUE_LSA |
| 2279 | case OSPF_OPAQUE_AS_LSA: |
| 2280 | #endif /* HAVE_OPAQUE_LSA */ |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 2281 | ospf_ls_retransmit_delete_nbr_as (ospf, old); |
| 2282 | ospf_ase_unregister_external_lsa (old, ospf); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2283 | break; |
paul | d748032 | 2003-05-16 17:31:51 +0000 | [diff] [blame] | 2284 | #ifdef HAVE_NSSA |
| 2285 | case OSPF_AS_NSSA_LSA: |
| 2286 | ospf_ls_retransmit_delete_nbr_area (old->area, old); |
| 2287 | ospf_ase_unregister_external_lsa (old, ospf); |
| 2288 | break; |
| 2289 | #endif /* HAVE_NSSA */ |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2290 | default: |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 2291 | ospf_ls_retransmit_delete_nbr_area (old->area, old); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2292 | break; |
| 2293 | } |
| 2294 | |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 2295 | ospf_lsa_maxage_delete (ospf, old); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2296 | ospf_lsa_discard (old); |
| 2297 | } |
| 2298 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2299 | struct ospf_lsa * |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 2300 | ospf_lsa_install (struct ospf *ospf, struct ospf_interface *oi, |
| 2301 | struct ospf_lsa *lsa) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2302 | { |
| 2303 | struct ospf_lsa *new = NULL; |
| 2304 | struct ospf_lsa *old = NULL; |
| 2305 | struct ospf_lsdb *lsdb = NULL; |
| 2306 | int rt_recalc; |
| 2307 | |
| 2308 | /* Set LSDB. */ |
| 2309 | switch (lsa->data->type) |
| 2310 | { |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 2311 | #ifdef HAVE_NSSA |
paul | f2c8065 | 2002-12-13 21:44:27 +0000 | [diff] [blame] | 2312 | /* kevinm */ |
| 2313 | case OSPF_AS_NSSA_LSA: |
| 2314 | if (lsa->area) |
| 2315 | lsdb = lsa->area->lsdb; |
| 2316 | else |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 2317 | lsdb = ospf->lsdb; |
paul | f2c8065 | 2002-12-13 21:44:27 +0000 | [diff] [blame] | 2318 | break; |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 2319 | #endif /* HAVE_NSSA */ |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2320 | case OSPF_AS_EXTERNAL_LSA: |
| 2321 | #ifdef HAVE_OPAQUE_LSA |
| 2322 | case OSPF_OPAQUE_AS_LSA: |
| 2323 | #endif /* HAVE_OPAQUE_LSA */ |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 2324 | lsdb = ospf->lsdb; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2325 | break; |
| 2326 | default: |
| 2327 | lsdb = lsa->area->lsdb; |
| 2328 | break; |
| 2329 | } |
| 2330 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2331 | assert (lsdb); |
| 2332 | |
| 2333 | /* RFC 2328 13.2. Installing LSAs in the database |
| 2334 | |
| 2335 | Installing a new LSA in the database, either as the result of |
| 2336 | flooding or a newly self-originated LSA, may cause the OSPF |
| 2337 | routing table structure to be recalculated. The contents of the |
| 2338 | new LSA should be compared to the old instance, if present. If |
| 2339 | there is no difference, there is no need to recalculate the |
| 2340 | routing table. When comparing an LSA to its previous instance, |
| 2341 | the following are all considered to be differences in contents: |
| 2342 | |
| 2343 | o The LSA's Options field has changed. |
| 2344 | |
| 2345 | o One of the LSA instances has LS age set to MaxAge, and |
| 2346 | the other does not. |
| 2347 | |
| 2348 | o The length field in the LSA header has changed. |
| 2349 | |
| 2350 | o The body of the LSA (i.e., anything outside the 20-byte |
| 2351 | LSA header) has changed. Note that this excludes changes |
| 2352 | in LS Sequence Number and LS Checksum. |
| 2353 | |
| 2354 | */ |
| 2355 | /* Look up old LSA and determine if any SPF calculation or incremental |
| 2356 | update is needed */ |
| 2357 | old = ospf_lsdb_lookup (lsdb, lsa); |
| 2358 | |
| 2359 | /* Do comparision and record if recalc needed. */ |
| 2360 | rt_recalc = 0; |
| 2361 | if ( old == NULL || ospf_lsa_different(old, lsa)) |
| 2362 | rt_recalc = 1; |
| 2363 | |
| 2364 | /* discard old LSA from LSDB */ |
| 2365 | if (old != NULL) |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 2366 | ospf_discard_from_db (ospf, lsdb, lsa); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2367 | |
| 2368 | /* Insert LSA to LSDB. */ |
| 2369 | ospf_lsdb_add (lsdb, lsa); |
| 2370 | lsa->lsdb = lsdb; |
| 2371 | |
| 2372 | /* Calculate Checksum if self-originated?. */ |
| 2373 | if (IS_LSA_SELF (lsa)) |
| 2374 | ospf_lsa_checksum (lsa->data); |
| 2375 | |
| 2376 | /* Do LSA specific installation process. */ |
| 2377 | switch (lsa->data->type) |
| 2378 | { |
| 2379 | case OSPF_ROUTER_LSA: |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 2380 | new = ospf_router_lsa_install (ospf, lsa, rt_recalc); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2381 | break; |
| 2382 | case OSPF_NETWORK_LSA: |
| 2383 | assert (oi); |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 2384 | new = ospf_network_lsa_install (ospf, oi, lsa, rt_recalc); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2385 | break; |
| 2386 | case OSPF_SUMMARY_LSA: |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 2387 | new = ospf_summary_lsa_install (ospf, lsa, rt_recalc); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2388 | break; |
| 2389 | case OSPF_ASBR_SUMMARY_LSA: |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 2390 | new = ospf_summary_asbr_lsa_install (ospf, lsa, rt_recalc); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2391 | break; |
| 2392 | case OSPF_AS_EXTERNAL_LSA: |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 2393 | new = ospf_external_lsa_install (ospf, lsa, rt_recalc); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2394 | break; |
| 2395 | #ifdef HAVE_OPAQUE_LSA |
| 2396 | case OSPF_OPAQUE_LINK_LSA: |
paul | 09e4efd | 2003-01-18 00:12:02 +0000 | [diff] [blame] | 2397 | if (IS_LSA_SELF (lsa)) |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 2398 | lsa->oi = oi; /* Specify outgoing ospf-interface for this LSA. */ |
paul | 09e4efd | 2003-01-18 00:12:02 +0000 | [diff] [blame] | 2399 | else |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 2400 | ; /* Incoming "oi" for this LSA has set at LSUpd reception. */ |
paul | 09e4efd | 2003-01-18 00:12:02 +0000 | [diff] [blame] | 2401 | /* Fallthrough */ |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2402 | case OSPF_OPAQUE_AREA_LSA: |
| 2403 | case OSPF_OPAQUE_AS_LSA: |
| 2404 | new = ospf_opaque_lsa_install (lsa, rt_recalc); |
| 2405 | break; |
| 2406 | #endif /* HAVE_OPAQUE_LSA */ |
| 2407 | default: /* NSSA, or type-6,8,9....nothing special */ |
| 2408 | #ifdef HAVE_NSSA |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 2409 | new = ospf_external_lsa_install (ospf, lsa, rt_recalc); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2410 | #endif /* HAVE_NSSA */ |
| 2411 | break; |
| 2412 | } |
| 2413 | |
| 2414 | if (new == NULL) |
| 2415 | return new; /* Installation failed, cannot proceed further -- endo. */ |
| 2416 | |
| 2417 | /* Debug logs. */ |
| 2418 | if (IS_DEBUG_OSPF (lsa, LSA_INSTALL)) |
| 2419 | { |
| 2420 | char area_str[INET_ADDRSTRLEN]; |
| 2421 | |
| 2422 | switch (lsa->data->type) |
| 2423 | { |
| 2424 | case OSPF_AS_EXTERNAL_LSA: |
| 2425 | #ifdef HAVE_OPAQUE_LSA |
| 2426 | case OSPF_OPAQUE_AS_LSA: |
| 2427 | #endif /* HAVE_OPAQUE_LSA */ |
paul | f2c8065 | 2002-12-13 21:44:27 +0000 | [diff] [blame] | 2428 | #ifdef HAVE_NSSA |
| 2429 | case OSPF_AS_NSSA_LSA: |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 2430 | #endif /* HAVE_NSSA */ |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2431 | zlog_info ("LSA[%s]: Install %s", |
| 2432 | dump_lsa_key (new), |
| 2433 | LOOKUP (ospf_lsa_type_msg, new->data->type)); |
| 2434 | break; |
| 2435 | default: |
| 2436 | strcpy (area_str, inet_ntoa (new->area->area_id)); |
| 2437 | zlog_info ("LSA[%s]: Install %s to Area %s", |
| 2438 | dump_lsa_key (new), |
| 2439 | LOOKUP (ospf_lsa_type_msg, new->data->type), area_str); |
| 2440 | break; |
| 2441 | } |
| 2442 | } |
| 2443 | |
| 2444 | /* If received LSA' ls_age is MaxAge, set LSA on MaxAge LSA list. */ |
| 2445 | if (IS_LSA_MAXAGE (new) && !IS_LSA_SELF (new)) |
| 2446 | { |
| 2447 | if (IS_DEBUG_OSPF (lsa, LSA_FLOODING)) |
| 2448 | zlog_info ("LSA[Type%d:%s]: Install LSA, MaxAge", |
| 2449 | new->data->type, inet_ntoa (new->data->id)); |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 2450 | ospf_lsa_maxage (ospf, lsa); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2451 | } |
| 2452 | |
| 2453 | return new; |
| 2454 | } |
| 2455 | |
| 2456 | |
| 2457 | int |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 2458 | ospf_check_nbr_status (struct ospf *ospf) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2459 | { |
| 2460 | listnode node; |
| 2461 | |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 2462 | for (node = listhead (ospf->oiflist); node; node = nextnode (node)) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2463 | { |
| 2464 | struct ospf_interface *oi = getdata (node); |
| 2465 | struct route_node *rn; |
| 2466 | struct ospf_neighbor *nbr; |
| 2467 | |
| 2468 | if (ospf_if_is_enable (oi)) |
| 2469 | for (rn = route_top (oi->nbrs); rn; rn = route_next (rn)) |
| 2470 | if ((nbr = rn->info) != NULL) |
| 2471 | if (nbr->state == NSM_Exchange || nbr->state == NSM_Loading) |
| 2472 | { |
| 2473 | route_unlock_node (rn); |
| 2474 | return 0; |
| 2475 | } |
| 2476 | } |
| 2477 | |
| 2478 | return 1; |
| 2479 | } |
| 2480 | |
| 2481 | |
| 2482 | #ifdef ORIGINAL_CODING |
| 2483 | /* This function flood the maxaged LSA to DR. */ |
| 2484 | void |
| 2485 | ospf_maxage_flood (struct ospf_lsa *lsa) |
| 2486 | { |
| 2487 | switch (lsa->data->type) |
| 2488 | { |
| 2489 | case OSPF_ROUTER_LSA: |
| 2490 | case OSPF_NETWORK_LSA: |
| 2491 | case OSPF_SUMMARY_LSA: |
| 2492 | case OSPF_ASBR_SUMMARY_LSA: |
| 2493 | #ifdef HAVE_NSSA |
| 2494 | case OSPF_AS_NSSA_LSA: |
| 2495 | #endif /* HAVE_NSSA */ |
| 2496 | #ifdef HAVE_OPAQUE_LSA |
| 2497 | case OSPF_OPAQUE_LINK_LSA: |
| 2498 | case OSPF_OPAQUE_AREA_LSA: |
| 2499 | #endif /* HAVE_OPAQUE_LSA */ |
| 2500 | ospf_flood_through_area (lsa->area, NULL, lsa); |
| 2501 | break; |
| 2502 | case OSPF_AS_EXTERNAL_LSA: |
| 2503 | #ifdef HAVE_OPAQUE_LSA |
| 2504 | case OSPF_OPAQUE_AS_LSA: |
| 2505 | #endif /* HAVE_OPAQUE_LSA */ |
| 2506 | ospf_flood_through_as (NULL, lsa); |
| 2507 | break; |
| 2508 | default: |
| 2509 | break; |
| 2510 | } |
| 2511 | } |
| 2512 | #endif /* ORIGINAL_CODING */ |
| 2513 | |
| 2514 | int |
| 2515 | ospf_maxage_lsa_remover (struct thread *thread) |
| 2516 | { |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 2517 | struct ospf *ospf = THREAD_ARG (thread); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2518 | listnode node; |
| 2519 | listnode next; |
| 2520 | int reschedule = 0; |
| 2521 | |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 2522 | ospf->t_maxage = NULL; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2523 | |
| 2524 | if (IS_DEBUG_OSPF (lsa, LSA_FLOODING)) |
| 2525 | zlog_info ("LSA[MaxAge]: remover Start"); |
| 2526 | |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 2527 | reschedule = !ospf_check_nbr_status (ospf); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2528 | |
| 2529 | if (!reschedule) |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 2530 | for (node = listhead (ospf->maxage_lsa); node; node = next) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2531 | { |
| 2532 | struct ospf_lsa *lsa = getdata (node); |
| 2533 | next = node->next; |
| 2534 | |
| 2535 | if (lsa->retransmit_counter > 0) |
| 2536 | { |
| 2537 | reschedule = 1; |
| 2538 | continue; |
| 2539 | } |
| 2540 | |
| 2541 | /* Remove LSA from the LSDB */ |
| 2542 | if (CHECK_FLAG (lsa->flags, OSPF_LSA_SELF)) |
| 2543 | if (IS_DEBUG_OSPF (lsa, LSA_FLOODING)) |
| 2544 | zlog_info ("LSA[Type%d:%s]: This LSA is self-originated: ", |
| 2545 | lsa->data->type, inet_ntoa (lsa->data->id)); |
| 2546 | |
| 2547 | if (IS_DEBUG_OSPF (lsa, LSA_FLOODING)) |
| 2548 | zlog_info ("LSA[Type%d:%s]: MaxAge LSA removed from list", |
| 2549 | lsa->data->type, inet_ntoa (lsa->data->id)); |
| 2550 | |
| 2551 | /* Flood max age LSA. */ |
| 2552 | #ifdef ORIGINAL_CODING |
| 2553 | ospf_maxage_flood (lsa); |
| 2554 | #else /* ORIGINAL_CODING */ |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 2555 | ospf_flood_through (ospf, NULL, lsa); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2556 | #endif /* ORIGINAL_CODING */ |
| 2557 | |
| 2558 | /* Remove from lsdb. */ |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 2559 | ospf_discard_from_db (ospf, lsa->lsdb, lsa); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2560 | ospf_lsdb_delete (lsa->lsdb, lsa); |
| 2561 | } |
| 2562 | |
| 2563 | /* A MaxAge LSA must be removed immediately from the router's link |
| 2564 | state database as soon as both a) it is no longer contained on any |
| 2565 | neighbor Link state retransmission lists and b) none of the router's |
| 2566 | neighbors are in states Exchange or Loading. */ |
| 2567 | if (reschedule) |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 2568 | OSPF_TIMER_ON (ospf->t_maxage, ospf_maxage_lsa_remover, 2); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2569 | |
| 2570 | return 0; |
| 2571 | } |
| 2572 | |
| 2573 | int |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 2574 | ospf_lsa_maxage_exist (struct ospf *ospf, struct ospf_lsa *new) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2575 | { |
| 2576 | listnode node; |
| 2577 | |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 2578 | for (node = listhead (ospf->maxage_lsa); node; nextnode (node)) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2579 | if (((struct ospf_lsa *) node->data) == new) |
| 2580 | return 1; |
| 2581 | |
| 2582 | return 0; |
| 2583 | } |
| 2584 | |
| 2585 | void |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 2586 | ospf_lsa_maxage_delete (struct ospf *ospf, struct ospf_lsa *lsa) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2587 | { |
| 2588 | listnode n; |
| 2589 | |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 2590 | if ((n = listnode_lookup (ospf->maxage_lsa, lsa))) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2591 | { |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 2592 | list_delete_node (ospf->maxage_lsa, n); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2593 | ospf_lsa_unlock (lsa); |
| 2594 | } |
| 2595 | } |
| 2596 | |
| 2597 | void |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 2598 | ospf_lsa_maxage (struct ospf *ospf, struct ospf_lsa *lsa) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2599 | { |
| 2600 | /* When we saw a MaxAge LSA flooded to us, we put it on the list |
| 2601 | and schedule the MaxAge LSA remover. */ |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 2602 | if (ospf_lsa_maxage_exist (ospf, lsa)) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2603 | { |
| 2604 | if (IS_DEBUG_OSPF (lsa, LSA_FLOODING)) |
| 2605 | zlog_info ("LSA[Type%d:%s]: %p already exists on MaxAge LSA list", |
| 2606 | lsa->data->type, inet_ntoa (lsa->data->id), lsa); |
| 2607 | return; |
| 2608 | } |
| 2609 | |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 2610 | listnode_add (ospf->maxage_lsa, ospf_lsa_lock (lsa)); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2611 | |
| 2612 | if (IS_DEBUG_OSPF (lsa, LSA_FLOODING)) |
| 2613 | zlog_info ("LSA[%s]: MaxAge LSA remover scheduled.", dump_lsa_key (lsa)); |
| 2614 | |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 2615 | OSPF_TIMER_ON (ospf->t_maxage, ospf_maxage_lsa_remover, 2); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2616 | } |
| 2617 | |
| 2618 | int |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 2619 | ospf_lsa_maxage_walker_remover (struct ospf *ospf, struct ospf_lsa *lsa) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2620 | { |
| 2621 | #ifdef HAVE_NSSA |
| 2622 | /* Stay away from any Local Translated Type-7 LSAs */ |
| 2623 | if (CHECK_FLAG (lsa->flags, OSPF_LSA_LOCAL_XLT)) |
| 2624 | return 0; |
| 2625 | #endif /* HAVE_NSSA */ |
| 2626 | |
| 2627 | if (IS_LSA_MAXAGE (lsa)) |
| 2628 | /* Self-originated LSAs should NOT time-out instead, |
| 2629 | they're flushed and submitted to the max_age list explicitly. */ |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 2630 | if (!ospf_lsa_is_self_originated (ospf, lsa)) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2631 | { |
| 2632 | if (IS_DEBUG_OSPF (lsa, LSA_FLOODING)) |
| 2633 | zlog_info("LSA[%s]: is MaxAge", dump_lsa_key (lsa)); |
| 2634 | |
| 2635 | switch (lsa->data->type) |
| 2636 | { |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2637 | #ifdef HAVE_OPAQUE_LSA |
paul | 37163d6 | 2003-02-03 18:40:56 +0000 | [diff] [blame] | 2638 | case OSPF_OPAQUE_LINK_LSA: |
| 2639 | case OSPF_OPAQUE_AREA_LSA: |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2640 | case OSPF_OPAQUE_AS_LSA: |
paul | 09e4efd | 2003-01-18 00:12:02 +0000 | [diff] [blame] | 2641 | /* |
| 2642 | * As a general rule, whenever network topology has changed |
| 2643 | * (due to an LSA removal in this case), routing recalculation |
| 2644 | * should be triggered. However, this is not true for opaque |
| 2645 | * LSAs. Even if an opaque LSA instance is going to be removed |
| 2646 | * from the routing domain, it does not mean a change in network |
| 2647 | * topology, and thus, routing recalculation is not needed here. |
| 2648 | */ |
| 2649 | break; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2650 | #endif /* HAVE_OPAQUE_LSA */ |
paul | 09e4efd | 2003-01-18 00:12:02 +0000 | [diff] [blame] | 2651 | case OSPF_AS_EXTERNAL_LSA: |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 2652 | #ifdef HAVE_NSSA |
| 2653 | case OSPF_AS_NSSA_LSA: |
| 2654 | #endif /* HAVE_NSSA */ |
| 2655 | ospf_ase_incremental_update (ospf, lsa); |
| 2656 | break; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2657 | default: |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 2658 | ospf_spf_calculate_schedule (ospf); |
| 2659 | break; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2660 | } |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 2661 | ospf_lsa_maxage (ospf, lsa); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2662 | } |
| 2663 | |
| 2664 | return 0; |
| 2665 | } |
| 2666 | |
| 2667 | /* Periodical check of MaxAge LSA. */ |
| 2668 | int |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 2669 | ospf_lsa_maxage_walker (struct thread *thread) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2670 | { |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 2671 | struct ospf *ospf = THREAD_ARG (thread); |
| 2672 | struct route_node *rn; |
| 2673 | struct ospf_lsa *lsa; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2674 | listnode node; |
| 2675 | |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 2676 | ospf->t_maxage_walker = NULL; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2677 | |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 2678 | for (node = listhead (ospf->areas); node; nextnode (node)) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2679 | { |
| 2680 | struct ospf_area *area = node->data; |
| 2681 | |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 2682 | LSDB_LOOP (ROUTER_LSDB (area), rn, lsa) |
| 2683 | ospf_lsa_maxage_walker_remover (ospf, lsa); |
| 2684 | LSDB_LOOP (NETWORK_LSDB (area), rn, lsa) |
| 2685 | ospf_lsa_maxage_walker_remover (ospf, lsa); |
| 2686 | LSDB_LOOP (SUMMARY_LSDB (area), rn, lsa) |
| 2687 | ospf_lsa_maxage_walker_remover (ospf, lsa); |
| 2688 | LSDB_LOOP (ASBR_SUMMARY_LSDB (area), rn, lsa) |
| 2689 | ospf_lsa_maxage_walker_remover (ospf, lsa); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2690 | #ifdef HAVE_OPAQUE_LSA |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 2691 | LSDB_LOOP (OPAQUE_AREA_LSDB (area), rn, lsa) |
| 2692 | ospf_lsa_maxage_walker_remover (ospf, lsa); |
| 2693 | LSDB_LOOP (OPAQUE_LINK_LSDB (area), rn, lsa) |
| 2694 | ospf_lsa_maxage_walker_remover (ospf, lsa); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2695 | #endif /* HAVE_OPAQUE_LSA */ |
paul | 4fb949e | 2003-05-10 20:06:51 +0000 | [diff] [blame] | 2696 | #ifdef HAVE_NSSA |
| 2697 | LSDB_LOOP (NSSA_LSDB (area), rn, lsa) |
| 2698 | ospf_lsa_maxage_walker_remover (ospf, lsa); |
| 2699 | #endif /* HAVE_NSSA */ |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2700 | } |
| 2701 | |
paul | 4fb949e | 2003-05-10 20:06:51 +0000 | [diff] [blame] | 2702 | /* for AS-external-LSAs. */ |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 2703 | if (ospf->lsdb) |
| 2704 | { |
| 2705 | LSDB_LOOP (EXTERNAL_LSDB (ospf), rn, lsa) |
| 2706 | ospf_lsa_maxage_walker_remover (ospf, lsa); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2707 | #ifdef HAVE_OPAQUE_LSA |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 2708 | LSDB_LOOP (OPAQUE_AS_LSDB (ospf), rn, lsa) |
| 2709 | ospf_lsa_maxage_walker_remover (ospf, lsa); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2710 | #endif /* HAVE_OPAQUE_LSA */ |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 2711 | } |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2712 | |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 2713 | OSPF_TIMER_ON (ospf->t_maxage_walker, ospf_lsa_maxage_walker, |
| 2714 | OSPF_LSA_MAXAGE_CHECK_INTERVAL); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2715 | return 0; |
| 2716 | } |
| 2717 | |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 2718 | struct ospf_lsa * |
| 2719 | ospf_lsa_lookup_by_prefix (struct ospf_lsdb *lsdb, u_char type, |
| 2720 | struct prefix_ipv4 *p, struct in_addr router_id) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2721 | { |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 2722 | struct ospf_lsa *lsa; |
| 2723 | struct in_addr mask, id; |
| 2724 | struct lsa_header_mask |
| 2725 | { |
| 2726 | struct lsa_header header; |
| 2727 | struct in_addr mask; |
| 2728 | } *hmask; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2729 | |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 2730 | lsa = ospf_lsdb_lookup_by_id (lsdb, type, p->prefix, router_id); |
| 2731 | if (lsa == NULL) |
| 2732 | return NULL; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2733 | |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 2734 | masklen2ip (p->prefixlen, &mask); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2735 | |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 2736 | hmask = (struct lsa_header_mask *) lsa->data; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2737 | |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 2738 | if (mask.s_addr != hmask->mask.s_addr) |
| 2739 | { |
| 2740 | id.s_addr = p->prefix.s_addr | (~mask.s_addr); |
| 2741 | lsa = ospf_lsdb_lookup_by_id (lsdb, type, id, router_id); |
| 2742 | if (!lsa) |
| 2743 | return NULL; |
| 2744 | } |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2745 | |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 2746 | return lsa; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2747 | } |
| 2748 | |
| 2749 | struct ospf_lsa * |
| 2750 | ospf_lsa_lookup (struct ospf_area *area, u_int32_t type, |
| 2751 | struct in_addr id, struct in_addr adv_router) |
| 2752 | { |
paul | e05fba4 | 2003-04-13 20:20:53 +0000 | [diff] [blame] | 2753 | struct ospf *ospf = ospf_lookup(); |
| 2754 | assert(ospf); |
| 2755 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2756 | switch (type) |
| 2757 | { |
| 2758 | case OSPF_ROUTER_LSA: |
| 2759 | case OSPF_NETWORK_LSA: |
| 2760 | case OSPF_SUMMARY_LSA: |
| 2761 | case OSPF_ASBR_SUMMARY_LSA: |
| 2762 | #ifdef HAVE_NSSA |
| 2763 | case OSPF_AS_NSSA_LSA: |
| 2764 | #endif /* HAVE_NSSA */ |
| 2765 | #ifdef HAVE_OPAQUE_LSA |
| 2766 | case OSPF_OPAQUE_LINK_LSA: |
| 2767 | case OSPF_OPAQUE_AREA_LSA: |
| 2768 | #endif /* HAVE_OPAQUE_LSA */ |
| 2769 | return ospf_lsdb_lookup_by_id (area->lsdb, type, id, adv_router); |
| 2770 | break; |
| 2771 | case OSPF_AS_EXTERNAL_LSA: |
| 2772 | #ifdef HAVE_OPAQUE_LSA |
| 2773 | case OSPF_OPAQUE_AS_LSA: |
| 2774 | #endif /* HAVE_OPAQUE_LSA */ |
paul | e05fba4 | 2003-04-13 20:20:53 +0000 | [diff] [blame] | 2775 | return ospf_lsdb_lookup_by_id (ospf->lsdb, type, id, adv_router); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2776 | break; |
| 2777 | default: |
| 2778 | break; |
| 2779 | } |
| 2780 | |
| 2781 | return NULL; |
| 2782 | } |
| 2783 | |
| 2784 | struct ospf_lsa * |
| 2785 | ospf_lsa_lookup_by_id (struct ospf_area *area, u_int32_t type, |
| 2786 | struct in_addr id) |
| 2787 | { |
| 2788 | struct ospf_lsa *lsa; |
| 2789 | struct route_node *rn; |
| 2790 | |
| 2791 | switch (type) |
| 2792 | { |
| 2793 | case OSPF_ROUTER_LSA: |
| 2794 | return ospf_lsdb_lookup_by_id (area->lsdb, type, id, id); |
| 2795 | break; |
| 2796 | case OSPF_NETWORK_LSA: |
| 2797 | for (rn = route_top (NETWORK_LSDB (area)); rn; rn = route_next (rn)) |
| 2798 | if ((lsa = rn->info)) |
| 2799 | if (IPV4_ADDR_SAME (&lsa->data->id, &id)) |
| 2800 | { |
| 2801 | route_unlock_node (rn); |
| 2802 | return lsa; |
| 2803 | } |
| 2804 | break; |
| 2805 | case OSPF_SUMMARY_LSA: |
| 2806 | case OSPF_ASBR_SUMMARY_LSA: |
| 2807 | /* Currently not used. */ |
| 2808 | assert (1); |
| 2809 | return ospf_lsdb_lookup_by_id (area->lsdb, type, id, id); |
| 2810 | break; |
| 2811 | case OSPF_AS_EXTERNAL_LSA: |
| 2812 | #ifdef HAVE_OPAQUE_LSA |
| 2813 | case OSPF_OPAQUE_LINK_LSA: |
| 2814 | case OSPF_OPAQUE_AREA_LSA: |
| 2815 | case OSPF_OPAQUE_AS_LSA: |
| 2816 | /* Currently not used. */ |
| 2817 | break; |
| 2818 | #endif /* HAVE_OPAQUE_LSA */ |
| 2819 | default: |
| 2820 | break; |
| 2821 | } |
| 2822 | |
| 2823 | return NULL; |
| 2824 | } |
| 2825 | |
| 2826 | struct ospf_lsa * |
| 2827 | ospf_lsa_lookup_by_header (struct ospf_area *area, struct lsa_header *lsah) |
| 2828 | { |
| 2829 | struct ospf_lsa *match; |
| 2830 | |
| 2831 | #ifdef HAVE_OPAQUE_LSA |
| 2832 | /* |
| 2833 | * Strictly speaking, the LSA-ID field for Opaque-LSAs (type-9/10/11) |
| 2834 | * is redefined to have two subfields; opaque-type and opaque-id. |
| 2835 | * However, it is harmless to treat the two sub fields together, as if |
| 2836 | * they two were forming a unique LSA-ID. |
| 2837 | */ |
| 2838 | #endif /* HAVE_OPAQUE_LSA */ |
| 2839 | |
| 2840 | match = ospf_lsa_lookup (area, lsah->type, lsah->id, lsah->adv_router); |
| 2841 | |
| 2842 | if (match == NULL) |
| 2843 | if (IS_DEBUG_OSPF (lsa, LSA) == OSPF_DEBUG_LSA) |
| 2844 | zlog_info ("LSA[Type%d:%s]: Lookup by header, NO MATCH", |
| 2845 | lsah->type, inet_ntoa (lsah->id)); |
| 2846 | |
| 2847 | return match; |
| 2848 | } |
| 2849 | |
| 2850 | /* return +n, l1 is more recent. |
| 2851 | return -n, l2 is more recent. |
| 2852 | return 0, l1 and l2 is identical. */ |
| 2853 | int |
| 2854 | ospf_lsa_more_recent (struct ospf_lsa *l1, struct ospf_lsa *l2) |
| 2855 | { |
| 2856 | int r; |
| 2857 | int x, y; |
| 2858 | |
| 2859 | if (l1 == NULL && l2 == NULL) |
| 2860 | return 0; |
| 2861 | if (l1 == NULL) |
| 2862 | return -1; |
| 2863 | if (l2 == NULL) |
| 2864 | return 1; |
| 2865 | |
| 2866 | /* compare LS sequence number. */ |
| 2867 | x = (int) ntohl (l1->data->ls_seqnum); |
| 2868 | y = (int) ntohl (l2->data->ls_seqnum); |
| 2869 | if (x > y) |
| 2870 | return 1; |
| 2871 | if (x < y) |
| 2872 | return -1; |
| 2873 | |
| 2874 | /* compare LS checksum. */ |
| 2875 | r = ntohs (l1->data->checksum) - ntohs (l2->data->checksum); |
| 2876 | if (r) |
| 2877 | return r; |
| 2878 | |
| 2879 | /* compare LS age. */ |
| 2880 | if (IS_LSA_MAXAGE (l1) && !IS_LSA_MAXAGE (l2)) |
| 2881 | return 1; |
| 2882 | else if (!IS_LSA_MAXAGE (l1) && IS_LSA_MAXAGE (l2)) |
| 2883 | return -1; |
| 2884 | |
| 2885 | /* compare LS age with MaxAgeDiff. */ |
| 2886 | if (LS_AGE (l1) - LS_AGE (l2) > OSPF_LSA_MAXAGE_DIFF) |
| 2887 | return -1; |
| 2888 | else if (LS_AGE (l2) - LS_AGE (l1) > OSPF_LSA_MAXAGE_DIFF) |
| 2889 | return 1; |
| 2890 | |
| 2891 | /* LSAs are identical. */ |
| 2892 | return 0; |
| 2893 | } |
| 2894 | |
| 2895 | /* If two LSAs are different, return 1, otherwise return 0. */ |
| 2896 | int |
| 2897 | ospf_lsa_different (struct ospf_lsa *l1, struct ospf_lsa *l2) |
| 2898 | { |
| 2899 | char *p1, *p2; |
| 2900 | assert (l1); |
| 2901 | assert (l2); |
| 2902 | assert (l1->data); |
| 2903 | assert (l2->data); |
| 2904 | |
| 2905 | if (l1->data->options != l2->data->options) |
| 2906 | return 1; |
| 2907 | |
| 2908 | if (IS_LSA_MAXAGE (l1) && !IS_LSA_MAXAGE (l2)) |
| 2909 | return 1; |
| 2910 | |
| 2911 | if (IS_LSA_MAXAGE (l2) && !IS_LSA_MAXAGE (l1)) |
| 2912 | return 1; |
| 2913 | |
| 2914 | if (l1->data->length != l2->data->length) |
| 2915 | return 1; |
| 2916 | |
| 2917 | if (l1->data->length == 0) |
| 2918 | return 1; |
| 2919 | |
paul | d182583 | 2003-04-03 01:27:01 +0000 | [diff] [blame] | 2920 | assert ( ntohs(l1->data->length) > OSPF_LSA_HEADER_SIZE); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2921 | |
| 2922 | p1 = (char *) l1->data; |
| 2923 | p2 = (char *) l2->data; |
| 2924 | |
| 2925 | if (memcmp (p1 + OSPF_LSA_HEADER_SIZE, p2 + OSPF_LSA_HEADER_SIZE, |
| 2926 | ntohs( l1->data->length ) - OSPF_LSA_HEADER_SIZE) != 0) |
| 2927 | return 1; |
| 2928 | |
| 2929 | return 0; |
| 2930 | } |
| 2931 | |
| 2932 | #ifdef ORIGINAL_CODING |
| 2933 | void |
| 2934 | ospf_lsa_flush_self_originated (struct ospf_neighbor *nbr, |
| 2935 | struct ospf_lsa *self, |
| 2936 | struct ospf_lsa *new) |
| 2937 | { |
| 2938 | u_int32_t seqnum; |
| 2939 | |
| 2940 | /* Adjust LS Sequence Number. */ |
| 2941 | seqnum = ntohl (new->data->ls_seqnum) + 1; |
| 2942 | self->data->ls_seqnum = htonl (seqnum); |
| 2943 | |
| 2944 | /* Recalculate LSA checksum. */ |
| 2945 | ospf_lsa_checksum (self->data); |
| 2946 | |
| 2947 | /* Reflooding LSA. */ |
| 2948 | /* RFC2328 Section 13.3 |
| 2949 | On non-broadcast networks, separate Link State Update |
| 2950 | packets must be sent, as unicasts, to each adjacent neighbor |
| 2951 | (i.e., those in state Exchange or greater). The destination |
| 2952 | IP addresses for these packets are the neighbors' IP |
| 2953 | addresses. */ |
| 2954 | if (nbr->oi->type == OSPF_IFTYPE_NBMA) |
| 2955 | { |
| 2956 | struct route_node *rn; |
| 2957 | struct ospf_neighbor *onbr; |
| 2958 | |
| 2959 | for (rn = route_top (nbr->oi->nbrs); rn; rn = route_next (rn)) |
| 2960 | if ((onbr = rn->info) != NULL) |
| 2961 | if (onbr != nbr->oi->nbr_self && onbr->status >= NSM_Exchange) |
| 2962 | ospf_ls_upd_send_lsa (onbr, self, OSPF_SEND_PACKET_DIRECT); |
| 2963 | } |
| 2964 | else |
| 2965 | ospf_ls_upd_send_lsa (nbr, self, OSPF_SEND_PACKET_INDIRECT); |
| 2966 | |
| 2967 | if (IS_DEBUG_OSPF (lsa, LSA_GENERATE)) |
| 2968 | zlog_info ("LSA[Type%d:%s]: Flush self-originated LSA", |
| 2969 | self->data->type, inet_ntoa (self->data->id)); |
| 2970 | } |
| 2971 | #else /* ORIGINAL_CODING */ |
| 2972 | static int |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 2973 | ospf_lsa_flush_schedule (struct ospf *ospf, struct ospf_lsa *lsa) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2974 | { |
| 2975 | if (lsa == NULL || !IS_LSA_SELF (lsa)) |
| 2976 | return 0; |
| 2977 | |
| 2978 | if (IS_DEBUG_OSPF_EVENT) |
| 2979 | zlog_info ("LSA[Type%d:%s]: Schedule self-originated LSA to FLUSH", lsa->data->type, inet_ntoa (lsa->data->id)); |
| 2980 | |
| 2981 | /* Force given lsa's age to MaxAge. */ |
| 2982 | lsa->data->ls_age = htons (OSPF_LSA_MAXAGE); |
| 2983 | |
| 2984 | switch (lsa->data->type) |
| 2985 | { |
| 2986 | #ifdef HAVE_OPAQUE_LSA |
| 2987 | case OSPF_OPAQUE_LINK_LSA: |
| 2988 | case OSPF_OPAQUE_AREA_LSA: |
| 2989 | case OSPF_OPAQUE_AS_LSA: |
| 2990 | ospf_opaque_lsa_refresh (lsa); |
| 2991 | break; |
| 2992 | #endif /* HAVE_OPAQUE_LSA */ |
| 2993 | default: |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 2994 | ospf_lsa_maxage (ospf, lsa); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2995 | break; |
| 2996 | } |
| 2997 | |
| 2998 | return 0; |
| 2999 | } |
| 3000 | |
| 3001 | void |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 3002 | ospf_flush_self_originated_lsas_now (struct ospf *ospf) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 3003 | { |
| 3004 | listnode n1, n2; |
| 3005 | struct ospf_area *area; |
| 3006 | struct ospf_interface *oi; |
| 3007 | struct ospf_lsa *lsa; |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 3008 | struct route_node *rn; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 3009 | int need_to_flush_ase = 0; |
| 3010 | |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 3011 | for (n1 = listhead (ospf->areas); n1; nextnode (n1)) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 3012 | { |
| 3013 | if ((area = getdata (n1)) == NULL) |
| 3014 | continue; |
| 3015 | |
| 3016 | if ((lsa = area->router_lsa_self) != NULL) |
| 3017 | { |
| 3018 | if (IS_DEBUG_OSPF_EVENT) |
| 3019 | zlog_info ("LSA[Type%d:%s]: Schedule self-originated LSA to FLUSH", lsa->data->type, inet_ntoa (lsa->data->id)); |
| 3020 | |
| 3021 | ospf_lsa_flush_area (lsa, area); |
| 3022 | ospf_lsa_unlock (area->router_lsa_self); |
| 3023 | area->router_lsa_self = NULL; |
| 3024 | OSPF_TIMER_OFF (area->t_router_lsa_self); |
| 3025 | } |
| 3026 | |
| 3027 | for (n2 = listhead (area->oiflist); n2; nextnode (n2)) |
| 3028 | { |
| 3029 | if ((oi = getdata (n2)) == NULL) |
| 3030 | continue; |
| 3031 | |
| 3032 | if ((lsa = oi->network_lsa_self) != NULL |
| 3033 | && oi->state == ISM_DR |
| 3034 | && oi->full_nbrs > 0) |
| 3035 | { |
| 3036 | if (IS_DEBUG_OSPF_EVENT) |
| 3037 | zlog_info ("LSA[Type%d:%s]: Schedule self-originated LSA to FLUSH", lsa->data->type, inet_ntoa (lsa->data->id)); |
| 3038 | |
| 3039 | ospf_lsa_flush_area (oi->network_lsa_self, area); |
| 3040 | ospf_lsa_unlock (oi->network_lsa_self); |
| 3041 | oi->network_lsa_self = NULL; |
| 3042 | OSPF_TIMER_OFF (oi->t_network_lsa_self); |
| 3043 | } |
| 3044 | |
| 3045 | if (oi->type != OSPF_IFTYPE_VIRTUALLINK |
| 3046 | && area->external_routing == OSPF_AREA_DEFAULT) |
| 3047 | need_to_flush_ase = 1; |
| 3048 | } |
| 3049 | |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 3050 | LSDB_LOOP (SUMMARY_LSDB (area), rn, lsa) |
| 3051 | ospf_lsa_flush_schedule (ospf, lsa); |
| 3052 | LSDB_LOOP (ASBR_SUMMARY_LSDB (area), rn, lsa) |
| 3053 | ospf_lsa_flush_schedule (ospf, lsa); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 3054 | #ifdef HAVE_OPAQUE_LSA |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 3055 | LSDB_LOOP (OPAQUE_LINK_LSDB (area), rn, lsa) |
| 3056 | ospf_lsa_flush_schedule (ospf, lsa); |
| 3057 | LSDB_LOOP (OPAQUE_AREA_LSDB (area), rn, lsa) |
| 3058 | ospf_lsa_flush_schedule (ospf, lsa); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 3059 | #endif /* HAVE_OPAQUE_LSA */ |
| 3060 | } |
| 3061 | |
| 3062 | if (need_to_flush_ase) |
| 3063 | { |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 3064 | LSDB_LOOP (EXTERNAL_LSDB (ospf), rn, lsa) |
| 3065 | ospf_lsa_flush_schedule (ospf, lsa); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 3066 | #ifdef HAVE_OPAQUE_LSA |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 3067 | LSDB_LOOP (OPAQUE_AS_LSDB (ospf), rn, lsa) |
| 3068 | ospf_lsa_flush_schedule (ospf, lsa); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 3069 | #endif /* HAVE_OPAQUE_LSA */ |
| 3070 | } |
| 3071 | |
| 3072 | /* |
| 3073 | * Make sure that the MaxAge LSA remover is executed immediately, |
| 3074 | * without conflicting to other threads. |
| 3075 | */ |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 3076 | if (ospf->t_maxage != NULL) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 3077 | { |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 3078 | OSPF_TIMER_OFF (ospf->t_maxage); |
| 3079 | thread_execute (master, ospf_maxage_lsa_remover, ospf, 0); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 3080 | } |
| 3081 | |
| 3082 | return; |
| 3083 | } |
| 3084 | #endif /* ORIGINAL_CODING */ |
| 3085 | |
| 3086 | /* If there is self-originated LSA, then return 1, otherwise return 0. */ |
| 3087 | /* An interface-independent version of ospf_lsa_is_self_originated */ |
| 3088 | int |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 3089 | ospf_lsa_is_self_originated (struct ospf *ospf, struct ospf_lsa *lsa) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 3090 | { |
| 3091 | listnode node; |
| 3092 | |
| 3093 | /* This LSA is already checked. */ |
| 3094 | if (CHECK_FLAG (lsa->flags, OSPF_LSA_SELF_CHECKED)) |
| 3095 | return CHECK_FLAG (lsa->flags, OSPF_LSA_SELF); |
| 3096 | |
| 3097 | /* Make sure LSA is self-checked. */ |
| 3098 | SET_FLAG (lsa->flags, OSPF_LSA_SELF_CHECKED); |
| 3099 | |
| 3100 | /* AdvRouter and Router ID is the same. */ |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 3101 | if (IPV4_ADDR_SAME (&lsa->data->adv_router, &ospf->router_id)) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 3102 | SET_FLAG (lsa->flags, OSPF_LSA_SELF); |
| 3103 | |
| 3104 | /* LSA is router-LSA. */ |
| 3105 | else if (lsa->data->type == OSPF_ROUTER_LSA && |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 3106 | IPV4_ADDR_SAME (&lsa->data->id, &ospf->router_id)) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 3107 | SET_FLAG (lsa->flags, OSPF_LSA_SELF); |
| 3108 | |
| 3109 | /* LSA is network-LSA. Compare Link ID with all interfaces. */ |
| 3110 | else if (lsa->data->type == OSPF_NETWORK_LSA) |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 3111 | for (node = listhead (ospf->oiflist); node; nextnode (node)) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 3112 | { |
| 3113 | struct ospf_interface *oi = getdata (node); |
| 3114 | |
| 3115 | /* Ignore virtual link. */ |
| 3116 | if (oi->type != OSPF_IFTYPE_VIRTUALLINK) |
| 3117 | if (oi->address->family == AF_INET) |
| 3118 | if (IPV4_ADDR_SAME (&lsa->data->id, &oi->address->u.prefix4)) |
| 3119 | { |
| 3120 | /* to make it easier later */ |
| 3121 | SET_FLAG (lsa->flags, OSPF_LSA_SELF); |
| 3122 | return CHECK_FLAG (lsa->flags, OSPF_LSA_SELF); |
| 3123 | } |
| 3124 | } |
| 3125 | |
| 3126 | return CHECK_FLAG (lsa->flags, OSPF_LSA_SELF); |
| 3127 | } |
| 3128 | |
| 3129 | /* Get unique Link State ID. */ |
| 3130 | struct in_addr |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 3131 | ospf_lsa_unique_id (struct ospf *ospf, |
| 3132 | struct ospf_lsdb *lsdb, u_char type, struct prefix_ipv4 *p) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 3133 | { |
| 3134 | struct ospf_lsa *lsa; |
| 3135 | struct in_addr mask, id; |
| 3136 | |
| 3137 | id = p->prefix; |
| 3138 | |
| 3139 | /* Check existence of LSA instance. */ |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 3140 | lsa = ospf_lsdb_lookup_by_id (lsdb, type, id, ospf->router_id); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 3141 | if (lsa) |
| 3142 | { |
| 3143 | struct as_external_lsa *al = (struct as_external_lsa *) lsa->data; |
| 3144 | if (ip_masklen (al->mask) == p->prefixlen) |
| 3145 | { |
| 3146 | if (IS_DEBUG_OSPF (lsa, LSA_GENERATE)) |
| 3147 | zlog_warn ("ospf_lsa_unique_id(): " |
| 3148 | "Can't get Link State ID for %s/%d", |
| 3149 | inet_ntoa (p->prefix), p->prefixlen); |
| 3150 | /* id.s_addr = 0; */ |
| 3151 | id.s_addr = 0xffffffff; |
| 3152 | return id; |
| 3153 | } |
| 3154 | /* Masklen differs, then apply wildcard mask to Link State ID. */ |
| 3155 | else |
| 3156 | { |
| 3157 | masklen2ip (p->prefixlen, &mask); |
| 3158 | |
| 3159 | id.s_addr = p->prefix.s_addr | (~mask.s_addr); |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 3160 | lsa = ospf_lsdb_lookup_by_id (ospf->lsdb, type, |
| 3161 | id, ospf->router_id); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 3162 | if (lsa) |
| 3163 | { |
| 3164 | if (IS_DEBUG_OSPF (lsa, LSA_GENERATE)) |
| 3165 | zlog_warn ("ospf_lsa_unique_id(): " |
| 3166 | "Can't get Link State ID for %s/%d", |
| 3167 | inet_ntoa (p->prefix), p->prefixlen); |
| 3168 | /* id.s_addr = 0; */ |
| 3169 | id.s_addr = 0xffffffff; |
| 3170 | return id; |
| 3171 | } |
| 3172 | } |
| 3173 | } |
| 3174 | |
| 3175 | return id; |
| 3176 | } |
| 3177 | |
| 3178 | |
| 3179 | #define LSA_ACTION_ORIGN_RTR 1 |
| 3180 | #define LSA_ACTION_ORIGN_NET 2 |
| 3181 | #define LSA_ACTION_FLOOD_AREA 3 |
| 3182 | #define LSA_ACTION_FLOOD_AS 4 |
| 3183 | #define LSA_ACTION_FLUSH_AREA 5 |
| 3184 | #define LSA_ACTION_FLUSH_AS 6 |
| 3185 | |
| 3186 | struct lsa_action |
| 3187 | { |
| 3188 | u_char action; |
| 3189 | struct ospf_area *area; |
| 3190 | struct ospf_interface *oi; |
| 3191 | struct ospf_lsa *lsa; |
| 3192 | }; |
| 3193 | |
| 3194 | int |
| 3195 | ospf_lsa_action (struct thread *t) |
| 3196 | { |
| 3197 | struct lsa_action *data; |
paul | 020709f | 2003-04-04 02:44:16 +0000 | [diff] [blame] | 3198 | struct ospf *ospf; |
| 3199 | |
| 3200 | ospf = ospf_lookup (); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 3201 | |
| 3202 | data = THREAD_ARG (t); |
| 3203 | |
| 3204 | if (IS_DEBUG_OSPF (lsa, LSA) == OSPF_DEBUG_LSA) |
| 3205 | zlog_info ("LSA[Action]: Performing scheduled LSA action: %d", |
| 3206 | data->action); |
| 3207 | |
| 3208 | switch (data->action) |
| 3209 | { |
| 3210 | case LSA_ACTION_ORIGN_RTR: |
| 3211 | ospf_router_lsa_refresh (data->area->router_lsa_self); |
| 3212 | break; |
| 3213 | case LSA_ACTION_ORIGN_NET: |
| 3214 | ospf_network_lsa_originate (data->oi); |
| 3215 | break; |
| 3216 | case LSA_ACTION_FLOOD_AREA: |
| 3217 | ospf_flood_through_area (data->area, NULL, data->lsa); |
| 3218 | break; |
| 3219 | case LSA_ACTION_FLOOD_AS: |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 3220 | ospf_flood_through_as (ospf, NULL, data->lsa); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 3221 | break; |
| 3222 | case LSA_ACTION_FLUSH_AREA: |
| 3223 | ospf_lsa_flush_area (data->lsa, data->area); |
| 3224 | break; |
| 3225 | case LSA_ACTION_FLUSH_AS: |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 3226 | ospf_lsa_flush_as (ospf, data->lsa); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 3227 | break; |
| 3228 | } |
| 3229 | |
| 3230 | ospf_lsa_unlock (data->lsa); |
| 3231 | XFREE (MTYPE_OSPF_MESSAGE, data); |
| 3232 | return 0; |
| 3233 | } |
| 3234 | |
| 3235 | void |
| 3236 | ospf_schedule_lsa_flood_area (struct ospf_area *area, struct ospf_lsa *lsa) |
| 3237 | { |
| 3238 | struct lsa_action *data; |
| 3239 | |
| 3240 | data = XMALLOC (MTYPE_OSPF_MESSAGE, sizeof (struct lsa_action)); |
| 3241 | memset (data, 0, sizeof (struct lsa_action)); |
| 3242 | |
| 3243 | data->action = LSA_ACTION_FLOOD_AREA; |
| 3244 | data->area = area; |
| 3245 | data->lsa = ospf_lsa_lock (lsa); |
| 3246 | |
| 3247 | thread_add_event (master, ospf_lsa_action, data, 0); |
| 3248 | } |
| 3249 | |
| 3250 | void |
| 3251 | ospf_schedule_lsa_flush_area (struct ospf_area *area, struct ospf_lsa *lsa) |
| 3252 | { |
| 3253 | struct lsa_action *data; |
| 3254 | |
| 3255 | data = XMALLOC (MTYPE_OSPF_MESSAGE, sizeof (struct lsa_action)); |
| 3256 | memset (data, 0, sizeof (struct lsa_action)); |
| 3257 | |
| 3258 | data->action = LSA_ACTION_FLUSH_AREA; |
| 3259 | data->area = area; |
| 3260 | data->lsa = ospf_lsa_lock (lsa); |
| 3261 | |
| 3262 | thread_add_event (master, ospf_lsa_action, data, 0); |
| 3263 | } |
| 3264 | |
| 3265 | |
| 3266 | /* LSA Refreshment functions. */ |
| 3267 | void |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 3268 | ospf_lsa_refresh (struct ospf *ospf, struct ospf_lsa *lsa) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 3269 | { |
| 3270 | struct external_info *ei; |
| 3271 | assert (CHECK_FLAG (lsa->flags, OSPF_LSA_SELF)); |
| 3272 | |
| 3273 | switch (lsa->data->type) |
| 3274 | { |
| 3275 | /* Router and Network LSAs are processed differently. */ |
| 3276 | case OSPF_ROUTER_LSA: |
| 3277 | case OSPF_NETWORK_LSA: |
| 3278 | break; |
| 3279 | case OSPF_SUMMARY_LSA: |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 3280 | ospf_summary_lsa_refresh (ospf, lsa); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 3281 | break; |
| 3282 | case OSPF_ASBR_SUMMARY_LSA: |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 3283 | ospf_summary_asbr_lsa_refresh (ospf, lsa); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 3284 | break; |
| 3285 | case OSPF_AS_EXTERNAL_LSA: |
| 3286 | ei = ospf_external_info_check (lsa); |
| 3287 | if (ei) |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 3288 | ospf_external_lsa_refresh (ospf, lsa, ei, LSA_REFRESH_FORCE); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 3289 | else |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 3290 | ospf_lsa_flush_as (ospf, lsa); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 3291 | break; |
| 3292 | #ifdef HAVE_OPAQUE_LSA |
| 3293 | case OSPF_OPAQUE_LINK_LSA: |
| 3294 | case OSPF_OPAQUE_AREA_LSA: |
| 3295 | case OSPF_OPAQUE_AS_LSA: |
| 3296 | ospf_opaque_lsa_refresh (lsa); |
| 3297 | break; |
paul | d748032 | 2003-05-16 17:31:51 +0000 | [diff] [blame] | 3298 | #endif /* HAVE_OPAQUE_LSA */ |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 3299 | default: |
| 3300 | break; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 3301 | } |
| 3302 | } |
| 3303 | |
| 3304 | void |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 3305 | ospf_refresher_register_lsa (struct ospf *ospf, struct ospf_lsa *lsa) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 3306 | { |
| 3307 | u_int16_t index, current_index; |
| 3308 | |
| 3309 | assert (CHECK_FLAG (lsa->flags, OSPF_LSA_SELF)); |
| 3310 | |
| 3311 | if (lsa->refresh_list < 0) |
| 3312 | { |
| 3313 | int delay; |
| 3314 | |
| 3315 | if (LS_AGE (lsa) == 0 && |
| 3316 | ntohl (lsa->data->ls_seqnum) == OSPF_INITIAL_SEQUENCE_NUMBER) |
| 3317 | /* Randomize first update by OSPF_LS_REFRESH_SHIFT factor */ |
| 3318 | delay = OSPF_LS_REFRESH_SHIFT + (random () % OSPF_LS_REFRESH_TIME); |
| 3319 | else |
| 3320 | /* Randomize another updates by +-OSPF_LS_REFRESH_JITTER factor */ |
| 3321 | delay = OSPF_LS_REFRESH_TIME - LS_AGE (lsa) - OSPF_LS_REFRESH_JITTER |
| 3322 | + (random () % (2*OSPF_LS_REFRESH_JITTER)); |
| 3323 | |
| 3324 | if (delay < 0) |
| 3325 | delay = 0; |
| 3326 | |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 3327 | current_index = ospf->lsa_refresh_queue.index + |
| 3328 | (time (NULL) - ospf->lsa_refresher_started)/OSPF_LSA_REFRESHER_GRANULARITY; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 3329 | |
| 3330 | index = (current_index + delay/OSPF_LSA_REFRESHER_GRANULARITY) |
| 3331 | % (OSPF_LSA_REFRESHER_SLOTS); |
| 3332 | |
| 3333 | if (IS_DEBUG_OSPF (lsa, LSA_REFRESH)) |
| 3334 | zlog_info ("LSA[Refresh]: lsa with age %d added to index %d", |
| 3335 | LS_AGE (lsa), index); |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 3336 | if (!ospf->lsa_refresh_queue.qs[index]) |
| 3337 | ospf->lsa_refresh_queue.qs[index] = list_new (); |
| 3338 | listnode_add (ospf->lsa_refresh_queue.qs[index], ospf_lsa_lock (lsa)); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 3339 | lsa->refresh_list = index; |
paul | f2c8065 | 2002-12-13 21:44:27 +0000 | [diff] [blame] | 3340 | if (IS_DEBUG_OSPF (lsa, LSA_REFRESH)) |
| 3341 | zlog_info ("LSA[Refresh]: ospf_refresher_register_lsa(): setting refresh_list on lsa %p (slod %d)", lsa, index); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 3342 | } |
| 3343 | } |
| 3344 | |
| 3345 | void |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 3346 | ospf_refresher_unregister_lsa (struct ospf *ospf, struct ospf_lsa *lsa) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 3347 | { |
| 3348 | assert (CHECK_FLAG (lsa->flags, OSPF_LSA_SELF)); |
| 3349 | if (lsa->refresh_list >= 0) |
| 3350 | { |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 3351 | list refresh_list = ospf->lsa_refresh_queue.qs[lsa->refresh_list]; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 3352 | listnode_delete (refresh_list, lsa); |
| 3353 | if (!listcount (refresh_list)) |
| 3354 | { |
| 3355 | list_free (refresh_list); |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 3356 | ospf->lsa_refresh_queue.qs[lsa->refresh_list] = NULL; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 3357 | } |
| 3358 | ospf_lsa_unlock (lsa); |
| 3359 | lsa->refresh_list = -1; |
| 3360 | } |
| 3361 | } |
| 3362 | |
| 3363 | int |
| 3364 | ospf_lsa_refresh_walker (struct thread *t) |
| 3365 | { |
| 3366 | list refresh_list; |
| 3367 | listnode node; |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 3368 | struct ospf *ospf = THREAD_ARG (t); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 3369 | int i; |
| 3370 | list lsa_to_refresh = list_new (); |
| 3371 | |
| 3372 | if (IS_DEBUG_OSPF (lsa, LSA_REFRESH)) |
| 3373 | zlog_info ("LSA[Refresh]:ospf_lsa_refresh_walker(): start"); |
| 3374 | |
| 3375 | |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 3376 | i = ospf->lsa_refresh_queue.index; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 3377 | |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 3378 | ospf->lsa_refresh_queue.index = |
| 3379 | (ospf->lsa_refresh_queue.index + |
| 3380 | (time (NULL) - ospf->lsa_refresher_started) / OSPF_LSA_REFRESHER_GRANULARITY) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 3381 | % OSPF_LSA_REFRESHER_SLOTS; |
| 3382 | |
| 3383 | if (IS_DEBUG_OSPF (lsa, LSA_REFRESH)) |
| 3384 | zlog_info ("LSA[Refresh]: ospf_lsa_refresh_walker(): next index %d", |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 3385 | ospf->lsa_refresh_queue.index); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 3386 | |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 3387 | for (;i != ospf->lsa_refresh_queue.index; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 3388 | i = (i + 1) % OSPF_LSA_REFRESHER_SLOTS) |
| 3389 | { |
| 3390 | if (IS_DEBUG_OSPF (lsa, LSA_REFRESH)) |
| 3391 | zlog_info ("LSA[Refresh]: ospf_lsa_refresh_walker(): refresh index %d", i); |
| 3392 | |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 3393 | refresh_list = ospf->lsa_refresh_queue.qs [i]; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 3394 | |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 3395 | ospf->lsa_refresh_queue.qs [i] = NULL; |
| 3396 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 3397 | if (refresh_list) |
| 3398 | { |
| 3399 | for (node = listhead (refresh_list); node;) |
| 3400 | { |
| 3401 | listnode next; |
| 3402 | struct ospf_lsa *lsa = getdata (node); |
| 3403 | next = node->next; |
| 3404 | |
| 3405 | if (IS_DEBUG_OSPF (lsa, LSA_REFRESH)) |
paul | f2c8065 | 2002-12-13 21:44:27 +0000 | [diff] [blame] | 3406 | zlog_info ("LSA[Refresh]: ospf_lsa_refresh_walker(): refresh lsa %p (slot %d)", lsa, i); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 3407 | |
| 3408 | list_delete_node (refresh_list, node); |
| 3409 | ospf_lsa_unlock (lsa); |
| 3410 | lsa->refresh_list = -1; |
| 3411 | listnode_add (lsa_to_refresh, lsa); |
| 3412 | node = next; |
| 3413 | } |
| 3414 | list_free (refresh_list); |
| 3415 | } |
| 3416 | } |
| 3417 | |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 3418 | ospf->t_lsa_refresher = thread_add_timer (master, ospf_lsa_refresh_walker, |
| 3419 | ospf, ospf->lsa_refresh_interval); |
| 3420 | ospf->lsa_refresher_started = time (NULL); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 3421 | |
| 3422 | for (node = listhead (lsa_to_refresh); node; nextnode (node)) |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 3423 | ospf_lsa_refresh (ospf, getdata (node)); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 3424 | |
| 3425 | list_delete (lsa_to_refresh); |
| 3426 | |
| 3427 | if (IS_DEBUG_OSPF (lsa, LSA_REFRESH)) |
| 3428 | zlog_info ("LSA[Refresh]: ospf_lsa_refresh_walker(): end"); |
| 3429 | |
| 3430 | return 0; |
| 3431 | } |
| 3432 | |