96e7e4cb44abd782c070aabd2f79aadae36a45a5
3 * Politecnico di Torino. All rights reserved.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that: (1) source code distributions
7 * retain the above copyright notice and this paragraph in its entirety, (2)
8 * distributions including binary code include the above copyright notice and
9 * this paragraph in its entirety in the documentation or other materials
10 * provided with the distribution, and (3) all advertising materials mentioning
11 * features or use of this software display the following acknowledgement:
12 * ``This product includes software developed by the Politecnico
13 * di Torino, and its contributors.'' Neither the name of
14 * the University nor the names of its contributors may be used to endorse
15 * or promote products derived from this software without specific prior
17 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
18 * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
19 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
23 * Portions copyright (c) 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997
24 * The Regents of the University of California. All rights reserved.
26 * This code is derived from the Stanford/CMU enet packet filter,
27 * (net/enet.c) distributed as part of 4.3BSD, and code contributed
28 * to Berkeley by Steven McCanne and Van Jacobson both of Lawrence
29 * Berkeley Laboratory.
31 * Redistribution and use in source and binary forms, with or without
32 * modification, are permitted provided that the following conditions
34 * 1. Redistributions of source code must retain the above copyright
35 * notice, this list of conditions and the following disclaimer.
36 * 2. Redistributions in binary form must reproduce the above copyright
37 * notice, this list of conditions and the following disclaimer in the
38 * documentation and/or other materials provided with the distribution.
39 * 3. All advertising materials mentioning features or use of this software
40 * must display the following acknowledgement:
41 * This product includes software developed by the University of
42 * California, Berkeley and its contributors.
43 * 4. Neither the name of the University nor the names of its contributors
44 * may be used to endorse or promote products derived from this software
45 * without specific prior written permission.
47 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
48 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
49 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
50 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
51 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
52 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
53 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
54 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
55 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
56 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
64 * Initialize the filter machine
66 uint32
bpf_filter_init(register struct bpf_insn
*pc
, MEM_TYPE
*mem_ex
, TME_CORE
*tme
, struct time_conv
*time_ref
)
69 int32 mem
[BPF_MEMWORDS
];
76 * No filter means accept all.
89 /* RET INSTRUCTIONS */
95 /* END RET INSTRUCTIONS */
97 /* LD NO PACKET INSTRUCTIONS */
102 case BPF_LDX
|BPF_IMM
:
110 case BPF_LDX
|BPF_MEM
:
114 case BPF_LD
|BPF_MEM_EX_IMM
|BPF_B
:
115 A
= mem_ex
->buffer
[pc
->k
];
118 case BPF_LDX
|BPF_MEM_EX_IMM
|BPF_B
:
119 X
= mem_ex
->buffer
[pc
->k
];
122 case BPF_LD
|BPF_MEM_EX_IMM
|BPF_H
:
123 tmp2
=(uint16
*)&mem_ex
->buffer
[pc
->k
];
141 case BPF_LDX
|BPF_MEM_EX_IMM
|BPF_H
:
142 tmp2
=(uint16
*)&mem_ex
->buffer
[pc
->k
];
160 case BPF_LD
|BPF_MEM_EX_IMM
|BPF_W
:
161 tmp
=(uint32
*)&mem_ex
->buffer
[pc
->k
];
178 case BPF_LDX
|BPF_MEM_EX_IMM
|BPF_W
:
179 tmp
=(uint32
*)&mem_ex
->buffer
[pc
->k
];
196 case BPF_LD
|BPF_MEM_EX_IND
|BPF_B
:
198 if ((int32
)k
>= (int32
)mem_ex
->size
) {
201 A
= mem_ex
->buffer
[k
];
204 case BPF_LD
|BPF_MEM_EX_IND
|BPF_H
:
206 if ((int32
)(k
+1)>= (int32
)mem_ex
->size
) {
209 tmp2
=(uint16
*)&mem_ex
->buffer
[k
];
227 case BPF_LD
|BPF_MEM_EX_IND
|BPF_W
:
229 if ((int32
)(k
+3)>= (int32
)mem_ex
->size
) {
232 tmp
=(uint32
*)&mem_ex
->buffer
[k
];
248 /* END LD NO PACKET INSTRUCTIONS */
250 /* STORE INSTRUCTIONS */
259 case BPF_ST
|BPF_MEM_EX_IMM
|BPF_B
:
260 mem_ex
->buffer
[pc
->k
]=(uint8
)A
;
263 case BPF_STX
|BPF_MEM_EX_IMM
|BPF_B
:
264 mem_ex
->buffer
[pc
->k
]=(uint8
)X
;
267 case BPF_ST
|BPF_MEM_EX_IMM
|BPF_W
:
268 tmp
=(uint32
*)&mem_ex
->buffer
[pc
->k
];
285 case BPF_STX
|BPF_MEM_EX_IMM
|BPF_W
:
286 tmp
=(uint32
*)&mem_ex
->buffer
[pc
->k
];
303 case BPF_ST
|BPF_MEM_EX_IMM
|BPF_H
:
304 tmp2
=(uint16
*)&mem_ex
->buffer
[pc
->k
];
321 case BPF_STX
|BPF_MEM_EX_IMM
|BPF_H
:
322 tmp2
=(uint16
*)&mem_ex
->buffer
[pc
->k
];
339 case BPF_ST
|BPF_MEM_EX_IND
|BPF_B
:
340 mem_ex
->buffer
[pc
->k
+X
]=(uint8
)A
;
342 case BPF_ST
|BPF_MEM_EX_IND
|BPF_W
:
343 tmp
=(uint32
*)&mem_ex
->buffer
[pc
->k
+X
];
360 case BPF_ST
|BPF_MEM_EX_IND
|BPF_H
:
361 tmp2
=(uint16
*)&mem_ex
->buffer
[pc
->k
+X
];
377 /* END STORE INSTRUCTIONS */
379 /* JUMP INSTRUCTIONS */
384 case BPF_JMP
|BPF_JGT
|BPF_K
:
385 pc
+= ((int32
)A
> (int32
)pc
->k
) ? pc
->jt
: pc
->jf
;
388 case BPF_JMP
|BPF_JGE
|BPF_K
:
389 pc
+= ((int32
)A
>= (int32
)pc
->k
) ? pc
->jt
: pc
->jf
;
392 case BPF_JMP
|BPF_JEQ
|BPF_K
:
393 pc
+= ((int32
)A
== (int32
)pc
->k
) ? pc
->jt
: pc
->jf
;
396 case BPF_JMP
|BPF_JSET
|BPF_K
:
397 pc
+= (A
& pc
->k
) ? pc
->jt
: pc
->jf
;
400 case BPF_JMP
|BPF_JGT
|BPF_X
:
401 pc
+= (A
> X
) ? pc
->jt
: pc
->jf
;
404 case BPF_JMP
|BPF_JGE
|BPF_X
:
405 pc
+= (A
>= X
) ? pc
->jt
: pc
->jf
;
408 case BPF_JMP
|BPF_JEQ
|BPF_X
:
409 pc
+= (A
== X
) ? pc
->jt
: pc
->jf
;
412 case BPF_JMP
|BPF_JSET
|BPF_X
:
413 pc
+= (A
& X
) ? pc
->jt
: pc
->jf
;
415 /* END JUMP INSTRUCTIONS */
417 /* ARITHMETIC INSTRUCTIONS */
418 case BPF_ALU
|BPF_ADD
|BPF_X
:
422 case BPF_ALU
|BPF_SUB
|BPF_X
:
426 case BPF_ALU
|BPF_MUL
|BPF_X
:
430 case BPF_ALU
|BPF_DIV
|BPF_X
:
436 case BPF_ALU
|BPF_AND
|BPF_X
:
440 case BPF_ALU
|BPF_OR
|BPF_X
:
444 case BPF_ALU
|BPF_LSH
|BPF_X
:
448 case BPF_ALU
|BPF_RSH
|BPF_X
:
452 case BPF_ALU
|BPF_ADD
|BPF_K
:
456 case BPF_ALU
|BPF_SUB
|BPF_K
:
460 case BPF_ALU
|BPF_MUL
|BPF_K
:
464 case BPF_ALU
|BPF_DIV
|BPF_K
:
468 case BPF_ALU
|BPF_AND
|BPF_K
:
472 case BPF_ALU
|BPF_OR
|BPF_K
:
476 case BPF_ALU
|BPF_LSH
|BPF_K
:
480 case BPF_ALU
|BPF_RSH
|BPF_K
:
484 case BPF_ALU
|BPF_NEG
:
485 (int32
)A
= -((int32
)A
);
487 /* ARITHMETIC INSTRUCTIONS */
489 /* MISC INSTRUCTIONS */
490 case BPF_MISC
|BPF_TAX
:
494 case BPF_MISC
|BPF_TXA
:
497 /* END MISC INSTRUCTIONS */
499 /* TME INSTRUCTIONS */
500 case BPF_MISC
|BPF_TME
|BPF_LOOKUP
:
501 j
=lookup_frontend(mem_ex
,tme
,pc
->k
,time_ref
);
504 pc
+= (j
== TME_TRUE
) ? pc
->jt
: pc
->jf
;
507 case BPF_MISC
|BPF_TME
|BPF_EXECUTE
:
508 if (execute_frontend(mem_ex
,tme
,0,pc
->k
)==TME_ERROR
)
512 case BPF_MISC
|BPF_TME
|BPF_INIT
:
513 if (init_tme_block(tme
,pc
->k
)==TME_ERROR
)
517 case BPF_MISC
|BPF_TME
|BPF_VALIDATE
:
518 if (validate_tme_block(mem_ex
,tme
,A
,pc
->k
)==TME_ERROR
)
522 case BPF_MISC
|BPF_TME
|BPF_SET_MEMORY
:
523 if (init_extended_memory(pc
->k
,mem_ex
)==TME_ERROR
)
527 case BPF_MISC
|BPF_TME
|BPF_SET_ACTIVE
:
528 if (set_active_tme_block(tme
,pc
->k
)==TME_ERROR
)
532 case BPF_MISC
|BPF_TME
|BPF_SET_ACTIVE_READ
:
533 if (set_active_tme_block(tme
,pc
->k
)==TME_ERROR
)
536 case BPF_MISC
|BPF_TME
|BPF_SET_WORKING
:
537 if ((pc
->k
<0)||(pc
->k
>=MAX_TME_DATA_BLOCKS
))
544 case BPF_MISC
|BPF_TME
|BPF_RESET
:
545 if (reset_tme(tme
)==TME_ERROR
)
549 case BPF_MISC
|BPF_TME
|BPF_GET_REGISTER_VALUE
:
550 if (get_tme_block_register(&tme
->block_data
[tme
->working
],mem_ex
,pc
->k
,&j
)==TME_ERROR
)
555 case BPF_MISC
|BPF_TME
|BPF_SET_REGISTER_VALUE
:
556 if (set_tme_block_register(&tme
->block_data
[tme
->working
],mem_ex
,pc
->k
,A
,TRUE
)==TME_ERROR
)
560 case BPF_MISC
|BPF_TME
|BPF_SET_AUTODELETION
:
561 set_autodeletion(&tme
->block_data
[tme
->working
],pc
->k
);
564 /* END TME INSTRUCTIONS */