move to dh
[debian/ipip] / ipip.h
1 /* ipip.h    general configuration info
2  *
3  * $Id: ipip.h,v 1.8 1995/03/19 17:21:06 bdale Exp $
4  *
5  * Copyright 1991, Michael Westerhof, Sun Microsystems, Inc.
6  * This software may be freely used, distributed, or modified, providing
7  * this header is not removed.
8  *
9  * Added support for Linux - Ron Atkinson N8FOW
10  */
11
12 /* setup the log class to be used when calling syslog - probably LOG_LOCALn */
13 #define IPIP_SYSLOG LOG_LOCAL0
14
15 /* and the location of the file to log the daemon's pid to */
16 #define PIDLOG "/var/run/ipip.pid"
17
18 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
19 /* The strtoul routine converts a string to a long unsigned integer.
20  * Some system (SunOS for instance) don't have this routine; they tend
21  * to allow long unsigned implicitly.  If your system supports the strtoul
22  * routine, use it!  Otherwise, try defining "NO_STRTOUL" below...
23  * you'll get an immediate bomb-out on execution of the resultant binary
24  * if strtol("0xffffffff",NULL,0) != 0xffffffff
25  */
26
27 #ifdef sun
28 #define NO_STRTOUL
29 #endif
30
31 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
32 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
33
34 #ifdef NO_STRTOUL
35 #define strtoul(a,b,c) strtol(a,b,c)
36 #endif
37
38 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
39
40 #define DEFAULTCONFIG "/etc/ipip/config"
41 #define DEFAULTROUTE  "/etc/ipip/routes"
42
43 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
44
45 #define MAX_SIZE 2048           /* largest IP packet we will handle */
46 #define MAX_IFACES 8            /* Total number of interfaces we support */
47 #define MAX_ROUTES 1024         /* Max entries in the route table */
48
49 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
50
51 int debugd;
52 int debugt;
53 char progname[32];
54 int no_timestamp;
55 int stat_interval;
56
57 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
58
59 /* The main per-interface data structure */
60
61 struct interface {
62
63         int type;               /* The type of interface this is       */
64 #define IF_TYPE_NONE  0
65 #define IF_TYPE_IPIP  1
66 #define IF_TYPE_IPUDP 2
67 #define IF_TYPE_SLIP  3
68 #define IF_TYPE_TUN   4
69
70         int status;             /* status flags for this interface        */
71 #define IF_STAT_OPEN 1
72 #define IF_STAT_CALL_AGAIN 2    /* call even though no data on the fd!    */
73         char *id;               /* The name assigned to this interface    */
74
75         char *devname;          /* (opt) the device name (/dev/ttya)      */
76         int unit;               /* IP prot ID, udp port, baud rate, etc   */
77
78         int fd;                 /* the file descriptor to use             */
79         char *private;          /* (opt) pointer to private data struct   */
80
81         int (*ifopen)();        /* routine to call to open                */
82         int (*ifread)();        /* routine to call to read a packet       */
83         int (*ifsend)();        /* routine to call to send a packet       */
84
85         long in;                /* count of packets in                    */
86         long out;               /* count of packets out                   */
87         long out_overruns;      /* count of output overrun errors         */
88         long martians_in;       /* count of bogus packets coming in       */
89         long looped_in;         /* count of packets looped                */
90         long bogus_in;          /* count of bogus packets in              */
91 };
92
93 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
94 /* Note: the ip addresses and the port numbers are always in net order   */
95
96 struct message {
97         int length;                     /* number of characters in packet  */
98         struct interface *from_if;      /* the interface this came from    */
99         struct interface *to_if;        /* the interface this goes to      */
100         unsigned long fip;              /* ip address from (IP/UDP only)   */
101         unsigned long tip;              /* ip address to (IP/UDP only)     */
102         unsigned short fport;           /* port number from (UDP only)     */
103         unsigned short tport;           /* port number to (UDP only)       */
104         unsigned char msg[MAX_SIZE];    /* the packet itself               */
105 };
106
107 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
108
109 #ifdef LINUX
110 struct ipip_route {
111 #else
112 struct route {
113 #endif
114         unsigned long ipaddr;           /* the ip address (network order) */
115         unsigned long mask;             /* the bit-mask to apply          */
116         struct interface *destif;       /* the destination interface      */
117         unsigned long destaddr;         /* the destination ip address     */
118         unsigned short destport;        /* the destination udp port       */
119         long hits;                      /* number of times route selected */
120 };
121
122 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
123
124 #ifdef LINUX
125 struct ipip_route rts[MAX_ROUTES];
126 #else
127 struct route rts[MAX_ROUTES];
128 #endif
129 int rts_top;
130
131 struct interface ifs[MAX_IFACES];
132 int ifs_top;
133
134 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
135 /*
136  * Our version of the perror routine... just make sure we ID things first!
137  */
138 #define PERR(x) {(void)syslog(LOG_ERR,x);}
139
140 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
141 /*
142  * Some driver routing error checking macros...
143  * Note that these require that the symbol IF_NAME be defined as the
144  * name of the driver; e.g. #define IF_NAME "slip"
145  */
146
147 #define CK_MNULL(x) \
148         if((x)==NULL){ \
149                 (void)fprintf(stderr,"%sInternal error: NULL message buffer passed to %s driver\n",progname,IF_NAME);\
150                 return -1;\
151         }
152
153 #define CK_IFNULL(x) \
154         if((x)==NULL){ \
155                 (void)fprintf(stderr,"%sInternal error: NULL interface passed to %s driver\n",progname,IF_NAME);\
156                 return -1;\
157         }
158
159 #define CK_IFTYPE(x,y) \
160         if((x)->type != (y)){ \
161                 (void)fprintf(stderr,"%sInternal error: incorrect interface type passed to %s driver\n",progname,IF_NAME);\
162                 return -1;\
163         }
164
165 #define CK_IFTYPE2(x,y,z) \
166         if(((x)->type != (y)) && ((x)->type != (z))){ \
167                 (void)fprintf(stderr,"%sInternal error: incorrect interface type passed to %s driver\n",progname,IF_NAME);\
168                 return -1;\
169         }
170
171 #define CK_IFOPEN(x) \
172         if(((x)->status & IF_STAT_OPEN)==0){ \
173                 (void)fprintf(stderr,"%sInternal error: interface has not been opened (%s driver)\n",progname,IF_NAME);\
174                 return -1;\
175         }
176
177 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
178  
179 /* slip.c */
180 int slip_open();
181 int slip_send();
182 int slip_read();
183
184 /* ip.c */
185 int ip_open();
186 int ip_send();
187 int ip_read();
188
189 /* tun.c */
190 int tun_open();
191 int tun_send();
192 int tun_read();
193
194 /* route.c */
195 int read_routes();
196
197 /* config.c */
198 int read_config();
199
200 /* run.c */
201 void send_stats();
202 int run_it();