Skip to content

Commit 0b069a9

Browse files
committed
Icmp: remove inputInterfaceId parameter, read InterfaceInd from packet
Remove the inputInterfaceId parameter from Icmp::sendErrorMessage, Icmp::maySendErrorMessage, Ipv4::sendIcmpError, and Icmpv4SendErrorReq. The input interface ID is now read directly from the InterfaceInd tag on the original packet, which is always present on network-received packets. This eliminates redundant parameter passing and the -1/TODO placeholders in callers.
1 parent 044d561 commit 0b069a9

7 files changed

Lines changed: 20 additions & 24 deletions

File tree

src/inet/networklayer/common/IcmpErrorTag.msg

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@ class Icmpv4SendErrorReq extends TagBase
4747
{
4848
IcmpType type; // ICMPv4 type (e.g. ICMP_DESTINATION_UNREACHABLE)
4949
int code; // ICMPv4 code (e.g. ICMP_DU_PORT_UNREACHABLE)
50-
int inputInterfaceId = -1;
5150
Packet *originalPacket @owned; // the packet that triggered the error
5251
}
5352

src/inet/networklayer/ipv4/Icmp.cc

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ void Icmp::handleMessage(cMessage *msg)
7979
auto origPacket = tag->getOriginalPacketForUpdate();
8080
// restore the original network datagram (IP header + transport payload)
8181
origPacket->setFrontOffset(origPacket->getTag<NetworkProtocolInd>()->getNetworkHeaderFrontOffset());
82-
sendErrorMessage(origPacket, tag->getInputInterfaceId(), tag->getType(), static_cast<IcmpCode>(tag->getCode()));
82+
sendErrorMessage(origPacket, tag->getType(), static_cast<IcmpCode>(tag->getCode()));
8383
}
8484
else {
8585
throw cRuntimeError("Unknown Request arrived on transportIn: %s", request->getName());
@@ -91,12 +91,15 @@ void Icmp::handleMessage(cMessage *msg)
9191
throw cRuntimeError("Message %s(%s) arrived in unknown '%s' gate", msg->getName(), msg->getClassName(), msg->getArrivalGate()->getName());
9292
}
9393

