]> git.proxmox.com Git - mirror_frr.git/blame - nhrpd/reqid.c
zebra: update local ns_id field
[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
996c9314
LB
17uint32_t nhrp_reqid_alloc(struct nhrp_reqid_pool *p, struct nhrp_reqid *r,
18 void (*cb)(struct nhrp_reqid *, void *))
2fb975da
TT
19{
20 if (!p->reqid_hash) {
996c9314 21 p->reqid_hash = hash_create(nhrp_reqid_key, nhrp_reqid_cmp,
8462c0ff 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;
996c9314
LB
28 if (++p->next_request_id == 0)
29 p->next_request_id = 1;
2fb975da
TT
30 r->cb = cb;
31 hash_get(p->reqid_hash, r, hash_alloc_intern);
32 }
33 return r->request_id;
34}
35
36void nhrp_reqid_free(struct nhrp_reqid_pool *p, struct nhrp_reqid *r)
37{
38 if (r->cb) {
39 hash_release(p->reqid_hash, r);
40 r->cb = NULL;
41 }
42}
43
44struct nhrp_reqid *nhrp_reqid_lookup(struct nhrp_reqid_pool *p, uint32_t reqid)
45{
46 struct nhrp_reqid key;
996c9314
LB
47 if (!p->reqid_hash)
48 return 0;
2fb975da
TT
49 key.request_id = reqid;
50 return hash_lookup(p->reqid_hash, &key);
51}