]> git.proxmox.com Git - mirror_frr.git/blob - bgpd/bgp_routemap_nb_config.c
Merge pull request #12641 from samanvithab/bgpd_crash
[mirror_frr.git] / bgpd / bgp_routemap_nb_config.c
1 /*
2 * Copyright (C) 2020 Vmware
3 * Sarita Patra
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/command.h"
23 #include "lib/log.h"
24 #include "lib/northbound.h"
25 #include "lib/routemap.h"
26 #include "bgpd/bgpd.h"
27 #include "bgpd/bgp_routemap_nb.h"
28
29 /* Add bgp route map rule. */
30 static int bgp_route_match_add(struct route_map_index *index,
31 const char *command, const char *arg,
32 route_map_event_t type,
33 char *errmsg, size_t errmsg_len)
34 {
35 int retval = CMD_SUCCESS;
36 enum rmap_compile_rets ret;
37
38 ret = route_map_add_match(index, command, arg, type);
39 switch (ret) {
40 case RMAP_RULE_MISSING:
41 snprintf(errmsg, errmsg_len, "%% BGP Can't find rule.");
42 retval = CMD_WARNING_CONFIG_FAILED;
43 break;
44 case RMAP_COMPILE_ERROR:
45 snprintf(errmsg, errmsg_len, "%% BGP Argument is malformed.");
46 retval = CMD_WARNING_CONFIG_FAILED;
47 break;
48 case RMAP_COMPILE_SUCCESS:
49 /*
50 * Intentionally doing nothing here.
51 */
52 break;
53 }
54
55 return retval;
56 }
57
58 /* Delete bgp route map rule. */
59 static int bgp_route_match_delete(struct route_map_index *index,
60 const char *command, const char *arg,
61 route_map_event_t type,
62 char *errmsg, size_t errmsg_len)
63 {
64 enum rmap_compile_rets ret;
65 int retval = CMD_SUCCESS;
66 char *dep_name = NULL;
67 const char *tmpstr;
68 char *rmap_name = NULL;
69
70 if (type != RMAP_EVENT_MATCH_DELETED) {
71 /* ignore the mundane, the types without any dependency */
72 if (arg == NULL) {
73 tmpstr = route_map_get_match_arg(index, command);
74 if (tmpstr != NULL)
75 dep_name =
76 XSTRDUP(MTYPE_ROUTE_MAP_RULE, tmpstr);
77 } else {
78 dep_name = XSTRDUP(MTYPE_ROUTE_MAP_RULE, arg);
79 }
80 rmap_name = XSTRDUP(MTYPE_ROUTE_MAP_NAME, index->map->name);
81 }
82
83 ret = route_map_delete_match(index, command, dep_name, type);
84 switch (ret) {
85 case RMAP_RULE_MISSING:
86 snprintf(errmsg, errmsg_len, "%% BGP Can't find rule.");
87 retval = CMD_WARNING_CONFIG_FAILED;
88 break;
89 case RMAP_COMPILE_ERROR:
90 snprintf(errmsg, errmsg_len,
91 "%% BGP Argument is malformed.");
92 retval = CMD_WARNING_CONFIG_FAILED;
93 break;
94 case RMAP_COMPILE_SUCCESS:
95 /*
96 * Nothing to do here
97 */
98 break;
99 }
100
101 XFREE(MTYPE_ROUTE_MAP_RULE, dep_name);
102 XFREE(MTYPE_ROUTE_MAP_NAME, rmap_name);
103
104 return retval;
105 }
106
107 /*
108 * XPath: /frr-route-map:lib/route-map/entry/match-condition/rmap-match-condition/frr-bgp-route-map:local-preference
109 */
110 int
111 lib_route_map_entry_match_condition_rmap_match_condition_local_preference_modify(
112 struct nb_cb_modify_args *args)
113 {
114 struct routemap_hook_context *rhc;
115 const char *local_pref;
116 enum rmap_compile_rets ret;
117
118 switch (args->event) {
119 case NB_EV_VALIDATE:
120 case NB_EV_PREPARE:
121 case NB_EV_ABORT:
122 break;
123 case NB_EV_APPLY:
124 /* Add configuration. */
125 rhc = nb_running_get_entry(args->dnode, NULL, true);
126 local_pref = yang_dnode_get_string(args->dnode, NULL);
127
128 /* Set destroy information. */
129 rhc->rhc_mhook = bgp_route_match_delete;
130 rhc->rhc_rule = "local-preference";
131 rhc->rhc_event = RMAP_EVENT_MATCH_DELETED;
132
133 ret = bgp_route_match_add(rhc->rhc_rmi, "local-preference",
134 local_pref, RMAP_EVENT_MATCH_ADDED,
135 args->errmsg, args->errmsg_len);
136
137 if (ret != RMAP_COMPILE_SUCCESS) {
138 rhc->rhc_mhook = NULL;
139 return NB_ERR_INCONSISTENCY;
140 }
141 }
142
143 return NB_OK;
144 }
145
146 int
147 lib_route_map_entry_match_condition_rmap_match_condition_local_preference_destroy(
148 struct nb_cb_destroy_args *args)
149 {
150 switch (args->event) {
151 case NB_EV_VALIDATE:
152 case NB_EV_PREPARE:
153 case NB_EV_ABORT:
154 break;
155 case NB_EV_APPLY:
156 return lib_route_map_entry_match_destroy(args);
157 }
158
159 return NB_OK;
160 }
161
162 /*
163 * XPath:
164 * /frr-route-map:lib/route-map/entry/match-condition/rmap-match-condition/frr-bgp-route-map:alias
165 */
166 int lib_route_map_entry_match_condition_rmap_match_condition_alias_modify(
167 struct nb_cb_modify_args *args)
168 {
169 struct routemap_hook_context *rhc;
170 const char *alias;
171 enum rmap_compile_rets ret;
172
173 switch (args->event) {
174 case NB_EV_VALIDATE:
175 case NB_EV_PREPARE:
176 case NB_EV_ABORT:
177 break;
178 case NB_EV_APPLY:
179 /* Add configuration. */
180 rhc = nb_running_get_entry(args->dnode, NULL, true);
181 alias = yang_dnode_get_string(args->dnode, NULL);
182
183 /* Set destroy information. */
184 rhc->rhc_mhook = bgp_route_match_delete;
185 rhc->rhc_rule = "alias";
186 rhc->rhc_event = RMAP_EVENT_MATCH_DELETED;
187
188 ret = bgp_route_match_add(rhc->rhc_rmi, "alias", alias,
189 RMAP_EVENT_MATCH_ADDED, args->errmsg,
190 args->errmsg_len);
191
192 if (ret != RMAP_COMPILE_SUCCESS) {
193 rhc->rhc_mhook = NULL;
194 return NB_ERR_VALIDATION;
195 }
196
197 break;
198 }
199
200 return NB_OK;
201 }
202
203 int lib_route_map_entry_match_condition_rmap_match_condition_alias_destroy(
204 struct nb_cb_destroy_args *args)
205 {
206 switch (args->event) {
207 case NB_EV_VALIDATE:
208 case NB_EV_PREPARE:
209 case NB_EV_ABORT:
210 break;
211 case NB_EV_APPLY:
212 return lib_route_map_entry_match_destroy(args);
213 }
214
215 return NB_OK;
216 }
217
218 /*
219 * XPath: /frr-route-map:lib/route-map/entry/match-condition/rmap-match-condition/frr-bgp-route-map:script
220 */
221 int
222 lib_route_map_entry_match_condition_rmap_match_condition_script_modify(
223 struct nb_cb_modify_args *args)
224 {
225 struct routemap_hook_context *rhc;
226 const char *script;
227 enum rmap_compile_rets ret;
228
229 switch (args->event) {
230 case NB_EV_VALIDATE:
231 case NB_EV_PREPARE:
232 case NB_EV_ABORT:
233 break;
234 case NB_EV_APPLY:
235 /* Add configuration. */
236 rhc = nb_running_get_entry(args->dnode, NULL, true);
237 script = yang_dnode_get_string(args->dnode, NULL);
238
239 /* Set destroy information. */
240 rhc->rhc_mhook = bgp_route_match_delete;
241 rhc->rhc_rule = "script";
242 rhc->rhc_event = RMAP_EVENT_MATCH_DELETED;
243
244 ret = bgp_route_match_add(rhc->rhc_rmi, "script",
245 script, RMAP_EVENT_MATCH_ADDED,
246 args->errmsg, args->errmsg_len);
247
248 if (ret != RMAP_COMPILE_SUCCESS) {
249 rhc->rhc_mhook = NULL;
250 return NB_ERR_INCONSISTENCY;
251 }
252 }
253
254 return NB_OK;
255 }
256
257 int
258 lib_route_map_entry_match_condition_rmap_match_condition_script_destroy(
259 struct nb_cb_destroy_args *args)
260 {
261 switch (args->event) {
262 case NB_EV_VALIDATE:
263 case NB_EV_PREPARE:
264 case NB_EV_ABORT:
265 break;
266 case NB_EV_APPLY:
267 return lib_route_map_entry_match_destroy(args);
268 }
269
270 return NB_OK;
271 }
272
273 /*
274 * XPath: /frr-route-map:lib/route-map/entry/match-condition/rmap-match-condition/frr-bgp-route-map:origin
275 */
276 int
277 lib_route_map_entry_match_condition_rmap_match_condition_origin_modify(
278 struct nb_cb_modify_args *args)
279 {
280 struct routemap_hook_context *rhc;
281 const char *origin;
282 enum rmap_compile_rets ret;
283
284 switch (args->event) {
285 case NB_EV_VALIDATE:
286 case NB_EV_PREPARE:
287 case NB_EV_ABORT:
288 break;
289 case NB_EV_APPLY:
290 /* Add configuration. */
291 rhc = nb_running_get_entry(args->dnode, NULL, true);
292 origin = yang_dnode_get_string(args->dnode, NULL);
293
294 /* Set destroy information. */
295 rhc->rhc_mhook = bgp_route_match_delete;
296 rhc->rhc_rule = "origin";
297 rhc->rhc_event = RMAP_EVENT_MATCH_DELETED;
298
299 ret = bgp_route_match_add(rhc->rhc_rmi, "origin", origin,
300 RMAP_EVENT_MATCH_ADDED,
301 args->errmsg, args->errmsg_len);
302
303 if (ret != RMAP_COMPILE_SUCCESS) {
304 rhc->rhc_mhook = NULL;
305 return NB_ERR_INCONSISTENCY;
306 }
307 }
308
309 return NB_OK;
310 }
311
312 int
313 lib_route_map_entry_match_condition_rmap_match_condition_origin_destroy(
314 struct nb_cb_destroy_args *args)
315 {
316 switch (args->event) {
317 case NB_EV_VALIDATE:
318 case NB_EV_PREPARE:
319 case NB_EV_ABORT:
320 break;
321 case NB_EV_APPLY:
322 return lib_route_map_entry_match_destroy(args);
323 }
324
325 return NB_OK;
326 }
327
328 /*
329 * XPath: /frr-route-map:lib/route-map/entry/match-condition/rmap-match-condition/frr-bgp-route-map:rpki
330 */
331 int
332 lib_route_map_entry_match_condition_rmap_match_condition_rpki_modify(
333 struct nb_cb_modify_args *args)
334 {
335 struct routemap_hook_context *rhc;
336 const char *rpki;
337 enum rmap_compile_rets ret;
338
339 switch (args->event) {
340 case NB_EV_VALIDATE:
341 case NB_EV_PREPARE:
342 case NB_EV_ABORT:
343 break;
344 case NB_EV_APPLY:
345 /* Add configuration. */
346 rhc = nb_running_get_entry(args->dnode, NULL, true);
347 rpki = yang_dnode_get_string(args->dnode, NULL);
348
349 /* Set destroy information. */
350 rhc->rhc_mhook = bgp_route_match_delete;
351 rhc->rhc_rule = "rpki";
352 rhc->rhc_event = RMAP_EVENT_MATCH_DELETED;
353
354 ret = bgp_route_match_add(rhc->rhc_rmi, "rpki", rpki,
355 RMAP_EVENT_MATCH_ADDED,
356 args->errmsg, args->errmsg_len);
357
358 if (ret != RMAP_COMPILE_SUCCESS) {
359 rhc->rhc_mhook = NULL;
360 return NB_ERR_INCONSISTENCY;
361 }
362 }
363
364 return NB_OK;
365 }
366
367 int
368 lib_route_map_entry_match_condition_rmap_match_condition_rpki_destroy(
369 struct nb_cb_destroy_args *args)
370 {
371 switch (args->event) {
372 case NB_EV_VALIDATE:
373 case NB_EV_PREPARE:
374 case NB_EV_ABORT:
375 break;
376 case NB_EV_APPLY:
377 return lib_route_map_entry_match_destroy(args);
378 }
379
380 return NB_OK;
381 }
382
383 /*
384 * XPath:
385 * /frr-route-map:lib/route-map/entry/match-condition/rmap-match-condition/frr-bgp-route-map:rpki-extcommunity
386 */
387 int lib_route_map_entry_match_condition_rmap_match_condition_rpki_extcommunity_modify(
388 struct nb_cb_modify_args *args)
389 {
390 struct routemap_hook_context *rhc;
391 const char *rpki;
392 enum rmap_compile_rets ret;
393
394 switch (args->event) {
395 case NB_EV_VALIDATE:
396 case NB_EV_PREPARE:
397 case NB_EV_ABORT:
398 break;
399 case NB_EV_APPLY:
400 /* Add configuration. */
401 rhc = nb_running_get_entry(args->dnode, NULL, true);
402 rpki = yang_dnode_get_string(args->dnode, NULL);
403
404 /* Set destroy information. */
405 rhc->rhc_mhook = bgp_route_match_delete;
406 rhc->rhc_rule = "rpki-extcommunity";
407 rhc->rhc_event = RMAP_EVENT_MATCH_DELETED;
408
409 ret = bgp_route_match_add(rhc->rhc_rmi, "rpki-extcommunity",
410 rpki, RMAP_EVENT_MATCH_ADDED,
411 args->errmsg, args->errmsg_len);
412
413 if (ret != RMAP_COMPILE_SUCCESS) {
414 rhc->rhc_mhook = NULL;
415 return NB_ERR_INCONSISTENCY;
416 }
417 }
418
419 return NB_OK;
420 }
421
422 int lib_route_map_entry_match_condition_rmap_match_condition_rpki_extcommunity_destroy(
423 struct nb_cb_destroy_args *args)
424 {
425 switch (args->event) {
426 case NB_EV_VALIDATE:
427 case NB_EV_PREPARE:
428 case NB_EV_ABORT:
429 break;
430 case NB_EV_APPLY:
431 return lib_route_map_entry_match_destroy(args);
432 }
433
434 return NB_OK;
435 }
436
437 /*
438 * XPath: /frr-route-map:lib/route-map/entry/match-condition/rmap-match-condition/frr-bgp-route-map:probability
439 */
440 int
441 lib_route_map_entry_match_condition_rmap_match_condition_probability_modify(
442 struct nb_cb_modify_args *args)
443 {
444 struct routemap_hook_context *rhc;
445 const char *probability;
446 enum rmap_compile_rets ret;
447
448 switch (args->event) {
449 case NB_EV_VALIDATE:
450 case NB_EV_PREPARE:
451 case NB_EV_ABORT:
452 break;
453 case NB_EV_APPLY:
454 /* Add configuration. */
455 rhc = nb_running_get_entry(args->dnode, NULL, true);
456 probability = yang_dnode_get_string(args->dnode, NULL);
457
458 /* Set destroy information. */
459 rhc->rhc_mhook = bgp_route_match_delete;
460 rhc->rhc_rule = "probability";
461 rhc->rhc_event = RMAP_EVENT_MATCH_DELETED;
462
463 ret = bgp_route_match_add(rhc->rhc_rmi, "probability",
464 probability, RMAP_EVENT_MATCH_ADDED,
465 args->errmsg, args->errmsg_len);
466
467 if (ret != RMAP_COMPILE_SUCCESS) {
468 rhc->rhc_mhook = NULL;
469 return NB_ERR_INCONSISTENCY;
470 }
471 }
472
473 return NB_OK;
474 }
475
476 int
477 lib_route_map_entry_match_condition_rmap_match_condition_probability_destroy(
478 struct nb_cb_destroy_args *args)
479 {
480 switch (args->event) {
481 case NB_EV_VALIDATE:
482 case NB_EV_PREPARE:
483 case NB_EV_ABORT:
484 case NB_EV_APPLY:
485 return lib_route_map_entry_match_destroy(args);
486 }
487
488 return NB_OK;
489 }
490
491 /*
492 * XPath: /frr-route-map:lib/route-map/entry/match-condition/rmap-match-condition/frr-bgp-route-map:source-vrf
493 */
494 int
495 lib_route_map_entry_match_condition_rmap_match_condition_source_vrf_modify(
496 struct nb_cb_modify_args *args)
497 {
498 struct routemap_hook_context *rhc;
499 const char *vrf;
500 enum rmap_compile_rets ret;
501
502 switch (args->event) {
503 case NB_EV_VALIDATE:
504 case NB_EV_PREPARE:
505 case NB_EV_ABORT:
506 break;
507 case NB_EV_APPLY:
508 /* Add configuration. */
509 rhc = nb_running_get_entry(args->dnode, NULL, true);
510 vrf = yang_dnode_get_string(args->dnode, NULL);
511
512 /* Set destroy information. */
513 rhc->rhc_mhook = bgp_route_match_delete;
514 rhc->rhc_rule = "source-vrf";
515 rhc->rhc_event = RMAP_EVENT_MATCH_DELETED;
516
517 ret = bgp_route_match_add(rhc->rhc_rmi, "source-vrf", vrf,
518 RMAP_EVENT_MATCH_ADDED,
519 args->errmsg, args->errmsg_len);
520
521 if (ret != RMAP_COMPILE_SUCCESS) {
522 rhc->rhc_mhook = NULL;
523 return NB_ERR_INCONSISTENCY;
524 }
525 }
526
527 return NB_OK;
528 }
529
530 int
531 lib_route_map_entry_match_condition_rmap_match_condition_source_vrf_destroy(
532 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 break;
539 case NB_EV_APPLY:
540 return lib_route_map_entry_match_destroy(args);
541 }
542
543 return NB_OK;
544 }
545
546 /*
547 * XPath: /frr-route-map:lib/route-map/entry/match-condition/rmap-match-condition/frr-bgp-route-map:peer-ipv4-address
548 */
549 int
550 lib_route_map_entry_match_condition_rmap_match_condition_peer_ipv4_address_modify(
551 struct nb_cb_modify_args *args)
552 {
553 struct routemap_hook_context *rhc;
554 const char *peer;
555 enum rmap_compile_rets ret;
556
557 switch (args->event) {
558 case NB_EV_VALIDATE:
559 case NB_EV_PREPARE:
560 case NB_EV_ABORT:
561 break;
562 case NB_EV_APPLY:
563 /* Add configuration. */
564 rhc = nb_running_get_entry(args->dnode, NULL, true);
565 peer = yang_dnode_get_string(args->dnode, NULL);
566
567 /* Set destroy information. */
568 rhc->rhc_mhook = bgp_route_match_delete;
569 rhc->rhc_rule = "peer";
570 rhc->rhc_event = RMAP_EVENT_MATCH_DELETED;
571
572 ret = bgp_route_match_add(rhc->rhc_rmi, "peer", peer,
573 RMAP_EVENT_MATCH_ADDED,
574 args->errmsg, args->errmsg_len);
575
576 if (ret != RMAP_COMPILE_SUCCESS) {
577 rhc->rhc_mhook = NULL;
578 return NB_ERR_INCONSISTENCY;
579 }
580 }
581
582 return NB_OK;
583 }
584
585 int
586 lib_route_map_entry_match_condition_rmap_match_condition_peer_ipv4_address_destroy(
587 struct nb_cb_destroy_args *args)
588 {
589 switch (args->event) {
590 case NB_EV_VALIDATE:
591 case NB_EV_PREPARE:
592 case NB_EV_ABORT:
593 break;
594 case NB_EV_APPLY:
595 return lib_route_map_entry_match_destroy(args);
596 }
597
598 return NB_OK;
599 }
600
601 /*
602 * XPath: /frr-route-map:lib/route-map/entry/match-condition/rmap-match-condition/frr-bgp-route-map:peer-interface
603 */
604 int
605 lib_route_map_entry_match_condition_rmap_match_condition_peer_interface_modify(
606 struct nb_cb_modify_args *args)
607 {
608 struct routemap_hook_context *rhc;
609 const char *peer;
610 enum rmap_compile_rets ret;
611
612 switch (args->event) {
613 case NB_EV_VALIDATE:
614 case NB_EV_PREPARE:
615 case NB_EV_ABORT:
616 break;
617 case NB_EV_APPLY:
618 /* Add configuration. */
619 rhc = nb_running_get_entry(args->dnode, NULL, true);
620 peer = yang_dnode_get_string(args->dnode, NULL);
621
622 /* Set destroy information. */
623 rhc->rhc_mhook = bgp_route_match_delete;
624 rhc->rhc_rule = "peer";
625 rhc->rhc_event = RMAP_EVENT_MATCH_DELETED;
626
627 ret = bgp_route_match_add(rhc->rhc_rmi, "peer", peer,
628 RMAP_EVENT_MATCH_ADDED,
629 args->errmsg, args->errmsg_len);
630
631 if (ret != RMAP_COMPILE_SUCCESS) {
632 rhc->rhc_mhook = NULL;
633 return NB_ERR_INCONSISTENCY;
634 }
635 }
636
637 return NB_OK;
638 }
639
640 int
641 lib_route_map_entry_match_condition_rmap_match_condition_peer_interface_destroy(
642 struct nb_cb_destroy_args *args)
643 {
644 switch (args->event) {
645 case NB_EV_VALIDATE:
646 case NB_EV_PREPARE:
647 case NB_EV_ABORT:
648 break;
649 case NB_EV_APPLY:
650 return lib_route_map_entry_match_destroy(args);
651 }
652
653 return NB_OK;
654 }
655
656 /*
657 * XPath: /frr-route-map:lib/route-map/entry/match-condition/rmap-match-condition/frr-bgp-route-map:peer-ipv6-address
658 */
659 int
660 lib_route_map_entry_match_condition_rmap_match_condition_peer_ipv6_address_modify(
661 struct nb_cb_modify_args *args)
662 {
663 struct routemap_hook_context *rhc;
664 const char *peer;
665 enum rmap_compile_rets ret;
666
667 switch (args->event) {
668 case NB_EV_VALIDATE:
669 case NB_EV_PREPARE:
670 case NB_EV_ABORT:
671 break;
672 case NB_EV_APPLY:
673 /* Add configuration. */
674 rhc = nb_running_get_entry(args->dnode, NULL, true);
675 peer = yang_dnode_get_string(args->dnode, NULL);
676
677 /* Set destroy information. */
678 rhc->rhc_mhook = bgp_route_match_delete;
679 rhc->rhc_rule = "peer";
680 rhc->rhc_event = RMAP_EVENT_MATCH_DELETED;
681
682 ret = bgp_route_match_add(rhc->rhc_rmi, "peer", peer,
683 RMAP_EVENT_MATCH_ADDED,
684 args->errmsg, args->errmsg_len);
685
686 if (ret != RMAP_COMPILE_SUCCESS) {
687 rhc->rhc_mhook = NULL;
688 return NB_ERR_INCONSISTENCY;
689 }
690 }
691
692 return NB_OK;
693 }
694
695 int
696 lib_route_map_entry_match_condition_rmap_match_condition_peer_ipv6_address_destroy(
697 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 break;
704 case NB_EV_APPLY:
705 return lib_route_map_entry_match_destroy(args);
706 }
707
708 return NB_OK;
709 }
710
711 /*
712 * XPath: /frr-route-map:lib/route-map/entry/match-condition/rmap-match-condition/frr-bgp-route-map:peer-local
713 */
714 int
715 lib_route_map_entry_match_condition_rmap_match_condition_peer_local_modify(
716 struct nb_cb_modify_args *args)
717 {
718 struct routemap_hook_context *rhc;
719 bool value;
720 enum rmap_compile_rets ret;
721
722 switch (args->event) {
723 case NB_EV_VALIDATE:
724 case NB_EV_PREPARE:
725 case NB_EV_ABORT:
726 break;
727 case NB_EV_APPLY:
728 /* Add configuration. */
729 rhc = nb_running_get_entry(args->dnode, NULL, true);
730 value = yang_dnode_get_bool(args->dnode, NULL);
731
732 /* Set destroy information. */
733 rhc->rhc_mhook = bgp_route_match_delete;
734 rhc->rhc_rule = "peer";
735 rhc->rhc_event = RMAP_EVENT_MATCH_DELETED;
736
737 if (value) {
738 ret = bgp_route_match_add(rhc->rhc_rmi, "peer",
739 "local",
740 RMAP_EVENT_MATCH_ADDED,
741 args->errmsg, args->errmsg_len);
742
743 if (ret != RMAP_COMPILE_SUCCESS) {
744 rhc->rhc_mhook = NULL;
745 return NB_ERR_INCONSISTENCY;
746 }
747 }
748 }
749
750 return NB_OK;
751 }
752
753 int
754 lib_route_map_entry_match_condition_rmap_match_condition_peer_local_destroy(
755 struct nb_cb_destroy_args *args)
756 {
757 switch (args->event) {
758 case NB_EV_VALIDATE:
759 case NB_EV_PREPARE:
760 case NB_EV_ABORT:
761 break;
762 case NB_EV_APPLY:
763 return lib_route_map_entry_match_destroy(args);
764 }
765
766 return NB_OK;
767 }
768
769 /*
770 * XPath: /frr-route-map:lib/route-map/entry/match-condition/rmap-match-condition/frr-bgp-route-map:list-name
771 */
772 int
773 lib_route_map_entry_match_condition_rmap_match_condition_list_name_modify(
774 struct nb_cb_modify_args *args)
775 {
776 struct routemap_hook_context *rhc;
777 const char *list_name;
778 enum rmap_compile_rets ret = RMAP_COMPILE_SUCCESS;
779 const char *condition;
780
781 switch (args->event) {
782 case NB_EV_VALIDATE:
783 case NB_EV_PREPARE:
784 case NB_EV_ABORT:
785 break;
786 case NB_EV_APPLY:
787 /* Add configuration. */
788 rhc = nb_running_get_entry(args->dnode, NULL, true);
789 list_name = yang_dnode_get_string(args->dnode, NULL);
790 condition = yang_dnode_get_string(args->dnode,
791 "../../frr-route-map:condition");
792
793 if (IS_MATCH_AS_LIST(condition)) {
794 /* Set destroy information. */
795 rhc->rhc_mhook = bgp_route_match_delete;
796 rhc->rhc_rule = "as-path";
797 rhc->rhc_event = RMAP_EVENT_ASLIST_DELETED;
798
799 ret = bgp_route_match_add(rhc->rhc_rmi, "as-path",
800 list_name, RMAP_EVENT_ASLIST_ADDED,
801 args->errmsg, args->errmsg_len);
802 } else if (IS_MATCH_MAC_LIST(condition)) {
803 /* Set destroy information. */
804 rhc->rhc_mhook = bgp_route_match_delete;
805 rhc->rhc_rule = "mac address";
806 rhc->rhc_event = RMAP_EVENT_FILTER_DELETED;
807
808 ret = bgp_route_match_add(rhc->rhc_rmi,
809 "mac address",
810 list_name,
811 RMAP_EVENT_FILTER_ADDED,
812 args->errmsg, args->errmsg_len);
813 } else if (IS_MATCH_ROUTE_SRC(condition)) {
814 /* Set destroy information. */
815 rhc->rhc_mhook = bgp_route_match_delete;
816 rhc->rhc_rule = "ip route-source";
817 rhc->rhc_event = RMAP_EVENT_FILTER_DELETED;
818
819 ret = bgp_route_match_add(rhc->rhc_rmi,
820 "ip route-source",
821 list_name, RMAP_EVENT_FILTER_ADDED,
822 args->errmsg, args->errmsg_len);
823 } else if (IS_MATCH_ROUTE_SRC_PL(condition)) {
824 /* Set destroy information. */
825 rhc->rhc_mhook = bgp_route_match_delete;
826 rhc->rhc_rule = "ip route-source prefix-list";
827 rhc->rhc_event = RMAP_EVENT_PLIST_DELETED;
828
829 ret = bgp_route_match_add(rhc->rhc_rmi,
830 "ip route-source prefix-list",
831 list_name, RMAP_EVENT_PLIST_ADDED,
832 args->errmsg, args->errmsg_len);
833 }
834
835 if (ret != RMAP_COMPILE_SUCCESS) {
836 rhc->rhc_mhook = NULL;
837 return NB_ERR_INCONSISTENCY;
838 }
839 }
840
841 return NB_OK;
842 }
843
844 int
845 lib_route_map_entry_match_condition_rmap_match_condition_list_name_destroy(
846 struct nb_cb_destroy_args *args)
847 {
848 switch (args->event) {
849 case NB_EV_VALIDATE:
850 case NB_EV_PREPARE:
851 case NB_EV_ABORT:
852 break;
853 case NB_EV_APPLY:
854 return lib_route_map_entry_match_destroy(args);
855 }
856
857 return NB_OK;
858 }
859
860 /*
861 * XPath: /frr-route-map:lib/route-map/entry/match-condition/rmap-match-condition/frr-bgp-route-map:evpn-default-route
862 */
863 int
864 lib_route_map_entry_match_condition_rmap_match_condition_evpn_default_route_create(
865 struct nb_cb_create_args *args)
866 {
867 struct routemap_hook_context *rhc;
868 enum rmap_compile_rets ret;
869
870 switch (args->event) {
871 case NB_EV_VALIDATE:
872 case NB_EV_PREPARE:
873 case NB_EV_ABORT:
874 break;
875 case NB_EV_APPLY:
876 /* Add configuration. */
877 rhc = nb_running_get_entry(args->dnode, NULL, true);
878
879 /* Set destroy information. */
880 rhc->rhc_mhook = bgp_route_match_delete;
881 rhc->rhc_rule = "evpn default-route";
882 rhc->rhc_event = RMAP_EVENT_MATCH_DELETED;
883
884 ret = bgp_route_match_add(rhc->rhc_rmi, "evpn default-route",
885 NULL, RMAP_EVENT_MATCH_ADDED,
886 args->errmsg, args->errmsg_len);
887
888 if (ret != RMAP_COMPILE_SUCCESS) {
889 rhc->rhc_mhook = NULL;
890 return NB_ERR_INCONSISTENCY;
891 }
892 }
893
894 return NB_OK;
895 }
896
897 int
898 lib_route_map_entry_match_condition_rmap_match_condition_evpn_default_route_destroy(
899 struct nb_cb_destroy_args *args)
900 {
901 switch (args->event) {
902 case NB_EV_VALIDATE:
903 case NB_EV_PREPARE:
904 case NB_EV_ABORT:
905 break;
906 case NB_EV_APPLY:
907 return lib_route_map_entry_match_destroy(args);
908 }
909
910 return NB_OK;
911 }
912
913 /*
914 * XPath: /frr-route-map:lib/route-map/entry/match-condition/rmap-match-condition/frr-bgp-route-map:evpn-vni
915 */
916 int
917 lib_route_map_entry_match_condition_rmap_match_condition_evpn_vni_modify(
918 struct nb_cb_modify_args *args)
919 {
920 struct routemap_hook_context *rhc;
921 const char *vni;
922 enum rmap_compile_rets ret;
923
924 switch (args->event) {
925 case NB_EV_VALIDATE:
926 case NB_EV_PREPARE:
927 case NB_EV_ABORT:
928 break;
929 case NB_EV_APPLY:
930 /* Add configuration. */
931 rhc = nb_running_get_entry(args->dnode, NULL, true);
932 vni = yang_dnode_get_string(args->dnode, NULL);
933
934 /* Set destroy information. */
935 rhc->rhc_mhook = bgp_route_match_delete;
936 rhc->rhc_rule = "evpn vni";
937 rhc->rhc_event = RMAP_EVENT_MATCH_DELETED;
938
939 ret = bgp_route_match_add(rhc->rhc_rmi, "evpn vni", vni,
940 RMAP_EVENT_MATCH_ADDED,
941 args->errmsg, args->errmsg_len);
942
943 if (ret != RMAP_COMPILE_SUCCESS) {
944 rhc->rhc_mhook = NULL;
945 return NB_ERR_INCONSISTENCY;
946 }
947 }
948
949 return NB_OK;
950 }
951
952 int
953 lib_route_map_entry_match_condition_rmap_match_condition_evpn_vni_destroy(
954 struct nb_cb_destroy_args *args)
955 {
956 switch (args->event) {
957 case NB_EV_VALIDATE:
958 case NB_EV_PREPARE:
959 case NB_EV_ABORT:
960 break;
961 case NB_EV_APPLY:
962 return lib_route_map_entry_match_destroy(args);
963 }
964
965 return NB_OK;
966 }
967
968 /*
969 * XPath: /frr-route-map:lib/route-map/entry/match-condition/rmap-match-condition/frr-bgp-route-map:evpn-route-type
970 */
971 int
972 lib_route_map_entry_match_condition_rmap_match_condition_evpn_route_type_modify(
973 struct nb_cb_modify_args *args)
974 {
975 struct routemap_hook_context *rhc;
976 const char *type;
977 enum rmap_compile_rets ret;
978
979 switch (args->event) {
980 case NB_EV_VALIDATE:
981 case NB_EV_PREPARE:
982 case NB_EV_ABORT:
983 break;
984 case NB_EV_APPLY:
985 /* Add configuration. */
986 rhc = nb_running_get_entry(args->dnode, NULL, true);
987 type = yang_dnode_get_string(args->dnode, NULL);
988
989 /* Set destroy information. */
990 rhc->rhc_mhook = bgp_route_match_delete;
991 rhc->rhc_rule = "evpn route-type";
992 rhc->rhc_event = RMAP_EVENT_MATCH_DELETED;
993
994 ret = bgp_route_match_add(rhc->rhc_rmi, "evpn route-type",
995 type,
996 RMAP_EVENT_MATCH_ADDED,
997 args->errmsg, args->errmsg_len);
998
999 if (ret != RMAP_COMPILE_SUCCESS) {
1000 rhc->rhc_mhook = NULL;
1001 return NB_ERR_INCONSISTENCY;
1002 }
1003 }
1004
1005 return NB_OK;
1006 }
1007
1008 int
1009 lib_route_map_entry_match_condition_rmap_match_condition_evpn_route_type_destroy(
1010 struct nb_cb_destroy_args *args)
1011 {
1012 switch (args->event) {
1013 case NB_EV_VALIDATE:
1014 case NB_EV_PREPARE:
1015 case NB_EV_ABORT:
1016 break;
1017 case NB_EV_APPLY:
1018 return lib_route_map_entry_match_destroy(args);
1019 }
1020
1021 return NB_OK;
1022 }
1023
1024 /*
1025 * XPath: /frr-route-map:lib/route-map/entry/match-condition/rmap-match-condition/frr-bgp-route-map:route-distinguisher
1026 */
1027 int
1028 lib_route_map_entry_match_condition_rmap_match_condition_route_distinguisher_modify(
1029 struct nb_cb_modify_args *args)
1030 {
1031 struct routemap_hook_context *rhc;
1032 const char *rd;
1033 enum rmap_compile_rets ret;
1034
1035 switch (args->event) {
1036 case NB_EV_VALIDATE:
1037 case NB_EV_PREPARE:
1038 case NB_EV_ABORT:
1039 break;
1040 case NB_EV_APPLY:
1041 /* Add configuration. */
1042 rhc = nb_running_get_entry(args->dnode, NULL, true);
1043 rd = yang_dnode_get_string(args->dnode, NULL);
1044
1045 /* Set destroy information. */
1046 rhc->rhc_mhook = bgp_route_match_delete;
1047 rhc->rhc_rule = "evpn rd";
1048 rhc->rhc_event = RMAP_EVENT_MATCH_DELETED;
1049
1050 ret = bgp_route_match_add(rhc->rhc_rmi, "evpn rd", rd,
1051 RMAP_EVENT_MATCH_ADDED,
1052 args->errmsg, args->errmsg_len);
1053
1054 if (ret != RMAP_COMPILE_SUCCESS) {
1055 rhc->rhc_mhook = NULL;
1056 return NB_ERR_INCONSISTENCY;
1057 }
1058 }
1059
1060 return NB_OK;
1061 }
1062
1063 int
1064 lib_route_map_entry_match_condition_rmap_match_condition_route_distinguisher_destroy(
1065 struct nb_cb_destroy_args *args)
1066 {
1067 switch (args->event) {
1068 case NB_EV_VALIDATE:
1069 case NB_EV_PREPARE:
1070 case NB_EV_ABORT:
1071 break;
1072 case NB_EV_APPLY:
1073 return lib_route_map_entry_match_destroy(args);
1074 }
1075
1076 return NB_OK;
1077 }
1078
1079 /*
1080 * XPath = /frr-route-map:lib/route-map/entry/match-condition/rmap-match-condition/frr-bgp-route-map:comm-list
1081 */
1082 void
1083 lib_route_map_entry_match_condition_rmap_match_condition_comm_list_finish(
1084 struct nb_cb_apply_finish_args *args)
1085 {
1086 struct routemap_hook_context *rhc;
1087 const char *value;
1088 bool exact_match = false;
1089 char *argstr;
1090 const char *condition;
1091 route_map_event_t event;
1092 int ret;
1093
1094 /* Add configuration. */
1095 rhc = nb_running_get_entry(args->dnode, NULL, true);
1096 value = yang_dnode_get_string(args->dnode, "./comm-list-name");
1097
1098 if (yang_dnode_exists(args->dnode, "./comm-list-name-exact-match"))
1099 exact_match = yang_dnode_get_bool(
1100 args->dnode, "./comm-list-name-exact-match");
1101
1102 if (exact_match) {
1103 argstr = XMALLOC(MTYPE_ROUTE_MAP_COMPILED,
1104 strlen(value) + strlen("exact-match") + 2);
1105
1106 snprintf(argstr, (strlen(value) + strlen("exact-match") + 2),
1107 "%s exact-match", value);
1108 } else
1109 argstr = (char *)value;
1110
1111 /* Set destroy information. */
1112 rhc->rhc_mhook = bgp_route_match_delete;
1113
1114 condition = yang_dnode_get_string(args->dnode,
1115 "../../frr-route-map:condition");
1116 if (IS_MATCH_COMMUNITY(condition)) {
1117 rhc->rhc_rule = "community";
1118 event = RMAP_EVENT_CLIST_ADDED;
1119 rhc->rhc_event = RMAP_EVENT_CLIST_DELETED;
1120 } else if (IS_MATCH_LCOMMUNITY(condition)) {
1121 rhc->rhc_rule = "large-community";
1122 event = RMAP_EVENT_LLIST_ADDED;
1123 rhc->rhc_event = RMAP_EVENT_LLIST_DELETED;
1124 } else {
1125 rhc->rhc_rule = "extcommunity";
1126 event = RMAP_EVENT_ECLIST_ADDED;
1127 rhc->rhc_event = RMAP_EVENT_ECLIST_DELETED;
1128 }
1129
1130 ret = bgp_route_match_add(rhc->rhc_rmi, rhc->rhc_rule, argstr, event,
1131 args->errmsg, args->errmsg_len);
1132 /*
1133 * At this point if this is not a successful operation
1134 * bgpd is about to crash. Let's just cut to the
1135 * chase and do it.
1136 */
1137 assert(ret == RMAP_COMPILE_SUCCESS);
1138
1139 if (argstr != value)
1140 XFREE(MTYPE_ROUTE_MAP_COMPILED, argstr);
1141 }
1142
1143 /*
1144 * XPath:
1145 * /frr-route-map:lib/route-map/entry/match-condition/rmap-match-condition/frr-bgp-route-map:comm-list/comm-list-name
1146 */
1147 int
1148 lib_route_map_entry_match_condition_rmap_match_condition_comm_list_comm_list_name_modify(
1149 struct nb_cb_modify_args *args)
1150 {
1151 switch (args->event) {
1152 case NB_EV_VALIDATE:
1153 case NB_EV_PREPARE:
1154 case NB_EV_ABORT:
1155 case NB_EV_APPLY:
1156 break;
1157 }
1158
1159 return NB_OK;
1160 }
1161
1162 int
1163 lib_route_map_entry_match_condition_rmap_match_condition_comm_list_comm_list_name_destroy(
1164 struct nb_cb_destroy_args *args)
1165 {
1166 switch (args->event) {
1167 case NB_EV_VALIDATE:
1168 case NB_EV_PREPARE:
1169 case NB_EV_ABORT:
1170 break;
1171 case NB_EV_APPLY:
1172 return lib_route_map_entry_match_destroy(args);
1173 }
1174
1175 return NB_OK;
1176
1177 }
1178
1179 /*
1180 * XPath: /frr-route-map:lib/route-map/entry/match-condition/rmap-match-condition/frr-bgp-route-map:comm-list/comm-list-name-exact-match
1181 */
1182 int
1183 lib_route_map_entry_match_condition_rmap_match_condition_comm_list_comm_list_name_exact_match_modify(
1184 struct nb_cb_modify_args *args)
1185 {
1186 switch (args->event) {
1187 case NB_EV_VALIDATE:
1188 case NB_EV_PREPARE:
1189 case NB_EV_ABORT:
1190 case NB_EV_APPLY:
1191 break;
1192 }
1193
1194 return NB_OK;
1195 }
1196
1197 int
1198 lib_route_map_entry_match_condition_rmap_match_condition_comm_list_comm_list_name_exact_match_destroy(
1199 struct nb_cb_destroy_args *args)
1200 {
1201 switch (args->event) {
1202 case NB_EV_VALIDATE:
1203 case NB_EV_PREPARE:
1204 case NB_EV_ABORT:
1205 break;
1206 case NB_EV_APPLY:
1207 return lib_route_map_entry_match_destroy(args);
1208 }
1209
1210 return NB_OK;
1211 }
1212
1213 /*
1214 * XPath: /frr-route-map:lib/route-map/entry/match-condition/rmap-match-condition/frr-bgp-route-map:ipv4-address
1215 */
1216 int
1217 lib_route_map_entry_match_condition_rmap_match_condition_ipv4_address_modify(
1218 struct nb_cb_modify_args *args)
1219 {
1220 struct routemap_hook_context *rhc;
1221 const char *peer;
1222 enum rmap_compile_rets ret;
1223
1224 switch (args->event) {
1225 case NB_EV_VALIDATE:
1226 case NB_EV_PREPARE:
1227 case NB_EV_ABORT:
1228 break;
1229 case NB_EV_APPLY:
1230 /* Add configuration. */
1231 rhc = nb_running_get_entry(args->dnode, NULL, true);
1232 peer = yang_dnode_get_string(args->dnode, NULL);
1233
1234 /* Set destroy information. */
1235 rhc->rhc_mhook = bgp_route_match_delete;
1236 rhc->rhc_rule = "ip next-hop address";
1237 rhc->rhc_event = RMAP_EVENT_MATCH_DELETED;
1238
1239 ret = bgp_route_match_add(rhc->rhc_rmi, rhc->rhc_rule,
1240 peer, RMAP_EVENT_MATCH_ADDED,
1241 args->errmsg, args->errmsg_len);
1242
1243 if (ret != RMAP_COMPILE_SUCCESS) {
1244 rhc->rhc_mhook = NULL;
1245 return NB_ERR_INCONSISTENCY;
1246 }
1247 }
1248
1249 return NB_OK;
1250 }
1251
1252 int
1253 lib_route_map_entry_match_condition_rmap_match_condition_ipv4_address_destroy(
1254 struct nb_cb_destroy_args *args)
1255 {
1256 switch (args->event) {
1257 case NB_EV_VALIDATE:
1258 case NB_EV_PREPARE:
1259 case NB_EV_ABORT:
1260 break;
1261 case NB_EV_APPLY:
1262 return lib_route_map_entry_match_destroy(args);
1263 }
1264
1265 return NB_OK;
1266 }
1267
1268 /*
1269 * XPath: /frr-route-map:lib/route-map/entry/match-condition/rmap-match-condition/frr-bgp-route-map:ipv6-address
1270 */
1271 int
1272 lib_route_map_entry_match_condition_rmap_match_condition_ipv6_address_modify(
1273 struct nb_cb_modify_args *args)
1274 {
1275 struct routemap_hook_context *rhc;
1276 const char *peer;
1277 enum rmap_compile_rets ret;
1278
1279 switch (args->event) {
1280 case NB_EV_VALIDATE:
1281 case NB_EV_PREPARE:
1282 case NB_EV_ABORT:
1283 break;
1284 case NB_EV_APPLY:
1285 /* Add configuration. */
1286 rhc = nb_running_get_entry(args->dnode, NULL, true);
1287 peer = yang_dnode_get_string(args->dnode, NULL);
1288
1289 /* Set destroy information. */
1290 rhc->rhc_mhook = bgp_route_match_delete;
1291 rhc->rhc_rule = "ipv6 next-hop address";
1292 rhc->rhc_event = RMAP_EVENT_MATCH_DELETED;
1293
1294 ret = bgp_route_match_add(rhc->rhc_rmi, rhc->rhc_rule,
1295 peer, RMAP_EVENT_MATCH_ADDED,
1296 args->errmsg, args->errmsg_len);
1297
1298 if (ret != RMAP_COMPILE_SUCCESS) {
1299 rhc->rhc_mhook = NULL;
1300 return NB_ERR_INCONSISTENCY;
1301 }
1302 }
1303
1304 return NB_OK;
1305 }
1306
1307 int
1308 lib_route_map_entry_match_condition_rmap_match_condition_ipv6_address_destroy(
1309 struct nb_cb_destroy_args *args)
1310 {
1311 switch (args->event) {
1312 case NB_EV_VALIDATE:
1313 case NB_EV_PREPARE:
1314 case NB_EV_ABORT:
1315 break;
1316 case NB_EV_APPLY:
1317 return lib_route_map_entry_match_destroy(args);
1318 }
1319
1320 return NB_OK;
1321 }
1322
1323 /*
1324 * XPath:
1325 * /frr-route-map:lib/route-map/entry/set-action/rmap-set-action/frr-bgp-route-map:distance
1326 */
1327 int lib_route_map_entry_set_action_rmap_set_action_distance_modify(
1328 struct nb_cb_modify_args *args)
1329 {
1330 struct routemap_hook_context *rhc;
1331 const char *type;
1332 int rv;
1333
1334 switch (args->event) {
1335 case NB_EV_VALIDATE:
1336 case NB_EV_PREPARE:
1337 case NB_EV_ABORT:
1338 break;
1339 case NB_EV_APPLY:
1340 /* Add configuration. */
1341 rhc = nb_running_get_entry(args->dnode, NULL, true);
1342 type = yang_dnode_get_string(args->dnode, NULL);
1343
1344 /* Set destroy information. */
1345 rhc->rhc_shook = generic_set_delete;
1346 rhc->rhc_rule = "distance";
1347 rhc->rhc_event = RMAP_EVENT_SET_DELETED;
1348
1349 rv = generic_set_add(rhc->rhc_rmi, "distance", type,
1350 args->errmsg, args->errmsg_len);
1351 if (rv != CMD_SUCCESS) {
1352 rhc->rhc_shook = NULL;
1353 return NB_ERR_INCONSISTENCY;
1354 }
1355 }
1356
1357 return NB_OK;
1358 }
1359
1360 int lib_route_map_entry_set_action_rmap_set_action_distance_destroy(
1361 struct nb_cb_destroy_args *args)
1362 {
1363 switch (args->event) {
1364 case NB_EV_VALIDATE:
1365 case NB_EV_PREPARE:
1366 case NB_EV_ABORT:
1367 break;
1368 case NB_EV_APPLY:
1369 return lib_route_map_entry_match_destroy(args);
1370 }
1371
1372 return NB_OK;
1373 }
1374
1375 /*
1376 * XPath:
1377 * /frr-route-map:lib/route-map/entry/set-action/rmap-set-action/frr-bgp-route-map:extcommunity-rt
1378 */
1379 int
1380 lib_route_map_entry_set_action_rmap_set_action_extcommunity_rt_modify(
1381 struct nb_cb_modify_args *args)
1382 {
1383 struct routemap_hook_context *rhc;
1384 const char *type;
1385 int rv;
1386
1387 switch (args->event) {
1388 case NB_EV_VALIDATE:
1389 case NB_EV_PREPARE:
1390 case NB_EV_ABORT:
1391 break;
1392 case NB_EV_APPLY:
1393 /* Add configuration. */
1394 rhc = nb_running_get_entry(args->dnode, NULL, true);
1395 type = yang_dnode_get_string(args->dnode, NULL);
1396
1397 /* Set destroy information. */
1398 rhc->rhc_shook = generic_set_delete;
1399 rhc->rhc_rule = "extcommunity rt";
1400 rhc->rhc_event = RMAP_EVENT_SET_DELETED;
1401
1402 rv = generic_set_add(rhc->rhc_rmi, "extcommunity rt", type,
1403 args->errmsg, args->errmsg_len);
1404 if (rv != CMD_SUCCESS) {
1405 rhc->rhc_shook = NULL;
1406 return NB_ERR_INCONSISTENCY;
1407 }
1408 }
1409
1410 return NB_OK;
1411 }
1412
1413 int
1414 lib_route_map_entry_set_action_rmap_set_action_extcommunity_rt_destroy(
1415 struct nb_cb_destroy_args *args)
1416 {
1417 switch (args->event) {
1418 case NB_EV_VALIDATE:
1419 case NB_EV_PREPARE:
1420 case NB_EV_ABORT:
1421 break;
1422 case NB_EV_APPLY:
1423 return lib_route_map_entry_match_destroy(args);
1424 }
1425
1426 return NB_OK;
1427 }
1428
1429 /*
1430 * XPath:
1431 * /frr-route-map:lib/route-map/entry/set-action/rmap-set-action/frr-bgp-route-map:extcommunity-soo
1432 */
1433 int
1434 lib_route_map_entry_set_action_rmap_set_action_extcommunity_soo_modify(
1435 struct nb_cb_modify_args *args)
1436 {
1437 struct routemap_hook_context *rhc;
1438 const char *type;
1439 int rv;
1440
1441 switch (args->event) {
1442 case NB_EV_VALIDATE:
1443 case NB_EV_PREPARE:
1444 case NB_EV_ABORT:
1445 break;
1446 case NB_EV_APPLY:
1447 /* Add configuration. */
1448 rhc = nb_running_get_entry(args->dnode, NULL, true);
1449 type = yang_dnode_get_string(args->dnode, NULL);
1450
1451 /* Set destroy information. */
1452 rhc->rhc_shook = generic_set_delete;
1453 rhc->rhc_rule = "extcommunity soo";
1454 rhc->rhc_event = RMAP_EVENT_SET_DELETED;
1455
1456 rv = generic_set_add(rhc->rhc_rmi, "extcommunity soo",
1457 type,
1458 args->errmsg, args->errmsg_len);
1459 if (rv != CMD_SUCCESS) {
1460 rhc->rhc_shook = NULL;
1461 return NB_ERR_INCONSISTENCY;
1462 }
1463 }
1464
1465 return NB_OK;
1466 }
1467
1468 int
1469 lib_route_map_entry_set_action_rmap_set_action_extcommunity_soo_destroy(
1470 struct nb_cb_destroy_args *args)
1471 {
1472 switch (args->event) {
1473 case NB_EV_VALIDATE:
1474 case NB_EV_PREPARE:
1475 case NB_EV_ABORT:
1476 break;
1477 case NB_EV_APPLY:
1478 return lib_route_map_entry_match_destroy(args);
1479 }
1480
1481 return NB_OK;
1482 }
1483
1484 /*
1485 * XPath:
1486 * /frr-route-map:lib/route-map/entry/set-action/rmap-set-action/frr-bgp-route-map:ipv4-address
1487 */
1488 int lib_route_map_entry_set_action_rmap_set_action_ipv4_address_modify(
1489 struct nb_cb_modify_args *args)
1490 {
1491 struct routemap_hook_context *rhc;
1492 const char *addr;
1493 int rv = CMD_SUCCESS;
1494
1495 switch (args->event) {
1496 case NB_EV_VALIDATE:
1497 case NB_EV_PREPARE:
1498 case NB_EV_ABORT:
1499 break;
1500 case NB_EV_APPLY:
1501 /* Add configuration. */
1502 rhc = nb_running_get_entry(args->dnode, NULL, true);
1503 addr = yang_dnode_get_string(args->dnode, NULL);
1504
1505 rhc->rhc_shook = generic_set_delete;
1506 rhc->rhc_event = RMAP_EVENT_SET_DELETED;
1507 rhc->rhc_rule = "ipv4 vpn next-hop";
1508
1509 rv = generic_set_add(rhc->rhc_rmi, rhc->rhc_rule, addr,
1510 args->errmsg, args->errmsg_len);
1511
1512 if (rv != CMD_SUCCESS) {
1513 rhc->rhc_shook = NULL;
1514 return NB_ERR_INCONSISTENCY;
1515 }
1516 }
1517
1518 return NB_OK;
1519 }
1520
1521 int lib_route_map_entry_set_action_rmap_set_action_ipv4_address_destroy(
1522 struct nb_cb_destroy_args *args)
1523 {
1524 switch (args->event) {
1525 case NB_EV_VALIDATE:
1526 case NB_EV_PREPARE:
1527 case NB_EV_ABORT:
1528 break;
1529 case NB_EV_APPLY:
1530 return lib_route_map_entry_set_destroy(args);
1531 }
1532
1533 return NB_OK;
1534 }
1535
1536 /*
1537 * XPath:
1538 * /frr-route-map:lib/route-map/entry/set-action/rmap-set-action/frr-bgp-route-map:ipv4-nexthop
1539 */
1540 int lib_route_map_entry_set_action_rmap_set_action_ipv4_nexthop_modify(
1541 struct nb_cb_modify_args *args)
1542 {
1543 struct routemap_hook_context *rhc;
1544 const char *type;
1545 int rv;
1546
1547 switch (args->event) {
1548 case NB_EV_VALIDATE:
1549 case NB_EV_PREPARE:
1550 case NB_EV_ABORT:
1551 break;
1552 case NB_EV_APPLY:
1553 /* Add configuration. */
1554 rhc = nb_running_get_entry(args->dnode, NULL, true);
1555 type = yang_dnode_get_string(args->dnode, NULL);
1556
1557 /* Set destroy information. */
1558 rhc->rhc_shook = generic_set_delete;
1559 rhc->rhc_rule = "ip next-hop";
1560 rhc->rhc_event = RMAP_EVENT_SET_DELETED;
1561
1562 rv = generic_set_add(rhc->rhc_rmi, rhc->rhc_rule, type,
1563 args->errmsg, args->errmsg_len);
1564
1565 if (rv != CMD_SUCCESS) {
1566 rhc->rhc_shook = NULL;
1567 return NB_ERR_INCONSISTENCY;
1568 }
1569 }
1570
1571 return NB_OK;
1572 }
1573
1574 int lib_route_map_entry_set_action_rmap_set_action_ipv4_nexthop_destroy(
1575 struct nb_cb_destroy_args *args)
1576 {
1577 switch (args->event) {
1578 case NB_EV_VALIDATE:
1579 case NB_EV_PREPARE:
1580 case NB_EV_ABORT:
1581 break;
1582 case NB_EV_APPLY:
1583 return lib_route_map_entry_set_destroy(args);
1584 }
1585
1586 return NB_OK;
1587 }
1588
1589 /*
1590 * XPath:
1591 * /frr-route-map:lib/route-map/entry/set-action/rmap-set-action/frr-bgp-route-map:ipv6-address
1592 */
1593 int lib_route_map_entry_set_action_rmap_set_action_ipv6_address_modify(
1594 struct nb_cb_modify_args *args)
1595 {
1596 struct routemap_hook_context *rhc;
1597 const char *addr;
1598 int rv = CMD_SUCCESS;
1599 const char *action = NULL;
1600 struct in6_addr i6a;
1601
1602 action = yang_dnode_get_string(args->dnode,
1603 "../../frr-route-map:action");
1604 switch (args->event) {
1605 case NB_EV_VALIDATE:
1606 if (action && IS_SET_IPV6_NH_GLOBAL(action)) {
1607 yang_dnode_get_ipv6(&i6a, args->dnode, NULL);
1608 if (IN6_IS_ADDR_UNSPECIFIED(&i6a)
1609 || IN6_IS_ADDR_LOOPBACK(&i6a)
1610 || IN6_IS_ADDR_MULTICAST(&i6a)
1611 || IN6_IS_ADDR_LINKLOCAL(&i6a))
1612 return NB_ERR_VALIDATION;
1613 }
1614 /* FALLTHROUGH */
1615 case NB_EV_PREPARE:
1616 case NB_EV_ABORT:
1617 return NB_OK;
1618 case NB_EV_APPLY:
1619 break;
1620 }
1621
1622 /* Add configuration. */
1623 rhc = nb_running_get_entry(args->dnode, NULL, true);
1624 addr = yang_dnode_get_string(args->dnode, NULL);
1625
1626 rhc->rhc_shook = generic_set_delete;
1627 rhc->rhc_event = RMAP_EVENT_SET_DELETED;
1628
1629 if (IS_SET_IPV6_NH_GLOBAL(action))
1630 /* Set destroy information. */
1631 rhc->rhc_rule = "ipv6 next-hop global";
1632 else
1633 rhc->rhc_rule = "ipv6 vpn next-hop";
1634
1635 rv = generic_set_add(rhc->rhc_rmi, rhc->rhc_rule, addr,
1636 args->errmsg, args->errmsg_len);
1637
1638 if (rv != CMD_SUCCESS) {
1639 rhc->rhc_shook = NULL;
1640 return NB_ERR_INCONSISTENCY;
1641 }
1642
1643 return NB_OK;
1644 }
1645
1646 int lib_route_map_entry_set_action_rmap_set_action_ipv6_address_destroy(
1647 struct nb_cb_destroy_args *args)
1648 {
1649 switch (args->event) {
1650 case NB_EV_VALIDATE:
1651 case NB_EV_PREPARE:
1652 case NB_EV_ABORT:
1653 break;
1654 case NB_EV_APPLY:
1655 return lib_route_map_entry_set_destroy(args);
1656 }
1657
1658 return NB_OK;
1659 }
1660
1661 /*
1662 * XPath:
1663 * /frr-route-map:lib/route-map/entry/set-action/rmap-set-action/frr-bgp-route-map:preference
1664 */
1665 int lib_route_map_entry_set_action_rmap_set_action_preference_modify(
1666 struct nb_cb_modify_args *args)
1667 {
1668 struct routemap_hook_context *rhc;
1669 int rv = CMD_SUCCESS;
1670 const char *action = NULL;
1671 bool value;
1672
1673 switch (args->event) {
1674 case NB_EV_VALIDATE:
1675 case NB_EV_PREPARE:
1676 case NB_EV_ABORT:
1677 break;
1678 case NB_EV_APPLY:
1679 /* Add configuration. */
1680 rhc = nb_running_get_entry(args->dnode, NULL, true);
1681 value = yang_dnode_get_bool(args->dnode, NULL);
1682
1683 rhc->rhc_shook = generic_set_delete;
1684 rhc->rhc_event = RMAP_EVENT_SET_DELETED;
1685
1686 action = yang_dnode_get_string(args->dnode,
1687 "../../frr-route-map:action");
1688
1689 if (value) {
1690 if (IS_SET_IPV6_PEER_ADDR(action))
1691 /* Set destroy information. */
1692 rhc->rhc_rule = "ipv6 next-hop peer-address";
1693 else
1694 rhc->rhc_rule = "ipv6 next-hop prefer-global";
1695
1696 rv = generic_set_add(rhc->rhc_rmi, rhc->rhc_rule,
1697 NULL,
1698 args->errmsg, args->errmsg_len);
1699 }
1700
1701 if (rv != CMD_SUCCESS) {
1702 rhc->rhc_shook = NULL;
1703 return NB_ERR_INCONSISTENCY;
1704 }
1705 }
1706
1707 return NB_OK;
1708 }
1709
1710 int lib_route_map_entry_set_action_rmap_set_action_preference_destroy(
1711 struct nb_cb_destroy_args *args)
1712 {
1713 switch (args->event) {
1714 case NB_EV_VALIDATE:
1715 case NB_EV_PREPARE:
1716 case NB_EV_ABORT:
1717 break;
1718 case NB_EV_APPLY:
1719 return lib_route_map_entry_set_destroy(args);
1720 }
1721
1722 return NB_OK;
1723 }
1724
1725 /*
1726 * XPath:
1727 * /frr-route-map:lib/route-map/entry/set-action/rmap-set-action/frr-bgp-route-map:label-index
1728 */
1729 int lib_route_map_entry_set_action_rmap_set_action_label_index_modify(
1730 struct nb_cb_modify_args *args)
1731 {
1732 struct routemap_hook_context *rhc;
1733 const char *type;
1734 int rv;
1735
1736 switch (args->event) {
1737 case NB_EV_VALIDATE:
1738 case NB_EV_PREPARE:
1739 case NB_EV_ABORT:
1740 break;
1741 case NB_EV_APPLY:
1742 /* Add configuration. */
1743 rhc = nb_running_get_entry(args->dnode, NULL, true);
1744 type = yang_dnode_get_string(args->dnode, NULL);
1745
1746 /* Set destroy information. */
1747 rhc->rhc_shook = generic_set_delete;
1748 rhc->rhc_rule = "label-index";
1749 rhc->rhc_event = RMAP_EVENT_SET_DELETED;
1750
1751 rv = generic_set_add(rhc->rhc_rmi, "label-index", type,
1752 args->errmsg, args->errmsg_len);
1753 if (rv != CMD_SUCCESS) {
1754 rhc->rhc_shook = NULL;
1755 return NB_ERR_INCONSISTENCY;
1756 }
1757 }
1758
1759 return NB_OK;
1760 }
1761
1762 int lib_route_map_entry_set_action_rmap_set_action_label_index_destroy(
1763 struct nb_cb_destroy_args *args)
1764 {
1765 switch (args->event) {
1766 case NB_EV_VALIDATE:
1767 case NB_EV_PREPARE:
1768 case NB_EV_ABORT:
1769 break;
1770 case NB_EV_APPLY:
1771 return lib_route_map_entry_set_destroy(args);
1772 }
1773
1774 return NB_OK;
1775 }
1776
1777 /*
1778 * XPath:
1779 * /frr-route-map:lib/route-map/entry/set-action/rmap-set-action/frr-bgp-route-map:local-pref
1780 */
1781 int lib_route_map_entry_set_action_rmap_set_action_local_pref_modify(
1782 struct nb_cb_modify_args *args)
1783 {
1784 struct routemap_hook_context *rhc;
1785 const char *type;
1786 int rv;
1787
1788 switch (args->event) {
1789 case NB_EV_VALIDATE:
1790 case NB_EV_PREPARE:
1791 case NB_EV_ABORT:
1792 break;
1793 case NB_EV_APPLY:
1794 /* Add configuration. */
1795 rhc = nb_running_get_entry(args->dnode, NULL, true);
1796 type = yang_dnode_get_string(args->dnode, NULL);
1797
1798 /* Set destroy information. */
1799 rhc->rhc_shook = generic_set_delete;
1800 rhc->rhc_rule = "local-preference";
1801 rhc->rhc_event = RMAP_EVENT_SET_DELETED;
1802
1803 rv = generic_set_add(rhc->rhc_rmi, "local-preference",
1804 type,
1805 args->errmsg, args->errmsg_len);
1806 if (rv != CMD_SUCCESS) {
1807 rhc->rhc_shook = NULL;
1808 return NB_ERR_INCONSISTENCY;
1809 }
1810 }
1811
1812 return NB_OK;
1813 }
1814
1815 int lib_route_map_entry_set_action_rmap_set_action_local_pref_destroy(
1816 struct nb_cb_destroy_args *args)
1817 {
1818 switch (args->event) {
1819 case NB_EV_VALIDATE:
1820 case NB_EV_PREPARE:
1821 case NB_EV_ABORT:
1822 break;
1823 case NB_EV_APPLY:
1824 return lib_route_map_entry_set_destroy(args);
1825 }
1826
1827 return NB_OK;
1828 }
1829
1830 /*
1831 * XPath:
1832 * /frr-route-map:lib/route-map/entry/set-action/rmap-set-action/frr-bgp-route-map:weight
1833 */
1834 int lib_route_map_entry_set_action_rmap_set_action_weight_modify(
1835 struct nb_cb_modify_args *args)
1836 {
1837 struct routemap_hook_context *rhc;
1838 const char *type;
1839 int rv;
1840
1841 switch (args->event) {
1842 case NB_EV_VALIDATE:
1843 case NB_EV_PREPARE:
1844 case NB_EV_ABORT:
1845 break;
1846 case NB_EV_APPLY:
1847 /* Add configuration. */
1848 rhc = nb_running_get_entry(args->dnode, NULL, true);
1849 type = yang_dnode_get_string(args->dnode, NULL);
1850
1851 /* Set destroy information. */
1852 rhc->rhc_shook = generic_set_delete;
1853 rhc->rhc_rule = "weight";
1854 rhc->rhc_event = RMAP_EVENT_SET_DELETED;
1855
1856 rv = generic_set_add(rhc->rhc_rmi, "weight", type,
1857 args->errmsg, args->errmsg_len);
1858 if (rv != CMD_SUCCESS) {
1859 rhc->rhc_shook = NULL;
1860 return NB_ERR_INCONSISTENCY;
1861 }
1862 }
1863
1864 return NB_OK;
1865 }
1866
1867 int lib_route_map_entry_set_action_rmap_set_action_weight_destroy(
1868 struct nb_cb_destroy_args *args)
1869 {
1870 switch (args->event) {
1871 case NB_EV_VALIDATE:
1872 case NB_EV_PREPARE:
1873 case NB_EV_ABORT:
1874 break;
1875 case NB_EV_APPLY:
1876 return lib_route_map_entry_set_destroy(args);
1877 }
1878
1879 return NB_OK;
1880 }
1881
1882 /*
1883 * XPath:
1884 * /frr-route-map:lib/route-map/entry/set-action/rmap-set-action/frr-bgp-route-map:origin
1885 */
1886 int lib_route_map_entry_set_action_rmap_set_action_origin_modify(
1887 struct nb_cb_modify_args *args)
1888 {
1889 struct routemap_hook_context *rhc;
1890 const char *type;
1891 int rv;
1892
1893 switch (args->event) {
1894 case NB_EV_VALIDATE:
1895 case NB_EV_PREPARE:
1896 case NB_EV_ABORT:
1897 break;
1898 case NB_EV_APPLY:
1899 /* Add configuration. */
1900 rhc = nb_running_get_entry(args->dnode, NULL, true);
1901 type = yang_dnode_get_string(args->dnode, NULL);
1902
1903 /* Set destroy information. */
1904 rhc->rhc_shook = generic_set_delete;
1905 rhc->rhc_rule = "origin";
1906 rhc->rhc_event = RMAP_EVENT_SET_DELETED;
1907
1908 rv = generic_set_add(rhc->rhc_rmi, "origin", type,
1909 args->errmsg, args->errmsg_len);
1910 if (rv != CMD_SUCCESS) {
1911 rhc->rhc_shook = NULL;
1912 return NB_ERR_INCONSISTENCY;
1913 }
1914 }
1915
1916 return NB_OK;
1917 }
1918
1919 int lib_route_map_entry_set_action_rmap_set_action_origin_destroy(
1920 struct nb_cb_destroy_args *args)
1921 {
1922 switch (args->event) {
1923 case NB_EV_VALIDATE:
1924 case NB_EV_PREPARE:
1925 case NB_EV_ABORT:
1926 break;
1927 case NB_EV_APPLY:
1928 return lib_route_map_entry_set_destroy(args);
1929
1930 }
1931
1932 return NB_OK;
1933 }
1934
1935 /*
1936 * XPath:
1937 * /frr-route-map:lib/route-map/entry/set-action/rmap-set-action/frr-bgp-route-map:originator-id
1938 */
1939 int lib_route_map_entry_set_action_rmap_set_action_originator_id_modify(
1940 struct nb_cb_modify_args *args)
1941 {
1942 struct routemap_hook_context *rhc;
1943 const char *type;
1944 int rv;
1945
1946 switch (args->event) {
1947 case NB_EV_VALIDATE:
1948 case NB_EV_PREPARE:
1949 case NB_EV_ABORT:
1950 break;
1951 case NB_EV_APPLY:
1952 /* Add configuration. */
1953 rhc = nb_running_get_entry(args->dnode, NULL, true);
1954 type = yang_dnode_get_string(args->dnode, NULL);
1955
1956 /* Set destroy information. */
1957 rhc->rhc_shook = generic_set_delete;
1958 rhc->rhc_rule = "originator-id";
1959 rhc->rhc_event = RMAP_EVENT_SET_DELETED;
1960
1961 rv = generic_set_add(rhc->rhc_rmi, "originator-id", type,
1962 args->errmsg, args->errmsg_len);
1963 if (rv != CMD_SUCCESS) {
1964 rhc->rhc_shook = NULL;
1965 return NB_ERR_INCONSISTENCY;
1966 }
1967 }
1968
1969 return NB_OK;
1970 }
1971
1972 int lib_route_map_entry_set_action_rmap_set_action_originator_id_destroy(
1973 struct nb_cb_destroy_args *args)
1974 {
1975 switch (args->event) {
1976 case NB_EV_VALIDATE:
1977 case NB_EV_PREPARE:
1978 case NB_EV_ABORT:
1979 break;
1980 case NB_EV_APPLY:
1981 return lib_route_map_entry_set_destroy(args);
1982 }
1983
1984 return NB_OK;
1985 }
1986
1987 /*
1988 * XPath:
1989 * /frr-route-map:lib/route-map/entry/set-action/rmap-set-action/frr-bgp-route-map:table
1990 */
1991 int lib_route_map_entry_set_action_rmap_set_action_table_modify(
1992 struct nb_cb_modify_args *args)
1993 {
1994 struct routemap_hook_context *rhc;
1995 const char *type;
1996 int rv;
1997
1998 switch (args->event) {
1999 case NB_EV_VALIDATE:
2000 case NB_EV_PREPARE:
2001 case NB_EV_ABORT:
2002 break;
2003 case NB_EV_APPLY:
2004 /* Add configuration. */
2005 rhc = nb_running_get_entry(args->dnode, NULL, true);
2006 type = yang_dnode_get_string(args->dnode, NULL);
2007
2008 /* Set destroy information. */
2009 rhc->rhc_shook = generic_set_delete;
2010 rhc->rhc_rule = "table";
2011 rhc->rhc_event = RMAP_EVENT_SET_DELETED;
2012
2013 rv = generic_set_add(rhc->rhc_rmi, "table", type,
2014 args->errmsg, args->errmsg_len);
2015 if (rv != CMD_SUCCESS) {
2016 rhc->rhc_shook = NULL;
2017 return NB_ERR_INCONSISTENCY;
2018 }
2019 }
2020
2021 return NB_OK;
2022 }
2023
2024 int lib_route_map_entry_set_action_rmap_set_action_table_destroy(
2025 struct nb_cb_destroy_args *args)
2026 {
2027 switch (args->event) {
2028 case NB_EV_VALIDATE:
2029 case NB_EV_PREPARE:
2030 case NB_EV_ABORT:
2031 break;
2032 case NB_EV_APPLY:
2033 return lib_route_map_entry_set_destroy(args);
2034 }
2035
2036 return NB_OK;
2037 }
2038
2039 /*
2040 * XPath:
2041 * /frr-route-map:lib/route-map/entry/set-action/rmap-set-action/frr-bgp-route-map:atomic-aggregate
2042 */
2043 int
2044 lib_route_map_entry_set_action_rmap_set_action_atomic_aggregate_create(
2045 struct nb_cb_create_args *args)
2046 {
2047 struct routemap_hook_context *rhc;
2048 int rv;
2049
2050 switch (args->event) {
2051 case NB_EV_VALIDATE:
2052 case NB_EV_PREPARE:
2053 case NB_EV_ABORT:
2054 break;
2055 case NB_EV_APPLY:
2056 /* Add configuration. */
2057 rhc = nb_running_get_entry(args->dnode, NULL, true);
2058
2059 /* Set destroy information. */
2060 rhc->rhc_shook = generic_set_delete;
2061 rhc->rhc_rule = "atomic-aggregate";
2062 rhc->rhc_event = RMAP_EVENT_SET_DELETED;
2063
2064 rv = generic_set_add(rhc->rhc_rmi, rhc->rhc_rule, NULL,
2065 args->errmsg, args->errmsg_len);
2066 if (rv != CMD_SUCCESS) {
2067 rhc->rhc_shook = NULL;
2068 return NB_ERR_INCONSISTENCY;
2069 }
2070 }
2071
2072 return NB_OK;
2073 }
2074
2075 int
2076 lib_route_map_entry_set_action_rmap_set_action_atomic_aggregate_destroy(
2077 struct nb_cb_destroy_args *args)
2078 {
2079 switch (args->event) {
2080 case NB_EV_VALIDATE:
2081 case NB_EV_PREPARE:
2082 case NB_EV_ABORT:
2083 break;
2084 case NB_EV_APPLY:
2085 return lib_route_map_entry_set_destroy(args);
2086 }
2087
2088 return NB_OK;
2089 }
2090
2091 /*
2092 * XPath:
2093 * /frr-route-map:lib/route-map/entry/set-action/rmap-set-action/frr-bgp-route-map:aigp-metric
2094 */
2095 int lib_route_map_entry_set_action_rmap_set_action_aigp_metric_modify(
2096 struct nb_cb_modify_args *args)
2097 {
2098 struct routemap_hook_context *rhc;
2099 const char *aigp;
2100 int rv;
2101
2102 switch (args->event) {
2103 case NB_EV_VALIDATE:
2104 case NB_EV_PREPARE:
2105 case NB_EV_ABORT:
2106 break;
2107 case NB_EV_APPLY:
2108 /* Add configuration. */
2109 rhc = nb_running_get_entry(args->dnode, NULL, true);
2110 aigp = yang_dnode_get_string(args->dnode, NULL);
2111
2112 /* Set destroy information. */
2113 rhc->rhc_shook = generic_set_delete;
2114 rhc->rhc_rule = "aigp-metric";
2115 rhc->rhc_event = RMAP_EVENT_SET_DELETED;
2116
2117 rv = generic_set_add(rhc->rhc_rmi, rhc->rhc_rule, aigp,
2118 args->errmsg, args->errmsg_len);
2119 if (rv != CMD_SUCCESS) {
2120 rhc->rhc_shook = NULL;
2121 return NB_ERR_INCONSISTENCY;
2122 }
2123 }
2124
2125 return NB_OK;
2126 }
2127
2128 int lib_route_map_entry_set_action_rmap_set_action_aigp_metric_destroy(
2129 struct nb_cb_destroy_args *args)
2130 {
2131 switch (args->event) {
2132 case NB_EV_VALIDATE:
2133 case NB_EV_PREPARE:
2134 case NB_EV_ABORT:
2135 break;
2136 case NB_EV_APPLY:
2137 return lib_route_map_entry_set_destroy(args);
2138 }
2139
2140 return NB_OK;
2141 }
2142
2143 /*
2144 * XPath:
2145 * /frr-route-map:lib/route-map/entry/set-action/rmap-set-action/frr-bgp-route-map:prepend-as-path
2146 */
2147 int
2148 lib_route_map_entry_set_action_rmap_set_action_prepend_as_path_modify(
2149 struct nb_cb_modify_args *args)
2150 {
2151 struct routemap_hook_context *rhc;
2152 const char *type;
2153 int rv;
2154
2155 switch (args->event) {
2156 case NB_EV_VALIDATE:
2157 case NB_EV_PREPARE:
2158 case NB_EV_ABORT:
2159 break;
2160 case NB_EV_APPLY:
2161 /* Add configuration. */
2162 rhc = nb_running_get_entry(args->dnode, NULL, true);
2163 type = yang_dnode_get_string(args->dnode, NULL);
2164
2165 /* Set destroy information. */
2166 rhc->rhc_shook = generic_set_delete;
2167 rhc->rhc_rule = "as-path prepend";
2168 rhc->rhc_event = RMAP_EVENT_SET_DELETED;
2169
2170 rv = generic_set_add(rhc->rhc_rmi, "as-path prepend",
2171 type,
2172 args->errmsg, args->errmsg_len);
2173 if (rv != CMD_SUCCESS) {
2174 rhc->rhc_shook = NULL;
2175 return NB_ERR_INCONSISTENCY;
2176 }
2177 }
2178
2179 return NB_OK;
2180 }
2181
2182 int
2183 lib_route_map_entry_set_action_rmap_set_action_prepend_as_path_destroy(
2184 struct nb_cb_destroy_args *args)
2185 {
2186 switch (args->event) {
2187 case NB_EV_VALIDATE:
2188 case NB_EV_PREPARE:
2189 case NB_EV_ABORT:
2190 break;
2191 case NB_EV_APPLY:
2192 return lib_route_map_entry_set_destroy(args);
2193 }
2194
2195 return NB_OK;
2196 }
2197
2198 /*
2199 * XPath:
2200 * /frr-route-map:lib/route-map/entry/set-action/rmap-set-action/frr-bgp-route-map:last-as
2201 */
2202 int lib_route_map_entry_set_action_rmap_set_action_last_as_modify(
2203 struct nb_cb_modify_args *args)
2204 {
2205 struct routemap_hook_context *rhc;
2206 const char *value;
2207 char *argstr;
2208 int rv;
2209
2210 switch (args->event) {
2211 case NB_EV_VALIDATE:
2212 case NB_EV_PREPARE:
2213 case NB_EV_ABORT:
2214 break;
2215 case NB_EV_APPLY:
2216 /* Add configuration. */
2217 rhc = nb_running_get_entry(args->dnode, NULL, true);
2218 value = yang_dnode_get_string(args->dnode, NULL);
2219
2220 /* Set destroy information. */
2221 rhc->rhc_shook = generic_set_delete;
2222 rhc->rhc_rule = "as-path prepend";
2223 rhc->rhc_event = RMAP_EVENT_SET_DELETED;
2224
2225 argstr = XMALLOC(MTYPE_ROUTE_MAP_COMPILED,
2226 strlen(value) + strlen("last-as") + 2);
2227
2228 snprintf(argstr, (strlen(value) + strlen("last-as") + 2),
2229 "last-as %s", value);
2230
2231 rv = generic_set_add(rhc->rhc_rmi, "as-path prepend",
2232 argstr,
2233 args->errmsg, args->errmsg_len);
2234 if (rv != CMD_SUCCESS) {
2235 rhc->rhc_shook = NULL;
2236 XFREE(MTYPE_ROUTE_MAP_COMPILED, argstr);
2237 return NB_ERR_INCONSISTENCY;
2238 }
2239
2240 XFREE(MTYPE_ROUTE_MAP_COMPILED, argstr);
2241 }
2242
2243 return NB_OK;
2244 }
2245
2246 int lib_route_map_entry_set_action_rmap_set_action_last_as_destroy(
2247 struct nb_cb_destroy_args *args)
2248 {
2249 switch (args->event) {
2250 case NB_EV_VALIDATE:
2251 case NB_EV_PREPARE:
2252 case NB_EV_ABORT:
2253 break;
2254 case NB_EV_APPLY:
2255 return lib_route_map_entry_set_destroy(args);
2256 }
2257
2258 return NB_OK;
2259 }
2260
2261 /*
2262 * XPath:
2263 * /frr-route-map:lib/route-map/entry/set-action/rmap-set-action/frr-bgp-route-map:exclude-as-path
2264 */
2265 int
2266 lib_route_map_entry_set_action_rmap_set_action_exclude_as_path_modify(
2267 struct nb_cb_modify_args *args)
2268 {
2269 struct routemap_hook_context *rhc;
2270 const char *type;
2271 int rv;
2272
2273 switch (args->event) {
2274 case NB_EV_VALIDATE:
2275 case NB_EV_PREPARE:
2276 case NB_EV_ABORT:
2277 break;
2278 case NB_EV_APPLY:
2279 /* Add configuration. */
2280 rhc = nb_running_get_entry(args->dnode, NULL, true);
2281 type = yang_dnode_get_string(args->dnode, NULL);
2282
2283 /* Set destroy information. */
2284 rhc->rhc_shook = generic_set_delete;
2285 rhc->rhc_rule = "as-path exclude";
2286 rhc->rhc_event = RMAP_EVENT_SET_DELETED;
2287
2288 rv = generic_set_add(rhc->rhc_rmi, "as-path exclude",
2289 type,
2290 args->errmsg, args->errmsg_len);
2291 if (rv != CMD_SUCCESS) {
2292 rhc->rhc_shook = NULL;
2293 return NB_ERR_INCONSISTENCY;
2294 }
2295 }
2296
2297 return NB_OK;
2298 }
2299
2300 int
2301 lib_route_map_entry_set_action_rmap_set_action_exclude_as_path_destroy(
2302 struct nb_cb_destroy_args *args)
2303 {
2304 switch (args->event) {
2305 case NB_EV_VALIDATE:
2306 case NB_EV_PREPARE:
2307 case NB_EV_ABORT:
2308 break;
2309 case NB_EV_APPLY:
2310 return lib_route_map_entry_set_destroy(args);
2311 }
2312
2313 return NB_OK;
2314 }
2315
2316 /*
2317 * XPath:
2318 * /frr-route-map:lib/route-map/entry/set-action/rmap-set-action/frr-bgp-route-map:replace-as-path
2319 */
2320 int lib_route_map_entry_set_action_rmap_set_action_replace_as_path_modify(
2321 struct nb_cb_modify_args *args)
2322 {
2323 struct routemap_hook_context *rhc;
2324 const char *type;
2325 int rv;
2326
2327 switch (args->event) {
2328 case NB_EV_VALIDATE:
2329 case NB_EV_PREPARE:
2330 case NB_EV_ABORT:
2331 break;
2332 case NB_EV_APPLY:
2333 /* Add configuration. */
2334 rhc = nb_running_get_entry(args->dnode, NULL, true);
2335 type = yang_dnode_get_string(args->dnode, NULL);
2336
2337 /* Set destroy information. */
2338 rhc->rhc_shook = generic_set_delete;
2339 rhc->rhc_rule = "as-path replace";
2340 rhc->rhc_event = RMAP_EVENT_SET_DELETED;
2341
2342 rv = generic_set_add(rhc->rhc_rmi, "as-path replace", type,
2343 args->errmsg, args->errmsg_len);
2344 if (rv != CMD_SUCCESS) {
2345 rhc->rhc_shook = NULL;
2346 return NB_ERR_INCONSISTENCY;
2347 }
2348 }
2349
2350 return NB_OK;
2351 }
2352
2353 int lib_route_map_entry_set_action_rmap_set_action_replace_as_path_destroy(
2354 struct nb_cb_destroy_args *args)
2355 {
2356 switch (args->event) {
2357 case NB_EV_VALIDATE:
2358 case NB_EV_PREPARE:
2359 case NB_EV_ABORT:
2360 break;
2361 case NB_EV_APPLY:
2362 return lib_route_map_entry_set_destroy(args);
2363 }
2364
2365 return NB_OK;
2366 }
2367
2368 /*
2369 * XPath:
2370 * /frr-route-map:lib/route-map/entry/set-action/rmap-set-action/frr-bgp-route-map:community-none
2371 */
2372 int lib_route_map_entry_set_action_rmap_set_action_community_none_modify(
2373 struct nb_cb_modify_args *args)
2374 {
2375 struct routemap_hook_context *rhc;
2376 bool none = false;
2377 int rv;
2378
2379 switch (args->event) {
2380 case NB_EV_VALIDATE:
2381 case NB_EV_PREPARE:
2382 case NB_EV_ABORT:
2383 break;
2384 case NB_EV_APPLY:
2385 /* Add configuration. */
2386 rhc = nb_running_get_entry(args->dnode, NULL, true);
2387 none = yang_dnode_get_bool(args->dnode, NULL);
2388
2389 /* Set destroy information. */
2390 rhc->rhc_shook = generic_set_delete;
2391 rhc->rhc_rule = "community";
2392 rhc->rhc_event = RMAP_EVENT_SET_DELETED;
2393
2394 if (none) {
2395 rv = generic_set_add(rhc->rhc_rmi, "community",
2396 "none",
2397 args->errmsg, args->errmsg_len);
2398 if (rv != CMD_SUCCESS) {
2399 rhc->rhc_shook = NULL;
2400 return NB_ERR_INCONSISTENCY;
2401 }
2402 return NB_OK;
2403 }
2404
2405 return NB_ERR_INCONSISTENCY;
2406 }
2407
2408 return NB_OK;
2409 }
2410
2411 int
2412 lib_route_map_entry_set_action_rmap_set_action_community_none_destroy(
2413 struct nb_cb_destroy_args *args)
2414 {
2415 switch (args->event) {
2416 case NB_EV_VALIDATE:
2417 case NB_EV_PREPARE:
2418 case NB_EV_ABORT:
2419 break;
2420 case NB_EV_APPLY:
2421 return lib_route_map_entry_set_destroy(args);
2422 }
2423
2424 return NB_OK;
2425 }
2426
2427 /*
2428 * XPath:
2429 * /frr-route-map:lib/route-map/entry/set-action/rmap-set-action/frr-bgp-route-map:community-string
2430 */
2431 int
2432 lib_route_map_entry_set_action_rmap_set_action_community_string_modify(
2433 struct nb_cb_modify_args *args)
2434 {
2435 struct routemap_hook_context *rhc;
2436 const char *type;
2437 int rv;
2438
2439 switch (args->event) {
2440 case NB_EV_VALIDATE:
2441 case NB_EV_PREPARE:
2442 case NB_EV_ABORT:
2443 break;
2444 case NB_EV_APPLY:
2445 /* Add configuration. */
2446 rhc = nb_running_get_entry(args->dnode, NULL, true);
2447 type = yang_dnode_get_string(args->dnode, NULL);
2448
2449 /* Set destroy information. */
2450 rhc->rhc_shook = generic_set_delete;
2451 rhc->rhc_rule = "community";
2452 rhc->rhc_event = RMAP_EVENT_SET_DELETED;
2453
2454 rv = generic_set_add(rhc->rhc_rmi, "community", type,
2455 args->errmsg, args->errmsg_len);
2456 if (rv != CMD_SUCCESS) {
2457 rhc->rhc_shook = NULL;
2458 return NB_ERR_INCONSISTENCY;
2459 }
2460 }
2461
2462 return NB_OK;
2463 }
2464
2465 int
2466 lib_route_map_entry_set_action_rmap_set_action_community_string_destroy(
2467 struct nb_cb_destroy_args *args)
2468 {
2469 switch (args->event) {
2470 case NB_EV_VALIDATE:
2471 case NB_EV_PREPARE:
2472 case NB_EV_ABORT:
2473 break;
2474 case NB_EV_APPLY:
2475 return lib_route_map_entry_set_destroy(args);
2476 }
2477
2478 return NB_OK;
2479 }
2480
2481 /*
2482 * XPath:
2483 * /frr-route-map:lib/route-map/entry/set-action/rmap-set-action/frr-bgp-route-map:large-community-none
2484 */
2485 int
2486 lib_route_map_entry_set_action_rmap_set_action_large_community_none_modify(
2487 struct nb_cb_modify_args *args)
2488 {
2489 struct routemap_hook_context *rhc;
2490 bool none = false;
2491 int rv;
2492
2493 switch (args->event) {
2494 case NB_EV_VALIDATE:
2495 case NB_EV_PREPARE:
2496 case NB_EV_ABORT:
2497 break;
2498 case NB_EV_APPLY:
2499 /* Add configuration. */
2500 rhc = nb_running_get_entry(args->dnode, NULL, true);
2501 none = yang_dnode_get_bool(args->dnode, NULL);
2502
2503 /* Set destroy information. */
2504 rhc->rhc_shook = generic_set_delete;
2505 rhc->rhc_rule = "large-community";
2506 rhc->rhc_event = RMAP_EVENT_SET_DELETED;
2507
2508 if (none) {
2509 rv = generic_set_add(rhc->rhc_rmi,
2510 "large-community",
2511 "none",
2512 args->errmsg, args->errmsg_len);
2513 if (rv != CMD_SUCCESS) {
2514 rhc->rhc_shook = NULL;
2515 return NB_ERR_INCONSISTENCY;
2516 }
2517 return NB_OK;
2518 }
2519
2520 return NB_ERR_INCONSISTENCY;
2521 }
2522
2523 return NB_OK;
2524 }
2525
2526 int
2527 lib_route_map_entry_set_action_rmap_set_action_large_community_none_destroy(
2528 struct nb_cb_destroy_args *args)
2529 {
2530 switch (args->event) {
2531 case NB_EV_VALIDATE:
2532 case NB_EV_PREPARE:
2533 case NB_EV_ABORT:
2534 break;
2535 case NB_EV_APPLY:
2536 return lib_route_map_entry_set_destroy(args);
2537 }
2538
2539 return NB_OK;
2540 }
2541
2542 /*
2543 * XPath:
2544 * /frr-route-map:lib/route-map/entry/set-action/rmap-set-action/frr-bgp-route-map:large-community-string
2545 */
2546 int
2547 lib_route_map_entry_set_action_rmap_set_action_large_community_string_modify(
2548 struct nb_cb_modify_args *args)
2549 {
2550 struct routemap_hook_context *rhc;
2551 const char *type;
2552 int rv;
2553
2554 switch (args->event) {
2555 case NB_EV_VALIDATE:
2556 case NB_EV_PREPARE:
2557 case NB_EV_ABORT:
2558 break;
2559 case NB_EV_APPLY:
2560 /* Add configuration. */
2561 rhc = nb_running_get_entry(args->dnode, NULL, true);
2562 type = yang_dnode_get_string(args->dnode, NULL);
2563
2564 /* Set destroy information. */
2565 rhc->rhc_shook = generic_set_delete;
2566 rhc->rhc_rule = "large-community";
2567 rhc->rhc_event = RMAP_EVENT_SET_DELETED;
2568
2569 rv = generic_set_add(rhc->rhc_rmi, "large-community",
2570 type,
2571 args->errmsg, args->errmsg_len);
2572 if (rv != CMD_SUCCESS) {
2573 rhc->rhc_shook = NULL;
2574 return NB_ERR_INCONSISTENCY;
2575 }
2576 }
2577
2578 return NB_OK;
2579 }
2580
2581 int
2582 lib_route_map_entry_set_action_rmap_set_action_large_community_string_destroy(
2583 struct nb_cb_destroy_args *args)
2584 {
2585 switch (args->event) {
2586 case NB_EV_VALIDATE:
2587 case NB_EV_PREPARE:
2588 case NB_EV_ABORT:
2589 break;
2590 case NB_EV_APPLY:
2591 return lib_route_map_entry_set_destroy(args);
2592 }
2593
2594 return NB_OK;
2595 }
2596
2597 /*
2598 * xpath =
2599 * /frr-route-map:lib/route-map/entry/set-action/rmap-set-action/frr-bgp-route-map:aggregator
2600 */
2601 void lib_route_map_entry_set_action_rmap_set_action_aggregator_finish(
2602 struct nb_cb_apply_finish_args *args)
2603 {
2604 struct routemap_hook_context *rhc;
2605 const char *asn;
2606 const char *addr;
2607 char *argstr;
2608 int ret;
2609
2610 /* Add configuration. */
2611 rhc = nb_running_get_entry(args->dnode, NULL, true);
2612 asn = yang_dnode_get_string(args->dnode, "./aggregator-asn");
2613 addr = yang_dnode_get_string(args->dnode, "./aggregator-address");
2614
2615 argstr = XMALLOC(MTYPE_ROUTE_MAP_COMPILED,
2616 strlen(asn) + strlen(addr) + 2);
2617
2618 snprintf(argstr, (strlen(asn) + strlen(addr) + 2), "%s %s", asn, addr);
2619
2620 /* Set destroy information. */
2621 rhc->rhc_shook = generic_set_delete;
2622 rhc->rhc_rule = "aggregator as";
2623 rhc->rhc_event = RMAP_EVENT_SET_DELETED;
2624
2625 ret = generic_set_add(rhc->rhc_rmi, rhc->rhc_rule, argstr, args->errmsg,
2626 args->errmsg_len);
2627 /*
2628 * At this point if this is not a successful operation
2629 * bgpd is about to crash. Let's just cut to the
2630 * chase and do it.
2631 */
2632 assert(ret == CMD_SUCCESS);
2633
2634 XFREE(MTYPE_ROUTE_MAP_COMPILED, argstr);
2635 }
2636 /*
2637 * XPath:
2638 * /frr-route-map:lib/route-map/entry/set-action/rmap-set-action/frr-bgp-route-map:aggregator/aggregator-asn
2639 */
2640 int
2641 lib_route_map_entry_set_action_rmap_set_action_aggregator_aggregator_asn_modify(
2642 struct nb_cb_modify_args *args)
2643 {
2644 switch (args->event) {
2645 case NB_EV_VALIDATE:
2646 case NB_EV_PREPARE:
2647 case NB_EV_ABORT:
2648 case NB_EV_APPLY:
2649 break;
2650 }
2651
2652 return NB_OK;
2653 }
2654
2655 int
2656 lib_route_map_entry_set_action_rmap_set_action_aggregator_aggregator_asn_destroy(
2657 struct nb_cb_destroy_args *args)
2658 {
2659 switch (args->event) {
2660 case NB_EV_VALIDATE:
2661 case NB_EV_PREPARE:
2662 case NB_EV_ABORT:
2663 break;
2664 case NB_EV_APPLY:
2665 return lib_route_map_entry_set_destroy(args);
2666 }
2667
2668 return NB_OK;
2669 }
2670
2671 /*
2672 * XPath:
2673 * /frr-route-map:lib/route-map/entry/set-action/rmap-set-action/frr-bgp-route-map:aggregator/aggregator-address
2674 */
2675 int
2676 lib_route_map_entry_set_action_rmap_set_action_aggregator_aggregator_address_modify(
2677 struct nb_cb_modify_args *args)
2678 {
2679 switch (args->event) {
2680 case NB_EV_VALIDATE:
2681 case NB_EV_PREPARE:
2682 case NB_EV_ABORT:
2683 case NB_EV_APPLY:
2684 break;
2685 }
2686
2687 return NB_OK;
2688 }
2689
2690 int
2691 lib_route_map_entry_set_action_rmap_set_action_aggregator_aggregator_address_destroy(
2692 struct nb_cb_destroy_args *args)
2693 {
2694 switch (args->event) {
2695 case NB_EV_VALIDATE:
2696 case NB_EV_PREPARE:
2697 case NB_EV_ABORT:
2698 break;
2699 case NB_EV_APPLY:
2700 return lib_route_map_entry_set_destroy(args);
2701 }
2702
2703 return NB_OK;
2704 }
2705
2706 /*
2707 * XPath:
2708 * /frr-route-map:lib/route-map/entry/set-action/rmap-set-action/frr-bgp-route-map:comm-list-name
2709 */
2710 int lib_route_map_entry_set_action_rmap_set_action_comm_list_name_modify(
2711 struct nb_cb_modify_args *args)
2712 {
2713 struct routemap_hook_context *rhc;
2714 const char *value;
2715 const char *action;
2716 int rv = CMD_SUCCESS;
2717
2718 switch (args->event) {
2719 case NB_EV_VALIDATE:
2720 case NB_EV_PREPARE:
2721 case NB_EV_ABORT:
2722 break;
2723 case NB_EV_APPLY:
2724 /* Add configuration. */
2725 rhc = nb_running_get_entry(args->dnode, NULL, true);
2726 value = yang_dnode_get_string(args->dnode, NULL);
2727
2728 /* Set destroy information. */
2729 rhc->rhc_shook = generic_set_delete;
2730
2731 action = yang_dnode_get_string(args->dnode,
2732 "../../frr-route-map:action");
2733 if (IS_SET_COMM_LIST_DEL(action))
2734 rhc->rhc_rule = "comm-list";
2735 else
2736 rhc->rhc_rule = "large-comm-list";
2737
2738 rhc->rhc_event = RMAP_EVENT_SET_DELETED;
2739
2740 rv = generic_set_add(rhc->rhc_rmi, rhc->rhc_rule, value,
2741 args->errmsg, args->errmsg_len);
2742
2743 if (rv != CMD_SUCCESS) {
2744 rhc->rhc_shook = NULL;
2745 return NB_ERR_INCONSISTENCY;
2746 }
2747 }
2748
2749 return NB_OK;
2750 }
2751
2752 int
2753 lib_route_map_entry_set_action_rmap_set_action_comm_list_name_destroy(
2754 struct nb_cb_destroy_args *args)
2755 {
2756 switch (args->event) {
2757 case NB_EV_VALIDATE:
2758 case NB_EV_PREPARE:
2759 case NB_EV_ABORT:
2760 break;
2761 case NB_EV_APPLY:
2762 return lib_route_map_entry_set_destroy(args);
2763 }
2764
2765 return NB_OK;
2766 }
2767
2768 /*
2769 * XPath:
2770 * /frr-route-map:lib/route-map/entry/set-action/rmap-set-action/frr-bgp-route-map:extcommunity-lb
2771 */
2772 void
2773 lib_route_map_entry_set_action_rmap_set_action_extcommunity_lb_finish(
2774 struct nb_cb_apply_finish_args *args)
2775 {
2776 struct routemap_hook_context *rhc;
2777 enum ecommunity_lb_type lb_type;
2778 char str[VTY_BUFSIZ];
2779 uint16_t bandwidth;
2780 int ret;
2781
2782 /* Add configuration. */
2783 rhc = nb_running_get_entry(args->dnode, NULL, true);
2784 lb_type = yang_dnode_get_enum(args->dnode, "./lb-type");
2785
2786 /* Set destroy information. */
2787 rhc->rhc_shook = generic_set_delete;
2788 rhc->rhc_rule = "extcommunity bandwidth";
2789 rhc->rhc_event = RMAP_EVENT_SET_DELETED;
2790
2791 switch (lb_type) {
2792 case EXPLICIT_BANDWIDTH:
2793 bandwidth = yang_dnode_get_uint16(args->dnode, "./bandwidth");
2794 snprintf(str, sizeof(str), "%d", bandwidth);
2795 break;
2796 case CUMULATIVE_BANDWIDTH:
2797 snprintf(str, sizeof(str), "%s", "cumulative");
2798 break;
2799 case COMPUTED_BANDWIDTH:
2800 snprintf(str, sizeof(str), "%s", "num-multipaths");
2801 }
2802
2803 if (yang_dnode_get_bool(args->dnode, "./two-octet-as-specific"))
2804 strlcat(str, " non-transitive", sizeof(str));
2805
2806 ret = generic_set_add(rhc->rhc_rmi, "extcommunity bandwidth", str,
2807 args->errmsg, args->errmsg_len);
2808 /*
2809 * At this point if this is not a successful operation
2810 * bgpd is about to crash. Let's just cut to the
2811 * chase and do it.
2812 */
2813 assert(ret == CMD_SUCCESS);
2814 }
2815
2816 /*
2817 * XPath:
2818 * /frr-route-map:lib/route-map/entry/set-action/rmap-set-action/frr-bgp-route-map:extcommunity-lb/lb-type
2819 */
2820 int
2821 lib_route_map_entry_set_action_rmap_set_action_extcommunity_lb_lb_type_modify(
2822 struct nb_cb_modify_args *args)
2823 {
2824 return NB_OK;
2825 }
2826
2827 int
2828 lib_route_map_entry_set_action_rmap_set_action_extcommunity_lb_lb_type_destroy(
2829 struct nb_cb_destroy_args *args)
2830 {
2831 return lib_route_map_entry_set_destroy(args);
2832 }
2833
2834 /*
2835 * XPath:
2836 * /frr-route-map:lib/route-map/entry/set-action/rmap-set-action/frr-bgp-route-map:extcommunity-lb/bandwidth
2837 */
2838 int
2839 lib_route_map_entry_set_action_rmap_set_action_extcommunity_lb_bandwidth_modify(
2840 struct nb_cb_modify_args *args)
2841 {
2842 return NB_OK;
2843 }
2844
2845 int
2846 lib_route_map_entry_set_action_rmap_set_action_extcommunity_lb_bandwidth_destroy(
2847 struct nb_cb_destroy_args *args)
2848 {
2849 return lib_route_map_entry_set_destroy(args);
2850 }
2851
2852 /*
2853 * XPath:
2854 * /frr-route-map:lib/route-map/entry/set-action/rmap-set-action/frr-bgp-route-map:extcommunity-lb/two-octet-as-specific
2855 */
2856 int
2857 lib_route_map_entry_set_action_rmap_set_action_extcommunity_lb_two_octet_as_specific_modify(
2858 struct nb_cb_modify_args *args)
2859 {
2860 return NB_OK;
2861 }
2862
2863 int
2864 lib_route_map_entry_set_action_rmap_set_action_extcommunity_lb_two_octet_as_specific_destroy(
2865 struct nb_cb_destroy_args *args)
2866 {
2867 return lib_route_map_entry_set_destroy(args);
2868 }
2869
2870 /*
2871 * XPath:
2872 * /frr-route-map:lib/route-map/entry/set-action/rmap-set-action/frr-bgp-route-map:extcommunity-none
2873 */
2874 int lib_route_map_entry_set_action_rmap_set_action_extcommunity_none_modify(
2875 struct nb_cb_modify_args *args)
2876 {
2877 struct routemap_hook_context *rhc;
2878 bool none = false;
2879 int rv;
2880
2881 switch (args->event) {
2882 case NB_EV_VALIDATE:
2883 case NB_EV_PREPARE:
2884 case NB_EV_ABORT:
2885 break;
2886 case NB_EV_APPLY:
2887 /* Add configuration. */
2888 rhc = nb_running_get_entry(args->dnode, NULL, true);
2889 none = yang_dnode_get_bool(args->dnode, NULL);
2890
2891 /* Set destroy information. */
2892 rhc->rhc_shook = generic_set_delete;
2893 rhc->rhc_rule = "extcommunity";
2894 rhc->rhc_event = RMAP_EVENT_SET_DELETED;
2895
2896 if (none) {
2897 rv = generic_set_add(rhc->rhc_rmi, "extcommunity",
2898 "none", args->errmsg,
2899 args->errmsg_len);
2900 if (rv != CMD_SUCCESS) {
2901 rhc->rhc_shook = NULL;
2902 return NB_ERR_INCONSISTENCY;
2903 }
2904 return NB_OK;
2905 }
2906
2907 return NB_ERR_INCONSISTENCY;
2908 }
2909
2910 return NB_OK;
2911 }
2912
2913 int lib_route_map_entry_set_action_rmap_set_action_extcommunity_none_destroy(
2914 struct nb_cb_destroy_args *args)
2915 {
2916 switch (args->event) {
2917 case NB_EV_VALIDATE:
2918 case NB_EV_PREPARE:
2919 case NB_EV_ABORT:
2920 break;
2921 case NB_EV_APPLY:
2922 return lib_route_map_entry_set_destroy(args);
2923 }
2924
2925 return NB_OK;
2926 }
2927
2928 /*
2929 * XPath:
2930 * /frr-route-map:lib/route-map/entry/set-action/rmap-set-action/frr-bgp-route-map:evpn-gateway-ip-ipv4
2931 */
2932 int lib_route_map_entry_set_action_rmap_set_action_evpn_gateway_ip_ipv4_modify(
2933 struct nb_cb_modify_args *args)
2934 {
2935 struct routemap_hook_context *rhc;
2936 const char *type;
2937 int rv;
2938
2939 switch (args->event) {
2940 case NB_EV_VALIDATE:
2941 case NB_EV_PREPARE:
2942 case NB_EV_ABORT:
2943 break;
2944 case NB_EV_APPLY:
2945 /* Add configuration. */
2946 rhc = nb_running_get_entry(args->dnode, NULL, true);
2947 type = yang_dnode_get_string(args->dnode, NULL);
2948
2949 /* Set destroy information. */
2950 rhc->rhc_shook = generic_set_delete;
2951 rhc->rhc_rule = "evpn gateway-ip ipv4";
2952 rhc->rhc_event = RMAP_EVENT_SET_DELETED;
2953
2954 rv = generic_set_add(rhc->rhc_rmi, "evpn gateway-ip ipv4", type,
2955 args->errmsg, args->errmsg_len);
2956 if (rv != CMD_SUCCESS) {
2957 rhc->rhc_shook = NULL;
2958 return NB_ERR_INCONSISTENCY;
2959 }
2960 }
2961
2962 return NB_OK;
2963 }
2964
2965 int lib_route_map_entry_set_action_rmap_set_action_evpn_gateway_ip_ipv4_destroy(
2966 struct nb_cb_destroy_args *args)
2967 {
2968 switch (args->event) {
2969 case NB_EV_VALIDATE:
2970 case NB_EV_PREPARE:
2971 case NB_EV_ABORT:
2972 break;
2973 case NB_EV_APPLY:
2974 return lib_route_map_entry_set_destroy(args);
2975 }
2976
2977 return NB_OK;
2978 }
2979
2980 /*
2981 * XPath:
2982 * /frr-route-map:lib/route-map/entry/set-action/rmap-set-action/frr-bgp-route-map:evpn-gateway-ip-ipv6
2983 */
2984 int lib_route_map_entry_set_action_rmap_set_action_evpn_gateway_ip_ipv6_modify(
2985 struct nb_cb_modify_args *args)
2986 {
2987 struct routemap_hook_context *rhc;
2988 const char *type;
2989 int rv;
2990
2991 switch (args->event) {
2992 case NB_EV_VALIDATE:
2993 case NB_EV_PREPARE:
2994 case NB_EV_ABORT:
2995 break;
2996 case NB_EV_APPLY:
2997 /* Add configuration. */
2998 rhc = nb_running_get_entry(args->dnode, NULL, true);
2999 type = yang_dnode_get_string(args->dnode, NULL);
3000
3001 /* Set destroy information. */
3002 rhc->rhc_shook = generic_set_delete;
3003 rhc->rhc_rule = "evpn gateway-ip ipv6";
3004 rhc->rhc_event = RMAP_EVENT_SET_DELETED;
3005
3006 rv = generic_set_add(rhc->rhc_rmi, "evpn gateway-ip ipv6", type,
3007 args->errmsg, args->errmsg_len);
3008 if (rv != CMD_SUCCESS) {
3009 rhc->rhc_shook = NULL;
3010 return NB_ERR_INCONSISTENCY;
3011 }
3012 }
3013
3014 return NB_OK;
3015 }
3016
3017 int lib_route_map_entry_set_action_rmap_set_action_evpn_gateway_ip_ipv6_destroy(
3018 struct nb_cb_destroy_args *args)
3019 {
3020 switch (args->event) {
3021 case NB_EV_VALIDATE:
3022 case NB_EV_PREPARE:
3023 case NB_EV_ABORT:
3024 break;
3025 case NB_EV_APPLY:
3026 return lib_route_map_entry_set_destroy(args);
3027 }
3028
3029 return NB_OK;
3030 }
3031
3032 /*
3033 * XPath:
3034 * /frr-route-map:lib/route-map/entry/set-action/rmap-set-action/l3vpn-nexthop-encapsulation
3035 */
3036 int lib_route_map_entry_set_action_rmap_set_action_l3vpn_nexthop_encapsulation_modify(
3037 struct nb_cb_modify_args *args)
3038 {
3039 struct routemap_hook_context *rhc;
3040 const char *type;
3041 int rv;
3042
3043 switch (args->event) {
3044 case NB_EV_VALIDATE:
3045 case NB_EV_PREPARE:
3046 case NB_EV_ABORT:
3047 break;
3048 case NB_EV_APPLY:
3049 /* Add configuration. */
3050 rhc = nb_running_get_entry(args->dnode, NULL, true);
3051 type = yang_dnode_get_string(args->dnode, NULL);
3052
3053 /* Set destroy information. */
3054 rhc->rhc_shook = generic_set_delete;
3055 rhc->rhc_rule = "l3vpn next-hop encapsulation";
3056 rhc->rhc_event = RMAP_EVENT_SET_DELETED;
3057
3058 rv = generic_set_add(rhc->rhc_rmi,
3059 "l3vpn next-hop encapsulation", type,
3060 args->errmsg, args->errmsg_len);
3061 if (rv != CMD_SUCCESS) {
3062 rhc->rhc_shook = NULL;
3063 return NB_ERR_INCONSISTENCY;
3064 }
3065 }
3066
3067 return NB_OK;
3068 }
3069
3070 int lib_route_map_entry_set_action_rmap_set_action_l3vpn_nexthop_encapsulation_destroy(
3071 struct nb_cb_destroy_args *args)
3072 {
3073 switch (args->event) {
3074 case NB_EV_VALIDATE:
3075 case NB_EV_PREPARE:
3076 case NB_EV_ABORT:
3077 break;
3078 case NB_EV_APPLY:
3079 return lib_route_map_entry_set_destroy(args);
3080 }
3081
3082 return NB_OK;
3083 }