Skip to main content
Sign in
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 @@ ...@@ -38,6 +38,23 @@
#include "ethernet.h" #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[] = { const struct eth_ops *eth_ops[] = {
#if defined(IOPSYS_BROADCOM) #if defined(IOPSYS_BROADCOM)
&bcm_eth_ops, &bcm_eth_ops,
... ...
......
...@@ -26,6 +26,7 @@ ...@@ -26,6 +26,7 @@
#include <stdbool.h> #include <stdbool.h>
#include <linux/types.h> #include <linux/types.h>
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
#endif #endif
...@@ -35,23 +36,6 @@ extern "C" { ...@@ -35,23 +36,6 @@ extern "C" {
#define libethernet_info(...) pr_info("libethernet: " __VA_ARGS__) #define libethernet_info(...) pr_info("libethernet: " __VA_ARGS__)
#define libethernet_dbg(...) pr_debug("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 - duplex modes */
enum eth_duplex { enum eth_duplex {
AUTO_DUPLEX, AUTO_DUPLEX,
... ...
......
...@@ -36,19 +36,6 @@ ...@@ -36,19 +36,6 @@
#include <unistd.h> #include <unistd.h>
#include <stdlib.h> #include <stdlib.h>
#include <linux/ethtool.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 <linux/sockios.h>
#include "easy.h" #include "easy.h"
#include "if_utils.h" #include "if_utils.h"
...@@ -56,74 +43,78 @@ ...@@ -56,74 +43,78 @@
#include "linux_eth.h" #include "linux_eth.h"
/************************************************************ typedef enum {
* Open a netlink socket connectivity with NETLINK_ROUTE tx_packets = 0,
* to read the stats using designated API. tx_bytes,
************************************************************ rx_packets,
*/ rx_bytes,
static int if_openlnk(const char *ifname, struct nl_sock **s, TxDrop,
struct rtnl_link **l) TxCrcErr,
{ TxUnicast,
struct rtnl_link *link; TxMulticast,
struct nl_sock *sk; TxBroadcast,
int ret = 0; TxCollision,
TxSingleCollision,
sk = nl_socket_alloc(); TxMultipleCollision,
if (sk == NULL) { TxDeferred,
ret = -errno; TxLateCollision,
return ret; TxExcessiveCollistion,
} TxPause,
TxPktSz64,
if (nl_connect(sk, NETLINK_ROUTE) < 0) { TxPktSz65To127,
syslog(LOG_ERR, "%s(%d) nl socket connection failed.", TxPktSz128To255,
__FUNCTION__, __LINE__); TxPktSz256To511,
ret = -1; TxPktSz512To1023,
goto out; Tx1024ToMax,
} TxBytes,
RxDrop,
if (rtnl_link_get_kernel(sk, 0, ifname, &link) < 0) { RxFiltering,
ret = -1; RxUnicast,
goto out; RxMulticast,
} RxBroadcast,
RxAlignErr,
*l = link; RxCrcErr,
*s = sk; RxUnderSizeErr,
return 0; RxFragErr,
RxOverSzErr,
out: RxJabberErr,
nl_socket_free(sk); RxPause,
return ret; RxPktSz64,
} RxPktSz65To127,
RxPktSz128To255,
/************************************************************ RxPktSz256To511,
* Close the socket and free the allocated nl objects. RxPktSz512To1023,
************************************************************ RxPktSz1024ToMax,
*/ RxBytes,
RxCtrlDrop,
static int if_closelnk(struct nl_sock *s, struct rtnl_link *l) RxIngressDrop,
{ RxArlDrop,
rtnl_link_put(l); STATS_END,
nl_socket_free(s); } idx;
return 0; 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) static int get_ifstats(const char *ifname, struct eth_stats *s)
{ {
struct rtnl_link *link; struct if_stats easy_ifstat;
struct nl_sock *sk;
int ret = 0;
if (!s) if (!s)
return -1; return -1;
ret = if_openlnk(ifname, &sk, &link); memset(&easy_ifstat, 0, sizeof(struct if_stats));
if (ret) if (if_getstats(ifname, &easy_ifstat) < 0) {
return -1; return -1;
}
s->tx_bytes = rtnl_link_get_stat(link, RTNL_LINK_TX_BYTES); s->tx_bytes = easy_ifstat.tx_bytes;
s->tx_packets = rtnl_link_get_stat(link, RTNL_LINK_TX_PACKETS); s->tx_packets = easy_ifstat.tx_packets;
s->tx_errors = rtnl_link_get_stat(link, RTNL_LINK_TX_ERRORS); s->tx_errors = easy_ifstat.tx_errors;
/* Some counters set to zero, and will be populated cross referring /* Some counters set to zero, and will be populated cross referring
* the rmon stats structure. * the rmon stats structure.
*/ */
...@@ -131,17 +122,15 @@ static int get_ifstats(const char *ifname, struct eth_stats *s) ...@@ -131,17 +122,15 @@ static int get_ifstats(const char *ifname, struct eth_stats *s)
s->tx_mcast_packets = 0; s->tx_mcast_packets = 0;
s->tx_bcast_packets = 0; s->tx_bcast_packets = 0;
s->tx_discard_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_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_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_bcast_packets = 0;
s->rx_discard_packets = 0; s->rx_discard_packets = 0;
s->rx_unknown_packets = 0; s->rx_unknown_packets = 0;
if_closelnk(sk, link);
return 0; return 0;
} }
...@@ -187,7 +176,7 @@ int linux_eth_get_stats(const char *ifname, struct eth_stats *s) ...@@ -187,7 +176,7 @@ int linux_eth_get_stats(const char *ifname, struct eth_stats *s)
s->tx_packets = ifstats.tx_packets; s->tx_packets = ifstats.tx_packets;
s->tx_errors = ifstats.tx_errors; s->tx_errors = ifstats.tx_errors;
s->tx_ucast_packets = stat.data[TxUnicast]; 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_bcast_packets = stat.data[TxBroadcast];
s->tx_discard_packets = stat.data[TxDrop]; s->tx_discard_packets = stat.data[TxDrop];
s->rx_bytes = ifstats.rx_bytes; s->rx_bytes = ifstats.rx_bytes;
... ...
......
#ifndef LINUX #ifndef LINUX_ETH_H
#define LINUX #define LINUX_ETH_H
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
#endif #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_stats(const char *ifname, struct eth_stats *s);
int linux_eth_get_rmon_stats(const char *ifname, struct eth_rmon_stats *rmon); 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); ...@@ -69,4 +12,4 @@ int linux_eth_get_rmon_stats(const char *ifname, struct eth_rmon_stats *rmon);
} }
#endif #endif
#endif /* LINUX */ #endif /* LINUX_ETH_H */
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment