public inbox for netdev@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] macvlan: Support interface operstate properly
@ 2016-04-06 20:30 Debabrata Banerjee
  2016-04-06 21:03 ` Nikolay Aleksandrov
  0 siblings, 1 reply; 5+ messages in thread
From: Debabrata Banerjee @ 2016-04-06 20:30 UTC (permalink / raw)
  To: Patrick McHardy, netdev; +Cc: linux-kernel, Debabrata Banerjee

Set appropriate macvlan interface status based on lower device and our
status. Can be up, down, or lowerlayerdown.

Signed-off-by: Debabrata Banerjee <dbanerje@akamai.com>

diff --git a/drivers/net/macvlan.c b/drivers/net/macvlan.c
index 2bcf1f3..0f4b000 100644
--- a/drivers/net/macvlan.c
+++ b/drivers/net/macvlan.c
@@ -91,6 +91,7 @@ static struct macvlan_port *macvlan_port_get_rtnl(const struct net_device *dev)
 }
 
 #define macvlan_port_exists(dev) (dev->priv_flags & IFF_MACVLAN_PORT)
+#define is_macvlan(dev) (dev->priv_flags & IFF_MACVLAN)
 
 static struct macvlan_dev *macvlan_hash_lookup(const struct macvlan_port *port,
 					       const unsigned char *addr)
@@ -1242,6 +1243,26 @@ static int macvlan_changelink_sources(struct macvlan_dev *vlan, u32 mode,
 	return 0;
 }
 
+static void macvlan_set_operstate(struct net_device *lowerdev,
+				  struct net_device *dev)
+{
+	unsigned char newstate = dev->operstate;
+
+	if (!(dev->flags & IFF_UP))
+		newstate = IF_OPER_DOWN;
+	else if ((lowerdev->flags & IFF_UP) && netif_oper_up(lowerdev))
+		newstate = IF_OPER_UP;
+	else
+		newstate = IF_OPER_LOWERLAYERDOWN;
+
+	if (dev->operstate != newstate) {
+		write_lock_bh(&dev_base_lock);
+		dev->operstate = newstate;
+		netdev_state_change(dev);
+		write_unlock_bh(&dev_base_lock);
+	}
+}
+
 int macvlan_common_newlink(struct net *src_net, struct net_device *dev,
 			   struct nlattr *tb[], struct nlattr *data[])
 {
@@ -1324,6 +1345,7 @@ int macvlan_common_newlink(struct net *src_net, struct net_device *dev,
 
 	list_add_tail_rcu(&vlan->list, &port->vlans);
 	netif_stacked_transfer_operstate(lowerdev, dev);
+	macvlan_set_operstate(lowerdev, dev);
 	linkwatch_fire_event(dev);
 
 	return 0;
@@ -1518,17 +1540,36 @@ static int macvlan_device_event(struct notifier_block *unused,
 	struct macvlan_port *port;
 	LIST_HEAD(list_kill);
 
-	if (!macvlan_port_exists(dev))
+	if (!macvlan_port_exists(dev) && !is_macvlan(dev))
 		return NOTIFY_DONE;
 
+	if (is_macvlan(dev)) {
+		vlan = netdev_priv(dev);
+
+		switch (event) {
+		case NETDEV_UP:
+		case NETDEV_DOWN:
+		case NETDEV_CHANGE:
+			netif_stacked_transfer_operstate(vlan->lowerdev,
+							 vlan->dev);
+			macvlan_set_operstate(vlan->lowerdev, vlan->dev);
+			break;
+		}
+
+		return NOTIFY_DONE;
+	}
+
 	port = macvlan_port_get_rtnl(dev);
 
 	switch (event) {
 	case NETDEV_UP:
+	case NETDEV_DOWN:
 	case NETDEV_CHANGE:
-		list_for_each_entry(vlan, &port->vlans, list)
+		list_for_each_entry(vlan, &port->vlans, list) {
 			netif_stacked_transfer_operstate(vlan->lowerdev,
 							 vlan->dev);
+			macvlan_set_operstate(vlan->lowerdev, vlan->dev);
+		}
 		break;
 	case NETDEV_FEAT_CHANGE:
 		list_for_each_entry(vlan, &port->vlans, list) {
-- 
2.8.0

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

* Re: [PATCH] macvlan: Support interface operstate properly
  2016-04-06 20:30 [PATCH] macvlan: Support interface operstate properly Debabrata Banerjee
@ 2016-04-06 21:03 ` Nikolay Aleksandrov
  2016-04-06 21:26   ` Banerjee, Debabrata
  2016-04-06 21:27   ` Nikolay Aleksandrov
  0 siblings, 2 replies; 5+ messages in thread
