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-2025 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.5.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 //Tick counter to handle periodic operations
45 
46 //NAT related functions
47 void natTick(NatContext *context);
48 
51 
52 error_t natProcessPacket(NatContext *context, NetInterface *inInterface,
53  const Ipv4PseudoHeader *inPseudoHeader, const NetBuffer *inBuffer,
54  size_t inOffset, NetRxAncillary *ancillary);
55 
58 
59 error_t natForwardPacket(NatContext *context, const NatIpPacket *packet);
60 
62  const NatIpPacket *packet);
63 
64 NatSession *natMatchSession(NatContext *context, const NatIpPacket *packet);
65 
67 
68 uint16_t natAllocatePort(NatContext *context);
69 uint16_t natAllocateIcmpQueryId(NatContext *context);
70 
72 
74  const Ipv4PseudoHeader *pseudoHeader, const NetBuffer *buffer,
75  size_t offset);
76 
77 void natDumpPacket(const NatIpPacket *packet);
78 
79 //C++ guard
80 #ifdef __cplusplus
81 }
82 #endif
83 
84 #endif
NatPortFwdRule * natMatchPortFwdRule(NatContext *context, const NatIpPacket *packet)
Search the port forwarding rules for a matching entry.
Definition: nat_misc.c:604
int bool_t
Definition: compiler_port.h:61
uint16_t natAllocateIcmpQueryId(NatContext *context)
Allocate a new ICMP query identifier.
Definition: nat_misc.c:872
error_t natParseTransportHeader(NatIpPacket *packet)
Parse transport header (TCP, UDP or ICMP)
Definition: nat_misc.c:916
NatSession * natMatchSession(NatContext *context, const NatIpPacket *packet)
Search the NAT sessions for a matching entry.
Definition: nat_misc.c:666
error_t natForwardPacket(NatContext *context, const NatIpPacket *packet)
Forward an IP packet to the specified interface.
Definition: nat_misc.c:524
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:381
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:182
uint16_t natAllocatePort(NatContext *context)
Allocate a new port number.
Definition: nat_misc.c:827
error_t
Error codes.
Definition: error.h:43
error_t natTranslateInboundPacket(NatContext *context, NatIpPacket *packet)
Perform address translation (inbound packet)
Definition: nat_misc.c:316
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:1021
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:113
#define NetRxAncillary
Definition: net_misc.h:40
#define NetInterface
Definition: net.h:36
systime_t natTickCounter
Definition: nat_misc.c:46
bool_t natIsPrivateInterface(NatContext *context, NetInterface *interface)
Check whether a network interface is a LAN interface.
Definition: nat_misc.c:142
NAT (IP Network Address Translator)
#define Ipv4PseudoHeader
Definition: ipv4.h:39
uint32_t systime_t
System time.
void natDumpPacket(const NatIpPacket *packet)
Dump IP packet for debugging purpose.
Definition: nat_misc.c:1110
TCP/IP stack core.
NatSession * natCreateSession(NatContext *context)
Create a new NAT session.
Definition: nat_misc.c:771
void natTick(NatContext *context)
NAT timer handler.
Definition: nat_misc.c:54
NAT session.
Definition: nat.h:155