2 net.h -- header for net.c
3 Copyright (C) 1998,1999,2000 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.
19 $Id: net.h,v 1.9.4.3 2000/06/25 15:22:16 guus Exp $
22 #ifndef __TINC_NET_H__
23 #define __TINC_NET_H__
30 #define MAXSIZE 1700 /* should be a bit more than the MTU for the tapdevice */
33 #define MAC_ADDR_S "%02x:%02x:%02x:%02x:%02x:%02x"
34 #define MAC_ADDR_V(x) ((unsigned char*)&(x))[0],((unsigned char*)&(x))[1], \
35 ((unsigned char*)&(x))[2],((unsigned char*)&(x))[3], \
36 ((unsigned char*)&(x))[4],((unsigned char*)&(x))[5]
38 #define IP_ADDR_S "%d.%d.%d.%d"
40 #ifdef WORDS_BIGENDIAN
41 # define IP_ADDR_V(x) ((unsigned char*)&(x))[0],((unsigned char*)&(x))[1], \
42 ((unsigned char*)&(x))[2],((unsigned char*)&(x))[3]
44 # define IP_ADDR_V(x) ((unsigned char*)&(x))[3],((unsigned char*)&(x))[2], \
45 ((unsigned char*)&(x))[1],((unsigned char*)&(x))[0]
48 #define MAXBUFSIZE 2048 /* Probably way too much, but it must fit every possible request. */
51 #define INDIRECTDATA 0x0001 /* Used to indicate that this host has to be reached indirect */
52 #define EXPORTINDIRECTDATA 0x0002 /* Used to indicate uplink that it has to tell others to do INDIRECTDATA */
54 typedef unsigned long ip_t;
55 typedef short length_t;
57 typedef struct vpn_packet_t {
58 length_t len; /* the actual number of bytes in the `data' field */
59 unsigned char data[MAXSIZE];
62 typedef struct real_packet_t {
63 length_t len; /* the length of the entire packet */
64 ip_t from; /* where the packet came from */
65 vpn_packet_t data; /* encrypted vpn_packet_t */
68 typedef struct passphrase_t {
70 unsigned char *phrase;
73 typedef struct status_bits_t {
74 int pinged:1; /* sent ping */
75 int got_pong:1; /* received pong */
76 int meta:1; /* meta connection exists */
77 int active:1; /* 1 if active.. */
78 int outgoing:1; /* I myself asked for this conn */
79 int termreq:1; /* the termination of this connection was requested */
80 int remove:1; /* Set to 1 if you want this connection removed */
81 int timeout:1; /* 1 if gotten timeout */
82 int validkey:1; /* 1 if we currently have a valid key for him */
83 int waitingforkey:1; /* 1 if we already sent out a request */
84 int dataopen:1; /* 1 if we have a valid UDP connection open */
88 typedef struct queue_element_t {
90 struct queue_element_t *prev;
91 struct queue_element_t *next;
94 typedef struct packet_queue_t {
95 queue_element_t *head;
96 queue_element_t *tail;
99 typedef struct enc_key_t {
105 typedef struct conn_list_t {
106 ip_t vpn_ip; /* his vpn ip */
107 ip_t vpn_mask; /* his vpn network address */
108 ip_t real_ip; /* his real (internet) ip */
109 /* char *hostname; /* the hostname of its real ip */
110 short unsigned int port; /* his portnumber */
111 int flags; /* his flags */
112 int socket; /* our udp vpn socket */
113 int meta_socket; /* our tcp meta socket */
114 int protocol_version; /* used protocol */
115 status_bits_t status; /* status info */
116 passphrase_t *pp; /* encoded passphrase */
117 packet_queue_t *sq; /* pending outgoing packets */
118 packet_queue_t *rq; /* pending incoming packets (they have no
119 valid key to be decrypted with) */
120 enc_key_t *public_key; /* the other party's public key */
121 enc_key_t *key; /* encrypt with this key */
122 char buffer[MAXBUFSIZE+1]; /* metadata input buffer */
123 int buflen; /* bytes read into buffer */
124 int reqlen; /* length of first request in buffer */
125 time_t last_ping_time; /* last time we saw some activity from the other end */
126 int want_ping; /* 0 if there's no need to check for activity */
127 struct conn_list_t *nexthop; /* nearest meta-hop in this direction */
128 struct conn_list_t *next; /* after all, it's a list of connections */
133 extern int total_tap_in;
134 extern int total_tap_out;
135 extern int total_socket_in;
136 extern int total_socket_out;
138 extern conn_list_t *conn_list;
139 extern conn_list_t *myself;
141 extern int send_packet(ip_t, vpn_packet_t *);
142 extern int setup_network_connections(void);
143 extern void close_network_connections(void);
144 extern void main_loop(void);
145 extern int setup_vpn_connection(conn_list_t *);
146 extern void terminate_connection(conn_list_t *);
147 extern void flush_queues(conn_list_t*);
149 #endif /* __TINC_NET_H__ */