]> git.proxmox.com Git - mirror_frr.git/blame - isisd/isis_circuit.c
Merge pull request #2608 from pacovn/PVS-Studio_dead_code_1
[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) {
d7c0a89a 212 uint32_t addr = connected->address->u.prefix4.s_addr;
d62a17ae 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,
c28135f3 360 sizeof(buf));
d62a17ae 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,
c28135f3 367 sizeof(buf));
d62a17ae 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
0849c75e 380static uint8_t isis_circuit_id_gen(struct isis *isis, 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
0849c75e 406 _ISIS_SET_FLAG(isis->circuit_ids_used, id);
d62a17ae 407 return id;
3f045a08
JB
408}
409
d62a17ae 410void isis_circuit_if_add(struct isis_circuit *circuit, struct interface *ifp)
eb5d44eb 411{
d62a17ae 412 struct listnode *node, *nnode;
413 struct connected *conn;
414
d62a17ae 415 isis_circuit_if_bind(circuit, ifp);
d62a17ae 416
417 if (if_is_broadcast(ifp)) {
418 if (circuit->circ_type_config == CIRCUIT_T_P2P)
419 circuit->circ_type = CIRCUIT_T_P2P;
420 else
421 circuit->circ_type = CIRCUIT_T_BROADCAST;
422 } else if (if_is_pointopoint(ifp)) {
423 circuit->circ_type = CIRCUIT_T_P2P;
424 } else if (if_is_loopback(ifp)) {
425 circuit->circ_type = CIRCUIT_T_LOOPBACK;
426 circuit->is_passive = 1;
427 } else {
428 /* It's normal in case of loopback etc. */
429 if (isis->debugs & DEBUG_EVENTS)
430 zlog_debug("isis_circuit_if_add: unsupported media");
431 circuit->circ_type = CIRCUIT_T_UNKNOWN;
432 }
433
434 circuit->ip_addrs = list_new();
435 circuit->ipv6_link = list_new();
436 circuit->ipv6_non_link = list_new();
437
438 for (ALL_LIST_ELEMENTS(ifp->connected, node, nnode, conn))
439 isis_circuit_add_addr(circuit, conn);
eb5d44eb 440}
441
d62a17ae 442void isis_circuit_if_del(struct isis_circuit *circuit, struct interface *ifp)
eb5d44eb 443{
d62a17ae 444 struct listnode *node, *nnode;
445 struct connected *conn;
446
447 assert(circuit->interface == ifp);
448
449 /* destroy addresses */
450 for (ALL_LIST_ELEMENTS(ifp->connected, node, nnode, conn))
451 isis_circuit_del_addr(circuit, conn);
452
453 if (circuit->ip_addrs) {
454 assert(listcount(circuit->ip_addrs) == 0);
affe9e99 455 list_delete_and_null(&circuit->ip_addrs);
d62a17ae 456 }
457
458 if (circuit->ipv6_link) {
459 assert(listcount(circuit->ipv6_link) == 0);
affe9e99 460 list_delete_and_null(&circuit->ipv6_link);
d62a17ae 461 }
462
463 if (circuit->ipv6_non_link) {
464 assert(listcount(circuit->ipv6_non_link) == 0);
affe9e99 465 list_delete_and_null(&circuit->ipv6_non_link);
d62a17ae 466 }
467
468 circuit->circ_type = CIRCUIT_T_UNKNOWN;
eb5d44eb 469}
470
d62a17ae 471void isis_circuit_if_bind(struct isis_circuit *circuit, struct interface *ifp)
3f045a08 472{
d62a17ae 473 assert(circuit != NULL);
474 assert(ifp != NULL);
475 if (circuit->interface)
476 assert(circuit->interface == ifp);
477 else
478 circuit->interface = ifp;
479 if (ifp->info)
480 assert(ifp->info == circuit);
481 else
482 ifp->info = circuit;
483 isis_link_params_update(circuit, ifp);
3f045a08
JB
484}
485
d62a17ae 486void isis_circuit_if_unbind(struct isis_circuit *circuit, struct interface *ifp)
eb5d44eb 487{
d62a17ae 488 assert(circuit != NULL);
489 assert(ifp != NULL);
490 assert(circuit->interface == ifp);
491 assert(ifp->info == circuit);
492 circuit->interface = NULL;
493 ifp->info = NULL;
3f045a08 494}
f390d2c7 495
d62a17ae 496static void isis_circuit_update_all_srmflags(struct isis_circuit *circuit,
497 int is_set)
3f045a08 498{
d62a17ae 499 struct isis_area *area;
500 struct isis_lsp *lsp;
501 dnode_t *dnode, *dnode_next;
502 int level;
503
504 assert(circuit);
505 area = circuit->area;
506 assert(area);
507 for (level = ISIS_LEVEL1; level <= ISIS_LEVEL2; level++) {
508 if (level & circuit->is_type) {
509 if (area->lspdb[level - 1]
510 && dict_count(area->lspdb[level - 1]) > 0) {
511 for (dnode = dict_first(area->lspdb[level - 1]);
512 dnode != NULL; dnode = dnode_next) {
513 dnode_next = dict_next(
514 area->lspdb[level - 1], dnode);
515 lsp = dnode_get(dnode);
516 if (is_set) {
517 ISIS_SET_FLAG(lsp->SRMflags,
518 circuit);
519 } else {
520 ISIS_CLEAR_FLAG(lsp->SRMflags,
521 circuit);
522 }
523 }
524 }
525 }
526 }
eb5d44eb 527}
528
d62a17ae 529size_t isis_circuit_pdu_size(struct isis_circuit *circuit)
b20ccb3a 530{
d62a17ae 531 return ISO_MTU(circuit);
b20ccb3a
CF
532}
533
d62a17ae 534void isis_circuit_stream(struct isis_circuit *circuit, struct stream **stream)
b20ccb3a 535{
d62a17ae 536 size_t stream_size = isis_circuit_pdu_size(circuit);
537
538 if (!*stream) {
539 *stream = stream_new(stream_size);
540 } else {
541 if (STREAM_SIZE(*stream) != stream_size)
542 stream_resize(*stream, stream_size);
543 stream_reset(*stream);
544 }
b20ccb3a
CF
545}
546
d62a17ae 547void isis_circuit_prepare(struct isis_circuit *circuit)
5904f19f 548{
b0dd98e7 549#if ISIS_METHOD != ISIS_METHOD_DLPI
d62a17ae 550 thread_add_read(master, isis_receive, circuit, circuit->fd,
551 &circuit->t_read);
5904f19f 552#else
d62a17ae 553 thread_add_timer_msec(master, isis_receive, circuit,
554 listcount(circuit->area->circuit_list) * 100,
555 &circuit->t_read);
5904f19f
RW
556#endif
557}
558
d62a17ae 559int isis_circuit_up(struct isis_circuit *circuit)
eb5d44eb 560{
d62a17ae 561 int retv;
562
563 /* Set the flags for all the lsps of the circuit. */
564 isis_circuit_update_all_srmflags(circuit, 1);
565
566 if (circuit->state == C_STATE_UP)
567 return ISIS_OK;
568
569 if (circuit->is_passive)
570 return ISIS_OK;
571
572 if (circuit->area->lsp_mtu > isis_circuit_pdu_size(circuit)) {
573 zlog_err(
574 "Interface MTU %zu on %s is too low to support area lsp mtu %u!",
575 isis_circuit_pdu_size(circuit),
576 circuit->interface->name, circuit->area->lsp_mtu);
577 isis_circuit_update_all_srmflags(circuit, 0);
578 return ISIS_ERROR;
579 }
580
581 if (circuit->circ_type == CIRCUIT_T_BROADCAST) {
0849c75e
CF
582 circuit->circuit_id = isis_circuit_id_gen(isis, circuit->interface);
583 if (!circuit->circuit_id) {
584 zlog_err("There are already 255 broadcast circuits active!");
585 return ISIS_ERROR;
586 }
587
d62a17ae 588 /*
589 * Get the Hardware Address
590 */
591 if (circuit->interface->hw_addr_len != ETH_ALEN) {
592 zlog_warn("unsupported link layer");
593 } else {
594 memcpy(circuit->u.bc.snpa, circuit->interface->hw_addr,
595 ETH_ALEN);
596 }
3f045a08 597#ifdef EXTREME_DEGUG
d62a17ae 598 zlog_debug("isis_circuit_if_add: if_id %d, isomtu %d snpa %s",
599 circuit->interface->ifindex, ISO_MTU(circuit),
600 snpa_print(circuit->u.bc.snpa));
3f045a08 601#endif /* EXTREME_DEBUG */
3f045a08 602
d62a17ae 603 circuit->u.bc.adjdb[0] = list_new();
604 circuit->u.bc.adjdb[1] = list_new();
605
606 /*
607 * ISO 10589 - 8.4.1 Enabling of broadcast circuits
608 */
609
610 /* initilizing the hello sending threads
611 * for a broadcast IF
612 */
613
614 /* 8.4.1 a) commence sending of IIH PDUs */
615
616 if (circuit->is_type & IS_LEVEL_1) {
617 thread_add_event(master, send_lan_l1_hello, circuit, 0,
618 NULL);
619 circuit->u.bc.lan_neighs[0] = list_new();
620 }
621
622 if (circuit->is_type & IS_LEVEL_2) {
623 thread_add_event(master, send_lan_l2_hello, circuit, 0,
624 NULL);
625 circuit->u.bc.lan_neighs[1] = list_new();
626 }
627
628 /* 8.4.1 b) FIXME: solicit ES - 8.4.6 */
629 /* 8.4.1 c) FIXME: listen for ESH PDUs */
630
631 /* 8.4.1 d) */
632 /* dr election will commence in... */
633 if (circuit->is_type & IS_LEVEL_1)
634 thread_add_timer(master, isis_run_dr_l1, circuit,
635 2 * circuit->hello_interval[0],
636 &circuit->u.bc.t_run_dr[0]);
637 if (circuit->is_type & IS_LEVEL_2)
638 thread_add_timer(master, isis_run_dr_l2, circuit,
639 2 * circuit->hello_interval[1],
640 &circuit->u.bc.t_run_dr[1]);
641 } else {
642 /* initializing the hello send threads
643 * for a ptp IF
644 */
645 circuit->u.p2p.neighbor = NULL;
646 thread_add_event(master, send_p2p_hello, circuit, 0, NULL);
647 }
648
649 /* initializing PSNP timers */
650 if (circuit->is_type & IS_LEVEL_1)
651 thread_add_timer(
652 master, send_l1_psnp, circuit,
653 isis_jitter(circuit->psnp_interval[0], PSNP_JITTER),
654 &circuit->t_send_psnp[0]);
655
656 if (circuit->is_type & IS_LEVEL_2)
657 thread_add_timer(
658 master, send_l2_psnp, circuit,
659 isis_jitter(circuit->psnp_interval[1], PSNP_JITTER),
660 &circuit->t_send_psnp[1]);
661
662 /* unified init for circuits; ignore warnings below this level */
663 retv = isis_sock_init(circuit);
664 if (retv != ISIS_OK) {
665 isis_circuit_down(circuit);
666 return retv;
667 }
668
669 /* initialize the circuit streams after opening connection */
670 isis_circuit_stream(circuit, &circuit->rcv_stream);
671 isis_circuit_stream(circuit, &circuit->snd_stream);
672
673 isis_circuit_prepare(circuit);
674
675 circuit->lsp_queue = list_new();
58e16237 676 circuit->lsp_hash = isis_lsp_hash_new();
c60158ae
RZ
677 circuit->lsp_queue_last_push[0] = circuit->lsp_queue_last_push[1] =
678 monotime(NULL);
d62a17ae 679
680 return ISIS_OK;
eb5d44eb 681}
682
d62a17ae 683void isis_circuit_down(struct isis_circuit *circuit)
eb5d44eb 684{
d62a17ae 685 if (circuit->state != C_STATE_UP)
686 return;
687
688 /* Clear the flags for all the lsps of the circuit. */
689 isis_circuit_update_all_srmflags(circuit, 0);
690
691 if (circuit->circ_type == CIRCUIT_T_BROADCAST) {
692 /* destroy neighbour lists */
693 if (circuit->u.bc.lan_neighs[0]) {
affe9e99 694 list_delete_and_null(&circuit->u.bc.lan_neighs[0]);
d62a17ae 695 circuit->u.bc.lan_neighs[0] = NULL;
696 }
697 if (circuit->u.bc.lan_neighs[1]) {
affe9e99 698 list_delete_and_null(&circuit->u.bc.lan_neighs[1]);
d62a17ae 699 circuit->u.bc.lan_neighs[1] = NULL;
700 }
701 /* destroy adjacency databases */
702 if (circuit->u.bc.adjdb[0]) {
703 circuit->u.bc.adjdb[0]->del = isis_delete_adj;
affe9e99 704 list_delete_and_null(&circuit->u.bc.adjdb[0]);
d62a17ae 705 circuit->u.bc.adjdb[0] = NULL;
706 }
707 if (circuit->u.bc.adjdb[1]) {
708 circuit->u.bc.adjdb[1]->del = isis_delete_adj;
affe9e99 709 list_delete_and_null(&circuit->u.bc.adjdb[1]);
d62a17ae 710 circuit->u.bc.adjdb[1] = NULL;
711 }
712 if (circuit->u.bc.is_dr[0]) {
713 isis_dr_resign(circuit, 1);
714 circuit->u.bc.is_dr[0] = 0;
715 }
716 memset(circuit->u.bc.l1_desig_is, 0, ISIS_SYS_ID_LEN + 1);
717 if (circuit->u.bc.is_dr[1]) {
718 isis_dr_resign(circuit, 2);
719 circuit->u.bc.is_dr[1] = 0;
720 }
721 memset(circuit->u.bc.l2_desig_is, 0, ISIS_SYS_ID_LEN + 1);
722 memset(circuit->u.bc.snpa, 0, ETH_ALEN);
723
724 THREAD_TIMER_OFF(circuit->u.bc.t_send_lan_hello[0]);
725 THREAD_TIMER_OFF(circuit->u.bc.t_send_lan_hello[1]);
726 THREAD_TIMER_OFF(circuit->u.bc.t_run_dr[0]);
727 THREAD_TIMER_OFF(circuit->u.bc.t_run_dr[1]);
728 THREAD_TIMER_OFF(circuit->u.bc.t_refresh_pseudo_lsp[0]);
729 THREAD_TIMER_OFF(circuit->u.bc.t_refresh_pseudo_lsp[1]);
730 circuit->lsp_regenerate_pending[0] = 0;
731 circuit->lsp_regenerate_pending[1] = 0;
0849c75e
CF
732
733 _ISIS_CLEAR_FLAG(isis->circuit_ids_used, circuit->circuit_id);
734 circuit->circuit_id = 0;
d62a17ae 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
58e5d748
CF
1044 if (circuit->disable_threeway_adj) {
1045 vty_out(vty, " no isis three-way-handshake\n");
1046 write++;
1047 }
1048
d62a17ae 1049 /* ISIS - Hello interval */
1050 if (circuit->hello_interval[0]
1051 == circuit->hello_interval[1]) {
1052 if (circuit->hello_interval[0]
1053 != DEFAULT_HELLO_INTERVAL) {
1054 vty_out(vty,
1055 " isis hello-interval %d\n",
1056 circuit->hello_interval[0]);
1057 write++;
1058 }
1059 } else {
1060 for (i = 0; i < 2; i++) {
1061 if (circuit->hello_interval[i]
1062 != DEFAULT_HELLO_INTERVAL) {
1063 vty_out(vty,
1064 " isis hello-interval %d level-%d\n",
1065 circuit->hello_interval
1066 [i],
1067 i + 1);
1068 write++;
1069 }
1070 }
1071 }
1072
1073 /* ISIS - Hello Multiplier */
1074 if (circuit->hello_multiplier[0]
1075 == circuit->hello_multiplier[1]) {
1076 if (circuit->hello_multiplier[0]
1077 != DEFAULT_HELLO_MULTIPLIER) {
1078 vty_out(vty,
1079 " isis hello-multiplier %d\n",
1080 circuit->hello_multiplier[0]);
1081 write++;
1082 }
1083 } else {
1084 for (i = 0; i < 2; i++) {
1085 if (circuit->hello_multiplier[i]
1086 != DEFAULT_HELLO_MULTIPLIER) {
1087 vty_out(vty,
1088 " isis hello-multiplier %d level-%d\n",
1089 circuit->hello_multiplier
1090 [i],
1091 i + 1);
1092 write++;
1093 }
1094 }
1095 }
1096
1097 /* ISIS - Priority */
1098 if (circuit->priority[0] == circuit->priority[1]) {
1099 if (circuit->priority[0] != DEFAULT_PRIORITY) {
1100 vty_out(vty, " isis priority %d\n",
1101 circuit->priority[0]);
1102 write++;
1103 }
1104 } else {
1105 for (i = 0; i < 2; i++) {
1106 if (circuit->priority[i]
1107 != DEFAULT_PRIORITY) {
1108 vty_out(vty,
1109 " isis priority %d level-%d\n",
1110 circuit->priority[i],
1111 i + 1);
1112 write++;
1113 }
1114 }
1115 }
1116
1117 /* ISIS - Metric */
1118 if (circuit->te_metric[0] == circuit->te_metric[1]) {
1119 if (circuit->te_metric[0]
1120 != DEFAULT_CIRCUIT_METRIC) {
1121 vty_out(vty, " isis metric %d\n",
1122 circuit->te_metric[0]);
1123 write++;
1124 }
1125 } else {
1126 for (i = 0; i < 2; i++) {
1127 if (circuit->te_metric[i]
1128 != DEFAULT_CIRCUIT_METRIC) {
1129 vty_out(vty,
1130 " isis metric %d level-%d\n",
1131 circuit->te_metric[i],
1132 i + 1);
1133 write++;
1134 }
1135 }
1136 }
1137 if (circuit->passwd.type == ISIS_PASSWD_TYPE_HMAC_MD5) {
1138 vty_out(vty, " isis password md5 %s\n",
1139 circuit->passwd.passwd);
1140 write++;
1141 } else if (circuit->passwd.type
1142 == ISIS_PASSWD_TYPE_CLEARTXT) {
1143 vty_out(vty, " isis password clear %s\n",
1144 circuit->passwd.passwd);
1145 write++;
1146 }
1147 write += circuit_write_mt_settings(circuit, vty);
1148 }
a8b828f3 1149 vty_endframe(vty, "!\n");
d62a17ae 1150 }
1151
1152 return write;
eb5d44eb 1153}
eb5d44eb 1154
d62a17ae 1155struct isis_circuit *isis_circuit_create(struct isis_area *area,
1156 struct interface *ifp)
eb5d44eb 1157{
d62a17ae 1158 struct isis_circuit *circuit = circuit_scan_by_ifp(ifp);
1159 if (circuit && circuit->area)
1160 return NULL;
1161 circuit = isis_csm_state_change(ISIS_ENABLE, circuit, area);
1162 if (circuit->state != C_STATE_CONF && circuit->state != C_STATE_UP)
1163 return circuit;
1164 isis_circuit_if_bind(circuit, ifp);
1165 return circuit;
eb5d44eb 1166}
1167
d62a17ae 1168void isis_circuit_af_set(struct isis_circuit *circuit, bool ip_router,
1169 bool ipv6_router)
eb5d44eb 1170{
d62a17ae 1171 struct isis_area *area = circuit->area;
1172 bool change = circuit->ip_router != ip_router
1173 || circuit->ipv6_router != ipv6_router;
d62a17ae 1174
1175 area->ip_circuits += ip_router - circuit->ip_router;
1176 area->ipv6_circuits += ipv6_router - circuit->ipv6_router;
1177 circuit->ip_router = ip_router;
1178 circuit->ipv6_router = ipv6_router;
1179
1180 if (!change)
1181 return;
1182
1183 circuit_update_nlpids(circuit);
1184
1185 if (!ip_router && !ipv6_router)
1186 isis_csm_state_change(ISIS_DISABLE, circuit, area);
d62a17ae 1187 else
1188 lsp_regenerate_schedule(circuit->area, circuit->is_type, 0);
3f045a08 1189}
eb5d44eb 1190
64dd3ffe 1191ferr_r isis_circuit_passive_set(struct isis_circuit *circuit, bool passive)
3f045a08 1192{
d62a17ae 1193 if (circuit->is_passive == passive)
64dd3ffe 1194 return ferr_ok();
d62a17ae 1195
1196 if (if_is_loopback(circuit->interface) && !passive)
64dd3ffe 1197 return ferr_cfg_invalid("loopback is always passive");
d62a17ae 1198
1199 if (circuit->state != C_STATE_UP) {
1200 circuit->is_passive = passive;
1201 } else {
1202 struct isis_area *area = circuit->area;
1203 isis_csm_state_change(ISIS_DISABLE, circuit, area);
1204 circuit->is_passive = passive;
1205 isis_csm_state_change(ISIS_ENABLE, circuit, area);
1206 }
1207
64dd3ffe 1208 return ferr_ok();
eb5d44eb 1209}
1210
64dd3ffe
DL
1211ferr_r isis_circuit_metric_set(struct isis_circuit *circuit, int level,
1212 int metric)
3f045a08 1213{
d62a17ae 1214 assert(level == IS_LEVEL_1 || level == IS_LEVEL_2);
1215 if (metric > MAX_WIDE_LINK_METRIC)
64dd3ffe
DL
1216 return ferr_cfg_invalid("metric %d too large for wide metric",
1217 metric);
d62a17ae 1218 if (circuit->area && circuit->area->oldmetric
1219 && metric > MAX_NARROW_LINK_METRIC)
64dd3ffe
DL
1220 return ferr_cfg_invalid("metric %d too large for narrow metric",
1221 metric);
d62a17ae 1222
1223 circuit->te_metric[level - 1] = metric;
1224 circuit->metric[level - 1] = metric;
1225
1226 if (circuit->area)
1227 lsp_regenerate_schedule(circuit->area, level, 0);
64dd3ffe 1228 return ferr_ok();
eb5d44eb 1229}
1230
64dd3ffe 1231ferr_r isis_circuit_passwd_unset(struct isis_circuit *circuit)
eb5d44eb 1232{
d62a17ae 1233 memset(&circuit->passwd, 0, sizeof(circuit->passwd));
64dd3ffe 1234 return ferr_ok();
3f045a08
JB
1235}
1236
d62a17ae 1237static int isis_circuit_passwd_set(struct isis_circuit *circuit,
d7c0a89a 1238 uint8_t passwd_type, const char *passwd)
3f045a08 1239{
d62a17ae 1240 int len;
f390d2c7 1241
d62a17ae 1242 if (!passwd)
64dd3ffe 1243 return ferr_code_bug("no circuit password given");
50c7d14a 1244
d62a17ae 1245 len = strlen(passwd);
1246 if (len > 254)
64dd3ffe
DL
1247 return ferr_code_bug(
1248 "circuit password too long (max 254 chars)");
f390d2c7 1249
d62a17ae 1250 circuit->passwd.len = len;
1251 strncpy((char *)circuit->passwd.passwd, passwd, 255);
1252 circuit->passwd.type = passwd_type;
64dd3ffe 1253 return ferr_ok();
eb5d44eb 1254}
1255
64dd3ffe
DL
1256ferr_r isis_circuit_passwd_cleartext_set(struct isis_circuit *circuit,
1257 const char *passwd)
eb5d44eb 1258{
d62a17ae 1259 return isis_circuit_passwd_set(circuit, ISIS_PASSWD_TYPE_CLEARTXT,
1260 passwd);
50c7d14a 1261}
f390d2c7 1262
64dd3ffe
DL
1263ferr_r isis_circuit_passwd_hmac_md5_set(struct isis_circuit *circuit,
1264 const char *passwd)
50c7d14a 1265{
d62a17ae 1266 return isis_circuit_passwd_set(circuit, ISIS_PASSWD_TYPE_HMAC_MD5,
1267 passwd);
eb5d44eb 1268}
64dd3ffe 1269
3f045a08 1270struct cmd_node interface_node = {
9d303b37 1271 INTERFACE_NODE, "%s(config-if)# ", 1,
eb5d44eb 1272};
1273
64dd3ffe 1274ferr_r isis_circuit_circ_type_set(struct isis_circuit *circuit, int circ_type)
3f045a08 1275{
64dd3ffe
DL
1276 if (circuit->circ_type == circ_type)
1277 return ferr_ok();
1278
d62a17ae 1279 /* Changing the network type to/of loopback or unknown interfaces
1280 * is not supported. */
1281 if (circ_type == CIRCUIT_T_UNKNOWN || circ_type == CIRCUIT_T_LOOPBACK
1282 || circuit->circ_type == CIRCUIT_T_LOOPBACK) {
64dd3ffe
DL
1283 return ferr_cfg_invalid(
1284 "cannot change network type on unknown interface");
d62a17ae 1285 }
1286
d62a17ae 1287 if (circuit->state != C_STATE_UP) {
1288 circuit->circ_type = circ_type;
1289 circuit->circ_type_config = circ_type;
1290 } else {
1291 struct isis_area *area = circuit->area;
1292 if (circ_type == CIRCUIT_T_BROADCAST
1293 && !if_is_broadcast(circuit->interface))
64dd3ffe
DL
1294 return ferr_cfg_reality(
1295 "cannot configure non-broadcast interface for broadcast operation");
d62a17ae 1296
1297 isis_csm_state_change(ISIS_DISABLE, circuit, area);
1298 circuit->circ_type = circ_type;
1299 circuit->circ_type_config = circ_type;
1300 isis_csm_state_change(ISIS_ENABLE, circuit, area);
1301 }
64dd3ffe 1302 return ferr_ok();
3f045a08
JB
1303}
1304
d62a17ae 1305int isis_circuit_mt_enabled_set(struct isis_circuit *circuit, uint16_t mtid,
1306 bool enabled)
064f4896 1307{
d62a17ae 1308 struct isis_circuit_mt_setting *setting;
064f4896 1309
d62a17ae 1310 setting = circuit_get_mt_setting(circuit, mtid);
1311 if (setting->enabled != enabled) {
1312 setting->enabled = enabled;
1313 lsp_regenerate_schedule(circuit->area, IS_LEVEL_1 | IS_LEVEL_2,
1314 0);
1315 }
064f4896 1316
d62a17ae 1317 return CMD_SUCCESS;
064f4896
CF
1318}
1319
d62a17ae 1320int isis_if_new_hook(struct interface *ifp)
eb5d44eb 1321{
d62a17ae 1322 return 0;
eb5d44eb 1323}
1324
d62a17ae 1325int isis_if_delete_hook(struct interface *ifp)
eb5d44eb 1326{
d62a17ae 1327 struct isis_circuit *circuit;
1328 /* Clean up the circuit data */
1329 if (ifp && ifp->info) {
1330 circuit = ifp->info;
1331 isis_csm_state_change(IF_DOWN_FROM_Z, circuit, circuit->area);
1332 isis_csm_state_change(ISIS_DISABLE, circuit, circuit->area);
1333 }
1334
1335 return 0;
eb5d44eb 1336}
1337
d62a17ae 1338void isis_circuit_init()
eb5d44eb 1339{
d62a17ae 1340 /* Initialize Zebra interface data structure */
ce19a04a
DL
1341 hook_register_prio(if_add, 0, isis_if_new_hook);
1342 hook_register_prio(if_del, 0, isis_if_delete_hook);
eb5d44eb 1343
d62a17ae 1344 /* Install interface node */
1345 install_node(&interface_node, isis_interface_config_write);
1346 if_cmd_init();
eb5d44eb 1347
d62a17ae 1348 isis_vty_init();
eb5d44eb 1349}
58e16237
CF
1350
1351void isis_circuit_schedule_lsp_send(struct isis_circuit *circuit)
1352{
1353 if (circuit->t_send_lsp)
1354 return;
996c9314
LB
1355 circuit->t_send_lsp =
1356 thread_add_event(master, send_lsp, circuit, 0, NULL);
58e16237
CF
1357}
1358
1359void isis_circuit_queue_lsp(struct isis_circuit *circuit, struct isis_lsp *lsp)
1360{
1361 if (isis_lsp_hash_lookup(circuit->lsp_hash, lsp))
1362 return;
1363
1364 listnode_add(circuit->lsp_queue, lsp);
1365 isis_lsp_hash_add(circuit->lsp_hash, lsp);
1366 isis_circuit_schedule_lsp_send(circuit);
1367}
1368
1369void isis_circuit_lsp_queue_clean(struct isis_circuit *circuit)
1370{
1371 if (!circuit->lsp_queue)
1372 return;
1373
1374 list_delete_all_node(circuit->lsp_queue);
1375 isis_lsp_hash_clean(circuit->lsp_hash);
1376}
1377
1378void isis_circuit_cancel_queued_lsp(struct isis_circuit *circuit,
1379 struct isis_lsp *lsp)
1380{
1381 if (!circuit->lsp_queue)
1382 return;
1383
1384 listnode_delete(circuit->lsp_queue, lsp);
1385 isis_lsp_hash_release(circuit->lsp_hash, lsp);
1386}
1387
1388struct isis_lsp *isis_circuit_lsp_queue_pop(struct isis_circuit *circuit)
1389{
1390 if (!circuit->lsp_queue)
1391 return NULL;
1392
1393 struct listnode *node = listhead(circuit->lsp_queue);
1394 if (!node)
1395 return NULL;
1396
1397 struct isis_lsp *rv = listgetdata(node);
1398
1399 list_delete_node(circuit->lsp_queue, node);
1400 isis_lsp_hash_release(circuit->lsp_hash, rv);
1401
1402 return rv;
1403}