nat_misc.h
Go to the documentation of this file.
1 /**
2  * @file nat_misc.h
3  * @brief Helper functions for NAT
4  *
5  * @section License
6  *
7  * SPDX-License-Identifier: GPL-2.0-or-later
8  *
9  * Copyright (C) 2010-2026 Oryx Embedded SARL. All rights reserved.
10  *
11  * This file is part of CycloneTCP Open.
12  *
13  * This program is free software; you can redistribute it and/or
14  * modify it under the terms of the GNU General Public License
15  * as published by the Free Software Foundation; either version 2
16  * of the License, or (at your option) any later version.
17  *
18  * This program is distributed in the hope that it will be useful,
19  * but WITHOUT ANY WARRANTY; without even the implied warranty of
20  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21  * GNU General Public License for more details.
22  *
23  * You should have received a copy of the GNU General Public License
24  * along with this program; if not, write to the Free Software Foundation,
25  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
26  *
27  * @author Oryx Embedded SARL (www.oryx-embedded.com)
28  * @version 2.6.0
29  **/
30 
31 #ifndef _NAT_MISC_H
32 #define _NAT_MISC_H
33 
34 //Dependencies
35 #include "core/net.h"
36 #include "nat/nat.h"
37 
38 //C++ guard
39 #ifdef __cplusplus
40 extern "C" {
41 #endif
42 
43 //NAT related functions
44 void natTick(NatContext *context);
45 
48 
49 error_t natProcessPacket(NatContext *context, NetInterface *inInterface,
50  const Ipv4PseudoHeader *inPseudoHeader, const NetBuffer *inBuffer,
51  size_t inOffset, NetRxAncillary *ancillary);
52 
55 
56 error_t natForwardPacket(NatContext *context, const NatIpPacket *packet);
57 
59  const NatIpPacket *packet);
60 
61 NatSession *natMatchSession(NatContext *context, const NatIpPacket *packet);
62 
64 
65 uint16_t natAllocatePort(NatContext *context);
66 uint16_t natAllocateIcmpQueryId(NatContext *context);
67 
69 
71  const Ipv4PseudoHeader *pseudoHeader, const NetBuffer *buffer,
72  size_t offset);
73 
74 void natDumpPacket(const NatIpPacket *packet);
75 
76 //C++ guard
77 #ifdef __cplusplus
78 }
79 #endif
80 
81 #endif
NatPortFwdRule * natMatchPortFwdRule(NatContext *context, const NatIpPacket *packet)
Search the port forwarding rules for a matching entry.
Definition: nat_misc.c:601
int bool_t
Definition: compiler_port.h:63
uint16_t natAllocateIcmpQueryId(NatContext *context)
Allocate a new ICMP query identifier.
Definition: nat_misc.c:870
error_t natParseTransportHeader(NatIpPacket *packet)
Parse transport header (TCP, UDP or ICMP)
Definition: nat_misc.c:915
NatSession * natMatchSession(NatContext *context, const NatIpPacket *packet)
Search the NAT sessions for a matching entry.
Definition: nat_misc.c:663
error_t natForwardPacket(NatContext *context, const NatIpPacket *packet)
Forward an IP packet to the specified interface.
Definition: nat_misc.c:521
Structure describing a buffer that spans multiple chunks.
Definition: net_mem.h:89
error_t natTranslateOutboundPacket(NatContext *context, NatIpPacket *packet)
Perform address translation (outbound packet)
Definition: nat_misc.c:378
IP packet.
Definition: nat.h:118
error_t natProcessPacket(NatContext *context, NetInterface *inInterface, const Ipv4PseudoHeader *inPseudoHeader, const NetBuffer *inBuffer, size_t inOffset, NetRxAncillary *ancillary)
Process IP packet.
Definition: nat_misc.c:179
uint16_t natAllocatePort(NatContext *context)
Allocate a new port number.
Definition: nat_misc.c:824
error_t
Error codes.
Definition: error.h:43
error_t natTranslateInboundPacket(NatContext *context, NatIpPacket *packet)
Perform address translation (inbound packet)
Definition: nat_misc.c:313
error_t natTranslateTransportHeader(const NatIpPacket *packet, const Ipv4PseudoHeader *pseudoHeader, const NetBuffer *buffer, size_t offset)
Translate transport header (TCP, UDP or ICMP)
Definition: nat_misc.c:1019
NAT context.
Definition: nat.h:192
Port redirection rule.
Definition: nat.h:139
bool_t natIsPublicInterface(NatContext *context, NetInterface *interface)
Check whether a network interface is the WAN interface.
Definition: nat_misc.c:110
#define NetRxAncillary
Definition: net_misc.h:40
#define NetInterface
Definition: net.h:40
bool_t natIsPrivateInterface(NatContext *context, NetInterface *interface)
Check whether a network interface is a LAN interface.
Definition: nat_misc.c:139
NAT (IP Network Address Translator)
#define Ipv4PseudoHeader
Definition: ipv4.h:39
void natDumpPacket(const NatIpPacket *packet)
Dump IP packet for debugging purpose.
Definition: nat_misc.c:1108
TCP/IP stack core.
NatSession * natCreateSession(NatContext *context)
Create a new NAT session.
Definition: nat_misc.c:768
void natTick(NatContext *context)
NAT timer handler.
Definition: nat_misc.c:51
NAT session.
Definition: nat.h:155