Skip to content

Commit

Permalink
feat(cli): Add --backend flag to specify packet capture backend (#206)
Browse files Browse the repository at this point in the history
  • Loading branch information
mozillazg authored Dec 6, 2024
1 parent 9e95911 commit 7bd3525
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 0 deletions.
8 changes: 8 additions & 0 deletions cmd/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ type Options struct {
dontConvertAddr int
verbose int
quiet bool
backend string

containerId string
containerName string
Expand Down Expand Up @@ -167,6 +168,13 @@ func prepareOptions(opts *Options, rawArgs []string, args []string) {
opts.enhancedContext |= types.EnhancedContextPod
}
}

switch types.NetHookBackend(opts.backend) {
case types.NetHookBackendTc:
default:
opts.backend = string(types.NetHookBackendTc)
}

}

func getPodNameFilter(raw string) (name, ns string) {
Expand Down
4 changes: 4 additions & 0 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package cmd
import (
"context"
"fmt"
"github.com/mozillazg/ptcpdump/internal/types"
"os"
"os/signal"
"strings"
Expand Down Expand Up @@ -130,6 +131,9 @@ func init() {
rootCmd.Flags().StringSliceVar(&opts.enhancedContexts, "context",
[]string{contextProcess, contextParentProc, contextContainer, contextPod},
"Specify which context information to include in the output")
rootCmd.Flags().StringVar(&opts.backend, "backend", string(types.NetHookBackendTc),
"Specify the backend to use for capturing packets. "+
fmt.Sprintf("Possible values are %q", types.NetHookBackendTc))

silenceKlog()
}
Expand Down
7 changes: 7 additions & 0 deletions internal/types/backend.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package types

type NetHookBackend string

const (
NetHookBackendTc NetHookBackend = "tc"
)

0 comments on commit 7bd3525

Please sign in to comment.