SlideShare a Scribd company logo
3
Most read
7
Most read
10
Most read
© 2010-16 SysPlay Workshops <workshop@sysplay.in>
All Rights Reserved.
Network Drivers
2© 2010-16 SysPlay Workshops <workshop@sysplay.in>
All Rights Reserved.
What to Expect?
Understanding Network Subsystem
Network Drivers: A different category
Writing Network Drivers
3© 2010-16 SysPlay Workshops <workshop@sysplay.in>
All Rights Reserved.
Network Subsystem
(Network) Protocol Stack
Typically, the TCP/IP Stack
Interfaces with the User Space through network interfaces, instead
of device files
Unlike other drivers, does not provide any /sys or /dev entries
Interface Examples: eth0, wlan1, …
Resides in the <kernel_source>/net folder
Network Interface Card (NIC) Drivers
Driver for the Physical Network Cards
Provides uniform hardware independent interface for the network
protocol layer to access the card
Typically, resides in the <kernel_source>/drivers/net folder
4© 2010-16 SysPlay Workshops <workshop@sysplay.in>
All Rights Reserved.
Related Data Structures
Writing a NIC or Network Driver involves
Interacting with the underlying Card over its I/O Bus
Providing the standard APIs to the Protocol Stack
This needs three kind of Data Structures
Core of Protocol Stack
struct sk_buff
NIC & Protocol Stack Interface
struct net_device
NIC I/O bus, e.g. PCI, USB, …
I/O bus specific data structure
5© 2010-16 SysPlay Workshops <workshop@sysplay.in>
All Rights Reserved.
struct sk_buff
Network Packet Descriptor
Header: <linux/skbuff.h>
Driver relevant Fields
head – points to the start of the packet
tail – points to the end of the packet
data – points to the start of the pkt payload
end – points to the end of the packet payload
len – amount of data that the packet contains
6© 2010-16 SysPlay Workshops <workshop@sysplay.in>
All Rights Reserved.
Socket Buffer APIs
Header: <linux/skbuff.h>
SK Buffer Storage
struct sk_buff *dev_alloc_skb(len);
dev_kfree_skb(skb);
SK Buffer Operations
void skb_reserve(struct sk_buff *, int len);
struct sk_buff *skb_clone(struct sk_buff *, gfp_t);
unsigned char *skb_put(struct sk_buff *, int len);
7© 2010-16 SysPlay Workshops <workshop@sysplay.in>
All Rights Reserved.
The Big Picture
(with a PCI NIC)
Network
Stack
sk_buff
net_device
eth0
system calls
ifconfig ping tcpdump ...
PCI Driver
handler
Tx
dpv
Network
Vertical
PCI
Horizontal
NIC Driver
PCI Core
PCI Ctrl Drv
PCI Host Ctrl
DMA
Ctrl
System RAM
Tx
Buf
Rx
Buf
PHY
NIC
PCI
Cfg
Space
Reg
Space
sk_buff...
CPU
User
Space
Kernel
Space
Hardware
Space
poll
Soft IRQ
TxDesc
RxDesc
8© 2010-16 SysPlay Workshops <workshop@sysplay.in>
All Rights Reserved.
struct net_device
Header: <linux/netdevice.h>
Driver relevant Operation Fields
Activation: open, stop, ioctl
Data Transfer: start_xmit, poll (NAPI: new API)
WatchDog: tx_timeout, int watchdog_timeo
Statistics: get_stats, get_wireless_stats
Typically uses struct net_device_stats, populated earlier
Configuration: struct *ethtool_ops, change_mtu
Structure defined in Header: <linux/ethtool.h>
Bus Specific: mem_start, mem_end
Latest kernels have all the operations moved under
struct net_dev_ops
And typically, a prefix ndo_ added and some name changes
9© 2010-16 SysPlay Workshops <workshop@sysplay.in>
All Rights Reserved.
Net Device Registration
Header: <linux/netdevice.h>
Net Device Storage
struct net_device *alloc_etherdev(sizeof_priv);
struct net_device *alloc_ieee80211dev(sizeof_priv);
struct net_device *alloc_irdadev(sizeof_priv);
struct net_device *alloc_netdev(sizeof_priv, name, setup_fn);
void free_netdev(struct net_device *);
Registering the Net Device
int register_netdev(struct net_device *);
void unregister_netdev(struct net_device *);
10© 2010-16 SysPlay Workshops <workshop@sysplay.in>
All Rights Reserved.
Network Device Open & Close
A typical Network Device Open
Allocates ring buffers and associated sk_buffs
Initializes the Device
Gets the MAC, … from device EEPROM
Requests firmware download, if needed
int request_firmware(fw, name, device);
Register the interrupt handler(s)
A typical Network Device Close
Would do the reverse in chronology reverse order
11© 2010-16 SysPlay Workshops <workshop@sysplay.in>
All Rights Reserved.
Packet Receive Interrupt Handler
A typical receive interrupt handler
Minimally handles the packet received
Sanity checks
Puts back equal number of sk_buffs for re-use
Passes the associated sk_buffs (& ring buffers) to the
protocol layer by the NET_RX_SOFTIRQ
On higher load, switch to poll mode, if supported,
which then passes the associated sk_buffs (& ring
buffers) to the protocol layer by the
NET_RX_SOFTIRQ
12© 2010-16 SysPlay Workshops <workshop@sysplay.in>
All Rights Reserved.
Flow Control related APIs
For interaction with the protocol layer
Header: <linux/netdevice.h>
APIs
void netif_start_queue(struct net_device *);
void netif_stop_queue(struct net_device *);
void netif_wake_queue(struct net_device *);
int netif_queue_stopped(struct net_device *);
13© 2010-16 SysPlay Workshops <workshop@sysplay.in>
All Rights Reserved.
Network Driver Examples
Driver: snull
Browse & Discuss
Driver for Realtek NIC 8136
Browse & Hack
14© 2010-16 SysPlay Workshops <workshop@sysplay.in>
All Rights Reserved.
What all have we learnt?
Linux Network Subsystem
How are Network Drivers different?
Writing Network Drivers
Key Data Structures & their APIs
sk_buff & net_device
Network Device Registration
Network Device Operations
Interrupt Handling for Packets received
Flow Control related APIs
15© 2010-16 SysPlay Workshops <workshop@sysplay.in>
All Rights Reserved.
Any Queries?

