summaryrefslogtreecommitdiffstats
path: root/bfdd/bfdd_nb_state.c
diff options
context:
space:
mode:
authorRenato Westphal <renato@opensourcerouting.org>2020-04-04 18:38:51 +0200
committerRenato Westphal <renato@opensourcerouting.org>2020-04-23 15:14:32 +0200
commit60ee8be107c593212a9b53e8ed5c34c4c5e70af3 (patch)
treef86993b9f63afab4a8e0291f27fd8f938f5dec8d /bfdd/bfdd_nb_state.c
parentlib: create a wrapper function for all northbound callbacks (diff)
downloadfrr-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 'bfdd/bfdd_nb_state.c')
-rw-r--r--bfdd/bfdd_nb_state.c189
1 files changed, 91 insertions, 98 deletions
diff --git a/bfdd/bfdd_nb_state.c b/bfdd/bfdd_nb_state.c
index 2a44d46c4..043f850af 100644
--- a/bfdd/bfdd_nb_state.c
+++ b/bfdd/bfdd_nb_state.c
@@ -31,37 +31,34 @@
/*
* XPath: /frr-bfdd:bfdd/bfd/sessions/single-hop
*/
-const void *bfdd_bfd_sessions_single_hop_get_next(const void *parent_list_entry
- __attribute__((__unused__)),
- const void *list_entry)
+const void *
+bfdd_bfd_sessions_single_hop_get_next(struct nb_cb_get_next_args *args)
{
- return bfd_session_next(list_entry, false);
+ return bfd_session_next(args->list_entry, false);
}
-int bfdd_bfd_sessions_single_hop_get_keys(const void *list_entry,
- struct yang_list_keys *keys)
+int bfdd_bfd_sessions_single_hop_get_keys(struct nb_cb_get_keys_args *args)
{
- const struct bfd_session *bs = list_entry;
+ const struct bfd_session *bs = args->list_entry;
char dstbuf[INET6_ADDRSTRLEN];
inet_ntop(bs->key.family, &bs->key.peer, dstbuf, sizeof(dstbuf));
- keys->num = 3;
- strlcpy(keys->key[0], dstbuf, sizeof(keys->key[0]));
- strlcpy(keys->key[1], bs->key.ifname, sizeof(keys->key[1]));
- strlcpy(keys->key[2], bs->key.vrfname, sizeof(keys->key[2]));
+ args->keys->num = 3;
+ strlcpy(args->keys->key[0], dstbuf, sizeof(args->keys->key[0]));
+ strlcpy(args->keys->key[1], bs->key.ifname, sizeof(args->keys->key[1]));
+ strlcpy(args->keys->key[2], bs->key.vrfname,
+ sizeof(args->keys->key[2]));
return NB_OK;
}
const void *
-bfdd_bfd_sessions_single_hop_lookup_entry(const void *parent_list_entry
- __attribute__((__unused__)),
- const struct yang_list_keys *keys)
+bfdd_bfd_sessions_single_hop_lookup_entry(struct nb_cb_lookup_entry_args *args)
{
- const char *dest_addr = keys->key[0];
- const char *ifname = keys->key[1];
- const char *vrf = keys->key[2];
+ const char *dest_addr = args->keys->key[0];
+ const char *ifname = args->keys->key[1];
+ const char *vrf = args->keys->key[2];
struct sockaddr_any psa, lsa;
struct bfd_key bk;
@@ -77,45 +74,44 @@ bfdd_bfd_sessions_single_hop_lookup_entry(const void *parent_list_entry
*/
struct yang_data *
bfdd_bfd_sessions_single_hop_stats_local_discriminator_get_elem(
- const char *xpath, const void *list_entry)
+ struct nb_cb_get_elem_args *args)
{
- const struct bfd_session *bs = list_entry;
+ const struct bfd_session *bs = args->list_entry;
- return yang_data_new_uint32(xpath, bs->discrs.my_discr);
+ return yang_data_new_uint32(args->xpath, bs->discrs.my_discr);
}
/*
* XPath: /frr-bfdd:bfdd/bfd/sessions/single-hop/stats/local-state
*/
-struct yang_data *
-bfdd_bfd_sessions_single_hop_stats_local_state_get_elem(const char *xpath,
- const void *list_entry)
+struct yang_data *bfdd_bfd_sessions_single_hop_stats_local_state_get_elem(
+ struct nb_cb_get_elem_args *args)
{
- const struct bfd_session *bs = list_entry;
+ const struct bfd_session *bs = args->list_entry;
- return yang_data_new_enum(xpath, bs->ses_state);
+ return yang_data_new_enum(args->xpath, bs->ses_state);
}
/*
* XPath: /frr-bfdd:bfdd/bfd/sessions/single-hop/stats/local-diagnostic
*/
struct yang_data *bfdd_bfd_sessions_single_hop_stats_local_diagnostic_get_elem(
- const char *xpath, const void *list_entry)
+ struct nb_cb_get_elem_args *args)
{
- const struct bfd_session *bs = list_entry;
+ const struct bfd_session *bs = args->list_entry;
- return yang_data_new_enum(xpath, bs->local_diag);
+ return yang_data_new_enum(args->xpath, bs->local_diag);
}
/*
* XPath: /frr-bfdd:bfdd/bfd/sessions/single-hop/stats/local-multiplier
*/
struct yang_data *bfdd_bfd_sessions_single_hop_stats_local_multiplier_get_elem(
- const char *xpath, const void *list_entry)
+ struct nb_cb_get_elem_args *args)
{
- const struct bfd_session *bs = list_entry;
+ const struct bfd_session *bs = args->list_entry;
- return yang_data_new_int8(xpath, bs->detect_mult);
+ return yang_data_new_int8(args->xpath, bs->detect_mult);
}
/*
@@ -123,48 +119,47 @@ struct yang_data *bfdd_bfd_sessions_single_hop_stats_local_multiplier_get_elem(
*/
struct yang_data *
bfdd_bfd_sessions_single_hop_stats_remote_discriminator_get_elem(
- const char *xpath, const void *list_entry)
+ struct nb_cb_get_elem_args *args)
{
- const struct bfd_session *bs = list_entry;
+ const struct bfd_session *bs = args->list_entry;
if (bs->discrs.remote_discr == 0)
return NULL;
- return yang_data_new_uint32(xpath, bs->discrs.remote_discr);
+ return yang_data_new_uint32(args->xpath, bs->discrs.remote_discr);
}
/*
* XPath: /frr-bfdd:bfdd/bfd/sessions/single-hop/stats/remote-state
*/
-struct yang_data *
-bfdd_bfd_sessions_single_hop_stats_remote_state_get_elem(const char *xpath,
- const void *list_entry)
+struct yang_data *bfdd_bfd_sessions_single_hop_stats_remote_state_get_elem(
+ struct nb_cb_get_elem_args *args)
{
- const struct bfd_session *bs = list_entry;
+ const struct bfd_session *bs = args->list_entry;
- return yang_data_new_enum(xpath, bs->ses_state);
+ return yang_data_new_enum(args->xpath, bs->ses_state);
}
/*
* XPath: /frr-bfdd:bfdd/bfd/sessions/single-hop/stats/remote-diagnostic
*/
struct yang_data *bfdd_bfd_sessions_single_hop_stats_remote_diagnostic_get_elem(
- const char *xpath, const void *list_entry)
+ struct nb_cb_get_elem_args *args)
{
- const struct bfd_session *bs = list_entry;
+ const struct bfd_session *bs = args->list_entry;
- return yang_data_new_enum(xpath, bs->remote_diag);
+ return yang_data_new_enum(args->xpath, bs->remote_diag);
}
/*
* XPath: /frr-bfdd:bfdd/bfd/sessions/single-hop/stats/remote-multiplier
*/
struct yang_data *bfdd_bfd_sessions_single_hop_stats_remote_multiplier_get_elem(
- const char *xpath, const void *list_entry)
+ struct nb_cb_get_elem_args *args)
{
- const struct bfd_session *bs = list_entry;
+ const struct bfd_session *bs = args->list_entry;
- return yang_data_new_int8(xpath, bs->remote_detect_mult);
+ return yang_data_new_int8(args->xpath, bs->remote_detect_mult);
}
/*
@@ -173,11 +168,12 @@ struct yang_data *bfdd_bfd_sessions_single_hop_stats_remote_multiplier_get_elem(
*/
struct yang_data *
bfdd_bfd_sessions_single_hop_stats_negotiated_transmission_interval_get_elem(
- const char *xpath, const void *list_entry)
+ struct nb_cb_get_elem_args *args)
{
- const struct bfd_session *bs = list_entry;
+ const struct bfd_session *bs = args->list_entry;
- return yang_data_new_uint32(xpath, bs->remote_timers.desired_min_tx);
+ return yang_data_new_uint32(args->xpath,
+ bs->remote_timers.desired_min_tx);
}
/*
@@ -186,20 +182,21 @@ bfdd_bfd_sessions_single_hop_stats_negotiated_transmission_interval_get_elem(
*/
struct yang_data *
bfdd_bfd_sessions_single_hop_stats_negotiated_receive_interval_get_elem(
- const char *xpath, const void *list_entry)
+ struct nb_cb_get_elem_args *args)
{
- const struct bfd_session *bs = list_entry;
+ const struct bfd_session *bs = args->list_entry;
- return yang_data_new_uint32(xpath, bs->remote_timers.required_min_rx);
+ return yang_data_new_uint32(args->xpath,
+ bs->remote_timers.required_min_rx);
}
/*
* XPath: /frr-bfdd:bfdd/bfd/sessions/single-hop/stats/detection-mode
*/
struct yang_data *bfdd_bfd_sessions_single_hop_stats_detection_mode_get_elem(
- const char *xpath, const void *list_entry)
+ struct nb_cb_get_elem_args *args)
{
- const struct bfd_session *bs = list_entry;
+ const struct bfd_session *bs = args->list_entry;
int detection_mode;
/*
@@ -216,15 +213,14 @@ struct yang_data *bfdd_bfd_sessions_single_hop_stats_detection_mode_get_elem(
else
detection_mode = 2;
- return yang_data_new_enum(xpath, detection_mode);
+ return yang_data_new_enum(args->xpath, detection_mode);
}
/*
* XPath: /frr-bfdd:bfdd/bfd/sessions/single-hop/stats/last-down-time
*/
struct yang_data *bfdd_bfd_sessions_single_hop_stats_last_down_time_get_elem(
- const char *xpath __attribute__((__unused__)),
- const void *list_entry __attribute__((__unused__)))
+ struct nb_cb_get_elem_args *args)
{
/*
* TODO: implement me.
@@ -238,8 +234,7 @@ struct yang_data *bfdd_bfd_sessions_single_hop_stats_last_down_time_get_elem(
* XPath: /frr-bfdd:bfdd/bfd/sessions/single-hop/stats/last-up-time
*/
struct yang_data *bfdd_bfd_sessions_single_hop_stats_last_up_time_get_elem(
- const char *xpath __attribute__((__unused__)),
- const void *list_entry __attribute__((__unused__)))
+ struct nb_cb_get_elem_args *args)
{
/*
* TODO: implement me.
@@ -254,22 +249,22 @@ struct yang_data *bfdd_bfd_sessions_single_hop_stats_last_up_time_get_elem(
*/
struct yang_data *
bfdd_bfd_sessions_single_hop_stats_session_down_count_get_elem(
- const char *xpath, const void *list_entry)
+ struct nb_cb_get_elem_args *args)
{
- const struct bfd_session *bs = list_entry;
+ const struct bfd_session *bs = args->list_entry;
- return yang_data_new_uint64(xpath, bs->stats.session_down);
+ return yang_data_new_uint64(args->xpath, bs->stats.session_down);
}
/*
* XPath: /frr-bfdd:bfdd/bfd/sessions/single-hop/stats/session-up-count
*/
struct yang_data *bfdd_bfd_sessions_single_hop_stats_session_up_count_get_elem(
- const char *xpath, const void *list_entry)
+ struct nb_cb_get_elem_args *args)
{
- const struct bfd_session *bs = list_entry;
+ const struct bfd_session *bs = args->list_entry;
- return yang_data_new_uint64(xpath, bs->stats.session_up);
+ return yang_data_new_uint64(args->xpath, bs->stats.session_up);
}
/*
@@ -278,11 +273,11 @@ struct yang_data *bfdd_bfd_sessions_single_hop_stats_session_up_count_get_elem(
*/
struct yang_data *
bfdd_bfd_sessions_single_hop_stats_control_packet_input_count_get_elem(
- const char *xpath, const void *list_entry)
+ struct nb_cb_get_elem_args *args)
{
- const struct bfd_session *bs = list_entry;
+ const struct bfd_session *bs = args->list_entry;
- return yang_data_new_uint64(xpath, bs->stats.rx_ctrl_pkt);
+ return yang_data_new_uint64(args->xpath, bs->stats.rx_ctrl_pkt);
}
/*
@@ -291,11 +286,11 @@ bfdd_bfd_sessions_single_hop_stats_control_packet_input_count_get_elem(
*/
struct yang_data *
bfdd_bfd_sessions_single_hop_stats_control_packet_output_count_get_elem(
- const char *xpath, const void *list_entry)
+ struct nb_cb_get_elem_args *args)
{
- const struct bfd_session *bs = list_entry;
+ const struct bfd_session *bs = args->list_entry;
- return yang_data_new_uint64(xpath, bs->stats.tx_ctrl_pkt);
+ return yang_data_new_uint64(args->xpath, bs->stats.tx_ctrl_pkt);
}
/*
@@ -304,11 +299,12 @@ bfdd_bfd_sessions_single_hop_stats_control_packet_output_count_get_elem(
*/
struct yang_data *
bfdd_bfd_sessions_single_hop_stats_negotiated_echo_transmission_interval_get_elem(
- const char *xpath, const void *list_entry)
+ struct nb_cb_get_elem_args *args)
{
- const struct bfd_session *bs = list_entry;
+ const struct bfd_session *bs = args->list_entry;
- return yang_data_new_uint32(xpath, bs->remote_timers.required_min_echo);
+ return yang_data_new_uint32(args->xpath,
+ bs->remote_timers.required_min_echo);
}
/*
@@ -316,11 +312,11 @@ bfdd_bfd_sessions_single_hop_stats_negotiated_echo_transmission_interval_get_ele
*/
struct yang_data *
bfdd_bfd_sessions_single_hop_stats_echo_packet_input_count_get_elem(
- const char *xpath, const void *list_entry)
+ struct nb_cb_get_elem_args *args)
{
- const struct bfd_session *bs = list_entry;
+ const struct bfd_session *bs = args->list_entry;
- return yang_data_new_uint64(xpath, bs->stats.rx_echo_pkt);
+ return yang_data_new_uint64(args->xpath, bs->stats.rx_echo_pkt);
}
/*
@@ -328,50 +324,47 @@ bfdd_bfd_sessions_single_hop_stats_echo_packet_input_count_get_elem(
*/
struct yang_data *
bfdd_bfd_sessions_single_hop_stats_echo_packet_output_count_get_elem(
- const char *xpath, const void *list_entry)
+ struct nb_cb_get_elem_args *args)
{
- const struct bfd_session *bs = list_entry;
+ const struct bfd_session *bs = args->list_entry;
- return yang_data_new_uint64(xpath, bs->stats.tx_echo_pkt);
+ return yang_data_new_uint64(args->xpath, bs->stats.tx_echo_pkt);
}
/*
* XPath: /frr-bfdd:bfdd/bfd/sessions/multi-hop
*/
-const void *bfdd_bfd_sessions_multi_hop_get_next(const void *parent_list_entry
- __attribute__((__unused__)),
- const void *list_entry)
+const void *
+bfdd_bfd_sessions_multi_hop_get_next(struct nb_cb_get_next_args *args)
{
- return bfd_session_next(list_entry, true);
+ return bfd_session_next(args->list_entry, true);
}
-int bfdd_bfd_sessions_multi_hop_get_keys(const void *list_entry,
- struct yang_list_keys *keys)
+int bfdd_bfd_sessions_multi_hop_get_keys(struct nb_cb_get_keys_args *args)
{
- const struct bfd_session *bs = list_entry;
+ const struct bfd_session *bs = args->list_entry;
char dstbuf[INET6_ADDRSTRLEN], srcbuf[INET6_ADDRSTRLEN];
inet_ntop(bs->key.family, &bs->key.peer, dstbuf, sizeof(dstbuf));
inet_ntop(bs->key.family, &bs->key.local, srcbuf, sizeof(srcbuf));
- keys->num = 4;
- strlcpy(keys->key[0], srcbuf, sizeof(keys->key[0]));
- strlcpy(keys->key[1], dstbuf, sizeof(keys->key[1]));
- strlcpy(keys->key[2], bs->key.ifname, sizeof(keys->key[2]));
- strlcpy(keys->key[3], bs->key.vrfname, sizeof(keys->key[3]));
+ args->keys->num = 4;
+ strlcpy(args->keys->key[0], srcbuf, sizeof(args->keys->key[0]));
+ strlcpy(args->keys->key[1], dstbuf, sizeof(args->keys->key[1]));
+ strlcpy(args->keys->key[2], bs->key.ifname, sizeof(args->keys->key[2]));
+ strlcpy(args->keys->key[3], bs->key.vrfname,
+ sizeof(args->keys->key[3]));
return NB_OK;
}
const void *
-bfdd_bfd_sessions_multi_hop_lookup_entry(const void *parent_list_entry
- __attribute__((__unused__)),
- const struct yang_list_keys *keys)
+bfdd_bfd_sessions_multi_hop_lookup_entry(struct nb_cb_lookup_entry_args *args)
{
- const char *source_addr = keys->key[0];
- const char *dest_addr = keys->key[1];
- const char *ifname = keys->key[2];
- const char *vrf = keys->key[3];
+ const char *source_addr = args->keys->key[0];
+ const char *dest_addr = args->keys->key[1];
+ const char *ifname = args->keys->key[2];
+ const char *vrf = args->keys->key[3];
struct sockaddr_any psa, lsa;
struct bfd_key bk;