diff --git a/bpf_image.c b/bpf_image.c index 3e9a23f..0b9e0b9 100644 --- a/bpf_image.c +++ b/bpf_image.c @@ -305,6 +305,17 @@ bpf_image(p, n) op = "txa"; fmt = ""; break; + + case BPF_MISC|BPF_COP: + op = "cop"; + fmt = "#%d"; + break; + + case BPF_MISC|BPF_COPX: + op = "copx"; + fmt = "x"; + break; + } (void)snprintf(operand, sizeof operand, fmt, v); if (BPF_CLASS(p->code) == BPF_JMP && BPF_OP(p->code) != BPF_JA) { diff --git a/gencode.c b/gencode.c index aefd38b..ef343cb 100644 --- a/gencode.c +++ b/gencode.c @@ -7333,6 +7333,26 @@ gen_byteop(op, idx, val) return b; } +struct block * +gen_cop(accum, idx, ret) + int accum, idx, ret; +{ + struct slist *s1, *s2; + struct block *b; + + s1 = new_stmt(BPF_LD|BPF_IMM); + s1->s.k = accum; + + s2 = new_stmt(BPF_MISC|BPF_COP); + s2->s.k = idx; + sappend(s1, s2); + + b = new_block(JMP(BPF_JEQ)); + b->stmts = s1; + b->s.k = ret; + return b; +} + static u_char abroadcast[] = { 0x0 }; struct block * diff --git a/gencode.h b/gencode.h index e6b3a71..9e1132d 100644 --- a/gencode.h +++ b/gencode.h @@ -304,6 +304,7 @@ struct block *gen_relation(int, struct arth *, struct arth *, int); struct block *gen_less(int); struct block *gen_greater(int); struct block *gen_byteop(int, int, int); +struct block *gen_cop(int, int, int); struct block *gen_broadcast(int); struct block *gen_multicast(int); struct block *gen_inbound(int); diff --git a/grammar.y b/grammar.y index b269d27..27af6ce 100644 --- a/grammar.y +++ b/grammar.y @@ -310,6 +310,7 @@ pfaction_to_num(const char *action) %token RADIO %token FISU LSSU MSU HFISU HLSSU HMSU %token SIO OPC DPC SLS HSIO HOPC HDPC HSLS +%token COP %type ID @@ -514,6 +515,7 @@ other: pqual TK_BROADCAST { $$ = gen_broadcast($1); } | LESS NUM { $$ = gen_less($2); } | GREATER NUM { $$ = gen_greater($2); } | CBYTE NUM byteop NUM { $$ = gen_byteop($3, $2, $4); } + | COP NUM NUM NUM { $$ = gen_cop($2, $3, $4); } | INBOUND { $$ = gen_inbound(0); } | OUTBOUND { $$ = gen_inbound(1); } | VLAN pnum { $$ = gen_vlan($2); } diff --git a/optimize.c b/optimize.c index feaf201..8f29990 100644 --- a/optimize.c +++ b/optimize.c @@ -1089,6 +1089,11 @@ opt_stmt(struct stmt *s, int val[], int alter) vstore(s, &val[X_ATOM], val[A_ATOM], alter); break; + case BPF_MISC|BPF_COP: + v = F(s->code, 0L, 0L); + vstore(s, &val[A_ATOM], v, alter); + break; + case BPF_LDX|BPF_MEM: v = val[s->k]; if (alter && vmap[v].is_const) { diff --git a/pcap-filter.manmisc.in b/pcap-filter.manmisc.in index f65a6a9..bdb255b 100644 --- a/pcap-filter.manmisc.in +++ b/pcap-filter.manmisc.in @@ -18,7 +18,7 @@ .\" WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF .\" MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. .\" -.TH PCAP-FILTER @MAN_MISC_INFO@ "17 May 2013" +.TH PCAP-FILTER @MAN_MISC_INFO@ "29 January 2015" .SH NAME pcap-filter \- packet filter syntax .br @@ -796,6 +796,17 @@ Connect Ack, Release, or Release Done message. True if the packet is an ATM packet, for SunATM on Solaris, and is on a meta signaling circuit and is a Q.2931 Setup, Call Proceeding, Connect, Release, or Release Done message. +.IP "\fBcop \fIaccum \fIindex \fIretval\fR" +Sets the accumulator register to +.IR accum +and invokes the BPF coprocessor function given the +.IR index . +True if the value returned by the function matches +.IR retval . +If the coprocessor is not set or the function index is out of range, +then the program will be aborted. +This keyword is applicable only for the custom BPF interpreters which +have the coprocessor support. .IP "\fIexpr relop expr\fR" True if the relation holds, where \fIrelop\fR is one of >, <, >=, <=, =, !=, and \fIexpr\fR is an arithmetic expression composed of integer diff --git a/pcap-int.h b/pcap-int.h index 2f71e11..470caf9 100644 --- a/pcap-int.h +++ b/pcap-int.h @@ -340,6 +340,16 @@ struct oneshot_userdata { int yylex(void); +/* + * NOTE: NetBSD - TBD on exposing + */ +#ifndef BPF_COP +#define BPF_COP 0x20 +#endif +#ifndef BPF_COPX +#define BPF_COPX 0x40 +#endif + #ifndef min #define min(a, b) ((a) > (b) ? (b) : (a)) #endif diff --git a/scanner.l b/scanner.l index a247c99..1083cba 100644 --- a/scanner.l +++ b/scanner.l @@ -295,6 +295,8 @@ vci return VCI; connectmsg return CONNECTMSG; metaconnect return METACONNECT; +cop return COP; + on|ifname return PF_IFNAME; rset|ruleset return PF_RSET; rnr|rulenum return PF_RNR;