Linux Kernel Architecture

(Jacob Rumans) #1

Chapter 12: Networks


In turn, the function uses a type-specific handlerfuncthat assumes further processing of the
packet in the higher layers like IP.
netif_receive_skbalso handles specialties like bridging, but it is not necessary to discuss
these corner cases — at least they are corner cases on average systems — any further.

All network layer functions used to receive data from the underlying network access layer are registered
in a hash table implemented by the global arrayptype_base.^13

New protocols are added by means ofdev_add_pack. The entries are structures of typepacket_type
whose definition is as follows:

<netdevice.h>
struct packet_type {
__be16 type; /* This is really htons(ether_type). */
struct net_device *dev; /* NULL is wildcarded here */
int (*func) (struct sk_buff *,
struct net_device *,
struct packet_type *,
struct net_device *);
...
void *af_packet_priv;
struct list_head list;
};

typespecifies the identifier of the protocol for the handler.devbinds a protocol handler to a specific
network card (a null pointer means that the handler is valid for all network devices of the system).

funcis the central element of the structure. It is a pointer to the network layer function to which the
packet is passed if it has the appropriate type.ip_rcv, discussed below, is used for IPv4-based protocols.

netif_receive_skbfinds the appropriate handler element for a given socket buffer, invokes itsfunc
function, and delegates responsibility for the packet to the network layer — the next higher level of the
network implementation.

Supportfor High-SpeedInterfaces


The previously discussed old approach to transferring packets from the network device into higher layers
of the kernel works well if the devices do not support too high transmission rates. Each time a frame
arrives, an IRQ is used to signalize this to the kernel. This implies a notion of ‘‘fast’’ and ‘‘slow.’’ For slow
devices, servicing the IRQ is usually finished before the next packet arrives. Since the next packet is also
signaled by an IRQ, failing to fulfill this condition — as is often the case for ‘‘fast’’ devices — leads to
problems. Modern Ethernet network cards operateat speeds of 10,000 MBit/s, and this would cause true
interrupt storms if the old methods were used to drive them. However if a new IRQ is received while
packets are still waiting to be processed, no new information is conveyed to the kernel: It was known
before that packets are waiting to be processed, and it is known afterward that packets are supposed to
be processed — which is not really any news. To solve this problem, NAPI uses a combination of IRQs
and polling.

(^13) Actually, another list with packet handlers is available.ptype_allcontains packet handlers that are called for all packet types.

Free download pdf