@@ -184,7 +184,9 @@ void NETIOAPI_API_ VirtioNetworking::OnNetworkConnectivityChange(PVOID context,
184184void VirtioNetworking::RefreshGuestConnection () noexcept
185185try
186186{
187- // Query current networking information before acquiring the lock.
187+ // Acquire the lock and perform device updates.
188+ auto lock = m_lock.lock_exclusive ();
189+
188190 m_networkSettings = GetHostEndpointSettings ();
189191
190192 // TODO: Determine gateway MAC address
220222
221223 const auto newDeviceOptions = device_options.str ();
222224
223- networking::DnsInfo currentDns{};
224- if (WI_IsFlagSet (m_flags, VirtioNetworkingFlags::DnsTunneling))
225- {
226- currentDns = networking::HostDnsInfo::GetDnsTunnelingSettings (default_route);
227- }
228- else
229- {
230- currentDns = networking::HostDnsInfo::GetDnsSettings (networking::DnsSettingsFlags::IncludeVpn);
231- }
232-
233- const auto minMtu = GetMinimumConnectedInterfaceMtu ();
234-
235- // Acquire the lock and perform device updates.
236- auto lock = m_lock.lock_exclusive ();
237225 if (newDeviceOptions != m_trackedDeviceOptions)
238226 {
239227 m_trackedDeviceOptions = newDeviceOptions;
277265 }
278266
279267 // Send DNS update if needed.
268+ networking::DnsInfo currentDns{};
269+ if (WI_IsFlagSet (m_flags, VirtioNetworkingFlags::DnsTunneling))
270+ {
271+ currentDns = networking::HostDnsInfo::GetDnsTunnelingSettings (default_route);
272+ }
273+ else
274+ {
275+ currentDns = networking::HostDnsInfo::GetDnsSettings (networking::DnsSettingsFlags::IncludeVpn);
276+ }
277+
280278 if (currentDns != m_trackedDnsSettings)
281279 {
282280 m_trackedDnsSettings = currentDns;
288286 }
289287
290288 // Send MTU update if needed.
289+ const auto minMtu = GetMinimumConnectedInterfaceMtu ();
291290 if (minMtu && minMtu.value () != m_networkMtu)
292291 {
293292 m_networkMtu = minMtu.value ();
0 commit comments