/*-1* SPDX-License-Identifier: BSD-3-Clause2*3* Copyright (C) 2002-2003 NetGroup, Politecnico di Torino (Italy)4* Copyright (C) 2005-2009 Jung-uk Kim <[email protected]>5* All rights reserved.6*7* Redistribution and use in source and binary forms, with or without8* modification, are permitted provided that the following conditions9* are met:10*11* 1. Redistributions of source code must retain the above copyright12* notice, this list of conditions and the following disclaimer.13* 2. Redistributions in binary form must reproduce the above copyright14* notice, this list of conditions and the following disclaimer in the15* documentation and/or other materials provided with the distribution.16* 3. Neither the name of the Politecnico di Torino nor the names of its17* contributors may be used to endorse or promote products derived from18* this software without specific prior written permission.19*20* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS21* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT22* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR23* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT24* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,25* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT26* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,27* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY28* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT29* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE30* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.31*/3233#ifndef _NET_BPF_JITTER_H_34#define _NET_BPF_JITTER_H_3536#ifdef _KERNEL37MALLOC_DECLARE(M_BPFJIT);38#endif3940extern int bpf_jitter_enable;4142/*43* Prototype of a filtering function created by the jitter.44*45* The syntax and the meaning of the parameters is analogous to the one of46* bpf_filter(). Notice that the filter is not among the parameters because47* it is hardwired in the function.48*/49typedef u_int (*bpf_filter_func)(u_char *, u_int, u_int);5051/* Structure describing a native filtering program created by the jitter. */52typedef struct bpf_jit_filter {53/* The native filtering binary, in the form of a bpf_filter_func. */54bpf_filter_func func;55size_t size;56} bpf_jit_filter;5758/*59* BPF jitter, builds a machine function from a BPF program.60*61* param fp The BPF pseudo-assembly filter that will be translated62* into native code.63* param nins Number of instructions of the input filter.64* return The bpf_jit_filter structure containing the native filtering65* binary.66*67* bpf_jitter allocates the buffers for the new native filter and68* then translates the program pointed by fp calling bpf_jit_compile().69*/70bpf_jit_filter *bpf_jitter(struct bpf_insn *fp, int nins);7172/*73* Deletes a filtering function that was previously created by bpf_jitter().74*75* param filter The filter to destroy.76*77* This function frees the variuos buffers (code, memory, etc.) associated78* with a filtering function.79*/80void bpf_destroy_jit_filter(bpf_jit_filter *filter);8182/*83* Declarations for machine-dependent functions.84*/85struct bpf_insn;8687bpf_filter_func bpf_jit_compile(struct bpf_insn *, u_int, size_t *);8889#endif /* _NET_BPF_JITTER_H_ */909192