LocalConnection shouldn't have to know about remote UDP address
...and generally know less about how overlays establish connectivity.
This commit is contained in:
1 parent
e7ff6a2191
commit
18fe553d23
5 files changed
+32
-23
No files matched your search
@@ -190,16 +190,11 @@ func (conn *LocalConnection) run(actionChan <-chan ConnectionAction, finished ch
|
|||||||
|
|
||||||
conn.Log("connection ready; using protocol version", conn.version)
|
conn.Log("connection ready; using protocol version", conn.version)
|
||||||
|
|
||||||
var remoteAddr *net.UDPAddr
|
|
||||||
if conn.outbound {
|
|
||||||
tcpAddr := conn.TCPConn.RemoteAddr().(*net.TCPAddr)
|
|
||||||
remoteAddr = &net.UDPAddr{IP: tcpAddr.IP, Port: tcpAddr.Port, Zone: tcpAddr.Zone}
|
|
||||||
}
|
|
||||||
|
|
||||||
params := ForwarderParams{
|
params := ForwarderParams{
|
||||||
RemotePeer: conn.remote,
|
RemotePeer: conn.remote,
|
||||||
LocalIP: conn.TCPConn.LocalAddr().(*net.TCPAddr).IP,
|
LocalAddr: conn.TCPConn.LocalAddr().(*net.TCPAddr),
|
||||||
RemoteAddr: remoteAddr,
|
RemoteAddr: conn.TCPConn.RemoteAddr().(*net.TCPAddr),
|
||||||
|
Outbound: conn.outbound,
|
||||||
ConnUID: conn.uid,
|
ConnUID: conn.uid,
|
||||||
Crypto: conn.forwarderCrypto(),
|
Crypto: conn.forwarderCrypto(),
|
||||||
SendControlMessage: conn.sendOverlayControlMessage,
|
SendControlMessage: conn.sendOverlayControlMessage,
|
||||||
|
|||||||
+6
-5
@@ -523,15 +523,16 @@ func (fastdp fastDatapathOverlay) MakeForwarder(params ForwarderParams) (Overlay
|
|||||||
}
|
}
|
||||||
|
|
||||||
vxlanVportID := fastdp.mainVxlanVportID
|
vxlanVportID := fastdp.mainVxlanVportID
|
||||||
remoteAddr := params.RemoteAddr
|
var remoteAddr *net.UDPAddr
|
||||||
if remoteAddr != nil {
|
|
||||||
|
if params.Outbound {
|
||||||
|
remoteAddr = makeUDPAddr(params.RemoteAddr)
|
||||||
// The provided address contains the main weave port
|
// The provided address contains the main weave port
|
||||||
// number to connect to. We need to derive the vxlan
|
// number to connect to. We need to derive the vxlan
|
||||||
// port number from that.
|
// port number from that.
|
||||||
vxlanRemoteAddr := *params.RemoteAddr
|
vxlanRemoteAddr := *remoteAddr
|
||||||
vxlanRemoteAddr.Port++
|
vxlanRemoteAddr.Port++
|
||||||
remoteAddr = &vxlanRemoteAddr
|
remoteAddr = &vxlanRemoteAddr
|
||||||
|
|
||||||
var err error
|
var err error
|
||||||
vxlanVportID, err = fastdp.getVxlanVportID(remoteAddr.Port)
|
vxlanVportID, err = fastdp.getVxlanVportID(remoteAddr.Port)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -539,7 +540,7 @@ func (fastdp fastDatapathOverlay) MakeForwarder(params ForwarderParams) (Overlay
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
localIP, err := ipv4Bytes(params.LocalIP)
|
localIP, err := ipv4Bytes(params.LocalAddr.IP)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|||||||
+12
-8
@@ -29,15 +29,19 @@ type Overlay interface {
|
|||||||
type ForwarderParams struct {
|
type ForwarderParams struct {
|
||||||
RemotePeer *Peer
|
RemotePeer *Peer
|
||||||
|
|
||||||
// The local IP address to use for sending. Derived from the
|
// The local address of the corresponding TCP connection. Used to
|
||||||
// local address of the corresponding TCP socket, so may
|
// derive the local IP address for sending. May differ for
|
||||||
// differ for different forwarders.
|
// different forwarders.
|
||||||
LocalIP net.IP
|
LocalAddr *net.TCPAddr
|
||||||
|
|
||||||
// The remote address to send to. nil if unknown, i.e. an
|
// The remote address of the corresponding TCP connection. Used to
|
||||||
// incoming connection, in which case the Overlay needs to
|
// determine the address to send to, but only if the TCP
|
||||||
// discover it (e.g. from incoming datagrams).
|
// connection is outbound. Otherwise the Overlay needs to discover
|
||||||
RemoteAddr *net.UDPAddr
|
// it (e.g. from incoming datagrams).
|
||||||
|
RemoteAddr *net.TCPAddr
|
||||||
|
|
||||||
|
// Is the corresponding TCP connection outbound?
|
||||||
|
Outbound bool
|
||||||
|
|
||||||
// Unique identifier for this connection
|
// Unique identifier for this connection
|
||||||
ConnUID uint64
|
ConnUID uint64
|
||||||
|
|||||||
+7
-2
@@ -365,6 +365,11 @@ func (sleeve *SleeveOverlay) MakeForwarder(params ForwarderParams) (OverlayForwa
|
|||||||
confirmedChan := make(chan struct{})
|
confirmedChan := make(chan struct{})
|
||||||
finishedChan := make(chan struct{})
|
finishedChan := make(chan struct{})
|
||||||
|
|
||||||
|
var remoteAddr *net.UDPAddr
|
||||||
|
if params.Outbound {
|
||||||
|
remoteAddr = makeUDPAddr(params.RemoteAddr)
|
||||||
|
}
|
||||||
|
|
||||||
fwd := &sleeveForwarder{
|
fwd := &sleeveForwarder{
|
||||||
sleeve: sleeve,
|
sleeve: sleeve,
|
||||||
remotePeer: params.RemotePeer,
|
remotePeer: params.RemotePeer,
|
||||||
@@ -379,13 +384,13 @@ func (sleeve *SleeveOverlay) MakeForwarder(params ForwarderParams) (OverlayForwa
|
|||||||
finishedChan: finishedChan,
|
finishedChan: finishedChan,
|
||||||
establishedChan: make(chan struct{}),
|
establishedChan: make(chan struct{}),
|
||||||
errorChan: make(chan error, 1),
|
errorChan: make(chan error, 1),
|
||||||
remoteAddr: params.RemoteAddr,
|
remoteAddr: remoteAddr,
|
||||||
mtu: DefaultMTU,
|
mtu: DefaultMTU,
|
||||||
crypto: crypto,
|
crypto: crypto,
|
||||||
maxPayload: DefaultMTU - UDPOverhead,
|
maxPayload: DefaultMTU - UDPOverhead,
|
||||||
overheadDF: UDPOverhead + crypto.EncDF.PacketOverhead() +
|
overheadDF: UDPOverhead + crypto.EncDF.PacketOverhead() +
|
||||||
crypto.EncDF.FrameOverhead() + EthernetOverhead,
|
crypto.EncDF.FrameOverhead() + EthernetOverhead,
|
||||||
senderDF: newUDPSenderDF(params.LocalIP, sleeve.localPort),
|
senderDF: newUDPSenderDF(params.LocalAddr.IP, sleeve.localPort),
|
||||||
}
|
}
|
||||||
|
|
||||||
go fwd.run(aggChan, aggDFChan, specialChan, controlMsgChan,
|
go fwd.run(aggChan, aggDFChan, specialChan, controlMsgChan,
|
||||||
|
|||||||
@@ -104,6 +104,10 @@ func intmac(key uint64) (r net.HardwareAddr) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func makeUDPAddr(addr *net.TCPAddr) *net.UDPAddr {
|
||||||
|
return &net.UDPAddr{IP: addr.IP, Port: addr.Port, Zone: addr.Zone}
|
||||||
|
}
|
||||||
|
|
||||||
type ListOfPeers []*Peer
|
type ListOfPeers []*Peer
|
||||||
|
|
||||||
func (lop ListOfPeers) Len() int {
|
func (lop ListOfPeers) Len() int {
|
||||||
|
|||||||
Reference in new issue
Block a user