Skip to content

Conversation

msune
Copy link
Member

@msune msune commented Aug 13, 2025

This small patchset improves:

  • trace_diff_pkts.py by:
    • Showing the diff between the expected packet and the one received, (potentially) field by field. This is done
      after dumping both packets.
    • Print pkt lengths in bytes as part of dumping the packets.
    • Changes formatting to make it easier to read.
  • ASSERT_CTX_BUF_OFF by:
    • Unconditionally dumping packets, even when lengths mismatch.
    • Adds useful info in the assert message (e.g. sizes).

Before this patch series

Example of CTX len < LEN
time=2025-08-13T16:02:22.755411559+02:00 level=info msg="Initializing dissection cache..."
--- FAIL: TestBPF (14.12s)
    --- FAIL: TestBPF/tc_l2_announcement.o (0.07s)
        --- FAIL: TestBPF/tc_l2_announcement.o/1_happy_path (0.00s)
            bpf_test.go:457: tc_l2_announcement.c:150: CTX size - offset < LEN tc_l2_announcement.c:150
        bpf_test.go:62: -> 1: [error]
FAIL
FAIL	github.com/cilium/cilium/bpf/tests/bpftest	14.144s
FAIL
Example of buffer length < LEN:
--- FAIL: TestBPF (14.51s)
    --- FAIL: TestBPF/tc_l2_announcement.o (0.08s)
        --- FAIL: TestBPF/tc_l2_announcement.o/1_happy_path (0.00s)
            bpf_test.go:457: tc_l2_announcement.c:150: CTX and buffer 'EXPECTED_ARP_REP' mismatch tc_l2_announcement.c:150
        bpf_test.go:62: -> 1: [error]
FAIL
FAIL	github.com/cilium/cilium/bpf/tests/bpftest	14.533s
FAIL
=== Start tc_l2_announcement.c:150 'arp_rep_ok' ===
--- Expected ---
###[ Ethernet ]### 
  dst       = de:ad:be:ef:de:ef
  src       = 13:37:13:37:13:37
  type      = 0x9000

--- Got ---
###[ Ethernet ]### 
  dst       = de:ad:be:ef:de:ef
  src       = 13:37:13:37:13:37
  type      = ARP

===  End  tc_l2_announcement.c:150 'arp_rep_ok' ===

After:

Simple diff:

--- FAIL: TestBPF (15.31s)
    --- FAIL: TestBPF/tc_l2_announcement.o (0.07s)
        --- FAIL: TestBPF/tc_l2_announcement.o/1_happy_path (0.00s)
            bpf_test.go:457: tc_l2_announcement.c:150: CTX and buffer 'EXPECTED_ARP_REP' content mismatch 
        bpf_test.go:62: -> 1: [error]
FAIL
FAIL	github.com/cilium/cilium/bpf/tests/bpftest	15.344s
FAIL
=== START tc_l2_announcement.c:150 'arp_rep_ok' ===
>>> Expected (len: 42 bytes) <<<
###[ Ethernet ]### 
  dst       = de:ad:be:ef:de:ef
  src       = 31:41:59:26:35:89
  type      = ARP
###[ ARP ]### 
     hwtype    = Ethernet (10Mb)
     ptype     = IPv4
     hwlen     = 6
     plen      = 4
     op        = is-at
     hwsrc     = 13:37:13:37:13:37
     psrc      = 172.16.10.1
     hwdst     = de:ad:be:ef:de:ef
     pdst      = 0.0.0.53

>>> Got (len: 42 bytes) <<<
###[ Ethernet ]### 
  dst       = de:ad:be:ef:de:ef
  src       = 13:37:13:37:13:37
  type      = ARP
###[ ARP ]### 
     hwtype    = Ethernet (10Mb)
     ptype     = IPv4
     hwlen     = 6
     plen      = 4
     op        = is-at
     hwsrc     = 13:37:13:37:13:37
     psrc      = 172.16.10.1
     hwdst     = de:ad:be:ef:de:ef
     pdst      = 110.0.11.1

>>> Diff <<<
  --- a/pkt (Expected)
  +++ b/pkt (Got)

  - [ Ether ].src: 31:41:59:26:35:89
  + [ Ether ].src: 13:37:13:37:13:37
  - [ Ether ][ ARP ].pdst: 0.0.0.53
  + [ Ether ][ ARP ].pdst: 110.0.11.1

