Skip to content

Commit

Permalink
Merge branch 'mlxsw-ERSPAN-Take-LACP-state-into-consideration'
Browse files Browse the repository at this point in the history
Ido Schimmel says:

====================
mlxsw: ERSPAN: Take LACP state into consideration

Petr says:

When offloading mirror-to-gretap, mlxsw needs to preroute the path that
the encapsulated packet will take. That path may include a LAG device
above a front panel port. So far, mlxsw resolved the path to the first
up front panel slave of the LAG interface, but that only reflects
administrative state of the port. It neglects to consider whether the
port actually has a carrier, and what the LACP state is. This patch set
aims to address these problems.

Patch #1 publishes team_port_get_rcu().

Then in patch #2, a new function is introduced,
mlxsw_sp_port_dev_check(). That returns, for a given netdevice that is a
slave of a LAG device, whether that device is "txable", i.e. whether the
LAG master would send traffic through it. Since there's no good place to
put LAG-wide helpers, introduce a new header include/net/lag.h.

Finally in patch #3, fix the slave selection logic to take into
consideration whether a given slave has a carrier and whether it is
txable.
====================

Signed-off-by: David S. Miller <davem@davemloft.net>
  • Loading branch information
David S. Miller committed Jul 12, 2018
2 parents 80fd2d6 + b5de82f commit d90a521
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 6 deletions.
5 changes: 4 additions & 1 deletion drivers/net/ethernet/mellanox/mlxsw/spectrum_span.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
#include <linux/list.h>
#include <net/arp.h>
#include <net/gre.h>
#include <net/lag.h>
#include <net/ndisc.h>
#include <net/ip6_tunnel.h>

Expand Down Expand Up @@ -254,7 +255,9 @@ mlxsw_sp_span_entry_lag(struct net_device *lag_dev)
struct list_head *iter;

netdev_for_each_lower_dev(lag_dev, dev, iter)
if ((dev->flags & IFF_UP) && mlxsw_sp_port_dev_check(dev))
if (netif_carrier_ok(dev) &&
net_lag_port_dev_txable(dev) &&
mlxsw_sp_port_dev_check(dev))
return dev;

return NULL;
Expand Down
5 changes: 0 additions & 5 deletions drivers/net/team/team.c
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,6 @@

#define team_port_exists(dev) (dev->priv_flags & IFF_TEAM_PORT)

static struct team_port *team_port_get_rcu(const struct net_device *dev)
{
return rcu_dereference(dev->rx_handler_data);
}

static struct team_port *team_port_get_rtnl(const struct net_device *dev)
{
struct team_port *port = rtnl_dereference(dev->rx_handler_data);
Expand Down
18 changes: 18 additions & 0 deletions include/linux/if_team.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,11 @@ struct team_port {
long mode_priv[0];
};

static inline struct team_port *team_port_get_rcu(const struct net_device *dev)
{
return rcu_dereference(dev->rx_handler_data);
}

static inline bool team_port_enabled(struct team_port *port)
{
return port->index != -1;
Expand All @@ -84,6 +89,19 @@ static inline bool team_port_txable(struct team_port *port)
return port->linkup && team_port_enabled(port);
}

static inline bool team_port_dev_txable(const struct net_device *port_dev)
{
struct team_port *port;
bool txable;

rcu_read_lock();
port = team_port_get_rcu(port_dev);
txable = port ? team_port_txable(port) : false;
rcu_read_unlock();

return txable;
}

#ifdef CONFIG_NET_POLL_CONTROLLER
static inline void team_netpoll_send_skb(struct team_port *port,
struct sk_buff *skb)
Expand Down
13 changes: 13 additions & 0 deletions include/net/bonding.h
Original file line number Diff line number Diff line change
Expand Up @@ -411,6 +411,19 @@ static inline bool bond_slave_can_tx(struct slave *slave)
bond_is_active_slave(slave);
}

static inline bool bond_is_active_slave_dev(const struct net_device *slave_dev)
{
struct slave *slave;
bool active;

rcu_read_lock();
slave = bond_slave_get_rcu(slave_dev);
active = bond_is_active_slave(slave);
rcu_read_unlock();

return active;
}

static inline void bond_hw_addr_copy(u8 *dst, const u8 *src, unsigned int len)
{
if (len == ETH_ALEN) {
Expand Down
17 changes: 17 additions & 0 deletions include/net/lag.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/* SPDX-License-Identifier: GPL-2.0 */
#ifndef _LINUX_IF_LAG_H
#define _LINUX_IF_LAG_H

#include <linux/netdevice.h>
#include <linux/if_team.h>
#include <net/bonding.h>

static inline bool net_lag_port_dev_txable(const struct net_device *port_dev)
{
if (netif_is_team_port(port_dev))
return team_port_dev_txable(port_dev);
else
return bond_is_active_slave_dev(port_dev);
}

#endif /* _LINUX_IF_LAG_H */

0 comments on commit d90a521

Please sign in to comment.