12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364(*
* Copyright (c) 2011-2015 Anil Madhavapeddy <anil@recoil.org>
* Copyright (c) 2013-2015 Thomas Gazagnaire <thomas@gazagnaire.org>
* Copyright (c) 2013 Citrix Systems Inc
* Copyright (c) 2018 Hannes Mehnert <hannes@mehnert.org>
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*)moduleNet=structtypeerror=[Mirage_device.error|`Invalid_length]letpp_errorppf=function|#Mirage_device.errorase->Mirage_device.pp_errorppfe|`Invalid_length->Fmt.stringppf"invalid length (exceeds size)"endtypestats={mutablerx_bytes:int64;mutablerx_pkts:int32;mutabletx_bytes:int64;mutabletx_pkts:int32;}moduleStats=structletcreate()={rx_pkts=0l;rx_bytes=0L;tx_pkts=0l;tx_bytes=0L}letrxtsize=t.rx_pkts<-Int32.succt.rx_pkts;t.rx_bytes<-Int64.addt.rx_bytessizelettxtsize=t.tx_pkts<-Int32.succt.tx_pkts;t.tx_bytes<-Int64.addt.tx_bytessizeletresett=t.rx_bytes<-0L;t.rx_pkts<-0l;t.tx_bytes<-0L;t.tx_pkts<-0lendmoduletypeS=sigtypeerror=private[>Net.error]valpp_error:errorFmt.ttypebuffertypemacaddrincludeMirage_device.Svalwrite:t->size:int->(buffer->int)->(unit,error)resultiovallisten:t->header_size:int->(buffer->unitio)->(unit,error)resultiovalmac:t->macaddrvalmtu:t->intvalget_stats_counters:t->statsvalreset_stats_counters:t->unitend