From: Nikolay Aleksandrov <nikolay@cumulusnetworks.com>
To: netdev@vger.kernel.org
Cc: roopa@cumulusnetworks.com, davem@davemloft.net, kuba@kernel.org,
bridge@lists.linux-foundation.org, dsahern@gmail.com,
Nikolay Aleksandrov <nikolay@cumulusnetworks.com>
Subject: [PATCH net-next v2 2/8] net: bridge: netlink: add extack error messages when processing vlans
Date: Tue, 14 Jan 2020 19:56:08 +0200 [thread overview]
Message-ID: <20200114175614.17543-3-nikolay@cumulusnetworks.com> (raw)
In-Reply-To: <20200114175614.17543-1-nikolay@cumulusnetworks.com>
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>
---
net/bridge/br_netlink.c | 6 +++---
net/bridge/br_private.h | 38 +++++++++++++++++++++++++++-----------
2 files changed, 30 insertions(+), 14 deletions(-)
diff --git a/net/bridge/br_netlink.c b/net/bridge/br_netlink.c
index 14100e8653e6..40942cece51a 100644
--- a/net/bridge/br_netlink.c
+++ b/net/bridge/br_netlink.c
@@ -568,11 +568,11 @@ static int br_process_vlan_info(struct net_bridge *br,
bool *changed,
struct netlink_ext_ack *extack)
{
- if (!br_vlan_valid_id(vinfo_curr->vid))
+ if (!br_vlan_valid_id(vinfo_curr->vid, extack))
return -EINVAL;
if (vinfo_curr->flags & BRIDGE_VLAN_INFO_RANGE_BEGIN) {
- if (!br_vlan_valid_range(vinfo_curr, *vinfo_last))
+ if (!br_vlan_valid_range(vinfo_curr, *vinfo_last, extack))
return -EINVAL;
*vinfo_last = vinfo_curr;
return 0;
@@ -582,7 +582,7 @@ static int br_process_vlan_info(struct net_bridge *br,
struct bridge_vlan_info tmp_vinfo;
int v, err;
- if (!br_vlan_valid_range(vinfo_curr, *vinfo_last))
+ if (!br_vlan_valid_range(vinfo_curr, *vinfo_last, extack))
return -EINVAL;
memcpy(&tmp_vinfo, *vinfo_last,
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;
--
2.21.0
next prev parent reply other threads:[~2020-01-14 17:58 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-01-14 17:56 [PATCH net-next v2 0/8] net: bridge: add vlan notifications and rtm support Nikolay Aleksandrov
2020-01-14 17:56 ` [PATCH net-next v2 1/8] net: bridge: vlan: add helpers to check for vlan id/range validity Nikolay Aleksandrov
2020-01-14 17:56 ` Nikolay Aleksandrov [this message]
2020-01-14 17:56 ` [PATCH net-next v2 3/8] net: bridge: vlan: add rtm definitions and dump support Nikolay Aleksandrov
2020-01-14 17:56 ` [PATCH net-next v2 4/8] net: bridge: vlan: add new rtm message support Nikolay Aleksandrov
2020-01-14 17:56 ` [PATCH net-next v2 5/8] net: bridge: vlan: add del " Nikolay Aleksandrov
2020-01-14 17:56 ` [PATCH net-next v2 6/8] net: bridge: vlan: add rtm range support Nikolay Aleksandrov
2020-01-14 17:56 ` [PATCH net-next v2 7/8] net: bridge: vlan: add rtnetlink group and notify support Nikolay Aleksandrov
2020-01-14 17:56 ` [PATCH net-next v2 8/8] net: bridge: vlan: notify on vlan add/delete/change flags Nikolay Aleksandrov
2020-01-15 12:51 ` [PATCH net-next v2 0/8] net: bridge: add vlan notifications and rtm support David Miller
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20200114175614.17543-3-nikolay@cumulusnetworks.com \
--to=nikolay@cumulusnetworks.com \
--cc=bridge@lists.linux-foundation.org \
--cc=davem@davemloft.net \
--cc=dsahern@gmail.com \
--cc=kuba@kernel.org \
--cc=netdev@vger.kernel.org \
--cc=roopa@cumulusnetworks.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).