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