npfkern.h revision 1.1
1/*- 2 * Copyright (c) 2015 Mindaugas Rasiukevicius <rmind at netbsd org> 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright 9 * notice, this list of conditions and the following disclaimer. 10 * 2. Redistributions in binary form must reproduce the above copyright 11 * notice, this list of conditions and the following disclaimer in the 12 * documentation and/or other materials provided with the distribution. 13 * 14 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 15 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 17 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 24 * SUCH DAMAGE. 25 */ 26 27#ifndef _NPFKERN_H_ 28#define _NPFKERN_H_ 29 30#ifndef _KERNEL 31#include <stdbool.h> 32#include <inttypes.h> 33#endif 34 35struct mbuf; 36struct ifnet; 37 38#if defined(_NPF_STANDALONE) || !defined(__NetBSD__) 39#define PFIL_IN 0x00000001 // incoming packet 40#define PFIL_OUT 0x00000002 // outgoing packet 41#endif 42 43#define NPF_NO_GC 0x01 44 45typedef struct { 46 const char * (*getname)(struct ifnet *); 47 struct ifnet * (*lookup)(const char *); 48 void (*flush)(void *); 49 void * (*getmeta)(const struct ifnet *); 50 void (*setmeta)(struct ifnet *, void *); 51} npf_ifops_t; 52 53typedef struct { 54 struct mbuf * (*alloc)(int, int); 55 void (*free)(struct mbuf *); 56 void * (*getdata)(const struct mbuf *); 57 struct mbuf * (*getnext)(struct mbuf *); 58 size_t (*getlen)(const struct mbuf *); 59 size_t (*getchainlen)(const struct mbuf *); 60 bool (*ensure_contig)(struct mbuf **, size_t); 61 bool (*ensure_writable)(struct mbuf **, size_t); 62} npf_mbufops_t; 63 64int npf_sysinit(unsigned); 65void npf_sysfini(void); 66 67npf_t * npf_create(int, const npf_mbufops_t *, const npf_ifops_t *); 68int npf_load(npf_t *, void *, npf_error_t *); 69void npf_gc(npf_t *); 70void npf_destroy(npf_t *); 71 72void npf_thread_register(npf_t *); 73int npf_packet_handler(npf_t *, struct mbuf **, struct ifnet *, int); 74void npf_ifmap_attach(npf_t *, struct ifnet *); 75void npf_ifmap_detach(npf_t *, struct ifnet *); 76void npf_stats(npf_t *, uint64_t *); 77 78#endif 79