]> git.proxmox.com Git - mirror_frr.git/blob - isisd/isisd.c
*: Properly use memset() when zeroing
[mirror_frr.git] / isisd / isisd.c
1 /*
2 * IS-IS Rout(e)ing protocol - isisd.c
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
23 #include <zebra.h>
24
25 #include "thread.h"
26 #include "vty.h"
27 #include "command.h"
28 #include "log.h"
29 #include "memory.h"
30 #include "time.h"
31 #include "linklist.h"
32 #include "if.h"
33 #include "hash.h"
34 #include "filter.h"
35 #include "plist.h"
36 #include "stream.h"
37 #include "prefix.h"
38 #include "table.h"
39 #include "qobj.h"
40 #include "zclient.h"
41 #include "vrf.h"
42 #include "spf_backoff.h"
43 #include "lib/northbound_cli.h"
44 #include "bfd.h"
45
46 #include "isisd/isis_constants.h"
47 #include "isisd/isis_common.h"
48 #include "isisd/isis_flags.h"
49 #include "isisd/isis_circuit.h"
50 #include "isisd/isis_csm.h"
51 #include "isisd/isisd.h"
52 #include "isisd/isis_dynhn.h"
53 #include "isisd/isis_adjacency.h"
54 #include "isisd/isis_pdu.h"
55 #include "isisd/isis_misc.h"
56 #include "isisd/isis_constants.h"
57 #include "isisd/isis_lsp.h"
58 #include "isisd/isis_spf.h"
59 #include "isisd/isis_route.h"
60 #include "isisd/isis_zebra.h"
61 #include "isisd/isis_events.h"
62 #include "isisd/isis_te.h"
63 #include "isisd/isis_mt.h"
64 #include "isisd/isis_sr.h"
65 #include "isisd/fabricd.h"
66 #include "isisd/isis_nb.h"
67
68 /* For debug statement. */
69 unsigned long debug_adj_pkt;
70 unsigned long debug_snp_pkt;
71 unsigned long debug_update_pkt;
72 unsigned long debug_spf_events;
73 unsigned long debug_rte_events;
74 unsigned long debug_events;
75 unsigned long debug_pkt_dump;
76 unsigned long debug_lsp_gen;
77 unsigned long debug_lsp_sched;
78 unsigned long debug_flooding;
79 unsigned long debug_bfd;
80 unsigned long debug_tx_queue;
81 unsigned long debug_sr;
82 unsigned long debug_ldp_sync;
83 unsigned long debug_lfa;
84 unsigned long debug_te;
85
86 DEFINE_MGROUP(ISISD, "isisd");
87
88 DEFINE_MTYPE_STATIC(ISISD, ISIS, "ISIS process");
89 DEFINE_MTYPE_STATIC(ISISD, ISIS_NAME, "ISIS process name");
90 DEFINE_MTYPE_STATIC(ISISD, ISIS_AREA, "ISIS area");
91 DEFINE_MTYPE(ISISD, ISIS_AREA_ADDR, "ISIS area address");
92 DEFINE_MTYPE(ISISD, ISIS_ACL_NAME, "ISIS access-list name");
93
94 DEFINE_QOBJ_TYPE(isis_area);
95
96 /* ISIS process wide configuration. */
97 static struct isis_master isis_master;
98
99 /* ISIS process wide configuration pointer to export. */
100 struct isis_master *im;
101
102 #ifndef FABRICD
103 DEFINE_HOOK(isis_hook_db_overload, (const struct isis_area *area), (area));
104 #endif /* ifndef FABRICD */
105
106 /*
107 * Prototypes.
108 */
109 int isis_area_get(struct vty *, const char *);
110 int area_net_title(struct vty *, const char *);
111 int area_clear_net_title(struct vty *, const char *);
112 int show_isis_interface_common(struct vty *, struct json_object *json,
113 const char *ifname, char, const char *vrf_name,
114 bool all_vrf);
115 int show_isis_interface_common_vty(struct vty *, const char *ifname, char,
116 const char *vrf_name, bool all_vrf);
117 int show_isis_interface_common_json(struct json_object *json,
118 const char *ifname, char,
119 const char *vrf_name, bool all_vrf);
120 int show_isis_neighbor_common(struct vty *, struct json_object *json,
121 const char *id, char, const char *vrf_name,
122 bool all_vrf);
123 int clear_isis_neighbor_common(struct vty *, const char *id,
124 const char *vrf_name, bool all_vrf);
125
126 /* Link ISIS instance to VRF. */
127 void isis_vrf_link(struct isis *isis, struct vrf *vrf)
128 {
129 isis->vrf_id = vrf->vrf_id;
130 if (vrf->info != (void *)isis)
131 vrf->info = (void *)isis;
132 }
133
134 /* Unlink ISIS instance to VRF. */
135 void isis_vrf_unlink(struct isis *isis, struct vrf *vrf)
136 {
137 if (vrf->info == (void *)isis)
138 vrf->info = NULL;
139 isis->vrf_id = VRF_UNKNOWN;
140 }
141
142 struct isis *isis_lookup_by_vrfid(vrf_id_t vrf_id)
143 {
144 struct isis *isis;
145 struct listnode *node;
146
147 for (ALL_LIST_ELEMENTS_RO(im->isis, node, isis))
148 if (isis->vrf_id == vrf_id)
149 return isis;
150
151 return NULL;
152 }
153
154 struct isis *isis_lookup_by_vrfname(const char *vrfname)
155 {
156 struct isis *isis;
157 struct listnode *node;
158
159 for (ALL_LIST_ELEMENTS_RO(im->isis, node, isis))
160 if (isis->name && vrfname && strcmp(isis->name, vrfname) == 0)
161 return isis;
162
163 return NULL;
164 }
165
166 struct isis *isis_lookup_by_sysid(const uint8_t *sysid)
167 {
168 struct isis *isis;
169 struct listnode *node;
170
171 for (ALL_LIST_ELEMENTS_RO(im->isis, node, isis))
172 if (!memcmp(isis->sysid, sysid, ISIS_SYS_ID_LEN))
173 return isis;
174
175 return NULL;
176 }
177
178 void isis_master_init(struct thread_master *master)
179 {
180 memset(&isis_master, 0, sizeof(isis_master));
181 im = &isis_master;
182 im->isis = list_new();
183 im->master = master;
184 }
185
186 struct isis *isis_new(const char *vrf_name)
187 {
188 struct vrf *vrf;
189 struct isis *isis;
190
191 isis = XCALLOC(MTYPE_ISIS, sizeof(struct isis));
192
193 isis->name = XSTRDUP(MTYPE_ISIS_NAME, vrf_name);
194
195 vrf = vrf_lookup_by_name(vrf_name);
196
197 if (vrf)
198 isis_vrf_link(isis, vrf);
199 else
200 isis->vrf_id = VRF_UNKNOWN;
201
202 isis_zebra_vrf_register(isis);
203
204 if (IS_DEBUG_EVENTS)
205 zlog_debug(
206 "%s: Create new isis instance with vrf_name %s vrf_id %u",
207 __func__, isis->name, isis->vrf_id);
208
209 /*
210 * Default values
211 */
212 isis->max_area_addrs = ISIS_DEFAULT_MAX_AREA_ADDRESSES;
213 isis->process_id = getpid();
214 isis->router_id = 0;
215 isis->area_list = list_new();
216 isis->uptime = time(NULL);
217 isis->snmp_notifications = 1;
218 dyn_cache_init(isis);
219
220 listnode_add(im->isis, isis);
221
222 return isis;
223 }
224
225 void isis_finish(struct isis *isis)
226 {
227 struct vrf *vrf = NULL;
228
229 listnode_delete(im->isis, isis);
230
231 isis_zebra_vrf_deregister(isis);
232
233 vrf = vrf_lookup_by_name(isis->name);
234 if (vrf)
235 isis_vrf_unlink(isis, vrf);
236 XFREE(MTYPE_ISIS_NAME, isis->name);
237
238 isis_redist_free(isis);
239 list_delete(&isis->area_list);
240 dyn_cache_finish(isis);
241 XFREE(MTYPE_ISIS, isis);
242 }
243
244 void isis_area_add_circuit(struct isis_area *area, struct isis_circuit *circuit)
245 {
246 isis_csm_state_change(ISIS_ENABLE, circuit, area);
247
248 area->ip_circuits += circuit->ip_router;
249 area->ipv6_circuits += circuit->ipv6_router;
250
251 area->lfa_protected_links[0] += circuit->lfa_protection[0];
252 area->rlfa_protected_links[0] += circuit->rlfa_protection[0];
253 area->tilfa_protected_links[0] += circuit->tilfa_protection[0];
254
255 area->lfa_protected_links[1] += circuit->lfa_protection[1];
256 area->rlfa_protected_links[1] += circuit->rlfa_protection[1];
257 area->tilfa_protected_links[1] += circuit->tilfa_protection[1];
258 }
259
260 void isis_area_del_circuit(struct isis_area *area, struct isis_circuit *circuit)
261 {
262 area->ip_circuits -= circuit->ip_router;
263 area->ipv6_circuits -= circuit->ipv6_router;
264
265 area->lfa_protected_links[0] -= circuit->lfa_protection[0];
266 area->rlfa_protected_links[0] -= circuit->rlfa_protection[0];
267 area->tilfa_protected_links[0] -= circuit->tilfa_protection[0];
268
269 area->lfa_protected_links[1] -= circuit->lfa_protection[1];
270 area->rlfa_protected_links[1] -= circuit->rlfa_protection[1];
271 area->tilfa_protected_links[1] -= circuit->tilfa_protection[1];
272
273 isis_csm_state_change(ISIS_DISABLE, circuit, area);
274 }
275
276 struct isis_area *isis_area_create(const char *area_tag, const char *vrf_name)
277 {
278 struct isis_area *area;
279 struct isis *isis = NULL;
280 struct vrf *vrf = NULL;
281 struct interface *ifp;
282 struct isis_circuit *circuit;
283
284 area = XCALLOC(MTYPE_ISIS_AREA, sizeof(struct isis_area));
285
286 if (!vrf_name)
287 vrf_name = VRF_DEFAULT_NAME;
288
289 vrf = vrf_lookup_by_name(vrf_name);
290 isis = isis_lookup_by_vrfname(vrf_name);
291
292 if (isis == NULL)
293 isis = isis_new(vrf_name);
294
295 listnode_add(isis->area_list, area);
296 area->isis = isis;
297
298 /*
299 * Fabricd runs only as level-2.
300 * For IS-IS, the default is level-1-2
301 */
302 if (fabricd)
303 area->is_type = IS_LEVEL_2;
304 else
305 area->is_type = yang_get_default_enum(
306 "/frr-isisd:isis/instance/is-type");
307
308 /*
309 * intialize the databases
310 */
311 if (area->is_type & IS_LEVEL_1)
312 lsp_db_init(&area->lspdb[0]);
313 if (area->is_type & IS_LEVEL_2)
314 lsp_db_init(&area->lspdb[1]);
315
316 spftree_area_init(area);
317
318 area->circuit_list = list_new();
319 area->adjacency_list = list_new();
320 area->area_addrs = list_new();
321 if (!CHECK_FLAG(im->options, F_ISIS_UNIT_TEST))
322 thread_add_timer(master, lsp_tick, area, 1, &area->t_tick);
323 flags_initialize(&area->flags);
324
325 isis_sr_area_init(area);
326
327 /*
328 * Default values
329 */
330 #ifndef FABRICD
331 enum isis_metric_style default_style;
332
333 area->max_lsp_lifetime[0] = yang_get_default_uint16(
334 "/frr-isisd:isis/instance/lsp/timers/level-1/maximum-lifetime");
335 area->max_lsp_lifetime[1] = yang_get_default_uint16(
336 "/frr-isisd:isis/instance/lsp/timers/level-2/maximum-lifetime");
337 area->lsp_refresh[0] = yang_get_default_uint16(
338 "/frr-isisd:isis/instance/lsp/timers/level-1/refresh-interval");
339 area->lsp_refresh[1] = yang_get_default_uint16(
340 "/frr-isisd:isis/instance/lsp/timers/level-2/refresh-interval");
341 area->lsp_gen_interval[0] = yang_get_default_uint16(
342 "/frr-isisd:isis/instance/lsp/timers/level-1/generation-interval");
343 area->lsp_gen_interval[1] = yang_get_default_uint16(
344 "/frr-isisd:isis/instance/lsp/timers/level-2/generation-interval");
345 area->min_spf_interval[0] = yang_get_default_uint16(
346 "/frr-isisd:isis/instance/spf/minimum-interval/level-1");
347 area->min_spf_interval[1] = yang_get_default_uint16(
348 "/frr-isisd:isis/instance/spf/minimum-interval/level-1");
349 area->dynhostname = yang_get_default_bool(
350 "/frr-isisd:isis/instance/dynamic-hostname");
351 default_style =
352 yang_get_default_enum("/frr-isisd:isis/instance/metric-style");
353 area->oldmetric = default_style == ISIS_WIDE_METRIC ? 0 : 1;
354 area->newmetric = default_style == ISIS_NARROW_METRIC ? 0 : 1;
355 area->lsp_frag_threshold = 90; /* not currently configurable */
356 area->lsp_mtu =
357 yang_get_default_uint16("/frr-isisd:isis/instance/lsp/mtu");
358 area->lfa_load_sharing[0] = yang_get_default_bool(
359 "/frr-isisd:isis/instance/fast-reroute/level-1/lfa/load-sharing");
360 area->lfa_load_sharing[1] = yang_get_default_bool(
361 "/frr-isisd:isis/instance/fast-reroute/level-2/lfa/load-sharing");
362 area->attached_bit_send =
363 yang_get_default_bool("/frr-isisd:isis/instance/attach-send");
364 area->attached_bit_rcv_ignore = yang_get_default_bool(
365 "/frr-isisd:isis/instance/attach-receive-ignore");
366
367 #else
368 area->max_lsp_lifetime[0] = DEFAULT_LSP_LIFETIME; /* 1200 */
369 area->max_lsp_lifetime[1] = DEFAULT_LSP_LIFETIME; /* 1200 */
370 area->lsp_refresh[0] = DEFAULT_MAX_LSP_GEN_INTERVAL; /* 900 */
371 area->lsp_refresh[1] = DEFAULT_MAX_LSP_GEN_INTERVAL; /* 900 */
372 area->lsp_gen_interval[0] = DEFAULT_MIN_LSP_GEN_INTERVAL;
373 area->lsp_gen_interval[1] = DEFAULT_MIN_LSP_GEN_INTERVAL;
374 area->min_spf_interval[0] = MINIMUM_SPF_INTERVAL;
375 area->min_spf_interval[1] = MINIMUM_SPF_INTERVAL;
376 area->dynhostname = 1;
377 area->oldmetric = 0;
378 area->newmetric = 1;
379 area->lsp_frag_threshold = 90;
380 area->lsp_mtu = DEFAULT_LSP_MTU;
381 area->lfa_load_sharing[0] = true;
382 area->lfa_load_sharing[1] = true;
383 area->attached_bit_send = true;
384 area->attached_bit_rcv_ignore = false;
385 #endif /* ifndef FABRICD */
386 area->lfa_priority_limit[0] = SPF_PREFIX_PRIO_LOW;
387 area->lfa_priority_limit[1] = SPF_PREFIX_PRIO_LOW;
388 isis_lfa_tiebreakers_init(area, ISIS_LEVEL1);
389 isis_lfa_tiebreakers_init(area, ISIS_LEVEL2);
390
391 area_mt_init(area);
392
393 area->area_tag = strdup(area_tag);
394
395 if (fabricd)
396 area->fabricd = fabricd_new(area);
397
398 area->lsp_refresh_arg[0].area = area;
399 area->lsp_refresh_arg[0].level = IS_LEVEL_1;
400 area->lsp_refresh_arg[1].area = area;
401 area->lsp_refresh_arg[1].level = IS_LEVEL_2;
402
403 area->bfd_signalled_down = false;
404 area->bfd_force_spf_refresh = false;
405
406 QOBJ_REG(area, isis_area);
407
408 if (vrf) {
409 FOR_ALL_INTERFACES (vrf, ifp) {
410 if (ifp->ifindex == IFINDEX_INTERNAL)
411 continue;
412
413 circuit = ifp->info;
414 if (circuit && strmatch(circuit->tag, area->area_tag))
415 isis_area_add_circuit(area, circuit);
416 }
417 }
418
419 return area;
420 }
421
422 struct isis_area *isis_area_lookup_by_vrf(const char *area_tag,
423 const char *vrf_name)
424 {
425 struct isis_area *area;
426 struct listnode *node;
427 struct isis *isis = NULL;
428
429 isis = isis_lookup_by_vrfname(vrf_name);
430 if (isis == NULL)
431 return NULL;
432
433 for (ALL_LIST_ELEMENTS_RO(isis->area_list, node, area))
434 if (strcmp(area->area_tag, area_tag) == 0)
435 return area;
436
437 return NULL;
438 }
439
440 struct isis_area *isis_area_lookup(const char *area_tag, vrf_id_t vrf_id)
441 {
442 struct isis_area *area;
443 struct listnode *node;
444 struct isis *isis;
445
446 isis = isis_lookup_by_vrfid(vrf_id);
447 if (isis == NULL)
448 return NULL;
449
450 for (ALL_LIST_ELEMENTS_RO(isis->area_list, node, area))
451 if ((area->area_tag == NULL && area_tag == NULL)
452 || (area->area_tag && area_tag
453 && strcmp(area->area_tag, area_tag) == 0))
454 return area;
455
456 return NULL;
457 }
458
459 int isis_area_get(struct vty *vty, const char *area_tag)
460 {
461 struct isis_area *area;
462
463 area = isis_area_lookup(area_tag, VRF_DEFAULT);
464
465 if (area) {
466 VTY_PUSH_CONTEXT(ROUTER_NODE, area);
467 return CMD_SUCCESS;
468 }
469
470 area = isis_area_create(area_tag, VRF_DEFAULT_NAME);
471
472 if (IS_DEBUG_EVENTS)
473 zlog_debug("New IS-IS area instance %s", area->area_tag);
474
475 VTY_PUSH_CONTEXT(ROUTER_NODE, area);
476
477 return CMD_SUCCESS;
478 }
479
480 void isis_area_destroy(struct isis_area *area)
481 {
482 struct listnode *node, *nnode;
483 struct isis_circuit *circuit;
484 struct area_addr *addr;
485
486 QOBJ_UNREG(area);
487
488 if (fabricd)
489 fabricd_finish(area->fabricd);
490
491 /* Disable MPLS if necessary before flooding LSP */
492 if (IS_MPLS_TE(area->mta))
493 area->mta->status = disable;
494
495 if (area->circuit_list) {
496 for (ALL_LIST_ELEMENTS(area->circuit_list, node, nnode,
497 circuit))
498 isis_area_del_circuit(area, circuit);
499
500 list_delete(&area->circuit_list);
501 }
502 list_delete(&area->adjacency_list);
503
504 lsp_db_fini(&area->lspdb[0]);
505 lsp_db_fini(&area->lspdb[1]);
506
507 /* invalidate and verify to delete all routes from zebra */
508 isis_area_invalidate_routes(area, area->is_type);
509 isis_area_verify_routes(area);
510
511 isis_sr_area_term(area);
512
513 spftree_area_del(area);
514
515 if (area->spf_timer[0])
516 isis_spf_timer_free(THREAD_ARG(area->spf_timer[0]));
517 thread_cancel(&area->spf_timer[0]);
518 if (area->spf_timer[1])
519 isis_spf_timer_free(THREAD_ARG(area->spf_timer[1]));
520 thread_cancel(&area->spf_timer[1]);
521
522 spf_backoff_free(area->spf_delay_ietf[0]);
523 spf_backoff_free(area->spf_delay_ietf[1]);
524
525 if (!CHECK_FLAG(im->options, F_ISIS_UNIT_TEST))
526 isis_redist_area_finish(area);
527
528 for (ALL_LIST_ELEMENTS(area->area_addrs, node, nnode, addr)) {
529 list_delete_node(area->area_addrs, node);
530 XFREE(MTYPE_ISIS_AREA_ADDR, addr);
531 }
532 area->area_addrs = NULL;
533
534 for (int i = SPF_PREFIX_PRIO_CRITICAL; i <= SPF_PREFIX_PRIO_MEDIUM;
535 i++) {
536 struct spf_prefix_priority_acl *ppa;
537
538 ppa = &area->spf_prefix_priorities[i];
539 XFREE(MTYPE_ISIS_ACL_NAME, ppa->name);
540 }
541 isis_lfa_tiebreakers_clear(area, ISIS_LEVEL1);
542 isis_lfa_tiebreakers_clear(area, ISIS_LEVEL2);
543
544 thread_cancel(&area->t_tick);
545 thread_cancel(&area->t_lsp_refresh[0]);
546 thread_cancel(&area->t_lsp_refresh[1]);
547 thread_cancel(&area->t_rlfa_rib_update);
548
549 thread_cancel_event(master, area);
550
551 listnode_delete(area->isis->area_list, area);
552
553 free(area->area_tag);
554
555 area_mt_finish(area);
556
557 if (listcount(area->isis->area_list) == 0) {
558 isis_finish(area->isis);
559 }
560
561 XFREE(MTYPE_ISIS_AREA, area);
562
563 }
564
565 /* This is hook function for vrf create called as part of vrf_init */
566 static int isis_vrf_new(struct vrf *vrf)
567 {
568 if (IS_DEBUG_EVENTS)
569 zlog_debug("%s: VRF Created: %s(%u)", __func__, vrf->name,
570 vrf->vrf_id);
571
572 return 0;
573 }
574
575 /* This is hook function for vrf delete call as part of vrf_init */
576 static int isis_vrf_delete(struct vrf *vrf)
577 {
578 if (IS_DEBUG_EVENTS)
579 zlog_debug("%s: VRF Deletion: %s(%u)", __func__, vrf->name,
580 vrf->vrf_id);
581
582 return 0;
583 }
584
585 static void isis_set_redist_vrf_bitmaps(struct isis *isis, bool set)
586 {
587 struct listnode *node;
588 struct isis_area *area;
589 int type;
590 int level;
591 int protocol;
592
593 char do_subscribe[REDIST_PROTOCOL_COUNT][ZEBRA_ROUTE_MAX + 1];
594
595 memset(do_subscribe, 0, sizeof(do_subscribe));
596
597 for (ALL_LIST_ELEMENTS_RO(isis->area_list, node, area))
598 for (protocol = 0; protocol < REDIST_PROTOCOL_COUNT; protocol++)
599 for (type = 0; type < ZEBRA_ROUTE_MAX + 1; type++)
600 for (level = 0; level < ISIS_LEVELS; level++)
601 if (area->redist_settings[protocol]
602 [type][level]
603 .redist
604 == 1)
605 do_subscribe[protocol][type] =
606 1;
607
608 for (protocol = 0; protocol < REDIST_PROTOCOL_COUNT; protocol++)
609 for (type = 0; type < ZEBRA_ROUTE_MAX + 1; type++) {
610 /* This field is actually controlling transmission of
611 * the IS-IS
612 * routes to Zebra and has nothing to do with
613 * redistribution,
614 * so skip it. */
615 if (type == PROTO_TYPE)
616 continue;
617
618 if (!do_subscribe[protocol][type])
619 continue;
620
621 afi_t afi = afi_for_redist_protocol(protocol);
622
623 if (type == DEFAULT_ROUTE) {
624 if (set)
625 vrf_bitmap_set(
626 zclient->default_information
627 [afi],
628 isis->vrf_id);
629 else
630 vrf_bitmap_unset(
631 zclient->default_information
632 [afi],
633 isis->vrf_id);
634 } else {
635 if (set)
636 vrf_bitmap_set(
637 zclient->redist[afi][type],
638 isis->vrf_id);
639 else
640 vrf_bitmap_unset(
641 zclient->redist[afi][type],
642 isis->vrf_id);
643 }
644 }
645 }
646
647 static int isis_vrf_enable(struct vrf *vrf)
648 {
649 struct isis *isis;
650 vrf_id_t old_vrf_id;
651
652 if (IS_DEBUG_EVENTS)
653 zlog_debug("%s: VRF %s id %u enabled", __func__, vrf->name,
654 vrf->vrf_id);
655
656 isis = isis_lookup_by_vrfname(vrf->name);
657 if (isis && isis->vrf_id != vrf->vrf_id) {
658 old_vrf_id = isis->vrf_id;
659 /* We have instance configured, link to VRF and make it "up". */
660 isis_vrf_link(isis, vrf);
661 if (IS_DEBUG_EVENTS)
662 zlog_debug(
663 "%s: isis linked to vrf %s vrf_id %u (old id %u)",
664 __func__, vrf->name, isis->vrf_id, old_vrf_id);
665 /* start zebra redist to us for new vrf */
666 isis_set_redist_vrf_bitmaps(isis, true);
667
668 isis_zebra_vrf_register(isis);
669 }
670
671 return 0;
672 }
673
674 static int isis_vrf_disable(struct vrf *vrf)
675 {
676 struct isis *isis;
677 vrf_id_t old_vrf_id = VRF_UNKNOWN;
678
679 if (vrf->vrf_id == VRF_DEFAULT)
680 return 0;
681
682 if (IS_DEBUG_EVENTS)
683 zlog_debug("%s: VRF %s id %d disabled.", __func__, vrf->name,
684 vrf->vrf_id);
685 isis = isis_lookup_by_vrfname(vrf->name);
686 if (isis) {
687 old_vrf_id = isis->vrf_id;
688
689 isis_zebra_vrf_deregister(isis);
690
691 isis_set_redist_vrf_bitmaps(isis, false);
692
693 /* We have instance configured, unlink
694 * from VRF and make it "down".
695 */
696 isis_vrf_unlink(isis, vrf);
697 if (IS_DEBUG_EVENTS)
698 zlog_debug("%s: isis old_vrf_id %d unlinked", __func__,
699 old_vrf_id);
700 }
701
702 return 0;
703 }
704
705 void isis_vrf_init(void)
706 {
707 vrf_init(isis_vrf_new, isis_vrf_enable, isis_vrf_disable,
708 isis_vrf_delete);
709
710 vrf_cmd_init(NULL);
711 }
712
713 void isis_terminate()
714 {
715 struct isis *isis;
716 struct listnode *node, *nnode;
717
718 bfd_protocol_integration_set_shutdown(true);
719
720 if (listcount(im->isis) == 0)
721 return;
722
723 for (ALL_LIST_ELEMENTS(im->isis, node, nnode, isis))
724 isis_finish(isis);
725 }
726
727 void isis_filter_update(struct access_list *access)
728 {
729 struct isis *isis;
730 struct isis_area *area;
731 struct listnode *node, *anode;
732
733 for (ALL_LIST_ELEMENTS_RO(im->isis, node, isis)) {
734 for (ALL_LIST_ELEMENTS_RO(isis->area_list, anode, area)) {
735 for (int i = SPF_PREFIX_PRIO_CRITICAL;
736 i <= SPF_PREFIX_PRIO_MEDIUM; i++) {
737 struct spf_prefix_priority_acl *ppa;
738
739 ppa = &area->spf_prefix_priorities[i];
740 ppa->list_v4 =
741 access_list_lookup(AFI_IP, ppa->name);
742 ppa->list_v6 =
743 access_list_lookup(AFI_IP6, ppa->name);
744 }
745 lsp_regenerate_schedule(area, area->is_type, 0);
746 }
747 }
748 }
749
750 void isis_prefix_list_update(struct prefix_list *plist)
751 {
752 struct isis *isis;
753 struct isis_area *area;
754 struct listnode *node, *anode;
755
756 for (ALL_LIST_ELEMENTS_RO(im->isis, node, isis)) {
757 for (ALL_LIST_ELEMENTS_RO(isis->area_list, anode, area)) {
758 for (int level = ISIS_LEVEL1; level <= ISIS_LEVELS;
759 level++) {
760 const char *plist_name =
761 prefix_list_name(plist);
762
763 if (!area->rlfa_plist_name[level - 1])
764 continue;
765
766 if (!strmatch(area->rlfa_plist_name[level - 1],
767 plist_name))
768 continue;
769
770 area->rlfa_plist[level - 1] =
771 prefix_list_lookup(AFI_IP, plist_name);
772 lsp_regenerate_schedule(area, area->is_type, 0);
773 }
774 }
775 }
776 }
777
778 #ifdef FABRICD
779 static void area_set_mt_enabled(struct isis_area *area, uint16_t mtid,
780 bool enabled)
781 {
782 struct isis_area_mt_setting *setting;
783
784 setting = area_get_mt_setting(area, mtid);
785 if (setting->enabled != enabled) {
786 setting->enabled = enabled;
787 lsp_regenerate_schedule(area, IS_LEVEL_1 | IS_LEVEL_2, 0);
788 }
789 }
790
791 static void area_set_mt_overload(struct isis_area *area, uint16_t mtid,
792 bool overload)
793 {
794 struct isis_area_mt_setting *setting;
795
796 setting = area_get_mt_setting(area, mtid);
797 if (setting->overload != overload) {
798 setting->overload = overload;
799 if (setting->enabled)
800 lsp_regenerate_schedule(area, IS_LEVEL_1 | IS_LEVEL_2,
801 0);
802 }
803 }
804 #endif /* ifdef FABRICD */
805
806 int area_net_title(struct vty *vty, const char *net_title)
807 {
808 VTY_DECLVAR_CONTEXT(isis_area, area);
809 struct area_addr *addr;
810 struct area_addr *addrp;
811 struct listnode *node;
812
813 uint8_t buff[255];
814
815 /* We check that we are not over the maximal number of addresses */
816 if (listcount(area->area_addrs) >= area->isis->max_area_addrs) {
817 vty_out(vty,
818 "Maximum of area addresses (%d) already reached \n",
819 area->isis->max_area_addrs);
820 return CMD_ERR_NOTHING_TODO;
821 }
822
823 addr = XMALLOC(MTYPE_ISIS_AREA_ADDR, sizeof(struct area_addr));
824 addr->addr_len = dotformat2buff(buff, net_title);
825 memcpy(addr->area_addr, buff, addr->addr_len);
826 #ifdef EXTREME_DEBUG
827 zlog_debug("added area address %s for area %s (address length %d)",
828 net_title, area->area_tag, addr->addr_len);
829 #endif /* EXTREME_DEBUG */
830 if (addr->addr_len < 8 || addr->addr_len > 20) {
831 vty_out(vty,
832 "area address must be at least 8..20 octets long (%d)\n",
833 addr->addr_len);
834 XFREE(MTYPE_ISIS_AREA_ADDR, addr);
835 return CMD_WARNING_CONFIG_FAILED;
836 }
837
838 if (addr->area_addr[addr->addr_len - 1] != 0) {
839 vty_out(vty,
840 "nsel byte (last byte) in area address must be 0\n");
841 XFREE(MTYPE_ISIS_AREA_ADDR, addr);
842 return CMD_WARNING_CONFIG_FAILED;
843 }
844
845 if (area->isis->sysid_set == 0) {
846 /*
847 * First area address - get the SystemID for this router
848 */
849 memcpy(area->isis->sysid, GETSYSID(addr), ISIS_SYS_ID_LEN);
850 area->isis->sysid_set = 1;
851 if (IS_DEBUG_EVENTS)
852 zlog_debug("Router has SystemID %s",
853 sysid_print(area->isis->sysid));
854 } else {
855 /*
856 * Check that the SystemID portions match
857 */
858 if (memcmp(area->isis->sysid, GETSYSID(addr),
859 ISIS_SYS_ID_LEN)) {
860 vty_out(vty,
861 "System ID must not change when defining additional area addresses\n");
862 XFREE(MTYPE_ISIS_AREA_ADDR, addr);
863 return CMD_WARNING_CONFIG_FAILED;
864 }
865
866 /* now we see that we don't already have this address */
867 for (ALL_LIST_ELEMENTS_RO(area->area_addrs, node, addrp)) {
868 if ((addrp->addr_len + ISIS_SYS_ID_LEN + ISIS_NSEL_LEN)
869 != (addr->addr_len))
870 continue;
871 if (!memcmp(addrp->area_addr, addr->area_addr,
872 addr->addr_len)) {
873 XFREE(MTYPE_ISIS_AREA_ADDR, addr);
874 return CMD_SUCCESS; /* silent fail */
875 }
876 }
877 }
878
879 /*
880 * Forget the systemID part of the address
881 */
882 addr->addr_len -= (ISIS_SYS_ID_LEN + ISIS_NSEL_LEN);
883 listnode_add(area->area_addrs, addr);
884
885 /* only now we can safely generate our LSPs for this area */
886 if (listcount(area->area_addrs) > 0) {
887 if (area->is_type & IS_LEVEL_1)
888 lsp_generate(area, IS_LEVEL_1);
889 if (area->is_type & IS_LEVEL_2)
890 lsp_generate(area, IS_LEVEL_2);
891 }
892
893 return CMD_SUCCESS;
894 }
895
896 int area_clear_net_title(struct vty *vty, const char *net_title)
897 {
898 VTY_DECLVAR_CONTEXT(isis_area, area);
899 struct area_addr addr, *addrp = NULL;
900 struct listnode *node;
901 uint8_t buff[255];
902
903 addr.addr_len = dotformat2buff(buff, net_title);
904 if (addr.addr_len < 8 || addr.addr_len > 20) {
905 vty_out(vty,
906 "Unsupported area address length %d, should be 8...20 \n",
907 addr.addr_len);
908 return CMD_WARNING_CONFIG_FAILED;
909 }
910
911 memcpy(addr.area_addr, buff, (int)addr.addr_len);
912
913 for (ALL_LIST_ELEMENTS_RO(area->area_addrs, node, addrp))
914 if ((addrp->addr_len + ISIS_SYS_ID_LEN + 1) == addr.addr_len
915 && !memcmp(addrp->area_addr, addr.area_addr, addr.addr_len))
916 break;
917
918 if (!addrp) {
919 vty_out(vty, "No area address %s for area %s \n", net_title,
920 area->area_tag);
921 return CMD_ERR_NO_MATCH;
922 }
923
924 listnode_delete(area->area_addrs, addrp);
925 XFREE(MTYPE_ISIS_AREA_ADDR, addrp);
926
927 /*
928 * Last area address - reset the SystemID for this router
929 */
930 if (listcount(area->area_addrs) == 0) {
931 memset(area->isis->sysid, 0, ISIS_SYS_ID_LEN);
932 area->isis->sysid_set = 0;
933 if (IS_DEBUG_EVENTS)
934 zlog_debug("Router has no SystemID");
935 }
936
937 return CMD_SUCCESS;
938 }
939
940 /*
941 * 'show isis interface' command
942 */
943 int show_isis_interface_common(struct vty *vty, struct json_object *json,
944 const char *ifname, char detail,
945 const char *vrf_name, bool all_vrf)
946 {
947 if (json) {
948 return show_isis_interface_common_json(json, ifname, detail,
949 vrf_name, all_vrf);
950 } else {
951 return show_isis_interface_common_vty(vty, ifname, detail,
952 vrf_name, all_vrf);
953 }
954 }
955
956 int show_isis_interface_common_json(struct json_object *json,
957 const char *ifname, char detail,
958 const char *vrf_name, bool all_vrf)
959 {
960 struct listnode *anode, *cnode, *inode;
961 struct isis_area *area;
962 struct isis_circuit *circuit;
963 struct isis *isis;
964 struct json_object *areas_json, *area_json;
965 struct json_object *circuits_json, *circuit_json;
966 if (!im) {
967 // IS-IS Routing Process not enabled
968 json_object_string_add(json, "is-is-routing-process-enabled",
969 "no");
970 return CMD_SUCCESS;
971 }
972 if (vrf_name) {
973 if (all_vrf) {
974 for (ALL_LIST_ELEMENTS_RO(im->isis, inode, isis)) {
975 areas_json = json_object_new_array();
976 json_object_object_add(json, "areas",
977 areas_json);
978 for (ALL_LIST_ELEMENTS_RO(isis->area_list,
979 anode, area)) {
980 area_json = json_object_new_object();
981 json_object_string_add(
982 area_json, "area",
983 area->area_tag ? area->area_tag
984 : "null");
985 circuits_json = json_object_new_array();
986 json_object_object_add(area_json,
987 "circuits",
988 circuits_json);
989 for (ALL_LIST_ELEMENTS_RO(
990 area->circuit_list, cnode,
991 circuit)) {
992 circuit_json =
993 json_object_new_object();
994 json_object_int_add(
995 circuit_json, "circuit",
996 circuit->circuit_id);
997 if (!ifname)
998 isis_circuit_print_json(
999 circuit,
1000 circuit_json,
1001 detail);
1002 else if (strcmp(circuit->interface->name, ifname) == 0)
1003 isis_circuit_print_json(
1004 circuit,
1005 circuit_json,
1006 detail);
1007 json_object_array_add(
1008 circuits_json,
1009 circuit_json);
1010 }
1011 json_object_array_add(areas_json,
1012 area_json);
1013 }
1014 }
1015 return CMD_SUCCESS;
1016 }
1017 isis = isis_lookup_by_vrfname(vrf_name);
1018 if (isis != NULL) {
1019 areas_json = json_object_new_array();
1020 json_object_object_add(json, "areas", areas_json);
1021 for (ALL_LIST_ELEMENTS_RO(isis->area_list, anode,
1022 area)) {
1023 area_json = json_object_new_object();
1024 json_object_string_add(area_json, "area",
1025 area->area_tag
1026 ? area->area_tag
1027 : "null");
1028
1029 circuits_json = json_object_new_array();
1030 json_object_object_add(area_json, "circuits",
1031 circuits_json);
1032 for (ALL_LIST_ELEMENTS_RO(area->circuit_list,
1033 cnode, circuit)) {
1034 circuit_json = json_object_new_object();
1035 json_object_int_add(
1036 circuit_json, "circuit",
1037 circuit->circuit_id);
1038 if (!ifname)
1039 isis_circuit_print_json(
1040 circuit, circuit_json,
1041 detail);
1042 else if (
1043 strcmp(circuit->interface->name,
1044 ifname) == 0)
1045 isis_circuit_print_json(
1046 circuit, circuit_json,
1047 detail);
1048 json_object_array_add(circuits_json,
1049 circuit_json);
1050 }
1051 json_object_array_add(areas_json, area_json);
1052 }
1053 }
1054 }
1055 return CMD_SUCCESS;
1056 }
1057
1058 int show_isis_interface_common_vty(struct vty *vty, const char *ifname,
1059 char detail, const char *vrf_name,
1060 bool all_vrf)
1061 {
1062 struct listnode *anode, *cnode, *inode;
1063 struct isis_area *area;
1064 struct isis_circuit *circuit;
1065 struct isis *isis;
1066
1067 if (!im) {
1068 vty_out(vty, "IS-IS Routing Process not enabled\n");
1069 return CMD_SUCCESS;
1070 }
1071 if (vrf_name) {
1072 if (all_vrf) {
1073 for (ALL_LIST_ELEMENTS_RO(im->isis, inode, isis)) {
1074 for (ALL_LIST_ELEMENTS_RO(isis->area_list,
1075 anode, area)) {
1076 vty_out(vty, "Area %s:\n",
1077 area->area_tag);
1078
1079 if (detail == ISIS_UI_LEVEL_BRIEF)
1080 vty_out(vty,
1081 " Interface CircId State Type Level\n");
1082
1083 for (ALL_LIST_ELEMENTS_RO(
1084 area->circuit_list, cnode,
1085 circuit))
1086 if (!ifname)
1087 isis_circuit_print_vty(
1088 circuit, vty,
1089 detail);
1090 else if (strcmp(circuit->interface->name, ifname) == 0)
1091 isis_circuit_print_vty(
1092 circuit, vty,
1093 detail);
1094 }
1095 }
1096 return CMD_SUCCESS;
1097 }
1098 isis = isis_lookup_by_vrfname(vrf_name);
1099 if (isis != NULL) {
1100 for (ALL_LIST_ELEMENTS_RO(isis->area_list, anode,
1101 area)) {
1102 vty_out(vty, "Area %s:\n", area->area_tag);
1103
1104 if (detail == ISIS_UI_LEVEL_BRIEF)
1105 vty_out(vty,
1106 " Interface CircId State Type Level\n");
1107
1108 for (ALL_LIST_ELEMENTS_RO(area->circuit_list,
1109 cnode, circuit))
1110 if (!ifname)
1111 isis_circuit_print_vty(
1112 circuit, vty, detail);
1113 else if (
1114 strcmp(circuit->interface->name,
1115 ifname) == 0)
1116 isis_circuit_print_vty(
1117 circuit, vty, detail);
1118 }
1119 }
1120 }
1121
1122 return CMD_SUCCESS;
1123 }
1124
1125 DEFUN(show_isis_interface,
1126 show_isis_interface_cmd,
1127 "show " PROTO_NAME " [vrf <NAME|all>] interface [json]",
1128 SHOW_STR
1129 PROTO_HELP
1130 VRF_CMD_HELP_STR
1131 "All VRFs\n"
1132 "json output\n"
1133 "IS-IS interface\n")
1134 {
1135 int res = CMD_SUCCESS;
1136 const char *vrf_name = VRF_DEFAULT_NAME;
1137 bool all_vrf = false;
1138 int idx_vrf = 0;
1139 bool uj = use_json(argc, argv);
1140 json_object *json = NULL;
1141
1142 ISIS_FIND_VRF_ARGS(argv, argc, idx_vrf, vrf_name, all_vrf);
1143 if (uj)
1144 json = json_object_new_object();
1145 res = show_isis_interface_common(vty, json, NULL, ISIS_UI_LEVEL_BRIEF,
1146 vrf_name, all_vrf);
1147 if (uj)
1148 vty_json(vty, json);
1149 return res;
1150 }
1151
1152 DEFUN(show_isis_interface_detail,
1153 show_isis_interface_detail_cmd,
1154 "show " PROTO_NAME " [vrf <NAME|all>] interface detail [json]",
1155 SHOW_STR
1156 PROTO_HELP
1157 VRF_CMD_HELP_STR
1158 "All VRFs\n"
1159 "IS-IS interface\n"
1160 "show detailed information\n"
1161 "json output\n")
1162 {
1163 int res = CMD_SUCCESS;
1164 const char *vrf_name = VRF_DEFAULT_NAME;
1165 bool all_vrf = false;
1166 int idx_vrf = 0;
1167 bool uj = use_json(argc, argv);
1168 json_object *json = NULL;
1169
1170 ISIS_FIND_VRF_ARGS(argv, argc, idx_vrf, vrf_name, all_vrf);
1171 if (uj)
1172 json = json_object_new_object();
1173 res = show_isis_interface_common(vty, json, NULL, ISIS_UI_LEVEL_DETAIL,
1174 vrf_name, all_vrf);
1175 if (uj)
1176 vty_json(vty, json);
1177 return res;
1178 }
1179
1180 DEFUN(show_isis_interface_arg,
1181 show_isis_interface_arg_cmd,
1182 "show " PROTO_NAME " [vrf <NAME|all>] interface WORD [json]",
1183 SHOW_STR
1184 PROTO_HELP
1185 VRF_CMD_HELP_STR
1186 "All VRFs\n"
1187 "IS-IS interface\n"
1188 "IS-IS interface name\n"
1189 "json output\n")
1190 {
1191 int res = CMD_SUCCESS;
1192 int idx_word = 0;
1193 const char *vrf_name = VRF_DEFAULT_NAME;
1194 bool all_vrf = false;
1195 int idx_vrf = 0;
1196 bool uj = use_json(argc, argv);
1197 json_object *json = NULL;
1198
1199 ISIS_FIND_VRF_ARGS(argv, argc, idx_vrf, vrf_name, all_vrf);
1200 if (uj)
1201 json = json_object_new_object();
1202
1203 char *ifname = argv_find(argv, argc, "WORD", &idx_word)
1204 ? argv[idx_word]->arg
1205 : NULL;
1206 res = show_isis_interface_common(
1207 vty, json, ifname, ISIS_UI_LEVEL_DETAIL, vrf_name, all_vrf);
1208 if (uj)
1209 vty_json(vty, json);
1210 return res;
1211 }
1212
1213 static int id_to_sysid(struct isis *isis, const char *id, uint8_t *sysid)
1214 {
1215 struct isis_dynhn *dynhn;
1216
1217 memset(sysid, 0, ISIS_SYS_ID_LEN);
1218 if (id) {
1219 if (sysid2buff(sysid, id) == 0) {
1220 dynhn = dynhn_find_by_name(isis, id);
1221 if (dynhn == NULL)
1222 return -1;
1223 memcpy(sysid, dynhn->id, ISIS_SYS_ID_LEN);
1224 }
1225 }
1226
1227 return 0;
1228 }
1229
1230 static void isis_neighbor_common_json(struct json_object *json, const char *id,
1231 char detail, struct isis *isis,
1232 uint8_t *sysid)
1233 {
1234 struct listnode *anode, *cnode, *node;
1235 struct isis_area *area;
1236 struct isis_circuit *circuit;
1237 struct list *adjdb;
1238 struct isis_adjacency *adj;
1239 struct json_object *areas_json, *area_json;
1240 struct json_object *circuits_json, *circuit_json;
1241 int i;
1242
1243 areas_json = json_object_new_array();
1244 json_object_object_add(json, "areas", areas_json);
1245 for (ALL_LIST_ELEMENTS_RO(isis->area_list, anode, area)) {
1246 area_json = json_object_new_object();
1247 json_object_string_add(area_json, "area",
1248 area->area_tag ? area->area_tag
1249 : "null");
1250 circuits_json = json_object_new_array();
1251 json_object_object_add(area_json, "circuits", circuits_json);
1252 for (ALL_LIST_ELEMENTS_RO(area->circuit_list, cnode, circuit)) {
1253 circuit_json = json_object_new_object();
1254 json_object_int_add(circuit_json, "circuit",
1255 circuit->circuit_id);
1256 if (circuit->circ_type == CIRCUIT_T_BROADCAST) {
1257 for (i = 0; i < 2; i++) {
1258 adjdb = circuit->u.bc.adjdb[i];
1259 if (adjdb && adjdb->count) {
1260 for (ALL_LIST_ELEMENTS_RO(
1261 adjdb, node, adj))
1262 if (!id ||
1263 !memcmp(adj->sysid,
1264 sysid,
1265 ISIS_SYS_ID_LEN))
1266 isis_adj_print_json(
1267 adj,
1268 circuit_json,
1269 detail);
1270 }
1271 }
1272 } else if (circuit->circ_type == CIRCUIT_T_P2P &&
1273 circuit->u.p2p.neighbor) {
1274 adj = circuit->u.p2p.neighbor;
1275 if (!id ||
1276 !memcmp(adj->sysid, sysid, ISIS_SYS_ID_LEN))
1277 isis_adj_print_json(adj, circuit_json,
1278 detail);
1279 }
1280 json_object_array_add(circuits_json, circuit_json);
1281 }
1282 json_object_array_add(areas_json, area_json);
1283 }
1284 }
1285
1286 static void isis_neighbor_common_vty(struct vty *vty, const char *id,
1287 char detail, struct isis *isis,
1288 uint8_t *sysid)
1289 {
1290 struct listnode *anode, *cnode, *node;
1291 struct isis_area *area;
1292 struct isis_circuit *circuit;
1293 struct list *adjdb;
1294 struct isis_adjacency *adj;
1295 int i;
1296
1297 for (ALL_LIST_ELEMENTS_RO(isis->area_list, anode, area)) {
1298 vty_out(vty, "Area %s:\n", area->area_tag);
1299
1300 if (detail == ISIS_UI_LEVEL_BRIEF)
1301 vty_out(vty,
1302 " System Id Interface L State Holdtime SNPA\n");
1303
1304 for (ALL_LIST_ELEMENTS_RO(area->circuit_list, cnode, circuit)) {
1305 if (circuit->circ_type == CIRCUIT_T_BROADCAST) {
1306 for (i = 0; i < 2; i++) {
1307 adjdb = circuit->u.bc.adjdb[i];
1308 if (adjdb && adjdb->count) {
1309 for (ALL_LIST_ELEMENTS_RO(
1310 adjdb, node, adj))
1311 if (!id ||
1312 !memcmp(adj->sysid,
1313 sysid,
1314 ISIS_SYS_ID_LEN))
1315 isis_adj_print_vty(
1316 adj,
1317 vty,
1318 detail);
1319 }
1320 }
1321 } else if (circuit->circ_type == CIRCUIT_T_P2P &&
1322 circuit->u.p2p.neighbor) {
1323 adj = circuit->u.p2p.neighbor;
1324 if (!id ||
1325 !memcmp(adj->sysid, sysid, ISIS_SYS_ID_LEN))
1326 isis_adj_print_vty(adj, vty, detail);
1327 }
1328 }
1329 }
1330 }
1331
1332 static void isis_neighbor_common(struct vty *vty, struct json_object *json,
1333 const char *id, char detail, struct isis *isis,
1334 uint8_t *sysid)
1335 {
1336 if (json) {
1337 isis_neighbor_common_json(json, id, detail,isis,sysid);
1338 } else {
1339 isis_neighbor_common_vty(vty, id, detail,isis,sysid);
1340 }
1341 }
1342
1343 /*
1344 * 'show isis neighbor' command
1345 */
1346
1347 int show_isis_neighbor_common(struct vty *vty, struct json_object *json,
1348 const char *id, char detail, const char *vrf_name,
1349 bool all_vrf)
1350 {
1351 struct listnode *node;
1352 uint8_t sysid[ISIS_SYS_ID_LEN];
1353 struct isis *isis;
1354
1355 if (!im) {
1356 vty_out(vty, "IS-IS Routing Process not enabled\n");
1357 return CMD_SUCCESS;
1358 }
1359
1360 if (vrf_name) {
1361 if (all_vrf) {
1362 for (ALL_LIST_ELEMENTS_RO(im->isis, node, isis)) {
1363 if (id_to_sysid(isis, id, sysid)) {
1364 vty_out(vty, "Invalid system id %s\n",
1365 id);
1366 return CMD_SUCCESS;
1367 }
1368 isis_neighbor_common(vty, json, id, detail,
1369 isis, sysid);
1370 }
1371 return CMD_SUCCESS;
1372 }
1373 isis = isis_lookup_by_vrfname(vrf_name);
1374 if (isis != NULL) {
1375 if (id_to_sysid(isis, id, sysid)) {
1376 vty_out(vty, "Invalid system id %s\n", id);
1377 return CMD_SUCCESS;
1378 }
1379 isis_neighbor_common(vty, json, id, detail, isis,
1380 sysid);
1381 }
1382 }
1383
1384 return CMD_SUCCESS;
1385 }
1386
1387 static void isis_neighbor_common_clear(struct vty *vty, const char *id,
1388 uint8_t *sysid, struct isis *isis)
1389 {
1390 struct listnode *anode, *cnode, *node, *nnode;
1391 struct isis_area *area;
1392 struct isis_circuit *circuit;
1393 struct list *adjdb;
1394 struct isis_adjacency *adj;
1395 int i;
1396
1397 for (ALL_LIST_ELEMENTS_RO(isis->area_list, anode, area)) {
1398 for (ALL_LIST_ELEMENTS_RO(area->circuit_list, cnode, circuit)) {
1399 if (circuit->circ_type == CIRCUIT_T_BROADCAST) {
1400 for (i = 0; i < 2; i++) {
1401 adjdb = circuit->u.bc.adjdb[i];
1402 if (adjdb && adjdb->count) {
1403 for (ALL_LIST_ELEMENTS(
1404 adjdb, node, nnode,
1405 adj))
1406 if (!id
1407 || !memcmp(
1408 adj->sysid,
1409 sysid,
1410 ISIS_SYS_ID_LEN))
1411 isis_adj_state_change(
1412 &adj,
1413 ISIS_ADJ_DOWN,
1414 "clear user request");
1415 }
1416 }
1417 } else if (circuit->circ_type == CIRCUIT_T_P2P
1418 && circuit->u.p2p.neighbor) {
1419 adj = circuit->u.p2p.neighbor;
1420 if (!id
1421 || !memcmp(adj->sysid, sysid,
1422 ISIS_SYS_ID_LEN))
1423 isis_adj_state_change(
1424 &adj, ISIS_ADJ_DOWN,
1425 "clear user request");
1426 }
1427 }
1428 }
1429 }
1430 /*
1431 * 'clear isis neighbor' command
1432 */
1433 int clear_isis_neighbor_common(struct vty *vty, const char *id, const char *vrf_name,
1434 bool all_vrf)
1435 {
1436 struct listnode *node;
1437 uint8_t sysid[ISIS_SYS_ID_LEN];
1438 struct isis *isis;
1439
1440 if (!im) {
1441 vty_out(vty, "IS-IS Routing Process not enabled\n");
1442 return CMD_SUCCESS;
1443 }
1444
1445 if (vrf_name) {
1446 if (all_vrf) {
1447 for (ALL_LIST_ELEMENTS_RO(im->isis, node, isis)) {
1448 if (id_to_sysid(isis, id, sysid)) {
1449 vty_out(vty, "Invalid system id %s\n",
1450 id);
1451 return CMD_SUCCESS;
1452 }
1453 isis_neighbor_common_clear(vty, id, sysid,
1454 isis);
1455 }
1456 return CMD_SUCCESS;
1457 }
1458 isis = isis_lookup_by_vrfname(vrf_name);
1459 if (isis != NULL) {
1460 if (id_to_sysid(isis, id, sysid)) {
1461 vty_out(vty, "Invalid system id %s\n", id);
1462 return CMD_SUCCESS;
1463 }
1464 isis_neighbor_common_clear(vty, id, sysid, isis);
1465 }
1466 }
1467
1468 return CMD_SUCCESS;
1469 }
1470
1471 DEFUN(show_isis_neighbor,
1472 show_isis_neighbor_cmd,
1473 "show " PROTO_NAME " [vrf <NAME|all>] neighbor [json]",
1474 SHOW_STR
1475 PROTO_HELP
1476 VRF_CMD_HELP_STR
1477 "All vrfs\n"
1478 "IS-IS neighbor adjacencies\n"
1479 "json output\n")
1480 {
1481 int res = CMD_SUCCESS;
1482 const char *vrf_name = VRF_DEFAULT_NAME;
1483 bool all_vrf = false;
1484 int idx_vrf = 0;
1485 bool uj = use_json(argc, argv);
1486 json_object *json = NULL;
1487
1488 ISIS_FIND_VRF_ARGS(argv, argc, idx_vrf, vrf_name, all_vrf);
1489 if (uj)
1490 json = json_object_new_object();
1491 res = show_isis_neighbor_common(vty, json, NULL, ISIS_UI_LEVEL_BRIEF,
1492 vrf_name, all_vrf);
1493 if (uj)
1494 vty_json(vty, json);
1495 return res;
1496 }
1497
1498 DEFUN(show_isis_neighbor_detail,
1499 show_isis_neighbor_detail_cmd,
1500 "show " PROTO_NAME " [vrf <NAME|all>] neighbor detail [json]",
1501 SHOW_STR
1502 PROTO_HELP
1503 VRF_CMD_HELP_STR
1504 "all vrfs\n"
1505 "IS-IS neighbor adjacencies\n"
1506 "show detailed information\n"
1507 "json output\n")
1508 {
1509 int res = CMD_SUCCESS;
1510 const char *vrf_name = VRF_DEFAULT_NAME;
1511 bool all_vrf = false;
1512 int idx_vrf = 0;
1513 bool uj = use_json(argc, argv);
1514 json_object *json = NULL;
1515
1516 ISIS_FIND_VRF_ARGS(argv, argc, idx_vrf, vrf_name, all_vrf);
1517 if (uj)
1518 json = json_object_new_object();
1519
1520 res = show_isis_neighbor_common(vty, json, NULL, ISIS_UI_LEVEL_DETAIL,
1521 vrf_name, all_vrf);
1522 if (uj)
1523 vty_json(vty, json);
1524 return res;
1525 }
1526
1527 DEFUN(show_isis_neighbor_arg,
1528 show_isis_neighbor_arg_cmd,
1529 "show " PROTO_NAME " [vrf <NAME|all>] neighbor WORD [json]",
1530 SHOW_STR
1531 PROTO_HELP
1532 VRF_CMD_HELP_STR
1533 "All vrfs\n"
1534 "IS-IS neighbor adjacencies\n"
1535 "System id\n"
1536 "json output\n")
1537 {
1538 int res = CMD_SUCCESS;
1539 int idx_word = 0;
1540 const char *vrf_name = VRF_DEFAULT_NAME;
1541 bool all_vrf = false;
1542 int idx_vrf = 0;
1543 bool uj = use_json(argc, argv);
1544 json_object *json = NULL;
1545
1546 ISIS_FIND_VRF_ARGS(argv, argc, idx_vrf, vrf_name, all_vrf);
1547 if (uj)
1548 json = json_object_new_object();
1549 char *id = argv_find(argv, argc, "WORD", &idx_word)
1550 ? argv[idx_word]->arg
1551 : NULL;
1552
1553 res = show_isis_neighbor_common(vty, json, id, ISIS_UI_LEVEL_DETAIL,
1554 vrf_name, all_vrf);
1555 if (uj)
1556 vty_json(vty, json);
1557 return res;
1558 }
1559
1560 DEFUN(clear_isis_neighbor,
1561 clear_isis_neighbor_cmd,
1562 "clear " PROTO_NAME " [vrf <NAME|all>] neighbor",
1563 CLEAR_STR
1564 PROTO_HELP
1565 VRF_CMD_HELP_STR
1566 "All vrfs\n"
1567 "IS-IS neighbor adjacencies\n")
1568 {
1569 const char *vrf_name = VRF_DEFAULT_NAME;
1570 bool all_vrf = false;
1571 int idx_vrf = 0;
1572
1573 ISIS_FIND_VRF_ARGS(argv, argc, idx_vrf, vrf_name, all_vrf);
1574 return clear_isis_neighbor_common(vty, NULL, vrf_name, all_vrf);
1575 }
1576
1577 DEFUN(clear_isis_neighbor_arg,
1578 clear_isis_neighbor_arg_cmd,
1579 "clear " PROTO_NAME " [vrf <NAME|all>] neighbor WORD",
1580 CLEAR_STR
1581 PROTO_HELP
1582 VRF_CMD_HELP_STR
1583 "All vrfs\n"
1584 "IS-IS neighbor adjacencies\n"
1585 "System id\n")
1586 {
1587 int idx_word = 0;
1588 const char *vrf_name = VRF_DEFAULT_NAME;
1589 bool all_vrf = false;
1590 int idx_vrf = 0;
1591
1592 char *id = argv_find(argv, argc, "WORD", &idx_word)
1593 ? argv[idx_word]->arg
1594 : NULL;
1595 ISIS_FIND_VRF_ARGS(argv, argc, idx_vrf, vrf_name, all_vrf);
1596 return clear_isis_neighbor_common(vty, id, vrf_name, all_vrf);
1597 }
1598
1599 /*
1600 * 'isis debug', 'show debugging'
1601 */
1602 void print_debug(struct vty *vty, int flags, int onoff)
1603 {
1604 const char *onoffs = onoff ? "on" : "off";
1605
1606 if (flags & DEBUG_ADJ_PACKETS)
1607 vty_out(vty,
1608 "IS-IS Adjacency related packets debugging is %s\n",
1609 onoffs);
1610 if (flags & DEBUG_TX_QUEUE)
1611 vty_out(vty, "IS-IS TX queue debugging is %s\n",
1612 onoffs);
1613 if (flags & DEBUG_SNP_PACKETS)
1614 vty_out(vty, "IS-IS CSNP/PSNP packets debugging is %s\n",
1615 onoffs);
1616 if (flags & DEBUG_SPF_EVENTS)
1617 vty_out(vty, "IS-IS SPF events debugging is %s\n", onoffs);
1618 if (flags & DEBUG_SR)
1619 vty_out(vty, "IS-IS Segment Routing events debugging is %s\n",
1620 onoffs);
1621 if (flags & DEBUG_TE)
1622 vty_out(vty,
1623 "IS-IS Traffic Engineering events debugging is %s\n",
1624 onoffs);
1625 if (flags & DEBUG_LFA)
1626 vty_out(vty, "IS-IS LFA events debugging is %s\n", onoffs);
1627 if (flags & DEBUG_UPDATE_PACKETS)
1628 vty_out(vty, "IS-IS Update related packet debugging is %s\n",
1629 onoffs);
1630 if (flags & DEBUG_RTE_EVENTS)
1631 vty_out(vty, "IS-IS Route related debugging is %s\n", onoffs);
1632 if (flags & DEBUG_EVENTS)
1633 vty_out(vty, "IS-IS Event debugging is %s\n", onoffs);
1634 if (flags & DEBUG_PACKET_DUMP)
1635 vty_out(vty, "IS-IS Packet dump debugging is %s\n", onoffs);
1636 if (flags & DEBUG_LSP_GEN)
1637 vty_out(vty, "IS-IS LSP generation debugging is %s\n", onoffs);
1638 if (flags & DEBUG_LSP_SCHED)
1639 vty_out(vty, "IS-IS LSP scheduling debugging is %s\n", onoffs);
1640 if (flags & DEBUG_FLOODING)
1641 vty_out(vty, "IS-IS Flooding debugging is %s\n", onoffs);
1642 if (flags & DEBUG_BFD)
1643 vty_out(vty, "IS-IS BFD debugging is %s\n", onoffs);
1644 if (flags & DEBUG_LDP_SYNC)
1645 vty_out(vty, "IS-IS ldp-sync debugging is %s\n", onoffs);
1646 }
1647
1648 DEFUN_NOSH (show_debugging,
1649 show_debugging_isis_cmd,
1650 "show debugging [" PROTO_NAME "]",
1651 SHOW_STR
1652 "State of each debugging option\n"
1653 PROTO_HELP)
1654 {
1655 vty_out(vty, PROTO_NAME " debugging status:\n");
1656
1657 if (IS_DEBUG_ADJ_PACKETS)
1658 print_debug(vty, DEBUG_ADJ_PACKETS, 1);
1659 if (IS_DEBUG_TX_QUEUE)
1660 print_debug(vty, DEBUG_TX_QUEUE, 1);
1661 if (IS_DEBUG_SNP_PACKETS)
1662 print_debug(vty, DEBUG_SNP_PACKETS, 1);
1663 if (IS_DEBUG_SPF_EVENTS)
1664 print_debug(vty, DEBUG_SPF_EVENTS, 1);
1665 if (IS_DEBUG_SR)
1666 print_debug(vty, DEBUG_SR, 1);
1667 if (IS_DEBUG_TE)
1668 print_debug(vty, DEBUG_TE, 1);
1669 if (IS_DEBUG_UPDATE_PACKETS)
1670 print_debug(vty, DEBUG_UPDATE_PACKETS, 1);
1671 if (IS_DEBUG_RTE_EVENTS)
1672 print_debug(vty, DEBUG_RTE_EVENTS, 1);
1673 if (IS_DEBUG_EVENTS)
1674 print_debug(vty, DEBUG_EVENTS, 1);
1675 if (IS_DEBUG_PACKET_DUMP)
1676 print_debug(vty, DEBUG_PACKET_DUMP, 1);
1677 if (IS_DEBUG_LSP_GEN)
1678 print_debug(vty, DEBUG_LSP_GEN, 1);
1679 if (IS_DEBUG_LSP_SCHED)
1680 print_debug(vty, DEBUG_LSP_SCHED, 1);
1681 if (IS_DEBUG_FLOODING)
1682 print_debug(vty, DEBUG_FLOODING, 1);
1683 if (IS_DEBUG_BFD)
1684 print_debug(vty, DEBUG_BFD, 1);
1685 if (IS_DEBUG_LDP_SYNC)
1686 print_debug(vty, DEBUG_LDP_SYNC, 1);
1687 if (IS_DEBUG_LFA)
1688 print_debug(vty, DEBUG_LFA, 1);
1689
1690 return CMD_SUCCESS;
1691 }
1692
1693 static int config_write_debug(struct vty *vty);
1694 /* Debug node. */
1695 static struct cmd_node debug_node = {
1696 .name = "debug",
1697 .node = DEBUG_NODE,
1698 .prompt = "",
1699 .config_write = config_write_debug,
1700 };
1701
1702 static int config_write_debug(struct vty *vty)
1703 {
1704 int write = 0;
1705
1706 if (IS_DEBUG_ADJ_PACKETS) {
1707 vty_out(vty, "debug " PROTO_NAME " adj-packets\n");
1708 write++;
1709 }
1710 if (IS_DEBUG_TX_QUEUE) {
1711 vty_out(vty, "debug " PROTO_NAME " tx-queue\n");
1712 write++;
1713 }
1714 if (IS_DEBUG_SNP_PACKETS) {
1715 vty_out(vty, "debug " PROTO_NAME " snp-packets\n");
1716 write++;
1717 }
1718 if (IS_DEBUG_SPF_EVENTS) {
1719 vty_out(vty, "debug " PROTO_NAME " spf-events\n");
1720 write++;
1721 }
1722 if (IS_DEBUG_SR) {
1723 vty_out(vty, "debug " PROTO_NAME " sr-events\n");
1724 write++;
1725 }
1726 if (IS_DEBUG_TE) {
1727 vty_out(vty, "debug " PROTO_NAME " te-events\n");
1728 write++;
1729 }
1730 if (IS_DEBUG_LFA) {
1731 vty_out(vty, "debug " PROTO_NAME " lfa\n");
1732 write++;
1733 }
1734 if (IS_DEBUG_UPDATE_PACKETS) {
1735 vty_out(vty, "debug " PROTO_NAME " update-packets\n");
1736 write++;
1737 }
1738 if (IS_DEBUG_RTE_EVENTS) {
1739 vty_out(vty, "debug " PROTO_NAME " route-events\n");
1740 write++;
1741 }
1742 if (IS_DEBUG_EVENTS) {
1743 vty_out(vty, "debug " PROTO_NAME " events\n");
1744 write++;
1745 }
1746 if (IS_DEBUG_PACKET_DUMP) {
1747 vty_out(vty, "debug " PROTO_NAME " packet-dump\n");
1748 write++;
1749 }
1750 if (IS_DEBUG_LSP_GEN) {
1751 vty_out(vty, "debug " PROTO_NAME " lsp-gen\n");
1752 write++;
1753 }
1754 if (IS_DEBUG_LSP_SCHED) {
1755 vty_out(vty, "debug " PROTO_NAME " lsp-sched\n");
1756 write++;
1757 }
1758 if (IS_DEBUG_FLOODING) {
1759 vty_out(vty, "debug " PROTO_NAME " flooding\n");
1760 write++;
1761 }
1762 if (IS_DEBUG_BFD) {
1763 vty_out(vty, "debug " PROTO_NAME " bfd\n");
1764 write++;
1765 }
1766 if (IS_DEBUG_LDP_SYNC) {
1767 vty_out(vty, "debug " PROTO_NAME " ldp-sync\n");
1768 write++;
1769 }
1770 write += spf_backoff_write_config(vty);
1771
1772 return write;
1773 }
1774
1775 DEFUN (debug_isis_adj,
1776 debug_isis_adj_cmd,
1777 "debug " PROTO_NAME " adj-packets",
1778 DEBUG_STR
1779 PROTO_HELP
1780 "IS-IS Adjacency related packets\n")
1781 {
1782 debug_adj_pkt |= DEBUG_ADJ_PACKETS;
1783 print_debug(vty, DEBUG_ADJ_PACKETS, 1);
1784
1785 return CMD_SUCCESS;
1786 }
1787
1788 DEFUN (no_debug_isis_adj,
1789 no_debug_isis_adj_cmd,
1790 "no debug " PROTO_NAME " adj-packets",
1791 NO_STR
1792 UNDEBUG_STR
1793 PROTO_HELP
1794 "IS-IS Adjacency related packets\n")
1795 {
1796 debug_adj_pkt &= ~DEBUG_ADJ_PACKETS;
1797 print_debug(vty, DEBUG_ADJ_PACKETS, 0);
1798
1799 return CMD_SUCCESS;
1800 }
1801
1802 DEFUN (debug_isis_tx_queue,
1803 debug_isis_tx_queue_cmd,
1804 "debug " PROTO_NAME " tx-queue",
1805 DEBUG_STR
1806 PROTO_HELP
1807 "IS-IS TX queues\n")
1808 {
1809 debug_tx_queue |= DEBUG_TX_QUEUE;
1810 print_debug(vty, DEBUG_TX_QUEUE, 1);
1811
1812 return CMD_SUCCESS;
1813 }
1814
1815 DEFUN (no_debug_isis_tx_queue,
1816 no_debug_isis_tx_queue_cmd,
1817 "no debug " PROTO_NAME " tx-queue",
1818 NO_STR
1819 UNDEBUG_STR
1820 PROTO_HELP
1821 "IS-IS TX queues\n")
1822 {
1823 debug_tx_queue &= ~DEBUG_TX_QUEUE;
1824 print_debug(vty, DEBUG_TX_QUEUE, 0);
1825
1826 return CMD_SUCCESS;
1827 }
1828
1829 DEFUN (debug_isis_flooding,
1830 debug_isis_flooding_cmd,
1831 "debug " PROTO_NAME " flooding",
1832 DEBUG_STR
1833 PROTO_HELP
1834 "Flooding algorithm\n")
1835 {
1836 debug_flooding |= DEBUG_FLOODING;
1837 print_debug(vty, DEBUG_FLOODING, 1);
1838
1839 return CMD_SUCCESS;
1840 }
1841
1842 DEFUN (no_debug_isis_flooding,
1843 no_debug_isis_flooding_cmd,
1844 "no debug " PROTO_NAME " flooding",
1845 NO_STR
1846 UNDEBUG_STR
1847 PROTO_HELP
1848 "Flooding algorithm\n")
1849 {
1850 debug_flooding &= ~DEBUG_FLOODING;
1851 print_debug(vty, DEBUG_FLOODING, 0);
1852
1853 return CMD_SUCCESS;
1854 }
1855
1856 DEFUN (debug_isis_snp,
1857 debug_isis_snp_cmd,
1858 "debug " PROTO_NAME " snp-packets",
1859 DEBUG_STR
1860 PROTO_HELP
1861 "IS-IS CSNP/PSNP packets\n")
1862 {
1863 debug_snp_pkt |= DEBUG_SNP_PACKETS;
1864 print_debug(vty, DEBUG_SNP_PACKETS, 1);
1865
1866 return CMD_SUCCESS;
1867 }
1868
1869 DEFUN (no_debug_isis_snp,
1870 no_debug_isis_snp_cmd,
1871 "no debug " PROTO_NAME " snp-packets",
1872 NO_STR
1873 UNDEBUG_STR
1874 PROTO_HELP
1875 "IS-IS CSNP/PSNP packets\n")
1876 {
1877 debug_snp_pkt &= ~DEBUG_SNP_PACKETS;
1878 print_debug(vty, DEBUG_SNP_PACKETS, 0);
1879
1880 return CMD_SUCCESS;
1881 }
1882
1883 DEFUN (debug_isis_upd,
1884 debug_isis_upd_cmd,
1885 "debug " PROTO_NAME " update-packets",
1886 DEBUG_STR
1887 PROTO_HELP
1888 "IS-IS Update related packets\n")
1889 {
1890 debug_update_pkt |= DEBUG_UPDATE_PACKETS;
1891 print_debug(vty, DEBUG_UPDATE_PACKETS, 1);
1892
1893 return CMD_SUCCESS;
1894 }
1895
1896 DEFUN (no_debug_isis_upd,
1897 no_debug_isis_upd_cmd,
1898 "no debug " PROTO_NAME " update-packets",
1899 NO_STR
1900 UNDEBUG_STR
1901 PROTO_HELP
1902 "IS-IS Update related packets\n")
1903 {
1904 debug_update_pkt &= ~DEBUG_UPDATE_PACKETS;
1905 print_debug(vty, DEBUG_UPDATE_PACKETS, 0);
1906
1907 return CMD_SUCCESS;
1908 }
1909
1910 DEFUN (debug_isis_spfevents,
1911 debug_isis_spfevents_cmd,
1912 "debug " PROTO_NAME " spf-events",
1913 DEBUG_STR
1914 PROTO_HELP
1915 "IS-IS Shortest Path First Events\n")
1916 {
1917 debug_spf_events |= DEBUG_SPF_EVENTS;
1918 print_debug(vty, DEBUG_SPF_EVENTS, 1);
1919
1920 return CMD_SUCCESS;
1921 }
1922
1923 DEFUN (no_debug_isis_spfevents,
1924 no_debug_isis_spfevents_cmd,
1925 "no debug " PROTO_NAME " spf-events",
1926 NO_STR
1927 UNDEBUG_STR
1928 PROTO_HELP
1929 "IS-IS Shortest Path First Events\n")
1930 {
1931 debug_spf_events &= ~DEBUG_SPF_EVENTS;
1932 print_debug(vty, DEBUG_SPF_EVENTS, 0);
1933
1934 return CMD_SUCCESS;
1935 }
1936
1937 DEFUN (debug_isis_srevents,
1938 debug_isis_srevents_cmd,
1939 "debug " PROTO_NAME " sr-events",
1940 DEBUG_STR
1941 PROTO_HELP
1942 "IS-IS Segment Routing Events\n")
1943 {
1944 debug_sr |= DEBUG_SR;
1945 print_debug(vty, DEBUG_SR, 1);
1946
1947 return CMD_SUCCESS;
1948 }
1949
1950 DEFUN (no_debug_isis_srevents,
1951 no_debug_isis_srevents_cmd,
1952 "no debug " PROTO_NAME " sr-events",
1953 NO_STR
1954 UNDEBUG_STR
1955 PROTO_HELP
1956 "IS-IS Segment Routing Events\n")
1957 {
1958 debug_sr &= ~DEBUG_SR;
1959 print_debug(vty, DEBUG_SR, 0);
1960
1961 return CMD_SUCCESS;
1962 }
1963
1964 DEFUN (debug_isis_teevents,
1965 debug_isis_teevents_cmd,
1966 "debug " PROTO_NAME " te-events",
1967 DEBUG_STR
1968 PROTO_HELP
1969 "IS-IS Traffic Engineering Events\n")
1970 {
1971 debug_te |= DEBUG_TE;
1972 print_debug(vty, DEBUG_TE, 1);
1973
1974 return CMD_SUCCESS;
1975 }
1976
1977 DEFUN (no_debug_isis_teevents,
1978 no_debug_isis_teevents_cmd,
1979 "no debug " PROTO_NAME " te-events",
1980 NO_STR
1981 UNDEBUG_STR
1982 PROTO_HELP
1983 "IS-IS Traffic Engineering Events\n")
1984 {
1985 debug_te &= ~DEBUG_TE;
1986 print_debug(vty, DEBUG_TE, 0);
1987
1988 return CMD_SUCCESS;
1989 }
1990
1991 DEFUN (debug_isis_lfa,
1992 debug_isis_lfa_cmd,
1993 "debug " PROTO_NAME " lfa",
1994 DEBUG_STR
1995 PROTO_HELP
1996 "IS-IS LFA Events\n")
1997 {
1998 debug_lfa |= DEBUG_LFA;
1999 print_debug(vty, DEBUG_LFA, 1);
2000
2001 return CMD_SUCCESS;
2002 }
2003
2004 DEFUN (no_debug_isis_lfa,
2005 no_debug_isis_lfa_cmd,
2006 "no debug " PROTO_NAME " lfa",
2007 NO_STR
2008 UNDEBUG_STR
2009 PROTO_HELP
2010 "IS-IS LFA Events\n")
2011 {
2012 debug_lfa &= ~DEBUG_LFA;
2013 print_debug(vty, DEBUG_LFA, 0);
2014
2015 return CMD_SUCCESS;
2016 }
2017
2018 DEFUN (debug_isis_rtevents,
2019 debug_isis_rtevents_cmd,
2020 "debug " PROTO_NAME " route-events",
2021 DEBUG_STR
2022 PROTO_HELP
2023 "IS-IS Route related events\n")
2024 {
2025 debug_rte_events |= DEBUG_RTE_EVENTS;
2026 print_debug(vty, DEBUG_RTE_EVENTS, 1);
2027
2028 return CMD_SUCCESS;
2029 }
2030
2031 DEFUN (no_debug_isis_rtevents,
2032 no_debug_isis_rtevents_cmd,
2033 "no debug " PROTO_NAME " route-events",
2034 NO_STR
2035 UNDEBUG_STR
2036 PROTO_HELP
2037 "IS-IS Route related events\n")
2038 {
2039 debug_rte_events &= ~DEBUG_RTE_EVENTS;
2040 print_debug(vty, DEBUG_RTE_EVENTS, 0);
2041
2042 return CMD_SUCCESS;
2043 }
2044
2045 DEFUN (debug_isis_events,
2046 debug_isis_events_cmd,
2047 "debug " PROTO_NAME " events",
2048 DEBUG_STR
2049 PROTO_HELP
2050 "IS-IS Events\n")
2051 {
2052 debug_events |= DEBUG_EVENTS;
2053 print_debug(vty, DEBUG_EVENTS, 1);
2054
2055 return CMD_SUCCESS;
2056 }
2057
2058 DEFUN (no_debug_isis_events,
2059 no_debug_isis_events_cmd,
2060 "no debug " PROTO_NAME " events",
2061 NO_STR
2062 UNDEBUG_STR
2063 PROTO_HELP
2064 "IS-IS Events\n")
2065 {
2066 debug_events &= ~DEBUG_EVENTS;
2067 print_debug(vty, DEBUG_EVENTS, 0);
2068
2069 return CMD_SUCCESS;
2070 }
2071
2072 DEFUN (debug_isis_packet_dump,
2073 debug_isis_packet_dump_cmd,
2074 "debug " PROTO_NAME " packet-dump",
2075 DEBUG_STR
2076 PROTO_HELP
2077 "IS-IS packet dump\n")
2078 {
2079 debug_pkt_dump |= DEBUG_PACKET_DUMP;
2080 print_debug(vty, DEBUG_PACKET_DUMP, 1);
2081
2082 return CMD_SUCCESS;
2083 }
2084
2085 DEFUN (no_debug_isis_packet_dump,
2086 no_debug_isis_packet_dump_cmd,
2087 "no debug " PROTO_NAME " packet-dump",
2088 NO_STR
2089 UNDEBUG_STR
2090 PROTO_HELP
2091 "IS-IS packet dump\n")
2092 {
2093 debug_pkt_dump &= ~DEBUG_PACKET_DUMP;
2094 print_debug(vty, DEBUG_PACKET_DUMP, 0);
2095
2096 return CMD_SUCCESS;
2097 }
2098
2099 DEFUN (debug_isis_lsp_gen,
2100 debug_isis_lsp_gen_cmd,
2101 "debug " PROTO_NAME " lsp-gen",
2102 DEBUG_STR
2103 PROTO_HELP
2104 "IS-IS generation of own LSPs\n")
2105 {
2106 debug_lsp_gen |= DEBUG_LSP_GEN;
2107 print_debug(vty, DEBUG_LSP_GEN, 1);
2108
2109 return CMD_SUCCESS;
2110 }
2111
2112 DEFUN (no_debug_isis_lsp_gen,
2113 no_debug_isis_lsp_gen_cmd,
2114 "no debug " PROTO_NAME " lsp-gen",
2115 NO_STR
2116 UNDEBUG_STR
2117 PROTO_HELP
2118 "IS-IS generation of own LSPs\n")
2119 {
2120 debug_lsp_gen &= ~DEBUG_LSP_GEN;
2121 print_debug(vty, DEBUG_LSP_GEN, 0);
2122
2123 return CMD_SUCCESS;
2124 }
2125
2126 DEFUN (debug_isis_lsp_sched,
2127 debug_isis_lsp_sched_cmd,
2128 "debug " PROTO_NAME " lsp-sched",
2129 DEBUG_STR
2130 PROTO_HELP
2131 "IS-IS scheduling of LSP generation\n")
2132 {
2133 debug_lsp_sched |= DEBUG_LSP_SCHED;
2134 print_debug(vty, DEBUG_LSP_SCHED, 1);
2135
2136 return CMD_SUCCESS;
2137 }
2138
2139 DEFUN (no_debug_isis_lsp_sched,
2140 no_debug_isis_lsp_sched_cmd,
2141 "no debug " PROTO_NAME " lsp-sched",
2142 NO_STR
2143 UNDEBUG_STR
2144 PROTO_HELP
2145 "IS-IS scheduling of LSP generation\n")
2146 {
2147 debug_lsp_sched &= ~DEBUG_LSP_SCHED;
2148 print_debug(vty, DEBUG_LSP_SCHED, 0);
2149
2150 return CMD_SUCCESS;
2151 }
2152
2153 DEFUN (debug_isis_bfd,
2154 debug_isis_bfd_cmd,
2155 "debug " PROTO_NAME " bfd",
2156 DEBUG_STR
2157 PROTO_HELP
2158 PROTO_NAME " interaction with BFD\n")
2159 {
2160 debug_bfd |= DEBUG_BFD;
2161 bfd_protocol_integration_set_debug(true);
2162 print_debug(vty, DEBUG_BFD, 1);
2163
2164 return CMD_SUCCESS;
2165 }
2166
2167 DEFUN (no_debug_isis_bfd,
2168 no_debug_isis_bfd_cmd,
2169 "no debug " PROTO_NAME " bfd",
2170 NO_STR
2171 UNDEBUG_STR
2172 PROTO_HELP
2173 PROTO_NAME " interaction with BFD\n")
2174 {
2175 debug_bfd &= ~DEBUG_BFD;
2176 bfd_protocol_integration_set_debug(false);
2177 print_debug(vty, DEBUG_BFD, 0);
2178
2179 return CMD_SUCCESS;
2180 }
2181
2182 DEFUN(debug_isis_ldp_sync, debug_isis_ldp_sync_cmd,
2183 "debug " PROTO_NAME " ldp-sync",
2184 DEBUG_STR PROTO_HELP PROTO_NAME " interaction with LDP-Sync\n")
2185 {
2186 debug_ldp_sync |= DEBUG_LDP_SYNC;
2187 print_debug(vty, DEBUG_LDP_SYNC, 1);
2188
2189 return CMD_SUCCESS;
2190 }
2191
2192 DEFUN(no_debug_isis_ldp_sync, no_debug_isis_ldp_sync_cmd,
2193 "no debug " PROTO_NAME " ldp-sync",
2194 NO_STR UNDEBUG_STR PROTO_HELP PROTO_NAME " interaction with LDP-Sync\n")
2195 {
2196 debug_ldp_sync &= ~DEBUG_LDP_SYNC;
2197 print_debug(vty, DEBUG_LDP_SYNC, 0);
2198
2199 return CMD_SUCCESS;
2200 }
2201
2202 DEFUN (show_hostname,
2203 show_hostname_cmd,
2204 "show " PROTO_NAME " [vrf <NAME|all>] hostname",
2205 SHOW_STR PROTO_HELP VRF_CMD_HELP_STR
2206 "All VRFs\n"
2207 "IS-IS Dynamic hostname mapping\n")
2208 {
2209 struct listnode *node;
2210 const char *vrf_name = VRF_DEFAULT_NAME;
2211 bool all_vrf = false;
2212 int idx_vrf = 0;
2213 struct isis *isis;
2214
2215 ISIS_FIND_VRF_ARGS(argv, argc, idx_vrf, vrf_name, all_vrf);
2216 if (vrf_name) {
2217 if (all_vrf) {
2218 for (ALL_LIST_ELEMENTS_RO(im->isis, node, isis))
2219 dynhn_print_all(vty, isis);
2220
2221 return CMD_SUCCESS;
2222 }
2223 isis = isis_lookup_by_vrfname(vrf_name);
2224 if (isis != NULL)
2225 dynhn_print_all(vty, isis);
2226 }
2227
2228 return CMD_SUCCESS;
2229 }
2230
2231 static void isis_spf_ietf_common(struct vty *vty, struct isis *isis)
2232 {
2233 struct listnode *node;
2234 struct isis_area *area;
2235 for (ALL_LIST_ELEMENTS_RO(isis->area_list, node, area)) {
2236
2237 vty_out(vty, "vrf : %s\n", isis->name);
2238 vty_out(vty, "Area %s:\n",
2239 area->area_tag ? area->area_tag : "null");
2240
2241 for (int level = ISIS_LEVEL1; level <= ISIS_LEVELS; level++) {
2242 if ((area->is_type & level) == 0)
2243 continue;
2244
2245 vty_out(vty, " Level-%d:\n", level);
2246 vty_out(vty, " SPF delay status: ");
2247 if (area->spf_timer[level - 1]) {
2248 struct timeval remain = thread_timer_remain(
2249 area->spf_timer[level - 1]);
2250 vty_out(vty, "Pending, due in %lld msec\n",
2251 (long long)remain.tv_sec * 1000
2252 + remain.tv_usec / 1000);
2253 } else {
2254 vty_out(vty, "Not scheduled\n");
2255 }
2256
2257 if (area->spf_delay_ietf[level - 1]) {
2258 vty_out(vty,
2259 " Using draft-ietf-rtgwg-backoff-algo-04\n");
2260 spf_backoff_show(
2261 area->spf_delay_ietf[level - 1], vty,
2262 " ");
2263 } else {
2264 vty_out(vty, " Using legacy backoff algo\n");
2265 }
2266 }
2267 }
2268 }
2269
2270 DEFUN(show_isis_spf_ietf, show_isis_spf_ietf_cmd,
2271 "show " PROTO_NAME " [vrf <NAME|all>] spf-delay-ietf",
2272 SHOW_STR PROTO_HELP VRF_CMD_HELP_STR
2273 "All VRFs\n"
2274 "SPF delay IETF information\n")
2275 {
2276 struct listnode *node;
2277 struct isis *isis;
2278 int idx_vrf = 0;
2279 const char *vrf_name = VRF_DEFAULT_NAME;
2280 bool all_vrf = false;
2281
2282 ISIS_FIND_VRF_ARGS(argv, argc, idx_vrf, vrf_name, all_vrf)
2283
2284 if (!im) {
2285 vty_out(vty, "ISIS is not running\n");
2286 return CMD_SUCCESS;
2287 }
2288
2289 if (vrf_name) {
2290 if (all_vrf) {
2291 for (ALL_LIST_ELEMENTS_RO(im->isis, node, isis))
2292 isis_spf_ietf_common(vty, isis);
2293
2294 return CMD_SUCCESS;
2295 }
2296 isis = isis_lookup_by_vrfname(vrf_name);
2297 if (isis != NULL)
2298 isis_spf_ietf_common(vty, isis);
2299 }
2300
2301 return CMD_SUCCESS;
2302 }
2303
2304
2305 static const char *pdu_counter_index_to_name_json(enum pdu_counter_index index)
2306 {
2307 switch (index) {
2308 case L1_LAN_HELLO_INDEX:
2309 return "l1-iih";
2310 case L2_LAN_HELLO_INDEX:
2311 return "l2-iih";
2312 case P2P_HELLO_INDEX:
2313 return "p2p-iih";
2314 case L1_LINK_STATE_INDEX:
2315 return "l1-lsp";
2316 case L2_LINK_STATE_INDEX:
2317 return "l2-lsp";
2318 case FS_LINK_STATE_INDEX:
2319 return "fs-lsp";
2320 case L1_COMPLETE_SEQ_NUM_INDEX:
2321 return "l1-csnp";
2322 case L2_COMPLETE_SEQ_NUM_INDEX:
2323 return "l2-csnp";
2324 case L1_PARTIAL_SEQ_NUM_INDEX:
2325 return "l1-psnp";
2326 case L2_PARTIAL_SEQ_NUM_INDEX:
2327 return "l2-psnp";
2328 default:
2329 return "???????";
2330 }
2331 }
2332
2333 static void common_isis_summary_json(struct json_object *json,
2334 struct isis *isis)
2335 {
2336 int level;
2337 json_object *areas_json, *area_json, *tx_pdu_json, *rx_pdu_json,
2338 *levels_json, *level_json;
2339 struct listnode *node, *node2;
2340 struct isis_area *area;
2341 time_t cur;
2342 char uptime[MONOTIME_STRLEN];
2343 char stier[5];
2344 json_object_string_add(json, "vrf", isis->name);
2345 json_object_int_add(json, "process-id", isis->process_id);
2346 if (isis->sysid_set)
2347 json_object_string_add(json, "system-id",
2348 sysid_print(isis->sysid));
2349
2350 cur = time(NULL);
2351 cur -= isis->uptime;
2352 frrtime_to_interval(cur, uptime, sizeof(uptime));
2353 json_object_string_add(json, "up-time", uptime);
2354 if (isis->area_list)
2355 json_object_int_add(json, "number-areas",
2356 isis->area_list->count);
2357 areas_json = json_object_new_array();
2358 json_object_object_add(json, "areas", areas_json);
2359 for (ALL_LIST_ELEMENTS_RO(isis->area_list, node, area)) {
2360 area_json = json_object_new_object();
2361 json_object_string_add(area_json, "area",
2362 area->area_tag ? area->area_tag
2363 : "null");
2364
2365
2366 if (fabricd) {
2367 uint8_t tier = fabricd_tier(area);
2368 snprintfrr(stier, sizeof(stier), "%s", &tier);
2369 json_object_string_add(area_json, "tier",
2370 tier == ISIS_TIER_UNDEFINED
2371 ? "undefined"
2372 : stier);
2373 }
2374
2375 if (listcount(area->area_addrs) > 0) {
2376 struct area_addr *area_addr;
2377 for (ALL_LIST_ELEMENTS_RO(area->area_addrs, node2,
2378 area_addr)) {
2379 json_object_string_add(
2380 area_json, "net",
2381 isonet_print(area_addr->area_addr,
2382 area_addr->addr_len +
2383 ISIS_SYS_ID_LEN +
2384 1));
2385 }
2386 }
2387
2388 tx_pdu_json = json_object_new_object();
2389 json_object_object_add(area_json, "tx-pdu-type", tx_pdu_json);
2390 for (int i = 0; i < PDU_COUNTER_SIZE; i++) {
2391 if (!area->pdu_tx_counters[i])
2392 continue;
2393 json_object_int_add(tx_pdu_json,
2394 pdu_counter_index_to_name_json(i),
2395 area->pdu_tx_counters[i]);
2396 }
2397 json_object_int_add(tx_pdu_json, "lsp-rxmt",
2398 area->lsp_rxmt_count);
2399
2400 rx_pdu_json = json_object_new_object();
2401 json_object_object_add(area_json, "rx-pdu-type", rx_pdu_json);
2402 for (int i = 0; i < PDU_COUNTER_SIZE; i++) {
2403 if (!area->pdu_rx_counters[i])
2404 continue;
2405 json_object_int_add(rx_pdu_json,
2406 pdu_counter_index_to_name_json(i),
2407 area->pdu_rx_counters[i]);
2408 }
2409
2410 levels_json = json_object_new_array();
2411 json_object_object_add(area_json, "levels", levels_json);
2412 for (level = ISIS_LEVEL1; level <= ISIS_LEVELS; level++) {
2413 if ((area->is_type & level) == 0)
2414 continue;
2415 level_json = json_object_new_object();
2416 json_object_int_add(level_json, "id", level);
2417 json_object_int_add(level_json, "lsp0-regenerated",
2418 area->lsp_gen_count[level - 1]);
2419 json_object_int_add(level_json, "lsp-purged",
2420 area->lsp_purge_count[level - 1]);
2421 if (area->spf_timer[level - 1])
2422 json_object_string_add(level_json, "spf",
2423 "pending");
2424 else
2425 json_object_string_add(level_json, "spf",
2426 "no pending");
2427 json_object_int_add(level_json, "minimum-interval",
2428 area->min_spf_interval[level - 1]);
2429 if (area->spf_delay_ietf[level - 1])
2430 json_object_string_add(
2431 level_json, "ietf-spf-delay-activated",
2432 "not used");
2433 if (area->ip_circuits) {
2434 isis_spf_print_json(
2435 area->spftree[SPFTREE_IPV4][level - 1],
2436 level_json);
2437 }
2438 if (area->ipv6_circuits) {
2439 isis_spf_print_json(
2440 area->spftree[SPFTREE_IPV6][level - 1],
2441 level_json);
2442 }
2443 json_object_array_add(levels_json, level_json);
2444 }
2445 json_object_array_add(areas_json, area_json);
2446 }
2447 }
2448
2449 static void common_isis_summary_vty(struct vty *vty, struct isis *isis)
2450 {
2451 struct listnode *node, *node2;
2452 struct isis_area *area;
2453 int level;
2454
2455 vty_out(vty, "vrf : %s\n", isis->name);
2456 vty_out(vty, "Process Id : %ld\n", isis->process_id);
2457 if (isis->sysid_set)
2458 vty_out(vty, "System Id : %s\n",
2459 sysid_print(isis->sysid));
2460
2461 vty_out(vty, "Up time : ");
2462 vty_out_timestr(vty, isis->uptime);
2463 vty_out(vty, "\n");
2464
2465 if (isis->area_list)
2466 vty_out(vty, "Number of areas : %d\n", isis->area_list->count);
2467
2468 for (ALL_LIST_ELEMENTS_RO(isis->area_list, node, area)) {
2469 vty_out(vty, "Area %s:\n",
2470 area->area_tag ? area->area_tag : "null");
2471
2472 if (fabricd) {
2473 uint8_t tier = fabricd_tier(area);
2474 if (tier == ISIS_TIER_UNDEFINED)
2475 vty_out(vty, " Tier: undefined\n");
2476 else
2477 vty_out(vty, " Tier: %hhu\n", tier);
2478 }
2479
2480 if (listcount(area->area_addrs) > 0) {
2481 struct area_addr *area_addr;
2482 for (ALL_LIST_ELEMENTS_RO(area->area_addrs, node2,
2483 area_addr)) {
2484 vty_out(vty, " Net: %s\n",
2485 isonet_print(area_addr->area_addr,
2486 area_addr->addr_len
2487 + ISIS_SYS_ID_LEN
2488 + 1));
2489 }
2490 }
2491
2492 vty_out(vty, " TX counters per PDU type:\n");
2493 pdu_counter_print(vty, " ", area->pdu_tx_counters);
2494 vty_out(vty, " LSP RXMT: %" PRIu64 "\n",
2495 area->lsp_rxmt_count);
2496 vty_out(vty, " RX counters per PDU type:\n");
2497 pdu_counter_print(vty, " ", area->pdu_rx_counters);
2498
2499 for (level = ISIS_LEVEL1; level <= ISIS_LEVELS; level++) {
2500 if ((area->is_type & level) == 0)
2501 continue;
2502
2503 vty_out(vty, " Level-%d:\n", level);
2504
2505 vty_out(vty, " LSP0 regenerated: %" PRIu64 "\n",
2506 area->lsp_gen_count[level - 1]);
2507
2508 vty_out(vty, " LSPs purged: %" PRIu64 "\n",
2509 area->lsp_purge_count[level - 1]);
2510
2511 if (area->spf_timer[level - 1])
2512 vty_out(vty, " SPF: (pending)\n");
2513 else
2514 vty_out(vty, " SPF:\n");
2515
2516 vty_out(vty, " minimum interval : %d",
2517 area->min_spf_interval[level - 1]);
2518 if (area->spf_delay_ietf[level - 1])
2519 vty_out(vty,
2520 " (not used, IETF SPF delay activated)");
2521 vty_out(vty, "\n");
2522
2523 if (area->ip_circuits) {
2524 vty_out(vty, " IPv4 route computation:\n");
2525 isis_spf_print(
2526 area->spftree[SPFTREE_IPV4][level - 1],
2527 vty);
2528 }
2529
2530 if (area->ipv6_circuits) {
2531 vty_out(vty, " IPv6 route computation:\n");
2532 isis_spf_print(
2533 area->spftree[SPFTREE_IPV6][level - 1],
2534 vty);
2535 }
2536
2537 if (area->ipv6_circuits
2538 && isis_area_ipv6_dstsrc_enabled(area)) {
2539 vty_out(vty,
2540 " IPv6 dst-src route computation:\n");
2541 isis_spf_print(area->spftree[SPFTREE_DSTSRC]
2542 [level - 1],
2543 vty);
2544 }
2545 }
2546 }
2547 }
2548
2549 static void common_isis_summary(struct vty *vty, struct json_object *json,
2550 struct isis *isis)
2551 {
2552 if (json) {
2553 common_isis_summary_json(json, isis);
2554 } else {
2555 common_isis_summary_vty(vty, isis);
2556 }
2557 }
2558
2559 DEFUN(show_isis_summary, show_isis_summary_cmd,
2560 "show " PROTO_NAME " [vrf <NAME|all>] summary [json]",
2561 SHOW_STR PROTO_HELP VRF_CMD_HELP_STR
2562 "All VRFs\n"
2563 "json output\n"
2564 "summary\n")
2565 {
2566 struct listnode *node;
2567 int idx_vrf = 0;
2568 struct isis *isis;
2569 const char *vrf_name = VRF_DEFAULT_NAME;
2570 bool all_vrf = false;
2571 bool uj = use_json(argc, argv);
2572 json_object *json = NULL;
2573
2574 ISIS_FIND_VRF_ARGS(argv, argc, idx_vrf, vrf_name, all_vrf)
2575 if (!im) {
2576 vty_out(vty, PROTO_NAME " is not running\n");
2577 return CMD_SUCCESS;
2578 }
2579 if (uj)
2580 json = json_object_new_object();
2581 if (vrf_name) {
2582 if (all_vrf) {
2583 for (ALL_LIST_ELEMENTS_RO(im->isis, node, isis))
2584 common_isis_summary(vty, json, isis);
2585
2586 return CMD_SUCCESS;
2587 }
2588 isis = isis_lookup_by_vrfname(vrf_name);
2589 if (isis != NULL)
2590 common_isis_summary(vty, json, isis);
2591 }
2592
2593 if (uj)
2594 vty_json(vty, json);
2595
2596 return CMD_SUCCESS;
2597 }
2598
2599 struct isis_lsp *lsp_for_sysid(struct lspdb_head *head, const char *sysid_str,
2600 struct isis *isis)
2601 {
2602 char sysid[255] = {0};
2603 uint8_t number[3] = {0};
2604 const char *pos;
2605 uint8_t lspid[ISIS_SYS_ID_LEN + 2] = {0};
2606 struct isis_dynhn *dynhn;
2607 struct isis_lsp *lsp = NULL;
2608
2609 if (!sysid_str)
2610 return NULL;
2611
2612 /*
2613 * extract fragment and pseudo id from the string sysid_str
2614 * in the forms:
2615 * (a) <systemid/hostname>.<pseudo-id>-<framenent> or
2616 * (b) <systemid/hostname>.<pseudo-id> or
2617 * (c) <systemid/hostname> or
2618 * Where systemid is in the form:
2619 * xxxx.xxxx.xxxx
2620 */
2621 strlcpy(sysid, sysid_str, sizeof(sysid));
2622
2623 if (strlen(sysid_str) > 3) {
2624 pos = sysid_str + strlen(sysid_str) - 3;
2625 if (strncmp(pos, "-", 1) == 0) {
2626 memcpy(number, ++pos, 2);
2627 lspid[ISIS_SYS_ID_LEN + 1] =
2628 (uint8_t)strtol((char *)number, NULL, 16);
2629 pos -= 4;
2630 if (strncmp(pos, ".", 1) != 0)
2631 return NULL;
2632 }
2633 if (strncmp(pos, ".", 1) == 0) {
2634 memcpy(number, ++pos, 2);
2635 lspid[ISIS_SYS_ID_LEN] =
2636 (uint8_t)strtol((char *)number, NULL, 16);
2637 sysid[pos - sysid_str - 1] = '\0';
2638 }
2639 }
2640
2641 /*
2642 * Try to find the lsp-id if the sysid_str
2643 * is in the form
2644 * hostname.<pseudo-id>-<fragment>
2645 */
2646 if (sysid2buff(lspid, sysid)) {
2647 lsp = lsp_search(head, lspid);
2648 } else if ((dynhn = dynhn_find_by_name(isis, sysid))) {
2649 memcpy(lspid, dynhn->id, ISIS_SYS_ID_LEN);
2650 lsp = lsp_search(head, lspid);
2651 } else if (strncmp(cmd_hostname_get(), sysid, 15) == 0) {
2652 memcpy(lspid, isis->sysid, ISIS_SYS_ID_LEN);
2653 lsp = lsp_search(head, lspid);
2654 }
2655
2656 return lsp;
2657 }
2658
2659 void show_isis_database_lspdb_json(struct json_object *json,
2660 struct isis_area *area, int level,
2661 struct lspdb_head *lspdb,
2662 const char *sysid_str, int ui_level)
2663 {
2664 struct isis_lsp *lsp;
2665 int lsp_count;
2666
2667 if (lspdb_count(lspdb) > 0) {
2668 lsp = lsp_for_sysid(lspdb, sysid_str, area->isis);
2669
2670 if (lsp != NULL || sysid_str == NULL) {
2671 json_object_int_add(json, "id", level + 1);
2672 }
2673
2674 if (lsp) {
2675 if (ui_level == ISIS_UI_LEVEL_DETAIL)
2676 lsp_print_detail(lsp, NULL, json,
2677 area->dynhostname, area->isis);
2678 else
2679 lsp_print_json(lsp, json, area->dynhostname,
2680 area->isis);
2681 } else if (sysid_str == NULL) {
2682 lsp_count =
2683 lsp_print_all(NULL, json, lspdb, ui_level,
2684 area->dynhostname, area->isis);
2685
2686 json_object_int_add(json, "count", lsp_count);
2687 }
2688 }
2689 }
2690 void show_isis_database_lspdb_vty(struct vty *vty, struct isis_area *area,
2691 int level, struct lspdb_head *lspdb,
2692 const char *sysid_str, int ui_level)
2693 {
2694 struct isis_lsp *lsp;
2695 int lsp_count;
2696
2697 if (lspdb_count(lspdb) > 0) {
2698 lsp = lsp_for_sysid(lspdb, sysid_str, area->isis);
2699
2700 if (lsp != NULL || sysid_str == NULL) {
2701 vty_out(vty, "IS-IS Level-%d link-state database:\n",
2702 level + 1);
2703
2704 /* print the title in all cases */
2705 vty_out(vty,
2706 "LSP ID PduLen SeqNumber Chksum Holdtime ATT/P/OL\n");
2707 }
2708
2709 if (lsp) {
2710 if (ui_level == ISIS_UI_LEVEL_DETAIL)
2711 lsp_print_detail(lsp, vty, NULL,
2712 area->dynhostname, area->isis);
2713 else
2714 lsp_print_vty(lsp, vty, area->dynhostname,
2715 area->isis);
2716 } else if (sysid_str == NULL) {
2717 lsp_count =
2718 lsp_print_all(vty, NULL, lspdb, ui_level,
2719 area->dynhostname, area->isis);
2720
2721 vty_out(vty, " %u LSPs\n\n", lsp_count);
2722 }
2723 }
2724 }
2725
2726 static void show_isis_database_json(struct json_object *json, const char *sysid_str,
2727 int ui_level, struct isis *isis)
2728 {
2729 struct listnode *node;
2730 struct isis_area *area;
2731 int level;
2732 struct json_object *tag_area_json,*area_json, *lsp_json, *area_arr_json, *arr_json;
2733 uint8_t area_cnt = 0;
2734
2735 if (isis->area_list->count == 0)
2736 return;
2737
2738 area_arr_json = json_object_new_array();
2739 json_object_object_add(json, "areas", area_arr_json);
2740 for (ALL_LIST_ELEMENTS_RO(isis->area_list, node, area)) {
2741 area_json = json_object_new_object();
2742 tag_area_json = json_object_new_object();
2743 json_object_string_add(tag_area_json, "name",
2744 area->area_tag ? area->area_tag
2745 : "null");
2746
2747 arr_json = json_object_new_array();
2748 json_object_object_add(area_json,"area",tag_area_json);
2749 json_object_object_add(area_json,"levels",arr_json);
2750 for (level = 0; level < ISIS_LEVELS; level++) {
2751 lsp_json = json_object_new_object();
2752 show_isis_database_lspdb_json(lsp_json, area, level,
2753 &area->lspdb[level],
2754 sysid_str, ui_level);
2755 json_object_array_add(arr_json, lsp_json);
2756 }
2757 json_object_array_add(area_arr_json, area_json);
2758 area_cnt++;
2759 }
2760 }
2761
2762 static void show_isis_database_vty(struct vty *vty, const char *sysid_str,
2763 int ui_level, struct isis *isis)
2764 {
2765 struct listnode *node;
2766 struct isis_area *area;
2767 int level;
2768
2769 if (isis->area_list->count == 0)
2770 return;
2771
2772 for (ALL_LIST_ELEMENTS_RO(isis->area_list, node, area)) {
2773 vty_out(vty, "Area %s:\n",
2774 area->area_tag ? area->area_tag : "null");
2775
2776 for (level = 0; level < ISIS_LEVELS; level++)
2777 show_isis_database_lspdb_vty(vty, area, level,
2778 &area->lspdb[level], sysid_str,
2779 ui_level);
2780 }
2781 }
2782
2783 static void show_isis_database_common(struct vty *vty, struct json_object *json, const char *sysid_str,
2784 int ui_level, struct isis *isis)
2785 {
2786 if (json) {
2787 show_isis_database_json(json, sysid_str, ui_level, isis);
2788 } else {
2789 show_isis_database_vty(vty, sysid_str, ui_level, isis);
2790 }
2791 }
2792
2793 /*
2794 * This function supports following display options:
2795 * [ show isis database [detail] ]
2796 * [ show isis database <sysid> [detail] ]
2797 * [ show isis database <hostname> [detail] ]
2798 * [ show isis database <sysid>.<pseudo-id> [detail] ]
2799 * [ show isis database <hostname>.<pseudo-id> [detail] ]
2800 * [ show isis database <sysid>.<pseudo-id>-<fragment-number> [detail] ]
2801 * [ show isis database <hostname>.<pseudo-id>-<fragment-number> [detail] ]
2802 * [ show isis database detail <sysid> ]
2803 * [ show isis database detail <hostname> ]
2804 * [ show isis database detail <sysid>.<pseudo-id> ]
2805 * [ show isis database detail <hostname>.<pseudo-id> ]
2806 * [ show isis database detail <sysid>.<pseudo-id>-<fragment-number> ]
2807 * [ show isis database detail <hostname>.<pseudo-id>-<fragment-number> ]
2808 */
2809 static int show_isis_database(struct vty *vty, struct json_object *json, const char *sysid_str,
2810 int ui_level, const char *vrf_name, bool all_vrf)
2811 {
2812 struct listnode *node;
2813 struct isis *isis;
2814
2815 if (vrf_name) {
2816 if (all_vrf) {
2817 for (ALL_LIST_ELEMENTS_RO(im->isis, node, isis))
2818 show_isis_database_common(vty, json, sysid_str,
2819 ui_level, isis);
2820
2821 return CMD_SUCCESS;
2822 }
2823 isis = isis_lookup_by_vrfname(vrf_name);
2824 if (isis)
2825 show_isis_database_common(vty, json, sysid_str,
2826 ui_level, isis);
2827 }
2828
2829 return CMD_SUCCESS;
2830 }
2831
2832 DEFUN(show_database, show_database_cmd,
2833 "show " PROTO_NAME " [vrf <NAME|all>] database [detail] [WORD] [json]",
2834 SHOW_STR PROTO_HELP VRF_CMD_HELP_STR
2835 "All VRFs\n"
2836 "Link state database\n"
2837 "Detailed information\n"
2838 "LSP ID\n"
2839 "json output\n")
2840 {
2841 int res = CMD_SUCCESS;
2842 int idx = 0;
2843 int idx_vrf = 0;
2844 const char *vrf_name = VRF_DEFAULT_NAME;
2845 bool all_vrf = false;
2846 int uilevel = argv_find(argv, argc, "detail", &idx)
2847 ? ISIS_UI_LEVEL_DETAIL
2848 : ISIS_UI_LEVEL_BRIEF;
2849 char *id = argv_find(argv, argc, "WORD", &idx) ? argv[idx]->arg : NULL;
2850 bool uj = use_json(argc, argv);
2851 json_object *json = NULL;
2852
2853 ISIS_FIND_VRF_ARGS(argv, argc, idx_vrf, vrf_name, all_vrf);
2854 if (uj)
2855 json = json_object_new_object();
2856
2857 res = show_isis_database(vty, json, id, uilevel, vrf_name, all_vrf);
2858 if (uj)
2859 vty_json(vty, json);
2860 return res;
2861 }
2862
2863 #ifdef FABRICD
2864 /*
2865 * 'router openfabric' command
2866 */
2867 DEFUN_NOSH (router_openfabric,
2868 router_openfabric_cmd,
2869 "router openfabric WORD",
2870 ROUTER_STR
2871 PROTO_HELP
2872 "ISO Routing area tag\n")
2873 {
2874 int idx_word = 2;
2875 return isis_area_get(vty, argv[idx_word]->arg);
2876 }
2877
2878 /*
2879 *'no router openfabric' command
2880 */
2881 DEFUN (no_router_openfabric,
2882 no_router_openfabric_cmd,
2883 "no router openfabric WORD",
2884 NO_STR
2885 ROUTER_STR
2886 PROTO_HELP
2887 "ISO Routing area tag\n")
2888 {
2889 struct isis_area *area;
2890 const char *area_tag;
2891 int idx_word = 3;
2892
2893 area_tag = argv[idx_word]->arg;
2894 area = isis_area_lookup(area_tag, VRF_DEFAULT);
2895 if (area == NULL) {
2896 zlog_warn("%s: could not find area with area-tag %s",
2897 __func__, area_tag);
2898 return CMD_ERR_NO_MATCH;
2899 }
2900
2901 isis_area_destroy(area);
2902 return CMD_SUCCESS;
2903 }
2904 #endif /* ifdef FABRICD */
2905 #ifdef FABRICD
2906 /*
2907 * 'net' command
2908 */
2909 DEFUN (net,
2910 net_cmd,
2911 "net WORD",
2912 "A Network Entity Title for this process (OSI only)\n"
2913 "XX.XXXX. ... .XXX.XX Network entity title (NET)\n")
2914 {
2915 int idx_word = 1;
2916 return area_net_title(vty, argv[idx_word]->arg);
2917 }
2918
2919 /*
2920 * 'no net' command
2921 */
2922 DEFUN (no_net,
2923 no_net_cmd,
2924 "no net WORD",
2925 NO_STR
2926 "A Network Entity Title for this process (OSI only)\n"
2927 "XX.XXXX. ... .XXX.XX Network entity title (NET)\n")
2928 {
2929 int idx_word = 2;
2930 return area_clear_net_title(vty, argv[idx_word]->arg);
2931 }
2932 #endif /* ifdef FABRICD */
2933 #ifdef FABRICD
2934 DEFUN (isis_topology,
2935 isis_topology_cmd,
2936 "topology " ISIS_MT_NAMES " [overload]",
2937 "Configure IS-IS topologies\n"
2938 ISIS_MT_DESCRIPTIONS
2939 "Set overload bit for topology\n")
2940 {
2941 VTY_DECLVAR_CONTEXT(isis_area, area);
2942
2943 const char *arg = argv[1]->arg;
2944 uint16_t mtid = isis_str2mtid(arg);
2945
2946 if (area->oldmetric) {
2947 vty_out(vty,
2948 "Multi topology IS-IS can only be used with wide metrics\n");
2949 return CMD_WARNING_CONFIG_FAILED;
2950 }
2951
2952 if (mtid == (uint16_t)-1) {
2953 vty_out(vty, "Don't know topology '%s'\n", arg);
2954 return CMD_WARNING_CONFIG_FAILED;
2955 }
2956 if (mtid == ISIS_MT_IPV4_UNICAST) {
2957 vty_out(vty, "Cannot configure IPv4 unicast topology\n");
2958 return CMD_WARNING_CONFIG_FAILED;
2959 }
2960
2961 area_set_mt_enabled(area, mtid, true);
2962 area_set_mt_overload(area, mtid, (argc == 3));
2963 return CMD_SUCCESS;
2964 }
2965
2966 DEFUN (no_isis_topology,
2967 no_isis_topology_cmd,
2968 "no topology " ISIS_MT_NAMES " [overload]",
2969 NO_STR
2970 "Configure IS-IS topologies\n"
2971 ISIS_MT_DESCRIPTIONS
2972 "Set overload bit for topology\n")
2973 {
2974 VTY_DECLVAR_CONTEXT(isis_area, area);
2975
2976 const char *arg = argv[2]->arg;
2977 uint16_t mtid = isis_str2mtid(arg);
2978
2979 if (area->oldmetric) {
2980 vty_out(vty,
2981 "Multi topology IS-IS can only be used with wide metrics\n");
2982 return CMD_WARNING_CONFIG_FAILED;
2983 }
2984
2985 if (mtid == (uint16_t)-1) {
2986 vty_out(vty, "Don't know topology '%s'\n", arg);
2987 return CMD_WARNING_CONFIG_FAILED;
2988 }
2989 if (mtid == ISIS_MT_IPV4_UNICAST) {
2990 vty_out(vty, "Cannot configure IPv4 unicast topology\n");
2991 return CMD_WARNING_CONFIG_FAILED;
2992 }
2993
2994 area_set_mt_enabled(area, mtid, false);
2995 area_set_mt_overload(area, mtid, false);
2996 return CMD_SUCCESS;
2997 }
2998 #endif /* ifdef FABRICD */
2999
3000 void isis_area_lsp_mtu_set(struct isis_area *area, unsigned int lsp_mtu)
3001 {
3002 area->lsp_mtu = lsp_mtu;
3003 lsp_regenerate_schedule(area, IS_LEVEL_1_AND_2, 1);
3004 }
3005
3006 static int isis_area_passwd_set(struct isis_area *area, int level,
3007 uint8_t passwd_type, const char *passwd,
3008 uint8_t snp_auth)
3009 {
3010 struct isis_passwd *dest;
3011 struct isis_passwd modified;
3012 int len;
3013
3014 assert((level == IS_LEVEL_1) || (level == IS_LEVEL_2));
3015 dest = (level == IS_LEVEL_1) ? &area->area_passwd
3016 : &area->domain_passwd;
3017 memset(&modified, 0, sizeof(modified));
3018
3019 if (passwd_type != ISIS_PASSWD_TYPE_UNUSED) {
3020 if (!passwd)
3021 return -1;
3022
3023 len = strlen(passwd);
3024 if (len > 254)
3025 return -1;
3026
3027 modified.len = len;
3028 strlcpy((char *)modified.passwd, passwd,
3029 sizeof(modified.passwd));
3030 modified.type = passwd_type;
3031 modified.snp_auth = snp_auth;
3032 }
3033
3034 if (memcmp(&modified, dest, sizeof(modified))) {
3035 memcpy(dest, &modified, sizeof(modified));
3036 lsp_regenerate_schedule(area, IS_LEVEL_1 | IS_LEVEL_2, 1);
3037 }
3038
3039 return 0;
3040 }
3041
3042 int isis_area_passwd_unset(struct isis_area *area, int level)
3043 {
3044 return isis_area_passwd_set(area, level, ISIS_PASSWD_TYPE_UNUSED, NULL,
3045 0);
3046 }
3047
3048 int isis_area_passwd_cleartext_set(struct isis_area *area, int level,
3049 const char *passwd, uint8_t snp_auth)
3050 {
3051 return isis_area_passwd_set(area, level, ISIS_PASSWD_TYPE_CLEARTXT,
3052 passwd, snp_auth);
3053 }
3054
3055 int isis_area_passwd_hmac_md5_set(struct isis_area *area, int level,
3056 const char *passwd, uint8_t snp_auth)
3057 {
3058 return isis_area_passwd_set(area, level, ISIS_PASSWD_TYPE_HMAC_MD5,
3059 passwd, snp_auth);
3060 }
3061
3062 void isis_area_invalidate_routes(struct isis_area *area, int levels)
3063 {
3064 for (int level = ISIS_LEVEL1; level <= ISIS_LEVEL2; level++) {
3065 if (!(level & levels))
3066 continue;
3067 for (int tree = SPFTREE_IPV4; tree < SPFTREE_COUNT; tree++) {
3068 isis_spf_invalidate_routes(
3069 area->spftree[tree][level - 1]);
3070 }
3071 }
3072 }
3073
3074 void isis_area_verify_routes(struct isis_area *area)
3075 {
3076 for (int tree = SPFTREE_IPV4; tree < SPFTREE_COUNT; tree++)
3077 isis_spf_verify_routes(area, area->spftree[tree]);
3078 }
3079
3080 static void area_resign_level(struct isis_area *area, int level)
3081 {
3082 isis_area_invalidate_routes(area, level);
3083 isis_area_verify_routes(area);
3084
3085 lsp_db_fini(&area->lspdb[level - 1]);
3086
3087 for (int tree = SPFTREE_IPV4; tree < SPFTREE_COUNT; tree++) {
3088 if (area->spftree[tree][level - 1]) {
3089 isis_spftree_del(area->spftree[tree][level - 1]);
3090 area->spftree[tree][level - 1] = NULL;
3091 }
3092 }
3093
3094 if (area->spf_timer[level - 1])
3095 isis_spf_timer_free(THREAD_ARG(area->spf_timer[level - 1]));
3096
3097 thread_cancel(&area->spf_timer[level - 1]);
3098
3099 sched_debug(
3100 "ISIS (%s): Resigned from L%d - canceling LSP regeneration timer.",
3101 area->area_tag, level);
3102 thread_cancel(&area->t_lsp_refresh[level - 1]);
3103 area->lsp_regenerate_pending[level - 1] = 0;
3104 }
3105
3106 void isis_area_is_type_set(struct isis_area *area, int is_type)
3107 {
3108 struct listnode *node;
3109 struct isis_circuit *circuit;
3110
3111 if (IS_DEBUG_EVENTS)
3112 zlog_debug("ISIS-Evt (%s) system type change %s -> %s",
3113 area->area_tag, circuit_t2string(area->is_type),
3114 circuit_t2string(is_type));
3115
3116 if (area->is_type == is_type)
3117 return; /* No change */
3118
3119 switch (area->is_type) {
3120 case IS_LEVEL_1:
3121 if (is_type == IS_LEVEL_2)
3122 area_resign_level(area, IS_LEVEL_1);
3123
3124 lsp_db_init(&area->lspdb[1]);
3125 break;
3126
3127 case IS_LEVEL_1_AND_2:
3128 if (is_type == IS_LEVEL_1)
3129 area_resign_level(area, IS_LEVEL_2);
3130 else
3131 area_resign_level(area, IS_LEVEL_1);
3132 break;
3133
3134 case IS_LEVEL_2:
3135 if (is_type == IS_LEVEL_1)
3136 area_resign_level(area, IS_LEVEL_2);
3137
3138 lsp_db_init(&area->lspdb[0]);
3139 break;
3140
3141 default:
3142 break;
3143 }
3144
3145 area->is_type = is_type;
3146
3147 /*
3148 * If area's IS type is strict Level-1 or Level-2, override circuit's
3149 * IS type. Otherwise use circuit's configured IS type.
3150 */
3151 if (area->is_type != IS_LEVEL_1_AND_2) {
3152 for (ALL_LIST_ELEMENTS_RO(area->circuit_list, node, circuit))
3153 isis_circuit_is_type_set(circuit, is_type);
3154 } else {
3155 for (ALL_LIST_ELEMENTS_RO(area->circuit_list, node, circuit))
3156 isis_circuit_is_type_set(circuit, circuit->is_type_config);
3157 }
3158
3159 spftree_area_init(area);
3160
3161 if (listcount(area->area_addrs) > 0) {
3162 if (is_type & IS_LEVEL_1)
3163 lsp_generate(area, IS_LEVEL_1);
3164 if (is_type & IS_LEVEL_2)
3165 lsp_generate(area, IS_LEVEL_2);
3166 }
3167 lsp_regenerate_schedule(area, IS_LEVEL_1 | IS_LEVEL_2, 1);
3168
3169 return;
3170 }
3171
3172 void isis_area_metricstyle_set(struct isis_area *area, bool old_metric,
3173 bool new_metric)
3174 {
3175 area->oldmetric = old_metric;
3176 area->newmetric = new_metric;
3177 lsp_regenerate_schedule(area, IS_LEVEL_1 | IS_LEVEL_2, 1);
3178 }
3179
3180 void isis_area_overload_bit_set(struct isis_area *area, bool overload_bit)
3181 {
3182 char new_overload_bit = overload_bit ? LSPBIT_OL : 0;
3183
3184 if (new_overload_bit != area->overload_bit) {
3185 area->overload_bit = new_overload_bit;
3186
3187 if (new_overload_bit)
3188 area->overload_counter++;
3189
3190 #ifndef FABRICD
3191 hook_call(isis_hook_db_overload, area);
3192 #endif /* ifndef FABRICD */
3193
3194 lsp_regenerate_schedule(area, IS_LEVEL_1 | IS_LEVEL_2, 1);
3195 }
3196 #ifndef FABRICD
3197 isis_notif_db_overload(area, overload_bit);
3198 #endif /* ifndef FABRICD */
3199 }
3200
3201 void isis_area_attached_bit_send_set(struct isis_area *area, bool attached_bit)
3202 {
3203
3204 if (attached_bit != area->attached_bit_send) {
3205 area->attached_bit_send = attached_bit;
3206 lsp_regenerate_schedule(area, IS_LEVEL_1 | IS_LEVEL_2, 1);
3207 }
3208 }
3209
3210 void isis_area_attached_bit_receive_set(struct isis_area *area,
3211 bool attached_bit)
3212 {
3213
3214 if (attached_bit != area->attached_bit_rcv_ignore) {
3215 area->attached_bit_rcv_ignore = attached_bit;
3216 lsp_regenerate_schedule(area, IS_LEVEL_1 | IS_LEVEL_2, 1);
3217 }
3218 }
3219
3220 void isis_area_dynhostname_set(struct isis_area *area, bool dynhostname)
3221 {
3222 if (area->dynhostname != dynhostname) {
3223 area->dynhostname = dynhostname;
3224 lsp_regenerate_schedule(area, IS_LEVEL_1 | IS_LEVEL_2, 0);
3225 }
3226 }
3227
3228 void isis_area_max_lsp_lifetime_set(struct isis_area *area, int level,
3229 uint16_t max_lsp_lifetime)
3230 {
3231 assert((level == IS_LEVEL_1) || (level == IS_LEVEL_2));
3232
3233 if (area->max_lsp_lifetime[level - 1] == max_lsp_lifetime)
3234 return;
3235
3236 area->max_lsp_lifetime[level - 1] = max_lsp_lifetime;
3237 lsp_regenerate_schedule(area, level, 1);
3238 }
3239
3240 void isis_area_lsp_refresh_set(struct isis_area *area, int level,
3241 uint16_t lsp_refresh)
3242 {
3243 assert((level == IS_LEVEL_1) || (level == IS_LEVEL_2));
3244
3245 if (area->lsp_refresh[level - 1] == lsp_refresh)
3246 return;
3247
3248 area->lsp_refresh[level - 1] = lsp_refresh;
3249 lsp_regenerate_schedule(area, level, 1);
3250 }
3251
3252 #ifdef FABRICD
3253 DEFUN (log_adj_changes,
3254 log_adj_changes_cmd,
3255 "log-adjacency-changes",
3256 "Log changes in adjacency state\n")
3257 {
3258 VTY_DECLVAR_CONTEXT(isis_area, area);
3259
3260 area->log_adj_changes = 1;
3261
3262 return CMD_SUCCESS;
3263 }
3264
3265 DEFUN (no_log_adj_changes,
3266 no_log_adj_changes_cmd,
3267 "no log-adjacency-changes",
3268 NO_STR
3269 "Stop logging changes in adjacency state\n")
3270 {
3271 VTY_DECLVAR_CONTEXT(isis_area, area);
3272
3273 area->log_adj_changes = 0;
3274
3275 return CMD_SUCCESS;
3276 }
3277 #endif /* ifdef FABRICD */
3278 #ifdef FABRICD
3279 /* IS-IS configuration write function */
3280 static int isis_config_write(struct vty *vty)
3281 {
3282 int write = 0;
3283 struct isis_area *area;
3284 struct listnode *node, *node2, *inode;
3285 struct isis *isis;
3286
3287 if (!im) {
3288 vty_out(vty, "IS-IS Routing Process not enabled\n");
3289 return CMD_SUCCESS;
3290 }
3291
3292 for (ALL_LIST_ELEMENTS_RO(im->isis, inode, isis)) {
3293 for (ALL_LIST_ELEMENTS_RO(isis->area_list, node, area)) {
3294 /* ISIS - Area name */
3295 vty_out(vty, "router " PROTO_NAME " %s\n", area->area_tag);
3296 write++;
3297 /* ISIS - Net */
3298 if (listcount(area->area_addrs) > 0) {
3299 struct area_addr *area_addr;
3300 for (ALL_LIST_ELEMENTS_RO(area->area_addrs,
3301 node2, area_addr)) {
3302 vty_out(vty, " net %s\n",
3303 isonet_print(
3304 area_addr->area_addr,
3305 area_addr->addr_len
3306 + ISIS_SYS_ID_LEN
3307 + 1));
3308 write++;
3309 }
3310 }
3311 /* ISIS - Dynamic hostname - Defaults to true so only
3312 * display if
3313 * false. */
3314 if (!area->dynhostname) {
3315 vty_out(vty, " no hostname dynamic\n");
3316 write++;
3317 }
3318 /* ISIS - Metric-Style - when true displays wide */
3319 if (!fabricd) {
3320 if (area->newmetric) {
3321 if (!area->oldmetric)
3322 vty_out(vty, " metric-style wide\n");
3323 else
3324 vty_out(vty,
3325 " metric-style transition\n");
3326 write++;
3327 } else {
3328 vty_out(vty, " metric-style narrow\n");
3329 write++;
3330 }
3331 }
3332 /* ISIS - overload-bit */
3333 if (area->overload_bit) {
3334 vty_out(vty, " set-overload-bit\n");
3335 write++;
3336 }
3337 /* ISIS - Area is-type (level-1-2 is default) */
3338 if (!fabricd) {
3339 if (area->is_type == IS_LEVEL_1) {
3340 vty_out(vty, " is-type level-1\n");
3341 write++;
3342 } else if (area->is_type == IS_LEVEL_2) {
3343 vty_out(vty, " is-type level-2-only\n");
3344 write++;
3345 }
3346 }
3347 write += isis_redist_config_write(vty, area, AF_INET);
3348 write += isis_redist_config_write(vty, area, AF_INET6);
3349 /* ISIS - Lsp generation interval */
3350 if (area->lsp_gen_interval[0]
3351 == area->lsp_gen_interval[1]) {
3352 if (area->lsp_gen_interval[0]
3353 != DEFAULT_MIN_LSP_GEN_INTERVAL) {
3354 vty_out(vty, " lsp-gen-interval %d\n",
3355 area->lsp_gen_interval[0]);
3356 write++;
3357 }
3358 } else {
3359 if (area->lsp_gen_interval[0]
3360 != DEFAULT_MIN_LSP_GEN_INTERVAL) {
3361 vty_out(vty,
3362 " lsp-gen-interval level-1 %d\n",
3363 area->lsp_gen_interval[0]);
3364 write++;
3365 }
3366 if (area->lsp_gen_interval[1]
3367 != DEFAULT_MIN_LSP_GEN_INTERVAL) {
3368 vty_out(vty,
3369 " lsp-gen-interval level-2 %d\n",
3370 area->lsp_gen_interval[1]);
3371 write++;
3372 }
3373 }
3374 /* ISIS - LSP lifetime */
3375 if (area->max_lsp_lifetime[0]
3376 == area->max_lsp_lifetime[1]) {
3377 if (area->max_lsp_lifetime[0]
3378 != DEFAULT_LSP_LIFETIME) {
3379 vty_out(vty, " max-lsp-lifetime %u\n",
3380 area->max_lsp_lifetime[0]);
3381 write++;
3382 }
3383 } else {
3384 if (area->max_lsp_lifetime[0]
3385 != DEFAULT_LSP_LIFETIME) {
3386 vty_out(vty,
3387 " max-lsp-lifetime level-1 %u\n",
3388 area->max_lsp_lifetime[0]);
3389 write++;
3390 }
3391 if (area->max_lsp_lifetime[1]
3392 != DEFAULT_LSP_LIFETIME) {
3393 vty_out(vty,
3394 " max-lsp-lifetime level-2 %u\n",
3395 area->max_lsp_lifetime[1]);
3396 write++;
3397 }
3398 }
3399 /* ISIS - LSP refresh interval */
3400 if (area->lsp_refresh[0] == area->lsp_refresh[1]) {
3401 if (area->lsp_refresh[0]
3402 != DEFAULT_MAX_LSP_GEN_INTERVAL) {
3403 vty_out(vty,
3404 " lsp-refresh-interval %u\n",
3405 area->lsp_refresh[0]);
3406 write++;
3407 }
3408 } else {
3409 if (area->lsp_refresh[0]
3410 != DEFAULT_MAX_LSP_GEN_INTERVAL) {
3411 vty_out(vty,
3412 " lsp-refresh-interval level-1 %u\n",
3413 area->lsp_refresh[0]);
3414 write++;
3415 }
3416 if (area->lsp_refresh[1]
3417 != DEFAULT_MAX_LSP_GEN_INTERVAL) {
3418 vty_out(vty,
3419 " lsp-refresh-interval level-2 %u\n",
3420 area->lsp_refresh[1]);
3421 write++;
3422 }
3423 }
3424 if (area->lsp_mtu != DEFAULT_LSP_MTU) {
3425 vty_out(vty, " lsp-mtu %u\n", area->lsp_mtu);
3426 write++;
3427 }
3428 if (area->purge_originator) {
3429 vty_out(vty, " purge-originator\n");
3430 write++;
3431 }
3432
3433 /* Minimum SPF interval. */
3434 if (area->min_spf_interval[0]
3435 == area->min_spf_interval[1]) {
3436 if (area->min_spf_interval[0]
3437 != MINIMUM_SPF_INTERVAL) {
3438 vty_out(vty, " spf-interval %d\n",
3439 area->min_spf_interval[0]);
3440 write++;
3441 }
3442 } else {
3443 if (area->min_spf_interval[0]
3444 != MINIMUM_SPF_INTERVAL) {
3445 vty_out(vty,
3446 " spf-interval level-1 %d\n",
3447 area->min_spf_interval[0]);
3448 write++;
3449 }
3450 if (area->min_spf_interval[1]
3451 != MINIMUM_SPF_INTERVAL) {
3452 vty_out(vty,
3453 " spf-interval level-2 %d\n",
3454 area->min_spf_interval[1]);
3455 write++;
3456 }
3457 }
3458
3459 /* IETF SPF interval */
3460 if (area->spf_delay_ietf[0]) {
3461 vty_out(vty,
3462 " spf-delay-ietf init-delay %ld short-delay %ld long-delay %ld holddown %ld time-to-learn %ld\n",
3463 spf_backoff_init_delay(
3464 area->spf_delay_ietf[0]),
3465 spf_backoff_short_delay(
3466 area->spf_delay_ietf[0]),
3467 spf_backoff_long_delay(
3468 area->spf_delay_ietf[0]),
3469 spf_backoff_holddown(
3470 area->spf_delay_ietf[0]),
3471 spf_backoff_timetolearn(
3472 area->spf_delay_ietf[0]));
3473 write++;
3474 }
3475
3476 /* Authentication passwords. */
3477 if (area->area_passwd.type
3478 == ISIS_PASSWD_TYPE_HMAC_MD5) {
3479 vty_out(vty, " area-password md5 %s",
3480 area->area_passwd.passwd);
3481 if (CHECK_FLAG(area->area_passwd.snp_auth,
3482 SNP_AUTH_SEND)) {
3483 vty_out(vty, " authenticate snp ");
3484 if (CHECK_FLAG(
3485 area->area_passwd.snp_auth,
3486 SNP_AUTH_RECV))
3487 vty_out(vty, "validate");
3488 else
3489 vty_out(vty, "send-only");
3490 }
3491 vty_out(vty, "\n");
3492 write++;
3493 } else if (area->area_passwd.type
3494 == ISIS_PASSWD_TYPE_CLEARTXT) {
3495 vty_out(vty, " area-password clear %s",
3496 area->area_passwd.passwd);
3497 if (CHECK_FLAG(area->area_passwd.snp_auth,
3498 SNP_AUTH_SEND)) {
3499 vty_out(vty, " authenticate snp ");
3500 if (CHECK_FLAG(
3501 area->area_passwd.snp_auth,
3502 SNP_AUTH_RECV))
3503 vty_out(vty, "validate");
3504 else
3505 vty_out(vty, "send-only");
3506 }
3507 vty_out(vty, "\n");
3508 write++;
3509 }
3510 if (area->domain_passwd.type
3511 == ISIS_PASSWD_TYPE_HMAC_MD5) {
3512 vty_out(vty, " domain-password md5 %s",
3513 area->domain_passwd.passwd);
3514 if (CHECK_FLAG(area->domain_passwd.snp_auth,
3515 SNP_AUTH_SEND)) {
3516 vty_out(vty, " authenticate snp ");
3517 if (CHECK_FLAG(area->domain_passwd
3518 .snp_auth,
3519 SNP_AUTH_RECV))
3520 vty_out(vty, "validate");
3521 else
3522 vty_out(vty, "send-only");
3523 }
3524 vty_out(vty, "\n");
3525 write++;
3526 } else if (area->domain_passwd.type
3527 == ISIS_PASSWD_TYPE_CLEARTXT) {
3528 vty_out(vty, " domain-password clear %s",
3529 area->domain_passwd.passwd);
3530 if (CHECK_FLAG(area->domain_passwd.snp_auth,
3531 SNP_AUTH_SEND)) {
3532 vty_out(vty, " authenticate snp ");
3533 if (CHECK_FLAG(area->domain_passwd
3534 .snp_auth,
3535 SNP_AUTH_RECV))
3536 vty_out(vty, "validate");
3537 else
3538 vty_out(vty, "send-only");
3539 }
3540 vty_out(vty, "\n");
3541 write++;
3542 }
3543
3544 if (area->log_adj_changes) {
3545 vty_out(vty, " log-adjacency-changes\n");
3546 write++;
3547 }
3548
3549 write += area_write_mt_settings(area, vty);
3550 write += fabricd_write_settings(area, vty);
3551
3552 vty_out(vty, "exit\n");
3553 }
3554 }
3555
3556 return write;
3557 }
3558
3559 struct cmd_node router_node = {
3560 .name = "openfabric",
3561 .node = OPENFABRIC_NODE,
3562 .parent_node = CONFIG_NODE,
3563 .prompt = "%s(config-router)# ",
3564 .config_write = isis_config_write,
3565 };
3566 #else
3567 /* IS-IS configuration write function */
3568 static int isis_config_write(struct vty *vty)
3569 {
3570 int write = 0;
3571 struct lyd_node *dnode;
3572
3573 dnode = yang_dnode_get(running_config->dnode, "/frr-isisd:isis");
3574 if (dnode) {
3575 nb_cli_show_dnode_cmds(vty, dnode, false);
3576 write++;
3577 }
3578
3579 return write;
3580 }
3581
3582 struct cmd_node router_node = {
3583 .name = "isis",
3584 .node = ISIS_NODE,
3585 .parent_node = CONFIG_NODE,
3586 .prompt = "%s(config-router)# ",
3587 .config_write = isis_config_write,
3588 };
3589 #endif /* ifdef FABRICD */
3590
3591 void isis_init(void)
3592 {
3593 /* Install IS-IS top node */
3594 install_node(&router_node);
3595
3596 install_element(VIEW_NODE, &show_isis_summary_cmd);
3597
3598 install_element(VIEW_NODE, &show_isis_spf_ietf_cmd);
3599
3600 install_element(VIEW_NODE, &show_isis_interface_cmd);
3601 install_element(VIEW_NODE, &show_isis_interface_detail_cmd);
3602 install_element(VIEW_NODE, &show_isis_interface_arg_cmd);
3603
3604 install_element(VIEW_NODE, &show_isis_neighbor_cmd);
3605 install_element(VIEW_NODE, &show_isis_neighbor_detail_cmd);
3606 install_element(VIEW_NODE, &show_isis_neighbor_arg_cmd);
3607 install_element(ENABLE_NODE, &clear_isis_neighbor_cmd);
3608 install_element(ENABLE_NODE, &clear_isis_neighbor_arg_cmd);
3609
3610 install_element(VIEW_NODE, &show_hostname_cmd);
3611 install_element(VIEW_NODE, &show_database_cmd);
3612
3613 install_element(ENABLE_NODE, &show_debugging_isis_cmd);
3614
3615 install_node(&debug_node);
3616
3617 install_element(ENABLE_NODE, &debug_isis_adj_cmd);
3618 install_element(ENABLE_NODE, &no_debug_isis_adj_cmd);
3619 install_element(ENABLE_NODE, &debug_isis_tx_queue_cmd);
3620 install_element(ENABLE_NODE, &no_debug_isis_tx_queue_cmd);
3621 install_element(ENABLE_NODE, &debug_isis_flooding_cmd);
3622 install_element(ENABLE_NODE, &no_debug_isis_flooding_cmd);
3623 install_element(ENABLE_NODE, &debug_isis_snp_cmd);
3624 install_element(ENABLE_NODE, &no_debug_isis_snp_cmd);
3625 install_element(ENABLE_NODE, &debug_isis_upd_cmd);
3626 install_element(ENABLE_NODE, &no_debug_isis_upd_cmd);
3627 install_element(ENABLE_NODE, &debug_isis_spfevents_cmd);
3628 install_element(ENABLE_NODE, &no_debug_isis_spfevents_cmd);
3629 install_element(ENABLE_NODE, &debug_isis_srevents_cmd);
3630 install_element(ENABLE_NODE, &no_debug_isis_srevents_cmd);
3631 install_element(ENABLE_NODE, &debug_isis_teevents_cmd);
3632 install_element(ENABLE_NODE, &no_debug_isis_teevents_cmd);
3633 install_element(ENABLE_NODE, &debug_isis_lfa_cmd);
3634 install_element(ENABLE_NODE, &no_debug_isis_lfa_cmd);
3635 install_element(ENABLE_NODE, &debug_isis_rtevents_cmd);
3636 install_element(ENABLE_NODE, &no_debug_isis_rtevents_cmd);
3637 install_element(ENABLE_NODE, &debug_isis_events_cmd);
3638 install_element(ENABLE_NODE, &no_debug_isis_events_cmd);
3639 install_element(ENABLE_NODE, &debug_isis_packet_dump_cmd);
3640 install_element(ENABLE_NODE, &no_debug_isis_packet_dump_cmd);
3641 install_element(ENABLE_NODE, &debug_isis_lsp_gen_cmd);
3642 install_element(ENABLE_NODE, &no_debug_isis_lsp_gen_cmd);
3643 install_element(ENABLE_NODE, &debug_isis_lsp_sched_cmd);
3644 install_element(ENABLE_NODE, &no_debug_isis_lsp_sched_cmd);
3645 install_element(ENABLE_NODE, &debug_isis_bfd_cmd);
3646 install_element(ENABLE_NODE, &no_debug_isis_bfd_cmd);
3647 install_element(ENABLE_NODE, &debug_isis_ldp_sync_cmd);
3648 install_element(ENABLE_NODE, &no_debug_isis_ldp_sync_cmd);
3649
3650 install_element(CONFIG_NODE, &debug_isis_adj_cmd);
3651 install_element(CONFIG_NODE, &no_debug_isis_adj_cmd);
3652 install_element(CONFIG_NODE, &debug_isis_tx_queue_cmd);
3653 install_element(CONFIG_NODE, &no_debug_isis_tx_queue_cmd);
3654 install_element(CONFIG_NODE, &debug_isis_flooding_cmd);
3655 install_element(CONFIG_NODE, &no_debug_isis_flooding_cmd);
3656 install_element(CONFIG_NODE, &debug_isis_snp_cmd);
3657 install_element(CONFIG_NODE, &no_debug_isis_snp_cmd);
3658 install_element(CONFIG_NODE, &debug_isis_upd_cmd);
3659 install_element(CONFIG_NODE, &no_debug_isis_upd_cmd);
3660 install_element(CONFIG_NODE, &debug_isis_spfevents_cmd);
3661 install_element(CONFIG_NODE, &no_debug_isis_spfevents_cmd);
3662 install_element(CONFIG_NODE, &debug_isis_srevents_cmd);
3663 install_element(CONFIG_NODE, &no_debug_isis_srevents_cmd);
3664 install_element(CONFIG_NODE, &debug_isis_teevents_cmd);
3665 install_element(CONFIG_NODE, &no_debug_isis_teevents_cmd);
3666 install_element(CONFIG_NODE, &debug_isis_lfa_cmd);
3667 install_element(CONFIG_NODE, &no_debug_isis_lfa_cmd);
3668 install_element(CONFIG_NODE, &debug_isis_rtevents_cmd);
3669 install_element(CONFIG_NODE, &no_debug_isis_rtevents_cmd);
3670 install_element(CONFIG_NODE, &debug_isis_events_cmd);
3671 install_element(CONFIG_NODE, &no_debug_isis_events_cmd);
3672 install_element(CONFIG_NODE, &debug_isis_packet_dump_cmd);
3673 install_element(CONFIG_NODE, &no_debug_isis_packet_dump_cmd);
3674 install_element(CONFIG_NODE, &debug_isis_lsp_gen_cmd);
3675 install_element(CONFIG_NODE, &no_debug_isis_lsp_gen_cmd);
3676 install_element(CONFIG_NODE, &debug_isis_lsp_sched_cmd);
3677 install_element(CONFIG_NODE, &no_debug_isis_lsp_sched_cmd);
3678 install_element(CONFIG_NODE, &debug_isis_bfd_cmd);
3679 install_element(CONFIG_NODE, &no_debug_isis_bfd_cmd);
3680 install_element(CONFIG_NODE, &debug_isis_ldp_sync_cmd);
3681 install_element(CONFIG_NODE, &no_debug_isis_ldp_sync_cmd);
3682
3683 install_default(ROUTER_NODE);
3684
3685 #ifdef FABRICD
3686 install_element(CONFIG_NODE, &router_openfabric_cmd);
3687 install_element(CONFIG_NODE, &no_router_openfabric_cmd);
3688
3689 install_element(ROUTER_NODE, &net_cmd);
3690 install_element(ROUTER_NODE, &no_net_cmd);
3691
3692 install_element(ROUTER_NODE, &isis_topology_cmd);
3693 install_element(ROUTER_NODE, &no_isis_topology_cmd);
3694
3695 install_element(ROUTER_NODE, &log_adj_changes_cmd);
3696 install_element(ROUTER_NODE, &no_log_adj_changes_cmd);
3697 #endif /* ifdef FABRICD */
3698
3699 spf_backoff_cmd_init();
3700 }