-
Notifications
You must be signed in to change notification settings - Fork 279
Force runtime to use custom Conn from netstack #29
Comments
Not without hacking the go runtime. |
Are you aware of any project that does this? I.e. modify the "net" package to use netstack. I'm going to try doing that. But if it already exists, that would be even better. |
I am pretty sure that it does not exist. We do have a package called gonet which creates net.Conn types backed by netstack. |
For example, I had to modify https://github.com/dutchcoders/goftp to be able to set a DialFunc which, if not nil, is called instead of the standard net Dial for the data transfer. The DialFunc is basically a wrapper for the gonet.DialTCP Other packages like ssh are pretty easy since you can wrap it around an existing connection. |
I've got some really hacky proof of concept code that does tcp & udp using netstack. E.g. I can just have regular code with http.ListenAndServe or http.Get, and it works with a tun device. I'm now configuring the stack through an env var GONET, setup with an init(), eg: GONET=ip=10.0.1.2,mtu=1500,sniff=yes. The changes I made are currently part of more changes to the runtime, I'll see if I can isolate this, and make it less hacky. Would be nice if building your code with a netstack buildtag would get you a netstack-based net package. The trick is finding the right (small) amount of changes to existing files in the net package that make this maintainable. |
Experimental code at https://github.com/mjl-/vmgo/tree/netstack, see README. Summary: "go build -tags netstack app.go" followed by "GONET=...netconfig... ./app". Only on linux for now. I've only done basic manual tests: net.Dial and net.Listen, and http.ListenAndServe and http.Get. Some notes about netstack & gonet:
|
@mjl- This is really neat! I was just checking out your project. I was reading the description and trying to understand what you are trying to do. The description just says So netstack is mostly developed as part of gVisor and it's also used by Fuchsia. As a result most of the link layer code assumes linux as target and amd64 though we have recently been getting pull requests to add support run gVisor/Netstack on arm64/linux as well. It should be possible to move these constants into platform specific bits in netstack and make most of the netstack code not use the unix package. If you would like you could send some of your changes as pull requests on gVisor repo and we can figure out a way to make this work. This repo is mostly a read-only replica and we don't really accept contributions here. |
There's some more info in the README of the nofiles branch at https://github.com/mjl-/vmgo. My end-goal is to compile existing, unmodified Go code to a (slim) virtual machine image that runs on a simple monitor (solo5?, firecracker?, learning as I go...). My approach was to start with an existing target (openbsd/amd64) and trim away (replace with pure Go code) the functionality the OS provides, like the file system, the network stack. I was happily surprised to find netstack and see it work so well, thanks! I'll have a look at gVisor and how to make changes there. |
Super cool! You may find more pieces you can use for your project in the gVisor repository. Its goal is to use Go to greatly reduce the host API surface required to run an unmodified Linux app. |
I'm getting tired of forking different golang projects to get them to use the conn interface from this project. Is there a way to get the runtime to always use a given netstack interface? Thanks!
The text was updated successfully, but these errors were encountered: