]>
Commit | Line | Data |
---|---|---|
686d244f RZ |
1 | /* |
2 | * Route map northbound implementation. | |
3 | * | |
4 | * Copyright (C) 2019 Network Device Education Foundation, Inc. ("NetDEF") | |
5 | * Rafael Zalamena | |
6 | * | |
7 | * This program is free software; you can redistribute it and/or modify | |
8 | * it under the terms of the GNU General Public License as published by | |
9 | * the Free Software Foundation; either version 2 of the License, or | |
10 | * (at your option) any later version. | |
11 | * | |
12 | * This program is distributed in the hope that it will be useful, | |
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
15 | * GNU General Public License for more details. | |
16 | * | |
17 | * You should have received a copy of the GNU General Public License | |
18 | * along with this program; if not, write to the Free Software | |
19 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA | |
20 | * 02110-1301 USA. | |
21 | */ | |
22 | ||
23 | #include <zebra.h> | |
24 | ||
25 | #include "lib/command.h" | |
26 | #include "lib/log.h" | |
27 | #include "lib/northbound.h" | |
28 | #include "lib/routemap.h" | |
29 | ||
30 | /* | |
31 | * Auxiliary functions to avoid code duplication: | |
32 | * | |
33 | * lib_route_map_entry_set_destroy: unset `set` commands. | |
34 | * lib_route_map_entry_match_destroy: unset `match` commands. | |
35 | */ | |
60ee8be1 | 36 | int lib_route_map_entry_match_destroy(struct nb_cb_destroy_args *args) |
686d244f RZ |
37 | { |
38 | struct routemap_hook_context *rhc; | |
39 | int rv; | |
40 | ||
60ee8be1 | 41 | if (args->event != NB_EV_APPLY) |
686d244f RZ |
42 | return NB_OK; |
43 | ||
60ee8be1 | 44 | rhc = nb_running_get_entry(args->dnode, NULL, true); |
686d244f RZ |
45 | if (rhc->rhc_mhook == NULL) |
46 | return NB_OK; | |
47 | ||
d5d737a2 SP |
48 | rv = rhc->rhc_mhook(rhc->rhc_rmi, rhc->rhc_rule, NULL, |
49 | rhc->rhc_event, | |
50 | args->errmsg, args->errmsg_len); | |
686d244f RZ |
51 | if (rv != CMD_SUCCESS) |
52 | return NB_ERR_INCONSISTENCY; | |
53 | ||
54 | return NB_OK; | |
55 | } | |
56 | ||
60ee8be1 | 57 | int lib_route_map_entry_set_destroy(struct nb_cb_destroy_args *args) |
686d244f RZ |
58 | { |
59 | struct routemap_hook_context *rhc; | |
60 | int rv; | |
61 | ||
60ee8be1 | 62 | if (args->event != NB_EV_APPLY) |
686d244f RZ |
63 | return NB_OK; |
64 | ||
60ee8be1 | 65 | rhc = nb_running_get_entry(args->dnode, NULL, true); |
686d244f RZ |
66 | if (rhc->rhc_shook == NULL) |
67 | return NB_OK; | |
68 | ||
d5d737a2 SP |
69 | rv = rhc->rhc_shook(rhc->rhc_rmi, rhc->rhc_rule, NULL, |
70 | args->errmsg, args->errmsg_len); | |
686d244f RZ |
71 | if (rv != CMD_SUCCESS) |
72 | return NB_ERR_INCONSISTENCY; | |
73 | ||
74 | return NB_OK; | |
75 | } | |
76 | ||
54a35ff4 RZ |
77 | /* |
78 | * Auxiliary hook context list manipulation functions. | |
79 | */ | |
80 | struct routemap_hook_context * | |
81 | routemap_hook_context_insert(struct route_map_index *rmi) | |
82 | { | |
83 | struct routemap_hook_context *rhc; | |
84 | ||
85 | rhc = XCALLOC(MTYPE_TMP, sizeof(*rhc)); | |
86 | rhc->rhc_rmi = rmi; | |
87 | TAILQ_INSERT_TAIL(&rmi->rhclist, rhc, rhc_entry); | |
88 | ||
89 | return rhc; | |
90 | } | |
91 | ||
60ee8be1 | 92 | void routemap_hook_context_free(struct routemap_hook_context *rhc) |
54a35ff4 RZ |
93 | { |
94 | struct route_map_index *rmi = rhc->rhc_rmi; | |
95 | ||
96 | TAILQ_REMOVE(&rmi->rhclist, rhc, rhc_entry); | |
97 | XFREE(MTYPE_TMP, rhc); | |
98 | } | |
99 | ||
686d244f RZ |
100 | /* |
101 | * XPath: /frr-route-map:lib/route-map | |
102 | */ | |
60ee8be1 | 103 | static int lib_route_map_create(struct nb_cb_create_args *args) |
686d244f RZ |
104 | { |
105 | struct route_map *rm; | |
106 | const char *rm_name; | |
107 | ||
60ee8be1 | 108 | switch (args->event) { |
686d244f RZ |
109 | case NB_EV_VALIDATE: |
110 | case NB_EV_PREPARE: | |
111 | case NB_EV_ABORT: | |
112 | /* NOTHING */ | |
113 | break; | |
114 | case NB_EV_APPLY: | |
60ee8be1 | 115 | rm_name = yang_dnode_get_string(args->dnode, "./name"); |
686d244f | 116 | rm = route_map_get(rm_name); |
60ee8be1 | 117 | nb_running_set_entry(args->dnode, rm); |
686d244f RZ |
118 | break; |
119 | } | |
120 | ||
121 | return NB_OK; | |
122 | } | |
123 | ||
60ee8be1 | 124 | static int lib_route_map_destroy(struct nb_cb_destroy_args *args) |
686d244f RZ |
125 | { |
126 | struct route_map *rm; | |
127 | ||
60ee8be1 | 128 | switch (args->event) { |
686d244f RZ |
129 | case NB_EV_VALIDATE: |
130 | case NB_EV_PREPARE: | |
131 | case NB_EV_ABORT: | |
132 | /* NOTHING */ | |
133 | break; | |
134 | case NB_EV_APPLY: | |
60ee8be1 | 135 | rm = nb_running_unset_entry(args->dnode); |
686d244f RZ |
136 | route_map_delete(rm); |
137 | break; | |
138 | } | |
139 | ||
140 | return NB_OK; | |
141 | } | |
142 | ||
3ebeec94 IR |
143 | /* |
144 | * XPath: /frr-route-map:lib/route-map/optimization-disabled | |
145 | */ | |
146 | static int | |
147 | lib_route_map_optimization_disabled_modify(struct nb_cb_modify_args *args) | |
148 | { | |
149 | struct route_map *rm; | |
150 | bool disabled = yang_dnode_get_bool(args->dnode, NULL); | |
151 | ||
152 | switch (args->event) { | |
153 | case NB_EV_VALIDATE: | |
154 | case NB_EV_PREPARE: | |
155 | case NB_EV_ABORT: | |
156 | /* NOTHING */ | |
157 | break; | |
158 | case NB_EV_APPLY: | |
159 | rm = nb_running_get_entry(args->dnode, NULL, true); | |
160 | rm->optimization_disabled = disabled; | |
161 | break; | |
162 | } | |
163 | ||
164 | return NB_OK; | |
165 | } | |
166 | ||
686d244f RZ |
167 | /* |
168 | * XPath: /frr-route-map:lib/route-map/entry | |
169 | */ | |
60ee8be1 | 170 | static int lib_route_map_entry_create(struct nb_cb_create_args *args) |
686d244f RZ |
171 | { |
172 | struct route_map_index *rmi; | |
173 | struct route_map *rm; | |
174 | uint16_t sequence; | |
175 | int action; | |
176 | ||
60ee8be1 | 177 | switch (args->event) { |
686d244f RZ |
178 | case NB_EV_VALIDATE: |
179 | case NB_EV_PREPARE: | |
180 | case NB_EV_ABORT: | |
181 | /* NOTHING */ | |
182 | break; | |
183 | case NB_EV_APPLY: | |
60ee8be1 RW |
184 | sequence = yang_dnode_get_uint16(args->dnode, "./sequence"); |
185 | action = yang_dnode_get_enum(args->dnode, "./action") == 0 | |
686d244f RZ |
186 | ? RMAP_PERMIT |
187 | : RMAP_DENY; | |
60ee8be1 | 188 | rm = nb_running_get_entry(args->dnode, NULL, true); |
686d244f | 189 | rmi = route_map_index_get(rm, action, sequence); |
60ee8be1 | 190 | nb_running_set_entry(args->dnode, rmi); |
686d244f RZ |
191 | break; |
192 | } | |
193 | ||
194 | return NB_OK; | |
195 | } | |
196 | ||
60ee8be1 | 197 | static int lib_route_map_entry_destroy(struct nb_cb_destroy_args *args) |
686d244f RZ |
198 | { |
199 | struct route_map_index *rmi; | |
200 | ||
60ee8be1 | 201 | switch (args->event) { |
686d244f RZ |
202 | case NB_EV_VALIDATE: |
203 | case NB_EV_PREPARE: | |
204 | case NB_EV_ABORT: | |
205 | /* NOTHING */ | |
206 | break; | |
207 | case NB_EV_APPLY: | |
60ee8be1 | 208 | rmi = nb_running_unset_entry(args->dnode); |
686d244f RZ |
209 | route_map_index_delete(rmi, 1); |
210 | break; | |
211 | } | |
212 | ||
213 | return NB_OK; | |
214 | } | |
215 | ||
216 | /* | |
217 | * XPath: /frr-route-map:lib/route-map/entry/description | |
218 | */ | |
60ee8be1 RW |
219 | static int |
220 | lib_route_map_entry_description_modify(struct nb_cb_modify_args *args) | |
686d244f RZ |
221 | { |
222 | struct route_map_index *rmi; | |
223 | const char *description; | |
224 | ||
60ee8be1 | 225 | switch (args->event) { |
686d244f RZ |
226 | case NB_EV_VALIDATE: |
227 | /* NOTHING */ | |
228 | break; | |
229 | case NB_EV_PREPARE: | |
60ee8be1 RW |
230 | description = yang_dnode_get_string(args->dnode, NULL); |
231 | args->resource->ptr = XSTRDUP(MTYPE_TMP, description); | |
232 | if (args->resource->ptr == NULL) | |
686d244f RZ |
233 | return NB_ERR_RESOURCE; |
234 | break; | |
235 | case NB_EV_ABORT: | |
60ee8be1 | 236 | XFREE(MTYPE_TMP, args->resource->ptr); |
686d244f RZ |
237 | break; |
238 | case NB_EV_APPLY: | |
60ee8be1 | 239 | rmi = nb_running_get_entry(args->dnode, NULL, true); |
5567e801 | 240 | XFREE(MTYPE_TMP, rmi->description); |
60ee8be1 | 241 | rmi->description = args->resource->ptr; |
686d244f RZ |
242 | break; |
243 | } | |
244 | ||
245 | return NB_OK; | |
246 | } | |
247 | ||
60ee8be1 RW |
248 | static int |
249 | lib_route_map_entry_description_destroy(struct nb_cb_destroy_args *args) | |
686d244f RZ |
250 | { |
251 | struct route_map_index *rmi; | |
252 | ||
60ee8be1 | 253 | switch (args->event) { |
686d244f RZ |
254 | case NB_EV_VALIDATE: |
255 | case NB_EV_PREPARE: | |
256 | case NB_EV_ABORT: | |
257 | /* NOTHING */ | |
258 | break; | |
259 | case NB_EV_APPLY: | |
60ee8be1 | 260 | rmi = nb_running_get_entry(args->dnode, NULL, true); |
ff51421e | 261 | XFREE(MTYPE_TMP, rmi->description); |
686d244f RZ |
262 | break; |
263 | } | |
264 | ||
265 | return NB_OK; | |
266 | } | |
267 | ||
268 | /* | |
269 | * XPath: /frr-route-map:lib/route-map/entry/action | |
270 | */ | |
60ee8be1 | 271 | static int lib_route_map_entry_action_modify(struct nb_cb_modify_args *args) |
686d244f RZ |
272 | { |
273 | struct route_map_index *rmi; | |
4fc5dafd | 274 | struct route_map *map; |
686d244f | 275 | |
60ee8be1 | 276 | switch (args->event) { |
686d244f RZ |
277 | case NB_EV_VALIDATE: |
278 | case NB_EV_PREPARE: | |
279 | case NB_EV_ABORT: | |
280 | /* NOTHING */ | |
281 | break; | |
282 | case NB_EV_APPLY: | |
60ee8be1 RW |
283 | rmi = nb_running_get_entry(args->dnode, NULL, true); |
284 | rmi->type = yang_dnode_get_enum(args->dnode, NULL); | |
4fc5dafd | 285 | map = rmi->map; |
286 | ||
287 | /* Execute event hook. */ | |
288 | if (route_map_master.event_hook) { | |
289 | (*route_map_master.event_hook)(map->name); | |
290 | route_map_notify_dependencies(map->name, | |
291 | RMAP_EVENT_CALL_ADDED); | |
292 | } | |
293 | ||
686d244f RZ |
294 | break; |
295 | } | |
296 | ||
297 | return NB_OK; | |
298 | } | |
299 | ||
300 | /* | |
301 | * XPath: /frr-route-map:lib/route-map/entry/call | |
302 | */ | |
60ee8be1 | 303 | static int lib_route_map_entry_call_modify(struct nb_cb_modify_args *args) |
686d244f RZ |
304 | { |
305 | struct route_map_index *rmi; | |
306 | const char *rm_name, *rmn_name; | |
307 | ||
60ee8be1 | 308 | switch (args->event) { |
686d244f | 309 | case NB_EV_VALIDATE: |
60ee8be1 RW |
310 | rm_name = yang_dnode_get_string(args->dnode, "../../name"); |
311 | rmn_name = yang_dnode_get_string(args->dnode, NULL); | |
686d244f RZ |
312 | /* Don't allow to jump to the same route map instance. */ |
313 | if (strcmp(rm_name, rmn_name) == 0) | |
314 | return NB_ERR_VALIDATION; | |
315 | ||
316 | /* TODO: detect circular route map sequences. */ | |
317 | break; | |
318 | case NB_EV_PREPARE: | |
60ee8be1 RW |
319 | rmn_name = yang_dnode_get_string(args->dnode, NULL); |
320 | args->resource->ptr = XSTRDUP(MTYPE_ROUTE_MAP_NAME, rmn_name); | |
686d244f RZ |
321 | break; |
322 | case NB_EV_ABORT: | |
60ee8be1 | 323 | XFREE(MTYPE_ROUTE_MAP_NAME, args->resource->ptr); |
686d244f RZ |
324 | break; |
325 | case NB_EV_APPLY: | |
60ee8be1 | 326 | rmi = nb_running_get_entry(args->dnode, NULL, true); |
686d244f RZ |
327 | if (rmi->nextrm) { |
328 | route_map_upd8_dependency(RMAP_EVENT_CALL_DELETED, | |
329 | rmi->nextrm, rmi->map->name); | |
330 | XFREE(MTYPE_ROUTE_MAP_NAME, rmi->nextrm); | |
331 | } | |
60ee8be1 | 332 | rmi->nextrm = args->resource->ptr; |
686d244f RZ |
333 | route_map_upd8_dependency(RMAP_EVENT_CALL_ADDED, rmi->nextrm, |
334 | rmi->map->name); | |
335 | break; | |
336 | } | |
337 | ||
338 | return NB_OK; | |
339 | } | |
340 | ||
60ee8be1 | 341 | static int lib_route_map_entry_call_destroy(struct nb_cb_destroy_args *args) |
686d244f RZ |
342 | { |
343 | struct route_map_index *rmi; | |
344 | ||
60ee8be1 | 345 | switch (args->event) { |
686d244f RZ |
346 | case NB_EV_VALIDATE: |
347 | case NB_EV_PREPARE: | |
348 | case NB_EV_ABORT: | |
349 | /* NOTHING */ | |
350 | break; | |
351 | case NB_EV_APPLY: | |
60ee8be1 | 352 | rmi = nb_running_get_entry(args->dnode, NULL, true); |
686d244f RZ |
353 | route_map_upd8_dependency(RMAP_EVENT_CALL_DELETED, rmi->nextrm, |
354 | rmi->map->name); | |
355 | XFREE(MTYPE_ROUTE_MAP_NAME, rmi->nextrm); | |
356 | rmi->nextrm = NULL; | |
357 | break; | |
358 | } | |
359 | ||
360 | return NB_OK; | |
361 | } | |
362 | ||
363 | /* | |
364 | * XPath: /frr-route-map:lib/route-map/entry/exit-policy | |
365 | */ | |
60ee8be1 RW |
366 | static int |
367 | lib_route_map_entry_exit_policy_modify(struct nb_cb_modify_args *args) | |
686d244f RZ |
368 | { |
369 | struct route_map_index *rmi; | |
370 | int rm_action; | |
371 | int policy; | |
372 | ||
60ee8be1 | 373 | switch (args->event) { |
686d244f | 374 | case NB_EV_VALIDATE: |
60ee8be1 | 375 | policy = yang_dnode_get_enum(args->dnode, NULL); |
686d244f RZ |
376 | switch (policy) { |
377 | case 0: /* permit-or-deny */ | |
378 | break; | |
379 | case 1: /* next */ | |
380 | /* FALLTHROUGH */ | |
381 | case 2: /* goto */ | |
60ee8be1 RW |
382 | rm_action = |
383 | yang_dnode_get_enum(args->dnode, "../action"); | |
686d244f RZ |
384 | if (rm_action == 1 /* deny */) { |
385 | /* | |
386 | * On deny it is not possible to 'goto' | |
387 | * anywhere. | |
388 | */ | |
389 | return NB_ERR_VALIDATION; | |
390 | } | |
391 | break; | |
392 | } | |
393 | break; | |
394 | case NB_EV_PREPARE: | |
395 | case NB_EV_ABORT: | |
396 | break; | |
397 | case NB_EV_APPLY: | |
60ee8be1 RW |
398 | rmi = nb_running_get_entry(args->dnode, NULL, true); |
399 | policy = yang_dnode_get_enum(args->dnode, NULL); | |
686d244f RZ |
400 | |
401 | switch (policy) { | |
402 | case 0: /* permit-or-deny */ | |
403 | rmi->exitpolicy = RMAP_EXIT; | |
404 | break; | |
405 | case 1: /* next */ | |
406 | rmi->exitpolicy = RMAP_NEXT; | |
407 | break; | |
408 | case 2: /* goto */ | |
409 | rmi->exitpolicy = RMAP_GOTO; | |
410 | break; | |
411 | } | |
412 | break; | |
413 | } | |
414 | ||
415 | return NB_OK; | |
416 | } | |
417 | ||
418 | /* | |
419 | * XPath: /frr-route-map:lib/route-map/entry/goto-value | |
420 | */ | |
60ee8be1 | 421 | static int lib_route_map_entry_goto_value_modify(struct nb_cb_modify_args *args) |
686d244f RZ |
422 | { |
423 | struct route_map_index *rmi; | |
424 | uint16_t rmi_index; | |
425 | uint16_t rmi_next; | |
426 | ||
60ee8be1 | 427 | switch (args->event) { |
686d244f | 428 | case NB_EV_VALIDATE: |
60ee8be1 RW |
429 | rmi_index = yang_dnode_get_uint16(args->dnode, "../sequence"); |
430 | rmi_next = yang_dnode_get_uint16(args->dnode, NULL); | |
686d244f RZ |
431 | if (rmi_next <= rmi_index) { |
432 | /* Can't jump backwards on a route map. */ | |
433 | return NB_ERR_VALIDATION; | |
434 | } | |
435 | break; | |
436 | case NB_EV_PREPARE: | |
437 | case NB_EV_ABORT: | |
438 | /* NOTHING */ | |
439 | break; | |
440 | case NB_EV_APPLY: | |
60ee8be1 RW |
441 | rmi = nb_running_get_entry(args->dnode, NULL, true); |
442 | rmi->nextpref = yang_dnode_get_uint16(args->dnode, NULL); | |
686d244f RZ |
443 | break; |
444 | } | |
445 | ||
446 | return NB_OK; | |
447 | } | |
448 | ||
60ee8be1 RW |
449 | static int |
450 | lib_route_map_entry_goto_value_destroy(struct nb_cb_destroy_args *args) | |
686d244f RZ |
451 | { |
452 | struct route_map_index *rmi; | |
453 | ||
60ee8be1 | 454 | switch (args->event) { |
686d244f RZ |
455 | case NB_EV_VALIDATE: |
456 | case NB_EV_PREPARE: | |
457 | case NB_EV_ABORT: | |
458 | /* NOTHING */ | |
459 | break; | |
460 | case NB_EV_APPLY: | |
60ee8be1 | 461 | rmi = nb_running_get_entry(args->dnode, NULL, true); |
686d244f RZ |
462 | rmi->nextpref = 0; |
463 | break; | |
464 | } | |
465 | ||
466 | return NB_OK; | |
467 | } | |
468 | ||
469 | /* | |
470 | * XPath: /frr-route-map:lib/route-map/entry/match-condition | |
471 | */ | |
472 | static int | |
60ee8be1 | 473 | lib_route_map_entry_match_condition_create(struct nb_cb_create_args *args) |
686d244f RZ |
474 | { |
475 | struct routemap_hook_context *rhc; | |
54a35ff4 | 476 | struct route_map_index *rmi; |
686d244f | 477 | |
60ee8be1 | 478 | switch (args->event) { |
686d244f | 479 | case NB_EV_VALIDATE: |
686d244f | 480 | case NB_EV_PREPARE: |
686d244f | 481 | case NB_EV_ABORT: |
54a35ff4 | 482 | /* NOTHING */ |
686d244f RZ |
483 | break; |
484 | case NB_EV_APPLY: | |
60ee8be1 | 485 | rmi = nb_running_get_entry(args->dnode, NULL, true); |
54a35ff4 | 486 | rhc = routemap_hook_context_insert(rmi); |
60ee8be1 | 487 | nb_running_set_entry(args->dnode, rhc); |
686d244f RZ |
488 | break; |
489 | } | |
490 | ||
491 | return NB_OK; | |
492 | } | |
493 | ||
494 | static int | |
60ee8be1 | 495 | lib_route_map_entry_match_condition_destroy(struct nb_cb_destroy_args *args) |
686d244f RZ |
496 | { |
497 | struct routemap_hook_context *rhc; | |
498 | int rv; | |
499 | ||
60ee8be1 | 500 | if (args->event != NB_EV_APPLY) |
686d244f RZ |
501 | return NB_OK; |
502 | ||
60ee8be1 RW |
503 | rv = lib_route_map_entry_match_destroy(args); |
504 | rhc = nb_running_unset_entry(args->dnode); | |
54a35ff4 | 505 | routemap_hook_context_free(rhc); |
686d244f RZ |
506 | |
507 | return rv; | |
508 | } | |
509 | ||
510 | /* | |
511 | * XPath: /frr-route-map:lib/route-map/entry/match-condition/interface | |
512 | */ | |
513 | static int lib_route_map_entry_match_condition_interface_modify( | |
60ee8be1 | 514 | struct nb_cb_modify_args *args) |
686d244f RZ |
515 | { |
516 | struct routemap_hook_context *rhc; | |
517 | const char *ifname; | |
518 | int rv; | |
519 | ||
60ee8be1 | 520 | if (args->event != NB_EV_APPLY) |
686d244f RZ |
521 | return NB_OK; |
522 | ||
523 | /* Check for hook function. */ | |
524 | if (rmap_match_set_hook.match_interface == NULL) | |
525 | return NB_OK; | |
526 | ||
527 | /* Add configuration. */ | |
60ee8be1 RW |
528 | rhc = nb_running_get_entry(args->dnode, NULL, true); |
529 | ifname = yang_dnode_get_string(args->dnode, NULL); | |
686d244f RZ |
530 | |
531 | /* Set destroy information. */ | |
532 | rhc->rhc_mhook = rmap_match_set_hook.no_match_interface; | |
533 | rhc->rhc_rule = "interface"; | |
534 | rhc->rhc_event = RMAP_EVENT_MATCH_DELETED; | |
535 | ||
d5d737a2 | 536 | rv = rmap_match_set_hook.match_interface(rhc->rhc_rmi, |
686d244f | 537 | "interface", ifname, |
d5d737a2 SP |
538 | RMAP_EVENT_MATCH_ADDED, |
539 | args->errmsg, args->errmsg_len); | |
686d244f RZ |
540 | if (rv != CMD_SUCCESS) { |
541 | rhc->rhc_mhook = NULL; | |
542 | return NB_ERR_INCONSISTENCY; | |
543 | } | |
544 | ||
545 | return NB_OK; | |
546 | } | |
547 | ||
548 | static int lib_route_map_entry_match_condition_interface_destroy( | |
60ee8be1 | 549 | struct nb_cb_destroy_args *args) |
686d244f | 550 | { |
60ee8be1 | 551 | return lib_route_map_entry_match_destroy(args); |
686d244f RZ |
552 | } |
553 | ||
686d244f RZ |
554 | /* |
555 | * XPath: /frr-route-map:lib/route-map/entry/match-condition/list-name | |
556 | */ | |
557 | static int lib_route_map_entry_match_condition_list_name_modify( | |
60ee8be1 | 558 | struct nb_cb_modify_args *args) |
686d244f RZ |
559 | { |
560 | struct routemap_hook_context *rhc; | |
561 | const char *acl; | |
d5d737a2 | 562 | const char *condition; |
686d244f RZ |
563 | int rv; |
564 | ||
60ee8be1 | 565 | if (args->event != NB_EV_APPLY) |
686d244f RZ |
566 | return NB_OK; |
567 | ||
568 | /* Check for hook installation, otherwise we can just stop. */ | |
60ee8be1 RW |
569 | acl = yang_dnode_get_string(args->dnode, NULL); |
570 | rhc = nb_running_get_entry(args->dnode, NULL, true); | |
d5d737a2 SP |
571 | condition = yang_dnode_get_string(args->dnode, "../../condition"); |
572 | ||
573 | if (IS_MATCH_IPv4_ADDRESS_LIST(condition)) { | |
686d244f RZ |
574 | if (rmap_match_set_hook.match_ip_address == NULL) |
575 | return NB_OK; | |
576 | rhc->rhc_mhook = rmap_match_set_hook.no_match_ip_address; | |
577 | rhc->rhc_rule = "ip address"; | |
578 | rhc->rhc_event = RMAP_EVENT_FILTER_DELETED; | |
579 | rv = rmap_match_set_hook.match_ip_address( | |
d5d737a2 SP |
580 | rhc->rhc_rmi, "ip address", acl, |
581 | RMAP_EVENT_FILTER_ADDED, | |
582 | args->errmsg, args->errmsg_len); | |
583 | } else if (IS_MATCH_IPv4_PREFIX_LIST(condition)) { | |
686d244f RZ |
584 | if (rmap_match_set_hook.match_ip_address_prefix_list == NULL) |
585 | return NB_OK; | |
586 | rhc->rhc_mhook = | |
587 | rmap_match_set_hook.no_match_ip_address_prefix_list; | |
588 | rhc->rhc_rule = "ip address prefix-list"; | |
589 | rhc->rhc_event = RMAP_EVENT_PLIST_DELETED; | |
590 | rv = rmap_match_set_hook.match_ip_address_prefix_list( | |
d5d737a2 SP |
591 | rhc->rhc_rmi, "ip address prefix-list", acl, |
592 | RMAP_EVENT_PLIST_ADDED, | |
593 | args->errmsg, args->errmsg_len); | |
594 | } else if (IS_MATCH_IPv4_NEXTHOP_LIST(condition)) { | |
686d244f RZ |
595 | if (rmap_match_set_hook.match_ip_next_hop == NULL) |
596 | return NB_OK; | |
597 | rhc->rhc_mhook = rmap_match_set_hook.no_match_ip_next_hop; | |
598 | rhc->rhc_rule = "ip next-hop"; | |
599 | rhc->rhc_event = RMAP_EVENT_FILTER_DELETED; | |
600 | rv = rmap_match_set_hook.match_ip_next_hop( | |
d5d737a2 SP |
601 | rhc->rhc_rmi, "ip next-hop", acl, |
602 | RMAP_EVENT_FILTER_ADDED, | |
603 | args->errmsg, args->errmsg_len); | |
604 | } else if (IS_MATCH_IPv4_NEXTHOP_PREFIX_LIST(condition)) { | |
686d244f RZ |
605 | if (rmap_match_set_hook.match_ip_next_hop_prefix_list == NULL) |
606 | return NB_OK; | |
607 | rhc->rhc_mhook = | |
608 | rmap_match_set_hook.no_match_ip_next_hop_prefix_list; | |
609 | rhc->rhc_rule = "ip next-hop prefix-list"; | |
610 | rhc->rhc_event = RMAP_EVENT_PLIST_DELETED; | |
611 | rv = rmap_match_set_hook.match_ip_next_hop_prefix_list( | |
d5d737a2 SP |
612 | rhc->rhc_rmi, "ip next-hop prefix-list", acl, |
613 | RMAP_EVENT_PLIST_ADDED, | |
614 | args->errmsg, args->errmsg_len); | |
615 | } else if (IS_MATCH_IPv6_ADDRESS_LIST(condition)) { | |
686d244f RZ |
616 | if (rmap_match_set_hook.match_ipv6_address == NULL) |
617 | return NB_OK; | |
618 | rhc->rhc_mhook = rmap_match_set_hook.no_match_ipv6_address; | |
619 | rhc->rhc_rule = "ipv6 address"; | |
620 | rhc->rhc_event = RMAP_EVENT_FILTER_DELETED; | |
621 | rv = rmap_match_set_hook.match_ipv6_address( | |
d5d737a2 SP |
622 | rhc->rhc_rmi, "ipv6 address", acl, |
623 | RMAP_EVENT_FILTER_ADDED, | |
624 | args->errmsg, args->errmsg_len); | |
625 | } else if (IS_MATCH_IPv6_PREFIX_LIST(condition)) { | |
686d244f RZ |
626 | if (rmap_match_set_hook.match_ipv6_address_prefix_list == NULL) |
627 | return NB_OK; | |
628 | rhc->rhc_mhook = | |
629 | rmap_match_set_hook.no_match_ipv6_address_prefix_list; | |
630 | rhc->rhc_rule = "ipv6 address prefix-list"; | |
631 | rhc->rhc_event = RMAP_EVENT_PLIST_DELETED; | |
632 | rv = rmap_match_set_hook.match_ipv6_address_prefix_list( | |
d5d737a2 SP |
633 | rhc->rhc_rmi, "ipv6 address prefix-list", acl, |
634 | RMAP_EVENT_PLIST_ADDED, | |
635 | args->errmsg, args->errmsg_len); | |
636 | } else | |
686d244f | 637 | rv = CMD_ERR_NO_MATCH; |
d5d737a2 | 638 | |
686d244f RZ |
639 | if (rv != CMD_SUCCESS) { |
640 | rhc->rhc_mhook = NULL; | |
641 | return NB_ERR_INCONSISTENCY; | |
642 | } | |
643 | ||
644 | return NB_OK; | |
645 | } | |
646 | ||
647 | static int lib_route_map_entry_match_condition_list_name_destroy( | |
60ee8be1 | 648 | struct nb_cb_destroy_args *args) |
686d244f | 649 | { |
60ee8be1 | 650 | return lib_route_map_entry_match_destroy(args); |
686d244f RZ |
651 | } |
652 | ||
653 | /* | |
654 | * XPath: /frr-route-map:lib/route-map/entry/match-condition/ipv4-next-hop-type | |
655 | */ | |
656 | static int lib_route_map_entry_match_condition_ipv4_next_hop_type_modify( | |
60ee8be1 | 657 | struct nb_cb_modify_args *args) |
686d244f RZ |
658 | { |
659 | struct routemap_hook_context *rhc; | |
660 | const char *type; | |
661 | int rv; | |
662 | ||
60ee8be1 | 663 | if (args->event != NB_EV_APPLY) |
686d244f RZ |
664 | return NB_OK; |
665 | ||
666 | /* Check for hook function. */ | |
667 | if (rmap_match_set_hook.match_ip_next_hop_type == NULL) | |
668 | return NB_OK; | |
669 | ||
670 | /* Add configuration. */ | |
60ee8be1 RW |
671 | rhc = nb_running_get_entry(args->dnode, NULL, true); |
672 | type = yang_dnode_get_string(args->dnode, NULL); | |
686d244f RZ |
673 | |
674 | /* Set destroy information. */ | |
675 | rhc->rhc_mhook = rmap_match_set_hook.no_match_ip_next_hop_type; | |
676 | rhc->rhc_rule = "ip next-hop type"; | |
677 | rhc->rhc_event = RMAP_EVENT_MATCH_DELETED; | |
678 | ||
679 | rv = rmap_match_set_hook.match_ip_next_hop_type( | |
d5d737a2 SP |
680 | rhc->rhc_rmi, "ip next-hop type", type, |
681 | RMAP_EVENT_MATCH_ADDED, | |
682 | args->errmsg, args->errmsg_len); | |
686d244f RZ |
683 | if (rv != CMD_SUCCESS) { |
684 | rhc->rhc_mhook = NULL; | |
685 | return NB_ERR_INCONSISTENCY; | |
686 | } | |
687 | ||
688 | return NB_OK; | |
689 | } | |
690 | ||
691 | static int lib_route_map_entry_match_condition_ipv4_next_hop_type_destroy( | |
60ee8be1 | 692 | struct nb_cb_destroy_args *args) |
686d244f | 693 | { |
60ee8be1 | 694 | return lib_route_map_entry_match_destroy(args); |
686d244f RZ |
695 | } |
696 | ||
697 | /* | |
698 | * XPath: /frr-route-map:lib/route-map/entry/match-condition/ipv6-next-hop-type | |
699 | */ | |
700 | static int lib_route_map_entry_match_condition_ipv6_next_hop_type_modify( | |
60ee8be1 | 701 | struct nb_cb_modify_args *args) |
686d244f RZ |
702 | { |
703 | struct routemap_hook_context *rhc; | |
704 | const char *type; | |
705 | int rv; | |
706 | ||
60ee8be1 | 707 | if (args->event != NB_EV_APPLY) |
686d244f RZ |
708 | return NB_OK; |
709 | ||
710 | /* Check for hook function. */ | |
711 | if (rmap_match_set_hook.match_ipv6_next_hop_type == NULL) | |
712 | return NB_OK; | |
713 | ||
714 | /* Add configuration. */ | |
60ee8be1 RW |
715 | rhc = nb_running_get_entry(args->dnode, NULL, true); |
716 | type = yang_dnode_get_string(args->dnode, NULL); | |
686d244f RZ |
717 | |
718 | /* Set destroy information. */ | |
719 | rhc->rhc_mhook = rmap_match_set_hook.no_match_ipv6_next_hop_type; | |
720 | rhc->rhc_rule = "ipv6 next-hop type"; | |
721 | rhc->rhc_event = RMAP_EVENT_MATCH_DELETED; | |
722 | ||
723 | rv = rmap_match_set_hook.match_ipv6_next_hop_type( | |
d5d737a2 SP |
724 | rhc->rhc_rmi, "ipv6 next-hop type", type, |
725 | RMAP_EVENT_MATCH_ADDED, | |
726 | args->errmsg, args->errmsg_len); | |
686d244f RZ |
727 | if (rv != CMD_SUCCESS) { |
728 | rhc->rhc_mhook = NULL; | |
729 | return NB_ERR_INCONSISTENCY; | |
730 | } | |
731 | ||
732 | return NB_OK; | |
733 | } | |
734 | ||
735 | static int lib_route_map_entry_match_condition_ipv6_next_hop_type_destroy( | |
60ee8be1 | 736 | struct nb_cb_destroy_args *args) |
686d244f | 737 | { |
60ee8be1 | 738 | return lib_route_map_entry_match_destroy(args); |
686d244f RZ |
739 | } |
740 | ||
741 | /* | |
742 | * XPath: /frr-route-map:lib/route-map/entry/match-condition/metric | |
743 | */ | |
60ee8be1 RW |
744 | static int lib_route_map_entry_match_condition_metric_modify( |
745 | struct nb_cb_modify_args *args) | |
686d244f RZ |
746 | { |
747 | struct routemap_hook_context *rhc; | |
748 | const char *type; | |
749 | int rv; | |
750 | ||
60ee8be1 | 751 | if (args->event != NB_EV_APPLY) |
686d244f RZ |
752 | return NB_OK; |
753 | ||
754 | /* Check for hook function. */ | |
755 | if (rmap_match_set_hook.match_metric == NULL) | |
756 | return NB_OK; | |
757 | ||
758 | /* Add configuration. */ | |
60ee8be1 RW |
759 | rhc = nb_running_get_entry(args->dnode, NULL, true); |
760 | type = yang_dnode_get_string(args->dnode, NULL); | |
686d244f RZ |
761 | |
762 | /* Set destroy information. */ | |
763 | rhc->rhc_mhook = rmap_match_set_hook.no_match_metric; | |
764 | rhc->rhc_rule = "metric"; | |
765 | rhc->rhc_event = RMAP_EVENT_MATCH_DELETED; | |
766 | ||
d5d737a2 SP |
767 | rv = rmap_match_set_hook.match_metric(rhc->rhc_rmi, "metric", |
768 | type, RMAP_EVENT_MATCH_ADDED, | |
769 | args->errmsg, args->errmsg_len); | |
686d244f RZ |
770 | if (rv != CMD_SUCCESS) { |
771 | rhc->rhc_mhook = NULL; | |
772 | return NB_ERR_INCONSISTENCY; | |
773 | } | |
774 | ||
775 | return NB_OK; | |
776 | } | |
777 | ||
60ee8be1 RW |
778 | static int lib_route_map_entry_match_condition_metric_destroy( |
779 | struct nb_cb_destroy_args *args) | |
686d244f | 780 | { |
60ee8be1 | 781 | return lib_route_map_entry_match_destroy(args); |
686d244f RZ |
782 | } |
783 | ||
784 | /* | |
785 | * XPath: /frr-route-map:lib/route-map/entry/match-condition/tag | |
786 | */ | |
787 | static int | |
60ee8be1 | 788 | lib_route_map_entry_match_condition_tag_modify(struct nb_cb_modify_args *args) |
686d244f RZ |
789 | { |
790 | struct routemap_hook_context *rhc; | |
791 | const char *tag; | |
792 | int rv; | |
793 | ||
60ee8be1 | 794 | if (args->event != NB_EV_APPLY) |
686d244f RZ |
795 | return NB_OK; |
796 | ||
797 | /* Check for hook function. */ | |
798 | if (rmap_match_set_hook.match_tag == NULL) | |
799 | return NB_OK; | |
800 | ||
801 | /* Add configuration. */ | |
60ee8be1 RW |
802 | rhc = nb_running_get_entry(args->dnode, NULL, true); |
803 | tag = yang_dnode_get_string(args->dnode, NULL); | |
686d244f RZ |
804 | |
805 | /* Set destroy information. */ | |
806 | rhc->rhc_mhook = rmap_match_set_hook.no_match_tag; | |
807 | rhc->rhc_rule = "tag"; | |
808 | rhc->rhc_event = RMAP_EVENT_MATCH_DELETED; | |
809 | ||
d5d737a2 SP |
810 | rv = rmap_match_set_hook.match_tag(rhc->rhc_rmi, "tag", tag, |
811 | RMAP_EVENT_MATCH_ADDED, | |
812 | args->errmsg, args->errmsg_len); | |
686d244f RZ |
813 | if (rv != CMD_SUCCESS) { |
814 | rhc->rhc_mhook = NULL; | |
815 | return NB_ERR_INCONSISTENCY; | |
816 | } | |
817 | ||
818 | return NB_OK; | |
819 | } | |
820 | ||
821 | static int | |
60ee8be1 | 822 | lib_route_map_entry_match_condition_tag_destroy(struct nb_cb_destroy_args *args) |
686d244f | 823 | { |
60ee8be1 | 824 | return lib_route_map_entry_match_destroy(args); |
686d244f RZ |
825 | } |
826 | ||
827 | /* | |
828 | * XPath: /frr-route-map:lib/route-map/entry/set-action | |
829 | */ | |
60ee8be1 | 830 | static int lib_route_map_entry_set_action_create(struct nb_cb_create_args *args) |
686d244f | 831 | { |
60ee8be1 | 832 | return lib_route_map_entry_match_condition_create(args); |
686d244f RZ |
833 | } |
834 | ||
60ee8be1 RW |
835 | static int |
836 | lib_route_map_entry_set_action_destroy(struct nb_cb_destroy_args *args) | |
686d244f RZ |
837 | { |
838 | struct routemap_hook_context *rhc; | |
839 | int rv; | |
840 | ||
60ee8be1 | 841 | if (args->event != NB_EV_APPLY) |
686d244f RZ |
842 | return NB_OK; |
843 | ||
60ee8be1 RW |
844 | rv = lib_route_map_entry_set_destroy(args); |
845 | rhc = nb_running_unset_entry(args->dnode); | |
54a35ff4 | 846 | routemap_hook_context_free(rhc); |
686d244f RZ |
847 | |
848 | return rv; | |
849 | } | |
850 | ||
851 | /* | |
852 | * XPath: /frr-route-map:lib/route-map/entry/set-action/ipv4-address | |
853 | */ | |
60ee8be1 RW |
854 | static int lib_route_map_entry_set_action_ipv4_address_modify( |
855 | struct nb_cb_modify_args *args) | |
686d244f RZ |
856 | { |
857 | struct routemap_hook_context *rhc; | |
858 | const char *address; | |
859 | struct in_addr ia; | |
860 | int rv; | |
861 | ||
60ee8be1 | 862 | switch (args->event) { |
686d244f RZ |
863 | case NB_EV_VALIDATE: |
864 | /* | |
865 | * NOTE: validate if 'action' is 'ipv4-next-hop', | |
866 | * currently it is not necessary because this is the | |
867 | * only implemented action. | |
868 | */ | |
60ee8be1 | 869 | yang_dnode_get_ipv4(&ia, args->dnode, NULL); |
975a328e | 870 | if (ia.s_addr == INADDR_ANY || IPV4_CLASS_DE(ntohl(ia.s_addr))) |
686d244f RZ |
871 | return NB_ERR_VALIDATION; |
872 | /* FALLTHROUGH */ | |
873 | case NB_EV_PREPARE: | |
874 | case NB_EV_ABORT: | |
875 | return NB_OK; | |
876 | case NB_EV_APPLY: | |
877 | break; | |
878 | } | |
879 | ||
880 | /* Check for hook function. */ | |
881 | if (rmap_match_set_hook.set_ip_nexthop == NULL) | |
882 | return NB_OK; | |
883 | ||
884 | /* Add configuration. */ | |
60ee8be1 RW |
885 | rhc = nb_running_get_entry(args->dnode, NULL, true); |
886 | address = yang_dnode_get_string(args->dnode, NULL); | |
686d244f RZ |
887 | |
888 | /* Set destroy information. */ | |
889 | rhc->rhc_shook = rmap_match_set_hook.no_set_ip_nexthop; | |
890 | rhc->rhc_rule = "ip next-hop"; | |
891 | ||
d5d737a2 SP |
892 | rv = rmap_match_set_hook.set_ip_nexthop(rhc->rhc_rmi, "ip next-hop", |
893 | address, | |
894 | args->errmsg, args->errmsg_len); | |
686d244f RZ |
895 | if (rv != CMD_SUCCESS) { |
896 | rhc->rhc_shook = NULL; | |
897 | return NB_ERR_INCONSISTENCY; | |
898 | } | |
899 | ||
900 | return NB_OK; | |
901 | } | |
902 | ||
903 | static int lib_route_map_entry_set_action_ipv4_address_destroy( | |
60ee8be1 | 904 | struct nb_cb_destroy_args *args) |
686d244f | 905 | { |
60ee8be1 | 906 | return lib_route_map_entry_set_destroy(args); |
686d244f RZ |
907 | } |
908 | ||
909 | /* | |
910 | * XPath: /frr-route-map:lib/route-map/entry/set-action/ipv6-address | |
911 | */ | |
60ee8be1 RW |
912 | static int lib_route_map_entry_set_action_ipv6_address_modify( |
913 | struct nb_cb_modify_args *args) | |
686d244f RZ |
914 | { |
915 | struct routemap_hook_context *rhc; | |
916 | const char *address; | |
917 | struct in6_addr i6a; | |
918 | int rv; | |
919 | ||
60ee8be1 | 920 | switch (args->event) { |
686d244f RZ |
921 | case NB_EV_VALIDATE: |
922 | /* | |
923 | * NOTE: validate if 'action' is 'ipv6-next-hop', | |
924 | * currently it is not necessary because this is the | |
925 | * only implemented action. Other actions might have | |
926 | * different validations. | |
927 | */ | |
60ee8be1 | 928 | yang_dnode_get_ipv6(&i6a, args->dnode, NULL); |
686d244f RZ |
929 | if (!IN6_IS_ADDR_LINKLOCAL(&i6a)) |
930 | return NB_ERR_VALIDATION; | |
931 | /* FALLTHROUGH */ | |
932 | case NB_EV_PREPARE: | |
933 | case NB_EV_ABORT: | |
934 | return NB_OK; | |
935 | case NB_EV_APPLY: | |
936 | break; | |
937 | } | |
938 | ||
939 | /* Check for hook function. */ | |
940 | if (rmap_match_set_hook.set_ipv6_nexthop_local == NULL) | |
941 | return NB_OK; | |
942 | ||
943 | /* Add configuration. */ | |
60ee8be1 RW |
944 | rhc = nb_running_get_entry(args->dnode, NULL, true); |
945 | address = yang_dnode_get_string(args->dnode, NULL); | |
686d244f RZ |
946 | |
947 | /* Set destroy information. */ | |
948 | rhc->rhc_shook = rmap_match_set_hook.no_set_ipv6_nexthop_local; | |
949 | rhc->rhc_rule = "ipv6 next-hop local"; | |
950 | ||
951 | rv = rmap_match_set_hook.set_ipv6_nexthop_local( | |
d5d737a2 SP |
952 | rhc->rhc_rmi, "ipv6 next-hop local", address, |
953 | args->errmsg, args->errmsg_len); | |
686d244f RZ |
954 | if (rv != CMD_SUCCESS) { |
955 | rhc->rhc_shook = NULL; | |
956 | return NB_ERR_INCONSISTENCY; | |
957 | } | |
958 | ||
959 | return NB_OK; | |
960 | } | |
961 | ||
962 | static int lib_route_map_entry_set_action_ipv6_address_destroy( | |
60ee8be1 | 963 | struct nb_cb_destroy_args *args) |
686d244f | 964 | { |
60ee8be1 | 965 | return lib_route_map_entry_set_destroy(args); |
686d244f RZ |
966 | } |
967 | ||
968 | /* | |
969 | * XPath: /frr-route-map:lib/route-map/entry/set-action/value | |
970 | */ | |
971 | static int set_action_modify(enum nb_event event, const struct lyd_node *dnode, | |
d5d737a2 SP |
972 | union nb_resource *resource, const char *value, |
973 | char *errmsg, size_t errmsg_len) | |
686d244f RZ |
974 | { |
975 | struct routemap_hook_context *rhc; | |
976 | int rv; | |
977 | ||
978 | /* | |
979 | * NOTE: validate if 'action' is 'metric', currently it is not | |
980 | * necessary because this is the only implemented action. Other | |
981 | * actions might have different validations. | |
982 | */ | |
983 | if (event != NB_EV_APPLY) | |
984 | return NB_OK; | |
985 | ||
986 | /* Check for hook function. */ | |
987 | if (rmap_match_set_hook.set_metric == NULL) | |
988 | return NB_OK; | |
989 | ||
990 | /* Add configuration. */ | |
991 | rhc = nb_running_get_entry(dnode, NULL, true); | |
992 | ||
993 | /* Set destroy information. */ | |
994 | rhc->rhc_shook = rmap_match_set_hook.no_set_metric; | |
995 | rhc->rhc_rule = "metric"; | |
996 | ||
d5d737a2 SP |
997 | rv = rmap_match_set_hook.set_metric(rhc->rhc_rmi, "metric", |
998 | value, | |
999 | errmsg, errmsg_len | |
1000 | ); | |
686d244f RZ |
1001 | if (rv != CMD_SUCCESS) { |
1002 | rhc->rhc_shook = NULL; | |
1003 | return NB_ERR_INCONSISTENCY; | |
1004 | } | |
1005 | ||
1006 | return NB_OK; | |
1007 | } | |
1008 | ||
1009 | static int | |
60ee8be1 | 1010 | lib_route_map_entry_set_action_value_modify(struct nb_cb_modify_args *args) |
686d244f | 1011 | { |
60ee8be1 | 1012 | const char *metric = yang_dnode_get_string(args->dnode, NULL); |
686d244f | 1013 | |
60ee8be1 | 1014 | return set_action_modify(args->event, args->dnode, args->resource, |
d5d737a2 | 1015 | metric, args->errmsg, args->errmsg_len); |
686d244f RZ |
1016 | } |
1017 | ||
1018 | static int | |
60ee8be1 | 1019 | lib_route_map_entry_set_action_value_destroy(struct nb_cb_destroy_args *args) |
686d244f | 1020 | { |
60ee8be1 | 1021 | return lib_route_map_entry_set_destroy(args); |
686d244f RZ |
1022 | } |
1023 | ||
1024 | /* | |
1025 | * XPath: /frr-route-map:lib/route-map/entry/set-action/add-metric | |
1026 | */ | |
1027 | static int | |
60ee8be1 | 1028 | lib_route_map_entry_set_action_add_metric_modify(struct nb_cb_modify_args *args) |
686d244f | 1029 | { |
add39cde RW |
1030 | char metric_str[16]; |
1031 | ||
1032 | if (args->event == NB_EV_VALIDATE | |
1033 | && yang_dnode_get_uint32(args->dnode, NULL) == 0) { | |
1034 | snprintf(args->errmsg, args->errmsg_len, | |
1035 | "Can't add zero to metric"); | |
1036 | return NB_ERR_VALIDATION; | |
1037 | } | |
1038 | ||
1039 | snprintf(metric_str, sizeof(metric_str), "+%s", | |
1040 | yang_dnode_get_string(args->dnode, NULL)); | |
60ee8be1 | 1041 | return set_action_modify(args->event, args->dnode, args->resource, |
d5d737a2 SP |
1042 | metric_str, |
1043 | args->errmsg, args->errmsg_len); | |
686d244f RZ |
1044 | } |
1045 | ||
60ee8be1 RW |
1046 | static int lib_route_map_entry_set_action_add_metric_destroy( |
1047 | struct nb_cb_destroy_args *args) | |
686d244f | 1048 | { |
60ee8be1 | 1049 | return lib_route_map_entry_set_action_value_destroy(args); |
686d244f RZ |
1050 | } |
1051 | ||
1052 | /* | |
1053 | * XPath: /frr-route-map:lib/route-map/entry/set-action/subtract-metric | |
1054 | */ | |
1055 | static int lib_route_map_entry_set_action_subtract_metric_modify( | |
60ee8be1 | 1056 | struct nb_cb_modify_args *args) |
686d244f | 1057 | { |
add39cde RW |
1058 | char metric_str[16]; |
1059 | ||
1060 | if (args->event == NB_EV_VALIDATE | |
1061 | && yang_dnode_get_uint32(args->dnode, NULL) == 0) { | |
1062 | snprintf(args->errmsg, args->errmsg_len, | |
1063 | "Can't subtract zero from metric"); | |
1064 | return NB_ERR_VALIDATION; | |
1065 | } | |
1066 | ||
1067 | snprintf(metric_str, sizeof(metric_str), "-%s", | |
1068 | yang_dnode_get_string(args->dnode, NULL)); | |
60ee8be1 | 1069 | return set_action_modify(args->event, args->dnode, args->resource, |
d5d737a2 SP |
1070 | metric_str, |
1071 | args->errmsg, args->errmsg_len); | |
686d244f RZ |
1072 | } |
1073 | ||
1074 | static int lib_route_map_entry_set_action_subtract_metric_destroy( | |
60ee8be1 | 1075 | struct nb_cb_destroy_args *args) |
686d244f | 1076 | { |
60ee8be1 | 1077 | return lib_route_map_entry_set_action_value_destroy(args); |
686d244f RZ |
1078 | } |
1079 | ||
1080 | /* | |
1081 | * XPath: /frr-route-map:lib/route-map/entry/set-action/use-round-trip-time | |
1082 | */ | |
1083 | static int lib_route_map_entry_set_action_use_round_trip_time_modify( | |
60ee8be1 | 1084 | struct nb_cb_modify_args *args) |
686d244f | 1085 | { |
60ee8be1 | 1086 | return set_action_modify(args->event, args->dnode, args->resource, |
d5d737a2 SP |
1087 | "rtt", |
1088 | args->errmsg, args->errmsg_len); | |
686d244f RZ |
1089 | } |
1090 | ||
1091 | static int lib_route_map_entry_set_action_use_round_trip_time_destroy( | |
60ee8be1 | 1092 | struct nb_cb_destroy_args *args) |
686d244f | 1093 | { |
60ee8be1 | 1094 | return lib_route_map_entry_set_action_value_destroy(args); |
686d244f RZ |
1095 | } |
1096 | ||
1097 | /* | |
1098 | * XPath: /frr-route-map:lib/route-map/entry/set-action/add-round-trip-time | |
1099 | */ | |
1100 | static int lib_route_map_entry_set_action_add_round_trip_time_modify( | |
60ee8be1 | 1101 | struct nb_cb_modify_args *args) |
686d244f | 1102 | { |
60ee8be1 | 1103 | return set_action_modify(args->event, args->dnode, args->resource, |
d5d737a2 SP |
1104 | "+rtt", |
1105 | args->errmsg, args->errmsg_len); | |
686d244f RZ |
1106 | } |
1107 | ||
1108 | static int lib_route_map_entry_set_action_add_round_trip_time_destroy( | |
60ee8be1 | 1109 | struct nb_cb_destroy_args *args) |
686d244f | 1110 | { |
60ee8be1 | 1111 | return lib_route_map_entry_set_action_value_destroy(args); |
686d244f RZ |
1112 | } |
1113 | ||
1114 | /* | |
1115 | * XPath: /frr-route-map:lib/route-map/entry/set-action/subtract-round-trip-time | |
1116 | */ | |
1117 | static int lib_route_map_entry_set_action_subtract_round_trip_time_modify( | |
60ee8be1 | 1118 | struct nb_cb_modify_args *args) |
686d244f | 1119 | { |
60ee8be1 | 1120 | return set_action_modify(args->event, args->dnode, args->resource, |
d5d737a2 | 1121 | "-rtt", args->errmsg, args->errmsg_len); |
686d244f RZ |
1122 | } |
1123 | ||
1124 | static int lib_route_map_entry_set_action_subtract_round_trip_time_destroy( | |
60ee8be1 | 1125 | struct nb_cb_destroy_args *args) |
686d244f | 1126 | { |
60ee8be1 | 1127 | return lib_route_map_entry_set_action_value_destroy(args); |
686d244f RZ |
1128 | } |
1129 | ||
1130 | /* | |
1131 | * XPath: /frr-route-map:lib/route-map/entry/set-action/tag | |
1132 | */ | |
1133 | static int | |
60ee8be1 | 1134 | lib_route_map_entry_set_action_tag_modify(struct nb_cb_modify_args *args) |
686d244f RZ |
1135 | { |
1136 | struct routemap_hook_context *rhc; | |
1137 | const char *tag; | |
1138 | int rv; | |
1139 | ||
1140 | /* | |
1141 | * NOTE: validate if 'action' is 'tag', currently it is not | |
1142 | * necessary because this is the only implemented action. Other | |
1143 | * actions might have different validations. | |
1144 | */ | |
60ee8be1 | 1145 | if (args->event != NB_EV_APPLY) |
686d244f RZ |
1146 | return NB_OK; |
1147 | ||
1148 | /* Check for hook function. */ | |
1149 | if (rmap_match_set_hook.set_tag == NULL) | |
1150 | return NB_OK; | |
1151 | ||
1152 | /* Add configuration. */ | |
60ee8be1 RW |
1153 | rhc = nb_running_get_entry(args->dnode, NULL, true); |
1154 | tag = yang_dnode_get_string(args->dnode, NULL); | |
686d244f RZ |
1155 | |
1156 | /* Set destroy information. */ | |
1157 | rhc->rhc_shook = rmap_match_set_hook.no_set_tag; | |
1158 | rhc->rhc_rule = "tag"; | |
1159 | ||
d5d737a2 SP |
1160 | rv = rmap_match_set_hook.set_tag(rhc->rhc_rmi, "tag", tag, |
1161 | args->errmsg, args->errmsg_len); | |
686d244f RZ |
1162 | if (rv != CMD_SUCCESS) { |
1163 | rhc->rhc_shook = NULL; | |
1164 | return NB_ERR_INCONSISTENCY; | |
1165 | } | |
1166 | ||
1167 | return NB_OK; | |
1168 | } | |
1169 | ||
1170 | static int | |
60ee8be1 | 1171 | lib_route_map_entry_set_action_tag_destroy(struct nb_cb_destroy_args *args) |
686d244f | 1172 | { |
60ee8be1 | 1173 | return lib_route_map_entry_set_destroy(args); |
686d244f RZ |
1174 | } |
1175 | ||
d5d737a2 SP |
1176 | /* |
1177 | * XPath: /frr-route-map:lib/route-map/entry/set-action/policy | |
1178 | */ | |
1179 | static int | |
1180 | lib_route_map_entry_set_action_policy_modify(struct nb_cb_modify_args *args) | |
1181 | { | |
1182 | struct routemap_hook_context *rhc; | |
1183 | const char *policy; | |
1184 | int rv; | |
1185 | ||
1186 | /* | |
1187 | * NOTE: validate if 'action' is 'tag', currently it is not | |
1188 | * necessary because this is the only implemented action. Other | |
1189 | * actions might have different validations. | |
1190 | */ | |
1191 | if (args->event != NB_EV_APPLY) | |
1192 | return NB_OK; | |
1193 | ||
1194 | /* Check for hook function. */ | |
1195 | if (rmap_match_set_hook.set_srte_color == NULL) | |
1196 | return NB_OK; | |
1197 | ||
1198 | /* Add configuration. */ | |
1199 | rhc = nb_running_get_entry(args->dnode, NULL, true); | |
1200 | policy = yang_dnode_get_string(args->dnode, NULL); | |
1201 | ||
1202 | /* Set destroy information. */ | |
1203 | rhc->rhc_shook = rmap_match_set_hook.no_set_tag; | |
1204 | rhc->rhc_rule = "sr-te color"; | |
1205 | ||
1206 | rv = rmap_match_set_hook.set_tag(rhc->rhc_rmi, "sr-te color", policy, | |
1207 | args->errmsg, args->errmsg_len); | |
1208 | if (rv != CMD_SUCCESS) { | |
1209 | rhc->rhc_shook = NULL; | |
1210 | return NB_ERR_INCONSISTENCY; | |
1211 | } | |
1212 | ||
1213 | return NB_OK; | |
1214 | } | |
1215 | ||
1216 | static int | |
1217 | lib_route_map_entry_set_action_policy_destroy(struct nb_cb_destroy_args *args) | |
1218 | { | |
1219 | return lib_route_map_entry_set_destroy(args); | |
1220 | } | |
1221 | ||
686d244f RZ |
1222 | /* clang-format off */ |
1223 | const struct frr_yang_module_info frr_route_map_info = { | |
1224 | .name = "frr-route-map", | |
1225 | .nodes = { | |
1226 | { | |
1227 | .xpath = "/frr-route-map:lib/route-map", | |
1228 | .cbs = { | |
1229 | .create = lib_route_map_create, | |
1230 | .destroy = lib_route_map_destroy, | |
1231 | } | |
1232 | }, | |
3ebeec94 IR |
1233 | { |
1234 | .xpath = "/frr-route-map:lib/route-map/optimization-disabled", | |
1235 | .cbs = { | |
1236 | .modify = lib_route_map_optimization_disabled_modify, | |
38133c4a | 1237 | .cli_show = route_map_optimization_disabled_show, |
3ebeec94 IR |
1238 | } |
1239 | }, | |
686d244f RZ |
1240 | { |
1241 | .xpath = "/frr-route-map:lib/route-map/entry", | |
1242 | .cbs = { | |
1243 | .create = lib_route_map_entry_create, | |
1244 | .destroy = lib_route_map_entry_destroy, | |
de8936be | 1245 | .cli_cmp = route_map_instance_cmp, |
2b3e4807 RZ |
1246 | .cli_show = route_map_instance_show, |
1247 | .cli_show_end = route_map_instance_show_end, | |
686d244f RZ |
1248 | } |
1249 | }, | |
1250 | { | |
1251 | .xpath = "/frr-route-map:lib/route-map/entry/description", | |
1252 | .cbs = { | |
1253 | .modify = lib_route_map_entry_description_modify, | |
1254 | .destroy = lib_route_map_entry_description_destroy, | |
2b3e4807 | 1255 | .cli_show = route_map_description_show, |
686d244f RZ |
1256 | } |
1257 | }, | |
1258 | { | |
1259 | .xpath = "/frr-route-map:lib/route-map/entry/action", | |
1260 | .cbs = { | |
1261 | .modify = lib_route_map_entry_action_modify, | |
1262 | } | |
1263 | }, | |
1264 | { | |
1265 | .xpath = "/frr-route-map:lib/route-map/entry/call", | |
1266 | .cbs = { | |
1267 | .modify = lib_route_map_entry_call_modify, | |
1268 | .destroy = lib_route_map_entry_call_destroy, | |
2b3e4807 | 1269 | .cli_show = route_map_call_show, |
686d244f RZ |
1270 | } |
1271 | }, | |
1272 | { | |
1273 | .xpath = "/frr-route-map:lib/route-map/entry/exit-policy", | |
1274 | .cbs = { | |
1275 | .modify = lib_route_map_entry_exit_policy_modify, | |
2b3e4807 | 1276 | .cli_show = route_map_exit_policy_show, |
686d244f RZ |
1277 | } |
1278 | }, | |
1279 | { | |
1280 | .xpath = "/frr-route-map:lib/route-map/entry/goto-value", | |
1281 | .cbs = { | |
1282 | .modify = lib_route_map_entry_goto_value_modify, | |
1283 | .destroy = lib_route_map_entry_goto_value_destroy, | |
1284 | } | |
1285 | }, | |
1286 | { | |
1287 | .xpath = "/frr-route-map:lib/route-map/entry/match-condition", | |
1288 | .cbs = { | |
1289 | .create = lib_route_map_entry_match_condition_create, | |
1290 | .destroy = lib_route_map_entry_match_condition_destroy, | |
2b3e4807 | 1291 | .cli_show = route_map_condition_show, |
686d244f RZ |
1292 | } |
1293 | }, | |
1294 | { | |
d5d737a2 | 1295 | .xpath = "/frr-route-map:lib/route-map/entry/match-condition/rmap-match-condition/interface", |
686d244f RZ |
1296 | .cbs = { |
1297 | .modify = lib_route_map_entry_match_condition_interface_modify, | |
1298 | .destroy = lib_route_map_entry_match_condition_interface_destroy, | |
1299 | } | |
1300 | }, | |
686d244f | 1301 | { |
d5d737a2 | 1302 | .xpath = "/frr-route-map:lib/route-map/entry/match-condition/rmap-match-condition/list-name", |
686d244f RZ |
1303 | .cbs = { |
1304 | .modify = lib_route_map_entry_match_condition_list_name_modify, | |
1305 | .destroy = lib_route_map_entry_match_condition_list_name_destroy, | |
1306 | } | |
1307 | }, | |
1308 | { | |
d5d737a2 | 1309 | .xpath = "/frr-route-map:lib/route-map/entry/match-condition/rmap-match-condition/ipv4-next-hop-type", |
686d244f RZ |
1310 | .cbs = { |
1311 | .modify = lib_route_map_entry_match_condition_ipv4_next_hop_type_modify, | |
1312 | .destroy = lib_route_map_entry_match_condition_ipv4_next_hop_type_destroy, | |
1313 | } | |
1314 | }, | |
1315 | { | |
d5d737a2 | 1316 | .xpath = "/frr-route-map:lib/route-map/entry/match-condition/rmap-match-condition/ipv6-next-hop-type", |
686d244f RZ |
1317 | .cbs = { |
1318 | .modify = lib_route_map_entry_match_condition_ipv6_next_hop_type_modify, | |
1319 | .destroy = lib_route_map_entry_match_condition_ipv6_next_hop_type_destroy, | |
1320 | } | |
1321 | }, | |
1322 | { | |
d5d737a2 | 1323 | .xpath = "/frr-route-map:lib/route-map/entry/match-condition/rmap-match-condition/metric", |
686d244f RZ |
1324 | .cbs = { |
1325 | .modify = lib_route_map_entry_match_condition_metric_modify, | |
1326 | .destroy = lib_route_map_entry_match_condition_metric_destroy, | |
1327 | } | |
1328 | }, | |
1329 | { | |
d5d737a2 | 1330 | .xpath = "/frr-route-map:lib/route-map/entry/match-condition/rmap-match-condition/tag", |
686d244f RZ |
1331 | .cbs = { |
1332 | .modify = lib_route_map_entry_match_condition_tag_modify, | |
1333 | .destroy = lib_route_map_entry_match_condition_tag_destroy, | |
1334 | } | |
1335 | }, | |
1336 | { | |
1337 | .xpath = "/frr-route-map:lib/route-map/entry/set-action", | |
1338 | .cbs = { | |
1339 | .create = lib_route_map_entry_set_action_create, | |
1340 | .destroy = lib_route_map_entry_set_action_destroy, | |
2b3e4807 | 1341 | .cli_show = route_map_action_show, |
686d244f RZ |
1342 | } |
1343 | }, | |
1344 | { | |
d5d737a2 | 1345 | .xpath = "/frr-route-map:lib/route-map/entry/set-action/rmap-set-action/ipv4-address", |
686d244f RZ |
1346 | .cbs = { |
1347 | .modify = lib_route_map_entry_set_action_ipv4_address_modify, | |
1348 | .destroy = lib_route_map_entry_set_action_ipv4_address_destroy, | |
1349 | } | |
1350 | }, | |
1351 | { | |
d5d737a2 | 1352 | .xpath = "/frr-route-map:lib/route-map/entry/set-action/rmap-set-action/ipv6-address", |
686d244f RZ |
1353 | .cbs = { |
1354 | .modify = lib_route_map_entry_set_action_ipv6_address_modify, | |
1355 | .destroy = lib_route_map_entry_set_action_ipv6_address_destroy, | |
1356 | } | |
1357 | }, | |
1358 | { | |
d5d737a2 | 1359 | .xpath = "/frr-route-map:lib/route-map/entry/set-action/rmap-set-action/value", |
686d244f RZ |
1360 | .cbs = { |
1361 | .modify = lib_route_map_entry_set_action_value_modify, | |
1362 | .destroy = lib_route_map_entry_set_action_value_destroy, | |
1363 | } | |
1364 | }, | |
1365 | { | |
d5d737a2 | 1366 | .xpath = "/frr-route-map:lib/route-map/entry/set-action/rmap-set-action/add-metric", |
686d244f RZ |
1367 | .cbs = { |
1368 | .modify = lib_route_map_entry_set_action_add_metric_modify, | |
1369 | .destroy = lib_route_map_entry_set_action_add_metric_destroy, | |
1370 | } | |
1371 | }, | |
1372 | { | |
d5d737a2 | 1373 | .xpath = "/frr-route-map:lib/route-map/entry/set-action/rmap-set-action/subtract-metric", |
686d244f RZ |
1374 | .cbs = { |
1375 | .modify = lib_route_map_entry_set_action_subtract_metric_modify, | |
1376 | .destroy = lib_route_map_entry_set_action_subtract_metric_destroy, | |
1377 | } | |
1378 | }, | |
1379 | { | |
d5d737a2 | 1380 | .xpath = "/frr-route-map:lib/route-map/entry/set-action/rmap-set-action/use-round-trip-time", |
686d244f RZ |
1381 | .cbs = { |
1382 | .modify = lib_route_map_entry_set_action_use_round_trip_time_modify, | |
1383 | .destroy = lib_route_map_entry_set_action_use_round_trip_time_destroy, | |
1384 | } | |
1385 | }, | |
1386 | { | |
d5d737a2 | 1387 | .xpath = "/frr-route-map:lib/route-map/entry/set-action/rmap-set-action/add-round-trip-time", |
686d244f RZ |
1388 | .cbs = { |
1389 | .modify = lib_route_map_entry_set_action_add_round_trip_time_modify, | |
1390 | .destroy = lib_route_map_entry_set_action_add_round_trip_time_destroy, | |
1391 | } | |
1392 | }, | |
1393 | { | |
d5d737a2 | 1394 | .xpath = "/frr-route-map:lib/route-map/entry/set-action/rmap-set-action/subtract-round-trip-time", |
686d244f RZ |
1395 | .cbs = { |
1396 | .modify = lib_route_map_entry_set_action_subtract_round_trip_time_modify, | |
1397 | .destroy = lib_route_map_entry_set_action_subtract_round_trip_time_destroy, | |
1398 | } | |
1399 | }, | |
1400 | { | |
d5d737a2 | 1401 | .xpath = "/frr-route-map:lib/route-map/entry/set-action/rmap-set-action/tag", |
686d244f RZ |
1402 | .cbs = { |
1403 | .modify = lib_route_map_entry_set_action_tag_modify, | |
1404 | .destroy = lib_route_map_entry_set_action_tag_destroy, | |
1405 | } | |
1406 | }, | |
d5d737a2 SP |
1407 | { |
1408 | .xpath = "/frr-route-map:lib/route-map/entry/set-action/rmap-set-action/policy", | |
1409 | .cbs = { | |
1410 | .modify = lib_route_map_entry_set_action_policy_modify, | |
1411 | .destroy = lib_route_map_entry_set_action_policy_destroy, | |
1412 | } | |
1413 | }, | |
1414 | ||
686d244f RZ |
1415 | { |
1416 | .xpath = NULL, | |
1417 | }, | |
1418 | } | |
1419 | }; |