]>
git.proxmox.com Git - mirror_frr.git/blob - isisd/isis_lsp_hash.c
2 * IS-IS Rout(e)ing protocol - LSP Hash
4 * Copyright (C) 2017 Christian Franke
6 * This file is part of FreeRangeRouting (FRR)
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
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.
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
27 #include "isisd/isis_memory.h"
28 #include "isisd/isis_flags.h"
30 #include "isisd/isis_circuit.h"
31 #include "isisd/isis_lsp.h"
32 #include "isisd/isis_lsp_hash.h"
34 DEFINE_MTYPE_STATIC(ISISD
, LSP_HASH
, "ISIS LSP Hash")
36 struct isis_lsp_hash
{
40 static unsigned lsp_hash_key(void *lp
)
42 struct isis_lsp
*lsp
= lp
;
44 return jhash(lsp
->hdr
.lsp_id
, ISIS_SYS_ID_LEN
+ 2, 0x55aa5a5a);
47 static int lsp_hash_cmp(const void *a
, const void *b
)
49 const struct isis_lsp
*la
= a
, *lb
= b
;
51 return 0 == memcmp(la
->hdr
.lsp_id
, lb
->hdr
.lsp_id
, ISIS_SYS_ID_LEN
+ 2);
54 struct isis_lsp_hash
*isis_lsp_hash_new(void)
56 struct isis_lsp_hash
*rv
= XCALLOC(MTYPE_LSP_HASH
, sizeof(*rv
));
58 rv
->h
= hash_create(lsp_hash_key
, lsp_hash_cmp
, NULL
);
62 void isis_lsp_hash_clean(struct isis_lsp_hash
*ih
)
64 hash_clean(ih
->h
, NULL
);
67 void isis_lsp_hash_free(struct isis_lsp_hash
*ih
)
69 isis_lsp_hash_clean(ih
);
73 struct isis_lsp
*isis_lsp_hash_lookup(struct isis_lsp_hash
*ih
,
76 return hash_lookup(ih
->h
, lsp
);
79 void isis_lsp_hash_add(struct isis_lsp_hash
*ih
, struct isis_lsp
*lsp
)
81 struct isis_lsp
*inserted
;
82 inserted
= hash_get(ih
->h
, lsp
, hash_alloc_intern
);
83 assert(inserted
== lsp
);
86 void isis_lsp_hash_release(struct isis_lsp_hash
*ih
, struct isis_lsp
*lsp
)
88 hash_release(ih
->h
, lsp
);