diff options
author | Timo Teräs <timo.teras@iki.fi> | 2015-12-25 10:32:11 +0200 |
---|---|---|
committer | Timo Teräs <timo.teras@iki.fi> | 2016-03-30 16:59:22 +0300 |
commit | 068e64859913c6844bbe6703815a633175650547 (patch) | |
tree | 3efc0440477560ac6211f9da3bea3f812bb05270 /nhrpd/reqid.c | |
parent | 76aaa0456a3804a0a1d2948d9a391383b62cbe37 (diff) | |
download | quagga-nhrp.tar.bz2 quagga-nhrp.tar.xz |
initial implementation of nhrpnhrp
this is nhrp changes from commit c321432aef01e13116980983f0a50ba486505804
rebased on quagga master and updated for vrf changes
Diffstat (limited to 'nhrpd/reqid.c')
-rw-r--r-- | nhrpd/reqid.c | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/nhrpd/reqid.c b/nhrpd/reqid.c new file mode 100644 index 00000000..24b31993 --- /dev/null +++ b/nhrpd/reqid.c @@ -0,0 +1,49 @@ +#include "zebra.h" +#include "hash.h" +#include "nhrpd.h" + +static unsigned int nhrp_reqid_key(void *data) +{ + struct nhrp_reqid *r = data; + return r->request_id; +} + +static int nhrp_reqid_cmp(const void *data, const void *key) +{ + const struct nhrp_reqid *a = data, *b = key; + return a->request_id == b->request_id; +} + +uint32_t nhrp_reqid_alloc(struct nhrp_reqid_pool *p, struct nhrp_reqid *r, void (*cb)(struct nhrp_reqid *, void *)) +{ + if (!p->reqid_hash) { + p->reqid_hash = hash_create(nhrp_reqid_key, nhrp_reqid_cmp); + p->next_request_id = 1; + } + + if (r->cb != cb) { + r->request_id = p->next_request_id; + if (++p->next_request_id == 0) p->next_request_id = 1; + r->cb = cb; + hash_get(p->reqid_hash, r, hash_alloc_intern); + } + return r->request_id; +} + +void nhrp_reqid_free(struct nhrp_reqid_pool *p, struct nhrp_reqid *r) +{ + if (r->cb) { + hash_release(p->reqid_hash, r); + r->cb = NULL; + } +} + +struct nhrp_reqid *nhrp_reqid_lookup(struct nhrp_reqid_pool *p, uint32_t reqid) +{ + struct nhrp_reqid key; + if (!p->reqid_hash) return 0; + key.request_id = reqid; + return hash_lookup(p->reqid_hash, &key); +} + + |