2 subnet.h -- header for subnet.c
3 Copyright (C) 2000-2012 Guus Sliepen <guus@tinc-vpn.org>,
4 2000-2005 Ivo Timmermans
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License along
17 with this program; if not, write to the Free Software Foundation, Inc.,
18 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
21 #ifndef __TINC_SUBNET_H__
22 #define __TINC_SUBNET_H__
26 typedef enum subnet_type_t {
30 SUBNET_TYPES /* Guardian */
33 typedef struct subnet_mac_t {
37 typedef struct subnet_ipv4_t {
42 typedef struct subnet_ipv6_t {
49 typedef struct subnet_t {
50 struct node_t *owner; /* the owner of this subnet */
52 subnet_type_t type; /* subnet type (IPv4? IPv6? MAC? something even weirder?) */
53 time_t expires; /* expiry time */
54 int weight; /* weight (higher value is higher priority) */
56 /* And now for the actual subnet: */
67 extern splay_tree_t *subnet_tree;
69 extern int subnet_compare(const struct subnet_t *, const struct subnet_t *);
70 extern subnet_t *new_subnet(void) __attribute__ ((__malloc__));
71 extern void free_subnet(subnet_t *);
72 extern void init_subnets(void);
73 extern void exit_subnets(void);
74 extern splay_tree_t *new_subnet_tree(void) __attribute__ ((__malloc__));
75 extern void free_subnet_tree(splay_tree_t *);
76 extern void subnet_add(struct node_t *, subnet_t *);
77 extern void subnet_del(struct node_t *, subnet_t *);
78 extern void subnet_update(struct node_t *, subnet_t *, bool);
79 extern int maskcmp(const void *, const void *, int);
80 extern void maskcpy(void *, const void *, int, int);
81 extern void mask(void *, int, int);
82 extern bool maskcheck(const void *, int, int);
83 extern bool net2str(char *, int, const subnet_t *);
84 extern bool str2net(subnet_t *, const char *);
85 extern subnet_t *lookup_subnet(const struct node_t *, const subnet_t *);
86 extern subnet_t *lookup_subnet_mac(const struct node_t *, const mac_t *);
87 extern subnet_t *lookup_subnet_ipv4(const ipv4_t *);
88 extern subnet_t *lookup_subnet_ipv6(const ipv6_t *);
89 extern bool dump_subnets(struct connection_t *);
90 extern void subnet_cache_flush(void);
92 #endif /* __TINC_SUBNET_H__ */