netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [patch net-next V3 0/4] net: allow to change carrier from userspace
@ 2012-12-19  9:35 Jiri Pirko
  2012-12-19  9:35 ` [patch net-next 1/4] net: add change_carrier netdev op Jiri Pirko
                   ` (4 more replies)
  0 siblings, 5 replies; 9+ messages in thread
From: Jiri Pirko @ 2012-12-19  9:35 UTC (permalink / raw)
  To: netdev
  Cc: davem, edumazet, bhutchings, mirqus, shemminger, greearb, fbl,
	john.r.fastabend

This is basically a V3 of a repost of my previous patchset:
"[patch net-next-2.6 0/2] net: allow to change carrier via sysfs" from Aug 30

The way net-sysfs stores values changed and this patchset reflects it.
Also, I exposed carrier via rtnetlink iface.

So far, only dummy driver uses carrier change ndo. In very near future
team driver will use that as well.

V2->V3:
 - updated ndo_change_carrier comment by Dan Williams

V1->v2:
 - added bigger comment to ndo and also note to operstate.txt documentation
   stating the clear purpose of this iface

Jiri Pirko (4):
  net: add change_carrier netdev op
  net: allow to change carrier via sysfs
  rtnl: expose carrier value with possibility to set it
  dummy: implement carrier change

 Documentation/networking/operstates.txt |  4 ++++
 drivers/net/dummy.c                     | 10 ++++++++++
 include/linux/netdevice.h               | 12 ++++++++++++
 include/uapi/linux/if_link.h            |  1 +
 net/core/dev.c                          | 19 +++++++++++++++++++
 net/core/net-sysfs.c                    | 15 ++++++++++++++-
 net/core/rtnetlink.c                    | 10 ++++++++++
 7 files changed, 70 insertions(+), 1 deletion(-)

-- 
1.8.0

^ permalink raw reply	[flat|nested] 9+ messages in thread

* [patch net-next 1/4] net: add change_carrier netdev op
  2012-12-19  9:35 [patch net-next V3 0/4] net: allow to change carrier from userspace Jiri Pirko
@ 2012-12-19  9:35 ` Jiri Pirko
  2012-12-19  9:35 ` [patch net-next 2/4] net: allow to change carrier via sysfs Jiri Pirko
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 9+ messages in thread
From: Jiri Pirko @ 2012-12-19  9:35 UTC (permalink / raw)
  To: netdev
  Cc: davem, edumazet, bhutchings, mirqus, shemminger, greearb, fbl,
	john.r.fastabend

This allows a driver to register change_carrier callback which will be
called whenever user will like to change carrier state. This is useful
for devices like dummy, gre, team and so on.

Signed-off-by: Jiri Pirko <jiri@resnulli.us>
---
 include/linux/netdevice.h | 12 ++++++++++++
 net/core/dev.c            | 19 +++++++++++++++++++
 2 files changed, 31 insertions(+)

