2017-03-02 09:52:55 -05:00
|
|
|
(* Copyright (C) 2015, Thomas Leonard <thomas.leonard@unikernel.com>
|
|
|
|
See the README file for details. *)
|
|
|
|
|
|
|
|
(** General utility functions. *)
|
|
|
|
|
|
|
|
(** An Ethernet interface. *)
|
|
|
|
class type interface = object
|
|
|
|
method my_mac : Macaddr.t
|
2022-01-09 06:36:35 -05:00
|
|
|
method writev : Ethernet.Packet.proto -> (Cstruct.t -> int) -> unit Lwt.t
|
2017-03-02 09:52:55 -05:00
|
|
|
method my_ip : Ipaddr.V4.t
|
|
|
|
method other_ip : Ipaddr.V4.t
|
|
|
|
end
|
|
|
|
|
|
|
|
(** An Ethernet interface connected to a clientVM. *)
|
|
|
|
class type client_link = object
|
|
|
|
inherit interface
|
|
|
|
method other_mac : Macaddr.t
|
2019-05-06 04:54:35 -04:00
|
|
|
method log_header : string (* For log messages *)
|
2020-04-29 09:58:01 -04:00
|
|
|
method get_rules: Pf_qubes.Parse_qubes.rule list
|
|
|
|
method set_rules: string Qubes.DB.KeyMap.t -> unit
|
2017-03-02 09:52:55 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
(** An Ethernet header from [src]'s MAC address to [dst]'s with an IPv4 payload. *)
|
|
|
|
let eth_header ethertype ~src ~dst =
|
2022-01-09 06:36:35 -05:00
|
|
|
Ethernet.Packet.make_cstruct { Ethernet.Packet.source = src; destination = dst; ethertype }
|
2017-03-02 09:52:55 -05:00
|
|
|
|
|
|
|
let error fmt =
|
|
|
|
let err s = Failure s in
|
|
|
|
Printf.ksprintf err fmt
|
|
|
|
|
|
|
|
let or_raise msg pp = function
|
|
|
|
| Ok x -> x
|
2021-11-05 14:59:00 -04:00
|
|
|
| Error e -> failwith (Fmt.str "%s: %a" msg pp e)
|