Move all source code to src/.
[tinc] / src / 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 #include <gnutls/extra.h>
28
29 #include "fd/fd.h"
30
31 #define TNL_PROTOCOL 0
32
33 #define TNL_RECORD_PACKET 0
34 #define TNL_RECORD_META 1
35 #define TNL_RECORD_HELLO 2
36 #define TNL_RECORD_BLA 3
37
38 typedef struct tnl_record {
39         uint16_t type;
40         uint16_t len;
41         char data[];
42 } tnl_record_t;
43
44 typedef enum tnl_status {
45         TNL_STATUS_DOWN,
46         TNL_STATUS_CONNECTING,
47         TNL_STATUS_HANDSHAKE,
48         TNL_STATUS_UP,
49 } tnl_status_t;
50
51 typedef struct tnl_ep_credentials {
52         gnutls_credentials_type type;
53         union {
54                 gnutls_anon_client_credentials anon_client;
55                 gnutls_anon_server_credentials anon_server;
56                 gnutls_srp_client_credentials srp_client;
57                 gnutls_srp_server_credentials srp_server;
58                 gnutls_certificate_credentials certificate;
59         };
60 } tnl_ep_credentials_t;         
61
62 typedef struct tnl_ep_cryptoparm {
63 } tnl_ep_cryptoparm_t;
64
65 typedef struct tnl_ep {
66         struct sockaddr_storage address;
67         char *id;
68         char *hostname;
69         struct tnl_ep_credentials cred;
70         struct tnl_ep_cryptoparm parm;
71 } tnl_ep_t;
72
73 typedef struct tnl {
74         struct tnl_ep local;
75         struct tnl_ep remote;
76         int type;
77         int protocol;
78         int mtu;
79         enum tnl_status status;
80         void *data;
81
82         bool (*send_packet)(struct tnl *tnl, const void *buf, int len);
83         bool (*send_meta)(struct tnl *tnl, const void *buf, int len);
84         bool (*close)(struct tnl *tnl);
85
86         bool (*recv_packet)(struct tnl *tnl, const void *buf, int len);
87         bool (*recv_meta)(struct tnl *tnl, const void *buf, int len);
88         bool (*accept)(struct tnl *tnl);
89         bool (*error)(struct tnl *tnl, int errnum);
90
91         /* private */
92         
93         gnutls_session session;
94         struct fd fd;
95         char buf[4096];
96         int bufread;
97 } tnl_t;
98
99 typedef struct tnl_listen {
100         struct tnl_ep local;
101         int type;
102         int protocol;
103
104         bool (*accept)(struct tnl *tnl);
105         bool (*close)(struct tnl_listen *listener);
106
107         struct fd fd;
108 } tnl_listen_t;
109
110 extern bool tnl_listen(struct tnl_listen *listener);
111 extern bool tnl_connect(struct tnl *tnl);
112
113 extern bool tnl_ep_set_x509_credentials(tnl_ep_t *tnl_ep, const char *key, const char *certificate, const char *trust, const char *crl);
114 extern bool tnl_ep_set_openpgp_credentials(tnl_ep_t *tnl_ep, const char *privkey, const char *pubkey, const char *keyring, const char *trustdb);
115
116 #endif /* __TNL_H__ */