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