All of lore.kernel.org
 help / color / mirror / Atom feed
From: Jiri Pirko <jiri@resnulli.us>
To: netdev@vger.kernel.org
Cc: davem@davemloft.net, jhs@mojatatu.com, xiyou.wangcong@gmail.com,
	dsa@cumulusnetworks.com, edumazet@google.com,
	stephen@networkplumber.org, daniel@iogearbox.net,
	alexander.h.duyck@intel.com, simon.horman@netronome.com,
	mlxsw@mellanox.com
Subject: [patch net-next v2 07/10] net: sched: push chain dump to a separate function
Date: Mon, 15 May 2017 10:38:54 +0200	[thread overview]
Message-ID: <20170515083857.3615-8-jiri@resnulli.us> (raw)
In-Reply-To: <20170515083857.3615-1-jiri@resnulli.us>

From: Jiri Pirko <jiri@mellanox.com>

Since there will be multiple chains to dump, push chain dumping code to
a separate function.

Signed-off-by: Jiri Pirko <jiri@mellanox.com>
---
 net/sched/cls_api.c | 95 +++++++++++++++++++++++++++++------------------------
 1 file changed, 52 insertions(+), 43 deletions(-)

diff --git a/net/sched/cls_api.c b/net/sched/cls_api.c
index 6f2ea68..9f48061 100644
--- a/net/sched/cls_api.c
+++ b/net/sched/cls_api.c
@@ -634,21 +634,65 @@ static int tcf_node_dump(struct tcf_proto *tp, unsigned long n,
 			     RTM_NEWTFILTER);
 }
 
