summaryrefslogtreecommitdiffstats
path: root/sharpd
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 /sharpd
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 'sharpd')
-rw-r--r--sharpd/sharp_zebra.c44
1 files changed, 26 insertions, 18 deletions
diff --git a/sharpd/sharp_zebra.c b/sharpd/sharp_zebra.c
index 67cff378e..8c9f0c278 100644
--- a/sharpd/sharp_zebra.c
+++ b/sharpd/sharp_zebra.c
@@ -720,6 +720,10 @@ void sharp_redistribute_vrf(struct vrf *vrf, int type)
0, vrf->vrf_id);
}
+static zclient_handler *const sharp_opaque_handlers[] = {
+ [ZEBRA_OPAQUE_MESSAGE] = sharp_opaque_handler,
+};
+
/* Add a zclient with a specified session id, for testing. */
int sharp_zclient_create(uint32_t session_id)
{
@@ -732,15 +736,14 @@ int sharp_zclient_create(uint32_t session_id)
return -1;
}
- client = zclient_new(master, &zclient_options_default);
+ client = zclient_new(master, &zclient_options_default,
+ sharp_opaque_handlers,
+ array_size(sharp_opaque_handlers));
client->sock = -1;
client->session_id = session_id;
zclient_init(client, ZEBRA_ROUTE_SHARP, 0, &sharp_privs);
- /* Register handlers for messages we expect this session to see */
- client->opaque_msg_handler = sharp_opaque_handler;
-
/* Enqueue on the list of test clients */
add_zclient(client);
@@ -928,7 +931,7 @@ int sharp_zebra_srv6_manager_release_locator_chunk(const char *locator_name)
return srv6_manager_release_locator_chunk(zclient, locator_name);
}
-static void sharp_zebra_process_srv6_locator_chunk(ZAPI_CALLBACK_ARGS)
+static int sharp_zebra_process_srv6_locator_chunk(ZAPI_CALLBACK_ARGS)
{
struct stream *s = NULL;
struct srv6_locator_chunk s6c = {};
@@ -951,17 +954,31 @@ static void sharp_zebra_process_srv6_locator_chunk(ZAPI_CALLBACK_ARGS)
for (ALL_LIST_ELEMENTS_RO(loc->chunks, chunk_node, c))
if (!prefix_cmp(c, &s6c.prefix))
- return;
+ return 0;
chunk = prefix_ipv6_new();
*chunk = s6c.prefix;
listnode_add(loc->chunks, chunk);
- return;
+ return 0;
}
zlog_err("%s: can't get locator_chunk!!", __func__);
+ return 0;
}
+static zclient_handler *const sharp_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] = sharp_nexthop_update,
+ [ZEBRA_NHG_NOTIFY_OWNER] = nhg_notify_owner,
+ [ZEBRA_REDISTRIBUTE_ROUTE_ADD] = sharp_redistribute_route,
+ [ZEBRA_REDISTRIBUTE_ROUTE_DEL] = sharp_redistribute_route,
+ [ZEBRA_OPAQUE_MESSAGE] = sharp_opaque_handler,
+ [ZEBRA_SRV6_MANAGER_GET_LOCATOR_CHUNK] =
+ sharp_zebra_process_srv6_locator_chunk,
+};
+
void sharp_zebra_init(void)
{
struct zclient_options opt = {.receive_notify = true};
@@ -969,19 +986,10 @@ void sharp_zebra_init(void)
if_zapi_callbacks(sharp_ifp_create, sharp_ifp_up,
sharp_ifp_down, sharp_ifp_destroy);
- zclient = zclient_new(master, &opt);
+ zclient = zclient_new(master, &opt, sharp_handlers,
+ array_size(sharp_handlers));
zclient_init(zclient, ZEBRA_ROUTE_SHARP, 0, &sharp_privs);
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 = sharp_nexthop_update;
- zclient->nhg_notify_owner = nhg_notify_owner;
zclient->zebra_buffer_write_ready = sharp_zclient_buffer_ready;
- zclient->redistribute_route_add = sharp_redistribute_route;
- zclient->redistribute_route_del = sharp_redistribute_route;
- zclient->opaque_msg_handler = sharp_opaque_handler;
- zclient->process_srv6_locator_chunk =
- sharp_zebra_process_srv6_locator_chunk;
}