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

snet: add support for new SCION header #3810

Merged
merged 1 commit into from
Jun 30, 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
25 changes: 23 additions & 2 deletions go/examples/pingpong/pingpong.go
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,17 @@ func (c *client) run() {
if err != nil {
LogFatal("Unable to initialize SCION network", "err", err)
}
network := snet.NewNetwork(local.IA, ds, sd.RevHandler{Connector: sciondConn})
network := &snet.SCIONNetwork{
LocalIA: local.IA,
Dispatcher: &snet.DefaultPacketDispatcherService{
Dispatcher: ds,
SCMPHandler: snet.NewSCMPHandler(
sd.RevHandler{Connector: sciondConn},
),
// TODO(scrye): set this when we have CLI support for features
Version2: false,
},
}

// Connect to remote address. Note that currently the SCION library
// does not support automatic binding to local addresses, so the local
Expand Down Expand Up @@ -348,7 +358,18 @@ func (s server) run() {
if err != nil {
LogFatal("Unable to initialize SCION network", "err", err)
}
network := snet.NewNetwork(local.IA, ds, sd.RevHandler{Connector: sciondConn})
network := &snet.SCIONNetwork{
LocalIA: local.IA,
Dispatcher: &snet.DefaultPacketDispatcherService{
Dispatcher: ds,
SCMPHandler: snet.NewSCMPHandler(
sciond.RevHandler{Connector: sciondConn},
),
// TODO(scrye): set this when we have CLI support for features
Version2: false,
},
}

if err != nil {
LogFatal("Unable to initialize SCION network", "err", err)
}
Expand Down
12 changes: 11 additions & 1 deletion go/integration/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,17 @@ func InitNetwork() *snet.SCIONNetwork {
if err != nil {
LogFatal("Unable to initialize SCION network", "err", err)
}
n := snet.NewNetwork(Local.IA, ds, sciond.RevHandler{Connector: sciondConn})
n := &snet.SCIONNetwork{
LocalIA: Local.IA,
Dispatcher: &snet.DefaultPacketDispatcherService{
Dispatcher: ds,
SCMPHandler: snet.NewSCMPHandler(
sciond.RevHandler{Connector: sciondConn},
),
// TODO(scrye): set this when we have CLI support for features
Version2: false,
},
}
log.Debug("SCION network successfully initialized")
return n
}
Expand Down
4 changes: 4 additions & 0 deletions go/integration/end2end/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,8 @@ func (s server) run() {
SCMPHandler: snet.NewSCMPHandler(
sciond.RevHandler{Connector: integration.SDConn()},
),
// TODO(scrye): set this when we have CLI support for features
Version2: false,
}
conn, port, err := connFactory.Register(context.Background(), integration.Local.IA,
integration.Local.Host, addr.SvcNone)
Expand Down Expand Up @@ -165,6 +167,8 @@ func (c client) run() int {
SCMPHandler: snet.NewSCMPHandler(
sciond.RevHandler{Connector: integration.SDConn()},
),
// TODO(scrye): set this when we have CLI support for features
Version2: false,
}

var err error
Expand Down
6 changes: 6 additions & 0 deletions go/lib/infra/infraenv/infraenv.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,9 @@ type NetworkConfig struct {
// SVCRouter is used to discover the underlay addresses of intra-AS SVC
// servers.
SVCRouter messenger.LocalSVCRouter

// Version2 switches packets to SCION header format version 2.
Version2 bool
}

// Messenger initializes a SCION control-plane RPC endpoint using the specified
Expand Down Expand Up @@ -138,6 +141,7 @@ func (nc *NetworkConfig) AddressRewriter(
if connFactory == nil {
connFactory = &snet.DefaultPacketDispatcherService{
Dispatcher: reliable.NewDispatcher(""),
Version2: nc.Version2,
}
}

Expand Down Expand Up @@ -187,6 +191,7 @@ func (nc *NetworkConfig) initUDPSocket(quicAddress string) (net.PacketConn, erro
packetDispatcher := svc.NewResolverPacketDispatcher(
&snet.DefaultPacketDispatcherService{
Dispatcher: dispatcherService,
Version2: nc.Version2,
},
&LegacyForwardingHandler{
BaseHandler: &svc.BaseHandler{
Expand Down Expand Up @@ -214,6 +219,7 @@ func (nc *NetworkConfig) initQUICSocket() (net.PacketConn, error) {
Dispatcher: &snet.DefaultPacketDispatcherService{
Dispatcher: dispatcherService,
SCMPHandler: ignoreSCMP{},
Version2: nc.Version2,
},
}
udpAddr, err := net.ResolveUDPAddr("udp", nc.QUIC.Address)
Expand Down
4 changes: 4 additions & 0 deletions go/lib/sciond/pathprobe/paths.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,9 @@ type Prober struct {
DstIA addr.IA
LocalIA addr.IA
LocalIP net.IP

// Version2 switches packets to SCION header format version 2.
Version2 bool
}

// GetStatuses probes the paths and returns the statuses of the paths. The
Expand All @@ -119,6 +122,7 @@ func (p Prober) GetStatuses(ctx context.Context,
Dispatcher: &snet.DefaultPacketDispatcherService{
Dispatcher: reliable.NewDispatcher(""),
SCMPHandler: scmpH,
Version2: p.Version2,
},
}
snetConn, err := network.Listen(ctx, "udp", &net.UDPAddr{IP: p.LocalIP}, addr.SvcNone)
Expand Down
3 changes: 3 additions & 0 deletions go/lib/snet/base.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ type scionConnBase struct {

// Describes L4 protocol; currently only udp is implemented
net string

// version2 switches packets to SCION header format version 2.
version2 bool
}

func (c *scionConnBase) LocalAddr() net.Addr {
Expand Down
9 changes: 8 additions & 1 deletion go/lib/snet/dispatcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ type DefaultPacketDispatcherService struct {
// handler is nil, errors are returned back to applications every time an
// SCMP message is received.
SCMPHandler SCMPHandler

// Version2 switches packets to SCION header format version 2.
Version2 bool
}

func (s *DefaultPacketDispatcherService) Register(ctx context.Context, ia addr.IA,
Expand All @@ -54,7 +57,11 @@ func (s *DefaultPacketDispatcherService) Register(ctx context.Context, ia addr.I
if err != nil {
return nil, 0, err
}
return &SCIONPacketConn{conn: rconn, scmpHandler: s.SCMPHandler}, port, nil
return &SCIONPacketConn{
conn: rconn,
scmpHandler: s.SCMPHandler,
version2: s.Version2,
}, port, nil
}

// RevocationHandler is called by the default SCMP Handler whenever revocations are encountered.
Expand Down
19 changes: 14 additions & 5 deletions go/lib/snet/packet_conn.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,9 @@ type SCIONPacketConn struct {
// handler is nil, errors are returned back to applications every time an
// SCMP message is received.
scmpHandler SCMPHandler

// version2 switches packets to SCION header format version 2.
version2 bool
}

// NewSCIONPacketConn creates a new conn with packet serialization/decoding
Expand Down Expand Up @@ -164,7 +167,12 @@ func (c *SCIONPacketConn) WriteTo(pkt *Packet, ov *net.UDPAddr) error {
Pld: pkt.Payload,
}
pkt.Prepare()
n, err := hpkt.WriteScnPkt(scnPkt, common.RawBytes(pkt.Bytes))
var n int
if c.version2 {
n, err = hpkt.WriteScnPkt2(scnPkt, pkt.Bytes)
} else {
n, err = hpkt.WriteScnPkt(scnPkt, common.RawBytes(pkt.Bytes))
}
if err != nil {
return common.NewBasicError("Unable to serialize SCION packet", err)
}
Expand Down Expand Up @@ -230,11 +238,12 @@ func (c *SCIONPacketConn) readFrom(pkt *Packet, ov *net.UDPAddr) error {

// TODO(scrye): scnPkt is a temporary solution. Its functionality will be
// absorbed by the easier to use Packet structure in this package.
scnPkt := &spkt.ScnPkt{
DstIA: addr.IA{},
SrcIA: addr.IA{},
scnPkt := &spkt.ScnPkt{}
if c.version2 {
err = hpkt.ParseScnPkt2(scnPkt, common.RawBytes(pkt.Bytes))
} else {
err = hpkt.ParseScnPkt(scnPkt, common.RawBytes(pkt.Bytes))
}
err = hpkt.ParseScnPkt(scnPkt, common.RawBytes(pkt.Bytes))
if err != nil {
metrics.M.ParseErrors().Inc()
return common.NewBasicError("SCION packet parse error", err)
Expand Down
3 changes: 3 additions & 0 deletions go/pkg/cs/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,7 @@ func (app *App) Run() int {
},
SVCResolutionFraction: Cfg.QUIC.ResolutionFraction,
SVCRouter: messenger.NewSVCRouter(itopo.Provider()),
Version2: Cfg.Features.HeaderV2,
}
msgr, err := nc.Messenger()
if err != nil {
Expand Down Expand Up @@ -458,6 +459,7 @@ func (app *App) Run() int {
}
pktDisp := &snet.DefaultPacketDispatcherService{
Dispatcher: dispatcherService,
Version2: Cfg.Features.HeaderV2,
}
// We do not need to drain the connection, since the src address is spoofed
// to contain the topo address.
Expand Down Expand Up @@ -488,6 +490,7 @@ func (app *App) Run() int {
&onehop.OHPPacketDispatcherService{
PacketDispatcherService: &snet.DefaultPacketDispatcherService{
Dispatcher: reliable.NewDispatcher(""),
Version2: Cfg.Features.HeaderV2,
},
},
),
Expand Down
2 changes: 2 additions & 0 deletions go/pkg/showpaths/showpaths.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,8 @@ func Run(ctx context.Context, dst addr.IA, cfg Config) (*Result, error) {
DstIA: dst,
LocalIA: localIA,
LocalIP: localIP,
// TODO(scrye): set this when we have CLI support for features
Version2: false,
}.GetStatuses(ctx, paths)
if err != nil {
serrors.WrapStr("failed to get status", err)
Expand Down
3 changes: 3 additions & 0 deletions go/scion-pki/certs/renew.go
Original file line number Diff line number Diff line change
Expand Up @@ -389,6 +389,7 @@ func buildMsgr(ctx context.Context, ds reliable.Dispatcher, sds sciond.Service,
SCMPHandler: snet.NewSCMPHandler(
sciond.RevHandler{Connector: sdConn},
),
Version2: false, // TODO(scrye): set this to true when we have CLI support for features
},
}
conn, err := sn.Dial(ctx, "udp", local.Host, remote, addr.SvcNone)
Expand All @@ -408,6 +409,8 @@ func buildMsgr(ctx context.Context, ds reliable.Dispatcher, sds sciond.Service,
LocalIA: local.IA,
ConnFactory: &snet.DefaultPacketDispatcherService{
Dispatcher: ds,
// TODO(scrye): set this to true when we have CLI support for features
Version2: false,
},
LocalIP: local.Host.IP,
Payload: []byte{0x00, 0x00, 0x00, 0x00},
Expand Down
32 changes: 23 additions & 9 deletions go/sig/internal/sigcmn/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,13 +57,13 @@ var (
CtrlConn *snet.Conn
)

func Init(cfg sigconfig.SigConf, sdCfg env.SCIONDClient) error {
func Init(cfg sigconfig.SigConf, sdCfg env.SCIONDClient, features env.Features) error {
IA = cfg.IA
CtrlAddr = cfg.IP
CtrlPort = int(cfg.CtrlPort)
DataAddr = cfg.IP
DataPort = int(cfg.EncapPort)
network, resolver, err := initNetwork(cfg, sdCfg)
network, resolver, err := initNetwork(cfg, sdCfg, features)
if err != nil {
return common.NewBasicError("Error creating local SCION Network context", err)
}
Expand All @@ -81,41 +81,55 @@ func Init(cfg sigconfig.SigConf, sdCfg env.SCIONDClient) error {
}

func initNetwork(cfg sigconfig.SigConf,
sdCfg env.SCIONDClient) (*snet.SCIONNetwork, pathmgr.Resolver, error) {
sdCfg env.SCIONDClient, features env.Features) (*snet.SCIONNetwork, pathmgr.Resolver, error) {

var err error
Dispatcher, err = newDispatcher(cfg)
if err != nil {
return nil, nil, serrors.WrapStr("unable to initialize SCION dispatcher", err)
}
if sdCfg.FakeData != "" {
return initNetworkWithFakeSCIOND(cfg, sdCfg)
return initNetworkWithFakeSCIOND(cfg, sdCfg, features)
}
return initNetworkWithRealSCIOND(cfg, sdCfg)
return initNetworkWithRealSCIOND(cfg, sdCfg, features)
}

func initNetworkWithFakeSCIOND(cfg sigconfig.SigConf,
sdCfg env.SCIONDClient) (*snet.SCIONNetwork, pathmgr.Resolver, error) {
sdCfg env.SCIONDClient, features env.Features) (*snet.SCIONNetwork, pathmgr.Resolver, error) {

sciondConn, err := fake.NewFromFile(sdCfg.FakeData)
if err != nil {
return nil, nil, serrors.WrapStr("unable to initialize fake SCIOND service", err)
}
pathResolver := pathmgr.New(sciondConn, pathmgr.Timers{}, sdCfg.PathCount)
network := snet.NewNetwork(cfg.IA, Dispatcher, pathResolver)
network := &snet.SCIONNetwork{
LocalIA: cfg.IA,
Dispatcher: &snet.DefaultPacketDispatcherService{
Dispatcher: Dispatcher,
SCMPHandler: snet.NewSCMPHandler(pathResolver),
Version2: features.HeaderV2,
},
}
return network, pathResolver, nil
}

func initNetworkWithRealSCIOND(cfg sigconfig.SigConf,
sdCfg env.SCIONDClient) (*snet.SCIONNetwork, pathmgr.Resolver, error) {
sdCfg env.SCIONDClient, features env.Features) (*snet.SCIONNetwork, pathmgr.Resolver, error) {

// TODO(karampok). To be kept until https://github.com/scionproto/scion/issues/3377
deadline := time.Now().Add(sdCfg.InitialConnectPeriod.Duration)
var retErr error
for tries := 0; time.Now().Before(deadline); tries++ {
resolver, err := snetmigrate.ResolverFromSD(sdCfg.Address, sdCfg.PathCount)
if err == nil {
return snet.NewNetwork(cfg.IA, Dispatcher, resolver), resolver, nil
return &snet.SCIONNetwork{
LocalIA: cfg.IA,
Dispatcher: &snet.DefaultPacketDispatcherService{
Dispatcher: Dispatcher,
SCMPHandler: snet.NewSCMPHandler(resolver),
Version2: features.HeaderV2,
},
}, resolver, nil
}
log.Debug("SIG is retrying to get NewNetwork", "err", err)
retErr = err
Expand Down
2 changes: 1 addition & 1 deletion go/sig/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ func realMain() int {
log.Error("TUN device initialization failed", "err", err)
return 1
}
if err := sigcmn.Init(cfg.Sig, cfg.Sciond); err != nil {
if err := sigcmn.Init(cfg.Sig, cfg.Sciond, cfg.Features); err != nil {
log.Error("SIG common initialization failed", "err", err)
return 1
}
Expand Down
2 changes: 2 additions & 0 deletions go/tools/showpaths/paths.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,8 @@ func main() {
DstIA: dstIA,
LocalIA: localIA,
LocalIP: localIP,
// TODO(scrye): set this when we have CLI support for features
Version2: false,
}.GetStatuses(ctx, paths)
if err != nil {
LogFatal("Failed to get status", "err", err)
Expand Down