-/* $OpenBSD: rde_rib.c,v 1.140 2014/12/12 18:15:51 tedu Exp $ */
+/* $OpenBSD: rde_rib.c,v 1.141 2014/12/18 19:28:44 tedu Exp $ */
/*
* Copyright (c) 2003, 2004 Claudio Jeker <claudio@openbsd.org>
#include <sys/types.h>
#include <sys/queue.h>
-#include <sys/hash.h>
#include <stdlib.h>
#include <string.h>
u_int32_t nexthop_hashmask;
} nexthoptable;
+SIPHASH_KEY nexthoptablekey;
+
void
nexthop_init(u_int32_t hashsize)
{
for (i = 0; i < hs; i++)
LIST_INIT(&nexthoptable.nexthop_hashtbl[i]);
+ arc4random_buf(&nexthoptablekey, sizeof(nexthoptablekey));
nexthoptable.nexthop_hashmask = hs - 1;
}
switch (nexthop->aid) {
case AID_INET:
- h = (AF_INET ^ ntohl(nexthop->v4.s_addr) ^
- ntohl(nexthop->v4.s_addr) >> 13) &
- nexthoptable.nexthop_hashmask;
+ h = SipHash24(&nexthoptablekey, &nexthop->v4.s_addr,
+ sizeof(nexthop->v4.s_addr));
break;
case AID_INET6:
- h = hash32_buf(&nexthop->v6, sizeof(struct in6_addr),
- HASHINIT) & nexthoptable.nexthop_hashmask;
+ h = SipHash24(&nexthoptablekey, &nexthop->v6,
+ sizeof(struct in6_addr));
break;
default:
fatalx("nexthop_hash: unsupported AF");
}
- return (&nexthoptable.nexthop_hashtbl[h]);
+ return (&nexthoptable.nexthop_hashtbl[h & nexthoptable.nexthop_hashmask]);
}
-/* $OpenBSD: rde_update.c,v 1.81 2013/08/14 20:34:27 claudio Exp $ */
+/* $OpenBSD: rde_update.c,v 1.82 2014/12/18 19:28:44 tedu Exp $ */
/*
* Copyright (c) 2004 Claudio Jeker <claudio@openbsd.org>
*/
#include <sys/types.h>
#include <sys/queue.h>
-#include <sys/hash.h>
#include <limits.h>
#include <stdlib.h>
#include <string.h>
+#include <siphash.h>
#include "bgpd.h"
#include "rde.h"
RB_PROTOTYPE(uptree_attr, update_attr, entry, up_attr_cmp)
RB_GENERATE(uptree_attr, update_attr, entry, up_attr_cmp)
+SIPHASH_KEY uptree_key;
+
void
up_init(struct rde_peer *peer)
{
peer->up_acnt = 0;
peer->up_nlricnt = 0;
peer->up_wcnt = 0;
+ arc4random_buf(&uptree_key, sizeof(uptree_key));
}
void
{
struct update_attr *ua = NULL;
struct update_prefix *up;
+ SIPHASH_CTX ctx;
if (asp) {
ua = calloc(1, sizeof(struct update_attr));
* use aspath_hash as attr_hash, this may be unoptimal
* but currently I don't care.
*/
- ua->attr_hash = hash32_buf(ua->attr, ua->attr_len, HASHINIT);
+ SipHash24_Init(&ctx, &uptree_key);
+ SipHash24_Update(&ctx, ua->attr, ua->attr_len);
if (ua->mpattr)
- ua->attr_hash = hash32_buf(ua->mpattr, ua->mpattr_len,
- ua->attr_hash);
+ SipHash24_Update(&ctx, ua->mpattr, ua->mpattr_len);
+ ua->attr_hash = SipHash24_End(&ctx);
}
up = calloc(1, sizeof(struct update_prefix));