Device Drivers & Kernel Modules

a network device

A network card is the odd one out among devices: you do not read() or write() it through /dev like a file, and there is no /dev/eth0 to open. Instead it is a doorway through which packets enter and leave the machine. A network device is the kernel's model of a network interface — a struct net_device — and its driver's whole job is to move packets between the hardware and the kernel's networking stack, not bytes between an application and a file.

The driver registers a net_device with the kernel and supplies operations like ndo_open, ndo_stop, and ndo_start_xmit (transmit). On the send side, when the IP stack has a packet to go out, it calls the driver's transmit function with an sk_buff (a 'socket buffer', the kernel's packet container); the driver hands that buffer's data to the card, usually by setting up a DMA descriptor. On the receive side, the card raises an interrupt when packets arrive; the driver (today usually via NAPI) pulls the packets out of the card's receive ring, wraps each in an sk_buff, and pushes it up into the stack with a call like netif_receive_skb. Applications never touch the device directly — they use sockets, and the kernel's TCP/IP code sits in between.

Network devices matter because they are the most performance-critical driver class: a fast card can deliver millions of packets per second, so the receive path is heavily optimized (this is exactly why NAPI exists). A common misconception is that you talk to a NIC like a character device; you do not. There is no byte-stream file interface — the abstraction is packet in, packet out, and the driver speaks to the networking subsystem, configured through tools like ip and ethtool rather than through a device node.

static const struct net_device_ops my_ops = { .ndo_open = my_open, // bring interface up .ndo_stop = my_stop, // bring it down .ndo_start_xmit = my_xmit, // send one sk_buff }; // no /dev node; configured via: $ ip link set eth0 up

A network driver exposes packet operations, not file read/write; it has no device node and is configured via ip/ethtool.

A NIC has no /dev node and no byte-stream file interface; you do not read()/write() it. Its model is packet-in, packet-out through sk_buffs, talking to the networking stack, not the VFS.

Also called
netdevnet_deviceNIC driver網路介面驅動程式