[ovs-dev] [PATCH 1/2] netdev-linux: Introduce netdev_linux_ethtool_set_flag().
Justin Pettit
jpettit at nicira.com
Thu Aug 18 02:01:53 UTC 2011
There will be a caller added soon.
---
lib/netdev-linux.c | 28 ++++++++++++++++++++++++++++
lib/netdev-linux.h | 8 ++++++++
2 files changed, 36 insertions(+), 0 deletions(-)
diff --git a/lib/netdev-linux.c b/lib/netdev-linux.c
index 05b830c..409f8b9 100644
--- a/lib/netdev-linux.c
+++ b/lib/netdev-linux.c
@@ -90,6 +90,11 @@ COVERAGE_DEFINE(netdev_ethtool);
#define ADVERTISED_Asym_Pause (1 << 14)
#endif
+/* These were introduced in Linux 2.6.24, so they might be missing if we
+ * have old headers. */
+#define ETHTOOL_GFLAGS 0x00000025 /* Get flags bitmap(ethtool_value) */
+#define ETHTOOL_SFLAGS 0x00000026 /* Set flags bitmap(ethtool_value) */
+
/* This was introduced in Linux 2.6.25, so it might be missing if we have old
* headers. */
#ifndef TC_RTAB_SIZE
@@ -4210,6 +4215,29 @@ netdev_linux_do_ethtool(const char *name, struct ethtool_cmd *ecmd,
}
}
+/* Modifies the 'flag' bit in ethtool's flags field for 'netdev'. If
+ * 'enable' is true, the bit is set. Otherwise, it is cleared. */
+int
+netdev_linux_ethtool_set_flag(struct netdev *netdev, uint32_t flag,
+ int enable)
+{
+ struct ethtool_value evalue;
+ int error;
+
+ memset(&evalue, 0, sizeof evalue);
+ error = netdev_linux_do_ethtool(netdev_get_name(netdev),
+ (struct ethtool_cmd *)&evalue,
+ ETHTOOL_GFLAGS, "ETHTOOL_GFLAGS");
+
+ if (error)
+ return error;
+
+ evalue.data = (evalue.data & ~flag) | (enable ? flag : 0);
+ return netdev_linux_do_ethtool(netdev_get_name(netdev),
+ (struct ethtool_cmd *)&evalue,
+ ETHTOOL_SFLAGS, "ETHTOOL_SFLAGS");
+}
+
static int
netdev_linux_do_ioctl(const char *name, struct ifreq *ifr, int cmd,
const char *cmd_name)
diff --git a/lib/netdev-linux.h b/lib/netdev-linux.h
index 7a11204..40d807b 100644
--- a/lib/netdev-linux.h
+++ b/lib/netdev-linux.h
@@ -17,9 +17,13 @@
#ifndef NETDEV_LINUX_H
#define NETDEV_LINUX_H 1
+#include <stdint.h>
+#include <stdbool.h>
+
/* These functions are Linux specific, so they should be used directly only by
* Linux-specific code. */
+struct netdev;
struct netdev_stats;
struct rtnl_link_stats;
struct rtnl_link_stats64;
@@ -31,4 +35,8 @@ void netdev_stats_from_rtnl_link_stats64(struct netdev_stats *dst,
void netdev_stats_to_rtnl_link_stats64(struct rtnl_link_stats64 *dst,
const struct netdev_stats *src);
+int netdev_linux_ethtool_set_flag(struct netdev *netdev, uint32_t flag,
+ int enable);
+
+
#endif /* netdev-linux.h */
--
1.7.1
More information about the dev
mailing list