From 1815c6fc9d80960233b7f72b7dc104826de12582 Mon Sep 17 00:00:00 2001 From: Philippe Guibert Date: Mon, 12 Mar 2018 12:56:06 +0100 Subject: [PATCH] bgpd: hash_lookup for iptables 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 --- bgpd/bgp_pbr.c | 33 +++++++++++++++++++++++++++++++++ bgpd/bgp_pbr.h | 2 ++ 2 files changed, 35 insertions(+) diff --git a/bgpd/bgp_pbr.c b/bgpd/bgp_pbr.c index 07f7be10b6..ec4f27bd19 100644 --- a/bgpd/bgp_pbr.c +++ b/bgpd/bgp_pbr.c @@ -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 = diff --git a/bgpd/bgp_pbr.h b/bgpd/bgp_pbr.h index 1fb1b0cccc..b6d26469f0 100644 --- a/bgpd/bgp_pbr.h +++ b/bgpd/bgp_pbr.h @@ -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); -- 2.39.5