summaryrefslogtreecommitdiffstats
path: root/staticd
diff options
context:
space:
mode:
authorDavid Lamparter <equinox@opensourcerouting.org>2021-10-20 13:07:47 +0200
committerDavid Lamparter <equinox@opensourcerouting.org>2021-10-20 13:28:46 +0200
commita243d1db93aaa123413a754fe69fbad36d810ae7 (patch)
tree3d2e74c2b3f4d4862f7a7029c2ff5d18d71999ae /staticd
parentMerge pull request #9848 from ton31337/feature/as-path_autocomplete (diff)
downloadfrr-a243d1db93aaa123413a754fe69fbad36d810ae7.tar.xz
frr-a243d1db93aaa123413a754fe69fbad36d810ae7.zip
*: convert zclient callbacks to table
This removes a giant `switch { }` block from lib/zclient.c and harmonizes all zclient callback function types to be the same (some had a subset of the args, some had a void return, now they all have ZAPI_CALLBACK_ARGS and int return.) Apart from getting rid of the giant switch, this is a minor security benefit since the function pointers are now in a `const` array, so they can't be overwritten by e.g. heap overflows for code execution anymore. Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
Diffstat (limited to 'staticd')
-rw-r--r--staticd/static_zebra.c14
1 files changed, 9 insertions, 5 deletions
diff --git a/staticd/static_zebra.c b/staticd/static_zebra.c
index a01ecad81..538fae28a 100644
--- a/staticd/static_zebra.c
+++ b/staticd/static_zebra.c
@@ -508,6 +508,13 @@ extern void static_zebra_route_add(struct static_path *pn, bool install)
zclient, &api);
}
+static zclient_handler *const static_handlers[] = {
+ [ZEBRA_INTERFACE_ADDRESS_ADD] = interface_address_add,
+ [ZEBRA_INTERFACE_ADDRESS_DELETE] = interface_address_delete,
+ [ZEBRA_ROUTE_NOTIFY_OWNER] = route_notify_owner,
+ [ZEBRA_NEXTHOP_UPDATE] = static_zebra_nexthop_update,
+};
+
void static_zebra_init(void)
{
struct zclient_options opt = { .receive_notify = true };
@@ -515,15 +522,12 @@ void static_zebra_init(void)
if_zapi_callbacks(static_ifp_create, static_ifp_up,
static_ifp_down, static_ifp_destroy);
- zclient = zclient_new(master, &opt);
+ zclient = zclient_new(master, &opt, static_handlers,
+ array_size(static_handlers));
zclient_init(zclient, ZEBRA_ROUTE_STATIC, 0, &static_privs);
zclient->zebra_capabilities = static_zebra_capabilities;
zclient->zebra_connected = zebra_connected;
- zclient->interface_address_add = interface_address_add;
- zclient->interface_address_delete = interface_address_delete;
- zclient->route_notify_owner = route_notify_owner;
- zclient->nexthop_update = static_zebra_nexthop_update;
static_nht_hash = hash_create(static_nht_hash_key,
static_nht_hash_cmp,