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