Skip to content

Commit e10e90b

Browse files
committed
fix: nocloud network link matching on MAC addresses
Fixes #9811 Fall back to non-permanent hardware addresses, ignore non-physical links (e.g. bonds). Signed-off-by: Andrey Smirnov <[email protected]>
1 parent 2a9130a commit e10e90b

File tree

2 files changed

+24
-1
lines changed

2 files changed

+24
-1
lines changed

internal/app/machined/pkg/runtime/v1alpha1/platform/nocloud/metadata.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -320,7 +320,15 @@ func (n *Nocloud) applyNetworkConfigV1(config *NetworkConfig, st state.State, ne
320320
macAddressMatched := false
321321

322322
for hostInterface := range hostInterfaces.All() {
323+
if !hostInterface.TypedSpec().Physical() {
324+
continue
325+
}
326+
323327
macAddress := hostInterface.TypedSpec().PermanentAddr.String()
328+
if macAddress == "" {
329+
macAddress = hostInterface.TypedSpec().HardwareAddr.String()
330+
}
331+
324332
if macAddress == ntwrk.Mac {
325333
name = hostInterface.Metadata().ID()
326334
macAddressMatched = true
@@ -626,7 +634,15 @@ func (n *Nocloud) applyNetworkConfigV2(config *NetworkConfig, st state.State, ne
626634
macAddressMatched := false
627635

628636
for hostInterface := range hostInterfaces.All() {
637+
if !hostInterface.TypedSpec().Physical() {
638+
continue
639+
}
640+
629641
macAddress := hostInterface.TypedSpec().PermanentAddr.String()
642+
if macAddress == "" {
643+
macAddress = hostInterface.TypedSpec().HardwareAddr.String()
644+
}
645+
630646
if macAddress == eth.Match.HWAddr {
631647
name = hostInterface.Metadata().ID()
632648
macAddressMatched = true

internal/app/machined/pkg/runtime/v1alpha1/platform/nocloud/nocloud_test.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,20 +63,27 @@ func TestParseMetadata(t *testing.T) {
6363

6464
st := state.WrapCore(namespaced.NewState(inmem.Build))
6565

66+
bond0 := network.NewLinkStatus(network.NamespaceName, "bond0")
67+
bond0.TypedSpec().PermanentAddr = nethelpers.HardwareAddr{0x68, 0x05, 0xca, 0xb8, 0xf1, 0xf7} // this link is not a physical one, so it should be ignored
68+
bond0.TypedSpec().Type = nethelpers.LinkEther
69+
bond0.TypedSpec().Kind = "bond"
70+
require.NoError(t, st.Create(context.TODO(), bond0))
71+
6672
eth0 := network.NewLinkStatus(network.NamespaceName, "eth0")
6773
eth0.TypedSpec().PermanentAddr = nethelpers.HardwareAddr{0x68, 0x05, 0xca, 0xb8, 0xf1, 0xf7}
6874
eth0.TypedSpec().Type = nethelpers.LinkEther
6975
eth0.TypedSpec().Kind = ""
7076
require.NoError(t, st.Create(context.TODO(), eth0))
7177

7278
eth1 := network.NewLinkStatus(network.NamespaceName, "eth1")
79+
eth1.TypedSpec().HardwareAddr = nethelpers.HardwareAddr{0x68, 0x05, 0xca, 0xb8, 0xf1, 0xf9} // this link has a permanent address, so hardware addr should be ignored
7380
eth1.TypedSpec().PermanentAddr = nethelpers.HardwareAddr{0x68, 0x05, 0xca, 0xb8, 0xf1, 0xf8}
7481
eth1.TypedSpec().Type = nethelpers.LinkEther
7582
eth1.TypedSpec().Kind = ""
7683
require.NoError(t, st.Create(context.TODO(), eth1))
7784

7885
eth2 := network.NewLinkStatus(network.NamespaceName, "eth2")
79-
eth2.TypedSpec().PermanentAddr = nethelpers.HardwareAddr{0x68, 0x05, 0xca, 0xb8, 0xf1, 0xf9}
86+
eth2.TypedSpec().HardwareAddr = nethelpers.HardwareAddr{0x68, 0x05, 0xca, 0xb8, 0xf1, 0xf9} // this link doesn't have a permanent address, but only a hardware address
8087
eth2.TypedSpec().Type = nethelpers.LinkEther
8188
eth2.TypedSpec().Kind = ""
8289
require.NoError(t, st.Create(context.TODO(), eth2))

0 commit comments

Comments
 (0)