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