Allow --debug/--trace options for pasta

Signed-off-by: Antoine Blin <antoine.blin3@gmail.com>
This commit is contained in:
Antoine Blin 2024-06-17 15:44:16 +02:00 committed by antoine
parent 87ddd531d3
commit b9edbab93a
2 changed files with 22 additions and 2 deletions

View File

@ -130,6 +130,7 @@ func createPastaArgs(opts *SetupOptions) ([]string, []string, error) {
noTCPNamespacePorts := true
noUDPNamespacePorts := true
noMapGW := true
quiet := true
cmdArgs := []string{"--config-net"}
// first append options set in the config
@ -158,6 +159,8 @@ func createPastaArgs(opts *SetupOptions) ([]string, []string, error) {
noTCPNamespacePorts = false
case "-U", "--udp-ns":
noUDPNamespacePorts = false
case "-d", "--debug", "--trace":
quiet = false
case dnsForwardOpt:
// if there is no arg after it pasta will likely error out anyway due invalid cli args
if len(cmdArgs) > i+1 {
@ -216,9 +219,12 @@ func createPastaArgs(opts *SetupOptions) ([]string, []string, error) {
if noMapGW {
cmdArgs = append(cmdArgs, "--no-map-gw")
}
if quiet {
// pass --quiet to silence the info output from pasta if verbose/trace pasta is not required
cmdArgs = append(cmdArgs, "--quiet")
}
// always pass --quiet to silence the info output from pasta
cmdArgs = append(cmdArgs, "--quiet", "--netns", opts.Netns)
cmdArgs = append(cmdArgs, "--netns", opts.Netns)
return cmdArgs, dnsForwardIPs, nil
}

View File

@ -251,6 +251,20 @@ func Test_createPastaArgs(t *testing.T) {
},
wantDnsForward: []string{dnsForwardIpv4},
},
{
name: "Add verbose logging",
input: makeSetupOptions(
nil,
[]string{"--log-file=/tmp/log", "--trace", "--debug"},
nil,
),
wantArgs: []string{
"--config-net", "--log-file=/tmp/log", "--trace", "--debug",
"--dns-forward", dnsForwardIpv4, "-t", "none", "-u", "none", "-T", "none", "-U", "none",
"--no-map-gw", "--netns", "netns123",
},
wantDnsForward: []string{dnsForwardIpv4},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {