Count any incoming packet that could not be recognized as an LLUDP packet as a malformed packet. Record this as stat clientstack.<scene>.IncomingPacketsMalformedCount

Used to detect if a simulator is receiving significant junk UDP
Decimates the number of packets between which a warning is logged and prints the IP source of the last malformed packet when logging
0.7.6-extended
Justin Clark-Casey (justincc) 2013-08-14 22:07:22 +01:00
parent 2c67aa0f41
commit 0d5680e971
1 changed files with 44 additions and 21 deletions

View File

@ -106,6 +106,19 @@ namespace OpenSim.Region.ClientStack.LindenUDP
stat => stat.Value = m_udpServer.IncomingPacketsProcessed,
StatVerbosity.Debug));
StatsManager.RegisterStat(
new Stat(
"IncomingPacketsMalformedCount",
"Number of inbound UDP packets that could not be recognized as LL protocol packets.",
"",
"",
"clientstack",
scene.Name,
StatType.Pull,
MeasuresOfInterest.AverageChangeOverTime,
stat => stat.Value = m_udpServer.IncomingMalformedPacketCount,
StatVerbosity.Info));
StatsManager.RegisterStat(
new Stat(
"OutgoingUDPSendsCount",
@ -268,7 +281,10 @@ namespace OpenSim.Region.ClientStack.LindenUDP
public Socket Server { get { return null; } }
private int m_malformedCount = 0; // Guard against a spamming attack
/// <summary>
/// Record how many inbound packets could not be recognized as LLUDP packets.
/// </summary>
public int IncomingMalformedPacketCount { get; private set; }
/// <summary>
/// Record current outgoing client for monitoring purposes.
@ -1181,6 +1197,19 @@ namespace OpenSim.Region.ClientStack.LindenUDP
outgoingPacket.TickCount = Environment.TickCount & Int32.MaxValue;
}
private void RecordMalformedInboundPacket(IPEndPoint endPoint)
{
// if (m_malformedCount < 100)
// m_log.DebugFormat("[LLUDPSERVER]: Dropped malformed packet: " + e.ToString());
IncomingMalformedPacketCount++;
if ((IncomingMalformedPacketCount % 10000) == 0)
m_log.WarnFormat(
"[LLUDPSERVER]: Received {0} malformed packets so far, probable network attack. Last malformed was from {1}",
IncomingMalformedPacketCount, endPoint);
}
public override void PacketReceived(UDPPacketBuffer buffer)
{
// Debugging/Profiling
@ -1202,6 +1231,8 @@ namespace OpenSim.Region.ClientStack.LindenUDP
// "[LLUDPSERVER]: Dropping undersized packet with {0} bytes received from {1} in {2}",
// buffer.DataLength, buffer.RemoteEndPoint, m_scene.RegionInfo.RegionName);
RecordMalformedInboundPacket(endPoint);
return; // Drop undersized packet
}
@ -1220,6 +1251,8 @@ namespace OpenSim.Region.ClientStack.LindenUDP
// "[LLUDPSERVER]: Dropping packet with malformed header received from {0} in {1}",
// buffer.RemoteEndPoint, m_scene.RegionInfo.RegionName);
RecordMalformedInboundPacket(endPoint);
return; // Malformed header
}
@ -1235,34 +1268,24 @@ namespace OpenSim.Region.ClientStack.LindenUDP
// Only allocate a buffer for zerodecoding if the packet is zerocoded
((buffer.Data[0] & Helpers.MSG_ZEROCODED) != 0) ? new byte[4096] : null);
}
catch (MalformedDataException)
{
}
catch (IndexOutOfRangeException)
{
// m_log.WarnFormat(
// "[LLUDPSERVER]: Dropping short packet received from {0} in {1}",
// buffer.RemoteEndPoint, m_scene.RegionInfo.RegionName);
return; // Drop short packet
}
catch (Exception e)
{
if (m_malformedCount < 100)
if (IncomingMalformedPacketCount < 100)
m_log.DebugFormat("[LLUDPSERVER]: Dropped malformed packet: " + e.ToString());
m_malformedCount++;
if ((m_malformedCount % 100000) == 0)
m_log.DebugFormat("[LLUDPSERVER]: Received {0} malformed packets so far, probable network attack.", m_malformedCount);
}
// Fail-safe check
if (packet == null)
{
if (IncomingMalformedPacketCount < 100)
{
m_log.ErrorFormat("[LLUDPSERVER]: Malformed data, cannot parse {0} byte packet from {1}:",
buffer.DataLength, buffer.RemoteEndPoint);
m_log.Error(Utils.BytesToHexString(buffer.Data, buffer.DataLength, null));
}
RecordMalformedInboundPacket(endPoint);
return;
}