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>
42 #include "isisd/dict.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_lsp_hash.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"
61 DEFINE_QOBJ_TYPE(isis_circuit
)
66 int isis_interface_config_write(struct vty
*);
67 int isis_if_new_hook(struct interface
*);
68 int isis_if_delete_hook(struct interface
*);
70 struct isis_circuit
*isis_circuit_new()
72 struct isis_circuit
*circuit
;
75 circuit
= XCALLOC(MTYPE_ISIS_CIRCUIT
, sizeof(struct isis_circuit
));
76 if (circuit
== NULL
) {
77 zlog_err("Can't malloc isis circuit");
84 circuit
->is_type
= IS_LEVEL_1_AND_2
;
86 circuit
->pad_hellos
= 1;
87 for (i
= 0; i
< 2; i
++) {
88 circuit
->hello_interval
[i
] = DEFAULT_HELLO_INTERVAL
;
89 circuit
->hello_multiplier
[i
] = DEFAULT_HELLO_MULTIPLIER
;
90 circuit
->csnp_interval
[i
] = DEFAULT_CSNP_INTERVAL
;
91 circuit
->psnp_interval
[i
] = DEFAULT_PSNP_INTERVAL
;
92 circuit
->priority
[i
] = DEFAULT_PRIORITY
;
93 circuit
->metric
[i
] = DEFAULT_CIRCUIT_METRIC
;
94 circuit
->te_metric
[i
] = DEFAULT_CIRCUIT_METRIC
;
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 (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_and_null(&circuit
->ip_addrs
);
458 if (circuit
->ipv6_link
) {
459 assert(listcount(circuit
->ipv6_link
) == 0);
460 list_delete_and_null(&circuit
->ipv6_link
);
463 if (circuit
->ipv6_non_link
) {
464 assert(listcount(circuit
->ipv6_non_link
) == 0);
465 list_delete_and_null(&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
;
501 dnode_t
*dnode
, *dnode_next
;
505 area
= circuit
->area
;
507 for (level
= ISIS_LEVEL1
; level
<= ISIS_LEVEL2
; level
++) {
508 if (level
& circuit
->is_type
) {
509 if (area
->lspdb
[level
- 1]
510 && dict_count(area
->lspdb
[level
- 1]) > 0) {
511 for (dnode
= dict_first(area
->lspdb
[level
- 1]);
512 dnode
!= NULL
; dnode
= dnode_next
) {
513 dnode_next
= dict_next(
514 area
->lspdb
[level
- 1], dnode
);
515 lsp
= dnode_get(dnode
);
517 ISIS_SET_FLAG(lsp
->SRMflags
,
520 ISIS_CLEAR_FLAG(lsp
->SRMflags
,
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(*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
)) {
574 "Interface MTU %zu on %s is too low to support area lsp mtu %u!",
575 isis_circuit_pdu_size(circuit
),
576 circuit
->interface
->name
, circuit
->area
->lsp_mtu
);
577 isis_circuit_update_all_srmflags(circuit
, 0);
581 if (circuit
->circ_type
== CIRCUIT_T_BROADCAST
) {
582 circuit
->circuit_id
= isis_circuit_id_gen(isis
, circuit
->interface
);
583 if (!circuit
->circuit_id
) {
584 zlog_err("There are already 255 broadcast circuits active!");
589 * Get the Hardware Address
591 if (circuit
->interface
->hw_addr_len
!= ETH_ALEN
) {
592 zlog_warn("unsupported link layer");
594 memcpy(circuit
->u
.bc
.snpa
, circuit
->interface
->hw_addr
,
598 zlog_debug("isis_circuit_if_add: if_id %d, isomtu %d snpa %s",
599 circuit
->interface
->ifindex
, ISO_MTU(circuit
),
600 snpa_print(circuit
->u
.bc
.snpa
));
601 #endif /* EXTREME_DEBUG */
603 circuit
->u
.bc
.adjdb
[0] = list_new();
604 circuit
->u
.bc
.adjdb
[1] = list_new();
607 * ISO 10589 - 8.4.1 Enabling of broadcast circuits
610 /* initilizing the hello sending threads
614 /* 8.4.1 a) commence sending of IIH PDUs */
616 if (circuit
->is_type
& IS_LEVEL_1
) {
617 thread_add_event(master
, send_lan_l1_hello
, circuit
, 0,
619 circuit
->u
.bc
.lan_neighs
[0] = list_new();
622 if (circuit
->is_type
& IS_LEVEL_2
) {
623 thread_add_event(master
, send_lan_l2_hello
, circuit
, 0,
625 circuit
->u
.bc
.lan_neighs
[1] = list_new();
628 /* 8.4.1 b) FIXME: solicit ES - 8.4.6 */
629 /* 8.4.1 c) FIXME: listen for ESH PDUs */
632 /* dr election will commence in... */
633 if (circuit
->is_type
& IS_LEVEL_1
)
634 thread_add_timer(master
, isis_run_dr_l1
, circuit
,
635 2 * circuit
->hello_interval
[0],
636 &circuit
->u
.bc
.t_run_dr
[0]);
637 if (circuit
->is_type
& IS_LEVEL_2
)
638 thread_add_timer(master
, isis_run_dr_l2
, circuit
,
639 2 * circuit
->hello_interval
[1],
640 &circuit
->u
.bc
.t_run_dr
[1]);
642 /* initializing the hello send threads
645 circuit
->u
.p2p
.neighbor
= NULL
;
646 thread_add_event(master
, send_p2p_hello
, circuit
, 0, NULL
);
649 /* initializing PSNP timers */
650 if (circuit
->is_type
& IS_LEVEL_1
)
652 master
, send_l1_psnp
, circuit
,
653 isis_jitter(circuit
->psnp_interval
[0], PSNP_JITTER
),
654 &circuit
->t_send_psnp
[0]);
656 if (circuit
->is_type
& IS_LEVEL_2
)
658 master
, send_l2_psnp
, circuit
,
659 isis_jitter(circuit
->psnp_interval
[1], PSNP_JITTER
),
660 &circuit
->t_send_psnp
[1]);
662 /* unified init for circuits; ignore warnings below this level */
663 retv
= isis_sock_init(circuit
);
664 if (retv
!= ISIS_OK
) {
665 isis_circuit_down(circuit
);
669 /* initialize the circuit streams after opening connection */
670 isis_circuit_stream(circuit
, &circuit
->rcv_stream
);
671 isis_circuit_stream(circuit
, &circuit
->snd_stream
);
673 isis_circuit_prepare(circuit
);
675 circuit
->lsp_queue
= list_new();
676 circuit
->lsp_hash
= isis_lsp_hash_new();
677 circuit
->lsp_queue_last_push
[0] = circuit
->lsp_queue_last_push
[1] =
683 void isis_circuit_down(struct isis_circuit
*circuit
)
685 if (circuit
->state
!= C_STATE_UP
)
688 /* Clear the flags for all the lsps of the circuit. */
689 isis_circuit_update_all_srmflags(circuit
, 0);
691 if (circuit
->circ_type
== CIRCUIT_T_BROADCAST
) {
692 /* destroy neighbour lists */
693 if (circuit
->u
.bc
.lan_neighs
[0]) {
694 list_delete_and_null(&circuit
->u
.bc
.lan_neighs
[0]);
695 circuit
->u
.bc
.lan_neighs
[0] = NULL
;
697 if (circuit
->u
.bc
.lan_neighs
[1]) {
698 list_delete_and_null(&circuit
->u
.bc
.lan_neighs
[1]);
699 circuit
->u
.bc
.lan_neighs
[1] = NULL
;
701 /* destroy adjacency databases */
702 if (circuit
->u
.bc
.adjdb
[0]) {
703 circuit
->u
.bc
.adjdb
[0]->del
= isis_delete_adj
;
704 list_delete_and_null(&circuit
->u
.bc
.adjdb
[0]);
705 circuit
->u
.bc
.adjdb
[0] = NULL
;
707 if (circuit
->u
.bc
.adjdb
[1]) {
708 circuit
->u
.bc
.adjdb
[1]->del
= isis_delete_adj
;
709 list_delete_and_null(&circuit
->u
.bc
.adjdb
[1]);
710 circuit
->u
.bc
.adjdb
[1] = NULL
;
712 if (circuit
->u
.bc
.is_dr
[0]) {
713 isis_dr_resign(circuit
, 1);
714 circuit
->u
.bc
.is_dr
[0] = 0;
716 memset(circuit
->u
.bc
.l1_desig_is
, 0, ISIS_SYS_ID_LEN
+ 1);
717 if (circuit
->u
.bc
.is_dr
[1]) {
718 isis_dr_resign(circuit
, 2);
719 circuit
->u
.bc
.is_dr
[1] = 0;
721 memset(circuit
->u
.bc
.l2_desig_is
, 0, ISIS_SYS_ID_LEN
+ 1);
722 memset(circuit
->u
.bc
.snpa
, 0, ETH_ALEN
);
724 THREAD_TIMER_OFF(circuit
->u
.bc
.t_send_lan_hello
[0]);
725 THREAD_TIMER_OFF(circuit
->u
.bc
.t_send_lan_hello
[1]);
726 THREAD_TIMER_OFF(circuit
->u
.bc
.t_run_dr
[0]);
727 THREAD_TIMER_OFF(circuit
->u
.bc
.t_run_dr
[1]);
728 THREAD_TIMER_OFF(circuit
->u
.bc
.t_refresh_pseudo_lsp
[0]);
729 THREAD_TIMER_OFF(circuit
->u
.bc
.t_refresh_pseudo_lsp
[1]);
730 circuit
->lsp_regenerate_pending
[0] = 0;
731 circuit
->lsp_regenerate_pending
[1] = 0;
733 _ISIS_CLEAR_FLAG(isis
->circuit_ids_used
, circuit
->circuit_id
);
734 circuit
->circuit_id
= 0;
735 } else if (circuit
->circ_type
== CIRCUIT_T_P2P
) {
736 isis_delete_adj(circuit
->u
.p2p
.neighbor
);
737 circuit
->u
.p2p
.neighbor
= NULL
;
738 THREAD_TIMER_OFF(circuit
->u
.p2p
.t_send_p2p_hello
);
741 /* Cancel all active threads */
742 THREAD_TIMER_OFF(circuit
->t_send_csnp
[0]);
743 THREAD_TIMER_OFF(circuit
->t_send_csnp
[1]);
744 THREAD_TIMER_OFF(circuit
->t_send_psnp
[0]);
745 THREAD_TIMER_OFF(circuit
->t_send_psnp
[1]);
746 THREAD_OFF(circuit
->t_send_lsp
);
747 THREAD_OFF(circuit
->t_read
);
749 if (circuit
->lsp_queue
) {
750 list_delete_and_null(&circuit
->lsp_queue
);
753 if (circuit
->lsp_hash
) {
754 isis_lsp_hash_free(circuit
->lsp_hash
);
755 circuit
->lsp_hash
= NULL
;
758 /* send one gratuitous hello to spead up convergence */
759 if (circuit
->is_type
& IS_LEVEL_1
)
760 send_hello(circuit
, IS_LEVEL_1
);
761 if (circuit
->is_type
& IS_LEVEL_2
)
762 send_hello(circuit
, IS_LEVEL_2
);
764 circuit
->upadjcount
[0] = 0;
765 circuit
->upadjcount
[1] = 0;
767 /* close the socket */
773 if (circuit
->rcv_stream
!= NULL
) {
774 stream_free(circuit
->rcv_stream
);
775 circuit
->rcv_stream
= NULL
;
778 if (circuit
->snd_stream
!= NULL
) {
779 stream_free(circuit
->snd_stream
);
780 circuit
->snd_stream
= NULL
;
783 thread_cancel_event(master
, circuit
);
788 void circuit_update_nlpids(struct isis_circuit
*circuit
)
790 circuit
->nlpids
.count
= 0;
792 if (circuit
->ip_router
) {
793 circuit
->nlpids
.nlpids
[0] = NLPID_IP
;
794 circuit
->nlpids
.count
++;
796 if (circuit
->ipv6_router
) {
797 circuit
->nlpids
.nlpids
[circuit
->nlpids
.count
] = NLPID_IPV6
;
798 circuit
->nlpids
.count
++;
803 void isis_circuit_print_vty(struct isis_circuit
*circuit
, struct vty
*vty
,
806 if (detail
== ISIS_UI_LEVEL_BRIEF
) {
807 vty_out(vty
, " %-12s", circuit
->interface
->name
);
808 vty_out(vty
, "0x%-7x", circuit
->circuit_id
);
809 vty_out(vty
, "%-9s", circuit_state2string(circuit
->state
));
810 vty_out(vty
, "%-9s", circuit_type2string(circuit
->circ_type
));
811 vty_out(vty
, "%-9s", circuit_t2string(circuit
->is_type
));
815 if (detail
== ISIS_UI_LEVEL_DETAIL
) {
816 struct listnode
*node
;
817 struct prefix
*ip_addr
;
820 vty_out(vty
, " Interface: %s", circuit
->interface
->name
);
821 vty_out(vty
, ", State: %s",
822 circuit_state2string(circuit
->state
));
823 if (circuit
->is_passive
)
824 vty_out(vty
, ", Passive");
826 vty_out(vty
, ", Active");
827 vty_out(vty
, ", Circuit Id: 0x%x", circuit
->circuit_id
);
829 vty_out(vty
, " Type: %s",
830 circuit_type2string(circuit
->circ_type
));
831 vty_out(vty
, ", Level: %s", circuit_t2string(circuit
->is_type
));
832 if (circuit
->circ_type
== CIRCUIT_T_BROADCAST
)
833 vty_out(vty
, ", SNPA: %-10s",
834 snpa_print(circuit
->u
.bc
.snpa
));
836 if (circuit
->is_type
& IS_LEVEL_1
) {
837 vty_out(vty
, " Level-1 Information:\n");
838 if (circuit
->area
->newmetric
)
839 vty_out(vty
, " Metric: %d",
840 circuit
->te_metric
[0]);
842 vty_out(vty
, " Metric: %d",
844 if (!circuit
->is_passive
) {
845 vty_out(vty
, ", Active neighbors: %u\n",
846 circuit
->upadjcount
[0]);
848 " Hello interval: %u, "
849 "Holddown count: %u %s\n",
850 circuit
->hello_interval
[0],
851 circuit
->hello_multiplier
[0],
852 (circuit
->pad_hellos
? "(pad)"
855 " CNSP interval: %u, "
856 "PSNP interval: %u\n",
857 circuit
->csnp_interval
[0],
858 circuit
->psnp_interval
[0]);
859 if (circuit
->circ_type
== CIRCUIT_T_BROADCAST
)
861 " LAN Priority: %u, %s\n",
862 circuit
->priority
[0],
863 (circuit
->u
.bc
.is_dr
[0]
870 if (circuit
->is_type
& IS_LEVEL_2
) {
871 vty_out(vty
, " Level-2 Information:\n");
872 if (circuit
->area
->newmetric
)
873 vty_out(vty
, " Metric: %d",
874 circuit
->te_metric
[1]);
876 vty_out(vty
, " Metric: %d",
878 if (!circuit
->is_passive
) {
879 vty_out(vty
, ", Active neighbors: %u\n",
880 circuit
->upadjcount
[1]);
882 " Hello interval: %u, "
883 "Holddown count: %u %s\n",
884 circuit
->hello_interval
[1],
885 circuit
->hello_multiplier
[1],
886 (circuit
->pad_hellos
? "(pad)"
889 " CNSP interval: %u, "
890 "PSNP interval: %u\n",
891 circuit
->csnp_interval
[1],
892 circuit
->psnp_interval
[1]);
893 if (circuit
->circ_type
== CIRCUIT_T_BROADCAST
)
895 " LAN Priority: %u, %s\n",
896 circuit
->priority
[1],
897 (circuit
->u
.bc
.is_dr
[1]
904 if (circuit
->ip_addrs
&& listcount(circuit
->ip_addrs
) > 0) {
905 vty_out(vty
, " IP Prefix(es):\n");
906 for (ALL_LIST_ELEMENTS_RO(circuit
->ip_addrs
, node
,
908 prefix2str(ip_addr
, buf
, sizeof(buf
)),
909 vty_out(vty
, " %s\n", buf
);
912 if (circuit
->ipv6_link
&& listcount(circuit
->ipv6_link
) > 0) {
913 vty_out(vty
, " IPv6 Link-Locals:\n");
914 for (ALL_LIST_ELEMENTS_RO(circuit
->ipv6_link
, node
,
916 prefix2str(ip_addr
, (char *)buf
, BUFSIZ
),
917 vty_out(vty
, " %s\n", buf
);
920 if (circuit
->ipv6_non_link
921 && listcount(circuit
->ipv6_non_link
) > 0) {
922 vty_out(vty
, " IPv6 Prefixes:\n");
923 for (ALL_LIST_ELEMENTS_RO(circuit
->ipv6_non_link
, node
,
925 prefix2str(ip_addr
, (char *)buf
, BUFSIZ
),
926 vty_out(vty
, " %s\n", buf
);
935 int isis_interface_config_write(struct vty
*vty
)
937 struct vrf
*vrf
= vrf_lookup_by_id(VRF_DEFAULT
);
939 struct listnode
*node
;
940 struct interface
*ifp
;
941 struct isis_area
*area
;
942 struct isis_circuit
*circuit
;
945 FOR_ALL_INTERFACES (vrf
, ifp
) {
947 vty_frame(vty
, "interface %s\n", ifp
->name
);
951 vty_out(vty
, " description %s\n", ifp
->desc
);
955 for (ALL_LIST_ELEMENTS_RO(isis
->area_list
, node
, area
)) {
957 circuit_lookup_by_ifp(ifp
, area
->circuit_list
);
960 if (circuit
->ip_router
) {
961 vty_out(vty
, " ip router isis %s\n",
965 if (circuit
->is_passive
) {
966 vty_out(vty
, " isis passive\n");
969 if (circuit
->circ_type_config
== CIRCUIT_T_P2P
) {
970 vty_out(vty
, " isis network point-to-point\n");
973 if (circuit
->ipv6_router
) {
974 vty_out(vty
, " ipv6 router isis %s\n",
979 /* ISIS - circuit type */
980 if (circuit
->is_type
== IS_LEVEL_1
) {
981 vty_out(vty
, " isis circuit-type level-1\n");
984 if (circuit
->is_type
== IS_LEVEL_2
) {
986 " isis circuit-type level-2-only\n");
991 /* ISIS - CSNP interval */
992 if (circuit
->csnp_interval
[0]
993 == circuit
->csnp_interval
[1]) {
994 if (circuit
->csnp_interval
[0]
995 != DEFAULT_CSNP_INTERVAL
) {
996 vty_out(vty
, " isis csnp-interval %d\n",
997 circuit
->csnp_interval
[0]);
1001 for (i
= 0; i
< 2; i
++) {
1002 if (circuit
->csnp_interval
[i
]
1003 != DEFAULT_CSNP_INTERVAL
) {
1005 " isis csnp-interval %d level-%d\n",
1006 circuit
->csnp_interval
1014 /* ISIS - PSNP interval */
1015 if (circuit
->psnp_interval
[0]
1016 == circuit
->psnp_interval
[1]) {
1017 if (circuit
->psnp_interval
[0]
1018 != DEFAULT_PSNP_INTERVAL
) {
1019 vty_out(vty
, " isis psnp-interval %d\n",
1020 circuit
->psnp_interval
[0]);
1024 for (i
= 0; i
< 2; i
++) {
1025 if (circuit
->psnp_interval
[i
]
1026 != DEFAULT_PSNP_INTERVAL
) {
1028 " isis psnp-interval %d level-%d\n",
1029 circuit
->psnp_interval
1037 /* ISIS - Hello padding - Defaults to true so only
1038 * display if false */
1039 if (circuit
->pad_hellos
== 0) {
1040 vty_out(vty
, " no isis hello padding\n");
1044 if (circuit
->disable_threeway_adj
) {
1045 vty_out(vty
, " no isis three-way-handshake\n");
1049 /* ISIS - Hello interval */
1050 if (circuit
->hello_interval
[0]
1051 == circuit
->hello_interval
[1]) {
1052 if (circuit
->hello_interval
[0]
1053 != DEFAULT_HELLO_INTERVAL
) {
1055 " isis hello-interval %d\n",
1056 circuit
->hello_interval
[0]);
1060 for (i
= 0; i
< 2; i
++) {
1061 if (circuit
->hello_interval
[i
]
1062 != DEFAULT_HELLO_INTERVAL
) {
1064 " isis hello-interval %d level-%d\n",
1065 circuit
->hello_interval
1073 /* ISIS - Hello Multiplier */
1074 if (circuit
->hello_multiplier
[0]
1075 == circuit
->hello_multiplier
[1]) {
1076 if (circuit
->hello_multiplier
[0]
1077 != DEFAULT_HELLO_MULTIPLIER
) {
1079 " isis hello-multiplier %d\n",
1080 circuit
->hello_multiplier
[0]);
1084 for (i
= 0; i
< 2; i
++) {
1085 if (circuit
->hello_multiplier
[i
]
1086 != DEFAULT_HELLO_MULTIPLIER
) {
1088 " isis hello-multiplier %d level-%d\n",
1089 circuit
->hello_multiplier
1097 /* ISIS - Priority */
1098 if (circuit
->priority
[0] == circuit
->priority
[1]) {
1099 if (circuit
->priority
[0] != DEFAULT_PRIORITY
) {
1100 vty_out(vty
, " isis priority %d\n",
1101 circuit
->priority
[0]);
1105 for (i
= 0; i
< 2; i
++) {
1106 if (circuit
->priority
[i
]
1107 != DEFAULT_PRIORITY
) {
1109 " isis priority %d level-%d\n",
1110 circuit
->priority
[i
],
1118 if (circuit
->te_metric
[0] == circuit
->te_metric
[1]) {
1119 if (circuit
->te_metric
[0]
1120 != DEFAULT_CIRCUIT_METRIC
) {
1121 vty_out(vty
, " isis metric %d\n",
1122 circuit
->te_metric
[0]);
1126 for (i
= 0; i
< 2; i
++) {
1127 if (circuit
->te_metric
[i
]
1128 != DEFAULT_CIRCUIT_METRIC
) {
1130 " isis metric %d level-%d\n",
1131 circuit
->te_metric
[i
],
1137 if (circuit
->passwd
.type
== ISIS_PASSWD_TYPE_HMAC_MD5
) {
1138 vty_out(vty
, " isis password md5 %s\n",
1139 circuit
->passwd
.passwd
);
1141 } else if (circuit
->passwd
.type
1142 == ISIS_PASSWD_TYPE_CLEARTXT
) {
1143 vty_out(vty
, " isis password clear %s\n",
1144 circuit
->passwd
.passwd
);
1147 write
+= circuit_write_mt_settings(circuit
, vty
);
1149 vty_endframe(vty
, "!\n");
1155 struct isis_circuit
*isis_circuit_create(struct isis_area
*area
,
1156 struct interface
*ifp
)
1158 struct isis_circuit
*circuit
= circuit_scan_by_ifp(ifp
);
1159 if (circuit
&& circuit
->area
)
1161 circuit
= isis_csm_state_change(ISIS_ENABLE
, circuit
, area
);
1162 if (circuit
->state
!= C_STATE_CONF
&& circuit
->state
!= C_STATE_UP
)
1164 isis_circuit_if_bind(circuit
, ifp
);
1168 void isis_circuit_af_set(struct isis_circuit
*circuit
, bool ip_router
,
1171 struct isis_area
*area
= circuit
->area
;
1172 bool change
= circuit
->ip_router
!= ip_router
1173 || circuit
->ipv6_router
!= ipv6_router
;
1175 area
->ip_circuits
+= ip_router
- circuit
->ip_router
;
1176 area
->ipv6_circuits
+= ipv6_router
- circuit
->ipv6_router
;
1177 circuit
->ip_router
= ip_router
;
1178 circuit
->ipv6_router
= ipv6_router
;
1183 circuit_update_nlpids(circuit
);
1185 if (!ip_router
&& !ipv6_router
)
1186 isis_csm_state_change(ISIS_DISABLE
, circuit
, area
);
1188 lsp_regenerate_schedule(circuit
->area
, circuit
->is_type
, 0);
1191 ferr_r
isis_circuit_passive_set(struct isis_circuit
*circuit
, bool passive
)
1193 if (circuit
->is_passive
== passive
)
1196 if (if_is_loopback(circuit
->interface
) && !passive
)
1197 return ferr_cfg_invalid("loopback is always passive");
1199 if (circuit
->state
!= C_STATE_UP
) {
1200 circuit
->is_passive
= passive
;
1202 struct isis_area
*area
= circuit
->area
;
1203 isis_csm_state_change(ISIS_DISABLE
, circuit
, area
);
1204 circuit
->is_passive
= passive
;
1205 isis_csm_state_change(ISIS_ENABLE
, circuit
, area
);
1211 ferr_r
isis_circuit_metric_set(struct isis_circuit
*circuit
, int level
,
1214 assert(level
== IS_LEVEL_1
|| level
== IS_LEVEL_2
);
1215 if (metric
> MAX_WIDE_LINK_METRIC
)
1216 return ferr_cfg_invalid("metric %d too large for wide metric",
1218 if (circuit
->area
&& circuit
->area
->oldmetric
1219 && metric
> MAX_NARROW_LINK_METRIC
)
1220 return ferr_cfg_invalid("metric %d too large for narrow metric",
1223 circuit
->te_metric
[level
- 1] = metric
;
1224 circuit
->metric
[level
- 1] = metric
;
1227 lsp_regenerate_schedule(circuit
->area
, level
, 0);
1231 ferr_r
isis_circuit_passwd_unset(struct isis_circuit
*circuit
)
1233 memset(&circuit
->passwd
, 0, sizeof(circuit
->passwd
));
1237 static int isis_circuit_passwd_set(struct isis_circuit
*circuit
,
1238 uint8_t passwd_type
, const char *passwd
)
1243 return ferr_code_bug("no circuit password given");
1245 len
= strlen(passwd
);
1247 return ferr_code_bug(
1248 "circuit password too long (max 254 chars)");
1250 circuit
->passwd
.len
= len
;
1251 strncpy((char *)circuit
->passwd
.passwd
, passwd
, 255);
1252 circuit
->passwd
.type
= passwd_type
;
1256 ferr_r
isis_circuit_passwd_cleartext_set(struct isis_circuit
*circuit
,
1259 return isis_circuit_passwd_set(circuit
, ISIS_PASSWD_TYPE_CLEARTXT
,
1263 ferr_r
isis_circuit_passwd_hmac_md5_set(struct isis_circuit
*circuit
,
1266 return isis_circuit_passwd_set(circuit
, ISIS_PASSWD_TYPE_HMAC_MD5
,
1270 struct cmd_node interface_node
= {
1271 INTERFACE_NODE
, "%s(config-if)# ", 1,
1274 ferr_r
isis_circuit_circ_type_set(struct isis_circuit
*circuit
, int circ_type
)
1276 if (circuit
->circ_type
== circ_type
)
1279 /* Changing the network type to/of loopback or unknown interfaces
1280 * is not supported. */
1281 if (circ_type
== CIRCUIT_T_UNKNOWN
|| circ_type
== CIRCUIT_T_LOOPBACK
1282 || circuit
->circ_type
== CIRCUIT_T_LOOPBACK
) {
1283 return ferr_cfg_invalid(
1284 "cannot change network type on unknown interface");
1287 if (circuit
->state
!= C_STATE_UP
) {
1288 circuit
->circ_type
= circ_type
;
1289 circuit
->circ_type_config
= circ_type
;
1291 struct isis_area
*area
= circuit
->area
;
1292 if (circ_type
== CIRCUIT_T_BROADCAST
1293 && !if_is_broadcast(circuit
->interface
))
1294 return ferr_cfg_reality(
1295 "cannot configure non-broadcast interface for broadcast operation");
1297 isis_csm_state_change(ISIS_DISABLE
, circuit
, area
);
1298 circuit
->circ_type
= circ_type
;
1299 circuit
->circ_type_config
= circ_type
;
1300 isis_csm_state_change(ISIS_ENABLE
, circuit
, area
);
1305 int isis_circuit_mt_enabled_set(struct isis_circuit
*circuit
, uint16_t mtid
,
1308 struct isis_circuit_mt_setting
*setting
;
1310 setting
= circuit_get_mt_setting(circuit
, mtid
);
1311 if (setting
->enabled
!= enabled
) {
1312 setting
->enabled
= enabled
;
1313 lsp_regenerate_schedule(circuit
->area
, IS_LEVEL_1
| IS_LEVEL_2
,
1320 int isis_if_new_hook(struct interface
*ifp
)
1325 int isis_if_delete_hook(struct interface
*ifp
)
1327 struct isis_circuit
*circuit
;
1328 /* Clean up the circuit data */
1329 if (ifp
&& ifp
->info
) {
1330 circuit
= ifp
->info
;
1331 isis_csm_state_change(IF_DOWN_FROM_Z
, circuit
, circuit
->area
);
1332 isis_csm_state_change(ISIS_DISABLE
, circuit
, circuit
->area
);
1338 void isis_circuit_init()
1340 /* Initialize Zebra interface data structure */
1341 hook_register_prio(if_add
, 0, isis_if_new_hook
);
1342 hook_register_prio(if_del
, 0, isis_if_delete_hook
);
1344 /* Install interface node */
1345 install_node(&interface_node
, isis_interface_config_write
);
1351 void isis_circuit_schedule_lsp_send(struct isis_circuit
*circuit
)
1353 if (circuit
->t_send_lsp
)
1355 circuit
->t_send_lsp
=
1356 thread_add_event(master
, send_lsp
, circuit
, 0, NULL
);
1359 void isis_circuit_queue_lsp(struct isis_circuit
*circuit
, struct isis_lsp
*lsp
)
1361 if (isis_lsp_hash_lookup(circuit
->lsp_hash
, lsp
))
1364 listnode_add(circuit
->lsp_queue
, lsp
);
1365 isis_lsp_hash_add(circuit
->lsp_hash
, lsp
);
1366 isis_circuit_schedule_lsp_send(circuit
);
1369 void isis_circuit_lsp_queue_clean(struct isis_circuit
*circuit
)
1371 if (!circuit
->lsp_queue
)
1374 list_delete_all_node(circuit
->lsp_queue
);
1375 isis_lsp_hash_clean(circuit
->lsp_hash
);
1378 void isis_circuit_cancel_queued_lsp(struct isis_circuit
*circuit
,
1379 struct isis_lsp
*lsp
)
1381 if (!circuit
->lsp_queue
)
1384 listnode_delete(circuit
->lsp_queue
, lsp
);
1385 isis_lsp_hash_release(circuit
->lsp_hash
, lsp
);
1388 struct isis_lsp
*isis_circuit_lsp_queue_pop(struct isis_circuit
*circuit
)
1390 if (!circuit
->lsp_queue
)
1393 struct listnode
*node
= listhead(circuit
->lsp_queue
);
1397 struct isis_lsp
*rv
= listgetdata(node
);
1399 list_delete_node(circuit
->lsp_queue
, node
);
1400 isis_lsp_hash_release(circuit
->lsp_hash
, rv
);