Skip to content

Commit 82e7ebd

Browse files
Merge pull request #15 from microsoft/20210819_LinkLayer7
20210819 link layer7
2 parents a0a16ca + f7a8a1b commit 82e7ebd

File tree

10 files changed

+113
-152
lines changed

10 files changed

+113
-152
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,4 @@
55
**/bin
66
**/obj
77
**/publish
8+
**/.vs
0 Bytes
Binary file not shown.
-1 KB
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.

SQL_Network_Analyzer/SQLNA/ConversationData.cs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,8 @@ public class ConversationData // - constructed in Get
6464
public uint threadID = 0; // - set in GetClientPreloginInfo
6565
// Conversation statistics
6666
public int tdsFrames = 0; // - set in ProcessTDS
67-
public ulong totalBytes = 0; // - set in ParseEthernetFrame
67+
public ulong totalBytes = 0; // - set in ParseTCPFrame
68+
public ulong totalPayloadBytes = 0; // - set in ParseTCPFrame
6869
public long startTick = 0; // - set in ParseEthernetFrame
6970
public long endTick = 0; // - set in ParseEthernetFrame
7071
public int ackCount = 0; // - accumulated in ParseTCPFrame - can be in combination with other flags
@@ -84,9 +85,11 @@ public class ConversationData // - constructed in Get
8485
public uint sourceFrames = 0; // - accumulated in ParseEthernetFrame
8586
public uint destFrames = 0; // - accumulated in ParseEthernetFrame
8687
public uint keepAliveCount = 0; // - accumulated in ParseTCPFrame
87-
public ushort maxKeepAliveRetransmits = 0; // - accoumulated in FindKeepAliveRetransmits
88-
public uint truncatedFrameLength = 0; //
89-
public uint truncationErrorCount = 0; //
88+
public ushort maxKeepAliveRetransmits = 0; // - accoumulated in FindKeepAliveRetransmits
89+
public uint truncatedFrameLength = 0; //
90+
public uint truncationErrorCount = 0; //
91+
public int maxPayloadSize = 0; // - accumulated in ParseTCPFrame
92+
public bool maxPayloadLimit = false; // - accumulated in ParseTCPFrame
9093
public long synTime = 0; //
9194
public long ackSynTime = 0; //
9295
public long PreLoginTime = 0; // - set in TDS Parser - so we can time the PreLogin packet delay

SQL_Network_Analyzer/SQLNA/OutputText.cs

Lines changed: 57 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ public static void TextReport(NetworkTrace Trace)
3333
DisplayAttentions(Trace);
3434
DisplayTLSIssues(Trace);
3535
DisplayRedirectedConnections(Trace);
36+
DisplayMTUReport(Trace);
3637
DisplayClientPortUsage(Trace);
3738
DisplaySSRPReport(Trace);
3839
DisplayKerberosResponseReport(Trace);
@@ -79,6 +80,7 @@ private static void DisplayFileStatistics(NetworkTrace Trace)
7980
private static void DisplayTrafficStatistics(NetworkTrace Trace)
8081
{
8182
ulong tcpBytes = 0, tdsBytes = 0;
83+
ulong tcpPayloadBytes = 0, tdsPayloadBytes = 0;
8284
int tcpConversations = 0, tdsConversations = 0;
8385
int tcpFrames = 0, tdsFrames = 0;
8486

@@ -87,22 +89,24 @@ private static void DisplayTrafficStatistics(NetworkTrace Trace)
8789
if (c.isUDP == false)
8890
{
8991
tcpBytes += c.totalBytes;
92+
tcpPayloadBytes += c.totalPayloadBytes;
9093
tcpFrames += c.frames.Count;
9194
tcpConversations++;
9295
if (c.isSQL)
9396
{
9497
tdsBytes += c.totalBytes;
98+
tdsPayloadBytes += c.totalPayloadBytes;
9599
tdsFrames += c.frames.Count;
96100
tdsConversations++;
97101
}
98102
}
99103
}
100104

101105
ReportFormatter rf = new ReportFormatter();
102-
rf.SetColumnNames("Statistic:L", "Bytes:R", "Frames:R", "Conversations:R");
106+
rf.SetColumnNames("Statistic:L", "Packet Bytes:R", "Payload Bytes:R", "Frames:R", "Conversations:R");
103107
rf.indent = 4;
104-
rf.SetcolumnData("TCP Traffic", tcpBytes.ToString("#,##0"), tcpFrames.ToString("#,##0"), tcpConversations.ToString("#,##0"));
105-
rf.SetcolumnData("SQL Traffic", tdsBytes.ToString("#,##0"), tdsFrames.ToString("#,##0"), tdsConversations.ToString("#,##0"));
108+
rf.SetcolumnData("TCP Traffic", tcpBytes.ToString("#,##0"), tcpPayloadBytes.ToString("#,##0"), tcpFrames.ToString("#,##0"), tcpConversations.ToString("#,##0"));
109+
rf.SetcolumnData("SQL Traffic", tdsBytes.ToString("#,##0"), tdsPayloadBytes.ToString("#,##0"), tdsFrames.ToString("#,##0"), tdsConversations.ToString("#,##0"));
106110

107111
Program.logMessage(rf.GetHeaderText());
108112
Program.logMessage(rf.GetSeparatorText());
@@ -1646,10 +1650,8 @@ private static void DisplayNamedPipesReport(NetworkTrace Trace)
16461650
}
16471651
}
16481652

1649-
Program.logMessage("The following Named Pipes conversations were detected in the network trace:\r\n");
16501653
ReportFormatter rf = new ReportFormatter();
16511654

