From 5b23ef31b7414d147cb7052376713b13c5d20d00 Mon Sep 17 00:00:00 2001 From: David Anderson Date: Tue, 16 Aug 2016 14:05:33 -0700 Subject: [PATCH] pixiecore/cli: add the "debug tcpdump" command. This just runs `tcpdump` as a subprocess, with the right arguments to capture interesting parts of the boot process (DHCP, PXE, TFTP). --- pixiecore/cli/debugcmd.go | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/pixiecore/cli/debugcmd.go b/pixiecore/cli/debugcmd.go index 2422457..de0e8ab 100644 --- a/pixiecore/cli/debugcmd.go +++ b/pixiecore/cli/debugcmd.go @@ -17,6 +17,9 @@ package cli import ( "fmt" "io/ioutil" + "os" + "os/exec" + "strings" "github.com/spf13/cobra" ) @@ -41,9 +44,27 @@ var ( } }, } + tcpdumpCmd = &cobra.Command{ + Use: "tcpdump interface pcap-file", + Short: "Run tcpdump to capture some parts of a boot exchange, for debugging", + Run: func(cmd *cobra.Command, args []string) { + if len(args) != 2 { + fatalf("Need exactly 2 argument, the interface to capture on and the pcap file to write") + } + filter := "port 67 or port 68 or port 69 or port 4011" + args = []string{"-w", args[1], "-e", "-i", args[0]} + c := exec.Command("tcpdump", append(args, strings.Split(filter, " ")...)...) + c.Stdout = os.Stdout + c.Stderr = os.Stderr + if err := c.Run(); err != nil { + fatalf("Running tcpdump: %s", err) + } + }, + } ) func init() { debugCmd.AddCommand(dumpIpxeCmd) + debugCmd.AddCommand(tcpdumpCmd) rootCmd.AddCommand(debugCmd) }