]> git.proxmox.com Git - mirror_frr.git/blob - isisd/isis_circuit.c
Merge pull request #1464 from chiragshah6/mdev
[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; see the file COPYING; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 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 #include "log.h"
30 #include "memory.h"
31 #include "vrf.h"
32 #include "if.h"
33 #include "linklist.h"
34 #include "command.h"
35 #include "thread.h"
36 #include "vty.h"
37 #include "hash.h"
38 #include "prefix.h"
39 #include "stream.h"
40 #include "qobj.h"
41
42 #include "isisd/dict.h"
43 #include "isisd/isis_constants.h"
44 #include "isisd/isis_common.h"
45 #include "isisd/isis_flags.h"
46 #include "isisd/isis_circuit.h"
47 #include "isisd/isis_lsp.h"
48 #include "isisd/isis_lsp_hash.h"
49 #include "isisd/isis_pdu.h"
50 #include "isisd/isis_network.h"
51 #include "isisd/isis_misc.h"
52 #include "isisd/isis_constants.h"
53 #include "isisd/isis_adjacency.h"
54 #include "isisd/isis_dr.h"
55 #include "isisd/isisd.h"
56 #include "isisd/isis_csm.h"
57 #include "isisd/isis_events.h"
58 #include "isisd/isis_te.h"
59 #include "isisd/isis_mt.h"
60
61 DEFINE_QOBJ_TYPE(isis_circuit)
62
63 /*
64 * Prototypes.
65 */
66 int isis_interface_config_write(struct vty *);
67 int isis_if_new_hook(struct interface *);
68 int isis_if_delete_hook(struct interface *);
69
70 struct isis_circuit *isis_circuit_new()
71 {
72 struct isis_circuit *circuit;
73 int i;
74
75 circuit = XCALLOC(MTYPE_ISIS_CIRCUIT, sizeof(struct isis_circuit));
76 if (circuit == NULL) {
77 zlog_err("Can't malloc isis circuit");
78 return NULL;
79 }
80
81 /*
82 * Default values
83 */
84 circuit->is_type = IS_LEVEL_1_AND_2;
85 circuit->flags = 0;
86 circuit->pad_hellos = 1;
87 for (i = 0; i < 2; i++) {
88 circuit->hello_interval[i] = DEFAULT_HELLO_INTERVAL;
89 circuit->hello_multiplier[i] = DEFAULT_HELLO_MULTIPLIER;
90 circuit->csnp_interval[i] = DEFAULT_CSNP_INTERVAL;
91 circuit->psnp_interval[i] = DEFAULT_PSNP_INTERVAL;
92 circuit->priority[i] = DEFAULT_PRIORITY;
93 circuit->metric[i] = DEFAULT_CIRCUIT_METRIC;
94 circuit->te_metric[i] = DEFAULT_CIRCUIT_METRIC;
95 }
96
97 circuit->mtc = mpls_te_circuit_new();
98
99 circuit_mt_init(circuit);
100
101 QOBJ_REG(circuit, isis_circuit);
102
103 return circuit;
104 }
105
106 void isis_circuit_del(struct isis_circuit *circuit)
107 {
108 if (!circuit)
109 return;
110
111 QOBJ_UNREG(circuit);
112
113 isis_circuit_if_unbind(circuit, circuit->interface);
114
115 circuit_mt_finish(circuit);
116
117 /* and lastly the circuit itself */
118 XFREE(MTYPE_ISIS_CIRCUIT, circuit);
119
120 return;
121 }
122
123 void isis_circuit_configure(struct isis_circuit *circuit,
124 struct isis_area *area)
125 {
126 assert(area);
127 circuit->area = area;
128
129 /*
130 * Whenever the is-type of an area is changed, the is-type of each
131 * circuit
132 * in that area is updated to a non-empty subset of the area is-type.
133 * Inversely, when configuring a new circuit, this property should be
134 * ensured as well.
135 */
136 if (area->is_type != IS_LEVEL_1_AND_2)
137 circuit->is_type = area->is_type;
138
139 /*
140 * Add the circuit into area
141 */
142 listnode_add(area->circuit_list, circuit);
143
144 circuit->idx = flags_get_index(&area->flags);
145
146 return;
147 }
148
149 void isis_circuit_deconfigure(struct isis_circuit *circuit,
150 struct isis_area *area)
151 {
152 /* Free the index of SRM and SSN flags */
153 flags_free_index(&area->flags, circuit->idx);
154 circuit->idx = 0;
155 /* Remove circuit from area */
156 assert(circuit->area == area);
157 listnode_delete(area->circuit_list, circuit);
158 circuit->area = NULL;
159
160 return;
161 }
162
163 struct isis_circuit *circuit_lookup_by_ifp(struct interface *ifp,
164 struct list *list)
165 {
166 struct isis_circuit *circuit = NULL;
167 struct listnode *node;
168
169 if (!list)
170 return NULL;
171
172 for (ALL_LIST_ELEMENTS_RO(list, node, circuit))
173 if (circuit->interface == ifp) {
174 assert(ifp->info == circuit);
175 return circuit;
176 }
177
178 return NULL;
179 }
180
181 struct isis_circuit *circuit_scan_by_ifp(struct interface *ifp)
182 {
183 struct isis_area *area;
184 struct listnode *node;
185 struct isis_circuit *circuit;
186
187 if (ifp->info)
188 return (struct isis_circuit *)ifp->info;
189
190 if (isis->area_list) {
191 for (ALL_LIST_ELEMENTS_RO(isis->area_list, node, area)) {
192 circuit =
193 circuit_lookup_by_ifp(ifp, area->circuit_list);
194 if (circuit)
195 return circuit;
196 }
197 }
198 return circuit_lookup_by_ifp(ifp, isis->init_circ_list);
199 }
200
201 void isis_circuit_add_addr(struct isis_circuit *circuit,
202 struct connected *connected)
203 {
204 struct listnode *node;
205 struct prefix_ipv4 *ipv4;
206 #if defined(EXTREME_DEBUG)
207 char buf[PREFIX2STR_BUFFER];
208 #endif
209 struct prefix_ipv6 *ipv6;
210
211 if (connected->address->family == AF_INET) {
212 u_int32_t addr = connected->address->u.prefix4.s_addr;
213 addr = ntohl(addr);
214 if (IPV4_NET0(addr) || IPV4_NET127(addr) || IN_CLASSD(addr)
215 || IPV4_LINKLOCAL(addr))
216 return;
217
218 for (ALL_LIST_ELEMENTS_RO(circuit->ip_addrs, node, ipv4))
219 if (prefix_same((struct prefix *)ipv4,
220 connected->address))
221 return;
222
223 ipv4 = prefix_ipv4_new();
224 ipv4->prefixlen = connected->address->prefixlen;
225 ipv4->prefix = connected->address->u.prefix4;
226 listnode_add(circuit->ip_addrs, ipv4);
227
228 /* Update MPLS TE Local IP address parameter */
229 set_circuitparams_local_ipaddr(circuit->mtc, ipv4->prefix);
230
231 if (circuit->area)
232 lsp_regenerate_schedule(circuit->area, circuit->is_type,
233 0);
234
235 #ifdef EXTREME_DEBUG
236 prefix2str(connected->address, buf, sizeof(buf));
237 zlog_debug("Added IP address %s to circuit %d", buf,
238 circuit->circuit_id);
239 #endif /* EXTREME_DEBUG */
240 }
241 if (connected->address->family == AF_INET6) {
242 if (IN6_IS_ADDR_LOOPBACK(&connected->address->u.prefix6))
243 return;
244
245 for (ALL_LIST_ELEMENTS_RO(circuit->ipv6_link, node, ipv6))
246 if (prefix_same((struct prefix *)ipv6,
247 connected->address))
248 return;
249 for (ALL_LIST_ELEMENTS_RO(circuit->ipv6_non_link, node, ipv6))
250 if (prefix_same((struct prefix *)ipv6,
251 connected->address))
252 return;
253
254 ipv6 = prefix_ipv6_new();
255 ipv6->prefixlen = connected->address->prefixlen;
256 ipv6->prefix = connected->address->u.prefix6;
257
258 if (IN6_IS_ADDR_LINKLOCAL(&ipv6->prefix))
259 listnode_add(circuit->ipv6_link, ipv6);
260 else
261 listnode_add(circuit->ipv6_non_link, ipv6);
262 if (circuit->area)
263 lsp_regenerate_schedule(circuit->area, circuit->is_type,
264 0);
265
266 #ifdef EXTREME_DEBUG
267 prefix2str(connected->address, buf, sizeof(buf));
268 zlog_debug("Added IPv6 address %s to circuit %d", buf,
269 circuit->circuit_id);
270 #endif /* EXTREME_DEBUG */
271 }
272 return;
273 }
274
275 void isis_circuit_del_addr(struct isis_circuit *circuit,
276 struct connected *connected)
277 {
278 struct prefix_ipv4 *ipv4, *ip = NULL;
279 struct listnode *node;
280 char buf[PREFIX2STR_BUFFER];
281 struct prefix_ipv6 *ipv6, *ip6 = NULL;
282 int found = 0;
283
284 if (connected->address->family == AF_INET) {
285 ipv4 = prefix_ipv4_new();
286 ipv4->prefixlen = connected->address->prefixlen;
287 ipv4->prefix = connected->address->u.prefix4;
288
289 for (ALL_LIST_ELEMENTS_RO(circuit->ip_addrs, node, ip))
290 if (prefix_same((struct prefix *)ip,
291 (struct prefix *)ipv4))
292 break;
293
294 if (ip) {
295 listnode_delete(circuit->ip_addrs, ip);
296 if (circuit->area)
297 lsp_regenerate_schedule(circuit->area,
298 circuit->is_type, 0);
299 } else {
300 prefix2str(connected->address, buf, sizeof(buf));
301 zlog_warn(
302 "Nonexistant ip address %s removal attempt from \
303 circuit %d",
304 buf, circuit->circuit_id);
305 zlog_warn("Current ip addresses on %s:",
306 circuit->interface->name);
307 for (ALL_LIST_ELEMENTS_RO(circuit->ip_addrs, node,
308 ip)) {
309 prefix2str(ip, buf, sizeof(buf));
310 zlog_warn(" %s", buf);
311 }
312 zlog_warn("End of addresses");
313 }
314
315 prefix_ipv4_free(ipv4);
316 }
317 if (connected->address->family == AF_INET6) {
318 ipv6 = prefix_ipv6_new();
319 ipv6->prefixlen = connected->address->prefixlen;
320 ipv6->prefix = connected->address->u.prefix6;
321
322 if (IN6_IS_ADDR_LINKLOCAL(&ipv6->prefix)) {
323 for (ALL_LIST_ELEMENTS_RO(circuit->ipv6_link, node,
324 ip6)) {
325 if (prefix_same((struct prefix *)ip6,
326 (struct prefix *)ipv6))
327 break;
328 }
329 if (ip6) {
330 listnode_delete(circuit->ipv6_link, ip6);
331 found = 1;
332 }
333 } else {
334 for (ALL_LIST_ELEMENTS_RO(circuit->ipv6_non_link, node,
335 ip6)) {
336 if (prefix_same((struct prefix *)ip6,
337 (struct prefix *)ipv6))
338 break;
339 }
340 if (ip6) {
341 listnode_delete(circuit->ipv6_non_link, ip6);
342 found = 1;
343 }
344 }
345
346 if (!found) {
347 prefix2str(connected->address, buf, sizeof(buf));
348 zlog_warn(
349 "Nonexitant ip address %s removal attempt from \
350 circuit %d",
351 buf, circuit->circuit_id);
352 zlog_warn("Current ip addresses on %s:",
353 circuit->interface->name);
354 for (ALL_LIST_ELEMENTS_RO(circuit->ipv6_link, node,
355 ip6)) {
356 prefix2str((struct prefix *)ip6, (char *)buf,
357 BUFSIZ);
358 zlog_warn(" %s", buf);
359 }
360 zlog_warn(" -----");
361 for (ALL_LIST_ELEMENTS_RO(circuit->ipv6_non_link, node,
362 ip6)) {
363 prefix2str((struct prefix *)ip6, (char *)buf,
364 BUFSIZ);
365 zlog_warn(" %s", buf);
366 }
367 zlog_warn("End of addresses");
368 } else if (circuit->area)
369 lsp_regenerate_schedule(circuit->area, circuit->is_type,
370 0);
371
372 prefix_ipv6_free(ipv6);
373 }
374 return;
375 }
376
377 static uint8_t isis_circuit_id_gen(struct interface *ifp)
378 {
379 /* Circuit ids MUST be unique for any broadcast circuits. Otherwise,
380 * Pseudo-Node LSPs cannot be generated correctly.
381 *
382 * Currently, allocate one circuit ID for any circuit, limiting the total
383 * numer of circuits IS-IS can run on to 255.
384 *
385 * We should revisit this when implementing 3-way adjacencies for p2p, since
386 * we then have extended interface IDs available.
387 */
388 uint8_t id = ifp->ifindex;
389 unsigned int i;
390
391 for (i = 0; i < 256; i++) {
392 if (id && !_ISIS_CHECK_FLAG(isis->circuit_ids_used, id))
393 break;
394 id++;
395 }
396
397 if (i == 256) {
398 zlog_warn("Could not allocate a circuit id for '%s'", ifp->name);
399 return 0;
400 }
401
402 return id;
403 }
404
405 void isis_circuit_if_add(struct isis_circuit *circuit, struct interface *ifp)
406 {
407 struct listnode *node, *nnode;
408 struct connected *conn;
409
410 circuit->circuit_id = isis_circuit_id_gen(ifp);
411 _ISIS_SET_FLAG(isis->circuit_ids_used, circuit->circuit_id);
412
413 isis_circuit_if_bind(circuit, ifp);
414 /* isis_circuit_update_addrs (circuit, ifp); */
415
416 if (if_is_broadcast(ifp)) {
417 if (circuit->circ_type_config == CIRCUIT_T_P2P)
418 circuit->circ_type = CIRCUIT_T_P2P;
419 else
420 circuit->circ_type = CIRCUIT_T_BROADCAST;
421 } else if (if_is_pointopoint(ifp)) {
422 circuit->circ_type = CIRCUIT_T_P2P;
423 } else if (if_is_loopback(ifp)) {
424 circuit->circ_type = CIRCUIT_T_LOOPBACK;
425 circuit->is_passive = 1;
426 } else {
427 /* It's normal in case of loopback etc. */
428 if (isis->debugs & DEBUG_EVENTS)
429 zlog_debug("isis_circuit_if_add: unsupported media");
430 circuit->circ_type = CIRCUIT_T_UNKNOWN;
431 }
432
433 circuit->ip_addrs = list_new();
434 circuit->ipv6_link = list_new();
435 circuit->ipv6_non_link = list_new();
436
437 for (ALL_LIST_ELEMENTS(ifp->connected, node, nnode, conn))
438 isis_circuit_add_addr(circuit, conn);
439
440 return;
441 }
442
443 void isis_circuit_if_del(struct isis_circuit *circuit, struct interface *ifp)
444 {
445 struct listnode *node, *nnode;
446 struct connected *conn;
447
448 assert(circuit->interface == ifp);
449
450 /* destroy addresses */
451 for (ALL_LIST_ELEMENTS(ifp->connected, node, nnode, conn))
452 isis_circuit_del_addr(circuit, conn);
453
454 if (circuit->ip_addrs) {
455 assert(listcount(circuit->ip_addrs) == 0);
456 list_delete_and_null(&circuit->ip_addrs);
457 circuit->ip_addrs = NULL;
458 }
459
460 if (circuit->ipv6_link) {
461 assert(listcount(circuit->ipv6_link) == 0);
462 list_delete_and_null(&circuit->ipv6_link);
463 circuit->ipv6_link = NULL;
464 }
465
466 if (circuit->ipv6_non_link) {
467 assert(listcount(circuit->ipv6_non_link) == 0);
468 list_delete_and_null(&circuit->ipv6_non_link);
469 circuit->ipv6_non_link = NULL;
470 }
471
472 circuit->circ_type = CIRCUIT_T_UNKNOWN;
473 _ISIS_CLEAR_FLAG(isis->circuit_ids_used, circuit->circuit_id);
474 circuit->circuit_id = 0;
475
476 return;
477 }
478
479 void isis_circuit_if_bind(struct isis_circuit *circuit, struct interface *ifp)
480 {
481 assert(circuit != NULL);
482 assert(ifp != NULL);
483 if (circuit->interface)
484 assert(circuit->interface == ifp);
485 else
486 circuit->interface = ifp;
487 if (ifp->info)
488 assert(ifp->info == circuit);
489 else
490 ifp->info = circuit;
491 isis_link_params_update(circuit, ifp);
492 }
493
494 void isis_circuit_if_unbind(struct isis_circuit *circuit, struct interface *ifp)
495 {
496 assert(circuit != NULL);
497 assert(ifp != NULL);
498 assert(circuit->interface == ifp);
499 assert(ifp->info == circuit);
500 circuit->interface = NULL;
501 ifp->info = NULL;
502 }
503
504 static void isis_circuit_update_all_srmflags(struct isis_circuit *circuit,
505 int is_set)
506 {
507 struct isis_area *area;
508 struct isis_lsp *lsp;
509 dnode_t *dnode, *dnode_next;
510 int level;
511
512 assert(circuit);
513 area = circuit->area;
514 assert(area);
515 for (level = ISIS_LEVEL1; level <= ISIS_LEVEL2; level++) {
516 if (level & circuit->is_type) {
517 if (area->lspdb[level - 1]
518 && dict_count(area->lspdb[level - 1]) > 0) {
519 for (dnode = dict_first(area->lspdb[level - 1]);
520 dnode != NULL; dnode = dnode_next) {
521 dnode_next = dict_next(
522 area->lspdb[level - 1], dnode);
523 lsp = dnode_get(dnode);
524 if (is_set) {
525 ISIS_SET_FLAG(lsp->SRMflags,
526 circuit);
527 } else {
528 ISIS_CLEAR_FLAG(lsp->SRMflags,
529 circuit);
530 }
531 }
532 }
533 }
534 }
535 }
536
537 size_t isis_circuit_pdu_size(struct isis_circuit *circuit)
538 {
539 return ISO_MTU(circuit);
540 }
541
542 void isis_circuit_stream(struct isis_circuit *circuit, struct stream **stream)
543 {
544 size_t stream_size = isis_circuit_pdu_size(circuit);
545
546 if (!*stream) {
547 *stream = stream_new(stream_size);
548 } else {
549 if (STREAM_SIZE(*stream) != stream_size)
550 stream_resize(*stream, stream_size);
551 stream_reset(*stream);
552 }
553 }
554
555 void isis_circuit_prepare(struct isis_circuit *circuit)
556 {
557 #ifdef GNU_LINUX
558 thread_add_read(master, isis_receive, circuit, circuit->fd,
559 &circuit->t_read);
560 #else
561 thread_add_timer_msec(master, isis_receive, circuit,
562 listcount(circuit->area->circuit_list) * 100,
563 &circuit->t_read);
564 #endif
565 }
566
567 int isis_circuit_up(struct isis_circuit *circuit)
568 {
569 int retv;
570
571 /* Set the flags for all the lsps of the circuit. */
572 isis_circuit_update_all_srmflags(circuit, 1);
573
574 if (circuit->state == C_STATE_UP)
575 return ISIS_OK;
576
577 if (circuit->is_passive)
578 return ISIS_OK;
579
580 if (circuit->area->lsp_mtu > isis_circuit_pdu_size(circuit)) {
581 zlog_err(
582 "Interface MTU %zu on %s is too low to support area lsp mtu %u!",
583 isis_circuit_pdu_size(circuit),
584 circuit->interface->name, circuit->area->lsp_mtu);
585 isis_circuit_update_all_srmflags(circuit, 0);
586 return ISIS_ERROR;
587 }
588
589 if (circuit->circ_type == CIRCUIT_T_BROADCAST) {
590 /*
591 * Get the Hardware Address
592 */
593 if (circuit->interface->hw_addr_len != ETH_ALEN) {
594 zlog_warn("unsupported link layer");
595 } else {
596 memcpy(circuit->u.bc.snpa, circuit->interface->hw_addr,
597 ETH_ALEN);
598 }
599 #ifdef EXTREME_DEGUG
600 zlog_debug("isis_circuit_if_add: if_id %d, isomtu %d snpa %s",
601 circuit->interface->ifindex, ISO_MTU(circuit),
602 snpa_print(circuit->u.bc.snpa));
603 #endif /* EXTREME_DEBUG */
604
605 circuit->u.bc.adjdb[0] = list_new();
606 circuit->u.bc.adjdb[1] = list_new();
607
608 /*
609 * ISO 10589 - 8.4.1 Enabling of broadcast circuits
610 */
611
612 /* initilizing the hello sending threads
613 * for a broadcast IF
614 */
615
616 /* 8.4.1 a) commence sending of IIH PDUs */
617
618 if (circuit->is_type & IS_LEVEL_1) {
619 thread_add_event(master, send_lan_l1_hello, circuit, 0,
620 NULL);
621 circuit->u.bc.lan_neighs[0] = list_new();
622 }
623
624 if (circuit->is_type & IS_LEVEL_2) {
625 thread_add_event(master, send_lan_l2_hello, circuit, 0,
626 NULL);
627 circuit->u.bc.lan_neighs[1] = list_new();
628 }
629
630 /* 8.4.1 b) FIXME: solicit ES - 8.4.6 */
631 /* 8.4.1 c) FIXME: listen for ESH PDUs */
632
633 /* 8.4.1 d) */
634 /* dr election will commence in... */
635 if (circuit->is_type & IS_LEVEL_1)
636 thread_add_timer(master, isis_run_dr_l1, circuit,
637 2 * circuit->hello_interval[0],
638 &circuit->u.bc.t_run_dr[0]);
639 if (circuit->is_type & IS_LEVEL_2)
640 thread_add_timer(master, isis_run_dr_l2, circuit,
641 2 * circuit->hello_interval[1],
642 &circuit->u.bc.t_run_dr[1]);
643 } else {
644 /* initializing the hello send threads
645 * for a ptp IF
646 */
647 circuit->u.p2p.neighbor = NULL;
648 thread_add_event(master, send_p2p_hello, circuit, 0, NULL);
649 }
650
651 /* initializing PSNP timers */
652 if (circuit->is_type & IS_LEVEL_1)
653 thread_add_timer(
654 master, send_l1_psnp, circuit,
655 isis_jitter(circuit->psnp_interval[0], PSNP_JITTER),
656 &circuit->t_send_psnp[0]);
657
658 if (circuit->is_type & IS_LEVEL_2)
659 thread_add_timer(
660 master, send_l2_psnp, circuit,
661 isis_jitter(circuit->psnp_interval[1], PSNP_JITTER),
662 &circuit->t_send_psnp[1]);
663
664 /* unified init for circuits; ignore warnings below this level */
665 retv = isis_sock_init(circuit);
666 if (retv != ISIS_OK) {
667 isis_circuit_down(circuit);
668 return retv;
669 }
670
671 /* initialize the circuit streams after opening connection */
672 isis_circuit_stream(circuit, &circuit->rcv_stream);
673 isis_circuit_stream(circuit, &circuit->snd_stream);
674
675 isis_circuit_prepare(circuit);
676
677 circuit->lsp_queue = list_new();
678 circuit->lsp_hash = isis_lsp_hash_new();
679 circuit->lsp_queue_last_push = monotime(NULL);
680
681 return ISIS_OK;
682 }
683
684 void isis_circuit_down(struct isis_circuit *circuit)
685 {
686 if (circuit->state != C_STATE_UP)
687 return;
688
689 /* Clear the flags for all the lsps of the circuit. */
690 isis_circuit_update_all_srmflags(circuit, 0);
691
692 if (circuit->circ_type == CIRCUIT_T_BROADCAST) {
693 /* destroy neighbour lists */
694 if (circuit->u.bc.lan_neighs[0]) {
695 list_delete_and_null(&circuit->u.bc.lan_neighs[0]);
696 circuit->u.bc.lan_neighs[0] = NULL;
697 }
698 if (circuit->u.bc.lan_neighs[1]) {
699 list_delete_and_null(&circuit->u.bc.lan_neighs[1]);
700 circuit->u.bc.lan_neighs[1] = NULL;
701 }
702 /* destroy adjacency databases */
703 if (circuit->u.bc.adjdb[0]) {
704 circuit->u.bc.adjdb[0]->del = isis_delete_adj;
705 list_delete_and_null(&circuit->u.bc.adjdb[0]);
706 circuit->u.bc.adjdb[0] = NULL;
707 }
708 if (circuit->u.bc.adjdb[1]) {
709 circuit->u.bc.adjdb[1]->del = isis_delete_adj;
710 list_delete_and_null(&circuit->u.bc.adjdb[1]);
711 circuit->u.bc.adjdb[1] = NULL;
712 }
713 if (circuit->u.bc.is_dr[0]) {
714 isis_dr_resign(circuit, 1);
715 circuit->u.bc.is_dr[0] = 0;
716 }
717 memset(circuit->u.bc.l1_desig_is, 0, ISIS_SYS_ID_LEN + 1);
718 if (circuit->u.bc.is_dr[1]) {
719 isis_dr_resign(circuit, 2);
720 circuit->u.bc.is_dr[1] = 0;
721 }
722 memset(circuit->u.bc.l2_desig_is, 0, ISIS_SYS_ID_LEN + 1);
723 memset(circuit->u.bc.snpa, 0, ETH_ALEN);
724
725 THREAD_TIMER_OFF(circuit->u.bc.t_send_lan_hello[0]);
726 THREAD_TIMER_OFF(circuit->u.bc.t_send_lan_hello[1]);
727 THREAD_TIMER_OFF(circuit->u.bc.t_run_dr[0]);
728 THREAD_TIMER_OFF(circuit->u.bc.t_run_dr[1]);
729 THREAD_TIMER_OFF(circuit->u.bc.t_refresh_pseudo_lsp[0]);
730 THREAD_TIMER_OFF(circuit->u.bc.t_refresh_pseudo_lsp[1]);
731 circuit->lsp_regenerate_pending[0] = 0;
732 circuit->lsp_regenerate_pending[1] = 0;
733 } else if (circuit->circ_type == CIRCUIT_T_P2P) {
734 isis_delete_adj(circuit->u.p2p.neighbor);
735 circuit->u.p2p.neighbor = NULL;
736 THREAD_TIMER_OFF(circuit->u.p2p.t_send_p2p_hello);
737 }
738
739 /* Cancel all active threads */
740 THREAD_TIMER_OFF(circuit->t_send_csnp[0]);
741 THREAD_TIMER_OFF(circuit->t_send_csnp[1]);
742 THREAD_TIMER_OFF(circuit->t_send_psnp[0]);
743 THREAD_TIMER_OFF(circuit->t_send_psnp[1]);
744 THREAD_OFF(circuit->t_send_lsp);
745 THREAD_OFF(circuit->t_read);
746
747 if (circuit->lsp_queue) {
748 list_delete_and_null(&circuit->lsp_queue);
749 }
750
751 if (circuit->lsp_hash) {
752 isis_lsp_hash_free(circuit->lsp_hash);
753 circuit->lsp_hash = NULL;
754 }
755
756 /* send one gratuitous hello to spead up convergence */
757 if (circuit->is_type & IS_LEVEL_1)
758 send_hello(circuit, IS_LEVEL_1);
759 if (circuit->is_type & IS_LEVEL_2)
760 send_hello(circuit, IS_LEVEL_2);
761
762 circuit->upadjcount[0] = 0;
763 circuit->upadjcount[1] = 0;
764
765 /* close the socket */
766 if (circuit->fd) {
767 close(circuit->fd);
768 circuit->fd = 0;
769 }
770
771 if (circuit->rcv_stream != NULL) {
772 stream_free(circuit->rcv_stream);
773 circuit->rcv_stream = NULL;
774 }
775
776 if (circuit->snd_stream != NULL) {
777 stream_free(circuit->snd_stream);
778 circuit->snd_stream = NULL;
779 }
780
781 thread_cancel_event(master, circuit);
782
783 return;
784 }
785
786 void circuit_update_nlpids(struct isis_circuit *circuit)
787 {
788 circuit->nlpids.count = 0;
789
790 if (circuit->ip_router) {
791 circuit->nlpids.nlpids[0] = NLPID_IP;
792 circuit->nlpids.count++;
793 }
794 if (circuit->ipv6_router) {
795 circuit->nlpids.nlpids[circuit->nlpids.count] = NLPID_IPV6;
796 circuit->nlpids.count++;
797 }
798 return;
799 }
800
801 void isis_circuit_print_vty(struct isis_circuit *circuit, struct vty *vty,
802 char detail)
803 {
804 if (detail == ISIS_UI_LEVEL_BRIEF) {
805 vty_out(vty, " %-12s", circuit->interface->name);
806 vty_out(vty, "0x%-7x", circuit->circuit_id);
807 vty_out(vty, "%-9s", circuit_state2string(circuit->state));
808 vty_out(vty, "%-9s", circuit_type2string(circuit->circ_type));
809 vty_out(vty, "%-9s", circuit_t2string(circuit->is_type));
810 vty_out(vty, "\n");
811 }
812
813 if (detail == ISIS_UI_LEVEL_DETAIL) {
814 struct listnode *node;
815 struct prefix *ip_addr;
816 char buf[BUFSIZ];
817
818 vty_out(vty, " Interface: %s", circuit->interface->name);
819 vty_out(vty, ", State: %s",
820 circuit_state2string(circuit->state));
821 if (circuit->is_passive)
822 vty_out(vty, ", Passive");
823 else
824 vty_out(vty, ", Active");
825 vty_out(vty, ", Circuit Id: 0x%x", circuit->circuit_id);
826 vty_out(vty, "\n");
827 vty_out(vty, " Type: %s",
828 circuit_type2string(circuit->circ_type));
829 vty_out(vty, ", Level: %s", circuit_t2string(circuit->is_type));
830 if (circuit->circ_type == CIRCUIT_T_BROADCAST)
831 vty_out(vty, ", SNPA: %-10s",
832 snpa_print(circuit->u.bc.snpa));
833 vty_out(vty, "\n");
834 if (circuit->is_type & IS_LEVEL_1) {
835 vty_out(vty, " Level-1 Information:\n");
836 if (circuit->area->newmetric)
837 vty_out(vty, " Metric: %d",
838 circuit->te_metric[0]);
839 else
840 vty_out(vty, " Metric: %d",
841 circuit->metric[0]);
842 if (!circuit->is_passive) {
843 vty_out(vty, ", Active neighbors: %u\n",
844 circuit->upadjcount[0]);
845 vty_out(vty,
846 " Hello interval: %u, "
847 "Holddown count: %u %s\n",
848 circuit->hello_interval[0],
849 circuit->hello_multiplier[0],
850 (circuit->pad_hellos ? "(pad)"
851 : "(no-pad)"));
852 vty_out(vty,
853 " CNSP interval: %u, "
854 "PSNP interval: %u\n",
855 circuit->csnp_interval[0],
856 circuit->psnp_interval[0]);
857 if (circuit->circ_type == CIRCUIT_T_BROADCAST)
858 vty_out(vty,
859 " LAN Priority: %u, %s\n",
860 circuit->priority[0],
861 (circuit->u.bc.is_dr[0]
862 ? "is DIS"
863 : "is not DIS"));
864 } else {
865 vty_out(vty, "\n");
866 }
867 }
868 if (circuit->is_type & IS_LEVEL_2) {
869 vty_out(vty, " Level-2 Information:\n");
870 if (circuit->area->newmetric)
871 vty_out(vty, " Metric: %d",
872 circuit->te_metric[1]);
873 else
874 vty_out(vty, " Metric: %d",
875 circuit->metric[1]);
876 if (!circuit->is_passive) {
877 vty_out(vty, ", Active neighbors: %u\n",
878 circuit->upadjcount[1]);
879 vty_out(vty,
880 " Hello interval: %u, "
881 "Holddown count: %u %s\n",
882 circuit->hello_interval[1],
883 circuit->hello_multiplier[1],
884 (circuit->pad_hellos ? "(pad)"
885 : "(no-pad)"));
886 vty_out(vty,
887 " CNSP interval: %u, "
888 "PSNP interval: %u\n",
889 circuit->csnp_interval[1],
890 circuit->psnp_interval[1]);
891 if (circuit->circ_type == CIRCUIT_T_BROADCAST)
892 vty_out(vty,
893 " LAN Priority: %u, %s\n",
894 circuit->priority[1],
895 (circuit->u.bc.is_dr[1]
896 ? "is DIS"
897 : "is not DIS"));
898 } else {
899 vty_out(vty, "\n");
900 }
901 }
902 if (circuit->ip_addrs && listcount(circuit->ip_addrs) > 0) {
903 vty_out(vty, " IP Prefix(es):\n");
904 for (ALL_LIST_ELEMENTS_RO(circuit->ip_addrs, node,
905 ip_addr)) {
906 prefix2str(ip_addr, buf, sizeof(buf)),
907 vty_out(vty, " %s\n", buf);
908 }
909 }
910 if (circuit->ipv6_link && listcount(circuit->ipv6_link) > 0) {
911 vty_out(vty, " IPv6 Link-Locals:\n");
912 for (ALL_LIST_ELEMENTS_RO(circuit->ipv6_link, node,
913 ip_addr)) {
914 prefix2str(ip_addr, (char *)buf, BUFSIZ),
915 vty_out(vty, " %s\n", buf);
916 }
917 }
918 if (circuit->ipv6_non_link
919 && listcount(circuit->ipv6_non_link) > 0) {
920 vty_out(vty, " IPv6 Prefixes:\n");
921 for (ALL_LIST_ELEMENTS_RO(circuit->ipv6_non_link, node,
922 ip_addr)) {
923 prefix2str(ip_addr, (char *)buf, BUFSIZ),
924 vty_out(vty, " %s\n", buf);
925 }
926 }
927
928 vty_out(vty, "\n");
929 }
930 return;
931 }
932
933 int isis_interface_config_write(struct vty *vty)
934 {
935 struct vrf *vrf = vrf_lookup_by_id(VRF_DEFAULT);
936 int write = 0;
937 struct listnode *node;
938 struct interface *ifp;
939 struct isis_area *area;
940 struct isis_circuit *circuit;
941 int i;
942
943 FOR_ALL_INTERFACES (vrf, ifp) {
944 /* IF name */
945 vty_frame(vty, "interface %s\n", ifp->name);
946 write++;
947 /* IF desc */
948 if (ifp->desc) {
949 vty_out(vty, " description %s\n", ifp->desc);
950 write++;
951 }
952 /* ISIS Circuit */
953 for (ALL_LIST_ELEMENTS_RO(isis->area_list, node, area)) {
954 circuit =
955 circuit_lookup_by_ifp(ifp, area->circuit_list);
956 if (circuit == NULL)
957 continue;
958 if (circuit->ip_router) {
959 vty_out(vty, " ip router isis %s\n",
960 area->area_tag);
961 write++;
962 }
963 if (circuit->is_passive) {
964 vty_out(vty, " isis passive\n");
965 write++;
966 }
967 if (circuit->circ_type_config == CIRCUIT_T_P2P) {
968 vty_out(vty, " isis network point-to-point\n");
969 write++;
970 }
971 if (circuit->ipv6_router) {
972 vty_out(vty, " ipv6 router isis %s\n",
973 area->area_tag);
974 write++;
975 }
976
977 /* ISIS - circuit type */
978 if (circuit->is_type == IS_LEVEL_1) {
979 vty_out(vty, " isis circuit-type level-1\n");
980 write++;
981 } else {
982 if (circuit->is_type == IS_LEVEL_2) {
983 vty_out(vty,
984 " isis circuit-type level-2-only\n");
985 write++;
986 }
987 }
988
989 /* ISIS - CSNP interval */
990 if (circuit->csnp_interval[0]
991 == circuit->csnp_interval[1]) {
992 if (circuit->csnp_interval[0]
993 != DEFAULT_CSNP_INTERVAL) {
994 vty_out(vty, " isis csnp-interval %d\n",
995 circuit->csnp_interval[0]);
996 write++;
997 }
998 } else {
999 for (i = 0; i < 2; i++) {
1000 if (circuit->csnp_interval[i]
1001 != DEFAULT_CSNP_INTERVAL) {
1002 vty_out(vty,
1003 " isis csnp-interval %d level-%d\n",
1004 circuit->csnp_interval
1005 [i],
1006 i + 1);
1007 write++;
1008 }
1009 }
1010 }
1011
1012 /* ISIS - PSNP interval */
1013 if (circuit->psnp_interval[0]
1014 == circuit->psnp_interval[1]) {
1015 if (circuit->psnp_interval[0]
1016 != DEFAULT_PSNP_INTERVAL) {
1017 vty_out(vty, " isis psnp-interval %d\n",
1018 circuit->psnp_interval[0]);
1019 write++;
1020 }
1021 } else {
1022 for (i = 0; i < 2; i++) {
1023 if (circuit->psnp_interval[i]
1024 != DEFAULT_PSNP_INTERVAL) {
1025 vty_out(vty,
1026 " isis psnp-interval %d level-%d\n",
1027 circuit->psnp_interval
1028 [i],
1029 i + 1);
1030 write++;
1031 }
1032 }
1033 }
1034
1035 /* ISIS - Hello padding - Defaults to true so only
1036 * display if false */
1037 if (circuit->pad_hellos == 0) {
1038 vty_out(vty, " no isis hello padding\n");
1039 write++;
1040 }
1041
1042 /* ISIS - Hello interval */
1043 if (circuit->hello_interval[0]
1044 == circuit->hello_interval[1]) {
1045 if (circuit->hello_interval[0]
1046 != DEFAULT_HELLO_INTERVAL) {
1047 vty_out(vty,
1048 " isis hello-interval %d\n",
1049 circuit->hello_interval[0]);
1050 write++;
1051 }
1052 } else {
1053 for (i = 0; i < 2; i++) {
1054 if (circuit->hello_interval[i]
1055 != DEFAULT_HELLO_INTERVAL) {
1056 vty_out(vty,
1057 " isis hello-interval %d level-%d\n",
1058 circuit->hello_interval
1059 [i],
1060 i + 1);
1061 write++;
1062 }
1063 }
1064 }
1065
1066 /* ISIS - Hello Multiplier */
1067 if (circuit->hello_multiplier[0]
1068 == circuit->hello_multiplier[1]) {
1069 if (circuit->hello_multiplier[0]
1070 != DEFAULT_HELLO_MULTIPLIER) {
1071 vty_out(vty,
1072 " isis hello-multiplier %d\n",
1073 circuit->hello_multiplier[0]);
1074 write++;
1075 }
1076 } else {
1077 for (i = 0; i < 2; i++) {
1078 if (circuit->hello_multiplier[i]
1079 != DEFAULT_HELLO_MULTIPLIER) {
1080 vty_out(vty,
1081 " isis hello-multiplier %d level-%d\n",
1082 circuit->hello_multiplier
1083 [i],
1084 i + 1);
1085 write++;
1086 }
1087 }
1088 }
1089
1090 /* ISIS - Priority */
1091 if (circuit->priority[0] == circuit->priority[1]) {
1092 if (circuit->priority[0] != DEFAULT_PRIORITY) {
1093 vty_out(vty, " isis priority %d\n",
1094 circuit->priority[0]);
1095 write++;
1096 }
1097 } else {
1098 for (i = 0; i < 2; i++) {
1099 if (circuit->priority[i]
1100 != DEFAULT_PRIORITY) {
1101 vty_out(vty,
1102 " isis priority %d level-%d\n",
1103 circuit->priority[i],
1104 i + 1);
1105 write++;
1106 }
1107 }
1108 }
1109
1110 /* ISIS - Metric */
1111 if (circuit->te_metric[0] == circuit->te_metric[1]) {
1112 if (circuit->te_metric[0]
1113 != DEFAULT_CIRCUIT_METRIC) {
1114 vty_out(vty, " isis metric %d\n",
1115 circuit->te_metric[0]);
1116 write++;
1117 }
1118 } else {
1119 for (i = 0; i < 2; i++) {
1120 if (circuit->te_metric[i]
1121 != DEFAULT_CIRCUIT_METRIC) {
1122 vty_out(vty,
1123 " isis metric %d level-%d\n",
1124 circuit->te_metric[i],
1125 i + 1);
1126 write++;
1127 }
1128 }
1129 }
1130 if (circuit->passwd.type == ISIS_PASSWD_TYPE_HMAC_MD5) {
1131 vty_out(vty, " isis password md5 %s\n",
1132 circuit->passwd.passwd);
1133 write++;
1134 } else if (circuit->passwd.type
1135 == ISIS_PASSWD_TYPE_CLEARTXT) {
1136 vty_out(vty, " isis password clear %s\n",
1137 circuit->passwd.passwd);
1138 write++;
1139 }
1140 write += circuit_write_mt_settings(circuit, vty);
1141 }
1142 vty_endframe(vty, "!\n");
1143 }
1144
1145 return write;
1146 }
1147
1148 struct isis_circuit *isis_circuit_create(struct isis_area *area,
1149 struct interface *ifp)
1150 {
1151 struct isis_circuit *circuit = circuit_scan_by_ifp(ifp);
1152 if (circuit && circuit->area)
1153 return NULL;
1154 circuit = isis_csm_state_change(ISIS_ENABLE, circuit, area);
1155 if (circuit->state != C_STATE_CONF && circuit->state != C_STATE_UP)
1156 return circuit;
1157 isis_circuit_if_bind(circuit, ifp);
1158 return circuit;
1159 }
1160
1161 void isis_circuit_af_set(struct isis_circuit *circuit, bool ip_router,
1162 bool ipv6_router)
1163 {
1164 struct isis_area *area = circuit->area;
1165 bool change = circuit->ip_router != ip_router
1166 || circuit->ipv6_router != ipv6_router;
1167 bool was_enabled = !!circuit->area;
1168
1169 area->ip_circuits += ip_router - circuit->ip_router;
1170 area->ipv6_circuits += ipv6_router - circuit->ipv6_router;
1171 circuit->ip_router = ip_router;
1172 circuit->ipv6_router = ipv6_router;
1173
1174 if (!change)
1175 return;
1176
1177 circuit_update_nlpids(circuit);
1178
1179 if (!ip_router && !ipv6_router)
1180 isis_csm_state_change(ISIS_DISABLE, circuit, area);
1181 else if (!was_enabled)
1182 isis_csm_state_change(ISIS_ENABLE, circuit, area);
1183 else
1184 lsp_regenerate_schedule(circuit->area, circuit->is_type, 0);
1185 }
1186
1187 ferr_r isis_circuit_passive_set(struct isis_circuit *circuit, bool passive)
1188 {
1189 if (circuit->is_passive == passive)
1190 return ferr_ok();
1191
1192 if (if_is_loopback(circuit->interface) && !passive)
1193 return ferr_cfg_invalid("loopback is always passive");
1194
1195 if (circuit->state != C_STATE_UP) {
1196 circuit->is_passive = passive;
1197 } else {
1198 struct isis_area *area = circuit->area;
1199 isis_csm_state_change(ISIS_DISABLE, circuit, area);
1200 circuit->is_passive = passive;
1201 isis_csm_state_change(ISIS_ENABLE, circuit, area);
1202 }
1203
1204 return ferr_ok();
1205 }
1206
1207 ferr_r isis_circuit_metric_set(struct isis_circuit *circuit, int level,
1208 int metric)
1209 {
1210 assert(level == IS_LEVEL_1 || level == IS_LEVEL_2);
1211 if (metric > MAX_WIDE_LINK_METRIC)
1212 return ferr_cfg_invalid("metric %d too large for wide metric",
1213 metric);
1214 if (circuit->area && circuit->area->oldmetric
1215 && metric > MAX_NARROW_LINK_METRIC)
1216 return ferr_cfg_invalid("metric %d too large for narrow metric",
1217 metric);
1218
1219 circuit->te_metric[level - 1] = metric;
1220 circuit->metric[level - 1] = metric;
1221
1222 if (circuit->area)
1223 lsp_regenerate_schedule(circuit->area, level, 0);
1224 return ferr_ok();
1225 }
1226
1227 ferr_r isis_circuit_passwd_unset(struct isis_circuit *circuit)
1228 {
1229 memset(&circuit->passwd, 0, sizeof(circuit->passwd));
1230 return ferr_ok();
1231 }
1232
1233 static int isis_circuit_passwd_set(struct isis_circuit *circuit,
1234 u_char passwd_type, const char *passwd)
1235 {
1236 int len;
1237
1238 if (!passwd)
1239 return ferr_code_bug("no circuit password given");
1240
1241 len = strlen(passwd);
1242 if (len > 254)
1243 return ferr_code_bug(
1244 "circuit password too long (max 254 chars)");
1245
1246 circuit->passwd.len = len;
1247 strncpy((char *)circuit->passwd.passwd, passwd, 255);
1248 circuit->passwd.type = passwd_type;
1249 return ferr_ok();
1250 }
1251
1252 ferr_r isis_circuit_passwd_cleartext_set(struct isis_circuit *circuit,
1253 const char *passwd)
1254 {
1255 return isis_circuit_passwd_set(circuit, ISIS_PASSWD_TYPE_CLEARTXT,
1256 passwd);
1257 }
1258
1259 ferr_r isis_circuit_passwd_hmac_md5_set(struct isis_circuit *circuit,
1260 const char *passwd)
1261 {
1262 return isis_circuit_passwd_set(circuit, ISIS_PASSWD_TYPE_HMAC_MD5,
1263 passwd);
1264 }
1265
1266 struct cmd_node interface_node = {
1267 INTERFACE_NODE, "%s(config-if)# ", 1,
1268 };
1269
1270 ferr_r isis_circuit_circ_type_set(struct isis_circuit *circuit, int circ_type)
1271 {
1272 if (circuit->circ_type == circ_type)
1273 return ferr_ok();
1274
1275 /* Changing the network type to/of loopback or unknown interfaces
1276 * is not supported. */
1277 if (circ_type == CIRCUIT_T_UNKNOWN || circ_type == CIRCUIT_T_LOOPBACK
1278 || circuit->circ_type == CIRCUIT_T_LOOPBACK) {
1279 return ferr_cfg_invalid(
1280 "cannot change network type on unknown interface");
1281 }
1282
1283 if (circuit->state != C_STATE_UP) {
1284 circuit->circ_type = circ_type;
1285 circuit->circ_type_config = circ_type;
1286 } else {
1287 struct isis_area *area = circuit->area;
1288 if (circ_type == CIRCUIT_T_BROADCAST
1289 && !if_is_broadcast(circuit->interface))
1290 return ferr_cfg_reality(
1291 "cannot configure non-broadcast interface for broadcast operation");
1292
1293 isis_csm_state_change(ISIS_DISABLE, circuit, area);
1294 circuit->circ_type = circ_type;
1295 circuit->circ_type_config = circ_type;
1296 isis_csm_state_change(ISIS_ENABLE, circuit, area);
1297 }
1298 return ferr_ok();
1299 }
1300
1301 int isis_circuit_mt_enabled_set(struct isis_circuit *circuit, uint16_t mtid,
1302 bool enabled)
1303 {
1304 struct isis_circuit_mt_setting *setting;
1305
1306 setting = circuit_get_mt_setting(circuit, mtid);
1307 if (setting->enabled != enabled) {
1308 setting->enabled = enabled;
1309 lsp_regenerate_schedule(circuit->area, IS_LEVEL_1 | IS_LEVEL_2,
1310 0);
1311 }
1312
1313 return CMD_SUCCESS;
1314 }
1315
1316 int isis_if_new_hook(struct interface *ifp)
1317 {
1318 return 0;
1319 }
1320
1321 int isis_if_delete_hook(struct interface *ifp)
1322 {
1323 struct isis_circuit *circuit;
1324 /* Clean up the circuit data */
1325 if (ifp && ifp->info) {
1326 circuit = ifp->info;
1327 isis_csm_state_change(IF_DOWN_FROM_Z, circuit, circuit->area);
1328 isis_csm_state_change(ISIS_DISABLE, circuit, circuit->area);
1329 }
1330
1331 return 0;
1332 }
1333
1334 void isis_circuit_init()
1335 {
1336 /* Initialize Zebra interface data structure */
1337 hook_register_prio(if_add, 0, isis_if_new_hook);
1338 hook_register_prio(if_del, 0, isis_if_delete_hook);
1339
1340 /* Install interface node */
1341 install_node(&interface_node, isis_interface_config_write);
1342 if_cmd_init();
1343
1344 isis_vty_init();
1345 }
1346
1347 void isis_circuit_schedule_lsp_send(struct isis_circuit *circuit)
1348 {
1349 if (circuit->t_send_lsp)
1350 return;
1351 circuit->t_send_lsp = thread_add_event(master, send_lsp, circuit, 0, NULL);
1352 }
1353
1354 void isis_circuit_queue_lsp(struct isis_circuit *circuit, struct isis_lsp *lsp)
1355 {
1356 if (isis_lsp_hash_lookup(circuit->lsp_hash, lsp))
1357 return;
1358
1359 listnode_add(circuit->lsp_queue, lsp);
1360 isis_lsp_hash_add(circuit->lsp_hash, lsp);
1361 isis_circuit_schedule_lsp_send(circuit);
1362 }
1363
1364 void isis_circuit_lsp_queue_clean(struct isis_circuit *circuit)
1365 {
1366 if (!circuit->lsp_queue)
1367 return;
1368
1369 list_delete_all_node(circuit->lsp_queue);
1370 isis_lsp_hash_clean(circuit->lsp_hash);
1371 }
1372
1373 void isis_circuit_cancel_queued_lsp(struct isis_circuit *circuit,
1374 struct isis_lsp *lsp)
1375 {
1376 if (!circuit->lsp_queue)
1377 return;
1378
1379 listnode_delete(circuit->lsp_queue, lsp);
1380 isis_lsp_hash_release(circuit->lsp_hash, lsp);
1381 }
1382
1383 struct isis_lsp *isis_circuit_lsp_queue_pop(struct isis_circuit *circuit)
1384 {
1385 if (!circuit->lsp_queue)
1386 return NULL;
1387
1388 struct listnode *node = listhead(circuit->lsp_queue);
1389 if (!node)
1390 return NULL;
1391
1392 struct isis_lsp *rv = listgetdata(node);
1393
1394 list_delete_node(circuit->lsp_queue, node);
1395 isis_lsp_hash_release(circuit->lsp_hash, rv);
1396
1397 return rv;
1398 }