xref: /freebsd/sys/netpfil/ipfw/nptv6/nptv6.h (revision 273c26a3c3bea87a241d6879abd4f991db180bf0)
1 /*-
2  * Copyright (c) 2016 Yandex LLC
3  * Copyright (c) 2016 Andrey V. Elsukov <ae@FreeBSD.org>
4  * All rights reserved.
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions
8  * are met:
9  *
10  * 1. Redistributions of source code must retain the above copyright
11  *    notice, this list of conditions and the following disclaimer.
12  * 2. Redistributions in binary form must reproduce the above copyright
13  *    notice, this list of conditions and the following disclaimer in the
14  *    documentation and/or other materials provided with the distribution.
15  *
16  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
17  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
18  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
19  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
20  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
21  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
22  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
23  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
25  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26  *
27  * $FreeBSD$
28  */
29 
30 #ifndef	_IP_FW_NPTV6_H_
31 #define	_IP_FW_NPTV6_H_
32 
33 #include <netinet6/ip_fw_nptv6.h>
34 
35 #ifdef _KERNEL
36 #define	NPTV6STATS	(sizeof(struct ipfw_nptv6_stats) / sizeof(uint64_t))
37 #define	NPTV6STAT_ADD(c, f, v)		\
38     counter_u64_add((c)->stats[		\
39 	offsetof(struct ipfw_nptv6_stats, f) / sizeof(uint64_t)], (v))
40 #define	NPTV6STAT_INC(c, f)	NPTV6STAT_ADD(c, f, 1)
41 #define	NPTV6STAT_FETCH(c, f)		\
42     counter_u64_fetch((c)->stats[	\
43 	offsetof(struct ipfw_nptv6_stats, f) / sizeof(uint64_t)])
44 
45 struct nptv6_cfg {
46 	struct named_object	no;
47 
48 	struct in6_addr		internal;   /* Internal IPv6 prefix */
49 	struct in6_addr		external;   /* External IPv6 prefix */
50 	struct in6_addr		mask;	    /* IPv6 prefix mask */
51 	uint16_t		adjustment; /* Checksum adjustment value */
52 	uint8_t			plen;	    /* Prefix length */
53 	uint8_t			flags;	    /* Flags for internal use */
54 #define	NPTV6_48PLEN		0x0001
55 	char			name[64];   /* Instance name */
56 	counter_u64_t		stats[NPTV6STATS]; /* Statistics counters */
57 };
58 #define	NPTV6_FLAGSMASK		0
59 
60 int nptv6_init(struct ip_fw_chain *ch, int first);
61 void nptv6_uninit(struct ip_fw_chain *ch, int last);
62 #endif /* _KERNEL */
63 
64 #endif /* _IP_FW_NPTV6_H_ */
65 
66