]> git.proxmox.com Git - mirror_frr.git/commitdiff
bgpd: get table identifier from table manager
authorPhilippe Guibert <philippe.guibert@6wind.com>
Tue, 3 Apr 2018 13:06:50 +0000 (15:06 +0200)
committerPhilippe Guibert <philippe.guibert@6wind.com>
Mon, 30 Apr 2018 09:56:23 +0000 (11:56 +0200)
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>
bgpd/bgp_pbr.c
bgpd/bgp_zebra.c
bgpd/bgp_zebra.h

index d7a4c920f462bdadacb386c95b9bb841892b53a3..4813bc0ce5e37ba3562e3bc9010516274fcf6951 100644 (file)
@@ -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;
index 6482ee8fed453f10fa1179360b4e92c900094d42..e7b6b127d0e4a05d701b8ed6246cd8d383bbbdac 100644 (file)
@@ -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);
 }
index 63ecb9fc8219ecbaa67f6b100584f56d98f1f422..7ac40fecff6c431bca9be10b48383690f2889a43 100644 (file)
@@ -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);