]> git.proxmox.com Git - mirror_frr.git/blob - isisd/isis_circuit.c
isisd: prevent segfault in isis_circuit_af_set
[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_if_new_hook(struct interface *);
71 int isis_if_delete_hook(struct interface *);
72
73 struct isis_circuit *isis_circuit_new(void)
74 {
75 struct isis_circuit *circuit;
76 int i;
77
78 circuit = XCALLOC(MTYPE_ISIS_CIRCUIT, sizeof(struct isis_circuit));
79
80 /*
81 * Default values
82 */
83 #ifndef FABRICD
84 circuit->is_type = yang_get_default_enum(
85 "/frr-interface:lib/interface/frr-isisd:isis/circuit-type");
86 circuit->flags = 0;
87
88 circuit->pad_hellos = yang_get_default_bool(
89 "/frr-interface:lib/interface/frr-isisd:isis/hello/padding");
90 circuit->hello_interval[0] = yang_get_default_uint32(
91 "/frr-interface:lib/interface/frr-isisd:isis/hello/interval/level-1");
92 circuit->hello_interval[1] = yang_get_default_uint32(
93 "/frr-interface:lib/interface/frr-isisd:isis/hello/interval/level-2");
94 circuit->hello_multiplier[0] = yang_get_default_uint32(
95 "/frr-interface:lib/interface/frr-isisd:isis/hello/multiplier/level-1");
96 circuit->hello_multiplier[1] = yang_get_default_uint32(
97 "/frr-interface:lib/interface/frr-isisd:isis/hello/multiplier/level-2");
98 circuit->csnp_interval[0] = yang_get_default_uint16(
99 "/frr-interface:lib/interface/frr-isisd:isis/csnp-interval/level-1");
100 circuit->csnp_interval[1] = yang_get_default_uint16(
101 "/frr-interface:lib/interface/frr-isisd:isis/csnp-interval/level-2");
102 circuit->psnp_interval[0] = yang_get_default_uint16(
103 "/frr-interface:lib/interface/frr-isisd:isis/psnp-interval/level-1");
104 circuit->psnp_interval[1] = yang_get_default_uint16(
105 "/frr-interface:lib/interface/frr-isisd:isis/psnp-interval/level-2");
106 circuit->priority[0] = yang_get_default_uint8(
107 "/frr-interface:lib/interface/frr-isisd:isis/priority/level-1");
108 circuit->priority[1] = yang_get_default_uint8(
109 "/frr-interface:lib/interface/frr-isisd:isis/priority/level-2");
110 circuit->metric[0] = yang_get_default_uint32(
111 "/frr-interface:lib/interface/frr-isisd:isis/metric/level-1");
112 circuit->metric[1] = yang_get_default_uint32(
113 "/frr-interface:lib/interface/frr-isisd:isis/metric/level-2");
114 circuit->te_metric[0] = yang_get_default_uint32(
115 "/frr-interface:lib/interface/frr-isisd:isis/metric/level-1");
116 circuit->te_metric[1] = yang_get_default_uint32(
117 "/frr-interface:lib/interface/frr-isisd:isis/metric/level-2");
118
119 for (i = 0; i < 2; i++) {
120 circuit->level_arg[i].level = i + 1;
121 circuit->level_arg[i].circuit = circuit;
122 }
123 #else
124 circuit->is_type = IS_LEVEL_1_AND_2;
125 circuit->flags = 0;
126 circuit->pad_hellos = 1;
127 for (i = 0; i < 2; i++) {
128 circuit->hello_interval[i] = DEFAULT_HELLO_INTERVAL;
129 circuit->hello_multiplier[i] = DEFAULT_HELLO_MULTIPLIER;
130 circuit->csnp_interval[i] = DEFAULT_CSNP_INTERVAL;
131 circuit->psnp_interval[i] = DEFAULT_PSNP_INTERVAL;
132 circuit->priority[i] = DEFAULT_PRIORITY;
133 circuit->metric[i] = DEFAULT_CIRCUIT_METRIC;
134 circuit->te_metric[i] = DEFAULT_CIRCUIT_METRIC;
135 circuit->level_arg[i].level = i + 1;
136 circuit->level_arg[i].circuit = circuit;
137 }
138 #endif /* ifndef FABRICD */
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 Local IP address parameter if MPLS TE is enable */
270 if (circuit->ext && circuit->area
271 && IS_MPLS_TE(circuit->area->mta)) {
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 #ifdef FABRICD
968 DEFINE_HOOK(isis_circuit_config_write,
969 (struct isis_circuit *circuit, struct vty *vty),
970 (circuit, vty))
971
972 static 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 static 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 lyd_node *dnode;
1201
1202 FOR_ALL_INTERFACES (vrf, ifp) {
1203 dnode = yang_dnode_get(
1204 running_config->dnode,
1205 "/frr-interface:lib/interface[name='%s'][vrf='%s']",
1206 ifp->name, vrf->name);
1207 if (dnode == NULL)
1208 continue;
1209
1210 write++;
1211 nb_cli_show_dnode_cmds(vty, dnode, false);
1212 }
1213 return write;
1214 }
1215 #endif /* ifdef FABRICD */
1216
1217 struct isis_circuit *isis_circuit_create(struct isis_area *area,
1218 struct interface *ifp)
1219 {
1220 struct isis_circuit *circuit = circuit_scan_by_ifp(ifp);
1221 if (circuit && circuit->area)
1222 return NULL;
1223 circuit = isis_csm_state_change(ISIS_ENABLE, circuit, area);
1224 if (circuit->state != C_STATE_CONF && circuit->state != C_STATE_UP)
1225 return circuit;
1226 isis_circuit_if_bind(circuit, ifp);
1227 if (circuit->area->mta && circuit->area->mta->status)
1228 isis_link_params_update(circuit, ifp);
1229 return circuit;
1230 }
1231
1232 void isis_circuit_af_set(struct isis_circuit *circuit, bool ip_router,
1233 bool ipv6_router)
1234 {
1235 struct isis_area *area = circuit->area;
1236 int old_ipr = circuit->ip_router;
1237 int old_ipv6r = circuit->ipv6_router;
1238
1239 /* is there something to do? */
1240 if (old_ipr == ip_router && old_ipv6r == ipv6_router)
1241 return;
1242
1243 circuit->ip_router = ip_router;
1244 circuit->ipv6_router = ipv6_router;
1245 circuit_update_nlpids(circuit);
1246
1247 /* the area should always be there if we get here, but in the past
1248 * there were corner cases where the area was NULL (e.g. because the
1249 * circuit was deconfigured following a validation error). Do not
1250 * segfault if this happens again.
1251 */
1252 if (!area) {
1253 zlog_err("%s: NULL area for circuit %u", __func__,
1254 circuit->circuit_id);
1255 return;
1256 }
1257
1258 area->ip_circuits += ip_router - old_ipr;
1259 area->ipv6_circuits += ipv6_router - old_ipv6r;
1260
1261 if (!ip_router && !ipv6_router)
1262 isis_csm_state_change(ISIS_DISABLE, circuit, area);
1263 else
1264 lsp_regenerate_schedule(area, circuit->is_type, 0);
1265 }
1266
1267 ferr_r isis_circuit_passive_set(struct isis_circuit *circuit, bool passive)
1268 {
1269 if (circuit->is_passive == passive)
1270 return ferr_ok();
1271
1272 if (if_is_loopback(circuit->interface) && !passive)
1273 return ferr_cfg_invalid("loopback is always passive");
1274
1275 if (circuit->state != C_STATE_UP) {
1276 circuit->is_passive = passive;
1277 } else {
1278 struct isis_area *area = circuit->area;
1279 isis_csm_state_change(ISIS_DISABLE, circuit, area);
1280 circuit->is_passive = passive;
1281 isis_csm_state_change(ISIS_ENABLE, circuit, area);
1282 }
1283
1284 return ferr_ok();
1285 }
1286
1287 ferr_r isis_circuit_metric_set(struct isis_circuit *circuit, int level,
1288 int metric)
1289 {
1290 assert(level == IS_LEVEL_1 || level == IS_LEVEL_2);
1291 if (metric > MAX_WIDE_LINK_METRIC)
1292 return ferr_cfg_invalid("metric %d too large for wide metric",
1293 metric);
1294 if (circuit->area && circuit->area->oldmetric
1295 && metric > MAX_NARROW_LINK_METRIC)
1296 return ferr_cfg_invalid("metric %d too large for narrow metric",
1297 metric);
1298
1299 circuit->te_metric[level - 1] = metric;
1300 circuit->metric[level - 1] = metric;
1301
1302 if (circuit->area)
1303 lsp_regenerate_schedule(circuit->area, level, 0);
1304 return ferr_ok();
1305 }
1306
1307 ferr_r isis_circuit_passwd_unset(struct isis_circuit *circuit)
1308 {
1309 memset(&circuit->passwd, 0, sizeof(circuit->passwd));
1310 return ferr_ok();
1311 }
1312
1313 ferr_r isis_circuit_passwd_set(struct isis_circuit *circuit,
1314 uint8_t passwd_type, const char *passwd)
1315 {
1316 int len;
1317
1318 if (!passwd)
1319 return ferr_code_bug("no circuit password given");
1320
1321 len = strlen(passwd);
1322 if (len > 254)
1323 return ferr_code_bug(
1324 "circuit password too long (max 254 chars)");
1325
1326 circuit->passwd.len = len;
1327 strlcpy((char *)circuit->passwd.passwd, passwd,
1328 sizeof(circuit->passwd.passwd));
1329 circuit->passwd.type = passwd_type;
1330 return ferr_ok();
1331 }
1332
1333 ferr_r isis_circuit_passwd_cleartext_set(struct isis_circuit *circuit,
1334 const char *passwd)
1335 {
1336 return isis_circuit_passwd_set(circuit, ISIS_PASSWD_TYPE_CLEARTXT,
1337 passwd);
1338 }
1339
1340 ferr_r isis_circuit_passwd_hmac_md5_set(struct isis_circuit *circuit,
1341 const char *passwd)
1342 {
1343 return isis_circuit_passwd_set(circuit, ISIS_PASSWD_TYPE_HMAC_MD5,
1344 passwd);
1345 }
1346
1347 struct cmd_node interface_node = {
1348 .name = "interface",
1349 .node = INTERFACE_NODE,
1350 .parent_node = CONFIG_NODE,
1351 .prompt = "%s(config-if)# ",
1352 .config_write = isis_interface_config_write,
1353 };
1354
1355 void isis_circuit_circ_type_set(struct isis_circuit *circuit, int circ_type)
1356 {
1357 if (circuit->circ_type == circ_type)
1358 return;
1359
1360 if (circuit->state != C_STATE_UP) {
1361 circuit->circ_type = circ_type;
1362 circuit->circ_type_config = circ_type;
1363 } else {
1364 struct isis_area *area = circuit->area;
1365
1366 isis_csm_state_change(ISIS_DISABLE, circuit, area);
1367 circuit->circ_type = circ_type;
1368 circuit->circ_type_config = circ_type;
1369 isis_csm_state_change(ISIS_ENABLE, circuit, area);
1370 }
1371 }
1372
1373 int isis_circuit_mt_enabled_set(struct isis_circuit *circuit, uint16_t mtid,
1374 bool enabled)
1375 {
1376 struct isis_circuit_mt_setting *setting;
1377
1378 setting = circuit_get_mt_setting(circuit, mtid);
1379 if (setting->enabled != enabled) {
1380 setting->enabled = enabled;
1381 lsp_regenerate_schedule(circuit->area, IS_LEVEL_1 | IS_LEVEL_2,
1382 0);
1383 }
1384
1385 return CMD_SUCCESS;
1386 }
1387
1388 int isis_if_new_hook(struct interface *ifp)
1389 {
1390 return 0;
1391 }
1392
1393 int isis_if_delete_hook(struct interface *ifp)
1394 {
1395 struct isis_circuit *circuit;
1396 /* Clean up the circuit data */
1397 if (ifp && ifp->info) {
1398 circuit = ifp->info;
1399 isis_csm_state_change(IF_DOWN_FROM_Z, circuit, circuit->area);
1400 }
1401
1402 return 0;
1403 }
1404
1405 static int isis_ifp_create(struct interface *ifp)
1406 {
1407 if (if_is_operative(ifp))
1408 isis_csm_state_change(IF_UP_FROM_Z, circuit_scan_by_ifp(ifp),
1409 ifp);
1410
1411 hook_call(isis_if_new_hook, ifp);
1412
1413 return 0;
1414 }
1415
1416 static int isis_ifp_up(struct interface *ifp)
1417 {
1418 isis_csm_state_change(IF_UP_FROM_Z, circuit_scan_by_ifp(ifp), ifp);
1419
1420 return 0;
1421 }
1422
1423 static int isis_ifp_down(struct interface *ifp)
1424 {
1425 struct isis_circuit *circuit;
1426
1427 circuit = isis_csm_state_change(IF_DOWN_FROM_Z,
1428 circuit_scan_by_ifp(ifp), ifp);
1429 if (circuit)
1430 SET_FLAG(circuit->flags, ISIS_CIRCUIT_FLAPPED_AFTER_SPF);
1431
1432 return 0;
1433 }
1434
1435 static int isis_ifp_destroy(struct interface *ifp)
1436 {
1437 if (if_is_operative(ifp))
1438 zlog_warn("Zebra: got delete of %s, but interface is still up",
1439 ifp->name);
1440
1441 isis_csm_state_change(IF_DOWN_FROM_Z, circuit_scan_by_ifp(ifp), ifp);
1442
1443 /* Cannot call if_delete because we should retain the pseudo interface
1444 in case there is configuration info attached to it. */
1445 if_delete_retain(ifp);
1446
1447 return 0;
1448 }
1449
1450 void isis_circuit_init(void)
1451 {
1452 /* Initialize Zebra interface data structure */
1453 hook_register_prio(if_add, 0, isis_if_new_hook);
1454 hook_register_prio(if_del, 0, isis_if_delete_hook);
1455
1456 /* Install interface node */
1457 install_node(&interface_node);
1458 if_cmd_init();
1459 if_zapi_callbacks(isis_ifp_create, isis_ifp_up,
1460 isis_ifp_down, isis_ifp_destroy);
1461 }