aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/ClientStack
diff options
context:
space:
mode:
authorJustin Clark-Casey (justincc)2013-08-14 22:07:22 +0100
committerJustin Clark-Casey (justincc)2013-08-14 22:08:28 +0100
commit0d5680e9712a5362c23b0ef6e479654d67e99b8b (patch)
tree3599cd4fbc21bec04412cbbddc22e8164327e0b9 /OpenSim/Region/ClientStack
parentIf pCampbot has been asked to shutdown, don't carry on logging in queued bots (diff)
downloadopensim-SC-0d5680e9712a5362c23b0ef6e479654d67e99b8b.zip
opensim-SC-0d5680e9712a5362c23b0ef6e479654d67e99b8b.tar.gz
opensim-SC-0d5680e9712a5362c23b0ef6e479654d67e99b8b.tar.bz2
opensim-SC-0d5680e9712a5362c23b0ef6e479654d67e99b8b.tar.xz
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
Diffstat (limited to 'OpenSim/Region/ClientStack')
-rw-r--r--OpenSim/Region/ClientStack/Linden/UDP/LLUDPServer.cs65
1 files changed, 44 insertions, 21 deletions
diff --git a/OpenSim/Region/ClientStack/Linden/UDP/LLUDPServer.cs b/OpenSim/Region/ClientStack/Linden/UDP/LLUDPServer.cs
index de2f9d4..553250c 100644
--- a/OpenSim/Region/ClientStack/Linden/UDP/LLUDPServer.cs
+++ b/OpenSim/Region/ClientStack/Linden/UDP/LLUDPServer.cs
@@ -108,6 +108,19 @@ namespace OpenSim.Region.ClientStack.LindenUDP
108 108
109 StatsManager.RegisterStat( 109 StatsManager.RegisterStat(
110 new Stat( 110 new Stat(
111 "IncomingPacketsMalformedCount",
112 "Number of inbound UDP packets that could not be recognized as LL protocol packets.",
113 "",
114 "",
115 "clientstack",
116 scene.Name,
117 StatType.Pull,
118 MeasuresOfInterest.AverageChangeOverTime,
119 stat => stat.Value = m_udpServer.IncomingMalformedPacketCount,
120 StatVerbosity.Info));
121
122 StatsManager.RegisterStat(
123 new Stat(
111 "OutgoingUDPSendsCount", 124 "OutgoingUDPSendsCount",
112 "Number of UDP sends performed", 125 "Number of UDP sends performed",
113 "", 126 "",
@@ -268,7 +281,10 @@ namespace OpenSim.Region.ClientStack.LindenUDP
268 281
269 public Socket Server { get { return null; } } 282 public Socket Server { get { return null; } }
270 283
271 private int m_malformedCount = 0; // Guard against a spamming attack 284 /// <summary>
285 /// Record how many inbound packets could not be recognized as LLUDP packets.
286 /// </summary>
287 public int IncomingMalformedPacketCount { get; private set; }
272 288
273 /// <summary> 289 /// <summary>
274 /// Record current outgoing client for monitoring purposes. 290 /// Record current outgoing client for monitoring purposes.
@@ -1181,6 +1197,19 @@ namespace OpenSim.Region.ClientStack.LindenUDP
1181 outgoingPacket.TickCount = Environment.TickCount & Int32.MaxValue; 1197 outgoingPacket.TickCount = Environment.TickCount & Int32.MaxValue;
1182 } 1198 }
1183 1199
1200 private void RecordMalformedInboundPacket(IPEndPoint endPoint)
1201 {
1202// if (m_malformedCount < 100)
1203// m_log.DebugFormat("[LLUDPSERVER]: Dropped malformed packet: " + e.ToString());
1204
1205 IncomingMalformedPacketCount++;
1206
1207 if ((IncomingMalformedPacketCount % 10000) == 0)
1208 m_log.WarnFormat(
1209 "[LLUDPSERVER]: Received {0} malformed packets so far, probable network attack. Last malformed was from {1}",
1210 IncomingMalformedPacketCount, endPoint);
1211 }
1212
1184 public override void PacketReceived(UDPPacketBuffer buffer) 1213 public override void PacketReceived(UDPPacketBuffer buffer)
1185 { 1214 {
1186 // Debugging/Profiling 1215 // Debugging/Profiling
@@ -1202,6 +1231,8 @@ namespace OpenSim.Region.ClientStack.LindenUDP
1202// "[LLUDPSERVER]: Dropping undersized packet with {0} bytes received from {1} in {2}", 1231// "[LLUDPSERVER]: Dropping undersized packet with {0} bytes received from {1} in {2}",
1203// buffer.DataLength, buffer.RemoteEndPoint, m_scene.RegionInfo.RegionName); 1232// buffer.DataLength, buffer.RemoteEndPoint, m_scene.RegionInfo.RegionName);
1204 1233
1234 RecordMalformedInboundPacket(endPoint);
1235
1205 return; // Drop undersized packet 1236 return; // Drop undersized packet
1206 } 1237 }
1207 1238
@@ -1220,6 +1251,8 @@ namespace OpenSim.Region.ClientStack.LindenUDP
1220// "[LLUDPSERVER]: Dropping packet with malformed header received from {0} in {1}", 1251// "[LLUDPSERVER]: Dropping packet with malformed header received from {0} in {1}",
1221// buffer.RemoteEndPoint, m_scene.RegionInfo.RegionName); 1252// buffer.RemoteEndPoint, m_scene.RegionInfo.RegionName);
1222 1253
1254 RecordMalformedInboundPacket(endPoint);
1255
1223 return; // Malformed header 1256 return; // Malformed header
1224 } 1257 }
1225 1258
@@ -1235,34 +1268,24 @@ namespace OpenSim.Region.ClientStack.LindenUDP
1235 // Only allocate a buffer for zerodecoding if the packet is zerocoded 1268 // Only allocate a buffer for zerodecoding if the packet is zerocoded
1236 ((buffer.Data[0] & Helpers.MSG_ZEROCODED) != 0) ? new byte[4096] : null); 1269 ((buffer.Data[0] & Helpers.MSG_ZEROCODED) != 0) ? new byte[4096] : null);
1237 } 1270 }
1238 catch (MalformedDataException)
1239 {
1240 }
1241 catch (IndexOutOfRangeException)
1242 {
1243// m_log.WarnFormat(
1244// "[LLUDPSERVER]: Dropping short packet received from {0} in {1}",
1245// buffer.RemoteEndPoint, m_scene.RegionInfo.RegionName);
1246
1247 return; // Drop short packet
1248 }
1249 catch (Exception e) 1271 catch (Exception e)
1250 { 1272 {
1251 if (m_malformedCount < 100) 1273 if (IncomingMalformedPacketCount < 100)
1252 m_log.DebugFormat("[LLUDPSERVER]: Dropped malformed packet: " + e.ToString()); 1274 m_log.DebugFormat("[LLUDPSERVER]: Dropped malformed packet: " + e.ToString());
1253
1254 m_malformedCount++;
1255
1256 if ((m_malformedCount % 100000) == 0)
1257 m_log.DebugFormat("[LLUDPSERVER]: Received {0} malformed packets so far, probable network attack.", m_malformedCount);
1258 } 1275 }
1259 1276
1260 // Fail-safe check 1277 // Fail-safe check
1261 if (packet == null) 1278 if (packet == null)
1262 { 1279 {
1263 m_log.ErrorFormat("[LLUDPSERVER]: Malformed data, cannot parse {0} byte packet from {1}:", 1280 if (IncomingMalformedPacketCount < 100)
1264 buffer.DataLength, buffer.RemoteEndPoint); 1281 {
1265 m_log.Error(Utils.BytesToHexString(buffer.Data, buffer.DataLength, null)); 1282 m_log.ErrorFormat("[LLUDPSERVER]: Malformed data, cannot parse {0} byte packet from {1}:",
1283 buffer.DataLength, buffer.RemoteEndPoint);
1284 m_log.Error(Utils.BytesToHexString(buffer.Data, buffer.DataLength, null));
1285 }
1286
1287 RecordMalformedInboundPacket(endPoint);
1288
1266 return; 1289 return;
1267 } 1290 }
1268 1291