diff options
| author | David Lamparter <equinox@opensourcerouting.org> | 2021-10-20 13:07:47 +0200 |
|---|---|---|
| committer | David Lamparter <equinox@opensourcerouting.org> | 2021-10-20 13:28:46 +0200 |
| commit | a243d1db93aaa123413a754fe69fbad36d810ae7 (patch) | |
| tree | 3d2e74c2b3f4d4862f7a7029c2ff5d18d71999ae /pathd/path_zebra.c | |
| parent | bf4af4ffb5e2ffa0b34c5bd67b5b7d4aa912747f (diff) | |
*: 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 'pathd/path_zebra.c')
| -rw-r--r-- | pathd/path_zebra.c | 14 |
1 files changed, 9 insertions, 5 deletions
diff --git a/pathd/path_zebra.c b/pathd/path_zebra.c index 53d834f360..156267a394 100644 --- a/pathd/path_zebra.c +++ b/pathd/path_zebra.c @@ -320,6 +320,12 @@ static int path_zebra_opaque_msg_handler(ZAPI_CALLBACK_ARGS) return ret; } +static zclient_handler *const path_handlers[] = { + [ZEBRA_SR_POLICY_NOTIFY_STATUS] = path_zebra_sr_policy_notify_status, + [ZEBRA_ROUTER_ID_UPDATE] = path_zebra_router_id_update, + [ZEBRA_OPAQUE_MESSAGE] = path_zebra_opaque_msg_handler, +}; + /** * Initializes Zebra asynchronous connection. * @@ -331,15 +337,13 @@ void path_zebra_init(struct thread_master *master) options.synchronous = true; /* Initialize asynchronous zclient. */ - zclient = zclient_new(master, &zclient_options_default); + zclient = zclient_new(master, &zclient_options_default, path_handlers, + array_size(path_handlers)); zclient_init(zclient, ZEBRA_ROUTE_SRTE, 0, &pathd_privs); zclient->zebra_connected = path_zebra_connected; - zclient->sr_policy_notify_status = path_zebra_sr_policy_notify_status; - zclient->router_id_update = path_zebra_router_id_update; - zclient->opaque_msg_handler = path_zebra_opaque_msg_handler; /* Initialize special zclient for synchronous message exchanges. */ - zclient_sync = zclient_new(master, &options); + zclient_sync = zclient_new(master, &options, NULL, 0); zclient_sync->sock = -1; zclient_sync->redist_default = ZEBRA_ROUTE_SRTE; zclient_sync->instance = 1; |
