cmd/tailscale/cli: adjust parameter order and update output message

This commit updates the parameter order for IsTCPForwardingOnPort and SetWebHandler.
Also updated the message msgServiceIPNotAssigned to msgServiceWaitingApproval to adapt to
latest terminologies around services.

Signed-off-by: KevinLiang10 <37811973+KevinLiang10@users.noreply.github.com>
This commit is contained in:
KevinLiang10 2025-06-26 17:07:51 -04:00
parent d40755be85
commit 71fe9a9860
7 changed files with 26 additions and 29 deletions

View File

@ -358,16 +358,12 @@ func (e *serveEnv) handleWebServe(ctx context.Context, srvPort uint16, useTLS bo
if err != nil { if err != nil {
return err return err
} }
if sc.IsTCPForwardingOnPort(srvPort, dnsName) { if sc.IsTCPForwardingOnPort(dnsName, srvPort) {
fmt.Fprintf(Stderr, "error: cannot serve web; already serving TCP\n") fmt.Fprintf(Stderr, "error: cannot serve web; already serving TCP\n")
return errHelp return errHelp
} }
st, err := e.getLocalClientStatusWithoutPeers(ctx) sc.SetWebHandler(h, dnsName, srvPort, mount, useTLS, nil)
if err != nil {
return fmt.Errorf("getting client status: %w", err)
}
sc.SetWebHandler(st, h, dnsName, srvPort, mount, useTLS)
if !reflect.DeepEqual(cursc, sc) { if !reflect.DeepEqual(cursc, sc) {
if err := e.lc.SetServeConfig(ctx, sc); err != nil { if err := e.lc.SetServeConfig(ctx, sc); err != nil {
@ -419,7 +415,7 @@ func (e *serveEnv) handleWebServeRemove(ctx context.Context, srvPort uint16, mou
if err != nil { if err != nil {
return err return err
} }
if sc.IsTCPForwardingOnPort(srvPort, dnsName) { if sc.IsTCPForwardingOnPort(dnsName, srvPort) {
return errors.New("cannot remove web handler; currently serving TCP") return errors.New("cannot remove web handler; currently serving TCP")
} }
hp := ipn.HostPort(net.JoinHostPort(dnsName, strconv.Itoa(int(srvPort)))) hp := ipn.HostPort(net.JoinHostPort(dnsName, strconv.Itoa(int(srvPort))))

View File

@ -527,16 +527,16 @@ func (e *serveEnv) setServe(sc *ipn.ServeConfig, st *ipnstate.Status, dnsName st
} }
var ( var (
msgFunnelAvailable = "Available on the internet:" msgFunnelAvailable = "Available on the internet:"
msgServeAvailable = "Available within your tailnet:" msgServeAvailable = "Available within your tailnet:"
msgServiceIPNotAssigned = "This service %s is being served by this machine, but is not approved to have VIPs assigned yet. Once approved, it will be available in your Tailnet as:" msgServiceWaitingApproval = "This machine is configured as a service proxy for %s, but approval from an admin is required. Once approved, it will be available in your Tailnet as:"
msgRunningInBackground = "%s started and running in the background." msgRunningInBackground = "%s started and running in the background."
msgRunningTunService = "IPv4 and IPv6 traffic to %s is being routed to your operating system." msgRunningTunService = "IPv4 and IPv6 traffic to %s is being routed to your operating system."
msgDisableProxy = "To disable the proxy, run: tailscale %s --%s=%d off" msgDisableProxy = "To disable the proxy, run: tailscale %s --%s=%d off"
msgDisableServiceProxy = "To disable the proxy, run: tailscale serve --service=%s --%s=%d off" msgDisableServiceProxy = "To disable the proxy, run: tailscale serve --service=%s --%s=%d off"
msgDisableServiceTun = "To disable the service in TUN mode, run: tailscale serve --service=%s --tun off" msgDisableServiceTun = "To disable the service in TUN mode, run: tailscale serve --service=%s --tun off"
msgDisableService = "To remove config for the service, run: tailscale serve clear --service=%s" msgDisableService = "To remove config for the service, run: tailscale serve clear --service=%s"
msgToExit = "Press Ctrl+C to exit." msgToExit = "Press Ctrl+C to exit."
) )
// messageForPort returns a message for the given port based on the // messageForPort returns a message for the given port based on the
@ -581,7 +581,7 @@ func (e *serveEnv) messageForPort(sc *ipn.ServeConfig, st *ipnstate.Status, dnsN
if err != nil || len(serviceIPMaps) == 0 || serviceIPMaps[0][svcName] == nil { if err != nil || len(serviceIPMaps) == 0 || serviceIPMaps[0][svcName] == nil {
// The capmap does not contain IPs for this service yet. Usually this means // The capmap does not contain IPs for this service yet. Usually this means
// the service hasn't been added to prefs and sent to control yet. // the service hasn't been added to prefs and sent to control yet.
output.WriteString(fmt.Sprintf(msgServiceIPNotAssigned, svcName.String())) output.WriteString(fmt.Sprintf(msgServiceWaitingApproval, svcName.String()))
ips = nil ips = nil
} else { } else {
output.WriteString(msgServeAvailable) output.WriteString(msgServeAvailable)
@ -698,11 +698,11 @@ func (e *serveEnv) applyWebServe(sc *ipn.ServeConfig, st *ipnstate.Status, dnsNa
} }
// TODO: validation needs to check nested foreground configs // TODO: validation needs to check nested foreground configs
if sc.IsTCPForwardingOnPort(srvPort, dnsName) { if sc.IsTCPForwardingOnPort(dnsName, srvPort) {
return errors.New("cannot serve web; already serving TCP") return errors.New("cannot serve web; already serving TCP")
} }
sc.SetWebHandler(st, h, dnsName, srvPort, mount, useTLS) sc.SetWebHandler(h, dnsName, srvPort, mount, useTLS, st)
return nil return nil
} }
@ -938,7 +938,7 @@ func (e *serveEnv) removeWebServe(sc *ipn.ServeConfig, st *ipnstate.Status, dnsN
hp := ipn.HostPort(net.JoinHostPort(hostName, portStr)) hp := ipn.HostPort(net.JoinHostPort(hostName, portStr))
if sc.IsTCPForwardingOnPort(srvPort, dnsName) { if sc.IsTCPForwardingOnPort(dnsName, srvPort) {
return errors.New("cannot remove web handler; currently serving TCP") return errors.New("cannot remove web handler; currently serving TCP")
} }
var targetExists bool var targetExists bool

View File

@ -1389,7 +1389,7 @@ func TestMessageForPort(t *testing.T) {
srvType: serveTypeHTTP, srvType: serveTypeHTTP,
srvPort: 80, srvPort: 80,
expected: strings.Join([]string{ expected: strings.Join([]string{
fmt.Sprintf(msgServiceIPNotAssigned, "svc:bar"), fmt.Sprintf(msgServiceWaitingApproval, "svc:bar"),
"", "",
"http://bar.test.ts.net/", "http://bar.test.ts.net/",
"|-- proxy http://localhost:3000", "|-- proxy http://localhost:3000",

View File

@ -260,7 +260,7 @@ func printFunnelStatus(ctx context.Context) {
} }
sni, portStr, _ := net.SplitHostPort(string(hp)) sni, portStr, _ := net.SplitHostPort(string(hp))
p, _ := strconv.ParseUint(portStr, 10, 16) p, _ := strconv.ParseUint(portStr, 10, 16)
isTCP := sc.IsTCPForwardingOnPort(uint16(p), sni) isTCP := sc.IsTCPForwardingOnPort(sni, uint16(p))
url := "https://" url := "https://"
if isTCP { if isTCP {
url = "tcp://" url = "tcp://"

View File

@ -266,9 +266,9 @@ func serveOnLocalTailscaled(ctx context.Context, lc *local.Client, st *ipnstate.
fmt.Printf("setting funnel for %s:%v\n", serverURL, dstPort) fmt.Printf("setting funnel for %s:%v\n", serverURL, dstPort)
foregroundSc.SetFunnel(serverURL, dstPort, shouldFunnel) foregroundSc.SetFunnel(serverURL, dstPort, shouldFunnel)
foregroundSc.SetWebHandler(st, &ipn.HTTPHandler{ foregroundSc.SetWebHandler(&ipn.HTTPHandler{
Proxy: fmt.Sprintf("https://%s", net.JoinHostPort(serverURL, strconv.Itoa(int(dstPort)))), Proxy: fmt.Sprintf("https://%s", net.JoinHostPort(serverURL, strconv.Itoa(int(dstPort)))),
}, serverURL, uint16(*flagPort), "/", true) }, serverURL, uint16(*flagPort), "/", true, st)
err = lc.SetServeConfig(ctx, sc) err = lc.SetServeConfig(ctx, sc)
if err != nil { if err != nil {
return nil, watcherChan, fmt.Errorf("could not set serve config: %v", err) return nil, watcherChan, fmt.Errorf("could not set serve config: %v", err)

View File

@ -247,7 +247,7 @@ func (sc *ServeConfig) IsTCPForwardingAny() bool {
// IsTCPForwardingOnPort reports whether ServeConfig is currently forwarding // IsTCPForwardingOnPort reports whether ServeConfig is currently forwarding
// in TCPForward mode on the given port for a DNSName. DNSName will be either node's DNSName, or a // in TCPForward mode on the given port for a DNSName. DNSName will be either node's DNSName, or a
// serviceName for service hosted on node. This is exclusive of Web/HTTPS serving. // serviceName for service hosted on node. This is exclusive of Web/HTTPS serving.
func (sc *ServeConfig) IsTCPForwardingOnPort(port uint16, dnsName string) bool { func (sc *ServeConfig) IsTCPForwardingOnPort(dnsName string, port uint16) bool {
if sc == nil { if sc == nil {
return false return false
} }
@ -338,8 +338,9 @@ func (sc *ServeConfig) FindConfig(port uint16) (*ServeConfig, bool) {
// SetWebHandler sets the given HTTPHandler at the specified host, port, // SetWebHandler sets the given HTTPHandler at the specified host, port,
// and mount in the serve config. sc.TCP is also updated to reflect web // and mount in the serve config. sc.TCP is also updated to reflect web
// serving usage of the given port. // serving usage of the given port. The st argument is needed when setting
func (sc *ServeConfig) SetWebHandler(st *ipnstate.Status, handler *HTTPHandler, host string, port uint16, mount string, useTLS bool) { // a web handler for a service, other wise it can be nil.
func (sc *ServeConfig) SetWebHandler(handler *HTTPHandler, host string, port uint16, mount string, useTLS bool, st *ipnstate.Status) {
if sc == nil { if sc == nil {
sc = new(ServeConfig) sc = new(ServeConfig)
} }

View File

@ -235,7 +235,7 @@ func TestIsTCPForwardingOnPort(t *testing.T) {
} }
for _, tt := range tests { for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) { t.Run(tt.name, func(t *testing.T) {
got := tt.cfg.IsTCPForwardingOnPort(tt.port, tt.dns) got := tt.cfg.IsTCPForwardingOnPort(tt.dns, tt.port)
if tt.want != got { if tt.want != got {
t.Errorf("IsTCPForwardingOnPort() = %v, want %v", got, tt.want) t.Errorf("IsTCPForwardingOnPort() = %v, want %v", got, tt.want)
} }