]> git.proxmox.com Git - mirror_frr.git/blob - zebra/zebra_nb_config.c
Merge pull request #12851 from sri-mohan1/sri-mohan-ldp
[mirror_frr.git] / zebra / zebra_nb_config.c
1 // SPDX-License-Identifier: GPL-2.0-or-later
2 /*
3 * Copyright (C) 2019 Cumulus Networks, Inc.
4 * Chirag Shah
5 */
6
7 #include <zebra.h>
8
9 #include "lib/admin_group.h"
10 #include "lib/affinitymap.h"
11 #include "lib/log.h"
12 #include "lib/northbound.h"
13 #include "lib/printfrr.h"
14 #include "libfrr.h"
15 #include "lib/command.h"
16 #include "lib/routemap.h"
17 #include "zebra/zebra_nb.h"
18 #include "zebra/rib.h"
19 #include "zebra_nb.h"
20 #include "zebra/interface.h"
21 #include "zebra/connected.h"
22 #include "zebra/zebra_router.h"
23 #include "zebra/debug.h"
24 #include "zebra/zebra_vxlan_private.h"
25 #include "zebra/zebra_vxlan.h"
26
27 /*
28 * XPath: /frr-zebra:zebra/mcast-rpf-lookup
29 */
30 int zebra_mcast_rpf_lookup_modify(struct nb_cb_modify_args *args)
31 {
32 switch (args->event) {
33 case NB_EV_VALIDATE:
34 case NB_EV_PREPARE:
35 case NB_EV_ABORT:
36 case NB_EV_APPLY:
37 /* TODO: implement me. */
38 break;
39 }
40
41 return NB_OK;
42 }
43
44 /*
45 * XPath: /frr-zebra:zebra/ip-forwarding
46 */
47 int zebra_ip_forwarding_modify(struct nb_cb_modify_args *args)
48 {
49 switch (args->event) {
50 case NB_EV_VALIDATE:
51 case NB_EV_PREPARE:
52 case NB_EV_ABORT:
53 case NB_EV_APPLY:
54 /* TODO: implement me. */
55 break;
56 }
57
58 return NB_OK;
59 }
60
61 int zebra_ip_forwarding_destroy(struct nb_cb_destroy_args *args)
62 {
63 switch (args->event) {
64 case NB_EV_VALIDATE:
65 case NB_EV_PREPARE:
66 case NB_EV_ABORT:
67 case NB_EV_APPLY:
68 /* TODO: implement me. */
69 break;
70 }
71
72 return NB_OK;
73 }
74
75 /*
76 * XPath: /frr-zebra:zebra/ipv6-forwarding
77 */
78 int zebra_ipv6_forwarding_modify(struct nb_cb_modify_args *args)
79 {
80 switch (args->event) {
81 case NB_EV_VALIDATE:
82 case NB_EV_PREPARE:
83 case NB_EV_ABORT:
84 case NB_EV_APPLY:
85 /* TODO: implement me. */
86 break;
87 }
88
89 return NB_OK;
90 }
91
92 int zebra_ipv6_forwarding_destroy(struct nb_cb_destroy_args *args)
93 {
94 switch (args->event) {
95 case NB_EV_VALIDATE:
96 case NB_EV_PREPARE:
97 case NB_EV_ABORT:
98 case NB_EV_APPLY:
99 /* TODO: implement me. */
100 break;
101 }
102
103 return NB_OK;
104 }
105
106 /*
107 * XPath: /frr-zebra:zebra/workqueue-hold-timer
108 */
109 int zebra_workqueue_hold_timer_modify(struct nb_cb_modify_args *args)
110 {
111 switch (args->event) {
112 case NB_EV_VALIDATE:
113 case NB_EV_PREPARE:
114 case NB_EV_ABORT:
115 case NB_EV_APPLY:
116 /* TODO: implement me. */
117 break;
118 }
119
120 return NB_OK;
121 }
122
123 /*
124 * XPath: /frr-zebra:zebra/zapi-packets
125 */
126 int zebra_zapi_packets_modify(struct nb_cb_modify_args *args)
127 {
128 switch (args->event) {
129 case NB_EV_VALIDATE:
130 case NB_EV_PREPARE:
131 case NB_EV_ABORT:
132 case NB_EV_APPLY:
133 /* TODO: implement me. */
134 break;
135 }
136
137 return NB_OK;
138 }
139
140 /*
141 * XPath: /frr-zebra:zebra/import-kernel-table/table-id
142 */
143 int zebra_import_kernel_table_table_id_modify(struct nb_cb_modify_args *args)
144 {
145 switch (args->event) {
146 case NB_EV_VALIDATE:
147 case NB_EV_PREPARE:
148 case NB_EV_ABORT:
149 case NB_EV_APPLY:
150 /* TODO: implement me. */
151 break;
152 }
153
154 return NB_OK;
155 }
156
157 int zebra_import_kernel_table_table_id_destroy(struct nb_cb_destroy_args *args)
158 {
159 switch (args->event) {
160 case NB_EV_VALIDATE:
161 case NB_EV_PREPARE:
162 case NB_EV_ABORT:
163 case NB_EV_APPLY:
164 /* TODO: implement me. */
165 break;
166 }
167
168 return NB_OK;
169 }
170
171 /*
172 * XPath: /frr-zebra:zebra/import-kernel-table/distance
173 */
174 int zebra_import_kernel_table_distance_modify(struct nb_cb_modify_args *args)
175 {
176 switch (args->event) {
177 case NB_EV_VALIDATE:
178 case NB_EV_PREPARE:
179 case NB_EV_ABORT:
180 case NB_EV_APPLY:
181 /* TODO: implement me. */
182 break;
183 }
184
185 return NB_OK;
186 }
187
188 /*
189 * XPath: /frr-zebra:zebra/import-kernel-table/route-map
190 */
191 int zebra_import_kernel_table_route_map_modify(struct nb_cb_modify_args *args)
192 {
193 switch (args->event) {
194 case NB_EV_VALIDATE:
195 case NB_EV_PREPARE:
196 case NB_EV_ABORT:
197 case NB_EV_APPLY:
198 /* TODO: implement me. */
199 break;
200 }
201
202 return NB_OK;
203 }
204
205 int zebra_import_kernel_table_route_map_destroy(struct nb_cb_destroy_args *args)
206 {
207 switch (args->event) {
208 case NB_EV_VALIDATE:
209 case NB_EV_PREPARE:
210 case NB_EV_ABORT:
211 case NB_EV_APPLY:
212 /* TODO: implement me. */
213 break;
214 }
215
216 return NB_OK;
217 }
218
219 /*
220 * XPath: /frr-zebra:zebra/allow-external-route-update
221 */
222 int zebra_allow_external_route_update_create(struct nb_cb_create_args *args)
223 {
224 switch (args->event) {
225 case NB_EV_VALIDATE:
226 case NB_EV_PREPARE:
227 case NB_EV_ABORT:
228 case NB_EV_APPLY:
229 /* TODO: implement me. */
230 break;
231 }
232
233 return NB_OK;
234 }
235
236 int zebra_allow_external_route_update_destroy(struct nb_cb_destroy_args *args)
237 {
238 switch (args->event) {
239 case NB_EV_VALIDATE:
240 case NB_EV_PREPARE:
241 case NB_EV_ABORT:
242 case NB_EV_APPLY:
243 /* TODO: implement me. */
244 break;
245 }
246
247 return NB_OK;
248 }
249
250 /*
251 * XPath: /frr-zebra:zebra/dplane-queue-limit
252 */
253 int zebra_dplane_queue_limit_modify(struct nb_cb_modify_args *args)
254 {
255 switch (args->event) {
256 case NB_EV_VALIDATE:
257 case NB_EV_PREPARE:
258 case NB_EV_ABORT:
259 case NB_EV_APPLY:
260 /* TODO: implement me. */
261 break;
262 }
263
264 return NB_OK;
265 }
266
267 /*
268 * XPath: /frr-zebra:zebra/debugs/debug-events
269 */
270 int zebra_debugs_debug_events_modify(struct nb_cb_modify_args *args)
271 {
272 switch (args->event) {
273 case NB_EV_VALIDATE:
274 case NB_EV_PREPARE:
275 case NB_EV_ABORT:
276 case NB_EV_APPLY:
277 /* TODO: implement me. */
278 break;
279 }
280
281 return NB_OK;
282 }
283
284 int zebra_debugs_debug_events_destroy(struct nb_cb_destroy_args *args)
285 {
286 switch (args->event) {
287 case NB_EV_VALIDATE:
288 case NB_EV_PREPARE:
289 case NB_EV_ABORT:
290 case NB_EV_APPLY:
291 /* TODO: implement me. */
292 break;
293 }
294
295 return NB_OK;
296 }
297
298 /*
299 * XPath: /frr-zebra:zebra/debugs/debug-zapi-send
300 */
301 int zebra_debugs_debug_zapi_send_modify(struct nb_cb_modify_args *args)
302 {
303 switch (args->event) {
304 case NB_EV_VALIDATE:
305 case NB_EV_PREPARE:
306 case NB_EV_ABORT:
307 case NB_EV_APPLY:
308 /* TODO: implement me. */
309 break;
310 }
311
312 return NB_OK;
313 }
314
315 int zebra_debugs_debug_zapi_send_destroy(struct nb_cb_destroy_args *args)
316 {
317 switch (args->event) {
318 case NB_EV_VALIDATE:
319 case NB_EV_PREPARE:
320 case NB_EV_ABORT:
321 case NB_EV_APPLY:
322 /* TODO: implement me. */
323 break;
324 }
325
326 return NB_OK;
327 }
328
329 /*
330 * XPath: /frr-zebra:zebra/debugs/debug-zapi-recv
331 */
332 int zebra_debugs_debug_zapi_recv_modify(struct nb_cb_modify_args *args)
333 {
334 switch (args->event) {
335 case NB_EV_VALIDATE:
336 case NB_EV_PREPARE:
337 case NB_EV_ABORT:
338 case NB_EV_APPLY:
339 /* TODO: implement me. */
340 break;
341 }
342
343 return NB_OK;
344 }
345
346 int zebra_debugs_debug_zapi_recv_destroy(struct nb_cb_destroy_args *args)
347 {
348 switch (args->event) {
349 case NB_EV_VALIDATE:
350 case NB_EV_PREPARE:
351 case NB_EV_ABORT:
352 case NB_EV_APPLY:
353 /* TODO: implement me. */
354 break;
355 }
356
357 return NB_OK;
358 }
359
360 /*
361 * XPath: /frr-zebra:zebra/debugs/debug-zapi-detail
362 */
363 int zebra_debugs_debug_zapi_detail_modify(struct nb_cb_modify_args *args)
364 {
365 switch (args->event) {
366 case NB_EV_VALIDATE:
367 case NB_EV_PREPARE:
368 case NB_EV_ABORT:
369 case NB_EV_APPLY:
370 /* TODO: implement me. */
371 break;
372 }
373
374 return NB_OK;
375 }
376
377 int zebra_debugs_debug_zapi_detail_destroy(struct nb_cb_destroy_args *args)
378 {
379 switch (args->event) {
380 case NB_EV_VALIDATE:
381 case NB_EV_PREPARE:
382 case NB_EV_ABORT:
383 case NB_EV_APPLY:
384 /* TODO: implement me. */
385 break;
386 }
387
388 return NB_OK;
389 }
390
391 /*
392 * XPath: /frr-zebra:zebra/debugs/debug-kernel
393 */
394 int zebra_debugs_debug_kernel_modify(struct nb_cb_modify_args *args)
395 {
396 switch (args->event) {
397 case NB_EV_VALIDATE:
398 case NB_EV_PREPARE:
399 case NB_EV_ABORT:
400 case NB_EV_APPLY:
401 /* TODO: implement me. */
402 break;
403 }
404
405 return NB_OK;
406 }
407
408 int zebra_debugs_debug_kernel_destroy(struct nb_cb_destroy_args *args)
409 {
410 switch (args->event) {
411 case NB_EV_VALIDATE:
412 case NB_EV_PREPARE:
413 case NB_EV_ABORT:
414 case NB_EV_APPLY:
415 /* TODO: implement me. */
416 break;
417 }
418
419 return NB_OK;
420 }
421
422 /*
423 * XPath: /frr-zebra:zebra/debugs/debug-kernel-msg-send
424 */
425 int zebra_debugs_debug_kernel_msg_send_modify(struct nb_cb_modify_args *args)
426 {
427 switch (args->event) {
428 case NB_EV_VALIDATE:
429 case NB_EV_PREPARE:
430 case NB_EV_ABORT:
431 case NB_EV_APPLY:
432 /* TODO: implement me. */
433 break;
434 }
435
436 return NB_OK;
437 }
438
439 int zebra_debugs_debug_kernel_msg_send_destroy(struct nb_cb_destroy_args *args)
440 {
441 switch (args->event) {
442 case NB_EV_VALIDATE:
443 case NB_EV_PREPARE:
444 case NB_EV_ABORT:
445 case NB_EV_APPLY:
446 /* TODO: implement me. */
447 break;
448 }
449
450 return NB_OK;
451 }
452
453 /*
454 * XPath: /frr-zebra:zebra/debugs/debug-kernel-msg-recv
455 */
456 int zebra_debugs_debug_kernel_msg_recv_modify(struct nb_cb_modify_args *args)
457 {
458 switch (args->event) {
459 case NB_EV_VALIDATE:
460 case NB_EV_PREPARE:
461 case NB_EV_ABORT:
462 case NB_EV_APPLY:
463 /* TODO: implement me. */
464 break;
465 }
466
467 return NB_OK;
468 }
469
470 int zebra_debugs_debug_kernel_msg_recv_destroy(struct nb_cb_destroy_args *args)
471 {
472 switch (args->event) {
473 case NB_EV_VALIDATE:
474 case NB_EV_PREPARE:
475 case NB_EV_ABORT:
476 case NB_EV_APPLY:
477 /* TODO: implement me. */
478 break;
479 }
480
481 return NB_OK;
482 }
483
484 /*
485 * XPath: /frr-zebra:zebra/debugs/debug-rib
486 */
487 int zebra_debugs_debug_rib_modify(struct nb_cb_modify_args *args)
488 {
489 switch (args->event) {
490 case NB_EV_VALIDATE:
491 case NB_EV_PREPARE:
492 case NB_EV_ABORT:
493 case NB_EV_APPLY:
494 /* TODO: implement me. */
495 break;
496 }
497
498 return NB_OK;
499 }
500
501 int zebra_debugs_debug_rib_destroy(struct nb_cb_destroy_args *args)
502 {
503 switch (args->event) {
504 case NB_EV_VALIDATE:
505 case NB_EV_PREPARE:
506 case NB_EV_ABORT:
507 case NB_EV_APPLY:
508 /* TODO: implement me. */
509 break;
510 }
511
512 return NB_OK;
513 }
514
515 /*
516 * XPath: /frr-zebra:zebra/debugs/debug-rib-detail
517 */
518 int zebra_debugs_debug_rib_detail_modify(struct nb_cb_modify_args *args)
519 {
520 switch (args->event) {
521 case NB_EV_VALIDATE:
522 case NB_EV_PREPARE:
523 case NB_EV_ABORT:
524 case NB_EV_APPLY:
525 /* TODO: implement me. */
526 break;
527 }
528
529 return NB_OK;
530 }
531
532 int zebra_debugs_debug_rib_detail_destroy(struct nb_cb_destroy_args *args)
533 {
534 switch (args->event) {
535 case NB_EV_VALIDATE:
536 case NB_EV_PREPARE:
537 case NB_EV_ABORT:
538 case NB_EV_APPLY:
539 /* TODO: implement me. */
540 break;
541 }
542
543 return NB_OK;
544 }
545
546 /*
547 * XPath: /frr-zebra:zebra/debugs/debug-fpm
548 */
549 int zebra_debugs_debug_fpm_modify(struct nb_cb_modify_args *args)
550 {
551 switch (args->event) {
552 case NB_EV_VALIDATE:
553 case NB_EV_PREPARE:
554 case NB_EV_ABORT:
555 case NB_EV_APPLY:
556 /* TODO: implement me. */
557 break;
558 }
559
560 return NB_OK;
561 }
562
563 int zebra_debugs_debug_fpm_destroy(struct nb_cb_destroy_args *args)
564 {
565 switch (args->event) {
566 case NB_EV_VALIDATE:
567 case NB_EV_PREPARE:
568 case NB_EV_ABORT:
569 case NB_EV_APPLY:
570 /* TODO: implement me. */
571 break;
572 }
573
574 return NB_OK;
575 }
576
577 /*
578 * XPath: /frr-zebra:zebra/debugs/debug-nht
579 */
580 int zebra_debugs_debug_nht_modify(struct nb_cb_modify_args *args)
581 {
582 switch (args->event) {
583 case NB_EV_VALIDATE:
584 case NB_EV_PREPARE:
585 case NB_EV_ABORT:
586 case NB_EV_APPLY:
587 /* TODO: implement me. */
588 break;
589 }
590
591 return NB_OK;
592 }
593
594 int zebra_debugs_debug_nht_destroy(struct nb_cb_destroy_args *args)
595 {
596 switch (args->event) {
597 case NB_EV_VALIDATE:
598 case NB_EV_PREPARE:
599 case NB_EV_ABORT:
600 case NB_EV_APPLY:
601 /* TODO: implement me. */
602 break;
603 }
604
605 return NB_OK;
606 }
607
608 /*
609 * XPath: /frr-zebra:zebra/debugs/debug-nht-detail
610 */
611 int zebra_debugs_debug_nht_detail_modify(struct nb_cb_modify_args *args)
612 {
613 switch (args->event) {
614 case NB_EV_VALIDATE:
615 case NB_EV_PREPARE:
616 case NB_EV_ABORT:
617 case NB_EV_APPLY:
618 /* TODO: implement me. */
619 break;
620 }
621
622 return NB_OK;
623 }
624
625 int zebra_debugs_debug_nht_detail_destroy(struct nb_cb_destroy_args *args)
626 {
627 switch (args->event) {
628 case NB_EV_VALIDATE:
629 case NB_EV_PREPARE:
630 case NB_EV_ABORT:
631 case NB_EV_APPLY:
632 /* TODO: implement me. */
633 break;
634 }
635
636 return NB_OK;
637 }
638
639 /*
640 * XPath: /frr-zebra:zebra/debugs/debug-mpls
641 */
642 int zebra_debugs_debug_mpls_modify(struct nb_cb_modify_args *args)
643 {
644 switch (args->event) {
645 case NB_EV_VALIDATE:
646 case NB_EV_PREPARE:
647 case NB_EV_ABORT:
648 case NB_EV_APPLY:
649 /* TODO: implement me. */
650 break;
651 }
652
653 return NB_OK;
654 }
655
656 int zebra_debugs_debug_mpls_destroy(struct nb_cb_destroy_args *args)
657 {
658 switch (args->event) {
659 case NB_EV_VALIDATE:
660 case NB_EV_PREPARE:
661 case NB_EV_ABORT:
662 case NB_EV_APPLY:
663 /* TODO: implement me. */
664 break;
665 }
666
667 return NB_OK;
668 }
669
670 /*
671 * XPath: /frr-zebra:zebra/debugs/debug-vxlan
672 */
673 int zebra_debugs_debug_vxlan_modify(struct nb_cb_modify_args *args)
674 {
675 switch (args->event) {
676 case NB_EV_VALIDATE:
677 case NB_EV_PREPARE:
678 case NB_EV_ABORT:
679 case NB_EV_APPLY:
680 /* TODO: implement me. */
681 break;
682 }
683
684 return NB_OK;
685 }
686
687 int zebra_debugs_debug_vxlan_destroy(struct nb_cb_destroy_args *args)
688 {
689 switch (args->event) {
690 case NB_EV_VALIDATE:
691 case NB_EV_PREPARE:
692 case NB_EV_ABORT:
693 case NB_EV_APPLY:
694 /* TODO: implement me. */
695 break;
696 }
697
698 return NB_OK;
699 }
700
701 /*
702 * XPath: /frr-zebra:zebra/debugs/debug-pw
703 */
704 int zebra_debugs_debug_pw_modify(struct nb_cb_modify_args *args)
705 {
706 switch (args->event) {
707 case NB_EV_VALIDATE:
708 case NB_EV_PREPARE:
709 case NB_EV_ABORT:
710 case NB_EV_APPLY:
711 /* TODO: implement me. */
712 break;
713 }
714
715 return NB_OK;
716 }
717
718 int zebra_debugs_debug_pw_destroy(struct nb_cb_destroy_args *args)
719 {
720 switch (args->event) {
721 case NB_EV_VALIDATE:
722 case NB_EV_PREPARE:
723 case NB_EV_ABORT:
724 case NB_EV_APPLY:
725 /* TODO: implement me. */
726 break;
727 }
728
729 return NB_OK;
730 }
731
732 /*
733 * XPath: /frr-zebra:zebra/debugs/debug-dplane
734 */
735 int zebra_debugs_debug_dplane_modify(struct nb_cb_modify_args *args)
736 {
737 switch (args->event) {
738 case NB_EV_VALIDATE:
739 case NB_EV_PREPARE:
740 case NB_EV_ABORT:
741 case NB_EV_APPLY:
742 /* TODO: implement me. */
743 break;
744 }
745
746 return NB_OK;
747 }
748
749 int zebra_debugs_debug_dplane_destroy(struct nb_cb_destroy_args *args)
750 {
751 switch (args->event) {
752 case NB_EV_VALIDATE:
753 case NB_EV_PREPARE:
754 case NB_EV_ABORT:
755 case NB_EV_APPLY:
756 /* TODO: implement me. */
757 break;
758 }
759
760 return NB_OK;
761 }
762
763 /*
764 * XPath: /frr-zebra:zebra/debugs/debug-dplane-detail
765 */
766 int zebra_debugs_debug_dplane_detail_modify(struct nb_cb_modify_args *args)
767 {
768 switch (args->event) {
769 case NB_EV_VALIDATE:
770 case NB_EV_PREPARE:
771 case NB_EV_ABORT:
772 case NB_EV_APPLY:
773 /* TODO: implement me. */
774 break;
775 }
776
777 return NB_OK;
778 }
779
780 int zebra_debugs_debug_dplane_detail_destroy(struct nb_cb_destroy_args *args)
781 {
782 switch (args->event) {
783 case NB_EV_VALIDATE:
784 case NB_EV_PREPARE:
785 case NB_EV_ABORT:
786 case NB_EV_APPLY:
787 /* TODO: implement me. */
788 break;
789 }
790
791 return NB_OK;
792 }
793
794 /*
795 * XPath: /frr-zebra:zebra/debugs/debug-mlag
796 */
797 int zebra_debugs_debug_mlag_modify(struct nb_cb_modify_args *args)
798 {
799 switch (args->event) {
800 case NB_EV_VALIDATE:
801 case NB_EV_PREPARE:
802 case NB_EV_ABORT:
803 case NB_EV_APPLY:
804 /* TODO: implement me. */
805 break;
806 }
807
808 return NB_OK;
809 }
810
811 int zebra_debugs_debug_mlag_destroy(struct nb_cb_destroy_args *args)
812 {
813 switch (args->event) {
814 case NB_EV_VALIDATE:
815 case NB_EV_PREPARE:
816 case NB_EV_ABORT:
817 case NB_EV_APPLY:
818 /* TODO: implement me. */
819 break;
820 }
821
822 return NB_OK;
823 }
824
825 /*
826 * XPath: /frr-interface:lib/interface/frr-zebra:zebra/ip-addrs
827 */
828 int lib_interface_zebra_ip_addrs_create(struct nb_cb_create_args *args)
829 {
830 struct interface *ifp;
831 struct prefix prefix;
832
833 // addr_family = yang_dnode_get_enum(dnode, "./address-family");
834 yang_dnode_get_prefix(&prefix, args->dnode, "./ip-prefix");
835 apply_mask(&prefix);
836
837 switch (args->event) {
838 case NB_EV_VALIDATE:
839 if (prefix.family == AF_INET
840 && ipv4_martian(&prefix.u.prefix4)) {
841 snprintfrr(args->errmsg, args->errmsg_len,
842 "invalid address %pFX", &prefix);
843 return NB_ERR_VALIDATION;
844 } else if (prefix.family == AF_INET6
845 && ipv6_martian(&prefix.u.prefix6)) {
846 snprintfrr(args->errmsg, args->errmsg_len,
847 "invalid address %pFX", &prefix);
848 return NB_ERR_VALIDATION;
849 }
850 break;
851 case NB_EV_PREPARE:
852 case NB_EV_ABORT:
853 break;
854 case NB_EV_APPLY:
855 ifp = nb_running_get_entry(args->dnode, NULL, true);
856 if (prefix.family == AF_INET)
857 if_ip_address_install(ifp, &prefix, NULL, NULL);
858 else if (prefix.family == AF_INET6)
859 if_ipv6_address_install(ifp, &prefix, NULL);
860
861 break;
862 }
863
864 return NB_OK;
865 }
866
867 int lib_interface_zebra_ip_addrs_destroy(struct nb_cb_destroy_args *args)
868 {
869 struct interface *ifp;
870 struct prefix prefix;
871 struct connected *ifc;
872
873 yang_dnode_get_prefix(&prefix, args->dnode, "./ip-prefix");
874 apply_mask(&prefix);
875
876 switch (args->event) {
877 case NB_EV_VALIDATE:
878 ifp = nb_running_get_entry(args->dnode, NULL, false);
879 if (!ifp)
880 return NB_OK;
881
882 if (prefix.family == AF_INET) {
883 /* Check current interface address. */
884 ifc = connected_check_ptp(ifp, &prefix, NULL);
885 if (!ifc) {
886 snprintf(args->errmsg, args->errmsg_len,
887 "interface %s Can't find address\n",
888 ifp->name);
889 return NB_ERR_VALIDATION;
890 }
891 } else if (prefix.family == AF_INET6) {
892 /* Check current interface address. */
893 ifc = connected_check(ifp, &prefix);
894 if (!ifc) {
895 snprintf(args->errmsg, args->errmsg_len,
896 "interface can't find address %s",
897 ifp->name);
898 return NB_ERR_VALIDATION;
899 }
900 } else
901 return NB_ERR_VALIDATION;
902
903 /* This is not configured address. */
904 if (!CHECK_FLAG(ifc->conf, ZEBRA_IFC_CONFIGURED)) {
905 snprintf(args->errmsg, args->errmsg_len,
906 "interface %s not configured", ifp->name);
907 return NB_ERR_VALIDATION;
908 }
909
910 /* This is not real address or interface is not active. */
911 if (!CHECK_FLAG(ifc->conf, ZEBRA_IFC_QUEUED)
912 || !CHECK_FLAG(ifp->status, ZEBRA_INTERFACE_ACTIVE)) {
913 listnode_delete(ifp->connected, ifc);
914 connected_free(&ifc);
915 return NB_ERR_VALIDATION;
916 }
917 break;
918 case NB_EV_PREPARE:
919 case NB_EV_ABORT:
920 break;
921 case NB_EV_APPLY:
922 ifp = nb_running_get_entry(args->dnode, NULL, true);
923 if_ip_address_uinstall(ifp, &prefix);
924 break;
925 }
926
927 return NB_OK;
928 }
929
930 /*
931 * XPath: /frr-interface:lib/interface/frr-zebra:zebra/ip-addrs/label
932 */
933 int lib_interface_zebra_ip_addrs_label_modify(struct nb_cb_modify_args *args)
934 {
935 switch (args->event) {
936 case NB_EV_VALIDATE:
937 case NB_EV_PREPARE:
938 case NB_EV_ABORT:
939 case NB_EV_APPLY:
940 /* TODO: implement me. */
941 break;
942 }
943
944 return NB_OK;
945 }
946
947 int lib_interface_zebra_ip_addrs_label_destroy(struct nb_cb_destroy_args *args)
948 {
949 switch (args->event) {
950 case NB_EV_VALIDATE:
951 case NB_EV_PREPARE:
952 case NB_EV_ABORT:
953 case NB_EV_APPLY:
954 /* TODO: implement me. */
955 break;
956 }
957
958 return NB_OK;
959 }
960
961 /*
962 * XPath: /frr-interface:lib/interface/frr-zebra:zebra/ip-addrs/ip4-peer
963 */
964 int lib_interface_zebra_ip_addrs_ip4_peer_modify(struct nb_cb_modify_args *args)
965 {
966 switch (args->event) {
967 case NB_EV_VALIDATE:
968 case NB_EV_PREPARE:
969 case NB_EV_ABORT:
970 case NB_EV_APPLY:
971 /* TODO: implement me. */
972 break;
973 }
974
975 return NB_OK;
976 }
977
978 int lib_interface_zebra_ip_addrs_ip4_peer_destroy(
979 struct nb_cb_destroy_args *args)
980 {
981 switch (args->event) {
982 case NB_EV_VALIDATE:
983 case NB_EV_PREPARE:
984 case NB_EV_ABORT:
985 case NB_EV_APPLY:
986 /* TODO: implement me. */
987 break;
988 }
989
990 return NB_OK;
991 }
992
993 /*
994 * XPath: /frr-interface:lib/interface/frr-zebra:zebra/multicast
995 */
996 int lib_interface_zebra_multicast_modify(struct nb_cb_modify_args *args)
997 {
998 if (args->event != NB_EV_APPLY)
999 return NB_OK;
1000
1001 struct interface *ifp;
1002
1003 ifp = nb_running_get_entry(args->dnode, NULL, true);
1004
1005 if_multicast_set(ifp);
1006
1007 return NB_OK;
1008 }
1009
1010 int lib_interface_zebra_multicast_destroy(struct nb_cb_destroy_args *args)
1011 {
1012 if (args->event != NB_EV_APPLY)
1013 return NB_OK;
1014
1015 struct interface *ifp;
1016
1017 ifp = nb_running_get_entry(args->dnode, NULL, true);
1018
1019 if_multicast_unset(ifp);
1020
1021 return NB_OK;
1022 }
1023
1024 /*
1025 * XPath: /frr-interface:lib/interface/frr-zebra:zebra/link-detect
1026 */
1027 int lib_interface_zebra_link_detect_modify(struct nb_cb_modify_args *args)
1028 {
1029 if (args->event != NB_EV_APPLY)
1030 return NB_OK;
1031
1032 struct interface *ifp;
1033 bool link_detect;
1034
1035 ifp = nb_running_get_entry(args->dnode, NULL, true);
1036 link_detect = yang_dnode_get_bool(args->dnode, "./link-detect");
1037
1038 if_linkdetect(ifp, link_detect);
1039
1040 return NB_OK;
1041 }
1042
1043 int lib_interface_zebra_link_detect_destroy(struct nb_cb_destroy_args *args)
1044 {
1045 if (args->event != NB_EV_APPLY)
1046 return NB_OK;
1047
1048 struct interface *ifp;
1049 bool link_detect;
1050
1051 ifp = nb_running_get_entry(args->dnode, NULL, true);
1052 link_detect = yang_dnode_get_bool(args->dnode, "./link-detect");
1053
1054 if_linkdetect(ifp, link_detect);
1055
1056 return NB_OK;
1057 }
1058
1059 /*
1060 * XPath: /frr-interface:lib/interface/frr-zebra:zebra/shutdown
1061 */
1062 int lib_interface_zebra_shutdown_modify(struct nb_cb_modify_args *args)
1063 {
1064 if (args->event != NB_EV_APPLY)
1065 return NB_OK;
1066
1067 struct interface *ifp;
1068
1069 ifp = nb_running_get_entry(args->dnode, NULL, true);
1070
1071 if_shutdown(ifp);
1072
1073 return NB_OK;
1074 }
1075
1076 int lib_interface_zebra_shutdown_destroy(struct nb_cb_destroy_args *args)
1077 {
1078 if (args->event != NB_EV_APPLY)
1079 return NB_OK;
1080
1081 struct interface *ifp;
1082
1083 ifp = nb_running_get_entry(args->dnode, NULL, true);
1084
1085 if_no_shutdown(ifp);
1086
1087 return NB_OK;
1088 }
1089
1090 /*
1091 * XPath: /frr-interface:lib/interface/frr-zebra:zebra/bandwidth
1092 */
1093 int lib_interface_zebra_bandwidth_modify(struct nb_cb_modify_args *args)
1094 {
1095 if (args->event != NB_EV_APPLY)
1096 return NB_OK;
1097
1098 struct interface *ifp;
1099 uint32_t bandwidth;
1100
1101 ifp = nb_running_get_entry(args->dnode, NULL, true);
1102 bandwidth = yang_dnode_get_uint32(args->dnode, "./bandwidth");
1103
1104 ifp->bandwidth = bandwidth;
1105
1106 /* force protocols to recalculate routes due to cost change */
1107 if (if_is_operative(ifp))
1108 zebra_interface_up_update(ifp);
1109
1110 return NB_OK;
1111 }
1112
1113 int lib_interface_zebra_bandwidth_destroy(struct nb_cb_destroy_args *args)
1114 {
1115 if (args->event != NB_EV_APPLY)
1116 return NB_OK;
1117
1118 struct interface *ifp;
1119
1120 ifp = nb_running_get_entry(args->dnode, NULL, true);
1121
1122 ifp->bandwidth = 0;
1123
1124 /* force protocols to recalculate routes due to cost change */
1125 if (if_is_operative(ifp))
1126 zebra_interface_up_update(ifp);
1127
1128 return NB_OK;
1129 }
1130
1131 /*
1132 * XPath:
1133 * /frr-interface:lib/interface/frr-zebra:zebra/link-params/legacy-admin-group
1134 */
1135 int lib_interface_zebra_legacy_admin_group_modify(
1136 struct nb_cb_modify_args *args)
1137 {
1138 struct interface *ifp;
1139 struct if_link_params *iflp;
1140 uint32_t admin_group_value;
1141
1142 ifp = nb_running_get_entry(args->dnode, NULL, true);
1143 admin_group_value = yang_dnode_get_uint32(args->dnode, ".");
1144
1145 if (!ifp)
1146 return NB_ERR_RESOURCE;
1147
1148 iflp = if_link_params_get(ifp);
1149
1150 switch (args->event) {
1151 case NB_EV_VALIDATE:
1152 case NB_EV_PREPARE:
1153 case NB_EV_ABORT:
1154 break;
1155 case NB_EV_APPLY:
1156 if (!iflp)
1157 iflp = if_link_params_enable(ifp);
1158
1159 iflp->admin_grp = admin_group_value;
1160 SET_PARAM(iflp, LP_ADM_GRP);
1161
1162 admin_group_clear(&iflp->ext_admin_grp);
1163 UNSET_PARAM(iflp, LP_EXTEND_ADM_GRP);
1164
1165 if (if_is_operative(ifp))
1166 zebra_interface_parameters_update(ifp);
1167 break;
1168 }
1169 return NB_OK;
1170 }
1171
1172 int lib_interface_zebra_legacy_admin_group_destroy(
1173 struct nb_cb_destroy_args *args)
1174 {
1175 struct interface *ifp;
1176 struct if_link_params *iflp;
1177
1178 ifp = nb_running_get_entry(args->dnode, NULL, true);
1179
1180 if (!ifp)
1181 return NB_ERR_RESOURCE;
1182
1183 iflp = if_link_params_get(ifp);
1184
1185 switch (args->event) {
1186 case NB_EV_VALIDATE:
1187 case NB_EV_PREPARE:
1188 case NB_EV_ABORT:
1189 break;
1190 case NB_EV_APPLY:
1191 if (!iflp)
1192 iflp = if_link_params_enable(ifp);
1193
1194 iflp->admin_grp = 0;
1195 UNSET_PARAM(iflp, LP_ADM_GRP);
1196
1197 if (if_is_operative(ifp))
1198 zebra_interface_parameters_update(ifp);
1199 break;
1200 }
1201 return NB_OK;
1202 }
1203
1204 /*
1205 * XPath:
1206 * /frr-interface:lib/interface/frr-zebra:zebra/link-params/affinities/affinity
1207 */
1208 int lib_interface_zebra_affinity_create(struct nb_cb_create_args *args)
1209 {
1210 struct interface *ifp;
1211 const char *affname;
1212 struct if_link_params *iflp;
1213 struct affinity_map *affmap;
1214 enum affinity_mode affinity_mode;
1215
1216
1217 ifp = nb_running_get_entry(args->dnode, NULL, true);
1218 affname = yang_dnode_get_string(args->dnode, ".");
1219 affinity_mode = yang_dnode_get_enum(args->dnode, "../../affinity-mode");
1220
1221 if (!ifp)
1222 return NB_ERR_RESOURCE;
1223
1224 affmap = affinity_map_get(affname);
1225 iflp = if_link_params_get(ifp);
1226
1227 switch (args->event) {
1228 case NB_EV_VALIDATE:
1229 if (!affmap) {
1230 snprintf(args->errmsg, args->errmsg_len,
1231 "affinity-map %s not found.", affname);
1232 return NB_ERR_VALIDATION;
1233 }
1234 if (affinity_mode == AFFINITY_MODE_STANDARD &&
1235 affmap->bit_position > 31) {
1236 snprintf(
1237 args->errmsg, args->errmsg_len,
1238 "affinity %s bit-position %d is not compatible with affinity-mode standard (bit-position > 31).",
1239 affname, affmap->bit_position);
1240 return NB_ERR_VALIDATION;
1241 }
1242 break;
1243 case NB_EV_PREPARE:
1244 case NB_EV_ABORT:
1245 break;
1246 case NB_EV_APPLY:
1247 if (!iflp)
1248 iflp = if_link_params_enable(ifp);
1249
1250 if (affmap->bit_position < 32 &&
1251 (affinity_mode == AFFINITY_MODE_STANDARD ||
1252 affinity_mode == AFFINITY_MODE_BOTH)) {
1253 iflp->admin_grp |= 1 << affmap->bit_position;
1254 SET_PARAM(iflp, LP_ADM_GRP);
1255 }
1256 if (affinity_mode == AFFINITY_MODE_EXTENDED ||
1257 affinity_mode == AFFINITY_MODE_BOTH) {
1258 admin_group_set(&iflp->ext_admin_grp,
1259 affmap->bit_position);
1260 SET_PARAM(iflp, LP_EXTEND_ADM_GRP);
1261 }
1262
1263 if (if_is_operative(ifp))
1264 zebra_interface_parameters_update(ifp);
1265 break;
1266 }
1267 return NB_OK;
1268 }
1269
1270 int lib_interface_zebra_affinity_destroy(struct nb_cb_destroy_args *args)
1271 {
1272 struct interface *ifp;
1273 const char *affname;
1274 struct if_link_params *iflp;
1275 struct affinity_map *affmap;
1276 enum affinity_mode affinity_mode;
1277
1278 ifp = nb_running_get_entry(args->dnode, NULL, true);
1279 affname = yang_dnode_get_string(args->dnode, ".");
1280 affinity_mode = yang_dnode_get_enum(args->dnode, "../../affinity-mode");
1281
1282 if (!ifp)
1283 return NB_ERR_RESOURCE;
1284
1285 affmap = affinity_map_get(affname);
1286 iflp = if_link_params_get(ifp);
1287
1288 switch (args->event) {
1289 case NB_EV_VALIDATE:
1290 if (!affmap) {
1291 snprintf(args->errmsg, args->errmsg_len,
1292 "affinity-map %s not found.", affname);
1293 return NB_ERR_VALIDATION;
1294 }
1295 break;
1296 case NB_EV_PREPARE:
1297 case NB_EV_ABORT:
1298 break;
1299 case NB_EV_APPLY:
1300 if (!iflp)
1301 return NB_OK;
1302 if (affmap->bit_position < 32 &&
1303 (affinity_mode == AFFINITY_MODE_STANDARD ||
1304 affinity_mode == AFFINITY_MODE_BOTH)) {
1305 iflp->admin_grp &= ~(1 << affmap->bit_position);
1306 if (iflp->admin_grp == 0)
1307 UNSET_PARAM(iflp, LP_ADM_GRP);
1308 }
1309 if (affinity_mode == AFFINITY_MODE_EXTENDED ||
1310 affinity_mode == AFFINITY_MODE_BOTH) {
1311 admin_group_unset(&iflp->ext_admin_grp,
1312 affmap->bit_position);
1313 if (admin_group_zero(&iflp->ext_admin_grp))
1314 UNSET_PARAM(iflp, LP_EXTEND_ADM_GRP);
1315 }
1316
1317 if (if_is_operative(ifp))
1318 zebra_interface_parameters_update(ifp);
1319 break;
1320 }
1321 return NB_OK;
1322 }
1323
1324 /*
1325 * XPath:
1326 * /frr-interface:lib/interface/frr-zebra:zebra/link-params/affinity-mode
1327 */
1328 int lib_interface_zebra_affinity_mode_modify(struct nb_cb_modify_args *args)
1329 {
1330 struct interface *ifp;
1331 struct if_link_params *iflp;
1332 enum affinity_mode affinity_mode;
1333
1334
1335 ifp = nb_running_get_entry(args->dnode, NULL, true);
1336 affinity_mode = yang_dnode_get_enum(args->dnode, ".");
1337
1338 if (!ifp)
1339 return NB_ERR_RESOURCE;
1340
1341 iflp = if_link_params_get(ifp);
1342
1343 switch (args->event) {
1344 case NB_EV_VALIDATE:
1345 if (affinity_mode == AFFINITY_MODE_STANDARD &&
1346 admin_group_nb_words(&iflp->ext_admin_grp) > 1) {
1347 snprintf(
1348 args->errmsg, args->errmsg_len,
1349 "affinity-mode standard cannot be set when a bit-position > 31 is set.");
1350 return NB_ERR_VALIDATION;
1351 }
1352 break;
1353 case NB_EV_PREPARE:
1354 case NB_EV_ABORT:
1355 break;
1356 case NB_EV_APPLY:
1357 if (!iflp)
1358 iflp = if_link_params_enable(ifp);
1359 if (affinity_mode == AFFINITY_MODE_STANDARD) {
1360 if (!IS_PARAM_SET(iflp, LP_ADM_GRP) &&
1361 IS_PARAM_SET(iflp, LP_EXTEND_ADM_GRP)) {
1362 iflp->admin_grp = admin_group_get_offset(
1363 &iflp->ext_admin_grp, 0);
1364 SET_PARAM(iflp, LP_ADM_GRP);
1365 }
1366 admin_group_clear(&iflp->ext_admin_grp);
1367 UNSET_PARAM(iflp, LP_EXTEND_ADM_GRP);
1368 }
1369 if (affinity_mode == AFFINITY_MODE_EXTENDED) {
1370 if (!IS_PARAM_SET(iflp, LP_EXTEND_ADM_GRP) &&
1371 IS_PARAM_SET(iflp, LP_ADM_GRP)) {
1372 admin_group_bulk_set(&iflp->ext_admin_grp,
1373 iflp->admin_grp, 0);
1374 SET_PARAM(iflp, LP_EXTEND_ADM_GRP);
1375 }
1376 iflp->admin_grp = 0;
1377 UNSET_PARAM(iflp, LP_ADM_GRP);
1378 }
1379 if (affinity_mode == AFFINITY_MODE_BOTH) {
1380 if (!IS_PARAM_SET(iflp, LP_EXTEND_ADM_GRP) &&
1381 IS_PARAM_SET(iflp, LP_ADM_GRP)) {
1382 admin_group_bulk_set(&iflp->ext_admin_grp,
1383 iflp->admin_grp, 0);
1384 SET_PARAM(iflp, LP_EXTEND_ADM_GRP);
1385 } else if (!IS_PARAM_SET(iflp, LP_ADM_GRP) &&
1386 IS_PARAM_SET(iflp, LP_EXTEND_ADM_GRP)) {
1387 iflp->admin_grp = admin_group_get_offset(
1388 &iflp->ext_admin_grp, 0);
1389 SET_PARAM(iflp, LP_ADM_GRP);
1390 }
1391 }
1392
1393 if (if_is_operative(ifp))
1394 zebra_interface_parameters_update(ifp);
1395 break;
1396 }
1397 return NB_OK;
1398 }
1399
1400 /*
1401 * XPath: /frr-vrf:lib/vrf/frr-zebra:zebra/l3vni-id
1402 */
1403 int lib_vrf_zebra_l3vni_id_modify(struct nb_cb_modify_args *args)
1404 {
1405 struct vrf *vrf;
1406 struct zebra_vrf *zvrf;
1407 vni_t vni = 0;
1408 struct zebra_l3vni *zl3vni = NULL;
1409 char err[ERR_STR_SZ];
1410 bool pfx_only = false;
1411 const struct lyd_node *pn_dnode;
1412 const char *vrfname;
1413
1414 switch (args->event) {
1415 case NB_EV_PREPARE:
1416 case NB_EV_ABORT:
1417 return NB_OK;
1418 case NB_EV_VALIDATE:
1419 vni = yang_dnode_get_uint32(args->dnode, NULL);
1420 /* Get vrf info from parent node, reject configuration
1421 * if zebra vrf already mapped to different vni id.
1422 */
1423 pn_dnode = yang_dnode_get_parent(args->dnode, "vrf");
1424 vrfname = yang_dnode_get_string(pn_dnode, "./name");
1425 zvrf = zebra_vrf_lookup_by_name(vrfname);
1426 if (!zvrf) {
1427 snprintf(args->errmsg, args->errmsg_len,
1428 "zebra vrf info not found for vrf:%s.",
1429 vrfname);
1430 return NB_ERR_VALIDATION;
1431 }
1432 if (zvrf->l3vni && zvrf->l3vni != vni) {
1433 snprintf(
1434 args->errmsg, args->errmsg_len,
1435 "vni %u cannot be configured as vni %u is already configured under the vrf",
1436 vni, zvrf->l3vni);
1437 return NB_ERR_VALIDATION;
1438 }
1439
1440 /* Check if this VNI is already present in the system */
1441 zl3vni = zl3vni_lookup(vni);
1442 if (zl3vni) {
1443 snprintf(args->errmsg, args->errmsg_len,
1444 "VNI %u is already configured as L3-VNI", vni);
1445 return NB_ERR_VALIDATION;
1446 }
1447
1448 break;
1449 case NB_EV_APPLY:
1450
1451 vrf = nb_running_get_entry(args->dnode, NULL, true);
1452 zvrf = zebra_vrf_lookup_by_name(vrf->name);
1453 vni = yang_dnode_get_uint32(args->dnode, NULL);
1454 /* Note: This covers lib_vrf_zebra_prefix_only_modify() config
1455 * along with l3vni config
1456 */
1457 pfx_only = yang_dnode_get_bool(args->dnode, "../prefix-only");
1458
1459 if (zebra_vxlan_process_vrf_vni_cmd(zvrf, vni, err, ERR_STR_SZ,
1460 pfx_only ? 1 : 0, 1)
1461 != 0) {
1462 if (IS_ZEBRA_DEBUG_VXLAN)
1463 snprintf(
1464 args->errmsg, args->errmsg_len,
1465 "vrf vni %u mapping failed with error: %s",
1466 vni, err);
1467 return NB_ERR;
1468 }
1469
1470 break;
1471 }
1472
1473 return NB_OK;
1474 }
1475
1476 int lib_vrf_zebra_l3vni_id_destroy(struct nb_cb_destroy_args *args)
1477 {
1478 struct vrf *vrf;
1479 struct zebra_vrf *zvrf;
1480 vni_t vni = 0;
1481 char err[ERR_STR_SZ];
1482 uint8_t filter = 0;
1483
1484 switch (args->event) {
1485 case NB_EV_PREPARE:
1486 case NB_EV_ABORT:
1487 case NB_EV_VALIDATE:
1488 return NB_OK;
1489 case NB_EV_APPLY:
1490 vrf = nb_running_get_entry(args->dnode, NULL, true);
1491 zvrf = zebra_vrf_lookup_by_name(vrf->name);
1492 vni = yang_dnode_get_uint32(args->dnode, NULL);
1493
1494 if (!zl3vni_lookup(vni))
1495 return NB_OK;
1496
1497 if (zvrf->l3vni != vni) {
1498 snprintf(args->errmsg, args->errmsg_len,
1499 "vrf %s has different vni %u mapped",
1500 vrf->name, zvrf->l3vni);
1501 return NB_ERR;
1502 }
1503
1504 if (is_l3vni_for_prefix_routes_only(zvrf->l3vni))
1505 filter = 1;
1506
1507 if (zebra_vxlan_process_vrf_vni_cmd(zvrf, vni, err, ERR_STR_SZ,
1508 filter, 0)
1509 != 0) {
1510 if (IS_ZEBRA_DEBUG_VXLAN)
1511 zlog_debug(
1512 "vrf vni %u unmapping failed with error: %s",
1513 vni, err);
1514 return NB_ERR;
1515 }
1516
1517 break;
1518 }
1519
1520 return NB_OK;
1521 }
1522
1523 /*
1524 * XPath: /frr-vrf:lib/vrf/frr-zebra:zebra/prefix-only
1525 */
1526 int lib_vrf_zebra_prefix_only_modify(struct nb_cb_modify_args *args)
1527 {
1528 switch (args->event) {
1529 case NB_EV_VALIDATE:
1530 case NB_EV_PREPARE:
1531 case NB_EV_ABORT:
1532 case NB_EV_APPLY:
1533 /* TODO: implement me. */
1534 break;
1535 }
1536
1537 return NB_OK;
1538 }