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