]> git.proxmox.com Git - mirror_frr.git/blob - staticd/static_nb_config.c
Merge pull request #8128 from qlyoung/docs-cleanup
[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(nh_vrf, 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 nb_running_set_entry(args->dnode, nh);
152 break;
153 }
154
155 return NB_OK;
156 }
157
158 static bool static_nexthop_destroy(struct nb_cb_destroy_args *args,
159 const struct lyd_node *rn_dnode,
160 struct stable_info *info)
161 {
162 struct route_node *rn;
163 struct static_path *pn;
164 const struct lyd_node *pn_dnode;
165 struct static_nexthop *nh;
166 int ret;
167
168 nh = nb_running_unset_entry(args->dnode);
169 pn_dnode = yang_dnode_get_parent(args->dnode, "path-list");
170 pn = nb_running_get_entry(pn_dnode, NULL, true);
171 rn = nb_running_get_entry(rn_dnode, NULL, true);
172
173 ret = static_delete_nexthop(rn, pn, info->safi, info->svrf, nh);
174 if (!ret) {
175 char buf[SRCDEST2STR_BUFFER];
176
177 flog_warn(EC_LIB_NB_CB_CONFIG_APPLY,
178 "%s : nh [%d:%s:%s:%s] nexthop destroy failed",
179 srcdest_rnode2str(rn, buf, sizeof(buf)),
180 yang_dnode_get_enum(args->dnode, "./nh-type"),
181 yang_dnode_get_string(args->dnode, "./interface"),
182 yang_dnode_get_string(args->dnode, "./gateway"),
183 yang_dnode_get_string(args->dnode, "./vrf"));
184 return NB_ERR;
185 }
186
187 return NB_OK;
188 }
189
190 static int nexthop_mpls_label_stack_entry_create(struct nb_cb_create_args *args)
191 {
192 struct static_nexthop *nh;
193 uint32_t pos;
194 uint8_t index;
195
196 switch (args->event) {
197 case NB_EV_VALIDATE:
198 if (!mpls_enabled) {
199 snprintf(
200 args->errmsg, args->errmsg_len,
201 "%% MPLS not turned on in kernel ignoring static route");
202 return NB_ERR_VALIDATION;
203 }
204 break;
205 case NB_EV_PREPARE:
206 case NB_EV_ABORT:
207 break;
208 case NB_EV_APPLY:
209 nh = nb_running_get_entry(args->dnode, NULL, true);
210 pos = yang_get_list_pos(args->dnode);
211 if (!pos) {
212 flog_warn(EC_LIB_NB_CB_CONFIG_APPLY,
213 "libyang returns invalid label position");
214 return NB_ERR;
215 }
216 /* Mapping to array = list-index -1 */
217 index = pos - 1;
218 nh->snh_label.label[index] = 0;
219 nh->snh_label.num_labels++;
220 break;
221 }
222
223 return NB_OK;
224 }
225
226 static int
227 nexthop_mpls_label_stack_entry_destroy(struct nb_cb_destroy_args *args)
228 {
229 struct static_nexthop *nh;
230 uint32_t pos;
231 uint8_t index;
232
233 switch (args->event) {
234 case NB_EV_VALIDATE:
235 case NB_EV_PREPARE:
236 case NB_EV_ABORT:
237 break;
238 case NB_EV_APPLY:
239 nh = nb_running_get_entry(args->dnode, NULL, true);
240 pos = yang_get_list_pos(args->dnode);
241 if (!pos) {
242 flog_warn(EC_LIB_NB_CB_CONFIG_APPLY,
243 "libyang returns invalid label position");
244 return NB_ERR;
245 }
246 index = pos - 1;
247 nh->snh_label.label[index] = 0;
248 nh->snh_label.num_labels--;
249 break;
250 }
251
252 return NB_OK;
253 }
254
255 static int static_nexthop_mpls_label_modify(struct nb_cb_modify_args *args)
256 {
257 struct static_nexthop *nh;
258 uint32_t pos;
259 uint8_t index;
260
261 nh = nb_running_get_entry(args->dnode, NULL, true);
262 pos = yang_get_list_pos(args->dnode->parent);
263 if (!pos) {
264 flog_warn(EC_LIB_NB_CB_CONFIG_APPLY,
265 "libyang returns invalid label position");
266 return NB_ERR;
267 }
268 /* Mapping to array = list-index -1 */
269 index = pos - 1;
270 nh->snh_label.label[index] = yang_dnode_get_uint32(args->dnode, NULL);
271
272 return NB_OK;
273 }
274
275 static int static_nexthop_onlink_modify(struct nb_cb_modify_args *args)
276 {
277 struct static_nexthop *nh;
278 static_types nh_type;
279
280 switch (args->event) {
281 case NB_EV_VALIDATE:
282 nh_type = yang_dnode_get_enum(args->dnode, "../nh-type");
283 if ((nh_type != STATIC_IPV4_GATEWAY_IFNAME)
284 && (nh_type != STATIC_IPV6_GATEWAY_IFNAME)) {
285 snprintf(
286 args->errmsg, args->errmsg_len,
287 "nexthop type is not the ipv4 or ipv6 interface type");
288 return NB_ERR_VALIDATION;
289 }
290 break;
291 case NB_EV_PREPARE:
292 case NB_EV_ABORT:
293 break;
294 case NB_EV_APPLY:
295 nh = nb_running_get_entry(args->dnode, NULL, true);
296 nh->onlink = yang_dnode_get_bool(args->dnode, NULL);
297 break;
298 }
299
300 return NB_OK;
301 }
302
303 static int static_nexthop_color_modify(struct nb_cb_modify_args *args)
304 {
305 struct static_nexthop *nh;
306
307 nh = nb_running_get_entry(args->dnode, NULL, true);
308 nh->color = yang_dnode_get_uint32(args->dnode, NULL);
309
310 return NB_OK;
311 }
312
313 static int static_nexthop_color_destroy(struct nb_cb_destroy_args *args)
314 {
315 struct static_nexthop *nh;
316
317 nh = nb_running_unset_entry(args->dnode);
318 nh->color = 0;
319
320 return NB_OK;
321 }
322
323 static int static_nexthop_bh_type_modify(struct nb_cb_modify_args *args)
324 {
325 struct static_nexthop *nh;
326 static_types nh_type;
327
328 switch (args->event) {
329 case NB_EV_VALIDATE:
330 nh_type = yang_dnode_get_enum(args->dnode, "../nh-type");
331 if (nh_type != STATIC_BLACKHOLE) {
332 snprintf(args->errmsg, args->errmsg_len,
333 "nexthop type is not the blackhole type");
334 return NB_ERR_VALIDATION;
335 }
336 break;
337 case NB_EV_PREPARE:
338 case NB_EV_ABORT:
339 break;
340 case NB_EV_APPLY:
341 nh = nb_running_get_entry(args->dnode, NULL, true);
342 nh->bh_type = yang_dnode_get_enum(args->dnode, NULL);
343 break;
344 }
345
346 return NB_OK;
347 }
348
349
350 void routing_control_plane_protocols_control_plane_protocol_staticd_route_list_path_list_frr_nexthops_nexthop_apply_finish(
351 struct nb_cb_apply_finish_args *args)
352 {
353 struct static_nexthop *nh;
354 struct static_path *pn;
355 struct route_node *rn;
356 const struct lyd_node *pn_dnode;
357 const struct lyd_node *rn_dnode;
358 const char *ifname;
359 const char *nh_vrf;
360 struct stable_info *info;
361 int nh_type;
362
363 nh_type = yang_dnode_get_enum(args->dnode, "./nh-type");
364 ifname = yang_dnode_get_string(args->dnode, "./interface");
365 nh_vrf = yang_dnode_get_string(args->dnode, "./vrf");
366
367 nh = nb_running_get_entry(args->dnode, NULL, true);
368
369 pn_dnode = yang_dnode_get_parent(args->dnode, "path-list");
370 pn = nb_running_get_entry(pn_dnode, NULL, true);
371
372 rn_dnode = yang_dnode_get_parent(pn_dnode, "route-list");
373 rn = nb_running_get_entry(rn_dnode, NULL, true);
374 info = route_table_get_info(rn->table);
375
376 static_install_nexthop(rn, pn, nh, info->safi, info->svrf, ifname,
377 nh_type, nh_vrf);
378 }
379
380
381 void routing_control_plane_protocols_control_plane_protocol_staticd_route_list_src_list_path_list_frr_nexthops_nexthop_apply_finish(
382 struct nb_cb_apply_finish_args *args)
383 {
384 struct static_nexthop *nh;
385 struct static_path *pn;
386 struct route_node *rn;
387 struct route_node *src_rn;
388 const struct lyd_node *pn_dnode;
389 const struct lyd_node *rn_dnode;
390 const struct lyd_node *src_dnode;
391 const char *ifname;
392 const char *nh_vrf;
393 struct stable_info *info;
394 int nh_type;
395
396 nh_type = yang_dnode_get_enum(args->dnode, "./nh-type");
397 ifname = yang_dnode_get_string(args->dnode, "./interface");
398 nh_vrf = yang_dnode_get_string(args->dnode, "./vrf");
399
400 nh = nb_running_get_entry(args->dnode, NULL, true);
401
402 pn_dnode = yang_dnode_get_parent(args->dnode, "path-list");
403 pn = nb_running_get_entry(pn_dnode, NULL, true);
404
405 src_dnode = yang_dnode_get_parent(pn_dnode, "src-list");
406 src_rn = nb_running_get_entry(src_dnode, NULL, true);
407
408 rn_dnode = yang_dnode_get_parent(src_dnode, "route-list");
409 rn = nb_running_get_entry(rn_dnode, NULL, true);
410 info = route_table_get_info(rn->table);
411
412 static_install_nexthop(src_rn, pn, nh, info->safi, info->svrf, ifname,
413 nh_type, nh_vrf);
414 }
415 int routing_control_plane_protocols_control_plane_protocol_staticd_route_list_path_list_frr_nexthops_nexthop_pre_validate(
416 struct nb_cb_pre_validate_args *args)
417 {
418 const struct lyd_node *mls_dnode;
419 uint32_t count;
420
421 mls_dnode = yang_dnode_get(args->dnode, "./mpls-label-stack");
422 count = yang_get_list_elements_count(yang_dnode_get_child(mls_dnode));
423
424 if (count > MPLS_MAX_LABELS) {
425 snprintf(args->errmsg, args->errmsg_len,
426 "Too many labels, Enter %d or fewer",
427 MPLS_MAX_LABELS);
428 return NB_ERR_VALIDATION;
429 }
430 return NB_OK;
431 }
432
433 int routing_control_plane_protocols_name_validate(
434 struct nb_cb_create_args *args)
435 {
436 const char *name;
437
438 name = yang_dnode_get_string(args->dnode, "./name");
439 if (!strmatch(name, "staticd")) {
440 snprintf(args->errmsg, args->errmsg_len,
441 "static routing supports only one instance with name staticd");
442 return NB_ERR_VALIDATION;
443 }
444 return NB_OK;
445 }
446 /*
447 * XPath:
448 * /frr-routing:routing/control-plane-protocols/control-plane-protocol/frr-staticd:staticd/route-list
449 */
450 int routing_control_plane_protocols_control_plane_protocol_staticd_route_list_create(
451 struct nb_cb_create_args *args)
452 {
453 struct vrf *vrf;
454 struct static_vrf *s_vrf;
455 struct route_node *rn;
456 const struct lyd_node *vrf_dnode;
457 struct prefix prefix;
458 const char *afi_safi;
459 afi_t prefix_afi;
460 afi_t afi;
461 safi_t safi;
462
463 switch (args->event) {
464 case NB_EV_VALIDATE:
465 yang_dnode_get_prefix(&prefix, args->dnode, "./prefix");
466 afi_safi = yang_dnode_get_string(args->dnode, "./afi-safi");
467 yang_afi_safi_identity2value(afi_safi, &afi, &safi);
468 prefix_afi = family2afi(prefix.family);
469 if (afi != prefix_afi) {
470 flog_warn(
471 EC_LIB_NB_CB_CONFIG_VALIDATE,
472 "route node %s creation failed",
473 yang_dnode_get_string(args->dnode, "./prefix"));
474 return NB_ERR_VALIDATION;
475 }
476 break;
477 case NB_EV_PREPARE:
478 case NB_EV_ABORT:
479 break;
480 case NB_EV_APPLY:
481 vrf_dnode = yang_dnode_get_parent(args->dnode,
482 "control-plane-protocol");
483 vrf = nb_running_get_entry(vrf_dnode, NULL, true);
484 s_vrf = vrf->info;
485
486 yang_dnode_get_prefix(&prefix, args->dnode, "./prefix");
487 afi_safi = yang_dnode_get_string(args->dnode, "./afi-safi");
488 yang_afi_safi_identity2value(afi_safi, &afi, &safi);
489
490 rn = static_add_route(afi, safi, &prefix, NULL, s_vrf);
491 if (!rn) {
492 flog_warn(
493 EC_LIB_NB_CB_CONFIG_APPLY,
494 "route node %s creation failed",
495 yang_dnode_get_string(args->dnode, "./prefix"));
496 return NB_ERR;
497 }
498 if (vrf->vrf_id == VRF_UNKNOWN)
499 snprintf(
500 args->errmsg, args->errmsg_len,
501 "Static Route to %s not installed currently because dependent config not fully available",
502 yang_dnode_get_string(args->dnode, "./prefix"));
503 nb_running_set_entry(args->dnode, rn);
504 break;
505 }
506 return NB_OK;
507 }
508
509 int routing_control_plane_protocols_control_plane_protocol_staticd_route_list_destroy(
510 struct nb_cb_destroy_args *args)
511 {
512 struct route_node *rn;
513 struct stable_info *info;
514
515 switch (args->event) {
516 case NB_EV_VALIDATE:
517 case NB_EV_PREPARE:
518 case NB_EV_ABORT:
519 break;
520 case NB_EV_APPLY:
521 rn = nb_running_unset_entry(args->dnode);
522 info = route_table_get_info(rn->table);
523 static_del_route(rn, info->safi, info->svrf);
524 break;
525 }
526 return NB_OK;
527 }
528
529 /*
530 * XPath:
531 * /frr-routing:routing/control-plane-protocols/control-plane-protocol/frr-staticd:staticd/route-list/path-list
532 */
533 int routing_control_plane_protocols_control_plane_protocol_staticd_route_list_path_list_create(
534 struct nb_cb_create_args *args)
535 {
536 return static_path_list_create(args);
537 }
538
539 int routing_control_plane_protocols_control_plane_protocol_staticd_route_list_path_list_destroy(
540 struct nb_cb_destroy_args *args)
541 {
542 const struct lyd_node *rn_dnode;
543 struct route_node *rn;
544 struct stable_info *info;
545
546 switch (args->event) {
547 case NB_EV_VALIDATE:
548 case NB_EV_PREPARE:
549 case NB_EV_ABORT:
550 break;
551 case NB_EV_APPLY:
552 rn_dnode = yang_dnode_get_parent(args->dnode, "route-list");
553 rn = nb_running_get_entry(rn_dnode, NULL, true);
554 info = route_table_get_info(rn->table);
555 static_path_list_destroy(args, rn_dnode, info);
556 break;
557 }
558 return NB_OK;
559 }
560
561 /*
562 * XPath:
563 * /frr-routing:routing/control-plane-protocols/control-plane-protocol/frr-staticd:staticd/route-list/path-list/tag
564 */
565 int routing_control_plane_protocols_control_plane_protocol_staticd_route_list_path_list_tag_modify(
566 struct nb_cb_modify_args *args)
567 {
568 struct stable_info *info;
569 struct route_node *rn;
570 const struct lyd_node *rn_dnode;
571
572 switch (args->event) {
573 case NB_EV_VALIDATE:
574 case NB_EV_ABORT:
575 case NB_EV_PREPARE:
576 break;
577 case NB_EV_APPLY:
578 rn_dnode = yang_dnode_get_parent(args->dnode, "route-list");
579 rn = nb_running_get_entry(rn_dnode, NULL, true);
580 info = route_table_get_info(rn->table);
581 static_path_list_tag_modify(args, rn_dnode, info);
582 break;
583 }
584
585 return NB_OK;
586 }
587
588 /*
589 * XPath:
590 * /frr-routing:routing/control-plane-protocols/control-plane-protocol/frr-staticd:staticd/route-list/path-list/frr-nexthops/nexthop
591 */
592 int routing_control_plane_protocols_control_plane_protocol_staticd_route_list_path_list_frr_nexthops_nexthop_create(
593 struct nb_cb_create_args *args)
594 {
595 struct route_node *rn;
596 const struct lyd_node *rn_dnode;
597 struct stable_info *info;
598
599 switch (args->event) {
600 case NB_EV_VALIDATE:
601 rn_dnode = yang_dnode_get_parent(args->dnode, "route-list");
602 if (static_nexthop_create(args, rn_dnode, NULL) != NB_OK)
603 return NB_ERR_VALIDATION;
604 break;
605 case NB_EV_PREPARE:
606 case NB_EV_ABORT:
607 break;
608 case NB_EV_APPLY:
609 rn_dnode = yang_dnode_get_parent(args->dnode, "route-list");
610 rn = nb_running_get_entry(rn_dnode, NULL, true);
611 info = route_table_get_info(rn->table);
612
613 if (static_nexthop_create(args, rn_dnode, info) != NB_OK)
614 return NB_ERR_INCONSISTENCY;
615 break;
616 }
617 return NB_OK;
618 }
619
620 int routing_control_plane_protocols_control_plane_protocol_staticd_route_list_path_list_frr_nexthops_nexthop_destroy(
621 struct nb_cb_destroy_args *args)
622 {
623 struct route_node *rn;
624 const struct lyd_node *rn_dnode;
625 struct stable_info *info;
626
627 switch (args->event) {
628 case NB_EV_VALIDATE:
629 case NB_EV_PREPARE:
630 case NB_EV_ABORT:
631 break;
632 case NB_EV_APPLY:
633 rn_dnode = yang_dnode_get_parent(args->dnode, "route-list");
634 rn = nb_running_get_entry(rn_dnode, NULL, true);
635 info = route_table_get_info(rn->table);
636
637 if (static_nexthop_destroy(args, rn_dnode, info) != NB_OK)
638 return NB_ERR;
639 break;
640 }
641 return NB_OK;
642 }
643
644 /*
645 * XPath:
646 * /frr-routing:routing/control-plane-protocols/control-plane-protocol/frr-staticd:staticd/route-list/path-list/frr-nexthops/nexthop/bh-type
647 */
648 int routing_control_plane_protocols_control_plane_protocol_staticd_route_list_path_list_frr_nexthops_nexthop_bh_type_modify(
649 struct nb_cb_modify_args *args)
650 {
651 return static_nexthop_bh_type_modify(args);
652 }
653
654 int routing_control_plane_protocols_control_plane_protocol_staticd_route_list_path_list_frr_nexthops_nexthop_bh_type_destroy(
655 struct nb_cb_destroy_args *args)
656 {
657 /* blackhole type has a boolean type with default value,
658 * so no need to do any operations in destroy callback
659 */
660 switch (args->event) {
661 case NB_EV_VALIDATE:
662 case NB_EV_PREPARE:
663 case NB_EV_ABORT:
664 case NB_EV_APPLY:
665 break;
666 }
667 return NB_OK;
668 }
669
670 /*
671 * XPath:
672 * /frr-routing:routing/control-plane-protocols/control-plane-protocol/frr-staticd:staticd/route-list/path-list/frr-nexthops/nexthop/onlink
673 */
674 int routing_control_plane_protocols_control_plane_protocol_staticd_route_list_path_list_frr_nexthops_nexthop_onlink_modify(
675 struct nb_cb_modify_args *args)
676 {
677 return static_nexthop_onlink_modify(args);
678 }
679
680 /*
681 * XPath:
682 * /frr-routing:routing/control-plane-protocols/control-plane-protocol/frr-staticd:staticd/route-list/path-list/frr-nexthops/nexthop/srte-color
683 */
684 int routing_control_plane_protocols_control_plane_protocol_staticd_route_list_path_list_frr_nexthops_nexthop_color_modify(
685 struct nb_cb_modify_args *args)
686 {
687 switch (args->event) {
688 case NB_EV_VALIDATE:
689 case NB_EV_PREPARE:
690 case NB_EV_ABORT:
691 break;
692 case NB_EV_APPLY:
693 if (static_nexthop_color_modify(args) != NB_OK)
694 return NB_ERR;
695
696 break;
697 }
698 return NB_OK;
699 }
700
701 int routing_control_plane_protocols_control_plane_protocol_staticd_route_list_path_list_frr_nexthops_nexthop_color_destroy(
702 struct nb_cb_destroy_args *args)
703 {
704 switch (args->event) {
705 case NB_EV_VALIDATE:
706 case NB_EV_PREPARE:
707 case NB_EV_ABORT:
708 break;
709 case NB_EV_APPLY:
710 if (static_nexthop_color_destroy(args) != NB_OK)
711 return NB_ERR;
712 break;
713 }
714 return NB_OK;
715 }
716
717 /*
718 * XPath:
719 * /frr-routing:routing/control-plane-protocols/control-plane-protocol/frr-staticd:staticd/route-list/path-list/frr-nexthops/nexthop/mpls-label-stack/entry
720 */
721 int routing_control_plane_protocols_control_plane_protocol_staticd_route_list_path_list_frr_nexthops_nexthop_mpls_label_stack_entry_create(
722 struct nb_cb_create_args *args)
723 {
724 return nexthop_mpls_label_stack_entry_create(args);
725 }
726
727 int routing_control_plane_protocols_control_plane_protocol_staticd_route_list_path_list_frr_nexthops_nexthop_mpls_label_stack_entry_destroy(
728 struct nb_cb_destroy_args *args)
729 {
730 return nexthop_mpls_label_stack_entry_destroy(args);
731 }
732
733 /*
734 * XPath:
735 * /frr-routing:routing/control-plane-protocols/control-plane-protocol/frr-staticd:staticd/route-list/path-list/frr-nexthops/nexthop/mpls-label-stack/entry/label
736 */
737 int routing_control_plane_protocols_control_plane_protocol_staticd_route_list_path_list_frr_nexthops_nexthop_mpls_label_stack_entry_label_modify(
738 struct nb_cb_modify_args *args)
739 {
740 switch (args->event) {
741 case NB_EV_VALIDATE:
742 case NB_EV_PREPARE:
743 case NB_EV_ABORT:
744 break;
745 case NB_EV_APPLY:
746 if (static_nexthop_mpls_label_modify(args) != NB_OK)
747 return NB_ERR;
748 break;
749 }
750 return NB_OK;
751 }
752
753 int routing_control_plane_protocols_control_plane_protocol_staticd_route_list_path_list_frr_nexthops_nexthop_mpls_label_stack_entry_label_destroy(
754 struct nb_cb_destroy_args *args)
755 {
756 /*
757 * No operation is required in this call back.
758 * nexthop_mpls_label_stack_entry_destroy() will take care
759 * to reset the label vaue.
760 */
761 switch (args->event) {
762 case NB_EV_VALIDATE:
763 case NB_EV_PREPARE:
764 case NB_EV_ABORT:
765 case NB_EV_APPLY:
766 break;
767 }
768 return NB_OK;
769 }
770
771 /*
772 * XPath:
773 * /frr-routing:routing/control-plane-protocols/control-plane-protocol/frr-staticd:staticd/route-list/path-list/frr-nexthops/nexthop/mpls-label-stack/entry/ttl
774 */
775 int routing_control_plane_protocols_control_plane_protocol_staticd_route_list_path_list_frr_nexthops_nexthop_mpls_label_stack_entry_ttl_modify(
776 struct nb_cb_modify_args *args)
777 {
778 switch (args->event) {
779 case NB_EV_VALIDATE:
780 case NB_EV_PREPARE:
781 case NB_EV_ABORT:
782 case NB_EV_APPLY:
783 break;
784 }
785
786 return NB_OK;
787 }
788
789 int routing_control_plane_protocols_control_plane_protocol_staticd_route_list_path_list_frr_nexthops_nexthop_mpls_label_stack_entry_ttl_destroy(
790 struct nb_cb_destroy_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 /*
804 * XPath:
805 * /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
806 */
807 int routing_control_plane_protocols_control_plane_protocol_staticd_route_list_path_list_frr_nexthops_nexthop_mpls_label_stack_entry_traffic_class_modify(
808 struct nb_cb_modify_args *args)
809 {
810 switch (args->event) {
811 case NB_EV_VALIDATE:
812 case NB_EV_PREPARE:
813 case NB_EV_ABORT:
814 case NB_EV_APPLY:
815 break;
816 }
817
818 return NB_OK;
819 }
820
821 int routing_control_plane_protocols_control_plane_protocol_staticd_route_list_path_list_frr_nexthops_nexthop_mpls_label_stack_entry_traffic_class_destroy(
822 struct nb_cb_destroy_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 /*
836 * XPath:
837 * /frr-routing:routing/control-plane-protocols/control-plane-protocol/frr-staticd:staticd/route-list/src-list
838 */
839 int routing_control_plane_protocols_control_plane_protocol_staticd_route_list_src_list_create(
840 struct nb_cb_create_args *args)
841 {
842 struct static_vrf *s_vrf;
843 struct route_node *rn;
844 struct route_node *src_rn;
845 struct prefix_ipv6 src_prefix = {};
846 struct stable_info *info;
847 afi_t afi;
848 safi_t safi = SAFI_UNICAST;
849
850 switch (args->event) {
851 case NB_EV_VALIDATE:
852 case NB_EV_PREPARE:
853 case NB_EV_ABORT:
854 break;
855 case NB_EV_APPLY:
856 rn = nb_running_get_entry(args->dnode, NULL, true);
857 info = route_table_get_info(rn->table);
858 s_vrf = info->svrf;
859 yang_dnode_get_ipv6p(&src_prefix, args->dnode, "./src-prefix");
860 afi = family2afi(src_prefix.family);
861 src_rn =
862 static_add_route(afi, safi, &rn->p, &src_prefix, s_vrf);
863 if (!src_rn) {
864 flog_warn(EC_LIB_NB_CB_CONFIG_APPLY,
865 "src rn %s creation failed",
866 yang_dnode_get_string(args->dnode,
867 "./src-prefix"));
868 return NB_ERR;
869 }
870 nb_running_set_entry(args->dnode, src_rn);
871 break;
872 }
873 return NB_OK;
874 }
875
876 int routing_control_plane_protocols_control_plane_protocol_staticd_route_list_src_list_destroy(
877 struct nb_cb_destroy_args *args)
878 {
879 struct route_node *src_rn;
880 struct route_node *rn;
881 struct stable_info *info;
882 const struct lyd_node *rn_dnode;
883
884 switch (args->event) {
885 case NB_EV_VALIDATE:
886 case NB_EV_PREPARE:
887 case NB_EV_ABORT:
888 break;
889 case NB_EV_APPLY:
890 src_rn = nb_running_unset_entry(args->dnode);
891 rn_dnode = yang_dnode_get_parent(args->dnode, "route-list");
892 rn = nb_running_get_entry(rn_dnode, NULL, true);
893 info = route_table_get_info(rn->table);
894 static_del_route(src_rn, info->safi, info->svrf);
895 break;
896 }
897
898 return NB_OK;
899 }
900
901 /*
902 * XPath:
903 * /frr-routing:routing/control-plane-protocols/control-plane-protocol/frr-staticd:staticd/route-list/src-list/path-list
904 */
905 int routing_control_plane_protocols_control_plane_protocol_staticd_route_list_src_list_path_list_create(
906 struct nb_cb_create_args *args)
907 {
908 return static_path_list_create(args);
909 }
910
911 int routing_control_plane_protocols_control_plane_protocol_staticd_route_list_src_list_path_list_destroy(
912 struct nb_cb_destroy_args *args)
913 {
914 struct route_node *rn;
915 const struct lyd_node *rn_dnode;
916 const struct lyd_node *srn_dnode;
917 struct stable_info *info;
918
919 switch (args->event) {
920 case NB_EV_VALIDATE:
921 case NB_EV_PREPARE:
922 case NB_EV_ABORT:
923 break;
924 case NB_EV_APPLY:
925 srn_dnode = yang_dnode_get_parent(args->dnode, "src-list");
926 rn_dnode = yang_dnode_get_parent(srn_dnode, "route-list");
927 rn = nb_running_get_entry(rn_dnode, NULL, true);
928 info = route_table_get_info(rn->table);
929 static_path_list_destroy(args, srn_dnode, info);
930 break;
931 }
932 return NB_OK;
933 }
934
935 /*
936 * XPath:
937 * /frr-routing:routing/control-plane-protocols/control-plane-protocol/frr-staticd:staticd/route-list/src-list/path-list/tag
938 */
939 int routing_control_plane_protocols_control_plane_protocol_staticd_route_list_src_list_path_list_tag_modify(
940 struct nb_cb_modify_args *args)
941 {
942 struct stable_info *info;
943 struct route_node *rn;
944 const struct lyd_node *srn_dnode;
945 const struct lyd_node *rn_dnode;
946
947 switch (args->event) {
948 case NB_EV_VALIDATE:
949 case NB_EV_ABORT:
950 case NB_EV_PREPARE:
951 break;
952 case NB_EV_APPLY:
953 srn_dnode = yang_dnode_get_parent(args->dnode, "src-list");
954 rn_dnode = yang_dnode_get_parent(srn_dnode, "route-list");
955 rn = nb_running_get_entry(rn_dnode, NULL, true);
956 info = route_table_get_info(rn->table);
957 static_path_list_tag_modify(args, srn_dnode, info);
958 break;
959 }
960 return NB_OK;
961 }
962
963 /*
964 * XPath:
965 * /frr-routing:routing/control-plane-protocols/control-plane-protocol/frr-staticd:staticd/route-list/src-list/path-list/frr-nexthops/nexthop
966 */
967 int routing_control_plane_protocols_control_plane_protocol_staticd_route_list_src_list_path_list_frr_nexthops_nexthop_create(
968 struct nb_cb_create_args *args)
969 {
970 struct route_node *rn;
971 const struct lyd_node *rn_dnode;
972 const struct lyd_node *src_dnode;
973 struct stable_info *info;
974
975 switch (args->event) {
976 case NB_EV_VALIDATE:
977 rn_dnode = yang_dnode_get_parent(args->dnode, "route-list");
978 if (static_nexthop_create(args, rn_dnode, NULL) != NB_OK)
979 return NB_ERR_VALIDATION;
980 break;
981 case NB_EV_PREPARE:
982 case NB_EV_ABORT:
983 break;
984 case NB_EV_APPLY:
985 src_dnode = yang_dnode_get_parent(args->dnode, "src-list");
986 rn_dnode = yang_dnode_get_parent(src_dnode, "route-list");
987 rn = nb_running_get_entry(rn_dnode, NULL, true);
988 info = route_table_get_info(rn->table);
989
990 if (static_nexthop_create(args, src_dnode, info) != NB_OK)
991 return NB_ERR_VALIDATION;
992
993 break;
994 }
995 return NB_OK;
996 }
997
998 int routing_control_plane_protocols_control_plane_protocol_staticd_route_list_src_list_path_list_frr_nexthops_nexthop_destroy(
999 struct nb_cb_destroy_args *args)
1000 {
1001 struct route_node *rn;
1002 const struct lyd_node *rn_dnode;
1003 const struct lyd_node *src_dnode;
1004 struct stable_info *info;
1005
1006 switch (args->event) {
1007 case NB_EV_VALIDATE:
1008 case NB_EV_PREPARE:
1009 case NB_EV_ABORT:
1010 break;
1011 case NB_EV_APPLY:
1012 src_dnode = yang_dnode_get_parent(args->dnode, "src-list");
1013 rn_dnode = yang_dnode_get_parent(src_dnode, "route-list");
1014 rn = nb_running_get_entry(rn_dnode, NULL, true);
1015 info = route_table_get_info(rn->table);
1016
1017 if (static_nexthop_destroy(args, rn_dnode, info) != NB_OK)
1018 return NB_ERR;
1019 break;
1020 }
1021 return NB_OK;
1022 }
1023
1024 /*
1025 * XPath:
1026 * /frr-routing:routing/control-plane-protocols/control-plane-protocol/frr-staticd:staticd/route-list/src-list/path-list/frr-nexthops/nexthop/bh-type
1027 */
1028 int routing_control_plane_protocols_control_plane_protocol_staticd_route_list_src_list_path_list_frr_nexthops_nexthop_bh_type_modify(
1029 struct nb_cb_modify_args *args)
1030 {
1031 return static_nexthop_bh_type_modify(args);
1032 }
1033
1034 int routing_control_plane_protocols_control_plane_protocol_staticd_route_list_src_list_path_list_frr_nexthops_nexthop_bh_type_destroy(
1035 struct nb_cb_destroy_args *args)
1036 {
1037 /* blackhole type has a boolean type with default value,
1038 * so no need to do any operations in destroy callback
1039 */
1040 switch (args->event) {
1041 case NB_EV_VALIDATE:
1042 case NB_EV_PREPARE:
1043 case NB_EV_ABORT:
1044 case NB_EV_APPLY:
1045 break;
1046 }
1047
1048 return NB_OK;
1049 }
1050
1051 /*
1052 * XPath:
1053 * /frr-routing:routing/control-plane-protocols/control-plane-protocol/frr-staticd:staticd/route-list/src-list/path-list/frr-nexthops/nexthop/onlink
1054 */
1055 int routing_control_plane_protocols_control_plane_protocol_staticd_route_list_src_list_path_list_frr_nexthops_nexthop_onlink_modify(
1056 struct nb_cb_modify_args *args)
1057 {
1058 return static_nexthop_onlink_modify(args);
1059 }
1060
1061 /*
1062 * XPath:
1063 * /frr-routing:routing/control-plane-protocols/control-plane-protocol/frr-staticd:staticd/route-list/src-list/path-list/frr-nexthops/nexthop/srte-color
1064 */
1065 int routing_control_plane_protocols_control_plane_protocol_staticd_route_list_src_list_path_list_frr_nexthops_nexthop_color_modify(
1066 struct nb_cb_modify_args *args)
1067 {
1068 switch (args->event) {
1069 case NB_EV_VALIDATE:
1070 case NB_EV_PREPARE:
1071 case NB_EV_ABORT:
1072 break;
1073 case NB_EV_APPLY:
1074 if (static_nexthop_color_modify(args) != NB_OK)
1075 return NB_ERR;
1076
1077 break;
1078 }
1079 return NB_OK;
1080 }
1081
1082
1083 int routing_control_plane_protocols_control_plane_protocol_staticd_route_list_src_list_path_list_frr_nexthops_nexthop_color_destroy(
1084 struct nb_cb_destroy_args *args)
1085 {
1086 switch (args->event) {
1087 case NB_EV_VALIDATE:
1088 case NB_EV_PREPARE:
1089 case NB_EV_ABORT:
1090 break;
1091 case NB_EV_APPLY:
1092 if (static_nexthop_color_destroy(args) != NB_OK)
1093 return NB_ERR;
1094 break;
1095 }
1096 return NB_OK;
1097 }
1098
1099 /*
1100 * XPath:
1101 * /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
1102 */
1103 int routing_control_plane_protocols_control_plane_protocol_staticd_route_list_src_list_path_list_frr_nexthops_nexthop_mpls_label_stack_entry_create(
1104 struct nb_cb_create_args *args)
1105 {
1106 return nexthop_mpls_label_stack_entry_create(args);
1107 }
1108
1109 int routing_control_plane_protocols_control_plane_protocol_staticd_route_list_src_list_path_list_frr_nexthops_nexthop_mpls_label_stack_entry_destroy(
1110 struct nb_cb_destroy_args *args)
1111 {
1112 return nexthop_mpls_label_stack_entry_destroy(args);
1113 }
1114
1115 /*
1116 * XPath:
1117 * /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
1118 */
1119 int routing_control_plane_protocols_control_plane_protocol_staticd_route_list_src_list_path_list_frr_nexthops_nexthop_mpls_label_stack_entry_label_modify(
1120 struct nb_cb_modify_args *args)
1121 {
1122 switch (args->event) {
1123 case NB_EV_VALIDATE:
1124 case NB_EV_PREPARE:
1125 case NB_EV_ABORT:
1126 break;
1127 case NB_EV_APPLY:
1128 if (static_nexthop_mpls_label_modify(args) != NB_OK)
1129 return NB_ERR;
1130 break;
1131 }
1132 return NB_OK;
1133 }
1134
1135 int routing_control_plane_protocols_control_plane_protocol_staticd_route_list_src_list_path_list_frr_nexthops_nexthop_mpls_label_stack_entry_label_destroy(
1136 struct nb_cb_destroy_args *args)
1137 {
1138 /*
1139 * No operation is required in this call back.
1140 * nexthop_mpls_label_stack_entry_destroy() will take care
1141 * to reset the label vaue.
1142 */
1143 switch (args->event) {
1144 case NB_EV_VALIDATE:
1145 case NB_EV_PREPARE:
1146 case NB_EV_ABORT:
1147 case NB_EV_APPLY:
1148 break;
1149 }
1150 return NB_OK;
1151 }
1152
1153 /*
1154 * XPath:
1155 * /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
1156 */
1157 int routing_control_plane_protocols_control_plane_protocol_staticd_route_list_src_list_path_list_frr_nexthops_nexthop_mpls_label_stack_entry_ttl_modify(
1158 struct nb_cb_modify_args *args)
1159 {
1160 switch (args->event) {
1161 case NB_EV_VALIDATE:
1162 case NB_EV_PREPARE:
1163 case NB_EV_ABORT:
1164 case NB_EV_APPLY:
1165 break;
1166 }
1167
1168 return NB_OK;
1169 }
1170
1171 int routing_control_plane_protocols_control_plane_protocol_staticd_route_list_src_list_path_list_frr_nexthops_nexthop_mpls_label_stack_entry_ttl_destroy(
1172 struct nb_cb_destroy_args *args)
1173 {
1174 switch (args->event) {
1175 case NB_EV_VALIDATE:
1176 case NB_EV_PREPARE:
1177 case NB_EV_ABORT:
1178 case NB_EV_APPLY:
1179 break;
1180 }
1181
1182 return NB_OK;
1183 }
1184
1185 /*
1186 * XPath:
1187 * /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
1188 */
1189 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(
1190 struct nb_cb_modify_args *args)
1191 {
1192 switch (args->event) {
1193 case NB_EV_VALIDATE:
1194 case NB_EV_PREPARE:
1195 case NB_EV_ABORT:
1196 case NB_EV_APPLY:
1197 break;
1198 }
1199
1200 return NB_OK;
1201 }
1202
1203 int routing_control_plane_protocols_control_plane_protocol_staticd_route_list_src_list_path_list_frr_nexthops_nexthop_mpls_label_stack_entry_traffic_class_destroy(
1204 struct nb_cb_destroy_args *args)
1205 {
1206 switch (args->event) {
1207 case NB_EV_VALIDATE:
1208 case NB_EV_PREPARE:
1209 case NB_EV_ABORT:
1210 case NB_EV_APPLY:
1211 break;
1212 }
1213
1214 return NB_OK;
1215 }