Skip to content

Commit

Permalink
Merge pull request #116 from hannesm/no-mirage-protocols
Browse files Browse the repository at this point in the history
avoid mirage-protocols
  • Loading branch information
hannesm authored Dec 15, 2021
2 parents b42b89e + 98fec12 commit a06207e
Show file tree
Hide file tree
Showing 13 changed files with 26 additions and 26 deletions.
5 changes: 3 additions & 2 deletions charrua-client.opam
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down
2 changes: 1 addition & 1 deletion charrua-server.opam
Original file line number Diff line number Diff line change
Expand Up @@ -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: [
Expand Down
2 changes: 1 addition & 1 deletion charrua-unix.opam
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down
4 changes: 2 additions & 2 deletions charrua.opam
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion client/lwt/dhcp_client_lwt.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion client/mirage/dhcp_ipv4.ml
Original file line number Diff line number Diff line change
@@ -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)
Expand Down
4 changes: 2 additions & 2 deletions client/mirage/dhcp_ipv4.mli
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion client/mirage/dune
Original file line number Diff line number Diff line change
Expand Up @@ -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))
20 changes: 10 additions & 10 deletions lib/dhcp_wire.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
Expand Down Expand Up @@ -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;
Expand All @@ -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);
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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 =
Expand All @@ -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 =
Expand Down
2 changes: 1 addition & 1 deletion test/client/dune
Original file line number Diff line number Diff line change
@@ -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))
3 changes: 1 addition & 2 deletions test/client/lwt/dune
Original file line number Diff line number Diff line change
@@ -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))
2 changes: 1 addition & 1 deletion test/dune
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion unix/dune
Original file line number Diff line number Diff line change
Expand Up @@ -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))

0 comments on commit a06207e

Please sign in to comment.