Understanding the network device driver sample – part 2

The interested reader can check the previous articles (links: sample skeleton driver and loading the skeleton driver) before going through this article.

In the sample skeleton driver, a set of callbacks were defined and later registered with the Linux network stack. The code snippet is shown below

  • callbacks for the network interface

  • allocating the network device and registering the network device

In the above code snippets, the network device is allocated via alloc_netdev API. The API has a setup function passed as a parameter net_init which performs basic initialization and sets the dev->netdev_ops to the callbacks defined for this driver as shown below:

The register_netdev API call registers the network device with the Linux network stack. The two APIs that are registered in the network ops – net_open and net_stop allow the network device to be brought up or brought down via ifconfig command as shown below.

dmesg command provides the print statements from the kernel module for stop and start.

The net_xmit function that is registered with the Linux network stack is the the data packet entry point for the network device driver. The current skeleton device driver does not do anything in the transmit routine and drops the incoming packet. The code snippet is shown below:

But, it is possible to see if the packet is reaching the interface. We will use ping command to send a packet to our skeleton networking device driver (choosing 8.8.8.8 google public DNS as destination) as shown below and check the dmesg logs to see if the packet is reaching the net_xmit callback registered with Linux for transmit via ndo_start_xmit. The ping command will fail but the packet should reach the driver interface for transmit.

.

Comments

  1. Pingback: Understanding the network device driver sample | Hitch Hiker's Guide to Learning

Leave a Reply

Your email address will not be published. Required fields are marked *