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 /bfdd | |
| 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 'bfdd')
| -rw-r--r-- | bfdd/ptm_adapter.c | 31 |
1 files changed, 17 insertions, 14 deletions
diff --git a/bfdd/ptm_adapter.c b/bfdd/ptm_adapter.c index 838acf450f..434d79c8f5 100644 --- a/bfdd/ptm_adapter.c +++ b/bfdd/ptm_adapter.c @@ -844,29 +844,32 @@ static int bfd_ifp_create(struct interface *ifp) return 0; } -void bfdd_zclient_init(struct zebra_privs_t *bfdd_priv) -{ - if_zapi_callbacks(bfd_ifp_create, NULL, NULL, bfd_ifp_destroy); - zclient = zclient_new(master, &zclient_options_default); - assert(zclient != NULL); - zclient_init(zclient, ZEBRA_ROUTE_BFD, 0, bfdd_priv); - +static zclient_handler *const bfd_handlers[] = { /* * We'll receive all messages through replay, however it will * contain a special field with the real command inside so we * avoid having to create too many handlers. */ - zclient->bfd_dest_replay = bfdd_replay; - - /* Send replay request on zebra connect. */ - zclient->zebra_connected = bfdd_zebra_connected; + [ZEBRA_BFD_DEST_REPLAY] = bfdd_replay, /* Learn about interface VRF. */ - zclient->interface_vrf_update = bfdd_interface_vrf_update; + [ZEBRA_INTERFACE_VRF_UPDATE] = bfdd_interface_vrf_update, /* Learn about new addresses being registered. */ - zclient->interface_address_add = bfdd_interface_address_update; - zclient->interface_address_delete = bfdd_interface_address_update; + [ZEBRA_INTERFACE_ADDRESS_ADD] = bfdd_interface_address_update, + [ZEBRA_INTERFACE_ADDRESS_DELETE] = bfdd_interface_address_update, +}; + +void bfdd_zclient_init(struct zebra_privs_t *bfdd_priv) +{ + if_zapi_callbacks(bfd_ifp_create, NULL, NULL, bfd_ifp_destroy); + zclient = zclient_new(master, &zclient_options_default, bfd_handlers, + array_size(bfd_handlers)); + assert(zclient != NULL); + zclient_init(zclient, ZEBRA_ROUTE_BFD, 0, bfdd_priv); + + /* Send replay request on zebra connect. */ + zclient->zebra_connected = bfdd_zebra_connected; } void bfdd_zclient_register(vrf_id_t vrf_id) |
