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_if_new_hook(struct interface
*);
71 int isis_if_delete_hook(struct interface
*);
73 struct isis_circuit
*isis_circuit_new(void)
75 struct isis_circuit
*circuit
;
78 circuit
= XCALLOC(MTYPE_ISIS_CIRCUIT
, sizeof(struct isis_circuit
));
84 circuit
->is_type
= yang_get_default_enum(
85 "/frr-interface:lib/interface/frr-isisd:isis/circuit-type");
88 circuit
->pad_hellos
= yang_get_default_bool(
89 "/frr-interface:lib/interface/frr-isisd:isis/hello/padding");
90 circuit
->hello_interval
[0] = yang_get_default_uint32(
91 "/frr-interface:lib/interface/frr-isisd:isis/hello/interval/level-1");
92 circuit
->hello_interval
[1] = yang_get_default_uint32(
93 "/frr-interface:lib/interface/frr-isisd:isis/hello/interval/level-2");
94 circuit
->hello_multiplier
[0] = yang_get_default_uint32(
95 "/frr-interface:lib/interface/frr-isisd:isis/hello/multiplier/level-1");
96 circuit
->hello_multiplier
[1] = yang_get_default_uint32(
97 "/frr-interface:lib/interface/frr-isisd:isis/hello/multiplier/level-2");
98 circuit
->csnp_interval
[0] = yang_get_default_uint16(
99 "/frr-interface:lib/interface/frr-isisd:isis/csnp-interval/level-1");
100 circuit
->csnp_interval
[1] = yang_get_default_uint16(
101 "/frr-interface:lib/interface/frr-isisd:isis/csnp-interval/level-2");
102 circuit
->psnp_interval
[0] = yang_get_default_uint16(
103 "/frr-interface:lib/interface/frr-isisd:isis/psnp-interval/level-1");
104 circuit
->psnp_interval
[1] = yang_get_default_uint16(
105 "/frr-interface:lib/interface/frr-isisd:isis/psnp-interval/level-2");
106 circuit
->priority
[0] = yang_get_default_uint8(
107 "/frr-interface:lib/interface/frr-isisd:isis/priority/level-1");
108 circuit
->priority
[1] = yang_get_default_uint8(
109 "/frr-interface:lib/interface/frr-isisd:isis/priority/level-2");
110 circuit
->metric
[0] = yang_get_default_uint32(
111 "/frr-interface:lib/interface/frr-isisd:isis/metric/level-1");
112 circuit
->metric
[1] = yang_get_default_uint32(
113 "/frr-interface:lib/interface/frr-isisd:isis/metric/level-2");
114 circuit
->te_metric
[0] = yang_get_default_uint32(
115 "/frr-interface:lib/interface/frr-isisd:isis/metric/level-1");
116 circuit
->te_metric
[1] = yang_get_default_uint32(
117 "/frr-interface:lib/interface/frr-isisd:isis/metric/level-2");
119 for (i
= 0; i
< 2; i
++) {
120 circuit
->level_arg
[i
].level
= i
+ 1;
121 circuit
->level_arg
[i
].circuit
= circuit
;
124 circuit
->is_type
= IS_LEVEL_1_AND_2
;
126 circuit
->pad_hellos
= 1;
127 for (i
= 0; i
< 2; i
++) {
128 circuit
->hello_interval
[i
] = DEFAULT_HELLO_INTERVAL
;
129 circuit
->hello_multiplier
[i
] = DEFAULT_HELLO_MULTIPLIER
;
130 circuit
->csnp_interval
[i
] = DEFAULT_CSNP_INTERVAL
;
131 circuit
->psnp_interval
[i
] = DEFAULT_PSNP_INTERVAL
;
132 circuit
->priority
[i
] = DEFAULT_PRIORITY
;
133 circuit
->metric
[i
] = DEFAULT_CIRCUIT_METRIC
;
134 circuit
->te_metric
[i
] = DEFAULT_CIRCUIT_METRIC
;
135 circuit
->level_arg
[i
].level
= i
+ 1;
136 circuit
->level_arg
[i
].circuit
= circuit
;
138 #endif /* ifndef FABRICD */
140 circuit_mt_init(circuit
);
142 QOBJ_REG(circuit
, isis_circuit
);
147 void isis_circuit_del(struct isis_circuit
*circuit
)
154 isis_circuit_if_unbind(circuit
, circuit
->interface
);
156 circuit_mt_finish(circuit
);
158 /* and lastly the circuit itself */
159 XFREE(MTYPE_ISIS_CIRCUIT
, circuit
);
164 void isis_circuit_configure(struct isis_circuit
*circuit
,
165 struct isis_area
*area
)
168 circuit
->area
= area
;
171 * Whenever the is-type of an area is changed, the is-type of each
173 * in that area is updated to a non-empty subset of the area is-type.
174 * Inversely, when configuring a new circuit, this property should be
177 if (area
->is_type
!= IS_LEVEL_1_AND_2
)
178 circuit
->is_type
= area
->is_type
;
181 * Add the circuit into area
183 listnode_add(area
->circuit_list
, circuit
);
185 circuit
->idx
= flags_get_index(&area
->flags
);
190 void isis_circuit_deconfigure(struct isis_circuit
*circuit
,
191 struct isis_area
*area
)
193 /* Free the index of SRM and SSN flags */
194 flags_free_index(&area
->flags
, circuit
->idx
);
196 /* Remove circuit from area */
197 assert(circuit
->area
== area
);
198 listnode_delete(area
->circuit_list
, circuit
);
199 circuit
->area
= NULL
;
204 struct isis_circuit
*circuit_lookup_by_ifp(struct interface
*ifp
,
207 struct isis_circuit
*circuit
= NULL
;
208 struct listnode
*node
;
213 for (ALL_LIST_ELEMENTS_RO(list
, node
, circuit
))
214 if (circuit
->interface
== ifp
) {
215 assert(ifp
->info
== circuit
);
222 struct isis_circuit
*circuit_scan_by_ifp(struct interface
*ifp
)
224 struct isis_area
*area
;
225 struct listnode
*node
;
226 struct isis_circuit
*circuit
;
229 return (struct isis_circuit
*)ifp
->info
;
231 if (isis
->area_list
) {
232 for (ALL_LIST_ELEMENTS_RO(isis
->area_list
, node
, area
)) {
234 circuit_lookup_by_ifp(ifp
, area
->circuit_list
);
239 return circuit_lookup_by_ifp(ifp
, isis
->init_circ_list
);
242 void isis_circuit_add_addr(struct isis_circuit
*circuit
,
243 struct connected
*connected
)
245 struct listnode
*node
;
246 struct prefix_ipv4
*ipv4
;
247 #if defined(EXTREME_DEBUG)
248 char buf
[PREFIX2STR_BUFFER
];
250 struct prefix_ipv6
*ipv6
;
252 if (connected
->address
->family
== AF_INET
) {
253 uint32_t addr
= connected
->address
->u
.prefix4
.s_addr
;
255 if (IPV4_NET0(addr
) || IPV4_NET127(addr
) || IN_CLASSD(addr
)
256 || IPV4_LINKLOCAL(addr
))
259 for (ALL_LIST_ELEMENTS_RO(circuit
->ip_addrs
, node
, ipv4
))
260 if (prefix_same((struct prefix
*)ipv4
,
264 ipv4
= prefix_ipv4_new();
265 ipv4
->prefixlen
= connected
->address
->prefixlen
;
266 ipv4
->prefix
= connected
->address
->u
.prefix4
;
267 listnode_add(circuit
->ip_addrs
, ipv4
);
269 /* Update Local IP address parameter if MPLS TE is enable */
270 if (circuit
->ext
&& IS_MPLS_TE(circuit
->ext
)) {
271 circuit
->ext
->local_addr
.s_addr
= ipv4
->prefix
.s_addr
;
272 SET_SUBTLV(circuit
->ext
, EXT_LOCAL_ADDR
);
276 lsp_regenerate_schedule(circuit
->area
, circuit
->is_type
,
280 prefix2str(connected
->address
, buf
, sizeof(buf
));
281 zlog_debug("Added IP address %s to circuit %s", buf
,
282 circuit
->interface
->name
);
283 #endif /* EXTREME_DEBUG */
285 if (connected
->address
->family
== AF_INET6
) {
286 if (IN6_IS_ADDR_LOOPBACK(&connected
->address
->u
.prefix6
))
289 for (ALL_LIST_ELEMENTS_RO(circuit
->ipv6_link
, node
, ipv6
))
290 if (prefix_same((struct prefix
*)ipv6
,
293 for (ALL_LIST_ELEMENTS_RO(circuit
->ipv6_non_link
, node
, ipv6
))
294 if (prefix_same((struct prefix
*)ipv6
,
298 ipv6
= prefix_ipv6_new();
299 ipv6
->prefixlen
= connected
->address
->prefixlen
;
300 ipv6
->prefix
= connected
->address
->u
.prefix6
;
302 if (IN6_IS_ADDR_LINKLOCAL(&ipv6
->prefix
))
303 listnode_add(circuit
->ipv6_link
, ipv6
);
305 listnode_add(circuit
->ipv6_non_link
, ipv6
);
307 lsp_regenerate_schedule(circuit
->area
, circuit
->is_type
,
311 prefix2str(connected
->address
, buf
, sizeof(buf
));
312 zlog_debug("Added IPv6 address %s to circuit %s", buf
,
313 circuit
->interface
->name
);
314 #endif /* EXTREME_DEBUG */
319 void isis_circuit_del_addr(struct isis_circuit
*circuit
,
320 struct connected
*connected
)
322 struct prefix_ipv4
*ipv4
, *ip
= NULL
;
323 struct listnode
*node
;
324 char buf
[PREFIX2STR_BUFFER
];
325 struct prefix_ipv6
*ipv6
, *ip6
= NULL
;
328 if (connected
->address
->family
== AF_INET
) {
329 ipv4
= prefix_ipv4_new();
330 ipv4
->prefixlen
= connected
->address
->prefixlen
;
331 ipv4
->prefix
= connected
->address
->u
.prefix4
;
333 for (ALL_LIST_ELEMENTS_RO(circuit
->ip_addrs
, node
, ip
))
334 if (prefix_same((struct prefix
*)ip
,
335 (struct prefix
*)ipv4
))
339 listnode_delete(circuit
->ip_addrs
, ip
);
340 prefix_ipv4_free(&ip
);
342 lsp_regenerate_schedule(circuit
->area
,
343 circuit
->is_type
, 0);
345 prefix2str(connected
->address
, buf
, sizeof(buf
));
347 "Nonexistent ip address %s removal attempt from circuit %s",
348 buf
, circuit
->interface
->name
);
349 zlog_warn("Current ip addresses on %s:",
350 circuit
->interface
->name
);
351 for (ALL_LIST_ELEMENTS_RO(circuit
->ip_addrs
, node
,
353 prefix2str(ip
, buf
, sizeof(buf
));
354 zlog_warn(" %s", buf
);
356 zlog_warn("End of addresses");
359 prefix_ipv4_free(&ipv4
);
361 if (connected
->address
->family
== AF_INET6
) {
362 ipv6
= prefix_ipv6_new();
363 ipv6
->prefixlen
= connected
->address
->prefixlen
;
364 ipv6
->prefix
= connected
->address
->u
.prefix6
;
366 if (IN6_IS_ADDR_LINKLOCAL(&ipv6
->prefix
)) {
367 for (ALL_LIST_ELEMENTS_RO(circuit
->ipv6_link
, node
,
369 if (prefix_same((struct prefix
*)ip6
,
370 (struct prefix
*)ipv6
))
374 listnode_delete(circuit
->ipv6_link
, ip6
);
375 prefix_ipv6_free(&ip6
);
379 for (ALL_LIST_ELEMENTS_RO(circuit
->ipv6_non_link
, node
,
381 if (prefix_same((struct prefix
*)ip6
,
382 (struct prefix
*)ipv6
))
386 listnode_delete(circuit
->ipv6_non_link
, ip6
);
387 prefix_ipv6_free(&ip6
);
393 prefix2str(connected
->address
, buf
, sizeof(buf
));
395 "Nonexistent ip address %s removal attempt from circuit %s",
396 buf
, circuit
->interface
->name
);
397 zlog_warn("Current ip addresses on %s:",
398 circuit
->interface
->name
);
399 for (ALL_LIST_ELEMENTS_RO(circuit
->ipv6_link
, node
,
401 prefix2str((struct prefix
*)ip6
, (char *)buf
,
403 zlog_warn(" %s", buf
);
406 for (ALL_LIST_ELEMENTS_RO(circuit
->ipv6_non_link
, node
,
408 prefix2str((struct prefix
*)ip6
, (char *)buf
,
410 zlog_warn(" %s", buf
);
412 zlog_warn("End of addresses");
413 } else if (circuit
->area
)
414 lsp_regenerate_schedule(circuit
->area
, circuit
->is_type
,
417 prefix_ipv6_free(&ipv6
);
422 static uint8_t isis_circuit_id_gen(struct isis
*isis
, struct interface
*ifp
)
424 /* Circuit ids MUST be unique for any broadcast circuits. Otherwise,
425 * Pseudo-Node LSPs cannot be generated correctly.
427 * Currently, allocate one circuit ID for any circuit, limiting the total
428 * numer of circuits IS-IS can run on to 255.
430 * We should revisit this when implementing 3-way adjacencies for p2p, since
431 * we then have extended interface IDs available.
433 uint8_t id
= ifp
->ifindex
;
436 for (i
= 0; i
< 256; i
++) {
437 if (id
&& !_ISIS_CHECK_FLAG(isis
->circuit_ids_used
, id
))
443 zlog_warn("Could not allocate a circuit id for '%s'",
448 _ISIS_SET_FLAG(isis
->circuit_ids_used
, id
);
452 void isis_circuit_if_add(struct isis_circuit
*circuit
, struct interface
*ifp
)
454 struct listnode
*node
, *nnode
;
455 struct connected
*conn
;
457 isis_circuit_if_bind(circuit
, ifp
);
459 if (if_is_broadcast(ifp
)) {
460 if (fabricd
|| circuit
->circ_type_config
== CIRCUIT_T_P2P
)
461 circuit
->circ_type
= CIRCUIT_T_P2P
;
463 circuit
->circ_type
= CIRCUIT_T_BROADCAST
;
464 } else if (if_is_pointopoint(ifp
)) {
465 circuit
->circ_type
= CIRCUIT_T_P2P
;
466 } else if (if_is_loopback(ifp
)) {
467 circuit
->circ_type
= CIRCUIT_T_LOOPBACK
;
468 circuit
->is_passive
= 1;
470 /* It's normal in case of loopback etc. */
471 if (isis
->debugs
& DEBUG_EVENTS
)
472 zlog_debug("isis_circuit_if_add: unsupported media");
473 circuit
->circ_type
= CIRCUIT_T_UNKNOWN
;
476 circuit
->ip_addrs
= list_new();
477 circuit
->ipv6_link
= list_new();
478 circuit
->ipv6_non_link
= list_new();
480 for (ALL_LIST_ELEMENTS(ifp
->connected
, node
, nnode
, conn
))
481 isis_circuit_add_addr(circuit
, conn
);
485 void isis_circuit_if_del(struct isis_circuit
*circuit
, struct interface
*ifp
)
487 struct listnode
*node
, *nnode
;
488 struct connected
*conn
;
490 assert(circuit
->interface
== ifp
);
492 /* destroy addresses */
493 for (ALL_LIST_ELEMENTS(ifp
->connected
, node
, nnode
, conn
))
494 isis_circuit_del_addr(circuit
, conn
);
496 if (circuit
->ip_addrs
) {
497 assert(listcount(circuit
->ip_addrs
) == 0);
498 list_delete(&circuit
->ip_addrs
);
501 if (circuit
->ipv6_link
) {
502 assert(listcount(circuit
->ipv6_link
) == 0);
503 list_delete(&circuit
->ipv6_link
);
506 if (circuit
->ipv6_non_link
) {
507 assert(listcount(circuit
->ipv6_non_link
) == 0);
508 list_delete(&circuit
->ipv6_non_link
);
511 circuit
->circ_type
= CIRCUIT_T_UNKNOWN
;
514 void isis_circuit_if_bind(struct isis_circuit
*circuit
, struct interface
*ifp
)
516 assert(circuit
!= NULL
);
518 if (circuit
->interface
)
519 assert(circuit
->interface
== ifp
);
521 circuit
->interface
= ifp
;
523 assert(ifp
->info
== circuit
);
528 void isis_circuit_if_unbind(struct isis_circuit
*circuit
, struct interface
*ifp
)
530 assert(circuit
!= NULL
);
532 assert(circuit
->interface
== ifp
);
533 assert(ifp
->info
== circuit
);
534 circuit
->interface
= NULL
;
538 static void isis_circuit_update_all_srmflags(struct isis_circuit
*circuit
,
541 struct isis_area
*area
;
542 struct isis_lsp
*lsp
;
546 area
= circuit
->area
;
548 for (level
= ISIS_LEVEL1
; level
<= ISIS_LEVEL2
; level
++) {
549 if (!(level
& circuit
->is_type
))
552 if (!lspdb_count(&area
->lspdb
[level
- 1]))
555 frr_each (lspdb
, &area
->lspdb
[level
- 1], lsp
) {
557 isis_tx_queue_add(circuit
->tx_queue
, lsp
,
560 isis_tx_queue_del(circuit
->tx_queue
, lsp
);
566 size_t isis_circuit_pdu_size(struct isis_circuit
*circuit
)
568 return ISO_MTU(circuit
);
571 void isis_circuit_stream(struct isis_circuit
*circuit
, struct stream
**stream
)
573 size_t stream_size
= isis_circuit_pdu_size(circuit
);
576 *stream
= stream_new(stream_size
);
578 if (STREAM_SIZE(*stream
) != stream_size
)
579 stream_resize_inplace(stream
, stream_size
);
580 stream_reset(*stream
);
584 void isis_circuit_prepare(struct isis_circuit
*circuit
)
586 #if ISIS_METHOD != ISIS_METHOD_DLPI
587 thread_add_read(master
, isis_receive
, circuit
, circuit
->fd
,
590 thread_add_timer_msec(master
, isis_receive
, circuit
,
591 listcount(circuit
->area
->circuit_list
) * 100,
596 int isis_circuit_up(struct isis_circuit
*circuit
)
600 /* Set the flags for all the lsps of the circuit. */
601 isis_circuit_update_all_srmflags(circuit
, 1);
603 if (circuit
->state
== C_STATE_UP
)
606 if (circuit
->is_passive
)
609 if (circuit
->area
->lsp_mtu
> isis_circuit_pdu_size(circuit
)) {
612 "Interface MTU %zu on %s is too low to support area lsp mtu %u!",
613 isis_circuit_pdu_size(circuit
),
614 circuit
->interface
->name
, circuit
->area
->lsp_mtu
);
615 isis_circuit_update_all_srmflags(circuit
, 0);
619 if (circuit
->circ_type
== CIRCUIT_T_BROADCAST
) {
620 circuit
->circuit_id
= isis_circuit_id_gen(isis
, circuit
->interface
);
621 if (!circuit
->circuit_id
) {
624 "There are already 255 broadcast circuits active!");
629 * Get the Hardware Address
631 if (circuit
->interface
->hw_addr_len
!= ETH_ALEN
) {
632 zlog_warn("unsupported link layer");
634 memcpy(circuit
->u
.bc
.snpa
, circuit
->interface
->hw_addr
,
638 zlog_debug("isis_circuit_if_add: if_id %d, isomtu %d snpa %s",
639 circuit
->interface
->ifindex
, ISO_MTU(circuit
),
640 snpa_print(circuit
->u
.bc
.snpa
));
641 #endif /* EXTREME_DEBUG */
643 circuit
->u
.bc
.adjdb
[0] = list_new();
644 circuit
->u
.bc
.adjdb
[1] = list_new();
647 * ISO 10589 - 8.4.1 Enabling of broadcast circuits
650 /* initilizing the hello sending threads
654 /* 8.4.1 a) commence sending of IIH PDUs */
656 for (int level
= ISIS_LEVEL1
; level
<= ISIS_LEVEL2
; level
++) {
657 if (!(circuit
->is_type
& level
))
660 send_hello_sched(circuit
, level
, TRIGGERED_IIH_DELAY
);
661 circuit
->u
.bc
.lan_neighs
[level
- 1] = list_new();
663 thread_add_timer(master
, isis_run_dr
,
664 &circuit
->level_arg
[level
- 1],
665 2 * circuit
->hello_interval
[level
- 1],
666 &circuit
->u
.bc
.t_run_dr
[level
- 1]);
669 /* 8.4.1 b) FIXME: solicit ES - 8.4.6 */
670 /* 8.4.1 c) FIXME: listen for ESH PDUs */
671 } else if (circuit
->circ_type
== CIRCUIT_T_P2P
) {
672 /* initializing the hello send threads
675 circuit
->u
.p2p
.neighbor
= NULL
;
676 send_hello_sched(circuit
, 0, TRIGGERED_IIH_DELAY
);
679 /* initializing PSNP timers */
680 if (circuit
->is_type
& IS_LEVEL_1
)
682 master
, send_l1_psnp
, circuit
,
683 isis_jitter(circuit
->psnp_interval
[0], PSNP_JITTER
),
684 &circuit
->t_send_psnp
[0]);
686 if (circuit
->is_type
& IS_LEVEL_2
)
688 master
, send_l2_psnp
, circuit
,
689 isis_jitter(circuit
->psnp_interval
[1], PSNP_JITTER
),
690 &circuit
->t_send_psnp
[1]);
692 /* unified init for circuits; ignore warnings below this level */
693 retv
= isis_sock_init(circuit
);
694 if (retv
!= ISIS_OK
) {
695 isis_circuit_down(circuit
);
699 /* initialize the circuit streams after opening connection */
700 isis_circuit_stream(circuit
, &circuit
->rcv_stream
);
701 isis_circuit_stream(circuit
, &circuit
->snd_stream
);
703 isis_circuit_prepare(circuit
);
705 circuit
->tx_queue
= isis_tx_queue_new(circuit
, send_lsp
);
708 /* send northbound notification */
709 isis_notif_if_state_change(circuit
, false);
710 #endif /* ifndef FABRICD */
715 void isis_circuit_down(struct isis_circuit
*circuit
)
718 /* send northbound notification */
719 isis_notif_if_state_change(circuit
, true);
720 #endif /* ifndef FABRICD */
722 /* Clear the flags for all the lsps of the circuit. */
723 isis_circuit_update_all_srmflags(circuit
, 0);
725 if (circuit
->circ_type
== CIRCUIT_T_BROADCAST
) {
726 /* destroy neighbour lists */
727 if (circuit
->u
.bc
.lan_neighs
[0]) {
728 list_delete(&circuit
->u
.bc
.lan_neighs
[0]);
729 circuit
->u
.bc
.lan_neighs
[0] = NULL
;
731 if (circuit
->u
.bc
.lan_neighs
[1]) {
732 list_delete(&circuit
->u
.bc
.lan_neighs
[1]);
733 circuit
->u
.bc
.lan_neighs
[1] = NULL
;
735 /* destroy adjacency databases */
736 if (circuit
->u
.bc
.adjdb
[0]) {
737 circuit
->u
.bc
.adjdb
[0]->del
= isis_delete_adj
;
738 list_delete(&circuit
->u
.bc
.adjdb
[0]);
739 circuit
->u
.bc
.adjdb
[0] = NULL
;
741 if (circuit
->u
.bc
.adjdb
[1]) {
742 circuit
->u
.bc
.adjdb
[1]->del
= isis_delete_adj
;
743 list_delete(&circuit
->u
.bc
.adjdb
[1]);
744 circuit
->u
.bc
.adjdb
[1] = NULL
;
746 if (circuit
->u
.bc
.is_dr
[0]) {
747 isis_dr_resign(circuit
, 1);
748 circuit
->u
.bc
.is_dr
[0] = 0;
750 memset(circuit
->u
.bc
.l1_desig_is
, 0, ISIS_SYS_ID_LEN
+ 1);
751 if (circuit
->u
.bc
.is_dr
[1]) {
752 isis_dr_resign(circuit
, 2);
753 circuit
->u
.bc
.is_dr
[1] = 0;
755 memset(circuit
->u
.bc
.l2_desig_is
, 0, ISIS_SYS_ID_LEN
+ 1);
756 memset(circuit
->u
.bc
.snpa
, 0, ETH_ALEN
);
758 THREAD_TIMER_OFF(circuit
->u
.bc
.t_send_lan_hello
[0]);
759 THREAD_TIMER_OFF(circuit
->u
.bc
.t_send_lan_hello
[1]);
760 THREAD_TIMER_OFF(circuit
->u
.bc
.t_run_dr
[0]);
761 THREAD_TIMER_OFF(circuit
->u
.bc
.t_run_dr
[1]);
762 THREAD_TIMER_OFF(circuit
->u
.bc
.t_refresh_pseudo_lsp
[0]);
763 THREAD_TIMER_OFF(circuit
->u
.bc
.t_refresh_pseudo_lsp
[1]);
764 circuit
->lsp_regenerate_pending
[0] = 0;
765 circuit
->lsp_regenerate_pending
[1] = 0;
767 _ISIS_CLEAR_FLAG(isis
->circuit_ids_used
, circuit
->circuit_id
);
768 circuit
->circuit_id
= 0;
769 } else if (circuit
->circ_type
== CIRCUIT_T_P2P
) {
770 isis_delete_adj(circuit
->u
.p2p
.neighbor
);
771 circuit
->u
.p2p
.neighbor
= NULL
;
772 THREAD_TIMER_OFF(circuit
->u
.p2p
.t_send_p2p_hello
);
775 /* Cancel all active threads */
776 THREAD_TIMER_OFF(circuit
->t_send_csnp
[0]);
777 THREAD_TIMER_OFF(circuit
->t_send_csnp
[1]);
778 THREAD_TIMER_OFF(circuit
->t_send_psnp
[0]);
779 THREAD_TIMER_OFF(circuit
->t_send_psnp
[1]);
780 THREAD_OFF(circuit
->t_read
);
782 if (circuit
->tx_queue
) {
783 isis_tx_queue_free(circuit
->tx_queue
);
784 circuit
->tx_queue
= NULL
;
787 /* send one gratuitous hello to spead up convergence */
788 if (circuit
->state
== C_STATE_UP
) {
789 if (circuit
->is_type
& IS_LEVEL_1
)
790 send_hello(circuit
, IS_LEVEL_1
);
791 if (circuit
->is_type
& IS_LEVEL_2
)
792 send_hello(circuit
, IS_LEVEL_2
);
795 circuit
->upadjcount
[0] = 0;
796 circuit
->upadjcount
[1] = 0;
798 /* close the socket */
804 if (circuit
->rcv_stream
!= NULL
) {
805 stream_free(circuit
->rcv_stream
);
806 circuit
->rcv_stream
= NULL
;
809 if (circuit
->snd_stream
!= NULL
) {
810 stream_free(circuit
->snd_stream
);
811 circuit
->snd_stream
= NULL
;
814 thread_cancel_event(master
, circuit
);
819 void circuit_update_nlpids(struct isis_circuit
*circuit
)
821 circuit
->nlpids
.count
= 0;
823 if (circuit
->ip_router
) {
824 circuit
->nlpids
.nlpids
[0] = NLPID_IP
;
825 circuit
->nlpids
.count
++;
827 if (circuit
->ipv6_router
) {
828 circuit
->nlpids
.nlpids
[circuit
->nlpids
.count
] = NLPID_IPV6
;
829 circuit
->nlpids
.count
++;
834 void isis_circuit_print_vty(struct isis_circuit
*circuit
, struct vty
*vty
,
837 if (detail
== ISIS_UI_LEVEL_BRIEF
) {
838 vty_out(vty
, " %-12s", circuit
->interface
->name
);
839 vty_out(vty
, "0x%-7x", circuit
->circuit_id
);
840 vty_out(vty
, "%-9s", circuit_state2string(circuit
->state
));
841 vty_out(vty
, "%-9s", circuit_type2string(circuit
->circ_type
));
842 vty_out(vty
, "%-9s", circuit_t2string(circuit
->is_type
));
846 if (detail
== ISIS_UI_LEVEL_DETAIL
) {
847 struct listnode
*node
;
848 struct prefix
*ip_addr
;
851 vty_out(vty
, " Interface: %s", circuit
->interface
->name
);
852 vty_out(vty
, ", State: %s",
853 circuit_state2string(circuit
->state
));
854 if (circuit
->is_passive
)
855 vty_out(vty
, ", Passive");
857 vty_out(vty
, ", Active");
858 vty_out(vty
, ", Circuit Id: 0x%x", circuit
->circuit_id
);
860 vty_out(vty
, " Type: %s",
861 circuit_type2string(circuit
->circ_type
));
862 vty_out(vty
, ", Level: %s", circuit_t2string(circuit
->is_type
));
863 if (circuit
->circ_type
== CIRCUIT_T_BROADCAST
)
864 vty_out(vty
, ", SNPA: %-10s",
865 snpa_print(circuit
->u
.bc
.snpa
));
867 if (circuit
->is_type
& IS_LEVEL_1
) {
868 vty_out(vty
, " Level-1 Information:\n");
869 if (circuit
->area
->newmetric
)
870 vty_out(vty
, " Metric: %d",
871 circuit
->te_metric
[0]);
873 vty_out(vty
, " Metric: %d",
875 if (!circuit
->is_passive
) {
876 vty_out(vty
, ", Active neighbors: %u\n",
877 circuit
->upadjcount
[0]);
879 " Hello interval: %u, "
880 "Holddown count: %u %s\n",
881 circuit
->hello_interval
[0],
882 circuit
->hello_multiplier
[0],
883 (circuit
->pad_hellos
? "(pad)"
886 " CNSP interval: %u, "
887 "PSNP interval: %u\n",
888 circuit
->csnp_interval
[0],
889 circuit
->psnp_interval
[0]);
890 if (circuit
->circ_type
== CIRCUIT_T_BROADCAST
)
892 " LAN Priority: %u, %s\n",
893 circuit
->priority
[0],
894 (circuit
->u
.bc
.is_dr
[0]
901 if (circuit
->is_type
& IS_LEVEL_2
) {
902 vty_out(vty
, " Level-2 Information:\n");
903 if (circuit
->area
->newmetric
)
904 vty_out(vty
, " Metric: %d",
905 circuit
->te_metric
[1]);
907 vty_out(vty
, " Metric: %d",
909 if (!circuit
->is_passive
) {
910 vty_out(vty
, ", Active neighbors: %u\n",
911 circuit
->upadjcount
[1]);
913 " Hello interval: %u, "
914 "Holddown count: %u %s\n",
915 circuit
->hello_interval
[1],
916 circuit
->hello_multiplier
[1],
917 (circuit
->pad_hellos
? "(pad)"
920 " CNSP interval: %u, "
921 "PSNP interval: %u\n",
922 circuit
->csnp_interval
[1],
923 circuit
->psnp_interval
[1]);
924 if (circuit
->circ_type
== CIRCUIT_T_BROADCAST
)
926 " LAN Priority: %u, %s\n",
927 circuit
->priority
[1],
928 (circuit
->u
.bc
.is_dr
[1]
935 if (circuit
->ip_addrs
&& listcount(circuit
->ip_addrs
) > 0) {
936 vty_out(vty
, " IP Prefix(es):\n");
937 for (ALL_LIST_ELEMENTS_RO(circuit
->ip_addrs
, node
,
939 prefix2str(ip_addr
, buf
, sizeof(buf
));
940 vty_out(vty
, " %s\n", buf
);
943 if (circuit
->ipv6_link
&& listcount(circuit
->ipv6_link
) > 0) {
944 vty_out(vty
, " IPv6 Link-Locals:\n");
945 for (ALL_LIST_ELEMENTS_RO(circuit
->ipv6_link
, node
,
947 prefix2str(ip_addr
, (char *)buf
, BUFSIZ
);
948 vty_out(vty
, " %s\n", buf
);
951 if (circuit
->ipv6_non_link
952 && listcount(circuit
->ipv6_non_link
) > 0) {
953 vty_out(vty
, " IPv6 Prefixes:\n");
954 for (ALL_LIST_ELEMENTS_RO(circuit
->ipv6_non_link
, node
,
956 prefix2str(ip_addr
, (char *)buf
, BUFSIZ
);
957 vty_out(vty
, " %s\n", buf
);
967 DEFINE_HOOK(isis_circuit_config_write
,
968 (struct isis_circuit
*circuit
, struct vty
*vty
),
971 static int isis_interface_config_write(struct vty
*vty
)
973 struct vrf
*vrf
= vrf_lookup_by_id(VRF_DEFAULT
);
975 struct listnode
*node
;
976 struct interface
*ifp
;
977 struct isis_area
*area
;
978 struct isis_circuit
*circuit
;
981 FOR_ALL_INTERFACES (vrf
, ifp
) {
983 vty_frame(vty
, "interface %s\n", ifp
->name
);
987 vty_out(vty
, " description %s\n", ifp
->desc
);
991 for (ALL_LIST_ELEMENTS_RO(isis
->area_list
, node
, area
)) {
993 circuit_lookup_by_ifp(ifp
, area
->circuit_list
);
996 if (circuit
->ip_router
) {
997 vty_out(vty
, " ip router " PROTO_NAME
" %s\n",
1001 if (circuit
->is_passive
) {
1002 vty_out(vty
, " " PROTO_NAME
" passive\n");
1005 if (circuit
->circ_type_config
== CIRCUIT_T_P2P
) {
1006 vty_out(vty
, " " PROTO_NAME
" network point-to-point\n");
1009 if (circuit
->ipv6_router
) {
1010 vty_out(vty
, " ipv6 router " PROTO_NAME
" %s\n",
1015 /* ISIS - circuit type */
1017 if (circuit
->is_type
== IS_LEVEL_1
) {
1018 vty_out(vty
, " " PROTO_NAME
" circuit-type level-1\n");
1021 if (circuit
->is_type
== IS_LEVEL_2
) {
1023 " " PROTO_NAME
" circuit-type level-2-only\n");
1029 /* ISIS - CSNP interval */
1030 if (circuit
->csnp_interval
[0]
1031 == circuit
->csnp_interval
[1]) {
1032 if (circuit
->csnp_interval
[0]
1033 != DEFAULT_CSNP_INTERVAL
) {
1034 vty_out(vty
, " " PROTO_NAME
" csnp-interval %d\n",
1035 circuit
->csnp_interval
[0]);
1039 for (i
= 0; i
< 2; i
++) {
1040 if (circuit
->csnp_interval
[i
]
1041 != DEFAULT_CSNP_INTERVAL
) {
1043 " " PROTO_NAME
" csnp-interval %d level-%d\n",
1044 circuit
->csnp_interval
1052 /* ISIS - PSNP interval */
1053 if (circuit
->psnp_interval
[0]
1054 == circuit
->psnp_interval
[1]) {
1055 if (circuit
->psnp_interval
[0]
1056 != DEFAULT_PSNP_INTERVAL
) {
1057 vty_out(vty
, " " PROTO_NAME
" psnp-interval %d\n",
1058 circuit
->psnp_interval
[0]);
1062 for (i
= 0; i
< 2; i
++) {
1063 if (circuit
->psnp_interval
[i
]
1064 != DEFAULT_PSNP_INTERVAL
) {
1066 " " PROTO_NAME
" psnp-interval %d level-%d\n",
1067 circuit
->psnp_interval
1075 /* ISIS - Hello padding - Defaults to true so only
1076 * display if false */
1077 if (circuit
->pad_hellos
== 0) {
1078 vty_out(vty
, " no " PROTO_NAME
" hello padding\n");
1082 if (circuit
->disable_threeway_adj
) {
1083 vty_out(vty
, " no isis three-way-handshake\n");
1087 /* ISIS - Hello interval */
1088 if (circuit
->hello_interval
[0]
1089 == circuit
->hello_interval
[1]) {
1090 if (circuit
->hello_interval
[0]
1091 != DEFAULT_HELLO_INTERVAL
) {
1093 " " PROTO_NAME
" hello-interval %d\n",
1094 circuit
->hello_interval
[0]);
1098 for (i
= 0; i
< 2; i
++) {
1099 if (circuit
->hello_interval
[i
]
1100 != DEFAULT_HELLO_INTERVAL
) {
1102 " " PROTO_NAME
" hello-interval %d level-%d\n",
1103 circuit
->hello_interval
1111 /* ISIS - Hello Multiplier */
1112 if (circuit
->hello_multiplier
[0]
1113 == circuit
->hello_multiplier
[1]) {
1114 if (circuit
->hello_multiplier
[0]
1115 != DEFAULT_HELLO_MULTIPLIER
) {
1117 " " PROTO_NAME
" hello-multiplier %d\n",
1118 circuit
->hello_multiplier
[0]);
1122 for (i
= 0; i
< 2; i
++) {
1123 if (circuit
->hello_multiplier
[i
]
1124 != DEFAULT_HELLO_MULTIPLIER
) {
1126 " " PROTO_NAME
" hello-multiplier %d level-%d\n",
1127 circuit
->hello_multiplier
1135 /* ISIS - Priority */
1136 if (circuit
->priority
[0] == circuit
->priority
[1]) {
1137 if (circuit
->priority
[0] != DEFAULT_PRIORITY
) {
1138 vty_out(vty
, " " PROTO_NAME
" priority %d\n",
1139 circuit
->priority
[0]);
1143 for (i
= 0; i
< 2; i
++) {
1144 if (circuit
->priority
[i
]
1145 != DEFAULT_PRIORITY
) {
1147 " " PROTO_NAME
" priority %d level-%d\n",
1148 circuit
->priority
[i
],
1156 if (circuit
->te_metric
[0] == circuit
->te_metric
[1]) {
1157 if (circuit
->te_metric
[0]
1158 != DEFAULT_CIRCUIT_METRIC
) {
1159 vty_out(vty
, " " PROTO_NAME
" metric %d\n",
1160 circuit
->te_metric
[0]);
1164 for (i
= 0; i
< 2; i
++) {
1165 if (circuit
->te_metric
[i
]
1166 != DEFAULT_CIRCUIT_METRIC
) {
1168 " " PROTO_NAME
" metric %d level-%d\n",
1169 circuit
->te_metric
[i
],
1175 if (circuit
->passwd
.type
== ISIS_PASSWD_TYPE_HMAC_MD5
) {
1176 vty_out(vty
, " " PROTO_NAME
" password md5 %s\n",
1177 circuit
->passwd
.passwd
);
1179 } else if (circuit
->passwd
.type
1180 == ISIS_PASSWD_TYPE_CLEARTXT
) {
1181 vty_out(vty
, " " PROTO_NAME
" password clear %s\n",
1182 circuit
->passwd
.passwd
);
1185 write
+= hook_call(isis_circuit_config_write
,
1188 vty_endframe(vty
, "!\n");
1194 static int isis_interface_config_write(struct vty
*vty
)
1196 struct vrf
*vrf
= vrf_lookup_by_id(VRF_DEFAULT
);
1198 struct interface
*ifp
;
1199 struct lyd_node
*dnode
;
1201 FOR_ALL_INTERFACES (vrf
, ifp
) {
1202 dnode
= yang_dnode_get(
1203 running_config
->dnode
,
1204 "/frr-interface:lib/interface[name='%s'][vrf='%s']",
1205 ifp
->name
, vrf
->name
);
1210 nb_cli_show_dnode_cmds(vty
, dnode
, false);
1214 #endif /* ifdef FABRICD */
1216 struct isis_circuit
*isis_circuit_create(struct isis_area
*area
,
1217 struct interface
*ifp
)
1219 struct isis_circuit
*circuit
= circuit_scan_by_ifp(ifp
);
1220 if (circuit
&& circuit
->area
)
1222 circuit
= isis_csm_state_change(ISIS_ENABLE
, circuit
, area
);
1223 if (circuit
->state
!= C_STATE_CONF
&& circuit
->state
!= C_STATE_UP
)
1225 isis_circuit_if_bind(circuit
, ifp
);
1226 if (circuit
->area
->mta
&& circuit
->area
->mta
->status
)
1227 isis_link_params_update(circuit
, ifp
);
1231 void isis_circuit_af_set(struct isis_circuit
*circuit
, bool ip_router
,
1234 struct isis_area
*area
= circuit
->area
;
1235 bool change
= circuit
->ip_router
!= ip_router
1236 || circuit
->ipv6_router
!= ipv6_router
;
1238 area
->ip_circuits
+= ip_router
- circuit
->ip_router
;
1239 area
->ipv6_circuits
+= ipv6_router
- circuit
->ipv6_router
;
1240 circuit
->ip_router
= ip_router
;
1241 circuit
->ipv6_router
= ipv6_router
;
1246 circuit_update_nlpids(circuit
);
1248 if (!ip_router
&& !ipv6_router
)
1249 isis_csm_state_change(ISIS_DISABLE
, circuit
, area
);
1251 lsp_regenerate_schedule(circuit
->area
, circuit
->is_type
, 0);
1254 ferr_r
isis_circuit_passive_set(struct isis_circuit
*circuit
, bool passive
)
1256 if (circuit
->is_passive
== passive
)
1259 if (if_is_loopback(circuit
->interface
) && !passive
)
1260 return ferr_cfg_invalid("loopback is always passive");
1262 if (circuit
->state
!= C_STATE_UP
) {
1263 circuit
->is_passive
= passive
;
1265 struct isis_area
*area
= circuit
->area
;
1266 isis_csm_state_change(ISIS_DISABLE
, circuit
, area
);
1267 circuit
->is_passive
= passive
;
1268 isis_csm_state_change(ISIS_ENABLE
, circuit
, area
);
1274 ferr_r
isis_circuit_metric_set(struct isis_circuit
*circuit
, int level
,
1277 assert(level
== IS_LEVEL_1
|| level
== IS_LEVEL_2
);
1278 if (metric
> MAX_WIDE_LINK_METRIC
)
1279 return ferr_cfg_invalid("metric %d too large for wide metric",
1281 if (circuit
->area
&& circuit
->area
->oldmetric
1282 && metric
> MAX_NARROW_LINK_METRIC
)
1283 return ferr_cfg_invalid("metric %d too large for narrow metric",
1286 circuit
->te_metric
[level
- 1] = metric
;
1287 circuit
->metric
[level
- 1] = metric
;
1290 lsp_regenerate_schedule(circuit
->area
, level
, 0);
1294 ferr_r
isis_circuit_passwd_unset(struct isis_circuit
*circuit
)
1296 memset(&circuit
->passwd
, 0, sizeof(circuit
->passwd
));
1300 ferr_r
isis_circuit_passwd_set(struct isis_circuit
*circuit
,
1301 uint8_t passwd_type
, const char *passwd
)
1306 return ferr_code_bug("no circuit password given");
1308 len
= strlen(passwd
);
1310 return ferr_code_bug(
1311 "circuit password too long (max 254 chars)");
1313 circuit
->passwd
.len
= len
;
1314 strlcpy((char *)circuit
->passwd
.passwd
, passwd
,
1315 sizeof(circuit
->passwd
.passwd
));
1316 circuit
->passwd
.type
= passwd_type
;
1320 ferr_r
isis_circuit_passwd_cleartext_set(struct isis_circuit
*circuit
,
1323 return isis_circuit_passwd_set(circuit
, ISIS_PASSWD_TYPE_CLEARTXT
,
1327 ferr_r
isis_circuit_passwd_hmac_md5_set(struct isis_circuit
*circuit
,
1330 return isis_circuit_passwd_set(circuit
, ISIS_PASSWD_TYPE_HMAC_MD5
,
1334 struct cmd_node interface_node
= {
1335 .name
= "interface",
1336 .node
= INTERFACE_NODE
,
1337 .parent_node
= CONFIG_NODE
,
1338 .prompt
= "%s(config-if)# ",
1339 .config_write
= isis_interface_config_write
,
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
);
1446 if_zapi_callbacks(isis_ifp_create
, isis_ifp_up
,
1447 isis_ifp_down
, isis_ifp_destroy
);