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 /lib/bfd.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 'lib/bfd.c')
| -rw-r--r-- | lib/bfd.c | 15 | 
1 files changed, 10 insertions, 5 deletions
@@ -821,10 +821,13 @@ void bfd_sess_show(struct vty *vty, struct json_object *json,   *   * Use this as `zclient` `bfd_dest_replay` callback.   */ -static int zclient_bfd_session_reply(ZAPI_CALLBACK_ARGS) +int zclient_bfd_session_reply(ZAPI_CALLBACK_ARGS)  {  	struct bfd_session_params *bsp; +	if (!zclient->bfd_integration) +		return 0; +  	/* Do nothing when shutting down. */  	if (bsglobal.shutting_down)  		return 0; @@ -855,7 +858,7 @@ static int zclient_bfd_session_reply(ZAPI_CALLBACK_ARGS)  	return 0;  } -static int zclient_bfd_session_update(ZAPI_CALLBACK_ARGS) +int zclient_bfd_session_update(ZAPI_CALLBACK_ARGS)  {  	struct bfd_session_params *bsp, *bspn;  	size_t sessions_updated = 0; @@ -868,6 +871,9 @@ static int zclient_bfd_session_update(ZAPI_CALLBACK_ARGS)  	struct prefix sp;  	char ifstr[128], cbitstr[32]; +	if (!zclient->bfd_integration) +		return 0; +  	/* Do nothing when shutting down. */  	if (bsglobal.shutting_down)  		return 0; @@ -969,9 +975,8 @@ void bfd_protocol_integration_init(struct zclient *zc, struct thread_master *tm)  	bsglobal.zc = zc;  	bsglobal.tm = tm; -	/* Install our callbacks. */ -	zc->interface_bfd_dest_update = zclient_bfd_session_update; -	zc->bfd_dest_replay = zclient_bfd_session_reply; +	/* Enable BFD callbacks. */ +	zc->bfd_integration = true;  	/* Send the client registration */  	bfd_client_sendmsg(zc, ZEBRA_BFD_CLIENT_REGISTER, VRF_DEFAULT);  | 
