Skip to content

Commit e9331b2

Browse files
mcanevetsmira
authored andcommitted
feat(machined): support per-interface route metric for OpenNebula (ETH*_METRIC)
Parse ETHn_METRIC context variables and apply the value as the route priority for static default gateway routes and the DHCP4 operator's RouteMetric. When absent, the existing default of 1024 is preserved, matching the reference netcfg-networkd behavior. Signed-off-by: Mickaël Canévet <mickael.canevet@proton.ch> Signed-off-by: Andrey Smirnov <andrey.smirnov@siderolabs.com> (cherry picked from commit 7adbbd2)
1 parent 6e78afb commit e9331b2

File tree

5 files changed

+39
-8
lines changed

5 files changed

+39
-8
lines changed

internal/app/machined/pkg/runtime/v1alpha1/platform/opennebula/opennebula.go

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -294,6 +294,17 @@ func (o *OpenNebula) ParseMetadata(st state.State, oneContextPlain []byte) (*run
294294

295295
ifaceNameLower := strings.ToLower(ifaceName)
296296

297+
routeMetric := uint32(network.DefaultRouteMetric)
298+
299+
if metricStr := oneContext[ifaceName+"_METRIC"]; metricStr != "" {
300+
m, err := strconv.ParseUint(metricStr, 10, 32)
301+
if err != nil {
302+
return nil, fmt.Errorf("interface %s: failed to parse metric: %w", ifaceName, err)
303+
}
304+
305+
routeMetric = uint32(m)
306+
}
307+
297308
if oneContext[ifaceName+"_METHOD"] == "dhcp" {
298309
// Create DHCP4 OperatorSpec entry
299310
networkConfig.Operators = append(networkConfig.Operators,
@@ -302,7 +313,7 @@ func (o *OpenNebula) ParseMetadata(st state.State, oneContextPlain []byte) (*run
302313
LinkName: ifaceNameLower,
303314
RequireUp: true,
304315
DHCP4: network.DHCP4OperatorSpec{
305-
RouteMetric: 1024,
316+
RouteMetric: routeMetric,
306317
SkipHostnameRequest: true,
307318
},
308319
ConfigLayer: network.ConfigPlatform,
@@ -372,7 +383,7 @@ func (o *OpenNebula) ParseMetadata(st state.State, oneContextPlain []byte) (*run
372383
Protocol: nethelpers.ProtocolStatic,
373384
Type: nethelpers.TypeUnicast,
374385
Family: nethelpers.FamilyInet4,
375-
Priority: network.DefaultRouteMetric,
386+
Priority: routeMetric,
376387
}
377388

378389
route.Normalize()

internal/app/machined/pkg/runtime/v1alpha1/platform/opennebula/testdata/expected.yaml

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ routes:
2626
gateway: 192.168.1.1
2727
outLinkName: eth0
2828
table: main
29-
priority: 1024
29+
priority: 100
3030
scope: global
3131
type: unicast
3232
flags: ""
@@ -71,7 +71,14 @@ resolvers:
7171
- global.example.com
7272
- example.com
7373
timeServers: []
74-
operators: []
74+
operators:
75+
- operator: dhcp4
76+
linkName: eth1
77+
requireUp: true
78+
dhcp4:
79+
routeMetric: 200
80+
skipHostnameRequest: true
81+
layer: platform
7582
externalIPs: []
7683
metadata:
7784
platform: opennebula

internal/app/machined/pkg/runtime/v1alpha1/platform/opennebula/testdata/expected_no_network_flag.yaml

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ routes:
2626
gateway: 192.168.1.1
2727
outLinkName: eth0
2828
table: main
29-
priority: 1024
29+
priority: 100
3030
scope: global
3131
type: unicast
3232
flags: ""
@@ -71,7 +71,14 @@ resolvers:
7171
- global.example.com
7272
- example.com
7373
timeServers: []
74-
operators: []
74+
operators:
75+
- operator: dhcp4
76+
linkName: eth1
77+
requireUp: true
78+
dhcp4:
79+
routeMetric: 200
80+
skipHostnameRequest: true
81+
layer: platform
7582
externalIPs: []
7683
metadata:
7784
platform: opennebula

internal/app/machined/pkg/runtime/v1alpha1/platform/opennebula/testdata/metadata.yaml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ ETH0_IP6_ULA = ""
1919
ETH0_MAC = "02:00:c0:a8:01:5c"
2020
ETH0_MASK = "255.255.255.0"
2121
ETH0_METHOD = ""
22-
ETH0_METRIC = ""
22+
ETH0_METRIC = "100"
2323
ETH0_MTU = ""
2424
ETH0_NETWORK = "192.168.1.0"
2525
ETH0_ROUTES = "10.0.0.0 255.0.0.0 192.168.1.1, 172.16.0.0 255.255.0.0 192.168.1.1 500"
@@ -33,4 +33,7 @@ NETWORK = "YES"
3333
SSH_PUBLIC_KEY = ""
3434
TARGET = "hda"
3535
VMID = "14"
36+
ETH1_MAC = "02:00:c0:a8:01:5d"
37+
ETH1_METHOD = "dhcp"
38+
ETH1_METRIC = "200"
3639
NAME = "code-server"

internal/app/machined/pkg/runtime/v1alpha1/platform/opennebula/testdata/metadata_no_network_flag.yaml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ ETH0_IP6_ULA = ""
2121
ETH0_MAC = "02:00:c0:a8:01:5c"
2222
ETH0_MASK = "255.255.255.0"
2323
ETH0_METHOD = ""
24-
ETH0_METRIC = ""
24+
ETH0_METRIC = "100"
2525
ETH0_MTU = ""
2626
ETH0_NETWORK = "192.168.1.0"
2727
ETH0_ROUTES = "10.0.0.0 255.0.0.0 192.168.1.1, 172.16.0.0 255.255.0.0 192.168.1.1 500"
@@ -35,4 +35,7 @@ NETWORK = "NO"
3535
SSH_PUBLIC_KEY = ""
3636
TARGET = "hda"
3737
VMID = "14"
38+
ETH1_MAC = "02:00:c0:a8:01:5d"
39+
ETH1_METHOD = "dhcp"
40+
ETH1_METRIC = "200"
3841
NAME = "code-server"

0 commit comments

Comments
 (0)