summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHarald Welte <laforge@gnumonks.org>2012-09-14 22:09:42 +0200
committerHarald Welte <laforge@gnumonks.org>2012-09-14 22:09:42 +0200
commit18a74f3e38f573e07c5cb340f77563ee593f15a7 (patch)
treeff48c1f4a36351f1d2e0c5c843de578b9dc6931b
parentbfe531b54943751019d44fa4eef017d7936c3610 (diff)
dynamically allocate hash table buckets based on init() call
we probably should move to a more tree-like data structure than a hash table. But well, lookup is not the most computationally expensive part compared to the cryptographic operations.
-rw-r--r--src/auc.h2
-rw-r--r--src/auc_core.c17
-rw-r--r--src/auc_main.c4
3 files changed, 16 insertions, 7 deletions
diff --git a/src/auc.h b/src/auc.h
index ae47ac8..eba9843 100644
--- a/src/auc.h
+++ b/src/auc.h
@@ -31,7 +31,7 @@ struct auc_rec {
struct osmo_sub_auth_data auth;
};
-int auc_core_init(void *ctx);
+int auc_core_init(void *ctx, unsigned int nbuckets);
int auc_add_rec(struct auc_rec *rec);
int auc_gen_vecs(struct osmo_auth_vector *vec,
const char *imsi, int n_vecs);
diff --git a/src/auc_core.c b/src/auc_core.c
index 0fd09f8..e137061 100644
--- a/src/auc_core.c
+++ b/src/auc_core.c
@@ -21,18 +21,25 @@
#include <string.h>
#include <osmocom/core/linuxlist.h>
+#include <osmocom/core/talloc.h>
#include <osmocom/crypt/auth.h>
#include "auc.h"
-#define NBUCKETS 1024
-static struct llist_head auc_buckets[NBUCKETS];
+static struct llist_head *auc_buckets;
+static unsigned int g_nbuckets;
-int auc_core_init(void *ctx)
+int auc_core_init(void *ctx, unsigned int nbuckets)
{
int i;
- for (i = 0; i < NBUCKETS; i++)
+ auc_buckets = talloc_array(ctx, struct llist_head, nbuckets);
+ if (!auc_buckets)
+ return -ENOMEM;
+
+ g_nbuckets = nbuckets;
+
+ for (i = 0; i < nbuckets; i++)
INIT_LLIST_HEAD(&auc_buckets[i]);
return 0;
@@ -45,7 +52,7 @@ static unsigned int osmo_auc_hashfn(const char *imsi)
res = atoi(imsi + len - 6);
- return res % NBUCKETS;
+ return res % g_nbuckets;
}
int auc_add_rec(struct auc_rec *rec)
diff --git a/src/auc_main.c b/src/auc_main.c
index a0b97ac..3486661 100644
--- a/src/auc_main.c
+++ b/src/auc_main.c
@@ -24,6 +24,8 @@
#include <osmocom/core/talloc.h>
#include <osmocom/crypt/auth.h>
+#include "auc.h"
+
void *tall_ctx;
static int auc_test(void)
@@ -60,7 +62,7 @@ int main(int argc, char **argv)
tall_ctx = talloc_zero_size(NULL, 1);
- rc = auc_core_init(tall_ctx);
+ rc = auc_core_init(tall_ctx, 64*1024);
if (rc < 0)
exit(1);