Documentation
¶
Overview ¶
Package vnet simulates a virtual Internet containing a set of networks with various NAT behaviors. You can then plug VMs into the virtual internet at different points to test Tailscale working end-to-end in various network conditions.
Index ¶
- Constants
- func FakeDNSIPv4() netip.Addr
- func FakeDNSIPv6() netip.Addr
- func FakeSyslogIPv4() netip.Addr
- func FakeSyslogIPv6() netip.Addr
- type Config
- type DialFunc
- type EthernetPacket
- type IPPool
- type MAC
- type NAT
- type NATTable
- type Network
- type NetworkService
- type Node
- type NodeAgentClient
- type NodeOption
- type Protocol
- type Server
- func (s *Server) Close()
- func (s *Server) HWAddr(mac MAC) net.HardwareAddr
- func (s *Server) MACs() iter.Seq[MAC]
- func (s *Server) NodeAgentClient(n *Node) *NodeAgentClient
- func (s *Server) NodeAgentDialer(n *Node) DialFunc
- func (s *Server) PopulateDERPMapIPs() error
- func (s *Server) RegisterSinkForTest(mac MAC, fn func(eth []byte))
- func (s *Server) RegisteredWritersForTest() int
- func (s *Server) ServeUnixConn(uc *net.UnixConn, proto Protocol)
- func (s *Server) SetLoggerForTest(logf func(format string, args ...any))
- func (s *Server) WriteStartingBanner(w io.Writer)
- type TailscaledEnv
- type UDPPacket
Constants ¶
const ( ProtocolQEMU = Protocol(iota + 1) ProtocolUnixDGRAM // for macOS Virtualization.Framework and VZFileHandleNetworkDeviceAttachment )
Variables ¶
This section is empty.
Functions ¶
func FakeDNSIPv4 ¶ added in v1.74.0
FakeDNSIPv4 returns the fake DNS IPv4 address.
func FakeDNSIPv6 ¶ added in v1.74.0
FakeDNSIPv6 returns the fake DNS IPv6 address.
func FakeSyslogIPv4 ¶ added in v1.74.0
FakeSyslogIPv4 returns the fake syslog IPv4 address.
func FakeSyslogIPv6 ¶ added in v1.74.0
FakeSyslogIPv6 returns the fake syslog IPv6 address.
Types ¶
type Config ¶
type Config struct {
// contains filtered or unexported fields
}
Config is the requested state of the natlab virtual network.
The zero value is a valid empty configuration. Call AddNode and AddNetwork to methods on the returned Node and Network values to modify the config before calling NewServer. Once the NewServer is called, Config is no longer used.
func (*Config) AddNetwork ¶
AddNetwork add a new network.
The opts may be of the following types:
- string IP address, for the network's WAN IP (if any)
- string netip.Prefix, for the network's LAN IP (defaults to 192.168.0.0/24) if IPv4, or its WAN IPv6 + CIDR (e.g. "2000:52::1/64")
- NAT, the type of NAT to use
- NetworkService, a service to add to the network
On an error or unknown opt type, AddNetwork returns a network with a carried error that gets returned later.
func (*Config) AddNode ¶
AddNode creates a new node in the world.
The opts may be of the following types:
- *Network: zero, one, or more networks to add this node to
- TODO: more
On an error or unknown opt type, AddNode returns a node with a carried error that gets returned later.
func (*Config) FirstNetwork ¶
FirstNetwork returns the first network in the config, or nil if none.
func (*Config) SetBlendReality ¶ added in v1.74.0
SetBlendReality sets whether to blend the real controlplane.tailscale.com and DERP servers into the virtual network. This is mostly useful for interactive testing when working on natlab.
func (*Config) SetPCAPFile ¶
SetPCAPFile sets the filename to write a pcap file to, or empty to disable pcap file writing.
type EthernetPacket ¶
type EthernetPacket struct {
// contains filtered or unexported fields
}
func (EthernetPacket) DstMAC ¶
func (ep EthernetPacket) DstMAC() MAC
func (EthernetPacket) SrcMAC ¶
func (ep EthernetPacket) SrcMAC() MAC
type IPPool ¶
type IPPool interface { // WANIP returns the primary WAN IP address. // // TODO: add another method for networks with multiple WAN IP addresses. WANIP() netip.Addr // SoleLanIP reports whether this network has a sole LAN client // and if so, its IP address. SoleLANIP() (_ netip.Addr, ok bool) // IsPublicPortUsed reports whether the provided WAN IP+port is in use by // anything. (In particular, the NAT-PMP/etc port mappers might have taken // a port.) Implementations should check this before allocating a port, // and then they should report IsPublicPortUsed themselves for that port. IsPublicPortUsed(netip.AddrPort) bool }
IPPool is the interface that a NAT implementation uses to get information about a network.
Outside of tests, this is typically a *network.
type MAC ¶
type MAC [6]byte
func (MAC) HWAddr ¶
func (m MAC) HWAddr() net.HardwareAddr
func (MAC) IsBroadcast ¶
func (MAC) IsIPv6Multicast ¶ added in v1.74.0
IsIPv6Multicast reports whether m is an IPv6 multicast MAC address, typically one containing a solicited-node multicast address.
type NAT ¶
type NAT string
NAT is a type of NAT that's known to natlab.
For example, "easy" for Linux-style NAT, "hard" for FreeBSD-style NAT, etc.
type NATTable ¶
type NATTable interface { // PickOutgoingSrc returns the source address to use for an outgoing packet. // // The result should either be invalid (to drop the packet) or a WAN (not // private) IP address. // // Typically, the src is a LAN source IP address, but it might also be a WAN // IP address if the packet is being forwarded for a source machine that has // a public IP address. PickOutgoingSrc(src, dst netip.AddrPort, at time.Time) (wanSrc netip.AddrPort) // PickIncomingDst returns the destination address to use for an incoming // packet. The incoming src address is always a public WAN IP. // // The result should either be invalid (to drop the packet) or the IP // address of a machine on the local network address, usually a private // LAN IP. PickIncomingDst(src, dst netip.AddrPort, at time.Time) (lanDst netip.AddrPort) // IsPublicPortUsed reports whether the provided WAN IP+port is in use by // anything. The port mapper uses this to avoid grabbing an in-use port. IsPublicPortUsed(netip.AddrPort) bool }
NATTable is what a NAT implementation is expected to do.
This project tests Tailscale as it faces various combinations various NAT implementations (e.g. Linux easy style NAT vs FreeBSD hard/endpoint dependent NAT vs Cloud 1:1 NAT, etc)
Implementations of NATTable need not handle concurrency; the natlab serializes all calls into a NATTable.
The provided `at` value will typically be time.Now, except for tests. Implementations should not use real time and should only compare previously provided time values.
type Network ¶
type Network struct {
// contains filtered or unexported fields
}
Network is the configuration of a network in the virtual network.
func (*Network) AddService ¶
func (n *Network) AddService(s NetworkService)
AddService adds a network service (such as port mapping protocols) to a network.
func (*Network) CanTakeMoreNodes ¶
func (*Network) SetBlackholedIPv4 ¶ added in v1.74.0
SetBlackholedIPv4 sets whether the network should blackhole all IPv4 traffic out to the Internet. (DHCP etc continues to work on the LAN.)
type NetworkService ¶
type NetworkService string
NetworkService is a service that can be added to a network.
const ( NATPMP NetworkService = "NAT-PMP" PCP NetworkService = "PCP" UPnP NetworkService = "UPnP" )
type Node ¶
type Node struct {
// contains filtered or unexported fields
}
Node is the configuration of a node in the virtual network.
func (*Node) Env ¶
func (n *Node) Env() []TailscaledEnv
func (*Node) HostFirewall ¶
func (*Node) IsV6Only ¶ added in v1.74.0
IsV6Only reports whether this node is only connected to IPv6 networks.
func (*Node) SetVerboseSyslog ¶
func (*Node) VerboseSyslog ¶
type NodeAgentClient ¶
type NodeAgentClient struct { *tailscale.LocalClient HTTPClient *http.Client }
func (*NodeAgentClient) EnableHostFirewall ¶
func (c *NodeAgentClient) EnableHostFirewall(ctx context.Context) error
EnableHostFirewall enables the host's stateful firewall.
type NodeOption ¶
type NodeOption string
NodeOption is an option that can be passed to Config.AddNode.
const ( HostFirewall NodeOption = "HostFirewall" VerboseSyslog NodeOption = "VerboseSyslog" )
type Server ¶
type Server struct {
// contains filtered or unexported fields
}
func (*Server) NodeAgentClient ¶
func (s *Server) NodeAgentClient(n *Node) *NodeAgentClient
func (*Server) NodeAgentDialer ¶
func (*Server) PopulateDERPMapIPs ¶
func (*Server) RegisterSinkForTest ¶ added in v1.74.0
func (*Server) RegisteredWritersForTest ¶ added in v1.74.0
RegisteredWritersForTest returns the number of registered connections (VM guests with a known MAC to whom a packet can be sent) there are to the server. It exists for testing.
func (*Server) ServeUnixConn ¶
Handles a single connection from a QEMU-style client or muxd connections for dgram mode
func (*Server) SetLoggerForTest ¶ added in v1.74.0
func (*Server) WriteStartingBanner ¶
type TailscaledEnv ¶
type TailscaledEnv struct {
Key, Value string
}
TailscaledEnv is а option that can be passed to Config.AddNode to set an environment variable for tailscaled.