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()
74 struct isis_circuit
*circuit
;
77 circuit
= XCALLOC(MTYPE_ISIS_CIRCUIT
, sizeof(struct isis_circuit
));
82 circuit
->is_type
= IS_LEVEL_1_AND_2
;
84 circuit
->pad_hellos
= 1;
85 for (i
= 0; i
< 2; i
++) {
86 circuit
->hello_interval
[i
] = DEFAULT_HELLO_INTERVAL
;
87 circuit
->hello_multiplier
[i
] = DEFAULT_HELLO_MULTIPLIER
;
88 circuit
->csnp_interval
[i
] = DEFAULT_CSNP_INTERVAL
;
89 circuit
->psnp_interval
[i
] = DEFAULT_PSNP_INTERVAL
;
90 circuit
->priority
[i
] = DEFAULT_PRIORITY
;
91 circuit
->metric
[i
] = DEFAULT_CIRCUIT_METRIC
;
92 circuit
->te_metric
[i
] = DEFAULT_CIRCUIT_METRIC
;
93 circuit
->level_arg
[i
].level
= i
+ 1;
94 circuit
->level_arg
[i
].circuit
= circuit
;
97 circuit
->mtc
= mpls_te_circuit_new();
99 circuit_mt_init(circuit
);
101 QOBJ_REG(circuit
, isis_circuit
);
106 void isis_circuit_del(struct isis_circuit
*circuit
)
113 isis_circuit_if_unbind(circuit
, circuit
->interface
);
115 circuit_mt_finish(circuit
);
117 /* and lastly the circuit itself */
118 XFREE(MTYPE_ISIS_CIRCUIT
, circuit
);
123 void isis_circuit_configure(struct isis_circuit
*circuit
,
124 struct isis_area
*area
)
127 circuit
->area
= area
;
130 * Whenever the is-type of an area is changed, the is-type of each
132 * in that area is updated to a non-empty subset of the area is-type.
133 * Inversely, when configuring a new circuit, this property should be
136 if (area
->is_type
!= IS_LEVEL_1_AND_2
)
137 circuit
->is_type
= area
->is_type
;
140 * Add the circuit into area
142 listnode_add(area
->circuit_list
, circuit
);
144 circuit
->idx
= flags_get_index(&area
->flags
);
149 void isis_circuit_deconfigure(struct isis_circuit
*circuit
,
150 struct isis_area
*area
)
152 /* Free the index of SRM and SSN flags */
153 flags_free_index(&area
->flags
, circuit
->idx
);
155 /* Remove circuit from area */
156 assert(circuit
->area
== area
);
157 listnode_delete(area
->circuit_list
, circuit
);
158 circuit
->area
= NULL
;
163 struct isis_circuit
*circuit_lookup_by_ifp(struct interface
*ifp
,
166 struct isis_circuit
*circuit
= NULL
;
167 struct listnode
*node
;
172 for (ALL_LIST_ELEMENTS_RO(list
, node
, circuit
))
173 if (circuit
->interface
== ifp
) {
174 assert(ifp
->info
== circuit
);
181 struct isis_circuit
*circuit_scan_by_ifp(struct interface
*ifp
)
183 struct isis_area
*area
;
184 struct listnode
*node
;
185 struct isis_circuit
*circuit
;
188 return (struct isis_circuit
*)ifp
->info
;
190 if (isis
->area_list
) {
191 for (ALL_LIST_ELEMENTS_RO(isis
->area_list
, node
, area
)) {
193 circuit_lookup_by_ifp(ifp
, area
->circuit_list
);
198 return circuit_lookup_by_ifp(ifp
, isis
->init_circ_list
);
201 void isis_circuit_add_addr(struct isis_circuit
*circuit
,
202 struct connected
*connected
)
204 struct listnode
*node
;
205 struct prefix_ipv4
*ipv4
;
206 #if defined(EXTREME_DEBUG)
207 char buf
[PREFIX2STR_BUFFER
];
209 struct prefix_ipv6
*ipv6
;
211 if (connected
->address
->family
== AF_INET
) {
212 uint32_t addr
= connected
->address
->u
.prefix4
.s_addr
;
214 if (IPV4_NET0(addr
) || IPV4_NET127(addr
) || IN_CLASSD(addr
)
215 || IPV4_LINKLOCAL(addr
))
218 for (ALL_LIST_ELEMENTS_RO(circuit
->ip_addrs
, node
, ipv4
))
219 if (prefix_same((struct prefix
*)ipv4
,
223 ipv4
= prefix_ipv4_new();
224 ipv4
->prefixlen
= connected
->address
->prefixlen
;
225 ipv4
->prefix
= connected
->address
->u
.prefix4
;
226 listnode_add(circuit
->ip_addrs
, ipv4
);
228 /* Update MPLS TE Local IP address parameter */
229 set_circuitparams_local_ipaddr(circuit
->mtc
, ipv4
->prefix
);
232 lsp_regenerate_schedule(circuit
->area
, circuit
->is_type
,
236 prefix2str(connected
->address
, buf
, sizeof(buf
));
237 zlog_debug("Added IP address %s to circuit %s", buf
,
238 circuit
->interface
->name
);
239 #endif /* EXTREME_DEBUG */
241 if (connected
->address
->family
== AF_INET6
) {
242 if (IN6_IS_ADDR_LOOPBACK(&connected
->address
->u
.prefix6
))
245 for (ALL_LIST_ELEMENTS_RO(circuit
->ipv6_link
, node
, ipv6
))
246 if (prefix_same((struct prefix
*)ipv6
,
249 for (ALL_LIST_ELEMENTS_RO(circuit
->ipv6_non_link
, node
, ipv6
))
250 if (prefix_same((struct prefix
*)ipv6
,
254 ipv6
= prefix_ipv6_new();
255 ipv6
->prefixlen
= connected
->address
->prefixlen
;
256 ipv6
->prefix
= connected
->address
->u
.prefix6
;
258 if (IN6_IS_ADDR_LINKLOCAL(&ipv6
->prefix
))
259 listnode_add(circuit
->ipv6_link
, ipv6
);
261 listnode_add(circuit
->ipv6_non_link
, ipv6
);
263 lsp_regenerate_schedule(circuit
->area
, circuit
->is_type
,
267 prefix2str(connected
->address
, buf
, sizeof(buf
));
268 zlog_debug("Added IPv6 address %s to circuit %s", buf
,
269 circuit
->interface
->name
);
270 #endif /* EXTREME_DEBUG */
275 void isis_circuit_del_addr(struct isis_circuit
*circuit
,
276 struct connected
*connected
)
278 struct prefix_ipv4
*ipv4
, *ip
= NULL
;
279 struct listnode
*node
;
280 char buf
[PREFIX2STR_BUFFER
];
281 struct prefix_ipv6
*ipv6
, *ip6
= NULL
;
284 if (connected
->address
->family
== AF_INET
) {
285 ipv4
= prefix_ipv4_new();
286 ipv4
->prefixlen
= connected
->address
->prefixlen
;
287 ipv4
->prefix
= connected
->address
->u
.prefix4
;
289 for (ALL_LIST_ELEMENTS_RO(circuit
->ip_addrs
, node
, ip
))
290 if (prefix_same((struct prefix
*)ip
,
291 (struct prefix
*)ipv4
))
295 listnode_delete(circuit
->ip_addrs
, ip
);
296 prefix_ipv4_free(ip
);
298 lsp_regenerate_schedule(circuit
->area
,
299 circuit
->is_type
, 0);
301 prefix2str(connected
->address
, buf
, sizeof(buf
));
303 "Nonexistent ip address %s removal attempt from \
305 buf
, circuit
->interface
->name
);
306 zlog_warn("Current ip addresses on %s:",
307 circuit
->interface
->name
);
308 for (ALL_LIST_ELEMENTS_RO(circuit
->ip_addrs
, node
,
310 prefix2str(ip
, buf
, sizeof(buf
));
311 zlog_warn(" %s", buf
);
313 zlog_warn("End of addresses");
316 prefix_ipv4_free(ipv4
);
318 if (connected
->address
->family
== AF_INET6
) {
319 ipv6
= prefix_ipv6_new();
320 ipv6
->prefixlen
= connected
->address
->prefixlen
;
321 ipv6
->prefix
= connected
->address
->u
.prefix6
;
323 if (IN6_IS_ADDR_LINKLOCAL(&ipv6
->prefix
)) {
324 for (ALL_LIST_ELEMENTS_RO(circuit
->ipv6_link
, node
,
326 if (prefix_same((struct prefix
*)ip6
,
327 (struct prefix
*)ipv6
))
331 listnode_delete(circuit
->ipv6_link
, ip6
);
332 prefix_ipv6_free(ip6
);
336 for (ALL_LIST_ELEMENTS_RO(circuit
->ipv6_non_link
, node
,
338 if (prefix_same((struct prefix
*)ip6
,
339 (struct prefix
*)ipv6
))
343 listnode_delete(circuit
->ipv6_non_link
, ip6
);
344 prefix_ipv6_free(ip6
);
350 prefix2str(connected
->address
, buf
, sizeof(buf
));
352 "Nonexistent ip address %s removal attempt from \
354 buf
, circuit
->interface
->name
);
355 zlog_warn("Current ip addresses on %s:",
356 circuit
->interface
->name
);
357 for (ALL_LIST_ELEMENTS_RO(circuit
->ipv6_link
, node
,
359 prefix2str((struct prefix
*)ip6
, (char *)buf
,
361 zlog_warn(" %s", buf
);
364 for (ALL_LIST_ELEMENTS_RO(circuit
->ipv6_non_link
, node
,
366 prefix2str((struct prefix
*)ip6
, (char *)buf
,
368 zlog_warn(" %s", buf
);
370 zlog_warn("End of addresses");
371 } else if (circuit
->area
)
372 lsp_regenerate_schedule(circuit
->area
, circuit
->is_type
,
375 prefix_ipv6_free(ipv6
);
380 static uint8_t isis_circuit_id_gen(struct isis
*isis
, struct interface
*ifp
)
382 /* Circuit ids MUST be unique for any broadcast circuits. Otherwise,
383 * Pseudo-Node LSPs cannot be generated correctly.
385 * Currently, allocate one circuit ID for any circuit, limiting the total
386 * numer of circuits IS-IS can run on to 255.
388 * We should revisit this when implementing 3-way adjacencies for p2p, since
389 * we then have extended interface IDs available.
391 uint8_t id
= ifp
->ifindex
;
394 for (i
= 0; i
< 256; i
++) {
395 if (id
&& !_ISIS_CHECK_FLAG(isis
->circuit_ids_used
, id
))
401 zlog_warn("Could not allocate a circuit id for '%s'",
406 _ISIS_SET_FLAG(isis
->circuit_ids_used
, id
);
410 void isis_circuit_if_add(struct isis_circuit
*circuit
, struct interface
*ifp
)
412 struct listnode
*node
, *nnode
;
413 struct connected
*conn
;
415 isis_circuit_if_bind(circuit
, ifp
);
417 if (if_is_broadcast(ifp
)) {
418 if (fabricd
|| circuit
->circ_type_config
== CIRCUIT_T_P2P
)
419 circuit
->circ_type
= CIRCUIT_T_P2P
;
421 circuit
->circ_type
= CIRCUIT_T_BROADCAST
;
422 } else if (if_is_pointopoint(ifp
)) {
423 circuit
->circ_type
= CIRCUIT_T_P2P
;
424 } else if (if_is_loopback(ifp
)) {
425 circuit
->circ_type
= CIRCUIT_T_LOOPBACK
;
426 circuit
->is_passive
= 1;
428 /* It's normal in case of loopback etc. */
429 if (isis
->debugs
& DEBUG_EVENTS
)
430 zlog_debug("isis_circuit_if_add: unsupported media");
431 circuit
->circ_type
= CIRCUIT_T_UNKNOWN
;
434 circuit
->ip_addrs
= list_new();
435 circuit
->ipv6_link
= list_new();
436 circuit
->ipv6_non_link
= list_new();
438 for (ALL_LIST_ELEMENTS(ifp
->connected
, node
, nnode
, conn
))
439 isis_circuit_add_addr(circuit
, conn
);
442 void isis_circuit_if_del(struct isis_circuit
*circuit
, struct interface
*ifp
)
444 struct listnode
*node
, *nnode
;
445 struct connected
*conn
;
447 assert(circuit
->interface
== ifp
);
449 /* destroy addresses */
450 for (ALL_LIST_ELEMENTS(ifp
->connected
, node
, nnode
, conn
))
451 isis_circuit_del_addr(circuit
, conn
);
453 if (circuit
->ip_addrs
) {
454 assert(listcount(circuit
->ip_addrs
) == 0);
455 list_delete(&circuit
->ip_addrs
);
458 if (circuit
->ipv6_link
) {
459 assert(listcount(circuit
->ipv6_link
) == 0);
460 list_delete(&circuit
->ipv6_link
);
463 if (circuit
->ipv6_non_link
) {
464 assert(listcount(circuit
->ipv6_non_link
) == 0);
465 list_delete(&circuit
->ipv6_non_link
);
468 circuit
->circ_type
= CIRCUIT_T_UNKNOWN
;
471 void isis_circuit_if_bind(struct isis_circuit
*circuit
, struct interface
*ifp
)
473 assert(circuit
!= NULL
);
475 if (circuit
->interface
)
476 assert(circuit
->interface
== ifp
);
478 circuit
->interface
= ifp
;
480 assert(ifp
->info
== circuit
);
483 isis_link_params_update(circuit
, ifp
);
486 void isis_circuit_if_unbind(struct isis_circuit
*circuit
, struct interface
*ifp
)
488 assert(circuit
!= NULL
);
490 assert(circuit
->interface
== ifp
);
491 assert(ifp
->info
== circuit
);
492 circuit
->interface
= NULL
;
496 static void isis_circuit_update_all_srmflags(struct isis_circuit
*circuit
,
499 struct isis_area
*area
;
500 struct isis_lsp
*lsp
;
505 area
= circuit
->area
;
507 for (level
= ISIS_LEVEL1
; level
<= ISIS_LEVEL2
; level
++) {
508 if (!(level
& circuit
->is_type
))
511 if (!area
->lspdb
[level
- 1]
512 || !dict_count(area
->lspdb
[level
- 1]))
515 for (dnode
= dict_first(area
->lspdb
[level
- 1]);
517 dnode
= dict_next(area
->lspdb
[level
- 1], dnode
)) {
518 lsp
= dnode_get(dnode
);
520 isis_tx_queue_add(circuit
->tx_queue
, lsp
,
523 isis_tx_queue_del(circuit
->tx_queue
, lsp
);
529 size_t isis_circuit_pdu_size(struct isis_circuit
*circuit
)
531 return ISO_MTU(circuit
);
534 void isis_circuit_stream(struct isis_circuit
*circuit
, struct stream
**stream
)
536 size_t stream_size
= isis_circuit_pdu_size(circuit
);
539 *stream
= stream_new(stream_size
);
541 if (STREAM_SIZE(*stream
) != stream_size
)
542 stream_resize_inplace(stream
, stream_size
);
543 stream_reset(*stream
);
547 void isis_circuit_prepare(struct isis_circuit
*circuit
)
549 #if ISIS_METHOD != ISIS_METHOD_DLPI
550 thread_add_read(master
, isis_receive
, circuit
, circuit
->fd
,
553 thread_add_timer_msec(master
, isis_receive
, circuit
,
554 listcount(circuit
->area
->circuit_list
) * 100,
559 int isis_circuit_up(struct isis_circuit
*circuit
)
563 /* Set the flags for all the lsps of the circuit. */
564 isis_circuit_update_all_srmflags(circuit
, 1);
566 if (circuit
->state
== C_STATE_UP
)
569 if (circuit
->is_passive
)
572 if (circuit
->area
->lsp_mtu
> isis_circuit_pdu_size(circuit
)) {
575 "Interface MTU %zu on %s is too low to support area lsp mtu %u!",
576 isis_circuit_pdu_size(circuit
),
577 circuit
->interface
->name
, circuit
->area
->lsp_mtu
);
578 isis_circuit_update_all_srmflags(circuit
, 0);
582 if (circuit
->circ_type
== CIRCUIT_T_BROADCAST
) {
583 circuit
->circuit_id
= isis_circuit_id_gen(isis
, circuit
->interface
);
584 if (!circuit
->circuit_id
) {
587 "There are already 255 broadcast circuits active!");
592 * Get the Hardware Address
594 if (circuit
->interface
->hw_addr_len
!= ETH_ALEN
) {
595 zlog_warn("unsupported link layer");
597 memcpy(circuit
->u
.bc
.snpa
, circuit
->interface
->hw_addr
,
601 zlog_debug("isis_circuit_if_add: if_id %d, isomtu %d snpa %s",
602 circuit
->interface
->ifindex
, ISO_MTU(circuit
),
603 snpa_print(circuit
->u
.bc
.snpa
));
604 #endif /* EXTREME_DEBUG */
606 circuit
->u
.bc
.adjdb
[0] = list_new();
607 circuit
->u
.bc
.adjdb
[1] = list_new();
610 * ISO 10589 - 8.4.1 Enabling of broadcast circuits
613 /* initilizing the hello sending threads
617 /* 8.4.1 a) commence sending of IIH PDUs */
619 for (int level
= ISIS_LEVEL1
; level
<= ISIS_LEVEL2
; level
++) {
620 if (!(circuit
->is_type
& level
))
623 send_hello_sched(circuit
, level
, TRIGGERED_IIH_DELAY
);
624 circuit
->u
.bc
.lan_neighs
[level
- 1] = list_new();
626 thread_add_timer(master
, isis_run_dr
,
627 &circuit
->level_arg
[level
- 1],
628 2 * circuit
->hello_interval
[level
- 1],
629 &circuit
->u
.bc
.t_run_dr
[level
- 1]);
632 /* 8.4.1 b) FIXME: solicit ES - 8.4.6 */
633 /* 8.4.1 c) FIXME: listen for ESH PDUs */
634 } else if (circuit
->circ_type
== CIRCUIT_T_P2P
) {
635 /* initializing the hello send threads
638 circuit
->u
.p2p
.neighbor
= NULL
;
639 send_hello_sched(circuit
, 0, TRIGGERED_IIH_DELAY
);
642 /* initializing PSNP timers */
643 if (circuit
->is_type
& IS_LEVEL_1
)
645 master
, send_l1_psnp
, circuit
,
646 isis_jitter(circuit
->psnp_interval
[0], PSNP_JITTER
),
647 &circuit
->t_send_psnp
[0]);
649 if (circuit
->is_type
& IS_LEVEL_2
)
651 master
, send_l2_psnp
, circuit
,
652 isis_jitter(circuit
->psnp_interval
[1], PSNP_JITTER
),
653 &circuit
->t_send_psnp
[1]);
655 /* unified init for circuits; ignore warnings below this level */
656 retv
= isis_sock_init(circuit
);
657 if (retv
!= ISIS_OK
) {
658 isis_circuit_down(circuit
);
662 /* initialize the circuit streams after opening connection */
663 isis_circuit_stream(circuit
, &circuit
->rcv_stream
);
664 isis_circuit_stream(circuit
, &circuit
->snd_stream
);
666 isis_circuit_prepare(circuit
);
668 circuit
->tx_queue
= isis_tx_queue_new(circuit
, send_lsp
);
671 /* send northbound notification */
672 isis_notif_if_state_change(circuit
, false);
673 #endif /* ifndef FABRICD */
678 void isis_circuit_down(struct isis_circuit
*circuit
)
681 /* send northbound notification */
682 isis_notif_if_state_change(circuit
, true);
683 #endif /* ifndef FABRICD */
685 /* Clear the flags for all the lsps of the circuit. */
686 isis_circuit_update_all_srmflags(circuit
, 0);
688 if (circuit
->circ_type
== CIRCUIT_T_BROADCAST
) {
689 /* destroy neighbour lists */
690 if (circuit
->u
.bc
.lan_neighs
[0]) {
691 list_delete(&circuit
->u
.bc
.lan_neighs
[0]);
692 circuit
->u
.bc
.lan_neighs
[0] = NULL
;
694 if (circuit
->u
.bc
.lan_neighs
[1]) {
695 list_delete(&circuit
->u
.bc
.lan_neighs
[1]);
696 circuit
->u
.bc
.lan_neighs
[1] = NULL
;
698 /* destroy adjacency databases */
699 if (circuit
->u
.bc
.adjdb
[0]) {
700 circuit
->u
.bc
.adjdb
[0]->del
= isis_delete_adj
;
701 list_delete(&circuit
->u
.bc
.adjdb
[0]);
702 circuit
->u
.bc
.adjdb
[0] = NULL
;
704 if (circuit
->u
.bc
.adjdb
[1]) {
705 circuit
->u
.bc
.adjdb
[1]->del
= isis_delete_adj
;
706 list_delete(&circuit
->u
.bc
.adjdb
[1]);
707 circuit
->u
.bc
.adjdb
[1] = NULL
;
709 if (circuit
->u
.bc
.is_dr
[0]) {
710 isis_dr_resign(circuit
, 1);
711 circuit
->u
.bc
.is_dr
[0] = 0;
713 memset(circuit
->u
.bc
.l1_desig_is
, 0, ISIS_SYS_ID_LEN
+ 1);
714 if (circuit
->u
.bc
.is_dr
[1]) {
715 isis_dr_resign(circuit
, 2);
716 circuit
->u
.bc
.is_dr
[1] = 0;
718 memset(circuit
->u
.bc
.l2_desig_is
, 0, ISIS_SYS_ID_LEN
+ 1);
719 memset(circuit
->u
.bc
.snpa
, 0, ETH_ALEN
);
721 THREAD_TIMER_OFF(circuit
->u
.bc
.t_send_lan_hello
[0]);
722 THREAD_TIMER_OFF(circuit
->u
.bc
.t_send_lan_hello
[1]);
723 THREAD_TIMER_OFF(circuit
->u
.bc
.t_run_dr
[0]);
724 THREAD_TIMER_OFF(circuit
->u
.bc
.t_run_dr
[1]);
725 THREAD_TIMER_OFF(circuit
->u
.bc
.t_refresh_pseudo_lsp
[0]);
726 THREAD_TIMER_OFF(circuit
->u
.bc
.t_refresh_pseudo_lsp
[1]);
727 circuit
->lsp_regenerate_pending
[0] = 0;
728 circuit
->lsp_regenerate_pending
[1] = 0;
730 _ISIS_CLEAR_FLAG(isis
->circuit_ids_used
, circuit
->circuit_id
);
731 circuit
->circuit_id
= 0;
732 } else if (circuit
->circ_type
== CIRCUIT_T_P2P
) {
733 isis_delete_adj(circuit
->u
.p2p
.neighbor
);
734 circuit
->u
.p2p
.neighbor
= NULL
;
735 THREAD_TIMER_OFF(circuit
->u
.p2p
.t_send_p2p_hello
);
738 /* Cancel all active threads */
739 THREAD_TIMER_OFF(circuit
->t_send_csnp
[0]);
740 THREAD_TIMER_OFF(circuit
->t_send_csnp
[1]);
741 THREAD_TIMER_OFF(circuit
->t_send_psnp
[0]);
742 THREAD_TIMER_OFF(circuit
->t_send_psnp
[1]);
743 THREAD_OFF(circuit
->t_read
);
745 if (circuit
->tx_queue
) {
746 isis_tx_queue_free(circuit
->tx_queue
);
747 circuit
->tx_queue
= NULL
;
750 /* send one gratuitous hello to spead up convergence */
751 if (circuit
->state
== C_STATE_UP
) {
752 if (circuit
->is_type
& IS_LEVEL_1
)
753 send_hello(circuit
, IS_LEVEL_1
);
754 if (circuit
->is_type
& IS_LEVEL_2
)
755 send_hello(circuit
, IS_LEVEL_2
);
758 circuit
->upadjcount
[0] = 0;
759 circuit
->upadjcount
[1] = 0;
761 /* close the socket */
767 if (circuit
->rcv_stream
!= NULL
) {
768 stream_free(circuit
->rcv_stream
);
769 circuit
->rcv_stream
= NULL
;
772 if (circuit
->snd_stream
!= NULL
) {
773 stream_free(circuit
->snd_stream
);
774 circuit
->snd_stream
= NULL
;
777 thread_cancel_event(master
, circuit
);
782 void circuit_update_nlpids(struct isis_circuit
*circuit
)
784 circuit
->nlpids
.count
= 0;
786 if (circuit
->ip_router
) {
787 circuit
->nlpids
.nlpids
[0] = NLPID_IP
;
788 circuit
->nlpids
.count
++;
790 if (circuit
->ipv6_router
) {
791 circuit
->nlpids
.nlpids
[circuit
->nlpids
.count
] = NLPID_IPV6
;
792 circuit
->nlpids
.count
++;
797 void isis_circuit_print_vty(struct isis_circuit
*circuit
, struct vty
*vty
,
800 if (detail
== ISIS_UI_LEVEL_BRIEF
) {
801 vty_out(vty
, " %-12s", circuit
->interface
->name
);
802 vty_out(vty
, "0x%-7x", circuit
->circuit_id
);
803 vty_out(vty
, "%-9s", circuit_state2string(circuit
->state
));
804 vty_out(vty
, "%-9s", circuit_type2string(circuit
->circ_type
));
805 vty_out(vty
, "%-9s", circuit_t2string(circuit
->is_type
));
809 if (detail
== ISIS_UI_LEVEL_DETAIL
) {
810 struct listnode
*node
;
811 struct prefix
*ip_addr
;
814 vty_out(vty
, " Interface: %s", circuit
->interface
->name
);
815 vty_out(vty
, ", State: %s",
816 circuit_state2string(circuit
->state
));
817 if (circuit
->is_passive
)
818 vty_out(vty
, ", Passive");
820 vty_out(vty
, ", Active");
821 vty_out(vty
, ", Circuit Id: 0x%x", circuit
->circuit_id
);
823 vty_out(vty
, " Type: %s",
824 circuit_type2string(circuit
->circ_type
));
825 vty_out(vty
, ", Level: %s", circuit_t2string(circuit
->is_type
));
826 if (circuit
->circ_type
== CIRCUIT_T_BROADCAST
)
827 vty_out(vty
, ", SNPA: %-10s",
828 snpa_print(circuit
->u
.bc
.snpa
));
830 if (circuit
->is_type
& IS_LEVEL_1
) {
831 vty_out(vty
, " Level-1 Information:\n");
832 if (circuit
->area
->newmetric
)
833 vty_out(vty
, " Metric: %d",
834 circuit
->te_metric
[0]);
836 vty_out(vty
, " Metric: %d",
838 if (!circuit
->is_passive
) {
839 vty_out(vty
, ", Active neighbors: %u\n",
840 circuit
->upadjcount
[0]);
842 " Hello interval: %u, "
843 "Holddown count: %u %s\n",
844 circuit
->hello_interval
[0],
845 circuit
->hello_multiplier
[0],
846 (circuit
->pad_hellos
? "(pad)"
849 " CNSP interval: %u, "
850 "PSNP interval: %u\n",
851 circuit
->csnp_interval
[0],
852 circuit
->psnp_interval
[0]);
853 if (circuit
->circ_type
== CIRCUIT_T_BROADCAST
)
855 " LAN Priority: %u, %s\n",
856 circuit
->priority
[0],
857 (circuit
->u
.bc
.is_dr
[0]
864 if (circuit
->is_type
& IS_LEVEL_2
) {
865 vty_out(vty
, " Level-2 Information:\n");
866 if (circuit
->area
->newmetric
)
867 vty_out(vty
, " Metric: %d",
868 circuit
->te_metric
[1]);
870 vty_out(vty
, " Metric: %d",
872 if (!circuit
->is_passive
) {
873 vty_out(vty
, ", Active neighbors: %u\n",
874 circuit
->upadjcount
[1]);
876 " Hello interval: %u, "
877 "Holddown count: %u %s\n",
878 circuit
->hello_interval
[1],
879 circuit
->hello_multiplier
[1],
880 (circuit
->pad_hellos
? "(pad)"
883 " CNSP interval: %u, "
884 "PSNP interval: %u\n",
885 circuit
->csnp_interval
[1],
886 circuit
->psnp_interval
[1]);
887 if (circuit
->circ_type
== CIRCUIT_T_BROADCAST
)
889 " LAN Priority: %u, %s\n",
890 circuit
->priority
[1],
891 (circuit
->u
.bc
.is_dr
[1]
898 if (circuit
->ip_addrs
&& listcount(circuit
->ip_addrs
) > 0) {
899 vty_out(vty
, " IP Prefix(es):\n");
900 for (ALL_LIST_ELEMENTS_RO(circuit
->ip_addrs
, node
,
902 prefix2str(ip_addr
, buf
, sizeof(buf
));
903 vty_out(vty
, " %s\n", buf
);
906 if (circuit
->ipv6_link
&& listcount(circuit
->ipv6_link
) > 0) {
907 vty_out(vty
, " IPv6 Link-Locals:\n");
908 for (ALL_LIST_ELEMENTS_RO(circuit
->ipv6_link
, node
,
910 prefix2str(ip_addr
, (char *)buf
, BUFSIZ
);
911 vty_out(vty
, " %s\n", buf
);
914 if (circuit
->ipv6_non_link
915 && listcount(circuit
->ipv6_non_link
) > 0) {
916 vty_out(vty
, " IPv6 Prefixes:\n");
917 for (ALL_LIST_ELEMENTS_RO(circuit
->ipv6_non_link
, node
,
919 prefix2str(ip_addr
, (char *)buf
, BUFSIZ
);
920 vty_out(vty
, " %s\n", buf
);
929 DEFINE_HOOK(isis_circuit_config_write
,
930 (struct isis_circuit
*circuit
, struct vty
*vty
),
934 int isis_interface_config_write(struct vty
*vty
)
936 struct vrf
*vrf
= vrf_lookup_by_id(VRF_DEFAULT
);
938 struct listnode
*node
;
939 struct interface
*ifp
;
940 struct isis_area
*area
;
941 struct isis_circuit
*circuit
;
944 FOR_ALL_INTERFACES (vrf
, ifp
) {
946 vty_frame(vty
, "interface %s\n", ifp
->name
);
950 vty_out(vty
, " description %s\n", ifp
->desc
);
954 for (ALL_LIST_ELEMENTS_RO(isis
->area_list
, node
, area
)) {
956 circuit_lookup_by_ifp(ifp
, area
->circuit_list
);
959 if (circuit
->ip_router
) {
960 vty_out(vty
, " ip router " PROTO_NAME
" %s\n",
964 if (circuit
->is_passive
) {
965 vty_out(vty
, " " PROTO_NAME
" passive\n");
968 if (circuit
->circ_type_config
== CIRCUIT_T_P2P
) {
969 vty_out(vty
, " " PROTO_NAME
" network point-to-point\n");
972 if (circuit
->ipv6_router
) {
973 vty_out(vty
, " ipv6 router " PROTO_NAME
" %s\n",
978 /* ISIS - circuit type */
980 if (circuit
->is_type
== IS_LEVEL_1
) {
981 vty_out(vty
, " " PROTO_NAME
" circuit-type level-1\n");
984 if (circuit
->is_type
== IS_LEVEL_2
) {
986 " " PROTO_NAME
" circuit-type level-2-only\n");
992 /* ISIS - CSNP interval */
993 if (circuit
->csnp_interval
[0]
994 == circuit
->csnp_interval
[1]) {
995 if (circuit
->csnp_interval
[0]
996 != DEFAULT_CSNP_INTERVAL
) {
997 vty_out(vty
, " " PROTO_NAME
" csnp-interval %d\n",
998 circuit
->csnp_interval
[0]);
1002 for (i
= 0; i
< 2; i
++) {
1003 if (circuit
->csnp_interval
[i
]
1004 != DEFAULT_CSNP_INTERVAL
) {
1006 " " PROTO_NAME
" csnp-interval %d level-%d\n",
1007 circuit
->csnp_interval
1015 /* ISIS - PSNP interval */
1016 if (circuit
->psnp_interval
[0]
1017 == circuit
->psnp_interval
[1]) {
1018 if (circuit
->psnp_interval
[0]
1019 != DEFAULT_PSNP_INTERVAL
) {
1020 vty_out(vty
, " " PROTO_NAME
" psnp-interval %d\n",
1021 circuit
->psnp_interval
[0]);
1025 for (i
= 0; i
< 2; i
++) {
1026 if (circuit
->psnp_interval
[i
]
1027 != DEFAULT_PSNP_INTERVAL
) {
1029 " " PROTO_NAME
" psnp-interval %d level-%d\n",
1030 circuit
->psnp_interval
1038 /* ISIS - Hello padding - Defaults to true so only
1039 * display if false */
1040 if (circuit
->pad_hellos
== 0) {
1041 vty_out(vty
, " no " PROTO_NAME
" hello padding\n");
1045 if (circuit
->disable_threeway_adj
) {
1046 vty_out(vty
, " no isis three-way-handshake\n");
1050 /* ISIS - Hello interval */
1051 if (circuit
->hello_interval
[0]
1052 == circuit
->hello_interval
[1]) {
1053 if (circuit
->hello_interval
[0]
1054 != DEFAULT_HELLO_INTERVAL
) {
1056 " " PROTO_NAME
" hello-interval %d\n",
1057 circuit
->hello_interval
[0]);
1061 for (i
= 0; i
< 2; i
++) {
1062 if (circuit
->hello_interval
[i
]
1063 != DEFAULT_HELLO_INTERVAL
) {
1065 " " PROTO_NAME
" hello-interval %d level-%d\n",
1066 circuit
->hello_interval
1074 /* ISIS - Hello Multiplier */
1075 if (circuit
->hello_multiplier
[0]
1076 == circuit
->hello_multiplier
[1]) {
1077 if (circuit
->hello_multiplier
[0]
1078 != DEFAULT_HELLO_MULTIPLIER
) {
1080 " " PROTO_NAME
" hello-multiplier %d\n",
1081 circuit
->hello_multiplier
[0]);
1085 for (i
= 0; i
< 2; i
++) {
1086 if (circuit
->hello_multiplier
[i
]
1087 != DEFAULT_HELLO_MULTIPLIER
) {
1089 " " PROTO_NAME
" hello-multiplier %d level-%d\n",
1090 circuit
->hello_multiplier
1098 /* ISIS - Priority */
1099 if (circuit
->priority
[0] == circuit
->priority
[1]) {
1100 if (circuit
->priority
[0] != DEFAULT_PRIORITY
) {
1101 vty_out(vty
, " " PROTO_NAME
" priority %d\n",
1102 circuit
->priority
[0]);
1106 for (i
= 0; i
< 2; i
++) {
1107 if (circuit
->priority
[i
]
1108 != DEFAULT_PRIORITY
) {
1110 " " PROTO_NAME
" priority %d level-%d\n",
1111 circuit
->priority
[i
],
1119 if (circuit
->te_metric
[0] == circuit
->te_metric
[1]) {
1120 if (circuit
->te_metric
[0]
1121 != DEFAULT_CIRCUIT_METRIC
) {
1122 vty_out(vty
, " " PROTO_NAME
" metric %d\n",
1123 circuit
->te_metric
[0]);
1127 for (i
= 0; i
< 2; i
++) {
1128 if (circuit
->te_metric
[i
]
1129 != DEFAULT_CIRCUIT_METRIC
) {
1131 " " PROTO_NAME
" metric %d level-%d\n",
1132 circuit
->te_metric
[i
],
1138 if (circuit
->passwd
.type
== ISIS_PASSWD_TYPE_HMAC_MD5
) {
1139 vty_out(vty
, " " PROTO_NAME
" password md5 %s\n",
1140 circuit
->passwd
.passwd
);
1142 } else if (circuit
->passwd
.type
1143 == ISIS_PASSWD_TYPE_CLEARTXT
) {
1144 vty_out(vty
, " " PROTO_NAME
" password clear %s\n",
1145 circuit
->passwd
.passwd
);
1148 write
+= hook_call(isis_circuit_config_write
,
1151 vty_endframe(vty
, "!\n");
1157 int isis_interface_config_write(struct vty
*vty
)
1159 struct vrf
*vrf
= vrf_lookup_by_id(VRF_DEFAULT
);
1161 struct interface
*ifp
;
1162 struct isis_circuit
*circuit
;
1163 struct lyd_node
*dnode
;
1165 FOR_ALL_INTERFACES (vrf
, ifp
) {
1166 dnode
= yang_dnode_get(
1167 running_config
->dnode
,
1168 "/frr-interface:lib/interface[name='%s'][vrf='%s']",
1169 ifp
->name
, vrf
->name
);
1174 nb_cli_show_dnode_cmds(vty
, dnode
, false);
1175 circuit
= circuit_scan_by_ifp(ifp
);
1177 write
+= hook_call(isis_circuit_config_write
, circuit
,
1182 #endif /* ifdef FABRICD */
1184 struct isis_circuit
*isis_circuit_create(struct isis_area
*area
,
1185 struct interface
*ifp
)
1187 struct isis_circuit
*circuit
= circuit_scan_by_ifp(ifp
);
1188 if (circuit
&& circuit
->area
)
1190 circuit
= isis_csm_state_change(ISIS_ENABLE
, circuit
, area
);
1191 if (circuit
->state
!= C_STATE_CONF
&& circuit
->state
!= C_STATE_UP
)
1193 isis_circuit_if_bind(circuit
, ifp
);
1197 void isis_circuit_af_set(struct isis_circuit
*circuit
, bool ip_router
,
1200 struct isis_area
*area
= circuit
->area
;
1201 bool change
= circuit
->ip_router
!= ip_router
1202 || circuit
->ipv6_router
!= ipv6_router
;
1204 area
->ip_circuits
+= ip_router
- circuit
->ip_router
;
1205 area
->ipv6_circuits
+= ipv6_router
- circuit
->ipv6_router
;
1206 circuit
->ip_router
= ip_router
;
1207 circuit
->ipv6_router
= ipv6_router
;
1212 circuit_update_nlpids(circuit
);
1214 if (!ip_router
&& !ipv6_router
)
1215 isis_csm_state_change(ISIS_DISABLE
, circuit
, area
);
1217 lsp_regenerate_schedule(circuit
->area
, circuit
->is_type
, 0);
1220 ferr_r
isis_circuit_passive_set(struct isis_circuit
*circuit
, bool passive
)
1222 if (circuit
->is_passive
== passive
)
1225 if (if_is_loopback(circuit
->interface
) && !passive
)
1226 return ferr_cfg_invalid("loopback is always passive");
1228 if (circuit
->state
!= C_STATE_UP
) {
1229 circuit
->is_passive
= passive
;
1231 struct isis_area
*area
= circuit
->area
;
1232 isis_csm_state_change(ISIS_DISABLE
, circuit
, area
);
1233 circuit
->is_passive
= passive
;
1234 isis_csm_state_change(ISIS_ENABLE
, circuit
, area
);
1240 ferr_r
isis_circuit_metric_set(struct isis_circuit
*circuit
, int level
,
1243 assert(level
== IS_LEVEL_1
|| level
== IS_LEVEL_2
);
1244 if (metric
> MAX_WIDE_LINK_METRIC
)
1245 return ferr_cfg_invalid("metric %d too large for wide metric",
1247 if (circuit
->area
&& circuit
->area
->oldmetric
1248 && metric
> MAX_NARROW_LINK_METRIC
)
1249 return ferr_cfg_invalid("metric %d too large for narrow metric",
1252 circuit
->te_metric
[level
- 1] = metric
;
1253 circuit
->metric
[level
- 1] = metric
;
1256 lsp_regenerate_schedule(circuit
->area
, level
, 0);
1260 ferr_r
isis_circuit_passwd_unset(struct isis_circuit
*circuit
)
1262 memset(&circuit
->passwd
, 0, sizeof(circuit
->passwd
));
1266 static int isis_circuit_passwd_set(struct isis_circuit
*circuit
,
1267 uint8_t passwd_type
, const char *passwd
)
1272 return ferr_code_bug("no circuit password given");
1274 len
= strlen(passwd
);
1276 return ferr_code_bug(
1277 "circuit password too long (max 254 chars)");
1279 circuit
->passwd
.len
= len
;
1280 strncpy((char *)circuit
->passwd
.passwd
, passwd
, 255);
1281 circuit
->passwd
.type
= passwd_type
;
1285 ferr_r
isis_circuit_passwd_cleartext_set(struct isis_circuit
*circuit
,
1288 return isis_circuit_passwd_set(circuit
, ISIS_PASSWD_TYPE_CLEARTXT
,
1292 ferr_r
isis_circuit_passwd_hmac_md5_set(struct isis_circuit
*circuit
,
1295 return isis_circuit_passwd_set(circuit
, ISIS_PASSWD_TYPE_HMAC_MD5
,
1299 struct cmd_node interface_node
= {
1300 INTERFACE_NODE
, "%s(config-if)# ", 1,
1303 void isis_circuit_circ_type_set(struct isis_circuit
*circuit
, int circ_type
)
1305 if (circuit
->circ_type
== circ_type
)
1308 if (circuit
->state
!= C_STATE_UP
) {
1309 circuit
->circ_type
= circ_type
;
1310 circuit
->circ_type_config
= circ_type
;
1312 struct isis_area
*area
= circuit
->area
;
1314 isis_csm_state_change(ISIS_DISABLE
, circuit
, area
);
1315 circuit
->circ_type
= circ_type
;
1316 circuit
->circ_type_config
= circ_type
;
1317 isis_csm_state_change(ISIS_ENABLE
, circuit
, area
);
1321 int isis_circuit_mt_enabled_set(struct isis_circuit
*circuit
, uint16_t mtid
,
1324 struct isis_circuit_mt_setting
*setting
;
1326 setting
= circuit_get_mt_setting(circuit
, mtid
);
1327 if (setting
->enabled
!= enabled
) {
1328 setting
->enabled
= enabled
;
1329 lsp_regenerate_schedule(circuit
->area
, IS_LEVEL_1
| IS_LEVEL_2
,
1336 int isis_if_new_hook(struct interface
*ifp
)
1341 int isis_if_delete_hook(struct interface
*ifp
)
1343 struct isis_circuit
*circuit
;
1344 /* Clean up the circuit data */
1345 if (ifp
&& ifp
->info
) {
1346 circuit
= ifp
->info
;
1347 isis_csm_state_change(IF_DOWN_FROM_Z
, circuit
, circuit
->area
);
1348 isis_csm_state_change(ISIS_DISABLE
, circuit
, circuit
->area
);
1354 void isis_circuit_init()
1356 /* Initialize Zebra interface data structure */
1357 hook_register_prio(if_add
, 0, isis_if_new_hook
);
1358 hook_register_prio(if_del
, 0, isis_if_delete_hook
);
1360 /* Install interface node */
1361 install_node(&interface_node
, isis_interface_config_write
);