These are needed to support vxlan encapsulation. In a vxlan packet, the only place we can straightforwardly hold the source and destination peers identifiers used by the weave router is in the 24-bit VNI (vxlan network identifier) field. This gives us 12 bits to indicate a peer. The resulting limit of 4096 peers on a weave network does not seem like a problem in the near future. But it does mean that decentralized allocation makes collisions fairly likely even in weave networks of sizes that are common today. Fortunately, the problem is much more tractable than IPAM because we can detect when collisions occur and take action to resolve them. TODO: We already notify the InterHost when a short id -> peer mapping changes, but we also need to flush any entries in the router MAC cache that might be affected.
91 lines
2.2 KiB
Go
91 lines
2.2 KiB
Go
package router
|
|
|
|
import (
|
|
"net"
|
|
)
|
|
|
|
// Interface to inter-host (i.e. overlay network) packet handling
|
|
type InterHost interface {
|
|
// Start consuming forwarded packets.
|
|
ConsumePackets(*Peer, *Peers, InterHostConsumer) error
|
|
|
|
// The routes have changed, so any cached information should
|
|
// be discarded.
|
|
InvalidateRoutes()
|
|
|
|
// A mapping of a short id to a peer has changed
|
|
InvalidateShortIDs()
|
|
|
|
// Form a packet-forwarding connection. The remote UDPAddr
|
|
// can be nil if unknown (in which case the implementation
|
|
// needs to discover it).
|
|
MakeForwarder(remotePeer *Peer, localIP net.IP, remote *net.UDPAddr,
|
|
connUID uint64, crypto InterHostCrypto,
|
|
sendControlMessage func([]byte) error) (InterHostForwarder, error)
|
|
}
|
|
|
|
// When a consumer is called, the decoder will already have been used
|
|
// to decode the frame.
|
|
type InterHostConsumer func(ForwardPacketKey) FlowOp
|
|
|
|
// Crypto settings for a forwarder.
|
|
type InterHostCrypto struct {
|
|
Dec Decryptor
|
|
Enc Encryptor
|
|
EncDF Encryptor
|
|
}
|
|
|
|
// All of the machinery to forward packets to a particular peer
|
|
type InterHostForwarder interface {
|
|
// Register a callback for forwarder state changes.
|
|
// side-effect, calling this confirms that the connection is
|
|
// really wanted, and so the provider should activate it.
|
|
// However, Forward might be called before this is called
|
|
// (e.g. on another thread).
|
|
SetListener(InterHostForwarderListener)
|
|
|
|
// Forward a packet across the connection.
|
|
Forward(ForwardPacketKey) FlowOp
|
|
|
|
Close()
|
|
|
|
// Handle a message from the peer
|
|
ControlMessage([]byte)
|
|
}
|
|
|
|
type InterHostForwarderListener interface {
|
|
Established()
|
|
Error(error)
|
|
}
|
|
|
|
type NullInterHost struct{}
|
|
|
|
func (NullInterHost) ConsumeInterHostPackets(*Peer, *Peers,
|
|
InterHostConsumer) error {
|
|
return nil
|
|
}
|
|
|
|
func (NullInterHost) InvalidateRoutes() {
|
|
}
|
|
|
|
func (NullInterHost) InvalidateShortIDs() {
|
|
}
|
|
|
|
func (NullInterHost) MakeForwarder(*Peer, net.IP, *net.UDPAddr, uint64,
|
|
InterHostCrypto, func([]byte) error) (InterHostForwarder, error) {
|
|
return NullInterHost{}, nil
|
|
}
|
|
|
|
func (NullInterHost) SetListener(InterHostForwarderListener) {
|
|
}
|
|
|
|
func (NullInterHost) Forward(ForwardPacketKey) FlowOp {
|
|
return nil
|
|
}
|
|
|
|
func (NullInterHost) Close() {
|
|
}
|
|
|
|
func (NullInterHost) ControlMessage([]byte) {
|
|
}
|