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"
62 DEFINE_QOBJ_TYPE(isis_circuit
)
67 int isis_interface_config_write(struct vty
*);
68 int isis_if_new_hook(struct interface
*);
69 int isis_if_delete_hook(struct interface
*);
71 struct isis_circuit
*isis_circuit_new(void)
73 struct isis_circuit
*circuit
;
76 circuit
= XCALLOC(MTYPE_ISIS_CIRCUIT
, sizeof(struct isis_circuit
));
82 circuit
->is_type
= yang_get_default_enum(
83 "/frr-interface:lib/interface/frr-isisd:isis/circuit-type");
86 circuit
->pad_hellos
= yang_get_default_bool(
87 "/frr-interface:lib/interface/frr-isisd:isis/hello/padding");
88 circuit
->hello_interval
[0] = yang_get_default_uint32(
89 "/frr-interface:lib/interface/frr-isisd:isis/hello/interval/level-1");
90 circuit
->hello_interval
[1] = yang_get_default_uint32(
91 "/frr-interface:lib/interface/frr-isisd:isis/hello/interval/level-2");
92 circuit
->hello_multiplier
[0] = yang_get_default_uint32(
93 "/frr-interface:lib/interface/frr-isisd:isis/hello/multiplier/level-1");
94 circuit
->hello_multiplier
[1] = yang_get_default_uint32(
95 "/frr-interface:lib/interface/frr-isisd:isis/hello/multiplier/level-2");
96 circuit
->csnp_interval
[0] = yang_get_default_uint16(
97 "/frr-interface:lib/interface/frr-isisd:isis/csnp-interval/level-1");
98 circuit
->csnp_interval
[1] = yang_get_default_uint16(
99 "/frr-interface:lib/interface/frr-isisd:isis/csnp-interval/level-2");
100 circuit
->psnp_interval
[0] = yang_get_default_uint16(
101 "/frr-interface:lib/interface/frr-isisd:isis/psnp-interval/level-1");
102 circuit
->psnp_interval
[1] = yang_get_default_uint16(
103 "/frr-interface:lib/interface/frr-isisd:isis/psnp-interval/level-2");
104 circuit
->priority
[0] = yang_get_default_uint8(
105 "/frr-interface:lib/interface/frr-isisd:isis/priority/level-1");
106 circuit
->priority
[1] = yang_get_default_uint8(
107 "/frr-interface:lib/interface/frr-isisd:isis/priority/level-2");
108 circuit
->metric
[0] = yang_get_default_uint32(
109 "/frr-interface:lib/interface/frr-isisd:isis/metric/level-1");
110 circuit
->metric
[1] = yang_get_default_uint32(
111 "/frr-interface:lib/interface/frr-isisd:isis/metric/level-2");
112 circuit
->te_metric
[0] = yang_get_default_uint32(
113 "/frr-interface:lib/interface/frr-isisd:isis/metric/level-1");
114 circuit
->te_metric
[1] = yang_get_default_uint32(
115 "/frr-interface:lib/interface/frr-isisd:isis/metric/level-2");
117 for (i
= 0; i
< 2; i
++) {
118 circuit
->level_arg
[i
].level
= i
+ 1;
119 circuit
->level_arg
[i
].circuit
= circuit
;
122 circuit
->is_type
= IS_LEVEL_1_AND_2
;
124 circuit
->pad_hellos
= 1;
125 for (i
= 0; i
< 2; i
++) {
126 circuit
->hello_interval
[i
] = DEFAULT_HELLO_INTERVAL
;
127 circuit
->hello_multiplier
[i
] = DEFAULT_HELLO_MULTIPLIER
;
128 circuit
->csnp_interval
[i
] = DEFAULT_CSNP_INTERVAL
;
129 circuit
->psnp_interval
[i
] = DEFAULT_PSNP_INTERVAL
;
130 circuit
->priority
[i
] = DEFAULT_PRIORITY
;
131 circuit
->metric
[i
] = DEFAULT_CIRCUIT_METRIC
;
132 circuit
->te_metric
[i
] = DEFAULT_CIRCUIT_METRIC
;
133 circuit
->level_arg
[i
].level
= i
+ 1;
134 circuit
->level_arg
[i
].circuit
= circuit
;
136 #endif /* ifndef FABRICD */
138 circuit
->mtc
= mpls_te_circuit_new();
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 MPLS TE Local IP address parameter */
270 set_circuitparams_local_ipaddr(circuit
->mtc
, ipv4
->prefix
);
273 lsp_regenerate_schedule(circuit
->area
, circuit
->is_type
,
277 prefix2str(connected
->address
, buf
, sizeof(buf
));
278 zlog_debug("Added IP address %s to circuit %s", buf
,
279 circuit
->interface
->name
);
280 #endif /* EXTREME_DEBUG */
282 if (connected
->address
->family
== AF_INET6
) {
283 if (IN6_IS_ADDR_LOOPBACK(&connected
->address
->u
.prefix6
))
286 for (ALL_LIST_ELEMENTS_RO(circuit
->ipv6_link
, node
, ipv6
))
287 if (prefix_same((struct prefix
*)ipv6
,
290 for (ALL_LIST_ELEMENTS_RO(circuit
->ipv6_non_link
, node
, ipv6
))
291 if (prefix_same((struct prefix
*)ipv6
,
295 ipv6
= prefix_ipv6_new();
296 ipv6
->prefixlen
= connected
->address
->prefixlen
;
297 ipv6
->prefix
= connected
->address
->u
.prefix6
;
299 if (IN6_IS_ADDR_LINKLOCAL(&ipv6
->prefix
))
300 listnode_add(circuit
->ipv6_link
, ipv6
);
302 listnode_add(circuit
->ipv6_non_link
, ipv6
);
304 lsp_regenerate_schedule(circuit
->area
, circuit
->is_type
,
308 prefix2str(connected
->address
, buf
, sizeof(buf
));
309 zlog_debug("Added IPv6 address %s to circuit %s", buf
,
310 circuit
->interface
->name
);
311 #endif /* EXTREME_DEBUG */
316 void isis_circuit_del_addr(struct isis_circuit
*circuit
,
317 struct connected
*connected
)
319 struct prefix_ipv4
*ipv4
, *ip
= NULL
;
320 struct listnode
*node
;
321 char buf
[PREFIX2STR_BUFFER
];
322 struct prefix_ipv6
*ipv6
, *ip6
= NULL
;
325 if (connected
->address
->family
== AF_INET
) {
326 ipv4
= prefix_ipv4_new();
327 ipv4
->prefixlen
= connected
->address
->prefixlen
;
328 ipv4
->prefix
= connected
->address
->u
.prefix4
;
330 for (ALL_LIST_ELEMENTS_RO(circuit
->ip_addrs
, node
, ip
))
331 if (prefix_same((struct prefix
*)ip
,
332 (struct prefix
*)ipv4
))
336 listnode_delete(circuit
->ip_addrs
, ip
);
337 prefix_ipv4_free(ip
);
339 lsp_regenerate_schedule(circuit
->area
,
340 circuit
->is_type
, 0);
342 prefix2str(connected
->address
, buf
, sizeof(buf
));
344 "Nonexistent ip address %s removal attempt from \
346 buf
, circuit
->interface
->name
);
347 zlog_warn("Current ip addresses on %s:",
348 circuit
->interface
->name
);
349 for (ALL_LIST_ELEMENTS_RO(circuit
->ip_addrs
, node
,
351 prefix2str(ip
, buf
, sizeof(buf
));
352 zlog_warn(" %s", buf
);
354 zlog_warn("End of addresses");
357 prefix_ipv4_free(ipv4
);
359 if (connected
->address
->family
== AF_INET6
) {
360 ipv6
= prefix_ipv6_new();
361 ipv6
->prefixlen
= connected
->address
->prefixlen
;
362 ipv6
->prefix
= connected
->address
->u
.prefix6
;
364 if (IN6_IS_ADDR_LINKLOCAL(&ipv6
->prefix
)) {
365 for (ALL_LIST_ELEMENTS_RO(circuit
->ipv6_link
, node
,
367 if (prefix_same((struct prefix
*)ip6
,
368 (struct prefix
*)ipv6
))
372 listnode_delete(circuit
->ipv6_link
, ip6
);
373 prefix_ipv6_free(ip6
);
377 for (ALL_LIST_ELEMENTS_RO(circuit
->ipv6_non_link
, node
,
379 if (prefix_same((struct prefix
*)ip6
,
380 (struct prefix
*)ipv6
))
384 listnode_delete(circuit
->ipv6_non_link
, ip6
);
385 prefix_ipv6_free(ip6
);
391 prefix2str(connected
->address
, buf
, sizeof(buf
));
393 "Nonexistent ip address %s removal attempt from \
395 buf
, circuit
->interface
->name
);
396 zlog_warn("Current ip addresses on %s:",
397 circuit
->interface
->name
);
398 for (ALL_LIST_ELEMENTS_RO(circuit
->ipv6_link
, node
,
400 prefix2str((struct prefix
*)ip6
, (char *)buf
,
402 zlog_warn(" %s", buf
);
405 for (ALL_LIST_ELEMENTS_RO(circuit
->ipv6_non_link
, node
,
407 prefix2str((struct prefix
*)ip6
, (char *)buf
,
409 zlog_warn(" %s", buf
);
411 zlog_warn("End of addresses");
412 } else if (circuit
->area
)
413 lsp_regenerate_schedule(circuit
->area
, circuit
->is_type
,
416 prefix_ipv6_free(ipv6
);
421 static uint8_t isis_circuit_id_gen(struct isis
*isis
, struct interface
*ifp
)
423 /* Circuit ids MUST be unique for any broadcast circuits. Otherwise,
424 * Pseudo-Node LSPs cannot be generated correctly.
426 * Currently, allocate one circuit ID for any circuit, limiting the total
427 * numer of circuits IS-IS can run on to 255.
429 * We should revisit this when implementing 3-way adjacencies for p2p, since
430 * we then have extended interface IDs available.
432 uint8_t id
= ifp
->ifindex
;
435 for (i
= 0; i
< 256; i
++) {
436 if (id
&& !_ISIS_CHECK_FLAG(isis
->circuit_ids_used
, id
))
442 zlog_warn("Could not allocate a circuit id for '%s'",
447 _ISIS_SET_FLAG(isis
->circuit_ids_used
, id
);
451 void isis_circuit_if_add(struct isis_circuit
*circuit
, struct interface
*ifp
)
453 struct listnode
*node
, *nnode
;
454 struct connected
*conn
;
456 isis_circuit_if_bind(circuit
, ifp
);
458 if (if_is_broadcast(ifp
)) {
459 if (fabricd
|| circuit
->circ_type_config
== CIRCUIT_T_P2P
)
460 circuit
->circ_type
= CIRCUIT_T_P2P
;
462 circuit
->circ_type
= CIRCUIT_T_BROADCAST
;
463 } else if (if_is_pointopoint(ifp
)) {
464 circuit
->circ_type
= CIRCUIT_T_P2P
;
465 } else if (if_is_loopback(ifp
)) {
466 circuit
->circ_type
= CIRCUIT_T_LOOPBACK
;
467 circuit
->is_passive
= 1;
469 /* It's normal in case of loopback etc. */
470 if (isis
->debugs
& DEBUG_EVENTS
)
471 zlog_debug("isis_circuit_if_add: unsupported media");
472 circuit
->circ_type
= CIRCUIT_T_UNKNOWN
;
475 circuit
->ip_addrs
= list_new();
476 circuit
->ipv6_link
= list_new();
477 circuit
->ipv6_non_link
= list_new();
479 for (ALL_LIST_ELEMENTS(ifp
->connected
, node
, nnode
, conn
))
480 isis_circuit_add_addr(circuit
, conn
);
483 void isis_circuit_if_del(struct isis_circuit
*circuit
, struct interface
*ifp
)
485 struct listnode
*node
, *nnode
;
486 struct connected
*conn
;
488 assert(circuit
->interface
== ifp
);
490 /* destroy addresses */
491 for (ALL_LIST_ELEMENTS(ifp
->connected
, node
, nnode
, conn
))
492 isis_circuit_del_addr(circuit
, conn
);
494 if (circuit
->ip_addrs
) {
495 assert(listcount(circuit
->ip_addrs
) == 0);
496 list_delete(&circuit
->ip_addrs
);
499 if (circuit
->ipv6_link
) {
500 assert(listcount(circuit
->ipv6_link
) == 0);
501 list_delete(&circuit
->ipv6_link
);
504 if (circuit
->ipv6_non_link
) {
505 assert(listcount(circuit
->ipv6_non_link
) == 0);
506 list_delete(&circuit
->ipv6_non_link
);
509 circuit
->circ_type
= CIRCUIT_T_UNKNOWN
;
512 void isis_circuit_if_bind(struct isis_circuit
*circuit
, struct interface
*ifp
)
514 assert(circuit
!= NULL
);
516 if (circuit
->interface
)
517 assert(circuit
->interface
== ifp
);
519 circuit
->interface
= ifp
;
521 assert(ifp
->info
== circuit
);
524 isis_link_params_update(circuit
, ifp
);
527 void isis_circuit_if_unbind(struct isis_circuit
*circuit
, struct interface
*ifp
)
529 assert(circuit
!= NULL
);
531 assert(circuit
->interface
== ifp
);
532 assert(ifp
->info
== circuit
);
533 circuit
->interface
= NULL
;
537 static void isis_circuit_update_all_srmflags(struct isis_circuit
*circuit
,
540 struct isis_area
*area
;
541 struct isis_lsp
*lsp
;
545 area
= circuit
->area
;
547 for (level
= ISIS_LEVEL1
; level
<= ISIS_LEVEL2
; level
++) {
548 if (!(level
& circuit
->is_type
))
551 if (!lspdb_count(&area
->lspdb
[level
- 1]))
554 for_each (lspdb
, &area
->lspdb
[level
- 1], lsp
) {
556 isis_tx_queue_add(circuit
->tx_queue
, lsp
,
559 isis_tx_queue_del(circuit
->tx_queue
, lsp
);
565 size_t isis_circuit_pdu_size(struct isis_circuit
*circuit
)
567 return ISO_MTU(circuit
);
570 void isis_circuit_stream(struct isis_circuit
*circuit
, struct stream
**stream
)
572 size_t stream_size
= isis_circuit_pdu_size(circuit
);
575 *stream
= stream_new(stream_size
);
577 if (STREAM_SIZE(*stream
) != stream_size
)
578 stream_resize_inplace(stream
, stream_size
);
579 stream_reset(*stream
);
583 void isis_circuit_prepare(struct isis_circuit
*circuit
)
585 #if ISIS_METHOD != ISIS_METHOD_DLPI
586 thread_add_read(master
, isis_receive
, circuit
, circuit
->fd
,
589 thread_add_timer_msec(master
, isis_receive
, circuit
,
590 listcount(circuit
->area
->circuit_list
) * 100,
595 int isis_circuit_up(struct isis_circuit
*circuit
)
599 /* Set the flags for all the lsps of the circuit. */
600 isis_circuit_update_all_srmflags(circuit
, 1);
602 if (circuit
->state
== C_STATE_UP
)
605 if (circuit
->is_passive
)
608 if (circuit
->area
->lsp_mtu
> isis_circuit_pdu_size(circuit
)) {
611 "Interface MTU %zu on %s is too low to support area lsp mtu %u!",
612 isis_circuit_pdu_size(circuit
),
613 circuit
->interface
->name
, circuit
->area
->lsp_mtu
);
614 isis_circuit_update_all_srmflags(circuit
, 0);
618 if (circuit
->circ_type
== CIRCUIT_T_BROADCAST
) {
619 circuit
->circuit_id
= isis_circuit_id_gen(isis
, circuit
->interface
);
620 if (!circuit
->circuit_id
) {
623 "There are already 255 broadcast circuits active!");
628 * Get the Hardware Address
630 if (circuit
->interface
->hw_addr_len
!= ETH_ALEN
) {
631 zlog_warn("unsupported link layer");
633 memcpy(circuit
->u
.bc
.snpa
, circuit
->interface
->hw_addr
,
637 zlog_debug("isis_circuit_if_add: if_id %d, isomtu %d snpa %s",
638 circuit
->interface
->ifindex
, ISO_MTU(circuit
),
639 snpa_print(circuit
->u
.bc
.snpa
));
640 #endif /* EXTREME_DEBUG */
642 circuit
->u
.bc
.adjdb
[0] = list_new();
643 circuit
->u
.bc
.adjdb
[1] = list_new();
646 * ISO 10589 - 8.4.1 Enabling of broadcast circuits
649 /* initilizing the hello sending threads
653 /* 8.4.1 a) commence sending of IIH PDUs */
655 for (int level
= ISIS_LEVEL1
; level
<= ISIS_LEVEL2
; level
++) {
656 if (!(circuit
->is_type
& level
))
659 send_hello_sched(circuit
, level
, TRIGGERED_IIH_DELAY
);
660 circuit
->u
.bc
.lan_neighs
[level
- 1] = list_new();
662 thread_add_timer(master
, isis_run_dr
,
663 &circuit
->level_arg
[level
- 1],
664 2 * circuit
->hello_interval
[level
- 1],
665 &circuit
->u
.bc
.t_run_dr
[level
- 1]);
668 /* 8.4.1 b) FIXME: solicit ES - 8.4.6 */
669 /* 8.4.1 c) FIXME: listen for ESH PDUs */
670 } else if (circuit
->circ_type
== CIRCUIT_T_P2P
) {
671 /* initializing the hello send threads
674 circuit
->u
.p2p
.neighbor
= NULL
;
675 send_hello_sched(circuit
, 0, TRIGGERED_IIH_DELAY
);
678 /* initializing PSNP timers */
679 if (circuit
->is_type
& IS_LEVEL_1
)
681 master
, send_l1_psnp
, circuit
,
682 isis_jitter(circuit
->psnp_interval
[0], PSNP_JITTER
),
683 &circuit
->t_send_psnp
[0]);
685 if (circuit
->is_type
& IS_LEVEL_2
)
687 master
, send_l2_psnp
, circuit
,
688 isis_jitter(circuit
->psnp_interval
[1], PSNP_JITTER
),
689 &circuit
->t_send_psnp
[1]);
691 /* unified init for circuits; ignore warnings below this level */
692 retv
= isis_sock_init(circuit
);
693 if (retv
!= ISIS_OK
) {
694 isis_circuit_down(circuit
);
698 /* initialize the circuit streams after opening connection */
699 isis_circuit_stream(circuit
, &circuit
->rcv_stream
);
700 isis_circuit_stream(circuit
, &circuit
->snd_stream
);
702 isis_circuit_prepare(circuit
);
704 circuit
->tx_queue
= isis_tx_queue_new(circuit
, send_lsp
);
707 /* send northbound notification */
708 isis_notif_if_state_change(circuit
, false);
709 #endif /* ifndef FABRICD */
714 void isis_circuit_down(struct isis_circuit
*circuit
)
717 /* send northbound notification */
718 isis_notif_if_state_change(circuit
, true);
719 #endif /* ifndef FABRICD */
721 /* Clear the flags for all the lsps of the circuit. */
722 isis_circuit_update_all_srmflags(circuit
, 0);
724 if (circuit
->circ_type
== CIRCUIT_T_BROADCAST
) {
725 /* destroy neighbour lists */
726 if (circuit
->u
.bc
.lan_neighs
[0]) {
727 list_delete(&circuit
->u
.bc
.lan_neighs
[0]);
728 circuit
->u
.bc
.lan_neighs
[0] = NULL
;
730 if (circuit
->u
.bc
.lan_neighs
[1]) {
731 list_delete(&circuit
->u
.bc
.lan_neighs
[1]);
732 circuit
->u
.bc
.lan_neighs
[1] = NULL
;
734 /* destroy adjacency databases */
735 if (circuit
->u
.bc
.adjdb
[0]) {
736 circuit
->u
.bc
.adjdb
[0]->del
= isis_delete_adj
;
737 list_delete(&circuit
->u
.bc
.adjdb
[0]);
738 circuit
->u
.bc
.adjdb
[0] = NULL
;
740 if (circuit
->u
.bc
.adjdb
[1]) {
741 circuit
->u
.bc
.adjdb
[1]->del
= isis_delete_adj
;
742 list_delete(&circuit
->u
.bc
.adjdb
[1]);
743 circuit
->u
.bc
.adjdb
[1] = NULL
;
745 if (circuit
->u
.bc
.is_dr
[0]) {
746 isis_dr_resign(circuit
, 1);
747 circuit
->u
.bc
.is_dr
[0] = 0;
749 memset(circuit
->u
.bc
.l1_desig_is
, 0, ISIS_SYS_ID_LEN
+ 1);
750 if (circuit
->u
.bc
.is_dr
[1]) {
751 isis_dr_resign(circuit
, 2);
752 circuit
->u
.bc
.is_dr
[1] = 0;
754 memset(circuit
->u
.bc
.l2_desig_is
, 0, ISIS_SYS_ID_LEN
+ 1);
755 memset(circuit
->u
.bc
.snpa
, 0, ETH_ALEN
);
757 THREAD_TIMER_OFF(circuit
->u
.bc
.t_send_lan_hello
[0]);
758 THREAD_TIMER_OFF(circuit
->u
.bc
.t_send_lan_hello
[1]);
759 THREAD_TIMER_OFF(circuit
->u
.bc
.t_run_dr
[0]);
760 THREAD_TIMER_OFF(circuit
->u
.bc
.t_run_dr
[1]);
761 THREAD_TIMER_OFF(circuit
->u
.bc
.t_refresh_pseudo_lsp
[0]);
762 THREAD_TIMER_OFF(circuit
->u
.bc
.t_refresh_pseudo_lsp
[1]);
763 circuit
->lsp_regenerate_pending
[0] = 0;
764 circuit
->lsp_regenerate_pending
[1] = 0;
766 _ISIS_CLEAR_FLAG(isis
->circuit_ids_used
, circuit
->circuit_id
);
767 circuit
->circuit_id
= 0;
768 } else if (circuit
->circ_type
== CIRCUIT_T_P2P
) {
769 isis_delete_adj(circuit
->u
.p2p
.neighbor
);
770 circuit
->u
.p2p
.neighbor
= NULL
;
771 THREAD_TIMER_OFF(circuit
->u
.p2p
.t_send_p2p_hello
);
774 /* Cancel all active threads */
775 THREAD_TIMER_OFF(circuit
->t_send_csnp
[0]);
776 THREAD_TIMER_OFF(circuit
->t_send_csnp
[1]);
777 THREAD_TIMER_OFF(circuit
->t_send_psnp
[0]);
778 THREAD_TIMER_OFF(circuit
->t_send_psnp
[1]);
779 THREAD_OFF(circuit
->t_read
);
781 if (circuit
->tx_queue
) {
782 isis_tx_queue_free(circuit
->tx_queue
);
783 circuit
->tx_queue
= NULL
;
786 /* send one gratuitous hello to spead up convergence */
787 if (circuit
->state
== C_STATE_UP
) {
788 if (circuit
->is_type
& IS_LEVEL_1
)
789 send_hello(circuit
, IS_LEVEL_1
);
790 if (circuit
->is_type
& IS_LEVEL_2
)
791 send_hello(circuit
, IS_LEVEL_2
);
794 circuit
->upadjcount
[0] = 0;
795 circuit
->upadjcount
[1] = 0;
797 /* close the socket */
803 if (circuit
->rcv_stream
!= NULL
) {
804 stream_free(circuit
->rcv_stream
);
805 circuit
->rcv_stream
= NULL
;
808 if (circuit
->snd_stream
!= NULL
) {
809 stream_free(circuit
->snd_stream
);
810 circuit
->snd_stream
= NULL
;
813 thread_cancel_event(master
, circuit
);
818 void circuit_update_nlpids(struct isis_circuit
*circuit
)
820 circuit
->nlpids
.count
= 0;
822 if (circuit
->ip_router
) {
823 circuit
->nlpids
.nlpids
[0] = NLPID_IP
;
824 circuit
->nlpids
.count
++;
826 if (circuit
->ipv6_router
) {
827 circuit
->nlpids
.nlpids
[circuit
->nlpids
.count
] = NLPID_IPV6
;
828 circuit
->nlpids
.count
++;
833 void isis_circuit_print_vty(struct isis_circuit
*circuit
, struct vty
*vty
,
836 if (detail
== ISIS_UI_LEVEL_BRIEF
) {
837 vty_out(vty
, " %-12s", circuit
->interface
->name
);
838 vty_out(vty
, "0x%-7x", circuit
->circuit_id
);
839 vty_out(vty
, "%-9s", circuit_state2string(circuit
->state
));
840 vty_out(vty
, "%-9s", circuit_type2string(circuit
->circ_type
));
841 vty_out(vty
, "%-9s", circuit_t2string(circuit
->is_type
));
845 if (detail
== ISIS_UI_LEVEL_DETAIL
) {
846 struct listnode
*node
;
847 struct prefix
*ip_addr
;
850 vty_out(vty
, " Interface: %s", circuit
->interface
->name
);
851 vty_out(vty
, ", State: %s",
852 circuit_state2string(circuit
->state
));
853 if (circuit
->is_passive
)
854 vty_out(vty
, ", Passive");
856 vty_out(vty
, ", Active");
857 vty_out(vty
, ", Circuit Id: 0x%x", circuit
->circuit_id
);
859 vty_out(vty
, " Type: %s",
860 circuit_type2string(circuit
->circ_type
));
861 vty_out(vty
, ", Level: %s", circuit_t2string(circuit
->is_type
));
862 if (circuit
->circ_type
== CIRCUIT_T_BROADCAST
)
863 vty_out(vty
, ", SNPA: %-10s",
864 snpa_print(circuit
->u
.bc
.snpa
));
866 if (circuit
->is_type
& IS_LEVEL_1
) {
867 vty_out(vty
, " Level-1 Information:\n");
868 if (circuit
->area
->newmetric
)
869 vty_out(vty
, " Metric: %d",
870 circuit
->te_metric
[0]);
872 vty_out(vty
, " Metric: %d",
874 if (!circuit
->is_passive
) {
875 vty_out(vty
, ", Active neighbors: %u\n",
876 circuit
->upadjcount
[0]);
878 " Hello interval: %u, "
879 "Holddown count: %u %s\n",
880 circuit
->hello_interval
[0],
881 circuit
->hello_multiplier
[0],
882 (circuit
->pad_hellos
? "(pad)"
885 " CNSP interval: %u, "
886 "PSNP interval: %u\n",
887 circuit
->csnp_interval
[0],
888 circuit
->psnp_interval
[0]);
889 if (circuit
->circ_type
== CIRCUIT_T_BROADCAST
)
891 " LAN Priority: %u, %s\n",
892 circuit
->priority
[0],
893 (circuit
->u
.bc
.is_dr
[0]
900 if (circuit
->is_type
& IS_LEVEL_2
) {
901 vty_out(vty
, " Level-2 Information:\n");
902 if (circuit
->area
->newmetric
)
903 vty_out(vty
, " Metric: %d",
904 circuit
->te_metric
[1]);
906 vty_out(vty
, " Metric: %d",
908 if (!circuit
->is_passive
) {
909 vty_out(vty
, ", Active neighbors: %u\n",
910 circuit
->upadjcount
[1]);
912 " Hello interval: %u, "
913 "Holddown count: %u %s\n",
914 circuit
->hello_interval
[1],
915 circuit
->hello_multiplier
[1],
916 (circuit
->pad_hellos
? "(pad)"
919 " CNSP interval: %u, "
920 "PSNP interval: %u\n",
921 circuit
->csnp_interval
[1],
922 circuit
->psnp_interval
[1]);
923 if (circuit
->circ_type
== CIRCUIT_T_BROADCAST
)
925 " LAN Priority: %u, %s\n",
926 circuit
->priority
[1],
927 (circuit
->u
.bc
.is_dr
[1]
934 if (circuit
->ip_addrs
&& listcount(circuit
->ip_addrs
) > 0) {
935 vty_out(vty
, " IP Prefix(es):\n");
936 for (ALL_LIST_ELEMENTS_RO(circuit
->ip_addrs
, node
,
938 prefix2str(ip_addr
, buf
, sizeof(buf
));
939 vty_out(vty
, " %s\n", buf
);
942 if (circuit
->ipv6_link
&& listcount(circuit
->ipv6_link
) > 0) {
943 vty_out(vty
, " IPv6 Link-Locals:\n");
944 for (ALL_LIST_ELEMENTS_RO(circuit
->ipv6_link
, node
,
946 prefix2str(ip_addr
, (char *)buf
, BUFSIZ
);
947 vty_out(vty
, " %s\n", buf
);
950 if (circuit
->ipv6_non_link
951 && listcount(circuit
->ipv6_non_link
) > 0) {
952 vty_out(vty
, " IPv6 Prefixes:\n");
953 for (ALL_LIST_ELEMENTS_RO(circuit
->ipv6_non_link
, node
,
955 prefix2str(ip_addr
, (char *)buf
, BUFSIZ
);
956 vty_out(vty
, " %s\n", buf
);
965 DEFINE_HOOK(isis_circuit_config_write
,
966 (struct isis_circuit
*circuit
, struct vty
*vty
),
970 int isis_interface_config_write(struct vty
*vty
)
972 struct vrf
*vrf
= vrf_lookup_by_id(VRF_DEFAULT
);
974 struct listnode
*node
;
975 struct interface
*ifp
;
976 struct isis_area
*area
;
977 struct isis_circuit
*circuit
;
980 FOR_ALL_INTERFACES (vrf
, ifp
) {
982 vty_frame(vty
, "interface %s\n", ifp
->name
);
986 vty_out(vty
, " description %s\n", ifp
->desc
);
990 for (ALL_LIST_ELEMENTS_RO(isis
->area_list
, node
, area
)) {
992 circuit_lookup_by_ifp(ifp
, area
->circuit_list
);
995 if (circuit
->ip_router
) {
996 vty_out(vty
, " ip router " PROTO_NAME
" %s\n",
1000 if (circuit
->is_passive
) {
1001 vty_out(vty
, " " PROTO_NAME
" passive\n");
1004 if (circuit
->circ_type_config
== CIRCUIT_T_P2P
) {
1005 vty_out(vty
, " " PROTO_NAME
" network point-to-point\n");
1008 if (circuit
->ipv6_router
) {
1009 vty_out(vty
, " ipv6 router " PROTO_NAME
" %s\n",
1014 /* ISIS - circuit type */
1016 if (circuit
->is_type
== IS_LEVEL_1
) {
1017 vty_out(vty
, " " PROTO_NAME
" circuit-type level-1\n");
1020 if (circuit
->is_type
== IS_LEVEL_2
) {
1022 " " PROTO_NAME
" circuit-type level-2-only\n");
1028 /* ISIS - CSNP interval */
1029 if (circuit
->csnp_interval
[0]
1030 == circuit
->csnp_interval
[1]) {
1031 if (circuit
->csnp_interval
[0]
1032 != DEFAULT_CSNP_INTERVAL
) {
1033 vty_out(vty
, " " PROTO_NAME
" csnp-interval %d\n",
1034 circuit
->csnp_interval
[0]);
1038 for (i
= 0; i
< 2; i
++) {
1039 if (circuit
->csnp_interval
[i
]
1040 != DEFAULT_CSNP_INTERVAL
) {
1042 " " PROTO_NAME
" csnp-interval %d level-%d\n",
1043 circuit
->csnp_interval
1051 /* ISIS - PSNP interval */
1052 if (circuit
->psnp_interval
[0]
1053 == circuit
->psnp_interval
[1]) {
1054 if (circuit
->psnp_interval
[0]
1055 != DEFAULT_PSNP_INTERVAL
) {
1056 vty_out(vty
, " " PROTO_NAME
" psnp-interval %d\n",
1057 circuit
->psnp_interval
[0]);
1061 for (i
= 0; i
< 2; i
++) {
1062 if (circuit
->psnp_interval
[i
]
1063 != DEFAULT_PSNP_INTERVAL
) {
1065 " " PROTO_NAME
" psnp-interval %d level-%d\n",
1066 circuit
->psnp_interval
1074 /* ISIS - Hello padding - Defaults to true so only
1075 * display if false */
1076 if (circuit
->pad_hellos
== 0) {
1077 vty_out(vty
, " no " PROTO_NAME
" hello padding\n");
1081 if (circuit
->disable_threeway_adj
) {
1082 vty_out(vty
, " no isis three-way-handshake\n");
1086 /* ISIS - Hello interval */
1087 if (circuit
->hello_interval
[0]
1088 == circuit
->hello_interval
[1]) {
1089 if (circuit
->hello_interval
[0]
1090 != DEFAULT_HELLO_INTERVAL
) {
1092 " " PROTO_NAME
" hello-interval %d\n",
1093 circuit
->hello_interval
[0]);
1097 for (i
= 0; i
< 2; i
++) {
1098 if (circuit
->hello_interval
[i
]
1099 != DEFAULT_HELLO_INTERVAL
) {
1101 " " PROTO_NAME
" hello-interval %d level-%d\n",
1102 circuit
->hello_interval
1110 /* ISIS - Hello Multiplier */
1111 if (circuit
->hello_multiplier
[0]
1112 == circuit
->hello_multiplier
[1]) {
1113 if (circuit
->hello_multiplier
[0]
1114 != DEFAULT_HELLO_MULTIPLIER
) {
1116 " " PROTO_NAME
" hello-multiplier %d\n",
1117 circuit
->hello_multiplier
[0]);
1121 for (i
= 0; i
< 2; i
++) {
1122 if (circuit
->hello_multiplier
[i
]
1123 != DEFAULT_HELLO_MULTIPLIER
) {
1125 " " PROTO_NAME
" hello-multiplier %d level-%d\n",
1126 circuit
->hello_multiplier
1134 /* ISIS - Priority */
1135 if (circuit
->priority
[0] == circuit
->priority
[1]) {
1136 if (circuit
->priority
[0] != DEFAULT_PRIORITY
) {
1137 vty_out(vty
, " " PROTO_NAME
" priority %d\n",
1138 circuit
->priority
[0]);
1142 for (i
= 0; i
< 2; i
++) {
1143 if (circuit
->priority
[i
]
1144 != DEFAULT_PRIORITY
) {
1146 " " PROTO_NAME
" priority %d level-%d\n",
1147 circuit
->priority
[i
],
1155 if (circuit
->te_metric
[0] == circuit
->te_metric
[1]) {
1156 if (circuit
->te_metric
[0]
1157 != DEFAULT_CIRCUIT_METRIC
) {
1158 vty_out(vty
, " " PROTO_NAME
" metric %d\n",
1159 circuit
->te_metric
[0]);
1163 for (i
= 0; i
< 2; i
++) {
1164 if (circuit
->te_metric
[i
]
1165 != DEFAULT_CIRCUIT_METRIC
) {
1167 " " PROTO_NAME
" metric %d level-%d\n",
1168 circuit
->te_metric
[i
],
1174 if (circuit
->passwd
.type
== ISIS_PASSWD_TYPE_HMAC_MD5
) {
1175 vty_out(vty
, " " PROTO_NAME
" password md5 %s\n",
1176 circuit
->passwd
.passwd
);
1178 } else if (circuit
->passwd
.type
1179 == ISIS_PASSWD_TYPE_CLEARTXT
) {
1180 vty_out(vty
, " " PROTO_NAME
" password clear %s\n",
1181 circuit
->passwd
.passwd
);
1184 write
+= hook_call(isis_circuit_config_write
,
1187 vty_endframe(vty
, "!\n");
1193 int isis_interface_config_write(struct vty
*vty
)
1195 struct vrf
*vrf
= vrf_lookup_by_id(VRF_DEFAULT
);
1197 struct interface
*ifp
;
1198 struct isis_circuit
*circuit
;
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);
1211 circuit
= circuit_scan_by_ifp(ifp
);
1213 write
+= hook_call(isis_circuit_config_write
, circuit
,
1218 #endif /* ifdef FABRICD */
1220 struct isis_circuit
*isis_circuit_create(struct isis_area
*area
,
1221 struct interface
*ifp
)
1223 struct isis_circuit
*circuit
= circuit_scan_by_ifp(ifp
);
1224 if (circuit
&& circuit
->area
)
1226 circuit
= isis_csm_state_change(ISIS_ENABLE
, circuit
, area
);
1227 if (circuit
->state
!= C_STATE_CONF
&& circuit
->state
!= C_STATE_UP
)
1229 isis_circuit_if_bind(circuit
, ifp
);
1233 void isis_circuit_af_set(struct isis_circuit
*circuit
, bool ip_router
,
1236 struct isis_area
*area
= circuit
->area
;
1237 bool change
= circuit
->ip_router
!= ip_router
1238 || circuit
->ipv6_router
!= ipv6_router
;
1240 area
->ip_circuits
+= ip_router
- circuit
->ip_router
;
1241 area
->ipv6_circuits
+= ipv6_router
- circuit
->ipv6_router
;
1242 circuit
->ip_router
= ip_router
;
1243 circuit
->ipv6_router
= ipv6_router
;
1248 circuit_update_nlpids(circuit
);
1250 if (!ip_router
&& !ipv6_router
)
1251 isis_csm_state_change(ISIS_DISABLE
, circuit
, area
);
1253 lsp_regenerate_schedule(circuit
->area
, circuit
->is_type
, 0);
1256 ferr_r
isis_circuit_passive_set(struct isis_circuit
*circuit
, bool passive
)
1258 if (circuit
->is_passive
== passive
)
1261 if (if_is_loopback(circuit
->interface
) && !passive
)
1262 return ferr_cfg_invalid("loopback is always passive");
1264 if (circuit
->state
!= C_STATE_UP
) {
1265 circuit
->is_passive
= passive
;
1267 struct isis_area
*area
= circuit
->area
;
1268 isis_csm_state_change(ISIS_DISABLE
, circuit
, area
);
1269 circuit
->is_passive
= passive
;
1270 isis_csm_state_change(ISIS_ENABLE
, circuit
, area
);
1276 ferr_r
isis_circuit_metric_set(struct isis_circuit
*circuit
, int level
,
1279 assert(level
== IS_LEVEL_1
|| level
== IS_LEVEL_2
);
1280 if (metric
> MAX_WIDE_LINK_METRIC
)
1281 return ferr_cfg_invalid("metric %d too large for wide metric",
1283 if (circuit
->area
&& circuit
->area
->oldmetric
1284 && metric
> MAX_NARROW_LINK_METRIC
)
1285 return ferr_cfg_invalid("metric %d too large for narrow metric",
1288 circuit
->te_metric
[level
- 1] = metric
;
1289 circuit
->metric
[level
- 1] = metric
;
1292 lsp_regenerate_schedule(circuit
->area
, level
, 0);
1296 ferr_r
isis_circuit_passwd_unset(struct isis_circuit
*circuit
)
1298 memset(&circuit
->passwd
, 0, sizeof(circuit
->passwd
));
1302 ferr_r
isis_circuit_passwd_set(struct isis_circuit
*circuit
,
1303 uint8_t passwd_type
, const char *passwd
)
1308 return ferr_code_bug("no circuit password given");
1310 len
= strlen(passwd
);
1312 return ferr_code_bug(
1313 "circuit password too long (max 254 chars)");
1315 circuit
->passwd
.len
= len
;
1316 strlcpy((char *)circuit
->passwd
.passwd
, passwd
,
1317 sizeof(circuit
->passwd
.passwd
));
1318 circuit
->passwd
.type
= passwd_type
;
1322 ferr_r
isis_circuit_passwd_cleartext_set(struct isis_circuit
*circuit
,
1325 return isis_circuit_passwd_set(circuit
, ISIS_PASSWD_TYPE_CLEARTXT
,
1329 ferr_r
isis_circuit_passwd_hmac_md5_set(struct isis_circuit
*circuit
,
1332 return isis_circuit_passwd_set(circuit
, ISIS_PASSWD_TYPE_HMAC_MD5
,
1336 struct cmd_node interface_node
= {
1337 INTERFACE_NODE
, "%s(config-if)# ", 1,
1340 void isis_circuit_circ_type_set(struct isis_circuit
*circuit
, int circ_type
)
1342 if (circuit
->circ_type
== circ_type
)
1345 if (circuit
->state
!= C_STATE_UP
) {
1346 circuit
->circ_type
= circ_type
;
1347 circuit
->circ_type_config
= circ_type
;
1349 struct isis_area
*area
= circuit
->area
;
1351 isis_csm_state_change(ISIS_DISABLE
, circuit
, area
);
1352 circuit
->circ_type
= circ_type
;
1353 circuit
->circ_type_config
= circ_type
;
1354 isis_csm_state_change(ISIS_ENABLE
, circuit
, area
);
1358 int isis_circuit_mt_enabled_set(struct isis_circuit
*circuit
, uint16_t mtid
,
1361 struct isis_circuit_mt_setting
*setting
;
1363 setting
= circuit_get_mt_setting(circuit
, mtid
);
1364 if (setting
->enabled
!= enabled
) {
1365 setting
->enabled
= enabled
;
1366 lsp_regenerate_schedule(circuit
->area
, IS_LEVEL_1
| IS_LEVEL_2
,
1373 int isis_if_new_hook(struct interface
*ifp
)
1378 int isis_if_delete_hook(struct interface
*ifp
)
1380 struct isis_circuit
*circuit
;
1381 /* Clean up the circuit data */
1382 if (ifp
&& ifp
->info
) {
1383 circuit
= ifp
->info
;
1384 isis_csm_state_change(IF_DOWN_FROM_Z
, circuit
, circuit
->area
);
1385 isis_csm_state_change(ISIS_DISABLE
, circuit
, circuit
->area
);
1391 void isis_circuit_init(void)
1393 /* Initialize Zebra interface data structure */
1394 hook_register_prio(if_add
, 0, isis_if_new_hook
);
1395 hook_register_prio(if_del
, 0, isis_if_delete_hook
);
1397 /* Install interface node */
1398 install_node(&interface_node
, isis_interface_config_write
);