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
35 struct mbuf;
36 struct 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
45 typedef 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
53 typedef 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
64 int npf_sysinit(unsigned);
65 void npf_sysfini(void);
66
67 npf_t * npf_create(int, const npf_mbufops_t *, const npf_ifops_t *);
68 int npf_load(npf_t *, void *, npf_error_t *);
69 void npf_gc(npf_t *);
70 void npf_destroy(npf_t *);
71
72 void npf_thread_register(npf_t *);
73 int npf_packet_handler(npf_t *, struct mbuf **, struct ifnet *, int);
74 void npf_ifmap_attach(npf_t *, struct ifnet *);
75 void npf_ifmap_detach(npf_t *, struct ifnet *);
76 void npf_stats(npf_t *, uint64_t *);
77
78 #endif
79