=== END tc_l2_announcement.c:150 'arp_rep_ok' ===
Example of CTX len < LEN
    --- FAIL: TestBPF (14.35s)
        --- FAIL: TestBPF/tc_l2_announcement.o (0.07s)
            --- FAIL: TestBPF/tc_l2_announcement.o/1_happy_path (0.00s)
                bpf_test.go:457: tc_l2_announcement.c:150: CTX len (46) - offset (4) < LEN (65)
            bpf_test.go:62: -> 1: [error]
    FAIL
    FAIL    github.com/cilium/cilium/bpf/tests/bpftest      14.372s
    FAIL
    === START tc_l2_announcement.c:150 'arp_rep_ok' ===
    >>> Expected (len: 65 bytes) <<<
      dst       = de:ad:be:ef:de:ef
      src       = 13:37:13:37:13:37
      type      = IPv4
         version   = 4
         ihl       = 5
         tos       = 0x0
         len       = 51
         id        = 1
         flags     =
         frag      = 0
         ttl       = 64
         proto     = tcp
         chksum    = 0x7cc2
         src       = 127.0.0.1
         dst       = 127.0.0.1
         \options   \
            sport     = ftp_data
            dport     = http
            seq       = 0
            ack       = 0
            dataofs   = 5
            reserved  = 0
            flags     = S
            window    = 8192
            chksum    = 0x1fa3
            urgptr    = 0
            options   = []
               load      = 'Hello world'
    
    >>> Got (len: 42 bytes) <<<
      dst       = de:ad:be:ef:de:ef
      src       = 13:37:13:37:13:37
      type      = ARP
         hwtype    = Ethernet (10Mb)
         ptype     = IPv4
         hwlen     = 6
         plen      = 4
         op        = is-at
         hwsrc     = 13:37:13:37:13:37
         psrc      = 172.16.10.1
         hwdst     = de:ad:be:ef:de:ef
         pdst      = 110.0.11.1
    
    >>> Diff <<<
      --- a/pkt (Expected)
      +++ b/pkt (Got)
    
      - [ Ether ].type: 2048
      + [ Ether ].type: 2054
      - [ Ether ][ IP ].options: []
      - [ Ether ][ IP ].version: 4
      - [ Ether ][ IP ].ihl: 5
      - [ Ether ][ IP ].tos: 0
      - [ Ether ][ IP ].len: 51
      - [ Ether ][ IP ].id: 1
      - [ Ether ][ IP ].flags:
      - [ Ether ][ IP ].frag: 0
      - [ Ether ][ IP ].ttl: 64
      - [ Ether ][ IP ].proto: 6
      - [ Ether ][ IP ].chksum: 31938
      - [ Ether ][ IP ].src: 127.0.0.1
      - [ Ether ][ IP ].dst: 127.0.0.1
      - [ Ether ][ IP ][ TCP ].sport: 20
      - [ Ether ][ IP ][ TCP ].dport: 80
      - [ Ether ][ IP ][ TCP ].seq: 0
      - [ Ether ][ IP ][ TCP ].ack: 0
      - [ Ether ][ IP ][ TCP ].dataofs: 5
      - [ Ether ][ IP ][ TCP ].reserved: 0
      - [ Ether ][ IP ][ TCP ].flags: S
      - [ Ether ][ IP ][ TCP ].window: 8192
      - [ Ether ][ IP ][ TCP ].chksum: 8099
      - [ Ether ][ IP ][ TCP ].urgptr: 0
      - [ Ether ][ IP ][ TCP ].options: []
      - [ Ether ][ IP ][ TCP ][ Raw ].load: b'Hello world'
      + [ Ether ][ ARP ].hwtype: 1
      + [ Ether ][ ARP ].ptype: 2048
      + [ Ether ][ ARP ].hwlen: 6
      + [ Ether ][ ARP ].plen: 4
      + [ Ether ][ ARP ].op: 2
      + [ Ether ][ ARP ].hwsrc: 13:37:13:37:13:37
      + [ Ether ][ ARP ].psrc: 172.16.10.1
      + [ Ether ][ ARP ].hwdst: de:ad:be:ef:de:ef
      + [ Ether ][ ARP ].pdst: 110.0.11.1
    
    === END tc_l2_announcement.c:150 'arp_rep_ok' ===
