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>
31 #include <netinet/in.h>
32 #include <arpa/inet.h>
35 #ifndef NO_UNIX_SOCKETS
38 #ifdef HAVE_SYS_SIGNAL_H
39 # include <sys/signal.h>
42 #include <sys/socket.h>
45 #if defined(HAVE_SYS_IOCTL_H)
46 # include <sys/ioctl.h>
49 #ifdef HAVE_SYS_SELECT_H
50 # include <sys/select.h>
53 #ifdef HAVE_SYS_WAIT_H
54 # include <sys/wait.h>
57 #ifdef HAVE_SYS_FILIO_H
58 # include <sys/filio.h>
61 /* Avoid conflicting with the libc insque() and remque(), which
62 have different prototypes. */
63 #define insque slirp_insque
64 #define remque slirp_remque
65 #define quehead slirp_quehead
67 #ifdef HAVE_SYS_STROPTS_H
68 #include <sys/stropts.h>
75 #include "qemu/queue.h"
76 #include "qemu/sockets.h"
83 #include "tcp_timer.h"
99 #define ARPOP_REQUEST 1 /* ARP request */
100 #define ARPOP_REPLY 2 /* ARP reply */
103 unsigned char h_dest[ETH_ALEN]; /* destination eth addr */
104 unsigned char h_source[ETH_ALEN]; /* source ether addr */
105 unsigned short h_proto; /* packet type ID field */
109 unsigned short ar_hrd; /* format of hardware address */
110 unsigned short ar_pro; /* format of protocol address */
111 unsigned char ar_hln; /* length of hardware address */
112 unsigned char ar_pln; /* length of protocol address */
113 unsigned short ar_op; /* ARP opcode (command) */
116 * Ethernet looks like this : This bit is variable sized however...
118 unsigned char ar_sha[ETH_ALEN]; /* sender hardware address */
119 uint32_t ar_sip; /* sender IP address */
120 unsigned char ar_tha[ETH_ALEN]; /* target hardware address */
121 uint32_t ar_tip; /* target IP address */
124 #define ARP_TABLE_SIZE 16
126 typedef struct ArpTable {
127 struct arphdr table[ARP_TABLE_SIZE];
131 void arp_table_add(Slirp *slirp, uint32_t ip_addr, uint8_t ethaddr[ETH_ALEN]);
133 bool arp_table_search(Slirp *slirp, uint32_t ip_addr,
134 uint8_t out_ethaddr[ETH_ALEN]);
137 unsigned char eth_addr[ETH_ALEN]; /* sender hardware address */
138 struct in6_addr ip_addr; /* sender IP address */
141 #define NDP_TABLE_SIZE 16
143 typedef struct NdpTable {
144 struct ndpentry table[NDP_TABLE_SIZE];
148 void ndp_table_add(Slirp *slirp, struct in6_addr ip_addr,
149 uint8_t ethaddr[ETH_ALEN]);
150 bool ndp_table_search(Slirp *slirp, struct in6_addr ip_addr,
151 uint8_t out_ethaddr[ETH_ALEN]);
154 QTAILQ_ENTRY(Slirp) entry;
159 bool in_enabled, in6_enabled;
161 /* virtual network configuration */
162 struct in_addr vnetwork_addr;
163 struct in_addr vnetwork_mask;
164 struct in_addr vhost_addr;
165 struct in6_addr vprefix_addr6;
167 struct in6_addr vhost_addr6;
168 struct in_addr vdhcp_startaddr;
169 struct in_addr vnameserver_addr;
170 struct in6_addr vnameserver_addr6;
172 struct in_addr client_ipaddr;
173 char client_hostname[33];
176 struct ex_list *exec_list;
179 struct quehead m_freelist;
180 struct quehead m_usedlist;
184 struct quehead if_fastq; /* fast queue (for interactive data) */
185 struct quehead if_batchq; /* queue for non-interactive data */
186 struct mbuf *next_m; /* pointer to next mbuf to output */
187 bool if_start_busy; /* avoid if_start recursion */
190 struct ipq ipq; /* ip reass. queue */
191 uint16_t ip_id; /* ip packet ctr, for ids */
193 /* bootp/dhcp states */
194 BOOTPClient bootp_clients[NB_BOOTP_CLIENTS];
195 char *bootp_filename;
196 size_t vdnssearch_len;
201 struct socket *tcp_last_so;
202 tcp_seq tcp_iss; /* tcp initial send seq # */
203 uint32_t tcp_now; /* for RFC 1323 timestamps */
207 struct socket *udp_last_so;
211 struct socket *icmp_last_so;
215 struct tftp_session tftp_sessions[TFTP_SESSIONS_MAX];
226 extern Slirp *slirp_instance;
229 #define NULL (void *)0
232 void if_start(Slirp *);
238 #define SO_OPTIONS DO_KEEPALIVE
239 #define TCP_MAXIDLE (TCPTV_KEEPCNT * TCPTV_KEEPINTVL)
242 int translate_dnssearch(Slirp *s, const char ** names);
245 int cksum(struct mbuf *m, int len);
246 int ip6_cksum(struct mbuf *m);
249 void if_init(Slirp *);
250 void if_output(struct socket *, struct mbuf *);
253 void ip_init(Slirp *);
254 void ip_cleanup(Slirp *);
255 void ip_input(struct mbuf *);
256 void ip_slowtimo(Slirp *);
257 void ip_stripoptions(register struct mbuf *, struct mbuf *);
260 int ip_output(struct socket *, struct mbuf *);
263 void ip6_init(Slirp *);
264 void ip6_cleanup(Slirp *);
265 void ip6_input(struct mbuf *);
268 int ip6_output(struct socket *, struct mbuf *, int fast);
271 void tcp_input(register struct mbuf *, int, struct socket *, unsigned short af);
272 int tcp_mss(register struct tcpcb *, u_int);
275 int tcp_output(register struct tcpcb *);
276 void tcp_setpersist(register struct tcpcb *);
279 void tcp_init(Slirp *);
280 void tcp_cleanup(Slirp *);
281 void tcp_template(struct tcpcb *);
282 void tcp_respond(struct tcpcb *, register struct tcpiphdr *,
283 register struct mbuf *, tcp_seq, tcp_seq, int, unsigned short);
284 struct tcpcb * tcp_newtcpcb(struct socket *);
285 struct tcpcb * tcp_close(register struct tcpcb *);
286 void tcp_sockclosed(struct tcpcb *);
287 int tcp_fconnect(struct socket *, unsigned short af);
288 void tcp_connect(struct socket *);
289 int tcp_attach(struct socket *);
290 uint8_t tcp_tos(struct socket *);
291 int tcp_emu(struct socket *, struct mbuf *);
292 int tcp_ctl(struct socket *);
293 struct tcpcb *tcp_drop(struct tcpcb *tp, int err);
296 #define min(x,y) ((x) < (y) ? (x) : (y))
297 #define max(x,y) ((x) > (y) ? (x) : (y))