|
INET Framework for OMNeT++/OMNEST
|
Icmp module.
More...
#include <Icmp.h>
|
| virtual void | sendErrorMessage (Packet *packet, int inputInterfaceId, IcmpType type, IcmpCode code) |
| | This method can be called from other modules to send an ICMP error packet in response to a received bogus packet. More...
|
| |
| virtual void | sendPtbMessage (Packet *packet, int mtu) |
| |
| void | insertCrc (const Ptr< IcmpHeader > &icmpHeader, Packet *payload) |
| |
| bool | verifyCrc (const Packet *packet) |
| |
| virtual void | handleRegisterServiceGroup (const ProtocolGroup &protocolGroup, cGate *gate, ServicePrimitive servicePrimitive) override |
| |
| virtual void | handleRegisterProtocolGroup (const ProtocolGroup &protocolGroup, cGate *gate, ServicePrimitive servicePrimitive) override |
| |
| virtual void | handleRegisterAnyService (cGate *gate, ServicePrimitive servicePrimitive) override |
| |
| virtual void | handleRegisterAnyProtocol (cGate *gate, ServicePrimitive servicePrimitive) override |
| |
◆ errorOut()
| void inet::Icmp::errorOut |
( |
Packet * |
packet | ) |
|
|
protectedvirtual |
◆ handleMessage()
| void inet::Icmp::handleMessage |
( |
cMessage * |
msg | ) |
|
|
overrideprotectedvirtual |
69 cGate *arrivalGate = msg->getArrivalGate();
72 if (arrivalGate->isName(
"ipIn")) {
73 EV_INFO <<
"Received " << msg <<
" from network protocol.\n";
78 throw cRuntimeError(
"Message %s(%s) arrived in unknown '%s' gate", msg->getName(), msg->getClassName(), msg->getArrivalGate()->getName());
◆ handleParameterChange()
| void inet::Icmp::handleParameterChange |
( |
const char * |
name | ) |
|
|
overrideprotectedvirtual |
38 else if (!strcmp(name,
"crcMode"))
40 else if (!strcmp(name,
"quoteLength"))
◆ handleRegisterProtocol()
◆ handleRegisterService()
◆ initialize()
| void inet::Icmp::initialize |
( |
int |
stage | ) |
|
|
overrideprotectedvirtual |
53 cSimpleModule::initialize(stage);
56 ift.reference(
this,
"interfaceTableModule",
true);
57 rt.reference(
this,
"routingTableModule",
true);
◆ insertCrc() [1/2]
| void inet::Icmp::insertCrc |
( |
const Ptr< IcmpHeader > & |
icmpHeader, |
|
|
Packet * |
payload |
|
) |
| |
|
inline |
◆ insertCrc() [2/2]
◆ maySendErrorMessage()
| bool inet::Icmp::maySendErrorMessage |
( |
Packet * |
packet, |
|
|
int |
inputInterfaceId |
|
) |
| |
|
protectedvirtual |
83 const auto& ipv4Header = packet->peekAtFront<Ipv4Header>();
84 Ipv4Address origSrcAddr = ipv4Header->getSrcAddress();
85 Ipv4Address origDestAddr = ipv4Header->getDestAddress();
88 if (origDestAddr.isMulticast() || origDestAddr.isLimitedBroadcastAddress() ||
possiblyLocalBroadcast(origDestAddr, inputInterfaceId)) {
89 EV_DETAIL <<
"won't send ICMP error messages for broadcast/multicast message " << ipv4Header << endl;
94 if ((inputInterfaceId != -1 && origSrcAddr.isUnspecified())
95 || origSrcAddr.isMulticast()
96 || origSrcAddr.isLimitedBroadcastAddress()
98 EV_DETAIL <<
"won't send ICMP error messages to broadcast/multicast address, message " << ipv4Header << endl;
103 if (ipv4Header->getFragmentOffset() != 0) {
104 EV_DETAIL <<
"won't send ICMP error messages about errors in non-first fragments" << endl;
110 const auto& recICMPMsg = packet->peekDataAt<IcmpHeader>(
B(ipv4Header->getHeaderLength()));
112 EV_DETAIL <<
"ICMP error received -- do not reply to it" << endl;
Referenced by sendErrorMessage(), and sendPtbMessage().
◆ numInitStages()
| virtual int inet::Icmp::numInitStages |
( |
| ) |
const |
|
inlineoverrideprotectedvirtual |
◆ parseQuoteLengthParameter()
| void inet::Icmp::parseQuoteLengthParameter |
( |
| ) |
|
|
protectedvirtual |
◆ possiblyLocalBroadcast()
| bool inet::Icmp::possiblyLocalBroadcast |
( |
const Ipv4Address & |
addr, |
|
|
int |
interfaceId |
|
) |
| |
|
protectedvirtual |
197 if ((addr.getInt() & 1) == 0)
200 if (
rt->isLocalBroadcastAddress(addr))
204 if (interfaceId != -1) {
205 NetworkInterface *ie =
ift->getInterfaceById(interfaceId);
206 auto ipv4Data = ie->findProtocolData<Ipv4InterfaceData>();
207 bool interfaceUnconfigured = (ipv4Data ==
nullptr) || ipv4Data->getIPAddress().isUnspecified();
208 return interfaceUnconfigured;
212 bool allInterfacesConfigured =
true;
213 for (
int i = 0; i <
ift->getNumInterfaces(); i++) {
214 auto ipv4Data =
ift->getInterface(i)->findProtocolData<Ipv4InterfaceData>();
215 if ((ipv4Data ==
nullptr) || ipv4Data->getIPAddress().isUnspecified())
216 allInterfacesConfigured =
false;
219 return !allInterfacesConfigured;
Referenced by maySendErrorMessage().
◆ processEchoRequest()
| void inet::Icmp::processEchoRequest |
( |
Packet * |
request | ) |
|
|
protectedvirtual |
299 const auto& icmpReq = request->popAtFront<IcmpEchoRequest>();
300 Packet *reply =
new Packet((std::string(request->getName()) +
"-reply").c_str());
301 const auto& icmpReply = makeShared<IcmpEchoReply>();
302 icmpReply->setIdentifier(icmpReq->getIdentifier());
303 icmpReply->setSeqNumber(icmpReq->getSeqNumber());
305 Ipv4Address src = addressInd->getSrcAddress().toIpv4();
306 Ipv4Address dest = addressInd->getDestAddress().toIpv4();
307 reply->insertAtBack(request->peekData());
309 reply->insertAtFront(icmpReply);
314 auto addressReq = reply->addTag<L3AddressReq>();
315 addressReq->setSrcAddress(addressInd->getDestAddress().toIpv4());
316 addressReq->setDestAddress(addressInd->getSrcAddress().toIpv4());
Referenced by processIcmpMessage().
◆ processIcmpMessage()
| void inet::Icmp::processIcmpMessage |
( |
Packet * |
packet | ) |
|
|
protectedvirtual |
226 EV_WARN <<
"incoming ICMP packet has wrong CRC, dropped\n";
228 PacketDropDetails details;
235 const auto& icmpmsg = packet->peekAtFront<IcmpHeader>();
236 switch (icmpmsg->getType()) {
239 EV_ERROR <<
"ICMP_REDIRECT not implemented yet, packet " <<
EV_FORMAT_OBJECT(packet) <<
" dropped.\n";
247 const auto& bogusL3Packet = packet->peekDataAt<Ipv4Header>(icmpmsg->getChunkLength());
248 int transportProtocol = bogusL3Packet->getProtocolId();
256 EV_ERROR <<
"Transport protocol " << transportProtocol <<
" not registered, packet dropped\n";
264 send(packet,
"transportOut");
287 throw cRuntimeError(
"Unknown ICMP type %d", icmpmsg->getType());
Referenced by handleMessage(), and sendOrProcessIcmpPacket().
◆ sendErrorMessage()
This method can be called from other modules to send an ICMP error packet in response to a received bogus packet.
It will not send ICMP error in response to broadcast or multicast packets – in that case it will simply delete the packet. KLUDGE if inputInterfaceId cannot be determined, pass in -1.
173 sprintf(msgname,
"ICMP-error-#%ld-type%d-code%d", ++
ctr,
type, code);
176 EV_DETAIL <<
"sending ICMP error " << msgname << endl;
179 Packet *errorPacket =
new Packet(msgname);
180 const auto& icmpHeader = makeShared<IcmpHeader>();
181 icmpHeader->setType(
type);
182 icmpHeader->setCode(code);
185 const auto& ipv4Header = packet->peekAtFront<Ipv4Header>();
186 B curQuoteLength =
std::min(
B(packet->getDataLength()), ipv4Header->getHeaderLength() +
quoteLength);
187 errorPacket->insertAtBack(packet->peekDataAt(
B(0), curQuoteLength));
189 errorPacket->insertAtFront(icmpHeader);
Referenced by inet::Ipv4FragBuf::purgeStaleFragments().
◆ sendOrProcessIcmpPacket()
| void inet::Icmp::sendOrProcessIcmpPacket |
( |
Packet * |
packet, |
|
|
Ipv4Address |
origSrcAddr |
|
) |
| |
|
protectedvirtual |
◆ sendPtbMessage()
| void inet::Icmp::sendPtbMessage |
( |
Packet * |
packet, |
|
|
int |
mtu |
|
) |
| |
|
virtual |
145 sprintf(msgname,
"ICMP-PTB-#%ld-mtu%d", ++
ctr, mtu);
148 EV_DETAIL <<
"sending ICMP PTB " << msgname << endl;
151 Packet *errorPacket =
new Packet(msgname);
152 const auto& icmpPtb = makeShared<IcmpPtb>();
153 icmpPtb->setMtu(mtu);
156 const auto& ipv4Header = packet->peekAtFront<Ipv4Header>();
157 B curQuoteLength =
std::min(
B(packet->getDataLength()), ipv4Header->getHeaderLength() +
quoteLength);
158 errorPacket->insertAtBack(packet->peekDataAt(
b(0), curQuoteLength));
160 errorPacket->insertAtFront(icmpPtb);
◆ sendToIP() [1/2]
◆ sendToIP() [2/2]
| void inet::Icmp::sendToIP |
( |
Packet * |
msg | ) |
|
|
protectedvirtual |
330 EV_INFO <<
"Sending " << msg <<
" to lower layer.\n";
◆ verifyCrc()
| bool inet::Icmp::verifyCrc |
( |
const Packet * |
packet | ) |
|
382 switch (icmpHeader->getCrcMode()) {
385 return icmpHeader->isCorrect();
394 return crc == 0 && icmpHeader->isCorrect();
397 throw cRuntimeError(
"Unknown CRC mode");
Referenced by processIcmpMessage().
◆ crcMode
◆ ctr
◆ ift
◆ quoteLength
| B inet::Icmp::quoteLength |
|
protected |
◆ rt
◆ transportProtocols
| std::set<int> inet::Icmp::transportProtocols |
|
protected |
The documentation for this class was generated from the following files:
ModuleRefByPar< IIpv4RoutingTable > rt
Definition: Icmp.h:33
removed DscpReq Ipv4ControlInfo Ipv6ControlInfo up L3AddressInd DispatchProtocolReq L4PortInd Ipv4ControlInfo Ipv6ControlInfo down protocol
Definition: IUdp-gates.txt:25
@ ICMP_DESTINATION_UNREACHABLE
Definition: IcmpHeader_m.h:77
@ INCORRECTLY_RECEIVED
Definition: Simsignals_m.h:71
static const Protocol ipv4
Definition: Protocol.h:93
@ ICMP_TIMESTAMP_REQUEST
Definition: IcmpHeader_m.h:86
@ IP_PROT_ICMP
Definition: IpProtocolId_m.h:91
@ ICMP_PARAMETER_PROBLEM
Definition: IcmpHeader_m.h:84
virtual void parseQuoteLengthParameter()
Definition: Icmp.cc:44
double min(const double a, const double b)
Returns the minimum of a and b.
Definition: SctpAssociation.h:261
static const Protocol icmpv4
Definition: Protocol.h:71
@ CRC_COMPUTED
Definition: CrcMode_m.h:59
static void serialize(MemoryOutputStream &stream, const Ptr< const Chunk > &chunk, b offset=b(0), b length=b(-1))
Serializes a chunk into the given stream.
Definition: Chunk.cc:175
removed DscpReq Ipv4ControlInfo Ipv6ControlInfo up L3AddressInd DispatchProtocolReq L4PortInd Ipv4ControlInfo Ipv6ControlInfo down DispatchProtocolReq
Definition: IUdp-gates.txt:25
static void insertCrc(CrcMode crcMode, const Ptr< IcmpHeader > &icmpHeader, Packet *payload)
Definition: Icmp.cc:351
removed DscpReq Ipv4ControlInfo Ipv6ControlInfo up L3AddressInd L3AddressInd
Definition: IUdp-gates.txt:20
CrcMode parseCrcMode(const char *crcModeString, bool allowDisable)
Definition: CrcMode.cc:14
@ ICMP_ECHO_REQUEST
Definition: IcmpHeader_m.h:80
@ ICMP_TIMESTAMP_REPLY
Definition: IcmpHeader_m.h:87
B quoteLength
Definition: Icmp.h:32
void registerService(const Protocol &protocol, cGate *gate, ServicePrimitive servicePrimitive)
Registers a service primitive (SDU processing) at the given gate.
Definition: IProtocolRegistrationListener.cc:14
simsignal_t packetDroppedSignal
Definition: Simsignals.cc:85
removed DscpReq Ipv4ControlInfo Ipv6ControlInfo up L3AddressInd DispatchProtocolReq L4PortInd Ipv4ControlInfo Ipv6ControlInfo down PacketProtocolTag
Definition: IUdp-gates.txt:25
virtual bool possiblyLocalBroadcast(const Ipv4Address &addr, int interfaceId)
Definition: Icmp.cc:195
@ ICMP_REDIRECT
Definition: IcmpHeader_m.h:79
intscale< b, 1, 8 > B
Definition: Units.h:1168
@ ICMP_TIME_EXCEEDED
Definition: IcmpHeader_m.h:83
virtual void sendOrProcessIcmpPacket(Packet *packet, Ipv4Address origSrcAddr)
Definition: Icmp.cc:120
bool verifyCrc(const Packet *packet)
Definition: Icmp.cc:379
virtual bool maySendErrorMessage(Packet *packet, int inputInterfaceId)
Definition: Icmp.cc:81
virtual void sendToIP(Packet *, const Ipv4Address &dest)
Definition: Icmp.cc:322
bool contains(const std::vector< T > &v, const Tk &a)
Definition: stlutils.h:65
ModuleRefByPar< IInterfaceTable > ift
Definition: Icmp.h:34
removed type
Definition: IUdp-gates.txt:7
bool isIcmpInfoType(int type)
Definition: IcmpHeader_m.h:211
INET_API InitStage INITSTAGE_LOCAL
Initialization of local state that don't use or affect other modules includes:
CrcMode crcMode
Definition: Icmp.h:31
int findProtocolNumber(const Protocol *protocol) const
Definition: ProtocolGroup.cc:40
value< int64_t, units::b > b
Definition: Units.h:1241
#define NUM_INIT_STAGES
Definition: InitStageRegistry.h:73
@ PF_ALLOW_INCORRECT
Definition: Chunk.h:281
@ SP_INDICATION
Definition: ProtocolTag_m.h:175
static uint16_t checksum(const void *addr, unsigned int count)
Definition: TcpIpChecksum.h:33
@ CRC_DECLARED_CORRECT
Definition: CrcMode_m.h:57
@ CRC_DECLARED_INCORRECT
Definition: CrcMode_m.h:58
#define EV_FORMAT_OBJECT(object)
Definition: INETDefs.h:107
#define Enter_Method(...)
Definition: SelfDoc.h:71
static const Ipv4Address LOOPBACK_ADDRESS
127.0.0.1
Definition: Ipv4Address.h:92
static ProtocolGroup ipprotocol
Definition: ProtocolGroup.h:42
virtual void processIcmpMessage(Packet *)
Definition: Icmp.cc:223
void registerProtocol(const Protocol &protocol, cGate *gate, ServicePrimitive servicePrimitive)
Registers a protocol primitive (PDU processing) at the given gate.
Definition: IProtocolRegistrationListener.cc:83
virtual void processEchoRequest(Packet *)
Definition: Icmp.cc:296
INET_API InitStage INITSTAGE_NETWORK_LAYER_PROTOCOLS
Initialization of network layer protocols over IP.
std::set< int > transportProtocols
Definition: Icmp.h:30
virtual void errorOut(Packet *)
Definition: Icmp.cc:291
@ ICMP_ECHO_REPLY
Definition: IcmpHeader_m.h:85
static long ctr
Definition: Icmp.h:35