[patch net-next-2.6] dummy: allow report link status and change it via sysfs

Subsystems: networking drivers, the rest

STALE5485d

3 messages, 3 authors, 2011-07-29 · open the first message on its own page

[patch net-next-2.6] dummy: allow report link status and change it via sysfs

From: Jiri Pirko <hidden>
Date: 2011-07-29 15:27:39

Signed-off-by: Jiri Pirko <redacted>
---
 drivers/net/dummy.c |   54 +++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 54 insertions(+), 0 deletions(-)
diff --git a/drivers/net/dummy.c b/drivers/net/dummy.c
index 39cf9b9..fc39c24 100644
--- a/drivers/net/dummy.c
+++ b/drivers/net/dummy.c
@@ -37,9 +37,57 @@
 #include <linux/rtnetlink.h>
 #include <net/rtnetlink.h>
 #include <linux/u64_stats_sync.h>
+#include <linux/ethtool.h>
 
 static int numdummies = 1;
 
+static ssize_t dummy_show_link(struct device *d,
+			       struct device_attribute *attr,
+			       char *buf)
+{
+	struct net_device *dev = to_net_dev(d);
+
+	return sprintf(buf, "%d\n", netif_carrier_ok(dev) ? 1 : 0);
+}
+
+static ssize_t dummy_store_link(struct device *d,
+				struct device_attribute *attr,
+				const char *buf, size_t count)
+{
+	struct net_device *dev = to_net_dev(d);
+	int new_value;
+
+	if (sscanf(buf, "%d", &new_value) != 1) {
+		pr_err("%s: no link value specified.\n", dev->name);
+		return -EINVAL;
+	}
+	switch (new_value) {
+	case 0:
+		netif_carrier_off(dev);
+		break;
+	case 1:
+		netif_carrier_on(dev);
+		break;
+	default:
+		pr_info("%s: Ignoring invalid link value %d.\n",
+			dev->name, new_value);
+	}
+	return count;
+}
+
+static DEVICE_ATTR(link, S_IRUGO | S_IWUSR,
+		   dummy_show_link, dummy_store_link);
+
+static struct attribute *per_dummy_attrs[] = {
+	&dev_attr_link.attr,
+	NULL,
+};
+
+static struct attribute_group dummy_group = {
+	.name = "dummy",
+	.attrs = per_dummy_attrs,
+};
+
 static int dummy_set_address(struct net_device *dev, void *p)
 {
 	struct sockaddr *sa = p;
@@ -103,6 +151,7 @@ static int dummy_dev_init(struct net_device *dev)
 	if (!dev->dstats)
 		return -ENOMEM;
 
+	dev->sysfs_groups[0] = &dummy_group;
 	return 0;
 }
 
@@ -121,12 +170,17 @@ static const struct net_device_ops dummy_netdev_ops = {
 	.ndo_get_stats64	= dummy_get_stats64,
 };
 
+static const struct ethtool_ops dummy_ethtool_ops = {
+	.get_link		= ethtool_op_get_link,
+};
+
 static void dummy_setup(struct net_device *dev)
 {
 	ether_setup(dev);
 
 	/* Initialize the device structure. */
 	dev->netdev_ops = &dummy_netdev_ops;
+	dev->ethtool_ops = &dummy_ethtool_ops;
 	dev->destructor = dummy_dev_free;
 
 	/* Fill in device structure with ethernet-generic values. */
-- 
1.7.6

Re: [patch net-next-2.6] dummy: allow report link status and change it via sysfs

From: Ben Hutchings <hidden>
Date: 2011-07-29 16:03:15

On Fri, 2011-07-29 at 17:27 +0200, Jiri Pirko wrote:
quoted hunk
Signed-off-by: Jiri Pirko <redacted>
---
 drivers/net/dummy.c |   54 +++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 54 insertions(+), 0 deletions(-)
diff --git a/drivers/net/dummy.c b/drivers/net/dummy.c
index 39cf9b9..fc39c24 100644
--- a/drivers/net/dummy.c
+++ b/drivers/net/dummy.c
@@ -37,9 +37,57 @@
 #include <linux/rtnetlink.h>
 #include <net/rtnetlink.h>
 #include <linux/u64_stats_sync.h>
+#include <linux/ethtool.h>
 
 static int numdummies = 1;
 
+static ssize_t dummy_show_link(struct device *d,
+			       struct device_attribute *attr,
+			       char *buf)
+{
+	struct net_device *dev = to_net_dev(d);
+
+	return sprintf(buf, "%d\n", netif_carrier_ok(dev) ? 1 : 0);
+}
[...]

Net devices already have the 'carrier' attribute.  You should make that
attribute writable for dummy devices, rather than adding another one.

Ben.

-- 
Ben Hutchings, Senior Software Engineer, Solarflare Communications
Not speaking for my employer; that's the marketing department's job.
They asked us to note that Solarflare product names are trademarked.

Re: [patch net-next-2.6] dummy: allow report link status and change it via sysfs

From: Stephen Hemminger <hidden>
Date: 2011-07-29 16:55:13

On Fri, 29 Jul 2011 18:03:09 +0200
Ben Hutchings [off-list ref] wrote:
On Fri, 2011-07-29 at 17:27 +0200, Jiri Pirko wrote:
quoted
Signed-off-by: Jiri Pirko <redacted>
---
 drivers/net/dummy.c |   54 +++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 54 insertions(+), 0 deletions(-)
diff --git a/drivers/net/dummy.c b/drivers/net/dummy.c
index 39cf9b9..fc39c24 100644
--- a/drivers/net/dummy.c
+++ b/drivers/net/dummy.c
@@ -37,9 +37,57 @@
 #include <linux/rtnetlink.h>
 #include <net/rtnetlink.h>
 #include <linux/u64_stats_sync.h>
+#include <linux/ethtool.h>
 
 static int numdummies = 1;
 
+static ssize_t dummy_show_link(struct device *d,
+			       struct device_attribute *attr,
+			       char *buf)
+{
+	struct net_device *dev = to_net_dev(d);
+
+	return sprintf(buf, "%d\n", netif_carrier_ok(dev) ? 1 : 0);
+}
[...]

Net devices already have the 'carrier' attribute.  You should make that
attribute writable for dummy devices, rather than adding another one.
And adding ethtool support is unnecessary since carrier is already
reported by tools like 'ip link'
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help