version 0.9.6
[rofl0r-htun.git] / include / common.h
blob6a27dcf6ddbf3503fd37e46cccd2a9580e35fe17
1 /* -------------------------------------------------------------------------
2 * common.h - htun common defs
3 * Copyright (C) 2002 Moshe Jacobson <moshe@runslinux.net>,
4 * Ola Nordström <ola@triblock.com>
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.
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.
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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 * -------------------------------------------------------------------------
21 /* $Id: common.h,v 2.24 2003/02/22 21:14:10 ola Exp $ */
23 #ifndef __COMMON_H
24 #define __COMMON_H
26 #include <netinet/in.h>
27 #include <time.h>
28 #include "queue.h"
29 #include "log.h"
30 #include "server.h"
31 #include "iprange.h"
33 #define HTUN_MAXPACKET 65536
34 #define HTUN_DEFAULT_CFGFILE "/etc/htund.conf"
35 #define HTUN_MAXCLIENTS 10
36 #define HTUN_MAXPENDING 5
37 #define HTUN_SOCKPENDING 10
39 #ifdef _DEBUG
40 #define dprintf lprintf
41 #else
42 #define dprintf(...)
43 #endif
45 #define iplen(pkt) \
46 ( (unsigned short)( ((((pkt)[6]&0xFF)<<8) | ((pkt)[7]&0xFF)) + 4 ) )
48 #define ipdst(pkt) htonl(((pkt)[20]<<24 | (pkt)[21]<<16 | (pkt)[22]<<8 | (pkt)[23]))
49 #define ipsrc(pkt) htonl(((pkt)[16]<<24 | (pkt)[17]<<16 | (pkt)[18]<<8 | (pkt)[19]))
50 #define max(a,b) ((a)>(b)?(a):(b))
51 #define min(a,b) ((b)>(a)?(a):(b))
53 struct server_config {
54 unsigned short max_clients;
55 unsigned short max_pending;
56 unsigned short idle_disconnect;
57 unsigned short server_ports[2];
58 unsigned short min_nack_delay;
59 unsigned short packet_count_threshold;
60 unsigned long packet_max_interval;
61 unsigned short max_response_delay;
62 time_t clidata_timeout;
63 iprange_t *ipr;
64 char *redir_host;
65 unsigned short redir_port;
68 struct client_config {
69 unsigned short proxy_port;
70 unsigned short server_ports[2];
71 struct in_addr proxy_ip;
72 struct in_addr server_ip;
73 struct in_addr local_ip;
74 struct in_addr peer_ip;
75 unsigned short do_routing;
76 unsigned short max_poll_interval;
77 unsigned long min_poll_interval_msec;
78 unsigned short poll_backoff_rate;
79 int channel_2_idle_allow;
80 int connect_tries;
81 int reconnect_tries;
82 int reconnect_sleep_sec;
83 int protocol;
84 int ack_wait;
85 iprange_t *ipr;
86 /* Put the large data at the end to speed up access to smaller data */
87 char proxy_ip_str[16];
88 char server_ip_str[16];
89 char local_ip_str[16]; /* virual tun if */
90 char peer_ip_str[16]; /* server virtual tun if */
91 char if_name[16]; /* eth0, eth1 etc.. */
92 char proxy_user[41];
93 char proxy_pass[81];
94 char base64_user_pass[300];
97 typedef struct {
98 char cfgfile[PATH_MAX];
99 char tunfile[PATH_MAX];
100 char logfile[PATH_MAX];
101 int is_server;
102 int demonize;
103 int debug;
105 union {
106 struct server_config s;
107 struct client_config c;
108 } u;
109 } config_data_t;
111 /* Reads the configuration and returns a dynamically allocated struct with the
112 * data */
113 config_data_t *read_config( const char *configfile );
115 /* dumps the config struct to the screen */
116 void print_config( config_data_t *configfile );
118 /* Reads exactly one packet's worth of data from tunfd and returns it in a
119 * dynamically allocated char buffer. */
120 char *get_packet( int tunfd );
122 /* Become a daemon: fork, die, setsid, fork, die, disconnect */
123 void daemonize( void );
125 /* Check the validity of the configuration data */
126 int config_check( config_data_t *c );
128 /* Drop privileges to nobody. Optional reason for log */
129 void dropprivs(char *reason);
131 /* Get root privileges back. Optional reason for log */
132 void getprivs(char *reason);
134 /* initialize signames[] array */
135 void init_signames(void);
137 /* Variables used by other modules */
138 extern log_t *log;
139 extern config_data_t *config;
140 extern char *signames[64]; /* 64 names of signals */
142 #endif /* _COMMON_DEFS_H_ */