]> git.proxmox.com Git - mirror_frr.git/blob - isisd/isis_csm.c
Merge pull request #3502 from donaldsharp/socket_to_me_baby
[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 #include "isisd/isis_errors.h"
51
52 extern struct isis *isis;
53
54 static const char *csm_statestr[] = {"C_STATE_NA", "C_STATE_INIT",
55 "C_STATE_CONF", "C_STATE_UP"};
56
57 #define STATE2STR(S) csm_statestr[S]
58
59 static const char *csm_eventstr[] = {
60 "NO_STATE", "ISIS_ENABLE", "IF_UP_FROM_Z",
61 "ISIS_DISABLE", "IF_DOWN_FROM_Z",
62 };
63
64 #define EVENT2STR(E) csm_eventstr[E]
65
66 struct isis_circuit *
67 isis_csm_state_change(int event, struct isis_circuit *circuit, void *arg)
68 {
69 int old_state;
70
71 old_state = circuit ? circuit->state : C_STATE_NA;
72 if (isis->debugs & DEBUG_EVENTS)
73 zlog_debug("CSM_EVENT: %s", EVENT2STR(event));
74
75 switch (old_state) {
76 case C_STATE_NA:
77 if (circuit)
78 zlog_warn("Non-null circuit while state C_STATE_NA");
79 assert(circuit == NULL);
80 switch (event) {
81 case ISIS_ENABLE:
82 circuit = isis_circuit_new();
83 isis_circuit_configure(circuit,
84 (struct isis_area *)arg);
85 circuit->state = C_STATE_CONF;
86 break;
87 case IF_UP_FROM_Z:
88 circuit = isis_circuit_new();
89 isis_circuit_if_add(circuit, (struct interface *)arg);
90 listnode_add(isis->init_circ_list, circuit);
91 circuit->state = C_STATE_INIT;
92 break;
93 case ISIS_DISABLE:
94 zlog_warn("circuit already disabled");
95 break;
96 case IF_DOWN_FROM_Z:
97 zlog_warn("circuit already disconnected");
98 break;
99 }
100 break;
101 case C_STATE_INIT:
102 assert(circuit);
103 switch (event) {
104 case ISIS_ENABLE:
105 isis_circuit_configure(circuit,
106 (struct isis_area *)arg);
107 if (isis_circuit_up(circuit) != ISIS_OK) {
108 isis_circuit_deconfigure(
109 circuit, (struct isis_area *)arg);
110 break;
111 }
112 circuit->state = C_STATE_UP;
113 isis_event_circuit_state_change(circuit, circuit->area,
114 1);
115 listnode_delete(isis->init_circ_list, circuit);
116 break;
117 case IF_UP_FROM_Z:
118 assert(circuit);
119 zlog_warn("circuit already connected");
120 break;
121 case ISIS_DISABLE:
122 zlog_warn("circuit already disabled");
123 break;
124 case IF_DOWN_FROM_Z:
125 isis_circuit_if_del(circuit, (struct interface *)arg);
126 listnode_delete(isis->init_circ_list, circuit);
127 isis_circuit_del(circuit);
128 circuit = NULL;
129 break;
130 }
131 break;
132 case C_STATE_CONF:
133 assert(circuit);
134 switch (event) {
135 case ISIS_ENABLE:
136 zlog_warn("circuit already enabled");
137 break;
138 case IF_UP_FROM_Z:
139 isis_circuit_if_add(circuit, (struct interface *)arg);
140 if (isis_circuit_up(circuit) != ISIS_OK) {
141 flog_err(
142 EC_ISIS_CONFIG,
143 "Could not bring up %s because of invalid config.",
144 circuit->interface->name);
145 flog_err(
146 EC_ISIS_CONFIG,
147 "Clearing config for %s. Please re-examine it.",
148 circuit->interface->name);
149 if (circuit->ip_router) {
150 circuit->ip_router = 0;
151 circuit->area->ip_circuits--;
152 }
153 if (circuit->ipv6_router) {
154 circuit->ipv6_router = 0;
155 circuit->area->ipv6_circuits--;
156 }
157 circuit_update_nlpids(circuit);
158 isis_circuit_deconfigure(circuit,
159 circuit->area);
160 listnode_add(isis->init_circ_list, circuit);
161 circuit->state = C_STATE_INIT;
162 break;
163 }
164 circuit->state = C_STATE_UP;
165 isis_event_circuit_state_change(circuit, circuit->area,
166 1);
167 break;
168 case ISIS_DISABLE:
169 isis_circuit_deconfigure(circuit,
170 (struct isis_area *)arg);
171 isis_circuit_del(circuit);
172 circuit = NULL;
173 break;
174 case IF_DOWN_FROM_Z:
175 zlog_warn("circuit already disconnected");
176 break;
177 }
178 break;
179 case C_STATE_UP:
180 assert(circuit);
181 switch (event) {
182 case ISIS_ENABLE:
183 zlog_warn("circuit already configured");
184 break;
185 case IF_UP_FROM_Z:
186 zlog_warn("circuit already connected");
187 break;
188 case ISIS_DISABLE:
189 isis_circuit_down(circuit);
190 isis_circuit_deconfigure(circuit,
191 (struct isis_area *)arg);
192 circuit->state = C_STATE_INIT;
193 isis_event_circuit_state_change(
194 circuit, (struct isis_area *)arg, 0);
195 listnode_add(isis->init_circ_list, circuit);
196 break;
197 case IF_DOWN_FROM_Z:
198 isis_circuit_down(circuit);
199 isis_circuit_if_del(circuit, (struct interface *)arg);
200 circuit->state = C_STATE_CONF;
201 isis_event_circuit_state_change(circuit, circuit->area,
202 0);
203 break;
204 }
205 break;
206
207 default:
208 zlog_warn("Invalid circuit state %d", old_state);
209 }
210
211 if (isis->debugs & DEBUG_EVENTS)
212 zlog_debug("CSM_STATE_CHANGE: %s -> %s ", STATE2STR(old_state),
213 circuit ? STATE2STR(circuit->state)
214 : STATE2STR(C_STATE_NA));
215
216 return circuit;
217 }