netfilter-devel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Pablo Neira Ayuso <pablo@netfilter.org>
To: netfilter-devel@vger.kernel.org
Cc: davem@davemloft.net, netdev@vger.kernel.org,
	jakub.kicinski@netronome.com, jiri@resnulli.us,
	saeedm@mellanox.com, vishal@chelsio.com, vladbu@mellanox.com,
	ecree@solarflare.com
Subject: [PATCH net-next,v4 4/4] net: flow_offload: add flow_rule_print()
Date: Tue, 15 Oct 2019 00:00:27 +0200	[thread overview]
Message-ID: <20191014220027.7500-5-pablo@netfilter.org> (raw)
In-Reply-To: <20191014220027.7500-1-pablo@netfilter.org>

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
---
 include/net/flow_offload.h        |  3 ++
 net/core/flow_offload.c           | 85 +++++++++++++++++++++++++++++++++++++++
 net/netfilter/nf_tables_offload.c |  6 ++-
 net/sched/cls_flower.c            |  4 ++
 4 files changed, 97 insertions(+), 1 deletion(-)

diff --git a/include/net/flow_offload.h b/include/net/flow_offload.h
index 78a462d4bfbb..e65007378d38 100644
--- a/include/net/flow_offload.h
+++ b/include/net/flow_offload.h
@@ -6,6 +6,9 @@
 #include <net/flow_dissector.h>
 #include <linux/rhashtable.h>
 
