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