diff options
author | 2002-06-07 18:05:20 +0000 | |
---|---|---|
committer | 2002-06-07 18:05:20 +0000 | |
commit | f8266386a259713338a7b3ed9d43a74f70d10107 (patch) | |
tree | 86cee5fc75631cfb68d444eba67961ac7c6dae0f | |
parent | Switch powerpc to using new split (aout/elf) link.h (diff) | |
download | wireguard-openbsd-f8266386a259713338a7b3ed9d43a74f70d10107.tar.xz wireguard-openbsd-f8266386a259713338a7b3ed9d43a74f70d10107.zip |
use profiling to order filter lists more optimally.
-rw-r--r-- | bin/systrace/filter.c | 21 | ||||
-rw-r--r-- | bin/systrace/systrace.h | 3 |
2 files changed, 19 insertions, 5 deletions
diff --git a/bin/systrace/filter.c b/bin/systrace/filter.c index 8401e7c3f6e..fe4f49a733c 100644 --- a/bin/systrace/filter.c +++ b/bin/systrace/filter.c @@ -1,4 +1,4 @@ -/* $OpenBSD: filter.c,v 1.8 2002/06/06 01:05:57 provos Exp $ */ +/* $OpenBSD: filter.c,v 1.9 2002/06/07 18:05:20 provos Exp $ */ /* * Copyright 2002 Niels Provos <provos@citi.umich.edu> * All rights reserved. @@ -96,17 +96,30 @@ filter_match(struct intercept_tlq *tls, struct logic *logic) short filter_evaluate(struct intercept_tlq *tls, struct filterq *fls, int *pflags) { - struct filter *filter; - short action; + struct filter *filter, *last = NULL; + short action, laction = 0; TAILQ_FOREACH(filter, fls, next) { + action = filter->match_action; + if (filter_match(tls, filter->logicroot)) { - action = filter->match_action; + /* Profile feedback optimization */ + filter->match_count++; + if (last != NULL && last->match_action == action && + filter->match_count > last->match_count) { + TAILQ_REMOVE(fls, last, next); + TAILQ_INSERT_AFTER(fls, filter, last, next); + } + if (action == ICPOLICY_NEVER) action = filter->match_error; *pflags = filter->match_flags; return (action); } + + /* Keep track of last processed filtered in a group */ + last = filter; + laction = action; } return (ICPOLICY_ASK); diff --git a/bin/systrace/systrace.h b/bin/systrace/systrace.h index b00a5523c4e..18d25cbad58 100644 --- a/bin/systrace/systrace.h +++ b/bin/systrace/systrace.h @@ -1,4 +1,4 @@ -/* $OpenBSD: systrace.h,v 1.4 2002/06/04 22:45:25 provos Exp $ */ +/* $OpenBSD: systrace.h,v 1.5 2002/06/07 18:05:20 provos Exp $ */ /* * Copyright 2002 Niels Provos <provos@citi.umich.edu> * All rights reserved. @@ -59,6 +59,7 @@ struct filter { short match_action; int match_error; int match_flags; + int match_count; /* Number of times this filter matched */ }; TAILQ_HEAD(filterq, filter); |