Friday, October 08, 2010

sk_buff structure and 2.6.32 linux kernel

I took me a while to figure out there have been a host of changes to sk_buff structure since 2.4 kernel days. Most important of them being removal of h,nh,mac unions for transport,network and link layer headers. Instead we have skb_network_header, skb_transport_header and skb_mac_header calls for accessing the headers.
for e.g. the netword header method is the following in the sources:

static inline unsigned char *skb_transport_header(const struct sk_buff *skb)

Other methods being similar. An alternative way to access the headers would be to use the protocol helper macros for e.g. the the ip_hdr macro defined in include/linux/ip.h>

struct iphdr* iph;
iph = ip_hdr(skb);

Another important change which I overlooked and lead to lot of system freezes was the netfilter hook handler function. The sk_buff structure passed in the handler is no longer a double pointer (struct sk_buff **skb) but a single pointer to sk_buff structure (struct sk_buff *skb). This last change responsible for a whole wasted day figuring out why the system hanged :) (the change not being part of as recent as 2.6.24 kernel made it harder to figure out)

No comments: