]> git.proxmox.com Git - mirror_frr.git/blob - isisd/isis_csm.c
Merge pull request #897 from donaldsharp/pim_memory_leak
[mirror_frr.git] / isisd / isis_csm.c
1 /*
2 * IS-IS Rout(e)ing protocol - isis_csm.c
3 * IS-IS circuit state machine
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; see the file COPYING; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
21 */
22
23 #include <zebra.h>
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
35 #include "isisd/dict.h"
36 #include "isisd/isis_constants.h"
37 #include "isisd/isis_common.h"
38 #include "isisd/isis_flags.h"
39 #include "isisd/isis_circuit.h"
40 #include "isisd/isis_lsp.h"
41 #include "isisd/isis_pdu.h"
42 #include "isisd/isis_network.h"
43 #include "isisd/isis_misc.h"
44 #include "isisd/isis_constants.h"
45 #include "isisd/isis_adjacency.h"
46 #include "isisd/isis_dr.h"
47 #include "isisd/isisd.h"
48 #include "isisd/isis_csm.h"
49 #include "isisd/isis_events.h"
50
51 extern struct isis *isis;
52
53 static const char *csm_statestr[] = {"C_STATE_NA", "C_STATE_INIT",
54 "C_STATE_CONF", "C_STATE_UP"};
55
56 #define STATE2STR(S) csm_statestr[S]
57
58 static const char *csm_eventstr[] = {
59 "NO_STATE", "ISIS_ENABLE", "IF_UP_FROM_Z",
60 "ISIS_DISABLE", "IF_DOWN_FROM_Z",
61 };
62
63 #define EVENT2STR(E) csm_eventstr[E]
64
65 struct isis_circuit *
66 isis_csm_state_change(int event, struct isis_circuit *circuit, void *arg)
67 {
68 int old_state;
69
70 old_state = circuit ? circuit->state : C_STATE_NA;
71 if (isis->debugs & DEBUG_EVENTS)
72 zlog_debug("CSM_EVENT: %s", EVENT2STR(event));
73
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) {
140 zlog_err(
141 "Could not bring up %s because of invalid config.",
142 circuit->interface->name);
143 zlog_err(
144 "Clearing config for %s. Please re-examine it.",
145 circuit->interface->name);
146 if (circuit->ip_router) {
147 circuit->ip_router = 0;
148 circuit->area->ip_circuits--;
149 }
150 if (circuit->ipv6_router) {
151 circuit->ipv6_router = 0;
152 circuit->area->ipv6_circuits--;
153 }
154 circuit_update_nlpids(circuit);
155 isis_circuit_deconfigure(circuit,
156 circuit->area);
157 listnode_add(isis->init_circ_list, circuit);
158 circuit->state = C_STATE_INIT;
159 break;
160 }
161 circuit->state = C_STATE_UP;
162 isis_event_circuit_state_change(circuit, circuit->area,
163 1);
164 break;
165 case ISIS_DISABLE:
166 isis_circuit_deconfigure(circuit,
167 (struct isis_area *)arg);
168 isis_circuit_del(circuit);
169 circuit = NULL;
170 break;
171 case IF_DOWN_FROM_Z:
172 zlog_warn("circuit already disconnected");
173 break;
174 }
175 break;
176 case C_STATE_UP:
177 assert(circuit);
178 switch (event) {
179 case ISIS_ENABLE:
180 zlog_warn("circuit already configured");
181 break;
182 case IF_UP_FROM_Z:
183 zlog_warn("circuit already connected");
184 break;
185 case ISIS_DISABLE:
186 isis_circuit_down(circuit);
187 isis_circuit_deconfigure(circuit,
188 (struct isis_area *)arg);
189 circuit->state = C_STATE_INIT;
190 isis_event_circuit_state_change(
191 circuit, (struct isis_area *)arg, 0);
192 listnode_add(isis->init_circ_list, circuit);
193 break;
194 case IF_DOWN_FROM_Z:
195 isis_circuit_down(circuit);
196 isis_circuit_if_del(circuit, (struct interface *)arg);
197 circuit->state = C_STATE_CONF;
198 isis_event_circuit_state_change(circuit, circuit->area,
199 0);
200 break;
201 }
202 break;
203
204 default:
205 zlog_warn("Invalid circuit state %d", old_state);
206 }
207
208 if (isis->debugs & DEBUG_EVENTS)
209 zlog_debug("CSM_STATE_CHANGE: %s -> %s ", STATE2STR(old_state),
210 circuit ? STATE2STR(circuit->state)
211 : STATE2STR(C_STATE_NA));
212
213 return circuit;
214 }