More Related Content

PDF
Meet cute-between-ebpf-and-tracing
PPTX
The TCP/IP Stack in the Linux Kernel
PPTX
Memory model
PPTX
Linux 802.11 subsystem and brcmsmac WLAN driver
PDF
U-Boot - An universal bootloader
PDF
LinuxCon 2015 Linux Kernel Networking Walkthrough
PDF
USB Drivers
Meet cute-between-ebpf-and-tracing
The TCP/IP Stack in the Linux Kernel
Memory model
Linux 802.11 subsystem and brcmsmac WLAN driver
U-Boot - An universal bootloader
LinuxCon 2015 Linux Kernel Networking Walkthrough
USB Drivers

What's hot (20)

PDF
The linux networking architecture
PPT
U boot porting guide for SoC
PDF
Embedded linux network device driver development
PPTX
Linux device drivers
PDF
Analysis of Open-Source Drivers for IEEE 802.11 WLANs
PDF
netfilter and iptables
PDF
Arm device tree and linux device drivers
PDF
Tutorial WiFi driver code - Opening Nuts and Bolts of Linux WiFi Subsystem
PPTX
QEMU - Binary Translation
PPTX
Linux Kernel MMC Storage driver Overview
PDF
Embedded Linux BSP Training (Intro)
PPTX
Linux Memory Management
PDF
Introduction to Linux Drivers
PDF
A practical guide to buildroot
PDF
Architecture Of The Linux Kernel
PDF
I2C Subsystem In Linux-2.6.24
PPTX
Slab Allocator in Linux Kernel
PDF
Interrupts
PPTX
Linux Device Tree
PDF
The Linux Block Layer - Built for Fast Storage
The linux networking architecture
U boot porting guide for SoC
Embedded linux network device driver development
Linux device drivers
Analysis of Open-Source Drivers for IEEE 802.11 WLANs
netfilter and iptables
Arm device tree and linux device drivers
Tutorial WiFi driver code - Opening Nuts and Bolts of Linux WiFi Subsystem
QEMU - Binary Translation
Linux Kernel MMC Storage driver Overview
Embedded Linux BSP Training (Intro)
Linux Memory Management
Introduction to Linux Drivers
A practical guide to buildroot
Architecture Of The Linux Kernel
I2C Subsystem In Linux-2.6.24
Slab Allocator in Linux Kernel
Interrupts
Linux Device Tree
The Linux Block Layer - Built for Fast Storage
Ad

