]> git.proxmox.com Git - mirror_frr.git/blame - nhrpd/reqid.c
bgpd: another change to keep indent.py happy
[mirror_frr.git] / nhrpd / reqid.c
CommitLineData
2fb975da
TT
1#include "zebra.h"
2#include "hash.h"
3#include "nhrpd.h"
4
5static unsigned int nhrp_reqid_key(void *data)
6{
7 struct nhrp_reqid *r = data;
8 return r->request_id;
9}
10
11static int nhrp_reqid_cmp(const void *data, const void *key)
12{
13 const struct nhrp_reqid *a = data, *b = key;
14 return a->request_id == b->request_id;
15}
16
17uint32_t nhrp_reqid_alloc(struct nhrp_reqid_pool *p, struct nhrp_reqid *r, void (*cb)(struct nhrp_reqid *, void *))
18{
19 if (!p->reqid_hash) {
8462c0ff
DS
20 p->reqid_hash = hash_create(nhrp_reqid_key,
21 nhrp_reqid_cmp,
22 "NHRP reqid Hash");
2fb975da
TT
23 p->next_request_id = 1;
24 }
25
26 if (r->cb != cb) {
27 r->request_id = p->next_request_id;
28 if (++p->next_request_id == 0) p->next_request_id = 1;
29 r->cb = cb;
30 hash_get(p->reqid_hash, r, hash_alloc_intern);
31 }
32 return r->request_id;
33}
34
35void nhrp_reqid_free(struct nhrp_reqid_pool *p, struct nhrp_reqid *r)
36{
37 if (r->cb) {
38 hash_release(p->reqid_hash, r);
39 r->cb = NULL;
40 }
41}
42
43struct nhrp_reqid *nhrp_reqid_lookup(struct nhrp_reqid_pool *p, uint32_t reqid)
44{
45 struct nhrp_reqid key;
46 if (!p->reqid_hash) return 0;
47 key.request_id = reqid;
48 return hash_lookup(p->reqid_hash, &key);
49}
50
51