Show HN: unsock: shim to automatically change AF_INET sockets to AF_UNIX, etc. (github.com)
unsock is an LD_PRELOAD-able Linux library that converts AF_INET socket connections to AF_UNIX, AF_VSOCK, AF_TIPC, etc, helping reduce the dependency on TCP/UDP/IP for local communication.
It even handles the painful "CONNECT" proxy dance on Firecracker AF_UNIX/AF_VSOCK multiplexing sockets for you.
8 comments
[ 19.6 ms ] story [ 598 ms ] threadHowever, I can see that running code in a Hypervisor environment may benefit from static linking, and yes, unsock may have a hard time intercepting the syscalls.
In that scenario, I think adding kernel-level support for the mapping, like what libkrun's "Transparent Socket Impersonation" patches attempt, may be a viable alternative (see README.md)
I haven't deeply looked into it, but there's also the seccomp/ptrace interception route, which could achieve something like that from userland, but I suspect it's too heavy on performance.
[1] https://github.com/nixcloud/ip2unix
As far as I can tell the main differences are 1. ip2unix is AF_UNIX-only (but does map AF_INET6), and 2. that it maintains an internal mapping instead of using dup3.
This teaches people it's OK to use predictable names in /tmp. Don't do that.