1616 *)
1717open Lwt.Infix
1818
19- [@@@ warning " -52" ]
20- open Mirage_net
21-
2219let src = Logs.Src. create " netif" ~doc: " Mirage unix network module"
2320module Log = (val Logs. src_log src : Logs.LOG )
2421
25- type +'a io = 'a Lwt .t
26-
2722type 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 *)
8979let 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
165153let 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
0 commit comments