| 1 | /*- |
| 2 | * SPDX-License-Identifier: BSD-2-Clause |
| 3 | * |
| 4 | * Copyright 2005, Gleb Smirnoff <glebius@FreeBSD.org> |
| 5 | * All rights reserved. |
| 6 | * |
| 7 | * Redistribution and use in source and binary forms, with or without |
| 8 | * modification, are permitted provided that the following conditions |
| 9 | * are met: |
| 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 AND CONTRIBUTORS ``AS IS'' AND |
| 17 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
| 18 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
| 19 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE |
| 20 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
| 21 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS |
| 22 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |
| 23 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
| 24 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY |
| 25 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
| 26 | * SUCH DAMAGE. |
| 27 | */ |
| 28 | |
| 29 | #define NG_NAT_NODE_TYPE "nat" |
| 30 | #define NGM_NAT_COOKIE 1107718711 |
| 31 | |
| 32 | #define	NG_NAT_HOOK_IN	"in" |
| 33 | #define	NG_NAT_HOOK_OUT	"out" |
| 34 | |
| 35 | /* Arguments for NGM_NAT_SET_MODE message */ |
| 36 | struct ng_nat_mode { |
| 37 | 	uint32_t	flags; |
| 38 | 	uint32_t	mask; |
| 39 | }; |
| 40 | |
| 41 | /* Keep this in sync with the above structure definition */ |
| 42 | #define NG_NAT_MODE_INFO {				\ |
| 43 | 	 { "flags",	&ng_parse_uint32_type	},	\ |
| 44 | 	 { "mask",	&ng_parse_uint32_type	},	\ |
| 45 | 	 { NULL }					\ |
| 46 | } |
| 47 | |
| 48 | #define NG_NAT_LOG			0x01 |
| 49 | #define NG_NAT_DENY_INCOMING		0x02 |
| 50 | #define NG_NAT_SAME_PORTS		0x04 |
| 51 | #define NG_NAT_UNREGISTERED_ONLY	0x10 |
| 52 | #define NG_NAT_RESET_ON_ADDR_CHANGE	0x20 |
| 53 | #define NG_NAT_PROXY_ONLY		0x40 |
| 54 | #define NG_NAT_REVERSE			0x80 |
| 55 | #define NG_NAT_UNREGISTERED_CGN		0x100 |
| 56 | #define NG_NAT_UDP_EIM			0x200 |
| 57 | |
| 58 | #define NG_NAT_DESC_LENGTH	64 |
| 59 | #define NG_NAT_REDIRPROTO_ADDR	(IPPROTO_MAX + 3) 	/* LibAlias' LINK_ADDR, also unused in in.h */ |
| 60 | |
| 61 | /* Arguments for NGM_NAT_REDIRECT_PORT message */ |
| 62 | struct ng_nat_redirect_port { |
| 63 | 	struct in_addr	local_addr; |
| 64 | 	struct in_addr	alias_addr; |
| 65 | 	struct in_addr	remote_addr; |
| 66 | 	uint16_t	local_port; |
| 67 | 	uint16_t	alias_port; |
| 68 | 	uint16_t	remote_port; |
| 69 | 	uint8_t		proto; |
| 70 | 	char		description[NG_NAT_DESC_LENGTH]; |
| 71 | }; |
| 72 | |
| 73 | /* Keep this in sync with the above structure definition */ |
| 74 | #define NG_NAT_REDIRECT_PORT_TYPE_INFO(desctype) {		\ |
| 75 | 	 { "local_addr",	&ng_parse_ipaddr_type	},	\ |
| 76 | 	 { "alias_addr",	&ng_parse_ipaddr_type	},	\ |
| 77 | 	 { "remote_addr",	&ng_parse_ipaddr_type	},	\ |
| 78 | 	 { "local_port",	&ng_parse_uint16_type	},	\ |
| 79 | 	 { "alias_port",	&ng_parse_uint16_type	},	\ |
| 80 | 	 { "remote_port",	&ng_parse_uint16_type	},	\ |
| 81 | 	 { "proto",		&ng_parse_uint8_type	},	\ |
| 82 | 	 { "description",	(desctype)		},	\ |
| 83 | 	 { NULL }						\ |
| 84 | } |
| 85 | |
| 86 | /* Arguments for NGM_NAT_REDIRECT_ADDR message */ |
| 87 | struct ng_nat_redirect_addr { |
| 88 | 	struct in_addr	local_addr; |
| 89 | 	struct in_addr	alias_addr; |
| 90 | 	char		description[NG_NAT_DESC_LENGTH]; |
| 91 | }; |
| 92 | |
| 93 | /* Keep this in sync with the above structure definition */ |
| 94 | #define NG_NAT_REDIRECT_ADDR_TYPE_INFO(desctype) {		\ |
| 95 | 	 { "local_addr",	&ng_parse_ipaddr_type	},	\ |
| 96 | 	 { "alias_addr",	&ng_parse_ipaddr_type	},	\ |
| 97 | 	 { "description",	(desctype)		},	\ |
| 98 | 	 { NULL }						\ |
| 99 | } |
| 100 | |
| 101 | /* Arguments for NGM_NAT_REDIRECT_PROTO message */ |
| 102 | struct ng_nat_redirect_proto { |
| 103 | 	struct in_addr	local_addr; |
| 104 | 	struct in_addr	alias_addr; |
| 105 | 	struct in_addr	remote_addr; |
| 106 | 	uint8_t		proto; |
| 107 | 	char		description[NG_NAT_DESC_LENGTH]; |
| 108 | }; |
| 109 | |
| 110 | /* Keep this in sync with the above structure definition */ |
| 111 | #define NG_NAT_REDIRECT_PROTO_TYPE_INFO(desctype) {		\ |
| 112 | 	 { "local_addr",	&ng_parse_ipaddr_type	},	\ |
| 113 | 	 { "alias_addr",	&ng_parse_ipaddr_type	},	\ |
| 114 | 	 { "remote_addr",	&ng_parse_ipaddr_type	},	\ |
| 115 | 	 { "proto",		&ng_parse_uint8_type	},	\ |
| 116 | 	 { "description",	(desctype)		},	\ |
| 117 | 	 { NULL }						\ |
| 118 | } |
| 119 | |
| 120 | /* Arguments for NGM_NAT_ADD_SERVER message */ |
| 121 | struct ng_nat_add_server { |
| 122 | 	uint32_t	id; |
| 123 | 	struct in_addr	addr; |
| 124 | 	uint16_t	port; |
| 125 | }; |
| 126 | |
| 127 | /* Keep this in sync with the above structure definition */ |
| 128 | #define NG_NAT_ADD_SERVER_TYPE_INFO {				\ |
| 129 | 	 { "id",		&ng_parse_uint32_type	},	\ |
| 130 | 	 { "addr",		&ng_parse_ipaddr_type	},	\ |
| 131 | 	 { "port",		&ng_parse_uint16_type	},	\ |
| 132 | 	 { NULL }						\ |
| 133 | } |
| 134 | |
| 135 | /* List entry of array returned in NGM_NAT_LIST_REDIRECTS message */ |
| 136 | struct ng_nat_listrdrs_entry { |
| 137 | 	uint32_t	id;		/* Anything except zero */ |
| 138 | 	struct in_addr	local_addr; |
| 139 | 	struct in_addr	alias_addr; |
| 140 | 	struct in_addr	remote_addr; |
| 141 | 	uint16_t	local_port; |
| 142 | 	uint16_t	alias_port; |
| 143 | 	uint16_t	remote_port; |
| 144 | 	uint16_t	proto;		/* Valid proto or NG_NAT_REDIRPROTO_ADDR */ |
| 145 | 	uint16_t	lsnat;		/* LSNAT servers count */ |
| 146 | 	char		description[NG_NAT_DESC_LENGTH]; |
| 147 | }; |
| 148 | |
| 149 | /* Keep this in sync with the above structure definition */ |
| 150 | #define NG_NAT_LISTRDRS_ENTRY_TYPE_INFO(desctype) {			\ |
| 151 | 	 { "id",		&ng_parse_uint32_type	},	\ |
| 152 | 	 { "local_addr",	&ng_parse_ipaddr_type	},	\ |
| 153 | 	 { "alias_addr",	&ng_parse_ipaddr_type	},	\ |
| 154 | 	 { "remote_addr",	&ng_parse_ipaddr_type	},	\ |
| 155 | 	 { "local_port",	&ng_parse_uint16_type	},	\ |
| 156 | 	 { "alias_port",	&ng_parse_uint16_type	},	\ |
| 157 | 	 { "remote_port",	&ng_parse_uint16_type	},	\ |
| 158 | 	 { "proto",		&ng_parse_uint16_type	},	\ |
| 159 | 	 { "lsnat",		&ng_parse_uint16_type	},	\ |
| 160 | 	 { "description",	(desctype)		},	\ |
| 161 | 	 { NULL }						\ |
| 162 | } |
| 163 | |
| 164 | /* Structure returned by NGM_NAT_LIST_REDIRECTS */ |
| 165 | struct ng_nat_list_redirects { |
| 166 | 	uint32_t		total_count; |
| 167 | 	struct ng_nat_listrdrs_entry redirects[]; |
| 168 | }; |
| 169 | |
| 170 | /* Keep this in sync with the above structure definition */ |
| 171 | #define NG_NAT_LIST_REDIRECTS_TYPE_INFO(redirtype) {		\ |
| 172 | 	 { "total_count",	&ng_parse_uint32_type	},	\ |
| 173 | 	 { "redirects",	(redirtype)		},	\ |
| 174 | 	 { NULL }						\ |
| 175 | } |
| 176 | |
| 177 | /* Structure returned by NGM_NAT_LIBALIAS_INFO */ |
| 178 | struct ng_nat_libalias_info { |
| 179 | 	uint32_t	icmpLinkCount; |
| 180 | 	uint32_t	udpLinkCount; |
| 181 | 	uint32_t	tcpLinkCount; |
| 182 | 	uint32_t	sctpLinkCount; |
| 183 | 	uint32_t	pptpLinkCount; |
| 184 | 	uint32_t	protoLinkCount; |
| 185 | 	uint32_t	fragmentIdLinkCount; |
| 186 | 	uint32_t	fragmentPtrLinkCount; |
| 187 | 	uint32_t	sockCount; |
| 188 | }; |
| 189 | |
| 190 | /* Keep this in sync with the above structure definition */ |
| 191 | #define NG_NAT_LIBALIAS_INFO {					\ |
| 192 | 	 { "icmpLinkCount",	&ng_parse_uint32_type	},	\ |
| 193 | 	 { "udpLinkCount",	&ng_parse_uint32_type	},	\ |
| 194 | 	 { "tcpLinkCount",	&ng_parse_uint32_type	},	\ |
| 195 | 	 { "sctpLinkCount",	&ng_parse_uint32_type	},	\ |
| 196 | 	 { "pptpLinkCount",	&ng_parse_uint32_type	},	\ |
| 197 | 	 { "protoLinkCount",	&ng_parse_uint32_type	},	\ |
| 198 | 	 { "fragmentIdLinkCount", &ng_parse_uint32_type },	\ |
| 199 | 	 { "fragmentPtrLinkCount", &ng_parse_uint32_type },	\ |
| 200 | 	 { "sockCount",	&ng_parse_uint32_type	},	\ |
| 201 | 	 { NULL }						\ |
| 202 | } |
| 203 | |
| 204 | enum { |
| 205 | 	NGM_NAT_SET_IPADDR = 1, |
| 206 | 	NGM_NAT_SET_MODE, |
| 207 | 	NGM_NAT_SET_TARGET, |
| 208 | 	NGM_NAT_REDIRECT_PORT, |
| 209 | 	NGM_NAT_REDIRECT_ADDR, |
| 210 | 	NGM_NAT_REDIRECT_PROTO, |
| 211 | 	NGM_NAT_REDIRECT_DYNAMIC, |
| 212 | 	NGM_NAT_REDIRECT_DELETE, |
| 213 | 	NGM_NAT_ADD_SERVER, |
| 214 | 	NGM_NAT_LIST_REDIRECTS, |
| 215 | 	NGM_NAT_PROXY_RULE, |
| 216 | 	NGM_NAT_LIBALIAS_INFO, |
| 217 | 	NGM_NAT_SET_DLT, |
| 218 | 	NGM_NAT_GET_DLT, |
| 219 | }; |