net: allow to change carrier from userspace
Subsystems (3)
v3 cover net: allow to change carrier from userspace
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(-)
Signature · 1 line
1.8.0
PATCH v3 1/4 net: add change_carrier netdev op
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.
--- include/linux/netdevice.h | 12 ++++++++++++ net/core/dev.c | 19 +++++++++++++++++++ 2 files changed, 31 insertions(+)
include/linux/netdevice.h +12 -0
@@ -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);
net/core/dev.c +19 -0
@@ -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() */
Signature · 1 line
1.8.0
PATCH v3 2/4 net: allow to change carrier via sysfs
In reply to Jiri PirkoMake carrier writable
--- net/core/net-sysfs.c | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-)
net/core/net-sysfs.c +14 -1
@@ -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),
Signature · 1 line
1.8.0
PATCH v3 3/4 rtnl: expose carrier value with possibility to set it
In reply to Jiri Pirko--- Documentation/networking/operstates.txt | 4 ++++ include/uapi/linux/if_link.h | 1 + net/core/rtnetlink.c | 10 ++++++++++ 3 files changed, 15 insertions(+)
Documentation/networking/operstates.txt +4 -0
@@ -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:
include/uapi/linux/if_link.h +1 -0
@@ -142,6 +142,7 @@ enum {#define IFLA_PROMISCUITY IFLA_PROMISCUITYIFLA_NUM_TX_QUEUES ,IFLA_NUM_RX_QUEUES , +IFLA_CARRIER , __IFLA_MAX };
net/core/rtnetlink.c +10 -0
@@ -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 ]);
Signature · 1 line
1.8.0
PATCH v3 4/4 dummy: implement carrier change
In reply to Jiri Pirko--- drivers/net/dummy.c | 10 ++++++++++ 1 file changed, 10 insertions(+)
drivers/net/dummy.c +10 -0
@@ -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)
Signature · 1 line
1.8.0
Dave, I see that the patchwork status of this is "Deferred". Should I repost the patchset?
thanks
Jiri
Quoted 34 lines · Wed, Dec 19, 2012 at 10:35:52AM CET, [email protected] 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 30The 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:
- updatedndo_change_carriercomment by Dan Williams
V1->v2:
- added bigger comment to ndo and also note to operstate.txt documentation stating the clear purpose of this ifaceJiri Pirko (4):
net: addchange_carriernetdev op
net: allow to change carrier via sysfs
rtnl: expose carrier value with possibility to set it
dummy: implement carrier changeDocumentation/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(-)Signature · 1 line
1.8.0
Quoted 4 lines · On Sun, 23 Dec 2012 11:12:06 +0100 Jiri Pirko <[email protected]> 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.
David Miller
maintainerFrom: Jiri Pirko <[email protected]>
Date: Sun, 23 Dec 2012 11:12:06 +0100
Quoted 2 lines
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.
Quoted 6 lines · Sun, Dec 23, 2012 at 11:11:53PM CET, [email protected] wrote:
From: Jiri Pirko <[email protected]>
Date: Sun, 23 Dec 2012 11:12:06 +0100Quoted 2 lines
Dave, I see that the patchwork status of this is "Deferred". Should I repost the patchset?
Quoted 6 lines
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.