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