Skip to content
Snippets Groups Projects
Commit c4c87d5c authored by Padmalochan Mohapatra's avatar Padmalochan Mohapatra Committed by Anjan Chanda
Browse files

libethernet : Addressing comments .

parent 0828daf7
Branches
No related tags found
No related merge requests found
......@@ -38,6 +38,23 @@
#include "ethernet.h"
#if defined(IOPSYS_BROADCOM)
extern const struct eth_ops bcm_eth_ops;
#elif defined(IOPSYS_TEST)
extern const struct eth_ops test_eth_ops;
#elif defined(IOPSYS_ECONET)
extern const struct eth_ops econet_gen_eth_ops;
extern const struct eth_ops econet_nas_wan_eth_ops;
extern const struct eth_ops econet_ae_wan_eth_ops;
#elif defined(IPQ95XX)
extern const struct eth_ops ipq95xx_eth_ops;
#elif defined(IOPSYS_LINUX)
extern const struct eth_ops linux_eth_ops;
#else
extern const struct eth_ops ethsw_ops;
#endif
const struct eth_ops *eth_ops[] = {
#if defined(IOPSYS_BROADCOM)
&bcm_eth_ops,
......
......@@ -26,6 +26,7 @@
#include <stdbool.h>
#include <linux/types.h>
#ifdef __cplusplus
extern "C" {
#endif
......@@ -35,23 +36,6 @@ extern "C" {
#define libethernet_info(...) pr_info("libethernet: " __VA_ARGS__)
#define libethernet_dbg(...) pr_debug("libethernet: " __VA_ARGS__)
#if defined(IOPSYS_BROADCOM)
extern const struct eth_ops bcm_eth_ops;
#elif defined(IOPSYS_TEST)
extern const struct eth_ops test_eth_ops;
#elif defined(IOPSYS_ECONET)
extern const struct eth_ops econet_gen_eth_ops;
extern const struct eth_ops econet_nas_wan_eth_ops;
extern const struct eth_ops econet_ae_wan_eth_ops;
#elif defined(IPQ95XX)
extern const struct eth_ops ipq95xx_eth_ops;
#elif defined(IOPSYS_LINUX)
extern const struct eth_ops linux_eth_ops;
#else
extern const struct eth_ops ethsw_ops;
#endif
/* enum eth_duplex - duplex modes */
enum eth_duplex {
AUTO_DUPLEX,
......
......@@ -36,19 +36,6 @@
#include <unistd.h>
#include <stdlib.h>
#include <linux/ethtool.h>
#include <netlink/genl/genl.h>
#include <netlink/cache.h>
#include <netlink/utils.h>
#include <netlink/object.h>
#include <netlink/genl/genl.h>
#include <netlink/genl/ctrl.h>
#include <netlink/netlink.h>
#include <netlink/route/rtnl.h>
#include <netlink/route/link.h>
#include <netlink/genl/ctrl.h>
#include <netlink/netlink.h>
#include <netlink/route/rtnl.h>
#include <netlink/route/link.h>
#include <linux/sockios.h>
#include "easy.h"
#include "if_utils.h"
......@@ -56,74 +43,78 @@
#include "linux_eth.h"
/************************************************************
* Open a netlink socket connectivity with NETLINK_ROUTE
* to read the stats using designated API.
************************************************************
*/
static int if_openlnk(const char *ifname, struct nl_sock **s,
struct rtnl_link **l)
{
struct rtnl_link *link;
struct nl_sock *sk;
int ret = 0;
sk = nl_socket_alloc();
if (sk == NULL) {
ret = -errno;
return ret;
}
if (nl_connect(sk, NETLINK_ROUTE) < 0) {
syslog(LOG_ERR, "%s(%d) nl socket connection failed.",
__FUNCTION__, __LINE__);
ret = -1;
goto out;
}
if (rtnl_link_get_kernel(sk, 0, ifname, &link) < 0) {
ret = -1;
goto out;
}
*l = link;
*s = sk;
return 0;
out:
nl_socket_free(sk);
return ret;
}
/************************************************************
* Close the socket and free the allocated nl objects.
************************************************************
*/
static int if_closelnk(struct nl_sock *s, struct rtnl_link *l)
{
rtnl_link_put(l);
nl_socket_free(s);
return 0;
}
typedef enum {
tx_packets = 0,
tx_bytes,
rx_packets,
rx_bytes,
TxDrop,
TxCrcErr,
TxUnicast,
TxMulticast,
TxBroadcast,
TxCollision,
TxSingleCollision,
TxMultipleCollision,
TxDeferred,
TxLateCollision,
TxExcessiveCollistion,
TxPause,
TxPktSz64,
TxPktSz65To127,
TxPktSz128To255,
TxPktSz256To511,
TxPktSz512To1023,
Tx1024ToMax,
TxBytes,
RxDrop,
RxFiltering,
RxUnicast,
RxMulticast,
RxBroadcast,
RxAlignErr,
RxCrcErr,
RxUnderSizeErr,
RxFragErr,
RxOverSzErr,
RxJabberErr,
RxPause,
RxPktSz64,
RxPktSz65To127,
RxPktSz128To255,
RxPktSz256To511,
RxPktSz512To1023,
RxPktSz1024ToMax,
RxBytes,
RxCtrlDrop,
RxIngressDrop,
RxArlDrop,
STATS_END,
} idx;
struct ethnic_stats {
uint32_t cmd;
uint32_t n_stats;
uint64_t data[STATS_END];
} stat;
static struct eth_stats ifstats;
static int get_ifstats(const char *ifname, struct eth_stats *s)
{
struct rtnl_link *link;
struct nl_sock *sk;
int ret = 0;
struct if_stats easy_ifstat;
if (!s)
return -1;
ret = if_openlnk(ifname, &sk, &link);
if (ret)
return -1;
memset(&easy_ifstat, 0, sizeof(struct if_stats));
if (if_getstats(ifname, &easy_ifstat) < 0) {
return -1;
}
s->tx_bytes = rtnl_link_get_stat(link, RTNL_LINK_TX_BYTES);
s->tx_packets = rtnl_link_get_stat(link, RTNL_LINK_TX_PACKETS);
s->tx_errors = rtnl_link_get_stat(link, RTNL_LINK_TX_ERRORS);
s->tx_bytes = easy_ifstat.tx_bytes;
s->tx_packets = easy_ifstat.tx_packets;
s->tx_errors = easy_ifstat.tx_errors;
/* Some counters set to zero, and will be populated cross referring
* the rmon stats structure.
*/
......@@ -131,17 +122,15 @@ static int get_ifstats(const char *ifname, struct eth_stats *s)
s->tx_mcast_packets = 0;
s->tx_bcast_packets = 0;
s->tx_discard_packets = 0;
s->rx_bytes = rtnl_link_get_stat(link, RTNL_LINK_RX_BYTES);
s->rx_bytes = easy_ifstat.rx_bytes;
s->rx_packets = 0;
s->rx_errors = rtnl_link_get_stat(link, RTNL_LINK_RX_ERRORS);
s->rx_errors = easy_ifstat.rx_errors;
s->rx_ucast_packets = 0;
s->rx_mcast_packets = rtnl_link_get_stat(link, RTNL_LINK_MULTICAST);
s->rx_mcast_packets = 0;
s->rx_bcast_packets = 0;
s->rx_discard_packets = 0;
s->rx_unknown_packets = 0;
if_closelnk(sk, link);
return 0;
}
......@@ -187,7 +176,7 @@ int linux_eth_get_stats(const char *ifname, struct eth_stats *s)
s->tx_packets = ifstats.tx_packets;
s->tx_errors = ifstats.tx_errors;
s->tx_ucast_packets = stat.data[TxUnicast];
s->tx_mcast_packets = ifstats.tx_mcast_packets;
s->tx_mcast_packets = stat.data[TxMulticast];
s->tx_bcast_packets = stat.data[TxBroadcast];
s->tx_discard_packets = stat.data[TxDrop];
s->rx_bytes = ifstats.rx_bytes;
......
#ifndef LINUX
#define LINUX
#ifndef LINUX_ETH_H
#define LINUX_ETH_H
#ifdef __cplusplus
extern "C" {
#endif
typedef enum {
tx_packets = 0,
tx_bytes,
rx_packets,
rx_bytes,
TxDrop,
TxCrcErr,
TxUnicast,
TxMulticast,
TxBroadcast,
TxCollision,
TxSingleCollision,
TxMultipleCollision,
TxDeferred,
TxLateCollision,
TxExcessiveCollistion,
TxPause,
TxPktSz64,
TxPktSz65To127,
TxPktSz128To255,
TxPktSz256To511,
TxPktSz512To1023,
Tx1024ToMax,
TxBytes,
RxDrop,
RxFiltering,
RxUnicast,
RxMulticast,
RxBroadcast,
RxAlignErr,
RxCrcErr,
RxUnderSizeErr,
RxFragErr,
RxOverSzErr,
RxJabberErr,
RxPause,
RxPktSz64,
RxPktSz65To127,
RxPktSz128To255,
RxPktSz256To511,
RxPktSz512To1023,
RxPktSz1024ToMax,
RxBytes,
RxCtrlDrop,
RxIngressDrop,
RxArlDrop,
STATS_END,
} idx;
static struct ethnic_stats {
__u32 cmd;
__u32 n_stats;
__u64 data[STATS_END];
} stat;
static struct eth_stats ifstats;
int linux_eth_get_stats(const char *ifname, struct eth_stats *s);
int linux_eth_get_rmon_stats(const char *ifname, struct eth_rmon_stats *rmon);
......@@ -69,4 +12,4 @@ int linux_eth_get_rmon_stats(const char *ifname, struct eth_rmon_stats *rmon);
}
#endif
#endif /* LINUX */
#endif /* LINUX_ETH_H */
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment