]> git.proxmox.com Git - mirror_frr.git/blame - isisd/isis_circuit.c
fabricd: implement asymmetric metric for tier 0 as per Section 6.2
[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"
54ece698 60#include "isisd/isis_errors.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;
92 }
93
94 circuit->mtc = mpls_te_circuit_new();
95
96 circuit_mt_init(circuit);
97
98 QOBJ_REG(circuit, isis_circuit);
99
100 return circuit;
eb5d44eb 101}
102
d62a17ae 103void isis_circuit_del(struct isis_circuit *circuit)
3f045a08 104{
d62a17ae 105 if (!circuit)
106 return;
3f045a08 107
d62a17ae 108 QOBJ_UNREG(circuit);
676a4ea3 109
d62a17ae 110 isis_circuit_if_unbind(circuit, circuit->interface);
3f045a08 111
d62a17ae 112 circuit_mt_finish(circuit);
064f4896 113
d62a17ae 114 /* and lastly the circuit itself */
115 XFREE(MTYPE_ISIS_CIRCUIT, circuit);
3f045a08 116
d62a17ae 117 return;
3f045a08
JB
118}
119
d62a17ae 120void isis_circuit_configure(struct isis_circuit *circuit,
121 struct isis_area *area)
eb5d44eb 122{
d62a17ae 123 assert(area);
124 circuit->area = area;
125
126 /*
127 * Whenever the is-type of an area is changed, the is-type of each
128 * circuit
129 * in that area is updated to a non-empty subset of the area is-type.
130 * Inversely, when configuring a new circuit, this property should be
131 * ensured as well.
132 */
133 if (area->is_type != IS_LEVEL_1_AND_2)
134 circuit->is_type = area->is_type;
135
136 /*
137 * Add the circuit into area
138 */
139 listnode_add(area->circuit_list, circuit);
140
141 circuit->idx = flags_get_index(&area->flags);
142
143 return;
eb5d44eb 144}
145
d62a17ae 146void isis_circuit_deconfigure(struct isis_circuit *circuit,
147 struct isis_area *area)
eb5d44eb 148{
d62a17ae 149 /* Free the index of SRM and SSN flags */
150 flags_free_index(&area->flags, circuit->idx);
151 circuit->idx = 0;
152 /* Remove circuit from area */
153 assert(circuit->area == area);
154 listnode_delete(area->circuit_list, circuit);
155 circuit->area = NULL;
156
157 return;
eb5d44eb 158}
159
d62a17ae 160struct isis_circuit *circuit_lookup_by_ifp(struct interface *ifp,
161 struct list *list)
eb5d44eb 162{
d62a17ae 163 struct isis_circuit *circuit = NULL;
164 struct listnode *node;
f390d2c7 165
d62a17ae 166 if (!list)
167 return NULL;
f390d2c7 168
d62a17ae 169 for (ALL_LIST_ELEMENTS_RO(list, node, circuit))
170 if (circuit->interface == ifp) {
171 assert(ifp->info == circuit);
172 return circuit;
173 }
3f045a08 174
d62a17ae 175 return NULL;
eb5d44eb 176}
177
d62a17ae 178struct isis_circuit *circuit_scan_by_ifp(struct interface *ifp)
eb5d44eb 179{
d62a17ae 180 struct isis_area *area;
181 struct listnode *node;
182 struct isis_circuit *circuit;
183
184 if (ifp->info)
185 return (struct isis_circuit *)ifp->info;
186
187 if (isis->area_list) {
188 for (ALL_LIST_ELEMENTS_RO(isis->area_list, node, area)) {
189 circuit =
190 circuit_lookup_by_ifp(ifp, area->circuit_list);
191 if (circuit)
192 return circuit;
193 }
194 }
195 return circuit_lookup_by_ifp(ifp, isis->init_circ_list);
eb5d44eb 196}
197
d62a17ae 198void isis_circuit_add_addr(struct isis_circuit *circuit,
199 struct connected *connected)
eb5d44eb 200{
d62a17ae 201 struct listnode *node;
202 struct prefix_ipv4 *ipv4;
4690c7d7 203#if defined(EXTREME_DEBUG)
d62a17ae 204 char buf[PREFIX2STR_BUFFER];
4690c7d7 205#endif
d62a17ae 206 struct prefix_ipv6 *ipv6;
f891f443 207
d62a17ae 208 if (connected->address->family == AF_INET) {
d7c0a89a 209 uint32_t addr = connected->address->u.prefix4.s_addr;
d62a17ae 210 addr = ntohl(addr);
211 if (IPV4_NET0(addr) || IPV4_NET127(addr) || IN_CLASSD(addr)
212 || IPV4_LINKLOCAL(addr))
213 return;
3f045a08 214
d62a17ae 215 for (ALL_LIST_ELEMENTS_RO(circuit->ip_addrs, node, ipv4))
216 if (prefix_same((struct prefix *)ipv4,
217 connected->address))
218 return;
3f045a08 219
d62a17ae 220 ipv4 = prefix_ipv4_new();
221 ipv4->prefixlen = connected->address->prefixlen;
222 ipv4->prefix = connected->address->u.prefix4;
223 listnode_add(circuit->ip_addrs, ipv4);
f8c06e2c 224
d62a17ae 225 /* Update MPLS TE Local IP address parameter */
226 set_circuitparams_local_ipaddr(circuit->mtc, ipv4->prefix);
f8c06e2c 227
d62a17ae 228 if (circuit->area)
229 lsp_regenerate_schedule(circuit->area, circuit->is_type,
230 0);
f891f443 231
eb5d44eb 232#ifdef EXTREME_DEBUG
d62a17ae 233 prefix2str(connected->address, buf, sizeof(buf));
c59f88c8
CF
234 zlog_debug("Added IP address %s to circuit %s", buf,
235 circuit->interface->name);
f390d2c7 236#endif /* EXTREME_DEBUG */
d62a17ae 237 }
238 if (connected->address->family == AF_INET6) {
239 if (IN6_IS_ADDR_LOOPBACK(&connected->address->u.prefix6))
240 return;
241
242 for (ALL_LIST_ELEMENTS_RO(circuit->ipv6_link, node, ipv6))
243 if (prefix_same((struct prefix *)ipv6,
244 connected->address))
245 return;
246 for (ALL_LIST_ELEMENTS_RO(circuit->ipv6_non_link, node, ipv6))
247 if (prefix_same((struct prefix *)ipv6,
248 connected->address))
249 return;
250
251 ipv6 = prefix_ipv6_new();
252 ipv6->prefixlen = connected->address->prefixlen;
253 ipv6->prefix = connected->address->u.prefix6;
254
255 if (IN6_IS_ADDR_LINKLOCAL(&ipv6->prefix))
256 listnode_add(circuit->ipv6_link, ipv6);
257 else
258 listnode_add(circuit->ipv6_non_link, ipv6);
259 if (circuit->area)
260 lsp_regenerate_schedule(circuit->area, circuit->is_type,
261 0);
f891f443 262
eb5d44eb 263#ifdef EXTREME_DEBUG
d62a17ae 264 prefix2str(connected->address, buf, sizeof(buf));
c59f88c8
CF
265 zlog_debug("Added IPv6 address %s to circuit %s", buf,
266 circuit->interface->name);
f390d2c7 267#endif /* EXTREME_DEBUG */
d62a17ae 268 }
269 return;
eb5d44eb 270}
271
d62a17ae 272void isis_circuit_del_addr(struct isis_circuit *circuit,
273 struct connected *connected)
eb5d44eb 274{
d62a17ae 275 struct prefix_ipv4 *ipv4, *ip = NULL;
276 struct listnode *node;
277 char buf[PREFIX2STR_BUFFER];
278 struct prefix_ipv6 *ipv6, *ip6 = NULL;
279 int found = 0;
280
281 if (connected->address->family == AF_INET) {
282 ipv4 = prefix_ipv4_new();
283 ipv4->prefixlen = connected->address->prefixlen;
284 ipv4->prefix = connected->address->u.prefix4;
285
286 for (ALL_LIST_ELEMENTS_RO(circuit->ip_addrs, node, ip))
287 if (prefix_same((struct prefix *)ip,
288 (struct prefix *)ipv4))
289 break;
290
291 if (ip) {
292 listnode_delete(circuit->ip_addrs, ip);
d0a6f3e0 293 prefix_ipv4_free(ip);
d62a17ae 294 if (circuit->area)
295 lsp_regenerate_schedule(circuit->area,
296 circuit->is_type, 0);
297 } else {
298 prefix2str(connected->address, buf, sizeof(buf));
299 zlog_warn(
c59f88c8
CF
300 "Nonexistent ip address %s removal attempt from \
301 circuit %s",
302 buf, circuit->interface->name);
d62a17ae 303 zlog_warn("Current ip addresses on %s:",
304 circuit->interface->name);
305 for (ALL_LIST_ELEMENTS_RO(circuit->ip_addrs, node,
306 ip)) {
307 prefix2str(ip, buf, sizeof(buf));
308 zlog_warn(" %s", buf);
309 }
310 zlog_warn("End of addresses");
311 }
312
313 prefix_ipv4_free(ipv4);
f891f443 314 }
d62a17ae 315 if (connected->address->family == AF_INET6) {
316 ipv6 = prefix_ipv6_new();
317 ipv6->prefixlen = connected->address->prefixlen;
318 ipv6->prefix = connected->address->u.prefix6;
319
320 if (IN6_IS_ADDR_LINKLOCAL(&ipv6->prefix)) {
321 for (ALL_LIST_ELEMENTS_RO(circuit->ipv6_link, node,
322 ip6)) {
323 if (prefix_same((struct prefix *)ip6,
324 (struct prefix *)ipv6))
325 break;
326 }
327 if (ip6) {
328 listnode_delete(circuit->ipv6_link, ip6);
d0a6f3e0 329 prefix_ipv6_free(ip6);
d62a17ae 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);
d0a6f3e0 341 prefix_ipv6_free(ip6);
d62a17ae 342 found = 1;
343 }
344 }
345
346 if (!found) {
347 prefix2str(connected->address, buf, sizeof(buf));
348 zlog_warn(
c59f88c8
CF
349 "Nonexistent ip address %s removal attempt from \
350 circuit %s",
351 buf, circuit->interface->name);
d62a17ae 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,
c28135f3 357 sizeof(buf));
d62a17ae 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,
c28135f3 364 sizeof(buf));
d62a17ae 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
0849c75e 377static uint8_t isis_circuit_id_gen(struct isis *isis, 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 *
98c5bc15 382 * Currently, allocate one circuit ID for any circuit, limiting the total
068c8222
CF
383 * numer of circuits IS-IS can run on to 255.
384 *
98c5bc15 385 * We should revisit this when implementing 3-way adjacencies for p2p, since
068c8222
CF
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 397 if (i == 256) {
996c9314
LB
398 zlog_warn("Could not allocate a circuit id for '%s'",
399 ifp->name);
068c8222 400 return 0;
f891f443 401 }
e8aca32f 402
0849c75e 403 _ISIS_SET_FLAG(isis->circuit_ids_used, id);
d62a17ae 404 return id;
3f045a08
JB
405}
406
d62a17ae 407void isis_circuit_if_add(struct isis_circuit *circuit, struct interface *ifp)
eb5d44eb 408{
d62a17ae 409 struct listnode *node, *nnode;
410 struct connected *conn;
411
d62a17ae 412 isis_circuit_if_bind(circuit, ifp);
d62a17ae 413
414 if (if_is_broadcast(ifp)) {
65f18157 415 if (fabricd || circuit->circ_type_config == CIRCUIT_T_P2P)
d62a17ae 416 circuit->circ_type = CIRCUIT_T_P2P;
417 else
418 circuit->circ_type = CIRCUIT_T_BROADCAST;
419 } else if (if_is_pointopoint(ifp)) {
420 circuit->circ_type = CIRCUIT_T_P2P;
421 } else if (if_is_loopback(ifp)) {
422 circuit->circ_type = CIRCUIT_T_LOOPBACK;
423 circuit->is_passive = 1;
424 } else {
425 /* It's normal in case of loopback etc. */
426 if (isis->debugs & DEBUG_EVENTS)
427 zlog_debug("isis_circuit_if_add: unsupported media");
428 circuit->circ_type = CIRCUIT_T_UNKNOWN;
429 }
430
431 circuit->ip_addrs = list_new();
432 circuit->ipv6_link = list_new();
433 circuit->ipv6_non_link = list_new();
434
435 for (ALL_LIST_ELEMENTS(ifp->connected, node, nnode, conn))
436 isis_circuit_add_addr(circuit, conn);
eb5d44eb 437}
438
d62a17ae 439void isis_circuit_if_del(struct isis_circuit *circuit, struct interface *ifp)
eb5d44eb 440{
d62a17ae 441 struct listnode *node, *nnode;
442 struct connected *conn;
443
444 assert(circuit->interface == ifp);
445
446 /* destroy addresses */
447 for (ALL_LIST_ELEMENTS(ifp->connected, node, nnode, conn))
448 isis_circuit_del_addr(circuit, conn);
449
450 if (circuit->ip_addrs) {
451 assert(listcount(circuit->ip_addrs) == 0);
affe9e99 452 list_delete_and_null(&circuit->ip_addrs);
d62a17ae 453 }
454
455 if (circuit->ipv6_link) {
456 assert(listcount(circuit->ipv6_link) == 0);
affe9e99 457 list_delete_and_null(&circuit->ipv6_link);
d62a17ae 458 }
459
460 if (circuit->ipv6_non_link) {
461 assert(listcount(circuit->ipv6_non_link) == 0);
affe9e99 462 list_delete_and_null(&circuit->ipv6_non_link);
d62a17ae 463 }
464
465 circuit->circ_type = CIRCUIT_T_UNKNOWN;
eb5d44eb 466}
467
d62a17ae 468void isis_circuit_if_bind(struct isis_circuit *circuit, struct interface *ifp)
3f045a08 469{
d62a17ae 470 assert(circuit != NULL);
471 assert(ifp != NULL);
472 if (circuit->interface)
473 assert(circuit->interface == ifp);
474 else
475 circuit->interface = ifp;
476 if (ifp->info)
477 assert(ifp->info == circuit);
478 else
479 ifp->info = circuit;
480 isis_link_params_update(circuit, ifp);
3f045a08
JB
481}
482
d62a17ae 483void isis_circuit_if_unbind(struct isis_circuit *circuit, struct interface *ifp)
eb5d44eb 484{
d62a17ae 485 assert(circuit != NULL);
486 assert(ifp != NULL);
487 assert(circuit->interface == ifp);
488 assert(ifp->info == circuit);
489 circuit->interface = NULL;
490 ifp->info = NULL;
3f045a08 491}
f390d2c7 492
d62a17ae 493static void isis_circuit_update_all_srmflags(struct isis_circuit *circuit,
494 int is_set)
3f045a08 495{
d62a17ae 496 struct isis_area *area;
497 struct isis_lsp *lsp;
498 dnode_t *dnode, *dnode_next;
499 int level;
500
501 assert(circuit);
502 area = circuit->area;
503 assert(area);
504 for (level = ISIS_LEVEL1; level <= ISIS_LEVEL2; level++) {
505 if (level & circuit->is_type) {
506 if (area->lspdb[level - 1]
507 && dict_count(area->lspdb[level - 1]) > 0) {
508 for (dnode = dict_first(area->lspdb[level - 1]);
509 dnode != NULL; dnode = dnode_next) {
510 dnode_next = dict_next(
511 area->lspdb[level - 1], dnode);
512 lsp = dnode_get(dnode);
513 if (is_set) {
514 ISIS_SET_FLAG(lsp->SRMflags,
515 circuit);
516 } else {
517 ISIS_CLEAR_FLAG(lsp->SRMflags,
518 circuit);
519 }
520 }
521 }
522 }
523 }
eb5d44eb 524}
525
d62a17ae 526size_t isis_circuit_pdu_size(struct isis_circuit *circuit)
b20ccb3a 527{
d62a17ae 528 return ISO_MTU(circuit);
b20ccb3a
CF
529}
530
d62a17ae 531void isis_circuit_stream(struct isis_circuit *circuit, struct stream **stream)
b20ccb3a 532{
d62a17ae 533 size_t stream_size = isis_circuit_pdu_size(circuit);
534
535 if (!*stream) {
536 *stream = stream_new(stream_size);
537 } else {
538 if (STREAM_SIZE(*stream) != stream_size)
db3c830a 539 stream_resize_inplace(stream, stream_size);
d62a17ae 540 stream_reset(*stream);
541 }
b20ccb3a
CF
542}
543
d62a17ae 544void isis_circuit_prepare(struct isis_circuit *circuit)
5904f19f 545{
b0dd98e7 546#if ISIS_METHOD != ISIS_METHOD_DLPI
d62a17ae 547 thread_add_read(master, isis_receive, circuit, circuit->fd,
548 &circuit->t_read);
5904f19f 549#else
d62a17ae 550 thread_add_timer_msec(master, isis_receive, circuit,
551 listcount(circuit->area->circuit_list) * 100,
552 &circuit->t_read);
5904f19f
RW
553#endif
554}
555
d62a17ae 556int isis_circuit_up(struct isis_circuit *circuit)
eb5d44eb 557{
d62a17ae 558 int retv;
559
560 /* Set the flags for all the lsps of the circuit. */
561 isis_circuit_update_all_srmflags(circuit, 1);
562
563 if (circuit->state == C_STATE_UP)
564 return ISIS_OK;
565
566 if (circuit->is_passive)
567 return ISIS_OK;
568
569 if (circuit->area->lsp_mtu > isis_circuit_pdu_size(circuit)) {
af4c2728 570 flog_err(
54ece698 571 ISIS_ERR_CONFIG,
d62a17ae 572 "Interface MTU %zu on %s is too low to support area lsp mtu %u!",
573 isis_circuit_pdu_size(circuit),
574 circuit->interface->name, circuit->area->lsp_mtu);
575 isis_circuit_update_all_srmflags(circuit, 0);
576 return ISIS_ERROR;
577 }
578
579 if (circuit->circ_type == CIRCUIT_T_BROADCAST) {
0849c75e
CF
580 circuit->circuit_id = isis_circuit_id_gen(isis, circuit->interface);
581 if (!circuit->circuit_id) {
af4c2728 582 flog_err(
54ece698
DS
583 ISIS_ERR_CONFIG,
584 "There are already 255 broadcast circuits active!");
0849c75e
CF
585 return ISIS_ERROR;
586 }
587
d62a17ae 588 /*
589 * Get the Hardware Address
590 */
591 if (circuit->interface->hw_addr_len != ETH_ALEN) {
592 zlog_warn("unsupported link layer");
593 } else {
594 memcpy(circuit->u.bc.snpa, circuit->interface->hw_addr,
595 ETH_ALEN);
596 }
3f045a08 597#ifdef EXTREME_DEGUG
d62a17ae 598 zlog_debug("isis_circuit_if_add: if_id %d, isomtu %d snpa %s",
599 circuit->interface->ifindex, ISO_MTU(circuit),
600 snpa_print(circuit->u.bc.snpa));
3f045a08 601#endif /* EXTREME_DEBUG */
3f045a08 602
d62a17ae 603 circuit->u.bc.adjdb[0] = list_new();
604 circuit->u.bc.adjdb[1] = list_new();
605
606 /*
607 * ISO 10589 - 8.4.1 Enabling of broadcast circuits
608 */
609
610 /* initilizing the hello sending threads
611 * for a broadcast IF
612 */
613
614 /* 8.4.1 a) commence sending of IIH PDUs */
615
616 if (circuit->is_type & IS_LEVEL_1) {
617 thread_add_event(master, send_lan_l1_hello, circuit, 0,
618 NULL);
619 circuit->u.bc.lan_neighs[0] = list_new();
620 }
621
622 if (circuit->is_type & IS_LEVEL_2) {
623 thread_add_event(master, send_lan_l2_hello, circuit, 0,
624 NULL);
625 circuit->u.bc.lan_neighs[1] = list_new();
626 }
627
628 /* 8.4.1 b) FIXME: solicit ES - 8.4.6 */
629 /* 8.4.1 c) FIXME: listen for ESH PDUs */
630
631 /* 8.4.1 d) */
632 /* dr election will commence in... */
633 if (circuit->is_type & IS_LEVEL_1)
634 thread_add_timer(master, isis_run_dr_l1, circuit,
635 2 * circuit->hello_interval[0],
636 &circuit->u.bc.t_run_dr[0]);
637 if (circuit->is_type & IS_LEVEL_2)
638 thread_add_timer(master, isis_run_dr_l2, circuit,
639 2 * circuit->hello_interval[1],
640 &circuit->u.bc.t_run_dr[1]);
d4670f51 641 } else if (circuit->circ_type == CIRCUIT_T_P2P) {
d62a17ae 642 /* initializing the hello send threads
643 * for a ptp IF
644 */
645 circuit->u.p2p.neighbor = NULL;
646 thread_add_event(master, send_p2p_hello, circuit, 0, NULL);
647 }
648
649 /* initializing PSNP timers */
650 if (circuit->is_type & IS_LEVEL_1)
651 thread_add_timer(
652 master, send_l1_psnp, circuit,
653 isis_jitter(circuit->psnp_interval[0], PSNP_JITTER),
654 &circuit->t_send_psnp[0]);
655
656 if (circuit->is_type & IS_LEVEL_2)
657 thread_add_timer(
658 master, send_l2_psnp, circuit,
659 isis_jitter(circuit->psnp_interval[1], PSNP_JITTER),
660 &circuit->t_send_psnp[1]);
661
662 /* unified init for circuits; ignore warnings below this level */
663 retv = isis_sock_init(circuit);
664 if (retv != ISIS_OK) {
665 isis_circuit_down(circuit);
666 return retv;
667 }
668
669 /* initialize the circuit streams after opening connection */
670 isis_circuit_stream(circuit, &circuit->rcv_stream);
671 isis_circuit_stream(circuit, &circuit->snd_stream);
672
673 isis_circuit_prepare(circuit);
674
675 circuit->lsp_queue = list_new();
58e16237 676 circuit->lsp_hash = isis_lsp_hash_new();
c60158ae
RZ
677 circuit->lsp_queue_last_push[0] = circuit->lsp_queue_last_push[1] =
678 monotime(NULL);
d62a17ae 679
680 return ISIS_OK;
eb5d44eb 681}
682
d62a17ae 683void isis_circuit_down(struct isis_circuit *circuit)
eb5d44eb 684{
d62a17ae 685 /* Clear the flags for all the lsps of the circuit. */
686 isis_circuit_update_all_srmflags(circuit, 0);
687
688 if (circuit->circ_type == CIRCUIT_T_BROADCAST) {
689 /* destroy neighbour lists */
690 if (circuit->u.bc.lan_neighs[0]) {
affe9e99 691 list_delete_and_null(&circuit->u.bc.lan_neighs[0]);
d62a17ae 692 circuit->u.bc.lan_neighs[0] = NULL;
693 }
694 if (circuit->u.bc.lan_neighs[1]) {
affe9e99 695 list_delete_and_null(&circuit->u.bc.lan_neighs[1]);
d62a17ae 696 circuit->u.bc.lan_neighs[1] = NULL;
697 }
698 /* destroy adjacency databases */
699 if (circuit->u.bc.adjdb[0]) {
700 circuit->u.bc.adjdb[0]->del = isis_delete_adj;
affe9e99 701 list_delete_and_null(&circuit->u.bc.adjdb[0]);
d62a17ae 702 circuit->u.bc.adjdb[0] = NULL;
703 }
704 if (circuit->u.bc.adjdb[1]) {
705 circuit->u.bc.adjdb[1]->del = isis_delete_adj;
affe9e99 706 list_delete_and_null(&circuit->u.bc.adjdb[1]);
d62a17ae 707 circuit->u.bc.adjdb[1] = NULL;
708 }
709 if (circuit->u.bc.is_dr[0]) {
710 isis_dr_resign(circuit, 1);
711 circuit->u.bc.is_dr[0] = 0;
712 }
713 memset(circuit->u.bc.l1_desig_is, 0, ISIS_SYS_ID_LEN + 1);
714 if (circuit->u.bc.is_dr[1]) {
715 isis_dr_resign(circuit, 2);
716 circuit->u.bc.is_dr[1] = 0;
717 }
718 memset(circuit->u.bc.l2_desig_is, 0, ISIS_SYS_ID_LEN + 1);
719 memset(circuit->u.bc.snpa, 0, ETH_ALEN);
720
721 THREAD_TIMER_OFF(circuit->u.bc.t_send_lan_hello[0]);
722 THREAD_TIMER_OFF(circuit->u.bc.t_send_lan_hello[1]);
723 THREAD_TIMER_OFF(circuit->u.bc.t_run_dr[0]);
724 THREAD_TIMER_OFF(circuit->u.bc.t_run_dr[1]);
725 THREAD_TIMER_OFF(circuit->u.bc.t_refresh_pseudo_lsp[0]);
726 THREAD_TIMER_OFF(circuit->u.bc.t_refresh_pseudo_lsp[1]);
727 circuit->lsp_regenerate_pending[0] = 0;
728 circuit->lsp_regenerate_pending[1] = 0;
0849c75e
CF
729
730 _ISIS_CLEAR_FLAG(isis->circuit_ids_used, circuit->circuit_id);
731 circuit->circuit_id = 0;
d62a17ae 732 } else if (circuit->circ_type == CIRCUIT_T_P2P) {
733 isis_delete_adj(circuit->u.p2p.neighbor);
734 circuit->u.p2p.neighbor = NULL;
735 THREAD_TIMER_OFF(circuit->u.p2p.t_send_p2p_hello);
736 }
737
738 /* Cancel all active threads */
739 THREAD_TIMER_OFF(circuit->t_send_csnp[0]);
740 THREAD_TIMER_OFF(circuit->t_send_csnp[1]);
741 THREAD_TIMER_OFF(circuit->t_send_psnp[0]);
742 THREAD_TIMER_OFF(circuit->t_send_psnp[1]);
58e16237 743 THREAD_OFF(circuit->t_send_lsp);
d62a17ae 744 THREAD_OFF(circuit->t_read);
745
746 if (circuit->lsp_queue) {
affe9e99 747 list_delete_and_null(&circuit->lsp_queue);
d62a17ae 748 }
749
58e16237
CF
750 if (circuit->lsp_hash) {
751 isis_lsp_hash_free(circuit->lsp_hash);
752 circuit->lsp_hash = NULL;
753 }
754
d62a17ae 755 /* send one gratuitous hello to spead up convergence */
d4670f51
CF
756 if (circuit->state == C_STATE_UP) {
757 if (circuit->is_type & IS_LEVEL_1)
758 send_hello(circuit, IS_LEVEL_1);
759 if (circuit->is_type & IS_LEVEL_2)
760 send_hello(circuit, IS_LEVEL_2);
761 }
d62a17ae 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) {
7c0cbd0e 960 vty_out(vty, " ip router " PROTO_NAME " %s\n",
d62a17ae 961 area->area_tag);
962 write++;
963 }
964 if (circuit->is_passive) {
7c0cbd0e 965 vty_out(vty, " " PROTO_NAME " passive\n");
d62a17ae 966 write++;
967 }
968 if (circuit->circ_type_config == CIRCUIT_T_P2P) {
7c0cbd0e 969 vty_out(vty, " " PROTO_NAME " network point-to-point\n");
d62a17ae 970 write++;
971 }
972 if (circuit->ipv6_router) {
7c0cbd0e 973 vty_out(vty, " ipv6 router " PROTO_NAME " %s\n",
d62a17ae 974 area->area_tag);
975 write++;
976 }
977
978 /* ISIS - circuit type */
65f18157
CF
979 if (!fabricd) {
980 if (circuit->is_type == IS_LEVEL_1) {
981 vty_out(vty, " " PROTO_NAME " circuit-type level-1\n");
d62a17ae 982 write++;
65f18157
CF
983 } else {
984 if (circuit->is_type == IS_LEVEL_2) {
985 vty_out(vty,
986 " " PROTO_NAME " circuit-type level-2-only\n");
987 write++;
988 }
d62a17ae 989 }
990 }
991
992 /* ISIS - CSNP interval */
993 if (circuit->csnp_interval[0]
994 == circuit->csnp_interval[1]) {
995 if (circuit->csnp_interval[0]
996 != DEFAULT_CSNP_INTERVAL) {
7c0cbd0e 997 vty_out(vty, " " PROTO_NAME " csnp-interval %d\n",
d62a17ae 998 circuit->csnp_interval[0]);
999 write++;
1000 }
1001 } else {
1002 for (i = 0; i < 2; i++) {
1003 if (circuit->csnp_interval[i]
1004 != DEFAULT_CSNP_INTERVAL) {
1005 vty_out(vty,
7c0cbd0e 1006 " " PROTO_NAME " csnp-interval %d level-%d\n",
d62a17ae 1007 circuit->csnp_interval
1008 [i],
1009 i + 1);
1010 write++;
1011 }
1012 }
1013 }
1014
1015 /* ISIS - PSNP interval */
1016 if (circuit->psnp_interval[0]
1017 == circuit->psnp_interval[1]) {
1018 if (circuit->psnp_interval[0]
1019 != DEFAULT_PSNP_INTERVAL) {
7c0cbd0e 1020 vty_out(vty, " " PROTO_NAME " psnp-interval %d\n",
d62a17ae 1021 circuit->psnp_interval[0]);
1022 write++;
1023 }
1024 } else {
1025 for (i = 0; i < 2; i++) {
1026 if (circuit->psnp_interval[i]
1027 != DEFAULT_PSNP_INTERVAL) {
1028 vty_out(vty,
7c0cbd0e 1029 " " PROTO_NAME " psnp-interval %d level-%d\n",
d62a17ae 1030 circuit->psnp_interval
1031 [i],
1032 i + 1);
1033 write++;
1034 }
1035 }
1036 }
1037
1038 /* ISIS - Hello padding - Defaults to true so only
1039 * display if false */
1040 if (circuit->pad_hellos == 0) {
7c0cbd0e 1041 vty_out(vty, " no " PROTO_NAME " hello padding\n");
d62a17ae 1042 write++;
1043 }
1044
58e5d748
CF
1045 if (circuit->disable_threeway_adj) {
1046 vty_out(vty, " no isis three-way-handshake\n");
1047 write++;
1048 }
1049
d62a17ae 1050 /* ISIS - Hello interval */
1051 if (circuit->hello_interval[0]
1052 == circuit->hello_interval[1]) {
1053 if (circuit->hello_interval[0]
1054 != DEFAULT_HELLO_INTERVAL) {
1055 vty_out(vty,
7c0cbd0e 1056 " " PROTO_NAME " hello-interval %d\n",
d62a17ae 1057 circuit->hello_interval[0]);
1058 write++;
1059 }
1060 } else {
1061 for (i = 0; i < 2; i++) {
1062 if (circuit->hello_interval[i]
1063 != DEFAULT_HELLO_INTERVAL) {
1064 vty_out(vty,
7c0cbd0e 1065 " " PROTO_NAME " hello-interval %d level-%d\n",
d62a17ae 1066 circuit->hello_interval
1067 [i],
1068 i + 1);
1069 write++;
1070 }
1071 }
1072 }
1073
1074 /* ISIS - Hello Multiplier */
1075 if (circuit->hello_multiplier[0]
1076 == circuit->hello_multiplier[1]) {
1077 if (circuit->hello_multiplier[0]
1078 != DEFAULT_HELLO_MULTIPLIER) {
1079 vty_out(vty,
7c0cbd0e 1080 " " PROTO_NAME " hello-multiplier %d\n",
d62a17ae 1081 circuit->hello_multiplier[0]);
1082 write++;
1083 }
1084 } else {
1085 for (i = 0; i < 2; i++) {
1086 if (circuit->hello_multiplier[i]
1087 != DEFAULT_HELLO_MULTIPLIER) {
1088 vty_out(vty,
7c0cbd0e 1089 " " PROTO_NAME " hello-multiplier %d level-%d\n",
d62a17ae 1090 circuit->hello_multiplier
1091 [i],
1092 i + 1);
1093 write++;
1094 }
1095 }
1096 }
1097
1098 /* ISIS - Priority */
1099 if (circuit->priority[0] == circuit->priority[1]) {
1100 if (circuit->priority[0] != DEFAULT_PRIORITY) {
7c0cbd0e 1101 vty_out(vty, " " PROTO_NAME " priority %d\n",
d62a17ae 1102 circuit->priority[0]);
1103 write++;
1104 }
1105 } else {
1106 for (i = 0; i < 2; i++) {
1107 if (circuit->priority[i]
1108 != DEFAULT_PRIORITY) {
1109 vty_out(vty,
7c0cbd0e 1110 " " PROTO_NAME " priority %d level-%d\n",
d62a17ae 1111 circuit->priority[i],
1112 i + 1);
1113 write++;
1114 }
1115 }
1116 }
1117
1118 /* ISIS - Metric */
1119 if (circuit->te_metric[0] == circuit->te_metric[1]) {
1120 if (circuit->te_metric[0]
1121 != DEFAULT_CIRCUIT_METRIC) {
7c0cbd0e 1122 vty_out(vty, " " PROTO_NAME " metric %d\n",
d62a17ae 1123 circuit->te_metric[0]);
1124 write++;
1125 }
1126 } else {
1127 for (i = 0; i < 2; i++) {
1128 if (circuit->te_metric[i]
1129 != DEFAULT_CIRCUIT_METRIC) {
1130 vty_out(vty,
7c0cbd0e 1131 " " PROTO_NAME " metric %d level-%d\n",
d62a17ae 1132 circuit->te_metric[i],
1133 i + 1);
1134 write++;
1135 }
1136 }
1137 }
1138 if (circuit->passwd.type == ISIS_PASSWD_TYPE_HMAC_MD5) {
7c0cbd0e 1139 vty_out(vty, " " PROTO_NAME " password md5 %s\n",
d62a17ae 1140 circuit->passwd.passwd);
1141 write++;
1142 } else if (circuit->passwd.type
1143 == ISIS_PASSWD_TYPE_CLEARTXT) {
7c0cbd0e 1144 vty_out(vty, " " PROTO_NAME " password clear %s\n",
d62a17ae 1145 circuit->passwd.passwd);
1146 write++;
1147 }
1148 write += circuit_write_mt_settings(circuit, vty);
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}
58e16237
CF
1349
1350void isis_circuit_schedule_lsp_send(struct isis_circuit *circuit)
1351{
1352 if (circuit->t_send_lsp)
1353 return;
996c9314
LB
1354 circuit->t_send_lsp =
1355 thread_add_event(master, send_lsp, circuit, 0, NULL);
58e16237
CF
1356}
1357
1358void isis_circuit_queue_lsp(struct isis_circuit *circuit, struct isis_lsp *lsp)
1359{
1360 if (isis_lsp_hash_lookup(circuit->lsp_hash, lsp))
1361 return;
1362
1363 listnode_add(circuit->lsp_queue, lsp);
1364 isis_lsp_hash_add(circuit->lsp_hash, lsp);
1365 isis_circuit_schedule_lsp_send(circuit);
1366}
1367
1368void isis_circuit_lsp_queue_clean(struct isis_circuit *circuit)
1369{
1370 if (!circuit->lsp_queue)
1371 return;
1372
1373 list_delete_all_node(circuit->lsp_queue);
1374 isis_lsp_hash_clean(circuit->lsp_hash);
1375}
1376
1377void isis_circuit_cancel_queued_lsp(struct isis_circuit *circuit,
1378 struct isis_lsp *lsp)
1379{
1380 if (!circuit->lsp_queue)
1381 return;
1382
1383 listnode_delete(circuit->lsp_queue, lsp);
1384 isis_lsp_hash_release(circuit->lsp_hash, lsp);
1385}
1386
1387struct isis_lsp *isis_circuit_lsp_queue_pop(struct isis_circuit *circuit)
1388{
1389 if (!circuit->lsp_queue)
1390 return NULL;
1391
1392 struct listnode *node = listhead(circuit->lsp_queue);
1393 if (!node)
1394 return NULL;
1395
1396 struct isis_lsp *rv = listgetdata(node);
1397
1398 list_delete_node(circuit->lsp_queue, node);
1399 isis_lsp_hash_release(circuit->lsp_hash, rv);
1400
1401 return rv;
1402}