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