4 #include "qemu/host-utils.h"
5 #include "slirp_config.h"
12 # include <winsock2.h>
13 # include <ws2tcpip.h>
14 # include <sys/timeb.h>
15 # include <iphlpapi.h>
18 # if !defined(__HAIKU__)
23 #ifdef HAVE_SYS_BITYPES_H
24 # include <sys/bitypes.h>
32 #include <netinet/in.h>
33 #include <arpa/inet.h>
36 #ifndef NO_UNIX_SOCKETS
39 #ifdef HAVE_SYS_SIGNAL_H
40 # include <sys/signal.h>
43 #include <sys/socket.h>
46 #if defined(HAVE_SYS_IOCTL_H)
47 # include <sys/ioctl.h>
50 #ifdef HAVE_SYS_SELECT_H
51 # include <sys/select.h>
54 #ifdef HAVE_SYS_WAIT_H
55 # include <sys/wait.h>
58 #ifdef HAVE_SYS_FILIO_H
59 # include <sys/filio.h>
62 /* Avoid conflicting with the libc insque() and remque(), which
63 have different prototypes. */
64 #define insque slirp_insque
65 #define remque slirp_remque
66 #define quehead slirp_quehead
68 #ifdef HAVE_SYS_STROPTS_H
69 #include <sys/stropts.h>
76 #include "qemu/queue.h"
77 #include "qemu/sockets.h"
84 #include "tcp_timer.h"
100 #define ARPOP_REQUEST 1 /* ARP request */
101 #define ARPOP_REPLY 2 /* ARP reply */
104 unsigned char h_dest
[ETH_ALEN
]; /* destination eth addr */
105 unsigned char h_source
[ETH_ALEN
]; /* source ether addr */
106 unsigned short h_proto
; /* packet type ID field */
110 unsigned short ar_hrd
; /* format of hardware address */
111 unsigned short ar_pro
; /* format of protocol address */
112 unsigned char ar_hln
; /* length of hardware address */
113 unsigned char ar_pln
; /* length of protocol address */
114 unsigned short ar_op
; /* ARP opcode (command) */
117 * Ethernet looks like this : This bit is variable sized however...
119 unsigned char ar_sha
[ETH_ALEN
]; /* sender hardware address */
120 uint32_t ar_sip
; /* sender IP address */
121 unsigned char ar_tha
[ETH_ALEN
]; /* target hardware address */
122 uint32_t ar_tip
; /* target IP address */
125 #define ARP_TABLE_SIZE 16
127 typedef struct ArpTable
{
128 struct arphdr table
[ARP_TABLE_SIZE
];
132 void arp_table_add(Slirp
*slirp
, uint32_t ip_addr
, uint8_t ethaddr
[ETH_ALEN
]);
134 bool arp_table_search(Slirp
*slirp
, uint32_t ip_addr
,
135 uint8_t out_ethaddr
[ETH_ALEN
]);
138 unsigned char eth_addr
[ETH_ALEN
]; /* sender hardware address */
139 struct in6_addr ip_addr
; /* sender IP address */
142 #define NDP_TABLE_SIZE 16
144 typedef struct NdpTable
{
145 struct ndpentry table
[NDP_TABLE_SIZE
];
149 void ndp_table_add(Slirp
*slirp
, struct in6_addr ip_addr
,
150 uint8_t ethaddr
[ETH_ALEN
]);
151 bool ndp_table_search(Slirp
*slirp
, struct in6_addr ip_addr
,
152 uint8_t out_ethaddr
[ETH_ALEN
]);
155 QTAILQ_ENTRY(Slirp
) entry
;
160 bool in_enabled
, in6_enabled
;
162 /* virtual network configuration */
163 struct in_addr vnetwork_addr
;
164 struct in_addr vnetwork_mask
;
165 struct in_addr vhost_addr
;
166 struct in6_addr vprefix_addr6
;
168 struct in6_addr vhost_addr6
;
169 struct in_addr vdhcp_startaddr
;
170 struct in_addr vnameserver_addr
;
171 struct in6_addr vnameserver_addr6
;
173 struct in_addr client_ipaddr
;
174 char client_hostname
[33];
177 struct ex_list
*exec_list
;
180 struct quehead m_freelist
;
181 struct quehead m_usedlist
;
185 struct quehead if_fastq
; /* fast queue (for interactive data) */
186 struct quehead if_batchq
; /* queue for non-interactive data */
187 struct mbuf
*next_m
; /* pointer to next mbuf to output */
188 bool if_start_busy
; /* avoid if_start recursion */
191 struct ipq ipq
; /* ip reass. queue */
192 uint16_t ip_id
; /* ip packet ctr, for ids */
194 /* bootp/dhcp states */
195 BOOTPClient bootp_clients
[NB_BOOTP_CLIENTS
];
196 char *bootp_filename
;
197 size_t vdnssearch_len
;
202 struct socket
*tcp_last_so
;
203 tcp_seq tcp_iss
; /* tcp initial send seq # */
204 uint32_t tcp_now
; /* for RFC 1323 timestamps */
208 struct socket
*udp_last_so
;
212 struct socket
*icmp_last_so
;
216 struct tftp_session tftp_sessions
[TFTP_SESSIONS_MAX
];
227 extern Slirp
*slirp_instance
;
230 #define NULL (void *)0
233 void if_start(Slirp
*);
239 #define SO_OPTIONS DO_KEEPALIVE
240 #define TCP_MAXIDLE (TCPTV_KEEPCNT * TCPTV_KEEPINTVL)
243 int translate_dnssearch(Slirp
*s
, const char ** names
);
246 int cksum(struct mbuf
*m
, int len
);
247 int ip6_cksum(struct mbuf
*m
);
250 void if_init(Slirp
*);
251 void if_output(struct socket
*, struct mbuf
*);
254 void ip_init(Slirp
*);
255 void ip_cleanup(Slirp
*);
256 void ip_input(struct mbuf
*);
257 void ip_slowtimo(Slirp
*);
258 void ip_stripoptions(register struct mbuf
*, struct mbuf
*);
261 int ip_output(struct socket
*, struct mbuf
*);
264 void ip6_init(Slirp
*);
265 void ip6_cleanup(Slirp
*);
266 void ip6_input(struct mbuf
*);
269 int ip6_output(struct socket
*, struct mbuf
*, int fast
);
272 void tcp_input(register struct mbuf
*, int, struct socket
*, unsigned short af
);
273 int tcp_mss(register struct tcpcb
*, u_int
);
276 int tcp_output(register struct tcpcb
*);
277 void tcp_setpersist(register struct tcpcb
*);
280 void tcp_init(Slirp
*);
281 void tcp_cleanup(Slirp
*);
282 void tcp_template(struct tcpcb
*);
283 void tcp_respond(struct tcpcb
*, register struct tcpiphdr
*,
284 register struct mbuf
*, tcp_seq
, tcp_seq
, int, unsigned short);
285 struct tcpcb
* tcp_newtcpcb(struct socket
*);
286 struct tcpcb
* tcp_close(register struct tcpcb
*);
287 void tcp_sockclosed(struct tcpcb
*);
288 int tcp_fconnect(struct socket
*, unsigned short af
);
289 void tcp_connect(struct socket
*);
290 int tcp_attach(struct socket
*);
291 uint8_t tcp_tos(struct socket
*);
292 int tcp_emu(struct socket
*, struct mbuf
*);
293 int tcp_ctl(struct socket
*);
294 struct tcpcb
*tcp_drop(struct tcpcb
*tp
, int err
);
297 #define min(x,y) ((x) < (y) ? (x) : (y))
298 #define max(x,y) ((x) > (y) ? (x) : (y))