Commit 33fa3823 authored by David Ahern's avatar David Ahern Committed by David S. Miller

vlan: Add extack messages for link create

Add informative messages for error paths related to adding a
VLAN to a device.
Signed-off-by: default avatarDavid Ahern <dsahern@gmail.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 8a863397
...@@ -118,17 +118,21 @@ void unregister_vlan_dev(struct net_device *dev, struct list_head *head) ...@@ -118,17 +118,21 @@ void unregister_vlan_dev(struct net_device *dev, struct list_head *head)
} }
int vlan_check_real_dev(struct net_device *real_dev, int vlan_check_real_dev(struct net_device *real_dev,
__be16 protocol, u16 vlan_id) __be16 protocol, u16 vlan_id,
struct netlink_ext_ack *extack)
{ {
const char *name = real_dev->name; const char *name = real_dev->name;
if (real_dev->features & NETIF_F_VLAN_CHALLENGED) { if (real_dev->features & NETIF_F_VLAN_CHALLENGED) {
pr_info("VLANs not supported on %s\n", name); pr_info("VLANs not supported on %s\n", name);
NL_SET_ERR_MSG_MOD(extack, "VLANs not supported on device");
return -EOPNOTSUPP; return -EOPNOTSUPP;
} }
if (vlan_find_dev(real_dev, protocol, vlan_id) != NULL) if (vlan_find_dev(real_dev, protocol, vlan_id) != NULL) {
NL_SET_ERR_MSG_MOD(extack, "VLAN device already exists");
return -EEXIST; return -EEXIST;
}
return 0; return 0;
} }
...@@ -215,7 +219,8 @@ static int register_vlan_device(struct net_device *real_dev, u16 vlan_id) ...@@ -215,7 +219,8 @@ static int register_vlan_device(struct net_device *real_dev, u16 vlan_id)
if (vlan_id >= VLAN_VID_MASK) if (vlan_id >= VLAN_VID_MASK)
return -ERANGE; return -ERANGE;
err = vlan_check_real_dev(real_dev, htons(ETH_P_8021Q), vlan_id); err = vlan_check_real_dev(real_dev, htons(ETH_P_8021Q), vlan_id,
NULL);
if (err < 0) if (err < 0)
return err; return err;
......
...@@ -109,7 +109,8 @@ int vlan_dev_change_flags(const struct net_device *dev, u32 flag, u32 mask); ...@@ -109,7 +109,8 @@ int vlan_dev_change_flags(const struct net_device *dev, u32 flag, u32 mask);
void vlan_dev_get_realdev_name(const struct net_device *dev, char *result); void vlan_dev_get_realdev_name(const struct net_device *dev, char *result);
int vlan_check_real_dev(struct net_device *real_dev, int vlan_check_real_dev(struct net_device *real_dev,
__be16 protocol, u16 vlan_id); __be16 protocol, u16 vlan_id,
struct netlink_ext_ack *extack);
void vlan_setup(struct net_device *dev); void vlan_setup(struct net_device *dev);
int register_vlan_dev(struct net_device *dev, struct netlink_ext_ack *extack); int register_vlan_dev(struct net_device *dev, struct netlink_ext_ack *extack);
void unregister_vlan_dev(struct net_device *dev, struct list_head *head); void unregister_vlan_dev(struct net_device *dev, struct list_head *head);
......
...@@ -47,14 +47,20 @@ static int vlan_validate(struct nlattr *tb[], struct nlattr *data[], ...@@ -47,14 +47,20 @@ static int vlan_validate(struct nlattr *tb[], struct nlattr *data[],
int err; int err;
if (tb[IFLA_ADDRESS]) { if (tb[IFLA_ADDRESS]) {
if (nla_len(tb[IFLA_ADDRESS]) != ETH_ALEN) if (nla_len(tb[IFLA_ADDRESS]) != ETH_ALEN) {
NL_SET_ERR_MSG_MOD(extack, "Invalid link address");
return -EINVAL; return -EINVAL;
if (!is_valid_ether_addr(nla_data(tb[IFLA_ADDRESS]))) }
if (!is_valid_ether_addr(nla_data(tb[IFLA_ADDRESS]))) {
NL_SET_ERR_MSG_MOD(extack, "Invalid link address");
return -EADDRNOTAVAIL; return -EADDRNOTAVAIL;
}
} }
if (!data) if (!data) {
NL_SET_ERR_MSG_MOD(extack, "VLAN properties not specified");
return -EINVAL; return -EINVAL;
}
if (data[IFLA_VLAN_PROTOCOL]) { if (data[IFLA_VLAN_PROTOCOL]) {
switch (nla_get_be16(data[IFLA_VLAN_PROTOCOL])) { switch (nla_get_be16(data[IFLA_VLAN_PROTOCOL])) {
...@@ -62,29 +68,38 @@ static int vlan_validate(struct nlattr *tb[], struct nlattr *data[], ...@@ -62,29 +68,38 @@ static int vlan_validate(struct nlattr *tb[], struct nlattr *data[],
case htons(ETH_P_8021AD): case htons(ETH_P_8021AD):
break; break;
default: default:
NL_SET_ERR_MSG_MOD(extack, "Invalid VLAN protocol");
return -EPROTONOSUPPORT; return -EPROTONOSUPPORT;
} }
} }
if (data[IFLA_VLAN_ID]) { if (data[IFLA_VLAN_ID]) {
id = nla_get_u16(data[IFLA_VLAN_ID]); id = nla_get_u16(data[IFLA_VLAN_ID]);
if (id >= VLAN_VID_MASK) if (id >= VLAN_VID_MASK) {
NL_SET_ERR_MSG_MOD(extack, "Invalid VLAN id");
return -ERANGE; return -ERANGE;
}
} }
if (data[IFLA_VLAN_FLAGS]) { if (data[IFLA_VLAN_FLAGS]) {
flags = nla_data(data[IFLA_VLAN_FLAGS]); flags = nla_data(data[IFLA_VLAN_FLAGS]);
if ((flags->flags & flags->mask) & if ((flags->flags & flags->mask) &
~(VLAN_FLAG_REORDER_HDR | VLAN_FLAG_GVRP | ~(VLAN_FLAG_REORDER_HDR | VLAN_FLAG_GVRP |
VLAN_FLAG_LOOSE_BINDING | VLAN_FLAG_MVRP)) VLAN_FLAG_LOOSE_BINDING | VLAN_FLAG_MVRP)) {
NL_SET_ERR_MSG_MOD(extack, "Invalid VLAN flags");
return -EINVAL; return -EINVAL;
}
} }
err = vlan_validate_qos_map(data[IFLA_VLAN_INGRESS_QOS]); err = vlan_validate_qos_map(data[IFLA_VLAN_INGRESS_QOS]);
if (err < 0) if (err < 0) {
NL_SET_ERR_MSG_MOD(extack, "Invalid ingress QOS map");
return err; return err;
}
err = vlan_validate_qos_map(data[IFLA_VLAN_EGRESS_QOS]); err = vlan_validate_qos_map(data[IFLA_VLAN_EGRESS_QOS]);
if (err < 0) if (err < 0) {
NL_SET_ERR_MSG_MOD(extack, "Invalid egress QOS map");
return err; return err;
}
return 0; return 0;
} }
...@@ -126,14 +141,21 @@ static int vlan_newlink(struct net *src_net, struct net_device *dev, ...@@ -126,14 +141,21 @@ static int vlan_newlink(struct net *src_net, struct net_device *dev,
__be16 proto; __be16 proto;
int err; int err;
if (!data[IFLA_VLAN_ID]) if (!data[IFLA_VLAN_ID]) {
NL_SET_ERR_MSG_MOD(extack, "VLAN id not specified");
return -EINVAL; return -EINVAL;
}
if (!tb[IFLA_LINK]) if (!tb[IFLA_LINK]) {
NL_SET_ERR_MSG_MOD(extack, "link not specified");
return -EINVAL; return -EINVAL;
}
real_dev = __dev_get_by_index(src_net, nla_get_u32(tb[IFLA_LINK])); real_dev = __dev_get_by_index(src_net, nla_get_u32(tb[IFLA_LINK]));
if (!real_dev) if (!real_dev) {
NL_SET_ERR_MSG_MOD(extack, "link does not exist");
return -ENODEV; return -ENODEV;
}
if (data[IFLA_VLAN_PROTOCOL]) if (data[IFLA_VLAN_PROTOCOL])
proto = nla_get_be16(data[IFLA_VLAN_PROTOCOL]); proto = nla_get_be16(data[IFLA_VLAN_PROTOCOL]);
...@@ -146,7 +168,8 @@ static int vlan_newlink(struct net *src_net, struct net_device *dev, ...@@ -146,7 +168,8 @@ static int vlan_newlink(struct net *src_net, struct net_device *dev,
dev->priv_flags |= (real_dev->priv_flags & IFF_XMIT_DST_RELEASE); dev->priv_flags |= (real_dev->priv_flags & IFF_XMIT_DST_RELEASE);
vlan->flags = VLAN_FLAG_REORDER_HDR; vlan->flags = VLAN_FLAG_REORDER_HDR;
err = vlan_check_real_dev(real_dev, vlan->vlan_proto, vlan->vlan_id); err = vlan_check_real_dev(real_dev, vlan->vlan_proto, vlan->vlan_id,
extack);
if (err < 0) if (err < 0)
return err; return err;
......
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