Linux Kernel Architecture

(Jacob Rumans) #1

Chapter 12: Networks


int (*init)(struct net *net);
void (*exit)(struct net *net);
};

The structure does not present any surprises:initstores an initialization function, while clean-up
work is handled byexit. All availablepernet_operationinstances are kept on a list headed by
pernet_list;listis used as the list element. The auxiliary functionsregister_pernet_subsysand
unregister_pernet_subsysadd and remove elements to and from the list, respectively. Whenever
a new networking namespace is created, the kernel iterates over the list ofpernet_operationsand
calls the initialization function with thenetinstance that represents the new namespace as parameter.
Cleaning up when a networking namespace is deleted is handled similarly.

Most computers will typically require only a single networking namespace. The global variableinit_net
(and in this case, the variable isreallyglobal and not contained in another namespace!) contains thenet
instance for this namespace. In the following, I mostly neglect namespaces to simplify matters. It suffices
to keep in mind that all global functions of the network layer require a network namespace as parameter,
and that any global properties of the networking subsystem may only be referenced by a detour through
the namespace under consideration.

12.6 Socket Buffers


When network packets are analyzed in the kernel, the data of lower-level protocols are passed to higher-
level layers. The reverse sequence applies when data are sent. The data (header and payload) generated
by the various protocols are successively passed to lower layers until they are finally transmitted. As
the speed of these operations is crucial to network layer performance, the kernel makes use of a special
structure known as asocket buffer, which is defined as follows:

<skbuff.h>
struct sk_buff {
/* These two members must be first. */
struct sk_buff *next;
struct sk_buff *prev;

struct sock *sk;
ktime_t tstamp;
struct net_device *dev;

struct dst_entry *dst;

char cb[48];

unsigned int len,
data_len;
__u16 mac_len,
hdr_len;
union {
__wsum csum;
struct {
__u16 csum_start;
Free download pdf