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

cmd/scion, snet: reduce range of IDs for SCMP requests #4495

Merged
merged 1 commit into from
Mar 28, 2024
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
3 changes: 1 addition & 2 deletions gateway/pathhealth/remotewatcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ package pathhealth
import (
"context"
"fmt"
"math/rand"
"sync"
"time"

Expand Down Expand Up @@ -257,7 +256,7 @@ func (w *remoteWatcher) updatePaths(ctx context.Context) {

func (w *remoteWatcher) selectID() (uint16, bool) {
for i := 0; i < 100; i++ {
id := uint16(rand.Uint32())
id := snet.RandomSCMPIdentifer()
if _, ok := w.pathWatchersByID[id]; !ok {
return id, true
}
Expand Down
26 changes: 26 additions & 0 deletions pkg/snet/packet.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
package snet

import (
"math/rand"

"github.com/google/gopacket"

"github.com/scionproto/scion/pkg/addr"
Expand Down Expand Up @@ -192,6 +194,30 @@ func (m SCMPInternalConnectivityDown) length() int {
return 28 + len(m.Payload)
}

const (
// SCMPIdentifierStart and SCMPIdentiferEnd define the range for Identifiers
// that should be used for SCMPEchoRequest and SCMPTracerouteRequest,
// in preparation for a dispatcher-less snet.
// This range corresponds to the port range used for SCION/UDP by the
// dispatcher. Using the same range for Identifiers in SCMP requests will
// allow a router to dispatch SCMP requests based on the Identifier,
// without risk of interfering with unaware endpoints.
//
// WARNING: transitional, this will be removed in the dispatcher-less snet.
SCMPIdentifierStart = 32768
SCMPIdentifierEnd = 65535
)

// RandomSCMPIdentifier returns a random SCMP identifier in the range
// [SCMPIdentifierStart, SCMPIdentifierEnd].
//
// WARNING: This is a transitional helper function, which will be removed
// in the dispatcher-less snet; then, the underlay port must be used as identifier.
func RandomSCMPIdentifer() uint16 {
id := SCMPIdentifierStart + rand.Int31n(SCMPIdentifierEnd-SCMPIdentifierStart+1)
return uint16(id)
}

// SCMPEchoRequest is the SCMP echo request payload.
type SCMPEchoRequest struct {
Identifier uint16
Expand Down
2 changes: 1 addition & 1 deletion private/app/path/path.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ func filterUnhealthy(
DstIA: remote,
LocalIA: cfg.LocalIA,
LocalIP: cfg.LocalIP,
ID: uint16(rand.Uint32()),
ID: snet.RandomSCMPIdentifer(),
SCIONPacketConnMetrics: cfg.SCIONPacketConnMetrics,
Dispatcher: cfg.Dispatcher,
}.GetStatuses(subCtx, nonEmptyPaths, pathprobe.WithEPIC(epic))
Expand Down
9 changes: 4 additions & 5 deletions scion/ping/ping.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ package ping
import (
"context"
"encoding/binary"
"math/rand"
"net"
"sync"
"time"
Expand Down Expand Up @@ -103,13 +102,13 @@ func Run(ctx context.Context, cfg Config) (Stats, error) {
return Stats{}, serrors.New("interval below millisecond")
}

id := rand.Uint64()
replies := make(chan reply, 10)

id := snet.RandomSCMPIdentifer()
svc := snet.DefaultPacketDispatcherService{
Dispatcher: cfg.Dispatcher,
SCMPHandler: scmpHandler{
id: uint16(id),
id: id,
replies: replies,
},
}
Expand Down Expand Up @@ -148,7 +147,7 @@ type pinger struct {
timeout time.Duration
pldSize int

id uint64
id uint16
conn snet.PacketConn
local *snet.UDPAddr
replies <-chan reply
Expand Down Expand Up @@ -224,7 +223,7 @@ func (p *pinger) send(remote *snet.UDPAddr) error {

binary.BigEndian.PutUint64(p.pld, uint64(time.Now().UnixNano()))
pkt, err := pack(p.local, remote, snet.SCMPEchoRequest{
Identifier: uint16(p.id),
Identifier: p.id,
SeqNumber: uint16(sequence),
Payload: p.pld,
})
Expand Down
3 changes: 1 addition & 2 deletions scion/showpaths/showpaths.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import (
"fmt"
"io"
"math"
"math/rand"
"net/netip"
"strconv"
"strings"
Expand Down Expand Up @@ -356,7 +355,7 @@ func Run(ctx context.Context, dst addr.IA, cfg Config) (*Result, error) {
DstIA: dst,
LocalIA: localIA,
LocalIP: cfg.Local,
ID: uint16(rand.Uint32()),
ID: snet.RandomSCMPIdentifer(),
Dispatcher: cfg.Dispatcher,
}.GetStatuses(ctx, p, pathprobe.WithEPIC(cfg.Epic))
if err != nil {
Expand Down
5 changes: 2 additions & 3 deletions scion/traceroute/traceroute.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ package traceroute

import (
"context"
"math/rand"
"net"
"net/netip"
"time"
Expand Down Expand Up @@ -100,7 +99,7 @@ func Run(ctx context.Context, cfg Config) (Stats, error) {
if _, isEmpty := cfg.PathEntry.Dataplane().(path.Empty); isEmpty {
return Stats{}, serrors.New("empty path is not allowed for traceroute")
}
id := rand.Uint64()
id := snet.RandomSCMPIdentifer()
replies := make(chan reply, 10)
dispatcher := snet.DefaultPacketDispatcherService{
Dispatcher: cfg.Dispatcher,
Expand All @@ -121,7 +120,7 @@ func Run(ctx context.Context, cfg Config) (Stats, error) {
replies: replies,
errHandler: cfg.ErrHandler,
updateHandler: cfg.UpdateHandler,
id: uint16(id),
id: id,
path: cfg.PathEntry,
epic: cfg.EPIC,
}
Expand Down
Loading