diff options
author | 2005-12-30 14:07:40 +0000 | |
---|---|---|
committer | 2005-12-30 14:07:40 +0000 | |
commit | aa1531671393315ecb19d9d65b51fc3345101a73 (patch) | |
tree | 7b6e4b5e805176c2d9e6243646ae4922c4c882b5 | |
parent | Merge rde_attr_error() into rde_attr_parse() it is no longer necessary to (diff) | |
download | wireguard-openbsd-aa1531671393315ecb19d9d65b51fc3345101a73.tar.xz wireguard-openbsd-aa1531671393315ecb19d9d65b51fc3345101a73.zip |
Use sys/hash.h instead of own built functions that work similar.
While there reorder some structs to help with alignment.
-rw-r--r-- | usr.sbin/bgpd/rde.h | 3 | ||||
-rw-r--r-- | usr.sbin/bgpd/rde_attr.c | 37 | ||||
-rw-r--r-- | usr.sbin/bgpd/rde_rib.c | 13 | ||||
-rw-r--r-- | usr.sbin/bgpd/rde_update.c | 25 |
4 files changed, 26 insertions, 52 deletions
diff --git a/usr.sbin/bgpd/rde.h b/usr.sbin/bgpd/rde.h index bc1c4ed13c8..ed277d6b672 100644 --- a/usr.sbin/bgpd/rde.h +++ b/usr.sbin/bgpd/rde.h @@ -1,4 +1,4 @@ -/* $OpenBSD: rde.h,v 1.74 2005/11/29 21:11:07 claudio Exp $ */ +/* $OpenBSD: rde.h,v 1.75 2005/12/30 14:07:40 claudio Exp $ */ /* * Copyright (c) 2003, 2004 Claudio Jeker <claudio@openbsd.org> and @@ -275,7 +275,6 @@ u_int16_t aspath_count(const void *, u_int16_t); u_int16_t aspath_neighbor(struct aspath *); int aspath_loopfree(struct aspath *, u_int16_t); int aspath_compare(struct aspath *, struct aspath *); -u_int32_t aspath_hash(const void *, u_int16_t); struct aspath *aspath_prepend(struct aspath *, u_int16_t, int); int aspath_snprint(char *, size_t, void *, u_int16_t); int aspath_asprint(char **, void *, u_int16_t); diff --git a/usr.sbin/bgpd/rde_attr.c b/usr.sbin/bgpd/rde_attr.c index 7b83952e0ce..72305403c7a 100644 --- a/usr.sbin/bgpd/rde_attr.c +++ b/usr.sbin/bgpd/rde_attr.c @@ -1,4 +1,4 @@ -/* $OpenBSD: rde_attr.c,v 1.50 2005/12/19 20:10:55 claudio Exp $ */ +/* $OpenBSD: rde_attr.c,v 1.51 2005/12/30 14:07:40 claudio Exp $ */ /* * Copyright (c) 2004 Claudio Jeker <claudio@openbsd.org> @@ -17,6 +17,7 @@ */ #include <sys/types.h> +#include <sys/hash.h> #include <sys/queue.h> #include <netinet/in.h> @@ -150,7 +151,6 @@ attr_optfree(struct rde_aspath *asp) /* aspath specific functions */ -u_int32_t aspath_hash(const void *, u_int16_t); u_int16_t aspath_extract(const void *, int); struct aspath *aspath_lookup(const void *, u_int16_t); @@ -242,7 +242,8 @@ aspath_get(void *data, u_int16_t len) memcpy(aspath->data, data, len); /* link */ - head = ASPATH_HASH(aspath_hash(aspath->data, aspath->len)); + head = ASPATH_HASH(hash32_buf(aspath->data, aspath->len, + HASHINIT)); LIST_INSERT_HEAD(head, aspath, entry); } aspath->refcnt++; @@ -359,34 +360,6 @@ aspath_compare(struct aspath *a1, struct aspath *a2) return (0); } -#define AS_HASH_INITIAL 8271 - -u_int32_t -aspath_hash(const void *data, u_int16_t len) -{ - const u_int8_t *seg; - u_int32_t hash; - u_int16_t seg_size; - u_int8_t i, seg_len, seg_type; - - hash = AS_HASH_INITIAL; - seg = data; - for (; len > 0; len -= seg_size, seg += seg_size) { - seg_type = seg[0]; - seg_len = seg[1]; - seg_size = 2 + 2 * seg_len; - - for (i = 0; i < seg_len; i++) { - hash += (hash << 5); - hash ^= aspath_extract(seg, i); - } - - if (seg_size > len) - fatalx("aspath_hash: bula bula"); - } - return (hash); -} - /* * Extract the asnum out of the as segment at the specified position. * Direct access is not possible because of non-aligned reads. @@ -412,7 +385,7 @@ aspath_lookup(const void *data, u_int16_t len) struct aspath *aspath; u_int32_t hash; - hash = aspath_hash(data, len); + hash = hash32_buf(data, len, HASHINIT); head = ASPATH_HASH(hash); LIST_FOREACH(aspath, head, entry) { diff --git a/usr.sbin/bgpd/rde_rib.c b/usr.sbin/bgpd/rde_rib.c index aed9953fbef..bb51d1514fc 100644 --- a/usr.sbin/bgpd/rde_rib.c +++ b/usr.sbin/bgpd/rde_rib.c @@ -1,4 +1,4 @@ -/* $OpenBSD: rde_rib.c,v 1.70 2005/11/29 21:11:07 claudio Exp $ */ +/* $OpenBSD: rde_rib.c,v 1.71 2005/12/30 14:07:40 claudio Exp $ */ /* * Copyright (c) 2003, 2004 Claudio Jeker <claudio@openbsd.org> @@ -18,6 +18,7 @@ #include <sys/types.h> #include <sys/queue.h> +#include <sys/hash.h> #include <stdlib.h> #include <string.h> @@ -42,7 +43,7 @@ struct path_table pathtable; /* XXX the hash should also include communities and the other attrs */ #define PATH_HASH(x) \ - &pathtable.path_hashtbl[aspath_hash((x)->data, (x)->len) & \ + &pathtable.path_hashtbl[hash32_buf((x)->data, (x)->len, HASHINIT) & \ pathtable.path_hashmask] void @@ -908,7 +909,7 @@ nexthop_lookup(struct bgpd_addr *nexthop) struct nexthop_head * nexthop_hash(struct bgpd_addr *nexthop) { - u_int32_t i, h = 0; + u_int32_t h = 0; switch (nexthop->af) { case AF_INET: @@ -917,10 +918,8 @@ nexthop_hash(struct bgpd_addr *nexthop) nexthoptable.nexthop_hashmask; break; case AF_INET6: - h = 8271; - for (i = 0; i < sizeof(struct in6_addr); i++) - h = ((h << 5) + h) ^ nexthop->v6.s6_addr[i]; - h &= nexthoptable.nexthop_hashmask; + h = hash32_buf(nexthop->v6.s6_addr, sizeof(struct in6_addr), + HASHINIT) & nexthoptable.nexthop_hashmask; break; default: fatalx("nexthop_hash: unsupported AF"); diff --git a/usr.sbin/bgpd/rde_update.c b/usr.sbin/bgpd/rde_update.c index cacaac8e582..04fef3b5df9 100644 --- a/usr.sbin/bgpd/rde_update.c +++ b/usr.sbin/bgpd/rde_update.c @@ -1,4 +1,4 @@ -/* $OpenBSD: rde_update.c,v 1.45 2005/11/29 21:11:07 claudio Exp $ */ +/* $OpenBSD: rde_update.c,v 1.46 2005/12/30 14:07:40 claudio Exp $ */ /* * Copyright (c) 2004 Claudio Jeker <claudio@openbsd.org> @@ -17,6 +17,7 @@ */ #include <sys/types.h> #include <sys/queue.h> +#include <sys/hash.h> #include <stdlib.h> #include <string.h> @@ -33,22 +34,22 @@ int up_set_prefix(u_char *, int, struct bgpd_addr *, u_int8_t); /* update stuff. */ struct update_prefix { - struct bgpd_addr prefix; - int prefixlen; - struct uplist_prefix *prefix_h; TAILQ_ENTRY(update_prefix) prefix_l; RB_ENTRY(update_prefix) entry; + struct uplist_prefix *prefix_h; + struct bgpd_addr prefix; + int prefixlen; }; struct update_attr { - u_int32_t attr_hash; + TAILQ_ENTRY(update_attr) attr_l; + RB_ENTRY(update_attr) entry; + struct uplist_prefix prefix_h; u_char *attr; + u_char *mpattr; + u_int32_t attr_hash; u_int16_t attr_len; u_int16_t mpattr_len; - u_char *mpattr; - struct uplist_prefix prefix_h; - TAILQ_ENTRY(update_attr) attr_l; - RB_ENTRY(update_attr) entry; }; void up_clear(struct uplist_attr *, struct uplist_prefix *); @@ -377,8 +378,10 @@ up_generate(struct rde_peer *peer, struct rde_aspath *asp, * use aspath_hash as attr_hash, this may be unoptimal * but currently I don't care. */ - ua->attr_hash = aspath_hash(asp->aspath->data, - asp->aspath->len); + ua->attr_hash = hash32_buf(ua->attr, ua->attr_len, HASHINIT); + if (ua->mpattr) + ua->attr_hash = hash32_buf(ua->mpattr, ua->mpattr_len, + ua->attr_hash); } up = calloc(1, sizeof(struct update_prefix)); |