exec: Fix memory allocation when memory path isn't on hugetlbfs
[qemu/kevin.git] / slirp / slirp.h
bloba6741e77b1353dfeeffee59d51fa09a6f0e03565
1 #ifndef __COMMON_H__
2 #define __COMMON_H__
4 #include "slirp_config.h"
6 #ifdef _WIN32
8 typedef char *caddr_t;
10 # include <windows.h>
11 # include <winsock2.h>
12 # include <ws2tcpip.h>
13 # include <sys/timeb.h>
14 # include <iphlpapi.h>
16 #else
17 # if !defined(__HAIKU__)
18 # define O_BINARY 0
19 # endif
20 #endif
22 #ifdef HAVE_SYS_BITYPES_H
23 # include <sys/bitypes.h>
24 #endif
27 #ifdef HAVE_UNISTD_H
28 #endif
30 #ifdef HAVE_STDLIB_H
31 #endif
34 #ifndef HAVE_MEMMOVE
35 #define memmove(x, y, z) bcopy(y, x, z)
36 #endif
38 #if TIME_WITH_SYS_TIME
39 #else
40 # ifdef HAVE_SYS_TIME_H
41 # else
42 # endif
43 #endif
45 #ifdef HAVE_STRING_H
46 #else
47 #endif
49 #ifndef _WIN32
50 #include <sys/uio.h>
51 #endif
53 #ifndef _WIN32
54 #include <netinet/in.h>
55 #include <arpa/inet.h>
56 #endif
58 /* Systems lacking strdup() definition in <string.h>. */
59 #if defined(ultrix)
60 char *strdup(const char *);
61 #endif
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
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
79 #if defined(HAVE_SYS_IOCTL_H)
80 # include <sys/ioctl.h>
81 #endif
83 #ifdef HAVE_SYS_SELECT_H
84 # include <sys/select.h>
85 #endif
87 #ifdef HAVE_SYS_WAIT_H
88 # include <sys/wait.h>
89 #endif
91 #ifdef HAVE_SYS_FILIO_H
92 # include <sys/filio.h>
93 #endif
95 #ifdef USE_PPP
96 #include <ppp/slirppp.h>
97 #endif
99 #ifdef __STDC__
100 #else
101 #include <varargs.h>
102 #endif
105 /* Avoid conflicting with the libc insque() and remque(), which
106 have different prototypes. */
107 #define insque slirp_insque
108 #define remque slirp_remque
110 #ifdef HAVE_SYS_STROPTS_H
111 #include <sys/stropts.h>
112 #endif
114 #include "debug.h"
116 #include "qemu/queue.h"
117 #include "qemu/sockets.h"
118 #include "net/eth.h"
120 #include "libslirp.h"
121 #include "ip.h"
122 #include "tcp.h"
123 #include "tcp_timer.h"
124 #include "tcp_var.h"
125 #include "tcpip.h"
126 #include "udp.h"
127 #include "ip_icmp.h"
128 #include "mbuf.h"
129 #include "sbuf.h"
130 #include "socket.h"
131 #include "if.h"
132 #include "main.h"
133 #include "misc.h"
134 #ifdef USE_PPP
135 #include "ppp/pppd.h"
136 #include "ppp/ppp.h"
137 #endif
139 #include "bootp.h"
140 #include "tftp.h"
142 #define ARPOP_REQUEST 1 /* ARP request */
143 #define ARPOP_REPLY 2 /* ARP reply */
145 struct ethhdr {
146 unsigned char h_dest[ETH_ALEN]; /* destination eth addr */
147 unsigned char h_source[ETH_ALEN]; /* source ether addr */
148 unsigned short h_proto; /* packet type ID field */
151 struct arphdr {
152 unsigned short ar_hrd; /* format of hardware address */
153 unsigned short ar_pro; /* format of protocol address */
154 unsigned char ar_hln; /* length of hardware address */
155 unsigned char ar_pln; /* length of protocol address */
156 unsigned short ar_op; /* ARP opcode (command) */
159 * Ethernet looks like this : This bit is variable sized however...
161 unsigned char ar_sha[ETH_ALEN]; /* sender hardware address */
162 uint32_t ar_sip; /* sender IP address */
163 unsigned char ar_tha[ETH_ALEN]; /* target hardware address */
164 uint32_t ar_tip; /* target IP address */
165 } QEMU_PACKED;
167 #define ARP_TABLE_SIZE 16
169 typedef struct ArpTable {
170 struct arphdr table[ARP_TABLE_SIZE];
171 int next_victim;
172 } ArpTable;
174 void arp_table_add(Slirp *slirp, uint32_t ip_addr, uint8_t ethaddr[ETH_ALEN]);
176 bool arp_table_search(Slirp *slirp, uint32_t ip_addr,
177 uint8_t out_ethaddr[ETH_ALEN]);
179 struct Slirp {
180 QTAILQ_ENTRY(Slirp) entry;
181 u_int time_fasttimo;
182 u_int last_slowtimo;
183 bool do_slowtimo;
185 /* virtual network configuration */
186 struct in_addr vnetwork_addr;
187 struct in_addr vnetwork_mask;
188 struct in_addr vhost_addr;
189 struct in_addr vdhcp_startaddr;
190 struct in_addr vnameserver_addr;
192 struct in_addr client_ipaddr;
193 char client_hostname[33];
195 int restricted;
196 struct ex_list *exec_list;
198 /* mbuf states */
199 struct mbuf m_freelist, m_usedlist;
200 int mbuf_alloced;
202 /* if states */
203 struct mbuf if_fastq; /* fast queue (for interactive data) */
204 struct mbuf if_batchq; /* queue for non-interactive data */
205 struct mbuf *next_m; /* pointer to next mbuf to output */
206 bool if_start_busy; /* avoid if_start recursion */
208 /* ip states */
209 struct ipq ipq; /* ip reass. queue */
210 uint16_t ip_id; /* ip packet ctr, for ids */
212 /* bootp/dhcp states */
213 BOOTPClient bootp_clients[NB_BOOTP_CLIENTS];
214 char *bootp_filename;
215 size_t vdnssearch_len;
216 uint8_t *vdnssearch;
218 /* tcp states */
219 struct socket tcb;
220 struct socket *tcp_last_so;
221 tcp_seq tcp_iss; /* tcp initial send seq # */
222 uint32_t tcp_now; /* for RFC 1323 timestamps */
224 /* udp states */
225 struct socket udb;
226 struct socket *udp_last_so;
228 /* icmp states */
229 struct socket icmp;
230 struct socket *icmp_last_so;
232 /* tftp states */
233 char *tftp_prefix;
234 struct tftp_session tftp_sessions[TFTP_SESSIONS_MAX];
236 ArpTable arp_table;
238 void *opaque;
241 extern Slirp *slirp_instance;
243 #ifndef NULL
244 #define NULL (void *)0
245 #endif
247 #ifndef FULL_BOLT
248 void if_start(Slirp *);
249 #else
250 void if_start(struct ttys *);
251 #endif
253 #ifndef HAVE_STRERROR
254 char *strerror(int error);
255 #endif
257 #ifndef HAVE_INDEX
258 char *index(const char *, int);
259 #endif
261 #ifndef HAVE_GETHOSTID
262 long gethostid(void);
263 #endif
265 #ifndef _WIN32
266 #include <netdb.h>
267 #endif
269 #define DEFAULT_BAUD 115200
271 #define SO_OPTIONS DO_KEEPALIVE
272 #define TCP_MAXIDLE (TCPTV_KEEPCNT * TCPTV_KEEPINTVL)
274 /* dnssearch.c */
275 int translate_dnssearch(Slirp *s, const char ** names);
277 /* cksum.c */
278 int cksum(struct mbuf *m, int len);
280 /* if.c */
281 void if_init(Slirp *);
282 void if_output(struct socket *, struct mbuf *);
284 /* ip_input.c */
285 void ip_init(Slirp *);
286 void ip_cleanup(Slirp *);
287 void ip_input(struct mbuf *);
288 void ip_slowtimo(Slirp *);
289 void ip_stripoptions(register struct mbuf *, struct mbuf *);
291 /* ip_output.c */
292 int ip_output(struct socket *, struct mbuf *);
294 /* tcp_input.c */
295 void tcp_input(register struct mbuf *, int, struct socket *);
296 int tcp_mss(register struct tcpcb *, u_int);
298 /* tcp_output.c */
299 int tcp_output(register struct tcpcb *);
300 void tcp_setpersist(register struct tcpcb *);
302 /* tcp_subr.c */
303 void tcp_init(Slirp *);
304 void tcp_cleanup(Slirp *);
305 void tcp_template(struct tcpcb *);
306 void tcp_respond(struct tcpcb *, register struct tcpiphdr *, register struct mbuf *, tcp_seq, tcp_seq, int);
307 struct tcpcb * tcp_newtcpcb(struct socket *);
308 struct tcpcb * tcp_close(register struct tcpcb *);
309 void tcp_sockclosed(struct tcpcb *);
310 int tcp_fconnect(struct socket *, unsigned short af);
311 void tcp_connect(struct socket *);
312 int tcp_attach(struct socket *);
313 uint8_t tcp_tos(struct socket *);
314 int tcp_emu(struct socket *, struct mbuf *);
315 int tcp_ctl(struct socket *);
316 struct tcpcb *tcp_drop(struct tcpcb *tp, int err);
318 #ifdef USE_PPP
319 #define MIN_MRU MINMRU
320 #define MAX_MRU MAXMRU
321 #else
322 #define MIN_MRU 128
323 #define MAX_MRU 16384
324 #endif
326 #ifndef _WIN32
327 #define min(x,y) ((x) < (y) ? (x) : (y))
328 #define max(x,y) ((x) > (y) ? (x) : (y))
329 #endif
331 #ifdef _WIN32
332 #undef errno
333 #define errno (WSAGetLastError())
334 #endif
336 #endif