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

Fix sig/mgmt/Addr #3386

Merged
merged 1 commit into from
Nov 15, 2019
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
20 changes: 15 additions & 5 deletions go/lib/hostinfo/hostinfo.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,16 @@ type Addrs struct {
IPv6 []byte `capnp:"ipv6"`
}

func FromHostAddr(host addr.HostAddr, port uint16) *Host {
h := &Host{Port: port}
if host.Type() == addr.HostTypeIPv4 {
h.Addrs.IPv4 = host.IP()
} else {
h.Addrs.IPv6 = host.IP()
}
return h
}

func FromUDPAddr(addr net.UDPAddr) Host {
if addr.IP.To4() != nil {
return Host{
Expand All @@ -53,7 +63,7 @@ func FromUDPAddr(addr net.UDPAddr) Host {
}
}

func (h *Host) host() addr.HostAddr {
func (h *Host) Host() addr.HostAddr {
if len(h.Addrs.IPv4) > 0 {
return addr.HostIPv4(h.Addrs.IPv4)
}
Expand All @@ -80,10 +90,10 @@ func (h *Host) UDP() *net.UDPAddr {
}

func (h *Host) Overlay() (*overlay.OverlayAddr, error) {
if h.host().IP() == nil {
return nil, common.NewBasicError("unsupported overlay L3 address", nil, "addr", h.host())
if h.Host().IP() == nil {
return nil, common.NewBasicError("unsupported overlay L3 address", nil, "addr", h.Host())
}
ip := h.host().IP()
ip := h.Host().IP()
return overlay.NewOverlayAddr(append(ip[:0:0], ip...), h.Port), nil
}

Expand All @@ -98,7 +108,7 @@ func (h *Host) Copy() *Host {
}

func (h *Host) String() string {
return fmt.Sprintf("[%v]:%d", h.host(), h.Port)
return fmt.Sprintf("[%v]:%d", h.Host(), h.Port)
}

func copyIP(ip net.IP) net.IP {
Expand Down
2 changes: 1 addition & 1 deletion go/sig/egress/session/sessmon.go
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,7 @@ func (sm *sessMonitor) handleRep(rpld *disp.RegPld) {
// Update sessmon's remote.
sm.smRemote.Sig = &siginfo.Sig{
IA: sm.smRemote.Sig.IA,
Host: addr.HostFromIP(pollRep.Addr.Ctrl.IP),
Host: pollRep.Addr.Ctrl.Host(),
CtrlL4Port: int(pollRep.Addr.Ctrl.Port),
EncapL4Port: int(pollRep.Addr.EncapPort),
}
Expand Down
2 changes: 1 addition & 1 deletion go/sig/internal/base/pollhdlr.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ func PollReqHdlr() {
}
sigCtrlAddr := &snet.Addr{
IA: rpld.Addr.IA,
Host: addr.AppAddrFromUDP(req.Addr.Ctrl),
Host: addr.AppAddrFromUDP(req.Addr.Ctrl.UDP()),
Path: rpld.Addr.Path,
NextHop: rpld.Addr.NextHop.Copy(),
}
Expand Down
1 change: 1 addition & 0 deletions go/sig/mgmt/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ go_library(
deps = [
"//go/lib/addr:go_default_library",
"//go/lib/common:go_default_library",
"//go/lib/hostinfo:go_default_library",
"//go/proto:go_default_library",
],
)
8 changes: 4 additions & 4 deletions go/sig/mgmt/addr.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,23 +17,23 @@ package mgmt

import (
"fmt"
"net"

"github.com/scionproto/scion/go/lib/addr"
"github.com/scionproto/scion/go/lib/common"
"github.com/scionproto/scion/go/lib/hostinfo"
"github.com/scionproto/scion/go/proto"
)

var _ proto.Cerealizable = (*Addr)(nil)

type Addr struct {
Ctrl *net.UDPAddr
Ctrl *hostinfo.Host
EncapPort uint16
}

func NewAddr(host addr.HostAddr, ctrlPort, encapPort uint16) *Addr {
return &Addr{
Ctrl: &net.UDPAddr{IP: host.IP(), Port: int(ctrlPort)},
Ctrl: hostinfo.FromHostAddr(host, ctrlPort),
EncapPort: encapPort,
}
}
Expand All @@ -53,5 +53,5 @@ func (a *Addr) Write(b common.RawBytes) (int, error) {

func (a *Addr) String() string {
return fmt.Sprintf("Host: %s CtrlPort: %d EncapPort: %d",
a.Ctrl.IP, a.Ctrl.Port, a.EncapPort)
a.Ctrl.Host(), a.Ctrl.Port, a.EncapPort)
}