Update documents.
[oweals/tinc.git] / rt / subnet.h
1 /*
2     subnet.h -- subnet handling
3
4     Copyright (C) 2003-2004 Guus Sliepen <guus@tinc-vpn.org>,
5                   2003-2004 Ivo Timmermans <ivo@tinc-vpn.org>
6
7     This program is free software; you can redistribute it and/or modify
8     it under the terms of the GNU General Public License as published by
9     the Free Software Foundation; either version 2 of the License, or
10     (at your option) any later version.
11
12     This program is distributed in the hope that it will be useful,
13     but WITHOUT ANY WARRANTY; without even the implied warranty of
14     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15     GNU General Public License for more details.
16
17     You should have received a copy of the GNU General Public License
18     along with this program; if not, write to the Free Software
19     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20
21     $Id$
22 */
23
24 #ifndef __SUBNET_H__
25 #define __SUBNET_H__
26
27 #include "rt/node.h"
28 #include "support/avl.h"
29
30 typedef struct mac {
31         uint8_t x[6];
32 } mac_t;
33
34 typedef struct ipv4 {
35         uint8_t x[4];
36 } ipv4_t;
37
38 typedef struct ipv6 {
39         uint16_t x[8];
40 } ipv6_t;
41
42 typedef enum subnet_type {
43         SUBNET_TYPE_MAC,
44         SUBNET_TYPE_IPV4,
45         SUBNET_TYPE_IPV6,
46 } subnet_type_t;
47
48 typedef struct subnet_mac {
49         mac_t address;
50 } subnet_mac_t;
51
52 typedef struct subnet_ipv4 {
53         ipv4_t address;
54         int prefixlength;
55 } subnet_ipv4_t;
56
57 typedef struct subnet_ipv6 {
58         ipv6_t address;
59         int prefixlength;
60 } subnet_ipv6_t;
61
62 typedef struct subnet {
63         struct node *owner;
64         struct timeval expires;
65
66         enum subnet_type type;
67
68         union net {
69                 struct subnet_mac mac;
70                 struct subnet_ipv4 ipv4;
71                 struct subnet_ipv6 ipv6;
72         } net;
73 } subnet_t;
74
75 extern subnet_t *subnet_new(void) __attribute__ ((__malloc__));
76 extern void subnet_free(struct subnet *);
77 extern bool subnet_init(void);
78 extern bool subnet_exit(void);
79 extern avl_tree_t *subnet_tree_new(void) __attribute__ ((__malloc__));
80 extern void subnet_tree_free(avl_tree_t *);
81 extern void subnet_add(struct subnet *);
82 extern void subnet_del(struct subnet *);
83 extern char *net2str(const struct subnet *);
84 extern struct subnet *str2net(const char *);
85 extern struct subnet *subnet_get(const struct subnet *);
86 extern struct subnet *subnet_get_mac(const struct mac *);
87 extern struct subnet *subnet_get_ipv4(const struct ipv4 *);
88 extern struct subnet *subnet_get_ipv6(const struct ipv6 *);
89
90 #endif