-
Notifications
You must be signed in to change notification settings - Fork 87
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
Fix udp socket #449
Fix udp socket #449
Conversation
@mirage/core this came out of using stack-socket. unfortunately SO_REUSEPORT is only available from OCaml 4.12 onwards -- anyone has problems with dropping earlier OCaml releases in tcpip? |
I'm personally happy with OCaml 4.12+ |
src/stack-unix/udpv4_socket.ml
Outdated
@@ -30,6 +30,7 @@ let get_udpv4_listening_fd {listen_fds;interface} port = | |||
Lwt.return @@ Hashtbl.find listen_fds (interface,port) | |||
with Not_found -> | |||
let fd = Lwt_unix.(socket PF_INET SOCK_DGRAM 0) in | |||
Lwt_unix.(setsockopt fd SO_REUSEPORT true); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this to allow multiple Unix processes to bind to the same port, to share responsibility for handling the requests?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is to allow the same unix process to bind to the same port several times, i.e. in DNS:
- we listen on UDP Ipaddr_any, 53 (via a listen callback) -- calls
bind(socket, *, 53)
- once a UDP frame is received, we take some time to find an answer, and eventually send from (, 53) to the client -- this means we have to bind as well to (, 53).
Without the REUSEPORT we can't bind to the same ip, port pair multiple times.
Hmmhmm, 4.12 is a bit higher for me. We should keep, at least, the support of the 3 last version of OCaml I think. |
ok, so what are the options?
Eventually, the SO_REUSEPORT is not required if -- similar to how Udpv4_socket (and Udpv6_socket) re-use listening sockets for writing. Unfortunately the lifetime of a socket is then infinite (with file descriptors leakage) -- I guess the stack-socket needs some enhancements anyways (and there should be the counterpart to llsten_tcp/listen_udp that stops the listener).
From my memory, we agreed to the last 2 OCaml versions -- and 4.13 is upcoming soon. I also think that the tcpip stack is barely used by others than MirageOS unikernels. IMHO it is fine to bump to 4.12 (and 4.13) for this library. So:
|
e51acc5
to
e26c153
Compare
So if we agree with that, it should fine so 👍. I largely prefer a non-buggy stack. |
we revised the implementation to address the file descriptor leaks (should solve #446 / #450). TL;DR: the socket stack any reviews welcome, I'm keen to merge and release a new version of tcpip without the leaks (plus the other changes in previous PRs). |
CHANGES: * This allows to listen on the same port as sending via UDP in the dual socket stack, and avoids file descriptor leaks in the socket stack. * Socket stack: avoid file descriptor leaks (remember opened file descriptors in data structure, close them in disconnect) (mirage/mirage-tcpip#449 @reynir @hannesm, fixes mirage/mirage-tcpip#446 mirage/mirage-tcpip#450) * Socket stack: convert an incoming packet on a dual socket to v4 source IP if received via IPv4 (mirage/mirage-tcpip#451 @reynir @hannesm) * Allow freestanding compilation without opam (mirage/mirage-tcpip#447 @sternenseemann) * Adapt to alcotest 1.4.0 breaking change (mirage/mirage-tcpip#448 @craigfe)
CHANGES: * This allows to listen on the same port as sending via UDP in the dual socket stack, and avoids file descriptor leaks in the socket stack. * Socket stack: avoid file descriptor leaks (remember opened file descriptors in data structure, close them in disconnect) (mirage/mirage-tcpip#449 @reynir @hannesm, fixes mirage/mirage-tcpip#446 mirage/mirage-tcpip#450) * Socket stack: convert an incoming packet on a dual socket to v4 source IP if received via IPv4 (mirage/mirage-tcpip#451 @reynir @hannesm) * Allow freestanding compilation without opam (mirage/mirage-tcpip#447 @sternenseemann) * Adapt to alcotest 1.4.0 breaking change (mirage/mirage-tcpip#448 @craigfe)
No description provided.