Network Linux Drivers

From KallestadWiki

Jump to: navigation, search

Building a Network Driver for Linux

There are two solid resources for understanding network drivers in Linux. One is the existing source code for open source drivers. Certainly there's some hardware specific code in their, but more importantly, there is a lot of information about how these drivers interact with the OS.

The other resource is a book available on Safari called "Linux Device Drivers". It was originally printed in 2005 (the third edition), but I have yet to find another resource that contains as much information - specifically in Chapter 17.

To be fair, I'm not really looking at building a Network Driver - but instead an ethernet driver. The difference being that I'm only interested in the ethernet specifics of building a Network Driver for Linux. Semantics for some of us. An important distinction for others.

From my basic review, it looks like there are just three important areas that need to be addressed for basic functionality:

  1. initialization/destruction
  2. data structures
  3. functions to manage data

For my purposes, I'm looking at providing a loopback device that does not look like a loopback device on first inspection. The reason for this is that I want to have a fully configurable primary ethernet device - so things like running oracle over dhcp, putting a configurable MAC Address in environments where this is not possible (i.e. VMs), and testing network functionality over a 'real-ish' network device are all possibilities.

Initialization

int drivername_init_module(void)

This seems to be the function that creates the device. From within this function - at least in the examples provided by the book I'm staring at, alloc_netdev is called. You pass in the size of your data structure, the prefix for your structure, and your own personal initialization function.

Once the network device is allocated, you must register the device by calling the function register_netdev.

Personal tools