diff --git a/go/lib/ctrl/sig_mgmt/addr.go b/go/lib/ctrl/sig_mgmt/addr.go index 464f6caf41..ef212ffbc8 100644 --- a/go/lib/ctrl/sig_mgmt/addr.go +++ b/go/lib/ctrl/sig_mgmt/addr.go @@ -27,14 +27,14 @@ import ( var _ proto.Cerealizable = (*Addr)(nil) type Addr struct { - Ctrl *hostinfo.Host - EncapPort uint16 + Ctrl *hostinfo.Host + Data *hostinfo.Host } -func NewAddr(host addr.HostAddr, ctrlPort, encapPort uint16) *Addr { +func NewAddr(ctrl addr.HostAddr, ctrlPort uint16, data addr.HostAddr, dataPort uint16) *Addr { return &Addr{ - Ctrl: hostinfo.FromHostAddr(host, ctrlPort), - EncapPort: encapPort, + Ctrl: hostinfo.FromHostAddr(ctrl, ctrlPort), + Data: hostinfo.FromHostAddr(data, dataPort), } } @@ -52,6 +52,6 @@ func (a *Addr) Write(b common.RawBytes) (int, error) { } func (a *Addr) String() string { - return fmt.Sprintf("Host: %s CtrlPort: %d EncapPort: %d", - a.Ctrl.Host(), a.Ctrl.Port, a.EncapPort) + return fmt.Sprintf("Ctrl: %s CtrlPort: %d Data: %s DataPort: %d", + a.Ctrl.Host(), a.Ctrl.Port, a.Data.Host(), a.Data.Port) } diff --git a/go/proto/sig.capnp.go b/go/proto/sig.capnp.go index 3f53f57636..7f57fdbac1 100644 --- a/go/proto/sig.capnp.go +++ b/go/proto/sig.capnp.go @@ -265,12 +265,12 @@ type SIGAddr struct{ capnp.Struct } const SIGAddr_TypeID = 0xddf1fce11d9b0028 func NewSIGAddr(s *capnp.Segment) (SIGAddr, error) { - st, err := capnp.NewStruct(s, capnp.ObjectSize{DataSize: 8, PointerCount: 1}) + st, err := capnp.NewStruct(s, capnp.ObjectSize{DataSize: 0, PointerCount: 2}) return SIGAddr{st}, err } func NewRootSIGAddr(s *capnp.Segment) (SIGAddr, error) { - st, err := capnp.NewRootStruct(s, capnp.ObjectSize{DataSize: 8, PointerCount: 1}) + st, err := capnp.NewRootStruct(s, capnp.ObjectSize{DataSize: 0, PointerCount: 2}) return SIGAddr{st}, err } @@ -309,12 +309,29 @@ func (s SIGAddr) NewCtrl() (HostInfo, error) { return ss, err } -func (s SIGAddr) EncapPort() uint16 { - return s.Struct.Uint16(0) +func (s SIGAddr) Data() (HostInfo, error) { + p, err := s.Struct.Ptr(1) + return HostInfo{Struct: p.Struct()}, err +} + +func (s SIGAddr) HasData() bool { + p, err := s.Struct.Ptr(1) + return p.IsValid() || err != nil } -func (s SIGAddr) SetEncapPort(v uint16) { - s.Struct.SetUint16(0, v) +func (s SIGAddr) SetData(v HostInfo) error { + return s.Struct.SetPtr(1, v.Struct.ToPtr()) +} + +// NewData sets the data field to a newly +// allocated HostInfo struct, preferring placement in s's segment. +func (s SIGAddr) NewData() (HostInfo, error) { + ss, err := NewHostInfo(s.Struct.Segment()) + if err != nil { + return HostInfo{}, err + } + err = s.Struct.SetPtr(1, ss.Struct.ToPtr()) + return ss, err } // SIGAddr_List is a list of SIGAddr. @@ -322,7 +339,7 @@ type SIGAddr_List struct{ capnp.List } // NewSIGAddr creates a new list of SIGAddr. func NewSIGAddr_List(s *capnp.Segment, sz int32) (SIGAddr_List, error) { - l, err := capnp.NewCompositeList(s, capnp.ObjectSize{DataSize: 8, PointerCount: 1}, sz) + l, err := capnp.NewCompositeList(s, capnp.ObjectSize{DataSize: 0, PointerCount: 2}, sz) return SIGAddr_List{l}, err } @@ -347,29 +364,33 @@ func (p SIGAddr_Promise) Ctrl() HostInfo_Promise { return HostInfo_Promise{Pipeline: p.Pipeline.GetPipeline(0)} } -const schema_8273379c3e06a721 = "x\xda\x8c\x91\xb1\xeb\xd3@\x1c\xc5\xdf\xbbk\x92\xdfO" + - ",Mh\xa7\x82\xa8P\xb1\x15\x15[,jA\xb1\x8a" + - "\x88[\xaf\xae\"\x86&\xd8@L\xd2$\xa5c\xc1?" + - "\xa1n\xea(8\xb9\xf8\x7f88\x88\x93C'gw" + - "\xeb\xc9\x11\xb5C\x1d~\xd3\x17\xbe\xef\xdd}\xee\xdds" + - "?\xdc\x15}\xabA@\x9d\xb6l=\xf6\xdf\x0d\xc5\xe8" + - "\xebk\xa8S\xa4>\xff\xde\xbe\xf3\xf6F\xf1\x12\x16\x1d" + - "\xc0{\xb1\xf1\x96f.V\xe0\xae\xfb\xe6\xcc\xf6\xe7\x8f" + - "o\xff\xf3}\xdax_\xcc\xfc\xbc\x02\xf5\xd1\xedA\xd1" + - "\xeb<\xdd\x9a\x1b\xc5\xde\xf9\x80\x8ed\xad\xd9\xe7\xa6y" + - "\xcb\x1cj\x0e\xf9\x1d\xd4E\xf4\xfc\xea\xcc\xcf\x12f\xa3" + - "\xc7\x8f\x1eN\xd2\x98\xf1\x84TG\xb2\x06\xd4\x08x\xbd" + - "K\x80\xeaH\xaak\x82d\x8bfw\xe5\x1e\xa0\xba\x92" + - "\xea\xba`\xc3\x0f\x82\x9c\xee\xdf\xe7\x81t\xc1u\x11\x16" + - "E\x94&\xb4!h\x1f`\xc6A\xc0\xfc\x04\x98)\xa0" + - ".K\xaa\x9b\x82\x8dY\x99\xc7t\xf5\xb9\x0b\xafV\xd6" + - "\xc5\xf6GT \x1d&3?\x9b\xa49X\xd2\x81\xa0" + - "s\x00\xbb_\xe6U&\xf7\x1f\xcco\x03\xea\x89\xa4\x9a" + - "\x0b\xd6\xa9u\x85\x0b\x07\x80z&\xa9b\xc1\xba\xf8\xa5" + - "[\x14\x80\x17\x99\xac\x81\xa4\xca\x04\xebr\xa7[\x94\xa6" + - "\x19\xb3\x9dK\xaaRPF\x01\x8f!x\x0c\x9e]&" + - "EX\xc2^gi\x1cO\xc3\x05\xdd}\xc1\x7f~\xa6" + - "R\xb2C\xe5w\x00\x00\x00\xff\xfflyx\xa7" +func (p SIGAddr_Promise) Data() HostInfo_Promise { + return HostInfo_Promise{Pipeline: p.Pipeline.GetPipeline(1)} +} + +const schema_8273379c3e06a721 = "x\xdat\x91Ok\x1aQ\x14\xc5\xefy\xcf\x19\xffP" + + "q\x06]\x09\xa5-X\xaa\x82\xa5J\xa5 \xb4\xd4\x96" + + "R\xb2\xf3%\xdb\x1028C\x1c\x98\xe883\xe2R" + + "\xc8G0\xbb$\xcb@6Y\xe5{d\x91E\xc8*" + + "\x0bWYg\x1f\xf3\xc2c\x12\x95HV\x17\xce\xb9\xdc" + + "\xdf;\xef\x18\xe7\xbfY]\xcb\x81H\xbc\xd3t\xd9\xb6" + + "N\x9b\xacusD\"\x03\xc8Og\xfa\xaf\x93\x1f\xe1" + + "\x01iH\x12\x99\xfbSs\xa4\xe6pL\x98\x97\x8f\xdf" + + "\xcf\x1e\xeeo\xcd\xcc\xea\x1aS\xf6\xe5\xd4\xbcV\xf3j" + + "L\x90\xa9\x9f\x8d\xb0R\xda\x99\xa9\x83l\xb9\xf9\x0fI" + + "\x8eD\xbe\x86i\xbe\xa9n\xe7\xeb\xb8#\xc8\xd0\xdd\xfb" + + "\xda\xb5\xfc>\xfc\xd6\xd6\xc6\xff\xce\xc0\x83\xd7\x01D\x8a" + + "'\x88\x12 2+U\"Q\xe2\x10\xdf\x18\x80\x02\x94" + + "V\xfbC$\xca\x1c\xe2;C\xce\xb2\xed\x00\xc6\xcb\xeb" + + "\x080\x08\x93\xd0\x09Cw\xd0\x87N\x0c\xfa\x1a\xa6m" + + "\xdb\x08\xde\xc6\x98\x0bNu\x85\xd3\x8d\x02\x0f\x86\xfc\xf8" + + "\xf9p\xac})^PL\xca\xd9Vd\xad\xcb\xaf\x80" + + "\x7f\xa3 \xcee,\x80V\x91Hls\x88\x1eC\x16" + + "R\xc6D\xa7A$v9\x84\xc7\x90e\x8f\xb2\x00F" + + "d\xba*\xaf\xcd!|\x86,\x9f\xcb\x02\xb8*G\xa9" + + "=\x0e\x111p\xd7F\x9a\x18\xd2\x84\x0f\xa3~\xe8D" + + "\xa4O\xfc\x81\xe7m:C\x18\xcb\x8e\x9f\x7f'v\xfc" + + "u\xe7)\x00\x00\xff\xff\x12\xacx\x8f" func init() { schemas.Register(schema_8273379c3e06a721, diff --git a/go/sig/egress/session/session.go b/go/sig/egress/session/session.go index d7728e65f9..342c6ab697 100644 --- a/go/sig/egress/session/session.go +++ b/go/sig/egress/session/session.go @@ -77,7 +77,7 @@ func NewSession(dstIA addr.IA, sessId sig_mgmt.SessionType, logger log.Logger, s.ring = ringbuf.New(64, nil, fmt.Sprintf("egress_%s_%s", dstIA, sessId)) // Not using a fixed local port, as this is for outgoing data only. s.conn, err = sigcmn.Network.Listen(context.Background(), "udp", - &net.UDPAddr{IP: sigcmn.Host.IP()}, addr.SvcNone) + &net.UDPAddr{IP: sigcmn.DataAddr}, addr.SvcNone) s.sessMonStop = make(chan struct{}) s.sessMonStopped = make(chan struct{}) s.pktDispStop = make(chan struct{}) diff --git a/go/sig/egress/session/sessmon.go b/go/sig/egress/session/sessmon.go index 22bcf9accc..110843ec60 100644 --- a/go/sig/egress/session/sessmon.go +++ b/go/sig/egress/session/sessmon.go @@ -257,7 +257,8 @@ func (sm *sessMonitor) sendReq() { return } sm.updateMsgId = sig_mgmt.MsgIdType(time.Now().UnixNano()) - spld, err := sig_mgmt.NewPld(sm.updateMsgId, sig_mgmt.NewPollReq(sigcmn.MgmtAddr, + mgmtAddr := sigcmn.GetMgmtAddr() + spld, err := sig_mgmt.NewPld(sm.updateMsgId, sig_mgmt.NewPollReq(&mgmtAddr, sm.sess.SessId)) if err != nil { sm.logger.Error("sessMonitor: Error creating SIGCtrl payload", "err", err) @@ -321,7 +322,7 @@ func (sm *sessMonitor) handleRep(rpld *sigdisp.RegPld) { IA: sm.smRemote.Sig.IA, Host: pollRep.Addr.Ctrl.Host(), CtrlL4Port: int(pollRep.Addr.Ctrl.Port), - EncapL4Port: int(pollRep.Addr.EncapPort), + EncapL4Port: int(pollRep.Addr.Data.Port), } // Update session's remote, if needed. sessRemote := sm.sess.Remote() diff --git a/go/sig/egress/worker/BUILD.bazel b/go/sig/egress/worker/BUILD.bazel index 7b8b77758e..7585881038 100644 --- a/go/sig/egress/worker/BUILD.bazel +++ b/go/sig/egress/worker/BUILD.bazel @@ -6,6 +6,7 @@ go_library( importpath = "github.com/scionproto/scion/go/sig/egress/worker", visibility = ["//visibility:public"], deps = [ + "//go/lib/addr:go_default_library", "//go/lib/common:go_default_library", "//go/lib/ctrl/sig_mgmt:go_default_library", "//go/lib/l4:go_default_library", diff --git a/go/sig/egress/worker/worker.go b/go/sig/egress/worker/worker.go index 7be4f6e665..aebc004f68 100644 --- a/go/sig/egress/worker/worker.go +++ b/go/sig/egress/worker/worker.go @@ -20,6 +20,7 @@ import ( "net" "time" + "github.com/scionproto/scion/go/lib/addr" "github.com/scionproto/scion/go/lib/common" "github.com/scionproto/scion/go/lib/ctrl/sig_mgmt" "github.com/scionproto/scion/go/lib/l4" @@ -220,7 +221,8 @@ func (w *worker) resetFrame(f *frame) { if remote != nil { w.currSig = remote.Sig if w.currSig != nil { - addrLen = uint16(spkt.AddrHdrLen(w.currSig.Host, sigcmn.Host)) + addrLen = uint16(spkt.AddrHdrLen(w.currSig.Host, + addr.HostFromIP(sigcmn.DataAddr))) } w.currPathEntry = nil if remote.SessPath != nil { diff --git a/go/sig/internal/base/pollhdlr.go b/go/sig/internal/base/pollhdlr.go index d9ea52e923..c008e633ff 100644 --- a/go/sig/internal/base/pollhdlr.go +++ b/go/sig/internal/base/pollhdlr.go @@ -16,6 +16,7 @@ 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/ctrl/sig_mgmt" @@ -35,9 +36,9 @@ func PollReqHdlr() { "src", rpld.Addr, "type", common.TypeOf(rpld.P), "Id", rpld.Id, "pld", rpld.P) continue } - //log.Debug("PollReqHdlr: got PollReq", "src", rpld.Addr, "pld", req, - // "replyAddr", sigcmn.MgmtAddr, "replySession", req.Session) - spld, err := sig_mgmt.NewPld(rpld.Id, sig_mgmt.NewPollRep(sigcmn.MgmtAddr, req.Session)) + addr := sig_mgmt.NewAddr(addr.HostFromIP(sigcmn.CtrlAddr), uint16(sigcmn.CtrlPort), + addr.HostFromIP(sigcmn.DataAddr), uint16(sigcmn.DataPort)) + spld, err := sig_mgmt.NewPld(rpld.Id, sig_mgmt.NewPollRep(addr, req.Session)) if err != nil { log.Error("PollReqHdlr: Error creating SIGCtrl payload", "err", err) break diff --git a/go/sig/internal/ingress/api.go b/go/sig/internal/ingress/api.go index 18b25d3831..21596dbc23 100644 --- a/go/sig/internal/ingress/api.go +++ b/go/sig/internal/ingress/api.go @@ -18,6 +18,7 @@ package ingress import ( "context" "io" + "net" "github.com/scionproto/scion/go/lib/addr" "github.com/scionproto/scion/go/lib/fatal" @@ -28,7 +29,7 @@ import ( func Init(tunIO io.ReadWriteCloser) { fatal.Check() conn, err := sigcmn.Network.Listen(context.Background(), "udp", - sigcmn.EncapSnetAddr().Host, addr.SvcNone) + &net.UDPAddr{IP: sigcmn.DataAddr, Port: sigcmn.DataPort}, addr.SvcNone) if err != nil { log.Crit("Unable to initialize ingress connection", "err", err) fatal.Fatal(err) diff --git a/go/sig/internal/sigcmn/common.go b/go/sig/internal/sigcmn/common.go index 1a404315af..512a393dc2 100644 --- a/go/sig/internal/sigcmn/common.go +++ b/go/sig/internal/sigcmn/common.go @@ -46,29 +46,29 @@ var ( ) var ( - IA addr.IA - Host addr.HostAddr - + IA addr.IA PathMgr pathmgr.Resolver Dispatcher reliable.Dispatcher Network *snet.SCIONNetwork + CtrlAddr net.IP + CtrlPort int + DataAddr net.IP + DataPort int CtrlConn snet.Conn - MgmtAddr *sig_mgmt.Addr - encapPort uint16 ) func Init(cfg sigconfig.SigConf, sdCfg env.SCIONDClient) error { IA = cfg.IA - Host = addr.HostFromIP(cfg.IP) - MgmtAddr = sig_mgmt.NewAddr(Host, cfg.CtrlPort, cfg.EncapPort) - encapPort = cfg.EncapPort - + CtrlAddr = cfg.IP + CtrlPort = int(cfg.CtrlPort) + DataAddr = cfg.IP + DataPort = int(cfg.EncapPort) network, resolver, err := initNetwork(cfg, sdCfg) if err != nil { return common.NewBasicError("Error creating local SCION Network context", err) } conn, err := network.Listen(context.Background(), "udp", - &net.UDPAddr{IP: Host.IP(), Port: int(cfg.CtrlPort)}, addr.SvcSIG) + &net.UDPAddr{IP: CtrlAddr, Port: CtrlPort}, addr.SvcSIG) if err != nil { return common.NewBasicError("Error creating ctrl socket", err) } @@ -151,10 +151,6 @@ func newDispatcher(cfg sigconfig.SigConf) (reliable.Dispatcher, error) { return dispServer, nil } -func EncapSnetAddr() *snet.UDPAddr { - return &snet.UDPAddr{IA: IA, Host: &net.UDPAddr{IP: Host.IP(), Port: int(encapPort)}} -} - func ValidatePort(desc string, port int) error { if port < 1 || port > MaxPort { return common.NewBasicError("Invalid port", nil, @@ -162,3 +158,8 @@ func ValidatePort(desc string, port int) error { } return nil } + +func GetMgmtAddr() sig_mgmt.Addr { + return *sig_mgmt.NewAddr(addr.HostFromIP(CtrlAddr), uint16(CtrlPort), + addr.HostFromIP(DataAddr), uint16(DataPort)) +} diff --git a/go/sig/main.go b/go/sig/main.go index 420aec573b..cbeb2e64b0 100644 --- a/go/sig/main.go +++ b/go/sig/main.go @@ -150,16 +150,16 @@ func setupTun() (io.ReadWriteCloser, error) { return nil, err } src := cfg.Sig.SrcIP4 - if len(src) == 0 && cfg.Sig.IP.To4() != nil { - src = cfg.Sig.IP + if len(src) == 0 && sigcmn.CtrlAddr.To4() != nil { + src = sigcmn.CtrlAddr } if err = xnet.AddRoute(cfg.Sig.TunRTableId, tunLink, sigcmn.DefV4Net, src); err != nil { return nil, common.NewBasicError("Unable to add default IPv4 route to SIG routing table", err) } src = cfg.Sig.SrcIP6 - if len(src) == 0 && cfg.Sig.IP.To16() != nil && cfg.Sig.IP.To4() == nil { - src = cfg.Sig.IP + if len(src) == 0 && sigcmn.CtrlAddr.To16() != nil && sigcmn.CtrlAddr.To4() == nil { + src = sigcmn.CtrlAddr } if err = xnet.AddRoute(cfg.Sig.TunRTableId, tunLink, sigcmn.DefV6Net, src); err != nil { return nil, diff --git a/proto/sig.capnp b/proto/sig.capnp index 68b4c8fe3c..8a671a5041 100644 --- a/proto/sig.capnp +++ b/proto/sig.capnp @@ -21,5 +21,5 @@ struct SIGPoll { struct SIGAddr { ctrl @0 :Sciond.HostInfo; - encapPort @1 :UInt16; + data @1 :Sciond.HostInfo; }