INET Framework for OMNeT++/OMNEST
inet::sctp::SctpCrcInsertion Class Reference

#include <SctpCrcInsertionHook.h>

Inheritance diagram for inet::sctp::SctpCrcInsertion:
inet::NetfilterBase::HookBase inet::INetfilter::IHook

Public Member Functions

 SctpCrcInsertion ()
 
void setCrcMode (CrcMode crcModeP)
 
void insertCrc (const Protocol *networkProtocol, const L3Address &srcAddress, const L3Address &destAddress, const Ptr< SctpHeader > &sctpHeader, Packet *packet)
 
uint32_t checksum (unsigned char const *, unsigned int)
 
virtual Result datagramPreRoutingHook (Packet *packet) override
 This is the first hook called by the network protocol before it routes a datagram that was received from the lower layer. More...
 
virtual Result datagramForwardHook (Packet *packet) override
 This is the second hook called by the network protocol before it sends a datagram to the lower layer. More...
 
virtual Result datagramPostRoutingHook (Packet *packet) override
 This is the last hook called by the network protocol before it sends a datagram to the lower layer. More...
 
virtual Result datagramLocalInHook (Packet *packet) override
 This is the last hook called by the network protocol before it sends a datagram to the upper layer. More...
 
virtual Result datagramLocalOutHook (Packet *packet) override
 This is the first hook called by the network protocol before it routes a datagram that was received from the upper layer. More...
 
- Public Member Functions inherited from inet::NetfilterBase::HookBase
virtual ~HookBase ()
 
void registeredTo (INetfilter *nf)
 
void unregisteredFrom (INetfilter *nf)
 
bool isRegisteredHook (INetfilter *nf)
 
- Public Member Functions inherited from inet::INetfilter::IHook
virtual ~IHook ()
 

Private Attributes

CrcMode crcMode = CRC_MODE_UNDEFINED
 

Additional Inherited Members

- Public Types inherited from inet::INetfilter::IHook
enum  Type {
  PREROUTING, LOCALIN, FORWARD, POSTROUTING,
  LOCALOUT
}
 
enum  Result { ACCEPT, DROP, QUEUE, STOLEN }
 
- Protected Attributes inherited from inet::NetfilterBase::HookBase
std::vector< INetfilter * > netfilters
 

Constructor & Destructor Documentation

◆ SctpCrcInsertion()

inet::sctp::SctpCrcInsertion::SctpCrcInsertion ( )
inline
25 {}

Member Function Documentation

◆ checksum()

uint32_t inet::sctp::SctpCrcInsertion::checksum ( unsigned char const *  ,
unsigned int   
)

◆ datagramForwardHook()

virtual Result inet::sctp::SctpCrcInsertion::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.

33 { return ACCEPT; }

◆ datagramLocalInHook()

virtual Result inet::sctp::SctpCrcInsertion::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.

35 { return ACCEPT; }

◆ datagramLocalOutHook()

virtual Result inet::sctp::SctpCrcInsertion::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.

36 { return ACCEPT; }

◆ datagramPostRoutingHook()

INetfilter::IHook::Result inet::sctp::SctpCrcInsertion::datagramPostRoutingHook ( Packet datagram)
overridevirtual

This is the last hook called by the network protocol before it sends a datagram to the lower layer.

Implements inet::INetfilter::IHook.

26 {
27  Enter_Method("datagramPostRoutingHook");
28 
29  if (packet->findTag<InterfaceInd>())
30  return ACCEPT; // FORWARD
31  auto networkProtocol = packet->getTag<PacketProtocolTag>()->getProtocol();
32  const auto& networkHeader = getNetworkProtocolHeader(packet);
33  if (networkHeader->getProtocol() == &Protocol::sctp) {
34  ASSERT(!networkHeader->isFragment());
35  packet->eraseAtFront(networkHeader->getChunkLength());
36  auto sctpHeader = packet->removeAtFront<SctpHeader>();
37  ASSERT(sctpHeader->getCrcMode() == CRC_COMPUTED);
38  const L3Address& srcAddress = networkHeader->getSourceAddress();
39  const L3Address& destAddress = networkHeader->getDestinationAddress();
40  insertCrc(networkProtocol, srcAddress, destAddress, sctpHeader, packet);
41  packet->insertAtFront(sctpHeader);
42  packet->insertAtFront(networkHeader);
43  }
44  return ACCEPT;
45 }

