All of lore.kernel.org
 help / color / mirror / Atom feed
From: Anton Danilov <littlesmilingcloud@gmail.com>
To: Stephen Hemminger <stephen@networkplumber.org>
Cc: netdev@vger.kernel.org, Anton Danilov <littlesmilingcloud@gmail.com>
Subject: [RFC 3/3] [RFC iproute2-next] tc: f_u32: fix the pretty print of ipv4 filters
Date: Tue,  8 Jun 2021 18:33:09 +0300	[thread overview]
Message-ID: <20210608153309.4019-3-littlesmilingcloud@gmail.com> (raw)
In-Reply-To: <20210608153309.4019-1-littlesmilingcloud@gmail.com>

~$: tc f add dev dummy0 parent 1: protocol ip prio 10 \
    u32 match ip ihl 10 0xf match ip dsfield 0x0a 0xff flowid 1:1

Before patch:

~$ sudo tc -p -s f ls dev dummy0
filter parent 1: protocol ip pref 10 u32 chain 0
filter parent 1: protocol ip pref 10 u32 chain 0 fh 801: ht divisor 1
filter parent 1: protocol ip pref 10 u32 chain 0 fh 801::801 order 2049 key ht 801 bkt 0 flowid 1:1 not_in_hw  (rule hit 0 success 0) (success 0 )

After patch:
~$ sudo tc -p -s f ls dev dummy0
filter parent 1: protocol ip pref 10 u32 chain 0
filter parent 1: protocol ip pref 10 u32 chain 0 fh 801: ht divisor 1
filter parent 1: protocol ip pref 10 u32 chain 0 fh 801::801 order 2049 key ht 801 bkt 0 flowid 1:1 not_in_hw  (rule hit 0 success 0)
  match ip ihl 10 0xf
  match ip dsfield 0xa 0xff (success 0 )

Signed-off-by: Anton Danilov <littlesmilingcloud@gmail.com>
---
 tc/f_u32.c | 23 ++++++++++++++---------
 1 file changed, 14 insertions(+), 9 deletions(-)

diff --git a/tc/f_u32.c b/tc/f_u32.c
index d7beb586..e60c787a 100644
--- a/tc/f_u32.c
+++ b/tc/f_u32.c
@@ -827,20 +827,25 @@ static int print_ipv4(FILE *f, const struct tc_u32_key *key)
 	if (key == NULL)
 		return 0;
 
+	int ret = 0;
+
 	switch (key->off) {
 	case 0:
-		switch (ntohl(key->mask)) {
-		case 0x0f000000:
-			return fprintf(f, "\n  match IP ihl %u",
-				ntohl(key->val) >> 24);
-		case 0x00ff0000:
-			return fprintf(f, "\n  match IP dsfield %#x",
-				ntohl(key->val) >> 16);
+		if (ntohl(key->mask) & 0x0f000000) {
+			ret = fprintf(f, "\n  match ip ihl %u %#x",
+				(ntohl(key->val) & 0x0f000000) >> 24,
+				(ntohl(key->mask) & 0x0f000000) >> 24);
+		}
+		if (ntohl(key->mask) & 0x00ff0000) {
+			ret += fprintf(f, "\n  match ip dsfield %#x %#x",
+				(ntohl(key->val) & 0x00ff0000) >> 16,
+				(ntohl(key->mask) & 0x00ff0000) >> 16);
 		}
+		return ret;
 		break;
 	case 8:
 		if (ntohl(key->mask) == 0x00ff0000) {
-			return fprintf(f, "\n  match IP protocol %d",
+			return fprintf(f, "\n  match ip protocol %d",
 				ntohl(key->val) >> 16);
 		}
 		break;
@@ -850,7 +855,7 @@ static int print_ipv4(FILE *f, const struct tc_u32_key *key)
 
 			if (bits >= 0) {
 				return fprintf(f, "\n  %s %s/%d",
-					key->off == 12 ? "match IP src" : "match IP dst",
+					key->off == 12 ? "match ip src" : "match ip dst",
 					inet_ntop(AF_INET, &key->val,
 						  abuf, sizeof(abuf)),
 					bits);
-- 
2.20.1


      parent reply	other threads:[~2021-06-08 15:34 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-06-08 15:33 [RFC 1/3] [RFC iproute2-next] tc: f_u32: Rename commands and functions ip6 to ipv6 to unify naming Anton Danilov
2021-06-08 15:33 ` [RFC 2/3] [RFC iproute2-next] tc: f_u32: Fix the ipv6 pretty printing Anton Danilov
2021-06-15  2:57   ` Stephen Hemminger
2021-06-16 10:49     ` Anton Danilov
2021-06-08 15:33 ` Anton Danilov [this message]

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=20210608153309.4019-3-littlesmilingcloud@gmail.com \
    --to=littlesmilingcloud@gmail.com \
    --cc=netdev@vger.kernel.org \
    --cc=stephen@networkplumber.org \
    /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.