summaryrefslogtreecommitdiffstats
path: root/sys/netgraph/ng_nat.h
blob: 1b929e094137fc6bd9c4435fe008e97f94cc3b9c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
/*-
 * Copyright 2005, Gleb Smirnoff <glebius@FreeBSD.org>
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 *
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 * SUCH DAMAGE.
 *
 * $FreeBSD$
 */

#define NG_NAT_NODE_TYPE    "nat"
#define NGM_NAT_COOKIE      1107718711

#define	NG_NAT_HOOK_IN	"in"
#define	NG_NAT_HOOK_OUT	"out"

/* Arguments for NGM_NAT_SET_MODE message */
struct ng_nat_mode {
	uint32_t	flags;
	uint32_t	mask;
};

/* Keep this in sync with the above structure definition */
#define NG_NAT_MODE_INFO {				\
	  { "flags",	&ng_parse_uint32_type	},	\
	  { "mask",	&ng_parse_uint32_type	},	\
	  { NULL }					\
}

#define NG_NAT_LOG			0x01
#define NG_NAT_DENY_INCOMING		0x02
#define NG_NAT_SAME_PORTS		0x04
#define NG_NAT_UNREGISTERED_ONLY	0x10
#define NG_NAT_RESET_ON_ADDR_CHANGE	0x20
#define NG_NAT_PROXY_ONLY		0x40
#define NG_NAT_REVERSE			0x80

#define NG_NAT_DESC_LENGTH	64
#define NG_NAT_REDIRPROTO_ADDR	(IPPROTO_MAX + 3) 	/* LibAlias' LINK_ADDR, also unused in in.h */

/* Arguments for NGM_NAT_REDIRECT_PORT message */
struct ng_nat_redirect_port {
	struct in_addr	local_addr;
	struct in_addr	alias_addr;
	struct in_addr	remote_addr;
	uint16_t	local_port;
	uint16_t	alias_port;
	uint16_t	remote_port;
	uint8_t		proto;
	char		description[NG_NAT_DESC_LENGTH];
};

/* Keep this in sync with the above structure definition */
#define NG_NAT_REDIRECT_PORT_TYPE_INFO(desctype) {		\
	  { "local_addr",	&ng_parse_ipaddr_type	},	\
	  { "alias_addr",	&ng_parse_ipaddr_type	},	\
	  { "remote_addr",	&ng_parse_ipaddr_type	},	\
	  { "local_port",	&ng_parse_uint16_type	},	\
	  { "alias_port",	&ng_parse_uint16_type	},	\
	  { "remote_port",	&ng_parse_uint16_type	},	\
	  { "proto",		&ng_parse_uint8_type	},	\
	  { "description",	(desctype)		},	\
	  { NULL }						\
}

/* Arguments for NGM_NAT_REDIRECT_ADDR message */
struct ng_nat_redirect_addr {
	struct in_addr	local_addr;
	struct in_addr	alias_addr;
	char		description[NG_NAT_DESC_LENGTH];
};

/* Keep this in sync with the above structure definition */
#define NG_NAT_REDIRECT_ADDR_TYPE_INFO(desctype) {		\
	  { "local_addr",	&ng_parse_ipaddr_type	},	\
	  { "alias_addr",	&ng_parse_ipaddr_type	},	\
	  { "description",	(desctype)		},	\
	  { NULL }						\
}

/* Arguments for NGM_NAT_REDIRECT_PROTO message */
struct ng_nat_redirect_proto {
	struct in_addr	local_addr;
	struct in_addr	alias_addr;
	struct in_addr	remote_addr;
	uint8_t		proto;
	char		description[NG_NAT_DESC_LENGTH];
};

/* Keep this in sync with the above structure definition */
#define NG_NAT_REDIRECT_PROTO_TYPE_INFO(desctype) {		\
	  { "local_addr",	&ng_parse_ipaddr_type	},	\
	  { "alias_addr",	&ng_parse_ipaddr_type	},	\
	  { "remote_addr",	&ng_parse_ipaddr_type	},	\
	  { "proto",		&ng_parse_uint8_type	},	\
	  { "description",	(desctype)		},	\
	  { NULL }						\
}

/* Arguments for NGM_NAT_ADD_SERVER message */
struct ng_nat_add_server {
	uint32_t	id;
	struct in_addr	addr;
	uint16_t	port;
};