From: Nikolay Aleksandrov @ 2016-04-06 21:03 UTC (permalink / raw)
  To: Debabrata Banerjee, Patrick McHardy, netdev

On 04/06/2016 10:30 PM, Debabrata Banerjee wrote:
> Set appropriate macvlan interface status based on lower device and our
> status. Can be up, down, or lowerlayerdown.
> 
> Signed-off-by: Debabrata Banerjee <dbanerje@akamai.com>
> 

May I ask what is exactly that you're fixing here ? I recently had to make macvlan's
operstates more accurate and I haven't experienced any wrong behaviour since commit
de7d244d0a35 ("macvlan: make operstate and carrier more accurate").
Also it's the linkwatch's job to take care for the proper operstate, we can use
netif_stacked_transfer_operstate to help it, but I don't think directly setting
operstate is a good idea.

One more thing - you cannot use netdev_state_change() under the write_lock as it
may sleep.

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

* Re: [PATCH] macvlan: Support interface operstate properly
  2016-04-06 21:03 ` Nikolay Aleksandrov
@ 2016-04-06 21:26   ` Banerjee, Debabrata
  2016-04-06 21:42     ` Nikolay Aleksandrov
  2016-04-06 21:27   ` Nikolay Aleksandrov
  1 sibling, 1 reply; 5+ messages in thread
From: Banerjee, Debabrata @ 2016-04-06 21:26 UTC (permalink / raw)
  To: Nikolay Aleksandrov, Patrick McHardy, netdev@vger.kernel.org

On 4/6/16, 5:03 PM, "Nikolay Aleksandrov" <nikolay@cumulusnetworks.com> wrote:


>On 04/06/2016 10:30 PM, Debabrata Banerjee wrote:
>> Set appropriate macvlan interface status based on lower device and our
>> status. Can be up, down, or lowerlayerdown.
>> 
>> Signed-off-by: Debabrata Banerjee <dbanerje@akamai.com>
>> 
>
>May I ask what is exactly that you're fixing here ? I recently had to make macvlan's
>operstates more accurate and I haven't experienced any wrong behaviour since commit
>de7d244d0a35 ("macvlan: make operstate and carrier more accurate").

Yes I saw the other patch, it's an improvement from when I started working on this. 


>Also it's the linkwatch's job to take care for the proper operstate, we can use
>netif_stacked_transfer_operstate to help it, but I don't think directly setting
>operstate is a good idea.

This patch was modeled after __hsr_set_operstate(). But I agree there's probably
better ways to do it. I'm not sure why netif_stacked_transfer_operstate() doesn't do
it itself, although in the case of a layered device, my patch actually uses the other
possible state, which is lowerlayerdown. Without the patch operstate goes directly to
down.

>
>One more thing - you cannot use netdev_state_change() under the write_lock as it
>may sleep.

You're right, I can resubmit moving the call out of the critical section, if the patch
will be taken.


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

* Re: [PATCH] macvlan: Support interface operstate properly
  2016-04-06 21:03 ` Nikolay Aleksandrov
  2016-04-06 21:26   ` Banerjee, Debabrata
