]> git.proxmox.com Git - mirror_frr.git/blob - isisd/isis_circuit.c
Merge pull request #6649 from xThaid/dplane_batching2
[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 (IS_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 /* log adjacency changes if configured to do so */
724 if (circuit->area->log_adj_changes) {
725 struct isis_adjacency *adj = NULL;
726 if (circuit->circ_type == CIRCUIT_T_P2P) {
727 adj = circuit->u.p2p.neighbor;
728 if (adj)
729 isis_log_adj_change(
730 adj, adj->adj_state, ISIS_ADJ_DOWN,
731 "circuit is being brought down");
732 } else if (circuit->circ_type == CIRCUIT_T_BROADCAST) {
733 struct list *adj_list;
734 struct listnode *node;
735 if (circuit->u.bc.adjdb[0]) {
736 adj_list = list_new();
737 isis_adj_build_up_list(circuit->u.bc.adjdb[0],
738 adj_list);
739 for (ALL_LIST_ELEMENTS_RO(adj_list, node, adj))
740 isis_log_adj_change(
741 adj, adj->adj_state,
742 ISIS_ADJ_DOWN,
743 "circuit is being brought down");
744 list_delete(&adj_list);
745 }
746 if (circuit->u.bc.adjdb[1]) {
747 adj_list = list_new();
748 isis_adj_build_up_list(circuit->u.bc.adjdb[1],
749 adj_list);
750 for (ALL_LIST_ELEMENTS_RO(adj_list, node, adj))
751 isis_log_adj_change(
752 adj, adj->adj_state,
753 ISIS_ADJ_DOWN,
754 "circuit is being brought down");
755 list_delete(&adj_list);
756 }
757 }
758 }
759
760 /* Clear the flags for all the lsps of the circuit. */
761 isis_circuit_update_all_srmflags(circuit, 0);
762
763 if (circuit->circ_type == CIRCUIT_T_BROADCAST) {
764 /* destroy neighbour lists */
765 if (circuit->u.bc.lan_neighs[0]) {
766 list_delete(&circuit->u.bc.lan_neighs[0]);
767 circuit->u.bc.lan_neighs[0] = NULL;
768 }
769 if (circuit->u.bc.lan_neighs[1]) {
770 list_delete(&circuit->u.bc.lan_neighs[1]);
771 circuit->u.bc.lan_neighs[1] = NULL;
772 }
773 /* destroy adjacency databases */
774 if (circuit->u.bc.adjdb[0]) {
775 circuit->u.bc.adjdb[0]->del = isis_delete_adj;
776 list_delete(&circuit->u.bc.adjdb[0]);
777 circuit->u.bc.adjdb[0] = NULL;
778 }
779 if (circuit->u.bc.adjdb[1]) {
780 circuit->u.bc.adjdb[1]->del = isis_delete_adj;
781 list_delete(&circuit->u.bc.adjdb[1]);
782 circuit->u.bc.adjdb[1] = NULL;
783 }
784 if (circuit->u.bc.is_dr[0]) {
785 isis_dr_resign(circuit, 1);
786 circuit->u.bc.is_dr[0] = 0;
787 }
788 memset(circuit->u.bc.l1_desig_is, 0, ISIS_SYS_ID_LEN + 1);
789 if (circuit->u.bc.is_dr[1]) {
790 isis_dr_resign(circuit, 2);
791 circuit->u.bc.is_dr[1] = 0;
792 }
793 memset(circuit->u.bc.l2_desig_is, 0, ISIS_SYS_ID_LEN + 1);
794 memset(circuit->u.bc.snpa, 0, ETH_ALEN);
795
796 THREAD_TIMER_OFF(circuit->u.bc.t_send_lan_hello[0]);
797 THREAD_TIMER_OFF(circuit->u.bc.t_send_lan_hello[1]);
798 THREAD_TIMER_OFF(circuit->u.bc.t_run_dr[0]);
799 THREAD_TIMER_OFF(circuit->u.bc.t_run_dr[1]);
800 THREAD_TIMER_OFF(circuit->u.bc.t_refresh_pseudo_lsp[0]);
801 THREAD_TIMER_OFF(circuit->u.bc.t_refresh_pseudo_lsp[1]);
802 circuit->lsp_regenerate_pending[0] = 0;
803 circuit->lsp_regenerate_pending[1] = 0;
804
805 _ISIS_CLEAR_FLAG(isis->circuit_ids_used, circuit->circuit_id);
806 circuit->circuit_id = 0;
807 } else if (circuit->circ_type == CIRCUIT_T_P2P) {
808 isis_delete_adj(circuit->u.p2p.neighbor);
809 circuit->u.p2p.neighbor = NULL;
810 THREAD_TIMER_OFF(circuit->u.p2p.t_send_p2p_hello);
811 }
812
813 /* Cancel all active threads */
814 THREAD_TIMER_OFF(circuit->t_send_csnp[0]);
815 THREAD_TIMER_OFF(circuit->t_send_csnp[1]);
816 THREAD_TIMER_OFF(circuit->t_send_psnp[0]);
817 THREAD_TIMER_OFF(circuit->t_send_psnp[1]);
818 THREAD_OFF(circuit->t_read);
819
820 if (circuit->tx_queue) {
821 isis_tx_queue_free(circuit->tx_queue);
822 circuit->tx_queue = NULL;
823 }
824
825 /* send one gratuitous hello to spead up convergence */
826 if (circuit->state == C_STATE_UP) {
827 if (circuit->is_type & IS_LEVEL_1)
828 send_hello(circuit, IS_LEVEL_1);
829 if (circuit->is_type & IS_LEVEL_2)
830 send_hello(circuit, IS_LEVEL_2);
831 }
832
833 circuit->upadjcount[0] = 0;
834 circuit->upadjcount[1] = 0;
835
836 /* close the socket */
837 if (circuit->fd) {
838 close(circuit->fd);
839 circuit->fd = 0;
840 }
841
842 if (circuit->rcv_stream != NULL) {
843 stream_free(circuit->rcv_stream);
844 circuit->rcv_stream = NULL;
845 }
846
847 if (circuit->snd_stream != NULL) {
848 stream_free(circuit->snd_stream);
849 circuit->snd_stream = NULL;
850 }
851
852 thread_cancel_event(master, circuit);
853
854 return;
855 }
856
857 void circuit_update_nlpids(struct isis_circuit *circuit)
858 {
859 circuit->nlpids.count = 0;
860
861 if (circuit->ip_router) {
862 circuit->nlpids.nlpids[0] = NLPID_IP;
863 circuit->nlpids.count++;
864 }
865 if (circuit->ipv6_router) {
866 circuit->nlpids.nlpids[circuit->nlpids.count] = NLPID_IPV6;
867 circuit->nlpids.count++;
868 }
869 return;
870 }
871
872 void isis_circuit_print_vty(struct isis_circuit *circuit, struct vty *vty,
873 char detail)
874 {
875 if (detail == ISIS_UI_LEVEL_BRIEF) {
876 vty_out(vty, " %-12s", circuit->interface->name);
877 vty_out(vty, "0x%-7x", circuit->circuit_id);
878 vty_out(vty, "%-9s", circuit_state2string(circuit->state));
879 vty_out(vty, "%-9s", circuit_type2string(circuit->circ_type));
880 vty_out(vty, "%-9s", circuit_t2string(circuit->is_type));
881 vty_out(vty, "\n");
882 }
883
884 if (detail == ISIS_UI_LEVEL_DETAIL) {
885 struct listnode *node;
886 struct prefix *ip_addr;
887 char buf[BUFSIZ];
888
889 vty_out(vty, " Interface: %s", circuit->interface->name);
890 vty_out(vty, ", State: %s",
891 circuit_state2string(circuit->state));
892 if (circuit->is_passive)
893 vty_out(vty, ", Passive");
894 else
895 vty_out(vty, ", Active");
896 vty_out(vty, ", Circuit Id: 0x%x", circuit->circuit_id);
897 vty_out(vty, "\n");
898 vty_out(vty, " Type: %s",
899 circuit_type2string(circuit->circ_type));
900 vty_out(vty, ", Level: %s", circuit_t2string(circuit->is_type));
901 if (circuit->circ_type == CIRCUIT_T_BROADCAST)
902 vty_out(vty, ", SNPA: %-10s",
903 snpa_print(circuit->u.bc.snpa));
904 vty_out(vty, "\n");
905 if (circuit->is_type & IS_LEVEL_1) {
906 vty_out(vty, " Level-1 Information:\n");
907 if (circuit->area->newmetric)
908 vty_out(vty, " Metric: %d",
909 circuit->te_metric[0]);
910 else
911 vty_out(vty, " Metric: %d",
912 circuit->metric[0]);
913 if (!circuit->is_passive) {
914 vty_out(vty, ", Active neighbors: %u\n",
915 circuit->upadjcount[0]);
916 vty_out(vty,
917 " Hello interval: %u, "
918 "Holddown count: %u %s\n",
919 circuit->hello_interval[0],
920 circuit->hello_multiplier[0],
921 (circuit->pad_hellos ? "(pad)"
922 : "(no-pad)"));
923 vty_out(vty,
924 " CNSP interval: %u, "
925 "PSNP interval: %u\n",
926 circuit->csnp_interval[0],
927 circuit->psnp_interval[0]);
928 if (circuit->circ_type == CIRCUIT_T_BROADCAST)
929 vty_out(vty,
930 " LAN Priority: %u, %s\n",
931 circuit->priority[0],
932 (circuit->u.bc.is_dr[0]
933 ? "is DIS"
934 : "is not DIS"));
935 } else {
936 vty_out(vty, "\n");
937 }
938 }
939 if (circuit->is_type & IS_LEVEL_2) {
940 vty_out(vty, " Level-2 Information:\n");
941 if (circuit->area->newmetric)
942 vty_out(vty, " Metric: %d",
943 circuit->te_metric[1]);
944 else
945 vty_out(vty, " Metric: %d",
946 circuit->metric[1]);
947 if (!circuit->is_passive) {
948 vty_out(vty, ", Active neighbors: %u\n",
949 circuit->upadjcount[1]);
950 vty_out(vty,
951 " Hello interval: %u, "
952 "Holddown count: %u %s\n",
953 circuit->hello_interval[1],
954 circuit->hello_multiplier[1],
955 (circuit->pad_hellos ? "(pad)"
956 : "(no-pad)"));
957 vty_out(vty,
958 " CNSP interval: %u, "
959 "PSNP interval: %u\n",
960 circuit->csnp_interval[1],
961 circuit->psnp_interval[1]);
962 if (circuit->circ_type == CIRCUIT_T_BROADCAST)
963 vty_out(vty,
964 " LAN Priority: %u, %s\n",
965 circuit->priority[1],
966 (circuit->u.bc.is_dr[1]
967 ? "is DIS"
968 : "is not DIS"));
969 } else {
970 vty_out(vty, "\n");
971 }
972 }
973 if (circuit->ip_addrs && listcount(circuit->ip_addrs) > 0) {
974 vty_out(vty, " IP Prefix(es):\n");
975 for (ALL_LIST_ELEMENTS_RO(circuit->ip_addrs, node,
976 ip_addr)) {
977 prefix2str(ip_addr, buf, sizeof(buf));
978 vty_out(vty, " %s\n", buf);
979 }
980 }
981 if (circuit->ipv6_link && listcount(circuit->ipv6_link) > 0) {
982 vty_out(vty, " IPv6 Link-Locals:\n");
983 for (ALL_LIST_ELEMENTS_RO(circuit->ipv6_link, node,
984 ip_addr)) {
985 prefix2str(ip_addr, (char *)buf, BUFSIZ);
986 vty_out(vty, " %s\n", buf);
987 }
988 }
989 if (circuit->ipv6_non_link
990 && listcount(circuit->ipv6_non_link) > 0) {
991 vty_out(vty, " IPv6 Prefixes:\n");
992 for (ALL_LIST_ELEMENTS_RO(circuit->ipv6_non_link, node,
993 ip_addr)) {
994 prefix2str(ip_addr, (char *)buf, BUFSIZ);
995 vty_out(vty, " %s\n", buf);
996 }
997 }
998
999 vty_out(vty, "\n");
1000 }
1001 return;
1002 }
1003
1004 #ifdef FABRICD
1005 DEFINE_HOOK(isis_circuit_config_write,
1006 (struct isis_circuit *circuit, struct vty *vty),
1007 (circuit, vty))
1008
1009 static int isis_interface_config_write(struct vty *vty)
1010 {
1011 struct vrf *vrf = vrf_lookup_by_id(VRF_DEFAULT);
1012 int write = 0;
1013 struct listnode *node;
1014 struct interface *ifp;
1015 struct isis_area *area;
1016 struct isis_circuit *circuit;
1017 int i;
1018
1019 FOR_ALL_INTERFACES (vrf, ifp) {
1020 /* IF name */
1021 vty_frame(vty, "interface %s\n", ifp->name);
1022 write++;
1023 /* IF desc */
1024 if (ifp->desc) {
1025 vty_out(vty, " description %s\n", ifp->desc);
1026 write++;
1027 }
1028 /* ISIS Circuit */
1029 for (ALL_LIST_ELEMENTS_RO(isis->area_list, node, area)) {
1030 circuit =
1031 circuit_lookup_by_ifp(ifp, area->circuit_list);
1032 if (circuit == NULL)
1033 continue;
1034 if (circuit->ip_router) {
1035 vty_out(vty, " ip router " PROTO_NAME " %s\n",
1036 area->area_tag);
1037 write++;
1038 }
1039 if (circuit->is_passive) {
1040 vty_out(vty, " " PROTO_NAME " passive\n");
1041 write++;
1042 }
1043 if (circuit->circ_type_config == CIRCUIT_T_P2P) {
1044 vty_out(vty, " " PROTO_NAME " network point-to-point\n");
1045 write++;
1046 }
1047 if (circuit->ipv6_router) {
1048 vty_out(vty, " ipv6 router " PROTO_NAME " %s\n",
1049 area->area_tag);
1050 write++;
1051 }
1052
1053 /* ISIS - circuit type */
1054 if (!fabricd) {
1055 if (circuit->is_type == IS_LEVEL_1) {
1056 vty_out(vty, " " PROTO_NAME " circuit-type level-1\n");
1057 write++;
1058 } else {
1059 if (circuit->is_type == IS_LEVEL_2) {
1060 vty_out(vty,
1061 " " PROTO_NAME " circuit-type level-2-only\n");
1062 write++;
1063 }
1064 }
1065 }
1066
1067 /* ISIS - CSNP interval */
1068 if (circuit->csnp_interval[0]
1069 == circuit->csnp_interval[1]) {
1070 if (circuit->csnp_interval[0]
1071 != DEFAULT_CSNP_INTERVAL) {
1072 vty_out(vty, " " PROTO_NAME " csnp-interval %d\n",
1073 circuit->csnp_interval[0]);
1074 write++;
1075 }
1076 } else {
1077 for (i = 0; i < 2; i++) {
1078 if (circuit->csnp_interval[i]
1079 != DEFAULT_CSNP_INTERVAL) {
1080 vty_out(vty,
1081 " " PROTO_NAME " csnp-interval %d level-%d\n",
1082 circuit->csnp_interval
1083 [i],
1084 i + 1);
1085 write++;
1086 }
1087 }
1088 }
1089
1090 /* ISIS - PSNP interval */
1091 if (circuit->psnp_interval[0]
1092 == circuit->psnp_interval[1]) {
1093 if (circuit->psnp_interval[0]
1094 != DEFAULT_PSNP_INTERVAL) {
1095 vty_out(vty, " " PROTO_NAME " psnp-interval %d\n",
1096 circuit->psnp_interval[0]);
1097 write++;
1098 }
1099 } else {
1100 for (i = 0; i < 2; i++) {
1101 if (circuit->psnp_interval[i]
1102 != DEFAULT_PSNP_INTERVAL) {
1103 vty_out(vty,
1104 " " PROTO_NAME " psnp-interval %d level-%d\n",
1105 circuit->psnp_interval
1106 [i],
1107 i + 1);
1108 write++;
1109 }
1110 }
1111 }
1112
1113 /* ISIS - Hello padding - Defaults to true so only
1114 * display if false */
1115 if (circuit->pad_hellos == 0) {
1116 vty_out(vty, " no " PROTO_NAME " hello padding\n");
1117 write++;
1118 }
1119
1120 if (circuit->disable_threeway_adj) {
1121 vty_out(vty, " no isis three-way-handshake\n");
1122 write++;
1123 }
1124
1125 /* ISIS - Hello interval */
1126 if (circuit->hello_interval[0]
1127 == circuit->hello_interval[1]) {
1128 if (circuit->hello_interval[0]
1129 != DEFAULT_HELLO_INTERVAL) {
1130 vty_out(vty,
1131 " " PROTO_NAME " hello-interval %d\n",
1132 circuit->hello_interval[0]);
1133 write++;
1134 }
1135 } else {
1136 for (i = 0; i < 2; i++) {
1137 if (circuit->hello_interval[i]
1138 != DEFAULT_HELLO_INTERVAL) {
1139 vty_out(vty,
1140 " " PROTO_NAME " hello-interval %d level-%d\n",
1141 circuit->hello_interval
1142 [i],
1143 i + 1);
1144 write++;
1145 }
1146 }
1147 }
1148
1149 /* ISIS - Hello Multiplier */
1150 if (circuit->hello_multiplier[0]
1151 == circuit->hello_multiplier[1]) {
1152 if (circuit->hello_multiplier[0]
1153 != DEFAULT_HELLO_MULTIPLIER) {
1154 vty_out(vty,
1155 " " PROTO_NAME " hello-multiplier %d\n",
1156 circuit->hello_multiplier[0]);
1157 write++;
1158 }
1159 } else {
1160 for (i = 0; i < 2; i++) {
1161 if (circuit->hello_multiplier[i]
1162 != DEFAULT_HELLO_MULTIPLIER) {
1163 vty_out(vty,
1164 " " PROTO_NAME " hello-multiplier %d level-%d\n",
1165 circuit->hello_multiplier
1166 [i],
1167 i + 1);
1168 write++;
1169 }
1170 }
1171 }
1172
1173 /* ISIS - Priority */
1174 if (circuit->priority[0] == circuit->priority[1]) {
1175 if (circuit->priority[0] != DEFAULT_PRIORITY) {
1176 vty_out(vty, " " PROTO_NAME " priority %d\n",
1177 circuit->priority[0]);
1178 write++;
1179 }
1180 } else {
1181 for (i = 0; i < 2; i++) {
1182 if (circuit->priority[i]
1183 != DEFAULT_PRIORITY) {
1184 vty_out(vty,
1185 " " PROTO_NAME " priority %d level-%d\n",
1186 circuit->priority[i],
1187 i + 1);
1188 write++;
1189 }
1190 }
1191 }
1192
1193 /* ISIS - Metric */
1194 if (circuit->te_metric[0] == circuit->te_metric[1]) {
1195 if (circuit->te_metric[0]
1196 != DEFAULT_CIRCUIT_METRIC) {
1197 vty_out(vty, " " PROTO_NAME " metric %d\n",
1198 circuit->te_metric[0]);
1199 write++;
1200 }
1201 } else {
1202 for (i = 0; i < 2; i++) {
1203 if (circuit->te_metric[i]
1204 != DEFAULT_CIRCUIT_METRIC) {
1205 vty_out(vty,
1206 " " PROTO_NAME " metric %d level-%d\n",
1207 circuit->te_metric[i],
1208 i + 1);
1209 write++;
1210 }
1211 }
1212 }
1213 if (circuit->passwd.type == ISIS_PASSWD_TYPE_HMAC_MD5) {
1214 vty_out(vty, " " PROTO_NAME " password md5 %s\n",
1215 circuit->passwd.passwd);
1216 write++;
1217 } else if (circuit->passwd.type
1218 == ISIS_PASSWD_TYPE_CLEARTXT) {
1219 vty_out(vty, " " PROTO_NAME " password clear %s\n",
1220 circuit->passwd.passwd);
1221 write++;
1222 }
1223 write += hook_call(isis_circuit_config_write,
1224 circuit, vty);
1225 }
1226 vty_endframe(vty, "!\n");
1227 }
1228
1229 return write;
1230 }
1231 #else
1232 static int isis_interface_config_write(struct vty *vty)
1233 {
1234 struct vrf *vrf = vrf_lookup_by_id(VRF_DEFAULT);
1235 int write = 0;
1236 struct interface *ifp;
1237 struct lyd_node *dnode;
1238
1239 FOR_ALL_INTERFACES (vrf, ifp) {
1240 dnode = yang_dnode_get(
1241 running_config->dnode,
1242 "/frr-interface:lib/interface[name='%s'][vrf='%s']",
1243 ifp->name, vrf->name);
1244 if (dnode == NULL)
1245 continue;
1246
1247 write++;
1248 nb_cli_show_dnode_cmds(vty, dnode, false);
1249 }
1250 return write;
1251 }
1252 #endif /* ifdef FABRICD */
1253
1254 struct isis_circuit *isis_circuit_create(struct isis_area *area,
1255 struct interface *ifp)
1256 {
1257 struct isis_circuit *circuit = circuit_scan_by_ifp(ifp);
1258 if (circuit && circuit->area)
1259 return NULL;
1260 circuit = isis_csm_state_change(ISIS_ENABLE, circuit, area);
1261 if (circuit->state != C_STATE_CONF && circuit->state != C_STATE_UP)
1262 return circuit;
1263 isis_circuit_if_bind(circuit, ifp);
1264 if (circuit->area->mta && circuit->area->mta->status)
1265 isis_link_params_update(circuit, ifp);
1266 return circuit;
1267 }
1268
1269 void isis_circuit_af_set(struct isis_circuit *circuit, bool ip_router,
1270 bool ipv6_router)
1271 {
1272 struct isis_area *area = circuit->area;
1273 int old_ipr = circuit->ip_router;
1274 int old_ipv6r = circuit->ipv6_router;
1275
1276 /* is there something to do? */
1277 if (old_ipr == ip_router && old_ipv6r == ipv6_router)
1278 return;
1279
1280 circuit->ip_router = ip_router;
1281 circuit->ipv6_router = ipv6_router;
1282 circuit_update_nlpids(circuit);
1283
1284 /* the area should always be there if we get here, but in the past
1285 * there were corner cases where the area was NULL (e.g. because the
1286 * circuit was deconfigured following a validation error). Do not
1287 * segfault if this happens again.
1288 */
1289 if (!area) {
1290 zlog_err("%s: NULL area for circuit %u", __func__,
1291 circuit->circuit_id);
1292 return;
1293 }
1294
1295 area->ip_circuits += ip_router - old_ipr;
1296 area->ipv6_circuits += ipv6_router - old_ipv6r;
1297
1298 if (!ip_router && !ipv6_router)
1299 isis_csm_state_change(ISIS_DISABLE, circuit, area);
1300 else
1301 lsp_regenerate_schedule(area, circuit->is_type, 0);
1302 }
1303
1304 ferr_r isis_circuit_passive_set(struct isis_circuit *circuit, bool passive)
1305 {
1306 if (circuit->is_passive == passive)
1307 return ferr_ok();
1308
1309 if (if_is_loopback(circuit->interface) && !passive)
1310 return ferr_cfg_invalid("loopback is always passive");
1311
1312 if (circuit->state != C_STATE_UP) {
1313 circuit->is_passive = passive;
1314 } else {
1315 struct isis_area *area = circuit->area;
1316 isis_csm_state_change(ISIS_DISABLE, circuit, area);
1317 circuit->is_passive = passive;
1318 isis_csm_state_change(ISIS_ENABLE, circuit, area);
1319 }
1320
1321 return ferr_ok();
1322 }
1323
1324 ferr_r isis_circuit_metric_set(struct isis_circuit *circuit, int level,
1325 int metric)
1326 {
1327 assert(level == IS_LEVEL_1 || level == IS_LEVEL_2);
1328 if (metric > MAX_WIDE_LINK_METRIC)
1329 return ferr_cfg_invalid("metric %d too large for wide metric",
1330 metric);
1331 if (circuit->area && circuit->area->oldmetric
1332 && metric > MAX_NARROW_LINK_METRIC)
1333 return ferr_cfg_invalid("metric %d too large for narrow metric",
1334 metric);
1335
1336 circuit->te_metric[level - 1] = metric;
1337 circuit->metric[level - 1] = metric;
1338
1339 if (circuit->area)
1340 lsp_regenerate_schedule(circuit->area, level, 0);
1341 return ferr_ok();
1342 }
1343
1344 ferr_r isis_circuit_passwd_unset(struct isis_circuit *circuit)
1345 {
1346 memset(&circuit->passwd, 0, sizeof(circuit->passwd));
1347 return ferr_ok();
1348 }
1349
1350 ferr_r isis_circuit_passwd_set(struct isis_circuit *circuit,
1351 uint8_t passwd_type, const char *passwd)
1352 {
1353 int len;
1354
1355 if (!passwd)
1356 return ferr_code_bug("no circuit password given");
1357
1358 len = strlen(passwd);
1359 if (len > 254)
1360 return ferr_code_bug(
1361 "circuit password too long (max 254 chars)");
1362
1363 circuit->passwd.len = len;
1364 strlcpy((char *)circuit->passwd.passwd, passwd,
1365 sizeof(circuit->passwd.passwd));
1366 circuit->passwd.type = passwd_type;
1367 return ferr_ok();
1368 }
1369
1370 ferr_r isis_circuit_passwd_cleartext_set(struct isis_circuit *circuit,
1371 const char *passwd)
1372 {
1373 return isis_circuit_passwd_set(circuit, ISIS_PASSWD_TYPE_CLEARTXT,
1374 passwd);
1375 }
1376
1377 ferr_r isis_circuit_passwd_hmac_md5_set(struct isis_circuit *circuit,
1378 const char *passwd)
1379 {
1380 return isis_circuit_passwd_set(circuit, ISIS_PASSWD_TYPE_HMAC_MD5,
1381 passwd);
1382 }
1383
1384 struct cmd_node interface_node = {
1385 .name = "interface",
1386 .node = INTERFACE_NODE,
1387 .parent_node = CONFIG_NODE,
1388 .prompt = "%s(config-if)# ",
1389 .config_write = isis_interface_config_write,
1390 };
1391
1392 void isis_circuit_circ_type_set(struct isis_circuit *circuit, int circ_type)
1393 {
1394 if (circuit->circ_type == circ_type)
1395 return;
1396
1397 if (circuit->state != C_STATE_UP) {
1398 circuit->circ_type = circ_type;
1399 circuit->circ_type_config = circ_type;
1400 } else {
1401 struct isis_area *area = circuit->area;
1402
1403 isis_csm_state_change(ISIS_DISABLE, circuit, area);
1404 circuit->circ_type = circ_type;
1405 circuit->circ_type_config = circ_type;
1406 isis_csm_state_change(ISIS_ENABLE, circuit, area);
1407 }
1408 }
1409
1410 int isis_circuit_mt_enabled_set(struct isis_circuit *circuit, uint16_t mtid,
1411 bool enabled)
1412 {
1413 struct isis_circuit_mt_setting *setting;
1414
1415 setting = circuit_get_mt_setting(circuit, mtid);
1416 if (setting->enabled != enabled) {
1417 setting->enabled = enabled;
1418 lsp_regenerate_schedule(circuit->area, IS_LEVEL_1 | IS_LEVEL_2,
1419 0);
1420 }
1421
1422 return CMD_SUCCESS;
1423 }
1424
1425 int isis_if_new_hook(struct interface *ifp)
1426 {
1427 return 0;
1428 }
1429
1430 int isis_if_delete_hook(struct interface *ifp)
1431 {
1432 struct isis_circuit *circuit;
1433 /* Clean up the circuit data */
1434 if (ifp && ifp->info) {
1435 circuit = ifp->info;
1436 isis_csm_state_change(IF_DOWN_FROM_Z, circuit, circuit->area);
1437 }
1438
1439 return 0;
1440 }
1441
1442 static int isis_ifp_create(struct interface *ifp)
1443 {
1444 if (if_is_operative(ifp))
1445 isis_csm_state_change(IF_UP_FROM_Z, circuit_scan_by_ifp(ifp),
1446 ifp);
1447
1448 hook_call(isis_if_new_hook, ifp);
1449
1450 return 0;
1451 }
1452
1453 static int isis_ifp_up(struct interface *ifp)
1454 {
1455 isis_csm_state_change(IF_UP_FROM_Z, circuit_scan_by_ifp(ifp), ifp);
1456
1457 return 0;
1458 }
1459
1460 static int isis_ifp_down(struct interface *ifp)
1461 {
1462 struct isis_circuit *circuit;
1463
1464 circuit = isis_csm_state_change(IF_DOWN_FROM_Z,
1465 circuit_scan_by_ifp(ifp), ifp);
1466 if (circuit)
1467 SET_FLAG(circuit->flags, ISIS_CIRCUIT_FLAPPED_AFTER_SPF);
1468
1469 return 0;
1470 }
1471
1472 static int isis_ifp_destroy(struct interface *ifp)
1473 {
1474 if (if_is_operative(ifp))
1475 zlog_warn("Zebra: got delete of %s, but interface is still up",
1476 ifp->name);
1477
1478 isis_csm_state_change(IF_DOWN_FROM_Z, circuit_scan_by_ifp(ifp), ifp);
1479
1480 /* Cannot call if_delete because we should retain the pseudo interface
1481 in case there is configuration info attached to it. */
1482 if_delete_retain(ifp);
1483
1484 return 0;
1485 }
1486
1487 void isis_circuit_init(void)
1488 {
1489 /* Initialize Zebra interface data structure */
1490 hook_register_prio(if_add, 0, isis_if_new_hook);
1491 hook_register_prio(if_del, 0, isis_if_delete_hook);
1492
1493 /* Install interface node */
1494 install_node(&interface_node);
1495 if_cmd_init();
1496 if_zapi_callbacks(isis_ifp_create, isis_ifp_up,
1497 isis_ifp_down, isis_ifp_destroy);
1498 }