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

hsr: use upper/lower device infrastructure

netdev_upper_dev_link() is useful to manage lower/upper interfaces.
And this function internally validates looping, maximum depth.
All or most virtual interfaces that could have a real interface
(e.g. macsec, macvlan, ipvlan etc.) use lower/upper infrastructure.
Signed-off-by: default avatarTaehee Yoo <ap420073@gmail.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 81390d0c
...@@ -341,22 +341,33 @@ static void hsr_announce(struct timer_list *t) ...@@ -341,22 +341,33 @@ static void hsr_announce(struct timer_list *t)
rcu_read_unlock(); rcu_read_unlock();
} }
static void hsr_del_ports(struct hsr_priv *hsr)
{
struct hsr_port *port;
port = hsr_port_get_hsr(hsr, HSR_PT_SLAVE_A);
if (port)
hsr_del_port(port);
port = hsr_port_get_hsr(hsr, HSR_PT_SLAVE_B);
if (port)
hsr_del_port(port);
port = hsr_port_get_hsr(hsr, HSR_PT_MASTER);
if (port)
hsr_del_port(port);
}
/* This has to be called after all the readers are gone. /* This has to be called after all the readers are gone.
* Otherwise we would have to check the return value of * Otherwise we would have to check the return value of
* hsr_port_get_hsr(). * hsr_port_get_hsr().
*/ */
static void hsr_dev_destroy(struct net_device *hsr_dev) static void hsr_dev_destroy(struct net_device *hsr_dev)
{ {
struct hsr_priv *hsr; struct hsr_priv *hsr = netdev_priv(hsr_dev);
struct hsr_port *port;
struct hsr_port *tmp;
hsr = netdev_priv(hsr_dev);
hsr_debugfs_term(hsr); hsr_debugfs_term(hsr);
hsr_del_ports(hsr);
list_for_each_entry_safe(port, tmp, &hsr->ports, port_list)
hsr_del_port(port);
del_timer_sync(&hsr->prune_timer); del_timer_sync(&hsr->prune_timer);
del_timer_sync(&hsr->announce_timer); del_timer_sync(&hsr->announce_timer);
...@@ -426,8 +437,6 @@ int hsr_dev_finalize(struct net_device *hsr_dev, struct net_device *slave[2], ...@@ -426,8 +437,6 @@ int hsr_dev_finalize(struct net_device *hsr_dev, struct net_device *slave[2],
struct netlink_ext_ack *extack) struct netlink_ext_ack *extack)
{ {
struct hsr_priv *hsr; struct hsr_priv *hsr;
struct hsr_port *port;
struct hsr_port *tmp;
int res; int res;
hsr = netdev_priv(hsr_dev); hsr = netdev_priv(hsr_dev);
...@@ -494,8 +503,7 @@ int hsr_dev_finalize(struct net_device *hsr_dev, struct net_device *slave[2], ...@@ -494,8 +503,7 @@ int hsr_dev_finalize(struct net_device *hsr_dev, struct net_device *slave[2],
err_add_slaves: err_add_slaves:
unregister_netdevice(hsr_dev); unregister_netdevice(hsr_dev);
err_unregister: err_unregister:
list_for_each_entry_safe(port, tmp, &hsr->ports, port_list) hsr_del_ports(hsr);
hsr_del_port(port);
err_add_master: err_add_master:
hsr_del_self_node(hsr); hsr_del_self_node(hsr);
......
...@@ -85,6 +85,7 @@ static int hsr_netdev_notify(struct notifier_block *nb, unsigned long event, ...@@ -85,6 +85,7 @@ 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))
hsr_del_port(port); hsr_del_port(port);
break; break;
case NETDEV_PRE_TYPE_CHANGE: case NETDEV_PRE_TYPE_CHANGE:
......
...@@ -97,19 +97,25 @@ static int hsr_check_dev_ok(struct net_device *dev, ...@@ -97,19 +97,25 @@ static int hsr_check_dev_ok(struct net_device *dev,
} }
/* Setup device to be added to the HSR bridge. */ /* Setup device to be added to the HSR bridge. */
static int hsr_portdev_setup(struct net_device *dev, struct hsr_port *port) static int hsr_portdev_setup(struct hsr_priv *hsr, struct net_device *dev,
struct hsr_port *port,
struct netlink_ext_ack *extack)
{ {
struct net_device *hsr_dev;
struct hsr_port *master;
int res; int res;
dev_hold(dev);
res = dev_set_promiscuity(dev, 1); res = dev_set_promiscuity(dev, 1);
if (res) if (res)
goto fail_promiscuity; goto fail_promiscuity;
/* FIXME: master = hsr_port_get_hsr(hsr, HSR_PT_MASTER);
* What does net device "adjacency" mean? Should we do hsr_dev = master->dev;
* res = netdev_master_upper_dev_link(port->dev, port->hsr->dev); ?
*/ res = netdev_upper_dev_link(dev, hsr_dev, extack);
if (res)
goto fail_upper_dev_link;
res = netdev_rx_handler_register(dev, hsr_handle_frame, port); res = netdev_rx_handler_register(dev, hsr_handle_frame, port);
if (res) if (res)
...@@ -119,6 +125,8 @@ static int hsr_portdev_setup(struct net_device *dev, struct hsr_port *port) ...@@ -119,6 +125,8 @@ static int hsr_portdev_setup(struct net_device *dev, struct hsr_port *port)
return 0; return 0;
fail_rx_handler: fail_rx_handler:
netdev_upper_dev_unlink(dev, hsr_dev);
fail_upper_dev_link:
dev_set_promiscuity(dev, -1); dev_set_promiscuity(dev, -1);
fail_promiscuity: fail_promiscuity:
dev_put(dev); dev_put(dev);
...@@ -147,7 +155,7 @@ int hsr_add_port(struct hsr_priv *hsr, struct net_device *dev, ...@@ -147,7 +155,7 @@ int hsr_add_port(struct hsr_priv *hsr, struct net_device *dev,
return -ENOMEM; return -ENOMEM;
if (type != HSR_PT_MASTER) { if (type != HSR_PT_MASTER) {
res = hsr_portdev_setup(dev, port); res = hsr_portdev_setup(hsr, dev, port, extack);
if (res) if (res)
goto fail_dev_setup; goto fail_dev_setup;
} }
...@@ -180,21 +188,14 @@ void hsr_del_port(struct hsr_port *port) ...@@ -180,21 +188,14 @@ void hsr_del_port(struct hsr_port *port)
list_del_rcu(&port->port_list); list_del_rcu(&port->port_list);
if (port != master) { if (port != master) {
if (master) {
netdev_update_features(master->dev); netdev_update_features(master->dev);
dev_set_mtu(master->dev, hsr_get_max_mtu(hsr)); dev_set_mtu(master->dev, hsr_get_max_mtu(hsr));
}
netdev_rx_handler_unregister(port->dev); netdev_rx_handler_unregister(port->dev);
dev_set_promiscuity(port->dev, -1); dev_set_promiscuity(port->dev, -1);
netdev_upper_dev_unlink(port->dev, master->dev);
} }
/* FIXME?
* netdev_upper_dev_unlink(port->dev, port->hsr->dev);
*/
synchronize_rcu(); synchronize_rcu();
if (port != master)
dev_put(port->dev);
kfree(port); kfree(port);
} }
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