5 subnet.h -- header for subnet.c
6 Copyright (C) 2000-2021 Guus Sliepen <guus@tinc-vpn.org>,
7 2000-2005 Ivo Timmermans
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 2 of the License, or
12 (at your option) any later version.
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License along
20 with this program; if not, write to the Free Software Foundation, Inc.,
21 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
27 typedef enum subnet_type_t {
33 typedef struct subnet_mac_t {
37 typedef struct subnet_ipv4_t {
42 typedef struct subnet_ipv6_t {
47 typedef struct subnet_t {
48 struct node_t *owner; /* the owner of this subnet */
50 subnet_type_t type; /* subnet type (IPv4? IPv6? MAC? something even weirder?) */
51 time_t expires; /* expiry time */
52 int weight; /* weight (higher value is higher priority) */
54 /* And now for the actual subnet: */
65 extern splay_tree_t subnet_tree;
67 extern int subnet_compare(const struct subnet_t *a, const struct subnet_t *b);
68 extern subnet_t *new_subnet(void) ATTR_MALLOC;
69 extern void free_subnet(subnet_t *subnet);
70 extern void init_subnets(void);
71 extern void exit_subnets(void);
72 extern void init_subnet_tree(splay_tree_t *tree);
73 extern void subnet_add(struct node_t *owner, subnet_t *subnet);
74 extern void subnet_del(struct node_t *owner, subnet_t *subnet);
75 extern void subnet_update(struct node_t *owner, subnet_t *subnet, bool up);
76 extern int maskcmp(const void *a, const void *b, size_t masklen);
77 extern void maskcpy(void *dest, const void *src, size_t masklen, size_t len);
78 extern void mask(void *mask, size_t masklen, size_t len);
79 extern bool subnetcheck(const subnet_t subnet);
80 extern bool maskcheck(const void *mask, size_t masklen, size_t len);
81 extern bool net2str(char *netstr, size_t len, const subnet_t *subnet);
82 extern bool str2net(subnet_t *subnet, const char *netstr);
83 extern subnet_t *lookup_subnet(struct node_t *owner, const subnet_t *subnet);
84 extern subnet_t *lookup_subnet_mac(const struct node_t *owner, const mac_t *address);
85 extern subnet_t *lookup_subnet_ipv4(const ipv4_t *address);
86 extern subnet_t *lookup_subnet_ipv6(const ipv6_t *address);
87 extern bool dump_subnets(struct connection_t *c);
88 extern void subnet_cache_flush_tables(void);
89 extern void subnet_cache_flush_table(subnet_type_t ipver);