Skip to content

Commit 587995b

Browse files
author
Marc Odermatt
committed
wip desc-lookup
1 parent 9ff3b0a commit 587995b

File tree

10 files changed

+777
-313
lines changed

10 files changed

+777
-313
lines changed

daemon/internal/servers/grpc.go

+17
Original file line numberDiff line numberDiff line change
@@ -657,3 +657,20 @@ func requestToHostHostMeta(req *sdpb.DRKeyHostHostRequest) (drkey.HostHostMeta,
657657
DstHost: req.DstHost,
658658
}, nil
659659
}
660+
661+
func (s *DaemonServer) RemotePolicyDescription(ctx context.Context,
662+
request *experimental.RemotePolicyDescriptionRequest) (
663+
*experimental.RemotePolicyDescriptionResponse, error) {
664+
conn, err := s.Dialer.Dial(ctx, &snet.SVCAddr{SVC: addr.SvcCS})
665+
if err != nil {
666+
log.FromCtx(ctx).Debug("Dialing CS failed", "err", err)
667+
}
668+
defer conn.Close()
669+
client := experimental.NewFABRIDIntraServiceClient(conn)
670+
response, err := client.RemotePolicyDescription(ctx, request)
671+
if err != nil {
672+
return &experimental.RemotePolicyDescriptionResponse{}, err
673+
}
674+
675+
return response, nil
676+
}

pkg/daemon/BUILD.bazel

