chore: move from inet.af/netaddr to net/netip and go4.org/netipx

Closes #6007

Signed-off-by: Dmitriy Matrenichev <dmitry.matrenichev@siderolabs.com>
This commit is contained in:
Dmitriy Matrenichev 2022-08-23 22:56:24 +03:00
parent 053af1d59e
commit b59ca5810e
No known key found for this signature in database
GPG Key ID: D3363CF894E68892
152 changed files with 1062 additions and 1015 deletions

1
go.mod
View File

@ -119,6 +119,7 @@ require (
go.etcd.io/etcd/etcdutl/v3 v3.5.4
go.uber.org/atomic v1.10.0
go.uber.org/zap v1.22.0
go4.org/netipx v0.0.0-20220812043211-3cc044ffd68d
golang.org/x/net v0.0.0-20220822230855-b0a4917ee28c
golang.org/x/sync v0.0.0-20220819030929-7fc1605a5dde
golang.org/x/sys v0.0.0-20220818161305-2296e01440c6

2
go.sum
View File

@ -1277,6 +1277,8 @@ go.uber.org/zap v1.22.0/go.mod h1:H4siCOZOrAolnUPJEkfaSjDqyP+BDS0DdDWzwcgt3+U=
go4.org/intern v0.0.0-20211027215823-ae77deb06f29/go.mod h1:cS2ma+47FKrLPdXFpr7CuxiTW3eyJbWew4qx0qtQWDA=
go4.org/intern v0.0.0-20220617035311-6925f38cc365 h1:t9hFvR102YlOqU0fQn1wgwhNvSbHGBbbJxX9JKfU3l0=
go4.org/intern v0.0.0-20220617035311-6925f38cc365/go.mod h1:WXRv3p7T6gzt0CcJm43AAKdKVZmcQbwwC7EwquU5BZU=
go4.org/netipx v0.0.0-20220812043211-3cc044ffd68d h1:ggxwEf5eu0l8v+87VhX1czFh8zJul3hK16Gmruxn7hw=
go4.org/netipx v0.0.0-20220812043211-3cc044ffd68d/go.mod h1:tgPU4N2u9RByaTN3NC2p9xOzyFpte4jYwsIIRF7XlSc=
go4.org/unsafe/assume-no-moving-gc v0.0.0-20211027215541-db492cf91b37/go.mod h1:FftLjUGFEDu5k8lt0ddY+HcrH/qU/0qk+H8j9/nTl3E=
go4.org/unsafe/assume-no-moving-gc v0.0.0-20220617031537-928513b29760 h1:FyBZqvoA/jbNzuAWLQE2kG820zMAkcilx6BMjGbL/E4=
go4.org/unsafe/assume-no-moving-gc v0.0.0-20220617031537-928513b29760/go.mod h1:FftLjUGFEDu5k8lt0ddY+HcrH/qU/0qk+H8j9/nTl3E=

View File

@ -189,8 +189,6 @@ github.com/networkplumbing/go-nft v0.2.0 h1:eKapmyVUt/3VGfhYaDos5yeprm+LPt881Uek
github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e h1:fD57ERR4JtEqsWbfPhv4DMiApHyliiK5xCTNVSPiaAs=
github.com/oklog/ulid v1.3.1 h1:EGfNDEx6MqHz8B3uNV6QAib1UR2Lm97sHi3ocA6ESJ4=
github.com/olekukonko/tablewriter v0.0.5 h1:P2Ga83D34wi1o9J6Wh1mRuqd4mF/x/lgBS7N7AbDhec=
github.com/onsi/ginkgo/v2 v2.1.4/go.mod h1:um6tUpWM/cxCK3/FK8BXqEiUMUwRgSM4JXG47RKZmLU=
github.com/onsi/gomega v1.19.0/go.mod h1:LY+I3pBVzYsTBU1AnDwOSxaYi9WoWiqgwooUqq9yPro=
github.com/opencontainers/runtime-tools v0.0.0-20181011054405-1d69bd0f9c39 h1:H7DMc6FAjgwZZi8BRqjrAAHWoqEr5e5L6pS4V0ezet4=
github.com/opentracing/opentracing-go v1.1.0 h1:pWlfV3Bxv7k65HYwkikxat0+s3pV4bsqf19k25Ur8rU=
github.com/orangecms/go-framebuffer v0.0.0-20200613202404-a0700d90c330 h1:zJBTzBuTR7EdFzmCGx0xp0pbOOb82sAh0+YUK4JTDEI=
@ -263,6 +261,7 @@ go.opentelemetry.io/proto/otlp v0.11.0 h1:cLDgIBTf4lLOlztkhzAEdQsJ4Lj+i5Wc9k6Nn0
go.uber.org/goleak v1.1.12/go.mod h1:cwTWslyiVhfpKIDGSZEM2HlOvcqm+tG4zioyIeLoqMQ=
go.uber.org/multierr v1.7.0/go.mod h1:7EAYxJLBy9rStEaz58O2t4Uvip6FSURkq8/ppBp95ak=
golang.org/x/exp v0.0.0-20200224162631-6cc2880d07d6 h1:QE6XYQK6naiK1EPAe1g/ILLxN5RBoH5xkJk3CqlMI/Y=
golang.org/x/exp/typeparams v0.0.0-20220218215828-6cf2b201936e h1:qyrTQ++p1afMkO4DPEeLGq/3oTsdlvdH4vqZUBWzUKM=
golang.org/x/image v0.0.0-20190802002840-cff245a6509b h1:+qEpEAPhDZ1o0x3tHzZTQDArnOixOzGD9HUJfcg0mb4=
golang.org/x/lint v0.0.0-20210508222113-6edffad5e616 h1:VLliZ0d+/avPrXXH+OakdXhpJuEoBZuwh1m2j7U6Iug=
golang.org/x/mobile v0.0.0-20190719004257-d2bd2a29d028 h1:4+4C/Iv2U4fMZBiMCc98MG1In4gJY5YRhtpDNeDeHWs=
@ -290,7 +289,6 @@ google.golang.org/genproto v0.0.0-20220805133916-01dd62135a58/go.mod h1:iHe1svFL
google.golang.org/grpc/cmd/protoc-gen-go-grpc v1.1.0 h1:M1YKkFIboKNieVO5DLUEVzQfGwJD30Nv2jfUgzb5UcE=
gopkg.in/airbrake/gobrake.v2 v2.0.9 h1:7z2uVWwn7oVeeugY1DtlPAy5H+KYgB1KeKTnqjNatLo=
gopkg.in/alecthomas/kingpin.v2 v2.2.6 h1:jMFz6MfLP0/4fUyZle81rXUoxOBFi19VUFKVDOQfozc=
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q=
gopkg.in/cheggaaa/pb.v1 v1.0.27 h1:kJdccidYzt3CaHD1crCFTS1hxyhSi059NhOFUf03YFo=
gopkg.in/errgo.v2 v2.1.0 h1:0vLT13EuvQ0hNvakwLuFZ/jYrLp5F3kcWHXdRggjCE8=
gopkg.in/fsnotify.v1 v1.4.7 h1:xOHLXZwVvI9hhs+cLKq5+I5onOuwQLhQwiu63xxlHs4=
@ -299,6 +297,7 @@ gopkg.in/natefinch/lumberjack.v2 v2.0.0 h1:1Lc07Kr7qY4U2YPouBjpCLxpiyxIVoxqXgkXL
gopkg.in/resty.v1 v1.12.0 h1:CuXP0Pjfw9rOuY6EP+UvtNvt5DSqHpIxILZKT/quCZI=
gopkg.in/square/go-jose.v2 v2.5.1 h1:7odma5RETjNHWJnR32wx8t+Io4djHE1PqxCFx3iiZ2w=
honnef.co/go/tools v0.2.2 h1:MNh1AVMyVX23VUHE2O27jm6lNj3vjO5DexS4A1xvnzk=
honnef.co/go/tools v0.3.2 h1:ytYb4rOqyp1TSa2EPvNVwtPQJctSELKaMyLfqNP4+34=
k8s.io/api v0.24.2 h1:g518dPU/L7VRLxWfcadQn2OnsiGWVOadTLpdnqgY2OI=
k8s.io/api v0.24.2/go.mod h1:AHqbSkTm6YrQ0ObxjO3Pmp/ubFF/KuM7jU+3khoBsOg=
k8s.io/apimachinery v0.24.2 h1:5QlH9SL2C8KMcrNJPor+LbXVTaZRReml7svPEh4OKDM=

View File

@ -7,11 +7,13 @@ package kubespan
import (
"fmt"
"net"
"net/netip"
"github.com/mdlayher/netx/eui64"
"go4.org/netipx"
"golang.zx2c4.com/wireguard/wgctrl/wgtypes"
"inet.af/netaddr"
"github.com/talos-systems/talos/pkg/machinery/generic"
"github.com/talos-systems/talos/pkg/machinery/resources/kubespan"
"github.com/talos-systems/talos/pkg/machinery/resources/network"
)
@ -53,20 +55,20 @@ func (a identity) UpdateAddress(clusterID string, mac net.HardwareAddr) error {
return err
}
func wgEUI64(prefix netaddr.IPPrefix, mac net.HardwareAddr) (out netaddr.IPPrefix, err error) {
if prefix.IsZero() {
func wgEUI64(prefix netip.Prefix, mac net.HardwareAddr) (out netip.Prefix, err error) {
if generic.IsZero(prefix) {
return out, fmt.Errorf("cannot calculate IP from zero prefix")
}
stdIP, err := eui64.ParseMAC(prefix.IPNet().IP, mac)
stdIP, err := eui64.ParseMAC(netipx.PrefixIPNet(prefix).IP, mac)
if err != nil {
return out, fmt.Errorf("failed to parse MAC into EUI-64 address: %w", err)
}
ip, ok := netaddr.FromStdIP(stdIP)
ip, ok := netipx.FromStdIP(stdIP)
if !ok {
return out, fmt.Errorf("failed to parse intermediate standard IP %q: %w", stdIP.String(), err)
}
return netaddr.IPPrefixFrom(ip, ip.BitLen()), nil
return netip.PrefixFrom(ip, ip.BitLen()), nil
}

View File

@ -5,11 +5,13 @@
package kubespan
import (
"net/netip"
"time"
"go4.org/netipx"
"golang.zx2c4.com/wireguard/wgctrl/wgtypes"
"inet.af/netaddr"
"github.com/talos-systems/talos/pkg/machinery/generic"
"github.com/talos-systems/talos/pkg/machinery/resources/kubespan"
)
@ -93,7 +95,7 @@ func (a peerStatus) CalculateStateWithDurations(sinceLastHandshake, sinceEndpoin
}
}
if a.PeerStatusSpec.State == kubespan.PeerStateDown && a.PeerStatusSpec.LastUsedEndpoint.IsZero() {
if a.PeerStatusSpec.State == kubespan.PeerStateDown && generic.IsZero(a.PeerStatusSpec.LastUsedEndpoint) {
// no endpoint, so unknown
a.PeerStatusSpec.State = kubespan.PeerStateUnknown
}
@ -102,9 +104,9 @@ func (a peerStatus) CalculateStateWithDurations(sinceLastHandshake, sinceEndpoin
// UpdateFromWireguard updates fields from wgtypes information.
func (a peerStatus) UpdateFromWireguard(peer wgtypes.Peer) {
if peer.Endpoint != nil {
a.PeerStatusSpec.Endpoint, _ = netaddr.FromStdAddr(peer.Endpoint.IP, peer.Endpoint.Port, "")
a.PeerStatusSpec.Endpoint, _ = netipx.FromStdAddr(peer.Endpoint.IP, peer.Endpoint.Port, "")
} else {
a.PeerStatusSpec.Endpoint = netaddr.IPPort{}
a.PeerStatusSpec.Endpoint = netip.AddrPort{}
}
a.PeerStatusSpec.LastHandshakeTime = peer.LastHandshakeTime
@ -113,7 +115,7 @@ func (a peerStatus) UpdateFromWireguard(peer wgtypes.Peer) {
}
// UpdateEndpoint updates the endpoint information and last update timestamp.
func (a peerStatus) UpdateEndpoint(endpoint netaddr.IPPort) {
func (a peerStatus) UpdateEndpoint(endpoint netip.AddrPort) {
a.PeerStatusSpec.Endpoint = endpoint
a.PeerStatusSpec.LastUsedEndpoint = endpoint
a.PeerStatusSpec.LastEndpointChange = time.Now()
@ -122,18 +124,18 @@ func (a peerStatus) UpdateEndpoint(endpoint netaddr.IPPort) {
// ShouldChangeEndpoint tells whether endpoint should be updated.
func (a peerStatus) ShouldChangeEndpoint() bool {
return a.PeerStatusSpec.State == kubespan.PeerStateDown || a.PeerStatusSpec.LastUsedEndpoint.IsZero()
return a.PeerStatusSpec.State == kubespan.PeerStateDown || generic.IsZero(a.PeerStatusSpec.LastUsedEndpoint)
}
// PickNewEndpoint picks new endpoint given the state and list of available endpoints.
//
// If returned newEndpoint is zero value, no new endpoint is available.
func (a peerStatus) PickNewEndpoint(endpoints []netaddr.IPPort) (newEndpoint netaddr.IPPort) {
func (a peerStatus) PickNewEndpoint(endpoints []netip.AddrPort) (newEndpoint netip.AddrPort) {
if len(endpoints) == 0 {
return
}
if a.PeerStatusSpec.LastUsedEndpoint.IsZero() {
if generic.IsZero(a.PeerStatusSpec.LastUsedEndpoint) {
// first time setting the endpoint
newEndpoint = endpoints[0]
} else {

View File

@ -5,13 +5,14 @@
package kubespan_test
import (
"net/netip"
"testing"
"time"
"github.com/stretchr/testify/assert"
"inet.af/netaddr"
kubespanadapter "github.com/talos-systems/talos/internal/app/machined/pkg/adapters/kubespan"
"github.com/talos-systems/talos/pkg/machinery/generic"
"github.com/talos-systems/talos/pkg/machinery/resources/kubespan"
)
@ -20,11 +21,11 @@ func TestPeerStatus_PickNewEndpoint(t *testing.T) {
peerStatus := kubespan.PeerStatusSpec{}
// no endpoint => no way to pick new one
assert.True(t, kubespanadapter.PeerStatusSpec(&peerStatus).PickNewEndpoint(nil).IsZero())
assert.True(t, generic.IsZero(kubespanadapter.PeerStatusSpec(&peerStatus).PickNewEndpoint(nil)))
endpoints := []netaddr.IPPort{
netaddr.MustParseIPPort("10.3.4.5:10500"),
netaddr.MustParseIPPort("192.168.3.8:457"),
endpoints := []netip.AddrPort{
netip.MustParseAddrPort("10.3.4.5:10500"),
netip.MustParseAddrPort("192.168.3.8:457"),
}
// initial choice should be the first endpoint
@ -43,7 +44,7 @@ func TestPeerStatus_PickNewEndpoint(t *testing.T) {
kubespanadapter.PeerStatusSpec(&peerStatus).UpdateEndpoint(newEndpoint)
// can't rotate a single endpoint
assert.True(t, kubespanadapter.PeerStatusSpec(&peerStatus).PickNewEndpoint(endpoints[:1]).IsZero())
assert.True(t, generic.IsZero(kubespanadapter.PeerStatusSpec(&peerStatus).PickNewEndpoint(endpoints[:1])))
// can rotate if the endpoint is different
newEndpoint = kubespanadapter.PeerStatusSpec(&peerStatus).PickNewEndpoint(endpoints[1:])
@ -51,9 +52,9 @@ func TestPeerStatus_PickNewEndpoint(t *testing.T) {
kubespanadapter.PeerStatusSpec(&peerStatus).UpdateEndpoint(newEndpoint)
// if totally new list of endpoints is given, pick the first one
endpoints = []netaddr.IPPort{
netaddr.MustParseIPPort("10.3.4.5:10501"),
netaddr.MustParseIPPort("192.168.3.8:458"),
endpoints = []netip.AddrPort{
netip.MustParseAddrPort("10.3.4.5:10501"),
netip.MustParseAddrPort("192.168.3.8:458"),
}
newEndpoint = kubespanadapter.PeerStatusSpec(&peerStatus).PickNewEndpoint(endpoints)
assert.Equal(t, endpoints[0], newEndpoint)
@ -123,7 +124,7 @@ func TestPeerStatus_CalculateState(t *testing.T) {
}
if !tt.lastUsedEndpointZero {
peerStatus.LastUsedEndpoint = netaddr.MustParseIPPort("192.168.1.1:10000")
peerStatus.LastUsedEndpoint = netip.MustParseAddrPort("192.168.1.1:10000")
}
kubespanadapter.PeerStatusSpec(&peerStatus).CalculateStateWithDurations(tt.sinceLastHandshake, tt.sinceEndpointChange)

View File

@ -6,9 +6,10 @@ package network
import (
"net"
"net/netip"
"go4.org/netipx"
"golang.zx2c4.com/wireguard/wgctrl/wgtypes"
"inet.af/netaddr"
"github.com/talos-systems/talos/pkg/machinery/generic/slices"
"github.com/talos-systems/talos/pkg/machinery/resources/network"
@ -95,8 +96,8 @@ func (a wireguardSpec) Encode(existing *network.WireguardSpec) (*wgtypes.Config,
PresharedKey: presharedKey,
PersistentKeepaliveInterval: &peer.PersistentKeepaliveInterval,
ReplaceAllowedIPs: true,
AllowedIPs: slices.Map(peer.AllowedIPs, func(peerIP netaddr.IPPrefix) net.IPNet {
return *peerIP.IPNet()
AllowedIPs: slices.Map(peer.AllowedIPs, func(peerIP netip.Prefix) net.IPNet {
return *netipx.PrefixIPNet(peerIP)
}),
})
@ -189,8 +190,8 @@ func (a wireguardSpec) Decode(dev *wgtypes.Device, isStatus bool) {
}
spec.Peers[i].PersistentKeepaliveInterval = dev.Peers[i].PersistentKeepaliveInterval
spec.Peers[i].AllowedIPs = slices.Map(dev.Peers[i].AllowedIPs, func(peerIP net.IPNet) netaddr.IPPrefix {
res, _ := netaddr.FromStdIPNet(&peerIP)
spec.Peers[i].AllowedIPs = slices.Map(dev.Peers[i].AllowedIPs, func(peerIP net.IPNet) netip.Prefix {
res, _ := netipx.FromStdIPNet(&peerIP)
return res
})

View File

@ -6,6 +6,7 @@ package network_test
import (
"net"
"net/netip"
"testing"
"time"
@ -13,7 +14,6 @@ import (
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"golang.zx2c4.com/wireguard/wgctrl/wgtypes"
"inet.af/netaddr"
networkadapter "github.com/talos-systems/talos/internal/app/machined/pkg/adapters/network"
"github.com/talos-systems/talos/pkg/machinery/resources/network"
@ -72,14 +72,14 @@ func TestWireguardSpecDecode(t *testing.T) {
PublicKey: pub1.PublicKey().String(),
PresharedKey: priv.String(),
Endpoint: "10.2.0.3:20000",
AllowedIPs: []netaddr.IPPrefix{
netaddr.MustParseIPPrefix("172.24.0.0/16"),
AllowedIPs: []netip.Prefix{
netip.MustParsePrefix("172.24.0.0/16"),
},
},
{
PublicKey: pub2.PublicKey().String(),
AllowedIPs: []netaddr.IPPrefix{
netaddr.MustParseIPPrefix("172.25.0.0/24"),
AllowedIPs: []netip.Prefix{
netip.MustParsePrefix("172.25.0.0/24"),
},
},
},
@ -149,14 +149,14 @@ func TestWireguardSpecEncode(t *testing.T) {
{
PublicKey: pub1.PublicKey().String(),
Endpoint: "10.2.0.3:20000",
AllowedIPs: []netaddr.IPPrefix{
netaddr.MustParseIPPrefix("172.24.0.0/16"),
AllowedIPs: []netip.Prefix{
netip.MustParsePrefix("172.24.0.0/16"),
},
},
{
PublicKey: pub2.PublicKey().String(),
AllowedIPs: []netaddr.IPPrefix{
netaddr.MustParseIPPrefix("172.25.0.0/24"),
AllowedIPs: []netip.Prefix{
netip.MustParsePrefix("172.25.0.0/24"),
},
},
},
@ -222,8 +222,8 @@ func TestWireguardSpecEncode(t *testing.T) {
{
PublicKey: pub1.PublicKey().String(),
Endpoint: "10.2.0.3:20000",
AllowedIPs: []netaddr.IPPrefix{
netaddr.MustParseIPPrefix("172.24.0.0/16"),
AllowedIPs: []netip.Prefix{
netip.MustParsePrefix("172.24.0.0/16"),
},
},
},
@ -250,8 +250,8 @@ func TestWireguardSpecEncode(t *testing.T) {
{
PublicKey: pub1.PublicKey().String(),
PresharedKey: priv.String(),
AllowedIPs: []netaddr.IPPrefix{
netaddr.MustParseIPPrefix("172.24.0.0/16"),
AllowedIPs: []netip.Prefix{
netip.MustParsePrefix("172.24.0.0/16"),
},
},
},

View File

@ -5,13 +5,13 @@
package cluster_test
import (
"net/netip"
"testing"
"time"
"github.com/cosi-project/runtime/pkg/resource"
"github.com/stretchr/testify/suite"
"github.com/talos-systems/go-retry/retry"
"inet.af/netaddr"
clusterctrl "github.com/talos-systems/talos/internal/app/machined/pkg/controllers/cluster"
"github.com/talos-systems/talos/pkg/machinery/config/types/v1alpha1/machine"
@ -33,12 +33,12 @@ func (suite *AffiliateMergeSuite) TestReconcileDefault() {
Hostname: "foo.com",
Nodename: "bar",
MachineType: machine.TypeControlPlane,
Addresses: []netaddr.IP{netaddr.MustParseIP("192.168.3.4")},
Addresses: []netip.Addr{netip.MustParseAddr("192.168.3.4")},
KubeSpan: cluster.KubeSpanAffiliateSpec{
PublicKey: "PLPNBddmTgHJhtw0vxltq1ZBdPP9RNOEUd5JjJZzBRY=",
Address: netaddr.MustParseIP("fd50:8d60:4238:6302:f857:23ff:fe21:d1e0"),
AdditionalAddresses: []netaddr.IPPrefix{netaddr.MustParseIPPrefix("10.244.3.1/24")},
Endpoints: []netaddr.IPPort{netaddr.MustParseIPPort("10.0.0.2:51820"), netaddr.MustParseIPPort("192.168.3.4:51820")},
Address: netip.MustParseAddr("fd50:8d60:4238:6302:f857:23ff:fe21:d1e0"),
AdditionalAddresses: []netip.Prefix{netip.MustParsePrefix("10.244.3.1/24")},
Endpoints: []netip.AddrPort{netip.MustParseAddrPort("10.0.0.2:51820"), netip.MustParseAddrPort("192.168.3.4:51820")},
},
}
@ -48,7 +48,7 @@ func (suite *AffiliateMergeSuite) TestReconcileDefault() {
Hostname: "foo.com",
Nodename: "bar",
MachineType: machine.TypeControlPlane,
Addresses: []netaddr.IP{netaddr.MustParseIP("192.168.3.4"), netaddr.MustParseIP("10.5.0.2")},
Addresses: []netip.Addr{netip.MustParseAddr("192.168.3.4"), netip.MustParseAddr("10.5.0.2")},
}
affiliate3 := cluster.NewAffiliate(cluster.RawNamespaceName, "service/9dwHNUViZlPlIervqX9Qo256RUhrfhgO0xBBnKcKl4F")
@ -57,7 +57,7 @@ func (suite *AffiliateMergeSuite) TestReconcileDefault() {
Hostname: "worker-1",
Nodename: "worker-1",
MachineType: machine.TypeWorker,
Addresses: []netaddr.IP{netaddr.MustParseIP("192.168.3.5")},
Addresses: []netip.Addr{netip.MustParseAddr("192.168.3.5")},
}
for _, r := range []resource.Resource{affiliate1, affiliate2, affiliate3} {
@ -70,14 +70,14 @@ func (suite *AffiliateMergeSuite) TestReconcileDefault() {
spec := r.(*cluster.Affiliate).TypedSpec()
suite.Assert().Equal(affiliate1.TypedSpec().NodeID, spec.NodeID)
suite.Assert().Equal([]netaddr.IP{netaddr.MustParseIP("192.168.3.4"), netaddr.MustParseIP("10.5.0.2")}, spec.Addresses)
suite.Assert().Equal([]netip.Addr{netip.MustParseAddr("192.168.3.4"), netip.MustParseAddr("10.5.0.2")}, spec.Addresses)
suite.Assert().Equal("foo.com", spec.Hostname)
suite.Assert().Equal("bar", spec.Nodename)
suite.Assert().Equal(machine.TypeControlPlane, spec.MachineType)
suite.Assert().Equal(netaddr.MustParseIP("fd50:8d60:4238:6302:f857:23ff:fe21:d1e0"), spec.KubeSpan.Address)
suite.Assert().Equal(netip.MustParseAddr("fd50:8d60:4238:6302:f857:23ff:fe21:d1e0"), spec.KubeSpan.Address)
suite.Assert().Equal("PLPNBddmTgHJhtw0vxltq1ZBdPP9RNOEUd5JjJZzBRY=", spec.KubeSpan.PublicKey)
suite.Assert().Equal([]netaddr.IPPrefix{netaddr.MustParseIPPrefix("10.244.3.1/24")}, spec.KubeSpan.AdditionalAddresses)
suite.Assert().Equal([]netaddr.IPPort{netaddr.MustParseIPPort("10.0.0.2:51820"), netaddr.MustParseIPPort("192.168.3.4:51820")}, spec.KubeSpan.Endpoints)
suite.Assert().Equal([]netip.Prefix{netip.MustParsePrefix("10.244.3.1/24")}, spec.KubeSpan.AdditionalAddresses)
suite.Assert().Equal([]netip.AddrPort{netip.MustParseAddrPort("10.0.0.2:51820"), netip.MustParseAddrPort("192.168.3.4:51820")}, spec.KubeSpan.Endpoints)
return nil
}),
@ -88,7 +88,7 @@ func (suite *AffiliateMergeSuite) TestReconcileDefault() {
spec := r.(*cluster.Affiliate).TypedSpec()
suite.Assert().Equal(affiliate3.TypedSpec().NodeID, spec.NodeID)
suite.Assert().Equal([]netaddr.IP{netaddr.MustParseIP("192.168.3.5")}, spec.Addresses)
suite.Assert().Equal([]netip.Addr{netip.MustParseAddr("192.168.3.5")}, spec.Addresses)
suite.Assert().Equal("worker-1", spec.Hostname)
suite.Assert().Equal("worker-1", spec.Nodename)
suite.Assert().Equal(machine.TypeWorker, spec.MachineType)

View File

@ -10,6 +10,7 @@ import (
"crypto/cipher"
"errors"
"fmt"
"net/netip"
"time"
"github.com/cosi-project/runtime/pkg/controller"
@ -19,7 +20,6 @@ import (
"github.com/talos-systems/discovery-api/api/v1alpha1/client/pb"
discoveryclient "github.com/talos-systems/discovery-client/pkg/client"
"go.uber.org/zap"
"inet.af/netaddr"
"github.com/talos-systems/talos/pkg/machinery/config/types/v1alpha1/machine"
"github.com/talos-systems/talos/pkg/machinery/generic/slices"
@ -280,7 +280,7 @@ func (ctrl *DiscoveryServiceController) Run(ctx context.Context, r controller.Ru
}
func pbAffiliate(affiliate *cluster.AffiliateSpec) *pb.Affiliate {
addresses := slices.Map(affiliate.Addresses, func(address netaddr.IP) []byte {
addresses := slices.Map(affiliate.Addresses, func(address netip.Addr) []byte {
result, _ := address.MarshalBinary() //nolint:errcheck // doesn't fail
return result
@ -302,7 +302,7 @@ func pbAffiliate(affiliate *cluster.AffiliateSpec) *pb.Affiliate {
Bits: uint32(affiliate.KubeSpan.AdditionalAddresses[i].Bits()),
}
additionalAddresses[i].Ip, _ = affiliate.KubeSpan.AdditionalAddresses[i].IP().MarshalBinary() //nolint:errcheck // doesn't fail
additionalAddresses[i].Ip, _ = affiliate.KubeSpan.AdditionalAddresses[i].Addr().MarshalBinary() //nolint:errcheck // doesn't fail
}
kubeSpan.AdditionalAddresses = additionalAddresses
@ -331,7 +331,7 @@ func pbEndpoints(affiliate *cluster.AffiliateSpec) []*pb.Endpoint {
Port: uint32(affiliate.KubeSpan.Endpoints[i].Port()),
}
result[i].Ip, _ = affiliate.KubeSpan.Endpoints[i].IP().MarshalBinary() //nolint:errcheck // doesn't fail
result[i].Ip, _ = affiliate.KubeSpan.Endpoints[i].Addr().MarshalBinary() //nolint:errcheck // doesn't fail
}
return result
@ -351,7 +351,7 @@ func pbOtherEndpoints(otherEndpointsList resource.List) []discoveryclient.Endpoi
Port: uint32(endpoint.Endpoint.Port()),
}
encodedEndpoint.Ip, _ = endpoint.Endpoint.IP().MarshalBinary() //nolint:errcheck // doesn't fail
encodedEndpoint.Ip, _ = endpoint.Endpoint.Addr().MarshalBinary() //nolint:errcheck // doesn't fail
result = append(result, discoveryclient.Endpoint{
AffiliateID: endpoint.AffiliateID,
@ -414,10 +414,10 @@ func specAffiliate(affiliate *pb.Affiliate, endpoints []*pb.Endpoint) cluster.Af
result.MachineType, _ = machine.ParseType(affiliate.MachineType) //nolint:errcheck // ignore parse error (machine.TypeUnknown)
result.Addresses = make([]netaddr.IP, 0, len(affiliate.Addresses))
result.Addresses = make([]netip.Addr, 0, len(affiliate.Addresses))
for i := range affiliate.Addresses {
var ip netaddr.IP
var ip netip.Addr
if err := ip.UnmarshalBinary(affiliate.Addresses[i]); err == nil {
result.Addresses = append(result.Addresses, ip)
@ -428,23 +428,23 @@ func specAffiliate(affiliate *pb.Affiliate, endpoints []*pb.Endpoint) cluster.Af
result.KubeSpan.PublicKey = affiliate.Kubespan.PublicKey
result.KubeSpan.Address.UnmarshalBinary(affiliate.Kubespan.Address) //nolint:errcheck // ignore error, address will be zero
result.KubeSpan.AdditionalAddresses = make([]netaddr.IPPrefix, 0, len(affiliate.Kubespan.AdditionalAddresses))
result.KubeSpan.AdditionalAddresses = make([]netip.Prefix, 0, len(affiliate.Kubespan.AdditionalAddresses))
for i := range affiliate.Kubespan.AdditionalAddresses {
var ip netaddr.IP
var ip netip.Addr
if err := ip.UnmarshalBinary(affiliate.Kubespan.AdditionalAddresses[i].Ip); err == nil {
result.KubeSpan.AdditionalAddresses = append(result.KubeSpan.AdditionalAddresses, netaddr.IPPrefixFrom(ip, uint8(affiliate.Kubespan.AdditionalAddresses[i].Bits)))
result.KubeSpan.AdditionalAddresses = append(result.KubeSpan.AdditionalAddresses, netip.PrefixFrom(ip, int(affiliate.Kubespan.AdditionalAddresses[i].Bits)))
}
}
result.KubeSpan.Endpoints = make([]netaddr.IPPort, 0, len(endpoints))
result.KubeSpan.Endpoints = make([]netip.AddrPort, 0, len(endpoints))
for i := range endpoints {
var ip netaddr.IP
var ip netip.Addr
if err := ip.UnmarshalBinary(endpoints[i].Ip); err == nil {
result.KubeSpan.Endpoints = append(result.KubeSpan.Endpoints, netaddr.IPPortFrom(ip, uint16(endpoints[i].Port)))
result.KubeSpan.Endpoints = append(result.KubeSpan.Endpoints, netip.AddrPortFrom(ip, uint16(endpoints[i].Port)))
}
}
}

View File

@ -11,6 +11,7 @@ import (
"encoding/base64"
"io"
"log"
"net/netip"
"net/url"
"testing"
"time"
@ -20,7 +21,6 @@ import (
"github.com/talos-systems/discovery-api/api/v1alpha1/client/pb"
"github.com/talos-systems/discovery-client/pkg/client"
"github.com/talos-systems/go-retry/retry"
"inet.af/netaddr"
clusteradapter "github.com/talos-systems/talos/internal/app/machined/pkg/adapters/cluster"
clusterctrl "github.com/talos-systems/talos/internal/app/machined/pkg/controllers/cluster"
@ -78,12 +78,12 @@ func (suite *DiscoveryServiceSuite) TestReconcile() {
Hostname: "foo.com",
Nodename: "bar",
MachineType: machine.TypeControlPlane,
Addresses: []netaddr.IP{netaddr.MustParseIP("192.168.3.4")},
Addresses: []netip.Addr{netip.MustParseAddr("192.168.3.4")},
KubeSpan: cluster.KubeSpanAffiliateSpec{
PublicKey: "PLPNBddmTgHJhtw0vxltq1ZBdPP9RNOEUd5JjJZzBRY=",
Address: netaddr.MustParseIP("fd50:8d60:4238:6302:f857:23ff:fe21:d1e0"),
AdditionalAddresses: []netaddr.IPPrefix{netaddr.MustParseIPPrefix("10.244.3.1/24")},
Endpoints: []netaddr.IPPort{netaddr.MustParseIPPort("10.0.0.2:51820"), netaddr.MustParseIPPort("192.168.3.4:51820")},
Address: netip.MustParseAddr("fd50:8d60:4238:6302:f857:23ff:fe21:d1e0"),
AdditionalAddresses: []netip.Prefix{netip.MustParsePrefix("10.244.3.1/24")},
Endpoints: []netip.AddrPort{netip.MustParseAddrPort("10.0.0.2:51820"), netip.MustParseAddrPort("192.168.3.4:51820")},
},
}
suite.Require().NoError(suite.state.Create(suite.ctx, localAffiliate))
@ -189,15 +189,15 @@ func (suite *DiscoveryServiceSuite) TestReconcile() {
spec := r.(*cluster.Affiliate).TypedSpec()
suite.Assert().Equal("7x1SuC8Ege5BGXdAfTEff5iQnlWZLfv9h1LGMxA2pYkC", spec.NodeID)
suite.Assert().Equal([]netaddr.IP{netaddr.MustParseIP("192.168.3.5")}, spec.Addresses)
suite.Assert().Equal([]netip.Addr{netip.MustParseAddr("192.168.3.5")}, spec.Addresses)
suite.Assert().Equal("some.com", spec.Hostname)
suite.Assert().Equal("some", spec.Nodename)
suite.Assert().Equal(machine.TypeWorker, spec.MachineType)
suite.Assert().Equal("test OS", spec.OperatingSystem)
suite.Assert().Equal(netaddr.MustParseIP("fd50:8d60:4238:6302:f857:23ff:fe21:d1e1"), spec.KubeSpan.Address)
suite.Assert().Equal(netip.MustParseAddr("fd50:8d60:4238:6302:f857:23ff:fe21:d1e1"), spec.KubeSpan.Address)
suite.Assert().Equal("1CXkdhWBm58c36kTpchR8iGlXHG1ruHa5W8gsFqD8Qs=", spec.KubeSpan.PublicKey)
suite.Assert().Equal([]netaddr.IPPrefix{netaddr.MustParseIPPrefix("10.244.4.1/24")}, spec.KubeSpan.AdditionalAddresses)
suite.Assert().Equal([]netaddr.IPPort{netaddr.MustParseIPPort("192.168.3.5:51820")}, spec.KubeSpan.Endpoints)
suite.Assert().Equal([]netip.Prefix{netip.MustParsePrefix("10.244.4.1/24")}, spec.KubeSpan.AdditionalAddresses)
suite.Assert().Equal([]netip.AddrPort{netip.MustParseAddrPort("192.168.3.5:51820")}, spec.KubeSpan.Endpoints)
return nil
}),
@ -207,7 +207,7 @@ func (suite *DiscoveryServiceSuite) TestReconcile() {
endpoint := kubespan.NewEndpoint(kubespan.NamespaceName, "1CXkdhWBm58c36kTpchR8iGlXHG1ruHa5W8gsFqD8Qs=")
*endpoint.TypedSpec() = kubespan.EndpointSpec{
AffiliateID: "7x1SuC8Ege5BGXdAfTEff5iQnlWZLfv9h1LGMxA2pYkC",
Endpoint: netaddr.MustParseIPPort("1.1.1.1:343"),
Endpoint: netip.MustParseAddrPort("1.1.1.1:343"),
}
suite.Require().NoError(suite.state.Create(suite.ctx, endpoint))
@ -219,9 +219,9 @@ func (suite *DiscoveryServiceSuite) TestReconcile() {
return retry.ExpectedErrorf("waiting for 2 endpoints, got %d", len(spec.KubeSpan.Endpoints))
}
suite.Assert().Equal([]netaddr.IPPort{
netaddr.MustParseIPPort("192.168.3.5:51820"),
netaddr.MustParseIPPort("1.1.1.1:343"),
suite.Assert().Equal([]netip.AddrPort{
netip.MustParseAddrPort("192.168.3.5:51820"),
netip.MustParseAddrPort("1.1.1.1:343"),
}, spec.KubeSpan.Endpoints)
return nil
@ -273,7 +273,7 @@ func (suite *DiscoveryServiceSuite) TestDisable() {
Hostname: "foo.com",
Nodename: "bar",
MachineType: machine.TypeControlPlane,
Addresses: []netaddr.IP{netaddr.MustParseIP("192.168.3.4")},
Addresses: []netip.Addr{netip.MustParseAddr("192.168.3.4")},
}
suite.Require().NoError(suite.state.Create(suite.ctx, localAffiliate))

View File

@ -7,13 +7,13 @@ package cluster
import (
"context"
"fmt"
"net/netip"
"reflect"
"sort"
"github.com/cosi-project/runtime/pkg/controller"
"github.com/cosi-project/runtime/pkg/resource"
"go.uber.org/zap"
"inet.af/netaddr"
"github.com/talos-systems/talos/pkg/machinery/config/types/v1alpha1/machine"
"github.com/talos-systems/talos/pkg/machinery/resources/cluster"
@ -63,7 +63,7 @@ func (ctrl *EndpointController) Run(ctx context.Context, r controller.Runtime, l
return fmt.Errorf("error listing members: %w", err)
}
var endpoints []netaddr.IP
var endpoints []netip.Addr
for _, res := range memberList.Items {
member := res.(*cluster.Member).TypedSpec()

View File

@ -6,13 +6,13 @@ package cluster_test
import (
"fmt"
"net/netip"
"testing"
"time"
"github.com/cosi-project/runtime/pkg/resource"
"github.com/stretchr/testify/suite"
"github.com/talos-systems/go-retry/retry"
"inet.af/netaddr"
clusterctrl "github.com/talos-systems/talos/internal/app/machined/pkg/controllers/cluster"
"github.com/talos-systems/talos/pkg/machinery/config/types/v1alpha1/machine"
@ -32,7 +32,7 @@ func (suite *EndpointSuite) TestReconcileDefault() {
member1 := cluster.NewMember(cluster.NamespaceName, "talos-default-controlplane-1")
*member1.TypedSpec() = cluster.MemberSpec{
NodeID: "7x1SuC8Ege5BGXdAfTEff5iQnlWZLfv9h1LGMxA2pYkC",
Addresses: []netaddr.IP{netaddr.MustParseIP("172.20.0.2"), netaddr.MustParseIP("fd50:8d60:4238:6302:f857:23ff:fe21:d1e0")},
Addresses: []netip.Addr{netip.MustParseAddr("172.20.0.2"), netip.MustParseAddr("fd50:8d60:4238:6302:f857:23ff:fe21:d1e0")},
Hostname: "talos-default-controlplane-1",
MachineType: machine.TypeControlPlane,
OperatingSystem: "Talos (v1.0.0)",
@ -41,7 +41,7 @@ func (suite *EndpointSuite) TestReconcileDefault() {
member2 := cluster.NewMember(cluster.NamespaceName, "talos-default-controlplane-2")
*member2.TypedSpec() = cluster.MemberSpec{
NodeID: "9dwHNUViZlPlIervqX9Qo256RUhrfhgO0xBBnKcKl4F",
Addresses: []netaddr.IP{netaddr.MustParseIP("172.20.0.3"), netaddr.MustParseIP("fd50:8d60:4238:6302:f857:23ff:fe21:d1e1")},
Addresses: []netip.Addr{netip.MustParseAddr("172.20.0.3"), netip.MustParseAddr("fd50:8d60:4238:6302:f857:23ff:fe21:d1e1")},
Hostname: "talos-default-controlplane-2",
MachineType: machine.TypeControlPlane,
OperatingSystem: "Talos (v1.0.0)",
@ -50,7 +50,7 @@ func (suite *EndpointSuite) TestReconcileDefault() {
member3 := cluster.NewMember(cluster.NamespaceName, "talos-default-worker-1")
*member3.TypedSpec() = cluster.MemberSpec{
NodeID: "xCnFFfxylOf9i5ynhAkt6ZbfcqaLDGKfIa3gwpuaxe7F",
Addresses: []netaddr.IP{netaddr.MustParseIP("172.20.0.4")},
Addresses: []netip.Addr{netip.MustParseAddr("172.20.0.4")},
Hostname: "talos-default-worker-1",
MachineType: machine.TypeWorker,
OperatingSystem: "Talos (v1.0.0)",

View File

@ -7,6 +7,7 @@ package cluster
import (
"context"
"fmt"
"net/netip"
"github.com/cosi-project/runtime/pkg/controller"
"github.com/cosi-project/runtime/pkg/resource"
@ -14,7 +15,6 @@ import (
"github.com/cosi-project/runtime/pkg/state"
"github.com/siderolabs/go-pointer"
"go.uber.org/zap"
"inet.af/netaddr"
"github.com/talos-systems/talos/pkg/machinery/constants"
"github.com/talos-systems/talos/pkg/machinery/resources/cluster"
@ -194,7 +194,7 @@ func (ctrl *LocalAffiliateController) Run(ctx context.Context, r controller.Runt
nodeIPs := addresses.(*network.NodeAddress).TypedSpec().IPs()
spec.Addresses = make([]netaddr.IP, 0, len(nodeIPs))
spec.Addresses = make([]netip.Addr, 0, len(nodeIPs))
for _, ip := range nodeIPs {
if network.IsULA(ip, network.ULASideroLink) {
@ -208,16 +208,16 @@ func (ctrl *LocalAffiliateController) Run(ctx context.Context, r controller.Runt
spec.KubeSpan = cluster.KubeSpanAffiliateSpec{}
if kubespanIdentity != nil && kubespanConfig != nil {
spec.KubeSpan.Address = kubespanIdentity.(*kubespan.Identity).TypedSpec().Address.IP()
spec.KubeSpan.Address = kubespanIdentity.(*kubespan.Identity).TypedSpec().Address.Addr()
spec.KubeSpan.PublicKey = kubespanIdentity.(*kubespan.Identity).TypedSpec().PublicKey
if kubespanConfig.TypedSpec().AdvertiseKubernetesNetworks {
spec.KubeSpan.AdditionalAddresses = append([]netaddr.IPPrefix(nil), ksAdditionalAddresses.(*network.NodeAddress).TypedSpec().Addresses...)
spec.KubeSpan.AdditionalAddresses = append([]netip.Prefix(nil), ksAdditionalAddresses.(*network.NodeAddress).TypedSpec().Addresses...)
} else {
spec.KubeSpan.AdditionalAddresses = nil
}
endpoints := make([]netaddr.IPPort, 0, len(nodeIPs))
endpoints := make([]netip.AddrPort, 0, len(nodeIPs))
for _, ip := range nodeIPs {
if ip == spec.KubeSpan.Address {
@ -230,7 +230,7 @@ func (ctrl *LocalAffiliateController) Run(ctx context.Context, r controller.Runt
continue
}
endpoints = append(endpoints, netaddr.IPPortFrom(ip, constants.KubeSpanDefaultPort))
endpoints = append(endpoints, netip.AddrPortFrom(ip, constants.KubeSpanDefaultPort))
}
spec.KubeSpan.Endpoints = endpoints

View File

@ -6,13 +6,13 @@ package cluster_test
import (
"net"
"net/netip"
"testing"
"time"
"github.com/cosi-project/runtime/pkg/resource"
"github.com/stretchr/testify/suite"
"github.com/talos-systems/go-retry/retry"
"inet.af/netaddr"
clusteradapter "github.com/talos-systems/talos/internal/app/machined/pkg/adapters/cluster"
kubespanadapter "github.com/talos-systems/talos/internal/app/machined/pkg/adapters/kubespan"
@ -53,10 +53,10 @@ func (suite *LocalAffiliateSuite) TestGeneration() {
suite.Require().NoError(suite.state.Create(suite.ctx, nodename))
nonK8sAddresses := network.NewNodeAddress(network.NamespaceName, network.FilteredNodeAddressID(network.NodeAddressCurrentID, k8s.NodeAddressFilterNoK8s))
nonK8sAddresses.TypedSpec().Addresses = []netaddr.IPPrefix{
netaddr.MustParseIPPrefix("172.20.0.2/24"),
netaddr.MustParseIPPrefix("10.5.0.1/32"),
netaddr.MustParseIPPrefix("fdae:41e4:649b:9303:60be:7e36:c270:3238/128"), // SideroLink, should be ignored
nonK8sAddresses.TypedSpec().Addresses = []netip.Prefix{
netip.MustParsePrefix("172.20.0.2/24"),
netip.MustParsePrefix("10.5.0.1/32"),
netip.MustParsePrefix("fdae:41e4:649b:9303:60be:7e36:c270:3238/128"), // SideroLink, should be ignored
}
suite.Require().NoError(suite.state.Create(suite.ctx, nonK8sAddresses))
@ -68,7 +68,7 @@ func (suite *LocalAffiliateSuite) TestGeneration() {
suite.assertResource(*cluster.NewAffiliate(cluster.NamespaceName, nodeIdentity.TypedSpec().NodeID).Metadata(), func(r resource.Resource) error {
spec := r.(*cluster.Affiliate).TypedSpec()
suite.Assert().Equal([]netaddr.IP{netaddr.MustParseIP("172.20.0.2"), netaddr.MustParseIP("10.5.0.1")}, spec.Addresses)
suite.Assert().Equal([]netip.Addr{netip.MustParseAddr("172.20.0.2"), netip.MustParseAddr("10.5.0.1")}, spec.Addresses)
suite.Assert().Equal("example1", spec.Hostname)
suite.Assert().Equal("example1.com", spec.Nodename)
suite.Assert().Equal(machine.TypeWorker, spec.MachineType)
@ -99,7 +99,7 @@ func (suite *LocalAffiliateSuite) TestGeneration() {
suite.Require().NoError(suite.state.Update(suite.ctx, oldVersion, nonK8sAddresses))
onlyK8sAddresses := network.NewNodeAddress(network.NamespaceName, network.FilteredNodeAddressID(network.NodeAddressCurrentID, k8s.NodeAddressFilterOnlyK8s))
onlyK8sAddresses.TypedSpec().Addresses = []netaddr.IPPrefix{netaddr.MustParseIPPrefix("10.244.1.0/24")}
onlyK8sAddresses.TypedSpec().Addresses = []netip.Prefix{netip.MustParsePrefix("10.244.1.0/24")}
suite.Require().NoError(suite.state.Create(suite.ctx, onlyK8sAddresses))
suite.Assert().NoError(retry.Constant(3*time.Second, retry.WithUnits(100*time.Millisecond)).Retry(
@ -110,7 +110,7 @@ func (suite *LocalAffiliateSuite) TestGeneration() {
return retry.ExpectedErrorf("not reconciled yet")
}
suite.Assert().Equal([]netaddr.IP{netaddr.MustParseIP("172.20.0.2"), netaddr.MustParseIP("10.5.0.1"), ksIdentity.TypedSpec().Address.IP()}, spec.Addresses)
suite.Assert().Equal([]netip.Addr{netip.MustParseAddr("172.20.0.2"), netip.MustParseAddr("10.5.0.1"), ksIdentity.TypedSpec().Address.Addr()}, spec.Addresses)
suite.Assert().Equal("example1", spec.Hostname)
suite.Assert().Equal("example1.com", spec.Nodename)
suite.Assert().Equal(machine.TypeWorker, spec.MachineType)
@ -123,10 +123,10 @@ func (suite *LocalAffiliateSuite) TestGeneration() {
return retry.ExpectedErrorf("kubespan is not filled in yet")
}
suite.Assert().Equal(ksIdentity.TypedSpec().Address.IP(), spec.KubeSpan.Address)
suite.Assert().Equal(ksIdentity.TypedSpec().Address.Addr(), spec.KubeSpan.Address)
suite.Assert().Equal(ksIdentity.TypedSpec().PublicKey, spec.KubeSpan.PublicKey)
suite.Assert().Equal([]netaddr.IPPrefix{netaddr.MustParseIPPrefix("10.244.1.0/24")}, spec.KubeSpan.AdditionalAddresses)
suite.Assert().Equal([]netaddr.IPPort{netaddr.MustParseIPPort("172.20.0.2:51820"), netaddr.MustParseIPPort("10.5.0.1:51820")}, spec.KubeSpan.Endpoints)
suite.Assert().Equal([]netip.Prefix{netip.MustParsePrefix("10.244.1.0/24")}, spec.KubeSpan.AdditionalAddresses)
suite.Assert().Equal([]netip.AddrPort{netip.MustParseAddrPort("172.20.0.2:51820"), netip.MustParseAddrPort("10.5.0.1:51820")}, spec.KubeSpan.Endpoints)
return nil
}),

View File

@ -7,11 +7,11 @@ package cluster
import (
"context"
"fmt"
"net/netip"
"github.com/cosi-project/runtime/pkg/controller"
"github.com/cosi-project/runtime/pkg/resource"
"go.uber.org/zap"
"inet.af/netaddr"
"github.com/talos-systems/talos/pkg/machinery/resources/cluster"
)
@ -73,7 +73,7 @@ func (ctrl *MemberController) Run(ctx context.Context, r controller.Runtime, log
if err = r.Modify(ctx, cluster.NewMember(cluster.NamespaceName, affiliateSpec.Nodename), func(res resource.Resource) error {
spec := res.(*cluster.Member).TypedSpec()
spec.Addresses = append([]netaddr.IP(nil), affiliateSpec.Addresses...)
spec.Addresses = append([]netip.Addr(nil), affiliateSpec.Addresses...)
spec.Hostname = affiliateSpec.Hostname
spec.MachineType = affiliateSpec.MachineType
spec.OperatingSystem = affiliateSpec.OperatingSystem

View File

@ -5,13 +5,13 @@
package cluster_test
import (
"net/netip"
"testing"
"time"
"github.com/cosi-project/runtime/pkg/resource"
"github.com/stretchr/testify/suite"
"github.com/talos-systems/go-retry/retry"
"inet.af/netaddr"
clusterctrl "github.com/talos-systems/talos/internal/app/machined/pkg/controllers/cluster"
"github.com/talos-systems/talos/pkg/machinery/config/types/v1alpha1/machine"
@ -34,12 +34,12 @@ func (suite *MemberSuite) TestReconcileDefault() {
Nodename: "bar",
MachineType: machine.TypeControlPlane,
OperatingSystem: "Talos (v1.0.0)",
Addresses: []netaddr.IP{netaddr.MustParseIP("192.168.3.4")},
Addresses: []netip.Addr{netip.MustParseAddr("192.168.3.4")},
KubeSpan: cluster.KubeSpanAffiliateSpec{
PublicKey: "PLPNBddmTgHJhtw0vxltq1ZBdPP9RNOEUd5JjJZzBRY=",
Address: netaddr.MustParseIP("fd50:8d60:4238:6302:f857:23ff:fe21:d1e0"),
AdditionalAddresses: []netaddr.IPPrefix{netaddr.MustParseIPPrefix("10.244.3.1/24")},
Endpoints: []netaddr.IPPort{netaddr.MustParseIPPort("10.0.0.2:51820"), netaddr.MustParseIPPort("192.168.3.4:51820")},
Address: netip.MustParseAddr("fd50:8d60:4238:6302:f857:23ff:fe21:d1e0"),
AdditionalAddresses: []netip.Prefix{netip.MustParsePrefix("10.244.3.1/24")},
Endpoints: []netip.AddrPort{netip.MustParseAddrPort("10.0.0.2:51820"), netip.MustParseAddrPort("192.168.3.4:51820")},
},
}
@ -49,14 +49,14 @@ func (suite *MemberSuite) TestReconcileDefault() {
Hostname: "worker-1",
Nodename: "worker-1",
MachineType: machine.TypeWorker,
Addresses: []netaddr.IP{netaddr.MustParseIP("192.168.3.5")},
Addresses: []netip.Addr{netip.MustParseAddr("192.168.3.5")},
}
affiliate3 := cluster.NewAffiliate(cluster.NamespaceName, "xCnFFfxylOf9i5ynhAkt6ZbfcqaLDGKfIa3gwpuaxe7F")
*affiliate3.TypedSpec() = cluster.AffiliateSpec{
NodeID: "xCnFFfxylOf9i5ynhAkt6ZbfcqaLDGKfIa3gwpuaxe7F",
MachineType: machine.TypeWorker,
Addresses: []netaddr.IP{netaddr.MustParseIP("192.168.3.6")},
Addresses: []netip.Addr{netip.MustParseAddr("192.168.3.6")},
}
for _, r := range []resource.Resource{affiliate1, affiliate2, affiliate3} {
@ -69,7 +69,7 @@ func (suite *MemberSuite) TestReconcileDefault() {
spec := r.(*cluster.Member).TypedSpec()
suite.Assert().Equal(affiliate1.TypedSpec().NodeID, spec.NodeID)
suite.Assert().Equal([]netaddr.IP{netaddr.MustParseIP("192.168.3.4")}, spec.Addresses)
suite.Assert().Equal([]netip.Addr{netip.MustParseAddr("192.168.3.4")}, spec.Addresses)
suite.Assert().Equal("foo.com", spec.Hostname)
suite.Assert().Equal(machine.TypeControlPlane, spec.MachineType)
suite.Assert().Equal("Talos (v1.0.0)", spec.OperatingSystem)
@ -83,7 +83,7 @@ func (suite *MemberSuite) TestReconcileDefault() {
spec := r.(*cluster.Member).TypedSpec()
suite.Assert().Equal(affiliate2.TypedSpec().NodeID, spec.NodeID)
suite.Assert().Equal([]netaddr.IP{netaddr.MustParseIP("192.168.3.5")}, spec.Addresses)
suite.Assert().Equal([]netip.Addr{netip.MustParseAddr("192.168.3.5")}, spec.Addresses)
suite.Assert().Equal("worker-1", spec.Hostname)
suite.Assert().Equal(machine.TypeWorker, spec.MachineType)

View File

@ -7,13 +7,13 @@ package config
import (
"context"
"fmt"
"net/netip"
"github.com/cosi-project/runtime/pkg/controller"
"github.com/cosi-project/runtime/pkg/resource"
"github.com/cosi-project/runtime/pkg/state"
"github.com/siderolabs/go-pointer"
"go.uber.org/zap"
"inet.af/netaddr"
"github.com/talos-systems/talos/pkg/machinery/resources/config"
"github.com/talos-systems/talos/pkg/machinery/resources/k8s"
@ -71,12 +71,12 @@ func (ctrl *K8sAddressFilterController) Run(ctx context.Context, r controller.Ru
if cfg != nil {
cfgProvider := cfg.(*config.MachineConfig).Config()
var podCIDRs, serviceCIDRs []netaddr.IPPrefix
var podCIDRs, serviceCIDRs []netip.Prefix
for _, cidr := range cfgProvider.Cluster().Network().PodCIDRs() {
var ipPrefix netaddr.IPPrefix
var ipPrefix netip.Prefix
ipPrefix, err = netaddr.ParseIPPrefix(cidr)
ipPrefix, err = netip.ParsePrefix(cidr)
if err != nil {
return fmt.Errorf("error parsing podCIDR: %w", err)
}
@ -85,9 +85,9 @@ func (ctrl *K8sAddressFilterController) Run(ctx context.Context, r controller.Ru
}
for _, cidr := range cfgProvider.Cluster().Network().ServiceCIDRs() {
var ipPrefix netaddr.IPPrefix
var ipPrefix netip.Prefix
ipPrefix, err = netaddr.ParseIPPrefix(cidr)
ipPrefix, err = netip.ParsePrefix(cidr)
if err != nil {
return fmt.Errorf("error parsing serviceCIDR: %w", err)
}
@ -98,7 +98,7 @@ func (ctrl *K8sAddressFilterController) Run(ctx context.Context, r controller.Ru
if err = r.Modify(ctx, network.NewNodeAddressFilter(network.NamespaceName, k8s.NodeAddressFilterNoK8s), func(r resource.Resource) error {
spec := r.(*network.NodeAddressFilter).TypedSpec()
spec.ExcludeSubnets = append(append([]netaddr.IPPrefix(nil), podCIDRs...), serviceCIDRs...)
spec.ExcludeSubnets = append(append([]netip.Prefix(nil), podCIDRs...), serviceCIDRs...)
return nil
}); err != nil {
@ -110,7 +110,7 @@ func (ctrl *K8sAddressFilterController) Run(ctx context.Context, r controller.Ru
if err = r.Modify(ctx, network.NewNodeAddressFilter(network.NamespaceName, k8s.NodeAddressFilterOnlyK8s), func(r resource.Resource) error {
spec := r.(*network.NodeAddressFilter).TypedSpec()
spec.IncludeSubnets = append(append([]netaddr.IPPrefix(nil), podCIDRs...), serviceCIDRs...)
spec.IncludeSubnets = append(append([]netip.Prefix(nil), podCIDRs...), serviceCIDRs...)
return nil
}); err != nil {

View File

@ -7,6 +7,7 @@ package etcd
import (
"context"
"fmt"
"net/netip"
"reflect"
"time"
@ -17,7 +18,6 @@ import (
"github.com/siderolabs/go-pointer"
"go.etcd.io/etcd/api/v3/etcdserverpb"
"go.uber.org/zap"
"inet.af/netaddr"
etcdcli "github.com/talos-systems/talos/internal/pkg/etcd"
"github.com/talos-systems/talos/pkg/machinery/constants"
@ -112,7 +112,7 @@ func (ctrl *AdvertisedPeerController) Run(ctx context.Context, r controller.Runt
}
}
func (ctrl *AdvertisedPeerController) updateAdvertisedPeers(ctx context.Context, logger *zap.Logger, advertisedAddresses []netaddr.IP) error {
func (ctrl *AdvertisedPeerController) updateAdvertisedPeers(ctx context.Context, logger *zap.Logger, advertisedAddresses []netip.Addr) error {
ctx, cancel := context.WithTimeout(ctx, 30*time.Second)
defer cancel()
@ -145,7 +145,7 @@ func (ctrl *AdvertisedPeerController) updateAdvertisedPeers(ctx context.Context,
return fmt.Errorf("local member not found in member list")
}
newPeerURLs := slices.Map(advertisedAddresses, func(addr netaddr.IP) string {
newPeerURLs := slices.Map(advertisedAddresses, func(addr netip.Addr) string {
return fmt.Sprintf("https://%s", nethelpers.JoinHostPort(addr.String(), constants.EtcdPeerPort))
})
currentPeerURLs := localMember.PeerURLs

View File

@ -8,6 +8,7 @@ import (
"context"
"fmt"
stdnet "net"
"net/netip"
"github.com/cosi-project/runtime/pkg/controller"
"github.com/cosi-project/runtime/pkg/resource"
@ -16,7 +17,6 @@ import (
"github.com/siderolabs/go-pointer"
"github.com/talos-systems/net"
"go.uber.org/zap"
"inet.af/netaddr"
"github.com/talos-systems/talos/pkg/machinery/generic/slices"
"github.com/talos-systems/talos/pkg/machinery/nethelpers"
@ -129,53 +129,53 @@ func (ctrl *SpecController) Run(ctx context.Context, r controller.Runtime, logge
listenCIDRs = append(listenCIDRs, etcdConfig.TypedSpec().ListenValidSubnets...)
listenCIDRs = append(listenCIDRs, slices.Map(etcdConfig.TypedSpec().ListenExcludeSubnets, func(cidr string) string { return "!" + cidr })...)
defaultListenAddress := netaddr.IPv4(0, 0, 0, 0)
loopbackAddress := netaddr.IPv4(127, 0, 0, 1)
defaultListenAddress := netip.AddrFrom4([4]byte{0, 0, 0, 0})
loopbackAddress := netip.AddrFrom4([4]byte{127, 0, 0, 1})
for _, ip := range addrs {
if ip.Is6() {
defaultListenAddress = netaddr.IPv6Unspecified()
loopbackAddress = netaddr.MustParseIP("::1")
defaultListenAddress = netip.IPv6Unspecified()
loopbackAddress = netip.MustParseAddr("::1")
break
}
}
var (
advertisedIPs []netaddr.IP
listenPeerIPs []netaddr.IP
listenClientIPs []netaddr.IP
advertisedIPs []netip.Addr
listenPeerIPs []netip.Addr
listenClientIPs []netip.Addr
)
if len(advertisedCIDRs) > 0 {
// TODO: this should eventually be rewritten with `net.FilterIPs` on netaddrs, but for now we'll keep same code and do the conversion.
var stdIPs []stdnet.IP
stdIPs, err = net.FilterIPs(nethelpers.MapNetAddrToStd(addrs), advertisedCIDRs)
stdIPs, err = net.FilterIPs(nethelpers.MapNetIPToStd(addrs), advertisedCIDRs)
if err != nil {
return fmt.Errorf("error filtering IPs: %w", err)
}
advertisedIPs = nethelpers.MapStdToNetAddr(stdIPs)
advertisedIPs = nethelpers.MapStdToNetIP(stdIPs)
} else {
// if advertise subnet is not set, advertise the first address
advertisedIPs = []netaddr.IP{addrs[0]}
advertisedIPs = []netip.Addr{addrs[0]}
}
if len(listenCIDRs) > 0 {
// TODO: this should eventually be rewritten with `net.FilterIPs` on netaddrs, but for now we'll keep same code and do the conversion.
var stdIPs []stdnet.IP
stdIPs, err = net.FilterIPs(nethelpers.MapNetAddrToStd(addrs), listenCIDRs)
stdIPs, err = net.FilterIPs(nethelpers.MapNetIPToStd(addrs), listenCIDRs)
if err != nil {
return fmt.Errorf("error filtering IPs: %w", err)
}
listenPeerIPs = nethelpers.MapStdToNetAddr(stdIPs)
listenClientIPs = append([]netaddr.IP{loopbackAddress}, listenPeerIPs...)
listenPeerIPs = nethelpers.MapStdToNetIP(stdIPs)
listenClientIPs = append([]netip.Addr{loopbackAddress}, listenPeerIPs...)
} else {
listenPeerIPs = []netaddr.IP{defaultListenAddress}
listenClientIPs = []netaddr.IP{defaultListenAddress}
listenPeerIPs = []netip.Addr{defaultListenAddress}
listenClientIPs = []netip.Addr{defaultListenAddress}
}
if len(advertisedIPs) == 0 || len(listenPeerIPs) == 0 {

View File

@ -5,6 +5,7 @@
package etcd_test
import (
"net/netip"
"testing"
"time"
@ -12,7 +13,6 @@ import (
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"github.com/stretchr/testify/suite"
"inet.af/netaddr"
"github.com/talos-systems/talos/internal/app/machined/pkg/controllers/ctest"
etcdctrl "github.com/talos-systems/talos/internal/app/machined/pkg/controllers/etcd"
@ -46,11 +46,11 @@ func (suite *SpecSuite) TestReconcile() {
network.FilteredNodeAddressID(network.NodeAddressRoutedID, k8s.NodeAddressFilterNoK8s),
)
addresses.TypedSpec().Addresses = []netaddr.IPPrefix{
netaddr.MustParseIPPrefix("10.0.0.5/24"),
netaddr.MustParseIPPrefix("192.168.1.1/24"),
netaddr.MustParseIPPrefix("2001:0db8:85a3:0000:0000:8a2e:0370:7334/64"),
netaddr.MustParseIPPrefix("2002:0db8:85a3:0000:0000:8a2e:0370:7335/64"),
addresses.TypedSpec().Addresses = []netip.Prefix{
netip.MustParsePrefix("10.0.0.5/24"),
netip.MustParsePrefix("192.168.1.1/24"),
netip.MustParsePrefix("2001:0db8:85a3:0000:0000:8a2e:0370:7334/64"),
netip.MustParsePrefix("2002:0db8:85a3:0000:0000:8a2e:0370:7335/64"),
}
suite.Require().NoError(suite.State().Create(suite.Ctx(), addresses))
@ -74,14 +74,14 @@ func (suite *SpecSuite) TestReconcile() {
ExtraArgs: map[string]string{
"arg": "value",
},
AdvertisedAddresses: []netaddr.IP{
netaddr.MustParseIP("10.0.0.5"),
AdvertisedAddresses: []netip.Addr{
netip.MustParseAddr("10.0.0.5"),
},
ListenPeerAddresses: []netaddr.IP{
netaddr.IPv6Unspecified(),
ListenPeerAddresses: []netip.Addr{
netip.IPv6Unspecified(),
},
ListenClientAddresses: []netaddr.IP{
netaddr.IPv6Unspecified(),
ListenClientAddresses: []netip.Addr{
netip.IPv6Unspecified(),
},
},
},
@ -96,14 +96,14 @@ func (suite *SpecSuite) TestReconcile() {
expected: etcd.SpecSpec{
Name: "worker1",
Image: "foo/bar:v1.0.0",
AdvertisedAddresses: []netaddr.IP{
netaddr.MustParseIP("192.168.1.1"),
AdvertisedAddresses: []netip.Addr{
netip.MustParseAddr("192.168.1.1"),
},
ListenPeerAddresses: []netaddr.IP{
netaddr.IPv6Unspecified(),
ListenPeerAddresses: []netip.Addr{
netip.IPv6Unspecified(),
},
ListenClientAddresses: []netaddr.IP{
netaddr.IPv6Unspecified(),
ListenClientAddresses: []netip.Addr{
netip.IPv6Unspecified(),
},
},
},
@ -122,16 +122,16 @@ func (suite *SpecSuite) TestReconcile() {
expected: etcd.SpecSpec{
Name: "worker1",
Image: "foo/bar:v1.0.0",
AdvertisedAddresses: []netaddr.IP{
netaddr.MustParseIP("192.168.1.1"),
netaddr.MustParseIP("2001:0db8:85a3:0000:0000:8a2e:0370:7334"),
AdvertisedAddresses: []netip.Addr{
netip.MustParseAddr("192.168.1.1"),
netip.MustParseAddr("2001:0db8:85a3:0000:0000:8a2e:0370:7334"),
},
ListenPeerAddresses: []netaddr.IP{
netaddr.MustParseIP("192.168.1.1"),
ListenPeerAddresses: []netip.Addr{
netip.MustParseAddr("192.168.1.1"),
},
ListenClientAddresses: []netaddr.IP{
netaddr.MustParseIP("::1"),
netaddr.MustParseIP("192.168.1.1"),
ListenClientAddresses: []netip.Addr{
netip.MustParseAddr("::1"),
netip.MustParseAddr("192.168.1.1"),
},
},
},

View File

@ -7,6 +7,7 @@ package k8s
import (
"context"
"fmt"
"net/netip"
"reflect"
"sort"
"time"
@ -16,7 +17,6 @@ import (
"github.com/cosi-project/runtime/pkg/state"
"github.com/siderolabs/go-pointer"
"go.uber.org/zap"
"inet.af/netaddr"
corev1 "k8s.io/api/core/v1"
v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/fields"
@ -196,11 +196,11 @@ func (ctrl *EndpointController) watchEndpointsOnControlPlane(ctx context.Context
}
func (ctrl *EndpointController) updateEndpointsResource(ctx context.Context, r controller.Runtime, logger *zap.Logger, endpoints *corev1.Endpoints) error {
addrs := []netaddr.IP{}
var addrs []netip.Addr
for _, endpoint := range endpoints.Subsets {
for _, addr := range endpoint.Addresses {
ip, err := netaddr.ParseIP(addr.IP)
ip, err := netip.ParseAddr(addr.IP)
if err == nil {
addrs = append(addrs, ip)
}

View File

@ -7,6 +7,7 @@ package k8s
import (
"context"
"fmt"
"net/netip"
"strings"
"time"
@ -16,7 +17,6 @@ import (
"github.com/hashicorp/go-multierror"
"github.com/siderolabs/go-pointer"
"go.uber.org/zap"
"inet.af/netaddr"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
kubeletconfig "k8s.io/kubelet/config/v1beta1"
@ -149,7 +149,7 @@ func (ctrl *KubeletSpecController) Run(ctx context.Context, r controller.Runtime
nodeIPSpec := nodeIP.(*k8s.NodeIP).TypedSpec()
nodeIPsString := slices.Map(nodeIPSpec.Addresses, netaddr.IP.String)
nodeIPsString := slices.Map(nodeIPSpec.Addresses, netip.Addr.String)
args["node-ip"] = strings.Join(nodeIPsString, ",")
}

View File

@ -8,6 +8,7 @@ package k8s_test
import (
"context"
"log"
"net/netip"
"sync"
"testing"
"time"
@ -23,7 +24,6 @@ import (
"github.com/stretchr/testify/require"
"github.com/stretchr/testify/suite"
"github.com/talos-systems/go-retry/retry"
"inet.af/netaddr"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
k8sruntime "k8s.io/apimachinery/pkg/runtime"
v1 "k8s.io/component-base/logs/api/v1"
@ -90,7 +90,7 @@ func (suite *KubeletSpecSuite) TestReconcileDefault() {
suite.Require().NoError(suite.state.Create(suite.ctx, cfg))
nodeIP := k8s.NewNodeIP(k8s.NamespaceName, k8s.KubeletID)
nodeIP.TypedSpec().Addresses = []netaddr.IP{netaddr.MustParseIP("172.20.0.2")}
nodeIP.TypedSpec().Addresses = []netip.Addr{netip.MustParseAddr("172.20.0.2")}
suite.Require().NoError(suite.state.Create(suite.ctx, nodeIP))
@ -220,7 +220,7 @@ func (suite *KubeletSpecSuite) TestReconcileWithExtraConfig() {
suite.Require().NoError(suite.state.Create(suite.ctx, nodename))
nodeIP := k8s.NewNodeIP(k8s.NamespaceName, k8s.KubeletID)
nodeIP.TypedSpec().Addresses = []netaddr.IP{netaddr.MustParseIP("172.20.0.3")}
nodeIP.TypedSpec().Addresses = []netip.Addr{netip.MustParseAddr("172.20.0.3")}
suite.Require().NoError(suite.state.Create(suite.ctx, nodeIP))
@ -280,7 +280,7 @@ func (suite *KubeletSpecSuite) TestReconcileWithSkipNodeRegistration() {
suite.Require().NoError(suite.state.Create(suite.ctx, nodename))
nodeIP := k8s.NewNodeIP(k8s.NamespaceName, k8s.KubeletID)
nodeIP.TypedSpec().Addresses = []netaddr.IP{netaddr.MustParseIP("172.20.0.3")}
nodeIP.TypedSpec().Addresses = []netip.Addr{netip.MustParseAddr("172.20.0.3")}
suite.Require().NoError(suite.state.Create(suite.ctx, nodeIP))

View File

@ -7,6 +7,7 @@ package k8s
import (
"context"
"fmt"
"net/netip"
"github.com/cosi-project/runtime/pkg/controller"
"github.com/cosi-project/runtime/pkg/resource"
@ -15,7 +16,6 @@ import (
"github.com/siderolabs/go-pointer"
"github.com/talos-systems/net"
"go.uber.org/zap"
"inet.af/netaddr"
"github.com/talos-systems/talos/pkg/machinery/generic/slices"
"github.com/talos-systems/talos/pkg/machinery/nethelpers"
@ -106,17 +106,17 @@ func (ctrl *NodeIPController) Run(ctx context.Context, r controller.Runtime, log
cidrs = append(cidrs, slices.Map(cfgSpec.ExcludeSubnets, func(cidr string) string { return "!" + cidr })...)
// TODO: this should eventually be rewritten with `net.FilterIPs` on netaddrs, but for now we'll keep same code and do the conversion.
stdIPs, err := net.FilterIPs(nethelpers.MapNetAddrToStd(addrs), cidrs)
stdIPs, err := net.FilterIPs(nethelpers.MapNetIPToStd(addrs), cidrs)
if err != nil {
return fmt.Errorf("error filtering IPs: %w", err)
}
ips := nethelpers.MapStdToNetAddr(stdIPs)
ips := nethelpers.MapStdToNetIP(stdIPs)
// filter down to make sure only one IPv4 and one IPv6 address stays
var hasIPv4, hasIPv6 bool
nodeIPs := make([]netaddr.IP, 0, 2)
nodeIPs := make([]netip.Addr, 0, 2)
for _, ip := range ips {
switch {

View File

@ -9,6 +9,7 @@ import (
"context"
"fmt"
"log"
"net/netip"
"sync"
"testing"
"time"
@ -20,7 +21,6 @@ import (
"github.com/cosi-project/runtime/pkg/state/impl/namespaced"
"github.com/stretchr/testify/suite"
"github.com/talos-systems/go-retry/retry"
"inet.af/netaddr"
k8sctrl "github.com/talos-systems/talos/internal/app/machined/pkg/controllers/k8s"
"github.com/talos-systems/talos/pkg/logging"
@ -78,9 +78,9 @@ func (suite *NodeIPSuite) TestReconcileIPv4() {
network.FilteredNodeAddressID(network.NodeAddressRoutedID, k8s.NodeAddressFilterNoK8s),
)
addresses.TypedSpec().Addresses = []netaddr.IPPrefix{
netaddr.MustParseIPPrefix("10.0.0.2/32"), // excluded explicitly
netaddr.MustParseIPPrefix("10.0.0.5/24"),
addresses.TypedSpec().Addresses = []netip.Prefix{
netip.MustParsePrefix("10.0.0.2/32"), // excluded explicitly
netip.MustParsePrefix("10.0.0.5/24"),
}
suite.Require().NoError(suite.state.Create(suite.ctx, addresses))
@ -122,11 +122,11 @@ func (suite *NodeIPSuite) TestReconcileDefaultSubnets() {
network.FilteredNodeAddressID(network.NodeAddressRoutedID, k8s.NodeAddressFilterNoK8s),
)
addresses.TypedSpec().Addresses = []netaddr.IPPrefix{
netaddr.MustParseIPPrefix("10.0.0.5/24"),
netaddr.MustParseIPPrefix("192.168.1.1/24"),
netaddr.MustParseIPPrefix("2001:0db8:85a3:0000:0000:8a2e:0370:7334/64"),
netaddr.MustParseIPPrefix("2001:0db8:85a3:0000:0000:8a2e:0370:7335/64"),
addresses.TypedSpec().Addresses = []netip.Prefix{
netip.MustParsePrefix("10.0.0.5/24"),
netip.MustParsePrefix("192.168.1.1/24"),
netip.MustParsePrefix("2001:0db8:85a3:0000:0000:8a2e:0370:7334/64"),
netip.MustParsePrefix("2001:0db8:85a3:0000:0000:8a2e:0370:7335/64"),
}
suite.Require().NoError(suite.state.Create(suite.ctx, addresses))

View File

@ -12,6 +12,7 @@ import (
"github.com/cosi-project/runtime/pkg/resource"
"go.uber.org/zap"
"github.com/talos-systems/talos/pkg/machinery/generic"
"github.com/talos-systems/talos/pkg/machinery/resources/cluster"
"github.com/talos-systems/talos/pkg/machinery/resources/kubespan"
)
@ -92,7 +93,7 @@ func (ctrl *EndpointController) Run(ctx context.Context, r controller.Runtime, l
continue
}
if peerStatus.Endpoint.IsZero() {
if generic.IsZero(peerStatus.Endpoint) {
continue
}

View File

@ -4,13 +4,13 @@
package kubespan_test
import (
"net/netip"
"testing"
"time"
"github.com/cosi-project/runtime/pkg/resource"
"github.com/stretchr/testify/suite"
"github.com/talos-systems/go-retry/retry"
"inet.af/netaddr"
kubespanctrl "github.com/talos-systems/talos/internal/app/machined/pkg/controllers/kubespan"
"github.com/talos-systems/talos/pkg/machinery/config/types/v1alpha1/machine"
@ -34,12 +34,12 @@ func (suite *EndpointSuite) TestReconcile() {
Hostname: "foo.com",
Nodename: "bar",
MachineType: machine.TypeControlPlane,
Addresses: []netaddr.IP{netaddr.MustParseIP("192.168.3.4")},
Addresses: []netip.Addr{netip.MustParseAddr("192.168.3.4")},
KubeSpan: cluster.KubeSpanAffiliateSpec{
PublicKey: "PLPNBddmTgHJhtw0vxltq1ZBdPP9RNOEUd5JjJZzBRY=",
Address: netaddr.MustParseIP("fd50:8d60:4238:6302:f857:23ff:fe21:d1e0"),
AdditionalAddresses: []netaddr.IPPrefix{netaddr.MustParseIPPrefix("10.244.3.1/24")},
Endpoints: []netaddr.IPPort{netaddr.MustParseIPPort("10.0.0.2:51820"), netaddr.MustParseIPPort("192.168.3.4:51820")},
Address: netip.MustParseAddr("fd50:8d60:4238:6302:f857:23ff:fe21:d1e0"),
AdditionalAddresses: []netip.Prefix{netip.MustParsePrefix("10.244.3.1/24")},
Endpoints: []netip.AddrPort{netip.MustParseAddrPort("10.0.0.2:51820"), netip.MustParseAddrPort("192.168.3.4:51820")},
},
}
@ -47,10 +47,10 @@ func (suite *EndpointSuite) TestReconcile() {
*affiliate2.TypedSpec() = cluster.AffiliateSpec{
NodeID: "roLng5hmP0Gv9S5Pbfzaa93JSZjsdpXNAn7vzuCfsc8",
MachineType: machine.TypeControlPlane,
Addresses: []netaddr.IP{netaddr.MustParseIP("192.168.3.5")},
Addresses: []netip.Addr{netip.MustParseAddr("192.168.3.5")},
KubeSpan: cluster.KubeSpanAffiliateSpec{
PublicKey: "1CXkdhWBm58c36kTpchR8iGlXHG1ruHa5W8gsFqD8Qs=",
Address: netaddr.MustParseIP("fd50:8d60:4238:6302:f857:23ff:fe21:d1e1"),
Address: netip.MustParseAddr("fd50:8d60:4238:6302:f857:23ff:fe21:d1e1"),
},
}
@ -59,19 +59,19 @@ func (suite *EndpointSuite) TestReconcile() {
peerStatus1 := kubespan.NewPeerStatus(kubespan.NamespaceName, affiliate1.TypedSpec().KubeSpan.PublicKey)
*peerStatus1.TypedSpec() = kubespan.PeerStatusSpec{
Endpoint: netaddr.MustParseIPPort("10.3.4.8:278"),
Endpoint: netip.MustParseAddrPort("10.3.4.8:278"),
State: kubespan.PeerStateUp,
}
peerStatus2 := kubespan.NewPeerStatus(kubespan.NamespaceName, affiliate2.TypedSpec().KubeSpan.PublicKey)
*peerStatus2.TypedSpec() = kubespan.PeerStatusSpec{
Endpoint: netaddr.MustParseIPPort("10.3.4.9:279"),
Endpoint: netip.MustParseAddrPort("10.3.4.9:279"),
State: kubespan.PeerStateUnknown,
}
peerStatus3 := kubespan.NewPeerStatus(kubespan.NamespaceName, "LoXPyyYh3kZwyKyWfCcf9VvgVv588cKhSKXavuUZqDg=")
*peerStatus3.TypedSpec() = kubespan.PeerStatusSpec{
Endpoint: netaddr.MustParseIPPort("10.3.4.10:270"),
Endpoint: netip.MustParseAddrPort("10.3.4.10:270"),
State: kubespan.PeerStateUp,
}

View File

@ -8,6 +8,7 @@ import (
"context"
"errors"
"fmt"
"net/netip"
"os"
"time"
@ -16,12 +17,13 @@ import (
"github.com/cosi-project/runtime/pkg/state"
"github.com/siderolabs/go-pointer"
"go.uber.org/zap"
"go4.org/netipx"
"golang.zx2c4.com/wireguard/wgctrl"
"golang.zx2c4.com/wireguard/wgctrl/wgtypes"
"inet.af/netaddr"
kubespanadapter "github.com/talos-systems/talos/internal/app/machined/pkg/adapters/kubespan"
"github.com/talos-systems/talos/pkg/machinery/constants"
"github.com/talos-systems/talos/pkg/machinery/generic"
"github.com/talos-systems/talos/pkg/machinery/nethelpers"
"github.com/talos-systems/talos/pkg/machinery/resources/config"
"github.com/talos-systems/talos/pkg/machinery/resources/kubespan"
@ -318,7 +320,7 @@ func (ctrl *ManagerController) Run(ctx context.Context, r controller.Runtime, lo
if kubespanadapter.PeerStatusSpec(peerStatus).ShouldChangeEndpoint() {
newEndpoint := kubespanadapter.PeerStatusSpec(peerStatus).PickNewEndpoint(peerSpec.Endpoints)
if !newEndpoint.IsZero() {
if !generic.IsZero(newEndpoint) {
logger.Debug("updating endpoint for the peer", zap.String("peer", pubKey), zap.String("label", peerSpec.Label), zap.Stringer("endpoint", newEndpoint))
endpoint = newEndpoint.String()
@ -329,7 +331,7 @@ func (ctrl *ManagerController) Run(ctx context.Context, r controller.Runtime, lo
}
// re-establish the endpoint if it wasn't applied to the Wireguard config completely
if !peerStatus.LastUsedEndpoint.IsZero() && (peerStatus.Endpoint.IsZero() || peerStatus.Endpoint == peerStatus.LastUsedEndpoint) {
if !generic.IsZero(peerStatus.LastUsedEndpoint) && (generic.IsZero(peerStatus.Endpoint) || peerStatus.Endpoint == peerStatus.LastUsedEndpoint) {
endpoint = peerStatus.LastUsedEndpoint.String()
peerStatus.Endpoint = peerStatus.LastUsedEndpoint
@ -341,12 +343,12 @@ func (ctrl *ManagerController) Run(ctx context.Context, r controller.Runtime, lo
PresharedKey: cfgSpec.SharedSecret,
Endpoint: endpoint,
PersistentKeepaliveInterval: constants.KubeSpanDefaultPeerKeepalive,
AllowedIPs: append([]netaddr.IPPrefix(nil), peerSpec.AllowedIPs...),
AllowedIPs: append([]netip.Prefix(nil), peerSpec.AllowedIPs...),
})
}
// build full allowedIPs set
var allowedIPsBuilder netaddr.IPSetBuilder
var allowedIPsBuilder netipx.IPSetBuilder
for pubKey, peerSpec := range peerSpecs {
// list of statuses and specs should be in sync at this point
@ -398,7 +400,7 @@ func (ctrl *ManagerController) Run(ctx context.Context, r controller.Runtime, lo
func(r resource.Resource) error {
spec := r.(*network.AddressSpec).TypedSpec()
spec.Address = netaddr.IPPrefixFrom(localSpec.Address.IP(), localSpec.Subnet.Bits())
spec.Address = netip.PrefixFrom(localSpec.Address.Addr(), localSpec.Subnet.Bits())
spec.ConfigLayer = network.ConfigOperator
spec.Family = nethelpers.FamilyInet6
spec.Flags = nethelpers.AddressFlags(nethelpers.AddressPermanent)
@ -414,9 +416,9 @@ func (ctrl *ManagerController) Run(ctx context.Context, r controller.Runtime, lo
for _, spec := range []network.RouteSpecSpec{
{
Family: nethelpers.FamilyInet4,
Destination: netaddr.IPPrefix{},
Source: netaddr.IP{},
Gateway: netaddr.IP{},
Destination: netip.Prefix{},
Source: netip.Addr{},
Gateway: netip.Addr{},
OutLinkName: constants.KubeSpanLinkName,
Table: nethelpers.RoutingTable(constants.KubeSpanDefaultRoutingTable),
Priority: 1,
@ -428,9 +430,9 @@ func (ctrl *ManagerController) Run(ctx context.Context, r controller.Runtime, lo
},
{
Family: nethelpers.FamilyInet6,
Destination: netaddr.IPPrefix{},
Source: netaddr.IP{},
Gateway: netaddr.IP{},
Destination: netip.Prefix{},
Source: netip.Addr{},
Gateway: netip.Addr{},
OutLinkName: constants.KubeSpanLinkName,
Table: nethelpers.RoutingTable(constants.KubeSpanDefaultRoutingTable),
Priority: 1,

View File

@ -6,6 +6,7 @@ package kubespan_test
import (
"fmt"
"net"
"net/netip"
"os"
"sync"
"testing"
@ -14,8 +15,8 @@ import (
"github.com/cosi-project/runtime/pkg/resource"
"github.com/stretchr/testify/suite"
"github.com/talos-systems/go-retry/retry"
"go4.org/netipx"
"golang.zx2c4.com/wireguard/wgctrl/wgtypes"
"inet.af/netaddr"
kubespanadapter "github.com/talos-systems/talos/internal/app/machined/pkg/adapters/kubespan"
kubespanctrl "github.com/talos-systems/talos/internal/app/machined/pkg/controllers/kubespan"
@ -88,10 +89,10 @@ func (mock mockRulesManager) Cleanup() error {
type mockNftablesManager struct {
mu sync.Mutex
ipSet *netaddr.IPSet
ipSet *netipx.IPSet
}
func (mock *mockNftablesManager) Update(ipSet *netaddr.IPSet) error {
func (mock *mockNftablesManager) Update(ipSet *netipx.IPSet) error {
mock.mu.Lock()
defer mock.mu.Unlock()
@ -104,7 +105,7 @@ func (mock *mockNftablesManager) Cleanup() error {
return nil
}
func (mock *mockNftablesManager) IPSet() *netaddr.IPSet {
func (mock *mockNftablesManager) IPSet() *netipx.IPSet {
mock.mu.Lock()
defer mock.mu.Unlock()
@ -200,7 +201,7 @@ func (suite *ManagerSuite) TestReconcile() {
func(res resource.Resource) error {
spec := res.(*network.AddressSpec).TypedSpec()
suite.Assert().Equal(localIdentity.TypedSpec().Address.IP(), spec.Address.IP())
suite.Assert().Equal(localIdentity.TypedSpec().Address.Addr(), spec.Address.Addr())
suite.Assert().Equal(localIdentity.TypedSpec().Subnet.Bits(), spec.Address.Bits())
suite.Assert().Equal(network.ConfigOperator, spec.ConfigLayer)
suite.Assert().Equal(nethelpers.FamilyInet6, spec.Family)
@ -229,8 +230,8 @@ func (suite *ManagerSuite) TestReconcile() {
network.RouteID(
constants.KubeSpanDefaultRoutingTable,
nethelpers.FamilyInet4,
netaddr.IPPrefix{},
netaddr.IP{},
netip.Prefix{},
netip.Addr{},
1,
),
),
@ -239,8 +240,8 @@ func (suite *ManagerSuite) TestReconcile() {
network.RouteID(
constants.KubeSpanDefaultRoutingTable,
nethelpers.FamilyInet6,
netaddr.IPPrefix{},
netaddr.IP{},
netip.Prefix{},
netip.Addr{},
1,
),
),
@ -259,13 +260,13 @@ func (suite *ManagerSuite) TestReconcile() {
// add two peers, they should be added to the wireguard link spec and should be tracked in peer statuses
peer1 := kubespan.NewPeerSpec(kubespan.NamespaceName, "3FxU7UuwektMjbyuJBs7i1hDj2rQA6tHnbNB6WrQxww=")
peer1.TypedSpec().Address = netaddr.MustParseIP("fd8a:4396:731e:e702:145e:c4ff:fe41:1ef9")
peer1.TypedSpec().Address = netip.MustParseAddr("fd8a:4396:731e:e702:145e:c4ff:fe41:1ef9")
peer1.TypedSpec().Label = "worker-1"
peer1.TypedSpec().AllowedIPs = []netaddr.IPPrefix{
netaddr.MustParseIPPrefix("10.244.1.0/24"),
peer1.TypedSpec().AllowedIPs = []netip.Prefix{
netip.MustParsePrefix("10.244.1.0/24"),
}
peer1.TypedSpec().Endpoints = []netaddr.IPPort{
netaddr.MustParseIPPort("172.20.0.3:51280"),
peer1.TypedSpec().Endpoints = []netip.AddrPort{
netip.MustParseAddrPort("172.20.0.3:51280"),
}
suite.Require().NoError(suite.state.Create(suite.ctx, peer1))
@ -273,13 +274,13 @@ func (suite *ManagerSuite) TestReconcile() {
suite.Require().NoError(err)
peer2 := kubespan.NewPeerSpec(kubespan.NamespaceName, "tQuicRD0tqCu48M+zrySTe4slT15JxWhWIboZOB4tWs=")
peer2.TypedSpec().Address = netaddr.MustParseIP("fd8a:4396:731e:e702:9c83:cbff:fed0:f94b")
peer2.TypedSpec().Address = netip.MustParseAddr("fd8a:4396:731e:e702:9c83:cbff:fed0:f94b")
peer2.TypedSpec().Label = "worker-2"
peer2.TypedSpec().AllowedIPs = []netaddr.IPPrefix{
netaddr.MustParseIPPrefix("10.244.2.0/24"),
peer2.TypedSpec().AllowedIPs = []netip.Prefix{
netip.MustParsePrefix("10.244.2.0/24"),
}
peer2.TypedSpec().Endpoints = []netaddr.IPPort{
netaddr.MustParseIPPort("172.20.0.4:51280"),
peer2.TypedSpec().Endpoints = []netip.AddrPort{
netip.MustParseAddrPort("172.20.0.4:51280"),
}
suite.Require().NoError(suite.state.Create(suite.ctx, peer2))
@ -394,12 +395,12 @@ func (suite *ManagerSuite) TestReconcile() {
Peers: []wgtypes.Peer{
{
PublicKey: key1,
Endpoint: peer1.TypedSpec().Endpoints[0].UDPAddr(),
Endpoint: asUDP(peer1.TypedSpec().Endpoints[0]),
LastHandshakeTime: time.Now(),
},
{
PublicKey: key2,
Endpoint: peer2.TypedSpec().Endpoints[0].UDPAddr(),
Endpoint: asUDP(peer2.TypedSpec().Endpoints[0]),
LastHandshakeTime: time.Now(),
},
},
@ -474,6 +475,14 @@ func (suite *ManagerSuite) TestReconcile() {
)
}
func asUDP(addr netip.AddrPort) *net.UDPAddr {
return &net.UDPAddr{
IP: addr.Addr().AsSlice(),
Port: int(addr.Port()),
Zone: addr.Addr().Zone(),
}
}
func TestManagerSuite(t *testing.T) {
suite.Run(t, new(ManagerSuite))
}

View File

@ -10,12 +10,12 @@ import (
"github.com/google/nftables"
"github.com/google/nftables/binaryutil"
"github.com/google/nftables/expr"
"inet.af/netaddr"
"go4.org/netipx"
)
// NfTablesManager manages nftables outside of controllers/resources scope.
type NfTablesManager interface {
Update(*netaddr.IPSet) error
Update(*netipx.IPSet) error
Cleanup() error
}
@ -53,7 +53,7 @@ type nfTablesManager struct {
ExternalMark uint32
MarkMask uint32
currentSet *netaddr.IPSet
currentSet *netipx.IPSet
// nfTable is a handle for the KubeSpan root table
nfTable *nftables.Table
@ -66,7 +66,7 @@ type nfTablesManager struct {
}
// Update the nftables rules based on the IPSet.
func (m *nfTablesManager) Update(desired *netaddr.IPSet) error {
func (m *nfTablesManager) Update(desired *netipx.IPSet) error {
if m.currentSet != nil && m.currentSet.Equal(desired) {
return nil
}
@ -129,7 +129,7 @@ func (m *nfTablesManager) tableExists() (bool, error) {
return foundExisting, nil
}
func (m *nfTablesManager) setNFTable(ips *netaddr.IPSet) error {
func (m *nfTablesManager) setNFTable(ips *netipx.IPSet) error {
c := &nftables.Conn{}
// NB: sets should be flushed before new members because nftables will fail
@ -324,7 +324,7 @@ func matchIPSet(set *nftables.Set, mark, mask uint32, family nftables.TableFamil
}
}
func (m *nfTablesManager) setElements(ips *netaddr.IPSet) (setElements4, setElements6 []nftables.SetElement) {
func (m *nfTablesManager) setElements(ips *netipx.IPSet) (setElements4, setElements6 []nftables.SetElement) {
if ips == nil {
return nil, nil
}

View File

@ -4,11 +4,12 @@
package kubespan_test
import (
"net/netip"
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"inet.af/netaddr"
"go4.org/netipx"
"github.com/talos-systems/talos/internal/app/machined/pkg/controllers/kubespan"
"github.com/talos-systems/talos/pkg/machinery/constants"
@ -23,17 +24,17 @@ func TestNfTables(t *testing.T) {
defer mgr.Cleanup() //nolint:errcheck
var builder netaddr.IPSetBuilder
var builder netipx.IPSetBuilder
builder.AddPrefix(netaddr.MustParseIPPrefix("172.20.0.0/24"))
builder.AddPrefix(netaddr.MustParseIPPrefix("10.0.0.0/16"))
builder.AddPrefix(netip.MustParsePrefix("172.20.0.0/24"))
builder.AddPrefix(netip.MustParsePrefix("10.0.0.0/16"))
ipSet, err := builder.IPSet()
require.NoError(t, err)
assert.NoError(t, mgr.Update(ipSet))
builder.AddPrefix(netaddr.MustParseIPPrefix("10.0.0.0/8"))
builder.AddPrefix(netip.MustParsePrefix("10.0.0.0/8"))
ipSet, err = builder.IPSet()
require.NoError(t, err)

View File

@ -7,13 +7,14 @@ package kubespan
import (
"context"
"fmt"
"net/netip"
"github.com/cosi-project/runtime/pkg/controller"
"github.com/cosi-project/runtime/pkg/resource"
"github.com/cosi-project/runtime/pkg/state"
"github.com/siderolabs/go-pointer"
"go.uber.org/zap"
"inet.af/netaddr"
"go4.org/netipx"
"github.com/talos-systems/talos/pkg/machinery/generic/slices"
"github.com/talos-systems/talos/pkg/machinery/resources/cluster"
@ -91,7 +92,7 @@ func (ctrl *PeerSpecController) Run(ctx context.Context, r controller.Runtime, l
if cfg != nil && localIdentity != nil && cfg.(*kubespan.Config).TypedSpec().Enabled {
localAffiliateID := localIdentity.(*cluster.Identity).TypedSpec().NodeID
peerIPSets := make(map[string]*netaddr.IPSet, len(affiliates.Items))
peerIPSets := make(map[string]*netipx.IPSet, len(affiliates.Items))
affiliateLoop:
for _, affiliate := range affiliates.Items {
@ -107,7 +108,7 @@ func (ctrl *PeerSpecController) Run(ctx context.Context, r controller.Runtime, l
continue
}
var builder netaddr.IPSetBuilder
var builder netipx.IPSetBuilder
for _, ipPrefix := range spec.KubeSpan.AdditionalAddresses {
builder.AddPrefix(ipPrefix)
@ -119,7 +120,7 @@ func (ctrl *PeerSpecController) Run(ctx context.Context, r controller.Runtime, l
builder.Add(spec.KubeSpan.Address)
var ipSet *netaddr.IPSet
var ipSet *netipx.IPSet
ipSet, err = builder.IPSet()
if err != nil {
@ -134,7 +135,7 @@ func (ctrl *PeerSpecController) Run(ctx context.Context, r controller.Runtime, l
zap.Strings("this_ips", dumpSet(ipSet)), zap.Strings("other_ips", dumpSet(otherIPSet)))
// exclude overlapping IPs from the ipSet
var bldr netaddr.IPSetBuilder
var bldr netipx.IPSetBuilder
// ipSet = ipSet & ~otherIPSet
bldr.AddSet(otherIPSet)
@ -160,7 +161,7 @@ func (ctrl *PeerSpecController) Run(ctx context.Context, r controller.Runtime, l
*res.(*kubespan.PeerSpec).TypedSpec() = kubespan.PeerSpecSpec{
Address: spec.KubeSpan.Address,
AllowedIPs: ipSet.Prefixes(),
Endpoints: append([]netaddr.IPPort(nil), spec.KubeSpan.Endpoints...),
Endpoints: append([]netip.AddrPort(nil), spec.KubeSpan.Endpoints...),
Label: spec.Nodename,
}
@ -195,6 +196,6 @@ func (ctrl *PeerSpecController) Run(ctx context.Context, r controller.Runtime, l
}
// dumpSet converts IPSet to a form suitable for logging.
func dumpSet(set *netaddr.IPSet) []string {
return slices.Map(set.Ranges(), netaddr.IPRange.String)
func dumpSet(set *netipx.IPSet) []string {
return slices.Map(set.Ranges(), netipx.IPRange.String)
}

View File

@ -5,13 +5,13 @@ package kubespan_test
import (
"fmt"
"net/netip"
"testing"
"time"
"github.com/cosi-project/runtime/pkg/resource"
"github.com/stretchr/testify/suite"
"github.com/talos-systems/go-retry/retry"
"inet.af/netaddr"
clusteradapter "github.com/talos-systems/talos/internal/app/machined/pkg/adapters/cluster"
kubespanctrl "github.com/talos-systems/talos/internal/app/machined/pkg/controllers/kubespan"
@ -56,12 +56,12 @@ func (suite *PeerSpecSuite) TestReconcile() {
Hostname: "foo.com",
Nodename: "bar",
MachineType: machine.TypeControlPlane,
Addresses: []netaddr.IP{netaddr.MustParseIP("192.168.3.4")},
Addresses: []netip.Addr{netip.MustParseAddr("192.168.3.4")},
KubeSpan: cluster.KubeSpanAffiliateSpec{
PublicKey: "PLPNBddmTgHJhtw0vxltq1ZBdPP9RNOEUd5JjJZzBRY=",
Address: netaddr.MustParseIP("fd50:8d60:4238:6302:f857:23ff:fe21:d1e0"),
AdditionalAddresses: []netaddr.IPPrefix{netaddr.MustParseIPPrefix("10.244.3.1/24"), netaddr.MustParseIPPrefix("10.244.3.0/32")},
Endpoints: []netaddr.IPPort{netaddr.MustParseIPPort("10.0.0.2:51820"), netaddr.MustParseIPPort("192.168.3.4:51820")},
Address: netip.MustParseAddr("fd50:8d60:4238:6302:f857:23ff:fe21:d1e0"),
AdditionalAddresses: []netip.Prefix{netip.MustParsePrefix("10.244.3.1/24"), netip.MustParsePrefix("10.244.3.0/32")},
Endpoints: []netip.AddrPort{netip.MustParseAddrPort("10.0.0.2:51820"), netip.MustParseAddrPort("192.168.3.4:51820")},
},
}
@ -71,7 +71,7 @@ func (suite *PeerSpecSuite) TestReconcile() {
Hostname: "worker-1",
Nodename: "worker-1",
MachineType: machine.TypeWorker,
Addresses: []netaddr.IP{netaddr.MustParseIP("192.168.3.5")},
Addresses: []netip.Addr{netip.MustParseAddr("192.168.3.5")},
}
affiliate3 := cluster.NewAffiliate(cluster.NamespaceName, "xCnFFfxylOf9i5ynhAkt6ZbfcqaLDGKfIa3gwpuaxe7F")
@ -79,12 +79,12 @@ func (suite *PeerSpecSuite) TestReconcile() {
NodeID: "xCnFFfxylOf9i5ynhAkt6ZbfcqaLDGKfIa3gwpuaxe7F",
MachineType: machine.TypeWorker,
Nodename: "worker-2",
Addresses: []netaddr.IP{netaddr.MustParseIP("192.168.3.6")},
Addresses: []netip.Addr{netip.MustParseAddr("192.168.3.6")},
KubeSpan: cluster.KubeSpanAffiliateSpec{
PublicKey: "mB6WlFOR66Jx5rtPMIpxJ3s4XHyer9NCzqWPP7idGRo",
Address: netaddr.MustParseIP("fdc8:8aee:4e2d:1202:f073:9cff:fe6c:4d67"),
AdditionalAddresses: []netaddr.IPPrefix{netaddr.MustParseIPPrefix("10.244.4.1/24")},
Endpoints: []netaddr.IPPort{netaddr.MustParseIPPort("192.168.3.6:51820")},
Address: netip.MustParseAddr("fdc8:8aee:4e2d:1202:f073:9cff:fe6c:4d67"),
AdditionalAddresses: []netip.Prefix{netip.MustParsePrefix("10.244.4.1/24")},
Endpoints: []netip.AddrPort{netip.MustParseAddrPort("192.168.3.6:51820")},
},
}
@ -93,12 +93,12 @@ func (suite *PeerSpecSuite) TestReconcile() {
*affiliate4.TypedSpec() = cluster.AffiliateSpec{
NodeID: nodeIdentity.TypedSpec().NodeID,
MachineType: machine.TypeWorker,
Addresses: []netaddr.IP{netaddr.MustParseIP("192.168.3.7")},
Addresses: []netip.Addr{netip.MustParseAddr("192.168.3.7")},
KubeSpan: cluster.KubeSpanAffiliateSpec{
PublicKey: "27E8I+ekrqT21cq2iW6+fDe+H7WBw6q9J7vqLCeswiM=",
Address: netaddr.MustParseIP("fdc8:8aee:4e2d:1202:f073:9cff:fe6c:4d67"),
AdditionalAddresses: []netaddr.IPPrefix{netaddr.MustParseIPPrefix("10.244.5.1/24")},
Endpoints: []netaddr.IPPort{netaddr.MustParseIPPort("192.168.3.7:51820")},
Address: netip.MustParseAddr("fdc8:8aee:4e2d:1202:f073:9cff:fe6c:4d67"),
AdditionalAddresses: []netip.Prefix{netip.MustParsePrefix("10.244.5.1/24")},
Endpoints: []netip.AddrPort{netip.MustParseAddrPort("192.168.3.7:51820")},
},
}
@ -124,7 +124,7 @@ func (suite *PeerSpecSuite) TestReconcile() {
suite.Assert().Equal("fd50:8d60:4238:6302:f857:23ff:fe21:d1e0", spec.Address.String())
suite.Assert().Equal("[10.244.3.0/24 192.168.3.4/32 fd50:8d60:4238:6302:f857:23ff:fe21:d1e0/128]", fmt.Sprintf("%v", spec.AllowedIPs))
suite.Assert().Equal([]netaddr.IPPort{netaddr.MustParseIPPort("10.0.0.2:51820"), netaddr.MustParseIPPort("192.168.3.4:51820")}, spec.Endpoints)
suite.Assert().Equal([]netip.AddrPort{netip.MustParseAddrPort("10.0.0.2:51820"), netip.MustParseAddrPort("192.168.3.4:51820")}, spec.Endpoints)
suite.Assert().Equal("bar", spec.Label)
return nil
@ -140,7 +140,7 @@ func (suite *PeerSpecSuite) TestReconcile() {
suite.Assert().Equal("fdc8:8aee:4e2d:1202:f073:9cff:fe6c:4d67", spec.Address.String())
suite.Assert().Equal("[10.244.4.0/24 192.168.3.6/32 fdc8:8aee:4e2d:1202:f073:9cff:fe6c:4d67/128]", fmt.Sprintf("%v", spec.AllowedIPs))
suite.Assert().Equal([]netaddr.IPPort{netaddr.MustParseIPPort("192.168.3.6:51820")}, spec.Endpoints)
suite.Assert().Equal([]netip.AddrPort{netip.MustParseAddrPort("192.168.3.6:51820")}, spec.Endpoints)
suite.Assert().Equal("worker-2", spec.Label)
return nil
@ -194,9 +194,9 @@ func (suite *PeerSpecSuite) TestIPOverlap() {
MachineType: machine.TypeControlPlane,
KubeSpan: cluster.KubeSpanAffiliateSpec{
PublicKey: "PLPNBddmTgHJhtw0vxltq1ZBdPP9RNOEUd5JjJZzBRY=",
Address: netaddr.MustParseIP("fd50:8d60:4238:6302:f857:23ff:fe21:d1e0"),
AdditionalAddresses: []netaddr.IPPrefix{netaddr.MustParseIPPrefix("10.244.3.1/24"), netaddr.MustParseIPPrefix("10.244.3.0/32")},
Endpoints: []netaddr.IPPort{netaddr.MustParseIPPort("10.0.0.2:51820"), netaddr.MustParseIPPort("192.168.3.4:51820")},
Address: netip.MustParseAddr("fd50:8d60:4238:6302:f857:23ff:fe21:d1e0"),
AdditionalAddresses: []netip.Prefix{netip.MustParsePrefix("10.244.3.1/24"), netip.MustParsePrefix("10.244.3.0/32")},
Endpoints: []netip.AddrPort{netip.MustParseAddrPort("10.0.0.2:51820"), netip.MustParseAddrPort("192.168.3.4:51820")},
},
}
@ -208,9 +208,9 @@ func (suite *PeerSpecSuite) TestIPOverlap() {
MachineType: machine.TypeWorker,
KubeSpan: cluster.KubeSpanAffiliateSpec{
PublicKey: "Zr5ewpUm2Ywo1c+/59WFKIBjZ3c/nVbIWsT5elbjwCU=",
Address: netaddr.MustParseIP("fd50:8d60:4238:6302:f857:23ff:fe21:d1e1"),
AdditionalAddresses: []netaddr.IPPrefix{netaddr.MustParseIPPrefix("10.244.2.0/23"), netaddr.MustParseIPPrefix("192.168.3.0/24")},
Endpoints: []netaddr.IPPort{netaddr.MustParseIPPort("10.0.0.2:51820"), netaddr.MustParseIPPort("192.168.3.4:51820")},
Address: netip.MustParseAddr("fd50:8d60:4238:6302:f857:23ff:fe21:d1e1"),
AdditionalAddresses: []netip.Prefix{netip.MustParsePrefix("10.244.2.0/23"), netip.MustParsePrefix("192.168.3.0/24")},
Endpoints: []netip.AddrPort{netip.MustParseAddrPort("10.0.0.2:51820"), netip.MustParseAddrPort("192.168.3.4:51820")},
},
}

View File

@ -7,6 +7,7 @@ package network
import (
"context"
"fmt"
"net/netip"
"strings"
"github.com/cosi-project/runtime/pkg/controller"
@ -14,10 +15,10 @@ import (
"github.com/cosi-project/runtime/pkg/state"
"github.com/talos-systems/go-procfs/procfs"
"go.uber.org/zap"
"inet.af/netaddr"
"github.com/talos-systems/talos/internal/app/machined/pkg/runtime"
"github.com/talos-systems/talos/pkg/machinery/config"
"github.com/talos-systems/talos/pkg/machinery/generic"
"github.com/talos-systems/talos/pkg/machinery/nethelpers"
"github.com/talos-systems/talos/pkg/machinery/resources/network"
)
@ -100,7 +101,7 @@ func (ctrl *AddressConfigController) Run(ctx context.Context, r controller.Runti
// parse kernel cmdline for the address
cmdlineAddress := ctrl.parseCmdline(logger)
if !cmdlineAddress.Address.IsZero() {
if !generic.IsZero(cmdlineAddress.Address) {
if _, ignored := ignoredInterfaces[cmdlineAddress.LinkName]; !ignored {
var ids []string
@ -186,7 +187,7 @@ func (ctrl *AddressConfigController) loopbackDefaults() []network.AddressSpecSpe
return []network.AddressSpecSpec{
{
Address: netaddr.IPPrefixFrom(netaddr.IPv4(127, 0, 0, 1), 8),
Address: netip.PrefixFrom(netip.AddrFrom4([4]byte{127, 0, 0, 1}), 8),
Family: nethelpers.FamilyInet4,
Scope: nethelpers.ScopeHost,
Flags: nethelpers.AddressFlags(nethelpers.AddressPermanent),
@ -208,12 +209,12 @@ func (ctrl *AddressConfigController) parseCmdline(logger *zap.Logger) (address n
return
}
if settings.Address.IsZero() {
if generic.IsZero(settings.Address) {
return
}
address.Address = settings.Address
if address.Address.IP().Is6() {
if address.Address.Addr().Is6() {
address.Family = nethelpers.FamilyInet6
} else {
address.Family = nethelpers.FamilyInet4
@ -227,18 +228,18 @@ func (ctrl *AddressConfigController) parseCmdline(logger *zap.Logger) (address n
return address
}
func parseIPOrIPPrefix(address string) (netaddr.IPPrefix, error) {
func parseIPOrIPPrefix(address string) (netip.Prefix, error) {
if strings.IndexByte(address, '/') >= 0 {
return netaddr.ParseIPPrefix(address)
return netip.ParsePrefix(address)
}
// parse as IP address and assume netmask of all ones
ip, err := netaddr.ParseIP(address)
ip, err := netip.ParseAddr(address)
if err != nil {
return netaddr.IPPrefix{}, err
return netip.Prefix{}, err
}
return netaddr.IPPrefixFrom(ip, ip.BitLen()), nil
return netip.PrefixFrom(ip, ip.BitLen()), nil
}
func (ctrl *AddressConfigController) processDevicesConfiguration(logger *zap.Logger, devices []config.Device) (addresses []network.AddressSpecSpec) {
@ -263,7 +264,7 @@ func (ctrl *AddressConfigController) processDevicesConfiguration(logger *zap.Log
Flags: nethelpers.AddressFlags(nethelpers.AddressPermanent),
}
if address.Address.IP().Is6() {
if address.Address.Addr().Is6() {
address.Family = nethelpers.FamilyInet6
} else {
address.Family = nethelpers.FamilyInet4
@ -274,7 +275,7 @@ func (ctrl *AddressConfigController) processDevicesConfiguration(logger *zap.Log
for _, vlan := range device.Vlans() {
for _, cidr := range vlan.Addresses() {
ipPrefix, err := netaddr.ParseIPPrefix(cidr)
ipPrefix, err := netip.ParsePrefix(cidr)
if err != nil {
logger.Info(fmt.Sprintf("skipping address %q on interface %q vlan %d", cidr, device.Interface(), vlan.ID()), zap.Error(err))
@ -289,7 +290,7 @@ func (ctrl *AddressConfigController) processDevicesConfiguration(logger *zap.Log
Flags: nethelpers.AddressFlags(nethelpers.AddressPermanent),
}
if address.Address.IP().Is6() {
if address.Address.Addr().Is6() {
address.Family = nethelpers.FamilyInet6
} else {
address.Family = nethelpers.FamilyInet4

View File

@ -90,7 +90,7 @@ func (ctrl *AddressEventController) Run(ctx context.Context, r controller.Runtim
for _, addr := range nodeAddr.(*network.NodeAddress).TypedSpec().Addresses {
addresses = append(
addresses,
addr.IP().String(),
addr.Addr().String(),
)
}
}

View File

@ -8,6 +8,7 @@ import (
"context"
"fmt"
"log"
"net/netip"
"sync"
"testing"
"time"
@ -18,7 +19,6 @@ import (
"github.com/cosi-project/runtime/pkg/state/impl/namespaced"
"github.com/stretchr/testify/suite"
"github.com/talos-systems/go-retry/retry"
"inet.af/netaddr"
"github.com/talos-systems/talos/internal/app/machined/pkg/controllers/network"
"github.com/talos-systems/talos/pkg/logging"
@ -141,8 +141,8 @@ func (suite *AddressEventsSuite) TestReconcile() {
nodeAddress.TypedSpec().Addresses = append(
nodeAddress.TypedSpec().Addresses,
netaddr.IPPrefixFrom(netaddr.MustParseIP(addrs[0]), 32),
netaddr.IPPrefixFrom(netaddr.MustParseIP(addrs[1]), 32),
netip.PrefixFrom(netip.MustParseAddr(addrs[0]), 32),
netip.PrefixFrom(netip.MustParseAddr(addrs[1]), 32),
)
suite.Require().NoError(suite.state.Create(suite.ctx, nodeAddress))

View File

@ -9,6 +9,7 @@ import (
"context"
"fmt"
"log"
"net/netip"
"sync"
"testing"
"time"
@ -21,7 +22,6 @@ import (
"github.com/stretchr/testify/suite"
"github.com/talos-systems/go-retry/retry"
"golang.org/x/sync/errgroup"
"inet.af/netaddr"
netctrl "github.com/talos-systems/talos/internal/app/machined/pkg/controllers/network"
"github.com/talos-systems/talos/pkg/logging"
@ -122,7 +122,7 @@ func (suite *AddressMergeSuite) assertNoAddress(id string) error {
func (suite *AddressMergeSuite) TestMerge() {
loopback := network.NewAddressSpec(network.ConfigNamespaceName, "default/lo/127.0.0.1/8")
*loopback.TypedSpec() = network.AddressSpecSpec{
Address: netaddr.MustParseIPPrefix("127.0.0.1/8"),
Address: netip.MustParsePrefix("127.0.0.1/8"),
LinkName: "lo",
Family: nethelpers.FamilyInet4,
Scope: nethelpers.ScopeHost,
@ -131,7 +131,7 @@ func (suite *AddressMergeSuite) TestMerge() {
dhcp := network.NewAddressSpec(network.ConfigNamespaceName, "dhcp/eth0/10.0.0.1/8")
*dhcp.TypedSpec() = network.AddressSpecSpec{
Address: netaddr.MustParseIPPrefix("10.0.0.1/8"),
Address: netip.MustParsePrefix("10.0.0.1/8"),
LinkName: "eth0",
Family: nethelpers.FamilyInet4,
Scope: nethelpers.ScopeGlobal,
@ -140,7 +140,7 @@ func (suite *AddressMergeSuite) TestMerge() {
static := network.NewAddressSpec(network.ConfigNamespaceName, "configuration/eth0/10.0.0.35/32")
*static.TypedSpec() = network.AddressSpecSpec{
Address: netaddr.MustParseIPPrefix("10.0.0.35/32"),
Address: netip.MustParsePrefix("10.0.0.35/32"),
LinkName: "eth0",
Family: nethelpers.FamilyInet4,
Scope: nethelpers.ScopeGlobal,
@ -149,7 +149,7 @@ func (suite *AddressMergeSuite) TestMerge() {
override := network.NewAddressSpec(network.ConfigNamespaceName, "configuration/eth0/10.0.0.1/8")
*override.TypedSpec() = network.AddressSpecSpec{
Address: netaddr.MustParseIPPrefix("10.0.0.1/8"),
Address: netip.MustParsePrefix("10.0.0.1/8"),
LinkName: "eth0",
Family: nethelpers.FamilyInet4,
Scope: nethelpers.ScopeHost,
@ -215,7 +215,7 @@ func (suite *AddressMergeSuite) TestMergeFlapping() {
// simulate two conflicting address definitions which are getting removed/added constantly
dhcp := network.NewAddressSpec(network.ConfigNamespaceName, "dhcp/eth0/10.0.0.1/8")
*dhcp.TypedSpec() = network.AddressSpecSpec{
Address: netaddr.MustParseIPPrefix("10.0.0.1/8"),
Address: netip.MustParsePrefix("10.0.0.1/8"),
LinkName: "eth0",
Family: nethelpers.FamilyInet4,
Scope: nethelpers.ScopeGlobal,
@ -224,7 +224,7 @@ func (suite *AddressMergeSuite) TestMergeFlapping() {
override := network.NewAddressSpec(network.ConfigNamespaceName, "configuration/eth0/10.0.0.1/8")
*override.TypedSpec() = network.AddressSpecSpec{
Address: netaddr.MustParseIPPrefix("10.0.0.1/8"),
Address: netip.MustParsePrefix("10.0.0.1/8"),
LinkName: "eth0",
Family: nethelpers.FamilyInet4,
Scope: nethelpers.ScopeHost,

View File

@ -17,8 +17,8 @@ import (
"github.com/jsimonetti/rtnetlink"
"github.com/mdlayher/arp"
"go.uber.org/zap"
"go4.org/netipx"
"golang.org/x/sys/unix"
"inet.af/netaddr"
"github.com/talos-systems/talos/internal/app/machined/pkg/controllers/network/watch"
"github.com/talos-systems/talos/pkg/machinery/nethelpers"
@ -125,17 +125,17 @@ func resolveLinkName(links []rtnetlink.LinkMessage, linkName string) uint32 {
return 0
}
func findAddress(addrs []rtnetlink.AddressMessage, linkIndex uint32, ipPrefix netaddr.IPPrefix) *rtnetlink.AddressMessage {
func findAddress(addrs []rtnetlink.AddressMessage, linkIndex uint32, ipPrefix netip.Prefix) *rtnetlink.AddressMessage {
for i, addr := range addrs {
if addr.Index != linkIndex {
continue
}
if addr.PrefixLength != ipPrefix.Bits() {
if int(addr.PrefixLength) != ipPrefix.Bits() {
continue
}
if !addr.Attributes.Address.Equal(ipPrefix.IP().IPAddr().IP) {
if !addr.Attributes.Address.Equal(ipPrefix.Addr().AsSlice()) {
continue
}
@ -212,13 +212,13 @@ func (ctrl *AddressSpecController) syncAddress(ctx context.Context, r controller
// add address
if err := conn.Address.New(&rtnetlink.AddressMessage{
Family: uint8(address.TypedSpec().Family),
PrefixLength: address.TypedSpec().Address.Bits(),
PrefixLength: uint8(address.TypedSpec().Address.Bits()),
Flags: uint8(address.TypedSpec().Flags),
Scope: uint8(address.TypedSpec().Scope),
Index: linkIndex,
Attributes: &rtnetlink.AddressAttributes{
Address: address.TypedSpec().Address.IP().IPAddr().IP,
Local: address.TypedSpec().Address.IP().IPAddr().IP,
Address: address.TypedSpec().Address.Addr().AsSlice(),
Local: address.TypedSpec().Address.Addr().AsSlice(),
Broadcast: broadcastAddr(address.TypedSpec().Address),
Flags: uint32(address.TypedSpec().Flags),
},
@ -232,7 +232,7 @@ func (ctrl *AddressSpecController) syncAddress(ctx context.Context, r controller
logger.Info("assigned address", zap.Stringer("address", address.TypedSpec().Address), zap.String("link", address.TypedSpec().LinkName))
if address.TypedSpec().AnnounceWithARP {
if err := ctrl.gratuitousARP(logger, linkIndex, address.TypedSpec().Address.IP()); err != nil {
if err := ctrl.gratuitousARP(logger, linkIndex, address.TypedSpec().Address.Addr()); err != nil {
logger.Warn("failure sending gratuitous ARP", zap.Stringer("address", address.TypedSpec().Address), zap.String("link", address.TypedSpec().LinkName), zap.Error(err))
}
}
@ -241,7 +241,7 @@ func (ctrl *AddressSpecController) syncAddress(ctx context.Context, r controller
return nil
}
func (ctrl *AddressSpecController) gratuitousARP(logger *zap.Logger, linkIndex uint32, ip netaddr.IP) error {
func (ctrl *AddressSpecController) gratuitousARP(logger *zap.Logger, linkIndex uint32, ip netip.Addr) error {
etherBroadcast := net.HardwareAddr{0xff, 0xff, 0xff, 0xff, 0xff, 0xff}
if !ip.Is4() {
@ -265,7 +265,7 @@ func (ctrl *AddressSpecController) gratuitousARP(logger *zap.Logger, linkIndex u
defer cli.Close() //nolint:errcheck
packet, err := arp.NewPacket(arp.OperationRequest, cli.HardwareAddr(), netaddrIPToNetipAddr(ip), cli.HardwareAddr(), netaddrIPToNetipAddr(ip))
packet, err := arp.NewPacket(arp.OperationRequest, cli.HardwareAddr(), ip, cli.HardwareAddr(), ip)
if err != nil {
return fmt.Errorf("error building packet: %w", err)
}
@ -279,18 +279,12 @@ func (ctrl *AddressSpecController) gratuitousARP(logger *zap.Logger, linkIndex u
return nil
}
func netaddrIPToNetipAddr(addr netaddr.IP) netip.Addr {
ip, _ := netip.AddrFromSlice(addr.IPAddr().IP)
return ip
}
func broadcastAddr(addr netaddr.IPPrefix) net.IP {
if !addr.IP().Is4() {
func broadcastAddr(addr netip.Prefix) net.IP {
if !addr.Addr().Is4() {
return nil
}
ipnet := addr.IPNet()
ipnet := netipx.PrefixIPNet(addr)
ip := ipnet.IP.To4()
if ip == nil {

View File

@ -11,6 +11,7 @@ import (
"log"
"math/rand"
"net"
"net/netip"
"sync"
"testing"
"time"
@ -24,7 +25,6 @@ import (
"github.com/stretchr/testify/suite"
"github.com/talos-systems/go-retry/retry"
"golang.org/x/sys/unix"
"inet.af/netaddr"
netctrl "github.com/talos-systems/talos/internal/app/machined/pkg/controllers/network"
"github.com/talos-systems/talos/pkg/logging"
@ -74,7 +74,7 @@ func (suite *AddressSpecSuite) startRuntime() {
}
func (suite *AddressSpecSuite) assertLinkAddress(linkName, address string) error {
addr := netaddr.MustParseIPPrefix(address)
addr := netip.MustParsePrefix(address)
iface, err := net.InterfaceByName(linkName)
suite.Require().NoError(err)
@ -92,11 +92,11 @@ func (suite *AddressSpecSuite) assertLinkAddress(linkName, address string) error
continue
}
if linkAddress.PrefixLength != addr.Bits() {
if int(linkAddress.PrefixLength) != addr.Bits() {
continue
}
if !linkAddress.Attributes.Address.Equal(addr.IP().IPAddr().IP) {
if !linkAddress.Attributes.Address.Equal(addr.Addr().AsSlice()) {
continue
}
@ -107,7 +107,7 @@ func (suite *AddressSpecSuite) assertLinkAddress(linkName, address string) error
}
func (suite *AddressSpecSuite) assertNoLinkAddress(linkName, address string) error {
addr := netaddr.MustParseIPPrefix(address)
addr := netip.MustParsePrefix(address)
iface, err := net.InterfaceByName(linkName)
suite.Require().NoError(err)
@ -121,7 +121,7 @@ func (suite *AddressSpecSuite) assertNoLinkAddress(linkName, address string) err
suite.Require().NoError(err)
for _, linkAddress := range linkAddresses {
if linkAddress.Index == uint32(iface.Index) && linkAddress.PrefixLength == addr.Bits() && linkAddress.Attributes.Address.Equal(addr.IP().IPAddr().IP) {
if linkAddress.Index == uint32(iface.Index) && int(linkAddress.PrefixLength) == addr.Bits() && linkAddress.Attributes.Address.Equal(addr.Addr().AsSlice()) {
return retry.ExpectedError(fmt.Errorf("address %s is assigned to %q", addr, linkName))
}
}
@ -132,7 +132,7 @@ func (suite *AddressSpecSuite) assertNoLinkAddress(linkName, address string) err
func (suite *AddressSpecSuite) TestLoopback() {
loopback := network.NewAddressSpec(network.NamespaceName, "lo/127.0.0.1/8")
*loopback.TypedSpec() = network.AddressSpecSpec{
Address: netaddr.MustParseIPPrefix("127.11.0.1/32"),
Address: netip.MustParsePrefix("127.11.0.1/32"),
LinkName: "lo",
Family: nethelpers.FamilyInet4,
Scope: nethelpers.ScopeHost,
@ -180,7 +180,7 @@ func (suite *AddressSpecSuite) TestDummy() {
dummy := network.NewAddressSpec(network.NamespaceName, "dummy/10.0.0.1/8")
*dummy.TypedSpec() = network.AddressSpecSpec{
Address: netaddr.MustParseIPPrefix("10.0.0.1/8"),
Address: netip.MustParsePrefix("10.0.0.1/8"),
LinkName: dummyInterface,
Family: nethelpers.FamilyInet4,
Scope: nethelpers.ScopeGlobal,

View File

@ -7,13 +7,14 @@ package network
import (
"context"
"fmt"
"net/netip"
"github.com/cosi-project/runtime/pkg/controller"
"github.com/cosi-project/runtime/pkg/resource"
"github.com/jsimonetti/rtnetlink"
"go.uber.org/zap"
"go4.org/netipx"
"golang.org/x/sys/unix"
"inet.af/netaddr"
"github.com/talos-systems/talos/internal/app/machined/pkg/controllers/network/watch"
"github.com/talos-systems/talos/pkg/machinery/nethelpers"
@ -97,18 +98,18 @@ func (ctrl *AddressStatusController) Run(ctx context.Context, r controller.Runti
// * but for point-to-point IFA_ADDRESS is DESTINATION address,
// * local address is supplied in IFA_LOCAL attribute.
ipAddr, _ := netaddr.FromStdIPRaw(addr.Attributes.Address)
ipPrefix := netaddr.IPPrefixFrom(ipAddr, addr.PrefixLength)
ipAddr, _ := netipx.FromStdIPRaw(addr.Attributes.Address)
ipPrefix := netip.PrefixFrom(ipAddr, int(addr.PrefixLength))
id := network.AddressID(linkLookup[addr.Index], ipPrefix)
if err = r.Modify(ctx, network.NewAddressStatus(network.NamespaceName, id), func(r resource.Resource) error {
status := r.(*network.AddressStatus).TypedSpec()
status.Address = ipPrefix
status.Local, _ = netaddr.FromStdIPRaw(addr.Attributes.Local)
status.Broadcast, _ = netaddr.FromStdIPRaw(addr.Attributes.Broadcast)
status.Anycast, _ = netaddr.FromStdIPRaw(addr.Attributes.Anycast)
status.Multicast, _ = netaddr.FromStdIPRaw(addr.Attributes.Multicast)
status.Local, _ = netipx.FromStdIPRaw(addr.Attributes.Local)
status.Broadcast, _ = netipx.FromStdIPRaw(addr.Attributes.Broadcast)
status.Anycast, _ = netipx.FromStdIPRaw(addr.Attributes.Anycast)
status.Multicast, _ = netipx.FromStdIPRaw(addr.Attributes.Multicast)
status.LinkIndex = addr.Index
status.LinkName = linkLookup[addr.Index]
status.Family = nethelpers.Family(addr.Family)

View File

@ -8,12 +8,12 @@ import (
"errors"
"fmt"
"net"
"net/netip"
"sort"
"strconv"
"strings"
"github.com/talos-systems/go-procfs/procfs"
"inet.af/netaddr"
"github.com/talos-systems/talos/pkg/machinery/config/types/v1alpha1"
"github.com/talos-systems/talos/pkg/machinery/constants"
@ -25,12 +25,12 @@ import (
// CmdlineNetworking contains parsed cmdline networking settings.
type CmdlineNetworking struct {
DHCP bool
Address netaddr.IPPrefix
Gateway netaddr.IP
Address netip.Prefix
Gateway netip.Addr
Hostname string
LinkName string
DNSAddresses []netaddr.IP
NTPAddresses []netaddr.IP
DNSAddresses []netip.Addr
NTPAddresses []netip.Addr
IgnoreInterfaces []string
NetworkLinkSpecs []network.LinkSpecSpec
}
@ -110,31 +110,31 @@ func ParseCmdlineNetwork(cmdline *procfs.Cmdline) (CmdlineNetworking, error) {
switch i {
case 0:
var ip netaddr.IP
var ip netip.Addr
ip, err = netaddr.ParseIP(fields[0])
ip, err = netip.ParseAddr(fields[0])
if err != nil {
return settings, fmt.Errorf("cmdline address parse failure: %s", err)
}
// default is to have complete address masked
settings.Address = netaddr.IPPrefixFrom(ip, ip.BitLen())
settings.Address = netip.PrefixFrom(ip, ip.BitLen())
case 2:
settings.Gateway, err = netaddr.ParseIP(fields[2])
settings.Gateway, err = netip.ParseAddr(fields[2])
if err != nil {
return settings, fmt.Errorf("cmdline gateway parse failure: %s", err)
}
case 3:
var netmask netaddr.IP
var netmask netip.Addr
netmask, err = netaddr.ParseIP(fields[3])
netmask, err = netip.ParseAddr(fields[3])
if err != nil {
return settings, fmt.Errorf("cmdline netmask parse failure: %s", err)
}
ones, _ := net.IPMask(netmask.IPAddr().IP).Size()
ones, _ := net.IPMask(netmask.AsSlice()).Size()
settings.Address = netaddr.IPPrefixFrom(settings.Address.IP(), uint8(ones))
settings.Address = netip.PrefixFrom(settings.Address.Addr(), ones)
case 4:
if settings.Hostname == "" {
settings.Hostname = fields[4]
@ -142,18 +142,18 @@ func ParseCmdlineNetwork(cmdline *procfs.Cmdline) (CmdlineNetworking, error) {
case 5:
settings.LinkName = fields[5]
case 7, 8:
var dnsIP netaddr.IP
var dnsIP netip.Addr
dnsIP, err = netaddr.ParseIP(fields[i])
dnsIP, err = netip.ParseAddr(fields[i])
if err != nil {
return settings, fmt.Errorf("error parsing DNS IP: %w", err)
}
settings.DNSAddresses = append(settings.DNSAddresses, dnsIP)
case 9:
var ntpIP netaddr.IP
var ntpIP netip.Addr
ntpIP, err = netaddr.ParseIP(fields[i])
ntpIP, err = netip.ParseAddr(fields[i])
if err != nil {
return settings, fmt.Errorf("error parsing DNS IP: %w", err)
}

View File

@ -6,12 +6,12 @@ package network_test
import (
"net"
"net/netip"
"sort"
"testing"
"github.com/stretchr/testify/suite"
"github.com/talos-systems/go-procfs/procfs"
"inet.af/netaddr"
"github.com/talos-systems/talos/internal/app/machined/pkg/controllers/network"
"github.com/talos-systems/talos/pkg/machinery/nethelpers"
@ -97,8 +97,8 @@ func (suite *CmdlineSuite) TestParse() {
cmdline: "ip=172.20.0.2::172.20.0.1:255.255.255.0::eth1:::::",
expectedSettings: network.CmdlineNetworking{
Address: netaddr.MustParseIPPrefix("172.20.0.2/24"),
Gateway: netaddr.MustParseIP("172.20.0.1"),
Address: netip.MustParsePrefix("172.20.0.2/24"),
Gateway: netip.MustParseAddr("172.20.0.1"),
LinkName: "eth1",
NetworkLinkSpecs: []netconfig.LinkSpecSpec{
{
@ -114,8 +114,8 @@ func (suite *CmdlineSuite) TestParse() {
cmdline: "ip=172.20.0.2::172.20.0.1",
expectedSettings: network.CmdlineNetworking{
Address: netaddr.MustParseIPPrefix("172.20.0.2/32"),
Gateway: netaddr.MustParseIP("172.20.0.1"),
Address: netip.MustParsePrefix("172.20.0.2/32"),
Gateway: netip.MustParseAddr("172.20.0.1"),
LinkName: defaultIfaceName,
NetworkLinkSpecs: []netconfig.LinkSpecSpec{
{
@ -131,12 +131,12 @@ func (suite *CmdlineSuite) TestParse() {
cmdline: "ip=172.20.0.2:172.21.0.1:172.20.0.1:255.255.255.0:master1:eth1::10.0.0.1:10.0.0.2:10.0.0.1",
expectedSettings: network.CmdlineNetworking{
Address: netaddr.MustParseIPPrefix("172.20.0.2/24"),
Gateway: netaddr.MustParseIP("172.20.0.1"),
Address: netip.MustParsePrefix("172.20.0.2/24"),
Gateway: netip.MustParseAddr("172.20.0.1"),
Hostname: "master1",
LinkName: "eth1",
DNSAddresses: []netaddr.IP{netaddr.MustParseIP("10.0.0.1"), netaddr.MustParseIP("10.0.0.2")},
NTPAddresses: []netaddr.IP{netaddr.MustParseIP("10.0.0.1")},
DNSAddresses: []netip.Addr{netip.MustParseAddr("10.0.0.1"), netip.MustParseAddr("10.0.0.2")},
NTPAddresses: []netip.Addr{netip.MustParseAddr("10.0.0.1")},
NetworkLinkSpecs: []netconfig.LinkSpecSpec{
{
Name: "eth1",
@ -150,12 +150,12 @@ func (suite *CmdlineSuite) TestParse() {
name: "ipv6",
cmdline: "ip=[2001:db8::a]:[2001:db8::b]:[fe80::1]::master1:eth1::[2001:4860:4860::6464]:[2001:4860:4860::64]:[2001:4860:4806::]",
expectedSettings: network.CmdlineNetworking{
Address: netaddr.MustParseIPPrefix("2001:db8::a/128"),
Gateway: netaddr.MustParseIP("fe80::1"),
Address: netip.MustParsePrefix("2001:db8::a/128"),
Gateway: netip.MustParseAddr("fe80::1"),
Hostname: "master1",
LinkName: "eth1",
DNSAddresses: []netaddr.IP{netaddr.MustParseIP("2001:4860:4860::6464"), netaddr.MustParseIP("2001:4860:4860::64")},
NTPAddresses: []netaddr.IP{netaddr.MustParseIP("2001:4860:4806::")},
DNSAddresses: []netip.Addr{netip.MustParseAddr("2001:4860:4860::6464"), netip.MustParseAddr("2001:4860:4860::64")},
NTPAddresses: []netip.Addr{netip.MustParseAddr("2001:4860:4806::")},
NetworkLinkSpecs: []netconfig.LinkSpecSpec{
{
Name: "eth1",
@ -169,7 +169,7 @@ func (suite *CmdlineSuite) TestParse() {
name: "unparseable IP",
cmdline: "ip=xyz:",
expectedError: "cmdline address parse failure: ParseIP(\"xyz\"): unable to parse IP",
expectedError: "cmdline address parse failure: ParseAddr(\"xyz\"): unable to parse IP",
},
{
name: "hostname override",
@ -315,8 +315,8 @@ func (suite *CmdlineSuite) TestParse() {
name: "vlan configuration",
cmdline: "vlan=eth1.169:eth1 ip=172.20.0.2::172.20.0.1:255.255.255.0::eth1.169:::::",
expectedSettings: network.CmdlineNetworking{
Address: netaddr.MustParseIPPrefix("172.20.0.2/24"),
Gateway: netaddr.MustParseIP("172.20.0.1"),
Address: netip.MustParsePrefix("172.20.0.2/24"),
Gateway: netip.MustParseAddr("172.20.0.1"),
LinkName: "eth1.169",
NetworkLinkSpecs: []netconfig.LinkSpecSpec{
{

View File

@ -187,7 +187,7 @@ func (ctrl *EtcFileController) renderHosts(hostnameStatus *network.HostnameStatu
write("127.0.0.1\tlocalhost\n")
write(fmt.Sprintf("%s\t%s", nodeAddressStatus.Addresses[0].IP(), hostnameStatus.FQDN()))
write(fmt.Sprintf("%s\t%s", nodeAddressStatus.Addresses[0].Addr(), hostnameStatus.FQDN()))
if hostnameStatus.Hostname != hostnameStatus.FQDN() {
write(" " + hostnameStatus.Hostname)

View File

@ -9,6 +9,7 @@ import (
"context"
"fmt"
"log"
"net/netip"
"net/url"
"sync"
"testing"
@ -22,7 +23,6 @@ import (
"github.com/siderolabs/go-pointer"
"github.com/stretchr/testify/suite"
"github.com/talos-systems/go-retry/retry"
"inet.af/netaddr"
netctrl "github.com/talos-systems/talos/internal/app/machined/pkg/controllers/network"
"github.com/talos-systems/talos/pkg/logging"
@ -94,18 +94,18 @@ func (suite *EtcFileConfigSuite) SetupTest() {
)
suite.defaultAddress = network.NewNodeAddress(network.NamespaceName, network.NodeAddressDefaultID)
suite.defaultAddress.TypedSpec().Addresses = []netaddr.IPPrefix{netaddr.MustParseIPPrefix("33.11.22.44/32")}
suite.defaultAddress.TypedSpec().Addresses = []netip.Prefix{netip.MustParsePrefix("33.11.22.44/32")}
suite.hostnameStatus = network.NewHostnameStatus(network.NamespaceName, network.HostnameID)
suite.hostnameStatus.TypedSpec().Hostname = "foo"
suite.hostnameStatus.TypedSpec().Domainname = "example.com"
suite.resolverStatus = network.NewResolverStatus(network.NamespaceName, network.ResolverID)
suite.resolverStatus.TypedSpec().DNSServers = []netaddr.IP{
netaddr.MustParseIP("1.1.1.1"),
netaddr.MustParseIP("2.2.2.2"),
netaddr.MustParseIP("3.3.3.3"),
netaddr.MustParseIP("4.4.4.4"),
suite.resolverStatus.TypedSpec().DNSServers = []netip.Addr{
netip.MustParseAddr("1.1.1.1"),
netip.MustParseAddr("2.2.2.2"),
netip.MustParseAddr("3.3.3.3"),
netip.MustParseAddr("4.4.4.4"),
}
}

View File

@ -216,7 +216,7 @@ func (ctrl *HostnameConfigController) getDefault(defaultAddr *network.NodeAddres
return
}
spec.Hostname = fmt.Sprintf("talos-%s", strings.ReplaceAll(strings.ReplaceAll(defaultAddr.TypedSpec().Addresses[0].IP().String(), ":", ""), ".", "-"))
spec.Hostname = fmt.Sprintf("talos-%s", strings.ReplaceAll(strings.ReplaceAll(defaultAddr.TypedSpec().Addresses[0].Addr().String(), ":", ""), ".", "-"))
spec.ConfigLayer = network.ConfigDefault
return spec

View File

@ -9,6 +9,7 @@ import (
"context"
"fmt"
"log"
"net/netip"
"net/url"
"strings"
"sync"
@ -24,7 +25,6 @@ import (
"github.com/stretchr/testify/suite"
"github.com/talos-systems/go-procfs/procfs"
"github.com/talos-systems/go-retry/retry"
"inet.af/netaddr"
netctrl "github.com/talos-systems/talos/internal/app/machined/pkg/controllers/network"
"github.com/talos-systems/talos/pkg/logging"
@ -126,7 +126,7 @@ func (suite *HostnameConfigSuite) TestNoDefaultWithoutMachineConfig() {
suite.startRuntime()
defaultAddress := network.NewNodeAddress(network.NamespaceName, network.NodeAddressDefaultID)
defaultAddress.TypedSpec().Addresses = []netaddr.IPPrefix{netaddr.MustParseIPPrefix("33.11.22.44/32")}
defaultAddress.TypedSpec().Addresses = []netip.Prefix{netip.MustParsePrefix("33.11.22.44/32")}
suite.Require().NoError(suite.state.Create(suite.ctx, defaultAddress))
@ -153,7 +153,7 @@ func (suite *HostnameConfigSuite) TestDefaultIPBasedHostname() {
suite.Require().NoError(suite.state.Create(suite.ctx, cfg))
defaultAddress := network.NewNodeAddress(network.NamespaceName, network.NodeAddressDefaultID)
defaultAddress.TypedSpec().Addresses = []netaddr.IPPrefix{netaddr.MustParseIPPrefix("33.11.22.44/32")}
defaultAddress.TypedSpec().Addresses = []netip.Prefix{netip.MustParsePrefix("33.11.22.44/32")}
suite.Require().NoError(suite.state.Create(suite.ctx, defaultAddress))

View File

@ -7,13 +7,13 @@ package network
import (
"context"
"fmt"
"net/netip"
"github.com/cosi-project/runtime/pkg/controller"
"github.com/cosi-project/runtime/pkg/resource"
"github.com/cosi-project/runtime/pkg/state"
"github.com/talos-systems/go-procfs/procfs"
"go.uber.org/zap"
"inet.af/netaddr"
talosconfig "github.com/talos-systems/talos/pkg/machinery/config"
"github.com/talos-systems/talos/pkg/machinery/generic/maps"
@ -425,10 +425,10 @@ func wireguardLink(link *network.LinkSpecSpec, config talosconfig.WireguardConfi
}
for _, peer := range config.Peers() {
allowedIPs := make([]netaddr.IPPrefix, 0, len(peer.AllowedIPs()))
allowedIPs := make([]netip.Prefix, 0, len(peer.AllowedIPs()))
for _, allowedIP := range peer.AllowedIPs() {
ip, err := netaddr.ParseIPPrefix(allowedIP)
ip, err := netip.ParsePrefix(allowedIP)
if err != nil {
return err
}

View File

@ -9,6 +9,7 @@ import (
"context"
"fmt"
"log"
"net/netip"
"net/url"
"sync"
"testing"
@ -23,7 +24,6 @@ import (
"github.com/stretchr/testify/suite"
"github.com/talos-systems/go-procfs/procfs"
"github.com/talos-systems/go-retry/retry"
"inet.af/netaddr"
netctrl "github.com/talos-systems/talos/internal/app/machined/pkg/controllers/network"
"github.com/talos-systems/talos/pkg/logging"
@ -375,9 +375,9 @@ func (suite *LinkConfigSuite) TestMachineConfiguration() {
{
PublicKey: "DEF",
Endpoint: "10.0.0.1:3000",
AllowedIPs: []netaddr.IPPrefix{
netaddr.MustParseIPPrefix("10.2.3.0/24"),
netaddr.MustParseIPPrefix("10.2.4.0/24"),
AllowedIPs: []netip.Prefix{
netip.MustParsePrefix("10.2.3.0/24"),
netip.MustParsePrefix("10.2.4.0/24"),
},
},
},

View File

@ -10,6 +10,7 @@ import (
"fmt"
"log"
"math/rand"
"net/netip"
"sync"
"testing"
"time"
@ -23,7 +24,6 @@ import (
"github.com/stretchr/testify/suite"
"github.com/talos-systems/go-retry/retry"
"golang.zx2c4.com/wireguard/wgctrl/wgtypes"
"inet.af/netaddr"
networkadapter "github.com/talos-systems/talos/internal/app/machined/pkg/adapters/network"
netctrl "github.com/talos-systems/talos/internal/app/machined/pkg/controllers/network"
@ -801,14 +801,14 @@ func (suite *LinkSpecSuite) TestWireguard() {
{
PublicKey: pub1.PublicKey().String(),
Endpoint: "10.2.0.3:20000",
AllowedIPs: []netaddr.IPPrefix{
netaddr.MustParseIPPrefix("172.24.0.0/16"),
AllowedIPs: []netip.Prefix{
netip.MustParsePrefix("172.24.0.0/16"),
},
},
{
PublicKey: pub2.PublicKey().String(),
AllowedIPs: []netaddr.IPPrefix{
netaddr.MustParseIPPrefix("172.25.0.0/24"),
AllowedIPs: []netip.Prefix{
netip.MustParsePrefix("172.25.0.0/24"),
},
},
},

View File

@ -7,13 +7,14 @@ package network
import (
"context"
"fmt"
"net/netip"
"sort"
"github.com/cosi-project/runtime/pkg/controller"
"github.com/cosi-project/runtime/pkg/resource"
"go.uber.org/zap"
"inet.af/netaddr"
"github.com/talos-systems/talos/pkg/machinery/generic"
"github.com/talos-systems/talos/pkg/machinery/generic/slices"
"github.com/talos-systems/talos/pkg/machinery/nethelpers"
"github.com/talos-systems/talos/pkg/machinery/resources/network"
@ -105,11 +106,11 @@ func (ctrl *NodeAddressController) Run(ctx context.Context, r controller.Runtime
}
var (
defaultAddress netaddr.IPPrefix
defaultAddress netip.Prefix
defaultAddrLinkName string
current []netaddr.IPPrefix
routed []netaddr.IPPrefix
accumulative []netaddr.IPPrefix
current []netip.Prefix
routed []netip.Prefix
accumulative []netip.Prefix
)
for _, r := range addresses.Items {
@ -121,13 +122,13 @@ func (ctrl *NodeAddressController) Run(ctx context.Context, r controller.Runtime
ip := addr.TypedSpec().Address
if ip.IP().IsLoopback() || ip.IP().IsMulticast() || ip.IP().IsLinkLocalUnicast() {
if ip.Addr().IsLoopback() || ip.Addr().IsMulticast() || ip.Addr().IsLinkLocalUnicast() {
continue
}
// set defaultAddress to the smallest IP from the alphabetically first link
if addr.Metadata().Owner() == addressStatusControllerName {
if defaultAddress.IsZero() || addr.TypedSpec().LinkName < defaultAddrLinkName || (addr.TypedSpec().LinkName == defaultAddrLinkName && ip.IP().Compare(defaultAddress.IP()) < 0) {
if generic.IsZero(defaultAddress) || addr.TypedSpec().LinkName < defaultAddrLinkName || (addr.TypedSpec().LinkName == defaultAddrLinkName && ip.Addr().Compare(defaultAddress.Addr()) < 0) {
defaultAddress = ip
defaultAddrLinkName = addr.TypedSpec().LinkName
}
@ -140,7 +141,7 @@ func (ctrl *NodeAddressController) Run(ctx context.Context, r controller.Runtime
// routed: filter out external addresses and addresses from SideroLink
if _, up := linksUp[addr.TypedSpec().LinkIndex]; up && addr.TypedSpec().LinkName != externalLink {
if network.NotSideroLinkIP(ip.IP()) {
if network.NotSideroLinkIP(ip.Addr()) {
routed = append(routed, ip)
}
}
@ -149,8 +150,8 @@ func (ctrl *NodeAddressController) Run(ctx context.Context, r controller.Runtime
}
// sort current addresses
sort.Slice(current, func(i, j int) bool { return current[i].IP().Compare(current[j].IP()) < 0 })
sort.Slice(routed, func(i, j int) bool { return routed[i].IP().Compare(routed[j].IP()) < 0 })
sort.Slice(current, func(i, j int) bool { return current[i].Addr().Compare(current[j].Addr()) < 0 })
sort.Slice(routed, func(i, j int) bool { return routed[i].Addr().Compare(routed[j].Addr()) < 0 })
// remove duplicates from current addresses
current = deduplicateIPPrefixes(current)
@ -159,7 +160,7 @@ func (ctrl *NodeAddressController) Run(ctx context.Context, r controller.Runtime
touchedIDs := make(map[resource.ID]struct{})
// update output resources
if !defaultAddress.IsZero() {
if !generic.IsZero(defaultAddress) {
if err = r.Modify(ctx, network.NewNodeAddress(network.NamespaceName, network.NodeAddressDefaultID), func(r resource.Resource) error {
spec := r.(*network.NodeAddress).TypedSpec()
@ -167,11 +168,11 @@ func (ctrl *NodeAddressController) Run(ctx context.Context, r controller.Runtime
// we should start handing default address updates, but for now we're not ready
//
// at the same time check that recorded default address is still on the host, if it's not => replace it
if len(spec.Addresses) > 0 && slices.Contains(current, func(addr netaddr.IPPrefix) bool { return spec.Addresses[0] == addr }) {
if len(spec.Addresses) > 0 && slices.Contains(current, func(addr netip.Prefix) bool { return spec.Addresses[0] == addr }) {
return nil
}
spec.Addresses = []netaddr.IPPrefix{defaultAddress}
spec.Addresses = []netip.Prefix{defaultAddress}
return nil
}); err != nil {
@ -245,11 +246,11 @@ func (ctrl *NodeAddressController) Run(ctx context.Context, r controller.Runtime
}
}
func deduplicateIPPrefixes(current []netaddr.IPPrefix) []netaddr.IPPrefix {
func deduplicateIPPrefixes(current []netip.Prefix) []netip.Prefix {
// assumes that current is sorted
n := 0
var prev netaddr.IPPrefix
var prev netip.Prefix
for _, x := range current {
if prev != x {
@ -263,8 +264,8 @@ func deduplicateIPPrefixes(current []netaddr.IPPrefix) []netaddr.IPPrefix {
return current[:n]
}
func filterIPs(addrs []netaddr.IPPrefix, includeSubnets, excludeSubnets []netaddr.IPPrefix) []netaddr.IPPrefix {
result := make([]netaddr.IPPrefix, 0, len(addrs))
func filterIPs(addrs []netip.Prefix, includeSubnets, excludeSubnets []netip.Prefix) []netip.Prefix {
result := make([]netip.Prefix, 0, len(addrs))
outer:
for _, ip := range addrs {
@ -296,7 +297,7 @@ outer:
return result
}
func updateCurrentAddresses(ctx context.Context, r controller.Runtime, id resource.ID, current []netaddr.IPPrefix) error {
func updateCurrentAddresses(ctx context.Context, r controller.Runtime, id resource.ID, current []netip.Prefix) error {
if err := r.Modify(ctx, network.NewNodeAddress(network.NamespaceName, id), func(r resource.Resource) error {
spec := r.(*network.NodeAddress).TypedSpec()
@ -310,7 +311,7 @@ func updateCurrentAddresses(ctx context.Context, r controller.Runtime, id resour
return nil
}
func updateAccumulativeAddresses(ctx context.Context, r controller.Runtime, id resource.ID, accumulative []netaddr.IPPrefix) error {
func updateAccumulativeAddresses(ctx context.Context, r controller.Runtime, id resource.ID, accumulative []netip.Prefix) error {
if err := r.Modify(ctx, network.NewNodeAddress(network.NamespaceName, id), func(r resource.Resource) error {
spec := r.(*network.NodeAddress).TypedSpec()
@ -319,15 +320,15 @@ func updateAccumulativeAddresses(ctx context.Context, r controller.Runtime, id r
// find insert position using binary search
i := sort.Search(len(spec.Addresses), func(j int) bool {
return !spec.Addresses[j].IP().Less(ip.IP())
return !spec.Addresses[j].Addr().Less(ip.Addr())
})
if i < len(spec.Addresses) && spec.Addresses[i].IP().Compare(ip.IP()) == 0 {
if i < len(spec.Addresses) && spec.Addresses[i].Addr().Compare(ip.Addr()) == 0 {
continue
}
// insert at position i
spec.Addresses = append(spec.Addresses, netaddr.IPPrefix{})
spec.Addresses = append(spec.Addresses, netip.Prefix{})
copy(spec.Addresses[i+1:], spec.Addresses[i:])
spec.Addresses[i] = ip
}

View File

@ -9,6 +9,7 @@ import (
"context"
"fmt"
"log"
"net/netip"
"reflect"
"sort"
"strings"
@ -23,7 +24,6 @@ import (
"github.com/cosi-project/runtime/pkg/state/impl/namespaced"
"github.com/stretchr/testify/suite"
"github.com/talos-systems/go-retry/retry"
"inet.af/netaddr"
netctrl "github.com/talos-systems/talos/internal/app/machined/pkg/controllers/network"
"github.com/talos-systems/talos/pkg/logging"
@ -124,7 +124,7 @@ func (suite *NodeAddressSuite) TestDefaults() {
suite.Assert().True(
sort.SliceIsSorted(
addrs, func(i, j int) bool {
return addrs[i].IP().Compare(addrs[j].IP()) < 0
return addrs[i].Addr().Compare(addrs[j].Addr()) < 0
},
), "addresses %s", addrs,
)
@ -166,7 +166,7 @@ func (suite *NodeAddressSuite) TestFilters() {
linkDown.TypedSpec().Index = 2
suite.Require().NoError(suite.state.Create(suite.ctx, linkDown))
newAddress := func(addr netaddr.IPPrefix, link *network.LinkStatus) {
newAddress := func(addr netip.Prefix, link *network.LinkStatus) {
addressStatus := network.NewAddressStatus(network.NamespaceName, network.AddressID(link.Metadata().ID(), addr))
addressStatus.TypedSpec().Address = addr
addressStatus.TypedSpec().LinkName = link.Metadata().ID()
@ -180,7 +180,7 @@ func (suite *NodeAddressSuite) TestFilters() {
)
}
newExternalAddress := func(addr netaddr.IPPrefix) {
newExternalAddress := func(addr netip.Prefix) {
addressStatus := network.NewAddressStatus(network.NamespaceName, network.AddressID("external", addr))
addressStatus.TypedSpec().Address = addr
addressStatus.TypedSpec().LinkName = "external"
@ -200,25 +200,25 @@ func (suite *NodeAddressSuite) TestFilters() {
"127.0.0.1/8",
"fdae:41e4:649b:9303:7886:731d:1ce9:4d4/128",
} {
newAddress(netaddr.MustParseIPPrefix(addr), linkUp)
newAddress(netip.MustParsePrefix(addr), linkUp)
}
for _, addr := range []string{"10.0.0.2/8", "192.168.3.7/24"} {
newAddress(netaddr.MustParseIPPrefix(addr), linkDown)
newAddress(netip.MustParsePrefix(addr), linkDown)
}
for _, addr := range []string{"1.2.3.4/32", "25.3.7.9/32"} { // duplicate with link address: 25.3.7.9
newExternalAddress(netaddr.MustParseIPPrefix(addr))
newExternalAddress(netip.MustParsePrefix(addr))
}
filter1 := network.NewNodeAddressFilter(network.NamespaceName, "no-k8s")
filter1.TypedSpec().ExcludeSubnets = []netaddr.IPPrefix{netaddr.MustParseIPPrefix("10.0.0.0/8")}
filter1.TypedSpec().ExcludeSubnets = []netip.Prefix{netip.MustParsePrefix("10.0.0.0/8")}
suite.Require().NoError(suite.state.Create(suite.ctx, filter1))
filter2 := network.NewNodeAddressFilter(network.NamespaceName, "only-k8s")
filter2.TypedSpec().IncludeSubnets = []netaddr.IPPrefix{
netaddr.MustParseIPPrefix("10.0.0.0/8"),
netaddr.MustParseIPPrefix("192.168.0.0/16"),
filter2.TypedSpec().IncludeSubnets = []netip.Prefix{
netip.MustParsePrefix("10.0.0.0/8"),
netip.MustParsePrefix("192.168.0.0/16"),
}
suite.Require().NoError(suite.state.Create(suite.ctx, filter2))
@ -316,7 +316,7 @@ func (suite *NodeAddressSuite) TestDefaultAddressChange() {
linkUp.TypedSpec().Index = 1
suite.Require().NoError(suite.state.Create(suite.ctx, linkUp))
newAddress := func(addr netaddr.IPPrefix, link *network.LinkStatus) {
newAddress := func(addr netip.Prefix, link *network.LinkStatus) {
addressStatus := network.NewAddressStatus(network.NamespaceName, network.AddressID(link.Metadata().ID(), addr))
addressStatus.TypedSpec().Address = addr
addressStatus.TypedSpec().LinkName = link.Metadata().ID()
@ -335,7 +335,7 @@ func (suite *NodeAddressSuite) TestDefaultAddressChange() {
"25.3.7.9/32",
"127.0.0.1/8",
} {
newAddress(netaddr.MustParseIPPrefix(addr), linkUp)
newAddress(netip.MustParsePrefix(addr), linkUp)
}
suite.Assert().NoError(
@ -378,7 +378,7 @@ func (suite *NodeAddressSuite) TestDefaultAddressChange() {
)
// add another address which is "smaller", but default address shouldn't change
newAddress(netaddr.MustParseIPPrefix("1.1.1.1/32"), linkUp)
newAddress(netip.MustParsePrefix("1.1.1.1/32"), linkUp)
suite.Assert().NoError(
retry.Constant(3*time.Second, retry.WithUnits(100*time.Millisecond)).Retry(
@ -421,7 +421,7 @@ func (suite *NodeAddressSuite) TestDefaultAddressChange() {
// remove the previous default address, now default address should change
suite.Require().NoError(suite.state.Destroy(suite.ctx,
network.NewAddressStatus(network.NamespaceName, network.AddressID(linkUp.Metadata().ID(), netaddr.MustParseIPPrefix("10.0.0.5/8"))).Metadata(),
network.NewAddressStatus(network.NamespaceName, network.AddressID(linkUp.Metadata().ID(), netip.MustParsePrefix("10.0.0.5/8"))).Metadata(),
state.WithDestroyOwner(addressStatusController.Name()),
))
@ -491,11 +491,11 @@ func TestNodeAddressSuite(t *testing.T) {
suite.Run(t, new(NodeAddressSuite))
}
func ipList(ips string) []netaddr.IPPrefix {
var result []netaddr.IPPrefix //nolint:prealloc
func ipList(ips string) []netip.Prefix {
var result []netip.Prefix //nolint:prealloc
for _, ip := range strings.Split(ips, " ") {
result = append(result, netaddr.MustParseIPPrefix(ip))
result = append(result, netip.MustParsePrefix(ip))
}
return result

View File

@ -9,6 +9,7 @@ import (
"errors"
"fmt"
"net"
"net/netip"
"strings"
"sync"
"time"
@ -16,7 +17,7 @@ import (
"github.com/insomniacslk/dhcp/dhcpv4"
"github.com/insomniacslk/dhcp/dhcpv4/nclient4"
"go.uber.org/zap"
"inet.af/netaddr"
"go4.org/netipx"
"github.com/talos-systems/talos/internal/app/machined/pkg/runtime"
"github.com/talos-systems/talos/pkg/machinery/generic/slices"
@ -154,7 +155,7 @@ func (d *DHCP4) parseAck(ack *dhcpv4.DHCPv4) {
d.mu.Lock()
defer d.mu.Unlock()
addr, _ := netaddr.FromStdIPNet(&net.IPNet{
addr, _ := netipx.FromStdIPNet(&net.IPNet{
IP: ack.YourIPAddr,
Mask: ack.SubnetMask(),
})
@ -190,13 +191,13 @@ func (d *DHCP4) parseAck(ack *dhcpv4.DHCPv4) {
if len(ack.ClasslessStaticRoute()) > 0 {
for _, route := range ack.ClasslessStaticRoute() {
gw, _ := netaddr.FromStdIP(route.Router)
dst, _ := netaddr.FromStdIPNet(route.Dest)
gw, _ := netipx.FromStdIP(route.Router)
dst, _ := netipx.FromStdIPNet(route.Dest)
d.routes = append(d.routes, network.RouteSpecSpec{
Family: nethelpers.FamilyInet4,
Destination: dst,
Source: addr.IP(),
Source: addr.Addr(),
Gateway: gw,
OutLinkName: d.linkName,
Table: nethelpers.TableMain,
@ -209,12 +210,12 @@ func (d *DHCP4) parseAck(ack *dhcpv4.DHCPv4) {
}
} else {
for _, router := range ack.Router() {
gw, _ := netaddr.FromStdIP(router)
gw, _ := netipx.FromStdIP(router)
d.routes = append(d.routes, network.RouteSpecSpec{
Family: nethelpers.FamilyInet4,
Gateway: gw,
Source: addr.IP(),
Source: addr.Addr(),
OutLinkName: d.linkName,
Table: nethelpers.TableMain,
Priority: d.routeMetric,
@ -228,8 +229,8 @@ func (d *DHCP4) parseAck(ack *dhcpv4.DHCPv4) {
// add an interface route for the gateway if it's not in the same network
d.routes = append(d.routes, network.RouteSpecSpec{
Family: nethelpers.FamilyInet4,
Destination: netaddr.IPPrefixFrom(gw, gw.BitLen()),
Source: addr.IP(),
Destination: netip.PrefixFrom(gw, gw.BitLen()),
Source: addr.Addr(),
OutLinkName: d.linkName,
Table: nethelpers.TableMain,
Priority: d.routeMetric,
@ -247,8 +248,8 @@ func (d *DHCP4) parseAck(ack *dhcpv4.DHCPv4) {
}
if len(ack.DNS()) > 0 {
convertIP := func(ip net.IP) netaddr.IP {
result, _ := netaddr.FromStdIP(ip)
convertIP := func(ip net.IP) netip.Addr {
result, _ := netipx.FromStdIP(ip)
return result
}
@ -285,7 +286,7 @@ func (d *DHCP4) parseAck(ack *dhcpv4.DHCPv4) {
if len(ack.NTPServers()) > 0 {
convertIP := func(ip net.IP) string {
result, _ := netaddr.FromStdIP(ip)
result, _ := netipx.FromStdIP(ip)
return result.String()
}

View File

@ -10,6 +10,7 @@ import (
"errors"
"fmt"
"net"
"net/netip"
"strings"
"sync"
"time"
@ -19,8 +20,8 @@ import (
"github.com/jsimonetti/rtnetlink"
"github.com/talos-systems/go-retry/retry"
"go.uber.org/zap"
"go4.org/netipx"
"golang.org/x/sys/unix"
"inet.af/netaddr"
"github.com/talos-systems/talos/pkg/machinery/generic/slices"
"github.com/talos-systems/talos/pkg/machinery/nethelpers"
@ -151,7 +152,7 @@ func (d *DHCP6) parseReply(reply *dhcpv6.Message) (leaseTime time.Duration) {
defer d.mu.Unlock()
if reply.Options.OneIANA() != nil && reply.Options.OneIANA().Options.OneAddress() != nil {
addr, _ := netaddr.FromStdIPNet(&net.IPNet{
addr, _ := netipx.FromStdIPNet(&net.IPNet{
IP: reply.Options.OneIANA().Options.OneAddress().IPv6Addr,
Mask: net.CIDRMask(128, 128),
})
@ -173,8 +174,8 @@ func (d *DHCP6) parseReply(reply *dhcpv6.Message) (leaseTime time.Duration) {
}
if len(reply.Options.DNS()) > 0 {
convertIP := func(ip net.IP) netaddr.IP {
result, _ := netaddr.FromStdIP(ip)
convertIP := func(ip net.IP) netip.Addr {
result, _ := netipx.FromStdIP(ip)
return result
}
@ -203,7 +204,7 @@ func (d *DHCP6) parseReply(reply *dhcpv6.Message) (leaseTime time.Duration) {
if len(reply.Options.NTPServers()) > 0 {
convertIP := func(ip net.IP) string {
result, _ := netaddr.FromStdIP(ip)
result, _ := netipx.FromStdIP(ip)
return result.String()
}

View File

@ -8,6 +8,7 @@ import (
"context"
"errors"
"fmt"
"net/netip"
"os"
"strings"
"sync"
@ -17,7 +18,6 @@ import (
"github.com/cosi-project/runtime/pkg/state"
"go.etcd.io/etcd/client/v3/concurrency"
"go.uber.org/zap"
"inet.af/netaddr"
"github.com/talos-systems/talos/internal/app/machined/pkg/controllers/network/operator/vip"
"github.com/talos-systems/talos/internal/pkg/etcd"
@ -35,7 +35,7 @@ type VIP struct {
logger *zap.Logger
linkName string
sharedIP netaddr.IP
sharedIP netip.Addr
gratuitousARP bool
state state.State
@ -111,7 +111,7 @@ func (vip *VIP) AddressSpecs() []network.AddressSpecSpec {
return []network.AddressSpecSpec{
{
Address: netaddr.IPPrefixFrom(vip.sharedIP, vip.sharedIP.BitLen()),
Address: netip.PrefixFrom(vip.sharedIP, vip.sharedIP.BitLen()),
LinkName: vip.linkName,
Family: family,
Scope: nethelpers.ScopeGlobal,

View File

@ -8,11 +8,11 @@ import (
"context"
"fmt"
"net"
"net/netip"
"strconv"
"github.com/hetznercloud/hcloud-go/hcloud"
"go.uber.org/zap"
"inet.af/netaddr"
"github.com/talos-systems/talos/pkg/download"
"github.com/talos-systems/talos/pkg/machinery/resources/network"
@ -155,7 +155,7 @@ func (handler *HCloudHandler) Release(ctx context.Context) error {
const HCloudMetaDataEndpoint = "http://169.254.169.254/hetzner/v1/metadata/instance-id"
// GetNetworkAndDeviceIDs fills in parts of the spec based on the API token and instance metadata.
func GetNetworkAndDeviceIDs(ctx context.Context, spec *network.VIPHCloudSpec, vip netaddr.IP) error {
func GetNetworkAndDeviceIDs(ctx context.Context, spec *network.VIPHCloudSpec, vip netip.Addr) error {
metadataInstanceID, err := download.Download(ctx, HCloudMetaDataEndpoint)
if err != nil {
return fmt.Errorf("error downloading instance-id: %w", err)
@ -181,7 +181,7 @@ func GetNetworkAndDeviceIDs(ctx context.Context, spec *network.VIPHCloudSpec, vi
return fmt.Errorf("error getting network info: %w", err)
}
if network.IPRange.Contains(vip.IPAddr().IP) {
if network.IPRange.Contains(vip.AsSlice()) {
spec.NetworkID = privnet.Network.ID
break

View File

@ -8,6 +8,7 @@ import (
"context"
"fmt"
"log"
"net/netip"
"sync"
"testing"
"time"
@ -20,7 +21,6 @@ import (
"github.com/stretchr/testify/suite"
"github.com/talos-systems/go-retry/retry"
"go.uber.org/zap"
"inet.af/netaddr"
netctrl "github.com/talos-systems/talos/internal/app/machined/pkg/controllers/network"
"github.com/talos-systems/talos/internal/app/machined/pkg/controllers/network/operator"
@ -254,7 +254,7 @@ func (suite *OperatorSpecSuite) TestScheduling() {
LinkName: "eth0",
RequireUp: false,
VIP: network.VIPOperatorSpec{
IP: netaddr.MustParseIP("1.2.3.4"),
IP: netip.MustParseAddr("1.2.3.4"),
},
}
@ -287,7 +287,7 @@ func (suite *OperatorSpecSuite) TestScheduling() {
func() error {
return suite.assertRunning(
[]string{"vip/eth0"}, func(op *mockOperator) error {
suite.Assert().Equal(netaddr.MustParseIP("1.2.3.4"), op.spec.VIP.IP)
suite.Assert().Equal(netip.MustParseAddr("1.2.3.4"), op.spec.VIP.IP)
return nil
},
@ -315,7 +315,7 @@ func (suite *OperatorSpecSuite) TestScheduling() {
case network.OperatorDHCP4:
suite.Assert().EqualValues(1024, op.spec.DHCP4.RouteMetric)
case network.OperatorVIP:
suite.Assert().Equal(netaddr.MustParseIP("1.2.3.4"), op.spec.VIP.IP)
suite.Assert().Equal(netip.MustParseAddr("1.2.3.4"), op.spec.VIP.IP)
default:
panic("unreachable")
}
@ -330,7 +330,7 @@ func (suite *OperatorSpecSuite) TestScheduling() {
// change the spec, operator should be rescheduled
_, err = suite.state.UpdateWithConflicts(
suite.ctx, specVIP.Metadata(), func(r resource.Resource) error {
r.(*network.OperatorSpec).TypedSpec().VIP.IP = netaddr.MustParseIP("3.4.5.6")
r.(*network.OperatorSpec).TypedSpec().VIP.IP = netip.MustParseAddr("3.4.5.6")
return nil
},
@ -346,7 +346,7 @@ func (suite *OperatorSpecSuite) TestScheduling() {
case network.OperatorDHCP4:
suite.Assert().EqualValues(1024, op.spec.DHCP4.RouteMetric)
case network.OperatorVIP:
if op.spec.VIP.IP.Compare(netaddr.MustParseIP("3.4.5.6")) != 0 {
if op.spec.VIP.IP.Compare(netip.MustParseAddr("3.4.5.6")) != 0 {
return retry.ExpectedErrorf("unexpected vip: %s", op.spec.VIP.IP)
}
default:
@ -475,7 +475,7 @@ func (suite *OperatorSpecSuite) TestOperatorOutputs() {
dhcpMock.mu.Lock()
dhcpMock.addresses = []network.AddressSpecSpec{
{
Address: netaddr.MustParseIPPrefix("10.5.0.2/24"),
Address: netip.MustParsePrefix("10.5.0.2/24"),
LinkName: "eth0",
Family: nethelpers.FamilyInet4,
Scope: nethelpers.ScopeGlobal,
@ -526,7 +526,7 @@ func (suite *OperatorSpecSuite) TestOperatorOutputs() {
dhcpMock.mu.Lock()
dhcpMock.addresses = []network.AddressSpecSpec{
{
Address: netaddr.MustParseIPPrefix("10.5.0.3/24"),
Address: netip.MustParsePrefix("10.5.0.3/24"),
LinkName: "eth0",
Family: nethelpers.FamilyInet4,
Scope: nethelpers.ScopeGlobal,

View File

@ -7,6 +7,7 @@ package network
import (
"context"
"fmt"
"net/netip"
"github.com/cosi-project/runtime/pkg/controller"
"github.com/cosi-project/runtime/pkg/resource"
@ -14,7 +15,6 @@ import (
"github.com/hashicorp/go-multierror"
"github.com/talos-systems/go-procfs/procfs"
"go.uber.org/zap"
"inet.af/netaddr"
"github.com/talos-systems/talos/internal/app/machined/pkg/controllers/network/operator/vip"
talosconfig "github.com/talos-systems/talos/pkg/machinery/config"
@ -193,9 +193,9 @@ func (ctrl *OperatorVIPConfigController) apply(ctx context.Context, r controller
}
func handleVIP(ctx context.Context, vlanConfig talosconfig.VIPConfig, deviceName string, logger *zap.Logger) (network.OperatorSpecSpec, error) {
var sharedIP netaddr.IP
var sharedIP netip.Addr
sharedIP, err := netaddr.ParseIP(vlanConfig.IP())
sharedIP, err := netip.ParseAddr(vlanConfig.IP())
if err != nil {
logger.Warn("ignoring vip parse failure", zap.Error(err), zap.String("link", deviceName))

View File

@ -9,6 +9,7 @@ import (
"context"
"fmt"
"log"
"net/netip"
"net/url"
"sync"
"testing"
@ -22,7 +23,6 @@ import (
"github.com/siderolabs/go-pointer"
"github.com/stretchr/testify/suite"
"github.com/talos-systems/go-retry/retry"
"inet.af/netaddr"
netctrl "github.com/talos-systems/talos/internal/app/machined/pkg/controllers/network"
"github.com/talos-systems/talos/pkg/logging"
@ -174,16 +174,16 @@ func (suite *OperatorVIPConfigSuite) TestMachineConfigurationVIP() {
switch r.Metadata().ID() {
case "configuration/vip/eth1":
suite.Assert().Equal("eth1", r.TypedSpec().LinkName)
suite.Assert().EqualValues(netaddr.MustParseIP("2.3.4.5"), r.TypedSpec().VIP.IP)
suite.Assert().EqualValues(netip.MustParseAddr("2.3.4.5"), r.TypedSpec().VIP.IP)
case "configuration/vip/eth2":
suite.Assert().Equal("eth2", r.TypedSpec().LinkName)
suite.Assert().EqualValues(
netaddr.MustParseIP("fd7a:115c:a1e0:ab12:4843:cd96:6277:2302"),
netip.MustParseAddr("fd7a:115c:a1e0:ab12:4843:cd96:6277:2302"),
r.TypedSpec().VIP.IP,
)
case "configuration/vip/eth3.26":
suite.Assert().Equal("eth3.26", r.TypedSpec().LinkName)
suite.Assert().EqualValues(netaddr.MustParseIP("5.5.4.4"), r.TypedSpec().VIP.IP)
suite.Assert().EqualValues(netip.MustParseAddr("5.5.4.4"), r.TypedSpec().VIP.IP)
}
return nil

View File

@ -8,6 +8,7 @@ import (
"bytes"
"context"
"fmt"
"net/netip"
"os"
"path/filepath"
"sync"
@ -20,7 +21,6 @@ import (
"github.com/siderolabs/go-pointer"
"go.uber.org/zap"
"gopkg.in/yaml.v3"
"inet.af/netaddr"
v1alpha1runtime "github.com/talos-systems/talos/internal/app/machined/pkg/runtime"
"github.com/talos-systems/talos/pkg/machinery/constants"
@ -381,8 +381,8 @@ func (ctrl *PlatformConfigController) apply(ctx context.Context, r controller.Ru
return networkConfig.ExternalIPs[i]
},
idBuilder: func(spec interface{}) resource.ID {
ipAddr := spec.(netaddr.IP) //nolint:errcheck,forcetypeassert
ipPrefix := netaddr.IPPrefixFrom(ipAddr, ipAddr.BitLen())
ipAddr := spec.(netip.Addr) //nolint:errcheck,forcetypeassert
ipPrefix := netip.PrefixFrom(ipAddr, ipAddr.BitLen())
return network.AddressID(externalLink, ipPrefix)
},
@ -391,8 +391,8 @@ func (ctrl *PlatformConfigController) apply(ctx context.Context, r controller.Ru
},
resourceModifier: func(newSpec interface{}) func(r resource.Resource) error {
return func(r resource.Resource) error {
ipAddr := newSpec.(netaddr.IP) //nolint:errcheck,forcetypeassert
ipPrefix := netaddr.IPPrefixFrom(ipAddr, ipAddr.BitLen())
ipAddr := newSpec.(netip.Addr) //nolint:errcheck,forcetypeassert
ipPrefix := netip.PrefixFrom(ipAddr, ipAddr.BitLen())
status := r.(*network.AddressStatus).TypedSpec()

View File

@ -9,6 +9,7 @@ import (
"context"
"fmt"
"log"
"net/netip"
"os"
"path/filepath"
"sync"
@ -23,7 +24,6 @@ import (
"github.com/stretchr/testify/suite"
"github.com/talos-systems/go-procfs/procfs"
"github.com/talos-systems/go-retry/retry"
"inet.af/netaddr"
netctrl "github.com/talos-systems/talos/internal/app/machined/pkg/controllers/network"
v1alpha1runtime "github.com/talos-systems/talos/internal/app/machined/pkg/runtime"
@ -212,9 +212,9 @@ func (suite *PlatformConfigSuite) TestPlatformMockAddresses() {
suite.runtime.RegisterController(
&netctrl.PlatformConfigController{
V1alpha1Platform: &platformMock{
addresses: []netaddr.IPPrefix{
netaddr.MustParseIPPrefix("192.168.1.24/24"),
netaddr.MustParseIPPrefix("2001:fd::3/64"),
addresses: []netip.Prefix{
netip.MustParsePrefix("192.168.1.24/24"),
netip.MustParsePrefix("2001:fd::3/64"),
},
},
StatePath: suite.statePath,
@ -293,7 +293,7 @@ func (suite *PlatformConfigSuite) TestPlatformMockRoutes() {
suite.runtime.RegisterController(
&netctrl.PlatformConfigController{
V1alpha1Platform: &platformMock{
defaultRoutes: []netaddr.IP{netaddr.MustParseIP("10.0.0.1")},
defaultRoutes: []netip.Addr{netip.MustParseAddr("10.0.0.1")},
},
StatePath: suite.statePath,
},
@ -362,7 +362,7 @@ func (suite *PlatformConfigSuite) TestPlatformMockResolvers() {
suite.runtime.RegisterController(
&netctrl.PlatformConfigController{
V1alpha1Platform: &platformMock{
resolvers: []netaddr.IP{netaddr.MustParseIP("1.1.1.1")},
resolvers: []netip.Addr{netip.MustParseAddr("1.1.1.1")},
},
StatePath: suite.statePath,
},
@ -430,9 +430,9 @@ func (suite *PlatformConfigSuite) TestPlatformMockExternalIPs() {
suite.runtime.RegisterController(
&netctrl.PlatformConfigController{
V1alpha1Platform: &platformMock{
externalIPs: []netaddr.IP{
netaddr.MustParseIP("10.3.4.5"),
netaddr.MustParseIP("2001:470:6d:30e:96f4:4219:5733:b860"),
externalIPs: []netip.Addr{
netip.MustParseAddr("10.3.4.5"),
netip.MustParseAddr("2001:470:6d:30e:96f4:4219:5733:b860"),
},
},
StatePath: suite.statePath,
@ -477,9 +477,9 @@ func (suite *PlatformConfigSuite) TestStoreConfig() {
&netctrl.PlatformConfigController{
V1alpha1Platform: &platformMock{
hostname: []byte("talos-e2e-897b4e49-gcp-controlplane-jvcnl"),
externalIPs: []netaddr.IP{
netaddr.MustParseIP("10.3.4.5"),
netaddr.MustParseIP("2001:470:6d:30e:96f4:4219:5733:b860"),
externalIPs: []netip.Addr{
netip.MustParseAddr("10.3.4.5"),
netip.MustParseAddr("2001:470:6d:30e:96f4:4219:5733:b860"),
},
},
StatePath: suite.statePath,
@ -603,11 +603,11 @@ type platformMock struct {
noData bool
hostname []byte
externalIPs []netaddr.IP
addresses []netaddr.IPPrefix
defaultRoutes []netaddr.IP
externalIPs []netip.Addr
addresses []netip.Prefix
defaultRoutes []netip.Addr
linksUp []string
resolvers []netaddr.IP
resolvers []netip.Addr
timeServers []string
dhcp4Links []string
}
@ -652,7 +652,7 @@ func (mock *platformMock) NetworkConfiguration(
for _, addr := range mock.addresses {
family := nethelpers.FamilyInet4
if addr.IP().Is6() {
if addr.Addr().Is6() {
family = nethelpers.FamilyInet6
}

View File

@ -7,6 +7,7 @@ package network
import (
"context"
"fmt"
"net/netip"
"github.com/cosi-project/runtime/pkg/controller"
"github.com/cosi-project/runtime/pkg/resource"
@ -14,7 +15,6 @@ import (
"github.com/siderolabs/go-pointer"
"github.com/talos-systems/go-procfs/procfs"
"go.uber.org/zap"
"inet.af/netaddr"
talosconfig "github.com/talos-systems/talos/pkg/machinery/config"
"github.com/talos-systems/talos/pkg/machinery/constants"
@ -157,7 +157,7 @@ func (ctrl *ResolverConfigController) apply(ctx context.Context, r controller.Ru
}
func (ctrl *ResolverConfigController) getDefault() (spec network.ResolverSpecSpec) {
spec.DNSServers = []netaddr.IP{netaddr.MustParseIP(constants.DefaultPrimaryResolver), netaddr.MustParseIP(constants.DefaultSecondaryResolver)}
spec.DNSServers = []netip.Addr{netip.MustParseAddr(constants.DefaultPrimaryResolver), netip.MustParseAddr(constants.DefaultSecondaryResolver)}
spec.ConfigLayer = network.ConfigDefault
return spec
@ -193,7 +193,7 @@ func (ctrl *ResolverConfigController) parseMachineConfiguration(logger *zap.Logg
}
for i := range resolvers {
server, err := netaddr.ParseIP(resolvers[i])
server, err := netip.ParseAddr(resolvers[i])
if err != nil {
logger.Warn("failed to parse DNS server", zap.String("server", resolvers[i]), zap.Error(err))

View File

@ -9,6 +9,7 @@ import (
"context"
"fmt"
"log"
"net/netip"
"net/url"
"sync"
"testing"
@ -22,7 +23,6 @@ import (
"github.com/stretchr/testify/suite"
"github.com/talos-systems/go-procfs/procfs"
"github.com/talos-systems/go-retry/retry"
"inet.af/netaddr"
netctrl "github.com/talos-systems/talos/internal/app/machined/pkg/controllers/network"
"github.com/talos-systems/talos/pkg/logging"
@ -131,9 +131,9 @@ func (suite *ResolverConfigSuite) TestDefaults() {
"default/resolvers",
}, func(r *network.ResolverSpec) error {
suite.Assert().Equal(
[]netaddr.IP{
netaddr.MustParseIP(constants.DefaultPrimaryResolver),
netaddr.MustParseIP(constants.DefaultSecondaryResolver),
[]netip.Addr{
netip.MustParseAddr(constants.DefaultPrimaryResolver),
netip.MustParseAddr(constants.DefaultSecondaryResolver),
}, r.TypedSpec().DNSServers,
)
suite.Assert().Equal(network.ConfigDefault, r.TypedSpec().ConfigLayer)
@ -165,9 +165,9 @@ func (suite *ResolverConfigSuite) TestCmdline() {
"cmdline/resolvers",
}, func(r *network.ResolverSpec) error {
suite.Assert().Equal(
[]netaddr.IP{
netaddr.MustParseIP("10.0.0.1"),
netaddr.MustParseIP("10.0.0.2"),
[]netip.Addr{
netip.MustParseAddr("10.0.0.1"),
netip.MustParseAddr("10.0.0.2"),
}, r.TypedSpec().DNSServers,
)
@ -215,9 +215,9 @@ func (suite *ResolverConfigSuite) TestMachineConfiguration() {
"configuration/resolvers",
}, func(r *network.ResolverSpec) error {
suite.Assert().Equal(
[]netaddr.IP{
netaddr.MustParseIP("2.2.2.2"),
netaddr.MustParseIP("3.3.3.3"),
[]netip.Addr{
netip.MustParseAddr("2.2.2.2"),
netip.MustParseAddr("3.3.3.3"),
}, r.TypedSpec().DNSServers,
)

View File

@ -9,6 +9,7 @@ import (
"context"
"fmt"
"log"
"net/netip"
"reflect"
"sync"
"testing"
@ -21,7 +22,6 @@ import (
"github.com/cosi-project/runtime/pkg/state/impl/namespaced"
"github.com/stretchr/testify/suite"
"github.com/talos-systems/go-retry/retry"
"inet.af/netaddr"
netctrl "github.com/talos-systems/talos/internal/app/machined/pkg/controllers/network"
"github.com/talos-systems/talos/pkg/logging"
@ -104,28 +104,28 @@ func (suite *ResolverMergeSuite) assertResolvers(requiredIDs []string, check fun
func (suite *ResolverMergeSuite) TestMerge() {
def := network.NewResolverSpec(network.ConfigNamespaceName, "default/resolvers")
*def.TypedSpec() = network.ResolverSpecSpec{
DNSServers: []netaddr.IP{
netaddr.MustParseIP(constants.DefaultPrimaryResolver),
netaddr.MustParseIP(constants.DefaultSecondaryResolver),
DNSServers: []netip.Addr{
netip.MustParseAddr(constants.DefaultPrimaryResolver),
netip.MustParseAddr(constants.DefaultSecondaryResolver),
},
ConfigLayer: network.ConfigDefault,
}
dhcp1 := network.NewResolverSpec(network.ConfigNamespaceName, "dhcp/eth0")
*dhcp1.TypedSpec() = network.ResolverSpecSpec{
DNSServers: []netaddr.IP{netaddr.MustParseIP("1.1.2.0")},
DNSServers: []netip.Addr{netip.MustParseAddr("1.1.2.0")},
ConfigLayer: network.ConfigOperator,
}
dhcp2 := network.NewResolverSpec(network.ConfigNamespaceName, "dhcp/eth1")
*dhcp2.TypedSpec() = network.ResolverSpecSpec{
DNSServers: []netaddr.IP{netaddr.MustParseIP("1.1.2.1")},
DNSServers: []netip.Addr{netip.MustParseAddr("1.1.2.1")},
ConfigLayer: network.ConfigOperator,
}
static := network.NewResolverSpec(network.ConfigNamespaceName, "configuration/resolvers")
*static.TypedSpec() = network.ResolverSpecSpec{
DNSServers: []netaddr.IP{netaddr.MustParseIP("2.2.2.2")},
DNSServers: []netip.Addr{netip.MustParseAddr("2.2.2.2")},
ConfigLayer: network.ConfigMachineConfiguration,
}
@ -160,7 +160,7 @@ func (suite *ResolverMergeSuite) TestMerge() {
}, func(r *network.ResolverSpec) error {
if !reflect.DeepEqual(
r.TypedSpec().DNSServers,
[]netaddr.IP{netaddr.MustParseIP("1.1.2.0"), netaddr.MustParseIP("1.1.2.1")},
[]netip.Addr{netip.MustParseAddr("1.1.2.0"), netip.MustParseAddr("1.1.2.1")},
) {
return retry.ExpectedErrorf("unexpected servers %q", r.TypedSpec().DNSServers)
}

View File

@ -7,12 +7,12 @@ package network
import (
"context"
"fmt"
"net/netip"
"github.com/cosi-project/runtime/pkg/controller"
"github.com/cosi-project/runtime/pkg/resource"
"github.com/cosi-project/runtime/pkg/state"
"go.uber.org/zap"
"inet.af/netaddr"
"github.com/talos-systems/talos/pkg/machinery/generic/slices"
"github.com/talos-systems/talos/pkg/machinery/resources/network"
@ -89,7 +89,7 @@ func (ctrl *ResolverSpecController) Run(ctx context.Context, r controller.Runtim
return fmt.Errorf("error removing finalizer: %w", err)
}
case resource.PhaseRunning:
resolvers := slices.Map(spec.TypedSpec().DNSServers, netaddr.IP.String)
resolvers := slices.Map(spec.TypedSpec().DNSServers, netip.Addr.String)
logger.Info("setting resolvers", zap.Strings("resolvers", resolvers))
if err = r.Modify(ctx, network.NewResolverStatus(network.NamespaceName, spec.Metadata().ID()), func(r resource.Resource) error {

View File

@ -8,6 +8,7 @@ package network_test
import (
"context"
"log"
"net/netip"
"reflect"
"sync"
"testing"
@ -20,7 +21,6 @@ import (
"github.com/cosi-project/runtime/pkg/state/impl/namespaced"
"github.com/stretchr/testify/suite"
"github.com/talos-systems/go-retry/retry"
"inet.af/netaddr"
netctrl "github.com/talos-systems/talos/internal/app/machined/pkg/controllers/network"
"github.com/talos-systems/talos/pkg/logging"
@ -65,7 +65,7 @@ func (suite *ResolverSpecSuite) startRuntime() {
}()
}
func (suite *ResolverSpecSuite) assertStatus(id string, servers ...netaddr.IP) error {
func (suite *ResolverSpecSuite) assertStatus(id string, servers ...netip.Addr) error {
r, err := suite.state.Get(
suite.ctx,
resource.NewMetadata(network.NamespaceName, network.ResolverStatusType, id, resource.VersionUndefined),
@ -90,7 +90,7 @@ func (suite *ResolverSpecSuite) assertStatus(id string, servers ...netaddr.IP) e
func (suite *ResolverSpecSuite) TestSpec() {
spec := network.NewResolverSpec(network.NamespaceName, "resolvers")
*spec.TypedSpec() = network.ResolverSpecSpec{
DNSServers: []netaddr.IP{netaddr.MustParseIP(constants.DefaultPrimaryResolver)},
DNSServers: []netip.Addr{netip.MustParseAddr(constants.DefaultPrimaryResolver)},
ConfigLayer: network.ConfigDefault,
}
@ -101,7 +101,7 @@ func (suite *ResolverSpecSuite) TestSpec() {
suite.Assert().NoError(
retry.Constant(3*time.Second, retry.WithUnits(100*time.Millisecond)).Retry(
func() error {
return suite.assertStatus("resolvers", netaddr.MustParseIP(constants.DefaultPrimaryResolver))
return suite.assertStatus("resolvers", netip.MustParseAddr(constants.DefaultPrimaryResolver))
},
),
)

View File

@ -7,15 +7,16 @@ package network
import (
"context"
"fmt"
"net/netip"
"github.com/cosi-project/runtime/pkg/controller"
"github.com/cosi-project/runtime/pkg/resource"
"github.com/cosi-project/runtime/pkg/state"
"github.com/talos-systems/go-procfs/procfs"
"go.uber.org/zap"
"inet.af/netaddr"
talosconfig "github.com/talos-systems/talos/pkg/machinery/config"
"github.com/talos-systems/talos/pkg/machinery/generic"
"github.com/talos-systems/talos/pkg/machinery/nethelpers"
"github.com/talos-systems/talos/pkg/machinery/resources/network"
)
@ -95,7 +96,7 @@ func (ctrl *RouteConfigController) Run(ctx context.Context, r controller.Runtime
// parse kernel cmdline for the default gateway
cmdlineRoute := ctrl.parseCmdline(logger)
if !cmdlineRoute.Gateway.IsZero() {
if !generic.IsZero(cmdlineRoute.Gateway) {
if _, ignored := ignoredInterfaces[cmdlineRoute.OutLinkName]; !ignored {
var ids []string
@ -184,7 +185,7 @@ func (ctrl *RouteConfigController) parseCmdline(logger *zap.Logger) (route netwo
return
}
if settings.Gateway.IsZero() {
if generic.IsZero(settings.Gateway) {
return
}
@ -213,21 +214,21 @@ func (ctrl *RouteConfigController) parseCmdline(logger *zap.Logger) (route netwo
func (ctrl *RouteConfigController) processDevicesConfiguration(logger *zap.Logger, devices []talosconfig.Device) (routes []network.RouteSpecSpec) {
convert := func(linkName string, in talosconfig.Route) (route network.RouteSpecSpec, err error) {
if in.Network() != "" {
route.Destination, err = netaddr.ParseIPPrefix(in.Network())
route.Destination, err = netip.ParsePrefix(in.Network())
if err != nil {
return route, fmt.Errorf("error parsing route network: %w", err)
}
}
if in.Gateway() != "" {
route.Gateway, err = netaddr.ParseIP(in.Gateway())
route.Gateway, err = netip.ParseAddr(in.Gateway())
if err != nil {
return route, fmt.Errorf("error parsing route gateway: %w", err)
}
}
if in.Source() != "" {
route.Source, err = netaddr.ParseIP(in.Source())
route.Source, err = netip.ParseAddr(in.Source())
if err != nil {
return route, fmt.Errorf("error parsing route source: %w", err)
}
@ -241,9 +242,9 @@ func (ctrl *RouteConfigController) processDevicesConfiguration(logger *zap.Logge
}
switch {
case !route.Gateway.IsZero() && route.Gateway.Is6():
case !generic.IsZero(route.Gateway) && route.Gateway.Is6():
route.Family = nethelpers.FamilyInet6
case !route.Destination.IsZero() && route.Destination.IP().Is6():
case !generic.IsZero(route.Destination) && route.Destination.Addr().Is6():
route.Family = nethelpers.FamilyInet6
default:
route.Family = nethelpers.FamilyInet4
@ -256,7 +257,7 @@ func (ctrl *RouteConfigController) processDevicesConfiguration(logger *zap.Logge
route.Type = nethelpers.TypeUnicast
if route.Destination.IP().IsMulticast() {
if route.Destination.Addr().IsMulticast() {
route.Type = nethelpers.TypeMulticast
}

View File

@ -9,6 +9,7 @@ import (
"context"
"fmt"
"log"
"net/netip"
"net/url"
"sync"
"testing"
@ -23,7 +24,6 @@ import (
"github.com/stretchr/testify/suite"
"github.com/talos-systems/go-procfs/procfs"
"github.com/talos-systems/go-retry/retry"
"inet.af/netaddr"
netctrl "github.com/talos-systems/talos/internal/app/machined/pkg/controllers/network"
"github.com/talos-systems/talos/pkg/logging"
@ -253,7 +253,7 @@ func (suite *RouteConfigSuite) TestMachineConfiguration() {
suite.Assert().Equal("eth1", r.TypedSpec().OutLinkName)
suite.Assert().Equal(nethelpers.FamilyInet4, r.TypedSpec().Family)
suite.Assert().EqualValues(netctrl.DefaultRouteMetric, r.TypedSpec().Priority)
suite.Assert().EqualValues(netaddr.MustParseIP("192.244.0.10"), r.TypedSpec().Source)
suite.Assert().EqualValues(netip.MustParseAddr("192.244.0.10"), r.TypedSpec().Source)
case "configuration/inet4//169.254.254.254/32/1024":
suite.Assert().Equal("eth3", r.TypedSpec().OutLinkName)
suite.Assert().Equal(nethelpers.FamilyInet4, r.TypedSpec().Family)

View File

@ -9,6 +9,7 @@ import (
"context"
"fmt"
"log"
"net/netip"
"sync"
"testing"
"time"
@ -21,7 +22,6 @@ import (
"github.com/stretchr/testify/suite"
"github.com/talos-systems/go-retry/retry"
"golang.org/x/sync/errgroup"
"inet.af/netaddr"
netctrl "github.com/talos-systems/talos/internal/app/machined/pkg/controllers/network"
"github.com/talos-systems/talos/pkg/logging"
@ -122,7 +122,7 @@ func (suite *RouteMergeSuite) assertNoRoute(id string) error {
func (suite *RouteMergeSuite) TestMerge() {
cmdline := network.NewRouteSpec(network.ConfigNamespaceName, "cmdline/inet4//10.5.0.3/50")
*cmdline.TypedSpec() = network.RouteSpecSpec{
Gateway: netaddr.MustParseIP("10.5.0.3"),
Gateway: netip.MustParseAddr("10.5.0.3"),
OutLinkName: "eth0",
Family: nethelpers.FamilyInet4,
Scope: nethelpers.ScopeGlobal,
@ -134,7 +134,7 @@ func (suite *RouteMergeSuite) TestMerge() {
dhcp := network.NewRouteSpec(network.ConfigNamespaceName, "dhcp/inet4//10.5.0.3/50")
*dhcp.TypedSpec() = network.RouteSpecSpec{
Gateway: netaddr.MustParseIP("10.5.0.3"),
Gateway: netip.MustParseAddr("10.5.0.3"),
OutLinkName: "eth0",
Family: nethelpers.FamilyInet4,
Scope: nethelpers.ScopeGlobal,
@ -146,8 +146,8 @@ func (suite *RouteMergeSuite) TestMerge() {
static := network.NewRouteSpec(network.ConfigNamespaceName, "configuration/inet4/10.0.0.35/32/10.0.0.34/1024")
*static.TypedSpec() = network.RouteSpecSpec{
Destination: netaddr.MustParseIPPrefix("10.0.0.35/32"),
Gateway: netaddr.MustParseIP("10.0.0.34"),
Destination: netip.MustParsePrefix("10.0.0.35/32"),
Gateway: netip.MustParseAddr("10.0.0.34"),
OutLinkName: "eth0",
Family: nethelpers.FamilyInet4,
Scope: nethelpers.ScopeGlobal,
@ -230,7 +230,7 @@ func (suite *RouteMergeSuite) TestMergeFlapping() {
// simulate two conflicting default route definitions which are getting removed/added constantly
cmdline := network.NewRouteSpec(network.ConfigNamespaceName, "cmdline/inet4//10.5.0.3/50")
*cmdline.TypedSpec() = network.RouteSpecSpec{
Gateway: netaddr.MustParseIP("10.5.0.3"),
Gateway: netip.MustParseAddr("10.5.0.3"),
OutLinkName: "eth0",
Family: nethelpers.FamilyInet4,
Scope: nethelpers.ScopeGlobal,
@ -242,7 +242,7 @@ func (suite *RouteMergeSuite) TestMergeFlapping() {
dhcp := network.NewRouteSpec(network.ConfigNamespaceName, "dhcp/inet4//10.5.0.3/50")
*dhcp.TypedSpec() = network.RouteSpecSpec{
Gateway: netaddr.MustParseIP("10.5.0.3"),
Gateway: netip.MustParseAddr("10.5.0.3"),
OutLinkName: "eth1",
Family: nethelpers.FamilyInet4,
Scope: nethelpers.ScopeGlobal,

View File

@ -7,6 +7,7 @@ package network
import (
"context"
"fmt"
"net/netip"
"github.com/cosi-project/runtime/pkg/controller"
"github.com/cosi-project/runtime/pkg/resource"
@ -14,9 +15,9 @@ import (
"github.com/jsimonetti/rtnetlink"
"go.uber.org/zap"
"golang.org/x/sys/unix"
"inet.af/netaddr"
"github.com/talos-systems/talos/internal/app/machined/pkg/controllers/network/watch"
"github.com/talos-systems/talos/pkg/machinery/generic"
"github.com/talos-systems/talos/pkg/machinery/nethelpers"
"github.com/talos-systems/talos/pkg/machinery/resources/network"
)
@ -117,7 +118,7 @@ func (ctrl *RouteSpecController) Run(ctx context.Context, r controller.Runtime,
}
}
func findRoutes(routes []rtnetlink.RouteMessage, family nethelpers.Family, destination netaddr.IPPrefix, gateway netaddr.IP, table nethelpers.RoutingTable) []*rtnetlink.RouteMessage {
func findRoutes(routes []rtnetlink.RouteMessage, family nethelpers.Family, destination netip.Prefix, gateway netip.Addr, table nethelpers.RoutingTable) []*rtnetlink.RouteMessage {
var result []*rtnetlink.RouteMessage //nolint:prealloc
for i, route := range routes {
@ -125,15 +126,15 @@ func findRoutes(routes []rtnetlink.RouteMessage, family nethelpers.Family, desti
continue
}
if route.DstLength != destination.Bits() {
if int(route.DstLength) != destination.Bits() {
continue
}
if !route.Attributes.Dst.Equal(destination.IP().IPAddr().IP) {
if !route.Attributes.Dst.Equal(destination.Addr().AsSlice()) {
continue
}
if !route.Attributes.Gateway.Equal(gateway.IPAddr().IP) {
if !route.Attributes.Gateway.Equal(gateway.AsSlice()) {
continue
}
@ -154,17 +155,17 @@ func (ctrl *RouteSpecController) syncRoute(ctx context.Context, r controller.Run
linkIndex := resolveLinkName(links, route.TypedSpec().OutLinkName)
destinationStr := route.TypedSpec().Destination.String()
if route.TypedSpec().Destination.IsZero() {
if generic.IsZero(route.TypedSpec().Destination) {
destinationStr = "default"
}
sourceStr := route.TypedSpec().Source.String()
if route.TypedSpec().Source.IsZero() {
if generic.IsZero(route.TypedSpec().Source) {
sourceStr = ""
}
gatewayStr := route.TypedSpec().Gateway.String()
if route.TypedSpec().Gateway.IsZero() {
if generic.IsZero(route.TypedSpec().Gateway) {
gatewayStr = ""
}
@ -201,8 +202,8 @@ func (ctrl *RouteSpecController) syncRoute(ctx context.Context, r controller.Run
if existing.Scope == uint8(route.TypedSpec().Scope) && nethelpers.RouteFlags(existing.Flags).Equal(route.TypedSpec().Flags) &&
existing.Protocol == uint8(route.TypedSpec().Protocol) &&
existing.Attributes.OutIface == linkIndex && existing.Attributes.Priority == route.TypedSpec().Priority &&
(route.TypedSpec().Source.IsZero() ||
existing.Attributes.Src.Equal(route.TypedSpec().Source.IPAddr().IP)) {
(generic.IsZero(route.TypedSpec().Source) ||
existing.Attributes.Src.Equal(route.TypedSpec().Source.AsSlice())) {
matchFound = true
continue
@ -240,16 +241,16 @@ func (ctrl *RouteSpecController) syncRoute(ctx context.Context, r controller.Run
// add route
msg := &rtnetlink.RouteMessage{
Family: uint8(route.TypedSpec().Family),
DstLength: route.TypedSpec().Destination.Bits(),
DstLength: uint8(route.TypedSpec().Destination.Bits()),
SrcLength: 0,
Protocol: uint8(route.TypedSpec().Protocol),
Scope: uint8(route.TypedSpec().Scope),
Type: uint8(route.TypedSpec().Type),
Flags: uint32(route.TypedSpec().Flags),
Attributes: rtnetlink.RouteAttributes{
Dst: route.TypedSpec().Destination.IP().IPAddr().IP,
Src: route.TypedSpec().Source.IPAddr().IP,
Gateway: route.TypedSpec().Gateway.IPAddr().IP,
Dst: route.TypedSpec().Destination.Addr().AsSlice(),
Src: route.TypedSpec().Source.AsSlice(),
Gateway: route.TypedSpec().Gateway.AsSlice(),
OutIface: linkIndex,
Priority: route.TypedSpec().Priority,
Table: uint32(route.TypedSpec().Table),

View File

@ -11,6 +11,7 @@ import (
"log"
"math/rand"
"net"
"net/netip"
"sync"
"testing"
"time"
@ -24,7 +25,6 @@ import (
"github.com/stretchr/testify/suite"
"github.com/talos-systems/go-retry/retry"
"golang.org/x/sys/unix"
"inet.af/netaddr"
netctrl "github.com/talos-systems/talos/internal/app/machined/pkg/controllers/network"
"github.com/talos-systems/talos/pkg/logging"
@ -76,8 +76,8 @@ func (suite *RouteSpecSuite) startRuntime() {
}
func (suite *RouteSpecSuite) assertRoute(
destination netaddr.IPPrefix,
gateway netaddr.IP,
destination netip.Prefix,
gateway netip.Addr,
check func(rtnetlink.RouteMessage) error,
) error {
conn, err := rtnetlink.Dial(nil)
@ -91,15 +91,15 @@ func (suite *RouteSpecSuite) assertRoute(
matching := 0
for _, route := range routes {
if !gateway.IPAddr().IP.Equal(route.Attributes.Gateway) {
if !route.Attributes.Gateway.Equal(gateway.AsSlice()) {
continue
}
if route.DstLength != destination.Bits() {
if int(route.DstLength) != destination.Bits() {
continue
}
if !destination.IP().IPAddr().IP.Equal(route.Attributes.Dst) {
if !route.Attributes.Dst.Equal(destination.Addr().AsSlice()) {
continue
}
@ -120,7 +120,7 @@ func (suite *RouteSpecSuite) assertRoute(
}
}
func (suite *RouteSpecSuite) assertNoRoute(destination netaddr.IPPrefix, gateway netaddr.IP) error {
func (suite *RouteSpecSuite) assertNoRoute(destination netip.Prefix, gateway netip.Addr) error {
conn, err := rtnetlink.Dial(nil)
suite.Require().NoError(err)
@ -130,7 +130,7 @@ func (suite *RouteSpecSuite) assertNoRoute(destination netaddr.IPPrefix, gateway
suite.Require().NoError(err)
for _, route := range routes {
if gateway.IPAddr().IP.Equal(route.Attributes.Gateway) && destination.Bits() == route.DstLength && destination.IP().IPAddr().IP.Equal(route.Attributes.Dst) {
if route.Attributes.Gateway.Equal(gateway.AsSlice()) && destination.Bits() == int(route.DstLength) && route.Attributes.Dst.Equal(destination.Addr().AsSlice()) {
return retry.ExpectedError(fmt.Errorf("route to %s via %s is present", destination, gateway))
}
}
@ -142,8 +142,8 @@ func (suite *RouteSpecSuite) TestLoopback() {
loopback := network.NewRouteSpec(network.NamespaceName, "loopback")
*loopback.TypedSpec() = network.RouteSpecSpec{
Family: nethelpers.FamilyInet4,
Destination: netaddr.MustParseIPPrefix("127.0.11.0/24"),
Gateway: netaddr.MustParseIP("127.0.11.1"),
Destination: netip.MustParsePrefix("127.0.11.0/24"),
Gateway: netip.MustParseAddr("127.0.11.1"),
OutLinkName: "lo",
Scope: nethelpers.ScopeGlobal,
Table: nethelpers.TableMain,
@ -160,8 +160,8 @@ func (suite *RouteSpecSuite) TestLoopback() {
retry.Constant(3*time.Second, retry.WithUnits(100*time.Millisecond)).Retry(
func() error {
return suite.assertRoute(
netaddr.MustParseIPPrefix("127.0.11.0/24"),
netaddr.MustParseIP("127.0.11.1"),
netip.MustParsePrefix("127.0.11.0/24"),
netip.MustParseAddr("127.0.11.1"),
func(route rtnetlink.RouteMessage) error {
suite.Assert().EqualValues(0, route.Attributes.Priority)
@ -187,8 +187,8 @@ func (suite *RouteSpecSuite) TestLoopback() {
// torn down address should be removed immediately
suite.Assert().NoError(
suite.assertNoRoute(
netaddr.MustParseIPPrefix("127.0.11.0/24"),
netaddr.MustParseIP("127.0.11.1"),
netip.MustParsePrefix("127.0.11.0/24"),
netip.MustParseAddr("127.0.11.1"),
),
)
@ -200,8 +200,8 @@ func (suite *RouteSpecSuite) TestDefaultRoute() {
def := network.NewRouteSpec(network.NamespaceName, "default")
*def.TypedSpec() = network.RouteSpecSpec{
Family: nethelpers.FamilyInet4,
Destination: netaddr.IPPrefix{},
Gateway: netaddr.MustParseIP("127.0.11.2"),
Destination: netip.Prefix{},
Gateway: netip.MustParseAddr("127.0.11.2"),
Scope: nethelpers.ScopeGlobal,
Table: nethelpers.TableMain,
OutLinkName: "lo",
@ -219,7 +219,7 @@ func (suite *RouteSpecSuite) TestDefaultRoute() {
retry.Constant(3*time.Second, retry.WithUnits(100*time.Millisecond)).Retry(
func() error {
return suite.assertRoute(
netaddr.IPPrefix{}, netaddr.MustParseIP("127.0.11.2"), func(route rtnetlink.RouteMessage) error {
netip.Prefix{}, netip.MustParseAddr("127.0.11.2"), func(route rtnetlink.RouteMessage) error {
suite.Assert().Nil(route.Attributes.Dst)
suite.Assert().EqualValues(1048576, route.Attributes.Priority)
@ -246,7 +246,7 @@ func (suite *RouteSpecSuite) TestDefaultRoute() {
retry.Constant(3*time.Second, retry.WithUnits(100*time.Millisecond)).Retry(
func() error {
return suite.assertRoute(
netaddr.IPPrefix{}, netaddr.MustParseIP("127.0.11.2"), func(route rtnetlink.RouteMessage) error {
netip.Prefix{}, netip.MustParseAddr("127.0.11.2"), func(route rtnetlink.RouteMessage) error {
suite.Assert().Nil(route.Attributes.Dst)
if route.Attributes.Priority != 1048577 {
@ -273,7 +273,7 @@ func (suite *RouteSpecSuite) TestDefaultRoute() {
}
// torn down route should be removed immediately
suite.Assert().NoError(suite.assertNoRoute(netaddr.IPPrefix{}, netaddr.MustParseIP("127.0.11.2")))
suite.Assert().NoError(suite.assertNoRoute(netip.Prefix{}, netip.MustParseAddr("127.0.11.2")))
suite.Require().NoError(suite.state.Destroy(suite.ctx, def.Metadata()))
}
@ -328,9 +328,9 @@ func (suite *RouteSpecSuite) TestDefaultAndInterfaceRoutes() {
def := network.NewRouteSpec(network.NamespaceName, "default")
*def.TypedSpec() = network.RouteSpecSpec{
Family: nethelpers.FamilyInet4,
Destination: netaddr.IPPrefix{},
Gateway: netaddr.MustParseIP("10.28.0.1"),
Source: netaddr.MustParseIP("10.28.0.27"),
Destination: netip.Prefix{},
Gateway: netip.MustParseAddr("10.28.0.1"),
Source: netip.MustParseAddr("10.28.0.27"),
Table: nethelpers.TableMain,
OutLinkName: dummyInterface,
Protocol: nethelpers.ProtocolStatic,
@ -343,9 +343,9 @@ func (suite *RouteSpecSuite) TestDefaultAndInterfaceRoutes() {
host := network.NewRouteSpec(network.NamespaceName, "aninterface")
*host.TypedSpec() = network.RouteSpecSpec{
Family: nethelpers.FamilyInet4,
Destination: netaddr.MustParseIPPrefix("10.28.0.1/32"),
Gateway: netaddr.MustParseIP("0.0.0.0"),
Source: netaddr.MustParseIP("10.28.0.27"),
Destination: netip.MustParsePrefix("10.28.0.1/32"),
Gateway: netip.MustParseAddr("0.0.0.0"),
Source: netip.MustParseAddr("10.28.0.27"),
Table: nethelpers.TableMain,
OutLinkName: dummyInterface,
Protocol: nethelpers.ProtocolStatic,
@ -363,7 +363,7 @@ func (suite *RouteSpecSuite) TestDefaultAndInterfaceRoutes() {
retry.Constant(3*time.Second, retry.WithUnits(100*time.Millisecond)).Retry(
func() error {
if err := suite.assertRoute(
netaddr.IPPrefix{}, netaddr.MustParseIP("10.28.0.1"), func(route rtnetlink.RouteMessage) error {
netip.Prefix{}, netip.MustParseAddr("10.28.0.1"), func(route rtnetlink.RouteMessage) error {
suite.Assert().Nil(route.Attributes.Dst)
suite.Assert().EqualValues(1048576, route.Attributes.Priority)
@ -374,7 +374,7 @@ func (suite *RouteSpecSuite) TestDefaultAndInterfaceRoutes() {
}
return suite.assertRoute(
netaddr.MustParseIPPrefix("10.28.0.1/32"), netaddr.IP{}, func(route rtnetlink.RouteMessage) error {
netip.MustParsePrefix("10.28.0.1/32"), netip.Addr{}, func(route rtnetlink.RouteMessage) error {
suite.Assert().Nil(route.Attributes.Gateway)
suite.Assert().EqualValues(1048576, route.Attributes.Priority)
@ -409,8 +409,8 @@ func (suite *RouteSpecSuite) TestDefaultAndInterfaceRoutes() {
}
// torn down route should be removed immediately
suite.Assert().NoError(suite.assertNoRoute(netaddr.IPPrefix{}, netaddr.MustParseIP("10.28.0.1")))
suite.Assert().NoError(suite.assertNoRoute(netaddr.MustParseIPPrefix("10.28.0.1/32"), netaddr.IP{}))
suite.Assert().NoError(suite.assertNoRoute(netip.Prefix{}, netip.MustParseAddr("10.28.0.1")))
suite.Assert().NoError(suite.assertNoRoute(netip.MustParsePrefix("10.28.0.1/32"), netip.Addr{}))
suite.Require().NoError(suite.state.Destroy(suite.ctx, def.Metadata()))
}
@ -465,9 +465,9 @@ func (suite *RouteSpecSuite) TestLinkLocalRoute() {
ll := network.NewRouteSpec(network.NamespaceName, "ll")
*ll.TypedSpec() = network.RouteSpecSpec{
Family: nethelpers.FamilyInet4,
Destination: netaddr.MustParseIPPrefix("169.254.169.254/32"),
Gateway: netaddr.MustParseIP("10.28.0.1"),
Source: netaddr.MustParseIP("10.28.0.27"),
Destination: netip.MustParsePrefix("169.254.169.254/32"),
Gateway: netip.MustParseAddr("10.28.0.1"),
Source: netip.MustParseAddr("10.28.0.27"),
Table: nethelpers.TableMain,
OutLinkName: dummyInterface,
Protocol: nethelpers.ProtocolStatic,
@ -485,8 +485,8 @@ func (suite *RouteSpecSuite) TestLinkLocalRoute() {
retry.Constant(3*time.Second, retry.WithUnits(100*time.Millisecond)).Retry(
func() error {
return suite.assertRoute(
netaddr.MustParseIPPrefix("169.254.169.254/32"),
netaddr.MustParseIP("10.28.0.1"),
netip.MustParsePrefix("169.254.169.254/32"),
netip.MustParseAddr("10.28.0.1"),
func(route rtnetlink.RouteMessage) error {
suite.Assert().EqualValues(1048576, route.Attributes.Priority)
@ -512,8 +512,8 @@ func (suite *RouteSpecSuite) TestLinkLocalRoute() {
// torn down route should be removed immediately
suite.Assert().NoError(
suite.assertNoRoute(
netaddr.MustParseIPPrefix("169.254.169.254/32"),
netaddr.MustParseIP("10.28.0.1"),
netip.MustParsePrefix("169.254.169.254/32"),
netip.MustParseAddr("10.28.0.1"),
),
)

View File

@ -7,13 +7,14 @@ package network
import (
"context"
"fmt"
"net/netip"
"github.com/cosi-project/runtime/pkg/controller"
"github.com/cosi-project/runtime/pkg/resource"
"github.com/jsimonetti/rtnetlink"
"go.uber.org/zap"
"go4.org/netipx"
"golang.org/x/sys/unix"
"inet.af/netaddr"
"github.com/talos-systems/talos/internal/app/machined/pkg/controllers/network/watch"
"github.com/talos-systems/talos/pkg/machinery/nethelpers"
@ -100,10 +101,10 @@ func (ctrl *RouteStatusController) Run(ctx context.Context, r controller.Runtime
for _, route := range routes {
route := route
dstAddr, _ := netaddr.FromStdIPRaw(route.Attributes.Dst)
dstPrefix := netaddr.IPPrefixFrom(dstAddr, route.DstLength)
srcAddr, _ := netaddr.FromStdIPRaw(route.Attributes.Src)
gatewayAddr, _ := netaddr.FromStdIPRaw(route.Attributes.Gateway)
dstAddr, _ := netipx.FromStdIPRaw(route.Attributes.Dst)
dstPrefix := netip.PrefixFrom(dstAddr, int(route.DstLength))
srcAddr, _ := netipx.FromStdIPRaw(route.Attributes.Src)
gatewayAddr, _ := netipx.FromStdIPRaw(route.Attributes.Gateway)
id := network.RouteID(nethelpers.RoutingTable(route.Table), nethelpers.Family(route.Family), dstPrefix, gatewayAddr, route.Attributes.Priority)
if err = r.Modify(ctx, network.NewRouteStatus(network.NamespaceName, id), func(r resource.Resource) error {

View File

@ -14,6 +14,7 @@ import (
"github.com/siderolabs/go-pointer"
"go.uber.org/zap"
"github.com/talos-systems/talos/pkg/machinery/generic"
"github.com/talos-systems/talos/pkg/machinery/resources/files"
"github.com/talos-systems/talos/pkg/machinery/resources/network"
)
@ -93,7 +94,7 @@ func (ctrl *StatusController) Run(ctx context.Context, r controller.Runtime, log
}
for _, item := range list.Items {
if item.(*network.RouteStatus).TypedSpec().Destination.IsZero() {
if generic.IsZero(item.(*network.RouteStatus).TypedSpec().Destination) {
result.ConnectivityReady = true
break

View File

@ -8,6 +8,7 @@ package network_test
import (
"context"
"log"
"net/netip"
"sync"
"testing"
"time"
@ -19,7 +20,6 @@ import (
"github.com/cosi-project/runtime/pkg/state/impl/namespaced"
"github.com/stretchr/testify/suite"
"github.com/talos-systems/go-retry/retry"
"inet.af/netaddr"
netctrl "github.com/talos-systems/talos/internal/app/machined/pkg/controllers/network"
"github.com/talos-systems/talos/pkg/logging"
@ -96,7 +96,7 @@ func (suite *StatusSuite) TestNone() {
func (suite *StatusSuite) TestAddresses() {
nodeAddress := network.NewNodeAddress(network.NamespaceName, network.NodeAddressCurrentID)
nodeAddress.TypedSpec().Addresses = []netaddr.IPPrefix{netaddr.MustParseIPPrefix("10.0.0.1/24")}
nodeAddress.TypedSpec().Addresses = []netip.Prefix{netip.MustParsePrefix("10.0.0.1/24")}
suite.Require().NoError(suite.state.Create(suite.ctx, nodeAddress))
@ -111,7 +111,7 @@ func (suite *StatusSuite) TestAddresses() {
func (suite *StatusSuite) TestRoutes() {
route := network.NewRouteStatus(network.NamespaceName, "foo")
route.TypedSpec().Gateway = netaddr.MustParseIP("10.0.0.1")
route.TypedSpec().Gateway = netip.MustParseAddr("10.0.0.1")
suite.Require().NoError(suite.state.Create(suite.ctx, route))

View File

@ -7,6 +7,7 @@ package secrets_test
import (
"fmt"
"net/netip"
"reflect"
"testing"
"time"
@ -15,7 +16,6 @@ import (
"github.com/cosi-project/runtime/pkg/state"
"github.com/stretchr/testify/suite"
"github.com/talos-systems/go-retry/retry"
"inet.af/netaddr"
"github.com/talos-systems/talos/internal/app/machined/pkg/controllers/ctest"
secretsctrl "github.com/talos-systems/talos/internal/app/machined/pkg/controllers/secrets"
@ -42,7 +42,7 @@ func (suite *APICertSANsSuite) TestReconcileControlPlane() {
rootSecrets := secrets.NewOSRoot(secrets.OSRootID)
rootSecrets.TypedSpec().CertSANDNSNames = []string{"some.org"}
rootSecrets.TypedSpec().CertSANIPs = []netaddr.IP{netaddr.MustParseIP("10.4.3.2"), netaddr.MustParseIP("10.2.1.3")}
rootSecrets.TypedSpec().CertSANIPs = []netip.Addr{netip.MustParseAddr("10.4.3.2"), netip.MustParseAddr("10.2.1.3")}
suite.Require().NoError(suite.State().Create(suite.Ctx(), rootSecrets))
hostnameStatus := network.NewHostnameStatus(network.NamespaceName, network.HostnameID)
@ -54,9 +54,9 @@ func (suite *APICertSANsSuite) TestReconcileControlPlane() {
network.NamespaceName,
network.FilteredNodeAddressID(network.NodeAddressAccumulativeID, k8s.NodeAddressFilterNoK8s),
)
nodeAddresses.TypedSpec().Addresses = []netaddr.IPPrefix{
netaddr.MustParseIPPrefix("10.2.1.3/24"),
netaddr.MustParseIPPrefix("172.16.0.1/32"),
nodeAddresses.TypedSpec().Addresses = []netip.Prefix{
netip.MustParsePrefix("10.2.1.3/24"),
netip.MustParsePrefix("172.16.0.1/32"),
}
suite.Require().NoError(suite.State().Create(suite.Ctx(), nodeAddresses))

View File

@ -8,6 +8,7 @@ package secrets_test
import (
stdlibx509 "crypto/x509"
"fmt"
"net/netip"
"testing"
"time"
@ -16,7 +17,6 @@ import (
"github.com/stretchr/testify/suite"
"github.com/talos-systems/crypto/x509"
"github.com/talos-systems/go-retry/retry"
"inet.af/netaddr"
"github.com/talos-systems/talos/internal/app/machined/pkg/controllers/ctest"
secretsctrl "github.com/talos-systems/talos/internal/app/machined/pkg/controllers/secrets"
@ -54,7 +54,7 @@ func (suite *APISuite) TestReconcileControlPlane() {
Key: talosCA.KeyPEM,
}
rootSecrets.TypedSpec().CertSANDNSNames = []string{"example.com"}
rootSecrets.TypedSpec().CertSANIPs = []netaddr.IP{netaddr.MustParseIP("10.4.3.2"), netaddr.MustParseIP("10.2.1.3")}
rootSecrets.TypedSpec().CertSANIPs = []netip.Addr{netip.MustParseAddr("10.4.3.2"), netip.MustParseAddr("10.2.1.3")}
rootSecrets.TypedSpec().Token = "something"
suite.Require().NoError(suite.State().Create(suite.Ctx(), rootSecrets))

View File

@ -7,6 +7,7 @@ package secrets_test
import (
"fmt"
"net/netip"
"testing"
"time"
@ -16,7 +17,6 @@ import (
"github.com/stretchr/testify/require"
"github.com/stretchr/testify/suite"
"github.com/talos-systems/crypto/x509"
"inet.af/netaddr"
"github.com/talos-systems/talos/internal/app/machined/pkg/controllers/ctest"
secretsctrl "github.com/talos-systems/talos/internal/app/machined/pkg/controllers/secrets"
@ -66,9 +66,9 @@ func (suite *EtcdSuite) TestReconcile() {
suite.Require().NoError(suite.State().Create(suite.Ctx(), hostnameStatus))
nodeAddresses := network.NewNodeAddress(network.NamespaceName, network.FilteredNodeAddressID(network.NodeAddressRoutedID, k8s.NodeAddressFilterNoK8s))
nodeAddresses.TypedSpec().Addresses = []netaddr.IPPrefix{
netaddr.MustParseIPPrefix("10.3.4.5/24"),
netaddr.MustParseIPPrefix("2001:db8::1eaf/64"),
nodeAddresses.TypedSpec().Addresses = []netip.Prefix{
netip.MustParsePrefix("10.3.4.5/24"),
netip.MustParsePrefix("2001:db8::1eaf/64"),
}
suite.Require().NoError(suite.State().Create(suite.Ctx(), nodeAddresses))
@ -134,8 +134,8 @@ func (suite *EtcdSuite) TestReconcile() {
// update node addresses, certs should be updated
oldVersion := nodeAddresses.Metadata().Version()
nodeAddresses.TypedSpec().Addresses = []netaddr.IPPrefix{
netaddr.MustParseIPPrefix("10.3.4.5/24"),
nodeAddresses.TypedSpec().Addresses = []netip.Prefix{
netip.MustParsePrefix("10.3.4.5/24"),
}
nodeAddresses.Metadata().BumpVersion()
suite.Require().NoError(suite.State().Update(suite.Ctx(), oldVersion, nodeAddresses))

View File

@ -8,6 +8,7 @@ package secrets_test
import (
"fmt"
"net"
"net/netip"
"net/url"
"reflect"
"testing"
@ -17,7 +18,6 @@ import (
"github.com/cosi-project/runtime/pkg/state"
"github.com/stretchr/testify/suite"
"github.com/talos-systems/go-retry/retry"
"inet.af/netaddr"
"github.com/talos-systems/talos/internal/app/machined/pkg/controllers/ctest"
secretsctrl "github.com/talos-systems/talos/internal/app/machined/pkg/controllers/secrets"
@ -64,9 +64,9 @@ func (suite *KubernetesCertSANsSuite) TestReconcile() {
network.NamespaceName,
network.FilteredNodeAddressID(network.NodeAddressAccumulativeID, k8s.NodeAddressFilterNoK8s),
)
nodeAddresses.TypedSpec().Addresses = []netaddr.IPPrefix{
netaddr.MustParseIPPrefix("10.2.1.3/24"),
netaddr.MustParseIPPrefix("172.16.0.1/32"),
nodeAddresses.TypedSpec().Addresses = []netip.Prefix{
netip.MustParsePrefix("10.2.1.3/24"),
netip.MustParsePrefix("172.16.0.1/32"),
}
suite.Require().NoError(suite.State().Create(suite.Ctx(), nodeAddresses))

View File

@ -7,6 +7,7 @@ package secrets
import (
"context"
"fmt"
"net/netip"
"net/url"
"github.com/cosi-project/runtime/pkg/controller"
@ -14,7 +15,6 @@ import (
"github.com/cosi-project/runtime/pkg/state"
"github.com/siderolabs/go-pointer"
"go.uber.org/zap"
"inet.af/netaddr"
talosconfig "github.com/talos-systems/talos/pkg/machinery/config"
"github.com/talos-systems/talos/pkg/machinery/config/types/v1alpha1/machine"
@ -140,7 +140,7 @@ func (ctrl *RootController) updateOSSecrets(cfgProvider talosconfig.Provider, os
osSecrets.CertSANDNSNames = nil
for _, san := range cfgProvider.Machine().Security().CertSANs() {
if ip, err := netaddr.ParseIP(san); err == nil {
if ip, err := netip.ParseAddr(san); err == nil {
osSecrets.CertSANIPs = append(osSecrets.CertSANIPs, ip)
} else {
osSecrets.CertSANDNSNames = append(osSecrets.CertSANDNSNames, san)

View File

@ -8,6 +8,7 @@ package secrets_test
import (
stdlibx509 "crypto/x509"
"fmt"
"net/netip"
"testing"
"time"
@ -16,7 +17,6 @@ import (
"github.com/stretchr/testify/suite"
"github.com/talos-systems/crypto/x509"
"github.com/talos-systems/go-retry/retry"
"inet.af/netaddr"
"github.com/talos-systems/talos/internal/app/machined/pkg/controllers/ctest"
secretsctrl "github.com/talos-systems/talos/internal/app/machined/pkg/controllers/secrets"
@ -53,7 +53,7 @@ func (suite *TrustdSuite) TestReconcileControlPlane() {
Key: talosCA.KeyPEM,
}
rootSecrets.TypedSpec().CertSANDNSNames = []string{"example.com"}
rootSecrets.TypedSpec().CertSANIPs = []netaddr.IP{netaddr.MustParseIP("10.4.3.2"), netaddr.MustParseIP("10.2.1.3")}
rootSecrets.TypedSpec().CertSANIPs = []netip.Addr{netip.MustParseAddr("10.4.3.2"), netip.MustParseAddr("10.2.1.3")}
rootSecrets.TypedSpec().Token = "something"
suite.Require().NoError(suite.State().Create(suite.Ctx(), rootSecrets))

View File

@ -9,6 +9,7 @@ import (
"context"
"crypto/tls"
"fmt"
"net/netip"
"net/url"
"regexp"
@ -23,7 +24,6 @@ import (
"google.golang.org/grpc"
"google.golang.org/grpc/credentials"
"google.golang.org/grpc/credentials/insecure"
"inet.af/netaddr"
"github.com/talos-systems/talos/internal/pkg/smbios"
"github.com/talos-systems/talos/pkg/machinery/constants"
@ -185,12 +185,12 @@ func (ctrl *ManagerController) Run(ctx context.Context, r controller.Runtime, lo
return fmt.Errorf("error accessing SideroLink API: %w", err)
}
serverAddress, err := netaddr.ParseIP(resp.ServerAddress)
serverAddress, err := netip.ParseAddr(resp.ServerAddress)
if err != nil {
return fmt.Errorf("error parsing server address: %w", err)
}
nodeAddress, err := netaddr.ParseIPPrefix(resp.NodeAddressPrefix)
nodeAddress, err := netip.ParsePrefix(resp.NodeAddressPrefix)
if err != nil {
return fmt.Errorf("error parsing node address: %w", err)
}
@ -213,8 +213,8 @@ func (ctrl *ManagerController) Run(ctx context.Context, r controller.Runtime, lo
{
PublicKey: resp.ServerPublicKey,
Endpoint: resp.ServerEndpoint,
AllowedIPs: []netaddr.IPPrefix{
netaddr.IPPrefixFrom(serverAddress, serverAddress.BitLen()),
AllowedIPs: []netip.Prefix{
netip.PrefixFrom(serverAddress, serverAddress.BitLen()),
},
// make sure Talos pings SideroLink endpoint, so that tunnel is established:
// SideroLink doesn't know Talos endpoint.

View File

@ -8,6 +8,7 @@ import (
"context"
"fmt"
"net"
"net/netip"
"testing"
"time"
@ -20,7 +21,6 @@ import (
"github.com/talos-systems/go-retry/retry"
pb "github.com/talos-systems/siderolink/api/siderolink"
"google.golang.org/grpc"
"inet.af/netaddr"
"github.com/talos-systems/talos/internal/app/machined/pkg/controllers/ctest"
siderolinkctrl "github.com/talos-systems/talos/internal/app/machined/pkg/controllers/siderolink"
@ -83,7 +83,7 @@ func (suite *ManagerSuite) TestReconcile() {
suite.Require().NoError(suite.State().Create(suite.Ctx(), networkStatus))
nodeAddress := netaddr.MustParseIPPrefix(mockNodeAddressPrefix)
nodeAddress := netip.MustParsePrefix(mockNodeAddressPrefix)
suite.AssertWithin(10*time.Second, 100*time.Millisecond, func() error {
addressResource, err := ctest.Get[*network.AddressSpec](
@ -139,9 +139,9 @@ func (suite *ManagerSuite) TestReconcile() {
suite.Assert().Equal(mockServerEndpoint, link.Wireguard.Peers[0].Endpoint)
suite.Assert().Equal(mockServerPublicKey, link.Wireguard.Peers[0].PublicKey)
suite.Assert().Equal(
[]netaddr.IPPrefix{
netaddr.IPPrefixFrom(
netaddr.MustParseIP(mockServerAddress),
[]netip.Prefix{
netip.PrefixFrom(
netip.MustParseAddr(mockServerAddress),
128,
),
}, link.Wireguard.Peers[0].AllowedIPs,

View File

@ -6,10 +6,10 @@ package runtime
import (
"context"
"net/netip"
"github.com/cosi-project/runtime/pkg/state"
"github.com/talos-systems/go-procfs/procfs"
"inet.af/netaddr"
"github.com/talos-systems/talos/pkg/machinery/resources/network"
)
@ -54,5 +54,5 @@ type PlatformNetworkConfig struct {
Operators []network.OperatorSpecSpec `yaml:"operators"`
ExternalIPs []netaddr.IP `yaml:"externalIPs"`
ExternalIPs []netip.Addr `yaml:"externalIPs"`
}

View File

@ -9,6 +9,7 @@ import (
"fmt"
"log"
"net/http"
"net/netip"
"strings"
"github.com/aws/aws-sdk-go/aws"
@ -18,7 +19,6 @@ import (
"github.com/aws/aws-sdk-go/aws/session"
"github.com/cosi-project/runtime/pkg/state"
"github.com/talos-systems/go-procfs/procfs"
"inet.af/netaddr"
"github.com/talos-systems/talos/internal/app/machined/pkg/runtime"
"github.com/talos-systems/talos/internal/app/machined/pkg/runtime/v1alpha1/platform/errors"
@ -129,7 +129,7 @@ func (a *AWS) NetworkConfiguration(ctx context.Context, ch chan<- *runtime.Platf
}
if externalIP != "" {
ip, err := netaddr.ParseIP(externalIP)
ip, err := netip.ParseAddr(externalIP)
if err != nil {
return err
}

View File

@ -12,6 +12,7 @@ import (
stderrors "errors"
"fmt"
"log"
"net/netip"
"os"
"path/filepath"
"regexp"
@ -20,7 +21,6 @@ import (
"github.com/cosi-project/runtime/pkg/state"
"github.com/talos-systems/go-procfs/procfs"
"golang.org/x/sys/unix"
"inet.af/netaddr"
"github.com/talos-systems/talos/internal/app/machined/pkg/runtime"
"github.com/talos-systems/talos/internal/app/machined/pkg/runtime/v1alpha1/platform/errors"
@ -104,13 +104,13 @@ func (a *Azure) ParseMetadata(interfaceAddresses []NetworkConfig, host []byte) (
// external IP
for _, iface := range interfaceAddresses {
for _, ipv4addr := range iface.IPv4.IPAddresses {
if ip, err := netaddr.ParseIP(ipv4addr.PublicIPAddress); err == nil {
if ip, err := netip.ParseAddr(ipv4addr.PublicIPAddress); err == nil {
networkConfig.ExternalIPs = append(networkConfig.ExternalIPs, ip)
}
}
for _, ipv6addr := range iface.IPv6.IPAddresses {
if ip, err := netaddr.ParseIP(ipv6addr.PublicIPAddress); err == nil {
if ip, err := netip.ParseAddr(ipv6addr.PublicIPAddress); err == nil {
networkConfig.ExternalIPs = append(networkConfig.ExternalIPs, ip)
}
}
@ -140,7 +140,7 @@ func (a *Azure) ParseMetadata(interfaceAddresses []NetworkConfig, host []byte) (
}
// ParseLoadBalancerIP parses Azure LoadBalancer metadata into the platform external ip list.
func (a *Azure) ParseLoadBalancerIP(lbConfig LoadBalancerMetadata, exIP []netaddr.IP) ([]netaddr.IP, error) {
func (a *Azure) ParseLoadBalancerIP(lbConfig LoadBalancerMetadata, exIP []netip.Addr) ([]netip.Addr, error) {
lbAddresses := exIP
for _, addr := range lbConfig.LoadBalancer.PublicIPAddresses {
@ -150,7 +150,7 @@ func (a *Azure) ParseLoadBalancerIP(lbConfig LoadBalancerMetadata, exIP []netadd
ipaddr = strings.TrimPrefix(ipaddr[:i], "[")
}
if ip, err := netaddr.ParseIP(ipaddr); err == nil {
if ip, err := netip.ParseAddr(ipaddr); err == nil {
lbAddresses = append(lbAddresses, ip)
}
}

View File

@ -8,10 +8,10 @@ import (
"context"
stderrors "errors"
"log"
"net/netip"
"github.com/cosi-project/runtime/pkg/state"
"github.com/talos-systems/go-procfs/procfs"
"inet.af/netaddr"
"github.com/talos-systems/talos/internal/app/machined/pkg/runtime"
"github.com/talos-systems/talos/internal/app/machined/pkg/runtime/v1alpha1/platform/errors"
@ -90,7 +90,7 @@ func (d *DigitalOcean) NetworkConfiguration(ctx context.Context, ch chan<- *runt
}
if len(extIP) > 0 {
if ip, err := netaddr.ParseIP(string(extIP)); err == nil {
if ip, err := netip.ParseAddr(string(extIP)); err == nil {
networkConfig.ExternalIPs = append(networkConfig.ExternalIPs, ip)
}
}

View File

@ -13,12 +13,12 @@ import (
"log"
"net"
"net/http"
"net/netip"
"time"
"github.com/cosi-project/runtime/pkg/state"
"github.com/talos-systems/go-procfs/procfs"
"github.com/talos-systems/go-retry/retry"
"inet.af/netaddr"
networkadapter "github.com/talos-systems/talos/internal/app/machined/pkg/adapters/network"
networkctrl "github.com/talos-systems/talos/internal/app/machined/pkg/controllers/network"
@ -211,13 +211,13 @@ func (p *EquinixMetal) ParseMetadata(equinixMetadata *Metadata) (*runtime.Platfo
continue
}
ipAddr, err := netaddr.ParseIPPrefix(fmt.Sprintf("%s/%d", addr.Address, addr.CIDR))
ipAddr, err := netip.ParsePrefix(fmt.Sprintf("%s/%d", addr.Address, addr.CIDR))
if err != nil {
return nil, err
}
family := nethelpers.FamilyInet4
if ipAddr.IP().Is6() {
if ipAddr.Addr().Is6() {
family = nethelpers.FamilyInet6
}
@ -240,19 +240,19 @@ func (p *EquinixMetal) ParseMetadata(equinixMetadata *Metadata) (*runtime.Platfo
continue
}
ipAddr, err := netaddr.ParseIPPrefix(fmt.Sprintf("%s/%d", addr.Address, addr.CIDR))
ipAddr, err := netip.ParsePrefix(fmt.Sprintf("%s/%d", addr.Address, addr.CIDR))
if err != nil {
return nil, err
}
family := nethelpers.FamilyInet4
if ipAddr.IP().Is6() {
if ipAddr.Addr().Is6() {
family = nethelpers.FamilyInet6
}
if addr.Public {
// for "Public" address add the default route
gw, err := netaddr.ParseIP(addr.Gateway)
gw, err := netip.ParseAddr(addr.Gateway)
if err != nil {
return nil, err
}
@ -278,12 +278,12 @@ func (p *EquinixMetal) ParseMetadata(equinixMetadata *Metadata) (*runtime.Platfo
} else {
// for "Private" addresses, we add a route that goes out the gateway for the private subnets.
for _, privSubnet := range equinixMetadata.PrivateSubnets {
gw, err := netaddr.ParseIP(addr.Gateway)
gw, err := netip.ParseAddr(addr.Gateway)
if err != nil {
return nil, err
}
dest, err := netaddr.ParseIPPrefix(privSubnet)
dest, err := netip.ParsePrefix(privSubnet)
if err != nil {
return nil, err
}

View File

@ -6,12 +6,12 @@ package gcp
import (
"context"
"net/netip"
"strings"
"cloud.google.com/go/compute/metadata"
"github.com/cosi-project/runtime/pkg/state"
"github.com/talos-systems/go-procfs/procfs"
"inet.af/netaddr"
"github.com/talos-systems/talos/internal/app/machined/pkg/runtime"
"github.com/talos-systems/talos/internal/app/machined/pkg/runtime/v1alpha1/platform/errors"
@ -85,7 +85,7 @@ func (g *GCP) NetworkConfiguration(ctx context.Context, ch chan<- *runtime.Platf
}
if externalIP != "" {
ip, err := netaddr.ParseIP(externalIP)
ip, err := netip.ParseAddr(externalIP)
if err != nil {
return err
}

View File

@ -9,11 +9,11 @@ import (
stderrors "errors"
"fmt"
"log"
"net/netip"
"github.com/cosi-project/runtime/pkg/state"
"github.com/talos-systems/go-procfs/procfs"
"gopkg.in/yaml.v3"
"inet.af/netaddr"
"github.com/talos-systems/talos/internal/app/machined/pkg/runtime"
"github.com/talos-systems/talos/internal/app/machined/pkg/runtime/v1alpha1/platform/errors"
@ -81,7 +81,7 @@ func (h *Hcloud) ParseMetadata(unmarshalledNetworkConfig *NetworkConfig, host, e
}
if len(extIP) > 0 {
if ip, err := netaddr.ParseIP(string(extIP)); err == nil {
if ip, err := netip.ParseAddr(string(extIP)); err == nil {
networkConfig.ExternalIPs = append(networkConfig.ExternalIPs, ip)
}
}
@ -110,13 +110,13 @@ func (h *Hcloud) ParseMetadata(unmarshalledNetworkConfig *NetworkConfig, host, e
}
if subnet.Type == "static" {
ipAddr, err := netaddr.ParseIPPrefix(subnet.Address)
ipAddr, err := netip.ParsePrefix(subnet.Address)
if err != nil {
return nil, err
}
family := nethelpers.FamilyInet4
if ipAddr.IP().Is6() {
if ipAddr.Addr().Is6() {
family = nethelpers.FamilyInet6
}
@ -133,7 +133,7 @@ func (h *Hcloud) ParseMetadata(unmarshalledNetworkConfig *NetworkConfig, host, e
}
if subnet.Gateway != "" && subnet.Ipv6 {
gw, err := netaddr.ParseIP(subnet.Gateway)
gw, err := netip.ParseAddr(subnet.Gateway)
if err != nil {
return nil, err
}

View File

@ -9,6 +9,7 @@ import (
"fmt"
"log"
"net"
"net/netip"
"net/url"
"os"
"path/filepath"
@ -17,7 +18,6 @@ import (
"github.com/talos-systems/go-blockdevice/blockdevice/filesystem"
"github.com/talos-systems/go-blockdevice/blockdevice/probe"
"golang.org/x/sys/unix"
"inet.af/netaddr"
"github.com/talos-systems/talos/internal/app/machined/pkg/runtime"
"github.com/talos-systems/talos/internal/app/machined/pkg/runtime/v1alpha1/platform/errors"
@ -227,10 +227,10 @@ func (n *Nocloud) applyNetworkConfigV1(config *NetworkConfig, networkConfig *run
for _, ntwrk := range config.Config {
switch ntwrk.Type {
case "nameserver":
dnsIPs := make([]netaddr.IP, 0, len(ntwrk.Address))
dnsIPs := make([]netip.Addr, 0, len(ntwrk.Address))
for i := range ntwrk.Address {
if ip, err := netaddr.ParseIP(ntwrk.Address[i]); err == nil {
if ip, err := netip.ParseAddr(ntwrk.Address[i]); err == nil {
dnsIPs = append(dnsIPs, ip)
} else {
return err
@ -267,21 +267,21 @@ func (n *Nocloud) applyNetworkConfigV1(config *NetworkConfig, networkConfig *run
family = nethelpers.FamilyInet6
}
ipPrefix, err := netaddr.ParseIPPrefix(subnet.Address)
ipPrefix, err := netip.ParsePrefix(subnet.Address)
if err != nil {
ip, err := netaddr.ParseIP(subnet.Address)
ip, err := netip.ParseAddr(subnet.Address)
if err != nil {
return err
}
netmask, err := netaddr.ParseIP(subnet.Netmask)
netmask, err := netip.ParseAddr(subnet.Netmask)
if err != nil {
return err
}
mask, _ := netmask.MarshalBinary() //nolint:errcheck // never fails
ones, _ := net.IPMask(mask).Size()
ipPrefix = netaddr.IPPrefixFrom(ip, uint8(ones))
ipPrefix = netip.PrefixFrom(ip, ones)
}
networkConfig.Addresses = append(networkConfig.Addresses,
@ -296,7 +296,7 @@ func (n *Nocloud) applyNetworkConfigV1(config *NetworkConfig, networkConfig *run
)
if subnet.Gateway != "" {
gw, err := netaddr.ParseIP(subnet.Gateway)
gw, err := netip.ParseAddr(subnet.Gateway)
if err != nil {
return err
}
@ -340,7 +340,7 @@ func (n *Nocloud) applyNetworkConfigV1(config *NetworkConfig, networkConfig *run
//nolint:gocyclo
func (n *Nocloud) applyNetworkConfigV2(config *NetworkConfig, networkConfig *runtime.PlatformNetworkConfig) error {
var dnsIPs []netaddr.IP
var dnsIPs []netip.Addr
for name, eth := range config.Ethernets {
if !strings.HasPrefix(name, "eth") {
@ -379,14 +379,14 @@ func (n *Nocloud) applyNetworkConfigV2(config *NetworkConfig, networkConfig *run
}
for _, addr := range eth.Address {
ipPrefix, err := netaddr.ParseIPPrefix(addr)
ipPrefix, err := netip.ParsePrefix(addr)
if err != nil {
return err
}
family := nethelpers.FamilyInet4
if ipPrefix.IP().Is6() {
if ipPrefix.Addr().Is6() {
family = nethelpers.FamilyInet6
}
@ -403,7 +403,7 @@ func (n *Nocloud) applyNetworkConfigV2(config *NetworkConfig, networkConfig *run
}
if eth.Gateway4 != "" {
gw, err := netaddr.ParseIP(eth.Gateway4)
gw, err := netip.ParseAddr(eth.Gateway4)
if err != nil {
return err
}
@ -425,7 +425,7 @@ func (n *Nocloud) applyNetworkConfigV2(config *NetworkConfig, networkConfig *run
}
if eth.Gateway6 != "" {
gw, err := netaddr.ParseIP(eth.Gateway6)
gw, err := netip.ParseAddr(eth.Gateway6)
if err != nil {
return err
}
@ -447,7 +447,7 @@ func (n *Nocloud) applyNetworkConfigV2(config *NetworkConfig, networkConfig *run
}
for _, addr := range eth.NameServers.Address {
if ip, err := netaddr.ParseIP(addr); err == nil {
if ip, err := netip.ParseAddr(addr); err == nil {
dnsIPs = append(dnsIPs, ip)
} else {
return err

View File

@ -8,13 +8,13 @@ import (
"context"
"fmt"
"log"
"net/netip"
"os"
"path/filepath"
"github.com/talos-systems/go-blockdevice/blockdevice/filesystem"
"github.com/talos-systems/go-blockdevice/blockdevice/probe"
"golang.org/x/sys/unix"
"inet.af/netaddr"
"github.com/talos-systems/talos/internal/app/machined/pkg/runtime/v1alpha1/platform/errors"
"github.com/talos-systems/talos/pkg/download"
@ -174,7 +174,7 @@ func (o *Openstack) hostname(ctx context.Context) []byte {
return hostname
}
func (o *Openstack) externalIPs(ctx context.Context) (addrs []netaddr.IP) {
func (o *Openstack) externalIPs(ctx context.Context) (addrs []netip.Addr) {
log.Printf("fetching externalIP from: %q", OpenstackExternalIPEndpoint)
exIP, err := download.Download(ctx, OpenstackExternalIPEndpoint,
@ -186,7 +186,7 @@ func (o *Openstack) externalIPs(ctx context.Context) (addrs []netaddr.IP) {
return nil
}
if addr, err := netaddr.ParseIP(string(exIP)); err == nil {
if addr, err := netip.ParseAddr(string(exIP)); err == nil {
addrs = append(addrs, addr)
}

View File

@ -11,10 +11,10 @@ import (
stderrors "errors"
"fmt"
"log"
"net/netip"
"github.com/cosi-project/runtime/pkg/state"
"github.com/talos-systems/go-procfs/procfs"
"inet.af/netaddr"
"github.com/talos-systems/talos/internal/app/machined/pkg/runtime"
"github.com/talos-systems/talos/internal/app/machined/pkg/runtime/v1alpha1/platform/errors"
@ -34,7 +34,7 @@ func (o *Openstack) Name() string {
// ParseMetadata converts OpenStack metadata to platform network configuration.
//
//nolint:gocyclo,cyclop
func (o *Openstack) ParseMetadata(unmarshalledMetadataConfig *MetadataConfig, unmarshalledNetworkConfig *NetworkConfig, hostname string, extIPs []netaddr.IP) (*runtime.PlatformNetworkConfig, error) {
func (o *Openstack) ParseMetadata(unmarshalledMetadataConfig *MetadataConfig, unmarshalledNetworkConfig *NetworkConfig, hostname string, extIPs []netip.Addr) (*runtime.PlatformNetworkConfig, error) {
networkConfig := &runtime.PlatformNetworkConfig{}
if hostname == "" {
@ -55,11 +55,11 @@ func (o *Openstack) ParseMetadata(unmarshalledMetadataConfig *MetadataConfig, un
networkConfig.ExternalIPs = extIPs
var dnsIPs []netaddr.IP
var dnsIPs []netip.Addr
for _, netsvc := range unmarshalledNetworkConfig.Services {
if netsvc.Type == "dns" && netsvc.Address != "" {
if ip, err := netaddr.ParseIP(netsvc.Address); err == nil {
if ip, err := netip.ParseAddr(netsvc.Address); err == nil {
dnsIPs = append(dnsIPs, ip)
} else {
return nil, fmt.Errorf("failed to parse dns service ip: %w", err)
@ -135,7 +135,7 @@ func (o *Openstack) ParseMetadata(unmarshalledMetadataConfig *MetadataConfig, un
}
family := nethelpers.FamilyInet4
if ipPrefix.IP().Is6() {
if ipPrefix.Addr().Is6() {
family = nethelpers.FamilyInet6
}
@ -151,7 +151,7 @@ func (o *Openstack) ParseMetadata(unmarshalledMetadataConfig *MetadataConfig, un
)
if ntwrk.Gateway != "" {
gw, err := netaddr.ParseIP(ntwrk.Gateway)
gw, err := netip.ParseAddr(ntwrk.Gateway)
if err != nil {
return nil, fmt.Errorf("failed to parse gateway ip: %w", err)
}
@ -174,7 +174,7 @@ func (o *Openstack) ParseMetadata(unmarshalledMetadataConfig *MetadataConfig, un
}
for _, route := range ntwrk.Routes {
gw, err := netaddr.ParseIP(route.Gateway)
gw, err := netip.ParseAddr(route.Gateway)
if err != nil {
return nil, fmt.Errorf("failed to parse route gateway: %w", err)
}
@ -185,7 +185,7 @@ func (o *Openstack) ParseMetadata(unmarshalledMetadataConfig *MetadataConfig, un
}
family := nethelpers.FamilyInet4
if dest.IP().Is6() {
if dest.Addr().Is6() {
family = nethelpers.FamilyInet6
}

View File

@ -7,12 +7,12 @@ package openstack_test
import (
_ "embed"
"encoding/json"
"net/netip"
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"gopkg.in/yaml.v3"
"inet.af/netaddr"
"github.com/talos-systems/talos/internal/app/machined/pkg/runtime/v1alpha1/platform/openstack"
)
@ -37,7 +37,7 @@ func TestParseMetadata(t *testing.T) {
require.NoError(t, json.Unmarshal(rawNetwork, &n))
networkConfig, err := o.ParseMetadata(&m, &n, "", []netaddr.IP{netaddr.MustParseIP("1.2.3.4")})
networkConfig, err := o.ParseMetadata(&m, &n, "", []netip.Addr{netip.MustParseAddr("1.2.3.4")})
require.NoError(t, err)
marshaled, err := yaml.Marshal(networkConfig)

View File

@ -8,12 +8,12 @@ import (
"context"
"encoding/json"
"log"
"net/netip"
"strconv"
"github.com/cosi-project/runtime/pkg/state"
"github.com/scaleway/scaleway-sdk-go/api/instance/v1"
"github.com/talos-systems/go-procfs/procfs"
"inet.af/netaddr"
"github.com/talos-systems/talos/internal/app/machined/pkg/runtime"
"github.com/talos-systems/talos/internal/app/machined/pkg/runtime/v1alpha1/platform/errors"
@ -54,7 +54,7 @@ func (s *Scaleway) ParseMetadata(metadataConfig *instance.Metadata) (*runtime.Pl
}
if metadataConfig.PublicIP.Address != "" {
ip, err := netaddr.ParseIP(metadataConfig.PublicIP.Address)
ip, err := netip.ParseAddr(metadataConfig.PublicIP.Address)
if err != nil {
return nil, err
}
@ -68,7 +68,7 @@ func (s *Scaleway) ParseMetadata(metadataConfig *instance.Metadata) (*runtime.Pl
ConfigLayer: network.ConfigPlatform,
})
gw, _ := netaddr.ParseIPPrefix("169.254.42.42/32") //nolint:errcheck
gw, _ := netip.ParsePrefix("169.254.42.42/32") //nolint:errcheck
route := network.RouteSpecSpec{
ConfigLayer: network.ConfigPlatform,
OutLinkName: "eth0",
@ -99,12 +99,12 @@ func (s *Scaleway) ParseMetadata(metadataConfig *instance.Metadata) (*runtime.Pl
return nil, err
}
ip, err := netaddr.ParseIP(metadataConfig.IPv6.Address)
ip, err := netip.ParseAddr(metadataConfig.IPv6.Address)
if err != nil {
return nil, err
}
addr := netaddr.IPPrefixFrom(ip, uint8(bits))
addr := netip.PrefixFrom(ip, bits)
networkConfig.Addresses = append(networkConfig.Addresses,
network.AddressSpecSpec{
@ -117,7 +117,7 @@ func (s *Scaleway) ParseMetadata(metadataConfig *instance.Metadata) (*runtime.Pl
},
)
gw, err := netaddr.ParseIP(metadataConfig.IPv6.Gateway)
gw, err := netip.ParseAddr(metadataConfig.IPv6.Gateway)
if err != nil {
return nil, err
}

View File

@ -9,10 +9,10 @@ import (
"encoding/json"
"fmt"
"log"
"net/netip"
"github.com/cosi-project/runtime/pkg/state"
"github.com/talos-systems/go-procfs/procfs"
"inet.af/netaddr"
"github.com/talos-systems/talos/internal/app/machined/pkg/runtime"
"github.com/talos-systems/talos/internal/app/machined/pkg/runtime/v1alpha1/platform/errors"
@ -82,7 +82,7 @@ func (u *UpCloud) ParseMetadata(meta *MetaData) (*runtime.PlatformNetworkConfig,
networkConfig.Hostnames = append(networkConfig.Hostnames, hostnameSpec)
}
var dnsIPs []netaddr.IP
var dnsIPs []netip.Addr
firstIP := true
@ -101,7 +101,7 @@ func (u *UpCloud) ParseMetadata(meta *MetaData) (*runtime.PlatformNetworkConfig,
for _, ip := range addr.IPAddresses {
if firstIP {
ipAddr, err := netaddr.ParseIP(ip.Address)
ipAddr, err := netip.ParseAddr(ip.Address)
if err != nil {
return nil, err
}
@ -112,7 +112,7 @@ func (u *UpCloud) ParseMetadata(meta *MetaData) (*runtime.PlatformNetworkConfig,
}
for _, addr := range ip.DNS {
if ipAddr, err := netaddr.ParseIP(addr); err == nil {
if ipAddr, err := netip.ParseAddr(addr); err == nil {
dnsIPs = append(dnsIPs, ipAddr)
}
}
@ -130,17 +130,17 @@ func (u *UpCloud) ParseMetadata(meta *MetaData) (*runtime.PlatformNetworkConfig,
}
if !ip.DHCP {
ntwrk, err := netaddr.ParseIPPrefix(ip.Network)
ntwrk, err := netip.ParsePrefix(ip.Network)
if err != nil {
return nil, err
}
addr, err := netaddr.ParseIP(ip.Address)
addr, err := netip.ParseAddr(ip.Address)
if err != nil {
return nil, err
}
ipPrefix := netaddr.IPPrefixFrom(addr, ntwrk.Bits())
ipPrefix := netip.PrefixFrom(addr, ntwrk.Bits())
family := nethelpers.FamilyInet4
if addr.Is6() {
@ -159,7 +159,7 @@ func (u *UpCloud) ParseMetadata(meta *MetaData) (*runtime.PlatformNetworkConfig,
)
if ip.Gateway != "" {
gw, err := netaddr.ParseIP(ip.Gateway)
gw, err := netip.ParseAddr(ip.Gateway)
if err != nil {
return nil, err
}

View File

@ -7,16 +7,15 @@ package utils
import (
"fmt"
"net"
"net/netip"
"strconv"
"strings"
"inet.af/netaddr"
)
// IPPrefixFrom make netaddr.IPPrefix from cidr-address and netmask strings.
// IPPrefixFrom make netip.Prefix from cidr-address and netmask strings.
// address can be IP or CIDR (1.1.1.1 or 1.1.1.1/8 or 1.1.1.1/255.0.0.0)
// netmask can be IP or number (255.255.255.0 or 24 or empty).
func IPPrefixFrom(address, netmask string) (netaddr.IPPrefix, error) {
func IPPrefixFrom(address, netmask string) (netip.Prefix, error) {
cidr := strings.SplitN(address, "/", 2)
if len(cidr) == 1 {
address = cidr[0]
@ -25,9 +24,9 @@ func IPPrefixFrom(address, netmask string) (netaddr.IPPrefix, error) {
netmask = cidr[1]
}
ip, err := netaddr.ParseIP(address)
ip, err := netip.ParseAddr(address)
if err != nil {
return netaddr.IPPrefix{}, fmt.Errorf("failed to parse ip address: %w", err)
return netip.Prefix{}, fmt.Errorf("failed to parse ip address: %w", err)
}
if netmask == "" {
@ -40,9 +39,9 @@ func IPPrefixFrom(address, netmask string) (netaddr.IPPrefix, error) {
bits, err := strconv.Atoi(netmask)
if err != nil {
netmask, err := netaddr.ParseIP(netmask)
netmask, err := netip.ParseAddr(netmask)
if err != nil {
return netaddr.IPPrefix{}, fmt.Errorf("failed to parse netmask: %w", err)
return netip.Prefix{}, fmt.Errorf("failed to parse netmask: %w", err)
}
mask, _ := netmask.MarshalBinary() //nolint:errcheck // never fails
@ -50,8 +49,8 @@ func IPPrefixFrom(address, netmask string) (netaddr.IPPrefix, error) {
}
if ip.Is4() && bits > 32 {
return netaddr.IPPrefix{}, fmt.Errorf("failed netmask should be the same address family")
return netip.Prefix{}, fmt.Errorf("failed netmask should be the same address family")
}
return netaddr.IPPrefixFrom(ip, uint8(bits)), nil
return netip.PrefixFrom(ip, bits), nil
}

View File

@ -11,11 +11,11 @@ import (
"fmt"
"log"
"net"
"net/netip"
"github.com/cosi-project/runtime/pkg/state"
"github.com/talos-systems/go-procfs/procfs"
"github.com/vultr/metadata"
"inet.af/netaddr"
"github.com/talos-systems/talos/internal/app/machined/pkg/runtime"
"github.com/talos-systems/talos/internal/app/machined/pkg/runtime/v1alpha1/platform/errors"
@ -47,7 +47,7 @@ func (v *Vultr) Name() string {
func (v *Vultr) ParseMetadata(meta *metadata.MetaData, extIP []byte) (*runtime.PlatformNetworkConfig, error) {
networkConfig := &runtime.PlatformNetworkConfig{}
if ip, err := netaddr.ParseIP(string(extIP)); err == nil {
if ip, err := netip.ParseAddr(string(extIP)); err == nil {
networkConfig.ExternalIPs = append(networkConfig.ExternalIPs, ip)
}
@ -90,19 +90,19 @@ func (v *Vultr) ParseMetadata(meta *metadata.MetaData, extIP []byte) (*runtime.P
ConfigLayer: network.ConfigPlatform,
})
} else {
ip, err := netaddr.ParseIP(addr.IPv4.Address)
ip, err := netip.ParseAddr(addr.IPv4.Address)
if err != nil {
return nil, err
}
netmask, err := netaddr.ParseIP(addr.IPv4.Netmask)
netmask, err := netip.ParseAddr(addr.IPv4.Netmask)
if err != nil {
return nil, err
}
mask, _ := netmask.MarshalBinary() //nolint:errcheck // never fails
ones, _ := net.IPMask(mask).Size()
ipAddr := netaddr.IPPrefixFrom(ip, uint8(ones))
ipAddr := netip.PrefixFrom(ip, ones)
networkConfig.Addresses = append(networkConfig.Addresses,
network.AddressSpecSpec{

View File

@ -10,6 +10,7 @@ import (
"fmt"
"io"
"log"
"net/netip"
"os"
goruntime "runtime"
"strings"
@ -26,7 +27,6 @@ import (
"github.com/talos-systems/go-retry/retry"
clientv3 "go.etcd.io/etcd/client/v3"
snapshot "go.etcd.io/etcd/etcdutl/v3/snapshot"
"inet.af/netaddr"
"github.com/talos-systems/talos/internal/app/machined/pkg/runtime"
"github.com/talos-systems/talos/internal/app/machined/pkg/runtime/v1alpha1/bootloader"
@ -696,16 +696,16 @@ func BootstrapEtcd(ctx context.Context, r runtime.Runtime, req *machineapi.Boots
return nil
}
func formatEtcdURL(addr netaddr.IP, port int) string {
func formatEtcdURL(addr netip.Addr, port int) string {
return fmt.Sprintf("https://%s", nethelpers.JoinHostPort(addr.String(), port))
}
func getEtcdURLs(addrs []netaddr.IP, port int) []string {
return slices.Map(addrs, func(addr netaddr.IP) string {
func getEtcdURLs(addrs []netip.Addr, port int) []string {
return slices.Map(addrs, func(addr netip.Addr) string {
return formatEtcdURL(addr, port)
})
}
func formatEtcdURLs(addrs []netaddr.IP, port int) string {
func formatEtcdURLs(addrs []netip.Addr, port int) string {
return strings.Join(getEtcdURLs(addrs, port), ",")
}

View File

@ -10,6 +10,7 @@ import (
"fmt"
"log"
"net"
"net/netip"
"github.com/cosi-project/runtime/pkg/resource"
"github.com/cosi-project/runtime/pkg/state"
@ -18,7 +19,6 @@ import (
"github.com/talos-systems/go-procfs/procfs"
"google.golang.org/grpc"
"google.golang.org/grpc/credentials"
"inet.af/netaddr"
"github.com/talos-systems/talos/internal/app/machined/pkg/runtime"
"github.com/talos-systems/talos/internal/app/maintenance/server"
@ -26,6 +26,7 @@ import (
"github.com/talos-systems/talos/pkg/grpc/gen"
"github.com/talos-systems/talos/pkg/grpc/middleware/authz"
"github.com/talos-systems/talos/pkg/machinery/constants"
"github.com/talos-systems/talos/pkg/machinery/generic"
"github.com/talos-systems/talos/pkg/machinery/generic/slices"
"github.com/talos-systems/talos/pkg/machinery/resources/network"
)
@ -40,7 +41,7 @@ func Run(ctx context.Context, logger *log.Logger, r runtime.Runtime) ([]byte, er
return nil, fmt.Errorf("error waiting for the network to be ready: %w", err)
}
var sideroLinkAddress netaddr.IP
var sideroLinkAddress netip.Addr
currentAddresses, err := r.State().V1Alpha2().Resources().WatchFor(ctx,
resource.NewMetadata(network.NamespaceName, network.NodeAddressType, network.NodeAddressCurrentID, resource.VersionUndefined),
@ -114,8 +115,8 @@ func Run(ctx context.Context, logger *log.Logger, r runtime.Runtime) ([]byte, er
server.Serve(listener)
}()
if !sideroLinkAddress.IsZero() {
ips = []netaddr.IP{sideroLinkAddress}
if !generic.IsZero(sideroLinkAddress) {
ips = []netip.Addr{sideroLinkAddress}
}
logger.Println("this machine is reachable at:")
@ -151,23 +152,23 @@ func Run(ctx context.Context, logger *log.Logger, r runtime.Runtime) ([]byte, er
}
}
func formatIP(addr netaddr.IP) string {
if addr.IsZero() {
func formatIP(addr netip.Addr) string {
if generic.IsZero(addr) {
return ""
}
return addr.String()
}
func genTLSConfig(ips []netaddr.IP, dnsNames []string) (tlsConfig *tls.Config, provider ttls.CertificateProvider, err error) {
func genTLSConfig(ips []netip.Addr, dnsNames []string) (tlsConfig *tls.Config, provider ttls.CertificateProvider, err error) {
ca, err := x509.NewSelfSignedCertificateAuthority()
if err != nil {
return nil, nil, fmt.Errorf("failed to generate self-signed CA: %w", err)
}
ips = append(ips, netaddr.MustParseIP("127.0.0.1"), netaddr.MustParseIP("::1"))
ips = append(ips, netip.MustParseAddr("127.0.0.1"), netip.MustParseAddr("::1"))
netIPs := slices.Map(ips, func(ip netaddr.IP) net.IP { return ip.IPAddr().IP })
netIPs := slices.Map(ips, func(ip netip.Addr) net.IP { return ip.AsSlice() })
var generator ttls.Generator
@ -198,7 +199,7 @@ func genTLSConfig(ips []netaddr.IP, dnsNames []string) (tlsConfig *tls.Config, p
return tlsConfig, provider, nil
}
func sideroLinkAddressFinder(address *netaddr.IP, logger *log.Logger) state.WatchForConditionFunc {
func sideroLinkAddressFinder(address *netip.Addr, logger *log.Logger) state.WatchForConditionFunc {
sideroLinkEnabled := false
if procfs.ProcCmdline().Get(constants.KernelParamSideroLink).First() != nil {
sideroLinkEnabled = true

View File

@ -9,6 +9,7 @@ import (
"fmt"
"log"
"net"
"net/netip"
"strings"
cosiv1alpha1 "github.com/cosi-project/runtime/api/v1alpha1"
@ -19,7 +20,6 @@ import (
"google.golang.org/grpc/peer"
"google.golang.org/grpc/status"
"google.golang.org/protobuf/types/known/emptypb"
"inet.af/netaddr"
"github.com/talos-systems/talos/internal/app/machined/pkg/runtime"
"github.com/talos-systems/talos/internal/app/resources"
@ -131,7 +131,7 @@ func (s *Server) GenerateClientConfiguration(ctx context.Context, in *machine.Ge
return nil, status.Error(codes.Unimplemented, "client configuration (talosconfig) can't be generated in the maintenance mode")
}
func verifyPeer(ctx context.Context, condition func(netaddr.IP) bool) bool {
func verifyPeer(ctx context.Context, condition func(netip.Addr) bool) bool {
remotePeer, ok := peer.FromContext(ctx)
if !ok {
return false
@ -146,7 +146,7 @@ func verifyPeer(ctx context.Context, condition func(netaddr.IP) bool) bool {
return false
}
addr, err := netaddr.ParseIP(ip)
addr, err := netip.ParseAddr(ip)
if err != nil {
return false
}
@ -156,7 +156,7 @@ func verifyPeer(ctx context.Context, condition func(netaddr.IP) bool) bool {
// Version implements the machine.MachineServer interface.
func (s *Server) Version(ctx context.Context, in *emptypb.Empty) (*machine.VersionResponse, error) {
if !verifyPeer(ctx, func(addr netaddr.IP) bool {
if !verifyPeer(ctx, func(addr netip.Addr) bool {
return network.IsULA(addr, network.ULASideroLink)
}) {
return nil, status.Error(codes.Unimplemented, "Version API is not implemented in maintenance mode")

Some files were not shown because too many files have changed in this diff Show More