@ 2016-04-06 21:27   ` Nikolay Aleksandrov
  1 sibling, 0 replies; 5+ messages in thread
From: Nikolay Aleksandrov @ 2016-04-06 21:27 UTC (permalink / raw)
  To: Debabrata Banerjee, Patrick McHardy, netdev

On 04/06/2016 11:03 PM, Nikolay Aleksandrov wrote:
> On 04/06/2016 10:30 PM, Debabrata Banerjee wrote:
>> Set appropriate macvlan interface status based on lower device and our
>> status. Can be up, down, or lowerlayerdown.
>>
>> Signed-off-by: Debabrata Banerjee <dbanerje@akamai.com>
>>
> 
> May I ask what is exactly that you're fixing here ? I recently had to make macvlan's
> operstates more accurate and I haven't experienced any wrong behaviour since commit
> de7d244d0a35 ("macvlan: make operstate and carrier more accurate").
> Also it's the linkwatch's job to take care for the proper operstate, we can use
> netif_stacked_transfer_operstate to help it, but I don't think directly setting
> operstate is a good idea.

Misread part of the change, got it now. My comment below still stands though,

> One more thing - you cannot use netdev_state_change() under the write_lock as it
> may sleep.
> 

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

* Re: [PATCH] macvlan: Support interface operstate properly
  2016-04-06 21:26   ` Banerjee, Debabrata
@ 2016-04-06 21:42     ` Nikolay Aleksandrov
  0 siblings, 0 replies; 5+ messages in thread
From: Nikolay Aleksandrov @ 2016-04-06 21:42 UTC (permalink / raw)
  To: Banerjee, Debabrata, Patrick McHardy, netdev@vger.kernel.org

On 04/06/2016 11:26 PM, Banerjee, Debabrata wrote:
> On 4/6/16, 5:03 PM, "Nikolay Aleksandrov" <nikolay@cumulusnetworks.com> wrote:
> 
> 
>> On 04/06/2016 10:30 PM, Debabrata Banerjee wrote:
>>> Set appropriate macvlan interface status based on lower device and our
>>> status. Can be up, down, or lowerlayerdown.
>>>
>>> Signed-off-by: Debabrata Banerjee <dbanerje@akamai.com>
>>>
>>
>> May I ask what is exactly that you're fixing here ? I recently had to make macvlan's
>> operstates more accurate and I haven't experienced any wrong behaviour since commit
>> de7d244d0a35 ("macvlan: make operstate and carrier more accurate").
> 
> Yes I saw the other patch, it's an improvement from when I started working on this. 
> 
> 
>> Also it's the linkwatch's job to take care for the proper operstate, we can use
>> netif_stacked_transfer_operstate to help it, but I don't think directly setting
>> operstate is a good idea.
> 
> This patch was modeled after __hsr_set_operstate(). But I agree there's probably
> better ways to do it. I'm not sure why netif_stacked_transfer_operstate() doesn't do
> it itself, although in the case of a layered device, my patch actually uses the other
> possible state, which is lowerlayerdown. Without the patch operstate goes directly to
> down.
> 
>>
>> One more thing - you cannot use netdev_state_change() under the write_lock as it
>> may sleep.
> 
> You're right, I can resubmit moving the call out of the critical section, if the patch
> will be taken.
> 

I don't know if it'll be taken, but you can submit v2 for review. I'll review and
test it tomorrow as it's late here and I'm tired. :-)
Since this is not a bug fix, I'd suggest to target net-next and you
don't have to CC linux-kernel@vger.kernel.org.

Thanks for the explanation, I misread part of the patch at first and was confused,
but I got the idea now.

Cheers,
 Nik

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

end of thread, other threads:[~2016-04-06 21:42 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-04-06 20:30 [PATCH] macvlan: Support interface operstate properly Debabrata Banerjee
2016-04-06 21:03 ` Nikolay Aleksandrov
2016-04-06 21:26   ` Banerjee, Debabrata
2016-04-06 21:42     ` Nikolay Aleksandrov
2016-04-06 21:27   ` Nikolay Aleksandrov

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox