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