4 #include "slirp_config.h"
11 # include <winsock2.h>
12 # include <ws2tcpip.h>
13 # include <sys/timeb.h>
14 # include <iphlpapi.h>
17 # if !defined(__HAIKU__)
22 #ifdef HAVE_SYS_BITYPES_H
23 # include <sys/bitypes.h>
28 #define memmove(x, y, z) bcopy(y, x, z)
36 #include <netinet/in.h>
37 #include <arpa/inet.h>
40 /* Systems lacking strdup() definition in <string.h>. */
42 char *strdup(const char *);
45 /* Systems lacking malloc() definition in <stdlib.h>. */
46 #if defined(ultrix) || defined(hcx)
47 void *malloc(size_t arg);
51 #ifndef NO_UNIX_SOCKETS
54 #ifdef HAVE_SYS_SIGNAL_H
55 # include <sys/signal.h>
58 #include <sys/socket.h>
61 #if defined(HAVE_SYS_IOCTL_H)
62 # include <sys/ioctl.h>
65 #ifdef HAVE_SYS_SELECT_H
66 # include <sys/select.h>
69 #ifdef HAVE_SYS_WAIT_H
70 # include <sys/wait.h>
73 #ifdef HAVE_SYS_FILIO_H
74 # include <sys/filio.h>
78 #include <ppp/slirppp.h>
81 /* Avoid conflicting with the libc insque() and remque(), which
82 have different prototypes. */
83 #define insque slirp_insque
84 #define remque slirp_remque
85 #define quehead slirp_quehead
87 #ifdef HAVE_SYS_STROPTS_H
88 #include <sys/stropts.h>
95 #include "qemu/queue.h"
96 #include "qemu/sockets.h"
103 #include "tcp_timer.h"
108 #include "ip6_icmp.h"
116 #include "ppp/pppd.h"
123 #define ARPOP_REQUEST 1 /* ARP request */
124 #define ARPOP_REPLY 2 /* ARP reply */
127 unsigned char h_dest[ETH_ALEN]; /* destination eth addr */
128 unsigned char h_source[ETH_ALEN]; /* source ether addr */
129 unsigned short h_proto; /* packet type ID field */
133 unsigned short ar_hrd; /* format of hardware address */
134 unsigned short ar_pro; /* format of protocol address */
135 unsigned char ar_hln; /* length of hardware address */
136 unsigned char ar_pln; /* length of protocol address */
137 unsigned short ar_op; /* ARP opcode (command) */
140 * Ethernet looks like this : This bit is variable sized however...
142 unsigned char ar_sha[ETH_ALEN]; /* sender hardware address */
143 uint32_t ar_sip; /* sender IP address */
144 unsigned char ar_tha[ETH_ALEN]; /* target hardware address */
145 uint32_t ar_tip; /* target IP address */
148 #define ARP_TABLE_SIZE 16
150 typedef struct ArpTable {
151 struct arphdr table[ARP_TABLE_SIZE];
155 void arp_table_add(Slirp *slirp, uint32_t ip_addr, uint8_t ethaddr[ETH_ALEN]);
157 bool arp_table_search(Slirp *slirp, uint32_t ip_addr,
158 uint8_t out_ethaddr[ETH_ALEN]);
161 unsigned char eth_addr[ETH_ALEN]; /* sender hardware address */
162 struct in6_addr ip_addr; /* sender IP address */
165 #define NDP_TABLE_SIZE 16
167 typedef struct NdpTable {
168 struct ndpentry table[NDP_TABLE_SIZE];
172 void ndp_table_add(Slirp *slirp, struct in6_addr ip_addr,
173 uint8_t ethaddr[ETH_ALEN]);
174 bool ndp_table_search(Slirp *slirp, struct in6_addr ip_addr,
175 uint8_t out_ethaddr[ETH_ALEN]);
178 QTAILQ_ENTRY(Slirp) entry;
183 bool in_enabled, in6_enabled;
185 /* virtual network configuration */
186 struct in_addr vnetwork_addr;
187 struct in_addr vnetwork_mask;
188 struct in_addr vhost_addr;
189 struct in6_addr vprefix_addr6;
191 struct in6_addr vhost_addr6;
192 struct in_addr vdhcp_startaddr;
193 struct in_addr vnameserver_addr;
194 struct in6_addr vnameserver_addr6;
196 struct in_addr client_ipaddr;
197 char client_hostname[33];
200 struct ex_list *exec_list;
203 struct quehead m_freelist;
204 struct quehead m_usedlist;
208 struct quehead if_fastq; /* fast queue (for interactive data) */
209 struct quehead if_batchq; /* queue for non-interactive data */
210 struct mbuf *next_m; /* pointer to next mbuf to output */
211 bool if_start_busy; /* avoid if_start recursion */
214 struct ipq ipq; /* ip reass. queue */
215 uint16_t ip_id; /* ip packet ctr, for ids */
217 /* bootp/dhcp states */
218 BOOTPClient bootp_clients[NB_BOOTP_CLIENTS];
219 char *bootp_filename;
220 size_t vdnssearch_len;
225 struct socket *tcp_last_so;
226 tcp_seq tcp_iss; /* tcp initial send seq # */
227 uint32_t tcp_now; /* for RFC 1323 timestamps */
231 struct socket *udp_last_so;
235 struct socket *icmp_last_so;
239 struct tftp_session tftp_sessions[TFTP_SESSIONS_MAX];
250 extern Slirp *slirp_instance;
253 #define NULL (void *)0
257 void if_start(Slirp *);
259 void if_start(struct ttys *);
262 #ifndef HAVE_STRERROR
263 char *strerror(int error);
267 char *index(const char *, int);
270 #ifndef HAVE_GETHOSTID
271 long gethostid(void);
278 #define DEFAULT_BAUD 115200
280 #define SO_OPTIONS DO_KEEPALIVE
281 #define TCP_MAXIDLE (TCPTV_KEEPCNT * TCPTV_KEEPINTVL)
284 int translate_dnssearch(Slirp *s, const char ** names);
287 int cksum(struct mbuf *m, int len);
288 int ip6_cksum(struct mbuf *m);
291 void if_init(Slirp *);
292 void if_output(struct socket *, struct mbuf *);
295 void ip_init(Slirp *);
296 void ip_cleanup(Slirp *);
297 void ip_input(struct mbuf *);
298 void ip_slowtimo(Slirp *);
299 void ip_stripoptions(register struct mbuf *, struct mbuf *);
302 int ip_output(struct socket *, struct mbuf *);
305 void ip6_init(Slirp *);
306 void ip6_cleanup(Slirp *);
307 void ip6_input(struct mbuf *);
310 int ip6_output(struct socket *, struct mbuf *, int fast);
313 void tcp_input(register struct mbuf *, int, struct socket *, unsigned short af);
314 int tcp_mss(register struct tcpcb *, u_int);
317 int tcp_output(register struct tcpcb *);
318 void tcp_setpersist(register struct tcpcb *);
321 void tcp_init(Slirp *);
322 void tcp_cleanup(Slirp *);
323 void tcp_template(struct tcpcb *);
324 void tcp_respond(struct tcpcb *, register struct tcpiphdr *,
325 register struct mbuf *, tcp_seq, tcp_seq, int, unsigned short);
326 struct tcpcb * tcp_newtcpcb(struct socket *);
327 struct tcpcb * tcp_close(register struct tcpcb *);
328 void tcp_sockclosed(struct tcpcb *);
329 int tcp_fconnect(struct socket *, unsigned short af);
330 void tcp_connect(struct socket *);
331 int tcp_attach(struct socket *);
332 uint8_t tcp_tos(struct socket *);
333 int tcp_emu(struct socket *, struct mbuf *);
334 int tcp_ctl(struct socket *);
335 struct tcpcb *tcp_drop(struct tcpcb *tp, int err);
338 #define MIN_MRU MINMRU
339 #define MAX_MRU MAXMRU
342 #define MAX_MRU 16384
346 #define min(x,y) ((x) < (y) ? (x) : (y))
347 #define max(x,y) ((x) > (y) ? (x) : (y))