static int rtnet_stats_show(struct xnvfile_regular_iterator *it, void *data) { struct net_device_stats *stats; struct rtnet_device *rtdev; if (it->pos == 0) { xnvfile_printf(it, "Inter-| Receive " " | Transmit\n"); xnvfile_printf(it, " face |bytes packets errs drop fifo frame " "compressed multicast|bytes packets errs " "drop fifo colls carrier compressed\n"); return 0; } rtdev = __rtdev_get_by_index(it->pos); if (rtdev == NULL) return VFILE_SEQ_SKIP; if (rtdev->get_stats == NULL) { xnvfile_printf(it, "%6s: No statistics available.\n", rtdev->name); return 0; } stats = rtdev->get_stats(rtdev); xnvfile_printf(it, "%6s:%8lu %7lu %4lu %4lu %4lu %5lu %10lu %9lu " "%8lu %7lu %4lu %4lu %4lu %5lu %7lu %10lu\n", rtdev->name, stats->rx_bytes, stats->rx_packets, stats->rx_errors, stats->rx_dropped + stats->rx_missed_errors, stats->rx_fifo_errors, stats->rx_length_errors + stats->rx_over_errors + stats->rx_crc_errors + stats->rx_frame_errors, stats->rx_compressed, stats->multicast, stats->tx_bytes, stats->tx_packets, stats->tx_errors, stats->tx_dropped, stats->tx_fifo_errors, stats->collisions, stats->tx_carrier_errors + stats->tx_aborted_errors + stats->tx_window_errors + stats->tx_heartbeat_errors, stats->tx_compressed); return 0; }
/*** * rtdev_get_by_index - find and lock a rtnet_device by its ifindex * @ifindex: index of device */ struct rtnet_device *rtdev_get_by_index(int ifindex) { struct rtnet_device *rtdev; unsigned long flags; if ((ifindex <= 0) || (ifindex > MAX_RT_DEVICES)) return NULL; rtos_spin_lock_irqsave(&rtnet_devices_rt_lock, flags); rtdev = __rtdev_get_by_index(ifindex); if (rtdev != NULL) atomic_inc(&rtdev->refcount); rtos_spin_unlock_irqrestore(&rtnet_devices_rt_lock, flags); return rtdev; }
static int rtnet_devices_show(struct xnvfile_regular_iterator *it, void *data) { struct rtnet_device *rtdev; if (data == NULL) { xnvfile_printf(it, "Index\tName\t\tFlags\n"); return 0; } rtdev = __rtdev_get_by_index(it->pos); if (rtdev == NULL) return VFILE_SEQ_SKIP; xnvfile_printf(it, "%d\t%-15s %s%s%s%s\n", rtdev->ifindex, rtdev->name, (rtdev->flags & IFF_UP) ? "UP" : "DOWN", (rtdev->flags & IFF_BROADCAST) ? " BROADCAST" : "", (rtdev->flags & IFF_LOOPBACK) ? " LOOPBACK" : "", (rtdev->flags & IFF_PROMISC) ? " PROMISC" : ""); return 0; }