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