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