]> git.proxmox.com Git - qemu.git/blame - slirp/slirp.h
slirp: Factor out internal state structure
[qemu.git] / slirp / slirp.h
CommitLineData
f0cbd3ec
FB
1#ifndef __COMMON_H__
2#define __COMMON_H__
3
5fa0ab8f 4#include "config-host.h"
f0cbd3ec
FB
5#include "slirp_config.h"
6
379ff53d
FB
7#ifdef _WIN32
8# include <inttypes.h>
9
10typedef uint8_t u_int8_t;
11typedef uint16_t u_int16_t;
12typedef uint32_t u_int32_t;
13typedef uint64_t u_int64_t;
14typedef char *caddr_t;
15
34444131 16# include <windows.h>
379ff53d 17# include <winsock2.h>
116842ee 18# include <ws2tcpip.h>
379ff53d
FB
19# include <sys/timeb.h>
20# include <iphlpapi.h>
21
22# define EWOULDBLOCK WSAEWOULDBLOCK
23# define EINPROGRESS WSAEINPROGRESS
24# define ENOTCONN WSAENOTCONN
25# define EHOSTUNREACH WSAEHOSTUNREACH
26# define ENETUNREACH WSAENETUNREACH
27# define ECONNREFUSED WSAECONNREFUSED
28#else
29# define ioctlsocket ioctl
30# define closesocket(s) close(s)
6d46bf8a 31# define O_BINARY 0
379ff53d
FB
32#endif
33
f0cbd3ec
FB
34#include <sys/types.h>
35#ifdef HAVE_SYS_BITYPES_H
36# include <sys/bitypes.h>
37#endif
38
170c6f87
FB
39#include <sys/time.h>
40
f0cbd3ec
FB
41#ifdef NEED_TYPEDEFS
42typedef char int8_t;
43typedef unsigned char u_int8_t;
44
45# if SIZEOF_SHORT == 2
46 typedef short int16_t;
47 typedef unsigned short u_int16_t;
48# else
49# if SIZEOF_INT == 2
50 typedef int int16_t;
51 typedef unsigned int u_int16_t;
52# else
53 #error Cannot find a type with sizeof() == 2
54# endif
55# endif
56
57# if SIZEOF_SHORT == 4
58 typedef short int32_t;
59 typedef unsigned short u_int32_t;
60# else
61# if SIZEOF_INT == 4
62 typedef int int32_t;
63 typedef unsigned int u_int32_t;
64# else
65 #error Cannot find a type with sizeof() == 4
66# endif
67# endif
68#endif /* NEED_TYPEDEFS */
69
70#ifdef HAVE_UNISTD_H
71# include <unistd.h>
72#endif
73
74#ifdef HAVE_STDLIB_H
75# include <stdlib.h>
76#endif
77
78#include <stdio.h>
79#include <errno.h>
80
81#ifndef HAVE_MEMMOVE
82#define memmove(x, y, z) bcopy(y, x, z)
83#endif
84
85#if TIME_WITH_SYS_TIME
86# include <sys/time.h>
87# include <time.h>
88#else
eb38c52c 89# ifdef HAVE_SYS_TIME_H
f0cbd3ec
FB
90# include <sys/time.h>
91# else
92# include <time.h>
93# endif
94#endif
95
96#ifdef HAVE_STRING_H
97# include <string.h>
98#else
99# include <strings.h>
100#endif
101
379ff53d 102#ifndef _WIN32
f0cbd3ec 103#include <sys/uio.h>
379ff53d 104#endif
f0cbd3ec 105
61dca5aa 106#undef _P
f0cbd3ec
FB
107#ifndef NO_PROTOTYPES
108# define _P(x) x
109#else
110# define _P(x) ()
111#endif
f0cbd3ec 112
379ff53d 113#ifndef _WIN32
f0cbd3ec
FB
114#include <netinet/in.h>
115#include <arpa/inet.h>
379ff53d 116#endif
f0cbd3ec
FB
117
118#ifdef GETTIMEOFDAY_ONE_ARG
119#define gettimeofday(x, y) gettimeofday(x)
120#endif
121
122/* Systems lacking strdup() definition in <string.h>. */
123#if defined(ultrix)
124char *strdup _P((const char *));
125#endif
126
127/* Systems lacking malloc() definition in <stdlib.h>. */
128#if defined(ultrix) || defined(hcx)
129void *malloc _P((size_t arg));
130void free _P((void *ptr));
131#endif
132
133#ifndef HAVE_INET_ATON
134int inet_aton _P((const char *cp, struct in_addr *ia));
135#endif
136
137#include <fcntl.h>
138#ifndef NO_UNIX_SOCKETS
139#include <sys/un.h>
140#endif
141#include <signal.h>
142#ifdef HAVE_SYS_SIGNAL_H
143# include <sys/signal.h>
144#endif
379ff53d 145#ifndef _WIN32
f0cbd3ec 146#include <sys/socket.h>
379ff53d 147#endif
f0cbd3ec 148
ee2654ac 149#if defined(HAVE_SYS_IOCTL_H)
f0cbd3ec 150# include <sys/ioctl.h>
f0cbd3ec
FB
151#endif
152
f0cbd3ec
FB
153#ifdef HAVE_SYS_SELECT_H
154# include <sys/select.h>
155#endif
156
157#ifdef HAVE_SYS_WAIT_H
158# include <sys/wait.h>
159#endif
160
161#ifdef HAVE_SYS_FILIO_H
162# include <sys/filio.h>
163#endif
164
165#ifdef USE_PPP
166#include <ppp/slirppp.h>
167#endif
168
169#ifdef __STDC__
170#include <stdarg.h>
171#else
172#include <varargs.h>
173#endif
174
175#include <sys/stat.h>
176
177/* Avoid conflicting with the libc insque() and remque(), which
178 have different prototypes. */
179#define insque slirp_insque
180#define remque slirp_remque
181
182#ifdef HAVE_SYS_STROPTS_H
183#include <sys/stropts.h>
184#endif
185
186#include "debug.h"
187
460fec67 188#include "libslirp.h"
f0cbd3ec
FB
189#include "ip.h"
190#include "tcp.h"
191#include "tcp_timer.h"
192#include "tcp_var.h"
193#include "tcpip.h"
194#include "udp.h"
f0cbd3ec
FB
195#include "mbuf.h"
196#include "sbuf.h"
197#include "socket.h"
198#include "if.h"
199#include "main.h"
200#include "misc.h"
f0cbd3ec
FB
201#ifdef USE_PPP
202#include "ppp/pppd.h"
203#include "ppp/ppp.h"
204#endif
205
206#include "bootp.h"
c7f74643 207#include "tftp.h"
460fec67
JK
208
209struct Slirp {
210 /* virtual network configuration */
211 struct in_addr vnetwork_addr;
212 struct in_addr vnetwork_mask;
213 struct in_addr vhost_addr;
214 struct in_addr vdhcp_startaddr;
215 struct in_addr vnameserver_addr;
216
217 /* ARP cache for the guest IP addresses (XXX: allow many entries) */
218 uint8_t client_ethaddr[6];
219
220 struct in_addr client_ipaddr;
221 char client_hostname[33];
222
223 int restricted;
224 struct timeval tt;
225 struct ex_list *exec_list;
226
227 /* mbuf states */
228 struct mbuf m_freelist, m_usedlist;
229 int mbuf_alloced;
230
231 /* if states */
232 int if_queued; /* number of packets queued so far */
233 struct mbuf if_fastq; /* fast queue (for interactive data) */
234 struct mbuf if_batchq; /* queue for non-interactive data */
235 struct mbuf *next_m; /* pointer to next mbuf to output */
236
237 /* ip states */
238 struct ipq ipq; /* ip reass. queue */
239 u_int16_t ip_id; /* ip packet ctr, for ids */
240
241 /* bootp/dhcp states */
242 BOOTPClient bootp_clients[NB_BOOTP_CLIENTS];
243 char *bootp_filename;
244
245 /* tcp states */
246 struct socket tcb;
247 struct socket *tcp_last_so;
248 tcp_seq tcp_iss; /* tcp initial send seq # */
249 u_int32_t tcp_now; /* for RFC 1323 timestamps */
250
251 /* udp states */
252 struct socket udb;
253 struct socket *udp_last_so;
254
255 /* tftp states */
256 char *tftp_prefix;
257 struct tftp_session tftp_sessions[TFTP_SESSIONS_MAX];
258
259};
260
261extern Slirp slirp_instance;
f0cbd3ec 262
f0cbd3ec
FB
263#ifndef NULL
264#define NULL (void *)0
265#endif
266
267#ifndef FULL_BOLT
460fec67 268void if_start _P((Slirp *));
f0cbd3ec
FB
269#else
270void if_start _P((struct ttys *));
271#endif
272
273#ifdef BAD_SPRINTF
274# define vsprintf vsprintf_len
275# define sprintf sprintf_len
276 extern int vsprintf_len _P((char *, const char *, va_list));
277 extern int sprintf_len _P((char *, const char *, ...));
278#endif
279
280#ifdef DECLARE_SPRINTF
281# ifndef BAD_SPRINTF
282 extern int vsprintf _P((char *, const char *, va_list));
283# endif
284 extern int vfprintf _P((FILE *, const char *, va_list));
285#endif
286
287#ifndef HAVE_STRERROR
288 extern char *strerror _P((int error));
289#endif
290
291#ifndef HAVE_INDEX
292 char *index _P((const char *, int));
293#endif
294
295#ifndef HAVE_GETHOSTID
296 long gethostid _P((void));
297#endif
298
299void lprint _P((const char *, ...));
300
379ff53d 301#ifndef _WIN32
f0cbd3ec 302#include <netdb.h>
379ff53d 303#endif
f0cbd3ec
FB
304
305#define DEFAULT_BAUD 115200
306
9634d903
BS
307#define SO_OPTIONS DO_KEEPALIVE
308#define TCP_MAXIDLE (TCPTV_KEEPCNT * TCPTV_KEEPINTVL)
309
f0cbd3ec
FB
310/* cksum.c */
311int cksum(struct mbuf *m, int len);
312
313/* if.c */
460fec67 314void if_init _P((Slirp *));
f0cbd3ec
FB
315void if_output _P((struct socket *, struct mbuf *));
316
317/* ip_input.c */
460fec67 318void ip_init _P((Slirp *));
f0cbd3ec 319void ip_input _P((struct mbuf *));
460fec67 320void ip_slowtimo _P((Slirp *));
f0cbd3ec
FB
321void ip_stripoptions _P((register struct mbuf *, struct mbuf *));
322
323/* ip_output.c */
324int ip_output _P((struct socket *, struct mbuf *));
325
326/* tcp_input.c */
f0cbd3ec 327void tcp_input _P((register struct mbuf *, int, struct socket *));
f0cbd3ec
FB
328int tcp_mss _P((register struct tcpcb *, u_int));
329
330/* tcp_output.c */
331int tcp_output _P((register struct tcpcb *));
332void tcp_setpersist _P((register struct tcpcb *));
333
334/* tcp_subr.c */
460fec67 335void tcp_init _P((Slirp *));
f0cbd3ec
FB
336void tcp_template _P((struct tcpcb *));
337void tcp_respond _P((struct tcpcb *, register struct tcpiphdr *, register struct mbuf *, tcp_seq, tcp_seq, int));
338struct tcpcb * tcp_newtcpcb _P((struct socket *));
339struct tcpcb * tcp_close _P((register struct tcpcb *));
f0cbd3ec
FB
340void tcp_sockclosed _P((struct tcpcb *));
341int tcp_fconnect _P((struct socket *));
342void tcp_connect _P((struct socket *));
343int tcp_attach _P((struct socket *));
344u_int8_t tcp_tos _P((struct socket *));
345int tcp_emu _P((struct socket *, struct mbuf *));
346int tcp_ctl _P((struct socket *));
9fafc9ea 347struct tcpcb *tcp_drop(struct tcpcb *tp, int err);
f0cbd3ec
FB
348
349#ifdef USE_PPP
350#define MIN_MRU MINMRU
351#define MAX_MRU MAXMRU
352#else
353#define MIN_MRU 128
354#define MAX_MRU 16384
355#endif
356
379ff53d
FB
357#ifndef _WIN32
358#define min(x,y) ((x) < (y) ? (x) : (y))
359#define max(x,y) ((x) > (y) ? (x) : (y))
360#endif
361
02d2c54c 362#ifdef _WIN32
ef6ff6b7 363#undef errno
02d2c54c
FB
364#define errno (WSAGetLastError())
365#endif
366
f0cbd3ec 367#endif