]> git.ipfire.org Git - thirdparty/bird.git/commitdiff
BGP: Simpler hashing in export table
authorMaria Matejka <mq@ucw.cz>
Wed, 29 May 2024 18:16:08 +0000 (20:16 +0200)
committerMaria Matejka <mq@ucw.cz>
Tue, 4 Jun 2024 08:11:36 +0000 (10:11 +0200)
We need a hashing simple enough to allow for feeding by netindex.

proto/bgp/attrs.c
proto/bgp/bgp.h
proto/bgp/packets.c

index 58c76d5934d35ba045c21c09ffbc3e223b04410b..3f8da7d298fe890a0b6486a4e2aee0cd15037eaa 100644 (file)
@@ -1690,10 +1690,10 @@ bgp_withdraw_bucket(struct bgp_channel *c, struct bgp_bucket *b)
  *     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_EQ(n1,i1,h1,n2,i2,h2) h1 == h2 && (add_path_tx ? (i1 == i2) : 1) && (n1 == n2)
-#define PXH_FN(n,i,h)          h
+#define PXH_EQ(n1,i1,n2,i2)    (add_path_tx ? (i1 == i2) : 1) && (n1 == n2)
+#define PXH_FN(n,i)            u32_hash(n)
 
 #define PXH_REHASH             bgp_pxh_rehash
 #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 *
 bgp_get_prefix(struct bgp_channel *c, struct netindex *ni, struct rte_src *src, int add_path_tx)
 {
-  u32 path_id = src->global_id;
-  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);
+  struct bgp_prefix *px = HASH_FIND(c->prefix_hash, PXH, ni->index, src);
 
   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);
-      px->path_id = path_id;
+      px->src = src;
     }
 
     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 = (struct bgp_prefix) {
-    .hash = hash,
-    .path_id = path_id,
+    .src = src,
     .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 { \
   if (c->c.debug & D_ROUTES) log(L_TRACE "%s.%s < %s %N %uG %s", \
       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();
 
   /* 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);
 
   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);
 }
index 74097cb87721faf9d66145db1a700f092638b307..0e89df2be0907a252b65e6bac8d39d3f9850ac18 100644 (file)
@@ -434,8 +434,7 @@ struct bgp_prefix {
   struct bgp_bucket *last;             /* Last bucket sent with this prefix */
   struct bgp_bucket *cur;              /* Current bucket (cur == last) if no update is required */
   btime lastmod;                       /* Last modification of this prefix */
-  u32 hash;
-  u32 path_id;
+  struct rte_src *src;                 /* Path ID encoded as rte_src */
   struct netindex *ni;
 };
 
index 31145ab9a90d1bf7afef8771d9cecd9615faf060..efffe1ce71b8e53dcb810829d79183e1f31dbb3d 100644 (file)
@@ -1605,7 +1605,7 @@ bgp_encode_nlri_ip4(struct bgp_write_state *s, struct bgp_bucket *buck, byte *bu
     /* Encode path ID */
     if (s->add_path)
     {
-      put_u32(pos, px->path_id);
+      put_u32(pos, px->src->global_id);
       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 */
     if (s->add_path)
     {
-      put_u32(pos, px->path_id);
+      put_u32(pos, px->src->global_id);
       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 */
     if (s->add_path)
     {
-      put_u32(pos, px->path_id);
+      put_u32(pos, px->src->global_id);
       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 */
     if (s->add_path)
     {
-      put_u32(pos, px->path_id);
+      put_u32(pos, px->src->global_id);
       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 */
     if (s->add_path)
     {
-      put_u32(pos, px->path_id);
+      put_u32(pos, px->src->global_id);
       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 */
     if (s->add_path)
     {
-      put_u32(pos, px->path_id);
+      put_u32(pos, px->src->global_id);
       ADVANCE(pos, size, 4);
     }