Viewers also liked (19)

PDF
File System Modules
PDF
Block Drivers
PDF
PCI Drivers
PDF
Kernel Debugging & Profiling
PDF
Embedded C
PDF
gcc and friends
PDF
References
PDF
Character Drivers
PDF
Video Drivers
PDF
Low-level Accesses
PDF
Kernel Programming
PDF
Audio Drivers
PDF
BeagleBone Black Bootloaders
PDF
Linux Porting
PDF
BeagleBoard-xM Bootloaders
PDF
File Systems
File System Modules
Block Drivers
PCI Drivers
Kernel Debugging & Profiling
Embedded C
gcc and friends
References
Character Drivers
Video Drivers
Low-level Accesses
Kernel Programming
Audio Drivers
BeagleBone Black Bootloaders
Linux Porting
BeagleBoard-xM Bootloaders
File Systems
Ad

Similar to Network Drivers (20)

PDF
Df35592595
PDF
Hands-on ethernet driver
PPTX
Linux Network Stack
PDF
International Journal of Computational Engineering Research(IJCER)
PDF
VLANs in the Linux Kernel
PPT
Input output in linux
PDF
Userspace networking
PDF
Linux Network Management
ODP
Sockets and Socket-Buffer
PDF
Geep networking stack-linuxkernel
PPT
Linux io
PDF
Fun with Network Interfaces
PDF
Ccna interview questions
PDF
Kernel Recipes 2019 - Metrics are money
PPT
Chapter05 -- networking hardware
PPTX
02 Introduction to Ethernet_Common_11.5_f2.pptx
PPTX
Network interface card(nic)
PDF
Ch14.run time support systems
PPT
Ccna introduction
Df35592595
Hands-on ethernet driver
Linux Network Stack
International Journal of Computational Engineering Research(IJCER)
VLANs in the Linux Kernel
Input output in linux
Userspace networking
Linux Network Management
Sockets and Socket-Buffer
Geep networking stack-linuxkernel
Linux io
Fun with Network Interfaces
Ccna interview questions
Kernel Recipes 2019 - Metrics are money
Chapter05 -- networking hardware
02 Introduction to Ethernet_Common_11.5_f2.pptx
Network interface card(nic)
Ch14.run time support systems
Ccna introduction

More from Anil Kumar Pugalia (20)

PDF
File System Modules
PDF
Kernel Debugging & Profiling
PDF
PDF
System Calls
PDF
Introduction to Linux
PDF
Embedded Software Design
PDF
Playing with R L C Circuits
PDF
Mobile Hacking using Linux Drivers
PDF
Shell Scripting
PDF
Functional Programming with LISP
PDF
Power of vi
PDF
"make" system
PDF
Hardware Design for Software Hackers
PDF
RPM Building
PDF
Linux User Space Debugging & Profiling
PDF
System Calls
PDF
PDF
Synchronization
PDF
File System Modules
Kernel Debugging & Profiling
System Calls
Introduction to Linux
Embedded Software Design
Playing with R L C Circuits
Mobile Hacking using Linux Drivers
Shell Scripting
Functional Programming with LISP
Power of vi
"make" system
Hardware Design for Software Hackers
RPM Building
Linux User Space Debugging & Profiling
System Calls
Synchronization

Recently uploaded (20)

