From 2055c776b0fd7ae331dfc99bf931bd92e3850278 Mon Sep 17 00:00:00 2001 From: Philippe Guibert Date: Mon, 12 Mar 2018 15:11:33 +0100 Subject: [PATCH] bgpd: hash lookup for iprule entries once an iprule has been created, a notification is sent back, and the context of bgp_action is searched. Signed-off-by: Philippe Guibert --- bgpd/bgp_pbr.c | 32 ++++++++++++++++++++++++++++++-- bgpd/bgp_pbr.h | 3 ++- bgpd/bgp_zebra.c | 2 +- 3 files changed, 33 insertions(+), 4 deletions(-) diff --git a/bgpd/bgp_pbr.c b/bgpd/bgp_pbr.c index 0f88011566..0e6a0dbbad 100644 --- a/bgpd/bgp_pbr.c +++ b/bgpd/bgp_pbr.c @@ -50,6 +50,25 @@ struct bgp_pbr_match_entry_unique { struct bgp_pbr_match_entry *bpme_found; }; +struct bgp_pbr_action_unique { + uint32_t unique; + struct bgp_pbr_action *bpa_found; +}; + +static int bgp_pbr_action_walkcb(struct hash_backet *backet, void *arg) +{ + struct bgp_pbr_action *bpa = (struct bgp_pbr_action *)backet->data; + struct bgp_pbr_action_unique *bpau = (struct bgp_pbr_action_unique *) + arg; + uint32_t unique = bpau->unique; + + if (bpa->unique == unique) { + bpau->bpa_found = bpa; + return HASHWALK_ABORT; + } + return HASHWALK_CONTINUE; +} + static int bgp_pbr_match_entry_walkcb(struct hash_backet *backet, void *arg) { struct bgp_pbr_match_entry *bpme = @@ -422,9 +441,18 @@ int bgp_pbr_action_hash_equal(const void *arg1, const void *arg2) return 1; } -struct bgp_pbr_action *bgp_pbr_action_rule_lookup(uint32_t unique) +struct bgp_pbr_action *bgp_pbr_action_rule_lookup(vrf_id_t vrf_id, + uint32_t unique) { - return NULL; + struct bgp *bgp = bgp_lookup_by_vrf_id(vrf_id); + struct bgp_pbr_action_unique bpau; + + if (!bgp || unique == 0) + return NULL; + bpau.unique = unique; + bpau.bpa_found = NULL; + hash_walk(bgp->pbr_action_hash, bgp_pbr_action_walkcb, &bpau); + return bpau.bpa_found; } struct bgp_pbr_match *bgp_pbr_match_ipset_lookup(vrf_id_t vrf_id, diff --git a/bgpd/bgp_pbr.h b/bgpd/bgp_pbr.h index b6d26469f0..d82f125ec3 100644 --- a/bgpd/bgp_pbr.h +++ b/bgpd/bgp_pbr.h @@ -218,7 +218,8 @@ struct bgp_pbr_action { }; -extern struct bgp_pbr_action *bgp_pbr_action_rule_lookup(uint32_t unique); +extern struct bgp_pbr_action *bgp_pbr_action_rule_lookup(vrf_id_t vrf_id, + uint32_t unique); extern struct bgp_pbr_match *bgp_pbr_match_ipset_lookup(vrf_id_t vrf_id, uint32_t unique); diff --git a/bgpd/bgp_zebra.c b/bgpd/bgp_zebra.c index f476686037..852c5fdec9 100644 --- a/bgpd/bgp_zebra.c +++ b/bgpd/bgp_zebra.c @@ -1921,7 +1921,7 @@ static int rule_notify_owner(int command, struct zclient *zclient, &ifi, ¬e)) return -1; - bgp_pbra = bgp_pbr_action_rule_lookup(unique); + bgp_pbra = bgp_pbr_action_rule_lookup(vrf_id, unique); if (!bgp_pbra) { if (BGP_DEBUG(zebra, ZEBRA)) zlog_debug("%s: Fail to look BGP rule (%u)", -- 2.39.5