diff options
author | Renato Westphal <renato@opensourcerouting.org> | 2020-04-04 18:38:51 +0200 |
---|---|---|
committer | Renato Westphal <renato@opensourcerouting.org> | 2020-04-23 15:14:32 +0200 |
commit | 60ee8be107c593212a9b53e8ed5c34c4c5e70af3 (patch) | |
tree | f86993b9f63afab4a8e0291f27fd8f938f5dec8d /ripngd | |
parent | lib: create a wrapper function for all northbound callbacks (diff) | |
download | frr-60ee8be107c593212a9b53e8ed5c34c4c5e70af3.tar.xz frr-60ee8be107c593212a9b53e8ed5c34c4c5e70af3.zip |
*: change the signature of the northbound callbacks to be more flexible
Having a fixed set of parameters for each northbound callback isn't a
good idea since it makes it difficult to add new parameters whenever
that becomes necessary, as several hundreds or thousands of existing
callbacks need to be updated accordingly.
To remediate this issue, this commit changes the signature of all
northbound callbacks to have a single parameter: a pointer to a
'nb_cb_x_args' structure (where x is different for each type
of callback). These structures encapsulate all real parameters
(both input and output) the callbacks need to have access to. And
adding a new parameter to a given callback is as simple as adding
a new field to the corresponding 'nb_cb_x_args' structure, without
needing to update any instance of that callback in any daemon.
This commit includes a .cocci semantic patch that can be used to
update old code to the new format automatically.
Signed-off-by: Renato Westphal <renato@opensourcerouting.org>
Diffstat (limited to 'ripngd')
-rw-r--r-- | ripngd/ripng_nb.h | 169 | ||||
-rw-r--r-- | ripngd/ripng_nb_config.c | 327 | ||||
-rw-r--r-- | ripngd/ripng_nb_rpcs.c | 6 | ||||
-rw-r--r-- | ripngd/ripng_nb_state.c | 111 |
4 files changed, 260 insertions, 353 deletions
diff --git a/ripngd/ripng_nb.h b/ripngd/ripng_nb.h index 45e92e0a1..d6aecbf6b 100644 --- a/ripngd/ripng_nb.h +++ b/ripngd/ripng_nb.h @@ -23,129 +23,82 @@ extern const struct frr_yang_module_info frr_ripngd_info; /* Mandatory callbacks. */ -int ripngd_instance_create(enum nb_event event, const struct lyd_node *dnode, - union nb_resource *resource); -int ripngd_instance_destroy(enum nb_event event, const struct lyd_node *dnode); -const void *ripngd_instance_get_next(const void *parent_list_entry, - const void *list_entry); -int ripngd_instance_get_keys(const void *list_entry, - struct yang_list_keys *keys); -const void *ripngd_instance_lookup_entry(const void *parent_list_entry, - const struct yang_list_keys *keys); -int ripngd_instance_allow_ecmp_modify(enum nb_event event, - const struct lyd_node *dnode, - union nb_resource *resource); +int ripngd_instance_create(struct nb_cb_create_args *args); +int ripngd_instance_destroy(struct nb_cb_destroy_args *args); +const void *ripngd_instance_get_next(struct nb_cb_get_next_args *args); +int ripngd_instance_get_keys(struct nb_cb_get_keys_args *args); +const void *ripngd_instance_lookup_entry(struct nb_cb_lookup_entry_args *args); +int ripngd_instance_allow_ecmp_modify(struct nb_cb_modify_args *args); int ripngd_instance_default_information_originate_modify( - enum nb_event event, const struct lyd_node *dnode, - union nb_resource *resource); -int ripngd_instance_default_metric_modify(enum nb_event event, - const struct lyd_node *dnode, - union nb_resource *resource); -int ripngd_instance_network_create(enum nb_event event, - const struct lyd_node *dnode, - union nb_resource *resource); -int ripngd_instance_network_destroy(enum nb_event event, - const struct lyd_node *dnode); -int ripngd_instance_interface_create(enum nb_event event, - const struct lyd_node *dnode, - union nb_resource *resource); -int ripngd_instance_interface_destroy(enum nb_event event, - const struct lyd_node *dnode); -int ripngd_instance_offset_list_create(enum nb_event event, - const struct lyd_node *dnode, - union nb_resource *resource); -int ripngd_instance_offset_list_destroy(enum nb_event event, - const struct lyd_node *dnode); -int ripngd_instance_offset_list_access_list_modify(enum nb_event event, - const struct lyd_node *dnode, - union nb_resource *resource); -int ripngd_instance_offset_list_metric_modify(enum nb_event event, - const struct lyd_node *dnode, - union nb_resource *resource); -int ripngd_instance_passive_interface_create(enum nb_event event, - const struct lyd_node *dnode, - union nb_resource *resource); -int ripngd_instance_passive_interface_destroy(enum nb_event event, - const struct lyd_node *dnode); -int ripngd_instance_redistribute_create(enum nb_event event, - const struct lyd_node *dnode, - union nb_resource *resource); -int ripngd_instance_redistribute_destroy(enum nb_event event, - const struct lyd_node *dnode); -int ripngd_instance_redistribute_route_map_modify(enum nb_event event, - const struct lyd_node *dnode, - union nb_resource *resource); + struct nb_cb_modify_args *args); +int ripngd_instance_default_metric_modify(struct nb_cb_modify_args *args); +int ripngd_instance_network_create(struct nb_cb_create_args *args); +int ripngd_instance_network_destroy(struct nb_cb_destroy_args *args); +int ripngd_instance_interface_create(struct nb_cb_create_args *args); +int ripngd_instance_interface_destroy(struct nb_cb_destroy_args *args); +int ripngd_instance_offset_list_create(struct nb_cb_create_args *args); +int ripngd_instance_offset_list_destroy(struct nb_cb_destroy_args *args); +int ripngd_instance_offset_list_access_list_modify( + struct nb_cb_modify_args *args); +int ripngd_instance_offset_list_metric_modify(struct nb_cb_modify_args *args); +int ripngd_instance_passive_interface_create(struct nb_cb_create_args *args); +int ripngd_instance_passive_interface_destroy(struct nb_cb_destroy_args *args); +int ripngd_instance_redistribute_create(struct nb_cb_create_args *args); +int ripngd_instance_redistribute_destroy(struct nb_cb_destroy_args *args); +int ripngd_instance_redistribute_route_map_modify( + struct nb_cb_modify_args *args); int ripngd_instance_redistribute_route_map_destroy( - enum nb_event event, const struct lyd_node *dnode); -int ripngd_instance_redistribute_metric_modify(enum nb_event event, - const struct lyd_node *dnode, - union nb_resource *resource); -int ripngd_instance_redistribute_metric_destroy(enum nb_event event, - const struct lyd_node *dnode); -int ripngd_instance_static_route_create(enum nb_event event, - const struct lyd_node *dnode, - union nb_resource *resource); -int ripngd_instance_static_route_destroy(enum nb_event event, - const struct lyd_node *dnode); -int ripngd_instance_aggregate_address_create(enum nb_event event, - const struct lyd_node *dnode, - union nb_resource *resource); -int ripngd_instance_aggregate_address_destroy(enum nb_event event, - const struct lyd_node *dnode); -int ripngd_instance_timers_flush_interval_modify(enum nb_event event, - const struct lyd_node *dnode, - union nb_resource *resource); + struct nb_cb_destroy_args *args); +int ripngd_instance_redistribute_metric_modify(struct nb_cb_modify_args *args); +int ripngd_instance_redistribute_metric_destroy( + struct nb_cb_destroy_args *args); +int ripngd_instance_static_route_create(struct nb_cb_create_args *args); +int ripngd_instance_static_route_destroy(struct nb_cb_destroy_args *args); +int ripngd_instance_aggregate_address_create(struct nb_cb_create_args *args); +int ripngd_instance_aggregate_address_destroy(struct nb_cb_destroy_args *args); +int ripngd_instance_timers_flush_interval_modify( + struct nb_cb_modify_args *args); int ripngd_instance_timers_holddown_interval_modify( - enum nb_event event, const struct lyd_node *dnode, - union nb_resource *resource); -int ripngd_instance_timers_update_interval_modify(enum nb_event event, - const struct lyd_node *dnode, - union nb_resource *resource); -const void * -ripngd_instance_state_neighbors_neighbor_get_next(const void *parent_list_entry, - const void *list_entry); + struct nb_cb_modify_args *args); +int ripngd_instance_timers_update_interval_modify( + struct nb_cb_modify_args *args); +const void *ripngd_instance_state_neighbors_neighbor_get_next( + struct nb_cb_get_next_args *args); int ripngd_instance_state_neighbors_neighbor_get_keys( - const void *list_entry, struct yang_list_keys *keys); + struct nb_cb_get_keys_args *args); const void *ripngd_instance_state_neighbors_neighbor_lookup_entry( - const void *parent_list_entry, const struct yang_list_keys *keys); + struct nb_cb_lookup_entry_args *args); struct yang_data *ripngd_instance_state_neighbors_neighbor_address_get_elem( - const char *xpath, const void *list_entry); + struct nb_cb_get_elem_args *args); struct yang_data *ripngd_instance_state_neighbors_neighbor_last_update_get_elem( - const char *xpath, const void *list_entry); + struct nb_cb_get_elem_args *args); struct yang_data * ripngd_instance_state_neighbors_neighbor_bad_packets_rcvd_get_elem( - const char *xpath, const void *list_entry); + struct nb_cb_get_elem_args *args); struct yang_data * ripngd_instance_state_neighbors_neighbor_bad_routes_rcvd_get_elem( - const char *xpath, const void *list_entry); + struct nb_cb_get_elem_args *args); const void * -ripngd_instance_state_routes_route_get_next(const void *parent_list_entry, - const void *list_entry); -int ripngd_instance_state_routes_route_get_keys(const void *list_entry, - struct yang_list_keys *keys); +ripngd_instance_state_routes_route_get_next(struct nb_cb_get_next_args *args); +int ripngd_instance_state_routes_route_get_keys( + struct nb_cb_get_keys_args *args); const void *ripngd_instance_state_routes_route_lookup_entry( - const void *parent_list_entry, const struct yang_list_keys *keys); -struct yang_data * -ripngd_instance_state_routes_route_prefix_get_elem(const char *xpath, - const void *list_entry); -struct yang_data * -ripngd_instance_state_routes_route_next_hop_get_elem(const char *xpath, - const void *list_entry); -struct yang_data * -ripngd_instance_state_routes_route_interface_get_elem(const char *xpath, - const void *list_entry); -struct yang_data * -ripngd_instance_state_routes_route_metric_get_elem(const char *xpath, - const void *list_entry); -int clear_ripng_route_rpc(const char *xpath, const struct list *input, - struct list *output); -int lib_interface_ripng_split_horizon_modify(enum nb_event event, - const struct lyd_node *dnode, - union nb_resource *resource); + struct nb_cb_lookup_entry_args *args); +struct yang_data *ripngd_instance_state_routes_route_prefix_get_elem( + struct nb_cb_get_elem_args *args); +struct yang_data *ripngd_instance_state_routes_route_next_hop_get_elem( + struct nb_cb_get_elem_args *args); +struct yang_data *ripngd_instance_state_routes_route_interface_get_elem( + struct nb_cb_get_elem_args *args); +struct yang_data *ripngd_instance_state_routes_route_metric_get_elem( + struct nb_cb_get_elem_args *args); +int clear_ripng_route_rpc(struct nb_cb_rpc_args *args); +int lib_interface_ripng_split_horizon_modify(struct nb_cb_modify_args *args); /* Optional 'apply_finish' callbacks. */ -void ripngd_instance_redistribute_apply_finish(const struct lyd_node *dnode); -void ripngd_instance_timers_apply_finish(const struct lyd_node *dnode); +void ripngd_instance_redistribute_apply_finish( + struct nb_cb_apply_finish_args *args); +void ripngd_instance_timers_apply_finish(struct nb_cb_apply_finish_args *args); /* Optional 'cli_show' callbacks. */ void cli_show_router_ripng(struct vty *vty, struct lyd_node *dnode, diff --git a/ripngd/ripng_nb_config.c b/ripngd/ripng_nb_config.c index b39c1d443..85f378bc9 100644 --- a/ripngd/ripng_nb_config.c +++ b/ripngd/ripng_nb_config.c @@ -39,22 +39,21 @@ /* * XPath: /frr-ripngd:ripngd/instance */ -int ripngd_instance_create(enum nb_event event, const struct lyd_node *dnode, - union nb_resource *resource) +int ripngd_instance_create(struct nb_cb_create_args *args) { struct ripng *ripng; struct vrf *vrf; const char *vrf_name; int socket; - vrf_name = yang_dnode_get_string(dnode, "./vrf"); + vrf_name = yang_dnode_get_string(args->dnode, "./vrf"); vrf = vrf_lookup_by_name(vrf_name); /* * Try to create a RIPng socket only if the VRF is enabled, otherwise * create a disabled RIPng instance and wait for the VRF to be enabled. */ - switch (event) { + switch (args->event) { case NB_EV_VALIDATE: break; case NB_EV_PREPARE: @@ -64,48 +63,47 @@ int ripngd_instance_create(enum nb_event event, const struct lyd_node *dnode, socket = ripng_make_socket(vrf); if (socket < 0) return NB_ERR_RESOURCE; - resource->fd = socket; + args->resource->fd = socket; break; case NB_EV_ABORT: if (!vrf || !vrf_is_enabled(vrf)) break; - socket = resource->fd; + socket = args->resource->fd; close(socket); break; case NB_EV_APPLY: if (vrf && vrf_is_enabled(vrf)) - socket = resource->fd; + socket = args->resource->fd; else socket = -1; ripng = ripng_create(vrf_name, vrf, socket); - nb_running_set_entry(dnode, ripng); + nb_running_set_entry(args->dnode, ripng); break; } return NB_OK; } -int ripngd_instance_destroy(enum nb_event event, const struct lyd_node *dnode) +int ripngd_instance_destroy(struct nb_cb_destroy_args *args) { struct ripng *ripng; - if (event != NB_EV_APPLY) + if (args->event != NB_EV_APPLY) return NB_OK; - ripng = nb_running_unset_entry(dnode); + ripng = nb_running_unset_entry(args->dnode); ripng_clean(ripng); return NB_OK; } -const void *ripngd_instance_get_next(const void *parent_list_entry, - const void *list_entry) +const void *ripngd_instance_get_next(struct nb_cb_get_next_args *args) { - struct ripng *ripng = (struct ripng *)list_entry; + struct ripng *ripng = (struct ripng *)args->list_entry; - if (list_entry == NULL) + if (args->list_entry == NULL) ripng = RB_MIN(ripng_instance_head, &ripng_instances); else ripng = RB_NEXT(ripng_instance_head, ripng); @@ -113,21 +111,20 @@ const void *ripngd_instance_get_next(const void *parent_list_entry, return ripng; } -int ripngd_instance_get_keys(const void *list_entry, - struct yang_list_keys *keys) +int ripngd_instance_get_keys(struct nb_cb_get_keys_args *args) { - const struct ripng *ripng = list_entry; + const struct ripng *ripng = args->list_entry; - keys->num = 1; - strlcpy(keys->key[0], ripng->vrf_name, sizeof(keys->key[0])); + args->keys->num = 1; + strlcpy(args->keys->key[0], ripng->vrf_name, + sizeof(args->keys->key[0])); return NB_OK; } -const void *ripngd_instance_lookup_entry(const void *parent_list_entry, - const struct yang_list_keys *keys) +const void *ripngd_instance_lookup_entry(struct nb_cb_lookup_entry_args *args) { - const char *vrf_name = keys->key[0]; + const char *vrf_name = args->keys->key[0]; return ripng_lookup_by_vrf_name(vrf_name); } @@ -135,17 +132,15 @@ const void *ripngd_instance_lookup_entry(const void *parent_list_entry, /* * XPath: /frr-ripngd:ripngd/instance/allow-ecmp */ -int ripngd_instance_allow_ecmp_modify(enum nb_event event, - const struct lyd_node *dnode, - union nb_resource *resource) +int ripngd_instance_allow_ecmp_modify(struct nb_cb_modify_args *args) { struct ripng *ripng; - if (event != NB_EV_APPLY) + if (args->event != NB_EV_APPLY) return NB_OK; - ripng = nb_running_get_entry(dnode, NULL, true); - ripng->ecmp = yang_dnode_get_bool(dnode, NULL); + ripng = nb_running_get_entry(args->dnode, NULL, true); + ripng->ecmp = yang_dnode_get_bool(args->dnode, NULL); if (!ripng->ecmp) ripng_ecmp_disable(ripng); @@ -156,18 +151,17 @@ int ripngd_instance_allow_ecmp_modify(enum nb_event event, * XPath: /frr-ripngd:ripngd/instance/default-information-originate */ int ripngd_instance_default_information_originate_modify( - enum nb_event event, const struct lyd_node *dnode, - union nb_resource *resource) + struct nb_cb_modify_args *args) { struct ripng *ripng; bool default_information; struct prefix_ipv6 p; - if (event != NB_EV_APPLY) + if (args->event != NB_EV_APPLY) return NB_OK; - ripng = nb_running_get_entry(dnode, NULL, true); - default_information = yang_dnode_get_bool(dnode, NULL); + ripng = nb_running_get_entry(args->dnode, NULL, true); + default_information = yang_dnode_get_bool(args->dnode, NULL); str2prefix_ipv6("::/0", &p); if (default_information) { @@ -184,17 +178,15 @@ int ripngd_instance_default_information_originate_modify( /* * XPath: /frr-ripngd:ripngd/instance/default-metric */ -int ripngd_instance_default_metric_modify(enum nb_event event, - const struct lyd_node *dnode, - union nb_resource *resource) +int ripngd_instance_default_metric_modify(struct nb_cb_modify_args *args) { struct ripng *ripng; - if (event != NB_EV_APPLY) + if (args->event != NB_EV_APPLY) return NB_OK; - ripng = nb_running_get_entry(dnode, NULL, true); - ripng->default_metric = yang_dnode_get_uint8(dnode, NULL); + ripng = nb_running_get_entry(args->dnode, NULL, true); + ripng->default_metric = yang_dnode_get_uint8(args->dnode, NULL); return NB_OK; } @@ -202,34 +194,31 @@ int ripngd_instance_default_metric_modify(enum nb_event event, /* * XPath: /frr-ripngd:ripngd/instance/network */ -int ripngd_instance_network_create(enum nb_event event, - const struct lyd_node *dnode, - union nb_resource *resource) +int ripngd_instance_network_create(struct nb_cb_create_args *args) { struct ripng *ripng; struct prefix p; - if (event != NB_EV_APPLY) + if (args->event != NB_EV_APPLY) return NB_OK; - ripng = nb_running_get_entry(dnode, NULL, true); - yang_dnode_get_ipv6p(&p, dnode, NULL); + ripng = nb_running_get_entry(args->dnode, NULL, true); + yang_dnode_get_ipv6p(&p, args->dnode, NULL); apply_mask_ipv6((struct prefix_ipv6 *)&p); return ripng_enable_network_add(ripng, &p); } -int ripngd_instance_network_destroy(enum nb_event event, - const struct lyd_node *dnode) +int ripngd_instance_network_destroy(struct nb_cb_destroy_args *args) { struct ripng *ripng; struct prefix p; - if (event != NB_EV_APPLY) + if (args->event != NB_EV_APPLY) return NB_OK; - ripng = nb_running_get_entry(dnode, NULL, true); - yang_dnode_get_ipv6p(&p, dnode, NULL); + ripng = nb_running_get_entry(args->dnode, NULL, true); + yang_dnode_get_ipv6p(&p, args->dnode, NULL); apply_mask_ipv6((struct prefix_ipv6 *)&p); return ripng_enable_network_delete(ripng, &p); @@ -238,33 +227,30 @@ int ripngd_instance_network_destroy(enum nb_event event, /* * XPath: /frr-ripngd:ripngd/instance/interface */ -int ripngd_instance_interface_create(enum nb_event event, - const struct lyd_node *dnode, - union nb_resource *resource) +int ripngd_instance_interface_create(struct nb_cb_create_args *args) { struct ripng *ripng; const char *ifname; - if (event != NB_EV_APPLY) + if (args->event != NB_EV_APPLY) return NB_OK; - ripng = nb_running_get_entry(dnode, NULL, true); - ifname = yang_dnode_get_string(dnode, NULL); + ripng = nb_running_get_entry(args->dnode, NULL, true); + ifname = yang_dnode_get_string(args->dnode, NULL); return ripng_enable_if_add(ripng, ifname); } -int ripngd_instance_interface_destroy(enum nb_event event, - const struct lyd_node *dnode) +int ripngd_instance_interface_destroy(struct nb_cb_destroy_args *args) { struct ripng *ripng; const char *ifname; - if (event != NB_EV_APPLY) + if (args->event != NB_EV_APPLY) return NB_OK; - ripng = nb_running_get_entry(dnode, NULL, true); - ifname = yang_dnode_get_string(dnode, NULL); + ripng = nb_running_get_entry(args->dnode, NULL, true); + ifname = yang_dnode_get_string(args->dnode, NULL); return ripng_enable_if_delete(ripng, ifname); } @@ -272,38 +258,35 @@ int ripngd_instance_interface_destroy(enum nb_event event, /* * XPath: /frr-ripngd:ripngd/instance/offset-list */ -int ripngd_instance_offset_list_create(enum nb_event event, - const struct lyd_node *dnode, - union nb_resource *resource) +int ripngd_instance_offset_list_create(struct nb_cb_create_args *args) { struct ripng *ripng; const char *ifname; struct ripng_offset_list *offset; - if (event != NB_EV_APPLY) + if (args->event != NB_EV_APPLY) return NB_OK; - ripng = nb_running_get_entry(dnode, NULL, true); - ifname = yang_dnode_get_string(dnode, "./interface"); + ripng = nb_running_get_entry(args->dnode, NULL, true); + ifname = yang_dnode_get_string(args->dnode, "./interface"); offset = ripng_offset_list_new(ripng, ifname); - nb_running_set_entry(dnode, offset); + nb_running_set_entry(args->dnode, offset); return NB_OK; } -int ripngd_instance_offset_list_destroy(enum nb_event event, - const struct lyd_node *dnode) +int ripngd_instance_offset_list_destroy(struct nb_cb_destroy_args *args) { int direct; struct ripng_offset_list *offset; - if (event != NB_EV_APPLY) + if (args->event != NB_EV_APPLY) return NB_OK; - direct = yang_dnode_get_enum(dnode, "./direction"); + direct = yang_dnode_get_enum(args->dnode, "./direction"); - offset = nb_running_unset_entry(dnode); + offset = nb_running_unset_entry(args->dnode); if (offset->direct[direct].alist_name) { free(offset->direct[direct].alist_name); offset->direct[direct].alist_name = NULL; @@ -318,21 +301,20 @@ int ripngd_instance_offset_list_destroy(enum nb_event event, /* * XPath: /frr-ripngd:ripngd/instance/offset-list/access-list */ -int ripngd_instance_offset_list_access_list_modify(enum nb_event event, - const struct lyd_node *dnode, - union nb_resource *resource) +int ripngd_instance_offset_list_access_list_modify( + struct nb_cb_modify_args *args) { int direct; struct ripng_offset_list *offset; const char *alist_name; - if (event != NB_EV_APPLY) + if (args->event != NB_EV_APPLY) return NB_OK; - direct = yang_dnode_get_enum(dnode, "../direction"); - alist_name = yang_dnode_get_string(dnode, NULL); + direct = yang_dnode_get_enum(args->dnode, "../direction"); + alist_name = yang_dnode_get_string(args->dnode, NULL); - offset = nb_running_get_entry(dnode, NULL, true); + offset = nb_running_get_entry(args->dnode, NULL, true); if (offset->direct[direct].alist_name) free(offset->direct[direct].alist_name); offset->direct[direct].alist_name = strdup(alist_name); @@ -343,21 +325,19 @@ int ripngd_instance_offset_list_access_list_modify(enum nb_event event, /* * XPath: /frr-ripngd:ripngd/instance/offset-list/metric */ -int ripngd_instance_offset_list_metric_modify(enum nb_event event, - const struct lyd_node *dnode, - union nb_resource *resource) +int ripngd_instance_offset_list_metric_modify(struct nb_cb_modify_args *args) { int direct; uint8_t metric; struct ripng_offset_list *offset; - if (event != NB_EV_APPLY) + if (args->event != NB_EV_APPLY) return NB_OK; - direct = yang_dnode_get_enum(dnode, "../direction"); - metric = yang_dnode_get_uint8(dnode, NULL); + direct = yang_dnode_get_enum(args->dnode, "../direction"); + metric = yang_dnode_get_uint8(args->dnode, NULL); - offset = nb_running_get_entry(dnode, NULL, true); + offset = nb_running_get_entry(args->dnode, NULL, true); offset->direct[direct].metric = metric; return NB_OK; @@ -366,33 +346,30 @@ int ripngd_instance_offset_list_metric_modify(enum nb_event event, /* * XPath: /frr-ripngd:ripngd/instance/passive-interface */ -int ripngd_instance_passive_interface_create(enum nb_event event, - const struct lyd_node *dnode, - union nb_resource *resource) +int ripngd_instance_passive_interface_create(struct nb_cb_create_args *args) { struct ripng *ripng; const char *ifname; - if (event != NB_EV_APPLY) + if (args->event != NB_EV_APPLY) return NB_OK; - ripng = nb_running_get_entry(dnode, NULL, true); - ifname = yang_dnode_get_string(dnode, NULL); + ripng = nb_running_get_entry(args->dnode, NULL, true); + ifname = yang_dnode_get_string(args->dnode, NULL); return ripng_passive_interface_set(ripng, ifname); } -int ripngd_instance_passive_interface_destroy(enum nb_event event, - const struct lyd_node *dnode) +int ripngd_instance_passive_interface_destroy(struct nb_cb_destroy_args *args) { struct ripng *ripng; const char *ifname; - if (event != NB_EV_APPLY) + if (args->event != NB_EV_APPLY) return NB_OK; - ripng = nb_running_get_entry(dnode, NULL, true); - ifname = yang_dnode_get_string(dnode, NULL); + ripng = nb_running_get_entry(args->dnode, NULL, true); + ifname = yang_dnode_get_string(args->dnode, NULL); return ripng_passive_interface_unset(ripng, ifname); } @@ -400,35 +377,32 @@ int ripngd_instance_passive_interface_destroy(enum nb_event event, /* * XPath: /frr-ripngd:ripngd/instance/redistribute */ -int ripngd_instance_redistribute_create(enum nb_event event, - const struct lyd_node *dnode, - union nb_resource *resource) +int ripngd_instance_redistribute_create(struct nb_cb_create_args *args) { struct ripng *ripng; int type; - if (event != NB_EV_APPLY) + if (args->event != NB_EV_APPLY) return NB_OK; - ripng = nb_running_get_entry(dnode, NULL, true); - type = yang_dnode_get_enum(dnode, "./protocol"); + ripng = nb_running_get_entry(args->dnode, NULL, true); + type = yang_dnode_get_enum(args->dnode, "./protocol"); ripng->redist[type].enabled = true; return NB_OK; } -int ripngd_instance_redistribute_destroy(enum nb_event event, - const struct lyd_node *dnode) +int ripngd_instance_redistribute_destroy(struct nb_cb_destroy_args *args) { struct ripng *ripng; int type; - if (event != NB_EV_APPLY) + if (args->event != NB_EV_APPLY) return NB_OK; - ripng = nb_running_get_entry(dnode, NULL, true); - type = yang_dnode_get_enum(dnode, "./protocol"); + ripng = nb_running_get_entry(args->dnode, NULL, true); + type = yang_dnode_get_enum(args->dnode, "./protocol"); ripng->redist[type].enabled = false; if (ripng->redist[type].route_map.name) { @@ -445,13 +419,14 @@ int ripngd_instance_redistribute_destroy(enum nb_event event, return NB_OK; } -void ripngd_instance_redistribute_apply_finish(const struct lyd_node *dnode) +void ripngd_instance_redistribute_apply_finish( + struct nb_cb_apply_finish_args *args) { struct ripng *ripng; int type; - ripng = nb_running_get_entry(dnode, NULL, true); - type = yang_dnode_get_enum(dnode, "./protocol"); + ripng = nb_running_get_entry(args->dnode, NULL, true); + type = yang_dnode_get_enum(args->dnode, "./protocol"); if (ripng->enabled) ripng_redistribute_conf_update(ripng, type); @@ -460,20 +435,19 @@ void ripngd_instance_redistribute_apply_finish(const struct lyd_node *dnode) /* * XPath: /frr-ripngd:ripngd/instance/redistribute/route-map */ -int ripngd_instance_redistribute_route_map_modify(enum nb_event event, - const struct lyd_node *dnode, - union nb_resource *resource) +int ripngd_instance_redistribute_route_map_modify( + struct nb_cb_modify_args *args) { struct ripng *ripng; int type; const char *rmap_name; - if (event != NB_EV_APPLY) + if (args->event != NB_EV_APPLY) return NB_OK; - ripng = nb_running_get_entry(dnode, NULL, true); - type = yang_dnode_get_enum(dnode, "../protocol"); - rmap_name = yang_dnode_get_string(dnode, NULL); + ripng = nb_running_get_entry(args->dnode, NULL, true); + type = yang_dnode_get_enum(args->dnode, "../protocol"); + rmap_name = yang_dnode_get_string(args->dnode, NULL); if (ripng->redist[type].route_map.name) free(ripng->redist[type].route_map.name); @@ -483,17 +457,17 @@ int ripngd_instance_redistribute_route_map_modify(enum nb_event event, return NB_OK; } -int ripngd_instance_redistribute_route_map_destroy(enum nb_event event, - const struct lyd_node *dnode) +int ripngd_instance_redistribute_route_map_destroy( + struct nb_cb_destroy_args *args) { struct ripng *ripng; int type; - if (event != NB_EV_APPLY) + if (args->event != NB_EV_APPLY) return NB_OK; - ripng = nb_running_get_entry(dnode, NULL, true); - type = yang_dnode_get_enum(dnode, "../protocol"); + ripng = nb_running_get_entry(args->dnode, NULL, true); + type = yang_dnode_get_enum(args->dnode, "../protocol"); free(ripng->redist[type].route_map.name); ripng->redist[type].route_map.name = NULL; @@ -505,20 +479,18 @@ int ripngd_instance_redistribute_route_map_destroy(enum nb_event event, /* * XPath: /frr-ripngd:ripngd/instance/redistribute/metric */ -int ripngd_instance_redistribute_metric_modify(enum nb_event event, - const struct lyd_node *dnode, - union nb_resource *resource) +int ripngd_instance_redistribute_metric_modify(struct nb_cb_modify_args *args) { struct ripng *ripng; int type; uint8_t metric; - if (event != NB_EV_APPLY) + if (args->event != NB_EV_APPLY) return NB_OK; - ripng = nb_running_get_entry(dnode, NULL, true); - type = yang_dnode_get_enum(dnode, "../protocol"); - metric = yang_dnode_get_uint8(dnode, NULL); + ripng = nb_running_get_entry(args->dnode, NULL, true); + type = yang_dnode_get_enum(args->dnode, "../protocol"); + metric = yang_dnode_get_uint8(args->dnode, NULL); ripng->redist[type].metric_config = true; ripng->redist[type].metric = metric; @@ -526,17 +498,16 @@ int ripngd_instance_redistribute_metric_modify(enum nb_event event, return NB_OK; } -int ripngd_instance_redistribute_metric_destroy(enum nb_event event, - const struct lyd_node *dnode) +int ripngd_instance_redistribute_metric_destroy(struct nb_cb_destroy_args *args) { struct ripng *ripng; int type; - if (event != NB_EV_APPLY) + if (args->event != NB_EV_APPLY) return NB_OK; - ripng = nb_running_get_entry(dnode, NULL, true); - type = yang_dnode_get_enum(dnode, "../protocol"); + ripng = nb_running_get_entry(args->dnode, NULL, true); + type = yang_dnode_get_enum(args->dnode, "../protocol"); ripng->redist[type].metric_config = false; ripng->redist[type].metric = 0; @@ -547,18 +518,16 @@ int ripngd_instance_redistribute_metric_destroy(enum nb_event event, /* * XPath: /frr-ripngd:ripngd/instance/static-route */ -int ripngd_instance_static_route_create(enum nb_event event, - const struct lyd_node *dnode, - union nb_resource *resource) +int ripngd_instance_static_route_create(struct nb_cb_create_args *args) { struct ripng *ripng; struct prefix_ipv6 p; - if (event != NB_EV_APPLY) + if (args->event != NB_EV_APPLY) return NB_OK; - ripng = nb_running_get_entry(dnode, NULL, true); - yang_dnode_get_ipv6p(&p, dnode, NULL); + ripng = nb_running_get_entry(args->dnode, NULL, true); + yang_dnode_get_ipv6p(&p, args->dnode, NULL); apply_mask_ipv6(&p); ripng_redistribute_add(ripng, ZEBRA_ROUTE_RIPNG, RIPNG_ROUTE_STATIC, &p, @@ -567,17 +536,16 @@ int ripngd_instance_static_route_create(enum nb_event event, return NB_OK; } -int ripngd_instance_static_route_destroy(enum nb_event event, - const struct lyd_node *dnode) +int ripngd_instance_static_route_destroy(struct nb_cb_destroy_args *args) { struct ripng *ripng; struct prefix_ipv6 p; - if (event != NB_EV_APPLY) + if (args->event != NB_EV_APPLY) return NB_OK; - ripng = nb_running_get_entry(dnode, NULL, true); - yang_dnode_get_ipv6p(&p, dnode, NULL); + ripng = nb_running_get_entry(args->dnode, NULL, true); + yang_dnode_get_ipv6p(&p, args->dnode, NULL); apply_mask_ipv6(&p); ripng_redistribute_delete(ripng, ZEBRA_ROUTE_RIPNG, RIPNG_ROUTE_STATIC, @@ -589,18 +557,16 @@ int ripngd_instance_static_route_destroy(enum nb_event event, /* * XPath: /frr-ripngd:ripngd/instance/aggregate-address */ -int ripngd_instance_aggregate_address_create(enum nb_event event, - const struct lyd_node *dnode, - union nb_resource *resource) +int ripngd_instance_aggregate_address_create(struct nb_cb_create_args *args) { struct ripng *ripng; struct prefix_ipv6 p; - if (event != NB_EV_APPLY) + if (args->event != NB_EV_APPLY) return NB_OK; - ripng = nb_running_get_entry(dnode, NULL, true); - yang_dnode_get_ipv6p(&p, dnode, NULL); + ripng = nb_running_get_entry(args->dnode, NULL, true); + yang_dnode_get_ipv6p(&p, args->dnode, NULL); apply_mask_ipv6(&p); ripng_aggregate_add(ripng, (struct prefix *)&p); @@ -608,17 +574,16 @@ int ripngd_instance_aggregate_address_create(enum nb_event event, return NB_OK; } -int ripngd_instance_aggregate_address_destroy(enum nb_event event, - const struct lyd_node *dnode) +int ripngd_instance_aggregate_address_destroy(struct nb_cb_destroy_args *args) { struct ripng *ripng; struct prefix_ipv6 p; - if (event != NB_EV_APPLY) + if (args->event != NB_EV_APPLY) return NB_OK; - ripng = nb_running_get_entry(dnode, NULL, true); - yang_dnode_get_ipv6p(&p, dnode, NULL); + ripng = nb_running_get_entry(args->dnode, NULL, true); + yang_dnode_get_ipv6p(&p, args->dnode, NULL); apply_mask_ipv6(&p); ripng_aggregate_delete(ripng, (struct prefix *)&p); @@ -629,11 +594,11 @@ int ripngd_instance_aggregate_address_destroy(enum nb_event event, /* * XPath: /frr-ripngd:ripngd/instance/timers */ -void ripngd_instance_timers_apply_finish(const struct lyd_node *dnode) +void ripngd_instance_timers_apply_finish(struct nb_cb_apply_finish_args *args) { struct ripng *ripng; - ripng = nb_running_get_entry(dnode, NULL, true); + ripng = nb_running_get_entry(args->dnode, NULL, true); /* Reset update timer thread. */ ripng_event(ripng, RIPNG_UPDATE_EVENT, 0); @@ -642,17 +607,15 @@ void ripngd_instance_timers_apply_finish(const struct lyd_node *dnode) /* * XPath: /frr-ripngd:ripngd/instance/timers/flush-interval */ -int ripngd_instance_timers_flush_interval_modify(enum nb_event event, - const struct lyd_node *dnode, - union nb_resource *resource) +int ripngd_instance_timers_flush_interval_modify(struct nb_cb_modify_args *args) { struct ripng *ripng; - if (event != NB_EV_APPLY) + if (args->event != NB_EV_APPLY) return NB_OK; - ripng = nb_running_get_entry(dnode, NULL, true); - ripng->garbage_time = yang_dnode_get_uint16(dnode, NULL); + ripng = nb_running_get_entry(args->dnode, NULL, true); + ripng->garbage_time = yang_dnode_get_uint16(args->dnode, NULL); return NB_OK; } @@ -661,16 +624,15 @@ int ripngd_instance_timers_flush_interval_modify(enum nb_event event, * XPath: /frr-ripngd:ripngd/instance/timers/holddown-interval */ int ripngd_instance_timers_holddown_interval_modify( - enum nb_event event, const struct lyd_node *dnode, - union nb_resource *resource) + struct nb_cb_modify_args *args) { struct ripng *ripng; - if (event != NB_EV_APPLY) + if (args->event != NB_EV_APPLY) return NB_OK; - ripng = nb_running_get_entry(dnode, NULL, true); - ripng->timeout_time = yang_dnode_get_uint16(dnode, NULL); + ripng = nb_running_get_entry(args->dnode, NULL, true); + ripng->timeout_time = yang_dnode_get_uint16(args->dnode, NULL); return NB_OK; } @@ -678,17 +640,16 @@ int ripngd_instance_timers_holddown_interval_modify( /* * XPath: /frr-ripngd:ripngd/instance/timers/update-interval */ -int ripngd_instance_timers_update_interval_modify(enum nb_event event, - const struct lyd_node *dnode, - union nb_resource *resource) +int ripngd_instance_timers_update_interval_modify( + struct nb_cb_modify_args *args) { struct ripng *ripng; - if (event != NB_EV_APPLY) + if (args->event != NB_EV_APPLY) return NB_OK; - ripng = nb_running_get_entry(dnode, NULL, true); - ripng->update_time = yang_dnode_get_uint16(dnode, NULL); + ripng = nb_running_get_entry(args->dnode, NULL, true); + ripng->update_time = yang_dnode_get_uint16(args->dnode, NULL); return NB_OK; } @@ -696,19 +657,17 @@ int ripngd_instance_timers_update_interval_modify(enum nb_event event, /* * XPath: /frr-interface:lib/interface/frr-ripngd:ripng/split-horizon */ -int lib_interface_ripng_split_horizon_modify(enum nb_event event, - const struct lyd_node *dnode, - union nb_resource *resource) +int lib_interface_ripng_split_horizon_modify(struct nb_cb_modify_args *args) { struct interface *ifp; struct ripng_interface *ri; - if (event != NB_EV_APPLY) + if (args->event != NB_EV_APPLY) return NB_OK; - ifp = nb_running_get_entry(dnode, NULL, true); + ifp = nb_running_get_entry(args->dnode, NULL, true); ri = ifp->info; - ri->split_horizon = yang_dnode_get_enum(dnode, NULL); + ri->split_horizon = yang_dnode_get_enum(args->dnode, NULL); return NB_OK; } diff --git a/ripngd/ripng_nb_rpcs.c b/ripngd/ripng_nb_rpcs.c index 0396daf89..4dfe9d964 100644 --- a/ripngd/ripng_nb_rpcs.c +++ b/ripngd/ripng_nb_rpcs.c @@ -80,13 +80,13 @@ static void clear_ripng_route(struct ripng *ripng) } } -int clear_ripng_route_rpc(const char *xpath, const struct list *input, - struct list *output) +int clear_ripng_route_rpc(struct nb_cb_rpc_args *args) { struct ripng *ripng; struct yang_data *yang_vrf; - yang_vrf = yang_data_list_find(input, "%s/%s", xpath, "input/vrf"); + yang_vrf = yang_data_list_find(args->input, "%s/%s", args->xpath, + "input/vrf"); if (yang_vrf) { ripng = ripng_lookup_by_vrf_name(yang_vrf->value); if (ripng) diff --git a/ripngd/ripng_nb_state.c b/ripngd/ripng_nb_state.c index 75dec3cb3..926573b40 100644 --- a/ripngd/ripng_nb_state.c +++ b/ripngd/ripng_nb_state.c @@ -38,43 +38,42 @@ /* * XPath: /frr-ripngd:ripngd/instance/state/neighbors/neighbor */ -const void * -ripngd_instance_state_neighbors_neighbor_get_next(const void *parent_list_entry, - const void *list_entry) +const void *ripngd_instance_state_neighbors_neighbor_get_next( + struct nb_cb_get_next_args *args) { - const struct ripng *ripng = parent_list_entry; + const struct ripng *ripng = args->parent_list_entry; struct listnode *node; - if (list_entry == NULL) + if (args->list_entry == NULL) node = listhead(ripng->peer_list); else - node = listnextnode((struct listnode *)list_entry); + node = listnextnode((struct listnode *)args->list_entry); return node; } int ripngd_instance_state_neighbors_neighbor_get_keys( - const void *list_entry, struct yang_list_keys *keys) + struct nb_cb_get_keys_args *args) { - const struct listnode *node = list_entry; + const struct listnode *node = args->list_entry; const struct ripng_peer *peer = listgetdata(node); - keys->num = 1; - (void)inet_ntop(AF_INET6, &peer->addr, keys->key[0], - sizeof(keys->key[0])); + args->keys->num = 1; + (void)inet_ntop(AF_INET6, &peer->addr, args->keys->key[0], + sizeof(args->keys->key[0])); return NB_OK; } const void *ripngd_instance_state_neighbors_neighbor_lookup_entry( - const void *parent_list_entry, const struct yang_list_keys *keys) + struct nb_cb_lookup_entry_args *args) { - const struct ripng *ripng = parent_list_entry; + const struct ripng *ripng = args->parent_list_entry; struct in6_addr address; struct ripng_peer *peer; struct listnode *node; - yang_str2ipv6(keys->key[0], &address); + yang_str2ipv6(args->keys->key[0], &address); for (ALL_LIST_ELEMENTS_RO(ripng->peer_list, node, peer)) { if (IPV6_ADDR_SAME(&peer->addr, &address)) @@ -88,19 +87,19 @@ const void *ripngd_instance_state_neighbors_neighbor_lookup_entry( * XPath: /frr-ripngd:ripngd/instance/state/neighbors/neighbor/address */ struct yang_data *ripngd_instance_state_neighbors_neighbor_address_get_elem( - const char *xpath, const void *list_entry) + struct nb_cb_get_elem_args *args) { - const struct listnode *node = list_entry; + const struct listnode *node = args->list_entry; const struct ripng_peer *peer = listgetdata(node); - return yang_data_new_ipv6(xpath, &peer->addr); + return yang_data_new_ipv6(args->xpath, &peer->addr); } /* * XPath: /frr-ripngd:ripngd/instance/state/neighbors/neighbor/last-update */ struct yang_data *ripngd_instance_state_neighbors_neighbor_last_update_get_elem( - const char *xpath, const void *list_entry) + struct nb_cb_get_elem_args *args) { /* TODO: yang:date-and-time is tricky */ return NULL; @@ -111,12 +110,12 @@ struct yang_data *ripngd_instance_state_neighbors_neighbor_last_update_get_elem( */ struct yang_data * ripngd_instance_state_neighbors_neighbor_bad_packets_rcvd_get_elem( - const char *xpath, const void *list_entry) + struct nb_cb_get_elem_args *args) { - const struct listnode *node = list_entry; + const struct listnode *node = args->list_entry; const struct ripng_peer *peer = listgetdata(node); - return yang_data_new_uint32(xpath, peer->recv_badpackets); + return yang_data_new_uint32(args->xpath, peer->recv_badpackets); } /* @@ -124,54 +123,53 @@ ripngd_instance_state_neighbors_neighbor_bad_packets_rcvd_get_elem( */ struct yang_data * ripngd_instance_state_neighbors_neighbor_bad_routes_rcvd_get_elem( - const char *xpath, const void *list_entry) + struct nb_cb_get_elem_args *args) { - const struct listnode *node = list_entry; + const struct listnode *node = args->list_entry; const struct ripng_peer *peer = listgetdata(node); - return yang_data_new_uint32(xpath, peer->recv_badroutes); + return yang_data_new_uint32(args->xpath, peer->recv_badroutes); } /* * XPath: /frr-ripngd:ripngd/instance/state/routes/route */ const void * -ripngd_instance_state_routes_route_get_next(const void *parent_list_entry, - const void *list_entry) +ripngd_instance_state_routes_route_get_next(struct nb_cb_get_next_args *args) { - const struct ripng *ripng = parent_list_entry; + const struct ripng *ripng = args->parent_list_entry; struct agg_node *rn; - if (list_entry == NULL) + if (args->list_entry == NULL) rn = agg_route_top(ripng->table); else - rn = agg_route_next((struct agg_node *)list_entry); + rn = agg_route_next((struct agg_node *)args->list_entry); while (rn && rn->info == NULL) rn = agg_route_next(rn); return rn; } -int ripngd_instance_state_routes_route_get_keys(const void *list_entry, - struct yang_list_keys *keys) +int ripngd_instance_state_routes_route_get_keys( + struct nb_cb_get_keys_args *args) { - const struct agg_node *rn = list_entry; + const struct agg_node *rn = args->list_entry; - keys->num = 1; - (void)prefix2str(agg_node_get_prefix(rn), keys->key[0], - sizeof(keys->key[0])); + args->keys->num = 1; + (void)prefix2str(agg_node_get_prefix(rn), args->keys->key[0], + sizeof(args->keys->key[0])); return NB_OK; } const void *ripngd_instance_state_routes_route_lookup_entry( - const void *parent_list_entry, const struct yang_list_keys *keys) + struct nb_cb_lookup_entry_args *args) { - const struct ripng *ripng = parent_list_entry; + const struct ripng *ripng = args->parent_list_entry; struct prefix prefix; struct agg_node *rn; - yang_str2ipv6p(keys->key[0], &prefix); + yang_str2ipv6p(args->keys->key[0], &prefix); rn = agg_node_lookup(ripng->table, &prefix); if (!rn || !rn->info) @@ -185,53 +183,50 @@ const void *ripngd_instance_state_routes_route_lookup_entry( /* * XPath: /frr-ripngd:ripngd/instance/state/routes/route/prefix */ -struct yang_data * -ripngd_instance_state_routes_route_prefix_get_elem(const char *xpath, - const void *list_entry) +struct yang_data *ripngd_instance_state_routes_route_prefix_get_elem( + struct nb_cb_get_elem_args *args) { - const struct agg_node *rn = list_entry; + const struct agg_node *rn = args->list_entry; const struct ripng_info *rinfo = listnode_head(rn->info); - return yang_data_new_ipv6p(xpath, agg_node_get_prefix(rinfo->rp)); + return yang_data_new_ipv6p(args->xpath, agg_node_get_prefix(rinfo->rp)); } /* * XPath: /frr-ripngd:ripngd/instance/state/routes/route/next-hop */ -struct yang_data * -ripngd_instance_state_routes_route_next_hop_get_elem(const char *xpath, - const void *list_entry) +struct yang_data *ripngd_instance_state_routes_route_next_hop_get_elem( + struct nb_cb_get_elem_args *args) { - const struct agg_node *rn = list_entry; + const struct agg_node *rn = args->list_entry; const struct ripng_info *rinfo = listnode_head(rn->info); - return yang_data_new_ipv6(xpath, &rinfo->nexthop); + return yang_data_new_ipv6(args->xpath, &rinfo->nexthop); } /* * XPath: /frr-ripngd:ripngd/instance/state/routes/route/interface */ -struct yang_data * -ripngd_instance_state_routes_route_interface_get_elem(const char *xpath, - const void *list_entry) +struct yang_data *ripngd_instance_state_routes_route_interface_get_elem( + struct nb_cb_get_elem_args *args) { - const struct agg_node *rn = list_entry; + const struct agg_node *rn = args->list_entry; const struct ripng_info *rinfo = listnode_head(rn->info); const struct ripng *ripng = ripng_info_get_instance(rinfo); return yang_data_new_string( - xpath, ifindex2ifname(rinfo->ifindex, ripng->vrf->vrf_id)); + args->xpath, + ifindex2ifname(rinfo->ifindex, ripng->vrf->vrf_id)); } /* * XPath: /frr-ripngd:ripngd/instance/state/routes/route/metric */ -struct yang_data * -ripngd_instance_state_routes_route_metric_get_elem(const char *xpath, - const void *list_entry) +struct yang_data *ripngd_instance_state_routes_route_metric_get_elem( + struct nb_cb_get_elem_args *args) { - const struct agg_node *rn = list_entry; + const struct agg_node *rn = args->list_entry; const struct ripng_info *rinfo = listnode_head(rn->info); - return yang_data_new_uint8(xpath, rinfo->metric); + return yang_data_new_uint8(args->xpath, rinfo->metric); } |