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