]> git.proxmox.com Git - mirror_frr.git/commitdiff
bgpd: hash lookup for iprule entries
authorPhilippe Guibert <philippe.guibert@6wind.com>
Mon, 12 Mar 2018 14:11:33 +0000 (15:11 +0100)
committerPhilippe Guibert <philippe.guibert@6wind.com>
Thu, 3 May 2018 13:15:08 +0000 (15:15 +0200)
once an iprule has been created, a notification is sent back, and the
context of bgp_action is searched.

Signed-off-by: Philippe Guibert <philippe.guibert@6wind.com>
bgpd/bgp_pbr.c
bgpd/bgp_pbr.h
bgpd/bgp_zebra.c

index 0f88011566011ec82a7e45e57d726b3f28aec56c..0e6a0dbbad204cefc764ccbe178de531de59abdb 100644 (file)
@@ -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,
index b6d26469f0ee76b3db6be1a20fbf42545eb30632..d82f125ec36d99c0b8a7ab4dab6761a5f81d11f1 100644 (file)
@@ -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);
index f476686037d1d63710909fccf932983c7f89087d..852c5fdec957215744effd2690e7d9af97b45587 100644 (file)
@@ -1921,7 +1921,7 @@ static int rule_notify_owner(int command, struct zclient *zclient,
                                     &ifi, &note))
                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)",