xref: /freebsd/sys/netpfil/ipfw/nptv6/nptv6.h (revision 95ee2897e98f5d444f26ed2334cc7c439f9c16c6)
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 
28 #ifndef	_IP_FW_NPTV6_H_
29 #define	_IP_FW_NPTV6_H_
30 
31 #include <netinet6/ip_fw_nptv6.h>
32 
33 #ifdef _KERNEL
34 #define	NPTV6STATS	(sizeof(struct ipfw_nptv6_stats) / sizeof(uint64_t))
35 #define	NPTV6STAT_ADD(c, f, v)		\
36     counter_u64_add((c)->stats[		\
37 	offsetof(struct ipfw_nptv6_stats, f) / sizeof(uint64_t)], (v))
38 #define	NPTV6STAT_INC(c, f)	NPTV6STAT_ADD(c, f, 1)
39 #define	NPTV6STAT_FETCH(c, f)		\
40     counter_u64_fetch((c)->stats[	\
41 	offsetof(struct ipfw_nptv6_stats, f) / sizeof(uint64_t)])
42 
43 struct nptv6_cfg {
44 	struct named_object	no;
45 
46 	struct in6_addr		internal;   /* Internal IPv6 prefix */
47 	struct in6_addr		external;   /* External IPv6 prefix */
48 	struct in6_addr		mask;	    /* IPv6 prefix mask */
49 	uint16_t		adjustment; /* Checksum adjustment value */
50 	uint8_t			plen;	    /* Prefix length */
51 	uint8_t			flags;	    /* Flags for internal use */
52 #define	NPTV6_READY		0x80
53 #define	NPTV6_48PLEN		0x40
54 
55 	char			if_name[IF_NAMESIZE];
56 	char			name[64];   /* Instance name */
57 	counter_u64_t		stats[NPTV6STATS]; /* Statistics counters */
58 };
59 #define	NPTV6_FLAGSMASK		(NPTV6_DYNAMIC_PREFIX)
60 
61 int nptv6_init(struct ip_fw_chain *ch, int first);
62 void nptv6_uninit(struct ip_fw_chain *ch, int last);
63 #endif /* _KERNEL */
64 
65 #endif /* _IP_FW_NPTV6_H_ */
66