]> git.proxmox.com Git - mirror_frr.git/blob - isisd/isis_circuit.c
isisd: The RFC states that v6 addresses are limited to 16 in a hello packet
[mirror_frr.git] / isisd / isis_circuit.c
1 /*
2 * IS-IS Rout(e)ing protocol - isis_circuit.h
3 *
4 * Copyright (C) 2001,2002 Sampo Saaristo
5 * Tampere University of Technology
6 * Institute of Communications Engineering
7 *
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)
11 * any later version.
12 *
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
16 * more details.
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
21 */
22 #include <zebra.h>
23 #ifdef GNU_LINUX
24 #include <net/ethernet.h>
25 #else
26 #include <netinet/if_ether.h>
27 #endif
28
29 #include "log.h"
30 #include "memory.h"
31 #include "vrf.h"
32 #include "if.h"
33 #include "linklist.h"
34 #include "command.h"
35 #include "thread.h"
36 #include "vty.h"
37 #include "hash.h"
38 #include "prefix.h"
39 #include "stream.h"
40 #include "qobj.h"
41 #include "lib/northbound_cli.h"
42
43 #include "isisd/isis_constants.h"
44 #include "isisd/isis_common.h"
45 #include "isisd/isis_flags.h"
46 #include "isisd/isis_circuit.h"
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"
54 #include "isisd/isisd.h"
55 #include "isisd/isis_csm.h"
56 #include "isisd/isis_events.h"
57 #include "isisd/isis_te.h"
58 #include "isisd/isis_mt.h"
59 #include "isisd/isis_errors.h"
60 #include "isisd/isis_tx_queue.h"
61
62 DEFINE_QOBJ_TYPE(isis_circuit)
63
64 /*
65 * Prototypes.
66 */
67 int isis_interface_config_write(struct vty *);
68 int isis_if_new_hook(struct interface *);
69 int isis_if_delete_hook(struct interface *);
70
71 struct isis_circuit *isis_circuit_new(void)
72 {
73 struct isis_circuit *circuit;
74 int i;
75
76 circuit = XCALLOC(MTYPE_ISIS_CIRCUIT, sizeof(struct isis_circuit));
77
78 /*
79 * Default values
80 */
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
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;
133 circuit->level_arg[i].level = i + 1;
134 circuit->level_arg[i].circuit = circuit;
135 }
136 #endif /* ifndef FABRICD */
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;
145 }
146
147 void isis_circuit_del(struct isis_circuit *circuit)
148 {
149 if (!circuit)
150 return;
151
152 QOBJ_UNREG(circuit);
153
154 isis_circuit_if_unbind(circuit, circuit->interface);
155
156 circuit_mt_finish(circuit);
157
158 /* and lastly the circuit itself */
159 XFREE(MTYPE_ISIS_CIRCUIT, circuit);
160
161 return;
162 }
163
164 void isis_circuit_configure(struct isis_circuit *circuit,
165 struct isis_area *area)
166 {
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;
188 }
189
190 void isis_circuit_deconfigure(struct isis_circuit *circuit,
191 struct isis_area *area)
192 {
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;
202 }
203
204 struct isis_circuit *circuit_lookup_by_ifp(struct interface *ifp,
205 struct list *list)
206 {
207 struct isis_circuit *circuit = NULL;
208 struct listnode *node;
209
210 if (!list)
211 return NULL;
212
213 for (ALL_LIST_ELEMENTS_RO(list, node, circuit))
214 if (circuit->interface == ifp) {
215 assert(ifp->info == circuit);
216 return circuit;
217 }
218
219 return NULL;
220 }
221
222 struct isis_circuit *circuit_scan_by_ifp(struct interface *ifp)
223 {
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);
240 }
241
242 void isis_circuit_add_addr(struct isis_circuit *circuit,
243 struct connected *connected)
244 {
245 struct listnode *node;
246 struct prefix_ipv4 *ipv4;
247 #if defined(EXTREME_DEBUG)
248 char buf[PREFIX2STR_BUFFER];
249 #endif
250 struct prefix_ipv6 *ipv6;
251
252 if (connected->address->family == AF_INET) {
253 uint32_t addr = connected->address->u.prefix4.s_addr;
254 addr = ntohl(addr);
255 if (IPV4_NET0(addr) || IPV4_NET127(addr) || IN_CLASSD(addr)
256 || IPV4_LINKLOCAL(addr))
257 return;
258
259 for (ALL_LIST_ELEMENTS_RO(circuit->ip_addrs, node, ipv4))
260 if (prefix_same((struct prefix *)ipv4,
261 connected->address))
262 return;
263
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);
268
269 /* Update MPLS TE Local IP address parameter */
270 set_circuitparams_local_ipaddr(circuit->mtc, ipv4->prefix);
271
272 if (circuit->area)
273 lsp_regenerate_schedule(circuit->area, circuit->is_type,
274 0);
275
276 #ifdef EXTREME_DEBUG
277 prefix2str(connected->address, buf, sizeof(buf));
278 zlog_debug("Added IP address %s to circuit %s", buf,
279 circuit->interface->name);
280 #endif /* EXTREME_DEBUG */
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);
306
307 #ifdef EXTREME_DEBUG
308 prefix2str(connected->address, buf, sizeof(buf));
309 zlog_debug("Added IPv6 address %s to circuit %s", buf,
310 circuit->interface->name);
311 #endif /* EXTREME_DEBUG */
312 }
313 return;
314 }
315
316 void isis_circuit_del_addr(struct isis_circuit *circuit,
317 struct connected *connected)
318 {
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);
337 prefix_ipv4_free(ip);
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(
344 "Nonexistent ip address %s removal attempt from \
345 circuit %s",
346 buf, circuit->interface->name);
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);
358 }
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);
373 prefix_ipv6_free(ip6);
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);
385 prefix_ipv6_free(ip6);
386 found = 1;
387 }
388 }
389
390 if (!found) {
391 prefix2str(connected->address, buf, sizeof(buf));
392 zlog_warn(
393 "Nonexistent ip address %s removal attempt from \
394 circuit %s",
395 buf, circuit->interface->name);
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,
401 sizeof(buf));
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,
408 sizeof(buf));
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);
417 }
418 return;
419 }
420
421 static uint8_t isis_circuit_id_gen(struct isis *isis, struct interface *ifp)
422 {
423 /* Circuit ids MUST be unique for any broadcast circuits. Otherwise,
424 * Pseudo-Node LSPs cannot be generated correctly.
425 *
426 * Currently, allocate one circuit ID for any circuit, limiting the total
427 * numer of circuits IS-IS can run on to 255.
428 *
429 * We should revisit this when implementing 3-way adjacencies for p2p, since
430 * we then have extended interface IDs available.
431 */
432 uint8_t id = ifp->ifindex;
433 unsigned int i;
434
435 for (i = 0; i < 256; i++) {
436 if (id && !_ISIS_CHECK_FLAG(isis->circuit_ids_used, id))
437 break;
438 id++;
439 }
440
441 if (i == 256) {
442 zlog_warn("Could not allocate a circuit id for '%s'",
443 ifp->name);
444 return 0;
445 }
446
447 _ISIS_SET_FLAG(isis->circuit_ids_used, id);
448 return id;
449 }
450
451 void isis_circuit_if_add(struct isis_circuit *circuit, struct interface *ifp)
452 {
453 struct listnode *node, *nnode;
454 struct connected *conn;
455
456 isis_circuit_if_bind(circuit, ifp);
457
458 if (if_is_broadcast(ifp)) {
459 if (fabricd || circuit->circ_type_config == CIRCUIT_T_P2P)
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);
481 }
482
483 void isis_circuit_if_del(struct isis_circuit *circuit, struct interface *ifp)
484 {
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);
496 list_delete(&circuit->ip_addrs);
497 }
498
499 if (circuit->ipv6_link) {
500 assert(listcount(circuit->ipv6_link) == 0);
501 list_delete(&circuit->ipv6_link);
502 }
503
504 if (circuit->ipv6_non_link) {
505 assert(listcount(circuit->ipv6_non_link) == 0);
506 list_delete(&circuit->ipv6_non_link);
507 }
508
509 circuit->circ_type = CIRCUIT_T_UNKNOWN;
510 }
511
512 void isis_circuit_if_bind(struct isis_circuit *circuit, struct interface *ifp)
513 {
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);
525 }
526
527 void isis_circuit_if_unbind(struct isis_circuit *circuit, struct interface *ifp)
528 {
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;
535 }
536
537 static void isis_circuit_update_all_srmflags(struct isis_circuit *circuit,
538 int is_set)
539 {
540 struct isis_area *area;
541 struct isis_lsp *lsp;
542 int level;
543
544 assert(circuit);
545 area = circuit->area;
546 assert(area);
547 for (level = ISIS_LEVEL1; level <= ISIS_LEVEL2; level++) {
548 if (!(level & circuit->is_type))
549 continue;
550
551 if (!lspdb_count(&area->lspdb[level - 1]))
552 continue;
553
554 for_each (lspdb, &area->lspdb[level - 1], lsp) {
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);
560 }
561 }
562 }
563 }
564
565 size_t isis_circuit_pdu_size(struct isis_circuit *circuit)
566 {
567 return ISO_MTU(circuit);
568 }
569
570 void isis_circuit_stream(struct isis_circuit *circuit, struct stream **stream)
571 {
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)
578 stream_resize_inplace(stream, stream_size);
579 stream_reset(*stream);
580 }
581 }
582
583 void isis_circuit_prepare(struct isis_circuit *circuit)
584 {
585 #if ISIS_METHOD != ISIS_METHOD_DLPI
586 thread_add_read(master, isis_receive, circuit, circuit->fd,
587 &circuit->t_read);
588 #else
589 thread_add_timer_msec(master, isis_receive, circuit,
590 listcount(circuit->area->circuit_list) * 100,
591 &circuit->t_read);
592 #endif
593 }
594
595 int isis_circuit_up(struct isis_circuit *circuit)
596 {
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)) {
609 flog_err(
610 EC_ISIS_CONFIG,
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) {
619 circuit->circuit_id = isis_circuit_id_gen(isis, circuit->interface);
620 if (!circuit->circuit_id) {
621 flog_err(
622 EC_ISIS_CONFIG,
623 "There are already 255 broadcast circuits active!");
624 return ISIS_ERROR;
625 }
626
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 }
636 #ifdef EXTREME_DEGUG
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));
640 #endif /* EXTREME_DEBUG */
641
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
655 for (int level = ISIS_LEVEL1; level <= ISIS_LEVEL2; level++) {
656 if (!(circuit->is_type & level))
657 continue;
658
659 send_hello_sched(circuit, level, TRIGGERED_IIH_DELAY);
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]);
666 }
667
668 /* 8.4.1 b) FIXME: solicit ES - 8.4.6 */
669 /* 8.4.1 c) FIXME: listen for ESH PDUs */
670 } else if (circuit->circ_type == CIRCUIT_T_P2P) {
671 /* initializing the hello send threads
672 * for a ptp IF
673 */
674 circuit->u.p2p.neighbor = NULL;
675 send_hello_sched(circuit, 0, TRIGGERED_IIH_DELAY);
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
704 circuit->tx_queue = isis_tx_queue_new(circuit, send_lsp);
705
706 #ifndef FABRICD
707 /* send northbound notification */
708 isis_notif_if_state_change(circuit, false);
709 #endif /* ifndef FABRICD */
710
711 return ISIS_OK;
712 }
713
714 void isis_circuit_down(struct isis_circuit *circuit)
715 {
716 #ifndef FABRICD
717 /* send northbound notification */
718 isis_notif_if_state_change(circuit, true);
719 #endif /* ifndef FABRICD */
720
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]) {
727 list_delete(&circuit->u.bc.lan_neighs[0]);
728 circuit->u.bc.lan_neighs[0] = NULL;
729 }
730 if (circuit->u.bc.lan_neighs[1]) {
731 list_delete(&circuit->u.bc.lan_neighs[1]);
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;
737 list_delete(&circuit->u.bc.adjdb[0]);
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;
742 list_delete(&circuit->u.bc.adjdb[1]);
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;
765
766 _ISIS_CLEAR_FLAG(isis->circuit_ids_used, circuit->circuit_id);
767 circuit->circuit_id = 0;
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
781 if (circuit->tx_queue) {
782 isis_tx_queue_free(circuit->tx_queue);
783 circuit->tx_queue = NULL;
784 }
785
786 /* send one gratuitous hello to spead up convergence */
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 }
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;
816 }
817
818 void circuit_update_nlpids(struct isis_circuit *circuit)
819 {
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;
831 }
832
833 void isis_circuit_print_vty(struct isis_circuit *circuit, struct vty *vty,
834 char detail)
835 {
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)) {
938 prefix2str(ip_addr, buf, sizeof(buf));
939 vty_out(vty, " %s\n", buf);
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)) {
946 prefix2str(ip_addr, (char *)buf, BUFSIZ);
947 vty_out(vty, " %s\n", buf);
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)) {
955 prefix2str(ip_addr, (char *)buf, BUFSIZ);
956 vty_out(vty, " %s\n", buf);
957 }
958 }
959
960 vty_out(vty, "\n");
961 }
962 return;
963 }
964
965 DEFINE_HOOK(isis_circuit_config_write,
966 (struct isis_circuit *circuit, struct vty *vty),
967 (circuit, vty))
968
969 #ifdef FABRICD
970 int isis_interface_config_write(struct vty *vty)
971 {
972 struct vrf *vrf = vrf_lookup_by_id(VRF_DEFAULT);
973 int write = 0;
974 struct listnode *node;
975 struct interface *ifp;
976 struct isis_area *area;
977 struct isis_circuit *circuit;
978 int i;
979
980 FOR_ALL_INTERFACES (vrf, ifp) {
981 /* IF name */
982 vty_frame(vty, "interface %s\n", ifp->name);
983 write++;
984 /* IF desc */
985 if (ifp->desc) {
986 vty_out(vty, " description %s\n", ifp->desc);
987 write++;
988 }
989 /* ISIS Circuit */
990 for (ALL_LIST_ELEMENTS_RO(isis->area_list, node, area)) {
991 circuit =
992 circuit_lookup_by_ifp(ifp, area->circuit_list);
993 if (circuit == NULL)
994 continue;
995 if (circuit->ip_router) {
996 vty_out(vty, " ip router " PROTO_NAME " %s\n",
997 area->area_tag);
998 write++;
999 }
1000 if (circuit->is_passive) {
1001 vty_out(vty, " " PROTO_NAME " passive\n");
1002 write++;
1003 }
1004 if (circuit->circ_type_config == CIRCUIT_T_P2P) {
1005 vty_out(vty, " " PROTO_NAME " network point-to-point\n");
1006 write++;
1007 }
1008 if (circuit->ipv6_router) {
1009 vty_out(vty, " ipv6 router " PROTO_NAME " %s\n",
1010 area->area_tag);
1011 write++;
1012 }
1013
1014 /* ISIS - circuit type */
1015 if (!fabricd) {
1016 if (circuit->is_type == IS_LEVEL_1) {
1017 vty_out(vty, " " PROTO_NAME " circuit-type level-1\n");
1018 write++;
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 }
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) {
1033 vty_out(vty, " " PROTO_NAME " csnp-interval %d\n",
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,
1042 " " PROTO_NAME " csnp-interval %d level-%d\n",
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) {
1056 vty_out(vty, " " PROTO_NAME " psnp-interval %d\n",
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,
1065 " " PROTO_NAME " psnp-interval %d level-%d\n",
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) {
1077 vty_out(vty, " no " PROTO_NAME " hello padding\n");
1078 write++;
1079 }
1080
1081 if (circuit->disable_threeway_adj) {
1082 vty_out(vty, " no isis three-way-handshake\n");
1083 write++;
1084 }
1085
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,
1092 " " PROTO_NAME " hello-interval %d\n",
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,
1101 " " PROTO_NAME " hello-interval %d level-%d\n",
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,
1116 " " PROTO_NAME " hello-multiplier %d\n",
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,
1125 " " PROTO_NAME " hello-multiplier %d level-%d\n",
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) {
1137 vty_out(vty, " " PROTO_NAME " priority %d\n",
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,
1146 " " PROTO_NAME " priority %d level-%d\n",
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) {
1158 vty_out(vty, " " PROTO_NAME " metric %d\n",
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,
1167 " " PROTO_NAME " metric %d level-%d\n",
1168 circuit->te_metric[i],
1169 i + 1);
1170 write++;
1171 }
1172 }
1173 }
1174 if (circuit->passwd.type == ISIS_PASSWD_TYPE_HMAC_MD5) {
1175 vty_out(vty, " " PROTO_NAME " password md5 %s\n",
1176 circuit->passwd.passwd);
1177 write++;
1178 } else if (circuit->passwd.type
1179 == ISIS_PASSWD_TYPE_CLEARTXT) {
1180 vty_out(vty, " " PROTO_NAME " password clear %s\n",
1181 circuit->passwd.passwd);
1182 write++;
1183 }
1184 write += hook_call(isis_circuit_config_write,
1185 circuit, vty);
1186 }
1187 vty_endframe(vty, "!\n");
1188 }
1189
1190 return write;
1191 }
1192 #else
1193 int 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 */
1219
1220 struct isis_circuit *isis_circuit_create(struct isis_area *area,
1221 struct interface *ifp)
1222 {
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;
1231 }
1232
1233 void isis_circuit_af_set(struct isis_circuit *circuit, bool ip_router,
1234 bool ipv6_router)
1235 {
1236 struct isis_area *area = circuit->area;
1237 bool change = circuit->ip_router != ip_router
1238 || circuit->ipv6_router != ipv6_router;
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);
1252 else
1253 lsp_regenerate_schedule(circuit->area, circuit->is_type, 0);
1254 }
1255
1256 ferr_r isis_circuit_passive_set(struct isis_circuit *circuit, bool passive)
1257 {
1258 if (circuit->is_passive == passive)
1259 return ferr_ok();
1260
1261 if (if_is_loopback(circuit->interface) && !passive)
1262 return ferr_cfg_invalid("loopback is always passive");
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
1273 return ferr_ok();
1274 }
1275
1276 ferr_r isis_circuit_metric_set(struct isis_circuit *circuit, int level,
1277 int metric)
1278 {
1279 assert(level == IS_LEVEL_1 || level == IS_LEVEL_2);
1280 if (metric > MAX_WIDE_LINK_METRIC)
1281 return ferr_cfg_invalid("metric %d too large for wide metric",
1282 metric);
1283 if (circuit->area && circuit->area->oldmetric
1284 && metric > MAX_NARROW_LINK_METRIC)
1285 return ferr_cfg_invalid("metric %d too large for narrow metric",
1286 metric);
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);
1293 return ferr_ok();
1294 }
1295
1296 ferr_r isis_circuit_passwd_unset(struct isis_circuit *circuit)
1297 {
1298 memset(&circuit->passwd, 0, sizeof(circuit->passwd));
1299 return ferr_ok();
1300 }
1301
1302 ferr_r isis_circuit_passwd_set(struct isis_circuit *circuit,
1303 uint8_t passwd_type, const char *passwd)
1304 {
1305 int len;
1306
1307 if (!passwd)
1308 return ferr_code_bug("no circuit password given");
1309
1310 len = strlen(passwd);
1311 if (len > 254)
1312 return ferr_code_bug(
1313 "circuit password too long (max 254 chars)");
1314
1315 circuit->passwd.len = len;
1316 strlcpy((char *)circuit->passwd.passwd, passwd,
1317 sizeof(circuit->passwd.passwd));
1318 circuit->passwd.type = passwd_type;
1319 return ferr_ok();
1320 }
1321
1322 ferr_r isis_circuit_passwd_cleartext_set(struct isis_circuit *circuit,
1323 const char *passwd)
1324 {
1325 return isis_circuit_passwd_set(circuit, ISIS_PASSWD_TYPE_CLEARTXT,
1326 passwd);
1327 }
1328
1329 ferr_r isis_circuit_passwd_hmac_md5_set(struct isis_circuit *circuit,
1330 const char *passwd)
1331 {
1332 return isis_circuit_passwd_set(circuit, ISIS_PASSWD_TYPE_HMAC_MD5,
1333 passwd);
1334 }
1335
1336 struct cmd_node interface_node = {
1337 INTERFACE_NODE, "%s(config-if)# ", 1,
1338 };
1339
1340 void isis_circuit_circ_type_set(struct isis_circuit *circuit, int circ_type)
1341 {
1342 if (circuit->circ_type == circ_type)
1343 return;
1344
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;
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 }
1356 }
1357
1358 int isis_circuit_mt_enabled_set(struct isis_circuit *circuit, uint16_t mtid,
1359 bool enabled)
1360 {
1361 struct isis_circuit_mt_setting *setting;
1362
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 }
1369
1370 return CMD_SUCCESS;
1371 }
1372
1373 int isis_if_new_hook(struct interface *ifp)
1374 {
1375 return 0;
1376 }
1377
1378 int isis_if_delete_hook(struct interface *ifp)
1379 {
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;
1389 }
1390
1391 void isis_circuit_init(void)
1392 {
1393 /* Initialize Zebra interface data structure */
1394 hook_register_prio(if_add, 0, isis_if_new_hook);
1395 hook_register_prio(if_del, 0, isis_if_delete_hook);
1396
1397 /* Install interface node */
1398 install_node(&interface_node, isis_interface_config_write);
1399 if_cmd_init();
1400 }