]>
Commit | Line | Data |
---|---|---|
acddc0ed | 1 | // SPDX-License-Identifier: GPL-2.0-or-later |
48cb7ea9 SP |
2 | /* |
3 | * Copyright (C) 2020 Vmware | |
4 | * Sarita Patra | |
48cb7ea9 SP |
5 | */ |
6 | ||
1f8031f7 DL |
7 | #include <zebra.h> |
8 | ||
48cb7ea9 SP |
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) { | |
4953391b DA |
60 | tmpstr = route_map_get_match_arg(index, command); |
61 | if (tmpstr != NULL) | |
48cb7ea9 SP |
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 | ||
2690f18c DA |
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 | ||
48cb7ea9 SP |
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) | |
1c035c8c DA |
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:source-protocol | |
373 | */ | |
374 | int lib_route_map_entry_match_condition_rmap_match_condition_source_protocol_modify( | |
375 | struct nb_cb_modify_args *args) | |
376 | { | |
377 | struct routemap_hook_context *rhc; | |
378 | enum rmap_compile_rets ret; | |
379 | const char *proto; | |
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 | proto = yang_dnode_get_string(args->dnode, NULL); | |
390 | ||
391 | /* Set destroy information. */ | |
392 | rhc->rhc_mhook = bgp_route_match_delete; | |
393 | rhc->rhc_rule = "source-protocol"; | |
394 | rhc->rhc_event = RMAP_EVENT_MATCH_DELETED; | |
395 | ||
396 | ret = bgp_route_match_add(rhc->rhc_rmi, "source-protocol", | |
397 | proto, 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_source_protocol_destroy( | |
410 | struct nb_cb_destroy_args *args) | |
48cb7ea9 SP |
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 | ||
324e8b1f DA |
424 | /* |
425 | * XPath: | |
426 | * /frr-route-map:lib/route-map/entry/match-condition/rmap-match-condition/frr-bgp-route-map:rpki-extcommunity | |
427 | */ | |
428 | int lib_route_map_entry_match_condition_rmap_match_condition_rpki_extcommunity_modify( | |
429 | struct nb_cb_modify_args *args) | |
430 | { | |
431 | struct routemap_hook_context *rhc; | |
432 | const char *rpki; | |
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 | rpki = yang_dnode_get_string(args->dnode, NULL); | |
444 | ||
445 | /* Set destroy information. */ | |
446 | rhc->rhc_mhook = bgp_route_match_delete; | |
447 | rhc->rhc_rule = "rpki-extcommunity"; | |
448 | rhc->rhc_event = RMAP_EVENT_MATCH_DELETED; | |
449 | ||
450 | ret = bgp_route_match_add(rhc->rhc_rmi, "rpki-extcommunity", | |
451 | rpki, 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 lib_route_map_entry_match_condition_rmap_match_condition_rpki_extcommunity_destroy( | |
464 | struct nb_cb_destroy_args *args) | |
465 | { | |
466 | switch (args->event) { | |
467 | case NB_EV_VALIDATE: | |
468 | case NB_EV_PREPARE: | |
469 | case NB_EV_ABORT: | |
470 | break; | |
471 | case NB_EV_APPLY: | |
472 | return lib_route_map_entry_match_destroy(args); | |
473 | } | |
474 | ||
48cb7ea9 SP |
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:probability | |
480 | */ | |
481 | int | |
482 | lib_route_map_entry_match_condition_rmap_match_condition_probability_modify( | |
483 | struct nb_cb_modify_args *args) | |
484 | { | |
485 | struct routemap_hook_context *rhc; | |
486 | const char *probability; | |
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 | probability = yang_dnode_get_string(args->dnode, NULL); | |
498 | ||
499 | /* Set destroy information. */ | |
500 | rhc->rhc_mhook = bgp_route_match_delete; | |
501 | rhc->rhc_rule = "probability"; | |
502 | rhc->rhc_event = RMAP_EVENT_MATCH_DELETED; | |
503 | ||
504 | ret = bgp_route_match_add(rhc->rhc_rmi, "probability", | |
505 | probability, 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_probability_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 | case NB_EV_APPLY: | |
526 | return lib_route_map_entry_match_destroy(args); | |
527 | } | |
528 | ||
529 | return NB_OK; | |
530 | } | |
531 | ||
532 | /* | |
533 | * XPath: /frr-route-map:lib/route-map/entry/match-condition/rmap-match-condition/frr-bgp-route-map:source-vrf | |
534 | */ | |
535 | int | |
536 | lib_route_map_entry_match_condition_rmap_match_condition_source_vrf_modify( | |
537 | struct nb_cb_modify_args *args) | |
538 | { | |
539 | struct routemap_hook_context *rhc; | |
540 | const char *vrf; | |
541 | enum rmap_compile_rets ret; | |
542 | ||
543 | switch (args->event) { | |
544 | case NB_EV_VALIDATE: | |
545 | case NB_EV_PREPARE: | |
546 | case NB_EV_ABORT: | |
547 | break; | |
548 | case NB_EV_APPLY: | |
549 | /* Add configuration. */ | |
550 | rhc = nb_running_get_entry(args->dnode, NULL, true); | |
551 | vrf = yang_dnode_get_string(args->dnode, NULL); | |
552 | ||
553 | /* Set destroy information. */ | |
554 | rhc->rhc_mhook = bgp_route_match_delete; | |
555 | rhc->rhc_rule = "source-vrf"; | |
556 | rhc->rhc_event = RMAP_EVENT_MATCH_DELETED; | |
557 | ||
558 | ret = bgp_route_match_add(rhc->rhc_rmi, "source-vrf", vrf, | |
559 | RMAP_EVENT_MATCH_ADDED, | |
560 | args->errmsg, args->errmsg_len); | |
561 | ||
562 | if (ret != RMAP_COMPILE_SUCCESS) { | |
563 | rhc->rhc_mhook = NULL; | |
564 | return NB_ERR_INCONSISTENCY; | |
565 | } | |
566 | } | |
567 | ||
568 | return NB_OK; | |
569 | } | |
570 | ||
571 | int | |
572 | lib_route_map_entry_match_condition_rmap_match_condition_source_vrf_destroy( | |
573 | struct nb_cb_destroy_args *args) | |
574 | { | |
575 | switch (args->event) { | |
576 | case NB_EV_VALIDATE: | |
577 | case NB_EV_PREPARE: | |
578 | case NB_EV_ABORT: | |
579 | break; | |
580 | case NB_EV_APPLY: | |
581 | return lib_route_map_entry_match_destroy(args); | |
582 | } | |
583 | ||
584 | return NB_OK; | |
585 | } | |
586 | ||
587 | /* | |
588 | * XPath: /frr-route-map:lib/route-map/entry/match-condition/rmap-match-condition/frr-bgp-route-map:peer-ipv4-address | |
589 | */ | |
590 | int | |
591 | lib_route_map_entry_match_condition_rmap_match_condition_peer_ipv4_address_modify( | |
592 | struct nb_cb_modify_args *args) | |
593 | { | |
594 | struct routemap_hook_context *rhc; | |
595 | const char *peer; | |
596 | enum rmap_compile_rets ret; | |
597 | ||
598 | switch (args->event) { | |
599 | case NB_EV_VALIDATE: | |
600 | case NB_EV_PREPARE: | |
601 | case NB_EV_ABORT: | |
602 | break; | |
603 | case NB_EV_APPLY: | |
604 | /* Add configuration. */ | |
605 | rhc = nb_running_get_entry(args->dnode, NULL, true); | |
606 | peer = yang_dnode_get_string(args->dnode, NULL); | |
607 | ||
608 | /* Set destroy information. */ | |
609 | rhc->rhc_mhook = bgp_route_match_delete; | |
610 | rhc->rhc_rule = "peer"; | |
611 | rhc->rhc_event = RMAP_EVENT_MATCH_DELETED; | |
612 | ||
613 | ret = bgp_route_match_add(rhc->rhc_rmi, "peer", peer, | |
614 | RMAP_EVENT_MATCH_ADDED, | |
615 | args->errmsg, args->errmsg_len); | |
616 | ||
617 | if (ret != RMAP_COMPILE_SUCCESS) { | |
618 | rhc->rhc_mhook = NULL; | |
619 | return NB_ERR_INCONSISTENCY; | |
620 | } | |
621 | } | |
622 | ||
623 | return NB_OK; | |
624 | } | |
625 | ||
626 | int | |
627 | lib_route_map_entry_match_condition_rmap_match_condition_peer_ipv4_address_destroy( | |
628 | struct nb_cb_destroy_args *args) | |
629 | { | |
630 | switch (args->event) { | |
631 | case NB_EV_VALIDATE: | |
632 | case NB_EV_PREPARE: | |
633 | case NB_EV_ABORT: | |
634 | break; | |
635 | case NB_EV_APPLY: | |
636 | return lib_route_map_entry_match_destroy(args); | |
637 | } | |
638 | ||
639 | return NB_OK; | |
640 | } | |
641 | ||
642 | /* | |
643 | * XPath: /frr-route-map:lib/route-map/entry/match-condition/rmap-match-condition/frr-bgp-route-map:peer-interface | |
644 | */ | |
645 | int | |
646 | lib_route_map_entry_match_condition_rmap_match_condition_peer_interface_modify( | |
647 | struct nb_cb_modify_args *args) | |
648 | { | |
649 | struct routemap_hook_context *rhc; | |
650 | const char *peer; | |
651 | enum rmap_compile_rets ret; | |
652 | ||
653 | switch (args->event) { | |
654 | case NB_EV_VALIDATE: | |
655 | case NB_EV_PREPARE: | |
656 | case NB_EV_ABORT: | |
657 | break; | |
658 | case NB_EV_APPLY: | |
659 | /* Add configuration. */ | |
660 | rhc = nb_running_get_entry(args->dnode, NULL, true); | |
661 | peer = yang_dnode_get_string(args->dnode, NULL); | |
662 | ||
663 | /* Set destroy information. */ | |
664 | rhc->rhc_mhook = bgp_route_match_delete; | |
665 | rhc->rhc_rule = "peer"; | |
666 | rhc->rhc_event = RMAP_EVENT_MATCH_DELETED; | |
667 | ||
668 | ret = bgp_route_match_add(rhc->rhc_rmi, "peer", peer, | |
669 | RMAP_EVENT_MATCH_ADDED, | |
670 | args->errmsg, args->errmsg_len); | |
671 | ||
672 | if (ret != RMAP_COMPILE_SUCCESS) { | |
673 | rhc->rhc_mhook = NULL; | |
674 | return NB_ERR_INCONSISTENCY; | |
675 | } | |
676 | } | |
677 | ||
678 | return NB_OK; | |
679 | } | |
680 | ||
681 | int | |
682 | lib_route_map_entry_match_condition_rmap_match_condition_peer_interface_destroy( | |
683 | struct nb_cb_destroy_args *args) | |
684 | { | |
685 | switch (args->event) { | |
686 | case NB_EV_VALIDATE: | |
687 | case NB_EV_PREPARE: | |
688 | case NB_EV_ABORT: | |
689 | break; | |
690 | case NB_EV_APPLY: | |
691 | return lib_route_map_entry_match_destroy(args); | |
692 | } | |
693 | ||
694 | return NB_OK; | |
695 | } | |
696 | ||
697 | /* | |
698 | * XPath: /frr-route-map:lib/route-map/entry/match-condition/rmap-match-condition/frr-bgp-route-map:peer-ipv6-address | |
699 | */ | |
700 | int | |
701 | lib_route_map_entry_match_condition_rmap_match_condition_peer_ipv6_address_modify( | |
702 | struct nb_cb_modify_args *args) | |
703 | { | |
704 | struct routemap_hook_context *rhc; | |
705 | const char *peer; | |
706 | enum rmap_compile_rets ret; | |
707 | ||
708 | switch (args->event) { | |
709 | case NB_EV_VALIDATE: | |
710 | case NB_EV_PREPARE: | |
711 | case NB_EV_ABORT: | |
712 | break; | |
713 | case NB_EV_APPLY: | |
714 | /* Add configuration. */ | |
715 | rhc = nb_running_get_entry(args->dnode, NULL, true); | |
716 | peer = yang_dnode_get_string(args->dnode, NULL); | |
717 | ||
718 | /* Set destroy information. */ | |
719 | rhc->rhc_mhook = bgp_route_match_delete; | |
720 | rhc->rhc_rule = "peer"; | |
721 | rhc->rhc_event = RMAP_EVENT_MATCH_DELETED; | |
722 | ||
723 | ret = bgp_route_match_add(rhc->rhc_rmi, "peer", peer, | |
724 | RMAP_EVENT_MATCH_ADDED, | |
725 | args->errmsg, args->errmsg_len); | |
726 | ||
727 | if (ret != RMAP_COMPILE_SUCCESS) { | |
728 | rhc->rhc_mhook = NULL; | |
729 | return NB_ERR_INCONSISTENCY; | |
730 | } | |
731 | } | |
732 | ||
733 | return NB_OK; | |
734 | } | |
735 | ||
736 | int | |
737 | lib_route_map_entry_match_condition_rmap_match_condition_peer_ipv6_address_destroy( | |
738 | struct nb_cb_destroy_args *args) | |
739 | { | |
740 | switch (args->event) { | |
741 | case NB_EV_VALIDATE: | |
742 | case NB_EV_PREPARE: | |
743 | case NB_EV_ABORT: | |
744 | break; | |
745 | case NB_EV_APPLY: | |
746 | return lib_route_map_entry_match_destroy(args); | |
747 | } | |
748 | ||
749 | return NB_OK; | |
750 | } | |
751 | ||
752 | /* | |
753 | * XPath: /frr-route-map:lib/route-map/entry/match-condition/rmap-match-condition/frr-bgp-route-map:peer-local | |
754 | */ | |
755 | int | |
756 | lib_route_map_entry_match_condition_rmap_match_condition_peer_local_modify( | |
757 | struct nb_cb_modify_args *args) | |
758 | { | |
759 | struct routemap_hook_context *rhc; | |
760 | bool value; | |
761 | enum rmap_compile_rets ret; | |
762 | ||
763 | switch (args->event) { | |
764 | case NB_EV_VALIDATE: | |
765 | case NB_EV_PREPARE: | |
766 | case NB_EV_ABORT: | |
767 | break; | |
768 | case NB_EV_APPLY: | |
769 | /* Add configuration. */ | |
770 | rhc = nb_running_get_entry(args->dnode, NULL, true); | |
771 | value = yang_dnode_get_bool(args->dnode, NULL); | |
772 | ||
773 | /* Set destroy information. */ | |
774 | rhc->rhc_mhook = bgp_route_match_delete; | |
775 | rhc->rhc_rule = "peer"; | |
776 | rhc->rhc_event = RMAP_EVENT_MATCH_DELETED; | |
777 | ||
778 | if (value) { | |
779 | ret = bgp_route_match_add(rhc->rhc_rmi, "peer", | |
780 | "local", | |
781 | RMAP_EVENT_MATCH_ADDED, | |
782 | args->errmsg, args->errmsg_len); | |
783 | ||
784 | if (ret != RMAP_COMPILE_SUCCESS) { | |
785 | rhc->rhc_mhook = NULL; | |
786 | return NB_ERR_INCONSISTENCY; | |
787 | } | |
788 | } | |
789 | } | |
790 | ||
791 | return NB_OK; | |
792 | } | |
793 | ||
794 | int | |
795 | lib_route_map_entry_match_condition_rmap_match_condition_peer_local_destroy( | |
796 | struct nb_cb_destroy_args *args) | |
797 | { | |
798 | switch (args->event) { | |
799 | case NB_EV_VALIDATE: | |
800 | case NB_EV_PREPARE: | |
801 | case NB_EV_ABORT: | |
802 | break; | |
803 | case NB_EV_APPLY: | |
804 | return lib_route_map_entry_match_destroy(args); | |
805 | } | |
806 | ||
807 | return NB_OK; | |
808 | } | |
809 | ||
810 | /* | |
811 | * XPath: /frr-route-map:lib/route-map/entry/match-condition/rmap-match-condition/frr-bgp-route-map:list-name | |
812 | */ | |
813 | int | |
814 | lib_route_map_entry_match_condition_rmap_match_condition_list_name_modify( | |
815 | struct nb_cb_modify_args *args) | |
816 | { | |
817 | struct routemap_hook_context *rhc; | |
818 | const char *list_name; | |
819 | enum rmap_compile_rets ret = RMAP_COMPILE_SUCCESS; | |
820 | const char *condition; | |
821 | ||
822 | switch (args->event) { | |
823 | case NB_EV_VALIDATE: | |
824 | case NB_EV_PREPARE: | |
825 | case NB_EV_ABORT: | |
826 | break; | |
827 | case NB_EV_APPLY: | |
828 | /* Add configuration. */ | |
829 | rhc = nb_running_get_entry(args->dnode, NULL, true); | |
830 | list_name = yang_dnode_get_string(args->dnode, NULL); | |
831 | condition = yang_dnode_get_string(args->dnode, | |
832 | "../../frr-route-map:condition"); | |
833 | ||
834 | if (IS_MATCH_AS_LIST(condition)) { | |
835 | /* Set destroy information. */ | |
836 | rhc->rhc_mhook = bgp_route_match_delete; | |
837 | rhc->rhc_rule = "as-path"; | |
838 | rhc->rhc_event = RMAP_EVENT_ASLIST_DELETED; | |
839 | ||
840 | ret = bgp_route_match_add(rhc->rhc_rmi, "as-path", | |
841 | list_name, RMAP_EVENT_ASLIST_ADDED, | |
842 | args->errmsg, args->errmsg_len); | |
843 | } else if (IS_MATCH_MAC_LIST(condition)) { | |
844 | /* Set destroy information. */ | |
845 | rhc->rhc_mhook = bgp_route_match_delete; | |
846 | rhc->rhc_rule = "mac address"; | |
847 | rhc->rhc_event = RMAP_EVENT_FILTER_DELETED; | |
848 | ||
849 | ret = bgp_route_match_add(rhc->rhc_rmi, | |
850 | "mac address", | |
851 | list_name, | |
852 | RMAP_EVENT_FILTER_ADDED, | |
853 | args->errmsg, args->errmsg_len); | |
854 | } else if (IS_MATCH_ROUTE_SRC(condition)) { | |
855 | /* Set destroy information. */ | |
856 | rhc->rhc_mhook = bgp_route_match_delete; | |
857 | rhc->rhc_rule = "ip route-source"; | |
858 | rhc->rhc_event = RMAP_EVENT_FILTER_DELETED; | |
859 | ||
860 | ret = bgp_route_match_add(rhc->rhc_rmi, | |
861 | "ip route-source", | |
862 | list_name, RMAP_EVENT_FILTER_ADDED, | |
863 | args->errmsg, args->errmsg_len); | |
864 | } else if (IS_MATCH_ROUTE_SRC_PL(condition)) { | |
865 | /* Set destroy information. */ | |
866 | rhc->rhc_mhook = bgp_route_match_delete; | |
867 | rhc->rhc_rule = "ip route-source prefix-list"; | |
868 | rhc->rhc_event = RMAP_EVENT_PLIST_DELETED; | |
869 | ||
870 | ret = bgp_route_match_add(rhc->rhc_rmi, | |
871 | "ip route-source prefix-list", | |
872 | list_name, RMAP_EVENT_PLIST_ADDED, | |
873 | args->errmsg, args->errmsg_len); | |
874 | } | |
875 | ||
876 | if (ret != RMAP_COMPILE_SUCCESS) { | |
877 | rhc->rhc_mhook = NULL; | |
878 | return NB_ERR_INCONSISTENCY; | |
879 | } | |
880 | } | |
881 | ||
882 | return NB_OK; | |
883 | } | |
884 | ||
885 | int | |
886 | lib_route_map_entry_match_condition_rmap_match_condition_list_name_destroy( | |
887 | struct nb_cb_destroy_args *args) | |
888 | { | |
889 | switch (args->event) { | |
890 | case NB_EV_VALIDATE: | |
891 | case NB_EV_PREPARE: | |
892 | case NB_EV_ABORT: | |
893 | break; | |
894 | case NB_EV_APPLY: | |
895 | return lib_route_map_entry_match_destroy(args); | |
896 | } | |
897 | ||
898 | return NB_OK; | |
899 | } | |
900 | ||
901 | /* | |
902 | * XPath: /frr-route-map:lib/route-map/entry/match-condition/rmap-match-condition/frr-bgp-route-map:evpn-default-route | |
903 | */ | |
904 | int | |
905 | lib_route_map_entry_match_condition_rmap_match_condition_evpn_default_route_create( | |
906 | struct nb_cb_create_args *args) | |
907 | { | |
908 | struct routemap_hook_context *rhc; | |
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 | ||
920 | /* Set destroy information. */ | |
921 | rhc->rhc_mhook = bgp_route_match_delete; | |
922 | rhc->rhc_rule = "evpn default-route"; | |
923 | rhc->rhc_event = RMAP_EVENT_MATCH_DELETED; | |
924 | ||
925 | ret = bgp_route_match_add(rhc->rhc_rmi, "evpn default-route", | |
926 | NULL, RMAP_EVENT_MATCH_ADDED, | |
927 | args->errmsg, args->errmsg_len); | |
928 | ||
929 | if (ret != RMAP_COMPILE_SUCCESS) { | |
930 | rhc->rhc_mhook = NULL; | |
931 | return NB_ERR_INCONSISTENCY; | |
932 | } | |
933 | } | |
934 | ||
935 | return NB_OK; | |
936 | } | |
937 | ||
938 | int | |
939 | lib_route_map_entry_match_condition_rmap_match_condition_evpn_default_route_destroy( | |
940 | struct nb_cb_destroy_args *args) | |
941 | { | |
942 | switch (args->event) { | |
943 | case NB_EV_VALIDATE: | |
944 | case NB_EV_PREPARE: | |
945 | case NB_EV_ABORT: | |
946 | break; | |
947 | case NB_EV_APPLY: | |
948 | return lib_route_map_entry_match_destroy(args); | |
949 | } | |
950 | ||
951 | return NB_OK; | |
952 | } | |
953 | ||
954 | /* | |
955 | * XPath: /frr-route-map:lib/route-map/entry/match-condition/rmap-match-condition/frr-bgp-route-map:evpn-vni | |
956 | */ | |
957 | int | |
958 | lib_route_map_entry_match_condition_rmap_match_condition_evpn_vni_modify( | |
959 | struct nb_cb_modify_args *args) | |
960 | { | |
961 | struct routemap_hook_context *rhc; | |
962 | const char *vni; | |
963 | enum rmap_compile_rets ret; | |
964 | ||
965 | switch (args->event) { | |
966 | case NB_EV_VALIDATE: | |
967 | case NB_EV_PREPARE: | |
968 | case NB_EV_ABORT: | |
969 | break; | |
970 | case NB_EV_APPLY: | |
971 | /* Add configuration. */ | |
972 | rhc = nb_running_get_entry(args->dnode, NULL, true); | |
973 | vni = yang_dnode_get_string(args->dnode, NULL); | |
974 | ||
975 | /* Set destroy information. */ | |
976 | rhc->rhc_mhook = bgp_route_match_delete; | |
977 | rhc->rhc_rule = "evpn vni"; | |
978 | rhc->rhc_event = RMAP_EVENT_MATCH_DELETED; | |
979 | ||
980 | ret = bgp_route_match_add(rhc->rhc_rmi, "evpn vni", vni, | |
981 | RMAP_EVENT_MATCH_ADDED, | |
982 | args->errmsg, args->errmsg_len); | |
983 | ||
984 | if (ret != RMAP_COMPILE_SUCCESS) { | |
985 | rhc->rhc_mhook = NULL; | |
986 | return NB_ERR_INCONSISTENCY; | |
987 | } | |
988 | } | |
989 | ||
990 | return NB_OK; | |
991 | } | |
992 | ||
993 | int | |
994 | lib_route_map_entry_match_condition_rmap_match_condition_evpn_vni_destroy( | |
995 | struct nb_cb_destroy_args *args) | |
996 | { | |
997 | switch (args->event) { | |
998 | case NB_EV_VALIDATE: | |
999 | case NB_EV_PREPARE: | |
1000 | case NB_EV_ABORT: | |
1001 | break; | |
1002 | case NB_EV_APPLY: | |
1003 | return lib_route_map_entry_match_destroy(args); | |
1004 | } | |
1005 | ||
1006 | return NB_OK; | |
1007 | } | |
1008 | ||
1009 | /* | |
1010 | * XPath: /frr-route-map:lib/route-map/entry/match-condition/rmap-match-condition/frr-bgp-route-map:evpn-route-type | |
1011 | */ | |
1012 | int | |
1013 | lib_route_map_entry_match_condition_rmap_match_condition_evpn_route_type_modify( | |
1014 | struct nb_cb_modify_args *args) | |
1015 | { | |
1016 | struct routemap_hook_context *rhc; | |
1017 | const char *type; | |
1018 | enum rmap_compile_rets ret; | |
1019 | ||
1020 | switch (args->event) { | |
1021 | case NB_EV_VALIDATE: | |
1022 | case NB_EV_PREPARE: | |
1023 | case NB_EV_ABORT: | |
1024 | break; | |
1025 | case NB_EV_APPLY: | |
1026 | /* Add configuration. */ | |
1027 | rhc = nb_running_get_entry(args->dnode, NULL, true); | |
1028 | type = yang_dnode_get_string(args->dnode, NULL); | |
1029 | ||
1030 | /* Set destroy information. */ | |
1031 | rhc->rhc_mhook = bgp_route_match_delete; | |
1032 | rhc->rhc_rule = "evpn route-type"; | |
1033 | rhc->rhc_event = RMAP_EVENT_MATCH_DELETED; | |
1034 | ||
1035 | ret = bgp_route_match_add(rhc->rhc_rmi, "evpn route-type", | |
1036 | type, | |
1037 | RMAP_EVENT_MATCH_ADDED, | |
1038 | args->errmsg, args->errmsg_len); | |
1039 | ||
1040 | if (ret != RMAP_COMPILE_SUCCESS) { | |
1041 | rhc->rhc_mhook = NULL; | |
1042 | return NB_ERR_INCONSISTENCY; | |
1043 | } | |
1044 | } | |
1045 | ||
1046 | return NB_OK; | |
1047 | } | |
1048 | ||
1049 | int | |
1050 | lib_route_map_entry_match_condition_rmap_match_condition_evpn_route_type_destroy( | |
1051 | struct nb_cb_destroy_args *args) | |
1052 | { | |
1053 | switch (args->event) { | |
1054 | case NB_EV_VALIDATE: | |
1055 | case NB_EV_PREPARE: | |
1056 | case NB_EV_ABORT: | |
1057 | break; | |
1058 | case NB_EV_APPLY: | |
1059 | return lib_route_map_entry_match_destroy(args); | |
1060 | } | |
1061 | ||
1062 | return NB_OK; | |
1063 | } | |
1064 | ||
1065 | /* | |
1066 | * XPath: /frr-route-map:lib/route-map/entry/match-condition/rmap-match-condition/frr-bgp-route-map:route-distinguisher | |
1067 | */ | |
1068 | int | |
1069 | lib_route_map_entry_match_condition_rmap_match_condition_route_distinguisher_modify( | |
1070 | struct nb_cb_modify_args *args) | |
1071 | { | |
1072 | struct routemap_hook_context *rhc; | |
1073 | const char *rd; | |
1074 | enum rmap_compile_rets ret; | |
1075 | ||
1076 | switch (args->event) { | |
1077 | case NB_EV_VALIDATE: | |
1078 | case NB_EV_PREPARE: | |
1079 | case NB_EV_ABORT: | |
1080 | break; | |
1081 | case NB_EV_APPLY: | |
1082 | /* Add configuration. */ | |
1083 | rhc = nb_running_get_entry(args->dnode, NULL, true); | |
1084 | rd = yang_dnode_get_string(args->dnode, NULL); | |
1085 | ||
1086 | /* Set destroy information. */ | |
1087 | rhc->rhc_mhook = bgp_route_match_delete; | |
1088 | rhc->rhc_rule = "evpn rd"; | |
1089 | rhc->rhc_event = RMAP_EVENT_MATCH_DELETED; | |
1090 | ||
1091 | ret = bgp_route_match_add(rhc->rhc_rmi, "evpn rd", rd, | |
1092 | RMAP_EVENT_MATCH_ADDED, | |
1093 | args->errmsg, args->errmsg_len); | |
1094 | ||
1095 | if (ret != RMAP_COMPILE_SUCCESS) { | |
1096 | rhc->rhc_mhook = NULL; | |
1097 | return NB_ERR_INCONSISTENCY; | |
1098 | } | |
1099 | } | |
1100 | ||
1101 | return NB_OK; | |
1102 | } | |
1103 | ||
1104 | int | |
1105 | lib_route_map_entry_match_condition_rmap_match_condition_route_distinguisher_destroy( | |
1106 | struct nb_cb_destroy_args *args) | |
1107 | { | |
1108 | switch (args->event) { | |
1109 | case NB_EV_VALIDATE: | |
1110 | case NB_EV_PREPARE: | |
1111 | case NB_EV_ABORT: | |
1112 | break; | |
1113 | case NB_EV_APPLY: | |
1114 | return lib_route_map_entry_match_destroy(args); | |
1115 | } | |
1116 | ||
1117 | return NB_OK; | |
1118 | } | |
1119 | ||
1120 | /* | |
1121 | * XPath = /frr-route-map:lib/route-map/entry/match-condition/rmap-match-condition/frr-bgp-route-map:comm-list | |
1122 | */ | |
1123 | void | |
1124 | lib_route_map_entry_match_condition_rmap_match_condition_comm_list_finish( | |
1125 | struct nb_cb_apply_finish_args *args) | |
1126 | { | |
1127 | struct routemap_hook_context *rhc; | |
1128 | const char *value; | |
1129 | bool exact_match = false; | |
1130 | char *argstr; | |
1131 | const char *condition; | |
1132 | route_map_event_t event; | |
ac0ed504 | 1133 | int ret; |
48cb7ea9 SP |
1134 | |
1135 | /* Add configuration. */ | |
1136 | rhc = nb_running_get_entry(args->dnode, NULL, true); | |
1137 | value = yang_dnode_get_string(args->dnode, "./comm-list-name"); | |
1138 | ||
1139 | if (yang_dnode_exists(args->dnode, "./comm-list-name-exact-match")) | |
1140 | exact_match = yang_dnode_get_bool( | |
1141 | args->dnode, "./comm-list-name-exact-match"); | |
1142 | ||
1143 | if (exact_match) { | |
1144 | argstr = XMALLOC(MTYPE_ROUTE_MAP_COMPILED, | |
1145 | strlen(value) + strlen("exact-match") + 2); | |
1146 | ||
1147 | snprintf(argstr, (strlen(value) + strlen("exact-match") + 2), | |
1148 | "%s exact-match", value); | |
1149 | } else | |
1150 | argstr = (char *)value; | |
1151 | ||
1152 | /* Set destroy information. */ | |
1153 | rhc->rhc_mhook = bgp_route_match_delete; | |
1154 | ||
1155 | condition = yang_dnode_get_string(args->dnode, | |
1156 | "../../frr-route-map:condition"); | |
1157 | if (IS_MATCH_COMMUNITY(condition)) { | |
1158 | rhc->rhc_rule = "community"; | |
1159 | event = RMAP_EVENT_CLIST_ADDED; | |
1160 | rhc->rhc_event = RMAP_EVENT_CLIST_DELETED; | |
1161 | } else if (IS_MATCH_LCOMMUNITY(condition)) { | |
1162 | rhc->rhc_rule = "large-community"; | |
1163 | event = RMAP_EVENT_LLIST_ADDED; | |
1164 | rhc->rhc_event = RMAP_EVENT_LLIST_DELETED; | |
1165 | } else { | |
1166 | rhc->rhc_rule = "extcommunity"; | |
1167 | event = RMAP_EVENT_ECLIST_ADDED; | |
1168 | rhc->rhc_event = RMAP_EVENT_ECLIST_DELETED; | |
1169 | } | |
1170 | ||
ac0ed504 DS |
1171 | ret = bgp_route_match_add(rhc->rhc_rmi, rhc->rhc_rule, argstr, event, |
1172 | args->errmsg, args->errmsg_len); | |
1173 | /* | |
1174 | * At this point if this is not a successful operation | |
1175 | * bgpd is about to crash. Let's just cut to the | |
1176 | * chase and do it. | |
1177 | */ | |
1178 | assert(ret == RMAP_COMPILE_SUCCESS); | |
48cb7ea9 SP |
1179 | |
1180 | if (argstr != value) | |
1181 | XFREE(MTYPE_ROUTE_MAP_COMPILED, argstr); | |
1182 | } | |
1183 | ||
1184 | /* | |
1185 | * XPath: | |
1186 | * /frr-route-map:lib/route-map/entry/match-condition/rmap-match-condition/frr-bgp-route-map:comm-list/comm-list-name | |
1187 | */ | |
1188 | int | |
1189 | lib_route_map_entry_match_condition_rmap_match_condition_comm_list_comm_list_name_modify( | |
1190 | struct nb_cb_modify_args *args) | |
1191 | { | |
1192 | switch (args->event) { | |
1193 | case NB_EV_VALIDATE: | |
1194 | case NB_EV_PREPARE: | |
1195 | case NB_EV_ABORT: | |
1196 | case NB_EV_APPLY: | |
1197 | break; | |
1198 | } | |
1199 | ||
1200 | return NB_OK; | |
1201 | } | |
1202 | ||
1203 | int | |
1204 | lib_route_map_entry_match_condition_rmap_match_condition_comm_list_comm_list_name_destroy( | |
1205 | struct nb_cb_destroy_args *args) | |
1206 | { | |
1207 | switch (args->event) { | |
1208 | case NB_EV_VALIDATE: | |
1209 | case NB_EV_PREPARE: | |
1210 | case NB_EV_ABORT: | |
1211 | break; | |
1212 | case NB_EV_APPLY: | |
1213 | return lib_route_map_entry_match_destroy(args); | |
1214 | } | |
1215 | ||
1216 | return NB_OK; | |
1217 | ||
1218 | } | |
1219 | ||
1220 | /* | |
1221 | * XPath: /frr-route-map:lib/route-map/entry/match-condition/rmap-match-condition/frr-bgp-route-map:comm-list/comm-list-name-exact-match | |
1222 | */ | |
1223 | int | |
1224 | lib_route_map_entry_match_condition_rmap_match_condition_comm_list_comm_list_name_exact_match_modify( | |
1225 | struct nb_cb_modify_args *args) | |
1226 | { | |
1227 | switch (args->event) { | |
1228 | case NB_EV_VALIDATE: | |
1229 | case NB_EV_PREPARE: | |
1230 | case NB_EV_ABORT: | |
1231 | case NB_EV_APPLY: | |
1232 | break; | |
1233 | } | |
1234 | ||
1235 | return NB_OK; | |
1236 | } | |
1237 | ||
1238 | int | |
1239 | lib_route_map_entry_match_condition_rmap_match_condition_comm_list_comm_list_name_exact_match_destroy( | |
1240 | struct nb_cb_destroy_args *args) | |
1241 | { | |
1242 | switch (args->event) { | |
1243 | case NB_EV_VALIDATE: | |
1244 | case NB_EV_PREPARE: | |
1245 | case NB_EV_ABORT: | |
1246 | break; | |
1247 | case NB_EV_APPLY: | |
1248 | return lib_route_map_entry_match_destroy(args); | |
1249 | } | |
1250 | ||
1251 | return NB_OK; | |
1252 | } | |
1253 | ||
1254 | /* | |
1255 | * XPath: /frr-route-map:lib/route-map/entry/match-condition/rmap-match-condition/frr-bgp-route-map:ipv4-address | |
1256 | */ | |
1257 | int | |
1258 | lib_route_map_entry_match_condition_rmap_match_condition_ipv4_address_modify( | |
1259 | struct nb_cb_modify_args *args) | |
1260 | { | |
1261 | struct routemap_hook_context *rhc; | |
1262 | const char *peer; | |
1263 | enum rmap_compile_rets ret; | |
1264 | ||
1265 | switch (args->event) { | |
1266 | case NB_EV_VALIDATE: | |
1267 | case NB_EV_PREPARE: | |
1268 | case NB_EV_ABORT: | |
1269 | break; | |
1270 | case NB_EV_APPLY: | |
1271 | /* Add configuration. */ | |
1272 | rhc = nb_running_get_entry(args->dnode, NULL, true); | |
1273 | peer = yang_dnode_get_string(args->dnode, NULL); | |
1274 | ||
1275 | /* Set destroy information. */ | |
1276 | rhc->rhc_mhook = bgp_route_match_delete; | |
1277 | rhc->rhc_rule = "ip next-hop address"; | |
1278 | rhc->rhc_event = RMAP_EVENT_MATCH_DELETED; | |
1279 | ||
1280 | ret = bgp_route_match_add(rhc->rhc_rmi, rhc->rhc_rule, | |
1281 | peer, RMAP_EVENT_MATCH_ADDED, | |
1282 | args->errmsg, args->errmsg_len); | |
1283 | ||
1284 | if (ret != RMAP_COMPILE_SUCCESS) { | |
1285 | rhc->rhc_mhook = NULL; | |
1286 | return NB_ERR_INCONSISTENCY; | |
1287 | } | |
1288 | } | |
1289 | ||
1290 | return NB_OK; | |
1291 | } | |
1292 | ||
1293 | int | |
1294 | lib_route_map_entry_match_condition_rmap_match_condition_ipv4_address_destroy( | |
1295 | struct nb_cb_destroy_args *args) | |
1296 | { | |
1297 | switch (args->event) { | |
1298 | case NB_EV_VALIDATE: | |
1299 | case NB_EV_PREPARE: | |
1300 | case NB_EV_ABORT: | |
1301 | break; | |
1302 | case NB_EV_APPLY: | |
1303 | return lib_route_map_entry_match_destroy(args); | |
1304 | } | |
1305 | ||
1306 | return NB_OK; | |
1307 | } | |
1308 | ||
1309 | /* | |
1310 | * XPath: /frr-route-map:lib/route-map/entry/match-condition/rmap-match-condition/frr-bgp-route-map:ipv6-address | |
1311 | */ | |
1312 | int | |
1313 | lib_route_map_entry_match_condition_rmap_match_condition_ipv6_address_modify( | |
1314 | struct nb_cb_modify_args *args) | |
1315 | { | |
1316 | struct routemap_hook_context *rhc; | |
1317 | const char *peer; | |
1318 | enum rmap_compile_rets ret; | |
1319 | ||
1320 | switch (args->event) { | |
1321 | case NB_EV_VALIDATE: | |
1322 | case NB_EV_PREPARE: | |
1323 | case NB_EV_ABORT: | |
1324 | break; | |
1325 | case NB_EV_APPLY: | |
1326 | /* Add configuration. */ | |
1327 | rhc = nb_running_get_entry(args->dnode, NULL, true); | |
1328 | peer = yang_dnode_get_string(args->dnode, NULL); | |
1329 | ||
1330 | /* Set destroy information. */ | |
1331 | rhc->rhc_mhook = bgp_route_match_delete; | |
03030106 | 1332 | rhc->rhc_rule = "ipv6 next-hop address"; |
48cb7ea9 SP |
1333 | rhc->rhc_event = RMAP_EVENT_MATCH_DELETED; |
1334 | ||
1335 | ret = bgp_route_match_add(rhc->rhc_rmi, rhc->rhc_rule, | |
1336 | peer, RMAP_EVENT_MATCH_ADDED, | |
1337 | args->errmsg, args->errmsg_len); | |
1338 | ||
1339 | if (ret != RMAP_COMPILE_SUCCESS) { | |
1340 | rhc->rhc_mhook = NULL; | |
1341 | return NB_ERR_INCONSISTENCY; | |
1342 | } | |
1343 | } | |
1344 | ||
1345 | return NB_OK; | |
1346 | } | |
1347 | ||
1348 | int | |
1349 | lib_route_map_entry_match_condition_rmap_match_condition_ipv6_address_destroy( | |
1350 | struct nb_cb_destroy_args *args) | |
1351 | { | |
1352 | switch (args->event) { | |
1353 | case NB_EV_VALIDATE: | |
1354 | case NB_EV_PREPARE: | |
1355 | case NB_EV_ABORT: | |
1356 | break; | |
1357 | case NB_EV_APPLY: | |
1358 | return lib_route_map_entry_match_destroy(args); | |
1359 | } | |
1360 | ||
1361 | return NB_OK; | |
1362 | } | |
1363 | ||
1364 | /* | |
1365 | * XPath: | |
1366 | * /frr-route-map:lib/route-map/entry/set-action/rmap-set-action/frr-bgp-route-map:distance | |
1367 | */ | |
1368 | int lib_route_map_entry_set_action_rmap_set_action_distance_modify( | |
1369 | struct nb_cb_modify_args *args) | |
1370 | { | |
1371 | struct routemap_hook_context *rhc; | |
1372 | const char *type; | |
1373 | int rv; | |
1374 | ||
1375 | switch (args->event) { | |
1376 | case NB_EV_VALIDATE: | |
1377 | case NB_EV_PREPARE: | |
1378 | case NB_EV_ABORT: | |
1379 | break; | |
1380 | case NB_EV_APPLY: | |
1381 | /* Add configuration. */ | |
1382 | rhc = nb_running_get_entry(args->dnode, NULL, true); | |
1383 | type = yang_dnode_get_string(args->dnode, NULL); | |
1384 | ||
1385 | /* Set destroy information. */ | |
1386 | rhc->rhc_shook = generic_set_delete; | |
1387 | rhc->rhc_rule = "distance"; | |
1388 | rhc->rhc_event = RMAP_EVENT_SET_DELETED; | |
1389 | ||
1390 | rv = generic_set_add(rhc->rhc_rmi, "distance", type, | |
1391 | args->errmsg, args->errmsg_len); | |
1392 | if (rv != CMD_SUCCESS) { | |
1393 | rhc->rhc_shook = NULL; | |
1394 | return NB_ERR_INCONSISTENCY; | |
1395 | } | |
1396 | } | |
1397 | ||
1398 | return NB_OK; | |
1399 | } | |
1400 | ||
1401 | int lib_route_map_entry_set_action_rmap_set_action_distance_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-rt | |
1419 | */ | |
1420 | int | |
1421 | lib_route_map_entry_set_action_rmap_set_action_extcommunity_rt_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 rt"; | |
1441 | rhc->rhc_event = RMAP_EVENT_SET_DELETED; | |
1442 | ||
1443 | rv = generic_set_add(rhc->rhc_rmi, "extcommunity rt", type, | |
1444 | args->errmsg, args->errmsg_len); | |
1445 | if (rv != CMD_SUCCESS) { | |
1446 | rhc->rhc_shook = NULL; | |
1447 | return NB_ERR_INCONSISTENCY; | |
1448 | } | |
1449 | } | |
1450 | ||
1451 | return NB_OK; | |
1452 | } | |
1453 | ||
1454 | int | |
1455 | lib_route_map_entry_set_action_rmap_set_action_extcommunity_rt_destroy( | |
1456 | struct nb_cb_destroy_args *args) | |
1457 | { | |
1458 | switch (args->event) { | |
1459 | case NB_EV_VALIDATE: | |
1460 | case NB_EV_PREPARE: | |
1461 | case NB_EV_ABORT: | |
1462 | break; | |
1463 | case NB_EV_APPLY: | |
1464 | return lib_route_map_entry_match_destroy(args); | |
1465 | } | |
1466 | ||
1467 | return NB_OK; | |
1468 | } | |
1469 | ||
c9a25614 DA |
1470 | /* |
1471 | * XPath: | |
1472 | * /frr-route-map:lib/route-map/entry/set-action/rmap-set-action/frr-bgp-route-map:extcommunity-nt | |
1473 | */ | |
1474 | int lib_route_map_entry_set_action_rmap_set_action_extcommunity_nt_modify( | |
1475 | struct nb_cb_modify_args *args) | |
1476 | { | |
1477 | struct routemap_hook_context *rhc; | |
1478 | const char *str; | |
1479 | int rv; | |
1480 | ||
1481 | switch (args->event) { | |
1482 | case NB_EV_VALIDATE: | |
1483 | case NB_EV_PREPARE: | |
1484 | case NB_EV_ABORT: | |
1485 | break; | |
1486 | case NB_EV_APPLY: | |
1487 | /* Add configuration. */ | |
1488 | rhc = nb_running_get_entry(args->dnode, NULL, true); | |
1489 | str = yang_dnode_get_string(args->dnode, NULL); | |
1490 | ||
1491 | /* Set destroy information. */ | |
1492 | rhc->rhc_shook = generic_set_delete; | |
1493 | rhc->rhc_rule = "extcommunity nt"; | |
1494 | rhc->rhc_event = RMAP_EVENT_SET_DELETED; | |
1495 | ||
1496 | rv = generic_set_add(rhc->rhc_rmi, "extcommunity nt", str, | |
1497 | args->errmsg, args->errmsg_len); | |
1498 | if (rv != CMD_SUCCESS) { | |
1499 | rhc->rhc_shook = NULL; | |
1500 | return NB_ERR_INCONSISTENCY; | |
1501 | } | |
1502 | } | |
1503 | ||
1504 | return NB_OK; | |
1505 | } | |
1506 | ||
1507 | int lib_route_map_entry_set_action_rmap_set_action_extcommunity_nt_destroy( | |
1508 | struct nb_cb_destroy_args *args) | |
1509 | { | |
1510 | switch (args->event) { | |
1511 | case NB_EV_VALIDATE: | |
1512 | case NB_EV_PREPARE: | |
1513 | case NB_EV_ABORT: | |
1514 | break; | |
1515 | case NB_EV_APPLY: | |
1516 | return lib_route_map_entry_match_destroy(args); | |
1517 | } | |
1518 | ||
1519 | return NB_OK; | |
1520 | } | |
1521 | ||
48cb7ea9 SP |
1522 | /* |
1523 | * XPath: | |
1524 | * /frr-route-map:lib/route-map/entry/set-action/rmap-set-action/frr-bgp-route-map:extcommunity-soo | |
1525 | */ | |
1526 | int | |
1527 | lib_route_map_entry_set_action_rmap_set_action_extcommunity_soo_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 = "extcommunity soo"; | |
1547 | rhc->rhc_event = RMAP_EVENT_SET_DELETED; | |
1548 | ||
1549 | rv = generic_set_add(rhc->rhc_rmi, "extcommunity soo", | |
1550 | type, | |
1551 | args->errmsg, args->errmsg_len); | |
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 | |
1562 | lib_route_map_entry_set_action_rmap_set_action_extcommunity_soo_destroy( | |
1563 | struct nb_cb_destroy_args *args) | |
1564 | { | |
1565 | switch (args->event) { | |
1566 | case NB_EV_VALIDATE: | |
1567 | case NB_EV_PREPARE: | |
1568 | case NB_EV_ABORT: | |
1569 | break; | |
1570 | case NB_EV_APPLY: | |
1571 | return lib_route_map_entry_match_destroy(args); | |
1572 | } | |
1573 | ||
1574 | return NB_OK; | |
1575 | } | |
1576 | ||
1577 | /* | |
1578 | * XPath: | |
1579 | * /frr-route-map:lib/route-map/entry/set-action/rmap-set-action/frr-bgp-route-map:ipv4-address | |
1580 | */ | |
1581 | int lib_route_map_entry_set_action_rmap_set_action_ipv4_address_modify( | |
1582 | struct nb_cb_modify_args *args) | |
1583 | { | |
1584 | struct routemap_hook_context *rhc; | |
1585 | const char *addr; | |
1586 | int rv = CMD_SUCCESS; | |
1587 | ||
1588 | switch (args->event) { | |
1589 | case NB_EV_VALIDATE: | |
1590 | case NB_EV_PREPARE: | |
1591 | case NB_EV_ABORT: | |
1592 | break; | |
1593 | case NB_EV_APPLY: | |
1594 | /* Add configuration. */ | |
1595 | rhc = nb_running_get_entry(args->dnode, NULL, true); | |
1596 | addr = yang_dnode_get_string(args->dnode, NULL); | |
1597 | ||
1598 | rhc->rhc_shook = generic_set_delete; | |
1599 | rhc->rhc_event = RMAP_EVENT_SET_DELETED; | |
1600 | rhc->rhc_rule = "ipv4 vpn next-hop"; | |
1601 | ||
1602 | rv = generic_set_add(rhc->rhc_rmi, rhc->rhc_rule, addr, | |
1603 | args->errmsg, args->errmsg_len); | |
1604 | ||
1605 | if (rv != CMD_SUCCESS) { | |
1606 | rhc->rhc_shook = NULL; | |
1607 | return NB_ERR_INCONSISTENCY; | |
1608 | } | |
1609 | } | |
1610 | ||
1611 | return NB_OK; | |
1612 | } | |
1613 | ||
1614 | int lib_route_map_entry_set_action_rmap_set_action_ipv4_address_destroy( | |
1615 | struct nb_cb_destroy_args *args) | |
1616 | { | |
1617 | switch (args->event) { | |
1618 | case NB_EV_VALIDATE: | |
1619 | case NB_EV_PREPARE: | |
1620 | case NB_EV_ABORT: | |
1621 | break; | |
1622 | case NB_EV_APPLY: | |
1623 | return lib_route_map_entry_set_destroy(args); | |
1624 | } | |
1625 | ||
1626 | return NB_OK; | |
1627 | } | |
1628 | ||
1629 | /* | |
1630 | * XPath: | |
1631 | * /frr-route-map:lib/route-map/entry/set-action/rmap-set-action/frr-bgp-route-map:ipv4-nexthop | |
1632 | */ | |
1633 | int lib_route_map_entry_set_action_rmap_set_action_ipv4_nexthop_modify( | |
1634 | struct nb_cb_modify_args *args) | |
1635 | { | |
1636 | struct routemap_hook_context *rhc; | |
1637 | const char *type; | |
1638 | int rv; | |
1639 | ||
1640 | switch (args->event) { | |
1641 | case NB_EV_VALIDATE: | |
1642 | case NB_EV_PREPARE: | |
1643 | case NB_EV_ABORT: | |
1644 | break; | |
1645 | case NB_EV_APPLY: | |
1646 | /* Add configuration. */ | |
1647 | rhc = nb_running_get_entry(args->dnode, NULL, true); | |
1648 | type = yang_dnode_get_string(args->dnode, NULL); | |
1649 | ||
1650 | /* Set destroy information. */ | |
1651 | rhc->rhc_shook = generic_set_delete; | |
1652 | rhc->rhc_rule = "ip next-hop"; | |
1653 | rhc->rhc_event = RMAP_EVENT_SET_DELETED; | |
1654 | ||
1655 | rv = generic_set_add(rhc->rhc_rmi, rhc->rhc_rule, type, | |
1656 | args->errmsg, args->errmsg_len); | |
1657 | ||
1658 | if (rv != CMD_SUCCESS) { | |
1659 | rhc->rhc_shook = NULL; | |
1660 | return NB_ERR_INCONSISTENCY; | |
1661 | } | |
1662 | } | |
1663 | ||
1664 | return NB_OK; | |
1665 | } | |
1666 | ||
1667 | int lib_route_map_entry_set_action_rmap_set_action_ipv4_nexthop_destroy( | |
1668 | struct nb_cb_destroy_args *args) | |
1669 | { | |
1670 | switch (args->event) { | |
1671 | case NB_EV_VALIDATE: | |
1672 | case NB_EV_PREPARE: | |
1673 | case NB_EV_ABORT: | |
1674 | break; | |
1675 | case NB_EV_APPLY: | |
1676 | return lib_route_map_entry_set_destroy(args); | |
1677 | } | |
1678 | ||
1679 | return NB_OK; | |
1680 | } | |
1681 | ||
1682 | /* | |
1683 | * XPath: | |
1684 | * /frr-route-map:lib/route-map/entry/set-action/rmap-set-action/frr-bgp-route-map:ipv6-address | |
1685 | */ | |
1686 | int lib_route_map_entry_set_action_rmap_set_action_ipv6_address_modify( | |
1687 | struct nb_cb_modify_args *args) | |
1688 | { | |
1689 | struct routemap_hook_context *rhc; | |
1690 | const char *addr; | |
1691 | int rv = CMD_SUCCESS; | |
1692 | const char *action = NULL; | |
1693 | struct in6_addr i6a; | |
1694 | ||
1695 | action = yang_dnode_get_string(args->dnode, | |
1696 | "../../frr-route-map:action"); | |
1697 | switch (args->event) { | |
1698 | case NB_EV_VALIDATE: | |
1699 | if (action && IS_SET_IPV6_NH_GLOBAL(action)) { | |
1700 | yang_dnode_get_ipv6(&i6a, args->dnode, NULL); | |
1701 | if (IN6_IS_ADDR_UNSPECIFIED(&i6a) | |
1702 | || IN6_IS_ADDR_LOOPBACK(&i6a) | |
1703 | || IN6_IS_ADDR_MULTICAST(&i6a) | |
1704 | || IN6_IS_ADDR_LINKLOCAL(&i6a)) | |
1705 | return NB_ERR_VALIDATION; | |
1706 | } | |
1707 | /* FALLTHROUGH */ | |
1708 | case NB_EV_PREPARE: | |
1709 | case NB_EV_ABORT: | |
1710 | return NB_OK; | |
1711 | case NB_EV_APPLY: | |
1712 | break; | |
1713 | } | |
1714 | ||
1715 | /* Add configuration. */ | |
1716 | rhc = nb_running_get_entry(args->dnode, NULL, true); | |
1717 | addr = yang_dnode_get_string(args->dnode, NULL); | |
1718 | ||
1719 | rhc->rhc_shook = generic_set_delete; | |
1720 | rhc->rhc_event = RMAP_EVENT_SET_DELETED; | |
1721 | ||
1722 | if (IS_SET_IPV6_NH_GLOBAL(action)) | |
1723 | /* Set destroy information. */ | |
1724 | rhc->rhc_rule = "ipv6 next-hop global"; | |
1725 | else | |
1726 | rhc->rhc_rule = "ipv6 vpn next-hop"; | |
1727 | ||
1728 | rv = generic_set_add(rhc->rhc_rmi, rhc->rhc_rule, addr, | |
1729 | args->errmsg, args->errmsg_len); | |
1730 | ||
1731 | if (rv != CMD_SUCCESS) { | |
1732 | rhc->rhc_shook = NULL; | |
1733 | return NB_ERR_INCONSISTENCY; | |
1734 | } | |
1735 | ||
1736 | return NB_OK; | |
1737 | } | |
1738 | ||
1739 | int lib_route_map_entry_set_action_rmap_set_action_ipv6_address_destroy( | |
1740 | struct nb_cb_destroy_args *args) | |
1741 | { | |
1742 | switch (args->event) { | |
1743 | case NB_EV_VALIDATE: | |
1744 | case NB_EV_PREPARE: | |
1745 | case NB_EV_ABORT: | |
1746 | break; | |
1747 | case NB_EV_APPLY: | |
1748 | return lib_route_map_entry_set_destroy(args); | |
1749 | } | |
1750 | ||
1751 | return NB_OK; | |
1752 | } | |
1753 | ||
1754 | /* | |
1755 | * XPath: | |
1756 | * /frr-route-map:lib/route-map/entry/set-action/rmap-set-action/frr-bgp-route-map:preference | |
1757 | */ | |
1758 | int lib_route_map_entry_set_action_rmap_set_action_preference_modify( | |
1759 | struct nb_cb_modify_args *args) | |
1760 | { | |
1761 | struct routemap_hook_context *rhc; | |
1762 | int rv = CMD_SUCCESS; | |
1763 | const char *action = NULL; | |
1764 | bool value; | |
1765 | ||
1766 | switch (args->event) { | |
1767 | case NB_EV_VALIDATE: | |
1768 | case NB_EV_PREPARE: | |
1769 | case NB_EV_ABORT: | |
1770 | break; | |
1771 | case NB_EV_APPLY: | |
1772 | /* Add configuration. */ | |
1773 | rhc = nb_running_get_entry(args->dnode, NULL, true); | |
1774 | value = yang_dnode_get_bool(args->dnode, NULL); | |
1775 | ||
1776 | rhc->rhc_shook = generic_set_delete; | |
1777 | rhc->rhc_event = RMAP_EVENT_SET_DELETED; | |
1778 | ||
1779 | action = yang_dnode_get_string(args->dnode, | |
1780 | "../../frr-route-map:action"); | |
1781 | ||
1782 | if (value) { | |
1783 | if (IS_SET_IPV6_PEER_ADDR(action)) | |
1784 | /* Set destroy information. */ | |
1785 | rhc->rhc_rule = "ipv6 next-hop peer-address"; | |
1786 | else | |
1787 | rhc->rhc_rule = "ipv6 next-hop prefer-global"; | |
1788 | ||
1789 | rv = generic_set_add(rhc->rhc_rmi, rhc->rhc_rule, | |
1790 | NULL, | |
1791 | args->errmsg, args->errmsg_len); | |
1792 | } | |
1793 | ||
1794 | if (rv != CMD_SUCCESS) { | |
1795 | rhc->rhc_shook = NULL; | |
1796 | return NB_ERR_INCONSISTENCY; | |
1797 | } | |
1798 | } | |
1799 | ||
1800 | return NB_OK; | |
1801 | } | |
1802 | ||
1803 | int lib_route_map_entry_set_action_rmap_set_action_preference_destroy( | |
1804 | struct nb_cb_destroy_args *args) | |
1805 | { | |
1806 | switch (args->event) { | |
1807 | case NB_EV_VALIDATE: | |
1808 | case NB_EV_PREPARE: | |
1809 | case NB_EV_ABORT: | |
1810 | break; | |
1811 | case NB_EV_APPLY: | |
1812 | return lib_route_map_entry_set_destroy(args); | |
1813 | } | |
1814 | ||
1815 | return NB_OK; | |
1816 | } | |
1817 | ||
1818 | /* | |
1819 | * XPath: | |
1820 | * /frr-route-map:lib/route-map/entry/set-action/rmap-set-action/frr-bgp-route-map:label-index | |
1821 | */ | |
1822 | int lib_route_map_entry_set_action_rmap_set_action_label_index_modify( | |
1823 | struct nb_cb_modify_args *args) | |
1824 | { | |
1825 | struct routemap_hook_context *rhc; | |
1826 | const char *type; | |
1827 | int rv; | |
1828 | ||
1829 | switch (args->event) { | |
1830 | case NB_EV_VALIDATE: | |
1831 | case NB_EV_PREPARE: | |
1832 | case NB_EV_ABORT: | |
1833 | break; | |
1834 | case NB_EV_APPLY: | |
1835 | /* Add configuration. */ | |
1836 | rhc = nb_running_get_entry(args->dnode, NULL, true); | |
1837 | type = yang_dnode_get_string(args->dnode, NULL); | |
1838 | ||
1839 | /* Set destroy information. */ | |
1840 | rhc->rhc_shook = generic_set_delete; | |
1841 | rhc->rhc_rule = "label-index"; | |
1842 | rhc->rhc_event = RMAP_EVENT_SET_DELETED; | |
1843 | ||
1844 | rv = generic_set_add(rhc->rhc_rmi, "label-index", type, | |
1845 | args->errmsg, args->errmsg_len); | |
1846 | if (rv != CMD_SUCCESS) { | |
1847 | rhc->rhc_shook = NULL; | |
1848 | return NB_ERR_INCONSISTENCY; | |
1849 | } | |
1850 | } | |
1851 | ||
1852 | return NB_OK; | |
1853 | } | |
1854 | ||
1855 | int lib_route_map_entry_set_action_rmap_set_action_label_index_destroy( | |
1856 | struct nb_cb_destroy_args *args) | |
1857 | { | |
1858 | switch (args->event) { | |
1859 | case NB_EV_VALIDATE: | |
1860 | case NB_EV_PREPARE: | |
1861 | case NB_EV_ABORT: | |
1862 | break; | |
1863 | case NB_EV_APPLY: | |
1864 | return lib_route_map_entry_set_destroy(args); | |
1865 | } | |
1866 | ||
1867 | return NB_OK; | |
1868 | } | |
1869 | ||
1870 | /* | |
1871 | * XPath: | |
1872 | * /frr-route-map:lib/route-map/entry/set-action/rmap-set-action/frr-bgp-route-map:local-pref | |
1873 | */ | |
1874 | int lib_route_map_entry_set_action_rmap_set_action_local_pref_modify( | |
1875 | struct nb_cb_modify_args *args) | |
1876 | { | |
1877 | struct routemap_hook_context *rhc; | |
1878 | const char *type; | |
1879 | int rv; | |
1880 | ||
1881 | switch (args->event) { | |
1882 | case NB_EV_VALIDATE: | |
1883 | case NB_EV_PREPARE: | |
1884 | case NB_EV_ABORT: | |
1885 | break; | |
1886 | case NB_EV_APPLY: | |
1887 | /* Add configuration. */ | |
1888 | rhc = nb_running_get_entry(args->dnode, NULL, true); | |
1889 | type = yang_dnode_get_string(args->dnode, NULL); | |
1890 | ||
1891 | /* Set destroy information. */ | |
1892 | rhc->rhc_shook = generic_set_delete; | |
1893 | rhc->rhc_rule = "local-preference"; | |
1894 | rhc->rhc_event = RMAP_EVENT_SET_DELETED; | |
1895 | ||
1896 | rv = generic_set_add(rhc->rhc_rmi, "local-preference", | |
1897 | type, | |
1898 | args->errmsg, args->errmsg_len); | |
1899 | if (rv != CMD_SUCCESS) { | |
1900 | rhc->rhc_shook = NULL; | |
1901 | return NB_ERR_INCONSISTENCY; | |
1902 | } | |
1903 | } | |
1904 | ||
1905 | return NB_OK; | |
1906 | } | |
1907 | ||
1908 | int lib_route_map_entry_set_action_rmap_set_action_local_pref_destroy( | |
1909 | struct nb_cb_destroy_args *args) | |
1910 | { | |
1911 | switch (args->event) { | |
1912 | case NB_EV_VALIDATE: | |
1913 | case NB_EV_PREPARE: | |
1914 | case NB_EV_ABORT: | |
1915 | break; | |
1916 | case NB_EV_APPLY: | |
1917 | return lib_route_map_entry_set_destroy(args); | |
1918 | } | |
1919 | ||
1920 | return NB_OK; | |
1921 | } | |
1922 | ||
1923 | /* | |
1924 | * XPath: | |
1925 | * /frr-route-map:lib/route-map/entry/set-action/rmap-set-action/frr-bgp-route-map:weight | |
1926 | */ | |
1927 | int lib_route_map_entry_set_action_rmap_set_action_weight_modify( | |
1928 | struct nb_cb_modify_args *args) | |
1929 | { | |
1930 | struct routemap_hook_context *rhc; | |
1931 | const char *type; | |
1932 | int rv; | |
1933 | ||
1934 | switch (args->event) { | |
1935 | case NB_EV_VALIDATE: | |
1936 | case NB_EV_PREPARE: | |
1937 | case NB_EV_ABORT: | |
1938 | break; | |
1939 | case NB_EV_APPLY: | |
1940 | /* Add configuration. */ | |
1941 | rhc = nb_running_get_entry(args->dnode, NULL, true); | |
1942 | type = yang_dnode_get_string(args->dnode, NULL); | |
1943 | ||
1944 | /* Set destroy information. */ | |
1945 | rhc->rhc_shook = generic_set_delete; | |
1946 | rhc->rhc_rule = "weight"; | |
1947 | rhc->rhc_event = RMAP_EVENT_SET_DELETED; | |
1948 | ||
1949 | rv = generic_set_add(rhc->rhc_rmi, "weight", type, | |
1950 | args->errmsg, args->errmsg_len); | |
1951 | if (rv != CMD_SUCCESS) { | |
1952 | rhc->rhc_shook = NULL; | |
1953 | return NB_ERR_INCONSISTENCY; | |
1954 | } | |
1955 | } | |
1956 | ||
1957 | return NB_OK; | |
1958 | } | |
1959 | ||
1960 | int lib_route_map_entry_set_action_rmap_set_action_weight_destroy( | |
1961 | struct nb_cb_destroy_args *args) | |
1962 | { | |
1963 | switch (args->event) { | |
1964 | case NB_EV_VALIDATE: | |
1965 | case NB_EV_PREPARE: | |
1966 | case NB_EV_ABORT: | |
1967 | break; | |
1968 | case NB_EV_APPLY: | |
1969 | return lib_route_map_entry_set_destroy(args); | |
1970 | } | |
1971 | ||
1972 | return NB_OK; | |
1973 | } | |
1974 | ||
1975 | /* | |
1976 | * XPath: | |
1977 | * /frr-route-map:lib/route-map/entry/set-action/rmap-set-action/frr-bgp-route-map:origin | |
1978 | */ | |
1979 | int lib_route_map_entry_set_action_rmap_set_action_origin_modify( | |
1980 | struct nb_cb_modify_args *args) | |
1981 | { | |
1982 | struct routemap_hook_context *rhc; | |
1983 | const char *type; | |
1984 | int rv; | |
1985 | ||
1986 | switch (args->event) { | |
1987 | case NB_EV_VALIDATE: | |
1988 | case NB_EV_PREPARE: | |
1989 | case NB_EV_ABORT: | |
1990 | break; | |
1991 | case NB_EV_APPLY: | |
1992 | /* Add configuration. */ | |
1993 | rhc = nb_running_get_entry(args->dnode, NULL, true); | |
1994 | type = yang_dnode_get_string(args->dnode, NULL); | |
1995 | ||
1996 | /* Set destroy information. */ | |
1997 | rhc->rhc_shook = generic_set_delete; | |
1998 | rhc->rhc_rule = "origin"; | |
1999 | rhc->rhc_event = RMAP_EVENT_SET_DELETED; | |
2000 | ||
2001 | rv = generic_set_add(rhc->rhc_rmi, "origin", type, | |
2002 | args->errmsg, args->errmsg_len); | |
2003 | if (rv != CMD_SUCCESS) { | |
2004 | rhc->rhc_shook = NULL; | |
2005 | return NB_ERR_INCONSISTENCY; | |
2006 | } | |
2007 | } | |
2008 | ||
2009 | return NB_OK; | |
2010 | } | |
2011 | ||
2012 | int lib_route_map_entry_set_action_rmap_set_action_origin_destroy( | |
2013 | struct nb_cb_destroy_args *args) | |
2014 | { | |
2015 | switch (args->event) { | |
2016 | case NB_EV_VALIDATE: | |
2017 | case NB_EV_PREPARE: | |
2018 | case NB_EV_ABORT: | |
2019 | break; | |
2020 | case NB_EV_APPLY: | |
2021 | return lib_route_map_entry_set_destroy(args); | |
2022 | ||
2023 | } | |
2024 | ||
2025 | return NB_OK; | |
2026 | } | |
2027 | ||
2028 | /* | |
2029 | * XPath: | |
2030 | * /frr-route-map:lib/route-map/entry/set-action/rmap-set-action/frr-bgp-route-map:originator-id | |
2031 | */ | |
2032 | int lib_route_map_entry_set_action_rmap_set_action_originator_id_modify( | |
2033 | struct nb_cb_modify_args *args) | |
2034 | { | |
2035 | struct routemap_hook_context *rhc; | |
2036 | const char *type; | |
2037 | int rv; | |
2038 | ||
2039 | switch (args->event) { | |
2040 | case NB_EV_VALIDATE: | |
2041 | case NB_EV_PREPARE: | |
2042 | case NB_EV_ABORT: | |
2043 | break; | |
2044 | case NB_EV_APPLY: | |
2045 | /* Add configuration. */ | |
2046 | rhc = nb_running_get_entry(args->dnode, NULL, true); | |
2047 | type = yang_dnode_get_string(args->dnode, NULL); | |
2048 | ||
2049 | /* Set destroy information. */ | |
2050 | rhc->rhc_shook = generic_set_delete; | |
2051 | rhc->rhc_rule = "originator-id"; | |
2052 | rhc->rhc_event = RMAP_EVENT_SET_DELETED; | |
2053 | ||
2054 | rv = generic_set_add(rhc->rhc_rmi, "originator-id", type, | |
2055 | args->errmsg, args->errmsg_len); | |
2056 | if (rv != CMD_SUCCESS) { | |
2057 | rhc->rhc_shook = NULL; | |
2058 | return NB_ERR_INCONSISTENCY; | |
2059 | } | |
2060 | } | |
2061 | ||
2062 | return NB_OK; | |
2063 | } | |
2064 | ||
2065 | int lib_route_map_entry_set_action_rmap_set_action_originator_id_destroy( | |
2066 | struct nb_cb_destroy_args *args) | |
2067 | { | |
2068 | switch (args->event) { | |
2069 | case NB_EV_VALIDATE: | |
2070 | case NB_EV_PREPARE: | |
2071 | case NB_EV_ABORT: | |
2072 | break; | |
2073 | case NB_EV_APPLY: | |
2074 | return lib_route_map_entry_set_destroy(args); | |
2075 | } | |
2076 | ||
2077 | return NB_OK; | |
2078 | } | |
2079 | ||
2080 | /* | |
2081 | * XPath: | |
2082 | * /frr-route-map:lib/route-map/entry/set-action/rmap-set-action/frr-bgp-route-map:table | |
2083 | */ | |
2084 | int lib_route_map_entry_set_action_rmap_set_action_table_modify( | |
2085 | struct nb_cb_modify_args *args) | |
2086 | { | |
2087 | struct routemap_hook_context *rhc; | |
2088 | const char *type; | |
2089 | int rv; | |
2090 | ||
2091 | switch (args->event) { | |
2092 | case NB_EV_VALIDATE: | |
2093 | case NB_EV_PREPARE: | |
2094 | case NB_EV_ABORT: | |
2095 | break; | |
2096 | case NB_EV_APPLY: | |
2097 | /* Add configuration. */ | |
2098 | rhc = nb_running_get_entry(args->dnode, NULL, true); | |
2099 | type = yang_dnode_get_string(args->dnode, NULL); | |
2100 | ||
2101 | /* Set destroy information. */ | |
2102 | rhc->rhc_shook = generic_set_delete; | |
2103 | rhc->rhc_rule = "table"; | |
2104 | rhc->rhc_event = RMAP_EVENT_SET_DELETED; | |
2105 | ||
2106 | rv = generic_set_add(rhc->rhc_rmi, "table", type, | |
2107 | args->errmsg, args->errmsg_len); | |
2108 | if (rv != CMD_SUCCESS) { | |
2109 | rhc->rhc_shook = NULL; | |
2110 | return NB_ERR_INCONSISTENCY; | |
2111 | } | |
2112 | } | |
2113 | ||
2114 | return NB_OK; | |
2115 | } | |
2116 | ||
2117 | int lib_route_map_entry_set_action_rmap_set_action_table_destroy( | |
2118 | struct nb_cb_destroy_args *args) | |
2119 | { | |
2120 | switch (args->event) { | |
2121 | case NB_EV_VALIDATE: | |
2122 | case NB_EV_PREPARE: | |
2123 | case NB_EV_ABORT: | |
2124 | break; | |
2125 | case NB_EV_APPLY: | |
2126 | return lib_route_map_entry_set_destroy(args); | |
2127 | } | |
2128 | ||
2129 | return NB_OK; | |
2130 | } | |
2131 | ||
2132 | /* | |
2133 | * XPath: | |
2134 | * /frr-route-map:lib/route-map/entry/set-action/rmap-set-action/frr-bgp-route-map:atomic-aggregate | |
2135 | */ | |
2136 | int | |
2137 | lib_route_map_entry_set_action_rmap_set_action_atomic_aggregate_create( | |
2138 | struct nb_cb_create_args *args) | |
2139 | { | |
2140 | struct routemap_hook_context *rhc; | |
2141 | int rv; | |
2142 | ||
2143 | switch (args->event) { | |
2144 | case NB_EV_VALIDATE: | |
2145 | case NB_EV_PREPARE: | |
2146 | case NB_EV_ABORT: | |
2147 | break; | |
2148 | case NB_EV_APPLY: | |
2149 | /* Add configuration. */ | |
2150 | rhc = nb_running_get_entry(args->dnode, NULL, true); | |
2151 | ||
2152 | /* Set destroy information. */ | |
2153 | rhc->rhc_shook = generic_set_delete; | |
2154 | rhc->rhc_rule = "atomic-aggregate"; | |
2155 | rhc->rhc_event = RMAP_EVENT_SET_DELETED; | |
2156 | ||
2157 | rv = generic_set_add(rhc->rhc_rmi, rhc->rhc_rule, NULL, | |
2158 | args->errmsg, args->errmsg_len); | |
2159 | if (rv != CMD_SUCCESS) { | |
2160 | rhc->rhc_shook = NULL; | |
2161 | return NB_ERR_INCONSISTENCY; | |
2162 | } | |
2163 | } | |
2164 | ||
2165 | return NB_OK; | |
2166 | } | |
2167 | ||
2168 | int | |
2169 | lib_route_map_entry_set_action_rmap_set_action_atomic_aggregate_destroy( | |
2170 | struct nb_cb_destroy_args *args) | |
2171 | { | |
2172 | switch (args->event) { | |
2173 | case NB_EV_VALIDATE: | |
2174 | case NB_EV_PREPARE: | |
2175 | case NB_EV_ABORT: | |
2176 | break; | |
2177 | case NB_EV_APPLY: | |
2178 | return lib_route_map_entry_set_destroy(args); | |
2179 | } | |
2180 | ||
2181 | return NB_OK; | |
2182 | } | |
2183 | ||
97a52c82 DA |
2184 | /* |
2185 | * XPath: | |
2186 | * /frr-route-map:lib/route-map/entry/set-action/rmap-set-action/frr-bgp-route-map:aigp-metric | |
2187 | */ | |
2188 | int lib_route_map_entry_set_action_rmap_set_action_aigp_metric_modify( | |
2189 | struct nb_cb_modify_args *args) | |
2190 | { | |
2191 | struct routemap_hook_context *rhc; | |
2192 | const char *aigp; | |
2193 | int rv; | |
2194 | ||
2195 | switch (args->event) { | |
2196 | case NB_EV_VALIDATE: | |
2197 | case NB_EV_PREPARE: | |
2198 | case NB_EV_ABORT: | |
2199 | break; | |
2200 | case NB_EV_APPLY: | |
2201 | /* Add configuration. */ | |
2202 | rhc = nb_running_get_entry(args->dnode, NULL, true); | |
2203 | aigp = yang_dnode_get_string(args->dnode, NULL); | |
2204 | ||
2205 | /* Set destroy information. */ | |
2206 | rhc->rhc_shook = generic_set_delete; | |
2207 | rhc->rhc_rule = "aigp-metric"; | |
2208 | rhc->rhc_event = RMAP_EVENT_SET_DELETED; | |
2209 | ||
2210 | rv = generic_set_add(rhc->rhc_rmi, rhc->rhc_rule, aigp, | |
2211 | args->errmsg, args->errmsg_len); | |
2212 | if (rv != CMD_SUCCESS) { | |
2213 | rhc->rhc_shook = NULL; | |
2214 | return NB_ERR_INCONSISTENCY; | |
2215 | } | |
2216 | } | |
2217 | ||
2218 | return NB_OK; | |
2219 | } | |
2220 | ||
2221 | int lib_route_map_entry_set_action_rmap_set_action_aigp_metric_destroy( | |
2222 | struct nb_cb_destroy_args *args) | |
2223 | { | |
2224 | switch (args->event) { | |
2225 | case NB_EV_VALIDATE: | |
2226 | case NB_EV_PREPARE: | |
2227 | case NB_EV_ABORT: | |
2228 | break; | |
2229 | case NB_EV_APPLY: | |
2230 | return lib_route_map_entry_set_destroy(args); | |
2231 | } | |
2232 | ||
2233 | return NB_OK; | |
2234 | } | |
2235 | ||
48cb7ea9 SP |
2236 | /* |
2237 | * XPath: | |
2238 | * /frr-route-map:lib/route-map/entry/set-action/rmap-set-action/frr-bgp-route-map:prepend-as-path | |
2239 | */ | |
2240 | int | |
2241 | lib_route_map_entry_set_action_rmap_set_action_prepend_as_path_modify( | |
2242 | struct nb_cb_modify_args *args) | |
2243 | { | |
2244 | struct routemap_hook_context *rhc; | |
2245 | const char *type; | |
2246 | int rv; | |
2247 | ||
2248 | switch (args->event) { | |
2249 | case NB_EV_VALIDATE: | |
2250 | case NB_EV_PREPARE: | |
2251 | case NB_EV_ABORT: | |
2252 | break; | |
2253 | case NB_EV_APPLY: | |
2254 | /* Add configuration. */ | |
2255 | rhc = nb_running_get_entry(args->dnode, NULL, true); | |
2256 | type = yang_dnode_get_string(args->dnode, NULL); | |
2257 | ||
2258 | /* Set destroy information. */ | |
2259 | rhc->rhc_shook = generic_set_delete; | |
2260 | rhc->rhc_rule = "as-path prepend"; | |
2261 | rhc->rhc_event = RMAP_EVENT_SET_DELETED; | |
2262 | ||
2263 | rv = generic_set_add(rhc->rhc_rmi, "as-path prepend", | |
2264 | type, | |
2265 | args->errmsg, args->errmsg_len); | |
2266 | if (rv != CMD_SUCCESS) { | |
2267 | rhc->rhc_shook = NULL; | |
2268 | return NB_ERR_INCONSISTENCY; | |
2269 | } | |
2270 | } | |
2271 | ||
2272 | return NB_OK; | |
2273 | } | |
2274 | ||
2275 | int | |
2276 | lib_route_map_entry_set_action_rmap_set_action_prepend_as_path_destroy( | |
2277 | struct nb_cb_destroy_args *args) | |
2278 | { | |
2279 | switch (args->event) { | |
2280 | case NB_EV_VALIDATE: | |
2281 | case NB_EV_PREPARE: | |
2282 | case NB_EV_ABORT: | |
2283 | break; | |
2284 | case NB_EV_APPLY: | |
2285 | return lib_route_map_entry_set_destroy(args); | |
2286 | } | |
2287 | ||
2288 | return NB_OK; | |
2289 | } | |
2290 | ||
2291 | /* | |
2292 | * XPath: | |
2293 | * /frr-route-map:lib/route-map/entry/set-action/rmap-set-action/frr-bgp-route-map:last-as | |
2294 | */ | |
2295 | int lib_route_map_entry_set_action_rmap_set_action_last_as_modify( | |
2296 | struct nb_cb_modify_args *args) | |
2297 | { | |
2298 | struct routemap_hook_context *rhc; | |
2299 | const char *value; | |
2300 | char *argstr; | |
2301 | int rv; | |
2302 | ||
2303 | switch (args->event) { | |
2304 | case NB_EV_VALIDATE: | |
2305 | case NB_EV_PREPARE: | |
2306 | case NB_EV_ABORT: | |
2307 | break; | |
2308 | case NB_EV_APPLY: | |
2309 | /* Add configuration. */ | |
2310 | rhc = nb_running_get_entry(args->dnode, NULL, true); | |
2311 | value = yang_dnode_get_string(args->dnode, NULL); | |
2312 | ||
2313 | /* Set destroy information. */ | |
2314 | rhc->rhc_shook = generic_set_delete; | |
2315 | rhc->rhc_rule = "as-path prepend"; | |
2316 | rhc->rhc_event = RMAP_EVENT_SET_DELETED; | |
2317 | ||
2318 | argstr = XMALLOC(MTYPE_ROUTE_MAP_COMPILED, | |
2319 | strlen(value) + strlen("last-as") + 2); | |
2320 | ||
2321 | snprintf(argstr, (strlen(value) + strlen("last-as") + 2), | |
2322 | "last-as %s", value); | |
2323 | ||
2324 | rv = generic_set_add(rhc->rhc_rmi, "as-path prepend", | |
2325 | argstr, | |
2326 | args->errmsg, args->errmsg_len); | |
2327 | if (rv != CMD_SUCCESS) { | |
2328 | rhc->rhc_shook = NULL; | |
2329 | XFREE(MTYPE_ROUTE_MAP_COMPILED, argstr); | |
2330 | return NB_ERR_INCONSISTENCY; | |
2331 | } | |
2332 | ||
2333 | XFREE(MTYPE_ROUTE_MAP_COMPILED, argstr); | |
2334 | } | |
2335 | ||
2336 | return NB_OK; | |
2337 | } | |
2338 | ||
2339 | int lib_route_map_entry_set_action_rmap_set_action_last_as_destroy( | |
2340 | struct nb_cb_destroy_args *args) | |
2341 | { | |
2342 | switch (args->event) { | |
2343 | case NB_EV_VALIDATE: | |
2344 | case NB_EV_PREPARE: | |
2345 | case NB_EV_ABORT: | |
2346 | break; | |
2347 | case NB_EV_APPLY: | |
2348 | return lib_route_map_entry_set_destroy(args); | |
2349 | } | |
2350 | ||
2351 | return NB_OK; | |
2352 | } | |
2353 | ||
2354 | /* | |
2355 | * XPath: | |
2356 | * /frr-route-map:lib/route-map/entry/set-action/rmap-set-action/frr-bgp-route-map:exclude-as-path | |
2357 | */ | |
2358 | int | |
2359 | lib_route_map_entry_set_action_rmap_set_action_exclude_as_path_modify( | |
2360 | struct nb_cb_modify_args *args) | |
2361 | { | |
2362 | struct routemap_hook_context *rhc; | |
2363 | const char *type; | |
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 | type = yang_dnode_get_string(args->dnode, NULL); | |
2375 | ||
2376 | /* Set destroy information. */ | |
2377 | rhc->rhc_shook = generic_set_delete; | |
2378 | rhc->rhc_rule = "as-path exclude"; | |
2379 | rhc->rhc_event = RMAP_EVENT_SET_DELETED; | |
2380 | ||
2381 | rv = generic_set_add(rhc->rhc_rmi, "as-path exclude", | |
2382 | type, | |
2383 | args->errmsg, args->errmsg_len); | |
2384 | if (rv != CMD_SUCCESS) { | |
2385 | rhc->rhc_shook = NULL; | |
2386 | return NB_ERR_INCONSISTENCY; | |
2387 | } | |
2388 | } | |
2389 | ||
2390 | return NB_OK; | |
2391 | } | |
2392 | ||
2393 | int | |
2394 | lib_route_map_entry_set_action_rmap_set_action_exclude_as_path_destroy( | |
2395 | struct nb_cb_destroy_args *args) | |
2396 | { | |
2397 | switch (args->event) { | |
2398 | case NB_EV_VALIDATE: | |
2399 | case NB_EV_PREPARE: | |
2400 | case NB_EV_ABORT: | |
2401 | break; | |
2402 | case NB_EV_APPLY: | |
2403 | return lib_route_map_entry_set_destroy(args); | |
2404 | } | |
2405 | ||
2406 | return NB_OK; | |
2407 | } | |
2408 | ||
77e3d821 DA |
2409 | /* |
2410 | * XPath: | |
2411 | * /frr-route-map:lib/route-map/entry/set-action/rmap-set-action/frr-bgp-route-map:replace-as-path | |
2412 | */ | |
2413 | int lib_route_map_entry_set_action_rmap_set_action_replace_as_path_modify( | |
2414 | struct nb_cb_modify_args *args) | |
2415 | { | |
2416 | struct routemap_hook_context *rhc; | |
2417 | const char *type; | |
2418 | int rv; | |
2419 | ||
2420 | switch (args->event) { | |
2421 | case NB_EV_VALIDATE: | |
2422 | case NB_EV_PREPARE: | |
2423 | case NB_EV_ABORT: | |
2424 | break; | |
2425 | case NB_EV_APPLY: | |
2426 | /* Add configuration. */ | |
2427 | rhc = nb_running_get_entry(args->dnode, NULL, true); | |
2428 | type = yang_dnode_get_string(args->dnode, NULL); | |
2429 | ||
2430 | /* Set destroy information. */ | |
2431 | rhc->rhc_shook = generic_set_delete; | |
2432 | rhc->rhc_rule = "as-path replace"; | |
2433 | rhc->rhc_event = RMAP_EVENT_SET_DELETED; | |
2434 | ||
2435 | rv = generic_set_add(rhc->rhc_rmi, "as-path replace", type, | |
2436 | args->errmsg, args->errmsg_len); | |
2437 | if (rv != CMD_SUCCESS) { | |
2438 | rhc->rhc_shook = NULL; | |
2439 | return NB_ERR_INCONSISTENCY; | |
2440 | } | |
2441 | } | |
2442 | ||
2443 | return NB_OK; | |
2444 | } | |
2445 | ||
2446 | int lib_route_map_entry_set_action_rmap_set_action_replace_as_path_destroy( | |
2447 | struct nb_cb_destroy_args *args) | |
2448 | { | |
2449 | switch (args->event) { | |
2450 | case NB_EV_VALIDATE: | |
2451 | case NB_EV_PREPARE: | |
2452 | case NB_EV_ABORT: | |
2453 | break; | |
2454 | case NB_EV_APPLY: | |
2455 | return lib_route_map_entry_set_destroy(args); | |
2456 | } | |
2457 | ||
2458 | return NB_OK; | |
2459 | } | |
2460 | ||
48cb7ea9 SP |
2461 | /* |
2462 | * XPath: | |
2463 | * /frr-route-map:lib/route-map/entry/set-action/rmap-set-action/frr-bgp-route-map:community-none | |
2464 | */ | |
2465 | int lib_route_map_entry_set_action_rmap_set_action_community_none_modify( | |
2466 | struct nb_cb_modify_args *args) | |
2467 | { | |
2468 | struct routemap_hook_context *rhc; | |
2469 | bool none = false; | |
2470 | int rv; | |
2471 | ||
2472 | switch (args->event) { | |
2473 | case NB_EV_VALIDATE: | |
2474 | case NB_EV_PREPARE: | |
2475 | case NB_EV_ABORT: | |
2476 | break; | |
2477 | case NB_EV_APPLY: | |
2478 | /* Add configuration. */ | |
2479 | rhc = nb_running_get_entry(args->dnode, NULL, true); | |
2480 | none = yang_dnode_get_bool(args->dnode, NULL); | |
2481 | ||
2482 | /* Set destroy information. */ | |
2483 | rhc->rhc_shook = generic_set_delete; | |
2484 | rhc->rhc_rule = "community"; | |
2485 | rhc->rhc_event = RMAP_EVENT_SET_DELETED; | |
2486 | ||
2487 | if (none) { | |
2488 | rv = generic_set_add(rhc->rhc_rmi, "community", | |
2489 | "none", | |
2490 | args->errmsg, args->errmsg_len); | |
2491 | if (rv != CMD_SUCCESS) { | |
2492 | rhc->rhc_shook = NULL; | |
2493 | return NB_ERR_INCONSISTENCY; | |
2494 | } | |
2495 | return NB_OK; | |
2496 | } | |
2497 | ||
2498 | return NB_ERR_INCONSISTENCY; | |
2499 | } | |
2500 | ||
2501 | return NB_OK; | |
2502 | } | |
2503 | ||
2504 | int | |
2505 | lib_route_map_entry_set_action_rmap_set_action_community_none_destroy( | |
2506 | struct nb_cb_destroy_args *args) | |
2507 | { | |
2508 | switch (args->event) { | |
2509 | case NB_EV_VALIDATE: | |
2510 | case NB_EV_PREPARE: | |
2511 | case NB_EV_ABORT: | |
2512 | break; | |
2513 | case NB_EV_APPLY: | |
2514 | return lib_route_map_entry_set_destroy(args); | |
2515 | } | |
2516 | ||
2517 | return NB_OK; | |
2518 | } | |
2519 | ||
2520 | /* | |
2521 | * XPath: | |
2522 | * /frr-route-map:lib/route-map/entry/set-action/rmap-set-action/frr-bgp-route-map:community-string | |
2523 | */ | |
2524 | int | |
2525 | lib_route_map_entry_set_action_rmap_set_action_community_string_modify( | |
2526 | struct nb_cb_modify_args *args) | |
2527 | { | |
2528 | struct routemap_hook_context *rhc; | |
2529 | const char *type; | |
2530 | int rv; | |
2531 | ||
2532 | switch (args->event) { | |
2533 | case NB_EV_VALIDATE: | |
2534 | case NB_EV_PREPARE: | |
2535 | case NB_EV_ABORT: | |
2536 | break; | |
2537 | case NB_EV_APPLY: | |
2538 | /* Add configuration. */ | |
2539 | rhc = nb_running_get_entry(args->dnode, NULL, true); | |
2540 | type = yang_dnode_get_string(args->dnode, NULL); | |
2541 | ||
2542 | /* Set destroy information. */ | |
2543 | rhc->rhc_shook = generic_set_delete; | |
2544 | rhc->rhc_rule = "community"; | |
2545 | rhc->rhc_event = RMAP_EVENT_SET_DELETED; | |
2546 | ||
2547 | rv = generic_set_add(rhc->rhc_rmi, "community", type, | |
2548 | args->errmsg, args->errmsg_len); | |
2549 | if (rv != CMD_SUCCESS) { | |
2550 | rhc->rhc_shook = NULL; | |
2551 | return NB_ERR_INCONSISTENCY; | |
2552 | } | |
2553 | } | |
2554 | ||
2555 | return NB_OK; | |
2556 | } | |
2557 | ||
2558 | int | |
2559 | lib_route_map_entry_set_action_rmap_set_action_community_string_destroy( | |
2560 | struct nb_cb_destroy_args *args) | |
2561 | { | |
2562 | switch (args->event) { | |
2563 | case NB_EV_VALIDATE: | |
2564 | case NB_EV_PREPARE: | |
2565 | case NB_EV_ABORT: | |
2566 | break; | |
2567 | case NB_EV_APPLY: | |
2568 | return lib_route_map_entry_set_destroy(args); | |
2569 | } | |
2570 | ||
2571 | return NB_OK; | |
2572 | } | |
2573 | ||
2574 | /* | |
2575 | * XPath: | |
2576 | * /frr-route-map:lib/route-map/entry/set-action/rmap-set-action/frr-bgp-route-map:large-community-none | |
2577 | */ | |
2578 | int | |
2579 | lib_route_map_entry_set_action_rmap_set_action_large_community_none_modify( | |
2580 | struct nb_cb_modify_args *args) | |
2581 | { | |
2582 | struct routemap_hook_context *rhc; | |
2583 | bool none = false; | |
2584 | int rv; | |
2585 | ||
2586 | switch (args->event) { | |
2587 | case NB_EV_VALIDATE: | |
2588 | case NB_EV_PREPARE: | |
2589 | case NB_EV_ABORT: | |
2590 | break; | |
2591 | case NB_EV_APPLY: | |
2592 | /* Add configuration. */ | |
2593 | rhc = nb_running_get_entry(args->dnode, NULL, true); | |
2594 | none = yang_dnode_get_bool(args->dnode, NULL); | |
2595 | ||
2596 | /* Set destroy information. */ | |
2597 | rhc->rhc_shook = generic_set_delete; | |
2598 | rhc->rhc_rule = "large-community"; | |
2599 | rhc->rhc_event = RMAP_EVENT_SET_DELETED; | |
2600 | ||
2601 | if (none) { | |
2602 | rv = generic_set_add(rhc->rhc_rmi, | |
2603 | "large-community", | |
2604 | "none", | |
2605 | args->errmsg, args->errmsg_len); | |
2606 | if (rv != CMD_SUCCESS) { | |
2607 | rhc->rhc_shook = NULL; | |
2608 | return NB_ERR_INCONSISTENCY; | |
2609 | } | |
2610 | return NB_OK; | |
2611 | } | |
2612 | ||
2613 | return NB_ERR_INCONSISTENCY; | |
2614 | } | |
2615 | ||
2616 | return NB_OK; | |
2617 | } | |
2618 | ||
2619 | int | |
2620 | lib_route_map_entry_set_action_rmap_set_action_large_community_none_destroy( | |
2621 | struct nb_cb_destroy_args *args) | |
2622 | { | |
2623 | switch (args->event) { | |
2624 | case NB_EV_VALIDATE: | |
2625 | case NB_EV_PREPARE: | |
2626 | case NB_EV_ABORT: | |
2627 | break; | |
2628 | case NB_EV_APPLY: | |
2629 | return lib_route_map_entry_set_destroy(args); | |
2630 | } | |
2631 | ||
2632 | return NB_OK; | |
2633 | } | |
2634 | ||
2635 | /* | |
2636 | * XPath: | |
2637 | * /frr-route-map:lib/route-map/entry/set-action/rmap-set-action/frr-bgp-route-map:large-community-string | |
2638 | */ | |
2639 | int | |
2640 | lib_route_map_entry_set_action_rmap_set_action_large_community_string_modify( | |
2641 | struct nb_cb_modify_args *args) | |
2642 | { | |
2643 | struct routemap_hook_context *rhc; | |
2644 | const char *type; | |
2645 | int rv; | |
2646 | ||
2647 | switch (args->event) { | |
2648 | case NB_EV_VALIDATE: | |
2649 | case NB_EV_PREPARE: | |
2650 | case NB_EV_ABORT: | |
2651 | break; | |
2652 | case NB_EV_APPLY: | |
2653 | /* Add configuration. */ | |
2654 | rhc = nb_running_get_entry(args->dnode, NULL, true); | |
2655 | type = yang_dnode_get_string(args->dnode, NULL); | |
2656 | ||
2657 | /* Set destroy information. */ | |
2658 | rhc->rhc_shook = generic_set_delete; | |
2659 | rhc->rhc_rule = "large-community"; | |
2660 | rhc->rhc_event = RMAP_EVENT_SET_DELETED; | |
2661 | ||
2662 | rv = generic_set_add(rhc->rhc_rmi, "large-community", | |
2663 | type, | |
2664 | args->errmsg, args->errmsg_len); | |
2665 | if (rv != CMD_SUCCESS) { | |
2666 | rhc->rhc_shook = NULL; | |
2667 | return NB_ERR_INCONSISTENCY; | |
2668 | } | |
2669 | } | |
2670 | ||
2671 | return NB_OK; | |
2672 | } | |
2673 | ||
2674 | int | |
2675 | lib_route_map_entry_set_action_rmap_set_action_large_community_string_destroy( | |
2676 | struct nb_cb_destroy_args *args) | |
2677 | { | |
2678 | switch (args->event) { | |
2679 | case NB_EV_VALIDATE: | |
2680 | case NB_EV_PREPARE: | |
2681 | case NB_EV_ABORT: | |
2682 | break; | |
2683 | case NB_EV_APPLY: | |
2684 | return lib_route_map_entry_set_destroy(args); | |
2685 | } | |
2686 | ||
2687 | return NB_OK; | |
2688 | } | |
2689 | ||
2690 | /* | |
2691 | * xpath = | |
2692 | * /frr-route-map:lib/route-map/entry/set-action/rmap-set-action/frr-bgp-route-map:aggregator | |
2693 | */ | |
2694 | void lib_route_map_entry_set_action_rmap_set_action_aggregator_finish( | |
2695 | struct nb_cb_apply_finish_args *args) | |
2696 | { | |
2697 | struct routemap_hook_context *rhc; | |
2698 | const char *asn; | |
2699 | const char *addr; | |
2700 | char *argstr; | |
16b398fa | 2701 | int ret; |
48cb7ea9 SP |
2702 | |
2703 | /* Add configuration. */ | |
2704 | rhc = nb_running_get_entry(args->dnode, NULL, true); | |
2705 | asn = yang_dnode_get_string(args->dnode, "./aggregator-asn"); | |
2706 | addr = yang_dnode_get_string(args->dnode, "./aggregator-address"); | |
2707 | ||
2708 | argstr = XMALLOC(MTYPE_ROUTE_MAP_COMPILED, | |
2709 | strlen(asn) + strlen(addr) + 2); | |
2710 | ||
2711 | snprintf(argstr, (strlen(asn) + strlen(addr) + 2), "%s %s", asn, addr); | |
2712 | ||
2713 | /* Set destroy information. */ | |
2714 | rhc->rhc_shook = generic_set_delete; | |
2715 | rhc->rhc_rule = "aggregator as"; | |
2716 | rhc->rhc_event = RMAP_EVENT_SET_DELETED; | |
2717 | ||
16b398fa DS |
2718 | ret = generic_set_add(rhc->rhc_rmi, rhc->rhc_rule, argstr, args->errmsg, |
2719 | args->errmsg_len); | |
2720 | /* | |
2721 | * At this point if this is not a successful operation | |
2722 | * bgpd is about to crash. Let's just cut to the | |
2723 | * chase and do it. | |
2724 | */ | |
2725 | assert(ret == CMD_SUCCESS); | |
2726 | ||
48cb7ea9 SP |
2727 | XFREE(MTYPE_ROUTE_MAP_COMPILED, argstr); |
2728 | } | |
2729 | /* | |
2730 | * XPath: | |
2731 | * /frr-route-map:lib/route-map/entry/set-action/rmap-set-action/frr-bgp-route-map:aggregator/aggregator-asn | |
2732 | */ | |
2733 | int | |
2734 | lib_route_map_entry_set_action_rmap_set_action_aggregator_aggregator_asn_modify( | |
2735 | struct nb_cb_modify_args *args) | |
2736 | { | |
5b498ae7 | 2737 | const char *asn; |
2738 | enum match_type match; | |
2739 | ||
48cb7ea9 SP |
2740 | switch (args->event) { |
2741 | case NB_EV_VALIDATE: | |
5b498ae7 | 2742 | asn = yang_dnode_get_string(args->dnode, NULL); |
2743 | if (!asn) | |
2744 | return NB_ERR_VALIDATION; | |
2745 | match = asn_str2asn_match(asn); | |
2746 | if (match == exact_match) | |
2747 | return NB_OK; | |
2748 | return NB_ERR_VALIDATION; | |
48cb7ea9 SP |
2749 | case NB_EV_PREPARE: |
2750 | case NB_EV_ABORT: | |
2751 | case NB_EV_APPLY: | |
2752 | break; | |
2753 | } | |
2754 | ||
2755 | return NB_OK; | |
2756 | } | |
2757 | ||
2758 | int | |
2759 | lib_route_map_entry_set_action_rmap_set_action_aggregator_aggregator_asn_destroy( | |
2760 | struct nb_cb_destroy_args *args) | |
2761 | { | |
2762 | switch (args->event) { | |
2763 | case NB_EV_VALIDATE: | |
2764 | case NB_EV_PREPARE: | |
2765 | case NB_EV_ABORT: | |
2766 | break; | |
2767 | case NB_EV_APPLY: | |
2768 | return lib_route_map_entry_set_destroy(args); | |
2769 | } | |
2770 | ||
2771 | return NB_OK; | |
2772 | } | |
2773 | ||
2774 | /* | |
2775 | * XPath: | |
2776 | * /frr-route-map:lib/route-map/entry/set-action/rmap-set-action/frr-bgp-route-map:aggregator/aggregator-address | |
2777 | */ | |
2778 | int | |
2779 | lib_route_map_entry_set_action_rmap_set_action_aggregator_aggregator_address_modify( | |
2780 | struct nb_cb_modify_args *args) | |
2781 | { | |
2782 | switch (args->event) { | |
2783 | case NB_EV_VALIDATE: | |
2784 | case NB_EV_PREPARE: | |
2785 | case NB_EV_ABORT: | |
2786 | case NB_EV_APPLY: | |
2787 | break; | |
2788 | } | |
2789 | ||
2790 | return NB_OK; | |
2791 | } | |
2792 | ||
2793 | int | |
2794 | lib_route_map_entry_set_action_rmap_set_action_aggregator_aggregator_address_destroy( | |
2795 | struct nb_cb_destroy_args *args) | |
2796 | { | |
2797 | switch (args->event) { | |
2798 | case NB_EV_VALIDATE: | |
2799 | case NB_EV_PREPARE: | |
2800 | case NB_EV_ABORT: | |
2801 | break; | |
2802 | case NB_EV_APPLY: | |
2803 | return lib_route_map_entry_set_destroy(args); | |
2804 | } | |
2805 | ||
2806 | return NB_OK; | |
2807 | } | |
2808 | ||
2809 | /* | |
2810 | * XPath: | |
2811 | * /frr-route-map:lib/route-map/entry/set-action/rmap-set-action/frr-bgp-route-map:comm-list-name | |
2812 | */ | |
2813 | int lib_route_map_entry_set_action_rmap_set_action_comm_list_name_modify( | |
2814 | struct nb_cb_modify_args *args) | |
2815 | { | |
2816 | struct routemap_hook_context *rhc; | |
2817 | const char *value; | |
2818 | const char *action; | |
2819 | int rv = CMD_SUCCESS; | |
2820 | ||
2821 | switch (args->event) { | |
2822 | case NB_EV_VALIDATE: | |
2823 | case NB_EV_PREPARE: | |
2824 | case NB_EV_ABORT: | |
2825 | break; | |
2826 | case NB_EV_APPLY: | |
2827 | /* Add configuration. */ | |
2828 | rhc = nb_running_get_entry(args->dnode, NULL, true); | |
2829 | value = yang_dnode_get_string(args->dnode, NULL); | |
2830 | ||
2831 | /* Set destroy information. */ | |
2832 | rhc->rhc_shook = generic_set_delete; | |
2833 | ||
2834 | action = yang_dnode_get_string(args->dnode, | |
2835 | "../../frr-route-map:action"); | |
2836 | if (IS_SET_COMM_LIST_DEL(action)) | |
2837 | rhc->rhc_rule = "comm-list"; | |
2838 | else | |
2839 | rhc->rhc_rule = "large-comm-list"; | |
2840 | ||
2841 | rhc->rhc_event = RMAP_EVENT_SET_DELETED; | |
2842 | ||
2843 | rv = generic_set_add(rhc->rhc_rmi, rhc->rhc_rule, value, | |
2844 | args->errmsg, args->errmsg_len); | |
2845 | ||
2846 | if (rv != CMD_SUCCESS) { | |
2847 | rhc->rhc_shook = NULL; | |
2848 | return NB_ERR_INCONSISTENCY; | |
2849 | } | |
2850 | } | |
2851 | ||
2852 | return NB_OK; | |
2853 | } | |
2854 | ||
2855 | int | |
2856 | lib_route_map_entry_set_action_rmap_set_action_comm_list_name_destroy( | |
2857 | struct nb_cb_destroy_args *args) | |
2858 | { | |
2859 | switch (args->event) { | |
2860 | case NB_EV_VALIDATE: | |
2861 | case NB_EV_PREPARE: | |
2862 | case NB_EV_ABORT: | |
2863 | break; | |
2864 | case NB_EV_APPLY: | |
2865 | return lib_route_map_entry_set_destroy(args); | |
2866 | } | |
2867 | ||
2868 | return NB_OK; | |
2869 | } | |
2870 | ||
48cb7ea9 SP |
2871 | /* |
2872 | * XPath: | |
2873 | * /frr-route-map:lib/route-map/entry/set-action/rmap-set-action/frr-bgp-route-map:extcommunity-lb | |
2874 | */ | |
2875 | void | |
2876 | lib_route_map_entry_set_action_rmap_set_action_extcommunity_lb_finish( | |
2877 | struct nb_cb_apply_finish_args *args) | |
2878 | { | |
2879 | struct routemap_hook_context *rhc; | |
71bdae66 | 2880 | enum ecommunity_lb_type lb_type; |
48cb7ea9 SP |
2881 | char str[VTY_BUFSIZ]; |
2882 | uint16_t bandwidth; | |
16b398fa | 2883 | int ret; |
48cb7ea9 SP |
2884 | |
2885 | /* Add configuration. */ | |
2886 | rhc = nb_running_get_entry(args->dnode, NULL, true); | |
2887 | lb_type = yang_dnode_get_enum(args->dnode, "./lb-type"); | |
2888 | ||
2889 | /* Set destroy information. */ | |
2890 | rhc->rhc_shook = generic_set_delete; | |
2891 | rhc->rhc_rule = "extcommunity bandwidth"; | |
2892 | rhc->rhc_event = RMAP_EVENT_SET_DELETED; | |
2893 | ||
2894 | switch (lb_type) { | |
2895 | case EXPLICIT_BANDWIDTH: | |
2896 | bandwidth = yang_dnode_get_uint16(args->dnode, "./bandwidth"); | |
2897 | snprintf(str, sizeof(str), "%d", bandwidth); | |
2898 | break; | |
2899 | case CUMULATIVE_BANDWIDTH: | |
2900 | snprintf(str, sizeof(str), "%s", "cumulative"); | |
2901 | break; | |
2902 | case COMPUTED_BANDWIDTH: | |
2903 | snprintf(str, sizeof(str), "%s", "num-multipaths"); | |
2904 | } | |
2905 | ||
2906 | if (yang_dnode_get_bool(args->dnode, "./two-octet-as-specific")) | |
2907 | strlcat(str, " non-transitive", sizeof(str)); | |
2908 | ||
16b398fa DS |
2909 | ret = generic_set_add(rhc->rhc_rmi, "extcommunity bandwidth", str, |
2910 | args->errmsg, args->errmsg_len); | |
2911 | /* | |
2912 | * At this point if this is not a successful operation | |
2913 | * bgpd is about to crash. Let's just cut to the | |
2914 | * chase and do it. | |
2915 | */ | |
2916 | assert(ret == CMD_SUCCESS); | |
48cb7ea9 SP |
2917 | } |
2918 | ||
2919 | /* | |
2920 | * XPath: | |
2921 | * /frr-route-map:lib/route-map/entry/set-action/rmap-set-action/frr-bgp-route-map:extcommunity-lb/lb-type | |
2922 | */ | |
2923 | int | |
2924 | lib_route_map_entry_set_action_rmap_set_action_extcommunity_lb_lb_type_modify( | |
2925 | struct nb_cb_modify_args *args) | |
2926 | { | |
2927 | return NB_OK; | |
2928 | } | |
2929 | ||
2930 | int | |
2931 | lib_route_map_entry_set_action_rmap_set_action_extcommunity_lb_lb_type_destroy( | |
2932 | struct nb_cb_destroy_args *args) | |
2933 | { | |
2934 | return lib_route_map_entry_set_destroy(args); | |
2935 | } | |
2936 | ||
2937 | /* | |
2938 | * XPath: | |
2939 | * /frr-route-map:lib/route-map/entry/set-action/rmap-set-action/frr-bgp-route-map:extcommunity-lb/bandwidth | |
2940 | */ | |
2941 | int | |
2942 | lib_route_map_entry_set_action_rmap_set_action_extcommunity_lb_bandwidth_modify( | |
2943 | struct nb_cb_modify_args *args) | |
2944 | { | |
2945 | return NB_OK; | |
2946 | } | |
2947 | ||
2948 | int | |
2949 | lib_route_map_entry_set_action_rmap_set_action_extcommunity_lb_bandwidth_destroy( | |
2950 | struct nb_cb_destroy_args *args) | |
2951 | { | |
2952 | return lib_route_map_entry_set_destroy(args); | |
2953 | } | |
2954 | ||
2955 | /* | |
2956 | * XPath: | |
2957 | * /frr-route-map:lib/route-map/entry/set-action/rmap-set-action/frr-bgp-route-map:extcommunity-lb/two-octet-as-specific | |
2958 | */ | |
2959 | int | |
2960 | lib_route_map_entry_set_action_rmap_set_action_extcommunity_lb_two_octet_as_specific_modify( | |
2961 | struct nb_cb_modify_args *args) | |
2962 | { | |
2963 | return NB_OK; | |
2964 | } | |
2965 | ||
2966 | int | |
2967 | lib_route_map_entry_set_action_rmap_set_action_extcommunity_lb_two_octet_as_specific_destroy( | |
2968 | struct nb_cb_destroy_args *args) | |
2969 | { | |
2970 | return lib_route_map_entry_set_destroy(args); | |
2971 | } | |
d0a4ee60 | 2972 | |
bb4dcdd1 DA |
2973 | /* |
2974 | * XPath: | |
2975 | * /frr-route-map:lib/route-map/entry/set-action/rmap-set-action/frr-bgp-route-map:extcommunity-none | |
2976 | */ | |
2977 | int lib_route_map_entry_set_action_rmap_set_action_extcommunity_none_modify( | |
2978 | struct nb_cb_modify_args *args) | |
2979 | { | |
2980 | struct routemap_hook_context *rhc; | |
2981 | bool none = false; | |
2982 | int rv; | |
2983 | ||
2984 | switch (args->event) { | |
2985 | case NB_EV_VALIDATE: | |
2986 | case NB_EV_PREPARE: | |
2987 | case NB_EV_ABORT: | |
2988 | break; | |
2989 | case NB_EV_APPLY: | |
2990 | /* Add configuration. */ | |
2991 | rhc = nb_running_get_entry(args->dnode, NULL, true); | |
2992 | none = yang_dnode_get_bool(args->dnode, NULL); | |
2993 | ||
2994 | /* Set destroy information. */ | |
2995 | rhc->rhc_shook = generic_set_delete; | |
2996 | rhc->rhc_rule = "extcommunity"; | |
2997 | rhc->rhc_event = RMAP_EVENT_SET_DELETED; | |
2998 | ||
2999 | if (none) { | |
3000 | rv = generic_set_add(rhc->rhc_rmi, "extcommunity", | |
3001 | "none", args->errmsg, | |
3002 | args->errmsg_len); | |
3003 | if (rv != CMD_SUCCESS) { | |
3004 | rhc->rhc_shook = NULL; | |
3005 | return NB_ERR_INCONSISTENCY; | |
3006 | } | |
3007 | return NB_OK; | |
3008 | } | |
3009 | ||
3010 | return NB_ERR_INCONSISTENCY; | |
3011 | } | |
3012 | ||
3013 | return NB_OK; | |
3014 | } | |
3015 | ||
3016 | int lib_route_map_entry_set_action_rmap_set_action_extcommunity_none_destroy( | |
3017 | struct nb_cb_destroy_args *args) | |
3018 | { | |
3019 | switch (args->event) { | |
3020 | case NB_EV_VALIDATE: | |
3021 | case NB_EV_PREPARE: | |
3022 | case NB_EV_ABORT: | |
3023 | break; | |
3024 | case NB_EV_APPLY: | |
3025 | return lib_route_map_entry_set_destroy(args); | |
3026 | } | |
3027 | ||
3028 | return NB_OK; | |
3029 | } | |
3030 | ||
d0a4ee60 AD |
3031 | /* |
3032 | * XPath: | |
3033 | * /frr-route-map:lib/route-map/entry/set-action/rmap-set-action/frr-bgp-route-map:evpn-gateway-ip-ipv4 | |
3034 | */ | |
3035 | int lib_route_map_entry_set_action_rmap_set_action_evpn_gateway_ip_ipv4_modify( | |
3036 | struct nb_cb_modify_args *args) | |
3037 | { | |
3038 | struct routemap_hook_context *rhc; | |
3039 | const char *type; | |
3040 | int rv; | |
3041 | ||
3042 | switch (args->event) { | |
3043 | case NB_EV_VALIDATE: | |
3044 | case NB_EV_PREPARE: | |
3045 | case NB_EV_ABORT: | |
3046 | break; | |
3047 | case NB_EV_APPLY: | |
3048 | /* Add configuration. */ | |
3049 | rhc = nb_running_get_entry(args->dnode, NULL, true); | |
3050 | type = yang_dnode_get_string(args->dnode, NULL); | |
3051 | ||
3052 | /* Set destroy information. */ | |
3053 | rhc->rhc_shook = generic_set_delete; | |
3054 | rhc->rhc_rule = "evpn gateway-ip ipv4"; | |
3055 | rhc->rhc_event = RMAP_EVENT_SET_DELETED; | |
3056 | ||
3057 | rv = generic_set_add(rhc->rhc_rmi, "evpn gateway-ip ipv4", type, | |
3058 | args->errmsg, args->errmsg_len); | |
3059 | if (rv != CMD_SUCCESS) { | |
3060 | rhc->rhc_shook = NULL; | |
3061 | return NB_ERR_INCONSISTENCY; | |
3062 | } | |
3063 | } | |
3064 | ||
3065 | return NB_OK; | |
3066 | } | |
3067 | ||
3068 | int lib_route_map_entry_set_action_rmap_set_action_evpn_gateway_ip_ipv4_destroy( | |
3069 | struct nb_cb_destroy_args *args) | |
3070 | { | |
3071 | switch (args->event) { | |
3072 | case NB_EV_VALIDATE: | |
3073 | case NB_EV_PREPARE: | |
3074 | case NB_EV_ABORT: | |
3075 | break; | |
3076 | case NB_EV_APPLY: | |
3077 | return lib_route_map_entry_set_destroy(args); | |
3078 | } | |
3079 | ||
3080 | return NB_OK; | |
3081 | } | |
3082 | ||
3083 | /* | |
3084 | * XPath: | |
3085 | * /frr-route-map:lib/route-map/entry/set-action/rmap-set-action/frr-bgp-route-map:evpn-gateway-ip-ipv6 | |
3086 | */ | |
3087 | int lib_route_map_entry_set_action_rmap_set_action_evpn_gateway_ip_ipv6_modify( | |
3088 | struct nb_cb_modify_args *args) | |
3089 | { | |
3090 | struct routemap_hook_context *rhc; | |
3091 | const char *type; | |
3092 | int rv; | |
3093 | ||
3094 | switch (args->event) { | |
3095 | case NB_EV_VALIDATE: | |
3096 | case NB_EV_PREPARE: | |
3097 | case NB_EV_ABORT: | |
3098 | break; | |
3099 | case NB_EV_APPLY: | |
3100 | /* Add configuration. */ | |
3101 | rhc = nb_running_get_entry(args->dnode, NULL, true); | |
3102 | type = yang_dnode_get_string(args->dnode, NULL); | |
3103 | ||
3104 | /* Set destroy information. */ | |
3105 | rhc->rhc_shook = generic_set_delete; | |
3106 | rhc->rhc_rule = "evpn gateway-ip ipv6"; | |
3107 | rhc->rhc_event = RMAP_EVENT_SET_DELETED; | |
3108 | ||
3109 | rv = generic_set_add(rhc->rhc_rmi, "evpn gateway-ip ipv6", type, | |
3110 | args->errmsg, args->errmsg_len); | |
3111 | if (rv != CMD_SUCCESS) { | |
3112 | rhc->rhc_shook = NULL; | |
3113 | return NB_ERR_INCONSISTENCY; | |
3114 | } | |
3115 | } | |
3116 | ||
3117 | return NB_OK; | |
3118 | } | |
3119 | ||
3120 | int lib_route_map_entry_set_action_rmap_set_action_evpn_gateway_ip_ipv6_destroy( | |
3121 | struct nb_cb_destroy_args *args) | |
3122 | { | |
3123 | switch (args->event) { | |
3124 | case NB_EV_VALIDATE: | |
3125 | case NB_EV_PREPARE: | |
3126 | case NB_EV_ABORT: | |
3127 | break; | |
3128 | case NB_EV_APPLY: | |
3129 | return lib_route_map_entry_set_destroy(args); | |
3130 | } | |
3131 | ||
3132 | return NB_OK; | |
3133 | } | |
1bb550b6 PG |
3134 | |
3135 | /* | |
3136 | * XPath: | |
3137 | * /frr-route-map:lib/route-map/entry/set-action/rmap-set-action/l3vpn-nexthop-encapsulation | |
3138 | */ | |
3139 | int lib_route_map_entry_set_action_rmap_set_action_l3vpn_nexthop_encapsulation_modify( | |
3140 | struct nb_cb_modify_args *args) | |
3141 | { | |
3142 | struct routemap_hook_context *rhc; | |
3143 | const char *type; | |
3144 | int rv; | |
3145 | ||
3146 | switch (args->event) { | |
3147 | case NB_EV_VALIDATE: | |
3148 | case NB_EV_PREPARE: | |
3149 | case NB_EV_ABORT: | |
3150 | break; | |
3151 | case NB_EV_APPLY: | |
3152 | /* Add configuration. */ | |
3153 | rhc = nb_running_get_entry(args->dnode, NULL, true); | |
3154 | type = yang_dnode_get_string(args->dnode, NULL); | |
3155 | ||
3156 | /* Set destroy information. */ | |
3157 | rhc->rhc_shook = generic_set_delete; | |
3158 | rhc->rhc_rule = "l3vpn next-hop encapsulation"; | |
3159 | rhc->rhc_event = RMAP_EVENT_SET_DELETED; | |
3160 | ||
3161 | rv = generic_set_add(rhc->rhc_rmi, | |
3162 | "l3vpn next-hop encapsulation", type, | |
3163 | args->errmsg, args->errmsg_len); | |
3164 | if (rv != CMD_SUCCESS) { | |
3165 | rhc->rhc_shook = NULL; | |
3166 | return NB_ERR_INCONSISTENCY; | |
3167 | } | |
3168 | } | |
3169 | ||
3170 | return NB_OK; | |
3171 | } | |
3172 | ||
3173 | int lib_route_map_entry_set_action_rmap_set_action_l3vpn_nexthop_encapsulation_destroy( | |
3174 | struct nb_cb_destroy_args *args) | |
3175 | { | |
3176 | switch (args->event) { | |
3177 | case NB_EV_VALIDATE: | |
3178 | case NB_EV_PREPARE: | |
3179 | case NB_EV_ABORT: | |
3180 | break; | |
3181 | case NB_EV_APPLY: | |
3182 | return lib_route_map_entry_set_destroy(args); | |
3183 | } | |
3184 | ||
3185 | return NB_OK; | |
3186 | } |