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