From: Phil Sutter <phil@nwl.cc>
To: Stephen Hemminger <shemming@brocade.com>
Cc: netdev@vger.kernel.org
Subject: [iproute PATCH 0/3] tc: pedit fixes
Date: Wed,  2 Mar 2016 12:20:28 +0100	[thread overview]
Message-ID: <1456917631-18447-1-git-send-email-phil@nwl.cc> (raw)
While implementing an implementation example for a pedit man page, I
noticed several issues with the current code. The following patch
series addreses them.
In order to validate my changes, I implemented a simple unit tester.
It requires the following hack:
--------------------------8<-----------------------------------------
--- a/tc/m_pedit.c
+++ b/tc/m_pedit.c
@@ -513,6 +513,12 @@ parse_pedit(struct action_util *a, int *argc_p, char ***argv_p, int tca_id, stru
                }
        }
 
+       fprintf(stderr, "mask=0x%x\n", sel.keys[0].mask);
+       fprintf(stderr, "val=0x%x\n", sel.keys[0].val);
+       fprintf(stderr, "off=0x%x\n", sel.keys[0].off);
+       fprintf(stderr, "at=0x%x\n", sel.keys[0].at);
+       fprintf(stderr, "offmask=0x%x\n", sel.keys[0].offmask);
+       fprintf(stderr, "shift=0x%x\n", sel.keys[0].shift);
        tail = NLMSG_TAIL(n);
        addattr_l(n, MAX_MSG, tca_id, NULL, 0);
        addattr_l(n, MAX_MSG, TCA_PEDIT_PARMS,&sel, sizeof(sel.sel)+sel.sel.nkeys*sizeof(struct tc_pedit_key));
--------------------------8<-----------------------------------------
With this in place, the following simple shell script can be used to
check generated permutation values:
--------------------------8<-----------------------------------------
#!/bin/bash
run_tc() {
	echo "testing $@"
	eval "$(./tc/tc filter add dev bla123 parent root u32 \
		match u32 0 0 action pedit munge $@ 2>&1 | \
		grep -e '^\(mask\|val\|off\|at\|offmask\|shift\)=')"
}
prove() { # (oval, check, ooff)
	local oval=$1
	local check=$2
	local ooff=$3
	[[ $ooff -eq $off ]] || {
		echo "Wrong offset ($off instead of $ooff)"
		#exit 1
	}
	[[ $(((oval & mask) ^ val)) -eq $check ]] || {
		echo "failed for $oval, should be $check but is 0x$(echo "obase = 16; $(((oval & mask) ^ val))" | bc)"
		echo "mask=$mask"
		echo "val=$val"
		echo "off=$off"
		echo "at=$at"
		echo "offmask=$offmask"
		echo "shift=$shift"
		#exit 1
	}
}
run_tc ip df set 0
prove 0xffffffff 0xffbfffff 4
prove 0x00400000 0x00000000 4
prove 0xffbfffff 0xffbfffff 4
prove 0x00000000 0x00000000 4
run_tc ip df set 0x40
prove 0xffffffff 0xffffffff 4
prove 0x00400000 0x00400000 4
prove 0xffbfffff 0xffffffff 4
prove 0x00000000 0x00400000 4
run_tc ip df preserve
prove 0xffffffff 0xffffffff 4
prove 0x00400000 0x00400000 4
prove 0xffbfffff 0xffbfffff 4
prove 0x00000000 0x00000000 4
run_tc ip df invert
prove 0xffffffff 0xffbfffff 4
prove 0x00400000 0x00000000 4
prove 0xffbfffff 0xffffffff 4
prove 0x00000000 0x00400000 4
run_tc ip mf set 0x20
prove 0xfffff2ff 0xfffff2ff 4
prove 0x00203000 0x00203000 4
prove 0xfadfffff 0xfaffffff 4
prove 0x00000000 0x00200000 4
run_tc ip ihl set 0x04
prove 0xffffffff 0xfffffff4 0
prove 0x00000005 0x00000004 0
prove 0xfffffff0 0xfffffff4 0
prove 0x00000000 0x00000004 0
run_tc ip tos set 0
prove 0xffffffff 0xffff00ff 0
prove 0x00002300 0x00000000 0
prove 0xffff00ff 0xffff00ff 0
prove 0x00000000 0x00000000 0
run_tc ip tos set 17
prove 0xffffffff 0xffff11ff 0
prove 0x00002300 0x00001100 0
prove 0xffff00ff 0xffff11ff 0
prove 0x00000000 0x00001100 0
run_tc ip tos invert
prove 0xffffffff 0xffff00ff 0
prove 0x00002300 0x0000DC00 0
prove 0xffff00ff 0xffffffff 0
prove 0x00000000 0x0000ff00 0
run_tc ip tos preserve
prove 0xffffffff 0xffffffff 0
prove 0x00002300 0x00002300 0
prove 0xffff00ff 0xffff00ff 0
prove 0x00000000 0x00000000 0
run_tc ip tos clear
prove 0xffffffff 0xffff00ff 0
prove 0x00002300 0x00000000 0
prove 0xffff00ff 0xffff00ff 0
prove 0x00000000 0x00000000 0
run_tc ip dport set 0
prove 0xffffffff 0x0000ffff 20
prove 0x12340000 0x00000000 20
prove 0x0000ffff 0x0000ffff 20
prove 0x00000000 0x00000000 20
run_tc ip dport set 27374
prove 0xfffff22f 0xee6af22f 20
prove 0x12340010 0xee6a0010 20
prove 0xee6aff0f 0xee6aff0f 20
prove 0xee6a0000 0xee6a0000 20
run_tc ip dport invert
prove 0xffffffff 0x0000ffff 20
prove 0x12340000 0xEDCB0000 20
prove 0x00000000 0xffff0000 20
run_tc ip dport preserve
prove 0xffffffff 0xffffffff 20
prove 0x12340000 0x12340000 20
prove 0xee6affff 0xee6affff 20
prove 0xee6a0000 0xee6a0000 20
run_tc ip dport clear
prove 0xffff3fff 0x00003fff 20
prove 0x12340030 0x00000030 20
prove 0xee6af1ff 0x0000f1ff 20
prove 0x00000000 0x00000000 20
run_tc ip src set 0.0.0.0
prove 0xffff3fff 0x00000000 12
prove 0x12340030 0x00000000 12
prove 0xee6af1ff 0x00000000 12
prove 0x00000000 0x00000000 12
run_tc ip src set 1.2.3.4
prove 0xffff3fff 0x01020304 12
prove 0x12340030 0x01020304 12
prove 0xee6af1ff 0x01020304 12
prove 0x00000000 0x01020304 12
run_tc ip src clear
prove 0xffff3fff 0x00000000 12
prove 0x12340030 0x00000000 12
prove 0xee6af1ff 0x00000000 12
prove 0x00000000 0x00000000 12
run_tc ip src preserve
prove 0xffff3fff 0xffff3fff 12
prove 0x12340030 0x12340030 12
prove 0xee6af1ff 0xee6af1ff 12
prove 0x00000000 0x00000000 12
run_tc ip src invert
prove 0xffff3fff 0x0000c000 12
prove 0x12340030 0xedcbffcf 12
prove 0xee6af1ff 0x11950e00 12
prove 0x00000000 0xffffffff 12
--------------------------8<-----------------------------------------
Phil Sutter (3):
  tc: pedit: Fix layered op parsing
  tc: pedit: Fix parse_cmd()
  tc: pedit: Fix retain value for ihl adjustments
 tc/m_pedit.c | 24 ++++++++----------------
 tc/p_ip.c    |  2 +-
 2 files changed, 9 insertions(+), 17 deletions(-)