PDF
CIFDAQ's Market Insight: SEC Turns Pro Crypto
PDF
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
PPTX
Cloud computing and distributed systems.
PDF
Shreyas Phanse Resume: Experienced Backend Engineer | Java • Spring Boot • Ka...
PDF
Modernizing your data center with Dell and AMD
DOCX
The AUB Centre for AI in Media Proposal.docx
PDF
Diabetes mellitus diagnosis method based random forest with bat algorithm
PPTX
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
PDF
KodekX | Application Modernization Development
PDF
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
PPTX
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
PPTX
Understanding_Digital_Forensics_Presentation.pptx
PPTX
PA Analog/Digital System: The Backbone of Modern Surveillance and Communication
PDF
Dropbox Q2 2025 Financial Results & Investor Presentation
PPTX
A Presentation on Artificial Intelligence
PDF
Approach and Philosophy of On baking technology
PDF
Encapsulation theory and applications.pdf
PDF
Building Integrated photovoltaic BIPV_UPV.pdf
PDF
Reach Out and Touch Someone: Haptics and Empathic Computing
PDF
NewMind AI Monthly Chronicles - July 2025
CIFDAQ's Market Insight: SEC Turns Pro Crypto
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
Cloud computing and distributed systems.
Shreyas Phanse Resume: Experienced Backend Engineer | Java • Spring Boot • Ka...
Modernizing your data center with Dell and AMD
The AUB Centre for AI in Media Proposal.docx
Diabetes mellitus diagnosis method based random forest with bat algorithm
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
KodekX | Application Modernization Development
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
Understanding_Digital_Forensics_Presentation.pptx
PA Analog/Digital System: The Backbone of Modern Surveillance and Communication
Dropbox Q2 2025 Financial Results & Investor Presentation
A Presentation on Artificial Intelligence
Approach and Philosophy of On baking technology
Encapsulation theory and applications.pdf
Building Integrated photovoltaic BIPV_UPV.pdf
Reach Out and Touch Someone: Haptics and Empathic Computing
NewMind AI Monthly Chronicles - July 2025

