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