Skip to content

Commit

Permalink
Fix sig/mgmt/Addr (#3386)
Browse files Browse the repository at this point in the history
We can't use UDPAddr on the wire format, instead use hostinfo again.

Fixes tests broken by  #3370
  • Loading branch information
lukedirtwalker authored Nov 15, 2019
1 parent ae70453 commit 9a26911
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 11 deletions.
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)
}

0 comments on commit 9a26911

Please sign in to comment.