]>
Commit | Line | Data |
---|---|---|
2fb975da TT |
1 | #include "zebra.h" |
2 | #include "hash.h" | |
3 | #include "nhrpd.h" | |
4 | ||
d8b87afe | 5 | static unsigned int nhrp_reqid_key(const void *data) |
2fb975da | 6 | { |
d8b87afe | 7 | const struct nhrp_reqid *r = data; |
2fb975da TT |
8 | return r->request_id; |
9 | } | |
10 | ||
74df8d6d | 11 | static bool nhrp_reqid_cmp(const void *data, const void *key) |
2fb975da TT |
12 | { |
13 | const struct nhrp_reqid *a = data, *b = key; | |
74df8d6d | 14 | |
2fb975da TT |
15 | return a->request_id == b->request_id; |
16 | } | |
17 | ||
996c9314 LB |
18 | uint32_t nhrp_reqid_alloc(struct nhrp_reqid_pool *p, struct nhrp_reqid *r, |
19 | void (*cb)(struct nhrp_reqid *, void *)) | |
2fb975da TT |
20 | { |
21 | if (!p->reqid_hash) { | |
996c9314 | 22 | p->reqid_hash = hash_create(nhrp_reqid_key, nhrp_reqid_cmp, |
8462c0ff | 23 | "NHRP reqid Hash"); |
2fb975da TT |
24 | p->next_request_id = 1; |
25 | } | |
26 | ||
27 | if (r->cb != cb) { | |
28 | r->request_id = p->next_request_id; | |
996c9314 LB |
29 | if (++p->next_request_id == 0) |
30 | p->next_request_id = 1; | |
2fb975da TT |
31 | r->cb = cb; |
32 | hash_get(p->reqid_hash, r, hash_alloc_intern); | |
33 | } | |
34 | return r->request_id; | |
35 | } | |
36 | ||
37 | void nhrp_reqid_free(struct nhrp_reqid_pool *p, struct nhrp_reqid *r) | |
38 | { | |
39 | if (r->cb) { | |
40 | hash_release(p->reqid_hash, r); | |
41 | r->cb = NULL; | |
42 | } | |
43 | } | |
44 | ||
45 | struct nhrp_reqid *nhrp_reqid_lookup(struct nhrp_reqid_pool *p, uint32_t reqid) | |
46 | { | |
47 | struct nhrp_reqid key; | |
996c9314 LB |
48 | if (!p->reqid_hash) |
49 | return 0; | |
2fb975da TT |
50 | key.request_id = reqid; |
51 | return hash_lookup(p->reqid_hash, &key); | |
52 | } |