]> git.proxmox.com Git - mirror_qemu.git/blob - slirp/slirp.h
slirp: Prevent recursion of if_start
[mirror_qemu.git] / slirp / slirp.h
1 #ifndef __COMMON_H__
2 #define __COMMON_H__
3
4 #include "config-host.h"
5 #include "slirp_config.h"
6
7 #ifdef _WIN32
8 # include <inttypes.h>
9
10 typedef char *caddr_t;
11
12 # include <windows.h>
13 # include <winsock2.h>
14 # include <ws2tcpip.h>
15 # include <sys/timeb.h>
16 # include <iphlpapi.h>
17
18 # define EWOULDBLOCK WSAEWOULDBLOCK
19 # define EINPROGRESS WSAEINPROGRESS
20 # define ENOTCONN WSAENOTCONN
21 # define EHOSTUNREACH WSAEHOSTUNREACH
22 # define ENETUNREACH WSAENETUNREACH
23 # define ECONNREFUSED WSAECONNREFUSED
24 #else
25 # define ioctlsocket ioctl
26 # define closesocket(s) close(s)
27 # if !defined(__HAIKU__)
28 # define O_BINARY 0
29 # endif
30 #endif
31
32 #include <sys/types.h>
33 #ifdef HAVE_SYS_BITYPES_H
34 # include <sys/bitypes.h>
35 #endif
36
37 #include <sys/time.h>
38
39 #ifdef HAVE_UNISTD_H
40 # include <unistd.h>
41 #endif
42
43 #ifdef HAVE_STDLIB_H
44 # include <stdlib.h>
45 #endif
46
47 #include <stdio.h>
48 #include <errno.h>
49
50 #ifndef HAVE_MEMMOVE
51 #define memmove(x, y, z) bcopy(y, x, z)
52 #endif
53
54 #if TIME_WITH_SYS_TIME
55 # include <sys/time.h>
56 # include <time.h>
57 #else
58 # ifdef HAVE_SYS_TIME_H
59 # include <sys/time.h>
60 # else
61 # include <time.h>
62 # endif
63 #endif
64
65 #ifdef HAVE_STRING_H
66 # include <string.h>
67 #else
68 # include <strings.h>
69 #endif
70
71 #ifndef _WIN32
72 #include <sys/uio.h>
73 #endif
74
75 #ifndef _WIN32
76 #include <netinet/in.h>
77 #include <arpa/inet.h>
78 #endif
79
80 /* Systems lacking strdup() definition in <string.h>. */
81 #if defined(ultrix)
82 char *strdup(const char *);
83 #endif
84
85 /* Systems lacking malloc() definition in <stdlib.h>. */
86 #if defined(ultrix) || defined(hcx)
87 void *malloc(size_t arg);
88 void free(void *ptr);
89 #endif
90
91 #ifndef HAVE_INET_ATON
92 int inet_aton(const char *cp, struct in_addr *ia);
93 #endif
94
95 #include <fcntl.h>
96 #ifndef NO_UNIX_SOCKETS
97 #include <sys/un.h>
98 #endif
99 #include <signal.h>
100 #ifdef HAVE_SYS_SIGNAL_H
101 # include <sys/signal.h>
102 #endif
103 #ifndef _WIN32
104 #include <sys/socket.h>
105 #endif
106
107 #if defined(HAVE_SYS_IOCTL_H)
108 # include <sys/ioctl.h>
109 #endif
110
111 #ifdef HAVE_SYS_SELECT_H
112 # include <sys/select.h>
113 #endif
114
115 #ifdef HAVE_SYS_WAIT_H
116 # include <sys/wait.h>
117 #endif
118
119 #ifdef HAVE_SYS_FILIO_H
120 # include <sys/filio.h>
121 #endif
122
123 #ifdef USE_PPP
124 #include <ppp/slirppp.h>
125 #endif
126
127 #ifdef __STDC__
128 #include <stdarg.h>
129 #else
130 #include <varargs.h>
131 #endif
132
133 #include <sys/stat.h>
134
135 /* Avoid conflicting with the libc insque() and remque(), which
136 have different prototypes. */
137 #define insque slirp_insque
138 #define remque slirp_remque
139
140 #ifdef HAVE_SYS_STROPTS_H
141 #include <sys/stropts.h>
142 #endif
143
144 #include "debug.h"
145
146 #include "qemu-queue.h"
147
148 #include "libslirp.h"
149 #include "ip.h"
150 #include "tcp.h"
151 #include "tcp_timer.h"
152 #include "tcp_var.h"
153 #include "tcpip.h"
154 #include "udp.h"
155 #include "ip_icmp.h"
156 #include "mbuf.h"
157 #include "sbuf.h"
158 #include "socket.h"
159 #include "if.h"
160 #include "main.h"
161 #include "misc.h"
162 #ifdef USE_PPP
163 #include "ppp/pppd.h"
164 #include "ppp/ppp.h"
165 #endif
166
167 #include "bootp.h"
168 #include "tftp.h"
169
170 /* osdep.c */
171 int qemu_socket(int domain, int type, int protocol);
172
173 #define ETH_ALEN 6
174 #define ETH_HLEN 14
175
176 #define ETH_P_IP 0x0800 /* Internet Protocol packet */
177 #define ETH_P_ARP 0x0806 /* Address Resolution packet */
178
179 #define ARPOP_REQUEST 1 /* ARP request */
180 #define ARPOP_REPLY 2 /* ARP reply */
181
182 struct ethhdr {
183 unsigned char h_dest[ETH_ALEN]; /* destination eth addr */
184 unsigned char h_source[ETH_ALEN]; /* source ether addr */
185 unsigned short h_proto; /* packet type ID field */
186 };
187
188 struct arphdr {
189 unsigned short ar_hrd; /* format of hardware address */
190 unsigned short ar_pro; /* format of protocol address */
191 unsigned char ar_hln; /* length of hardware address */
192 unsigned char ar_pln; /* length of protocol address */
193 unsigned short ar_op; /* ARP opcode (command) */
194
195 /*
196 * Ethernet looks like this : This bit is variable sized however...
197 */
198 unsigned char ar_sha[ETH_ALEN]; /* sender hardware address */
199 uint32_t ar_sip; /* sender IP address */
200 unsigned char ar_tha[ETH_ALEN]; /* target hardware address */
201 uint32_t ar_tip; /* target IP address */
202 } QEMU_PACKED;
203
204 #define ARP_TABLE_SIZE 16
205
206 typedef struct ArpTable {
207 struct arphdr table[ARP_TABLE_SIZE];
208 int next_victim;
209 } ArpTable;
210
211 void arp_table_add(Slirp *slirp, uint32_t ip_addr, uint8_t ethaddr[ETH_ALEN]);
212
213 bool arp_table_search(Slirp *slirp, uint32_t ip_addr,
214 uint8_t out_ethaddr[ETH_ALEN]);
215
216 struct Slirp {
217 QTAILQ_ENTRY(Slirp) entry;
218
219 /* virtual network configuration */
220 struct in_addr vnetwork_addr;
221 struct in_addr vnetwork_mask;
222 struct in_addr vhost_addr;
223 struct in_addr vdhcp_startaddr;
224 struct in_addr vnameserver_addr;
225
226 struct in_addr client_ipaddr;
227 char client_hostname[33];
228
229 int restricted;
230 struct timeval tt;
231 struct ex_list *exec_list;
232
233 /* mbuf states */
234 struct mbuf m_freelist, m_usedlist;
235 int mbuf_alloced;
236
237 /* if states */
238 int if_queued; /* number of packets queued so far */
239 struct mbuf if_fastq; /* fast queue (for interactive data) */
240 struct mbuf if_batchq; /* queue for non-interactive data */
241 struct mbuf *next_m; /* pointer to next mbuf to output */
242 bool if_start_busy; /* avoid if_start recursion */
243
244 /* ip states */
245 struct ipq ipq; /* ip reass. queue */
246 uint16_t ip_id; /* ip packet ctr, for ids */
247
248 /* bootp/dhcp states */
249 BOOTPClient bootp_clients[NB_BOOTP_CLIENTS];
250 char *bootp_filename;
251
252 /* tcp states */
253 struct socket tcb;
254 struct socket *tcp_last_so;
255 tcp_seq tcp_iss; /* tcp initial send seq # */
256 uint32_t tcp_now; /* for RFC 1323 timestamps */
257
258 /* udp states */
259 struct socket udb;
260 struct socket *udp_last_so;
261
262 /* icmp states */
263 struct socket icmp;
264 struct socket *icmp_last_so;
265
266 /* tftp states */
267 char *tftp_prefix;
268 struct tftp_session tftp_sessions[TFTP_SESSIONS_MAX];
269
270 ArpTable arp_table;
271
272 void *opaque;
273 };
274
275 extern Slirp *slirp_instance;
276
277 #ifndef NULL
278 #define NULL (void *)0
279 #endif
280
281 #ifndef FULL_BOLT
282 void if_start(Slirp *);
283 #else
284 void if_start(struct ttys *);
285 #endif
286
287 #ifndef HAVE_STRERROR
288 char *strerror(int error);
289 #endif
290
291 #ifndef HAVE_INDEX
292 char *index(const char *, int);
293 #endif
294
295 #ifndef HAVE_GETHOSTID
296 long gethostid(void);
297 #endif
298
299 void lprint(const char *, ...) GCC_FMT_ATTR(1, 2);
300
301 #ifndef _WIN32
302 #include <netdb.h>
303 #endif
304
305 #define DEFAULT_BAUD 115200
306
307 #define SO_OPTIONS DO_KEEPALIVE
308 #define TCP_MAXIDLE (TCPTV_KEEPCNT * TCPTV_KEEPINTVL)
309
310 /* cksum.c */
311 int cksum(struct mbuf *m, int len);
312
313 /* if.c */
314 void if_init(Slirp *);
315 void if_output(struct socket *, struct mbuf *);
316
317 /* ip_input.c */
318 void ip_init(Slirp *);
319 void ip_input(struct mbuf *);
320 void ip_slowtimo(Slirp *);
321 void ip_stripoptions(register struct mbuf *, struct mbuf *);
322
323 /* ip_output.c */
324 int ip_output(struct socket *, struct mbuf *);
325
326 /* tcp_input.c */
327 void tcp_input(register struct mbuf *, int, struct socket *);
328 int tcp_mss(register struct tcpcb *, u_int);
329
330 /* tcp_output.c */
331 int tcp_output(register struct tcpcb *);
332 void tcp_setpersist(register struct tcpcb *);
333
334 /* tcp_subr.c */
335 void tcp_init(Slirp *);
336 void tcp_template(struct tcpcb *);
337 void tcp_respond(struct tcpcb *, register struct tcpiphdr *, register struct mbuf *, tcp_seq, tcp_seq, int);
338 struct tcpcb * tcp_newtcpcb(struct socket *);
339 struct tcpcb * tcp_close(register struct tcpcb *);
340 void tcp_sockclosed(struct tcpcb *);
341 int tcp_fconnect(struct socket *);
342 void tcp_connect(struct socket *);
343 int tcp_attach(struct socket *);
344 uint8_t tcp_tos(struct socket *);
345 int tcp_emu(struct socket *, struct mbuf *);
346 int tcp_ctl(struct socket *);
347 struct tcpcb *tcp_drop(struct tcpcb *tp, int err);
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
357 #ifndef _WIN32
358 #define min(x,y) ((x) < (y) ? (x) : (y))
359 #define max(x,y) ((x) > (y) ? (x) : (y))
360 #endif
361
362 #ifdef _WIN32
363 #undef errno
364 #define errno (WSAGetLastError())
365 #endif
366
367 #endif