]> git.proxmox.com Git - mirror_frr.git/blob - isisd/isis_csm.c
doc: Add `show ipv6 rpf X:X::X:X` command to docs
[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/isis_constants.h"
36 #include "isisd/isis_common.h"
37 #include "isisd/isis_flags.h"
38 #include "isisd/isis_circuit.h"
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"
46 #include "isisd/isisd.h"
47 #include "isisd/isis_csm.h"
48 #include "isisd/isis_events.h"
49 #include "isisd/isis_errors.h"
50
51 static const char *const csm_statestr[] = {"C_STATE_NA", "C_STATE_INIT",
52 "C_STATE_CONF", "C_STATE_UP"};
53
54 #define STATE2STR(S) csm_statestr[S]
55
56 static const char *const csm_eventstr[] = {
57 "NO_STATE", "ISIS_ENABLE", "IF_UP_FROM_Z",
58 "ISIS_DISABLE", "IF_DOWN_FROM_Z",
59 };
60
61 #define EVENT2STR(E) csm_eventstr[E]
62
63 struct isis_circuit *isis_csm_state_change(enum isis_circuit_event event,
64 struct isis_circuit *circuit,
65 void *arg)
66 {
67 enum isis_circuit_state old_state;
68 struct isis_area *area = NULL;
69 struct interface *ifp;
70
71 assert(circuit);
72
73 old_state = circuit->state;
74 if (IS_DEBUG_EVENTS)
75 zlog_debug("CSM_EVENT for %s: %s", circuit->interface->name,
76 EVENT2STR(event));
77
78 switch (old_state) {
79 case C_STATE_NA:
80 switch (event) {
81 case ISIS_ENABLE:
82 area = arg;
83
84 isis_circuit_configure(circuit, area);
85 circuit->state = C_STATE_CONF;
86 break;
87 case IF_UP_FROM_Z:
88 ifp = arg;
89
90 isis_circuit_if_add(circuit, ifp);
91 circuit->state = C_STATE_INIT;
92 break;
93 case ISIS_DISABLE:
94 if (IS_DEBUG_EVENTS)
95 zlog_debug("circuit %s already disabled",
96 circuit->interface->name);
97 break;
98 case IF_DOWN_FROM_Z:
99 if (IS_DEBUG_EVENTS)
100 zlog_debug("circuit %s already disconnected",
101 circuit->interface->name);
102 break;
103 }
104 break;
105 case C_STATE_INIT:
106 switch (event) {
107 case ISIS_ENABLE:
108 area = arg;
109
110 isis_circuit_configure(circuit, area);
111 if (isis_circuit_up(circuit) != ISIS_OK) {
112 isis_circuit_deconfigure(circuit, area);
113 break;
114 }
115 circuit->state = C_STATE_UP;
116 isis_event_circuit_state_change(circuit, circuit->area,
117 1);
118 break;
119 case IF_UP_FROM_Z:
120 if (IS_DEBUG_EVENTS)
121 zlog_debug("circuit %s already connected",
122 circuit->interface->name);
123 break;
124 case ISIS_DISABLE:
125 if (IS_DEBUG_EVENTS)
126 zlog_debug("circuit %s already disabled",
127 circuit->interface->name);
128 break;
129 case IF_DOWN_FROM_Z:
130 ifp = arg;
131
132 isis_circuit_if_del(circuit, ifp);
133 circuit->state = C_STATE_NA;
134 break;
135 }
136 break;
137 case C_STATE_CONF:
138 switch (event) {
139 case ISIS_ENABLE:
140 if (IS_DEBUG_EVENTS)
141 zlog_debug("circuit %s is already enabled",
142 circuit->interface->name);
143 break;
144 case IF_UP_FROM_Z:
145 ifp = arg;
146
147 isis_circuit_if_add(circuit, ifp);
148 if (isis_circuit_up(circuit) != ISIS_OK) {
149 isis_circuit_if_del(circuit, ifp);
150 flog_err(
151 EC_ISIS_CONFIG,
152 "Could not bring up %s because of invalid config.",
153 circuit->interface->name);
154 break;
155 }
156 circuit->state = C_STATE_UP;
157 isis_event_circuit_state_change(circuit, circuit->area,
158 1);
159 break;
160 case ISIS_DISABLE:
161 area = arg;
162
163 isis_circuit_deconfigure(circuit, area);
164 circuit->state = C_STATE_NA;
165 break;
166 case IF_DOWN_FROM_Z:
167 if (IS_DEBUG_EVENTS)
168 zlog_debug("circuit %s already disconnected",
169 circuit->interface->name);
170 break;
171 }
172 break;
173 case C_STATE_UP:
174 switch (event) {
175 case ISIS_ENABLE:
176 if (IS_DEBUG_EVENTS)
177 zlog_debug("circuit %s already enabled",
178 circuit->interface->name);
179 break;
180 case IF_UP_FROM_Z:
181 if (IS_DEBUG_EVENTS)
182 zlog_debug("circuit %s already connected",
183 circuit->interface->name);
184 break;
185 case ISIS_DISABLE:
186 area = arg;
187
188 isis_circuit_down(circuit);
189 isis_circuit_deconfigure(circuit, area);
190 circuit->state = C_STATE_INIT;
191 isis_event_circuit_state_change(circuit, area, 0);
192 break;
193 case IF_DOWN_FROM_Z:
194 ifp = arg;
195
196 isis_circuit_down(circuit);
197 isis_circuit_if_del(circuit, ifp);
198 circuit->state = C_STATE_CONF;
199 isis_event_circuit_state_change(circuit, circuit->area,
200 0);
201 break;
202 }
203 break;
204 }
205
206 if (IS_DEBUG_EVENTS)
207 zlog_debug("CSM_STATE_CHANGE: %s -> %s ", STATE2STR(old_state),
208 STATE2STR(circuit->state));
209
210 return circuit;
211 }