Skip to content

Commit

Permalink
update to ethernet, arp 3.0.0
Browse files Browse the repository at this point in the history
Signed-off-by: David Scott <dave@recoil.org>

ethernet

Signed-off-by: David Scott <dave@recoil.org>
  • Loading branch information
djs55 committed Jan 17, 2022
1 parent 47cebca commit ee2e5c0
Show file tree
Hide file tree
Showing 8 changed files with 26 additions and 25 deletions.
2 changes: 1 addition & 1 deletion src/hostnet/filter.ml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ module Make(Input: Sig.VMNET) = struct
let write t ~size fill = Input.write t.input ~size fill >|= lift_error

let filter valid_subnets valid_sources next buf =
match Ethernet_packet.Unmarshal.of_cstruct buf with
match Ethernet.Packet.of_cstruct buf with
| Ok (_header, payload) ->
let src = Ipaddr.V4.of_int32 @@ Ipv4_wire.get_ipv4_src payload in
let from_valid_networks =
Expand Down
6 changes: 3 additions & 3 deletions src/hostnet/hostnet_dhcp.ml
Original file line number Diff line number Diff line change
Expand Up @@ -173,10 +173,10 @@ module Make (Clock: Mirage_clock.MCLOCK) (Netif: Mirage_net.S) = struct
pre-allocated IP anyway, but this will present a problem if
that assumption ever changes. *)
let database = ref (Dhcp_server.Lease.make_db ()) in
match Ethernet_packet.Unmarshal.of_cstruct buf with
match Ethernet.Packet.of_cstruct buf with
| Ok (pkt, _payload) when
of_interest t.server_macaddr pkt.Ethernet_packet.destination ->
(match pkt.Ethernet_packet.ethertype with
of_interest t.server_macaddr pkt.Ethernet.Packet.destination ->
(match pkt.Ethernet.Packet.ethertype with
| `IPv4 ->
if Dhcp_wire.is_dhcp buf (Cstruct.length buf) then begin
input t.netif (t.get_dhcp_configuration ()) !database buf
Expand Down
14 changes: 7 additions & 7 deletions src/hostnet/hostnet_dns.ml
Original file line number Diff line number Diff line change
Expand Up @@ -253,9 +253,9 @@ struct
packet creation fn *)
let frame = Io_page.to_cstruct (Io_page.get 1) in
let smac = "\000\000\000\000\000\000" in
Ethernet_wire.set_ethernet_src smac 0 frame;
Ethernet_wire.set_ethernet_ethertype frame 0x0800;
let buf = Cstruct.shift frame Ethernet_wire.sizeof_ethernet in
Ethernet__Ethernet_wire.set_ethernet_src smac 0 frame;
Ethernet__Ethernet_wire.set_ethernet_ethertype frame 0x0800;
let buf = Cstruct.shift frame Ethernet.Packet.sizeof_ethernet in
Ipv4_wire.set_ipv4_hlen_version buf ((4 lsl 4) + (5));
Ipv4_wire.set_ipv4_tos buf 0;
Ipv4_wire.set_ipv4_ttl buf 38;
Expand All @@ -264,7 +264,7 @@ struct
Ipv4_wire.set_ipv4_src buf (Ipaddr.V4.to_int32 source_ip);
Ipv4_wire.set_ipv4_dst buf (Ipaddr.V4.to_int32 dest_ip);
let header_len =
Ethernet_wire.sizeof_ethernet + Ipv4_wire.sizeof_ipv4
Ethernet.Packet.sizeof_ethernet + Ipv4_wire.sizeof_ipv4
in

let frame = Cstruct.sub frame 0 (header_len + Udp_wire.sizeof_udp) in
Expand All @@ -276,12 +276,12 @@ struct
(* Only for recording, no need to set a checksum. *)
(* Ip.writev *)
let bufs = frame :: bufs in
let tlen = Cstruct.lenv bufs - Ethernet_wire.sizeof_ethernet in
let tlen = Cstruct.lenv bufs - Ethernet.Packet.sizeof_ethernet in
let dmac = String.make 6 '\000' in
(* Ip.adjust_output_header *)
Ethernet_wire.set_ethernet_dst dmac 0 frame;
Ethernet__Ethernet_wire.set_ethernet_dst dmac 0 frame;
let buf =
Cstruct.sub frame Ethernet_wire.sizeof_ethernet Ipv4_wire.sizeof_ipv4
Cstruct.sub frame Ethernet.Packet.sizeof_ethernet Ipv4_wire.sizeof_ipv4
in
(* Set the mutable values in the ipv4 header *)
Ipv4_wire.set_ipv4_len buf tlen;
Expand Down
2 changes: 1 addition & 1 deletion src/hostnet/mux.ml
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ module Make (Netif: Mirage_net.S) = struct
let t = { netif; rules; default_callback } in
Lwt.async
(fun () ->
Netif.listen netif ~header_size:Ethernet_wire.sizeof_ethernet @@ callback t >>= function
Netif.listen netif ~header_size:Ethernet.Packet.sizeof_ethernet @@ callback t >>= function
| Ok () -> Lwt.return_unit
| Error _e ->
Log.err (fun f -> f "Mux.connect calling Netif.listen: failed");
Expand Down
14 changes: 7 additions & 7 deletions src/hostnet/slirp.ml
Original file line number Diff line number Diff line change
Expand Up @@ -554,7 +554,7 @@ struct
let tcp_stack = { endpoint; udp_nat; dns_ips } in
let open Lwt.Infix in
(* Wire up the listeners to receive future packets: *)
Switch.Port.listen ~header_size:Ethernet_wire.sizeof_ethernet endpoint.Endpoint.netif
Switch.Port.listen ~header_size:Ethernet.Packet.sizeof_ethernet endpoint.Endpoint.netif
(fun buf ->
let open Frame in
match parse [ buf ] with
Expand Down Expand Up @@ -681,7 +681,7 @@ struct
let tcp_stack = { endpoint; udp_nat; dns_ips; localhost_names; localhost_ips } in
let open Lwt.Infix in
(* Wire up the listeners to receive future packets: *)
Switch.Port.listen ~header_size:Ethernet_wire.sizeof_ethernet endpoint.Endpoint.netif
Switch.Port.listen ~header_size:Ethernet.Packet.sizeof_ethernet endpoint.Endpoint.netif
(fun buf ->
let open Frame in
match parse [ buf ] with
Expand Down Expand Up @@ -780,7 +780,7 @@ struct
let tcp_stack = { endpoint; udp_nat; icmp_nat; localhost_names; localhost_ips } in
let open Lwt.Infix in
(* Wire up the listeners to receive future packets: *)
Switch.Port.listen ~header_size:Ethernet_wire.sizeof_ethernet endpoint.Endpoint.netif
Switch.Port.listen ~header_size:Ethernet.Packet.sizeof_ethernet endpoint.Endpoint.netif
(fun buf ->
let open Frame in
match parse [ buf ] with
Expand Down Expand Up @@ -1130,7 +1130,7 @@ struct
vnet_client_id
(Macaddr.to_string eth_src)
(Macaddr.to_string eth_dst));
(Switch.write ~size:Ethernet_wire.sizeof_ethernet switch (fun toBuf ->
(Switch.write ~size:Ethernet.Packet.sizeof_ethernet switch (fun toBuf ->
Cstruct.blit buf 0 toBuf 0 (Cstruct.length buf);
Cstruct.length buf)
>|= function
Expand All @@ -1144,7 +1144,7 @@ struct
Log.info (fun f ->
f "Client mac: %s server mac: %s"
(Macaddr.to_string client_macaddr) (Macaddr.to_string c.Configuration.server_macaddr));
Switch.listen switch ~header_size:Ethernet_wire.sizeof_ethernet (fun buf ->
Switch.listen switch ~header_size:Ethernet.Packet.sizeof_ethernet (fun buf ->
let open Frame in
match parse [ buf ] with
| Ok (Ethernet { src = eth_src ; dst = eth_dst ; _ }) when
Expand All @@ -1157,7 +1157,7 @@ struct
(Macaddr.to_string eth_src) (Macaddr.to_string eth_dst));
(* pass to virtual network *)
begin
Vnet.write vnet_switch t.vnet_client_id ~size:Ethernet_wire.sizeof_ethernet (fun toBuf ->
Vnet.write vnet_switch t.vnet_client_id ~size:Ethernet.Packet.sizeof_ethernet (fun toBuf ->
Cstruct.blit buf 0 toBuf 0 (Cstruct.length buf);
Cstruct.length buf)
>|= function
Expand Down Expand Up @@ -1190,7 +1190,7 @@ struct
|> Lwt.return)
end
>>= fun arp ->
Global_arp.input arp (Cstruct.shift buf Ethernet_wire.sizeof_ethernet)
Global_arp.input arp (Cstruct.shift buf Ethernet.Packet.sizeof_ethernet)
| Ok (Ethernet { payload = Ipv4 ({ src; dst; _ } as ipv4 ); _ }) ->
(* For any new IP destination, create a stack to proxy for
the remote system *)
Expand Down
6 changes: 3 additions & 3 deletions src/hostnet/static_arp.ml
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,14 @@ let src =

module Log = (val Logs.src_log src : Logs.LOG)

module Make (Ethif: Mirage_protocols.ETHERNET) = struct
module Make (Ethif: Ethernet.S) = struct

module Table = Map.Make(Ipaddr.V4)

type macaddr = Macaddr.t
type t = { ethif: Ethif.t; mutable table: macaddr Table.t }
type error = Mirage_protocols.Arp.error
let pp_error = Mirage_protocols.Arp.pp_error
type error = [ `Timeout ]
let pp_error ppf `Timeout = Fmt.string ppf "Timeout"

let to_string t =
let pp_one (ip, mac) =
Expand Down
4 changes: 2 additions & 2 deletions src/hostnet/static_arp.mli
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
rely on the dynamic version which can fail with `No_route_to_host` if
the other side doesn't respond *)

module Make(Ethif: Mirage_protocols.ETHERNET): sig
include Mirage_protocols.ARP
module Make(Ethif: Ethernet.S): sig
include Arp.S

type ethif = Ethif.t

Expand Down
3 changes: 2 additions & 1 deletion vpnkit.opam
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ depends: [
"logs"
"fmt"
"astring"
"arp" {= "2.3.1"}
"ethernet" {>= "3.0.0"}
"arp" {>= "3.0.0"}
"mirage-device" {= "2.0.0"}
"mirage-kv" {= "3.0.1"}
"mirage-net" {= "3.0.1"}
Expand Down

0 comments on commit ee2e5c0

Please sign in to comment.