Skip to content

Commit

Permalink
feat: implement 'permanent addr' in link statuses
Browse files Browse the repository at this point in the history
Permanent address is only available for physical links, and it might be
different from the 'hardware address': when bonding, 'hardware address'
gets overridden from the bond master, while 'permanent address' still
shows MAC of the interface.

This part of the fix for incorrect bonding issue on Equinix Metal.

Signed-off-by: Andrey Smirnov <[email protected]>
  • Loading branch information
smira committed Sep 26, 2022
1 parent c90e202 commit 0b2767c
Show file tree
Hide file tree
Showing 9 changed files with 308 additions and 230 deletions.
1 change: 1 addition & 0 deletions api/resource/definitions/network/network.proto
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,7 @@ message LinkStatusSpec {
BridgeMasterSpec bridge_master = 27;
BondMasterSpec bond_master = 28;
WireguardSpec wireguard = 29;
bytes permanent_addr = 30;
}

// NodeAddressFilterSpec describes a filter for NodeAddresses.
Expand Down
18 changes: 14 additions & 4 deletions internal/app/machined/pkg/controllers/network/link_status.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"context"
"errors"
"fmt"
"net"
"os"

"github.com/cosi-project/runtime/pkg/controller"
Expand Down Expand Up @@ -152,10 +153,11 @@ func (ctrl *LinkStatusController) reconcile(
link := link

var (
ethState *ethtool.LinkState
ethInfo *ethtool.LinkInfo
ethMode *ethtool.LinkMode
driverInfo ethtoolioctl.DrvInfo
ethState *ethtool.LinkState
ethInfo *ethtool.LinkInfo
ethMode *ethtool.LinkMode
driverInfo ethtoolioctl.DrvInfo
permanentAddr net.HardwareAddr
)

if ethClient != nil {
Expand Down Expand Up @@ -190,13 +192,21 @@ func (ctrl *LinkStatusController) reconcile(

if ethtoolIoctlClient != nil {
driverInfo, _ = ethtoolIoctlClient.DriverInfo(link.Attributes.Name) //nolint:errcheck

var permAddr string

permAddr, err = ethtoolIoctlClient.PermAddr(link.Attributes.Name)
if err == nil && permAddr != "" {
permanentAddr, _ = net.ParseMAC(permAddr) //nolint:errcheck
}
}

if err = r.Modify(ctx, network.NewLinkStatus(network.NamespaceName, link.Attributes.Name), func(r resource.Resource) error {
status := r.(*network.LinkStatus).TypedSpec()

status.Index = link.Index
status.HardwareAddr = nethelpers.HardwareAddr(link.Attributes.Address)
status.PermanentAddr = nethelpers.HardwareAddr(permanentAddr)
status.BroadcastAddr = nethelpers.HardwareAddr(link.Attributes.Broadcast)
status.LinkIndex = link.Attributes.Type
status.Flags = nethelpers.LinkFlags(link.Flags)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,10 +153,11 @@ func (suite *LinkStatusSuite) TestInterfaceHwInfo() {
emptyFields := []string{}

for key, value := range map[string]string{
"hw addr": spec.HardwareAddr.String(),
"driver": spec.Driver,
"bus path": spec.BusPath,
"PCI id": spec.PCIID,
"hw addr": spec.HardwareAddr.String(),
"perm addr": spec.PermanentAddr.String(),
"driver": spec.Driver,
"bus path": spec.BusPath,
"PCI id": spec.PCIID,
} {
if value == "" {
emptyFields = append(emptyFields, key)
Expand Down
455 changes: 233 additions & 222 deletions pkg/machinery/api/resource/definitions/network/network.pb.go

Large diffs are not rendered by default.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions pkg/machinery/resources/network/deep_copy.generated.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions pkg/machinery/resources/network/link_status.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ type LinkStatusSpec struct {
LinkIndex uint32 `yaml:"linkIndex" protobuf:"3"`
Flags nethelpers.LinkFlags `yaml:"flags" protobuf:"4"`
HardwareAddr nethelpers.HardwareAddr `yaml:"hardwareAddr" protobuf:"5"`
PermanentAddr nethelpers.HardwareAddr `yaml:"permanentAddr" protobuf:"30"`
BroadcastAddr nethelpers.HardwareAddr `yaml:"broadcastAddr" protobuf:"6"`
MTU uint32 `yaml:"mtu" protobuf:"7"`
QueueDisc string `yaml:"queueDisc" protobuf:"8"`
Expand Down
2 changes: 2 additions & 0 deletions pkg/machinery/resources/network/link_status_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ func TestLinkStatusMarshalYAML(t *testing.T) {
LinkIndex: 44,
Flags: nethelpers.LinkFlags(nethelpers.LinkUp | nethelpers.LinkRunning),
HardwareAddr: nethelpers.HardwareAddr(hwAddr),
PermanentAddr: nethelpers.HardwareAddr(hwAddr),
BroadcastAddr: nethelpers.HardwareAddr(bcAddr),
MTU: 1500,
QueueDisc: "fifo",
Expand Down Expand Up @@ -109,6 +110,7 @@ type: ether
linkIndex: 44
flags: UP,RUNNING
hardwareAddr: 01:23:45:67:89:ab
permanentAddr: 01:23:45:67:89:ab
broadcastAddr: ff:ff:ff:ff:ff:ff
mtu: 1500
queueDisc: fifo
Expand Down
1 change: 1 addition & 0 deletions website/content/v1.3/reference/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -2509,6 +2509,7 @@ LinkStatusSpec describes status of rendered secrets.
| bridge_master | [BridgeMasterSpec](#talos.resource.definitions.network.BridgeMasterSpec) | | |
| bond_master | [BondMasterSpec](#talos.resource.definitions.network.BondMasterSpec) | | |
| wireguard | [WireguardSpec](#talos.resource.definitions.network.WireguardSpec) | | |
| permanent_addr | [bytes](#bytes) | | |



Expand Down

0 comments on commit 0b2767c

Please sign in to comment.