From ee2e5c0f7fd3100715957af2d6b497fbf90806db Mon Sep 17 00:00:00 2001 From: David Scott Date: Mon, 17 Jan 2022 10:36:20 +0000 Subject: [PATCH] update to ethernet, arp 3.0.0 Signed-off-by: David Scott ethernet Signed-off-by: David Scott --- src/hostnet/filter.ml | 2 +- src/hostnet/hostnet_dhcp.ml | 6 +++--- src/hostnet/hostnet_dns.ml | 14 +++++++------- src/hostnet/mux.ml | 2 +- src/hostnet/slirp.ml | 14 +++++++------- src/hostnet/static_arp.ml | 6 +++--- src/hostnet/static_arp.mli | 4 ++-- vpnkit.opam | 3 ++- 8 files changed, 26 insertions(+), 25 deletions(-) diff --git a/src/hostnet/filter.ml b/src/hostnet/filter.ml index ffc16e78e..f84a57ab0 100644 --- a/src/hostnet/filter.ml +++ b/src/hostnet/filter.ml @@ -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 = diff --git a/src/hostnet/hostnet_dhcp.ml b/src/hostnet/hostnet_dhcp.ml index 9f3790228..a2349d86a 100644 --- a/src/hostnet/hostnet_dhcp.ml +++ b/src/hostnet/hostnet_dhcp.ml @@ -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 diff --git a/src/hostnet/hostnet_dns.ml b/src/hostnet/hostnet_dns.ml index ba78ee2aa..d243239ea 100644 --- a/src/hostnet/hostnet_dns.ml +++ b/src/hostnet/hostnet_dns.ml @@ -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; @@ -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 @@ -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; diff --git a/src/hostnet/mux.ml b/src/hostnet/mux.ml index e9635213a..da0f04b77 100644 --- a/src/hostnet/mux.ml +++ b/src/hostnet/mux.ml @@ -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"); diff --git a/src/hostnet/slirp.ml b/src/hostnet/slirp.ml index 72f57ed7a..b0a46bfd6 100644 --- a/src/hostnet/slirp.ml +++ b/src/hostnet/slirp.ml @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 *) diff --git a/src/hostnet/static_arp.ml b/src/hostnet/static_arp.ml index cf7e05c4a..822e7d09f 100644 --- a/src/hostnet/static_arp.ml +++ b/src/hostnet/static_arp.ml @@ -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) = diff --git a/src/hostnet/static_arp.mli b/src/hostnet/static_arp.mli index e09c69ea9..7b8473094 100644 --- a/src/hostnet/static_arp.mli +++ b/src/hostnet/static_arp.mli @@ -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 diff --git a/vpnkit.opam b/vpnkit.opam index c71595b31..364a5f154 100644 --- a/vpnkit.opam +++ b/vpnkit.opam @@ -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"}