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

Revise the "fill" signature in Ethernet (and likely other layers) #9

Open
hannesm opened this issue Dec 20, 2019 · 1 comment
Open

Comments

@hannesm
Copy link
Member

hannesm commented Dec 20, 2019

The issue at hand is:

            E.write eth dst `IPv4 (fun b ->
                match Nat_packet.into_cstruct packet b with
                | Ok n -> n
                | Ok (n, adds) -> more := adds ; n
                | Error e ->
                  (* E.write takes a fill function (Cstruct.t -> int), which
                     can not result in an error. Now, if Nat_packet results in
                     an error (e.g. need to fragment, but fragmentation is not
                     allowed (don't fragment bit is set)), we can't pass this
                     information up the stack. Instead we log an error and
                     return 0 -- thus an empty Ethernet header will be
                     transmitted on the wire. *)
                  (* TODO an ICMP error should be sent to the packet origin *)
                  Log.err (fun m -> m "error %a while Nat_packet.into_cstruct"
                              Nat_packet.pp_error e);
                  0)

The ethernet write was called in order to allocate the buffer by the network device, and filling it is done via Nat_packet, which may fail (if don't fragment is set, and fragmentation is required). Instead of returning an int from E.write, it should be possible to result in an error, which can then be handled by the caller of write. I think I remember similar code elsewhere as well. May be worth to revise in the same go as Cstruct_cap gets used.

Further discussion by @cfcs in robur-coop/miragevpn#8 (comment)

@hannesm hannesm changed the title Revise the fill" Revise the fill" signature in Ethernet (and likely other layers) Dec 20, 2019
@hannesm hannesm changed the title Revise the fill" signature in Ethernet (and likely other layers) Revise the "fill" signature in Ethernet (and likely other layers) Dec 20, 2019
@hannesm
Copy link
Member Author

hannesm commented Dec 20, 2019

it may even be nice to use:

val write : t -> ?size:int -> (Cstruct.t -> (int * 'a, 'b) result) -> ('a, error | 'b) result Lwt.t

which would allow a smooth API for Nat_packet.into_cstruct, though I'm not sure how to express the error | 'b in OCaml (error is a polymorphic variant so it should be extensible, but 'b is just a type variable).

@hannesm hannesm transferred this issue from mirage/mirage-protocols Dec 15, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant