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 \
350 buf
, circuit
->interface
->name
);
351 zlog_warn("Current ip addresses on %s:",
352 circuit
->interface
->name
);
353 for (ALL_LIST_ELEMENTS_RO(circuit
->ip_addrs
, node
,
355 prefix2str(ip
, buf
, sizeof(buf
));
356 zlog_warn(" %s", buf
);
358 zlog_warn("End of addresses");
361 prefix_ipv4_free(ipv4
);
363 if (connected
->address
->family
== AF_INET6
) {
364 ipv6
= prefix_ipv6_new();
365 ipv6
->prefixlen
= connected
->address
->prefixlen
;
366 ipv6
->prefix
= connected
->address
->u
.prefix6
;
368 if (IN6_IS_ADDR_LINKLOCAL(&ipv6
->prefix
)) {
369 for (ALL_LIST_ELEMENTS_RO(circuit
->ipv6_link
, node
,
371 if (prefix_same((struct prefix
*)ip6
,
372 (struct prefix
*)ipv6
))
376 listnode_delete(circuit
->ipv6_link
, ip6
);
377 prefix_ipv6_free(ip6
);
381 for (ALL_LIST_ELEMENTS_RO(circuit
->ipv6_non_link
, node
,
383 if (prefix_same((struct prefix
*)ip6
,
384 (struct prefix
*)ipv6
))
388 listnode_delete(circuit
->ipv6_non_link
, ip6
);
389 prefix_ipv6_free(ip6
);
395 prefix2str(connected
->address
, buf
, sizeof(buf
));
397 "Nonexistent ip address %s removal attempt from \
399 buf
, circuit
->interface
->name
);
400 zlog_warn("Current ip addresses on %s:",
401 circuit
->interface
->name
);
402 for (ALL_LIST_ELEMENTS_RO(circuit
->ipv6_link
, node
,
404 prefix2str((struct prefix
*)ip6
, (char *)buf
,
406 zlog_warn(" %s", buf
);
409 for (ALL_LIST_ELEMENTS_RO(circuit
->ipv6_non_link
, node
,
411 prefix2str((struct prefix
*)ip6
, (char *)buf
,
413 zlog_warn(" %s", buf
);
415 zlog_warn("End of addresses");
416 } else if (circuit
->area
)
417 lsp_regenerate_schedule(circuit
->area
, circuit
->is_type
,
420 prefix_ipv6_free(ipv6
);
425 static uint8_t isis_circuit_id_gen(struct isis
*isis
, struct interface
*ifp
)
427 /* Circuit ids MUST be unique for any broadcast circuits. Otherwise,
428 * Pseudo-Node LSPs cannot be generated correctly.
430 * Currently, allocate one circuit ID for any circuit, limiting the total
431 * numer of circuits IS-IS can run on to 255.
433 * We should revisit this when implementing 3-way adjacencies for p2p, since
434 * we then have extended interface IDs available.
436 uint8_t id
= ifp
->ifindex
;
439 for (i
= 0; i
< 256; i
++) {
440 if (id
&& !_ISIS_CHECK_FLAG(isis
->circuit_ids_used
, id
))
446 zlog_warn("Could not allocate a circuit id for '%s'",
451 _ISIS_SET_FLAG(isis
->circuit_ids_used
, id
);
455 void isis_circuit_if_add(struct isis_circuit
*circuit
, struct interface
*ifp
)
457 struct listnode
*node
, *nnode
;
458 struct connected
*conn
;
460 isis_circuit_if_bind(circuit
, ifp
);
462 if (if_is_broadcast(ifp
)) {
463 if (fabricd
|| circuit
->circ_type_config
== CIRCUIT_T_P2P
)
464 circuit
->circ_type
= CIRCUIT_T_P2P
;
466 circuit
->circ_type
= CIRCUIT_T_BROADCAST
;
467 } else if (if_is_pointopoint(ifp
)) {
468 circuit
->circ_type
= CIRCUIT_T_P2P
;
469 } else if (if_is_loopback(ifp
)) {
470 circuit
->circ_type
= CIRCUIT_T_LOOPBACK
;
471 circuit
->is_passive
= 1;
473 /* It's normal in case of loopback etc. */
474 if (isis
->debugs
& DEBUG_EVENTS
)
475 zlog_debug("isis_circuit_if_add: unsupported media");
476 circuit
->circ_type
= CIRCUIT_T_UNKNOWN
;
479 circuit
->ip_addrs
= list_new();
480 circuit
->ipv6_link
= list_new();
481 circuit
->ipv6_non_link
= list_new();
483 for (ALL_LIST_ELEMENTS(ifp
->connected
, node
, nnode
, conn
))
484 isis_circuit_add_addr(circuit
, conn
);
488 void isis_circuit_if_del(struct isis_circuit
*circuit
, struct interface
*ifp
)
490 struct listnode
*node
, *nnode
;
491 struct connected
*conn
;
493 assert(circuit
->interface
== ifp
);
495 /* destroy addresses */
496 for (ALL_LIST_ELEMENTS(ifp
->connected
, node
, nnode
, conn
))
497 isis_circuit_del_addr(circuit
, conn
);
499 if (circuit
->ip_addrs
) {
500 assert(listcount(circuit
->ip_addrs
) == 0);
501 list_delete(&circuit
->ip_addrs
);
504 if (circuit
->ipv6_link
) {
505 assert(listcount(circuit
->ipv6_link
) == 0);
506 list_delete(&circuit
->ipv6_link
);
509 if (circuit
->ipv6_non_link
) {
510 assert(listcount(circuit
->ipv6_non_link
) == 0);
511 list_delete(&circuit
->ipv6_non_link
);
514 circuit
->circ_type
= CIRCUIT_T_UNKNOWN
;
517 void isis_circuit_if_bind(struct isis_circuit
*circuit
, struct interface
*ifp
)
519 assert(circuit
!= NULL
);
521 if (circuit
->interface
)
522 assert(circuit
->interface
== ifp
);
524 circuit
->interface
= ifp
;
526 assert(ifp
->info
== circuit
);
531 void isis_circuit_if_unbind(struct isis_circuit
*circuit
, struct interface
*ifp
)
533 assert(circuit
!= NULL
);
535 assert(circuit
->interface
== ifp
);
536 assert(ifp
->info
== circuit
);
537 circuit
->interface
= NULL
;
541 static void isis_circuit_update_all_srmflags(struct isis_circuit
*circuit
,
544 struct isis_area
*area
;
545 struct isis_lsp
*lsp
;
549 area
= circuit
->area
;
551 for (level
= ISIS_LEVEL1
; level
<= ISIS_LEVEL2
; level
++) {
552 if (!(level
& circuit
->is_type
))
555 if (!lspdb_count(&area
->lspdb
[level
- 1]))
558 frr_each (lspdb
, &area
->lspdb
[level
- 1], lsp
) {
560 isis_tx_queue_add(circuit
->tx_queue
, lsp
,
563 isis_tx_queue_del(circuit
->tx_queue
, lsp
);
569 size_t isis_circuit_pdu_size(struct isis_circuit
*circuit
)
571 return ISO_MTU(circuit
);
574 void isis_circuit_stream(struct isis_circuit
*circuit
, struct stream
**stream
)
576 size_t stream_size
= isis_circuit_pdu_size(circuit
);
579 *stream
= stream_new(stream_size
);
581 if (STREAM_SIZE(*stream
) != stream_size
)
582 stream_resize_inplace(stream
, stream_size
);
583 stream_reset(*stream
);
587 void isis_circuit_prepare(struct isis_circuit
*circuit
)
589 #if ISIS_METHOD != ISIS_METHOD_DLPI
590 thread_add_read(master
, isis_receive
, circuit
, circuit
->fd
,
593 thread_add_timer_msec(master
, isis_receive
, circuit
,
594 listcount(circuit
->area
->circuit_list
) * 100,
599 int isis_circuit_up(struct isis_circuit
*circuit
)
603 /* Set the flags for all the lsps of the circuit. */
604 isis_circuit_update_all_srmflags(circuit
, 1);
606 if (circuit
->state
== C_STATE_UP
)
609 if (circuit
->is_passive
)
612 if (circuit
->area
->lsp_mtu
> isis_circuit_pdu_size(circuit
)) {
615 "Interface MTU %zu on %s is too low to support area lsp mtu %u!",
616 isis_circuit_pdu_size(circuit
),
617 circuit
->interface
->name
, circuit
->area
->lsp_mtu
);
618 isis_circuit_update_all_srmflags(circuit
, 0);
622 if (circuit
->circ_type
== CIRCUIT_T_BROADCAST
) {
623 circuit
->circuit_id
= isis_circuit_id_gen(isis
, circuit
->interface
);
624 if (!circuit
->circuit_id
) {
627 "There are already 255 broadcast circuits active!");
632 * Get the Hardware Address
634 if (circuit
->interface
->hw_addr_len
!= ETH_ALEN
) {
635 zlog_warn("unsupported link layer");
637 memcpy(circuit
->u
.bc
.snpa
, circuit
->interface
->hw_addr
,
641 zlog_debug("isis_circuit_if_add: if_id %d, isomtu %d snpa %s",
642 circuit
->interface
->ifindex
, ISO_MTU(circuit
),
643 snpa_print(circuit
->u
.bc
.snpa
));
644 #endif /* EXTREME_DEBUG */
646 circuit
->u
.bc
.adjdb
[0] = list_new();
647 circuit
->u
.bc
.adjdb
[1] = list_new();
650 * ISO 10589 - 8.4.1 Enabling of broadcast circuits
653 /* initilizing the hello sending threads
657 /* 8.4.1 a) commence sending of IIH PDUs */
659 for (int level
= ISIS_LEVEL1
; level
<= ISIS_LEVEL2
; level
++) {
660 if (!(circuit
->is_type
& level
))
663 send_hello_sched(circuit
, level
, TRIGGERED_IIH_DELAY
);
664 circuit
->u
.bc
.lan_neighs
[level
- 1] = list_new();
666 thread_add_timer(master
, isis_run_dr
,
667 &circuit
->level_arg
[level
- 1],
668 2 * circuit
->hello_interval
[level
- 1],
669 &circuit
->u
.bc
.t_run_dr
[level
- 1]);
672 /* 8.4.1 b) FIXME: solicit ES - 8.4.6 */
673 /* 8.4.1 c) FIXME: listen for ESH PDUs */
674 } else if (circuit
->circ_type
== CIRCUIT_T_P2P
) {
675 /* initializing the hello send threads
678 circuit
->u
.p2p
.neighbor
= NULL
;
679 send_hello_sched(circuit
, 0, TRIGGERED_IIH_DELAY
);
682 /* initializing PSNP timers */
683 if (circuit
->is_type
& IS_LEVEL_1
)
685 master
, send_l1_psnp
, circuit
,
686 isis_jitter(circuit
->psnp_interval
[0], PSNP_JITTER
),
687 &circuit
->t_send_psnp
[0]);
689 if (circuit
->is_type
& IS_LEVEL_2
)
691 master
, send_l2_psnp
, circuit
,
692 isis_jitter(circuit
->psnp_interval
[1], PSNP_JITTER
),
693 &circuit
->t_send_psnp
[1]);
695 /* unified init for circuits; ignore warnings below this level */
696 retv
= isis_sock_init(circuit
);
697 if (retv
!= ISIS_OK
) {
698 isis_circuit_down(circuit
);
702 /* initialize the circuit streams after opening connection */
703 isis_circuit_stream(circuit
, &circuit
->rcv_stream
);
704 isis_circuit_stream(circuit
, &circuit
->snd_stream
);
706 isis_circuit_prepare(circuit
);
708 circuit
->tx_queue
= isis_tx_queue_new(circuit
, send_lsp
);
711 /* send northbound notification */
712 isis_notif_if_state_change(circuit
, false);
713 #endif /* ifndef FABRICD */
718 void isis_circuit_down(struct isis_circuit
*circuit
)
721 /* send northbound notification */
722 isis_notif_if_state_change(circuit
, true);
723 #endif /* ifndef FABRICD */
725 /* Clear the flags for all the lsps of the circuit. */
726 isis_circuit_update_all_srmflags(circuit
, 0);
728 if (circuit
->circ_type
== CIRCUIT_T_BROADCAST
) {
729 /* destroy neighbour lists */
730 if (circuit
->u
.bc
.lan_neighs
[0]) {
731 list_delete(&circuit
->u
.bc
.lan_neighs
[0]);
732 circuit
->u
.bc
.lan_neighs
[0] = NULL
;
734 if (circuit
->u
.bc
.lan_neighs
[1]) {
735 list_delete(&circuit
->u
.bc
.lan_neighs
[1]);
736 circuit
->u
.bc
.lan_neighs
[1] = NULL
;
738 /* destroy adjacency databases */
739 if (circuit
->u
.bc
.adjdb
[0]) {
740 circuit
->u
.bc
.adjdb
[0]->del
= isis_delete_adj
;
741 list_delete(&circuit
->u
.bc
.adjdb
[0]);
742 circuit
->u
.bc
.adjdb
[0] = NULL
;
744 if (circuit
->u
.bc
.adjdb
[1]) {
745 circuit
->u
.bc
.adjdb
[1]->del
= isis_delete_adj
;
746 list_delete(&circuit
->u
.bc
.adjdb
[1]);
747 circuit
->u
.bc
.adjdb
[1] = NULL
;
749 if (circuit
->u
.bc
.is_dr
[0]) {
750 isis_dr_resign(circuit
, 1);
751 circuit
->u
.bc
.is_dr
[0] = 0;
753 memset(circuit
->u
.bc
.l1_desig_is
, 0, ISIS_SYS_ID_LEN
+ 1);
754 if (circuit
->u
.bc
.is_dr
[1]) {
755 isis_dr_resign(circuit
, 2);
756 circuit
->u
.bc
.is_dr
[1] = 0;
758 memset(circuit
->u
.bc
.l2_desig_is
, 0, ISIS_SYS_ID_LEN
+ 1);
759 memset(circuit
->u
.bc
.snpa
, 0, ETH_ALEN
);
761 THREAD_TIMER_OFF(circuit
->u
.bc
.t_send_lan_hello
[0]);
762 THREAD_TIMER_OFF(circuit
->u
.bc
.t_send_lan_hello
[1]);
763 THREAD_TIMER_OFF(circuit
->u
.bc
.t_run_dr
[0]);
764 THREAD_TIMER_OFF(circuit
->u
.bc
.t_run_dr
[1]);
765 THREAD_TIMER_OFF(circuit
->u
.bc
.t_refresh_pseudo_lsp
[0]);
766 THREAD_TIMER_OFF(circuit
->u
.bc
.t_refresh_pseudo_lsp
[1]);
767 circuit
->lsp_regenerate_pending
[0] = 0;
768 circuit
->lsp_regenerate_pending
[1] = 0;
770 _ISIS_CLEAR_FLAG(isis
->circuit_ids_used
, circuit
->circuit_id
);
771 circuit
->circuit_id
= 0;
772 } else if (circuit
->circ_type
== CIRCUIT_T_P2P
) {
773 isis_delete_adj(circuit
->u
.p2p
.neighbor
);
774 circuit
->u
.p2p
.neighbor
= NULL
;
775 THREAD_TIMER_OFF(circuit
->u
.p2p
.t_send_p2p_hello
);
778 /* Cancel all active threads */
779 THREAD_TIMER_OFF(circuit
->t_send_csnp
[0]);
780 THREAD_TIMER_OFF(circuit
->t_send_csnp
[1]);
781 THREAD_TIMER_OFF(circuit
->t_send_psnp
[0]);
782 THREAD_TIMER_OFF(circuit
->t_send_psnp
[1]);
783 THREAD_OFF(circuit
->t_read
);
785 if (circuit
->tx_queue
) {
786 isis_tx_queue_free(circuit
->tx_queue
);
787 circuit
->tx_queue
= NULL
;
790 /* send one gratuitous hello to spead up convergence */
791 if (circuit
->state
== C_STATE_UP
) {
792 if (circuit
->is_type
& IS_LEVEL_1
)
793 send_hello(circuit
, IS_LEVEL_1
);
794 if (circuit
->is_type
& IS_LEVEL_2
)
795 send_hello(circuit
, IS_LEVEL_2
);
798 circuit
->upadjcount
[0] = 0;
799 circuit
->upadjcount
[1] = 0;
801 /* close the socket */
807 if (circuit
->rcv_stream
!= NULL
) {
808 stream_free(circuit
->rcv_stream
);
809 circuit
->rcv_stream
= NULL
;
812 if (circuit
->snd_stream
!= NULL
) {
813 stream_free(circuit
->snd_stream
);
814 circuit
->snd_stream
= NULL
;
817 thread_cancel_event(master
, circuit
);
822 void circuit_update_nlpids(struct isis_circuit
*circuit
)
824 circuit
->nlpids
.count
= 0;
826 if (circuit
->ip_router
) {
827 circuit
->nlpids
.nlpids
[0] = NLPID_IP
;
828 circuit
->nlpids
.count
++;
830 if (circuit
->ipv6_router
) {
831 circuit
->nlpids
.nlpids
[circuit
->nlpids
.count
] = NLPID_IPV6
;
832 circuit
->nlpids
.count
++;
837 void isis_circuit_print_vty(struct isis_circuit
*circuit
, struct vty
*vty
,
840 if (detail
== ISIS_UI_LEVEL_BRIEF
) {
841 vty_out(vty
, " %-12s", circuit
->interface
->name
);
842 vty_out(vty
, "0x%-7x", circuit
->circuit_id
);
843 vty_out(vty
, "%-9s", circuit_state2string(circuit
->state
));
844 vty_out(vty
, "%-9s", circuit_type2string(circuit
->circ_type
));
845 vty_out(vty
, "%-9s", circuit_t2string(circuit
->is_type
));
849 if (detail
== ISIS_UI_LEVEL_DETAIL
) {
850 struct listnode
*node
;
851 struct prefix
*ip_addr
;
854 vty_out(vty
, " Interface: %s", circuit
->interface
->name
);
855 vty_out(vty
, ", State: %s",
856 circuit_state2string(circuit
->state
));
857 if (circuit
->is_passive
)
858 vty_out(vty
, ", Passive");
860 vty_out(vty
, ", Active");
861 vty_out(vty
, ", Circuit Id: 0x%x", circuit
->circuit_id
);
863 vty_out(vty
, " Type: %s",
864 circuit_type2string(circuit
->circ_type
));
865 vty_out(vty
, ", Level: %s", circuit_t2string(circuit
->is_type
));
866 if (circuit
->circ_type
== CIRCUIT_T_BROADCAST
)
867 vty_out(vty
, ", SNPA: %-10s",
868 snpa_print(circuit
->u
.bc
.snpa
));
870 if (circuit
->is_type
& IS_LEVEL_1
) {
871 vty_out(vty
, " Level-1 Information:\n");
872 if (circuit
->area
->newmetric
)
873 vty_out(vty
, " Metric: %d",
874 circuit
->te_metric
[0]);
876 vty_out(vty
, " Metric: %d",
878 if (!circuit
->is_passive
) {
879 vty_out(vty
, ", Active neighbors: %u\n",
880 circuit
->upadjcount
[0]);
882 " Hello interval: %u, "
883 "Holddown count: %u %s\n",
884 circuit
->hello_interval
[0],
885 circuit
->hello_multiplier
[0],
886 (circuit
->pad_hellos
? "(pad)"
889 " CNSP interval: %u, "
890 "PSNP interval: %u\n",
891 circuit
->csnp_interval
[0],
892 circuit
->psnp_interval
[0]);
893 if (circuit
->circ_type
== CIRCUIT_T_BROADCAST
)
895 " LAN Priority: %u, %s\n",
896 circuit
->priority
[0],
897 (circuit
->u
.bc
.is_dr
[0]
904 if (circuit
->is_type
& IS_LEVEL_2
) {
905 vty_out(vty
, " Level-2 Information:\n");
906 if (circuit
->area
->newmetric
)
907 vty_out(vty
, " Metric: %d",
908 circuit
->te_metric
[1]);
910 vty_out(vty
, " Metric: %d",
912 if (!circuit
->is_passive
) {
913 vty_out(vty
, ", Active neighbors: %u\n",
914 circuit
->upadjcount
[1]);
916 " Hello interval: %u, "
917 "Holddown count: %u %s\n",
918 circuit
->hello_interval
[1],
919 circuit
->hello_multiplier
[1],
920 (circuit
->pad_hellos
? "(pad)"
923 " CNSP interval: %u, "
924 "PSNP interval: %u\n",
925 circuit
->csnp_interval
[1],
926 circuit
->psnp_interval
[1]);
927 if (circuit
->circ_type
== CIRCUIT_T_BROADCAST
)
929 " LAN Priority: %u, %s\n",
930 circuit
->priority
[1],
931 (circuit
->u
.bc
.is_dr
[1]
938 if (circuit
->ip_addrs
&& listcount(circuit
->ip_addrs
) > 0) {
939 vty_out(vty
, " IP Prefix(es):\n");
940 for (ALL_LIST_ELEMENTS_RO(circuit
->ip_addrs
, node
,
942 prefix2str(ip_addr
, buf
, sizeof(buf
));
943 vty_out(vty
, " %s\n", buf
);
946 if (circuit
->ipv6_link
&& listcount(circuit
->ipv6_link
) > 0) {
947 vty_out(vty
, " IPv6 Link-Locals:\n");
948 for (ALL_LIST_ELEMENTS_RO(circuit
->ipv6_link
, node
,
950 prefix2str(ip_addr
, (char *)buf
, BUFSIZ
);
951 vty_out(vty
, " %s\n", buf
);
954 if (circuit
->ipv6_non_link
955 && listcount(circuit
->ipv6_non_link
) > 0) {
956 vty_out(vty
, " IPv6 Prefixes:\n");
957 for (ALL_LIST_ELEMENTS_RO(circuit
->ipv6_non_link
, node
,
959 prefix2str(ip_addr
, (char *)buf
, BUFSIZ
);
960 vty_out(vty
, " %s\n", buf
);
969 DEFINE_HOOK(isis_circuit_config_write
,
970 (struct isis_circuit
*circuit
, struct vty
*vty
),
974 int isis_interface_config_write(struct vty
*vty
)
976 struct vrf
*vrf
= vrf_lookup_by_id(VRF_DEFAULT
);
978 struct listnode
*node
;
979 struct interface
*ifp
;
980 struct isis_area
*area
;
981 struct isis_circuit
*circuit
;
984 FOR_ALL_INTERFACES (vrf
, ifp
) {
986 vty_frame(vty
, "interface %s\n", ifp
->name
);
990 vty_out(vty
, " description %s\n", ifp
->desc
);
994 for (ALL_LIST_ELEMENTS_RO(isis
->area_list
, node
, area
)) {
996 circuit_lookup_by_ifp(ifp
, area
->circuit_list
);
999 if (circuit
->ip_router
) {
1000 vty_out(vty
, " ip router " PROTO_NAME
" %s\n",
1004 if (circuit
->is_passive
) {
1005 vty_out(vty
, " " PROTO_NAME
" passive\n");
1008 if (circuit
->circ_type_config
== CIRCUIT_T_P2P
) {
1009 vty_out(vty
, " " PROTO_NAME
" network point-to-point\n");
1012 if (circuit
->ipv6_router
) {
1013 vty_out(vty
, " ipv6 router " PROTO_NAME
" %s\n",
1018 /* ISIS - circuit type */
1020 if (circuit
->is_type
== IS_LEVEL_1
) {
1021 vty_out(vty
, " " PROTO_NAME
" circuit-type level-1\n");
1024 if (circuit
->is_type
== IS_LEVEL_2
) {
1026 " " PROTO_NAME
" circuit-type level-2-only\n");
1032 /* ISIS - CSNP interval */
1033 if (circuit
->csnp_interval
[0]
1034 == circuit
->csnp_interval
[1]) {
1035 if (circuit
->csnp_interval
[0]
1036 != DEFAULT_CSNP_INTERVAL
) {
1037 vty_out(vty
, " " PROTO_NAME
" csnp-interval %d\n",
1038 circuit
->csnp_interval
[0]);
1042 for (i
= 0; i
< 2; i
++) {
1043 if (circuit
->csnp_interval
[i
]
1044 != DEFAULT_CSNP_INTERVAL
) {
1046 " " PROTO_NAME
" csnp-interval %d level-%d\n",
1047 circuit
->csnp_interval
1055 /* ISIS - PSNP interval */
1056 if (circuit
->psnp_interval
[0]
1057 == circuit
->psnp_interval
[1]) {
1058 if (circuit
->psnp_interval
[0]
1059 != DEFAULT_PSNP_INTERVAL
) {
1060 vty_out(vty
, " " PROTO_NAME
" psnp-interval %d\n",
1061 circuit
->psnp_interval
[0]);
1065 for (i
= 0; i
< 2; i
++) {
1066 if (circuit
->psnp_interval
[i
]
1067 != DEFAULT_PSNP_INTERVAL
) {
1069 " " PROTO_NAME
" psnp-interval %d level-%d\n",
1070 circuit
->psnp_interval
1078 /* ISIS - Hello padding - Defaults to true so only
1079 * display if false */
1080 if (circuit
->pad_hellos
== 0) {
1081 vty_out(vty
, " no " PROTO_NAME
" hello padding\n");
1085 if (circuit
->disable_threeway_adj
) {
1086 vty_out(vty
, " no isis three-way-handshake\n");
1090 /* ISIS - Hello interval */
1091 if (circuit
->hello_interval
[0]
1092 == circuit
->hello_interval
[1]) {
1093 if (circuit
->hello_interval
[0]
1094 != DEFAULT_HELLO_INTERVAL
) {
1096 " " PROTO_NAME
" hello-interval %d\n",
1097 circuit
->hello_interval
[0]);
1101 for (i
= 0; i
< 2; i
++) {
1102 if (circuit
->hello_interval
[i
]
1103 != DEFAULT_HELLO_INTERVAL
) {
1105 " " PROTO_NAME
" hello-interval %d level-%d\n",
1106 circuit
->hello_interval
1114 /* ISIS - Hello Multiplier */
1115 if (circuit
->hello_multiplier
[0]
1116 == circuit
->hello_multiplier
[1]) {
1117 if (circuit
->hello_multiplier
[0]
1118 != DEFAULT_HELLO_MULTIPLIER
) {
1120 " " PROTO_NAME
" hello-multiplier %d\n",
1121 circuit
->hello_multiplier
[0]);
1125 for (i
= 0; i
< 2; i
++) {
1126 if (circuit
->hello_multiplier
[i
]
1127 != DEFAULT_HELLO_MULTIPLIER
) {
1129 " " PROTO_NAME
" hello-multiplier %d level-%d\n",
1130 circuit
->hello_multiplier
1138 /* ISIS - Priority */
1139 if (circuit
->priority
[0] == circuit
->priority
[1]) {
1140 if (circuit
->priority
[0] != DEFAULT_PRIORITY
) {
1141 vty_out(vty
, " " PROTO_NAME
" priority %d\n",
1142 circuit
->priority
[0]);
1146 for (i
= 0; i
< 2; i
++) {
1147 if (circuit
->priority
[i
]
1148 != DEFAULT_PRIORITY
) {
1150 " " PROTO_NAME
" priority %d level-%d\n",
1151 circuit
->priority
[i
],
1159 if (circuit
->te_metric
[0] == circuit
->te_metric
[1]) {
1160 if (circuit
->te_metric
[0]
1161 != DEFAULT_CIRCUIT_METRIC
) {
1162 vty_out(vty
, " " PROTO_NAME
" metric %d\n",
1163 circuit
->te_metric
[0]);
1167 for (i
= 0; i
< 2; i
++) {
1168 if (circuit
->te_metric
[i
]
1169 != DEFAULT_CIRCUIT_METRIC
) {
1171 " " PROTO_NAME
" metric %d level-%d\n",
1172 circuit
->te_metric
[i
],
1178 if (circuit
->passwd
.type
== ISIS_PASSWD_TYPE_HMAC_MD5
) {
1179 vty_out(vty
, " " PROTO_NAME
" password md5 %s\n",
1180 circuit
->passwd
.passwd
);
1182 } else if (circuit
->passwd
.type
1183 == ISIS_PASSWD_TYPE_CLEARTXT
) {
1184 vty_out(vty
, " " PROTO_NAME
" password clear %s\n",
1185 circuit
->passwd
.passwd
);
1188 write
+= hook_call(isis_circuit_config_write
,
1191 vty_endframe(vty
, "!\n");
1197 int isis_interface_config_write(struct vty
*vty
)
1199 struct vrf
*vrf
= vrf_lookup_by_id(VRF_DEFAULT
);
1201 struct interface
*ifp
;
1202 struct isis_circuit
*circuit
;
1203 struct lyd_node
*dnode
;
1205 FOR_ALL_INTERFACES (vrf
, ifp
) {
1206 dnode
= yang_dnode_get(
1207 running_config
->dnode
,
1208 "/frr-interface:lib/interface[name='%s'][vrf='%s']",
1209 ifp
->name
, vrf
->name
);
1214 nb_cli_show_dnode_cmds(vty
, dnode
, false);
1215 circuit
= circuit_scan_by_ifp(ifp
);
1217 write
+= hook_call(isis_circuit_config_write
, circuit
,
1222 #endif /* ifdef FABRICD */
1224 struct isis_circuit
*isis_circuit_create(struct isis_area
*area
,
1225 struct interface
*ifp
)
1227 struct isis_circuit
*circuit
= circuit_scan_by_ifp(ifp
);
1228 if (circuit
&& circuit
->area
)
1230 circuit
= isis_csm_state_change(ISIS_ENABLE
, circuit
, area
);
1231 if (circuit
->state
!= C_STATE_CONF
&& circuit
->state
!= C_STATE_UP
)
1233 isis_circuit_if_bind(circuit
, ifp
);
1237 void isis_circuit_af_set(struct isis_circuit
*circuit
, bool ip_router
,
1240 struct isis_area
*area
= circuit
->area
;
1241 bool change
= circuit
->ip_router
!= ip_router
1242 || circuit
->ipv6_router
!= ipv6_router
;
1244 area
->ip_circuits
+= ip_router
- circuit
->ip_router
;
1245 area
->ipv6_circuits
+= ipv6_router
- circuit
->ipv6_router
;
1246 circuit
->ip_router
= ip_router
;
1247 circuit
->ipv6_router
= ipv6_router
;
1252 circuit_update_nlpids(circuit
);
1254 if (!ip_router
&& !ipv6_router
)
1255 isis_csm_state_change(ISIS_DISABLE
, circuit
, area
);
1257 lsp_regenerate_schedule(circuit
->area
, circuit
->is_type
, 0);
1260 ferr_r
isis_circuit_passive_set(struct isis_circuit
*circuit
, bool passive
)
1262 if (circuit
->is_passive
== passive
)
1265 if (if_is_loopback(circuit
->interface
) && !passive
)
1266 return ferr_cfg_invalid("loopback is always passive");
1268 if (circuit
->state
!= C_STATE_UP
) {
1269 circuit
->is_passive
= passive
;
1271 struct isis_area
*area
= circuit
->area
;
1272 isis_csm_state_change(ISIS_DISABLE
, circuit
, area
);
1273 circuit
->is_passive
= passive
;
1274 isis_csm_state_change(ISIS_ENABLE
, circuit
, area
);
1280 ferr_r
isis_circuit_metric_set(struct isis_circuit
*circuit
, int level
,
1283 assert(level
== IS_LEVEL_1
|| level
== IS_LEVEL_2
);
1284 if (metric
> MAX_WIDE_LINK_METRIC
)
1285 return ferr_cfg_invalid("metric %d too large for wide metric",
1287 if (circuit
->area
&& circuit
->area
->oldmetric
1288 && metric
> MAX_NARROW_LINK_METRIC
)
1289 return ferr_cfg_invalid("metric %d too large for narrow metric",
1292 circuit
->te_metric
[level
- 1] = metric
;
1293 circuit
->metric
[level
- 1] = metric
;
1296 lsp_regenerate_schedule(circuit
->area
, level
, 0);
1300 ferr_r
isis_circuit_passwd_unset(struct isis_circuit
*circuit
)
1302 memset(&circuit
->passwd
, 0, sizeof(circuit
->passwd
));
1306 ferr_r
isis_circuit_passwd_set(struct isis_circuit
*circuit
,
1307 uint8_t passwd_type
, const char *passwd
)
1312 return ferr_code_bug("no circuit password given");
1314 len
= strlen(passwd
);
1316 return ferr_code_bug(
1317 "circuit password too long (max 254 chars)");
1319 circuit
->passwd
.len
= len
;
1320 strlcpy((char *)circuit
->passwd
.passwd
, passwd
,
1321 sizeof(circuit
->passwd
.passwd
));
1322 circuit
->passwd
.type
= passwd_type
;
1326 ferr_r
isis_circuit_passwd_cleartext_set(struct isis_circuit
*circuit
,
1329 return isis_circuit_passwd_set(circuit
, ISIS_PASSWD_TYPE_CLEARTXT
,
1333 ferr_r
isis_circuit_passwd_hmac_md5_set(struct isis_circuit
*circuit
,
1336 return isis_circuit_passwd_set(circuit
, ISIS_PASSWD_TYPE_HMAC_MD5
,
1340 struct cmd_node interface_node
= {
1341 INTERFACE_NODE
, "%s(config-if)# ", 1,
1344 void isis_circuit_circ_type_set(struct isis_circuit
*circuit
, int circ_type
)
1346 if (circuit
->circ_type
== circ_type
)
1349 if (circuit
->state
!= C_STATE_UP
) {
1350 circuit
->circ_type
= circ_type
;
1351 circuit
->circ_type_config
= circ_type
;
1353 struct isis_area
*area
= circuit
->area
;
1355 isis_csm_state_change(ISIS_DISABLE
, circuit
, area
);
1356 circuit
->circ_type
= circ_type
;
1357 circuit
->circ_type_config
= circ_type
;
1358 isis_csm_state_change(ISIS_ENABLE
, circuit
, area
);
1362 int isis_circuit_mt_enabled_set(struct isis_circuit
*circuit
, uint16_t mtid
,
1365 struct isis_circuit_mt_setting
*setting
;
1367 setting
= circuit_get_mt_setting(circuit
, mtid
);
1368 if (setting
->enabled
!= enabled
) {
1369 setting
->enabled
= enabled
;
1370 lsp_regenerate_schedule(circuit
->area
, IS_LEVEL_1
| IS_LEVEL_2
,
1377 int isis_if_new_hook(struct interface
*ifp
)
1382 int isis_if_delete_hook(struct interface
*ifp
)
1384 struct isis_circuit
*circuit
;
1385 /* Clean up the circuit data */
1386 if (ifp
&& ifp
->info
) {
1387 circuit
= ifp
->info
;
1388 isis_csm_state_change(IF_DOWN_FROM_Z
, circuit
, circuit
->area
);
1389 isis_csm_state_change(ISIS_DISABLE
, circuit
, circuit
->area
);
1395 static int isis_ifp_create(struct interface
*ifp
)
1397 if (if_is_operative(ifp
))
1398 isis_csm_state_change(IF_UP_FROM_Z
, circuit_scan_by_ifp(ifp
),
1401 hook_call(isis_if_new_hook
, ifp
);
1406 static int isis_ifp_up(struct interface
*ifp
)
1408 isis_csm_state_change(IF_UP_FROM_Z
, circuit_scan_by_ifp(ifp
), ifp
);
1413 static int isis_ifp_down(struct interface
*ifp
)
1415 struct isis_circuit
*circuit
;
1417 circuit
= isis_csm_state_change(IF_DOWN_FROM_Z
,
1418 circuit_scan_by_ifp(ifp
), ifp
);
1420 SET_FLAG(circuit
->flags
, ISIS_CIRCUIT_FLAPPED_AFTER_SPF
);
1425 static int isis_ifp_destroy(struct interface
*ifp
)
1427 if (if_is_operative(ifp
))
1428 zlog_warn("Zebra: got delete of %s, but interface is still up",
1431 isis_csm_state_change(IF_DOWN_FROM_Z
, circuit_scan_by_ifp(ifp
), ifp
);
1433 /* Cannot call if_delete because we should retain the pseudo interface
1434 in case there is configuration info attached to it. */
1435 if_delete_retain(ifp
);
1440 void isis_circuit_init(void)
1442 /* Initialize Zebra interface data structure */
1443 hook_register_prio(if_add
, 0, isis_if_new_hook
);
1444 hook_register_prio(if_del
, 0, isis_if_delete_hook
);
1446 /* Install interface node */
1447 install_node(&interface_node
, isis_interface_config_write
);
1449 if_zapi_callbacks(isis_ifp_create
, isis_ifp_up
,
1450 isis_ifp_down
, isis_ifp_destroy
);