Skip to content

Commit

Permalink
fix: don't set bond delay options if miimon is not enabled
Browse files Browse the repository at this point in the history
Basically all delay options are interlocked with `miimon`: if `miimon`
is zero, all delays are set to zero, and kernel complains even if zero
delay attribute is sent while miimon is zero.

Signed-off-by: Andrey Smirnov <smirnov.andrey@gmail.com>
(cherry picked from commit 78583ba)
  • Loading branch information
smira committed Jun 29, 2021
1 parent de7db38 commit 33d7318
Show file tree
Hide file tree
Showing 2 changed files with 99 additions and 3 deletions.
91 changes: 91 additions & 0 deletions internal/app/machined/pkg/controllers/network/link_spec_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -445,6 +445,97 @@ func (suite *LinkSpecSuite) TestBond() {
}))
}

//nolint:gocyclo
func (suite *LinkSpecSuite) TestBond8023ad() {
bondName := suite.uniqueDummyInterface()
bond := network.NewLinkSpec(network.NamespaceName, bondName)
*bond.TypedSpec() = network.LinkSpecSpec{
Name: bondName,
Type: nethelpers.LinkEther,
Kind: network.LinkKindBond,
MTU: 9000,
Up: true,
Logical: true,
BondMaster: network.BondMasterSpec{
Mode: nethelpers.BondMode8023AD,
LACPRate: nethelpers.LACPRateFast,
UseCarrier: true,
},
ConfigLayer: network.ConfigDefault,
}
bond.TypedSpec().BondMaster.FillDefaults()

dummies := []resource.Resource{}
dummyNames := []string{}

for i := 0; i < 4; i++ {
dummyName := suite.uniqueDummyInterface()
dummy := network.NewLinkSpec(network.NamespaceName, dummyName)
*dummy.TypedSpec() = network.LinkSpecSpec{
Name: dummyName,
Type: nethelpers.LinkEther,
Kind: "dummy",
Up: true,
Logical: true,
MasterName: bondName,
ConfigLayer: network.ConfigDefault,
}

dummies = append(dummies, dummy)
dummyNames = append(dummyNames, dummyName)
}

for _, res := range append(dummies, bond) {
suite.Require().NoError(suite.state.Create(suite.ctx, res), "%v", res.Spec())
}

suite.Assert().NoError(retry.Constant(10*time.Second, retry.WithUnits(100*time.Millisecond)).Retry(
func() error {
return suite.assertInterfaces(append(dummyNames, bondName), func(r *network.LinkStatus) error {
if r.Metadata().ID() == bondName {
// master
suite.Assert().Equal(network.LinkKindBond, r.TypedSpec().Kind)

if r.TypedSpec().OperationalState != nethelpers.OperStateUnknown && r.TypedSpec().OperationalState != nethelpers.OperStateUp {
return retry.ExpectedErrorf("link is not up: %s", r.TypedSpec().OperationalState)
}
} else {
// slaves
suite.Assert().Equal("dummy", r.TypedSpec().Kind)

if r.TypedSpec().OperationalState != nethelpers.OperStateUnknown {
return retry.ExpectedErrorf("link is not up: %s", r.TypedSpec().OperationalState)
}

if r.TypedSpec().MasterIndex == 0 {
return retry.ExpectedErrorf("masterIndex should be non-zero")
}
}

return nil
})
}))

// teardown the links
for _, r := range append(dummies, bond) {
for {
ready, err := suite.state.Teardown(suite.ctx, r.Metadata())
suite.Require().NoError(err)

if ready {
break
}

time.Sleep(100 * time.Millisecond)
}
}

suite.Assert().NoError(retry.Constant(3*time.Second, retry.WithUnits(100*time.Millisecond)).Retry(
func() error {
return suite.assertNoInterface(bondName)
}))
}

func (suite *LinkSpecSuite) TestWireguard() {
priv, err := wgtypes.GeneratePrivateKey()
suite.Require().NoError(err)
Expand Down
11 changes: 8 additions & 3 deletions pkg/resources/network/link.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,8 +141,11 @@ func (bond *BondMasterSpec) Encode() ([]byte, error) {
encoder.Uint8(unix.IFLA_BOND_FAIL_OVER_MAC, uint8(bond.FailOverMac))
encoder.Uint8(unix.IFLA_BOND_AD_SELECT, uint8(bond.ADSelect))
encoder.Uint32(unix.IFLA_BOND_MIIMON, bond.MIIMon)
encoder.Uint32(unix.IFLA_BOND_UPDELAY, bond.UpDelay)
encoder.Uint32(unix.IFLA_BOND_DOWNDELAY, bond.DownDelay)

if bond.MIIMon != 0 {
encoder.Uint32(unix.IFLA_BOND_UPDELAY, bond.UpDelay)
encoder.Uint32(unix.IFLA_BOND_DOWNDELAY, bond.DownDelay)
}

if bond.Mode != nethelpers.BondMode8023AD && bond.Mode != nethelpers.BondModeALB && bond.Mode != nethelpers.BondModeTLB {
encoder.Uint32(unix.IFLA_BOND_ARP_INTERVAL, bond.ARPInterval)
Expand Down Expand Up @@ -177,7 +180,9 @@ func (bond *BondMasterSpec) Encode() ([]byte, error) {
encoder.Uint16(unix.IFLA_BOND_AD_USER_PORT_KEY, bond.ADUserPortKey)
}

encoder.Uint32(unix.IFLA_BOND_PEER_NOTIF_DELAY, bond.PeerNotifyDelay)
if bond.MIIMon != 0 {
encoder.Uint32(unix.IFLA_BOND_PEER_NOTIF_DELAY, bond.PeerNotifyDelay)
}

return encoder.Encode()
}
Expand Down

0 comments on commit 33d7318

Please sign in to comment.