]> git.proxmox.com Git - mirror_frr.git/blob - staticd/static_nb_config.c
Merge pull request #7639 from qlyoung/frr-lua
[mirror_frr.git] / staticd / static_nb_config.c
1 /*
2 * Copyright (C) 2018 Vmware
3 * Vishal Dhingra
4 *
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License as published by the Free
7 * Software Foundation; either version 2 of the License, or (at your option)
8 * any later version.
9 *
10 * This program is distributed in the hope that it will be useful, but WITHOUT
11 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
13 * more details.
14 *
15 * You should have received a copy of the GNU General Public License along
16 * with this program; see the file COPYING; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18 */
19 #include "northbound.h"
20 #include "libfrr.h"
21 #include "log.h"
22 #include "lib_errors.h"
23 #include "prefix.h"
24 #include "table.h"
25 #include "vrf.h"
26 #include "nexthop.h"
27 #include "srcdest_table.h"
28
29 #include "static_vrf.h"
30 #include "static_routes.h"
31 #include "static_nb.h"
32
33
34 static int static_path_list_create(struct nb_cb_create_args *args)
35 {
36 struct route_node *rn;
37 struct static_path *pn;
38 const struct lyd_node *vrf_dnode;
39 const char *vrf;
40 uint8_t distance;
41 uint32_t table_id;
42
43 switch (args->event) {
44 case NB_EV_VALIDATE:
45 vrf_dnode = yang_dnode_get_parent(args->dnode,
46 "control-plane-protocol");
47 vrf = yang_dnode_get_string(vrf_dnode, "./vrf");
48 table_id = yang_dnode_get_uint32(args->dnode, "./table-id");
49
50 /*
51 * TableId is not applicable for VRF. Consider the case of
52 * l3mdev, there is one uint32_t space to work with.
53 * A l3mdev device points at a specific table that it
54 * relates to and a set of interfaces it belongs to.
55 */
56 if (table_id && (strcmp(vrf, vrf_get_default_name()) != 0)
57 && !vrf_is_backend_netns()) {
58 snprintf(
59 args->errmsg, args->errmsg_len,
60 "%% table param only available when running on netns-based vrfs");
61 return NB_ERR_VALIDATION;
62 }
63 break;
64 case NB_EV_ABORT:
65 case NB_EV_PREPARE:
66 break;
67 case NB_EV_APPLY:
68 rn = nb_running_get_entry(args->dnode, NULL, true);
69 distance = yang_dnode_get_uint8(args->dnode, "./distance");
70 table_id = yang_dnode_get_uint32(args->dnode, "./table-id");
71 pn = static_add_path(rn, table_id, distance);
72 nb_running_set_entry(args->dnode, pn);
73 }
74
75 return NB_OK;
76 }
77
78 static void static_path_list_destroy(struct nb_cb_destroy_args *args,
79 const struct lyd_node *rn_dnode,
80 struct stable_info *info)
81 {
82 struct route_node *rn;
83 struct static_path *pn;
84
85 pn = nb_running_unset_entry(args->dnode);
86 rn = nb_running_get_entry(rn_dnode, NULL, true);
87 static_del_path(rn, pn, info->safi, info->svrf);
88 }
89
90 static void static_path_list_tag_modify(struct nb_cb_modify_args *args,
91 const struct lyd_node *rn_dnode,
92 struct stable_info *info)
93 {
94 struct static_path *pn;
95 struct route_node *rn;
96 route_tag_t tag;
97
98 tag = yang_dnode_get_uint32(args->dnode, NULL);
99 pn = nb_running_get_entry(args->dnode, NULL, true);
100 pn->tag = tag;
101 rn = nb_running_get_entry(rn_dnode, NULL, true);
102
103 static_install_path(rn, pn, info->safi, info->svrf);
104 }
105
106 static bool static_nexthop_create(struct nb_cb_create_args *args,
107 const struct lyd_node *rn_dnode,
108 struct stable_info *info)
109 {
110 struct route_node *rn;
111 struct static_path *pn;
112 struct ipaddr ipaddr;
113 struct static_nexthop *nh;
114 int nh_type;
115 const char *ifname;
116 const char *nh_vrf;
117
118 switch (args->event) {
119 case NB_EV_VALIDATE:
120 ifname = yang_dnode_get_string(args->dnode, "./interface");
121 if (ifname != NULL) {
122 if (strcasecmp(ifname, "Null0") == 0
123 || strcasecmp(ifname, "reject") == 0
124 || strcasecmp(ifname, "blackhole") == 0) {
125 snprintf(args->errmsg, args->errmsg_len,
126 "%s: Nexthop interface name can not be from reserved keywords(Null0, reject, blackhole)",
127 ifname);
128 return NB_ERR_VALIDATION;
129 }
130 }
131 break;
132 case NB_EV_PREPARE:
133 case NB_EV_ABORT:
134 break;
135 case NB_EV_APPLY:
136 yang_dnode_get_ip(&ipaddr, args->dnode, "./gateway");
137 nh_type = yang_dnode_get_enum(args->dnode, "./nh-type");
138 ifname = yang_dnode_get_string(args->dnode, "./interface");
139 nh_vrf = yang_dnode_get_string(args->dnode, "./vrf");
140 pn = nb_running_get_entry(args->dnode, NULL, true);
141 rn = nb_running_get_entry(rn_dnode, NULL, true);
142
143 if (!static_add_nexthop_validate(info->svrf, nh_type, &ipaddr))
144 flog_warn(
145 EC_LIB_NB_CB_CONFIG_VALIDATE,
146 "Warning!! Local connected address is configured as Gateway IP((%s))",
147 yang_dnode_get_string(args->dnode,
148 "./gateway"));
149 nh = static_add_nexthop(rn, pn, info->safi, info->svrf, nh_type,
150 &ipaddr, ifname, nh_vrf, 0);
151 if (!nh) {
152 char buf[SRCDEST2STR_BUFFER];
153
154 flog_warn(
155 EC_LIB_NB_CB_CONFIG_APPLY,
156 "%s : nh [%d:%s:%s:%s] nexthop creation failed",
157 srcdest_rnode2str(rn, buf, sizeof(buf)),
158 nh_type, ifname,
159 yang_dnode_get_string(args->dnode, "./gateway"),
160 nh_vrf);
161 return NB_ERR;
162 }
163 nb_running_set_entry(args->dnode, nh);
164 break;
165 }
166
167 return NB_OK;
168 }
169
170 static bool static_nexthop_destroy(struct nb_cb_destroy_args *args,
171 const struct lyd_node *rn_dnode,
172 struct stable_info *info)
173 {
174 struct route_node *rn;
175 struct static_path *pn;
176 const struct lyd_node *pn_dnode;
177 struct static_nexthop *nh;
178 int ret;
179
180 nh = nb_running_unset_entry(args->dnode);
181 pn_dnode = yang_dnode_get_parent(args->dnode, "path-list");
182 pn = nb_running_get_entry(pn_dnode, NULL, true);
183 rn = nb_running_get_entry(rn_dnode, NULL, true);
184
185 ret = static_delete_nexthop(rn, pn, info->safi, info->svrf, nh);
186 if (!ret) {
187 char buf[SRCDEST2STR_BUFFER];
188
189 flog_warn(EC_LIB_NB_CB_CONFIG_APPLY,
190 "%s : nh [%d:%s:%s:%s] nexthop destroy failed",
191 srcdest_rnode2str(rn, buf, sizeof(buf)),
192 yang_dnode_get_enum(args->dnode, "./nh-type"),
193 yang_dnode_get_string(args->dnode, "./interface"),
194 yang_dnode_get_string(args->dnode, "./gateway"),
195 yang_dnode_get_string(args->dnode, "./vrf"));
196 return NB_ERR;
197 }
198
199 return NB_OK;
200 }
201
202 static int nexthop_mpls_label_stack_entry_create(struct nb_cb_create_args *args)
203 {
204 struct static_nexthop *nh;
205 uint32_t pos;
206 uint8_t index;
207
208 switch (args->event) {
209 case NB_EV_VALIDATE:
210 if (!mpls_enabled) {
211 snprintf(
212 args->errmsg, args->errmsg_len,
213 "%% MPLS not turned on in kernel ignoring static route");
214 return NB_ERR_VALIDATION;
215 }
216 break;
217 case NB_EV_PREPARE:
218 case NB_EV_ABORT:
219 break;
220 case NB_EV_APPLY:
221 nh = nb_running_get_entry(args->dnode, NULL, true);
222 pos = yang_get_list_pos(args->dnode);
223 if (!pos) {
224 flog_warn(EC_LIB_NB_CB_CONFIG_APPLY,
225 "libyang returns invalid label position");
226 return NB_ERR;
227 }
228 /* Mapping to array = list-index -1 */
229 index = pos - 1;
230 nh->snh_label.label[index] = 0;
231 nh->snh_label.num_labels++;
232 break;
233 }
234
235 return NB_OK;
236 }
237
238 static int
239 nexthop_mpls_label_stack_entry_destroy(struct nb_cb_destroy_args *args)
240 {
241 struct static_nexthop *nh;
242 uint32_t pos;
243 uint8_t index;
244
245 switch (args->event) {
246 case NB_EV_VALIDATE:
247 case NB_EV_PREPARE:
248 case NB_EV_ABORT:
249 break;
250 case NB_EV_APPLY:
251 nh = nb_running_get_entry(args->dnode, NULL, true);
252 pos = yang_get_list_pos(args->dnode);
253 if (!pos) {
254 flog_warn(EC_LIB_NB_CB_CONFIG_APPLY,
255 "libyang returns invalid label position");
256 return NB_ERR;
257 }
258 index = pos - 1;
259 nh->snh_label.label[index] = 0;
260 nh->snh_label.num_labels--;
261 break;
262 }
263
264 return NB_OK;
265 }
266
267 static int static_nexthop_mpls_label_modify(struct nb_cb_modify_args *args)
268 {
269 struct static_nexthop *nh;
270 uint32_t pos;
271 uint8_t index;
272
273 nh = nb_running_get_entry(args->dnode, NULL, true);
274 pos = yang_get_list_pos(args->dnode->parent);
275 if (!pos) {
276 flog_warn(EC_LIB_NB_CB_CONFIG_APPLY,
277 "libyang returns invalid label position");
278 return NB_ERR;
279 }
280 /* Mapping to array = list-index -1 */
281 index = pos - 1;
282 nh->snh_label.label[index] = yang_dnode_get_uint32(args->dnode, NULL);
283
284 return NB_OK;
285 }
286
287 static int static_nexthop_onlink_modify(struct nb_cb_modify_args *args)
288 {
289 struct static_nexthop *nh;
290
291 nh = nb_running_get_entry(args->dnode, NULL, true);
292 nh->onlink = yang_dnode_get_bool(args->dnode, NULL);
293
294 return NB_OK;
295 }
296
297 static int static_nexthop_color_modify(struct nb_cb_modify_args *args)
298 {
299 struct static_nexthop *nh;
300
301 nh = nb_running_get_entry(args->dnode, NULL, true);
302 nh->color = yang_dnode_get_uint32(args->dnode, NULL);
303
304 return NB_OK;
305 }
306
307 static int static_nexthop_color_destroy(struct nb_cb_destroy_args *args)
308 {
309 struct static_nexthop *nh;
310
311 nh = nb_running_unset_entry(args->dnode);
312 nh->color = 0;
313
314 return NB_OK;
315 }
316
317 static int static_nexthop_bh_type_modify(struct nb_cb_modify_args *args)
318 {
319 struct static_nexthop *nh;
320
321 nh = nb_running_get_entry(args->dnode, NULL, true);
322 nh->bh_type = yang_dnode_get_enum(args->dnode, NULL);
323
324 return NB_OK;
325 }
326
327
328 void routing_control_plane_protocols_control_plane_protocol_staticd_route_list_path_list_frr_nexthops_nexthop_apply_finish(
329 struct nb_cb_apply_finish_args *args)
330 {
331 struct static_nexthop *nh;
332 struct static_path *pn;
333 struct route_node *rn;
334 const struct lyd_node *pn_dnode;
335 const struct lyd_node *rn_dnode;
336 const char *ifname;
337 const char *nh_vrf;
338 struct stable_info *info;
339 int nh_type;
340
341 nh_type = yang_dnode_get_enum(args->dnode, "./nh-type");
342 ifname = yang_dnode_get_string(args->dnode, "./interface");
343 nh_vrf = yang_dnode_get_string(args->dnode, "./vrf");
344
345 nh = nb_running_get_entry(args->dnode, NULL, true);
346
347 pn_dnode = yang_dnode_get_parent(args->dnode, "path-list");
348 pn = nb_running_get_entry(pn_dnode, NULL, true);
349
350 rn_dnode = yang_dnode_get_parent(pn_dnode, "route-list");
351 rn = nb_running_get_entry(rn_dnode, NULL, true);
352 info = route_table_get_info(rn->table);
353
354 static_install_nexthop(rn, pn, nh, info->safi, info->svrf, ifname,
355 nh_type, nh_vrf);
356 }
357
358
359 void routing_control_plane_protocols_control_plane_protocol_staticd_route_list_src_list_path_list_frr_nexthops_nexthop_apply_finish(
360 struct nb_cb_apply_finish_args *args)
361 {
362 struct static_nexthop *nh;
363 struct static_path *pn;
364 struct route_node *rn;
365 struct route_node *src_rn;
366 const struct lyd_node *pn_dnode;
367 const struct lyd_node *rn_dnode;
368 const struct lyd_node *src_dnode;
369 const char *ifname;
370 const char *nh_vrf;
371 struct stable_info *info;
372 int nh_type;
373
374 nh_type = yang_dnode_get_enum(args->dnode, "./nh-type");
375 ifname = yang_dnode_get_string(args->dnode, "./interface");
376 nh_vrf = yang_dnode_get_string(args->dnode, "./vrf");
377
378 nh = nb_running_get_entry(args->dnode, NULL, true);
379
380 pn_dnode = yang_dnode_get_parent(args->dnode, "path-list");
381 pn = nb_running_get_entry(pn_dnode, NULL, true);
382
383 src_dnode = yang_dnode_get_parent(pn_dnode, "src-list");
384 src_rn = nb_running_get_entry(src_dnode, NULL, true);
385
386 rn_dnode = yang_dnode_get_parent(src_dnode, "route-list");
387 rn = nb_running_get_entry(rn_dnode, NULL, true);
388 info = route_table_get_info(rn->table);
389
390 static_install_nexthop(src_rn, pn, nh, info->safi, info->svrf, ifname,
391 nh_type, nh_vrf);
392 }
393 int routing_control_plane_protocols_control_plane_protocol_staticd_route_list_path_list_frr_nexthops_nexthop_pre_validate(
394 struct nb_cb_pre_validate_args *args)
395 {
396 const struct lyd_node *mls_dnode;
397 uint32_t count;
398
399 mls_dnode = yang_dnode_get(args->dnode, "./mpls-label-stack");
400 count = yang_get_list_elements_count(yang_dnode_get_child(mls_dnode));
401
402 if (count > MPLS_MAX_LABELS) {
403 snprintf(args->errmsg, args->errmsg_len,
404 "Too many labels, Enter %d or fewer",
405 MPLS_MAX_LABELS);
406 return NB_ERR_VALIDATION;
407 }
408 return NB_OK;
409 }
410
411 int routing_control_plane_protocols_name_validate(
412 struct nb_cb_create_args *args)
413 {
414 const char *name;
415
416 name = yang_dnode_get_string(args->dnode, "./name");
417 if (!strmatch(name, "staticd")) {
418 snprintf(args->errmsg, args->errmsg_len,
419 "static routing supports only one instance with name staticd");
420 return NB_ERR_VALIDATION;
421 }
422 return NB_OK;
423 }
424 /*
425 * XPath:
426 * /frr-routing:routing/control-plane-protocols/control-plane-protocol/frr-staticd:staticd/route-list
427 */
428 int routing_control_plane_protocols_control_plane_protocol_staticd_route_list_create(
429 struct nb_cb_create_args *args)
430 {
431 struct vrf *vrf;
432 struct static_vrf *s_vrf;
433 struct route_node *rn;
434 const struct lyd_node *vrf_dnode;
435 struct prefix prefix;
436 const char *afi_safi;
437 afi_t prefix_afi;
438 afi_t afi;
439 safi_t safi;
440
441 switch (args->event) {
442 case NB_EV_VALIDATE:
443 yang_dnode_get_prefix(&prefix, args->dnode, "./prefix");
444 afi_safi = yang_dnode_get_string(args->dnode, "./afi-safi");
445 yang_afi_safi_identity2value(afi_safi, &afi, &safi);
446 prefix_afi = family2afi(prefix.family);
447 if (afi != prefix_afi) {
448 flog_warn(
449 EC_LIB_NB_CB_CONFIG_VALIDATE,
450 "route node %s creation failed",
451 yang_dnode_get_string(args->dnode, "./prefix"));
452 return NB_ERR_VALIDATION;
453 }
454 break;
455 case NB_EV_PREPARE:
456 case NB_EV_ABORT:
457 break;
458 case NB_EV_APPLY:
459 vrf_dnode = yang_dnode_get_parent(args->dnode,
460 "control-plane-protocol");
461 vrf = nb_running_get_entry(vrf_dnode, NULL, true);
462 s_vrf = vrf->info;
463
464 yang_dnode_get_prefix(&prefix, args->dnode, "./prefix");
465 afi_safi = yang_dnode_get_string(args->dnode, "./afi-safi");
466 yang_afi_safi_identity2value(afi_safi, &afi, &safi);
467
468 rn = static_add_route(afi, safi, &prefix, NULL, s_vrf);
469 if (!rn) {
470 flog_warn(
471 EC_LIB_NB_CB_CONFIG_APPLY,
472 "route node %s creation failed",
473 yang_dnode_get_string(args->dnode, "./prefix"));
474 return NB_ERR;
475 }
476 if (vrf->vrf_id == VRF_UNKNOWN)
477 snprintf(
478 args->errmsg, args->errmsg_len,
479 "Static Route to %s not installed currently because dependent config not fully available",
480 yang_dnode_get_string(args->dnode, "./prefix"));
481 nb_running_set_entry(args->dnode, rn);
482 break;
483 }
484 return NB_OK;
485 }
486
487 int routing_control_plane_protocols_control_plane_protocol_staticd_route_list_destroy(
488 struct nb_cb_destroy_args *args)
489 {
490 struct route_node *rn;
491 struct stable_info *info;
492
493 switch (args->event) {
494 case NB_EV_VALIDATE:
495 case NB_EV_PREPARE:
496 case NB_EV_ABORT:
497 break;
498 case NB_EV_APPLY:
499 rn = nb_running_unset_entry(args->dnode);
500 info = route_table_get_info(rn->table);
501 static_del_route(rn, info->safi, info->svrf);
502 break;
503 }
504 return NB_OK;
505 }
506
507 /*
508 * XPath:
509 * /frr-routing:routing/control-plane-protocols/control-plane-protocol/frr-staticd:staticd/route-list/path-list
510 */
511 int routing_control_plane_protocols_control_plane_protocol_staticd_route_list_path_list_create(
512 struct nb_cb_create_args *args)
513 {
514 return static_path_list_create(args);
515 }
516
517 int routing_control_plane_protocols_control_plane_protocol_staticd_route_list_path_list_destroy(
518 struct nb_cb_destroy_args *args)
519 {
520 const struct lyd_node *rn_dnode;
521 struct route_node *rn;
522 struct stable_info *info;
523
524 switch (args->event) {
525 case NB_EV_VALIDATE:
526 case NB_EV_PREPARE:
527 case NB_EV_ABORT:
528 break;
529 case NB_EV_APPLY:
530 rn_dnode = yang_dnode_get_parent(args->dnode, "route-list");
531 rn = nb_running_get_entry(rn_dnode, NULL, true);
532 info = route_table_get_info(rn->table);
533 static_path_list_destroy(args, rn_dnode, info);
534 break;
535 }
536 return NB_OK;
537 }
538
539 /*
540 * XPath:
541 * /frr-routing:routing/control-plane-protocols/control-plane-protocol/frr-staticd:staticd/route-list/path-list/tag
542 */
543 int routing_control_plane_protocols_control_plane_protocol_staticd_route_list_path_list_tag_modify(
544 struct nb_cb_modify_args *args)
545 {
546 struct stable_info *info;
547 struct route_node *rn;
548 const struct lyd_node *rn_dnode;
549
550 switch (args->event) {
551 case NB_EV_VALIDATE:
552 case NB_EV_ABORT:
553 case NB_EV_PREPARE:
554 break;
555 case NB_EV_APPLY:
556 rn_dnode = yang_dnode_get_parent(args->dnode, "route-list");
557 rn = nb_running_get_entry(rn_dnode, NULL, true);
558 info = route_table_get_info(rn->table);
559 static_path_list_tag_modify(args, rn_dnode, info);
560 break;
561 }
562
563 return NB_OK;
564 }
565
566 /*
567 * XPath:
568 * /frr-routing:routing/control-plane-protocols/control-plane-protocol/frr-staticd:staticd/route-list/path-list/frr-nexthops/nexthop
569 */
570 int routing_control_plane_protocols_control_plane_protocol_staticd_route_list_path_list_frr_nexthops_nexthop_create(
571 struct nb_cb_create_args *args)
572 {
573 struct route_node *rn;
574 const struct lyd_node *rn_dnode;
575 struct stable_info *info;
576
577 switch (args->event) {
578 case NB_EV_VALIDATE:
579 rn_dnode = yang_dnode_get_parent(args->dnode, "route-list");
580 if (static_nexthop_create(args, rn_dnode, NULL) != NB_OK)
581 return NB_ERR_VALIDATION;
582 break;
583 case NB_EV_PREPARE:
584 case NB_EV_ABORT:
585 break;
586 case NB_EV_APPLY:
587 rn_dnode = yang_dnode_get_parent(args->dnode, "route-list");
588 rn = nb_running_get_entry(rn_dnode, NULL, true);
589 info = route_table_get_info(rn->table);
590
591 if (static_nexthop_create(args, rn_dnode, info) != NB_OK)
592 return NB_ERR_VALIDATION;
593 break;
594 }
595 return NB_OK;
596 }
597
598 int routing_control_plane_protocols_control_plane_protocol_staticd_route_list_path_list_frr_nexthops_nexthop_destroy(
599 struct nb_cb_destroy_args *args)
600 {
601 struct route_node *rn;
602 const struct lyd_node *rn_dnode;
603 struct stable_info *info;
604
605 switch (args->event) {
606 case NB_EV_VALIDATE:
607 case NB_EV_PREPARE:
608 case NB_EV_ABORT:
609 break;
610 case NB_EV_APPLY:
611 rn_dnode = yang_dnode_get_parent(args->dnode, "route-list");
612 rn = nb_running_get_entry(rn_dnode, NULL, true);
613 info = route_table_get_info(rn->table);
614
615 if (static_nexthop_destroy(args, rn_dnode, info) != NB_OK)
616 return NB_ERR;
617 break;
618 }
619 return NB_OK;
620 }
621
622 /*
623 * XPath:
624 * /frr-routing:routing/control-plane-protocols/control-plane-protocol/frr-staticd:staticd/route-list/path-list/frr-nexthops/nexthop/bh-type
625 */
626 int routing_control_plane_protocols_control_plane_protocol_staticd_route_list_path_list_frr_nexthops_nexthop_bh_type_modify(
627 struct nb_cb_modify_args *args)
628 {
629 switch (args->event) {
630 case NB_EV_VALIDATE:
631 case NB_EV_PREPARE:
632 case NB_EV_ABORT:
633 break;
634 case NB_EV_APPLY:
635 if (static_nexthop_bh_type_modify(args) != NB_OK)
636 return NB_ERR;
637 break;
638 }
639 return NB_OK;
640 }
641
642 int routing_control_plane_protocols_control_plane_protocol_staticd_route_list_path_list_frr_nexthops_nexthop_bh_type_destroy(
643 struct nb_cb_destroy_args *args)
644 {
645 /* blackhole type has a boolean type with default value,
646 * so no need to do any operations in destroy callback
647 */
648 switch (args->event) {
649 case NB_EV_VALIDATE:
650 case NB_EV_PREPARE:
651 case NB_EV_ABORT:
652 case NB_EV_APPLY:
653 break;
654 }
655 return NB_OK;
656 }
657
658 /*
659 * XPath:
660 * /frr-routing:routing/control-plane-protocols/control-plane-protocol/frr-staticd:staticd/route-list/path-list/frr-nexthops/nexthop/onlink
661 */
662 int routing_control_plane_protocols_control_plane_protocol_staticd_route_list_path_list_frr_nexthops_nexthop_onlink_modify(
663 struct nb_cb_modify_args *args)
664 {
665 switch (args->event) {
666 case NB_EV_VALIDATE:
667 case NB_EV_PREPARE:
668 case NB_EV_ABORT:
669 break;
670 case NB_EV_APPLY:
671 if (static_nexthop_onlink_modify(args) != NB_OK)
672 return NB_ERR;
673
674 break;
675 }
676 return NB_OK;
677 }
678 int routing_control_plane_protocols_control_plane_protocol_staticd_route_list_path_list_frr_nexthops_nexthop_onlink_destroy(
679 struct nb_cb_destroy_args *args)
680 {
681 /* onlink has a boolean type with default value,
682 * so no need to do any operations in destroy callback
683 */
684 switch (args->event) {
685 case NB_EV_VALIDATE:
686 case NB_EV_PREPARE:
687 case NB_EV_ABORT:
688 case NB_EV_APPLY:
689 break;
690 }
691 return NB_OK;
692 }
693
694 /*
695 * XPath:
696 * /frr-routing:routing/control-plane-protocols/control-plane-protocol/frr-staticd:staticd/route-list/path-list/frr-nexthops/nexthop/srte-color
697 */
698 int routing_control_plane_protocols_control_plane_protocol_staticd_route_list_path_list_frr_nexthops_nexthop_color_modify(
699 struct nb_cb_modify_args *args)
700 {
701 switch (args->event) {
702 case NB_EV_VALIDATE:
703 case NB_EV_PREPARE:
704 case NB_EV_ABORT:
705 break;
706 case NB_EV_APPLY:
707 if (static_nexthop_color_modify(args) != NB_OK)
708 return NB_ERR;
709
710 break;
711 }
712 return NB_OK;
713 }
714
715 int routing_control_plane_protocols_control_plane_protocol_staticd_route_list_path_list_frr_nexthops_nexthop_color_destroy(
716 struct nb_cb_destroy_args *args)
717 {
718 switch (args->event) {
719 case NB_EV_VALIDATE:
720 case NB_EV_PREPARE:
721 case NB_EV_ABORT:
722 break;
723 case NB_EV_APPLY:
724 if (static_nexthop_color_destroy(args) != NB_OK)
725 return NB_ERR;
726 break;
727 }
728 return NB_OK;
729 }
730
731 /*
732 * XPath:
733 * /frr-routing:routing/control-plane-protocols/control-plane-protocol/frr-staticd:staticd/route-list/path-list/frr-nexthops/nexthop/mpls-label-stack/entry
734 */
735 int routing_control_plane_protocols_control_plane_protocol_staticd_route_list_path_list_frr_nexthops_nexthop_mpls_label_stack_entry_create(
736 struct nb_cb_create_args *args)
737 {
738 return nexthop_mpls_label_stack_entry_create(args);
739 }
740
741 int routing_control_plane_protocols_control_plane_protocol_staticd_route_list_path_list_frr_nexthops_nexthop_mpls_label_stack_entry_destroy(
742 struct nb_cb_destroy_args *args)
743 {
744 return nexthop_mpls_label_stack_entry_destroy(args);
745 }
746
747 /*
748 * XPath:
749 * /frr-routing:routing/control-plane-protocols/control-plane-protocol/frr-staticd:staticd/route-list/path-list/frr-nexthops/nexthop/mpls-label-stack/entry/label
750 */
751 int routing_control_plane_protocols_control_plane_protocol_staticd_route_list_path_list_frr_nexthops_nexthop_mpls_label_stack_entry_label_modify(
752 struct nb_cb_modify_args *args)
753 {
754 switch (args->event) {
755 case NB_EV_VALIDATE:
756 case NB_EV_PREPARE:
757 case NB_EV_ABORT:
758 break;
759 case NB_EV_APPLY:
760 if (static_nexthop_mpls_label_modify(args) != NB_OK)
761 return NB_ERR;
762 break;
763 }
764 return NB_OK;
765 }
766
767 int routing_control_plane_protocols_control_plane_protocol_staticd_route_list_path_list_frr_nexthops_nexthop_mpls_label_stack_entry_label_destroy(
768 struct nb_cb_destroy_args *args)
769 {
770 /*
771 * No operation is required in this call back.
772 * nexthop_mpls_label_stack_entry_destroy() will take care
773 * to reset the label vaue.
774 */
775 switch (args->event) {
776 case NB_EV_VALIDATE:
777 case NB_EV_PREPARE:
778 case NB_EV_ABORT:
779 case NB_EV_APPLY:
780 break;
781 }
782 return NB_OK;
783 }
784
785 /*
786 * XPath:
787 * /frr-routing:routing/control-plane-protocols/control-plane-protocol/frr-staticd:staticd/route-list/path-list/frr-nexthops/nexthop/mpls-label-stack/entry/ttl
788 */
789 int routing_control_plane_protocols_control_plane_protocol_staticd_route_list_path_list_frr_nexthops_nexthop_mpls_label_stack_entry_ttl_modify(
790 struct nb_cb_modify_args *args)
791 {
792 switch (args->event) {
793 case NB_EV_VALIDATE:
794 case NB_EV_PREPARE:
795 case NB_EV_ABORT:
796 case NB_EV_APPLY:
797 break;
798 }
799
800 return NB_OK;
801 }
802
803 int routing_control_plane_protocols_control_plane_protocol_staticd_route_list_path_list_frr_nexthops_nexthop_mpls_label_stack_entry_ttl_destroy(
804 struct nb_cb_destroy_args *args)
805 {
806 switch (args->event) {
807 case NB_EV_VALIDATE:
808 case NB_EV_PREPARE:
809 case NB_EV_ABORT:
810 case NB_EV_APPLY:
811 break;
812 }
813
814 return NB_OK;
815 }
816
817 /*
818 * XPath:
819 * /frr-routing:routing/control-plane-protocols/control-plane-protocol/frr-staticd:staticd/route-list/path-list/frr-nexthops/nexthop/mpls-label-stack/entry/traffic-class
820 */
821 int routing_control_plane_protocols_control_plane_protocol_staticd_route_list_path_list_frr_nexthops_nexthop_mpls_label_stack_entry_traffic_class_modify(
822 struct nb_cb_modify_args *args)
823 {
824 switch (args->event) {
825 case NB_EV_VALIDATE:
826 case NB_EV_PREPARE:
827 case NB_EV_ABORT:
828 case NB_EV_APPLY:
829 break;
830 }
831
832 return NB_OK;
833 }
834
835 int routing_control_plane_protocols_control_plane_protocol_staticd_route_list_path_list_frr_nexthops_nexthop_mpls_label_stack_entry_traffic_class_destroy(
836 struct nb_cb_destroy_args *args)
837 {
838 switch (args->event) {
839 case NB_EV_VALIDATE:
840 case NB_EV_PREPARE:
841 case NB_EV_ABORT:
842 case NB_EV_APPLY:
843 break;
844 }
845
846 return NB_OK;
847 }
848
849 /*
850 * XPath:
851 * /frr-routing:routing/control-plane-protocols/control-plane-protocol/frr-staticd:staticd/route-list/src-list
852 */
853 int routing_control_plane_protocols_control_plane_protocol_staticd_route_list_src_list_create(
854 struct nb_cb_create_args *args)
855 {
856 struct static_vrf *s_vrf;
857 struct route_node *rn;
858 struct route_node *src_rn;
859 struct prefix_ipv6 src_prefix = {};
860 struct stable_info *info;
861 afi_t afi;
862 safi_t safi = SAFI_UNICAST;
863
864 switch (args->event) {
865 case NB_EV_VALIDATE:
866 case NB_EV_PREPARE:
867 case NB_EV_ABORT:
868 break;
869 case NB_EV_APPLY:
870 rn = nb_running_get_entry(args->dnode, NULL, true);
871 info = route_table_get_info(rn->table);
872 s_vrf = info->svrf;
873 yang_dnode_get_ipv6p(&src_prefix, args->dnode, "./src-prefix");
874 afi = family2afi(src_prefix.family);
875 src_rn =
876 static_add_route(afi, safi, &rn->p, &src_prefix, s_vrf);
877 if (!src_rn) {
878 flog_warn(EC_LIB_NB_CB_CONFIG_APPLY,
879 "src rn %s creation failed",
880 yang_dnode_get_string(args->dnode,
881 "./src-prefix"));
882 return NB_ERR;
883 }
884 nb_running_set_entry(args->dnode, src_rn);
885 break;
886 }
887 return NB_OK;
888 }
889
890 int routing_control_plane_protocols_control_plane_protocol_staticd_route_list_src_list_destroy(
891 struct nb_cb_destroy_args *args)
892 {
893 struct route_node *src_rn;
894 struct route_node *rn;
895 struct stable_info *info;
896 const struct lyd_node *rn_dnode;
897
898 switch (args->event) {
899 case NB_EV_VALIDATE:
900 case NB_EV_PREPARE:
901 case NB_EV_ABORT:
902 break;
903 case NB_EV_APPLY:
904 src_rn = nb_running_unset_entry(args->dnode);
905 rn_dnode = yang_dnode_get_parent(args->dnode, "route-list");
906 rn = nb_running_get_entry(rn_dnode, NULL, true);
907 info = route_table_get_info(rn->table);
908 static_del_route(src_rn, info->safi, info->svrf);
909 break;
910 }
911
912 return NB_OK;
913 }
914
915 /*
916 * XPath:
917 * /frr-routing:routing/control-plane-protocols/control-plane-protocol/frr-staticd:staticd/route-list/src-list/path-list
918 */
919 int routing_control_plane_protocols_control_plane_protocol_staticd_route_list_src_list_path_list_create(
920 struct nb_cb_create_args *args)
921 {
922 return static_path_list_create(args);
923 }
924
925 int routing_control_plane_protocols_control_plane_protocol_staticd_route_list_src_list_path_list_destroy(
926 struct nb_cb_destroy_args *args)
927 {
928 struct route_node *rn;
929 const struct lyd_node *rn_dnode;
930 const struct lyd_node *srn_dnode;
931 struct stable_info *info;
932
933 switch (args->event) {
934 case NB_EV_VALIDATE:
935 case NB_EV_PREPARE:
936 case NB_EV_ABORT:
937 break;
938 case NB_EV_APPLY:
939 srn_dnode = yang_dnode_get_parent(args->dnode, "src-list");
940 rn_dnode = yang_dnode_get_parent(srn_dnode, "route-list");
941 rn = nb_running_get_entry(rn_dnode, NULL, true);
942 info = route_table_get_info(rn->table);
943 static_path_list_destroy(args, srn_dnode, info);
944 break;
945 }
946 return NB_OK;
947 }
948
949 /*
950 * XPath:
951 * /frr-routing:routing/control-plane-protocols/control-plane-protocol/frr-staticd:staticd/route-list/src-list/path-list/tag
952 */
953 int routing_control_plane_protocols_control_plane_protocol_staticd_route_list_src_list_path_list_tag_modify(
954 struct nb_cb_modify_args *args)
955 {
956 struct stable_info *info;
957 struct route_node *rn;
958 const struct lyd_node *srn_dnode;
959 const struct lyd_node *rn_dnode;
960
961 switch (args->event) {
962 case NB_EV_VALIDATE:
963 case NB_EV_ABORT:
964 case NB_EV_PREPARE:
965 break;
966 case NB_EV_APPLY:
967 srn_dnode = yang_dnode_get_parent(args->dnode, "src-list");
968 rn_dnode = yang_dnode_get_parent(srn_dnode, "route-list");
969 rn = nb_running_get_entry(rn_dnode, NULL, true);
970 info = route_table_get_info(rn->table);
971 static_path_list_tag_modify(args, srn_dnode, info);
972 break;
973 }
974 return NB_OK;
975 }
976
977 /*
978 * XPath:
979 * /frr-routing:routing/control-plane-protocols/control-plane-protocol/frr-staticd:staticd/route-list/src-list/path-list/frr-nexthops/nexthop
980 */
981 int routing_control_plane_protocols_control_plane_protocol_staticd_route_list_src_list_path_list_frr_nexthops_nexthop_create(
982 struct nb_cb_create_args *args)
983 {
984 struct route_node *rn;
985 const struct lyd_node *rn_dnode;
986 const struct lyd_node *src_dnode;
987 struct stable_info *info;
988
989 switch (args->event) {
990 case NB_EV_VALIDATE:
991 rn_dnode = yang_dnode_get_parent(args->dnode, "route-list");
992 if (static_nexthop_create(args, rn_dnode, NULL) != NB_OK)
993 return NB_ERR_VALIDATION;
994 break;
995 case NB_EV_PREPARE:
996 case NB_EV_ABORT:
997 break;
998 case NB_EV_APPLY:
999 src_dnode = yang_dnode_get_parent(args->dnode, "src-list");
1000 rn_dnode = yang_dnode_get_parent(src_dnode, "route-list");
1001 rn = nb_running_get_entry(rn_dnode, NULL, true);
1002 info = route_table_get_info(rn->table);
1003
1004 if (static_nexthop_create(args, src_dnode, info) != NB_OK)
1005 return NB_ERR_VALIDATION;
1006
1007 break;
1008 }
1009 return NB_OK;
1010 }
1011
1012 int routing_control_plane_protocols_control_plane_protocol_staticd_route_list_src_list_path_list_frr_nexthops_nexthop_destroy(
1013 struct nb_cb_destroy_args *args)
1014 {
1015 struct route_node *rn;
1016 const struct lyd_node *rn_dnode;
1017 const struct lyd_node *src_dnode;
1018 struct stable_info *info;
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 src_dnode = yang_dnode_get_parent(args->dnode, "src-list");
1027 rn_dnode = yang_dnode_get_parent(src_dnode, "route-list");
1028 rn = nb_running_get_entry(rn_dnode, NULL, true);
1029 info = route_table_get_info(rn->table);
1030
1031 if (static_nexthop_destroy(args, rn_dnode, info) != NB_OK)
1032 return NB_ERR;
1033 break;
1034 }
1035 return NB_OK;
1036 }
1037
1038 /*
1039 * XPath:
1040 * /frr-routing:routing/control-plane-protocols/control-plane-protocol/frr-staticd:staticd/route-list/src-list/path-list/frr-nexthops/nexthop/bh-type
1041 */
1042 int routing_control_plane_protocols_control_plane_protocol_staticd_route_list_src_list_path_list_frr_nexthops_nexthop_bh_type_modify(
1043 struct nb_cb_modify_args *args)
1044 {
1045 switch (args->event) {
1046 case NB_EV_VALIDATE:
1047 case NB_EV_PREPARE:
1048 case NB_EV_ABORT:
1049 break;
1050 case NB_EV_APPLY:
1051 if (static_nexthop_bh_type_modify(args) != NB_OK)
1052 return NB_ERR;
1053 break;
1054 }
1055 return NB_OK;
1056 }
1057
1058 int routing_control_plane_protocols_control_plane_protocol_staticd_route_list_src_list_path_list_frr_nexthops_nexthop_bh_type_destroy(
1059 struct nb_cb_destroy_args *args)
1060 {
1061 /* blackhole type has a boolean type with default value,
1062 * so no need to do any operations in destroy callback
1063 */
1064 switch (args->event) {
1065 case NB_EV_VALIDATE:
1066 case NB_EV_PREPARE:
1067 case NB_EV_ABORT:
1068 case NB_EV_APPLY:
1069 break;
1070 }
1071
1072 return NB_OK;
1073 }
1074
1075 /*
1076 * XPath:
1077 * /frr-routing:routing/control-plane-protocols/control-plane-protocol/frr-staticd:staticd/route-list/src-list/path-list/frr-nexthops/nexthop/onlink
1078 */
1079 int routing_control_plane_protocols_control_plane_protocol_staticd_route_list_src_list_path_list_frr_nexthops_nexthop_onlink_modify(
1080 struct nb_cb_modify_args *args)
1081 {
1082 switch (args->event) {
1083 case NB_EV_VALIDATE:
1084 case NB_EV_PREPARE:
1085 case NB_EV_ABORT:
1086 break;
1087 case NB_EV_APPLY:
1088 if (static_nexthop_onlink_modify(args) != NB_OK)
1089 return NB_ERR;
1090
1091 break;
1092 }
1093 return NB_OK;
1094 }
1095
1096
1097 int routing_control_plane_protocols_control_plane_protocol_staticd_route_list_src_list_path_list_frr_nexthops_nexthop_onlink_destroy(
1098 struct nb_cb_destroy_args *args)
1099 {
1100 /* onlink has a boolean type with default value,
1101 * so no need to do any operations in destroy callback
1102 */
1103 switch (args->event) {
1104 case NB_EV_VALIDATE:
1105 case NB_EV_PREPARE:
1106 case NB_EV_ABORT:
1107 case NB_EV_APPLY:
1108 break;
1109 }
1110 return NB_OK;
1111 }
1112
1113 /*
1114 * XPath:
1115 * /frr-routing:routing/control-plane-protocols/control-plane-protocol/frr-staticd:staticd/route-list/src-list/path-list/frr-nexthops/nexthop/srte-color
1116 */
1117 int routing_control_plane_protocols_control_plane_protocol_staticd_route_list_src_list_path_list_frr_nexthops_nexthop_color_modify(
1118 struct nb_cb_modify_args *args)
1119 {
1120 switch (args->event) {
1121 case NB_EV_VALIDATE:
1122 case NB_EV_PREPARE:
1123 case NB_EV_ABORT:
1124 break;
1125 case NB_EV_APPLY:
1126 if (static_nexthop_color_modify(args) != NB_OK)
1127 return NB_ERR;
1128
1129 break;
1130 }
1131 return NB_OK;
1132 }
1133
1134
1135 int routing_control_plane_protocols_control_plane_protocol_staticd_route_list_src_list_path_list_frr_nexthops_nexthop_color_destroy(
1136 struct nb_cb_destroy_args *args)
1137 {
1138 switch (args->event) {
1139 case NB_EV_VALIDATE:
1140 case NB_EV_PREPARE:
1141 case NB_EV_ABORT:
1142 break;
1143 case NB_EV_APPLY:
1144 if (static_nexthop_color_destroy(args) != NB_OK)
1145 return NB_ERR;
1146 break;
1147 }
1148 return NB_OK;
1149 }
1150
1151 /*
1152 * XPath:
1153 * /frr-routing:routing/control-plane-protocols/control-plane-protocol/frr-staticd:staticd/route-list/src-list/path-list/frr-nexthops/nexthop/mpls-label-stack/entry
1154 */
1155 int routing_control_plane_protocols_control_plane_protocol_staticd_route_list_src_list_path_list_frr_nexthops_nexthop_mpls_label_stack_entry_create(
1156 struct nb_cb_create_args *args)
1157 {
1158 return nexthop_mpls_label_stack_entry_create(args);
1159 }
1160
1161 int routing_control_plane_protocols_control_plane_protocol_staticd_route_list_src_list_path_list_frr_nexthops_nexthop_mpls_label_stack_entry_destroy(
1162 struct nb_cb_destroy_args *args)
1163 {
1164 return nexthop_mpls_label_stack_entry_destroy(args);
1165 }
1166
1167 /*
1168 * XPath:
1169 * /frr-routing:routing/control-plane-protocols/control-plane-protocol/frr-staticd:staticd/route-list/src-list/path-list/frr-nexthops/nexthop/mpls-label-stack/entry/label
1170 */
1171 int routing_control_plane_protocols_control_plane_protocol_staticd_route_list_src_list_path_list_frr_nexthops_nexthop_mpls_label_stack_entry_label_modify(
1172 struct nb_cb_modify_args *args)
1173 {
1174 switch (args->event) {
1175 case NB_EV_VALIDATE:
1176 case NB_EV_PREPARE:
1177 case NB_EV_ABORT:
1178 break;
1179 case NB_EV_APPLY:
1180 if (static_nexthop_mpls_label_modify(args) != NB_OK)
1181 return NB_ERR;
1182 break;
1183 }
1184 return NB_OK;
1185 }
1186
1187 int routing_control_plane_protocols_control_plane_protocol_staticd_route_list_src_list_path_list_frr_nexthops_nexthop_mpls_label_stack_entry_label_destroy(
1188 struct nb_cb_destroy_args *args)
1189 {
1190 /*
1191 * No operation is required in this call back.
1192 * nexthop_mpls_label_stack_entry_destroy() will take care
1193 * to reset the label vaue.
1194 */
1195 switch (args->event) {
1196 case NB_EV_VALIDATE:
1197 case NB_EV_PREPARE:
1198 case NB_EV_ABORT:
1199 case NB_EV_APPLY:
1200 break;
1201 }
1202 return NB_OK;
1203 }
1204
1205 /*
1206 * XPath:
1207 * /frr-routing:routing/control-plane-protocols/control-plane-protocol/frr-staticd:staticd/route-list/src-list/path-list/frr-nexthops/nexthop/mpls-label-stack/entry/ttl
1208 */
1209 int routing_control_plane_protocols_control_plane_protocol_staticd_route_list_src_list_path_list_frr_nexthops_nexthop_mpls_label_stack_entry_ttl_modify(
1210 struct nb_cb_modify_args *args)
1211 {
1212 switch (args->event) {
1213 case NB_EV_VALIDATE:
1214 case NB_EV_PREPARE:
1215 case NB_EV_ABORT:
1216 case NB_EV_APPLY:
1217 break;
1218 }
1219
1220 return NB_OK;
1221 }
1222
1223 int routing_control_plane_protocols_control_plane_protocol_staticd_route_list_src_list_path_list_frr_nexthops_nexthop_mpls_label_stack_entry_ttl_destroy(
1224 struct nb_cb_destroy_args *args)
1225 {
1226 switch (args->event) {
1227 case NB_EV_VALIDATE:
1228 case NB_EV_PREPARE:
1229 case NB_EV_ABORT:
1230 case NB_EV_APPLY:
1231 break;
1232 }
1233
1234 return NB_OK;
1235 }
1236
1237 /*
1238 * XPath:
1239 * /frr-routing:routing/control-plane-protocols/control-plane-protocol/frr-staticd:staticd/route-list/src-list/path-list/frr-nexthops/nexthop/mpls-label-stack/entry/traffic-class
1240 */
1241 int routing_control_plane_protocols_control_plane_protocol_staticd_route_list_src_list_path_list_frr_nexthops_nexthop_mpls_label_stack_entry_traffic_class_modify(
1242 struct nb_cb_modify_args *args)
1243 {
1244 switch (args->event) {
1245 case NB_EV_VALIDATE:
1246 case NB_EV_PREPARE:
1247 case NB_EV_ABORT:
1248 case NB_EV_APPLY:
1249 break;
1250 }
1251
1252 return NB_OK;
1253 }
1254
1255 int routing_control_plane_protocols_control_plane_protocol_staticd_route_list_src_list_path_list_frr_nexthops_nexthop_mpls_label_stack_entry_traffic_class_destroy(
1256 struct nb_cb_destroy_args *args)
1257 {
1258 switch (args->event) {
1259 case NB_EV_VALIDATE:
1260 case NB_EV_PREPARE:
1261 case NB_EV_ABORT:
1262 case NB_EV_APPLY:
1263 break;
1264 }
1265
1266 return NB_OK;
1267 }