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