diff options
author | Philippe Guibert <philippe.guibert@6wind.com> | 2018-04-03 15:06:50 +0200 |
---|---|---|
committer | Philippe Guibert <philippe.guibert@6wind.com> | 2018-04-30 11:56:23 +0200 |
commit | 31c28cd7083149a7888e4882d3cda4a0b62a0d4d (patch) | |
tree | 4fdb295d925f123c8d1c3654bfacdb3dc8fa0bc0 /bgpd | |
parent | bgpd: handle FS redirect IP rule in PBR (diff) | |
download | frr-31c28cd7083149a7888e4882d3cda4a0b62a0d4d.tar.xz frr-31c28cd7083149a7888e4882d3cda4a0b62a0d4d.zip |
bgpd: get table identifier from table manager
A table chunk of 100000 is allocated from zebra, and when needed in
flowspec, the table identifier is extracted from that chunk.
Signed-off-by: Philippe Guibert <philippe.guibert@6wind.com>
Diffstat (limited to 'bgpd')
-rw-r--r-- | bgpd/bgp_pbr.c | 7 | ||||
-rw-r--r-- | bgpd/bgp_zebra.c | 21 | ||||
-rw-r--r-- | bgpd/bgp_zebra.h | 1 |
3 files changed, 24 insertions, 5 deletions
diff --git a/bgpd/bgp_pbr.c b/bgpd/bgp_pbr.c index d7a4c920f..4813bc0ce 100644 --- a/bgpd/bgp_pbr.c +++ b/bgpd/bgp_pbr.c @@ -805,16 +805,13 @@ static void bgp_pbr_policyroute_add_to_zebra(struct bgp *bgp, bgp_pbr_action_alloc_intern); if (bpa->fwmark == 0) { - /* TODO: allocate new table ID using zebra */ - static int fwmark_id; - /* drop is handled by iptable */ if (nh && nh->type == NEXTHOP_TYPE_BLACKHOLE) { bpa->table_id = 0; bpa->installed = true; } else { - bpa->fwmark = ++fwmark_id; - bpa->table_id = fwmark_id; + bpa->fwmark = bgp_zebra_tm_get_id(); + bpa->table_id = bpa->fwmark; bpa->installed = false; } bpa->unique = ++bgp_pbr_action_counter_unique; diff --git a/bgpd/bgp_zebra.c b/bgpd/bgp_zebra.c index 6482ee8fe..e7b6b127d 100644 --- a/bgpd/bgp_zebra.c +++ b/bgpd/bgp_zebra.c @@ -998,6 +998,9 @@ static int bgp_table_map_apply(struct route_map *map, struct prefix *p, static struct thread *bgp_tm_thread_connect; static bool bgp_tm_status_connected; +static bool bgp_tm_chunk_obtained; +#define BGP_FLOWSPEC_TABLE_CHUNK 100000 +static uint32_t bgp_tm_min, bgp_tm_max, bgp_tm_chunk_size; static int bgp_zebra_tm_connect(struct thread *t) { @@ -1018,12 +1021,27 @@ static int bgp_zebra_tm_connect(struct thread *t) if (!bgp_tm_status_connected) zlog_debug("Connecting to table manager. Success"); bgp_tm_status_connected = true; + if (!bgp_tm_chunk_obtained) { + if (bgp_zebra_get_table_range(bgp_tm_chunk_size, + &bgp_tm_min, + &bgp_tm_max) >= 0) + bgp_tm_chunk_obtained = true; + } } thread_add_timer(bm->master, bgp_zebra_tm_connect, zclient, delay, &bgp_tm_thread_connect); return 0; } +uint32_t bgp_zebra_tm_get_id(void) +{ + static int table_id; + + if (!bgp_tm_chunk_obtained) + return ++table_id; + return bgp_tm_min++; +} + void bgp_zebra_init_tm_connect(void) { int delay = 1; @@ -1033,6 +1051,9 @@ void bgp_zebra_init_tm_connect(void) if (bgp_tm_thread_connect != NULL) return; bgp_tm_status_connected = false; + bgp_tm_chunk_obtained = false; + bgp_tm_min = bgp_tm_max = 0; + bgp_tm_chunk_size = BGP_FLOWSPEC_TABLE_CHUNK; thread_add_timer(bm->master, bgp_zebra_tm_connect, zclient, delay, &bgp_tm_thread_connect); } diff --git a/bgpd/bgp_zebra.h b/bgpd/bgp_zebra.h index 63ecb9fc8..7ac40fecf 100644 --- a/bgpd/bgp_zebra.h +++ b/bgpd/bgp_zebra.h @@ -25,6 +25,7 @@ extern void bgp_zebra_init(struct thread_master *master); extern void bgp_zebra_init_tm_connect(void); +extern uint32_t bgp_zebra_tm_get_id(void); extern void bgp_zebra_destroy(void); extern int bgp_zebra_get_table_range(uint32_t chunk_size, uint32_t *start, uint32_t *end); |