Linux kernel mirror (for testing)
git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel
os
linux
1/* SPDX-License-Identifier: GPL-2.0 */
2/*
3 * Copyright (C) 2015-2019 Jason A. Donenfeld <Jason@zx2c4.com>. All Rights Reserved.
4 */
5
6#ifndef _WG_ALLOWEDIPS_H
7#define _WG_ALLOWEDIPS_H
8
9#include <linux/mutex.h>
10#include <linux/ip.h>
11#include <linux/ipv6.h>
12
13struct wg_peer;
14
15struct 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));
20
21 /* Keep rarely used members at bottom to be beyond cache line. */
22 unsigned long parent_bit_packed;
23 union {
24 struct list_head peer_list;
25 struct rcu_head rcu;
26 };
27};
28
29struct allowedips {
30 struct allowedips_node __rcu *root4;
31 struct allowedips_node __rcu *root6;
32 u64 seq;
33} __aligned(4); /* We pack the lower 2 bits of &root, but m68k only gives 16-bit alignment. */
34
35void wg_allowedips_init(struct allowedips *table);
36void wg_allowedips_free(struct allowedips *table, struct mutex *mutex);
37int wg_allowedips_insert_v4(struct allowedips *table, const struct in_addr *ip,
38 u8 cidr, struct wg_peer *peer, struct mutex *lock);
39int wg_allowedips_insert_v6(struct allowedips *table, const struct in6_addr *ip,
40 u8 cidr, struct wg_peer *peer, struct mutex *lock);
41int wg_allowedips_remove_v4(struct allowedips *table, const struct in_addr *ip,
42 u8 cidr, struct wg_peer *peer, struct mutex *lock);
43int wg_allowedips_remove_v6(struct allowedips *table, const struct in6_addr *ip,
44 u8 cidr, struct wg_peer *peer, struct mutex *lock);
45void wg_allowedips_remove_by_peer(struct allowedips *table,
46 struct wg_peer *peer, struct mutex *lock);
47/* The ip input pointer should be __aligned(__alignof(u64))) */
48int wg_allowedips_read_node(struct allowedips_node *node, u8 ip[16], u8 *cidr);
49
50/* These return a strong reference to a peer: */
51struct wg_peer *wg_allowedips_lookup_dst(struct allowedips *table,
52 struct sk_buff *skb);
53struct wg_peer *wg_allowedips_lookup_src(struct allowedips *table,
54 struct sk_buff *skb);
55
56#ifdef DEBUG
57bool wg_allowedips_selftest(void);
58#endif
59
60int wg_allowedips_slab_init(void);
61void wg_allowedips_slab_uninit(void);
62
63#endif /* _WG_ALLOWEDIPS_H */