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