]> git.proxmox.com Git - mirror_frr.git/blob - isisd/isis_circuit.c
Merge branch 'vtysh-grammar'
[mirror_frr.git] / isisd / isis_circuit.c
1 /*
2 * IS-IS Rout(e)ing protocol - isis_circuit.h
3 *
4 * Copyright (C) 2001,2002 Sampo Saaristo
5 * Tampere University of Technology
6 * Institute of Communications Engineering
7 *
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)
11 * any later version.
12 *
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
16 * more details.
17
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.
21 */
22 #include <zebra.h>
23 #ifdef GNU_LINUX
24 #include <net/ethernet.h>
25 #else
26 #include <netinet/if_ether.h>
27 #endif
28
29 #ifndef ETHER_ADDR_LEN
30 #define ETHER_ADDR_LEN ETHERADDRL
31 #endif
32
33 #include "log.h"
34 #include "memory.h"
35 #include "vrf.h"
36 #include "if.h"
37 #include "linklist.h"
38 #include "command.h"
39 #include "thread.h"
40 #include "vty.h"
41 #include "hash.h"
42 #include "prefix.h"
43 #include "stream.h"
44 #include "qobj.h"
45
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"
63
64 DEFINE_QOBJ_TYPE(isis_circuit)
65
66 /*
67 * Prototypes.
68 */
69 int isis_interface_config_write(struct vty *);
70 int isis_if_new_hook(struct interface *);
71 int isis_if_delete_hook(struct interface *);
72
73 struct isis_circuit *
74 isis_circuit_new ()
75 {
76 struct isis_circuit *circuit;
77 int i;
78
79 circuit = XCALLOC (MTYPE_ISIS_CIRCUIT, sizeof (struct isis_circuit));
80 if (circuit == NULL)
81 {
82 zlog_err ("Can't malloc isis circuit");
83 return NULL;
84 }
85
86 /*
87 * Default values
88 */
89 circuit->is_type = IS_LEVEL_1_AND_2;
90 circuit->flags = 0;
91 circuit->pad_hellos = 1;
92 for (i = 0; i < 2; i++)
93 {
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;
101 }
102
103 circuit->mtc = mpls_te_circuit_new();
104
105 QOBJ_REG (circuit, isis_circuit);
106
107 return circuit;
108 }
109
110 void
111 isis_circuit_del (struct isis_circuit *circuit)
112 {
113 if (!circuit)
114 return;
115
116 QOBJ_UNREG (circuit);
117
118 isis_circuit_if_unbind (circuit, circuit->interface);
119
120 /* and lastly the circuit itself */
121 XFREE (MTYPE_ISIS_CIRCUIT, circuit);
122
123 return;
124 }
125
126 void
127 isis_circuit_configure (struct isis_circuit *circuit, struct isis_area *area)
128 {
129 assert (area);
130 circuit->area = area;
131
132 /*
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
136 * ensured as well.
137 */
138 if (area->is_type != IS_LEVEL_1_AND_2)
139 circuit->is_type = area->is_type;
140
141 /*
142 * Add the circuit into area
143 */
144 listnode_add (area->circuit_list, circuit);
145
146 circuit->idx = flags_get_index (&area->flags);
147
148 return;
149 }
150
151 void
152 isis_circuit_deconfigure (struct isis_circuit *circuit, struct isis_area *area)
153 {
154 /* Free the index of SRM and SSN flags */
155 flags_free_index (&area->flags, circuit->idx);
156 circuit->idx = 0;
157 /* Remove circuit from area */
158 assert (circuit->area == area);
159 listnode_delete (area->circuit_list, circuit);
160 circuit->area = NULL;
161
162 return;
163 }
164
165 struct isis_circuit *
166 circuit_lookup_by_ifp (struct interface *ifp, struct list *list)
167 {
168 struct isis_circuit *circuit = NULL;
169 struct listnode *node;
170
171 if (!list)
172 return NULL;
173
174 for (ALL_LIST_ELEMENTS_RO (list, node, circuit))
175 if (circuit->interface == ifp)
176 {
177 assert (ifp->info == circuit);
178 return circuit;
179 }
180
181 return NULL;
182 }
183
184 struct isis_circuit *
185 circuit_scan_by_ifp (struct interface *ifp)
186 {
187 struct isis_area *area;
188 struct listnode *node;
189 struct isis_circuit *circuit;
190
191 if (ifp->info)
192 return (struct isis_circuit *)ifp->info;
193
194 if (isis->area_list)
195 {
196 for (ALL_LIST_ELEMENTS_RO (isis->area_list, node, area))
197 {
198 circuit = circuit_lookup_by_ifp (ifp, area->circuit_list);
199 if (circuit)
200 return circuit;
201 }
202 }
203 return circuit_lookup_by_ifp (ifp, isis->init_circ_list);
204 }
205
206 void
207 isis_circuit_add_addr (struct isis_circuit *circuit,
208 struct connected *connected)
209 {
210 struct listnode *node;
211 struct prefix_ipv4 *ipv4;
212 #if defined(EXTREME_DEBUG)
213 char buf[PREFIX2STR_BUFFER];
214 #endif
215 struct prefix_ipv6 *ipv6;
216
217 if (connected->address->family == AF_INET)
218 {
219 u_int32_t addr = connected->address->u.prefix4.s_addr;
220 addr = ntohl (addr);
221 if (IPV4_NET0(addr) ||
222 IPV4_NET127(addr) ||
223 IN_CLASSD(addr) ||
224 IPV4_LINKLOCAL(addr))
225 return;
226
227 for (ALL_LIST_ELEMENTS_RO (circuit->ip_addrs, node, ipv4))
228 if (prefix_same ((struct prefix *) ipv4, connected->address))
229 return;
230
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);
235
236 /* Update MPLS TE Local IP address parameter */
237 set_circuitparams_local_ipaddr (circuit->mtc, ipv4->prefix);
238
239 if (circuit->area)
240 lsp_regenerate_schedule (circuit->area, circuit->is_type, 0);
241
242 #ifdef EXTREME_DEBUG
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 */
247 }
248 if (connected->address->family == AF_INET6)
249 {
250 if (IN6_IS_ADDR_LOOPBACK(&connected->address->u.prefix6))
251 return;
252
253 for (ALL_LIST_ELEMENTS_RO (circuit->ipv6_link, node, ipv6))
254 if (prefix_same ((struct prefix *) ipv6, connected->address))
255 return;
256 for (ALL_LIST_ELEMENTS_RO (circuit->ipv6_non_link, node, ipv6))
257 if (prefix_same ((struct prefix *) ipv6, connected->address))
258 return;
259
260 ipv6 = prefix_ipv6_new ();
261 ipv6->prefixlen = connected->address->prefixlen;
262 ipv6->prefix = connected->address->u.prefix6;
263
264 if (IN6_IS_ADDR_LINKLOCAL (&ipv6->prefix))
265 listnode_add (circuit->ipv6_link, ipv6);
266 else
267 listnode_add (circuit->ipv6_non_link, ipv6);
268 if (circuit->area)
269 lsp_regenerate_schedule (circuit->area, circuit->is_type, 0);
270
271 #ifdef EXTREME_DEBUG
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 */
276 }
277 return;
278 }
279
280 void
281 isis_circuit_del_addr (struct isis_circuit *circuit,
282 struct connected *connected)
283 {
284 struct prefix_ipv4 *ipv4, *ip = NULL;
285 struct listnode *node;
286 char buf[PREFIX2STR_BUFFER];
287 #ifdef HAVE_IPV6
288 struct prefix_ipv6 *ipv6, *ip6 = NULL;
289 int found = 0;
290 #endif /* HAVE_IPV6 */
291
292 if (connected->address->family == AF_INET)
293 {
294 ipv4 = prefix_ipv4_new ();
295 ipv4->prefixlen = connected->address->prefixlen;
296 ipv4->prefix = connected->address->u.prefix4;
297
298 for (ALL_LIST_ELEMENTS_RO (circuit->ip_addrs, node, ip))
299 if (prefix_same ((struct prefix *) ip, (struct prefix *) ipv4))
300 break;
301
302 if (ip)
303 {
304 listnode_delete (circuit->ip_addrs, ip);
305 if (circuit->area)
306 lsp_regenerate_schedule (circuit->area, circuit->is_type, 0);
307 }
308 else
309 {
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))
315 {
316 prefix2str((struct prefix*)ip, (char *)buf, BUFSIZ);
317 zlog_warn(" %s", buf);
318 }
319 zlog_warn("End of addresses");
320 }
321
322 prefix_ipv4_free (ipv4);
323 }
324 #ifdef HAVE_IPV6
325 if (connected->address->family == AF_INET6)
326 {
327 ipv6 = prefix_ipv6_new ();
328 ipv6->prefixlen = connected->address->prefixlen;
329 ipv6->prefix = connected->address->u.prefix6;
330
331 if (IN6_IS_ADDR_LINKLOCAL (&ipv6->prefix))
332 {
333 for (ALL_LIST_ELEMENTS_RO (circuit->ipv6_link, node, ip6))
334 {
335 if (prefix_same ((struct prefix *) ip6, (struct prefix *) ipv6))
336 break;
337 }
338 if (ip6)
339 {
340 listnode_delete (circuit->ipv6_link, ip6);
341 found = 1;
342 }
343 }
344 else
345 {
346 for (ALL_LIST_ELEMENTS_RO (circuit->ipv6_non_link, node, ip6))
347 {
348 if (prefix_same ((struct prefix *) ip6, (struct prefix *) ipv6))
349 break;
350 }
351 if (ip6)
352 {
353 listnode_delete (circuit->ipv6_non_link, ip6);
354 found = 1;
355 }
356 }
357
358 if (!found)
359 {
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))
365 {
366 prefix2str((struct prefix*)ip6, (char *)buf, BUFSIZ);
367 zlog_warn(" %s", buf);
368 }
369 zlog_warn(" -----");
370 for (ALL_LIST_ELEMENTS_RO(circuit->ipv6_non_link, node, ip6))
371 {
372 prefix2str((struct prefix*)ip6, (char *)buf, BUFSIZ);
373 zlog_warn(" %s", buf);
374 }
375 zlog_warn("End of addresses");
376 }
377 else if (circuit->area)
378 lsp_regenerate_schedule (circuit->area, circuit->is_type, 0);
379
380 prefix_ipv6_free (ipv6);
381 }
382 #endif /* HAVE_IPV6 */
383 return;
384 }
385
386 static u_char
387 isis_circuit_id_gen (struct interface *ifp)
388 {
389 u_char id = 0;
390 char ifname[16];
391 unsigned int i;
392 int start = -1, end = -1;
393
394 /*
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.
401 */
402 for (i = 0; i < strlen (ifp->name); i++)
403 {
404 if (isdigit((unsigned char)ifp->name[i]))
405 {
406 if (start < 0)
407 {
408 start = i;
409 end = i + 1;
410 }
411 else
412 {
413 end = i + 1;
414 }
415 }
416 else if (start >= 0)
417 break;
418 }
419
420 if ((start >= 0) && (end >= start) && (end - start) < 16)
421 {
422 memset (ifname, 0, 16);
423 strncpy (ifname, &ifp->name[start], end - start);
424 id = (u_char)atoi(ifname);
425 }
426
427 /* Try to be unique. */
428 if (!id)
429 id = (u_char)((ifp->ifindex & 0xff) | 0x80);
430
431 return id;
432 }
433
434 void
435 isis_circuit_if_add (struct isis_circuit *circuit, struct interface *ifp)
436 {
437 struct listnode *node, *nnode;
438 struct connected *conn;
439
440 circuit->circuit_id = isis_circuit_id_gen (ifp);
441
442 isis_circuit_if_bind (circuit, ifp);
443 /* isis_circuit_update_addrs (circuit, ifp); */
444
445 if (if_is_broadcast (ifp))
446 {
447 if (circuit->circ_type_config == CIRCUIT_T_P2P)
448 circuit->circ_type = CIRCUIT_T_P2P;
449 else
450 circuit->circ_type = CIRCUIT_T_BROADCAST;
451 }
452 else if (if_is_pointopoint (ifp))
453 {
454 circuit->circ_type = CIRCUIT_T_P2P;
455 }
456 else if (if_is_loopback (ifp))
457 {
458 circuit->circ_type = CIRCUIT_T_LOOPBACK;
459 circuit->is_passive = 1;
460 }
461 else
462 {
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;
467 }
468
469 circuit->ip_addrs = list_new ();
470 #ifdef HAVE_IPV6
471 circuit->ipv6_link = list_new ();
472 circuit->ipv6_non_link = list_new ();
473 #endif /* HAVE_IPV6 */
474
475 for (ALL_LIST_ELEMENTS (ifp->connected, node, nnode, conn))
476 isis_circuit_add_addr (circuit, conn);
477
478 return;
479 }
480
481 void
482 isis_circuit_if_del (struct isis_circuit *circuit, struct interface *ifp)
483 {
484 struct listnode *node, *nnode;
485 struct connected *conn;
486
487 assert (circuit->interface == ifp);
488
489 /* destroy addresses */
490 for (ALL_LIST_ELEMENTS (ifp->connected, node, nnode, conn))
491 isis_circuit_del_addr (circuit, conn);
492
493 if (circuit->ip_addrs)
494 {
495 assert (listcount(circuit->ip_addrs) == 0);
496 list_delete (circuit->ip_addrs);
497 circuit->ip_addrs = NULL;
498 }
499
500 #ifdef HAVE_IPV6
501 if (circuit->ipv6_link)
502 {
503 assert (listcount(circuit->ipv6_link) == 0);
504 list_delete (circuit->ipv6_link);
505 circuit->ipv6_link = NULL;
506 }
507
508 if (circuit->ipv6_non_link)
509 {
510 assert (listcount(circuit->ipv6_non_link) == 0);
511 list_delete (circuit->ipv6_non_link);
512 circuit->ipv6_non_link = NULL;
513 }
514 #endif /* HAVE_IPV6 */
515
516 circuit->circ_type = CIRCUIT_T_UNKNOWN;
517 circuit->circuit_id = 0;
518
519 return;
520 }
521
522 void
523 isis_circuit_if_bind (struct isis_circuit *circuit, struct interface *ifp)
524 {
525 assert (circuit != NULL);
526 assert (ifp != NULL);
527 if (circuit->interface)
528 assert (circuit->interface == ifp);
529 else
530 circuit->interface = ifp;
531 if (ifp->info)
532 assert (ifp->info == circuit);
533 else
534 ifp->info = circuit;
535 isis_link_params_update (circuit, ifp);
536 }
537
538 void
539 isis_circuit_if_unbind (struct isis_circuit *circuit, struct interface *ifp)
540 {
541 assert (circuit != NULL);
542 assert (ifp != NULL);
543 assert (circuit->interface == ifp);
544 assert (ifp->info == circuit);
545 circuit->interface = NULL;
546 ifp->info = NULL;
547 }
548
549 static void
550 isis_circuit_update_all_srmflags (struct isis_circuit *circuit, int is_set)
551 {
552 struct isis_area *area;
553 struct isis_lsp *lsp;
554 dnode_t *dnode, *dnode_next;
555 int level;
556
557 assert (circuit);
558 area = circuit->area;
559 assert (area);
560 for (level = ISIS_LEVEL1; level <= ISIS_LEVEL2; level++)
561 {
562 if (level & circuit->is_type)
563 {
564 if (area->lspdb[level - 1] &&
565 dict_count (area->lspdb[level - 1]) > 0)
566 {
567 for (dnode = dict_first (area->lspdb[level - 1]);
568 dnode != NULL; dnode = dnode_next)
569 {
570 dnode_next = dict_next (area->lspdb[level - 1], dnode);
571 lsp = dnode_get (dnode);
572 if (is_set)
573 {
574 ISIS_SET_FLAG (lsp->SRMflags, circuit);
575 }
576 else
577 {
578 ISIS_CLEAR_FLAG (lsp->SRMflags, circuit);
579 }
580 }
581 }
582 }
583 }
584 }
585
586 size_t
587 isis_circuit_pdu_size(struct isis_circuit *circuit)
588 {
589 return ISO_MTU(circuit);
590 }
591
592 void
593 isis_circuit_stream(struct isis_circuit *circuit, struct stream **stream)
594 {
595 size_t stream_size = isis_circuit_pdu_size(circuit);
596
597 if (!*stream)
598 {
599 *stream = stream_new(stream_size);
600 }
601 else
602 {
603 if (STREAM_SIZE(*stream) != stream_size)
604 stream_resize(*stream, stream_size);
605 stream_reset(*stream);
606 }
607 }
608
609 int
610 isis_circuit_up (struct isis_circuit *circuit)
611 {
612 int retv;
613
614 /* Set the flags for all the lsps of the circuit. */
615 isis_circuit_update_all_srmflags (circuit, 1);
616
617 if (circuit->state == C_STATE_UP)
618 return ISIS_OK;
619
620 if (circuit->is_passive)
621 return ISIS_OK;
622
623 if (circuit->area->lsp_mtu > isis_circuit_pdu_size(circuit))
624 {
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);
629 return ISIS_ERROR;
630 }
631
632 if (circuit->circ_type == CIRCUIT_T_BROADCAST)
633 {
634 /*
635 * Get the Hardware Address
636 */
637 if (circuit->interface->hw_addr_len != ETH_ALEN)
638 {
639 zlog_warn ("unsupported link layer");
640 }
641 else
642 {
643 memcpy (circuit->u.bc.snpa, circuit->interface->hw_addr, ETH_ALEN);
644 }
645 #ifdef EXTREME_DEGUG
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 */
650
651 circuit->u.bc.adjdb[0] = list_new ();
652 circuit->u.bc.adjdb[1] = list_new ();
653
654 /*
655 * ISO 10589 - 8.4.1 Enabling of broadcast circuits
656 */
657
658 /* initilizing the hello sending threads
659 * for a broadcast IF
660 */
661
662 /* 8.4.1 a) commence sending of IIH PDUs */
663
664 if (circuit->is_type & IS_LEVEL_1)
665 {
666 thread_add_event (master, send_lan_l1_hello, circuit, 0);
667 circuit->u.bc.lan_neighs[0] = list_new ();
668 }
669
670 if (circuit->is_type & IS_LEVEL_2)
671 {
672 thread_add_event (master, send_lan_l2_hello, circuit, 0);
673 circuit->u.bc.lan_neighs[1] = list_new ();
674 }
675
676 /* 8.4.1 b) FIXME: solicit ES - 8.4.6 */
677 /* 8.4.1 c) FIXME: listen for ESH PDUs */
678
679 /* 8.4.1 d) */
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]);
687 }
688 else
689 {
690 /* initializing the hello send threads
691 * for a ptp IF
692 */
693 circuit->u.p2p.neighbor = NULL;
694 thread_add_event (master, send_p2p_hello, circuit, 0);
695 }
696
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));
701
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));
705
706 /* unified init for circuits; ignore warnings below this level */
707 retv = isis_sock_init (circuit);
708 if (retv != ISIS_OK)
709 {
710 isis_circuit_down (circuit);
711 return retv;
712 }
713
714 /* initialize the circuit streams after opening connection */
715 isis_circuit_stream(circuit, &circuit->rcv_stream);
716 isis_circuit_stream(circuit, &circuit->snd_stream);
717
718 #ifdef GNU_LINUX
719 THREAD_READ_ON (master, circuit->t_read, isis_receive, circuit,
720 circuit->fd);
721 #else
722 THREAD_TIMER_MSEC_ON (master, circuit->t_read, isis_receive, circuit,
723 listcount (circuit->area->circuit_list) * 100);
724 #endif
725
726 circuit->lsp_queue = list_new ();
727 circuit->lsp_queue_last_cleared = time (NULL);
728
729 return ISIS_OK;
730 }
731
732 void
733 isis_circuit_down (struct isis_circuit *circuit)
734 {
735 if (circuit->state != C_STATE_UP)
736 return;
737
738 /* Clear the flags for all the lsps of the circuit. */
739 isis_circuit_update_all_srmflags (circuit, 0);
740
741 if (circuit->circ_type == CIRCUIT_T_BROADCAST)
742 {
743 /* destroy neighbour lists */
744 if (circuit->u.bc.lan_neighs[0])
745 {
746 list_delete (circuit->u.bc.lan_neighs[0]);
747 circuit->u.bc.lan_neighs[0] = NULL;
748 }
749 if (circuit->u.bc.lan_neighs[1])
750 {
751 list_delete (circuit->u.bc.lan_neighs[1]);
752 circuit->u.bc.lan_neighs[1] = NULL;
753 }
754 /* destroy adjacency databases */
755 if (circuit->u.bc.adjdb[0])
756 {
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;
760 }
761 if (circuit->u.bc.adjdb[1])
762 {
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;
766 }
767 if (circuit->u.bc.is_dr[0])
768 {
769 isis_dr_resign (circuit, 1);
770 circuit->u.bc.is_dr[0] = 0;
771 }
772 memset (circuit->u.bc.l1_desig_is, 0, ISIS_SYS_ID_LEN + 1);
773 if (circuit->u.bc.is_dr[1])
774 {
775 isis_dr_resign (circuit, 2);
776 circuit->u.bc.is_dr[1] = 0;
777 }
778 memset (circuit->u.bc.l2_desig_is, 0, ISIS_SYS_ID_LEN + 1);
779 memset (circuit->u.bc.snpa, 0, ETH_ALEN);
780
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;
789 }
790 else if (circuit->circ_type == CIRCUIT_T_P2P)
791 {
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);
795 }
796
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);
803
804 if (circuit->lsp_queue)
805 {
806 circuit->lsp_queue->del = NULL;
807 list_delete (circuit->lsp_queue);
808 circuit->lsp_queue = NULL;
809 }
810
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);
816
817 circuit->upadjcount[0] = 0;
818 circuit->upadjcount[1] = 0;
819
820 /* close the socket */
821 if (circuit->fd)
822 {
823 close (circuit->fd);
824 circuit->fd = 0;
825 }
826
827 if (circuit->rcv_stream != NULL)
828 {
829 stream_free (circuit->rcv_stream);
830 circuit->rcv_stream = NULL;
831 }
832
833 if (circuit->snd_stream != NULL)
834 {
835 stream_free (circuit->snd_stream);
836 circuit->snd_stream = NULL;
837 }
838
839 thread_cancel_event (master, circuit);
840
841 return;
842 }
843
844 void
845 circuit_update_nlpids (struct isis_circuit *circuit)
846 {
847 circuit->nlpids.count = 0;
848
849 if (circuit->ip_router)
850 {
851 circuit->nlpids.nlpids[0] = NLPID_IP;
852 circuit->nlpids.count++;
853 }
854 #ifdef HAVE_IPV6
855 if (circuit->ipv6_router)
856 {
857 circuit->nlpids.nlpids[circuit->nlpids.count] = NLPID_IPV6;
858 circuit->nlpids.count++;
859 }
860 #endif /* HAVE_IPV6 */
861 return;
862 }
863
864 void
865 isis_circuit_print_vty (struct isis_circuit *circuit, struct vty *vty,
866 char detail)
867 {
868 if (detail == ISIS_UI_LEVEL_BRIEF)
869 {
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);
876 }
877
878 if (detail == ISIS_UI_LEVEL_DETAIL)
879 {
880 struct listnode *node;
881 struct prefix *ip_addr;
882 char buf[BUFSIZ];
883
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");
888 else
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)
898 {
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]);
902 else
903 vty_out (vty, " Metric: %d",
904 circuit->metric[0]);
905 if (!circuit->is_passive)
906 {
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)"),
914 VTY_NEWLINE);
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);
924 }
925 else
926 {
927 vty_out (vty, "%s", VTY_NEWLINE);
928 }
929 }
930 if (circuit->is_type & IS_LEVEL_2)
931 {
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]);
935 else
936 vty_out (vty, " Metric: %d",
937 circuit->metric[1]);
938 if (!circuit->is_passive)
939 {
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)"),
947 VTY_NEWLINE);
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);
957 }
958 else
959 {
960 vty_out (vty, "%s", VTY_NEWLINE);
961 }
962 }
963 if (circuit->ip_addrs && listcount (circuit->ip_addrs) > 0)
964 {
965 vty_out (vty, " IP Prefix(es):%s", VTY_NEWLINE);
966 for (ALL_LIST_ELEMENTS_RO (circuit->ip_addrs, node, ip_addr))
967 {
968 prefix2str (ip_addr, buf, sizeof (buf)),
969 vty_out (vty, " %s%s", buf, VTY_NEWLINE);
970 }
971 }
972 if (circuit->ipv6_link && listcount(circuit->ipv6_link) > 0)
973 {
974 vty_out(vty, " IPv6 Link-Locals:%s", VTY_NEWLINE);
975 for (ALL_LIST_ELEMENTS_RO(circuit->ipv6_link, node, ip_addr))
976 {
977 prefix2str(ip_addr, (char*)buf, BUFSIZ),
978 vty_out(vty, " %s%s", buf, VTY_NEWLINE);
979 }
980 }
981 if (circuit->ipv6_non_link && listcount(circuit->ipv6_non_link) > 0)
982 {
983 vty_out(vty, " IPv6 Prefixes:%s", VTY_NEWLINE);
984 for (ALL_LIST_ELEMENTS_RO(circuit->ipv6_non_link, node, ip_addr))
985 {
986 prefix2str(ip_addr, (char*)buf, BUFSIZ),
987 vty_out(vty, " %s%s", buf, VTY_NEWLINE);
988 }
989 }
990
991 vty_out (vty, "%s", VTY_NEWLINE);
992 }
993 return;
994 }
995
996 int
997 isis_interface_config_write (struct vty *vty)
998 {
999 int write = 0;
1000 struct listnode *node, *node2;
1001 struct interface *ifp;
1002 struct isis_area *area;
1003 struct isis_circuit *circuit;
1004 int i;
1005
1006 for (ALL_LIST_ELEMENTS_RO (vrf_iflist (VRF_DEFAULT), node, ifp))
1007 {
1008 if (ifp->ifindex == IFINDEX_DELETED)
1009 continue;
1010
1011 /* IF name */
1012 vty_out (vty, "interface %s%s", ifp->name, VTY_NEWLINE);
1013 write++;
1014 /* IF desc */
1015 if (ifp->desc)
1016 {
1017 vty_out (vty, " description %s%s", ifp->desc, VTY_NEWLINE);
1018 write++;
1019 }
1020 /* ISIS Circuit */
1021 for (ALL_LIST_ELEMENTS_RO (isis->area_list, node2, area))
1022 {
1023 circuit = circuit_lookup_by_ifp (ifp, area->circuit_list);
1024 if (circuit == NULL)
1025 continue;
1026 if (circuit->ip_router)
1027 {
1028 vty_out (vty, " ip router isis %s%s", area->area_tag,
1029 VTY_NEWLINE);
1030 write++;
1031 }
1032 if (circuit->is_passive)
1033 {
1034 vty_out (vty, " isis passive%s", VTY_NEWLINE);
1035 write++;
1036 }
1037 if (circuit->circ_type_config == CIRCUIT_T_P2P)
1038 {
1039 vty_out (vty, " isis network point-to-point%s", VTY_NEWLINE);
1040 write++;
1041 }
1042 #ifdef HAVE_IPV6
1043 if (circuit->ipv6_router)
1044 {
1045 vty_out (vty, " ipv6 router isis %s%s", area->area_tag,
1046 VTY_NEWLINE);
1047 write++;
1048 }
1049 #endif /* HAVE_IPV6 */
1050
1051 /* ISIS - circuit type */
1052 if (circuit->is_type == IS_LEVEL_1)
1053 {
1054 vty_out (vty, " isis circuit-type level-1%s", VTY_NEWLINE);
1055 write++;
1056 }
1057 else
1058 {
1059 if (circuit->is_type == IS_LEVEL_2)
1060 {
1061 vty_out (vty, " isis circuit-type level-2-only%s",
1062 VTY_NEWLINE);
1063 write++;
1064 }
1065 }
1066
1067 /* ISIS - CSNP interval */
1068 if (circuit->csnp_interval[0] == circuit->csnp_interval[1])
1069 {
1070 if (circuit->csnp_interval[0] != DEFAULT_CSNP_INTERVAL)
1071 {
1072 vty_out (vty, " isis csnp-interval %d%s",
1073 circuit->csnp_interval[0], VTY_NEWLINE);
1074 write++;
1075 }
1076 }
1077 else
1078 {
1079 for (i = 0; i < 2; i++)
1080 {
1081 if (circuit->csnp_interval[i] != DEFAULT_CSNP_INTERVAL)
1082 {
1083 vty_out (vty, " isis csnp-interval %d level-%d%s",
1084 circuit->csnp_interval[i], i + 1, VTY_NEWLINE);
1085 write++;
1086 }
1087 }
1088 }
1089
1090 /* ISIS - PSNP interval */
1091 if (circuit->psnp_interval[0] == circuit->psnp_interval[1])
1092 {
1093 if (circuit->psnp_interval[0] != DEFAULT_PSNP_INTERVAL)
1094 {
1095 vty_out (vty, " isis psnp-interval %d%s",
1096 circuit->psnp_interval[0], VTY_NEWLINE);
1097 write++;
1098 }
1099 }
1100 else
1101 {
1102 for (i = 0; i < 2; i++)
1103 {
1104 if (circuit->psnp_interval[i] != DEFAULT_PSNP_INTERVAL)
1105 {
1106 vty_out (vty, " isis psnp-interval %d level-%d%s",
1107 circuit->psnp_interval[i], i + 1, VTY_NEWLINE);
1108 write++;
1109 }
1110 }
1111 }
1112
1113 /* ISIS - Hello padding - Defaults to true so only display if false */
1114 if (circuit->pad_hellos == 0)
1115 {
1116 vty_out (vty, " no isis hello padding%s", VTY_NEWLINE);
1117 write++;
1118 }
1119
1120 /* ISIS - Hello interval */
1121 if (circuit->hello_interval[0] == circuit->hello_interval[1])
1122 {
1123 if (circuit->hello_interval[0] != DEFAULT_HELLO_INTERVAL)
1124 {
1125 vty_out (vty, " isis hello-interval %d%s",
1126 circuit->hello_interval[0], VTY_NEWLINE);
1127 write++;
1128 }
1129 }
1130 else
1131 {
1132 for (i = 0; i < 2; i++)
1133 {
1134 if (circuit->hello_interval[i] != DEFAULT_HELLO_INTERVAL)
1135 {
1136 vty_out (vty, " isis hello-interval %d level-%d%s",
1137 circuit->hello_interval[i], i + 1, VTY_NEWLINE);
1138 write++;
1139 }
1140 }
1141 }
1142
1143 /* ISIS - Hello Multiplier */
1144 if (circuit->hello_multiplier[0] == circuit->hello_multiplier[1])
1145 {
1146 if (circuit->hello_multiplier[0] != DEFAULT_HELLO_MULTIPLIER)
1147 {
1148 vty_out (vty, " isis hello-multiplier %d%s",
1149 circuit->hello_multiplier[0], VTY_NEWLINE);
1150 write++;
1151 }
1152 }
1153 else
1154 {
1155 for (i = 0; i < 2; i++)
1156 {
1157 if (circuit->hello_multiplier[i] != DEFAULT_HELLO_MULTIPLIER)
1158 {
1159 vty_out (vty, " isis hello-multiplier %d level-%d%s",
1160 circuit->hello_multiplier[i], i + 1,
1161 VTY_NEWLINE);
1162 write++;
1163 }
1164 }
1165 }
1166
1167 /* ISIS - Priority */
1168 if (circuit->priority[0] == circuit->priority[1])
1169 {
1170 if (circuit->priority[0] != DEFAULT_PRIORITY)
1171 {
1172 vty_out (vty, " isis priority %d%s",
1173 circuit->priority[0], VTY_NEWLINE);
1174 write++;
1175 }
1176 }
1177 else
1178 {
1179 for (i = 0; i < 2; i++)
1180 {
1181 if (circuit->priority[i] != DEFAULT_PRIORITY)
1182 {
1183 vty_out (vty, " isis priority %d level-%d%s",
1184 circuit->priority[i], i + 1, VTY_NEWLINE);
1185 write++;
1186 }
1187 }
1188 }
1189
1190 /* ISIS - Metric */
1191 if (circuit->te_metric[0] == circuit->te_metric[1])
1192 {
1193 if (circuit->te_metric[0] != DEFAULT_CIRCUIT_METRIC)
1194 {
1195 vty_out (vty, " isis metric %d%s", circuit->te_metric[0],
1196 VTY_NEWLINE);
1197 write++;
1198 }
1199 }
1200 else
1201 {
1202 for (i = 0; i < 2; i++)
1203 {
1204 if (circuit->te_metric[i] != DEFAULT_CIRCUIT_METRIC)
1205 {
1206 vty_out (vty, " isis metric %d level-%d%s",
1207 circuit->te_metric[i], i + 1, VTY_NEWLINE);
1208 write++;
1209 }
1210 }
1211 }
1212 if (circuit->passwd.type == ISIS_PASSWD_TYPE_HMAC_MD5)
1213 {
1214 vty_out (vty, " isis password md5 %s%s", circuit->passwd.passwd,
1215 VTY_NEWLINE);
1216 write++;
1217 }
1218 else if (circuit->passwd.type == ISIS_PASSWD_TYPE_CLEARTXT)
1219 {
1220 vty_out (vty, " isis password clear %s%s", circuit->passwd.passwd,
1221 VTY_NEWLINE);
1222 write++;
1223 }
1224 }
1225 vty_out (vty, "!%s", VTY_NEWLINE);
1226 }
1227
1228 return write;
1229 }
1230
1231 struct isis_circuit *
1232 isis_circuit_create (struct isis_area *area, struct interface *ifp)
1233 {
1234 struct isis_circuit *circuit = circuit_scan_by_ifp (ifp);
1235 if (circuit && circuit->area)
1236 return NULL;
1237 circuit = isis_csm_state_change (ISIS_ENABLE, circuit, area);
1238 if (circuit->state != C_STATE_CONF && circuit->state != C_STATE_UP)
1239 return circuit;
1240 isis_circuit_if_bind (circuit, ifp);
1241 return circuit;
1242 }
1243
1244 void
1245 isis_circuit_af_set (struct isis_circuit *circuit, bool ip_router, bool ipv6_router)
1246 {
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;
1250
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;
1255
1256 if (!change)
1257 return;
1258
1259 circuit_update_nlpids (circuit);
1260
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);
1265 else
1266 lsp_regenerate_schedule(circuit->area, circuit->is_type, 0);
1267 }
1268
1269 int
1270 isis_circuit_passive_set (struct isis_circuit *circuit, bool passive)
1271 {
1272 if (circuit->is_passive == passive)
1273 return 0;
1274
1275 if (if_is_loopback (circuit->interface) && !passive)
1276 return -1;
1277
1278 if (circuit->state != C_STATE_UP)
1279 {
1280 circuit->is_passive = passive;
1281 }
1282 else
1283 {
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);
1288 }
1289
1290 return 0;
1291 }
1292
1293 int
1294 isis_circuit_metric_set (struct isis_circuit *circuit, int level, int metric)
1295 {
1296 assert (level == IS_LEVEL_1 || level == IS_LEVEL_2);
1297 if (metric > MAX_WIDE_LINK_METRIC)
1298 return -1;
1299 if (circuit->area && circuit->area->oldmetric
1300 && metric > MAX_NARROW_LINK_METRIC)
1301 return -1;
1302
1303 circuit->te_metric[level - 1] = metric;
1304 circuit->metric[level - 1] = metric;
1305
1306 if (circuit->area)
1307 lsp_regenerate_schedule (circuit->area, level, 0);
1308 return 0;
1309 }
1310
1311 int
1312 isis_circuit_passwd_unset (struct isis_circuit *circuit)
1313 {
1314 memset(&circuit->passwd, 0, sizeof(circuit->passwd));
1315 return 0;
1316 }
1317
1318 static int
1319 isis_circuit_passwd_set (struct isis_circuit *circuit, u_char passwd_type, const char *passwd)
1320 {
1321 int len;
1322
1323 if (!passwd)
1324 return -1;
1325
1326 len = strlen(passwd);
1327 if (len > 254)
1328 return -1;
1329
1330 circuit->passwd.len = len;
1331 strncpy((char *)circuit->passwd.passwd, passwd, 255);
1332 circuit->passwd.type = passwd_type;
1333 return 0;
1334 }
1335
1336 int
1337 isis_circuit_passwd_cleartext_set (struct isis_circuit *circuit, const char *passwd)
1338 {
1339 return isis_circuit_passwd_set (circuit, ISIS_PASSWD_TYPE_CLEARTXT, passwd);
1340 }
1341
1342 int
1343 isis_circuit_passwd_hmac_md5_set (struct isis_circuit *circuit, const char *passwd)
1344 {
1345 return isis_circuit_passwd_set (circuit, ISIS_PASSWD_TYPE_HMAC_MD5, passwd);
1346 }
1347 struct cmd_node interface_node = {
1348 INTERFACE_NODE,
1349 "%s(config-if)# ",
1350 1,
1351 };
1352
1353 int
1354 isis_circuit_circ_type_set(struct isis_circuit *circuit, int circ_type)
1355 {
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)
1361 {
1362 if (circuit->circ_type != circ_type)
1363 return -1;
1364 else
1365 return 0;
1366 }
1367
1368 if (circuit->circ_type == circ_type)
1369 return 0;
1370
1371 if (circuit->state != C_STATE_UP)
1372 {
1373 circuit->circ_type = circ_type;
1374 circuit->circ_type_config = circ_type;
1375 }
1376 else
1377 {
1378 struct isis_area *area = circuit->area;
1379 if (circ_type == CIRCUIT_T_BROADCAST
1380 && !if_is_broadcast(circuit->interface))
1381 return -1;
1382
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);
1387 }
1388 return 0;
1389 }
1390
1391 int
1392 isis_if_new_hook (struct interface *ifp)
1393 {
1394 return 0;
1395 }
1396
1397 int
1398 isis_if_delete_hook (struct interface *ifp)
1399 {
1400 struct isis_circuit *circuit;
1401 /* Clean up the circuit data */
1402 if (ifp && ifp->info)
1403 {
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);
1407 }
1408
1409 return 0;
1410 }
1411
1412 void
1413 isis_circuit_init ()
1414 {
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);
1418
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);
1423
1424 install_default (INTERFACE_NODE);
1425 install_element (INTERFACE_NODE, &interface_desc_cmd);
1426 install_element (INTERFACE_NODE, &no_interface_desc_cmd);
1427
1428 isis_vty_init ();
1429 }