Skip to content

Commit 4040e08

Browse files
6ixfallsshanduur
authored andcommitted
feat: implement multicast setting
Add a multicast option to LinkSpec that can be configured to explicitly declare the state of the multicast flag. Signed-off-by: Bryan Lee <me@bryanl.ee> (cherry picked from commit 6db06f4)
1 parent eb636dc commit 4040e08

File tree

10 files changed

+111
-7
lines changed

10 files changed

+111
-7
lines changed

api/resource/definitions/network/network.proto

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -251,6 +251,7 @@ message LinkSpecSpec {
251251
WireguardSpec wireguard = 13;
252252
talos.resource.definitions.enums.NetworkConfigLayer config_layer = 14;
253253
bytes hardware_address = 15;
254+
bool multicast = 16;
254255
}
255256

256257
// LinkStatusSpec describes status of rendered secrets.

internal/app/machined/pkg/controllers/network/link_spec.go

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -634,6 +634,27 @@ func (ctrl *LinkSpecController) syncLink(ctx context.Context, r controller.Runti
634634
logger.Info("changed hardware address for the link", zap.String("hwaddr", net.HardwareAddr(link.TypedSpec().HardwareAddress).String()))
635635
}
636636

637+
// sync multicast flag if it's set in the spec
638+
if link.TypedSpec().Multicast != nil && ((existing.Flags&unix.IFF_MULTICAST == unix.IFF_MULTICAST) != *link.TypedSpec().Multicast) {
639+
flags := uint32(0)
640+
641+
if *link.TypedSpec().Multicast {
642+
flags = unix.IFF_MULTICAST
643+
}
644+
645+
if err := conn.Link.Set(&rtnetlink.LinkMessage{
646+
Family: existing.Family,
647+
Type: existing.Type,
648+
Index: existing.Index,
649+
Flags: flags,
650+
Change: unix.IFF_MULTICAST,
651+
}); err != nil {
652+
return fmt.Errorf("error changing multicast flag for %q: %w", link.TypedSpec().Name, err)
653+
}
654+
655+
logger.Info("changed multicast flag for the link", zap.Bool("multicast", *link.TypedSpec().Multicast))
656+
}
657+
637658
// sync master index (for links which are bridge or bond slaves)
638659
var masterIndex uint32
639660

internal/app/machined/pkg/controllers/network/link_spec_test.go

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import (
2222
"github.com/stretchr/testify/assert"
2323
"github.com/stretchr/testify/require"
2424
"github.com/stretchr/testify/suite"
25+
"golang.org/x/sys/unix"
2526
"golang.zx2c4.com/wireguard/wgctrl/wgtypes"
2627

2728
networkadapter "github.com/siderolabs/talos/internal/app/machined/pkg/adapters/network"
@@ -94,6 +95,35 @@ func (suite *LinkSpecSuite) TestDummy() {
9495
asrt.Equal(newHardwareAddr, net.HardwareAddr(r.TypedSpec().HardwareAddr))
9596
})
9697

98+
// check default multicast behavior (disabled on dummy interfaces)
99+
ctest.AssertResource(suite, dummyInterface, func(r *network.LinkStatus, asrt *assert.Assertions) {
100+
asrt.Equal(r.TypedSpec().Flags&unix.IFF_MULTICAST == unix.IFF_MULTICAST, false)
101+
})
102+
103+
// attempt to change multicast flag
104+
ctest.UpdateWithConflicts(suite, dummy, func(r *network.LinkSpec) error {
105+
r.TypedSpec().Multicast = new(bool)
106+
*r.TypedSpec().Multicast = true
107+
108+
return nil
109+
})
110+
111+
ctest.AssertResource(suite, dummyInterface, func(r *network.LinkStatus, asrt *assert.Assertions) {
112+
asrt.Equal(r.TypedSpec().Flags&unix.IFF_MULTICAST == unix.IFF_MULTICAST, true)
113+
})
114+
115+
// attempt to disable multicast
116+
ctest.UpdateWithConflicts(suite, dummy, func(r *network.LinkSpec) error {
117+
r.TypedSpec().Multicast = new(bool)
118+
*r.TypedSpec().Multicast = false
119+
120+
return nil
121+
})
122+
123+
ctest.AssertResource(suite, dummyInterface, func(r *network.LinkStatus, asrt *assert.Assertions) {
124+
asrt.Equal(r.TypedSpec().Flags&unix.IFF_MULTICAST == unix.IFF_MULTICAST, false)
125+
})
126+
97127
suite.Require().NoError(suite.State().TeardownAndDestroy(suite.Ctx(), dummy.Metadata()))
98128

99129
ctest.AssertNoResource[*network.LinkSpec](suite, dummyInterface)

pkg/machinery/api/resource/definitions/network/network.pb.go

Lines changed: 11 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/machinery/api/resource/definitions/network/network_vtproto.pb.go

Lines changed: 35 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/machinery/nethelpers/arpalltargets_enumer.go

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/machinery/nethelpers/linkflag.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ const (
7070
LinkAllMulti // ALLMULTI
7171
LinkMaster // MASTER
7272
LinkSlave // SLAVE
73-
LinkMulticase // MULTICAST
73+
LinkMulticast // MULTICAST
7474
LinkPortsel // PORTSEL
7575
LinKAutoMedia // AUTOMEDIA
7676
LinkDynamic // DYNAMIC

pkg/machinery/resources/network/deep_copy.generated.go

Lines changed: 4 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/machinery/resources/network/link_spec.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,9 @@ type LinkSpecSpec struct {
6464

6565
// Configuration layer.
6666
ConfigLayer ConfigLayer `yaml:"layer" protobuf:"14"`
67+
68+
// Multicast indicates whether the multicast flag should be set on the interface to the value.
69+
Multicast *bool `yaml:"multicast,omitempty" protobuf:"16"`
6770
}
6871

6972
// BondSlave contains a bond's master name and slave index.

website/content/v1.12/reference/api.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8781,6 +8781,7 @@ LinkSpecSpec describes spec for the link.
87818781
| wireguard | [WireguardSpec](#talos.resource.definitions.network.WireguardSpec) | | |
87828782
| config_layer | [talos.resource.definitions.enums.NetworkConfigLayer](#talos.resource.definitions.enums.NetworkConfigLayer) | | |
87838783
| hardware_address | [bytes](#bytes) | | |
8784+
| multicast | [bool](#bool) | | |
87848785

87858786

87868787

0 commit comments

Comments
 (0)