scripts/qemu.py: log QEMU launch command line
[qemu/ar7.git] / slirp / slirp.h
blob752a4cd8c81c687bfb45269637a21f7123f56a57
1 #ifndef SLIRP_H
2 #define SLIRP_H
4 #ifdef _WIN32
6 /* as defined in sdkddkver.h */
7 #ifndef _WIN32_WINNT
8 #define _WIN32_WINNT 0x0600 /* Vista */
9 #endif
10 /* reduces the number of implicitly included headers */
11 #ifndef WIN32_LEAN_AND_MEAN
12 #define WIN32_LEAN_AND_MEAN
13 #endif
15 # include <winsock2.h>
16 # include <windows.h>
17 # include <ws2tcpip.h>
18 # include <sys/timeb.h>
19 # include <iphlpapi.h>
21 #else
22 # if !defined(__HAIKU__)
23 # define O_BINARY 0
24 # endif
25 #endif
27 #ifndef _WIN32
28 #include <sys/uio.h>
29 #include <netinet/in.h>
30 #include <arpa/inet.h>
31 #include <sys/socket.h>
32 #include <sys/ioctl.h>
33 #endif
35 #ifdef __APPLE__
36 # include <sys/filio.h>
37 #endif
39 /* Avoid conflicting with the libc insque() and remque(), which
40 have different prototypes. */
41 #define insque slirp_insque
42 #define remque slirp_remque
43 #define quehead slirp_quehead
45 #include "debug.h"
46 #include "util.h"
47 #include "qtailq.h"
49 #include "libslirp.h"
50 #include "ip.h"
51 #include "ip6.h"
52 #include "tcp.h"
53 #include "tcp_timer.h"
54 #include "tcp_var.h"
55 #include "tcpip.h"
56 #include "udp.h"
57 #include "ip_icmp.h"
58 #include "ip6_icmp.h"
59 #include "mbuf.h"
60 #include "sbuf.h"
61 #include "socket.h"
62 #include "if.h"
63 #include "main.h"
64 #include "misc.h"
66 #include "bootp.h"
67 #include "tftp.h"
69 #define ARPOP_REQUEST 1 /* ARP request */
70 #define ARPOP_REPLY 2 /* ARP reply */
72 struct ethhdr {
73 unsigned char h_dest[ETH_ALEN]; /* destination eth addr */
74 unsigned char h_source[ETH_ALEN]; /* source ether addr */
75 unsigned short h_proto; /* packet type ID field */
78 struct slirp_arphdr {
79 unsigned short ar_hrd; /* format of hardware address */
80 unsigned short ar_pro; /* format of protocol address */
81 unsigned char ar_hln; /* length of hardware address */
82 unsigned char ar_pln; /* length of protocol address */
83 unsigned short ar_op; /* ARP opcode (command) */
86 * Ethernet looks like this : This bit is variable sized however...
88 unsigned char ar_sha[ETH_ALEN]; /* sender hardware address */
89 uint32_t ar_sip; /* sender IP address */
90 unsigned char ar_tha[ETH_ALEN]; /* target hardware address */
91 uint32_t ar_tip; /* target IP address */
92 } SLIRP_PACKED;
94 #define ARP_TABLE_SIZE 16
96 typedef struct ArpTable {
97 struct slirp_arphdr table[ARP_TABLE_SIZE];
98 int next_victim;
99 } ArpTable;
101 void arp_table_add(Slirp *slirp, uint32_t ip_addr, uint8_t ethaddr[ETH_ALEN]);
103 bool arp_table_search(Slirp *slirp, uint32_t ip_addr,
104 uint8_t out_ethaddr[ETH_ALEN]);
106 struct ndpentry {
107 unsigned char eth_addr[ETH_ALEN]; /* sender hardware address */
108 struct in6_addr ip_addr; /* sender IP address */
109 } SLIRP_PACKED;
111 #define NDP_TABLE_SIZE 16
113 typedef struct NdpTable {
114 struct ndpentry table[NDP_TABLE_SIZE];
115 int next_victim;
116 } NdpTable;
118 void ndp_table_add(Slirp *slirp, struct in6_addr ip_addr,
119 uint8_t ethaddr[ETH_ALEN]);
120 bool ndp_table_search(Slirp *slirp, struct in6_addr ip_addr,
121 uint8_t out_ethaddr[ETH_ALEN]);
123 struct Slirp {
124 QTAILQ_ENTRY(Slirp) entry;
125 unsigned time_fasttimo;
126 unsigned last_slowtimo;
127 bool do_slowtimo;
129 bool in_enabled, in6_enabled;
131 /* virtual network configuration */
132 struct in_addr vnetwork_addr;
133 struct in_addr vnetwork_mask;
134 struct in_addr vhost_addr;
135 struct in6_addr vprefix_addr6;
136 uint8_t vprefix_len;
137 struct in6_addr vhost_addr6;
138 struct in_addr vdhcp_startaddr;
139 struct in_addr vnameserver_addr;
140 struct in6_addr vnameserver_addr6;
142 struct in_addr client_ipaddr;
143 char client_hostname[33];
145 int restricted;
146 struct gfwd_list *guestfwd_list;
148 /* mbuf states */
149 struct quehead m_freelist;
150 struct quehead m_usedlist;
151 int mbuf_alloced;
153 /* if states */
154 struct quehead if_fastq; /* fast queue (for interactive data) */
155 struct quehead if_batchq; /* queue for non-interactive data */
156 bool if_start_busy; /* avoid if_start recursion */
158 /* ip states */
159 struct ipq ipq; /* ip reass. queue */
160 uint16_t ip_id; /* ip packet ctr, for ids */
162 /* bootp/dhcp states */
163 BOOTPClient bootp_clients[NB_BOOTP_CLIENTS];
164 char *bootp_filename;
165 size_t vdnssearch_len;
166 uint8_t *vdnssearch;
167 char *vdomainname;
169 /* tcp states */
170 struct socket tcb;
171 struct socket *tcp_last_so;
172 tcp_seq tcp_iss; /* tcp initial send seq # */
173 uint32_t tcp_now; /* for RFC 1323 timestamps */
175 /* udp states */
176 struct socket udb;
177 struct socket *udp_last_so;
179 /* icmp states */
180 struct socket icmp;
181 struct socket *icmp_last_so;
183 /* tftp states */
184 char *tftp_prefix;
185 struct tftp_session tftp_sessions[TFTP_SESSIONS_MAX];
186 char *tftp_server_name;
188 ArpTable arp_table;
189 NdpTable ndp_table;
191 GRand *grand;
192 void *ra_timer;
194 const SlirpCb *cb;
195 void *opaque;
198 void if_start(Slirp *);
200 int get_dns_addr(struct in_addr *pdns_addr);
201 int get_dns6_addr(struct in6_addr *pdns6_addr, uint32_t *scope_id);
203 /* ncsi.c */
204 void ncsi_input(Slirp *slirp, const uint8_t *pkt, int pkt_len);
206 #ifndef _WIN32
207 #include <netdb.h>
208 #endif
211 extern bool slirp_do_keepalive;
213 #define TCP_MAXIDLE (TCPTV_KEEPCNT * TCPTV_KEEPINTVL)
215 /* dnssearch.c */
216 int translate_dnssearch(Slirp *s, const char ** names);
218 /* cksum.c */
219 int cksum(struct mbuf *m, int len);
220 int ip6_cksum(struct mbuf *m);
222 /* if.c */
223 void if_init(Slirp *);
224 void if_output(struct socket *, struct mbuf *);
226 /* ip_input.c */
227 void ip_init(Slirp *);
228 void ip_cleanup(Slirp *);
229 void ip_input(struct mbuf *);
230 void ip_slowtimo(Slirp *);
231 void ip_stripoptions(register struct mbuf *, struct mbuf *);
233 /* ip_output.c */
234 int ip_output(struct socket *, struct mbuf *);
236 /* ip6_input.c */
237 void ip6_init(Slirp *);
238 void ip6_cleanup(Slirp *);
239 void ip6_input(struct mbuf *);
241 /* ip6_output */
242 int ip6_output(struct socket *, struct mbuf *, int fast);
244 /* tcp_input.c */
245 void tcp_input(register struct mbuf *, int, struct socket *, unsigned short af);
246 int tcp_mss(register struct tcpcb *, unsigned);
248 /* tcp_output.c */
249 int tcp_output(register struct tcpcb *);
250 void tcp_setpersist(register struct tcpcb *);
252 /* tcp_subr.c */
253 void tcp_init(Slirp *);
254 void tcp_cleanup(Slirp *);
255 void tcp_template(struct tcpcb *);
256 void tcp_respond(struct tcpcb *, register struct tcpiphdr *,
257 register struct mbuf *, tcp_seq, tcp_seq, int, unsigned short);
258 struct tcpcb * tcp_newtcpcb(struct socket *);
259 struct tcpcb * tcp_close(register struct tcpcb *);
260 void tcp_sockclosed(struct tcpcb *);
261 int tcp_fconnect(struct socket *, unsigned short af);
262 void tcp_connect(struct socket *);
263 int tcp_attach(struct socket *);
264 uint8_t tcp_tos(struct socket *);
265 int tcp_emu(struct socket *, struct mbuf *);
266 int tcp_ctl(struct socket *);
267 struct tcpcb *tcp_drop(struct tcpcb *tp, int err);
269 struct socket *
270 slirp_find_ctl_socket(Slirp *slirp, struct in_addr guest_addr, int guest_port);
272 void slirp_send_packet_all(Slirp *slirp, const void *buf, size_t len);
274 #endif