@ -28,6 +28,7 @@ import (
"github.com/peterbourgon/ff/v3/ffcli"
"github.com/peterbourgon/ff/v3/ffcli"
"golang.org/x/net/http/httpproxy"
"golang.org/x/net/http/httpproxy"
"tailscale.com/client/tailscale"
"tailscale.com/client/tailscale/apitype"
"tailscale.com/client/tailscale/apitype"
"tailscale.com/control/controlhttp"
"tailscale.com/control/controlhttp"
"tailscale.com/hostinfo"
"tailscale.com/hostinfo"
@ -219,7 +220,9 @@ var debugCmd = &ffcli.Command{
fs := newFlagSet ( "portmap" )
fs := newFlagSet ( "portmap" )
fs . DurationVar ( & debugPortmapArgs . duration , "duration" , 5 * time . Second , "timeout for port mapping" )
fs . DurationVar ( & debugPortmapArgs . duration , "duration" , 5 * time . Second , "timeout for port mapping" )
fs . StringVar ( & debugPortmapArgs . ty , "type" , "" , ` portmap debug type (one of "", "pmp", "pcp", or "upnp") ` )
fs . StringVar ( & debugPortmapArgs . ty , "type" , "" , ` portmap debug type (one of "", "pmp", "pcp", or "upnp") ` )
fs . StringVar ( & debugPortmapArgs . gwSelf , "gw-self" , "" , ` override gateway and self IP (format: "gatewayIP/selfIP") ` )
fs . StringVar ( & debugPortmapArgs . gatewayAddr , "gateway-addr" , "" , ` override gateway IP (must also pass --self-addr) ` )
fs . StringVar ( & debugPortmapArgs . selfAddr , "self-addr" , "" , ` override self IP (must also pass --gateway-addr) ` )
fs . BoolVar ( & debugPortmapArgs . logHTTP , "log-http" , false , ` print all HTTP requests and responses to the log ` )
return fs
return fs
} ) ( ) ,
} ) ( ) ,
} ,
} ,
@ -818,17 +821,34 @@ func runCapture(ctx context.Context, args []string) error {
}
}
var debugPortmapArgs struct {
var debugPortmapArgs struct {
duration time . Duration
duration time . Duration
gwSelf string
gatewayAddr string
ty string
selfAddr string
ty string
logHTTP bool
}
}
func debugPortmap ( ctx context . Context , args [ ] string ) error {
func debugPortmap ( ctx context . Context , args [ ] string ) error {
rc , err := localClient . DebugPortmap ( ctx ,
opts := & tailscale . DebugPortmapOpts {
debugPortmapArgs . duration ,
Duration : debugPortmapArgs . duration ,
debugPortmapArgs . ty ,
Type : debugPortmapArgs . ty ,
debugPortmapArgs . gwSelf ,
LogHTTP : debugPortmapArgs . logHTTP ,
)
}
if ( debugPortmapArgs . gatewayAddr != "" ) != ( debugPortmapArgs . selfAddr != "" ) {
return fmt . Errorf ( "if one of --gateway-addr and --self-addr is provided, the other must be as well" )
}
if debugPortmapArgs . gatewayAddr != "" {
var err error
opts . GatewayAddr , err = netip . ParseAddr ( debugPortmapArgs . gatewayAddr )
if err != nil {
return fmt . Errorf ( "invalid --gateway-addr: %w" , err )
}
opts . SelfAddr , err = netip . ParseAddr ( debugPortmapArgs . selfAddr )
if err != nil {
return fmt . Errorf ( "invalid --self-addr: %w" , err )
}
}
rc , err := localClient . DebugPortmap ( ctx , opts )
if err != nil {
if err != nil {
return err
return err
}
}