1
votes

I have a linux kernel module that needs to process the data received via netfilter hook as a socket buffer.

This is what I am doing in the callback,

unsigned char *eth = skb_mac_header(skb);
int len = skb->len + 14; //Assuming eth is 14 bytes. Neglecting VLAN case. 

for (int j=0; j < len; j++)
{
     printk("%X ", eth[j]);
}

On receiving packets, i get correct length. However he packet contents for some UDP traffic has only correct 48 bytes (initial) and rest of the bytes are not what my interface is receiving. User-space application is receiving correct packet contents as being received on the interface.

Can anyone help explain that what I am doing wrong. Help will be greatly appreciated. Thanks.

1

1 Answers

0
votes

skb_mac_header(skb) gives you the pointer to the mac header. It's valid length is skb->mac_len.

If you need to dump the user data (payload), you may print each char from skb->data to skb->tail. The following link shows the skb data layout: http://vger.kernel.org/~davem/skb_data.html.