1
2#ifndef SLIRP_H
3#define SLIRP_H
4
5#ifdef _WIN32
6
7
8#ifndef _WIN32_WINNT
9#define _WIN32_WINNT 0x0600
10#endif
11
12#ifndef WIN32_LEAN_AND_MEAN
13#define WIN32_LEAN_AND_MEAN
14#endif
15
16# include <winsock2.h>
17# include <windows.h>
18# include <ws2tcpip.h>
19# include <sys/timeb.h>
20# include <iphlpapi.h>
21
22#else
23# if !defined(__HAIKU__)
24# define O_BINARY 0
25# endif
26#endif
27
28#ifndef _WIN32
29#include <sys/uio.h>
30#include <netinet/in.h>
31#include <arpa/inet.h>
32#include <sys/socket.h>
33#include <sys/ioctl.h>
34#endif
35
36#ifdef __APPLE__
37# include <sys/filio.h>
38#endif
39
40
41
42#define insque slirp_insque
43#define remque slirp_remque
44#define quehead slirp_quehead
45
46#include "debug.h"
47#include "util.h"
48#include "qtailq.h"
49
50#include "libslirp.h"
51#include "ip.h"
52#include "ip6.h"
53#include "tcp.h"
54#include "tcp_timer.h"
55#include "tcp_var.h"
56#include "tcpip.h"
57#include "udp.h"
58#include "ip_icmp.h"
59#include "ip6_icmp.h"
60#include "mbuf.h"
61#include "sbuf.h"
62#include "socket.h"
63#include "if.h"
64#include "main.h"
65#include "misc.h"
66
67#include "bootp.h"
68#include "tftp.h"
69
70#define ARPOP_REQUEST 1
71#define ARPOP_REPLY 2
72
73struct ethhdr {
74 unsigned char h_dest[ETH_ALEN];
75 unsigned char h_source[ETH_ALEN];
76 unsigned short h_proto;
77};
78
79struct slirp_arphdr {
80 unsigned short ar_hrd;
81 unsigned short ar_pro;
82 unsigned char ar_hln;
83 unsigned char ar_pln;
84 unsigned short ar_op;
85
86
87
88
89 unsigned char ar_sha[ETH_ALEN];
90 uint32_t ar_sip;
91 unsigned char ar_tha[ETH_ALEN];
92 uint32_t ar_tip;
93} SLIRP_PACKED;
94
95#define ARP_TABLE_SIZE 16
96
97typedef struct ArpTable {
98 struct slirp_arphdr table[ARP_TABLE_SIZE];
99 int next_victim;
100} ArpTable;
101
102void arp_table_add(Slirp *slirp, uint32_t ip_addr, uint8_t ethaddr[ETH_ALEN]);
103
104bool arp_table_search(Slirp *slirp, uint32_t ip_addr,
105 uint8_t out_ethaddr[ETH_ALEN]);
106
107struct ndpentry {
108 unsigned char eth_addr[ETH_ALEN];
109 struct in6_addr ip_addr;
110};
111
112#define NDP_TABLE_SIZE 16
113
114typedef struct NdpTable {
115 struct ndpentry table[NDP_TABLE_SIZE];
116 int next_victim;
117} NdpTable;
118
119void ndp_table_add(Slirp *slirp, struct in6_addr ip_addr,
120 uint8_t ethaddr[ETH_ALEN]);
121bool ndp_table_search(Slirp *slirp, struct in6_addr ip_addr,
122 uint8_t out_ethaddr[ETH_ALEN]);
123
124struct Slirp {
125 QTAILQ_ENTRY(Slirp) entry;
126 unsigned time_fasttimo;
127 unsigned last_slowtimo;
128 bool do_slowtimo;
129
130 bool in_enabled, in6_enabled;
131
132
133 struct in_addr vnetwork_addr;
134 struct in_addr vnetwork_mask;
135 struct in_addr vhost_addr;
136 struct in6_addr vprefix_addr6;
137 uint8_t vprefix_len;
138 struct in6_addr vhost_addr6;
139 struct in_addr vdhcp_startaddr;
140 struct in_addr vnameserver_addr;
141 struct in6_addr vnameserver_addr6;
142
143 struct in_addr client_ipaddr;
144 char client_hostname[33];
145
146 int restricted;
147 struct gfwd_list *guestfwd_list;
148
149
150 struct quehead m_freelist;
151 struct quehead m_usedlist;
152 int mbuf_alloced;
153
154
155 struct quehead if_fastq;
156 struct quehead if_batchq;
157 bool if_start_busy;
158
159
160 struct ipq ipq;
161 uint16_t ip_id;
162
163
164 BOOTPClient bootp_clients[NB_BOOTP_CLIENTS];
165 char *bootp_filename;
166 size_t vdnssearch_len;
167 uint8_t *vdnssearch;
168 char *vdomainname;
169
170
171 struct socket tcb;
172 struct socket *tcp_last_so;
173 tcp_seq tcp_iss;
174 uint32_t tcp_now;
175
176
177 struct socket udb;
178 struct socket *udp_last_so;
179
180
181 struct socket icmp;
182 struct socket *icmp_last_so;
183
184
185 char *tftp_prefix;
186 struct tftp_session tftp_sessions[TFTP_SESSIONS_MAX];
187 char *tftp_server_name;
188
189 ArpTable arp_table;
190 NdpTable ndp_table;
191
192 GRand *grand;
193 void *ra_timer;
194
195 const SlirpCb *cb;
196 void *opaque;
197};
198
199void if_start(Slirp *);
200
201int get_dns_addr(struct in_addr *pdns_addr);
202int get_dns6_addr(struct in6_addr *pdns6_addr, uint32_t *scope_id);
203
204
205void ncsi_input(Slirp *slirp, const uint8_t *pkt, int pkt_len);
206
207#ifndef _WIN32
208#include <netdb.h>
209#endif
210
211
212extern bool slirp_do_keepalive;
213
214#define TCP_MAXIDLE (TCPTV_KEEPCNT * TCPTV_KEEPINTVL)
215
216
217int translate_dnssearch(Slirp *s, const char ** names);
218
219
220int cksum(struct mbuf *m, int len);
221int ip6_cksum(struct mbuf *m);
222
223
224void if_init(Slirp *);
225void if_output(struct socket *, struct mbuf *);
226
227
228void ip_init(Slirp *);
229void ip_cleanup(Slirp *);
230void ip_input(struct mbuf *);
231void ip_slowtimo(Slirp *);
232void ip_stripoptions(register struct mbuf *, struct mbuf *);
233
234
235int ip_output(struct socket *, struct mbuf *);
236
237
238void ip6_init(Slirp *);
239void ip6_cleanup(Slirp *);
240void ip6_input(struct mbuf *);
241
242
243int ip6_output(struct socket *, struct mbuf *, int fast);
244
245
246void tcp_input(register struct mbuf *, int, struct socket *, unsigned short af);
247int tcp_mss(register struct tcpcb *, unsigned);
248
249
250int tcp_output(register struct tcpcb *);
251void tcp_setpersist(register struct tcpcb *);
252
253
254void tcp_init(Slirp *);
255void tcp_cleanup(Slirp *);
256void tcp_template(struct tcpcb *);
257void tcp_respond(struct tcpcb *, register struct tcpiphdr *,
258 register struct mbuf *, tcp_seq, tcp_seq, int, unsigned short);
259struct tcpcb * tcp_newtcpcb(struct socket *);
260struct tcpcb * tcp_close(register struct tcpcb *);
261void tcp_sockclosed(struct tcpcb *);
262int tcp_fconnect(struct socket *, unsigned short af);
263void tcp_connect(struct socket *);
264int tcp_attach(struct socket *);
265uint8_t tcp_tos(struct socket *);
266int tcp_emu(struct socket *, struct mbuf *);
267int tcp_ctl(struct socket *);
268struct tcpcb *tcp_drop(struct tcpcb *tp, int err);
269
270struct socket *
271slirp_find_ctl_socket(Slirp *slirp, struct in_addr guest_addr, int guest_port);
272
273void slirp_send_packet_all(Slirp *slirp, const void *buf, size_t len);
274
275#endif
276