-
Notifications
You must be signed in to change notification settings - Fork 661
Support for lima usernet network #1383
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
package main | ||
|
||
import ( | ||
"errors" | ||
"fmt" | ||
"os" | ||
"strconv" | ||
|
||
"github.com/lima-vm/lima/pkg/networks/usernet" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
func newUsernetCommand() *cobra.Command { | ||
var hostagentCommand = &cobra.Command{ | ||
Use: "usernet", | ||
Short: "run usernet", | ||
Args: cobra.ExactArgs(0), | ||
RunE: usernetAction, | ||
Hidden: true, | ||
} | ||
hostagentCommand.Flags().StringP("pidfile", "p", "", "write pid to file") | ||
hostagentCommand.Flags().StringP("endpoint", "e", "", "exposes usernet api(s) on this endpoint") | ||
hostagentCommand.Flags().String("listen-qemu", "", "listen for qemu connections") | ||
hostagentCommand.Flags().String("listen", "", "listen on a Unix socket and receive Bess-compatible FDs as SCM_RIGHTS messages") | ||
hostagentCommand.Flags().Int("mtu", 1500, "mtu") | ||
return hostagentCommand | ||
} | ||
|
||
func usernetAction(cmd *cobra.Command, args []string) error { | ||
pidfile, err := cmd.Flags().GetString("pidfile") | ||
if err != nil { | ||
return err | ||
} | ||
if pidfile != "" { | ||
if _, err := os.Stat(pidfile); !errors.Is(err, os.ErrNotExist) { | ||
return fmt.Errorf("pidfile %q already exists", pidfile) | ||
} | ||
if err := os.WriteFile(pidfile, []byte(strconv.Itoa(os.Getpid())+"\n"), 0644); err != nil { | ||
return err | ||
} | ||
defer os.RemoveAll(pidfile) | ||
} | ||
endpoint, err := cmd.Flags().GetString("endpoint") | ||
if err != nil { | ||
return err | ||
} | ||
qemuSocket, err := cmd.Flags().GetString("listen-qemu") | ||
if err != nil { | ||
return err | ||
} | ||
fdSocket, err := cmd.Flags().GetString("listen") | ||
if err != nil { | ||
return err | ||
} | ||
|
||
mtu, err := cmd.Flags().GetInt("mtu") | ||
if err != nil { | ||
return err | ||
} | ||
|
||
os.RemoveAll(endpoint) | ||
os.RemoveAll(qemuSocket) | ||
os.RemoveAll(fdSocket) | ||
|
||
return usernet.StartGVisorNetstack(cmd.Context(), &usernet.GVisorNetstackOpts{ | ||
MTU: mtu, | ||
Endpoint: endpoint, | ||
QemuSocket: qemuSocket, | ||
FdSocket: fdSocket, | ||
}) | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -193,3 +193,33 @@ networks: | |
The range of the IP address is not specifiable. | ||
|
||
The "vzNAT" network does not need the `socket_vmnet` binary and the `sudoers` file. | ||
|
||
## Lima user-v2 network | ||
|
||
user-v2 network provides a user-mode networking similar to the [default user-mode network](#user-mode-network--1921685024-) and also provides support for `vm -> vm` communication. | ||
|
||
> **Warning** | ||
> This network mode is experimental | ||
|
||
To enable this network mode, define a network with `mode: user-v2` in networks.yaml | ||
|
||
```yaml | ||
... | ||
networks: | ||
example-user-v2: | ||
mode: user-v2 | ||
... | ||
``` | ||
|
||
Instances can then reference these networks from their `lima.yaml` file: | ||
|
||
```yaml | ||
networks: | ||
- lima: example-user-v2 | ||
``` | ||
|
||
_Note_ | ||
|
||
- Enabling this network will disable the [default user-mode network](#user-mode-network--1921685024-) | ||
- Subnet used for this network is 192.168.5.0/24 with 192.168.5.2 used for host connection and 192.168.5.3 used for DNS resolution | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this configurable or not? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not configurable as of now. I will provide this support in a follow-up PR. |
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
# Example to run lima instance with experimental user-v2 network enabled | ||
images: | ||
- location: "https://cloud-images.ubuntu.com/releases/22.04/release/ubuntu-22.04-server-cloudimg-amd64.img" | ||
arch: "x86_64" | ||
- location: "https://cloud-images.ubuntu.com/releases/22.04/release/ubuntu-22.04-server-cloudimg-arm64.img" | ||
arch: "aarch64" | ||
|
||
mounts: | ||
- location: "~" | ||
- location: "/tmp/lima" | ||
writable: true | ||
networks: | ||
- lima: user-v2 |
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.
What are drawbacks?
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.
Only drawback i see is,
Running high number of vm's under this network might add bottleneck from gvisor-tap-vsock.