+struct flow_rule;
+void flow_rule_print(const struct flow_rule *flow_rule);
+
 struct flow_match {
 	struct flow_dissector	*dissector;
 	void			*mask;
diff --git a/net/core/flow_offload.c b/net/core/flow_offload.c
index cf52d9c422fa..9ef74e338d3f 100644
--- a/net/core/flow_offload.c
+++ b/net/core/flow_offload.c
@@ -5,6 +5,91 @@
 #include <linux/rtnetlink.h>
 #include <linux/mutex.h>
 
+void flow_rule_print(const struct flow_rule *flow_rule)
+{
+	const struct flow_action_entry *act;
+	int i;
+
+	pr_info("match : ");
+	if (flow_rule_match_key(flow_rule, FLOW_DISSECTOR_KEY_BASIC)) {
+		struct flow_match_basic match;
+
+		flow_rule_match_basic(flow_rule, &match);
+		pr_info("l3num %hu/%x protocol %u/%x ",
+			match.key->n_proto, match.mask->n_proto,
+			match.key->ip_proto, match.mask->ip_proto);
+	}
+
+	if (flow_rule_match_key(flow_rule, FLOW_DISSECTOR_KEY_IPV4_ADDRS)) {
+		struct flow_match_ipv4_addrs match;
+
+		flow_rule_match_ipv4_addrs(flow_rule, &match);
+		pr_info("src=%pI4/%pI4 dst=%pI4/%pI4 ",
+			&match.key->src, &match.mask->src,
+			&match.key->dst, &match.mask->dst);
+	}
+
+	if (flow_rule_match_key(flow_rule, FLOW_DISSECTOR_KEY_PORTS)) {
+		struct flow_match_ports match;
+
+		flow_rule_match_ports(flow_rule, &match);
+		pr_info("sport %hu/%x dport %hu/%x ",
+			match.key->src, match.mask->src,
+			match.key->dst, match.mask->dst);
+	}
+
+	pr_info("actions(%d): ", flow_rule->action.num_entries);
+	flow_action_for_each(i, act, &flow_rule->action) {
+		switch (act->id) {
+		case FLOW_ACTION_DROP:
+			pr_info("drop");
+			break;
+		case FLOW_ACTION_ACCEPT:
+			pr_info("accept");
+			break;
+		case FLOW_ACTION_MANGLE:
+			pr_info("mangle htype=%u offset=%u len=%u ",
+				act->mangle.htype, act->mangle.offset,
+				act->mangle.len);
+			{
+				int k;
+
+				pr_info("val=");
+				for (k = 0; k < act->mangle.len; k++)
+					pr_info("%.2x ", act->mangle.val[k]);
+
+				pr_info(" mask=");
+				for (k = 0; k < act->mangle.len; k++)
+					pr_info("%.2x ", act->mangle.mask[k]);
+
+				pr_info("\n");
+			}
+			break;
+		case FLOW_ACTION_REDIRECT:
+			pr_info("redirect\n");
+			break;
+		case FLOW_ACTION_MIRRED:
+			pr_info("mirred\n");
+			break;
+		case FLOW_ACTION_CSUM:
+			pr_info("checksum\n");
+			break;
+		case FLOW_ACTION_TUNNEL_ENCAP:
+			pr_info("tunnel encap\n");
+			break;
+		case FLOW_ACTION_TUNNEL_DECAP:
+			pr_info("tunnel decap\n");
+			break;
+		default:
+			pr_info("unknown!!!!");
+			break;
+		}
+	}
+
+	pr_info("\n");
+}
+EXPORT_SYMBOL_GPL(flow_rule_print);
+
 struct flow_rule *flow_rule_alloc(unsigned int num_actions)
 {
 	struct flow_rule *rule;
diff --git a/net/netfilter/nf_tables_offload.c b/net/netfilter/nf_tables_offload.c
index e546f759b7a7..f73f5b84be70 100644
--- a/net/netfilter/nf_tables_offload.c
+++ b/net/netfilter/nf_tables_offload.c
@@ -177,8 +177,12 @@ static int nft_flow_offload_rule(struct nft_chain *chain,
 				     basechain->ops.priority, &extack);
 	cls_flow.command = command;
 	cls_flow.cookie = (unsigned long) rule;
-	if (flow)
+	if (flow) {
 		cls_flow.rule = flow->rule;
+		pr_info("---- nft hw offload ----\n");
+		flow_rule_print(cls_flow.rule);
+		pr_info("--------\n");
+	}
 
 	return nft_setup_cb_call(basechain, TC_SETUP_CLSFLOWER, &cls_flow);
 }
diff --git a/net/sched/cls_flower.c b/net/sched/cls_flower.c
index 74221e3351c3..9beab50474c3 100644
--- a/net/sched/cls_flower.c
+++ b/net/sched/cls_flower.c
@@ -453,6 +453,10 @@ static int fl_hw_replace_filter(struct tcf_proto *tp,
 		return 0;
 	}
 
+	pr_info("---- hw offload ----\n");
+	flow_rule_print(cls_flower.rule);
+	pr_info("--------\n");
+
 	err = tc_setup_cb_add(block, tp, TC_SETUP_CLSFLOWER, &cls_flower,
 			      skip_sw, &f->flags, &f->in_hw_count, rtnl_held);
 	tc_cleanup_flow_action(&cls_flower.rule->action);
-- 
2.11.0


  parent reply	other threads:[~2019-10-14 22:01 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-10-14 22:00 [PATCH net-next,v4 0/4] flow_offload: update mangle action representation Pablo Neira Ayuso
2019-10-14 22:00 ` [PATCH net-next,v4 1/4] net: flow_offload: bitwise AND on mangle action value field Pablo Neira Ayuso
2019-10-14 22:00 ` [PATCH net-next,v4 2/4] net: flow_offload: mangle action at byte level Pablo Neira Ayuso
2019-10-14 22:00 ` [PATCH net-next,v4 3/4] netfilter: nft_payload: packet mangling offload support Pablo Neira Ayuso
2019-10-14 22:00 ` Pablo Neira Ayuso [this message]
2019-10-14 22:04 ` [PATCH net-next,v4 0/4] flow_offload: update mangle action representation Pablo Neira Ayuso

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=20191014220027.7500-5-pablo@netfilter.org \
    --to=pablo@netfilter.org \
    --cc=davem@davemloft.net \
    --cc=ecree@solarflare.com \
    --cc=jakub.kicinski@netronome.com \
    --cc=jiri@resnulli.us \
    --cc=netdev@vger.kernel.org \
    --cc=netfilter-devel@vger.kernel.org \
    --cc=saeedm@mellanox.com \
    --cc=vishal@chelsio.com \
    --cc=vladbu@mellanox.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).