Netdev Archive on lore.kernel.org
help / color / mirror / Atom feed
From: zhudi <zhudi21@huawei.com>
To: <j.vosburgh@gmail.com>, <vfalico@gmail.com>, <kuba@kernel.org>,
	<davem@davemloft.net>
Cc: <netdev@vger.kernel.org>, <zhudi21@huawei.com>, <rose.chen@huawei.com>
Subject: [PATCH] bonding: Avoid adding slave devices to inactive bonding
Date: Wed, 28 Jul 2021 11:35:05 +0800	[thread overview]
Message-ID: <20210728033505.1627-1-zhudi21@huawei.com> (raw)

We need to refuse to add slave devices to the bonding which does
not set IFF_UP flag, otherwise some problems will be caused(such as
bond_set_carrier() will not sync carrier state to upper net device).
The ifenslave command can prevent such use case, but through the sysfs
interface, slave devices can still be added regardless of whether
the bonding is set with IFF_UP flag or not.

So we introduce a new BOND_OPTFLAG_IFUP flag to avoid adding slave
devices to inactive bonding.

Signed-off-by: zhudi <zhudi21@huawei.com>
---
 drivers/net/bonding/bond_options.c | 4 +++-
 include/net/bond_options.h         | 4 +++-
 2 files changed, 6 insertions(+), 2 deletions(-)

diff --git a/drivers/net/bonding/bond_options.c b/drivers/net/bonding/bond_options.c
index 0cf25de6f46d..6d2f44b3528d 100644
--- a/drivers/net/bonding/bond_options.c
+++ b/drivers/net/bonding/bond_options.c
@@ -387,7 +387,7 @@ static const struct bond_option bond_opts[BOND_OPT_LAST] = {
 		.id = BOND_OPT_SLAVES,
 		.name = "slaves",
 		.desc = "Slave membership management",
-		.flags = BOND_OPTFLAG_RAWVAL,
+		.flags = BOND_OPTFLAG_RAWVAL | BOND_OPTFLAG_IFUP,
 		.set = bond_option_slaves_set
 	},
 	[BOND_OPT_TLB_DYNAMIC_LB] = {
@@ -583,6 +583,8 @@ static int bond_opt_check_deps(struct bonding *bond,
 		return -ENOTEMPTY;
 	if ((opt->flags & BOND_OPTFLAG_IFDOWN) && (bond->dev->flags & IFF_UP))
 		return -EBUSY;
+	if ((opt->flags & BOND_OPTFLAG_IFUP) && !(bond->dev->flags & IFF_UP))
+		return -EPERM;
 
 	return 0;
 }
diff --git a/include/net/bond_options.h b/include/net/bond_options.h
index 9d382f2f0bc5..742f5cc81adf 100644
--- a/include/net/bond_options.h
+++ b/include/net/bond_options.h
@@ -15,11 +15,13 @@
  * BOND_OPTFLAG_NOSLAVES - check if the bond device is empty before setting
  * BOND_OPTFLAG_IFDOWN - check if the bond device is down before setting
  * BOND_OPTFLAG_RAWVAL - the option parses the value itself
+ * BOND_OPTFLAG_IFUP - check if the bond device is up before setting
  */
 enum {
 	BOND_OPTFLAG_NOSLAVES	= BIT(0),
 	BOND_OPTFLAG_IFDOWN	= BIT(1),
-	BOND_OPTFLAG_RAWVAL	= BIT(2)
+	BOND_OPTFLAG_RAWVAL	= BIT(2),
+	BOND_OPTFLAG_IFUP	= BIT(3)
 };
 
 /* Value type flags:
-- 
2.27.0


             reply	other threads:[~2021-07-28  3:35 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-07-28  3:35 zhudi [this message]
2021-07-28  5:06 ` Jay Vosburgh
2021-07-28  6:51 zhudi (J)
2021-07-28 19:57 ` Jay Vosburgh
2021-07-29  1:46 zhudi (J)

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=20210728033505.1627-1-zhudi21@huawei.com \
    --to=zhudi21@huawei.com \
    --cc=davem@davemloft.net \
    --cc=j.vosburgh@gmail.com \
    --cc=kuba@kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=rose.chen@huawei.com \
    --cc=vfalico@gmail.com \
    --subject='Re: [PATCH] bonding: Avoid adding slave devices to inactive bonding' \
    /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

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).