]> git.puffer.fish Git - mirror/frr.git/commitdiff
bgpd: add a hook before bgp_process()
authorDavid Lamparter <equinox@diac24.net>
Thu, 9 May 2019 09:12:14 +0000 (11:12 +0200)
committerDavid Lamparter <equinox@diac24.net>
Wed, 3 Jul 2019 14:54:09 +0000 (16:54 +0200)
BMP uses this to get notified about any changes to prefixes, at which
point it schedules its own processing to happen later.

Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
bgpd/bgp_route.c
bgpd/bgp_route.h

index 683aa61e757686347c5f4876fa1b840446bd3f32..aa02cc3c63cae7fad3a7f7f65506d3f54efae48a 100644 (file)
@@ -107,6 +107,12 @@ static const struct message bgp_pmsi_tnltype_str[] = {
 
 #define VRFID_NONE_STR "-"
 
+DEFINE_HOOK(bgp_process,
+               (struct bgp *bgp, afi_t afi, safi_t safi,
+                       struct bgp_node *bn, struct peer *peer, bool withdraw),
+               (bgp, afi, safi, bn, peer, withdraw))
+
+
 struct bgp_node *bgp_afi_node_get(struct bgp_table *table, afi_t afi,
                                  safi_t safi, struct prefix *p,
                                  struct prefix_rd *prd)
@@ -2819,6 +2825,8 @@ void bgp_rib_remove(struct bgp_node *rn, struct bgp_path_info *pi,
        if (!CHECK_FLAG(pi->flags, BGP_PATH_HISTORY))
                bgp_path_info_delete(rn, pi); /* keep historical info */
 
+       hook_call(bgp_process, peer->bgp, afi, safi, rn, peer, true);
+
        bgp_process(peer->bgp, rn, afi, safi);
 }
 
@@ -3188,6 +3196,8 @@ int bgp_update(struct peer *peer, struct prefix *p, uint32_t addpath_id,
                pi->uptime = bgp_clock();
                same_attr = attrhash_cmp(pi->attr, attr_new);
 
+               hook_call(bgp_process, bgp, afi, safi, rn, peer, true);
+
                /* Same attribute comes in. */
                if (!CHECK_FLAG(pi->flags, BGP_PATH_REMOVED)
                    && attrhash_cmp(pi->attr, attr_new)
@@ -3616,6 +3626,8 @@ int bgp_update(struct peer *peer, struct prefix *p, uint32_t addpath_id,
        if (safi == SAFI_EVPN)
                bgp_evpn_import_route(bgp, afi, safi, p, new);
 
+       hook_call(bgp_process, bgp, afi, safi, rn, peer, false);
+
        /* Process change. */
        bgp_process(bgp, rn, afi, safi);
 
@@ -3647,6 +3659,8 @@ int bgp_update(struct peer *peer, struct prefix *p, uint32_t addpath_id,
 /* This BGP update is filtered.  Log the reason then update BGP
    entry.  */
 filtered:
+       hook_call(bgp_process, bgp, afi, safi, rn, peer, true);
+
        if (bgp_debug_update(peer, p, NULL, 1)) {
                if (!peer->rcvd_attr_printed) {
                        zlog_debug("%s rcvd UPDATE w/ attr: %s", peer->host,
index 0f2363dc6f49f9959f5372ce45a0952bf4025633..704cd39710d8069909a2de8a673e357f3234972c 100644 (file)
@@ -21,6 +21,9 @@
 #ifndef _QUAGGA_BGP_ROUTE_H
 #define _QUAGGA_BGP_ROUTE_H
 
+#include <stdbool.h>
+
+#include "hook.h"
 #include "queue.h"
 #include "nexthop.h"
 #include "bgp_table.h"
@@ -447,6 +450,12 @@ static inline bool is_pi_family_matching(struct bgp_path_info *pi,
        return false;
 }
 
+/* called before bgp_process() */
+DECLARE_HOOK(bgp_process,
+               (struct bgp *bgp, afi_t afi, safi_t safi,
+                       struct bgp_node *bn, struct peer *peer, bool withdraw),
+               (bgp, afi, safi, bn, peer, withdraw))
+
 /* Prototypes. */
 extern void bgp_rib_remove(struct bgp_node *rn, struct bgp_path_info *pi,
                           struct peer *peer, afi_t afi, safi_t safi);