xref: /freebsd/sys/netgraph/ng_nat.h (revision f132be9bac5f29e844e8dde4f3a70f4c3c158221)
1c4c9b52bSGleb Smirnoff /*-
24d846d26SWarner Losh  * SPDX-License-Identifier: BSD-2-Clause
3fe267a55SPedro F. Giffuni  *
4c4c9b52bSGleb Smirnoff  * Copyright 2005, Gleb Smirnoff <glebius@FreeBSD.org>
5c4c9b52bSGleb Smirnoff  * All rights reserved.
6c4c9b52bSGleb Smirnoff  *
7c4c9b52bSGleb Smirnoff  * Redistribution and use in source and binary forms, with or without
8c4c9b52bSGleb Smirnoff  * modification, are permitted provided that the following conditions
9c4c9b52bSGleb Smirnoff  * are met:
10c4c9b52bSGleb Smirnoff  * 1. Redistributions of source code must retain the above copyright
11c4c9b52bSGleb Smirnoff  *    notice, this list of conditions and the following disclaimer.
12c4c9b52bSGleb Smirnoff  * 2. Redistributions in binary form must reproduce the above copyright
13c4c9b52bSGleb Smirnoff  *    notice, this list of conditions and the following disclaimer in the
14c4c9b52bSGleb Smirnoff  *    documentation and/or other materials provided with the distribution.
15c4c9b52bSGleb Smirnoff  *
16c4c9b52bSGleb Smirnoff  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
17c4c9b52bSGleb Smirnoff  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18c4c9b52bSGleb Smirnoff  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19c4c9b52bSGleb Smirnoff  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
20c4c9b52bSGleb Smirnoff  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21c4c9b52bSGleb Smirnoff  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22c4c9b52bSGleb Smirnoff  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23c4c9b52bSGleb Smirnoff  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24c4c9b52bSGleb Smirnoff  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25c4c9b52bSGleb Smirnoff  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26c4c9b52bSGleb Smirnoff  * SUCH DAMAGE.
27c4c9b52bSGleb Smirnoff  */
28c4c9b52bSGleb Smirnoff 
29c4c9b52bSGleb Smirnoff #define NG_NAT_NODE_TYPE    "nat"
30c4c9b52bSGleb Smirnoff #define NGM_NAT_COOKIE      1107718711
31c4c9b52bSGleb Smirnoff 
32c4c9b52bSGleb Smirnoff #define	NG_NAT_HOOK_IN	"in"
33c4c9b52bSGleb Smirnoff #define	NG_NAT_HOOK_OUT	"out"
34c4c9b52bSGleb Smirnoff 
35e842c540SAlexander Motin /* Arguments for NGM_NAT_SET_MODE message */
36e842c540SAlexander Motin struct ng_nat_mode {
37e842c540SAlexander Motin 	uint32_t	flags;
38e842c540SAlexander Motin 	uint32_t	mask;
39e842c540SAlexander Motin };
40e842c540SAlexander Motin 
41e842c540SAlexander Motin /* Keep this in sync with the above structure definition */
42e842c540SAlexander Motin #define NG_NAT_MODE_INFO {				\
43e842c540SAlexander Motin 	  { "flags",	&ng_parse_uint32_type	},	\
44e842c540SAlexander Motin 	  { "mask",	&ng_parse_uint32_type	},	\
45e842c540SAlexander Motin 	  { NULL }					\
46e842c540SAlexander Motin }
47e842c540SAlexander Motin 
48e842c540SAlexander Motin #define NG_NAT_LOG			0x01
49e842c540SAlexander Motin #define NG_NAT_DENY_INCOMING		0x02
50e842c540SAlexander Motin #define NG_NAT_SAME_PORTS		0x04
51e842c540SAlexander Motin #define NG_NAT_UNREGISTERED_ONLY	0x10
52e842c540SAlexander Motin #define NG_NAT_RESET_ON_ADDR_CHANGE	0x20
53e842c540SAlexander Motin #define NG_NAT_PROXY_ONLY		0x40
54e842c540SAlexander Motin #define NG_NAT_REVERSE			0x80
555fe433a6SNeel Chauhan #define NG_NAT_UNREGISTERED_CGN		0x100
56*f132be9bSDamjan Jovanovic #define NG_NAT_UDP_EIM			0x200
57e842c540SAlexander Motin 
58fffba935SAlexander Motin #define NG_NAT_DESC_LENGTH	64
59fffba935SAlexander Motin #define NG_NAT_REDIRPROTO_ADDR	(IPPROTO_MAX + 3) 	/* LibAlias' LINK_ADDR, also unused in in.h */
60fffba935SAlexander Motin 
61fffba935SAlexander Motin /* Arguments for NGM_NAT_REDIRECT_PORT message */
62fffba935SAlexander Motin struct ng_nat_redirect_port {
63fffba935SAlexander Motin 	struct in_addr	local_addr;
64fffba935SAlexander Motin 	struct in_addr	alias_addr;
65fffba935SAlexander Motin 	struct in_addr	remote_addr;
66fffba935SAlexander Motin 	uint16_t	local_port;
67fffba935SAlexander Motin 	uint16_t	alias_port;
68fffba935SAlexander Motin 	uint16_t	remote_port;
69fffba935SAlexander Motin 	uint8_t		proto;
70fffba935SAlexander Motin 	char		description[NG_NAT_DESC_LENGTH];
71fffba935SAlexander Motin };
72fffba935SAlexander Motin 
73fffba935SAlexander Motin /* Keep this in sync with the above structure definition */
74fffba935SAlexander Motin #define NG_NAT_REDIRECT_PORT_TYPE_INFO(desctype) {		\
75fffba935SAlexander Motin 	  { "local_addr",	&ng_parse_ipaddr_type	},	\
76fffba935SAlexander Motin 	  { "alias_addr",	&ng_parse_ipaddr_type	},	\
77fffba935SAlexander Motin 	  { "remote_addr",	&ng_parse_ipaddr_type	},	\
78fffba935SAlexander Motin 	  { "local_port",	&ng_parse_uint16_type	},	\
79fffba935SAlexander Motin 	  { "alias_port",	&ng_parse_uint16_type	},	\
80fffba935SAlexander Motin 	  { "remote_port",	&ng_parse_uint16_type	},	\
81b7c649d8SAlexander Motin 	  { "proto",		&ng_parse_uint8_type	},	\
82fffba935SAlexander Motin 	  { "description",	(desctype)		},	\
83fffba935SAlexander Motin 	  { NULL }						\
84fffba935SAlexander Motin }
85fffba935SAlexander Motin 
86fffba935SAlexander Motin /* Arguments for NGM_NAT_REDIRECT_ADDR message */
87fffba935SAlexander Motin struct ng_nat_redirect_addr {
88fffba935SAlexander Motin 	struct in_addr	local_addr;
89fffba935SAlexander Motin 	struct in_addr	alias_addr;
90fffba935SAlexander Motin 	char		description[NG_NAT_DESC_LENGTH];
91fffba935SAlexander Motin };
92fffba935SAlexander Motin 
93fffba935SAlexander Motin /* Keep this in sync with the above structure definition */
94fffba935SAlexander Motin #define NG_NAT_REDIRECT_ADDR_TYPE_INFO(desctype) {		\
95fffba935SAlexander Motin 	  { "local_addr",	&ng_parse_ipaddr_type	},	\
96fffba935SAlexander Motin 	  { "alias_addr",	&ng_parse_ipaddr_type	},	\
97fffba935SAlexander Motin 	  { "description",	(desctype)		},	\
98fffba935SAlexander Motin 	  { NULL }						\
99fffba935SAlexander Motin }
100fffba935SAlexander Motin 
101fffba935SAlexander Motin /* Arguments for NGM_NAT_REDIRECT_PROTO message */
102fffba935SAlexander Motin struct ng_nat_redirect_proto {
103fffba935SAlexander Motin 	struct in_addr	local_addr;
104fffba935SAlexander Motin 	struct in_addr	alias_addr;
105fffba935SAlexander Motin 	struct in_addr	remote_addr;
106fffba935SAlexander Motin 	uint8_t		proto;
107fffba935SAlexander Motin 	char		description[NG_NAT_DESC_LENGTH];
108fffba935SAlexander Motin };
109fffba935SAlexander Motin 
110fffba935SAlexander Motin /* Keep this in sync with the above structure definition */
111fffba935SAlexander Motin #define NG_NAT_REDIRECT_PROTO_TYPE_INFO(desctype) {		\
112fffba935SAlexander Motin 	  { "local_addr",	&ng_parse_ipaddr_type	},	\
113fffba935SAlexander Motin 	  { "alias_addr",	&ng_parse_ipaddr_type	},	\
114fffba935SAlexander Motin 	  { "remote_addr",	&ng_parse_ipaddr_type	},	\
115fffba935SAlexander Motin 	  { "proto",		&ng_parse_uint8_type	},	\
116fffba935SAlexander Motin 	  { "description",	(desctype)		},	\
117fffba935SAlexander Motin 	  { NULL }						\
118fffba935SAlexander Motin }
119fffba935SAlexander Motin 
120fffba935SAlexander Motin /* Arguments for NGM_NAT_ADD_SERVER message */
121fffba935SAlexander Motin struct ng_nat_add_server {
122fffba935SAlexander Motin 	uint32_t	id;
123fffba935SAlexander Motin 	struct in_addr	addr;
124fffba935SAlexander Motin 	uint16_t	port;
125fffba935SAlexander Motin };
126fffba935SAlexander Motin 
127fffba935SAlexander Motin /* Keep this in sync with the above structure definition */
128fffba935SAlexander Motin #define NG_NAT_ADD_SERVER_TYPE_INFO {				\
129fffba935SAlexander Motin 	  { "id",		&ng_parse_uint32_type	},	\
130fffba935SAlexander Motin 	  { "addr",		&ng_parse_ipaddr_type	},	\
131fffba935SAlexander Motin 	  { "port",		&ng_parse_uint16_type	},	\
132fffba935SAlexander Motin 	  { NULL }						\
133fffba935SAlexander Motin }
134fffba935SAlexander Motin 
135fffba935SAlexander Motin /* List entry of array returned in NGM_NAT_LIST_REDIRECTS message */
136fffba935SAlexander Motin struct ng_nat_listrdrs_entry {
137fffba935SAlexander Motin 	uint32_t	id;		/* Anything except zero */
138fffba935SAlexander Motin 	struct in_addr	local_addr;
139fffba935SAlexander Motin 	struct in_addr	alias_addr;
140fffba935SAlexander Motin 	struct in_addr	remote_addr;
141fffba935SAlexander Motin 	uint16_t	local_port;
142fffba935SAlexander Motin 	uint16_t	alias_port;
143fffba935SAlexander Motin 	uint16_t	remote_port;
144fffba935SAlexander Motin 	uint16_t	proto;		/* Valid proto or NG_NAT_REDIRPROTO_ADDR */
145fffba935SAlexander Motin 	uint16_t	lsnat;		/* LSNAT servers count */
146fffba935SAlexander Motin 	char		description[NG_NAT_DESC_LENGTH];
147fffba935SAlexander Motin };
148fffba935SAlexander Motin 
149fffba935SAlexander Motin /* Keep this in sync with the above structure definition */
150fffba935SAlexander Motin #define NG_NAT_LISTRDRS_ENTRY_TYPE_INFO(desctype) {			\
151fffba935SAlexander Motin 	  { "id",		&ng_parse_uint32_type	},	\
152fffba935SAlexander Motin 	  { "local_addr",	&ng_parse_ipaddr_type	},	\
153fffba935SAlexander Motin 	  { "alias_addr",	&ng_parse_ipaddr_type	},	\
154fffba935SAlexander Motin 	  { "remote_addr",	&ng_parse_ipaddr_type	},	\
155fffba935SAlexander Motin 	  { "local_port",	&ng_parse_uint16_type	},	\
156fffba935SAlexander Motin 	  { "alias_port",	&ng_parse_uint16_type	},	\
157fffba935SAlexander Motin 	  { "remote_port",	&ng_parse_uint16_type	},	\
158fffba935SAlexander Motin 	  { "proto",		&ng_parse_uint16_type	},	\
159fffba935SAlexander Motin 	  { "lsnat",		&ng_parse_uint16_type	},	\
160fffba935SAlexander Motin 	  { "description",	(desctype)		},	\
161fffba935SAlexander Motin 	  { NULL }						\
162fffba935SAlexander Motin }
163fffba935SAlexander Motin 
164fffba935SAlexander Motin /* Structure returned by NGM_NAT_LIST_REDIRECTS */
165fffba935SAlexander Motin struct ng_nat_list_redirects {
166fffba935SAlexander Motin 	uint32_t		total_count;
167fffba935SAlexander Motin 	struct ng_nat_listrdrs_entry redirects[];
168fffba935SAlexander Motin };
169fffba935SAlexander Motin 
170fffba935SAlexander Motin /* Keep this in sync with the above structure definition */
171fffba935SAlexander Motin #define NG_NAT_LIST_REDIRECTS_TYPE_INFO(redirtype) {		\
172fffba935SAlexander Motin 	  { "total_count",	&ng_parse_uint32_type	},	\
173fffba935SAlexander Motin 	  { "redirects",	(redirtype)		},	\
174fffba935SAlexander Motin 	  { NULL }						\
175fffba935SAlexander Motin }
176fffba935SAlexander Motin 
1775aedfa32SGleb Smirnoff /* Structure returned by NGM_NAT_LIBALIAS_INFO */
1785aedfa32SGleb Smirnoff struct ng_nat_libalias_info {
1795aedfa32SGleb Smirnoff 	uint32_t	icmpLinkCount;
1805aedfa32SGleb Smirnoff 	uint32_t	udpLinkCount;
1815aedfa32SGleb Smirnoff 	uint32_t	tcpLinkCount;
1825aedfa32SGleb Smirnoff 	uint32_t	sctpLinkCount;
1835aedfa32SGleb Smirnoff 	uint32_t	pptpLinkCount;
1845aedfa32SGleb Smirnoff 	uint32_t	protoLinkCount;
1855aedfa32SGleb Smirnoff 	uint32_t	fragmentIdLinkCount;
1865aedfa32SGleb Smirnoff 	uint32_t	fragmentPtrLinkCount;
1875aedfa32SGleb Smirnoff 	uint32_t	sockCount;
1885aedfa32SGleb Smirnoff };
1895aedfa32SGleb Smirnoff 
1905aedfa32SGleb Smirnoff /* Keep this in sync with the above structure definition */
1915aedfa32SGleb Smirnoff #define NG_NAT_LIBALIAS_INFO {					\
1925aedfa32SGleb Smirnoff 	  { "icmpLinkCount",	&ng_parse_uint32_type	},	\
1935aedfa32SGleb Smirnoff 	  { "udpLinkCount",	&ng_parse_uint32_type	},	\
1945aedfa32SGleb Smirnoff 	  { "tcpLinkCount",	&ng_parse_uint32_type	},	\
1955aedfa32SGleb Smirnoff 	  { "sctpLinkCount",	&ng_parse_uint32_type	},	\
1965aedfa32SGleb Smirnoff 	  { "pptpLinkCount",	&ng_parse_uint32_type	},	\
1975aedfa32SGleb Smirnoff 	  { "protoLinkCount",	&ng_parse_uint32_type	},	\
1985aedfa32SGleb Smirnoff 	  { "fragmentIdLinkCount", &ng_parse_uint32_type },	\
1995aedfa32SGleb Smirnoff 	  { "fragmentPtrLinkCount", &ng_parse_uint32_type },	\
2005aedfa32SGleb Smirnoff 	  { "sockCount",	&ng_parse_uint32_type	},	\
2015aedfa32SGleb Smirnoff 	  { NULL }						\
2025aedfa32SGleb Smirnoff }
2035aedfa32SGleb Smirnoff 
204c4c9b52bSGleb Smirnoff enum {
205c4c9b52bSGleb Smirnoff 	NGM_NAT_SET_IPADDR = 1,
206e842c540SAlexander Motin 	NGM_NAT_SET_MODE,
207e842c540SAlexander Motin 	NGM_NAT_SET_TARGET,
208fffba935SAlexander Motin 	NGM_NAT_REDIRECT_PORT,
209fffba935SAlexander Motin 	NGM_NAT_REDIRECT_ADDR,
210fffba935SAlexander Motin 	NGM_NAT_REDIRECT_PROTO,
211fffba935SAlexander Motin 	NGM_NAT_REDIRECT_DYNAMIC,
212fffba935SAlexander Motin 	NGM_NAT_REDIRECT_DELETE,
213fffba935SAlexander Motin 	NGM_NAT_ADD_SERVER,
214fffba935SAlexander Motin 	NGM_NAT_LIST_REDIRECTS,
215fffba935SAlexander Motin 	NGM_NAT_PROXY_RULE,
2165aedfa32SGleb Smirnoff 	NGM_NAT_LIBALIAS_INFO,
2173ff4b317SEugene Grosbein 	NGM_NAT_SET_DLT,
2183ff4b317SEugene Grosbein 	NGM_NAT_GET_DLT,
219c4c9b52bSGleb Smirnoff };
220