summaryrefslogtreecommitdiff
path: root/pbrd/pbr_zebra.c
diff options
context:
space:
mode:
authorDavid Lamparter <equinox@opensourcerouting.org>2021-10-20 13:07:47 +0200
committerDavid Lamparter <equinox@opensourcerouting.org>2021-10-20 13:28:46 +0200
commita243d1db93aaa123413a754fe69fbad36d810ae7 (patch)
tree3d2e74c2b3f4d4862f7a7029c2ff5d18d71999ae /pbrd/pbr_zebra.c
parentbf4af4ffb5e2ffa0b34c5bd67b5b7d4aa912747f (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 'pbrd/pbr_zebra.c')
-rw-r--r--pbrd/pbr_zebra.c18
1 files changed, 11 insertions, 7 deletions
diff --git a/pbrd/pbr_zebra.c b/pbrd/pbr_zebra.c
index 643269e34e..4df01043a9 100644
--- a/pbrd/pbr_zebra.c
+++ b/pbrd/pbr_zebra.c
@@ -429,20 +429,24 @@ static int pbr_zebra_nexthop_update(ZAPI_CALLBACK_ARGS)
extern struct zebra_privs_t pbr_privs;
+static zclient_handler *const pbr_handlers[] = {
+ [ZEBRA_INTERFACE_ADDRESS_ADD] = interface_address_add,
+ [ZEBRA_INTERFACE_ADDRESS_DELETE] = interface_address_delete,
+ [ZEBRA_INTERFACE_VRF_UPDATE] = interface_vrf_update,
+ [ZEBRA_ROUTE_NOTIFY_OWNER] = route_notify_owner,
+ [ZEBRA_RULE_NOTIFY_OWNER] = rule_notify_owner,
+ [ZEBRA_NEXTHOP_UPDATE] = pbr_zebra_nexthop_update,
+};
+
void pbr_zebra_init(void)
{
struct zclient_options opt = { .receive_notify = true };
- zclient = zclient_new(master, &opt);
+ zclient = zclient_new(master, &opt, pbr_handlers,
+ array_size(pbr_handlers));
zclient_init(zclient, ZEBRA_ROUTE_PBR, 0, &pbr_privs);
zclient->zebra_connected = zebra_connected;
- zclient->interface_address_add = interface_address_add;
- zclient->interface_address_delete = interface_address_delete;
- zclient->interface_vrf_update = interface_vrf_update;
- zclient->route_notify_owner = route_notify_owner;
- zclient->rule_notify_owner = rule_notify_owner;
- zclient->nexthop_update = pbr_zebra_nexthop_update;
}
void pbr_send_rnh(struct nexthop *nhop, bool reg)