Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove AppAddr from SIG code #3578

Merged
merged 2 commits into from
Jan 8, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions go/sig/egress/session/sessmon.go
Original file line number Diff line number Diff line change
Expand Up @@ -277,13 +277,14 @@ func (sm *sessMonitor) sendReq() {
sm.Error("sessMonitor: Error packing signed Ctrl payload", "err", err)
return
}
raddr := sm.smRemote.Sig.CtrlSnetAddr()
raddr.Path = sm.smRemote.SessPath.Path().Path()
raddr.NextHop = sm.smRemote.SessPath.Path().OverlayNextHop()
raddr := sm.smRemote.Sig.CtrlSnetAddr(
sm.smRemote.SessPath.Path().Path(),
sm.smRemote.SessPath.Path().OverlayNextHop(),
)
// 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.
_, err = sm.sess.conn.WriteToSCION(raw, raddr)
_, err = sm.sess.conn.WriteTo(raw, raddr)
if err != nil {
sm.Error("sessMonitor: Error sending signed Ctrl payload", "err", err)
}
Expand Down
1 change: 1 addition & 0 deletions go/sig/egress/siginfo/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,6 @@ go_library(
deps = [
"//go/lib/addr:go_default_library",
"//go/lib/snet:go_default_library",
"//go/lib/spath:go_default_library",
],
)
36 changes: 32 additions & 4 deletions go/sig/egress/siginfo/sig.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,11 @@ package siginfo

import (
"fmt"
"net"

"github.com/scionproto/scion/go/lib/addr"
"github.com/scionproto/scion/go/lib/snet"
"github.com/scionproto/scion/go/lib/spath"
)

