summaryrefslogtreecommitdiff
path: root/lib/if.c
diff options
context:
space:
mode:
authorRenato Westphal <renato@opensourcerouting.org>2020-04-04 13:38:51 -0300
committerRenato Westphal <renato@opensourcerouting.org>2020-04-23 10:14:32 -0300
commit60ee8be107c593212a9b53e8ed5c34c4c5e70af3 (patch)
treef86993b9f63afab4a8e0291f27fd8f938f5dec8d /lib/if.c
parent97cd849362b45ecbcb20194b5771c5ce777de6bc (diff)
*: 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 'lib/if.c')
-rw-r--r--lib/if.c121
1 files changed, 56 insertions, 65 deletions
diff --git a/lib/if.c b/lib/if.c
index c887bb6265..96638dc918 100644
--- a/lib/if.c
+++ b/lib/if.c
@@ -1489,19 +1489,17 @@ void if_zapi_callbacks(int (*create)(struct interface *ifp),
/*
* XPath: /frr-interface:lib/interface
*/
-static int lib_interface_create(enum nb_event event,
- const struct lyd_node *dnode,
- union nb_resource *resource)
+static int lib_interface_create(struct nb_cb_create_args *args)
{
const char *ifname;
const char *vrfname;
struct vrf *vrf;
struct interface *ifp;
- ifname = yang_dnode_get_string(dnode, "./name");
- vrfname = yang_dnode_get_string(dnode, "./vrf");
+ ifname = yang_dnode_get_string(args->dnode, "./name");
+ vrfname = yang_dnode_get_string(args->dnode, "./vrf");
- switch (event) {
+ switch (args->event) {
case NB_EV_VALIDATE:
vrf = vrf_lookup_by_name(vrfname);
if (!vrf) {
@@ -1542,22 +1540,21 @@ static int lib_interface_create(enum nb_event event,
#endif /* SUNOS_5 */
ifp->configured = true;
- nb_running_set_entry(dnode, ifp);
+ nb_running_set_entry(args->dnode, ifp);
break;
}
return NB_OK;
}
-static int lib_interface_destroy(enum nb_event event,
- const struct lyd_node *dnode)
+static int lib_interface_destroy(struct nb_cb_destroy_args *args)
{
struct interface *ifp;
- switch (event) {
+ switch (args->event) {
case NB_EV_VALIDATE:
- ifp = nb_running_get_entry(dnode, NULL, true);
+ ifp = nb_running_get_entry(args->dnode, NULL, true);
if (CHECK_FLAG(ifp->status, ZEBRA_INTERFACE_ACTIVE)) {
zlog_warn("%s: only inactive interfaces can be deleted",
__func__);
@@ -1568,7 +1565,7 @@ static int lib_interface_destroy(enum nb_event event,
case NB_EV_ABORT:
break;
case NB_EV_APPLY:
- ifp = nb_running_unset_entry(dnode);
+ ifp = nb_running_unset_entry(args->dnode);
ifp->configured = false;
if_delete(&ifp);
@@ -1581,13 +1578,12 @@ static int lib_interface_destroy(enum nb_event event,
/*
* XPath: /frr-interface:lib/interface
*/
-static const void *lib_interface_get_next(const void *parent_list_entry,
- const void *list_entry)
+static const void *lib_interface_get_next(struct nb_cb_get_next_args *args)
{
struct vrf *vrf;
- struct interface *pif = (struct interface *)list_entry;
+ struct interface *pif = (struct interface *)args->list_entry;
- if (list_entry == NULL) {
+ if (args->list_entry == NULL) {
vrf = RB_MIN(vrf_name_head, &vrfs_by_name);
assert(vrf);
pif = RB_MIN(if_name_head, &vrf->ifaces_by_name);
@@ -1606,27 +1602,26 @@ static const void *lib_interface_get_next(const void *parent_list_entry,
return pif;
}
-static int lib_interface_get_keys(const void *list_entry,
- struct yang_list_keys *keys)
+static int lib_interface_get_keys(struct nb_cb_get_keys_args *args)
{
- const struct interface *ifp = list_entry;
+ const struct interface *ifp = args->list_entry;
struct vrf *vrf = vrf_lookup_by_id(ifp->vrf_id);
assert(vrf);
- keys->num = 2;
- strlcpy(keys->key[0], ifp->name, sizeof(keys->key[0]));
- strlcpy(keys->key[1], vrf->name, sizeof(keys->key[1]));
+ args->keys->num = 2;
+ strlcpy(args->keys->key[0], ifp->name, sizeof(args->keys->key[0]));
+ strlcpy(args->keys->key[1], vrf->name, sizeof(args->keys->key[1]));
return NB_OK;
}
-static const void *lib_interface_lookup_entry(const void *parent_list_entry,
- const struct yang_list_keys *keys)
+static const void *
+lib_interface_lookup_entry(struct nb_cb_lookup_entry_args *args)
{
- const char *ifname = keys->key[0];
- const char *vrfname = keys->key[1];
+ const char *ifname = args->keys->key[0];
+ const char *vrfname = args->keys->key[1];
struct vrf *vrf = vrf_lookup_by_name(vrfname);
return vrf ? if_lookup_by_name(ifname, vrf->vrf_id) : NULL;
@@ -1635,33 +1630,30 @@ static const void *lib_interface_lookup_entry(const void *parent_list_entry,
/*
* XPath: /frr-interface:lib/interface/description
*/
-static int lib_interface_description_modify(enum nb_event event,
- const struct lyd_node *dnode,
- union nb_resource *resource)
+static int lib_interface_description_modify(struct nb_cb_modify_args *args)
{
struct interface *ifp;
const char *description;
- 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);
XFREE(MTYPE_TMP, ifp->desc);
- description = yang_dnode_get_string(dnode, NULL);
+ description = yang_dnode_get_string(args->dnode, NULL);
ifp->desc = XSTRDUP(MTYPE_TMP, description);
return NB_OK;
}
-static int lib_interface_description_destroy(enum nb_event event,
- const struct lyd_node *dnode)
+static int lib_interface_description_destroy(struct nb_cb_destroy_args *args)
{
struct interface *ifp;
- 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);
XFREE(MTYPE_TMP, ifp->desc);
return NB_OK;
@@ -1670,63 +1662,63 @@ static int lib_interface_description_destroy(enum nb_event event,
/*
* XPath: /frr-interface:lib/interface/state/if-index
*/
-struct yang_data *lib_interface_state_if_index_get_elem(const char *xpath,
- const void *list_entry)
+static struct yang_data *
+lib_interface_state_if_index_get_elem(struct nb_cb_get_elem_args *args)
{
- const struct interface *ifp = list_entry;
+ const struct interface *ifp = args->list_entry;
- return yang_data_new_int32(xpath, ifp->ifindex);
+ return yang_data_new_int32(args->xpath, ifp->ifindex);
}
/*
* XPath: /frr-interface:lib/interface/state/mtu
*/
-struct yang_data *lib_interface_state_mtu_get_elem(const char *xpath,
- const void *list_entry)
+static struct yang_data *
+lib_interface_state_mtu_get_elem(struct nb_cb_get_elem_args *args)
{
- const struct interface *ifp = list_entry;
+ const struct interface *ifp = args->list_entry;
- return yang_data_new_uint16(xpath, ifp->mtu);
+ return yang_data_new_uint16(args->xpath, ifp->mtu);
}
/*
* XPath: /frr-interface:lib/interface/state/mtu6
*/
-struct yang_data *lib_interface_state_mtu6_get_elem(const char *xpath,
- const void *list_entry)
+static struct yang_data *
+lib_interface_state_mtu6_get_elem(struct nb_cb_get_elem_args *args)
{
- const struct interface *ifp = list_entry;
+ const struct interface *ifp = args->list_entry;
- return yang_data_new_uint32(xpath, ifp->mtu6);
+ return yang_data_new_uint32(args->xpath, ifp->mtu6);
}
/*
* XPath: /frr-interface:lib/interface/state/speed
*/
-struct yang_data *lib_interface_state_speed_get_elem(const char *xpath,
- const void *list_entry)
+static struct yang_data *
+lib_interface_state_speed_get_elem(struct nb_cb_get_elem_args *args)
{
- const struct interface *ifp = list_entry;
+ const struct interface *ifp = args->list_entry;
- return yang_data_new_uint32(xpath, ifp->speed);
+ return yang_data_new_uint32(args->xpath, ifp->speed);
}
/*
* XPath: /frr-interface:lib/interface/state/metric
*/
-struct yang_data *lib_interface_state_metric_get_elem(const char *xpath,
- const void *list_entry)
+static struct yang_data *
+lib_interface_state_metric_get_elem(struct nb_cb_get_elem_args *args)
{
- const struct interface *ifp = list_entry;
+ const struct interface *ifp = args->list_entry;
- return yang_data_new_uint32(xpath, ifp->metric);
+ return yang_data_new_uint32(args->xpath, ifp->metric);
}
/*
* XPath: /frr-interface:lib/interface/state/flags
*/
-struct yang_data *lib_interface_state_flags_get_elem(const char *xpath,
- const void *list_entry)
+static struct yang_data *
+lib_interface_state_flags_get_elem(struct nb_cb_get_elem_args *args)
{
/* TODO: implement me. */
return NULL;
@@ -1735,8 +1727,8 @@ struct yang_data *lib_interface_state_flags_get_elem(const char *xpath,
/*
* XPath: /frr-interface:lib/interface/state/type
*/
-struct yang_data *lib_interface_state_type_get_elem(const char *xpath,
- const void *list_entry)
+static struct yang_data *
+lib_interface_state_type_get_elem(struct nb_cb_get_elem_args *args)
{
/* TODO: implement me. */
return NULL;
@@ -1745,16 +1737,15 @@ struct yang_data *lib_interface_state_type_get_elem(const char *xpath,
/*
* XPath: /frr-interface:lib/interface/state/phy-address
*/
-struct yang_data *
-lib_interface_state_phy_address_get_elem(const char *xpath,
- const void *list_entry)
+static struct yang_data *
+lib_interface_state_phy_address_get_elem(struct nb_cb_get_elem_args *args)
{
- const struct interface *ifp = list_entry;
+ const struct interface *ifp = args->list_entry;
struct ethaddr macaddr;
memcpy(&macaddr.octet, ifp->hw_addr, ETH_ALEN);
- return yang_data_new_mac(xpath, &macaddr);
+ return yang_data_new_mac(args->xpath, &macaddr);
}
/* clang-format off */