internet: Add missing data to Ipv[4,6]PacketInfoTag

This commit is contained in:
Tommaso Pecorella
2020-12-27 03:24:48 +00:00
parent df95721323
commit 52b5b84a9e
6 changed files with 18 additions and 40 deletions

View File

@@ -30,7 +30,6 @@ NS_LOG_COMPONENT_DEFINE ("Ipv4PacketInfoTag");
Ipv4PacketInfoTag::Ipv4PacketInfoTag ()
: m_addr (Ipv4Address ()),
m_spec_dst (Ipv4Address ()),
m_ifindex (0),
m_ttl (0)
{
@@ -51,20 +50,6 @@ Ipv4PacketInfoTag::GetAddress (void) const
return m_addr;
}
void
Ipv4PacketInfoTag::SetLocalAddress (Ipv4Address addr)
{
NS_LOG_FUNCTION (this << addr);
m_spec_dst = addr;
}
Ipv4Address
Ipv4PacketInfoTag::GetLocalAddress (void) const
{
NS_LOG_FUNCTION (this);
return m_spec_dst;
}
void
Ipv4PacketInfoTag::SetRecvIf (uint32_t ifindex)
{
@@ -116,9 +101,7 @@ uint32_t
Ipv4PacketInfoTag::GetSerializedSize (void) const
{
NS_LOG_FUNCTION (this);
return 4 + 4
+ sizeof (uint32_t)
+ sizeof (uint8_t);
return 4 + sizeof (uint32_t) + sizeof (uint8_t);
}
void
Ipv4PacketInfoTag::Serialize (TagBuffer i) const
@@ -127,8 +110,6 @@ Ipv4PacketInfoTag::Serialize (TagBuffer i) const
uint8_t buf[4];
m_addr.Serialize (buf);
i.Write (buf, 4);
m_spec_dst.Serialize (buf);
i.Write (buf, 4);
i.WriteU32 (m_ifindex);
i.WriteU8 (m_ttl);
}
@@ -139,8 +120,6 @@ Ipv4PacketInfoTag::Deserialize (TagBuffer i)
uint8_t buf[4];
i.Read (buf, 4);
m_addr = Ipv4Address::Deserialize (buf);
i.Read (buf, 4);
m_spec_dst = Ipv4Address::Deserialize (buf);
m_ifindex = i.ReadU32 ();
m_ttl = i.ReadU8 ();
}
@@ -149,7 +128,6 @@ Ipv4PacketInfoTag::Print (std::ostream &os) const
{
NS_LOG_FUNCTION (this << &os);
os << "Ipv4 PKTINFO [DestAddr: " << m_addr;
os << ", Local Address:" << m_spec_dst;
os << ", RecvIf:" << (uint32_t) m_ifindex;
os << ", TTL:" << (uint32_t) m_ttl;
os << "] ";

View File

@@ -38,6 +38,11 @@ class Packet;
* This is used with socket option such as IP_PKTINFO, IP_RECVTTL,
* IP_RECVTOS. See linux manpage ip(7).
*
* See also SocketIpTosTag and SocketIpTtlTag
*
* The Tag does not carry the Local address (as it is not currently
* used to force a source address).
*
* This tag in the send direction is presently not enabled but we
* would accept a patch along those lines in the future.
*/
@@ -59,22 +64,6 @@ public:
* \returns the address
*/
Ipv4Address GetAddress (void) const;
/**
* \brief Set the tag's \a local address
*
* This corresponds to "ipi_spec_dst" in struct in_pktinfo.
* Implemented, but not used in the stack yet
* \param addr the address
*/
void SetLocalAddress (Ipv4Address addr);
/**
* \brief Get the tag's \a local address
*
* This corresponds to "ipi_spec_dst" in struct in_pktinfo.
* Implemented, but not used in the stack yet
* \returns the address
*/
Ipv4Address GetLocalAddress (void) const;
/**
* \brief Set the tag's receiving interface
@@ -124,7 +113,6 @@ private:
// };
Ipv4Address m_addr; //!< Header destination address
Ipv4Address m_spec_dst; //!< Local address
uint32_t m_ifindex; //!< interface index
// Used for IP_RECVTTL, though not implemented yet.

View File

@@ -440,6 +440,8 @@ Ipv4RawSocketImpl::ForwardUp (Ptr<const Packet> p, Ipv4Header ipHeader, Ptr<Ipv4
{
Ipv4PacketInfoTag tag;
copy->RemovePacketTag (tag);
tag.SetAddress (ipHeader.GetDestination ());
tag.SetTtl (ipHeader.GetTtl ());
tag.SetRecvIf (incomingInterface->GetDevice ()->GetIfIndex ());
copy->AddPacketTag (tag);
}

View File

@@ -37,6 +37,8 @@ class Packet;
* data to the socket interface. This is used like
* socket option of IP_PKTINFO/IPV6_PKTINFO in \RFC{3542}
*
* See also SocketIpv6TclassTag and SocketIpv6HopLimitTag
*
* This tag in the send direction is presently not enabled but we
* would accept a patch along those lines in the future. To include
* the nexthop in the send direction would increase the size of the

View File

@@ -437,6 +437,9 @@ bool Ipv6RawSocketImpl::ForwardUp (Ptr<const Packet> p, Ipv6Header hdr, Ptr<NetD
{
Ipv6PacketInfoTag tag;
copy->RemovePacketTag (tag);
tag.SetAddress (hdr.GetDestinationAddress ());
tag.SetHoplimit (hdr.GetHopLimit ());
tag.SetTrafficClass (hdr.GetTrafficClass ());
tag.SetRecvIf (device->GetIfIndex ());
copy->AddPacketTag (tag);
}

View File

@@ -1011,6 +1011,8 @@ UdpSocketImpl::ForwardUp (Ptr<Packet> packet, Ipv4Header header, uint16_t port,
{
Ipv4PacketInfoTag tag;
packet->RemovePacketTag (tag);
tag.SetAddress (header.GetDestination ());
tag.SetTtl (header.GetTtl ());
tag.SetRecvIf (incomingInterface->GetDevice ()->GetIfIndex ());
packet->AddPacketTag (tag);
}
@@ -1068,6 +1070,9 @@ UdpSocketImpl::ForwardUp6 (Ptr<Packet> packet, Ipv6Header header, uint16_t port,
{
Ipv6PacketInfoTag tag;
packet->RemovePacketTag (tag);
tag.SetAddress (header.GetDestinationAddress ());
tag.SetHoplimit (header.GetHopLimit ());
tag.SetTrafficClass (header.GetTrafficClass ());
tag.SetRecvIf (incomingInterface->GetDevice ()->GetIfIndex ());
packet->AddPacketTag (tag);
}