diff --git a/include/linux/netdevice.h b/include/linux/netdevice.h
index 02e0f6b..22ca4a8 100644
--- a/include/linux/netdevice.h
+++ b/include/linux/netdevice.h
@@ -891,6 +891,14 @@ struct netdev_fcoe_hbainfo {
  * int (*ndo_bridge_setlink)(struct net_device *dev, struct nlmsghdr *nlh)
  * int (*ndo_bridge_getlink)(struct sk_buff *skb, u32 pid, u32 seq,
  *			     struct net_device *dev)
+ *
+ * int (*ndo_change_carrier)(struct net_device *dev, bool new_carrier);
+ *	Called to change device carrier. Soft-devices (like dummy, team, etc)
+ *	which do not represent real hardware may define this to allow their
+ *	userspace components to manage their virtual carrier state. Devices
+ *	that determine carrier state from physical hardware properties (eg
+ *	network cables) or protocol-dependent mechanisms (eg
+ *	USB_CDC_NOTIFY_NETWORK_CONNECTION) should NOT implement this function.
  */
 struct net_device_ops {
 	int			(*ndo_init)(struct net_device *dev);
@@ -1008,6 +1016,8 @@ struct net_device_ops {
 	int			(*ndo_bridge_getlink)(struct sk_buff *skb,
 						      u32 pid, u32 seq,
 						      struct net_device *dev);
+	int			(*ndo_change_carrier)(struct net_device *dev,
+						      bool new_carrier);
 };
 
 /*
@@ -2194,6 +2204,8 @@ extern int		dev_set_mtu(struct net_device *, int);
 extern void		dev_set_group(struct net_device *, int);
 extern int		dev_set_mac_address(struct net_device *,
 					    struct sockaddr *);
+extern int		dev_change_carrier(struct net_device *,
+					   bool new_carrier);
 extern int		dev_hard_start_xmit(struct sk_buff *skb,
 					    struct net_device *dev,
 					    struct netdev_queue *txq);
diff --git a/net/core/dev.c b/net/core/dev.c
index d0cbc93..268a714 100644
--- a/net/core/dev.c
+++ b/net/core/dev.c
@@ -5027,6 +5027,25 @@ int dev_set_mac_address(struct net_device *dev, struct sockaddr *sa)
 }
 EXPORT_SYMBOL(dev_set_mac_address);
 
+/**
+ *	dev_change_carrier - Change device carrier
+ *	@dev: device
+ *	@new_carries: new value
+ *
+ *	Change device carrier
+ */
+int dev_change_carrier(struct net_device *dev, bool new_carrier)
+{
+	const struct net_device_ops *ops = dev->netdev_ops;
+
+	if (!ops->ndo_change_carrier)
+		return -EOPNOTSUPP;
+	if (!netif_device_present(dev))
+		return -ENODEV;
+	return ops->ndo_change_carrier(dev, new_carrier);
+}
+EXPORT_SYMBOL(dev_change_carrier);
+
 /*
  *	Perform the SIOCxIFxxx calls, inside rcu_read_lock()
  */
-- 
1.8.0

^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [patch net-next 2/4] net: allow to change carrier via sysfs
  2012-12-19  9:35 [patch net-next V3 0/4] net: allow to change carrier from userspace Jiri Pirko
  2012-12-19  9:35 ` [patch net-next 1/4] net: add change_carrier netdev op Jiri Pirko
@ 2012-12-19  9:35 ` Jiri Pirko
  2012-12-19  9:35 ` [patch net-next 3/4] rtnl: expose carrier value with possibility to set it Jiri Pirko
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 9+ messages in thread
From: Jiri Pirko @ 2012-12-19  9:35 UTC (permalink / raw)
  To: netdev
  Cc: davem, edumazet, bhutchings, mirqus, shemminger, greearb, fbl,
	john.r.fastabend

Make carrier writable

Signed-off-by: Jiri Pirko <jiri@resnulli.us>
---
 net/core/net-sysfs.c | 15 ++++++++++++++-
 1 file changed, 14 insertions(+), 1 deletion(-)

diff --git a/net/core/net-sysfs.c b/net/core/net-sysfs.c
index 334efd5..7eda40a 100644
--- a/net/core/net-sysfs.c
+++ b/net/core/net-sysfs.c
@@ -126,6 +126,19 @@ static ssize_t show_broadcast(struct device *dev,
 	return -EINVAL;
 }
 
+static int change_carrier(struct net_device *net, unsigned long new_carrier)
+{
+	if (!netif_running(net))
+		return -EINVAL;
+	return dev_change_carrier(net, (bool) new_carrier);
+}
+
+static ssize_t store_carrier(struct device *dev, struct device_attribute *attr,
+			 const char *buf, size_t len)
+{
+	return netdev_store(dev, attr, buf, len, change_carrier);
+}
+
 static ssize_t show_carrier(struct device *dev,
 			    struct device_attribute *attr, char *buf)
 {
@@ -331,7 +344,7 @@ static struct device_attribute net_class_attributes[] = {
 	__ATTR(link_mode, S_IRUGO, show_link_mode, NULL),
 	__ATTR(address, S_IRUGO, show_address, NULL),
 	__ATTR(broadcast, S_IRUGO, show_broadcast, NULL),
-	__ATTR(carrier, S_IRUGO, show_carrier, NULL),
+	__ATTR(carrier, S_IRUGO | S_IWUSR, show_carrier, store_carrier),
 	__ATTR(speed, S_IRUGO, show_speed, NULL),
 	__ATTR(duplex, S_IRUGO, show_duplex, NULL),
 	__ATTR(dormant, S_IRUGO, show_dormant, NULL),
-- 
1.8.0

^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [patch net-next 3/4] rtnl: expose carrier value with possibility to set it
  2012-12-19  9:35 [patch net-next V3 0/4] net: allow to change carrier from userspace Jiri Pirko
  2012-12-19  9:35 ` [patch net-next 1/4] net: add change_carrier netdev op Jiri Pirko
  2012-12-19  9:35 ` [patch net-next 2/4] net: allow to change carrier via sysfs Jiri Pirko
@ 2012-12-19  9:35 ` Jiri Pirko
  2012-12-19  9:35 ` [patch net-next 4/4] dummy: implement carrier change Jiri Pirko
  2012-12-23 10:12 ` [patch net-next V3 0/4] net: allow to change carrier from userspace Jiri Pirko
  4 siblings, 0 replies; 9+ messages in thread
From: Jiri Pirko @ 2012-12-19  9:35 UTC (permalink / raw)
  To: netdev
  Cc: davem, edumazet, bhutchings, mirqus, shemminger, greearb, fbl,
	john.r.fastabend

Signed-off-by: Jiri Pirko <jiri@resnulli.us>
---
 Documentation/networking/operstates.txt |  4 ++++
 include/uapi/linux/if_link.h            |  1 +
 net/core/rtnetlink.c                    | 10 ++++++++++
 3 files changed, 15 insertions(+)

diff --git a/Documentation/networking/operstates.txt b/Documentation/networking/operstates.txt
index 1a77a3c..9769457 100644
--- a/Documentation/networking/operstates.txt
+++ b/Documentation/networking/operstates.txt
@@ -88,6 +88,10 @@ set this flag. On netif_carrier_off(), the scheduler stops sending
 packets. The name 'carrier' and the inversion are historical, think of
 it as lower layer.
 
+Note that for certain kind of soft-devices, which are not managing any
+real hardware, there is possible to set this bit from userpsace.
+One should use TVL IFLA_CARRIER to do so.
+
 netif_carrier_ok() can be used to query that bit.
 
 __LINK_STATE_DORMANT, maps to IFF_DORMANT:
diff --git a/include/uapi/linux/if_link.h b/include/uapi/linux/if_link.h
index 60f3b6b..c4edfe1 100644
--- a/include/uapi/linux/if_link.h
+++ b/include/uapi/linux/if_link.h
@@ -142,6 +142,7 @@ enum {
 #define IFLA_PROMISCUITY IFLA_PROMISCUITY
 	IFLA_NUM_TX_QUEUES,
 	IFLA_NUM_RX_QUEUES,
+	IFLA_CARRIER,
 	__IFLA_MAX
 };
 
diff --git a/net/core/rtnetlink.c b/net/core/rtnetlink.c
index 1868625..2ef7a56 100644
--- a/net/core/rtnetlink.c
+++ b/net/core/rtnetlink.c
@@ -780,6 +780,7 @@ static noinline size_t if_nlmsg_size(const struct net_device *dev,
 	       + nla_total_size(4) /* IFLA_MTU */
 	       + nla_total_size(4) /* IFLA_LINK */
 	       + nla_total_size(4) /* IFLA_MASTER */
+	       + nla_total_size(1) /* IFLA_CARRIER */
 	       + nla_total_size(4) /* IFLA_PROMISCUITY */
 	       + nla_total_size(4) /* IFLA_NUM_TX_QUEUES */
 	       + nla_total_size(4) /* IFLA_NUM_RX_QUEUES */
@@ -909,6 +910,7 @@ static int rtnl_fill_ifinfo(struct sk_buff *skb, struct net_device *dev,
 	     nla_put_u32(skb, IFLA_LINK, dev->iflink)) ||
 	    (dev->master &&
 	     nla_put_u32(skb, IFLA_MASTER, dev->master->ifindex)) ||
+	    nla_put_u8(skb, IFLA_CARRIER, netif_carrier_ok(dev)) ||
 	    (dev->qdisc &&
 	     nla_put_string(skb, IFLA_QDISC, dev->qdisc->ops->id)) ||
 	    (dev->ifalias &&
@@ -1108,6 +1110,7 @@ const struct nla_policy ifla_policy[IFLA_MAX+1] = {
 	[IFLA_MTU]		= { .type = NLA_U32 },
 	[IFLA_LINK]		= { .type = NLA_U32 },
 	[IFLA_MASTER]		= { .type = NLA_U32 },
+	[IFLA_CARRIER]		= { .type = NLA_U8 },
 	[IFLA_TXQLEN]		= { .type = NLA_U32 },
 	[IFLA_WEIGHT]		= { .type = NLA_U32 },
 	[IFLA_OPERSTATE]	= { .type = NLA_U8 },
@@ -1438,6 +1441,13 @@ static int do_setlink(struct net_device *dev, struct ifinfomsg *ifm,
 		modified = 1;
 	}
 
+	if (tb[IFLA_CARRIER]) {
+		err = dev_change_carrier(dev, nla_get_u8(tb[IFLA_CARRIER]));
+		if (err)
+			goto errout;
+		modified = 1;
+	}
+
 	if (tb[IFLA_TXQLEN])
 		dev->tx_queue_len = nla_get_u32(tb[IFLA_TXQLEN]);
 
-- 
1.8.0

^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [patch net-next 4/4] dummy: implement carrier change
  2012-12-19  9:35 [patch net-next V3 0/4] net: allow to change carrier from userspace Jiri Pirko
                   ` (2 preceding siblings ...)
  2012-12-19  9:35 ` [patch net-next 3/4] rtnl: expose carrier value with possibility to set it Jiri Pirko
@ 2012-12-19  9:35 ` Jiri Pirko
  2012-12-23 10:12 ` [patch net-next V3 0/4] net: allow to change carrier from userspace Jiri Pirko
  4 siblings, 0 replies; 9+ messages in thread
From: Jiri Pirko @ 2012-12-19  9:35 UTC (permalink / raw)
  To: netdev
  Cc: davem, edumazet, bhutchings, mirqus, shemminger, greearb, fbl,
	john.r.fastabend

Signed-off-by: Jiri Pirko <jiri@resnulli.us>
---
 drivers/net/dummy.c | 10 ++++++++++
 1 file changed, 10 insertions(+)

diff --git a/drivers/net/dummy.c b/drivers/net/dummy.c
index c260af5..42aa54a 100644
--- a/drivers/net/dummy.c
+++ b/drivers/net/dummy.c
@@ -100,6 +100,15 @@ static void dummy_dev_uninit(struct net_device *dev)
 	free_percpu(dev->dstats);
 }
 
+static int dummy_change_carrier(struct net_device *dev, bool new_carrier)
+{
+	if (new_carrier)
+		netif_carrier_on(dev);
+	else
+		netif_carrier_off(dev);
+	return 0;
+}
+
 static const struct net_device_ops dummy_netdev_ops = {
 	.ndo_init		= dummy_dev_init,
 	.ndo_uninit		= dummy_dev_uninit,
@@ -108,6 +117,7 @@ static const struct net_device_ops dummy_netdev_ops = {
 	.ndo_set_rx_mode	= set_multicast_list,
 	.ndo_set_mac_address	= eth_mac_addr,
 	.ndo_get_stats64	= dummy_get_stats64,
+	.ndo_change_carrier	= dummy_change_carrier,
 };
 
 static void dummy_setup(struct net_device *dev)
-- 
1.8.0

^ permalink raw reply related	[flat|nested] 9+ messages in thread

* Re: [patch net-next V3 0/4] net: allow to change carrier from userspace
  2012-12-19  9:35 [patch net-next V3 0/4] net: allow to change carrier from userspace Jiri Pirko
                   ` (3 preceding siblings ...)
  2012-12-19  9:35 ` [patch net-next 4/4] dummy: implement carrier change Jiri Pirko
@ 2012-12-23 10:12 ` Jiri Pirko
  2012-12-23 19:51   ` Stephen Hemminger
  2012-12-23 22:11   ` David Miller
  4 siblings, 2 replies; 9+ messages in thread
From: Jiri Pirko @ 2012-12-23 10:12 UTC (permalink / raw)
  To: netdev
  Cc: davem, edumazet, bhutchings, mirqus, shemminger, greearb, fbl,
	john.r.fastabend

Dave, I see that the patchwork status of this is "Deferred".
Should I repost the patchset?

thanks

Jiri


Wed, Dec 19, 2012 at 10:35:52AM CET, jiri@resnulli.us wrote:
>This is basically a V3 of a repost of my previous patchset:
>"[patch net-next-2.6 0/2] net: allow to change carrier via sysfs" from Aug 30
>
>The way net-sysfs stores values changed and this patchset reflects it.
>Also, I exposed carrier via rtnetlink iface.
>
>So far, only dummy driver uses carrier change ndo. In very near future
>team driver will use that as well.
>
>V2->V3:
> - updated ndo_change_carrier comment by Dan Williams
>
>V1->v2:
> - added bigger comment to ndo and also note to operstate.txt documentation
>   stating the clear purpose of this iface
>
>Jiri Pirko (4):
>  net: add change_carrier netdev op
>  net: allow to change carrier via sysfs
>  rtnl: expose carrier value with possibility to set it
>  dummy: implement carrier change
>
> Documentation/networking/operstates.txt |  4 ++++
> drivers/net/dummy.c                     | 10 ++++++++++
> include/linux/netdevice.h               | 12 ++++++++++++
> include/uapi/linux/if_link.h            |  1 +
> net/core/dev.c                          | 19 +++++++++++++++++++
> net/core/net-sysfs.c                    | 15 ++++++++++++++-
> net/core/rtnetlink.c                    | 10 ++++++++++
> 7 files changed, 70 insertions(+), 1 deletion(-)
>
>-- 
>1.8.0
>

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [patch net-next V3 0/4] net: allow to change carrier from userspace
  2012-12-23 10:12 ` [patch net-next V3 0/4] net: allow to change carrier from userspace Jiri Pirko
@ 2012-12-23 19:51   ` Stephen Hemminger
  2012-12-23 22:11   ` David Miller
  1 sibling, 0 replies; 9+ messages in thread
From: Stephen Hemminger @ 2012-12-23 19:51 UTC (permalink / raw)
  To: Jiri Pirko
  Cc: netdev, davem, edumazet, bhutchings, mirqus, greearb, fbl,
	john.r.fastabend

On Sun, 23 Dec 2012 11:12:06 +0100
Jiri Pirko <jiri@resnulli.us> wrote:

> Dave, I see that the patchwork status of this is "Deferred".
> Should I repost the patchset?
> 
> thanks

The merge window for 3.8 is complete, only bug fixes are accepted.
And Net-next is not open yet. And this is a new feature.

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [patch net-next V3 0/4] net: allow to change carrier from userspace
  2012-12-23 10:12 ` [patch net-next V3 0/4] net: allow to change carrier from userspace Jiri Pirko
  2012-12-23 19:51   ` Stephen Hemminger
@ 2012-12-23 22:11   ` David Miller
  2012-12-24  8:06     ` Jiri Pirko
  1 sibling, 1 reply; 9+ messages in thread
From: David Miller @ 2012-12-23 22:11 UTC (permalink / raw)
  To: jiri
  Cc: netdev, edumazet, bhutchings, mirqus, shemminger, greearb, fbl,
	john.r.fastabend

From: Jiri Pirko <jiri@resnulli.us>
Date: Sun, 23 Dec 2012 11:12:06 +0100

> Dave, I see that the patchwork status of this is "Deferred".
> Should I repost the patchset?

It's deferred because I haven't openned up the net-next tree
yet, so you're wasting your time if you just keep reposting
the serious while the tree is closed.

Please instead wait patiently for when I announce here that
the net-next tree is open again.

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [patch net-next V3 0/4] net: allow to change carrier from userspace
  2012-12-23 22:11   ` David Miller
@ 2012-12-24  8:06     ` Jiri Pirko
  0 siblings, 0 replies; 9+ messages in thread
From: Jiri Pirko @ 2012-12-24  8:06 UTC (permalink / raw)
  To: David Miller
  Cc: netdev, edumazet, bhutchings, mirqus, shemminger, greearb, fbl,
	john.r.fastabend

Sun, Dec 23, 2012 at 11:11:53PM CET, davem@davemloft.net wrote:
>From: Jiri Pirko <jiri@resnulli.us>
>Date: Sun, 23 Dec 2012 11:12:06 +0100
>
>> Dave, I see that the patchwork status of this is "Deferred".
>> Should I repost the patchset?
>
>It's deferred because I haven't openned up the net-next tree
>yet, so you're wasting your time if you just keep reposting
>the serious while the tree is closed.
>
>Please instead wait patiently for when I announce here that
>the net-next tree is open again.

Okay, thanks.

^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2012-12-24  8:07 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-12-19  9:35 [patch net-next V3 0/4] net: allow to change carrier from userspace Jiri Pirko
2012-12-19  9:35 ` [patch net-next 1/4] net: add change_carrier netdev op Jiri Pirko
2012-12-19  9:35 ` [patch net-next 2/4] net: allow to change carrier via sysfs Jiri Pirko
2012-12-19  9:35 ` [patch net-next 3/4] rtnl: expose carrier value with possibility to set it Jiri Pirko
2012-12-19  9:35 ` [patch net-next 4/4] dummy: implement carrier change Jiri Pirko
2012-12-23 10:12 ` [patch net-next V3 0/4] net: allow to change carrier from userspace Jiri Pirko
2012-12-23 19:51   ` Stephen Hemminger
2012-12-23 22:11   ` David Miller
2012-12-24  8:06     ` Jiri Pirko

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).