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