Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions docs/vm-configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,10 @@ that take the following fields:
- `mac` (reqired): MAC address
- `dhcp` (optional, defaults to false): tells the VM to retrieve the IPv4 address
of this interface through DHCPv4.
- `addr` (required): IP address with subnet mask (in CIDR notation). This field
can be specified either zero times (when `dhcp` is specified), or at most
twice (once per IP family).
- `addr` (optional): IP address with subnet mask (in CIDR notation). This field
can be omitted (specified zero times) either when `dhcp` is enabled or when the
interface is intended to be L2-only (no IP assigned), and may be specified at
most twice otherwise (once per IP family).
- `features` (optional, defaults to 0): Bitwise-OR separated list of virtio-net
features. Supported features:
- `VIRTIO_NET_F_CSUM`: Device handles packets with partial checksum offload
Expand All @@ -61,6 +62,10 @@ that take the following fields:

Note that the first network specified will be used as the default gateway.

If neither `addr` nor `dhcp` are specified, the network interface will have no IP
address assigned and will be used exclusively to switch packets between the VM
and the host.

#### gvisor-tap-vsock

Here's an example using [containers/gvisor-tap-vsock](https://github.com/containers/gvisor-tap-vsock).
Expand Down
4 changes: 2 additions & 2 deletions internal/shim/task/networking_unix.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,8 +154,8 @@ func parseNetwork(annotation string) (network, error) {
}
}

if n.endpoint == "" || n.mode == "" || n.mac == nil || (!n.dhcp && !n.addr4.IsValid() && !n.addr6.IsValid()) {
return network{}, fmt.Errorf("either 'endpoint', 'mode', 'mac', 'dhcp' or 'addr' is missing")
if n.endpoint == "" || n.mode == "" || n.mac == nil {
return network{}, fmt.Errorf("missing required field(s): endpoint, mode, mac")
}

return n, nil
Expand Down
4 changes: 2 additions & 2 deletions internal/vminit/vmnetworking/vmnetworking.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ type Network struct {
}

func (nw Network) Validate() error {
if nw.MAC == nil || (!nw.Addr4.IsValid() && !nw.Addr6.IsValid() && !nw.DHCP) {
return errors.New("must specify either addr or dhcp")
if nw.MAC == nil {
return errors.New("must specify MAC address")
}
if (nw.Addr4.IsValid() || nw.Addr6.IsValid()) && nw.DHCP {
return errors.New("cannot specify both addr and dhcp")
Expand Down