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