Ensure all parameters have names in header files.
[oweals/tinc.git] / src / subnet.h
1 #ifndef TINC_SUBNET_H
2 #define TINC_SUBNET_H
3
4 /*
5     subnet.h -- header for subnet.c
6     Copyright (C) 2000-2012 Guus Sliepen <guus@tinc-vpn.org>,
7                   2000-2005 Ivo Timmermans
8
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.
13
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.
18
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.
22 */
23
24 #include "net.h"
25 #include "node.h"
26
27 typedef enum subnet_type_t {
28         SUBNET_MAC = 0,
29         SUBNET_IPV4,
30         SUBNET_IPV6,
31         SUBNET_TYPES            /* Guardian */
32 } subnet_type_t;
33
34 typedef struct subnet_mac_t {
35         mac_t address;
36 } subnet_mac_t;
37
38 typedef struct subnet_ipv4_t {
39         ipv4_t address;
40         int prefixlength;
41 } subnet_ipv4_t;
42
43 typedef struct subnet_ipv6_t {
44         ipv6_t address;
45         int prefixlength;
46 } subnet_ipv6_t;
47
48 typedef struct subnet_t {
49         struct node_t *owner;   /* the owner of this subnet */
50
51         subnet_type_t type;     /* subnet type (IPv4? IPv6? MAC? something even weirder?) */
52         time_t expires;         /* expiry time */
53         int weight;             /* weight (higher value is higher priority) */
54
55         /* And now for the actual subnet: */
56
57         union net {
58                 subnet_mac_t mac;
59                 subnet_ipv4_t ipv4;
60                 subnet_ipv6_t ipv6;
61         } net;
62 } subnet_t;
63
64 #define MAXNETSTR 64
65
66 extern splay_tree_t *subnet_tree;
67
68 extern int subnet_compare(const struct subnet_t *a, const struct subnet_t *b);
69 extern subnet_t *new_subnet(void) __attribute__((__malloc__));
70 extern void free_subnet(subnet_t *subnet);
71 extern void init_subnets(void);
72 extern void exit_subnets(void);
73 extern splay_tree_t *new_subnet_tree(void) __attribute__((__malloc__));
74 extern void free_subnet_tree(splay_tree_t *);
75 extern void subnet_add(struct node_t *owner, subnet_t *subnet);
76 extern void subnet_del(struct node_t *owner, subnet_t *subnet);
77 extern void subnet_update(struct node_t *owner, subnet_t *subnet, bool up);
78 extern int maskcmp(const void *a, const void *b, int masklen);
79 extern void maskcpy(void *dest, const void *src, int masklen, int len);
80 extern void mask(void *mask, int masklen, int len);
81 extern bool maskcheck(const void *mask, int masklen, int len);
82 extern bool net2str(char *netstr, int len, const subnet_t *subnet);
83 extern bool str2net(subnet_t *subnet, const char *netstr);
84 extern subnet_t *lookup_subnet(const struct node_t *owner, const subnet_t *subnet);
85 extern subnet_t *lookup_subnet_mac(const struct node_t *owner, const mac_t *address);
86 extern subnet_t *lookup_subnet_ipv4(const ipv4_t *address);
87 extern subnet_t *lookup_subnet_ipv6(const ipv6_t *address);
88 extern bool dump_subnets(struct connection_t *c);
89 extern void subnet_cache_flush(void);
90
91 #endif