]>
Commit | Line | Data |
---|---|---|
121d0712 MA |
1 | #ifndef SLIRP_H |
2 | #define SLIRP_H | |
f0cbd3ec | 3 | |
f0cbd3ec FB |
4 | #include "slirp_config.h" |
5 | ||
379ff53d | 6 | #ifdef _WIN32 |
379ff53d | 7 | |
379ff53d FB |
8 | typedef char *caddr_t; |
9 | ||
34444131 | 10 | # include <windows.h> |
379ff53d | 11 | # include <winsock2.h> |
116842ee | 12 | # include <ws2tcpip.h> |
379ff53d FB |
13 | # include <sys/timeb.h> |
14 | # include <iphlpapi.h> | |
15 | ||
379ff53d | 16 | #else |
4a2b39d3 AF |
17 | # if !defined(__HAIKU__) |
18 | # define O_BINARY 0 | |
19 | # endif | |
379ff53d FB |
20 | #endif |
21 | ||
f0cbd3ec FB |
22 | #ifdef HAVE_SYS_BITYPES_H |
23 | # include <sys/bitypes.h> | |
24 | #endif | |
25 | ||
379ff53d | 26 | #ifndef _WIN32 |
f0cbd3ec | 27 | #include <sys/uio.h> |
379ff53d | 28 | #endif |
f0cbd3ec | 29 | |
379ff53d | 30 | #ifndef _WIN32 |
f0cbd3ec FB |
31 | #include <netinet/in.h> |
32 | #include <arpa/inet.h> | |
379ff53d | 33 | #endif |
f0cbd3ec | 34 | |
f0cbd3ec FB |
35 | #ifndef NO_UNIX_SOCKETS |
36 | #include <sys/un.h> | |
37 | #endif | |
f0cbd3ec FB |
38 | #ifdef HAVE_SYS_SIGNAL_H |
39 | # include <sys/signal.h> | |
40 | #endif | |
379ff53d | 41 | #ifndef _WIN32 |
f0cbd3ec | 42 | #include <sys/socket.h> |
379ff53d | 43 | #endif |
f0cbd3ec | 44 | |
ee2654ac | 45 | #if defined(HAVE_SYS_IOCTL_H) |
f0cbd3ec | 46 | # include <sys/ioctl.h> |
f0cbd3ec FB |
47 | #endif |
48 | ||
f0cbd3ec FB |
49 | #ifdef HAVE_SYS_SELECT_H |
50 | # include <sys/select.h> | |
51 | #endif | |
52 | ||
53 | #ifdef HAVE_SYS_WAIT_H | |
54 | # include <sys/wait.h> | |
55 | #endif | |
56 | ||
57 | #ifdef HAVE_SYS_FILIO_H | |
58 | # include <sys/filio.h> | |
59 | #endif | |
60 | ||
f0cbd3ec FB |
61 | /* Avoid conflicting with the libc insque() and remque(), which |
62 | have different prototypes. */ | |
63 | #define insque slirp_insque | |
64 | #define remque slirp_remque | |
67e3eee4 | 65 | #define quehead slirp_quehead |
f0cbd3ec FB |
66 | |
67 | #ifdef HAVE_SYS_STROPTS_H | |
68 | #include <sys/stropts.h> | |
69 | #endif | |
70 | ||
0d6ff71a | 71 | |
f0cbd3ec FB |
72 | #include "debug.h" |
73 | ||
1de7afc9 PB |
74 | #include "qemu/queue.h" |
75 | #include "qemu/sockets.h" | |
9c7ffe26 | 76 | #include "net/eth.h" |
b1c99fcd | 77 | |
460fec67 | 78 | #include "libslirp.h" |
f0cbd3ec | 79 | #include "ip.h" |
0d6ff71a | 80 | #include "ip6.h" |
f0cbd3ec FB |
81 | #include "tcp.h" |
82 | #include "tcp_timer.h" | |
83 | #include "tcp_var.h" | |
84 | #include "tcpip.h" | |
85 | #include "udp.h" | |
e6d43cfb | 86 | #include "ip_icmp.h" |
0d6ff71a | 87 | #include "ip6_icmp.h" |
f0cbd3ec FB |
88 | #include "mbuf.h" |
89 | #include "sbuf.h" | |
90 | #include "socket.h" | |
91 | #include "if.h" | |
92 | #include "main.h" | |
93 | #include "misc.h" | |
f0cbd3ec FB |
94 | |
95 | #include "bootp.h" | |
c7f74643 | 96 | #include "tftp.h" |
460fec67 | 97 | |
1a0ca1e1 FC |
98 | #define ARPOP_REQUEST 1 /* ARP request */ |
99 | #define ARPOP_REPLY 2 /* ARP reply */ | |
100 | ||
101 | struct ethhdr { | |
102 | unsigned char h_dest[ETH_ALEN]; /* destination eth addr */ | |
103 | unsigned char h_source[ETH_ALEN]; /* source ether addr */ | |
104 | unsigned short h_proto; /* packet type ID field */ | |
105 | }; | |
106 | ||
1f8b56e7 | 107 | struct slirp_arphdr { |
1a0ca1e1 FC |
108 | unsigned short ar_hrd; /* format of hardware address */ |
109 | unsigned short ar_pro; /* format of protocol address */ | |
110 | unsigned char ar_hln; /* length of hardware address */ | |
111 | unsigned char ar_pln; /* length of protocol address */ | |
112 | unsigned short ar_op; /* ARP opcode (command) */ | |
113 | ||
114 | /* | |
115 | * Ethernet looks like this : This bit is variable sized however... | |
116 | */ | |
117 | unsigned char ar_sha[ETH_ALEN]; /* sender hardware address */ | |
118 | uint32_t ar_sip; /* sender IP address */ | |
119 | unsigned char ar_tha[ETH_ALEN]; /* target hardware address */ | |
120 | uint32_t ar_tip; /* target IP address */ | |
541dc0d4 | 121 | } QEMU_PACKED; |
1a0ca1e1 FC |
122 | |
123 | #define ARP_TABLE_SIZE 16 | |
124 | ||
125 | typedef struct ArpTable { | |
1f8b56e7 | 126 | struct slirp_arphdr table[ARP_TABLE_SIZE]; |
1a0ca1e1 FC |
127 | int next_victim; |
128 | } ArpTable; | |
129 | ||
5a371a2e | 130 | void arp_table_add(Slirp *slirp, uint32_t ip_addr, uint8_t ethaddr[ETH_ALEN]); |
1a0ca1e1 | 131 | |
5a371a2e | 132 | bool arp_table_search(Slirp *slirp, uint32_t ip_addr, |
1a0ca1e1 | 133 | uint8_t out_ethaddr[ETH_ALEN]); |
40ff6d7e | 134 | |
0d6ff71a GS |
135 | struct ndpentry { |
136 | unsigned char eth_addr[ETH_ALEN]; /* sender hardware address */ | |
137 | struct in6_addr ip_addr; /* sender IP address */ | |
138 | } QEMU_PACKED; | |
139 | ||
140 | #define NDP_TABLE_SIZE 16 | |
141 | ||
142 | typedef struct NdpTable { | |
143 | struct ndpentry table[NDP_TABLE_SIZE]; | |
144 | int next_victim; | |
145 | } NdpTable; | |
146 | ||
147 | void ndp_table_add(Slirp *slirp, struct in6_addr ip_addr, | |
148 | uint8_t ethaddr[ETH_ALEN]); | |
149 | bool ndp_table_search(Slirp *slirp, struct in6_addr ip_addr, | |
150 | uint8_t out_ethaddr[ETH_ALEN]); | |
151 | ||
460fec67 | 152 | struct Slirp { |
72cf2d4f | 153 | QTAILQ_ENTRY(Slirp) entry; |
fe0ff43c LPF |
154 | u_int time_fasttimo; |
155 | u_int last_slowtimo; | |
156 | bool do_slowtimo; | |
b1c99fcd | 157 | |
0b11c036 ST |
158 | bool in_enabled, in6_enabled; |
159 | ||
460fec67 JK |
160 | /* virtual network configuration */ |
161 | struct in_addr vnetwork_addr; | |
162 | struct in_addr vnetwork_mask; | |
163 | struct in_addr vhost_addr; | |
0d6ff71a GS |
164 | struct in6_addr vprefix_addr6; |
165 | uint8_t vprefix_len; | |
166 | struct in6_addr vhost_addr6; | |
460fec67 JK |
167 | struct in_addr vdhcp_startaddr; |
168 | struct in_addr vnameserver_addr; | |
05061d85 | 169 | struct in6_addr vnameserver_addr6; |
460fec67 | 170 | |
460fec67 JK |
171 | struct in_addr client_ipaddr; |
172 | char client_hostname[33]; | |
173 | ||
174 | int restricted; | |
460fec67 JK |
175 | struct ex_list *exec_list; |
176 | ||
177 | /* mbuf states */ | |
67e3eee4 ST |
178 | struct quehead m_freelist; |
179 | struct quehead m_usedlist; | |
460fec67 JK |
180 | int mbuf_alloced; |
181 | ||
182 | /* if states */ | |
67e3eee4 ST |
183 | struct quehead if_fastq; /* fast queue (for interactive data) */ |
184 | struct quehead if_batchq; /* queue for non-interactive data */ | |
953e7f54 | 185 | bool if_start_busy; /* avoid if_start recursion */ |
460fec67 JK |
186 | |
187 | /* ip states */ | |
188 | struct ipq ipq; /* ip reass. queue */ | |
b6dce92e | 189 | uint16_t ip_id; /* ip packet ctr, for ids */ |
460fec67 JK |
190 | |
191 | /* bootp/dhcp states */ | |
192 | BOOTPClient bootp_clients[NB_BOOTP_CLIENTS]; | |
193 | char *bootp_filename; | |
63d2960b KS |
194 | size_t vdnssearch_len; |
195 | uint8_t *vdnssearch; | |
f18d1375 | 196 | char *vdomainname; |
460fec67 JK |
197 | |
198 | /* tcp states */ | |
199 | struct socket tcb; | |
200 | struct socket *tcp_last_so; | |
201 | tcp_seq tcp_iss; /* tcp initial send seq # */ | |
b6dce92e | 202 | uint32_t tcp_now; /* for RFC 1323 timestamps */ |
460fec67 JK |
203 | |
204 | /* udp states */ | |
205 | struct socket udb; | |
206 | struct socket *udp_last_so; | |
207 | ||
e6d43cfb JK |
208 | /* icmp states */ |
209 | struct socket icmp; | |
210 | struct socket *icmp_last_so; | |
211 | ||
460fec67 JK |
212 | /* tftp states */ |
213 | char *tftp_prefix; | |
214 | struct tftp_session tftp_sessions[TFTP_SESSIONS_MAX]; | |
215 | ||
1a0ca1e1 | 216 | ArpTable arp_table; |
0d6ff71a GS |
217 | NdpTable ndp_table; |
218 | ||
219 | GRand *grand; | |
220 | QEMUTimer *ra_timer; | |
1a0ca1e1 | 221 | |
9f8bd042 | 222 | void *opaque; |
460fec67 JK |
223 | }; |
224 | ||
ad0d8c4c | 225 | extern Slirp *slirp_instance; |
f0cbd3ec | 226 | |
f0cbd3ec FB |
227 | #ifndef NULL |
228 | #define NULL (void *)0 | |
229 | #endif | |
230 | ||
6cb9c6d3 | 231 | void if_start(Slirp *); |
f0cbd3ec | 232 | |
47bb83ca CLG |
233 | /* ncsi.c */ |
234 | void ncsi_input(Slirp *slirp, const uint8_t *pkt, int pkt_len); | |
235 | ||
379ff53d | 236 | #ifndef _WIN32 |
f0cbd3ec | 237 | #include <netdb.h> |
379ff53d | 238 | #endif |
f0cbd3ec | 239 | |
9634d903 BS |
240 | #define SO_OPTIONS DO_KEEPALIVE |
241 | #define TCP_MAXIDLE (TCPTV_KEEPCNT * TCPTV_KEEPINTVL) | |
242 | ||
63d2960b KS |
243 | /* dnssearch.c */ |
244 | int translate_dnssearch(Slirp *s, const char ** names); | |
245 | ||
f0cbd3ec FB |
246 | /* cksum.c */ |
247 | int cksum(struct mbuf *m, int len); | |
0d6ff71a | 248 | int ip6_cksum(struct mbuf *m); |
f0cbd3ec FB |
249 | |
250 | /* if.c */ | |
6cb9c6d3 BS |
251 | void if_init(Slirp *); |
252 | void if_output(struct socket *, struct mbuf *); | |
f0cbd3ec FB |
253 | |
254 | /* ip_input.c */ | |
6cb9c6d3 | 255 | void ip_init(Slirp *); |
a68adc22 | 256 | void ip_cleanup(Slirp *); |
6cb9c6d3 BS |
257 | void ip_input(struct mbuf *); |
258 | void ip_slowtimo(Slirp *); | |
259 | void ip_stripoptions(register struct mbuf *, struct mbuf *); | |
f0cbd3ec FB |
260 | |
261 | /* ip_output.c */ | |
6cb9c6d3 | 262 | int ip_output(struct socket *, struct mbuf *); |
f0cbd3ec | 263 | |
0d6ff71a GS |
264 | /* ip6_input.c */ |
265 | void ip6_init(Slirp *); | |
266 | void ip6_cleanup(Slirp *); | |
267 | void ip6_input(struct mbuf *); | |
268 | ||
269 | /* ip6_output */ | |
270 | int ip6_output(struct socket *, struct mbuf *, int fast); | |
271 | ||
f0cbd3ec | 272 | /* tcp_input.c */ |
9dfbf250 | 273 | void tcp_input(register struct mbuf *, int, struct socket *, unsigned short af); |
6cb9c6d3 | 274 | int tcp_mss(register struct tcpcb *, u_int); |
f0cbd3ec FB |
275 | |
276 | /* tcp_output.c */ | |
6cb9c6d3 BS |
277 | int tcp_output(register struct tcpcb *); |
278 | void tcp_setpersist(register struct tcpcb *); | |
f0cbd3ec FB |
279 | |
280 | /* tcp_subr.c */ | |
6cb9c6d3 | 281 | void tcp_init(Slirp *); |
a68adc22 | 282 | void tcp_cleanup(Slirp *); |
6cb9c6d3 | 283 | void tcp_template(struct tcpcb *); |
9dfbf250 GS |
284 | void tcp_respond(struct tcpcb *, register struct tcpiphdr *, |
285 | register struct mbuf *, tcp_seq, tcp_seq, int, unsigned short); | |
6cb9c6d3 BS |
286 | struct tcpcb * tcp_newtcpcb(struct socket *); |
287 | struct tcpcb * tcp_close(register struct tcpcb *); | |
288 | void tcp_sockclosed(struct tcpcb *); | |
cc573a69 | 289 | int tcp_fconnect(struct socket *, unsigned short af); |
6cb9c6d3 BS |
290 | void tcp_connect(struct socket *); |
291 | int tcp_attach(struct socket *); | |
b6dce92e | 292 | uint8_t tcp_tos(struct socket *); |
6cb9c6d3 BS |
293 | int tcp_emu(struct socket *, struct mbuf *); |
294 | int tcp_ctl(struct socket *); | |
9fafc9ea | 295 | struct tcpcb *tcp_drop(struct tcpcb *tp, int err); |
f0cbd3ec | 296 | |
f0cbd3ec | 297 | #endif |