summaryrefslogtreecommitdiffstats
path: root/src/fixedmap.h
diff options
context:
space:
mode:
authorMatt Dunwoodie <ncon@mail.noconroy.net>2019-09-22 23:29:40 +0200
committerMatt Dunwoodie <ncon@mail.noconroy.net>2019-09-22 23:29:40 +0200
commitb5ba2568f9800eacb9bc0bef1d53bf9b1efcacb8 (patch)
tree212ffdb10ef22925af143eaa036eaded05de626f /src/fixedmap.h
parentMove antireplay to it's own header (diff)
downloadwireguard-openbsd-b5ba2568f9800eacb9bc0bef1d53bf9b1efcacb8.tar.xz
wireguard-openbsd-b5ba2568f9800eacb9bc0bef1d53bf9b1efcacb8.zip
Move functions from header files into dedicated file
The header files were nice while experimenting, but they are not ideal. Currently we have all the custom data structures in kerk/kern_wg.c, which would ideally not be named after wireguard, But for the time being, at least they're organised.
Diffstat (limited to 'src/fixedmap.h')
-rw-r--r--src/fixedmap.h105
1 files changed, 0 insertions, 105 deletions
diff --git a/src/fixedmap.h b/src/fixedmap.h
index 076628dd412..0226fd67ffa 100644
--- a/src/fixedmap.h
+++ b/src/fixedmap.h
@@ -43,109 +43,4 @@ uint32_t fm_insert(struct fixed_map *, void *);
void *fm_lookup(struct fixed_map *, uint32_t);
void fm_remove(struct fixed_map *, uint32_t);
-#define FM_SIZE(fm) (1 << (fm)->bits)
-#define FM_ITEM(fm, k) ((fm)->map[(k) & ((fm)->bits - 1)])
-
-void
-fm_init(struct fixed_map *fm)
-{
- rw_init(&fm->lock, "fixed_map");
- fm->bits = 0;
- fm->map = NULL;
-}
-
-void
-fm_destroy(struct fixed_map *fm)
-{
- free(fm->map, M_DEVBUF, 0);
-}
-
-void
-fm_resize(struct fixed_map *fm, size_t size)
-{
- struct map_item *old_map;
- size_t old_size, i;
-
- if (size <= FM_SIZE(fm))
- return;
-
- rw_enter_write(&fm->lock);
- old_size = FM_SIZE(fm);
- old_map = fm->map;
-
- for(fm->bits = 1; size >>= 1; fm->bits++);
- fm->map = mallocarray(FM_SIZE(fm), sizeof(*fm->map), M_DEVBUF, M_WAITOK | M_ZERO);
-
- if (old_map != NULL) {
- for (i = 0; i < old_size; i++)
- FM_ITEM(fm, old_map[i].key) = old_map[i];
- free(old_map, M_DEVBUF, 0);
- }
- rw_exit_write(&fm->lock);
-}
-
-uint32_t
-fm_reserve(struct fixed_map *fm)
-{
- size_t i;
- struct map_item *item = NULL;
-
- rw_enter_write(&fm->lock);
- for (i = 0; i < FM_SIZE(fm); i++) {
- if (fm->map[i].state == FM_ITEM_EMPTY) {
- item = &fm->map[i];
- break;
- }
- }
-
- if (item == NULL)
- panic("unable to find space in fixed map");
-
- item->key = (arc4random() << fm->bits) + i;
- item->state = FM_ITEM_RESERVED;
- rw_exit_write(&fm->lock);
-
- return item->key;
-}
-
-void
-fm_set(struct fixed_map *fm, uint32_t k, void *v)
-{
- rw_enter_write(&fm->lock);
- if (FM_ITEM(fm, k).key == k ) {
- FM_ITEM(fm, k).value = v;
- FM_ITEM(fm, k).state = FM_ITEM_FILLED;
- }
- rw_exit_write(&fm->lock);
-}
-
-uint32_t
-fm_insert(struct fixed_map *fm, void *v)
-{
- uint32_t k = fm_reserve(fm);
- fm_set(fm, k, v);
- return k;
-}
-
-void *
-fm_lookup(struct fixed_map *fm, uint32_t k)
-{
- void *v;
- rw_enter_read(&fm->lock);
- v = FM_ITEM(fm, k).key == k ? FM_ITEM(fm, k).value : NULL;
- rw_exit_read(&fm->lock);
- return v;
-}
-
-void
-fm_remove(struct fixed_map *fm, uint32_t k)
-{
- rw_enter_write(&fm->lock);
- if (FM_ITEM(fm, k).key == k) {
- FM_ITEM(fm, k).value = NULL;
- FM_ITEM(fm, k).state = FM_ITEM_EMPTY;
- }
- rw_exit_write(&fm->lock);
-}
-
#endif /* __FIXEDMAP_H__ */