Skip to content

Commit 33fa382

Browse files
dsaherndavem330
authored andcommitted
vlan: Add extack messages for link create
Add informative messages for error paths related to adding a VLAN to a device. Signed-off-by: David Ahern <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 8a86339 commit 33fa382

File tree

3 files changed

+44
-15
lines changed

3 files changed

+44
-15
lines changed

net/8021q/vlan.c

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -118,17 +118,21 @@ void unregister_vlan_dev(struct net_device *dev, struct list_head *head)
118118
}
119119

120120
int vlan_check_real_dev(struct net_device *real_dev,
121-
__be16 protocol, u16 vlan_id)
121+
__be16 protocol, u16 vlan_id,
122+
struct netlink_ext_ack *extack)
122123
{
123124
const char *name = real_dev->name;
124125

125126
if (real_dev->features & NETIF_F_VLAN_CHALLENGED) {
126127
pr_info("VLANs not supported on %s\n", name);
128+
NL_SET_ERR_MSG_MOD(extack, "VLANs not supported on device");
127129
return -EOPNOTSUPP;
128130
}
129131

130-
if (vlan_find_dev(real_dev, protocol, vlan_id) != NULL)
132+
if (vlan_find_dev(real_dev, protocol, vlan_id) != NULL) {
133+
NL_SET_ERR_MSG_MOD(extack, "VLAN device already exists");
131134
return -EEXIST;
135+
}
132136

133137
return 0;
134138
}
@@ -215,7 +219,8 @@ static int register_vlan_device(struct net_device *real_dev, u16 vlan_id)
215219
if (vlan_id >= VLAN_VID_MASK)
216220
return -ERANGE;
217221

218-
err = vlan_check_real_dev(real_dev, htons(ETH_P_8021Q), vlan_id);
222+
err = vlan_check_real_dev(real_dev, htons(ETH_P_8021Q), vlan_id,
223+
NULL);
219224
if (err < 0)
220225
return err;
221226

net/8021q/vlan.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,8 @@ int vlan_dev_change_flags(const struct net_device *dev, u32 flag, u32 mask);
109109
void vlan_dev_get_realdev_name(const struct net_device *dev, char *result);
110110

111111
int vlan_check_real_dev(struct net_device *real_dev,
112-
__be16 protocol, u16 vlan_id);
112+
__be16 protocol, u16 vlan_id,
113+
struct netlink_ext_ack *extack);
113114
void vlan_setup(struct net_device *dev);
114115
int register_vlan_dev(struct net_device *dev, struct netlink_ext_ack *extack);
115116
void unregister_vlan_dev(struct net_device *dev, struct list_head *head);

net/8021q/vlan_netlink.c

Lines changed: 34 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -47,44 +47,59 @@ static int vlan_validate(struct nlattr *tb[], struct nlattr *data[],
4747
int err;
4848

4949
if (tb[IFLA_ADDRESS]) {
50-
if (nla_len(tb[IFLA_ADDRESS]) != ETH_ALEN)
50+
if (nla_len(tb[IFLA_ADDRESS]) != ETH_ALEN) {
51+
NL_SET_ERR_MSG_MOD(extack, "Invalid link address");
5152
return -EINVAL;
52-
if (!is_valid_ether_addr(nla_data(tb[IFLA_ADDRESS])))
53+
}
54+
if (!is_valid_ether_addr(nla_data(tb[IFLA_ADDRESS]))) {
55+
NL_SET_ERR_MSG_MOD(extack, "Invalid link address");
5356
return -EADDRNOTAVAIL;
57+
}
5458
}
5559

56-
if (!data)
60+
if (!data) {
61+
NL_SET_ERR_MSG_MOD(extack, "VLAN properties not specified");
5762
return -EINVAL;
63+
}
5864

5965
if (data[IFLA_VLAN_PROTOCOL]) {
6066
switch (nla_get_be16(data[IFLA_VLAN_PROTOCOL])) {
6167
case htons(ETH_P_8021Q):
6268
case htons(ETH_P_8021AD):
6369
break;
6470
default:
71+
NL_SET_ERR_MSG_MOD(extack, "Invalid VLAN protocol");
6572
return -EPROTONOSUPPORT;
6673
}
6774
}
6875

6976
if (data[IFLA_VLAN_ID]) {
7077
id = nla_get_u16(data[IFLA_VLAN_ID]);
71-
if (id >= VLAN_VID_MASK)
78+
if (id >= VLAN_VID_MASK) {
79+
NL_SET_ERR_MSG_MOD(extack, "Invalid VLAN id");
7280
return -ERANGE;
81+
}
7382
}
7483
if (data[IFLA_VLAN_FLAGS]) {
7584
flags = nla_data(data[IFLA_VLAN_FLAGS]);
7685
if ((flags->flags & flags->mask) &
7786
~(VLAN_FLAG_REORDER_HDR | VLAN_FLAG_GVRP |
78-
VLAN_FLAG_LOOSE_BINDING | VLAN_FLAG_MVRP))
87+
VLAN_FLAG_LOOSE_BINDING | VLAN_FLAG_MVRP)) {
88+
NL_SET_ERR_MSG_MOD(extack, "Invalid VLAN flags");
7989
return -EINVAL;
90+
}
8091
}
8192

8293
err = vlan_validate_qos_map(data[IFLA_VLAN_INGRESS_QOS]);
83-
if (err < 0)
94+
if (err < 0) {
95+
NL_SET_ERR_MSG_MOD(extack, "Invalid ingress QOS map");
8496
return err;
97+
}
8598
err = vlan_validate_qos_map(data[IFLA_VLAN_EGRESS_QOS]);
86-
if (err < 0)
99+
if (err < 0) {
100+
NL_SET_ERR_MSG_MOD(extack, "Invalid egress QOS map");
87101
return err;
102+
}
88103
return 0;
89104
}
90105

@@ -126,14 +141,21 @@ static int vlan_newlink(struct net *src_net, struct net_device *dev,
126141
__be16 proto;
127142
int err;
128143

129-
if (!data[IFLA_VLAN_ID])
144+
if (!data[IFLA_VLAN_ID]) {
145+
NL_SET_ERR_MSG_MOD(extack, "VLAN id not specified");
130146
return -EINVAL;
147+
}
131148

132-
if (!tb[IFLA_LINK])
149+
if (!tb[IFLA_LINK]) {
150+
NL_SET_ERR_MSG_MOD(extack, "link not specified");
133151
return -EINVAL;
152+
}
153+
134154
real_dev = __dev_get_by_index(src_net, nla_get_u32(tb[IFLA_LINK]));
135-
if (!real_dev)
155+
if (!real_dev) {
156+
NL_SET_ERR_MSG_MOD(extack, "link does not exist");
136157
return -ENODEV;
158+
}
137159

138160
if (data[IFLA_VLAN_PROTOCOL])
139161
proto = nla_get_be16(data[IFLA_VLAN_PROTOCOL]);
@@ -146,7 +168,8 @@ static int vlan_newlink(struct net *src_net, struct net_device *dev,
146168
dev->priv_flags |= (real_dev->priv_flags & IFF_XMIT_DST_RELEASE);
147169
vlan->flags = VLAN_FLAG_REORDER_HDR;
148170

149-
err = vlan_check_real_dev(real_dev, vlan->vlan_proto, vlan->vlan_id);
171+
err = vlan_check_real_dev(real_dev, vlan->vlan_proto, vlan->vlan_id,
172+
extack);
150173
if (err < 0)
151174
return err;
152175

0 commit comments

Comments
 (0)