paul | 2d59836 | 2003-01-17 23:48:42 +0000 | [diff] [blame] | 1 | /* |
| 2 | * OSPF version 2 Neighbor State Machine |
| 3 | * From RFC2328 [OSPF Version 2] |
| 4 | * Copyright (C) 1999, 2000 Toshiaki Takada |
| 5 | * |
| 6 | * This file is part of GNU Zebra. |
| 7 | * |
| 8 | * GNU Zebra is free software; you can redistribute it and/or modify it |
| 9 | * under the terms of the GNU General Public License as published by the |
| 10 | * Free Software Foundation; either version 2, or (at your option) any |
| 11 | * later version. |
| 12 | * |
| 13 | * GNU Zebra is distributed in the hope that it will be useful, but |
| 14 | * WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 16 | * General Public License for more details. |
| 17 | * |
| 18 | * You should have received a copy of the GNU General Public License |
| 19 | * along with GNU Zebra; see the file COPYING. If not, write to the Free |
| 20 | * Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA |
| 21 | * 02111-1307, USA. |
| 22 | */ |
| 23 | |
| 24 | #include <zebra.h> |
| 25 | |
| 26 | #include "thread.h" |
| 27 | #include "memory.h" |
| 28 | #include "hash.h" |
| 29 | #include "linklist.h" |
| 30 | #include "prefix.h" |
| 31 | #include "if.h" |
| 32 | #include "table.h" |
| 33 | #include "stream.h" |
| 34 | #include "table.h" |
| 35 | #include "log.h" |
| 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_network.h" |
| 46 | #include "ospfd/ospf_packet.h" |
| 47 | #include "ospfd/ospf_dump.h" |
| 48 | #include "ospfd/ospf_flood.h" |
| 49 | #include "ospfd/ospf_abr.h" |
vincent | 5e4914c | 2005-09-29 16:34:30 +0000 | [diff] [blame] | 50 | #include "ospfd/ospf_snmp.h" |
paul | 2d59836 | 2003-01-17 23:48:42 +0000 | [diff] [blame] | 51 | |
| 52 | void nsm_reset_nbr (struct ospf_neighbor *); |
| 53 | |
| 54 | |
| 55 | /* OSPF NSM Timer functions. */ |
paul | 4dadc29 | 2005-05-06 21:37:42 +0000 | [diff] [blame] | 56 | static int |
paul | 2d59836 | 2003-01-17 23:48:42 +0000 | [diff] [blame] | 57 | ospf_inactivity_timer (struct thread *thread) |
| 58 | { |
| 59 | struct ospf_neighbor *nbr; |
| 60 | |
| 61 | nbr = THREAD_ARG (thread); |
| 62 | nbr->t_inactivity = NULL; |
| 63 | |
| 64 | if (IS_DEBUG_OSPF (nsm, NSM_TIMERS)) |
| 65 | zlog (NULL, LOG_DEBUG, "NSM[%s:%s]: Timer (Inactivity timer expire)", |
| 66 | IF_NAME (nbr->oi), inet_ntoa (nbr->router_id)); |
| 67 | |
| 68 | OSPF_NSM_EVENT_SCHEDULE (nbr, NSM_InactivityTimer); |
| 69 | |
| 70 | return 0; |
| 71 | } |
| 72 | |
paul | 4dadc29 | 2005-05-06 21:37:42 +0000 | [diff] [blame] | 73 | static int |
paul | 2d59836 | 2003-01-17 23:48:42 +0000 | [diff] [blame] | 74 | ospf_db_desc_timer (struct thread *thread) |
| 75 | { |
| 76 | struct ospf_interface *oi; |
| 77 | struct ospf_neighbor *nbr; |
| 78 | |
| 79 | nbr = THREAD_ARG (thread); |
| 80 | nbr->t_db_desc = NULL; |
| 81 | |
| 82 | oi = nbr->oi; |
| 83 | |
| 84 | if (IS_DEBUG_OSPF (nsm, NSM_TIMERS)) |
ajs | 2a42e28 | 2004-12-08 18:43:03 +0000 | [diff] [blame] | 85 | zlog (NULL, LOG_DEBUG, "NSM[%s:%s]: Timer (DD Retransmit timer expire)", |
paul | 2d59836 | 2003-01-17 23:48:42 +0000 | [diff] [blame] | 86 | IF_NAME (nbr->oi), inet_ntoa (nbr->src)); |
| 87 | |
| 88 | /* resent last send DD packet. */ |
| 89 | assert (nbr->last_send); |
| 90 | ospf_db_desc_resend (nbr); |
| 91 | |
| 92 | /* DD Retransmit timer set. */ |
| 93 | OSPF_NSM_TIMER_ON (nbr->t_db_desc, ospf_db_desc_timer, nbr->v_db_desc); |
| 94 | |
| 95 | return 0; |
| 96 | } |
| 97 | |
| 98 | /* Hook function called after ospf NSM event is occured. */ |
| 99 | |
paul | 4dadc29 | 2005-05-06 21:37:42 +0000 | [diff] [blame] | 100 | static void |
paul | 2d59836 | 2003-01-17 23:48:42 +0000 | [diff] [blame] | 101 | nsm_timer_set (struct ospf_neighbor *nbr) |
| 102 | { |
| 103 | switch (nbr->state) |
| 104 | { |
| 105 | case NSM_Down: |
| 106 | OSPF_NSM_TIMER_OFF (nbr->t_db_desc); |
| 107 | OSPF_NSM_TIMER_OFF (nbr->t_ls_upd); |
| 108 | break; |
| 109 | case NSM_Attempt: |
| 110 | OSPF_NSM_TIMER_OFF (nbr->t_db_desc); |
| 111 | OSPF_NSM_TIMER_OFF (nbr->t_ls_upd); |
| 112 | break; |
| 113 | case NSM_Init: |
| 114 | OSPF_NSM_TIMER_OFF (nbr->t_db_desc); |
| 115 | OSPF_NSM_TIMER_OFF (nbr->t_ls_upd); |
| 116 | break; |
| 117 | case NSM_TwoWay: |
| 118 | OSPF_NSM_TIMER_OFF (nbr->t_db_desc); |
| 119 | OSPF_NSM_TIMER_OFF (nbr->t_ls_upd); |
| 120 | break; |
| 121 | case NSM_ExStart: |
| 122 | OSPF_NSM_TIMER_ON (nbr->t_db_desc, ospf_db_desc_timer, nbr->v_db_desc); |
| 123 | OSPF_NSM_TIMER_OFF (nbr->t_ls_upd); |
| 124 | break; |
| 125 | case NSM_Exchange: |
| 126 | OSPF_NSM_TIMER_ON (nbr->t_ls_upd, ospf_ls_upd_timer, nbr->v_ls_upd); |
| 127 | if (!IS_SET_DD_MS (nbr->dd_flags)) |
| 128 | OSPF_NSM_TIMER_OFF (nbr->t_db_desc); |
| 129 | break; |
| 130 | case NSM_Loading: |
| 131 | OSPF_NSM_TIMER_OFF (nbr->t_db_desc); |
| 132 | break; |
| 133 | case NSM_Full: |
| 134 | OSPF_NSM_TIMER_OFF (nbr->t_db_desc); |
| 135 | break; |
| 136 | default: |
| 137 | OSPF_NSM_TIMER_OFF (nbr->t_db_desc); |
| 138 | break; |
| 139 | } |
| 140 | } |
| 141 | |
| 142 | |
| 143 | /* OSPF NSM functions. */ |
paul | 4dadc29 | 2005-05-06 21:37:42 +0000 | [diff] [blame] | 144 | static int |
paul | 2d59836 | 2003-01-17 23:48:42 +0000 | [diff] [blame] | 145 | nsm_ignore (struct ospf_neighbor *nbr) |
| 146 | { |
| 147 | if (IS_DEBUG_OSPF (nsm, NSM_EVENTS)) |
ajs | 2a42e28 | 2004-12-08 18:43:03 +0000 | [diff] [blame] | 148 | zlog (NULL, LOG_DEBUG, "NSM[%s:%s]: nsm_ignore called", |
paul | 2d59836 | 2003-01-17 23:48:42 +0000 | [diff] [blame] | 149 | IF_NAME (nbr->oi), inet_ntoa (nbr->router_id)); |
| 150 | |
| 151 | return 0; |
| 152 | } |
| 153 | |
paul | 4dadc29 | 2005-05-06 21:37:42 +0000 | [diff] [blame] | 154 | static int |
paul | 2d59836 | 2003-01-17 23:48:42 +0000 | [diff] [blame] | 155 | nsm_hello_received (struct ospf_neighbor *nbr) |
| 156 | { |
| 157 | /* Start or Restart Inactivity Timer. */ |
| 158 | OSPF_NSM_TIMER_OFF (nbr->t_inactivity); |
| 159 | |
| 160 | OSPF_NSM_TIMER_ON (nbr->t_inactivity, ospf_inactivity_timer, |
| 161 | nbr->v_inactivity); |
| 162 | |
| 163 | if (nbr->oi->type == OSPF_IFTYPE_NBMA && nbr->nbr_nbma) |
| 164 | OSPF_POLL_TIMER_OFF (nbr->nbr_nbma->t_poll); |
| 165 | |
| 166 | return 0; |
| 167 | } |
| 168 | |
paul | 4dadc29 | 2005-05-06 21:37:42 +0000 | [diff] [blame] | 169 | static int |
paul | 2d59836 | 2003-01-17 23:48:42 +0000 | [diff] [blame] | 170 | nsm_start (struct ospf_neighbor *nbr) |
| 171 | { |
| 172 | |
| 173 | nsm_reset_nbr (nbr); |
| 174 | |
| 175 | if (nbr->nbr_nbma) |
| 176 | OSPF_POLL_TIMER_OFF (nbr->nbr_nbma->t_poll); |
| 177 | |
| 178 | OSPF_NSM_TIMER_OFF (nbr->t_inactivity); |
| 179 | |
| 180 | OSPF_NSM_TIMER_ON (nbr->t_inactivity, ospf_inactivity_timer, |
| 181 | nbr->v_inactivity); |
| 182 | |
| 183 | return 0; |
| 184 | } |
| 185 | |
paul | 4dadc29 | 2005-05-06 21:37:42 +0000 | [diff] [blame] | 186 | static int |
paul | 2d59836 | 2003-01-17 23:48:42 +0000 | [diff] [blame] | 187 | nsm_twoway_received (struct ospf_neighbor *nbr) |
| 188 | { |
| 189 | struct ospf_interface *oi; |
| 190 | int next_state = NSM_TwoWay; |
| 191 | |
| 192 | oi = nbr->oi; |
| 193 | |
| 194 | /* These netowork types must be adjacency. */ |
| 195 | if (oi->type == OSPF_IFTYPE_POINTOPOINT || |
| 196 | oi->type == OSPF_IFTYPE_POINTOMULTIPOINT || |
| 197 | oi->type == OSPF_IFTYPE_VIRTUALLINK) |
| 198 | next_state = NSM_ExStart; |
| 199 | |
| 200 | /* Router itself is the DRouter or the BDRouter. */ |
| 201 | if (IPV4_ADDR_SAME (&oi->address->u.prefix4, &DR (oi)) || |
| 202 | IPV4_ADDR_SAME (&oi->address->u.prefix4, &BDR (oi))) |
| 203 | next_state = NSM_ExStart; |
| 204 | |
| 205 | /* Neighboring Router is the DRouter or the BDRouter. */ |
| 206 | if (IPV4_ADDR_SAME (&nbr->address.u.prefix4, &nbr->d_router) || |
| 207 | IPV4_ADDR_SAME (&nbr->address.u.prefix4, &nbr->bd_router)) |
| 208 | next_state = NSM_ExStart; |
| 209 | |
| 210 | return next_state; |
| 211 | } |
| 212 | |
| 213 | int |
| 214 | ospf_db_summary_count (struct ospf_neighbor *nbr) |
| 215 | { |
| 216 | return ospf_lsdb_count_all (&nbr->db_sum); |
| 217 | } |
| 218 | |
| 219 | int |
| 220 | ospf_db_summary_isempty (struct ospf_neighbor *nbr) |
| 221 | { |
| 222 | return ospf_lsdb_isempty (&nbr->db_sum); |
| 223 | } |
| 224 | |
paul | 4dadc29 | 2005-05-06 21:37:42 +0000 | [diff] [blame] | 225 | static int |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 226 | ospf_db_summary_add (struct ospf_neighbor *nbr, struct ospf_lsa *lsa) |
paul | 2d59836 | 2003-01-17 23:48:42 +0000 | [diff] [blame] | 227 | { |
paul | 09e4efd | 2003-01-18 00:12:02 +0000 | [diff] [blame] | 228 | #ifdef HAVE_OPAQUE_LSA |
| 229 | switch (lsa->data->type) |
| 230 | { |
| 231 | case OSPF_OPAQUE_LINK_LSA: |
| 232 | /* Exclude type-9 LSAs that does not have the same "oi" with "nbr". */ |
| 233 | if (lsa->oi != nbr->oi) |
| 234 | return 0; |
| 235 | break; |
| 236 | case OSPF_OPAQUE_AREA_LSA: |
| 237 | /* |
| 238 | * It is assured by the caller function "nsm_negotiation_done()" |
| 239 | * that every given LSA belongs to the same area with "nbr". |
| 240 | */ |
| 241 | break; |
| 242 | case OSPF_OPAQUE_AS_LSA: |
| 243 | default: |
| 244 | break; |
| 245 | } |
| 246 | #endif /* HAVE_OPAQUE_LSA */ |
| 247 | |
paul | 2d59836 | 2003-01-17 23:48:42 +0000 | [diff] [blame] | 248 | /* Stay away from any Local Translated Type-7 LSAs */ |
| 249 | if (CHECK_FLAG (lsa->flags, OSPF_LSA_LOCAL_XLT)) |
| 250 | return 0; |
paul | 2d59836 | 2003-01-17 23:48:42 +0000 | [diff] [blame] | 251 | |
| 252 | if (IS_LSA_MAXAGE (lsa)) |
| 253 | ospf_ls_retransmit_add (nbr, lsa); |
| 254 | else |
| 255 | ospf_lsdb_add (&nbr->db_sum, lsa); |
| 256 | |
| 257 | return 0; |
| 258 | } |
| 259 | |
| 260 | void |
| 261 | ospf_db_summary_clear (struct ospf_neighbor *nbr) |
| 262 | { |
| 263 | struct ospf_lsdb *lsdb; |
| 264 | int i; |
| 265 | |
| 266 | lsdb = &nbr->db_sum; |
| 267 | for (i = OSPF_MIN_LSA; i < OSPF_MAX_LSA; i++) |
| 268 | { |
| 269 | struct route_table *table = lsdb->type[i].db; |
| 270 | struct route_node *rn; |
| 271 | |
| 272 | for (rn = route_top (table); rn; rn = route_next (rn)) |
| 273 | if (rn->info) |
| 274 | ospf_lsdb_delete (&nbr->db_sum, rn->info); |
| 275 | } |
| 276 | } |
| 277 | |
| 278 | |
| 279 | |
paul | 2d59836 | 2003-01-17 23:48:42 +0000 | [diff] [blame] | 280 | /* The area link state database consists of the router-LSAs, |
| 281 | network-LSAs and summary-LSAs contained in the area structure, |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 282 | along with the AS-external-LSAs contained in the global structure. |
| 283 | AS-external-LSAs are omitted from a virtual neighbor's Database |
paul | 2d59836 | 2003-01-17 23:48:42 +0000 | [diff] [blame] | 284 | summary list. AS-external-LSAs are omitted from the Database |
| 285 | summary list if the area has been configured as a stub. */ |
paul | 4dadc29 | 2005-05-06 21:37:42 +0000 | [diff] [blame] | 286 | static int |
paul | 2d59836 | 2003-01-17 23:48:42 +0000 | [diff] [blame] | 287 | nsm_negotiation_done (struct ospf_neighbor *nbr) |
| 288 | { |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 289 | struct ospf_area *area = nbr->oi->area; |
| 290 | struct ospf_lsa *lsa; |
| 291 | struct route_node *rn; |
paul | 2d59836 | 2003-01-17 23:48:42 +0000 | [diff] [blame] | 292 | |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 293 | LSDB_LOOP (ROUTER_LSDB (area), rn, lsa) |
| 294 | ospf_db_summary_add (nbr, lsa); |
| 295 | LSDB_LOOP (NETWORK_LSDB (area), rn, lsa) |
| 296 | ospf_db_summary_add (nbr, lsa); |
| 297 | LSDB_LOOP (SUMMARY_LSDB (area), rn, lsa) |
| 298 | ospf_db_summary_add (nbr, lsa); |
| 299 | LSDB_LOOP (ASBR_SUMMARY_LSDB (area), rn, lsa) |
| 300 | ospf_db_summary_add (nbr, lsa); |
paul | 2d59836 | 2003-01-17 23:48:42 +0000 | [diff] [blame] | 301 | |
paul | 2d59836 | 2003-01-17 23:48:42 +0000 | [diff] [blame] | 302 | #ifdef HAVE_OPAQUE_LSA |
| 303 | /* Process only if the neighbor is opaque capable. */ |
| 304 | if (CHECK_FLAG (nbr->options, OSPF_OPTION_O)) |
| 305 | { |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 306 | LSDB_LOOP (OPAQUE_LINK_LSDB (area), rn, lsa) |
| 307 | ospf_db_summary_add (nbr, lsa); |
| 308 | LSDB_LOOP (OPAQUE_AREA_LSDB (area), rn, lsa) |
| 309 | ospf_db_summary_add (nbr, lsa); |
paul | 2d59836 | 2003-01-17 23:48:42 +0000 | [diff] [blame] | 310 | } |
| 311 | #endif /* HAVE_OPAQUE_LSA */ |
| 312 | |
hasso | f4833e9 | 2005-06-20 20:42:26 +0000 | [diff] [blame] | 313 | if (CHECK_FLAG (nbr->options, OSPF_OPTION_NP)) |
| 314 | { |
| 315 | LSDB_LOOP (NSSA_LSDB (area), rn, lsa) |
| 316 | ospf_db_summary_add (nbr, lsa); |
| 317 | } |
| 318 | |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 319 | if (nbr->oi->type != OSPF_IFTYPE_VIRTUALLINK |
| 320 | && area->external_routing == OSPF_AREA_DEFAULT) |
| 321 | LSDB_LOOP (EXTERNAL_LSDB (nbr->oi->ospf), rn, lsa) |
| 322 | ospf_db_summary_add (nbr, lsa); |
paul | 2d59836 | 2003-01-17 23:48:42 +0000 | [diff] [blame] | 323 | |
| 324 | #ifdef HAVE_OPAQUE_LSA |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 325 | if (CHECK_FLAG (nbr->options, OSPF_OPTION_O) |
| 326 | && (nbr->oi->type != OSPF_IFTYPE_VIRTUALLINK |
| 327 | && area->external_routing == OSPF_AREA_DEFAULT)) |
| 328 | LSDB_LOOP (OPAQUE_AS_LSDB (nbr->oi->ospf), rn, lsa) |
| 329 | ospf_db_summary_add (nbr, lsa); |
paul | 2d59836 | 2003-01-17 23:48:42 +0000 | [diff] [blame] | 330 | #endif /* HAVE_OPAQUE_LSA */ |
| 331 | |
paul | 2d59836 | 2003-01-17 23:48:42 +0000 | [diff] [blame] | 332 | return 0; |
| 333 | } |
| 334 | |
paul | 4dadc29 | 2005-05-06 21:37:42 +0000 | [diff] [blame] | 335 | static int |
paul | 2d59836 | 2003-01-17 23:48:42 +0000 | [diff] [blame] | 336 | nsm_exchange_done (struct ospf_neighbor *nbr) |
| 337 | { |
paul | 2d59836 | 2003-01-17 23:48:42 +0000 | [diff] [blame] | 338 | if (ospf_ls_request_isempty (nbr)) |
| 339 | return NSM_Full; |
| 340 | |
| 341 | /* Cancel dd retransmit timer. */ |
| 342 | /* OSPF_NSM_TIMER_OFF (nbr->t_db_desc); */ |
| 343 | |
| 344 | /* Send Link State Request. */ |
| 345 | ospf_ls_req_send (nbr); |
| 346 | |
| 347 | return NSM_Loading; |
| 348 | } |
| 349 | |
paul | 4dadc29 | 2005-05-06 21:37:42 +0000 | [diff] [blame] | 350 | static int |
paul | 2d59836 | 2003-01-17 23:48:42 +0000 | [diff] [blame] | 351 | nsm_bad_ls_req (struct ospf_neighbor *nbr) |
| 352 | { |
| 353 | /* Clear neighbor. */ |
| 354 | nsm_reset_nbr (nbr); |
| 355 | |
| 356 | return 0; |
| 357 | } |
| 358 | |
paul | 4dadc29 | 2005-05-06 21:37:42 +0000 | [diff] [blame] | 359 | static int |
paul | 2d59836 | 2003-01-17 23:48:42 +0000 | [diff] [blame] | 360 | nsm_adj_ok (struct ospf_neighbor *nbr) |
| 361 | { |
| 362 | struct ospf_interface *oi; |
| 363 | int next_state; |
| 364 | int flag = 0; |
| 365 | |
| 366 | oi = nbr->oi; |
| 367 | next_state = nbr->state; |
| 368 | |
| 369 | /* These netowork types must be adjacency. */ |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 370 | if (oi->type == OSPF_IFTYPE_POINTOPOINT |
| 371 | || oi->type == OSPF_IFTYPE_POINTOMULTIPOINT |
| 372 | || oi->type == OSPF_IFTYPE_VIRTUALLINK) |
paul | 2d59836 | 2003-01-17 23:48:42 +0000 | [diff] [blame] | 373 | flag = 1; |
| 374 | |
| 375 | /* Router itself is the DRouter or the BDRouter. */ |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 376 | if (IPV4_ADDR_SAME (&oi->address->u.prefix4, &DR (oi)) |
| 377 | || IPV4_ADDR_SAME (&oi->address->u.prefix4, &BDR (oi))) |
paul | 2d59836 | 2003-01-17 23:48:42 +0000 | [diff] [blame] | 378 | flag = 1; |
| 379 | |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 380 | if (IPV4_ADDR_SAME (&nbr->address.u.prefix4, &DR (oi)) |
| 381 | || IPV4_ADDR_SAME (&nbr->address.u.prefix4, &BDR (oi))) |
paul | 2d59836 | 2003-01-17 23:48:42 +0000 | [diff] [blame] | 382 | flag = 1; |
| 383 | |
| 384 | if (nbr->state == NSM_TwoWay && flag == 1) |
| 385 | next_state = NSM_ExStart; |
| 386 | else if (nbr->state >= NSM_ExStart && flag == 0) |
| 387 | next_state = NSM_TwoWay; |
| 388 | |
| 389 | return next_state; |
| 390 | } |
| 391 | |
paul | 4dadc29 | 2005-05-06 21:37:42 +0000 | [diff] [blame] | 392 | static int |
paul | 2d59836 | 2003-01-17 23:48:42 +0000 | [diff] [blame] | 393 | nsm_seq_number_mismatch (struct ospf_neighbor *nbr) |
| 394 | { |
| 395 | /* Clear neighbor. */ |
| 396 | nsm_reset_nbr (nbr); |
| 397 | |
| 398 | return 0; |
| 399 | } |
| 400 | |
paul | 4dadc29 | 2005-05-06 21:37:42 +0000 | [diff] [blame] | 401 | static int |
paul | 2d59836 | 2003-01-17 23:48:42 +0000 | [diff] [blame] | 402 | nsm_oneway_received (struct ospf_neighbor *nbr) |
| 403 | { |
| 404 | /* Clear neighbor. */ |
| 405 | nsm_reset_nbr (nbr); |
| 406 | |
| 407 | return 0; |
| 408 | } |
| 409 | |
| 410 | void |
| 411 | nsm_reset_nbr (struct ospf_neighbor *nbr) |
| 412 | { |
| 413 | /* Clear Database Summary list. */ |
| 414 | if (!ospf_db_summary_isempty (nbr)) |
| 415 | ospf_db_summary_clear (nbr); |
| 416 | |
| 417 | /* Clear Link State Request list. */ |
| 418 | if (!ospf_ls_request_isempty (nbr)) |
| 419 | ospf_ls_request_delete_all (nbr); |
| 420 | |
| 421 | /* Clear Link State Retransmission list. */ |
| 422 | if (!ospf_ls_retransmit_isempty (nbr)) |
| 423 | ospf_ls_retransmit_clear (nbr); |
| 424 | |
| 425 | /* Cancel thread. */ |
| 426 | OSPF_NSM_TIMER_OFF (nbr->t_db_desc); |
| 427 | OSPF_NSM_TIMER_OFF (nbr->t_ls_req); |
| 428 | OSPF_NSM_TIMER_OFF (nbr->t_ls_upd); |
| 429 | OSPF_NSM_TIMER_OFF (nbr->t_hello_reply); |
| 430 | |
| 431 | #ifdef HAVE_OPAQUE_LSA |
| 432 | if (CHECK_FLAG (nbr->options, OSPF_OPTION_O)) |
| 433 | UNSET_FLAG (nbr->options, OSPF_OPTION_O); |
| 434 | #endif /* HAVE_OPAQUE_LSA */ |
| 435 | } |
| 436 | |
paul | 4dadc29 | 2005-05-06 21:37:42 +0000 | [diff] [blame] | 437 | static int |
paul | 2d59836 | 2003-01-17 23:48:42 +0000 | [diff] [blame] | 438 | nsm_kill_nbr (struct ospf_neighbor *nbr) |
| 439 | { |
| 440 | /* call it here because we cannot call it from ospf_nsm_event */ |
| 441 | nsm_change_state (nbr, NSM_Down); |
| 442 | |
Paul Jakma | 478aab9 | 2006-04-03 21:25:32 +0000 | [diff] [blame^] | 443 | /* killing nbr_self is invalid */ |
| 444 | assert (nbr != nbr->oi->nbr_self); |
| 445 | if (nbr == nbr->oi->nbr_self) |
| 446 | return 1; |
| 447 | |
paul | 2d59836 | 2003-01-17 23:48:42 +0000 | [diff] [blame] | 448 | /* Reset neighbor. */ |
| 449 | nsm_reset_nbr (nbr); |
| 450 | |
| 451 | if (nbr->oi->type == OSPF_IFTYPE_NBMA && nbr->nbr_nbma != NULL) |
| 452 | { |
| 453 | struct ospf_nbr_nbma *nbr_nbma = nbr->nbr_nbma; |
| 454 | |
| 455 | nbr_nbma->nbr = NULL; |
| 456 | nbr_nbma->state_change = nbr->state_change; |
| 457 | |
| 458 | nbr->nbr_nbma = NULL; |
| 459 | |
| 460 | OSPF_POLL_TIMER_ON (nbr_nbma->t_poll, ospf_poll_timer, |
| 461 | nbr_nbma->v_poll); |
| 462 | |
| 463 | if (IS_DEBUG_OSPF (nsm, NSM_EVENTS)) |
ajs | 2a42e28 | 2004-12-08 18:43:03 +0000 | [diff] [blame] | 464 | zlog_debug ("NSM[%s:%s]: Down (PollIntervalTimer scheduled)", |
paul | 2d59836 | 2003-01-17 23:48:42 +0000 | [diff] [blame] | 465 | IF_NAME (nbr->oi), inet_ntoa (nbr->address.u.prefix4)); |
| 466 | } |
| 467 | |
| 468 | /* Delete neighbor from interface. */ |
| 469 | ospf_nbr_delete (nbr); |
| 470 | |
| 471 | return 0; |
| 472 | } |
| 473 | |
paul | 4dadc29 | 2005-05-06 21:37:42 +0000 | [diff] [blame] | 474 | static int |
paul | 2d59836 | 2003-01-17 23:48:42 +0000 | [diff] [blame] | 475 | nsm_inactivity_timer (struct ospf_neighbor *nbr) |
| 476 | { |
| 477 | /* Kill neighbor. */ |
| 478 | nsm_kill_nbr (nbr); |
| 479 | |
| 480 | return 0; |
| 481 | } |
| 482 | |
paul | 4dadc29 | 2005-05-06 21:37:42 +0000 | [diff] [blame] | 483 | static int |
paul | 2d59836 | 2003-01-17 23:48:42 +0000 | [diff] [blame] | 484 | nsm_ll_down (struct ospf_neighbor *nbr) |
| 485 | { |
| 486 | /* Reset neighbor. */ |
| 487 | /*nsm_reset_nbr (nbr);*/ |
| 488 | |
| 489 | /* Kill neighbor. */ |
| 490 | nsm_kill_nbr (nbr); |
| 491 | |
| 492 | return 0; |
| 493 | } |
| 494 | |
| 495 | /* Neighbor State Machine */ |
| 496 | struct { |
paul | 4dadc29 | 2005-05-06 21:37:42 +0000 | [diff] [blame] | 497 | int (*func) (struct ospf_neighbor *); |
paul | 2d59836 | 2003-01-17 23:48:42 +0000 | [diff] [blame] | 498 | int next_state; |
| 499 | } NSM [OSPF_NSM_STATE_MAX][OSPF_NSM_EVENT_MAX] = |
| 500 | { |
| 501 | { |
| 502 | /* DependUpon: dummy state. */ |
| 503 | { nsm_ignore, NSM_DependUpon }, /* NoEvent */ |
| 504 | { nsm_ignore, NSM_DependUpon }, /* HelloReceived */ |
| 505 | { nsm_ignore, NSM_DependUpon }, /* Start */ |
| 506 | { nsm_ignore, NSM_DependUpon }, /* 2-WayReceived */ |
| 507 | { nsm_ignore, NSM_DependUpon }, /* NegotiationDone */ |
| 508 | { nsm_ignore, NSM_DependUpon }, /* ExchangeDone */ |
| 509 | { nsm_ignore, NSM_DependUpon }, /* BadLSReq */ |
| 510 | { nsm_ignore, NSM_DependUpon }, /* LoadingDone */ |
| 511 | { nsm_ignore, NSM_DependUpon }, /* AdjOK? */ |
| 512 | { nsm_ignore, NSM_DependUpon }, /* SeqNumberMismatch */ |
| 513 | { nsm_ignore, NSM_DependUpon }, /* 1-WayReceived */ |
| 514 | { nsm_ignore, NSM_DependUpon }, /* KillNbr */ |
| 515 | { nsm_ignore, NSM_DependUpon }, /* InactivityTimer */ |
| 516 | { nsm_ignore, NSM_DependUpon }, /* LLDown */ |
| 517 | }, |
| 518 | { |
| 519 | /* Down: */ |
| 520 | { nsm_ignore, NSM_DependUpon }, /* NoEvent */ |
| 521 | { nsm_hello_received, NSM_Init }, /* HelloReceived */ |
| 522 | { nsm_start, NSM_Attempt }, /* Start */ |
| 523 | { nsm_ignore, NSM_Down }, /* 2-WayReceived */ |
| 524 | { nsm_ignore, NSM_Down }, /* NegotiationDone */ |
| 525 | { nsm_ignore, NSM_Down }, /* ExchangeDone */ |
| 526 | { nsm_ignore, NSM_Down }, /* BadLSReq */ |
| 527 | { nsm_ignore, NSM_Down }, /* LoadingDone */ |
| 528 | { nsm_ignore, NSM_Down }, /* AdjOK? */ |
| 529 | { nsm_ignore, NSM_Down }, /* SeqNumberMismatch */ |
| 530 | { nsm_ignore, NSM_Down }, /* 1-WayReceived */ |
| 531 | { nsm_kill_nbr, NSM_Down }, /* KillNbr */ |
| 532 | { nsm_inactivity_timer, NSM_Down }, /* InactivityTimer */ |
| 533 | { nsm_ll_down, NSM_Down }, /* LLDown */ |
| 534 | }, |
| 535 | { |
| 536 | /* Attempt: */ |
| 537 | { nsm_ignore, NSM_DependUpon }, /* NoEvent */ |
| 538 | { nsm_hello_received, NSM_Init }, /* HelloReceived */ |
| 539 | { nsm_ignore, NSM_Attempt }, /* Start */ |
| 540 | { nsm_ignore, NSM_Attempt }, /* 2-WayReceived */ |
| 541 | { nsm_ignore, NSM_Attempt }, /* NegotiationDone */ |
| 542 | { nsm_ignore, NSM_Attempt }, /* ExchangeDone */ |
| 543 | { nsm_ignore, NSM_Attempt }, /* BadLSReq */ |
| 544 | { nsm_ignore, NSM_Attempt }, /* LoadingDone */ |
| 545 | { nsm_ignore, NSM_Attempt }, /* AdjOK? */ |
| 546 | { nsm_ignore, NSM_Attempt }, /* SeqNumberMismatch */ |
| 547 | { nsm_ignore, NSM_Attempt }, /* 1-WayReceived */ |
| 548 | { nsm_kill_nbr, NSM_Down }, /* KillNbr */ |
| 549 | { nsm_inactivity_timer, NSM_Down }, /* InactivityTimer */ |
| 550 | { nsm_ll_down, NSM_Down }, /* LLDown */ |
| 551 | }, |
| 552 | { |
| 553 | /* Init: */ |
| 554 | { nsm_ignore, NSM_DependUpon }, /* NoEvent */ |
| 555 | { nsm_hello_received, NSM_Init }, /* HelloReceived */ |
| 556 | { nsm_ignore, NSM_Init }, /* Start */ |
| 557 | { nsm_twoway_received, NSM_DependUpon }, /* 2-WayReceived */ |
| 558 | { nsm_ignore, NSM_Init }, /* NegotiationDone */ |
| 559 | { nsm_ignore, NSM_Init }, /* ExchangeDone */ |
| 560 | { nsm_ignore, NSM_Init }, /* BadLSReq */ |
| 561 | { nsm_ignore, NSM_Init }, /* LoadingDone */ |
| 562 | { nsm_ignore, NSM_Init }, /* AdjOK? */ |
| 563 | { nsm_ignore, NSM_Init }, /* SeqNumberMismatch */ |
| 564 | { nsm_ignore, NSM_Init }, /* 1-WayReceived */ |
| 565 | { nsm_kill_nbr, NSM_Down }, /* KillNbr */ |
| 566 | { nsm_inactivity_timer, NSM_Down }, /* InactivityTimer */ |
| 567 | { nsm_ll_down, NSM_Down }, /* LLDown */ |
| 568 | }, |
| 569 | { |
| 570 | /* 2-Way: */ |
| 571 | { nsm_ignore, NSM_DependUpon }, /* NoEvent */ |
| 572 | { nsm_hello_received, NSM_TwoWay }, /* HelloReceived */ |
| 573 | { nsm_ignore, NSM_TwoWay }, /* Start */ |
| 574 | { nsm_ignore, NSM_TwoWay }, /* 2-WayReceived */ |
| 575 | { nsm_ignore, NSM_TwoWay }, /* NegotiationDone */ |
| 576 | { nsm_ignore, NSM_TwoWay }, /* ExchangeDone */ |
| 577 | { nsm_ignore, NSM_TwoWay }, /* BadLSReq */ |
| 578 | { nsm_ignore, NSM_TwoWay }, /* LoadingDone */ |
| 579 | { nsm_adj_ok, NSM_DependUpon }, /* AdjOK? */ |
| 580 | { nsm_ignore, NSM_TwoWay }, /* SeqNumberMismatch */ |
| 581 | { nsm_oneway_received, NSM_Init }, /* 1-WayReceived */ |
| 582 | { nsm_kill_nbr, NSM_Down }, /* KillNbr */ |
| 583 | { nsm_inactivity_timer, NSM_Down }, /* InactivityTimer */ |
| 584 | { nsm_ll_down, NSM_Down }, /* LLDown */ |
| 585 | }, |
| 586 | { |
| 587 | /* ExStart: */ |
| 588 | { nsm_ignore, NSM_DependUpon }, /* NoEvent */ |
| 589 | { nsm_hello_received, NSM_ExStart }, /* HelloReceived */ |
| 590 | { nsm_ignore, NSM_ExStart }, /* Start */ |
| 591 | { nsm_ignore, NSM_ExStart }, /* 2-WayReceived */ |
| 592 | { nsm_negotiation_done, NSM_Exchange }, /* NegotiationDone */ |
| 593 | { nsm_ignore, NSM_ExStart }, /* ExchangeDone */ |
| 594 | { nsm_ignore, NSM_ExStart }, /* BadLSReq */ |
| 595 | { nsm_ignore, NSM_ExStart }, /* LoadingDone */ |
| 596 | { nsm_adj_ok, NSM_DependUpon }, /* AdjOK? */ |
| 597 | { nsm_ignore, NSM_ExStart }, /* SeqNumberMismatch */ |
| 598 | { nsm_oneway_received, NSM_Init }, /* 1-WayReceived */ |
| 599 | { nsm_kill_nbr, NSM_Down }, /* KillNbr */ |
| 600 | { nsm_inactivity_timer, NSM_Down }, /* InactivityTimer */ |
| 601 | { nsm_ll_down, NSM_Down }, /* LLDown */ |
| 602 | }, |
| 603 | { |
| 604 | /* Exchange: */ |
| 605 | { nsm_ignore, NSM_DependUpon }, /* NoEvent */ |
| 606 | { nsm_hello_received, NSM_Exchange }, /* HelloReceived */ |
| 607 | { nsm_ignore, NSM_Exchange }, /* Start */ |
| 608 | { nsm_ignore, NSM_Exchange }, /* 2-WayReceived */ |
| 609 | { nsm_ignore, NSM_Exchange }, /* NegotiationDone */ |
| 610 | { nsm_exchange_done, NSM_DependUpon }, /* ExchangeDone */ |
| 611 | { nsm_bad_ls_req, NSM_ExStart }, /* BadLSReq */ |
| 612 | { nsm_ignore, NSM_Exchange }, /* LoadingDone */ |
| 613 | { nsm_adj_ok, NSM_DependUpon }, /* AdjOK? */ |
| 614 | { nsm_seq_number_mismatch, NSM_ExStart }, /* SeqNumberMismatch */ |
| 615 | { nsm_oneway_received, NSM_Init }, /* 1-WayReceived */ |
| 616 | { nsm_kill_nbr, NSM_Down }, /* KillNbr */ |
| 617 | { nsm_inactivity_timer, NSM_Down }, /* InactivityTimer */ |
| 618 | { nsm_ll_down, NSM_Down }, /* LLDown */ |
| 619 | }, |
| 620 | { |
| 621 | /* Loading: */ |
| 622 | { nsm_ignore, NSM_DependUpon }, /* NoEvent */ |
| 623 | { nsm_hello_received, NSM_Loading }, /* HelloReceived */ |
| 624 | { nsm_ignore, NSM_Loading }, /* Start */ |
| 625 | { nsm_ignore, NSM_Loading }, /* 2-WayReceived */ |
| 626 | { nsm_ignore, NSM_Loading }, /* NegotiationDone */ |
| 627 | { nsm_ignore, NSM_Loading }, /* ExchangeDone */ |
| 628 | { nsm_bad_ls_req, NSM_ExStart }, /* BadLSReq */ |
| 629 | { nsm_ignore, NSM_Full }, /* LoadingDone */ |
| 630 | { nsm_adj_ok, NSM_DependUpon }, /* AdjOK? */ |
| 631 | { nsm_seq_number_mismatch, NSM_ExStart }, /* SeqNumberMismatch */ |
| 632 | { nsm_oneway_received, NSM_Init }, /* 1-WayReceived */ |
| 633 | { nsm_kill_nbr, NSM_Down }, /* KillNbr */ |
| 634 | { nsm_inactivity_timer, NSM_Down }, /* InactivityTimer */ |
| 635 | { nsm_ll_down, NSM_Down }, /* LLDown */ |
| 636 | }, |
| 637 | { /* Full: */ |
| 638 | { nsm_ignore, NSM_DependUpon }, /* NoEvent */ |
| 639 | { nsm_hello_received, NSM_Full }, /* HelloReceived */ |
| 640 | { nsm_ignore, NSM_Full }, /* Start */ |
| 641 | { nsm_ignore, NSM_Full }, /* 2-WayReceived */ |
| 642 | { nsm_ignore, NSM_Full }, /* NegotiationDone */ |
| 643 | { nsm_ignore, NSM_Full }, /* ExchangeDone */ |
| 644 | { nsm_bad_ls_req, NSM_ExStart }, /* BadLSReq */ |
| 645 | { nsm_ignore, NSM_Full }, /* LoadingDone */ |
| 646 | { nsm_adj_ok, NSM_DependUpon }, /* AdjOK? */ |
| 647 | { nsm_seq_number_mismatch, NSM_ExStart }, /* SeqNumberMismatch */ |
| 648 | { nsm_oneway_received, NSM_Init }, /* 1-WayReceived */ |
| 649 | { nsm_kill_nbr, NSM_Down }, /* KillNbr */ |
| 650 | { nsm_inactivity_timer, NSM_Down }, /* InactivityTimer */ |
| 651 | { nsm_ll_down, NSM_Down }, /* LLDown */ |
| 652 | }, |
| 653 | }; |
| 654 | |
hasso | eb1ce60 | 2004-10-08 08:17:22 +0000 | [diff] [blame] | 655 | const static char *ospf_nsm_event_str[] = |
paul | 2d59836 | 2003-01-17 23:48:42 +0000 | [diff] [blame] | 656 | { |
| 657 | "NoEvent", |
| 658 | "HelloReceived", |
| 659 | "Start", |
| 660 | "2-WayReceived", |
| 661 | "NegotiationDone", |
| 662 | "ExchangeDone", |
| 663 | "BadLSReq", |
| 664 | "LoadingDone", |
| 665 | "AdjOK?", |
| 666 | "SeqNumberMismatch", |
| 667 | "1-WayReceived", |
| 668 | "KillNbr", |
| 669 | "InactivityTimer", |
| 670 | "LLDown", |
| 671 | }; |
| 672 | |
| 673 | void |
| 674 | nsm_change_state (struct ospf_neighbor *nbr, int state) |
| 675 | { |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 676 | struct ospf_interface *oi = nbr->oi; |
paul | 2d59836 | 2003-01-17 23:48:42 +0000 | [diff] [blame] | 677 | struct ospf_area *vl_area = NULL; |
| 678 | u_char old_state; |
| 679 | int x; |
| 680 | int force = 1; |
| 681 | |
| 682 | /* Logging change of status. */ |
| 683 | if (IS_DEBUG_OSPF (nsm, NSM_STATUS)) |
ajs | 2a42e28 | 2004-12-08 18:43:03 +0000 | [diff] [blame] | 684 | zlog_debug ("NSM[%s:%s]: State change %s -> %s", |
paul | 2d59836 | 2003-01-17 23:48:42 +0000 | [diff] [blame] | 685 | IF_NAME (nbr->oi), inet_ntoa (nbr->router_id), |
| 686 | LOOKUP (ospf_nsm_state_msg, nbr->state), |
| 687 | LOOKUP (ospf_nsm_state_msg, state)); |
| 688 | |
| 689 | /* Preserve old status. */ |
| 690 | old_state = nbr->state; |
| 691 | |
| 692 | /* Change to new status. */ |
| 693 | nbr->state = state; |
| 694 | |
| 695 | /* Statistics. */ |
| 696 | nbr->state_change++; |
| 697 | |
paul | 2d59836 | 2003-01-17 23:48:42 +0000 | [diff] [blame] | 698 | if (oi->type == OSPF_IFTYPE_VIRTUALLINK) |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 699 | vl_area = ospf_area_lookup_by_area_id (oi->ospf, oi->vl_data->vl_area_id); |
paul | 2d59836 | 2003-01-17 23:48:42 +0000 | [diff] [blame] | 700 | |
vincent | 5e4914c | 2005-09-29 16:34:30 +0000 | [diff] [blame] | 701 | #ifdef HAVE_SNMP |
| 702 | /* Terminal state or regression */ |
| 703 | if ((state == NSM_Full) || (state == NSM_TwoWay) || (state < old_state)) |
| 704 | { |
| 705 | /* ospfVirtNbrStateChange */ |
| 706 | if (oi->type == OSPF_IFTYPE_VIRTUALLINK) |
| 707 | ospfTrapVirtNbrStateChange(nbr); |
| 708 | /* ospfNbrStateChange trap */ |
| 709 | else |
| 710 | /* To/From FULL, only managed by DR */ |
| 711 | if (((state != NSM_Full) && (old_state != NSM_Full)) || |
| 712 | (oi->state == ISM_DR)) |
| 713 | ospfTrapNbrStateChange(nbr); |
| 714 | } |
| 715 | #endif |
| 716 | |
paul | 2d59836 | 2003-01-17 23:48:42 +0000 | [diff] [blame] | 717 | /* One of the neighboring routers changes to/from the FULL state. */ |
| 718 | if ((old_state != NSM_Full && state == NSM_Full) || |
| 719 | (old_state == NSM_Full && state != NSM_Full)) |
ajs | 3aa8d5f | 2004-12-11 18:00:06 +0000 | [diff] [blame] | 720 | { |
paul | 2d59836 | 2003-01-17 23:48:42 +0000 | [diff] [blame] | 721 | if (state == NSM_Full) |
| 722 | { |
| 723 | oi->full_nbrs++; |
| 724 | oi->area->full_nbrs++; |
| 725 | |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 726 | ospf_check_abr_status (oi->ospf); |
paul | 2d59836 | 2003-01-17 23:48:42 +0000 | [diff] [blame] | 727 | |
| 728 | if (oi->type == OSPF_IFTYPE_VIRTUALLINK && vl_area) |
| 729 | if (++vl_area->full_vls == 1) |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 730 | ospf_schedule_abr_task (oi->ospf); |
paul | 2d59836 | 2003-01-17 23:48:42 +0000 | [diff] [blame] | 731 | |
| 732 | /* kevinm: refresh any redistributions */ |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 733 | for (x = ZEBRA_ROUTE_SYSTEM; x < ZEBRA_ROUTE_MAX; x++) |
| 734 | { |
| 735 | if (x == ZEBRA_ROUTE_OSPF || x == ZEBRA_ROUTE_OSPF6) |
| 736 | continue; |
| 737 | ospf_external_lsa_refresh_type (oi->ospf, x, force); |
| 738 | } |
paul | 2d59836 | 2003-01-17 23:48:42 +0000 | [diff] [blame] | 739 | } |
| 740 | else |
| 741 | { |
| 742 | oi->full_nbrs--; |
| 743 | oi->area->full_nbrs--; |
| 744 | |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 745 | ospf_check_abr_status (oi->ospf); |
paul | 2d59836 | 2003-01-17 23:48:42 +0000 | [diff] [blame] | 746 | |
| 747 | if (oi->type == OSPF_IFTYPE_VIRTUALLINK && vl_area) |
| 748 | if (vl_area->full_vls > 0) |
| 749 | if (--vl_area->full_vls == 0) |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 750 | ospf_schedule_abr_task (oi->ospf); |
paul | 2d59836 | 2003-01-17 23:48:42 +0000 | [diff] [blame] | 751 | |
| 752 | /* clear neighbor retransmit list */ |
| 753 | if (!ospf_ls_retransmit_isempty (nbr)) |
| 754 | ospf_ls_retransmit_clear (nbr); |
| 755 | } |
| 756 | |
ajs | 3aa8d5f | 2004-12-11 18:00:06 +0000 | [diff] [blame] | 757 | zlog_info ("nsm_change_state(%s, %s -> %s): " |
| 758 | "scheduling new router-LSA origination", |
| 759 | inet_ntoa (nbr->router_id), |
| 760 | LOOKUP(ospf_nsm_state_msg, old_state), |
| 761 | LOOKUP(ospf_nsm_state_msg, state)); |
paul | 2d59836 | 2003-01-17 23:48:42 +0000 | [diff] [blame] | 762 | |
| 763 | ospf_router_lsa_timer_add (oi->area); |
| 764 | |
| 765 | if (oi->type == OSPF_IFTYPE_VIRTUALLINK) |
| 766 | { |
| 767 | struct ospf_area *vl_area = |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 768 | ospf_area_lookup_by_area_id (oi->ospf, oi->vl_data->vl_area_id); |
paul | 2d59836 | 2003-01-17 23:48:42 +0000 | [diff] [blame] | 769 | |
| 770 | if (vl_area) |
| 771 | ospf_router_lsa_timer_add (vl_area); |
| 772 | } |
| 773 | |
| 774 | /* Originate network-LSA. */ |
| 775 | if (oi->state == ISM_DR) |
| 776 | { |
| 777 | if (oi->network_lsa_self && oi->full_nbrs == 0) |
| 778 | { |
| 779 | ospf_lsa_flush_area (oi->network_lsa_self, oi->area); |
| 780 | ospf_lsa_unlock (oi->network_lsa_self); |
| 781 | oi->network_lsa_self = NULL; |
| 782 | OSPF_TIMER_OFF (oi->t_network_lsa_self); |
| 783 | } |
| 784 | else |
| 785 | ospf_network_lsa_timer_add (oi); |
| 786 | } |
| 787 | } |
| 788 | |
| 789 | #ifdef HAVE_OPAQUE_LSA |
| 790 | ospf_opaque_nsm_change (nbr, old_state); |
| 791 | #endif /* HAVE_OPAQUE_LSA */ |
| 792 | |
| 793 | /* Start DD exchange protocol */ |
| 794 | if (state == NSM_ExStart) |
| 795 | { |
| 796 | if (nbr->dd_seqnum == 0) |
| 797 | nbr->dd_seqnum = time (NULL); |
| 798 | else |
| 799 | nbr->dd_seqnum++; |
| 800 | |
| 801 | nbr->dd_flags = OSPF_DD_FLAG_I|OSPF_DD_FLAG_M|OSPF_DD_FLAG_MS; |
| 802 | ospf_db_desc_send (nbr); |
| 803 | } |
| 804 | |
| 805 | /* clear cryptographic sequence number */ |
| 806 | if (state == NSM_Down) |
| 807 | nbr->crypt_seqnum = 0; |
| 808 | |
| 809 | /* Generete NeighborChange ISM event. */ |
| 810 | #ifdef BUGGY_ISM_TRANSITION |
| 811 | if ((old_state < NSM_TwoWay && state >= NSM_TwoWay) || |
| 812 | (old_state >= NSM_TwoWay && state < NSM_TwoWay)) |
| 813 | OSPF_ISM_EVENT_EXECUTE (oi, ISM_NeighborChange); |
| 814 | #else /* BUGGY_ISM_TRANSITION */ |
| 815 | switch (oi->state) { |
| 816 | case ISM_DROther: |
| 817 | case ISM_Backup: |
| 818 | case ISM_DR: |
| 819 | if ((old_state < NSM_TwoWay && state >= NSM_TwoWay) || |
| 820 | (old_state >= NSM_TwoWay && state < NSM_TwoWay)) |
| 821 | OSPF_ISM_EVENT_EXECUTE (oi, ISM_NeighborChange); |
| 822 | break; |
| 823 | default: |
| 824 | /* ISM_PointToPoint -> ISM_Down, ISM_Loopback -> ISM_Down, etc. */ |
| 825 | break; |
| 826 | } |
| 827 | #endif /* BUGGY_ISM_TRANSITION */ |
| 828 | |
| 829 | /* Performance hack. Send hello immideately when some neighbor enter |
| 830 | Init state. This whay we decrease neighbor discovery time. Gleb.*/ |
| 831 | if (state == NSM_Init) |
| 832 | { |
| 833 | OSPF_ISM_TIMER_OFF (oi->t_hello); |
paul | f9ad937 | 2005-10-21 00:45:17 +0000 | [diff] [blame] | 834 | OSPF_ISM_TIMER_MSEC_ON (oi->t_hello, ospf_hello_timer, 1); |
paul | 2d59836 | 2003-01-17 23:48:42 +0000 | [diff] [blame] | 835 | } |
| 836 | |
| 837 | /* Preserve old status? */ |
| 838 | } |
| 839 | |
| 840 | /* Execute NSM event process. */ |
| 841 | int |
| 842 | ospf_nsm_event (struct thread *thread) |
| 843 | { |
| 844 | int event; |
| 845 | int next_state; |
| 846 | struct ospf_neighbor *nbr; |
| 847 | struct in_addr router_id; |
| 848 | int old_state; |
| 849 | struct ospf_interface *oi; |
| 850 | |
| 851 | nbr = THREAD_ARG (thread); |
| 852 | event = THREAD_VAL (thread); |
| 853 | router_id = nbr->router_id; |
| 854 | |
| 855 | old_state = nbr->state; |
| 856 | oi = nbr->oi ; |
| 857 | |
| 858 | /* Call function. */ |
| 859 | next_state = (*(NSM [nbr->state][event].func))(nbr); |
| 860 | |
| 861 | /* When event is NSM_KillNbr or InactivityTimer, the neighbor is |
| 862 | deleted. */ |
| 863 | if (event == NSM_KillNbr || event == NSM_InactivityTimer) |
| 864 | { |
| 865 | if (IS_DEBUG_OSPF (nsm, NSM_EVENTS)) |
ajs | 2a42e28 | 2004-12-08 18:43:03 +0000 | [diff] [blame] | 866 | zlog_debug ("NSM[%s:%s]: neighbor deleted", |
paul | 2d59836 | 2003-01-17 23:48:42 +0000 | [diff] [blame] | 867 | IF_NAME (oi), inet_ntoa (router_id)); |
| 868 | |
| 869 | /* Timers are canceled in ospf_nbr_free, moreover we cannot call |
| 870 | nsm_timer_set here because nbr is freed already!!!*/ |
| 871 | /*nsm_timer_set (nbr);*/ |
| 872 | |
| 873 | return 0; |
| 874 | } |
| 875 | |
| 876 | if (! next_state) |
| 877 | next_state = NSM [nbr->state][event].next_state; |
| 878 | |
| 879 | if (IS_DEBUG_OSPF (nsm, NSM_EVENTS)) |
ajs | 2a42e28 | 2004-12-08 18:43:03 +0000 | [diff] [blame] | 880 | zlog_debug ("NSM[%s:%s]: %s (%s)", IF_NAME (oi), |
paul | 2d59836 | 2003-01-17 23:48:42 +0000 | [diff] [blame] | 881 | inet_ntoa (nbr->router_id), |
| 882 | LOOKUP (ospf_nsm_state_msg, nbr->state), |
| 883 | ospf_nsm_event_str [event]); |
| 884 | |
| 885 | /* If state is changed. */ |
| 886 | if (next_state != nbr->state) |
| 887 | nsm_change_state (nbr, next_state); |
| 888 | |
| 889 | /* Make sure timer is set. */ |
| 890 | nsm_timer_set (nbr); |
| 891 | |
| 892 | return 0; |
| 893 | } |
| 894 | |
| 895 | /* Check loading state. */ |
| 896 | void |
| 897 | ospf_check_nbr_loading (struct ospf_neighbor *nbr) |
| 898 | { |
| 899 | if (nbr->state == NSM_Loading) |
| 900 | { |
| 901 | if (ospf_ls_request_isempty (nbr)) |
| 902 | OSPF_NSM_EVENT_SCHEDULE (nbr, NSM_LoadingDone); |
| 903 | else if (nbr->ls_req_last == NULL) |
| 904 | ospf_ls_req_event (nbr); |
| 905 | } |
| 906 | } |