Use buffer instead of line in read_config_file(), line may be assigned
[oweals/tinc.git] / src / net.h
1 /*
2     net.h -- header for net.c
3     Copyright (C) 1998,1999,2000 Ivo Timmermans <zarq@iname.com>
4
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.
9
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.
14
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.
18
19     $Id: net.h,v 1.9.4.23 2000/11/30 23:18:21 zarq Exp $
20 */
21
22 #ifndef __TINC_NET_H__
23 #define __TINC_NET_H__
24
25 #include <sys/time.h>
26
27 #include "config.h"
28
29 #define MAXSIZE 1700  /* should be a bit more than the MTU for the tapdevice */
30 #define MTU 1600
31
32 #define MAC_ADDR_S "%02x:%02x:%02x:%02x:%02x:%02x"
33 #define MAC_ADDR_V(x) ((unsigned char*)&(x))[0],((unsigned char*)&(x))[1], \
34                       ((unsigned char*)&(x))[2],((unsigned char*)&(x))[3], \
35                       ((unsigned char*)&(x))[4],((unsigned char*)&(x))[5]
36
37 #define IP_ADDR_S "%d.%d.%d.%d"
38
39 #ifdef WORDS_BIGENDIAN
40 # define IP_ADDR_V(x) ((unsigned char*)&(x))[0],((unsigned char*)&(x))[1], \
41                       ((unsigned char*)&(x))[2],((unsigned char*)&(x))[3]
42 #else
43 # define IP_ADDR_V(x) ((unsigned char*)&(x))[3],((unsigned char*)&(x))[2], \
44                       ((unsigned char*)&(x))[1],((unsigned char*)&(x))[0]
45 #endif
46
47 #define MAXBUFSIZE 4096 /* Probably way too much, but it must fit every possible request. */
48
49 /* flags */
50 #define INDIRECTDATA        0x0001 /* Used to indicate that this host has to be reached indirect */
51 #define EXPORTINDIRECTDATA  0x0002 /* Used to indicate uplink that it has to tell others to do INDIRECTDATA */
52 #define TCPONLY             0x0004 /* Tells sender to send packets over TCP instead of UDP (for firewalls) */
53
54 /* tap types */
55 #define TAP_TYPE_ETHERTAP 0
56 #define TAP_TYPE_TUNTAP   1
57
58 typedef struct mac_t
59 {
60   unsigned char x[6];
61 } mac_t;
62
63 typedef unsigned long ipv4_t;
64
65 typedef ipv4_t ip_t; /* alias for ipv4_t */
66
67 typedef struct ipv6_t
68 {
69   unsigned short x[8];
70 } ipv6_t;
71
72 typedef unsigned short port_t;
73
74 typedef short length_t;
75
76 typedef struct vpn_packet_t {
77   length_t len;         /* the actual number of bytes in the `data' field */
78   unsigned char data[MAXSIZE];
79 } vpn_packet_t;
80
81 typedef struct queue_element_t {
82   void *packet;
83   struct queue_element_t *prev;
84   struct queue_element_t *next;
85 } queue_element_t;
86
87 typedef struct packet_queue_t {
88   queue_element_t *head;
89   queue_element_t *tail;
90 } packet_queue_t;
91
92 typedef struct enc_key_t {
93   int length;
94   char *key;
95   time_t expiry;
96 } enc_key_t;
97
98 extern int tap_fd;
99
100 extern int total_tap_in;
101 extern int total_tap_out;
102 extern int total_socket_in;
103 extern int total_socket_out;
104
105 extern char *unknown;
106
107 extern char *request_name[256];
108 extern char *status_text[10];
109
110 #include "connection.h"         /* Yes, very strange placement indeed, but otherwise the typedefs get all tangled up */
111
112 extern int str2opt(const char *);
113 extern char *opt2str(int);
114 extern int send_packet(ip_t, vpn_packet_t *);
115 extern int setup_network_connections(void);
116 extern void close_network_connections(void);
117 extern void main_loop(void);
118 extern int setup_vpn_connection(connection_t *);
119 extern void terminate_connection(connection_t *);
120 extern void flush_queues(connection_t *);
121 extern void add_queue(packet_queue_t **, void *, size_t);
122
123
124 #include <config.h>
125 #ifdef HAVE_OPENSSL_RSA_H
126 # include <openssl/rsa.h>
127 #else
128 # include <rsa.h>
129 #endif
130
131 extern int read_rsa_public_key(RSA **, const char *);
132
133 #endif /* __TINC_NET_H__ */