Obtain socket fd from netstack

15 views
Skip to first unread message

pronebird

unread,
Sep 3, 2024, 6:15:16 AM9/3/24
to gVisor Users [Public]
Hi,

I'd like to exclude netstack traffic from being routed over the tunnel device, typically I'd need a socket fd for that. Does anyone know how to extract the socket fd from gonet.UDPConn?

Best,
Andrej

Kevin Krakauer

unread,
Sep 3, 2024, 12:52:51 PM9/3/24
to pronebird, gVisor Users [Public]
Hi Andrej. Two things:

- In order to create a gonet.UDPConn that sends data over a socket, the socket has to be manually created (and then used to create an NIC in the netstack that gonet is using). Do you not have access to that socket?
- UDPConn (and TCPConn) lack a function for this because they aren't always based on sockets. They could work over a unix pipe, Go channel, or any other transport. You could maybe embed UDPConn in your own type that's capable of remembering the socket FD used to initialize it.

Kevin

--
You received this message because you are subscribed to the Google Groups "gVisor Users [Public]" group.
To unsubscribe from this group and stop receiving emails from it, send an email to gvisor-users...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/gvisor-users/86c3d1c1-25c2-4611-ba6d-fbb8156f211bn%40googlegroups.com.

Andrej Mihajlov

unread,
Sep 3, 2024, 2:49:40 PM9/3/24
to Kevin Krakauer, gVisor Users [Public]
Hi Kevin,

Thanks for a quick reply. I am probably looking in the wrong place. I am using netstack with wireguard-go, so perhaps I need to obtain the socket fd from wireguard-go itself since it uses channels to interact with netstack, at least based on my ability to read go code.

Best,
Andrej
Reply all
Reply to author
Forward
0 new messages