◆ datagramPreRoutingHook()

virtual Result inet::sctp::SctpCrcInsertion::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.

32 { return ACCEPT; }

◆ insertCrc()

void inet::sctp::SctpCrcInsertion::insertCrc ( const Protocol networkProtocol,
const L3Address srcAddress,
const L3Address destAddress,
const Ptr< SctpHeader > &  sctpHeader,
Packet packet 
)
48 {
49  sctpHeader->setCrcMode(crcMode);
50  switch (crcMode) {
52  // if the CRC mode is declared to be correct, then set the CRC to an easily recognizable value
53  sctpHeader->setCrc(0xC00D);
54  break;
56  // if the CRC mode is declared to be incorrect, then set the CRC to an easily recognizable value
57  sctpHeader->setCrc(0xBAAD);
58  break;
59  case CRC_COMPUTED: {
60  // if the CRC mode is computed, then compute the CRC and set it
61  // this computation is delayed after the routing decision, see INetfilter hook
62  sctpHeader->setCrc(0); // make sure that the CRC is 0 in the SCTP header before computing the CRC
63  MemoryOutputStream sctpPacketStream;
64  Chunk::serialize(sctpPacketStream, sctpHeader);
65  Chunk::serialize(sctpPacketStream, packet->peekData(Chunk::PF_ALLOW_EMPTY));
66  const auto& sctpPacketBytes = sctpPacketStream.getData();
67  auto length = sctpPacketBytes.size();
68  auto buffer = new uint8_t[length];
69  std::copy(sctpPacketBytes.begin(), sctpPacketBytes.end(), (uint8_t *)buffer);
70  auto crc = SctpChecksum::checksum(buffer, length);
71  sctpHeader->setCrc(crc);
72  delete[] buffer;
73  break;
74  }
75  default:
76  throw cRuntimeError("Unknown CRC mode");
77  }
78 }

Referenced by datagramPostRoutingHook().

◆ setCrcMode()

void inet::sctp::SctpCrcInsertion::setCrcMode ( CrcMode  crcModeP)
inline
26 { crcMode = crcModeP; }

Member Data Documentation

◆ crcMode

CrcMode inet::sctp::SctpCrcInsertion::crcMode = CRC_MODE_UNDEFINED
private

Referenced by insertCrc(), and setCrcMode().


The documentation for this class was generated from the following files:
inet::CRC_COMPUTED
@ CRC_COMPUTED
Definition: CrcMode_m.h:59
inet::Chunk::serialize
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
PacketProtocolTag
removed DscpReq Ipv4ControlInfo Ipv6ControlInfo up L3AddressInd DispatchProtocolReq L4PortInd Ipv4ControlInfo Ipv6ControlInfo down PacketProtocolTag
Definition: IUdp-gates.txt:25
inet::sctp::SctpCrcInsertion::crcMode
CrcMode crcMode
Definition: SctpCrcInsertionHook.h:22
inet::getNetworkProtocolHeader
const Ptr< const NetworkHeaderBase > getNetworkProtocolHeader(Packet *packet)
Definition: L3Tools.cc:43
inet::sctp::SctpChecksum::checksum
static uint32_t checksum(const void *addr, unsigned int count)
Definition: SctpChecksum.cc:87
inet::Chunk::PF_ALLOW_EMPTY
@ PF_ALLOW_EMPTY
Definition: Chunk.h:279
inet::CRC_DECLARED_CORRECT
@ CRC_DECLARED_CORRECT
Definition: CrcMode_m.h:57
inet::CRC_DECLARED_INCORRECT
@ CRC_DECLARED_INCORRECT
Definition: CrcMode_m.h:58
inet::Protocol::sctp
static const Protocol sctp
Definition: Protocol.h:108
Enter_Method
#define Enter_Method(...)
Definition: SelfDoc.h:71
inet::INetfilter::IHook::ACCEPT
@ ACCEPT
allows the datagram to pass to the next hook
Definition: INetfilter.h:40
copy
MIT License free of to any person obtaining a copy of this software and associated documentation to deal in the Software without including without limitation the rights to copy
Definition: LICENSE.txt:8
inet::sctp::SctpCrcInsertion::insertCrc
void insertCrc(const Protocol *networkProtocol, const L3Address &srcAddress, const L3Address &destAddress, const Ptr< SctpHeader > &sctpHeader, Packet *packet)
Definition: SctpCrcInsertionHook.cc:47