]> git.proxmox.com Git - mirror_frr.git/blame - isisd/isis_circuit.c
Merge pull request #1701 from donaldsharp/zapi_vrf_label
[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));
237 zlog_debug("Added IP address %s to circuit %d", buf,
238 circuit->circuit_id);
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));
268 zlog_debug("Added IPv6 address %s to circuit %d", buf,
269 circuit->circuit_id);
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);
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);
f891f443 316 }
d62a17ae 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);
f891f443 373 }
d62a17ae 374 return;
375}
e8aca32f 376
068c8222 377static uint8_t isis_circuit_id_gen(struct interface *ifp)
d62a17ae 378{
068c8222
CF
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;
d62a17ae 389 unsigned int i;
d62a17ae 390
068c8222
CF
391 for (i = 0; i < 256; i++) {
392 if (id && !_ISIS_CHECK_FLAG(isis->circuit_ids_used, id))
d62a17ae 393 break;
068c8222 394 id++;
f891f443 395 }
396
068c8222
CF
397 if (i == 256) {
398 zlog_warn("Could not allocate a circuit id for '%s'", ifp->name);
399 return 0;
f891f443 400 }
e8aca32f 401
d62a17ae 402 return id;
3f045a08
JB
403}
404
d62a17ae 405void isis_circuit_if_add(struct isis_circuit *circuit, struct interface *ifp)
eb5d44eb 406{
d62a17ae 407 struct listnode *node, *nnode;
408 struct connected *conn;
409
410 circuit->circuit_id = isis_circuit_id_gen(ifp);
068c8222 411 _ISIS_SET_FLAG(isis->circuit_ids_used, circuit->circuit_id);
d62a17ae 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;
eb5d44eb 441}
442
d62a17ae 443void isis_circuit_if_del(struct isis_circuit *circuit, struct interface *ifp)
eb5d44eb 444{
d62a17ae 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);
affe9e99 456 list_delete_and_null(&circuit->ip_addrs);
d62a17ae 457 circuit->ip_addrs = NULL;
458 }
459
460 if (circuit->ipv6_link) {
461 assert(listcount(circuit->ipv6_link) == 0);
affe9e99 462 list_delete_and_null(&circuit->ipv6_link);
d62a17ae 463 circuit->ipv6_link = NULL;
464 }
465
466 if (circuit->ipv6_non_link) {
467 assert(listcount(circuit->ipv6_non_link) == 0);
affe9e99 468 list_delete_and_null(&circuit->ipv6_non_link);
d62a17ae 469 circuit->ipv6_non_link = NULL;
470 }
471
472 circuit->circ_type = CIRCUIT_T_UNKNOWN;
068c8222 473 _ISIS_CLEAR_FLAG(isis->circuit_ids_used, circuit->circuit_id);
d62a17ae 474 circuit->circuit_id = 0;
475
476 return;
eb5d44eb 477}
478
d62a17ae 479void isis_circuit_if_bind(struct isis_circuit *circuit, struct interface *ifp)
3f045a08 480{
d62a17ae 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);
3f045a08
JB
492}
493
d62a17ae 494void isis_circuit_if_unbind(struct isis_circuit *circuit, struct interface *ifp)
eb5d44eb 495{
d62a17ae 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;
3f045a08 502}
f390d2c7 503
d62a17ae 504static void isis_circuit_update_all_srmflags(struct isis_circuit *circuit,
505 int is_set)
3f045a08 506{
d62a17ae 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 }
eb5d44eb 535}
536
d62a17ae 537size_t isis_circuit_pdu_size(struct isis_circuit *circuit)
b20ccb3a 538{
d62a17ae 539 return ISO_MTU(circuit);
b20ccb3a
CF
540}
541
d62a17ae 542void isis_circuit_stream(struct isis_circuit *circuit, struct stream **stream)
b20ccb3a 543{
d62a17ae 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 }
b20ccb3a
CF
553}
554
d62a17ae 555void isis_circuit_prepare(struct isis_circuit *circuit)
5904f19f 556{
b0dd98e7 557#if ISIS_METHOD != ISIS_METHOD_DLPI
d62a17ae 558 thread_add_read(master, isis_receive, circuit, circuit->fd,
559 &circuit->t_read);
5904f19f 560#else
d62a17ae 561 thread_add_timer_msec(master, isis_receive, circuit,
562 listcount(circuit->area->circuit_list) * 100,
563 &circuit->t_read);
5904f19f
RW
564#endif
565}
566
d62a17ae 567int isis_circuit_up(struct isis_circuit *circuit)
eb5d44eb 568{
d62a17ae 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 }
3f045a08 599#ifdef EXTREME_DEGUG
d62a17ae 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));
3f045a08 603#endif /* EXTREME_DEBUG */
3f045a08 604
d62a17ae 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();
58e16237 678 circuit->lsp_hash = isis_lsp_hash_new();
c60158ae
RZ
679 circuit->lsp_queue_last_push[0] = circuit->lsp_queue_last_push[1] =
680 monotime(NULL);
d62a17ae 681
682 return ISIS_OK;
eb5d44eb 683}
684
d62a17ae 685void isis_circuit_down(struct isis_circuit *circuit)
eb5d44eb 686{
d62a17ae 687 if (circuit->state != C_STATE_UP)
688 return;
689
690 /* Clear the flags for all the lsps of the circuit. */
691 isis_circuit_update_all_srmflags(circuit, 0);
692
693 if (circuit->circ_type == CIRCUIT_T_BROADCAST) {
694 /* destroy neighbour lists */
695 if (circuit->u.bc.lan_neighs[0]) {
affe9e99 696 list_delete_and_null(&circuit->u.bc.lan_neighs[0]);
d62a17ae 697 circuit->u.bc.lan_neighs[0] = NULL;
698 }
699 if (circuit->u.bc.lan_neighs[1]) {
affe9e99 700 list_delete_and_null(&circuit->u.bc.lan_neighs[1]);
d62a17ae 701 circuit->u.bc.lan_neighs[1] = NULL;
702 }
703 /* destroy adjacency databases */
704 if (circuit->u.bc.adjdb[0]) {
705 circuit->u.bc.adjdb[0]->del = isis_delete_adj;
affe9e99 706 list_delete_and_null(&circuit->u.bc.adjdb[0]);
d62a17ae 707 circuit->u.bc.adjdb[0] = NULL;
708 }
709 if (circuit->u.bc.adjdb[1]) {
710 circuit->u.bc.adjdb[1]->del = isis_delete_adj;
affe9e99 711 list_delete_and_null(&circuit->u.bc.adjdb[1]);
d62a17ae 712 circuit->u.bc.adjdb[1] = NULL;
713 }
714 if (circuit->u.bc.is_dr[0]) {
715 isis_dr_resign(circuit, 1);
716 circuit->u.bc.is_dr[0] = 0;
717 }
718 memset(circuit->u.bc.l1_desig_is, 0, ISIS_SYS_ID_LEN + 1);
719 if (circuit->u.bc.is_dr[1]) {
720 isis_dr_resign(circuit, 2);
721 circuit->u.bc.is_dr[1] = 0;
722 }
723 memset(circuit->u.bc.l2_desig_is, 0, ISIS_SYS_ID_LEN + 1);
724 memset(circuit->u.bc.snpa, 0, ETH_ALEN);
725
726 THREAD_TIMER_OFF(circuit->u.bc.t_send_lan_hello[0]);
727 THREAD_TIMER_OFF(circuit->u.bc.t_send_lan_hello[1]);
728 THREAD_TIMER_OFF(circuit->u.bc.t_run_dr[0]);
729 THREAD_TIMER_OFF(circuit->u.bc.t_run_dr[1]);
730 THREAD_TIMER_OFF(circuit->u.bc.t_refresh_pseudo_lsp[0]);
731 THREAD_TIMER_OFF(circuit->u.bc.t_refresh_pseudo_lsp[1]);
732 circuit->lsp_regenerate_pending[0] = 0;
733 circuit->lsp_regenerate_pending[1] = 0;
734 } else if (circuit->circ_type == CIRCUIT_T_P2P) {
735 isis_delete_adj(circuit->u.p2p.neighbor);
736 circuit->u.p2p.neighbor = NULL;
737 THREAD_TIMER_OFF(circuit->u.p2p.t_send_p2p_hello);
738 }
739
740 /* Cancel all active threads */
741 THREAD_TIMER_OFF(circuit->t_send_csnp[0]);
742 THREAD_TIMER_OFF(circuit->t_send_csnp[1]);
743 THREAD_TIMER_OFF(circuit->t_send_psnp[0]);
744 THREAD_TIMER_OFF(circuit->t_send_psnp[1]);
58e16237 745 THREAD_OFF(circuit->t_send_lsp);
d62a17ae 746 THREAD_OFF(circuit->t_read);
747
748 if (circuit->lsp_queue) {
affe9e99 749 list_delete_and_null(&circuit->lsp_queue);
d62a17ae 750 }
751
58e16237
CF
752 if (circuit->lsp_hash) {
753 isis_lsp_hash_free(circuit->lsp_hash);
754 circuit->lsp_hash = NULL;
755 }
756
d62a17ae 757 /* send one gratuitous hello to spead up convergence */
758 if (circuit->is_type & IS_LEVEL_1)
759 send_hello(circuit, IS_LEVEL_1);
760 if (circuit->is_type & IS_LEVEL_2)
761 send_hello(circuit, IS_LEVEL_2);
762
763 circuit->upadjcount[0] = 0;
764 circuit->upadjcount[1] = 0;
765
766 /* close the socket */
767 if (circuit->fd) {
768 close(circuit->fd);
769 circuit->fd = 0;
770 }
771
772 if (circuit->rcv_stream != NULL) {
773 stream_free(circuit->rcv_stream);
774 circuit->rcv_stream = NULL;
775 }
776
777 if (circuit->snd_stream != NULL) {
778 stream_free(circuit->snd_stream);
779 circuit->snd_stream = NULL;
780 }
781
782 thread_cancel_event(master, circuit);
783
784 return;
eb5d44eb 785}
786
d62a17ae 787void circuit_update_nlpids(struct isis_circuit *circuit)
eb5d44eb 788{
d62a17ae 789 circuit->nlpids.count = 0;
790
791 if (circuit->ip_router) {
792 circuit->nlpids.nlpids[0] = NLPID_IP;
793 circuit->nlpids.count++;
794 }
795 if (circuit->ipv6_router) {
796 circuit->nlpids.nlpids[circuit->nlpids.count] = NLPID_IPV6;
797 circuit->nlpids.count++;
798 }
799 return;
eb5d44eb 800}
801
d62a17ae 802void isis_circuit_print_vty(struct isis_circuit *circuit, struct vty *vty,
803 char detail)
3f045a08 804{
d62a17ae 805 if (detail == ISIS_UI_LEVEL_BRIEF) {
806 vty_out(vty, " %-12s", circuit->interface->name);
807 vty_out(vty, "0x%-7x", circuit->circuit_id);
808 vty_out(vty, "%-9s", circuit_state2string(circuit->state));
809 vty_out(vty, "%-9s", circuit_type2string(circuit->circ_type));
810 vty_out(vty, "%-9s", circuit_t2string(circuit->is_type));
811 vty_out(vty, "\n");
812 }
813
814 if (detail == ISIS_UI_LEVEL_DETAIL) {
815 struct listnode *node;
816 struct prefix *ip_addr;
817 char buf[BUFSIZ];
818
819 vty_out(vty, " Interface: %s", circuit->interface->name);
820 vty_out(vty, ", State: %s",
821 circuit_state2string(circuit->state));
822 if (circuit->is_passive)
823 vty_out(vty, ", Passive");
824 else
825 vty_out(vty, ", Active");
826 vty_out(vty, ", Circuit Id: 0x%x", circuit->circuit_id);
827 vty_out(vty, "\n");
828 vty_out(vty, " Type: %s",
829 circuit_type2string(circuit->circ_type));
830 vty_out(vty, ", Level: %s", circuit_t2string(circuit->is_type));
831 if (circuit->circ_type == CIRCUIT_T_BROADCAST)
832 vty_out(vty, ", SNPA: %-10s",
833 snpa_print(circuit->u.bc.snpa));
834 vty_out(vty, "\n");
835 if (circuit->is_type & IS_LEVEL_1) {
836 vty_out(vty, " Level-1 Information:\n");
837 if (circuit->area->newmetric)
838 vty_out(vty, " Metric: %d",
839 circuit->te_metric[0]);
840 else
841 vty_out(vty, " Metric: %d",
842 circuit->metric[0]);
843 if (!circuit->is_passive) {
844 vty_out(vty, ", Active neighbors: %u\n",
845 circuit->upadjcount[0]);
846 vty_out(vty,
847 " Hello interval: %u, "
848 "Holddown count: %u %s\n",
849 circuit->hello_interval[0],
850 circuit->hello_multiplier[0],
851 (circuit->pad_hellos ? "(pad)"
852 : "(no-pad)"));
853 vty_out(vty,
854 " CNSP interval: %u, "
855 "PSNP interval: %u\n",
856 circuit->csnp_interval[0],
857 circuit->psnp_interval[0]);
858 if (circuit->circ_type == CIRCUIT_T_BROADCAST)
859 vty_out(vty,
860 " LAN Priority: %u, %s\n",
861 circuit->priority[0],
862 (circuit->u.bc.is_dr[0]
863 ? "is DIS"
864 : "is not DIS"));
865 } else {
866 vty_out(vty, "\n");
867 }
868 }
869 if (circuit->is_type & IS_LEVEL_2) {
870 vty_out(vty, " Level-2 Information:\n");
871 if (circuit->area->newmetric)
872 vty_out(vty, " Metric: %d",
873 circuit->te_metric[1]);
874 else
875 vty_out(vty, " Metric: %d",
876 circuit->metric[1]);
877 if (!circuit->is_passive) {
878 vty_out(vty, ", Active neighbors: %u\n",
879 circuit->upadjcount[1]);
880 vty_out(vty,
881 " Hello interval: %u, "
882 "Holddown count: %u %s\n",
883 circuit->hello_interval[1],
884 circuit->hello_multiplier[1],
885 (circuit->pad_hellos ? "(pad)"
886 : "(no-pad)"));
887 vty_out(vty,
888 " CNSP interval: %u, "
889 "PSNP interval: %u\n",
890 circuit->csnp_interval[1],
891 circuit->psnp_interval[1]);
892 if (circuit->circ_type == CIRCUIT_T_BROADCAST)
893 vty_out(vty,
894 " LAN Priority: %u, %s\n",
895 circuit->priority[1],
896 (circuit->u.bc.is_dr[1]
897 ? "is DIS"
898 : "is not DIS"));
899 } else {
900 vty_out(vty, "\n");
901 }
902 }
903 if (circuit->ip_addrs && listcount(circuit->ip_addrs) > 0) {
904 vty_out(vty, " IP Prefix(es):\n");
905 for (ALL_LIST_ELEMENTS_RO(circuit->ip_addrs, node,
906 ip_addr)) {
907 prefix2str(ip_addr, buf, sizeof(buf)),
908 vty_out(vty, " %s\n", buf);
909 }
910 }
911 if (circuit->ipv6_link && listcount(circuit->ipv6_link) > 0) {
912 vty_out(vty, " IPv6 Link-Locals:\n");
913 for (ALL_LIST_ELEMENTS_RO(circuit->ipv6_link, node,
914 ip_addr)) {
915 prefix2str(ip_addr, (char *)buf, BUFSIZ),
916 vty_out(vty, " %s\n", buf);
917 }
918 }
919 if (circuit->ipv6_non_link
920 && listcount(circuit->ipv6_non_link) > 0) {
921 vty_out(vty, " IPv6 Prefixes:\n");
922 for (ALL_LIST_ELEMENTS_RO(circuit->ipv6_non_link, node,
923 ip_addr)) {
924 prefix2str(ip_addr, (char *)buf, BUFSIZ),
925 vty_out(vty, " %s\n", buf);
926 }
927 }
928
929 vty_out(vty, "\n");
930 }
931 return;
3f045a08
JB
932}
933
d62a17ae 934int isis_interface_config_write(struct vty *vty)
eb5d44eb 935{
f4e14fdb 936 struct vrf *vrf = vrf_lookup_by_id(VRF_DEFAULT);
d62a17ae 937 int write = 0;
f4e14fdb 938 struct listnode *node;
d62a17ae 939 struct interface *ifp;
940 struct isis_area *area;
941 struct isis_circuit *circuit;
942 int i;
943
451fda4f 944 FOR_ALL_INTERFACES (vrf, ifp) {
d62a17ae 945 /* IF name */
a8b828f3 946 vty_frame(vty, "interface %s\n", ifp->name);
d62a17ae 947 write++;
948 /* IF desc */
949 if (ifp->desc) {
950 vty_out(vty, " description %s\n", ifp->desc);
951 write++;
952 }
953 /* ISIS Circuit */
f4e14fdb 954 for (ALL_LIST_ELEMENTS_RO(isis->area_list, node, area)) {
d62a17ae 955 circuit =
956 circuit_lookup_by_ifp(ifp, area->circuit_list);
957 if (circuit == NULL)
958 continue;
959 if (circuit->ip_router) {
960 vty_out(vty, " ip router isis %s\n",
961 area->area_tag);
962 write++;
963 }
964 if (circuit->is_passive) {
965 vty_out(vty, " isis passive\n");
966 write++;
967 }
968 if (circuit->circ_type_config == CIRCUIT_T_P2P) {
969 vty_out(vty, " isis network point-to-point\n");
970 write++;
971 }
972 if (circuit->ipv6_router) {
973 vty_out(vty, " ipv6 router isis %s\n",
974 area->area_tag);
975 write++;
976 }
977
978 /* ISIS - circuit type */
979 if (circuit->is_type == IS_LEVEL_1) {
980 vty_out(vty, " isis circuit-type level-1\n");
981 write++;
982 } else {
983 if (circuit->is_type == IS_LEVEL_2) {
984 vty_out(vty,
985 " isis circuit-type level-2-only\n");
986 write++;
987 }
988 }
989
990 /* ISIS - CSNP interval */
991 if (circuit->csnp_interval[0]
992 == circuit->csnp_interval[1]) {
993 if (circuit->csnp_interval[0]
994 != DEFAULT_CSNP_INTERVAL) {
995 vty_out(vty, " isis csnp-interval %d\n",
996 circuit->csnp_interval[0]);
997 write++;
998 }
999 } else {
1000 for (i = 0; i < 2; i++) {
1001 if (circuit->csnp_interval[i]
1002 != DEFAULT_CSNP_INTERVAL) {
1003 vty_out(vty,
1004 " isis csnp-interval %d level-%d\n",
1005 circuit->csnp_interval
1006 [i],
1007 i + 1);
1008 write++;
1009 }
1010 }
1011 }
1012
1013 /* ISIS - PSNP interval */
1014 if (circuit->psnp_interval[0]
1015 == circuit->psnp_interval[1]) {
1016 if (circuit->psnp_interval[0]
1017 != DEFAULT_PSNP_INTERVAL) {
1018 vty_out(vty, " isis psnp-interval %d\n",
1019 circuit->psnp_interval[0]);
1020 write++;
1021 }
1022 } else {
1023 for (i = 0; i < 2; i++) {
1024 if (circuit->psnp_interval[i]
1025 != DEFAULT_PSNP_INTERVAL) {
1026 vty_out(vty,
1027 " isis psnp-interval %d level-%d\n",
1028 circuit->psnp_interval
1029 [i],
1030 i + 1);
1031 write++;
1032 }
1033 }
1034 }
1035
1036 /* ISIS - Hello padding - Defaults to true so only
1037 * display if false */
1038 if (circuit->pad_hellos == 0) {
1039 vty_out(vty, " no isis hello padding\n");
1040 write++;
1041 }
1042
1043 /* ISIS - Hello interval */
1044 if (circuit->hello_interval[0]
1045 == circuit->hello_interval[1]) {
1046 if (circuit->hello_interval[0]
1047 != DEFAULT_HELLO_INTERVAL) {
1048 vty_out(vty,
1049 " isis hello-interval %d\n",
1050 circuit->hello_interval[0]);
1051 write++;
1052 }
1053 } else {
1054 for (i = 0; i < 2; i++) {
1055 if (circuit->hello_interval[i]
1056 != DEFAULT_HELLO_INTERVAL) {
1057 vty_out(vty,
1058 " isis hello-interval %d level-%d\n",
1059 circuit->hello_interval
1060 [i],
1061 i + 1);
1062 write++;
1063 }
1064 }
1065 }
1066
1067 /* ISIS - Hello Multiplier */
1068 if (circuit->hello_multiplier[0]
1069 == circuit->hello_multiplier[1]) {
1070 if (circuit->hello_multiplier[0]
1071 != DEFAULT_HELLO_MULTIPLIER) {
1072 vty_out(vty,
1073 " isis hello-multiplier %d\n",
1074 circuit->hello_multiplier[0]);
1075 write++;
1076 }
1077 } else {
1078 for (i = 0; i < 2; i++) {
1079 if (circuit->hello_multiplier[i]
1080 != DEFAULT_HELLO_MULTIPLIER) {
1081 vty_out(vty,
1082 " isis hello-multiplier %d level-%d\n",
1083 circuit->hello_multiplier
1084 [i],
1085 i + 1);
1086 write++;
1087 }
1088 }
1089 }
1090
1091 /* ISIS - Priority */
1092 if (circuit->priority[0] == circuit->priority[1]) {
1093 if (circuit->priority[0] != DEFAULT_PRIORITY) {
1094 vty_out(vty, " isis priority %d\n",
1095 circuit->priority[0]);
1096 write++;
1097 }
1098 } else {
1099 for (i = 0; i < 2; i++) {
1100 if (circuit->priority[i]
1101 != DEFAULT_PRIORITY) {
1102 vty_out(vty,
1103 " isis priority %d level-%d\n",
1104 circuit->priority[i],
1105 i + 1);
1106 write++;
1107 }
1108 }
1109 }
1110
1111 /* ISIS - Metric */
1112 if (circuit->te_metric[0] == circuit->te_metric[1]) {
1113 if (circuit->te_metric[0]
1114 != DEFAULT_CIRCUIT_METRIC) {
1115 vty_out(vty, " isis metric %d\n",
1116 circuit->te_metric[0]);
1117 write++;
1118 }
1119 } else {
1120 for (i = 0; i < 2; i++) {
1121 if (circuit->te_metric[i]
1122 != DEFAULT_CIRCUIT_METRIC) {
1123 vty_out(vty,
1124 " isis metric %d level-%d\n",
1125 circuit->te_metric[i],
1126 i + 1);
1127 write++;
1128 }
1129 }
1130 }
1131 if (circuit->passwd.type == ISIS_PASSWD_TYPE_HMAC_MD5) {
1132 vty_out(vty, " isis password md5 %s\n",
1133 circuit->passwd.passwd);
1134 write++;
1135 } else if (circuit->passwd.type
1136 == ISIS_PASSWD_TYPE_CLEARTXT) {
1137 vty_out(vty, " isis password clear %s\n",
1138 circuit->passwd.passwd);
1139 write++;
1140 }
1141 write += circuit_write_mt_settings(circuit, vty);
1142 }
a8b828f3 1143 vty_endframe(vty, "!\n");
d62a17ae 1144 }
1145
1146 return write;
eb5d44eb 1147}
eb5d44eb 1148
d62a17ae 1149struct isis_circuit *isis_circuit_create(struct isis_area *area,
1150 struct interface *ifp)
eb5d44eb 1151{
d62a17ae 1152 struct isis_circuit *circuit = circuit_scan_by_ifp(ifp);
1153 if (circuit && circuit->area)
1154 return NULL;
1155 circuit = isis_csm_state_change(ISIS_ENABLE, circuit, area);
1156 if (circuit->state != C_STATE_CONF && circuit->state != C_STATE_UP)
1157 return circuit;
1158 isis_circuit_if_bind(circuit, ifp);
1159 return circuit;
eb5d44eb 1160}
1161
d62a17ae 1162void isis_circuit_af_set(struct isis_circuit *circuit, bool ip_router,
1163 bool ipv6_router)
eb5d44eb 1164{
d62a17ae 1165 struct isis_area *area = circuit->area;
1166 bool change = circuit->ip_router != ip_router
1167 || circuit->ipv6_router != ipv6_router;
1168 bool was_enabled = !!circuit->area;
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);
1182 else if (!was_enabled)
1183 isis_csm_state_change(ISIS_ENABLE, circuit, area);
1184 else
1185 lsp_regenerate_schedule(circuit->area, circuit->is_type, 0);
3f045a08 1186}
eb5d44eb 1187
64dd3ffe 1188ferr_r isis_circuit_passive_set(struct isis_circuit *circuit, bool passive)
3f045a08 1189{
d62a17ae 1190 if (circuit->is_passive == passive)
64dd3ffe 1191 return ferr_ok();
d62a17ae 1192
1193 if (if_is_loopback(circuit->interface) && !passive)
64dd3ffe 1194 return ferr_cfg_invalid("loopback is always passive");
d62a17ae 1195
1196 if (circuit->state != C_STATE_UP) {
1197 circuit->is_passive = passive;
1198 } else {
1199 struct isis_area *area = circuit->area;
1200 isis_csm_state_change(ISIS_DISABLE, circuit, area);
1201 circuit->is_passive = passive;
1202 isis_csm_state_change(ISIS_ENABLE, circuit, area);
1203 }
1204
64dd3ffe 1205 return ferr_ok();
eb5d44eb 1206}
1207
64dd3ffe
DL
1208ferr_r isis_circuit_metric_set(struct isis_circuit *circuit, int level,
1209 int metric)
3f045a08 1210{
d62a17ae 1211 assert(level == IS_LEVEL_1 || level == IS_LEVEL_2);
1212 if (metric > MAX_WIDE_LINK_METRIC)
64dd3ffe
DL
1213 return ferr_cfg_invalid("metric %d too large for wide metric",
1214 metric);
d62a17ae 1215 if (circuit->area && circuit->area->oldmetric
1216 && metric > MAX_NARROW_LINK_METRIC)
64dd3ffe
DL
1217 return ferr_cfg_invalid("metric %d too large for narrow metric",
1218 metric);
d62a17ae 1219
1220 circuit->te_metric[level - 1] = metric;
1221 circuit->metric[level - 1] = metric;
1222
1223 if (circuit->area)
1224 lsp_regenerate_schedule(circuit->area, level, 0);
64dd3ffe 1225 return ferr_ok();
eb5d44eb 1226}
1227
64dd3ffe 1228ferr_r isis_circuit_passwd_unset(struct isis_circuit *circuit)
eb5d44eb 1229{
d62a17ae 1230 memset(&circuit->passwd, 0, sizeof(circuit->passwd));
64dd3ffe 1231 return ferr_ok();
3f045a08
JB
1232}
1233
d62a17ae 1234static int isis_circuit_passwd_set(struct isis_circuit *circuit,
1235 u_char passwd_type, const char *passwd)
3f045a08 1236{
d62a17ae 1237 int len;
f390d2c7 1238
d62a17ae 1239 if (!passwd)
64dd3ffe 1240 return ferr_code_bug("no circuit password given");
50c7d14a 1241
d62a17ae 1242 len = strlen(passwd);
1243 if (len > 254)
64dd3ffe
DL
1244 return ferr_code_bug(
1245 "circuit password too long (max 254 chars)");
f390d2c7 1246
d62a17ae 1247 circuit->passwd.len = len;
1248 strncpy((char *)circuit->passwd.passwd, passwd, 255);
1249 circuit->passwd.type = passwd_type;
64dd3ffe 1250 return ferr_ok();
eb5d44eb 1251}
1252
64dd3ffe
DL
1253ferr_r isis_circuit_passwd_cleartext_set(struct isis_circuit *circuit,
1254 const char *passwd)
eb5d44eb 1255{
d62a17ae 1256 return isis_circuit_passwd_set(circuit, ISIS_PASSWD_TYPE_CLEARTXT,
1257 passwd);
50c7d14a 1258}
f390d2c7 1259
64dd3ffe
DL
1260ferr_r isis_circuit_passwd_hmac_md5_set(struct isis_circuit *circuit,
1261 const char *passwd)
50c7d14a 1262{
d62a17ae 1263 return isis_circuit_passwd_set(circuit, ISIS_PASSWD_TYPE_HMAC_MD5,
1264 passwd);
eb5d44eb 1265}
64dd3ffe 1266
3f045a08 1267struct cmd_node interface_node = {
9d303b37 1268 INTERFACE_NODE, "%s(config-if)# ", 1,
eb5d44eb 1269};
1270
64dd3ffe 1271ferr_r isis_circuit_circ_type_set(struct isis_circuit *circuit, int circ_type)
3f045a08 1272{
64dd3ffe
DL
1273 if (circuit->circ_type == circ_type)
1274 return ferr_ok();
1275
d62a17ae 1276 /* Changing the network type to/of loopback or unknown interfaces
1277 * is not supported. */
1278 if (circ_type == CIRCUIT_T_UNKNOWN || circ_type == CIRCUIT_T_LOOPBACK
1279 || circuit->circ_type == CIRCUIT_T_LOOPBACK) {
64dd3ffe
DL
1280 return ferr_cfg_invalid(
1281 "cannot change network type on unknown interface");
d62a17ae 1282 }
1283
d62a17ae 1284 if (circuit->state != C_STATE_UP) {
1285 circuit->circ_type = circ_type;
1286 circuit->circ_type_config = circ_type;
1287 } else {
1288 struct isis_area *area = circuit->area;
1289 if (circ_type == CIRCUIT_T_BROADCAST
1290 && !if_is_broadcast(circuit->interface))
64dd3ffe
DL
1291 return ferr_cfg_reality(
1292 "cannot configure non-broadcast interface for broadcast operation");
d62a17ae 1293
1294 isis_csm_state_change(ISIS_DISABLE, circuit, area);
1295 circuit->circ_type = circ_type;
1296 circuit->circ_type_config = circ_type;
1297 isis_csm_state_change(ISIS_ENABLE, circuit, area);
1298 }
64dd3ffe 1299 return ferr_ok();
3f045a08
JB
1300}
1301
d62a17ae 1302int isis_circuit_mt_enabled_set(struct isis_circuit *circuit, uint16_t mtid,
1303 bool enabled)
064f4896 1304{
d62a17ae 1305 struct isis_circuit_mt_setting *setting;
064f4896 1306
d62a17ae 1307 setting = circuit_get_mt_setting(circuit, mtid);
1308 if (setting->enabled != enabled) {
1309 setting->enabled = enabled;
1310 lsp_regenerate_schedule(circuit->area, IS_LEVEL_1 | IS_LEVEL_2,
1311 0);
1312 }
064f4896 1313
d62a17ae 1314 return CMD_SUCCESS;
064f4896
CF
1315}
1316
d62a17ae 1317int isis_if_new_hook(struct interface *ifp)
eb5d44eb 1318{
d62a17ae 1319 return 0;
eb5d44eb 1320}
1321
d62a17ae 1322int isis_if_delete_hook(struct interface *ifp)
eb5d44eb 1323{
d62a17ae 1324 struct isis_circuit *circuit;
1325 /* Clean up the circuit data */
1326 if (ifp && ifp->info) {
1327 circuit = ifp->info;
1328 isis_csm_state_change(IF_DOWN_FROM_Z, circuit, circuit->area);
1329 isis_csm_state_change(ISIS_DISABLE, circuit, circuit->area);
1330 }
1331
1332 return 0;
eb5d44eb 1333}
1334
d62a17ae 1335void isis_circuit_init()
eb5d44eb 1336{
d62a17ae 1337 /* Initialize Zebra interface data structure */
ce19a04a
DL
1338 hook_register_prio(if_add, 0, isis_if_new_hook);
1339 hook_register_prio(if_del, 0, isis_if_delete_hook);
eb5d44eb 1340
d62a17ae 1341 /* Install interface node */
1342 install_node(&interface_node, isis_interface_config_write);
1343 if_cmd_init();
eb5d44eb 1344
d62a17ae 1345 isis_vty_init();
eb5d44eb 1346}
58e16237
CF
1347
1348void isis_circuit_schedule_lsp_send(struct isis_circuit *circuit)
1349{
1350 if (circuit->t_send_lsp)
1351 return;
1352 circuit->t_send_lsp = thread_add_event(master, send_lsp, circuit, 0, NULL);
1353}
1354
1355void isis_circuit_queue_lsp(struct isis_circuit *circuit, struct isis_lsp *lsp)
1356{
1357 if (isis_lsp_hash_lookup(circuit->lsp_hash, lsp))
1358 return;
1359
1360 listnode_add(circuit->lsp_queue, lsp);
1361 isis_lsp_hash_add(circuit->lsp_hash, lsp);
1362 isis_circuit_schedule_lsp_send(circuit);
1363}
1364
1365void isis_circuit_lsp_queue_clean(struct isis_circuit *circuit)
1366{
1367 if (!circuit->lsp_queue)
1368 return;
1369
1370 list_delete_all_node(circuit->lsp_queue);
1371 isis_lsp_hash_clean(circuit->lsp_hash);
1372}
1373
1374void isis_circuit_cancel_queued_lsp(struct isis_circuit *circuit,
1375 struct isis_lsp *lsp)
1376{
1377 if (!circuit->lsp_queue)
1378 return;
1379
1380 listnode_delete(circuit->lsp_queue, lsp);
1381 isis_lsp_hash_release(circuit->lsp_hash, lsp);
1382}
1383
1384struct isis_lsp *isis_circuit_lsp_queue_pop(struct isis_circuit *circuit)
1385{
1386 if (!circuit->lsp_queue)
1387 return NULL;
1388
1389 struct listnode *node = listhead(circuit->lsp_queue);
1390 if (!node)
1391 return NULL;
1392
1393 struct isis_lsp *rv = listgetdata(node);
1394
1395 list_delete_node(circuit->lsp_queue, node);
1396 isis_lsp_hash_release(circuit->lsp_hash, rv);
1397
1398 return rv;
1399}