1652-
16531655
// "Client Address:L", "Port:R", "Files:R", "Last Frame:R", "Start Offset:R", "End Offset:R", "End Time:R", "Frames:R", "Duration:R", "Login Progress:L", "Keep-Alives:R", "Retransmits:R", "NullCreds:R", "DHE:R", "LoginAck:L", "Error:L");
16541656
switch (Program.filterFormat)
16551657
{
@@ -1713,18 +1715,20 @@ private static void DisplayNamedPipesReport(NetworkTrace Trace)
17131715
}
17141716
}
17151717

1716-
Program.logMessage(rf.GetHeaderText());
1717-
Program.logMessage(rf.GetSeparatorText());
1718-
1719-
for (int i = 0; i < rf.GetRowCount(); i++)
1718+
if (PipeRecords.Count != 0)
17201719
{
1721-
Program.logMessage(rf.GetDataText(i));
1722-
}
1723-
1724-
Program.logMessage();
1720+
Program.logMessage("The following Named Pipes conversations were detected in the network trace:\r\n");
1721+
Program.logMessage(rf.GetHeaderText());
1722+
Program.logMessage(rf.GetSeparatorText());
17251723

1724+
for (int i = 0; i < rf.GetRowCount(); i++)
1725+
{
1726+
Program.logMessage(rf.GetDataText(i));
1727+
}
17261728

1727-
if (PipeRecords.Count == 0)
1729+
Program.logMessage();
1730+
}
1731+
else
17281732
{
17291733
Program.logMessage("No Named Pipes conversations found.");
17301734
Program.logMessage();
@@ -2203,6 +2207,42 @@ private static void DisplayClientPortUsage(NetworkTrace Trace)
22032207
Program.logMessage();
22042208
}
22052209

2210+
private static void DisplayMTUReport(NetworkTrace Trace)
2211+
{
2212+
ArrayList MTUSizes = new ArrayList();
2213+
int maxPayloadSize = 0;
2214+
2215+
// gather unique max payload sizes
2216+
foreach (ConversationData c in Trace.conversations)
2217+
{
2218+
if (c.maxPayloadSize > maxPayloadSize) maxPayloadSize = c.maxPayloadSize;
2219+
if (c.maxPayloadLimit && MTUSizes.IndexOf(c.maxPayloadSize) < 0) MTUSizes.Add(c.maxPayloadSize);
2220+
}
2221+
2222+
Program.logMessage($"The maximum payload size observed was {maxPayloadSize}.");
2223+
2224+
// how many did we find?
2225+
if (MTUSizes.Count == 1)
2226+
{
2227+
Program.logMessage($"The MTU maximum payload size observed was {(int)MTUSizes[0]}.");
2228+
}
2229+
else if (MTUSizes.Count > 0)
2230+
{
2231+
string rowList = "";
2232+
var OrderedRows = from row in MTUSizes.ToArray() orderby (int)row ascending select row;
2233+
foreach (var row in OrderedRows) rowList += ", " + row.ToString();
2234+
rowList = rowList.Substring(2); // get rid of leading ", "
2235+
Program.logMessage($"Multiple MTU maximum payload sizes were observed: {rowList}");
2236+
2237+
}
2238+
else
2239+
{
2240+
Program.logMessage("MTU maximum payload size was not determined.");
2241+
}
2242+
2243+
Program.logMessage();
2244+
}
2245+
22062246
private static void DisplayRedirectedConnections(NetworkTrace Trace)
22072247
{
22082248
//
@@ -2387,7 +2427,7 @@ private static void DisplayFooter()
23872427

23882428
private static void OutputStats(NetworkTrace Trace)
23892429
{
2390-
Program.logStat(@"SourceIP,SourcePort,DestIP,DestPort,IPVersion,Protocol,Syn,Fin,Reset,Retransmit,KeepAlive,Integrated Login,NTLM,Login7,Encrypted,Mars,Frames,Bytes,SentBytes,ReceivedBytes,Bytes/Sec,StartFile,EndFile,StartTime,EndTime,Duration,ServerName,ServerVersion,DatabaseName,ServerTDSVersion,ClientTDSVersion,ServerTLSVersion,ClientTLSVersion,RedirSrv,RedirPort,Error,ErrorState,ErrorMessage,");
2430+
Program.logStat(@"SourceIP,SourcePort,DestIP,DestPort,IPVersion,Protocol,Syn,Fin,Reset,Retransmit,KeepAlive,Integrated Login,NTLM,Login7,Encrypted,Mars,MaxPayloadSize,PayloadSizeLimit,Frames,Bytes,SentBytes,ReceivedBytes,Bytes/Sec,StartFile,EndFile,StartTime,EndTime,Duration,ServerName,ServerVersion,DatabaseName,ServerTDSVersion,ClientTDSVersion,ServerTLSVersion,ClientTLSVersion,RedirSrv,RedirPort,Error,ErrorState,ErrorMessage,");
23912431
foreach (ConversationData c in Trace.conversations)
23922432
{
23932433
int firstFile = Trace.files.IndexOf(((FrameData)(c.frames[0])).file);
@@ -2421,6 +2461,8 @@ private static void OutputStats(NetworkTrace Trace)
24212461
(c.hasLogin7 ? "Y" : "") + "," +
24222462
(c.isEncrypted ? "Y" : "") + "," +
24232463
(c.isSQL && (c.isMARSEnabled || (c.smpAckCount + c.smpSynCount + c.smpFinCount + c.smpDataCount) > 0) ? "Y" : "") + "," +
2464+
c.maxPayloadSize + "," +
2465+
(c.maxPayloadLimit ? "Y": "") + "," +
24242466
c.frames.Count + "," +
24252467
c.totalBytes + "," +
24262468
"," + // do not have a separate counter for sent bytes TODO ? do we really need it?

0 commit comments

Comments
 (0)