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 /ldpd | |
parent | Merge pull request #9848 from ton31337/feature/as-path_autocomplete (diff) | |
download | frr-a243d1db93aaa123413a754fe69fbad36d810ae7.tar.xz frr-a243d1db93aaa123413a754fe69fbad36d810ae7.zip |
*: 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 'ldpd')
-rw-r--r-- | ldpd/lde.c | 2 | ||||
-rw-r--r-- | ldpd/ldp_zebra.c | 20 |
2 files changed, 13 insertions, 9 deletions
diff --git a/ldpd/lde.c b/ldpd/lde.c index babadc461..095631036 100644 --- a/ldpd/lde.c +++ b/ldpd/lde.c @@ -2192,7 +2192,7 @@ static void zclient_sync_init(void) options.synchronous = true; /* 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_LDP; zclient_sync->session_id = 1; /* Distinguish from main session */ diff --git a/ldpd/ldp_zebra.c b/ldpd/ldp_zebra.c index 2d90412d1..059115915 100644 --- a/ldpd/ldp_zebra.c +++ b/ldpd/ldp_zebra.c @@ -694,6 +694,16 @@ ldp_zebra_filter_update(struct access_list *access) extern struct zebra_privs_t ldpd_privs; +static zclient_handler *const ldp_handlers[] = { + [ZEBRA_ROUTER_ID_UPDATE] = ldp_router_id_update, + [ZEBRA_INTERFACE_ADDRESS_ADD] = ldp_interface_address_add, + [ZEBRA_INTERFACE_ADDRESS_DELETE] = ldp_interface_address_delete, + [ZEBRA_REDISTRIBUTE_ROUTE_ADD] = ldp_zebra_read_route, + [ZEBRA_REDISTRIBUTE_ROUTE_DEL] = ldp_zebra_read_route, + [ZEBRA_PW_STATUS_UPDATE] = ldp_zebra_read_pw_status_update, + [ZEBRA_OPAQUE_MESSAGE] = ldp_zebra_opaque_msg_handler, +}; + void ldp_zebra_init(struct thread_master *master) { @@ -701,18 +711,12 @@ ldp_zebra_init(struct thread_master *master) ldp_ifp_down, ldp_ifp_destroy); /* Set default values. */ - zclient = zclient_new(master, &zclient_options_default); + zclient = zclient_new(master, &zclient_options_default, ldp_handlers, + array_size(ldp_handlers)); zclient_init(zclient, ZEBRA_ROUTE_LDP, 0, &ldpd_privs); /* set callbacks */ zclient->zebra_connected = ldp_zebra_connected; - zclient->router_id_update = ldp_router_id_update; - zclient->interface_address_add = ldp_interface_address_add; - zclient->interface_address_delete = ldp_interface_address_delete; - zclient->redistribute_route_add = ldp_zebra_read_route; - zclient->redistribute_route_del = ldp_zebra_read_route; - zclient->pw_status_update = ldp_zebra_read_pw_status_update; - zclient->opaque_msg_handler = ldp_zebra_opaque_msg_handler; /* Access list initialize. */ access_list_add_hook(ldp_zebra_filter_update); |