]> git.proxmox.com Git - mirror_frr.git/blame - isisd/isis_circuit.c
*: move CLI node names to cmd_node->name
[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_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);
63265b5c 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(
d6951e5e 347 "Nonexistent ip address %s removal attempt from circuit %s",
c59f88c8 348 buf, circuit->interface->name);
d62a17ae 349 zlog_warn("Current ip addresses on %s:",
350 circuit->interface->name);
351 for (ALL_LIST_ELEMENTS_RO(circuit->ip_addrs, node,
352 ip)) {
353 prefix2str(ip, buf, sizeof(buf));
354 zlog_warn(" %s", buf);
355 }
356 zlog_warn("End of addresses");
357 }
358
63265b5c 359 prefix_ipv4_free(&ipv4);
f891f443 360 }
d62a17ae 361 if (connected->address->family == AF_INET6) {
362 ipv6 = prefix_ipv6_new();
363 ipv6->prefixlen = connected->address->prefixlen;
364 ipv6->prefix = connected->address->u.prefix6;
365
366 if (IN6_IS_ADDR_LINKLOCAL(&ipv6->prefix)) {
367 for (ALL_LIST_ELEMENTS_RO(circuit->ipv6_link, node,
368 ip6)) {
369 if (prefix_same((struct prefix *)ip6,
370 (struct prefix *)ipv6))
371 break;
372 }
373 if (ip6) {
374 listnode_delete(circuit->ipv6_link, ip6);
63265b5c 375 prefix_ipv6_free(&ip6);
d62a17ae 376 found = 1;
377 }
378 } else {
379 for (ALL_LIST_ELEMENTS_RO(circuit->ipv6_non_link, node,
380 ip6)) {
381 if (prefix_same((struct prefix *)ip6,
382 (struct prefix *)ipv6))
383 break;
384 }
385 if (ip6) {
386 listnode_delete(circuit->ipv6_non_link, ip6);
63265b5c 387 prefix_ipv6_free(&ip6);
d62a17ae 388 found = 1;
389 }
390 }
391
392 if (!found) {
393 prefix2str(connected->address, buf, sizeof(buf));
394 zlog_warn(
d6951e5e 395 "Nonexistent ip address %s removal attempt from circuit %s",
c59f88c8 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
63265b5c 417 prefix_ipv6_free(&ipv6);
f891f443 418 }
d62a17ae 419 return;
420}
e8aca32f 421
0849c75e 422static 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 452void 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);
1b3f47d0 482
eb5d44eb 483}
484
d62a17ae 485void isis_circuit_if_del(struct isis_circuit *circuit, struct interface *ifp)
eb5d44eb 486{
d62a17ae 487 struct listnode *node, *nnode;
488 struct connected *conn;
489
490 assert(circuit->interface == ifp);
491
492 /* destroy addresses */
493 for (ALL_LIST_ELEMENTS(ifp->connected, node, nnode, conn))
494 isis_circuit_del_addr(circuit, conn);
495
496 if (circuit->ip_addrs) {
497 assert(listcount(circuit->ip_addrs) == 0);
6a154c88 498 list_delete(&circuit->ip_addrs);
d62a17ae 499 }
500
501 if (circuit->ipv6_link) {
502 assert(listcount(circuit->ipv6_link) == 0);
6a154c88 503 list_delete(&circuit->ipv6_link);
d62a17ae 504 }
505
506 if (circuit->ipv6_non_link) {
507 assert(listcount(circuit->ipv6_non_link) == 0);
6a154c88 508 list_delete(&circuit->ipv6_non_link);
d62a17ae 509 }
510
511 circuit->circ_type = CIRCUIT_T_UNKNOWN;
eb5d44eb 512}
513
d62a17ae 514void isis_circuit_if_bind(struct isis_circuit *circuit, struct interface *ifp)
3f045a08 515{
d62a17ae 516 assert(circuit != NULL);
517 assert(ifp != NULL);
518 if (circuit->interface)
519 assert(circuit->interface == ifp);
520 else
521 circuit->interface = ifp;
522 if (ifp->info)
523 assert(ifp->info == circuit);
524 else
525 ifp->info = circuit;
3f045a08
JB
526}
527
d62a17ae 528void 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 538static 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;
d62a17ae 543 int level;
544
545 assert(circuit);
546 area = circuit->area;
547 assert(area);
548 for (level = ISIS_LEVEL1; level <= ISIS_LEVEL2; level++) {
9b39405f
CF
549 if (!(level & circuit->is_type))
550 continue;
551
4bef0ec4 552 if (!lspdb_count(&area->lspdb[level - 1]))
9b39405f
CF
553 continue;
554
81fddbe7 555 frr_each (lspdb, &area->lspdb[level - 1], lsp) {
9b39405f
CF
556 if (is_set) {
557 isis_tx_queue_add(circuit->tx_queue, lsp,
558 TX_LSP_NORMAL);
559 } else {
560 isis_tx_queue_del(circuit->tx_queue, lsp);
d62a17ae 561 }
562 }
563 }
eb5d44eb 564}
565
d62a17ae 566size_t isis_circuit_pdu_size(struct isis_circuit *circuit)
b20ccb3a 567{
d62a17ae 568 return ISO_MTU(circuit);
b20ccb3a
CF
569}
570
d62a17ae 571void isis_circuit_stream(struct isis_circuit *circuit, struct stream **stream)
b20ccb3a 572{
d62a17ae 573 size_t stream_size = isis_circuit_pdu_size(circuit);
574
575 if (!*stream) {
576 *stream = stream_new(stream_size);
577 } else {
578 if (STREAM_SIZE(*stream) != stream_size)
db3c830a 579 stream_resize_inplace(stream, stream_size);
d62a17ae 580 stream_reset(*stream);
581 }
b20ccb3a
CF
582}
583
d62a17ae 584void isis_circuit_prepare(struct isis_circuit *circuit)
5904f19f 585{
b0dd98e7 586#if ISIS_METHOD != ISIS_METHOD_DLPI
d62a17ae 587 thread_add_read(master, isis_receive, circuit, circuit->fd,
588 &circuit->t_read);
5904f19f 589#else
d62a17ae 590 thread_add_timer_msec(master, isis_receive, circuit,
591 listcount(circuit->area->circuit_list) * 100,
592 &circuit->t_read);
5904f19f
RW
593#endif
594}
595
d62a17ae 596int isis_circuit_up(struct isis_circuit *circuit)
eb5d44eb 597{
d62a17ae 598 int retv;
599
600 /* Set the flags for all the lsps of the circuit. */
601 isis_circuit_update_all_srmflags(circuit, 1);
602
603 if (circuit->state == C_STATE_UP)
604 return ISIS_OK;
605
606 if (circuit->is_passive)
607 return ISIS_OK;
608
609 if (circuit->area->lsp_mtu > isis_circuit_pdu_size(circuit)) {
af4c2728 610 flog_err(
1a7ecb96 611 EC_ISIS_CONFIG,
d62a17ae 612 "Interface MTU %zu on %s is too low to support area lsp mtu %u!",
613 isis_circuit_pdu_size(circuit),
614 circuit->interface->name, circuit->area->lsp_mtu);
615 isis_circuit_update_all_srmflags(circuit, 0);
616 return ISIS_ERROR;
617 }
618
619 if (circuit->circ_type == CIRCUIT_T_BROADCAST) {
0849c75e
CF
620 circuit->circuit_id = isis_circuit_id_gen(isis, circuit->interface);
621 if (!circuit->circuit_id) {
af4c2728 622 flog_err(
1a7ecb96 623 EC_ISIS_CONFIG,
54ece698 624 "There are already 255 broadcast circuits active!");
0849c75e
CF
625 return ISIS_ERROR;
626 }
627
d62a17ae 628 /*
629 * Get the Hardware Address
630 */
631 if (circuit->interface->hw_addr_len != ETH_ALEN) {
632 zlog_warn("unsupported link layer");
633 } else {
634 memcpy(circuit->u.bc.snpa, circuit->interface->hw_addr,
635 ETH_ALEN);
636 }
3f045a08 637#ifdef EXTREME_DEGUG
d62a17ae 638 zlog_debug("isis_circuit_if_add: if_id %d, isomtu %d snpa %s",
639 circuit->interface->ifindex, ISO_MTU(circuit),
640 snpa_print(circuit->u.bc.snpa));
3f045a08 641#endif /* EXTREME_DEBUG */
3f045a08 642
d62a17ae 643 circuit->u.bc.adjdb[0] = list_new();
644 circuit->u.bc.adjdb[1] = list_new();
645
646 /*
647 * ISO 10589 - 8.4.1 Enabling of broadcast circuits
648 */
649
650 /* initilizing the hello sending threads
651 * for a broadcast IF
652 */
653
654 /* 8.4.1 a) commence sending of IIH PDUs */
655
7c4f7aab
CF
656 for (int level = ISIS_LEVEL1; level <= ISIS_LEVEL2; level++) {
657 if (!(circuit->is_type & level))
658 continue;
659
a0a707ee 660 send_hello_sched(circuit, level, TRIGGERED_IIH_DELAY);
7c4f7aab
CF
661 circuit->u.bc.lan_neighs[level - 1] = list_new();
662
663 thread_add_timer(master, isis_run_dr,
664 &circuit->level_arg[level - 1],
665 2 * circuit->hello_interval[level - 1],
666 &circuit->u.bc.t_run_dr[level - 1]);
d62a17ae 667 }
668
669 /* 8.4.1 b) FIXME: solicit ES - 8.4.6 */
670 /* 8.4.1 c) FIXME: listen for ESH PDUs */
d4670f51 671 } else if (circuit->circ_type == CIRCUIT_T_P2P) {
d62a17ae 672 /* initializing the hello send threads
673 * for a ptp IF
674 */
675 circuit->u.p2p.neighbor = NULL;
a0a707ee 676 send_hello_sched(circuit, 0, TRIGGERED_IIH_DELAY);
d62a17ae 677 }
678
679 /* initializing PSNP timers */
680 if (circuit->is_type & IS_LEVEL_1)
681 thread_add_timer(
682 master, send_l1_psnp, circuit,
683 isis_jitter(circuit->psnp_interval[0], PSNP_JITTER),
684 &circuit->t_send_psnp[0]);
685
686 if (circuit->is_type & IS_LEVEL_2)
687 thread_add_timer(
688 master, send_l2_psnp, circuit,
689 isis_jitter(circuit->psnp_interval[1], PSNP_JITTER),
690 &circuit->t_send_psnp[1]);
691
692 /* unified init for circuits; ignore warnings below this level */
693 retv = isis_sock_init(circuit);
694 if (retv != ISIS_OK) {
695 isis_circuit_down(circuit);
696 return retv;
697 }
698
699 /* initialize the circuit streams after opening connection */
700 isis_circuit_stream(circuit, &circuit->rcv_stream);
701 isis_circuit_stream(circuit, &circuit->snd_stream);
702
703 isis_circuit_prepare(circuit);
704
9b39405f 705 circuit->tx_queue = isis_tx_queue_new(circuit, send_lsp);
d62a17ae 706
392b89f3
EDP
707#ifndef FABRICD
708 /* send northbound notification */
709 isis_notif_if_state_change(circuit, false);
710#endif /* ifndef FABRICD */
711
d62a17ae 712 return ISIS_OK;
eb5d44eb 713}
714
d62a17ae 715void isis_circuit_down(struct isis_circuit *circuit)
eb5d44eb 716{
392b89f3
EDP
717#ifndef FABRICD
718 /* send northbound notification */
719 isis_notif_if_state_change(circuit, true);
720#endif /* ifndef FABRICD */
721
d62a17ae 722 /* Clear the flags for all the lsps of the circuit. */
723 isis_circuit_update_all_srmflags(circuit, 0);
724
725 if (circuit->circ_type == CIRCUIT_T_BROADCAST) {
726 /* destroy neighbour lists */
727 if (circuit->u.bc.lan_neighs[0]) {
6a154c88 728 list_delete(&circuit->u.bc.lan_neighs[0]);
d62a17ae 729 circuit->u.bc.lan_neighs[0] = NULL;
730 }
731 if (circuit->u.bc.lan_neighs[1]) {
6a154c88 732 list_delete(&circuit->u.bc.lan_neighs[1]);
d62a17ae 733 circuit->u.bc.lan_neighs[1] = NULL;
734 }
735 /* destroy adjacency databases */
736 if (circuit->u.bc.adjdb[0]) {
737 circuit->u.bc.adjdb[0]->del = isis_delete_adj;
6a154c88 738 list_delete(&circuit->u.bc.adjdb[0]);
d62a17ae 739 circuit->u.bc.adjdb[0] = NULL;
740 }
741 if (circuit->u.bc.adjdb[1]) {
742 circuit->u.bc.adjdb[1]->del = isis_delete_adj;
6a154c88 743 list_delete(&circuit->u.bc.adjdb[1]);
d62a17ae 744 circuit->u.bc.adjdb[1] = NULL;
745 }
746 if (circuit->u.bc.is_dr[0]) {
747 isis_dr_resign(circuit, 1);
748 circuit->u.bc.is_dr[0] = 0;
749 }
750 memset(circuit->u.bc.l1_desig_is, 0, ISIS_SYS_ID_LEN + 1);
751 if (circuit->u.bc.is_dr[1]) {
752 isis_dr_resign(circuit, 2);
753 circuit->u.bc.is_dr[1] = 0;
754 }
755 memset(circuit->u.bc.l2_desig_is, 0, ISIS_SYS_ID_LEN + 1);
756 memset(circuit->u.bc.snpa, 0, ETH_ALEN);
757
758 THREAD_TIMER_OFF(circuit->u.bc.t_send_lan_hello[0]);
759 THREAD_TIMER_OFF(circuit->u.bc.t_send_lan_hello[1]);
760 THREAD_TIMER_OFF(circuit->u.bc.t_run_dr[0]);
761 THREAD_TIMER_OFF(circuit->u.bc.t_run_dr[1]);
762 THREAD_TIMER_OFF(circuit->u.bc.t_refresh_pseudo_lsp[0]);
763 THREAD_TIMER_OFF(circuit->u.bc.t_refresh_pseudo_lsp[1]);
764 circuit->lsp_regenerate_pending[0] = 0;
765 circuit->lsp_regenerate_pending[1] = 0;
0849c75e
CF
766
767 _ISIS_CLEAR_FLAG(isis->circuit_ids_used, circuit->circuit_id);
768 circuit->circuit_id = 0;
d62a17ae 769 } else if (circuit->circ_type == CIRCUIT_T_P2P) {
770 isis_delete_adj(circuit->u.p2p.neighbor);
771 circuit->u.p2p.neighbor = NULL;
772 THREAD_TIMER_OFF(circuit->u.p2p.t_send_p2p_hello);
773 }
774
775 /* Cancel all active threads */
776 THREAD_TIMER_OFF(circuit->t_send_csnp[0]);
777 THREAD_TIMER_OFF(circuit->t_send_csnp[1]);
778 THREAD_TIMER_OFF(circuit->t_send_psnp[0]);
779 THREAD_TIMER_OFF(circuit->t_send_psnp[1]);
780 THREAD_OFF(circuit->t_read);
781
9b39405f
CF
782 if (circuit->tx_queue) {
783 isis_tx_queue_free(circuit->tx_queue);
784 circuit->tx_queue = NULL;
58e16237
CF
785 }
786
d62a17ae 787 /* send one gratuitous hello to spead up convergence */
d4670f51
CF
788 if (circuit->state == C_STATE_UP) {
789 if (circuit->is_type & IS_LEVEL_1)
790 send_hello(circuit, IS_LEVEL_1);
791 if (circuit->is_type & IS_LEVEL_2)
792 send_hello(circuit, IS_LEVEL_2);
793 }
d62a17ae 794
795 circuit->upadjcount[0] = 0;
796 circuit->upadjcount[1] = 0;
797
798 /* close the socket */
799 if (circuit->fd) {
800 close(circuit->fd);
801 circuit->fd = 0;
802 }
803
804 if (circuit->rcv_stream != NULL) {
805 stream_free(circuit->rcv_stream);
806 circuit->rcv_stream = NULL;
807 }
808
809 if (circuit->snd_stream != NULL) {
810 stream_free(circuit->snd_stream);
811 circuit->snd_stream = NULL;
812 }
813
814 thread_cancel_event(master, circuit);
815
816 return;
eb5d44eb 817}
818
d62a17ae 819void circuit_update_nlpids(struct isis_circuit *circuit)
eb5d44eb 820{
d62a17ae 821 circuit->nlpids.count = 0;
822
823 if (circuit->ip_router) {
824 circuit->nlpids.nlpids[0] = NLPID_IP;
825 circuit->nlpids.count++;
826 }
827 if (circuit->ipv6_router) {
828 circuit->nlpids.nlpids[circuit->nlpids.count] = NLPID_IPV6;
829 circuit->nlpids.count++;
830 }
831 return;
eb5d44eb 832}
833
d62a17ae 834void isis_circuit_print_vty(struct isis_circuit *circuit, struct vty *vty,
835 char detail)
3f045a08 836{
d62a17ae 837 if (detail == ISIS_UI_LEVEL_BRIEF) {
838 vty_out(vty, " %-12s", circuit->interface->name);
839 vty_out(vty, "0x%-7x", circuit->circuit_id);
840 vty_out(vty, "%-9s", circuit_state2string(circuit->state));
841 vty_out(vty, "%-9s", circuit_type2string(circuit->circ_type));
842 vty_out(vty, "%-9s", circuit_t2string(circuit->is_type));
843 vty_out(vty, "\n");
844 }
845
846 if (detail == ISIS_UI_LEVEL_DETAIL) {
847 struct listnode *node;
848 struct prefix *ip_addr;
849 char buf[BUFSIZ];
850
851 vty_out(vty, " Interface: %s", circuit->interface->name);
852 vty_out(vty, ", State: %s",
853 circuit_state2string(circuit->state));
854 if (circuit->is_passive)
855 vty_out(vty, ", Passive");
856 else
857 vty_out(vty, ", Active");
858 vty_out(vty, ", Circuit Id: 0x%x", circuit->circuit_id);
859 vty_out(vty, "\n");
860 vty_out(vty, " Type: %s",
861 circuit_type2string(circuit->circ_type));
862 vty_out(vty, ", Level: %s", circuit_t2string(circuit->is_type));
863 if (circuit->circ_type == CIRCUIT_T_BROADCAST)
864 vty_out(vty, ", SNPA: %-10s",
865 snpa_print(circuit->u.bc.snpa));
866 vty_out(vty, "\n");
867 if (circuit->is_type & IS_LEVEL_1) {
868 vty_out(vty, " Level-1 Information:\n");
869 if (circuit->area->newmetric)
870 vty_out(vty, " Metric: %d",
871 circuit->te_metric[0]);
872 else
873 vty_out(vty, " Metric: %d",
874 circuit->metric[0]);
875 if (!circuit->is_passive) {
876 vty_out(vty, ", Active neighbors: %u\n",
877 circuit->upadjcount[0]);
878 vty_out(vty,
879 " Hello interval: %u, "
880 "Holddown count: %u %s\n",
881 circuit->hello_interval[0],
882 circuit->hello_multiplier[0],
883 (circuit->pad_hellos ? "(pad)"
884 : "(no-pad)"));
885 vty_out(vty,
886 " CNSP interval: %u, "
887 "PSNP interval: %u\n",
888 circuit->csnp_interval[0],
889 circuit->psnp_interval[0]);
890 if (circuit->circ_type == CIRCUIT_T_BROADCAST)
891 vty_out(vty,
892 " LAN Priority: %u, %s\n",
893 circuit->priority[0],
894 (circuit->u.bc.is_dr[0]
895 ? "is DIS"
896 : "is not DIS"));
897 } else {
898 vty_out(vty, "\n");
899 }
900 }
901 if (circuit->is_type & IS_LEVEL_2) {
902 vty_out(vty, " Level-2 Information:\n");
903 if (circuit->area->newmetric)
904 vty_out(vty, " Metric: %d",
905 circuit->te_metric[1]);
906 else
907 vty_out(vty, " Metric: %d",
908 circuit->metric[1]);
909 if (!circuit->is_passive) {
910 vty_out(vty, ", Active neighbors: %u\n",
911 circuit->upadjcount[1]);
912 vty_out(vty,
913 " Hello interval: %u, "
914 "Holddown count: %u %s\n",
915 circuit->hello_interval[1],
916 circuit->hello_multiplier[1],
917 (circuit->pad_hellos ? "(pad)"
918 : "(no-pad)"));
919 vty_out(vty,
920 " CNSP interval: %u, "
921 "PSNP interval: %u\n",
922 circuit->csnp_interval[1],
923 circuit->psnp_interval[1]);
924 if (circuit->circ_type == CIRCUIT_T_BROADCAST)
925 vty_out(vty,
926 " LAN Priority: %u, %s\n",
927 circuit->priority[1],
928 (circuit->u.bc.is_dr[1]
929 ? "is DIS"
930 : "is not DIS"));
931 } else {
932 vty_out(vty, "\n");
933 }
934 }
935 if (circuit->ip_addrs && listcount(circuit->ip_addrs) > 0) {
936 vty_out(vty, " IP Prefix(es):\n");
937 for (ALL_LIST_ELEMENTS_RO(circuit->ip_addrs, node,
938 ip_addr)) {
1445b43c
A
939 prefix2str(ip_addr, buf, sizeof(buf));
940 vty_out(vty, " %s\n", buf);
d62a17ae 941 }
942 }
943 if (circuit->ipv6_link && listcount(circuit->ipv6_link) > 0) {
944 vty_out(vty, " IPv6 Link-Locals:\n");
945 for (ALL_LIST_ELEMENTS_RO(circuit->ipv6_link, node,
946 ip_addr)) {
1445b43c
A
947 prefix2str(ip_addr, (char *)buf, BUFSIZ);
948 vty_out(vty, " %s\n", buf);
d62a17ae 949 }
950 }
951 if (circuit->ipv6_non_link
952 && listcount(circuit->ipv6_non_link) > 0) {
953 vty_out(vty, " IPv6 Prefixes:\n");
954 for (ALL_LIST_ELEMENTS_RO(circuit->ipv6_non_link, node,
955 ip_addr)) {
1445b43c
A
956 prefix2str(ip_addr, (char *)buf, BUFSIZ);
957 vty_out(vty, " %s\n", buf);
d62a17ae 958 }
959 }
960
961 vty_out(vty, "\n");
962 }
963 return;
3f045a08
JB
964}
965
d56afe53
CF
966DEFINE_HOOK(isis_circuit_config_write,
967 (struct isis_circuit *circuit, struct vty *vty),
968 (circuit, vty))
969
20600086 970#ifdef FABRICD
612c2c15 971static int isis_interface_config_write(struct vty *vty)
eb5d44eb 972{
f4e14fdb 973 struct vrf *vrf = vrf_lookup_by_id(VRF_DEFAULT);
d62a17ae 974 int write = 0;
f4e14fdb 975 struct listnode *node;
d62a17ae 976 struct interface *ifp;
977 struct isis_area *area;
978 struct isis_circuit *circuit;
979 int i;
980
451fda4f 981 FOR_ALL_INTERFACES (vrf, ifp) {
d62a17ae 982 /* IF name */
a8b828f3 983 vty_frame(vty, "interface %s\n", ifp->name);
d62a17ae 984 write++;
985 /* IF desc */
986 if (ifp->desc) {
987 vty_out(vty, " description %s\n", ifp->desc);
988 write++;
989 }
990 /* ISIS Circuit */
f4e14fdb 991 for (ALL_LIST_ELEMENTS_RO(isis->area_list, node, area)) {
d62a17ae 992 circuit =
993 circuit_lookup_by_ifp(ifp, area->circuit_list);
994 if (circuit == NULL)
995 continue;
996 if (circuit->ip_router) {
7c0cbd0e 997 vty_out(vty, " ip router " PROTO_NAME " %s\n",
d62a17ae 998 area->area_tag);
999 write++;
1000 }
1001 if (circuit->is_passive) {
7c0cbd0e 1002 vty_out(vty, " " PROTO_NAME " passive\n");
d62a17ae 1003 write++;
1004 }
1005 if (circuit->circ_type_config == CIRCUIT_T_P2P) {
7c0cbd0e 1006 vty_out(vty, " " PROTO_NAME " network point-to-point\n");
d62a17ae 1007 write++;
1008 }
1009 if (circuit->ipv6_router) {
7c0cbd0e 1010 vty_out(vty, " ipv6 router " PROTO_NAME " %s\n",
d62a17ae 1011 area->area_tag);
1012 write++;
1013 }
1014
1015 /* ISIS - circuit type */
65f18157
CF
1016 if (!fabricd) {
1017 if (circuit->is_type == IS_LEVEL_1) {
1018 vty_out(vty, " " PROTO_NAME " circuit-type level-1\n");
d62a17ae 1019 write++;
65f18157
CF
1020 } else {
1021 if (circuit->is_type == IS_LEVEL_2) {
1022 vty_out(vty,
1023 " " PROTO_NAME " circuit-type level-2-only\n");
1024 write++;
1025 }
d62a17ae 1026 }
1027 }
1028
1029 /* ISIS - CSNP interval */
1030 if (circuit->csnp_interval[0]
1031 == circuit->csnp_interval[1]) {
1032 if (circuit->csnp_interval[0]
1033 != DEFAULT_CSNP_INTERVAL) {
7c0cbd0e 1034 vty_out(vty, " " PROTO_NAME " csnp-interval %d\n",
d62a17ae 1035 circuit->csnp_interval[0]);
1036 write++;
1037 }
1038 } else {
1039 for (i = 0; i < 2; i++) {
1040 if (circuit->csnp_interval[i]
1041 != DEFAULT_CSNP_INTERVAL) {
1042 vty_out(vty,
7c0cbd0e 1043 " " PROTO_NAME " csnp-interval %d level-%d\n",
d62a17ae 1044 circuit->csnp_interval
1045 [i],
1046 i + 1);
1047 write++;
1048 }
1049 }
1050 }
1051
1052 /* ISIS - PSNP interval */
1053 if (circuit->psnp_interval[0]
1054 == circuit->psnp_interval[1]) {
1055 if (circuit->psnp_interval[0]
1056 != DEFAULT_PSNP_INTERVAL) {
7c0cbd0e 1057 vty_out(vty, " " PROTO_NAME " psnp-interval %d\n",
d62a17ae 1058 circuit->psnp_interval[0]);
1059 write++;
1060 }
1061 } else {
1062 for (i = 0; i < 2; i++) {
1063 if (circuit->psnp_interval[i]
1064 != DEFAULT_PSNP_INTERVAL) {
1065 vty_out(vty,
7c0cbd0e 1066 " " PROTO_NAME " psnp-interval %d level-%d\n",
d62a17ae 1067 circuit->psnp_interval
1068 [i],
1069 i + 1);
1070 write++;
1071 }
1072 }
1073 }
1074
1075 /* ISIS - Hello padding - Defaults to true so only
1076 * display if false */
1077 if (circuit->pad_hellos == 0) {
7c0cbd0e 1078 vty_out(vty, " no " PROTO_NAME " hello padding\n");
d62a17ae 1079 write++;
1080 }
1081
58e5d748
CF
1082 if (circuit->disable_threeway_adj) {
1083 vty_out(vty, " no isis three-way-handshake\n");
1084 write++;
1085 }
1086
d62a17ae 1087 /* ISIS - Hello interval */
1088 if (circuit->hello_interval[0]
1089 == circuit->hello_interval[1]) {
1090 if (circuit->hello_interval[0]
1091 != DEFAULT_HELLO_INTERVAL) {
1092 vty_out(vty,
7c0cbd0e 1093 " " PROTO_NAME " hello-interval %d\n",
d62a17ae 1094 circuit->hello_interval[0]);
1095 write++;
1096 }
1097 } else {
1098 for (i = 0; i < 2; i++) {
1099 if (circuit->hello_interval[i]
1100 != DEFAULT_HELLO_INTERVAL) {
1101 vty_out(vty,
7c0cbd0e 1102 " " PROTO_NAME " hello-interval %d level-%d\n",
d62a17ae 1103 circuit->hello_interval
1104 [i],
1105 i + 1);
1106 write++;
1107 }
1108 }
1109 }
1110
1111 /* ISIS - Hello Multiplier */
1112 if (circuit->hello_multiplier[0]
1113 == circuit->hello_multiplier[1]) {
1114 if (circuit->hello_multiplier[0]
1115 != DEFAULT_HELLO_MULTIPLIER) {
1116 vty_out(vty,
7c0cbd0e 1117 " " PROTO_NAME " hello-multiplier %d\n",
d62a17ae 1118 circuit->hello_multiplier[0]);
1119 write++;
1120 }
1121 } else {
1122 for (i = 0; i < 2; i++) {
1123 if (circuit->hello_multiplier[i]
1124 != DEFAULT_HELLO_MULTIPLIER) {
1125 vty_out(vty,
7c0cbd0e 1126 " " PROTO_NAME " hello-multiplier %d level-%d\n",
d62a17ae 1127 circuit->hello_multiplier
1128 [i],
1129 i + 1);
1130 write++;
1131 }
1132 }
1133 }
1134
1135 /* ISIS - Priority */
1136 if (circuit->priority[0] == circuit->priority[1]) {
1137 if (circuit->priority[0] != DEFAULT_PRIORITY) {
7c0cbd0e 1138 vty_out(vty, " " PROTO_NAME " priority %d\n",
d62a17ae 1139 circuit->priority[0]);
1140 write++;
1141 }
1142 } else {
1143 for (i = 0; i < 2; i++) {
1144 if (circuit->priority[i]
1145 != DEFAULT_PRIORITY) {
1146 vty_out(vty,
7c0cbd0e 1147 " " PROTO_NAME " priority %d level-%d\n",
d62a17ae 1148 circuit->priority[i],
1149 i + 1);
1150 write++;
1151 }
1152 }
1153 }
1154
1155 /* ISIS - Metric */
1156 if (circuit->te_metric[0] == circuit->te_metric[1]) {
1157 if (circuit->te_metric[0]
1158 != DEFAULT_CIRCUIT_METRIC) {
7c0cbd0e 1159 vty_out(vty, " " PROTO_NAME " metric %d\n",
d62a17ae 1160 circuit->te_metric[0]);
1161 write++;
1162 }
1163 } else {
1164 for (i = 0; i < 2; i++) {
1165 if (circuit->te_metric[i]
1166 != DEFAULT_CIRCUIT_METRIC) {
1167 vty_out(vty,
7c0cbd0e 1168 " " PROTO_NAME " metric %d level-%d\n",
d62a17ae 1169 circuit->te_metric[i],
1170 i + 1);
1171 write++;
1172 }
1173 }
1174 }
1175 if (circuit->passwd.type == ISIS_PASSWD_TYPE_HMAC_MD5) {
7c0cbd0e 1176 vty_out(vty, " " PROTO_NAME " password md5 %s\n",
d62a17ae 1177 circuit->passwd.passwd);
1178 write++;
1179 } else if (circuit->passwd.type
1180 == ISIS_PASSWD_TYPE_CLEARTXT) {
7c0cbd0e 1181 vty_out(vty, " " PROTO_NAME " password clear %s\n",
d62a17ae 1182 circuit->passwd.passwd);
1183 write++;
1184 }
5489eb45
CF
1185 write += hook_call(isis_circuit_config_write,
1186 circuit, vty);
d62a17ae 1187 }
a8b828f3 1188 vty_endframe(vty, "!\n");
d62a17ae 1189 }
1190
1191 return write;
eb5d44eb 1192}
20600086 1193#else
612c2c15 1194static int isis_interface_config_write(struct vty *vty)
20600086
EDP
1195{
1196 struct vrf *vrf = vrf_lookup_by_id(VRF_DEFAULT);
1197 int write = 0;
1198 struct interface *ifp;
1199 struct isis_circuit *circuit;
1200 struct lyd_node *dnode;
1201
1202 FOR_ALL_INTERFACES (vrf, ifp) {
1203 dnode = yang_dnode_get(
1204 running_config->dnode,
1205 "/frr-interface:lib/interface[name='%s'][vrf='%s']",
1206 ifp->name, vrf->name);
1207 if (dnode == NULL)
1208 continue;
1209
1210 write++;
1211 nb_cli_show_dnode_cmds(vty, dnode, false);
1212 circuit = circuit_scan_by_ifp(ifp);
1213 if (circuit)
1214 write += hook_call(isis_circuit_config_write, circuit,
1215 vty);
1216 }
1217 return write;
1218}
1219#endif /* ifdef FABRICD */
eb5d44eb 1220
d62a17ae 1221struct isis_circuit *isis_circuit_create(struct isis_area *area,
1222 struct interface *ifp)
eb5d44eb 1223{
d62a17ae 1224 struct isis_circuit *circuit = circuit_scan_by_ifp(ifp);
1225 if (circuit && circuit->area)
1226 return NULL;
1227 circuit = isis_csm_state_change(ISIS_ENABLE, circuit, area);
1228 if (circuit->state != C_STATE_CONF && circuit->state != C_STATE_UP)
1229 return circuit;
1230 isis_circuit_if_bind(circuit, ifp);
1231 return circuit;
eb5d44eb 1232}
1233
d62a17ae 1234void isis_circuit_af_set(struct isis_circuit *circuit, bool ip_router,
1235 bool ipv6_router)
eb5d44eb 1236{
d62a17ae 1237 struct isis_area *area = circuit->area;
1238 bool change = circuit->ip_router != ip_router
1239 || circuit->ipv6_router != ipv6_router;
d62a17ae 1240
1241 area->ip_circuits += ip_router - circuit->ip_router;
1242 area->ipv6_circuits += ipv6_router - circuit->ipv6_router;
1243 circuit->ip_router = ip_router;
1244 circuit->ipv6_router = ipv6_router;
1245
1246 if (!change)
1247 return;
1248
1249 circuit_update_nlpids(circuit);
1250
1251 if (!ip_router && !ipv6_router)
1252 isis_csm_state_change(ISIS_DISABLE, circuit, area);
d62a17ae 1253 else
1254 lsp_regenerate_schedule(circuit->area, circuit->is_type, 0);
3f045a08 1255}
eb5d44eb 1256
64dd3ffe 1257ferr_r isis_circuit_passive_set(struct isis_circuit *circuit, bool passive)
3f045a08 1258{
d62a17ae 1259 if (circuit->is_passive == passive)
64dd3ffe 1260 return ferr_ok();
d62a17ae 1261
1262 if (if_is_loopback(circuit->interface) && !passive)
64dd3ffe 1263 return ferr_cfg_invalid("loopback is always passive");
d62a17ae 1264
1265 if (circuit->state != C_STATE_UP) {
1266 circuit->is_passive = passive;
1267 } else {
1268 struct isis_area *area = circuit->area;
1269 isis_csm_state_change(ISIS_DISABLE, circuit, area);
1270 circuit->is_passive = passive;
1271 isis_csm_state_change(ISIS_ENABLE, circuit, area);
1272 }
1273
64dd3ffe 1274 return ferr_ok();
eb5d44eb 1275}
1276
64dd3ffe
DL
1277ferr_r isis_circuit_metric_set(struct isis_circuit *circuit, int level,
1278 int metric)
3f045a08 1279{
d62a17ae 1280 assert(level == IS_LEVEL_1 || level == IS_LEVEL_2);
1281 if (metric > MAX_WIDE_LINK_METRIC)
64dd3ffe
DL
1282 return ferr_cfg_invalid("metric %d too large for wide metric",
1283 metric);
d62a17ae 1284 if (circuit->area && circuit->area->oldmetric
1285 && metric > MAX_NARROW_LINK_METRIC)
64dd3ffe
DL
1286 return ferr_cfg_invalid("metric %d too large for narrow metric",
1287 metric);
d62a17ae 1288
1289 circuit->te_metric[level - 1] = metric;
1290 circuit->metric[level - 1] = metric;
1291
1292 if (circuit->area)
1293 lsp_regenerate_schedule(circuit->area, level, 0);
64dd3ffe 1294 return ferr_ok();
eb5d44eb 1295}
1296
64dd3ffe 1297ferr_r isis_circuit_passwd_unset(struct isis_circuit *circuit)
eb5d44eb 1298{
d62a17ae 1299 memset(&circuit->passwd, 0, sizeof(circuit->passwd));
64dd3ffe 1300 return ferr_ok();
3f045a08
JB
1301}
1302
e28544ed
QY
1303ferr_r isis_circuit_passwd_set(struct isis_circuit *circuit,
1304 uint8_t passwd_type, const char *passwd)
3f045a08 1305{
d62a17ae 1306 int len;
f390d2c7 1307
d62a17ae 1308 if (!passwd)
64dd3ffe 1309 return ferr_code_bug("no circuit password given");
50c7d14a 1310
d62a17ae 1311 len = strlen(passwd);
1312 if (len > 254)
64dd3ffe
DL
1313 return ferr_code_bug(
1314 "circuit password too long (max 254 chars)");
f390d2c7 1315
d62a17ae 1316 circuit->passwd.len = len;
e28544ed
QY
1317 strlcpy((char *)circuit->passwd.passwd, passwd,
1318 sizeof(circuit->passwd.passwd));
d62a17ae 1319 circuit->passwd.type = passwd_type;
64dd3ffe 1320 return ferr_ok();
eb5d44eb 1321}
1322
64dd3ffe
DL
1323ferr_r isis_circuit_passwd_cleartext_set(struct isis_circuit *circuit,
1324 const char *passwd)
eb5d44eb 1325{
d62a17ae 1326 return isis_circuit_passwd_set(circuit, ISIS_PASSWD_TYPE_CLEARTXT,
1327 passwd);
50c7d14a 1328}
f390d2c7 1329
64dd3ffe
DL
1330ferr_r isis_circuit_passwd_hmac_md5_set(struct isis_circuit *circuit,
1331 const char *passwd)
50c7d14a 1332{
d62a17ae 1333 return isis_circuit_passwd_set(circuit, ISIS_PASSWD_TYPE_HMAC_MD5,
1334 passwd);
eb5d44eb 1335}
64dd3ffe 1336
3f045a08 1337struct cmd_node interface_node = {
f4b8291f 1338 .name = "interface",
62b346ee 1339 .node = INTERFACE_NODE,
24389580 1340 .parent_node = CONFIG_NODE,
62b346ee 1341 .prompt = "%s(config-if)# ",
612c2c15 1342 .config_write = isis_interface_config_write,
eb5d44eb 1343};
1344
d0820765 1345void isis_circuit_circ_type_set(struct isis_circuit *circuit, int circ_type)
3f045a08 1346{
64dd3ffe 1347 if (circuit->circ_type == circ_type)
d0820765 1348 return;
d62a17ae 1349
d62a17ae 1350 if (circuit->state != C_STATE_UP) {
1351 circuit->circ_type = circ_type;
1352 circuit->circ_type_config = circ_type;
1353 } else {
1354 struct isis_area *area = circuit->area;
d62a17ae 1355
1356 isis_csm_state_change(ISIS_DISABLE, circuit, area);
1357 circuit->circ_type = circ_type;
1358 circuit->circ_type_config = circ_type;
1359 isis_csm_state_change(ISIS_ENABLE, circuit, area);
1360 }
3f045a08
JB
1361}
1362
d62a17ae 1363int isis_circuit_mt_enabled_set(struct isis_circuit *circuit, uint16_t mtid,
1364 bool enabled)
064f4896 1365{
d62a17ae 1366 struct isis_circuit_mt_setting *setting;
064f4896 1367
d62a17ae 1368 setting = circuit_get_mt_setting(circuit, mtid);
1369 if (setting->enabled != enabled) {
1370 setting->enabled = enabled;
1371 lsp_regenerate_schedule(circuit->area, IS_LEVEL_1 | IS_LEVEL_2,
1372 0);
1373 }
064f4896 1374
d62a17ae 1375 return CMD_SUCCESS;
064f4896
CF
1376}
1377
d62a17ae 1378int isis_if_new_hook(struct interface *ifp)
eb5d44eb 1379{
d62a17ae 1380 return 0;
eb5d44eb 1381}
1382
d62a17ae 1383int isis_if_delete_hook(struct interface *ifp)
eb5d44eb 1384{
d62a17ae 1385 struct isis_circuit *circuit;
1386 /* Clean up the circuit data */
1387 if (ifp && ifp->info) {
1388 circuit = ifp->info;
1389 isis_csm_state_change(IF_DOWN_FROM_Z, circuit, circuit->area);
d62a17ae 1390 }
1391
1392 return 0;
eb5d44eb 1393}
1394
138c5a74
DS
1395static int isis_ifp_create(struct interface *ifp)
1396{
ef7bd2a3
DS
1397 if (if_is_operative(ifp))
1398 isis_csm_state_change(IF_UP_FROM_Z, circuit_scan_by_ifp(ifp),
1399 ifp);
1400
1401 hook_call(isis_if_new_hook, ifp);
1402
138c5a74
DS
1403 return 0;
1404}
1405
1406static int isis_ifp_up(struct interface *ifp)
1407{
ddbf3e60
DS
1408 isis_csm_state_change(IF_UP_FROM_Z, circuit_scan_by_ifp(ifp), ifp);
1409
138c5a74
DS
1410 return 0;
1411}
1412
1413static int isis_ifp_down(struct interface *ifp)
1414{
b0b69e59
DS
1415 struct isis_circuit *circuit;
1416
1417 circuit = isis_csm_state_change(IF_DOWN_FROM_Z,
1418 circuit_scan_by_ifp(ifp), ifp);
1419 if (circuit)
1420 SET_FLAG(circuit->flags, ISIS_CIRCUIT_FLAPPED_AFTER_SPF);
1421
138c5a74
DS
1422 return 0;
1423}
1424
1425static int isis_ifp_destroy(struct interface *ifp)
1426{
3c3c3252
DS
1427 if (if_is_operative(ifp))
1428 zlog_warn("Zebra: got delete of %s, but interface is still up",
1429 ifp->name);
1430
1431 isis_csm_state_change(IF_DOWN_FROM_Z, circuit_scan_by_ifp(ifp), ifp);
1432
1433 /* Cannot call if_delete because we should retain the pseudo interface
1434 in case there is configuration info attached to it. */
1435 if_delete_retain(ifp);
1436
138c5a74
DS
1437 return 0;
1438}
1439
4d762f26 1440void isis_circuit_init(void)
eb5d44eb 1441{
d62a17ae 1442 /* Initialize Zebra interface data structure */
ce19a04a
DL
1443 hook_register_prio(if_add, 0, isis_if_new_hook);
1444 hook_register_prio(if_del, 0, isis_if_delete_hook);
eb5d44eb 1445
d62a17ae 1446 /* Install interface node */
612c2c15 1447 install_node(&interface_node);
d62a17ae 1448 if_cmd_init();
138c5a74
DS
1449 if_zapi_callbacks(isis_ifp_create, isis_ifp_up,
1450 isis_ifp_down, isis_ifp_destroy);
eb5d44eb 1451}