The Socket Buffers
We’ve now discussed most of the issues related to network interfaces.
What’s still missing is some more detailed discussion of the
sk_buff structure. The structure is at the core of
the network subsystem of the Linux kernel, and we now introduce both
the main fields of the structure and the functions used to act on it.
Although there is no strict need to understand the internals of
sk_buff, the ability to look at its contents can be
helpful when you are tracking down problems and when you are trying to
optimize the code. For example, if you look in
loopback.c, you’ll find an optimization based on
knowledge of the sk_buff internals. The usual
warning applies here: if you write code that takes advantage of
knowledge of the sk_buff structure, you should be
prepared to see it break with future kernel releases. Still,
sometimes the performance advantages justify the additional
maintenance cost.
We are not going to describe the whole structure here, just the fields
that might be used from within a driver. If you want to see more, you
can look at <linux/skbuff.h>, where the
structure is defined and the functions are prototyped. Additional
details about how the fields and functions are used can be easily
retrieved by grepping in the kernel sources.
The Important Fields
The fields introduced here are the ones a driver might need to access. They are listed in no particular order.
-
struct net_device *rx_dev;,struct net_device *dev; The devices receiving and sending ...