+static void tcf_chain_dump(struct tcf_chain *chain, struct sk_buff *skb,
+			   struct netlink_callback *cb,
+			   long index_start, long *p_index)
+{
+	struct net *net = sock_net(skb->sk);
+	struct tcmsg *tcm = nlmsg_data(cb->nlh);
+	struct tcf_dump_args arg;
+	struct tcf_proto *tp;
+
+	for (tp = rtnl_dereference(chain->filter_chain);
+	     tp; tp = rtnl_dereference(tp->next), (*p_index)++) {
+		if (*p_index < index_start)
+			continue;
+		if (TC_H_MAJ(tcm->tcm_info) &&
+		    TC_H_MAJ(tcm->tcm_info) != tp->prio)
+			continue;
+		if (TC_H_MIN(tcm->tcm_info) &&
+		    TC_H_MIN(tcm->tcm_info) != tp->protocol)
+			continue;
+		if (*p_index > index_start)
+			memset(&cb->args[1], 0,
+			       sizeof(cb->args) - sizeof(cb->args[0]));
+		if (cb->args[1] == 0) {
+			if (tcf_fill_node(net, skb, tp, 0,
+					  NETLINK_CB(cb->skb).portid,
+					  cb->nlh->nlmsg_seq, NLM_F_MULTI,
+					  RTM_NEWTFILTER) <= 0)
+				break;
+
+			cb->args[1] = 1;
+		}
+		if (!tp->ops->walk)
+			continue;
+		arg.w.fn = tcf_node_dump;
+		arg.skb = skb;
+		arg.cb = cb;
+		arg.w.stop = 0;
+		arg.w.skip = cb->args[1] - 1;
+		arg.w.count = 0;
+		tp->ops->walk(tp, &arg.w);
+		cb->args[1] = arg.w.count + 1;
+		if (arg.w.stop)
+			break;
+	}
+}
+
 /* called with RTNL */
 static int tc_dump_tfilter(struct sk_buff *skb, struct netlink_callback *cb)
 {
 	struct net *net = sock_net(skb->sk);
-	int t;
-	int s_t;
 	struct net_device *dev;
 	struct Qdisc *q;
 	struct tcf_block *block;
-	struct tcf_proto *tp;
 	struct tcf_chain *chain;
 	struct tcmsg *tcm = nlmsg_data(cb->nlh);
 	unsigned long cl = 0;
 	const struct Qdisc_class_ops *cops;
-	struct tcf_dump_args arg;
+	long index_start;
+	long index;
 
 	if (nlmsg_len(cb->nlh) < sizeof(*tcm))
 		return skb->len;
@@ -677,45 +721,10 @@ static int tc_dump_tfilter(struct sk_buff *skb, struct netlink_callback *cb)
 		goto errout;
 	chain = block->chain;
 
-	s_t = cb->args[0];
-
-	for (tp = rtnl_dereference(chain->filter_chain), t = 0;
-	     tp; tp = rtnl_dereference(tp->next), t++) {
-		if (t < s_t)
-			continue;
-		if (TC_H_MAJ(tcm->tcm_info) &&
-		    TC_H_MAJ(tcm->tcm_info) != tp->prio)
-			continue;
-		if (TC_H_MIN(tcm->tcm_info) &&
-		    TC_H_MIN(tcm->tcm_info) != tp->protocol)
-			continue;
-		if (t > s_t)
-			memset(&cb->args[1], 0,
-			       sizeof(cb->args)-sizeof(cb->args[0]));
-		if (cb->args[1] == 0) {
-			if (tcf_fill_node(net, skb, tp, 0,
-					  NETLINK_CB(cb->skb).portid,
-					  cb->nlh->nlmsg_seq, NLM_F_MULTI,
-					  RTM_NEWTFILTER) <= 0)
-				break;
-
-			cb->args[1] = 1;
-		}
-		if (tp->ops->walk == NULL)
-			continue;
-		arg.w.fn = tcf_node_dump;
-		arg.skb = skb;
-		arg.cb = cb;
-		arg.w.stop = 0;
-		arg.w.skip = cb->args[1] - 1;
-		arg.w.count = 0;
-		tp->ops->walk(tp, &arg.w);
-		cb->args[1] = arg.w.count + 1;
-		if (arg.w.stop)
-			break;
-	}
-
-	cb->args[0] = t;
+	index_start = cb->args[0];
+	index = 0;
+	tcf_chain_dump(chain, skb, cb, index_start, &index);
+	cb->args[0] = index;
 
 errout:
 	if (cl)
-- 
2.9.3

  parent reply	other threads:[~2017-05-15  8:39 UTC|newest]

Thread overview: 27+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-05-15  8:38 [patch net-next v2 00/10] net: sched: introduce multichain support for filters Jiri Pirko
2017-05-15  8:38 ` [patch net-next v2 01/10] net: sched: move tc_classify function to cls_api.c Jiri Pirko
2017-05-15  8:38 ` [patch net-next v2 02/10] net: sched: introduce tcf block infractructure Jiri Pirko
2017-05-16 12:07   ` Jamal Hadi Salim
2017-05-16 12:23     ` Jiri Pirko
2017-05-16 12:52       ` Jamal Hadi Salim
2017-05-16 13:10         ` Jiri Pirko
2017-05-15  8:38 ` [patch net-next v2 03/10] net: sched: rename tcf_destroy_chain helper Jiri Pirko
2017-05-15  8:38 ` [patch net-next v2 04/10] net: sched: replace nprio by a bool to make the function more readable Jiri Pirko
2017-05-16 12:09   ` Jamal Hadi Salim
2017-05-16 12:25     ` Jiri Pirko
2017-05-16 12:56       ` Jamal Hadi Salim
2017-05-15  8:38 ` [patch net-next v2 05/10] net: sched: move TC_H_MAJ macro call into tcf_auto_prio Jiri Pirko
2017-05-15  8:38 ` [patch net-next v2 06/10] net: sched: introduce helpers to work with filter chains Jiri Pirko
2017-05-15  8:38 ` Jiri Pirko [this message]
2017-05-15  8:38 ` [patch net-next v2 08/10] net: sched: introduce multichain support for filters Jiri Pirko
2017-05-15  8:38 ` [patch net-next v2 09/10] net: sched: push tp down to action init Jiri Pirko
2017-05-15  8:38 ` [patch net-next v2 10/10] net: sched: add termination action to allow goto chain Jiri Pirko
2017-05-15 20:02   ` Daniel Borkmann
2017-05-16  4:43     ` Jiri Pirko
2017-05-16  7:59       ` Daniel Borkmann
2017-05-16 12:46         ` Jamal Hadi Salim
2017-05-15  8:41 ` [patch iproute2 v2 1/3] tc_filter: add support for chain index Jiri Pirko
2017-05-15  8:41 ` [patch iproute2 v2 2/3] tc: actions: add helpers to parse and print control actions Jiri Pirko
2017-05-15  8:41 ` [patch iproute2 v2 3/3] tc/actions: introduce support for goto chain action Jiri Pirko
2017-05-16 16:20 ` [patch net-next v2 00/10] net: sched: introduce multichain support for filters David Miller
2017-05-16 16:23   ` Jiri Pirko

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=20170515083857.3615-8-jiri@resnulli.us \
    --to=jiri@resnulli.us \
    --cc=alexander.h.duyck@intel.com \
    --cc=daniel@iogearbox.net \
    --cc=davem@davemloft.net \
    --cc=dsa@cumulusnetworks.com \
    --cc=edumazet@google.com \
    --cc=jhs@mojatatu.com \
    --cc=mlxsw@mellanox.com \
    --cc=netdev@vger.kernel.org \
    --cc=simon.horman@netronome.com \
    --cc=stephen@networkplumber.org \
    --cc=xiyou.wangcong@gmail.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.