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