]> git.puffer.fish Git - matthieu/frr.git/commitdiff
lib: add common NHT update decode callback
authorDavid Lamparter <equinox@opensourcerouting.org>
Tue, 29 Nov 2022 11:09:45 +0000 (12:09 +0100)
committerDavid Lamparter <equinox@opensourcerouting.org>
Mon, 20 Nov 2023 10:24:21 +0000 (11:24 +0100)
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 <equinox@opensourcerouting.org>
lib/zclient.c
lib/zclient.h

index 47d6c5fbaf8d861a8796c8d2a1643d5ee4a63cdb..d76d6dbbddd6b5c692f48f15e750b9f394df3325 100644 (file)
@@ -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,
index f18fc056fce3d22d9a5037c59f8448af0f53ddad..e541a3becc56c12f9eed116c1d7d23f5bddd5a73 100644 (file)
@@ -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);