1c4c9b52bSGleb Smirnoff /*- 2fe267a55SPedro F. Giffuni * SPDX-License-Identifier: BSD-2-Clause-FreeBSD 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 * $FreeBSD$ 29c4c9b52bSGleb Smirnoff */ 30c4c9b52bSGleb Smirnoff 31c4c9b52bSGleb Smirnoff #define NG_NAT_NODE_TYPE "nat" 32c4c9b52bSGleb Smirnoff #define NGM_NAT_COOKIE 1107718711 33c4c9b52bSGleb Smirnoff 34c4c9b52bSGleb Smirnoff #define NG_NAT_HOOK_IN "in" 35c4c9b52bSGleb Smirnoff #define NG_NAT_HOOK_OUT "out" 36c4c9b52bSGleb Smirnoff 37e842c540SAlexander Motin /* Arguments for NGM_NAT_SET_MODE message */ 38e842c540SAlexander Motin struct ng_nat_mode { 39e842c540SAlexander Motin uint32_t flags; 40e842c540SAlexander Motin uint32_t mask; 41e842c540SAlexander Motin }; 42e842c540SAlexander Motin 43e842c540SAlexander Motin /* Keep this in sync with the above structure definition */ 44e842c540SAlexander Motin #define NG_NAT_MODE_INFO { \ 45e842c540SAlexander Motin { "flags", &ng_parse_uint32_type }, \ 46e842c540SAlexander Motin { "mask", &ng_parse_uint32_type }, \ 47e842c540SAlexander Motin { NULL } \ 48e842c540SAlexander Motin } 49e842c540SAlexander Motin 50e842c540SAlexander Motin #define NG_NAT_LOG 0x01 51e842c540SAlexander Motin #define NG_NAT_DENY_INCOMING 0x02 52e842c540SAlexander Motin #define NG_NAT_SAME_PORTS 0x04 53e842c540SAlexander Motin #define NG_NAT_UNREGISTERED_ONLY 0x10 54e842c540SAlexander Motin #define NG_NAT_RESET_ON_ADDR_CHANGE 0x20 55e842c540SAlexander Motin #define NG_NAT_PROXY_ONLY 0x40 56e842c540SAlexander Motin #define NG_NAT_REVERSE 0x80 57*5fe433a6SNeel Chauhan #define NG_NAT_UNREGISTERED_CGN 0x100 58e842c540SAlexander Motin 59fffba935SAlexander Motin #define NG_NAT_DESC_LENGTH 64 60fffba935SAlexander Motin #define NG_NAT_REDIRPROTO_ADDR (IPPROTO_MAX + 3) /* LibAlias' LINK_ADDR, also unused in in.h */ 61fffba935SAlexander Motin 62fffba935SAlexander Motin /* Arguments for NGM_NAT_REDIRECT_PORT message */ 63fffba935SAlexander Motin struct ng_nat_redirect_port { 64fffba935SAlexander Motin struct in_addr local_addr; 65fffba935SAlexander Motin struct in_addr alias_addr; 66fffba935SAlexander Motin struct in_addr remote_addr; 67fffba935SAlexander Motin uint16_t local_port; 68fffba935SAlexander Motin uint16_t alias_port; 69fffba935SAlexander Motin uint16_t remote_port; 70fffba935SAlexander Motin uint8_t proto; 71fffba935SAlexander Motin char description[NG_NAT_DESC_LENGTH]; 72fffba935SAlexander Motin }; 73fffba935SAlexander Motin 74fffba935SAlexander Motin /* Keep this in sync with the above structure definition */ 75fffba935SAlexander Motin #define NG_NAT_REDIRECT_PORT_TYPE_INFO(desctype) { \ 76fffba935SAlexander Motin { "local_addr", &ng_parse_ipaddr_type }, \ 77fffba935SAlexander Motin { "alias_addr", &ng_parse_ipaddr_type }, \ 78fffba935SAlexander Motin { "remote_addr", &ng_parse_ipaddr_type }, \ 79fffba935SAlexander Motin { "local_port", &ng_parse_uint16_type }, \ 80fffba935SAlexander Motin { "alias_port", &ng_parse_uint16_type }, \ 81fffba935SAlexander Motin { "remote_port", &ng_parse_uint16_type }, \ 82b7c649d8SAlexander Motin { "proto", &ng_parse_uint8_type }, \ 83fffba935SAlexander Motin { "description", (desctype) }, \ 84fffba935SAlexander Motin { NULL } \ 85fffba935SAlexander Motin } 86fffba935SAlexander Motin 87fffba935SAlexander Motin /* Arguments for NGM_NAT_REDIRECT_ADDR message */ 88fffba935SAlexander Motin struct ng_nat_redirect_addr { 89fffba935SAlexander Motin struct in_addr local_addr; 90fffba935SAlexander Motin struct in_addr alias_addr; 91fffba935SAlexander Motin char description[NG_NAT_DESC_LENGTH]; 92fffba935SAlexander Motin }; 93fffba935SAlexander Motin 94fffba935SAlexander Motin /* Keep this in sync with the above structure definition */ 95fffba935SAlexander Motin #define NG_NAT_REDIRECT_ADDR_TYPE_INFO(desctype) { \ 96fffba935SAlexander Motin { "local_addr", &ng_parse_ipaddr_type }, \ 97fffba935SAlexander Motin { "alias_addr", &ng_parse_ipaddr_type }, \ 98fffba935SAlexander Motin { "description", (desctype) }, \ 99fffba935SAlexander Motin { NULL } \ 100fffba935SAlexander Motin } 101fffba935SAlexander Motin 102fffba935SAlexander Motin /* Arguments for NGM_NAT_REDIRECT_PROTO message */ 103fffba935SAlexander Motin struct ng_nat_redirect_proto { 104fffba935SAlexander Motin struct in_addr local_addr; 105fffba935SAlexander Motin struct in_addr alias_addr; 106fffba935SAlexander Motin struct in_addr remote_addr; 107fffba935SAlexander Motin uint8_t proto; 108fffba935SAlexander Motin char description[NG_NAT_DESC_LENGTH]; 109fffba935SAlexander Motin }; 110fffba935SAlexander Motin 111fffba935SAlexander Motin /* Keep this in sync with the above structure definition */ 112fffba935SAlexander Motin #define NG_NAT_REDIRECT_PROTO_TYPE_INFO(desctype) { \ 113fffba935SAlexander Motin { "local_addr", &ng_parse_ipaddr_type }, \ 114fffba935SAlexander Motin { "alias_addr", &ng_parse_ipaddr_type }, \ 115fffba935SAlexander Motin { "remote_addr", &ng_parse_ipaddr_type }, \ 116fffba935SAlexander Motin { "proto", &ng_parse_uint8_type }, \ 117fffba935SAlexander Motin { "description", (desctype) }, \ 118fffba935SAlexander Motin { NULL } \ 119fffba935SAlexander Motin } 120fffba935SAlexander Motin 121fffba935SAlexander Motin /* Arguments for NGM_NAT_ADD_SERVER message */ 122fffba935SAlexander Motin struct ng_nat_add_server { 123fffba935SAlexander Motin uint32_t id; 124fffba935SAlexander Motin struct in_addr addr; 125fffba935SAlexander Motin uint16_t port; 126fffba935SAlexander Motin }; 127fffba935SAlexander Motin 128fffba935SAlexander Motin /* Keep this in sync with the above structure definition */ 129fffba935SAlexander Motin #define NG_NAT_ADD_SERVER_TYPE_INFO { \ 130fffba935SAlexander Motin { "id", &ng_parse_uint32_type }, \ 131fffba935SAlexander Motin { "addr", &ng_parse_ipaddr_type }, \ 132fffba935SAlexander Motin { "port", &ng_parse_uint16_type }, \ 133fffba935SAlexander Motin { NULL } \ 134fffba935SAlexander Motin } 135fffba935SAlexander Motin 136fffba935SAlexander Motin /* List entry of array returned in NGM_NAT_LIST_REDIRECTS message */ 137fffba935SAlexander Motin struct ng_nat_listrdrs_entry { 138fffba935SAlexander Motin uint32_t id; /* Anything except zero */ 139fffba935SAlexander Motin struct in_addr local_addr; 140fffba935SAlexander Motin struct in_addr alias_addr; 141fffba935SAlexander Motin struct in_addr remote_addr; 142fffba935SAlexander Motin uint16_t local_port; 143fffba935SAlexander Motin uint16_t alias_port; 144fffba935SAlexander Motin uint16_t remote_port; 145fffba935SAlexander Motin uint16_t proto; /* Valid proto or NG_NAT_REDIRPROTO_ADDR */ 146fffba935SAlexander Motin uint16_t lsnat; /* LSNAT servers count */ 147fffba935SAlexander Motin char description[NG_NAT_DESC_LENGTH]; 148fffba935SAlexander Motin }; 149fffba935SAlexander Motin 150fffba935SAlexander Motin /* Keep this in sync with the above structure definition */ 151fffba935SAlexander Motin #define NG_NAT_LISTRDRS_ENTRY_TYPE_INFO(desctype) { \ 152fffba935SAlexander Motin { "id", &ng_parse_uint32_type }, \ 153fffba935SAlexander Motin { "local_addr", &ng_parse_ipaddr_type }, \ 154fffba935SAlexander Motin { "alias_addr", &ng_parse_ipaddr_type }, \ 155fffba935SAlexander Motin { "remote_addr", &ng_parse_ipaddr_type }, \ 156fffba935SAlexander Motin { "local_port", &ng_parse_uint16_type }, \ 157fffba935SAlexander Motin { "alias_port", &ng_parse_uint16_type }, \ 158fffba935SAlexander Motin { "remote_port", &ng_parse_uint16_type }, \ 159fffba935SAlexander Motin { "proto", &ng_parse_uint16_type }, \ 160fffba935SAlexander Motin { "lsnat", &ng_parse_uint16_type }, \ 161fffba935SAlexander Motin { "description", (desctype) }, \ 162fffba935SAlexander Motin { NULL } \ 163fffba935SAlexander Motin } 164fffba935SAlexander Motin 165fffba935SAlexander Motin /* Structure returned by NGM_NAT_LIST_REDIRECTS */ 166fffba935SAlexander Motin struct ng_nat_list_redirects { 167fffba935SAlexander Motin uint32_t total_count; 168fffba935SAlexander Motin struct ng_nat_listrdrs_entry redirects[]; 169fffba935SAlexander Motin }; 170fffba935SAlexander Motin 171fffba935SAlexander Motin /* Keep this in sync with the above structure definition */ 172fffba935SAlexander Motin #define NG_NAT_LIST_REDIRECTS_TYPE_INFO(redirtype) { \ 173fffba935SAlexander Motin { "total_count", &ng_parse_uint32_type }, \ 174fffba935SAlexander Motin { "redirects", (redirtype) }, \ 175fffba935SAlexander Motin { NULL } \ 176fffba935SAlexander Motin } 177fffba935SAlexander Motin 1785aedfa32SGleb Smirnoff /* Structure returned by NGM_NAT_LIBALIAS_INFO */ 1795aedfa32SGleb Smirnoff struct ng_nat_libalias_info { 1805aedfa32SGleb Smirnoff uint32_t icmpLinkCount; 1815aedfa32SGleb Smirnoff uint32_t udpLinkCount; 1825aedfa32SGleb Smirnoff uint32_t tcpLinkCount; 1835aedfa32SGleb Smirnoff uint32_t sctpLinkCount; 1845aedfa32SGleb Smirnoff uint32_t pptpLinkCount; 1855aedfa32SGleb Smirnoff uint32_t protoLinkCount; 1865aedfa32SGleb Smirnoff uint32_t fragmentIdLinkCount; 1875aedfa32SGleb Smirnoff uint32_t fragmentPtrLinkCount; 1885aedfa32SGleb Smirnoff uint32_t sockCount; 1895aedfa32SGleb Smirnoff }; 1905aedfa32SGleb Smirnoff 1915aedfa32SGleb Smirnoff /* Keep this in sync with the above structure definition */ 1925aedfa32SGleb Smirnoff #define NG_NAT_LIBALIAS_INFO { \ 1935aedfa32SGleb Smirnoff { "icmpLinkCount", &ng_parse_uint32_type }, \ 1945aedfa32SGleb Smirnoff { "udpLinkCount", &ng_parse_uint32_type }, \ 1955aedfa32SGleb Smirnoff { "tcpLinkCount", &ng_parse_uint32_type }, \ 1965aedfa32SGleb Smirnoff { "sctpLinkCount", &ng_parse_uint32_type }, \ 1975aedfa32SGleb Smirnoff { "pptpLinkCount", &ng_parse_uint32_type }, \ 1985aedfa32SGleb Smirnoff { "protoLinkCount", &ng_parse_uint32_type }, \ 1995aedfa32SGleb Smirnoff { "fragmentIdLinkCount", &ng_parse_uint32_type }, \ 2005aedfa32SGleb Smirnoff { "fragmentPtrLinkCount", &ng_parse_uint32_type }, \ 2015aedfa32SGleb Smirnoff { "sockCount", &ng_parse_uint32_type }, \ 2025aedfa32SGleb Smirnoff { NULL } \ 2035aedfa32SGleb Smirnoff } 2045aedfa32SGleb Smirnoff 205c4c9b52bSGleb Smirnoff enum { 206c4c9b52bSGleb Smirnoff NGM_NAT_SET_IPADDR = 1, 207e842c540SAlexander Motin NGM_NAT_SET_MODE, 208e842c540SAlexander Motin NGM_NAT_SET_TARGET, 209fffba935SAlexander Motin NGM_NAT_REDIRECT_PORT, 210fffba935SAlexander Motin NGM_NAT_REDIRECT_ADDR, 211fffba935SAlexander Motin NGM_NAT_REDIRECT_PROTO, 212fffba935SAlexander Motin NGM_NAT_REDIRECT_DYNAMIC, 213fffba935SAlexander Motin NGM_NAT_REDIRECT_DELETE, 214fffba935SAlexander Motin NGM_NAT_ADD_SERVER, 215fffba935SAlexander Motin NGM_NAT_LIST_REDIRECTS, 216fffba935SAlexander Motin NGM_NAT_PROXY_RULE, 2175aedfa32SGleb Smirnoff NGM_NAT_LIBALIAS_INFO, 2183ff4b317SEugene Grosbein NGM_NAT_SET_DLT, 2193ff4b317SEugene Grosbein NGM_NAT_GET_DLT, 220c4c9b52bSGleb Smirnoff }; 221