]>
Commit | Line | Data |
---|---|---|
58e16237 CF |
1 | /* |
2 | * IS-IS Rout(e)ing protocol - LSP Hash | |
3 | * | |
4 | * Copyright (C) 2017 Christian Franke | |
5 | * | |
6 | * This file is part of FreeRangeRouting (FRR) | |
7 | * | |
8 | * FRR is free software; you can redistribute it and/or modify it | |
9 | * under the terms of the GNU General Public License as published by the | |
10 | * Free Software Foundation; either version 2, or (at your option) any | |
11 | * later version. | |
12 | * | |
13 | * FRR is distributed in the hope that it will be useful, but | |
14 | * WITHOUT ANY WARRANTY; without even the implied warranty of | |
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
16 | * General Public License for more details. | |
17 | * | |
18 | * You should have received a copy of the GNU General Public License along | |
19 | * with this program; see the file COPYING; if not, write to the Free Software | |
20 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | |
21 | */ | |
22 | #include <zebra.h> | |
23 | ||
24 | #include "hash.h" | |
25 | #include "jhash.h" | |
26 | ||
27 | #include "isisd/isis_memory.h" | |
28 | #include "isisd/isis_flags.h" | |
29 | #include "dict.h" | |
30 | #include "isisd/isis_circuit.h" | |
31 | #include "isisd/isis_lsp.h" | |
32 | #include "isisd/isis_lsp_hash.h" | |
33 | ||
34 | DEFINE_MTYPE_STATIC(ISISD, LSP_HASH, "ISIS LSP Hash") | |
35 | ||
36 | struct isis_lsp_hash { | |
37 | struct hash *h; | |
38 | }; | |
39 | ||
40 | static unsigned lsp_hash_key(void *lp) | |
41 | { | |
42 | struct isis_lsp *lsp = lp; | |
43 | ||
44 | return jhash(lsp->hdr.lsp_id, ISIS_SYS_ID_LEN + 2, 0x55aa5a5a); | |
45 | } | |
46 | ||
47 | static int lsp_hash_cmp(const void *a, const void *b) | |
48 | { | |
49 | const struct isis_lsp *la = a, *lb = b; | |
50 | ||
51 | return 0 == memcmp(la->hdr.lsp_id, lb->hdr.lsp_id, ISIS_SYS_ID_LEN + 2); | |
52 | } | |
53 | ||
54 | struct isis_lsp_hash *isis_lsp_hash_new(void) | |
55 | { | |
56 | struct isis_lsp_hash *rv = XCALLOC(MTYPE_LSP_HASH, sizeof(*rv)); | |
57 | ||
58 | rv->h = hash_create(lsp_hash_key, lsp_hash_cmp, NULL); | |
59 | return rv; | |
60 | } | |
61 | ||
62 | void isis_lsp_hash_clean(struct isis_lsp_hash *ih) | |
63 | { | |
64 | hash_clean(ih->h, NULL); | |
65 | } | |
66 | ||
67 | void isis_lsp_hash_free(struct isis_lsp_hash *ih) | |
68 | { | |
69 | isis_lsp_hash_clean(ih); | |
70 | hash_free(ih->h); | |
71 | } | |
72 | ||
73 | struct isis_lsp *isis_lsp_hash_lookup(struct isis_lsp_hash *ih, | |
996c9314 | 74 | struct isis_lsp *lsp) |
58e16237 CF |
75 | { |
76 | return hash_lookup(ih->h, lsp); | |
77 | } | |
78 | ||
79 | void isis_lsp_hash_add(struct isis_lsp_hash *ih, struct isis_lsp *lsp) | |
80 | { | |
81 | struct isis_lsp *inserted; | |
82 | inserted = hash_get(ih->h, lsp, hash_alloc_intern); | |
83 | assert(inserted == lsp); | |
84 | } | |
85 | ||
86 | void isis_lsp_hash_release(struct isis_lsp_hash *ih, struct isis_lsp *lsp) | |
87 | { | |
88 | hash_release(ih->h, lsp); | |
89 | } |