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