2 * Copyright (C) 1997, 1998, 1999 Kunihiro Ishiguro <kunihiro@zebra.org>
3 * Copyright (C) 2018 NetDEF, Inc.
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License as published by the Free
8 * Software Foundation; either version 2 of the License, or (at your option)
11 * This program is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
16 * You should have received a copy of the GNU General Public License along
17 * with this program; see the file COPYING; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
30 #include "northbound.h"
33 #include "ripd/ripd.h"
34 #include "ripd/rip_cli.h"
37 * XPath: /frr-ripd:ripd/instance
39 static int ripd_instance_create(enum nb_event event
,
40 const struct lyd_node
*dnode
,
41 union nb_resource
*resource
)
49 socket
= rip_create_socket();
51 return NB_ERR_RESOURCE
;
52 resource
->fd
= socket
;
55 socket
= resource
->fd
;
59 socket
= resource
->fd
;
67 static int ripd_instance_delete(enum nb_event event
,
68 const struct lyd_node
*dnode
)
70 if (event
!= NB_EV_APPLY
)
79 * XPath: /frr-ripd:ripd/instance/allow-ecmp
81 static int ripd_instance_allow_ecmp_modify(enum nb_event event
,
82 const struct lyd_node
*dnode
,
83 union nb_resource
*resource
)
85 if (event
!= NB_EV_APPLY
)
88 rip
->ecmp
= yang_dnode_get_bool(dnode
, NULL
);
96 * XPath: /frr-ripd:ripd/instance/default-information-originate
99 ripd_instance_default_information_originate_modify(enum nb_event event
,
100 const struct lyd_node
*dnode
,
101 union nb_resource
*resource
)
103 bool default_information
;
104 struct prefix_ipv4 p
;
106 if (event
!= NB_EV_APPLY
)
109 default_information
= yang_dnode_get_bool(dnode
, NULL
);
111 memset(&p
, 0, sizeof(struct prefix_ipv4
));
113 if (default_information
) {
116 memset(&nh
, 0, sizeof(nh
));
117 nh
.type
= NEXTHOP_TYPE_IPV4
;
118 rip_redistribute_add(ZEBRA_ROUTE_RIP
, RIP_ROUTE_DEFAULT
, &p
,
121 rip_redistribute_delete(ZEBRA_ROUTE_RIP
, RIP_ROUTE_DEFAULT
, &p
,
129 * XPath: /frr-ripd:ripd/instance/default-metric
131 static int ripd_instance_default_metric_modify(enum nb_event event
,
132 const struct lyd_node
*dnode
,
133 union nb_resource
*resource
)
135 if (event
!= NB_EV_APPLY
)
138 rip
->default_metric
= yang_dnode_get_uint8(dnode
, NULL
);
139 /* rip_update_default_metric (); */
145 * XPath: /frr-ripd:ripd/instance/distance/default
147 static int ripd_instance_distance_default_modify(enum nb_event event
,
148 const struct lyd_node
*dnode
,
149 union nb_resource
*resource
)
151 if (event
!= NB_EV_APPLY
)
154 rip
->distance
= yang_dnode_get_uint8(dnode
, NULL
);
160 * XPath: /frr-ripd:ripd/instance/distance/source
162 static int ripd_instance_distance_source_create(enum nb_event event
,
163 const struct lyd_node
*dnode
,
164 union nb_resource
*resource
)
166 struct prefix_ipv4 prefix
;
167 struct route_node
*rn
;
169 if (event
!= NB_EV_APPLY
)
172 yang_dnode_get_ipv4p(&prefix
, dnode
, "./prefix");
173 apply_mask_ipv4(&prefix
);
175 /* Get RIP distance node. */
176 rn
= route_node_get(rip_distance_table
, (struct prefix
*)&prefix
);
177 rn
->info
= rip_distance_new();
178 yang_dnode_set_entry(dnode
, rn
);
183 static int ripd_instance_distance_source_delete(enum nb_event event
,
184 const struct lyd_node
*dnode
)
186 struct route_node
*rn
;
187 struct rip_distance
*rdistance
;
189 if (event
!= NB_EV_APPLY
)
192 rn
= yang_dnode_get_entry(dnode
, true);
193 rdistance
= rn
->info
;
194 if (rdistance
->access_list
)
195 free(rdistance
->access_list
);
196 rip_distance_free(rdistance
);
199 route_unlock_node(rn
);
205 * XPath: /frr-ripd:ripd/instance/distance/source/distance
208 ripd_instance_distance_source_distance_modify(enum nb_event event
,
209 const struct lyd_node
*dnode
,
210 union nb_resource
*resource
)
212 struct route_node
*rn
;
214 struct rip_distance
*rdistance
;
216 if (event
!= NB_EV_APPLY
)
219 /* Set distance value. */
220 rn
= yang_dnode_get_entry(dnode
, true);
221 distance
= yang_dnode_get_uint8(dnode
, NULL
);
222 rdistance
= rn
->info
;
223 rdistance
->distance
= distance
;
229 * XPath: /frr-ripd:ripd/instance/distance/source/access-list
232 ripd_instance_distance_source_access_list_modify(enum nb_event event
,
233 const struct lyd_node
*dnode
,
234 union nb_resource
*resource
)
236 const char *acl_name
;
237 struct route_node
*rn
;
238 struct rip_distance
*rdistance
;
240 if (event
!= NB_EV_APPLY
)
243 acl_name
= yang_dnode_get_string(dnode
, NULL
);
245 /* Set access-list */
246 rn
= yang_dnode_get_entry(dnode
, true);
247 rdistance
= rn
->info
;
248 if (rdistance
->access_list
)
249 free(rdistance
->access_list
);
250 rdistance
->access_list
= strdup(acl_name
);
256 ripd_instance_distance_source_access_list_delete(enum nb_event event
,
257 const struct lyd_node
*dnode
)
259 struct route_node
*rn
;
260 struct rip_distance
*rdistance
;
262 if (event
!= NB_EV_APPLY
)
265 /* Reset access-list configuration. */
266 rn
= yang_dnode_get_entry(dnode
, true);
267 rdistance
= rn
->info
;
268 free(rdistance
->access_list
);
269 rdistance
->access_list
= NULL
;
275 * XPath: /frr-ripd:ripd/instance/explicit-neighbor
277 static int ripd_instance_explicit_neighbor_create(enum nb_event event
,
278 const struct lyd_node
*dnode
,
279 union nb_resource
*resource
)
281 struct prefix_ipv4 p
;
283 if (event
!= NB_EV_APPLY
)
287 p
.prefixlen
= IPV4_MAX_BITLEN
;
288 yang_dnode_get_ipv4(&p
.prefix
, dnode
, NULL
);
290 return rip_neighbor_add(&p
);
293 static int ripd_instance_explicit_neighbor_delete(enum nb_event event
,
294 const struct lyd_node
*dnode
)
296 struct prefix_ipv4 p
;
298 if (event
!= NB_EV_APPLY
)
302 p
.prefixlen
= IPV4_MAX_BITLEN
;
303 yang_dnode_get_ipv4(&p
.prefix
, dnode
, NULL
);
305 return rip_neighbor_delete(&p
);
309 * XPath: /frr-ripd:ripd/instance/network
311 static int ripd_instance_network_create(enum nb_event event
,
312 const struct lyd_node
*dnode
,
313 union nb_resource
*resource
)
317 if (event
!= NB_EV_APPLY
)
320 yang_dnode_get_ipv4p(&p
, dnode
, NULL
);
321 apply_mask_ipv4((struct prefix_ipv4
*)&p
);
323 return rip_enable_network_add(&p
);
326 static int ripd_instance_network_delete(enum nb_event event
,
327 const struct lyd_node
*dnode
)
331 if (event
!= NB_EV_APPLY
)
334 yang_dnode_get_ipv4p(&p
, dnode
, NULL
);
335 apply_mask_ipv4((struct prefix_ipv4
*)&p
);
337 return rip_enable_network_delete(&p
);
341 * XPath: /frr-ripd:ripd/instance/interface
343 static int ripd_instance_interface_create(enum nb_event event
,
344 const struct lyd_node
*dnode
,
345 union nb_resource
*resource
)
349 if (event
!= NB_EV_APPLY
)
352 ifname
= yang_dnode_get_string(dnode
, NULL
);
354 return rip_enable_if_add(ifname
);
357 static int ripd_instance_interface_delete(enum nb_event event
,
358 const struct lyd_node
*dnode
)
362 if (event
!= NB_EV_APPLY
)
365 ifname
= yang_dnode_get_string(dnode
, NULL
);
367 return rip_enable_if_delete(ifname
);
371 * XPath: /frr-ripd:ripd/instance/offset-list
373 static int ripd_instance_offset_list_create(enum nb_event event
,
374 const struct lyd_node
*dnode
,
375 union nb_resource
*resource
)
378 struct rip_offset_list
*offset
;
380 if (event
!= NB_EV_APPLY
)
383 ifname
= yang_dnode_get_string(dnode
, "./interface");
385 offset
= rip_offset_list_new(ifname
);
386 yang_dnode_set_entry(dnode
, offset
);
391 static int ripd_instance_offset_list_delete(enum nb_event event
,
392 const struct lyd_node
*dnode
)
395 struct rip_offset_list
*offset
;
397 if (event
!= NB_EV_APPLY
)
400 direct
= yang_dnode_get_enum(dnode
, "./direction");
402 offset
= yang_dnode_get_entry(dnode
, true);
403 if (offset
->direct
[direct
].alist_name
) {
404 free(offset
->direct
[direct
].alist_name
);
405 offset
->direct
[direct
].alist_name
= NULL
;
407 if (offset
->direct
[RIP_OFFSET_LIST_IN
].alist_name
== NULL
408 && offset
->direct
[RIP_OFFSET_LIST_OUT
].alist_name
== NULL
)
409 offset_list_del(offset
);
415 * XPath: /frr-ripd:ripd/instance/offset-list/access-list
418 ripd_instance_offset_list_access_list_modify(enum nb_event event
,
419 const struct lyd_node
*dnode
,
420 union nb_resource
*resource
)
423 struct rip_offset_list
*offset
;
424 const char *alist_name
;
426 if (event
!= NB_EV_APPLY
)
429 direct
= yang_dnode_get_enum(dnode
, "../direction");
430 alist_name
= yang_dnode_get_string(dnode
, NULL
);
432 offset
= yang_dnode_get_entry(dnode
, true);
433 if (offset
->direct
[direct
].alist_name
)
434 free(offset
->direct
[direct
].alist_name
);
435 offset
->direct
[direct
].alist_name
= strdup(alist_name
);
441 * XPath: /frr-ripd:ripd/instance/offset-list/metric
443 static int ripd_instance_offset_list_metric_modify(enum nb_event event
,
444 const struct lyd_node
*dnode
,
445 union nb_resource
*resource
)
449 struct rip_offset_list
*offset
;
451 if (event
!= NB_EV_APPLY
)
454 direct
= yang_dnode_get_enum(dnode
, "../direction");
455 metric
= yang_dnode_get_uint8(dnode
, NULL
);
457 offset
= yang_dnode_get_entry(dnode
, true);
458 offset
->direct
[direct
].metric
= metric
;
464 * XPath: /frr-ripd:ripd/instance/passive-default
466 static int ripd_instance_passive_default_modify(enum nb_event event
,
467 const struct lyd_node
*dnode
,
468 union nb_resource
*resource
)
470 if (event
!= NB_EV_APPLY
)
473 rip
->passive_default
= yang_dnode_get_bool(dnode
, NULL
);
474 rip_passive_nondefault_clean();
480 * XPath: /frr-ripd:ripd/instance/passive-interface
482 static int ripd_instance_passive_interface_create(enum nb_event event
,
483 const struct lyd_node
*dnode
,
484 union nb_resource
*resource
)
488 if (event
!= NB_EV_APPLY
)
491 ifname
= yang_dnode_get_string(dnode
, NULL
);
493 return rip_passive_nondefault_set(ifname
);
496 static int ripd_instance_passive_interface_delete(enum nb_event event
,
497 const struct lyd_node
*dnode
)
501 if (event
!= NB_EV_APPLY
)
504 ifname
= yang_dnode_get_string(dnode
, NULL
);
506 return rip_passive_nondefault_unset(ifname
);
510 * XPath: /frr-ripd:ripd/instance/non-passive-interface
513 ripd_instance_non_passive_interface_create(enum nb_event event
,
514 const struct lyd_node
*dnode
,
515 union nb_resource
*resource
)
519 if (event
!= NB_EV_APPLY
)
522 ifname
= yang_dnode_get_string(dnode
, NULL
);
524 return rip_passive_nondefault_unset(ifname
);
528 ripd_instance_non_passive_interface_delete(enum nb_event event
,
529 const struct lyd_node
*dnode
)
533 if (event
!= NB_EV_APPLY
)
536 ifname
= yang_dnode_get_string(dnode
, NULL
);
538 return rip_passive_nondefault_set(ifname
);
542 * XPath: /frr-ripd:ripd/instance/redistribute
544 static int ripd_instance_redistribute_create(enum nb_event event
,
545 const struct lyd_node
*dnode
,
546 union nb_resource
*resource
)
551 static int ripd_instance_redistribute_delete(enum nb_event event
,
552 const struct lyd_node
*dnode
)
556 if (event
!= NB_EV_APPLY
)
559 type
= yang_dnode_get_enum(dnode
, "./protocol");
561 rip_redistribute_conf_delete(type
);
567 ripd_instance_redistribute_apply_finish(const struct lyd_node
*dnode
)
571 type
= yang_dnode_get_enum(dnode
, "./protocol");
572 rip_redistribute_conf_update(type
);
576 * XPath: /frr-ripd:ripd/instance/redistribute/route-map
579 ripd_instance_redistribute_route_map_modify(enum nb_event event
,
580 const struct lyd_node
*dnode
,
581 union nb_resource
*resource
)
584 const char *rmap_name
;
586 if (event
!= NB_EV_APPLY
)
589 type
= yang_dnode_get_enum(dnode
, "../protocol");
590 rmap_name
= yang_dnode_get_string(dnode
, NULL
);
592 if (rip
->route_map
[type
].name
)
593 free(rip
->route_map
[type
].name
);
594 rip
->route_map
[type
].name
= strdup(rmap_name
);
595 rip
->route_map
[type
].map
= route_map_lookup_by_name(rmap_name
);
601 ripd_instance_redistribute_route_map_delete(enum nb_event event
,
602 const struct lyd_node
*dnode
)
606 if (event
!= NB_EV_APPLY
)
609 type
= yang_dnode_get_enum(dnode
, "../protocol");
611 free(rip
->route_map
[type
].name
);
612 rip
->route_map
[type
].name
= NULL
;
613 rip
->route_map
[type
].map
= NULL
;
619 * XPath: /frr-ripd:ripd/instance/redistribute/metric
622 ripd_instance_redistribute_metric_modify(enum nb_event event
,
623 const struct lyd_node
*dnode
,
624 union nb_resource
*resource
)
629 if (event
!= NB_EV_APPLY
)
632 type
= yang_dnode_get_enum(dnode
, "../protocol");
633 metric
= yang_dnode_get_uint8(dnode
, NULL
);
635 rip
->route_map
[type
].metric_config
= true;
636 rip
->route_map
[type
].metric
= metric
;
642 ripd_instance_redistribute_metric_delete(enum nb_event event
,
643 const struct lyd_node
*dnode
)
647 if (event
!= NB_EV_APPLY
)
650 type
= yang_dnode_get_enum(dnode
, "../protocol");
652 rip
->route_map
[type
].metric_config
= false;
653 rip
->route_map
[type
].metric
= 0;
659 * XPath: /frr-ripd:ripd/instance/static-route
661 static int ripd_instance_static_route_create(enum nb_event event
,
662 const struct lyd_node
*dnode
,
663 union nb_resource
*resource
)
666 struct prefix_ipv4 p
;
668 if (event
!= NB_EV_APPLY
)
671 yang_dnode_get_ipv4p(&p
, dnode
, NULL
);
674 memset(&nh
, 0, sizeof(nh
));
675 nh
.type
= NEXTHOP_TYPE_IPV4
;
676 rip_redistribute_add(ZEBRA_ROUTE_RIP
, RIP_ROUTE_STATIC
, &p
, &nh
, 0, 0,
682 static int ripd_instance_static_route_delete(enum nb_event event
,
683 const struct lyd_node
*dnode
)
685 struct prefix_ipv4 p
;
687 if (event
!= NB_EV_APPLY
)
690 yang_dnode_get_ipv4p(&p
, dnode
, NULL
);
693 rip_redistribute_delete(ZEBRA_ROUTE_RIP
, RIP_ROUTE_STATIC
, &p
, 0);
699 * XPath: /frr-ripd:ripd/instance/timers/
701 static void ripd_instance_timers_apply_finish(const struct lyd_node
*dnode
)
703 /* Reset update timer thread. */
704 rip_event(RIP_UPDATE_EVENT
, 0);
708 * XPath: /frr-ripd:ripd/instance/timers/flush-interval
711 ripd_instance_timers_flush_interval_modify(enum nb_event event
,
712 const struct lyd_node
*dnode
,
713 union nb_resource
*resource
)
715 if (event
!= NB_EV_APPLY
)
718 rip
->garbage_time
= yang_dnode_get_uint32(dnode
, NULL
);
724 * XPath: /frr-ripd:ripd/instance/timers/holddown-interval
727 ripd_instance_timers_holddown_interval_modify(enum nb_event event
,
728 const struct lyd_node
*dnode
,
729 union nb_resource
*resource
)
731 if (event
!= NB_EV_APPLY
)
734 rip
->timeout_time
= yang_dnode_get_uint32(dnode
, NULL
);
740 * XPath: /frr-ripd:ripd/instance/timers/update-interval
743 ripd_instance_timers_update_interval_modify(enum nb_event event
,
744 const struct lyd_node
*dnode
,
745 union nb_resource
*resource
)
747 if (event
!= NB_EV_APPLY
)
750 rip
->update_time
= yang_dnode_get_uint32(dnode
, NULL
);
756 * XPath: /frr-ripd:ripd/instance/version/receive
758 static int ripd_instance_version_receive_modify(enum nb_event event
,
759 const struct lyd_node
*dnode
,
760 union nb_resource
*resource
)
762 if (event
!= NB_EV_APPLY
)
765 rip
->version_recv
= yang_dnode_get_enum(dnode
, NULL
);
771 * XPath: /frr-ripd:ripd/instance/version/send
773 static int ripd_instance_version_send_modify(enum nb_event event
,
774 const struct lyd_node
*dnode
,
775 union nb_resource
*resource
)
777 if (event
!= NB_EV_APPLY
)
780 rip
->version_send
= yang_dnode_get_enum(dnode
, NULL
);
786 * XPath: /frr-interface:lib/interface/frr-ripd:rip/split-horizon
788 static int lib_interface_rip_split_horizon_modify(enum nb_event event
,
789 const struct lyd_node
*dnode
,
790 union nb_resource
*resource
)
792 struct interface
*ifp
;
793 struct rip_interface
*ri
;
795 if (event
!= NB_EV_APPLY
)
798 ifp
= yang_dnode_get_entry(dnode
, true);
800 ri
->split_horizon
= yang_dnode_get_enum(dnode
, NULL
);
806 * XPath: /frr-interface:lib/interface/frr-ripd:rip/v2-broadcast
808 static int lib_interface_rip_v2_broadcast_modify(enum nb_event event
,
809 const struct lyd_node
*dnode
,
810 union nb_resource
*resource
)
812 struct interface
*ifp
;
813 struct rip_interface
*ri
;
815 if (event
!= NB_EV_APPLY
)
818 ifp
= yang_dnode_get_entry(dnode
, true);
820 ri
->v2_broadcast
= yang_dnode_get_bool(dnode
, NULL
);
826 * XPath: /frr-interface:lib/interface/frr-ripd:rip/version-receive
829 lib_interface_rip_version_receive_modify(enum nb_event event
,
830 const struct lyd_node
*dnode
,
831 union nb_resource
*resource
)
833 struct interface
*ifp
;
834 struct rip_interface
*ri
;
836 if (event
!= NB_EV_APPLY
)
839 ifp
= yang_dnode_get_entry(dnode
, true);
841 ri
->ri_receive
= yang_dnode_get_enum(dnode
, NULL
);
847 * XPath: /frr-interface:lib/interface/frr-ripd:rip/version-send
849 static int lib_interface_rip_version_send_modify(enum nb_event event
,
850 const struct lyd_node
*dnode
,
851 union nb_resource
*resource
)
853 struct interface
*ifp
;
854 struct rip_interface
*ri
;
856 if (event
!= NB_EV_APPLY
)
859 ifp
= yang_dnode_get_entry(dnode
, true);
861 ri
->ri_send
= yang_dnode_get_enum(dnode
, NULL
);
867 * XPath: /frr-interface:lib/interface/frr-ripd:rip/authentication-scheme/mode
869 static int lib_interface_rip_authentication_scheme_mode_modify(
870 enum nb_event event
, const struct lyd_node
*dnode
,
871 union nb_resource
*resource
)
873 struct interface
*ifp
;
874 struct rip_interface
*ri
;
876 if (event
!= NB_EV_APPLY
)
879 ifp
= yang_dnode_get_entry(dnode
, true);
881 ri
->auth_type
= yang_dnode_get_enum(dnode
, NULL
);
888 * /frr-interface:lib/interface/frr-ripd:rip/authentication-scheme/md5-auth-length
890 static int lib_interface_rip_authentication_scheme_md5_auth_length_modify(
891 enum nb_event event
, const struct lyd_node
*dnode
,
892 union nb_resource
*resource
)
894 struct interface
*ifp
;
895 struct rip_interface
*ri
;
897 if (event
!= NB_EV_APPLY
)
900 ifp
= yang_dnode_get_entry(dnode
, true);
902 ri
->md5_auth_len
= yang_dnode_get_enum(dnode
, NULL
);
907 static int lib_interface_rip_authentication_scheme_md5_auth_length_delete(
908 enum nb_event event
, const struct lyd_node
*dnode
)
910 struct interface
*ifp
;
911 struct rip_interface
*ri
;
913 if (event
!= NB_EV_APPLY
)
916 ifp
= yang_dnode_get_entry(dnode
, true);
918 ri
->md5_auth_len
= yang_get_default_enum(
919 "%s/authentication-scheme/md5-auth-length", RIP_IFACE
);
925 * XPath: /frr-interface:lib/interface/frr-ripd:rip/authentication-password
928 lib_interface_rip_authentication_password_modify(enum nb_event event
,
929 const struct lyd_node
*dnode
,
930 union nb_resource
*resource
)
932 struct interface
*ifp
;
933 struct rip_interface
*ri
;
935 if (event
!= NB_EV_APPLY
)
938 ifp
= yang_dnode_get_entry(dnode
, true);
941 XFREE(MTYPE_RIP_INTERFACE_STRING
, ri
->auth_str
);
942 ri
->auth_str
= XSTRDUP(MTYPE_RIP_INTERFACE_STRING
,
943 yang_dnode_get_string(dnode
, NULL
));
949 lib_interface_rip_authentication_password_delete(enum nb_event event
,
950 const struct lyd_node
*dnode
)
952 struct interface
*ifp
;
953 struct rip_interface
*ri
;
955 if (event
!= NB_EV_APPLY
)
958 ifp
= yang_dnode_get_entry(dnode
, true);
960 XFREE(MTYPE_RIP_INTERFACE_STRING
, ri
->auth_str
);
966 * XPath: /frr-interface:lib/interface/frr-ripd:rip/authentication-key-chain
969 lib_interface_rip_authentication_key_chain_modify(enum nb_event event
,
970 const struct lyd_node
*dnode
,
971 union nb_resource
*resource
)
973 struct interface
*ifp
;
974 struct rip_interface
*ri
;
976 if (event
!= NB_EV_APPLY
)
979 ifp
= yang_dnode_get_entry(dnode
, true);
982 XFREE(MTYPE_RIP_INTERFACE_STRING
, ri
->key_chain
);
983 ri
->key_chain
= XSTRDUP(MTYPE_RIP_INTERFACE_STRING
,
984 yang_dnode_get_string(dnode
, NULL
));
990 lib_interface_rip_authentication_key_chain_delete(enum nb_event event
,
991 const struct lyd_node
*dnode
)
993 struct interface
*ifp
;
994 struct rip_interface
*ri
;
996 if (event
!= NB_EV_APPLY
)
999 ifp
= yang_dnode_get_entry(dnode
, true);
1001 XFREE(MTYPE_RIP_INTERFACE_STRING
, ri
->key_chain
);
1007 * XPath: /frr-ripd:ripd/state/neighbors/neighbor
1010 ripd_state_neighbors_neighbor_get_next(const void *parent_list_entry
,
1011 const void *list_entry
)
1013 struct listnode
*node
;
1015 if (list_entry
== NULL
)
1016 node
= listhead(peer_list
);
1018 node
= listnextnode((struct listnode
*)list_entry
);
1023 static int ripd_state_neighbors_neighbor_get_keys(const void *list_entry
,
1024 struct yang_list_keys
*keys
)
1026 const struct listnode
*node
= list_entry
;
1027 const struct rip_peer
*peer
= listgetdata(node
);
1030 (void)inet_ntop(AF_INET
, &peer
->addr
, keys
->key
[0],
1031 sizeof(keys
->key
[0]));
1037 ripd_state_neighbors_neighbor_lookup_entry(const void *parent_list_entry
,
1038 const struct yang_list_keys
*keys
)
1040 struct in_addr address
;
1041 struct rip_peer
*peer
;
1042 struct listnode
*node
;
1044 yang_str2ipv4(keys
->key
[0], &address
);
1046 for (ALL_LIST_ELEMENTS_RO(peer_list
, node
, peer
)) {
1047 if (IPV4_ADDR_SAME(&peer
->addr
, &address
))
1055 * XPath: /frr-ripd:ripd/state/neighbors/neighbor/address
1057 static struct yang_data
*
1058 ripd_state_neighbors_neighbor_address_get_elem(const char *xpath
,
1059 const void *list_entry
)
1061 const struct listnode
*node
= list_entry
;
1062 const struct rip_peer
*peer
= listgetdata(node
);
1064 return yang_data_new_ipv4(xpath
, &peer
->addr
);
1068 * XPath: /frr-ripd:ripd/state/neighbors/neighbor/last-update
1070 static struct yang_data
*
1071 ripd_state_neighbors_neighbor_last_update_get_elem(const char *xpath
,
1072 const void *list_entry
)
1074 /* TODO: yang:date-and-time is tricky */
1079 * XPath: /frr-ripd:ripd/state/neighbors/neighbor/bad-packets-rcvd
1081 static struct yang_data
*
1082 ripd_state_neighbors_neighbor_bad_packets_rcvd_get_elem(const char *xpath
,
1083 const void *list_entry
)
1085 const struct listnode
*node
= list_entry
;
1086 const struct rip_peer
*peer
= listgetdata(node
);
1088 return yang_data_new_uint32(xpath
, peer
->recv_badpackets
);
1092 * XPath: /frr-ripd:ripd/state/neighbors/neighbor/bad-routes-rcvd
1094 static struct yang_data
*
1095 ripd_state_neighbors_neighbor_bad_routes_rcvd_get_elem(const char *xpath
,
1096 const void *list_entry
)
1098 const struct listnode
*node
= list_entry
;
1099 const struct rip_peer
*peer
= listgetdata(node
);
1101 return yang_data_new_uint32(xpath
, peer
->recv_badroutes
);
1105 * XPath: /frr-ripd:ripd/state/routes/route
1108 ripd_state_routes_route_get_next(const void *parent_list_entry
,
1109 const void *list_entry
)
1111 struct route_node
*rn
;
1116 if (list_entry
== NULL
)
1117 rn
= route_top(rip
->table
);
1119 rn
= route_next((struct route_node
*)list_entry
);
1120 while (rn
&& rn
->info
== NULL
)
1121 rn
= route_next(rn
);
1126 static int ripd_state_routes_route_get_keys(const void *list_entry
,
1127 struct yang_list_keys
*keys
)
1129 const struct route_node
*rn
= list_entry
;
1132 (void)prefix2str(&rn
->p
, keys
->key
[0], sizeof(keys
->key
[0]));
1138 ripd_state_routes_route_lookup_entry(const void *parent_list_entry
,
1139 const struct yang_list_keys
*keys
)
1141 struct prefix prefix
;
1142 struct route_node
*rn
;
1144 yang_str2ipv4p(keys
->key
[0], &prefix
);
1146 rn
= route_node_lookup(rip
->table
, &prefix
);
1147 if (!rn
|| !rn
->info
)
1150 route_unlock_node(rn
);
1156 * XPath: /frr-ripd:ripd/state/routes/route/prefix
1158 static struct yang_data
*
1159 ripd_state_routes_route_prefix_get_elem(const char *xpath
,
1160 const void *list_entry
)
1162 const struct route_node
*rn
= list_entry
;
1163 const struct rip_info
*rinfo
= listnode_head(rn
->info
);
1165 return yang_data_new_ipv4p(xpath
, &rinfo
->rp
->p
);
1169 * XPath: /frr-ripd:ripd/state/routes/route/next-hop
1171 static struct yang_data
*
1172 ripd_state_routes_route_next_hop_get_elem(const char *xpath
,
1173 const void *list_entry
)
1175 const struct route_node
*rn
= list_entry
;
1176 const struct rip_info
*rinfo
= listnode_head(rn
->info
);
1178 switch (rinfo
->nh
.type
) {
1179 case NEXTHOP_TYPE_IPV4
:
1180 case NEXTHOP_TYPE_IPV4_IFINDEX
:
1181 return yang_data_new_ipv4(xpath
, &rinfo
->nh
.gate
.ipv4
);
1188 * XPath: /frr-ripd:ripd/state/routes/route/interface
1190 static struct yang_data
*
1191 ripd_state_routes_route_interface_get_elem(const char *xpath
,
1192 const void *list_entry
)
1194 const struct route_node
*rn
= list_entry
;
1195 const struct rip_info
*rinfo
= listnode_head(rn
->info
);
1197 switch (rinfo
->nh
.type
) {
1198 case NEXTHOP_TYPE_IFINDEX
:
1199 case NEXTHOP_TYPE_IPV4_IFINDEX
:
1200 return yang_data_new_string(
1201 xpath
, ifindex2ifname(rinfo
->nh
.ifindex
, VRF_DEFAULT
));
1208 * XPath: /frr-ripd:ripd/state/routes/route/metric
1210 static struct yang_data
*
1211 ripd_state_routes_route_metric_get_elem(const char *xpath
,
1212 const void *list_entry
)
1214 const struct route_node
*rn
= list_entry
;
1215 const struct rip_info
*rinfo
= listnode_head(rn
->info
);
1217 return yang_data_new_uint8(xpath
, rinfo
->metric
);
1221 * XPath: /frr-ripd:clear-rip-route
1223 static int clear_rip_route_rpc(const char *xpath
, const struct list
*input
,
1224 struct list
*output
)
1226 struct route_node
*rp
;
1227 struct rip_info
*rinfo
;
1229 struct listnode
*listnode
;
1231 /* Clear received RIP routes */
1232 for (rp
= route_top(rip
->table
); rp
; rp
= route_next(rp
)) {
1237 for (ALL_LIST_ELEMENTS_RO(list
, listnode
, rinfo
)) {
1238 if (!rip_route_rte(rinfo
))
1241 if (CHECK_FLAG(rinfo
->flags
, RIP_RTF_FIB
))
1242 rip_zebra_ipv4_delete(rp
);
1247 RIP_TIMER_OFF(rinfo
->t_timeout
);
1248 RIP_TIMER_OFF(rinfo
->t_garbage_collect
);
1249 listnode_delete(list
, rinfo
);
1250 rip_info_free(rinfo
);
1253 if (list_isempty(list
)) {
1256 route_unlock_node(rp
);
1264 * XPath: /frr-ripd:authentication-type-failure
1266 void ripd_notif_send_auth_type_failure(const char *ifname
)
1268 const char *xpath
= "/frr-ripd:authentication-type-failure";
1269 struct list
*arguments
;
1270 char xpath_arg
[XPATH_MAXLEN
];
1271 struct yang_data
*data
;
1273 arguments
= yang_data_list_new();
1275 snprintf(xpath_arg
, sizeof(xpath_arg
), "%s/interface-name", xpath
);
1276 data
= yang_data_new_string(xpath_arg
, ifname
);
1277 listnode_add(arguments
, data
);
1279 nb_notification_send(xpath
, arguments
);
1283 * XPath: /frr-ripd:authentication-failure
1285 void ripd_notif_send_auth_failure(const char *ifname
)
1287 const char *xpath
= "/frr-ripd:authentication-failure";
1288 struct list
*arguments
;
1289 char xpath_arg
[XPATH_MAXLEN
];
1290 struct yang_data
*data
;
1292 arguments
= yang_data_list_new();
1294 snprintf(xpath_arg
, sizeof(xpath_arg
), "%s/interface-name", xpath
);
1295 data
= yang_data_new_string(xpath_arg
, ifname
);
1296 listnode_add(arguments
, data
);
1298 nb_notification_send(xpath
, arguments
);
1301 /* clang-format off */
1302 const struct frr_yang_module_info frr_ripd_info
= {
1306 .xpath
= "/frr-ripd:ripd/instance",
1307 .cbs
.create
= ripd_instance_create
,
1308 .cbs
.destroy
= ripd_instance_delete
,
1309 .cbs
.cli_show
= cli_show_router_rip
,
1312 .xpath
= "/frr-ripd:ripd/instance/allow-ecmp",
1313 .cbs
.modify
= ripd_instance_allow_ecmp_modify
,
1314 .cbs
.cli_show
= cli_show_rip_allow_ecmp
,
1317 .xpath
= "/frr-ripd:ripd/instance/default-information-originate",
1318 .cbs
.modify
= ripd_instance_default_information_originate_modify
,
1319 .cbs
.cli_show
= cli_show_rip_default_information_originate
,
1322 .xpath
= "/frr-ripd:ripd/instance/default-metric",
1323 .cbs
.modify
= ripd_instance_default_metric_modify
,
1324 .cbs
.cli_show
= cli_show_rip_default_metric
,
1327 .xpath
= "/frr-ripd:ripd/instance/distance/default",
1328 .cbs
.modify
= ripd_instance_distance_default_modify
,
1329 .cbs
.cli_show
= cli_show_rip_distance
,
1332 .xpath
= "/frr-ripd:ripd/instance/distance/source",
1333 .cbs
.create
= ripd_instance_distance_source_create
,
1334 .cbs
.destroy
= ripd_instance_distance_source_delete
,
1335 .cbs
.cli_show
= cli_show_rip_distance_source
,
1338 .xpath
= "/frr-ripd:ripd/instance/distance/source/distance",
1339 .cbs
.modify
= ripd_instance_distance_source_distance_modify
,
1342 .xpath
= "/frr-ripd:ripd/instance/distance/source/access-list",
1343 .cbs
.modify
= ripd_instance_distance_source_access_list_modify
,
1344 .cbs
.destroy
= ripd_instance_distance_source_access_list_delete
,
1347 .xpath
= "/frr-ripd:ripd/instance/explicit-neighbor",
1348 .cbs
.create
= ripd_instance_explicit_neighbor_create
,
1349 .cbs
.destroy
= ripd_instance_explicit_neighbor_delete
,
1350 .cbs
.cli_show
= cli_show_rip_neighbor
,
1353 .xpath
= "/frr-ripd:ripd/instance/network",
1354 .cbs
.create
= ripd_instance_network_create
,
1355 .cbs
.destroy
= ripd_instance_network_delete
,
1356 .cbs
.cli_show
= cli_show_rip_network_prefix
,
1359 .xpath
= "/frr-ripd:ripd/instance/interface",
1360 .cbs
.create
= ripd_instance_interface_create
,
1361 .cbs
.destroy
= ripd_instance_interface_delete
,
1362 .cbs
.cli_show
= cli_show_rip_network_interface
,
1365 .xpath
= "/frr-ripd:ripd/instance/offset-list",
1366 .cbs
.create
= ripd_instance_offset_list_create
,
1367 .cbs
.destroy
= ripd_instance_offset_list_delete
,
1368 .cbs
.cli_show
= cli_show_rip_offset_list
,
1371 .xpath
= "/frr-ripd:ripd/instance/offset-list/access-list",
1372 .cbs
.modify
= ripd_instance_offset_list_access_list_modify
,
1375 .xpath
= "/frr-ripd:ripd/instance/offset-list/metric",
1376 .cbs
.modify
= ripd_instance_offset_list_metric_modify
,
1379 .xpath
= "/frr-ripd:ripd/instance/passive-default",
1380 .cbs
.modify
= ripd_instance_passive_default_modify
,
1381 .cbs
.cli_show
= cli_show_rip_passive_default
,
1384 .xpath
= "/frr-ripd:ripd/instance/passive-interface",
1385 .cbs
.create
= ripd_instance_passive_interface_create
,
1386 .cbs
.destroy
= ripd_instance_passive_interface_delete
,
1387 .cbs
.cli_show
= cli_show_rip_passive_interface
,
1390 .xpath
= "/frr-ripd:ripd/instance/non-passive-interface",
1391 .cbs
.create
= ripd_instance_non_passive_interface_create
,
1392 .cbs
.destroy
= ripd_instance_non_passive_interface_delete
,
1393 .cbs
.cli_show
= cli_show_rip_non_passive_interface
,
1396 .xpath
= "/frr-ripd:ripd/instance/redistribute",
1397 .cbs
.create
= ripd_instance_redistribute_create
,
1398 .cbs
.destroy
= ripd_instance_redistribute_delete
,
1399 .cbs
.apply_finish
= ripd_instance_redistribute_apply_finish
,
1400 .cbs
.cli_show
= cli_show_rip_redistribute
,
1403 .xpath
= "/frr-ripd:ripd/instance/redistribute/route-map",
1404 .cbs
.modify
= ripd_instance_redistribute_route_map_modify
,
1405 .cbs
.destroy
= ripd_instance_redistribute_route_map_delete
,
1408 .xpath
= "/frr-ripd:ripd/instance/redistribute/metric",
1409 .cbs
.modify
= ripd_instance_redistribute_metric_modify
,
1410 .cbs
.destroy
= ripd_instance_redistribute_metric_delete
,
1413 .xpath
= "/frr-ripd:ripd/instance/static-route",
1414 .cbs
.create
= ripd_instance_static_route_create
,
1415 .cbs
.destroy
= ripd_instance_static_route_delete
,
1416 .cbs
.cli_show
= cli_show_rip_route
,
1419 .xpath
= "/frr-ripd:ripd/instance/timers",
1420 .cbs
.apply_finish
= ripd_instance_timers_apply_finish
,
1421 .cbs
.cli_show
= cli_show_rip_timers
,
1424 .xpath
= "/frr-ripd:ripd/instance/timers/flush-interval",
1425 .cbs
.modify
= ripd_instance_timers_flush_interval_modify
,
1428 .xpath
= "/frr-ripd:ripd/instance/timers/holddown-interval",
1429 .cbs
.modify
= ripd_instance_timers_holddown_interval_modify
,
1432 .xpath
= "/frr-ripd:ripd/instance/timers/update-interval",
1433 .cbs
.modify
= ripd_instance_timers_update_interval_modify
,
1436 .xpath
= "/frr-ripd:ripd/instance/version",
1437 .cbs
.cli_show
= cli_show_rip_version
,
1440 .xpath
= "/frr-ripd:ripd/instance/version/receive",
1441 .cbs
.modify
= ripd_instance_version_receive_modify
,
1444 .xpath
= "/frr-ripd:ripd/instance/version/send",
1445 .cbs
.modify
= ripd_instance_version_send_modify
,
1448 .xpath
= "/frr-interface:lib/interface/frr-ripd:rip/split-horizon",
1449 .cbs
.modify
= lib_interface_rip_split_horizon_modify
,
1450 .cbs
.cli_show
= cli_show_ip_rip_split_horizon
,
1453 .xpath
= "/frr-interface:lib/interface/frr-ripd:rip/v2-broadcast",
1454 .cbs
.modify
= lib_interface_rip_v2_broadcast_modify
,
1455 .cbs
.cli_show
= cli_show_ip_rip_v2_broadcast
,
1458 .xpath
= "/frr-interface:lib/interface/frr-ripd:rip/version-receive",
1459 .cbs
.modify
= lib_interface_rip_version_receive_modify
,
1460 .cbs
.cli_show
= cli_show_ip_rip_receive_version
,
1463 .xpath
= "/frr-interface:lib/interface/frr-ripd:rip/version-send",
1464 .cbs
.modify
= lib_interface_rip_version_send_modify
,
1465 .cbs
.cli_show
= cli_show_ip_rip_send_version
,
1468 .xpath
= "/frr-interface:lib/interface/frr-ripd:rip/authentication-scheme",
1469 .cbs
.cli_show
= cli_show_ip_rip_authentication_scheme
,
1472 .xpath
= "/frr-interface:lib/interface/frr-ripd:rip/authentication-scheme/mode",
1473 .cbs
.modify
= lib_interface_rip_authentication_scheme_mode_modify
,
1476 .xpath
= "/frr-interface:lib/interface/frr-ripd:rip/authentication-scheme/md5-auth-length",
1477 .cbs
.modify
= lib_interface_rip_authentication_scheme_md5_auth_length_modify
,
1478 .cbs
.destroy
= lib_interface_rip_authentication_scheme_md5_auth_length_delete
,
1481 .xpath
= "/frr-interface:lib/interface/frr-ripd:rip/authentication-password",
1482 .cbs
.modify
= lib_interface_rip_authentication_password_modify
,
1483 .cbs
.destroy
= lib_interface_rip_authentication_password_delete
,
1484 .cbs
.cli_show
= cli_show_ip_rip_authentication_string
,
1487 .xpath
= "/frr-interface:lib/interface/frr-ripd:rip/authentication-key-chain",
1488 .cbs
.modify
= lib_interface_rip_authentication_key_chain_modify
,
1489 .cbs
.destroy
= lib_interface_rip_authentication_key_chain_delete
,
1490 .cbs
.cli_show
= cli_show_ip_rip_authentication_key_chain
,
1493 .xpath
= "/frr-ripd:ripd/state/neighbors/neighbor",
1494 .cbs
.get_next
= ripd_state_neighbors_neighbor_get_next
,
1495 .cbs
.get_keys
= ripd_state_neighbors_neighbor_get_keys
,
1496 .cbs
.lookup_entry
= ripd_state_neighbors_neighbor_lookup_entry
,
1499 .xpath
= "/frr-ripd:ripd/state/neighbors/neighbor/address",
1500 .cbs
.get_elem
= ripd_state_neighbors_neighbor_address_get_elem
,
1503 .xpath
= "/frr-ripd:ripd/state/neighbors/neighbor/last-update",
1504 .cbs
.get_elem
= ripd_state_neighbors_neighbor_last_update_get_elem
,
1507 .xpath
= "/frr-ripd:ripd/state/neighbors/neighbor/bad-packets-rcvd",
1508 .cbs
.get_elem
= ripd_state_neighbors_neighbor_bad_packets_rcvd_get_elem
,
1511 .xpath
= "/frr-ripd:ripd/state/neighbors/neighbor/bad-routes-rcvd",
1512 .cbs
.get_elem
= ripd_state_neighbors_neighbor_bad_routes_rcvd_get_elem
,
1515 .xpath
= "/frr-ripd:ripd/state/routes/route",
1516 .cbs
.get_next
= ripd_state_routes_route_get_next
,
1517 .cbs
.get_keys
= ripd_state_routes_route_get_keys
,
1518 .cbs
.lookup_entry
= ripd_state_routes_route_lookup_entry
,
1521 .xpath
= "/frr-ripd:ripd/state/routes/route/prefix",
1522 .cbs
.get_elem
= ripd_state_routes_route_prefix_get_elem
,
1525 .xpath
= "/frr-ripd:ripd/state/routes/route/next-hop",
1526 .cbs
.get_elem
= ripd_state_routes_route_next_hop_get_elem
,
1529 .xpath
= "/frr-ripd:ripd/state/routes/route/interface",
1530 .cbs
.get_elem
= ripd_state_routes_route_interface_get_elem
,
1533 .xpath
= "/frr-ripd:ripd/state/routes/route/metric",
1534 .cbs
.get_elem
= ripd_state_routes_route_metric_get_elem
,
1537 .xpath
= "/frr-ripd:clear-rip-route",
1538 .cbs
.rpc
= clear_rip_route_rpc
,