From f86d5cf0acf710dd39e2bbfc15130c7cd3bbc33c Mon Sep 17 00:00:00 2001 From: Mina Almasry Date: Mon, 4 Sep 2023 12:06:06 +0000 Subject: [PATCH] drgn.helpers.linux.net: add basic skb_dump helper Signed-off-by: Mina Almasry --- drgn/helpers/linux/net.py | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/drgn/helpers/linux/net.py b/drgn/helpers/linux/net.py index b631cde2f..7a9c7769f 100644 --- a/drgn/helpers/linux/net.py +++ b/drgn/helpers/linux/net.py @@ -35,6 +35,7 @@ "skb_is_nonlinear", "skb_tailroom", "skb_availroom", + "skb_dump", ) @@ -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))