1 /*- 2 * Copyright (c) 2015-2020 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)(npf_t *, struct ifnet *); 47 struct ifnet * (*lookup)(npf_t *, const char *); 48 void (*flush)(npf_t *, void *); 49 void * (*getmeta)(npf_t *, const struct ifnet *); 50 void (*setmeta)(npf_t *, struct ifnet *, void *); 51 } npf_ifops_t; 52 53 typedef struct { 54 struct mbuf * (*alloc)(npf_t *, unsigned, size_t); 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 int (*get_tag)(const struct mbuf *, uint32_t *); 63 int (*set_tag)(struct mbuf *, uint32_t); 64 } npf_mbufops_t; 65 66 int npfk_sysinit(unsigned); 67 void npfk_sysfini(void); 68 69 npf_t * npfk_create(int, const npf_mbufops_t *, const npf_ifops_t *, void *); 70 int npfk_load(npf_t *, const void *, npf_error_t *); 71 int npfk_socket_load(npf_t *, int); 72 void npfk_gc(npf_t *); 73 void npfk_destroy(npf_t *); 74 void * npfk_getarg(npf_t *); 75 76 void npfk_thread_register(npf_t *); 77 void npfk_thread_unregister(npf_t *); 78 79 int npfk_packet_handler(npf_t *, struct mbuf **, struct ifnet *, int); 80 81 void npfk_ifmap_attach(npf_t *, struct ifnet *); 82 void npfk_ifmap_detach(npf_t *, struct ifnet *); 83 84 int npfk_param_get(npf_t *, const char *, int *); 85 int npfk_param_set(npf_t *, const char *, int); 86 87 void npfk_stats(npf_t *, uint64_t *); 88 void npfk_stats_clear(npf_t *); 89 90 /* 91 * Extensions. 92 */ 93 94 int npf_ext_log_init(npf_t *); 95 int npf_ext_log_fini(npf_t *); 96 97 int npf_ext_normalize_init(npf_t *); 98 int npf_ext_normalize_fini(npf_t *); 99 100 int npf_ext_rndblock_init(npf_t *); 101 int npf_ext_rndblock_fini(npf_t *); 102 103 /* 104 * ALGs. 105 */ 106 107 int npf_alg_icmp_init(npf_t *); 108 int npf_alg_icmp_fini(npf_t *); 109 110 int npf_alg_pptp_init(npf_t *); 111 int npf_alg_pptp_fini(npf_t *); 112 113 #endif 114