2016-06-29 16:12:57 +08:00
|
|
|
#ifndef SLIRP_H
|
|
|
|
#define SLIRP_H
|
2004-04-22 08:10:48 +08:00
|
|
|
|
|
|
|
#include "slirp_config.h"
|
|
|
|
|
2004-07-13 06:33:07 +08:00
|
|
|
#ifdef _WIN32
|
|
|
|
|
|
|
|
typedef char *caddr_t;
|
|
|
|
|
2005-01-11 07:19:34 +08:00
|
|
|
# include <windows.h>
|
2004-07-13 06:33:07 +08:00
|
|
|
# include <winsock2.h>
|
2008-05-18 02:07:00 +08:00
|
|
|
# include <ws2tcpip.h>
|
2004-07-13 06:33:07 +08:00
|
|
|
# include <sys/timeb.h>
|
|
|
|
# include <iphlpapi.h>
|
|
|
|
|
|
|
|
#else
|
2010-09-20 06:50:48 +08:00
|
|
|
# if !defined(__HAIKU__)
|
|
|
|
# define O_BINARY 0
|
|
|
|
# endif
|
2004-07-13 06:33:07 +08:00
|
|
|
#endif
|
|
|
|
|
2004-04-22 08:10:48 +08:00
|
|
|
#ifdef HAVE_SYS_BITYPES_H
|
|
|
|
# include <sys/bitypes.h>
|
|
|
|
#endif
|
|
|
|
|
2004-07-13 06:33:07 +08:00
|
|
|
#ifndef _WIN32
|
2004-04-22 08:10:48 +08:00
|
|
|
#include <sys/uio.h>
|
2004-07-13 06:33:07 +08:00
|
|
|
#endif
|
2004-04-22 08:10:48 +08:00
|
|
|
|
2004-07-13 06:33:07 +08:00
|
|
|
#ifndef _WIN32
|
2004-04-22 08:10:48 +08:00
|
|
|
#include <netinet/in.h>
|
|
|
|
#include <arpa/inet.h>
|
2004-07-13 06:33:07 +08:00
|
|
|
#endif
|
2004-04-22 08:10:48 +08:00
|
|
|
|
|
|
|
#ifndef NO_UNIX_SOCKETS
|
|
|
|
#include <sys/un.h>
|
|
|
|
#endif
|
|
|
|
#ifdef HAVE_SYS_SIGNAL_H
|
|
|
|
# include <sys/signal.h>
|
|
|
|
#endif
|
2004-07-13 06:33:07 +08:00
|
|
|
#ifndef _WIN32
|
2004-04-22 08:10:48 +08:00
|
|
|
#include <sys/socket.h>
|
2004-07-13 06:33:07 +08:00
|
|
|
#endif
|
2004-04-22 08:10:48 +08:00
|
|
|
|
2004-07-13 05:11:45 +08:00
|
|
|
#if defined(HAVE_SYS_IOCTL_H)
|
2004-04-22 08:10:48 +08:00
|
|
|
# include <sys/ioctl.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef HAVE_SYS_SELECT_H
|
|
|
|
# include <sys/select.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef HAVE_SYS_WAIT_H
|
|
|
|
# include <sys/wait.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef HAVE_SYS_FILIO_H
|
|
|
|
# include <sys/filio.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* Avoid conflicting with the libc insque() and remque(), which
|
|
|
|
have different prototypes. */
|
|
|
|
#define insque slirp_insque
|
|
|
|
#define remque slirp_remque
|
2016-02-23 05:29:21 +08:00
|
|
|
#define quehead slirp_quehead
|
2004-04-22 08:10:48 +08:00
|
|
|
|
|
|
|
#ifdef HAVE_SYS_STROPTS_H
|
|
|
|
#include <sys/stropts.h>
|
|
|
|
#endif
|
|
|
|
|
2016-03-15 17:31:19 +08:00
|
|
|
|
2004-04-22 08:10:48 +08:00
|
|
|
#include "debug.h"
|
|
|
|
|
2012-12-18 01:20:00 +08:00
|
|
|
#include "qemu/queue.h"
|
|
|
|
#include "qemu/sockets.h"
|
2016-01-08 22:41:28 +08:00
|
|
|
#include "net/eth.h"
|
2009-06-24 20:42:31 +08:00
|
|
|
|
2009-06-24 20:42:31 +08:00
|
|
|
#include "libslirp.h"
|
2004-04-22 08:10:48 +08:00
|
|
|
#include "ip.h"
|
2016-03-15 17:31:19 +08:00
|
|
|
#include "ip6.h"
|
2004-04-22 08:10:48 +08:00
|
|
|
#include "tcp.h"
|
|
|
|
#include "tcp_timer.h"
|
|
|
|
#include "tcp_var.h"
|
|
|
|
#include "tcpip.h"
|
|
|
|
#include "udp.h"
|
2011-07-20 18:20:18 +08:00
|
|
|
#include "ip_icmp.h"
|
2016-03-15 17:31:19 +08:00
|
|
|
#include "ip6_icmp.h"
|
2004-04-22 08:10:48 +08:00
|
|
|
#include "mbuf.h"
|
|
|
|
#include "sbuf.h"
|
|
|
|
#include "socket.h"
|
|
|
|
#include "if.h"
|
|
|
|
#include "main.h"
|
|
|
|
#include "misc.h"
|
|
|
|
|
|
|
|
#include "bootp.h"
|
2004-08-25 05:57:12 +08:00
|
|
|
#include "tftp.h"
|
2009-06-24 20:42:31 +08:00
|
|
|
|
2011-08-03 18:52:54 +08:00
|
|
|
#define ARPOP_REQUEST 1 /* ARP request */
|
|
|
|
#define ARPOP_REPLY 2 /* ARP reply */
|
|
|
|
|
|
|
|
struct ethhdr {
|
|
|
|
unsigned char h_dest[ETH_ALEN]; /* destination eth addr */
|
|
|
|
unsigned char h_source[ETH_ALEN]; /* source ether addr */
|
|
|
|
unsigned short h_proto; /* packet type ID field */
|
|
|
|
};
|
|
|
|
|
2016-08-15 16:24:54 +08:00
|
|
|
struct slirp_arphdr {
|
2011-08-03 18:52:54 +08:00
|
|
|
unsigned short ar_hrd; /* format of hardware address */
|
|
|
|
unsigned short ar_pro; /* format of protocol address */
|
|
|
|
unsigned char ar_hln; /* length of hardware address */
|
|
|
|
unsigned char ar_pln; /* length of protocol address */
|
|
|
|
unsigned short ar_op; /* ARP opcode (command) */
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Ethernet looks like this : This bit is variable sized however...
|
|
|
|
*/
|
|
|
|
unsigned char ar_sha[ETH_ALEN]; /* sender hardware address */
|
|
|
|
uint32_t ar_sip; /* sender IP address */
|
|
|
|
unsigned char ar_tha[ETH_ALEN]; /* target hardware address */
|
|
|
|
uint32_t ar_tip; /* target IP address */
|
2011-08-31 18:38:01 +08:00
|
|
|
} QEMU_PACKED;
|
2011-08-03 18:52:54 +08:00
|
|
|
|
|
|
|
#define ARP_TABLE_SIZE 16
|
|
|
|
|
|
|
|
typedef struct ArpTable {
|
2016-08-15 16:24:54 +08:00
|
|
|
struct slirp_arphdr table[ARP_TABLE_SIZE];
|
2011-08-03 18:52:54 +08:00
|
|
|
int next_victim;
|
|
|
|
} ArpTable;
|
|
|
|
|
2011-08-05 18:51:11 +08:00
|
|
|
void arp_table_add(Slirp *slirp, uint32_t ip_addr, uint8_t ethaddr[ETH_ALEN]);
|
2011-08-03 18:52:54 +08:00
|
|
|
|
2011-08-05 18:51:11 +08:00
|
|
|
bool arp_table_search(Slirp *slirp, uint32_t ip_addr,
|
2011-08-03 18:52:54 +08:00
|
|
|
uint8_t out_ethaddr[ETH_ALEN]);
|
2009-12-02 19:24:42 +08:00
|
|
|
|
2016-03-15 17:31:19 +08:00
|
|
|
struct ndpentry {
|
|
|
|
unsigned char eth_addr[ETH_ALEN]; /* sender hardware address */
|
|
|
|
struct in6_addr ip_addr; /* sender IP address */
|
|
|
|
} QEMU_PACKED;
|
|
|
|
|
|
|
|
#define NDP_TABLE_SIZE 16
|
|
|
|
|
|
|
|
typedef struct NdpTable {
|
|
|
|
struct ndpentry table[NDP_TABLE_SIZE];
|
|
|
|
int next_victim;
|
|
|
|
} NdpTable;
|
|
|
|
|
|
|
|
void ndp_table_add(Slirp *slirp, struct in6_addr ip_addr,
|
|
|
|
uint8_t ethaddr[ETH_ALEN]);
|
|
|
|
bool ndp_table_search(Slirp *slirp, struct in6_addr ip_addr,
|
|
|
|
uint8_t out_ethaddr[ETH_ALEN]);
|
|
|
|
|
2009-06-24 20:42:31 +08:00
|
|
|
struct Slirp {
|
2009-09-12 15:36:22 +08:00
|
|
|
QTAILQ_ENTRY(Slirp) entry;
|
2013-08-25 10:01:19 +08:00
|
|
|
u_int time_fasttimo;
|
|
|
|
u_int last_slowtimo;
|
|
|
|
bool do_slowtimo;
|
2009-06-24 20:42:31 +08:00
|
|
|
|
2016-03-20 19:29:54 +08:00
|
|
|
bool in_enabled, in6_enabled;
|
|
|
|
|
2009-06-24 20:42:31 +08:00
|
|
|
/* virtual network configuration */
|
|
|
|
struct in_addr vnetwork_addr;
|
|
|
|
struct in_addr vnetwork_mask;
|
|
|
|
struct in_addr vhost_addr;
|
2016-03-15 17:31:19 +08:00
|
|
|
struct in6_addr vprefix_addr6;
|
|
|
|
uint8_t vprefix_len;
|
|
|
|
struct in6_addr vhost_addr6;
|
2009-06-24 20:42:31 +08:00
|
|
|
struct in_addr vdhcp_startaddr;
|
|
|
|
struct in_addr vnameserver_addr;
|
2016-03-15 17:31:22 +08:00
|
|
|
struct in6_addr vnameserver_addr6;
|
2009-06-24 20:42:31 +08:00
|
|
|
|
|
|
|
struct in_addr client_ipaddr;
|
|
|
|
char client_hostname[33];
|
|
|
|
|
|
|
|
int restricted;
|
|
|
|
struct ex_list *exec_list;
|
|
|
|
|
|
|
|
/* mbuf states */
|
2016-02-23 05:29:21 +08:00
|
|
|
struct quehead m_freelist;
|
|
|
|
struct quehead m_usedlist;
|
2009-06-24 20:42:31 +08:00
|
|
|
int mbuf_alloced;
|
|
|
|
|
|
|
|
/* if states */
|
2016-02-23 05:29:21 +08:00
|
|
|
struct quehead if_fastq; /* fast queue (for interactive data) */
|
|
|
|
struct quehead if_batchq; /* queue for non-interactive data */
|
2012-03-06 02:50:39 +08:00
|
|
|
bool if_start_busy; /* avoid if_start recursion */
|
2009-06-24 20:42:31 +08:00
|
|
|
|
|
|
|
/* ip states */
|
|
|
|
struct ipq ipq; /* ip reass. queue */
|
2010-07-23 04:15:23 +08:00
|
|
|
uint16_t ip_id; /* ip packet ctr, for ids */
|
2009-06-24 20:42:31 +08:00
|
|
|
|
|
|
|
/* bootp/dhcp states */
|
|
|
|
BOOTPClient bootp_clients[NB_BOOTP_CLIENTS];
|
|
|
|
char *bootp_filename;
|
2012-10-28 01:53:39 +08:00
|
|
|
size_t vdnssearch_len;
|
|
|
|
uint8_t *vdnssearch;
|
2018-02-28 00:06:01 +08:00
|
|
|
char *vdomainname;
|
2009-06-24 20:42:31 +08:00
|
|
|
|
|
|
|
/* tcp states */
|
|
|
|
struct socket tcb;
|
|
|
|
struct socket *tcp_last_so;
|
|
|
|
tcp_seq tcp_iss; /* tcp initial send seq # */
|
2010-07-23 04:15:23 +08:00
|
|
|
uint32_t tcp_now; /* for RFC 1323 timestamps */
|
2009-06-24 20:42:31 +08:00
|
|
|
|
|
|
|
/* udp states */
|
|
|
|
struct socket udb;
|
|
|
|
struct socket *udp_last_so;
|
|
|
|
|
2011-07-20 18:20:18 +08:00
|
|
|
/* icmp states */
|
|
|
|
struct socket icmp;
|
|
|
|
struct socket *icmp_last_so;
|
|
|
|
|
2009-06-24 20:42:31 +08:00
|
|
|
/* tftp states */
|
|
|
|
char *tftp_prefix;
|
|
|
|
struct tftp_session tftp_sessions[TFTP_SESSIONS_MAX];
|
2018-09-14 15:26:16 +08:00
|
|
|
char *tftp_server_name;
|
2009-06-24 20:42:31 +08:00
|
|
|
|
2011-08-03 18:52:54 +08:00
|
|
|
ArpTable arp_table;
|
2016-03-15 17:31:19 +08:00
|
|
|
NdpTable ndp_table;
|
|
|
|
|
|
|
|
GRand *grand;
|
|
|
|
QEMUTimer *ra_timer;
|
2011-08-03 18:52:54 +08:00
|
|
|
|
2009-06-24 20:42:31 +08:00
|
|
|
void *opaque;
|
2009-06-24 20:42:31 +08:00
|
|
|
};
|
|
|
|
|
2009-06-24 20:42:31 +08:00
|
|
|
extern Slirp *slirp_instance;
|
2004-04-22 08:10:48 +08:00
|
|
|
|
|
|
|
#ifndef NULL
|
|
|
|
#define NULL (void *)0
|
|
|
|
#endif
|
|
|
|
|
2009-07-02 03:11:17 +08:00
|
|
|
void if_start(Slirp *);
|
2004-04-22 08:10:48 +08:00
|
|
|
|
2017-04-14 16:35:03 +08:00
|
|
|
/* ncsi.c */
|
|
|
|
void ncsi_input(Slirp *slirp, const uint8_t *pkt, int pkt_len);
|
|
|
|
|
2004-07-13 06:33:07 +08:00
|
|
|
#ifndef _WIN32
|
2004-04-22 08:10:48 +08:00
|
|
|
#include <netdb.h>
|
2004-07-13 06:33:07 +08:00
|
|
|
#endif
|
2004-04-22 08:10:48 +08:00
|
|
|
|
2007-10-27 03:01:16 +08:00
|
|
|
#define SO_OPTIONS DO_KEEPALIVE
|
|
|
|
#define TCP_MAXIDLE (TCPTV_KEEPCNT * TCPTV_KEEPINTVL)
|
|
|
|
|
2012-10-28 01:53:39 +08:00
|
|
|
/* dnssearch.c */
|
|
|
|
int translate_dnssearch(Slirp *s, const char ** names);
|
|
|
|
|
2004-04-22 08:10:48 +08:00
|
|
|
/* cksum.c */
|
|
|
|
int cksum(struct mbuf *m, int len);
|
2016-03-15 17:31:19 +08:00
|
|
|
int ip6_cksum(struct mbuf *m);
|
2004-04-22 08:10:48 +08:00
|
|
|
|
|
|
|
/* if.c */
|
2009-07-02 03:11:17 +08:00
|
|
|
void if_init(Slirp *);
|
|
|
|
void if_output(struct socket *, struct mbuf *);
|
2004-04-22 08:10:48 +08:00
|
|
|
|
|
|
|
/* ip_input.c */
|
2009-07-02 03:11:17 +08:00
|
|
|
void ip_init(Slirp *);
|
2012-03-01 02:14:23 +08:00
|
|
|
void ip_cleanup(Slirp *);
|
2009-07-02 03:11:17 +08:00
|
|
|
void ip_input(struct mbuf *);
|
|
|
|
void ip_slowtimo(Slirp *);
|
|
|
|
void ip_stripoptions(register struct mbuf *, struct mbuf *);
|
2004-04-22 08:10:48 +08:00
|
|
|
|
|
|
|
/* ip_output.c */
|
2009-07-02 03:11:17 +08:00
|
|
|
int ip_output(struct socket *, struct mbuf *);
|
2004-04-22 08:10:48 +08:00
|
|
|
|
2016-03-15 17:31:19 +08:00
|
|
|
/* ip6_input.c */
|
|
|
|
void ip6_init(Slirp *);
|
|
|
|
void ip6_cleanup(Slirp *);
|
|
|
|
void ip6_input(struct mbuf *);
|
|
|
|
|
|
|
|
/* ip6_output */
|
|
|
|
int ip6_output(struct socket *, struct mbuf *, int fast);
|
|
|
|
|
2004-04-22 08:10:48 +08:00
|
|
|
/* tcp_input.c */
|
2016-03-15 17:31:21 +08:00
|
|
|
void tcp_input(register struct mbuf *, int, struct socket *, unsigned short af);
|
2009-07-02 03:11:17 +08:00
|
|
|
int tcp_mss(register struct tcpcb *, u_int);
|
2004-04-22 08:10:48 +08:00
|
|
|
|
|
|
|
/* tcp_output.c */
|
2009-07-02 03:11:17 +08:00
|
|
|
int tcp_output(register struct tcpcb *);
|
|
|
|
void tcp_setpersist(register struct tcpcb *);
|
2004-04-22 08:10:48 +08:00
|
|
|
|
|
|
|
/* tcp_subr.c */
|
2009-07-02 03:11:17 +08:00
|
|
|
void tcp_init(Slirp *);
|
2012-03-01 02:14:23 +08:00
|
|
|
void tcp_cleanup(Slirp *);
|
2009-07-02 03:11:17 +08:00
|
|
|
void tcp_template(struct tcpcb *);
|
2016-03-15 17:31:21 +08:00
|
|
|
void tcp_respond(struct tcpcb *, register struct tcpiphdr *,
|
|
|
|
register struct mbuf *, tcp_seq, tcp_seq, int, unsigned short);
|
2009-07-02 03:11:17 +08:00
|
|
|
struct tcpcb * tcp_newtcpcb(struct socket *);
|
|
|
|
struct tcpcb * tcp_close(register struct tcpcb *);
|
|
|
|
void tcp_sockclosed(struct tcpcb *);
|
2015-12-20 05:25:03 +08:00
|
|
|
int tcp_fconnect(struct socket *, unsigned short af);
|
2009-07-02 03:11:17 +08:00
|
|
|
void tcp_connect(struct socket *);
|
|
|
|
int tcp_attach(struct socket *);
|
2010-07-23 04:15:23 +08:00
|
|
|
uint8_t tcp_tos(struct socket *);
|
2009-07-02 03:11:17 +08:00
|
|
|
int tcp_emu(struct socket *, struct mbuf *);
|
|
|
|
int tcp_ctl(struct socket *);
|
2004-04-27 03:50:09 +08:00
|
|
|
struct tcpcb *tcp_drop(struct tcpcb *tp, int err);
|
2004-04-22 08:10:48 +08:00
|
|
|
|
|
|
|
#endif
|