The Socket Buffers
We’ve now discussed most of the issues related to network interfaces.
The next few sections explain in more detail how the sk_buff
structure
is designed. They introduce both the main fields of the structure and
the functions used to act on the socket buffers.
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.
I’m 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
For our purposes, the important fields in the structure are those a driver writer might need. They are listed here in no particular order.
-
struct device *dev;
The device receiving or sending this buffer.
-
__u32 saddr;
,__u32 daddr;
,__u32 raddr;
Source address, destination address, and router address, used by the IP protocol.
raddr
is the first hop the packet must take to reach its destination. These fields are set before the packet is transmitted and need not be assigned when it is received. An outgoing packet reaching ...
Get Linux Device Drivers now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.