Commit 34a9c361 authored by Taehee Yoo's avatar Taehee Yoo Committed by David S. Miller

hsr: remove hsr interface if all slaves are removed

When all hsr slave interfaces are removed, hsr interface doesn't work.
At that moment, it's fine to remove an unused hsr interface automatically
for saving resources.
That's a common behavior of virtual interfaces.
Signed-off-by: default avatarTaehee Yoo <ap420073@gmail.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 1b2e7884
...@@ -15,12 +15,23 @@ ...@@ -15,12 +15,23 @@
#include "hsr_framereg.h" #include "hsr_framereg.h"
#include "hsr_slave.h" #include "hsr_slave.h"
static bool hsr_slave_empty(struct hsr_priv *hsr)
{
struct hsr_port *port;
hsr_for_each_port(hsr, port)
if (port->type != HSR_PT_MASTER)
return false;
return true;
}
static int hsr_netdev_notify(struct notifier_block *nb, unsigned long event, static int hsr_netdev_notify(struct notifier_block *nb, unsigned long event,
void *ptr) void *ptr)
{ {
struct net_device *dev;
struct hsr_port *port, *master; struct hsr_port *port, *master;
struct net_device *dev;
struct hsr_priv *hsr; struct hsr_priv *hsr;
LIST_HEAD(list_kill);
int mtu_max; int mtu_max;
int res; int res;
...@@ -85,8 +96,15 @@ static int hsr_netdev_notify(struct notifier_block *nb, unsigned long event, ...@@ -85,8 +96,15 @@ static int hsr_netdev_notify(struct notifier_block *nb, unsigned long event,
master->dev->mtu = mtu_max; master->dev->mtu = mtu_max;
break; break;
case NETDEV_UNREGISTER: case NETDEV_UNREGISTER:
if (!is_hsr_master(dev)) if (!is_hsr_master(dev)) {
master = hsr_port_get_hsr(port->hsr, HSR_PT_MASTER);
hsr_del_port(port); hsr_del_port(port);
if (hsr_slave_empty(master->hsr)) {
unregister_netdevice_queue(master->dev,
&list_kill);
unregister_netdevice_many(&list_kill);
}
}
break; break;
case NETDEV_PRE_TYPE_CHANGE: case NETDEV_PRE_TYPE_CHANGE:
/* HSR works only on Ethernet devices. Refuse slave to change /* HSR works only on Ethernet devices. Refuse slave to change
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment