1#ifndef SLIRP_H
2#define SLIRP_H
3
4#include "qemu/host-utils.h"
5#include "slirp_config.h"
6
7#ifdef _WIN32
8
9typedef char *caddr_t;
10
11# include <windows.h>
12# include <winsock2.h>
13# include <ws2tcpip.h>
14# include <sys/timeb.h>
15# include <iphlpapi.h>
16
17#else
18# if !defined(__HAIKU__)
19# define O_BINARY 0
20# endif
21#endif
22
23#ifdef HAVE_SYS_BITYPES_H
24# include <sys/bitypes.h>
25#endif
26
27#ifndef _WIN32
28#include <sys/uio.h>
29#endif
30
31#ifndef _WIN32
32#include <netinet/in.h>
33#include <arpa/inet.h>
34#endif
35
36#ifndef NO_UNIX_SOCKETS
37#include <sys/un.h>
38#endif
39#ifdef HAVE_SYS_SIGNAL_H
40# include <sys/signal.h>
41#endif
42#ifndef _WIN32
43#include <sys/socket.h>
44#endif
45
46#if defined(HAVE_SYS_IOCTL_H)
47# include <sys/ioctl.h>
48#endif
49
50#ifdef HAVE_SYS_SELECT_H
51# include <sys/select.h>
52#endif
53
54#ifdef HAVE_SYS_WAIT_H
55# include <sys/wait.h>
56#endif
57
58#ifdef HAVE_SYS_FILIO_H
59# include <sys/filio.h>
60#endif
61
62
63
64#define insque slirp_insque
65#define remque slirp_remque
66#define quehead slirp_quehead
67
68#ifdef HAVE_SYS_STROPTS_H
69#include <sys/stropts.h>
70#endif
71
72
73#include "debug.h"
74
75#include "qemu/queue.h"
76#include "qemu/sockets.h"
77#include "net/eth.h"
78
79#include "libslirp.h"
80#include "ip.h"
81#include "ip6.h"
82#include "tcp.h"
83#include "tcp_timer.h"
84#include "tcp_var.h"
85#include "tcpip.h"
86#include "udp.h"
87#include "ip_icmp.h"
88#include "ip6_icmp.h"
89#include "mbuf.h"
90#include "sbuf.h"
91#include "socket.h"
92#include "if.h"
93#include "main.h"
94#include "misc.h"
95
96#include "bootp.h"
97#include "tftp.h"
98
99#define ARPOP_REQUEST 1
100#define ARPOP_REPLY 2
101
102struct ethhdr {
103 unsigned char h_dest[ETH_ALEN];
104 unsigned char h_source[ETH_ALEN];
105 unsigned short h_proto;
106};
107
108struct slirp_arphdr {
109 unsigned short ar_hrd;
110 unsigned short ar_pro;
111 unsigned char ar_hln;
112 unsigned char ar_pln;
113 unsigned short ar_op;
114
115
116
117
118 unsigned char ar_sha[ETH_ALEN];
119 uint32_t ar_sip;
120 unsigned char ar_tha[ETH_ALEN];
121 uint32_t ar_tip;
122} QEMU_PACKED;
123
124#define ARP_TABLE_SIZE 16
125
126typedef struct ArpTable {
127 struct slirp_arphdr table[ARP_TABLE_SIZE];
128 int next_victim;
129} ArpTable;
130
131void arp_table_add(Slirp *slirp, uint32_t ip_addr, uint8_t ethaddr[ETH_ALEN]);
132
133bool arp_table_search(Slirp *slirp, uint32_t ip_addr,
134 uint8_t out_ethaddr[ETH_ALEN]);
135
136struct ndpentry {
137 unsigned char eth_addr[ETH_ALEN];
138 struct in6_addr ip_addr;
139} QEMU_PACKED;
140
141#define NDP_TABLE_SIZE 16
142
143typedef struct NdpTable {
144 struct ndpentry table[NDP_TABLE_SIZE];
145 int next_victim;
146} NdpTable;
147
148void ndp_table_add(Slirp *slirp, struct in6_addr ip_addr,
149 uint8_t ethaddr[ETH_ALEN]);
150bool ndp_table_search(Slirp *slirp, struct in6_addr ip_addr,
151 uint8_t out_ethaddr[ETH_ALEN]);
152
153struct Slirp {
154 QTAILQ_ENTRY(Slirp) entry;
155 u_int time_fasttimo;
156 u_int last_slowtimo;
157 bool do_slowtimo;
158
159 bool in_enabled, in6_enabled;
160
161
162 struct in_addr vnetwork_addr;
163 struct in_addr vnetwork_mask;
164 struct in_addr vhost_addr;
165 struct in6_addr vprefix_addr6;
166 uint8_t vprefix_len;
167 struct in6_addr vhost_addr6;
168 struct in_addr vdhcp_startaddr;
169 struct in_addr vnameserver_addr;
170 struct in6_addr vnameserver_addr6;
171
172 struct in_addr client_ipaddr;
173 char client_hostname[33];
174
175 int restricted;
176 struct ex_list *exec_list;
177
178
179 struct quehead m_freelist;
180 struct quehead m_usedlist;
181 int mbuf_alloced;
182
183
184 struct quehead if_fastq;
185 struct quehead if_batchq;
186 struct mbuf *next_m;
187 bool if_start_busy;
188
189
190 struct ipq ipq;
191 uint16_t ip_id;
192
193
194 BOOTPClient bootp_clients[NB_BOOTP_CLIENTS];
195 char *bootp_filename;
196 size_t vdnssearch_len;
197 uint8_t *vdnssearch;
198
199
200 struct socket tcb;
201 struct socket *tcp_last_so;
202 tcp_seq tcp_iss;
203 uint32_t tcp_now;
204
205
206 struct socket udb;
207 struct socket *udp_last_so;
208
209
210 struct socket icmp;
211 struct socket *icmp_last_so;
212
213
214 char *tftp_prefix;
215 struct tftp_session tftp_sessions[TFTP_SESSIONS_MAX];
216
217 ArpTable arp_table;
218 NdpTable ndp_table;
219
220 GRand *grand;
221 QEMUTimer *ra_timer;
222
223 void *opaque;
224};
225
226extern Slirp *slirp_instance;
227
228#ifndef NULL
229#define NULL (void *)0
230#endif
231
232void if_start(Slirp *);
233
234#ifndef _WIN32
235#include <netdb.h>
236#endif
237
238#define SO_OPTIONS DO_KEEPALIVE
239#define TCP_MAXIDLE (TCPTV_KEEPCNT * TCPTV_KEEPINTVL)
240
241
242int translate_dnssearch(Slirp *s, const char ** names);
243
244
245int cksum(struct mbuf *m, int len);
246int ip6_cksum(struct mbuf *m);
247
248
249void if_init(Slirp *);
250void if_output(struct socket *, struct mbuf *);
251
252
253void ip_init(Slirp *);
254void ip_cleanup(Slirp *);
255void ip_input(struct mbuf *);
256void ip_slowtimo(Slirp *);
257void ip_stripoptions(register struct mbuf *, struct mbuf *);
258
259
260int ip_output(struct socket *, struct mbuf *);
261
262
263void ip6_init(Slirp *);
264void ip6_cleanup(Slirp *);
265void ip6_input(struct mbuf *);
266
267
268int ip6_output(struct socket *, struct mbuf *, int fast);
269
270
271void tcp_input(register struct mbuf *, int, struct socket *, unsigned short af);
272int tcp_mss(register struct tcpcb *, u_int);
273
274
275int tcp_output(register struct tcpcb *);
276void tcp_setpersist(register struct tcpcb *);
277
278
279void tcp_init(Slirp *);
280void tcp_cleanup(Slirp *);
281void tcp_template(struct tcpcb *);
282void tcp_respond(struct tcpcb *, register struct tcpiphdr *,
283 register struct mbuf *, tcp_seq, tcp_seq, int, unsigned short);
284struct tcpcb * tcp_newtcpcb(struct socket *);
285struct tcpcb * tcp_close(register struct tcpcb *);
286void tcp_sockclosed(struct tcpcb *);
287int tcp_fconnect(struct socket *, unsigned short af);
288void tcp_connect(struct socket *);
289int tcp_attach(struct socket *);
290uint8_t tcp_tos(struct socket *);
291int tcp_emu(struct socket *, struct mbuf *);
292int tcp_ctl(struct socket *);
293struct tcpcb *tcp_drop(struct tcpcb *tp, int err);
294
295#endif
296