From: Russell Stuart <russell-lartc@stuart.id.au>
To: netdev@vger.kernel.org, lartc@mailman.ds9a.nl, shemminger@osdl.org
Subject: [PATCH] TC: bug fixes to the "sample" clause
Date: Fri, 10 Feb 2006 12:33:26 +1000 [thread overview]
Message-ID: <1139538806.15476.33.camel@ras> (raw)
PATCH 1
=======
On my machine tc does not parse filter "sample" for the u32
filter. Eg:
tc filter add dev eth2 parent 1:0 protocol ip prio 1 u32 ht 801: \
classid 1:3 \
sample ip protocol 1 0xff match ip protocol 1 0xff
Illegal "sample"
The reason is a missing memset. This patch fixes it.
diff -Nur iproute-20051007.keep/tc/f_u32.c iproute-20051007/tc/f_u32.c
--- iproute-20051007.keep/tc/f_u32.c 2005-01-19 08:11:58.000000000 +1000
+++ iproute-20051007/tc/f_u32.c 2006-01-12 17:12:43.000000000 +1000
@@ -878,6 +878,7 @@
struct tc_u32_sel sel;
struct tc_u32_key keys[4];
} sel2;
+ memset(&sel2, 0, sizeof(sel2));
NEXT_ARG();
if (parse_selector(&argc, &argv, &sel2.sel, n)) {
fprintf(stderr, "Illegal \"sample\"\n");
PATCH 2
=======
In tc, the u32 sample clause uses the 2.4 hashing algorithm.
The hashing algorithm used by the kernel changed in 2.6,
consequently "sample" hasn't work since then.
This patch makes the sample clause work for both 2.4 and 2.6:
diff -Nur iproute-20051007.keep/tc/f_u32.c iproute-20051007/tc/f_u32.c
--- iproute-20051007.keep/tc/f_u32.c 2006-01-12 17:34:37.000000000 +1000
+++ iproute-20051007/tc/f_u32.c 2006-02-07 17:10:29.000000000 +1000
@@ -17,6 +17,7 @@
#include <syslog.h>
#include <fcntl.h>
#include <sys/socket.h>
+#include <sys/utsname.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <string.h>
@@ -874,6 +875,7 @@
htid = (handle&0xFFFFF000);
} else if (strcmp(*argv, "sample") == 0) {
__u32 hash;
+ struct utsname utsname;
struct {
struct tc_u32_sel sel;
struct tc_u32_key keys[4];
@@ -889,8 +891,19 @@
return -1;
}
hash = sel2.sel.keys[0].val&sel2.sel.keys[0].mask;
- hash ^= hash>>16;
- hash ^= hash>>8;
+ uname(&utsname);
+ if (strncmp(utsname.release, "2.4.", 4) == 0) {
+ hash ^= hash>>16;
+ hash ^= hash>>8;
+ }
+ else {
+ __u32 mask = sel2.sel.keys[0].mask;
+ while (mask && !(mask & 1)) {
+ mask >>= 1;
+ hash >>= 1;
+ }
+ hash &= 0xFF;
+ }
htid = ((hash<<12)&0xFF000)|(htid&0xFFF00000);
sample_ok = 1;
continue;
PATCH 3
=======
"tc" does not allow you to specify the divisor for the
"sample" clause, it always assumes a divisor of 256.
If the divisor isn't 256, (ie it is something less),
the kernel will usually whinge because the bucket given
to it by "tc" is typically too big.
This patch adds a "divisor" option to tc's "sample"
clause:
diff -Nur iproute-20051007.keep/tc/f_u32.c iproute-20051007/tc/f_u32.c
--- iproute-20051007.keep/tc/f_u32.c 2006-02-10 11:40:16.000000000 +1000
+++ iproute-20051007/tc/f_u32.c 2006-02-10 11:47:14.000000000 +1000
@@ -35,7 +35,7 @@
fprintf(stderr, "or u32 divisor DIVISOR\n");
fprintf(stderr, "\n");
fprintf(stderr, "Where: SELECTOR := SAMPLE SAMPLE ...\n");
- fprintf(stderr, " SAMPLE := { ip | ip6 | udp | tcp | icmp | u{32|16|8} | mark } SAMPLE_ARGS\n");
+ fprintf(stderr, " SAMPLE := { ip | ip6 | udp | tcp | icmp | u{32|16|8} | mark } SAMPLE_ARGS [divisor DIVISOR]\n");
fprintf(stderr, " FILTERID := X:Y:Z\n");
}
@@ -835,7 +835,7 @@
unsigned divisor;
NEXT_ARG();
if (get_unsigned(&divisor, *argv, 0) || divisor == 0 ||
- divisor > 0x100) {
+ divisor > 0x100 || (divisor - 1 & divisor)) {
fprintf(stderr, "Illegal \"divisor\"\n");
return -1;
}
@@ -875,6 +875,7 @@
htid = (handle&0xFFFFF000);
} else if (strcmp(*argv, "sample") == 0) {
__u32 hash;
+ unsigned divisor = 0x100;
struct utsname utsname;
struct {
struct tc_u32_sel sel;
@@ -890,6 +891,15 @@
fprintf(stderr, "\"sample\" must contain exactly ONE key.\n");
return -1;
}
+ if (*argv != 0 && strcmp(*argv, "divisor") == 0) {
+ NEXT_ARG();
+ if (get_unsigned(&divisor, *argv, 0) || divisor == 0 ||
+ divisor > 0x100 || (divisor - 1 & divisor)) {
+ fprintf(stderr, "Illegal sample \"divisor\"\n");
+ return -1;
+ }
+ NEXT_ARG();
+ }
hash = sel2.sel.keys[0].val&sel2.sel.keys[0].mask;
uname(&utsname);
if (strncmp(utsname.release, "2.4.", 4) == 0) {
@@ -904,7 +913,7 @@
}
hash &= 0xFF;
}
- htid = ((hash<<12)&0xFF000)|(htid&0xFFF00000);
+ htid = ((hash%divisor)<<12)|(htid&0xFFF00000);
sample_ok = 1;
continue;
} else if (strcmp(*argv, "indev") == 0) {
next reply other threads:[~2006-02-10 2:33 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2006-02-10 2:33 Russell Stuart [this message]
[not found] ` <1142082696.5184.53.camel@jzny2>
2006-03-13 4:44 ` [PATCH] TC: bug fixes to the "sample" clause Russell Stuart
[not found] ` <1142269090.5242.29.camel@jzny2>
2006-03-13 17:55 ` Patrick McHardy
2006-03-13 18:04 ` Stephen Hemminger
2006-03-13 18:15 ` Patrick McHardy
2006-03-13 19:02 ` Patrick McHardy
2006-03-13 21:43 ` Russell Stuart
2006-03-13 21:50 ` Stephen Hemminger
2006-03-14 0:31 ` Russell Stuart
[not found] ` <1142303082.5219.16.camel@jzny2>
[not found] ` <1142306212.17608.178.camel@ras.pc.brisbane.lube>
[not found] ` <1142307572.5219.73.camel@jzny2>
[not found] ` <1142312708.17608.270.camel@ras.pc.brisbane.lube>
[not found] ` <1142436098.5346.3.camel@jzny2>
[not found] ` <1142470323.17608.341.camel@ras.pc.brisbane.lube>
[not found] ` <20060315165757.44bf1548@localhost.localdomain>
2006-03-16 1:43 ` Russell Stuart
[not found] ` <1142472481.5417.20.camel@jzny2>
[not found] ` <1142476647.17608.394.camel@ras.pc.brisbane.lube>
[not found] ` <1142478478.5417.46.camel@jzny2>
[not found] ` <1142488027.17608.485.camel@ras.pc.brisbane.lube>
[not found] ` <1142517116.5417.137.camel@jzny2>
2006-03-16 23:24 ` Russell Stuart
[not found] ` <1142606049.5322.89.camel@jzny2>
2006-03-18 5:10 ` Russell Stuart
2006-03-20 3:11 ` Russell Stuart
2006-03-14 2:29 ` Russell Stuart
[not found] ` <1142085718.5184.73.camel@jzny2>
[not found] ` <1142088594.4199.115.camel@ras.pc.stuart.local>
[not found] ` <1142092598.5184.93.camel@jzny2>
2006-03-14 2:45 ` Russell Stuart
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=1139538806.15476.33.camel@ras \
--to=russell-lartc@stuart.id.au \
--cc=lartc@mailman.ds9a.nl \
--cc=netdev@vger.kernel.org \
--cc=shemminger@osdl.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 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).