all: add ts_omit_serve, start making tailscale serve/funnel be modular

tailscaled tailscale combined (linux/amd64)
     29853147  17384418  31412596 omitting everything
    +  621570 +  219277 +  554256 .. add serve

Updates #17128

Change-Id: I87c2c6c3d3fc2dc026c3de8ef7000a813b41d31c
Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
This commit is contained in:
Brad Fitzpatrick
2025-09-13 20:20:08 -07:00
committed by Brad Fitzpatrick
parent 5b5ae2b2ee
commit 4cca9f7c67
21 changed files with 651 additions and 491 deletions

View File

@@ -798,6 +798,7 @@ tailscale.com/cmd/k8s-operator dependencies: (generated by github.com/tailscale/
tailscale.com/envknob from tailscale.com/client/local+
tailscale.com/envknob/featureknob from tailscale.com/client/web+
tailscale.com/feature from tailscale.com/ipn/ipnext+
tailscale.com/feature/buildfeatures from tailscale.com/ipn/ipnlocal+
tailscale.com/feature/syspolicy from tailscale.com/logpolicy
tailscale.com/health from tailscale.com/control/controlclient+
tailscale.com/health/healthmsg from tailscale.com/ipn/ipnlocal+

View File

@@ -213,6 +213,8 @@ var (
maybeWebCmd,
maybeDriveCmd,
maybeNetlockCmd,
maybeFunnelCmd,
maybeServeCmd,
_ func() *ffcli.Command
)
@@ -254,8 +256,8 @@ change in the future.
pingCmd,
ncCmd,
sshCmd,
funnelCmd(),
serveCmd(),
nilOrCall(maybeFunnelCmd),
nilOrCall(maybeServeCmd),
versionCmd,
nilOrCall(maybeWebCmd),
nilOrCall(fileCmd),

View File

@@ -1,6 +1,8 @@
// Copyright (c) Tailscale Inc & AUTHORS
// SPDX-License-Identifier: BSD-3-Clause
//go:build !ts_omit_serve
package cli
import (
@@ -16,6 +18,10 @@ import (
"tailscale.com/tailcfg"
)
func init() {
maybeFunnelCmd = funnelCmd
}
var funnelCmd = func() *ffcli.Command {
se := &serveEnv{lc: &localClient}
// previously used to serve legacy newFunnelCommand unless useWIPCode is true
@@ -174,3 +180,42 @@ func printFunnelWarning(sc *ipn.ServeConfig) {
fmt.Fprintf(Stderr, " run: `tailscale serve --help` to see how to configure handlers\n")
}
}
func init() {
hookPrintFunnelStatus.Set(printFunnelStatus)
}
// printFunnelStatus prints the status of the funnel, if it's running.
// It prints nothing if the funnel is not running.
func printFunnelStatus(ctx context.Context) {
sc, err := localClient.GetServeConfig(ctx)
if err != nil {
outln()
printf("# Funnel:\n")
printf("# - Unable to get Funnel status: %v\n", err)
return
}
if !sc.IsFunnelOn() {
return
}
outln()
printf("# Funnel on:\n")
for hp, on := range sc.AllowFunnel {
if !on { // if present, should be on
continue
}
sni, portStr, _ := net.SplitHostPort(string(hp))
p, _ := strconv.ParseUint(portStr, 10, 16)
isTCP := sc.IsTCPForwardingOnPort(uint16(p), noService)
url := "https://"
if isTCP {
url = "tcp://"
}
url += sni
if isTCP || p != 443 {
url += ":" + portStr
}
printf("# - %s\n", url)
}
outln()
}

View File

@@ -1,6 +1,8 @@
// Copyright (c) Tailscale Inc & AUTHORS
// SPDX-License-Identifier: BSD-3-Clause
//go:build !ts_omit_serve
package cli
import (
@@ -31,6 +33,10 @@ import (
"tailscale.com/version"
)
func init() {
maybeServeCmd = serveCmd
}
var serveCmd = func() *ffcli.Command {
se := &serveEnv{lc: &localClient}
// previously used to serve legacy newFunnelCommand unless useWIPCode is true

View File

@@ -1,6 +1,8 @@
// Copyright (c) Tailscale Inc & AUTHORS
// SPDX-License-Identifier: BSD-3-Clause
//go:build !ts_omit_serve
package cli
import (

View File

@@ -15,12 +15,12 @@ import (
"net/http"
"net/netip"
"os"
"strconv"
"strings"
"github.com/peterbourgon/ff/v3/ffcli"
"github.com/toqueteos/webbrowser"
"golang.org/x/net/idna"
"tailscale.com/feature"
"tailscale.com/ipn"
"tailscale.com/ipn/ipnstate"
"tailscale.com/net/netmon"
@@ -238,44 +238,13 @@ func runStatus(ctx context.Context, args []string) error {
outln()
printHealth()
}
printFunnelStatus(ctx)
if f, ok := hookPrintFunnelStatus.GetOk(); ok {
f(ctx)
}
return nil
}
// printFunnelStatus prints the status of the funnel, if it's running.
// It prints nothing if the funnel is not running.
func printFunnelStatus(ctx context.Context) {
sc, err := localClient.GetServeConfig(ctx)
if err != nil {
outln()
printf("# Funnel:\n")
printf("# - Unable to get Funnel status: %v\n", err)
return
}
if !sc.IsFunnelOn() {
return
}
outln()
printf("# Funnel on:\n")
for hp, on := range sc.AllowFunnel {
if !on { // if present, should be on
continue
}
sni, portStr, _ := net.SplitHostPort(string(hp))
p, _ := strconv.ParseUint(portStr, 10, 16)
isTCP := sc.IsTCPForwardingOnPort(uint16(p), noService)
url := "https://"
if isTCP {
url = "tcp://"
}
url += sni
if isTCP || p != 443 {
url += ":" + portStr
}
printf("# - %s\n", url)
}
outln()
}
var hookPrintFunnelStatus feature.Hook[func(context.Context)]
// isRunningOrStarting reports whether st is in state Running or Starting.
// It also returns a description of the status suitable to display to a user.

View File

@@ -104,7 +104,7 @@ tailscale.com/cmd/tailscale dependencies: (generated by github.com/tailscale/dep
tailscale.com/drive from tailscale.com/client/local+
tailscale.com/envknob from tailscale.com/client/local+
tailscale.com/envknob/featureknob from tailscale.com/client/web
tailscale.com/feature from tailscale.com/tsweb
tailscale.com/feature from tailscale.com/tsweb+
tailscale.com/feature/capture/dissector from tailscale.com/cmd/tailscale/cli
tailscale.com/feature/syspolicy from tailscale.com/cmd/tailscale/cli
tailscale.com/health from tailscale.com/net/tlsdial+

View File

@@ -272,6 +272,7 @@ tailscale.com/cmd/tailscaled dependencies: (generated by github.com/tailscale/de
tailscale.com/envknob from tailscale.com/client/local+
tailscale.com/envknob/featureknob from tailscale.com/client/web+
tailscale.com/feature from tailscale.com/feature/wakeonlan+
tailscale.com/feature/buildfeatures from tailscale.com/ipn/ipnlocal+
tailscale.com/feature/capture from tailscale.com/feature/condregister
tailscale.com/feature/condregister from tailscale.com/cmd/tailscaled
tailscale.com/feature/drive from tailscale.com/feature/condregister

View File

@@ -239,6 +239,7 @@ tailscale.com/cmd/tsidp dependencies: (generated by github.com/tailscale/depawar
tailscale.com/envknob from tailscale.com/client/local+
tailscale.com/envknob/featureknob from tailscale.com/client/web+
tailscale.com/feature from tailscale.com/ipn/ipnext+
tailscale.com/feature/buildfeatures from tailscale.com/ipn/ipnlocal+
tailscale.com/feature/syspolicy from tailscale.com/logpolicy
tailscale.com/health from tailscale.com/control/controlclient+
tailscale.com/health/healthmsg from tailscale.com/ipn/ipnlocal+