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