From c43f942cc59aa2687f60e7cdddf8212bf52a2987 Mon Sep 17 00:00:00 2001 From: Marc Frei Date: Fri, 12 May 2023 11:10:21 +0200 Subject: [PATCH] deps: replace inet.af/netaddr with net/netip and go4.org/netipx (#4313) Replace deprecated inet.af/netaddr with its standard library replacement package net/netip. Use go4.org/netipx for some the pieces that were not added to the standard library. This change does not affect the `snet` API, or any other public API. --- control/beaconing/BUILD.bazel | 1 - control/beaconing/originator.go | 2 +- control/beaconing/originator_test.go | 2 +- control/beaconing/propagator.go | 3 +- control/beaconing/propagator_test.go | 2 +- control/beaconing/writer_test.go | 6 +- control/cmd/control/BUILD.bazel | 2 +- control/cmd/control/main.go | 4 +- control/config/BUILD.bazel | 2 - control/config/drkey.go | 7 +- control/config/drkey_test.go | 6 +- control/drkey/grpc/BUILD.bazel | 3 +- control/drkey/grpc/drkey_service.go | 4 +- control/drkey/grpc/drkey_service_test.go | 72 +++++++++---------- control/ifstate/BUILD.bazel | 1 - control/ifstate/ifstate.go | 5 +- gateway/BUILD.bazel | 1 - gateway/control/BUILD.bazel | 2 +- gateway/control/grpc/BUILD.bazel | 1 - gateway/control/grpc/mock_grpc/BUILD.bazel | 1 - gateway/control/grpc/mock_grpc/mock.go | 6 +- gateway/control/grpc/prefix_server.go | 8 +-- gateway/control/prefixesfilter.go | 8 +-- gateway/gateway.go | 4 +- gateway/routing/BUILD.bazel | 3 +- gateway/routing/advertise.go | 11 +-- gateway/routing/export_test.go | 5 +- gateway/routing/ipset.go | 11 +-- gateway/routing/marshal.go | 7 +- gateway/routing/policy.go | 19 ++--- gateway/routing/policy_test.go | 4 +- go.mod | 4 +- go.sum | 10 +-- go_deps.bzl | 34 ++++----- licenses/data/org_go4_intern/LICENSE | 29 -------- .../LICENSE | 0 .../LICENSE | 29 -------- pkg/experimental/hiddenpath/BUILD.bazel | 1 - .../hiddenpath/beaconwriter_test.go | 6 +- pkg/private/xtest/BUILD.bazel | 1 - pkg/private/xtest/helpers.go | 10 +-- pkg/snet/BUILD.bazel | 1 - pkg/snet/udpaddr.go | 6 +- private/app/flag/BUILD.bazel | 2 - private/app/flag/env.go | 20 +++--- private/app/flag/env_test.go | 16 ++--- scion-pki/certs/renew.go | 2 +- scion/cmd/scion/ping.go | 2 +- scion/cmd/scion/showpaths.go | 3 +- scion/cmd/scion/traceroute.go | 2 +- 50 files changed, 152 insertions(+), 239 deletions(-) delete mode 100644 licenses/data/org_go4_intern/LICENSE rename licenses/data/{af_inet_netaddr => org_go4_netipx}/LICENSE (100%) delete mode 100644 licenses/data/org_go4_unsafe_assume_no_moving_gc/LICENSE diff --git a/control/beaconing/BUILD.bazel b/control/beaconing/BUILD.bazel index 515c9ef1cf..d3123fdd6a 100644 --- a/control/beaconing/BUILD.bazel +++ b/control/beaconing/BUILD.bazel @@ -78,7 +78,6 @@ go_test( "//private/segment/verifier/mock_verifier:go_default_library", "//private/topology:go_default_library", "//private/trust:go_default_library", - "@af_inet_netaddr//:go_default_library", "@com_github_golang_mock//gomock:go_default_library", "@com_github_stretchr_testify//assert:go_default_library", "@com_github_stretchr_testify//require:go_default_library", diff --git a/control/beaconing/originator.go b/control/beaconing/originator.go index d8541c2145..52997e72d0 100644 --- a/control/beaconing/originator.go +++ b/control/beaconing/originator.go @@ -174,7 +174,7 @@ func (o *beaconOriginator) originateBeacon(ctx context.Context) error { senderCtx, topoInfo.IA, o.intf.TopoInfo().ID, - topoInfo.InternalAddr.UDPAddr(), + net.UDPAddrFromAddrPort(topoInfo.InternalAddr), ) if err != nil { o.incrementMetrics(labels.WithResult(prom.ErrNetwork)) diff --git a/control/beaconing/originator_test.go b/control/beaconing/originator_test.go index ac98015e2b..3c9d78d1f8 100644 --- a/control/beaconing/originator_test.go +++ b/control/beaconing/originator_test.go @@ -104,7 +104,7 @@ func TestOriginatorRun(t *testing.T) { // Check the interface matches. assert.Equal(t, hopF.ConsEgress, egIfId) // Check that the beacon is sent to the correct border router. - br := interfaceInfos(topo)[egIfId].InternalAddr.UDPAddr() + br := net.UDPAddrFromAddrPort(interfaceInfos(topo)[egIfId].InternalAddr) assert.Equal(t, br, nextHop) return nil }, diff --git a/control/beaconing/propagator.go b/control/beaconing/propagator.go index e3f24cb1cf..f2d0e27190 100644 --- a/control/beaconing/propagator.go +++ b/control/beaconing/propagator.go @@ -16,6 +16,7 @@ package beaconing import ( "context" + "net" "sort" "strconv" "sync" @@ -266,7 +267,7 @@ func (p *propagator) Propagate(ctx context.Context) error { senderCtx, topoInfo.IA, egress, - topoInfo.InternalAddr.UDPAddr(), + net.UDPAddrFromAddrPort(topoInfo.InternalAddr), ) if err != nil { for _, b := range p.beacons { diff --git a/control/beaconing/propagator_test.go b/control/beaconing/propagator_test.go index d79d2c8c0d..1bd1ea99e8 100644 --- a/control/beaconing/propagator_test.go +++ b/control/beaconing/propagator_test.go @@ -293,6 +293,6 @@ func validateSend( // Check the interface matches. assert.Equal(t, hopF.ConsEgress, egIfId) // Check that the beacon is sent to the correct border router. - br := interfaceInfos(topo)[egIfId].InternalAddr.UDPAddr() + br := net.UDPAddrFromAddrPort(interfaceInfos(topo)[egIfId].InternalAddr) assert.Equal(t, br, nextHop) } diff --git a/control/beaconing/writer_test.go b/control/beaconing/writer_test.go index 69013e028d..4613aa1e99 100644 --- a/control/beaconing/writer_test.go +++ b/control/beaconing/writer_test.go @@ -23,6 +23,7 @@ import ( "fmt" "hash" "net" + "net/netip" "sync" "testing" "time" @@ -30,7 +31,6 @@ import ( "github.com/golang/mock/gomock" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" - "inet.af/netaddr" "github.com/scionproto/scion/control/beacon" "github.com/scionproto/scion/control/beaconing" @@ -259,7 +259,7 @@ func TestRegistrarRun(t *testing.T) { assert.Equal(t, pathHopField.ConsEgress, segHopField.ConsEgress) nextHop := pathHopField.ConsIngress - a := interfaceInfos(topo)[nextHop].InternalAddr.UDPAddr() + a := net.UDPAddrFromAddrPort(interfaceInfos(topo)[nextHop].InternalAddr) assert.Equal(t, a, s.Addr.NextHop) } }) @@ -371,7 +371,7 @@ func interfaceInfos(topo topology.Topology) map[uint16]ifstate.InterfaceInfo { ID: uint16(info.ID), IA: info.IA, LinkType: info.LinkType, - InternalAddr: netaddr.MustParseIPPort(info.InternalAddr.String()), + InternalAddr: netip.MustParseAddrPort(info.InternalAddr.String()), RemoteID: uint16(info.RemoteIFID), MTU: uint16(info.MTU), } diff --git a/control/cmd/control/BUILD.bazel b/control/cmd/control/BUILD.bazel index bdb3b63070..ad9a6938a1 100644 --- a/control/cmd/control/BUILD.bazel +++ b/control/cmd/control/BUILD.bazel @@ -68,12 +68,12 @@ go_library( "//private/trust/compat:go_default_library", "//private/trust/grpc:go_default_library", "//private/trust/metrics:go_default_library", - "@af_inet_netaddr//:go_default_library", "@com_github_go_chi_chi_v5//:go_default_library", "@com_github_go_chi_cors//:go_default_library", "@com_github_grpc_ecosystem_go_grpc_prometheus//:go_default_library", "@com_github_spf13_cobra//:go_default_library", "@in_gopkg_yaml_v2//:go_default_library", + "@org_go4_netipx//:go_default_library", "@org_golang_google_grpc//:go_default_library", "@org_golang_google_grpc//health:go_default_library", "@org_golang_google_grpc//health/grpc_health_v1:go_default_library", diff --git a/control/cmd/control/main.go b/control/cmd/control/main.go index 2f53c2ca97..d481cd607c 100644 --- a/control/cmd/control/main.go +++ b/control/cmd/control/main.go @@ -32,11 +32,11 @@ import ( "github.com/go-chi/cors" promgrpc "github.com/grpc-ecosystem/go-grpc-prometheus" "github.com/spf13/cobra" + "go4.org/netipx" "golang.org/x/sync/errgroup" "google.golang.org/grpc" "google.golang.org/grpc/health" healthpb "google.golang.org/grpc/health/grpc_health_v1" - "inet.af/netaddr" cs "github.com/scionproto/scion/control" "github.com/scionproto/scion/control/beacon" @@ -834,7 +834,7 @@ func createBeaconStore( func adaptInterfaceMap(in map[common.IFIDType]topology.IFInfo) map[uint16]ifstate.InterfaceInfo { converted := make(map[uint16]ifstate.InterfaceInfo, len(in)) for id, info := range in { - addr, ok := netaddr.FromStdAddr( + addr, ok := netipx.FromStdAddr( info.InternalAddr.IP, info.InternalAddr.Port, info.InternalAddr.Zone, diff --git a/control/config/BUILD.bazel b/control/config/BUILD.bazel index dfff0ea962..97e2c636e7 100644 --- a/control/config/BUILD.bazel +++ b/control/config/BUILD.bazel @@ -22,7 +22,6 @@ go_library( "//private/mgmtapi/jwtauth:go_default_library", "//private/storage:go_default_library", "//private/trust/config:go_default_library", - "@af_inet_netaddr//:go_default_library", ], ) @@ -41,7 +40,6 @@ go_test( "//private/mgmtapi/mgmtapitest:go_default_library", "//private/storage:go_default_library", "//private/storage/test:go_default_library", - "@af_inet_netaddr//:go_default_library", "@com_github_pelletier_go_toml//:go_default_library", "@com_github_stretchr_testify//assert:go_default_library", "@com_github_stretchr_testify//require:go_default_library", diff --git a/control/config/drkey.go b/control/config/drkey.go index 7dbdcdcdbc..38ad9f7768 100644 --- a/control/config/drkey.go +++ b/control/config/drkey.go @@ -16,11 +16,10 @@ package config import ( "io" + "net/netip" "strings" "time" - "inet.af/netaddr" - "github.com/scionproto/scion/pkg/addr" "github.com/scionproto/scion/pkg/drkey" "github.com/scionproto/scion/pkg/private/serrors" @@ -138,7 +137,7 @@ func (cfg *SecretValueHostList) ConfigName() string { } type HostProto struct { - Host netaddr.IP + Host netip.Addr Proto drkey.Protocol } @@ -147,7 +146,7 @@ func (cfg *SecretValueHostList) ToAllowedSet() map[HostProto]struct{} { m := make(map[HostProto]struct{}) for proto, ipList := range *cfg { for _, ip := range ipList { - host, err := netaddr.ParseIP(ip) + host, err := netip.ParseAddr(ip) if err != nil { continue } diff --git a/control/config/drkey_test.go b/control/config/drkey_test.go index b127a07b66..4c1a4ac620 100644 --- a/control/config/drkey_test.go +++ b/control/config/drkey_test.go @@ -16,13 +16,13 @@ package config import ( "bytes" + "net/netip" "os" "testing" toml "github.com/pelletier/go-toml" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" - "inet.af/netaddr" "github.com/scionproto/scion/pkg/drkey" "github.com/scionproto/scion/private/storage" @@ -107,9 +107,9 @@ func TestSecretValueHostListSyntax(t *testing.T) { func TestToMapPerHost(t *testing.T) { var cfg SecretValueHostList sample := `scmp = ["1.1.1.1", "2.2.2.2"]` - ip1111, err := netaddr.ParseIP("1.1.1.1") + ip1111, err := netip.ParseAddr("1.1.1.1") require.NoError(t, err) - ip2222, err := netaddr.ParseIP("2.2.2.2") + ip2222, err := netip.ParseAddr("2.2.2.2") require.NoError(t, err) err = toml.NewDecoder(bytes.NewReader([]byte(sample))).Strict(true).Decode(&cfg) require.NoError(t, err) diff --git a/control/drkey/grpc/BUILD.bazel b/control/drkey/grpc/BUILD.bazel index eef4d1bcb5..9eb9cdef72 100644 --- a/control/drkey/grpc/BUILD.bazel +++ b/control/drkey/grpc/BUILD.bazel @@ -21,7 +21,7 @@ go_library( "//pkg/proto/drkey:go_default_library", "//pkg/scrypto/cppki:go_default_library", "//pkg/snet:go_default_library", - "@af_inet_netaddr//:go_default_library", + "@org_go4_netipx//:go_default_library", "@org_golang_google_grpc//credentials:go_default_library", "@org_golang_google_grpc//peer:go_default_library", "@org_golang_google_protobuf//types/known/timestamppb:go_default_library", @@ -54,7 +54,6 @@ go_test( "//private/trust:go_default_library", "//private/trust/mock_trust:go_default_library", "//scion-pki/testcrypto:go_default_library", - "@af_inet_netaddr//:go_default_library", "@com_github_golang_mock//gomock:go_default_library", "@com_github_stretchr_testify//assert:go_default_library", "@com_github_stretchr_testify//require:go_default_library", diff --git a/control/drkey/grpc/drkey_service.go b/control/drkey/grpc/drkey_service.go index 23ca586927..b0a7278c25 100644 --- a/control/drkey/grpc/drkey_service.go +++ b/control/drkey/grpc/drkey_service.go @@ -19,10 +19,10 @@ import ( "crypto/x509" "net" + "go4.org/netipx" "google.golang.org/grpc/credentials" "google.golang.org/grpc/peer" "google.golang.org/protobuf/types/known/timestamppb" - "inet.af/netaddr" "github.com/scionproto/scion/control/config" "github.com/scionproto/scion/pkg/addr" @@ -263,7 +263,7 @@ func (d *Server) validateAllowedHost(protoId drkey.Protocol, peerAddr net.Addr) return serrors.New("invalid peer address type, expected *net.TCPAddr", "peer", peerAddr, "type", common.TypeOf(peerAddr)) } - localAddr, ok := netaddr.FromStdIP(tcpAddr.IP) + localAddr, ok := netipx.FromStdIP(tcpAddr.IP) if !ok { return serrors.New("unable to parse IP", "addr", tcpAddr.IP.String()) } diff --git a/control/drkey/grpc/drkey_service_test.go b/control/drkey/grpc/drkey_service_test.go index f70bc9f492..d9690769b8 100644 --- a/control/drkey/grpc/drkey_service_test.go +++ b/control/drkey/grpc/drkey_service_test.go @@ -17,13 +17,13 @@ package grpc_test import ( "context" "net" + "net/netip" "testing" "github.com/golang/mock/gomock" "github.com/stretchr/testify/assert" "google.golang.org/grpc/peer" "google.golang.org/protobuf/types/known/timestamppb" - "inet.af/netaddr" "github.com/scionproto/scion/control/config" dk_grpc "github.com/scionproto/scion/control/drkey/grpc" @@ -39,8 +39,8 @@ import ( var ( ia111 = xtest.MustParseIA("1-ff00:0:111") ia112 = xtest.MustParseIA("1-ff00:0:112") - tcpHost1 = netaddr.MustParseIPPort("127.0.0.1:12345") - tcpHost2 = netaddr.MustParseIPPort("127.0.0.2:12345") + tcpHost1 = netip.MustParseAddrPort("127.0.0.1:12345") + tcpHost2 = netip.MustParseAddrPort("127.0.0.2:12345") ) var _ cppb.DRKeyInterServiceServer = &dk_grpc.Server{} @@ -64,11 +64,11 @@ func TestDRKeySV(t *testing.T) { }{ "allowed host": { ctx: peer.NewContext(context.Background(), &peer.Peer{ - Addr: tcpHost1.TCPAddr(), + Addr: net.TCPAddrFromAddrPort(tcpHost1), }), list: map[config.HostProto]struct{}{ { - Host: tcpHost1.IP(), + Host: tcpHost1.Addr(), Proto: drkey.SCMP, }: {}, }, @@ -81,11 +81,11 @@ func TestDRKeySV(t *testing.T) { }, "not allowed host": { ctx: peer.NewContext(context.Background(), &peer.Peer{ - Addr: tcpHost2.TCPAddr(), + Addr: net.TCPAddrFromAddrPort(tcpHost2), }), list: map[config.HostProto]struct{}{ { - Host: tcpHost1.IP(), + Host: tcpHost1.Addr(), Proto: drkey.SCMP, }: {}, }, @@ -121,7 +121,7 @@ func TestValidateASHost(t *testing.T) { assertErr assert.ErrorAssertionFunc }{ "no host": { - peerAddr: tcpHost1.TCPAddr(), + peerAddr: net.TCPAddrFromAddrPort(tcpHost1), req: drkey.ASHostMeta{ SrcIA: ia111, DstIA: ia112, @@ -130,30 +130,30 @@ func TestValidateASHost(t *testing.T) { assertErr: assert.Error, }, "no localIA": { - peerAddr: tcpHost1.TCPAddr(), + peerAddr: net.TCPAddrFromAddrPort(tcpHost1), req: drkey.ASHostMeta{ SrcIA: ia111, DstIA: ia112, - DstHost: tcpHost1.IP().String(), + DstHost: tcpHost1.Addr().String(), }, assertErr: assert.Error, }, "mismatch addr": { - peerAddr: tcpHost1.TCPAddr(), + peerAddr: net.TCPAddrFromAddrPort(tcpHost1), req: drkey.ASHostMeta{ SrcIA: ia111, DstIA: ia112, - DstHost: tcpHost2.IP().String(), + DstHost: tcpHost2.Addr().String(), }, LocalIA: ia112, assertErr: assert.Error, }, "valid host": { - peerAddr: tcpHost2.TCPAddr(), + peerAddr: net.TCPAddrFromAddrPort(tcpHost2), req: drkey.ASHostMeta{ SrcIA: ia111, DstIA: ia112, - DstHost: tcpHost2.IP().String(), + DstHost: tcpHost2.Addr().String(), }, LocalIA: ia112, assertErr: assert.NoError, @@ -177,7 +177,7 @@ func TestValidateHostASReq(t *testing.T) { assertErr assert.ErrorAssertionFunc }{ "no host": { - peerAddr: tcpHost1.TCPAddr(), + peerAddr: net.TCPAddrFromAddrPort(tcpHost1), req: drkey.HostASMeta{ SrcIA: ia111, DstIA: ia112, @@ -186,16 +186,16 @@ func TestValidateHostASReq(t *testing.T) { assertErr: assert.Error, }, "no localIA": { - peerAddr: tcpHost1.TCPAddr(), + peerAddr: net.TCPAddrFromAddrPort(tcpHost1), req: drkey.HostASMeta{ SrcIA: ia111, DstIA: ia112, - SrcHost: tcpHost1.IP().String(), + SrcHost: tcpHost1.Addr().String(), }, assertErr: assert.Error, }, "mismatch addr": { - peerAddr: tcpHost2.TCPAddr(), + peerAddr: net.TCPAddrFromAddrPort(tcpHost2), req: drkey.HostASMeta{ SrcIA: ia111, DstIA: ia112, @@ -205,11 +205,11 @@ func TestValidateHostASReq(t *testing.T) { assertErr: assert.Error, }, "valid src": { - peerAddr: tcpHost1.TCPAddr(), + peerAddr: net.TCPAddrFromAddrPort(tcpHost1), req: drkey.HostASMeta{ SrcIA: ia111, DstIA: ia112, - SrcHost: tcpHost1.IP().String(), + SrcHost: tcpHost1.Addr().String(), }, LocalIA: ia111, assertErr: assert.NoError, @@ -233,7 +233,7 @@ func TestValidateHostHostReq(t *testing.T) { assertErr assert.ErrorAssertionFunc }{ "no host": { - peerAddr: tcpHost1.TCPAddr(), + peerAddr: net.TCPAddrFromAddrPort(tcpHost1), req: drkey.HostHostMeta{ SrcIA: ia111, DstIA: ia112, @@ -242,44 +242,44 @@ func TestValidateHostHostReq(t *testing.T) { assertErr: assert.Error, }, "no localIA": { - peerAddr: tcpHost1.TCPAddr(), + peerAddr: net.TCPAddrFromAddrPort(tcpHost1), req: drkey.HostHostMeta{ SrcIA: ia111, DstIA: ia112, - SrcHost: tcpHost1.IP().String(), - DstHost: tcpHost2.IP().String(), + SrcHost: tcpHost1.Addr().String(), + DstHost: tcpHost2.Addr().String(), }, assertErr: assert.Error, }, "mismatch addr": { - peerAddr: tcpHost2.TCPAddr(), + peerAddr: net.TCPAddrFromAddrPort(tcpHost2), req: drkey.HostHostMeta{ SrcIA: ia111, DstIA: ia112, - SrcHost: tcpHost1.IP().String(), - DstHost: tcpHost2.IP().String(), + SrcHost: tcpHost1.Addr().String(), + DstHost: tcpHost2.Addr().String(), }, LocalIA: ia111, assertErr: assert.Error, }, "valid src": { - peerAddr: tcpHost1.TCPAddr(), + peerAddr: net.TCPAddrFromAddrPort(tcpHost1), req: drkey.HostHostMeta{ SrcIA: ia111, DstIA: ia112, - SrcHost: tcpHost1.IP().String(), - DstHost: tcpHost2.IP().String(), + SrcHost: tcpHost1.Addr().String(), + DstHost: tcpHost2.Addr().String(), }, LocalIA: ia111, assertErr: assert.NoError, }, "valid dst": { - peerAddr: tcpHost2.TCPAddr(), + peerAddr: net.TCPAddrFromAddrPort(tcpHost2), req: drkey.HostHostMeta{ SrcIA: ia111, DstIA: ia112, - SrcHost: tcpHost1.IP().String(), - DstHost: tcpHost2.IP().String(), + SrcHost: tcpHost1.Addr().String(), + DstHost: tcpHost2.Addr().String(), }, LocalIA: ia112, assertErr: assert.NoError, @@ -321,7 +321,7 @@ func TestASHost(t *testing.T) { Engine: engine, } remotePeer := peer.Peer{ - Addr: tcpHost1.TCPAddr(), + Addr: net.TCPAddrFromAddrPort(tcpHost1), } request := &cppb.DRKeyASHostRequest{ ProtocolId: 200, @@ -352,7 +352,7 @@ func TestHostAS(t *testing.T) { Engine: engine, } remotePeer := peer.Peer{ - Addr: tcpHost1.TCPAddr(), + Addr: net.TCPAddrFromAddrPort(tcpHost1), } request := &cppb.DRKeyHostASRequest{ ProtocolId: 200, @@ -383,7 +383,7 @@ func TestHostHost(t *testing.T) { Engine: engine, } remotePeer := peer.Peer{ - Addr: tcpHost1.TCPAddr(), + Addr: net.TCPAddrFromAddrPort(tcpHost1), } request := &cppb.DRKeyHostHostRequest{ ProtocolId: 200, diff --git a/control/ifstate/BUILD.bazel b/control/ifstate/BUILD.bazel index df10c51193..cbd9054189 100644 --- a/control/ifstate/BUILD.bazel +++ b/control/ifstate/BUILD.bazel @@ -11,7 +11,6 @@ go_library( deps = [ "//pkg/addr:go_default_library", "//private/topology:go_default_library", - "@af_inet_netaddr//:go_default_library", ], ) diff --git a/control/ifstate/ifstate.go b/control/ifstate/ifstate.go index f43b7133e1..5fa04e4fa8 100644 --- a/control/ifstate/ifstate.go +++ b/control/ifstate/ifstate.go @@ -15,11 +15,10 @@ package ifstate import ( + "net/netip" "sync" "time" - "inet.af/netaddr" - "github.com/scionproto/scion/pkg/addr" "github.com/scionproto/scion/private/topology" ) @@ -32,7 +31,7 @@ type InterfaceInfo struct { LinkType topology.LinkType // InternalAddr is the AS-internal address of the router that owns this // interface. - InternalAddr netaddr.IPPort + InternalAddr netip.AddrPort // RemoteID is the remote interface ID. RemoteID uint16 // MTU is the SCION MTU supported on this interface. diff --git a/gateway/BUILD.bazel b/gateway/BUILD.bazel index c15e426386..20a9406fb5 100644 --- a/gateway/BUILD.bazel +++ b/gateway/BUILD.bazel @@ -38,7 +38,6 @@ go_library( "//private/service:go_default_library", "//private/svc:go_default_library", "//private/worker:go_default_library", - "@af_inet_netaddr//:go_default_library", "@com_github_lucas_clemente_quic_go//:go_default_library", "@com_github_prometheus_client_golang//prometheus:go_default_library", "@com_github_prometheus_client_golang//prometheus/promauto:go_default_library", diff --git a/gateway/control/BUILD.bazel b/gateway/control/BUILD.bazel index f00b574b03..d574dcb612 100644 --- a/gateway/control/BUILD.bazel +++ b/gateway/control/BUILD.bazel @@ -36,10 +36,10 @@ go_library( "//pkg/snet:go_default_library", "//private/path/pathpol:go_default_library", "//private/worker:go_default_library", - "@af_inet_netaddr//:go_default_library", "@com_github_google_gopacket//:go_default_library", "@com_github_google_gopacket//layers:go_default_library", "@com_github_olekukonko_tablewriter//:go_default_library", + "@org_go4_netipx//:go_default_library", "@org_golang_google_protobuf//proto:go_default_library", ], ) diff --git a/gateway/control/grpc/BUILD.bazel b/gateway/control/grpc/BUILD.bazel index 90bf20e99d..b020d0a8a2 100644 --- a/gateway/control/grpc/BUILD.bazel +++ b/gateway/control/grpc/BUILD.bazel @@ -22,7 +22,6 @@ go_library( "//pkg/proto/gateway:go_default_library", "//pkg/snet:go_default_library", "//pkg/sock/reliable:go_default_library", - "@af_inet_netaddr//:go_default_library", "@org_golang_google_grpc//codes:go_default_library", "@org_golang_google_grpc//peer:go_default_library", "@org_golang_google_grpc//status:go_default_library", diff --git a/gateway/control/grpc/mock_grpc/BUILD.bazel b/gateway/control/grpc/mock_grpc/BUILD.bazel index f22bc97ea3..ba9de36685 100644 --- a/gateway/control/grpc/mock_grpc/BUILD.bazel +++ b/gateway/control/grpc/mock_grpc/BUILD.bazel @@ -16,7 +16,6 @@ go_library( visibility = ["//visibility:public"], deps = [ "//pkg/addr:go_default_library", - "@af_inet_netaddr//:go_default_library", "@com_github_golang_mock//gomock:go_default_library", ], ) diff --git a/gateway/control/grpc/mock_grpc/mock.go b/gateway/control/grpc/mock_grpc/mock.go index 13418bf5d4..4a00edcf0c 100644 --- a/gateway/control/grpc/mock_grpc/mock.go +++ b/gateway/control/grpc/mock_grpc/mock.go @@ -5,11 +5,11 @@ package mock_grpc import ( + netip "net/netip" reflect "reflect" gomock "github.com/golang/mock/gomock" addr "github.com/scionproto/scion/pkg/addr" - netaddr "inet.af/netaddr" ) // MockAdvertiser is a mock of Advertiser interface. @@ -36,10 +36,10 @@ func (m *MockAdvertiser) EXPECT() *MockAdvertiserMockRecorder { } // AdvertiseList mocks base method. -func (m *MockAdvertiser) AdvertiseList(arg0, arg1 addr.IA) ([]netaddr.IPPrefix, error) { +func (m *MockAdvertiser) AdvertiseList(arg0, arg1 addr.IA) ([]netip.Prefix, error) { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "AdvertiseList", arg0, arg1) - ret0, _ := ret[0].([]netaddr.IPPrefix) + ret0, _ := ret[0].([]netip.Prefix) ret1, _ := ret[1].(error) return ret0, ret1 } diff --git a/gateway/control/grpc/prefix_server.go b/gateway/control/grpc/prefix_server.go index e53f8607c6..421af07610 100644 --- a/gateway/control/grpc/prefix_server.go +++ b/gateway/control/grpc/prefix_server.go @@ -16,11 +16,11 @@ package grpc import ( "context" + "net/netip" "google.golang.org/grpc/codes" "google.golang.org/grpc/peer" "google.golang.org/grpc/status" - "inet.af/netaddr" "github.com/scionproto/scion/pkg/addr" "github.com/scionproto/scion/pkg/metrics" @@ -30,7 +30,7 @@ import ( // Advertiser returns a list of IP prefixes to advertise. type Advertiser interface { - AdvertiseList(from, to addr.IA) ([]netaddr.IPPrefix, error) + AdvertiseList(from, to addr.IA) ([]netip.Prefix, error) } // IPPrefixServer serves IP prefix requests. @@ -68,7 +68,7 @@ func (s IPPrefixServer) Prefixes(ctx context.Context, continue } pb = append(pb, &gpb.Prefix{ - Prefix: canonicalIP(prefix.IP()), + Prefix: canonicalIP(prefix.Addr()), Mask: uint32(prefix.Bits()), }) } @@ -77,7 +77,7 @@ func (s IPPrefixServer) Prefixes(ctx context.Context, }, nil } -func canonicalIP(ip netaddr.IP) []byte { +func canonicalIP(ip netip.Addr) []byte { if ip.Is4() { a4 := ip.As4() return append([]byte(nil), a4[:]...) diff --git a/gateway/control/prefixesfilter.go b/gateway/control/prefixesfilter.go index 03f744df89..3ac09833e4 100644 --- a/gateway/control/prefixesfilter.go +++ b/gateway/control/prefixesfilter.go @@ -17,7 +17,7 @@ package control import ( "net" - "inet.af/netaddr" + "go4.org/netipx" "github.com/scionproto/scion/gateway/routing" "github.com/scionproto/scion/pkg/addr" @@ -62,11 +62,11 @@ func (f PrefixesFilter) Prefixes( if rp == nil { return nil } - var sb netaddr.IPSetBuilder + var sb netipx.IPSetBuilder allowedCount := 0 rejectedCount := 0 for _, prefix := range prefixes { - p, ok := netaddr.FromStdIPNet(prefix) + p, ok := netipx.FromStdIPNet(prefix) if !ok { return serrors.New("can not convert prefix", "prefix", prefix) } @@ -92,7 +92,7 @@ func (f PrefixesFilter) Prefixes( } var allowedPrefixes []*net.IPNet for _, prefix := range set.Prefixes() { - allowedPrefixes = append(allowedPrefixes, prefix.IPNet()) + allowedPrefixes = append(allowedPrefixes, netipx.PrefixIPNet(prefix)) } return f.Consumer.Prefixes(remote, gateway, allowedPrefixes) } diff --git a/gateway/gateway.go b/gateway/gateway.go index bdd994d5db..14103af340 100644 --- a/gateway/gateway.go +++ b/gateway/gateway.go @@ -19,6 +19,7 @@ import ( "encoding/json" "net" "net/http" + "net/netip" "os" "strconv" "time" @@ -26,7 +27,6 @@ import ( quic "github.com/lucas-clemente/quic-go" "github.com/prometheus/client_golang/prometheus" "google.golang.org/grpc" - "inet.af/netaddr" "github.com/scionproto/scion/gateway/control" controlgrpc "github.com/scionproto/scion/gateway/control/grpc" @@ -156,7 +156,7 @@ type SelectAdvertisedRoutes struct { ConfigPublisher *control.ConfigPublisher } -func (a *SelectAdvertisedRoutes) AdvertiseList(from, to addr.IA) ([]netaddr.IPPrefix, error) { +func (a *SelectAdvertisedRoutes) AdvertiseList(from, to addr.IA) ([]netip.Prefix, error) { return routing.AdvertiseList(a.ConfigPublisher.RoutingPolicy(), from, to) } diff --git a/gateway/routing/BUILD.bazel b/gateway/routing/BUILD.bazel index 832377c1f2..be44c3ae8b 100644 --- a/gateway/routing/BUILD.bazel +++ b/gateway/routing/BUILD.bazel @@ -16,7 +16,7 @@ go_library( deps = [ "//pkg/addr:go_default_library", "//pkg/private/serrors:go_default_library", - "@af_inet_netaddr//:go_default_library", + "@org_go4_netipx//:go_default_library", ], ) @@ -36,7 +36,6 @@ go_test( "//gateway/routing/mock_routing:go_default_library", "//pkg/addr:go_default_library", "//pkg/private/xtest:go_default_library", - "@af_inet_netaddr//:go_default_library", "@com_github_golang_mock//gomock:go_default_library", "@com_github_stretchr_testify//assert:go_default_library", "@com_github_stretchr_testify//require:go_default_library", diff --git a/gateway/routing/advertise.go b/gateway/routing/advertise.go index 01b47c5fc4..36f252aa6b 100644 --- a/gateway/routing/advertise.go +++ b/gateway/routing/advertise.go @@ -16,19 +16,20 @@ package routing import ( "net" + "net/netip" - "inet.af/netaddr" + "go4.org/netipx" "github.com/scionproto/scion/pkg/addr" ) // AdvertiseList returns the list of prefixes to advertise for the given policy // and ISD-ASes. -func AdvertiseList(pol *Policy, from, to addr.IA) ([]netaddr.IPPrefix, error) { +func AdvertiseList(pol *Policy, from, to addr.IA) ([]netip.Prefix, error) { if pol == nil { - return []netaddr.IPPrefix{}, nil + return []netip.Prefix{}, nil } - var nets []netaddr.IPPrefix + var nets []netip.Prefix for _, r := range pol.Rules { if r.Action != Advertise || !r.From.Match(from) || !r.To.Match(to) { continue @@ -56,7 +57,7 @@ func StaticAdvertised(pol *Policy) []*net.IPNet { continue } for _, prefix := range r.Network.Allowed { - nets = append(nets, prefix.IPNet()) + nets = append(nets, netipx.PrefixIPNet(prefix)) } } return nets diff --git a/gateway/routing/export_test.go b/gateway/routing/export_test.go index 8429004412..9f54dbf9cc 100644 --- a/gateway/routing/export_test.go +++ b/gateway/routing/export_test.go @@ -15,11 +15,10 @@ package routing import ( + "net/netip" "strings" "testing" - "inet.af/netaddr" - "github.com/scionproto/scion/pkg/private/xtest" ) @@ -50,7 +49,7 @@ func NewNetworkMatcher(t *testing.T, networks string) NetworkMatcher { } matcher := NetworkMatcher{Negated: negated} for _, network := range strings.Split(networks, ",") { - matcher.Allowed = append(matcher.Allowed, netaddr.MustParseIPPrefix(network)) + matcher.Allowed = append(matcher.Allowed, netip.MustParsePrefix(network)) } return matcher } diff --git a/gateway/routing/ipset.go b/gateway/routing/ipset.go index 3f41251b0e..9e052c0886 100644 --- a/gateway/routing/ipset.go +++ b/gateway/routing/ipset.go @@ -15,24 +15,25 @@ package routing import ( + "net/netip" "strings" - "inet.af/netaddr" + "go4.org/netipx" ) -// IPSet is the same as netaddr.IPSet except that it can be converted to/from string. +// IPSet is the same as netipx.IPSet except that it can be converted to/from string. type IPSet struct { - netaddr.IPSet + netipx.IPSet } func ParseIPSet(s string) (IPSet, error) { - var sb netaddr.IPSetBuilder + var sb netipx.IPSetBuilder prefixes := strings.Split(s, ",") for _, prefix := range prefixes { if prefix == "" { continue } - p, err := netaddr.ParseIPPrefix(prefix) + p, err := netip.ParsePrefix(prefix) if err != nil { return IPSet{}, err } diff --git a/gateway/routing/marshal.go b/gateway/routing/marshal.go index 654962284a..5b59ec3a88 100644 --- a/gateway/routing/marshal.go +++ b/gateway/routing/marshal.go @@ -19,11 +19,10 @@ import ( "bytes" "fmt" "net" + "net/netip" "strings" "text/tabwriter" - "inet.af/netaddr" - "github.com/scionproto/scion/pkg/addr" "github.com/scionproto/scion/pkg/private/serrors" ) @@ -147,9 +146,9 @@ func parseNetworkMatcher(b []byte) (NetworkMatcher, error) { negative = true b = b[1:] } - var networks []netaddr.IPPrefix + var networks []netip.Prefix for _, network := range bytes.Split(b, []byte(",")) { - n, err := netaddr.ParseIPPrefix(string(network)) + n, err := netip.ParsePrefix(string(network)) if err != nil { return NetworkMatcher{}, serrors.WrapStr("parsing network", err) } diff --git a/gateway/routing/policy.go b/gateway/routing/policy.go index f577cf9c1e..17c5f8a07b 100644 --- a/gateway/routing/policy.go +++ b/gateway/routing/policy.go @@ -18,9 +18,10 @@ import ( "crypto/sha256" "fmt" "net" + "net/netip" "strings" - "inet.af/netaddr" + "go4.org/netipx" "github.com/scionproto/scion/pkg/addr" ) @@ -71,12 +72,12 @@ func (p Policy) Digest() []byte { } // Match matches an IP range to the policy and returns the subranges that satisfy it. -func (p Policy) Match(from, to addr.IA, ipPrefix netaddr.IPPrefix) (IPSet, error) { +func (p Policy) Match(from, to addr.IA, ipPrefix netip.Prefix) (IPSet, error) { // Compile the rules into a set of allowed addresses. - var sb netaddr.IPSetBuilder + var sb netipx.IPSetBuilder if p.DefaultAction == Accept { - sb.AddPrefix(netaddr.MustParseIPPrefix("0.0.0.0/0")) - sb.AddPrefix(netaddr.MustParseIPPrefix("::/0")) + sb.AddPrefix(netip.MustParsePrefix("0.0.0.0/0")) + sb.AddPrefix(netip.MustParsePrefix("::/0")) } for i := len(p.Rules) - 1; i >= 0; i-- { rule := p.Rules[i] @@ -95,7 +96,7 @@ func (p Policy) Match(from, to addr.IA, ipPrefix netaddr.IPPrefix) (IPSet, error } } // Intersect the supplied IP range with the allowed range to get the result. - var nb netaddr.IPSetBuilder + var nb netipx.IPSetBuilder nb.AddPrefix(ipPrefix) ns, err := nb.IPSet() if err != nil { @@ -126,13 +127,13 @@ type IAMatcher interface { // NetworkMatcher matches IP networks. type NetworkMatcher struct { - Allowed []netaddr.IPPrefix + Allowed []netip.Prefix Negated bool } // IPSet returns a set containing all IPs allowed by the matcher. -func (m NetworkMatcher) IPSet() (*netaddr.IPSet, error) { - var sb netaddr.IPSetBuilder +func (m NetworkMatcher) IPSet() (*netipx.IPSet, error) { + var sb netipx.IPSetBuilder for _, prefix := range m.Allowed { sb.AddPrefix(prefix) } diff --git a/gateway/routing/policy_test.go b/gateway/routing/policy_test.go index 194f7df729..3a4171b009 100644 --- a/gateway/routing/policy_test.go +++ b/gateway/routing/policy_test.go @@ -15,11 +15,11 @@ package routing_test import ( + "net/netip" "testing" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" - "inet.af/netaddr" "github.com/scionproto/scion/gateway/routing" "github.com/scionproto/scion/pkg/private/xtest" @@ -201,7 +201,7 @@ func TestNetworkMatch(t *testing.T) { To: iaMatcher, } } - out, err := tc.policy.Match(ia, ia, netaddr.MustParseIPPrefix(tc.in)) + out, err := tc.policy.Match(ia, ia, netip.MustParsePrefix(tc.in)) assert.NoError(t, err) assert.Equal(t, tc.out, out.String()) }) diff --git a/go.mod b/go.mod index ab01fd8f95..dda75b54f2 100644 --- a/go.mod +++ b/go.mod @@ -41,6 +41,7 @@ require ( github.com/vishvananda/netlink v1.2.1-beta.2 go.uber.org/goleak v1.2.1 go.uber.org/zap v1.24.0 + go4.org/netipx v0.0.0-20230125063823-8449b0a6169f golang.org/x/crypto v0.6.0 golang.org/x/net v0.7.0 golang.org/x/sync v0.1.0 @@ -49,7 +50,6 @@ require ( google.golang.org/grpc/examples v0.0.0-20230222033013-5353eaa44095 google.golang.org/protobuf v1.28.1 gopkg.in/yaml.v2 v2.4.0 - inet.af/netaddr v0.0.0-20220811202034-502d2d690317 ) require ( @@ -107,8 +107,6 @@ require ( github.com/vishvananda/netns v0.0.0-20200728191858-db3c7e526aae // indirect go.uber.org/atomic v1.9.0 // indirect go.uber.org/multierr v1.8.0 // indirect - go4.org/intern v0.0.0-20211027215823-ae77deb06f29 // indirect - go4.org/unsafe/assume-no-moving-gc v0.0.0-20220617031537-928513b29760 // indirect golang.org/x/exp v0.0.0-20220722155223-a9213eeb770e // indirect golang.org/x/mod v0.8.0 // indirect golang.org/x/sys v0.5.0 // indirect diff --git a/go.sum b/go.sum index c8e8da25e0..b77723de2a 100644 --- a/go.sum +++ b/go.sum @@ -95,7 +95,6 @@ github.com/docker/cli v20.10.20+incompatible h1:lWQbHSHUFs7KraSN2jOJK7zbMS2jNCHI github.com/docker/distribution v2.8.1+incompatible h1:Q50tZOPR6T/hjNsyc9g8/syEs6bk8XXApsHjKukMl68= github.com/docker/docker v20.10.20+incompatible h1:kH9tx6XO+359d+iAkumyKDc5Q1kOwPuAUaeri48nD6E= github.com/docker/docker-credential-helpers v0.7.0 h1:xtCHsjxogADNZcdv1pKUHXryefjlVRqWqIhk/uXJp0A= -github.com/dvyukov/go-fuzz v0.0.0-20210103155950-6a8e9d1f2415/go.mod h1:11Gm+ccJnvAhCNLlf5+cS9KjtbaD5I5zaZpFMsTHWTw= github.com/envoyproxy/go-control-plane v0.9.0/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4= github.com/envoyproxy/go-control-plane v0.9.1-0.20191026205805-5f8ba28d4473/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4= github.com/envoyproxy/go-control-plane v0.9.4/go.mod h1:6rpuAdCZL397s3pYoYcLgu1mIlRU8Am5FuJP05cCM98= @@ -453,11 +452,8 @@ go.uber.org/multierr v1.8.0/go.mod h1:7EAYxJLBy9rStEaz58O2t4Uvip6FSURkq8/ppBp95a go.uber.org/zap v1.10.0/go.mod h1:vwi/ZaCAaUcBkycHslxD9B2zi4UTXhF60s6SWpuDF0Q= go.uber.org/zap v1.24.0 h1:FiJd5l1UOLj0wCgbSE0rwwXHzEdAZS6hiiSnxJN/D60= go.uber.org/zap v1.24.0/go.mod h1:2kMP+WWQ8aoFoedH3T2sq6iJ2yDWpHbP0f6MQbS9Gkg= -go4.org/intern v0.0.0-20211027215823-ae77deb06f29 h1:UXLjNohABv4S58tHmeuIZDO6e3mHpW2Dx33gaNt03LE= -go4.org/intern v0.0.0-20211027215823-ae77deb06f29/go.mod h1:cS2ma+47FKrLPdXFpr7CuxiTW3eyJbWew4qx0qtQWDA= -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= +go4.org/netipx v0.0.0-20230125063823-8449b0a6169f h1:ketMxHg+vWm3yccyYiq+uK8D3fRmna2Fcj+awpQp84s= +go4.org/netipx v0.0.0-20230125063823-8449b0a6169f/go.mod h1:tgPU4N2u9RByaTN3NC2p9xOzyFpte4jYwsIIRF7XlSc= golang.org/x/crypto v0.0.0-20180904163835-0709b304e793/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= golang.org/x/crypto v0.0.0-20190510104115-cbcb75029529/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= @@ -835,8 +831,6 @@ honnef.co/go/tools v0.0.0-20190523083050-ea95bdfd59fc/go.mod h1:rf3lG4BRIbNafJWh honnef.co/go/tools v0.0.1-2019.2.3/go.mod h1:a3bituU0lyd329TUQxRnasdCoJDkEUEAqEt0JzvZhAg= honnef.co/go/tools v0.0.1-2020.1.3/go.mod h1:X/FiERA/W4tHapMX5mGpAtMSVEeEUOyHaw9vFzvIQ3k= honnef.co/go/tools v0.0.1-2020.1.4/go.mod h1:X/FiERA/W4tHapMX5mGpAtMSVEeEUOyHaw9vFzvIQ3k= -inet.af/netaddr v0.0.0-20220811202034-502d2d690317 h1:U2fwK6P2EqmopP/hFLTOAjWTki0qgd4GMJn5X8wOleU= -inet.af/netaddr v0.0.0-20220811202034-502d2d690317/go.mod h1:OIezDfdzOgFhuw4HuWapWq2e9l0H9tK4F1j+ETRtF3k= rsc.io/binaryregexp v0.2.0/go.mod h1:qTv7/COck+e2FymRvadv62gMdZztPaShugOCi3I+8D8= rsc.io/quote/v3 v3.1.0/go.mod h1:yEA65RcK8LyAZtP9Kv3t0HmxON59tX3rD+tICJqUlj0= rsc.io/sampler v1.3.0/go.mod h1:T1hPZKmBbMNahiBKFy5HrXp6adAjACjK9JXDnKaTXpA= diff --git a/go_deps.bzl b/go_deps.bzl index 4de35e40dc..af2ee79988 100644 --- a/go_deps.bzl +++ b/go_deps.bzl @@ -7,17 +7,11 @@ load("@bazel_gazelle//:deps.bzl", "go_repository") def go_deps(): - go_repository( - name = "af_inet_netaddr", - importpath = "inet.af/netaddr", - sum = "h1:U2fwK6P2EqmopP/hFLTOAjWTki0qgd4GMJn5X8wOleU=", - version = "v0.0.0-20220811202034-502d2d690317", - ) go_repository( name = "co_honnef_go_tools", importpath = "honnef.co/go/tools", - sum = "h1:UoveltGrhghAA7ePc+e+QYDHXrBps2PqFZiHkGR/xK8=", - version = "v0.0.1-2020.1.4", + sum = "h1:ytYb4rOqyp1TSa2EPvNVwtPQJctSELKaMyLfqNP4+34=", + version = "v0.3.2", ) go_repository( name = "com_github_alecthomas_template", @@ -88,8 +82,8 @@ def go_deps(): go_repository( name = "com_github_burntsushi_toml", importpath = "github.com/BurntSushi/toml", - sum = "h1:WXkYYl6Yr3qBf1K79EBnL4mak0OimBfB0XUf9Vl28OQ=", - version = "v0.3.1", + sum = "h1:GaI7EiDXDRfa8VshkTj7Fym7ha+y8/XxIgD2okUIjLw=", + version = "v0.4.1", ) go_repository( name = "com_github_burntsushi_xgb", @@ -2037,16 +2031,10 @@ def go_deps(): version = "v1.3.0", ) go_repository( - name = "org_go4_intern", - importpath = "go4.org/intern", - sum = "h1:UXLjNohABv4S58tHmeuIZDO6e3mHpW2Dx33gaNt03LE=", - version = "v0.0.0-20211027215823-ae77deb06f29", - ) - go_repository( - name = "org_go4_unsafe_assume_no_moving_gc", - importpath = "go4.org/unsafe/assume-no-moving-gc", - sum = "h1:FyBZqvoA/jbNzuAWLQE2kG820zMAkcilx6BMjGbL/E4=", - version = "v0.0.0-20220617031537-928513b29760", + name = "org_go4_netipx", + importpath = "go4.org/netipx", + sum = "h1:ketMxHg+vWm3yccyYiq+uK8D3fRmna2Fcj+awpQp84s=", + version = "v0.0.0-20230125063823-8449b0a6169f", ) go_repository( name = "org_golang_google_api", @@ -2096,6 +2084,12 @@ def go_deps(): sum = "h1:+WEEuIdZHnUeJJmEUjyYC2gfUMj69yZXw17EnHg/otA=", version = "v0.0.0-20220722155223-a9213eeb770e", ) + go_repository( + name = "org_golang_x_exp_typeparams", + importpath = "golang.org/x/exp/typeparams", + sum = "h1:qyrTQ++p1afMkO4DPEeLGq/3oTsdlvdH4vqZUBWzUKM=", + version = "v0.0.0-20220218215828-6cf2b201936e", + ) go_repository( name = "org_golang_x_image", importpath = "golang.org/x/image", diff --git a/licenses/data/org_go4_intern/LICENSE b/licenses/data/org_go4_intern/LICENSE deleted file mode 100644 index b0ab8921dc..0000000000 --- a/licenses/data/org_go4_intern/LICENSE +++ /dev/null @@ -1,29 +0,0 @@ -BSD 3-Clause License - -Copyright (c) 2020, Brad Fitzpatrick -All rights reserved. - -Redistribution and use in source and binary forms, with or without -modification, are permitted provided that the following conditions are met: - -1. Redistributions of source code must retain the above copyright notice, this - list of conditions and the following disclaimer. - -2. Redistributions in binary form must reproduce the above copyright notice, - this list of conditions and the following disclaimer in the documentation - and/or other materials provided with the distribution. - -3. Neither the name of the copyright holder nor the names of its - contributors may be used to endorse or promote products derived from - this software without specific prior written permission. - -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" -AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE -DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE -FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR -SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER -CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, -OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. diff --git a/licenses/data/af_inet_netaddr/LICENSE b/licenses/data/org_go4_netipx/LICENSE similarity index 100% rename from licenses/data/af_inet_netaddr/LICENSE rename to licenses/data/org_go4_netipx/LICENSE diff --git a/licenses/data/org_go4_unsafe_assume_no_moving_gc/LICENSE b/licenses/data/org_go4_unsafe_assume_no_moving_gc/LICENSE deleted file mode 100644 index b0ab8921dc..0000000000 --- a/licenses/data/org_go4_unsafe_assume_no_moving_gc/LICENSE +++ /dev/null @@ -1,29 +0,0 @@ -BSD 3-Clause License - -Copyright (c) 2020, Brad Fitzpatrick -All rights reserved. - -Redistribution and use in source and binary forms, with or without -modification, are permitted provided that the following conditions are met: - -1. Redistributions of source code must retain the above copyright notice, this - list of conditions and the following disclaimer. - -2. Redistributions in binary form must reproduce the above copyright notice, - this list of conditions and the following disclaimer in the documentation - and/or other materials provided with the distribution. - -3. Neither the name of the copyright holder nor the names of its - contributors may be used to endorse or promote products derived from - this software without specific prior written permission. - -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" -AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE -DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE -FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR -SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER -CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, -OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. diff --git a/pkg/experimental/hiddenpath/BUILD.bazel b/pkg/experimental/hiddenpath/BUILD.bazel index 5da8e413a1..ee33cdb962 100644 --- a/pkg/experimental/hiddenpath/BUILD.bazel +++ b/pkg/experimental/hiddenpath/BUILD.bazel @@ -74,7 +74,6 @@ go_test( "//private/pathdb/query:go_default_library", "//private/topology:go_default_library", "//private/trust:go_default_library", - "@af_inet_netaddr//:go_default_library", "@com_github_golang_mock//gomock:go_default_library", "@com_github_stretchr_testify//assert:go_default_library", "@com_github_stretchr_testify//require:go_default_library", diff --git a/pkg/experimental/hiddenpath/beaconwriter_test.go b/pkg/experimental/hiddenpath/beaconwriter_test.go index 89a6188cfb..95c0891077 100644 --- a/pkg/experimental/hiddenpath/beaconwriter_test.go +++ b/pkg/experimental/hiddenpath/beaconwriter_test.go @@ -22,6 +22,7 @@ import ( "crypto/rand" "hash" "net" + "net/netip" "sort" "testing" "time" @@ -29,7 +30,6 @@ import ( "github.com/golang/mock/gomock" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" - "inet.af/netaddr" "github.com/scionproto/scion/control/beacon" "github.com/scionproto/scion/control/beaconing" @@ -82,7 +82,7 @@ func TestRemoteBeaconWriterWrite(t *testing.T) { assert.Equal(t, pathHopField.ConsEgress, segHopField.ConsEgress) nextHop := pathHopField.ConsIngress - ta := interfaceInfos(topo)[nextHop].InternalAddr.UDPAddr() + ta := net.UDPAddrFromAddrPort(interfaceInfos(topo)[nextHop].InternalAddr) assert.Equal(t, ta, a.NextHop) } } @@ -360,7 +360,7 @@ func interfaceInfos(topo topology.Topology) map[uint16]ifstate.InterfaceInfo { ID: uint16(info.ID), IA: info.IA, LinkType: info.LinkType, - InternalAddr: netaddr.MustParseIPPort(info.InternalAddr.String()), + InternalAddr: netip.MustParseAddrPort(info.InternalAddr.String()), RemoteID: uint16(info.RemoteIFID), MTU: uint16(info.MTU), } diff --git a/pkg/private/xtest/BUILD.bazel b/pkg/private/xtest/BUILD.bazel index aebaf656e1..cb693100c1 100644 --- a/pkg/private/xtest/BUILD.bazel +++ b/pkg/private/xtest/BUILD.bazel @@ -13,7 +13,6 @@ go_library( deps = [ "//pkg/addr:go_default_library", "//pkg/scrypto/cppki:go_default_library", - "@af_inet_netaddr//:go_default_library", "@com_github_stretchr_testify//assert:go_default_library", "@com_github_stretchr_testify//require:go_default_library", "@org_golang_google_grpc//:go_default_library", diff --git a/pkg/private/xtest/helpers.go b/pkg/private/xtest/helpers.go index 406e1d910e..70c893762b 100644 --- a/pkg/private/xtest/helpers.go +++ b/pkg/private/xtest/helpers.go @@ -21,6 +21,7 @@ import ( "encoding/json" "flag" "net" + "net/netip" "os" "path/filepath" "regexp" @@ -29,7 +30,6 @@ import ( "time" "github.com/stretchr/testify/require" - "inet.af/netaddr" "github.com/scionproto/scion/pkg/addr" ) @@ -268,12 +268,12 @@ func MustParseCIDRs(t *testing.T, entries ...string) []*net.IPNet { } // MustParseIPPrefixes parses the CIDR entries and returns a list containing the -// parsed netaddr.IPPrefix objects. -func MustParseIPPrefixes(t *testing.T, prefixes ...string) []netaddr.IPPrefix { +// parsed netip.Prefix objects. +func MustParseIPPrefixes(t *testing.T, prefixes ...string) []netip.Prefix { t.Helper() - var result []netaddr.IPPrefix + var result []netip.Prefix for _, prefix := range prefixes { - p, err := netaddr.ParseIPPrefix(prefix) + p, err := netip.ParsePrefix(prefix) require.NoError(t, err) result = append(result, p) } diff --git a/pkg/snet/BUILD.bazel b/pkg/snet/BUILD.bazel index d2ab4a31b8..66f0c6f674 100644 --- a/pkg/snet/BUILD.bazel +++ b/pkg/snet/BUILD.bazel @@ -33,7 +33,6 @@ go_library( "//pkg/slayers/path/epic:go_default_library", "//pkg/sock/reliable:go_default_library", "//private/topology/underlay:go_default_library", - "@af_inet_netaddr//:go_default_library", "@com_github_google_gopacket//:go_default_library", ], ) diff --git a/pkg/snet/udpaddr.go b/pkg/snet/udpaddr.go index b207681178..6d741fea76 100644 --- a/pkg/snet/udpaddr.go +++ b/pkg/snet/udpaddr.go @@ -22,8 +22,6 @@ import ( "strconv" "strings" - "inet.af/netaddr" - "github.com/scionproto/scion/pkg/addr" "github.com/scionproto/scion/pkg/private/serrors" ) @@ -191,8 +189,8 @@ func parseAddr(s string) (string, string, error) { } func ipOnly(s string) bool { - _, portErr := netaddr.ParseIPPort(s) - _, ipErr := netaddr.ParseIP(strings.Trim(s, "[]")) + _, portErr := netip.ParseAddrPort(s) + _, ipErr := netip.ParseAddr(strings.Trim(s, "[]")) return portErr != nil && ipErr == nil } diff --git a/private/app/flag/BUILD.bazel b/private/app/flag/BUILD.bazel index f642420454..2dddf09adb 100644 --- a/private/app/flag/BUILD.bazel +++ b/private/app/flag/BUILD.bazel @@ -16,7 +16,6 @@ go_library( "//pkg/private/util:go_default_library", "//pkg/sock/reliable:go_default_library", "//private/app/env:go_default_library", - "@af_inet_netaddr//:go_default_library", "@com_github_spf13_pflag//:go_default_library", ], ) @@ -34,7 +33,6 @@ go_test( "//pkg/private/xtest:go_default_library", "//pkg/sock/reliable:go_default_library", "//private/app/env:go_default_library", - "@af_inet_netaddr//:go_default_library", "@com_github_spf13_pflag//:go_default_library", "@com_github_stretchr_testify//assert:go_default_library", "@com_github_stretchr_testify//require:go_default_library", diff --git a/private/app/flag/env.go b/private/app/flag/env.go index b223e0b70a..964534f62b 100644 --- a/private/app/flag/env.go +++ b/private/app/flag/env.go @@ -18,11 +18,11 @@ import ( "encoding/json" "errors" "io/fs" + "net/netip" "os" "sync" "github.com/spf13/pflag" - "inet.af/netaddr" "github.com/scionproto/scion/pkg/addr" "github.com/scionproto/scion/pkg/daemon" @@ -62,10 +62,10 @@ func (v *iaVal) Set(val string) error { func (v *iaVal) Type() string { return "isd-as" } func (v *iaVal) String() string { return addr.IA(*v).String() } -type ipVal netaddr.IP +type ipVal netip.Addr func (v *ipVal) Set(val string) error { - ip, err := netaddr.ParseIP(val) + ip, err := netip.ParseAddr(val) if err != nil { return err } @@ -74,7 +74,7 @@ func (v *ipVal) Set(val string) error { } func (v *ipVal) Type() string { return "ip" } -func (v *ipVal) String() string { return netaddr.IP(*v).String() } +func (v *ipVal) String() string { return netip.Addr(*v).String() } // SCIONEnvironment can be used to access the common SCION configuration values, // like the SCION daemon address, the dispatcher socket address and the local IP @@ -86,8 +86,8 @@ type SCIONEnvironment struct { iaFlag *pflag.Flag dispFlag *pflag.Flag dispEnv *string - local netaddr.IP - localEnv *netaddr.IP + local netip.Addr + localEnv *netip.Addr localFlag *pflag.Flag file env.SCION filepath string @@ -165,7 +165,7 @@ func (e *SCIONEnvironment) loadEnv() error { e.dispEnv = &d } if l, ok := os.LookupEnv("SCION_LOCAL_ADDR"); ok { - a, err := netaddr.ParseIP(l) + a, err := netip.ParseAddr(l) if err != nil { return serrors.WrapStr("parsing SCION_LOCAL_ADDR", err) } @@ -222,12 +222,12 @@ func (e *SCIONEnvironment) Dispatcher() string { return defaultDispatcher } -// Local returns the loca IP to listen on. The value is loaded from one of the +// Local returns the local IP to listen on. The value is loaded from one of the // following sources with the precedence as listed: // 1. Command line flag // 2. Environment variable // 3. Default value. -func (e *SCIONEnvironment) Local() netaddr.IP { +func (e *SCIONEnvironment) Local() netip.Addr { e.mtx.Lock() defer e.mtx.Unlock() @@ -237,5 +237,5 @@ func (e *SCIONEnvironment) Local() netaddr.IP { if e.localEnv != nil { return *e.localEnv } - return netaddr.IP{} + return netip.Addr{} } diff --git a/private/app/flag/env_test.go b/private/app/flag/env_test.go index 4aafe8609f..cb5d9737cb 100644 --- a/private/app/flag/env_test.go +++ b/private/app/flag/env_test.go @@ -16,13 +16,13 @@ package flag_test import ( "encoding/json" + "net/netip" "os" "testing" "github.com/spf13/pflag" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" - "inet.af/netaddr" "github.com/scionproto/scion/pkg/addr" "github.com/scionproto/scion/pkg/daemon" @@ -79,7 +79,7 @@ func TestSCIONEnvironment(t *testing.T) { env func(t *testing.T) daemon string dispatcher string - local netaddr.IP + local netip.Addr }{ "no flag, no file, no env, defaults only": { flags: noFlags, @@ -87,7 +87,7 @@ func TestSCIONEnvironment(t *testing.T) { file: noFile, daemon: daemon.DefaultAPIAddress, dispatcher: reliable.DefaultDispPath, - local: netaddr.IP{}, + local: netip.Addr{}, }, "flag values set": { flags: setupFlags, @@ -95,7 +95,7 @@ func TestSCIONEnvironment(t *testing.T) { file: noFile, daemon: "scion:1234", dispatcher: "/test/dispatcher.socket", - local: netaddr.MustParseIP("10.0.0.42"), + local: netip.MustParseAddr("10.0.0.42"), }, "env values set": { flags: noFlags, @@ -103,7 +103,7 @@ func TestSCIONEnvironment(t *testing.T) { file: noFile, daemon: "scion_env:1234", dispatcher: "/test/dispatcher_env.socket", - local: netaddr.MustParseIP("10.0.42.0"), + local: netip.MustParseAddr("10.0.42.0"), }, "file values set": { flags: noFlags, @@ -111,7 +111,7 @@ func TestSCIONEnvironment(t *testing.T) { file: setupFile, daemon: "scion_file:1234", dispatcher: "/test/dispatcher_file.socket", - local: netaddr.IP{}, + local: netip.Addr{}, }, "all set, flag precedence": { flags: setupFlags, @@ -119,7 +119,7 @@ func TestSCIONEnvironment(t *testing.T) { file: setupFile, daemon: "scion:1234", dispatcher: "/test/dispatcher.socket", - local: netaddr.MustParseIP("10.0.0.42"), + local: netip.MustParseAddr("10.0.0.42"), }, "env set, file set, env precedence": { flags: noFlags, @@ -127,7 +127,7 @@ func TestSCIONEnvironment(t *testing.T) { file: setupFile, daemon: "scion_env:1234", dispatcher: "/test/dispatcher_env.socket", - local: netaddr.MustParseIP("10.0.42.0"), + local: netip.MustParseAddr("10.0.42.0"), }, } for name, tc := range testCases { diff --git a/scion-pki/certs/renew.go b/scion-pki/certs/renew.go index 7ae4a1e577..498b6d2770 100644 --- a/scion-pki/certs/renew.go +++ b/scion-pki/certs/renew.go @@ -264,7 +264,7 @@ The template is expressed in JSON. A valid example:: } daemonAddr := envFlags.Daemon() dispatcher := envFlags.Dispatcher() - localIP := envFlags.Local().IPAddr().IP + localIP := net.IP(envFlags.Local().AsSlice()) log.Debug("Resolved SCION environment flags", "daemon", daemonAddr, "dispatcher", dispatcher, diff --git a/scion/cmd/scion/ping.go b/scion/cmd/scion/ping.go index 065f4fd28a..df6bf02ac1 100644 --- a/scion/cmd/scion/ping.go +++ b/scion/cmd/scion/ping.go @@ -132,7 +132,7 @@ On other errors, ping will exit with code 2. } daemonAddr := envFlags.Daemon() dispatcher := envFlags.Dispatcher() - localIP := envFlags.Local().IPAddr().IP + localIP := net.IP(envFlags.Local().AsSlice()) log.Debug("Resolved SCION environment flags", "daemon", daemonAddr, "dispatcher", dispatcher, diff --git a/scion/cmd/scion/showpaths.go b/scion/cmd/scion/showpaths.go index f531ed9e9c..54e3282994 100644 --- a/scion/cmd/scion/showpaths.go +++ b/scion/cmd/scion/showpaths.go @@ -18,6 +18,7 @@ import ( "context" "encoding/json" "fmt" + "net" "os" "time" @@ -99,7 +100,7 @@ On other errors, showpaths will exit with code 2. flags.cfg.Daemon = envFlags.Daemon() flags.cfg.Dispatcher = envFlags.Dispatcher() - flags.cfg.Local = envFlags.Local().IPAddr().IP + flags.cfg.Local = net.IP(envFlags.Local().AsSlice()) log.Debug("Resolved SCION environment flags", "daemon", flags.cfg.Daemon, "dispatcher", flags.cfg.Dispatcher, diff --git a/scion/cmd/scion/traceroute.go b/scion/cmd/scion/traceroute.go index 228bb37733..0bdf6a5233 100644 --- a/scion/cmd/scion/traceroute.go +++ b/scion/cmd/scion/traceroute.go @@ -108,7 +108,7 @@ On other errors, traceroute will exit with code 2. } daemonAddr := envFlags.Daemon() dispatcher := envFlags.Dispatcher() - localIP := envFlags.Local().IPAddr().IP + localIP := net.IP(envFlags.Local().AsSlice()) log.Debug("Resolved SCION environment flags", "daemon", daemonAddr, "dispatcher", dispatcher,