This commit is contained in:
swrup 2025-11-11 02:07:51 +01:00
parent aa2ff7b2f0
commit 2f3113f55d
11742 changed files with 1223940 additions and 0 deletions

View file

@ -0,0 +1,4 @@
_build
*.install
*~
.merlin

View file

@ -0,0 +1,45 @@
### v4.0.0 (2021-11-15)
- remove dependency on mirage-device (#24 @hannesm)
- remove Mirage_net_lwt module (#24 @hannesm)
- add `Disconnected to Mirage_net.Net.error (@hannesm)
### v3.0.1 (2019-11-04)
- provide deprecated Mirage_net_lwt for smooth transition (#23 @hannesm)
### v3.0.0 (2019-10-22)
- remove mirage-net-lwt (#21 @hannesm)
- specialise to Lwt.t, Cstruct.t, Macaddr.t (#21 @hannesm)
- raise lower OCaml bound to 4.06.0 (#21 @hannesm)
### v2.0.0 (2019-02-24)
- Improvements to the write path (#15, #18 @hannesm)
* remove `page_aligned_buffer` and `io-page` dependency
* remove `writev`
* provide `mtu : t -> int`
* adjust `write : t -> size:int -> (buffer -> int) -> (unit, error) result io`
-> allocation is done by the mirage-net implementation, and the buffer is
filled by the upper layers. once filled, it is send out.
- Port build to dune from jbuilder (#16 @avsm)
- Switch to dune-release instead of topkg (#16 @avsm)
### v1.2.0 (2019-01-10)
- Use macaddr opam package (since ipaddr 3.0.0, macaddr is a separate opam package)
- Port to opam2
### v1.1.1 (2017-06-29)
- Fix an issue with linking with the `Result` module on 4.04 on Linux.
### v1.1.0 (2017-05-30)
- Port to [Jbuilder](https://github.com/janestreet/jbuilder).
### v1.0.0 (2016-12-26)
- Add Stats module from `mirage-net-xen` for common use
- Initial version, code imported from <https://github.com/mirage/mirage>

View file

@ -0,0 +1,11 @@
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.

View file

@ -0,0 +1,13 @@
.PHONY: build clean test
build:
dune build
test:
dune runtest
install:
dune install
clean:
dune clean

View file

@ -0,0 +1,22 @@
## mirage-net -- Network signatures for MirageOS
mirage-net defines [Mirage_net.S][1] the signature for
network operations for MirageOS.
[1]: https://mirage.github.io/mirage-net/Mirage_net.S.html
### Installation
`mirage-net` can be installed with `opam`:
opam install mirage-net
If you don't use `opam` consult the [`opam`](opam) file for build
instructions.
### Documentation
The documentation and API reference is automatically generated by
`ocamldoc` from the interfaces. It can be consulted [online][2].
[2]: https://mirage.github.io/mirage-net/Mirage_net.html

View file

@ -0,0 +1,3 @@
(lang dune 1.0)
(name mirage-net)
(version v4.0.0)

View file

@ -0,0 +1,30 @@
version: "4.0.0"
opam-version: "2.0"
maintainer: "thomas@gazagnaire.org"
homepage: "https://github.com/mirage/mirage-net"
bug-reports: "https://github.com/mirage/mirage-net/issues"
dev-repo: "git+https://github.com/mirage/mirage-net.git"
doc: "https://mirage.github.io/mirage-net/"
authors: ["Thomas Gazagnaire" "Anil Madhavapeddy" "Gabriel Radanne"
"Mindy Preston" "Thomas Leonard" "Nicolas Ojeda Bar"
"Dave Scott" "David Kaloper" "Hannes Mehnert" "Richard Mortier"]
tags: [ "org:mirage"]
license: "ISC"
build: [
["dune" "subst"] {dev}
["dune" "build" "-p" name "-j" jobs]
]
depends: [
"ocaml" {>= "4.08.0"}
"dune" {>= "1.0"}
"fmt"
"macaddr" {>= "4.0.0"}
"cstruct" {>= "4.0.0"}
"lwt" {>= "4.0.0"}
]
synopsis: "Network signatures for MirageOS"
description: """
mirage-net defines `Mirage_net.S`, the signature for network operations for MirageOS.
"""

View file

@ -0,0 +1,4 @@
(library
(name mirage_net)
(public_name mirage-net)
(libraries fmt cstruct macaddr lwt))

View file

@ -0,0 +1,63 @@
(*
* 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.
*)
module Net = struct
type error = [ `Invalid_length | `Disconnected ]
let pp_error ppf = function
| `Invalid_length -> Fmt.string ppf "invalid length (exceeds size)"
| `Disconnected -> Fmt.string ppf "network device is disconnected"
end
type stats = {
mutable rx_bytes: int64;
mutable rx_pkts: int32;
mutable tx_bytes: int64;
mutable tx_pkts: int32;
}
module Stats = struct
let create () = { rx_pkts=0l; rx_bytes=0L; tx_pkts=0l; tx_bytes=0L }
let rx t size =
t.rx_pkts <- Int32.succ t.rx_pkts;
t.rx_bytes <- Int64.add t.rx_bytes size
let tx t size =
t.tx_pkts <- Int32.succ t.tx_pkts;
t.tx_bytes <- Int64.add t.tx_bytes size
let reset t =
t.rx_bytes <- 0L;
t.rx_pkts <- 0l;
t.tx_bytes <- 0L;
t.tx_pkts <- 0l
end
module type S = sig
type error = private [> Net.error ]
val pp_error: error Fmt.t
type t
val disconnect : t -> unit Lwt.t
val write: t -> size:int -> (Cstruct.t -> int) -> (unit, error) result Lwt.t
val listen: t -> header_size:int -> (Cstruct.t -> unit Lwt.t) -> (unit, error) result Lwt.t
val mac: t -> Macaddr.t
val mtu: t -> int
val get_stats_counters: t -> stats
val reset_stats_counters: t -> unit
end

View file

@ -0,0 +1,103 @@
(*
* 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-2019 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.
*)
(** Network devices
[Mirage_net] defines the signature for MirageOS network devices.
{e Release v4.0.0 } *)
module Net : sig
type error = [ `Invalid_length | `Disconnected ]
(** The type for IO operation errors *)
val pp_error: error Fmt.t
(** [pp_error] pretty-print network errors. *)
end
type stats = {
mutable rx_bytes: int64;
mutable rx_pkts: int32;
mutable tx_bytes: int64;
mutable tx_pkts: int32;
}
(** The type for frame statistics to track the usage of the device. *)
(** {2 Networking} *)
(** A network interface that serves Ethernet frames. *)
module type S = sig
type error = private [> Net.error]
(** The type for network interface errors. *)
val pp_error: error Fmt.t
(** [pp_error] is the pretty-printer for errors. *)
type t
(** The type representing the internal state of the network device. *)
val disconnect: t -> unit Lwt.t
(** Disconnect from the network device. While this might take some time to
complete, it can never result in an error. *)
val write: t -> size:int -> (Cstruct.t -> int) -> (unit, error) result Lwt.t
(** [write net ~size fill] allocates a buffer of length [size], where [size]
must not exceed the interface maximum packet size ({!mtu} plus Ethernet
header). The allocated buffer is zeroed and passed to the [fill] function
which returns the payload length, which may not exceed the length of the
buffer. When [fill] returns, a sub buffer is put on the wire: the allocated
buffer from index 0 to the returned length. *)
val listen: t -> header_size:int -> (Cstruct.t -> unit Lwt.t) -> (unit, error) result Lwt.t
(** [listen ~header_size net fn] waits for a [packet] with size at most
[header_size + mtu] on the network device. When a [packet] is received, an
asynchronous task is created in which [fn packet] is called. The ownership
of [packet] is transferred to [fn]. The function can be stopped by calling
{!disconnect}. *)
val mac: t -> Macaddr.t
(** [mac net] is the MAC address of [net]. *)
val mtu: t -> int
(** [mtu net] is the Maximum Transmission Unit of [net]. This excludes the
Ethernet header. *)
val get_stats_counters: t -> stats
(** Obtain the most recent snapshot of the interface statistics. *)
val reset_stats_counters: t -> unit
(** Reset the statistics associated with this interface to their
defaults. *)
end
module Stats : sig
val create: unit -> stats
(** [create ()] returns a fresh set of zeroed counters *)
val rx: stats -> int64 -> unit
(** [rx t size] records that we received a packet of length [size] *)
val tx: stats -> int64 -> unit
(** [tx t size] records that we transmitted a packet of length [size] *)
val reset: stats -> unit
(** [reset t] resets all packet counters in [t] to 0 *)
end