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