1 /* SPDX-License-Identifier: GPL-2.0 */
3 * Copyright (C) 2015-2019 Jason A. Donenfeld <Jason@zx2c4.com>. All Rights Reserved.
6 #ifndef _WG_ALLOWEDIPS_H
7 #define _WG_ALLOWEDIPS_H
9 #include <linux/mutex.h>
11 #include <linux/ipv6.h>
15 struct allowedips_node
{
16 struct wg_peer __rcu
*peer
;
17 struct allowedips_node __rcu
*bit
[2];
18 u8 cidr
, bit_at_a
, bit_at_b
, bitlen
;
19 u8 bits
[16] __aligned(__alignof(u64
));
21 /* Keep rarely used members at bottom to be beyond cache line. */
22 unsigned long parent_bit_packed
;
24 struct list_head peer_list
;
30 struct allowedips_node __rcu
*root4
;
31 struct allowedips_node __rcu
*root6
;
33 } __aligned(4); /* We pack the lower 2 bits of &root, but m68k only gives 16-bit alignment. */
35 void wg_allowedips_init(struct allowedips
*table
);
36 void wg_allowedips_free(struct allowedips
*table
, struct mutex
*mutex
);
37 int wg_allowedips_insert_v4(struct allowedips
*table
, const struct in_addr
*ip
,
38 u8 cidr
, struct wg_peer
*peer
, struct mutex
*lock
);
39 int wg_allowedips_insert_v6(struct allowedips
*table
, const struct in6_addr
*ip
,
40 u8 cidr
, struct wg_peer
*peer
, struct mutex
*lock
);
41 void wg_allowedips_remove_by_peer(struct allowedips
*table
,
42 struct wg_peer
*peer
, struct mutex
*lock
);
43 /* The ip input pointer should be __aligned(__alignof(u64))) */
44 int wg_allowedips_read_node(struct allowedips_node
*node
, u8 ip
[16], u8
*cidr
);
46 /* These return a strong reference to a peer: */
47 struct wg_peer
*wg_allowedips_lookup_dst(struct allowedips
*table
,
49 struct wg_peer
*wg_allowedips_lookup_src(struct allowedips
*table
,
53 bool wg_allowedips_selftest(void);
56 int wg_allowedips_slab_init(void);
57 void wg_allowedips_slab_uninit(void);
59 #endif /* _WG_ALLOWEDIPS_H */