Network Drivers

  • 1. © 2010-16 SysPlay Workshops <workshop@sysplay.in> All Rights Reserved. Network Drivers
  • 2. 2© 2010-16 SysPlay Workshops <workshop@sysplay.in> All Rights Reserved. What to Expect? Understanding Network Subsystem Network Drivers: A different category Writing Network Drivers
  • 3. 3© 2010-16 SysPlay Workshops <workshop@sysplay.in> All Rights Reserved. Network Subsystem (Network) Protocol Stack Typically, the TCP/IP Stack Interfaces with the User Space through network interfaces, instead of device files Unlike other drivers, does not provide any /sys or /dev entries Interface Examples: eth0, wlan1, … Resides in the <kernel_source>/net folder Network Interface Card (NIC) Drivers Driver for the Physical Network Cards Provides uniform hardware independent interface for the network protocol layer to access the card Typically, resides in the <kernel_source>/drivers/net folder
  • 4. 4© 2010-16 SysPlay Workshops <workshop@sysplay.in> All Rights Reserved. Related Data Structures Writing a NIC or Network Driver involves Interacting with the underlying Card over its I/O Bus Providing the standard APIs to the Protocol Stack This needs three kind of Data Structures Core of Protocol Stack struct sk_buff NIC & Protocol Stack Interface struct net_device NIC I/O bus, e.g. PCI, USB, … I/O bus specific data structure
  • 5. 5© 2010-16 SysPlay Workshops <workshop@sysplay.in> All Rights Reserved. struct sk_buff Network Packet Descriptor Header: <linux/skbuff.h> Driver relevant Fields head – points to the start of the packet tail – points to the end of the packet data – points to the start of the pkt payload end – points to the end of the packet payload len – amount of data that the packet contains
  • 6. 6© 2010-16 SysPlay Workshops <workshop@sysplay.in> All Rights Reserved. Socket Buffer APIs Header: <linux/skbuff.h> SK Buffer Storage struct sk_buff *dev_alloc_skb(len); dev_kfree_skb(skb); SK Buffer Operations void skb_reserve(struct sk_buff *, int len); struct sk_buff *skb_clone(struct sk_buff *, gfp_t); unsigned char *skb_put(struct sk_buff *, int len);
  • 7. 7© 2010-16 SysPlay Workshops <workshop@sysplay.in> All Rights Reserved. The Big Picture (with a PCI NIC) Network Stack sk_buff net_device eth0 system calls ifconfig ping tcpdump ... PCI Driver handler Tx dpv Network Vertical PCI Horizontal NIC Driver PCI Core PCI Ctrl Drv PCI Host Ctrl DMA Ctrl System RAM Tx Buf Rx Buf PHY NIC PCI Cfg Space Reg Space sk_buff... CPU User Space Kernel Space Hardware Space poll Soft IRQ TxDesc RxDesc
  • 8. 8© 2010-16 SysPlay Workshops <workshop@sysplay.in> All Rights Reserved. struct net_device Header: <linux/netdevice.h> Driver relevant Operation Fields Activation: open, stop, ioctl Data Transfer: start_xmit, poll (NAPI: new API) WatchDog: tx_timeout, int watchdog_timeo Statistics: get_stats, get_wireless_stats Typically uses struct net_device_stats, populated earlier Configuration: struct *ethtool_ops, change_mtu Structure defined in Header: <linux/ethtool.h> Bus Specific: mem_start, mem_end Latest kernels have all the operations moved under struct net_dev_ops And typically, a prefix ndo_ added and some name changes
  • 9. 9© 2010-16 SysPlay Workshops <workshop@sysplay.in> All Rights Reserved. Net Device Registration Header: <linux/netdevice.h> Net Device Storage struct net_device *alloc_etherdev(sizeof_priv); struct net_device *alloc_ieee80211dev(sizeof_priv); struct net_device *alloc_irdadev(sizeof_priv); struct net_device *alloc_netdev(sizeof_priv, name, setup_fn); void free_netdev(struct net_device *); Registering the Net Device int register_netdev(struct net_device *); void unregister_netdev(struct net_device *);
  • 10. 10© 2010-16 SysPlay Workshops <workshop@sysplay.in> All Rights Reserved. Network Device Open & Close A typical Network Device Open Allocates ring buffers and associated sk_buffs Initializes the Device Gets the MAC, … from device EEPROM Requests firmware download, if needed int request_firmware(fw, name, device); Register the interrupt handler(s) A typical Network Device Close Would do the reverse in chronology reverse order
  • 11. 11© 2010-16 SysPlay Workshops <workshop@sysplay.in> All Rights Reserved. Packet Receive Interrupt Handler A typical receive interrupt handler Minimally handles the packet received Sanity checks Puts back equal number of sk_buffs for re-use Passes the associated sk_buffs (& ring buffers) to the protocol layer by the NET_RX_SOFTIRQ On higher load, switch to poll mode, if supported, which then passes the associated sk_buffs (& ring buffers) to the protocol layer by the NET_RX_SOFTIRQ
  • 12. 12© 2010-16 SysPlay Workshops <workshop@sysplay.in> All Rights Reserved. Flow Control related APIs For interaction with the protocol layer Header: <linux/netdevice.h> APIs void netif_start_queue(struct net_device *); void netif_stop_queue(struct net_device *); void netif_wake_queue(struct net_device *); int netif_queue_stopped(struct net_device *);
  • 13. 13© 2010-16 SysPlay Workshops <workshop@sysplay.in> All Rights Reserved. Network Driver Examples Driver: snull Browse & Discuss Driver for Realtek NIC 8136 Browse & Hack
  • 14. 14© 2010-16 SysPlay Workshops <workshop@sysplay.in> All Rights Reserved. What all have we learnt? Linux Network Subsystem How are Network Drivers different? Writing Network Drivers Key Data Structures & their APIs sk_buff & net_device Network Device Registration Network Device Operations Interrupt Handling for Packets received Flow Control related APIs
  • 15. 15© 2010-16 SysPlay Workshops <workshop@sysplay.in> All Rights Reserved. Any Queries?