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