This diff replaces hash32 by SipHash in the hash table in ospf{,6}d/lsupdate.c.
Seems pretty straightforward...
Index: usr.sbin/ospfd/lsupdate.c
===================================================================
RCS file: /cvs/src/usr.sbin/ospfd/lsupdate.c,v
retrieving revision 1.41
diff -u -p -r1.41 lsupdate.c
--- usr.sbin/ospfd/lsupdate.c 17 Jan 2013 09:06:35 -0000 1.41
+++ usr.sbin/ospfd/lsupdate.c 9 Dec 2014 21:03:28 -0000
@@ -18,13 +18,13 @@
*/
#include <sys/types.h>
-#include <sys/hash.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <stdlib.h>
#include <string.h>
+#include <siphash.h>
#include "ospf.h"
#include "ospfd.h"
@@ -528,6 +528,8 @@ struct lsa_cache {
u_int32_t hashmask;
} lsacache;
+SIPHASH_KEY lsacache_key;
+
struct lsa_ref *lsa_cache_look(struct lsa_hdr *);
void
@@ -535,6 +537,7 @@ lsa_cache_init(u_int32_t hashsize)
{
u_int32_t hs, i;
+ arc4random_buf(&lsacache_key, sizeof(lsacache_key));
for (hs = 1; hs < hashsize; hs <<= 1)
;
lsacache.hashtbl = calloc(hs, sizeof(struct lsa_cache_head));
@@ -573,8 +576,8 @@ lsa_cache_add(void *data, u_int16_t len)
ref->len = len;
ref->refcnt = 1;
- head = &lsacache.hashtbl[hash32_buf(&ref->hdr, sizeof(ref->hdr),
- HASHINIT) & lsacache.hashmask];
+ head = &lsacache.hashtbl[SipHash24(&lsacache_key, &ref->hdr,
+ sizeof(ref->hdr)) & lsacache.hashmask];
LIST_INSERT_HEAD(head, ref, entry);
return (ref);
}
@@ -612,8 +615,8 @@ lsa_cache_look(struct lsa_hdr *lsa_hdr)
struct lsa_cache_head *head;
struct lsa_ref *ref;
- head = &lsacache.hashtbl[hash32_buf(lsa_hdr, sizeof(*lsa_hdr),
- HASHINIT) & lsacache.hashmask];
+ head = &lsacache.hashtbl[SipHash24(&lsacache_key, lsa_hdr,
+ sizeof(*lsa_hdr)) & lsacache.hashmask];
LIST_FOREACH(ref, head, entry) {
if (memcmp(&ref->hdr, lsa_hdr, sizeof(*lsa_hdr)) == 0)
Index: usr.sbin/ospf6d/lsupdate.c
===================================================================
RCS file: /cvs/src/usr.sbin/ospf6d/lsupdate.c,v
retrieving revision 1.10
diff -u -p -r1.10 lsupdate.c
--- usr.sbin/ospf6d/lsupdate.c 25 Mar 2013 14:29:35 -0000 1.10
+++ usr.sbin/ospf6d/lsupdate.c 9 Dec 2014 21:03:28 -0000
@@ -18,7 +18,6 @@
*/
#include <sys/types.h>
-#include <sys/hash.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <netinet/ip6.h>
@@ -27,6 +26,7 @@
#include <stdlib.h>
#include <string.h>
+#include <siphash.h>
#include "ospf6.h"
#include "ospf6d.h"
@@ -542,6 +542,8 @@ struct lsa_cache {
u_int32_t hashmask;
} lsacache;
+SIPHASH_KEY lsacache_key;
+
struct lsa_ref *lsa_cache_look(struct lsa_hdr *);
void
@@ -549,6 +551,7 @@ lsa_cache_init(u_int32_t hashsize)
{
u_int32_t hs, i;
+ arc4random_buf(&lsacache_key, sizeof(lsacache_key));
for (hs = 1; hs < hashsize; hs <<= 1)
;
lsacache.hashtbl = calloc(hs, sizeof(struct lsa_cache_head));
@@ -587,8 +590,8 @@ lsa_cache_add(void *data, u_int16_t len)
ref->len = len;
ref->refcnt = 1;
- head = &lsacache.hashtbl[hash32_buf(&ref->hdr, sizeof(ref->hdr),
- HASHINIT) & lsacache.hashmask];
+ head = &lsacache.hashtbl[SipHash24(&lsacache_key, &ref->hdr,
+ sizeof(ref->hdr)) & lsacache.hashmask];
LIST_INSERT_HEAD(head, ref, entry);
return (ref);
}
@@ -626,8 +629,8 @@ lsa_cache_look(struct lsa_hdr *lsa_hdr)
struct lsa_cache_head *head;
struct lsa_ref *ref;
- head = &lsacache.hashtbl[hash32_buf(lsa_hdr, sizeof(*lsa_hdr),
- HASHINIT) & lsacache.hashmask];
+ head = &lsacache.hashtbl[SipHash24(&lsacache_key, lsa_hdr,
+ sizeof(*lsa_hdr)) & lsacache.hashmask];
LIST_FOREACH(ref, head, entry) {
if (memcmp(&ref->hdr, lsa_hdr, sizeof(*lsa_hdr)) == 0)