Skip to content

Commit

Permalink
Tunnel mode selection feature for agent mode. (#544)
Browse files Browse the repository at this point in the history
With this change ENABLE_GO_IOS_AGENT can be set to "user" or "kernel" to start selective mode tunnel.

Co-authored-by: dmissmann <[email protected]>

---------

Co-authored-by: Serhat Toktamisoglu <[email protected]>
Co-authored-by: dmissmann <[email protected]>
  • Loading branch information
3 people authored Jan 14, 2025
1 parent f5b5d81 commit 99b19bc
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 5 deletions.
14 changes: 12 additions & 2 deletions ios/tunnel/tunnel_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ func WaitUntilAgentReady() bool {
}
}

func RunAgent(args ...string) error {
func RunAgent(mode string, args ...string) error {
if IsAgentRunning() {
return nil
}
Expand All @@ -64,8 +64,18 @@ func RunAgent(args ...string) error {
return fmt.Errorf("RunAgent: failed to get executable path: %w", err)
}

cmd := exec.Command(ex, append([]string{"tunnel", "start"}, args...)...)
var cmd *exec.Cmd
switch mode {
case "kernel":
cmd = exec.Command(ex, append([]string{"tunnel", "start"}, args...)...)
case "user":
cmd = exec.Command(ex, append([]string{"tunnel", "start", "--userspace"}, args...)...)
default:
return fmt.Errorf("RunAgent: unknown mode: %s. Only 'kernel' and 'user' are supported", mode)
}

err = cmd.Start()

if err != nil {
return fmt.Errorf("RunAgent: failed to start agent: %w", err)
}
Expand Down
7 changes: 4 additions & 3 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -295,11 +295,12 @@ The commands work as following:
log.Debug(arguments)

skipAgent, _ := os.LookupEnv("ENABLE_GO_IOS_AGENT")
if skipAgent == "yes" {
tunnel.RunAgent()
if skipAgent == "user" || skipAgent == "kernel" {
tunnel.RunAgent(skipAgent)
}

if !tunnel.IsAgentRunning() {
log.Warn("go-ios agent is not running. You might need to start it with 'ios tunnel start' for ios17+. Use ENABLE_GO_IOS_AGENT=yes for experimental daemon mode.")
log.Warn("go-ios agent is not running. You might need to start it with 'ios tunnel start' for ios17+. Use ENABLE_GO_IOS_AGENT=user for userspace tunnel or ENABLE_GO_IOS_AGENT=kernel for kernel tunnel for the experimental daemon mode.")
}
shouldPrintVersionNoDashes, _ := arguments.Bool("version")
shouldPrintVersion, _ := arguments.Bool("--version")
Expand Down

0 comments on commit 99b19bc

Please sign in to comment.