bpf_jitter.h revision 272461
1302876Ssephe/*- 2302876Ssephe * Copyright (C) 2002-2003 NetGroup, Politecnico di Torino (Italy) 3302876Ssephe * Copyright (C) 2005-2009 Jung-uk Kim <jkim@FreeBSD.org> 4302876Ssephe * All rights reserved. 5302876Ssephe * 6302876Ssephe * Redistribution and use in source and binary forms, with or without 7302876Ssephe * modification, are permitted provided that the following conditions 8302876Ssephe * are met: 9302876Ssephe * 10302876Ssephe * 1. Redistributions of source code must retain the above copyright 11302876Ssephe * notice, this list of conditions and the following disclaimer. 12302876Ssephe * 2. Redistributions in binary form must reproduce the above copyright 13302876Ssephe * notice, this list of conditions and the following disclaimer in the 14302876Ssephe * documentation and/or other materials provided with the distribution. 15302876Ssephe * 3. Neither the name of the Politecnico di Torino nor the names of its 16302876Ssephe * contributors may be used to endorse or promote products derived from 17302876Ssephe * this software without specific prior written permission. 18302876Ssephe * 19302876Ssephe * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 20302876Ssephe * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 21302876Ssephe * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 22302876Ssephe * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 23302876Ssephe * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 24302876Ssephe * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 25302876Ssephe * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 26302876Ssephe * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 27302876Ssephe * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 28302876Ssephe * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 29302876Ssephe * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30302876Ssephe * 31302876Ssephe * $FreeBSD: releng/10.1/sys/net/bpf_jitter.h 199603 2009-11-20 18:49:20Z jkim $ 32302876Ssephe */ 33302876Ssephe 34307455Ssephe#ifndef _NET_BPF_JITTER_H_ 35307455Ssephe#define _NET_BPF_JITTER_H_ 36307455Ssephe 37307455Ssephe#ifdef _KERNEL 38307455SsepheMALLOC_DECLARE(M_BPFJIT); 39307455Ssephe#endif 40307455Ssephe 41307455Ssepheextern int bpf_jitter_enable; 42307455Ssephe 43302876Ssephe/* 44302876Ssephe * Prototype of a filtering function created by the jitter. 45302876Ssephe * 46302876Ssephe * The syntax and the meaning of the parameters is analogous to the one of 47302876Ssephe * bpf_filter(). Notice that the filter is not among the parameters because 48302876Ssephe * it is hardwired in the function. 49302876Ssephe */ 50307455Ssephetypedef u_int (*bpf_filter_func)(u_char *, u_int, u_int); 51307455Ssephe 52307455Ssephe/* Structure describing a native filtering program created by the jitter. */ 53307455Ssephetypedef struct bpf_jit_filter { 54302876Ssephe /* The native filtering binary, in the form of a bpf_filter_func. */ 55307455Ssephe bpf_filter_func func; 56307455Ssephe size_t size; 57307455Ssephe} bpf_jit_filter; 58307455Ssephe 59307455Ssephe/* 60302876Ssephe * BPF jitter, builds a machine function from a BPF program. 61302876Ssephe * 62307456Ssephe * param fp The BPF pseudo-assembly filter that will be translated 63307456Ssephe * into native code. 64302876Ssephe * param nins Number of instructions of the input filter. 65302876Ssephe * return The bpf_jit_filter structure containing the native filtering 66302876Ssephe * binary. 67307455Ssephe * 68307455Ssephe * bpf_jitter allocates the buffers for the new native filter and 69307455Ssephe * then translates the program pointed by fp calling bpf_jit_compile(). 70302876Ssephe */ 71302876Ssephebpf_jit_filter *bpf_jitter(struct bpf_insn *fp, int nins); 72 73/* 74 * Deletes a filtering function that was previously created by bpf_jitter(). 75 * 76 * param filter The filter to destroy. 77 * 78 * This function frees the variuos buffers (code, memory, etc.) associated 79 * with a filtering function. 80 */ 81void bpf_destroy_jit_filter(bpf_jit_filter *filter); 82 83#endif /* _NET_BPF_JITTER_H_ */ 84