Path: blob/main/sys/netpfil/ipfw/nat64/ip_fw_nat64.h
39507 views
/*-1* SPDX-License-Identifier: BSD-2-Clause2*3* Copyright (c) 2015-2019 Yandex LLC4* Copyright (c) 2015-2019 Andrey V. Elsukov <[email protected]>5*6* Redistribution and use in source and binary forms, with or without7* modification, are permitted provided that the following conditions8* are met:9*10* 1. Redistributions of source code must retain the above copyright11* notice, this list of conditions and the following disclaimer.12* 2. Redistributions in binary form must reproduce the above copyright13* notice, this list of conditions and the following disclaimer in the14* documentation and/or other materials provided with the distribution.15*16* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR17* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES18* 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, BUT21* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,22* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY23* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT24* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF25* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.26*/2728#ifndef _IP_FW_NAT64_H_29#define _IP_FW_NAT64_H_3031#define DPRINTF(mask, fmt, ...) \32if (V_nat64_debug & (mask)) \33printf("NAT64: %s: " fmt "\n", __func__, ## __VA_ARGS__)34#define DP_GENERIC 0x000135#define DP_OBJ 0x000236#define DP_JQUEUE 0x000437#define DP_STATE 0x000838#define DP_DROPS 0x001039#define DP_ALL 0xFFFF4041VNET_DECLARE(int, nat64_debug);42#define V_nat64_debug VNET(nat64_debug)4344#if 045#define NAT64NOINLINE __noinline46#else47#define NAT64NOINLINE48#endif4950int nat64stl_init(struct ip_fw_chain *ch, int first);51void nat64stl_uninit(struct ip_fw_chain *ch, int last);52int nat64lsn_init(struct ip_fw_chain *ch, int first);53void nat64lsn_uninit(struct ip_fw_chain *ch, int last);54int nat64clat_init(struct ip_fw_chain *ch, int first);55void nat64clat_uninit(struct ip_fw_chain *ch, int last);5657#define NAT64_DEFINE_OPCODE_REWRITER(mod, name, ops) \58static int \59mod ## _classify(ipfw_insn *cmd0, uint32_t *puidx, uint8_t *ptype) \60{ \61ipfw_insn *icmd; \62icmd = cmd0 - F_LEN(cmd0); \63if (icmd->opcode != O_EXTERNAL_ACTION || \64insntod(icmd, kidx)->kidx != V_ ## mod ## _eid) \65return (1); \66*puidx = insntod(cmd0, kidx)->kidx; \67*ptype = 0; \68return (0); \69} \70static void \71mod ## _update_kidx(ipfw_insn *cmd0, uint32_t idx) \72{ \73insntod(cmd0, kidx)->kidx = idx; \74} \75static int \76mod ## _findbyname(struct ip_fw_chain *ch, struct tid_info *ti, \77struct named_object **pno) \78{ \79return (ipfw_objhash_find_type(CHAIN_TO_SRV(ch), ti, \80IPFW_TLV_## name ## _NAME, pno)); \81} \82static struct named_object * \83mod ## _findbykidx(struct ip_fw_chain *ch, uint32_t idx) \84{ \85struct namedobj_instance *ni; \86struct named_object *no; \87IPFW_UH_WLOCK_ASSERT(ch); \88ni = CHAIN_TO_SRV(ch); \89no = ipfw_objhash_lookup_kidx(ni, idx); \90KASSERT(no != NULL, ("NAT with index %u not found", idx)); \91return (no); \92} \93static struct opcode_obj_rewrite ops[] = { \94{ \95.opcode = O_EXTERNAL_INSTANCE, \96.etlv = IPFW_TLV_EACTION /* just show it isn't table */,\97.classifier = mod ## _classify, \98.update = mod ## _update_kidx, \99.find_byname = mod ## _findbyname, \100.find_bykidx = mod ## _findbykidx, \101.manage_sets = mod ## _manage_sets, \102}, \103}104105#endif /* _IP_FW_NAT64_H_ */106107108