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 /vrrpd | |
| 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 'vrrpd')
| -rw-r--r-- | vrrpd/vrrp_zebra.c | 12 | 
1 files changed, 8 insertions, 4 deletions
diff --git a/vrrpd/vrrp_zebra.c b/vrrpd/vrrp_zebra.c index 385d443571..d7d37f1f33 100644 --- a/vrrpd/vrrp_zebra.c +++ b/vrrpd/vrrp_zebra.c @@ -188,18 +188,22 @@ void vrrp_zclient_send_interface_protodown(struct interface *ifp, bool down)  	zclient_send_interface_protodown(zclient, ifp->vrf_id, ifp, down);  } +static zclient_handler *const vrrp_handlers[] = { +	[ZEBRA_ROUTER_ID_UPDATE] = vrrp_router_id_update_zebra, +	[ZEBRA_INTERFACE_ADDRESS_ADD] = vrrp_zebra_if_address_add, +	[ZEBRA_INTERFACE_ADDRESS_DELETE] = vrrp_zebra_if_address_del, +}; +  void vrrp_zebra_init(void)  {  	if_zapi_callbacks(vrrp_ifp_create, vrrp_ifp_up,  			  vrrp_ifp_down, vrrp_ifp_destroy);  	/* Socket for receiving updates from Zebra daemon */ -	zclient = zclient_new(master, &zclient_options_default); +	zclient = zclient_new(master, &zclient_options_default, vrrp_handlers, +			      array_size(vrrp_handlers));  	zclient->zebra_connected = vrrp_zebra_connected; -	zclient->router_id_update = vrrp_router_id_update_zebra; -	zclient->interface_address_add = vrrp_zebra_if_address_add; -	zclient->interface_address_delete = vrrp_zebra_if_address_del;  	zclient_init(zclient, ZEBRA_ROUTE_VRRP, 0, &vrrp_privs);  | 
