Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: provide ethtool-style features #9167

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
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
2 changes: 2 additions & 0 deletions api/resource/definitions/network/network.proto
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,8 @@ message LinkStatusSpec {
BondMasterSpec bond_master = 28;
WireguardSpec wireguard = 29;
bytes permanent_addr = 30;
map<string, string> features = 31;
map<string, bool> private_flags = 32;
}

// NfTablesAddressMatch describes the match on the IP address.
Expand Down
16 changes: 16 additions & 0 deletions internal/app/machined/pkg/controllers/network/link_status.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
"golang.zx2c4.com/wireguard/wgctrl/wgtypes"

networkadapter "github.com/siderolabs/talos/internal/app/machined/pkg/adapters/network"
networkutils "github.com/siderolabs/talos/internal/app/machined/pkg/controllers/network/utils"
"github.com/siderolabs/talos/internal/app/machined/pkg/controllers/network/watch"
"github.com/siderolabs/talos/internal/app/machined/pkg/controllers/runtime"
"github.com/siderolabs/talos/internal/pkg/pci"
Expand Down Expand Up @@ -166,6 +167,8 @@ func (ctrl *LinkStatusController) reconcile(
ethMode *ethtool.LinkMode
driverInfo ethtoolioctl.DrvInfo
permanentAddr net.HardwareAddr
features map[string]ethtoolioctl.FeatureState
privateFlags map[string]bool
)

if ethClient != nil {
Expand Down Expand Up @@ -221,6 +224,16 @@ func (ctrl *LinkStatusController) reconcile(
}
}
}

features, err = ethtoolIoctlClient.FeaturesWithState(link.Attributes.Name)
if err != nil {
logger.Warn("error querying ethtool ioctl features", zap.String("link", link.Attributes.Name), zap.Error(err))
}

privateFlags, err = ethtoolIoctlClient.PrivFlags(link.Attributes.Name)
if err != nil {
logger.Warn("error querying ethtool ioctl private flags", zap.String("link", link.Attributes.Name), zap.Error(err))
}
}

if err = r.Modify(ctx, network.NewLinkStatus(network.NamespaceName, link.Attributes.Name), func(r resource.Resource) error {
Expand Down Expand Up @@ -310,6 +323,9 @@ func (ctrl *LinkStatusController) reconcile(
status.DriverVersion = driverInfo.Version
status.FirmwareVersion = driverInfo.FwVersion

status.PrivateFlags = privateFlags
status.Features = networkutils.FormatFeatures(features)

// link.Attributes.Info will be non-nil, because we set status.Kind above using link.Attributes.Info.Kind
var rawLinkData []byte

Expand Down
41 changes: 41 additions & 0 deletions internal/app/machined/pkg/controllers/network/utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,13 @@ package networkutils

import (
"context"
"slices"

"github.com/cosi-project/runtime/pkg/controller"
"github.com/cosi-project/runtime/pkg/safe"
"github.com/cosi-project/runtime/pkg/state"
"github.com/safchain/ethtool"
"github.com/siderolabs/gen/maps"
"github.com/siderolabs/gen/optional"

"github.com/siderolabs/talos/pkg/machinery/resources/network"
Expand Down Expand Up @@ -64,3 +67,41 @@ func WaitForNetworkReady(ctx context.Context, r controller.Runtime, condition fu

return nil
}

// FormatFeatures formats ethtool features.
func FormatFeatures(features map[string]ethtool.FeatureState) map[string]string {
if features == nil {
return nil
}

keys := maps.Keys(features)
slices.Sort(keys)

out := make(map[string]string, len(keys))

for _, feature := range keys {
state := features[feature]

var value string

if state.Active {
value = "on"
} else {
value = "off"
}

if !state.Available || state.NeverChanged {
value += " [fixed]"
} else if state.Requested != state.Active {
if state.Requested {
value += " [requested on]"
} else {
value += " [requested off]"
}
}

out[feature] = value
}

return out
}
1,092 changes: 566 additions & 526 deletions pkg/machinery/api/resource/definitions/network/network.pb.go

Large diffs are not rendered by default.

Loading
Loading