Home | History | Annotate | Line # | Download | only in npf
npfkern.h revision 1.3
      1  1.1  christos /*-
      2  1.1  christos  * Copyright (c) 2015 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.1  christos 	const char *	(*getname)(struct ifnet *);
     47  1.1  christos 	struct ifnet *	(*lookup)(const char *);
     48  1.1  christos 	void		(*flush)(void *);
     49  1.1  christos 	void *		(*getmeta)(const struct ifnet *);
     50  1.1  christos 	void		(*setmeta)(struct ifnet *, void *);
     51  1.1  christos } npf_ifops_t;
     52  1.1  christos 
     53  1.1  christos typedef struct {
     54  1.1  christos 	struct mbuf *	(*alloc)(int, int);
     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.1  christos } npf_mbufops_t;
     63  1.1  christos 
     64  1.1  christos int	npf_sysinit(unsigned);
     65  1.1  christos void	npf_sysfini(void);
     66  1.1  christos 
     67  1.1  christos npf_t *	npf_create(int, const npf_mbufops_t *, const npf_ifops_t *);
     68  1.1  christos int	npf_load(npf_t *, void *, npf_error_t *);
     69  1.1  christos void	npf_gc(npf_t *);
     70  1.1  christos void	npf_destroy(npf_t *);
     71  1.1  christos 
     72  1.1  christos void	npf_thread_register(npf_t *);
     73  1.2     rmind void	npf_thread_unregister(npf_t *);
     74  1.1  christos int	npf_packet_handler(npf_t *, struct mbuf **, struct ifnet *, int);
     75  1.1  christos void	npf_ifmap_attach(npf_t *, struct ifnet *);
     76  1.1  christos void	npf_ifmap_detach(npf_t *, struct ifnet *);
     77  1.3     rmind int	npf_param_get(npf_t *, const char *, int *);
     78  1.3     rmind int	npf_param_set(npf_t *, const char *, int);
     79  1.1  christos void	npf_stats(npf_t *, uint64_t *);
     80  1.3     rmind void	npf_stats_clear(npf_t *);
     81  1.3     rmind 
     82  1.3     rmind /*
     83  1.3     rmind  * ALGs.
     84  1.3     rmind  */
     85  1.3     rmind 
     86  1.3     rmind int	npf_alg_icmp_init(npf_t *);
     87  1.3     rmind int	npf_alg_icmp_fini(npf_t *);
     88  1.1  christos 
     89  1.1  christos #endif
     90