Home | History | Annotate | Line # | Download | only in npf
      1  1.1  christos /*-
      2  1.5     rmind  * Copyright (c) 2015-2020 Mindaugas Rasiukevicius <rmind at netbsd org>
      3  1.1  christos  * All rights reserved.
      4  1.1  christos  *
      5  1.1  christos  * Redistribution and use in source and binary forms, with or without
      6  1.1  christos  * modification, are permitted provided that the following conditions
      7  1.1  christos  * are met:
      8  1.1  christos  * 1. Redistributions of source code must retain the above copyright
      9  1.1  christos  *    notice, this list of conditions and the following disclaimer.
     10  1.1  christos  * 2. Redistributions in binary form must reproduce the above copyright
     11  1.1  christos  *    notice, this list of conditions and the following disclaimer in the
     12  1.1  christos  *    documentation and/or other materials provided with the distribution.
     13  1.1  christos  *
     14  1.1  christos  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
     15  1.1  christos  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     16  1.1  christos  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     17  1.1  christos  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
     18  1.1  christos  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     19  1.1  christos  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     20  1.1  christos  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     21  1.1  christos  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     22  1.1  christos  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     23  1.1  christos  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     24  1.1  christos  * SUCH DAMAGE.
     25  1.1  christos  */
     26  1.1  christos 
     27  1.1  christos #ifndef _NPFKERN_H_
     28  1.1  christos #define _NPFKERN_H_
     29  1.1  christos 
     30  1.1  christos #ifndef _KERNEL
     31  1.1  christos #include <stdbool.h>
     32  1.1  christos #include <inttypes.h>
     33  1.1  christos #endif
     34  1.1  christos 
     35  1.1  christos struct mbuf;
     36  1.1  christos struct ifnet;
     37  1.1  christos 
     38  1.1  christos #if defined(_NPF_STANDALONE) || !defined(__NetBSD__)
     39  1.1  christos #define PFIL_IN		0x00000001	// incoming packet
     40  1.1  christos #define PFIL_OUT	0x00000002	// outgoing packet
     41  1.1  christos #endif
     42  1.1  christos 
     43  1.1  christos #define	NPF_NO_GC	0x01
     44  1.1  christos 
     45  1.1  christos typedef struct {
     46  1.5     rmind 	const char *	(*getname)(npf_t *, struct ifnet *);
     47  1.5     rmind 	struct ifnet *	(*lookup)(npf_t *, const char *);
     48  1.5     rmind 	void		(*flush)(npf_t *, void *);
     49  1.5     rmind 	void *		(*getmeta)(npf_t *, const struct ifnet *);
     50  1.5     rmind 	void		(*setmeta)(npf_t *, struct ifnet *, void *);
     51  1.1  christos } npf_ifops_t;
     52  1.1  christos 
     53  1.1  christos typedef struct {
     54  1.5     rmind 	struct mbuf *	(*alloc)(npf_t *, unsigned, size_t);
     55  1.1  christos 	void		(*free)(struct mbuf *);
     56  1.1  christos 	void *		(*getdata)(const struct mbuf *);
     57  1.1  christos 	struct mbuf *	(*getnext)(struct mbuf *);
     58  1.1  christos 	size_t		(*getlen)(const struct mbuf *);
     59  1.1  christos 	size_t		(*getchainlen)(const struct mbuf *);
     60  1.1  christos 	bool		(*ensure_contig)(struct mbuf **, size_t);
     61  1.1  christos 	bool		(*ensure_writable)(struct mbuf **, size_t);
     62  1.5     rmind 	int		(*get_tag)(const struct mbuf *, uint32_t *);
     63  1.5     rmind 	int		(*set_tag)(struct mbuf *, uint32_t);
     64  1.1  christos } npf_mbufops_t;
     65  1.1  christos 
     66  1.4     rmind int	npfk_sysinit(unsigned);
     67  1.4     rmind void	npfk_sysfini(void);
     68  1.1  christos 
     69  1.5     rmind npf_t *	npfk_create(int, const npf_mbufops_t *, const npf_ifops_t *, void *);
     70  1.5     rmind int	npfk_load(npf_t *, const void *, npf_error_t *);
     71  1.5     rmind int	npfk_socket_load(npf_t *, int);
     72  1.4     rmind void	npfk_gc(npf_t *);
     73  1.4     rmind void	npfk_destroy(npf_t *);
     74  1.5     rmind void *	npfk_getarg(npf_t *);
     75  1.1  christos 
     76  1.4     rmind void	npfk_thread_register(npf_t *);
     77  1.4     rmind void	npfk_thread_unregister(npf_t *);
     78  1.5     rmind 
     79  1.4     rmind int	npfk_packet_handler(npf_t *, struct mbuf **, struct ifnet *, int);
     80  1.6       joe int	npfk_layer2_handler(npf_t *, struct mbuf **, struct ifnet *, int);
     81  1.5     rmind 
     82  1.4     rmind void	npfk_ifmap_attach(npf_t *, struct ifnet *);
     83  1.4     rmind void	npfk_ifmap_detach(npf_t *, struct ifnet *);
     84  1.5     rmind 
     85  1.4     rmind int	npfk_param_get(npf_t *, const char *, int *);
     86  1.4     rmind int	npfk_param_set(npf_t *, const char *, int);
     87  1.5     rmind 
     88  1.4     rmind void	npfk_stats(npf_t *, uint64_t *);
     89  1.4     rmind void	npfk_stats_clear(npf_t *);
     90  1.3     rmind 
     91  1.3     rmind /*
     92  1.5     rmind  * Extensions.
     93  1.5     rmind  */
     94  1.5     rmind 
     95  1.5     rmind int	npf_ext_log_init(npf_t *);
     96  1.5     rmind int	npf_ext_log_fini(npf_t *);
     97  1.5     rmind 
     98  1.5     rmind int	npf_ext_normalize_init(npf_t *);
     99  1.5     rmind int	npf_ext_normalize_fini(npf_t *);
    100  1.5     rmind 
    101  1.5     rmind int	npf_ext_rndblock_init(npf_t *);
    102  1.5     rmind int	npf_ext_rndblock_fini(npf_t *);
    103  1.5     rmind 
    104  1.5     rmind /*
    105  1.3     rmind  * ALGs.
    106  1.3     rmind  */
    107  1.3     rmind 
    108  1.3     rmind int	npf_alg_icmp_init(npf_t *);
    109  1.3     rmind int	npf_alg_icmp_fini(npf_t *);
    110  1.1  christos 
    111  1.5     rmind int	npf_alg_pptp_init(npf_t *);
    112  1.5     rmind int	npf_alg_pptp_fini(npf_t *);
    113  1.5     rmind 
    114  1.1  christos #endif
    115