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