Skip to content
Merged
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
7 changes: 1 addition & 6 deletions pkg/cidata/cidata.TEMPLATE.d/network-config
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,7 @@ ethernets:
dhcp4: true
set-name: {{$nw.Interface}}
dhcp4-overrides:
{{- if (eq $nw.Interface $.SlirpNICName) }}
route-metric: 200
{{- else }}
route-metric: 100
{{- end }}
route-metric: {{$nw.Metric}}
{{- if and (eq $nw.Interface $.SlirpNICName) (gt (len $.DNSAddresses) 0) }}
nameservers:
addresses:
Expand All @@ -20,4 +16,3 @@ ethernets:
{{- end }}
{{- end }}
{{- end }}

4 changes: 2 additions & 2 deletions pkg/cidata/cidata.go
Original file line number Diff line number Diff line change
Expand Up @@ -256,12 +256,12 @@ func templateArgs(bootScripts bool, instDir, name string, instConfig *limayaml.L
})
}

args.Networks = append(args.Networks, Network{MACAddress: limayaml.MACAddress(instDir), Interface: networks.SlirpNICName})
args.Networks = append(args.Networks, Network{MACAddress: limayaml.MACAddress(instDir), Interface: networks.SlirpNICName, Metric: 200})
for i, nw := range instConfig.Networks {
if i == firstUsernetIndex {
continue
}
args.Networks = append(args.Networks, Network{MACAddress: nw.MACAddress, Interface: nw.Interface})
args.Networks = append(args.Networks, Network{MACAddress: nw.MACAddress, Interface: nw.Interface, Metric: *nw.Metric})
}

args.Env, err = setupEnv(instConfig.Env, *instConfig.PropagateProxyEnv, args.SlirpGateway)
Expand Down
1 change: 1 addition & 0 deletions pkg/cidata/template.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ type Containerd struct {
type Network struct {
MACAddress string
Interface string
Metric uint32
}
type Mount struct {
Tag string
Expand Down
6 changes: 6 additions & 0 deletions pkg/limayaml/defaults.go
Original file line number Diff line number Diff line change
Expand Up @@ -609,6 +609,9 @@ func FillDefault(y, d, o *LimaYAML, filePath string, warn bool) {
if nw.MACAddress != "" {
networks[i].MACAddress = nw.MACAddress
}
if nw.Metric != nil {
networks[i].Metric = nw.Metric
}
} else {
// unnamed network definitions are not combined/overwritten
if nw.Interface != "" {
Expand All @@ -627,6 +630,9 @@ func FillDefault(y, d, o *LimaYAML, filePath string, warn bool) {
if nw.Interface == "" {
nw.Interface = "lima" + strconv.Itoa(i)
}
if nw.Metric == nil {
nw.Metric = ptr.Of(uint32(100))
}
}

y.MountTypesUnsupported = append(append(o.MountTypesUnsupported, y.MountTypesUnsupported...), d.MountTypesUnsupported...)
Expand Down
3 changes: 3 additions & 0 deletions pkg/limayaml/defaults_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,7 @@ func TestFillDefault(t *testing.T) {
expect.Networks = slices.Clone(y.Networks)
expect.Networks[0].MACAddress = MACAddress(fmt.Sprintf("%s#%d", filePath, 0))
expect.Networks[0].Interface = "lima0"
expect.Networks[0].Metric = ptr.Of(uint32(100))

expect.DNS = slices.Clone(y.DNS)
expect.PortForwards = []PortForward{
Expand Down Expand Up @@ -401,6 +402,7 @@ func TestFillDefault(t *testing.T) {
{
MACAddress: "11:22:33:44:55:66",
Interface: "def0",
Metric: ptr.Of(uint32(50)),
},
},
DNS: []net.IP{
Expand Down Expand Up @@ -622,6 +624,7 @@ func TestFillDefault(t *testing.T) {
Lima: "shared",
MACAddress: "10:20:30:40:50:60",
Interface: "def1",
Metric: ptr.Of(uint32(25)),
},
{
Lima: "bridged",
Expand Down
5 changes: 3 additions & 2 deletions pkg/limayaml/limayaml.go
Original file line number Diff line number Diff line change
Expand Up @@ -274,8 +274,9 @@ type Network struct {
// VZNAT uses VZNATNetworkDeviceAttachment. Needs VZ. No root privilege is required.
VZNAT *bool `yaml:"vzNAT,omitempty" json:"vzNAT,omitempty"`

MACAddress string `yaml:"macAddress,omitempty" json:"macAddress,omitempty"`
Interface string `yaml:"interface,omitempty" json:"interface,omitempty"`
MACAddress string `yaml:"macAddress,omitempty" json:"macAddress,omitempty"`
Interface string `yaml:"interface,omitempty" json:"interface,omitempty"`
Metric *uint32 `yaml:"metric,omitempty" json:"metric,omitempty"`
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

limactl start now prints

WARN[0000] vmType vz: ignoring networks[0]: [Metric]

}

type HostResolver struct {
Expand Down
3 changes: 3 additions & 0 deletions templates/default.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -384,6 +384,9 @@ networks:
# macAddress: ""
# # Interface name, defaults to "lima0", "lima1", etc.
# interface: ""
# # Interface metric, lowest metric becomes the preferred route.
# # Defaults to 100. Builtin SLIRP network uses 200.
# metric: 100
#
# Lima can also connect to "unmanaged" networks addressed by "socket". This
# means that the daemons will not be controlled by Lima, but must be started
Expand Down
Loading