|
INET Framework for OMNeT++/OMNEST
|
#include <Ipv4NatTable.h>
◆ ~Ipv4NatTable()
| inet::Ipv4NatTable::~Ipv4NatTable |
( |
| ) |
|
|
virtual |
33 delete it.second.first;
◆ datagramForwardHook()
| virtual Result inet::Ipv4NatTable::datagramForwardHook |
( |
Packet * |
datagram | ) |
|
|
inlineoverridevirtual |
This is the second hook called by the network protocol before it sends a datagram to the lower layer.
This is done after the datagramPreRoutingHook or the datagramLocalInHook is called and the datagram is routed.
Implements inet::INetfilter::IHook.
◆ datagramLocalInHook()
| virtual Result inet::Ipv4NatTable::datagramLocalInHook |
( |
Packet * |
datagram | ) |
|
|
inlineoverridevirtual |
This is the last hook called by the network protocol before it sends a datagram to the upper layer.
This is done after the datagramPreRoutingHook is called and the datagram is routed.
Implements inet::INetfilter::IHook.
◆ datagramLocalOutHook()
| virtual Result inet::Ipv4NatTable::datagramLocalOutHook |
( |
Packet * |
datagram | ) |
|
|
inlineoverridevirtual |
This is the first hook called by the network protocol before it routes a datagram that was received from the upper layer.
The nextHopAddress is ignored when the outputNetworkInterface is a nullptr. After this is done
Implements inet::INetfilter::IHook.
◆ datagramPostRoutingHook()
| virtual Result inet::Ipv4NatTable::datagramPostRoutingHook |
( |
Packet * |
datagram | ) |
|
|
inlineoverridevirtual |
This is the last hook called by the network protocol before it sends a datagram to the lower layer.
Implements inet::INetfilter::IHook.
◆ datagramPreRoutingHook()
| virtual Result inet::Ipv4NatTable::datagramPreRoutingHook |
( |
Packet * |
datagram | ) |
|
|
inlineoverridevirtual |
This is the first hook called by the network protocol before it routes a datagram that was received from the lower layer.
The nextHopAddress is ignored when the outputNetworkInterface is nullptr.
Implements inet::INetfilter::IHook.
◆ handleMessage()
| void inet::Ipv4NatTable::handleMessage |
( |
cMessage * |
message | ) |
|
|
overrideprotectedvirtual |
54 throw cRuntimeError(
"This module can not handle messages");
◆ initialize()
| void inet::Ipv4NatTable::initialize |
( |
int |
stage | ) |
|
|
overrideprotectedvirtual |
38 cSimpleModule::initialize(stage);
47 auto text = std::to_string(
natEntries.size()) +
" entries";
48 getDisplayString().setTagArg(
"t", 0, text.c_str());
◆ numInitStages()
| virtual int inet::Ipv4NatTable::numInitStages |
( |
| ) |
const |
|
inlineoverrideprotectedvirtual |
◆ parseConfig()
| void inet::Ipv4NatTable::parseConfig |
( |
| ) |
|
|
protectedvirtual |
59 cXMLElementList xmlEntries =
config->getChildrenByTagName(
"entry");
60 for (
auto& xmlEntry : xmlEntries) {
62 const char *typeAttr = xmlEntry->getAttribute(
"type");
64 if (!strcmp(
"prerouting", typeAttr))
66 else if (!strcmp(
"localin", typeAttr))
68 else if (!strcmp(
"forward", typeAttr))
70 else if (!strcmp(
"postrouting", typeAttr))
72 else if (!strcmp(
"localout", typeAttr))
75 throw cRuntimeError(
"Unknown type");
77 PacketFilter *packetFilter =
new PacketFilter();
78 const char *packetFilterAttr = xmlEntry->getAttribute(
"packetFilter");
79 packetFilter->setExpression(packetFilterAttr !=
nullptr ? packetFilterAttr :
"*");
81 Ipv4NatEntry natEntry;
82 const char *destAddressAttr = xmlEntry->getAttribute(
"destAddress");
83 if (destAddressAttr !=
nullptr && *destAddressAttr !=
'\0')
84 natEntry.setDestAddress(Ipv4Address(destAddressAttr));
85 const char *destPortAttr = xmlEntry->getAttribute(
"destPort");
86 if (destPortAttr !=
nullptr && *destPortAttr !=
'\0')
87 natEntry.setDestPort(atoi(destPortAttr));
88 const char *srcAddressAttr = xmlEntry->getAttribute(
"srcAddress");
89 if (srcAddressAttr !=
nullptr && *srcAddressAttr !=
'\0')
90 natEntry.setSrcAddress(Ipv4Address(srcAddressAttr));
91 const char *srcPortAttr = xmlEntry->getAttribute(
"srcPort");
92 if (srcPortAttr !=
nullptr && *srcPortAttr !=
'\0')
93 natEntry.setSrcPort(atoi(srcPortAttr));
Referenced by initialize().
◆ processPacket()
104 for (; lt != ut; lt++) {
105 const auto& packetFilter = lt->second.first;
106 const auto& natEntry = lt->second.second;
108 if (packetFilter->matches(packet)) {
109 auto& ipv4Header = removeNetworkProtocolHeader<Ipv4Header>(packet);
110 if (!natEntry.getDestAddress().isUnspecified())
111 ipv4Header->setDestAddress(natEntry.getDestAddress());
112 if (!natEntry.getSrcAddress().isUnspecified())
113 ipv4Header->setSrcAddress(natEntry.getSrcAddress());
114 auto transportProtocol = ipv4Header->getProtocol();
117 auto& udpHeader = removeTransportProtocolHeader<UdpHeader>(packet);
119 auto udpData = packet->peekData();
120 if (natEntry.getDestPort() != -1)
121 udpHeader->setDestPort(natEntry.getDestPort());
122 if (natEntry.getSrcPort() != -1)
123 udpHeader->setSrcPort(natEntry.getSrcPort());
129 #ifdef INET_WITH_TCP_COMMON
131 auto& tcpHeader = removeTransportProtocolHeader<tcp::TcpHeader>(packet);
133 if (natEntry.getDestPort() != -1)
134 tcpHeader->setDestPort(natEntry.getDestPort());
135 if (natEntry.getSrcPort() != -1)
136 tcpHeader->setSrcPort(natEntry.getSrcPort());
142 throw cRuntimeError(
"Unknown protocol: '%s'", transportProtocol ? transportProtocol->getName() : std::to_string((
int)ipv4Header->getProtocolId()).c_str());
◆ config
| cXMLElement* inet::Ipv4NatTable::config = nullptr |
|
protected |
◆ natEntries
◆ networkProtocol
The documentation for this class was generated from the following files:
Type
Definition: INetfilter.h:31
virtual void parseConfig()
Definition: Ipv4NatTable.cc:57
static void insertCrc(const Protocol *networkProtocol, const L3Address &srcAddress, const L3Address &destAddress, const Ptr< TcpHeader > &tcpHeader, Packet *tcpPayload)
Definition: TcpCrcInsertionHook.cc:47
static const Protocol tcp
Definition: Protocol.h:112
static const Protocol ipv4
Definition: Protocol.h:93
INET_API InitStage INITSTAGE_NETWORK_LAYER
Initialization of network layer protocols.
@ FORWARD
Definition: INetfilter.h:34
void insertNetworkProtocolHeader(Packet *packet, const Protocol &protocol, const Ptr< NetworkHeaderBase > &header)
Definition: L3Tools.cc:70
static void insertCrc(const Protocol *networkProtocol, const L3Address &srcAddress, const L3Address &destAddress, const Ptr< UdpHeader > &udpHeader, Packet *udpPayload)
Definition: Udp.cc:809
virtual Result processPacket(Packet *packet, INetfilter::IHook::Type type)
Definition: Ipv4NatTable.cc:99
static const Protocol udp
Definition: Protocol.h:117
void insertTransportProtocolHeader(Packet *packet, const Protocol &protocol, const Ptr< TransportHeaderBase > &header)
Definition: L4Tools.cc:77
ModuleRefByPar< INetfilter > networkProtocol
Definition: Ipv4NatTable.h:22
removed type
Definition: IUdp-gates.txt:7
INET_API InitStage INITSTAGE_LOCAL
Initialization of local state that don't use or affect other modules includes:
#define NUM_INIT_STAGES
Definition: InitStageRegistry.h:73
@ PREROUTING
Definition: INetfilter.h:32
cXMLElement * config
Definition: Ipv4NatTable.h:21
#define Enter_Method(...)
Definition: SelfDoc.h:71
@ ACCEPT
allows the datagram to pass to the next hook
Definition: INetfilter.h:40
@ LOCALIN
Definition: INetfilter.h:33
@ POSTROUTING
Definition: INetfilter.h:35
@ LOCALOUT
Definition: INetfilter.h:36
std::multimap< INetfilter::IHook::Type, std::pair< PacketFilter *, Ipv4NatEntry > > natEntries
Definition: Ipv4NatTable.h:24