10 # include <ws2tcpip.h>
11 # include <sys/timeb.h>
12 # include <iphlpapi.h>
15 # if !defined(__HAIKU__)
25 #include <netinet/in.h>
26 #include <arpa/inet.h>
30 #include <sys/socket.h>
34 # include <sys/ioctl.h>
38 # include <sys/filio.h>
41 /* Avoid conflicting with the libc insque() and remque(), which
42 have different prototypes. */
43 #define insque slirp_insque
44 #define remque slirp_remque
45 #define quehead slirp_quehead
49 #include "qemu/queue.h"
50 #include "qemu/sockets.h"
57 #include "tcp_timer.h"
73 #define ARPOP_REQUEST 1 /* ARP request */
74 #define ARPOP_REPLY 2 /* ARP reply */
77 unsigned char h_dest
[ETH_ALEN
]; /* destination eth addr */
78 unsigned char h_source
[ETH_ALEN
]; /* source ether addr */
79 unsigned short h_proto
; /* packet type ID field */
83 unsigned short ar_hrd
; /* format of hardware address */
84 unsigned short ar_pro
; /* format of protocol address */
85 unsigned char ar_hln
; /* length of hardware address */
86 unsigned char ar_pln
; /* length of protocol address */
87 unsigned short ar_op
; /* ARP opcode (command) */
90 * Ethernet looks like this : This bit is variable sized however...
92 unsigned char ar_sha
[ETH_ALEN
]; /* sender hardware address */
93 uint32_t ar_sip
; /* sender IP address */
94 unsigned char ar_tha
[ETH_ALEN
]; /* target hardware address */
95 uint32_t ar_tip
; /* target IP address */
98 #define ARP_TABLE_SIZE 16
100 typedef struct ArpTable
{
101 struct slirp_arphdr table
[ARP_TABLE_SIZE
];
105 void arp_table_add(Slirp
*slirp
, uint32_t ip_addr
, uint8_t ethaddr
[ETH_ALEN
]);
107 bool arp_table_search(Slirp
*slirp
, uint32_t ip_addr
,
108 uint8_t out_ethaddr
[ETH_ALEN
]);
111 unsigned char eth_addr
[ETH_ALEN
]; /* sender hardware address */
112 struct in6_addr ip_addr
; /* sender IP address */
115 #define NDP_TABLE_SIZE 16
117 typedef struct NdpTable
{
118 struct ndpentry table
[NDP_TABLE_SIZE
];
122 void ndp_table_add(Slirp
*slirp
, struct in6_addr ip_addr
,
123 uint8_t ethaddr
[ETH_ALEN
]);
124 bool ndp_table_search(Slirp
*slirp
, struct in6_addr ip_addr
,
125 uint8_t out_ethaddr
[ETH_ALEN
]);
128 QTAILQ_ENTRY(Slirp
) entry
;
133 bool in_enabled
, in6_enabled
;
135 /* virtual network configuration */
136 struct in_addr vnetwork_addr
;
137 struct in_addr vnetwork_mask
;
138 struct in_addr vhost_addr
;
139 struct in6_addr vprefix_addr6
;
141 struct in6_addr vhost_addr6
;
142 struct in_addr vdhcp_startaddr
;
143 struct in_addr vnameserver_addr
;
144 struct in6_addr vnameserver_addr6
;
146 struct in_addr client_ipaddr
;
147 char client_hostname
[33];
150 struct gfwd_list
*guestfwd_list
;
153 struct quehead m_freelist
;
154 struct quehead m_usedlist
;
158 struct quehead if_fastq
; /* fast queue (for interactive data) */
159 struct quehead if_batchq
; /* queue for non-interactive data */
160 bool if_start_busy
; /* avoid if_start recursion */
163 struct ipq ipq
; /* ip reass. queue */
164 uint16_t ip_id
; /* ip packet ctr, for ids */
166 /* bootp/dhcp states */
167 BOOTPClient bootp_clients
[NB_BOOTP_CLIENTS
];
168 char *bootp_filename
;
169 size_t vdnssearch_len
;
175 struct socket
*tcp_last_so
;
176 tcp_seq tcp_iss
; /* tcp initial send seq # */
177 uint32_t tcp_now
; /* for RFC 1323 timestamps */
181 struct socket
*udp_last_so
;
185 struct socket
*icmp_last_so
;
189 struct tftp_session tftp_sessions
[TFTP_SESSIONS_MAX
];
190 char *tftp_server_name
;
202 void if_start(Slirp
*);
204 int get_dns_addr(struct in_addr
*pdns_addr
);
205 int get_dns6_addr(struct in6_addr
*pdns6_addr
, uint32_t *scope_id
);
208 void ncsi_input(Slirp
*slirp
, const uint8_t *pkt
, int pkt_len
);
215 extern bool slirp_do_keepalive
;
217 #define TCP_MAXIDLE (TCPTV_KEEPCNT * TCPTV_KEEPINTVL)
220 int translate_dnssearch(Slirp
*s
, const char ** names
);
223 int cksum(struct mbuf
*m
, int len
);
224 int ip6_cksum(struct mbuf
*m
);
227 void if_init(Slirp
*);
228 void if_output(struct socket
*, struct mbuf
*);
231 void ip_init(Slirp
*);
232 void ip_cleanup(Slirp
*);
233 void ip_input(struct mbuf
*);
234 void ip_slowtimo(Slirp
*);
235 void ip_stripoptions(register struct mbuf
*, struct mbuf
*);
238 int ip_output(struct socket
*, struct mbuf
*);
241 void ip6_init(Slirp
*);
242 void ip6_cleanup(Slirp
*);
243 void ip6_input(struct mbuf
*);
246 int ip6_output(struct socket
*, struct mbuf
*, int fast
);
249 void tcp_input(register struct mbuf
*, int, struct socket
*, unsigned short af
);
250 int tcp_mss(register struct tcpcb
*, u_int
);
253 int tcp_output(register struct tcpcb
*);
254 void tcp_setpersist(register struct tcpcb
*);
257 void tcp_init(Slirp
*);
258 void tcp_cleanup(Slirp
*);
259 void tcp_template(struct tcpcb
*);
260 void tcp_respond(struct tcpcb
*, register struct tcpiphdr
*,
261 register struct mbuf
*, tcp_seq
, tcp_seq
, int, unsigned short);
262 struct tcpcb
* tcp_newtcpcb(struct socket
*);
263 struct tcpcb
* tcp_close(register struct tcpcb
*);
264 void tcp_sockclosed(struct tcpcb
*);
265 int tcp_fconnect(struct socket
*, unsigned short af
);
266 void tcp_connect(struct socket
*);
267 int tcp_attach(struct socket
*);
268 uint8_t tcp_tos(struct socket
*);
269 int tcp_emu(struct socket
*, struct mbuf
*);
270 int tcp_ctl(struct socket
*);
271 struct tcpcb
*tcp_drop(struct tcpcb
*tp
, int err
);