17.13. Statistical Information
The last method a driver needs is
get_stats. This method returns a pointer to the
statistics for the device. Its implementation is pretty easy; the one
shown works even when several interfaces are managed by the same
driver, because the statistics are hosted within the device data
struct net_device_stats *snull_stats(struct net_device *dev)
struct snull_priv *priv = netdev_priv(dev);
real work needed to return meaningful statistics is distributed
throughout the driver, where the various fields are updated. The
following list shows the most interesting fields in
- unsigned long rx_packets;
- unsigned long tx_packets;
The total number of incoming and outgoing packets successfully
transferred by the interface.
- unsigned long rx_bytes;
- unsigned long tx_bytes;
The number of bytes received and transmitted by the interface.
- unsigned long rx_errors;
- unsigned long tx_errors;
The number of erroneous receptions and transmissions.
There's no end of things that can go wrong with
packet transmission, and the net_device_stats
structure includes six counters for specific receive errors and five
for transmit errors. See
<linux/netdevice.h> for the full list. If
possible, your driver should maintain detailed error statistics,
because they can be most helpful to system administrators trying to
track down a problem.
- unsigned long rx_dropped;
- unsigned long tx_dropped;
The number of packets dropped during reception and transmission.
Packets are dropped when there's no memory available
for packet data. tx_dropped is rarely used.
- unsigned long collisions;
The number of collisions due to congestion on the medium.
- unsigned long multicast;
The number of multicast packets received.
It is worth repeating that the get_stats method
can be called at any time—even when the interface is
down—so the driver must retain statistical information for as
long as the net_device structure exists.