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