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 | |
Paul Jakma | d1b1cd8 | 2006-07-04 13:50:44 +0000 | [diff] [blame] | 52 | static void nsm_clear_adj (struct ospf_neighbor *); |
David Lamparter | 6b0655a | 2014-06-04 06:53:35 +0200 | [diff] [blame] | 53 | |
paul | 2d59836 | 2003-01-17 23:48:42 +0000 | [diff] [blame] | 54 | /* OSPF NSM Timer functions. */ |
paul | 4dadc29 | 2005-05-06 21:37:42 +0000 | [diff] [blame] | 55 | static int |
paul | 2d59836 | 2003-01-17 23:48:42 +0000 | [diff] [blame] | 56 | ospf_inactivity_timer (struct thread *thread) |
| 57 | { |
| 58 | struct ospf_neighbor *nbr; |
| 59 | |
| 60 | nbr = THREAD_ARG (thread); |
| 61 | nbr->t_inactivity = NULL; |
| 62 | |
| 63 | if (IS_DEBUG_OSPF (nsm, NSM_TIMERS)) |
| 64 | zlog (NULL, LOG_DEBUG, "NSM[%s:%s]: Timer (Inactivity timer expire)", |
| 65 | IF_NAME (nbr->oi), inet_ntoa (nbr->router_id)); |
| 66 | |
| 67 | OSPF_NSM_EVENT_SCHEDULE (nbr, NSM_InactivityTimer); |
| 68 | |
| 69 | return 0; |
| 70 | } |
| 71 | |
paul | 4dadc29 | 2005-05-06 21:37:42 +0000 | [diff] [blame] | 72 | static int |
paul | 2d59836 | 2003-01-17 23:48:42 +0000 | [diff] [blame] | 73 | ospf_db_desc_timer (struct thread *thread) |
| 74 | { |
paul | 2d59836 | 2003-01-17 23:48:42 +0000 | [diff] [blame] | 75 | struct ospf_neighbor *nbr; |
| 76 | |
| 77 | nbr = THREAD_ARG (thread); |
| 78 | nbr->t_db_desc = NULL; |
| 79 | |
paul | 2d59836 | 2003-01-17 23:48:42 +0000 | [diff] [blame] | 80 | if (IS_DEBUG_OSPF (nsm, NSM_TIMERS)) |
ajs | 2a42e28 | 2004-12-08 18:43:03 +0000 | [diff] [blame] | 81 | zlog (NULL, LOG_DEBUG, "NSM[%s:%s]: Timer (DD Retransmit timer expire)", |
paul | 2d59836 | 2003-01-17 23:48:42 +0000 | [diff] [blame] | 82 | IF_NAME (nbr->oi), inet_ntoa (nbr->src)); |
| 83 | |
| 84 | /* resent last send DD packet. */ |
| 85 | assert (nbr->last_send); |
| 86 | ospf_db_desc_resend (nbr); |
| 87 | |
| 88 | /* DD Retransmit timer set. */ |
| 89 | OSPF_NSM_TIMER_ON (nbr->t_db_desc, ospf_db_desc_timer, nbr->v_db_desc); |
| 90 | |
| 91 | return 0; |
| 92 | } |
| 93 | |
Paul Jakma | 1f2c274 | 2006-07-10 07:45:13 +0000 | [diff] [blame] | 94 | /* Hook function called after ospf NSM event is occured. |
| 95 | * |
| 96 | * Set/clear any timers whose condition is implicit to the neighbour |
| 97 | * state. There may be other timers which are set/unset according to other |
| 98 | * state. |
| 99 | * |
| 100 | * We rely on this function to properly clear timers in lower states, |
| 101 | * particularly before deleting a neighbour. |
| 102 | */ |
paul | 4dadc29 | 2005-05-06 21:37:42 +0000 | [diff] [blame] | 103 | static void |
paul | 2d59836 | 2003-01-17 23:48:42 +0000 | [diff] [blame] | 104 | nsm_timer_set (struct ospf_neighbor *nbr) |
| 105 | { |
| 106 | switch (nbr->state) |
| 107 | { |
Paul Jakma | 1f2c274 | 2006-07-10 07:45:13 +0000 | [diff] [blame] | 108 | case NSM_Deleted: |
paul | 2d59836 | 2003-01-17 23:48:42 +0000 | [diff] [blame] | 109 | case NSM_Down: |
Paul Jakma | e55dd53 | 2006-07-04 13:46:14 +0000 | [diff] [blame] | 110 | OSPF_NSM_TIMER_OFF (nbr->t_inactivity); |
Paul Jakma | 1f2c274 | 2006-07-10 07:45:13 +0000 | [diff] [blame] | 111 | OSPF_NSM_TIMER_OFF (nbr->t_hello_reply); |
paul | 2d59836 | 2003-01-17 23:48:42 +0000 | [diff] [blame] | 112 | case NSM_Attempt: |
paul | 2d59836 | 2003-01-17 23:48:42 +0000 | [diff] [blame] | 113 | case NSM_Init: |
paul | 2d59836 | 2003-01-17 23:48:42 +0000 | [diff] [blame] | 114 | case NSM_TwoWay: |
| 115 | OSPF_NSM_TIMER_OFF (nbr->t_db_desc); |
| 116 | OSPF_NSM_TIMER_OFF (nbr->t_ls_upd); |
Paul Jakma | e55dd53 | 2006-07-04 13:46:14 +0000 | [diff] [blame] | 117 | OSPF_NSM_TIMER_OFF (nbr->t_ls_req); |
paul | 2d59836 | 2003-01-17 23:48:42 +0000 | [diff] [blame] | 118 | break; |
| 119 | case NSM_ExStart: |
| 120 | OSPF_NSM_TIMER_ON (nbr->t_db_desc, ospf_db_desc_timer, nbr->v_db_desc); |
| 121 | OSPF_NSM_TIMER_OFF (nbr->t_ls_upd); |
Paul Jakma | e55dd53 | 2006-07-04 13:46:14 +0000 | [diff] [blame] | 122 | OSPF_NSM_TIMER_OFF (nbr->t_ls_req); |
paul | 2d59836 | 2003-01-17 23:48:42 +0000 | [diff] [blame] | 123 | break; |
| 124 | case NSM_Exchange: |
| 125 | OSPF_NSM_TIMER_ON (nbr->t_ls_upd, ospf_ls_upd_timer, nbr->v_ls_upd); |
| 126 | if (!IS_SET_DD_MS (nbr->dd_flags)) |
| 127 | OSPF_NSM_TIMER_OFF (nbr->t_db_desc); |
| 128 | break; |
| 129 | case NSM_Loading: |
paul | 2d59836 | 2003-01-17 23:48:42 +0000 | [diff] [blame] | 130 | case NSM_Full: |
paul | 2d59836 | 2003-01-17 23:48:42 +0000 | [diff] [blame] | 131 | default: |
| 132 | OSPF_NSM_TIMER_OFF (nbr->t_db_desc); |
| 133 | break; |
| 134 | } |
| 135 | } |
| 136 | |
Paul Jakma | d7b0fb6 | 2006-07-04 13:35:24 +0000 | [diff] [blame] | 137 | /* 10.4 of RFC2328, indicate whether an adjacency is appropriate with |
| 138 | * the given neighbour |
| 139 | */ |
| 140 | static int |
| 141 | nsm_should_adj (struct ospf_neighbor *nbr) |
| 142 | { |
Paul Jakma | f7a76ab | 2006-07-04 13:57:49 +0000 | [diff] [blame] | 143 | struct ospf_interface *oi = nbr->oi; |
Paul Jakma | d7b0fb6 | 2006-07-04 13:35:24 +0000 | [diff] [blame] | 144 | |
Paul Jakma | f7a76ab | 2006-07-04 13:57:49 +0000 | [diff] [blame] | 145 | /* These network types must always form adjacencies. */ |
Paul Jakma | d7b0fb6 | 2006-07-04 13:35:24 +0000 | [diff] [blame] | 146 | if (oi->type == OSPF_IFTYPE_POINTOPOINT |
| 147 | || oi->type == OSPF_IFTYPE_POINTOMULTIPOINT |
Paul Jakma | f7a76ab | 2006-07-04 13:57:49 +0000 | [diff] [blame] | 148 | || oi->type == OSPF_IFTYPE_VIRTUALLINK |
| 149 | /* Router itself is the DRouter or the BDRouter. */ |
| 150 | || IPV4_ADDR_SAME (&oi->address->u.prefix4, &DR (oi)) |
| 151 | || IPV4_ADDR_SAME (&oi->address->u.prefix4, &BDR (oi)) |
| 152 | /* Neighboring Router is the DRouter or the BDRouter. */ |
| 153 | || IPV4_ADDR_SAME (&nbr->address.u.prefix4, &DR (oi)) |
Paul Jakma | d7b0fb6 | 2006-07-04 13:35:24 +0000 | [diff] [blame] | 154 | || IPV4_ADDR_SAME (&nbr->address.u.prefix4, &BDR (oi))) |
| 155 | return 1; |
| 156 | |
| 157 | return 0; |
| 158 | } |
David Lamparter | 6b0655a | 2014-06-04 06:53:35 +0200 | [diff] [blame] | 159 | |
paul | 2d59836 | 2003-01-17 23:48:42 +0000 | [diff] [blame] | 160 | /* OSPF NSM functions. */ |
paul | 4dadc29 | 2005-05-06 21:37:42 +0000 | [diff] [blame] | 161 | static int |
Paul Jakma | 57c5c65 | 2010-01-07 06:12:53 +0000 | [diff] [blame] | 162 | nsm_packet_received (struct ospf_neighbor *nbr) |
paul | 2d59836 | 2003-01-17 23:48:42 +0000 | [diff] [blame] | 163 | { |
| 164 | /* Start or Restart Inactivity Timer. */ |
| 165 | OSPF_NSM_TIMER_OFF (nbr->t_inactivity); |
| 166 | |
| 167 | OSPF_NSM_TIMER_ON (nbr->t_inactivity, ospf_inactivity_timer, |
| 168 | nbr->v_inactivity); |
| 169 | |
| 170 | if (nbr->oi->type == OSPF_IFTYPE_NBMA && nbr->nbr_nbma) |
| 171 | OSPF_POLL_TIMER_OFF (nbr->nbr_nbma->t_poll); |
| 172 | |
| 173 | return 0; |
| 174 | } |
| 175 | |
paul | 4dadc29 | 2005-05-06 21:37:42 +0000 | [diff] [blame] | 176 | static int |
paul | 2d59836 | 2003-01-17 23:48:42 +0000 | [diff] [blame] | 177 | nsm_start (struct ospf_neighbor *nbr) |
| 178 | { |
paul | 2d59836 | 2003-01-17 23:48:42 +0000 | [diff] [blame] | 179 | if (nbr->nbr_nbma) |
| 180 | OSPF_POLL_TIMER_OFF (nbr->nbr_nbma->t_poll); |
| 181 | |
| 182 | OSPF_NSM_TIMER_OFF (nbr->t_inactivity); |
| 183 | |
| 184 | OSPF_NSM_TIMER_ON (nbr->t_inactivity, ospf_inactivity_timer, |
| 185 | nbr->v_inactivity); |
| 186 | |
| 187 | return 0; |
| 188 | } |
| 189 | |
paul | 4dadc29 | 2005-05-06 21:37:42 +0000 | [diff] [blame] | 190 | static int |
paul | 2d59836 | 2003-01-17 23:48:42 +0000 | [diff] [blame] | 191 | nsm_twoway_received (struct ospf_neighbor *nbr) |
| 192 | { |
Paul Jakma | f7a76ab | 2006-07-04 13:57:49 +0000 | [diff] [blame] | 193 | return (nsm_should_adj (nbr) ? NSM_ExStart : NSM_TwoWay); |
paul | 2d59836 | 2003-01-17 23:48:42 +0000 | [diff] [blame] | 194 | } |
| 195 | |
| 196 | int |
| 197 | ospf_db_summary_count (struct ospf_neighbor *nbr) |
| 198 | { |
| 199 | return ospf_lsdb_count_all (&nbr->db_sum); |
| 200 | } |
| 201 | |
| 202 | int |
| 203 | ospf_db_summary_isempty (struct ospf_neighbor *nbr) |
| 204 | { |
| 205 | return ospf_lsdb_isempty (&nbr->db_sum); |
| 206 | } |
| 207 | |
paul | 4dadc29 | 2005-05-06 21:37:42 +0000 | [diff] [blame] | 208 | static int |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 209 | ospf_db_summary_add (struct ospf_neighbor *nbr, struct ospf_lsa *lsa) |
paul | 2d59836 | 2003-01-17 23:48:42 +0000 | [diff] [blame] | 210 | { |
paul | 09e4efd | 2003-01-18 00:12:02 +0000 | [diff] [blame] | 211 | switch (lsa->data->type) |
| 212 | { |
| 213 | case OSPF_OPAQUE_LINK_LSA: |
| 214 | /* Exclude type-9 LSAs that does not have the same "oi" with "nbr". */ |
Paul Jakma | d71ea65 | 2011-03-22 15:23:55 +0000 | [diff] [blame] | 215 | if (nbr->oi && ospf_if_exists (lsa->oi) != nbr->oi) |
paul | 09e4efd | 2003-01-18 00:12:02 +0000 | [diff] [blame] | 216 | return 0; |
| 217 | break; |
| 218 | case OSPF_OPAQUE_AREA_LSA: |
| 219 | /* |
| 220 | * It is assured by the caller function "nsm_negotiation_done()" |
| 221 | * that every given LSA belongs to the same area with "nbr". |
| 222 | */ |
| 223 | break; |
| 224 | case OSPF_OPAQUE_AS_LSA: |
| 225 | default: |
| 226 | break; |
| 227 | } |
paul | 09e4efd | 2003-01-18 00:12:02 +0000 | [diff] [blame] | 228 | |
paul | 2d59836 | 2003-01-17 23:48:42 +0000 | [diff] [blame] | 229 | /* Stay away from any Local Translated Type-7 LSAs */ |
| 230 | if (CHECK_FLAG (lsa->flags, OSPF_LSA_LOCAL_XLT)) |
| 231 | return 0; |
paul | 2d59836 | 2003-01-17 23:48:42 +0000 | [diff] [blame] | 232 | |
| 233 | if (IS_LSA_MAXAGE (lsa)) |
| 234 | ospf_ls_retransmit_add (nbr, lsa); |
| 235 | else |
| 236 | ospf_lsdb_add (&nbr->db_sum, lsa); |
| 237 | |
| 238 | return 0; |
| 239 | } |
| 240 | |
| 241 | void |
| 242 | ospf_db_summary_clear (struct ospf_neighbor *nbr) |
| 243 | { |
| 244 | struct ospf_lsdb *lsdb; |
| 245 | int i; |
| 246 | |
| 247 | lsdb = &nbr->db_sum; |
| 248 | for (i = OSPF_MIN_LSA; i < OSPF_MAX_LSA; i++) |
| 249 | { |
| 250 | struct route_table *table = lsdb->type[i].db; |
| 251 | struct route_node *rn; |
| 252 | |
| 253 | for (rn = route_top (table); rn; rn = route_next (rn)) |
| 254 | if (rn->info) |
| 255 | ospf_lsdb_delete (&nbr->db_sum, rn->info); |
| 256 | } |
| 257 | } |
| 258 | |
David Lamparter | 6b0655a | 2014-06-04 06:53:35 +0200 | [diff] [blame] | 259 | |
paul | 2d59836 | 2003-01-17 23:48:42 +0000 | [diff] [blame] | 260 | |
paul | 2d59836 | 2003-01-17 23:48:42 +0000 | [diff] [blame] | 261 | /* The area link state database consists of the router-LSAs, |
| 262 | network-LSAs and summary-LSAs contained in the area structure, |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 263 | along with the AS-external-LSAs contained in the global structure. |
| 264 | AS-external-LSAs are omitted from a virtual neighbor's Database |
paul | 2d59836 | 2003-01-17 23:48:42 +0000 | [diff] [blame] | 265 | summary list. AS-external-LSAs are omitted from the Database |
| 266 | summary list if the area has been configured as a stub. */ |
paul | 4dadc29 | 2005-05-06 21:37:42 +0000 | [diff] [blame] | 267 | static int |
paul | 2d59836 | 2003-01-17 23:48:42 +0000 | [diff] [blame] | 268 | nsm_negotiation_done (struct ospf_neighbor *nbr) |
| 269 | { |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 270 | struct ospf_area *area = nbr->oi->area; |
| 271 | struct ospf_lsa *lsa; |
| 272 | struct route_node *rn; |
paul | 2d59836 | 2003-01-17 23:48:42 +0000 | [diff] [blame] | 273 | |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 274 | LSDB_LOOP (ROUTER_LSDB (area), rn, lsa) |
| 275 | ospf_db_summary_add (nbr, lsa); |
| 276 | LSDB_LOOP (NETWORK_LSDB (area), rn, lsa) |
| 277 | ospf_db_summary_add (nbr, lsa); |
| 278 | LSDB_LOOP (SUMMARY_LSDB (area), rn, lsa) |
| 279 | ospf_db_summary_add (nbr, lsa); |
| 280 | LSDB_LOOP (ASBR_SUMMARY_LSDB (area), rn, lsa) |
| 281 | ospf_db_summary_add (nbr, lsa); |
paul | 2d59836 | 2003-01-17 23:48:42 +0000 | [diff] [blame] | 282 | |
paul | 2d59836 | 2003-01-17 23:48:42 +0000 | [diff] [blame] | 283 | /* Process only if the neighbor is opaque capable. */ |
| 284 | if (CHECK_FLAG (nbr->options, OSPF_OPTION_O)) |
| 285 | { |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 286 | LSDB_LOOP (OPAQUE_LINK_LSDB (area), rn, lsa) |
| 287 | ospf_db_summary_add (nbr, lsa); |
| 288 | LSDB_LOOP (OPAQUE_AREA_LSDB (area), rn, lsa) |
| 289 | ospf_db_summary_add (nbr, lsa); |
paul | 2d59836 | 2003-01-17 23:48:42 +0000 | [diff] [blame] | 290 | } |
paul | 2d59836 | 2003-01-17 23:48:42 +0000 | [diff] [blame] | 291 | |
hasso | f4833e9 | 2005-06-20 20:42:26 +0000 | [diff] [blame] | 292 | if (CHECK_FLAG (nbr->options, OSPF_OPTION_NP)) |
| 293 | { |
| 294 | LSDB_LOOP (NSSA_LSDB (area), rn, lsa) |
| 295 | ospf_db_summary_add (nbr, lsa); |
| 296 | } |
| 297 | |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 298 | if (nbr->oi->type != OSPF_IFTYPE_VIRTUALLINK |
| 299 | && area->external_routing == OSPF_AREA_DEFAULT) |
| 300 | LSDB_LOOP (EXTERNAL_LSDB (nbr->oi->ospf), rn, lsa) |
| 301 | ospf_db_summary_add (nbr, lsa); |
paul | 2d59836 | 2003-01-17 23:48:42 +0000 | [diff] [blame] | 302 | |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 303 | if (CHECK_FLAG (nbr->options, OSPF_OPTION_O) |
| 304 | && (nbr->oi->type != OSPF_IFTYPE_VIRTUALLINK |
| 305 | && area->external_routing == OSPF_AREA_DEFAULT)) |
| 306 | LSDB_LOOP (OPAQUE_AS_LSDB (nbr->oi->ospf), rn, lsa) |
| 307 | ospf_db_summary_add (nbr, lsa); |
paul | 2d59836 | 2003-01-17 23:48:42 +0000 | [diff] [blame] | 308 | |
Dinesh Dutt | f687b62 | 2015-05-19 18:03:50 -0700 | [diff] [blame] | 309 | /* Send Link State Request. */ |
| 310 | if (nbr->t_ls_req == NULL) |
| 311 | ospf_ls_req_send (nbr); |
| 312 | |
paul | 2d59836 | 2003-01-17 23:48:42 +0000 | [diff] [blame] | 313 | return 0; |
| 314 | } |
| 315 | |
paul | 4dadc29 | 2005-05-06 21:37:42 +0000 | [diff] [blame] | 316 | static int |
paul | 2d59836 | 2003-01-17 23:48:42 +0000 | [diff] [blame] | 317 | nsm_exchange_done (struct ospf_neighbor *nbr) |
| 318 | { |
paul | 2d59836 | 2003-01-17 23:48:42 +0000 | [diff] [blame] | 319 | if (ospf_ls_request_isempty (nbr)) |
| 320 | return NSM_Full; |
Dinesh Dutt | f687b62 | 2015-05-19 18:03:50 -0700 | [diff] [blame] | 321 | |
| 322 | if (nbr->t_ls_req == NULL) |
| 323 | ospf_ls_req_send (nbr); |
| 324 | |
paul | 2d59836 | 2003-01-17 23:48:42 +0000 | [diff] [blame] | 325 | return NSM_Loading; |
| 326 | } |
| 327 | |
paul | 4dadc29 | 2005-05-06 21:37:42 +0000 | [diff] [blame] | 328 | static int |
paul | 2d59836 | 2003-01-17 23:48:42 +0000 | [diff] [blame] | 329 | nsm_adj_ok (struct ospf_neighbor *nbr) |
| 330 | { |
Paul Jakma | d7b0fb6 | 2006-07-04 13:35:24 +0000 | [diff] [blame] | 331 | int next_state = nbr->state; |
| 332 | int adj = nsm_should_adj (nbr); |
paul | 2d59836 | 2003-01-17 23:48:42 +0000 | [diff] [blame] | 333 | |
Paul Jakma | d7b0fb6 | 2006-07-04 13:35:24 +0000 | [diff] [blame] | 334 | if (nbr->state == NSM_TwoWay && adj == 1) |
paul | 2d59836 | 2003-01-17 23:48:42 +0000 | [diff] [blame] | 335 | next_state = NSM_ExStart; |
Paul Jakma | d7b0fb6 | 2006-07-04 13:35:24 +0000 | [diff] [blame] | 336 | else if (nbr->state >= NSM_ExStart && adj == 0) |
paul | 2d59836 | 2003-01-17 23:48:42 +0000 | [diff] [blame] | 337 | next_state = NSM_TwoWay; |
| 338 | |
| 339 | return next_state; |
| 340 | } |
| 341 | |
Paul Jakma | d1b1cd8 | 2006-07-04 13:50:44 +0000 | [diff] [blame] | 342 | /* Clear adjacency related state for a neighbour, intended where nbr |
| 343 | * transitions from > ExStart (i.e. a Full or forming adjacency) |
| 344 | * to <= ExStart. |
| 345 | */ |
| 346 | static void |
| 347 | nsm_clear_adj (struct ospf_neighbor *nbr) |
paul | 2d59836 | 2003-01-17 23:48:42 +0000 | [diff] [blame] | 348 | { |
| 349 | /* Clear Database Summary list. */ |
| 350 | if (!ospf_db_summary_isempty (nbr)) |
| 351 | ospf_db_summary_clear (nbr); |
| 352 | |
| 353 | /* Clear Link State Request list. */ |
| 354 | if (!ospf_ls_request_isempty (nbr)) |
| 355 | ospf_ls_request_delete_all (nbr); |
| 356 | |
| 357 | /* Clear Link State Retransmission list. */ |
| 358 | if (!ospf_ls_retransmit_isempty (nbr)) |
| 359 | ospf_ls_retransmit_clear (nbr); |
paul | 2d59836 | 2003-01-17 23:48:42 +0000 | [diff] [blame] | 360 | |
paul | 2d59836 | 2003-01-17 23:48:42 +0000 | [diff] [blame] | 361 | if (CHECK_FLAG (nbr->options, OSPF_OPTION_O)) |
| 362 | UNSET_FLAG (nbr->options, OSPF_OPTION_O); |
paul | 2d59836 | 2003-01-17 23:48:42 +0000 | [diff] [blame] | 363 | } |
| 364 | |
paul | 4dadc29 | 2005-05-06 21:37:42 +0000 | [diff] [blame] | 365 | static int |
paul | 2d59836 | 2003-01-17 23:48:42 +0000 | [diff] [blame] | 366 | nsm_kill_nbr (struct ospf_neighbor *nbr) |
| 367 | { |
Paul Jakma | 478aab9 | 2006-04-03 21:25:32 +0000 | [diff] [blame] | 368 | /* killing nbr_self is invalid */ |
Paul Jakma | 478aab9 | 2006-04-03 21:25:32 +0000 | [diff] [blame] | 369 | if (nbr == nbr->oi->nbr_self) |
Paul Jakma | 1f2c274 | 2006-07-10 07:45:13 +0000 | [diff] [blame] | 370 | { |
| 371 | assert (nbr != nbr->oi->nbr_self); |
| 372 | return 0; |
| 373 | } |
Paul Jakma | 478aab9 | 2006-04-03 21:25:32 +0000 | [diff] [blame] | 374 | |
paul | 2d59836 | 2003-01-17 23:48:42 +0000 | [diff] [blame] | 375 | if (nbr->oi->type == OSPF_IFTYPE_NBMA && nbr->nbr_nbma != NULL) |
| 376 | { |
| 377 | struct ospf_nbr_nbma *nbr_nbma = nbr->nbr_nbma; |
| 378 | |
| 379 | nbr_nbma->nbr = NULL; |
| 380 | nbr_nbma->state_change = nbr->state_change; |
| 381 | |
| 382 | nbr->nbr_nbma = NULL; |
| 383 | |
| 384 | OSPF_POLL_TIMER_ON (nbr_nbma->t_poll, ospf_poll_timer, |
| 385 | nbr_nbma->v_poll); |
| 386 | |
| 387 | if (IS_DEBUG_OSPF (nsm, NSM_EVENTS)) |
ajs | 2a42e28 | 2004-12-08 18:43:03 +0000 | [diff] [blame] | 388 | zlog_debug ("NSM[%s:%s]: Down (PollIntervalTimer scheduled)", |
paul | 2d59836 | 2003-01-17 23:48:42 +0000 | [diff] [blame] | 389 | IF_NAME (nbr->oi), inet_ntoa (nbr->address.u.prefix4)); |
| 390 | } |
| 391 | |
paul | 2d59836 | 2003-01-17 23:48:42 +0000 | [diff] [blame] | 392 | return 0; |
| 393 | } |
| 394 | |
paul | 2d59836 | 2003-01-17 23:48:42 +0000 | [diff] [blame] | 395 | /* Neighbor State Machine */ |
| 396 | struct { |
paul | 4dadc29 | 2005-05-06 21:37:42 +0000 | [diff] [blame] | 397 | int (*func) (struct ospf_neighbor *); |
paul | 2d59836 | 2003-01-17 23:48:42 +0000 | [diff] [blame] | 398 | int next_state; |
| 399 | } NSM [OSPF_NSM_STATE_MAX][OSPF_NSM_EVENT_MAX] = |
| 400 | { |
| 401 | { |
| 402 | /* DependUpon: dummy state. */ |
Paul Jakma | 539e152 | 2006-07-11 17:49:22 +0000 | [diff] [blame] | 403 | { NULL, NSM_DependUpon }, /* NoEvent */ |
Paul Jakma | 57c5c65 | 2010-01-07 06:12:53 +0000 | [diff] [blame] | 404 | { NULL, NSM_DependUpon }, /* PacketReceived */ |
Paul Jakma | 539e152 | 2006-07-11 17:49:22 +0000 | [diff] [blame] | 405 | { NULL, NSM_DependUpon }, /* Start */ |
| 406 | { NULL, NSM_DependUpon }, /* 2-WayReceived */ |
| 407 | { NULL, NSM_DependUpon }, /* NegotiationDone */ |
| 408 | { NULL, NSM_DependUpon }, /* ExchangeDone */ |
| 409 | { NULL, NSM_DependUpon }, /* BadLSReq */ |
| 410 | { NULL, NSM_DependUpon }, /* LoadingDone */ |
| 411 | { NULL, NSM_DependUpon }, /* AdjOK? */ |
| 412 | { NULL, NSM_DependUpon }, /* SeqNumberMismatch */ |
| 413 | { NULL, NSM_DependUpon }, /* 1-WayReceived */ |
| 414 | { NULL, NSM_DependUpon }, /* KillNbr */ |
| 415 | { NULL, NSM_DependUpon }, /* InactivityTimer */ |
| 416 | { NULL, NSM_DependUpon }, /* LLDown */ |
paul | 2d59836 | 2003-01-17 23:48:42 +0000 | [diff] [blame] | 417 | }, |
| 418 | { |
Paul Jakma | 1f2c274 | 2006-07-10 07:45:13 +0000 | [diff] [blame] | 419 | /* Deleted: dummy state. */ |
Paul Jakma | 539e152 | 2006-07-11 17:49:22 +0000 | [diff] [blame] | 420 | { NULL, NSM_Deleted }, /* NoEvent */ |
Paul Jakma | 57c5c65 | 2010-01-07 06:12:53 +0000 | [diff] [blame] | 421 | { NULL, NSM_Deleted }, /* PacketReceived */ |
Paul Jakma | 539e152 | 2006-07-11 17:49:22 +0000 | [diff] [blame] | 422 | { NULL, NSM_Deleted }, /* Start */ |
| 423 | { NULL, NSM_Deleted }, /* 2-WayReceived */ |
| 424 | { NULL, NSM_Deleted }, /* NegotiationDone */ |
| 425 | { NULL, NSM_Deleted }, /* ExchangeDone */ |
| 426 | { NULL, NSM_Deleted }, /* BadLSReq */ |
| 427 | { NULL, NSM_Deleted }, /* LoadingDone */ |
| 428 | { NULL, NSM_Deleted }, /* AdjOK? */ |
| 429 | { NULL, NSM_Deleted }, /* SeqNumberMismatch */ |
| 430 | { NULL, NSM_Deleted }, /* 1-WayReceived */ |
| 431 | { NULL, NSM_Deleted }, /* KillNbr */ |
| 432 | { NULL, NSM_Deleted }, /* InactivityTimer */ |
| 433 | { NULL, NSM_Deleted }, /* LLDown */ |
Paul Jakma | 1f2c274 | 2006-07-10 07:45:13 +0000 | [diff] [blame] | 434 | }, |
| 435 | { |
paul | 2d59836 | 2003-01-17 23:48:42 +0000 | [diff] [blame] | 436 | /* Down: */ |
Paul Jakma | 539e152 | 2006-07-11 17:49:22 +0000 | [diff] [blame] | 437 | { NULL, NSM_DependUpon }, /* NoEvent */ |
Paul Jakma | 57c5c65 | 2010-01-07 06:12:53 +0000 | [diff] [blame] | 438 | { nsm_packet_received, NSM_Init }, /* PacketReceived */ |
paul | 2d59836 | 2003-01-17 23:48:42 +0000 | [diff] [blame] | 439 | { nsm_start, NSM_Attempt }, /* Start */ |
Paul Jakma | 539e152 | 2006-07-11 17:49:22 +0000 | [diff] [blame] | 440 | { NULL, NSM_Down }, /* 2-WayReceived */ |
| 441 | { NULL, NSM_Down }, /* NegotiationDone */ |
| 442 | { NULL, NSM_Down }, /* ExchangeDone */ |
| 443 | { NULL, NSM_Down }, /* BadLSReq */ |
| 444 | { NULL, NSM_Down }, /* LoadingDone */ |
| 445 | { NULL, NSM_Down }, /* AdjOK? */ |
| 446 | { NULL, NSM_Down }, /* SeqNumberMismatch */ |
| 447 | { NULL, NSM_Down }, /* 1-WayReceived */ |
Paul Jakma | 1f2c274 | 2006-07-10 07:45:13 +0000 | [diff] [blame] | 448 | { nsm_kill_nbr, NSM_Deleted }, /* KillNbr */ |
Paul Jakma | 539e152 | 2006-07-11 17:49:22 +0000 | [diff] [blame] | 449 | { nsm_kill_nbr, NSM_Deleted }, /* InactivityTimer */ |
| 450 | { nsm_kill_nbr, NSM_Deleted }, /* LLDown */ |
paul | 2d59836 | 2003-01-17 23:48:42 +0000 | [diff] [blame] | 451 | }, |
| 452 | { |
| 453 | /* Attempt: */ |
Paul Jakma | 539e152 | 2006-07-11 17:49:22 +0000 | [diff] [blame] | 454 | { NULL, NSM_DependUpon }, /* NoEvent */ |
Paul Jakma | 57c5c65 | 2010-01-07 06:12:53 +0000 | [diff] [blame] | 455 | { nsm_packet_received, NSM_Init }, /* PacketReceived */ |
Paul Jakma | 539e152 | 2006-07-11 17:49:22 +0000 | [diff] [blame] | 456 | { NULL, NSM_Attempt }, /* Start */ |
| 457 | { NULL, NSM_Attempt }, /* 2-WayReceived */ |
| 458 | { NULL, NSM_Attempt }, /* NegotiationDone */ |
| 459 | { NULL, NSM_Attempt }, /* ExchangeDone */ |
| 460 | { NULL, NSM_Attempt }, /* BadLSReq */ |
| 461 | { NULL, NSM_Attempt }, /* LoadingDone */ |
| 462 | { NULL, NSM_Attempt }, /* AdjOK? */ |
| 463 | { NULL, NSM_Attempt }, /* SeqNumberMismatch */ |
| 464 | { NULL, NSM_Attempt }, /* 1-WayReceived */ |
Paul Jakma | 1f2c274 | 2006-07-10 07:45:13 +0000 | [diff] [blame] | 465 | { nsm_kill_nbr, NSM_Deleted }, /* KillNbr */ |
Paul Jakma | 539e152 | 2006-07-11 17:49:22 +0000 | [diff] [blame] | 466 | { nsm_kill_nbr, NSM_Deleted }, /* InactivityTimer */ |
| 467 | { nsm_kill_nbr, NSM_Deleted }, /* LLDown */ |
paul | 2d59836 | 2003-01-17 23:48:42 +0000 | [diff] [blame] | 468 | }, |
| 469 | { |
| 470 | /* Init: */ |
Paul Jakma | 539e152 | 2006-07-11 17:49:22 +0000 | [diff] [blame] | 471 | { NULL, NSM_DependUpon }, /* NoEvent */ |
Paul Jakma | 57c5c65 | 2010-01-07 06:12:53 +0000 | [diff] [blame] | 472 | { nsm_packet_received, NSM_Init }, /* PacketReceived */ |
Paul Jakma | 539e152 | 2006-07-11 17:49:22 +0000 | [diff] [blame] | 473 | { NULL, NSM_Init }, /* Start */ |
paul | 2d59836 | 2003-01-17 23:48:42 +0000 | [diff] [blame] | 474 | { nsm_twoway_received, NSM_DependUpon }, /* 2-WayReceived */ |
Paul Jakma | 539e152 | 2006-07-11 17:49:22 +0000 | [diff] [blame] | 475 | { NULL, NSM_Init }, /* NegotiationDone */ |
| 476 | { NULL, NSM_Init }, /* ExchangeDone */ |
| 477 | { NULL, NSM_Init }, /* BadLSReq */ |
| 478 | { NULL, NSM_Init }, /* LoadingDone */ |
| 479 | { NULL, NSM_Init }, /* AdjOK? */ |
| 480 | { NULL, NSM_Init }, /* SeqNumberMismatch */ |
| 481 | { NULL, NSM_Init }, /* 1-WayReceived */ |
Paul Jakma | 1f2c274 | 2006-07-10 07:45:13 +0000 | [diff] [blame] | 482 | { nsm_kill_nbr, NSM_Deleted }, /* KillNbr */ |
Paul Jakma | 539e152 | 2006-07-11 17:49:22 +0000 | [diff] [blame] | 483 | { nsm_kill_nbr, NSM_Deleted }, /* InactivityTimer */ |
| 484 | { nsm_kill_nbr, NSM_Deleted }, /* LLDown */ |
paul | 2d59836 | 2003-01-17 23:48:42 +0000 | [diff] [blame] | 485 | }, |
| 486 | { |
| 487 | /* 2-Way: */ |
Paul Jakma | 539e152 | 2006-07-11 17:49:22 +0000 | [diff] [blame] | 488 | { NULL, NSM_DependUpon }, /* NoEvent */ |
Paul Jakma | 57c5c65 | 2010-01-07 06:12:53 +0000 | [diff] [blame] | 489 | { nsm_packet_received, NSM_TwoWay }, /* HelloReceived */ |
Paul Jakma | 539e152 | 2006-07-11 17:49:22 +0000 | [diff] [blame] | 490 | { NULL, NSM_TwoWay }, /* Start */ |
| 491 | { NULL, NSM_TwoWay }, /* 2-WayReceived */ |
| 492 | { NULL, NSM_TwoWay }, /* NegotiationDone */ |
| 493 | { NULL, NSM_TwoWay }, /* ExchangeDone */ |
| 494 | { NULL, NSM_TwoWay }, /* BadLSReq */ |
| 495 | { NULL, NSM_TwoWay }, /* LoadingDone */ |
paul | 2d59836 | 2003-01-17 23:48:42 +0000 | [diff] [blame] | 496 | { nsm_adj_ok, NSM_DependUpon }, /* AdjOK? */ |
Paul Jakma | 539e152 | 2006-07-11 17:49:22 +0000 | [diff] [blame] | 497 | { NULL, NSM_TwoWay }, /* SeqNumberMismatch */ |
| 498 | { NULL, NSM_Init }, /* 1-WayReceived */ |
Paul Jakma | 1f2c274 | 2006-07-10 07:45:13 +0000 | [diff] [blame] | 499 | { nsm_kill_nbr, NSM_Deleted }, /* KillNbr */ |
Paul Jakma | 539e152 | 2006-07-11 17:49:22 +0000 | [diff] [blame] | 500 | { nsm_kill_nbr, NSM_Deleted }, /* InactivityTimer */ |
| 501 | { nsm_kill_nbr, NSM_Deleted }, /* LLDown */ |
paul | 2d59836 | 2003-01-17 23:48:42 +0000 | [diff] [blame] | 502 | }, |
| 503 | { |
| 504 | /* ExStart: */ |
Paul Jakma | 539e152 | 2006-07-11 17:49:22 +0000 | [diff] [blame] | 505 | { NULL, NSM_DependUpon }, /* NoEvent */ |
Paul Jakma | 57c5c65 | 2010-01-07 06:12:53 +0000 | [diff] [blame] | 506 | { nsm_packet_received, NSM_ExStart }, /* PacaketReceived */ |
Paul Jakma | 539e152 | 2006-07-11 17:49:22 +0000 | [diff] [blame] | 507 | { NULL, NSM_ExStart }, /* Start */ |
| 508 | { NULL, NSM_ExStart }, /* 2-WayReceived */ |
paul | 2d59836 | 2003-01-17 23:48:42 +0000 | [diff] [blame] | 509 | { nsm_negotiation_done, NSM_Exchange }, /* NegotiationDone */ |
Paul Jakma | 539e152 | 2006-07-11 17:49:22 +0000 | [diff] [blame] | 510 | { NULL, NSM_ExStart }, /* ExchangeDone */ |
| 511 | { NULL, NSM_ExStart }, /* BadLSReq */ |
| 512 | { NULL, NSM_ExStart }, /* LoadingDone */ |
paul | 2d59836 | 2003-01-17 23:48:42 +0000 | [diff] [blame] | 513 | { nsm_adj_ok, NSM_DependUpon }, /* AdjOK? */ |
Paul Jakma | 539e152 | 2006-07-11 17:49:22 +0000 | [diff] [blame] | 514 | { NULL, NSM_ExStart }, /* SeqNumberMismatch */ |
| 515 | { NULL, NSM_Init }, /* 1-WayReceived */ |
Paul Jakma | 1f2c274 | 2006-07-10 07:45:13 +0000 | [diff] [blame] | 516 | { nsm_kill_nbr, NSM_Deleted }, /* KillNbr */ |
Paul Jakma | 539e152 | 2006-07-11 17:49:22 +0000 | [diff] [blame] | 517 | { nsm_kill_nbr, NSM_Deleted }, /* InactivityTimer */ |
| 518 | { nsm_kill_nbr, NSM_Deleted }, /* LLDown */ |
paul | 2d59836 | 2003-01-17 23:48:42 +0000 | [diff] [blame] | 519 | }, |
| 520 | { |
| 521 | /* Exchange: */ |
Paul Jakma | 539e152 | 2006-07-11 17:49:22 +0000 | [diff] [blame] | 522 | { NULL, NSM_DependUpon }, /* NoEvent */ |
Paul Jakma | 57c5c65 | 2010-01-07 06:12:53 +0000 | [diff] [blame] | 523 | { nsm_packet_received, NSM_Exchange }, /* PacketReceived */ |
Paul Jakma | 539e152 | 2006-07-11 17:49:22 +0000 | [diff] [blame] | 524 | { NULL, NSM_Exchange }, /* Start */ |
| 525 | { NULL, NSM_Exchange }, /* 2-WayReceived */ |
| 526 | { NULL, NSM_Exchange }, /* NegotiationDone */ |
paul | 2d59836 | 2003-01-17 23:48:42 +0000 | [diff] [blame] | 527 | { nsm_exchange_done, NSM_DependUpon }, /* ExchangeDone */ |
Paul Jakma | 539e152 | 2006-07-11 17:49:22 +0000 | [diff] [blame] | 528 | { NULL, NSM_ExStart }, /* BadLSReq */ |
| 529 | { NULL, NSM_Exchange }, /* LoadingDone */ |
paul | 2d59836 | 2003-01-17 23:48:42 +0000 | [diff] [blame] | 530 | { nsm_adj_ok, NSM_DependUpon }, /* AdjOK? */ |
Paul Jakma | 539e152 | 2006-07-11 17:49:22 +0000 | [diff] [blame] | 531 | { NULL, NSM_ExStart }, /* SeqNumberMismatch */ |
| 532 | { NULL, NSM_Init }, /* 1-WayReceived */ |
Paul Jakma | 1f2c274 | 2006-07-10 07:45:13 +0000 | [diff] [blame] | 533 | { nsm_kill_nbr, NSM_Deleted }, /* KillNbr */ |
Paul Jakma | 539e152 | 2006-07-11 17:49:22 +0000 | [diff] [blame] | 534 | { nsm_kill_nbr, NSM_Deleted }, /* InactivityTimer */ |
| 535 | { nsm_kill_nbr, NSM_Deleted }, /* LLDown */ |
paul | 2d59836 | 2003-01-17 23:48:42 +0000 | [diff] [blame] | 536 | }, |
| 537 | { |
| 538 | /* Loading: */ |
Paul Jakma | 539e152 | 2006-07-11 17:49:22 +0000 | [diff] [blame] | 539 | { NULL, NSM_DependUpon }, /* NoEvent */ |
Paul Jakma | 57c5c65 | 2010-01-07 06:12:53 +0000 | [diff] [blame] | 540 | { nsm_packet_received, NSM_Loading }, /* PacketReceived */ |
Paul Jakma | 539e152 | 2006-07-11 17:49:22 +0000 | [diff] [blame] | 541 | { NULL, NSM_Loading }, /* Start */ |
| 542 | { NULL, NSM_Loading }, /* 2-WayReceived */ |
| 543 | { NULL, NSM_Loading }, /* NegotiationDone */ |
| 544 | { NULL, NSM_Loading }, /* ExchangeDone */ |
| 545 | { NULL, NSM_ExStart }, /* BadLSReq */ |
| 546 | { NULL, NSM_Full }, /* LoadingDone */ |
paul | 2d59836 | 2003-01-17 23:48:42 +0000 | [diff] [blame] | 547 | { nsm_adj_ok, NSM_DependUpon }, /* AdjOK? */ |
Paul Jakma | 539e152 | 2006-07-11 17:49:22 +0000 | [diff] [blame] | 548 | { NULL, NSM_ExStart }, /* SeqNumberMismatch */ |
| 549 | { NULL, NSM_Init }, /* 1-WayReceived */ |
Paul Jakma | 1f2c274 | 2006-07-10 07:45:13 +0000 | [diff] [blame] | 550 | { nsm_kill_nbr, NSM_Deleted }, /* KillNbr */ |
Paul Jakma | 539e152 | 2006-07-11 17:49:22 +0000 | [diff] [blame] | 551 | { nsm_kill_nbr, NSM_Deleted }, /* InactivityTimer */ |
| 552 | { nsm_kill_nbr, NSM_Deleted }, /* LLDown */ |
paul | 2d59836 | 2003-01-17 23:48:42 +0000 | [diff] [blame] | 553 | }, |
| 554 | { /* Full: */ |
Paul Jakma | 539e152 | 2006-07-11 17:49:22 +0000 | [diff] [blame] | 555 | { NULL, NSM_DependUpon }, /* NoEvent */ |
Paul Jakma | 57c5c65 | 2010-01-07 06:12:53 +0000 | [diff] [blame] | 556 | { nsm_packet_received, NSM_Full }, /* PacketReceived */ |
Paul Jakma | 539e152 | 2006-07-11 17:49:22 +0000 | [diff] [blame] | 557 | { NULL, NSM_Full }, /* Start */ |
| 558 | { NULL, NSM_Full }, /* 2-WayReceived */ |
| 559 | { NULL, NSM_Full }, /* NegotiationDone */ |
| 560 | { NULL, NSM_Full }, /* ExchangeDone */ |
| 561 | { NULL, NSM_ExStart }, /* BadLSReq */ |
| 562 | { NULL, NSM_Full }, /* LoadingDone */ |
paul | 2d59836 | 2003-01-17 23:48:42 +0000 | [diff] [blame] | 563 | { nsm_adj_ok, NSM_DependUpon }, /* AdjOK? */ |
Paul Jakma | 539e152 | 2006-07-11 17:49:22 +0000 | [diff] [blame] | 564 | { NULL, NSM_ExStart }, /* SeqNumberMismatch */ |
| 565 | { NULL, NSM_Init }, /* 1-WayReceived */ |
Paul Jakma | 1f2c274 | 2006-07-10 07:45:13 +0000 | [diff] [blame] | 566 | { nsm_kill_nbr, NSM_Deleted }, /* KillNbr */ |
Paul Jakma | 539e152 | 2006-07-11 17:49:22 +0000 | [diff] [blame] | 567 | { nsm_kill_nbr, NSM_Deleted }, /* InactivityTimer */ |
| 568 | { nsm_kill_nbr, NSM_Deleted }, /* LLDown */ |
paul | 2d59836 | 2003-01-17 23:48:42 +0000 | [diff] [blame] | 569 | }, |
| 570 | }; |
| 571 | |
Paul Jakma | 30a2231 | 2008-08-15 14:05:22 +0100 | [diff] [blame] | 572 | static const char *ospf_nsm_event_str[] = |
paul | 2d59836 | 2003-01-17 23:48:42 +0000 | [diff] [blame] | 573 | { |
| 574 | "NoEvent", |
Paul Jakma | 57c5c65 | 2010-01-07 06:12:53 +0000 | [diff] [blame] | 575 | "PacketReceived", |
paul | 2d59836 | 2003-01-17 23:48:42 +0000 | [diff] [blame] | 576 | "Start", |
| 577 | "2-WayReceived", |
| 578 | "NegotiationDone", |
| 579 | "ExchangeDone", |
| 580 | "BadLSReq", |
| 581 | "LoadingDone", |
| 582 | "AdjOK?", |
| 583 | "SeqNumberMismatch", |
| 584 | "1-WayReceived", |
| 585 | "KillNbr", |
| 586 | "InactivityTimer", |
| 587 | "LLDown", |
| 588 | }; |
| 589 | |
Paul Jakma | 3d63f38 | 2006-07-11 17:52:53 +0000 | [diff] [blame] | 590 | static void |
| 591 | nsm_notice_state_change (struct ospf_neighbor *nbr, int next_state, int event) |
| 592 | { |
| 593 | /* Logging change of status. */ |
| 594 | if (IS_DEBUG_OSPF (nsm, NSM_STATUS)) |
| 595 | zlog_debug ("NSM[%s:%s]: State change %s -> %s (%s)", |
| 596 | IF_NAME (nbr->oi), inet_ntoa (nbr->router_id), |
| 597 | LOOKUP (ospf_nsm_state_msg, nbr->state), |
| 598 | LOOKUP (ospf_nsm_state_msg, next_state), |
| 599 | ospf_nsm_event_str [event]); |
| 600 | |
| 601 | /* Optionally notify about adjacency changes */ |
| 602 | if (CHECK_FLAG(nbr->oi->ospf->config, OSPF_LOG_ADJACENCY_CHANGES) && |
| 603 | (CHECK_FLAG(nbr->oi->ospf->config, OSPF_LOG_ADJACENCY_DETAIL) || |
| 604 | (next_state == NSM_Full) || (next_state < nbr->state))) |
| 605 | zlog_notice("AdjChg: Nbr %s on %s: %s -> %s (%s)", |
| 606 | inet_ntoa (nbr->router_id), IF_NAME (nbr->oi), |
| 607 | LOOKUP (ospf_nsm_state_msg, nbr->state), |
| 608 | LOOKUP (ospf_nsm_state_msg, next_state), |
| 609 | ospf_nsm_event_str [event]); |
| 610 | |
Paul Jakma | 3fed416 | 2006-07-25 20:44:12 +0000 | [diff] [blame] | 611 | /* Advance in NSM */ |
| 612 | if (next_state > nbr->state) |
Paul Jakma | 2518efd | 2006-08-27 06:49:29 +0000 | [diff] [blame] | 613 | nbr->ts_last_progress = recent_relative_time (); |
Paul Jakma | 3fed416 | 2006-07-25 20:44:12 +0000 | [diff] [blame] | 614 | else /* regression in NSM */ |
| 615 | { |
Paul Jakma | 2518efd | 2006-08-27 06:49:29 +0000 | [diff] [blame] | 616 | nbr->ts_last_regress = recent_relative_time (); |
Paul Jakma | 3fed416 | 2006-07-25 20:44:12 +0000 | [diff] [blame] | 617 | nbr->last_regress_str = ospf_nsm_event_str [event]; |
| 618 | } |
Paul Jakma | 90c3317 | 2006-07-11 17:57:25 +0000 | [diff] [blame] | 619 | |
Paul Jakma | 3d63f38 | 2006-07-11 17:52:53 +0000 | [diff] [blame] | 620 | } |
| 621 | |
Andrew Certain | de54b26 | 2012-12-04 13:40:58 -0800 | [diff] [blame] | 622 | static void |
paul | 2d59836 | 2003-01-17 23:48:42 +0000 | [diff] [blame] | 623 | nsm_change_state (struct ospf_neighbor *nbr, int state) |
| 624 | { |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 625 | struct ospf_interface *oi = nbr->oi; |
paul | 2d59836 | 2003-01-17 23:48:42 +0000 | [diff] [blame] | 626 | struct ospf_area *vl_area = NULL; |
| 627 | u_char old_state; |
| 628 | int x; |
| 629 | int force = 1; |
| 630 | |
paul | 2d59836 | 2003-01-17 23:48:42 +0000 | [diff] [blame] | 631 | /* Preserve old status. */ |
| 632 | old_state = nbr->state; |
| 633 | |
| 634 | /* Change to new status. */ |
| 635 | nbr->state = state; |
| 636 | |
| 637 | /* Statistics. */ |
| 638 | nbr->state_change++; |
| 639 | |
paul | 2d59836 | 2003-01-17 23:48:42 +0000 | [diff] [blame] | 640 | if (oi->type == OSPF_IFTYPE_VIRTUALLINK) |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 641 | vl_area = ospf_area_lookup_by_area_id (oi->ospf, oi->vl_data->vl_area_id); |
Andrew J. Schorr | d7e60dd | 2006-06-29 20:20:52 +0000 | [diff] [blame] | 642 | |
Christian Franke | 7a9d983 | 2013-07-10 11:56:18 +0000 | [diff] [blame] | 643 | /* Generate NeighborChange ISM event. |
| 644 | * |
| 645 | * In response to NeighborChange, DR election is rerun. The information |
| 646 | * from the election process is required by the router-lsa construction. |
| 647 | * |
| 648 | * Therefore, trigger the event prior to refreshing the LSAs. */ |
| 649 | switch (oi->state) { |
| 650 | case ISM_DROther: |
| 651 | case ISM_Backup: |
| 652 | case ISM_DR: |
| 653 | if ((old_state < NSM_TwoWay && state >= NSM_TwoWay) || |
| 654 | (old_state >= NSM_TwoWay && state < NSM_TwoWay)) |
| 655 | OSPF_ISM_EVENT_EXECUTE (oi, ISM_NeighborChange); |
| 656 | break; |
| 657 | default: |
| 658 | /* ISM_PointToPoint -> ISM_Down, ISM_Loopback -> ISM_Down, etc. */ |
| 659 | break; |
| 660 | } |
| 661 | |
paul | 2d59836 | 2003-01-17 23:48:42 +0000 | [diff] [blame] | 662 | /* One of the neighboring routers changes to/from the FULL state. */ |
| 663 | if ((old_state != NSM_Full && state == NSM_Full) || |
| 664 | (old_state == NSM_Full && state != NSM_Full)) |
ajs | 3aa8d5f | 2004-12-11 18:00:06 +0000 | [diff] [blame] | 665 | { |
paul | 2d59836 | 2003-01-17 23:48:42 +0000 | [diff] [blame] | 666 | if (state == NSM_Full) |
| 667 | { |
| 668 | oi->full_nbrs++; |
| 669 | oi->area->full_nbrs++; |
| 670 | |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 671 | ospf_check_abr_status (oi->ospf); |
paul | 2d59836 | 2003-01-17 23:48:42 +0000 | [diff] [blame] | 672 | |
| 673 | if (oi->type == OSPF_IFTYPE_VIRTUALLINK && vl_area) |
| 674 | if (++vl_area->full_vls == 1) |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 675 | ospf_schedule_abr_task (oi->ospf); |
paul | 2d59836 | 2003-01-17 23:48:42 +0000 | [diff] [blame] | 676 | |
| 677 | /* kevinm: refresh any redistributions */ |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 678 | for (x = ZEBRA_ROUTE_SYSTEM; x < ZEBRA_ROUTE_MAX; x++) |
| 679 | { |
| 680 | if (x == ZEBRA_ROUTE_OSPF || x == ZEBRA_ROUTE_OSPF6) |
| 681 | continue; |
| 682 | ospf_external_lsa_refresh_type (oi->ospf, x, force); |
| 683 | } |
Daniel Ng | 9fd4958 | 2008-08-13 20:37:52 +0100 | [diff] [blame] | 684 | /* XXX: Clearly some thing is wrong with refresh of external LSAs |
| 685 | * this added to hack around defaults not refreshing after a timer |
| 686 | * jump. |
| 687 | */ |
| 688 | ospf_external_lsa_refresh_default (oi->ospf); |
paul | 2d59836 | 2003-01-17 23:48:42 +0000 | [diff] [blame] | 689 | } |
| 690 | else |
| 691 | { |
| 692 | oi->full_nbrs--; |
| 693 | oi->area->full_nbrs--; |
| 694 | |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 695 | ospf_check_abr_status (oi->ospf); |
paul | 2d59836 | 2003-01-17 23:48:42 +0000 | [diff] [blame] | 696 | |
| 697 | if (oi->type == OSPF_IFTYPE_VIRTUALLINK && vl_area) |
| 698 | if (vl_area->full_vls > 0) |
| 699 | if (--vl_area->full_vls == 0) |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 700 | ospf_schedule_abr_task (oi->ospf); |
paul | 2d59836 | 2003-01-17 23:48:42 +0000 | [diff] [blame] | 701 | } |
| 702 | |
ajs | 3aa8d5f | 2004-12-11 18:00:06 +0000 | [diff] [blame] | 703 | zlog_info ("nsm_change_state(%s, %s -> %s): " |
| 704 | "scheduling new router-LSA origination", |
| 705 | inet_ntoa (nbr->router_id), |
| 706 | LOOKUP(ospf_nsm_state_msg, old_state), |
| 707 | LOOKUP(ospf_nsm_state_msg, state)); |
paul | 2d59836 | 2003-01-17 23:48:42 +0000 | [diff] [blame] | 708 | |
Paul Jakma | c363d38 | 2010-01-24 22:42:13 +0000 | [diff] [blame] | 709 | ospf_router_lsa_update_area (oi->area); |
paul | 2d59836 | 2003-01-17 23:48:42 +0000 | [diff] [blame] | 710 | |
| 711 | if (oi->type == OSPF_IFTYPE_VIRTUALLINK) |
| 712 | { |
| 713 | struct ospf_area *vl_area = |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 714 | 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] | 715 | |
| 716 | if (vl_area) |
Paul Jakma | c363d38 | 2010-01-24 22:42:13 +0000 | [diff] [blame] | 717 | ospf_router_lsa_update_area (vl_area); |
paul | 2d59836 | 2003-01-17 23:48:42 +0000 | [diff] [blame] | 718 | } |
| 719 | |
| 720 | /* Originate network-LSA. */ |
| 721 | if (oi->state == ISM_DR) |
| 722 | { |
| 723 | if (oi->network_lsa_self && oi->full_nbrs == 0) |
| 724 | { |
| 725 | ospf_lsa_flush_area (oi->network_lsa_self, oi->area); |
Paul Jakma | 1fe6ed3 | 2006-07-26 09:37:26 +0000 | [diff] [blame] | 726 | ospf_lsa_unlock (&oi->network_lsa_self); |
paul | 2d59836 | 2003-01-17 23:48:42 +0000 | [diff] [blame] | 727 | oi->network_lsa_self = NULL; |
paul | 2d59836 | 2003-01-17 23:48:42 +0000 | [diff] [blame] | 728 | } |
| 729 | else |
Paul Jakma | c363d38 | 2010-01-24 22:42:13 +0000 | [diff] [blame] | 730 | ospf_network_lsa_update (oi); |
paul | 2d59836 | 2003-01-17 23:48:42 +0000 | [diff] [blame] | 731 | } |
| 732 | } |
| 733 | |
paul | 2d59836 | 2003-01-17 23:48:42 +0000 | [diff] [blame] | 734 | ospf_opaque_nsm_change (nbr, old_state); |
paul | 2d59836 | 2003-01-17 23:48:42 +0000 | [diff] [blame] | 735 | |
Paul Jakma | d1b1cd8 | 2006-07-04 13:50:44 +0000 | [diff] [blame] | 736 | /* State changes from > ExStart to <= ExStart should clear any Exchange |
| 737 | * or Full/LSA Update related lists and state. |
| 738 | * Potential causal events: BadLSReq, SeqNumberMismatch, AdjOK? |
Paul Jakma | d1b1cd8 | 2006-07-04 13:50:44 +0000 | [diff] [blame] | 739 | */ |
Paul Jakma | 539e152 | 2006-07-11 17:49:22 +0000 | [diff] [blame] | 740 | if ((old_state > NSM_ExStart) && (state <= NSM_ExStart)) |
Paul Jakma | d1b1cd8 | 2006-07-04 13:50:44 +0000 | [diff] [blame] | 741 | nsm_clear_adj (nbr); |
| 742 | |
paul | 2d59836 | 2003-01-17 23:48:42 +0000 | [diff] [blame] | 743 | /* Start DD exchange protocol */ |
| 744 | if (state == NSM_ExStart) |
| 745 | { |
| 746 | if (nbr->dd_seqnum == 0) |
Paul Jakma | 2518efd | 2006-08-27 06:49:29 +0000 | [diff] [blame] | 747 | nbr->dd_seqnum = quagga_time (NULL); |
paul | 2d59836 | 2003-01-17 23:48:42 +0000 | [diff] [blame] | 748 | else |
| 749 | nbr->dd_seqnum++; |
| 750 | |
| 751 | nbr->dd_flags = OSPF_DD_FLAG_I|OSPF_DD_FLAG_M|OSPF_DD_FLAG_MS; |
| 752 | ospf_db_desc_send (nbr); |
| 753 | } |
| 754 | |
| 755 | /* clear cryptographic sequence number */ |
| 756 | if (state == NSM_Down) |
| 757 | nbr->crypt_seqnum = 0; |
| 758 | |
paul | 2d59836 | 2003-01-17 23:48:42 +0000 | [diff] [blame] | 759 | /* Preserve old status? */ |
| 760 | } |
| 761 | |
| 762 | /* Execute NSM event process. */ |
| 763 | int |
| 764 | ospf_nsm_event (struct thread *thread) |
| 765 | { |
| 766 | int event; |
| 767 | int next_state; |
| 768 | struct ospf_neighbor *nbr; |
paul | 2d59836 | 2003-01-17 23:48:42 +0000 | [diff] [blame] | 769 | |
| 770 | nbr = THREAD_ARG (thread); |
| 771 | event = THREAD_VAL (thread); |
paul | 2d59836 | 2003-01-17 23:48:42 +0000 | [diff] [blame] | 772 | |
Paul Jakma | 3d63f38 | 2006-07-11 17:52:53 +0000 | [diff] [blame] | 773 | if (IS_DEBUG_OSPF (nsm, NSM_EVENTS)) |
| 774 | zlog_debug ("NSM[%s:%s]: %s (%s)", IF_NAME (nbr->oi), |
| 775 | inet_ntoa (nbr->router_id), |
| 776 | LOOKUP (ospf_nsm_state_msg, nbr->state), |
| 777 | ospf_nsm_event_str [event]); |
| 778 | |
Paul Jakma | 539e152 | 2006-07-11 17:49:22 +0000 | [diff] [blame] | 779 | next_state = NSM [nbr->state][event].next_state; |
paul | 2d59836 | 2003-01-17 23:48:42 +0000 | [diff] [blame] | 780 | |
Paul Jakma | 539e152 | 2006-07-11 17:49:22 +0000 | [diff] [blame] | 781 | /* Call function. */ |
| 782 | if (NSM [nbr->state][event].func != NULL) |
Paul Jakma | ba0beb4 | 2006-07-04 13:44:19 +0000 | [diff] [blame] | 783 | { |
Paul Jakma | 539e152 | 2006-07-11 17:49:22 +0000 | [diff] [blame] | 784 | int func_state = (*(NSM [nbr->state][event].func))(nbr); |
Paul Jakma | ba0beb4 | 2006-07-04 13:44:19 +0000 | [diff] [blame] | 785 | |
Paul Jakma | 539e152 | 2006-07-11 17:49:22 +0000 | [diff] [blame] | 786 | if (NSM [nbr->state][event].next_state == NSM_DependUpon) |
| 787 | next_state = func_state; |
| 788 | else if (func_state) |
| 789 | { |
| 790 | /* There's a mismatch between the FSM tables and what an FSM |
| 791 | * action/state-change function returned. State changes which |
| 792 | * do not have conditional/DependUpon next-states should not |
| 793 | * try set next_state. |
| 794 | */ |
| 795 | zlog_warn ("NSM[%s:%s]: %s (%s): " |
| 796 | "Warning: action tried to change next_state to %s", |
| 797 | IF_NAME (nbr->oi), inet_ntoa (nbr->router_id), |
| 798 | LOOKUP (ospf_nsm_state_msg, nbr->state), |
| 799 | ospf_nsm_event_str [event], |
| 800 | LOOKUP (ospf_nsm_state_msg, func_state)); |
| 801 | } |
Paul Jakma | ba0beb4 | 2006-07-04 13:44:19 +0000 | [diff] [blame] | 802 | } |
paul | 2d59836 | 2003-01-17 23:48:42 +0000 | [diff] [blame] | 803 | |
Paul Jakma | 539e152 | 2006-07-11 17:49:22 +0000 | [diff] [blame] | 804 | assert (next_state != NSM_DependUpon); |
| 805 | |
paul | 2d59836 | 2003-01-17 23:48:42 +0000 | [diff] [blame] | 806 | /* If state is changed. */ |
| 807 | if (next_state != nbr->state) |
Paul Jakma | 3d63f38 | 2006-07-11 17:52:53 +0000 | [diff] [blame] | 808 | { |
| 809 | nsm_notice_state_change (nbr, next_state, event); |
Fernando Soto | b640439 | 2015-05-11 20:52:00 +0000 | [diff] [blame] | 810 | #ifdef HAVE_SNMP |
| 811 | int send_trap_virt = 0; |
| 812 | int send_trap = 0; |
| 813 | /* Terminal state or regression */ |
| 814 | if ((next_state == NSM_Full) |
| 815 | || (next_state == NSM_TwoWay) |
| 816 | || (next_state < nbr->state)) |
| 817 | { |
| 818 | /* ospfVirtNbrStateChange */ |
| 819 | if (nbr->oi->type == OSPF_IFTYPE_VIRTUALLINK) |
| 820 | send_trap_virt = 1; |
| 821 | /* ospfNbrStateChange trap */ |
| 822 | else |
| 823 | /* To/From FULL, only managed by DR */ |
| 824 | if (((next_state != NSM_Full) && (nbr->state != NSM_Full)) |
| 825 | || (nbr->oi->state == ISM_DR)) |
| 826 | send_trap = 1; |
| 827 | } |
| 828 | #endif |
Paul Jakma | 3d63f38 | 2006-07-11 17:52:53 +0000 | [diff] [blame] | 829 | nsm_change_state (nbr, next_state); |
Fernando Soto | b640439 | 2015-05-11 20:52:00 +0000 | [diff] [blame] | 830 | |
| 831 | #ifdef HAVE_SNMP |
| 832 | if (send_trap_virt) { |
| 833 | ospfTrapVirtNbrStateChange(nbr); |
| 834 | } else if (send_trap) { |
| 835 | ospfTrapNbrStateChange(nbr); |
| 836 | } |
| 837 | #endif |
Paul Jakma | 3d63f38 | 2006-07-11 17:52:53 +0000 | [diff] [blame] | 838 | } |
paul | 2d59836 | 2003-01-17 23:48:42 +0000 | [diff] [blame] | 839 | |
| 840 | /* Make sure timer is set. */ |
| 841 | nsm_timer_set (nbr); |
| 842 | |
Paul Jakma | 1f2c274 | 2006-07-10 07:45:13 +0000 | [diff] [blame] | 843 | /* When event is NSM_KillNbr, InactivityTimer or LLDown, the neighbor |
| 844 | * is deleted. |
| 845 | * |
| 846 | * Rather than encode knowledge here of which events lead to NBR |
| 847 | * delete, we take our cue from the NSM table, via the dummy |
| 848 | * 'Deleted' neighbour state. |
| 849 | */ |
| 850 | if (nbr->state == NSM_Deleted) |
| 851 | ospf_nbr_delete (nbr); |
| 852 | |
paul | 2d59836 | 2003-01-17 23:48:42 +0000 | [diff] [blame] | 853 | return 0; |
| 854 | } |
| 855 | |
| 856 | /* Check loading state. */ |
| 857 | void |
| 858 | ospf_check_nbr_loading (struct ospf_neighbor *nbr) |
| 859 | { |
| 860 | if (nbr->state == NSM_Loading) |
| 861 | { |
| 862 | if (ospf_ls_request_isempty (nbr)) |
| 863 | OSPF_NSM_EVENT_SCHEDULE (nbr, NSM_LoadingDone); |
| 864 | else if (nbr->ls_req_last == NULL) |
| 865 | ospf_ls_req_event (nbr); |
| 866 | } |
| 867 | } |