summaryrefslogtreecommitdiffstats
path: root/src/include/ipxe/slirp.h
blob: 4fb13b93409383766046e2ef8ecc3f11a537654c (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
#ifndef _IPXE_SLIRP_H
#define _IPXE_SLIRP_H

/** @file
 *
 * Linux Slirp network driver
 *
 */

FILE_LICENCE ( GPL2_OR_LATER );

#include <stdint.h>
#include <stdbool.h>

/** Ready to be read */
#define SLIRP_EVENT_IN 0x01

/** Ready to be written */
#define SLIRP_EVENT_OUT 0x02

/** Exceptional condition */
#define SLIRP_EVENT_PRI 0x04

/** Error condition */
#define SLIRP_EVENT_ERR 0x08

/** Hang up */
#define SLIRP_EVENT_HUP 0x10

/** Slirp device configuration */
struct slirp_config {
	/** Configuration version */
	uint32_t version;
	/** Restrict to host loopback connections only */
	int restricted;
	/** IPv4 is enabled */
	bool in_enabled;
	/** IPv4 network */
	struct in_addr vnetwork;
	/** IPv4 netmask */
	struct in_addr vnetmask;
	/** IPv4 host server address */
	struct in_addr vhost;
	/** IPv6 is enabled */
	bool in6_enabled;
	/** IPv6 prefix */
	struct in6_addr vprefix_addr6;
	/** IPv6 prefix length */
	uint8_t vprefix_len;
	/** IPv6 host server address */
	struct in6_addr vhost6;
	/** Client hostname */
	const char *vhostname;
	/** TFTP server name */
	const char *tftp_server_name;
	/** TFTP path prefix */
	const char *tftp_path;
	/** Boot filename */
	const char *bootfile;
	/** DHCPv4 start address */
	struct in_addr vdhcp_start;
	/** DNS IPv4 address */
	struct in_addr vnameserver;
	/** DNS IPv6 address */
	struct in_addr vnameserver6;
	/** DNS search list */
	const char **vdnssearch;
	/** Domain name */
	const char *vdomainname;
	/** Interface MTU */
	size_t if_mtu;
	/** Interface MRU */
	size_t if_mru;
	/** Disable host loopback connections */
	bool disable_host_loopback;
	/** Enable emulation (apparently unsafe) */
	bool enable_emu;
};

/** Slirp device callbacks */
struct slirp_callbacks {
	/**
	 * Send packet
	 *
	 * @v buf		Data buffer
	 * @v len		Length of data
	 * @v device		Device opaque pointer
	 * @ret len		Consumed length (or negative on error)
	 */
	ssize_t ( __asmcall * send_packet ) ( const void *buf, size_t len,
					      void *device );
	/**
	 * Print an error message
	 *
	 * @v msg		Error message
	 * @v device		Device opaque pointer
	 */
	void ( __asmcall * guest_error ) ( const char *msg, void *device );
	/**
	 * Get virtual clock
	 *
	 * @v device		Device opaque pointer
	 * @ret clock_ns	Clock time in nanoseconds
	 */
	int64_t ( __asmcall * clock_get_ns ) ( void *device );
	/**
	 * Create a new timer
	 *
	 * @v callback		Timer callback
	 * @v opaque		Timer opaque pointer
	 * @v device		Device opaque pointer
	 * @ret timer		Timer
	 */
	void * ( __asmcall * timer_new ) ( void ( __asmcall * callback )
					   ( void *opaque ),
					   void *opaque, void *device );
	/**
	 * Delete a timer
	 *
	 * @v timer		Timer
	 * @v device		Device opaque pointer
	 */
	void ( __asmcall * timer_free ) ( void *timer, void *device );
	/**
	 * Set timer expiry time
	 *
	 * @v timer		Timer
	 * @v expire		Expiry time
	 * @v device		Device opaque pointer
	 */
	void ( __asmcall * timer_mod ) ( void *timer, int64_t expire,
					 void *device );
	/**
	 * Register file descriptor for polling
	 *
	 * @v fd		File descriptor
	 * @v device		Device opaque pointer
	 */
	void ( __asmcall * register_poll_fd ) ( int fd, void *device );
	/**
	 * Unregister file descriptor
	 *
	 * @v fd		File descriptor
	 * @v device		Device opaque pointer
	 */
	void ( __asmcall * unregister_poll_fd ) ( int fd, void *device );
	/**
	 * Notify that new events are ready
	 *
	 * @v device		Device opaque pointer
	 */
	void ( __asmcall * notify ) ( void *device );
};

#endif /* _IPXE_SLIRP_H */