0001
0002
0003
0004
0005
0006 #ifndef _WG_ALLOWEDIPS_H
0007 #define _WG_ALLOWEDIPS_H
0008
0009 #include <linux/mutex.h>
0010 #include <linux/ip.h>
0011 #include <linux/ipv6.h>
0012
0013 struct wg_peer;
0014
0015 struct allowedips_node {
0016 struct wg_peer __rcu *peer;
0017 struct allowedips_node __rcu *bit[2];
0018 u8 cidr, bit_at_a, bit_at_b, bitlen;
0019 u8 bits[16] __aligned(__alignof(u64));
0020
0021
0022 unsigned long parent_bit_packed;
0023 union {
0024 struct list_head peer_list;
0025 struct rcu_head rcu;
0026 };
0027 };
0028
0029 struct allowedips {
0030 struct allowedips_node __rcu *root4;
0031 struct allowedips_node __rcu *root6;
0032 u64 seq;
0033 } __aligned(4);
0034
0035 void wg_allowedips_init(struct allowedips *table);
0036 void wg_allowedips_free(struct allowedips *table, struct mutex *mutex);
0037 int wg_allowedips_insert_v4(struct allowedips *table, const struct in_addr *ip,
0038 u8 cidr, struct wg_peer *peer, struct mutex *lock);
0039 int wg_allowedips_insert_v6(struct allowedips *table, const struct in6_addr *ip,
0040 u8 cidr, struct wg_peer *peer, struct mutex *lock);
0041 void wg_allowedips_remove_by_peer(struct allowedips *table,
0042 struct wg_peer *peer, struct mutex *lock);
0043
0044 int wg_allowedips_read_node(struct allowedips_node *node, u8 ip[16], u8 *cidr);
0045
0046
0047 struct wg_peer *wg_allowedips_lookup_dst(struct allowedips *table,
0048 struct sk_buff *skb);
0049 struct wg_peer *wg_allowedips_lookup_src(struct allowedips *table,
0050 struct sk_buff *skb);
0051
0052 #ifdef DEBUG
0053 bool wg_allowedips_selftest(void);
0054 #endif
0055
0056 int wg_allowedips_slab_init(void);
0057 void wg_allowedips_slab_uninit(void);
0058
0059 #endif