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