| From: |
| Thomas Graf <tgraf@suug.ch> |
| To: |
| davem@davemloft.net |
| Subject: |
| [PATCHSET] Textsearch infrastructure/ematch and zerocopy skb data reading |
| Date: |
| Thu, 23 Jun 2005 15:45:58 +0200 |
| Cc: |
| netdev@vger.kernel.org, hadi@cyberus.ca, pablo@eurodev.net |
Dave,
This patchset implements packet classification based on
textsearch. It introduces various new APIs also useable
by other subsystems.
o Generic textsearch infastructure including an implemention
of Knuth-Morris-Pratt and a finite state machine based
regular expressions alike algorithm.
o Zerocopy sequential reading of skb data
o skb_find_text(), combination of the textsearch infrastructure
and the zerocopy sequential reading of skb data.
o The actual textsearch ematch based on skb_find_text().
I gave it some testing (see results below) except for
the seq reading of non-linear skbs. I have to get a SG
capable NIC first to do some real tests.
I guess the zerocopy stuff should be quite useful for the
netfilter folks as well, at least making the nbyte ematch
aware of non-linear skbs will be easy.
Test 1: KMP
const char *pattern = "chicken";
const char *d = "We dance the funky chicken, chicken, chicken";
conf = textsearch_prepare("kmp", pattern, strlen(pattern),
GFP_KERNEL, TS_AUTOLOAD);
for (pos = textsearch_find_continuous(conf, &state, d, strlen(d));
pos != UINT_MAX; pos = textsearch_next(conf, &state))
printk("Oh my good, dancing chickens at %d\n", pos);
textsearch_destroy(conf);
[ 485.534457] Oh my good, dancing chickens at 19
[ 485.534460] Oh my good, dancing chickens at 28
[ 485.534462] Oh my good, dancing chickens at 37
Test 2: FSM
struct ts_fsm_token pattern[] = {
{
.type = TS_FSM_WILDCARD,
.recur = TS_FSM_HEAD_IGNORE,
},
{
.type = TS_FSM_SPECIFIC,
.recur = TS_FSM_SINGLE,
.value = 'c',
},
{
.type = TS_FSM_SPECIFIC,
.recur = TS_FSM_PERHAPS,
.value = 'k',
},
{
.type = TS_FSM_SPECIFIC,
.recur = TS_FSM_SINGLE,
.value = 'e',
},
{
.type = TS_FSM_WILDCARD,
.recur = TS_FSM_ANY,
},
};
const char *d = "We dance the funky chicken, chicken, chicken";
conf = textsearch_prepare("fsm", pattern, sizeof(pattern),
GFP_KERNEL, TS_AUTOLOAD);
for (pos = textsearch_find_continuous(conf, &state, d, strlen(d));
pos != UINT_MAX; pos = textsearch_next(conf, &state))
printk("Oh my good, dancing chickens at %d\n", pos);
textsearch_destroy(conf);
[ 682.908463] Oh my good, dancing chickens at 6
[ 682.908465] Oh my good, dancing chickens at 22
[ 682.908467] Oh my good, dancing chickens at 31
[ 682.908470] Oh my good, dancing chickens at 40
Test 3: text ematch
DEV="lo"
TC="/home/tgr/dev/iproute2/iproute2-ss050607/tc/tc"
$TC qdisc del dev $DEV root >/dev/null 2>&1
# cbq:root
$TC qdisc add dev $DEV root handle 10:10 cbq \
bandwidth 100Mbit avpkt 1400 mpu 64
# cbq:c:icmp
$TC class add dev $DEV parent 10:0 classid 10:12 cbq \
bandwidth 100mbit rate 100mbit allot 1514 \
prio 3 maxburst 1 avpkt 500 bounded
# cbq:c:test
$TC class add dev $DEV parent 10:12 classid 10:13 cbq \
bandwidth 100mbit rate 100mbit allot 1514 \
prio 3 maxburst 1 avpkt 500 bounded
# leaf
$TC qdisc add dev $DEV parent 10:13 bfifo
# icmp -> 10:12
$TC filter add dev $DEV parent 10:0 prio 10 protocol ip u32 \
match ip protocol 1 0xff classid 10:12
# "foobar" within first 200 octets -> 10:13
$TC filter add dev $DEV parent 10:12 prio 10 protocol ip basic \
match 'text(kmp foobar from 0 to 200)' flowid 10:13
$TC filter list dev $DEV parent 10:12
ping -c 5 localhost
# send 5 echo requests with payload "foobar"
ping -c 5 -p 666f6f626172 localhost
$TC -s class list dev eth0 parent 10:0
filter protocol ip pref 10 basic
filter protocol ip pref 10 basic handle 0x1 flowid 10:13
text(kmp 66 6f 6f 62 61 72 "foobar" from 0 layer 1 to 200 layer 1)
PING localhost.localdomain (127.0.0.1) 56(84) bytes of data.
[...]
PATTERN: 0x666f6f626172
PING localhost.localdomain (127.0.0.1) 56(84) bytes of data.
[...]
class cbq 10:13 parent 10:12 leaf 8002: rate 100000Kbit (bounded) prio 3
Sent 490 bytes 5 pkt (dropped 0, overlimits 0 requeues 0)
^^^^^^^^^^^^^^^^^^^^
5 classified packets
class cbq 10:12 parent 10: rate 100000Kbit (bounded) prio 3
Sent 980 bytes 10 pkt (dropped 0, overlimits 0 requeues 0)
^^^^^^^^^^^^^^^^^^^^^
5 classified + 5 unclassified packets
-
To unsubscribe from this list: send the line "unsubscribe netdev" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html