Skip to content

Commit

Permalink
hsr: use extack error message instead of netdev_info
Browse files Browse the repository at this point in the history
If HSR uses the extack instead of netdev_info(), users can get
error messages immediately without any checking the kernel message.

Signed-off-by: Taehee Yoo <ap420073@gmail.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
  • Loading branch information
Taehee Yoo authored and David S. Miller committed Mar 1, 2020
1 parent f3f2f98 commit 13eeb5f
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 21 deletions.
9 changes: 5 additions & 4 deletions net/hsr/hsr_device.c
Original file line number Diff line number Diff line change
Expand Up @@ -431,7 +431,8 @@ static const unsigned char def_multicast_addr[ETH_ALEN] __aligned(2) = {
};

int hsr_dev_finalize(struct net_device *hsr_dev, struct net_device *slave[2],
unsigned char multicast_spec, u8 protocol_version)
unsigned char multicast_spec, u8 protocol_version,
struct netlink_ext_ack *extack)
{
struct hsr_priv *hsr;
struct hsr_port *port;
Expand Down Expand Up @@ -478,19 +479,19 @@ int hsr_dev_finalize(struct net_device *hsr_dev, struct net_device *slave[2],
/* Make sure the 1st call to netif_carrier_on() gets through */
netif_carrier_off(hsr_dev);

res = hsr_add_port(hsr, hsr_dev, HSR_PT_MASTER);
res = hsr_add_port(hsr, hsr_dev, HSR_PT_MASTER, extack);
if (res)
goto err_add_master;

res = register_netdevice(hsr_dev);
if (res)
goto err_unregister;

res = hsr_add_port(hsr, slave[0], HSR_PT_SLAVE_A);
res = hsr_add_port(hsr, slave[0], HSR_PT_SLAVE_A, extack);
if (res)
goto err_add_slaves;

res = hsr_add_port(hsr, slave[1], HSR_PT_SLAVE_B);
res = hsr_add_port(hsr, slave[1], HSR_PT_SLAVE_B, extack);
if (res)
goto err_add_slaves;

Expand Down
3 changes: 2 additions & 1 deletion net/hsr/hsr_device.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@

void hsr_dev_setup(struct net_device *dev);
int hsr_dev_finalize(struct net_device *hsr_dev, struct net_device *slave[2],
unsigned char multicast_spec, u8 protocol_version);
unsigned char multicast_spec, u8 protocol_version,
struct netlink_ext_ack *extack);
void hsr_check_carrier_and_operstate(struct hsr_priv *hsr);
bool is_hsr_master(struct net_device *dev);
int hsr_get_max_mtu(struct hsr_priv *hsr);
Expand Down
22 changes: 15 additions & 7 deletions net/hsr/hsr_netlink.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,26 +35,34 @@ static int hsr_newlink(struct net *src_net, struct net_device *dev,
unsigned char multicast_spec, hsr_version;

if (!data) {
netdev_info(dev, "HSR: No slave devices specified\n");
NL_SET_ERR_MSG_MOD(extack, "No slave devices specified");
return -EINVAL;
}
if (!data[IFLA_HSR_SLAVE1]) {
netdev_info(dev, "HSR: Slave1 device not specified\n");
NL_SET_ERR_MSG_MOD(extack, "Slave1 device not specified");
return -EINVAL;
}
link[0] = __dev_get_by_index(src_net,
nla_get_u32(data[IFLA_HSR_SLAVE1]));
if (!link[0]) {
NL_SET_ERR_MSG_MOD(extack, "Slave1 does not exist");
return -EINVAL;
}
if (!data[IFLA_HSR_SLAVE2]) {
netdev_info(dev, "HSR: Slave2 device not specified\n");
NL_SET_ERR_MSG_MOD(extack, "Slave2 device not specified");
return -EINVAL;
}
link[1] = __dev_get_by_index(src_net,
nla_get_u32(data[IFLA_HSR_SLAVE2]));
if (!link[1]) {
NL_SET_ERR_MSG_MOD(extack, "Slave2 does not exist");
return -EINVAL;
}

if (!link[0] || !link[1])
return -ENODEV;
if (link[0] == link[1])
if (link[0] == link[1]) {
NL_SET_ERR_MSG_MOD(extack, "Slave1 and Slave2 are same");
return -EINVAL;
}

if (!data[IFLA_HSR_MULTICAST_SPEC])
multicast_spec = 0;
Expand All @@ -66,7 +74,7 @@ static int hsr_newlink(struct net *src_net, struct net_device *dev,
else
hsr_version = nla_get_u8(data[IFLA_HSR_VERSION]);

return hsr_dev_finalize(dev, link, multicast_spec, hsr_version);
return hsr_dev_finalize(dev, link, multicast_spec, hsr_version, extack);
}

static int hsr_fill_info(struct sk_buff *skb, const struct net_device *dev)
Expand Down
20 changes: 12 additions & 8 deletions net/hsr/hsr_slave.c
Original file line number Diff line number Diff line change
Expand Up @@ -58,33 +58,37 @@ bool hsr_port_exists(const struct net_device *dev)
return rcu_access_pointer(dev->rx_handler) == hsr_handle_frame;
}

static int hsr_check_dev_ok(struct net_device *dev)
static int hsr_check_dev_ok(struct net_device *dev,
struct netlink_ext_ack *extack)
{
/* Don't allow HSR on non-ethernet like devices */
if ((dev->flags & IFF_LOOPBACK) || dev->type != ARPHRD_ETHER ||
dev->addr_len != ETH_ALEN) {
netdev_info(dev, "Cannot use loopback or non-ethernet device as HSR slave.\n");
NL_SET_ERR_MSG_MOD(extack, "Cannot use loopback or non-ethernet device as HSR slave.");
return -EINVAL;
}

/* Don't allow enslaving hsr devices */
if (is_hsr_master(dev)) {
netdev_info(dev, "Cannot create trees of HSR devices.\n");
NL_SET_ERR_MSG_MOD(extack,
"Cannot create trees of HSR devices.");
return -EINVAL;
}

if (hsr_port_exists(dev)) {
netdev_info(dev, "This device is already a HSR slave.\n");
NL_SET_ERR_MSG_MOD(extack,
"This device is already a HSR slave.");
return -EINVAL;
}

if (is_vlan_dev(dev)) {
netdev_info(dev, "HSR on top of VLAN is not yet supported in this driver.\n");
NL_SET_ERR_MSG_MOD(extack, "HSR on top of VLAN is not yet supported in this driver.");
return -EINVAL;
}

if (dev->priv_flags & IFF_DONT_BRIDGE) {
netdev_info(dev, "This device does not support bridging.\n");
NL_SET_ERR_MSG_MOD(extack,
"This device does not support bridging.");
return -EOPNOTSUPP;
}

Expand Down Expand Up @@ -126,13 +130,13 @@ static int hsr_portdev_setup(struct net_device *dev, struct hsr_port *port)
}

int hsr_add_port(struct hsr_priv *hsr, struct net_device *dev,
enum hsr_port_type type)
enum hsr_port_type type, struct netlink_ext_ack *extack)
{
struct hsr_port *port, *master;
int res;

if (type != HSR_PT_MASTER) {
res = hsr_check_dev_ok(dev);
res = hsr_check_dev_ok(dev, extack);
if (res)
return res;
}
Expand Down
2 changes: 1 addition & 1 deletion net/hsr/hsr_slave.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
#include "hsr_main.h"

int hsr_add_port(struct hsr_priv *hsr, struct net_device *dev,
enum hsr_port_type pt);
enum hsr_port_type pt, struct netlink_ext_ack *extack);
void hsr_del_port(struct hsr_port *port);
bool hsr_port_exists(const struct net_device *dev);

Expand Down

0 comments on commit 13eeb5f

Please sign in to comment.