Commit fa205602 authored by Sven Eckelmann's avatar Sven Eckelmann Committed by Simon Wunderlich

batman-adv: Avoid name based attaching of hard interfaces

The sysfs code for the batman-adv/mesh_iface file was receiving a string of
the batadv interface. This interface name was then provided to the code
which shared sysfs+rtnetlink code for attaching an hard-interface to an
batadv interface. The rtnetlink code was also using the (extracted)
interface name from the ndo_add_slave callback to increase the shared code
- even when it would have been more efficient to use the provided
net_device object directly instead of searching it again (based on its
name) in batadv_hardif_enable_interface.

But this indirect handling is no longer necessary because the sysfs code
was dropped. There is now only a single code path which is using
batadv_hardif_enable_interface.
Signed-off-by: default avatarSven Eckelmann <sven@narfation.org>
Signed-off-by: default avatarSimon Wunderlich <sw@simonwunderlich.de>
parent bf6b260b
...@@ -705,16 +705,15 @@ static int batadv_master_del_slave(struct batadv_hard_iface *slave, ...@@ -705,16 +705,15 @@ static int batadv_master_del_slave(struct batadv_hard_iface *slave,
/** /**
* batadv_hardif_enable_interface() - Enslave hard interface to soft interface * batadv_hardif_enable_interface() - Enslave hard interface to soft interface
* @hard_iface: hard interface to add to soft interface * @hard_iface: hard interface to add to soft interface
* @net: the applicable net namespace * @soft_iface: netdev struct of the mesh interface
* @iface_name: name of the soft interface
* *
* Return: 0 on success or negative error number in case of failure * Return: 0 on success or negative error number in case of failure
*/ */
int batadv_hardif_enable_interface(struct batadv_hard_iface *hard_iface, int batadv_hardif_enable_interface(struct batadv_hard_iface *hard_iface,
struct net *net, const char *iface_name) struct net_device *soft_iface)
{ {
struct batadv_priv *bat_priv; struct batadv_priv *bat_priv;
struct net_device *soft_iface, *master; struct net_device *master;
__be16 ethertype = htons(ETH_P_BATMAN); __be16 ethertype = htons(ETH_P_BATMAN);
int max_header_len = batadv_max_header_len(); int max_header_len = batadv_max_header_len();
int ret; int ret;
...@@ -724,11 +723,7 @@ int batadv_hardif_enable_interface(struct batadv_hard_iface *hard_iface, ...@@ -724,11 +723,7 @@ int batadv_hardif_enable_interface(struct batadv_hard_iface *hard_iface,
kref_get(&hard_iface->refcount); kref_get(&hard_iface->refcount);
soft_iface = dev_get_by_name(net, iface_name); dev_hold(soft_iface);
if (!soft_iface) {
ret = -EINVAL;
goto err;
}
if (!batadv_softif_is_valid(soft_iface)) { if (!batadv_softif_is_valid(soft_iface)) {
pr_err("Can't create batman mesh interface %s: already exists as regular interface\n", pr_err("Can't create batman mesh interface %s: already exists as regular interface\n",
...@@ -802,7 +797,6 @@ int batadv_hardif_enable_interface(struct batadv_hard_iface *hard_iface, ...@@ -802,7 +797,6 @@ int batadv_hardif_enable_interface(struct batadv_hard_iface *hard_iface,
err_dev: err_dev:
hard_iface->soft_iface = NULL; hard_iface->soft_iface = NULL;
dev_put(soft_iface); dev_put(soft_iface);
err:
batadv_hardif_put(hard_iface); batadv_hardif_put(hard_iface);
return ret; return ret;
} }
......
...@@ -16,7 +16,6 @@ ...@@ -16,7 +16,6 @@
#include <linux/rcupdate.h> #include <linux/rcupdate.h>
#include <linux/stddef.h> #include <linux/stddef.h>
#include <linux/types.h> #include <linux/types.h>
#include <net/net_namespace.h>
/** /**
* enum batadv_hard_if_state - State of a hard interface * enum batadv_hard_if_state - State of a hard interface
...@@ -75,7 +74,7 @@ bool batadv_is_wifi_hardif(struct batadv_hard_iface *hard_iface); ...@@ -75,7 +74,7 @@ bool batadv_is_wifi_hardif(struct batadv_hard_iface *hard_iface);
struct batadv_hard_iface* struct batadv_hard_iface*
batadv_hardif_get_by_netdev(const struct net_device *net_dev); batadv_hardif_get_by_netdev(const struct net_device *net_dev);
int batadv_hardif_enable_interface(struct batadv_hard_iface *hard_iface, int batadv_hardif_enable_interface(struct batadv_hard_iface *hard_iface,
struct net *net, const char *iface_name); struct net_device *soft_iface);
void batadv_hardif_disable_interface(struct batadv_hard_iface *hard_iface); void batadv_hardif_disable_interface(struct batadv_hard_iface *hard_iface);
int batadv_hardif_min_mtu(struct net_device *soft_iface); int batadv_hardif_min_mtu(struct net_device *soft_iface);
void batadv_update_min_mtu(struct net_device *soft_iface); void batadv_update_min_mtu(struct net_device *soft_iface);
......
...@@ -842,14 +842,13 @@ static int batadv_softif_slave_add(struct net_device *dev, ...@@ -842,14 +842,13 @@ static int batadv_softif_slave_add(struct net_device *dev,
struct netlink_ext_ack *extack) struct netlink_ext_ack *extack)
{ {
struct batadv_hard_iface *hard_iface; struct batadv_hard_iface *hard_iface;
struct net *net = dev_net(dev);
int ret = -EINVAL; int ret = -EINVAL;
hard_iface = batadv_hardif_get_by_netdev(slave_dev); hard_iface = batadv_hardif_get_by_netdev(slave_dev);
if (!hard_iface || hard_iface->soft_iface) if (!hard_iface || hard_iface->soft_iface)
goto out; goto out;
ret = batadv_hardif_enable_interface(hard_iface, net, dev->name); ret = batadv_hardif_enable_interface(hard_iface, dev);
out: out:
if (hard_iface) if (hard_iface)
......
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