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 /pimd/pim_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 'pimd/pim_zebra.c')
| -rw-r--r-- | pimd/pim_zebra.c | 28 |
1 files changed, 17 insertions, 11 deletions
diff --git a/pimd/pim_zebra.c b/pimd/pim_zebra.c index aa041df857..1da33af006 100644 --- a/pimd/pim_zebra.c +++ b/pimd/pim_zebra.c @@ -439,23 +439,29 @@ static void pim_zebra_capabilities(struct zclient_capabilities *cap) router->mlag_role = cap->role; } +static zclient_handler *const pim_handlers[] = { + [ZEBRA_ROUTER_ID_UPDATE] = pim_router_id_update_zebra, + [ZEBRA_INTERFACE_ADDRESS_ADD] = pim_zebra_if_address_add, + [ZEBRA_INTERFACE_ADDRESS_DELETE] = pim_zebra_if_address_del, + [ZEBRA_INTERFACE_VRF_UPDATE] = pim_zebra_interface_vrf_update, + [ZEBRA_NEXTHOP_UPDATE] = pim_parse_nexthop_update, + + [ZEBRA_VXLAN_SG_ADD] = pim_zebra_vxlan_sg_proc, + [ZEBRA_VXLAN_SG_DEL] = pim_zebra_vxlan_sg_proc, + + [ZEBRA_MLAG_PROCESS_UP] = pim_zebra_mlag_process_up, + [ZEBRA_MLAG_PROCESS_DOWN] = pim_zebra_mlag_process_down, + [ZEBRA_MLAG_FORWARD_MSG] = pim_zebra_mlag_handle_msg, +}; + void pim_zebra_init(void) { /* Socket for receiving updates from Zebra daemon */ - zclient = zclient_new(router->master, &zclient_options_default); + zclient = zclient_new(router->master, &zclient_options_default, + pim_handlers, array_size(pim_handlers)); zclient->zebra_capabilities = pim_zebra_capabilities; zclient->zebra_connected = pim_zebra_connected; - zclient->router_id_update = pim_router_id_update_zebra; - zclient->interface_address_add = pim_zebra_if_address_add; - zclient->interface_address_delete = pim_zebra_if_address_del; - zclient->interface_vrf_update = pim_zebra_interface_vrf_update; - zclient->nexthop_update = pim_parse_nexthop_update; - zclient->vxlan_sg_add = pim_zebra_vxlan_sg_proc; - zclient->vxlan_sg_del = pim_zebra_vxlan_sg_proc; - zclient->mlag_process_up = pim_zebra_mlag_process_up; - zclient->mlag_process_down = pim_zebra_mlag_process_down; - zclient->mlag_handle_msg = pim_zebra_mlag_handle_msg; zclient_init(zclient, ZEBRA_ROUTE_PIM, 0, &pimd_privs); if (PIM_DEBUG_PIM_TRACE) { |
