]> git.proxmox.com Git - mirror_frr.git/blame - isisd/isis_csm.c
zebra: Fix label manager memory leak (#5680)
[mirror_frr.git] / isisd / isis_csm.c
CommitLineData
eb5d44eb 1/*
2 * IS-IS Rout(e)ing protocol - isis_csm.c
3 * IS-IS circuit state machine
4 * Copyright (C) 2001,2002 Sampo Saaristo
d62a17ae 5 * Tampere University of Technology
eb5d44eb 6 * Institute of Communications Engineering
7 *
d62a17ae 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)
eb5d44eb 11 * any later version.
12 *
d62a17ae 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
eb5d44eb 16 * more details.
17 *
896014f4
DL
18 * You should have received a copy of the GNU General Public License along
19 * with this program; see the file COPYING; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
eb5d44eb 21 */
22
23#include <zebra.h>
eb5d44eb 24
25#include "log.h"
26#include "memory.h"
27#include "if.h"
28#include "linklist.h"
29#include "command.h"
30#include "thread.h"
31#include "hash.h"
32#include "prefix.h"
33#include "stream.h"
34
eb5d44eb 35#include "isisd/isis_constants.h"
36#include "isisd/isis_common.h"
3f045a08 37#include "isisd/isis_flags.h"
eb5d44eb 38#include "isisd/isis_circuit.h"
eb5d44eb 39#include "isisd/isis_lsp.h"
40#include "isisd/isis_pdu.h"
41#include "isisd/isis_network.h"
42#include "isisd/isis_misc.h"
43#include "isisd/isis_constants.h"
44#include "isisd/isis_adjacency.h"
45#include "isisd/isis_dr.h"
eb5d44eb 46#include "isisd/isisd.h"
47#include "isisd/isis_csm.h"
48#include "isisd/isis_events.h"
54ece698 49#include "isisd/isis_errors.h"
eb5d44eb 50
51extern struct isis *isis;
52
2b64873d 53static const char *const csm_statestr[] = {"C_STATE_NA", "C_STATE_INIT",
d62a17ae 54 "C_STATE_CONF", "C_STATE_UP"};
eb5d44eb 55
56#define STATE2STR(S) csm_statestr[S]
57
2b64873d 58static const char *const csm_eventstr[] = {
d62a17ae 59 "NO_STATE", "ISIS_ENABLE", "IF_UP_FROM_Z",
60 "ISIS_DISABLE", "IF_DOWN_FROM_Z",
eb5d44eb 61};
62
63#define EVENT2STR(E) csm_eventstr[E]
64
f390d2c7 65struct isis_circuit *
d62a17ae 66isis_csm_state_change(int event, struct isis_circuit *circuit, void *arg)
eb5d44eb 67{
d62a17ae 68 int old_state;
eb5d44eb 69
d62a17ae 70 old_state = circuit ? circuit->state : C_STATE_NA;
71 if (isis->debugs & DEBUG_EVENTS)
72 zlog_debug("CSM_EVENT: %s", EVENT2STR(event));
f390d2c7 73
d62a17ae 74 switch (old_state) {
75 case C_STATE_NA:
76 if (circuit)
77 zlog_warn("Non-null circuit while state C_STATE_NA");
78 assert(circuit == NULL);
79 switch (event) {
80 case ISIS_ENABLE:
81 circuit = isis_circuit_new();
82 isis_circuit_configure(circuit,
83 (struct isis_area *)arg);
84 circuit->state = C_STATE_CONF;
85 break;
86 case IF_UP_FROM_Z:
87 circuit = isis_circuit_new();
88 isis_circuit_if_add(circuit, (struct interface *)arg);
89 listnode_add(isis->init_circ_list, circuit);
90 circuit->state = C_STATE_INIT;
91 break;
92 case ISIS_DISABLE:
93 zlog_warn("circuit already disabled");
94 break;
95 case IF_DOWN_FROM_Z:
96 zlog_warn("circuit already disconnected");
97 break;
98 }
99 break;
100 case C_STATE_INIT:
101 assert(circuit);
102 switch (event) {
103 case ISIS_ENABLE:
104 isis_circuit_configure(circuit,
105 (struct isis_area *)arg);
106 if (isis_circuit_up(circuit) != ISIS_OK) {
107 isis_circuit_deconfigure(
108 circuit, (struct isis_area *)arg);
109 break;
110 }
111 circuit->state = C_STATE_UP;
112 isis_event_circuit_state_change(circuit, circuit->area,
113 1);
114 listnode_delete(isis->init_circ_list, circuit);
115 break;
116 case IF_UP_FROM_Z:
117 assert(circuit);
118 zlog_warn("circuit already connected");
119 break;
120 case ISIS_DISABLE:
121 zlog_warn("circuit already disabled");
122 break;
123 case IF_DOWN_FROM_Z:
124 isis_circuit_if_del(circuit, (struct interface *)arg);
125 listnode_delete(isis->init_circ_list, circuit);
126 isis_circuit_del(circuit);
127 circuit = NULL;
128 break;
129 }
130 break;
131 case C_STATE_CONF:
132 assert(circuit);
133 switch (event) {
134 case ISIS_ENABLE:
135 zlog_warn("circuit already enabled");
136 break;
137 case IF_UP_FROM_Z:
138 isis_circuit_if_add(circuit, (struct interface *)arg);
139 if (isis_circuit_up(circuit) != ISIS_OK) {
af4c2728 140 flog_err(
1a7ecb96 141 EC_ISIS_CONFIG,
d62a17ae 142 "Could not bring up %s because of invalid config.",
143 circuit->interface->name);
af4c2728 144 flog_err(
1a7ecb96 145 EC_ISIS_CONFIG,
d62a17ae 146 "Clearing config for %s. Please re-examine it.",
147 circuit->interface->name);
148 if (circuit->ip_router) {
149 circuit->ip_router = 0;
150 circuit->area->ip_circuits--;
151 }
152 if (circuit->ipv6_router) {
153 circuit->ipv6_router = 0;
154 circuit->area->ipv6_circuits--;
155 }
156 circuit_update_nlpids(circuit);
157 isis_circuit_deconfigure(circuit,
158 circuit->area);
159 listnode_add(isis->init_circ_list, circuit);
160 circuit->state = C_STATE_INIT;
161 break;
162 }
163 circuit->state = C_STATE_UP;
164 isis_event_circuit_state_change(circuit, circuit->area,
165 1);
166 break;
167 case ISIS_DISABLE:
168 isis_circuit_deconfigure(circuit,
169 (struct isis_area *)arg);
170 isis_circuit_del(circuit);
171 circuit = NULL;
172 break;
173 case IF_DOWN_FROM_Z:
174 zlog_warn("circuit already disconnected");
175 break;
176 }
177 break;
178 case C_STATE_UP:
179 assert(circuit);
180 switch (event) {
181 case ISIS_ENABLE:
182 zlog_warn("circuit already configured");
183 break;
184 case IF_UP_FROM_Z:
185 zlog_warn("circuit already connected");
186 break;
187 case ISIS_DISABLE:
188 isis_circuit_down(circuit);
189 isis_circuit_deconfigure(circuit,
190 (struct isis_area *)arg);
191 circuit->state = C_STATE_INIT;
192 isis_event_circuit_state_change(
193 circuit, (struct isis_area *)arg, 0);
194 listnode_add(isis->init_circ_list, circuit);
195 break;
196 case IF_DOWN_FROM_Z:
197 isis_circuit_down(circuit);
198 isis_circuit_if_del(circuit, (struct interface *)arg);
199 circuit->state = C_STATE_CONF;
200 isis_event_circuit_state_change(circuit, circuit->area,
201 0);
202 break;
203 }
204 break;
f390d2c7 205
d62a17ae 206 default:
207 zlog_warn("Invalid circuit state %d", old_state);
208 }
f390d2c7 209
d62a17ae 210 if (isis->debugs & DEBUG_EVENTS)
211 zlog_debug("CSM_STATE_CHANGE: %s -> %s ", STATE2STR(old_state),
212 circuit ? STATE2STR(circuit->state)
213 : STATE2STR(C_STATE_NA));
eb5d44eb 214
d62a17ae 215 return circuit;
eb5d44eb 216}