From: David Lamparter Date: Tue, 29 Nov 2022 11:09:45 +0000 (+0100) Subject: lib: add common NHT update decode callback X-Git-Tag: base_10.0~255^2~8 X-Git-Url: https://git.puffer.fish/?a=commitdiff_plain;h=b951e593004a8e85276dd9b8a36e72263d6d7743;p=matthieu%2Ffrr.git lib: add common NHT update decode callback All users of `ZEBRA_NEXTHOP_UPDATE` check the VRF and then call into `zapi_nexthop_update_decode` before further processing. Begin moving this into common code in lib/. Signed-off-by: David Lamparter --- diff --git a/lib/zclient.c b/lib/zclient.c index 47d6c5fbaf..d76d6dbbdd 100644 --- a/lib/zclient.c +++ b/lib/zclient.c @@ -4298,6 +4298,28 @@ stream_failure: return -1; } +static int zclient_nexthop_update(ZAPI_CALLBACK_ARGS) +{ + struct vrf *vrf = vrf_lookup_by_id(vrf_id); + struct prefix match; + struct zapi_route route; + + if (!vrf) { + zlog_warn("nexthop update for unknown VRF ID %u", vrf_id); + return 0; + } + + if (!zapi_nexthop_update_decode(zclient->ibuf, &match, &route)) { + zlog_err("failed to decode nexthop update"); + return -1; + } + + if (zclient->nexthop_update) + zclient->nexthop_update(vrf, &match, &route); + + return 0; +} + static zclient_handler *const lib_handlers[] = { /* fundamentals */ [ZEBRA_CAPABILITIES] = zclient_capability_decode, @@ -4311,6 +4333,9 @@ static zclient_handler *const lib_handlers[] = { [ZEBRA_INTERFACE_UP] = zclient_interface_up, [ZEBRA_INTERFACE_DOWN] = zclient_interface_down, + /* NHT pre-decode */ + [ZEBRA_NEXTHOP_UPDATE] = zclient_nexthop_update, + /* BFD */ [ZEBRA_BFD_DEST_REPLAY] = zclient_bfd_session_replay, [ZEBRA_INTERFACE_BFD_DEST_UPDATE] = zclient_bfd_session_update, diff --git a/lib/zclient.h b/lib/zclient.h index f18fc056fc..e541a3becc 100644 --- a/lib/zclient.h +++ b/lib/zclient.h @@ -293,6 +293,8 @@ struct zapi_cap { typedef int (zclient_handler)(ZAPI_CALLBACK_ARGS); /* clang-format on */ +struct zapi_route; + /* Structure for the zebra client. */ struct zclient { /* The thread master we schedule ourselves on */ @@ -347,6 +349,8 @@ struct zclient { /* Pointer to the callback functions. */ void (*zebra_connected)(struct zclient *); void (*zebra_capabilities)(struct zclient_capabilities *cap); + void (*nexthop_update)(struct vrf *vrf, struct prefix *match, + struct zapi_route *nhr); int (*handle_error)(enum zebra_error_types error);