Statistics
| Branch: | Revision:

root / slirp / slirp.h @ 1de7afc9

History | View | Annotate | Download (7.6 kB)

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