aboutsummaryrefslogtreecommitdiffstats
path: root/net/bridge/br_private.h
diff options
context:
space:
mode:
authorNikolay Aleksandrov <nikolay@cumulusnetworks.com>2020-01-14 19:56:08 +0200
committerDavid S. Miller <davem@davemloft.net>2020-01-15 13:48:17 +0100
commit8f4cc940a149b9fe013a191d6d8dc87aee9a204f (patch)
tree0ddeb28db98f900befe91e0d56de5eb6b98f2274 /net/bridge/br_private.h
parentnet: bridge: vlan: add helpers to check for vlan id/range validity (diff)
downloadlinux-dev-8f4cc940a149b9fe013a191d6d8dc87aee9a204f.tar.xz
linux-dev-8f4cc940a149b9fe013a191d6d8dc87aee9a204f.zip
net: bridge: netlink: add extack error messages when processing vlans
Add extack messages on vlan processing errors. We need to move the flags missing check after the "last" check since we may have "last" set but lack a range end flag in the next entry. Signed-off-by: Nikolay Aleksandrov <nikolay@cumulusnetworks.com> Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'net/bridge/br_private.h')
-rw-r--r--net/bridge/br_private.h38
1 files changed, 27 insertions, 11 deletions
diff --git a/net/bridge/br_private.h b/net/bridge/br_private.h
index dbc0089e2c1a..a7dddc5d7790 100644
--- a/net/bridge/br_private.h
+++ b/net/bridge/br_private.h
@@ -507,32 +507,48 @@ static inline bool nbp_state_should_learn(const struct net_bridge_port *p)
return p->state == BR_STATE_LEARNING || p->state == BR_STATE_FORWARDING;
}
-static inline bool br_vlan_valid_id(u16 vid)
+static inline bool br_vlan_valid_id(u16 vid, struct netlink_ext_ack *extack)
{
- return vid > 0 && vid < VLAN_VID_MASK;
+ bool ret = vid > 0 && vid < VLAN_VID_MASK;
+
+ if (!ret)
+ NL_SET_ERR_MSG_MOD(extack, "Vlan id is invalid");
+
+ return ret;
}
static inline bool br_vlan_valid_range(const struct bridge_vlan_info *cur,
- const struct bridge_vlan_info *last)
+ const struct bridge_vlan_info *last,
+ struct netlink_ext_ack *extack)
{
/* pvid flag is not allowed in ranges */
- if (cur->flags & BRIDGE_VLAN_INFO_PVID)
- return false;
-
- /* check for required range flags */
- if (!(cur->flags & (BRIDGE_VLAN_INFO_RANGE_BEGIN |
- BRIDGE_VLAN_INFO_RANGE_END)))
+ if (cur->flags & BRIDGE_VLAN_INFO_PVID) {
+ NL_SET_ERR_MSG_MOD(extack, "Pvid isn't allowed in a range");
return false;
+ }
/* when cur is the range end, check if:
* - it has range start flag
* - range ids are invalid (end is equal to or before start)
*/
if (last) {
- if (cur->flags & BRIDGE_VLAN_INFO_RANGE_BEGIN)
+ if (cur->flags & BRIDGE_VLAN_INFO_RANGE_BEGIN) {
+ NL_SET_ERR_MSG_MOD(extack, "Found a new vlan range start while processing one");
return false;
- else if (cur->vid <= last->vid)
+ } else if (!(cur->flags & BRIDGE_VLAN_INFO_RANGE_END)) {
+ NL_SET_ERR_MSG_MOD(extack, "Vlan range end flag is missing");
return false;
+ } else if (cur->vid <= last->vid) {
+ NL_SET_ERR_MSG_MOD(extack, "End vlan id is less than or equal to start vlan id");
+ return false;
+ }
+ }
+
+ /* check for required range flags */
+ if (!(cur->flags & (BRIDGE_VLAN_INFO_RANGE_BEGIN |
+ BRIDGE_VLAN_INFO_RANGE_END))) {
+ NL_SET_ERR_MSG_MOD(extack, "Both vlan range flags are missing");
+ return false;
}
return true;