blob: 26f02100a0a524028aafd2ec37f14e9963a87516 [file] [log] [blame]
jardineb5d44e2003-12-23 08:09:43 +00001/*
2 * IS-IS Rout(e)ing protocol - isis_events.h
3 *
4 * Copyright (C) 2001,2002 Sampo Saaristo
5 * Tampere University of Technology
6 * Institute of Communications Engineering
7 *
8 * This program is free software; you can redistribute it and/or modify it
9 * under the terms of the GNU General Public Licenseas published by the Free
10 * Software Foundation; either version 2 of the License, or (at your option)
11 * any later version.
12 *
13 * This program is distributed in the hope that it will be useful,but WITHOUT
14 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
15 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
16 * more details.
17
18 * You should have received a copy of the GNU General Public License along
19 * with this program; if not, write to the Free Software Foundation, Inc.,
20 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
21 */
jardineb5d44e2003-12-23 08:09:43 +000022#include <zebra.h>
jardineb5d44e2003-12-23 08:09:43 +000023
24#include "log.h"
25#include "memory.h"
26#include "if.h"
27#include "linklist.h"
28#include "command.h"
29#include "thread.h"
30#include "hash.h"
31#include "prefix.h"
32#include "stream.h"
Josh Bailey3f045a02012-03-24 08:35:20 -070033#include "table.h"
jardineb5d44e2003-12-23 08:09:43 +000034
35#include "isisd/dict.h"
36#include "isisd/include-netbsd/iso.h"
37#include "isisd/isis_constants.h"
38#include "isisd/isis_common.h"
Josh Bailey3f045a02012-03-24 08:35:20 -070039#include "isisd/isis_flags.h"
jardineb5d44e2003-12-23 08:09:43 +000040#include "isisd/isis_circuit.h"
41#include "isisd/isis_tlv.h"
42#include "isisd/isis_lsp.h"
43#include "isisd/isis_pdu.h"
44#include "isisd/isis_network.h"
45#include "isisd/isis_misc.h"
46#include "isisd/isis_constants.h"
47#include "isisd/isis_adjacency.h"
48#include "isisd/isis_dr.h"
jardineb5d44e2003-12-23 08:09:43 +000049#include "isisd/isisd.h"
50#include "isisd/isis_csm.h"
51#include "isisd/isis_events.h"
52#include "isisd/isis_spf.h"
53
jardineb5d44e2003-12-23 08:09:43 +000054/* debug isis-spf spf-events
55 4w4d: ISIS-Spf (tlt): L2 SPF needed, new adjacency, from 0x609229F4
56 4w4d: ISIS-Spf (tlt): L2, 0000.0000.0042.01-00 TLV contents changed, code 0x2
57 4w4d: ISIS-Spf (tlt): L2, new LSP 0 DEAD.BEEF.0043.00-00
58 4w5d: ISIS-Spf (tlt): L1 SPF needed, periodic SPF, from 0x6091C844
59 4w5d: ISIS-Spf (tlt): L2 SPF needed, periodic SPF, from 0x6091C844
60*/
61
hassof390d2c2004-09-10 20:48:21 +000062void
Josh Bailey3f045a02012-03-24 08:35:20 -070063isis_event_circuit_state_change (struct isis_circuit *circuit,
64 struct isis_area *area, int up)
jardineb5d44e2003-12-23 08:09:43 +000065{
jardineb5d44e2003-12-23 08:09:43 +000066 area->circuit_state_changes++;
hassof390d2c2004-09-10 20:48:21 +000067
68 if (isis->debugs & DEBUG_EVENTS)
Josh Bailey3f045a02012-03-24 08:35:20 -070069 zlog_debug ("ISIS-Evt (%s) circuit %s", area->area_tag,
70 up ? "up" : "down");
hassof390d2c2004-09-10 20:48:21 +000071
jardineb5d44e2003-12-23 08:09:43 +000072 /*
73 * Regenerate LSPs this affects
74 */
Josh Bailey3f045a02012-03-24 08:35:20 -070075 lsp_regenerate_schedule (area, IS_LEVEL_1 | IS_LEVEL_2, 0);
jardineb5d44e2003-12-23 08:09:43 +000076
77 return;
78}
79
Josh Bailey3f045a02012-03-24 08:35:20 -070080static void
81area_resign_level (struct isis_area *area, int level)
82{
83 if (area->lspdb[level - 1])
84 {
85 lsp_db_destroy (area->lspdb[level - 1]);
86 area->lspdb[level - 1] = NULL;
87 }
88 if (area->spftree[level - 1])
89 {
90 isis_spftree_del (area->spftree[level - 1]);
91 area->spftree[level - 1] = NULL;
92 }
93#ifdef HAVE_IPV6
94 if (area->spftree6[level - 1])
95 {
96 isis_spftree_del (area->spftree6[level - 1]);
97 area->spftree6[level - 1] = NULL;
98 }
99#endif
100 if (area->route_table[level - 1])
101 {
102 route_table_finish (area->route_table[level - 1]);
103 area->route_table[level - 1] = NULL;
104 }
105#ifdef HAVE_IPV6
106 if (area->route_table6[level - 1])
107 {
108 route_table_finish (area->route_table6[level - 1]);
109 area->route_table6[level - 1] = NULL;
110 }
111#endif /* HAVE_IPV6 */
112
Christian Franke61010c32015-11-10 18:43:34 +0100113 sched_debug("ISIS (%s): Resigned from L%d - canceling LSP regeneration timer.",
114 area->area_tag, level);
Josh Bailey3f045a02012-03-24 08:35:20 -0700115 THREAD_TIMER_OFF (area->t_lsp_refresh[level - 1]);
Christian Franke61010c32015-11-10 18:43:34 +0100116 area->lsp_regenerate_pending[level - 1] = 0;
Josh Bailey3f045a02012-03-24 08:35:20 -0700117}
118
hassof390d2c2004-09-10 20:48:21 +0000119void
jardineb5d44e2003-12-23 08:09:43 +0000120isis_event_system_type_change (struct isis_area *area, int newtype)
121{
hasso3fdb2dd2005-09-28 18:45:54 +0000122 struct listnode *node;
jardineb5d44e2003-12-23 08:09:43 +0000123 struct isis_circuit *circuit;
124
hassof390d2c2004-09-10 20:48:21 +0000125 if (isis->debugs & DEBUG_EVENTS)
hasso529d65b2004-12-24 00:14:50 +0000126 zlog_debug ("ISIS-Evt (%s) system type change %s -> %s", area->area_tag,
jardineb5d44e2003-12-23 08:09:43 +0000127 circuit_t2string (area->is_type), circuit_t2string (newtype));
hassof390d2c2004-09-10 20:48:21 +0000128
jardineb5d44e2003-12-23 08:09:43 +0000129 if (area->is_type == newtype)
hassof390d2c2004-09-10 20:48:21 +0000130 return; /* No change */
131
132 switch (area->is_type)
Josh Bailey3f045a02012-03-24 08:35:20 -0700133 {
hassof390d2c2004-09-10 20:48:21 +0000134 case IS_LEVEL_1:
Josh Bailey3f045a02012-03-24 08:35:20 -0700135 if (newtype == IS_LEVEL_2)
Josh Bailey3f045a02012-03-24 08:35:20 -0700136 area_resign_level (area, IS_LEVEL_1);
Subbaiah Venkatae38e0df2012-03-27 23:48:05 -0700137
138 if (area->lspdb[1] == NULL)
139 area->lspdb[1] = lsp_db_init ();
140 if (area->route_table[1] == NULL)
141 area->route_table[1] = route_table_init ();
Josh Bailey3f045a02012-03-24 08:35:20 -0700142#ifdef HAVE_IPV6
Subbaiah Venkatae38e0df2012-03-27 23:48:05 -0700143 if (area->route_table6[1] == NULL)
144 area->route_table6[1] = route_table_init ();
Josh Bailey3f045a02012-03-24 08:35:20 -0700145#endif /* HAVE_IPV6 */
hassof390d2c2004-09-10 20:48:21 +0000146 break;
Josh Bailey3f045a02012-03-24 08:35:20 -0700147
hassof390d2c2004-09-10 20:48:21 +0000148 case IS_LEVEL_1_AND_2:
149 if (newtype == IS_LEVEL_1)
Josh Bailey3f045a02012-03-24 08:35:20 -0700150 area_resign_level (area, IS_LEVEL_2);
hassof390d2c2004-09-10 20:48:21 +0000151 else
Josh Bailey3f045a02012-03-24 08:35:20 -0700152 area_resign_level (area, IS_LEVEL_1);
hassof390d2c2004-09-10 20:48:21 +0000153 break;
Josh Bailey3f045a02012-03-24 08:35:20 -0700154
hassof390d2c2004-09-10 20:48:21 +0000155 case IS_LEVEL_2:
Josh Bailey3f045a02012-03-24 08:35:20 -0700156 if (newtype == IS_LEVEL_1)
Josh Bailey3f045a02012-03-24 08:35:20 -0700157 area_resign_level (area, IS_LEVEL_2);
Subbaiah Venkatae38e0df2012-03-27 23:48:05 -0700158
159 if (area->lspdb[0] == NULL)
160 area->lspdb[0] = lsp_db_init ();
161 if (area->route_table[0] == NULL)
162 area->route_table[0] = route_table_init ();
Josh Bailey3f045a02012-03-24 08:35:20 -0700163#ifdef HAVE_IPV6
Subbaiah Venkatae38e0df2012-03-27 23:48:05 -0700164 if (area->route_table6[0] == NULL)
165 area->route_table6[0] = route_table_init ();
Josh Bailey3f045a02012-03-24 08:35:20 -0700166#endif /* HAVE_IPV6 */
hassof390d2c2004-09-10 20:48:21 +0000167 break;
Subbaiah Venkatae38e0df2012-03-27 23:48:05 -0700168
hassof390d2c2004-09-10 20:48:21 +0000169 default:
170 break;
Josh Bailey3f045a02012-03-24 08:35:20 -0700171 }
hassof390d2c2004-09-10 20:48:21 +0000172
jardineb5d44e2003-12-23 08:09:43 +0000173 area->is_type = newtype;
Josh Bailey3f045a02012-03-24 08:35:20 -0700174
175 /* override circuit's is_type */
176 if (area->is_type != IS_LEVEL_1_AND_2)
177 {
178 for (ALL_LIST_ELEMENTS_RO (area->circuit_list, node, circuit))
179 isis_event_circuit_type_change (circuit, newtype);
180 }
jardineb5d44e2003-12-23 08:09:43 +0000181
182 spftree_area_init (area);
Josh Bailey3f045a02012-03-24 08:35:20 -0700183
184 if (newtype & IS_LEVEL_1)
185 lsp_generate (area, IS_LEVEL_1);
186 if (newtype & IS_LEVEL_2)
187 lsp_generate (area, IS_LEVEL_2);
188 lsp_regenerate_schedule (area, IS_LEVEL_1 | IS_LEVEL_2, 1);
jardineb5d44e2003-12-23 08:09:43 +0000189
190 return;
191}
192
hasso92365882005-01-18 13:53:33 +0000193static void
jardineb5d44e2003-12-23 08:09:43 +0000194circuit_commence_level (struct isis_circuit *circuit, int level)
195{
hassof390d2c2004-09-10 20:48:21 +0000196 if (level == 1)
197 {
Subbaiah Venkatae38e0df2012-03-27 23:48:05 -0700198 if (! circuit->is_passive)
199 THREAD_TIMER_ON (master, circuit->t_send_psnp[0], send_l1_psnp, circuit,
200 isis_jitter (circuit->psnp_interval[0], PSNP_JITTER));
hassod70f99e2004-02-11 20:26:31 +0000201
hassof390d2c2004-09-10 20:48:21 +0000202 if (circuit->circ_type == CIRCUIT_T_BROADCAST)
203 {
hassof390d2c2004-09-10 20:48:21 +0000204 THREAD_TIMER_ON (master, circuit->u.bc.t_run_dr[0], isis_run_dr_l1,
Josh Bailey3f045a02012-03-24 08:35:20 -0700205 circuit, 2 * circuit->hello_interval[0]);
hassof390d2c2004-09-10 20:48:21 +0000206
207 THREAD_TIMER_ON (master, circuit->u.bc.t_send_lan_hello[0],
208 send_lan_l1_hello, circuit,
209 isis_jitter (circuit->hello_interval[0],
210 IIH_JITTER));
211
212 circuit->u.bc.lan_neighs[0] = list_new ();
213 }
jardineb5d44e2003-12-23 08:09:43 +0000214 }
hassof390d2c2004-09-10 20:48:21 +0000215 else
216 {
Subbaiah Venkatae38e0df2012-03-27 23:48:05 -0700217 if (! circuit->is_passive)
218 THREAD_TIMER_ON (master, circuit->t_send_psnp[1], send_l2_psnp, circuit,
219 isis_jitter (circuit->psnp_interval[1], PSNP_JITTER));
hassof390d2c2004-09-10 20:48:21 +0000220
221 if (circuit->circ_type == CIRCUIT_T_BROADCAST)
222 {
hassof390d2c2004-09-10 20:48:21 +0000223 THREAD_TIMER_ON (master, circuit->u.bc.t_run_dr[1], isis_run_dr_l2,
hassoa211d652004-09-20 14:55:29 +0000224 circuit, 2 * circuit->hello_interval[1]);
hassof390d2c2004-09-10 20:48:21 +0000225
226 THREAD_TIMER_ON (master, circuit->u.bc.t_send_lan_hello[1],
227 send_lan_l2_hello, circuit,
228 isis_jitter (circuit->hello_interval[1],
229 IIH_JITTER));
230
231 circuit->u.bc.lan_neighs[1] = list_new ();
232 }
233 }
234
jardineb5d44e2003-12-23 08:09:43 +0000235 return;
236}
237
hasso92365882005-01-18 13:53:33 +0000238static void
jardineb5d44e2003-12-23 08:09:43 +0000239circuit_resign_level (struct isis_circuit *circuit, int level)
240{
241 int idx = level - 1;
jardineb5d44e2003-12-23 08:09:43 +0000242
hassof390d2c2004-09-10 20:48:21 +0000243 THREAD_TIMER_OFF (circuit->t_send_csnp[idx]);
244 THREAD_TIMER_OFF (circuit->t_send_psnp[idx]);
245
246 if (circuit->circ_type == CIRCUIT_T_BROADCAST)
247 {
248 THREAD_TIMER_OFF (circuit->u.bc.t_send_lan_hello[idx]);
249 THREAD_TIMER_OFF (circuit->u.bc.t_run_dr[idx]);
hasso13fb40a2005-10-01 06:03:04 +0000250 THREAD_TIMER_OFF (circuit->u.bc.t_refresh_pseudo_lsp[idx]);
Christian Franke61010c32015-11-10 18:43:34 +0100251 circuit->lsp_regenerate_pending[idx] = 0;
hassof390d2c2004-09-10 20:48:21 +0000252 circuit->u.bc.run_dr_elect[idx] = 0;
boris yakubova0a661f2013-04-26 14:38:34 -0400253 if (circuit->u.bc.lan_neighs[idx] != NULL) {
254 list_delete (circuit->u.bc.lan_neighs[idx]);
255 circuit->u.bc.lan_neighs[idx] = NULL;
256 }
hassof390d2c2004-09-10 20:48:21 +0000257 }
258
jardineb5d44e2003-12-23 08:09:43 +0000259 return;
260}
261
hassof390d2c2004-09-10 20:48:21 +0000262void
263isis_event_circuit_type_change (struct isis_circuit *circuit, int newtype)
jardineb5d44e2003-12-23 08:09:43 +0000264{
Josh Bailey3f045a02012-03-24 08:35:20 -0700265 if (circuit->state != C_STATE_UP)
266 {
267 circuit->is_type = newtype;
268 return;
269 }
hassof390d2c2004-09-10 20:48:21 +0000270
271 if (isis->debugs & DEBUG_EVENTS)
hasso529d65b2004-12-24 00:14:50 +0000272 zlog_debug ("ISIS-Evt (%s) circuit type change %s -> %s",
hassof390d2c2004-09-10 20:48:21 +0000273 circuit->area->area_tag,
Josh Bailey3f045a02012-03-24 08:35:20 -0700274 circuit_t2string (circuit->is_type),
jardineb5d44e2003-12-23 08:09:43 +0000275 circuit_t2string (newtype));
276
Josh Bailey3f045a02012-03-24 08:35:20 -0700277 if (circuit->is_type == newtype)
hassof390d2c2004-09-10 20:48:21 +0000278 return; /* No change */
jardineb5d44e2003-12-23 08:09:43 +0000279
hassof390d2c2004-09-10 20:48:21 +0000280 if (!(newtype & circuit->area->is_type))
281 {
282 zlog_err ("ISIS-Evt (%s) circuit type change - invalid level %s because"
283 " area is %s", circuit->area->area_tag,
284 circuit_t2string (newtype),
285 circuit_t2string (circuit->area->is_type));
286 return;
287 }
288
Lu Feng92cff4f2015-01-08 01:21:02 +0000289 if (! circuit->is_passive)
hassof390d2c2004-09-10 20:48:21 +0000290 {
Lu Feng92cff4f2015-01-08 01:21:02 +0000291 switch (circuit->is_type)
292 {
293 case IS_LEVEL_1:
294 if (newtype == IS_LEVEL_2)
295 circuit_resign_level (circuit, 1);
296 circuit_commence_level (circuit, 2);
297 break;
298 case IS_LEVEL_1_AND_2:
299 if (newtype == IS_LEVEL_1)
300 circuit_resign_level (circuit, 2);
301 else
302 circuit_resign_level (circuit, 1);
303 break;
304 case IS_LEVEL_2:
305 if (newtype == IS_LEVEL_1)
306 circuit_resign_level (circuit, 2);
307 circuit_commence_level (circuit, 1);
308 break;
309 default:
310 break;
311 }
hassof390d2c2004-09-10 20:48:21 +0000312 }
313
Josh Bailey3f045a02012-03-24 08:35:20 -0700314 circuit->is_type = newtype;
315 lsp_regenerate_schedule (circuit->area, IS_LEVEL_1 | IS_LEVEL_2, 0);
jardineb5d44e2003-12-23 08:09:43 +0000316
317 return;
318}
319
320 /* 04/18/2002 by Gwak. */
321 /**************************************************************************
322 *
323 * EVENTS for LSP generation
324 *
325 * 1) an Adajacency or Circuit Up/Down event
326 * 2) a chnage in Circuit metric
327 * 3) a change in Reachable Address metric
328 * 4) a change in manualAreaAddresses
329 * 5) a change in systemID
330 * 6) a change in DIS status
331 * 7) a chnage in the waiting status
332 *
333 * ***********************************************************************
334 *
335 * current support event
336 *
337 * 1) Adjacency Up/Down event
338 * 6) a change in DIS status
339 *
340 * ***********************************************************************/
341
hassof390d2c2004-09-10 20:48:21 +0000342void
jardineb5d44e2003-12-23 08:09:43 +0000343isis_event_adjacency_state_change (struct isis_adjacency *adj, int newstate)
344{
345 /* adjacency state change event.
346 * - the only proto-type was supported */
hassof390d2c2004-09-10 20:48:21 +0000347
348 /* invalid arguments */
349 if (!adj || !adj->circuit || !adj->circuit->area)
350 return;
351
hassoc89c05d2005-09-04 21:36:36 +0000352 if (isis->debugs & DEBUG_EVENTS)
353 zlog_debug ("ISIS-Evt (%s) Adjacency State change",
354 adj->circuit->area->area_tag);
hassof390d2c2004-09-10 20:48:21 +0000355
jardineb5d44e2003-12-23 08:09:43 +0000356 /* LSP generation again */
Josh Bailey3f045a02012-03-24 08:35:20 -0700357 lsp_regenerate_schedule (adj->circuit->area, IS_LEVEL_1 | IS_LEVEL_2, 0);
jardineb5d44e2003-12-23 08:09:43 +0000358
359 return;
360}
361
362/* events supporting code */
363
364int
365isis_event_dis_status_change (struct thread *thread)
366{
367 struct isis_circuit *circuit;
hassof390d2c2004-09-10 20:48:21 +0000368
jardineb5d44e2003-12-23 08:09:43 +0000369 circuit = THREAD_ARG (thread);
hassof390d2c2004-09-10 20:48:21 +0000370
jardineb5d44e2003-12-23 08:09:43 +0000371 /* invalid arguments */
hassof390d2c2004-09-10 20:48:21 +0000372 if (!circuit || !circuit->area)
373 return 0;
hassoc89c05d2005-09-04 21:36:36 +0000374 if (isis->debugs & DEBUG_EVENTS)
375 zlog_debug ("ISIS-Evt (%s) DIS status change", circuit->area->area_tag);
jardineb5d44e2003-12-23 08:09:43 +0000376
377 /* LSP generation again */
Josh Bailey3f045a02012-03-24 08:35:20 -0700378 lsp_regenerate_schedule (circuit->area, IS_LEVEL_1 | IS_LEVEL_2, 0);
hassof390d2c2004-09-10 20:48:21 +0000379
jardineb5d44e2003-12-23 08:09:43 +0000380 return 0;
381}
382
hassof390d2c2004-09-10 20:48:21 +0000383void
hasso1cd80842004-10-07 20:07:40 +0000384isis_event_auth_failure (char *area_tag, const char *error_string, u_char *sysid)
jardineb5d44e2003-12-23 08:09:43 +0000385{
hassoc89c05d2005-09-04 21:36:36 +0000386 if (isis->debugs & DEBUG_EVENTS)
387 zlog_debug ("ISIS-Evt (%s) Authentication failure %s from %s",
388 area_tag, error_string, sysid_print (sysid));
hassof390d2c2004-09-10 20:48:21 +0000389
jardineb5d44e2003-12-23 08:09:43 +0000390 return;
391}