]> git.proxmox.com Git - mirror_frr.git/blob - isisd/isis_nb_config.c
Merge pull request #6407 from donaldsharp/revert_ospfv3_fix
[mirror_frr.git] / isisd / isis_nb_config.c
1 /*
2 * Copyright (C) 2001,2002 Sampo Saaristo
3 * Tampere University of Technology
4 * Institute of Communications Engineering
5 * Copyright (C) 2018 Volta Networks
6 * Emanuele Di Pascale
7 *
8 * This program is free software; you can redistribute it and/or modify it
9 * under the terms of the GNU General Public License as published by the Free
10 * Software Foundation; either version 2 of the License, or (at your option)
11 * any later version.
12 *
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
16 * more details.
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
21 */
22
23 #include <zebra.h>
24
25 #include "northbound.h"
26 #include "linklist.h"
27 #include "log.h"
28 #include "bfd.h"
29 #include "spf_backoff.h"
30 #include "lib_errors.h"
31 #include "vrf.h"
32
33 #include "isisd/isisd.h"
34 #include "isisd/isis_nb.h"
35 #include "isisd/isis_common.h"
36 #include "isisd/isis_bfd.h"
37 #include "isisd/isis_circuit.h"
38 #include "isisd/isis_lsp.h"
39 #include "isisd/isis_dynhn.h"
40 #include "isisd/isis_misc.h"
41 #include "isisd/isis_csm.h"
42 #include "isisd/isis_adjacency.h"
43 #include "isisd/isis_spf.h"
44 #include "isisd/isis_te.h"
45 #include "isisd/isis_memory.h"
46 #include "isisd/isis_mt.h"
47 #include "isisd/isis_redist.h"
48
49 /*
50 * XPath: /frr-isisd:isis/instance
51 */
52 int isis_instance_create(struct nb_cb_create_args *args)
53 {
54 struct isis_area *area;
55 const char *area_tag;
56
57 if (args->event != NB_EV_APPLY)
58 return NB_OK;
59
60 area_tag = yang_dnode_get_string(args->dnode, "./area-tag");
61 area = isis_area_lookup(area_tag);
62 if (area)
63 return NB_ERR_INCONSISTENCY;
64
65 area = isis_area_create(area_tag);
66 /* save area in dnode to avoid looking it up all the time */
67 nb_running_set_entry(args->dnode, area);
68
69 return NB_OK;
70 }
71
72 int isis_instance_destroy(struct nb_cb_destroy_args *args)
73 {
74 struct isis_area *area;
75
76 if (args->event != NB_EV_APPLY)
77 return NB_OK;
78
79 area = nb_running_unset_entry(args->dnode);
80 isis_area_destroy(area->area_tag);
81
82 return NB_OK;
83 }
84
85 /*
86 * XPath: /frr-isisd:isis/instance/is-type
87 */
88 int isis_instance_is_type_modify(struct nb_cb_modify_args *args)
89 {
90 struct isis_area *area;
91 int type;
92
93 if (args->event != NB_EV_APPLY)
94 return NB_OK;
95
96 area = nb_running_get_entry(args->dnode, NULL, true);
97 type = yang_dnode_get_enum(args->dnode, NULL);
98 isis_area_is_type_set(area, type);
99
100 return NB_OK;
101 }
102
103 /*
104 * XPath: /frr-isisd:isis/instance/area-address
105 */
106 int isis_instance_area_address_create(struct nb_cb_create_args *args)
107 {
108 struct isis_area *area;
109 struct area_addr addr, *addrr = NULL, *addrp = NULL;
110 struct listnode *node;
111 uint8_t buff[255];
112 const char *net_title = yang_dnode_get_string(args->dnode, NULL);
113
114 switch (args->event) {
115 case NB_EV_VALIDATE:
116 addr.addr_len = dotformat2buff(buff, net_title);
117 memcpy(addr.area_addr, buff, addr.addr_len);
118 if (addr.area_addr[addr.addr_len - 1] != 0) {
119 flog_warn(
120 EC_LIB_NB_CB_CONFIG_VALIDATE,
121 "nsel byte (last byte) in area address must be 0");
122 return NB_ERR_VALIDATION;
123 }
124 if (isis->sysid_set) {
125 /* Check that the SystemID portions match */
126 if (memcmp(isis->sysid, GETSYSID((&addr)),
127 ISIS_SYS_ID_LEN)) {
128 flog_warn(
129 EC_LIB_NB_CB_CONFIG_VALIDATE,
130 "System ID must not change when defining additional area addresses");
131 return NB_ERR_VALIDATION;
132 }
133 }
134 break;
135 case NB_EV_PREPARE:
136 addrr = XMALLOC(MTYPE_ISIS_AREA_ADDR, sizeof(struct area_addr));
137 addrr->addr_len = dotformat2buff(buff, net_title);
138 memcpy(addrr->area_addr, buff, addrr->addr_len);
139 args->resource->ptr = addrr;
140 break;
141 case NB_EV_ABORT:
142 XFREE(MTYPE_ISIS_AREA_ADDR, args->resource->ptr);
143 break;
144 case NB_EV_APPLY:
145 area = nb_running_get_entry(args->dnode, NULL, true);
146 addrr = args->resource->ptr;
147
148 if (isis->sysid_set == 0) {
149 /*
150 * First area address - get the SystemID for this router
151 */
152 memcpy(isis->sysid, GETSYSID(addrr), ISIS_SYS_ID_LEN);
153 isis->sysid_set = 1;
154 } else {
155 /* check that we don't already have this address */
156 for (ALL_LIST_ELEMENTS_RO(area->area_addrs, node,
157 addrp)) {
158 if ((addrp->addr_len + ISIS_SYS_ID_LEN
159 + ISIS_NSEL_LEN)
160 != (addrr->addr_len))
161 continue;
162 if (!memcmp(addrp->area_addr, addrr->area_addr,
163 addrr->addr_len)) {
164 XFREE(MTYPE_ISIS_AREA_ADDR, addrr);
165 return NB_OK; /* silent fail */
166 }
167 }
168 }
169
170 /*Forget the systemID part of the address */
171 addrr->addr_len -= (ISIS_SYS_ID_LEN + ISIS_NSEL_LEN);
172 assert(area->area_addrs); /* to silence scan-build sillyness */
173 listnode_add(area->area_addrs, addrr);
174
175 /* only now we can safely generate our LSPs for this area */
176 if (listcount(area->area_addrs) > 0) {
177 if (area->is_type & IS_LEVEL_1)
178 lsp_generate(area, IS_LEVEL_1);
179 if (area->is_type & IS_LEVEL_2)
180 lsp_generate(area, IS_LEVEL_2);
181 }
182 break;
183 }
184
185 return NB_OK;
186 }
187
188 int isis_instance_area_address_destroy(struct nb_cb_destroy_args *args)
189 {
190 struct area_addr addr, *addrp = NULL;
191 struct listnode *node;
192 uint8_t buff[255];
193 struct isis_area *area;
194 const char *net_title;
195
196 if (args->event != NB_EV_APPLY)
197 return NB_OK;
198
199 net_title = yang_dnode_get_string(args->dnode, NULL);
200 addr.addr_len = dotformat2buff(buff, net_title);
201 memcpy(addr.area_addr, buff, (int)addr.addr_len);
202 area = nb_running_get_entry(args->dnode, NULL, true);
203 for (ALL_LIST_ELEMENTS_RO(area->area_addrs, node, addrp)) {
204 if ((addrp->addr_len + ISIS_SYS_ID_LEN + 1) == addr.addr_len
205 && !memcmp(addrp->area_addr, addr.area_addr, addr.addr_len))
206 break;
207 }
208 if (!addrp)
209 return NB_ERR_INCONSISTENCY;
210
211 listnode_delete(area->area_addrs, addrp);
212 XFREE(MTYPE_ISIS_AREA_ADDR, addrp);
213 /*
214 * Last area address - reset the SystemID for this router
215 */
216 if (listcount(area->area_addrs) == 0) {
217 memset(isis->sysid, 0, ISIS_SYS_ID_LEN);
218 isis->sysid_set = 0;
219 if (isis->debugs & DEBUG_EVENTS)
220 zlog_debug("Router has no SystemID");
221 }
222
223 return NB_OK;
224 }
225
226 /*
227 * XPath: /frr-isisd:isis/instance/dynamic-hostname
228 */
229 int isis_instance_dynamic_hostname_modify(struct nb_cb_modify_args *args)
230 {
231 struct isis_area *area;
232
233 if (args->event != NB_EV_APPLY)
234 return NB_OK;
235
236 area = nb_running_get_entry(args->dnode, NULL, true);
237 isis_area_dynhostname_set(area, yang_dnode_get_bool(args->dnode, NULL));
238
239 return NB_OK;
240 }
241
242 /*
243 * XPath: /frr-isisd:isis/instance/attached
244 */
245 int isis_instance_attached_modify(struct nb_cb_modify_args *args)
246 {
247 struct isis_area *area;
248 bool attached;
249
250 if (args->event != NB_EV_APPLY)
251 return NB_OK;
252
253 area = nb_running_get_entry(args->dnode, NULL, true);
254 attached = yang_dnode_get_bool(args->dnode, NULL);
255 isis_area_attached_bit_set(area, attached);
256
257 return NB_OK;
258 }
259
260 /*
261 * XPath: /frr-isisd:isis/instance/overload
262 */
263 int isis_instance_overload_modify(struct nb_cb_modify_args *args)
264 {
265 struct isis_area *area;
266 bool overload;
267
268 if (args->event != NB_EV_APPLY)
269 return NB_OK;
270
271 area = nb_running_get_entry(args->dnode, NULL, true);
272 overload = yang_dnode_get_bool(args->dnode, NULL);
273 isis_area_overload_bit_set(area, overload);
274
275 return NB_OK;
276 }
277
278 /*
279 * XPath: /frr-isisd:isis/instance/metric-style
280 */
281 int isis_instance_metric_style_modify(struct nb_cb_modify_args *args)
282 {
283 struct isis_area *area;
284 bool old_metric, new_metric;
285 enum isis_metric_style metric_style =
286 yang_dnode_get_enum(args->dnode, NULL);
287
288 if (args->event != NB_EV_APPLY)
289 return NB_OK;
290
291 area = nb_running_get_entry(args->dnode, NULL, true);
292 old_metric = (metric_style == ISIS_WIDE_METRIC) ? false : true;
293 new_metric = (metric_style == ISIS_NARROW_METRIC) ? false : true;
294 isis_area_metricstyle_set(area, old_metric, new_metric);
295
296 return NB_OK;
297 }
298
299 /*
300 * XPath: /frr-isisd:isis/instance/purge-originator
301 */
302 int isis_instance_purge_originator_modify(struct nb_cb_modify_args *args)
303 {
304 struct isis_area *area;
305
306 if (args->event != NB_EV_APPLY)
307 return NB_OK;
308
309 area = nb_running_get_entry(args->dnode, NULL, true);
310 area->purge_originator = yang_dnode_get_bool(args->dnode, NULL);
311
312 return NB_OK;
313 }
314
315 /*
316 * XPath: /frr-isisd:isis/instance/lsp/mtu
317 */
318 int isis_instance_lsp_mtu_modify(struct nb_cb_modify_args *args)
319 {
320 struct listnode *node;
321 struct isis_circuit *circuit;
322 uint16_t lsp_mtu = yang_dnode_get_uint16(args->dnode, NULL);
323 struct isis_area *area;
324
325 switch (args->event) {
326 case NB_EV_VALIDATE:
327 area = nb_running_get_entry(args->dnode, NULL, false);
328 if (!area)
329 break;
330 for (ALL_LIST_ELEMENTS_RO(area->circuit_list, node, circuit)) {
331 if (circuit->state != C_STATE_INIT
332 && circuit->state != C_STATE_UP)
333 continue;
334 if (lsp_mtu > isis_circuit_pdu_size(circuit)) {
335 flog_warn(
336 EC_LIB_NB_CB_CONFIG_VALIDATE,
337 "ISIS area contains circuit %s, which has a maximum PDU size of %zu",
338 circuit->interface->name,
339 isis_circuit_pdu_size(circuit));
340 return NB_ERR_VALIDATION;
341 }
342 }
343 break;
344 case NB_EV_PREPARE:
345 case NB_EV_ABORT:
346 break;
347 case NB_EV_APPLY:
348 area = nb_running_get_entry(args->dnode, NULL, true);
349 isis_area_lsp_mtu_set(area, lsp_mtu);
350 break;
351 }
352
353 return NB_OK;
354 }
355
356 /*
357 * XPath: /frr-isisd:isis/instance/lsp/timers/level-1/refresh-interval
358 */
359 int isis_instance_lsp_refresh_interval_level_1_modify(
360 struct nb_cb_modify_args *args)
361 {
362 struct isis_area *area;
363 uint16_t refr_int;
364
365 if (args->event != NB_EV_APPLY)
366 return NB_OK;
367
368 refr_int = yang_dnode_get_uint16(args->dnode, NULL);
369 area = nb_running_get_entry(args->dnode, NULL, true);
370 isis_area_lsp_refresh_set(area, IS_LEVEL_1, refr_int);
371
372 return NB_OK;
373 }
374
375 /*
376 * XPath: /frr-isisd:isis/instance/lsp/timers/level-2/refresh-interval
377 */
378 int isis_instance_lsp_refresh_interval_level_2_modify(
379 struct nb_cb_modify_args *args)
380 {
381 struct isis_area *area;
382 uint16_t refr_int;
383
384 if (args->event != NB_EV_APPLY)
385 return NB_OK;
386
387 refr_int = yang_dnode_get_uint16(args->dnode, NULL);
388 area = nb_running_get_entry(args->dnode, NULL, true);
389 isis_area_lsp_refresh_set(area, IS_LEVEL_2, refr_int);
390
391 return NB_OK;
392 }
393
394 /*
395 * XPath: /frr-isisd:isis/instance/lsp/timers/level-1/maximum-lifetime
396 */
397 int isis_instance_lsp_maximum_lifetime_level_1_modify(
398 struct nb_cb_modify_args *args)
399 {
400 struct isis_area *area;
401 uint16_t max_lt;
402
403 if (args->event != NB_EV_APPLY)
404 return NB_OK;
405
406 max_lt = yang_dnode_get_uint16(args->dnode, NULL);
407 area = nb_running_get_entry(args->dnode, NULL, true);
408 isis_area_max_lsp_lifetime_set(area, IS_LEVEL_1, max_lt);
409
410 return NB_OK;
411 }
412
413 /*
414 * XPath: /frr-isisd:isis/instance/lsp/timers/level-2/maximum-lifetime
415 */
416 int isis_instance_lsp_maximum_lifetime_level_2_modify(
417 struct nb_cb_modify_args *args)
418 {
419 struct isis_area *area;
420 uint16_t max_lt;
421
422 if (args->event != NB_EV_APPLY)
423 return NB_OK;
424
425 max_lt = yang_dnode_get_uint16(args->dnode, NULL);
426 area = nb_running_get_entry(args->dnode, NULL, true);
427 isis_area_max_lsp_lifetime_set(area, IS_LEVEL_2, max_lt);
428
429 return NB_OK;
430 }
431
432 /*
433 * XPath: /frr-isisd:isis/instance/lsp/timers/level-1/generation-interval
434 */
435 int isis_instance_lsp_generation_interval_level_1_modify(
436 struct nb_cb_modify_args *args)
437 {
438 struct isis_area *area;
439 uint16_t gen_int;
440
441 if (args->event != NB_EV_APPLY)
442 return NB_OK;
443
444 gen_int = yang_dnode_get_uint16(args->dnode, NULL);
445 area = nb_running_get_entry(args->dnode, NULL, true);
446 area->lsp_gen_interval[0] = gen_int;
447
448 return NB_OK;
449 }
450
451 /*
452 * XPath: /frr-isisd:isis/instance/lsp/timers/level-2/generation-interval
453 */
454 int isis_instance_lsp_generation_interval_level_2_modify(
455 struct nb_cb_modify_args *args)
456 {
457 struct isis_area *area;
458 uint16_t gen_int;
459
460 if (args->event != NB_EV_APPLY)
461 return NB_OK;
462
463 gen_int = yang_dnode_get_uint16(args->dnode, NULL);
464 area = nb_running_get_entry(args->dnode, NULL, true);
465 area->lsp_gen_interval[1] = gen_int;
466
467 return NB_OK;
468 }
469
470 /*
471 * XPath: /frr-isisd:isis/instance/spf/ietf-backoff-delay
472 */
473 void ietf_backoff_delay_apply_finish(struct nb_cb_apply_finish_args *args)
474 {
475 long init_delay = yang_dnode_get_uint16(args->dnode, "./init-delay");
476 long short_delay = yang_dnode_get_uint16(args->dnode, "./short-delay");
477 long long_delay = yang_dnode_get_uint16(args->dnode, "./long-delay");
478 long holddown = yang_dnode_get_uint16(args->dnode, "./hold-down");
479 long timetolearn =
480 yang_dnode_get_uint16(args->dnode, "./time-to-learn");
481 struct isis_area *area = nb_running_get_entry(args->dnode, NULL, true);
482 size_t bufsiz = strlen(area->area_tag) + sizeof("IS-IS Lx");
483 char *buf = XCALLOC(MTYPE_TMP, bufsiz);
484
485 snprintf(buf, bufsiz, "IS-IS %s L1", area->area_tag);
486 spf_backoff_free(area->spf_delay_ietf[0]);
487 area->spf_delay_ietf[0] =
488 spf_backoff_new(master, buf, init_delay, short_delay,
489 long_delay, holddown, timetolearn);
490
491 snprintf(buf, bufsiz, "IS-IS %s L2", area->area_tag);
492 spf_backoff_free(area->spf_delay_ietf[1]);
493 area->spf_delay_ietf[1] =
494 spf_backoff_new(master, buf, init_delay, short_delay,
495 long_delay, holddown, timetolearn);
496
497 XFREE(MTYPE_TMP, buf);
498 }
499
500 int isis_instance_spf_ietf_backoff_delay_create(struct nb_cb_create_args *args)
501 {
502 /* All the work is done in the apply_finish */
503 return NB_OK;
504 }
505
506 int isis_instance_spf_ietf_backoff_delay_destroy(
507 struct nb_cb_destroy_args *args)
508 {
509 struct isis_area *area;
510
511 if (args->event != NB_EV_APPLY)
512 return NB_OK;
513
514 area = nb_running_get_entry(args->dnode, NULL, true);
515 spf_backoff_free(area->spf_delay_ietf[0]);
516 spf_backoff_free(area->spf_delay_ietf[1]);
517 area->spf_delay_ietf[0] = NULL;
518 area->spf_delay_ietf[1] = NULL;
519
520 return NB_OK;
521 }
522
523 /*
524 * XPath: /frr-isisd:isis/instance/spf/ietf-backoff-delay/init-delay
525 */
526 int isis_instance_spf_ietf_backoff_delay_init_delay_modify(
527 struct nb_cb_modify_args *args)
528 {
529 /* All the work is done in the apply_finish */
530 return NB_OK;
531 }
532
533 /*
534 * XPath: /frr-isisd:isis/instance/spf/ietf-backoff-delay/short-delay
535 */
536 int isis_instance_spf_ietf_backoff_delay_short_delay_modify(
537 struct nb_cb_modify_args *args)
538 {
539 /* All the work is done in the apply_finish */
540 return NB_OK;
541 }
542
543 /*
544 * XPath: /frr-isisd:isis/instance/spf/ietf-backoff-delay/long-delay
545 */
546 int isis_instance_spf_ietf_backoff_delay_long_delay_modify(
547 struct nb_cb_modify_args *args)
548 {
549 /* All the work is done in the apply_finish */
550 return NB_OK;
551 }
552
553 /*
554 * XPath: /frr-isisd:isis/instance/spf/ietf-backoff-delay/hold-down
555 */
556 int isis_instance_spf_ietf_backoff_delay_hold_down_modify(
557 struct nb_cb_modify_args *args)
558 {
559 /* All the work is done in the apply_finish */
560 return NB_OK;
561 }
562
563 /*
564 * XPath: /frr-isisd:isis/instance/spf/ietf-backoff-delay/time-to-learn
565 */
566 int isis_instance_spf_ietf_backoff_delay_time_to_learn_modify(
567 struct nb_cb_modify_args *args)
568 {
569 /* All the work is done in the apply_finish */
570 return NB_OK;
571 }
572
573 /*
574 * XPath: /frr-isisd:isis/instance/spf/minimum-interval/level-1
575 */
576 int isis_instance_spf_minimum_interval_level_1_modify(
577 struct nb_cb_modify_args *args)
578 {
579 struct isis_area *area;
580
581 if (args->event != NB_EV_APPLY)
582 return NB_OK;
583
584 area = nb_running_get_entry(args->dnode, NULL, true);
585 area->min_spf_interval[0] = yang_dnode_get_uint16(args->dnode, NULL);
586
587 return NB_OK;
588 }
589
590 /*
591 * XPath: /frr-isisd:isis/instance/spf/minimum-interval/level-2
592 */
593 int isis_instance_spf_minimum_interval_level_2_modify(
594 struct nb_cb_modify_args *args)
595 {
596 struct isis_area *area;
597
598 if (args->event != NB_EV_APPLY)
599 return NB_OK;
600
601 area = nb_running_get_entry(args->dnode, NULL, true);
602 area->min_spf_interval[1] = yang_dnode_get_uint16(args->dnode, NULL);
603
604 return NB_OK;
605 }
606
607 /*
608 * XPath: /frr-isisd:isis/instance/area-password
609 */
610 void area_password_apply_finish(struct nb_cb_apply_finish_args *args)
611 {
612 const char *password = yang_dnode_get_string(args->dnode, "./password");
613 struct isis_area *area = nb_running_get_entry(args->dnode, NULL, true);
614 int pass_type = yang_dnode_get_enum(args->dnode, "./password-type");
615 uint8_t snp_auth =
616 yang_dnode_get_enum(args->dnode, "./authenticate-snp");
617
618 switch (pass_type) {
619 case ISIS_PASSWD_TYPE_CLEARTXT:
620 isis_area_passwd_cleartext_set(area, IS_LEVEL_1, password,
621 snp_auth);
622 break;
623 case ISIS_PASSWD_TYPE_HMAC_MD5:
624 isis_area_passwd_hmac_md5_set(area, IS_LEVEL_1, password,
625 snp_auth);
626 break;
627 }
628 }
629
630 int isis_instance_area_password_create(struct nb_cb_create_args *args)
631 {
632 /* actual setting is done in apply_finish */
633 return NB_OK;
634 }
635
636 int isis_instance_area_password_destroy(struct nb_cb_destroy_args *args)
637 {
638 struct isis_area *area;
639
640 if (args->event != NB_EV_APPLY)
641 return NB_OK;
642
643 area = nb_running_get_entry(args->dnode, NULL, true);
644 isis_area_passwd_unset(area, IS_LEVEL_1);
645
646 return NB_OK;
647 }
648
649 /*
650 * XPath: /frr-isisd:isis/instance/area-password/password
651 */
652 int isis_instance_area_password_password_modify(struct nb_cb_modify_args *args)
653 {
654 /* actual setting is done in apply_finish */
655 return NB_OK;
656 }
657
658 /*
659 * XPath: /frr-isisd:isis/instance/area-password/password-type
660 */
661 int isis_instance_area_password_password_type_modify(
662 struct nb_cb_modify_args *args)
663 {
664 /* actual setting is done in apply_finish */
665 return NB_OK;
666 }
667
668 /*
669 * XPath: /frr-isisd:isis/instance/area-password/authenticate-snp
670 */
671 int isis_instance_area_password_authenticate_snp_modify(
672 struct nb_cb_modify_args *args)
673 {
674 /* actual setting is done in apply_finish */
675 return NB_OK;
676 }
677
678 /*
679 * XPath: /frr-isisd:isis/instance/domain-password
680 */
681 void domain_password_apply_finish(struct nb_cb_apply_finish_args *args)
682 {
683 const char *password = yang_dnode_get_string(args->dnode, "./password");
684 struct isis_area *area = nb_running_get_entry(args->dnode, NULL, true);
685 int pass_type = yang_dnode_get_enum(args->dnode, "./password-type");
686 uint8_t snp_auth =
687 yang_dnode_get_enum(args->dnode, "./authenticate-snp");
688
689 switch (pass_type) {
690 case ISIS_PASSWD_TYPE_CLEARTXT:
691 isis_area_passwd_cleartext_set(area, IS_LEVEL_2, password,
692 snp_auth);
693 break;
694 case ISIS_PASSWD_TYPE_HMAC_MD5:
695 isis_area_passwd_hmac_md5_set(area, IS_LEVEL_2, password,
696 snp_auth);
697 break;
698 }
699 }
700
701 int isis_instance_domain_password_create(struct nb_cb_create_args *args)
702 {
703 /* actual setting is done in apply_finish */
704 return NB_OK;
705 }
706
707 int isis_instance_domain_password_destroy(struct nb_cb_destroy_args *args)
708 {
709 struct isis_area *area;
710
711 if (args->event != NB_EV_APPLY)
712 return NB_OK;
713
714 area = nb_running_get_entry(args->dnode, NULL, true);
715 isis_area_passwd_unset(area, IS_LEVEL_2);
716
717 return NB_OK;
718 }
719
720 /*
721 * XPath: /frr-isisd:isis/instance/domain-password/password
722 */
723 int isis_instance_domain_password_password_modify(
724 struct nb_cb_modify_args *args)
725 {
726 /* actual setting is done in apply_finish */
727 return NB_OK;
728 }
729
730 /*
731 * XPath: /frr-isisd:isis/instance/domain-password/password-type
732 */
733 int isis_instance_domain_password_password_type_modify(
734 struct nb_cb_modify_args *args)
735 {
736 /* actual setting is done in apply_finish */
737 return NB_OK;
738 }
739
740 /*
741 * XPath: /frr-isisd:isis/instance/domain-password/authenticate-snp
742 */
743 int isis_instance_domain_password_authenticate_snp_modify(
744 struct nb_cb_modify_args *args)
745 {
746 /* actual setting is done in apply_finish */
747 return NB_OK;
748 }
749
750 /*
751 * XPath: /frr-isisd:isis/instance/default-information-originate/ipv4
752 */
753 void default_info_origin_apply_finish(const struct lyd_node *dnode, int family)
754 {
755 int originate_type = DEFAULT_ORIGINATE;
756 unsigned long metric = 0;
757 const char *routemap = NULL;
758 struct isis_area *area = nb_running_get_entry(dnode, NULL, true);
759 int level = yang_dnode_get_enum(dnode, "./level");
760
761 if (yang_dnode_get_bool(dnode, "./always")) {
762 originate_type = DEFAULT_ORIGINATE_ALWAYS;
763 } else if (family == AF_INET6) {
764 zlog_warn(
765 "%s: Zebra doesn't implement default-originate for IPv6 yet, so use with care or use default-originate always.",
766 __func__);
767 }
768
769 if (yang_dnode_exists(dnode, "./metric"))
770 metric = yang_dnode_get_uint32(dnode, "./metric");
771 if (yang_dnode_exists(dnode, "./route-map"))
772 routemap = yang_dnode_get_string(dnode, "./route-map");
773
774 isis_redist_set(area, level, family, DEFAULT_ROUTE, metric, routemap,
775 originate_type);
776 }
777
778 void default_info_origin_ipv4_apply_finish(struct nb_cb_apply_finish_args *args)
779 {
780 default_info_origin_apply_finish(args->dnode, AF_INET);
781 }
782
783 void default_info_origin_ipv6_apply_finish(struct nb_cb_apply_finish_args *args)
784 {
785 default_info_origin_apply_finish(args->dnode, AF_INET6);
786 }
787
788 int isis_instance_default_information_originate_ipv4_create(
789 struct nb_cb_create_args *args)
790 {
791 /* It's all done by default_info_origin_apply_finish */
792 return NB_OK;
793 }
794
795 int isis_instance_default_information_originate_ipv4_destroy(
796 struct nb_cb_destroy_args *args)
797 {
798 struct isis_area *area;
799 int level;
800
801 if (args->event != NB_EV_APPLY)
802 return NB_OK;
803
804 area = nb_running_get_entry(args->dnode, NULL, true);
805 level = yang_dnode_get_enum(args->dnode, "./level");
806 isis_redist_unset(area, level, AF_INET, DEFAULT_ROUTE);
807
808 return NB_OK;
809 }
810
811 /*
812 * XPath: /frr-isisd:isis/instance/default-information-originate/ipv4/always
813 */
814 int isis_instance_default_information_originate_ipv4_always_modify(
815 struct nb_cb_modify_args *args)
816 {
817 /* It's all done by default_info_origin_apply_finish */
818 return NB_OK;
819 }
820
821 /*
822 * XPath: /frr-isisd:isis/instance/default-information-originate/ipv4/route-map
823 */
824 int isis_instance_default_information_originate_ipv4_route_map_modify(
825 struct nb_cb_modify_args *args)
826 {
827 /* It's all done by default_info_origin_apply_finish */
828 return NB_OK;
829 }
830
831 int isis_instance_default_information_originate_ipv4_route_map_destroy(
832 struct nb_cb_destroy_args *args)
833 {
834 /* It's all done by default_info_origin_apply_finish */
835 return NB_OK;
836 }
837
838 /*
839 * XPath: /frr-isisd:isis/instance/default-information-originate/ipv4/metric
840 */
841 int isis_instance_default_information_originate_ipv4_metric_modify(
842 struct nb_cb_modify_args *args)
843 {
844 /* It's all done by default_info_origin_apply_finish */
845 return NB_OK;
846 }
847
848 /*
849 * XPath: /frr-isisd:isis/instance/default-information-originate/ipv6
850 */
851 int isis_instance_default_information_originate_ipv6_create(
852 struct nb_cb_create_args *args)
853 {
854 /* It's all done by default_info_origin_apply_finish */
855 return NB_OK;
856 }
857
858 int isis_instance_default_information_originate_ipv6_destroy(
859 struct nb_cb_destroy_args *args)
860 {
861 struct isis_area *area;
862 int level;
863
864 if (args->event != NB_EV_APPLY)
865 return NB_OK;
866
867 area = nb_running_get_entry(args->dnode, NULL, true);
868 level = yang_dnode_get_enum(args->dnode, "./level");
869 isis_redist_unset(area, level, AF_INET6, DEFAULT_ROUTE);
870
871 return NB_OK;
872 }
873
874 /*
875 * XPath: /frr-isisd:isis/instance/default-information-originate/ipv6/always
876 */
877 int isis_instance_default_information_originate_ipv6_always_modify(
878 struct nb_cb_modify_args *args)
879 {
880 /* It's all done by default_info_origin_apply_finish */
881 return NB_OK;
882 }
883
884 /*
885 * XPath: /frr-isisd:isis/instance/default-information-originate/ipv6/route-map
886 */
887 int isis_instance_default_information_originate_ipv6_route_map_modify(
888 struct nb_cb_modify_args *args)
889 {
890 /* It's all done by default_info_origin_apply_finish */
891 return NB_OK;
892 }
893
894 int isis_instance_default_information_originate_ipv6_route_map_destroy(
895 struct nb_cb_destroy_args *args)
896 {
897 /* It's all done by default_info_origin_apply_finish */
898 return NB_OK;
899 }
900
901 /*
902 * XPath: /frr-isisd:isis/instance/default-information-originate/ipv6/metric
903 */
904 int isis_instance_default_information_originate_ipv6_metric_modify(
905 struct nb_cb_modify_args *args)
906 {
907 /* It's all done by default_info_origin_apply_finish */
908 return NB_OK;
909 }
910
911 /*
912 * XPath: /frr-isisd:isis/instance/redistribute/ipv4
913 */
914 void redistribute_apply_finish(const struct lyd_node *dnode, int family)
915 {
916 assert(family == AF_INET || family == AF_INET6);
917 int type, level;
918 unsigned long metric = 0;
919 const char *routemap = NULL;
920 struct isis_area *area;
921
922 type = yang_dnode_get_enum(dnode, "./protocol");
923 level = yang_dnode_get_enum(dnode, "./level");
924 area = nb_running_get_entry(dnode, NULL, true);
925
926 if (yang_dnode_exists(dnode, "./metric"))
927 metric = yang_dnode_get_uint32(dnode, "./metric");
928 if (yang_dnode_exists(dnode, "./route-map"))
929 routemap = yang_dnode_get_string(dnode, "./route-map");
930
931 isis_redist_set(area, level, family, type, metric, routemap, 0);
932 }
933
934 void redistribute_ipv4_apply_finish(struct nb_cb_apply_finish_args *args)
935 {
936 redistribute_apply_finish(args->dnode, AF_INET);
937 }
938
939 void redistribute_ipv6_apply_finish(struct nb_cb_apply_finish_args *args)
940 {
941 redistribute_apply_finish(args->dnode, AF_INET6);
942 }
943
944 int isis_instance_redistribute_ipv4_create(struct nb_cb_create_args *args)
945 {
946 /* It's all done by redistribute_apply_finish */
947 return NB_OK;
948 }
949
950 int isis_instance_redistribute_ipv4_destroy(struct nb_cb_destroy_args *args)
951 {
952 struct isis_area *area;
953 int level, type;
954
955 if (args->event != NB_EV_APPLY)
956 return NB_OK;
957
958 area = nb_running_get_entry(args->dnode, NULL, true);
959 level = yang_dnode_get_enum(args->dnode, "./level");
960 type = yang_dnode_get_enum(args->dnode, "./protocol");
961 isis_redist_unset(area, level, AF_INET, type);
962
963 return NB_OK;
964 }
965
966 /*
967 * XPath: /frr-isisd:isis/instance/redistribute/ipv4/route-map
968 */
969 int isis_instance_redistribute_ipv4_route_map_modify(
970 struct nb_cb_modify_args *args)
971 {
972 /* It's all done by redistribute_apply_finish */
973 return NB_OK;
974 }
975
976 int isis_instance_redistribute_ipv4_route_map_destroy(
977 struct nb_cb_destroy_args *args)
978 {
979 /* It's all done by redistribute_apply_finish */
980 return NB_OK;
981 }
982
983 /*
984 * XPath: /frr-isisd:isis/instance/redistribute/ipv4/metric
985 */
986 int isis_instance_redistribute_ipv4_metric_modify(
987 struct nb_cb_modify_args *args)
988 {
989 /* It's all done by redistribute_apply_finish */
990 return NB_OK;
991 }
992
993 /*
994 * XPath: /frr-isisd:isis/instance/redistribute/ipv6
995 */
996 int isis_instance_redistribute_ipv6_create(struct nb_cb_create_args *args)
997 {
998 /* It's all done by redistribute_apply_finish */
999 return NB_OK;
1000 }
1001
1002 int isis_instance_redistribute_ipv6_destroy(struct nb_cb_destroy_args *args)
1003 {
1004 struct isis_area *area;
1005 int level, type;
1006
1007 if (args->event != NB_EV_APPLY)
1008 return NB_OK;
1009
1010 area = nb_running_get_entry(args->dnode, NULL, true);
1011 level = yang_dnode_get_enum(args->dnode, "./level");
1012 type = yang_dnode_get_enum(args->dnode, "./protocol");
1013 isis_redist_unset(area, level, AF_INET6, type);
1014
1015 return NB_OK;
1016 }
1017
1018 /*
1019 * XPath: /frr-isisd:isis/instance/redistribute/ipv6/route-map
1020 */
1021 int isis_instance_redistribute_ipv6_route_map_modify(
1022 struct nb_cb_modify_args *args)
1023 {
1024 /* It's all done by redistribute_apply_finish */
1025 return NB_OK;
1026 }
1027
1028 int isis_instance_redistribute_ipv6_route_map_destroy(
1029 struct nb_cb_destroy_args *args)
1030 {
1031 /* It's all done by redistribute_apply_finish */
1032 return NB_OK;
1033 }
1034
1035 /*
1036 * XPath: /frr-isisd:isis/instance/redistribute/ipv6/metric
1037 */
1038 int isis_instance_redistribute_ipv6_metric_modify(
1039 struct nb_cb_modify_args *args)
1040 {
1041 /* It's all done by redistribute_apply_finish */
1042 return NB_OK;
1043 }
1044
1045 /*
1046 * XPath: /frr-isisd:isis/instance/multi-topology/ipv4-multicast
1047 */
1048 static int isis_multi_topology_common(enum nb_event event,
1049 const struct lyd_node *dnode,
1050 const char *topology, bool create)
1051 {
1052 struct isis_area *area;
1053 struct isis_area_mt_setting *setting;
1054 uint16_t mtid = isis_str2mtid(topology);
1055
1056 switch (event) {
1057 case NB_EV_VALIDATE:
1058 if (mtid == (uint16_t)-1) {
1059 flog_warn(EC_LIB_NB_CB_CONFIG_VALIDATE,
1060 "Unknown topology %s", topology);
1061 return NB_ERR_VALIDATION;
1062 }
1063 break;
1064 case NB_EV_PREPARE:
1065 case NB_EV_ABORT:
1066 break;
1067 case NB_EV_APPLY:
1068 area = nb_running_get_entry(dnode, NULL, true);
1069 setting = area_get_mt_setting(area, mtid);
1070 setting->enabled = create;
1071 lsp_regenerate_schedule(area, IS_LEVEL_1 | IS_LEVEL_2, 0);
1072 break;
1073 }
1074
1075 return NB_OK;
1076 }
1077
1078 static int isis_multi_topology_overload_common(enum nb_event event,
1079 const struct lyd_node *dnode,
1080 const char *topology)
1081 {
1082 struct isis_area *area;
1083 struct isis_area_mt_setting *setting;
1084 uint16_t mtid = isis_str2mtid(topology);
1085
1086 /* validation is done in isis_multi_topology_common */
1087 if (event != NB_EV_APPLY)
1088 return NB_OK;
1089
1090 area = nb_running_get_entry(dnode, NULL, true);
1091 setting = area_get_mt_setting(area, mtid);
1092 setting->overload = yang_dnode_get_bool(dnode, NULL);
1093 if (setting->enabled)
1094 lsp_regenerate_schedule(area, IS_LEVEL_1 | IS_LEVEL_2, 0);
1095
1096 return NB_OK;
1097 }
1098
1099 int isis_instance_multi_topology_ipv4_multicast_create(
1100 struct nb_cb_create_args *args)
1101 {
1102 return isis_multi_topology_common(args->event, args->dnode,
1103 "ipv4-multicast", true);
1104 }
1105
1106 int isis_instance_multi_topology_ipv4_multicast_destroy(
1107 struct nb_cb_destroy_args *args)
1108 {
1109 return isis_multi_topology_common(args->event, args->dnode,
1110 "ipv4-multicast", false);
1111 }
1112
1113 /*
1114 * XPath: /frr-isisd:isis/instance/multi-topology/ipv4-multicast/overload
1115 */
1116 int isis_instance_multi_topology_ipv4_multicast_overload_modify(
1117 struct nb_cb_modify_args *args)
1118 {
1119 return isis_multi_topology_overload_common(args->event, args->dnode,
1120 "ipv4-multicast");
1121 }
1122
1123 /*
1124 * XPath: /frr-isisd:isis/instance/multi-topology/ipv4-management
1125 */
1126 int isis_instance_multi_topology_ipv4_management_create(
1127 struct nb_cb_create_args *args)
1128 {
1129 return isis_multi_topology_common(args->event, args->dnode, "ipv4-mgmt",
1130 true);
1131 }
1132
1133 int isis_instance_multi_topology_ipv4_management_destroy(
1134 struct nb_cb_destroy_args *args)
1135 {
1136 return isis_multi_topology_common(args->event, args->dnode, "ipv4-mgmt",
1137 false);
1138 }
1139
1140 /*
1141 * XPath: /frr-isisd:isis/instance/multi-topology/ipv4-management/overload
1142 */
1143 int isis_instance_multi_topology_ipv4_management_overload_modify(
1144 struct nb_cb_modify_args *args)
1145 {
1146 return isis_multi_topology_overload_common(args->event, args->dnode,
1147 "ipv4-mgmt");
1148 }
1149
1150 /*
1151 * XPath: /frr-isisd:isis/instance/multi-topology/ipv6-unicast
1152 */
1153 int isis_instance_multi_topology_ipv6_unicast_create(
1154 struct nb_cb_create_args *args)
1155 {
1156 return isis_multi_topology_common(args->event, args->dnode,
1157 "ipv6-unicast", true);
1158 }
1159
1160 int isis_instance_multi_topology_ipv6_unicast_destroy(
1161 struct nb_cb_destroy_args *args)
1162 {
1163 return isis_multi_topology_common(args->event, args->dnode,
1164 "ipv6-unicast", false);
1165 }
1166
1167 /*
1168 * XPath: /frr-isisd:isis/instance/multi-topology/ipv6-unicast/overload
1169 */
1170 int isis_instance_multi_topology_ipv6_unicast_overload_modify(
1171 struct nb_cb_modify_args *args)
1172 {
1173 return isis_multi_topology_overload_common(args->event, args->dnode,
1174 "ipv6-unicast");
1175 }
1176
1177 /*
1178 * XPath: /frr-isisd:isis/instance/multi-topology/ipv6-multicast
1179 */
1180 int isis_instance_multi_topology_ipv6_multicast_create(
1181 struct nb_cb_create_args *args)
1182 {
1183 return isis_multi_topology_common(args->event, args->dnode,
1184 "ipv6-multicast", true);
1185 }
1186
1187 int isis_instance_multi_topology_ipv6_multicast_destroy(
1188 struct nb_cb_destroy_args *args)
1189 {
1190 return isis_multi_topology_common(args->event, args->dnode,
1191 "ipv6-multicast", false);
1192 }
1193
1194 /*
1195 * XPath: /frr-isisd:isis/instance/multi-topology/ipv6-multicast/overload
1196 */
1197 int isis_instance_multi_topology_ipv6_multicast_overload_modify(
1198 struct nb_cb_modify_args *args)
1199 {
1200 return isis_multi_topology_overload_common(args->event, args->dnode,
1201 "ipv6-multicast");
1202 }
1203
1204 /*
1205 * XPath: /frr-isisd:isis/instance/multi-topology/ipv6-management
1206 */
1207 int isis_instance_multi_topology_ipv6_management_create(
1208 struct nb_cb_create_args *args)
1209 {
1210 return isis_multi_topology_common(args->event, args->dnode, "ipv6-mgmt",
1211 true);
1212 }
1213
1214 int isis_instance_multi_topology_ipv6_management_destroy(
1215 struct nb_cb_destroy_args *args)
1216 {
1217 return isis_multi_topology_common(args->event, args->dnode, "ipv6-mgmt",
1218 false);
1219 }
1220
1221 /*
1222 * XPath: /frr-isisd:isis/instance/multi-topology/ipv6-management/overload
1223 */
1224 int isis_instance_multi_topology_ipv6_management_overload_modify(
1225 struct nb_cb_modify_args *args)
1226 {
1227 return isis_multi_topology_overload_common(args->event, args->dnode,
1228 "ipv6-mgmt");
1229 }
1230
1231 /*
1232 * XPath: /frr-isisd:isis/instance/multi-topology/ipv6-dstsrc
1233 */
1234 int isis_instance_multi_topology_ipv6_dstsrc_create(
1235 struct nb_cb_create_args *args)
1236 {
1237 return isis_multi_topology_common(args->event, args->dnode,
1238 "ipv6-dstsrc", true);
1239 }
1240
1241 int isis_instance_multi_topology_ipv6_dstsrc_destroy(
1242 struct nb_cb_destroy_args *args)
1243 {
1244 return isis_multi_topology_common(args->event, args->dnode,
1245 "ipv6-dstsrc", false);
1246 }
1247
1248 /*
1249 * XPath: /frr-isisd:isis/instance/multi-topology/ipv6-dstsrc/overload
1250 */
1251 int isis_instance_multi_topology_ipv6_dstsrc_overload_modify(
1252 struct nb_cb_modify_args *args)
1253 {
1254 return isis_multi_topology_overload_common(args->event, args->dnode,
1255 "ipv6-dstsrc");
1256 }
1257
1258 /*
1259 * XPath: /frr-isisd:isis/instance/log-adjacency-changes
1260 */
1261 int isis_instance_log_adjacency_changes_modify(struct nb_cb_modify_args *args)
1262 {
1263 struct isis_area *area;
1264 bool log = yang_dnode_get_bool(args->dnode, NULL);
1265
1266 if (args->event != NB_EV_APPLY)
1267 return NB_OK;
1268
1269 area = nb_running_get_entry(args->dnode, NULL, true);
1270 area->log_adj_changes = log ? 1 : 0;
1271
1272 return NB_OK;
1273 }
1274
1275 /*
1276 * XPath: /frr-isisd:isis/instance/mpls-te
1277 */
1278 int isis_instance_mpls_te_create(struct nb_cb_create_args *args)
1279 {
1280 struct listnode *node;
1281 struct isis_area *area;
1282 struct isis_circuit *circuit;
1283
1284 if (args->event != NB_EV_APPLY)
1285 return NB_OK;
1286
1287 area = nb_running_get_entry(args->dnode, NULL, true);
1288 if (area->mta == NULL) {
1289
1290 struct mpls_te_area *new;
1291
1292 zlog_debug("ISIS-TE(%s): Initialize MPLS Traffic Engineering",
1293 area->area_tag);
1294
1295 new = XCALLOC(MTYPE_ISIS_MPLS_TE, sizeof(struct mpls_te_area));
1296
1297 /* Initialize MPLS_TE structure */
1298 new->status = enable;
1299 new->level = 0;
1300 new->inter_as = off;
1301 new->interas_areaid.s_addr = 0;
1302 new->router_id.s_addr = 0;
1303
1304 area->mta = new;
1305 } else {
1306 area->mta->status = enable;
1307 }
1308
1309 /* Update Extended TLVs according to Interface link parameters */
1310 for (ALL_LIST_ELEMENTS_RO(area->circuit_list, node, circuit))
1311 isis_link_params_update(circuit, circuit->interface);
1312
1313 /* Reoriginate STD_TE & GMPLS circuits */
1314 lsp_regenerate_schedule(area, area->is_type, 0);
1315
1316 return NB_OK;
1317 }
1318
1319 int isis_instance_mpls_te_destroy(struct nb_cb_destroy_args *args)
1320 {
1321 struct listnode *node;
1322 struct isis_area *area;
1323 struct isis_circuit *circuit;
1324
1325 if (args->event != NB_EV_APPLY)
1326 return NB_OK;
1327
1328 area = nb_running_get_entry(args->dnode, NULL, true);
1329 if (IS_MPLS_TE(area->mta))
1330 area->mta->status = disable;
1331 else
1332 return NB_OK;
1333
1334 /* Flush LSP if circuit engage */
1335 for (ALL_LIST_ELEMENTS_RO(area->circuit_list, node, circuit)) {
1336 if (!IS_EXT_TE(circuit->ext))
1337 continue;
1338
1339 /* disable MPLS_TE Circuit keeping SR one's */
1340 if (IS_SUBTLV(circuit->ext, EXT_ADJ_SID))
1341 circuit->ext->status = EXT_ADJ_SID;
1342 else if (IS_SUBTLV(circuit->ext, EXT_LAN_ADJ_SID))
1343 circuit->ext->status = EXT_LAN_ADJ_SID;
1344 else
1345 circuit->ext->status = 0;
1346 }
1347
1348 /* Reoriginate STD_TE & GMPLS circuits */
1349 lsp_regenerate_schedule(area, area->is_type, 0);
1350
1351 zlog_debug("ISIS-TE(%s): Disabled MPLS Traffic Engineering",
1352 area->area_tag);
1353
1354 return NB_OK;
1355 }
1356
1357 /*
1358 * XPath: /frr-isisd:isis/instance/mpls-te/router-address
1359 */
1360 int isis_instance_mpls_te_router_address_modify(struct nb_cb_modify_args *args)
1361 {
1362 struct in_addr value;
1363 struct isis_area *area;
1364
1365 if (args->event != NB_EV_APPLY)
1366 return NB_OK;
1367
1368 area = nb_running_get_entry(args->dnode, NULL, true);
1369 /* only proceed if MPLS-TE is enabled */
1370 if (!IS_MPLS_TE(area->mta))
1371 return NB_OK;
1372
1373 /* Update Area Router ID */
1374 yang_dnode_get_ipv4(&value, args->dnode, NULL);
1375 area->mta->router_id.s_addr = value.s_addr;
1376
1377 /* And re-schedule LSP update */
1378 lsp_regenerate_schedule(area, area->is_type, 0);
1379
1380 return NB_OK;
1381 }
1382
1383 int isis_instance_mpls_te_router_address_destroy(
1384 struct nb_cb_destroy_args *args)
1385 {
1386 struct isis_area *area;
1387
1388 if (args->event != NB_EV_APPLY)
1389 return NB_OK;
1390
1391 area = nb_running_get_entry(args->dnode, NULL, true);
1392 /* only proceed if MPLS-TE is enabled */
1393 if (!IS_MPLS_TE(area->mta))
1394 return NB_OK;
1395
1396 /* Reset Area Router ID */
1397 area->mta->router_id.s_addr = INADDR_ANY;
1398
1399 /* And re-schedule LSP update */
1400 lsp_regenerate_schedule(area, area->is_type, 0);
1401
1402 return NB_OK;
1403 }
1404
1405 /*
1406 * XPath: /frr-isisd:isis/instance/segment-routing/enabled
1407 */
1408 int isis_instance_segment_routing_enabled_modify(
1409 struct nb_cb_modify_args *args)
1410 {
1411 struct isis_area *area;
1412
1413 if (args->event != NB_EV_APPLY)
1414 return NB_OK;
1415
1416 area = nb_running_get_entry(args->dnode, NULL, true);
1417 area->srdb.config.enabled = yang_dnode_get_bool(args->dnode, NULL);
1418
1419 if (area->srdb.config.enabled) {
1420 if (IS_DEBUG_ISIS(DEBUG_EVENTS))
1421 zlog_debug("SR: Segment Routing: OFF -> ON");
1422
1423 if (isis_sr_start(area) == 0)
1424 area->srdb.enabled = true;
1425 } else {
1426 if (IS_DEBUG_ISIS(DEBUG_EVENTS))
1427 zlog_debug("SR: Segment Routing: ON -> OFF");
1428
1429 isis_sr_stop(area);
1430 area->srdb.enabled = false;
1431 }
1432
1433 return NB_OK;
1434 }
1435
1436 /*
1437 * XPath: /frr-isisd:isis/instance/segment-routing/srgb
1438 */
1439 void isis_instance_segment_routing_srgb_apply_finish(
1440 struct nb_cb_apply_finish_args *args)
1441 {
1442 struct isis_area *area;
1443 uint32_t lower_bound, upper_bound;
1444 int ret;
1445
1446 area = nb_running_get_entry(args->dnode, NULL, true);
1447 lower_bound = yang_dnode_get_uint32(args->dnode, "./lower-bound");
1448 upper_bound = yang_dnode_get_uint32(args->dnode, "./upper-bound");
1449
1450 ret = isis_sr_cfg_srgb_update(area, lower_bound, upper_bound);
1451 if (area->srdb.config.enabled) {
1452 if (ret == 0)
1453 area->srdb.enabled = true;
1454 else {
1455 isis_sr_stop(area);
1456 area->srdb.enabled = false;
1457 }
1458 }
1459 }
1460
1461 /*
1462 * XPath: /frr-isisd:isis/instance/segment-routing/srgb/lower-bound
1463 */
1464 int isis_instance_segment_routing_srgb_lower_bound_modify(
1465 struct nb_cb_modify_args *args)
1466 {
1467 uint32_t lower_bound = yang_dnode_get_uint32(args->dnode, NULL);
1468
1469 switch (args->event) {
1470 case NB_EV_VALIDATE:
1471 if (!IS_MPLS_UNRESERVED_LABEL(lower_bound)) {
1472 zlog_warn("Invalid SRGB lower bound: %" PRIu32,
1473 lower_bound);
1474 return NB_ERR_VALIDATION;
1475 }
1476 break;
1477 case NB_EV_PREPARE:
1478 case NB_EV_ABORT:
1479 case NB_EV_APPLY:
1480 break;
1481 }
1482
1483 return NB_OK;
1484 }
1485
1486 /*
1487 * XPath: /frr-isisd:isis/instance/segment-routing/srgb/upper-bound
1488 */
1489 int isis_instance_segment_routing_srgb_upper_bound_modify(
1490 struct nb_cb_modify_args *args)
1491 {
1492 uint32_t upper_bound = yang_dnode_get_uint32(args->dnode, NULL);
1493
1494 switch (args->event) {
1495 case NB_EV_VALIDATE:
1496 if (!IS_MPLS_UNRESERVED_LABEL(upper_bound)) {
1497 zlog_warn("Invalid SRGB upper bound: %" PRIu32,
1498 upper_bound);
1499 return NB_ERR_VALIDATION;
1500 }
1501 break;
1502 case NB_EV_PREPARE:
1503 case NB_EV_ABORT:
1504 case NB_EV_APPLY:
1505 break;
1506 }
1507
1508 return NB_OK;
1509 }
1510
1511 /*
1512 * XPath: /frr-isisd:isis/instance/segment-routing/msd/node-msd
1513 */
1514 int isis_instance_segment_routing_msd_node_msd_modify(
1515 struct nb_cb_modify_args *args)
1516 {
1517 struct isis_area *area;
1518
1519 if (args->event != NB_EV_APPLY)
1520 return NB_OK;
1521
1522 area = nb_running_get_entry(args->dnode, NULL, true);
1523 area->srdb.config.msd = yang_dnode_get_uint8(args->dnode, NULL);
1524
1525 /* Update and regenerate LSP */
1526 lsp_regenerate_schedule(area, area->is_type, 0);
1527
1528 return NB_OK;
1529 }
1530
1531 int isis_instance_segment_routing_msd_node_msd_destroy(
1532 struct nb_cb_destroy_args *args)
1533 {
1534 struct isis_area *area;
1535
1536 if (args->event != NB_EV_APPLY)
1537 return NB_OK;
1538
1539 area = nb_running_get_entry(args->dnode, NULL, true);
1540 area->srdb.config.msd = 0;
1541
1542 /* Update and regenerate LSP */
1543 lsp_regenerate_schedule(area, area->is_type, 0);
1544
1545 return NB_OK;
1546 }
1547
1548 /*
1549 * XPath: /frr-isisd:isis/instance/segment-routing/prefix-sid-map/prefix-sid
1550 */
1551 int isis_instance_segment_routing_prefix_sid_map_prefix_sid_create(
1552 struct nb_cb_create_args *args)
1553 {
1554 struct isis_area *area;
1555 struct prefix prefix;
1556 struct sr_prefix_cfg *pcfg;
1557
1558 if (args->event != NB_EV_APPLY)
1559 return NB_OK;
1560
1561 area = nb_running_get_entry(args->dnode, NULL, true);
1562 yang_dnode_get_prefix(&prefix, args->dnode, "./prefix");
1563
1564 pcfg = isis_sr_cfg_prefix_add(area, &prefix);
1565 nb_running_set_entry(args->dnode, pcfg);
1566
1567 return NB_OK;
1568 }
1569
1570 int isis_instance_segment_routing_prefix_sid_map_prefix_sid_destroy(
1571 struct nb_cb_destroy_args *args)
1572 {
1573 struct sr_prefix_cfg *pcfg;
1574 struct isis_area *area;
1575
1576 if (args->event != NB_EV_APPLY)
1577 return NB_OK;
1578
1579 pcfg = nb_running_unset_entry(args->dnode);
1580 area = pcfg->area;
1581 isis_sr_cfg_prefix_del(pcfg);
1582 lsp_regenerate_schedule(area, area->is_type, 0);
1583
1584 return NB_OK;
1585 }
1586
1587 int isis_instance_segment_routing_prefix_sid_map_prefix_sid_pre_validate(
1588 struct nb_cb_pre_validate_args *args)
1589 {
1590 uint32_t srgb_lbound;
1591 uint32_t srgb_ubound;
1592 uint32_t srgb_range;
1593 uint32_t sid;
1594 enum sr_sid_value_type sid_type;
1595
1596 srgb_lbound = yang_dnode_get_uint32(args->dnode,
1597 "../../srgb/lower-bound");
1598 srgb_ubound = yang_dnode_get_uint32(args->dnode,
1599 "../../srgb/upper-bound");
1600 sid = yang_dnode_get_uint32(args->dnode, "./sid-value");
1601 sid_type = yang_dnode_get_enum(args->dnode, "./sid-value-type");
1602
1603 srgb_range = srgb_ubound - srgb_lbound + 1;
1604 switch (sid_type) {
1605 case SR_SID_VALUE_TYPE_INDEX:
1606 if (sid >= srgb_range) {
1607 zlog_warn("SID index %u falls outside local SRGB range",
1608 sid);
1609 return NB_ERR_VALIDATION;
1610 }
1611 break;
1612 case SR_SID_VALUE_TYPE_ABSOLUTE:
1613 if (!IS_MPLS_UNRESERVED_LABEL(sid)) {
1614 zlog_warn("Invalid absolute SID %u", sid);
1615 return NB_ERR_VALIDATION;
1616 }
1617 break;
1618 }
1619
1620 return NB_OK;
1621 }
1622
1623 void isis_instance_segment_routing_prefix_sid_map_prefix_sid_apply_finish(
1624 struct nb_cb_apply_finish_args *args)
1625 {
1626 struct sr_prefix_cfg *pcfg;
1627 struct isis_area *area;
1628
1629 pcfg = nb_running_get_entry(args->dnode, NULL, true);
1630 area = pcfg->area;
1631 lsp_regenerate_schedule(area, area->is_type, 0);
1632 }
1633
1634 /*
1635 * XPath:
1636 * /frr-isisd:isis/instance/segment-routing/prefix-sid-map/prefix-sid/sid-value-type
1637 */
1638 int isis_instance_segment_routing_prefix_sid_map_prefix_sid_sid_value_type_modify(
1639 struct nb_cb_modify_args *args)
1640 {
1641 struct sr_prefix_cfg *pcfg;
1642
1643 if (args->event != NB_EV_APPLY)
1644 return NB_OK;
1645
1646 pcfg = nb_running_get_entry(args->dnode, NULL, true);
1647 pcfg->sid_type = yang_dnode_get_enum(args->dnode, NULL);
1648
1649 return NB_OK;
1650 }
1651
1652 /*
1653 * XPath:
1654 * /frr-isisd:isis/instance/segment-routing/prefix-sid-map/prefix-sid/sid-value
1655 */
1656 int isis_instance_segment_routing_prefix_sid_map_prefix_sid_sid_value_modify(
1657 struct nb_cb_modify_args *args)
1658 {
1659 struct sr_prefix_cfg *pcfg;
1660
1661 if (args->event != NB_EV_APPLY)
1662 return NB_OK;
1663
1664 pcfg = nb_running_get_entry(args->dnode, NULL, true);
1665 pcfg->sid = yang_dnode_get_uint32(args->dnode, NULL);
1666
1667 return NB_OK;
1668 }
1669
1670 /*
1671 * XPath:
1672 * /frr-isisd:isis/instance/segment-routing/prefix-sid-map/prefix-sid/last-hop-behavior
1673 */
1674 int isis_instance_segment_routing_prefix_sid_map_prefix_sid_last_hop_behavior_modify(
1675 struct nb_cb_modify_args *args)
1676 {
1677 struct sr_prefix_cfg *pcfg;
1678
1679 if (args->event != NB_EV_APPLY)
1680 return NB_OK;
1681
1682 pcfg = nb_running_get_entry(args->dnode, NULL, true);
1683 pcfg->last_hop_behavior = yang_dnode_get_enum(args->dnode, NULL);
1684
1685 return NB_OK;
1686 }
1687
1688 /*
1689 * XPath: /frr-interface:lib/interface/frr-isisd:isis
1690 */
1691 int lib_interface_isis_create(struct nb_cb_create_args *args)
1692 {
1693 struct isis_area *area;
1694 struct interface *ifp;
1695 struct isis_circuit *circuit;
1696 const char *area_tag = yang_dnode_get_string(args->dnode, "./area-tag");
1697 uint32_t min_mtu, actual_mtu;
1698
1699 switch (args->event) {
1700 case NB_EV_PREPARE:
1701 case NB_EV_ABORT:
1702 break;
1703 case NB_EV_VALIDATE:
1704 /* check if interface mtu is sufficient. If the area has not
1705 * been created yet, assume default MTU for the area
1706 */
1707 ifp = nb_running_get_entry(args->dnode, NULL, false);
1708 /* zebra might not know yet about the MTU - nothing we can do */
1709 if (!ifp || ifp->mtu == 0)
1710 break;
1711 actual_mtu =
1712 if_is_broadcast(ifp) ? ifp->mtu - LLC_LEN : ifp->mtu;
1713 area = isis_area_lookup(area_tag);
1714 if (area)
1715 min_mtu = area->lsp_mtu;
1716 else
1717 #ifndef FABRICD
1718 min_mtu = yang_get_default_uint16(
1719 "/frr-isisd:isis/instance/lsp/mtu");
1720 #else
1721 min_mtu = DEFAULT_LSP_MTU;
1722 #endif /* ifndef FABRICD */
1723 if (actual_mtu < min_mtu) {
1724 flog_warn(EC_LIB_NB_CB_CONFIG_VALIDATE,
1725 "Interface %s has MTU %" PRIu32
1726 ", minimum MTU for the area is %" PRIu32 "",
1727 ifp->name, actual_mtu, min_mtu);
1728 return NB_ERR_VALIDATION;
1729 }
1730 break;
1731 case NB_EV_APPLY:
1732 area = isis_area_lookup(area_tag);
1733 /* The area should have already be created. We are
1734 * setting the priority of the global isis area creation
1735 * slightly lower, so it should be executed first, but I
1736 * cannot rely on that so here I have to check.
1737 */
1738 if (!area) {
1739 flog_err(
1740 EC_LIB_NB_CB_CONFIG_APPLY,
1741 "%s: attempt to create circuit for area %s before the area has been created",
1742 __func__, area_tag);
1743 abort();
1744 }
1745
1746 ifp = nb_running_get_entry(args->dnode, NULL, true);
1747 circuit = isis_circuit_create(area, ifp);
1748 assert(circuit
1749 && (circuit->state == C_STATE_CONF
1750 || circuit->state == C_STATE_UP));
1751 nb_running_set_entry(args->dnode, circuit);
1752 break;
1753 }
1754
1755 return NB_OK;
1756 }
1757
1758 int lib_interface_isis_destroy(struct nb_cb_destroy_args *args)
1759 {
1760 struct isis_circuit *circuit;
1761
1762 if (args->event != NB_EV_APPLY)
1763 return NB_OK;
1764
1765 circuit = nb_running_unset_entry(args->dnode);
1766 if (!circuit)
1767 return NB_ERR_INCONSISTENCY;
1768
1769 /* disable both AFs for this circuit. this will also update the
1770 * CSM state by sending an ISIS_DISABLED signal. If there is no
1771 * area associated to the circuit there is nothing to do
1772 */
1773 if (circuit->area)
1774 isis_circuit_af_set(circuit, false, false);
1775 return NB_OK;
1776 }
1777
1778 /*
1779 * XPath: /frr-interface:lib/interface/frr-isisd:isis/area-tag
1780 */
1781 int lib_interface_isis_area_tag_modify(struct nb_cb_modify_args *args)
1782 {
1783 struct isis_circuit *circuit;
1784 struct interface *ifp;
1785 struct vrf *vrf;
1786 const char *area_tag, *ifname, *vrfname;
1787
1788 if (args->event == NB_EV_VALIDATE) {
1789 /* libyang doesn't like relative paths across module boundaries
1790 */
1791 ifname = yang_dnode_get_string(args->dnode->parent->parent,
1792 "./name");
1793 vrfname = yang_dnode_get_string(args->dnode->parent->parent,
1794 "./vrf");
1795 vrf = vrf_lookup_by_name(vrfname);
1796 assert(vrf);
1797 ifp = if_lookup_by_name(ifname, vrf->vrf_id);
1798 if (!ifp)
1799 return NB_OK;
1800 circuit = circuit_lookup_by_ifp(ifp, isis->init_circ_list);
1801 area_tag = yang_dnode_get_string(args->dnode, NULL);
1802 if (circuit && circuit->area && circuit->area->area_tag
1803 && strcmp(circuit->area->area_tag, area_tag)) {
1804 flog_warn(EC_LIB_NB_CB_CONFIG_VALIDATE,
1805 "ISIS circuit is already defined on %s",
1806 circuit->area->area_tag);
1807 return NB_ERR_VALIDATION;
1808 }
1809 }
1810
1811 return NB_OK;
1812 }
1813
1814 /*
1815 * XPath: /frr-interface:lib/interface/frr-isisd:isis/circuit-type
1816 */
1817 int lib_interface_isis_circuit_type_modify(struct nb_cb_modify_args *args)
1818 {
1819 int circ_type = yang_dnode_get_enum(args->dnode, NULL);
1820 struct isis_circuit *circuit;
1821 struct interface *ifp;
1822 struct vrf *vrf;
1823 const char *ifname, *vrfname;
1824
1825 switch (args->event) {
1826 case NB_EV_VALIDATE:
1827 /* libyang doesn't like relative paths across module boundaries
1828 */
1829 ifname = yang_dnode_get_string(args->dnode->parent->parent,
1830 "./name");
1831 vrfname = yang_dnode_get_string(args->dnode->parent->parent,
1832 "./vrf");
1833 vrf = vrf_lookup_by_name(vrfname);
1834 assert(vrf);
1835 ifp = if_lookup_by_name(ifname, vrf->vrf_id);
1836 if (!ifp)
1837 break;
1838 circuit = circuit_lookup_by_ifp(ifp, isis->init_circ_list);
1839 if (circuit && circuit->state == C_STATE_UP
1840 && circuit->area->is_type != IS_LEVEL_1_AND_2
1841 && circuit->area->is_type != circ_type) {
1842 flog_warn(EC_LIB_NB_CB_CONFIG_VALIDATE,
1843 "Invalid circuit level for area %s",
1844 circuit->area->area_tag);
1845 return NB_ERR_VALIDATION;
1846 }
1847 break;
1848 case NB_EV_PREPARE:
1849 case NB_EV_ABORT:
1850 break;
1851 case NB_EV_APPLY:
1852 circuit = nb_running_get_entry(args->dnode, NULL, true);
1853 isis_circuit_is_type_set(circuit, circ_type);
1854 break;
1855 }
1856
1857 return NB_OK;
1858 }
1859
1860 /*
1861 * XPath: /frr-interface:lib/interface/frr-isisd:isis/ipv4-routing
1862 */
1863 int lib_interface_isis_ipv4_routing_modify(struct nb_cb_modify_args *args)
1864 {
1865 bool ipv4, ipv6;
1866 struct isis_circuit *circuit;
1867
1868 if (args->event != NB_EV_APPLY)
1869 return NB_OK;
1870
1871 circuit = nb_running_get_entry(args->dnode, NULL, true);
1872 ipv4 = yang_dnode_get_bool(args->dnode, NULL);
1873 ipv6 = yang_dnode_get_bool(args->dnode, "../ipv6-routing");
1874 isis_circuit_af_set(circuit, ipv4, ipv6);
1875
1876 return NB_OK;
1877 }
1878
1879 /*
1880 * XPath: /frr-interface:lib/interface/frr-isisd:isis/ipv6-routing
1881 */
1882 int lib_interface_isis_ipv6_routing_modify(struct nb_cb_modify_args *args)
1883 {
1884 bool ipv4, ipv6;
1885 struct isis_circuit *circuit;
1886
1887 if (args->event != NB_EV_APPLY)
1888 return NB_OK;
1889
1890 circuit = nb_running_get_entry(args->dnode, NULL, true);
1891 ipv4 = yang_dnode_exists(args->dnode, "../ipv4-routing");
1892 ipv6 = yang_dnode_get_bool(args->dnode, NULL);
1893 isis_circuit_af_set(circuit, ipv4, ipv6);
1894
1895 return NB_OK;
1896 }
1897
1898 /*
1899 * XPath: /frr-interface:lib/interface/frr-isisd:isis/bfd-monitoring
1900 */
1901 int lib_interface_isis_bfd_monitoring_modify(struct nb_cb_modify_args *args)
1902 {
1903 struct isis_circuit *circuit;
1904 bool bfd_monitoring;
1905
1906 if (args->event != NB_EV_APPLY)
1907 return NB_OK;
1908
1909 circuit = nb_running_get_entry(args->dnode, NULL, true);
1910 bfd_monitoring = yang_dnode_get_bool(args->dnode, NULL);
1911
1912 if (bfd_monitoring) {
1913 isis_bfd_circuit_param_set(circuit, BFD_DEF_MIN_RX,
1914 BFD_DEF_MIN_TX, BFD_DEF_DETECT_MULT,
1915 true);
1916 } else {
1917 isis_bfd_circuit_cmd(circuit, ZEBRA_BFD_DEST_DEREGISTER);
1918 bfd_info_free(&circuit->bfd_info);
1919 }
1920
1921 return NB_OK;
1922 }
1923
1924 /*
1925 * XPath: /frr-interface:lib/interface/frr-isisd:isis/csnp-interval/level-1
1926 */
1927 int lib_interface_isis_csnp_interval_level_1_modify(
1928 struct nb_cb_modify_args *args)
1929 {
1930 struct isis_circuit *circuit;
1931
1932 if (args->event != NB_EV_APPLY)
1933 return NB_OK;
1934
1935 circuit = nb_running_get_entry(args->dnode, NULL, true);
1936 circuit->csnp_interval[0] = yang_dnode_get_uint16(args->dnode, NULL);
1937
1938 return NB_OK;
1939 }
1940
1941 /*
1942 * XPath: /frr-interface:lib/interface/frr-isisd:isis/csnp-interval/level-2
1943 */
1944 int lib_interface_isis_csnp_interval_level_2_modify(
1945 struct nb_cb_modify_args *args)
1946 {
1947 struct isis_circuit *circuit;
1948
1949 if (args->event != NB_EV_APPLY)
1950 return NB_OK;
1951
1952 circuit = nb_running_get_entry(args->dnode, NULL, true);
1953 circuit->csnp_interval[1] = yang_dnode_get_uint16(args->dnode, NULL);
1954
1955 return NB_OK;
1956 }
1957
1958 /*
1959 * XPath: /frr-interface:lib/interface/frr-isisd:isis/psnp-interval/level-1
1960 */
1961 int lib_interface_isis_psnp_interval_level_1_modify(
1962 struct nb_cb_modify_args *args)
1963 {
1964 struct isis_circuit *circuit;
1965
1966 if (args->event != NB_EV_APPLY)
1967 return NB_OK;
1968
1969 circuit = nb_running_get_entry(args->dnode, NULL, true);
1970 circuit->psnp_interval[0] = yang_dnode_get_uint16(args->dnode, NULL);
1971
1972 return NB_OK;
1973 }
1974
1975 /*
1976 * XPath: /frr-interface:lib/interface/frr-isisd:isis/psnp-interval/level-2
1977 */
1978 int lib_interface_isis_psnp_interval_level_2_modify(
1979 struct nb_cb_modify_args *args)
1980 {
1981 struct isis_circuit *circuit;
1982
1983 if (args->event != NB_EV_APPLY)
1984 return NB_OK;
1985
1986 circuit = nb_running_get_entry(args->dnode, NULL, true);
1987 circuit->psnp_interval[1] = yang_dnode_get_uint16(args->dnode, NULL);
1988
1989 return NB_OK;
1990 }
1991
1992 /*
1993 * XPath: /frr-interface:lib/interface/frr-isisd:isis/hello/padding
1994 */
1995 int lib_interface_isis_hello_padding_modify(struct nb_cb_modify_args *args)
1996 {
1997 struct isis_circuit *circuit;
1998
1999 if (args->event != NB_EV_APPLY)
2000 return NB_OK;
2001
2002 circuit = nb_running_get_entry(args->dnode, NULL, true);
2003 circuit->pad_hellos = yang_dnode_get_bool(args->dnode, NULL);
2004
2005 return NB_OK;
2006 }
2007
2008 /*
2009 * XPath: /frr-interface:lib/interface/frr-isisd:isis/hello/interval/level-1
2010 */
2011 int lib_interface_isis_hello_interval_level_1_modify(
2012 struct nb_cb_modify_args *args)
2013 {
2014 struct isis_circuit *circuit;
2015 uint32_t interval;
2016
2017 if (args->event != NB_EV_APPLY)
2018 return NB_OK;
2019
2020 circuit = nb_running_get_entry(args->dnode, NULL, true);
2021 interval = yang_dnode_get_uint32(args->dnode, NULL);
2022 circuit->hello_interval[0] = interval;
2023
2024 return NB_OK;
2025 }
2026
2027 /*
2028 * XPath: /frr-interface:lib/interface/frr-isisd:isis/hello/interval/level-2
2029 */
2030 int lib_interface_isis_hello_interval_level_2_modify(
2031 struct nb_cb_modify_args *args)
2032 {
2033 struct isis_circuit *circuit;
2034 uint32_t interval;
2035
2036 if (args->event != NB_EV_APPLY)
2037 return NB_OK;
2038
2039 circuit = nb_running_get_entry(args->dnode, NULL, true);
2040 interval = yang_dnode_get_uint32(args->dnode, NULL);
2041 circuit->hello_interval[1] = interval;
2042
2043 return NB_OK;
2044 }
2045
2046 /*
2047 * XPath: /frr-interface:lib/interface/frr-isisd:isis/hello/multiplier/level-1
2048 */
2049 int lib_interface_isis_hello_multiplier_level_1_modify(
2050 struct nb_cb_modify_args *args)
2051 {
2052 struct isis_circuit *circuit;
2053 uint16_t multi;
2054
2055 if (args->event != NB_EV_APPLY)
2056 return NB_OK;
2057
2058 circuit = nb_running_get_entry(args->dnode, NULL, true);
2059 multi = yang_dnode_get_uint16(args->dnode, NULL);
2060 circuit->hello_multiplier[0] = multi;
2061
2062 return NB_OK;
2063 }
2064
2065 /*
2066 * XPath: /frr-interface:lib/interface/frr-isisd:isis/hello/multiplier/level-2
2067 */
2068 int lib_interface_isis_hello_multiplier_level_2_modify(
2069 struct nb_cb_modify_args *args)
2070 {
2071 struct isis_circuit *circuit;
2072 uint16_t multi;
2073
2074 if (args->event != NB_EV_APPLY)
2075 return NB_OK;
2076
2077 circuit = nb_running_get_entry(args->dnode, NULL, true);
2078 multi = yang_dnode_get_uint16(args->dnode, NULL);
2079 circuit->hello_multiplier[1] = multi;
2080
2081 return NB_OK;
2082 }
2083
2084 /*
2085 * XPath: /frr-interface:lib/interface/frr-isisd:isis/metric/level-1
2086 */
2087 int lib_interface_isis_metric_level_1_modify(struct nb_cb_modify_args *args)
2088 {
2089 struct isis_circuit *circuit;
2090 unsigned int met;
2091
2092 if (args->event != NB_EV_APPLY)
2093 return NB_OK;
2094
2095 circuit = nb_running_get_entry(args->dnode, NULL, true);
2096 met = yang_dnode_get_uint32(args->dnode, NULL);
2097 isis_circuit_metric_set(circuit, IS_LEVEL_1, met);
2098
2099 return NB_OK;
2100 }
2101
2102 /*
2103 * XPath: /frr-interface:lib/interface/frr-isisd:isis/metric/level-2
2104 */
2105 int lib_interface_isis_metric_level_2_modify(struct nb_cb_modify_args *args)
2106 {
2107 struct isis_circuit *circuit;
2108 unsigned int met;
2109
2110 if (args->event != NB_EV_APPLY)
2111 return NB_OK;
2112
2113 circuit = nb_running_get_entry(args->dnode, NULL, true);
2114 met = yang_dnode_get_uint32(args->dnode, NULL);
2115 isis_circuit_metric_set(circuit, IS_LEVEL_2, met);
2116
2117 return NB_OK;
2118 }
2119
2120 /*
2121 * XPath: /frr-interface:lib/interface/frr-isisd:isis/priority/level-1
2122 */
2123 int lib_interface_isis_priority_level_1_modify(struct nb_cb_modify_args *args)
2124 {
2125 struct isis_circuit *circuit;
2126
2127 if (args->event != NB_EV_APPLY)
2128 return NB_OK;
2129
2130 circuit = nb_running_get_entry(args->dnode, NULL, true);
2131 circuit->priority[0] = yang_dnode_get_uint8(args->dnode, NULL);
2132
2133 return NB_OK;
2134 }
2135
2136 /*
2137 * XPath: /frr-interface:lib/interface/frr-isisd:isis/priority/level-2
2138 */
2139 int lib_interface_isis_priority_level_2_modify(struct nb_cb_modify_args *args)
2140 {
2141 struct isis_circuit *circuit;
2142
2143 if (args->event != NB_EV_APPLY)
2144 return NB_OK;
2145
2146 circuit = nb_running_get_entry(args->dnode, NULL, true);
2147 circuit->priority[1] = yang_dnode_get_uint8(args->dnode, NULL);
2148
2149 return NB_OK;
2150 }
2151
2152 /*
2153 * XPath: /frr-interface:lib/interface/frr-isisd:isis/network-type
2154 */
2155 int lib_interface_isis_network_type_modify(struct nb_cb_modify_args *args)
2156 {
2157 struct isis_circuit *circuit;
2158 int net_type = yang_dnode_get_enum(args->dnode, NULL);
2159
2160 switch (args->event) {
2161 case NB_EV_VALIDATE:
2162 circuit = nb_running_get_entry(args->dnode, NULL, false);
2163 if (!circuit)
2164 break;
2165 if (circuit->circ_type == CIRCUIT_T_LOOPBACK) {
2166 flog_warn(
2167 EC_LIB_NB_CB_CONFIG_VALIDATE,
2168 "Cannot change network type on loopback interface");
2169 return NB_ERR_VALIDATION;
2170 }
2171 if (net_type == CIRCUIT_T_BROADCAST
2172 && circuit->state == C_STATE_UP
2173 && !if_is_broadcast(circuit->interface)) {
2174 flog_warn(
2175 EC_LIB_NB_CB_CONFIG_VALIDATE,
2176 "Cannot configure non-broadcast interface for broadcast operation");
2177 return NB_ERR_VALIDATION;
2178 }
2179 break;
2180 case NB_EV_PREPARE:
2181 case NB_EV_ABORT:
2182 break;
2183 case NB_EV_APPLY:
2184 circuit = nb_running_get_entry(args->dnode, NULL, true);
2185 isis_circuit_circ_type_set(circuit, net_type);
2186 break;
2187 }
2188
2189 return NB_OK;
2190 }
2191
2192 /*
2193 * XPath: /frr-interface:lib/interface/frr-isisd:isis/passive
2194 */
2195 int lib_interface_isis_passive_modify(struct nb_cb_modify_args *args)
2196 {
2197 struct isis_circuit *circuit;
2198 struct isis_area *area;
2199 struct interface *ifp;
2200 bool passive = yang_dnode_get_bool(args->dnode, NULL);
2201
2202 /* validation only applies if we are setting passive to false */
2203 if (!passive && args->event == NB_EV_VALIDATE) {
2204 circuit = nb_running_get_entry(args->dnode, NULL, false);
2205 if (!circuit)
2206 return NB_OK;
2207 ifp = circuit->interface;
2208 if (!ifp)
2209 return NB_OK;
2210 if (if_is_loopback(ifp)) {
2211 flog_warn(EC_LIB_NB_CB_CONFIG_VALIDATE,
2212 "Loopback is always passive");
2213 return NB_ERR_VALIDATION;
2214 }
2215 }
2216
2217 if (args->event != NB_EV_APPLY)
2218 return NB_OK;
2219
2220 circuit = nb_running_get_entry(args->dnode, NULL, true);
2221 if (circuit->state != C_STATE_UP) {
2222 circuit->is_passive = passive;
2223 } else {
2224 area = circuit->area;
2225 isis_csm_state_change(ISIS_DISABLE, circuit, area);
2226 circuit->is_passive = passive;
2227 isis_csm_state_change(ISIS_ENABLE, circuit, area);
2228 }
2229
2230 return NB_OK;
2231 }
2232
2233 /*
2234 * XPath: /frr-interface:lib/interface/frr-isisd:isis/password
2235 */
2236 int lib_interface_isis_password_create(struct nb_cb_create_args *args)
2237 {
2238 return NB_OK;
2239 }
2240
2241 int lib_interface_isis_password_destroy(struct nb_cb_destroy_args *args)
2242 {
2243 struct isis_circuit *circuit;
2244
2245 if (args->event != NB_EV_APPLY)
2246 return NB_OK;
2247
2248 circuit = nb_running_get_entry(args->dnode, NULL, true);
2249 isis_circuit_passwd_unset(circuit);
2250
2251 return NB_OK;
2252 }
2253
2254 /*
2255 * XPath: /frr-interface:lib/interface/frr-isisd:isis/password/password
2256 */
2257 int lib_interface_isis_password_password_modify(struct nb_cb_modify_args *args)
2258 {
2259 struct isis_circuit *circuit;
2260 const char *password;
2261
2262 if (args->event != NB_EV_APPLY)
2263 return NB_OK;
2264
2265 password = yang_dnode_get_string(args->dnode, NULL);
2266 circuit = nb_running_get_entry(args->dnode, NULL, true);
2267
2268 isis_circuit_passwd_set(circuit, circuit->passwd.type, password);
2269
2270 return NB_OK;
2271 }
2272
2273 /*
2274 * XPath: /frr-interface:lib/interface/frr-isisd:isis/password/password-type
2275 */
2276 int lib_interface_isis_password_password_type_modify(
2277 struct nb_cb_modify_args *args)
2278 {
2279 struct isis_circuit *circuit;
2280 uint8_t pass_type;
2281
2282 if (args->event != NB_EV_APPLY)
2283 return NB_OK;
2284
2285 pass_type = yang_dnode_get_enum(args->dnode, NULL);
2286 circuit = nb_running_get_entry(args->dnode, NULL, true);
2287 circuit->passwd.type = pass_type;
2288
2289 return NB_OK;
2290 }
2291
2292 /*
2293 * XPath:
2294 * /frr-interface:lib/interface/frr-isisd:isis/disable-three-way-handshake
2295 */
2296 int lib_interface_isis_disable_three_way_handshake_modify(
2297 struct nb_cb_modify_args *args)
2298 {
2299 struct isis_circuit *circuit;
2300
2301 if (args->event != NB_EV_APPLY)
2302 return NB_OK;
2303
2304 circuit = nb_running_get_entry(args->dnode, NULL, true);
2305 circuit->disable_threeway_adj = yang_dnode_get_bool(args->dnode, NULL);
2306
2307 return NB_OK;
2308 }
2309
2310 /*
2311 * XPath:
2312 * /frr-interface:lib/interface/frr-isisd:isis/multi-topology/ipv4-unicast
2313 */
2314 static int lib_interface_isis_multi_topology_common(
2315 enum nb_event event, const struct lyd_node *dnode, uint16_t mtid)
2316 {
2317 struct isis_circuit *circuit;
2318 bool value;
2319
2320 switch (event) {
2321 case NB_EV_VALIDATE:
2322 circuit = nb_running_get_entry(dnode, NULL, false);
2323 if (circuit && circuit->area && circuit->area->oldmetric) {
2324 flog_warn(
2325 EC_LIB_NB_CB_CONFIG_VALIDATE,
2326 "Multi topology IS-IS can only be used with wide metrics");
2327 return NB_ERR_VALIDATION;
2328 }
2329 break;
2330 case NB_EV_PREPARE:
2331 case NB_EV_ABORT:
2332 break;
2333 case NB_EV_APPLY:
2334 circuit = nb_running_get_entry(dnode, NULL, true);
2335 value = yang_dnode_get_bool(dnode, NULL);
2336 isis_circuit_mt_enabled_set(circuit, mtid, value);
2337 break;
2338 }
2339
2340 return NB_OK;
2341 }
2342
2343 int lib_interface_isis_multi_topology_ipv4_unicast_modify(
2344 struct nb_cb_modify_args *args)
2345 {
2346 return lib_interface_isis_multi_topology_common(
2347 args->event, args->dnode, ISIS_MT_IPV4_UNICAST);
2348 }
2349
2350 /*
2351 * XPath:
2352 * /frr-interface:lib/interface/frr-isisd:isis/multi-topology/ipv4-multicast
2353 */
2354 int lib_interface_isis_multi_topology_ipv4_multicast_modify(
2355 struct nb_cb_modify_args *args)
2356 {
2357 return lib_interface_isis_multi_topology_common(
2358 args->event, args->dnode, ISIS_MT_IPV4_MULTICAST);
2359 }
2360
2361 /*
2362 * XPath:
2363 * /frr-interface:lib/interface/frr-isisd:isis/multi-topology/ipv4-management
2364 */
2365 int lib_interface_isis_multi_topology_ipv4_management_modify(
2366 struct nb_cb_modify_args *args)
2367 {
2368 return lib_interface_isis_multi_topology_common(
2369 args->event, args->dnode, ISIS_MT_IPV4_MGMT);
2370 }
2371
2372 /*
2373 * XPath:
2374 * /frr-interface:lib/interface/frr-isisd:isis/multi-topology/ipv6-unicast
2375 */
2376 int lib_interface_isis_multi_topology_ipv6_unicast_modify(
2377 struct nb_cb_modify_args *args)
2378 {
2379 return lib_interface_isis_multi_topology_common(
2380 args->event, args->dnode, ISIS_MT_IPV6_UNICAST);
2381 }
2382
2383 /*
2384 * XPath:
2385 * /frr-interface:lib/interface/frr-isisd:isis/multi-topology/ipv6-multicast
2386 */
2387 int lib_interface_isis_multi_topology_ipv6_multicast_modify(
2388 struct nb_cb_modify_args *args)
2389 {
2390 return lib_interface_isis_multi_topology_common(
2391 args->event, args->dnode, ISIS_MT_IPV6_MULTICAST);
2392 }
2393
2394 /*
2395 * XPath:
2396 * /frr-interface:lib/interface/frr-isisd:isis/multi-topology/ipv6-management
2397 */
2398 int lib_interface_isis_multi_topology_ipv6_management_modify(
2399 struct nb_cb_modify_args *args)
2400 {
2401 return lib_interface_isis_multi_topology_common(
2402 args->event, args->dnode, ISIS_MT_IPV6_MGMT);
2403 }
2404
2405 /*
2406 * XPath: /frr-interface:lib/interface/frr-isisd:isis/multi-topology/ipv6-dstsrc
2407 */
2408 int lib_interface_isis_multi_topology_ipv6_dstsrc_modify(
2409 struct nb_cb_modify_args *args)
2410 {
2411 return lib_interface_isis_multi_topology_common(
2412 args->event, args->dnode, ISIS_MT_IPV6_DSTSRC);
2413 }