summaryrefslogtreecommitdiffstats
path: root/contrib/libpcap/optimize.c
diff options
context:
space:
mode:
authorfenner <fenner@FreeBSD.org>2000-01-30 00:32:56 +0000
committerfenner <fenner@FreeBSD.org>2000-01-30 00:32:56 +0000
commitaae9bd2bccda7ddbeb438e8238ced9c4cd1e9d1d (patch)
treed7ccf2b8332af627d9692b32089580fd3967581f /contrib/libpcap/optimize.c
parentca0d84cb8bfc8789fd48ada56322a575c4a1aa68 (diff)
downloadFreeBSD-src-aae9bd2bccda7ddbeb438e8238ced9c4cd1e9d1d.zip
FreeBSD-src-aae9bd2bccda7ddbeb438e8238ced9c4cd1e9d1d.tar.gz
Virgin import of tcpdump.org libpcap v0.5
Diffstat (limited to 'contrib/libpcap/optimize.c')
-rw-r--r--contrib/libpcap/optimize.c88
1 files changed, 87 insertions, 1 deletions
diff --git a/contrib/libpcap/optimize.c b/contrib/libpcap/optimize.c
index f711417..928cc1c 100644
--- a/contrib/libpcap/optimize.c
+++ b/contrib/libpcap/optimize.c
@@ -22,7 +22,7 @@
*/
#ifndef lint
static const char rcsid[] =
- "@(#) $Header: optimize.c,v 1.60 96/09/26 23:28:14 leres Exp $ (LBL)";
+ "@(#) $Header: /tcpdump/master/libpcap/optimize.c,v 1.61 1999/10/19 15:18:30 itojun Exp $ (LBL)";
#endif
#include <sys/types.h>
@@ -1104,6 +1104,14 @@ opt_blk(b, do_stmts)
int i;
bpf_int32 aval;
+#if 0
+ for (s = b->stmts; s && s->next; s = s->next)
+ if (BPF_CLASS(s->s.code) == BPF_JMP) {
+ do_stmts = 0;
+ break;
+ }
+#endif
+
/*
* Initialize the atom values.
* If we have no predecessors, everything is undefined.
@@ -1886,6 +1894,7 @@ convert_code_r(p)
int slen;
u_int off;
int extrajmps; /* number of extra jumps inserted */
+ struct slist **offset = NULL;
if (p == 0 || isMarked(p))
return (1);
@@ -1902,13 +1911,90 @@ convert_code_r(p)
p->offset = dst - fstart;
+ /* generate offset[] for convenience */
+ if (slen) {
+ offset = (struct slist **)calloc(sizeof(struct slist *), slen);
+ if (!offset) {
+ bpf_error("not enough core");
+ /*NOTREACHED*/
+ }
+ }
+ src = p->stmts;
+ for (off = 0; off < slen && src; off++) {
+#if 0
+ printf("off=%d src=%x\n", off, src);
+#endif
+ offset[off] = src;
+ src = src->next;
+ }
+
+ off = 0;
for (src = p->stmts; src; src = src->next) {
if (src->s.code == NOP)
continue;
dst->code = (u_short)src->s.code;
dst->k = src->s.k;
+
+ /* fill block-local relative jump */
+ if (BPF_CLASS(src->s.code) != BPF_JMP || src->s.code == BPF_JMP|BPF_JA) {
+#if 0
+ if (src->s.jt || src->s.jf) {
+ bpf_error("illegal jmp destination");
+ /*NOTREACHED*/
+ }
+#endif
+ goto filled;
+ }
+ if (off == slen - 2) /*???*/
+ goto filled;
+
+ {
+ int i;
+ int jt, jf;
+ char *ljerr = "%s for block-local relative jump: off=%d";
+
+#if 0
+ printf("code=%x off=%d %x %x\n", src->s.code,
+ off, src->s.jt, src->s.jf);
+#endif
+
+ if (!src->s.jt || !src->s.jf) {
+ bpf_error(ljerr, "no jmp destination", off);
+ /*NOTREACHED*/
+ }
+
+ jt = jf = 0;
+ for (i = 0; i < slen; i++) {
+ if (offset[i] == src->s.jt) {
+ if (jt) {
+ bpf_error(ljerr, "multiple matches", off);
+ /*NOTREACHED*/
+ }
+
+ dst->jt = i - off - 1;
+ jt++;
+ }
+ if (offset[i] == src->s.jf) {
+ if (jf) {
+ bpf_error(ljerr, "multiple matches", off);
+ /*NOTREACHED*/
+ }
+ dst->jf = i - off - 1;
+ jf++;
+ }
+ }
+ if (!jt || !jf) {
+ bpf_error(ljerr, "no destination found", off);
+ /*NOTREACHED*/
+ }
+ }
+filled:
++dst;
+ ++off;
}
+ if (offset)
+ free(offset);
+
#ifdef BDEBUG
bids[dst - fstart] = p->id + 1;
#endif
OpenPOWER on IntegriCloud