-
Notifications
You must be signed in to change notification settings - Fork 192
/
Copy pathsig.ml
255 lines (182 loc) · 6.59 KB
/
sig.ml
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
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
module type READ_INTO = sig
type flow
type error
val read_into: flow -> Cstruct.t ->
(unit Mirage_flow.or_eof, error) result Lwt.t
(** Completely fills the given buffer with data from [fd] *)
end
module type FLOW_CLIENT = sig
include Mirage_flow_combinators.SHUTDOWNABLE
type address
val connect: ?read_buffer_size:int -> address ->
(flow, [`Msg of string]) result Lwt.t
(** [connect address] creates a connection to [address] and returns
he connected flow. *)
end
module type CONN = sig
include Mirage_flow.S
include READ_INTO
with type flow := flow
and type error := error
end
module type FLOW_SERVER = sig
type server
(* A server bound to some address *)
type address
val of_bound_fd: ?read_buffer_size:int -> Unix.file_descr -> server Lwt.t
(** Create a server from a file descriptor bound to a Unix domain socket
by some other process and passed to us. *)
val bind: ?description:string -> address -> server Lwt.t
(** Bind a server to an address *)
val getsockname: server -> address Lwt.t
(** Query the address the server is bound to *)
val disable_connection_tracking: server -> unit
(** For a particular server, exempt connections from the tracking mechanism.
This is intended for internal purposes only (e.g. extracting diagnostics
information) *)
type flow
val listen: server -> (flow -> unit Lwt.t) -> unit
(** Accept connections forever, calling the callback with each one.
Connections are closed automatically when the callback finishes. *)
val shutdown: server -> unit Lwt.t
(** Stop accepting connections on the given server *)
end
module type FLOW_CLIENT_SERVER = sig
include FLOW_CLIENT
include FLOW_SERVER
with type address := address
and type flow := flow
end
module type SOCKETS = sig
(* An OS-based BSD sockets implementation *)
module Datagram: sig
type address = Ipaddr.t * int
module Udp: sig
type address = Ipaddr.t * int
include FLOW_CLIENT_SERVER
with type address := address
val recvfrom: server -> Cstruct.t -> (int * address) Lwt.t
val sendto: server -> address -> ?ttl:int -> Cstruct.t -> unit Lwt.t
end
end
module Stream: sig
module Tcp: sig
type address = Ipaddr.t * int
include FLOW_CLIENT_SERVER
with type address := address
include READ_INTO
with type flow := flow
and type error := error
end
module Unix: sig
type address = string
include FLOW_CLIENT_SERVER
with type address := address
include READ_INTO
with type flow := flow
and type error := error
val unsafe_get_raw_fd: flow -> Unix.file_descr
(** Return the underlying fd. This is intended for careful integration
with 3rd party libraries. Don't use this fd at the same time as the
flow. *)
end
end
end
module type FILES = sig
(** An OS-based file reading implementation *)
val read_file: string -> (string, [`Msg of string]) result Lwt.t
(** Read a whole file into a string *)
type watch
val watch_file: string -> (unit -> unit) -> (watch, [ `Msg of string ]) result Lwt.t
(** [watch_file path callback] executes [callback] whenever the contents of
[path] may have changed. This blocks until the watch has been established. *)
val unwatch: watch -> unit Lwt.t
(** [unwatch watch] stops watching the path(s) associated with [watch] *)
end
module type DNS = sig
val resolve: Dns.Packet.question -> Dns.Packet.rr list Lwt.t
(** Given a question, find associated resource records *)
end
module type HOST = sig
(** The Host interface *)
module Sockets: sig
(** User-space socket connections *)
include SOCKETS
end
module Files: sig
include FILES
end
module Time: Mirage_time.S
module Dns: sig
include DNS
end
module Main: sig
val run: unit Lwt.t -> unit
(** Run the main event loop *)
val run_in_main: (unit -> 'a Lwt.t) -> 'a
(** Run the function in the main thread *)
end
module Fn: sig
(** Call a blocking ('a -> 'b) function in a ('a -> 'b Lwt.t) context *)
type ('request, 'response) t
(** A function from 'request to 'response *)
val create: ('request -> 'response) -> ('request, 'response) t
val destroy: ('request, 'response) t -> unit
val fn: ('request, 'response) t -> 'request -> 'response Lwt.t
(** Apply the function *)
end
end
module type VMNET = sig
(** A virtual ethernet link to the VM *)
include Mirage_net.S
val add_listener: t -> (Cstruct.t -> unit Lwt.t) -> unit
(** Add a callback which will be invoked in parallel with all received packets *)
val after_disconnect: t -> unit Lwt.t
(** Waits until the network has disconnected *)
type fd
val of_fd:
connect_client_fn:(Uuidm.t -> Ipaddr.V4.t option -> (Macaddr.t, [`Msg of string]) result Lwt.t) ->
server_macaddr:Macaddr.t ->
mtu:int ->
fd -> (t, [`Msg of string]) result Lwt.t
val start_capture: t -> ?size_limit:int64 -> string -> unit Lwt.t
val stop_capture: t -> unit Lwt.t
val get_client_uuid: t -> Uuidm.t
val get_client_macaddr: t -> Macaddr.t
end
module type DNS_POLICY = sig
(** Policy settings
DNS configuration is taken from 4 places, lowest to highest priority:
- 0: a built-in default of the Google public DNS servers
- 1: a default configuration (from a command-line argument or a
configuration file)
- 2: the `/etc/resolv.conf` file if present
- 3: the database key `slirp/dns`
If configuration with a higher priority is found then it
completely overrides lower priority configuration. *)
type priority = int (** higher is more important *)
val add: priority:priority ->
config:[ `Upstream of Dns_forward.Config.t | `Host ] -> unit
(** Add some configuration at the given priority level *)
val remove: priority:priority -> unit
(** Remove the configuration at the given priority level *)
val config: unit -> [ `Upstream of Dns_forward.Config.t | `Host ]
(** Return the currently active DNS configuration *)
end
module type RECORDER = sig
(** Allow ethernet packets to be recorded *)
type t
val record: t -> Cstruct.t list -> unit
(** Inject a packet and record it if it matches a rule. This is
intended for debugging: the packet will not be transmitted to
the underlying network. *)
end
module type Connector = sig
(** Make connections into the VM *)
include FLOW_CLIENT
val connect: unit -> flow Lwt.t
(** Connect to the port multiplexing service in the VM *)
include READ_INTO
with type flow := flow
and type error := error
end