NAT (IP Network Address Translator) More...
#include "core/net.h"Go to the source code of this file.
| Data Structures | |
| struct | NatIpPacket | 
| IP packet.  More... | |
| struct | NatPortFwdRule | 
| Port redirection rule.  More... | |
| struct | NatSession | 
| NAT session.  More... | |
| struct | NatSettings | 
| NAT settings.  More... | |
| struct | NatContext | 
| NAT context.  More... | |
| Macros | |
| #define | NAT_SUPPORT DISABLED | 
| #define | NAT_MAX_PRIVATE_INTERFACES 4 | 
| #define | NAT_TICK_INTERVAL 1000 | 
| #define | NAT_TCP_SESSION_TIMEOUT 120000 | 
| #define | NAT_UDP_SESSION_TIMEOUT 120000 | 
| #define | NAT_ICMP_SESSION_TIMEOUT 10000 | 
| #define | NAT_TCP_UDP_PORT_MIN 32768 | 
| #define | NAT_TCP_UDP_PORT_MAX 49151 | 
| #define | NAT_ICMP_QUERY_ID_MIN 32768 | 
| #define | NAT_ICMP_QUERY_ID_MAX 65535 | 
| Functions | |
| void | natGetDefaultSettings (NatSettings *settings) | 
| Initialize settings with default values.  More... | |
| error_t | natInit (NatContext *context, const NatSettings *settings) | 
| NAT initialization.  More... | |
| error_t | natSetPublicInterface (NatContext *context, NetInterface *publicInterface) | 
| Specify the NAT public interface.  More... | |
| error_t | natSetPortFwdRule (NatContext *context, uint_t index, Ipv4Protocol protocol, uint16_t publicPort, NetInterface *privateInterface, Ipv4Addr privateIpAddr, uint16_t privatePort) | 
| Add port redirection rule.  More... | |
| error_t | natSetPortRangeFwdRule (NatContext *context, uint_t index, Ipv4Protocol protocol, uint16_t publicPortMin, uint16_t publicPortMax, NetInterface *privateInterface, Ipv4Addr privateIpAddr, uint16_t privatePortMin) | 
| Add port range redirection rule.  More... | |
| error_t | natClearPortFwdRule (NatContext *context, uint_t index) | 
| Remove port redirection rule.  More... | |
| error_t | natStart (NatContext *context) | 
| Start NAT operation.  More... | |
| error_t | natStop (NatContext *context) | 
| Stop NAT operation.  More... | |
| void | natDeinit (NatContext *context) | 
| Release NAT context.  More... | |
Detailed Description
NAT (IP Network Address Translator)
License
SPDX-License-Identifier: GPL-2.0-or-later
Copyright (C) 2010-2025 Oryx Embedded SARL. All rights reserved.
This file is part of CycloneTCP Open.
This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- Version
- 2.5.4
Definition in file nat.h.
Macro Definition Documentation
◆ NAT_ICMP_QUERY_ID_MAX
◆ NAT_ICMP_QUERY_ID_MIN
◆ NAT_ICMP_SESSION_TIMEOUT
◆ NAT_MAX_PRIVATE_INTERFACES
◆ NAT_SUPPORT
◆ NAT_TCP_SESSION_TIMEOUT
◆ NAT_TCP_UDP_PORT_MAX
◆ NAT_TCP_UDP_PORT_MIN
◆ NAT_TICK_INTERVAL
◆ NAT_UDP_SESSION_TIMEOUT
Function Documentation
◆ natClearPortFwdRule()
| error_t natClearPortFwdRule | ( | NatContext * | context, | 
| uint_t | index | ||
| ) | 
◆ natDeinit()
| void natDeinit | ( | NatContext * | context | ) | 
◆ natGetDefaultSettings()
| void natGetDefaultSettings | ( | NatSettings * | settings | ) | 
◆ natInit()
| error_t natInit | ( | NatContext * | context, | 
| const NatSettings * | settings | ||
| ) | 
◆ natSetPortFwdRule()
| error_t natSetPortFwdRule | ( | NatContext * | context, | 
| uint_t | index, | ||
| Ipv4Protocol | protocol, | ||
| uint16_t | publicPort, | ||
| NetInterface * | privateInterface, | ||
| Ipv4Addr | privateIpAddr, | ||
| uint16_t | privatePort | ||
| ) | 
Add port redirection rule.
- Parameters
- 
  [in] context Pointer to the NAT context [in] index Zero-based index identifying a given entry [in] protocol Transport protocol (IPV4_PROTOCOL_TCP or IPV4_PROTOCOL_UDP) [in] publicPort Public port to be redirected [in] privateInterface Destination interface [in] privateIpAddr Destination IP address [in] privatePort Destination port 
- Returns
- Error code
◆ natSetPortRangeFwdRule()
| error_t natSetPortRangeFwdRule | ( | NatContext * | context, | 
| uint_t | index, | ||
| Ipv4Protocol | protocol, | ||
| uint16_t | publicPortMin, | ||
| uint16_t | publicPortMax, | ||
| NetInterface * | privateInterface, | ||
| Ipv4Addr | privateIpAddr, | ||
| uint16_t | privatePortMin | ||
| ) | 
Add port range redirection rule.
- Parameters
- 
  [in] context Pointer to the NAT context [in] index Zero-based index identifying a given entry [in] protocol Transport protocol (IPV4_PROTOCOL_TCP or IPV4_PROTOCOL_UDP) [in] publicPortMin Public port range to be redirected (lower value) [in] publicPortMax Public port range to be redirected (upper value) [in] privateInterface Destination interface [in] privateIpAddr Destination IP address [in] privatePortMin Destination port (lower value) 
- Returns
- Error code
◆ natSetPublicInterface()
| error_t natSetPublicInterface | ( | NatContext * | context, | 
| NetInterface * | publicInterface | ||
| ) | 
◆ natStart()
| error_t natStart | ( | NatContext * | context | ) | 
◆ natStop()
| error_t natStop | ( | NatContext * | context | ) | 
