team: add support for non-ethernet devices
This is resolved by two things: 1) allow dev_addr of different length than ETH_ALEN 2) during port add, check for dev->type and change it if necessary Signed-off-by: Jiri Pirko <jiri@resnulli.us> Signed-off-by: David S. Miller <davem@davemloft.net>
This commit is contained in:
parent
4c6de2fedc
commit
1d76efe157
|
@ -21,7 +21,7 @@ config NET_TEAM_MODE_BROADCAST
|
||||||
---help---
|
---help---
|
||||||
Basic mode where packets are transmitted always by all suitable ports.
|
Basic mode where packets are transmitted always by all suitable ports.
|
||||||
|
|
||||||
All added ports are setup to have team's mac address.
|
All added ports are setup to have team's device address.
|
||||||
|
|
||||||
To compile this team mode as a module, choose M here: the module
|
To compile this team mode as a module, choose M here: the module
|
||||||
will be called team_mode_broadcast.
|
will be called team_mode_broadcast.
|
||||||
|
@ -33,7 +33,7 @@ config NET_TEAM_MODE_ROUNDROBIN
|
||||||
Basic mode where port used for transmitting packets is selected in
|
Basic mode where port used for transmitting packets is selected in
|
||||||
round-robin fashion using packet counter.
|
round-robin fashion using packet counter.
|
||||||
|
|
||||||
All added ports are setup to have team's mac address.
|
All added ports are setup to have team's device address.
|
||||||
|
|
||||||
To compile this team mode as a module, choose M here: the module
|
To compile this team mode as a module, choose M here: the module
|
||||||
will be called team_mode_roundrobin.
|
will be called team_mode_roundrobin.
|
||||||
|
|
|
@ -54,29 +54,29 @@ static struct team_port *team_port_get_rtnl(const struct net_device *dev)
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Since the ability to change mac address for open port device is tested in
|
* Since the ability to change device address for open port device is tested in
|
||||||
* team_port_add, this function can be called without control of return value
|
* team_port_add, this function can be called without control of return value
|
||||||
*/
|
*/
|
||||||
static int __set_port_mac(struct net_device *port_dev,
|
static int __set_port_dev_addr(struct net_device *port_dev,
|
||||||
const unsigned char *dev_addr)
|
const unsigned char *dev_addr)
|
||||||
{
|
{
|
||||||
struct sockaddr addr;
|
struct sockaddr addr;
|
||||||
|
|
||||||
memcpy(addr.sa_data, dev_addr, ETH_ALEN);
|
memcpy(addr.sa_data, dev_addr, port_dev->addr_len);
|
||||||
addr.sa_family = ARPHRD_ETHER;
|
addr.sa_family = port_dev->type;
|
||||||
return dev_set_mac_address(port_dev, &addr);
|
return dev_set_mac_address(port_dev, &addr);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int team_port_set_orig_mac(struct team_port *port)
|
static int team_port_set_orig_dev_addr(struct team_port *port)
|
||||||
{
|
{
|
||||||
return __set_port_mac(port->dev, port->orig.dev_addr);
|
return __set_port_dev_addr(port->dev, port->orig.dev_addr);
|
||||||
}
|
}
|
||||||
|
|
||||||
int team_port_set_team_mac(struct team_port *port)
|
int team_port_set_team_dev_addr(struct team_port *port)
|
||||||
{
|
{
|
||||||
return __set_port_mac(port->dev, port->team->dev->dev_addr);
|
return __set_port_dev_addr(port->dev, port->team->dev->dev_addr);
|
||||||
}
|
}
|
||||||
EXPORT_SYMBOL(team_port_set_team_mac);
|
EXPORT_SYMBOL(team_port_set_team_dev_addr);
|
||||||
|
|
||||||
static void team_refresh_port_linkup(struct team_port *port)
|
static void team_refresh_port_linkup(struct team_port *port)
|
||||||
{
|
{
|
||||||
|
@ -965,6 +965,8 @@ static struct netpoll_info *team_netpoll_info(struct team *team)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
static void __team_port_change_check(struct team_port *port, bool linkup);
|
static void __team_port_change_check(struct team_port *port, bool linkup);
|
||||||
|
static int team_dev_type_check_change(struct net_device *dev,
|
||||||
|
struct net_device *port_dev);
|
||||||
|
|
||||||
static int team_port_add(struct team *team, struct net_device *port_dev)
|
static int team_port_add(struct team *team, struct net_device *port_dev)
|
||||||
{
|
{
|
||||||
|
@ -973,9 +975,8 @@ static int team_port_add(struct team *team, struct net_device *port_dev)
|
||||||
char *portname = port_dev->name;
|
char *portname = port_dev->name;
|
||||||
int err;
|
int err;
|
||||||
|
|
||||||
if (port_dev->flags & IFF_LOOPBACK ||
|
if (port_dev->flags & IFF_LOOPBACK) {
|
||||||
port_dev->type != ARPHRD_ETHER) {
|
netdev_err(dev, "Device %s is loopback device. Loopback devices can't be added as a team port\n",
|
||||||
netdev_err(dev, "Device %s is of an unsupported type\n",
|
|
||||||
portname);
|
portname);
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
}
|
}
|
||||||
|
@ -986,6 +987,10 @@ static int team_port_add(struct team *team, struct net_device *port_dev)
|
||||||
return -EBUSY;
|
return -EBUSY;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
err = team_dev_type_check_change(dev, port_dev);
|
||||||
|
if (err)
|
||||||
|
return err;
|
||||||
|
|
||||||
if (port_dev->flags & IFF_UP) {
|
if (port_dev->flags & IFF_UP) {
|
||||||
netdev_err(dev, "Device %s is up. Set it down before adding it as a team port\n",
|
netdev_err(dev, "Device %s is up. Set it down before adding it as a team port\n",
|
||||||
portname);
|
portname);
|
||||||
|
@ -1008,7 +1013,7 @@ static int team_port_add(struct team *team, struct net_device *port_dev)
|
||||||
goto err_set_mtu;
|
goto err_set_mtu;
|
||||||
}
|
}
|
||||||
|
|
||||||
memcpy(port->orig.dev_addr, port_dev->dev_addr, ETH_ALEN);
|
memcpy(port->orig.dev_addr, port_dev->dev_addr, port_dev->addr_len);
|
||||||
|
|
||||||
err = team_port_enter(team, port);
|
err = team_port_enter(team, port);
|
||||||
if (err) {
|
if (err) {
|
||||||
|
@ -1089,7 +1094,7 @@ err_vids_add:
|
||||||
|
|
||||||
err_dev_open:
|
err_dev_open:
|
||||||
team_port_leave(team, port);
|
team_port_leave(team, port);
|
||||||
team_port_set_orig_mac(port);
|
team_port_set_orig_dev_addr(port);
|
||||||
|
|
||||||
err_port_enter:
|
err_port_enter:
|
||||||
dev_set_mtu(port_dev, port->orig.mtu);
|
dev_set_mtu(port_dev, port->orig.mtu);
|
||||||
|
@ -1126,7 +1131,7 @@ static int team_port_del(struct team *team, struct net_device *port_dev)
|
||||||
vlan_vids_del_by_dev(port_dev, dev);
|
vlan_vids_del_by_dev(port_dev, dev);
|
||||||
dev_close(port_dev);
|
dev_close(port_dev);
|
||||||
team_port_leave(team, port);
|
team_port_leave(team, port);
|
||||||
team_port_set_orig_mac(port);
|
team_port_set_orig_dev_addr(port);
|
||||||
dev_set_mtu(port_dev, port->orig.mtu);
|
dev_set_mtu(port_dev, port->orig.mtu);
|
||||||
synchronize_rcu();
|
synchronize_rcu();
|
||||||
kfree(port);
|
kfree(port);
|
||||||
|
@ -1477,17 +1482,18 @@ static void team_set_rx_mode(struct net_device *dev)
|
||||||
|
|
||||||
static int team_set_mac_address(struct net_device *dev, void *p)
|
static int team_set_mac_address(struct net_device *dev, void *p)
|
||||||
{
|
{
|
||||||
|
struct sockaddr *addr = p;
|
||||||
struct team *team = netdev_priv(dev);
|
struct team *team = netdev_priv(dev);
|
||||||
struct team_port *port;
|
struct team_port *port;
|
||||||
int err;
|
|
||||||
|
|
||||||
err = eth_mac_addr(dev, p);
|
if (dev->type == ARPHRD_ETHER && !is_valid_ether_addr(addr->sa_data))
|
||||||
if (err)
|
return -EADDRNOTAVAIL;
|
||||||
return err;
|
memcpy(dev->dev_addr, addr->sa_data, dev->addr_len);
|
||||||
|
dev->addr_assign_type &= ~NET_ADDR_RANDOM;
|
||||||
rcu_read_lock();
|
rcu_read_lock();
|
||||||
list_for_each_entry_rcu(port, &team->port_list, list)
|
list_for_each_entry_rcu(port, &team->port_list, list)
|
||||||
if (team->ops.port_change_mac)
|
if (team->ops.port_change_dev_addr)
|
||||||
team->ops.port_change_mac(team, port);
|
team->ops.port_change_dev_addr(team, port);
|
||||||
rcu_read_unlock();
|
rcu_read_unlock();
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -1718,6 +1724,45 @@ static const struct net_device_ops team_netdev_ops = {
|
||||||
* rt netlink interface
|
* rt netlink interface
|
||||||
***********************/
|
***********************/
|
||||||
|
|
||||||
|
static void team_setup_by_port(struct net_device *dev,
|
||||||
|
struct net_device *port_dev)
|
||||||
|
{
|
||||||
|
dev->header_ops = port_dev->header_ops;
|
||||||
|
dev->type = port_dev->type;
|
||||||
|
dev->hard_header_len = port_dev->hard_header_len;
|
||||||
|
dev->addr_len = port_dev->addr_len;
|
||||||
|
dev->mtu = port_dev->mtu;
|
||||||
|
memcpy(dev->broadcast, port_dev->broadcast, port_dev->addr_len);
|
||||||
|
memcpy(dev->dev_addr, port_dev->dev_addr, port_dev->addr_len);
|
||||||
|
dev->addr_assign_type &= ~NET_ADDR_RANDOM;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int team_dev_type_check_change(struct net_device *dev,
|
||||||
|
struct net_device *port_dev)
|
||||||
|
{
|
||||||
|
struct team *team = netdev_priv(dev);
|
||||||
|
char *portname = port_dev->name;
|
||||||
|
int err;
|
||||||
|
|
||||||
|
if (dev->type == port_dev->type)
|
||||||
|
return 0;
|
||||||
|
if (!list_empty(&team->port_list)) {
|
||||||
|
netdev_err(dev, "Device %s is of different type\n", portname);
|
||||||
|
return -EBUSY;
|
||||||
|
}
|
||||||
|
err = call_netdevice_notifiers(NETDEV_PRE_TYPE_CHANGE, dev);
|
||||||
|
err = notifier_to_errno(err);
|
||||||
|
if (err) {
|
||||||
|
netdev_err(dev, "Refused to change device type\n");
|
||||||
|
return err;
|
||||||
|
}
|
||||||
|
dev_uc_flush(dev);
|
||||||
|
dev_mc_flush(dev);
|
||||||
|
team_setup_by_port(dev, port_dev);
|
||||||
|
call_netdevice_notifiers(NETDEV_POST_TYPE_CHANGE, dev);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
static void team_setup(struct net_device *dev)
|
static void team_setup(struct net_device *dev)
|
||||||
{
|
{
|
||||||
ether_setup(dev);
|
ether_setup(dev);
|
||||||
|
|
|
@ -48,18 +48,18 @@ static bool bc_transmit(struct team *team, struct sk_buff *skb)
|
||||||
|
|
||||||
static int bc_port_enter(struct team *team, struct team_port *port)
|
static int bc_port_enter(struct team *team, struct team_port *port)
|
||||||
{
|
{
|
||||||
return team_port_set_team_mac(port);
|
return team_port_set_team_dev_addr(port);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void bc_port_change_mac(struct team *team, struct team_port *port)
|
static void bc_port_change_dev_addr(struct team *team, struct team_port *port)
|
||||||
{
|
{
|
||||||
team_port_set_team_mac(port);
|
team_port_set_team_dev_addr(port);
|
||||||
}
|
}
|
||||||
|
|
||||||
static const struct team_mode_ops bc_mode_ops = {
|
static const struct team_mode_ops bc_mode_ops = {
|
||||||
.transmit = bc_transmit,
|
.transmit = bc_transmit,
|
||||||
.port_enter = bc_port_enter,
|
.port_enter = bc_port_enter,
|
||||||
.port_change_mac = bc_port_change_mac,
|
.port_change_dev_addr = bc_port_change_dev_addr,
|
||||||
};
|
};
|
||||||
|
|
||||||
static const struct team_mode bc_mode = {
|
static const struct team_mode bc_mode = {
|
||||||
|
|
|
@ -66,18 +66,18 @@ drop:
|
||||||
|
|
||||||
static int rr_port_enter(struct team *team, struct team_port *port)
|
static int rr_port_enter(struct team *team, struct team_port *port)
|
||||||
{
|
{
|
||||||
return team_port_set_team_mac(port);
|
return team_port_set_team_dev_addr(port);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void rr_port_change_mac(struct team *team, struct team_port *port)
|
static void rr_port_change_dev_addr(struct team *team, struct team_port *port)
|
||||||
{
|
{
|
||||||
team_port_set_team_mac(port);
|
team_port_set_team_dev_addr(port);
|
||||||
}
|
}
|
||||||
|
|
||||||
static const struct team_mode_ops rr_mode_ops = {
|
static const struct team_mode_ops rr_mode_ops = {
|
||||||
.transmit = rr_transmit,
|
.transmit = rr_transmit,
|
||||||
.port_enter = rr_port_enter,
|
.port_enter = rr_port_enter,
|
||||||
.port_change_mac = rr_port_change_mac,
|
.port_change_dev_addr = rr_port_change_dev_addr,
|
||||||
};
|
};
|
||||||
|
|
||||||
static const struct team_mode rr_mode = {
|
static const struct team_mode rr_mode = {
|
||||||
|
|
|
@ -123,7 +123,7 @@ struct team_mode_ops {
|
||||||
bool (*transmit)(struct team *team, struct sk_buff *skb);
|
bool (*transmit)(struct team *team, struct sk_buff *skb);
|
||||||
int (*port_enter)(struct team *team, struct team_port *port);
|
int (*port_enter)(struct team *team, struct team_port *port);
|
||||||
void (*port_leave)(struct team *team, struct team_port *port);
|
void (*port_leave)(struct team *team, struct team_port *port);
|
||||||
void (*port_change_mac)(struct team *team, struct team_port *port);
|
void (*port_change_dev_addr)(struct team *team, struct team_port *port);
|
||||||
void (*port_enabled)(struct team *team, struct team_port *port);
|
void (*port_enabled)(struct team *team, struct team_port *port);
|
||||||
void (*port_disabled)(struct team *team, struct team_port *port);
|
void (*port_disabled)(struct team *team, struct team_port *port);
|
||||||
};
|
};
|
||||||
|
@ -238,7 +238,7 @@ static inline struct team_port *team_get_port_by_index_rcu(struct team *team,
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
extern int team_port_set_team_mac(struct team_port *port);
|
extern int team_port_set_team_dev_addr(struct team_port *port);
|
||||||
extern int team_options_register(struct team *team,
|
extern int team_options_register(struct team *team,
|
||||||
const struct team_option *option,
|
const struct team_option *option,
|
||||||
size_t option_count);
|
size_t option_count);
|
||||||
|
|
Loading…
Reference in New Issue