2 net.h -- header for net.c
3 Copyright (C) 1998,99 Ivo Timmermans <zarq@iname.com>
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 #ifndef __TINC_NET_H__
21 #define __TINC_NET_H__
28 #define MAXSIZE 1700 /* should be a bit more than the MTU for the tapdevice */
31 #define MAC_ADDR_S "%02x:%02x:%02x:%02x:%02x:%02x"
32 #define MAC_ADDR_V(x) ((unsigned char*)&(x))[0],((unsigned char*)&(x))[1], \
33 ((unsigned char*)&(x))[2],((unsigned char*)&(x))[3], \
34 ((unsigned char*)&(x))[4],((unsigned char*)&(x))[5]
36 #define IP_ADDR_S "%d.%d.%d.%d"
38 #ifdef WORDS_BIGENDIAN
39 # define IP_ADDR_V(x) ((unsigned char*)&(x))[0],((unsigned char*)&(x))[1], \
40 ((unsigned char*)&(x))[2],((unsigned char*)&(x))[3]
42 # define IP_ADDR_V(x) ((unsigned char*)&(x))[3],((unsigned char*)&(x))[2], \
43 ((unsigned char*)&(x))[1],((unsigned char*)&(x))[0]
46 #define MAXBUFSIZE 2048 /* Probably way too much, but it must fit every possible request. */
48 typedef unsigned long ip_t;
49 typedef short length_t;
51 typedef struct vpn_packet_t {
52 length_t len; /* the actual number of bytes in the `data' field */
53 unsigned char data[MAXSIZE];
56 typedef struct real_packet_t {
57 length_t len; /* the length of the entire packet */
58 ip_t from; /* where the packet came from */
59 vpn_packet_t data; /* encrypted vpn_packet_t */
62 typedef struct passphrase_t {
64 unsigned char *phrase;
67 typedef struct status_bits_t {
68 int pinged:1; /* sent ping */
69 int got_pong:1; /* received pong */
70 int meta:1; /* meta connection exists */
71 int active:1; /* 1 if active.. */
72 int outgoing:1; /* I myself asked for this conn */
73 int termreq:1; /* the termination of this connection was requested */
74 int remove:1; /* Set to 1 if you want this connection removed */
75 int timeout:1; /* 1 if gotten timeout */
76 int validkey:1; /* 1 if we currently have a valid key for him */
77 int waitingforkey:1; /* 1 if we already sent out a request */
78 int dataopen:1; /* 1 if we have a valid UDP connection open */
82 typedef struct queue_element_t {
84 struct queue_element_t *prev;
85 struct queue_element_t *next;
88 typedef struct packet_queue_t {
89 queue_element_t *head;
90 queue_element_t *tail;
93 typedef struct enc_key_t {
99 typedef struct conn_list_t {
100 ip_t vpn_ip; /* his vpn ip */
101 ip_t vpn_mask; /* his vpn network address */
102 ip_t real_ip; /* his real (internet) ip */
103 char *hostname; /* the hostname of its real ip */
104 short unsigned int port; /* his portnumber */
105 int socket; /* our udp vpn socket */
106 int meta_socket; /* our tcp meta socket */
107 int protocol_version; /* used protocol */
108 status_bits_t status; /* status info */
109 passphrase_t *pp; /* encoded passphrase */
110 packet_queue_t *sq; /* pending outgoing packets */
111 packet_queue_t *rq; /* pending incoming packets (they have no
112 valid key to be decrypted with) */
113 enc_key_t *public_key; /* the other party's public key */
114 enc_key_t *key; /* encrypt with this key */
115 char buffer[MAXBUFSIZE]; /* metadata input buffer */
116 int buflen; /* bytes read into buffer */
117 int reqlen; /* length of first request in buffer */
118 struct conn_list_t *nexthop; /* nearest meta-hop in this direction */
119 struct conn_list_t *next; /* after all, it's a list of connections */
124 extern int total_tap_in;
125 extern int total_tap_out;
126 extern int total_socket_in;
127 extern int total_socket_out;
129 extern conn_list_t *conn_list;
130 extern conn_list_t *myself;
132 extern int send_packet(ip_t, vpn_packet_t *);
133 extern int send_broadcast(conn_list_t *, vpn_packet_t *);
134 extern int setup_network_connections(void);
135 extern void close_network_connections(void);
136 extern void main_loop(void);
137 extern int setup_vpn_connection(conn_list_t *);
138 extern void terminate_connection(conn_list_t *);
139 extern void flush_queues(conn_list_t*);
141 #endif /* __TINC_NET_H__ */