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