[ovs-dev] [PATCH 16/18] implement get_stats for NetBSD
YAMAMOTO Takashi
yamamoto at valinux.co.jp
Thu Jan 31 10:49:50 UTC 2013
From: YAMAMOTO Takashi <yamt at mwd.biglobe.ne.jp>
Signed-off-by: YAMAMOTO Takashi <yamamoto at valinux.co.jp>
---
lib/netdev-bsd.c | 53 +++++++++++++++++++++++++++++++++++++++++++++++++----
1 file changed, 49 insertions(+), 4 deletions(-)
diff --git a/lib/netdev-bsd.c b/lib/netdev-bsd.c
index 615a26f..1cb1d8b 100644
--- a/lib/netdev-bsd.c
+++ b/lib/netdev-bsd.c
@@ -890,7 +890,7 @@ netdev_bsd_get_carrier(const struct netdev *netdev_, bool *carrier)
/* Retrieves current device stats for 'netdev'. */
static int
-netdev_bsd_get_stats(const struct netdev *netdev_ __attribute__((__unused__)), struct netdev_stats *stats)
+netdev_bsd_get_stats(const struct netdev *netdev_, struct netdev_stats *stats)
{
#if defined(__FreeBSD__)
int if_count, i;
@@ -951,10 +951,55 @@ netdev_bsd_get_stats(const struct netdev *netdev_ __attribute__((__unused__)), s
}
return 0;
-#else
- /* XXXnotyet */
- memset(stats, 0, sizeof(*stats));
+#elif defined(__NetBSD__)
+ struct netdev_dev_bsd *netdev_dev =
+ netdev_dev_bsd_cast(netdev_get_dev(netdev_));
+ struct ifdatareq ifdr;
+ struct if_data *ifd;
+ int saved_errno;
+ int s;
+ int ret;
+
+ s = socket(AF_LINK, SOCK_DGRAM, 0);
+ if (s == -1) {
+ return errno;
+ }
+ memset(&ifdr, 0, sizeof(ifdr));
+ strncpy(ifdr.ifdr_name, netdev_dev->kernel_name, sizeof(ifdr.ifdr_name));
+ ret = ioctl(s, SIOCGIFDATA, &ifdr);
+ saved_errno = errno;
+ close(s);
+ if (ret == -1) {
+ return saved_errno;
+ }
+ ifd = &ifdr.ifdr_data;
+ /*
+ * note: UINT64_MAX means unsupported
+ */
+ stats->rx_packets = ifd->ifi_ipackets;
+ stats->tx_packets = ifd->ifi_opackets;
+ stats->rx_bytes = ifd->ifi_obytes;
+ stats->tx_bytes = ifd->ifi_ibytes;
+ stats->rx_errors = ifd->ifi_ierrors;
+ stats->tx_errors = ifd->ifi_oerrors;
+ stats->rx_dropped = ifd->ifi_iqdrops;
+ stats->tx_dropped = UINT64_MAX;
+ stats->multicast = ifd->ifi_imcasts;
+ stats->collisions = ifd->ifi_collisions;
+ 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;
return 0;
+#else
+#error not implemented
#endif
}
--
1.7.12
More information about the dev
mailing list