From dfaba43eee3ce916157c2ac274867da1ea98787b Mon Sep 17 00:00:00 2001 From: gray Date: Fri, 17 May 2024 11:17:27 +0800 Subject: [PATCH 01/15] Complete column names Signed-off-by: gray --- internal/pwru/output.go | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/internal/pwru/output.go b/internal/pwru/output.go index 06e89b4c..5599859b 100644 --- a/internal/pwru/output.go +++ b/internal/pwru/output.go @@ -123,6 +123,12 @@ func (o *output) PrintHeader() { if o.flags.OutputTS != "none" { fmt.Fprintf(o.writer, " %16s", "TIMESTAMP") } + if o.flags.OutputMeta { + fmt.Fprintf(o.writer, " %s %s %s %s %s %s", "NETNS", "MARK", "IFACE", "PROTO", "MTU", "LEN") + } + if o.flags.OutputTuple { + fmt.Fprintf(o.writer, " %s", "TUPLE") + } fmt.Fprintf(o.writer, "\n") } @@ -288,7 +294,7 @@ func getShinfoData(event *Event, o *output) (shinfoData string) { } func getMetaData(event *Event, o *output) (metaData string) { - metaData = fmt.Sprintf("netns=%d mark=%#x iface=%s proto=%#04x mtu=%d len=%d", + metaData = fmt.Sprintf("%d %#x %s %#04x %d %d", event.Meta.Netns, event.Meta.Mark, o.getIfaceName(event.Meta.Netns, event.Meta.Ifindex), byteorder.NetworkToHost16(event.Meta.Proto), event.Meta.MTU, event.Meta.Len) From 660854d63dc880acb717045a52a61421d547575e Mon Sep 17 00:00:00 2001 From: gray Date: Fri, 17 May 2024 11:22:55 +0800 Subject: [PATCH 02/15] Move FUNC to the last column Because it has variant length. Signed-off-by: gray --- internal/pwru/output.go | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/internal/pwru/output.go b/internal/pwru/output.go index 5599859b..cd278178 100644 --- a/internal/pwru/output.go +++ b/internal/pwru/output.go @@ -119,7 +119,7 @@ func (o *output) PrintHeader() { if o.flags.OutputTS == "absolute" { fmt.Fprintf(o.writer, "%12s ", "TIME") } - fmt.Fprintf(o.writer, "%18s %6s %16s %24s", "SKB", "CPU", "PROCESS", "FUNC") + fmt.Fprintf(o.writer, "%18s %6s %16s", "SKB", "CPU", "PROCESS") if o.flags.OutputTS != "none" { fmt.Fprintf(o.writer, " %16s", "TIMESTAMP") } @@ -129,6 +129,7 @@ func (o *output) PrintHeader() { if o.flags.OutputTuple { fmt.Fprintf(o.writer, " %s", "TUPLE") } + fmt.Fprintf(o.writer, " %s", "FUNC") fmt.Fprintf(o.writer, "\n") } @@ -344,8 +345,8 @@ func (o *output) Print(event *Event) { outFuncName := getOutFuncName(o, event, addr) - fmt.Fprintf(o.writer, "%18s %6s %16s %24s", fmt.Sprintf("%#x", event.SAddr), - fmt.Sprintf("%d", event.CPU), fmt.Sprintf("[%s]", execName), outFuncName) + fmt.Fprintf(o.writer, "%18s %6s %16s", fmt.Sprintf("%#x", event.SAddr), + fmt.Sprintf("%d", event.CPU), fmt.Sprintf("[%s]", execName)) if o.flags.OutputTS != "none" { fmt.Fprintf(o.writer, " %16d", ts) } @@ -359,6 +360,8 @@ func (o *output) Print(event *Event) { fmt.Fprintf(o.writer, " %s", getTupleData(event)) } + fmt.Fprintf(o.writer, " %s", outFuncName) + if o.flags.OutputStack && event.PrintStackId > 0 { fmt.Fprintf(o.writer, "%s", getStackData(event, o)) } From a12ebc603f6287aa0dbff5d2d4b8dcd91cfa610e Mon Sep 17 00:00:00 2001 From: gray Date: Fri, 17 May 2024 11:28:40 +0800 Subject: [PATCH 03/15] Left align Signed-off-by: gray --- internal/pwru/output.go | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/internal/pwru/output.go b/internal/pwru/output.go index cd278178..63452b2d 100644 --- a/internal/pwru/output.go +++ b/internal/pwru/output.go @@ -117,11 +117,11 @@ func (o *output) Close() { func (o *output) PrintHeader() { if o.flags.OutputTS == "absolute" { - fmt.Fprintf(o.writer, "%12s ", "TIME") + fmt.Fprintf(o.writer, "%-12s ", "TIME") } - fmt.Fprintf(o.writer, "%18s %6s %16s", "SKB", "CPU", "PROCESS") + fmt.Fprintf(o.writer, "%-18s %-6s %-16s", "SKB", "CPU", "PROCESS") if o.flags.OutputTS != "none" { - fmt.Fprintf(o.writer, " %16s", "TIMESTAMP") + fmt.Fprintf(o.writer, " %-16s", "TIMESTAMP") } if o.flags.OutputMeta { fmt.Fprintf(o.writer, " %s %s %s %s %s %s", "NETNS", "MARK", "IFACE", "PROTO", "MTU", "LEN") @@ -330,7 +330,7 @@ func getOutFuncName(o *output, event *Event, addr uint64) string { func (o *output) Print(event *Event) { if o.flags.OutputTS == "absolute" { - fmt.Fprintf(o.writer, "%12s ", getAbsoluteTs()) + fmt.Fprintf(o.writer, "%-12s ", getAbsoluteTs()) } execName := getExecName(int(event.PID)) @@ -345,10 +345,10 @@ func (o *output) Print(event *Event) { outFuncName := getOutFuncName(o, event, addr) - fmt.Fprintf(o.writer, "%18s %6s %16s", fmt.Sprintf("%#x", event.SAddr), + fmt.Fprintf(o.writer, "%-18s %-6s %-16s", fmt.Sprintf("%#x", event.SAddr), fmt.Sprintf("%d", event.CPU), fmt.Sprintf("[%s]", execName)) if o.flags.OutputTS != "none" { - fmt.Fprintf(o.writer, " %16d", ts) + fmt.Fprintf(o.writer, " %-16d", ts) } o.lastSeenSkb[event.SAddr] = event.Timestamp From 2eb1124cd459f038d5e68f38893a28435cdc960e Mon Sep 17 00:00:00 2001 From: gray Date: Fri, 17 May 2024 11:36:43 +0800 Subject: [PATCH 04/15] Reduce CPU column width to 3 Signed-off-by: gray --- internal/pwru/output.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/internal/pwru/output.go b/internal/pwru/output.go index 63452b2d..e5748661 100644 --- a/internal/pwru/output.go +++ b/internal/pwru/output.go @@ -119,7 +119,7 @@ func (o *output) PrintHeader() { if o.flags.OutputTS == "absolute" { fmt.Fprintf(o.writer, "%-12s ", "TIME") } - fmt.Fprintf(o.writer, "%-18s %-6s %-16s", "SKB", "CPU", "PROCESS") + fmt.Fprintf(o.writer, "%-18s %-3s %-16s", "SKB", "CPU", "PROCESS") if o.flags.OutputTS != "none" { fmt.Fprintf(o.writer, " %-16s", "TIMESTAMP") } @@ -345,7 +345,7 @@ func (o *output) Print(event *Event) { outFuncName := getOutFuncName(o, event, addr) - fmt.Fprintf(o.writer, "%-18s %-6s %-16s", fmt.Sprintf("%#x", event.SAddr), + fmt.Fprintf(o.writer, "%-18s %-3s %-16s", fmt.Sprintf("%#x", event.SAddr), fmt.Sprintf("%d", event.CPU), fmt.Sprintf("[%s]", execName)) if o.flags.OutputTS != "none" { fmt.Fprintf(o.writer, " %-16d", ts) From 51991311f0b7ab515845eee888b3694d45a43eea Mon Sep 17 00:00:00 2001 From: gray Date: Fri, 17 May 2024 11:48:09 +0800 Subject: [PATCH 05/15] Limit PROCESS to 16 bytes Signed-off-by: gray --- internal/pwru/output.go | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/internal/pwru/output.go b/internal/pwru/output.go index e5748661..28dd3b8b 100644 --- a/internal/pwru/output.go +++ b/internal/pwru/output.go @@ -216,9 +216,15 @@ func getRelativeTs(event *Event, o *output) uint64 { func getExecName(pid int) string { p, err := ps.FindProcess(pid) - execName := fmt.Sprintf(":(%d)", pid) + execName := fmt.Sprintf(":%d", pid) if err == nil && p != nil { - return fmt.Sprintf("%s:%d", p.ExecutablePath(), pid) + execName = fmt.Sprintf("%s:%d", p.ExecutablePath(), pid) + if len(execName) > 16 { + execName = execName[len(execName)-16:] + bexecName := []byte(execName) + bexecName[0] = '~' + execName = string(bexecName) + } } return execName } @@ -346,7 +352,7 @@ func (o *output) Print(event *Event) { outFuncName := getOutFuncName(o, event, addr) fmt.Fprintf(o.writer, "%-18s %-3s %-16s", fmt.Sprintf("%#x", event.SAddr), - fmt.Sprintf("%d", event.CPU), fmt.Sprintf("[%s]", execName)) + fmt.Sprintf("%d", event.CPU), fmt.Sprintf("%s", execName)) if o.flags.OutputTS != "none" { fmt.Fprintf(o.writer, " %-16d", ts) } From 69d268b8052aafb9573a31ae28b0e78abbf04cc5 Mon Sep 17 00:00:00 2001 From: gray Date: Fri, 17 May 2024 11:56:03 +0800 Subject: [PATCH 06/15] Set 10 width to NETNS column Signed-off-by: gray --- internal/pwru/output.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/internal/pwru/output.go b/internal/pwru/output.go index 28dd3b8b..3df31cd4 100644 --- a/internal/pwru/output.go +++ b/internal/pwru/output.go @@ -124,7 +124,7 @@ func (o *output) PrintHeader() { fmt.Fprintf(o.writer, " %-16s", "TIMESTAMP") } if o.flags.OutputMeta { - fmt.Fprintf(o.writer, " %s %s %s %s %s %s", "NETNS", "MARK", "IFACE", "PROTO", "MTU", "LEN") + fmt.Fprintf(o.writer, " %-10s %s %s %s %s %s", "NETNS", "MARK", "IFACE", "PROTO", "MTU", "LEN") } if o.flags.OutputTuple { fmt.Fprintf(o.writer, " %s", "TUPLE") @@ -301,7 +301,7 @@ func getShinfoData(event *Event, o *output) (shinfoData string) { } func getMetaData(event *Event, o *output) (metaData string) { - metaData = fmt.Sprintf("%d %#x %s %#04x %d %d", + metaData = fmt.Sprintf("%10d %#x %s %#04x %d %d", event.Meta.Netns, event.Meta.Mark, o.getIfaceName(event.Meta.Netns, event.Meta.Ifindex), byteorder.NetworkToHost16(event.Meta.Proto), event.Meta.MTU, event.Meta.Len) From 145a57d6b811aa63c5f3c19103b0d4de6457239d Mon Sep 17 00:00:00 2001 From: gray Date: Fri, 17 May 2024 12:04:17 +0800 Subject: [PATCH 07/15] Set 8 width to MARK column Also strip 0x prefix. Signed-off-by: gray --- internal/pwru/output.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/internal/pwru/output.go b/internal/pwru/output.go index 3df31cd4..14781a3b 100644 --- a/internal/pwru/output.go +++ b/internal/pwru/output.go @@ -124,7 +124,7 @@ func (o *output) PrintHeader() { fmt.Fprintf(o.writer, " %-16s", "TIMESTAMP") } if o.flags.OutputMeta { - fmt.Fprintf(o.writer, " %-10s %s %s %s %s %s", "NETNS", "MARK", "IFACE", "PROTO", "MTU", "LEN") + fmt.Fprintf(o.writer, " %-10s %-8s %s %s %s %s", "NETNS", "MARK", "IFACE", "PROTO", "MTU", "LEN") } if o.flags.OutputTuple { fmt.Fprintf(o.writer, " %s", "TUPLE") @@ -301,7 +301,7 @@ func getShinfoData(event *Event, o *output) (shinfoData string) { } func getMetaData(event *Event, o *output) (metaData string) { - metaData = fmt.Sprintf("%10d %#x %s %#04x %d %d", + metaData = fmt.Sprintf("%10d %08x %s %#04x %d %d", event.Meta.Netns, event.Meta.Mark, o.getIfaceName(event.Meta.Netns, event.Meta.Ifindex), byteorder.NetworkToHost16(event.Meta.Proto), event.Meta.MTU, event.Meta.Len) From c738749713d6185906bdf4cf636d4be944e51698 Mon Sep 17 00:00:00 2001 From: gray Date: Fri, 17 May 2024 12:22:29 +0800 Subject: [PATCH 08/15] Set 16 to IFACE column width ifname can be as long as 16 bytes, plust len of ifindex len(str(1<<32))=10, it should be at least 26. However, 16 is enough for most of situations, so let's make it 16. Also center align this column out of aesthetics. Signed-off-by: gray --- internal/pwru/output.go | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/internal/pwru/output.go b/internal/pwru/output.go index 14781a3b..40f3e32e 100644 --- a/internal/pwru/output.go +++ b/internal/pwru/output.go @@ -15,6 +15,7 @@ import ( "path/filepath" "runtime" "strconv" + "strings" "syscall" "time" @@ -70,6 +71,15 @@ type jsonTuple struct { Proto uint8 `json:"proto,omitempty"` } +func centerAlignString(s string, width int) string { + if len(s) >= width { + return s + } + leftPadding := (width - len(s)) / 2 + rightPadding := width - len(s) - leftPadding + return fmt.Sprintf("%s%s%s", strings.Repeat(" ", leftPadding), s, strings.Repeat(" ", rightPadding)) +} + func NewOutput(flags *Flags, printSkbMap, printShinfoMap, printStackMap *ebpf.Map, addr2Name Addr2Name, kprobeMulti bool, btfSpec *btf.Spec) (*output, error) { writer := os.Stdout @@ -124,7 +134,7 @@ func (o *output) PrintHeader() { fmt.Fprintf(o.writer, " %-16s", "TIMESTAMP") } if o.flags.OutputMeta { - fmt.Fprintf(o.writer, " %-10s %-8s %s %s %s %s", "NETNS", "MARK", "IFACE", "PROTO", "MTU", "LEN") + fmt.Fprintf(o.writer, " %-10s %-8s %16s %s %s %s", "NETNS", "MARK", centerAlignString("IFACE", 16), "PROTO", "MTU", "LEN") } if o.flags.OutputTuple { fmt.Fprintf(o.writer, " %s", "TUPLE") @@ -301,9 +311,9 @@ func getShinfoData(event *Event, o *output) (shinfoData string) { } func getMetaData(event *Event, o *output) (metaData string) { - metaData = fmt.Sprintf("%10d %08x %s %#04x %d %d", + metaData = fmt.Sprintf("%10d %08x %16s %#04x %d %d", event.Meta.Netns, event.Meta.Mark, - o.getIfaceName(event.Meta.Netns, event.Meta.Ifindex), + centerAlignString(o.getIfaceName(event.Meta.Netns, event.Meta.Ifindex), 16), byteorder.NetworkToHost16(event.Meta.Proto), event.Meta.MTU, event.Meta.Len) return metaData } @@ -386,7 +396,14 @@ func (o *output) Print(event *Event) { func (o *output) getIfaceName(netnsInode, ifindex uint32) string { if ifaces, ok := o.ifaceCache[uint64(netnsInode)]; ok { if name, ok := ifaces[ifindex]; ok { - return fmt.Sprintf("%d(%s)", ifindex, name) + ifname := fmt.Sprintf("%s:%d", name, ifindex) + if len(ifname) > 16 { + ifname = ifname[len(ifname)-16:] + bifname := []byte(ifname) + bifname[0] = '~' + ifname = string(bifname) + } + return ifname } } return fmt.Sprintf("%d", ifindex) From 9a860be3ad3fb8e5fa19bfb7c1356e126d296797 Mon Sep 17 00:00:00 2001 From: gray Date: Fri, 17 May 2024 12:27:08 +0800 Subject: [PATCH 09/15] Limit PROTO column to 6 bytes Signed-off-by: gray --- internal/pwru/output.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/pwru/output.go b/internal/pwru/output.go index 40f3e32e..3e280521 100644 --- a/internal/pwru/output.go +++ b/internal/pwru/output.go @@ -134,7 +134,7 @@ func (o *output) PrintHeader() { fmt.Fprintf(o.writer, " %-16s", "TIMESTAMP") } if o.flags.OutputMeta { - fmt.Fprintf(o.writer, " %-10s %-8s %16s %s %s %s", "NETNS", "MARK", centerAlignString("IFACE", 16), "PROTO", "MTU", "LEN") + fmt.Fprintf(o.writer, " %-10s %-8s %16s %-6s %s %s", "NETNS", "MARK", centerAlignString("IFACE", 16), "PROTO", "MTU", "LEN") } if o.flags.OutputTuple { fmt.Fprintf(o.writer, " %s", "TUPLE") From 0774a646115d03799dbf6a73c5063d0dd837a354 Mon Sep 17 00:00:00 2001 From: gray Date: Fri, 17 May 2024 12:34:12 +0800 Subject: [PATCH 10/15] MTU has 5 bytes Actually it's a uint32, but let's make it 5 that fits most scenarios. Signed-off-by: gray --- internal/pwru/output.go | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/internal/pwru/output.go b/internal/pwru/output.go index 3e280521..8225ccac 100644 --- a/internal/pwru/output.go +++ b/internal/pwru/output.go @@ -134,7 +134,7 @@ func (o *output) PrintHeader() { fmt.Fprintf(o.writer, " %-16s", "TIMESTAMP") } if o.flags.OutputMeta { - fmt.Fprintf(o.writer, " %-10s %-8s %16s %-6s %s %s", "NETNS", "MARK", centerAlignString("IFACE", 16), "PROTO", "MTU", "LEN") + fmt.Fprintf(o.writer, " %-10s %-8s %16s %-6s %-5s %s", "NETNS", "MARK", centerAlignString("IFACE", 16), "PROTO", "MTU", "LEN") } if o.flags.OutputTuple { fmt.Fprintf(o.writer, " %s", "TUPLE") @@ -311,10 +311,12 @@ func getShinfoData(event *Event, o *output) (shinfoData string) { } func getMetaData(event *Event, o *output) (metaData string) { - metaData = fmt.Sprintf("%10d %08x %16s %#04x %d %d", + metaData = fmt.Sprintf("%10d %08x %16s %#04x %-5s %d", event.Meta.Netns, event.Meta.Mark, centerAlignString(o.getIfaceName(event.Meta.Netns, event.Meta.Ifindex), 16), - byteorder.NetworkToHost16(event.Meta.Proto), event.Meta.MTU, event.Meta.Len) + byteorder.NetworkToHost16(event.Meta.Proto), + fmt.Sprintf("%d", event.Meta.MTU), + event.Meta.Len) return metaData } From cc69af0112bb406d45033fc5006e51308aa1e0fa Mon Sep 17 00:00:00 2001 From: gray Date: Fri, 17 May 2024 12:39:28 +0800 Subject: [PATCH 11/15] LEN has 5 bytes Still, it's a u32, but let's treat it as u16 for most cases. Signed-off-by: gray --- internal/pwru/output.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/internal/pwru/output.go b/internal/pwru/output.go index 8225ccac..b8617e57 100644 --- a/internal/pwru/output.go +++ b/internal/pwru/output.go @@ -134,7 +134,7 @@ func (o *output) PrintHeader() { fmt.Fprintf(o.writer, " %-16s", "TIMESTAMP") } if o.flags.OutputMeta { - fmt.Fprintf(o.writer, " %-10s %-8s %16s %-6s %-5s %s", "NETNS", "MARK", centerAlignString("IFACE", 16), "PROTO", "MTU", "LEN") + fmt.Fprintf(o.writer, " %-10s %-8s %16s %-6s %-5s %-5s", "NETNS", "MARK", centerAlignString("IFACE", 16), "PROTO", "MTU", "LEN") } if o.flags.OutputTuple { fmt.Fprintf(o.writer, " %s", "TUPLE") @@ -311,12 +311,12 @@ func getShinfoData(event *Event, o *output) (shinfoData string) { } func getMetaData(event *Event, o *output) (metaData string) { - metaData = fmt.Sprintf("%10d %08x %16s %#04x %-5s %d", + metaData = fmt.Sprintf("%10d %08x %16s %#04x %-5s %-5s", event.Meta.Netns, event.Meta.Mark, centerAlignString(o.getIfaceName(event.Meta.Netns, event.Meta.Ifindex), 16), byteorder.NetworkToHost16(event.Meta.Proto), fmt.Sprintf("%d", event.Meta.MTU), - event.Meta.Len) + fmt.Sprintf("%d", event.Meta.Len)) return metaData } From 928a72b072794a3152f1816fa80c25e82ddb597f Mon Sep 17 00:00:00 2001 From: gray Date: Fri, 17 May 2024 12:56:14 +0800 Subject: [PATCH 12/15] Print TUPLE with historical max length So that the following FUNC can be aligned Signed-off-by: gray --- internal/pwru/output.go | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/internal/pwru/output.go b/internal/pwru/output.go index b8617e57..6d0ca19f 100644 --- a/internal/pwru/output.go +++ b/internal/pwru/output.go @@ -346,6 +346,16 @@ func getOutFuncName(o *output, event *Event, addr uint64) string { return outFuncName } +var maxTupleLengthSeen int + +func fprintTupleData(writer *os.File, tupleData string) { + if len(tupleData) > maxTupleLengthSeen { + maxTupleLengthSeen = len(tupleData) + } + formatter := fmt.Sprintf(" %%-%ds", maxTupleLengthSeen) + fmt.Fprintf(writer, formatter, tupleData) +} + func (o *output) Print(event *Event) { if o.flags.OutputTS == "absolute" { fmt.Fprintf(o.writer, "%-12s ", getAbsoluteTs()) @@ -375,7 +385,7 @@ func (o *output) Print(event *Event) { } if o.flags.OutputTuple { - fmt.Fprintf(o.writer, " %s", getTupleData(event)) + fprintTupleData(o.writer, getTupleData(event)) } fmt.Fprintf(o.writer, " %s", outFuncName) From 385a9f9c95fa21a8f1ee63fd56c2e5084e444b63 Mon Sep 17 00:00:00 2001 From: gray Date: Fri, 17 May 2024 14:39:34 +0800 Subject: [PATCH 13/15] ci: Adjust test cases Signed-off-by: gray --- .github/workflows/test.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index e2fb7939..727fd310 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -72,7 +72,7 @@ jobs: traffic-setup: | iptables -I OUTPUT 1 -m tcp --proto tcp --dst 1.0.0.1/32 --dport 8080 -j DROP curl -vvv -sS --fail --connect-timeout "1" -o /dev/null http://1.0.0.1:8080 || true - expected-output-pattern: '(kfree_skb_reason|kfree_skb\b).*1.0.0.1:8080' + expected-output-pattern: '1.0.0.1:8080.*(kfree_skb_reason|kfree_skb\b)' - name: Test basic IPv6 uses: ./.github/actions/pwru-test @@ -82,7 +82,7 @@ jobs: traffic-setup: | ip6tables -I OUTPUT 1 -m tcp --proto tcp --dst 2606:4700:4700::1001 --dport 8080 -j DROP curl -vvv -sS --fail --connect-timeout "1" -o /dev/null http://[2606:4700:4700::1001]:8080 || true - expected-output-pattern: '(kfree_skb_reason|kfree_skb\b).*\[2606:4700:4700::1001\]:8080' + expected-output-pattern: '\[2606:4700:4700::1001\]:8080.*(kfree_skb_reason|kfree_skb\b)' - name: Test advanced IPv4 uses: ./.github/actions/pwru-test @@ -92,7 +92,7 @@ jobs: traffic-setup: | iptables -I OUTPUT 1 -m tcp --proto tcp --dst 1.0.0.2/32 --dport 8080 -j DROP curl -vvv -sS --fail --connect-timeout "1" -o /dev/null http://1.0.0.2:8080 || true - expected-output-pattern: '(kfree_skb_reason|kfree_skb\b).*1.0.0.2:8080' + expected-output-pattern: '1.0.0.2:8080.*(kfree_skb_reason|kfree_skb\b)' - name: Test advanced IPv6 uses: ./.github/actions/pwru-test @@ -102,7 +102,7 @@ jobs: traffic-setup: | ip6tables -I OUTPUT 1 -m tcp --proto tcp --dst 2606:4700:4700::1002 --dport 8080 -j DROP curl -vvv -sS --fail --connect-timeout "1" -o /dev/null http://[2606:4700:4700::1002]:8080 || true - expected-output-pattern: '(kfree_skb_reason|kfree_skb\b).*\[2606:4700:4700::1002\]:8080' + expected-output-pattern: '\[2606:4700:4700::1002\]:8080.*(kfree_skb_reason|kfree_skb\b)' - name: Test pcap filter using stack uses: ./.github/actions/pwru-test From 6034b5086af9ed0960db285fa940528a0d75ff71 Mon Sep 17 00:00:00 2001 From: gray Date: Tue, 21 May 2024 17:18:23 +0800 Subject: [PATCH 14/15] Left align zero NETNS Signed-off-by: gray --- internal/pwru/output.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/internal/pwru/output.go b/internal/pwru/output.go index 6d0ca19f..e0f70448 100644 --- a/internal/pwru/output.go +++ b/internal/pwru/output.go @@ -311,8 +311,8 @@ func getShinfoData(event *Event, o *output) (shinfoData string) { } func getMetaData(event *Event, o *output) (metaData string) { - metaData = fmt.Sprintf("%10d %08x %16s %#04x %-5s %-5s", - event.Meta.Netns, event.Meta.Mark, + metaData = fmt.Sprintf("%-10s %08x %16s %#04x %-5s %-5s", + fmt.Sprintf("%d", event.Meta.Netns), event.Meta.Mark, centerAlignString(o.getIfaceName(event.Meta.Netns, event.Meta.Ifindex), 16), byteorder.NetworkToHost16(event.Meta.Proto), fmt.Sprintf("%d", event.Meta.MTU), From 945cb58420a89fc93cdb82f875613f767628196a Mon Sep 17 00:00:00 2001 From: gray Date: Tue, 21 May 2024 17:21:28 +0800 Subject: [PATCH 15/15] Use 0 instead of 00000000 for MARK Otherwise it's hard to distinguish 00000000 from 08000000. Signed-off-by: gray --- internal/pwru/output.go | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/internal/pwru/output.go b/internal/pwru/output.go index e0f70448..bb82e755 100644 --- a/internal/pwru/output.go +++ b/internal/pwru/output.go @@ -134,7 +134,7 @@ func (o *output) PrintHeader() { fmt.Fprintf(o.writer, " %-16s", "TIMESTAMP") } if o.flags.OutputMeta { - fmt.Fprintf(o.writer, " %-10s %-8s %16s %-6s %-5s %-5s", "NETNS", "MARK", centerAlignString("IFACE", 16), "PROTO", "MTU", "LEN") + fmt.Fprintf(o.writer, " %-10s %-8s %16s %-6s %-5s %-5s", "NETNS", "MARK/x", centerAlignString("IFACE", 16), "PROTO", "MTU", "LEN") } if o.flags.OutputTuple { fmt.Fprintf(o.writer, " %s", "TUPLE") @@ -311,8 +311,9 @@ func getShinfoData(event *Event, o *output) (shinfoData string) { } func getMetaData(event *Event, o *output) (metaData string) { - metaData = fmt.Sprintf("%-10s %08x %16s %#04x %-5s %-5s", - fmt.Sprintf("%d", event.Meta.Netns), event.Meta.Mark, + metaData = fmt.Sprintf("%-10s %-8s %16s %#04x %-5s %-5s", + fmt.Sprintf("%d", event.Meta.Netns), + fmt.Sprintf("%x", event.Meta.Mark), centerAlignString(o.getIfaceName(event.Meta.Netns, event.Meta.Ifindex), 16), byteorder.NetworkToHost16(event.Meta.Proto), fmt.Sprintf("%d", event.Meta.MTU),