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 outputInterfaceEntry is nullptr.
126 dgram = check_and_cast<IPv4Datagram *>(datagram);
132 SCTPMessage *sctpMsg = check_and_cast<SCTPMessage *>(dgram->getEncapsulatedPacket());
133 unsigned int numberOfChunks = sctpMsg->getChunksArraySize();
134 if (numberOfChunks == 1)
135 chunk = (SCTPChunk *)(sctpMsg->peekFirstChunk());
137 chunk = (SCTPChunk *)(sctpMsg->peekLastChunk());
139 entry =
natTable->
getEntry(dgram->getSrcAddress(), sctpMsg->getSrcPort(), dgram->getDestAddress(), sctpMsg->getDestPort(), sctpMsg->getTag());
140 EV <<
"getEntry for " << dgram->getSrcAddress() <<
":" << sctpMsg->getSrcPort() <<
" to " << dgram->getDestAddress() <<
":" << sctpMsg->getDestPort() <<
" peerVTag=" << sctpMsg->getTag() <<
"\n";
141 uint32 numberOfChunks = sctpMsg->getChunksArraySize();
142 if (entry ==
nullptr) {
143 EV <<
"no entry found\n";
144 if (numberOfChunks == 1)
145 chunk = (SCTPChunk *)(sctpMsg->peekFirstChunk());
147 chunk = (SCTPChunk *)(sctpMsg->peekLastChunk());
148 if (chunk->getChunkType() ==
INIT || chunk->getChunkType() ==
ASCONF) {
149 EV <<
"could be an Init collision\n";
150 entry =
natTable->
getSpecialEntry(dgram->getSrcAddress(), sctpMsg->getSrcPort(), dgram->getDestAddress(), sctpMsg->getDestPort());
151 if (entry !=
nullptr) {
152 if (chunk->getChunkType() ==
INIT) {
153 SCTPInitChunk *initChunk = check_and_cast<SCTPInitChunk *>(chunk);
155 EV <<
"InitTag=" << initChunk->getInitTag() <<
"\n";
157 else if (chunk->getChunkType() ==
ASCONF) {
158 SCTPAsconfChunk *asconfChunk = check_and_cast<SCTPAsconfChunk *>(chunk);
159 entry->setLocalVTag(asconfChunk->getPeerVTag());
161 dgram->setDestAddress(entry->getLocalAddress().toIPv4());
162 sctpMsg->setDestPort(entry->getLocalPort());
163 EV <<
"destAddress set to " << dgram->getDestAddress() <<
", destPort set to " << sctpMsg->getDestPort() <<
"\n";
171 if (numberOfChunks > 0) {
172 EV <<
"number of chunks=" << numberOfChunks <<
"\n";
173 for (
uint32 i = 0; i < numberOfChunks; i++) {
174 schunk = (SCTPChunk *)(sctpMsg->removeChunk());
175 if (schunk->getChunkType() ==
DATA)
176 delete (SCTPSimpleMessage *)schunk->decapsulate();
177 EV <<
"delete chunk " << schunk->getName() <<
"\n";
185 dgram->setDestAddress(entry->getLocalAddress().toIPv4());
186 sctpMsg->setDestPort(entry->getLocalPort());
187 if (entry->getGlobalVTag() == 0 && chunk->getChunkType() ==
INIT_ACK) {
188 SCTPInitAckChunk *initAckChunk = check_and_cast<SCTPInitAckChunk *>(chunk);
189 entry->setGlobalVTag(initAckChunk->getInitTag());
191 EV <<
"destAddress set to " << dgram->getDestAddress() <<
", destPort set to " << sctpMsg->getDestPort() <<
"\n";
195 if (chunk->getChunkType() ==
INIT) {
196 EV <<
"getLocALEntry for " << dgram->getSrcAddress() <<
":" << sctpMsg->getSrcPort() <<
" to " << dgram->getDestAddress() <<
":" << sctpMsg->getDestPort() <<
" peerVTag=" << sctpMsg->getTag() <<
"\n";
198 if (entry ==
nullptr) {
199 entry =
new SCTPNatEntry();
200 entry->setLocalAddress(dgram->getSrcAddress());
201 entry->setLocalPort(sctpMsg->getSrcPort());
202 entry->setGlobalAddress(dgram->getDestAddress());
203 entry->setGlobalPort(sctpMsg->getDestPort());
204 entry->setNattedPort(sctpMsg->getSrcPort());
205 entry->setNattedAddress(dgram->getDestAddress());
206 SCTPInitChunk *initChunk = check_and_cast<SCTPInitChunk *>(chunk);
207 entry->setGlobalVTag(initChunk->getInitTag());
209 EV <<
"added entry for local deliver\n";
214 SCTPNatEntry *entry2 =
new SCTPNatEntry();
215 entry2->setLocalAddress(dgram->getSrcAddress());
216 entry2->setLocalPort(sctpMsg->getSrcPort());
217 entry2->setGlobalAddress(entry->getGlobalAddress());
218 entry2->setGlobalPort(sctpMsg->getDestPort());
219 entry2->setNattedPort(sctpMsg->getSrcPort());
220 entry2->setNattedAddress(entry->getGlobalAddress());
221 SCTPInitChunk *initChunk = check_and_cast<SCTPInitChunk *>(chunk);
222 entry2->setGlobalVTag(initChunk->getInitTag());
224 dgram->setDestAddress(entry->getLocalAddress().toIPv4());
225 sctpMsg->setDestPort(entry->getLocalPort());
226 dgram->setSrcAddress(entry->getGlobalAddress().toIPv4());
227 sctpMsg->setSrcPort(entry->getGlobalPort());
228 EV <<
"added additional entry for local deliver\n";
230 EV <<
"destAddress set to " << dgram->getDestAddress() <<
", destPort set to " << sctpMsg->getDestPort() <<
"\n";
234 EV <<
"no INIT: destAddr=" << dgram->getDestAddress() <<
" destPort=" << sctpMsg->getDestPort() <<
" srcPort=" << sctpMsg->getSrcPort() <<
" vTag=" << sctpMsg->getTag() <<
"\n";
235 entry =
natTable->
getLocalEntry(dgram->getDestAddress(), sctpMsg->getSrcPort(), sctpMsg->getDestPort(), sctpMsg->getTag());
236 if (entry !=
nullptr) {
237 dgram->setDestAddress(entry->getLocalAddress().toIPv4());
238 sctpMsg->setDestPort(entry->getLocalPort());
239 dgram->setSrcAddress(entry->getGlobalAddress().toIPv4());
240 sctpMsg->setSrcPort(entry->getGlobalPort());
243 EV <<
"no entry found\n";
SCTPNatEntryTable natEntries
Definition: SCTPNatTable.h:74
Definition: SCTPAssociation.h:111
doesn't allow the datagram to pass to the next hook, will be deleted
Definition: INetfilter.h:51
uint64 nattedPackets
Definition: SCTPNatHook.h:21
virtual bool isLocalAddress(const L3Address &dest) const =0
Checks if the address is a local one, i.e.
void printNatTable()
Definition: SCTPNatTable.cc:133
Definition: SCTPAssociation.h:130
SCTPNatEntry * getSpecialEntry(L3Address globalAddr, uint16 globalPrt, L3Address nattedAddr, uint16 nattedPrt)
Definition: SCTPNatTable.cc:77
allows the datagram to pass to the next hook
Definition: INetfilter.h:50
Definition: SCTPAssociation.h:112
uint32_t uint32
Definition: Compat.h:30
static int getAddressLevel(const L3Address &addr)
Utility: return IPv4 or IPv6 address level.
Definition: SCTPAssociationUtil.cc:2814
SCTPNatEntry * getLocalInitEntry(L3Address globalAddr, uint16 localPrt, uint16 globalPrt)
Definition: SCTPNatTable.cc:93
SCTPNatTable * natTable
Definition: SCTPNatHook.h:18
SCTPNatEntry * getLocalEntry(L3Address globalAddr, uint16 localPrt, uint16 globalPrt, uint32 localVtag)
Definition: SCTPNatTable.cc:106
Definition: SCTPAssociation.h:113
IRoutingTable * rt
Definition: SCTPNatHook.h:19
void setLocalVTag(uint32 tag)
Definition: SCTPNatTable.h:55
SCTPNatEntry * getEntry(L3Address globalAddr, uint16 globalPrt, L3Address nattedAddr, uint16 nattedPrt, uint32 localVtag)
Definition: SCTPNatTable.cc:62