+static void
+convert_stats_tap(struct netdev_stats *stats, const struct if_data *ifd)
+{
+ /*
+ * Similar to convert_stats_system but swapping rxq and tx
+ * because 'ifd' is stats for the network interface side of the
+ * tap device and what the caller wants is one for the character
+ * device side.
+ *
+ * note: UINT64_MAX means unsupported
+ */
+ stats->rx_packets = ifd->ifi_opackets;
+ stats->tx_packets = ifd->ifi_ipackets;
+ stats->rx_bytes = ifd->ifi_ibytes;
+ stats->tx_bytes = ifd->ifi_obytes;
+ stats->rx_errors = ifd->ifi_oerrors;
+ stats->tx_errors = ifd->ifi_ierrors;
+ stats->rx_dropped = UINT64_MAX;
+ stats->tx_dropped = ifd->ifi_iqdrops;
+ stats->multicast = ifd->ifi_omcasts;
+ stats->collisions = UINT64_MAX;
+ stats->rx_length_errors = UINT64_MAX;
+ stats->rx_over_errors = UINT64_MAX;
+ stats->rx_crc_errors = UINT64_MAX;
+ stats->rx_frame_errors = UINT64_MAX;
+ stats->rx_fifo_errors = UINT64_MAX;
+ stats->rx_missed_errors = UINT64_MAX;
+ stats->tx_aborted_errors = UINT64_MAX;
+ stats->tx_carrier_errors = UINT64_MAX;
+ stats->tx_fifo_errors = UINT64_MAX;
+ stats->tx_heartbeat_errors = UINT64_MAX;
+ stats->tx_window_errors = UINT64_MAX;
+}
+
+static void
+convert_stats(const struct netdev *netdev, struct netdev_stats *stats,
+ const struct if_data *ifd)
+{
+ if (netdev_bsd_cast(netdev)->tap_fd == -1) {
+ convert_stats_system(stats, ifd);
+ } else {
+ convert_stats_tap(stats, ifd);
+ }
+}
+