Saturday, November 28, 2020

Linux: Putting prints in the kernel socket layer

 I was debugging an issue and needed to see if certain packets were making it to the kernel netlink layer. In doing this, I found it easy to trace down by putting hex prints in the kernel packet handling layer.

In the simplest case, it can be done here:

mylinux_machine52> git diff
diff --git a/net/packet/af_packet.c b/net/packet/af_packet.c
index 00d395555586d3e525f2
--- a/net/packet/af_packet.c
+++ b/net/packet/af_packet.c
@@ -1800,6 +1800,7 @@ static int packet_rcv(struct sk_buff *skb, struct net_device *dev,

        snaplen = skb->len;

+       printk("***gb**** ETHER type === 0x%x\n", eth_hdr(skb)->h_proto);
        res = run_filter(skb, sk, snaplen);
        if (!res)

                goto drop_n_restore;

I hope you find this useful.