Example of buffer length < LEN:
    --- FAIL: TestBPF (14.42s)
        --- FAIL: TestBPF/tc_l2_announcement.o (0.07s)
            --- FAIL: TestBPF/tc_l2_announcement.o/1_happy_path (0.00s)
                bpf_test.go:457: tc_l2_announcement.c:151: Buffer 'EXPECTED_ARP_REP' of len (14) < LEN (42)
            bpf_test.go:62: -> 1: [error]
    FAIL
    FAIL    github.com/cilium/cilium/bpf/tests/bpftest      14.444s
    FAIL
    === START tc_l2_announcement.c:151 'arp_rep_ok' ===
    >>> Expected (len: 14 bytes) <<<
      dst       = de:ad:be:ef:de:ef
      src       = 13:37:13:37:13:37
      type      = 0x9000
    
    >>> Got (len: 42 bytes) <<<
      dst       = de:ad:be:ef:de:ef
      src       = 13:37:13:37:13:37
      type      = ARP
         hwtype    = Ethernet (10Mb)
         ptype     = IPv4
         hwlen     = 6
         plen      = 4
         op        = is-at
         hwsrc     = 13:37:13:37:13:37
         psrc      = 172.16.10.1
         hwdst     = de:ad:be:ef:de:ef
         pdst      = 110.0.11.1
    
    >>> Diff <<<
      --- a/pkt (Expected)
      +++ b/pkt (Got)
    
      - [ Ether ].type: 36864
      + [ Ether ].type: 2054
      + [ Ether ][ ARP ].hwtype: 1
      + [ Ether ][ ARP ].ptype: 2048
      + [ Ether ][ ARP ].hwlen: 6
      + [ Ether ][ ARP ].plen: 4
      + [ Ether ][ ARP ].op: 2
      + [ Ether ][ ARP ].hwsrc: 13:37:13:37:13:37
      + [ Ether ][ ARP ].psrc: 172.16.10.1
      + [ Ether ][ ARP ].hwdst: de:ad:be:ef:de:ef
      + [ Ether ][ ARP ].pdst: 110.0.11.1
    
    === END tc_l2_announcement.c:151 'arp_rep_ok' ===

@msune msune requested a review from a team as a code owner August 13, 2025 14:08
@msune msune requested a review from YutaroHayakawa August 13, 2025 14:08
@maintainer-s-little-helper maintainer-s-little-helper bot added the dont-merge/needs-release-note-label The author needs to describe the release impact of these changes. label Aug 13, 2025
@msune
Copy link
Member Author

msune commented Aug 13, 2025

cc @smagnani96

@smagnani96 smagnani96 self-requested a review August 13, 2025 16:15
msune added 2 commits August 15, 2025 10:10
This commit improves `trace_diff_pkts.py` by:

* Showing the diff, (potentially) field by field. This is done
   _after_ the dump of the entire packet.
* Print pkt lengths in bytes.
* Changes formatting to make it easier to read.

Signed-off-by: Marc Suñé <marc.sune@isovalent.com>
Prior to this commit, if packet lengths were mismatching,
`ASSERT_CTX_BUF_OFF` was NOT attempting to dump the packet.

This commit:

* Modifies `ASSERT_CTX_BUF_OFF` logic so that packets are always dumped.
* Adds useful info in the assert message (e.g. sizes).

Signed-off-by: Marc Suñé <marc.sune@isovalent.com>
@msune msune force-pushed the bpf_improve_trace_diff_pkts branch from 845dd37 to 399a8e9 Compare August 15, 2025 08:10
@msune
Copy link
Member Author

msune commented Aug 15, 2025

/test

@msune
Copy link
Member Author

msune commented Aug 15, 2025

(rebased to workaround flakes)

@msune
Copy link
Member Author

msune commented Aug 15, 2025

🟢 Ready to merge. No release note necessary

@gentoo-root gentoo-root added the release-note/misc This PR makes changes that have no direct user impact. label Aug 15, 2025
@maintainer-s-little-helper maintainer-s-little-helper bot added ready-to-merge This PR has passed all tests and received consensus from code owners to merge. and removed dont-merge/needs-release-note-label The author needs to describe the release impact of these changes. labels Aug 15, 2025
@msune
Copy link
Member Author

msune commented Aug 19, 2025

4 days in ready-to-merge with all green lights, yet not merged. Can someone please merge?

cc @aanm @joestringer @brb

@aanm aanm added this pull request to the merge queue Aug 19, 2025
Merged via the queue into cilium:main with commit 2c7c686 Aug 19, 2025
68 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ready-to-merge This PR has passed all tests and received consensus from code owners to merge. release-note/misc This PR makes changes that have no direct user impact.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants