Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

less packages, less abstraction #110

Merged
merged 2 commits into from
Nov 25, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 0 additions & 18 deletions .travis.yml

This file was deleted.

6 changes: 1 addition & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,18 +1,14 @@
## Charrua DHCP - a DHCP client, server and wire frame encoder and decoder


[![docs](https://img.shields.io/badge/doc-online-blue.svg)](https://mirage.github.io/charrua/)
[![Build Status](https://travis-ci.org/mirage/charrua.svg)](https://travis-ci.org/mirage/charrua)

[charrua](http://www.github.com/mirage/charrua) is an
_ISC-licensed_ DHCP library implementation in OCaml.
It provides five packages:
It provides the following packages:

- charrua: a library that handles wire traffic parsing
- charrua-server: a DHCP server implementation
- charrua-client: a library for handling DHCP client state and messages
- charrua-client-lwt: a DHCP client library with timeouts and network read/write
- charrua-client-mirage: a MirageOS-compatible set of interfaces to charrua-client-lwt
- charrua-unix: a Unix DHCP server implementation

### Charrua
38 changes: 0 additions & 38 deletions charrua-client-lwt.opam

This file was deleted.

32 changes: 0 additions & 32 deletions charrua-client-mirage.opam

This file was deleted.

9 changes: 9 additions & 0 deletions charrua-client.opam
Original file line number Diff line number Diff line change
@@ -24,6 +24,15 @@ depends: [
"cstruct" {>="3.0.2"}
"ipaddr" {>= "5.0.0"}
"macaddr" {>= "4.0.0"}
"mirage-random" {>= "2.0.0"}
"mirage-clock" {>= "3.0.0"}
"mirage-time" {>= "2.0.0"}
"mirage-net" {>= "3.0.0"}
"mirage-protocols" {>= "4.0.0"}
"duration"
"logs"
"fmt"
"lwt" {>= "4.0.0"}
]
synopsis: "DHCP client implementation"
description: """
2 changes: 1 addition & 1 deletion client/lwt/dune
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
(library
(name dhcp_client_lwt)
(public_name charrua-client-lwt)
(public_name charrua-client.lwt)
(modules dhcp_client_lwt)
(libraries charrua lwt charrua-client cstruct ipaddr mirage-time
mirage-random mirage-net duration fmt logs))
10 changes: 4 additions & 6 deletions client/mirage/dhcp_client_mirage.ml
Original file line number Diff line number Diff line change
@@ -4,7 +4,7 @@ module Log = (val Logs.src_log src : Logs.LOG)
let config_of_lease lease =
let open Dhcp_wire in
(* ipv4_config expects a single IP address and the information
* needed to construct a prefix. It can optionally use one router. *)
needed to construct a prefix. It can optionally use one router. *)
let address = lease.yiaddr in
match Dhcp_wire.find_subnet_mask lease.options with
| None ->
@@ -19,18 +19,16 @@ let config_of_lease lease =
| Ok network ->
let valid_routers = Dhcp_wire.collect_routers lease.options in
match valid_routers with
| [] -> Some Mirage_protocols.{ address; network; gateway = None }
| hd::_ ->
Some Mirage_protocols.{ address; network; gateway = Some hd }
| [] -> Some (network, None)
| hd::_ -> Some (network, Some hd)

module Make(Random : Mirage_random.S)(Time : Mirage_time.S) (Net : Mirage_net.S) = struct
open Lwt.Infix

type t = Mirage_protocols.ipv4_config Lwt_stream.t
type t = (Ipaddr.V4.Prefix.t * Ipaddr.V4.t option) Lwt_stream.t

let connect ?(requests : Dhcp_wire.option_code list option) net =
let module Lwt_client = Dhcp_client_lwt.Make(Random)(Time)(Net) in
Lwt_client.connect ~renew:false ?requests net >>= fun lease_stream ->
Lwt.return @@ Lwt_stream.filter_map config_of_lease lease_stream

end
16 changes: 8 additions & 8 deletions client/mirage/dhcp_client_mirage.mli
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
module Make(Random : Mirage_random.S)(Time : Mirage_time.S) (Network : Mirage_net.S) : sig
type t = Mirage_protocols.ipv4_config Lwt_stream.t
type t = (Ipaddr.V4.Prefix.t * Ipaddr.V4.t option) Lwt_stream.t
val connect : ?requests:Dhcp_wire.option_code list
-> Network.t -> t Lwt.t
(** [connect ?requests net] attempts to use [net] to obtain a valid
* DHCP lease containing the DHCP option codes listed in [request].
* If [request] is not specified, [connect] uses the default values
* provided by the upstream Dhcp_client implementation, which are
* a small set useful in establishing ipv4 connectivity.
* [connect] does not time out; it will terminate on send/receive
* errors or when a lease is obtained.
* *)
DHCP lease containing the DHCP option codes listed in [request].
If [request] is not specified, [connect] uses the default values
provided by the upstream Dhcp_client implementation, which are
a small set useful in establishing ipv4 connectivity.
[connect] does not time out; it will terminate on send/receive
errors or when a lease is obtained.
*)
end
10 changes: 6 additions & 4 deletions client/mirage/dhcp_ipv4.ml
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
open Lwt.Infix

module Make(Dhcp_client : Mirage_protocols.DHCP_CLIENT) (R : Mirage_random.S) (C : Mirage_clock.MCLOCK) (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 : Mirage_protocols.ETHERNET) (Arp : Mirage_protocols.ARP) = 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)
let connect dhcp ethernet arp =
Lwt_stream.last_new dhcp >>= fun (config : Mirage_protocols.ipv4_config) ->
connect ~cidr:config.network ?gateway:config.gateway ethernet arp
let connect net ethernet arp =
DHCP.connect net >>= fun dhcp ->
Lwt_stream.last_new dhcp >>= fun (cidr, gateway) ->
connect ~cidr ?gateway ethernet arp
end
4 changes: 2 additions & 2 deletions client/mirage/dhcp_ipv4.mli
Original file line number Diff line number Diff line change
@@ -14,8 +14,8 @@
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*)

module Make (D: Mirage_protocols.DHCP_CLIENT) (R : Mirage_random.S) (C : Mirage_clock.MCLOCK) (E:Mirage_protocols.ETHERNET) (A: Mirage_protocols.ARP) : sig
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
val connect : D.t -> E.t -> A.t -> t Lwt.t
val connect : Network.t -> E.t -> Arp.t -> t Lwt.t
(** Connect to an ipv4 device using information from a DHCP lease. *)
end
4 changes: 2 additions & 2 deletions client/mirage/dune
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
(library
(name dhcp_client_mirage)
(public_name charrua-client-mirage)
(libraries charrua-client-lwt ipaddr mirage-clock mirage-random mirage-time
(public_name charrua-client.mirage)
(libraries charrua-client.lwt ipaddr mirage-clock mirage-random mirage-time
mirage-net mirage-protocols logs)
(wrapped false))
4 changes: 2 additions & 2 deletions test/client/lwt/dune
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
(test
(name test_client_lwt)
(package charrua-client-lwt)
(libraries cstruct-unix alcotest charrua-client-lwt lwt.unix mirage-random
(package charrua-client)
(libraries cstruct-unix alcotest charrua-client.lwt lwt.unix mirage-random
tcpip.unix))