slirp: replace QEMU_BUILD_BUG_ON with G_STATIC_ASSERT
[qemu/ar7.git] / slirp / slirp.h
blob0e4d973c2abf14d8ad4a372122ec00d57d5fa910
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 typedef char *caddr_t;
17 # include <winsock2.h>
18 # include <windows.h>
19 # include <ws2tcpip.h>
20 # include <sys/timeb.h>
21 # include <iphlpapi.h>
23 #else
24 # if !defined(__HAIKU__)
25 # define O_BINARY 0
26 # endif
27 #endif
29 #ifndef _WIN32
30 #include <sys/uio.h>
31 #include <netinet/in.h>
32 #include <arpa/inet.h>
33 #include <sys/socket.h>
34 #include <sys/ioctl.h>
35 #endif
37 #ifdef __APPLE__
38 # include <sys/filio.h>
39 #endif
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
47 #include "debug.h"
48 #include "util.h"
49 #include "qtailq.h"
51 #include "libslirp.h"
52 #include "ip.h"
53 #include "ip6.h"
54 #include "tcp.h"
55 #include "tcp_timer.h"
56 #include "tcp_var.h"
57 #include "tcpip.h"
58 #include "udp.h"
59 #include "ip_icmp.h"
60 #include "ip6_icmp.h"
61 #include "mbuf.h"
62 #include "sbuf.h"
63 #include "socket.h"
64 #include "if.h"
65 #include "main.h"
66 #include "misc.h"
68 #include "bootp.h"
69 #include "tftp.h"
71 #define ARPOP_REQUEST 1 /* ARP request */
72 #define ARPOP_REPLY 2 /* ARP reply */
74 struct ethhdr {
75 unsigned char h_dest[ETH_ALEN]; /* destination eth addr */
76 unsigned char h_source[ETH_ALEN]; /* source ether addr */
77 unsigned short h_proto; /* packet type ID field */
80 struct slirp_arphdr {
81 unsigned short ar_hrd; /* format of hardware address */
82 unsigned short ar_pro; /* format of protocol address */
83 unsigned char ar_hln; /* length of hardware address */
84 unsigned char ar_pln; /* length of protocol address */
85 unsigned short ar_op; /* ARP opcode (command) */
88 * Ethernet looks like this : This bit is variable sized however...
90 unsigned char ar_sha[ETH_ALEN]; /* sender hardware address */
91 uint32_t ar_sip; /* sender IP address */
92 unsigned char ar_tha[ETH_ALEN]; /* target hardware address */
93 uint32_t ar_tip; /* target IP address */
94 } SLIRP_PACKED;
96 #define ARP_TABLE_SIZE 16
98 typedef struct ArpTable {
99 struct slirp_arphdr table[ARP_TABLE_SIZE];
100 int next_victim;
101 } ArpTable;
103 void arp_table_add(Slirp *slirp, uint32_t ip_addr, uint8_t ethaddr[ETH_ALEN]);
105 bool arp_table_search(Slirp *slirp, uint32_t ip_addr,
106 uint8_t out_ethaddr[ETH_ALEN]);
108 struct ndpentry {
109 unsigned char eth_addr[ETH_ALEN]; /* sender hardware address */
110 struct in6_addr ip_addr; /* sender IP address */
111 } SLIRP_PACKED;
113 #define NDP_TABLE_SIZE 16
115 typedef struct NdpTable {
116 struct ndpentry table[NDP_TABLE_SIZE];
117 int next_victim;
118 } NdpTable;
120 void ndp_table_add(Slirp *slirp, struct in6_addr ip_addr,
121 uint8_t ethaddr[ETH_ALEN]);
122 bool ndp_table_search(Slirp *slirp, struct in6_addr ip_addr,
123 uint8_t out_ethaddr[ETH_ALEN]);
125 struct Slirp {
126 QTAILQ_ENTRY(Slirp) entry;
127 u_int time_fasttimo;
128 u_int last_slowtimo;
129 bool do_slowtimo;
131 bool in_enabled, in6_enabled;
133 /* virtual network configuration */
134 struct in_addr vnetwork_addr;
135 struct in_addr vnetwork_mask;
136 struct in_addr vhost_addr;
137 struct in6_addr vprefix_addr6;
138 uint8_t vprefix_len;
139 struct in6_addr vhost_addr6;
140 struct in_addr vdhcp_startaddr;
141 struct in_addr vnameserver_addr;
142 struct in6_addr vnameserver_addr6;
144 struct in_addr client_ipaddr;
145 char client_hostname[33];
147 int restricted;
148 struct gfwd_list *guestfwd_list;
150 /* mbuf states */
151 struct quehead m_freelist;
152 struct quehead m_usedlist;
153 int mbuf_alloced;
155 /* if states */
156 struct quehead if_fastq; /* fast queue (for interactive data) */
157 struct quehead if_batchq; /* queue for non-interactive data */
158 bool if_start_busy; /* avoid if_start recursion */
160 /* ip states */
161 struct ipq ipq; /* ip reass. queue */
162 uint16_t ip_id; /* ip packet ctr, for ids */
164 /* bootp/dhcp states */
165 BOOTPClient bootp_clients[NB_BOOTP_CLIENTS];
166 char *bootp_filename;
167 size_t vdnssearch_len;
168 uint8_t *vdnssearch;
169 char *vdomainname;
171 /* tcp states */
172 struct socket tcb;
173 struct socket *tcp_last_so;
174 tcp_seq tcp_iss; /* tcp initial send seq # */
175 uint32_t tcp_now; /* for RFC 1323 timestamps */
177 /* udp states */
178 struct socket udb;
179 struct socket *udp_last_so;
181 /* icmp states */
182 struct socket icmp;
183 struct socket *icmp_last_so;
185 /* tftp states */
186 char *tftp_prefix;
187 struct tftp_session tftp_sessions[TFTP_SESSIONS_MAX];
188 char *tftp_server_name;
190 ArpTable arp_table;
191 NdpTable ndp_table;
193 GRand *grand;
194 void *ra_timer;
196 const SlirpCb *cb;
197 void *opaque;
200 void if_start(Slirp *);
202 int get_dns_addr(struct in_addr *pdns_addr);
203 int get_dns6_addr(struct in6_addr *pdns6_addr, uint32_t *scope_id);
205 /* ncsi.c */
206 void ncsi_input(Slirp *slirp, const uint8_t *pkt, int pkt_len);
208 #ifndef _WIN32
209 #include <netdb.h>
210 #endif
213 extern bool slirp_do_keepalive;
215 #define TCP_MAXIDLE (TCPTV_KEEPCNT * TCPTV_KEEPINTVL)
217 /* dnssearch.c */
218 int translate_dnssearch(Slirp *s, const char ** names);
220 /* cksum.c */
221 int cksum(struct mbuf *m, int len);
222 int ip6_cksum(struct mbuf *m);
224 /* if.c */
225 void if_init(Slirp *);
226 void if_output(struct socket *, struct mbuf *);
228 /* ip_input.c */
229 void ip_init(Slirp *);
230 void ip_cleanup(Slirp *);
231 void ip_input(struct mbuf *);
232 void ip_slowtimo(Slirp *);
233 void ip_stripoptions(register struct mbuf *, struct mbuf *);
235 /* ip_output.c */
236 int ip_output(struct socket *, struct mbuf *);
238 /* ip6_input.c */
239 void ip6_init(Slirp *);
240 void ip6_cleanup(Slirp *);
241 void ip6_input(struct mbuf *);
243 /* ip6_output */
244 int ip6_output(struct socket *, struct mbuf *, int fast);
246 /* tcp_input.c */
247 void tcp_input(register struct mbuf *, int, struct socket *, unsigned short af);
248 int tcp_mss(register struct tcpcb *, u_int);
250 /* tcp_output.c */
251 int tcp_output(register struct tcpcb *);
252 void tcp_setpersist(register struct tcpcb *);
254 /* tcp_subr.c */
255 void tcp_init(Slirp *);
256 void tcp_cleanup(Slirp *);
257 void tcp_template(struct tcpcb *);
258 void tcp_respond(struct tcpcb *, register struct tcpiphdr *,
259 register struct mbuf *, tcp_seq, tcp_seq, int, unsigned short);
260 struct tcpcb * tcp_newtcpcb(struct socket *);
261 struct tcpcb * tcp_close(register struct tcpcb *);
262 void tcp_sockclosed(struct tcpcb *);
263 int tcp_fconnect(struct socket *, unsigned short af);
264 void tcp_connect(struct socket *);
265 int tcp_attach(struct socket *);
266 uint8_t tcp_tos(struct socket *);
267 int tcp_emu(struct socket *, struct mbuf *);
268 int tcp_ctl(struct socket *);
269 struct tcpcb *tcp_drop(struct tcpcb *tp, int err);
271 struct socket *
272 slirp_find_ctl_socket(Slirp *slirp, struct in_addr guest_addr, int guest_port);
274 #endif