2023-02-08 13:17:09 +01:00
|
|
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
2003-12-23 09:09:43 +01:00
|
|
|
/*
|
|
|
|
* IS-IS Rout(e)ing protocol - isis_dr.c
|
|
|
|
* IS-IS designated router related routines
|
|
|
|
*
|
|
|
|
* Copyright (C) 2001,2002 Sampo Saaristo
|
|
|
|
* Tampere University of Technology
|
|
|
|
* Institute of Communications Engineering
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
#include <zebra.h>
|
|
|
|
|
|
|
|
#include "log.h"
|
|
|
|
#include "hash.h"
|
2023-03-07 20:22:48 +01:00
|
|
|
#include "frrevent.h"
|
2003-12-23 09:09:43 +01:00
|
|
|
#include "linklist.h"
|
|
|
|
#include "vty.h"
|
|
|
|
#include "stream.h"
|
|
|
|
#include "if.h"
|
|
|
|
|
|
|
|
#include "isisd/isis_constants.h"
|
|
|
|
#include "isisd/isis_common.h"
|
|
|
|
#include "isisd/isis_misc.h"
|
|
|
|
#include "isisd/isis_flags.h"
|
|
|
|
#include "isisd/isis_circuit.h"
|
|
|
|
#include "isisd/isisd.h"
|
|
|
|
#include "isisd/isis_adjacency.h"
|
|
|
|
#include "isisd/isis_constants.h"
|
|
|
|
#include "isisd/isis_pdu.h"
|
|
|
|
#include "isisd/isis_lsp.h"
|
|
|
|
#include "isisd/isis_dr.h"
|
|
|
|
#include "isisd/isis_events.h"
|
|
|
|
|
2004-09-10 22:48:21 +02:00
|
|
|
const char *isis_disflag2string(int disflag)
|
|
|
|
{
|
2003-12-23 09:09:43 +01:00
|
|
|
|
2004-09-10 22:48:21 +02:00
|
|
|
switch (disflag) {
|
2003-12-23 09:09:43 +01:00
|
|
|
case ISIS_IS_NOT_DIS:
|
|
|
|
return "is not DIS";
|
|
|
|
case ISIS_IS_DIS:
|
|
|
|
return "is DIS";
|
|
|
|
case ISIS_WAS_DIS:
|
|
|
|
return "was DIS";
|
2004-09-10 22:48:21 +02:00
|
|
|
default:
|
|
|
|
return "unknown DIS state";
|
|
|
|
}
|
|
|
|
return NULL; /* not reached */
|
2003-12-23 09:09:43 +01:00
|
|
|
}
|
|
|
|
|
2022-03-01 22:18:12 +01:00
|
|
|
void isis_run_dr(struct event *thread)
|
2003-12-23 09:09:43 +01:00
|
|
|
{
|
2022-12-25 16:26:52 +01:00
|
|
|
struct isis_circuit_arg *arg = EVENT_ARG(thread);
|
2004-09-10 22:48:21 +02:00
|
|
|
|
2018-10-10 11:16:39 +02:00
|
|
|
assert(arg);
|
2004-09-10 22:48:21 +02:00
|
|
|
|
2018-10-10 11:16:39 +02:00
|
|
|
struct isis_circuit *circuit = arg->circuit;
|
|
|
|
int level = arg->level;
|
2003-12-23 09:09:43 +01:00
|
|
|
|
|
|
|
assert(circuit);
|
|
|
|
|
2018-10-10 11:16:39 +02:00
|
|
|
if (circuit->circ_type != CIRCUIT_T_BROADCAST) {
|
|
|
|
zlog_warn("%s: scheduled for non broadcast circuit from %s:%d",
|
2020-04-28 09:30:50 +02:00
|
|
|
__func__, thread->xref->xref.file,
|
|
|
|
thread->xref->xref.line);
|
2022-02-23 01:04:25 +01:00
|
|
|
return;
|
2018-10-10 11:16:39 +02:00
|
|
|
}
|
2004-09-10 22:48:21 +02:00
|
|
|
|
2018-10-10 11:16:39 +02:00
|
|
|
if (circuit->u.bc.run_dr_elect[level - 1])
|
2022-08-29 08:53:46 +02:00
|
|
|
zlog_warn("%s: run_dr_elect already set for l%d", __func__,
|
|
|
|
level);
|
2004-09-10 22:48:21 +02:00
|
|
|
|
2018-10-10 11:16:39 +02:00
|
|
|
circuit->u.bc.t_run_dr[level - 1] = NULL;
|
|
|
|
circuit->u.bc.run_dr_elect[level - 1] = 1;
|
2003-12-23 09:09:43 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static int isis_check_dr_change(struct isis_adjacency *adj, int level)
|
|
|
|
{
|
|
|
|
int i;
|
2017-07-17 14:03:14 +02:00
|
|
|
|
2004-09-10 22:48:21 +02:00
|
|
|
if (adj->dis_record[level - 1].dis
|
|
|
|
!= adj->dis_record[(1 * ISIS_LEVELS) + level - 1].dis)
|
|
|
|
/* was there a DIS state transition ? */
|
2003-12-23 09:09:43 +01:00
|
|
|
{
|
2004-09-10 22:48:21 +02:00
|
|
|
adj->dischanges[level - 1]++;
|
2020-09-15 22:46:15 +02:00
|
|
|
adj->circuit->desig_changes[level - 1]++;
|
2003-12-23 09:09:43 +01:00
|
|
|
/* ok rotate the history list through */
|
2004-09-10 22:48:21 +02:00
|
|
|
for (i = DIS_RECORDS - 1; i > 0; i--) {
|
|
|
|
adj->dis_record[(i * ISIS_LEVELS) + level - 1].dis =
|
|
|
|
adj->dis_record[((i - 1) * ISIS_LEVELS) + level
|
|
|
|
- 1]
|
|
|
|
.dis;
|
|
|
|
adj->dis_record[(i * ISIS_LEVELS) + level - 1]
|
|
|
|
.last_dis_change =
|
|
|
|
adj->dis_record[((i - 1) * ISIS_LEVELS) + level
|
|
|
|
- 1]
|
|
|
|
.last_dis_change;
|
2017-07-17 14:03:14 +02:00
|
|
|
}
|
2003-12-23 09:09:43 +01:00
|
|
|
}
|
|
|
|
return ISIS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
int isis_dr_elect(struct isis_circuit *circuit, int level)
|
|
|
|
{
|
|
|
|
struct list *adjdb;
|
2005-09-28 20:45:54 +02:00
|
|
|
struct listnode *node;
|
2003-12-23 09:09:43 +01:00
|
|
|
struct isis_adjacency *adj, *adj_dr = NULL;
|
|
|
|
struct list *list = list_new();
|
2018-03-27 21:13:34 +02:00
|
|
|
uint8_t own_prio;
|
2003-12-23 09:09:43 +01:00
|
|
|
int biggest_prio = -1;
|
|
|
|
int cmp_res, retval = ISIS_OK;
|
2017-07-17 14:03:14 +02:00
|
|
|
|
2012-03-24 16:35:20 +01:00
|
|
|
own_prio = circuit->priority[level - 1];
|
2004-09-10 22:48:21 +02:00
|
|
|
adjdb = circuit->u.bc.adjdb[level - 1];
|
2017-07-17 14:03:14 +02:00
|
|
|
|
2004-09-10 22:48:21 +02:00
|
|
|
if (!adjdb) {
|
2022-08-29 08:53:46 +02:00
|
|
|
zlog_warn("%s adjdb == NULL", __func__);
|
2018-10-02 11:39:51 +02:00
|
|
|
list_delete(&list);
|
2004-09-10 22:48:21 +02:00
|
|
|
return ISIS_WARNING;
|
|
|
|
}
|
2003-12-23 09:09:43 +01:00
|
|
|
isis_adj_build_up_list(adjdb, list);
|
2017-07-17 14:03:14 +02:00
|
|
|
|
|
|
|
/*
|
2003-12-23 09:09:43 +01:00
|
|
|
* Loop the adjacencies and find the one with the biggest priority
|
2017-07-17 14:03:14 +02:00
|
|
|
*/
|
2005-09-28 20:45:54 +02:00
|
|
|
for (ALL_LIST_ELEMENTS_RO(list, node, adj)) {
|
2004-09-10 22:48:21 +02:00
|
|
|
/* clear flag for show output */
|
2012-03-24 16:35:20 +01:00
|
|
|
adj->dis_record[level - 1].dis = ISIS_IS_NOT_DIS;
|
|
|
|
adj->dis_record[level - 1].last_dis_change = time(NULL);
|
2017-07-17 14:03:14 +02:00
|
|
|
|
2004-09-10 22:48:21 +02:00
|
|
|
if (adj->prio[level - 1] > biggest_prio) {
|
|
|
|
biggest_prio = adj->prio[level - 1];
|
|
|
|
adj_dr = adj;
|
|
|
|
} else if (adj->prio[level - 1] == biggest_prio) {
|
|
|
|
/*
|
|
|
|
* Comparison of MACs breaks a tie
|
|
|
|
*/
|
|
|
|
if (adj_dr) {
|
|
|
|
cmp_res = memcmp(adj_dr->snpa, adj->snpa,
|
|
|
|
ETH_ALEN);
|
|
|
|
if (cmp_res < 0) {
|
|
|
|
adj_dr = adj;
|
2017-07-17 14:03:14 +02:00
|
|
|
}
|
2004-09-10 22:48:21 +02:00
|
|
|
if (cmp_res == 0)
|
2017-07-17 14:03:14 +02:00
|
|
|
zlog_warn(
|
2022-08-29 08:53:46 +02:00
|
|
|
"%s: multiple adjacencies with same SNPA",
|
|
|
|
__func__);
|
2004-09-10 22:48:21 +02:00
|
|
|
} else {
|
|
|
|
adj_dr = adj;
|
2017-07-17 14:03:14 +02:00
|
|
|
}
|
2004-09-10 22:48:21 +02:00
|
|
|
}
|
|
|
|
}
|
2017-07-17 14:03:14 +02:00
|
|
|
|
2004-09-10 22:48:21 +02:00
|
|
|
if (!adj_dr) {
|
2003-12-23 09:09:43 +01:00
|
|
|
/*
|
2012-03-24 16:35:20 +01:00
|
|
|
* Could not find the DR - means we are alone. Resign if we were
|
|
|
|
* DR.
|
2003-12-23 09:09:43 +01:00
|
|
|
*/
|
2012-03-24 16:35:20 +01:00
|
|
|
if (circuit->u.bc.is_dr[level - 1])
|
|
|
|
retval = isis_dr_resign(circuit, level);
|
2018-10-02 11:39:51 +02:00
|
|
|
list_delete(&list);
|
2012-03-24 16:35:20 +01:00
|
|
|
return retval;
|
2003-12-23 09:09:43 +01:00
|
|
|
}
|
2017-07-17 14:03:14 +02:00
|
|
|
|
2003-12-23 09:09:43 +01:00
|
|
|
/*
|
|
|
|
* Now we have the DR adjacency, compare it to self
|
|
|
|
*/
|
2012-03-24 16:35:20 +01:00
|
|
|
if (adj_dr->prio[level - 1] < own_prio
|
|
|
|
|| (adj_dr->prio[level - 1] == own_prio
|
|
|
|
&& memcmp(adj_dr->snpa, circuit->u.bc.snpa, ETH_ALEN) < 0)) {
|
|
|
|
adj_dr->dis_record[level - 1].dis = ISIS_IS_NOT_DIS;
|
|
|
|
adj_dr->dis_record[level - 1].last_dis_change = time(NULL);
|
2017-07-17 14:03:14 +02:00
|
|
|
|
2012-03-24 16:35:20 +01:00
|
|
|
/* rotate the history log */
|
|
|
|
for (ALL_LIST_ELEMENTS_RO(list, node, adj))
|
|
|
|
isis_check_dr_change(adj, level);
|
2017-07-17 14:03:14 +02:00
|
|
|
|
2012-03-24 16:35:20 +01:00
|
|
|
/* We are the DR, commence DR */
|
|
|
|
if (circuit->u.bc.is_dr[level - 1] == 0 && listcount(list) > 0)
|
|
|
|
retval = isis_dr_commence(circuit, level);
|
2004-09-10 22:48:21 +02:00
|
|
|
} else {
|
|
|
|
/* ok we have found the DIS - lets mark the adjacency */
|
|
|
|
/* set flag for show output */
|
|
|
|
adj_dr->dis_record[level - 1].dis = ISIS_IS_DIS;
|
|
|
|
adj_dr->dis_record[level - 1].last_dis_change = time(NULL);
|
2017-07-17 14:03:14 +02:00
|
|
|
|
2004-09-10 22:48:21 +02:00
|
|
|
/* now loop through a second time to check if there has been a
|
|
|
|
* DIS change
|
|
|
|
* if yes rotate the history log
|
|
|
|
*/
|
2017-07-17 14:03:14 +02:00
|
|
|
|
2005-09-28 20:45:54 +02:00
|
|
|
for (ALL_LIST_ELEMENTS_RO(list, node, adj))
|
2005-04-07 Paul Jakma <paul.jakma@sun.com>
* (global): Fix up list loops to match changes in lib/linklist,
and some basic auditing of usage.
* configure.ac: define QUAGGA_NO_DEPRECATED_INTERFACES
* HACKING: Add notes about deprecating interfaces and commands.
* lib/linklist.h: Add usage comments.
Rename getdata macro to listgetdata.
Rename nextnode to listnextnode and fix its odd behaviour to be
less dangerous.
Make listgetdata macro assert node is not null, NULL list entries
should be bug condition.
ALL_LIST_ELEMENTS, new macro, forward-referencing macro for use
with for loop, Suggested by Jim Carlson of Sun.
Add ALL_LIST_ELEMENTS_RO for cases which obviously do not need the
"safety" of previous macro.
LISTNODE_ADD and DELETE macros renamed to ATTACH, DETACH, to
distinguish from the similarly named functions, and reflect their
effect better.
Add a QUAGGA_NO_DEPRECATED_INTERFACES define guarded section
with the old defines which were modified above,
for backwards compatibility - guarded to prevent Quagga using it..
* lib/linklist.c: fix up for linklist.h changes.
* ospf6d/ospf6_abr.c: (ospf6_abr_examin_brouter) change to a single
scan of the area list, rather than scanning all areas first for
INTER_ROUTER and then again for INTER_NETWORK. According to
16.2, the scan should be area specific anyway, and further
ospf6d does not seem to implement 16.3 anyway.
2005-04-07 09:30:20 +02:00
|
|
|
isis_check_dr_change(adj, level);
|
2017-07-17 14:03:14 +02:00
|
|
|
|
2004-09-10 22:48:21 +02:00
|
|
|
/*
|
|
|
|
* We are not DR - if we were -> resign
|
|
|
|
*/
|
|
|
|
if (circuit->u.bc.is_dr[level - 1])
|
2012-03-24 16:35:20 +01:00
|
|
|
retval = isis_dr_resign(circuit, level);
|
2003-12-23 09:09:43 +01:00
|
|
|
}
|
2018-10-02 11:39:51 +02:00
|
|
|
list_delete(&list);
|
2003-12-23 09:09:43 +01:00
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
|
|
|
int isis_dr_resign(struct isis_circuit *circuit, int level)
|
|
|
|
{
|
2018-03-27 21:13:34 +02:00
|
|
|
uint8_t id[ISIS_SYS_ID_LEN + 2];
|
2004-09-10 22:48:21 +02:00
|
|
|
|
2022-04-20 13:50:39 +02:00
|
|
|
if (IS_DEBUG_EVENTS)
|
2022-08-29 08:53:46 +02:00
|
|
|
zlog_debug("%s l%d", __func__, level);
|
2003-12-23 09:09:43 +01:00
|
|
|
|
|
|
|
circuit->u.bc.is_dr[level - 1] = 0;
|
2004-09-10 22:48:21 +02:00
|
|
|
circuit->u.bc.run_dr_elect[level - 1] = 0;
|
2022-12-25 16:26:52 +01:00
|
|
|
EVENT_OFF(circuit->u.bc.t_run_dr[level - 1]);
|
|
|
|
EVENT_OFF(circuit->u.bc.t_refresh_pseudo_lsp[level - 1]);
|
2012-03-24 16:35:20 +01:00
|
|
|
circuit->lsp_regenerate_pending[level - 1] = 0;
|
2004-09-10 22:48:21 +02:00
|
|
|
|
2020-10-09 14:00:44 +02:00
|
|
|
memcpy(id, circuit->isis->sysid, ISIS_SYS_ID_LEN);
|
2004-09-10 22:48:21 +02:00
|
|
|
LSP_PSEUDO_ID(id) = circuit->circuit_id;
|
|
|
|
LSP_FRAGMENT(id) = 0;
|
2012-03-24 16:35:20 +01:00
|
|
|
lsp_purge_pseudo(id, circuit, level);
|
2003-12-23 09:09:43 +01:00
|
|
|
|
2004-09-10 22:48:21 +02:00
|
|
|
if (level == 1) {
|
|
|
|
memset(circuit->u.bc.l1_desig_is, 0, ISIS_SYS_ID_LEN + 1);
|
|
|
|
|
2022-05-20 20:19:08 +02:00
|
|
|
event_add_timer(master, send_l1_psnp, circuit,
|
|
|
|
isis_jitter(circuit->psnp_interval[level - 1],
|
|
|
|
PSNP_JITTER),
|
|
|
|
&circuit->t_send_psnp[0]);
|
2004-09-10 22:48:21 +02:00
|
|
|
} else {
|
|
|
|
memset(circuit->u.bc.l2_desig_is, 0, ISIS_SYS_ID_LEN + 1);
|
|
|
|
|
2022-05-20 20:19:08 +02:00
|
|
|
event_add_timer(master, send_l2_psnp, circuit,
|
|
|
|
isis_jitter(circuit->psnp_interval[level - 1],
|
|
|
|
PSNP_JITTER),
|
|
|
|
&circuit->t_send_psnp[1]);
|
2004-09-10 22:48:21 +02:00
|
|
|
}
|
|
|
|
|
2022-12-25 16:26:52 +01:00
|
|
|
EVENT_OFF(circuit->t_send_csnp[level - 1]);
|
2018-10-10 11:16:39 +02:00
|
|
|
|
2022-05-20 20:19:08 +02:00
|
|
|
event_add_timer(master, isis_run_dr, &circuit->level_arg[level - 1],
|
|
|
|
2 * circuit->hello_interval[level - 1],
|
|
|
|
&circuit->u.bc.t_run_dr[level - 1]);
|
2018-10-10 11:16:39 +02:00
|
|
|
|
|
|
|
|
2022-05-20 20:19:08 +02:00
|
|
|
event_add_event(master, isis_event_dis_status_change, circuit, 0, NULL);
|
2003-12-23 09:09:43 +01:00
|
|
|
|
|
|
|
return ISIS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
int isis_dr_commence(struct isis_circuit *circuit, int level)
|
|
|
|
{
|
2018-03-27 21:13:34 +02:00
|
|
|
uint8_t old_dr[ISIS_SYS_ID_LEN + 2];
|
2017-07-17 14:03:14 +02:00
|
|
|
|
2020-06-19 21:04:33 +02:00
|
|
|
if (IS_DEBUG_EVENTS)
|
2022-08-29 08:53:46 +02:00
|
|
|
zlog_debug("%s l%d", __func__, level);
|
2017-07-17 14:03:14 +02:00
|
|
|
|
2003-12-23 09:09:43 +01:00
|
|
|
/* Lets keep a pause in DR election */
|
|
|
|
circuit->u.bc.run_dr_elect[level - 1] = 0;
|
|
|
|
circuit->u.bc.is_dr[level - 1] = 1;
|
2017-07-17 14:03:14 +02:00
|
|
|
|
2004-09-10 22:48:21 +02:00
|
|
|
if (level == 1) {
|
|
|
|
memcpy(old_dr, circuit->u.bc.l1_desig_is, ISIS_SYS_ID_LEN + 1);
|
|
|
|
LSP_FRAGMENT(old_dr) = 0;
|
|
|
|
if (LSP_PSEUDO_ID(old_dr)) {
|
|
|
|
/* there was a dr elected, purge its LSPs from the db */
|
2012-03-24 16:35:20 +01:00
|
|
|
lsp_purge_pseudo(old_dr, circuit, level);
|
2004-09-10 22:48:21 +02:00
|
|
|
}
|
2020-10-09 14:00:44 +02:00
|
|
|
memcpy(circuit->u.bc.l1_desig_is, circuit->isis->sysid,
|
2020-07-13 14:37:59 +02:00
|
|
|
ISIS_SYS_ID_LEN);
|
2004-09-10 22:48:21 +02:00
|
|
|
*(circuit->u.bc.l1_desig_is + ISIS_SYS_ID_LEN) =
|
|
|
|
circuit->circuit_id;
|
2017-07-17 14:03:14 +02:00
|
|
|
|
2004-09-10 22:48:21 +02:00
|
|
|
assert(circuit->circuit_id); /* must be non-zero */
|
2012-03-24 16:35:20 +01:00
|
|
|
lsp_generate_pseudo(circuit, 1);
|
2017-07-17 14:03:14 +02:00
|
|
|
|
2022-05-20 20:19:08 +02:00
|
|
|
event_add_timer(master, send_l1_csnp, circuit,
|
|
|
|
isis_jitter(circuit->csnp_interval[level - 1],
|
|
|
|
CSNP_JITTER),
|
|
|
|
&circuit->t_send_csnp[0]);
|
2017-07-17 14:03:14 +02:00
|
|
|
|
2003-12-23 09:09:43 +01:00
|
|
|
} else {
|
2004-09-10 22:48:21 +02:00
|
|
|
memcpy(old_dr, circuit->u.bc.l2_desig_is, ISIS_SYS_ID_LEN + 1);
|
|
|
|
LSP_FRAGMENT(old_dr) = 0;
|
|
|
|
if (LSP_PSEUDO_ID(old_dr)) {
|
|
|
|
/* there was a dr elected, purge its LSPs from the db */
|
|
|
|
lsp_purge_pseudo(old_dr, circuit, level);
|
2017-07-17 14:03:14 +02:00
|
|
|
}
|
2020-10-09 14:00:44 +02:00
|
|
|
memcpy(circuit->u.bc.l2_desig_is, circuit->isis->sysid,
|
2020-07-13 14:37:59 +02:00
|
|
|
ISIS_SYS_ID_LEN);
|
2004-09-10 22:48:21 +02:00
|
|
|
*(circuit->u.bc.l2_desig_is + ISIS_SYS_ID_LEN) =
|
|
|
|
circuit->circuit_id;
|
2017-07-17 14:03:14 +02:00
|
|
|
|
2004-09-10 22:48:21 +02:00
|
|
|
assert(circuit->circuit_id); /* must be non-zero */
|
2012-03-24 16:35:20 +01:00
|
|
|
lsp_generate_pseudo(circuit, 2);
|
2017-07-17 14:03:14 +02:00
|
|
|
|
2022-05-20 20:19:08 +02:00
|
|
|
event_add_timer(master, send_l2_csnp, circuit,
|
|
|
|
isis_jitter(circuit->csnp_interval[level - 1],
|
|
|
|
CSNP_JITTER),
|
|
|
|
&circuit->t_send_csnp[1]);
|
2004-09-10 22:48:21 +02:00
|
|
|
}
|
2003-12-23 09:09:43 +01:00
|
|
|
|
2022-05-20 20:19:08 +02:00
|
|
|
event_add_timer(master, isis_run_dr, &circuit->level_arg[level - 1],
|
|
|
|
2 * circuit->hello_interval[level - 1],
|
|
|
|
&circuit->u.bc.t_run_dr[level - 1]);
|
|
|
|
event_add_event(master, isis_event_dis_status_change, circuit, 0, NULL);
|
2004-09-10 22:48:21 +02:00
|
|
|
|
2003-12-23 09:09:43 +01:00
|
|
|
return ISIS_OK;
|
|
|
|
}
|