Skip to content

Commit 5d8f257

Browse files
authored
Merge pull request #48 from hannesm/easy
adapt to mirage-net 3.0.0 (instead of mirage-net-lwt) signature:
2 parents c3085dd + 1d72433 commit 5d8f257

File tree

6 files changed

+16
-29
lines changed

6 files changed

+16
-29
lines changed

.travis.yml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,8 @@ script: bash -ex ./.travis-docker.sh
77
env:
88
global:
99
- PACKAGE="mirage-net-unix"
10-
- EXTRA_REMOTES="https://github.com/mirage/mirage-dev.git"
1110
matrix:
12-
- DISTRO="alpine" OCAML_VERSION="4.04"
13-
- DISTRO="alpine" OCAML_VERSION="4.05"
1411
- DISTRO="alpine" OCAML_VERSION="4.06"
1512
- DISTRO="alpine" OCAML_VERSION="4.07"
13+
- DISTRO="alpine" OCAML_VERSION="4.08"
14+
- DISTRO="alpine" OCAML_VERSION="4.09"

CHANGES.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
### v2.7.0 (25-Oct-2019)
2+
3+
* Adapt to mirage-net 3.0.0 changes (@hannesm)
4+
15
### v2.6.0 (26-Feb-2019)
26

37
* Adapt to mirage-net 2.0.0 changs (@hannesm)

mirage-net-unix.opam

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,12 @@ homepage: "https://github.com/mirage/mirage-net-unix"
88
doc: "https://mirage.github.io/mirage-net-unix/"
99
bug-reports: "https://github.com/mirage/mirage-net-unix/issues"
1010
depends: [
11-
"ocaml" {>= "4.04.2"}
11+
"ocaml" {>= "4.06.0"}
1212
"dune" {>= "1.0"}
1313
"cstruct" {>= "1.7.1"}
1414
"cstruct-lwt"
1515
"lwt" {>= "2.4.3"}
16-
"mirage-net-lwt" {>= "2.0.0"}
16+
"mirage-net" {>= "3.0.0"}
1717
"tuntap" {>= "1.8.0"}
1818
"alcotest" {with-test}
1919
"logs"

src/dune

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
(library
22
(name mirage_net_unix)
33
(public_name mirage-net-unix)
4-
(libraries logs macaddr cstruct cstruct-lwt lwt.unix mirage-net-lwt tuntap)
4+
(libraries logs macaddr cstruct cstruct-lwt lwt.unix mirage-net tuntap)
55
(wrapped false))

src/netif.ml

Lines changed: 6 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,9 @@
1616
*)
1717
open Lwt.Infix
1818

19-
[@@@warning "-52"]
20-
open Mirage_net
21-
2219
let src = Logs.Src.create "netif" ~doc:"Mirage unix network module"
2320
module Log = (val Logs.src_log src : Logs.LOG)
2421

25-
type +'a io = 'a Lwt.t
26-
2722
type t = {
2823
id: string;
2924
dev: Lwt_unix.file_descr;
@@ -64,14 +59,12 @@ let connect devname =
6459
Log.debug (fun m -> m "plugging into %s with mac %a and mtu %d"
6560
devname Macaddr.pp mac mtu);
6661
let active = true in
67-
let t = {
68-
id=devname; dev; active; mac; mtu;
69-
stats= { rx_bytes=0L;rx_pkts=0l; tx_bytes=0L; tx_pkts=0l } }
70-
in
62+
let stats = Mirage_net.Stats.create () in
63+
let t = { id=devname; dev; active; mac; mtu; stats } in
7164
Log.info (fun m -> m "connect %s with mac %a" devname Macaddr.pp mac);
7265
Lwt.return t
7366
with
74-
| Failure "tun[open]: Permission denied" ->
67+
| Failure "tun[open]: Permission denied" [@warning "-52"] ->
7568
Lwt.fail_with (err_permission_denied devname)
7669
| exn -> Lwt.fail exn
7770

@@ -82,9 +75,6 @@ let disconnect t =
8275
Tuntap.closetap t.id;
8376
Lwt.return_unit
8477

85-
type macaddr = Macaddr.t
86-
type buffer = Cstruct.t
87-
8878
(* Input a frame, and block if nothing is available *)
8979
let rec read t buf =
9080
let process () =
@@ -93,8 +83,7 @@ let rec read t buf =
9383
| (-1) -> Error `Continue (* EAGAIN or EWOULDBLOCK *)
9484
| 0 -> Error `Disconnected (* EOF *)
9585
| len ->
96-
t.stats.rx_pkts <- Int32.succ t.stats.rx_pkts;
97-
t.stats.rx_bytes <- Int64.add t.stats.rx_bytes (Int64.of_int len);
86+
Mirage_net.Stats.rx t.stats (Int64.of_int len);
9887
let buf = Cstruct.sub buf 0 len in
9988
Ok buf)
10089
(function
@@ -152,8 +141,7 @@ let write t ~size fillf =
152141
else
153142
Lwt.catch (fun () ->
154143
Lwt_bytes.write t.dev buf.Cstruct.buffer 0 len >|= fun len' ->
155-
t.stats.tx_pkts <- Int32.succ t.stats.tx_pkts;
156-
t.stats.tx_bytes <- Int64.add t.stats.tx_bytes (Int64.of_int len);
144+
Mirage_net.Stats.tx t.stats (Int64.of_int len);
157145
if len' <> len then Error (`Partial (t.id, len', buf))
158146
else Ok ())
159147
(fun exn -> Lwt.return (Error (`Exn exn)))
@@ -164,8 +152,4 @@ let mtu t = t.mtu
164152

165153
let get_stats_counters t = t.stats
166154

167-
let reset_stats_counters t =
168-
t.stats.rx_bytes <- 0L;
169-
t.stats.rx_pkts <- 0l;
170-
t.stats.tx_bytes <- 0L;
171-
t.stats.tx_pkts <- 0l
155+
let reset_stats_counters t = Mirage_net.Stats.reset t.stats

src/netif.mli

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717

1818
(** Implementation of the network interface for Unix backends. *)
1919

20-
include Mirage_net_lwt.S
20+
include Mirage_net.S
2121

2222
val connect : string -> t Lwt.t
2323
(** [connect tap] connects to the given tap interface. *)

0 commit comments

Comments
 (0)