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