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