mirror of
https://gitlab.nic.cz/labs/bird.git
synced 2024-12-22 17:51:53 +00:00
BGP: Simpler hashing in export table
We need a hashing simple enough to allow for feeding by netindex.
This commit is contained in:
parent
5ed9dcb1b6
commit
dd841dd472
@ -1690,10 +1690,10 @@ bgp_withdraw_bucket(struct bgp_channel *c, struct bgp_bucket *b)
|
|||||||
* Prefix hash table
|
* Prefix hash table
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#define PXH_KEY(px) px->ni->index, px->path_id, px->hash
|
#define PXH_KEY(px) px->ni->index, px->src
|
||||||
#define PXH_NEXT(px) px->next
|
#define PXH_NEXT(px) px->next
|
||||||
#define PXH_EQ(n1,i1,h1,n2,i2,h2) h1 == h2 && (add_path_tx ? (i1 == i2) : 1) && (n1 == n2)
|
#define PXH_EQ(n1,i1,n2,i2) (add_path_tx ? (i1 == i2) : 1) && (n1 == n2)
|
||||||
#define PXH_FN(n,i,h) h
|
#define PXH_FN(n,i) u32_hash(n)
|
||||||
|
|
||||||
#define PXH_REHASH bgp_pxh_rehash
|
#define PXH_REHASH bgp_pxh_rehash
|
||||||
#define PXH_PARAMS /16, *1, 2, 2, 12, 24
|
#define PXH_PARAMS /16, *1, 2, 2, 12, 24
|
||||||
@ -1711,19 +1711,15 @@ bgp_init_prefix_table(struct bgp_channel *c)
|
|||||||
static struct bgp_prefix *
|
static struct bgp_prefix *
|
||||||
bgp_get_prefix(struct bgp_channel *c, struct netindex *ni, struct rte_src *src, int add_path_tx)
|
bgp_get_prefix(struct bgp_channel *c, struct netindex *ni, struct rte_src *src, int add_path_tx)
|
||||||
{
|
{
|
||||||
u32 path_id = src->global_id;
|
struct bgp_prefix *px = HASH_FIND(c->prefix_hash, PXH, ni->index, src);
|
||||||
u32 path_id_hash = add_path_tx ? path_id : 0;
|
|
||||||
/* We must use a different hash function than the rtable */
|
|
||||||
u32 hash = u32_hash(u32_hash(ni->index) ^ u32_hash(path_id_hash));
|
|
||||||
struct bgp_prefix *px = HASH_FIND(c->prefix_hash, PXH, ni->index, path_id_hash, hash);
|
|
||||||
|
|
||||||
if (px)
|
if (px)
|
||||||
{
|
{
|
||||||
if (!add_path_tx && (path_id != px->path_id))
|
if (!add_path_tx && (src != px->src))
|
||||||
{
|
{
|
||||||
rt_unlock_source(rt_find_source_global(px->path_id));
|
rt_unlock_source(px->src);
|
||||||
rt_lock_source(src);
|
rt_lock_source(src);
|
||||||
px->path_id = path_id;
|
px->src = src;
|
||||||
}
|
}
|
||||||
|
|
||||||
return px;
|
return px;
|
||||||
@ -1731,8 +1727,7 @@ bgp_get_prefix(struct bgp_channel *c, struct netindex *ni, struct rte_src *src,
|
|||||||
|
|
||||||
px = sl_alloc(c->prefix_slab);
|
px = sl_alloc(c->prefix_slab);
|
||||||
*px = (struct bgp_prefix) {
|
*px = (struct bgp_prefix) {
|
||||||
.hash = hash,
|
.src = src,
|
||||||
.path_id = path_id,
|
|
||||||
.ni = ni,
|
.ni = ni,
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -1753,7 +1748,7 @@ bgp_update_prefix(struct bgp_channel *c, struct bgp_prefix *px, struct bgp_bucke
|
|||||||
#define BPX_TRACE(what) do { \
|
#define BPX_TRACE(what) do { \
|
||||||
if (c->c.debug & D_ROUTES) log(L_TRACE "%s.%s < %s %N %uG %s", \
|
if (c->c.debug & D_ROUTES) log(L_TRACE "%s.%s < %s %N %uG %s", \
|
||||||
c->c.proto->name, c->c.name, what, \
|
c->c.proto->name, c->c.name, what, \
|
||||||
px->ni->addr, px->path_id, IS_WITHDRAW_BUCKET(b) ? "withdraw" : "update"); } while (0)
|
px->ni->addr, px->src->global_id, IS_WITHDRAW_BUCKET(b) ? "withdraw" : "update"); } while (0)
|
||||||
px->lastmod = current_time();
|
px->lastmod = current_time();
|
||||||
|
|
||||||
/* Already queued for the same bucket */
|
/* Already queued for the same bucket */
|
||||||
@ -1806,7 +1801,7 @@ bgp_free_prefix(struct bgp_channel *c, struct bgp_prefix *px)
|
|||||||
HASH_REMOVE2(c->prefix_hash, PXH, c->pool, px);
|
HASH_REMOVE2(c->prefix_hash, PXH, c->pool, px);
|
||||||
|
|
||||||
net_unlock_index(c->c.table->netindex, px->ni);
|
net_unlock_index(c->c.table->netindex, px->ni);
|
||||||
rt_unlock_source(rt_find_source_global(px->path_id));
|
rt_unlock_source(px->src);
|
||||||
|
|
||||||
sl_free(px);
|
sl_free(px);
|
||||||
}
|
}
|
||||||
|
@ -434,8 +434,7 @@ struct bgp_prefix {
|
|||||||
struct bgp_bucket *last; /* Last bucket sent with this prefix */
|
struct bgp_bucket *last; /* Last bucket sent with this prefix */
|
||||||
struct bgp_bucket *cur; /* Current bucket (cur == last) if no update is required */
|
struct bgp_bucket *cur; /* Current bucket (cur == last) if no update is required */
|
||||||
btime lastmod; /* Last modification of this prefix */
|
btime lastmod; /* Last modification of this prefix */
|
||||||
u32 hash;
|
struct rte_src *src; /* Path ID encoded as rte_src */
|
||||||
u32 path_id;
|
|
||||||
struct netindex *ni;
|
struct netindex *ni;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -1605,7 +1605,7 @@ bgp_encode_nlri_ip4(struct bgp_write_state *s, struct bgp_bucket *buck, byte *bu
|
|||||||
/* Encode path ID */
|
/* Encode path ID */
|
||||||
if (s->add_path)
|
if (s->add_path)
|
||||||
{
|
{
|
||||||
put_u32(pos, px->path_id);
|
put_u32(pos, px->src->global_id);
|
||||||
ADVANCE(pos, size, 4);
|
ADVANCE(pos, size, 4);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1691,7 +1691,7 @@ bgp_encode_nlri_ip6(struct bgp_write_state *s, struct bgp_bucket *buck, byte *bu
|
|||||||
/* Encode path ID */
|
/* Encode path ID */
|
||||||
if (s->add_path)
|
if (s->add_path)
|
||||||
{
|
{
|
||||||
put_u32(pos, px->path_id);
|
put_u32(pos, px->src->global_id);
|
||||||
ADVANCE(pos, size, 4);
|
ADVANCE(pos, size, 4);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1776,7 +1776,7 @@ bgp_encode_nlri_vpn4(struct bgp_write_state *s, struct bgp_bucket *buck, byte *b
|
|||||||
/* Encode path ID */
|
/* Encode path ID */
|
||||||
if (s->add_path)
|
if (s->add_path)
|
||||||
{
|
{
|
||||||
put_u32(pos, px->path_id);
|
put_u32(pos, px->src->global_id);
|
||||||
ADVANCE(pos, size, 4);
|
ADVANCE(pos, size, 4);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1874,7 +1874,7 @@ bgp_encode_nlri_vpn6(struct bgp_write_state *s, struct bgp_bucket *buck, byte *b
|
|||||||
/* Encode path ID */
|
/* Encode path ID */
|
||||||
if (s->add_path)
|
if (s->add_path)
|
||||||
{
|
{
|
||||||
put_u32(pos, px->path_id);
|
put_u32(pos, px->src->global_id);
|
||||||
ADVANCE(pos, size, 4);
|
ADVANCE(pos, size, 4);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1973,7 +1973,7 @@ bgp_encode_nlri_flow4(struct bgp_write_state *s, struct bgp_bucket *buck, byte *
|
|||||||
/* Encode path ID */
|
/* Encode path ID */
|
||||||
if (s->add_path)
|
if (s->add_path)
|
||||||
{
|
{
|
||||||
put_u32(pos, px->path_id);
|
put_u32(pos, px->src->global_id);
|
||||||
ADVANCE(pos, size, 4);
|
ADVANCE(pos, size, 4);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2061,7 +2061,7 @@ bgp_encode_nlri_flow6(struct bgp_write_state *s, struct bgp_bucket *buck, byte *
|
|||||||
/* Encode path ID */
|
/* Encode path ID */
|
||||||
if (s->add_path)
|
if (s->add_path)
|
||||||
{
|
{
|
||||||
put_u32(pos, px->path_id);
|
put_u32(pos, px->src->global_id);
|
||||||
ADVANCE(pos, size, 4);
|
ADVANCE(pos, size, 4);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user