Update copyright notices.
[tinc] / src / subnet.h
1 /*
2     subnet.h -- header for subnet.c
3     Copyright (C) 2000-2006 Guus Sliepen <guus@tinc-vpn.org>,
4                   2000-2005 Ivo Timmermans
5
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.
10
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.
15
16     You should have received a copy of the GNU General Public License
17     along with this program; if not, write to the Free Software
18     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19
20     $Id$
21 */
22
23 #ifndef __TINC_SUBNET_H__
24 #define __TINC_SUBNET_H__
25
26 #include "net.h"
27
28 typedef enum subnet_type_t {
29         SUBNET_MAC = 0,
30         SUBNET_IPV4,
31         SUBNET_IPV6,
32         SUBNET_TYPES                            /* Guardian */
33 } subnet_type_t;
34
35 typedef struct subnet_mac_t {
36         mac_t address;
37 } subnet_mac_t;
38
39 typedef struct subnet_ipv4_t {
40         ipv4_t address;
41         int prefixlength;
42 } subnet_ipv4_t;
43
44 typedef struct subnet_ipv6_t {
45         ipv6_t address;
46         int prefixlength;
47 } subnet_ipv6_t;
48
49 #include "node.h"
50
51 typedef struct subnet_t {
52         struct node_t *owner;           /* the owner of this subnet */
53
54         subnet_type_t type;             /* subnet type (IPv4? IPv6? MAC? something even weirder?) */
55         time_t expires;                 /* expiry time */
56
57         /* And now for the actual subnet: */
58
59         union net {
60                 subnet_mac_t mac;
61                 subnet_ipv4_t ipv4;
62                 subnet_ipv6_t ipv6;
63         } net;
64 } subnet_t;
65
66 #define MAXNETSTR 64
67
68 extern int subnet_compare(const struct subnet_t *, const struct subnet_t *);
69 extern subnet_t *new_subnet(void) __attribute__ ((__malloc__));
70 extern void free_subnet(subnet_t *);
71 extern void init_subnets(void);
72 extern void exit_subnets(void);
73 extern avl_tree_t *new_subnet_tree(void) __attribute__ ((__malloc__));
74 extern void free_subnet_tree(avl_tree_t *);
75 extern void subnet_add(struct node_t *, subnet_t *);
76 extern void subnet_del(struct node_t *, subnet_t *);
77 extern void subnet_update(struct node_t *, subnet_t *, bool);
78 extern bool net2str(char *, int, const subnet_t *);
79 extern bool str2net(subnet_t *, const char *);
80 extern subnet_t *lookup_subnet(const struct node_t *, const subnet_t *);
81 extern subnet_t *lookup_subnet_mac(const mac_t *);
82 extern subnet_t *lookup_subnet_ipv4(const ipv4_t *);
83 extern subnet_t *lookup_subnet_ipv6(const ipv6_t *);
84 extern void dump_subnets(void);
85
86 #endif                                                  /* __TINC_SUBNET_H__ */