]> git.proxmox.com Git - mirror_frr.git/blame - isisd/isis_circuit.c
isisd: Add level&circuit thread argument to circuit
[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"
54ece698 59#include "isisd/isis_errors.h"
9b39405f 60#include "isisd/isis_tx_queue.h"
eb5d44eb 61
676a4ea3
DL
62DEFINE_QOBJ_TYPE(isis_circuit)
63
41b36e90
PJ
64/*
65 * Prototypes.
66 */
41b36e90
PJ
67int isis_interface_config_write(struct vty *);
68int isis_if_new_hook(struct interface *);
69int isis_if_delete_hook(struct interface *);
70
d62a17ae 71struct isis_circuit *isis_circuit_new()
eb5d44eb 72{
d62a17ae 73 struct isis_circuit *circuit;
74 int i;
75
76 circuit = XCALLOC(MTYPE_ISIS_CIRCUIT, sizeof(struct isis_circuit));
d62a17ae 77
78 /*
79 * Default values
80 */
81 circuit->is_type = IS_LEVEL_1_AND_2;
82 circuit->flags = 0;
83 circuit->pad_hellos = 1;
84 for (i = 0; i < 2; i++) {
85 circuit->hello_interval[i] = DEFAULT_HELLO_INTERVAL;
86 circuit->hello_multiplier[i] = DEFAULT_HELLO_MULTIPLIER;
87 circuit->csnp_interval[i] = DEFAULT_CSNP_INTERVAL;
88 circuit->psnp_interval[i] = DEFAULT_PSNP_INTERVAL;
89 circuit->priority[i] = DEFAULT_PRIORITY;
90 circuit->metric[i] = DEFAULT_CIRCUIT_METRIC;
91 circuit->te_metric[i] = DEFAULT_CIRCUIT_METRIC;
7da4aa3c
CF
92 circuit->level_arg[i].level = i + 1;
93 circuit->level_arg[i].circuit = circuit;
d62a17ae 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) {
d7c0a89a 211 uint32_t addr = connected->address->u.prefix4.s_addr;
d62a17ae 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));
c59f88c8
CF
236 zlog_debug("Added IP address %s to circuit %s", buf,
237 circuit->interface->name);
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));
c59f88c8
CF
267 zlog_debug("Added IPv6 address %s to circuit %s", buf,
268 circuit->interface->name);
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);
d0a6f3e0 295 prefix_ipv4_free(ip);
d62a17ae 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(
c59f88c8
CF
302 "Nonexistent ip address %s removal attempt from \
303 circuit %s",
304 buf, circuit->interface->name);
d62a17ae 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);
d0a6f3e0 331 prefix_ipv6_free(ip6);
d62a17ae 332 found = 1;
333 }
334 } else {
335 for (ALL_LIST_ELEMENTS_RO(circuit->ipv6_non_link, node,
336 ip6)) {
337 if (prefix_same((struct prefix *)ip6,
338 (struct prefix *)ipv6))
339 break;
340 }
341 if (ip6) {
342 listnode_delete(circuit->ipv6_non_link, ip6);
d0a6f3e0 343 prefix_ipv6_free(ip6);
d62a17ae 344 found = 1;
345 }
346 }
347
348 if (!found) {
349 prefix2str(connected->address, buf, sizeof(buf));
350 zlog_warn(
c59f88c8
CF
351 "Nonexistent ip address %s removal attempt from \
352 circuit %s",
353 buf, circuit->interface->name);
d62a17ae 354 zlog_warn("Current ip addresses on %s:",
355 circuit->interface->name);
356 for (ALL_LIST_ELEMENTS_RO(circuit->ipv6_link, node,
357 ip6)) {
358 prefix2str((struct prefix *)ip6, (char *)buf,
c28135f3 359 sizeof(buf));
d62a17ae 360 zlog_warn(" %s", buf);
361 }
362 zlog_warn(" -----");
363 for (ALL_LIST_ELEMENTS_RO(circuit->ipv6_non_link, node,
364 ip6)) {
365 prefix2str((struct prefix *)ip6, (char *)buf,
c28135f3 366 sizeof(buf));
d62a17ae 367 zlog_warn(" %s", buf);
368 }
369 zlog_warn("End of addresses");
370 } else if (circuit->area)
371 lsp_regenerate_schedule(circuit->area, circuit->is_type,
372 0);
373
374 prefix_ipv6_free(ipv6);
f891f443 375 }
d62a17ae 376 return;
377}
e8aca32f 378
0849c75e 379static uint8_t isis_circuit_id_gen(struct isis *isis, struct interface *ifp)
d62a17ae 380{
068c8222
CF
381 /* Circuit ids MUST be unique for any broadcast circuits. Otherwise,
382 * Pseudo-Node LSPs cannot be generated correctly.
383 *
98c5bc15 384 * Currently, allocate one circuit ID for any circuit, limiting the total
068c8222
CF
385 * numer of circuits IS-IS can run on to 255.
386 *
98c5bc15 387 * We should revisit this when implementing 3-way adjacencies for p2p, since
068c8222
CF
388 * we then have extended interface IDs available.
389 */
390 uint8_t id = ifp->ifindex;
d62a17ae 391 unsigned int i;
d62a17ae 392
068c8222
CF
393 for (i = 0; i < 256; i++) {
394 if (id && !_ISIS_CHECK_FLAG(isis->circuit_ids_used, id))
d62a17ae 395 break;
068c8222 396 id++;
f891f443 397 }
398
068c8222 399 if (i == 256) {
996c9314
LB
400 zlog_warn("Could not allocate a circuit id for '%s'",
401 ifp->name);
068c8222 402 return 0;
f891f443 403 }
e8aca32f 404
0849c75e 405 _ISIS_SET_FLAG(isis->circuit_ids_used, id);
d62a17ae 406 return id;
3f045a08
JB
407}
408
d62a17ae 409void isis_circuit_if_add(struct isis_circuit *circuit, struct interface *ifp)
eb5d44eb 410{
d62a17ae 411 struct listnode *node, *nnode;
412 struct connected *conn;
413
d62a17ae 414 isis_circuit_if_bind(circuit, ifp);
d62a17ae 415
416 if (if_is_broadcast(ifp)) {
65f18157 417 if (fabricd || circuit->circ_type_config == CIRCUIT_T_P2P)
d62a17ae 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);
eb5d44eb 439}
440
d62a17ae 441void isis_circuit_if_del(struct isis_circuit *circuit, struct interface *ifp)
eb5d44eb 442{
d62a17ae 443 struct listnode *node, *nnode;
444 struct connected *conn;
445
446 assert(circuit->interface == ifp);
447
448 /* destroy addresses */
449 for (ALL_LIST_ELEMENTS(ifp->connected, node, nnode, conn))
450 isis_circuit_del_addr(circuit, conn);
451
452 if (circuit->ip_addrs) {
453 assert(listcount(circuit->ip_addrs) == 0);
6a154c88 454 list_delete(&circuit->ip_addrs);
d62a17ae 455 }
456
457 if (circuit->ipv6_link) {
458 assert(listcount(circuit->ipv6_link) == 0);
6a154c88 459 list_delete(&circuit->ipv6_link);
d62a17ae 460 }
461
462 if (circuit->ipv6_non_link) {
463 assert(listcount(circuit->ipv6_non_link) == 0);
6a154c88 464 list_delete(&circuit->ipv6_non_link);
d62a17ae 465 }
466
467 circuit->circ_type = CIRCUIT_T_UNKNOWN;
eb5d44eb 468}
469
d62a17ae 470void isis_circuit_if_bind(struct isis_circuit *circuit, struct interface *ifp)
3f045a08 471{
d62a17ae 472 assert(circuit != NULL);
473 assert(ifp != NULL);
474 if (circuit->interface)
475 assert(circuit->interface == ifp);
476 else
477 circuit->interface = ifp;
478 if (ifp->info)
479 assert(ifp->info == circuit);
480 else
481 ifp->info = circuit;
482 isis_link_params_update(circuit, ifp);
3f045a08
JB
483}
484
d62a17ae 485void isis_circuit_if_unbind(struct isis_circuit *circuit, struct interface *ifp)
eb5d44eb 486{
d62a17ae 487 assert(circuit != NULL);
488 assert(ifp != NULL);
489 assert(circuit->interface == ifp);
490 assert(ifp->info == circuit);
491 circuit->interface = NULL;
492 ifp->info = NULL;
3f045a08 493}
f390d2c7 494
d62a17ae 495static void isis_circuit_update_all_srmflags(struct isis_circuit *circuit,
496 int is_set)
3f045a08 497{
d62a17ae 498 struct isis_area *area;
499 struct isis_lsp *lsp;
9b39405f 500 dnode_t *dnode;
d62a17ae 501 int level;
502
503 assert(circuit);
504 area = circuit->area;
505 assert(area);
506 for (level = ISIS_LEVEL1; level <= ISIS_LEVEL2; level++) {
9b39405f
CF
507 if (!(level & circuit->is_type))
508 continue;
509
510 if (!area->lspdb[level - 1]
511 || !dict_count(area->lspdb[level - 1]))
512 continue;
513
514 for (dnode = dict_first(area->lspdb[level - 1]);
515 dnode != NULL;
516 dnode = dict_next(area->lspdb[level - 1], dnode)) {
517 lsp = dnode_get(dnode);
518 if (is_set) {
519 isis_tx_queue_add(circuit->tx_queue, lsp,
520 TX_LSP_NORMAL);
521 } else {
522 isis_tx_queue_del(circuit->tx_queue, lsp);
d62a17ae 523 }
524 }
525 }
eb5d44eb 526}
527
d62a17ae 528size_t isis_circuit_pdu_size(struct isis_circuit *circuit)
b20ccb3a 529{
d62a17ae 530 return ISO_MTU(circuit);
b20ccb3a
CF
531}
532
d62a17ae 533void isis_circuit_stream(struct isis_circuit *circuit, struct stream **stream)
b20ccb3a 534{
d62a17ae 535 size_t stream_size = isis_circuit_pdu_size(circuit);
536
537 if (!*stream) {
538 *stream = stream_new(stream_size);
539 } else {
540 if (STREAM_SIZE(*stream) != stream_size)
db3c830a 541 stream_resize_inplace(stream, stream_size);
d62a17ae 542 stream_reset(*stream);
543 }
b20ccb3a
CF
544}
545
d62a17ae 546void isis_circuit_prepare(struct isis_circuit *circuit)
5904f19f 547{
b0dd98e7 548#if ISIS_METHOD != ISIS_METHOD_DLPI
d62a17ae 549 thread_add_read(master, isis_receive, circuit, circuit->fd,
550 &circuit->t_read);
5904f19f 551#else
d62a17ae 552 thread_add_timer_msec(master, isis_receive, circuit,
553 listcount(circuit->area->circuit_list) * 100,
554 &circuit->t_read);
5904f19f
RW
555#endif
556}
557
d62a17ae 558int isis_circuit_up(struct isis_circuit *circuit)
eb5d44eb 559{
d62a17ae 560 int retv;
561
562 /* Set the flags for all the lsps of the circuit. */
563 isis_circuit_update_all_srmflags(circuit, 1);
564
565 if (circuit->state == C_STATE_UP)
566 return ISIS_OK;
567
568 if (circuit->is_passive)
569 return ISIS_OK;
570
571 if (circuit->area->lsp_mtu > isis_circuit_pdu_size(circuit)) {
af4c2728 572 flog_err(
1a7ecb96 573 EC_ISIS_CONFIG,
d62a17ae 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) {
af4c2728 584 flog_err(
1a7ecb96 585 EC_ISIS_CONFIG,
54ece698 586 "There are already 255 broadcast circuits active!");
0849c75e
CF
587 return ISIS_ERROR;
588 }
589
d62a17ae 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]);
d4670f51 643 } else if (circuit->circ_type == CIRCUIT_T_P2P) {
d62a17ae 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
9b39405f 677 circuit->tx_queue = isis_tx_queue_new(circuit, send_lsp);
d62a17ae 678
679 return ISIS_OK;
eb5d44eb 680}
681
d62a17ae 682void isis_circuit_down(struct isis_circuit *circuit)
eb5d44eb 683{
d62a17ae 684 /* Clear the flags for all the lsps of the circuit. */
685 isis_circuit_update_all_srmflags(circuit, 0);
686
687 if (circuit->circ_type == CIRCUIT_T_BROADCAST) {
688 /* destroy neighbour lists */
689 if (circuit->u.bc.lan_neighs[0]) {
6a154c88 690 list_delete(&circuit->u.bc.lan_neighs[0]);
d62a17ae 691 circuit->u.bc.lan_neighs[0] = NULL;
692 }
693 if (circuit->u.bc.lan_neighs[1]) {
6a154c88 694 list_delete(&circuit->u.bc.lan_neighs[1]);
d62a17ae 695 circuit->u.bc.lan_neighs[1] = NULL;
696 }
697 /* destroy adjacency databases */
698 if (circuit->u.bc.adjdb[0]) {
699 circuit->u.bc.adjdb[0]->del = isis_delete_adj;
6a154c88 700 list_delete(&circuit->u.bc.adjdb[0]);
d62a17ae 701 circuit->u.bc.adjdb[0] = NULL;
702 }
703 if (circuit->u.bc.adjdb[1]) {
704 circuit->u.bc.adjdb[1]->del = isis_delete_adj;
6a154c88 705 list_delete(&circuit->u.bc.adjdb[1]);
d62a17ae 706 circuit->u.bc.adjdb[1] = NULL;
707 }
708 if (circuit->u.bc.is_dr[0]) {
709 isis_dr_resign(circuit, 1);
710 circuit->u.bc.is_dr[0] = 0;
711 }
712 memset(circuit->u.bc.l1_desig_is, 0, ISIS_SYS_ID_LEN + 1);
713 if (circuit->u.bc.is_dr[1]) {
714 isis_dr_resign(circuit, 2);
715 circuit->u.bc.is_dr[1] = 0;
716 }
717 memset(circuit->u.bc.l2_desig_is, 0, ISIS_SYS_ID_LEN + 1);
718 memset(circuit->u.bc.snpa, 0, ETH_ALEN);
719
720 THREAD_TIMER_OFF(circuit->u.bc.t_send_lan_hello[0]);
721 THREAD_TIMER_OFF(circuit->u.bc.t_send_lan_hello[1]);
722 THREAD_TIMER_OFF(circuit->u.bc.t_run_dr[0]);
723 THREAD_TIMER_OFF(circuit->u.bc.t_run_dr[1]);
724 THREAD_TIMER_OFF(circuit->u.bc.t_refresh_pseudo_lsp[0]);
725 THREAD_TIMER_OFF(circuit->u.bc.t_refresh_pseudo_lsp[1]);
726 circuit->lsp_regenerate_pending[0] = 0;
727 circuit->lsp_regenerate_pending[1] = 0;
0849c75e
CF
728
729 _ISIS_CLEAR_FLAG(isis->circuit_ids_used, circuit->circuit_id);
730 circuit->circuit_id = 0;
d62a17ae 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]);
58e16237 742 THREAD_OFF(circuit->t_send_lsp);
d62a17ae 743 THREAD_OFF(circuit->t_read);
744
9b39405f
CF
745 if (circuit->tx_queue) {
746 isis_tx_queue_free(circuit->tx_queue);
747 circuit->tx_queue = NULL;
58e16237
CF
748 }
749
d62a17ae 750 /* send one gratuitous hello to spead up convergence */
d4670f51
CF
751 if (circuit->state == C_STATE_UP) {
752 if (circuit->is_type & IS_LEVEL_1)
753 send_hello(circuit, IS_LEVEL_1);
754 if (circuit->is_type & IS_LEVEL_2)
755 send_hello(circuit, IS_LEVEL_2);
756 }
d62a17ae 757
758 circuit->upadjcount[0] = 0;
759 circuit->upadjcount[1] = 0;
760
761 /* close the socket */
762 if (circuit->fd) {
763 close(circuit->fd);
764 circuit->fd = 0;
765 }
766
767 if (circuit->rcv_stream != NULL) {
768 stream_free(circuit->rcv_stream);
769 circuit->rcv_stream = NULL;
770 }
771
772 if (circuit->snd_stream != NULL) {
773 stream_free(circuit->snd_stream);
774 circuit->snd_stream = NULL;
775 }
776
777 thread_cancel_event(master, circuit);
778
779 return;
eb5d44eb 780}
781
d62a17ae 782void circuit_update_nlpids(struct isis_circuit *circuit)
eb5d44eb 783{
d62a17ae 784 circuit->nlpids.count = 0;
785
786 if (circuit->ip_router) {
787 circuit->nlpids.nlpids[0] = NLPID_IP;
788 circuit->nlpids.count++;
789 }
790 if (circuit->ipv6_router) {
791 circuit->nlpids.nlpids[circuit->nlpids.count] = NLPID_IPV6;
792 circuit->nlpids.count++;
793 }
794 return;
eb5d44eb 795}
796
d62a17ae 797void isis_circuit_print_vty(struct isis_circuit *circuit, struct vty *vty,
798 char detail)
3f045a08 799{
d62a17ae 800 if (detail == ISIS_UI_LEVEL_BRIEF) {
801 vty_out(vty, " %-12s", circuit->interface->name);
802 vty_out(vty, "0x%-7x", circuit->circuit_id);
803 vty_out(vty, "%-9s", circuit_state2string(circuit->state));
804 vty_out(vty, "%-9s", circuit_type2string(circuit->circ_type));
805 vty_out(vty, "%-9s", circuit_t2string(circuit->is_type));
806 vty_out(vty, "\n");
807 }
808
809 if (detail == ISIS_UI_LEVEL_DETAIL) {
810 struct listnode *node;
811 struct prefix *ip_addr;
812 char buf[BUFSIZ];
813
814 vty_out(vty, " Interface: %s", circuit->interface->name);
815 vty_out(vty, ", State: %s",
816 circuit_state2string(circuit->state));
817 if (circuit->is_passive)
818 vty_out(vty, ", Passive");
819 else
820 vty_out(vty, ", Active");
821 vty_out(vty, ", Circuit Id: 0x%x", circuit->circuit_id);
822 vty_out(vty, "\n");
823 vty_out(vty, " Type: %s",
824 circuit_type2string(circuit->circ_type));
825 vty_out(vty, ", Level: %s", circuit_t2string(circuit->is_type));
826 if (circuit->circ_type == CIRCUIT_T_BROADCAST)
827 vty_out(vty, ", SNPA: %-10s",
828 snpa_print(circuit->u.bc.snpa));
829 vty_out(vty, "\n");
830 if (circuit->is_type & IS_LEVEL_1) {
831 vty_out(vty, " Level-1 Information:\n");
832 if (circuit->area->newmetric)
833 vty_out(vty, " Metric: %d",
834 circuit->te_metric[0]);
835 else
836 vty_out(vty, " Metric: %d",
837 circuit->metric[0]);
838 if (!circuit->is_passive) {
839 vty_out(vty, ", Active neighbors: %u\n",
840 circuit->upadjcount[0]);
841 vty_out(vty,
842 " Hello interval: %u, "
843 "Holddown count: %u %s\n",
844 circuit->hello_interval[0],
845 circuit->hello_multiplier[0],
846 (circuit->pad_hellos ? "(pad)"
847 : "(no-pad)"));
848 vty_out(vty,
849 " CNSP interval: %u, "
850 "PSNP interval: %u\n",
851 circuit->csnp_interval[0],
852 circuit->psnp_interval[0]);
853 if (circuit->circ_type == CIRCUIT_T_BROADCAST)
854 vty_out(vty,
855 " LAN Priority: %u, %s\n",
856 circuit->priority[0],
857 (circuit->u.bc.is_dr[0]
858 ? "is DIS"
859 : "is not DIS"));
860 } else {
861 vty_out(vty, "\n");
862 }
863 }
864 if (circuit->is_type & IS_LEVEL_2) {
865 vty_out(vty, " Level-2 Information:\n");
866 if (circuit->area->newmetric)
867 vty_out(vty, " Metric: %d",
868 circuit->te_metric[1]);
869 else
870 vty_out(vty, " Metric: %d",
871 circuit->metric[1]);
872 if (!circuit->is_passive) {
873 vty_out(vty, ", Active neighbors: %u\n",
874 circuit->upadjcount[1]);
875 vty_out(vty,
876 " Hello interval: %u, "
877 "Holddown count: %u %s\n",
878 circuit->hello_interval[1],
879 circuit->hello_multiplier[1],
880 (circuit->pad_hellos ? "(pad)"
881 : "(no-pad)"));
882 vty_out(vty,
883 " CNSP interval: %u, "
884 "PSNP interval: %u\n",
885 circuit->csnp_interval[1],
886 circuit->psnp_interval[1]);
887 if (circuit->circ_type == CIRCUIT_T_BROADCAST)
888 vty_out(vty,
889 " LAN Priority: %u, %s\n",
890 circuit->priority[1],
891 (circuit->u.bc.is_dr[1]
892 ? "is DIS"
893 : "is not DIS"));
894 } else {
895 vty_out(vty, "\n");
896 }
897 }
898 if (circuit->ip_addrs && listcount(circuit->ip_addrs) > 0) {
899 vty_out(vty, " IP Prefix(es):\n");
900 for (ALL_LIST_ELEMENTS_RO(circuit->ip_addrs, node,
901 ip_addr)) {
1445b43c
A
902 prefix2str(ip_addr, buf, sizeof(buf));
903 vty_out(vty, " %s\n", buf);
d62a17ae 904 }
905 }
906 if (circuit->ipv6_link && listcount(circuit->ipv6_link) > 0) {
907 vty_out(vty, " IPv6 Link-Locals:\n");
908 for (ALL_LIST_ELEMENTS_RO(circuit->ipv6_link, node,
909 ip_addr)) {
1445b43c
A
910 prefix2str(ip_addr, (char *)buf, BUFSIZ);
911 vty_out(vty, " %s\n", buf);
d62a17ae 912 }
913 }
914 if (circuit->ipv6_non_link
915 && listcount(circuit->ipv6_non_link) > 0) {
916 vty_out(vty, " IPv6 Prefixes:\n");
917 for (ALL_LIST_ELEMENTS_RO(circuit->ipv6_non_link, node,
918 ip_addr)) {
1445b43c
A
919 prefix2str(ip_addr, (char *)buf, BUFSIZ);
920 vty_out(vty, " %s\n", buf);
d62a17ae 921 }
922 }
923
924 vty_out(vty, "\n");
925 }
926 return;
3f045a08
JB
927}
928
d56afe53
CF
929DEFINE_HOOK(isis_circuit_config_write,
930 (struct isis_circuit *circuit, struct vty *vty),
931 (circuit, vty))
932
d62a17ae 933int isis_interface_config_write(struct vty *vty)
eb5d44eb 934{
f4e14fdb 935 struct vrf *vrf = vrf_lookup_by_id(VRF_DEFAULT);
d62a17ae 936 int write = 0;
f4e14fdb 937 struct listnode *node;
d62a17ae 938 struct interface *ifp;
939 struct isis_area *area;
940 struct isis_circuit *circuit;
941 int i;
942
451fda4f 943 FOR_ALL_INTERFACES (vrf, ifp) {
d62a17ae 944 /* IF name */
a8b828f3 945 vty_frame(vty, "interface %s\n", ifp->name);
d62a17ae 946 write++;
947 /* IF desc */
948 if (ifp->desc) {
949 vty_out(vty, " description %s\n", ifp->desc);
950 write++;
951 }
952 /* ISIS Circuit */
f4e14fdb 953 for (ALL_LIST_ELEMENTS_RO(isis->area_list, node, area)) {
d62a17ae 954 circuit =
955 circuit_lookup_by_ifp(ifp, area->circuit_list);
956 if (circuit == NULL)
957 continue;
958 if (circuit->ip_router) {
7c0cbd0e 959 vty_out(vty, " ip router " PROTO_NAME " %s\n",
d62a17ae 960 area->area_tag);
961 write++;
962 }
963 if (circuit->is_passive) {
7c0cbd0e 964 vty_out(vty, " " PROTO_NAME " passive\n");
d62a17ae 965 write++;
966 }
967 if (circuit->circ_type_config == CIRCUIT_T_P2P) {
7c0cbd0e 968 vty_out(vty, " " PROTO_NAME " network point-to-point\n");
d62a17ae 969 write++;
970 }
971 if (circuit->ipv6_router) {
7c0cbd0e 972 vty_out(vty, " ipv6 router " PROTO_NAME " %s\n",
d62a17ae 973 area->area_tag);
974 write++;
975 }
976
977 /* ISIS - circuit type */
65f18157
CF
978 if (!fabricd) {
979 if (circuit->is_type == IS_LEVEL_1) {
980 vty_out(vty, " " PROTO_NAME " circuit-type level-1\n");
d62a17ae 981 write++;
65f18157
CF
982 } else {
983 if (circuit->is_type == IS_LEVEL_2) {
984 vty_out(vty,
985 " " PROTO_NAME " circuit-type level-2-only\n");
986 write++;
987 }
d62a17ae 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) {
7c0cbd0e 996 vty_out(vty, " " PROTO_NAME " csnp-interval %d\n",
d62a17ae 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,
7c0cbd0e 1005 " " PROTO_NAME " csnp-interval %d level-%d\n",
d62a17ae 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) {
7c0cbd0e 1019 vty_out(vty, " " PROTO_NAME " psnp-interval %d\n",
d62a17ae 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,
7c0cbd0e 1028 " " PROTO_NAME " psnp-interval %d level-%d\n",
d62a17ae 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) {
7c0cbd0e 1040 vty_out(vty, " no " PROTO_NAME " hello padding\n");
d62a17ae 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,
7c0cbd0e 1055 " " PROTO_NAME " hello-interval %d\n",
d62a17ae 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,
7c0cbd0e 1064 " " PROTO_NAME " hello-interval %d level-%d\n",
d62a17ae 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,
7c0cbd0e 1079 " " PROTO_NAME " hello-multiplier %d\n",
d62a17ae 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,
7c0cbd0e 1088 " " PROTO_NAME " hello-multiplier %d level-%d\n",
d62a17ae 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) {
7c0cbd0e 1100 vty_out(vty, " " PROTO_NAME " priority %d\n",
d62a17ae 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,
7c0cbd0e 1109 " " PROTO_NAME " priority %d level-%d\n",
d62a17ae 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) {
7c0cbd0e 1121 vty_out(vty, " " PROTO_NAME " metric %d\n",
d62a17ae 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,
7c0cbd0e 1130 " " PROTO_NAME " metric %d level-%d\n",
d62a17ae 1131 circuit->te_metric[i],
1132 i + 1);
1133 write++;
1134 }
1135 }
1136 }
1137 if (circuit->passwd.type == ISIS_PASSWD_TYPE_HMAC_MD5) {
7c0cbd0e 1138 vty_out(vty, " " PROTO_NAME " password md5 %s\n",
d62a17ae 1139 circuit->passwd.passwd);
1140 write++;
1141 } else if (circuit->passwd.type
1142 == ISIS_PASSWD_TYPE_CLEARTXT) {
7c0cbd0e 1143 vty_out(vty, " " PROTO_NAME " password clear %s\n",
d62a17ae 1144 circuit->passwd.passwd);
1145 write++;
1146 }
5489eb45
CF
1147 write += hook_call(isis_circuit_config_write,
1148 circuit, vty);
d62a17ae 1149 }
a8b828f3 1150 vty_endframe(vty, "!\n");
d62a17ae 1151 }
1152
1153 return write;
eb5d44eb 1154}
eb5d44eb 1155
d62a17ae 1156struct isis_circuit *isis_circuit_create(struct isis_area *area,
1157 struct interface *ifp)
eb5d44eb 1158{
d62a17ae 1159 struct isis_circuit *circuit = circuit_scan_by_ifp(ifp);
1160 if (circuit && circuit->area)
1161 return NULL;
1162 circuit = isis_csm_state_change(ISIS_ENABLE, circuit, area);
1163 if (circuit->state != C_STATE_CONF && circuit->state != C_STATE_UP)
1164 return circuit;
1165 isis_circuit_if_bind(circuit, ifp);
1166 return circuit;
eb5d44eb 1167}
1168
d62a17ae 1169void isis_circuit_af_set(struct isis_circuit *circuit, bool ip_router,
1170 bool ipv6_router)
eb5d44eb 1171{
d62a17ae 1172 struct isis_area *area = circuit->area;
1173 bool change = circuit->ip_router != ip_router
1174 || circuit->ipv6_router != ipv6_router;
d62a17ae 1175
1176 area->ip_circuits += ip_router - circuit->ip_router;
1177 area->ipv6_circuits += ipv6_router - circuit->ipv6_router;
1178 circuit->ip_router = ip_router;
1179 circuit->ipv6_router = ipv6_router;
1180
1181 if (!change)
1182 return;
1183
1184 circuit_update_nlpids(circuit);
1185
1186 if (!ip_router && !ipv6_router)
1187 isis_csm_state_change(ISIS_DISABLE, circuit, area);
d62a17ae 1188 else
1189 lsp_regenerate_schedule(circuit->area, circuit->is_type, 0);
3f045a08 1190}
eb5d44eb 1191
64dd3ffe 1192ferr_r isis_circuit_passive_set(struct isis_circuit *circuit, bool passive)
3f045a08 1193{
d62a17ae 1194 if (circuit->is_passive == passive)
64dd3ffe 1195 return ferr_ok();
d62a17ae 1196
1197 if (if_is_loopback(circuit->interface) && !passive)
64dd3ffe 1198 return ferr_cfg_invalid("loopback is always passive");
d62a17ae 1199
1200 if (circuit->state != C_STATE_UP) {
1201 circuit->is_passive = passive;
1202 } else {
1203 struct isis_area *area = circuit->area;
1204 isis_csm_state_change(ISIS_DISABLE, circuit, area);
1205 circuit->is_passive = passive;
1206 isis_csm_state_change(ISIS_ENABLE, circuit, area);
1207 }
1208
64dd3ffe 1209 return ferr_ok();
eb5d44eb 1210}
1211
64dd3ffe
DL
1212ferr_r isis_circuit_metric_set(struct isis_circuit *circuit, int level,
1213 int metric)
3f045a08 1214{
d62a17ae 1215 assert(level == IS_LEVEL_1 || level == IS_LEVEL_2);
1216 if (metric > MAX_WIDE_LINK_METRIC)
64dd3ffe
DL
1217 return ferr_cfg_invalid("metric %d too large for wide metric",
1218 metric);
d62a17ae 1219 if (circuit->area && circuit->area->oldmetric
1220 && metric > MAX_NARROW_LINK_METRIC)
64dd3ffe
DL
1221 return ferr_cfg_invalid("metric %d too large for narrow metric",
1222 metric);
d62a17ae 1223
1224 circuit->te_metric[level - 1] = metric;
1225 circuit->metric[level - 1] = metric;
1226
1227 if (circuit->area)
1228 lsp_regenerate_schedule(circuit->area, level, 0);
64dd3ffe 1229 return ferr_ok();
eb5d44eb 1230}
1231
64dd3ffe 1232ferr_r isis_circuit_passwd_unset(struct isis_circuit *circuit)
eb5d44eb 1233{
d62a17ae 1234 memset(&circuit->passwd, 0, sizeof(circuit->passwd));
64dd3ffe 1235 return ferr_ok();
3f045a08
JB
1236}
1237
d62a17ae 1238static int isis_circuit_passwd_set(struct isis_circuit *circuit,
d7c0a89a 1239 uint8_t passwd_type, const char *passwd)
3f045a08 1240{
d62a17ae 1241 int len;
f390d2c7 1242
d62a17ae 1243 if (!passwd)
64dd3ffe 1244 return ferr_code_bug("no circuit password given");
50c7d14a 1245
d62a17ae 1246 len = strlen(passwd);
1247 if (len > 254)
64dd3ffe
DL
1248 return ferr_code_bug(
1249 "circuit password too long (max 254 chars)");
f390d2c7 1250
d62a17ae 1251 circuit->passwd.len = len;
1252 strncpy((char *)circuit->passwd.passwd, passwd, 255);
1253 circuit->passwd.type = passwd_type;
64dd3ffe 1254 return ferr_ok();
eb5d44eb 1255}
1256
64dd3ffe
DL
1257ferr_r isis_circuit_passwd_cleartext_set(struct isis_circuit *circuit,
1258 const char *passwd)
eb5d44eb 1259{
d62a17ae 1260 return isis_circuit_passwd_set(circuit, ISIS_PASSWD_TYPE_CLEARTXT,
1261 passwd);
50c7d14a 1262}
f390d2c7 1263
64dd3ffe
DL
1264ferr_r isis_circuit_passwd_hmac_md5_set(struct isis_circuit *circuit,
1265 const char *passwd)
50c7d14a 1266{
d62a17ae 1267 return isis_circuit_passwd_set(circuit, ISIS_PASSWD_TYPE_HMAC_MD5,
1268 passwd);
eb5d44eb 1269}
64dd3ffe 1270
3f045a08 1271struct cmd_node interface_node = {
9d303b37 1272 INTERFACE_NODE, "%s(config-if)# ", 1,
eb5d44eb 1273};
1274
64dd3ffe 1275ferr_r isis_circuit_circ_type_set(struct isis_circuit *circuit, int circ_type)
3f045a08 1276{
64dd3ffe
DL
1277 if (circuit->circ_type == circ_type)
1278 return ferr_ok();
1279
d62a17ae 1280 /* Changing the network type to/of loopback or unknown interfaces
1281 * is not supported. */
1282 if (circ_type == CIRCUIT_T_UNKNOWN || circ_type == CIRCUIT_T_LOOPBACK
1283 || circuit->circ_type == CIRCUIT_T_LOOPBACK) {
64dd3ffe
DL
1284 return ferr_cfg_invalid(
1285 "cannot change network type on unknown interface");
d62a17ae 1286 }
1287
d62a17ae 1288 if (circuit->state != C_STATE_UP) {
1289 circuit->circ_type = circ_type;
1290 circuit->circ_type_config = circ_type;
1291 } else {
1292 struct isis_area *area = circuit->area;
1293 if (circ_type == CIRCUIT_T_BROADCAST
1294 && !if_is_broadcast(circuit->interface))
64dd3ffe
DL
1295 return ferr_cfg_reality(
1296 "cannot configure non-broadcast interface for broadcast operation");
d62a17ae 1297
1298 isis_csm_state_change(ISIS_DISABLE, circuit, area);
1299 circuit->circ_type = circ_type;
1300 circuit->circ_type_config = circ_type;
1301 isis_csm_state_change(ISIS_ENABLE, circuit, area);
1302 }
64dd3ffe 1303 return ferr_ok();
3f045a08
JB
1304}
1305
d62a17ae 1306int isis_circuit_mt_enabled_set(struct isis_circuit *circuit, uint16_t mtid,
1307 bool enabled)
064f4896 1308{
d62a17ae 1309 struct isis_circuit_mt_setting *setting;
064f4896 1310
d62a17ae 1311 setting = circuit_get_mt_setting(circuit, mtid);
1312 if (setting->enabled != enabled) {
1313 setting->enabled = enabled;
1314 lsp_regenerate_schedule(circuit->area, IS_LEVEL_1 | IS_LEVEL_2,
1315 0);
1316 }
064f4896 1317
d62a17ae 1318 return CMD_SUCCESS;
064f4896
CF
1319}
1320
d62a17ae 1321int isis_if_new_hook(struct interface *ifp)
eb5d44eb 1322{
d62a17ae 1323 return 0;
eb5d44eb 1324}
1325
d62a17ae 1326int isis_if_delete_hook(struct interface *ifp)
eb5d44eb 1327{
d62a17ae 1328 struct isis_circuit *circuit;
1329 /* Clean up the circuit data */
1330 if (ifp && ifp->info) {
1331 circuit = ifp->info;
1332 isis_csm_state_change(IF_DOWN_FROM_Z, circuit, circuit->area);
1333 isis_csm_state_change(ISIS_DISABLE, circuit, circuit->area);
1334 }
1335
1336 return 0;
eb5d44eb 1337}
1338
d62a17ae 1339void isis_circuit_init()
eb5d44eb 1340{
d62a17ae 1341 /* Initialize Zebra interface data structure */
ce19a04a
DL
1342 hook_register_prio(if_add, 0, isis_if_new_hook);
1343 hook_register_prio(if_del, 0, isis_if_delete_hook);
eb5d44eb 1344
d62a17ae 1345 /* Install interface node */
1346 install_node(&interface_node, isis_interface_config_write);
1347 if_cmd_init();
eb5d44eb 1348}