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