diff --git a/charrua-client.opam b/charrua-client.opam index cd94f82..4974a23 100644 --- a/charrua-client.opam +++ b/charrua-client.opam @@ -27,12 +27,13 @@ depends: [ "mirage-clock" {>= "3.0.0"} "mirage-time" {>= "2.0.0"} "mirage-net" {>= "3.0.0"} - "mirage-protocols" {>= "4.0.0"} "duration" "logs" "fmt" + "ethernet" {>= "3.0.0"} + "arp" {>= "3.0.0"} + "tcpip" {>= "7.0.0"} "lwt" {>= "4.0.0"} - "tcpip" {>= "6.1.0" & with-test} ] build: [ ["dune" "subst"] {dev} diff --git a/charrua-server.opam b/charrua-server.opam index d9de9be..fea3091 100644 --- a/charrua-server.opam +++ b/charrua-server.opam @@ -40,7 +40,7 @@ depends: [ "macaddr-sexp" "cstruct-unix" {with-test} "ppx_cstruct" {>= "6.0.0" & with-test} - "tcpip" {>= "6.1.0" & with-test} + "tcpip" {>= "7.0.0" & with-test} "alcotest" {with-test & >= "1.4.0"} ] build: [ diff --git a/charrua-unix.opam b/charrua-unix.opam index 7523fb4..18528dd 100644 --- a/charrua-unix.opam +++ b/charrua-unix.opam @@ -22,7 +22,7 @@ depends: [ "mtime" {>= "1.0.0"} "cstruct-lwt" {>= "6.0.0"} "ipaddr" {>= "5.1.0"} - "tcpip" {>= "6.1.0"} + "tcpip" {>= "7.0.0"} ] build: [ ["dune" "subst"] {dev} diff --git a/charrua.opam b/charrua.opam index 0540680..912dee1 100644 --- a/charrua.opam +++ b/charrua.opam @@ -23,8 +23,8 @@ depends: [ "macaddr" {>= "4.0.0"} "ipaddr-sexp" "macaddr-sexp" - "ethernet" {>= "2.2.0"} - "tcpip" {>= "5.0.0"} + "ethernet" {>= "3.0.0"} + "tcpip" {>= "7.0.0"} ] conflicts: [ "result" {< "1.5"} ] synopsis: "DHCP wire frame encoder and decoder" diff --git a/client/lwt/dhcp_client_lwt.ml b/client/lwt/dhcp_client_lwt.ml index 9c895fe..0c62b9c 100644 --- a/client/lwt/dhcp_client_lwt.ml +++ b/client/lwt/dhcp_client_lwt.ml @@ -14,7 +14,7 @@ module Make(Random : Mirage_random.S)(Time : Mirage_time.S) (Net : Mirage_net.S) (* listener needs to occasionally check to see whether the state has advanced, * and if not, start a new attempt at a lease transaction *) let sleep_interval = Duration.of_sec 4 in - let header_size = Ethernet_wire.sizeof_ethernet in + let header_size = Ethernet.Packet.sizeof_ethernet in let size = Net.mtu net + header_size in let xid = match xid with diff --git a/client/mirage/dhcp_ipv4.ml b/client/mirage/dhcp_ipv4.ml index bc9d0e8..250be8b 100644 --- a/client/mirage/dhcp_ipv4.ml +++ b/client/mirage/dhcp_ipv4.ml @@ -1,6 +1,6 @@ open Lwt.Infix -module Make(R : Mirage_random.S) (C : Mirage_clock.MCLOCK) (Time : Mirage_time.S) (Network : Mirage_net.S) (E : Mirage_protocols.ETHERNET) (Arp : Mirage_protocols.ARP) = struct +module Make(R : Mirage_random.S) (C : Mirage_clock.MCLOCK) (Time : Mirage_time.S) (Network : Mirage_net.S) (E : Ethernet.S) (Arp : Arp.S) = struct (* for now, just wrap a static ipv4 *) module DHCP = Dhcp_client_mirage.Make(R)(Time)(Network) include Static_ipv4.Make(R)(C)(E)(Arp) diff --git a/client/mirage/dhcp_ipv4.mli b/client/mirage/dhcp_ipv4.mli index e6de4ca..05d8867 100644 --- a/client/mirage/dhcp_ipv4.mli +++ b/client/mirage/dhcp_ipv4.mli @@ -14,8 +14,8 @@ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. *) -module Make(R : Mirage_random.S) (C : Mirage_clock.MCLOCK) (Time : Mirage_time.S) (Network : Mirage_net.S) (E : Mirage_protocols.ETHERNET) (Arp : Mirage_protocols.ARP) : sig - include Mirage_protocols.IPV4 +module Make(R : Mirage_random.S) (C : Mirage_clock.MCLOCK) (Time : Mirage_time.S) (Network : Mirage_net.S) (E : Ethernet.S) (Arp : Arp.S) : sig + include Tcpip.Ip.S with type ipaddr = Ipaddr.V4.t val connect : Network.t -> E.t -> Arp.t -> t Lwt.t (** Connect to an ipv4 device using information from a DHCP lease. *) end diff --git a/client/mirage/dune b/client/mirage/dune index e7e114c..daf0fb7 100644 --- a/client/mirage/dune +++ b/client/mirage/dune @@ -2,5 +2,5 @@ (name dhcp_client_mirage) (public_name charrua-client.mirage) (libraries charrua-client.lwt ipaddr mirage-clock mirage-random mirage-time - mirage-net mirage-protocols logs) + mirage-net logs ethernet arp.mirage tcpip) (wrapped false)) diff --git a/lib/dhcp_wire.ml b/lib/dhcp_wire.ml index 58fc545..502a089 100644 --- a/lib/dhcp_wire.ml +++ b/lib/dhcp_wire.ml @@ -1082,15 +1082,15 @@ let buf_of_options sbuf options = let pkt_of_buf buf len = let open Printf in let wrap () = - let min_len = sizeof_dhcp + Ethernet_wire.sizeof_ethernet + + let min_len = sizeof_dhcp + Ethernet.Packet.sizeof_ethernet + Ipv4_wire.sizeof_ipv4 + Udp_wire.sizeof_udp in let* () = guard (len >= min_len) (sprintf "packet is too small: %d < %d" len min_len) in (* Handle ethernet *) - let* eth_header, eth_payload = Ethernet_packet.Unmarshal.of_cstruct buf in - match eth_header.Ethernet_packet.ethertype with + let* eth_header, eth_payload = Ethernet.Packet.of_cstruct buf in + match eth_header.Ethernet.Packet.ethertype with | `ARP | `IPv6 -> Error "packet is not ipv4" | `IPv4 -> let* ipv4_header, ipv4_payload = @@ -1135,8 +1135,8 @@ let pkt_of_buf buf len = let sname = cstruct_copy_normalized copy_dhcp_sname udp_payload in let file = cstruct_copy_normalized copy_dhcp_file udp_payload in let options = options_of_buf udp_payload len in - Ok { srcmac = eth_header.Ethernet_packet.source; - dstmac = eth_header.Ethernet_packet.destination; + Ok { srcmac = eth_header.Ethernet.Packet.source; + dstmac = eth_header.Ethernet.Packet.destination; srcip = ipv4_header.Ipv4_packet.src; dstip = ipv4_header.Ipv4_packet.dst; srcport = udp_header.Udp_packet.src_port; @@ -1147,7 +1147,7 @@ let pkt_of_buf buf len = try wrap () with | Invalid_argument e -> Error e let pkt_into_buf pkt buf = - let eth, rest = Cstruct.split buf Ethernet_wire.sizeof_ethernet in + let eth, rest = Cstruct.split buf Ethernet.Packet.sizeof_ethernet in let ip, rest' = Cstruct.split rest Ipv4_wire.sizeof_ipv4 in let udp, dhcp = Cstruct.split rest' Udp_wire.sizeof_udp in set_dhcp_op dhcp (op_to_int pkt.op); @@ -1185,7 +1185,7 @@ let pkt_into_buf pkt buf = in let dhcp = Cstruct.sub dhcp 0 (Cstruct.length dhcp - Cstruct.length buf_end) in (* Ethernet *) - (match Ethernet_packet.(Marshal.into_cstruct + (match Ethernet.Packet.(into_cstruct { source = pkt.srcmac; destination = pkt.dstmac; ethertype = `IPv4; } eth) @@ -1214,7 +1214,7 @@ let pkt_into_buf pkt buf = with | Ok () -> () | Error e -> invalid_arg e) ; - Ethernet_wire.sizeof_ethernet + Ipv4_wire.sizeof_ipv4 + + Ethernet.Packet.sizeof_ethernet + Ipv4_wire.sizeof_ipv4 + Udp_wire.sizeof_udp + Cstruct.length dhcp let buf_of_pkt pkg = @@ -1225,8 +1225,8 @@ let buf_of_pkt pkg = let is_dhcp buf _len = let aux buf = - let* eth_header, eth_payload = Ethernet_packet.Unmarshal.of_cstruct buf in - match eth_header.Ethernet_packet.ethertype with + let* eth_header, eth_payload = Ethernet.Packet.of_cstruct buf in + match eth_header.Ethernet.Packet.ethertype with | `ARP | `IPv6 -> Ok false | `IPv4 -> let* ipv4_header, ipv4_payload = diff --git a/test/client/dune b/test/client/dune index 08d1fd8..ab24a6d 100644 --- a/test/client/dune +++ b/test/client/dune @@ -1,5 +1,5 @@ (test (name test_client) (package charrua-client) - (libraries cstruct-unix alcotest charrua-client charrua-server tcpip.unix + (libraries cstruct-unix alcotest charrua-client charrua-server mirage-random-test)) diff --git a/test/client/lwt/dune b/test/client/lwt/dune index d912610..1e6fa1e 100644 --- a/test/client/lwt/dune +++ b/test/client/lwt/dune @@ -1,5 +1,4 @@ (test (name test_client_lwt) (package charrua-client) - (libraries cstruct-unix alcotest charrua-client.lwt lwt.unix mirage-random - tcpip.unix)) + (libraries cstruct-unix alcotest charrua-client.lwt lwt.unix mirage-random)) diff --git a/test/dune b/test/dune index 3953096..4bd664b 100644 --- a/test/dune +++ b/test/dune @@ -2,7 +2,7 @@ (name test) (package charrua-server) (preprocess (pps ppx_cstruct)) - (libraries cstruct-unix alcotest charrua charrua-server tcpip.unix)) + (libraries cstruct-unix alcotest charrua charrua-server)) (alias (name runtest) diff --git a/unix/dune b/unix/dune index d6ca1a6..ba76ca2 100644 --- a/unix/dune +++ b/unix/dune @@ -3,4 +3,4 @@ (public_name charruad) (package charrua-unix) (libraries charrua charrua-server lwt.unix cstruct-lwt cstruct-unix cmdliner - ipaddr tuntap rawlink.lwt mtime.clock.os tcpip.unix lwt_log)) + ipaddr tuntap rawlink.lwt mtime.clock.os lwt_log))