diff --git a/acceptance/topo_br_reload_if_ip_acceptance/test b/acceptance/topo_br_reload_if_ip_acceptance/test index c387005132..ae30003499 100755 --- a/acceptance/topo_br_reload_if_ip_acceptance/test +++ b/acceptance/topo_br_reload_if_ip_acceptance/test @@ -76,8 +76,8 @@ change_local_ip() { jq ".BorderRouters[].Interfaces[].PublicOverlay.Addr = $3" $1 | sponge $1 ./tools/dc scion kill -s HUP scion_br"$2"-1 sleep 2 - check_logs "posixOutput starting addr=[$(unqoute $3)]" $2 - check_logs "posixInput starting addr=[$(unqoute $3)]" $2 + check_logs "posixOutput starting addr=$(unqoute $3)" $2 + check_logs "posixInput starting addr=$(unqoute $3)" $2 } check_change_remote_ip() { diff --git a/acceptance/topo_br_reload_if_port_acceptance/test b/acceptance/topo_br_reload_if_port_acceptance/test index 07f8c9ce89..f039414f45 100755 --- a/acceptance/topo_br_reload_if_port_acceptance/test +++ b/acceptance/topo_br_reload_if_port_acceptance/test @@ -37,8 +37,8 @@ check_change_local_port() { jq '.BorderRouters[].Interfaces[].PublicOverlay.OverlayPort = 42424' $SRC_TOPO | sponge $SRC_TOPO ./tools/dc scion kill -s HUP scion_br"$SRC_IA_FILE"-1 sleep 2 - check_logs "posixOutput starting addr=[$addr_src]:42424" $SRC_IA_FILE - check_logs "posixInput starting addr=[$addr_src]:42424" $SRC_IA_FILE + check_logs "posixOutput starting addr=$addr_src:42424" $SRC_IA_FILE + check_logs "posixInput starting addr=$addr_src:42424" $SRC_IA_FILE bin/end2end_integration -src $SRC_IA -dst $DST_IA -attempts 1 -d -log.console=crit || local failed=$? if [ -z ${failed+x} ]; then echo "FAIL: Traffic still passes. End check_change_local_port" diff --git a/acceptance/topo_ps_reloads_br_acceptance/test b/acceptance/topo_ps_reloads_br_acceptance/test index 16197fc382..e71b78fe2e 100755 --- a/acceptance/topo_ps_reloads_br_acceptance/test +++ b/acceptance/topo_ps_reloads_br_acceptance/test @@ -33,7 +33,7 @@ test_run() { sleep 6 ./tools/dc exec_tester $SRC_IA_FILE bin/showpaths -srcIA $SRC_IA -dstIA $DST_IA -sciondFromIA || true sleep 2 - grep -q "\[TRACE\] \[Acceptance\] .*overlay=\[127\.42\.42\.42\]" "logs/ps$SRC_IA_FILE-1.log" || \ + grep -q "\[TRACE\] \[Acceptance\] .*overlay=127\.42\.42\.42" "logs/ps$SRC_IA_FILE-1.log" || \ fail "Request to 127.42.42.42 not found in logs" } diff --git a/acceptance/topo_ps_reloads_cs_acceptance/test b/acceptance/topo_ps_reloads_cs_acceptance/test index 9d597a4eaf..8b086e07b5 100755 --- a/acceptance/topo_ps_reloads_cs_acceptance/test +++ b/acceptance/topo_ps_reloads_cs_acceptance/test @@ -32,7 +32,7 @@ test_run() { # Wait for 1 (PS crypto push interval) + 1 (logging flush interval) # + 1 to guarantee a push is seen sleep 3 - grep -q "\[TRACE\] \[Acceptance\] .*overlay=\[127\.42\.42\.42\]" "logs/ps$IA_FILE-1.log" || \ + grep -q "\[TRACE\] \[Acceptance\] .*overlay=127\.42\.42\.42" "logs/ps$IA_FILE-1.log" || \ fail "Push request to 127.42.42.42 not found in logs" } diff --git a/acceptance/topo_sd_reloads_cs_acceptance/test b/acceptance/topo_sd_reloads_cs_acceptance/test index d9c1ef0f48..5474a80384 100755 --- a/acceptance/topo_sd_reloads_cs_acceptance/test +++ b/acceptance/topo_sd_reloads_cs_acceptance/test @@ -33,7 +33,7 @@ test_run() { sleep 1 ./tools/dc exec_tester $SRC_IA_FILE bin/showpaths -srcIA $SRC_IA -dstIA $DST_IA -sciondFromIA -refresh || true sleep 2 - grep -q "\[TRACE\] \[Acceptance\] .*overlay=\[127\.42\.42\.42\]" "logs/sd$SRC_IA_FILE.log" || \ + grep -q "\[TRACE\] \[Acceptance\] .*overlay=127\.42\.42\.42" "logs/sd$SRC_IA_FILE.log" || \ fail "Request to 127.42.42.42 not found in logs" } diff --git a/acceptance/topo_sd_reloads_ps_acceptance/test b/acceptance/topo_sd_reloads_ps_acceptance/test index c8aaf37080..02375be023 100755 --- a/acceptance/topo_sd_reloads_ps_acceptance/test +++ b/acceptance/topo_sd_reloads_ps_acceptance/test @@ -32,7 +32,7 @@ test_run() { sleep 1 ./tools/dc exec_tester $SRC_IA_FILE bin/showpaths -srcIA $SRC_IA -dstIA $DST_IA -sciondFromIA -refresh || true sleep 2 - grep -q "\[TRACE\] \[Acceptance\] .*overlay=\[127\.42\.42\.42\]" "logs/sd$SRC_IA_FILE.log" || \ + grep -q "\[TRACE\] \[Acceptance\] .*overlay=127\.42\.42\.42" "logs/sd$SRC_IA_FILE.log" || \ fail "Request to 127.42.42.42 not found in logs" } diff --git a/go/beacon_srv/internal/beaconing/BUILD.bazel b/go/beacon_srv/internal/beaconing/BUILD.bazel index bf5f65419f..5958c1c82b 100644 --- a/go/beacon_srv/internal/beaconing/BUILD.bazel +++ b/go/beacon_srv/internal/beaconing/BUILD.bazel @@ -67,7 +67,6 @@ go_test( "//go/lib/infra/modules/itopo/itopotest:go_default_library", "//go/lib/infra/modules/trust:go_default_library", "//go/lib/log:go_default_library", - "//go/lib/overlay:go_default_library", "//go/lib/scrypto:go_default_library", "//go/lib/serrors:go_default_library", "//go/lib/snet:go_default_library", diff --git a/go/beacon_srv/internal/beaconing/originator.go b/go/beacon_srv/internal/beaconing/originator.go index 4518820254..e76871294b 100644 --- a/go/beacon_srv/internal/beaconing/originator.go +++ b/go/beacon_srv/internal/beaconing/originator.go @@ -164,7 +164,7 @@ func (o *beaconOriginator) originateBeacon(ctx context.Context) error { return serrors.New("Interface does not exist") } topoInfo := intf.TopoInfo() - ov := topoInfo.InternalAddrs.PublicOverlay(topoInfo.InternalAddrs.Overlay) + ov := topoInfo.InternalAddrs.PublicOverlayUDP(topoInfo.InternalAddrs.Overlay) bseg, err := o.createBeacon() if err != nil { diff --git a/go/beacon_srv/internal/beaconing/originator_test.go b/go/beacon_srv/internal/beaconing/originator_test.go index fd189691c8..9c3dbfbc55 100644 --- a/go/beacon_srv/internal/beaconing/originator_test.go +++ b/go/beacon_srv/internal/beaconing/originator_test.go @@ -18,6 +18,7 @@ import ( "context" "errors" "fmt" + "net" "sync" "testing" "time" @@ -33,7 +34,6 @@ import ( "github.com/scionproto/scion/go/lib/ctrl" "github.com/scionproto/scion/go/lib/ctrl/seg" "github.com/scionproto/scion/go/lib/infra/modules/itopo/itopotest" - "github.com/scionproto/scion/go/lib/overlay" "github.com/scionproto/scion/go/lib/scrypto" "github.com/scionproto/scion/go/lib/snet" "github.com/scionproto/scion/go/lib/snet/mock_snet" @@ -93,7 +93,7 @@ func TestOriginatorRun(t *testing.T) { defer msgsMtx.Unlock() msgs = append(msgs, msg{ pkt: ipkt.(*snet.SCIONPacket), - ov: iov.(*overlay.OverlayAddr), + ov: iov.(*net.UDPAddr), }) return nil }, @@ -161,7 +161,7 @@ func TestOriginatorRun(t *testing.T) { type msg struct { pkt *snet.SCIONPacket - ov *overlay.OverlayAddr + ov *net.UDPAddr } func checkMsg(t *testing.T, msg msg, pub common.RawBytes, infos topology.IfInfoMap) { @@ -188,7 +188,8 @@ func checkMsg(t *testing.T, msg msg, pub common.RawBytes, infos topology.IfInfoM xtest.FailOnErr(t, err) SoMsg("Egress", hopF.ConsEgress, ShouldEqual, bHopF.ConsEgress) brAddr := infos[hopF.ConsEgress].InternalAddrs - SoMsg("ov", msg.ov, ShouldResemble, brAddr.PublicOverlay(brAddr.Overlay)) + SoMsg("ov", msg.ov, ShouldResemble, + brAddr.PublicOverlayUDP(brAddr.Overlay)) }) } diff --git a/go/beacon_srv/internal/beaconing/propagator.go b/go/beacon_srv/internal/beaconing/propagator.go index 8fa31b8d85..88748d8644 100644 --- a/go/beacon_srv/internal/beaconing/propagator.go +++ b/go/beacon_srv/internal/beaconing/propagator.go @@ -277,7 +277,7 @@ func (p *beaconPropagator) extendAndSend(ctx context.Context, bseg beacon.Beacon return } topoInfo := intf.TopoInfo() - ov := topoInfo.InternalAddrs.PublicOverlay(topoInfo.InternalAddrs.Overlay) + ov := topoInfo.InternalAddrs.PublicOverlayUDP(topoInfo.InternalAddrs.Overlay) err := p.beaconSender.Send( ctx, diff --git a/go/beacon_srv/internal/beaconing/propagator_test.go b/go/beacon_srv/internal/beaconing/propagator_test.go index b12dea21ca..65af6fcff1 100644 --- a/go/beacon_srv/internal/beaconing/propagator_test.go +++ b/go/beacon_srv/internal/beaconing/propagator_test.go @@ -17,6 +17,7 @@ package beaconing import ( "errors" "fmt" + "net" "sync" "testing" "time" @@ -31,7 +32,6 @@ import ( "github.com/scionproto/scion/go/lib/addr" "github.com/scionproto/scion/go/lib/common" "github.com/scionproto/scion/go/lib/infra/modules/itopo/itopotest" - "github.com/scionproto/scion/go/lib/overlay" "github.com/scionproto/scion/go/lib/scrypto" "github.com/scionproto/scion/go/lib/snet" "github.com/scionproto/scion/go/lib/snet/mock_snet" @@ -196,7 +196,7 @@ func TestPropagatorRun(t *testing.T) { defer msgsMtx.Unlock() msgs = append(msgs, msg{ pkt: ipkt.(*snet.SCIONPacket), - ov: iov.(*overlay.OverlayAddr), + ov: iov.(*net.UDPAddr), }) return nil }, diff --git a/go/beacon_srv/internal/beaconing/registrar_test.go b/go/beacon_srv/internal/beaconing/registrar_test.go index 3d1b42d38d..bbe7eea309 100644 --- a/go/beacon_srv/internal/beaconing/registrar_test.go +++ b/go/beacon_srv/internal/beaconing/registrar_test.go @@ -176,7 +176,8 @@ func TestRegistrarRun(t *testing.T) { SoMsg("HopField", []uint8(hopF.Pack()), ShouldResemble, pseg.ASEntries[pseg.MaxAEIdx()].HopEntries[0].RawHopField) a := topoProvider.Get().IFInfoMap()[hopF.ConsIngress].InternalAddrs - SoMsg("Next", s.Addr.NextHop, ShouldResemble, a.PublicOverlay(a.Overlay)) + SoMsg("Next", s.Addr.NextHop, ShouldResemble, + a.PublicOverlayUDP(a.Overlay)) }) } // The second run should not do anything, since the period has not passed. diff --git a/go/beacon_srv/internal/keepalive/sender.go b/go/beacon_srv/internal/keepalive/sender.go index a4ae22cc26..38f9bd23b0 100644 --- a/go/beacon_srv/internal/keepalive/sender.go +++ b/go/beacon_srv/internal/keepalive/sender.go @@ -71,7 +71,7 @@ func (s *Sender) Run(ctx context.Context) { InfoTime: time.Now(), Pld: pld, } - ov := intf.InternalAddrs.PublicOverlay(intf.InternalAddrs.Overlay) + ov := intf.InternalAddrs.PublicOverlayUDP(intf.InternalAddrs.Overlay) if err := s.Send(msg, ov); err != nil { logger.Error("[keepalive.Sender] Unable to send packet", "err", err) metrics.Keepalive.Transmits(l).Inc() diff --git a/go/beacon_srv/internal/onehop/BUILD.bazel b/go/beacon_srv/internal/onehop/BUILD.bazel index aa0744176a..8a633b6743 100644 --- a/go/beacon_srv/internal/onehop/BUILD.bazel +++ b/go/beacon_srv/internal/onehop/BUILD.bazel @@ -18,7 +18,6 @@ go_library( "//go/lib/l4:go_default_library", "//go/lib/layers:go_default_library", "//go/lib/log:go_default_library", - "//go/lib/overlay:go_default_library", "//go/lib/snet:go_default_library", "//go/lib/spath:go_default_library", ], @@ -33,7 +32,6 @@ go_test( "//go/lib/common:go_default_library", "//go/lib/l4:go_default_library", "//go/lib/layers:go_default_library", - "//go/lib/overlay:go_default_library", "//go/lib/scrypto:go_default_library", "//go/lib/snet:go_default_library", "//go/lib/snet/mock_snet:go_default_library", diff --git a/go/beacon_srv/internal/onehop/network.go b/go/beacon_srv/internal/onehop/network.go index f3b77433ef..7cbff02cb2 100644 --- a/go/beacon_srv/internal/onehop/network.go +++ b/go/beacon_srv/internal/onehop/network.go @@ -15,11 +15,11 @@ package onehop import ( + "net" "time" "github.com/scionproto/scion/go/lib/addr" "github.com/scionproto/scion/go/lib/layers" - "github.com/scionproto/scion/go/lib/overlay" "github.com/scionproto/scion/go/lib/snet" ) @@ -32,7 +32,7 @@ type OHPPacketDispatcherService struct { } func (s *OHPPacketDispatcherService) RegisterTimeout(ia addr.IA, public *addr.AppAddr, - bind *overlay.OverlayAddr, svc addr.HostSVC, + bind *net.UDPAddr, svc addr.HostSVC, timeout time.Duration) (snet.PacketConn, uint16, error) { conn, port, err := s.PacketDispatcherService.RegisterTimeout(ia, public, bind, svc, timeout) @@ -48,7 +48,7 @@ type ohpPacketConn struct { snet.PacketConn } -func (c *ohpPacketConn) WriteTo(pkt *snet.SCIONPacket, ov *overlay.OverlayAddr) error { +func (c *ohpPacketConn) WriteTo(pkt *snet.SCIONPacket, ov *net.UDPAddr) error { return c.PacketConn.WriteTo( &snet.SCIONPacket{ Bytes: pkt.Bytes, diff --git a/go/beacon_srv/internal/onehop/sender.go b/go/beacon_srv/internal/onehop/sender.go index a4ce3c74e3..c3e4f315aa 100644 --- a/go/beacon_srv/internal/onehop/sender.go +++ b/go/beacon_srv/internal/onehop/sender.go @@ -31,7 +31,6 @@ import ( "github.com/scionproto/scion/go/lib/l4" "github.com/scionproto/scion/go/lib/layers" "github.com/scionproto/scion/go/lib/log" - "github.com/scionproto/scion/go/lib/overlay" "github.com/scionproto/scion/go/lib/snet" "github.com/scionproto/scion/go/lib/spath" ) @@ -72,7 +71,7 @@ type Sender struct { } // Send sends the payload on a one-hop path. -func (s *Sender) Send(msg *Msg, nextHop *overlay.OverlayAddr) error { +func (s *Sender) Send(msg *Msg, nextHop *net.UDPAddr) error { pkt, err := s.CreatePkt(msg) if err != nil { return common.NewBasicError("Unable to create packet", err) @@ -126,7 +125,7 @@ type BeaconSender struct { // Send packs and sends out the beacon. QUIC is first attempted, and if that // fails the method falls back on UDP. func (s *BeaconSender) Send(ctx context.Context, bseg *seg.Beacon, ia addr.IA, - egIfid common.IFIDType, signer infra.Signer, ov *overlay.OverlayAddr) error { + egIfid common.IFIDType, signer infra.Signer, ov *net.UDPAddr) error { path, err := s.CreatePath(egIfid, time.Now()) if err != nil { @@ -167,7 +166,7 @@ func (s *BeaconSender) Send(ctx context.Context, bseg *seg.Beacon, ia addr.IA, } func (s *BeaconSender) attemptQUIC(ctx context.Context, ia addr.IA, path *spath.Path, - nextHop *overlay.OverlayAddr, bseg *seg.Beacon) (bool, error) { + nextHop *net.UDPAddr, bseg *seg.Beacon) (bool, error) { if s.AddressRewriter == nil { return false, nil diff --git a/go/beacon_srv/internal/onehop/sender_test.go b/go/beacon_srv/internal/onehop/sender_test.go index 86b7ecaec6..ac7576f27c 100644 --- a/go/beacon_srv/internal/onehop/sender_test.go +++ b/go/beacon_srv/internal/onehop/sender_test.go @@ -27,7 +27,6 @@ import ( "github.com/scionproto/scion/go/lib/common" "github.com/scionproto/scion/go/lib/l4" "github.com/scionproto/scion/go/lib/layers" - "github.com/scionproto/scion/go/lib/overlay" "github.com/scionproto/scion/go/lib/scrypto" "github.com/scionproto/scion/go/lib/snet" "github.com/scionproto/scion/go/lib/snet/mock_snet" @@ -110,7 +109,7 @@ func TestSenderSend(t *testing.T) { MAC: createMac(t), } // Read from connection to unblock sender. - ov := overlay.NewOverlayAddr(net.IP{127, 0, 0, 42}, 1337) + ov := &net.UDPAddr{IP: net.IP{127, 0, 0, 42}, Port: 1337} var pkt *snet.SCIONPacket conn.EXPECT().WriteTo(gomock.Any(), ov).DoAndReturn( func(ipkt, _ interface{}) error { @@ -159,7 +158,7 @@ type testConn struct { func (conn *testConn) ReadFrom(b []byte) (int, net.Addr, error) { n, _, err := conn.PacketConn.ReadFrom(b) - return n, &overlay.OverlayAddr{}, err + return n, &net.UDPAddr{}, err } func createMac(t *testing.T) hash.Hash { diff --git a/go/border/BUILD.bazel b/go/border/BUILD.bazel index 3fb854883b..f75556ef99 100644 --- a/go/border/BUILD.bazel +++ b/go/border/BUILD.bazel @@ -67,11 +67,12 @@ go_test( "//go/lib/common:go_default_library", "//go/lib/infra/modules/itopo:go_default_library", "//go/lib/log:go_default_library", - "//go/lib/overlay:go_default_library", "//go/lib/overlay/conn:go_default_library", "//go/lib/overlay/conn/mock_conn:go_default_library", "//go/lib/prom:go_default_library", "//go/lib/ringbuf:go_default_library", + "//go/lib/topology:go_default_library", + "//go/lib/topology/overlay:go_default_library", "//go/lib/xtest:go_default_library", "@com_github_golang_mock//gomock:go_default_library", "@com_github_smartystreets_goconvey//convey:go_default_library", diff --git a/go/border/io.go b/go/border/io.go index d0a445df94..bad039ab8a 100644 --- a/go/border/io.go +++ b/go/border/io.go @@ -306,9 +306,8 @@ func (r *Router) posixPrepOutput(epkts ringbuf.EntryList, msgs []ipv4.Message, msgs[i].Buffers[0] = rp.Raw if !connected { // Unconnected socket, use supplied address - uaddr := msgs[i].Addr.(*net.UDPAddr) - uaddr.IP = erp.Dst.L3().IP() - uaddr.Port = int(erp.Dst.L4()) + msgs[i].Addr.(*net.UDPAddr).IP = erp.Dst.IP + msgs[i].Addr.(*net.UDPAddr).Port = int(erp.Dst.Port) } } return epkts, true diff --git a/go/border/io_test.go b/go/border/io_test.go index f4dfafc44d..e504187b91 100644 --- a/go/border/io_test.go +++ b/go/border/io_test.go @@ -27,11 +27,11 @@ import ( "github.com/scionproto/scion/go/border/rctx" "github.com/scionproto/scion/go/border/rpkt" "github.com/scionproto/scion/go/lib/log" - "github.com/scionproto/scion/go/lib/overlay" "github.com/scionproto/scion/go/lib/overlay/conn" "github.com/scionproto/scion/go/lib/overlay/conn/mock_conn" "github.com/scionproto/scion/go/lib/prom" "github.com/scionproto/scion/go/lib/ringbuf" + "github.com/scionproto/scion/go/lib/topology" ) func TestPosixOutputNoLeakNoErrors(t *testing.T) { @@ -147,8 +147,11 @@ func newTestPktList(t *testing.T, length int) (ringbuf.EntryList, func(expected } } -func newTestDst(t *testing.T) *overlay.OverlayAddr { - return overlay.NewOverlayAddr(net.IP{127, 0, 0, 1}, overlay.EndhostPort) +func newTestDst(t *testing.T) *net.UDPAddr { + return &net.UDPAddr{ + IP: net.IP{127, 0, 0, 1}, + Port: topology.EndhostPort, + } } func newTestSock(r *Router, ringSize int, mconn conn.Conn) *rctx.Sock { diff --git a/go/border/rctx/BUILD.bazel b/go/border/rctx/BUILD.bazel index 6744c1b9b4..a4a03217bb 100644 --- a/go/border/rctx/BUILD.bazel +++ b/go/border/rctx/BUILD.bazel @@ -16,7 +16,6 @@ go_library( "//go/lib/assert:go_default_library", "//go/lib/common:go_default_library", "//go/lib/log:go_default_library", - "//go/lib/overlay:go_default_library", "//go/lib/overlay/conn:go_default_library", "//go/lib/ringbuf:go_default_library", "//go/lib/scrypto:go_default_library", diff --git a/go/border/rctx/rctx.go b/go/border/rctx/rctx.go index c545bf8779..0282991e1e 100644 --- a/go/border/rctx/rctx.go +++ b/go/border/rctx/rctx.go @@ -18,13 +18,13 @@ package rctx import ( + "net" "sync" "sync/atomic" "github.com/scionproto/scion/go/border/brconf" "github.com/scionproto/scion/go/lib/addr" "github.com/scionproto/scion/go/lib/common" - "github.com/scionproto/scion/go/lib/overlay" "github.com/scionproto/scion/go/lib/scrypto" ) @@ -74,7 +74,7 @@ func (ctx *Ctx) InitMacPool() error { return nil } -func (ctx *Ctx) ResolveSVC(svc addr.HostSVC) ([]*overlay.OverlayAddr, error) { +func (ctx *Ctx) ResolveSVC(svc addr.HostSVC) ([]*net.UDPAddr, error) { if svc.IsMulticast() { return ctx.ResolveSVCMulti(svc) } @@ -82,18 +82,18 @@ func (ctx *Ctx) ResolveSVC(svc addr.HostSVC) ([]*overlay.OverlayAddr, error) { if err != nil { return nil, err } - return []*overlay.OverlayAddr{resolvedAddr}, nil + return []*net.UDPAddr{resolvedAddr}, nil } // ResolveSVCAny resolves an anycast SVC address (i.e. a single instance of a local // infrastructure service). -func (ctx *Ctx) ResolveSVCAny(svc addr.HostSVC) (*overlay.OverlayAddr, error) { +func (ctx *Ctx) ResolveSVCAny(svc addr.HostSVC) (*net.UDPAddr, error) { return ctx.Conf.Topo.OverlayAnycast(svc) } // ResolveSVCMulti resolves a multicast SVC address (i.e. one packet per machine hosting // instances for a local infrastructure service). -func (ctx *Ctx) ResolveSVCMulti(svc addr.HostSVC) ([]*overlay.OverlayAddr, error) { +func (ctx *Ctx) ResolveSVCMulti(svc addr.HostSVC) ([]*net.UDPAddr, error) { return ctx.Conf.Topo.OverlayMulticast(svc) } diff --git a/go/border/rpkt/BUILD.bazel b/go/border/rpkt/BUILD.bazel index ab6774ae8f..66aced4702 100644 --- a/go/border/rpkt/BUILD.bazel +++ b/go/border/rpkt/BUILD.bazel @@ -38,7 +38,6 @@ go_library( "//go/lib/l4:go_default_library", "//go/lib/layers:go_default_library", "//go/lib/log:go_default_library", - "//go/lib/overlay:go_default_library", "//go/lib/ringbuf:go_default_library", "//go/lib/scmp:go_default_library", "//go/lib/serrors:go_default_library", @@ -46,6 +45,7 @@ go_library( "//go/lib/spkt:go_default_library", "//go/lib/spse:go_default_library", "//go/lib/spse/scmp_auth:go_default_library", + "//go/lib/topology:go_default_library", "//go/lib/util:go_default_library", "//go/proto:go_default_library", "@org_golang_x_xerrors//:go_default_library", diff --git a/go/border/rpkt/create.go b/go/border/rpkt/create.go index 7b4c7d8dce..d34e0896af 100644 --- a/go/border/rpkt/create.go +++ b/go/border/rpkt/create.go @@ -18,6 +18,7 @@ package rpkt import ( + "net" "time" "github.com/scionproto/scion/go/border/rcmn" @@ -27,7 +28,6 @@ import ( "github.com/scionproto/scion/go/lib/common" "github.com/scionproto/scion/go/lib/l4" "github.com/scionproto/scion/go/lib/log" - "github.com/scionproto/scion/go/lib/overlay" "github.com/scionproto/scion/go/lib/spkt" ) @@ -179,8 +179,8 @@ func (rp *RtrPkt) CreateReplyScnPkt() (*spkt.ScnPkt, error) { } sp.SrcIA = rp.Ctx.Conf.IA // Use the local address as the source host - pub := rp.Ctx.Conf.BR.InternalAddrs.PublicOverlay(rp.Ctx.Conf.Topo.Overlay()) - sp.SrcHost = pub.L3() + pub := rp.Ctx.Conf.BR.InternalAddrs.PublicOverlayUDP(rp.Ctx.Conf.Topo.Overlay()) + sp.SrcHost = addr.HostFromIP(pub.IP) return sp, nil } @@ -230,7 +230,7 @@ func (rp *RtrPkt) CreateReply(sp *spkt.ScnPkt) (*RtrPkt, error) { // replyEgress calculates the corresponding egress function and destination // address to use when replying to a packet. -func (rp *RtrPkt) replyEgress(dir rcmn.Dir, dst *overlay.OverlayAddr, ifid common.IFIDType) error { +func (rp *RtrPkt) replyEgress(dir rcmn.Dir, dst *net.UDPAddr, ifid common.IFIDType) error { // Destination is the local AS if rp.dstIA.Equal(rp.Ctx.Conf.IA) { // Write to local socket diff --git a/go/border/rpkt/route.go b/go/border/rpkt/route.go index 96e67d633a..fe5c1ae2de 100644 --- a/go/border/rpkt/route.go +++ b/go/border/rpkt/route.go @@ -18,16 +18,17 @@ package rpkt import ( "fmt" + "net" "github.com/scionproto/scion/go/border/internal/metrics" "github.com/scionproto/scion/go/border/rcmn" "github.com/scionproto/scion/go/lib/addr" "github.com/scionproto/scion/go/lib/assert" "github.com/scionproto/scion/go/lib/common" - "github.com/scionproto/scion/go/lib/overlay" "github.com/scionproto/scion/go/lib/ringbuf" "github.com/scionproto/scion/go/lib/scmp" "github.com/scionproto/scion/go/lib/serrors" + "github.com/scionproto/scion/go/lib/topology" "github.com/scionproto/scion/go/proto" ) @@ -120,7 +121,10 @@ func (rp *RtrPkt) forwardFromExternal() (HookResult, error) { return HookError, common.NewBasicError("invalid overlay L3 address", nil, "addr", rp.dstHost) } - dst := overlay.NewOverlayAddr(rp.dstHost.IP(), overlay.EndhostPort) + dst := &net.UDPAddr{ + IP: rp.dstHost.IP(), + Port: int(topology.EndhostPort), + } rp.Egress = append(rp.Egress, EgressPair{S: rp.Ctx.LocSockOut, Dst: dst}) return HookContinue, nil } @@ -140,7 +144,7 @@ func (rp *RtrPkt) forwardFromExternal() (HookResult, error) { return rp.reprocess() } nextBR := rp.Ctx.Conf.Topo.IFInfoMap()[*rp.ifNext] - dst := nextBR.InternalAddrs.PublicOverlay(rp.Ctx.Conf.Topo.Overlay()) + dst := nextBR.InternalAddrs.PublicOverlayUDP(rp.Ctx.Conf.Topo.Overlay()) rp.Egress = append(rp.Egress, EgressPair{S: rp.Ctx.LocSockOut, Dst: dst}) return HookContinue, nil } diff --git a/go/border/rpkt/rpkt.go b/go/border/rpkt/rpkt.go index 23acaedaad..db2ec72851 100644 --- a/go/border/rpkt/rpkt.go +++ b/go/border/rpkt/rpkt.go @@ -22,6 +22,7 @@ package rpkt import ( "fmt" + "net" "sync/atomic" "time" @@ -34,7 +35,6 @@ import ( "github.com/scionproto/scion/go/lib/common" "github.com/scionproto/scion/go/lib/l4" "github.com/scionproto/scion/go/lib/log" - "github.com/scionproto/scion/go/lib/overlay" "github.com/scionproto/scion/go/lib/scmp" "github.com/scionproto/scion/go/lib/spath" "github.com/scionproto/scion/go/lib/spkt" @@ -158,8 +158,8 @@ func (rp *RtrPkt) Release() { // addrIFPair contains the overlay destination/source addresses, as well as the // list of associated interface IDs. type addrIFPair struct { - Dst *overlay.OverlayAddr - Src *overlay.OverlayAddr + Dst *net.UDPAddr + Src *net.UDPAddr IfID common.IFIDType IfLabel string } @@ -168,12 +168,12 @@ type addrIFPair struct { // overlay destination address. type EgressPair struct { S *rctx.Sock - Dst *overlay.OverlayAddr + Dst *net.UDPAddr } type EgressRtrPkt struct { Rp *RtrPkt - Dst *overlay.OverlayAddr + Dst *net.UDPAddr } // packetIdxs provides offsets into a packet buffer to the start of various diff --git a/go/border/setup-posix.go b/go/border/setup-posix.go index 6fc05e584d..04b653e64c 100644 --- a/go/border/setup-posix.go +++ b/go/border/setup-posix.go @@ -17,6 +17,7 @@ package main import ( "fmt" + "net" "github.com/scionproto/scion/go/border/brconf" "github.com/scionproto/scion/go/border/rcmn" @@ -82,7 +83,11 @@ func (p posixLoc) Rollback(r *Router, ctx *rctx.Ctx, oldCtx *rctx.Ctx) error { func (p posixLoc) addSock(r *Router, ctx *rctx.Ctx) error { // Get Bind address if set, Public otherwise - bind := ctx.Conf.BR.InternalAddrs.BindOrPublicOverlay(ctx.Conf.Topo.Overlay()) + bindOv := ctx.Conf.BR.InternalAddrs.BindOrPublicOverlay(ctx.Conf.Topo.Overlay()) + var bind *net.UDPAddr + if bindOv != nil { + bind = bindOv.ToUDPAddr() + } log.Debug("Setting up new local socket.", "bind", bind) // Listen on the socket. over, err := conn.New(bind, nil, nil) @@ -153,8 +158,17 @@ func (p posixExt) addIntf(r *Router, ctx *rctx.Ctx, intf *topology.IFInfo) error // Connect to remote address. log.Debug("Setting up new external socket.", "intf", intf) - bind := intf.Local.BindOrPublicOverlay(intf.Local.Overlay) - c, err := conn.New(bind, intf.Remote, nil) + bindOv := intf.Local.BindOrPublicOverlay(intf.Local.Overlay) + var bind *net.UDPAddr + if bindOv != nil { + bind = bindOv.ToUDPAddr() + } + remoteOv := intf.Remote + var remote *net.UDPAddr + if remoteOv != nil { + remote = remoteOv.ToUDPAddr() + } + c, err := conn.New(bind, remote, nil) if err != nil { return common.NewBasicError("Unable to listen on external socket", err) } diff --git a/go/border/setup.go b/go/border/setup.go index d478e9691c..20e2e19aa4 100644 --- a/go/border/setup.go +++ b/go/border/setup.go @@ -306,7 +306,7 @@ func (r *Router) startDiscovery() error { func (r *Router) discoveryClient() (*http.Client, error) { internalAddr := rctx.Get().Conf.BR.InternalAddrs tcpAddr, err := net.ResolveTCPAddr("tcp", fmt.Sprintf("%s:0", - internalAddr.PublicOverlay(internalAddr.Overlay).L3())) + internalAddr.PublicOverlayUDP(internalAddr.Overlay).IP)) if err != nil { return nil, err } diff --git a/go/border/setup_test.go b/go/border/setup_test.go index 720b6172e6..07121d1a7f 100644 --- a/go/border/setup_test.go +++ b/go/border/setup_test.go @@ -27,8 +27,8 @@ import ( "github.com/scionproto/scion/go/lib/common" "github.com/scionproto/scion/go/lib/infra/modules/itopo" "github.com/scionproto/scion/go/lib/log" - "github.com/scionproto/scion/go/lib/overlay" "github.com/scionproto/scion/go/lib/ringbuf" + "github.com/scionproto/scion/go/lib/topology/overlay" "github.com/scionproto/scion/go/lib/xtest" ) @@ -53,7 +53,7 @@ func TestSetupNet(t *testing.T) { // Modify local socket address. A new socket should be opened when // setting up the context. addr := ctx.Conf.BR.InternalAddrs - addr.PublicOverlay(addr.Overlay).L3().IP()[3] = 255 + addr.PublicOverlayUDP(addr.Overlay).IP[3] = 255 SoMsg("In", oldCtx.LocSockIn, ShouldNotBeNil) clean := updateTestRouter(r, ctx, oldCtx) defer clean() @@ -69,7 +69,7 @@ func TestSetupNet(t *testing.T) { r, oldCtx := setupTestRouter(t) copyCtx := copyContext(oldCtx) ctx := rctx.New(loadConfig(t)) - ctx.Conf.BR.IFs[12].Local.PublicOverlay(overlay.IPv4).L3().IP()[3] = 255 + ctx.Conf.BR.IFs[12].Local.PublicOverlayUDP(overlay.IPv4).IP[3] = 255 clean := updateTestRouter(r, ctx, oldCtx) defer clean() // Check that unaffected sockets have not changed. @@ -133,7 +133,7 @@ func TestRollbackNet(t *testing.T) { copyCtx := copyContext(oldCtx) ctx := rctx.New(loadConfig(t)) addr := ctx.Conf.BR.InternalAddrs - addr.PublicOverlay(addr.Overlay).L3().IP()[3] = 255 + addr.PublicOverlayUDP(addr.Overlay).IP[3] = 255 clean := updateTestRouter(r, ctx, oldCtx) defer clean() // Rollback the changes. @@ -151,7 +151,7 @@ func TestRollbackNet(t *testing.T) { r, oldCtx := setupTestRouter(t) copyCtx := copyContext(oldCtx) ctx := rctx.New(loadConfig(t)) - ctx.Conf.BR.IFs[12].Local.PublicOverlay(overlay.IPv4).L3().IP()[3] = 255 + ctx.Conf.BR.IFs[12].Local.PublicOverlayUDP(overlay.IPv4).IP[3] = 255 clean := updateTestRouter(r, ctx, oldCtx) defer clean() // Rollback the changes. @@ -191,7 +191,7 @@ func TestTeardownNet(t *testing.T) { r, oldCtx := setupTestRouter(t) ctx := rctx.New(loadConfig(t)) addr := ctx.Conf.BR.InternalAddrs - addr.PublicOverlay(addr.Overlay).L3().IP()[3] = 255 + addr.PublicOverlayUDP(addr.Overlay).IP[3] = 255 clean := updateTestRouter(r, ctx, oldCtx) defer clean() // Start sockets on the new context. @@ -209,7 +209,7 @@ func TestTeardownNet(t *testing.T) { Convey("Tearing down config with changed interface should be a noop", t, func() { r, oldCtx := setupTestRouter(t) ctx := rctx.New(loadConfig(t)) - ctx.Conf.BR.IFs[12].Local.PublicOverlay(overlay.IPv4).L3().IP()[3] = 255 + ctx.Conf.BR.IFs[12].Local.PublicOverlayUDP(overlay.IPv4).IP[3] = 255 clean := updateTestRouter(r, ctx, oldCtx) defer clean() // Start sockets on the new context. diff --git a/go/examples/pingpong/pingpong.go b/go/examples/pingpong/pingpong.go index fee04898b1..84ce9b1bca 100644 --- a/go/examples/pingpong/pingpong.go +++ b/go/examples/pingpong/pingpong.go @@ -278,7 +278,7 @@ func (c client) setupPath() { } remote.Path = spath.New(pathEntry.Path.FwdPath) remote.Path.InitOffsets() - remote.NextHop, _ = pathEntry.HostInfo.Overlay() + remote.NextHop = pathEntry.HostInfo.Overlay() } } diff --git a/go/godispatcher/BUILD.bazel b/go/godispatcher/BUILD.bazel index 03472ecb02..41e460e229 100644 --- a/go/godispatcher/BUILD.bazel +++ b/go/godispatcher/BUILD.bazel @@ -36,7 +36,6 @@ go_test( "//go/lib/hpkt:go_default_library", "//go/lib/l4:go_default_library", "//go/lib/log:go_default_library", - "//go/lib/overlay:go_default_library", "//go/lib/scmp:go_default_library", "//go/lib/sock/reliable:go_default_library", "//go/lib/spkt:go_default_library", diff --git a/go/godispatcher/internal/config/BUILD.bazel b/go/godispatcher/internal/config/BUILD.bazel index 0fb47d71c6..42ddeed7a5 100644 --- a/go/godispatcher/internal/config/BUILD.bazel +++ b/go/godispatcher/internal/config/BUILD.bazel @@ -11,9 +11,9 @@ go_library( deps = [ "//go/lib/config:go_default_library", "//go/lib/env:go_default_library", - "//go/lib/overlay:go_default_library", "//go/lib/serrors:go_default_library", "//go/lib/sock/reliable:go_default_library", + "//go/lib/topology:go_default_library", "//go/lib/util:go_default_library", ], ) @@ -24,8 +24,8 @@ go_test( embed = [":go_default_library"], deps = [ "//go/lib/env/envtest:go_default_library", - "//go/lib/overlay:go_default_library", "//go/lib/sock/reliable:go_default_library", + "//go/lib/topology:go_default_library", "@com_github_burntsushi_toml//:go_default_library", "@com_github_stretchr_testify//assert:go_default_library", ], diff --git a/go/godispatcher/internal/config/config.go b/go/godispatcher/internal/config/config.go index 190e8e2321..476eda6387 100644 --- a/go/godispatcher/internal/config/config.go +++ b/go/godispatcher/internal/config/config.go @@ -21,9 +21,9 @@ import ( "github.com/scionproto/scion/go/lib/config" "github.com/scionproto/scion/go/lib/env" - "github.com/scionproto/scion/go/lib/overlay" "github.com/scionproto/scion/go/lib/serrors" "github.com/scionproto/scion/go/lib/sock/reliable" + "github.com/scionproto/scion/go/lib/topology" "github.com/scionproto/scion/go/lib/util" ) @@ -59,7 +59,7 @@ func (cfg *Config) InitDefaults() { cfg.Dispatcher.SocketFileMode = reliable.DefaultDispSocketFileMode } if cfg.Dispatcher.OverlayPort == 0 { - cfg.Dispatcher.OverlayPort = overlay.EndhostPort + cfg.Dispatcher.OverlayPort = topology.EndhostPort } } diff --git a/go/godispatcher/internal/config/config_test.go b/go/godispatcher/internal/config/config_test.go index bf045637a5..7d02e90418 100644 --- a/go/godispatcher/internal/config/config_test.go +++ b/go/godispatcher/internal/config/config_test.go @@ -23,8 +23,8 @@ import ( "github.com/stretchr/testify/assert" "github.com/scionproto/scion/go/lib/env/envtest" - "github.com/scionproto/scion/go/lib/overlay" "github.com/scionproto/scion/go/lib/sock/reliable" + "github.com/scionproto/scion/go/lib/topology" ) func TestConfigSample(t *testing.T) { @@ -50,7 +50,7 @@ func CheckTestConfig(t *testing.T, cfg *Config, id string) { assert.Equal(t, id, cfg.Dispatcher.ID) assert.Equal(t, reliable.DefaultDispPath, cfg.Dispatcher.ApplicationSocket) assert.Equal(t, reliable.DefaultDispSocketFileMode, int(cfg.Dispatcher.SocketFileMode)) - assert.Equal(t, overlay.EndhostPort, cfg.Dispatcher.OverlayPort) + assert.Equal(t, topology.EndhostPort, cfg.Dispatcher.OverlayPort) assert.Empty(t, cfg.Dispatcher.PerfData) assert.False(t, cfg.Dispatcher.DeleteSocket) } diff --git a/go/godispatcher/internal/respool/BUILD.bazel b/go/godispatcher/internal/respool/BUILD.bazel index 83703f89bd..21a2a75666 100644 --- a/go/godispatcher/internal/respool/BUILD.bazel +++ b/go/godispatcher/internal/respool/BUILD.bazel @@ -12,7 +12,6 @@ go_library( "//go/godispatcher/internal/metrics:go_default_library", "//go/lib/common:go_default_library", "//go/lib/hpkt:go_default_library", - "//go/lib/overlay:go_default_library", "//go/lib/serrors:go_default_library", "//go/lib/spkt:go_default_library", ], diff --git a/go/godispatcher/internal/respool/packet.go b/go/godispatcher/internal/respool/packet.go index e602d95144..c8ea7c657f 100644 --- a/go/godispatcher/internal/respool/packet.go +++ b/go/godispatcher/internal/respool/packet.go @@ -21,7 +21,6 @@ import ( "github.com/scionproto/scion/go/godispatcher/internal/metrics" "github.com/scionproto/scion/go/lib/common" "github.com/scionproto/scion/go/lib/hpkt" - "github.com/scionproto/scion/go/lib/overlay" "github.com/scionproto/scion/go/lib/serrors" "github.com/scionproto/scion/go/lib/spkt" ) @@ -128,7 +127,7 @@ func (pkt *Packet) DecodeFromReliableConn(conn net.PacketConn) error { if readExtra == nil { return serrors.New("missing next-hop") } - pkt.OverlayRemote = readExtra.(*overlay.OverlayAddr).ToUDPAddr() + pkt.OverlayRemote = readExtra.(*net.UDPAddr) // XXX(scrye): We ignore the return value of packet parsing on egress // because some tests (e.g., the Python SCMP error test) rely on being able diff --git a/go/godispatcher/main_test.go b/go/godispatcher/main_test.go index 1afcaa6d51..54a35af6ba 100644 --- a/go/godispatcher/main_test.go +++ b/go/godispatcher/main_test.go @@ -29,7 +29,6 @@ import ( "github.com/scionproto/scion/go/lib/hpkt" "github.com/scionproto/scion/go/lib/l4" "github.com/scionproto/scion/go/lib/log" - "github.com/scionproto/scion/go/lib/overlay" "github.com/scionproto/scion/go/lib/scmp" "github.com/scionproto/scion/go/lib/sock/reliable" "github.com/scionproto/scion/go/lib/spkt" @@ -37,9 +36,9 @@ import ( ) const ( - dispatcherTestPort uint16 = 40031 - defaultTimeout = 2 * time.Second - defaultWaitDuration = 200 * time.Millisecond + dispatcherTestPort = 40031 + defaultTimeout = 2 * time.Second + defaultWaitDuration = 200 * time.Millisecond ) type TestSettings struct { @@ -71,18 +70,16 @@ type ClientAddress struct { PublicAddress addr.HostAddr PublicPort uint16 ServiceAddress addr.HostSVC - OverlayAddress *overlay.OverlayAddr + OverlayAddress *net.UDPAddr OverlayPort uint16 } // Addressing information var ( - commonIA = xtest.MustParseIA("1-ff00:0:1") - commonPublicL3Address = addr.HostFromIP(net.IP{127, 0, 0, 1}) - commonOverlayL3Address = net.IP{127, 0, 0, 1} - commonOverlayL4Address = dispatcherTestPort - commonOverlayAddress = overlay.NewOverlayAddr(commonOverlayL3Address, commonOverlayL4Address) - clientXAddress = &ClientAddress{ + commonIA = xtest.MustParseIA("1-ff00:0:1") + commonPublicL3Address = addr.HostFromIP(net.IP{127, 0, 0, 1}) + commonOverlayAddress = &net.UDPAddr{IP: net.IP{127, 0, 0, 1}, Port: dispatcherTestPort} + clientXAddress = &ClientAddress{ IA: commonIA, PublicAddress: commonPublicL3Address, PublicPort: 8080, @@ -102,7 +99,7 @@ type TestCase struct { Name string ClientAddress *ClientAddress TestPackets []*spkt.ScnPkt - OverlayAddress *overlay.OverlayAddr + OverlayAddress *net.UDPAddr ExpectedPacket *spkt.ScnPkt } diff --git a/go/godispatcher/network/BUILD.bazel b/go/godispatcher/network/BUILD.bazel index b048ac1af3..71eb504140 100644 --- a/go/godispatcher/network/BUILD.bazel +++ b/go/godispatcher/network/BUILD.bazel @@ -21,7 +21,6 @@ go_library( "//go/lib/l4:go_default_library", "//go/lib/layers:go_default_library", "//go/lib/log:go_default_library", - "//go/lib/overlay:go_default_library", "//go/lib/overlay/conn:go_default_library", "//go/lib/ringbuf:go_default_library", "//go/lib/scmp:go_default_library", diff --git a/go/godispatcher/network/app_socket.go b/go/godispatcher/network/app_socket.go index 89fcd06fc9..dcb09584ab 100644 --- a/go/godispatcher/network/app_socket.go +++ b/go/godispatcher/network/app_socket.go @@ -25,7 +25,6 @@ import ( "github.com/scionproto/scion/go/lib/addr" "github.com/scionproto/scion/go/lib/common" "github.com/scionproto/scion/go/lib/log" - "github.com/scionproto/scion/go/lib/overlay" "github.com/scionproto/scion/go/lib/ringbuf" "github.com/scionproto/scion/go/lib/scmp" "github.com/scionproto/scion/go/lib/sock/reliable" @@ -268,11 +267,7 @@ func (h *AppConnHandler) RunRingToAppDataplane(r *ringbuf.Ring) { } if n > 0 { pkt := entries[0].(*respool.Packet) - overlayAddr := overlay.NewOverlayAddr( - pkt.OverlayRemote.IP, - uint16(pkt.OverlayRemote.Port), - ) - n, err := pkt.SendOnConn(h.Conn, overlayAddr) + n, err := pkt.SendOnConn(h.Conn, pkt.OverlayRemote) if err != nil { metrics.M.AppWriteErrors().Inc() h.Logger.Error("[network->app] App connection error.", "err", err) diff --git a/go/godispatcher/network/dispatcher.go b/go/godispatcher/network/dispatcher.go index 4d01f59403..984364f701 100644 --- a/go/godispatcher/network/dispatcher.go +++ b/go/godispatcher/network/dispatcher.go @@ -23,7 +23,6 @@ import ( "github.com/scionproto/scion/go/godispatcher/internal/metrics" "github.com/scionproto/scion/go/lib/common" "github.com/scionproto/scion/go/lib/log" - "github.com/scionproto/scion/go/lib/overlay" "github.com/scionproto/scion/go/lib/overlay/conn" "github.com/scionproto/scion/go/lib/sock/reliable" ) @@ -125,8 +124,7 @@ func openConn(network, address string, p SocketMetaHandler) (net.PacketConn, err listeningAddress.IP = net.IPv6zero } - ov := overlay.NewOverlayAddr(listeningAddress.IP, uint16(listeningAddress.Port)) - c, err := conn.New(ov, nil, &conn.Config{ReceiveBufferSize: ReceiveBufferSize}) + c, err := conn.New(listeningAddress, nil, &conn.Config{ReceiveBufferSize: ReceiveBufferSize}) if err != nil { return nil, common.NewBasicError("unable to open conn", err) } @@ -186,7 +184,7 @@ func (o *overlayConnWrapper) ReadFrom(p []byte) (int, net.Addr, error) { return n, nil, err } o.Handler.Handle(meta) - return n, meta.Src.ToUDPAddr(), err + return n, meta.Src, err } func (o *overlayConnWrapper) WriteTo(p []byte, a net.Addr) (int, error) { @@ -194,8 +192,7 @@ func (o *overlayConnWrapper) WriteTo(p []byte, a net.Addr) (int, error) { if !ok { return 0, common.NewBasicError("address is not UDP", nil, "addr", a) } - ov := overlay.NewOverlayAddr(udpAddr.IP, uint16(udpAddr.Port)) - return o.Conn.WriteTo(common.RawBytes(p), ov) + return o.Conn.WriteTo(common.RawBytes(p), udpAddr) } func (o *overlayConnWrapper) Close() error { @@ -203,7 +200,7 @@ func (o *overlayConnWrapper) Close() error { } func (o *overlayConnWrapper) LocalAddr() net.Addr { - return o.Conn.LocalAddr().ToUDPAddr() + return o.Conn.LocalAddr() } func (o *overlayConnWrapper) SetDeadline(t time.Time) error { diff --git a/go/integration/end2end/BUILD.bazel b/go/integration/end2end/BUILD.bazel index 874b841783..3bb595bc24 100644 --- a/go/integration/end2end/BUILD.bazel +++ b/go/integration/end2end/BUILD.bazel @@ -14,13 +14,13 @@ go_library( "//go/lib/l4:go_default_library", "//go/lib/layers:go_default_library", "//go/lib/log:go_default_library", - "//go/lib/overlay:go_default_library", "//go/lib/pathmgr:go_default_library", "//go/lib/sciond:go_default_library", "//go/lib/serrors:go_default_library", "//go/lib/snet:go_default_library", "//go/lib/sock/reliable:go_default_library", "//go/lib/spath:go_default_library", + "//go/lib/topology:go_default_library", "//go/lib/util:go_default_library", ], ) diff --git a/go/integration/end2end/main.go b/go/integration/end2end/main.go index d2d3b4dd51..547021d69f 100644 --- a/go/integration/end2end/main.go +++ b/go/integration/end2end/main.go @@ -20,6 +20,7 @@ import ( "crypto/rand" "flag" "fmt" + "net" "os" "time" @@ -30,13 +31,13 @@ import ( "github.com/scionproto/scion/go/lib/l4" "github.com/scionproto/scion/go/lib/layers" "github.com/scionproto/scion/go/lib/log" - "github.com/scionproto/scion/go/lib/overlay" "github.com/scionproto/scion/go/lib/pathmgr" "github.com/scionproto/scion/go/lib/sciond" "github.com/scionproto/scion/go/lib/serrors" "github.com/scionproto/scion/go/lib/snet" "github.com/scionproto/scion/go/lib/sock/reliable" "github.com/scionproto/scion/go/lib/spath" + "github.com/scionproto/scion/go/lib/topology" "github.com/scionproto/scion/go/lib/util" ) @@ -110,7 +111,7 @@ func (s server) run() { // Receive ping message for { var p snet.SCIONPacket - var ov overlay.OverlayAddr + var ov net.UDPAddr if err := conn.ReadFrom(&p, &ov); err != nil { log.Error("Error reading packet", "err", err) continue @@ -186,7 +187,10 @@ func (c client) ping(ctx context.Context, n int) error { } c.conn.SetWriteDeadline(getDeadline(ctx)) if remote.NextHop == nil { - remote.NextHop = overlay.NewOverlayAddr(remote.Host.L3.IP(), overlay.EndhostPort) + remote.NextHop = &net.UDPAddr{ + IP: remote.Host.L3.IP(), + Port: topology.EndhostPort, + } } var debugID [common.ExtnFirstLineLen]byte // API guarantees return values are ok @@ -241,17 +245,14 @@ func (c client) getRemote(ctx context.Context, n int) error { } // Extract forwarding path from sciond response remote.Path = path - remote.NextHop, err = pathEntry.HostInfo.Overlay() - if err != nil { - return common.NewBasicError("Error getting overlay", err) - } + remote.NextHop = pathEntry.HostInfo.Overlay() return nil } func (c client) pong(ctx context.Context) error { c.conn.SetReadDeadline(getDeadline(ctx)) var p snet.SCIONPacket - var ov overlay.OverlayAddr + var ov net.UDPAddr if err := c.conn.ReadFrom(&p, &ov); err != nil { return common.NewBasicError("Error reading packet", err) } diff --git a/go/lib/hostinfo/BUILD.bazel b/go/lib/hostinfo/BUILD.bazel index 10dd1f3b7a..6c9fb7d430 100644 --- a/go/lib/hostinfo/BUILD.bazel +++ b/go/lib/hostinfo/BUILD.bazel @@ -5,9 +5,5 @@ go_library( srcs = ["hostinfo.go"], importpath = "github.com/scionproto/scion/go/lib/hostinfo", visibility = ["//visibility:public"], - deps = [ - "//go/lib/addr:go_default_library", - "//go/lib/common:go_default_library", - "//go/lib/overlay:go_default_library", - ], + deps = ["//go/lib/addr:go_default_library"], ) diff --git a/go/lib/hostinfo/hostinfo.go b/go/lib/hostinfo/hostinfo.go index 3c204f950c..9818d33f89 100644 --- a/go/lib/hostinfo/hostinfo.go +++ b/go/lib/hostinfo/hostinfo.go @@ -20,8 +20,6 @@ import ( "net" "github.com/scionproto/scion/go/lib/addr" - "github.com/scionproto/scion/go/lib/common" - "github.com/scionproto/scion/go/lib/overlay" ) // Host contains connectivity information for a host. @@ -89,12 +87,8 @@ func (h *Host) UDP() *net.UDPAddr { return nil } -func (h *Host) Overlay() (*overlay.OverlayAddr, error) { - if h.Host().IP() == nil { - return nil, common.NewBasicError("unsupported overlay L3 address", nil, "addr", h.Host()) - } - ip := h.Host().IP() - return overlay.NewOverlayAddr(append(ip[:0:0], ip...), h.Port), nil +func (h *Host) Overlay() *net.UDPAddr { + return &net.UDPAddr{IP: h.Host().IP(), Port: int(h.Port)} } func (h *Host) Copy() *Host { diff --git a/go/lib/infra/messenger/BUILD.bazel b/go/lib/infra/messenger/BUILD.bazel index 84a25fc311..63164fdb12 100644 --- a/go/lib/infra/messenger/BUILD.bazel +++ b/go/lib/infra/messenger/BUILD.bazel @@ -30,7 +30,6 @@ go_library( "//go/lib/infra/modules/itopo:go_default_library", "//go/lib/infra/rpc:go_default_library", "//go/lib/log:go_default_library", - "//go/lib/overlay:go_default_library", "//go/lib/scrypto:go_default_library", "//go/lib/serrors:go_default_library", "//go/lib/snet:go_default_library", @@ -57,7 +56,6 @@ go_test( "//go/lib/addr:go_default_library", "//go/lib/infra/messenger/mock_messenger:go_default_library", "//go/lib/log:go_default_library", - "//go/lib/overlay:go_default_library", "//go/lib/snet:go_default_library", "//go/lib/snet/mock_snet:go_default_library", "//go/lib/spath:go_default_library", diff --git a/go/lib/infra/messenger/addr.go b/go/lib/infra/messenger/addr.go index 466587cad2..faabd67ad5 100644 --- a/go/lib/infra/messenger/addr.go +++ b/go/lib/infra/messenger/addr.go @@ -24,7 +24,6 @@ import ( "github.com/scionproto/scion/go/lib/common" "github.com/scionproto/scion/go/lib/infra/modules/itopo" "github.com/scionproto/scion/go/lib/log" - "github.com/scionproto/scion/go/lib/overlay" "github.com/scionproto/scion/go/lib/serrors" "github.com/scionproto/scion/go/lib/snet" "github.com/scionproto/scion/go/lib/svc" @@ -254,7 +253,7 @@ func BuildReply(address *addr.AppAddr) *svc.Reply { type LocalSVCRouter interface { // GetOverlay returns the overlay address of a SVC server of the specified // type. When multiple servers are available, the choice is random. - GetOverlay(svc addr.HostSVC) (*overlay.OverlayAddr, error) + GetOverlay(svc addr.HostSVC) (*net.UDPAddr, error) } // NewSVCRouter build a SVC router backed by topology information from the @@ -269,6 +268,6 @@ type baseSVCRouter struct { topology itopo.ProviderI } -func (r *baseSVCRouter) GetOverlay(svc addr.HostSVC) (*overlay.OverlayAddr, error) { +func (r *baseSVCRouter) GetOverlay(svc addr.HostSVC) (*net.UDPAddr, error) { return r.topology.Get().OverlayAnycast(svc) } diff --git a/go/lib/infra/messenger/addr_test.go b/go/lib/infra/messenger/addr_test.go index 6b750af70e..8e7cbdd774 100644 --- a/go/lib/infra/messenger/addr_test.go +++ b/go/lib/infra/messenger/addr_test.go @@ -27,7 +27,6 @@ import ( "github.com/scionproto/scion/go/lib/addr" "github.com/scionproto/scion/go/lib/infra/messenger/mock_messenger" - "github.com/scionproto/scion/go/lib/overlay" "github.com/scionproto/scion/go/lib/snet" "github.com/scionproto/scion/go/lib/snet/mock_snet" "github.com/scionproto/scion/go/lib/spath" @@ -126,7 +125,7 @@ func TestBuildFullAddress(t *testing.T) { Convey("snet address without path, successful retrieving path", func() { path := mock_snet.NewMockPath(ctrl) path.EXPECT().Path().Return(&spath.Path{}) - path.EXPECT().OverlayNextHop().Return(&overlay.OverlayAddr{}) + path.EXPECT().OverlayNextHop().Return(&net.UDPAddr{}) router.EXPECT().Route(gomock.Any(), gomock.Any()).Return(path, nil) inputAddress := &snet.Addr{ IA: remoteIA, @@ -143,12 +142,15 @@ func TestBuildFullAddress(t *testing.T) { L4: 1, }, Path: &spath.Path{}, - NextHop: &overlay.OverlayAddr{}, + NextHop: &net.UDPAddr{}, }) SoMsg("err", err, ShouldBeNil) }) Convey("snet address in local AS, overlay address extraction succeeds", func() { - overlayAddr := overlay.NewOverlayAddr(net.IP{192, 168, 0, 1}, 10) + overlayAddr := &net.UDPAddr{ + IP: net.IP{192, 168, 0, 1}, + Port: 10, + } router.EXPECT().LocalIA().Return(localIA).AnyTimes() svcRouter.EXPECT().GetOverlay(addr.SvcBS).Return(overlayAddr, nil) @@ -465,7 +467,7 @@ func (t *testPath) Fingerprint() string { panic("not implemented") } -func (t *testPath) OverlayNextHop() *overlay.OverlayAddr { +func (t *testPath) OverlayNextHop() *net.UDPAddr { panic("not implemented") } diff --git a/go/lib/infra/messenger/mock_messenger/BUILD.bazel b/go/lib/infra/messenger/mock_messenger/BUILD.bazel index 8d4f2fec03..67c7d19a02 100644 --- a/go/lib/infra/messenger/mock_messenger/BUILD.bazel +++ b/go/lib/infra/messenger/mock_messenger/BUILD.bazel @@ -7,7 +7,6 @@ go_library( visibility = ["//visibility:public"], deps = [ "//go/lib/addr:go_default_library", - "//go/lib/overlay:go_default_library", "//go/lib/snet:go_default_library", "//go/lib/svc:go_default_library", "@com_github_golang_mock//gomock:go_default_library", diff --git a/go/lib/infra/messenger/mock_messenger/messenger.go b/go/lib/infra/messenger/mock_messenger/messenger.go index 6edf22a5ad..5f50d47013 100644 --- a/go/lib/infra/messenger/mock_messenger/messenger.go +++ b/go/lib/infra/messenger/mock_messenger/messenger.go @@ -8,9 +8,9 @@ import ( context "context" gomock "github.com/golang/mock/gomock" addr "github.com/scionproto/scion/go/lib/addr" - overlay "github.com/scionproto/scion/go/lib/overlay" snet "github.com/scionproto/scion/go/lib/snet" svc "github.com/scionproto/scion/go/lib/svc" + net "net" reflect "reflect" ) @@ -38,10 +38,10 @@ func (m *MockLocalSVCRouter) EXPECT() *MockLocalSVCRouterMockRecorder { } // GetOverlay mocks base method -func (m *MockLocalSVCRouter) GetOverlay(arg0 addr.HostSVC) (*overlay.OverlayAddr, error) { +func (m *MockLocalSVCRouter) GetOverlay(arg0 addr.HostSVC) (*net.UDPAddr, error) { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "GetOverlay", arg0) - ret0, _ := ret[0].(*overlay.OverlayAddr) + ret0, _ := ret[0].(*net.UDPAddr) ret1, _ := ret[1].(error) return ret0, ret1 } diff --git a/go/lib/infra/modules/itopo/BUILD.bazel b/go/lib/infra/modules/itopo/BUILD.bazel index ccb49e844f..b2a7c6377c 100644 --- a/go/lib/infra/modules/itopo/BUILD.bazel +++ b/go/lib/infra/modules/itopo/BUILD.bazel @@ -16,12 +16,12 @@ go_library( "//go/lib/common:go_default_library", "//go/lib/infra/modules/itopo/internal/metrics:go_default_library", "//go/lib/log:go_default_library", - "//go/lib/overlay:go_default_library", "//go/lib/periodic:go_default_library", "//go/lib/scmp:go_default_library", "//go/lib/serrors:go_default_library", "//go/lib/snet:go_default_library", "//go/lib/topology:go_default_library", + "//go/lib/topology/overlay:go_default_library", "//go/proto:go_default_library", "@com_github_google_go_cmp//cmp:go_default_library", "@com_github_google_go_cmp//cmp/cmpopts:go_default_library", @@ -37,8 +37,8 @@ go_test( data = glob(["testdata/**"]), embed = [":go_default_library"], deps = [ - "//go/lib/overlay:go_default_library", "//go/lib/topology:go_default_library", + "//go/lib/topology/overlay:go_default_library", "//go/lib/xtest:go_default_library", "//go/lib/xtest/mock_xtest:go_default_library", "//go/proto:go_default_library", diff --git a/go/lib/infra/modules/itopo/itopo_test.go b/go/lib/infra/modules/itopo/itopo_test.go index 299217a532..e8c7d9a64a 100644 --- a/go/lib/infra/modules/itopo/itopo_test.go +++ b/go/lib/infra/modules/itopo/itopo_test.go @@ -21,8 +21,8 @@ import ( "github.com/golang/mock/gomock" . "github.com/smartystreets/goconvey/convey" - "github.com/scionproto/scion/go/lib/overlay" "github.com/scionproto/scion/go/lib/topology" + "github.com/scionproto/scion/go/lib/topology/overlay" "github.com/scionproto/scion/go/lib/xtest" "github.com/scionproto/scion/go/lib/xtest/mock_xtest" "github.com/scionproto/scion/go/proto" diff --git a/go/lib/infra/modules/itopo/topology.go b/go/lib/infra/modules/itopo/topology.go index 5c93cb3eaf..8faf5f982f 100644 --- a/go/lib/infra/modules/itopo/topology.go +++ b/go/lib/infra/modules/itopo/topology.go @@ -19,11 +19,11 @@ import ( "github.com/scionproto/scion/go/lib/addr" "github.com/scionproto/scion/go/lib/common" - "github.com/scionproto/scion/go/lib/overlay" "github.com/scionproto/scion/go/lib/scmp" "github.com/scionproto/scion/go/lib/serrors" "github.com/scionproto/scion/go/lib/snet" "github.com/scionproto/scion/go/lib/topology" + "github.com/scionproto/scion/go/lib/topology/overlay" "github.com/scionproto/scion/go/proto" ) @@ -66,19 +66,19 @@ type Topology interface { SBRAddress(name string) *snet.Addr // OverlayAnycast returns the overlay address for an arbitrary server of the requested type. - OverlayAnycast(svc addr.HostSVC) (*overlay.OverlayAddr, error) + OverlayAnycast(svc addr.HostSVC) (*net.UDPAddr, error) // OverlayMulticast returns all overlay addresses for the requested type. - OverlayMulticast(svc addr.HostSVC) ([]*overlay.OverlayAddr, error) + OverlayMulticast(svc addr.HostSVC) ([]*net.UDPAddr, error) // OverlayByName returns the overlay address of the server name of the requested type. // // FIXME(scrye): This isn't really needed. We should also get rid of it. - OverlayByName(svc addr.HostSVC, name string) (*overlay.OverlayAddr, error) + OverlayByName(svc addr.HostSVC, name string) (*net.UDPAddr, error) // OverlayNextHop2 returns the internal overlay address of the router containing the ID. The // return value is encoded as an overlay address. // // FIXME(scrye): Remove either this or the other method. A single return type should be // supported. - OverlayNextHop2(ifID common.IFIDType) (*overlay.OverlayAddr, bool) + OverlayNextHop2(ifID common.IFIDType) (*net.UDPAddr, bool) // OverlayNextHop returns the internal overlay address of the router // containing the interface ID. @@ -204,12 +204,12 @@ func (t *topologyS) OverlayNextHop(ifid common.IFIDType) (*net.UDPAddr, bool) { return nil, false } -func (t *topologyS) OverlayNextHop2(ifid common.IFIDType) (*overlay.OverlayAddr, bool) { +func (t *topologyS) OverlayNextHop2(ifid common.IFIDType) (*net.UDPAddr, bool) { ifInfo, ok := t.Topology.IFInfoMap[ifid] if !ok { return nil, false } - return ifInfo.InternalAddrs.PublicOverlay(t.Topology.Overlay).Copy(), true + return ifInfo.InternalAddrs.PublicOverlayUDP(t.Topology.Overlay), true } func (t *topologyS) MakeHostInfos(st proto.ServiceType) []net.UDPAddr { @@ -314,7 +314,7 @@ func (t *topologyS) topoAddress(svc addr.HostSVC, name string) *topology.TopoAdd return addresses.GetById(name) } -func (t *topologyS) OverlayAnycast(svc addr.HostSVC) (*overlay.OverlayAddr, error) { +func (t *topologyS) OverlayAnycast(svc addr.HostSVC) (*net.UDPAddr, error) { st, err := toProtoServiceType(svc) if err != nil { return nil, err @@ -326,14 +326,14 @@ func (t *topologyS) OverlayAnycast(svc addr.HostSVC) (*overlay.OverlayAddr, erro return nil, common.NewBasicError("No instances found for SVC address", scmp.NewError(scmp.C_Routing, scmp.T_R_UnreachHost, nil, nil), "svc", svc) } - overlayAddr := topoAddr.OverlayAddr(t.Topology.Overlay) - if overlayAddr == nil { + ov := topoAddr.OverlayAddrUDP(t.Topology.Overlay) + if ov == nil { return nil, serrors.New("overlay address not found", "svc", svc) } - return overlayAddr.Copy(), nil + return ov, nil } -func (t *topologyS) OverlayMulticast(svc addr.HostSVC) ([]*overlay.OverlayAddr, error) { +func (t *topologyS) OverlayMulticast(svc addr.HostSVC) ([]*net.UDPAddr, error) { st, err := toProtoServiceType(svc) if err != nil { return nil, err @@ -352,23 +352,23 @@ func (t *topologyS) OverlayMulticast(svc addr.HostSVC) ([]*overlay.OverlayAddr, // Only select each IP:OverlayPort combination once, s.t. the same message isn't multicasted // multiple times by the remote dispatcher. - uniqueOverlayAddrs := make(map[string]*overlay.OverlayAddr) + uniqueOverlayAddrs := make(map[string]*net.UDPAddr) for _, topoAddr := range topoAddrs { - overlayAddr := topoAddr.OverlayAddr(t.Topology.Overlay) + overlayAddr := topoAddr.OverlayAddrUDP(t.Topology.Overlay) if overlayAddr == nil { continue } uniqueOverlayAddrs[overlayAddr.String()] = overlayAddr } - var overlayAddrs []*overlay.OverlayAddr + var overlayAddrs []*net.UDPAddr for _, overlayAddr := range uniqueOverlayAddrs { - overlayAddrs = append(overlayAddrs, overlayAddr.Copy()) + overlayAddrs = append(overlayAddrs, overlayAddr) } return overlayAddrs, nil } -func (t *topologyS) OverlayByName(svc addr.HostSVC, name string) (*overlay.OverlayAddr, error) { +func (t *topologyS) OverlayByName(svc addr.HostSVC, name string) (*net.UDPAddr, error) { st, err := toProtoServiceType(svc) if err != nil { return nil, err @@ -377,11 +377,11 @@ func (t *topologyS) OverlayByName(svc addr.HostSVC, name string) (*overlay.Overl if err != nil { return nil, serrors.WrapStr("SVC not supported", err, "svc", svc) } - overlayAddr := topoAddr.OverlayAddr(t.Topology.Overlay) + overlayAddr := topoAddr.OverlayAddrUDP(t.Topology.Overlay) if overlayAddr == nil { return nil, serrors.New("overlay address not found", "svc", svc) } - return overlayAddr.Copy(), nil + return overlayAddr, nil } func toProtoServiceType(svc addr.HostSVC) (proto.ServiceType, error) { @@ -418,7 +418,7 @@ func (t *topologyS) SBRAddress(name string) *snet.Addr { return &snet.Addr{ IA: t.IA(), Host: br.CtrlAddrs.PublicAddr(br.CtrlAddrs.Overlay), - NextHop: br.CtrlAddrs.OverlayAddr(br.CtrlAddrs.Overlay), + NextHop: br.CtrlAddrs.OverlayAddrUDP(br.CtrlAddrs.Overlay), } } diff --git a/go/lib/infra/modules/itopo/validate_test.go b/go/lib/infra/modules/itopo/validate_test.go index 1d11b4cdd2..85273b7dd6 100644 --- a/go/lib/infra/modules/itopo/validate_test.go +++ b/go/lib/infra/modules/itopo/validate_test.go @@ -20,8 +20,8 @@ import ( . "github.com/smartystreets/goconvey/convey" - "github.com/scionproto/scion/go/lib/overlay" "github.com/scionproto/scion/go/lib/topology" + "github.com/scionproto/scion/go/lib/topology/overlay" "github.com/scionproto/scion/go/proto" ) diff --git a/go/lib/overlay/conn/BUILD.bazel b/go/lib/overlay/conn/BUILD.bazel index c50f81de64..329ce65d81 100644 --- a/go/lib/overlay/conn/BUILD.bazel +++ b/go/lib/overlay/conn/BUILD.bazel @@ -10,9 +10,9 @@ go_library( "//go/lib/assert:go_default_library", "//go/lib/common:go_default_library", "//go/lib/log:go_default_library", - "//go/lib/overlay:go_default_library", "//go/lib/serrors:go_default_library", "//go/lib/sockctrl:go_default_library", + "//go/lib/topology/overlay:go_default_library", "@org_golang_x_net//ipv4:go_default_library", "@org_golang_x_net//ipv6:go_default_library", ], @@ -20,9 +20,9 @@ go_library( "//go/lib/assert:go_default_library", "//go/lib/common:go_default_library", "//go/lib/log:go_default_library", - "//go/lib/overlay:go_default_library", "//go/lib/serrors:go_default_library", "//go/lib/sockctrl:go_default_library", + "//go/lib/topology/overlay:go_default_library", "@org_golang_x_net//ipv4:go_default_library", "@org_golang_x_net//ipv6:go_default_library", ], diff --git a/go/lib/overlay/conn/conn.go b/go/lib/overlay/conn/conn.go index 99e1185b9d..f6810670f0 100644 --- a/go/lib/overlay/conn/conn.go +++ b/go/lib/overlay/conn/conn.go @@ -30,9 +30,9 @@ import ( "github.com/scionproto/scion/go/lib/assert" "github.com/scionproto/scion/go/lib/common" "github.com/scionproto/scion/go/lib/log" - "github.com/scionproto/scion/go/lib/overlay" "github.com/scionproto/scion/go/lib/serrors" "github.com/scionproto/scion/go/lib/sockctrl" + "github.com/scionproto/scion/go/lib/topology/overlay" ) // ReceiveBufferSize is the default size, in bytes, of receive buffers for @@ -56,10 +56,10 @@ type Conn interface { Read(common.RawBytes) (int, *ReadMeta, error) ReadBatch(Messages, []ReadMeta) (int, error) Write(common.RawBytes) (int, error) - WriteTo(common.RawBytes, *overlay.OverlayAddr) (int, error) + WriteTo(common.RawBytes, *net.UDPAddr) (int, error) WriteBatch(Messages) (int, error) - LocalAddr() *overlay.OverlayAddr - RemoteAddr() *overlay.OverlayAddr + LocalAddr() *net.UDPAddr + RemoteAddr() *net.UDPAddr SetReadDeadline(time.Time) error SetWriteDeadline(time.Time) error SetDeadline(time.Time) error @@ -84,24 +84,21 @@ func (c *Config) getReceiveBufferSize() int { // // The config can be used to customize socket behavior. If config is nil, // default values are used. -func New(listen, remote *overlay.OverlayAddr, cfg *Config) (Conn, error) { +func New(listen, remote *net.UDPAddr, cfg *Config) (Conn, error) { if cfg == nil { cfg = &Config{} } - if assert.On { - assert.Must(listen != nil || remote != nil, "Either listen or remote must be set") - } a := listen if remote != nil { a = remote } - switch a.Type() { - case overlay.UDPIPv6: - return newConnUDPIPv6(listen, remote, cfg) - case overlay.UDPIPv4: + if assert.On { + assert.Must(listen != nil || remote != nil, "Either listen or remote must be set") + } + if a.IP.To4() != nil { return newConnUDPIPv4(listen, remote, cfg) } - return nil, common.NewBasicError("Unsupported overlay type", nil, "overlay", a.Type()) + return newConnUDPIPv6(listen, remote, cfg) } type connUDPIPv4 struct { @@ -109,7 +106,7 @@ type connUDPIPv4 struct { pconn *ipv4.PacketConn } -func newConnUDPIPv4(listen, remote *overlay.OverlayAddr, cfg *Config) (*connUDPIPv4, error) { +func newConnUDPIPv4(listen, remote *net.UDPAddr, cfg *Config) (*connUDPIPv4, error) { cc := &connUDPIPv4{} if err := cc.initConnUDP("udp4", listen, remote, cfg); err != nil { return nil, err @@ -162,7 +159,7 @@ type connUDPIPv6 struct { pconn *ipv6.PacketConn } -func newConnUDPIPv6(listen, remote *overlay.OverlayAddr, cfg *Config) (*connUDPIPv6, error) { +func newConnUDPIPv6(listen, remote *net.UDPAddr, cfg *Config) (*connUDPIPv6, error) { cc := &connUDPIPv6{} if err := cc.initConnUDP("udp6", listen, remote, cfg); err != nil { return nil, err @@ -212,64 +209,53 @@ func (c *connUDPIPv6) SetDeadline(t time.Time) error { type connUDPBase struct { conn *net.UDPConn - Listen *overlay.OverlayAddr - Remote *overlay.OverlayAddr + Listen *net.UDPAddr + Remote *net.UDPAddr oob common.RawBytes closed bool readMeta ReadMeta } -func (cc *connUDPBase) initConnUDP(network string, listen, remote *overlay.OverlayAddr, - cfg *Config) error { - - var laddr, raddr *net.UDPAddr +func (cc *connUDPBase) initConnUDP(network string, laddr, raddr *net.UDPAddr, cfg *Config) error { var c *net.UDPConn var err error - if listen == nil { - return serrors.New("listen address must be specified") - } - laddr = listen.ToUDPAddr() if laddr == nil { - return common.NewBasicError("Invalid listen address", nil, "addr", listen) + return serrors.New("listen address must be specified") } - if remote == nil { + if raddr == nil { if c, err = net.ListenUDP(network, laddr); err != nil { return common.NewBasicError("Error listening on socket", err, - "network", network, "listen", listen) + "network", network, "listen", laddr) } } else { - raddr = remote.ToUDPAddr() - if raddr == nil { - return common.NewBasicError("Invalid remote address", nil, "addr", remote) - } if c, err = net.DialUDP(network, laddr, raddr); err != nil { return common.NewBasicError("Error setting up connection", err, - "network", network, "listen", listen, "remote", remote) + "network", network, "listen", laddr, "remote", raddr) } } // Set reporting socket options if err := sockctrl.SetsockoptInt(c, syscall.SOL_SOCKET, syscall.SO_RXQ_OVFL, 1); err != nil { return common.NewBasicError("Error setting SO_RXQ_OVFL socket option", err, - "listen", listen, "remote", remote) + "listen", laddr, "remote", raddr) } if err := sockctrl.SetsockoptInt(c, syscall.SOL_SOCKET, syscall.SO_TIMESTAMPNS, 1); err != nil { return common.NewBasicError("Error setting SO_TIMESTAMPNS socket option", err, - "listen", listen, "remote", remote) + "listen", laddr, "remote", raddr) } // Set and confirm receive buffer size before, err := sockctrl.GetsockoptInt(c, syscall.SOL_SOCKET, syscall.SO_RCVBUF) if err != nil { return common.NewBasicError("Error getting SO_RCVBUF socket option (before)", err, - "listen", listen, "remote", remote) + "listen", laddr, "remote", raddr) } if err = c.SetReadBuffer(cfg.getReceiveBufferSize()); err != nil { return common.NewBasicError("Error setting recv buffer size", err, - "listen", listen, "remote", remote) + "listen", laddr, "remote", raddr) } after, err := sockctrl.GetsockoptInt(c, syscall.SOL_SOCKET, syscall.SO_RCVBUF) if err != nil { return common.NewBasicError("Error getting SO_RCVBUF socket option (after)", err, - "listen", listen, "remote", remote) + "listen", laddr, "remote", raddr) } if after/2 != ReceiveBufferSize { msg := "Receive buffer size smaller than requested" @@ -282,8 +268,8 @@ func (cc *connUDPBase) initConnUDP(network string, listen, remote *overlay.Overl } oob := make(common.RawBytes, oobSize) cc.conn = c - cc.Listen = listen - cc.Remote = remote + cc.Listen = laddr + cc.Remote = raddr cc.oob = oob return nil } @@ -298,7 +284,10 @@ func (c *connUDPBase) Read(b common.RawBytes) (int, *ReadMeta, error) { if c.Remote != nil { c.readMeta.Src = c.Remote } else { - c.readMeta.Src = overlay.NewOverlayAddr(src.IP, uint16(src.Port)) + c.readMeta.Src = &net.UDPAddr{ + IP: src.IP, + Port: src.Port, + } } return n, &c.readMeta, err } @@ -341,22 +330,21 @@ func (c *connUDPBase) Write(b common.RawBytes) (int, error) { return c.conn.Write(b) } -func (c *connUDPBase) WriteTo(b common.RawBytes, dst *overlay.OverlayAddr) (int, error) { +func (c *connUDPBase) WriteTo(b common.RawBytes, dst *net.UDPAddr) (int, error) { if c.Remote != nil { return c.conn.Write(b) } if assert.On { - assert.Must(dst.L4() != 0, "OverlayPort must not be 0") + assert.Must(dst.Port != 0, "Underlay port must not be 0") } - addr := &net.UDPAddr{IP: dst.L3().IP(), Port: int(dst.L4())} - return c.conn.WriteTo(b, addr) + return c.conn.WriteTo(b, dst) } -func (c *connUDPBase) LocalAddr() *overlay.OverlayAddr { +func (c *connUDPBase) LocalAddr() *net.UDPAddr { return c.Listen } -func (c *connUDPBase) RemoteAddr() *overlay.OverlayAddr { +func (c *connUDPBase) RemoteAddr() *net.UDPAddr { return c.Remote } @@ -371,9 +359,9 @@ func (c *connUDPBase) Close() error { // ReadMeta contains extra information about socket reads. type ReadMeta struct { // Src is the remote address from which the datagram was received - Src *overlay.OverlayAddr + Src *net.UDPAddr // Local is the address on which the datagram was received - Local *overlay.OverlayAddr + Local *net.UDPAddr // RcvOvfl is the total number of packets that were dropped by the OS due // to the receive buffers being full. RcvOvfl uint32 @@ -393,11 +381,14 @@ func (m *ReadMeta) reset() { m.ReadDelay = 0 } -func (m *ReadMeta) setSrc(a *overlay.OverlayAddr, raddr *net.UDPAddr, ot overlay.Type) { +func (m *ReadMeta) setSrc(a *net.UDPAddr, raddr *net.UDPAddr, ot overlay.Type) { if a != nil { m.Src = a } else { - m.Src = overlay.NewOverlayAddr(raddr.IP, uint16(raddr.Port)) + m.Src = &net.UDPAddr{ + IP: raddr.IP, + Port: raddr.Port, + } } } diff --git a/go/lib/overlay/conn/mock_conn/BUILD.bazel b/go/lib/overlay/conn/mock_conn/BUILD.bazel index 479b6d7512..ba0e013f4d 100644 --- a/go/lib/overlay/conn/mock_conn/BUILD.bazel +++ b/go/lib/overlay/conn/mock_conn/BUILD.bazel @@ -7,7 +7,6 @@ go_library( visibility = ["//visibility:public"], deps = [ "//go/lib/common:go_default_library", - "//go/lib/overlay:go_default_library", "//go/lib/overlay/conn:go_default_library", "@com_github_golang_mock//gomock:go_default_library", ], diff --git a/go/lib/overlay/conn/mock_conn/conn.go b/go/lib/overlay/conn/mock_conn/conn.go index 99fc3a9f2c..15c1488205 100644 --- a/go/lib/overlay/conn/mock_conn/conn.go +++ b/go/lib/overlay/conn/mock_conn/conn.go @@ -7,8 +7,8 @@ package mock_conn import ( gomock "github.com/golang/mock/gomock" common "github.com/scionproto/scion/go/lib/common" - overlay "github.com/scionproto/scion/go/lib/overlay" conn "github.com/scionproto/scion/go/lib/overlay/conn" + net "net" reflect "reflect" time "time" ) @@ -51,10 +51,10 @@ func (mr *MockConnMockRecorder) Close() *gomock.Call { } // LocalAddr mocks base method -func (m *MockConn) LocalAddr() *overlay.OverlayAddr { +func (m *MockConn) LocalAddr() *net.UDPAddr { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "LocalAddr") - ret0, _ := ret[0].(*overlay.OverlayAddr) + ret0, _ := ret[0].(*net.UDPAddr) return ret0 } @@ -96,10 +96,10 @@ func (mr *MockConnMockRecorder) ReadBatch(arg0, arg1 interface{}) *gomock.Call { } // RemoteAddr mocks base method -func (m *MockConn) RemoteAddr() *overlay.OverlayAddr { +func (m *MockConn) RemoteAddr() *net.UDPAddr { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "RemoteAddr") - ret0, _ := ret[0].(*overlay.OverlayAddr) + ret0, _ := ret[0].(*net.UDPAddr) return ret0 } @@ -182,7 +182,7 @@ func (mr *MockConnMockRecorder) WriteBatch(arg0 interface{}) *gomock.Call { } // WriteTo mocks base method -func (m *MockConn) WriteTo(arg0 common.RawBytes, arg1 *overlay.OverlayAddr) (int, error) { +func (m *MockConn) WriteTo(arg0 common.RawBytes, arg1 *net.UDPAddr) (int, error) { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "WriteTo", arg0, arg1) ret0, _ := ret[0].(int) diff --git a/go/lib/sciond/pathprobe/paths.go b/go/lib/sciond/pathprobe/paths.go index d8b9ab3bfa..8d5fc1c832 100644 --- a/go/lib/sciond/pathprobe/paths.go +++ b/go/lib/sciond/pathprobe/paths.go @@ -136,20 +136,16 @@ func (p Prober) send(scionConn snet.Conn, path sciond.PathReplyEntry) error { if err := sPath.InitOffsets(); err != nil { return common.NewBasicError("unable to initialize path", err) } - nextHop, err := path.HostInfo.Overlay() - if err != nil { - return common.NewBasicError("unable to get overlay info", err) - } addr := &snet.Addr{ IA: p.DstIA, Host: &addr.AppAddr{ L3: addr.HostSVCFromString("NONE"), }, - NextHop: nextHop, + NextHop: path.HostInfo.Overlay(), Path: sPath, } log.Debug("Sending test packet.", "path", path.Path.String()) - _, err = scionConn.WriteTo([]byte{}, addr) + _, err := scionConn.WriteTo([]byte{}, addr) if err != nil { return common.NewBasicError("cannot send packet", err) } diff --git a/go/lib/snet/BUILD.bazel b/go/lib/snet/BUILD.bazel index d0f4d70648..5c44c1f3fa 100644 --- a/go/lib/snet/BUILD.bazel +++ b/go/lib/snet/BUILD.bazel @@ -24,7 +24,6 @@ go_library( "//go/lib/hpkt:go_default_library", "//go/lib/l4:go_default_library", "//go/lib/log:go_default_library", - "//go/lib/overlay:go_default_library", "//go/lib/pathmgr:go_default_library", "//go/lib/pathpol:go_default_library", "//go/lib/sciond:go_default_library", @@ -37,6 +36,7 @@ go_library( "//go/lib/spath:go_default_library", "//go/lib/spath/spathmeta:go_default_library", "//go/lib/spkt:go_default_library", + "//go/lib/topology:go_default_library", ], ) @@ -54,13 +54,13 @@ go_test( "//go/lib/common:go_default_library", "//go/lib/layers:go_default_library", "//go/lib/mocks/net/mock_net:go_default_library", - "//go/lib/overlay:go_default_library", "//go/lib/pathmgr/mock_pathmgr:go_default_library", "//go/lib/snet/internal/ctxmonitor:go_default_library", "//go/lib/snet/internal/ctxmonitor/mock_ctxmonitor:go_default_library", "//go/lib/snet/internal/pathsource/mock_pathsource:go_default_library", "//go/lib/spath:go_default_library", "//go/lib/spath/spathmeta:go_default_library", + "//go/lib/topology:go_default_library", "//go/lib/xtest:go_default_library", "@com_github_golang_mock//gomock:go_default_library", "@com_github_stretchr_testify//assert:go_default_library", diff --git a/go/lib/snet/addr.go b/go/lib/snet/addr.go index b1baa52b2e..05f7e62773 100644 --- a/go/lib/snet/addr.go +++ b/go/lib/snet/addr.go @@ -23,7 +23,6 @@ import ( "github.com/scionproto/scion/go/lib/addr" "github.com/scionproto/scion/go/lib/common" - "github.com/scionproto/scion/go/lib/overlay" "github.com/scionproto/scion/go/lib/spath" ) @@ -37,7 +36,7 @@ type Addr struct { IA addr.IA Host *addr.AppAddr Path *spath.Path - NextHop *overlay.OverlayAddr + NextHop *net.UDPAddr } func (a *Addr) Network() string { @@ -101,7 +100,7 @@ func (a *Addr) Copy() *Addr { newA.Path = a.Path.Copy() } if a.NextHop != nil { - newA.NextHop = a.NextHop.Copy() + newA.NextHop = CopyUDPAddr(a.NextHop) } return newA } @@ -179,3 +178,13 @@ func (a *Addr) Set(s string) error { a.IA, a.Host = other.IA, other.Host return nil } + +func CopyUDPAddr(a *net.UDPAddr) *net.UDPAddr { + if a == nil { + return nil + } + return &net.UDPAddr{ + IP: append(a.IP[:0:0], a.IP...), + Port: a.Port, + } +} diff --git a/go/lib/snet/dispatcher.go b/go/lib/snet/dispatcher.go index 6a61356489..557d59b58e 100644 --- a/go/lib/snet/dispatcher.go +++ b/go/lib/snet/dispatcher.go @@ -16,13 +16,13 @@ package snet import ( "context" + "net" "time" "github.com/scionproto/scion/go/lib/addr" "github.com/scionproto/scion/go/lib/common" "github.com/scionproto/scion/go/lib/ctrl/path_mgmt" "github.com/scionproto/scion/go/lib/log" - "github.com/scionproto/scion/go/lib/overlay" "github.com/scionproto/scion/go/lib/scmp" "github.com/scionproto/scion/go/lib/snet/internal/metrics" "github.com/scionproto/scion/go/lib/sock/reliable" @@ -31,7 +31,7 @@ import ( // PacketDispatcherService constructs SCION sockets where applications have // fine-grained control over header fields. type PacketDispatcherService interface { - RegisterTimeout(ia addr.IA, public *addr.AppAddr, bind *overlay.OverlayAddr, + RegisterTimeout(ia addr.IA, public *addr.AppAddr, bind *net.UDPAddr, svc addr.HostSVC, timeout time.Duration) (PacketConn, uint16, error) } @@ -49,7 +49,7 @@ type DefaultPacketDispatcherService struct { } func (s *DefaultPacketDispatcherService) RegisterTimeout(ia addr.IA, public *addr.AppAddr, - bind *overlay.OverlayAddr, svc addr.HostSVC, + bind *net.UDPAddr, svc addr.HostSVC, timeout time.Duration) (PacketConn, uint16, error) { rconn, port, err := s.Dispatcher.RegisterTimeout(ia, public, bind, svc, timeout) diff --git a/go/lib/snet/internal/pathsource/BUILD.bazel b/go/lib/snet/internal/pathsource/BUILD.bazel index 4bf9cb3a38..62e47608d8 100644 --- a/go/lib/snet/internal/pathsource/BUILD.bazel +++ b/go/lib/snet/internal/pathsource/BUILD.bazel @@ -8,7 +8,6 @@ go_library( deps = [ "//go/lib/addr:go_default_library", "//go/lib/common:go_default_library", - "//go/lib/overlay:go_default_library", "//go/lib/pathmgr:go_default_library", "//go/lib/sciond:go_default_library", "//go/lib/spath:go_default_library", diff --git a/go/lib/snet/internal/pathsource/mock_pathsource/BUILD.bazel b/go/lib/snet/internal/pathsource/mock_pathsource/BUILD.bazel index 10fb090a01..151afeb7da 100644 --- a/go/lib/snet/internal/pathsource/mock_pathsource/BUILD.bazel +++ b/go/lib/snet/internal/pathsource/mock_pathsource/BUILD.bazel @@ -7,7 +7,6 @@ go_library( visibility = ["//go/lib/snet:__subpackages__"], deps = [ "//go/lib/addr:go_default_library", - "//go/lib/overlay:go_default_library", "//go/lib/spath:go_default_library", "@com_github_golang_mock//gomock:go_default_library", ], diff --git a/go/lib/snet/internal/pathsource/mock_pathsource/pathsource.go b/go/lib/snet/internal/pathsource/mock_pathsource/pathsource.go index ebe05e1fdd..48225c017a 100644 --- a/go/lib/snet/internal/pathsource/mock_pathsource/pathsource.go +++ b/go/lib/snet/internal/pathsource/mock_pathsource/pathsource.go @@ -8,8 +8,8 @@ import ( context "context" gomock "github.com/golang/mock/gomock" addr "github.com/scionproto/scion/go/lib/addr" - overlay "github.com/scionproto/scion/go/lib/overlay" spath "github.com/scionproto/scion/go/lib/spath" + net "net" reflect "reflect" ) @@ -37,10 +37,10 @@ func (m *MockPathSource) EXPECT() *MockPathSourceMockRecorder { } // Get mocks base method -func (m *MockPathSource) Get(arg0 context.Context, arg1, arg2 addr.IA) (*overlay.OverlayAddr, *spath.Path, error) { +func (m *MockPathSource) Get(arg0 context.Context, arg1, arg2 addr.IA) (*net.UDPAddr, *spath.Path, error) { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "Get", arg0, arg1, arg2) - ret0, _ := ret[0].(*overlay.OverlayAddr) + ret0, _ := ret[0].(*net.UDPAddr) ret1, _ := ret[1].(*spath.Path) ret2, _ := ret[2].(error) return ret0, ret1, ret2 diff --git a/go/lib/snet/internal/pathsource/pathsource.go b/go/lib/snet/internal/pathsource/pathsource.go index 2637315598..c5a8f0611b 100644 --- a/go/lib/snet/internal/pathsource/pathsource.go +++ b/go/lib/snet/internal/pathsource/pathsource.go @@ -16,10 +16,10 @@ package pathsource import ( "context" + "net" "github.com/scionproto/scion/go/lib/addr" "github.com/scionproto/scion/go/lib/common" - "github.com/scionproto/scion/go/lib/overlay" "github.com/scionproto/scion/go/lib/pathmgr" "github.com/scionproto/scion/go/lib/sciond" "github.com/scionproto/scion/go/lib/spath" @@ -29,12 +29,11 @@ const ( ErrNoResolver common.ErrMsg = "no resolver set" ErrNoPath common.ErrMsg = "path not found" ErrInitPath common.ErrMsg = "raw forwarding path offsets could not be initialized" - ErrBadOverlay common.ErrMsg = "unable to extract next hop from sciond path entry" ) // PathSource is a source of paths and overlay addresses for snet. type PathSource interface { - Get(ctx context.Context, src, dst addr.IA) (*overlay.OverlayAddr, *spath.Path, error) + Get(ctx context.Context, src, dst addr.IA) (*net.UDPAddr, *spath.Path, error) } type pathSource struct { @@ -49,7 +48,7 @@ func NewPathSource(resolver pathmgr.Resolver) PathSource { } func (ps *pathSource) Get(ctx context.Context, - src, dst addr.IA) (*overlay.OverlayAddr, *spath.Path, error) { + src, dst addr.IA) (*net.UDPAddr, *spath.Path, error) { if ps.resolver == nil { return nil, nil, common.NewBasicError(ErrNoResolver, nil) @@ -63,9 +62,6 @@ func (ps *pathSource) Get(ctx context.Context, if err := path.InitOffsets(); err != nil { return nil, nil, common.NewBasicError(ErrInitPath, nil) } - overlayAddr, err := sciondPath.Entry.HostInfo.Overlay() - if err != nil { - return nil, nil, common.NewBasicError(ErrBadOverlay, nil) - } + overlayAddr := sciondPath.Entry.HostInfo.Overlay() return overlayAddr, path, nil } diff --git a/go/lib/snet/mock_snet/BUILD.bazel b/go/lib/snet/mock_snet/BUILD.bazel index 27487efe7c..405e3b8388 100644 --- a/go/lib/snet/mock_snet/BUILD.bazel +++ b/go/lib/snet/mock_snet/BUILD.bazel @@ -7,7 +7,6 @@ go_library( visibility = ["//visibility:public"], deps = [ "//go/lib/addr:go_default_library", - "//go/lib/overlay:go_default_library", "//go/lib/snet:go_default_library", "//go/lib/spath:go_default_library", "@com_github_golang_mock//gomock:go_default_library", diff --git a/go/lib/snet/mock_snet/snet.go b/go/lib/snet/mock_snet/snet.go index 63e9f7ada3..6adb77ffd9 100644 --- a/go/lib/snet/mock_snet/snet.go +++ b/go/lib/snet/mock_snet/snet.go @@ -8,7 +8,6 @@ import ( context "context" gomock "github.com/golang/mock/gomock" addr "github.com/scionproto/scion/go/lib/addr" - overlay "github.com/scionproto/scion/go/lib/overlay" snet "github.com/scionproto/scion/go/lib/snet" spath "github.com/scionproto/scion/go/lib/spath" net "net" @@ -267,7 +266,7 @@ func (m *MockPacketDispatcherService) EXPECT() *MockPacketDispatcherServiceMockR } // RegisterTimeout mocks base method -func (m *MockPacketDispatcherService) RegisterTimeout(arg0 addr.IA, arg1 *addr.AppAddr, arg2 *overlay.OverlayAddr, arg3 addr.HostSVC, arg4 time.Duration) (snet.PacketConn, uint16, error) { +func (m *MockPacketDispatcherService) RegisterTimeout(arg0 addr.IA, arg1 *addr.AppAddr, arg2 *net.UDPAddr, arg3 addr.HostSVC, arg4 time.Duration) (snet.PacketConn, uint16, error) { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "RegisterTimeout", arg0, arg1, arg2, arg3, arg4) ret0, _ := ret[0].(snet.PacketConn) @@ -373,7 +372,7 @@ func (mr *MockPacketConnMockRecorder) Close() *gomock.Call { } // ReadFrom mocks base method -func (m *MockPacketConn) ReadFrom(arg0 *snet.SCIONPacket, arg1 *overlay.OverlayAddr) error { +func (m *MockPacketConn) ReadFrom(arg0 *snet.SCIONPacket, arg1 *net.UDPAddr) error { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "ReadFrom", arg0, arg1) ret0, _ := ret[0].(error) @@ -429,7 +428,7 @@ func (mr *MockPacketConnMockRecorder) SetWriteDeadline(arg0 interface{}) *gomock } // WriteTo mocks base method -func (m *MockPacketConn) WriteTo(arg0 *snet.SCIONPacket, arg1 *overlay.OverlayAddr) error { +func (m *MockPacketConn) WriteTo(arg0 *snet.SCIONPacket, arg1 *net.UDPAddr) error { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "WriteTo", arg0, arg1) ret0, _ := ret[0].(error) @@ -550,10 +549,10 @@ func (mr *MockPathMockRecorder) MTU() *gomock.Call { } // OverlayNextHop mocks base method -func (m *MockPath) OverlayNextHop() *overlay.OverlayAddr { +func (m *MockPath) OverlayNextHop() *net.UDPAddr { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "OverlayNextHop") - ret0, _ := ret[0].(*overlay.OverlayAddr) + ret0, _ := ret[0].(*net.UDPAddr) return ret0 } diff --git a/go/lib/snet/packet_conn.go b/go/lib/snet/packet_conn.go index 0dd4f6d363..fdf6e92a01 100644 --- a/go/lib/snet/packet_conn.go +++ b/go/lib/snet/packet_conn.go @@ -23,7 +23,6 @@ import ( "github.com/scionproto/scion/go/lib/common" "github.com/scionproto/scion/go/lib/hpkt" "github.com/scionproto/scion/go/lib/l4" - "github.com/scionproto/scion/go/lib/overlay" "github.com/scionproto/scion/go/lib/scmp" "github.com/scionproto/scion/go/lib/snet/internal/metrics" "github.com/scionproto/scion/go/lib/spath" @@ -33,8 +32,8 @@ import ( // PacketConn gives applications easy access to writing and reading custom // SCION packets. type PacketConn interface { - ReadFrom(pkt *SCIONPacket, ov *overlay.OverlayAddr) error - WriteTo(pkt *SCIONPacket, ov *overlay.OverlayAddr) error + ReadFrom(pkt *SCIONPacket, ov *net.UDPAddr) error + WriteTo(pkt *SCIONPacket, ov *net.UDPAddr) error SetReadDeadline(t time.Time) error SetWriteDeadline(t time.Time) error SetDeadline(t time.Time) error @@ -145,7 +144,7 @@ func (c *SCIONPacketConn) Close() error { return c.conn.Close() } -func (c *SCIONPacketConn) WriteTo(pkt *SCIONPacket, ov *overlay.OverlayAddr) error { +func (c *SCIONPacketConn) WriteTo(pkt *SCIONPacket, ov *net.UDPAddr) error { StableSortExtensions(pkt.Extensions) hbh, e2e, err := hpkt.ValidateExtensions(pkt.Extensions) if err != nil { @@ -184,7 +183,7 @@ func (c *SCIONPacketConn) SetWriteDeadline(d time.Time) error { return c.conn.SetWriteDeadline(d) } -func (c *SCIONPacketConn) ReadFrom(pkt *SCIONPacket, ov *overlay.OverlayAddr) error { +func (c *SCIONPacketConn) ReadFrom(pkt *SCIONPacket, ov *net.UDPAddr) error { for { // Read until we get an error or a data packet if err := c.readFrom(pkt, ov); err != nil { @@ -209,7 +208,7 @@ func (c *SCIONPacketConn) ReadFrom(pkt *SCIONPacket, ov *overlay.OverlayAddr) er } } -func (c *SCIONPacketConn) readFrom(pkt *SCIONPacket, ov *overlay.OverlayAddr) error { +func (c *SCIONPacketConn) readFrom(pkt *SCIONPacket, ov *net.UDPAddr) error { pkt.Prepare() n, lastHopNetAddr, err := c.conn.ReadFrom(pkt.Bytes) if err != nil { @@ -220,10 +219,10 @@ func (c *SCIONPacketConn) readFrom(pkt *SCIONPacket, ov *overlay.OverlayAddr) er metrics.M.ReadPackets().Inc() pkt.Bytes = pkt.Bytes[:n] - var lastHop *overlay.OverlayAddr + var lastHop *net.UDPAddr var ok bool - lastHop, ok = lastHopNetAddr.(*overlay.OverlayAddr) + lastHop, ok = lastHopNetAddr.(*net.UDPAddr) if !ok { return common.NewBasicError("Invalid lastHop address Type", nil, "Actual", lastHopNetAddr) diff --git a/go/lib/snet/path.go b/go/lib/snet/path.go index 17c6363f67..19873223c5 100644 --- a/go/lib/snet/path.go +++ b/go/lib/snet/path.go @@ -17,11 +17,11 @@ package snet import ( "crypto/sha256" "encoding/binary" + "net" "time" "github.com/scionproto/scion/go/lib/addr" "github.com/scionproto/scion/go/lib/common" - "github.com/scionproto/scion/go/lib/overlay" "github.com/scionproto/scion/go/lib/sciond" "github.com/scionproto/scion/go/lib/serrors" "github.com/scionproto/scion/go/lib/spath" @@ -42,7 +42,7 @@ type Path interface { Fingerprint() string // OverlayNextHop returns the address:port pair of a local-AS overlay // speaker. Usually, this is a border router that will forward the traffic. - OverlayNextHop() *overlay.OverlayAddr + OverlayNextHop() *net.UDPAddr // Path returns a raw (data-plane compatible) representation of the path. // The returned path is initialized and ready for use in snet calls that // deal with raw paths. @@ -78,7 +78,7 @@ type path struct { // spath is the raw SCION forwarding path. spath *spath.Path // overlay is the intra-AS next-hop to use for this path. - overlay *overlay.OverlayAddr + overlay *net.UDPAddr // source is the AS where the path starts. source addr.IA } @@ -89,10 +89,7 @@ func newPathFromSDReply(srcIA addr.IA, replyEntry *sciond.PathReplyEntry) (Path, if err := sp.InitOffsets(); err != nil { return nil, serrors.WrapStr("path error", err) } - overlayAddr, err := replyEntry.HostInfo.Overlay() - if err != nil { - return nil, serrors.WrapStr("path error", err) - } + overlayAddr := replyEntry.HostInfo.Overlay() return &path{ sciondPath: replyEntry, spath: sp, @@ -113,8 +110,8 @@ func (p *path) Fingerprint() string { return string(h.Sum(nil)) } -func (p *path) OverlayNextHop() *overlay.OverlayAddr { - return p.overlay.Copy() +func (p *path) OverlayNextHop() *net.UDPAddr { + return copyUDP(p.overlay) } func (p *path) Path() *spath.Path { @@ -160,7 +157,7 @@ func (p *path) Copy() Path { return &path{ sciondPath: p.sciondPath.Copy(), spath: p.spath.Copy(), - overlay: p.overlay.Copy(), + overlay: copyUDP(p.overlay), source: p.source, } } @@ -177,7 +174,7 @@ func (p *path) String() string { // objects, notably snet.Addr. type partialPath struct { spath *spath.Path - overlay *overlay.OverlayAddr + overlay *net.UDPAddr destination addr.IA } @@ -185,7 +182,7 @@ func (p *partialPath) Fingerprint() string { return "" } -func (p *partialPath) OverlayNextHop() *overlay.OverlayAddr { +func (p *partialPath) OverlayNextHop() *net.UDPAddr { return p.overlay } @@ -215,7 +212,17 @@ func (p *partialPath) Expiry() time.Time { func (p *partialPath) Copy() Path { return &partialPath{ spath: p.spath.Copy(), - overlay: p.overlay.Copy(), + overlay: copyUDP(p.overlay), destination: p.destination, } } + +func copyUDP(udp *net.UDPAddr) *net.UDPAddr { + if udp == nil { + return nil + } + return &net.UDPAddr{ + IP: append(udp.IP[:0:0], udp.IP...), + Port: udp.Port, + } +} diff --git a/go/lib/snet/reader.go b/go/lib/snet/reader.go index 1d9e316370..2f4d3271dd 100644 --- a/go/lib/snet/reader.go +++ b/go/lib/snet/reader.go @@ -22,7 +22,6 @@ import ( "github.com/scionproto/scion/go/lib/addr" "github.com/scionproto/scion/go/lib/common" "github.com/scionproto/scion/go/lib/l4" - "github.com/scionproto/scion/go/lib/overlay" "github.com/scionproto/scion/go/lib/scmp" "github.com/scionproto/scion/go/lib/serrors" ) @@ -74,7 +73,7 @@ func (c *scionConnReader) read(b []byte) (int, *Addr, error) { pkt := SCIONPacket{ Bytes: Bytes(c.buffer), } - var lastHop overlay.OverlayAddr + var lastHop net.UDPAddr err := c.conn.ReadFrom(&pkt, &lastHop) if err != nil { return 0, nil, err @@ -105,7 +104,7 @@ func (c *scionConnReader) read(b []byte) (int, *Addr, error) { // Copy the address to prevent races. See // https://github.com/scionproto/scion/issues/1659. - remote.NextHop = lastHop.Copy() + remote.NextHop = CopyUDPAddr(&lastHop) var err error var l4i uint16 diff --git a/go/lib/snet/router.go b/go/lib/snet/router.go index 255e782191..31047d27c1 100644 --- a/go/lib/snet/router.go +++ b/go/lib/snet/router.go @@ -20,7 +20,6 @@ import ( "github.com/scionproto/scion/go/lib/addr" "github.com/scionproto/scion/go/lib/common" - "github.com/scionproto/scion/go/lib/overlay" "github.com/scionproto/scion/go/lib/pathmgr" "github.com/scionproto/scion/go/lib/pathpol" "github.com/scionproto/scion/go/lib/sciond" @@ -131,6 +130,6 @@ func (m *LocalMachine) AppAddress() *addr.AppAddr { // BindAddress returns a bind address for the local machine. The port is // set to 0. -func (m *LocalMachine) BindAddress() *overlay.OverlayAddr { - return overlay.NewOverlayAddr(m.InterfaceIP, 0) +func (m *LocalMachine) BindAddress() *net.UDPAddr { + return &net.UDPAddr{IP: m.InterfaceIP} } diff --git a/go/lib/snet/router_test.go b/go/lib/snet/router_test.go index 3a0fe479f4..d0486b3c50 100644 --- a/go/lib/snet/router_test.go +++ b/go/lib/snet/router_test.go @@ -21,7 +21,6 @@ import ( "github.com/stretchr/testify/assert" "github.com/scionproto/scion/go/lib/addr" - "github.com/scionproto/scion/go/lib/overlay" ) func TestLocalMachineBuildAppAddress(t *testing.T) { @@ -64,13 +63,13 @@ func TestLocalMachineBuildAppAddress(t *testing.T) { func TestLocalMachineBuildBindAddress(t *testing.T) { tests := map[string]struct { Machine *LocalMachine - ExpectedBindAddr *overlay.OverlayAddr + ExpectedBindAddr *net.UDPAddr }{ "bind IP is computed based on default IP": { Machine: &LocalMachine{ InterfaceIP: net.IP{192, 0, 2, 1}, }, - ExpectedBindAddr: overlay.NewOverlayAddr(net.IP{192, 0, 2, 1}, 0), + ExpectedBindAddr: &net.UDPAddr{IP: net.IP{192, 0, 2, 1}}, }, } diff --git a/go/lib/snet/snet.go b/go/lib/snet/snet.go index becbe926ae..608b0ad587 100644 --- a/go/lib/snet/snet.go +++ b/go/lib/snet/snet.go @@ -46,12 +46,12 @@ package snet import ( "context" + "net" "time" "github.com/scionproto/scion/go/lib/addr" "github.com/scionproto/scion/go/lib/common" "github.com/scionproto/scion/go/lib/log" - "github.com/scionproto/scion/go/lib/overlay" "github.com/scionproto/scion/go/lib/pathmgr" "github.com/scionproto/scion/go/lib/sciond" "github.com/scionproto/scion/go/lib/serrors" @@ -245,10 +245,13 @@ func (n *SCIONNetwork) ListenSCIONWithBindSVC(network string, laddr, baddr *Addr return nil, common.NewBasicError("Unable to listen on non-local IA", nil, "expected", conn.scionNet.localIA, "actual", conn.laddr.IA, "type", "public") } - var bindAddr *overlay.OverlayAddr + var bindAddr *net.UDPAddr if baddr != nil { conn.baddr = baddr.Copy() - bindAddr = overlay.NewOverlayAddr(baddr.Host.L3.IP(), baddr.Host.L4) + bindAddr = &net.UDPAddr{ + IP: baddr.Host.L3.IP(), + Port: int(baddr.Host.L4), + } if !conn.baddr.IA.Equal(conn.scionNet.localIA) { return nil, common.NewBasicError("Unable to listen on non-local IA", nil, "expected", conn.scionNet.localIA, "actual", conn.baddr.IA, "type", "bind") diff --git a/go/lib/snet/writer.go b/go/lib/snet/writer.go index f4a0b585f4..0ca57302ad 100644 --- a/go/lib/snet/writer.go +++ b/go/lib/snet/writer.go @@ -23,10 +23,10 @@ import ( "github.com/scionproto/scion/go/lib/addr" "github.com/scionproto/scion/go/lib/common" "github.com/scionproto/scion/go/lib/l4" - "github.com/scionproto/scion/go/lib/overlay" "github.com/scionproto/scion/go/lib/pathmgr" "github.com/scionproto/scion/go/lib/snet/internal/ctxmonitor" "github.com/scionproto/scion/go/lib/snet/internal/pathsource" + "github.com/scionproto/scion/go/lib/topology" ) // Possible write errors @@ -208,6 +208,6 @@ func (r *remoteAddressResolver) addPath(address *Addr) (*Addr, error) { func addOverlayFromScionAddress(address *Addr) *Addr { address = address.Copy() - address.NextHop = overlay.NewOverlayAddr(address.Host.L3.IP(), overlay.EndhostPort) + address.NextHop = &net.UDPAddr{IP: address.Host.L3.IP(), Port: topology.EndhostPort} return address } diff --git a/go/lib/snet/writer_test.go b/go/lib/snet/writer_test.go index bf389a828b..4a497d7e21 100644 --- a/go/lib/snet/writer_test.go +++ b/go/lib/snet/writer_test.go @@ -17,6 +17,7 @@ package snet import ( "context" "fmt" + "net" "testing" "time" @@ -24,13 +25,13 @@ import ( "github.com/stretchr/testify/assert" "github.com/scionproto/scion/go/lib/mocks/net/mock_net" - "github.com/scionproto/scion/go/lib/overlay" "github.com/scionproto/scion/go/lib/pathmgr/mock_pathmgr" "github.com/scionproto/scion/go/lib/snet/internal/ctxmonitor" "github.com/scionproto/scion/go/lib/snet/internal/ctxmonitor/mock_ctxmonitor" "github.com/scionproto/scion/go/lib/snet/internal/pathsource/mock_pathsource" "github.com/scionproto/scion/go/lib/spath" "github.com/scionproto/scion/go/lib/spath/spathmeta" + "github.com/scionproto/scion/go/lib/topology" "github.com/scionproto/scion/go/lib/xtest" ) @@ -94,7 +95,7 @@ func TestRemoteAddressResolver(t *testing.T) { }) t.Run("return same address if path unset, and overlay address set.", func(t *testing.T) { inAddress := MustParseAddr("1-ff00:0:110,[127.0.0.1]:80") - inAddress.NextHop = &overlay.OverlayAddr{} + inAddress.NextHop = &net.UDPAddr{} outAddress, err := resolver.resolveAddr(inAddress) assert.NoError(t, err, "err") assert.Equal(t, outAddress, inAddress) @@ -104,8 +105,8 @@ func TestRemoteAddressResolver(t *testing.T) { outAddress, err := resolver.resolveAddr(inAddress) assert.NoError(t, err) assert.NotNil(t, outAddress) - assert.Equal(t, outAddress.NextHop.L3(), outAddress.Host.L3, "overlay addr") - assert.Equal(t, outAddress.NextHop.L4(), uint16(overlay.EndhostPort), "overlay port") + assert.Equal(t, outAddress.NextHop.IP, outAddress.Host.L3.IP(), "overlay addr") + assert.Equal(t, outAddress.NextHop.Port, topology.EndhostPort, "overlay port") }) }) t.Run("if destination is not in local AS", func(t *testing.T) { @@ -118,7 +119,7 @@ func TestRemoteAddressResolver(t *testing.T) { }) t.Run("error if overlay set but path unset.", func(t *testing.T) { inAddress := MustParseAddr("1-ff00:0:113,[127.0.0.1]:80") - inAddress.NextHop = &overlay.OverlayAddr{} + inAddress.NextHop = &net.UDPAddr{} outAddress, err := resolver.resolveAddr(inAddress) assert.EqualError(t, err, string(ErrMustHavePath)) assert.Nil(t, outAddress, "address") @@ -126,7 +127,7 @@ func TestRemoteAddressResolver(t *testing.T) { t.Run("return same address if path and overlay set.", func(t *testing.T) { inAddress := MustParseAddr("1-ff00:0:113,[127.0.0.1]:80") inAddress.Path = &spath.Path{} - inAddress.NextHop = &overlay.OverlayAddr{} + inAddress.NextHop = &net.UDPAddr{} outAddress, err := resolver.resolveAddr(inAddress) assert.NoError(t, err, "err") assert.Equal(t, outAddress, inAddress) @@ -143,7 +144,7 @@ func TestRemoteAddressResolver(t *testing.T) { t.Run("if request successful, return address.", func(t *testing.T) { inAddress := MustParseAddr("1-ff00:0:113,[127.0.0.1]:80") path := &spath.Path{} - overlayAddr := &overlay.OverlayAddr{} + overlayAddr := &net.UDPAddr{} pathSource.EXPECT().Get(gomock.Any(), gomock.Any(), gomock.Any()). Return(overlayAddr, path, nil) outAddress, err := resolver.resolveAddr(inAddress) diff --git a/go/lib/sock/reliable/BUILD.bazel b/go/lib/sock/reliable/BUILD.bazel index 0ca322f72a..057b591496 100644 --- a/go/lib/sock/reliable/BUILD.bazel +++ b/go/lib/sock/reliable/BUILD.bazel @@ -15,7 +15,6 @@ go_library( deps = [ "//go/lib/addr:go_default_library", "//go/lib/common:go_default_library", - "//go/lib/overlay:go_default_library", "//go/lib/prom:go_default_library", "//go/lib/serrors:go_default_library", "//go/lib/sock/reliable/internal/metrics:go_default_library", diff --git a/go/lib/sock/reliable/mock_reliable/BUILD.bazel b/go/lib/sock/reliable/mock_reliable/BUILD.bazel index b1815a6e7e..4034905fde 100644 --- a/go/lib/sock/reliable/mock_reliable/BUILD.bazel +++ b/go/lib/sock/reliable/mock_reliable/BUILD.bazel @@ -7,7 +7,6 @@ go_library( visibility = ["//visibility:public"], deps = [ "//go/lib/addr:go_default_library", - "//go/lib/overlay:go_default_library", "@com_github_golang_mock//gomock:go_default_library", ], ) diff --git a/go/lib/sock/reliable/mock_reliable/reliable.go b/go/lib/sock/reliable/mock_reliable/reliable.go index fef32d4e2b..a8813c3c44 100644 --- a/go/lib/sock/reliable/mock_reliable/reliable.go +++ b/go/lib/sock/reliable/mock_reliable/reliable.go @@ -7,7 +7,6 @@ package mock_reliable import ( gomock "github.com/golang/mock/gomock" addr "github.com/scionproto/scion/go/lib/addr" - overlay "github.com/scionproto/scion/go/lib/overlay" net "net" reflect "reflect" time "time" @@ -37,7 +36,7 @@ func (m *MockDispatcherService) EXPECT() *MockDispatcherServiceMockRecorder { } // Register mocks base method -func (m *MockDispatcherService) Register(arg0 addr.IA, arg1 *addr.AppAddr, arg2 *overlay.OverlayAddr, arg3 addr.HostSVC) (net.PacketConn, uint16, error) { +func (m *MockDispatcherService) Register(arg0 addr.IA, arg1 *addr.AppAddr, arg2 *net.UDPAddr, arg3 addr.HostSVC) (net.PacketConn, uint16, error) { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "Register", arg0, arg1, arg2, arg3) ret0, _ := ret[0].(net.PacketConn) @@ -53,7 +52,7 @@ func (mr *MockDispatcherServiceMockRecorder) Register(arg0, arg1, arg2, arg3 int } // RegisterTimeout mocks base method -func (m *MockDispatcherService) RegisterTimeout(arg0 addr.IA, arg1 *addr.AppAddr, arg2 *overlay.OverlayAddr, arg3 addr.HostSVC, arg4 time.Duration) (net.PacketConn, uint16, error) { +func (m *MockDispatcherService) RegisterTimeout(arg0 addr.IA, arg1 *addr.AppAddr, arg2 *net.UDPAddr, arg3 addr.HostSVC, arg4 time.Duration) (net.PacketConn, uint16, error) { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "RegisterTimeout", arg0, arg1, arg2, arg3, arg4) ret0, _ := ret[0].(net.PacketConn) diff --git a/go/lib/sock/reliable/reconnect/BUILD.bazel b/go/lib/sock/reliable/reconnect/BUILD.bazel index c72f09fe8b..f42eba639f 100644 --- a/go/lib/sock/reliable/reconnect/BUILD.bazel +++ b/go/lib/sock/reliable/reconnect/BUILD.bazel @@ -16,7 +16,6 @@ go_library( deps = [ "//go/lib/addr:go_default_library", "//go/lib/log:go_default_library", - "//go/lib/overlay:go_default_library", "//go/lib/serrors:go_default_library", "//go/lib/sock/reliable:go_default_library", "//go/lib/sock/reliable/reconnect/internal/metrics:go_default_library", @@ -39,7 +38,6 @@ go_test( "//go/lib/common:go_default_library", "//go/lib/log:go_default_library", "//go/lib/mocks/net/mock_net:go_default_library", - "//go/lib/overlay:go_default_library", "//go/lib/serrors:go_default_library", "//go/lib/snet:go_default_library", "//go/lib/sock/reliable/mock_reliable:go_default_library", diff --git a/go/lib/sock/reliable/reconnect/main_test.go b/go/lib/sock/reliable/reconnect/main_test.go index a8e86e8584..4b01b22406 100644 --- a/go/lib/sock/reliable/reconnect/main_test.go +++ b/go/lib/sock/reliable/reconnect/main_test.go @@ -26,7 +26,6 @@ import ( "github.com/scionproto/scion/go/lib/addr" "github.com/scionproto/scion/go/lib/log" - "github.com/scionproto/scion/go/lib/overlay" "github.com/scionproto/scion/go/lib/serrors" "github.com/scionproto/scion/go/lib/snet" "github.com/scionproto/scion/go/lib/sock/reliable/reconnect" @@ -40,8 +39,8 @@ var ( localNoPortAddr = MustParseSnet("1-ff00:0:1,[192.168.0.1]:0") localAddr = MustParseSnet("1-ff00:0:1,[192.168.0.1]:80") otherLocalAddr = MustParseSnet("1-ff00:0:1,[192.168.0.1]:10080") - bindAddr = MustBuildOverlay("[192.168.0.2]:80") - otherBindAddr = MustBuildOverlay("[192.168.0.2]:10080") + bindAddr = &net.UDPAddr{IP: net.IP{192, 168, 0, 2}, Port: 80} + otherBindAddr = &net.UDPAddr{IP: net.IP{192, 168, 0, 2}, Port: 10080} remoteAddr = MustParseSnet("2-ff00:0:2,[172.16.0.1]:80") svc = addr.SvcNone timeout = time.Duration(0) @@ -63,14 +62,6 @@ func MustParseSnet(str string) *snet.Addr { return address } -func MustBuildOverlay(str string) *overlay.OverlayAddr { - udpAddr, err := net.ResolveUDPAddr("udp4", str) - if err != nil { - panic(fmt.Sprintf("bad overlay address %v, err=%v", str, err)) - } - return overlay.NewOverlayAddr(udpAddr.IP, uint16(udpAddr.Port)) -} - // tickerMultiplier computes durations relative to the default reconnect // ticking interval. This is needed for some timing tests that need sleep // values to stay fairly close to the ticking interval. diff --git a/go/lib/sock/reliable/reconnect/network.go b/go/lib/sock/reliable/reconnect/network.go index 824469e362..29a93186a5 100644 --- a/go/lib/sock/reliable/reconnect/network.go +++ b/go/lib/sock/reliable/reconnect/network.go @@ -21,7 +21,6 @@ import ( "golang.org/x/xerrors" "github.com/scionproto/scion/go/lib/addr" - "github.com/scionproto/scion/go/lib/overlay" "github.com/scionproto/scion/go/lib/sock/reliable" "github.com/scionproto/scion/go/lib/sock/reliable/reconnect/internal/metrics" ) @@ -45,13 +44,13 @@ func NewDispatcherService(dispatcher reliable.DispatcherService) *DispatcherServ } func (pn *DispatcherService) Register(ia addr.IA, public *addr.AppAddr, - bind *overlay.OverlayAddr, svc addr.HostSVC) (net.PacketConn, uint16, error) { + bind *net.UDPAddr, svc addr.HostSVC) (net.PacketConn, uint16, error) { return pn.RegisterTimeout(ia, public, bind, svc, 0) } func (pn *DispatcherService) RegisterTimeout(ia addr.IA, public *addr.AppAddr, - bind *overlay.OverlayAddr, svc addr.HostSVC, + bind *net.UDPAddr, svc addr.HostSVC, timeout time.Duration) (net.PacketConn, uint16, error) { // Perform initial connection to allocate port. We use a reconnecter here @@ -72,7 +71,7 @@ func (pn *DispatcherService) RegisterTimeout(ia addr.IA, public *addr.AppAddr, } func (pn *DispatcherService) newReconnecterFromListenArgs(ia addr.IA, - public *addr.AppAddr, bind *overlay.OverlayAddr, + public *addr.AppAddr, bind *net.UDPAddr, svc addr.HostSVC, timeout time.Duration) *TickingReconnecter { // f represents individual connection attempts diff --git a/go/lib/sock/reliable/reliable.go b/go/lib/sock/reliable/reliable.go index 235b5d26f8..188abae50a 100644 --- a/go/lib/sock/reliable/reliable.go +++ b/go/lib/sock/reliable/reliable.go @@ -69,7 +69,6 @@ import ( "github.com/scionproto/scion/go/lib/addr" "github.com/scionproto/scion/go/lib/common" - "github.com/scionproto/scion/go/lib/overlay" "github.com/scionproto/scion/go/lib/prom" "github.com/scionproto/scion/go/lib/serrors" "github.com/scionproto/scion/go/lib/sock/reliable/internal/metrics" @@ -89,9 +88,9 @@ const ( // DispatcherService controls how SCION applications open sockets in the SCION world. type DispatcherService interface { - Register(ia addr.IA, public *addr.AppAddr, bind *overlay.OverlayAddr, + Register(ia addr.IA, public *addr.AppAddr, bind *net.UDPAddr, svc addr.HostSVC) (net.PacketConn, uint16, error) - RegisterTimeout(ia addr.IA, public *addr.AppAddr, bind *overlay.OverlayAddr, + RegisterTimeout(ia addr.IA, public *addr.AppAddr, bind *net.UDPAddr, svc addr.HostSVC, timeout time.Duration) (net.PacketConn, uint16, error) } @@ -109,14 +108,14 @@ type dispatcherService struct { Address string } -func (d *dispatcherService) Register(ia addr.IA, public *addr.AppAddr, bind *overlay.OverlayAddr, +func (d *dispatcherService) Register(ia addr.IA, public *addr.AppAddr, bind *net.UDPAddr, svc addr.HostSVC) (net.PacketConn, uint16, error) { return Register(d.Address, ia, public, bind, svc) } func (d *dispatcherService) RegisterTimeout(ia addr.IA, public *addr.AppAddr, - bind *overlay.OverlayAddr, svc addr.HostSVC, + bind *net.UDPAddr, svc addr.HostSVC, timeout time.Duration) (net.PacketConn, uint16, error) { return RegisterTimeout(d.Address, ia, public, bind, svc, timeout) @@ -178,7 +177,7 @@ func dialTimeout(address string, timeout time.Duration) (*Conn, error) { // Register connects to a SCION Dispatcher's UNIX socket. // Future messages for address public or bind in AS ia which arrive at the dispatcher can be // read by calling Read on the returned Conn structure. -func Register(dispatcher string, ia addr.IA, public *addr.AppAddr, bind *overlay.OverlayAddr, +func Register(dispatcher string, ia addr.IA, public *addr.AppAddr, bind *net.UDPAddr, svc addr.HostSVC) (*Conn, uint16, error) { return RegisterTimeout(dispatcher, ia, public, bind, svc, time.Duration(0)) @@ -190,7 +189,7 @@ func Register(dispatcher string, ia addr.IA, public *addr.AppAddr, bind *overlay // // To check for timeout errors, call serrors.IsTimeout on the error. func RegisterTimeout(dispatcher string, ia addr.IA, public *addr.AppAddr, - bind *overlay.OverlayAddr, svc addr.HostSVC, timeout time.Duration) (*Conn, uint16, error) { + bind *net.UDPAddr, svc addr.HostSVC, timeout time.Duration) (*Conn, uint16, error) { conn, port, err := registerTimeout(dispatcher, ia, public, bind, svc, timeout) labels := metrics.RegisterLabels{Result: labelResult(err), SVC: svc.BaseString()} @@ -199,21 +198,16 @@ func RegisterTimeout(dispatcher string, ia addr.IA, public *addr.AppAddr, } func registerTimeout(dispatcher string, ia addr.IA, public *addr.AppAddr, - bind *overlay.OverlayAddr, svc addr.HostSVC, timeout time.Duration) (*Conn, uint16, error) { + bind *net.UDPAddr, svc addr.HostSVC, timeout time.Duration) (*Conn, uint16, error) { publicUDP, err := createUDPAddrFromAppAddr(public) if err != nil { return nil, 0, err } - - var bindUDP *net.UDPAddr - if bind != nil { - bindUDP = bind.ToUDPAddr() - } reg := &Registration{ IA: ia, PublicAddress: publicUDP, - BindAddress: bindUDP, + BindAddress: bind, SVCAddress: svc, } @@ -280,9 +274,12 @@ func (conn *Conn) readFrom(buf []byte) (int, net.Addr, error) { } var p OverlayPacket p.DecodeFromBytes(conn.readBuffer[:n]) - var overlayAddr *overlay.OverlayAddr + var overlayAddr *net.UDPAddr if p.Address != nil { - overlayAddr = overlay.NewOverlayAddr(p.Address.IP, uint16(p.Address.Port)) + overlayAddr = &net.UDPAddr{ + IP: append(p.Address.IP[:0:0], p.Address.IP...), + Port: p.Address.Port, + } } if len(buf) < len(p.Payload) { return 0, nil, serrors.New("buffer too small") @@ -305,17 +302,16 @@ func (conn *Conn) writeTo(buf []byte, dst net.Addr) (int, error) { conn.writeMutex.Lock() defer conn.writeMutex.Unlock() - var publicAddress *net.UDPAddr + var udpAddr *net.UDPAddr if dst != nil { - overlayAddr := dst.(*overlay.OverlayAddr) - if overlayAddr != nil { - publicAddress = overlayAddr.ToUDPAddr() + var ok bool + udpAddr, ok = dst.(*net.UDPAddr) + if !ok { + return 0, serrors.New("unsupported address type, must be UDP", + "address", fmt.Sprintf("%#v", dst)) } } - p := &OverlayPacket{ - Address: publicAddress, - Payload: buf, - } + p := &OverlayPacket{Address: udpAddr, Payload: buf} n, err := p.SerializeTo(conn.writeBuffer) if err != nil { return 0, err diff --git a/go/lib/svc/BUILD.bazel b/go/lib/svc/BUILD.bazel index 4b4f5aafb8..4d12c3c98e 100644 --- a/go/lib/svc/BUILD.bazel +++ b/go/lib/svc/BUILD.bazel @@ -13,7 +13,6 @@ go_library( "//go/lib/addr:go_default_library", "//go/lib/common:go_default_library", "//go/lib/l4:go_default_library", - "//go/lib/overlay:go_default_library", "//go/lib/snet:go_default_library", "//go/lib/spath:go_default_library", "//go/lib/svc/internal/ctxconn:go_default_library", @@ -35,7 +34,6 @@ go_test( "//go/lib/common:go_default_library", "//go/lib/ctrl:go_default_library", "//go/lib/l4:go_default_library", - "//go/lib/overlay:go_default_library", "//go/lib/serrors:go_default_library", "//go/lib/snet:go_default_library", "//go/lib/snet/mock_snet:go_default_library", diff --git a/go/lib/svc/mock_svc/BUILD.bazel b/go/lib/svc/mock_svc/BUILD.bazel index 5de7bf4a5c..7dec142526 100644 --- a/go/lib/svc/mock_svc/BUILD.bazel +++ b/go/lib/svc/mock_svc/BUILD.bazel @@ -6,7 +6,6 @@ go_library( importpath = "github.com/scionproto/scion/go/lib/svc/mock_svc", visibility = ["//visibility:public"], deps = [ - "//go/lib/overlay:go_default_library", "//go/lib/snet:go_default_library", "//go/lib/svc:go_default_library", "@com_github_golang_mock//gomock:go_default_library", diff --git a/go/lib/svc/mock_svc/svc.go b/go/lib/svc/mock_svc/svc.go index 0da9c014f9..c89679c267 100644 --- a/go/lib/svc/mock_svc/svc.go +++ b/go/lib/svc/mock_svc/svc.go @@ -7,9 +7,9 @@ package mock_svc import ( context "context" gomock "github.com/golang/mock/gomock" - overlay "github.com/scionproto/scion/go/lib/overlay" snet "github.com/scionproto/scion/go/lib/snet" svc "github.com/scionproto/scion/go/lib/svc" + net "net" reflect "reflect" ) @@ -75,7 +75,7 @@ func (m *MockRoundTripper) EXPECT() *MockRoundTripperMockRecorder { } // RoundTrip mocks base method -func (m *MockRoundTripper) RoundTrip(arg0 context.Context, arg1 snet.PacketConn, arg2 *snet.SCIONPacket, arg3 *overlay.OverlayAddr) (*svc.Reply, error) { +func (m *MockRoundTripper) RoundTrip(arg0 context.Context, arg1 snet.PacketConn, arg2 *snet.SCIONPacket, arg3 *net.UDPAddr) (*svc.Reply, error) { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "RoundTrip", arg0, arg1, arg2, arg3) ret0, _ := ret[0].(*svc.Reply) diff --git a/go/lib/svc/resolver.go b/go/lib/svc/resolver.go index 0e0fb99a1d..5083c0d5a4 100644 --- a/go/lib/svc/resolver.go +++ b/go/lib/svc/resolver.go @@ -17,6 +17,7 @@ package svc import ( "bytes" "context" + "net" "time" "github.com/opentracing/opentracing-go" @@ -24,7 +25,6 @@ import ( "github.com/scionproto/scion/go/lib/addr" "github.com/scionproto/scion/go/lib/common" "github.com/scionproto/scion/go/lib/l4" - "github.com/scionproto/scion/go/lib/overlay" "github.com/scionproto/scion/go/lib/snet" "github.com/scionproto/scion/go/lib/spath" "github.com/scionproto/scion/go/lib/svc/internal/ctxconn" @@ -104,7 +104,7 @@ func (r *Resolver) getRoundTripper() RoundTripper { type RoundTripper interface { // RoundTrip performs the round trip interaction. RoundTrip(ctx context.Context, c snet.PacketConn, request *snet.SCIONPacket, - ov *overlay.OverlayAddr) (*Reply, error) + ov *net.UDPAddr) (*Reply, error) } // DefaultRoundTripper returns a basic implementation of the RoundTripper @@ -118,7 +118,7 @@ var _ RoundTripper = (*roundTripper)(nil) type roundTripper struct{} func (roundTripper) RoundTrip(ctx context.Context, c snet.PacketConn, pkt *snet.SCIONPacket, - ov *overlay.OverlayAddr) (*Reply, error) { + ov *net.UDPAddr) (*Reply, error) { cancelF := ctxconn.CloseConnOnDone(ctx, c) defer cancelF() @@ -135,7 +135,7 @@ func (roundTripper) RoundTrip(ctx context.Context, c snet.PacketConn, pkt *snet. } var replyPacket snet.SCIONPacket - var replyOv overlay.OverlayAddr + var replyOv net.UDPAddr if err := c.ReadFrom(&replyPacket, &replyOv); err != nil { return nil, common.NewBasicError(errRead, err) } @@ -166,7 +166,7 @@ func (roundTripper) RoundTrip(ctx context.Context, c snet.PacketConn, pkt *snet. type path struct { spath *spath.Path - overlay *overlay.OverlayAddr + overlay *net.UDPAddr destination addr.IA } @@ -174,7 +174,7 @@ func (p *path) Fingerprint() string { return "" } -func (p *path) OverlayNextHop() *overlay.OverlayAddr { +func (p *path) OverlayNextHop() *net.UDPAddr { return p.overlay } @@ -201,7 +201,7 @@ func (p *path) Expiry() time.Time { func (p *path) Copy() snet.Path { return &path{ spath: p.spath.Copy(), - overlay: p.overlay.Copy(), + overlay: snet.CopyUDPAddr(p.overlay), destination: p.destination, } } diff --git a/go/lib/svc/resolver_test.go b/go/lib/svc/resolver_test.go index a0009f8290..4697625282 100644 --- a/go/lib/svc/resolver_test.go +++ b/go/lib/svc/resolver_test.go @@ -28,7 +28,6 @@ import ( "github.com/scionproto/scion/go/lib/addr" "github.com/scionproto/scion/go/lib/common" "github.com/scionproto/scion/go/lib/ctrl" - "github.com/scionproto/scion/go/lib/overlay" "github.com/scionproto/scion/go/lib/snet" "github.com/scionproto/scion/go/lib/snet/mock_snet" "github.com/scionproto/scion/go/lib/svc" @@ -93,14 +92,14 @@ func TestRoundTripper(t *testing.T) { testCases := []struct { Description string InputPacket *snet.SCIONPacket - InputOverlay *overlay.OverlayAddr + InputOverlay *net.UDPAddr ExpectedError bool ExpectedReply *svc.Reply ConnSetup func(*mock_snet.MockPacketConn) }{ { Description: "nil packet returns error", - InputOverlay: &overlay.OverlayAddr{}, + InputOverlay: &net.UDPAddr{}, ExpectedError: true, }, { @@ -111,7 +110,7 @@ func TestRoundTripper(t *testing.T) { { Description: "if write fails, return error", InputPacket: &snet.SCIONPacket{}, - InputOverlay: &overlay.OverlayAddr{}, + InputOverlay: &net.UDPAddr{}, ExpectedError: true, ConnSetup: func(c *mock_snet.MockPacketConn) { c.EXPECT().WriteTo(gomock.Any(), gomock.Any()).Return(errors.New("write err")) @@ -120,7 +119,7 @@ func TestRoundTripper(t *testing.T) { { Description: "if read fails, return error", InputPacket: &snet.SCIONPacket{}, - InputOverlay: &overlay.OverlayAddr{}, + InputOverlay: &net.UDPAddr{}, ExpectedError: true, ConnSetup: func(c *mock_snet.MockPacketConn) { c.EXPECT().WriteTo(gomock.Any(), gomock.Any()).Return(nil) @@ -130,12 +129,12 @@ func TestRoundTripper(t *testing.T) { { Description: "if bad payload type, return error", InputPacket: &snet.SCIONPacket{}, - InputOverlay: &overlay.OverlayAddr{}, + InputOverlay: &net.UDPAddr{}, ExpectedError: true, ConnSetup: func(c *mock_snet.MockPacketConn) { c.EXPECT().WriteTo(gomock.Any(), gomock.Any()).Return(nil) c.EXPECT().ReadFrom(gomock.Any(), gomock.Any()).DoAndReturn( - func(pkt *snet.SCIONPacket, _ *overlay.OverlayAddr) error { + func(pkt *snet.SCIONPacket, _ *net.UDPAddr) error { pkt.Payload = &ctrl.SignedPld{} return nil }, @@ -145,12 +144,12 @@ func TestRoundTripper(t *testing.T) { { Description: "if reply cannot be parsed, return error", InputPacket: &snet.SCIONPacket{}, - InputOverlay: &overlay.OverlayAddr{}, + InputOverlay: &net.UDPAddr{}, ExpectedError: true, ConnSetup: func(c *mock_snet.MockPacketConn) { c.EXPECT().WriteTo(gomock.Any(), gomock.Any()).Return(nil) c.EXPECT().ReadFrom(gomock.Any(), gomock.Any()).DoAndReturn( - func(pkt *snet.SCIONPacket, _ *overlay.OverlayAddr) error { + func(pkt *snet.SCIONPacket, _ *net.UDPAddr) error { pkt.Payload = common.RawBytes{42} return nil }, @@ -160,11 +159,11 @@ func TestRoundTripper(t *testing.T) { { Description: "successful operation", InputPacket: &snet.SCIONPacket{}, - InputOverlay: &overlay.OverlayAddr{}, + InputOverlay: &net.UDPAddr{}, ConnSetup: func(c *mock_snet.MockPacketConn) { c.EXPECT().WriteTo(gomock.Any(), gomock.Any()).Return(nil) c.EXPECT().ReadFrom(gomock.Any(), gomock.Any()).DoAndReturn( - func(pkt *snet.SCIONPacket, _ *overlay.OverlayAddr) error { + func(pkt *snet.SCIONPacket, _ *net.UDPAddr) error { buf := &bytes.Buffer{} if err := testReply.SerializeTo(buf); err != nil { panic(err) diff --git a/go/lib/svc/svc.go b/go/lib/svc/svc.go index 3235f4dc5b..9f50303684 100644 --- a/go/lib/svc/svc.go +++ b/go/lib/svc/svc.go @@ -16,12 +16,12 @@ package svc import ( + "net" "time" "github.com/scionproto/scion/go/lib/addr" "github.com/scionproto/scion/go/lib/common" "github.com/scionproto/scion/go/lib/l4" - "github.com/scionproto/scion/go/lib/overlay" "github.com/scionproto/scion/go/lib/snet" "github.com/scionproto/scion/go/lib/spath" ) @@ -73,7 +73,7 @@ type ResolverPacketDispatcher struct { } func (d *ResolverPacketDispatcher) RegisterTimeout(ia addr.IA, public *addr.AppAddr, - bind *overlay.OverlayAddr, svc addr.HostSVC, + bind *net.UDPAddr, svc addr.HostSVC, timeout time.Duration) (snet.PacketConn, uint16, error) { c, port, err := d.dispService.RegisterTimeout(ia, public, bind, svc, timeout) @@ -102,7 +102,7 @@ type resolverPacketConn struct { handler RequestHandler } -func (c *resolverPacketConn) ReadFrom(pkt *snet.SCIONPacket, ov *overlay.OverlayAddr) error { +func (c *resolverPacketConn) ReadFrom(pkt *snet.SCIONPacket, ov *net.UDPAddr) error { for { if err := c.PacketConn.ReadFrom(pkt, ov); err != nil { return err @@ -157,7 +157,7 @@ type Request struct { // Conn is the connection to send the reply on. Conn must not be nil. Conn snet.PacketConn Packet *snet.SCIONPacket - Overlay *overlay.OverlayAddr + Overlay *net.UDPAddr } var _ RequestHandler = (*BaseHandler)(nil) diff --git a/go/lib/svc/svc_test.go b/go/lib/svc/svc_test.go index ad0b1cf97a..0c6b2ba0a6 100644 --- a/go/lib/svc/svc_test.go +++ b/go/lib/svc/svc_test.go @@ -25,7 +25,6 @@ import ( "github.com/scionproto/scion/go/lib/addr" "github.com/scionproto/scion/go/lib/common" "github.com/scionproto/scion/go/lib/l4" - "github.com/scionproto/scion/go/lib/overlay" "github.com/scionproto/scion/go/lib/serrors" "github.com/scionproto/scion/go/lib/snet" "github.com/scionproto/scion/go/lib/snet/mock_snet" @@ -52,7 +51,7 @@ func TestSVCResolutionServer(t *testing.T) { dispatcherService := svc.NewResolverPacketDispatcher(mockPacketDispatcherService, mockReqHandler) conn, port, err := dispatcherService.RegisterTimeout(addr.IA{}, &addr.AppAddr{}, - &overlay.OverlayAddr{}, addr.SvcPS, 0) + &net.UDPAddr{}, addr.SvcPS, 0) SoMsg("conn", conn, ShouldBeNil) SoMsg("port", port, ShouldEqual, 0) SoMsg("err", err, ShouldNotBeNil) @@ -64,16 +63,16 @@ func TestSVCResolutionServer(t *testing.T) { dispatcherService := svc.NewResolverPacketDispatcher(mockPacketDispatcherService, mockReqHandler) conn, port, err := dispatcherService.RegisterTimeout(addr.IA{}, &addr.AppAddr{}, - &overlay.OverlayAddr{}, addr.SvcPS, 0) + &net.UDPAddr{}, addr.SvcPS, 0) SoMsg("conn", conn, ShouldNotBeNil) SoMsg("port", port, ShouldEqual, 1337) SoMsg("err", err, ShouldBeNil) var pkt snet.SCIONPacket - var ov overlay.OverlayAddr + var ov net.UDPAddr Convey("If handler fails, caller sees error", func() { mockPacketConn.EXPECT().ReadFrom(gomock.Any(), gomock.Any()).DoAndReturn( - func(pkt *snet.SCIONPacket, ov *overlay.OverlayAddr) error { + func(pkt *snet.SCIONPacket, ov *net.UDPAddr) error { pkt.Destination = snet.SCIONAddress{ Host: addr.SvcPS, } @@ -88,7 +87,7 @@ func TestSVCResolutionServer(t *testing.T) { }) Convey("If handler returns forward, caller sees data", func() { mockPacketConn.EXPECT().ReadFrom(gomock.Any(), gomock.Any()).DoAndReturn( - func(pkt *snet.SCIONPacket, ov *overlay.OverlayAddr) error { + func(pkt *snet.SCIONPacket, ov *net.UDPAddr) error { pkt.Destination = snet.SCIONAddress{ Host: addr.SvcPS, } @@ -102,7 +101,7 @@ func TestSVCResolutionServer(t *testing.T) { }) Convey("If handler succeeds", func() { mockPacketConn.EXPECT().ReadFrom(gomock.Any(), gomock.Any()).DoAndReturn( - func(pkt *snet.SCIONPacket, ov *overlay.OverlayAddr) error { + func(pkt *snet.SCIONPacket, ov *net.UDPAddr) error { pkt.Destination = snet.SCIONAddress{ Host: addr.SvcPS, } @@ -112,7 +111,7 @@ func TestSVCResolutionServer(t *testing.T) { mockReqHandler.EXPECT().Handle(gomock.Any()).Return(svc.Handled, nil).AnyTimes() Convey("return from conn with no error next internal read yields data", func() { mockPacketConn.EXPECT().ReadFrom(gomock.Any(), gomock.Any()).DoAndReturn( - func(pkt *snet.SCIONPacket, ov *overlay.OverlayAddr) error { + func(pkt *snet.SCIONPacket, ov *net.UDPAddr) error { pkt.Destination = snet.SCIONAddress{ Host: addr.HostIPv4(net.IP{192, 168, 0, 1}), } @@ -124,7 +123,7 @@ func TestSVCResolutionServer(t *testing.T) { }) Convey("return from socket with error if next internal read fails", func() { mockPacketConn.EXPECT().ReadFrom(gomock.Any(), gomock.Any()).DoAndReturn( - func(pkt *snet.SCIONPacket, ov *overlay.OverlayAddr) error { + func(pkt *snet.SCIONPacket, ov *net.UDPAddr) error { return serrors.New("forced exit") }, ) @@ -134,7 +133,7 @@ func TestSVCResolutionServer(t *testing.T) { }) Convey("Multicast SVC packets get delivered to caller", func() { mockPacketConn.EXPECT().ReadFrom(gomock.Any(), gomock.Any()).DoAndReturn( - func(pkt *snet.SCIONPacket, ov *overlay.OverlayAddr) error { + func(pkt *snet.SCIONPacket, ov *net.UDPAddr) error { pkt.Destination = snet.SCIONAddress{ Host: addr.SvcBS.Multicast(), } @@ -246,7 +245,7 @@ func TestDefaultHandler(t *testing.T) { conn := mock_snet.NewMockPacketConn(ctrl) packet := &snet.SCIONPacket{} - ov := overlay.NewOverlayAddr(net.IP{192, 168, 0, 1}, 0x29a) + ov := &net.UDPAddr{IP: net.IP{192, 168, 0, 1}, Port: 0x29a} conn.EXPECT().WriteTo(packet, ov).Times(1) sender := &svc.BaseHandler{} diff --git a/go/lib/topology/BUILD.bazel b/go/lib/topology/BUILD.bazel index 7e892565e6..cf8dff3738 100644 --- a/go/lib/topology/BUILD.bazel +++ b/go/lib/topology/BUILD.bazel @@ -16,8 +16,8 @@ go_library( deps = [ "//go/lib/addr:go_default_library", "//go/lib/common:go_default_library", - "//go/lib/overlay:go_default_library", "//go/lib/serrors:go_default_library", + "//go/lib/topology/overlay:go_default_library", "//go/proto:go_default_library", ], ) @@ -33,7 +33,7 @@ go_test( deps = [ "//go/lib/addr:go_default_library", "//go/lib/common:go_default_library", - "//go/lib/overlay:go_default_library", + "//go/lib/topology/overlay:go_default_library", "//go/lib/xtest:go_default_library", "//go/proto:go_default_library", "@com_github_smartystreets_goconvey//convey:go_default_library", diff --git a/go/lib/topology/addr.go b/go/lib/topology/addr.go index b0bc102b7d..fd4d411be6 100644 --- a/go/lib/topology/addr.go +++ b/go/lib/topology/addr.go @@ -16,11 +16,12 @@ package topology import ( "fmt" + "net" "strings" "github.com/scionproto/scion/go/lib/addr" "github.com/scionproto/scion/go/lib/common" - "github.com/scionproto/scion/go/lib/overlay" + "github.com/scionproto/scion/go/lib/topology/overlay" ) const ( @@ -122,15 +123,19 @@ func (t *TopoAddr) fromRaw(s RawAddrMap) error { } func (t *TopoAddr) PublicAddr(ot overlay.Type) *addr.AppAddr { - return t.getAddr(ot).PublicAddr() + return t.getAddr(overlay.Type(ot)).PublicAddr() } func (t *TopoAddr) BindAddr(ot overlay.Type) *addr.AppAddr { - return t.getAddr(ot).BindAddr() + return t.getAddr(overlay.Type(ot)).BindAddr() } -func (t *TopoAddr) OverlayAddr(ot overlay.Type) *overlay.OverlayAddr { - return t.getAddr(ot).OverlayAddr() +func (t *TopoAddr) OverlayAddrUDP(ot overlay.Type) *net.UDPAddr { + ovAddr := t.getAddr(overlay.Type(ot)).OverlayAddr() + if ovAddr == nil { + return nil + } + return ovAddr.ToUDPAddr() } func (t *TopoAddr) BindOrPublic(ot overlay.Type) *addr.AppAddr { diff --git a/go/lib/topology/addr_test.go b/go/lib/topology/addr_test.go index af0f4272f4..6a463c153e 100644 --- a/go/lib/topology/addr_test.go +++ b/go/lib/topology/addr_test.go @@ -22,7 +22,7 @@ import ( "github.com/stretchr/testify/assert" "github.com/scionproto/scion/go/lib/addr" - "github.com/scionproto/scion/go/lib/overlay" + "github.com/scionproto/scion/go/lib/topology/overlay" "github.com/scionproto/scion/go/lib/xtest" ) diff --git a/go/lib/topology/braddr.go b/go/lib/topology/braddr.go index 72a99eaca3..1479ade20f 100644 --- a/go/lib/topology/braddr.go +++ b/go/lib/topology/braddr.go @@ -16,11 +16,12 @@ package topology import ( "fmt" + "net" "strings" "github.com/scionproto/scion/go/lib/addr" "github.com/scionproto/scion/go/lib/common" - "github.com/scionproto/scion/go/lib/overlay" + "github.com/scionproto/scion/go/lib/topology/overlay" ) type TopoBRAddr struct { @@ -95,6 +96,16 @@ func (t *TopoBRAddr) PublicOverlay(ot overlay.Type) *overlay.OverlayAddr { return nil } +func (t *TopoBRAddr) PublicOverlayUDP(ot overlay.Type) *net.UDPAddr { + ov := t.PublicOverlay(ot) + if ov == nil { + return nil + } + // XXX(scrye): Return only a shallow copy here because some tests use the + // returned value to edit the topology in place. + return ov.ShallowUDPAddr() +} + func (t *TopoBRAddr) BindOverlay(ot overlay.Type) *overlay.OverlayAddr { if oba := t.getAddr(ot); oba != nil { return oba.BindOverlay @@ -102,6 +113,14 @@ func (t *TopoBRAddr) BindOverlay(ot overlay.Type) *overlay.OverlayAddr { return nil } +func (t *TopoBRAddr) BindOverlayUDP(ot overlay.Type) *net.UDPAddr { + ov := t.BindOverlay(ot) + if ov == nil { + return nil + } + return ov.ToUDPAddr() +} + func (t *TopoBRAddr) BindOrPublicOverlay(ot overlay.Type) *overlay.OverlayAddr { if oba := t.getAddr(ot); oba != nil { return oba.BindOrPublicOverlay() @@ -109,6 +128,14 @@ func (t *TopoBRAddr) BindOrPublicOverlay(ot overlay.Type) *overlay.OverlayAddr { return nil } +func (t *TopoBRAddr) BindOrPublicOverlayUDP(ot overlay.Type) *net.UDPAddr { + ov := t.BindOrPublicOverlay(ot) + if ov == nil { + return nil + } + return ov.ToUDPAddr() +} + func (t *TopoBRAddr) getAddr(ot overlay.Type) *OverBindAddr { if t == nil { return nil diff --git a/go/lib/overlay/BUILD.bazel b/go/lib/topology/overlay/BUILD.bazel similarity index 81% rename from go/lib/overlay/BUILD.bazel rename to go/lib/topology/overlay/BUILD.bazel index ceade32c5c..c8e2ccaa81 100644 --- a/go/lib/overlay/BUILD.bazel +++ b/go/lib/topology/overlay/BUILD.bazel @@ -6,7 +6,7 @@ go_library( "addr.go", "defs.go", ], - importpath = "github.com/scionproto/scion/go/lib/overlay", + importpath = "github.com/scionproto/scion/go/lib/topology/overlay", visibility = ["//visibility:public"], deps = [ "//go/lib/addr:go_default_library", diff --git a/go/lib/overlay/addr.go b/go/lib/topology/overlay/addr.go similarity index 75% rename from go/lib/overlay/addr.go rename to go/lib/topology/overlay/addr.go index f6799d0b85..240848eaba 100644 --- a/go/lib/overlay/addr.go +++ b/go/lib/topology/overlay/addr.go @@ -86,6 +86,20 @@ func (a *OverlayAddr) ToUDPAddr() *net.UDPAddr { return &net.UDPAddr{IP: copyIP(a.l3), Port: int(a.l4)} } +// ShallowUDPAddr returns a net.UDPAddr interpretation of the overlay L3 address field. The IP is a +// slice pointing to the same memory region as the overlay address, so it can be edited (note that +// since the port is an integer and always copied, the port of the overlay address cannot be +// edited). +// +// FIXME(scrye): This is used only for some unit tests which effect topology changes by editing an +// address in-place. This should never be used and should be removed. +func (a *OverlayAddr) ShallowUDPAddr() *net.UDPAddr { + return &net.UDPAddr{ + IP: a.l3, + Port: int(a.l4), + } +} + func copyIP(ip net.IP) net.IP { return append(ip[:0:0], ip...) } diff --git a/go/lib/overlay/defs.go b/go/lib/topology/overlay/defs.go similarity index 100% rename from go/lib/overlay/defs.go rename to go/lib/topology/overlay/defs.go diff --git a/go/lib/topology/raw.go b/go/lib/topology/raw.go index 9e850b5bdc..8f4f8758a2 100644 --- a/go/lib/topology/raw.go +++ b/go/lib/topology/raw.go @@ -23,7 +23,7 @@ import ( "github.com/scionproto/scion/go/lib/addr" "github.com/scionproto/scion/go/lib/common" - "github.com/scionproto/scion/go/lib/overlay" + "github.com/scionproto/scion/go/lib/topology/overlay" ) const CfgName = "topology.json" diff --git a/go/lib/topology/topology.go b/go/lib/topology/topology.go index 51fb615984..ea5c0081ef 100644 --- a/go/lib/topology/topology.go +++ b/go/lib/topology/topology.go @@ -23,11 +23,14 @@ import ( "github.com/scionproto/scion/go/lib/addr" "github.com/scionproto/scion/go/lib/common" - "github.com/scionproto/scion/go/lib/overlay" "github.com/scionproto/scion/go/lib/serrors" + "github.com/scionproto/scion/go/lib/topology/overlay" "github.com/scionproto/scion/go/proto" ) +// EndhostPort is the overlay port that the dispatcher binds to on non-routers. +const EndhostPort = overlay.EndhostPort + type IDAddrMap map[string]TopoAddr // GetById returns the TopoAddr for the given ID, or nil if there is none. diff --git a/go/lib/topology/topology_test.go b/go/lib/topology/topology_test.go index 2e526a268a..3d80941f08 100644 --- a/go/lib/topology/topology_test.go +++ b/go/lib/topology/topology_test.go @@ -27,7 +27,7 @@ import ( "github.com/scionproto/scion/go/lib/addr" "github.com/scionproto/scion/go/lib/common" - "github.com/scionproto/scion/go/lib/overlay" + "github.com/scionproto/scion/go/lib/topology/overlay" "github.com/scionproto/scion/go/proto" ) diff --git a/go/sig/egress/session/sessmon.go b/go/sig/egress/session/sessmon.go index e566a49eab..ed1d97d977 100644 --- a/go/sig/egress/session/sessmon.go +++ b/go/sig/egress/session/sessmon.go @@ -282,11 +282,7 @@ func (sm *sessMonitor) sendReq() { if err := raddr.Path.InitOffsets(); err != nil { sm.Error("sessMonitor: Error initializing path offsets", "err", err) } - nh, err := sm.smRemote.SessPath.PathEntry().HostInfo.Overlay() - if err != nil { - sm.Error("sessMonitor: Unsupported NextHop", "err", err) - } - raddr.NextHop = nh + raddr.NextHop = sm.smRemote.SessPath.PathEntry().HostInfo.Overlay() // XXX(kormat): if this blocks, both the sessMon and egress worker // goroutines will block. Can't just use SetWriteDeadline, as both // goroutines write to it. diff --git a/go/sig/egress/worker/worker.go b/go/sig/egress/worker/worker.go index 59cb00eb70..86ea618377 100644 --- a/go/sig/egress/worker/worker.go +++ b/go/sig/egress/worker/worker.go @@ -204,11 +204,7 @@ func (w *worker) write(f *frame) error { if err := snetAddr.Path.InitOffsets(); err != nil { return common.NewBasicError("Error initializing path offsets", err) } - nh, err := w.currPathEntry.HostInfo.Overlay() - if err != nil { - return common.NewBasicError("Egress unsupported NextHop", err) - } - snetAddr.NextHop = nh + snetAddr.NextHop = w.currPathEntry.HostInfo.Overlay() } f.writeHdr(w.sess.ID(), w.epoch, seq) diff --git a/go/sig/internal/base/pollhdlr.go b/go/sig/internal/base/pollhdlr.go index 3c8ee9290b..1f0d166ca4 100644 --- a/go/sig/internal/base/pollhdlr.go +++ b/go/sig/internal/base/pollhdlr.go @@ -62,7 +62,7 @@ func PollReqHdlr() { IA: rpld.Addr.IA, Host: addr.AppAddrFromUDP(req.Addr.Ctrl.UDP()), Path: rpld.Addr.Path, - NextHop: rpld.Addr.NextHop.Copy(), + NextHop: snet.CopyUDPAddr(rpld.Addr.NextHop), } _, err = sigcmn.CtrlConn.WriteToSCION(raw, sigCtrlAddr) if err != nil { diff --git a/go/tools/scmp/BUILD.bazel b/go/tools/scmp/BUILD.bazel index eab6e977ff..d7bd07dc1b 100644 --- a/go/tools/scmp/BUILD.bazel +++ b/go/tools/scmp/BUILD.bazel @@ -8,7 +8,6 @@ go_library( visibility = ["//visibility:private"], deps = [ "//go/lib/addr:go_default_library", - "//go/lib/overlay:go_default_library", "//go/lib/sciond:go_default_library", "//go/lib/sock/reliable:go_default_library", "//go/lib/spath:go_default_library", diff --git a/go/tools/scmp/cmn/BUILD.bazel b/go/tools/scmp/cmn/BUILD.bazel index 4854a19ebd..9eca8d0dc8 100644 --- a/go/tools/scmp/cmn/BUILD.bazel +++ b/go/tools/scmp/cmn/BUILD.bazel @@ -10,7 +10,6 @@ go_library( "//go/lib/ctrl/path_mgmt:go_default_library", "//go/lib/env:go_default_library", "//go/lib/log:go_default_library", - "//go/lib/overlay:go_default_library", "//go/lib/sciond:go_default_library", "//go/lib/scmp:go_default_library", "//go/lib/scrypto:go_default_library", @@ -18,5 +17,6 @@ go_library( "//go/lib/snet:go_default_library", "//go/lib/sock/reliable:go_default_library", "//go/lib/spkt:go_default_library", + "//go/lib/topology:go_default_library", ], ) diff --git a/go/tools/scmp/cmn/common.go b/go/tools/scmp/cmn/common.go index b9a3c49684..e7da8c345c 100644 --- a/go/tools/scmp/cmn/common.go +++ b/go/tools/scmp/cmn/common.go @@ -29,7 +29,6 @@ import ( "github.com/scionproto/scion/go/lib/ctrl/path_mgmt" "github.com/scionproto/scion/go/lib/env" "github.com/scionproto/scion/go/lib/log" - "github.com/scionproto/scion/go/lib/overlay" "github.com/scionproto/scion/go/lib/sciond" "github.com/scionproto/scion/go/lib/scmp" _ "github.com/scionproto/scion/go/lib/scrypto" // Make sure math/rand is seeded @@ -37,6 +36,7 @@ import ( "github.com/scionproto/scion/go/lib/snet" "github.com/scionproto/scion/go/lib/sock/reliable" "github.com/scionproto/scion/go/lib/spkt" + "github.com/scionproto/scion/go/lib/topology" ) const ( @@ -166,9 +166,12 @@ func NewSCMPPkt(t scmp.Type, info scmp.Info, ext common.Extension) *spkt.ScnPkt } func NextHopAddr() net.Addr { - var nhAddr *overlay.OverlayAddr + var nhAddr *net.UDPAddr if Remote.NextHop == nil { - nhAddr = overlay.NewOverlayAddr(Remote.Host.L3.IP(), overlay.EndhostPort) + nhAddr = &net.UDPAddr{ + IP: Remote.Host.L3.IP(), + Port: topology.EndhostPort, + } } else { nhAddr = Remote.NextHop } diff --git a/go/tools/scmp/main.go b/go/tools/scmp/main.go index a9014bfc4f..757c845db4 100644 --- a/go/tools/scmp/main.go +++ b/go/tools/scmp/main.go @@ -20,12 +20,12 @@ import ( "context" "flag" "fmt" + "net" "os" "strconv" "time" "github.com/scionproto/scion/go/lib/addr" - "github.com/scionproto/scion/go/lib/overlay" "github.com/scionproto/scion/go/lib/sciond" "github.com/scionproto/scion/go/lib/sock/reliable" "github.com/scionproto/scion/go/lib/spath" @@ -68,9 +68,12 @@ func main() { cmn.Fatal("Failed to connect to SCIOND: %v\n", err) } // Connect to the dispatcher - var overlayBindAddr *overlay.OverlayAddr + var overlayBindAddr *net.UDPAddr if cmn.Bind.Host != nil { - overlayBindAddr = overlay.NewOverlayAddr(cmn.Bind.Host.L3.IP(), cmn.Bind.Host.L4) + overlayBindAddr = &net.UDPAddr{ + IP: cmn.Bind.Host.L3.IP(), + Port: int(cmn.Bind.Host.L4), + } } cmn.Conn, _, err = reliable.Register(*dispatcher, cmn.Local.IA, cmn.Local.Host, overlayBindAddr, addr.SvcNone) @@ -153,7 +156,7 @@ func setPathAndMtu() uint16 { cmn.PathEntry = &path cmn.Remote.Path = spath.New(cmn.PathEntry.Path.FwdPath) cmn.Remote.Path.InitOffsets() - cmn.Remote.NextHop, _ = cmn.PathEntry.HostInfo.Overlay() + cmn.Remote.NextHop = cmn.PathEntry.HostInfo.Overlay() return cmn.PathEntry.Path.Mtu }