Skip to content

Commit

Permalink
add PortRange() RPC in daemon
Browse files Browse the repository at this point in the history
  • Loading branch information
JordiSubira committed Mar 12, 2024
1 parent abdba38 commit 85db1d3
Show file tree
Hide file tree
Showing 7 changed files with 451 additions and 335 deletions.
1 change: 1 addition & 0 deletions daemon/internal/servers/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ go_library(
"@com_github_golang_protobuf//ptypes/duration",
"@com_github_golang_protobuf//ptypes/timestamp",
"@com_github_opentracing_opentracing_go//:go_default_library",
"@org_golang_google_protobuf//types/known/emptypb:go_default_library",
"@org_golang_x_sync//singleflight:go_default_library",
],
)
26 changes: 17 additions & 9 deletions daemon/internal/servers/grpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (
timestamppb "github.com/golang/protobuf/ptypes/timestamp"
"github.com/opentracing/opentracing-go"
"golang.org/x/sync/singleflight"
"google.golang.org/protobuf/types/known/emptypb"

drkey_daemon "github.com/scionproto/scion/daemon/drkey"
"github.com/scionproto/scion/daemon/fetcher"
Expand Down Expand Up @@ -243,21 +244,15 @@ func (s *DaemonServer) as(ctx context.Context, req *sdpb.ASRequest) (*sdpb.ASRes
if reqIA.Equal(s.IA) {
mtu = uint32(s.MTU)
}
var startPort, endPort uint16
if reqIA.Equal(s.IA) {
startPort, endPort = s.Topology.PortRange()
}
core, err := s.ASInspector.HasAttributes(ctx, reqIA, trust.Core)
if err != nil {
log.FromCtx(ctx).Error("Inspecting ISD-AS", "err", err, "isd_as", reqIA)
return nil, serrors.WrapStr("inspecting ISD-AS", err, "isd_as", reqIA)
}
reply := &sdpb.ASResponse{
IsdAs: uint64(reqIA),
Core: core,
Mtu: mtu,
EndhostStartPort: uint32(startPort),
EndhostEndPort: uint32(endPort),
IsdAs: uint64(reqIA),
Core: core,
Mtu: mtu,
}
return reply, nil
}
Expand Down Expand Up @@ -358,6 +353,19 @@ func (s *DaemonServer) notifyInterfaceDown(ctx context.Context,
return &sdpb.NotifyInterfaceDownResponse{}, nil
}

// AS serves the AS request.
func (s *DaemonServer) PortRange(
_ context.Context,
_ *emptypb.Empty,
) (*sdpb.PortRangeResponse, error) {

startPort, endPort := s.Topology.PortRange()
return &sdpb.PortRangeResponse{
EndhostStartPort: uint32(startPort),
EndhostEndPort: uint32(endPort),
}, nil
}

func (s *DaemonServer) DRKeyASHost(
ctx context.Context,
req *pb_daemon.DRKeyASHostRequest,
Expand Down
1 change: 1 addition & 0 deletions pkg/daemon/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ go_library(
"//pkg/snet/path:go_default_library",
"//private/topology:go_default_library",
"@org_golang_google_grpc//:go_default_library",
"@org_golang_google_protobuf//types/known/emptypb:go_default_library",
"@org_golang_google_protobuf//types/known/timestamppb:go_default_library",
],
)
12 changes: 6 additions & 6 deletions pkg/daemon/grpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"time"

"google.golang.org/grpc"
"google.golang.org/protobuf/types/known/emptypb"
"google.golang.org/protobuf/types/known/timestamppb"

"github.com/scionproto/scion/pkg/addr"
Expand Down Expand Up @@ -75,11 +76,12 @@ func (c grpcConn) LocalIA(ctx context.Context) (addr.IA, error) {
}

func (c grpcConn) PortRange(ctx context.Context) (uint16, uint16, error) {
asInfo, err := c.ASInfo(ctx, 0)
client := sdpb.NewDaemonServiceClient(c.conn)
response, err := client.PortRange(ctx, &emptypb.Empty{})
if err != nil {
return 0, 0, err
}
return asInfo.EndhostStartPort, asInfo.EndhostEndPort, nil
return uint16(response.EndhostStartPort), uint16(response.EndhostEndPort), nil
}

func (c grpcConn) Interfaces(ctx context.Context) (map[uint16]*net.UDPAddr, error) {
Expand Down Expand Up @@ -130,10 +132,8 @@ func (c grpcConn) ASInfo(ctx context.Context, ia addr.IA) (ASInfo, error) {
}
c.metrics.incAS(nil)
return ASInfo{
IA: addr.IA(response.IsdAs),
MTU: uint16(response.Mtu),
EndhostStartPort: uint16(response.EndhostStartPort),
EndhostEndPort: uint16(response.EndhostEndPort),
IA: addr.IA(response.IsdAs),
MTU: uint16(response.Mtu),
}, nil
}

Expand Down
Loading

0 comments on commit 85db1d3

Please sign in to comment.