Network Buffers and Memory Management

Writing a network device driver for Linux is fundamentally simple—most of the complexity (other than talking to the hardware) involves managing network packets in memory.

Ethernet Support Routines

Ethernet is probably the most common physical interface type
that can be handled. The kernel provides a set of general purpose
Ethernet support routines that such drivers can use.

eth_header() is the standard Ethernet
handler for the dev-hard_header routine, and can
be used in any Ethernet driver. Combined with
eth_rebuild_header() for the rebuild routine it
provides all the ARP lookup required to put Ethernet headers on IP
packets.

The eth_type_trans() routine expects to be
fed a raw Ethernet packet. It analyses the headers and sets
skb->pkt_type and
skb->mac itself as well as returning the
suggested value for skb->protocol. This
routine is normally called from the Ethernet driver receive
interrupt handler to classify packets.

eth_copy_and_sum(), the final Ethernet
support routine is internally quite complex, but offers significant
performance improvements for memory mapped cards. It provides the
support to copy and checksum data from the card into a
sk_buff in a single pass. This single pass
through memory almost eliminates the cost of checksum computation
when used and improves IP throughput.

Alan Cox
has been working on Linux since version 0.95, when
he installed it in order to do further work on the AberMUD game. He
now manages the Linux Networking, SMP, and Linux/8086 projects and
hasn't done any work on AberMUD since November 1993.

Comment viewing options

An admirable in-depth article. Just a stupid question (I'm so slow-witted) : I still don't catch the link between the rmem_default/rmem_max sysctl parameters (socket receive buffer default/max length) and the buffer allocated by dev_alloc_skb(). Socket receive buffer vs buffer of skb : are we talking about he same memory area, or are they different things (involving necessarily a copy from the one to the other, sooner or later) ?

The links to figures do not work (File not found error). I guess time does matter (1996 article!). To anyone reading this article, please provide us some links for the pictures (or link to some other up to date articles).

Hi Alan Cox,
Thanx for the article.
Iam Ram.Iam new to device driver development.
some how i manged to write a network driver.
still i need some help.But I want to access the driver functions directly from user program written in c.

i.e. I want to access the open,close,hard_start_xmit(),ioctl functions directly without using the socket api(socket,bind,connect etc). I want my own function api.
is it possible to do it.

thanks for this article. It explains most of the things. But still I feel that some more thing related to Bottom Half/Top half processing should be added. and also things are not clear about the logic of freeing/owning skbuffers.

Trending Topics

Webinar: 8 Signs You’re Beyond Cron

Scheduling Crontabs With an Enterprise Scheduler
11am CDT, April 29th

Join Linux Journal and Pat Cameron, Director of Automation Technology at HelpSystems, as they discuss the eight primary advantages of moving beyond cron job scheduling. In this webinar, you’ll learn about integrating cron with an enterprise scheduler.