Helper functions for NAT. More...
Go to the source code of this file.
| Functions | |
| void | natTick (NatContext *context) | 
| NAT timer handler.  More... | |
| bool_t | natIsPublicInterface (NatContext *context, NetInterface *interface) | 
| Check whether a network interface is the WAN interface.  More... | |
| bool_t | natIsPrivateInterface (NatContext *context, NetInterface *interface) | 
| Check whether a network interface is a LAN interface.  More... | |
| error_t | natProcessPacket (NatContext *context, NetInterface *inInterface, const Ipv4PseudoHeader *inPseudoHeader, const NetBuffer *inBuffer, size_t inOffset, NetRxAncillary *ancillary) | 
| Process IP packet.  More... | |
| error_t | natTranslateInboundPacket (NatContext *context, NatIpPacket *packet) | 
| Perform address translation (inbound packet)  More... | |
| error_t | natTranslateOutboundPacket (NatContext *context, NatIpPacket *packet) | 
| Perform address translation (outbound packet)  More... | |
| error_t | natForwardPacket (NatContext *context, const NatIpPacket *packet) | 
| Forward an IP packet to the specified interface.  More... | |
| NatPortFwdRule * | natMatchPortFwdRule (NatContext *context, const NatIpPacket *packet) | 
| Search the port forwarding rules for a matching entry.  More... | |
| NatSession * | natMatchSession (NatContext *context, const NatIpPacket *packet) | 
| Search the NAT sessions for a matching entry.  More... | |
| NatSession * | natCreateSession (NatContext *context) | 
| Create a new NAT session.  More... | |
| uint16_t | natAllocatePort (NatContext *context) | 
| Allocate a new port number.  More... | |
| uint16_t | natAllocateIcmpQueryId (NatContext *context) | 
| Allocate a new ICMP query identifier.  More... | |
| error_t | natParseTransportHeader (NatIpPacket *packet) | 
| Parse transport header (TCP, UDP or ICMP)  More... | |
| error_t | natTranslateTransportHeader (const NatIpPacket *packet, const Ipv4PseudoHeader *pseudoHeader, const NetBuffer *buffer, size_t offset) | 
| Translate transport header (TCP, UDP or ICMP)  More... | |
| void | natDumpPacket (const NatIpPacket *packet) | 
| Dump IP packet for debugging purpose.  More... | |
| Variables | |
| systime_t | natTickCounter | 
Detailed Description
Helper functions for NAT.
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_misc.h.
Function Documentation
◆ natAllocateIcmpQueryId()
| uint16_t natAllocateIcmpQueryId | ( | NatContext * | context | ) | 
Allocate a new ICMP query identifier.
- Parameters
- 
  [in] context Pointer to the NAT context 
- Returns
- ICMP query identifier
Definition at line 872 of file nat_misc.c.
◆ natAllocatePort()
| uint16_t natAllocatePort | ( | NatContext * | context | ) | 
Allocate a new port number.
- Parameters
- 
  [in] context Pointer to the NAT context 
- Returns
- Port number
Definition at line 827 of file nat_misc.c.
◆ natCreateSession()
| NatSession* natCreateSession | ( | NatContext * | context | ) | 
Create a new NAT session.
- Parameters
- 
  [in] context Pointer to the NAT context 
- Returns
- Pointer to the newly created session
Definition at line 771 of file nat_misc.c.
◆ natDumpPacket()
| void natDumpPacket | ( | const NatIpPacket * | packet | ) | 
Dump IP packet for debugging purpose.
- Parameters
- 
  [in] packet IP packet 
Definition at line 1110 of file nat_misc.c.
◆ natForwardPacket()
| error_t natForwardPacket | ( | NatContext * | context, | 
| const NatIpPacket * | packet | ||
| ) | 
Forward an IP packet to the specified interface.
- Parameters
- 
  [in] context Pointer to the NAT context [in] packet IP packet 
- Returns
- Error code
Definition at line 524 of file nat_misc.c.
◆ natIsPrivateInterface()
| bool_t natIsPrivateInterface | ( | NatContext * | context, | 
| NetInterface * | interface | ||
| ) | 
Check whether a network interface is a LAN interface.
- Parameters
- 
  [in] context Pointer to the NAT context [in] interface Pointer to a network interface 
