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 structure.
struct net_device_stats *snull_stats(struct net_device *dev)
{
struct snull_priv *priv = (struct snull_priv *) dev->priv;
return &priv->stats;
}
The 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 struct net_device_stats.
-
unsigned long rx_packets;,unsigned long tx_packets; These fields hold 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. These fields were added in the 2.2 kernel.
-
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_statsstructure 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 ...