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

gateway: determine default local IP #3936

Merged
merged 3 commits into from
Nov 27, 2020
Merged
Show file tree
Hide file tree
Changes from 2 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
1 change: 1 addition & 0 deletions go/lib/snet/addrutil/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ go_library(
deps = [
"//go/lib/addr:go_default_library",
"//go/lib/ctrl/seg:go_default_library",
"//go/lib/sciond:go_default_library",
"//go/lib/serrors:go_default_library",
"//go/lib/slayers:go_default_library",
"//go/lib/slayers/path:go_default_library",
Expand Down
21 changes: 21 additions & 0 deletions go/lib/snet/addrutil/addrutil.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,13 @@
package addrutil

import (
"context"
"encoding/binary"
"net"

"github.com/scionproto/scion/go/lib/addr"
"github.com/scionproto/scion/go/lib/ctrl/seg"
"github.com/scionproto/scion/go/lib/sciond"
"github.com/scionproto/scion/go/lib/serrors"
"github.com/scionproto/scion/go/lib/slayers"
"github.com/scionproto/scion/go/lib/slayers/path"
Expand Down Expand Up @@ -94,6 +96,25 @@ func (p Pather) GetPath(svc addr.HostSVC, ps *seg.PathSegment) (*snet.SVCAddr, e

}

// DefaultLocalIP returns _a_ IP of this host in the local AS.
//
// This returns a sensible but arbitrary local IP. In the general case the
// local IP would depend on the next hop of selected path. This approach will
// not work in more complicated setups where e.g. different network interfaces
// are used to talk to different AS interfaces.
//
// This is a simple workaround for not being able to use wildcard addresses
// with snet. Once a available, a wildcard address should be used instead and
// this should simply be removed.
func DefaultLocalIP(ctx context.Context, sdConn sciond.Connector) (net.IP, error) {
// Choose CS as default routing "target". Using any of the interfaces would also make sense.
csAddr, err := sciond.TopoQuerier{Connector: sdConn}.UnderlayAnycast(ctx, addr.SvcCS)
if err != nil {
return nil, err
}
return ResolveLocal(csAddr.IP)
}

// ResolveLocal returns the local IP address used for traffic destined to dst.
func ResolveLocal(dst net.IP) (net.IP, error) {
udpAddr := net.UDPAddr{IP: dst, Port: 1}
Expand Down
29 changes: 1 addition & 28 deletions go/pkg/showpaths/showpaths.go
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ func Run(ctx context.Context, dst addr.IA, cfg Config) (*Result, error) {
if !cfg.NoProbe {
// Resolve local IP in case it is not configured.
if localIP = cfg.Local; localIP == nil {
localIP, err = findDefaultLocalIP(ctx, sdConn)
localIP, err = addrutil.DefaultLocalIP(ctx, sdConn)
if err != nil {
return nil, serrors.WrapStr("failed to determine local IP", err)
}
Expand Down Expand Up @@ -206,30 +206,3 @@ func Run(ctx context.Context, dst addr.IA, cfg Config) (*Result, error) {
}
return res, nil
}

// TODO(matzf): this is a simple, hopefully temporary, workaround to not having
// wildcard addresses in snet.
// Here we just use a seemingly sensible default IP, but in the general case
// the local IP would depend on the next hop of selected path. This approach
// will not work in more complicated setups where e.g. different network
// interface are used to talk to different AS interfaces.
// Once a available, a wildcard address should be used and this should simply
// be removed.
//
// findDefaultLocalIP returns _a_ IP of this host in the local AS.
func findDefaultLocalIP(ctx context.Context, sciondConn sciond.Connector) (net.IP, error) {
hostInLocalAS, err := findAnyHostInLocalAS(ctx, sciondConn)
if err != nil {
return nil, err
}
return addrutil.ResolveLocal(hostInLocalAS)
}

// findAnyHostInLocalAS returns the IP address of some (infrastructure) host in the local AS.
func findAnyHostInLocalAS(ctx context.Context, sciondConn sciond.Connector) (net.IP, error) {
addr, err := sciond.TopoQuerier{Connector: sciondConn}.UnderlayAnycast(ctx, addr.SvcCS)
if err != nil {
return nil, err
}
return addr.IP, nil
}
1 change: 1 addition & 0 deletions go/posix-gateway/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ go_library(
"//go/lib/prom:go_default_library",
"//go/lib/sciond:go_default_library",
"//go/lib/serrors:go_default_library",
"//go/lib/snet/addrutil:go_default_library",
"//go/lib/sock/reliable:go_default_library",
"//go/pkg/command:go_default_library",
"//go/pkg/gateway:go_default_library",
Expand Down
7 changes: 7 additions & 0 deletions go/posix-gateway/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import (
"github.com/scionproto/scion/go/lib/prom"
"github.com/scionproto/scion/go/lib/sciond"
"github.com/scionproto/scion/go/lib/serrors"
"github.com/scionproto/scion/go/lib/snet/addrutil"
"github.com/scionproto/scion/go/lib/sock/reliable"
"github.com/scionproto/scion/go/pkg/command"
"github.com/scionproto/scion/go/pkg/gateway"
Expand Down Expand Up @@ -115,6 +116,12 @@ func run(file string) error {
if err != nil {
return serrors.WrapStr("parsing control address", err)
}
if len(controlAddress.IP) == 0 {
controlAddress.IP, err = addrutil.DefaultLocalIP(context.Background(), daemon)
if err != nil {
return serrors.WrapStr("determine default local IP", err)
}
}
dataAddress, err := net.ResolveUDPAddr("udp", cfg.Gateway.DataAddr)
if err != nil {
return serrors.WrapStr("parsing data address", err)
Expand Down
6 changes: 1 addition & 5 deletions go/scion-pki/certs/renew.go
Original file line number Diff line number Diff line change
Expand Up @@ -507,11 +507,7 @@ func findLocalAddr(ctx context.Context, sds sciond.Service) (*snet.UDPAddr, erro
if err != nil {
return nil, err
}
csAddr, err := sciond.TopoQuerier{Connector: sdConn}.UnderlayAnycast(ctx, addr.SvcCS)
if err != nil {
return nil, err
}
localIP, err := addrutil.ResolveLocal(csAddr.IP)
localIP, err := addrutil.DefaultLocalIP(ctx, sdConn)
if err != nil {
return nil, err
}
Expand Down