type Sig struct {
Expand All @@ -29,12 +31,38 @@ type Sig struct {
EncapL4Port int
}

func (s *Sig) CtrlSnetAddr() *snet.Addr {
return &snet.Addr{IA: s.IA, Host: &addr.AppAddr{L3: s.Host, L4: uint16(s.CtrlL4Port)}}
func (s *Sig) CtrlSnetAddr(path *spath.Path, nextHop *net.UDPAddr) net.Addr {
switch s.Host.(type) {
case addr.HostSVC:
return snet.NewSVCAddr(
s.IA,
path,
nextHop,
addr.SvcSIG,
)
default:
return snet.NewUDPAddr(
s.IA,
path,
nextHop,
&net.UDPAddr{
IP: s.Host.IP(),
Port: s.CtrlL4Port,
},
)
}
}

func (s *Sig) EncapSnetAddr() *snet.Addr {
return &snet.Addr{IA: s.IA, Host: &addr.AppAddr{L3: s.Host, L4: uint16(s.EncapL4Port)}}
func (s *Sig) EncapSnetAddr() *snet.UDPAddr {
return snet.NewUDPAddr(
s.IA,
nil,
nil,
&net.UDPAddr{
IP: s.Host.IP(),
Port: s.EncapL4Port,
},
)
}

func (s *Sig) Equal(x *Sig) bool {
Expand Down
5 changes: 1 addition & 4 deletions go/sig/egress/worker/mock_worker/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,5 @@ go_library(
srcs = ["worker.go"],
importpath = "github.com/scionproto/scion/go/sig/egress/worker/mock_worker",
visibility = ["//visibility:public"],
deps = [
"//go/lib/snet:go_default_library",
"@com_github_golang_mock//gomock:go_default_library",
],
deps = ["@com_github_golang_mock//gomock:go_default_library"],
)
14 changes: 7 additions & 7 deletions go/sig/egress/worker/mock_worker/worker.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 4 additions & 3 deletions go/sig/egress/worker/worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package worker

import (
"net"
"time"

"github.com/scionproto/scion/go/lib/common"
Expand Down Expand Up @@ -56,7 +57,7 @@ const (
)

type SCIONWriter interface {
WriteToSCION(b []byte, address *snet.Addr) (int, error)
WriteTo(b []byte, address net.Addr) (int, error)
}

type worker struct {
Expand Down Expand Up @@ -187,7 +188,7 @@ func (w *worker) write(f *frame) error {
w.seq = 0
}

var snetAddr *snet.Addr
var snetAddr *snet.UDPAddr
if !w.ignoreAddress {
if w.currPathEntry == nil {
// FIXME(kormat): add some metrics to track this.
Expand All @@ -203,7 +204,7 @@ func (w *worker) write(f *frame) error {
}

f.writeHdr(w.sess.ID(), w.epoch, seq)
bytesWritten, err := w.writer.WriteToSCION(f.raw(), snetAddr)
bytesWritten, err := w.writer.WriteTo(f.raw(), snetAddr)
if err != nil {
return common.NewBasicError("Egress write error", err)
}
Expand Down
6 changes: 3 additions & 3 deletions go/sig/egress/worker/worker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,12 +83,12 @@ func NewWorkerTester(t *testing.T) *WorkerTester {
}

func (wt *WorkerTester) ExpectFrame(frame []byte) {
wt.writer.EXPECT().WriteToSCION(MatchFrame(frame), gomock.Any()).Return(len(frame), nil)
wt.writer.EXPECT().WriteTo(MatchFrame(frame), gomock.Any()).Return(len(frame), nil)
}

func (wt *WorkerTester) ExpectLastFrame(frame []byte) {
wt.writer.EXPECT().WriteToSCION(MatchFrame(frame), gomock.Any()).DoAndReturn(
func(frame []byte, address *snet.Addr) (int, error) {
wt.writer.EXPECT().WriteTo(MatchFrame(frame), gomock.Any()).DoAndReturn(
func(frame []byte, address *snet.UDPAddr) (int, error) {
wt.ring.Close()
return len(frame), nil
})
Expand Down
15 changes: 7 additions & 8 deletions go/sig/internal/base/pollhdlr.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
package base

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/infra"
Expand Down Expand Up @@ -58,13 +57,13 @@ func PollReqHdlr() {
log.Error("PollReqHdlr: Error packing signed Ctrl payload", "err", err)
break
}
sigCtrlAddr := &snet.Addr{
IA: rpld.Addr.IA,
Host: addr.AppAddrFromUDP(req.Addr.Ctrl.UDP()),
Path: rpld.Addr.Path,
NextHop: snet.CopyUDPAddr(rpld.Addr.NextHop),
}
_, err = sigcmn.CtrlConn.WriteToSCION(raw, sigCtrlAddr)
sigCtrlAddr := snet.NewUDPAddr(
rpld.Addr.IA,
rpld.Addr.Path,
snet.CopyUDPAddr(rpld.Addr.NextHop),
req.Addr.Ctrl.UDP(),
)
_, err = sigcmn.CtrlConn.WriteTo(raw, sigCtrlAddr)
if err != nil {
log.Error("PollReqHdlr: Error sending Ctrl payload", "dest", rpld.Addr, "err", err)
}
Expand Down
5 changes: 2 additions & 3 deletions go/sig/internal/ingress/dispatcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ const (
// source ISD-AS -> source host Addr -> Sess Id and hands it off to the
// appropriate Worker, starting a new one if none currently exists.
type Dispatcher struct {
laddr *snet.Addr
laddr *snet.UDPAddr
workers map[string]*Worker
extConn snet.Conn
tunIO io.ReadWriteCloser
Expand All @@ -61,8 +61,7 @@ func NewDispatcher(tio io.ReadWriteCloser) *Dispatcher {

func (d *Dispatcher) Run() error {
var err error
d.extConn, err = sigcmn.Network.Listen(context.Background(), "udp",
d.laddr.ToNetUDPAddr(), addr.SvcNone)
d.extConn, err = sigcmn.Network.Listen(context.Background(), "udp", d.laddr.Host, addr.SvcNone)
if err != nil {
return common.NewBasicError("Unable to initialize extConn", err)
}
Expand Down
4 changes: 2 additions & 2 deletions go/sig/internal/sigcmn/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,8 +125,8 @@ func initNetworkWithRealSCIOND(cfg sigconfig.SigConf,
return nil, nil, retErr
}

func EncapSnetAddr() *snet.Addr {
return &snet.Addr{IA: IA, Host: &addr.AppAddr{L3: Host, L4: uint16(encapPort)}}
func EncapSnetAddr() *snet.UDPAddr {
return snet.NewUDPAddr(IA, nil, nil, &net.UDPAddr{IP: Host.IP(), Port: int(encapPort)})
}

func ValidatePort(desc string, port int) error {
Expand Down