wip address feedback and simplify script
Catalin-Emil Fetoiu committed
Oct 18, 2023 at 16:55 UTC
330da556103391c6a200615184189dcec733ddd0
5 files changed
+203
-160
CONTRIBUTING.md
+6
-25
@@ -117,35 +117,16 @@ Availability Capabilities CapabilityDescriptions
117
{3, 4, 10} {"Random Access", "Supports Writing", "SMART Notification"} \\.\PHYSICALDRIVE2 SCSI TRUE Fixed hard disk media ST2000DM001-1ER164 \\.\PHYSICALDRIVE2 1
118
```
119
120
-#### Networking issues
120
+#### Collect WSL logs for networking issues
121
122
-Install tcpdump in your WSL distribution using the following commands.
123
-Note: This might not work if WSL has Internet connectivity issues.
122
+To collect WSL networking logs, download and execute [collect-wsl-logs.ps1](https://github.com/Microsoft/WSL/blob/master/diagnostics/collect-networking-logs.ps1) in an administrative powershell prompt:
123
124
```
126
-# sudo apt-get update
127
-# sudo apt-get -y install tcpdump
128
-```
129
-
130
-Run networking_diagnostics.bat in an administrative Powershell window:
131
-
132
-```
133
-$ Invoke-WebRequest 'https://github.com/microsoft/WSL/archive/refs/heads/master.zip' -OutFile .\wsl.zip
134
-$ Expand-Archive .\wsl.zip .\
135
-$ Remove-Item .\wsl.zip
136
-$ cd .\WSL-master\diagnostics
137
-$ .\networking_diagnostics.bat
125
+Invoke-WebRequest -UseBasicParsing "https://raw.githubusercontent.com/microsoft/WSL/master/diagnostics/collect-networking-logs.ps1" -OutFile collect-networking-logs.ps1
126
+Set-ExecutionPolicy Bypass -Scope Process -Force
127
+.\collect-networking-logs.ps1
128
```
139
-
140
-Note:
141
-If tcpdump is installed, the script will open 2 more shells.
142
-If tcpdump is not installed, only 1 additional shell will be opened
143
-Wait for those shells to be opened before reproducing the issue
144
-
145
-After reproducing the issue, in the shell with tcpdump, hit Ctrl + C. In the other shell, press any key.
146
-After the new shells exit, press any key in the original Powershell window.
147
-
148
-The script will output the path to a zip archive with the diagnostics when done. Collect the zip and attach it to the issue.
129
+The script will output the path of the log file once done.
130
131
<!-- Preserving anchors -->
132
<div id="8-detailed-logs"></div>
diagnostics/collect-networking-logs.ps1
new
+191
@@ -0,0 +1,191 @@
1
+#Requires -RunAsAdministrator
2
+
3
+[CmdletBinding()]
4
+Param (
5
+ [switch]$DeleteHnsState = $false
6
+ )
7
+
8
+$folder = "WslNetworkingLogs-" + (Get-Date -Format "yyyy-MM-dd_HH-mm-ss")
9
+mkdir -p $folder
10
+
11
+# TODO! tcpdump??
12
+
13
+# Retrieve WSL version and wslconfig file
14
+get-appxpackage MicrosoftCorporationII.WindowsSubsystemforLinux > $folder/appxpackage.txt
15
+
16
+$wslconfig = "$env:USERPROFILE/.wslconfig"
17
+if (Test-Path $wslconfig)
18
+{
19
+ Copy-Item $wslconfig $folder
20
+}
21
+
22
+if ($DeleteHnsState)
23
+{
24
+ # The WSL HNS network is created once per boot. Resetting it to collect network creation logs.
25
+ Get-HnsNetwork | Where-Object {$_.Name -eq 'WSL'} | Remove-HnsNetwork
26
+
27
+ # Stop WSL.
28
+ net.exe stop WslService || net.exe stop LxssManager
29
+}
30
+
31
+# Collect Linux network state before the repro
32
+& wsl.exe -e ./networking.sh 2>&1 > $folder/linux_network_configuration_before.log
33
+
34
+# Start logging.
35
+$logProfile = ".\wsl_networking.wprp"
36
+$wprOutputLog = "$folder/wpr.txt"
37
+
38
+wpr.exe -start $logProfile -filemode 2>&1 >> $wprOutputLog
39
+if ($LastExitCode -Ne 0)
40
+{
41
+ Write-Host -ForegroundColor Yellow "Log collection failed to start (exit code: $LastExitCode), trying to reset it."
42
+ wpr.exe -cancel 2>&1 >> $wprOutputLog
43
+
44
+ wpr.exe -start $logProfile -filemode 2>&1 >> $wprOutputLog
45
+ if ($LastExitCode -Ne 0)
46
+ {
47
+ Write-Host -ForegroundColor Red "Couldn't start log collection (exitCode: $LastExitCode)"
48
+ }
49
+}
50
+
51
+# Start packet capture using pktmon
52
+pktmon start -c --flags 0x1A --file-name "$folder/pktmon.etl"
53
+
54
+# Start WFP capture
55
+netsh wfp capture start file="$folder/wfpdiag.cab"
56
+
57
+try
58
+{
59
+ Write-Host -NoNewLine -ForegroundColor Green "Log collection is running. Please reproduce the problem and press any key to save the logs."
60
+
61
+ $KeysToIgnore =
62
+ 16, # Shift (left or right)
63
+ 17, # Ctrl (left or right)
64
+ 18, # Alt (left or right)
65
+ 20, # Caps lock
66
+ 91, # Windows key (left)
67
+ 92, # Windows key (right)
68
+ 93, # Menu key
69
+ 144, # Num lock
70
+ 145, # Scroll lock
71
+ 166, # Back
72
+ 167, # Forward
73
+ 168, # Refresh
74
+ 169, # Stop
75
+ 170, # Search
76
+ 171, # Favorites
77
+ 172, # Start/Home
78
+ 173, # Mute
79
+ 174, # Volume Down
80
+ 175, # Volume Up
81
+ 176, # Next Track
82
+ 177, # Previous Track
83
+ 178, # Stop Media
84
+ 179, # Play
85
+ 180, # Mail
86
+ 181, # Select Media
87
+ 182, # Application 1
88
+ 183 # Application 2
89
+
90
+ $Key = $null
91
+ while ($Key -Eq $null -Or $Key.VirtualKeyCode -Eq $null -Or $KeysToIgnore -Contains $Key.VirtualKeyCode)
92
+ {
93
+ $Key = $Host.UI.RawUI.ReadKey('NoEcho,IncludeKeyDown')
94
+ }
95
+
96
+ Write-Host "`nSaving logs..."
97
+}
98
+finally
99
+{
100
+ netsh wfp capture stop
101
+ pktmon stop
102
+ wpr.exe -stop $folder/logs.etl 2>&1 >> $wprOutputLog
103
+}
104
+
105
+# Collect Linux network state after the repro
106
+& wsl.exe -e ./networking.sh 2>&1 > $folder/linux_network_configuration_after.log
107
+
108
+# Collect host networking state relevant for WSL
109
+# Using a try/catch for commands below, as some of them do not exist on all OS versions
110
+
111
+try
112
+{
113
+ Get-NetAdapter -includeHidden | select Name,ifIndex,NetLuid,InterfaceGuid,Status,MacAddress,MtuSize,InterfaceType,Hidden,HardwareInterface,ConnectorPresent,MediaType,PhysicalMediaType | Out-File -FilePath "$folder/Get-NetAdapter.log" -Append
114
+}
115
+catch {}
116
+
117
+try
118
+{
119
+ Get-NetIPConfiguration -All -Detailed | Out-File -FilePath "$folder/Get-NetIPConfiguration.log" -Append
120
+}
121
+catch {}
122
+
123
+try
124
+{
125
+ Get-NetRoute | Out-File -FilePath "$folder/Get-NetRoute.log" -Append
126
+}
127
+catch {}
128
+
129
+try
130
+{
131
+ Get-NetFirewallHyperVVMCreator | Out-File -FilePath "$folder/Get-NetFirewallHyperVVMCreator.log" -Append
132
+}
133
+catch {}
134
+
135
+try
136
+{
137
+ Get-NetFirewallHyperVVMSetting -PolicyStore ActiveStore | Out-File -FilePath "$folder/Get-NetFirewallHyperVVMSetting_ActiveStore.log" -Append
138
+}
139
+catch {}
140
+
141
+try
142
+{
143
+ Get-NetFirewallHyperVProfile -PolicyStore ActiveStore | Out-File -FilePath "$folder/Get-NetFirewallHyperVProfile_ActiveStore.log" -Append
144
+}
145
+catch {}
146
+
147
+try
148
+{
149
+ Get-NetFirewallHyperVRule -PolicyStore ActiveStore | Out-File -FilePath "$folder/Get-NetFirewallHyperVRule_ActiveStore.log" -Append
150
+}
151
+catch {}
152
+
153
+try
154
+{
155
+ Get-NetFirewallHyperVPort | Out-File -FilePath "$folder/Get-NetFirewallHyperVPort.log" -Append
156
+}
157
+catch {}
158
+
159
+try
160
+{
161
+ & hnsdiag.exe list all 2>&1 > $folder/hnsdiag_list_all.log
162
+}
163
+catch {}
164
+
165
+try
166
+{
167
+ & hnsdiag.exe list endpoints -df 2>&1 > $folder/hnsdiag_list_endpoints.log
168
+}
169
+catch {}
170
+
171
+try
172
+{
173
+ foreach ($port in Get-NetFirewallHyperVPort)
174
+ {
175
+ & vfpctrl.exe /port $port.PortName /get-port-state 2>&1 > "$folder/vfp-port-$($port.PortName)-get-port-state.log"
176
+ & vfpctrl.exe /port $port.PortName /list-rule 2>&1 > "$folder/vfp-port-$($port.PortName)-list-rule.log"
177
+ }
178
+}
179
+catch {}
180
+
181
+try
182
+{
183
+ & vfpctrl.exe /list-vmswitch-port 2>&1 > $folder/vfpctrl_list_vmswitch_port.log
184
+}
185
+catch {}
186
+
187
+logArchive = "$(Resolve-Path $folder).zip"
188
+Compress-Archive -Path $folder -DestinationPath $logArchive
189
+Remove-Item $folder -Recurse
190
+
191
+Write-Host -ForegroundColor Green "Logs saved in: $logArchive. Please attach that file to the GitHub issue."
\ No newline at end of file
diagnostics/collect-wsl-logs.ps1
-73
@@ -130,79 +130,6 @@ if ($Dump)
130
}
131
}
132
133
-# Collect networking state relevant for WSL
134
-# Using a try/catch for commands below, as some of them do not exist on all OS versions
135
-
136
-Write-Host "`nCollecting additional network state..."
137
-
138
-$networkingFolder = "$folder/networking"
139
-mkdir -p $networkingFolder
140
-
141
-# Host networking info
142
-try
143
-{
144
- Get-NetAdapter -includeHidden | select Name,ifIndex,NetLuid,InterfaceGuid,Status,MacAddress,MtuSize,InterfaceType,Hidden,HardwareInterface,ConnectorPresent,MediaType,PhysicalMediaType | Out-File -FilePath "$networkingFolder/Get-NetAdapter.log" -Append
145
-}
146
-catch {}
147
-
148
-try
149
-{
150
- Get-NetIPConfiguration -All -Detailed | Out-File -FilePath "$networkingFolder/Get-NetIPConfiguration.log" -Append
151
-}
152
-catch {}
153
-
154
-try
155
-{
156
- Get-NetFirewallHyperVVMCreator | Out-File -FilePath "$networkingFolder/Get-NetFirewallHyperVVMCreator.log" -Append
157
-}
158
-catch {}
159
-
160
-try
161
-{
162
- Get-NetFirewallHyperVVMSetting -PolicyStore ActiveStore | Out-File -FilePath "$networkingFolder/Get-NetFirewallHyperVVMSetting_ActiveStore.log" -Append
163
-}
164
-catch {}
165
-
166
-try
167
-{
168
- Get-NetFirewallHyperVProfile -PolicyStore ActiveStore | Out-File -FilePath "$networkingFolder/Get-NetFirewallHyperVProfile_ActiveStore.log" -Append
169
-}
170
-catch {}
171
-
172
-try
173
-{
174
- Get-NetFirewallHyperVPort | Out-File -FilePath "$networkingFolder/Get-NetFirewallHyperVPort.log" -Append
175
-}
176
-catch {}
177
-
178
-try
179
-{
180
- & hnsdiag.exe list all 2>&1 > $networkingFolder/hnsdiag_list_all.log
181
-}
182
-catch {}
183
-
184
-try
185
-{
186
- & hnsdiag.exe list endpoints -df 2>&1 > $networkingFolder/hnsdiag_list_endpoints.log
187
-}
188
-catch {}
189
-
190
-try
191
-{
192
- foreach ($port in Get-NetFirewallHyperVPort)
193
- {
194
- & vfpctrl.exe /port $port.PortName /get-port-state 2>&1 > "$networkingFolder/vfp-port-$($port.PortName)-get-port-state.log"
195
- & vfpctrl.exe /port $port.PortName /list-rule 2>&1 > "$networkingFolder/vfp-port-$($port.PortName)-list-rule.log"
196
- }
197
-}
198
-catch {}
199
-
200
-try
201
-{
202
- & vfpctrl.exe /list-vmswitch-port 2>&1 > $networkingFolder/vfpctrl_list_vmswitch_port.log
203
-}
204
-catch {}
205
-
133
$logArchive = "$(Resolve-Path $folder).zip"
134
Compress-Archive -Path $folder -DestinationPath $logArchive
135
Remove-Item $folder -Recurse
diagnostics/networking.sh
+6
-2
@@ -5,11 +5,15 @@ set -xu
5
lsb_release -a || cat /etc/issue /etc/os-release
6
uname -a
7
8
-# Output adapter & routing configuration.
8
+echo "Printing adapter & routing configuration"
9
ip a
10
ip route show table all
11
ip neighbor
12
ip link
13
14
-# Display the DNS configuration.
14
+# This will include the HTTP proxy env variables, if present
15
+echo "Printing all environment variables"
16
+printenv
17
+
18
+echo "Printing DNS configuration"
19
cat /etc/resolv.conf
diagnostics/networking_diagnostics.bat
deleted
-60
@@ -1,60 +0,0 @@
1
-:: Check for administrator privileges.
2
-net session >nul 2>&1 || goto :admin
3
-
4
-:: Validate that required files are here.
5
-if not exist wsl_networking.wprp (echo wsl_networking.wprp not found && exit /b 1)
6
-if not exist networking.sh (echo networking.sh not found && exit /b 1)
7
-
8
-set networking_folder=".\networking_logs"
9
-set neworking_logs_zip=".\WslNetworkingLogs.zip"
10
-
11
-mkdir %networking_folder%
12
-
13
-cd %networking_folder%
14
-
15
-IF "%1"=="--stop-wsl" (
16
- :: The WSL HNS network is created once per boot. Resetting it to collect network creation logs.
17
- echo Deleting HNS network
18
- powershell.exe -NoProfile "Get-HnsNetwork | Where-Object {$_.Name -eq 'WSL'} | Remove-HnsNetwork"
19
-
20
- :: Stop WSL.
21
- net.exe stop WslService || net.exe stop LxssManager
22
-)
23
-
24
-wsl.exe tr -d "\r" ^| bash < ../networking.sh > wsl_network_configuration_before.log
25
-powershell Get-NetRoute > get_netroute.log
26
-
27
-powershell invoke-expression 'cmd /c start powershell -Command { ..\collect-wsl-logs.ps1 }'
28
-powershell invoke-expression 'cmd /c start powershell -Command { "wsl.exe -u root sudo tcpdump -n -i any > tcpdump.log" }'
29
-
30
-wpr -start ..\wsl_networking.wprp -filemode -instanceName wpr_networking
31
-pktmon start -c --flags 0x1A
32
-netsh wfp capture start
33
-
34
-pause
35
-
36
-:: allow some time for the user to stop logs in all the spawned shells
37
-timeout 20
38
-
39
-netsh wfp capture stop
40
-pktmon stop
41
-wpr -stop wsl_networking.etl -instanceName wpr_networking
42
-
43
-wsl.exe tr -d "\r" ^| bash < ../networking.sh > wsl_network_configuration_after.log
44
-
45
-cd ..
46
-
47
-del %neworking_logs_zip%
48
-powershell Compress-Archive -Path %networking_folder% -DestinationPath %neworking_logs_zip%
49
-
50
-rmdir /s /q %networking_folder%
51
-
52
-echo "Finished log collection - please collect the zip archive from the path below"
53
-powershell Resolve-Path %neworking_logs_zip%
54
-
55
-exit /b 0
56
-
57
-:: Error message if the user does not have administrative privileges.
58
-:admin
59
-echo This script needs to run with administrative privileges.
60
-exit /b 1
\ No newline at end of file