- Returns
- TRUE if the specified interface is a LAN interface, else FALSE
Definition at line 142 of file nat_misc.c.
◆ natIsPublicInterface()
| bool_t natIsPublicInterface | ( | NatContext * | context, | 
| NetInterface * | interface | ||
| ) | 
Check whether a network interface is the WAN interface.
- Parameters
- 
  [in] context Pointer to the NAT context [in] interface Pointer to a network interface 
- Returns
- TRUE if the specified interface is the WAN interface, else FALSE
Definition at line 113 of file nat_misc.c.
◆ natMatchPortFwdRule()
| NatPortFwdRule* natMatchPortFwdRule | ( | NatContext * | context, | 
| const NatIpPacket * | packet | ||
| ) | 
Search the port forwarding rules for a matching entry.
- Parameters
- 
  [in] context Pointer to the NAT context [in] packet IP packet 
- Returns
- Pointer to the matching port forwarding rule, if any
Definition at line 604 of file nat_misc.c.
◆ natMatchSession()
| NatSession* natMatchSession | ( | NatContext * | context, | 
| const NatIpPacket * | packet | ||
| ) | 
Search the NAT sessions for a matching entry.
- Parameters
- 
  [in] context Pointer to the NAT context [in] packet IP packet 
- Returns
- Pointer to the matching session, if any
Definition at line 666 of file nat_misc.c.
◆ natParseTransportHeader()
| error_t natParseTransportHeader | ( | NatIpPacket * | packet | ) | 
Parse transport header (TCP, UDP or ICMP)
- Parameters
- 
  [in,out] packet IP packet 
- Returns
- Error code
Definition at line 916 of file nat_misc.c.
◆ natProcessPacket()
| error_t natProcessPacket | ( | NatContext * | context, | 
| NetInterface * | inInterface, | ||
| const Ipv4PseudoHeader * | inPseudoHeader, | ||
| const NetBuffer * | inBuffer, | ||
| size_t | inOffset, | ||
| NetRxAncillary * | ancillary | ||
| ) | 
Process IP packet.
- Parameters
- 
  [in] context Pointer to the NAT context [in] inInterface Pointer to the interface where the packet was received [in] inPseudoHeader Pointer to the pseudo header [in] inBuffer Multi-part buffer that holds the incoming IP packet [in] inOffset Packet Offset to the payload of the IP packet [in] ancillary Additional options passed to the stack along with the packet 
- Returns
- Error code
Definition at line 182 of file nat_misc.c.
◆ natTick()
| void natTick | ( | NatContext * | context | ) | 
NAT timer handler.
- Parameters
- 
  [in] context Pointer to the NAT context 
Definition at line 54 of file nat_misc.c.
◆ natTranslateInboundPacket()
| error_t natTranslateInboundPacket | ( | NatContext * | context, | 
| NatIpPacket * | packet | ||
| ) | 
Perform address translation (inbound packet)
- Parameters
- 
  [in] context Pointer to the NAT context [in] packet IP packet 
- Returns
- Error code
Definition at line 316 of file nat_misc.c.
◆ natTranslateOutboundPacket()
| error_t natTranslateOutboundPacket | ( | NatContext * | context, | 
| NatIpPacket * | packet | ||
| ) | 
Perform address translation (outbound packet)
- Parameters
- 
  [in] context Pointer to the NAT context [in] packet IP packet 
- Returns
- Error code
Definition at line 381 of file nat_misc.c.
◆ natTranslateTransportHeader()
| error_t natTranslateTransportHeader | ( | const NatIpPacket * | packet, | 
| const Ipv4PseudoHeader * | pseudoHeader, | ||
| const NetBuffer * | buffer, | ||
| size_t | offset | ||
| ) | 
Translate transport header (TCP, UDP or ICMP)
- Parameters
- 
  [in] packet IP packet [in] pseudoHeader Pointer to the pseudo header [in] buffer Multi-part buffer that holds the IP packet [in] offset Packet Offset to the payload of the IP packet 
- Returns
- Error code
Definition at line 1021 of file nat_misc.c.
Variable Documentation
◆ natTickCounter
| 
 | extern | 
Definition at line 46 of file nat_misc.c.