94-
bool Icmp::maySendErrorMessage(Packet *packet, int inputInterfaceId)
94+
bool Icmp::maySendErrorMessage(Packet *packet)
9595
{
9696
const auto& ipv4Header = packet->peekAtFront<Ipv4Header>();
9797
Ipv4Address origSrcAddr = ipv4Header->getSrcAddress();
9898
Ipv4Address origDestAddr = ipv4Header->getDestAddress();
9999

100+
auto& interfaceInd = packet->findTag<InterfaceInd>();
101+
int inputInterfaceId = interfaceInd ? interfaceInd->getInterfaceId() : -1;
102+
100103
// don't send ICMP error messages in response to broadcast or multicast messages
101104
if (origDestAddr.isMulticast() || origDestAddr.isLimitedBroadcastAddress() || possiblyLocalBroadcast(origDestAddr, inputInterfaceId)) {
102105
EV_DETAIL << "won't send ICMP error messages for broadcast/multicast message " << ipv4Header << endl;
@@ -152,7 +155,7 @@ void Icmp::sendPtbMessage(Packet *packet, int mtu)
152155
{
153156
Enter_Method("sendPtbMessage(datagram, mtu=%d)", mtu);
154157

155-
if (maySendErrorMessage(packet, -1)) {
158+
if (maySendErrorMessage(packet)) {
156159
// assemble a message name
157160
char msgname[80];
158161
snprintf(msgname, sizeof(msgname), "ICMP-PTB-#%" PRIu64 "-mtu%d", ++ctr, mtu);
@@ -176,11 +179,11 @@ void Icmp::sendPtbMessage(Packet *packet, int mtu)
176179
}
177180
}
178181

179-
void Icmp::sendErrorMessage(Packet *packet, int inputInterfaceId, IcmpType type, IcmpCode code)
182+
void Icmp::sendErrorMessage(Packet *packet, IcmpType type, IcmpCode code)
180183
{
181184
Enter_Method("sendErrorMessage(datagram, type=%d, code=%d)", type, code);
182185

183-
if (maySendErrorMessage(packet, inputInterfaceId)) {
186+
if (maySendErrorMessage(packet)) {
184187
// assemble a message name
185188
char msgname[80];
186189
snprintf(msgname, sizeof(msgname), "ICMP-error-#%" PRIu64 "-type%d-code%d", ++ctr, type, code);

src/inet/networklayer/ipv4/Icmp.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,8 @@ class INET_API Icmp : public SimpleModule, public DefaultProtocolRegistrationLis
5050
* This method can be called from other modules to send an ICMP error packet
5151
* in response to a received bogus packet. It will not send ICMP error in response
5252
* to broadcast or multicast packets -- in that case it will simply delete the packet.
53-
* KLUDGE if inputInterfaceId cannot be determined, pass in -1.
5453
*/
55-
virtual void sendErrorMessage(Packet *packet, int inputInterfaceId, IcmpType type, IcmpCode code);
54+
virtual void sendErrorMessage(Packet *packet, IcmpType type, IcmpCode code);
5655
virtual void sendPtbMessage(Packet *packet, int mtu);
5756
static void insertChecksum(ChecksumMode checksumMode, const Ptr<IcmpHeader>& icmpHeader, Packet *payload);
5857
void insertChecksum(const Ptr<IcmpHeader>& icmpHeader, Packet *payload) { insertChecksum(checksumMode, icmpHeader, payload); }
@@ -64,7 +63,7 @@ class INET_API Icmp : public SimpleModule, public DefaultProtocolRegistrationLis
6463
virtual void handleMessage(cMessage *msg) override;
6564
virtual void handleParameterChange(const char *name) override;
6665
virtual void parseQuoteLengthParameter();
67-
virtual bool maySendErrorMessage(Packet *packet, int inputInterfaceId);
66+
virtual bool maySendErrorMessage(Packet *packet);
6867
virtual void sendOrProcessIcmpPacket(Packet *packet, Ipv4Address origSrcAddr);
6968
};
7069

src/inet/networklayer/ipv4/Ipv4.cc

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,7 @@ Ipv4Address Ipv4::getNextHop(Packet *packet)
264264
void Ipv4::handleIncomingDatagram(Packet *packet)
265265
{
266266
ASSERT(packet);
267-
int interfaceId = packet->getTag<InterfaceInd>()->getInterfaceId();
267+
ASSERT(packet->getTag<InterfaceInd>());
268268
emit(packetReceivedFromLowerSignal, packet);
269269

270270
//
@@ -286,7 +286,7 @@ void Ipv4::handleIncomingDatagram(Packet *packet)
286286

287287
if (ipv4Header->getTotalLengthField() > packet->getDataLength()) {
288288
EV_WARN << "length error found, sending ICMP_PARAMETER_PROBLEM\n";
289-
sendIcmpError(packet, interfaceId, ICMP_PARAMETER_PROBLEM, 0);
289+
sendIcmpError(packet, ICMP_PARAMETER_PROBLEM, 0);
290290
return;
291291
}
292292

@@ -302,7 +302,7 @@ void Ipv4::handleIncomingDatagram(Packet *packet)
302302
double relativeHeaderLength = ipv4Header->getHeaderLength().get<B>() / (double)ipv4Header->getChunkLength().get<B>();
303303
if (dblrand() <= relativeHeaderLength) {
304304
EV_WARN << "bit error found, sending ICMP_PARAMETER_PROBLEM\n";
305-
sendIcmpError(packet, interfaceId, ICMP_PARAMETER_PROBLEM, 0);
305+
sendIcmpError(packet, ICMP_PARAMETER_PROBLEM, 0);
306306
return;
307307
}
308308
}
@@ -656,7 +656,7 @@ void Ipv4::routeUnicastPacket(Packet *packet)
656656
PacketDropDetails details;
657657
details.setReason(NO_ROUTE_FOUND);
658658
emit(packetDroppedSignal, packet, &details);
659-
sendIcmpError(packet, fromIE ? fromIE->getInterfaceId() : -1, ICMP_DESTINATION_UNREACHABLE, 0);
659+
sendIcmpError(packet, ICMP_DESTINATION_UNREACHABLE, 0);
660660
}
661661
else { // fragment and send
662662
if (fromIE != nullptr) {
@@ -883,9 +883,7 @@ void Ipv4::reassembleAndDeliverFinish(Packet *packet)
883883
else {
884884
EV_ERROR << "Transport protocol '" << protocol->getName() << "' not connected, discarding packet\n";
885885
packet->setFrontOffset(ipv4HeaderPosition);
886-
// get source interface:
887-
const auto& tag = packet->findTag<InterfaceInd>();
888-
sendIcmpError(packet, tag ? tag->getInterfaceId() : -1, ICMP_DESTINATION_UNREACHABLE, ICMP_DU_PROTOCOL_UNREACHABLE);
886+
sendIcmpError(packet, ICMP_DESTINATION_UNREACHABLE, ICMP_DU_PROTOCOL_UNREACHABLE);
889887
}
890888
}
891889

@@ -944,7 +942,7 @@ void Ipv4::fragmentAndSend(Packet *packet)
944942
details.setReason(HOP_LIMIT_REACHED);
945943
emit(packetDroppedSignal, packet, &details);
946944
EV_WARN << "datagram TTL reached zero, sending ICMP_TIME_EXCEEDED\n";
947-
sendIcmpError(packet, -1 /*TODO*/, ICMP_TIME_EXCEEDED, 0);
945+
sendIcmpError(packet, ICMP_TIME_EXCEEDED, 0);
948946
numDropped++;
949947
return;
950948
}
@@ -1485,9 +1483,9 @@ void Ipv4::receiveSignal(cComponent *source, simsignal_t signalID, cObject *obj,
14851483
}
14861484
}
14871485

1488-
void Ipv4::sendIcmpError(Packet *origPacket, int inputInterfaceId, IcmpType type, IcmpCode code)
1486+
void Ipv4::sendIcmpError(Packet *origPacket, IcmpType type, IcmpCode code)
14891487
{
1490-
icmp->sendErrorMessage(origPacket, inputInterfaceId, type, code);
1488+
icmp->sendErrorMessage(origPacket, type, code);
14911489
delete origPacket;
14921490
}
14931491

src/inet/networklayer/ipv4/Ipv4.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ class INET_API Ipv4 : public OperationalBase, public NetfilterBase, public INetw
210210

211211
virtual void sendPacketToNIC(Packet *packet);
212212

213-
virtual void sendIcmpError(Packet *packet, int inputInterfaceId, IcmpType type, IcmpCode code);
213+
virtual void sendIcmpError(Packet *packet, IcmpType type, IcmpCode code);
214214

215215
virtual Packet *prepareForForwarding(Packet *packet) const;
216216

src/inet/networklayer/ipv4/Ipv4FragBuf.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ void Ipv4FragBuf::purgeStaleFragments(Icmp *icmpModule, simtime_t lastupdate)
113113
// packet, resulting in "length became negative" error. Use getEncapsulatedPacket().
114114
EV_WARN << "datagram fragment timed out in reassembly buffer, sending ICMP_TIME_EXCEEDED\n";
115115
if (buf.packet != nullptr) {
116-
icmpModule->sendErrorMessage(buf.packet, -1 /*TODO*/, ICMP_TIME_EXCEEDED, 0);
116+
icmpModule->sendErrorMessage(buf.packet, ICMP_TIME_EXCEEDED, 0);
117117
delete buf.packet;
118118
}
119119

src/inet/transportlayer/udp/Udp.cc

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1094,14 +1094,11 @@ void Udp::processUndeliverablePacket(Packet *udpPacket)
10941094
udpPacket->getClassName(), udpPacket->getName());
10951095
}
10961096

1097-
auto inIe = udpPacket->getTag<InterfaceInd>()->getInterfaceId();
1098-
10991097
if (protocol->getId() == Protocol::ipv4.getId()) {
11001098
auto request = new Request("ICMP_send_error");
11011099
auto& tag = request->addTag<Icmpv4SendErrorReq>();
11021100
tag->setType(ICMP_DESTINATION_UNREACHABLE);
11031101
tag->setCode(ICMP_DU_PORT_UNREACHABLE);
1104-
tag->setInputInterfaceId(inIe);
11051102
tag->setOriginalPacket(udpPacket);
11061103
request->addTag<DispatchProtocolReq>()->setProtocol(&Protocol::icmpv4);
11071104
send(request, "ipOut");

0 commit comments

Comments
 (0)