This section provides a reference for the concepts introduced in this
chapter. It also explains the role of each header file that a driver
needs to include. The lists of fields in the
structures, however, are not repeated here.
This header hosts the definitions of
struct net_device_stats, and includes a few other headers that are needed by network drivers.
int register_netdev(struct net_device *dev);,
void unregister_netdev(struct net_device *dev);
SET_MODULE_OWNER(struct net_device *dev);
This macro will store a pointer to the current module in the device structure (or in any structure with an
ownerfield, actually); it is used to enable the networking subsystem to manage the module’s use count.
netif_start_queue(struct net_device *dev);,
netif_stop_queue(struct net_device *dev);,
netif_wake_queue(struct net_device *dev);
These functions control the passing of packets to the driver for transmission. No packets will be transmitted until netif_start_queue has been called. netif_stop_queue suspends transmission, and netif_wake_queue restarts the queue and pokes the network layer to restart transmitting packets.
void netif_rx(struct sk_buff *skb);
This function can be called (including at interrupt time) to notify the kernel that a packet has been received and encapsulated into a socket buffer.
netdevice.h, this file declares the interface flags (
struct ifmap, which has a major role in the ioctl implementation for network drivers.
void netif_carrier_off(struct net_device *dev);,
void netif_carrier_on(struct net_device *dev);,
int netif_carrier_ok(struct net_device *dev);
The first two functions may be used to tell the kernel whether a carrier signal is currently present on the given interface. netif_carrier_ok will test the carrier state as reflected in the device structure.
if_ether.hdefines all the
ETH_macros used to represent octet lengths (such as the address length) and network protocols (such as IP). It also defines the
The definition of
struct sk_buffand related structures, as well as several inline functions to act on the buffers. This header is included by
struct sk_buff *alloc_skb(unsigned int len, int priority);,
struct sk_buff *dev_alloc_skb(unsigned int len);,
void kfree_skb(struct sk_buff *skb);,
void dev_kfree_skb(struct sk_buff *skb);
These functions handle the allocation and freeing of socket buffers. Drivers should normally use the
dev_variants, which are intended for that purpose.
unsigned char *skb_put(struct sk_buff *skb, int len);,
unsigned char *__skb_put(struct sk_buff *skb, int len);,
unsigned char *skb_push(struct sk_buff *skb, int len);,
unsigned char *__skb_push(struct sk_buff *skb, int len);
These functions add data to an
skb; skb_put puts the data at the end of the
skb, while skb_push puts it at the beginning. The regular versions perform checking to ensure that adequate space is available; double-underscore versions leave those tests out.
int skb_headroom(struct sk_buff *skb);,
int skb_tailroom(struct sk_buff *skb);,
void skb_reserve(struct sk_buff *skb, int len);
These functions perform management of space within an
skb. skb_headroom and skb_tailroom tell how much space is available at the beginning and end, respectively, of an
skb. skb_reserve may be used to reserve space at the beginning of an
skb, which must be empty.
unsigned char *skb_pull(struct sk_buff *skb, int len);
skb_pull will “remove” data from an
skbby adjusting the internal pointers.
void ether_setup(struct net_device *dev);
This function sets most device methods to the general-purpose implementation for Ethernet drivers. It also sets
dev->flagsand assigns the next available
ethx name to
dev->nameif the first character in the name is a blank space or the null character.
unsigned short eth_type_trans(struct sk_buff *skb, struct net_device *dev);
When an Ethernet interface receives a packet, this function can be called to set
skb->pkt_type. The return value is a protocol number that is usually stored in
This is the first of 16 ioctl commands that can be implemented by each driver for its own private use. All the network ioctl commands are defined in
Get Linux Device Drivers, Second Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.