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