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/dict.h"
44 #include "isisd/isis_constants.h"
45 #include "isisd/isis_common.h"
46 #include "isisd/isis_flags.h"
47 #include "isisd/isis_circuit.h"
48 #include "isisd/isis_lsp.h"
49 #include "isisd/isis_pdu.h"
50 #include "isisd/isis_network.h"
51 #include "isisd/isis_misc.h"
52 #include "isisd/isis_constants.h"
53 #include "isisd/isis_adjacency.h"
54 #include "isisd/isis_dr.h"
55 #include "isisd/isisd.h"
56 #include "isisd/isis_csm.h"
57 #include "isisd/isis_events.h"
58 #include "isisd/isis_te.h"
59 #include "isisd/isis_mt.h"
60 #include "isisd/isis_errors.h"
61 #include "isisd/isis_tx_queue.h"
63 DEFINE_QOBJ_TYPE(isis_circuit
)
68 int isis_interface_config_write(struct vty
*);
69 int isis_if_new_hook(struct interface
*);
70 int isis_if_delete_hook(struct interface
*);
72 struct isis_circuit
*isis_circuit_new(void)
74 struct isis_circuit
*circuit
;
77 circuit
= XCALLOC(MTYPE_ISIS_CIRCUIT
, sizeof(struct isis_circuit
));
83 circuit
->is_type
= yang_get_default_enum(
84 "/frr-interface:lib/interface/frr-isisd:isis/circuit-type");
87 circuit
->pad_hellos
= yang_get_default_bool(
88 "/frr-interface:lib/interface/frr-isisd:isis/hello/padding");
89 circuit
->hello_interval
[0] = yang_get_default_uint32(
90 "/frr-interface:lib/interface/frr-isisd:isis/hello/interval/level-1");
91 circuit
->hello_interval
[1] = yang_get_default_uint32(
92 "/frr-interface:lib/interface/frr-isisd:isis/hello/interval/level-2");
93 circuit
->hello_multiplier
[0] = yang_get_default_uint32(
94 "/frr-interface:lib/interface/frr-isisd:isis/hello/multiplier/level-1");
95 circuit
->hello_multiplier
[1] = yang_get_default_uint32(
96 "/frr-interface:lib/interface/frr-isisd:isis/hello/multiplier/level-2");
97 circuit
->csnp_interval
[0] = yang_get_default_uint16(
98 "/frr-interface:lib/interface/frr-isisd:isis/csnp-interval/level-1");
99 circuit
->csnp_interval
[1] = yang_get_default_uint16(
100 "/frr-interface:lib/interface/frr-isisd:isis/csnp-interval/level-2");
101 circuit
->psnp_interval
[0] = yang_get_default_uint16(
102 "/frr-interface:lib/interface/frr-isisd:isis/psnp-interval/level-1");
103 circuit
->psnp_interval
[1] = yang_get_default_uint16(
104 "/frr-interface:lib/interface/frr-isisd:isis/psnp-interval/level-2");
105 circuit
->priority
[0] = yang_get_default_uint8(
106 "/frr-interface:lib/interface/frr-isisd:isis/priority/level-1");
107 circuit
->priority
[1] = yang_get_default_uint8(
108 "/frr-interface:lib/interface/frr-isisd:isis/priority/level-2");
109 circuit
->metric
[0] = yang_get_default_uint32(
110 "/frr-interface:lib/interface/frr-isisd:isis/metric/level-1");
111 circuit
->metric
[1] = yang_get_default_uint32(
112 "/frr-interface:lib/interface/frr-isisd:isis/metric/level-2");
113 circuit
->te_metric
[0] = yang_get_default_uint32(
114 "/frr-interface:lib/interface/frr-isisd:isis/metric/level-1");
115 circuit
->te_metric
[1] = yang_get_default_uint32(
116 "/frr-interface:lib/interface/frr-isisd:isis/metric/level-2");
118 for (i
= 0; i
< 2; i
++) {
119 circuit
->level_arg
[i
].level
= i
+ 1;
120 circuit
->level_arg
[i
].circuit
= circuit
;
123 circuit
->is_type
= IS_LEVEL_1_AND_2
;
125 circuit
->pad_hellos
= 1;
126 for (i
= 0; i
< 2; i
++) {
127 circuit
->hello_interval
[i
] = DEFAULT_HELLO_INTERVAL
;
128 circuit
->hello_multiplier
[i
] = DEFAULT_HELLO_MULTIPLIER
;
129 circuit
->csnp_interval
[i
] = DEFAULT_CSNP_INTERVAL
;
130 circuit
->psnp_interval
[i
] = DEFAULT_PSNP_INTERVAL
;
131 circuit
->priority
[i
] = DEFAULT_PRIORITY
;
132 circuit
->metric
[i
] = DEFAULT_CIRCUIT_METRIC
;
133 circuit
->te_metric
[i
] = DEFAULT_CIRCUIT_METRIC
;
134 circuit
->level_arg
[i
].level
= i
+ 1;
135 circuit
->level_arg
[i
].circuit
= circuit
;
137 #endif /* ifndef FABRICD */
139 circuit
->mtc
= mpls_te_circuit_new();
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 MPLS TE Local IP address parameter */
271 set_circuitparams_local_ipaddr(circuit
->mtc
, ipv4
->prefix
);
274 lsp_regenerate_schedule(circuit
->area
, circuit
->is_type
,
278 prefix2str(connected
->address
, buf
, sizeof(buf
));
279 zlog_debug("Added IP address %s to circuit %s", buf
,
280 circuit
->interface
->name
);
281 #endif /* EXTREME_DEBUG */
283 if (connected
->address
->family
== AF_INET6
) {
284 if (IN6_IS_ADDR_LOOPBACK(&connected
->address
->u
.prefix6
))
287 for (ALL_LIST_ELEMENTS_RO(circuit
->ipv6_link
, node
, ipv6
))
288 if (prefix_same((struct prefix
*)ipv6
,
291 for (ALL_LIST_ELEMENTS_RO(circuit
->ipv6_non_link
, node
, ipv6
))
292 if (prefix_same((struct prefix
*)ipv6
,
296 ipv6
= prefix_ipv6_new();
297 ipv6
->prefixlen
= connected
->address
->prefixlen
;
298 ipv6
->prefix
= connected
->address
->u
.prefix6
;
300 if (IN6_IS_ADDR_LINKLOCAL(&ipv6
->prefix
))
301 listnode_add(circuit
->ipv6_link
, ipv6
);
303 listnode_add(circuit
->ipv6_non_link
, ipv6
);
305 lsp_regenerate_schedule(circuit
->area
, circuit
->is_type
,
309 prefix2str(connected
->address
, buf
, sizeof(buf
));
310 zlog_debug("Added IPv6 address %s to circuit %s", buf
,
311 circuit
->interface
->name
);
312 #endif /* EXTREME_DEBUG */
317 void isis_circuit_del_addr(struct isis_circuit
*circuit
,
318 struct connected
*connected
)
320 struct prefix_ipv4
*ipv4
, *ip
= NULL
;
321 struct listnode
*node
;
322 char buf
[PREFIX2STR_BUFFER
];
323 struct prefix_ipv6
*ipv6
, *ip6
= NULL
;
326 if (connected
->address
->family
== AF_INET
) {
327 ipv4
= prefix_ipv4_new();
328 ipv4
->prefixlen
= connected
->address
->prefixlen
;
329 ipv4
->prefix
= connected
->address
->u
.prefix4
;
331 for (ALL_LIST_ELEMENTS_RO(circuit
->ip_addrs
, node
, ip
))
332 if (prefix_same((struct prefix
*)ip
,
333 (struct prefix
*)ipv4
))
337 listnode_delete(circuit
->ip_addrs
, ip
);
338 prefix_ipv4_free(ip
);
340 lsp_regenerate_schedule(circuit
->area
,
341 circuit
->is_type
, 0);
343 prefix2str(connected
->address
, buf
, sizeof(buf
));
345 "Nonexistent ip address %s removal attempt from \
347 buf
, circuit
->interface
->name
);
348 zlog_warn("Current ip addresses on %s:",
349 circuit
->interface
->name
);
350 for (ALL_LIST_ELEMENTS_RO(circuit
->ip_addrs
, node
,
352 prefix2str(ip
, buf
, sizeof(buf
));
353 zlog_warn(" %s", buf
);
355 zlog_warn("End of addresses");
358 prefix_ipv4_free(ipv4
);
360 if (connected
->address
->family
== AF_INET6
) {
361 ipv6
= prefix_ipv6_new();
362 ipv6
->prefixlen
= connected
->address
->prefixlen
;
363 ipv6
->prefix
= connected
->address
->u
.prefix6
;
365 if (IN6_IS_ADDR_LINKLOCAL(&ipv6
->prefix
)) {
366 for (ALL_LIST_ELEMENTS_RO(circuit
->ipv6_link
, node
,
368 if (prefix_same((struct prefix
*)ip6
,
369 (struct prefix
*)ipv6
))
373 listnode_delete(circuit
->ipv6_link
, ip6
);
374 prefix_ipv6_free(ip6
);
378 for (ALL_LIST_ELEMENTS_RO(circuit
->ipv6_non_link
, node
,
380 if (prefix_same((struct prefix
*)ip6
,
381 (struct prefix
*)ipv6
))
385 listnode_delete(circuit
->ipv6_non_link
, ip6
);
386 prefix_ipv6_free(ip6
);
392 prefix2str(connected
->address
, buf
, sizeof(buf
));
394 "Nonexistent ip address %s removal attempt from \
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
);
484 void isis_circuit_if_del(struct isis_circuit
*circuit
, struct interface
*ifp
)
486 struct listnode
*node
, *nnode
;
487 struct connected
*conn
;
489 assert(circuit
->interface
== ifp
);
491 /* destroy addresses */
492 for (ALL_LIST_ELEMENTS(ifp
->connected
, node
, nnode
, conn
))
493 isis_circuit_del_addr(circuit
, conn
);
495 if (circuit
->ip_addrs
) {
496 assert(listcount(circuit
->ip_addrs
) == 0);
497 list_delete(&circuit
->ip_addrs
);
500 if (circuit
->ipv6_link
) {
501 assert(listcount(circuit
->ipv6_link
) == 0);
502 list_delete(&circuit
->ipv6_link
);
505 if (circuit
->ipv6_non_link
) {
506 assert(listcount(circuit
->ipv6_non_link
) == 0);
507 list_delete(&circuit
->ipv6_non_link
);
510 circuit
->circ_type
= CIRCUIT_T_UNKNOWN
;
513 void isis_circuit_if_bind(struct isis_circuit
*circuit
, struct interface
*ifp
)
515 assert(circuit
!= NULL
);
517 if (circuit
->interface
)
518 assert(circuit
->interface
== ifp
);
520 circuit
->interface
= ifp
;
522 assert(ifp
->info
== circuit
);
525 isis_link_params_update(circuit
, ifp
);
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
;
547 area
= circuit
->area
;
549 for (level
= ISIS_LEVEL1
; level
<= ISIS_LEVEL2
; level
++) {
550 if (!(level
& circuit
->is_type
))
553 if (!area
->lspdb
[level
- 1]
554 || !dict_count(area
->lspdb
[level
- 1]))
557 for (dnode
= dict_first(area
->lspdb
[level
- 1]);
559 dnode
= dict_next(area
->lspdb
[level
- 1], dnode
)) {
560 lsp
= dnode_get(dnode
);
562 isis_tx_queue_add(circuit
->tx_queue
, lsp
,
565 isis_tx_queue_del(circuit
->tx_queue
, lsp
);
571 size_t isis_circuit_pdu_size(struct isis_circuit
*circuit
)
573 return ISO_MTU(circuit
);
576 void isis_circuit_stream(struct isis_circuit
*circuit
, struct stream
**stream
)
578 size_t stream_size
= isis_circuit_pdu_size(circuit
);
581 *stream
= stream_new(stream_size
);
583 if (STREAM_SIZE(*stream
) != stream_size
)
584 stream_resize_inplace(stream
, stream_size
);
585 stream_reset(*stream
);
589 void isis_circuit_prepare(struct isis_circuit
*circuit
)
591 #if ISIS_METHOD != ISIS_METHOD_DLPI
592 thread_add_read(master
, isis_receive
, circuit
, circuit
->fd
,
595 thread_add_timer_msec(master
, isis_receive
, circuit
,
596 listcount(circuit
->area
->circuit_list
) * 100,
601 int isis_circuit_up(struct isis_circuit
*circuit
)
605 /* Set the flags for all the lsps of the circuit. */
606 isis_circuit_update_all_srmflags(circuit
, 1);
608 if (circuit
->state
== C_STATE_UP
)
611 if (circuit
->is_passive
)
614 if (circuit
->area
->lsp_mtu
> isis_circuit_pdu_size(circuit
)) {
617 "Interface MTU %zu on %s is too low to support area lsp mtu %u!",
618 isis_circuit_pdu_size(circuit
),
619 circuit
->interface
->name
, circuit
->area
->lsp_mtu
);
620 isis_circuit_update_all_srmflags(circuit
, 0);
624 if (circuit
->circ_type
== CIRCUIT_T_BROADCAST
) {
625 circuit
->circuit_id
= isis_circuit_id_gen(isis
, circuit
->interface
);
626 if (!circuit
->circuit_id
) {
629 "There are already 255 broadcast circuits active!");
634 * Get the Hardware Address
636 if (circuit
->interface
->hw_addr_len
!= ETH_ALEN
) {
637 zlog_warn("unsupported link layer");
639 memcpy(circuit
->u
.bc
.snpa
, circuit
->interface
->hw_addr
,
643 zlog_debug("isis_circuit_if_add: if_id %d, isomtu %d snpa %s",
644 circuit
->interface
->ifindex
, ISO_MTU(circuit
),
645 snpa_print(circuit
->u
.bc
.snpa
));
646 #endif /* EXTREME_DEBUG */
648 circuit
->u
.bc
.adjdb
[0] = list_new();
649 circuit
->u
.bc
.adjdb
[1] = list_new();
652 * ISO 10589 - 8.4.1 Enabling of broadcast circuits
655 /* initilizing the hello sending threads
659 /* 8.4.1 a) commence sending of IIH PDUs */
661 for (int level
= ISIS_LEVEL1
; level
<= ISIS_LEVEL2
; level
++) {
662 if (!(circuit
->is_type
& level
))
665 send_hello_sched(circuit
, level
, TRIGGERED_IIH_DELAY
);
666 circuit
->u
.bc
.lan_neighs
[level
- 1] = list_new();
668 thread_add_timer(master
, isis_run_dr
,
669 &circuit
->level_arg
[level
- 1],
670 2 * circuit
->hello_interval
[level
- 1],
671 &circuit
->u
.bc
.t_run_dr
[level
- 1]);
674 /* 8.4.1 b) FIXME: solicit ES - 8.4.6 */
675 /* 8.4.1 c) FIXME: listen for ESH PDUs */
676 } else if (circuit
->circ_type
== CIRCUIT_T_P2P
) {
677 /* initializing the hello send threads
680 circuit
->u
.p2p
.neighbor
= NULL
;
681 send_hello_sched(circuit
, 0, TRIGGERED_IIH_DELAY
);
684 /* initializing PSNP timers */
685 if (circuit
->is_type
& IS_LEVEL_1
)
687 master
, send_l1_psnp
, circuit
,
688 isis_jitter(circuit
->psnp_interval
[0], PSNP_JITTER
),
689 &circuit
->t_send_psnp
[0]);
691 if (circuit
->is_type
& IS_LEVEL_2
)
693 master
, send_l2_psnp
, circuit
,
694 isis_jitter(circuit
->psnp_interval
[1], PSNP_JITTER
),
695 &circuit
->t_send_psnp
[1]);
697 /* unified init for circuits; ignore warnings below this level */
698 retv
= isis_sock_init(circuit
);
699 if (retv
!= ISIS_OK
) {
700 isis_circuit_down(circuit
);
704 /* initialize the circuit streams after opening connection */
705 isis_circuit_stream(circuit
, &circuit
->rcv_stream
);
706 isis_circuit_stream(circuit
, &circuit
->snd_stream
);
708 isis_circuit_prepare(circuit
);
710 circuit
->tx_queue
= isis_tx_queue_new(circuit
, send_lsp
);
713 /* send northbound notification */
714 isis_notif_if_state_change(circuit
, false);
715 #endif /* ifndef FABRICD */
720 void isis_circuit_down(struct isis_circuit
*circuit
)
723 /* send northbound notification */
724 isis_notif_if_state_change(circuit
, true);
725 #endif /* ifndef FABRICD */
727 /* Clear the flags for all the lsps of the circuit. */
728 isis_circuit_update_all_srmflags(circuit
, 0);
730 if (circuit
->circ_type
== CIRCUIT_T_BROADCAST
) {
731 /* destroy neighbour lists */
732 if (circuit
->u
.bc
.lan_neighs
[0]) {
733 list_delete(&circuit
->u
.bc
.lan_neighs
[0]);
734 circuit
->u
.bc
.lan_neighs
[0] = NULL
;
736 if (circuit
->u
.bc
.lan_neighs
[1]) {
737 list_delete(&circuit
->u
.bc
.lan_neighs
[1]);
738 circuit
->u
.bc
.lan_neighs
[1] = NULL
;
740 /* destroy adjacency databases */
741 if (circuit
->u
.bc
.adjdb
[0]) {
742 circuit
->u
.bc
.adjdb
[0]->del
= isis_delete_adj
;
743 list_delete(&circuit
->u
.bc
.adjdb
[0]);
744 circuit
->u
.bc
.adjdb
[0] = NULL
;
746 if (circuit
->u
.bc
.adjdb
[1]) {
747 circuit
->u
.bc
.adjdb
[1]->del
= isis_delete_adj
;
748 list_delete(&circuit
->u
.bc
.adjdb
[1]);
749 circuit
->u
.bc
.adjdb
[1] = NULL
;
751 if (circuit
->u
.bc
.is_dr
[0]) {
752 isis_dr_resign(circuit
, 1);
753 circuit
->u
.bc
.is_dr
[0] = 0;
755 memset(circuit
->u
.bc
.l1_desig_is
, 0, ISIS_SYS_ID_LEN
+ 1);
756 if (circuit
->u
.bc
.is_dr
[1]) {
757 isis_dr_resign(circuit
, 2);
758 circuit
->u
.bc
.is_dr
[1] = 0;
760 memset(circuit
->u
.bc
.l2_desig_is
, 0, ISIS_SYS_ID_LEN
+ 1);
761 memset(circuit
->u
.bc
.snpa
, 0, ETH_ALEN
);
763 THREAD_TIMER_OFF(circuit
->u
.bc
.t_send_lan_hello
[0]);
764 THREAD_TIMER_OFF(circuit
->u
.bc
.t_send_lan_hello
[1]);
765 THREAD_TIMER_OFF(circuit
->u
.bc
.t_run_dr
[0]);
766 THREAD_TIMER_OFF(circuit
->u
.bc
.t_run_dr
[1]);
767 THREAD_TIMER_OFF(circuit
->u
.bc
.t_refresh_pseudo_lsp
[0]);
768 THREAD_TIMER_OFF(circuit
->u
.bc
.t_refresh_pseudo_lsp
[1]);
769 circuit
->lsp_regenerate_pending
[0] = 0;
770 circuit
->lsp_regenerate_pending
[1] = 0;
772 _ISIS_CLEAR_FLAG(isis
->circuit_ids_used
, circuit
->circuit_id
);
773 circuit
->circuit_id
= 0;
774 } else if (circuit
->circ_type
== CIRCUIT_T_P2P
) {
775 isis_delete_adj(circuit
->u
.p2p
.neighbor
);
776 circuit
->u
.p2p
.neighbor
= NULL
;
777 THREAD_TIMER_OFF(circuit
->u
.p2p
.t_send_p2p_hello
);
780 /* Cancel all active threads */
781 THREAD_TIMER_OFF(circuit
->t_send_csnp
[0]);
782 THREAD_TIMER_OFF(circuit
->t_send_csnp
[1]);
783 THREAD_TIMER_OFF(circuit
->t_send_psnp
[0]);
784 THREAD_TIMER_OFF(circuit
->t_send_psnp
[1]);
785 THREAD_OFF(circuit
->t_read
);
787 if (circuit
->tx_queue
) {
788 isis_tx_queue_free(circuit
->tx_queue
);
789 circuit
->tx_queue
= NULL
;
792 /* send one gratuitous hello to spead up convergence */
793 if (circuit
->state
== C_STATE_UP
) {
794 if (circuit
->is_type
& IS_LEVEL_1
)
795 send_hello(circuit
, IS_LEVEL_1
);
796 if (circuit
->is_type
& IS_LEVEL_2
)
797 send_hello(circuit
, IS_LEVEL_2
);
800 circuit
->upadjcount
[0] = 0;
801 circuit
->upadjcount
[1] = 0;
803 /* close the socket */
809 if (circuit
->rcv_stream
!= NULL
) {
810 stream_free(circuit
->rcv_stream
);
811 circuit
->rcv_stream
= NULL
;
814 if (circuit
->snd_stream
!= NULL
) {
815 stream_free(circuit
->snd_stream
);
816 circuit
->snd_stream
= NULL
;
819 thread_cancel_event(master
, circuit
);
824 void circuit_update_nlpids(struct isis_circuit
*circuit
)
826 circuit
->nlpids
.count
= 0;
828 if (circuit
->ip_router
) {
829 circuit
->nlpids
.nlpids
[0] = NLPID_IP
;
830 circuit
->nlpids
.count
++;
832 if (circuit
->ipv6_router
) {
833 circuit
->nlpids
.nlpids
[circuit
->nlpids
.count
] = NLPID_IPV6
;
834 circuit
->nlpids
.count
++;
839 void isis_circuit_print_vty(struct isis_circuit
*circuit
, struct vty
*vty
,
842 if (detail
== ISIS_UI_LEVEL_BRIEF
) {
843 vty_out(vty
, " %-12s", circuit
->interface
->name
);
844 vty_out(vty
, "0x%-7x", circuit
->circuit_id
);
845 vty_out(vty
, "%-9s", circuit_state2string(circuit
->state
));
846 vty_out(vty
, "%-9s", circuit_type2string(circuit
->circ_type
));
847 vty_out(vty
, "%-9s", circuit_t2string(circuit
->is_type
));
851 if (detail
== ISIS_UI_LEVEL_DETAIL
) {
852 struct listnode
*node
;
853 struct prefix
*ip_addr
;
856 vty_out(vty
, " Interface: %s", circuit
->interface
->name
);
857 vty_out(vty
, ", State: %s",
858 circuit_state2string(circuit
->state
));
859 if (circuit
->is_passive
)
860 vty_out(vty
, ", Passive");
862 vty_out(vty
, ", Active");
863 vty_out(vty
, ", Circuit Id: 0x%x", circuit
->circuit_id
);
865 vty_out(vty
, " Type: %s",
866 circuit_type2string(circuit
->circ_type
));
867 vty_out(vty
, ", Level: %s", circuit_t2string(circuit
->is_type
));
868 if (circuit
->circ_type
== CIRCUIT_T_BROADCAST
)
869 vty_out(vty
, ", SNPA: %-10s",
870 snpa_print(circuit
->u
.bc
.snpa
));
872 if (circuit
->is_type
& IS_LEVEL_1
) {
873 vty_out(vty
, " Level-1 Information:\n");
874 if (circuit
->area
->newmetric
)
875 vty_out(vty
, " Metric: %d",
876 circuit
->te_metric
[0]);
878 vty_out(vty
, " Metric: %d",
880 if (!circuit
->is_passive
) {
881 vty_out(vty
, ", Active neighbors: %u\n",
882 circuit
->upadjcount
[0]);
884 " Hello interval: %u, "
885 "Holddown count: %u %s\n",
886 circuit
->hello_interval
[0],
887 circuit
->hello_multiplier
[0],
888 (circuit
->pad_hellos
? "(pad)"
891 " CNSP interval: %u, "
892 "PSNP interval: %u\n",
893 circuit
->csnp_interval
[0],
894 circuit
->psnp_interval
[0]);
895 if (circuit
->circ_type
== CIRCUIT_T_BROADCAST
)
897 " LAN Priority: %u, %s\n",
898 circuit
->priority
[0],
899 (circuit
->u
.bc
.is_dr
[0]
906 if (circuit
->is_type
& IS_LEVEL_2
) {
907 vty_out(vty
, " Level-2 Information:\n");
908 if (circuit
->area
->newmetric
)
909 vty_out(vty
, " Metric: %d",
910 circuit
->te_metric
[1]);
912 vty_out(vty
, " Metric: %d",
914 if (!circuit
->is_passive
) {
915 vty_out(vty
, ", Active neighbors: %u\n",
916 circuit
->upadjcount
[1]);
918 " Hello interval: %u, "
919 "Holddown count: %u %s\n",
920 circuit
->hello_interval
[1],
921 circuit
->hello_multiplier
[1],
922 (circuit
->pad_hellos
? "(pad)"
925 " CNSP interval: %u, "
926 "PSNP interval: %u\n",
927 circuit
->csnp_interval
[1],
928 circuit
->psnp_interval
[1]);
929 if (circuit
->circ_type
== CIRCUIT_T_BROADCAST
)
931 " LAN Priority: %u, %s\n",
932 circuit
->priority
[1],
933 (circuit
->u
.bc
.is_dr
[1]
940 if (circuit
->ip_addrs
&& listcount(circuit
->ip_addrs
) > 0) {
941 vty_out(vty
, " IP Prefix(es):\n");
942 for (ALL_LIST_ELEMENTS_RO(circuit
->ip_addrs
, node
,
944 prefix2str(ip_addr
, buf
, sizeof(buf
));
945 vty_out(vty
, " %s\n", buf
);
948 if (circuit
->ipv6_link
&& listcount(circuit
->ipv6_link
) > 0) {
949 vty_out(vty
, " IPv6 Link-Locals:\n");
950 for (ALL_LIST_ELEMENTS_RO(circuit
->ipv6_link
, node
,
952 prefix2str(ip_addr
, (char *)buf
, BUFSIZ
);
953 vty_out(vty
, " %s\n", buf
);
956 if (circuit
->ipv6_non_link
957 && listcount(circuit
->ipv6_non_link
) > 0) {
958 vty_out(vty
, " IPv6 Prefixes:\n");
959 for (ALL_LIST_ELEMENTS_RO(circuit
->ipv6_non_link
, node
,
961 prefix2str(ip_addr
, (char *)buf
, BUFSIZ
);
962 vty_out(vty
, " %s\n", buf
);
971 DEFINE_HOOK(isis_circuit_config_write
,
972 (struct isis_circuit
*circuit
, struct vty
*vty
),
976 int isis_interface_config_write(struct vty
*vty
)
978 struct vrf
*vrf
= vrf_lookup_by_id(VRF_DEFAULT
);
980 struct listnode
*node
;
981 struct interface
*ifp
;
982 struct isis_area
*area
;
983 struct isis_circuit
*circuit
;
986 FOR_ALL_INTERFACES (vrf
, ifp
) {
988 vty_frame(vty
, "interface %s\n", ifp
->name
);
992 vty_out(vty
, " description %s\n", ifp
->desc
);
996 for (ALL_LIST_ELEMENTS_RO(isis
->area_list
, node
, area
)) {
998 circuit_lookup_by_ifp(ifp
, area
->circuit_list
);
1001 if (circuit
->ip_router
) {
1002 vty_out(vty
, " ip router " PROTO_NAME
" %s\n",
1006 if (circuit
->is_passive
) {
1007 vty_out(vty
, " " PROTO_NAME
" passive\n");
1010 if (circuit
->circ_type_config
== CIRCUIT_T_P2P
) {
1011 vty_out(vty
, " " PROTO_NAME
" network point-to-point\n");
1014 if (circuit
->ipv6_router
) {
1015 vty_out(vty
, " ipv6 router " PROTO_NAME
" %s\n",
1020 /* ISIS - circuit type */
1022 if (circuit
->is_type
== IS_LEVEL_1
) {
1023 vty_out(vty
, " " PROTO_NAME
" circuit-type level-1\n");
1026 if (circuit
->is_type
== IS_LEVEL_2
) {
1028 " " PROTO_NAME
" circuit-type level-2-only\n");
1034 /* ISIS - CSNP interval */
1035 if (circuit
->csnp_interval
[0]
1036 == circuit
->csnp_interval
[1]) {
1037 if (circuit
->csnp_interval
[0]
1038 != DEFAULT_CSNP_INTERVAL
) {
1039 vty_out(vty
, " " PROTO_NAME
" csnp-interval %d\n",
1040 circuit
->csnp_interval
[0]);
1044 for (i
= 0; i
< 2; i
++) {
1045 if (circuit
->csnp_interval
[i
]
1046 != DEFAULT_CSNP_INTERVAL
) {
1048 " " PROTO_NAME
" csnp-interval %d level-%d\n",
1049 circuit
->csnp_interval
1057 /* ISIS - PSNP interval */
1058 if (circuit
->psnp_interval
[0]
1059 == circuit
->psnp_interval
[1]) {
1060 if (circuit
->psnp_interval
[0]
1061 != DEFAULT_PSNP_INTERVAL
) {
1062 vty_out(vty
, " " PROTO_NAME
" psnp-interval %d\n",
1063 circuit
->psnp_interval
[0]);
1067 for (i
= 0; i
< 2; i
++) {
1068 if (circuit
->psnp_interval
[i
]
1069 != DEFAULT_PSNP_INTERVAL
) {
1071 " " PROTO_NAME
" psnp-interval %d level-%d\n",
1072 circuit
->psnp_interval
1080 /* ISIS - Hello padding - Defaults to true so only
1081 * display if false */
1082 if (circuit
->pad_hellos
== 0) {
1083 vty_out(vty
, " no " PROTO_NAME
" hello padding\n");
1087 if (circuit
->disable_threeway_adj
) {
1088 vty_out(vty
, " no isis three-way-handshake\n");
1092 /* ISIS - Hello interval */
1093 if (circuit
->hello_interval
[0]
1094 == circuit
->hello_interval
[1]) {
1095 if (circuit
->hello_interval
[0]
1096 != DEFAULT_HELLO_INTERVAL
) {
1098 " " PROTO_NAME
" hello-interval %d\n",
1099 circuit
->hello_interval
[0]);
1103 for (i
= 0; i
< 2; i
++) {
1104 if (circuit
->hello_interval
[i
]
1105 != DEFAULT_HELLO_INTERVAL
) {
1107 " " PROTO_NAME
" hello-interval %d level-%d\n",
1108 circuit
->hello_interval
1116 /* ISIS - Hello Multiplier */
1117 if (circuit
->hello_multiplier
[0]
1118 == circuit
->hello_multiplier
[1]) {
1119 if (circuit
->hello_multiplier
[0]
1120 != DEFAULT_HELLO_MULTIPLIER
) {
1122 " " PROTO_NAME
" hello-multiplier %d\n",
1123 circuit
->hello_multiplier
[0]);
1127 for (i
= 0; i
< 2; i
++) {
1128 if (circuit
->hello_multiplier
[i
]
1129 != DEFAULT_HELLO_MULTIPLIER
) {
1131 " " PROTO_NAME
" hello-multiplier %d level-%d\n",
1132 circuit
->hello_multiplier
1140 /* ISIS - Priority */
1141 if (circuit
->priority
[0] == circuit
->priority
[1]) {
1142 if (circuit
->priority
[0] != DEFAULT_PRIORITY
) {
1143 vty_out(vty
, " " PROTO_NAME
" priority %d\n",
1144 circuit
->priority
[0]);
1148 for (i
= 0; i
< 2; i
++) {
1149 if (circuit
->priority
[i
]
1150 != DEFAULT_PRIORITY
) {
1152 " " PROTO_NAME
" priority %d level-%d\n",
1153 circuit
->priority
[i
],
1161 if (circuit
->te_metric
[0] == circuit
->te_metric
[1]) {
1162 if (circuit
->te_metric
[0]
1163 != DEFAULT_CIRCUIT_METRIC
) {
1164 vty_out(vty
, " " PROTO_NAME
" metric %d\n",
1165 circuit
->te_metric
[0]);
1169 for (i
= 0; i
< 2; i
++) {
1170 if (circuit
->te_metric
[i
]
1171 != DEFAULT_CIRCUIT_METRIC
) {
1173 " " PROTO_NAME
" metric %d level-%d\n",
1174 circuit
->te_metric
[i
],
1180 if (circuit
->passwd
.type
== ISIS_PASSWD_TYPE_HMAC_MD5
) {
1181 vty_out(vty
, " " PROTO_NAME
" password md5 %s\n",
1182 circuit
->passwd
.passwd
);
1184 } else if (circuit
->passwd
.type
1185 == ISIS_PASSWD_TYPE_CLEARTXT
) {
1186 vty_out(vty
, " " PROTO_NAME
" password clear %s\n",
1187 circuit
->passwd
.passwd
);
1190 write
+= hook_call(isis_circuit_config_write
,
1193 vty_endframe(vty
, "!\n");
1199 int isis_interface_config_write(struct vty
*vty
)
1201 struct vrf
*vrf
= vrf_lookup_by_id(VRF_DEFAULT
);
1203 struct interface
*ifp
;
1204 struct isis_circuit
*circuit
;
1205 struct lyd_node
*dnode
;
1207 FOR_ALL_INTERFACES (vrf
, ifp
) {
1208 dnode
= yang_dnode_get(
1209 running_config
->dnode
,
1210 "/frr-interface:lib/interface[name='%s'][vrf='%s']",
1211 ifp
->name
, vrf
->name
);
1216 nb_cli_show_dnode_cmds(vty
, dnode
, false);
1217 circuit
= circuit_scan_by_ifp(ifp
);
1219 write
+= hook_call(isis_circuit_config_write
, circuit
,
1224 #endif /* ifdef FABRICD */
1226 struct isis_circuit
*isis_circuit_create(struct isis_area
*area
,
1227 struct interface
*ifp
)
1229 struct isis_circuit
*circuit
= circuit_scan_by_ifp(ifp
);
1230 if (circuit
&& circuit
->area
)
1232 circuit
= isis_csm_state_change(ISIS_ENABLE
, circuit
, area
);
1233 if (circuit
->state
!= C_STATE_CONF
&& circuit
->state
!= C_STATE_UP
)
1235 isis_circuit_if_bind(circuit
, ifp
);
1239 void isis_circuit_af_set(struct isis_circuit
*circuit
, bool ip_router
,
1242 struct isis_area
*area
= circuit
->area
;
1243 bool change
= circuit
->ip_router
!= ip_router
1244 || circuit
->ipv6_router
!= ipv6_router
;
1246 area
->ip_circuits
+= ip_router
- circuit
->ip_router
;
1247 area
->ipv6_circuits
+= ipv6_router
- circuit
->ipv6_router
;
1248 circuit
->ip_router
= ip_router
;
1249 circuit
->ipv6_router
= ipv6_router
;
1254 circuit_update_nlpids(circuit
);
1256 if (!ip_router
&& !ipv6_router
)
1257 isis_csm_state_change(ISIS_DISABLE
, circuit
, area
);
1259 lsp_regenerate_schedule(circuit
->area
, circuit
->is_type
, 0);
1262 ferr_r
isis_circuit_passive_set(struct isis_circuit
*circuit
, bool passive
)
1264 if (circuit
->is_passive
== passive
)
1267 if (if_is_loopback(circuit
->interface
) && !passive
)
1268 return ferr_cfg_invalid("loopback is always passive");
1270 if (circuit
->state
!= C_STATE_UP
) {
1271 circuit
->is_passive
= passive
;
1273 struct isis_area
*area
= circuit
->area
;
1274 isis_csm_state_change(ISIS_DISABLE
, circuit
, area
);
1275 circuit
->is_passive
= passive
;
1276 isis_csm_state_change(ISIS_ENABLE
, circuit
, area
);
1282 ferr_r
isis_circuit_metric_set(struct isis_circuit
*circuit
, int level
,
1285 assert(level
== IS_LEVEL_1
|| level
== IS_LEVEL_2
);
1286 if (metric
> MAX_WIDE_LINK_METRIC
)
1287 return ferr_cfg_invalid("metric %d too large for wide metric",
1289 if (circuit
->area
&& circuit
->area
->oldmetric
1290 && metric
> MAX_NARROW_LINK_METRIC
)
1291 return ferr_cfg_invalid("metric %d too large for narrow metric",
1294 circuit
->te_metric
[level
- 1] = metric
;
1295 circuit
->metric
[level
- 1] = metric
;
1298 lsp_regenerate_schedule(circuit
->area
, level
, 0);
1302 ferr_r
isis_circuit_passwd_unset(struct isis_circuit
*circuit
)
1304 memset(&circuit
->passwd
, 0, sizeof(circuit
->passwd
));
1308 static int isis_circuit_passwd_set(struct isis_circuit
*circuit
,
1309 uint8_t passwd_type
, const char *passwd
)
1314 return ferr_code_bug("no circuit password given");
1316 len
= strlen(passwd
);
1318 return ferr_code_bug(
1319 "circuit password too long (max 254 chars)");
1321 circuit
->passwd
.len
= len
;
1322 strncpy((char *)circuit
->passwd
.passwd
, passwd
, 255);
1323 circuit
->passwd
.type
= passwd_type
;
1327 ferr_r
isis_circuit_passwd_cleartext_set(struct isis_circuit
*circuit
,
1330 return isis_circuit_passwd_set(circuit
, ISIS_PASSWD_TYPE_CLEARTXT
,
1334 ferr_r
isis_circuit_passwd_hmac_md5_set(struct isis_circuit
*circuit
,
1337 return isis_circuit_passwd_set(circuit
, ISIS_PASSWD_TYPE_HMAC_MD5
,
1341 struct cmd_node interface_node
= {
1342 INTERFACE_NODE
, "%s(config-if)# ", 1,
1345 void isis_circuit_circ_type_set(struct isis_circuit
*circuit
, int circ_type
)
1347 if (circuit
->circ_type
== circ_type
)
1350 if (circuit
->state
!= C_STATE_UP
) {
1351 circuit
->circ_type
= circ_type
;
1352 circuit
->circ_type_config
= circ_type
;
1354 struct isis_area
*area
= circuit
->area
;
1356 isis_csm_state_change(ISIS_DISABLE
, circuit
, area
);
1357 circuit
->circ_type
= circ_type
;
1358 circuit
->circ_type_config
= circ_type
;
1359 isis_csm_state_change(ISIS_ENABLE
, circuit
, area
);
1363 int isis_circuit_mt_enabled_set(struct isis_circuit
*circuit
, uint16_t mtid
,
1366 struct isis_circuit_mt_setting
*setting
;
1368 setting
= circuit_get_mt_setting(circuit
, mtid
);
1369 if (setting
->enabled
!= enabled
) {
1370 setting
->enabled
= enabled
;
1371 lsp_regenerate_schedule(circuit
->area
, IS_LEVEL_1
| IS_LEVEL_2
,
1378 int isis_if_new_hook(struct interface
*ifp
)
1383 int isis_if_delete_hook(struct interface
*ifp
)
1385 struct isis_circuit
*circuit
;
1386 /* Clean up the circuit data */
1387 if (ifp
&& ifp
->info
) {
1388 circuit
= ifp
->info
;
1389 isis_csm_state_change(IF_DOWN_FROM_Z
, circuit
, circuit
->area
);
1390 isis_csm_state_change(ISIS_DISABLE
, circuit
, circuit
->area
);
1396 void isis_circuit_init(void)
1398 /* Initialize Zebra interface data structure */
1399 hook_register_prio(if_add
, 0, isis_if_new_hook
);
1400 hook_register_prio(if_del
, 0, isis_if_delete_hook
);
1402 /* Install interface node */
1403 install_node(&interface_node
, isis_interface_config_write
);