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