Documentation
¶
Overview ¶
Package netutil sets up the Linux networking for endpoints: veth pairs, routing and NAT.
Index ¶
- Constants
- func CleanupAllNAT() error
- func CleanupNAT(vethHost string) error
- func CleanupTailnetBlackhole(nsPath string) error
- func CreateVethPair(baseName string, mtu int) (string, string, error)
- func DeleteVeth(name string) error
- func ListenInNetNS(nsPath, addr string) (net.Listener, error)
- func MoveToNetNS(ifName string, nsPath string) error
- func RemoveHostIsolation() error
- func SetupBypassRoute(nsPath, ifName, gatewayIP string) error
- func SetupContainerRouting(nsPath string, ifName string, containerIP string, gatewayIP string) error
- func SetupHostIsolation(bridges []string) error
- func SetupHostRouting(vethHost string, hostIP string) error
- func SetupInterfaceInNS(nsPath string, ifName string, newName string) error
- func SetupNAT(vethHost string) error
- func SetupTailnetBlackhole(nsPath string) error
- func SetupVethIsolation(port int) error
- func UsedVethSubnets() (map[netip.Prefix]bool, error)
- func VethIPv4(name string) (string, error)
Constants ¶
const DefaultMTU = 1500
DefaultMTU is the veth MTU when the network sets none.
Variables ¶
This section is empty.
Functions ¶
func CleanupAllNAT ¶
func CleanupAllNAT() error
CleanupAllNAT removes the entire custom chain and all its rules. This is useful for complete plugin cleanup.
func CleanupNAT ¶
CleanupNAT removes the FORWARD rules for a specific veth interface. The global MASQUERADE rule and chain structure are intentionally left in place.
func CleanupTailnetBlackhole ¶
CleanupTailnetBlackhole removes the routes added by SetupTailnetBlackhole. A namespace or route that is already gone is not an error.
Note that a container that stays attached to another network regains a path to the tailnet ranges through the host once these routes are removed.
func CreateVethPair ¶
CreateVethPair creates a veth pair with the given base name and MTU (0 for DefaultMTU). Returns the host-side name and container-side name.
func ListenInNetNS ¶
ListenInNetNS opens a TCP listener on addr in the network namespace at nsPath. The socket belongs to the namespace it was created in, so it keeps listening there after the thread returns to the plugin's namespace, and only that namespace's processes reach a loopback address.
func MoveToNetNS ¶
MoveToNetNS moves a network interface to the specified network namespace.
func RemoveHostIsolation ¶
func RemoveHostIsolation() error
RemoveHostIsolation removes the host's tailnet isolation, and tolerates its absence.
func SetupBypassRoute ¶
SetupBypassRoute sends tailscaled's own traffic through the tslink veth, whatever the container's default route. A task on an overlay network defaults via docker_gwbridge, and Docker may detach that network before tslink's: tailscaled would then lose the control plane before it can log out, and the device would linger.
func SetupContainerRouting ¶
func SetupContainerRouting( nsPath string, ifName string, containerIP string, gatewayIP string, ) error
SetupContainerRouting sets up routing inside the container namespace.
func SetupHostIsolation ¶
SetupHostIsolation installs the host's tailnet isolation, or restores it: rules another program removed, and jumps it pushed down. bridges are the interface names of Docker's bridge networks, which containerInterfaces may not match. It changes nothing that is in place, so it can run periodically.
func SetupHostRouting ¶
SetupHostRouting sets up routing on the host side for internet access.
func SetupInterfaceInNS ¶
SetupInterfaceInNS sets up an interface inside a network namespace.
func SetupNAT ¶
SetupNAT sets up MASQUERADE for traffic from the container. Uses a custom chain (TS-CNI-FORWARD) for organized rule management.
func SetupTailnetBlackhole ¶
SetupTailnetBlackhole installs unreachable routes for the tailnet ranges in the main table of the container namespace. tailscaled's policy rules consult table 52 first, so peers it can reach still route via tailscale0.
The IPv4 route is mandatory. The IPv6 route may fail when IPv6 is disabled in the namespace; that is accepted only if the namespace has no route to the IPv6 range anyway.
func SetupVethIsolation ¶
SetupVethIsolation installs the veth isolation, or restores it, letting only replies and UDP to port from tslink's veths through to them. IPv4 only: the veths have no other addresses than link-local IPv6 ones. It changes nothing that is in place, so it can run periodically.
func UsedVethSubnets ¶
UsedVethSubnets returns the /30 subnets in tslink's veth range that links of the current network namespace have addresses in.
Types ¶
This section is empty.