From b9edbab93a6eac6df384b9b432c3f1c269666b1a Mon Sep 17 00:00:00 2001 From: Antoine Blin Date: Mon, 17 Jun 2024 15:44:16 +0200 Subject: [PATCH] Allow --debug/--trace options for pasta Signed-off-by: Antoine Blin --- common/libnetwork/pasta/pasta_linux.go | 10 ++++++++-- common/libnetwork/pasta/pasta_linux_test.go | 14 ++++++++++++++ 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/common/libnetwork/pasta/pasta_linux.go b/common/libnetwork/pasta/pasta_linux.go index 2e6dc7d59f..fd68f87f27 100644 --- a/common/libnetwork/pasta/pasta_linux.go +++ b/common/libnetwork/pasta/pasta_linux.go @@ -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 } diff --git a/common/libnetwork/pasta/pasta_linux_test.go b/common/libnetwork/pasta/pasta_linux_test.go index bcefeaa108..6ad78b2426 100644 --- a/common/libnetwork/pasta/pasta_linux_test.go +++ b/common/libnetwork/pasta/pasta_linux_test.go @@ -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) {