internet: fixes to IPv4 subnet-directed broadcast

This commit is contained in:
Tommaso Pecorella
2022-11-25 19:23:37 +01:00
parent 3396de4c99
commit 520865a919
4 changed files with 48 additions and 9 deletions

View File

@@ -19,13 +19,16 @@ Release 3-dev
### New user-visible features
- (network) !938 - Add class `TimestampTag` for associating a timestamp with a packet.
- (network) !1163 Initializing an Ipv[4,6]Address from an invalid string do not raise an exception anymore. Instead the address is marked as not initialized.
- (internet) !1186 `TcpWestwood` model has been removed, and the class has been renamed `TcpWestwoodPlus`.
- (network) !1163 - Initializing an Ipv[4,6]Address from an invalid string do not raise an exception anymore. Instead the address is marked as not initialized.
- (internet) !1186 - `TcpWestwood` model has been removed, and the class has been renamed `TcpWestwoodPlus`.
- (internet) !1229 - You can now ping broadcast addresses.
### Bugs fixed
- (build) #808 - Handle profile setting changes in the first ns3 run
- (build) #815 - Configure find_program to search for programs in PATH first, then AppBundles in MacOS
- (network) !1229 - Fixed a bug in `Ipv4Address::IsSubnetDirectedBroadcast`
- (internet) !1229 - Fixed a bug in `Icmpv4Header::HandleEcho` when replying to broadcast-type Echo requests, and two bugs in `Ipv4RawSocketImpl::SendTo` in handling sockets bound to a specific address and directed to a broadcast-type address.
Release 3.37
------------

View File

@@ -300,9 +300,35 @@ Icmpv4L4Protocol::Receive(Ptr<Packet> p,
p->RemoveHeader(icmp);
switch (icmp.GetType())
{
case Icmpv4Header::ICMPV4_ECHO:
HandleEcho(p, icmp, header.GetSource(), header.GetDestination());
case Icmpv4Header::ICMPV4_ECHO: {
Ipv4Address dst = header.GetDestination();
// We could have received an Echo request to a broadcast-type address.
if (dst.IsBroadcast())
{
Ipv4Address src = header.GetSource();
for (uint32_t index = 0; index < incomingInterface->GetNAddresses(); index++)
{
Ipv4InterfaceAddress addr = incomingInterface->GetAddress(index);
if (addr.IsInSameSubnet(src))
{
dst = addr.GetAddress();
}
}
}
else
{
for (uint32_t index = 0; index < incomingInterface->GetNAddresses(); index++)
{
Ipv4InterfaceAddress addr = incomingInterface->GetAddress(index);
if (dst == addr.GetBroadcast())
{
dst = addr.GetAddress();
}
}
}
HandleEcho(p, icmp, header.GetSource(), dst);
break;
}
case Icmpv4Header::ICMPV4_DEST_UNREACH:
HandleDestUnreach(p, icmp, header.GetSource(), header.GetDestination());
break;

View File

@@ -275,10 +275,19 @@ Ipv4RawSocketImpl::SendTo(Ptr<Packet> p, uint32_t flags, const Address& toAddres
p->AddPacketTag(tag);
}
bool subnetDirectedBroadcast = false;
if (m_boundnetdevice)
Ptr<NetDevice> boundNetDevice = m_boundnetdevice;
if (!m_src.IsAny())
{
uint32_t iif = ipv4->GetInterfaceForDevice(m_boundnetdevice);
int32_t index = ipv4->GetInterfaceForAddress(m_src);
NS_ASSERT(index >= 0);
boundNetDevice = ipv4->GetNetDevice(index);
}
bool subnetDirectedBroadcast = false;
if (boundNetDevice)
{
uint32_t iif = ipv4->GetInterfaceForDevice(boundNetDevice);
for (uint32_t j = 0; j < ipv4->GetNAddresses(iif); j++)
{
Ipv4InterfaceAddress ifAddr = ipv4->GetAddress(iif, j);
@@ -291,7 +300,6 @@ Ipv4RawSocketImpl::SendTo(Ptr<Packet> p, uint32_t flags, const Address& toAddres
if (dst.IsBroadcast() || subnetDirectedBroadcast)
{
Ptr<NetDevice> boundNetDevice = m_boundnetdevice;
if (ipv4->GetNInterfaces() == 1)
{
boundNetDevice = ipv4->GetNetDevice(0);
@@ -312,6 +320,7 @@ Ipv4RawSocketImpl::SendTo(Ptr<Packet> p, uint32_t flags, const Address& toAddres
route->SetSource(src);
route->SetDestination(dst);
route->SetOutputDevice(boundNetDevice);
route->SetGateway("0.0.0.0");
ipv4->Send(p, route->GetSource(), dst, m_protocol, route);
}
else
@@ -324,6 +333,7 @@ Ipv4RawSocketImpl::SendTo(Ptr<Packet> p, uint32_t flags, const Address& toAddres
route->SetSource(src);
route->SetDestination(dst);
route->SetOutputDevice(boundNetDevice);
route->SetGateway("0.0.0.0");
ipv4->SendWithHeader(p, header, route);
}
NotifyDataSent(pktSize);

View File

@@ -248,7 +248,7 @@ Ipv4Address::IsSubnetDirectedBroadcast(const Ipv4Mask& mask) const
// broadcast for this address.
return false;
}
return ((Get() | mask.GetInverse()) == Get());
return ((Get() | mask.Get()) == Ipv4Address::GetBroadcast().Get());
}
bool