Lots of changes. It compiles, but doesn't do much yet.
[tinc] / tnl / tnl.h
1 /*
2     tnl.h -- tunnels
3
4     Copyright (C) 2003-2004 Guus Sliepen <guus@tinc-vpn.org>,
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 __TNL_H__
24 #define __TNL_H__
25
26 #include <gnutls/gnutls.h>
27
28 #include "fd/fd.h"
29
30 #define TNL_PROTOCOL 0
31
32 #define TNL_RECORD_PACKET 0
33 #define TNL_RECORD_META 1
34 #define TNL_RECORD_HELLO 2
35 #define TNL_RECORD_BLA 3
36
37 typedef struct tnl_record {
38         uint16_t type;
39         uint16_t len;
40         char data[];
41 } tnl_record_t;
42
43 typedef enum tnl_status {
44         TNL_STATUS_DOWN,
45         TNL_STATUS_CONNECTING,
46         TNL_STATUS_HANDSHAKE,
47         TNL_STATUS_UP,
48 } tnl_status_t;
49
50 typedef struct tnl_ep {
51         struct sockaddr_storage address;
52         char *id;
53         char *hostname;
54         struct tnl_ep_credentials *cred;
55         struct tnl_ep_cryptoparm *parm;
56 } tnl_ep_t;
57
58 typedef struct tnl {
59         struct tnl_ep local;
60         struct tnl_ep remote;
61         int type;
62         int protocol;
63         int mtu;
64         enum tnl_status status;
65         void *data;
66
67         bool (*send_packet)(struct tnl *tnl, const void *buf, int len);
68         bool (*send_meta)(struct tnl *tnl, const void *buf, int len);
69         bool (*close)(struct tnl *tnl);
70
71         bool (*recv_packet)(struct tnl *tnl, const void *buf, int len);
72         bool (*recv_meta)(struct tnl *tnl, const void *buf, int len);
73         bool (*accept)(struct tnl *tnl);
74         bool (*error)(struct tnl *tnl, int errnum);
75
76         /* private */
77         
78         struct fd fd;
79         gnutls_session session;
80         char buf[4096];
81         int bufread;
82 } tnl_t;
83
84 typedef struct tnl_listen {
85         struct tnl_ep local;
86         int type;
87         int protocol;
88
89         bool (*accept)(struct tnl *tnl);
90         bool (*close)(struct tnl_listen *listener);
91
92         struct fd fd;
93 } tnl_listen_t;
94
95 extern bool tnl_listen(struct tnl_listen *listener);
96 extern bool tnl_connect(struct tnl *tnl);
97
98 extern bool tnl_credentials_sprint(const char *buf, int len, const struct tnl_ep_credentials *cred);
99 extern bool tnl_credentials_sscan(const char *buf, struct tnl_ep_credentials *cred);
100 extern bool tnl_cryptoparm_sprint(const char *buf, int len, const struct tnl_ep_cryptoparm *parm);
101 extern bool tnl_cryptoparm_sscan(const char *buf, struct tnl_ep_cryptoparm *parm);
102 extern bool tnl_credentials_fprint(FILE *stream, const struct tnl_ep_credentials *cred);
103 extern bool tnl_credentials_fscan(FILE *stream, struct tnl_ep_credentials *cred);
104
105 #endif /* __TNL_H__ */