Skip to content

Commit

Permalink
drgn.helpers.linux.net: add basic skb_dump helper
Browse files Browse the repository at this point in the history
Signed-off-by: Mina Almasry <[email protected]>
  • Loading branch information
mina committed Sep 4, 2023
1 parent 06d475d commit f86d5cf
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions drgn/helpers/linux/net.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
"skb_is_nonlinear",
"skb_tailroom",
"skb_availroom",
"skb_dump",
)


Expand Down Expand Up @@ -315,3 +316,32 @@ def skb_mac_header_was_set(skb: Object) -> int:
def skb_transport_header_was_set(skb: Object) -> int:
prog = skb.prog_
return skb.transport_header != 65535;


def skb_dump(skb: Object) -> None:
prog = skb.prog_

headroom = skb_headroom(skb)
tailroom = skb_tailroom(skb)
sh = skb_shinfo(skb)

has_mac = skb_mac_header_was_set(skb)
has_trans = skb_transport_header_was_set(skb)

print("skb len=%u headroom=%u headlen=%u tailroom=%u\n"
"mac=(%d,%d) net=(%d,%d) trans=%d\n"
"shinfo(txflags=%u nr_frags=%u gso(size=%hu type=%u segs=%hu))\n"
"csum(0x%x ip_summed=%u complete_sw=%u valid=%u level=%u)\n"
"hash(0x%x sw=%u l4=%u) proto=0x%04x pkttype=%u iif=%d\n" %
(skb.len, headroom, skb_headlen(skb), tailroom,
skb.mac_header if has_mac else -1,
skb_mac_header_len(skb) if has_mac else -1,
skb.network_header,
skb_network_header_len(skb) if has_trans else -1,
skb.transport_header if has_trans else -1,
sh.tx_flags, sh.nr_frags,
sh.gso_size, sh.gso_type, sh.gso_segs,
skb.csum, skb.ip_summed, skb.csum_complete_sw,
skb.csum_valid, skb.csum_level,
skb.hash, skb.sw_hash, skb.l4_hash,
skb.protocol, skb.pkt_type, skb.skb_iif))

0 comments on commit f86d5cf

Please sign in to comment.