Skip to content

Commit

Permalink
chore: upgrade to rtnetlink/v2 library
Browse files Browse the repository at this point in the history
The v1 version is no longer supported.

The major change is the decoding of link data, but we're not using it,
as we have our own decoders/encoders for a long time.

Signed-off-by: Andrey Smirnov <andrey.smirnov@siderolabs.com>
  • Loading branch information
smira committed Jun 13, 2024
1 parent 1fb8453 commit 6f6a5d1
Show file tree
Hide file tree
Showing 18 changed files with 79 additions and 33 deletions.
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ require (
github.com/hetznercloud/hcloud-go/v2 v2.9.0
github.com/insomniacslk/dhcp v0.0.0-20240529192340-51bc6136a0a6
github.com/jeromer/syslogparser v1.1.0
github.com/jsimonetti/rtnetlink v1.4.2
github.com/jsimonetti/rtnetlink/v2 v2.0.2
github.com/jxskiss/base62 v1.1.0
github.com/klauspost/compress v1.17.9
github.com/klauspost/cpuid/v2 v2.2.8
Expand Down Expand Up @@ -147,7 +147,7 @@ require (
github.com/siderolabs/grpc-proxy v0.4.0
github.com/siderolabs/kms-client v0.1.0
github.com/siderolabs/net v0.4.0
github.com/siderolabs/siderolink v0.3.8
github.com/siderolabs/siderolink v0.3.9
github.com/siderolabs/talos/pkg/machinery v1.8.0-alpha.0.0.20240521134552-e1711cd3c985
github.com/spf13/cobra v1.8.0
github.com/spf13/pflag v1.0.5
Expand Down
8 changes: 4 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -436,8 +436,8 @@ github.com/josharian/native v1.1.0 h1:uuaP0hAbW7Y4l0ZRQ6C9zfb7Mg1mbFKry/xzDAfmtL
github.com/josharian/native v1.1.0/go.mod h1:7X/raswPFr05uY3HiLlYeyQntB6OO7E/d2Cu7qoaN2w=
github.com/jsimonetti/rtnetlink v0.0.0-20190606172950-9527aa82566a/go.mod h1:Oz+70psSo5OFh8DBl0Zv2ACw7Esh6pPUphlvZG9x7uw=
github.com/jsimonetti/rtnetlink v0.0.0-20200117123717-f846d4f6c1f4/go.mod h1:WGuG/smIU4J/54PblvSbh+xvCZmpJnFgr3ds6Z55XMQ=
github.com/jsimonetti/rtnetlink v1.4.2 h1:Df9w9TZ3npHTyDn0Ev9e1uzmN2odmXd0QX+J5GTEn90=
github.com/jsimonetti/rtnetlink v1.4.2/go.mod h1:92s6LJdE+1iOrw+F2/RO7LYI2Qd8pPpFNNUYW06gcoM=
github.com/jsimonetti/rtnetlink/v2 v2.0.2 h1:ZKlbCujrIpp4/u3V2Ka0oxlf4BCkt6ojkvpy3nZoCBY=
github.com/jsimonetti/rtnetlink/v2 v2.0.2/go.mod h1:7MoNYNbb3UaDHtF8udiJo/RH6VsTKP1pqKLUTVCvToE=
github.com/json-iterator/go v1.1.12 h1:PV8peI4a0ysnczrg+LtxykD8LfKY9ML6u2jnxaEnrnM=
github.com/json-iterator/go v1.1.12/go.mod h1:e30LSqwooZae/UwlEbR2852Gd8hjQvJoHmT4TnhNGBo=
github.com/jstemmer/go-junit-report v0.0.0-20190106144839-af01ea7f8024/go.mod h1:6v2b51hI/fHJwM22ozAgKL4VKDeJcHhJFhtBdhmNjmU=
Expand Down Expand Up @@ -680,8 +680,8 @@ github.com/siderolabs/net v0.4.0 h1:1bOgVay/ijPkJz4qct98nHsiB/ysLQU0KLoBC4qLm7I=
github.com/siderolabs/net v0.4.0/go.mod h1:/ibG+Hm9HU27agp5r9Q3eZicEfjquzNzQNux5uEk0kM=
github.com/siderolabs/protoenc v0.2.1 h1:BqxEmeWQeMpNP3R6WrPqDatX8sM/r4t97OP8mFmg6GA=
github.com/siderolabs/protoenc v0.2.1/go.mod h1:StTHxjet1g11GpNAWiATgc8K0HMKiFSEVVFOa/H0otc=
github.com/siderolabs/siderolink v0.3.8 h1:UPG7SKgWXCrCRiHfQkHZQYy0xSVSF+KitnhXYC+ofAE=
github.com/siderolabs/siderolink v0.3.8/go.mod h1:mgfFQbAB28mX88jJp/7LlWmoyMEB4CcObcdJUcdNskQ=
github.com/siderolabs/siderolink v0.3.9 h1:lvHFCu+CdfUyMk90g1Zt5r7n1Dw3jhXMxyzXmQ0776o=
github.com/siderolabs/siderolink v0.3.9/go.mod h1:QbGnXpHI5MDq6qMZkCFnxYOOw5eE+lkLx53L5ZgjLMQ=
github.com/siderolabs/tcpproxy v0.1.0 h1:IbkS9vRhjMOscc1US3M5P1RnsGKFgB6U5IzUk+4WkKA=
github.com/siderolabs/tcpproxy v0.1.0/go.mod h1:onn6CPPj/w1UNqQ0U97oRPF0CqbrgEApYCw4P9IiCW8=
github.com/siderolabs/wgctrl-go v0.0.0-20240401105613-579af3342774 h1:wLhs5zMQVjA6LN9WpF2owOdtcoRp40zL8AaQSle+9EE=
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (

"github.com/cosi-project/runtime/pkg/controller"
"github.com/cosi-project/runtime/pkg/resource"
"github.com/jsimonetti/rtnetlink"
"github.com/jsimonetti/rtnetlink/v2"
"github.com/mdlayher/arp"
"go.uber.org/zap"
"go4.org/netipx"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import (
"github.com/cosi-project/runtime/pkg/state"
"github.com/cosi-project/runtime/pkg/state/impl/inmem"
"github.com/cosi-project/runtime/pkg/state/impl/namespaced"
"github.com/jsimonetti/rtnetlink"
"github.com/jsimonetti/rtnetlink/v2"
"github.com/siderolabs/go-retry/retry"
"github.com/stretchr/testify/suite"
"go.uber.org/zap/zaptest"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (

"github.com/cosi-project/runtime/pkg/controller"
"github.com/cosi-project/runtime/pkg/resource"
"github.com/jsimonetti/rtnetlink"
"github.com/jsimonetti/rtnetlink/v2"
"go.uber.org/zap"
"golang.org/x/sys/unix"

Expand Down
43 changes: 36 additions & 7 deletions internal/app/machined/pkg/controllers/network/link_spec.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (
"github.com/cosi-project/runtime/pkg/resource"
"github.com/cosi-project/runtime/pkg/safe"
"github.com/hashicorp/go-multierror"
"github.com/jsimonetti/rtnetlink"
"github.com/jsimonetti/rtnetlink/v2"
"github.com/siderolabs/gen/pair/ordered"
"github.com/siderolabs/go-pointer"
"go.uber.org/zap"
Expand Down Expand Up @@ -231,6 +231,14 @@ func (ctrl *LinkSpecController) syncLink(ctx context.Context, r controller.Runti
case resource.PhaseRunning:
existing := findLink(*links, link.TypedSpec().Name)

var existingRawLinkData []byte

if existing != nil && existing.Attributes != nil && existing.Attributes.Info != nil && existing.Attributes.Info.Data != nil {
if existingLinkData, ok := existing.Attributes.Info.Data.(*rtnetlink.LinkData); ok {
existingRawLinkData = existingLinkData.Data
}
}

// check if type/kind matches for the existing logical link
if existing != nil && link.TypedSpec().Logical {
replace := false
Expand Down Expand Up @@ -261,7 +269,11 @@ func (ctrl *LinkSpecController) syncLink(ctx context.Context, r controller.Runti
if !replace && link.TypedSpec().Kind == network.LinkKindVLAN {
var existingVLAN network.VLANSpec

if err := networkadapter.VLANSpec(&existingVLAN).Decode(existing.Attributes.Info.Data); err != nil {
if existingRawLinkData == nil {
return fmt.Errorf("existing link %q has no data, can't decode VLAN settings", link.TypedSpec().Name)
}

if err := networkadapter.VLANSpec(&existingVLAN).Decode(existingRawLinkData); err != nil {
return fmt.Errorf("error decoding VLAN properties on %q: %w", link.TypedSpec().Name, err)
}

Expand Down Expand Up @@ -326,7 +338,10 @@ func (ctrl *LinkSpecController) syncLink(ctx context.Context, r controller.Runti
Type: parentIndex,
Info: &rtnetlink.LinkInfo{
Kind: link.TypedSpec().Kind,
Data: data,
Data: &rtnetlink.LinkData{
Name: link.TypedSpec().Kind,
Data: data,
},
},
},
}); err != nil {
Expand All @@ -351,7 +366,11 @@ func (ctrl *LinkSpecController) syncLink(ctx context.Context, r controller.Runti
if link.TypedSpec().Kind == network.LinkKindBond {
var existingBond network.BondMasterSpec

if err := networkadapter.BondMasterSpec(&existingBond).Decode(existing.Attributes.Info.Data); err != nil {
if existingRawLinkData == nil {
return fmt.Errorf("existing link %q has no data, can't decode bond settings", link.TypedSpec().Name)
}

if err := networkadapter.BondMasterSpec(&existingBond).Decode(existingRawLinkData); err != nil {
return fmt.Errorf("error parsing bond attributes for %q: %w", link.TypedSpec().Name, err)
}

Expand Down Expand Up @@ -403,7 +422,10 @@ func (ctrl *LinkSpecController) syncLink(ctx context.Context, r controller.Runti
Attributes: &rtnetlink.LinkAttributes{
Info: &rtnetlink.LinkInfo{
Kind: existing.Attributes.Info.Kind,
Data: data,
Data: &rtnetlink.LinkData{
Name: existing.Attributes.Info.Kind,
Data: data,
},
},
},
}); err != nil {
Expand All @@ -418,7 +440,11 @@ func (ctrl *LinkSpecController) syncLink(ctx context.Context, r controller.Runti
if link.TypedSpec().Kind == network.LinkKindBridge {
var existingBridge network.BridgeMasterSpec

if err := networkadapter.BridgeMasterSpec(&existingBridge).Decode(existing.Attributes.Info.Data); err != nil {
if existingRawLinkData == nil {
return fmt.Errorf("existing link %q has no data, can't decode bridge settings", link.TypedSpec().Name)
}

if err := networkadapter.BridgeMasterSpec(&existingBridge).Decode(existingRawLinkData); err != nil {
return fmt.Errorf("error parsing bridge attributes for %q: %w", link.TypedSpec().Name, err)
}

Expand Down Expand Up @@ -470,7 +496,10 @@ func (ctrl *LinkSpecController) syncLink(ctx context.Context, r controller.Runti
Attributes: &rtnetlink.LinkAttributes{
Info: &rtnetlink.LinkInfo{
Kind: existing.Attributes.Info.Kind,
Data: data,
Data: &rtnetlink.LinkData{
Name: existing.Attributes.Info.Kind,
Data: data,
},
},
},
}); err != nil {
Expand Down
22 changes: 18 additions & 4 deletions internal/app/machined/pkg/controllers/network/link_status.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (

"github.com/cosi-project/runtime/pkg/controller"
"github.com/cosi-project/runtime/pkg/resource"
"github.com/jsimonetti/rtnetlink"
"github.com/jsimonetti/rtnetlink/v2"
"github.com/mdlayher/ethtool"
ethtoolioctl "github.com/safchain/ethtool"
"go.uber.org/zap"
Expand Down Expand Up @@ -297,17 +297,31 @@ func (ctrl *LinkStatusController) reconcile(
status.FirmwareVersion = driverInfo.FwVersion

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

if link.Attributes.Info != nil && link.Attributes.Info.Data != nil {
if linkData, ok := link.Attributes.Info.Data.(*rtnetlink.LinkData); ok {
rawLinkData = linkData.Data
}
}

switch status.Kind {
case network.LinkKindVLAN:
if err = networkadapter.VLANSpec(&status.VLAN).Decode(link.Attributes.Info.Data); err != nil {
if rawLinkData == nil {
logger.Warn("VLAN link data is nil", zap.String("link", link.Attributes.Name))
} else if err = networkadapter.VLANSpec(&status.VLAN).Decode(rawLinkData); err != nil {
logger.Warn("failure decoding VLAN attributes", zap.Error(err), zap.String("link", link.Attributes.Name))
}
case network.LinkKindBond:
if err = networkadapter.BondMasterSpec(&status.BondMaster).Decode(link.Attributes.Info.Data); err != nil {
if rawLinkData == nil {
logger.Warn("bond link data is nil", zap.String("link", link.Attributes.Name))
} else if err = networkadapter.BondMasterSpec(&status.BondMaster).Decode(rawLinkData); err != nil {
logger.Warn("failure decoding bond attributes", zap.Error(err), zap.String("link", link.Attributes.Name))
}
case network.LinkKindBridge:
if err = networkadapter.BridgeMasterSpec(&status.BridgeMaster).Decode(link.Attributes.Info.Data); err != nil {
if rawLinkData == nil {
logger.Warn("bridge link data is nil", zap.String("link", link.Attributes.Name))
} else if err = networkadapter.BridgeMasterSpec(&status.BridgeMaster).Decode(rawLinkData); err != nil {
logger.Warn("failure decoding bridge attributes", zap.Error(err), zap.String("link", link.Attributes.Name))
}
case network.LinkKindWireguard:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import (
"github.com/cosi-project/runtime/pkg/state"
"github.com/cosi-project/runtime/pkg/state/impl/inmem"
"github.com/cosi-project/runtime/pkg/state/impl/namespaced"
"github.com/jsimonetti/rtnetlink"
"github.com/jsimonetti/rtnetlink/v2"
"github.com/mdlayher/netlink"
"github.com/siderolabs/go-retry/retry"
"github.com/stretchr/testify/suite"
Expand Down Expand Up @@ -317,7 +317,10 @@ func (suite *LinkStatusSuite) TestBridgeInterface() {
Name: bridgeInterface,
Info: &rtnetlink.LinkInfo{
Kind: "bridge",
Data: bridgeData,
Data: &rtnetlink.LinkData{
Name: "bridge",
Data: bridgeData,
},
},
},
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ func (s *NfTablesChainSuite) TestICMPLimit() {
s.checkNftOutput(`table inet talos-test {
chain test1 {
type filter hook input priority security; policy accept;
meta l4proto icmp limit rate 5/second accept
meta l4proto icmp limit rate 5/second burst 5 packets accept
}
}`)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import (

"github.com/insomniacslk/dhcp/dhcpv6"
"github.com/insomniacslk/dhcp/dhcpv6/nclient6"
"github.com/jsimonetti/rtnetlink"
"github.com/jsimonetti/rtnetlink/v2"
"github.com/siderolabs/gen/xslices"
"github.com/siderolabs/go-retry/retry"
"go.uber.org/zap"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
"github.com/cosi-project/runtime/pkg/controller"
"github.com/cosi-project/runtime/pkg/resource"
"github.com/hashicorp/go-multierror"
"github.com/jsimonetti/rtnetlink"
"github.com/jsimonetti/rtnetlink/v2"
"github.com/siderolabs/gen/value"
"go.uber.org/zap"
"golang.org/x/sys/unix"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import (
"github.com/cosi-project/runtime/pkg/state"
"github.com/cosi-project/runtime/pkg/state/impl/inmem"
"github.com/cosi-project/runtime/pkg/state/impl/namespaced"
"github.com/jsimonetti/rtnetlink"
"github.com/jsimonetti/rtnetlink/v2"
"github.com/siderolabs/go-retry/retry"
"github.com/stretchr/testify/suite"
"go.uber.org/zap/zaptest"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (

"github.com/cosi-project/runtime/pkg/controller"
"github.com/cosi-project/runtime/pkg/resource"
"github.com/jsimonetti/rtnetlink"
"github.com/jsimonetti/rtnetlink/v2"
"go.uber.org/zap"
"golang.org/x/sys/unix"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"fmt"
"sync"

"github.com/jsimonetti/rtnetlink"
"github.com/jsimonetti/rtnetlink/v2"
"github.com/mdlayher/netlink"
)

Expand Down
2 changes: 1 addition & 1 deletion pkg/machinery/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ require (
github.com/evanphx/json-patch v5.9.0+incompatible
github.com/ghodss/yaml v1.0.0
github.com/hashicorp/go-multierror v1.1.1
github.com/jsimonetti/rtnetlink v1.4.2
github.com/jsimonetti/rtnetlink/v2 v2.0.2
github.com/mdlayher/ethtool v0.1.0
github.com/opencontainers/runtime-spec v1.2.0
github.com/planetscale/vtprotobuf v0.6.0
Expand Down
4 changes: 2 additions & 2 deletions pkg/machinery/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,8 @@ github.com/hashicorp/go-multierror v1.1.1 h1:H5DkEtf6CXdFp0N0Em5UCwQpXMWke8IA0+l
github.com/hashicorp/go-multierror v1.1.1/go.mod h1:iw975J/qwKPdAO1clOe2L8331t/9/fmwbPZ6JB6eMoM=
github.com/josharian/native v1.1.0 h1:uuaP0hAbW7Y4l0ZRQ6C9zfb7Mg1mbFKry/xzDAfmtLA=
github.com/josharian/native v1.1.0/go.mod h1:7X/raswPFr05uY3HiLlYeyQntB6OO7E/d2Cu7qoaN2w=
github.com/jsimonetti/rtnetlink v1.4.2 h1:Df9w9TZ3npHTyDn0Ev9e1uzmN2odmXd0QX+J5GTEn90=
github.com/jsimonetti/rtnetlink v1.4.2/go.mod h1:92s6LJdE+1iOrw+F2/RO7LYI2Qd8pPpFNNUYW06gcoM=
github.com/jsimonetti/rtnetlink/v2 v2.0.2 h1:ZKlbCujrIpp4/u3V2Ka0oxlf4BCkt6ojkvpy3nZoCBY=
github.com/jsimonetti/rtnetlink/v2 v2.0.2/go.mod h1:7MoNYNbb3UaDHtF8udiJo/RH6VsTKP1pqKLUTVCvToE=
github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE=
github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk=
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
Expand Down
2 changes: 1 addition & 1 deletion pkg/machinery/nethelpers/operstate.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
package nethelpers

import (
"github.com/jsimonetti/rtnetlink"
"github.com/jsimonetti/rtnetlink/v2"
)

// OperationalState wraps rtnetlink.OperationalState for YAML marshaling.
Expand Down
2 changes: 1 addition & 1 deletion pkg/provision/providers/vm/network.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import (
"github.com/containernetworking/plugins/pkg/testutils"
"github.com/coreos/go-iptables/iptables"
"github.com/google/uuid"
"github.com/jsimonetti/rtnetlink"
"github.com/jsimonetti/rtnetlink/v2"
"github.com/siderolabs/gen/xslices"
sideronet "github.com/siderolabs/net"
"github.com/vishvananda/netlink"
Expand Down

0 comments on commit 6f6a5d1

Please sign in to comment.