public inbox for netdev@vger.kernel.org 
 help / color / mirror / Atom feed
From: Al Viro <viro@ZenIV•linux.org.uk>
To: netdev@vger•kernel.org
Cc: Jamal Hadi Salim <jhs@mojatatu•com>,
	Cong Wang <xiyou.wangcong@gmail•com>,
	Jiri Pirko <jiri@resnulli•us>
Subject: [PATCH 2/7] mark root hnode explicitly
Date: Wed,  5 Sep 2018 20:04:09 +0100	[thread overview]
Message-ID: <20180905190414.5477-2-viro@ZenIV.linux.org.uk> (raw)
In-Reply-To: <20180905190414.5477-1-viro@ZenIV.linux.org.uk>

From: Al Viro <viro@zeniv•linux.org.uk>

... and disallow deleting or linking to such

Signed-off-by: Al Viro <viro@zeniv•linux.org.uk>
---
 net/sched/cls_u32.c | 14 +++++++++++---
 1 file changed, 11 insertions(+), 3 deletions(-)

diff --git a/net/sched/cls_u32.c b/net/sched/cls_u32.c
index 3f985f29ef30..9ea5f2be907b 100644
--- a/net/sched/cls_u32.c
+++ b/net/sched/cls_u32.c
@@ -91,6 +91,7 @@ struct tc_u_hnode {
 	 */
 	struct tc_u_knode __rcu	*ht[1];
 };
+#define TCA_CLS_FLAGS_U32_ROOT (1<<8)
 
 struct tc_u_common {
 	struct tc_u_hnode __rcu	*hlist;
@@ -377,6 +378,7 @@ static int u32_init(struct tcf_proto *tp)
 	root_ht->refcnt++;
 	root_ht->handle = tp_c ? gen_new_htid(tp_c, root_ht) : 0x80000000;
 	root_ht->prio = tp->prio;
+	root_ht->flags = TCA_CLS_FLAGS_U32_ROOT;
 	idr_init(&root_ht->handle_idr);
 
 	if (tp_c == NULL) {
@@ -491,7 +493,8 @@ static void u32_clear_hw_hnode(struct tcf_proto *tp, struct tc_u_hnode *h,
 	struct tcf_block *block = tp->chain->block;
 	struct tc_cls_u32_offload cls_u32 = {};
 
-	tc_cls_common_offload_init(&cls_u32.common, tp, h->flags, extack);
+	tc_cls_common_offload_init(&cls_u32.common, tp,
+		h->flags & ~TCA_CLS_FLAGS_U32_ROOT, extack);
 	cls_u32.command = TC_CLSU32_DELETE_HNODE;
 	cls_u32.hnode.divisor = h->divisor;
 	cls_u32.hnode.handle = h->handle;
@@ -693,7 +696,7 @@ static int u32_delete(struct tcf_proto *tp, void *arg, bool *last,
 		goto out;
 	}
 
-	if (root_ht == ht) {
+	if (ht->flags & TCA_CLS_FLAGS_U32_ROOT) {
 		NL_SET_ERR_MSG_MOD(extack, "Not allowed to delete root node");
 		return -EINVAL;
 	}
@@ -795,6 +798,10 @@ static int u32_set_parms(struct net *net, struct tcf_proto *tp,
 				NL_SET_ERR_MSG_MOD(extack, "Link hash table not found");
 				return -EINVAL;
 			}
+			if (ht_down->flags & TCA_CLS_FLAGS_U32_ROOT) {
+				NL_SET_ERR_MSG_MOD(extack, "Not linke to root node");
+				return -EINVAL;
+			}
 			ht_down->refcnt++;
 		}
 
@@ -1214,7 +1221,8 @@ static int u32_reoffload_hnode(struct tcf_proto *tp, struct tc_u_hnode *ht,
 	struct tc_cls_u32_offload cls_u32 = {};
 	int err;
 
-	tc_cls_common_offload_init(&cls_u32.common, tp, ht->flags, extack);
+	tc_cls_common_offload_init(&cls_u32.common, tp,
+		ht->flags & ~TCA_CLS_FLAGS_U32_ROOT, extack);
 	cls_u32.command = add ? TC_CLSU32_NEW_HNODE : TC_CLSU32_DELETE_HNODE;
 	cls_u32.hnode.divisor = ht->divisor;
 	cls_u32.hnode.handle = ht->handle;
-- 
2.11.0

  reply	other threads:[~2018-09-05 23:35 UTC|newest]

Thread overview: 30+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-09-05 19:01 [PATCHES] cls_u32 cleanups and fixes Al Viro
2018-09-05 19:04 ` [PATCH 1/7] fix hnode refcounting Al Viro
2018-09-05 19:04   ` Al Viro [this message]
2018-09-06 10:28     ` [PATCH 2/7] mark root hnode explicitly Jamal Hadi Salim
2018-09-06 10:34       ` Jamal Hadi Salim
2018-09-06 10:42         ` Jamal Hadi Salim
2018-09-06 10:59         ` Al Viro
2018-09-06 11:04           ` Jamal Hadi Salim
2018-09-07  2:57           ` Cong Wang
2018-09-07  3:04             ` Al Viro
2018-09-07  3:23               ` Cong Wang
2018-09-07  3:49                 ` Al Viro
2018-09-07  4:14                   ` Cong Wang
2018-09-05 19:04   ` [PATCH 3/7] make sure that divisor is a power of 2 Al Viro
2018-09-06 10:28     ` Jamal Hadi Salim
2018-09-05 19:04   ` [PATCH 4/7] get rid of unused argument of u32_destroy_key() Al Viro
2018-09-06 10:34     ` Jamal Hadi Salim
2018-09-05 19:04   ` [PATCH 5/7] get rid of tc_u_knode ->tp Al Viro
2018-09-06 10:35     ` Jamal Hadi Salim
2018-09-05 19:04   ` [PATCH 6/7] get rid of tc_u_common ->rcu Al Viro
2018-09-06 10:36     ` Jamal Hadi Salim
2018-09-07  4:18     ` Cong Wang
2018-09-07  4:28       ` Al Viro
2018-09-05 19:04   ` [PATCH 7/7] clean tc_u_common hashtable Al Viro
2018-09-06 10:36     ` Jamal Hadi Salim
2018-09-06 10:21   ` [PATCH 1/7] fix hnode refcounting Jamal Hadi Salim
2018-09-07  2:35     ` Al Viro
2018-09-07 12:13       ` Jamal Hadi Salim
2018-09-07 12:33         ` Jamal Hadi Salim
2018-09-08 15:03         ` Al Viro

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=20180905190414.5477-2-viro@ZenIV.linux.org.uk \
    --to=viro@zeniv$(echo .)linux.org.uk \
    --cc=jhs@mojatatu$(echo .)com \
    --cc=jiri@resnulli$(echo .)us \
    --cc=netdev@vger$(echo .)kernel.org \
    --cc=xiyou.wangcong@gmail$(echo .)com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html
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