2 * IS-IS Rout(e)ing protocol - isis_circuit.h
4 * Copyright (C) 2001,2002 Sampo Saaristo
5 * Tampere University of Technology
6 * Institute of Communications Engineering
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)
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
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
24 #include <net/ethernet.h>
26 #include <netinet/if_ether.h>
41 #include "lib/northbound_cli.h"
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"
63 DEFINE_QOBJ_TYPE(isis_circuit
)
65 DEFINE_HOOK(isis_if_new_hook
, (struct interface
*ifp
), (ifp
))
70 int isis_interface_config_write(struct vty
*);
71 int isis_if_new_hook(struct interface
*);
72 int isis_if_delete_hook(struct interface
*);
74 struct isis_circuit
*isis_circuit_new(void)
76 struct isis_circuit
*circuit
;
79 circuit
= XCALLOC(MTYPE_ISIS_CIRCUIT
, sizeof(struct isis_circuit
));
85 circuit
->is_type
= yang_get_default_enum(
86 "/frr-interface:lib/interface/frr-isisd:isis/circuit-type");
89 circuit
->pad_hellos
= yang_get_default_bool(
90 "/frr-interface:lib/interface/frr-isisd:isis/hello/padding");
91 circuit
->hello_interval
[0] = yang_get_default_uint32(
92 "/frr-interface:lib/interface/frr-isisd:isis/hello/interval/level-1");
93 circuit
->hello_interval
[1] = yang_get_default_uint32(
94 "/frr-interface:lib/interface/frr-isisd:isis/hello/interval/level-2");
95 circuit
->hello_multiplier
[0] = yang_get_default_uint32(
96 "/frr-interface:lib/interface/frr-isisd:isis/hello/multiplier/level-1");
97 circuit
->hello_multiplier
[1] = yang_get_default_uint32(
98 "/frr-interface:lib/interface/frr-isisd:isis/hello/multiplier/level-2");
99 circuit
->csnp_interval
[0] = yang_get_default_uint16(
100 "/frr-interface:lib/interface/frr-isisd:isis/csnp-interval/level-1");
101 circuit
->csnp_interval
[1] = yang_get_default_uint16(
102 "/frr-interface:lib/interface/frr-isisd:isis/csnp-interval/level-2");
103 circuit
->psnp_interval
[0] = yang_get_default_uint16(
104 "/frr-interface:lib/interface/frr-isisd:isis/psnp-interval/level-1");
105 circuit
->psnp_interval
[1] = yang_get_default_uint16(
106 "/frr-interface:lib/interface/frr-isisd:isis/psnp-interval/level-2");
107 circuit
->priority
[0] = yang_get_default_uint8(
108 "/frr-interface:lib/interface/frr-isisd:isis/priority/level-1");
109 circuit
->priority
[1] = yang_get_default_uint8(
110 "/frr-interface:lib/interface/frr-isisd:isis/priority/level-2");
111 circuit
->metric
[0] = yang_get_default_uint32(
112 "/frr-interface:lib/interface/frr-isisd:isis/metric/level-1");
113 circuit
->metric
[1] = yang_get_default_uint32(
114 "/frr-interface:lib/interface/frr-isisd:isis/metric/level-2");
115 circuit
->te_metric
[0] = yang_get_default_uint32(
116 "/frr-interface:lib/interface/frr-isisd:isis/metric/level-1");
117 circuit
->te_metric
[1] = yang_get_default_uint32(
118 "/frr-interface:lib/interface/frr-isisd:isis/metric/level-2");
120 for (i
= 0; i
< 2; i
++) {
121 circuit
->level_arg
[i
].level
= i
+ 1;
122 circuit
->level_arg
[i
].circuit
= circuit
;
125 circuit
->is_type
= IS_LEVEL_1_AND_2
;
127 circuit
->pad_hellos
= 1;
128 for (i
= 0; i
< 2; i
++) {
129 circuit
->hello_interval
[i
] = DEFAULT_HELLO_INTERVAL
;
130 circuit
->hello_multiplier
[i
] = DEFAULT_HELLO_MULTIPLIER
;
131 circuit
->csnp_interval
[i
] = DEFAULT_CSNP_INTERVAL
;
132 circuit
->psnp_interval
[i
] = DEFAULT_PSNP_INTERVAL
;
133 circuit
->priority
[i
] = DEFAULT_PRIORITY
;
134 circuit
->metric
[i
] = DEFAULT_CIRCUIT_METRIC
;
135 circuit
->te_metric
[i
] = DEFAULT_CIRCUIT_METRIC
;
136 circuit
->level_arg
[i
].level
= i
+ 1;
137 circuit
->level_arg
[i
].circuit
= circuit
;
139 #endif /* ifndef FABRICD */
141 circuit_mt_init(circuit
);
143 QOBJ_REG(circuit
, isis_circuit
);
148 void isis_circuit_del(struct isis_circuit
*circuit
)
155 isis_circuit_if_unbind(circuit
, circuit
->interface
);
157 circuit_mt_finish(circuit
);
159 /* and lastly the circuit itself */
160 XFREE(MTYPE_ISIS_CIRCUIT
, circuit
);
165 void isis_circuit_configure(struct isis_circuit
*circuit
,
166 struct isis_area
*area
)
169 circuit
->area
= area
;
172 * Whenever the is-type of an area is changed, the is-type of each
174 * in that area is updated to a non-empty subset of the area is-type.
175 * Inversely, when configuring a new circuit, this property should be
178 if (area
->is_type
!= IS_LEVEL_1_AND_2
)
179 circuit
->is_type
= area
->is_type
;
182 * Add the circuit into area
184 listnode_add(area
->circuit_list
, circuit
);
186 circuit
->idx
= flags_get_index(&area
->flags
);
191 void isis_circuit_deconfigure(struct isis_circuit
*circuit
,
192 struct isis_area
*area
)
194 /* Free the index of SRM and SSN flags */
195 flags_free_index(&area
->flags
, circuit
->idx
);
197 /* Remove circuit from area */
198 assert(circuit
->area
== area
);
199 listnode_delete(area
->circuit_list
, circuit
);
200 circuit
->area
= NULL
;
205 struct isis_circuit
*circuit_lookup_by_ifp(struct interface
*ifp
,
208 struct isis_circuit
*circuit
= NULL
;
209 struct listnode
*node
;
214 for (ALL_LIST_ELEMENTS_RO(list
, node
, circuit
))
215 if (circuit
->interface
== ifp
) {
216 assert(ifp
->info
== circuit
);
223 struct isis_circuit
*circuit_scan_by_ifp(struct interface
*ifp
)
225 struct isis_area
*area
;
226 struct listnode
*node
;
227 struct isis_circuit
*circuit
;
230 return (struct isis_circuit
*)ifp
->info
;
232 if (isis
->area_list
) {
233 for (ALL_LIST_ELEMENTS_RO(isis
->area_list
, node
, area
)) {
235 circuit_lookup_by_ifp(ifp
, area
->circuit_list
);
240 return circuit_lookup_by_ifp(ifp
, isis
->init_circ_list
);
243 void isis_circuit_add_addr(struct isis_circuit
*circuit
,
244 struct connected
*connected
)
246 struct listnode
*node
;
247 struct prefix_ipv4
*ipv4
;
248 #if defined(EXTREME_DEBUG)
249 char buf
[PREFIX2STR_BUFFER
];
251 struct prefix_ipv6
*ipv6
;
253 if (connected
->address
->family
== AF_INET
) {
254 uint32_t addr
= connected
->address
->u
.prefix4
.s_addr
;
256 if (IPV4_NET0(addr
) || IPV4_NET127(addr
) || IN_CLASSD(addr
)
257 || IPV4_LINKLOCAL(addr
))
260 for (ALL_LIST_ELEMENTS_RO(circuit
->ip_addrs
, node
, ipv4
))
261 if (prefix_same((struct prefix
*)ipv4
,
265 ipv4
= prefix_ipv4_new();
266 ipv4
->prefixlen
= connected
->address
->prefixlen
;
267 ipv4
->prefix
= connected
->address
->u
.prefix4
;
268 listnode_add(circuit
->ip_addrs
, ipv4
);
270 /* Update Local IP address parameter if MPLS TE is enable */
271 if (circuit
->ext
&& IS_MPLS_TE(circuit
->ext
)) {
272 circuit
->ext
->local_addr
.s_addr
= ipv4
->prefix
.s_addr
;
273 SET_SUBTLV(circuit
->ext
, EXT_LOCAL_ADDR
);
277 lsp_regenerate_schedule(circuit
->area
, circuit
->is_type
,
281 prefix2str(connected
->address
, buf
, sizeof(buf
));
282 zlog_debug("Added IP address %s to circuit %s", buf
,
283 circuit
->interface
->name
);
284 #endif /* EXTREME_DEBUG */
286 if (connected
->address
->family
== AF_INET6
) {
287 if (IN6_IS_ADDR_LOOPBACK(&connected
->address
->u
.prefix6
))
290 for (ALL_LIST_ELEMENTS_RO(circuit
->ipv6_link
, node
, ipv6
))
291 if (prefix_same((struct prefix
*)ipv6
,
294 for (ALL_LIST_ELEMENTS_RO(circuit
->ipv6_non_link
, node
, ipv6
))
295 if (prefix_same((struct prefix
*)ipv6
,
299 ipv6
= prefix_ipv6_new();
300 ipv6
->prefixlen
= connected
->address
->prefixlen
;
301 ipv6
->prefix
= connected
->address
->u
.prefix6
;
303 if (IN6_IS_ADDR_LINKLOCAL(&ipv6
->prefix
))
304 listnode_add(circuit
->ipv6_link
, ipv6
);
306 listnode_add(circuit
->ipv6_non_link
, ipv6
);
308 lsp_regenerate_schedule(circuit
->area
, circuit
->is_type
,
312 prefix2str(connected
->address
, buf
, sizeof(buf
));
313 zlog_debug("Added IPv6 address %s to circuit %s", buf
,
314 circuit
->interface
->name
);
315 #endif /* EXTREME_DEBUG */
320 void isis_circuit_del_addr(struct isis_circuit
*circuit
,
321 struct connected
*connected
)
323 struct prefix_ipv4
*ipv4
, *ip
= NULL
;
324 struct listnode
*node
;
325 char buf
[PREFIX2STR_BUFFER
];
326 struct prefix_ipv6
*ipv6
, *ip6
= NULL
;
329 if (connected
->address
->family
== AF_INET
) {
330 ipv4
= prefix_ipv4_new();
331 ipv4
->prefixlen
= connected
->address
->prefixlen
;
332 ipv4
->prefix
= connected
->address
->u
.prefix4
;
334 for (ALL_LIST_ELEMENTS_RO(circuit
->ip_addrs
, node
, ip
))
335 if (prefix_same((struct prefix
*)ip
,
336 (struct prefix
*)ipv4
))
340 listnode_delete(circuit
->ip_addrs
, ip
);
341 prefix_ipv4_free(&ip
);
343 lsp_regenerate_schedule(circuit
->area
,
344 circuit
->is_type
, 0);
346 prefix2str(connected
->address
, buf
, sizeof(buf
));
348 "Nonexistent ip address %s removal attempt from circuit %s",
349 buf
, circuit
->interface
->name
);
350 zlog_warn("Current ip addresses on %s:",
351 circuit
->interface
->name
);
352 for (ALL_LIST_ELEMENTS_RO(circuit
->ip_addrs
, node
,
354 prefix2str(ip
, buf
, sizeof(buf
));
355 zlog_warn(" %s", buf
);
357 zlog_warn("End of addresses");
360 prefix_ipv4_free(&ipv4
);
362 if (connected
->address
->family
== AF_INET6
) {
363 ipv6
= prefix_ipv6_new();
364 ipv6
->prefixlen
= connected
->address
->prefixlen
;
365 ipv6
->prefix
= connected
->address
->u
.prefix6
;
367 if (IN6_IS_ADDR_LINKLOCAL(&ipv6
->prefix
)) {
368 for (ALL_LIST_ELEMENTS_RO(circuit
->ipv6_link
, node
,
370 if (prefix_same((struct prefix
*)ip6
,
371 (struct prefix
*)ipv6
))
375 listnode_delete(circuit
->ipv6_link
, ip6
);
376 prefix_ipv6_free(&ip6
);
380 for (ALL_LIST_ELEMENTS_RO(circuit
->ipv6_non_link
, node
,
382 if (prefix_same((struct prefix
*)ip6
,
383 (struct prefix
*)ipv6
))
387 listnode_delete(circuit
->ipv6_non_link
, ip6
);
388 prefix_ipv6_free(&ip6
);
394 prefix2str(connected
->address
, buf
, sizeof(buf
));
396 "Nonexistent ip address %s removal attempt from circuit %s",
397 buf
, circuit
->interface
->name
);
398 zlog_warn("Current ip addresses on %s:",
399 circuit
->interface
->name
);
400 for (ALL_LIST_ELEMENTS_RO(circuit
->ipv6_link
, node
,
402 prefix2str((struct prefix
*)ip6
, (char *)buf
,
404 zlog_warn(" %s", buf
);
407 for (ALL_LIST_ELEMENTS_RO(circuit
->ipv6_non_link
, node
,
409 prefix2str((struct prefix
*)ip6
, (char *)buf
,
411 zlog_warn(" %s", buf
);
413 zlog_warn("End of addresses");
414 } else if (circuit
->area
)
415 lsp_regenerate_schedule(circuit
->area
, circuit
->is_type
,
418 prefix_ipv6_free(&ipv6
);
423 static uint8_t isis_circuit_id_gen(struct isis
*isis
, struct interface
*ifp
)
425 /* Circuit ids MUST be unique for any broadcast circuits. Otherwise,
426 * Pseudo-Node LSPs cannot be generated correctly.
428 * Currently, allocate one circuit ID for any circuit, limiting the total
429 * numer of circuits IS-IS can run on to 255.
431 * We should revisit this when implementing 3-way adjacencies for p2p, since
432 * we then have extended interface IDs available.
434 uint8_t id
= ifp
->ifindex
;
437 for (i
= 0; i
< 256; i
++) {
438 if (id
&& !_ISIS_CHECK_FLAG(isis
->circuit_ids_used
, id
))
444 zlog_warn("Could not allocate a circuit id for '%s'",
449 _ISIS_SET_FLAG(isis
->circuit_ids_used
, id
);
453 void isis_circuit_if_add(struct isis_circuit
*circuit
, struct interface
*ifp
)
455 struct listnode
*node
, *nnode
;
456 struct connected
*conn
;
458 isis_circuit_if_bind(circuit
, ifp
);
460 if (if_is_broadcast(ifp
)) {
461 if (fabricd
|| circuit
->circ_type_config
== CIRCUIT_T_P2P
)
462 circuit
->circ_type
= CIRCUIT_T_P2P
;
464 circuit
->circ_type
= CIRCUIT_T_BROADCAST
;
465 } else if (if_is_pointopoint(ifp
)) {
466 circuit
->circ_type
= CIRCUIT_T_P2P
;
467 } else if (if_is_loopback(ifp
)) {
468 circuit
->circ_type
= CIRCUIT_T_LOOPBACK
;
469 circuit
->is_passive
= 1;
471 /* It's normal in case of loopback etc. */
472 if (isis
->debugs
& DEBUG_EVENTS
)
473 zlog_debug("isis_circuit_if_add: unsupported media");
474 circuit
->circ_type
= CIRCUIT_T_UNKNOWN
;
477 circuit
->ip_addrs
= list_new();
478 circuit
->ipv6_link
= list_new();
479 circuit
->ipv6_non_link
= list_new();
481 for (ALL_LIST_ELEMENTS(ifp
->connected
, node
, nnode
, conn
))
482 isis_circuit_add_addr(circuit
, conn
);
486 void isis_circuit_if_del(struct isis_circuit
*circuit
, struct interface
*ifp
)
488 struct listnode
*node
, *nnode
;
489 struct connected
*conn
;
491 assert(circuit
->interface
== ifp
);
493 /* destroy addresses */
494 for (ALL_LIST_ELEMENTS(ifp
->connected
, node
, nnode
, conn
))
495 isis_circuit_del_addr(circuit
, conn
);
497 if (circuit
->ip_addrs
) {
498 assert(listcount(circuit
->ip_addrs
) == 0);
499 list_delete(&circuit
->ip_addrs
);
502 if (circuit
->ipv6_link
) {
503 assert(listcount(circuit
->ipv6_link
) == 0);
504 list_delete(&circuit
->ipv6_link
);
507 if (circuit
->ipv6_non_link
) {
508 assert(listcount(circuit
->ipv6_non_link
) == 0);
509 list_delete(&circuit
->ipv6_non_link
);
512 circuit
->circ_type
= CIRCUIT_T_UNKNOWN
;
515 void isis_circuit_if_bind(struct isis_circuit
*circuit
, struct interface
*ifp
)
517 assert(circuit
!= NULL
);
519 if (circuit
->interface
)
520 assert(circuit
->interface
== ifp
);
522 circuit
->interface
= ifp
;
524 assert(ifp
->info
== circuit
);
529 void isis_circuit_if_unbind(struct isis_circuit
*circuit
, struct interface
*ifp
)
531 assert(circuit
!= NULL
);
533 assert(circuit
->interface
== ifp
);
534 assert(ifp
->info
== circuit
);
535 circuit
->interface
= NULL
;
539 static void isis_circuit_update_all_srmflags(struct isis_circuit
*circuit
,
542 struct isis_area
*area
;
543 struct isis_lsp
*lsp
;
547 area
= circuit
->area
;
549 for (level
= ISIS_LEVEL1
; level
<= ISIS_LEVEL2
; level
++) {
550 if (!(level
& circuit
->is_type
))
553 if (!lspdb_count(&area
->lspdb
[level
- 1]))
556 frr_each (lspdb
, &area
->lspdb
[level
- 1], lsp
) {
558 isis_tx_queue_add(circuit
->tx_queue
, lsp
,
561 isis_tx_queue_del(circuit
->tx_queue
, lsp
);
567 size_t isis_circuit_pdu_size(struct isis_circuit
*circuit
)
569 return ISO_MTU(circuit
);
572 void isis_circuit_stream(struct isis_circuit
*circuit
, struct stream
**stream
)
574 size_t stream_size
= isis_circuit_pdu_size(circuit
);
577 *stream
= stream_new(stream_size
);
579 if (STREAM_SIZE(*stream
) != stream_size
)
580 stream_resize_inplace(stream
, stream_size
);
581 stream_reset(*stream
);
585 void isis_circuit_prepare(struct isis_circuit
*circuit
)
587 #if ISIS_METHOD != ISIS_METHOD_DLPI
588 thread_add_read(master
, isis_receive
, circuit
, circuit
->fd
,
591 thread_add_timer_msec(master
, isis_receive
, circuit
,
592 listcount(circuit
->area
->circuit_list
) * 100,
597 int isis_circuit_up(struct isis_circuit
*circuit
)
601 /* Set the flags for all the lsps of the circuit. */
602 isis_circuit_update_all_srmflags(circuit
, 1);
604 if (circuit
->state
== C_STATE_UP
)
607 if (circuit
->is_passive
)
610 if (circuit
->area
->lsp_mtu
> isis_circuit_pdu_size(circuit
)) {
613 "Interface MTU %zu on %s is too low to support area lsp mtu %u!",
614 isis_circuit_pdu_size(circuit
),
615 circuit
->interface
->name
, circuit
->area
->lsp_mtu
);
616 isis_circuit_update_all_srmflags(circuit
, 0);
620 if (circuit
->circ_type
== CIRCUIT_T_BROADCAST
) {
621 circuit
->circuit_id
= isis_circuit_id_gen(isis
, circuit
->interface
);
622 if (!circuit
->circuit_id
) {
625 "There are already 255 broadcast circuits active!");
630 * Get the Hardware Address
632 if (circuit
->interface
->hw_addr_len
!= ETH_ALEN
) {
633 zlog_warn("unsupported link layer");
635 memcpy(circuit
->u
.bc
.snpa
, circuit
->interface
->hw_addr
,
639 zlog_debug("isis_circuit_if_add: if_id %d, isomtu %d snpa %s",
640 circuit
->interface
->ifindex
, ISO_MTU(circuit
),
641 snpa_print(circuit
->u
.bc
.snpa
));
642 #endif /* EXTREME_DEBUG */
644 circuit
->u
.bc
.adjdb
[0] = list_new();
645 circuit
->u
.bc
.adjdb
[1] = list_new();
648 * ISO 10589 - 8.4.1 Enabling of broadcast circuits
651 /* initilizing the hello sending threads
655 /* 8.4.1 a) commence sending of IIH PDUs */
657 for (int level
= ISIS_LEVEL1
; level
<= ISIS_LEVEL2
; level
++) {
658 if (!(circuit
->is_type
& level
))
661 send_hello_sched(circuit
, level
, TRIGGERED_IIH_DELAY
);
662 circuit
->u
.bc
.lan_neighs
[level
- 1] = list_new();
664 thread_add_timer(master
, isis_run_dr
,
665 &circuit
->level_arg
[level
- 1],
666 2 * circuit
->hello_interval
[level
- 1],
667 &circuit
->u
.bc
.t_run_dr
[level
- 1]);
670 /* 8.4.1 b) FIXME: solicit ES - 8.4.6 */
671 /* 8.4.1 c) FIXME: listen for ESH PDUs */
672 } else if (circuit
->circ_type
== CIRCUIT_T_P2P
) {
673 /* initializing the hello send threads
676 circuit
->u
.p2p
.neighbor
= NULL
;
677 send_hello_sched(circuit
, 0, TRIGGERED_IIH_DELAY
);
680 /* initializing PSNP timers */
681 if (circuit
->is_type
& IS_LEVEL_1
)
683 master
, send_l1_psnp
, circuit
,
684 isis_jitter(circuit
->psnp_interval
[0], PSNP_JITTER
),
685 &circuit
->t_send_psnp
[0]);
687 if (circuit
->is_type
& IS_LEVEL_2
)
689 master
, send_l2_psnp
, circuit
,
690 isis_jitter(circuit
->psnp_interval
[1], PSNP_JITTER
),
691 &circuit
->t_send_psnp
[1]);
693 /* unified init for circuits; ignore warnings below this level */
694 retv
= isis_sock_init(circuit
);
695 if (retv
!= ISIS_OK
) {
696 isis_circuit_down(circuit
);
700 /* initialize the circuit streams after opening connection */
701 isis_circuit_stream(circuit
, &circuit
->rcv_stream
);
702 isis_circuit_stream(circuit
, &circuit
->snd_stream
);
704 isis_circuit_prepare(circuit
);
706 circuit
->tx_queue
= isis_tx_queue_new(circuit
, send_lsp
);
709 /* send northbound notification */
710 isis_notif_if_state_change(circuit
, false);
711 #endif /* ifndef FABRICD */
716 void isis_circuit_down(struct isis_circuit
*circuit
)
719 /* send northbound notification */
720 isis_notif_if_state_change(circuit
, true);
721 #endif /* ifndef FABRICD */
723 /* Clear the flags for all the lsps of the circuit. */
724 isis_circuit_update_all_srmflags(circuit
, 0);
726 if (circuit
->circ_type
== CIRCUIT_T_BROADCAST
) {
727 /* destroy neighbour lists */
728 if (circuit
->u
.bc
.lan_neighs
[0]) {
729 list_delete(&circuit
->u
.bc
.lan_neighs
[0]);
730 circuit
->u
.bc
.lan_neighs
[0] = NULL
;
732 if (circuit
->u
.bc
.lan_neighs
[1]) {
733 list_delete(&circuit
->u
.bc
.lan_neighs
[1]);
734 circuit
->u
.bc
.lan_neighs
[1] = NULL
;
736 /* destroy adjacency databases */
737 if (circuit
->u
.bc
.adjdb
[0]) {
738 circuit
->u
.bc
.adjdb
[0]->del
= isis_delete_adj
;
739 list_delete(&circuit
->u
.bc
.adjdb
[0]);
740 circuit
->u
.bc
.adjdb
[0] = NULL
;
742 if (circuit
->u
.bc
.adjdb
[1]) {
743 circuit
->u
.bc
.adjdb
[1]->del
= isis_delete_adj
;
744 list_delete(&circuit
->u
.bc
.adjdb
[1]);
745 circuit
->u
.bc
.adjdb
[1] = NULL
;
747 if (circuit
->u
.bc
.is_dr
[0]) {
748 isis_dr_resign(circuit
, 1);
749 circuit
->u
.bc
.is_dr
[0] = 0;
751 memset(circuit
->u
.bc
.l1_desig_is
, 0, ISIS_SYS_ID_LEN
+ 1);
752 if (circuit
->u
.bc
.is_dr
[1]) {
753 isis_dr_resign(circuit
, 2);
754 circuit
->u
.bc
.is_dr
[1] = 0;
756 memset(circuit
->u
.bc
.l2_desig_is
, 0, ISIS_SYS_ID_LEN
+ 1);
757 memset(circuit
->u
.bc
.snpa
, 0, ETH_ALEN
);
759 THREAD_TIMER_OFF(circuit
->u
.bc
.t_send_lan_hello
[0]);
760 THREAD_TIMER_OFF(circuit
->u
.bc
.t_send_lan_hello
[1]);
761 THREAD_TIMER_OFF(circuit
->u
.bc
.t_run_dr
[0]);
762 THREAD_TIMER_OFF(circuit
->u
.bc
.t_run_dr
[1]);
763 THREAD_TIMER_OFF(circuit
->u
.bc
.t_refresh_pseudo_lsp
[0]);
764 THREAD_TIMER_OFF(circuit
->u
.bc
.t_refresh_pseudo_lsp
[1]);
765 circuit
->lsp_regenerate_pending
[0] = 0;
766 circuit
->lsp_regenerate_pending
[1] = 0;
768 _ISIS_CLEAR_FLAG(isis
->circuit_ids_used
, circuit
->circuit_id
);
769 circuit
->circuit_id
= 0;
770 } else if (circuit
->circ_type
== CIRCUIT_T_P2P
) {
771 isis_delete_adj(circuit
->u
.p2p
.neighbor
);
772 circuit
->u
.p2p
.neighbor
= NULL
;
773 THREAD_TIMER_OFF(circuit
->u
.p2p
.t_send_p2p_hello
);
776 /* Cancel all active threads */
777 THREAD_TIMER_OFF(circuit
->t_send_csnp
[0]);
778 THREAD_TIMER_OFF(circuit
->t_send_csnp
[1]);
779 THREAD_TIMER_OFF(circuit
->t_send_psnp
[0]);
780 THREAD_TIMER_OFF(circuit
->t_send_psnp
[1]);
781 THREAD_OFF(circuit
->t_read
);
783 if (circuit
->tx_queue
) {
784 isis_tx_queue_free(circuit
->tx_queue
);
785 circuit
->tx_queue
= NULL
;
788 /* send one gratuitous hello to spead up convergence */
789 if (circuit
->state
== C_STATE_UP
) {
790 if (circuit
->is_type
& IS_LEVEL_1
)
791 send_hello(circuit
, IS_LEVEL_1
);
792 if (circuit
->is_type
& IS_LEVEL_2
)
793 send_hello(circuit
, IS_LEVEL_2
);
796 circuit
->upadjcount
[0] = 0;
797 circuit
->upadjcount
[1] = 0;
799 /* close the socket */
805 if (circuit
->rcv_stream
!= NULL
) {
806 stream_free(circuit
->rcv_stream
);
807 circuit
->rcv_stream
= NULL
;
810 if (circuit
->snd_stream
!= NULL
) {
811 stream_free(circuit
->snd_stream
);
812 circuit
->snd_stream
= NULL
;
815 thread_cancel_event(master
, circuit
);
820 void circuit_update_nlpids(struct isis_circuit
*circuit
)
822 circuit
->nlpids
.count
= 0;
824 if (circuit
->ip_router
) {
825 circuit
->nlpids
.nlpids
[0] = NLPID_IP
;
826 circuit
->nlpids
.count
++;
828 if (circuit
->ipv6_router
) {
829 circuit
->nlpids
.nlpids
[circuit
->nlpids
.count
] = NLPID_IPV6
;
830 circuit
->nlpids
.count
++;
835 void isis_circuit_print_vty(struct isis_circuit
*circuit
, struct vty
*vty
,
838 if (detail
== ISIS_UI_LEVEL_BRIEF
) {
839 vty_out(vty
, " %-12s", circuit
->interface
->name
);
840 vty_out(vty
, "0x%-7x", circuit
->circuit_id
);
841 vty_out(vty
, "%-9s", circuit_state2string(circuit
->state
));
842 vty_out(vty
, "%-9s", circuit_type2string(circuit
->circ_type
));
843 vty_out(vty
, "%-9s", circuit_t2string(circuit
->is_type
));
847 if (detail
== ISIS_UI_LEVEL_DETAIL
) {
848 struct listnode
*node
;
849 struct prefix
*ip_addr
;
852 vty_out(vty
, " Interface: %s", circuit
->interface
->name
);
853 vty_out(vty
, ", State: %s",
854 circuit_state2string(circuit
->state
));
855 if (circuit
->is_passive
)
856 vty_out(vty
, ", Passive");
858 vty_out(vty
, ", Active");
859 vty_out(vty
, ", Circuit Id: 0x%x", circuit
->circuit_id
);
861 vty_out(vty
, " Type: %s",
862 circuit_type2string(circuit
->circ_type
));
863 vty_out(vty
, ", Level: %s", circuit_t2string(circuit
->is_type
));
864 if (circuit
->circ_type
== CIRCUIT_T_BROADCAST
)
865 vty_out(vty
, ", SNPA: %-10s",
866 snpa_print(circuit
->u
.bc
.snpa
));
868 if (circuit
->is_type
& IS_LEVEL_1
) {
869 vty_out(vty
, " Level-1 Information:\n");
870 if (circuit
->area
->newmetric
)
871 vty_out(vty
, " Metric: %d",
872 circuit
->te_metric
[0]);
874 vty_out(vty
, " Metric: %d",
876 if (!circuit
->is_passive
) {
877 vty_out(vty
, ", Active neighbors: %u\n",
878 circuit
->upadjcount
[0]);
880 " Hello interval: %u, "
881 "Holddown count: %u %s\n",
882 circuit
->hello_interval
[0],
883 circuit
->hello_multiplier
[0],
884 (circuit
->pad_hellos
? "(pad)"
887 " CNSP interval: %u, "
888 "PSNP interval: %u\n",
889 circuit
->csnp_interval
[0],
890 circuit
->psnp_interval
[0]);
891 if (circuit
->circ_type
== CIRCUIT_T_BROADCAST
)
893 " LAN Priority: %u, %s\n",
894 circuit
->priority
[0],
895 (circuit
->u
.bc
.is_dr
[0]
902 if (circuit
->is_type
& IS_LEVEL_2
) {
903 vty_out(vty
, " Level-2 Information:\n");
904 if (circuit
->area
->newmetric
)
905 vty_out(vty
, " Metric: %d",
906 circuit
->te_metric
[1]);
908 vty_out(vty
, " Metric: %d",
910 if (!circuit
->is_passive
) {
911 vty_out(vty
, ", Active neighbors: %u\n",
912 circuit
->upadjcount
[1]);
914 " Hello interval: %u, "
915 "Holddown count: %u %s\n",
916 circuit
->hello_interval
[1],
917 circuit
->hello_multiplier
[1],
918 (circuit
->pad_hellos
? "(pad)"
921 " CNSP interval: %u, "
922 "PSNP interval: %u\n",
923 circuit
->csnp_interval
[1],
924 circuit
->psnp_interval
[1]);
925 if (circuit
->circ_type
== CIRCUIT_T_BROADCAST
)
927 " LAN Priority: %u, %s\n",
928 circuit
->priority
[1],
929 (circuit
->u
.bc
.is_dr
[1]
936 if (circuit
->ip_addrs
&& listcount(circuit
->ip_addrs
) > 0) {
937 vty_out(vty
, " IP Prefix(es):\n");
938 for (ALL_LIST_ELEMENTS_RO(circuit
->ip_addrs
, node
,
940 prefix2str(ip_addr
, buf
, sizeof(buf
));
941 vty_out(vty
, " %s\n", buf
);
944 if (circuit
->ipv6_link
&& listcount(circuit
->ipv6_link
) > 0) {
945 vty_out(vty
, " IPv6 Link-Locals:\n");
946 for (ALL_LIST_ELEMENTS_RO(circuit
->ipv6_link
, node
,
948 prefix2str(ip_addr
, (char *)buf
, BUFSIZ
);
949 vty_out(vty
, " %s\n", buf
);
952 if (circuit
->ipv6_non_link
953 && listcount(circuit
->ipv6_non_link
) > 0) {
954 vty_out(vty
, " IPv6 Prefixes:\n");
955 for (ALL_LIST_ELEMENTS_RO(circuit
->ipv6_non_link
, node
,
957 prefix2str(ip_addr
, (char *)buf
, BUFSIZ
);
958 vty_out(vty
, " %s\n", buf
);
967 DEFINE_HOOK(isis_circuit_config_write
,
968 (struct isis_circuit
*circuit
, struct vty
*vty
),
972 int isis_interface_config_write(struct vty
*vty
)
974 struct vrf
*vrf
= vrf_lookup_by_id(VRF_DEFAULT
);
976 struct listnode
*node
;
977 struct interface
*ifp
;
978 struct isis_area
*area
;
979 struct isis_circuit
*circuit
;
982 FOR_ALL_INTERFACES (vrf
, ifp
) {
984 vty_frame(vty
, "interface %s\n", ifp
->name
);
988 vty_out(vty
, " description %s\n", ifp
->desc
);
992 for (ALL_LIST_ELEMENTS_RO(isis
->area_list
, node
, area
)) {
994 circuit_lookup_by_ifp(ifp
, area
->circuit_list
);
997 if (circuit
->ip_router
) {
998 vty_out(vty
, " ip router " PROTO_NAME
" %s\n",
1002 if (circuit
->is_passive
) {
1003 vty_out(vty
, " " PROTO_NAME
" passive\n");
1006 if (circuit
->circ_type_config
== CIRCUIT_T_P2P
) {
1007 vty_out(vty
, " " PROTO_NAME
" network point-to-point\n");
1010 if (circuit
->ipv6_router
) {
1011 vty_out(vty
, " ipv6 router " PROTO_NAME
" %s\n",
1016 /* ISIS - circuit type */
1018 if (circuit
->is_type
== IS_LEVEL_1
) {
1019 vty_out(vty
, " " PROTO_NAME
" circuit-type level-1\n");
1022 if (circuit
->is_type
== IS_LEVEL_2
) {
1024 " " PROTO_NAME
" circuit-type level-2-only\n");
1030 /* ISIS - CSNP interval */
1031 if (circuit
->csnp_interval
[0]
1032 == circuit
->csnp_interval
[1]) {
1033 if (circuit
->csnp_interval
[0]
1034 != DEFAULT_CSNP_INTERVAL
) {
1035 vty_out(vty
, " " PROTO_NAME
" csnp-interval %d\n",
1036 circuit
->csnp_interval
[0]);
1040 for (i
= 0; i
< 2; i
++) {
1041 if (circuit
->csnp_interval
[i
]
1042 != DEFAULT_CSNP_INTERVAL
) {
1044 " " PROTO_NAME
" csnp-interval %d level-%d\n",
1045 circuit
->csnp_interval
1053 /* ISIS - PSNP interval */
1054 if (circuit
->psnp_interval
[0]
1055 == circuit
->psnp_interval
[1]) {
1056 if (circuit
->psnp_interval
[0]
1057 != DEFAULT_PSNP_INTERVAL
) {
1058 vty_out(vty
, " " PROTO_NAME
" psnp-interval %d\n",
1059 circuit
->psnp_interval
[0]);
1063 for (i
= 0; i
< 2; i
++) {
1064 if (circuit
->psnp_interval
[i
]
1065 != DEFAULT_PSNP_INTERVAL
) {
1067 " " PROTO_NAME
" psnp-interval %d level-%d\n",
1068 circuit
->psnp_interval
1076 /* ISIS - Hello padding - Defaults to true so only
1077 * display if false */
1078 if (circuit
->pad_hellos
== 0) {
1079 vty_out(vty
, " no " PROTO_NAME
" hello padding\n");
1083 if (circuit
->disable_threeway_adj
) {
1084 vty_out(vty
, " no isis three-way-handshake\n");
1088 /* ISIS - Hello interval */
1089 if (circuit
->hello_interval
[0]
1090 == circuit
->hello_interval
[1]) {
1091 if (circuit
->hello_interval
[0]
1092 != DEFAULT_HELLO_INTERVAL
) {
1094 " " PROTO_NAME
" hello-interval %d\n",
1095 circuit
->hello_interval
[0]);
1099 for (i
= 0; i
< 2; i
++) {
1100 if (circuit
->hello_interval
[i
]
1101 != DEFAULT_HELLO_INTERVAL
) {
1103 " " PROTO_NAME
" hello-interval %d level-%d\n",
1104 circuit
->hello_interval
1112 /* ISIS - Hello Multiplier */
1113 if (circuit
->hello_multiplier
[0]
1114 == circuit
->hello_multiplier
[1]) {
1115 if (circuit
->hello_multiplier
[0]
1116 != DEFAULT_HELLO_MULTIPLIER
) {
1118 " " PROTO_NAME
" hello-multiplier %d\n",
1119 circuit
->hello_multiplier
[0]);
1123 for (i
= 0; i
< 2; i
++) {
1124 if (circuit
->hello_multiplier
[i
]
1125 != DEFAULT_HELLO_MULTIPLIER
) {
1127 " " PROTO_NAME
" hello-multiplier %d level-%d\n",
1128 circuit
->hello_multiplier
1136 /* ISIS - Priority */
1137 if (circuit
->priority
[0] == circuit
->priority
[1]) {
1138 if (circuit
->priority
[0] != DEFAULT_PRIORITY
) {
1139 vty_out(vty
, " " PROTO_NAME
" priority %d\n",
1140 circuit
->priority
[0]);
1144 for (i
= 0; i
< 2; i
++) {
1145 if (circuit
->priority
[i
]
1146 != DEFAULT_PRIORITY
) {
1148 " " PROTO_NAME
" priority %d level-%d\n",
1149 circuit
->priority
[i
],
1157 if (circuit
->te_metric
[0] == circuit
->te_metric
[1]) {
1158 if (circuit
->te_metric
[0]
1159 != DEFAULT_CIRCUIT_METRIC
) {
1160 vty_out(vty
, " " PROTO_NAME
" metric %d\n",
1161 circuit
->te_metric
[0]);
1165 for (i
= 0; i
< 2; i
++) {
1166 if (circuit
->te_metric
[i
]
1167 != DEFAULT_CIRCUIT_METRIC
) {
1169 " " PROTO_NAME
" metric %d level-%d\n",
1170 circuit
->te_metric
[i
],
1176 if (circuit
->passwd
.type
== ISIS_PASSWD_TYPE_HMAC_MD5
) {
1177 vty_out(vty
, " " PROTO_NAME
" password md5 %s\n",
1178 circuit
->passwd
.passwd
);
1180 } else if (circuit
->passwd
.type
1181 == ISIS_PASSWD_TYPE_CLEARTXT
) {
1182 vty_out(vty
, " " PROTO_NAME
" password clear %s\n",
1183 circuit
->passwd
.passwd
);
1186 write
+= hook_call(isis_circuit_config_write
,
1189 vty_endframe(vty
, "!\n");
1195 int isis_interface_config_write(struct vty
*vty
)
1197 struct vrf
*vrf
= vrf_lookup_by_id(VRF_DEFAULT
);
1199 struct interface
*ifp
;
1200 struct isis_circuit
*circuit
;
1201 struct lyd_node
*dnode
;
1203 FOR_ALL_INTERFACES (vrf
, ifp
) {
1204 dnode
= yang_dnode_get(
1205 running_config
->dnode
,
1206 "/frr-interface:lib/interface[name='%s'][vrf='%s']",
1207 ifp
->name
, vrf
->name
);
1212 nb_cli_show_dnode_cmds(vty
, dnode
, false);
1213 circuit
= circuit_scan_by_ifp(ifp
);
1215 write
+= hook_call(isis_circuit_config_write
, circuit
,
1220 #endif /* ifdef FABRICD */
1222 struct isis_circuit
*isis_circuit_create(struct isis_area
*area
,
1223 struct interface
*ifp
)
1225 struct isis_circuit
*circuit
= circuit_scan_by_ifp(ifp
);
1226 if (circuit
&& circuit
->area
)
1228 circuit
= isis_csm_state_change(ISIS_ENABLE
, circuit
, area
);
1229 if (circuit
->state
!= C_STATE_CONF
&& circuit
->state
!= C_STATE_UP
)
1231 isis_circuit_if_bind(circuit
, ifp
);
1235 void isis_circuit_af_set(struct isis_circuit
*circuit
, bool ip_router
,
1238 struct isis_area
*area
= circuit
->area
;
1239 bool change
= circuit
->ip_router
!= ip_router
1240 || circuit
->ipv6_router
!= ipv6_router
;
1242 area
->ip_circuits
+= ip_router
- circuit
->ip_router
;
1243 area
->ipv6_circuits
+= ipv6_router
- circuit
->ipv6_router
;
1244 circuit
->ip_router
= ip_router
;
1245 circuit
->ipv6_router
= ipv6_router
;
1250 circuit_update_nlpids(circuit
);
1252 if (!ip_router
&& !ipv6_router
)
1253 isis_csm_state_change(ISIS_DISABLE
, circuit
, area
);
1255 lsp_regenerate_schedule(circuit
->area
, circuit
->is_type
, 0);
1258 ferr_r
isis_circuit_passive_set(struct isis_circuit
*circuit
, bool passive
)
1260 if (circuit
->is_passive
== passive
)
1263 if (if_is_loopback(circuit
->interface
) && !passive
)
1264 return ferr_cfg_invalid("loopback is always passive");
1266 if (circuit
->state
!= C_STATE_UP
) {
1267 circuit
->is_passive
= passive
;
1269 struct isis_area
*area
= circuit
->area
;
1270 isis_csm_state_change(ISIS_DISABLE
, circuit
, area
);
1271 circuit
->is_passive
= passive
;
1272 isis_csm_state_change(ISIS_ENABLE
, circuit
, area
);
1278 ferr_r
isis_circuit_metric_set(struct isis_circuit
*circuit
, int level
,
1281 assert(level
== IS_LEVEL_1
|| level
== IS_LEVEL_2
);
1282 if (metric
> MAX_WIDE_LINK_METRIC
)
1283 return ferr_cfg_invalid("metric %d too large for wide metric",
1285 if (circuit
->area
&& circuit
->area
->oldmetric
1286 && metric
> MAX_NARROW_LINK_METRIC
)
1287 return ferr_cfg_invalid("metric %d too large for narrow metric",
1290 circuit
->te_metric
[level
- 1] = metric
;
1291 circuit
->metric
[level
- 1] = metric
;
1294 lsp_regenerate_schedule(circuit
->area
, level
, 0);
1298 ferr_r
isis_circuit_passwd_unset(struct isis_circuit
*circuit
)
1300 memset(&circuit
->passwd
, 0, sizeof(circuit
->passwd
));
1304 ferr_r
isis_circuit_passwd_set(struct isis_circuit
*circuit
,
1305 uint8_t passwd_type
, const char *passwd
)
1310 return ferr_code_bug("no circuit password given");
1312 len
= strlen(passwd
);
1314 return ferr_code_bug(
1315 "circuit password too long (max 254 chars)");
1317 circuit
->passwd
.len
= len
;
1318 strlcpy((char *)circuit
->passwd
.passwd
, passwd
,
1319 sizeof(circuit
->passwd
.passwd
));
1320 circuit
->passwd
.type
= passwd_type
;
1324 ferr_r
isis_circuit_passwd_cleartext_set(struct isis_circuit
*circuit
,
1327 return isis_circuit_passwd_set(circuit
, ISIS_PASSWD_TYPE_CLEARTXT
,
1331 ferr_r
isis_circuit_passwd_hmac_md5_set(struct isis_circuit
*circuit
,
1334 return isis_circuit_passwd_set(circuit
, ISIS_PASSWD_TYPE_HMAC_MD5
,
1338 struct cmd_node interface_node
= {
1339 INTERFACE_NODE
, "%s(config-if)# ", 1,
1342 void isis_circuit_circ_type_set(struct isis_circuit
*circuit
, int circ_type
)
1344 if (circuit
->circ_type
== circ_type
)
1347 if (circuit
->state
!= C_STATE_UP
) {
1348 circuit
->circ_type
= circ_type
;
1349 circuit
->circ_type_config
= circ_type
;
1351 struct isis_area
*area
= circuit
->area
;
1353 isis_csm_state_change(ISIS_DISABLE
, circuit
, area
);
1354 circuit
->circ_type
= circ_type
;
1355 circuit
->circ_type_config
= circ_type
;
1356 isis_csm_state_change(ISIS_ENABLE
, circuit
, area
);
1360 int isis_circuit_mt_enabled_set(struct isis_circuit
*circuit
, uint16_t mtid
,
1363 struct isis_circuit_mt_setting
*setting
;
1365 setting
= circuit_get_mt_setting(circuit
, mtid
);
1366 if (setting
->enabled
!= enabled
) {
1367 setting
->enabled
= enabled
;
1368 lsp_regenerate_schedule(circuit
->area
, IS_LEVEL_1
| IS_LEVEL_2
,
1375 int isis_if_new_hook(struct interface
*ifp
)
1380 int isis_if_delete_hook(struct interface
*ifp
)
1382 struct isis_circuit
*circuit
;
1383 /* Clean up the circuit data */
1384 if (ifp
&& ifp
->info
) {
1385 circuit
= ifp
->info
;
1386 isis_csm_state_change(IF_DOWN_FROM_Z
, circuit
, circuit
->area
);
1392 static int isis_ifp_create(struct interface
*ifp
)
1394 if (if_is_operative(ifp
))
1395 isis_csm_state_change(IF_UP_FROM_Z
, circuit_scan_by_ifp(ifp
),
1398 hook_call(isis_if_new_hook
, ifp
);
1403 static int isis_ifp_up(struct interface
*ifp
)
1405 isis_csm_state_change(IF_UP_FROM_Z
, circuit_scan_by_ifp(ifp
), ifp
);
1410 static int isis_ifp_down(struct interface
*ifp
)
1412 struct isis_circuit
*circuit
;
1414 circuit
= isis_csm_state_change(IF_DOWN_FROM_Z
,
1415 circuit_scan_by_ifp(ifp
), ifp
);
1417 SET_FLAG(circuit
->flags
, ISIS_CIRCUIT_FLAPPED_AFTER_SPF
);
1422 static int isis_ifp_destroy(struct interface
*ifp
)
1424 if (if_is_operative(ifp
))
1425 zlog_warn("Zebra: got delete of %s, but interface is still up",
1428 isis_csm_state_change(IF_DOWN_FROM_Z
, circuit_scan_by_ifp(ifp
), ifp
);
1430 /* Cannot call if_delete because we should retain the pseudo interface
1431 in case there is configuration info attached to it. */
1432 if_delete_retain(ifp
);
1437 void isis_circuit_init(void)
1439 /* Initialize Zebra interface data structure */
1440 hook_register_prio(if_add
, 0, isis_if_new_hook
);
1441 hook_register_prio(if_del
, 0, isis_if_delete_hook
);
1443 /* Install interface node */
1444 install_node(&interface_node
, isis_interface_config_write
);
1446 if_zapi_callbacks(isis_ifp_create
, isis_ifp_up
,
1447 isis_ifp_down
, isis_ifp_destroy
);