-- 
2.7.2
next             reply	other threads:[~2016-03-02 11:21 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-03-02 11:20 Phil Sutter [this message]
2016-03-02 11:20 ` [iproute PATCH 1/3] tc: pedit: Fix layered op parsing Phil Sutter
2016-03-02 11:20 ` [iproute PATCH 2/3] tc: pedit: Fix parse_cmd() Phil Sutter
2016-03-02 11:20 ` [iproute PATCH 3/3] tc: pedit: Fix retain value for ihl adjustments Phil Sutter
     [not found] ` <499abfe479324d1e83289cd68b2a7641@HQ1WP-EXMB11.corp.brocade.com>
2016-03-02 17:54   ` Stephen Hemminger
2016-03-02 18:45     ` [iproute PATCH v2 0/4] tc: pedit fixes Phil Sutter
2016-03-02 18:45       ` [iproute PATCH v2 1/4] tc: pedit: Fix layered op parsing Phil Sutter
2016-03-02 18:45       ` [iproute PATCH v2 2/4] tc: pedit: Fix parse_cmd() Phil Sutter
2016-03-02 18:45       ` [iproute PATCH v2 3/4] tc: pedit: Fix retain value for ihl adjustments Phil Sutter
2016-03-02 18:45       ` [iproute PATCH v2 4/4] tc/p_ip.c: Lint through checkpatch.pl Phil Sutter
2016-03-02 19:05       ` [iproute PATCH v2 0/4] tc: pedit fixes Stephen Hemminger
2016-03-02 19:23         ` Phil Sutter
     [not found]       ` <fd3bfe390dda465ab0d6b758553a9b04@HQ1WP-EXMB11.corp.brocade.com>
2016-03-21 19:21         ` [iproute PATCH v2 4/4] tc/p_ip.c: Lint through checkpatch.pl Stephen Hemminger
2016-03-03 14:21     ` [iproute PATCH 3/3] tc: pedit: Fix retain value for ihl adjustments Jamal Hadi Salim
2016-03-03 14:28       ` Jamal Hadi Salim
2016-03-03 14:54         ` Phil Sutter
2016-03-03 14:32       ` Phil Sutter
2016-03-07 11:21         ` Jamal Hadi Salim
2016-03-07 12:57           ` Phil Sutter
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=1456917631-18447-1-git-send-email-phil@nwl.cc \
    --to=phil@nwl.cc \
    --cc=netdev@vger.kernel.org \
    --cc=shemming@brocade.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).