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 #include +#include #include #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 #include +#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);