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