1153151Sjkim/*-
2181846Sjkim * Copyright (C) 2002-2003 NetGroup, Politecnico di Torino (Italy)
3199492Sjkim * Copyright (C) 2005-2009 Jung-uk Kim <jkim@FreeBSD.org>
4153151Sjkim * All rights reserved.
5153151Sjkim *
6153151Sjkim * Redistribution and use in source and binary forms, with or without
7153151Sjkim * modification, are permitted provided that the following conditions
8153151Sjkim * are met:
9153151Sjkim *
10153151Sjkim * 1. Redistributions of source code must retain the above copyright
11153151Sjkim * notice, this list of conditions and the following disclaimer.
12153151Sjkim * 2. Redistributions in binary form must reproduce the above copyright
13153151Sjkim * notice, this list of conditions and the following disclaimer in the
14153151Sjkim * documentation and/or other materials provided with the distribution.
15153151Sjkim * 3. Neither the name of the Politecnico di Torino nor the names of its
16153151Sjkim * contributors may be used to endorse or promote products derived from
17153151Sjkim * this software without specific prior written permission.
18153151Sjkim *
19153151Sjkim * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20153151Sjkim * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21153151Sjkim * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
22153151Sjkim * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
23153151Sjkim * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
24153151Sjkim * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
25153151Sjkim * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26182173Sjkim * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27153151Sjkim * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28153151Sjkim * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29153151Sjkim * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30153151Sjkim *
31153151Sjkim * $FreeBSD$
32153151Sjkim */
33153151Sjkim
34153151Sjkim#ifndef _NET_BPF_JITTER_H_
35153151Sjkim#define _NET_BPF_JITTER_H_
36153151Sjkim
37181846Sjkim#ifdef _KERNEL
38153151SjkimMALLOC_DECLARE(M_BPFJIT);
39181846Sjkim#endif
40153151Sjkim
41153213Sjkimextern int bpf_jitter_enable;
42153213Sjkim
43153151Sjkim/*
44153151Sjkim * Prototype of a filtering function created by the jitter.
45153151Sjkim *
46153151Sjkim * The syntax and the meaning of the parameters is analogous to the one of
47153151Sjkim * bpf_filter(). Notice that the filter is not among the parameters because
48153151Sjkim * it is hardwired in the function.
49153151Sjkim */
50153151Sjkimtypedef u_int (*bpf_filter_func)(u_char *, u_int, u_int);
51153151Sjkim
52153151Sjkim/* Structure describing a native filtering program created by the jitter. */
53153151Sjkimtypedef struct bpf_jit_filter {
54153151Sjkim	/* The native filtering binary, in the form of a bpf_filter_func. */
55153151Sjkim	bpf_filter_func	func;
56199498Sjkim	size_t		size;
57153151Sjkim} bpf_jit_filter;
58153151Sjkim
59153151Sjkim/*
60153151Sjkim * BPF jitter, builds a machine function from a BPF program.
61153151Sjkim *
62153151Sjkim * param fp	The BPF pseudo-assembly filter that will be translated
63153151Sjkim *		into native code.
64153151Sjkim * param nins	Number of instructions of the input filter.
65153151Sjkim * return	The bpf_jit_filter structure containing the native filtering
66153151Sjkim *		binary.
67153151Sjkim *
68153151Sjkim * bpf_jitter allocates the buffers for the new native filter and
69153151Sjkim * then translates the program pointed by fp calling bpf_jit_compile().
70153151Sjkim */
71153151Sjkimbpf_jit_filter	*bpf_jitter(struct bpf_insn *fp, int nins);
72153151Sjkim
73153151Sjkim/*
74153151Sjkim * Deletes a filtering function that was previously created by bpf_jitter().
75153151Sjkim *
76153151Sjkim * param filter	The filter to destroy.
77153151Sjkim *
78153151Sjkim * This function frees the variuos buffers (code, memory, etc.) associated
79153151Sjkim * with a filtering function.
80153151Sjkim */
81153151Sjkimvoid		bpf_destroy_jit_filter(bpf_jit_filter *filter);
82153151Sjkim
83153151Sjkim#endif	/* _NET_BPF_JITTER_H_ */
84