mirror of
https://github.com/tailscale/tailscale.git
synced 2025-10-09 08:01:31 +00:00
cmd/tailscale,net/netcheck: add debug feature to force preferred DERP
This provides an interface for a user to force a preferred DERP outcome for all future netchecks that will take precedence unless the forced region is unreachable. The option does not persist and will be lost when the daemon restarts. Updates tailscale/corp#18997 Updates tailscale/corp#24755 Signed-off-by: James Tucker <james@tailscale.com>
This commit is contained in:

committed by
James Tucker

parent
74069774be
commit
7f9ebc0a83
@@ -175,6 +175,12 @@ var debugCmd = &ffcli.Command{
|
||||
Exec: localAPIAction("pick-new-derp"),
|
||||
ShortHelp: "Switch to some other random DERP home region for a short time",
|
||||
},
|
||||
{
|
||||
Name: "force-prefer-derp",
|
||||
ShortUsage: "tailscale debug force-prefer-derp",
|
||||
Exec: forcePreferDERP,
|
||||
ShortHelp: "Prefer the given region ID if reachable (until restart, or 0 to clear)",
|
||||
},
|
||||
{
|
||||
Name: "force-netmap-update",
|
||||
ShortUsage: "tailscale debug force-netmap-update",
|
||||
@@ -577,6 +583,25 @@ func runDERPMap(ctx context.Context, args []string) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func forcePreferDERP(ctx context.Context, args []string) error {
|
||||
var n int
|
||||
if len(args) != 1 {
|
||||
return errors.New("expected exactly one integer argument")
|
||||
}
|
||||
n, err := strconv.Atoi(args[0])
|
||||
if err != nil {
|
||||
return fmt.Errorf("expected exactly one integer argument: %w", err)
|
||||
}
|
||||
b, err := json.Marshal(n)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to marshal DERP region: %w", err)
|
||||
}
|
||||
if err := localClient.DebugActionBody(ctx, "force-prefer-derp", bytes.NewReader(b)); err != nil {
|
||||
return fmt.Errorf("failed to force preferred DERP: %w", err)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func localAPIAction(action string) func(context.Context, []string) error {
|
||||
return func(ctx context.Context, args []string) error {
|
||||
if len(args) > 0 {
|
||||
|
Reference in New Issue
Block a user