]>
Commit | Line | Data |
---|---|---|
eb5d44eb | 1 | /* |
2 | * IS-IS Rout(e)ing protocol - isis_circuit.h | |
3 | * | |
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. |
896014f4 DL |
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 | |
eb5d44eb | 21 | */ |
eb5d44eb | 22 | #include <zebra.h> |
37da8c01 | 23 | #ifdef GNU_LINUX |
eb5d44eb | 24 | #include <net/ethernet.h> |
37da8c01 | 25 | #else |
26 | #include <netinet/if_ether.h> | |
27 | #endif | |
eb5d44eb | 28 | |
29 | #include "log.h" | |
30 | #include "memory.h" | |
b2d7c082 | 31 | #include "vrf.h" |
eb5d44eb | 32 | #include "if.h" |
33 | #include "linklist.h" | |
34 | #include "command.h" | |
35 | #include "thread.h" | |
f8c06e2c | 36 | #include "vty.h" |
eb5d44eb | 37 | #include "hash.h" |
38 | #include "prefix.h" | |
39 | #include "stream.h" | |
676a4ea3 | 40 | #include "qobj.h" |
20600086 | 41 | #include "lib/northbound_cli.h" |
eb5d44eb | 42 | |
43 | #include "isisd/dict.h" | |
eb5d44eb | 44 | #include "isisd/isis_constants.h" |
45 | #include "isisd/isis_common.h" | |
3f045a08 | 46 | #include "isisd/isis_flags.h" |
eb5d44eb | 47 | #include "isisd/isis_circuit.h" |
eb5d44eb | 48 | #include "isisd/isis_lsp.h" |
49 | #include "isisd/isis_pdu.h" | |
50 | #include "isisd/isis_network.h" | |
51 | #include "isisd/isis_misc.h" | |
52 | #include "isisd/isis_constants.h" | |
53 | #include "isisd/isis_adjacency.h" | |
54 | #include "isisd/isis_dr.h" | |
eb5d44eb | 55 | #include "isisd/isisd.h" |
56 | #include "isisd/isis_csm.h" | |
57 | #include "isisd/isis_events.h" | |
f8c06e2c | 58 | #include "isisd/isis_te.h" |
064f4896 | 59 | #include "isisd/isis_mt.h" |
54ece698 | 60 | #include "isisd/isis_errors.h" |
9b39405f | 61 | #include "isisd/isis_tx_queue.h" |
eb5d44eb | 62 | |
676a4ea3 DL |
63 | DEFINE_QOBJ_TYPE(isis_circuit) |
64 | ||
41b36e90 PJ |
65 | /* |
66 | * Prototypes. | |
67 | */ | |
41b36e90 PJ |
68 | int isis_interface_config_write(struct vty *); |
69 | int isis_if_new_hook(struct interface *); | |
70 | int isis_if_delete_hook(struct interface *); | |
71 | ||
4d762f26 | 72 | struct isis_circuit *isis_circuit_new(void) |
eb5d44eb | 73 | { |
d62a17ae | 74 | struct isis_circuit *circuit; |
75 | int i; | |
76 | ||
77 | circuit = XCALLOC(MTYPE_ISIS_CIRCUIT, sizeof(struct isis_circuit)); | |
d62a17ae | 78 | |
79 | /* | |
80 | * Default values | |
81 | */ | |
cc50ddb2 EDP |
82 | #ifndef FABRICD |
83 | circuit->is_type = yang_get_default_enum( | |
84 | "/frr-interface:lib/interface/frr-isisd:isis/circuit-type"); | |
85 | circuit->flags = 0; | |
86 | ||
87 | circuit->pad_hellos = yang_get_default_bool( | |
88 | "/frr-interface:lib/interface/frr-isisd:isis/hello/padding"); | |
89 | circuit->hello_interval[0] = yang_get_default_uint32( | |
90 | "/frr-interface:lib/interface/frr-isisd:isis/hello/interval/level-1"); | |
91 | circuit->hello_interval[1] = yang_get_default_uint32( | |
92 | "/frr-interface:lib/interface/frr-isisd:isis/hello/interval/level-2"); | |
93 | circuit->hello_multiplier[0] = yang_get_default_uint32( | |
94 | "/frr-interface:lib/interface/frr-isisd:isis/hello/multiplier/level-1"); | |
95 | circuit->hello_multiplier[1] = yang_get_default_uint32( | |
96 | "/frr-interface:lib/interface/frr-isisd:isis/hello/multiplier/level-2"); | |
97 | circuit->csnp_interval[0] = yang_get_default_uint16( | |
98 | "/frr-interface:lib/interface/frr-isisd:isis/csnp-interval/level-1"); | |
99 | circuit->csnp_interval[1] = yang_get_default_uint16( | |
100 | "/frr-interface:lib/interface/frr-isisd:isis/csnp-interval/level-2"); | |
101 | circuit->psnp_interval[0] = yang_get_default_uint16( | |
102 | "/frr-interface:lib/interface/frr-isisd:isis/psnp-interval/level-1"); | |
103 | circuit->psnp_interval[1] = yang_get_default_uint16( | |
104 | "/frr-interface:lib/interface/frr-isisd:isis/psnp-interval/level-2"); | |
105 | circuit->priority[0] = yang_get_default_uint8( | |
106 | "/frr-interface:lib/interface/frr-isisd:isis/priority/level-1"); | |
107 | circuit->priority[1] = yang_get_default_uint8( | |
108 | "/frr-interface:lib/interface/frr-isisd:isis/priority/level-2"); | |
109 | circuit->metric[0] = yang_get_default_uint32( | |
110 | "/frr-interface:lib/interface/frr-isisd:isis/metric/level-1"); | |
111 | circuit->metric[1] = yang_get_default_uint32( | |
112 | "/frr-interface:lib/interface/frr-isisd:isis/metric/level-2"); | |
113 | circuit->te_metric[0] = yang_get_default_uint32( | |
114 | "/frr-interface:lib/interface/frr-isisd:isis/metric/level-1"); | |
115 | circuit->te_metric[1] = yang_get_default_uint32( | |
116 | "/frr-interface:lib/interface/frr-isisd:isis/metric/level-2"); | |
117 | ||
118 | for (i = 0; i < 2; i++) { | |
119 | circuit->level_arg[i].level = i + 1; | |
120 | circuit->level_arg[i].circuit = circuit; | |
121 | } | |
122 | #else | |
d62a17ae | 123 | circuit->is_type = IS_LEVEL_1_AND_2; |
124 | circuit->flags = 0; | |
125 | circuit->pad_hellos = 1; | |
126 | for (i = 0; i < 2; i++) { | |
127 | circuit->hello_interval[i] = DEFAULT_HELLO_INTERVAL; | |
128 | circuit->hello_multiplier[i] = DEFAULT_HELLO_MULTIPLIER; | |
129 | circuit->csnp_interval[i] = DEFAULT_CSNP_INTERVAL; | |
130 | circuit->psnp_interval[i] = DEFAULT_PSNP_INTERVAL; | |
131 | circuit->priority[i] = DEFAULT_PRIORITY; | |
132 | circuit->metric[i] = DEFAULT_CIRCUIT_METRIC; | |
133 | circuit->te_metric[i] = DEFAULT_CIRCUIT_METRIC; | |
7da4aa3c CF |
134 | circuit->level_arg[i].level = i + 1; |
135 | circuit->level_arg[i].circuit = circuit; | |
d62a17ae | 136 | } |
cc50ddb2 | 137 | #endif /* ifndef FABRICD */ |
d62a17ae | 138 | |
139 | circuit->mtc = mpls_te_circuit_new(); | |
140 | ||
141 | circuit_mt_init(circuit); | |
142 | ||
143 | QOBJ_REG(circuit, isis_circuit); | |
144 | ||
145 | return circuit; | |
eb5d44eb | 146 | } |
147 | ||
d62a17ae | 148 | void isis_circuit_del(struct isis_circuit *circuit) |
3f045a08 | 149 | { |
d62a17ae | 150 | if (!circuit) |
151 | return; | |
3f045a08 | 152 | |
d62a17ae | 153 | QOBJ_UNREG(circuit); |
676a4ea3 | 154 | |
d62a17ae | 155 | isis_circuit_if_unbind(circuit, circuit->interface); |
3f045a08 | 156 | |
d62a17ae | 157 | circuit_mt_finish(circuit); |
064f4896 | 158 | |
d62a17ae | 159 | /* and lastly the circuit itself */ |
160 | XFREE(MTYPE_ISIS_CIRCUIT, circuit); | |
3f045a08 | 161 | |
d62a17ae | 162 | return; |
3f045a08 JB |
163 | } |
164 | ||
d62a17ae | 165 | void isis_circuit_configure(struct isis_circuit *circuit, |
166 | struct isis_area *area) | |
eb5d44eb | 167 | { |
d62a17ae | 168 | assert(area); |
169 | circuit->area = area; | |
170 | ||
171 | /* | |
172 | * Whenever the is-type of an area is changed, the is-type of each | |
173 | * circuit | |
174 | * in that area is updated to a non-empty subset of the area is-type. | |
175 | * Inversely, when configuring a new circuit, this property should be | |
176 | * ensured as well. | |
177 | */ | |
178 | if (area->is_type != IS_LEVEL_1_AND_2) | |
179 | circuit->is_type = area->is_type; | |
180 | ||
181 | /* | |
182 | * Add the circuit into area | |
183 | */ | |
184 | listnode_add(area->circuit_list, circuit); | |
185 | ||
186 | circuit->idx = flags_get_index(&area->flags); | |
187 | ||
188 | return; | |
eb5d44eb | 189 | } |
190 | ||
d62a17ae | 191 | void isis_circuit_deconfigure(struct isis_circuit *circuit, |
192 | struct isis_area *area) | |
eb5d44eb | 193 | { |
d62a17ae | 194 | /* Free the index of SRM and SSN flags */ |
195 | flags_free_index(&area->flags, circuit->idx); | |
196 | circuit->idx = 0; | |
197 | /* Remove circuit from area */ | |
198 | assert(circuit->area == area); | |
199 | listnode_delete(area->circuit_list, circuit); | |
200 | circuit->area = NULL; | |
201 | ||
202 | return; | |
eb5d44eb | 203 | } |
204 | ||
d62a17ae | 205 | struct isis_circuit *circuit_lookup_by_ifp(struct interface *ifp, |
206 | struct list *list) | |
eb5d44eb | 207 | { |
d62a17ae | 208 | struct isis_circuit *circuit = NULL; |
209 | struct listnode *node; | |
f390d2c7 | 210 | |
d62a17ae | 211 | if (!list) |
212 | return NULL; | |
f390d2c7 | 213 | |
d62a17ae | 214 | for (ALL_LIST_ELEMENTS_RO(list, node, circuit)) |
215 | if (circuit->interface == ifp) { | |
216 | assert(ifp->info == circuit); | |
217 | return circuit; | |
218 | } | |
3f045a08 | 219 | |
d62a17ae | 220 | return NULL; |
eb5d44eb | 221 | } |
222 | ||
d62a17ae | 223 | struct isis_circuit *circuit_scan_by_ifp(struct interface *ifp) |
eb5d44eb | 224 | { |
d62a17ae | 225 | struct isis_area *area; |
226 | struct listnode *node; | |
227 | struct isis_circuit *circuit; | |
228 | ||
229 | if (ifp->info) | |
230 | return (struct isis_circuit *)ifp->info; | |
231 | ||
232 | if (isis->area_list) { | |
233 | for (ALL_LIST_ELEMENTS_RO(isis->area_list, node, area)) { | |
234 | circuit = | |
235 | circuit_lookup_by_ifp(ifp, area->circuit_list); | |
236 | if (circuit) | |
237 | return circuit; | |
238 | } | |
239 | } | |
240 | return circuit_lookup_by_ifp(ifp, isis->init_circ_list); | |
eb5d44eb | 241 | } |
242 | ||
d62a17ae | 243 | void isis_circuit_add_addr(struct isis_circuit *circuit, |
244 | struct connected *connected) | |
eb5d44eb | 245 | { |
d62a17ae | 246 | struct listnode *node; |
247 | struct prefix_ipv4 *ipv4; | |
4690c7d7 | 248 | #if defined(EXTREME_DEBUG) |
d62a17ae | 249 | char buf[PREFIX2STR_BUFFER]; |
4690c7d7 | 250 | #endif |
d62a17ae | 251 | struct prefix_ipv6 *ipv6; |
f891f443 | 252 | |
d62a17ae | 253 | if (connected->address->family == AF_INET) { |
d7c0a89a | 254 | uint32_t addr = connected->address->u.prefix4.s_addr; |
d62a17ae | 255 | addr = ntohl(addr); |
256 | if (IPV4_NET0(addr) || IPV4_NET127(addr) || IN_CLASSD(addr) | |
257 | || IPV4_LINKLOCAL(addr)) | |
258 | return; | |
3f045a08 | 259 | |
d62a17ae | 260 | for (ALL_LIST_ELEMENTS_RO(circuit->ip_addrs, node, ipv4)) |
261 | if (prefix_same((struct prefix *)ipv4, | |
262 | connected->address)) | |
263 | return; | |
3f045a08 | 264 | |
d62a17ae | 265 | ipv4 = prefix_ipv4_new(); |
266 | ipv4->prefixlen = connected->address->prefixlen; | |
267 | ipv4->prefix = connected->address->u.prefix4; | |
268 | listnode_add(circuit->ip_addrs, ipv4); | |
f8c06e2c | 269 | |
d62a17ae | 270 | /* Update MPLS TE Local IP address parameter */ |
271 | set_circuitparams_local_ipaddr(circuit->mtc, ipv4->prefix); | |
f8c06e2c | 272 | |
d62a17ae | 273 | if (circuit->area) |
274 | lsp_regenerate_schedule(circuit->area, circuit->is_type, | |
275 | 0); | |
f891f443 | 276 | |
eb5d44eb | 277 | #ifdef EXTREME_DEBUG |
d62a17ae | 278 | prefix2str(connected->address, buf, sizeof(buf)); |
c59f88c8 CF |
279 | zlog_debug("Added IP address %s to circuit %s", buf, |
280 | circuit->interface->name); | |
f390d2c7 | 281 | #endif /* EXTREME_DEBUG */ |
d62a17ae | 282 | } |
283 | if (connected->address->family == AF_INET6) { | |
284 | if (IN6_IS_ADDR_LOOPBACK(&connected->address->u.prefix6)) | |
285 | return; | |
286 | ||
287 | for (ALL_LIST_ELEMENTS_RO(circuit->ipv6_link, node, ipv6)) | |
288 | if (prefix_same((struct prefix *)ipv6, | |
289 | connected->address)) | |
290 | return; | |
291 | for (ALL_LIST_ELEMENTS_RO(circuit->ipv6_non_link, node, ipv6)) | |
292 | if (prefix_same((struct prefix *)ipv6, | |
293 | connected->address)) | |
294 | return; | |
295 | ||
296 | ipv6 = prefix_ipv6_new(); | |
297 | ipv6->prefixlen = connected->address->prefixlen; | |
298 | ipv6->prefix = connected->address->u.prefix6; | |
299 | ||
300 | if (IN6_IS_ADDR_LINKLOCAL(&ipv6->prefix)) | |
301 | listnode_add(circuit->ipv6_link, ipv6); | |
302 | else | |
303 | listnode_add(circuit->ipv6_non_link, ipv6); | |
304 | if (circuit->area) | |
305 | lsp_regenerate_schedule(circuit->area, circuit->is_type, | |
306 | 0); | |
f891f443 | 307 | |
eb5d44eb | 308 | #ifdef EXTREME_DEBUG |
d62a17ae | 309 | prefix2str(connected->address, buf, sizeof(buf)); |
c59f88c8 CF |
310 | zlog_debug("Added IPv6 address %s to circuit %s", buf, |
311 | circuit->interface->name); | |
f390d2c7 | 312 | #endif /* EXTREME_DEBUG */ |
d62a17ae | 313 | } |
314 | return; | |
eb5d44eb | 315 | } |
316 | ||
d62a17ae | 317 | void isis_circuit_del_addr(struct isis_circuit *circuit, |
318 | struct connected *connected) | |
eb5d44eb | 319 | { |
d62a17ae | 320 | struct prefix_ipv4 *ipv4, *ip = NULL; |
321 | struct listnode *node; | |
322 | char buf[PREFIX2STR_BUFFER]; | |
323 | struct prefix_ipv6 *ipv6, *ip6 = NULL; | |
324 | int found = 0; | |
325 | ||
326 | if (connected->address->family == AF_INET) { | |
327 | ipv4 = prefix_ipv4_new(); | |
328 | ipv4->prefixlen = connected->address->prefixlen; | |
329 | ipv4->prefix = connected->address->u.prefix4; | |
330 | ||
331 | for (ALL_LIST_ELEMENTS_RO(circuit->ip_addrs, node, ip)) | |
332 | if (prefix_same((struct prefix *)ip, | |
333 | (struct prefix *)ipv4)) | |
334 | break; | |
335 | ||
336 | if (ip) { | |
337 | listnode_delete(circuit->ip_addrs, ip); | |
d0a6f3e0 | 338 | prefix_ipv4_free(ip); |
d62a17ae | 339 | if (circuit->area) |
340 | lsp_regenerate_schedule(circuit->area, | |
341 | circuit->is_type, 0); | |
342 | } else { | |
343 | prefix2str(connected->address, buf, sizeof(buf)); | |
344 | zlog_warn( | |
c59f88c8 CF |
345 | "Nonexistent ip address %s removal attempt from \ |
346 | circuit %s", | |
347 | buf, circuit->interface->name); | |
d62a17ae | 348 | zlog_warn("Current ip addresses on %s:", |
349 | circuit->interface->name); | |
350 | for (ALL_LIST_ELEMENTS_RO(circuit->ip_addrs, node, | |
351 | ip)) { | |
352 | prefix2str(ip, buf, sizeof(buf)); | |
353 | zlog_warn(" %s", buf); | |
354 | } | |
355 | zlog_warn("End of addresses"); | |
356 | } | |
357 | ||
358 | prefix_ipv4_free(ipv4); | |
f891f443 | 359 | } |
d62a17ae | 360 | if (connected->address->family == AF_INET6) { |
361 | ipv6 = prefix_ipv6_new(); | |
362 | ipv6->prefixlen = connected->address->prefixlen; | |
363 | ipv6->prefix = connected->address->u.prefix6; | |
364 | ||
365 | if (IN6_IS_ADDR_LINKLOCAL(&ipv6->prefix)) { | |
366 | for (ALL_LIST_ELEMENTS_RO(circuit->ipv6_link, node, | |
367 | ip6)) { | |
368 | if (prefix_same((struct prefix *)ip6, | |
369 | (struct prefix *)ipv6)) | |
370 | break; | |
371 | } | |
372 | if (ip6) { | |
373 | listnode_delete(circuit->ipv6_link, ip6); | |
d0a6f3e0 | 374 | prefix_ipv6_free(ip6); |
d62a17ae | 375 | found = 1; |
376 | } | |
377 | } else { | |
378 | for (ALL_LIST_ELEMENTS_RO(circuit->ipv6_non_link, node, | |
379 | ip6)) { | |
380 | if (prefix_same((struct prefix *)ip6, | |
381 | (struct prefix *)ipv6)) | |
382 | break; | |
383 | } | |
384 | if (ip6) { | |
385 | listnode_delete(circuit->ipv6_non_link, ip6); | |
d0a6f3e0 | 386 | prefix_ipv6_free(ip6); |
d62a17ae | 387 | found = 1; |
388 | } | |
389 | } | |
390 | ||
391 | if (!found) { | |
392 | prefix2str(connected->address, buf, sizeof(buf)); | |
393 | zlog_warn( | |
c59f88c8 CF |
394 | "Nonexistent ip address %s removal attempt from \ |
395 | circuit %s", | |
396 | buf, circuit->interface->name); | |
d62a17ae | 397 | zlog_warn("Current ip addresses on %s:", |
398 | circuit->interface->name); | |
399 | for (ALL_LIST_ELEMENTS_RO(circuit->ipv6_link, node, | |
400 | ip6)) { | |
401 | prefix2str((struct prefix *)ip6, (char *)buf, | |
c28135f3 | 402 | sizeof(buf)); |
d62a17ae | 403 | zlog_warn(" %s", buf); |
404 | } | |
405 | zlog_warn(" -----"); | |
406 | for (ALL_LIST_ELEMENTS_RO(circuit->ipv6_non_link, node, | |
407 | ip6)) { | |
408 | prefix2str((struct prefix *)ip6, (char *)buf, | |
c28135f3 | 409 | sizeof(buf)); |
d62a17ae | 410 | zlog_warn(" %s", buf); |
411 | } | |
412 | zlog_warn("End of addresses"); | |
413 | } else if (circuit->area) | |
414 | lsp_regenerate_schedule(circuit->area, circuit->is_type, | |
415 | 0); | |
416 | ||
417 | prefix_ipv6_free(ipv6); | |
f891f443 | 418 | } |
d62a17ae | 419 | return; |
420 | } | |
e8aca32f | 421 | |
0849c75e | 422 | static uint8_t isis_circuit_id_gen(struct isis *isis, struct interface *ifp) |
d62a17ae | 423 | { |
068c8222 CF |
424 | /* Circuit ids MUST be unique for any broadcast circuits. Otherwise, |
425 | * Pseudo-Node LSPs cannot be generated correctly. | |
426 | * | |
98c5bc15 | 427 | * Currently, allocate one circuit ID for any circuit, limiting the total |
068c8222 CF |
428 | * numer of circuits IS-IS can run on to 255. |
429 | * | |
98c5bc15 | 430 | * We should revisit this when implementing 3-way adjacencies for p2p, since |
068c8222 CF |
431 | * we then have extended interface IDs available. |
432 | */ | |
433 | uint8_t id = ifp->ifindex; | |
d62a17ae | 434 | unsigned int i; |
d62a17ae | 435 | |
068c8222 CF |
436 | for (i = 0; i < 256; i++) { |
437 | if (id && !_ISIS_CHECK_FLAG(isis->circuit_ids_used, id)) | |
d62a17ae | 438 | break; |
068c8222 | 439 | id++; |
f891f443 | 440 | } |
441 | ||
068c8222 | 442 | if (i == 256) { |
996c9314 LB |
443 | zlog_warn("Could not allocate a circuit id for '%s'", |
444 | ifp->name); | |
068c8222 | 445 | return 0; |
f891f443 | 446 | } |
e8aca32f | 447 | |
0849c75e | 448 | _ISIS_SET_FLAG(isis->circuit_ids_used, id); |
d62a17ae | 449 | return id; |
3f045a08 JB |
450 | } |
451 | ||
d62a17ae | 452 | void isis_circuit_if_add(struct isis_circuit *circuit, struct interface *ifp) |
eb5d44eb | 453 | { |
d62a17ae | 454 | struct listnode *node, *nnode; |
455 | struct connected *conn; | |
456 | ||
d62a17ae | 457 | isis_circuit_if_bind(circuit, ifp); |
d62a17ae | 458 | |
459 | if (if_is_broadcast(ifp)) { | |
65f18157 | 460 | if (fabricd || circuit->circ_type_config == CIRCUIT_T_P2P) |
d62a17ae | 461 | circuit->circ_type = CIRCUIT_T_P2P; |
462 | else | |
463 | circuit->circ_type = CIRCUIT_T_BROADCAST; | |
464 | } else if (if_is_pointopoint(ifp)) { | |
465 | circuit->circ_type = CIRCUIT_T_P2P; | |
466 | } else if (if_is_loopback(ifp)) { | |
467 | circuit->circ_type = CIRCUIT_T_LOOPBACK; | |
468 | circuit->is_passive = 1; | |
469 | } else { | |
470 | /* It's normal in case of loopback etc. */ | |
471 | if (isis->debugs & DEBUG_EVENTS) | |
472 | zlog_debug("isis_circuit_if_add: unsupported media"); | |
473 | circuit->circ_type = CIRCUIT_T_UNKNOWN; | |
474 | } | |
475 | ||
476 | circuit->ip_addrs = list_new(); | |
477 | circuit->ipv6_link = list_new(); | |
478 | circuit->ipv6_non_link = list_new(); | |
479 | ||
480 | for (ALL_LIST_ELEMENTS(ifp->connected, node, nnode, conn)) | |
481 | isis_circuit_add_addr(circuit, conn); | |
eb5d44eb | 482 | } |
483 | ||
d62a17ae | 484 | void isis_circuit_if_del(struct isis_circuit *circuit, struct interface *ifp) |
eb5d44eb | 485 | { |
d62a17ae | 486 | struct listnode *node, *nnode; |
487 | struct connected *conn; | |
488 | ||
489 | assert(circuit->interface == ifp); | |
490 | ||
491 | /* destroy addresses */ | |
492 | for (ALL_LIST_ELEMENTS(ifp->connected, node, nnode, conn)) | |
493 | isis_circuit_del_addr(circuit, conn); | |
494 | ||
495 | if (circuit->ip_addrs) { | |
496 | assert(listcount(circuit->ip_addrs) == 0); | |
6a154c88 | 497 | list_delete(&circuit->ip_addrs); |
d62a17ae | 498 | } |
499 | ||
500 | if (circuit->ipv6_link) { | |
501 | assert(listcount(circuit->ipv6_link) == 0); | |
6a154c88 | 502 | list_delete(&circuit->ipv6_link); |
d62a17ae | 503 | } |
504 | ||
505 | if (circuit->ipv6_non_link) { | |
506 | assert(listcount(circuit->ipv6_non_link) == 0); | |
6a154c88 | 507 | list_delete(&circuit->ipv6_non_link); |
d62a17ae | 508 | } |
509 | ||
510 | circuit->circ_type = CIRCUIT_T_UNKNOWN; | |
eb5d44eb | 511 | } |
512 | ||
d62a17ae | 513 | void isis_circuit_if_bind(struct isis_circuit *circuit, struct interface *ifp) |
3f045a08 | 514 | { |
d62a17ae | 515 | assert(circuit != NULL); |
516 | assert(ifp != NULL); | |
517 | if (circuit->interface) | |
518 | assert(circuit->interface == ifp); | |
519 | else | |
520 | circuit->interface = ifp; | |
521 | if (ifp->info) | |
522 | assert(ifp->info == circuit); | |
523 | else | |
524 | ifp->info = circuit; | |
525 | isis_link_params_update(circuit, ifp); | |
3f045a08 JB |
526 | } |
527 | ||
d62a17ae | 528 | void isis_circuit_if_unbind(struct isis_circuit *circuit, struct interface *ifp) |
eb5d44eb | 529 | { |
d62a17ae | 530 | assert(circuit != NULL); |
531 | assert(ifp != NULL); | |
532 | assert(circuit->interface == ifp); | |
533 | assert(ifp->info == circuit); | |
534 | circuit->interface = NULL; | |
535 | ifp->info = NULL; | |
3f045a08 | 536 | } |
f390d2c7 | 537 | |
d62a17ae | 538 | static void isis_circuit_update_all_srmflags(struct isis_circuit *circuit, |
539 | int is_set) | |
3f045a08 | 540 | { |
d62a17ae | 541 | struct isis_area *area; |
542 | struct isis_lsp *lsp; | |
9b39405f | 543 | dnode_t *dnode; |
d62a17ae | 544 | int level; |
545 | ||
546 | assert(circuit); | |
547 | area = circuit->area; | |
548 | assert(area); | |
549 | for (level = ISIS_LEVEL1; level <= ISIS_LEVEL2; level++) { | |
9b39405f CF |
550 | if (!(level & circuit->is_type)) |
551 | continue; | |
552 | ||
553 | if (!area->lspdb[level - 1] | |
554 | || !dict_count(area->lspdb[level - 1])) | |
555 | continue; | |
556 | ||
557 | for (dnode = dict_first(area->lspdb[level - 1]); | |
558 | dnode != NULL; | |
559 | dnode = dict_next(area->lspdb[level - 1], dnode)) { | |
560 | lsp = dnode_get(dnode); | |
561 | if (is_set) { | |
562 | isis_tx_queue_add(circuit->tx_queue, lsp, | |
563 | TX_LSP_NORMAL); | |
564 | } else { | |
565 | isis_tx_queue_del(circuit->tx_queue, lsp); | |
d62a17ae | 566 | } |
567 | } | |
568 | } | |
eb5d44eb | 569 | } |
570 | ||
d62a17ae | 571 | size_t isis_circuit_pdu_size(struct isis_circuit *circuit) |
b20ccb3a | 572 | { |
d62a17ae | 573 | return ISO_MTU(circuit); |
b20ccb3a CF |
574 | } |
575 | ||
d62a17ae | 576 | void isis_circuit_stream(struct isis_circuit *circuit, struct stream **stream) |
b20ccb3a | 577 | { |
d62a17ae | 578 | size_t stream_size = isis_circuit_pdu_size(circuit); |
579 | ||
580 | if (!*stream) { | |
581 | *stream = stream_new(stream_size); | |
582 | } else { | |
583 | if (STREAM_SIZE(*stream) != stream_size) | |
db3c830a | 584 | stream_resize_inplace(stream, stream_size); |
d62a17ae | 585 | stream_reset(*stream); |
586 | } | |
b20ccb3a CF |
587 | } |
588 | ||
d62a17ae | 589 | void isis_circuit_prepare(struct isis_circuit *circuit) |
5904f19f | 590 | { |
b0dd98e7 | 591 | #if ISIS_METHOD != ISIS_METHOD_DLPI |
d62a17ae | 592 | thread_add_read(master, isis_receive, circuit, circuit->fd, |
593 | &circuit->t_read); | |
5904f19f | 594 | #else |
d62a17ae | 595 | thread_add_timer_msec(master, isis_receive, circuit, |
596 | listcount(circuit->area->circuit_list) * 100, | |
597 | &circuit->t_read); | |
5904f19f RW |
598 | #endif |
599 | } | |
600 | ||
d62a17ae | 601 | int isis_circuit_up(struct isis_circuit *circuit) |
eb5d44eb | 602 | { |
d62a17ae | 603 | int retv; |
604 | ||
605 | /* Set the flags for all the lsps of the circuit. */ | |
606 | isis_circuit_update_all_srmflags(circuit, 1); | |
607 | ||
608 | if (circuit->state == C_STATE_UP) | |
609 | return ISIS_OK; | |
610 | ||
611 | if (circuit->is_passive) | |
612 | return ISIS_OK; | |
613 | ||
614 | if (circuit->area->lsp_mtu > isis_circuit_pdu_size(circuit)) { | |
af4c2728 | 615 | flog_err( |
1a7ecb96 | 616 | EC_ISIS_CONFIG, |
d62a17ae | 617 | "Interface MTU %zu on %s is too low to support area lsp mtu %u!", |
618 | isis_circuit_pdu_size(circuit), | |
619 | circuit->interface->name, circuit->area->lsp_mtu); | |
620 | isis_circuit_update_all_srmflags(circuit, 0); | |
621 | return ISIS_ERROR; | |
622 | } | |
623 | ||
624 | if (circuit->circ_type == CIRCUIT_T_BROADCAST) { | |
0849c75e CF |
625 | circuit->circuit_id = isis_circuit_id_gen(isis, circuit->interface); |
626 | if (!circuit->circuit_id) { | |
af4c2728 | 627 | flog_err( |
1a7ecb96 | 628 | EC_ISIS_CONFIG, |
54ece698 | 629 | "There are already 255 broadcast circuits active!"); |
0849c75e CF |
630 | return ISIS_ERROR; |
631 | } | |
632 | ||
d62a17ae | 633 | /* |
634 | * Get the Hardware Address | |
635 | */ | |
636 | if (circuit->interface->hw_addr_len != ETH_ALEN) { | |
637 | zlog_warn("unsupported link layer"); | |
638 | } else { | |
639 | memcpy(circuit->u.bc.snpa, circuit->interface->hw_addr, | |
640 | ETH_ALEN); | |
641 | } | |
3f045a08 | 642 | #ifdef EXTREME_DEGUG |
d62a17ae | 643 | zlog_debug("isis_circuit_if_add: if_id %d, isomtu %d snpa %s", |
644 | circuit->interface->ifindex, ISO_MTU(circuit), | |
645 | snpa_print(circuit->u.bc.snpa)); | |
3f045a08 | 646 | #endif /* EXTREME_DEBUG */ |
3f045a08 | 647 | |
d62a17ae | 648 | circuit->u.bc.adjdb[0] = list_new(); |
649 | circuit->u.bc.adjdb[1] = list_new(); | |
650 | ||
651 | /* | |
652 | * ISO 10589 - 8.4.1 Enabling of broadcast circuits | |
653 | */ | |
654 | ||
655 | /* initilizing the hello sending threads | |
656 | * for a broadcast IF | |
657 | */ | |
658 | ||
659 | /* 8.4.1 a) commence sending of IIH PDUs */ | |
660 | ||
7c4f7aab CF |
661 | for (int level = ISIS_LEVEL1; level <= ISIS_LEVEL2; level++) { |
662 | if (!(circuit->is_type & level)) | |
663 | continue; | |
664 | ||
a0a707ee | 665 | send_hello_sched(circuit, level, TRIGGERED_IIH_DELAY); |
7c4f7aab CF |
666 | circuit->u.bc.lan_neighs[level - 1] = list_new(); |
667 | ||
668 | thread_add_timer(master, isis_run_dr, | |
669 | &circuit->level_arg[level - 1], | |
670 | 2 * circuit->hello_interval[level - 1], | |
671 | &circuit->u.bc.t_run_dr[level - 1]); | |
d62a17ae | 672 | } |
673 | ||
674 | /* 8.4.1 b) FIXME: solicit ES - 8.4.6 */ | |
675 | /* 8.4.1 c) FIXME: listen for ESH PDUs */ | |
d4670f51 | 676 | } else if (circuit->circ_type == CIRCUIT_T_P2P) { |
d62a17ae | 677 | /* initializing the hello send threads |
678 | * for a ptp IF | |
679 | */ | |
680 | circuit->u.p2p.neighbor = NULL; | |
a0a707ee | 681 | send_hello_sched(circuit, 0, TRIGGERED_IIH_DELAY); |
d62a17ae | 682 | } |
683 | ||
684 | /* initializing PSNP timers */ | |
685 | if (circuit->is_type & IS_LEVEL_1) | |
686 | thread_add_timer( | |
687 | master, send_l1_psnp, circuit, | |
688 | isis_jitter(circuit->psnp_interval[0], PSNP_JITTER), | |
689 | &circuit->t_send_psnp[0]); | |
690 | ||
691 | if (circuit->is_type & IS_LEVEL_2) | |
692 | thread_add_timer( | |
693 | master, send_l2_psnp, circuit, | |
694 | isis_jitter(circuit->psnp_interval[1], PSNP_JITTER), | |
695 | &circuit->t_send_psnp[1]); | |
696 | ||
697 | /* unified init for circuits; ignore warnings below this level */ | |
698 | retv = isis_sock_init(circuit); | |
699 | if (retv != ISIS_OK) { | |
700 | isis_circuit_down(circuit); | |
701 | return retv; | |
702 | } | |
703 | ||
704 | /* initialize the circuit streams after opening connection */ | |
705 | isis_circuit_stream(circuit, &circuit->rcv_stream); | |
706 | isis_circuit_stream(circuit, &circuit->snd_stream); | |
707 | ||
708 | isis_circuit_prepare(circuit); | |
709 | ||
9b39405f | 710 | circuit->tx_queue = isis_tx_queue_new(circuit, send_lsp); |
d62a17ae | 711 | |
392b89f3 EDP |
712 | #ifndef FABRICD |
713 | /* send northbound notification */ | |
714 | isis_notif_if_state_change(circuit, false); | |
715 | #endif /* ifndef FABRICD */ | |
716 | ||
d62a17ae | 717 | return ISIS_OK; |
eb5d44eb | 718 | } |
719 | ||
d62a17ae | 720 | void isis_circuit_down(struct isis_circuit *circuit) |
eb5d44eb | 721 | { |
392b89f3 EDP |
722 | #ifndef FABRICD |
723 | /* send northbound notification */ | |
724 | isis_notif_if_state_change(circuit, true); | |
725 | #endif /* ifndef FABRICD */ | |
726 | ||
d62a17ae | 727 | /* Clear the flags for all the lsps of the circuit. */ |
728 | isis_circuit_update_all_srmflags(circuit, 0); | |
729 | ||
730 | if (circuit->circ_type == CIRCUIT_T_BROADCAST) { | |
731 | /* destroy neighbour lists */ | |
732 | if (circuit->u.bc.lan_neighs[0]) { | |
6a154c88 | 733 | list_delete(&circuit->u.bc.lan_neighs[0]); |
d62a17ae | 734 | circuit->u.bc.lan_neighs[0] = NULL; |
735 | } | |
736 | if (circuit->u.bc.lan_neighs[1]) { | |
6a154c88 | 737 | list_delete(&circuit->u.bc.lan_neighs[1]); |
d62a17ae | 738 | circuit->u.bc.lan_neighs[1] = NULL; |
739 | } | |
740 | /* destroy adjacency databases */ | |
741 | if (circuit->u.bc.adjdb[0]) { | |
742 | circuit->u.bc.adjdb[0]->del = isis_delete_adj; | |
6a154c88 | 743 | list_delete(&circuit->u.bc.adjdb[0]); |
d62a17ae | 744 | circuit->u.bc.adjdb[0] = NULL; |
745 | } | |
746 | if (circuit->u.bc.adjdb[1]) { | |
747 | circuit->u.bc.adjdb[1]->del = isis_delete_adj; | |
6a154c88 | 748 | list_delete(&circuit->u.bc.adjdb[1]); |
d62a17ae | 749 | circuit->u.bc.adjdb[1] = NULL; |
750 | } | |
751 | if (circuit->u.bc.is_dr[0]) { | |
752 | isis_dr_resign(circuit, 1); | |
753 | circuit->u.bc.is_dr[0] = 0; | |
754 | } | |
755 | memset(circuit->u.bc.l1_desig_is, 0, ISIS_SYS_ID_LEN + 1); | |
756 | if (circuit->u.bc.is_dr[1]) { | |
757 | isis_dr_resign(circuit, 2); | |
758 | circuit->u.bc.is_dr[1] = 0; | |
759 | } | |
760 | memset(circuit->u.bc.l2_desig_is, 0, ISIS_SYS_ID_LEN + 1); | |
761 | memset(circuit->u.bc.snpa, 0, ETH_ALEN); | |
762 | ||
763 | THREAD_TIMER_OFF(circuit->u.bc.t_send_lan_hello[0]); | |
764 | THREAD_TIMER_OFF(circuit->u.bc.t_send_lan_hello[1]); | |
765 | THREAD_TIMER_OFF(circuit->u.bc.t_run_dr[0]); | |
766 | THREAD_TIMER_OFF(circuit->u.bc.t_run_dr[1]); | |
767 | THREAD_TIMER_OFF(circuit->u.bc.t_refresh_pseudo_lsp[0]); | |
768 | THREAD_TIMER_OFF(circuit->u.bc.t_refresh_pseudo_lsp[1]); | |
769 | circuit->lsp_regenerate_pending[0] = 0; | |
770 | circuit->lsp_regenerate_pending[1] = 0; | |
0849c75e CF |
771 | |
772 | _ISIS_CLEAR_FLAG(isis->circuit_ids_used, circuit->circuit_id); | |
773 | circuit->circuit_id = 0; | |
d62a17ae | 774 | } else if (circuit->circ_type == CIRCUIT_T_P2P) { |
775 | isis_delete_adj(circuit->u.p2p.neighbor); | |
776 | circuit->u.p2p.neighbor = NULL; | |
777 | THREAD_TIMER_OFF(circuit->u.p2p.t_send_p2p_hello); | |
778 | } | |
779 | ||
780 | /* Cancel all active threads */ | |
781 | THREAD_TIMER_OFF(circuit->t_send_csnp[0]); | |
782 | THREAD_TIMER_OFF(circuit->t_send_csnp[1]); | |
783 | THREAD_TIMER_OFF(circuit->t_send_psnp[0]); | |
784 | THREAD_TIMER_OFF(circuit->t_send_psnp[1]); | |
785 | THREAD_OFF(circuit->t_read); | |
786 | ||
9b39405f CF |
787 | if (circuit->tx_queue) { |
788 | isis_tx_queue_free(circuit->tx_queue); | |
789 | circuit->tx_queue = NULL; | |
58e16237 CF |
790 | } |
791 | ||
d62a17ae | 792 | /* send one gratuitous hello to spead up convergence */ |
d4670f51 CF |
793 | if (circuit->state == C_STATE_UP) { |
794 | if (circuit->is_type & IS_LEVEL_1) | |
795 | send_hello(circuit, IS_LEVEL_1); | |
796 | if (circuit->is_type & IS_LEVEL_2) | |
797 | send_hello(circuit, IS_LEVEL_2); | |
798 | } | |
d62a17ae | 799 | |
800 | circuit->upadjcount[0] = 0; | |
801 | circuit->upadjcount[1] = 0; | |
802 | ||
803 | /* close the socket */ | |
804 | if (circuit->fd) { | |
805 | close(circuit->fd); | |
806 | circuit->fd = 0; | |
807 | } | |
808 | ||
809 | if (circuit->rcv_stream != NULL) { | |
810 | stream_free(circuit->rcv_stream); | |
811 | circuit->rcv_stream = NULL; | |
812 | } | |
813 | ||
814 | if (circuit->snd_stream != NULL) { | |
815 | stream_free(circuit->snd_stream); | |
816 | circuit->snd_stream = NULL; | |
817 | } | |
818 | ||
819 | thread_cancel_event(master, circuit); | |
820 | ||
821 | return; | |
eb5d44eb | 822 | } |
823 | ||
d62a17ae | 824 | void circuit_update_nlpids(struct isis_circuit *circuit) |
eb5d44eb | 825 | { |
d62a17ae | 826 | circuit->nlpids.count = 0; |
827 | ||
828 | if (circuit->ip_router) { | |
829 | circuit->nlpids.nlpids[0] = NLPID_IP; | |
830 | circuit->nlpids.count++; | |
831 | } | |
832 | if (circuit->ipv6_router) { | |
833 | circuit->nlpids.nlpids[circuit->nlpids.count] = NLPID_IPV6; | |
834 | circuit->nlpids.count++; | |
835 | } | |
836 | return; | |
eb5d44eb | 837 | } |
838 | ||
d62a17ae | 839 | void isis_circuit_print_vty(struct isis_circuit *circuit, struct vty *vty, |
840 | char detail) | |
3f045a08 | 841 | { |
d62a17ae | 842 | if (detail == ISIS_UI_LEVEL_BRIEF) { |
843 | vty_out(vty, " %-12s", circuit->interface->name); | |
844 | vty_out(vty, "0x%-7x", circuit->circuit_id); | |
845 | vty_out(vty, "%-9s", circuit_state2string(circuit->state)); | |
846 | vty_out(vty, "%-9s", circuit_type2string(circuit->circ_type)); | |
847 | vty_out(vty, "%-9s", circuit_t2string(circuit->is_type)); | |
848 | vty_out(vty, "\n"); | |
849 | } | |
850 | ||
851 | if (detail == ISIS_UI_LEVEL_DETAIL) { | |
852 | struct listnode *node; | |
853 | struct prefix *ip_addr; | |
854 | char buf[BUFSIZ]; | |
855 | ||
856 | vty_out(vty, " Interface: %s", circuit->interface->name); | |
857 | vty_out(vty, ", State: %s", | |
858 | circuit_state2string(circuit->state)); | |
859 | if (circuit->is_passive) | |
860 | vty_out(vty, ", Passive"); | |
861 | else | |
862 | vty_out(vty, ", Active"); | |
863 | vty_out(vty, ", Circuit Id: 0x%x", circuit->circuit_id); | |
864 | vty_out(vty, "\n"); | |
865 | vty_out(vty, " Type: %s", | |
866 | circuit_type2string(circuit->circ_type)); | |
867 | vty_out(vty, ", Level: %s", circuit_t2string(circuit->is_type)); | |
868 | if (circuit->circ_type == CIRCUIT_T_BROADCAST) | |
869 | vty_out(vty, ", SNPA: %-10s", | |
870 | snpa_print(circuit->u.bc.snpa)); | |
871 | vty_out(vty, "\n"); | |
872 | if (circuit->is_type & IS_LEVEL_1) { | |
873 | vty_out(vty, " Level-1 Information:\n"); | |
874 | if (circuit->area->newmetric) | |
875 | vty_out(vty, " Metric: %d", | |
876 | circuit->te_metric[0]); | |
877 | else | |
878 | vty_out(vty, " Metric: %d", | |
879 | circuit->metric[0]); | |
880 | if (!circuit->is_passive) { | |
881 | vty_out(vty, ", Active neighbors: %u\n", | |
882 | circuit->upadjcount[0]); | |
883 | vty_out(vty, | |
884 | " Hello interval: %u, " | |
885 | "Holddown count: %u %s\n", | |
886 | circuit->hello_interval[0], | |
887 | circuit->hello_multiplier[0], | |
888 | (circuit->pad_hellos ? "(pad)" | |
889 | : "(no-pad)")); | |
890 | vty_out(vty, | |
891 | " CNSP interval: %u, " | |
892 | "PSNP interval: %u\n", | |
893 | circuit->csnp_interval[0], | |
894 | circuit->psnp_interval[0]); | |
895 | if (circuit->circ_type == CIRCUIT_T_BROADCAST) | |
896 | vty_out(vty, | |
897 | " LAN Priority: %u, %s\n", | |
898 | circuit->priority[0], | |
899 | (circuit->u.bc.is_dr[0] | |
900 | ? "is DIS" | |
901 | : "is not DIS")); | |
902 | } else { | |
903 | vty_out(vty, "\n"); | |
904 | } | |
905 | } | |
906 | if (circuit->is_type & IS_LEVEL_2) { | |
907 | vty_out(vty, " Level-2 Information:\n"); | |
908 | if (circuit->area->newmetric) | |
909 | vty_out(vty, " Metric: %d", | |
910 | circuit->te_metric[1]); | |
911 | else | |
912 | vty_out(vty, " Metric: %d", | |
913 | circuit->metric[1]); | |
914 | if (!circuit->is_passive) { | |
915 | vty_out(vty, ", Active neighbors: %u\n", | |
916 | circuit->upadjcount[1]); | |
917 | vty_out(vty, | |
918 | " Hello interval: %u, " | |
919 | "Holddown count: %u %s\n", | |
920 | circuit->hello_interval[1], | |
921 | circuit->hello_multiplier[1], | |
922 | (circuit->pad_hellos ? "(pad)" | |
923 | : "(no-pad)")); | |
924 | vty_out(vty, | |
925 | " CNSP interval: %u, " | |
926 | "PSNP interval: %u\n", | |
927 | circuit->csnp_interval[1], | |
928 | circuit->psnp_interval[1]); | |
929 | if (circuit->circ_type == CIRCUIT_T_BROADCAST) | |
930 | vty_out(vty, | |
931 | " LAN Priority: %u, %s\n", | |
932 | circuit->priority[1], | |
933 | (circuit->u.bc.is_dr[1] | |
934 | ? "is DIS" | |
935 | : "is not DIS")); | |
936 | } else { | |
937 | vty_out(vty, "\n"); | |
938 | } | |
939 | } | |
940 | if (circuit->ip_addrs && listcount(circuit->ip_addrs) > 0) { | |
941 | vty_out(vty, " IP Prefix(es):\n"); | |
942 | for (ALL_LIST_ELEMENTS_RO(circuit->ip_addrs, node, | |
943 | ip_addr)) { | |
1445b43c A |
944 | prefix2str(ip_addr, buf, sizeof(buf)); |
945 | vty_out(vty, " %s\n", buf); | |
d62a17ae | 946 | } |
947 | } | |
948 | if (circuit->ipv6_link && listcount(circuit->ipv6_link) > 0) { | |
949 | vty_out(vty, " IPv6 Link-Locals:\n"); | |
950 | for (ALL_LIST_ELEMENTS_RO(circuit->ipv6_link, node, | |
951 | ip_addr)) { | |
1445b43c A |
952 | prefix2str(ip_addr, (char *)buf, BUFSIZ); |
953 | vty_out(vty, " %s\n", buf); | |
d62a17ae | 954 | } |
955 | } | |
956 | if (circuit->ipv6_non_link | |
957 | && listcount(circuit->ipv6_non_link) > 0) { | |
958 | vty_out(vty, " IPv6 Prefixes:\n"); | |
959 | for (ALL_LIST_ELEMENTS_RO(circuit->ipv6_non_link, node, | |
960 | ip_addr)) { | |
1445b43c A |
961 | prefix2str(ip_addr, (char *)buf, BUFSIZ); |
962 | vty_out(vty, " %s\n", buf); | |
d62a17ae | 963 | } |
964 | } | |
965 | ||
966 | vty_out(vty, "\n"); | |
967 | } | |
968 | return; | |
3f045a08 JB |
969 | } |
970 | ||
d56afe53 CF |
971 | DEFINE_HOOK(isis_circuit_config_write, |
972 | (struct isis_circuit *circuit, struct vty *vty), | |
973 | (circuit, vty)) | |
974 | ||
20600086 | 975 | #ifdef FABRICD |
d62a17ae | 976 | int isis_interface_config_write(struct vty *vty) |
eb5d44eb | 977 | { |
f4e14fdb | 978 | struct vrf *vrf = vrf_lookup_by_id(VRF_DEFAULT); |
d62a17ae | 979 | int write = 0; |
f4e14fdb | 980 | struct listnode *node; |
d62a17ae | 981 | struct interface *ifp; |
982 | struct isis_area *area; | |
983 | struct isis_circuit *circuit; | |
984 | int i; | |
985 | ||
451fda4f | 986 | FOR_ALL_INTERFACES (vrf, ifp) { |
d62a17ae | 987 | /* IF name */ |
a8b828f3 | 988 | vty_frame(vty, "interface %s\n", ifp->name); |
d62a17ae | 989 | write++; |
990 | /* IF desc */ | |
991 | if (ifp->desc) { | |
992 | vty_out(vty, " description %s\n", ifp->desc); | |
993 | write++; | |
994 | } | |
995 | /* ISIS Circuit */ | |
f4e14fdb | 996 | for (ALL_LIST_ELEMENTS_RO(isis->area_list, node, area)) { |
d62a17ae | 997 | circuit = |
998 | circuit_lookup_by_ifp(ifp, area->circuit_list); | |
999 | if (circuit == NULL) | |
1000 | continue; | |
1001 | if (circuit->ip_router) { | |
7c0cbd0e | 1002 | vty_out(vty, " ip router " PROTO_NAME " %s\n", |
d62a17ae | 1003 | area->area_tag); |
1004 | write++; | |
1005 | } | |
1006 | if (circuit->is_passive) { | |
7c0cbd0e | 1007 | vty_out(vty, " " PROTO_NAME " passive\n"); |
d62a17ae | 1008 | write++; |
1009 | } | |
1010 | if (circuit->circ_type_config == CIRCUIT_T_P2P) { | |
7c0cbd0e | 1011 | vty_out(vty, " " PROTO_NAME " network point-to-point\n"); |
d62a17ae | 1012 | write++; |
1013 | } | |
1014 | if (circuit->ipv6_router) { | |
7c0cbd0e | 1015 | vty_out(vty, " ipv6 router " PROTO_NAME " %s\n", |
d62a17ae | 1016 | area->area_tag); |
1017 | write++; | |
1018 | } | |
1019 | ||
1020 | /* ISIS - circuit type */ | |
65f18157 CF |
1021 | if (!fabricd) { |
1022 | if (circuit->is_type == IS_LEVEL_1) { | |
1023 | vty_out(vty, " " PROTO_NAME " circuit-type level-1\n"); | |
d62a17ae | 1024 | write++; |
65f18157 CF |
1025 | } else { |
1026 | if (circuit->is_type == IS_LEVEL_2) { | |
1027 | vty_out(vty, | |
1028 | " " PROTO_NAME " circuit-type level-2-only\n"); | |
1029 | write++; | |
1030 | } | |
d62a17ae | 1031 | } |
1032 | } | |
1033 | ||
1034 | /* ISIS - CSNP interval */ | |
1035 | if (circuit->csnp_interval[0] | |
1036 | == circuit->csnp_interval[1]) { | |
1037 | if (circuit->csnp_interval[0] | |
1038 | != DEFAULT_CSNP_INTERVAL) { | |
7c0cbd0e | 1039 | vty_out(vty, " " PROTO_NAME " csnp-interval %d\n", |
d62a17ae | 1040 | circuit->csnp_interval[0]); |
1041 | write++; | |
1042 | } | |
1043 | } else { | |
1044 | for (i = 0; i < 2; i++) { | |
1045 | if (circuit->csnp_interval[i] | |
1046 | != DEFAULT_CSNP_INTERVAL) { | |
1047 | vty_out(vty, | |
7c0cbd0e | 1048 | " " PROTO_NAME " csnp-interval %d level-%d\n", |
d62a17ae | 1049 | circuit->csnp_interval |
1050 | [i], | |
1051 | i + 1); | |
1052 | write++; | |
1053 | } | |
1054 | } | |
1055 | } | |
1056 | ||
1057 | /* ISIS - PSNP interval */ | |
1058 | if (circuit->psnp_interval[0] | |
1059 | == circuit->psnp_interval[1]) { | |
1060 | if (circuit->psnp_interval[0] | |
1061 | != DEFAULT_PSNP_INTERVAL) { | |
7c0cbd0e | 1062 | vty_out(vty, " " PROTO_NAME " psnp-interval %d\n", |
d62a17ae | 1063 | circuit->psnp_interval[0]); |
1064 | write++; | |
1065 | } | |
1066 | } else { | |
1067 | for (i = 0; i < 2; i++) { | |
1068 | if (circuit->psnp_interval[i] | |
1069 | != DEFAULT_PSNP_INTERVAL) { | |
1070 | vty_out(vty, | |
7c0cbd0e | 1071 | " " PROTO_NAME " psnp-interval %d level-%d\n", |
d62a17ae | 1072 | circuit->psnp_interval |
1073 | [i], | |
1074 | i + 1); | |
1075 | write++; | |
1076 | } | |
1077 | } | |
1078 | } | |
1079 | ||
1080 | /* ISIS - Hello padding - Defaults to true so only | |
1081 | * display if false */ | |
1082 | if (circuit->pad_hellos == 0) { | |
7c0cbd0e | 1083 | vty_out(vty, " no " PROTO_NAME " hello padding\n"); |
d62a17ae | 1084 | write++; |
1085 | } | |
1086 | ||
58e5d748 CF |
1087 | if (circuit->disable_threeway_adj) { |
1088 | vty_out(vty, " no isis three-way-handshake\n"); | |
1089 | write++; | |
1090 | } | |
1091 | ||
d62a17ae | 1092 | /* ISIS - Hello interval */ |
1093 | if (circuit->hello_interval[0] | |
1094 | == circuit->hello_interval[1]) { | |
1095 | if (circuit->hello_interval[0] | |
1096 | != DEFAULT_HELLO_INTERVAL) { | |
1097 | vty_out(vty, | |
7c0cbd0e | 1098 | " " PROTO_NAME " hello-interval %d\n", |
d62a17ae | 1099 | circuit->hello_interval[0]); |
1100 | write++; | |
1101 | } | |
1102 | } else { | |
1103 | for (i = 0; i < 2; i++) { | |
1104 | if (circuit->hello_interval[i] | |
1105 | != DEFAULT_HELLO_INTERVAL) { | |
1106 | vty_out(vty, | |
7c0cbd0e | 1107 | " " PROTO_NAME " hello-interval %d level-%d\n", |
d62a17ae | 1108 | circuit->hello_interval |
1109 | [i], | |
1110 | i + 1); | |
1111 | write++; | |
1112 | } | |
1113 | } | |
1114 | } | |
1115 | ||
1116 | /* ISIS - Hello Multiplier */ | |
1117 | if (circuit->hello_multiplier[0] | |
1118 | == circuit->hello_multiplier[1]) { | |
1119 | if (circuit->hello_multiplier[0] | |
1120 | != DEFAULT_HELLO_MULTIPLIER) { | |
1121 | vty_out(vty, | |
7c0cbd0e | 1122 | " " PROTO_NAME " hello-multiplier %d\n", |
d62a17ae | 1123 | circuit->hello_multiplier[0]); |
1124 | write++; | |
1125 | } | |
1126 | } else { | |
1127 | for (i = 0; i < 2; i++) { | |
1128 | if (circuit->hello_multiplier[i] | |
1129 | != DEFAULT_HELLO_MULTIPLIER) { | |
1130 | vty_out(vty, | |
7c0cbd0e | 1131 | " " PROTO_NAME " hello-multiplier %d level-%d\n", |
d62a17ae | 1132 | circuit->hello_multiplier |
1133 | [i], | |
1134 | i + 1); | |
1135 | write++; | |
1136 | } | |
1137 | } | |
1138 | } | |
1139 | ||
1140 | /* ISIS - Priority */ | |
1141 | if (circuit->priority[0] == circuit->priority[1]) { | |
1142 | if (circuit->priority[0] != DEFAULT_PRIORITY) { | |
7c0cbd0e | 1143 | vty_out(vty, " " PROTO_NAME " priority %d\n", |
d62a17ae | 1144 | circuit->priority[0]); |
1145 | write++; | |
1146 | } | |
1147 | } else { | |
1148 | for (i = 0; i < 2; i++) { | |
1149 | if (circuit->priority[i] | |
1150 | != DEFAULT_PRIORITY) { | |
1151 | vty_out(vty, | |
7c0cbd0e | 1152 | " " PROTO_NAME " priority %d level-%d\n", |
d62a17ae | 1153 | circuit->priority[i], |
1154 | i + 1); | |
1155 | write++; | |
1156 | } | |
1157 | } | |
1158 | } | |
1159 | ||
1160 | /* ISIS - Metric */ | |
1161 | if (circuit->te_metric[0] == circuit->te_metric[1]) { | |
1162 | if (circuit->te_metric[0] | |
1163 | != DEFAULT_CIRCUIT_METRIC) { | |
7c0cbd0e | 1164 | vty_out(vty, " " PROTO_NAME " metric %d\n", |
d62a17ae | 1165 | circuit->te_metric[0]); |
1166 | write++; | |
1167 | } | |
1168 | } else { | |
1169 | for (i = 0; i < 2; i++) { | |
1170 | if (circuit->te_metric[i] | |
1171 | != DEFAULT_CIRCUIT_METRIC) { | |
1172 | vty_out(vty, | |
7c0cbd0e | 1173 | " " PROTO_NAME " metric %d level-%d\n", |
d62a17ae | 1174 | circuit->te_metric[i], |
1175 | i + 1); | |
1176 | write++; | |
1177 | } | |
1178 | } | |
1179 | } | |
1180 | if (circuit->passwd.type == ISIS_PASSWD_TYPE_HMAC_MD5) { | |
7c0cbd0e | 1181 | vty_out(vty, " " PROTO_NAME " password md5 %s\n", |
d62a17ae | 1182 | circuit->passwd.passwd); |
1183 | write++; | |
1184 | } else if (circuit->passwd.type | |
1185 | == ISIS_PASSWD_TYPE_CLEARTXT) { | |
7c0cbd0e | 1186 | vty_out(vty, " " PROTO_NAME " password clear %s\n", |
d62a17ae | 1187 | circuit->passwd.passwd); |
1188 | write++; | |
1189 | } | |
5489eb45 CF |
1190 | write += hook_call(isis_circuit_config_write, |
1191 | circuit, vty); | |
d62a17ae | 1192 | } |
a8b828f3 | 1193 | vty_endframe(vty, "!\n"); |
d62a17ae | 1194 | } |
1195 | ||
1196 | return write; | |
eb5d44eb | 1197 | } |
20600086 EDP |
1198 | #else |
1199 | int isis_interface_config_write(struct vty *vty) | |
1200 | { | |
1201 | struct vrf *vrf = vrf_lookup_by_id(VRF_DEFAULT); | |
1202 | int write = 0; | |
1203 | struct interface *ifp; | |
1204 | struct isis_circuit *circuit; | |
1205 | struct lyd_node *dnode; | |
1206 | ||
1207 | FOR_ALL_INTERFACES (vrf, ifp) { | |
1208 | dnode = yang_dnode_get( | |
1209 | running_config->dnode, | |
1210 | "/frr-interface:lib/interface[name='%s'][vrf='%s']", | |
1211 | ifp->name, vrf->name); | |
1212 | if (dnode == NULL) | |
1213 | continue; | |
1214 | ||
1215 | write++; | |
1216 | nb_cli_show_dnode_cmds(vty, dnode, false); | |
1217 | circuit = circuit_scan_by_ifp(ifp); | |
1218 | if (circuit) | |
1219 | write += hook_call(isis_circuit_config_write, circuit, | |
1220 | vty); | |
1221 | } | |
1222 | return write; | |
1223 | } | |
1224 | #endif /* ifdef FABRICD */ | |
eb5d44eb | 1225 | |
d62a17ae | 1226 | struct isis_circuit *isis_circuit_create(struct isis_area *area, |
1227 | struct interface *ifp) | |
eb5d44eb | 1228 | { |
d62a17ae | 1229 | struct isis_circuit *circuit = circuit_scan_by_ifp(ifp); |
1230 | if (circuit && circuit->area) | |
1231 | return NULL; | |
1232 | circuit = isis_csm_state_change(ISIS_ENABLE, circuit, area); | |
1233 | if (circuit->state != C_STATE_CONF && circuit->state != C_STATE_UP) | |
1234 | return circuit; | |
1235 | isis_circuit_if_bind(circuit, ifp); | |
1236 | return circuit; | |
eb5d44eb | 1237 | } |
1238 | ||
d62a17ae | 1239 | void isis_circuit_af_set(struct isis_circuit *circuit, bool ip_router, |
1240 | bool ipv6_router) | |
eb5d44eb | 1241 | { |
d62a17ae | 1242 | struct isis_area *area = circuit->area; |
1243 | bool change = circuit->ip_router != ip_router | |
1244 | || circuit->ipv6_router != ipv6_router; | |
d62a17ae | 1245 | |
1246 | area->ip_circuits += ip_router - circuit->ip_router; | |
1247 | area->ipv6_circuits += ipv6_router - circuit->ipv6_router; | |
1248 | circuit->ip_router = ip_router; | |
1249 | circuit->ipv6_router = ipv6_router; | |
1250 | ||
1251 | if (!change) | |
1252 | return; | |
1253 | ||
1254 | circuit_update_nlpids(circuit); | |
1255 | ||
1256 | if (!ip_router && !ipv6_router) | |
1257 | isis_csm_state_change(ISIS_DISABLE, circuit, area); | |
d62a17ae | 1258 | else |
1259 | lsp_regenerate_schedule(circuit->area, circuit->is_type, 0); | |
3f045a08 | 1260 | } |
eb5d44eb | 1261 | |
64dd3ffe | 1262 | ferr_r isis_circuit_passive_set(struct isis_circuit *circuit, bool passive) |
3f045a08 | 1263 | { |
d62a17ae | 1264 | if (circuit->is_passive == passive) |
64dd3ffe | 1265 | return ferr_ok(); |
d62a17ae | 1266 | |
1267 | if (if_is_loopback(circuit->interface) && !passive) | |
64dd3ffe | 1268 | return ferr_cfg_invalid("loopback is always passive"); |
d62a17ae | 1269 | |
1270 | if (circuit->state != C_STATE_UP) { | |
1271 | circuit->is_passive = passive; | |
1272 | } else { | |
1273 | struct isis_area *area = circuit->area; | |
1274 | isis_csm_state_change(ISIS_DISABLE, circuit, area); | |
1275 | circuit->is_passive = passive; | |
1276 | isis_csm_state_change(ISIS_ENABLE, circuit, area); | |
1277 | } | |
1278 | ||
64dd3ffe | 1279 | return ferr_ok(); |
eb5d44eb | 1280 | } |
1281 | ||
64dd3ffe DL |
1282 | ferr_r isis_circuit_metric_set(struct isis_circuit *circuit, int level, |
1283 | int metric) | |
3f045a08 | 1284 | { |
d62a17ae | 1285 | assert(level == IS_LEVEL_1 || level == IS_LEVEL_2); |
1286 | if (metric > MAX_WIDE_LINK_METRIC) | |
64dd3ffe DL |
1287 | return ferr_cfg_invalid("metric %d too large for wide metric", |
1288 | metric); | |
d62a17ae | 1289 | if (circuit->area && circuit->area->oldmetric |
1290 | && metric > MAX_NARROW_LINK_METRIC) | |
64dd3ffe DL |
1291 | return ferr_cfg_invalid("metric %d too large for narrow metric", |
1292 | metric); | |
d62a17ae | 1293 | |
1294 | circuit->te_metric[level - 1] = metric; | |
1295 | circuit->metric[level - 1] = metric; | |
1296 | ||
1297 | if (circuit->area) | |
1298 | lsp_regenerate_schedule(circuit->area, level, 0); | |
64dd3ffe | 1299 | return ferr_ok(); |
eb5d44eb | 1300 | } |
1301 | ||
64dd3ffe | 1302 | ferr_r isis_circuit_passwd_unset(struct isis_circuit *circuit) |
eb5d44eb | 1303 | { |
d62a17ae | 1304 | memset(&circuit->passwd, 0, sizeof(circuit->passwd)); |
64dd3ffe | 1305 | return ferr_ok(); |
3f045a08 JB |
1306 | } |
1307 | ||
e28544ed QY |
1308 | ferr_r isis_circuit_passwd_set(struct isis_circuit *circuit, |
1309 | uint8_t passwd_type, const char *passwd) | |
3f045a08 | 1310 | { |
d62a17ae | 1311 | int len; |
f390d2c7 | 1312 | |
d62a17ae | 1313 | if (!passwd) |
64dd3ffe | 1314 | return ferr_code_bug("no circuit password given"); |
50c7d14a | 1315 | |
d62a17ae | 1316 | len = strlen(passwd); |
1317 | if (len > 254) | |
64dd3ffe DL |
1318 | return ferr_code_bug( |
1319 | "circuit password too long (max 254 chars)"); | |
f390d2c7 | 1320 | |
d62a17ae | 1321 | circuit->passwd.len = len; |
e28544ed QY |
1322 | strlcpy((char *)circuit->passwd.passwd, passwd, |
1323 | sizeof(circuit->passwd.passwd)); | |
d62a17ae | 1324 | circuit->passwd.type = passwd_type; |
64dd3ffe | 1325 | return ferr_ok(); |
eb5d44eb | 1326 | } |
1327 | ||
64dd3ffe DL |
1328 | ferr_r isis_circuit_passwd_cleartext_set(struct isis_circuit *circuit, |
1329 | const char *passwd) | |
eb5d44eb | 1330 | { |
d62a17ae | 1331 | return isis_circuit_passwd_set(circuit, ISIS_PASSWD_TYPE_CLEARTXT, |
1332 | passwd); | |
50c7d14a | 1333 | } |
f390d2c7 | 1334 | |
64dd3ffe DL |
1335 | ferr_r isis_circuit_passwd_hmac_md5_set(struct isis_circuit *circuit, |
1336 | const char *passwd) | |
50c7d14a | 1337 | { |
d62a17ae | 1338 | return isis_circuit_passwd_set(circuit, ISIS_PASSWD_TYPE_HMAC_MD5, |
1339 | passwd); | |
eb5d44eb | 1340 | } |
64dd3ffe | 1341 | |
3f045a08 | 1342 | struct cmd_node interface_node = { |
9d303b37 | 1343 | INTERFACE_NODE, "%s(config-if)# ", 1, |
eb5d44eb | 1344 | }; |
1345 | ||
d0820765 | 1346 | void isis_circuit_circ_type_set(struct isis_circuit *circuit, int circ_type) |
3f045a08 | 1347 | { |
64dd3ffe | 1348 | if (circuit->circ_type == circ_type) |
d0820765 | 1349 | return; |
d62a17ae | 1350 | |
d62a17ae | 1351 | if (circuit->state != C_STATE_UP) { |
1352 | circuit->circ_type = circ_type; | |
1353 | circuit->circ_type_config = circ_type; | |
1354 | } else { | |
1355 | struct isis_area *area = circuit->area; | |
d62a17ae | 1356 | |
1357 | isis_csm_state_change(ISIS_DISABLE, circuit, area); | |
1358 | circuit->circ_type = circ_type; | |
1359 | circuit->circ_type_config = circ_type; | |
1360 | isis_csm_state_change(ISIS_ENABLE, circuit, area); | |
1361 | } | |
3f045a08 JB |
1362 | } |
1363 | ||
d62a17ae | 1364 | int isis_circuit_mt_enabled_set(struct isis_circuit *circuit, uint16_t mtid, |
1365 | bool enabled) | |
064f4896 | 1366 | { |
d62a17ae | 1367 | struct isis_circuit_mt_setting *setting; |
064f4896 | 1368 | |
d62a17ae | 1369 | setting = circuit_get_mt_setting(circuit, mtid); |
1370 | if (setting->enabled != enabled) { | |
1371 | setting->enabled = enabled; | |
1372 | lsp_regenerate_schedule(circuit->area, IS_LEVEL_1 | IS_LEVEL_2, | |
1373 | 0); | |
1374 | } | |
064f4896 | 1375 | |
d62a17ae | 1376 | return CMD_SUCCESS; |
064f4896 CF |
1377 | } |
1378 | ||
d62a17ae | 1379 | int isis_if_new_hook(struct interface *ifp) |
eb5d44eb | 1380 | { |
d62a17ae | 1381 | return 0; |
eb5d44eb | 1382 | } |
1383 | ||
d62a17ae | 1384 | int isis_if_delete_hook(struct interface *ifp) |
eb5d44eb | 1385 | { |
d62a17ae | 1386 | struct isis_circuit *circuit; |
1387 | /* Clean up the circuit data */ | |
1388 | if (ifp && ifp->info) { | |
1389 | circuit = ifp->info; | |
1390 | isis_csm_state_change(IF_DOWN_FROM_Z, circuit, circuit->area); | |
1391 | isis_csm_state_change(ISIS_DISABLE, circuit, circuit->area); | |
1392 | } | |
1393 | ||
1394 | return 0; | |
eb5d44eb | 1395 | } |
1396 | ||
4d762f26 | 1397 | void isis_circuit_init(void) |
eb5d44eb | 1398 | { |
d62a17ae | 1399 | /* Initialize Zebra interface data structure */ |
ce19a04a DL |
1400 | hook_register_prio(if_add, 0, isis_if_new_hook); |
1401 | hook_register_prio(if_del, 0, isis_if_delete_hook); | |
eb5d44eb | 1402 | |
d62a17ae | 1403 | /* Install interface node */ |
1404 | install_node(&interface_node, isis_interface_config_write); | |
1405 | if_cmd_init(); | |
eb5d44eb | 1406 | } |