/* Keep this in sync with the above structure definition */
#define NG_NAT_ADD_SERVER_TYPE_INFO {				\
	  { "id",		&ng_parse_uint32_type	},	\
	  { "addr",		&ng_parse_ipaddr_type	},	\
	  { "port",		&ng_parse_uint16_type	},	\
	  { NULL }						\
}

/* List entry of array returned in NGM_NAT_LIST_REDIRECTS message */
struct ng_nat_listrdrs_entry {
	uint32_t	id;		/* Anything except zero */
	struct in_addr	local_addr;
	struct in_addr	alias_addr;
	struct in_addr	remote_addr;
	uint16_t	local_port;
	uint16_t	alias_port;
	uint16_t	remote_port;
	uint16_t	proto;		/* Valid proto or NG_NAT_REDIRPROTO_ADDR */
	uint16_t	lsnat;		/* LSNAT servers count */
	char		description[NG_NAT_DESC_LENGTH];
};

/* Keep this in sync with the above structure definition */
#define NG_NAT_LISTRDRS_ENTRY_TYPE_INFO(desctype) {			\
	  { "id",		&ng_parse_uint32_type	},	\
	  { "local_addr",	&ng_parse_ipaddr_type	},	\
	  { "alias_addr",	&ng_parse_ipaddr_type	},	\
	  { "remote_addr",	&ng_parse_ipaddr_type	},	\
	  { "local_port",	&ng_parse_uint16_type	},	\
	  { "alias_port",	&ng_parse_uint16_type	},	\
	  { "remote_port",	&ng_parse_uint16_type	},	\
	  { "proto",		&ng_parse_uint16_type	},	\
	  { "lsnat",		&ng_parse_uint16_type	},	\
	  { "description",	(desctype)		},	\
	  { NULL }						\
}

/* Structure returned by NGM_NAT_LIST_REDIRECTS */
struct ng_nat_list_redirects {
	uint32_t		total_count;
	struct ng_nat_listrdrs_entry redirects[];
};

/* Keep this in sync with the above structure definition */
#define NG_NAT_LIST_REDIRECTS_TYPE_INFO(redirtype) {		\
	  { "total_count",	&ng_parse_uint32_type	},	\
	  { "redirects",	(redirtype)		},	\
	  { NULL }						\
}

/* Structure returned by NGM_NAT_LIBALIAS_INFO */
struct ng_nat_libalias_info {
	uint32_t	icmpLinkCount;
	uint32_t	udpLinkCount;
	uint32_t	tcpLinkCount;
	uint32_t	sctpLinkCount;
	uint32_t	pptpLinkCount;
	uint32_t	protoLinkCount;
	uint32_t	fragmentIdLinkCount;
	uint32_t	fragmentPtrLinkCount;
	uint32_t	sockCount;
};

/* Keep this in sync with the above structure definition */
#define NG_NAT_LIBALIAS_INFO {					\
	  { "icmpLinkCount",	&ng_parse_uint32_type	},	\
	  { "udpLinkCount",	&ng_parse_uint32_type	},	\
	  { "tcpLinkCount",	&ng_parse_uint32_type	},	\
	  { "sctpLinkCount",	&ng_parse_uint32_type	},	\
	  { "pptpLinkCount",	&ng_parse_uint32_type	},	\
	  { "protoLinkCount",	&ng_parse_uint32_type	},	\
	  { "fragmentIdLinkCount", &ng_parse_uint32_type },	\
	  { "fragmentPtrLinkCount", &ng_parse_uint32_type },	\
	  { "sockCount",	&ng_parse_uint32_type	},	\
	  { NULL }						\
}

enum {
	NGM_NAT_SET_IPADDR = 1,
	NGM_NAT_SET_MODE,
	NGM_NAT_SET_TARGET,
	NGM_NAT_REDIRECT_PORT,
	NGM_NAT_REDIRECT_ADDR,
	NGM_NAT_REDIRECT_PROTO,
	NGM_NAT_REDIRECT_DYNAMIC,
	NGM_NAT_REDIRECT_DELETE,
	NGM_NAT_ADD_SERVER,
	NGM_NAT_LIST_REDIRECTS,
	NGM_NAT_PROXY_RULE,
	NGM_NAT_LIBALIAS_INFO,
};
OpenPOWER on IntegriCloud