Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
folium-app
GitHub Repository: folium-app/Folium
Path: blob/a-new-beginning/SharedDependencies/Sources/libslirp/include/slirp.h
2 views
1
/* SPDX-License-Identifier: BSD-3-Clause */
2
#ifndef SLIRP_H
3
#define SLIRP_H
4
5
#ifdef _WIN32
6
7
/* as defined in sdkddkver.h */
8
#ifndef _WIN32_WINNT
9
#define _WIN32_WINNT 0x0601 /* Windows 7 */
10
#endif
11
/* reduces the number of implicitly included headers */
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
#define O_BINARY 0
24
#endif
25
26
#ifndef _WIN32
27
#include <sys/uio.h>
28
#include <netinet/in.h>
29
#include <arpa/inet.h>
30
#include <sys/socket.h>
31
#include <sys/ioctl.h>
32
#endif
33
34
#ifdef __APPLE__
35
#include <sys/filio.h>
36
#endif
37
38
#include "debug.h"
39
#include "util.h"
40
41
#include "libslirp.h"
42
#include <netinet/ip.h>
43
#include "ip.h"
44
#include "ip6.h"
45
#include "tcp.h"
46
#include "tcp_timer.h"
47
#include "tcp_var.h"
48
#include "tcpip.h"
49
#include <netinet/udp.h>
50
#include "udp.h"
51
#include <netinet/ip_icmp.h>
52
#include "ip_icmp.h"
53
#include "ip6_icmp.h"
54
#include "mbuf.h"
55
#include "sbuf.h"
56
#include "socket.h"
57
#include "if.h"
58
#include "main.h"
59
#include "misc.h"
60
61
#include "bootp.h"
62
#include "tftp.h"
63
64
#define ARPOP_REQUEST 1 /* ARP request */
65
#define ARPOP_REPLY 2 /* ARP reply */
66
67
struct ethhdr {
68
unsigned char h_dest[ETH_ALEN]; /* destination eth addr */
69
unsigned char h_source[ETH_ALEN]; /* source ether addr */
70
unsigned short h_proto; /* packet type ID field */
71
};
72
73
SLIRP_PACKED_BEGIN
74
struct slirp_arphdr {
75
unsigned short ar_hrd; /* format of hardware address */
76
unsigned short ar_pro; /* format of protocol address */
77
unsigned char ar_hln; /* length of hardware address */
78
unsigned char ar_pln; /* length of protocol address */
79
unsigned short ar_op; /* ARP opcode (command) */
80
81
/*
82
* Ethernet looks like this : This bit is variable sized however...
83
*/
84
uint8_t ar_sha[ETH_ALEN]; /* sender hardware address */
85
uint32_t ar_sip; /* sender IP address */
86
uint8_t ar_tha[ETH_ALEN]; /* target hardware address */
87
uint32_t ar_tip; /* target IP address */
88
} SLIRP_PACKED_END;
89
90
#define ARP_TABLE_SIZE 16
91
92
typedef struct ArpTable {
93
struct slirp_arphdr table[ARP_TABLE_SIZE];
94
int next_victim;
95
} ArpTable;
96
97
/* Add a new ARP entry for the given addresses */
98
void arp_table_add(Slirp *slirp, uint32_t ip_addr,
99
const uint8_t ethaddr[ETH_ALEN]);
100
101
/* Look for an ARP entry for the given IP address */
102
bool arp_table_search(Slirp *slirp, uint32_t ip_addr,
103
uint8_t out_ethaddr[ETH_ALEN]);
104
105
struct ndpentry {
106
uint8_t eth_addr[ETH_ALEN]; /* sender hardware address */
107
struct in6_addr ip_addr; /* sender IP address */
108
};
109
110
#define NDP_TABLE_SIZE 16
111
112
typedef struct NdpTable {
113
struct ndpentry table[NDP_TABLE_SIZE];
114
/*
115
* The table is a cache with old entries overwritten when the table fills.
116
* Preserve the first entry: it is the guest, which is needed for lazy
117
* hostfwd guest address assignment.
118
*/
119
struct in6_addr guest_in6_addr;
120
int next_victim;
121
} NdpTable;
122
123
/* Add a new NDP entry for the given addresses */
124
void ndp_table_add(Slirp *slirp, struct in6_addr ip_addr,
125
uint8_t ethaddr[ETH_ALEN]);
126
127
/* Look for an NDP entry for the given IPv6 address */
128
bool ndp_table_search(Slirp *slirp, struct in6_addr ip_addr,
129
uint8_t out_ethaddr[ETH_ALEN]);
130
131
/* Slirp configuration, specified by the application */
132
struct Slirp {
133
int cfg_version;
134
135
unsigned time_fasttimo;
136
unsigned last_slowtimo;
137
bool do_slowtimo;
138
139
bool in_enabled, in6_enabled;
140
141
/* virtual network configuration */
142
struct in_addr vnetwork_addr;
143
struct in_addr vnetwork_mask;
144
struct in_addr vhost_addr;
145
struct in6_addr vprefix_addr6;
146
uint8_t vprefix_len;
147
struct in6_addr vhost_addr6;
148
bool disable_dhcp; /* slirp will not reply to any DHCP requests */
149
struct in_addr vdhcp_startaddr;
150
struct in_addr vnameserver_addr;
151
struct in6_addr vnameserver_addr6;
152
153
struct in_addr client_ipaddr;
154
char client_hostname[33];
155
156
int restricted;
157
struct gfwd_list *guestfwd_list;
158
159
int if_mtu;
160
int if_mru;
161
162
bool disable_host_loopback;
163
164
uint32_t mfr_id;
165
uint8_t oob_eth_addr[ETH_ALEN];
166
167
/* mbuf states */
168
struct slirp_quehead m_freelist;
169
struct slirp_quehead m_usedlist;
170
int mbuf_alloced;
171
172
/* if states */
173
struct slirp_quehead if_fastq; /* fast queue (for interactive data) */
174
struct slirp_quehead if_batchq; /* queue for non-interactive data */
175
bool if_start_busy; /* avoid if_start recursion */
176
177
/* ip states */
178
struct ipq ipq; /* ip reass. queue */
179
uint16_t ip_id; /* ip packet ctr, for ids */
180
181
/* bootp/dhcp states */
182
BOOTPClient bootp_clients[NB_BOOTP_CLIENTS];
183
char *bootp_filename;
184
size_t vdnssearch_len;
185
uint8_t *vdnssearch;
186
char *vdomainname;
187
188
/* tcp states */
189
struct socket tcb;
190
struct socket *tcp_last_so;
191
tcp_seq tcp_iss; /* tcp initial send seq # */
192
uint32_t tcp_now; /* for RFC 1323 timestamps */
193
194
/* udp states */
195
struct socket udb;
196
struct socket *udp_last_so;
197
198
/* icmp states */
199
struct socket icmp;
200
struct socket *icmp_last_so;
201
202
/* tftp states */
203
char *tftp_prefix;
204
struct tftp_session tftp_sessions[TFTP_SESSIONS_MAX];
205
char *tftp_server_name;
206
207
ArpTable arp_table;
208
NdpTable ndp_table;
209
210
GRand *grand;
211
void *ra_timer;
212
213
bool enable_emu;
214
215
const SlirpCb *cb;
216
void *opaque;
217
218
struct sockaddr_in *outbound_addr;
219
struct sockaddr_in6 *outbound_addr6;
220
bool disable_dns; /* slirp will not redirect/serve any DNS packet */
221
};
222
223
/*
224
* Send one packet from each session.
225
* If there are packets on the fastq, they are sent FIFO, before
226
* everything else. Then we choose the first packet from each
227
* batchq session (socket) and send it.
228
* For example, if there are 3 ftp sessions fighting for bandwidth,
229
* one packet will be sent from the first session, then one packet
230
* from the second session, then one packet from the third.
231
*/
232
void if_start(Slirp *);
233
234
/* Get the address of the DNS server on the host side */
235
int get_dns_addr(struct in_addr *pdns_addr);
236
237
/* Get the IPv6 address of the DNS server on the host side */
238
int get_dns6_addr(struct in6_addr *pdns6_addr, uint32_t *scope_id);
239
240
/* ncsi.c */
241
242
/* Process NCSI packet coming from the guest */
243
void ncsi_input(Slirp *slirp, const uint8_t *pkt, int pkt_len);
244
245
#ifndef _WIN32
246
#include <netdb.h>
247
#endif
248
249
/* Whether we should send TCP keepalive packets */
250
extern bool slirp_do_keepalive;
251
252
#define TCP_MAXIDLE (TCPTV_KEEPCNT * TCPTV_KEEPINTVL)
253
254
/* dnssearch.c */
255
/* Translate from vdnssearch in configuration, into Slirp */
256
int translate_dnssearch(Slirp *s, const char **names);
257
258
/* cksum.c */
259
/* Compute the checksum of the mbuf */
260
int cksum(struct mbuf *m, int len);
261
/* Compute the checksum of the mbuf which contains an IPv6 packet */
262
int ip6_cksum(struct mbuf *m);
263
264
/* if.c */
265
/* Called from slirp_new */
266
void if_init(Slirp *);
267
/* Queue packet into an output queue (fast or batch), for sending to the guest */
268
void if_output(struct socket *, struct mbuf *);
269
270
/* ip_input.c */
271
/* Called from slirp_new */
272
void ip_init(Slirp *);
273
/* Called from slirp_cleanup */
274
void ip_cleanup(Slirp *);
275
/* Process IPv4 packet coming from the guest */
276
void ip_input(struct mbuf *);
277
/*
278
* IP timer processing;
279
* if a timer expires on a reassembly
280
* queue, discard it.
281
*/
282
void ip_slowtimo(Slirp *);
283
/*
284
* Strip out IP options, at higher
285
* level protocol in the kernel.
286
*/
287
void ip_stripoptions(register struct mbuf *);
288
289
/* ip_output.c */
290
/* Send IPv4 packet to the guest */
291
int ip_output(struct socket *, struct mbuf *);
292
293
/* ip6_input.c */
294
/* Called from slirp_new, but after other initialization */
295
void ip6_post_init(Slirp *);
296
/* Called from slirp_cleanup */
297
void ip6_cleanup(Slirp *);
298
/* Process IPv6 packet coming from the guest */
299
void ip6_input(struct mbuf *);
300
301
/* ip6_output */
302
/* Send IPv6 packet to the guest */
303
int ip6_output(struct socket *, struct mbuf *, int fast);
304
305
/* tcp_input.c */
306
/* Process TCP datagram coming from the guest */
307
void tcp_input(register struct mbuf *, int, struct socket *, unsigned short af);
308
/* Determine a reasonable value for maxseg size */
309
int tcp_mss(register struct tcpcb *, unsigned offer);
310
311
/* tcp_output.c */
312
/* Send TCP datagram to the guest */
313
int tcp_output(register struct tcpcb *);
314
/* Start/restart persistence timer */
315
void tcp_setpersist(register struct tcpcb *);
316
317
/* tcp_subr.c */
318
/* Called from slirp_new */
319
void tcp_init(Slirp *);
320
/* Called from slirp_cleanup */
321
void tcp_cleanup(Slirp *);
322
/*
323
* Create template to be used to send tcp packets on a connection.
324
* Call after host entry created, fills
325
* in a skeletal tcp/ip header, minimizing the amount of work
326
* necessary when the connection is used.
327
*/
328
void tcp_template(struct tcpcb *);
329
/*
330
* Send a single message to the TCP at address specified by
331
* the given TCP/IP header.
332
*/
333
void tcp_respond(struct tcpcb *, register struct tcpiphdr *,
334
register struct mbuf *, tcp_seq, tcp_seq, int, unsigned short);
335
/*
336
* Create a new TCP control block, making an
337
* empty reassembly queue and hooking it to the argument
338
* protocol control block.
339
*/
340
struct tcpcb *tcp_newtcpcb(struct socket *);
341
/*
342
* Close a TCP control block:
343
* discard all space held by the tcp
344
* discard internet protocol block
345
* wake up any sleepers
346
*/
347
struct tcpcb *tcp_close(register struct tcpcb *);
348
/* The Internet socket got closed, tell the guest */
349
void tcp_sockclosed(struct tcpcb *);
350
/*
351
* Connect to a host on the Internet
352
* Called by tcp_input
353
*/
354
int tcp_fconnect(struct socket *, unsigned short af);
355
/* Accept the connection from the Internet, and connect to the guest */
356
void tcp_connect(struct socket *);
357
/* Attach a TCPCB to a socket */
358
void tcp_attach(struct socket *);
359
/* * Return TOS according to the ports */
360
uint8_t tcp_tos(struct socket *);
361
/*
362
* We received a packet from the guest.
363
*
364
* Emulate programs that try and connect to us
365
* This includes ftp (the data connection is
366
* initiated by the server) and IRC (DCC CHAT and
367
* DCC SEND) for now
368
*/
369
int tcp_emu(struct socket *, struct mbuf *);
370
/* Configure the socket, now that the guest completed accepting the connection */
371
int tcp_ctl(struct socket *);
372
/*
373
* Drop a TCP connection, reporting
374
* the specified error. If connection is synchronized,
375
* then send a RST to peer.
376
*/
377
struct tcpcb *tcp_drop(struct tcpcb *tp, int err);
378
379
/* Find the socket for the guest address and port */
380
struct socket *slirp_find_ctl_socket(Slirp *slirp, struct in_addr guest_addr,
381
int guest_port);
382
383
/* Send a frame to the virtual Ethernet board, i.e. call the application send_packet callback */
384
void slirp_send_packet_all(Slirp *slirp, const void *buf, size_t len);
385
386
/* Create a new timer, i.e. call the application timer_new callback */
387
void *slirp_timer_new(Slirp *slirp, SlirpTimerId id, void *cb_opaque);
388
389
#endif
390
391