+1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ go_library(
2121
"//pkg/private/ctrl/path_mgmt:go_default_library",
2222
"//pkg/private/prom:go_default_library",
2323
"//pkg/private/serrors:go_default_library",
24+
"//pkg/proto/control_plane/experimental:go_default_library",
2425
"//pkg/proto/daemon:go_default_library",
2526
"//pkg/proto/drkey:go_default_library",
2627
"//pkg/scrypto/cppki:go_default_library",

pkg/daemon/daemon.go

+2
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ package daemon
1818

1919
import (
2020
"context"
21+
"github.com/scionproto/scion/pkg/proto/control_plane/experimental"
2122
"net/netip"
2223

2324
"github.com/scionproto/scion/pkg/addr"
@@ -90,6 +91,7 @@ type Connector interface {
9091
DRKeyGetHostHostKey(ctx context.Context, meta drkey.HostHostMeta) (drkey.HostHostKey, error)
9192
// FabridKeys requests FABRID DRKeys for all provided ASes and the path validation key
9293
FabridKeys(ctx context.Context, meta drkey.FabridKeysMeta) (drkey.FabridKeysResponse, error)
94+
RemotePolicyDescription(context.Context, *experimental.RemotePolicyDescriptionRequest) (*experimental.RemotePolicyDescriptionResponse, error)
9395
// Close shuts down the connection to the daemon.
9496
Close() error
9597
}

pkg/daemon/grpc.go

+16
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,15 @@ import (
2424
"google.golang.org/protobuf/types/known/emptypb"
2525
"google.golang.org/protobuf/types/known/timestamppb"
2626

27+
fabrid_control "github.com/scionproto/scion/control/fabrid"
2728
"github.com/scionproto/scion/pkg/addr"
2829
"github.com/scionproto/scion/pkg/drkey"
2930
"github.com/scionproto/scion/pkg/experimental/fabrid"
3031
libgrpc "github.com/scionproto/scion/pkg/grpc"
3132
"github.com/scionproto/scion/pkg/private/common"
3233
"github.com/scionproto/scion/pkg/private/ctrl/path_mgmt"
3334
"github.com/scionproto/scion/pkg/private/serrors"
35+
cppb "github.com/scionproto/scion/pkg/proto/control_plane/experimental"
3436
sdpb "github.com/scionproto/scion/pkg/proto/daemon"
3537
dkpb "github.com/scionproto/scion/pkg/proto/drkey"
3638
"github.com/scionproto/scion/pkg/scrypto/cppki"
@@ -277,6 +279,20 @@ func (c grpcConn) FabridKeys(ctx context.Context, meta drkey.FabridKeysMeta,
277279
}, nil
278280
}
279281

282+
func (c grpcConn) RemotePolicyDescription(ctx context.Context,
283+
identifier fabrid_control.RemotePolicyIdentifier) (fabrid_control.RemotePolicyDescription, error) {
284+
285+
client := sdpb.NewDaemonServiceClient(c.conn)
286+
response, err := client.RemotePolicyDescription(ctx, &cppb.RemotePolicyDescriptionRequest{
287+
PolicyIdentifier: identifier.Identifier,
288+
IsdAs: identifier.ISDAS,
289+
})
290+
if err != nil {
291+
return fabrid_control.RemotePolicyDescription{}, err
292+
}
293+
return fabrid_control.RemotePolicyDescription{Description: }, err
294+
}
295+
280296
func (c grpcConn) Close() error {
281297
return c.conn.Close()
282298
}

pkg/proto/daemon/daemon.pb.go

+366-313
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

proto/daemon/v1/daemon.proto

+6
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import "google/protobuf/timestamp.proto";
2222
import "google/protobuf/duration.proto";
2323
import "google/protobuf/empty.proto";
2424
import "proto/drkey/v1/drkey.proto";
25+
import "proto/control_plane/experimental/v1/fabrid.proto";
2526
import "proto/control_plane/experimental/v1/fabrid_extensions.proto";
2627

2728
service DaemonService {
@@ -47,6 +48,11 @@ service DaemonService {
4748
rpc DRKeyHostHost (DRKeyHostHostRequest) returns (DRKeyHostHostResponse) {}
4849
// FabridKeys returns the DRKeys for FABRID
4950
rpc FabridKeys (FabridKeysRequest) returns (FabridKeysResponse) {}
51+
// Used by a host inside the AS to request a policy description for another AS. The control
52+
// service will request the policy description from the remote AS if it is unknown to the
53+
// control service.
54+
rpc RemotePolicyDescription(proto.control_plane.experimental.v1.RemotePolicyDescriptionRequest) returns
55+
(proto.control_plane.experimental.v1.RemotePolicyDescriptionResponse) {}
5056
}
5157

5258
message PathsRequest {

scion/cmd/scion/fabrid.go

+150
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,150 @@
1+
// Copyright 2020 Anapaya Systems
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
package main
16+
17+
import (
18+
"context"
19+
"fmt"
20+
"net"
21+
"time"
22+
23+
"github.com/scionproto/scion/pkg/addr"
24+
"github.com/scionproto/scion/pkg/log"
25+
"github.com/scionproto/scion/pkg/private/serrors"
26+
"github.com/scionproto/scion/private/app"
27+
"github.com/scionproto/scion/private/app/flag"
28+
"github.com/scionproto/scion/private/tracing"
29+
"github.com/scionproto/scion/scion/fabrid"
30+
"github.com/spf13/cobra"
31+
)
32+
33+
func newFabrid(pather CommandPather) *cobra.Command {
34+
var envFlags flag.SCIONEnvironment
35+
var flags struct {
36+
timeout time.Duration
37+
cfg fabrid.Config
38+
extended bool
39+
json bool
40+
logLevel string
41+
noColor bool
42+
tracer string
43+
format string
44+
}
45+
46+
var cmd = &cobra.Command{
47+
Use: "fabrid",
48+
Short: "Display FABRID policy information",
49+
Args: cobra.ExactArgs(1),
50+
Example: fmt.Sprintf(` %[1]s showpaths 1-ff00:0:110 --extended
51+
%[1]s showpaths 1-ff00:0:110 --local 127.0.0.55 --json
52+
%[1]s showpaths 1-ff00:0:111 --sequence="0-0#2 0*" # outgoing IfID=2
53+
%[1]s showpaths 1-ff00:0:111 --sequence="0* 0-0#41" # incoming IfID=41 at dstIA
54+
%[1]s showpaths 1-ff00:0:111 --sequence="0* 1-ff00:0:112 0*" # 1-ff00:0:112 on the path
55+
%[1]s showpaths 1-ff00:0:110 --no-probe`, pather.CommandPath()),
56+
Long: `'fabrid' lists available policies at a remote AS, or shows the
57+
description of a specific policy.`,
58+
RunE: func(cmd *cobra.Command, args []string) error {
59+
dst, err := addr.ParseIA(args[0])
60+
if err != nil {
61+
return serrors.WrapStr("invalid destination ISD-AS", err)
62+
}
63+
if err := app.SetupLog(flags.logLevel); err != nil {
64+
return serrors.WrapStr("setting up logging", err)
65+
}
66+
closer, err := setupTracer("fabrid", flags.tracer)
67+
if err != nil {
68+
return serrors.WrapStr("setting up tracing", err)
69+
}
70+
defer closer()
71+
72+
if flags.json && !cmd.Flags().Lookup("format").Changed {
73+
flags.format = "json"
74+
}
75+
printf, err := getPrintf(flags.format, cmd.OutOrStdout())
76+
if err != nil {
77+
return serrors.WrapStr("get formatting", err)
78+
}
79+
80+
cmd.SilenceUsage = true
81+
82+
if err := envFlags.LoadExternalVars(); err != nil {
83+
return err
84+
}
85+
86+
flags.cfg.Daemon = envFlags.Daemon()
87+
flags.cfg.Local = net.IP(envFlags.Local().AsSlice())
88+
log.Debug("Resolved SCION environment flags",
89+
"daemon", flags.cfg.Daemon,
90+
"local", flags.cfg.Local,
91+
)
92+
93+
span, traceCtx := tracing.CtxWith(context.Background(), "run")
94+
span.SetTag("dst.isd_as", dst)
95+
defer span.Finish()
96+
97+
ctx, cancel := context.WithTimeout(traceCtx, flags.timeout)
98+
defer cancel()
99+
res, err := fabrid.Run(ctx, dst, flags.cfg)
100+
if err != nil {
101+
return err
102+
}
103+
104+
switch flags.format {
105+
case "human":
106+
if res.IsLocal() {
107+
printf("Empty path, destination is local AS %s\n", res.Destination)
108+
return nil
109+
}
110+
printf("Available policies at %s\n", res.Destination)
111+
if len(res.Paths) == 0 {
112+
return app.WithExitCode(serrors.New("no policies found"), 1)
113+
}
114+
res.Human(cmd.OutOrStdout(), flags.extended, !flags.noColor)
115+
case "json":
116+
return serrors.New("Not implemented", "format", flags.format)
117+
case "yaml":
118+
return serrors.New("Not implemented", "format", flags.format)
119+
default:
120+
return serrors.New("output format not supported", "format", flags.format)
121+
}
122+
return nil
123+
},
124+
}
125+
126+
envFlags.Register(cmd.Flags())
127+
cmd.Flags().DurationVar(&flags.timeout, "timeout", 5*time.Second, "Timeout")
128+
cmd.Flags().StringVar(&flags.cfg.Sequence, "sequence", "", app.SequenceUsage)
129+
cmd.Flags().IntVarP(&flags.cfg.MaxPaths, "maxpaths", "m", 10,
130+
"Maximum number of paths that are displayed")
131+
cmd.Flags().BoolVarP(&flags.extended, "extended", "e", false,
132+
"Show extended path meta data information")
133+
cmd.Flags().BoolVarP(&flags.cfg.Refresh, "refresh", "r", false,
134+
"Set refresh flag for SCION Daemon path request")
135+
cmd.Flags().BoolVar(&flags.cfg.NoProbe, "no-probe", false,
136+
"Do not probe the paths and print the health status")
137+
cmd.Flags().BoolVarP(&flags.json, "json", "j", false,
138+
"Write the output as machine readable json")
139+
cmd.Flags().StringVar(&flags.format, "format", "human",
140+
"Specify the output format (human|json|yaml)")
141+
cmd.Flags().BoolVar(&flags.noColor, "no-color", false, "disable colored output")
142+
cmd.Flags().StringVar(&flags.logLevel, "log.level", "", app.LogLevelUsage)
143+
cmd.Flags().StringVar(&flags.tracer, "tracing.agent", "", "Tracing agent address")
144+
cmd.Flags().BoolVar(&flags.cfg.Epic, "epic", false, "Enable EPIC.")
145+
err := cmd.Flags().MarkDeprecated("json", "json flag is deprecated, use format flag")
146+
if err != nil {
147+
panic(err)
148+
}
149+
return cmd
150+
}

scion/fabrid/BUILD.bazel

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
load("//tools/lint:go.bzl", "go_library")
2+
3+
go_library(
4+
name = "go_default_library",
5+
srcs = [
6+
"config.go",
7+
"showpaths.go",
8+
],
9+
importpath = "github.com/scionproto/scion/scion/fabrid",
10+
visibility = ["//visibility:public"],
11+
deps = [
12+
"//pkg/addr:go_default_library",
13+
"//pkg/daemon:go_default_library",
14+
"//pkg/private/common:go_default_library",
15+
"//pkg/private/serrors:go_default_library",
16+
"//pkg/snet:go_default_library",
17+
"//private/app/path:go_default_library",
18+
"//private/app/path/pathprobe:go_default_library",
19+
"//private/path/pathpol:go_default_library",
20+
],
21+
)

scion/fabrid/config.go

+44
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
// Copyright 2020 Anapaya Systems
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
package fabrid
16+
17+
import (
18+
"net"
19+
)
20+
21+
// DefaultMaxPaths is the maximum number of paths that are displayed by default.
22+
const DefaultMaxPaths = 10
23+
24+
// Config configures the showpath run.
25+
type Config struct {
26+
// Local configures the local IP address to use. If this option is not provided,
27+
// a local IP that can reach SCION hosts is selected with the help of the kernel.
28+
Local net.IP
29+
// Daemon configures a specific SCION Daemon address.
30+
Daemon string
31+
// MaxPaths configures the maximum number of displayed paths. If this option is
32+
// not provided, the DefaultMaxPaths is used.
33+
MaxPaths int
34+
// Refresh configures whether the daemon is queried with the refresh flag.
35+
Refresh bool
36+
// NoProbe configures whether the path status is probed or not.
37+
NoProbe bool
38+
// Sequence is a string of space separated Hop Predicates that is used for
39+
// filtering.
40+
Sequence string
41+
// Epic filters paths for which EPIC is not available, and when probing, the
42+
// EPIC path type header is used.
43+
Epic bool
44+
}

0 commit comments

Comments
 (0)