cmd/tailscaled: move cleanup to an implicit action during startup

This removes a potentially increased boot delay for certain boot
topologies where they block on ExecStartPre that may have socket
activation dependencies on other system services (such as
systemd-resolved and NetworkManager).

Also rename cleanup to clean up in affected/immediately nearby places
per code review commentary.

Fixes #11599

Signed-off-by: James Tucker <james@tailscale.com>
This commit is contained in:
James Tucker
2024-04-02 19:52:19 -07:00
committed by James Tucker
parent 8d83adde07
commit db760d0bac
11 changed files with 31 additions and 28 deletions

View File

@@ -49,11 +49,11 @@ func New(logf logger.Logf, tundev tun.Device, netMon *netmon.Monitor) (Router, e
return newUserspaceRouter(logf, tundev, netMon)
}
// Cleanup restores the system network configuration to its original state
// CleanUp restores the system network configuration to its original state
// in case the Tailscale daemon terminated without closing the router.
// No other state needs to be instantiated before this runs.
func Cleanup(logf logger.Logf, interfaceName string) {
cleanup(logf, interfaceName)
func CleanUp(logf logger.Logf, interfaceName string) {
cleanUp(logf, interfaceName)
}
// Config is the subset of Tailscale configuration that is relevant to

View File

@@ -13,6 +13,6 @@ func newUserspaceRouter(logf logger.Logf, tundev tun.Device, netMon *netmon.Moni
return newUserspaceBSDRouter(logf, tundev, netMon)
}
func cleanup(logger.Logf, string) {
func cleanUp(logger.Logf, string) {
// Nothing to do.
}

View File

@@ -18,6 +18,6 @@ func newUserspaceRouter(logf logger.Logf, tunDev tun.Device, netMon *netmon.Moni
return nil, fmt.Errorf("unsupported OS %q", runtime.GOOS)
}
func cleanup(logf logger.Logf, interfaceName string) {
func cleanUp(logf logger.Logf, interfaceName string) {
// Nothing to do here.
}

View File

@@ -18,7 +18,7 @@ func newUserspaceRouter(logf logger.Logf, tundev tun.Device, netMon *netmon.Moni
return newUserspaceBSDRouter(logf, tundev, netMon)
}
func cleanup(logf logger.Logf, interfaceName string) {
func cleanUp(logf logger.Logf, interfaceName string) {
// If the interface was left behind, ifconfig down will not remove it.
// In fact, this will leave a system in a tainted state where starting tailscaled
// will result in "interface tailscale0 already exists"

View File

@@ -1396,12 +1396,12 @@ func normalizeCIDR(cidr netip.Prefix) string {
return cidr.Masked().String()
}
// cleanup removes all the rules and routes that were added by the linux router.
// The function calls cleanup for both iptables and nftables since which ever
// netfilter runner is used, the cleanup function for the other one doesn't do anything.
func cleanup(logf logger.Logf, interfaceName string) {
// cleanUp removes all the rules and routes that were added by the linux router.
// The function calls cleanUp for both iptables and nftables since which ever
// netfilter runner is used, the cleanUp function for the other one doesn't do anything.
func cleanUp(logf logger.Logf, interfaceName string) {
if interfaceName != "userspace-networking" {
linuxfw.IPTablesCleanup(logf)
linuxfw.IPTablesCleanUp(logf)
linuxfw.NfTablesCleanUp(logf)
}
}

View File

@@ -236,11 +236,11 @@ func (r *openbsdRouter) UpdateMagicsockPort(_ uint16, _ string) error {
}
func (r *openbsdRouter) Close() error {
cleanup(r.logf, r.tunname)
cleanUp(r.logf, r.tunname)
return nil
}
func cleanup(logf logger.Logf, interfaceName string) {
func cleanUp(logf logger.Logf, interfaceName string) {
out, err := cmd("ifconfig", interfaceName, "down").CombinedOutput()
if err != nil {
logf("ifconfig down: %v\n%s", err, out)

View File

@@ -120,7 +120,7 @@ func (r *winRouter) Close() error {
return nil
}
func cleanup(logf logger.Logf, interfaceName string) {
func cleanUp(logf logger.Logf, interfaceName string) {
// Nothing to do here.
}