]> git.proxmox.com Git - mirror_frr.git/commitdiff
bgpd: hash_lookup for iptables
authorPhilippe Guibert <philippe.guibert@6wind.com>
Mon, 12 Mar 2018 11:56:06 +0000 (12:56 +0100)
committerPhilippe Guibert <philippe.guibert@6wind.com>
Thu, 3 May 2018 13:15:08 +0000 (15:15 +0200)
This commit is reading the installed2 value from bgp_pbr_match hash set.
Once value matches with the one received, the walk stops and the last
bgp_pbr_match structure is stored in a static entry, so that the entry
is obtained.

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

index 07f7be10b609ff309af05e8abc74f1f93d090e41..ec4f27bd19716ad142824608b50c46b15b1eab9c 100644 (file)
@@ -40,6 +40,25 @@ static int bgp_pbr_match_entry_counter_unique;
 static int bgp_pbr_action_counter_unique;
 static int bgp_pbr_match_iptable_counter_unique;
 
+struct bgp_pbr_match_iptable_unique {
+       uint32_t unique;
+       struct bgp_pbr_match *bpm_found;
+};
+
+static int bgp_pbr_match_iptable_walkcb(struct hash_backet *backet, void *arg)
+{
+       struct bgp_pbr_match *bpm = (struct bgp_pbr_match *)backet->data;
+       struct bgp_pbr_match_iptable_unique *bpmiu =
+               (struct bgp_pbr_match_iptable_unique *)arg;
+       uint32_t unique = bpmiu->unique;
+
+       if (bpm->unique2 == unique) {
+               bpmiu->bpm_found = bpm;
+               return HASHWALK_ABORT;
+       }
+       return HASHWALK_CONTINUE;
+}
+
 static int sprintf_bgp_pbr_match_val(char *str, struct bgp_pbr_match_val *mval,
                                     const char *prepend)
 {
@@ -362,6 +381,20 @@ struct bgp_pbr_match_entry *bgp_pbr_match_ipset_entry_lookup(vrf_id_t vrf_id,
        return NULL;
 }
 
+struct bgp_pbr_match *bgp_pbr_match_iptable_lookup(vrf_id_t vrf_id,
+                                                  uint32_t unique)
+{
+       struct bgp *bgp = bgp_lookup_by_vrf_id(vrf_id);
+       struct bgp_pbr_match_iptable_unique bpmiu;
+
+       if (!bgp || unique == 0)
+               return NULL;
+       bpmiu.unique = unique;
+       bpmiu.bpm_found = NULL;
+       hash_walk(bgp->pbr_match_hash, bgp_pbr_match_iptable_walkcb, &bpmiu);
+       return bpmiu.bpm_found;
+}
+
 void bgp_pbr_init(struct bgp *bgp)
 {
        bgp->pbr_match_hash =
index 1fb1b0cccc89424b617c1a2895ef85ec1a9037e2..b6d26469f0ee76b3db6be1a20fbf42545eb30632 100644 (file)
@@ -226,6 +226,8 @@ extern struct bgp_pbr_match *bgp_pbr_match_ipset_lookup(vrf_id_t vrf_id,
 extern struct bgp_pbr_match_entry *bgp_pbr_match_ipset_entry_lookup(
                                            vrf_id_t vrf_id, char *name,
                                            uint32_t unique);
+extern struct bgp_pbr_match *bgp_pbr_match_iptable_lookup(vrf_id_t vrf_id,
+                                                         uint32_t unique);
 
 extern void bgp_pbr_init(struct bgp *bgp);