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; if not, write to the Free Software Foundation, Inc.,
20 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
24 #include <net/ethernet.h>
26 #include <netinet/if_ether.h>
29 #ifndef ETHER_ADDR_LEN
30 #define ETHER_ADDR_LEN ETHERADDRL
46 #include "isisd/dict.h"
47 #include "isisd/isis_constants.h"
48 #include "isisd/isis_common.h"
49 #include "isisd/isis_flags.h"
50 #include "isisd/isis_circuit.h"
51 #include "isisd/isis_tlv.h"
52 #include "isisd/isis_lsp.h"
53 #include "isisd/isis_pdu.h"
54 #include "isisd/isis_network.h"
55 #include "isisd/isis_misc.h"
56 #include "isisd/isis_constants.h"
57 #include "isisd/isis_adjacency.h"
58 #include "isisd/isis_dr.h"
59 #include "isisd/isisd.h"
60 #include "isisd/isis_csm.h"
61 #include "isisd/isis_events.h"
62 #include "isisd/isis_te.h"
64 DEFINE_QOBJ_TYPE(isis_circuit
)
69 int isis_interface_config_write(struct vty
*);
70 int isis_if_new_hook(struct interface
*);
71 int isis_if_delete_hook(struct interface
*);
76 struct isis_circuit
*circuit
;
79 circuit
= XCALLOC (MTYPE_ISIS_CIRCUIT
, sizeof (struct isis_circuit
));
82 zlog_err ("Can't malloc isis circuit");
89 circuit
->is_type
= IS_LEVEL_1_AND_2
;
91 circuit
->pad_hellos
= 1;
92 for (i
= 0; i
< 2; i
++)
94 circuit
->hello_interval
[i
] = DEFAULT_HELLO_INTERVAL
;
95 circuit
->hello_multiplier
[i
] = DEFAULT_HELLO_MULTIPLIER
;
96 circuit
->csnp_interval
[i
] = DEFAULT_CSNP_INTERVAL
;
97 circuit
->psnp_interval
[i
] = DEFAULT_PSNP_INTERVAL
;
98 circuit
->priority
[i
] = DEFAULT_PRIORITY
;
99 circuit
->metric
[i
] = DEFAULT_CIRCUIT_METRIC
;
100 circuit
->te_metric
[i
] = DEFAULT_CIRCUIT_METRIC
;
103 circuit
->mtc
= mpls_te_circuit_new();
105 QOBJ_REG (circuit
, isis_circuit
);
111 isis_circuit_del (struct isis_circuit
*circuit
)
116 QOBJ_UNREG (circuit
);
118 isis_circuit_if_unbind (circuit
, circuit
->interface
);
120 /* and lastly the circuit itself */
121 XFREE (MTYPE_ISIS_CIRCUIT
, circuit
);
127 isis_circuit_configure (struct isis_circuit
*circuit
, struct isis_area
*area
)
130 circuit
->area
= area
;
133 * Whenever the is-type of an area is changed, the is-type of each circuit
134 * in that area is updated to a non-empty subset of the area is-type.
135 * Inversely, when configuring a new circuit, this property should be
138 if (area
->is_type
!= IS_LEVEL_1_AND_2
)
139 circuit
->is_type
= area
->is_type
;
142 * Add the circuit into area
144 listnode_add (area
->circuit_list
, circuit
);
146 circuit
->idx
= flags_get_index (&area
->flags
);
152 isis_circuit_deconfigure (struct isis_circuit
*circuit
, struct isis_area
*area
)
154 /* Free the index of SRM and SSN flags */
155 flags_free_index (&area
->flags
, circuit
->idx
);
157 /* Remove circuit from area */
158 assert (circuit
->area
== area
);
159 listnode_delete (area
->circuit_list
, circuit
);
160 circuit
->area
= NULL
;
165 struct isis_circuit
*
166 circuit_lookup_by_ifp (struct interface
*ifp
, struct list
*list
)
168 struct isis_circuit
*circuit
= NULL
;
169 struct listnode
*node
;
174 for (ALL_LIST_ELEMENTS_RO (list
, node
, circuit
))
175 if (circuit
->interface
== ifp
)
177 assert (ifp
->info
== circuit
);
184 struct isis_circuit
*
185 circuit_scan_by_ifp (struct interface
*ifp
)
187 struct isis_area
*area
;
188 struct listnode
*node
;
189 struct isis_circuit
*circuit
;
192 return (struct isis_circuit
*)ifp
->info
;
196 for (ALL_LIST_ELEMENTS_RO (isis
->area_list
, node
, area
))
198 circuit
= circuit_lookup_by_ifp (ifp
, area
->circuit_list
);
203 return circuit_lookup_by_ifp (ifp
, isis
->init_circ_list
);
207 isis_circuit_add_addr (struct isis_circuit
*circuit
,
208 struct connected
*connected
)
210 struct listnode
*node
;
211 struct prefix_ipv4
*ipv4
;
212 #if defined(EXTREME_DEBUG)
213 char buf
[PREFIX2STR_BUFFER
];
215 struct prefix_ipv6
*ipv6
;
217 if (connected
->address
->family
== AF_INET
)
219 u_int32_t addr
= connected
->address
->u
.prefix4
.s_addr
;
221 if (IPV4_NET0(addr
) ||
224 IPV4_LINKLOCAL(addr
))
227 for (ALL_LIST_ELEMENTS_RO (circuit
->ip_addrs
, node
, ipv4
))
228 if (prefix_same ((struct prefix
*) ipv4
, connected
->address
))
231 ipv4
= prefix_ipv4_new ();
232 ipv4
->prefixlen
= connected
->address
->prefixlen
;
233 ipv4
->prefix
= connected
->address
->u
.prefix4
;
234 listnode_add (circuit
->ip_addrs
, ipv4
);
236 /* Update MPLS TE Local IP address parameter */
237 set_circuitparams_local_ipaddr (circuit
->mtc
, ipv4
->prefix
);
240 lsp_regenerate_schedule (circuit
->area
, circuit
->is_type
, 0);
243 prefix2str (connected
->address
, buf
, sizeof (buf
));
244 zlog_debug ("Added IP address %s to circuit %d", buf
,
245 circuit
->circuit_id
);
246 #endif /* EXTREME_DEBUG */
248 if (connected
->address
->family
== AF_INET6
)
250 if (IN6_IS_ADDR_LOOPBACK(&connected
->address
->u
.prefix6
))
253 for (ALL_LIST_ELEMENTS_RO (circuit
->ipv6_link
, node
, ipv6
))
254 if (prefix_same ((struct prefix
*) ipv6
, connected
->address
))
256 for (ALL_LIST_ELEMENTS_RO (circuit
->ipv6_non_link
, node
, ipv6
))
257 if (prefix_same ((struct prefix
*) ipv6
, connected
->address
))
260 ipv6
= prefix_ipv6_new ();
261 ipv6
->prefixlen
= connected
->address
->prefixlen
;
262 ipv6
->prefix
= connected
->address
->u
.prefix6
;
264 if (IN6_IS_ADDR_LINKLOCAL (&ipv6
->prefix
))
265 listnode_add (circuit
->ipv6_link
, ipv6
);
267 listnode_add (circuit
->ipv6_non_link
, ipv6
);
269 lsp_regenerate_schedule (circuit
->area
, circuit
->is_type
, 0);
272 prefix2str (connected
->address
, buf
, sizeof (buf
));
273 zlog_debug ("Added IPv6 address %s to circuit %d", buf
,
274 circuit
->circuit_id
);
275 #endif /* EXTREME_DEBUG */
281 isis_circuit_del_addr (struct isis_circuit
*circuit
,
282 struct connected
*connected
)
284 struct prefix_ipv4
*ipv4
, *ip
= NULL
;
285 struct listnode
*node
;
286 char buf
[PREFIX2STR_BUFFER
];
288 struct prefix_ipv6
*ipv6
, *ip6
= NULL
;
290 #endif /* HAVE_IPV6 */
292 if (connected
->address
->family
== AF_INET
)
294 ipv4
= prefix_ipv4_new ();
295 ipv4
->prefixlen
= connected
->address
->prefixlen
;
296 ipv4
->prefix
= connected
->address
->u
.prefix4
;
298 for (ALL_LIST_ELEMENTS_RO (circuit
->ip_addrs
, node
, ip
))
299 if (prefix_same ((struct prefix
*) ip
, (struct prefix
*) ipv4
))
304 listnode_delete (circuit
->ip_addrs
, ip
);
306 lsp_regenerate_schedule (circuit
->area
, circuit
->is_type
, 0);
310 prefix2str (connected
->address
, buf
, sizeof (buf
));
311 zlog_warn ("Nonexitant ip address %s removal attempt from \
312 circuit %d", buf
, circuit
->circuit_id
);
313 zlog_warn ("Current ip addresses on %s:", circuit
->interface
->name
);
314 for (ALL_LIST_ELEMENTS_RO(circuit
->ip_addrs
, node
, ip
))
316 prefix2str((struct prefix
*)ip
, (char *)buf
, BUFSIZ
);
317 zlog_warn(" %s", buf
);
319 zlog_warn("End of addresses");
322 prefix_ipv4_free (ipv4
);
325 if (connected
->address
->family
== AF_INET6
)
327 ipv6
= prefix_ipv6_new ();
328 ipv6
->prefixlen
= connected
->address
->prefixlen
;
329 ipv6
->prefix
= connected
->address
->u
.prefix6
;
331 if (IN6_IS_ADDR_LINKLOCAL (&ipv6
->prefix
))
333 for (ALL_LIST_ELEMENTS_RO (circuit
->ipv6_link
, node
, ip6
))
335 if (prefix_same ((struct prefix
*) ip6
, (struct prefix
*) ipv6
))
340 listnode_delete (circuit
->ipv6_link
, ip6
);
346 for (ALL_LIST_ELEMENTS_RO (circuit
->ipv6_non_link
, node
, ip6
))
348 if (prefix_same ((struct prefix
*) ip6
, (struct prefix
*) ipv6
))
353 listnode_delete (circuit
->ipv6_non_link
, ip6
);
360 prefix2str (connected
->address
, buf
, sizeof (buf
));
361 zlog_warn ("Nonexitant ip address %s removal attempt from \
362 circuit %d", buf
, circuit
->circuit_id
);
363 zlog_warn ("Current ip addresses on %s:", circuit
->interface
->name
);
364 for (ALL_LIST_ELEMENTS_RO(circuit
->ipv6_link
, node
, ip6
))
366 prefix2str((struct prefix
*)ip6
, (char *)buf
, BUFSIZ
);
367 zlog_warn(" %s", buf
);
370 for (ALL_LIST_ELEMENTS_RO(circuit
->ipv6_non_link
, node
, ip6
))
372 prefix2str((struct prefix
*)ip6
, (char *)buf
, BUFSIZ
);
373 zlog_warn(" %s", buf
);
375 zlog_warn("End of addresses");
377 else if (circuit
->area
)
378 lsp_regenerate_schedule (circuit
->area
, circuit
->is_type
, 0);
380 prefix_ipv6_free (ipv6
);
382 #endif /* HAVE_IPV6 */
387 isis_circuit_id_gen (struct interface
*ifp
)
392 int start
= -1, end
= -1;
395 * Get a stable circuit id from ifname. This makes
396 * the ifindex from flapping when netdevs are created
397 * and deleted on the fly. Note that this circuit id
398 * is used in pseudo lsps so it is better to be stable.
399 * The following code works on any reasonanle ifname
400 * like: eth1 or trk-1.1 etc.
402 for (i
= 0; i
< strlen (ifp
->name
); i
++)
404 if (isdigit((unsigned char)ifp
->name
[i
]))
420 if ((start
>= 0) && (end
>= start
) && (end
- start
) < 16)
422 memset (ifname
, 0, 16);
423 strncpy (ifname
, &ifp
->name
[start
], end
- start
);
424 id
= (u_char
)atoi(ifname
);
427 /* Try to be unique. */
429 id
= (u_char
)((ifp
->ifindex
& 0xff) | 0x80);
435 isis_circuit_if_add (struct isis_circuit
*circuit
, struct interface
*ifp
)
437 struct listnode
*node
, *nnode
;
438 struct connected
*conn
;
440 circuit
->circuit_id
= isis_circuit_id_gen (ifp
);
442 isis_circuit_if_bind (circuit
, ifp
);
443 /* isis_circuit_update_addrs (circuit, ifp); */
445 if (if_is_broadcast (ifp
))
447 if (circuit
->circ_type_config
== CIRCUIT_T_P2P
)
448 circuit
->circ_type
= CIRCUIT_T_P2P
;
450 circuit
->circ_type
= CIRCUIT_T_BROADCAST
;
452 else if (if_is_pointopoint (ifp
))
454 circuit
->circ_type
= CIRCUIT_T_P2P
;
456 else if (if_is_loopback (ifp
))
458 circuit
->circ_type
= CIRCUIT_T_LOOPBACK
;
459 circuit
->is_passive
= 1;
463 /* It's normal in case of loopback etc. */
464 if (isis
->debugs
& DEBUG_EVENTS
)
465 zlog_debug ("isis_circuit_if_add: unsupported media");
466 circuit
->circ_type
= CIRCUIT_T_UNKNOWN
;
469 circuit
->ip_addrs
= list_new ();
471 circuit
->ipv6_link
= list_new ();
472 circuit
->ipv6_non_link
= list_new ();
473 #endif /* HAVE_IPV6 */
475 for (ALL_LIST_ELEMENTS (ifp
->connected
, node
, nnode
, conn
))
476 isis_circuit_add_addr (circuit
, conn
);
482 isis_circuit_if_del (struct isis_circuit
*circuit
, struct interface
*ifp
)
484 struct listnode
*node
, *nnode
;
485 struct connected
*conn
;
487 assert (circuit
->interface
== ifp
);
489 /* destroy addresses */
490 for (ALL_LIST_ELEMENTS (ifp
->connected
, node
, nnode
, conn
))
491 isis_circuit_del_addr (circuit
, conn
);
493 if (circuit
->ip_addrs
)
495 assert (listcount(circuit
->ip_addrs
) == 0);
496 list_delete (circuit
->ip_addrs
);
497 circuit
->ip_addrs
= NULL
;
501 if (circuit
->ipv6_link
)
503 assert (listcount(circuit
->ipv6_link
) == 0);
504 list_delete (circuit
->ipv6_link
);
505 circuit
->ipv6_link
= NULL
;
508 if (circuit
->ipv6_non_link
)
510 assert (listcount(circuit
->ipv6_non_link
) == 0);
511 list_delete (circuit
->ipv6_non_link
);
512 circuit
->ipv6_non_link
= NULL
;
514 #endif /* HAVE_IPV6 */
516 circuit
->circ_type
= CIRCUIT_T_UNKNOWN
;
517 circuit
->circuit_id
= 0;
523 isis_circuit_if_bind (struct isis_circuit
*circuit
, struct interface
*ifp
)
525 assert (circuit
!= NULL
);
526 assert (ifp
!= NULL
);
527 if (circuit
->interface
)
528 assert (circuit
->interface
== ifp
);
530 circuit
->interface
= ifp
;
532 assert (ifp
->info
== circuit
);
535 isis_link_params_update (circuit
, ifp
);
539 isis_circuit_if_unbind (struct isis_circuit
*circuit
, struct interface
*ifp
)
541 assert (circuit
!= NULL
);
542 assert (ifp
!= NULL
);
543 assert (circuit
->interface
== ifp
);
544 assert (ifp
->info
== circuit
);
545 circuit
->interface
= NULL
;
550 isis_circuit_update_all_srmflags (struct isis_circuit
*circuit
, int is_set
)
552 struct isis_area
*area
;
553 struct isis_lsp
*lsp
;
554 dnode_t
*dnode
, *dnode_next
;
558 area
= circuit
->area
;
560 for (level
= ISIS_LEVEL1
; level
<= ISIS_LEVEL2
; level
++)
562 if (level
& circuit
->is_type
)
564 if (area
->lspdb
[level
- 1] &&
565 dict_count (area
->lspdb
[level
- 1]) > 0)
567 for (dnode
= dict_first (area
->lspdb
[level
- 1]);
568 dnode
!= NULL
; dnode
= dnode_next
)
570 dnode_next
= dict_next (area
->lspdb
[level
- 1], dnode
);
571 lsp
= dnode_get (dnode
);
574 ISIS_SET_FLAG (lsp
->SRMflags
, circuit
);
578 ISIS_CLEAR_FLAG (lsp
->SRMflags
, circuit
);
587 isis_circuit_pdu_size(struct isis_circuit
*circuit
)
589 return ISO_MTU(circuit
);
593 isis_circuit_stream(struct isis_circuit
*circuit
, struct stream
**stream
)
595 size_t stream_size
= isis_circuit_pdu_size(circuit
);
599 *stream
= stream_new(stream_size
);
603 if (STREAM_SIZE(*stream
) != stream_size
)
604 stream_resize(*stream
, stream_size
);
605 stream_reset(*stream
);
610 isis_circuit_prepare (struct isis_circuit
*circuit
)
613 THREAD_READ_ON (master
, circuit
->t_read
, isis_receive
, circuit
,
616 THREAD_TIMER_MSEC_ON (master
, circuit
->t_read
, isis_receive
, circuit
,
617 listcount (circuit
->area
->circuit_list
) * 100);
622 isis_circuit_up (struct isis_circuit
*circuit
)
626 /* Set the flags for all the lsps of the circuit. */
627 isis_circuit_update_all_srmflags (circuit
, 1);
629 if (circuit
->state
== C_STATE_UP
)
632 if (circuit
->is_passive
)
635 if (circuit
->area
->lsp_mtu
> isis_circuit_pdu_size(circuit
))
637 zlog_err("Interface MTU %zu on %s is too low to support area lsp mtu %u!",
638 isis_circuit_pdu_size(circuit
), circuit
->interface
->name
,
639 circuit
->area
->lsp_mtu
);
640 isis_circuit_update_all_srmflags(circuit
, 0);
644 if (circuit
->circ_type
== CIRCUIT_T_BROADCAST
)
647 * Get the Hardware Address
649 if (circuit
->interface
->hw_addr_len
!= ETH_ALEN
)
651 zlog_warn ("unsupported link layer");
655 memcpy (circuit
->u
.bc
.snpa
, circuit
->interface
->hw_addr
, ETH_ALEN
);
658 zlog_debug ("isis_circuit_if_add: if_id %d, isomtu %d snpa %s",
659 circuit
->interface
->ifindex
, ISO_MTU (circuit
),
660 snpa_print (circuit
->u
.bc
.snpa
));
661 #endif /* EXTREME_DEBUG */
663 circuit
->u
.bc
.adjdb
[0] = list_new ();
664 circuit
->u
.bc
.adjdb
[1] = list_new ();
667 * ISO 10589 - 8.4.1 Enabling of broadcast circuits
670 /* initilizing the hello sending threads
674 /* 8.4.1 a) commence sending of IIH PDUs */
676 if (circuit
->is_type
& IS_LEVEL_1
)
678 thread_add_event (master
, send_lan_l1_hello
, circuit
, 0);
679 circuit
->u
.bc
.lan_neighs
[0] = list_new ();
682 if (circuit
->is_type
& IS_LEVEL_2
)
684 thread_add_event (master
, send_lan_l2_hello
, circuit
, 0);
685 circuit
->u
.bc
.lan_neighs
[1] = list_new ();
688 /* 8.4.1 b) FIXME: solicit ES - 8.4.6 */
689 /* 8.4.1 c) FIXME: listen for ESH PDUs */
692 /* dr election will commence in... */
693 if (circuit
->is_type
& IS_LEVEL_1
)
694 THREAD_TIMER_ON (master
, circuit
->u
.bc
.t_run_dr
[0], isis_run_dr_l1
,
695 circuit
, 2 * circuit
->hello_interval
[0]);
696 if (circuit
->is_type
& IS_LEVEL_2
)
697 THREAD_TIMER_ON (master
, circuit
->u
.bc
.t_run_dr
[1], isis_run_dr_l2
,
698 circuit
, 2 * circuit
->hello_interval
[1]);
702 /* initializing the hello send threads
705 circuit
->u
.p2p
.neighbor
= NULL
;
706 thread_add_event (master
, send_p2p_hello
, circuit
, 0);
709 /* initializing PSNP timers */
710 if (circuit
->is_type
& IS_LEVEL_1
)
711 THREAD_TIMER_ON (master
, circuit
->t_send_psnp
[0], send_l1_psnp
, circuit
,
712 isis_jitter (circuit
->psnp_interval
[0], PSNP_JITTER
));
714 if (circuit
->is_type
& IS_LEVEL_2
)
715 THREAD_TIMER_ON (master
, circuit
->t_send_psnp
[1], send_l2_psnp
, circuit
,
716 isis_jitter (circuit
->psnp_interval
[1], PSNP_JITTER
));
718 /* unified init for circuits; ignore warnings below this level */
719 retv
= isis_sock_init (circuit
);
722 isis_circuit_down (circuit
);
726 /* initialize the circuit streams after opening connection */
727 isis_circuit_stream(circuit
, &circuit
->rcv_stream
);
728 isis_circuit_stream(circuit
, &circuit
->snd_stream
);
730 isis_circuit_prepare (circuit
);
732 circuit
->lsp_queue
= list_new ();
733 circuit
->lsp_queue_last_cleared
= time (NULL
);
739 isis_circuit_down (struct isis_circuit
*circuit
)
741 if (circuit
->state
!= C_STATE_UP
)
744 /* Clear the flags for all the lsps of the circuit. */
745 isis_circuit_update_all_srmflags (circuit
, 0);
747 if (circuit
->circ_type
== CIRCUIT_T_BROADCAST
)
749 /* destroy neighbour lists */
750 if (circuit
->u
.bc
.lan_neighs
[0])
752 list_delete (circuit
->u
.bc
.lan_neighs
[0]);
753 circuit
->u
.bc
.lan_neighs
[0] = NULL
;
755 if (circuit
->u
.bc
.lan_neighs
[1])
757 list_delete (circuit
->u
.bc
.lan_neighs
[1]);
758 circuit
->u
.bc
.lan_neighs
[1] = NULL
;
760 /* destroy adjacency databases */
761 if (circuit
->u
.bc
.adjdb
[0])
763 circuit
->u
.bc
.adjdb
[0]->del
= isis_delete_adj
;
764 list_delete (circuit
->u
.bc
.adjdb
[0]);
765 circuit
->u
.bc
.adjdb
[0] = NULL
;
767 if (circuit
->u
.bc
.adjdb
[1])
769 circuit
->u
.bc
.adjdb
[1]->del
= isis_delete_adj
;
770 list_delete (circuit
->u
.bc
.adjdb
[1]);
771 circuit
->u
.bc
.adjdb
[1] = NULL
;
773 if (circuit
->u
.bc
.is_dr
[0])
775 isis_dr_resign (circuit
, 1);
776 circuit
->u
.bc
.is_dr
[0] = 0;
778 memset (circuit
->u
.bc
.l1_desig_is
, 0, ISIS_SYS_ID_LEN
+ 1);
779 if (circuit
->u
.bc
.is_dr
[1])
781 isis_dr_resign (circuit
, 2);
782 circuit
->u
.bc
.is_dr
[1] = 0;
784 memset (circuit
->u
.bc
.l2_desig_is
, 0, ISIS_SYS_ID_LEN
+ 1);
785 memset (circuit
->u
.bc
.snpa
, 0, ETH_ALEN
);
787 THREAD_TIMER_OFF (circuit
->u
.bc
.t_send_lan_hello
[0]);
788 THREAD_TIMER_OFF (circuit
->u
.bc
.t_send_lan_hello
[1]);
789 THREAD_TIMER_OFF (circuit
->u
.bc
.t_run_dr
[0]);
790 THREAD_TIMER_OFF (circuit
->u
.bc
.t_run_dr
[1]);
791 THREAD_TIMER_OFF (circuit
->u
.bc
.t_refresh_pseudo_lsp
[0]);
792 THREAD_TIMER_OFF (circuit
->u
.bc
.t_refresh_pseudo_lsp
[1]);
793 circuit
->lsp_regenerate_pending
[0] = 0;
794 circuit
->lsp_regenerate_pending
[1] = 0;
796 else if (circuit
->circ_type
== CIRCUIT_T_P2P
)
798 isis_delete_adj (circuit
->u
.p2p
.neighbor
);
799 circuit
->u
.p2p
.neighbor
= NULL
;
800 THREAD_TIMER_OFF (circuit
->u
.p2p
.t_send_p2p_hello
);
803 /* Cancel all active threads */
804 THREAD_TIMER_OFF (circuit
->t_send_csnp
[0]);
805 THREAD_TIMER_OFF (circuit
->t_send_csnp
[1]);
806 THREAD_TIMER_OFF (circuit
->t_send_psnp
[0]);
807 THREAD_TIMER_OFF (circuit
->t_send_psnp
[1]);
808 THREAD_OFF (circuit
->t_read
);
810 if (circuit
->lsp_queue
)
812 circuit
->lsp_queue
->del
= NULL
;
813 list_delete (circuit
->lsp_queue
);
814 circuit
->lsp_queue
= NULL
;
817 /* send one gratuitous hello to spead up convergence */
818 if (circuit
->is_type
& IS_LEVEL_1
)
819 send_hello (circuit
, IS_LEVEL_1
);
820 if (circuit
->is_type
& IS_LEVEL_2
)
821 send_hello (circuit
, IS_LEVEL_2
);
823 circuit
->upadjcount
[0] = 0;
824 circuit
->upadjcount
[1] = 0;
826 /* close the socket */
833 if (circuit
->rcv_stream
!= NULL
)
835 stream_free (circuit
->rcv_stream
);
836 circuit
->rcv_stream
= NULL
;
839 if (circuit
->snd_stream
!= NULL
)
841 stream_free (circuit
->snd_stream
);
842 circuit
->snd_stream
= NULL
;
845 thread_cancel_event (master
, circuit
);
851 circuit_update_nlpids (struct isis_circuit
*circuit
)
853 circuit
->nlpids
.count
= 0;
855 if (circuit
->ip_router
)
857 circuit
->nlpids
.nlpids
[0] = NLPID_IP
;
858 circuit
->nlpids
.count
++;
861 if (circuit
->ipv6_router
)
863 circuit
->nlpids
.nlpids
[circuit
->nlpids
.count
] = NLPID_IPV6
;
864 circuit
->nlpids
.count
++;
866 #endif /* HAVE_IPV6 */
871 isis_circuit_print_vty (struct isis_circuit
*circuit
, struct vty
*vty
,
874 if (detail
== ISIS_UI_LEVEL_BRIEF
)
876 vty_out (vty
, " %-12s", circuit
->interface
->name
);
877 vty_out (vty
, "0x%-7x", circuit
->circuit_id
);
878 vty_out (vty
, "%-9s", circuit_state2string (circuit
->state
));
879 vty_out (vty
, "%-9s", circuit_type2string (circuit
->circ_type
));
880 vty_out (vty
, "%-9s", circuit_t2string (circuit
->is_type
));
881 vty_out (vty
, "%s", VTY_NEWLINE
);
884 if (detail
== ISIS_UI_LEVEL_DETAIL
)
886 struct listnode
*node
;
887 struct prefix
*ip_addr
;
890 vty_out (vty
, " Interface: %s", circuit
->interface
->name
);
891 vty_out (vty
, ", State: %s", circuit_state2string (circuit
->state
));
892 if (circuit
->is_passive
)
893 vty_out (vty
, ", Passive");
895 vty_out (vty
, ", Active");
896 vty_out (vty
, ", Circuit Id: 0x%x", circuit
->circuit_id
);
897 vty_out (vty
, "%s", VTY_NEWLINE
);
898 vty_out (vty
, " Type: %s", circuit_type2string (circuit
->circ_type
));
899 vty_out (vty
, ", Level: %s", circuit_t2string (circuit
->is_type
));
900 if (circuit
->circ_type
== CIRCUIT_T_BROADCAST
)
901 vty_out (vty
, ", SNPA: %-10s", snpa_print (circuit
->u
.bc
.snpa
));
902 vty_out (vty
, "%s", VTY_NEWLINE
);
903 if (circuit
->is_type
& IS_LEVEL_1
)
905 vty_out (vty
, " Level-1 Information:%s", VTY_NEWLINE
);
906 if (circuit
->area
->newmetric
)
907 vty_out (vty
, " Metric: %d", circuit
->te_metric
[0]);
909 vty_out (vty
, " Metric: %d",
911 if (!circuit
->is_passive
)
913 vty_out (vty
, ", Active neighbors: %u%s",
914 circuit
->upadjcount
[0], VTY_NEWLINE
);
915 vty_out (vty
, " Hello interval: %u, "
916 "Holddown count: %u %s%s",
917 circuit
->hello_interval
[0],
918 circuit
->hello_multiplier
[0],
919 (circuit
->pad_hellos
? "(pad)" : "(no-pad)"),
921 vty_out (vty
, " CNSP interval: %u, "
922 "PSNP interval: %u%s",
923 circuit
->csnp_interval
[0],
924 circuit
->psnp_interval
[0], VTY_NEWLINE
);
925 if (circuit
->circ_type
== CIRCUIT_T_BROADCAST
)
926 vty_out (vty
, " LAN Priority: %u, %s%s",
927 circuit
->priority
[0],
928 (circuit
->u
.bc
.is_dr
[0] ? \
929 "is DIS" : "is not DIS"), VTY_NEWLINE
);
933 vty_out (vty
, "%s", VTY_NEWLINE
);
936 if (circuit
->is_type
& IS_LEVEL_2
)
938 vty_out (vty
, " Level-2 Information:%s", VTY_NEWLINE
);
939 if (circuit
->area
->newmetric
)
940 vty_out (vty
, " Metric: %d", circuit
->te_metric
[1]);
942 vty_out (vty
, " Metric: %d",
944 if (!circuit
->is_passive
)
946 vty_out (vty
, ", Active neighbors: %u%s",
947 circuit
->upadjcount
[1], VTY_NEWLINE
);
948 vty_out (vty
, " Hello interval: %u, "
949 "Holddown count: %u %s%s",
950 circuit
->hello_interval
[1],
951 circuit
->hello_multiplier
[1],
952 (circuit
->pad_hellos
? "(pad)" : "(no-pad)"),
954 vty_out (vty
, " CNSP interval: %u, "
955 "PSNP interval: %u%s",
956 circuit
->csnp_interval
[1],
957 circuit
->psnp_interval
[1], VTY_NEWLINE
);
958 if (circuit
->circ_type
== CIRCUIT_T_BROADCAST
)
959 vty_out (vty
, " LAN Priority: %u, %s%s",
960 circuit
->priority
[1],
961 (circuit
->u
.bc
.is_dr
[1] ? \
962 "is DIS" : "is not DIS"), VTY_NEWLINE
);
966 vty_out (vty
, "%s", VTY_NEWLINE
);
969 if (circuit
->ip_addrs
&& listcount (circuit
->ip_addrs
) > 0)
971 vty_out (vty
, " IP Prefix(es):%s", VTY_NEWLINE
);
972 for (ALL_LIST_ELEMENTS_RO (circuit
->ip_addrs
, node
, ip_addr
))
974 prefix2str (ip_addr
, buf
, sizeof (buf
)),
975 vty_out (vty
, " %s%s", buf
, VTY_NEWLINE
);
978 if (circuit
->ipv6_link
&& listcount(circuit
->ipv6_link
) > 0)
980 vty_out(vty
, " IPv6 Link-Locals:%s", VTY_NEWLINE
);
981 for (ALL_LIST_ELEMENTS_RO(circuit
->ipv6_link
, node
, ip_addr
))
983 prefix2str(ip_addr
, (char*)buf
, BUFSIZ
),
984 vty_out(vty
, " %s%s", buf
, VTY_NEWLINE
);
987 if (circuit
->ipv6_non_link
&& listcount(circuit
->ipv6_non_link
) > 0)
989 vty_out(vty
, " IPv6 Prefixes:%s", VTY_NEWLINE
);
990 for (ALL_LIST_ELEMENTS_RO(circuit
->ipv6_non_link
, node
, ip_addr
))
992 prefix2str(ip_addr
, (char*)buf
, BUFSIZ
),
993 vty_out(vty
, " %s%s", buf
, VTY_NEWLINE
);
997 vty_out (vty
, "%s", VTY_NEWLINE
);
1003 isis_interface_config_write (struct vty
*vty
)
1006 struct listnode
*node
, *node2
;
1007 struct interface
*ifp
;
1008 struct isis_area
*area
;
1009 struct isis_circuit
*circuit
;
1012 for (ALL_LIST_ELEMENTS_RO (vrf_iflist (VRF_DEFAULT
), node
, ifp
))
1014 if (ifp
->ifindex
== IFINDEX_DELETED
)
1018 vty_out (vty
, "interface %s%s", ifp
->name
, VTY_NEWLINE
);
1023 vty_out (vty
, " description %s%s", ifp
->desc
, VTY_NEWLINE
);
1027 for (ALL_LIST_ELEMENTS_RO (isis
->area_list
, node2
, area
))
1029 circuit
= circuit_lookup_by_ifp (ifp
, area
->circuit_list
);
1030 if (circuit
== NULL
)
1032 if (circuit
->ip_router
)
1034 vty_out (vty
, " ip router isis %s%s", area
->area_tag
,
1038 if (circuit
->is_passive
)
1040 vty_out (vty
, " isis passive%s", VTY_NEWLINE
);
1043 if (circuit
->circ_type_config
== CIRCUIT_T_P2P
)
1045 vty_out (vty
, " isis network point-to-point%s", VTY_NEWLINE
);
1049 if (circuit
->ipv6_router
)
1051 vty_out (vty
, " ipv6 router isis %s%s", area
->area_tag
,
1055 #endif /* HAVE_IPV6 */
1057 /* ISIS - circuit type */
1058 if (circuit
->is_type
== IS_LEVEL_1
)
1060 vty_out (vty
, " isis circuit-type level-1%s", VTY_NEWLINE
);
1065 if (circuit
->is_type
== IS_LEVEL_2
)
1067 vty_out (vty
, " isis circuit-type level-2-only%s",
1073 /* ISIS - CSNP interval */
1074 if (circuit
->csnp_interval
[0] == circuit
->csnp_interval
[1])
1076 if (circuit
->csnp_interval
[0] != DEFAULT_CSNP_INTERVAL
)
1078 vty_out (vty
, " isis csnp-interval %d%s",
1079 circuit
->csnp_interval
[0], VTY_NEWLINE
);
1085 for (i
= 0; i
< 2; i
++)
1087 if (circuit
->csnp_interval
[i
] != DEFAULT_CSNP_INTERVAL
)
1089 vty_out (vty
, " isis csnp-interval %d level-%d%s",
1090 circuit
->csnp_interval
[i
], i
+ 1, VTY_NEWLINE
);
1096 /* ISIS - PSNP interval */
1097 if (circuit
->psnp_interval
[0] == circuit
->psnp_interval
[1])
1099 if (circuit
->psnp_interval
[0] != DEFAULT_PSNP_INTERVAL
)
1101 vty_out (vty
, " isis psnp-interval %d%s",
1102 circuit
->psnp_interval
[0], VTY_NEWLINE
);
1108 for (i
= 0; i
< 2; i
++)
1110 if (circuit
->psnp_interval
[i
] != DEFAULT_PSNP_INTERVAL
)
1112 vty_out (vty
, " isis psnp-interval %d level-%d%s",
1113 circuit
->psnp_interval
[i
], i
+ 1, VTY_NEWLINE
);
1119 /* ISIS - Hello padding - Defaults to true so only display if false */
1120 if (circuit
->pad_hellos
== 0)
1122 vty_out (vty
, " no isis hello padding%s", VTY_NEWLINE
);
1126 /* ISIS - Hello interval */
1127 if (circuit
->hello_interval
[0] == circuit
->hello_interval
[1])
1129 if (circuit
->hello_interval
[0] != DEFAULT_HELLO_INTERVAL
)
1131 vty_out (vty
, " isis hello-interval %d%s",
1132 circuit
->hello_interval
[0], VTY_NEWLINE
);
1138 for (i
= 0; i
< 2; i
++)
1140 if (circuit
->hello_interval
[i
] != DEFAULT_HELLO_INTERVAL
)
1142 vty_out (vty
, " isis hello-interval %d level-%d%s",
1143 circuit
->hello_interval
[i
], i
+ 1, VTY_NEWLINE
);
1149 /* ISIS - Hello Multiplier */
1150 if (circuit
->hello_multiplier
[0] == circuit
->hello_multiplier
[1])
1152 if (circuit
->hello_multiplier
[0] != DEFAULT_HELLO_MULTIPLIER
)
1154 vty_out (vty
, " isis hello-multiplier %d%s",
1155 circuit
->hello_multiplier
[0], VTY_NEWLINE
);
1161 for (i
= 0; i
< 2; i
++)
1163 if (circuit
->hello_multiplier
[i
] != DEFAULT_HELLO_MULTIPLIER
)
1165 vty_out (vty
, " isis hello-multiplier %d level-%d%s",
1166 circuit
->hello_multiplier
[i
], i
+ 1,
1173 /* ISIS - Priority */
1174 if (circuit
->priority
[0] == circuit
->priority
[1])
1176 if (circuit
->priority
[0] != DEFAULT_PRIORITY
)
1178 vty_out (vty
, " isis priority %d%s",
1179 circuit
->priority
[0], VTY_NEWLINE
);
1185 for (i
= 0; i
< 2; i
++)
1187 if (circuit
->priority
[i
] != DEFAULT_PRIORITY
)
1189 vty_out (vty
, " isis priority %d level-%d%s",
1190 circuit
->priority
[i
], i
+ 1, VTY_NEWLINE
);
1197 if (circuit
->te_metric
[0] == circuit
->te_metric
[1])
1199 if (circuit
->te_metric
[0] != DEFAULT_CIRCUIT_METRIC
)
1201 vty_out (vty
, " isis metric %d%s", circuit
->te_metric
[0],
1208 for (i
= 0; i
< 2; i
++)
1210 if (circuit
->te_metric
[i
] != DEFAULT_CIRCUIT_METRIC
)
1212 vty_out (vty
, " isis metric %d level-%d%s",
1213 circuit
->te_metric
[i
], i
+ 1, VTY_NEWLINE
);
1218 if (circuit
->passwd
.type
== ISIS_PASSWD_TYPE_HMAC_MD5
)
1220 vty_out (vty
, " isis password md5 %s%s", circuit
->passwd
.passwd
,
1224 else if (circuit
->passwd
.type
== ISIS_PASSWD_TYPE_CLEARTXT
)
1226 vty_out (vty
, " isis password clear %s%s", circuit
->passwd
.passwd
,
1231 vty_out (vty
, "!%s", VTY_NEWLINE
);
1237 struct isis_circuit
*
1238 isis_circuit_create (struct isis_area
*area
, struct interface
*ifp
)
1240 struct isis_circuit
*circuit
= circuit_scan_by_ifp (ifp
);
1241 if (circuit
&& circuit
->area
)
1243 circuit
= isis_csm_state_change (ISIS_ENABLE
, circuit
, area
);
1244 if (circuit
->state
!= C_STATE_CONF
&& circuit
->state
!= C_STATE_UP
)
1246 isis_circuit_if_bind (circuit
, ifp
);
1251 isis_circuit_af_set (struct isis_circuit
*circuit
, bool ip_router
, bool ipv6_router
)
1253 struct isis_area
*area
= circuit
->area
;
1254 bool change
= circuit
->ip_router
!= ip_router
|| circuit
->ipv6_router
!= ipv6_router
;
1255 bool was_enabled
= !!circuit
->area
;
1257 area
->ip_circuits
+= ip_router
- circuit
->ip_router
;
1258 area
->ipv6_circuits
+= ipv6_router
- circuit
->ipv6_router
;
1259 circuit
->ip_router
= ip_router
;
1260 circuit
->ipv6_router
= ipv6_router
;
1265 circuit_update_nlpids (circuit
);
1267 if (!ip_router
&& !ipv6_router
)
1268 isis_csm_state_change (ISIS_DISABLE
, circuit
, area
);
1269 else if (!was_enabled
)
1270 isis_csm_state_change (ISIS_ENABLE
, circuit
, area
);
1272 lsp_regenerate_schedule(circuit
->area
, circuit
->is_type
, 0);
1276 isis_circuit_passive_set (struct isis_circuit
*circuit
, bool passive
)
1278 if (circuit
->is_passive
== passive
)
1281 if (if_is_loopback (circuit
->interface
) && !passive
)
1284 if (circuit
->state
!= C_STATE_UP
)
1286 circuit
->is_passive
= passive
;
1290 struct isis_area
*area
= circuit
->area
;
1291 isis_csm_state_change (ISIS_DISABLE
, circuit
, area
);
1292 circuit
->is_passive
= passive
;
1293 isis_csm_state_change (ISIS_ENABLE
, circuit
, area
);
1300 isis_circuit_metric_set (struct isis_circuit
*circuit
, int level
, int metric
)
1302 assert (level
== IS_LEVEL_1
|| level
== IS_LEVEL_2
);
1303 if (metric
> MAX_WIDE_LINK_METRIC
)
1305 if (circuit
->area
&& circuit
->area
->oldmetric
1306 && metric
> MAX_NARROW_LINK_METRIC
)
1309 circuit
->te_metric
[level
- 1] = metric
;
1310 circuit
->metric
[level
- 1] = metric
;
1313 lsp_regenerate_schedule (circuit
->area
, level
, 0);
1318 isis_circuit_passwd_unset (struct isis_circuit
*circuit
)
1320 memset(&circuit
->passwd
, 0, sizeof(circuit
->passwd
));
1325 isis_circuit_passwd_set (struct isis_circuit
*circuit
, u_char passwd_type
, const char *passwd
)
1332 len
= strlen(passwd
);
1336 circuit
->passwd
.len
= len
;
1337 strncpy((char *)circuit
->passwd
.passwd
, passwd
, 255);
1338 circuit
->passwd
.type
= passwd_type
;
1343 isis_circuit_passwd_cleartext_set (struct isis_circuit
*circuit
, const char *passwd
)
1345 return isis_circuit_passwd_set (circuit
, ISIS_PASSWD_TYPE_CLEARTXT
, passwd
);
1349 isis_circuit_passwd_hmac_md5_set (struct isis_circuit
*circuit
, const char *passwd
)
1351 return isis_circuit_passwd_set (circuit
, ISIS_PASSWD_TYPE_HMAC_MD5
, passwd
);
1353 struct cmd_node interface_node
= {
1360 isis_circuit_circ_type_set(struct isis_circuit
*circuit
, int circ_type
)
1362 /* Changing the network type to/of loopback or unknown interfaces
1363 * is not supported. */
1364 if (circ_type
== CIRCUIT_T_UNKNOWN
1365 || circ_type
== CIRCUIT_T_LOOPBACK
1366 || circuit
->circ_type
== CIRCUIT_T_LOOPBACK
)
1368 if (circuit
->circ_type
!= circ_type
)
1374 if (circuit
->circ_type
== circ_type
)
1377 if (circuit
->state
!= C_STATE_UP
)
1379 circuit
->circ_type
= circ_type
;
1380 circuit
->circ_type_config
= circ_type
;
1384 struct isis_area
*area
= circuit
->area
;
1385 if (circ_type
== CIRCUIT_T_BROADCAST
1386 && !if_is_broadcast(circuit
->interface
))
1389 isis_csm_state_change(ISIS_DISABLE
, circuit
, area
);
1390 circuit
->circ_type
= circ_type
;
1391 circuit
->circ_type_config
= circ_type
;
1392 isis_csm_state_change(ISIS_ENABLE
, circuit
, area
);
1398 isis_if_new_hook (struct interface
*ifp
)
1404 isis_if_delete_hook (struct interface
*ifp
)
1406 struct isis_circuit
*circuit
;
1407 /* Clean up the circuit data */
1408 if (ifp
&& ifp
->info
)
1410 circuit
= ifp
->info
;
1411 isis_csm_state_change (IF_DOWN_FROM_Z
, circuit
, circuit
->area
);
1412 isis_csm_state_change (ISIS_DISABLE
, circuit
, circuit
->area
);
1419 isis_circuit_init ()
1421 /* Initialize Zebra interface data structure */
1422 if_add_hook (IF_NEW_HOOK
, isis_if_new_hook
);
1423 if_add_hook (IF_DELETE_HOOK
, isis_if_delete_hook
);
1425 /* Install interface node */
1426 install_node (&interface_node
, isis_interface_config_write
);