From 2a333afca3adeb2f2b6a83efb94eeabf0e1a98e3 Mon Sep 17 00:00:00 2001 From: Oussama Ghorbel <oussama.ghorbel@iopsys.eu> Date: Wed, 8 Jul 2020 15:15:54 +0200 Subject: [PATCH] libethernet: bcm : read extended stats from proc --- bcm/bcm.c | 15 ++++++++------- ethernet.c | 3 ++- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/bcm/bcm.c b/bcm/bcm.c index 805c154..4133430 100644 --- a/bcm/bcm.c +++ b/bcm/bcm.c @@ -4,6 +4,7 @@ * Copyright (C) 2018 iopsys Software Solutions AB. All rights reserved. * * Author: anjan.chanda@iopsys.eu + * oussama.ghorbel@iopsys.eu * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License @@ -225,10 +226,10 @@ static int bcm_eth_get_stats_from_proc(const char *ifname, struct eth_stats *s) unsigned long rx_fifo, rx_frame, rx_comp, rx_multi; unsigned long tx_bytes, tx_packets, tx_err, tx_drop; unsigned long tx_fifo, tx_coll, tx_carr, tx_comp; - unsigned long tx_mcast_packets, rx_mcast_bytes, tx_mcast_bytes; - unsigned long rx_ucast_packets, tx_ucast_packets; - unsigned long rx_bcast_packets, tx_bcast_packets; - unsigned long rx_err_unknown; + unsigned long tx_mcast_packets = 0, rx_mcast_bytes = 0, tx_mcast_bytes = 0; + unsigned long rx_ucast_packets = 0, tx_ucast_packets = 0; + unsigned long rx_bcast_packets = 0, tx_bcast_packets = 0; + unsigned long rx_err_unknown = 0; char cmdbuf[512] = {0}; char *ptr; int ret; @@ -253,7 +254,7 @@ static int bcm_eth_get_stats_from_proc(const char *ifname, struct eth_stats *s) &rx_bcast_packets, &tx_bcast_packets, &rx_err_unknown); - if (ret != 12) + if (ret < 16) return -1; s->tx_bytes = tx_bytes; @@ -262,14 +263,14 @@ static int bcm_eth_get_stats_from_proc(const char *ifname, struct eth_stats *s) s->rx_packets = rx_packets; s->tx_errors = tx_err; s->rx_errors = rx_err; + s->tx_discard_packets = tx_drop; + s->rx_discard_packets = rx_drop; s->tx_ucast_packets = tx_ucast_packets; s->rx_ucast_packets = rx_ucast_packets; s->tx_mcast_packets = tx_mcast_packets; s->rx_mcast_packets = INVALID_UINT32; /* 'rx_mcast_bytes' available */ s->tx_bcast_packets = tx_bcast_packets; s->rx_bcast_packets = rx_bcast_packets; - s->tx_discard_packets = tx_drop; - s->rx_discard_packets = rx_drop; s->rx_unknown_packets = rx_err_unknown; return 0; diff --git a/ethernet.c b/ethernet.c index 6650810..8e151f7 100644 --- a/ethernet.c +++ b/ethernet.c @@ -55,10 +55,11 @@ const struct eth_ops *get_eth_driver(const char *ifname) { int i; - for (i = 0; i < sizeof(eth_ops)/sizeof(eth_ops[0]); i++) + for (i = 0; i < sizeof(eth_ops)/sizeof(eth_ops[0]); i++) { if (!strncmp(eth_ops[i]->ifname, ifname, strlen(eth_ops[i]->ifname))) return eth_ops[i]; + } return NULL; } -- GitLab