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_up (struct isis_circuit
*circuit
)
614 /* Set the flags for all the lsps of the circuit. */
615 isis_circuit_update_all_srmflags (circuit
, 1);
617 if (circuit
->state
== C_STATE_UP
)
620 if (circuit
->is_passive
)
623 if (circuit
->area
->lsp_mtu
> isis_circuit_pdu_size(circuit
))
625 zlog_err("Interface MTU %zu on %s is too low to support area lsp mtu %u!",
626 isis_circuit_pdu_size(circuit
), circuit
->interface
->name
,
627 circuit
->area
->lsp_mtu
);
628 isis_circuit_update_all_srmflags(circuit
, 0);
632 if (circuit
->circ_type
== CIRCUIT_T_BROADCAST
)
635 * Get the Hardware Address
637 if (circuit
->interface
->hw_addr_len
!= ETH_ALEN
)
639 zlog_warn ("unsupported link layer");
643 memcpy (circuit
->u
.bc
.snpa
, circuit
->interface
->hw_addr
, ETH_ALEN
);
646 zlog_debug ("isis_circuit_if_add: if_id %d, isomtu %d snpa %s",
647 circuit
->interface
->ifindex
, ISO_MTU (circuit
),
648 snpa_print (circuit
->u
.bc
.snpa
));
649 #endif /* EXTREME_DEBUG */
651 circuit
->u
.bc
.adjdb
[0] = list_new ();
652 circuit
->u
.bc
.adjdb
[1] = list_new ();
655 * ISO 10589 - 8.4.1 Enabling of broadcast circuits
658 /* initilizing the hello sending threads
662 /* 8.4.1 a) commence sending of IIH PDUs */
664 if (circuit
->is_type
& IS_LEVEL_1
)
666 thread_add_event (master
, send_lan_l1_hello
, circuit
, 0);
667 circuit
->u
.bc
.lan_neighs
[0] = list_new ();
670 if (circuit
->is_type
& IS_LEVEL_2
)
672 thread_add_event (master
, send_lan_l2_hello
, circuit
, 0);
673 circuit
->u
.bc
.lan_neighs
[1] = list_new ();
676 /* 8.4.1 b) FIXME: solicit ES - 8.4.6 */
677 /* 8.4.1 c) FIXME: listen for ESH PDUs */
680 /* dr election will commence in... */
681 if (circuit
->is_type
& IS_LEVEL_1
)
682 THREAD_TIMER_ON (master
, circuit
->u
.bc
.t_run_dr
[0], isis_run_dr_l1
,
683 circuit
, 2 * circuit
->hello_interval
[0]);
684 if (circuit
->is_type
& IS_LEVEL_2
)
685 THREAD_TIMER_ON (master
, circuit
->u
.bc
.t_run_dr
[1], isis_run_dr_l2
,
686 circuit
, 2 * circuit
->hello_interval
[1]);
690 /* initializing the hello send threads
693 circuit
->u
.p2p
.neighbor
= NULL
;
694 thread_add_event (master
, send_p2p_hello
, circuit
, 0);
697 /* initializing PSNP timers */
698 if (circuit
->is_type
& IS_LEVEL_1
)
699 THREAD_TIMER_ON (master
, circuit
->t_send_psnp
[0], send_l1_psnp
, circuit
,
700 isis_jitter (circuit
->psnp_interval
[0], PSNP_JITTER
));
702 if (circuit
->is_type
& IS_LEVEL_2
)
703 THREAD_TIMER_ON (master
, circuit
->t_send_psnp
[1], send_l2_psnp
, circuit
,
704 isis_jitter (circuit
->psnp_interval
[1], PSNP_JITTER
));
706 /* unified init for circuits; ignore warnings below this level */
707 retv
= isis_sock_init (circuit
);
710 isis_circuit_down (circuit
);
714 /* initialize the circuit streams after opening connection */
715 isis_circuit_stream(circuit
, &circuit
->rcv_stream
);
716 isis_circuit_stream(circuit
, &circuit
->snd_stream
);
719 THREAD_READ_ON (master
, circuit
->t_read
, isis_receive
, circuit
,
722 THREAD_TIMER_MSEC_ON (master
, circuit
->t_read
, isis_receive
, circuit
,
723 listcount (circuit
->area
->circuit_list
) * 100);
726 circuit
->lsp_queue
= list_new ();
727 circuit
->lsp_queue_last_cleared
= time (NULL
);
733 isis_circuit_down (struct isis_circuit
*circuit
)
735 if (circuit
->state
!= C_STATE_UP
)
738 /* Clear the flags for all the lsps of the circuit. */
739 isis_circuit_update_all_srmflags (circuit
, 0);
741 if (circuit
->circ_type
== CIRCUIT_T_BROADCAST
)
743 /* destroy neighbour lists */
744 if (circuit
->u
.bc
.lan_neighs
[0])
746 list_delete (circuit
->u
.bc
.lan_neighs
[0]);
747 circuit
->u
.bc
.lan_neighs
[0] = NULL
;
749 if (circuit
->u
.bc
.lan_neighs
[1])
751 list_delete (circuit
->u
.bc
.lan_neighs
[1]);
752 circuit
->u
.bc
.lan_neighs
[1] = NULL
;
754 /* destroy adjacency databases */
755 if (circuit
->u
.bc
.adjdb
[0])
757 circuit
->u
.bc
.adjdb
[0]->del
= isis_delete_adj
;
758 list_delete (circuit
->u
.bc
.adjdb
[0]);
759 circuit
->u
.bc
.adjdb
[0] = NULL
;
761 if (circuit
->u
.bc
.adjdb
[1])
763 circuit
->u
.bc
.adjdb
[1]->del
= isis_delete_adj
;
764 list_delete (circuit
->u
.bc
.adjdb
[1]);
765 circuit
->u
.bc
.adjdb
[1] = NULL
;
767 if (circuit
->u
.bc
.is_dr
[0])
769 isis_dr_resign (circuit
, 1);
770 circuit
->u
.bc
.is_dr
[0] = 0;
772 memset (circuit
->u
.bc
.l1_desig_is
, 0, ISIS_SYS_ID_LEN
+ 1);
773 if (circuit
->u
.bc
.is_dr
[1])
775 isis_dr_resign (circuit
, 2);
776 circuit
->u
.bc
.is_dr
[1] = 0;
778 memset (circuit
->u
.bc
.l2_desig_is
, 0, ISIS_SYS_ID_LEN
+ 1);
779 memset (circuit
->u
.bc
.snpa
, 0, ETH_ALEN
);
781 THREAD_TIMER_OFF (circuit
->u
.bc
.t_send_lan_hello
[0]);
782 THREAD_TIMER_OFF (circuit
->u
.bc
.t_send_lan_hello
[1]);
783 THREAD_TIMER_OFF (circuit
->u
.bc
.t_run_dr
[0]);
784 THREAD_TIMER_OFF (circuit
->u
.bc
.t_run_dr
[1]);
785 THREAD_TIMER_OFF (circuit
->u
.bc
.t_refresh_pseudo_lsp
[0]);
786 THREAD_TIMER_OFF (circuit
->u
.bc
.t_refresh_pseudo_lsp
[1]);
787 circuit
->lsp_regenerate_pending
[0] = 0;
788 circuit
->lsp_regenerate_pending
[1] = 0;
790 else if (circuit
->circ_type
== CIRCUIT_T_P2P
)
792 isis_delete_adj (circuit
->u
.p2p
.neighbor
);
793 circuit
->u
.p2p
.neighbor
= NULL
;
794 THREAD_TIMER_OFF (circuit
->u
.p2p
.t_send_p2p_hello
);
797 /* Cancel all active threads */
798 THREAD_TIMER_OFF (circuit
->t_send_csnp
[0]);
799 THREAD_TIMER_OFF (circuit
->t_send_csnp
[1]);
800 THREAD_TIMER_OFF (circuit
->t_send_psnp
[0]);
801 THREAD_TIMER_OFF (circuit
->t_send_psnp
[1]);
802 THREAD_OFF (circuit
->t_read
);
804 if (circuit
->lsp_queue
)
806 circuit
->lsp_queue
->del
= NULL
;
807 list_delete (circuit
->lsp_queue
);
808 circuit
->lsp_queue
= NULL
;
811 /* send one gratuitous hello to spead up convergence */
812 if (circuit
->is_type
& IS_LEVEL_1
)
813 send_hello (circuit
, IS_LEVEL_1
);
814 if (circuit
->is_type
& IS_LEVEL_2
)
815 send_hello (circuit
, IS_LEVEL_2
);
817 circuit
->upadjcount
[0] = 0;
818 circuit
->upadjcount
[1] = 0;
820 /* close the socket */
827 if (circuit
->rcv_stream
!= NULL
)
829 stream_free (circuit
->rcv_stream
);
830 circuit
->rcv_stream
= NULL
;
833 if (circuit
->snd_stream
!= NULL
)
835 stream_free (circuit
->snd_stream
);
836 circuit
->snd_stream
= NULL
;
839 thread_cancel_event (master
, circuit
);
845 circuit_update_nlpids (struct isis_circuit
*circuit
)
847 circuit
->nlpids
.count
= 0;
849 if (circuit
->ip_router
)
851 circuit
->nlpids
.nlpids
[0] = NLPID_IP
;
852 circuit
->nlpids
.count
++;
855 if (circuit
->ipv6_router
)
857 circuit
->nlpids
.nlpids
[circuit
->nlpids
.count
] = NLPID_IPV6
;
858 circuit
->nlpids
.count
++;
860 #endif /* HAVE_IPV6 */
865 isis_circuit_print_vty (struct isis_circuit
*circuit
, struct vty
*vty
,
868 if (detail
== ISIS_UI_LEVEL_BRIEF
)
870 vty_out (vty
, " %-12s", circuit
->interface
->name
);
871 vty_out (vty
, "0x%-7x", circuit
->circuit_id
);
872 vty_out (vty
, "%-9s", circuit_state2string (circuit
->state
));
873 vty_out (vty
, "%-9s", circuit_type2string (circuit
->circ_type
));
874 vty_out (vty
, "%-9s", circuit_t2string (circuit
->is_type
));
875 vty_out (vty
, "%s", VTY_NEWLINE
);
878 if (detail
== ISIS_UI_LEVEL_DETAIL
)
880 struct listnode
*node
;
881 struct prefix
*ip_addr
;
884 vty_out (vty
, " Interface: %s", circuit
->interface
->name
);
885 vty_out (vty
, ", State: %s", circuit_state2string (circuit
->state
));
886 if (circuit
->is_passive
)
887 vty_out (vty
, ", Passive");
889 vty_out (vty
, ", Active");
890 vty_out (vty
, ", Circuit Id: 0x%x", circuit
->circuit_id
);
891 vty_out (vty
, "%s", VTY_NEWLINE
);
892 vty_out (vty
, " Type: %s", circuit_type2string (circuit
->circ_type
));
893 vty_out (vty
, ", Level: %s", circuit_t2string (circuit
->is_type
));
894 if (circuit
->circ_type
== CIRCUIT_T_BROADCAST
)
895 vty_out (vty
, ", SNPA: %-10s", snpa_print (circuit
->u
.bc
.snpa
));
896 vty_out (vty
, "%s", VTY_NEWLINE
);
897 if (circuit
->is_type
& IS_LEVEL_1
)
899 vty_out (vty
, " Level-1 Information:%s", VTY_NEWLINE
);
900 if (circuit
->area
->newmetric
)
901 vty_out (vty
, " Metric: %d", circuit
->te_metric
[0]);
903 vty_out (vty
, " Metric: %d",
905 if (!circuit
->is_passive
)
907 vty_out (vty
, ", Active neighbors: %u%s",
908 circuit
->upadjcount
[0], VTY_NEWLINE
);
909 vty_out (vty
, " Hello interval: %u, "
910 "Holddown count: %u %s%s",
911 circuit
->hello_interval
[0],
912 circuit
->hello_multiplier
[0],
913 (circuit
->pad_hellos
? "(pad)" : "(no-pad)"),
915 vty_out (vty
, " CNSP interval: %u, "
916 "PSNP interval: %u%s",
917 circuit
->csnp_interval
[0],
918 circuit
->psnp_interval
[0], VTY_NEWLINE
);
919 if (circuit
->circ_type
== CIRCUIT_T_BROADCAST
)
920 vty_out (vty
, " LAN Priority: %u, %s%s",
921 circuit
->priority
[0],
922 (circuit
->u
.bc
.is_dr
[0] ? \
923 "is DIS" : "is not DIS"), VTY_NEWLINE
);
927 vty_out (vty
, "%s", VTY_NEWLINE
);
930 if (circuit
->is_type
& IS_LEVEL_2
)
932 vty_out (vty
, " Level-2 Information:%s", VTY_NEWLINE
);
933 if (circuit
->area
->newmetric
)
934 vty_out (vty
, " Metric: %d", circuit
->te_metric
[1]);
936 vty_out (vty
, " Metric: %d",
938 if (!circuit
->is_passive
)
940 vty_out (vty
, ", Active neighbors: %u%s",
941 circuit
->upadjcount
[1], VTY_NEWLINE
);
942 vty_out (vty
, " Hello interval: %u, "
943 "Holddown count: %u %s%s",
944 circuit
->hello_interval
[1],
945 circuit
->hello_multiplier
[1],
946 (circuit
->pad_hellos
? "(pad)" : "(no-pad)"),
948 vty_out (vty
, " CNSP interval: %u, "
949 "PSNP interval: %u%s",
950 circuit
->csnp_interval
[1],
951 circuit
->psnp_interval
[1], VTY_NEWLINE
);
952 if (circuit
->circ_type
== CIRCUIT_T_BROADCAST
)
953 vty_out (vty
, " LAN Priority: %u, %s%s",
954 circuit
->priority
[1],
955 (circuit
->u
.bc
.is_dr
[1] ? \
956 "is DIS" : "is not DIS"), VTY_NEWLINE
);
960 vty_out (vty
, "%s", VTY_NEWLINE
);
963 if (circuit
->ip_addrs
&& listcount (circuit
->ip_addrs
) > 0)
965 vty_out (vty
, " IP Prefix(es):%s", VTY_NEWLINE
);
966 for (ALL_LIST_ELEMENTS_RO (circuit
->ip_addrs
, node
, ip_addr
))
968 prefix2str (ip_addr
, buf
, sizeof (buf
)),
969 vty_out (vty
, " %s%s", buf
, VTY_NEWLINE
);
972 if (circuit
->ipv6_link
&& listcount(circuit
->ipv6_link
) > 0)
974 vty_out(vty
, " IPv6 Link-Locals:%s", VTY_NEWLINE
);
975 for (ALL_LIST_ELEMENTS_RO(circuit
->ipv6_link
, node
, ip_addr
))
977 prefix2str(ip_addr
, (char*)buf
, BUFSIZ
),
978 vty_out(vty
, " %s%s", buf
, VTY_NEWLINE
);
981 if (circuit
->ipv6_non_link
&& listcount(circuit
->ipv6_non_link
) > 0)
983 vty_out(vty
, " IPv6 Prefixes:%s", VTY_NEWLINE
);
984 for (ALL_LIST_ELEMENTS_RO(circuit
->ipv6_non_link
, node
, ip_addr
))
986 prefix2str(ip_addr
, (char*)buf
, BUFSIZ
),
987 vty_out(vty
, " %s%s", buf
, VTY_NEWLINE
);
991 vty_out (vty
, "%s", VTY_NEWLINE
);
997 isis_interface_config_write (struct vty
*vty
)
1000 struct listnode
*node
, *node2
;
1001 struct interface
*ifp
;
1002 struct isis_area
*area
;
1003 struct isis_circuit
*circuit
;
1006 for (ALL_LIST_ELEMENTS_RO (vrf_iflist (VRF_DEFAULT
), node
, ifp
))
1008 if (ifp
->ifindex
== IFINDEX_DELETED
)
1012 vty_out (vty
, "interface %s%s", ifp
->name
, VTY_NEWLINE
);
1017 vty_out (vty
, " description %s%s", ifp
->desc
, VTY_NEWLINE
);
1021 for (ALL_LIST_ELEMENTS_RO (isis
->area_list
, node2
, area
))
1023 circuit
= circuit_lookup_by_ifp (ifp
, area
->circuit_list
);
1024 if (circuit
== NULL
)
1026 if (circuit
->ip_router
)
1028 vty_out (vty
, " ip router isis %s%s", area
->area_tag
,
1032 if (circuit
->is_passive
)
1034 vty_out (vty
, " isis passive%s", VTY_NEWLINE
);
1037 if (circuit
->circ_type_config
== CIRCUIT_T_P2P
)
1039 vty_out (vty
, " isis network point-to-point%s", VTY_NEWLINE
);
1043 if (circuit
->ipv6_router
)
1045 vty_out (vty
, " ipv6 router isis %s%s", area
->area_tag
,
1049 #endif /* HAVE_IPV6 */
1051 /* ISIS - circuit type */
1052 if (circuit
->is_type
== IS_LEVEL_1
)
1054 vty_out (vty
, " isis circuit-type level-1%s", VTY_NEWLINE
);
1059 if (circuit
->is_type
== IS_LEVEL_2
)
1061 vty_out (vty
, " isis circuit-type level-2-only%s",
1067 /* ISIS - CSNP interval */
1068 if (circuit
->csnp_interval
[0] == circuit
->csnp_interval
[1])
1070 if (circuit
->csnp_interval
[0] != DEFAULT_CSNP_INTERVAL
)
1072 vty_out (vty
, " isis csnp-interval %d%s",
1073 circuit
->csnp_interval
[0], VTY_NEWLINE
);
1079 for (i
= 0; i
< 2; i
++)
1081 if (circuit
->csnp_interval
[i
] != DEFAULT_CSNP_INTERVAL
)
1083 vty_out (vty
, " isis csnp-interval %d level-%d%s",
1084 circuit
->csnp_interval
[i
], i
+ 1, VTY_NEWLINE
);
1090 /* ISIS - PSNP interval */
1091 if (circuit
->psnp_interval
[0] == circuit
->psnp_interval
[1])
1093 if (circuit
->psnp_interval
[0] != DEFAULT_PSNP_INTERVAL
)
1095 vty_out (vty
, " isis psnp-interval %d%s",
1096 circuit
->psnp_interval
[0], VTY_NEWLINE
);
1102 for (i
= 0; i
< 2; i
++)
1104 if (circuit
->psnp_interval
[i
] != DEFAULT_PSNP_INTERVAL
)
1106 vty_out (vty
, " isis psnp-interval %d level-%d%s",
1107 circuit
->psnp_interval
[i
], i
+ 1, VTY_NEWLINE
);
1113 /* ISIS - Hello padding - Defaults to true so only display if false */
1114 if (circuit
->pad_hellos
== 0)
1116 vty_out (vty
, " no isis hello padding%s", VTY_NEWLINE
);
1120 /* ISIS - Hello interval */
1121 if (circuit
->hello_interval
[0] == circuit
->hello_interval
[1])
1123 if (circuit
->hello_interval
[0] != DEFAULT_HELLO_INTERVAL
)
1125 vty_out (vty
, " isis hello-interval %d%s",
1126 circuit
->hello_interval
[0], VTY_NEWLINE
);
1132 for (i
= 0; i
< 2; i
++)
1134 if (circuit
->hello_interval
[i
] != DEFAULT_HELLO_INTERVAL
)
1136 vty_out (vty
, " isis hello-interval %d level-%d%s",
1137 circuit
->hello_interval
[i
], i
+ 1, VTY_NEWLINE
);
1143 /* ISIS - Hello Multiplier */
1144 if (circuit
->hello_multiplier
[0] == circuit
->hello_multiplier
[1])
1146 if (circuit
->hello_multiplier
[0] != DEFAULT_HELLO_MULTIPLIER
)
1148 vty_out (vty
, " isis hello-multiplier %d%s",
1149 circuit
->hello_multiplier
[0], VTY_NEWLINE
);
1155 for (i
= 0; i
< 2; i
++)
1157 if (circuit
->hello_multiplier
[i
] != DEFAULT_HELLO_MULTIPLIER
)
1159 vty_out (vty
, " isis hello-multiplier %d level-%d%s",
1160 circuit
->hello_multiplier
[i
], i
+ 1,
1167 /* ISIS - Priority */
1168 if (circuit
->priority
[0] == circuit
->priority
[1])
1170 if (circuit
->priority
[0] != DEFAULT_PRIORITY
)
1172 vty_out (vty
, " isis priority %d%s",
1173 circuit
->priority
[0], VTY_NEWLINE
);
1179 for (i
= 0; i
< 2; i
++)
1181 if (circuit
->priority
[i
] != DEFAULT_PRIORITY
)
1183 vty_out (vty
, " isis priority %d level-%d%s",
1184 circuit
->priority
[i
], i
+ 1, VTY_NEWLINE
);
1191 if (circuit
->te_metric
[0] == circuit
->te_metric
[1])
1193 if (circuit
->te_metric
[0] != DEFAULT_CIRCUIT_METRIC
)
1195 vty_out (vty
, " isis metric %d%s", circuit
->te_metric
[0],
1202 for (i
= 0; i
< 2; i
++)
1204 if (circuit
->te_metric
[i
] != DEFAULT_CIRCUIT_METRIC
)
1206 vty_out (vty
, " isis metric %d level-%d%s",
1207 circuit
->te_metric
[i
], i
+ 1, VTY_NEWLINE
);
1212 if (circuit
->passwd
.type
== ISIS_PASSWD_TYPE_HMAC_MD5
)
1214 vty_out (vty
, " isis password md5 %s%s", circuit
->passwd
.passwd
,
1218 else if (circuit
->passwd
.type
== ISIS_PASSWD_TYPE_CLEARTXT
)
1220 vty_out (vty
, " isis password clear %s%s", circuit
->passwd
.passwd
,
1225 vty_out (vty
, "!%s", VTY_NEWLINE
);
1231 struct isis_circuit
*
1232 isis_circuit_create (struct isis_area
*area
, struct interface
*ifp
)
1234 struct isis_circuit
*circuit
= circuit_scan_by_ifp (ifp
);
1235 if (circuit
&& circuit
->area
)
1237 circuit
= isis_csm_state_change (ISIS_ENABLE
, circuit
, area
);
1238 if (circuit
->state
!= C_STATE_CONF
&& circuit
->state
!= C_STATE_UP
)
1240 isis_circuit_if_bind (circuit
, ifp
);
1245 isis_circuit_af_set (struct isis_circuit
*circuit
, bool ip_router
, bool ipv6_router
)
1247 struct isis_area
*area
= circuit
->area
;
1248 bool change
= circuit
->ip_router
!= ip_router
|| circuit
->ipv6_router
!= ipv6_router
;
1249 bool was_enabled
= !!circuit
->area
;
1251 area
->ip_circuits
+= ip_router
- circuit
->ip_router
;
1252 area
->ipv6_circuits
+= ipv6_router
- circuit
->ipv6_router
;
1253 circuit
->ip_router
= ip_router
;
1254 circuit
->ipv6_router
= ipv6_router
;
1259 circuit_update_nlpids (circuit
);
1261 if (!ip_router
&& !ipv6_router
)
1262 isis_csm_state_change (ISIS_DISABLE
, circuit
, area
);
1263 else if (!was_enabled
)
1264 isis_csm_state_change (ISIS_ENABLE
, circuit
, area
);
1266 lsp_regenerate_schedule(circuit
->area
, circuit
->is_type
, 0);
1270 isis_circuit_passive_set (struct isis_circuit
*circuit
, bool passive
)
1272 if (circuit
->is_passive
== passive
)
1275 if (if_is_loopback (circuit
->interface
) && !passive
)
1278 if (circuit
->state
!= C_STATE_UP
)
1280 circuit
->is_passive
= passive
;
1284 struct isis_area
*area
= circuit
->area
;
1285 isis_csm_state_change (ISIS_DISABLE
, circuit
, area
);
1286 circuit
->is_passive
= passive
;
1287 isis_csm_state_change (ISIS_ENABLE
, circuit
, area
);
1294 isis_circuit_metric_set (struct isis_circuit
*circuit
, int level
, int metric
)
1296 assert (level
== IS_LEVEL_1
|| level
== IS_LEVEL_2
);
1297 if (metric
> MAX_WIDE_LINK_METRIC
)
1299 if (circuit
->area
&& circuit
->area
->oldmetric
1300 && metric
> MAX_NARROW_LINK_METRIC
)
1303 circuit
->te_metric
[level
- 1] = metric
;
1304 circuit
->metric
[level
- 1] = metric
;
1307 lsp_regenerate_schedule (circuit
->area
, level
, 0);
1312 isis_circuit_passwd_unset (struct isis_circuit
*circuit
)
1314 memset(&circuit
->passwd
, 0, sizeof(circuit
->passwd
));
1319 isis_circuit_passwd_set (struct isis_circuit
*circuit
, u_char passwd_type
, const char *passwd
)
1326 len
= strlen(passwd
);
1330 circuit
->passwd
.len
= len
;
1331 strncpy((char *)circuit
->passwd
.passwd
, passwd
, 255);
1332 circuit
->passwd
.type
= passwd_type
;
1337 isis_circuit_passwd_cleartext_set (struct isis_circuit
*circuit
, const char *passwd
)
1339 return isis_circuit_passwd_set (circuit
, ISIS_PASSWD_TYPE_CLEARTXT
, passwd
);
1343 isis_circuit_passwd_hmac_md5_set (struct isis_circuit
*circuit
, const char *passwd
)
1345 return isis_circuit_passwd_set (circuit
, ISIS_PASSWD_TYPE_HMAC_MD5
, passwd
);
1347 struct cmd_node interface_node
= {
1354 isis_circuit_circ_type_set(struct isis_circuit
*circuit
, int circ_type
)
1356 /* Changing the network type to/of loopback or unknown interfaces
1357 * is not supported. */
1358 if (circ_type
== CIRCUIT_T_UNKNOWN
1359 || circ_type
== CIRCUIT_T_LOOPBACK
1360 || circuit
->circ_type
== CIRCUIT_T_LOOPBACK
)
1362 if (circuit
->circ_type
!= circ_type
)
1368 if (circuit
->circ_type
== circ_type
)
1371 if (circuit
->state
!= C_STATE_UP
)
1373 circuit
->circ_type
= circ_type
;
1374 circuit
->circ_type_config
= circ_type
;
1378 struct isis_area
*area
= circuit
->area
;
1379 if (circ_type
== CIRCUIT_T_BROADCAST
1380 && !if_is_broadcast(circuit
->interface
))
1383 isis_csm_state_change(ISIS_DISABLE
, circuit
, area
);
1384 circuit
->circ_type
= circ_type
;
1385 circuit
->circ_type_config
= circ_type
;
1386 isis_csm_state_change(ISIS_ENABLE
, circuit
, area
);
1392 isis_if_new_hook (struct interface
*ifp
)
1398 isis_if_delete_hook (struct interface
*ifp
)
1400 struct isis_circuit
*circuit
;
1401 /* Clean up the circuit data */
1402 if (ifp
&& ifp
->info
)
1404 circuit
= ifp
->info
;
1405 isis_csm_state_change (IF_DOWN_FROM_Z
, circuit
, circuit
->area
);
1406 isis_csm_state_change (ISIS_DISABLE
, circuit
, circuit
->area
);
1413 isis_circuit_init ()
1415 /* Initialize Zebra interface data structure */
1416 if_add_hook (IF_NEW_HOOK
, isis_if_new_hook
);
1417 if_add_hook (IF_DELETE_HOOK
, isis_if_delete_hook
);
1419 /* Install interface node */
1420 install_node (&interface_node
, isis_interface_config_write
);
1421 install_element (CONFIG_NODE
, &interface_cmd
);
1422 install_element (CONFIG_NODE
, &no_interface_cmd
);
1424 install_default (INTERFACE_NODE
);
1425 install_element (INTERFACE_NODE
, &interface_desc_cmd
);
1426 install_element (INTERFACE_NODE
, &no_interface_desc_cmd
);