From: Phil Sutter <phil@nwl.cc>
To: Stephen Hemminger <shemming@brocade.com>
Cc: netdev@vger.kernel.org
Subject: [iproute PATCH v2 2/4] tc: pedit: Fix parse_cmd()
Date: Wed, 2 Mar 2016 19:45:41 +0100 [thread overview]
Message-ID: <1456944343-19058-3-git-send-email-phil@nwl.cc> (raw)
In-Reply-To: <1456944343-19058-1-git-send-email-phil@nwl.cc>
This was horribly broken:
* pack_key8() and pack_key16() ...
* missed to invert retain value when applying it to the mask,
* did not sanitize val by ANDing it with retain,
* and ignored the mask which is necessary for 'invert' command.
* pack_key16() did not convert mask to network byte order.
* Changing the retain value for 'invert' or 'retain' operation seems
just plain wrong.
* While here, also got rid of unnecessary offset sanitization in
pack_key32().
* Simplify code a bit by always assigning the local mask variable to
tkey->mask before calling any of the pack_key*() variants.
Signed-off-by: Phil Sutter <phil@nwl.cc>
---
tc/m_pedit.c | 23 +++++++----------------
1 file changed, 7 insertions(+), 16 deletions(-)
diff --git a/tc/m_pedit.c b/tc/m_pedit.c
index 455e4ffd4b2bb..a314f482cd9c0 100644
--- a/tc/m_pedit.c
+++ b/tc/m_pedit.c
@@ -152,8 +152,6 @@ pack_key32(__u32 retain,struct tc_pedit_sel *sel,struct tc_pedit_key *tkey)
tkey->val = htonl(tkey->val & retain);
tkey->mask = htonl(tkey->mask | ~retain);
- /* jamal remove this - it is not necessary given the if check above */
- tkey->off &= ~3;
return pack_key(sel,tkey);
}
@@ -176,11 +174,8 @@ pack_key16(__u32 retain,struct tc_pedit_sel *sel,struct tc_pedit_key *tkey)
}
stride = 8 * ind;
- tkey->val = htons(tkey->val);
- tkey->val <<= stride;
- tkey->mask <<= stride;
- retain <<= stride;
- tkey->mask = retain|m[ind];
+ tkey->val = htons(tkey->val & retain) << stride;
+ tkey->mask = (htons(tkey->mask | ~retain) << stride) | m[ind];
tkey->off &= ~3;
@@ -204,10 +199,8 @@ pack_key8(__u32 retain,struct tc_pedit_sel *sel,struct tc_pedit_key *tkey)
ind = tkey->off & 3;
stride = 8 * ind;
- tkey->val <<= stride;
- tkey->mask <<= stride;
- retain <<= stride;
- tkey->mask = retain|m[ind];
+ tkey->val = (tkey->val & retain) << stride;
+ tkey->mask = ((tkey->mask | ~retain) << stride) | m[ind];
tkey->off &= ~3;
@@ -268,13 +261,13 @@ parse_cmd(int *argc_p, char ***argv_p, __u32 len, int type,__u32 retain,struct t
o = 0xFFFFFFFF;
if (matches(*argv, "invert") == 0) {
- retain = val = mask = o;
+ val = mask = o;
} else if (matches(*argv, "set") == 0) {
NEXT_ARG();
if (parse_val(&argc, &argv, &val, type))
return -1;
} else if (matches(*argv, "preserve") == 0) {
- retain = mask = o;
+ retain = 0;
} else {
if (matches(*argv, "clear") != 0)
return -1;
@@ -290,19 +283,17 @@ parse_cmd(int *argc_p, char ***argv_p, __u32 len, int type,__u32 retain,struct t
}
tkey->val = val;
+ tkey->mask = mask;
if (len == 1) {
- tkey->mask = 0xFF;
res = pack_key8(retain,sel,tkey);
goto done;
}
if (len == 2) {
- tkey->mask = mask;
res = pack_key16(retain,sel,tkey);
goto done;
}
if (len == 4) {
- tkey->mask = mask;
res = pack_key32(retain,sel,tkey);
goto done;
}
--
2.7.2
next prev parent reply other threads:[~2016-03-02 18:46 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-03-02 11:20 [iproute PATCH 0/3] tc: pedit fixes Phil Sutter
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 ` Phil Sutter [this message]
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=1456944343-19058-3-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).