OpenVPN / openvpn

OpenVPN is an open source VPN daemon
http://openvpn.net
Other
10.25k stars 2.92k forks source link

tapctl.exe creates an adapter, but fails to rename it #544

Closed oblomingo closed 2 months ago

oblomingo commented 2 months ago

Describe the bug tapctl.exe fails on creating adapter and shows an error:

C:\Program Files\App\Resources\x64>tapctl.exe create --hwid ovpn-dco --name "Custom name"
tap_set_adapter_name: Error renaming adapter
Error 0x1: Incorrect function.
Renaming TUN/TAP adapter {45EBB6FE-B5FD-472D-A04A-2E26ABA6F09B} to "Custom name" failed (error 0x1).

However C:\Windows\INF\setupapi.dev.log content doesn't have error message:

>>>  [Device Install (DiInstallDevice) - ROOT\NET\0000]
>>>  Section start 2024/04/24 16:38:27.352
      cmd: tapctl.exe  create --hwid ovpn-dco --name "Custom name"
     ndv: Flags: 0x00000000
     ndv: Search options: 0x00000002
     ndv: Searching default INF path
     dvi: {Build Driver List} 16:38:27.368
     dvi:      Searching for hardware ID(s):
     dvi:           ovpn-dco
     dvi:      Created Driver Node:
     dvi:           HardwareID   - ovpn-dco
     dvi:           InfName      - C:\Windows\System32\DriverStore\FileRepository\ovpn-dco.inf_amd64_f2b346196cf322ed\ovpn-dco.inf
     dvi:           DevDesc      - OpenVPN Data Channel Offload
     dvi:           Section      - ovpn-dco_Device.NT
     dvi:           Rank         - 0x00ff0000
     dvi:           Signer Score - WHQL
     dvi:           DrvDate      - 04/12/2024
     dvi:           Version      - 1.1.1.0
     dvi: {Build Driver List - exit(0x00000000)} 16:38:27.511
     dvi: {DIF_SELECTBESTCOMPATDRV} 16:38:27.511
     dvi:      Default installer: Enter 16:38:27.511
     dvi:           {Select Best Driver}
     dvi:                Class GUID of device changed to: {4d36e972-e325-11ce-bfc1-08002be10318}.
     dvi:                Selected Driver:
     dvi:                     Description - OpenVPN Data Channel Offload
     dvi:                     InfFile     - c:\windows\system32\driverstore\filerepository\ovpn-dco.inf_amd64_f2b346196cf322ed\ovpn-dco.inf
     dvi:                     Section     - ovpn-dco_Device
     dvi:           {Select Best Driver - exit(0x00000000)}
     dvi:      Default installer: Exit
     dvi: {DIF_SELECTBESTCOMPATDRV - exit(0x00000000)} 16:38:27.511
     ndv: Driver package 'C:\Windows\System32\DriverStore\FileRepository\ovpn-dco.inf_amd64_f2b346196cf322ed\ovpn-dco.inf' is already imported.
     sto: {Setup Import Driver Package: C:\Windows\INF\oem0.inf} 16:38:27.527
     sto:      Driver package already imported as 'oem0.inf'.
     sto: {Setup Import Driver Package - exit (0x00000000)} 16:38:27.531
     dvi: Searching for hardware ID(s):
     dvi:      ovpn-dco
     dvi: Class GUID of device changed to: {4d36e972-e325-11ce-bfc1-08002be10318}.
     ump: {Plug and Play Service: Device Install for ROOT\NET\0000}
     dvi:      {Core Device Install} 16:38:27.594
     dvi:           {Configure Device - ROOT\NET\0000} 16:38:27.594
     dvi:                Device Status: 0x01802001
     dvi:                Parent Device: HTREE\ROOT\0
     sto:                {Configure Driver Package: C:\Windows\System32\DriverStore\FileRepository\ovpn-dco.inf_amd64_f2b346196cf322ed\ovpn-dco.inf}
     sto:                     Source Filter  = ovpn-dco
     inf:                     Config Options = ForceConfigurable ForceCritical
     inf:                     Class GUID     = {4d36e972-e325-11ce-bfc1-08002be10318}
     inf:                     Class Options  = Configurable
     inf:                     {Configure Driver: OpenVPN Data Channel Offload}
     inf:                          Section Name = ovpn-dco_Device.NT
     inf:                          {Add Service: ovpn-dco}
     inf:                               Start Type    = 3
     inf:                               Service Type  = 1
     inf:                               Error Control = 1
     inf:                               Image Path    = \SystemRoot\System32\drivers\ovpn-dco.sys
     inf:                               Display Name  = ovpn-dco
     inf:                               Updated service 'ovpn-dco'.
     inf:                          {Add Service: exit(0x00000000)}
     inf:                          Hardware Id  = ovpn-dco
     inf:                          {Configure Driver Configuration: ovpn-dco_Device.NT}
     inf:                               Service Name  = ovpn-dco
     inf:                               Config Flags  = 0x00000000
     inf:                          {Configure Driver Configuration: exit(0x00000000)}
     inf:                     {Configure Driver: exit(0x00000000)}
     flq:                     {FILE_QUEUE_COMMIT} 16:38:27.607
     flq:                          Copying 'C:\Windows\System32\DriverStore\FileRepository\ovpn-dco.inf_amd64_f2b346196cf322ed\ovpn-dco.sys' to 'C:\Windows\System32\drivers\ovpn-dco.sys'.
     cpy:                          Existing file 'C:\Windows\System32\drivers\ovpn-dco.sys' remains unchanged.
     flq:                     {FILE_QUEUE_COMMIT - exit(0x00000000)} 16:38:27.638
     sto:                {Configure Driver Package: exit(0x00000000)}
     dvi:                Install Device: Configuring device. 16:38:27.638
     dvi:                     Configuration: oem0.inf:ovpn-dco,ovpn-dco_Device
     dvi:                Install Device: Configuring device completed. 16:38:27.638
     dvi:                Device Status: 0x01802001
     dvi:                Install Device: Starting device 'ROOT\NET\0000'. 16:38:27.638
     dvi:                Install Device: Starting device completed. 16:38:27.638
!    dvi:                Device pending start: Device has problem: 0x38 (CM_PROB_NEED_CLASS_CONFIG), problem status: 0x00000000.
     dvi:           {Configure Device - exit(0x00000000)} 16:38:27.638
     dvi:      {Core Device Install - exit(0x00000000)} 16:38:27.638
     dvi:      Waiting for device post-install to complete. 16:38:27.638
     dvi:      Device post-install completed. 16:38:27.702
     dvi:      Device Status: 0x0180200b
     ump: {Plug and Play Service: Device Install exit(00000000)}
<<<  Section end 2024/04/24 16:38:27.719
<<<  [Exit status: SUCCESS]

The command actually creates an adapter, but fails to rename it:

C:\Program Files\App\Resources\x64>tapctl.exe list
{5A9AD0A4-66E4-497C-9DC9-A29EFFC7F1DB}  Local Area Connection

To Reproduce Add OpenVPN DCO driver merged module (https://github.com/OpenVPN/ovpn-dco-win/releases/download/1.1.1/ovpn-dco-amd64.msm) to a installer. Install an app with OpenVPN DCO driver merged module to Windows 11 (22621.3447) After installation ensure that OpenVPN DCO driver is installed successfully. After the installation process, run a command line "tapctl.exe create --hwid ovpn-dco --name "Custom name"" The command line fails and shows the error message:

tap_set_adapter_name: Error renaming adapter
Error 0x1: Incorrect function.
Renaming TUN/TAP adapter {45EBB6FE-B5FD-472D-A04A-2E26ABA6F09B} to "Custom name" failed (error 0x1).

Expected behavior The command line creates a device with a defined name.

Version information (please complete the following information):

lstipakov commented 2 months ago

Interesting, I cannot reproduce this.

c:\Program Files\OpenVPN\bin>tapctl.exe create --hwid ovpn-dco --name "MyDCO"
{1160607E-64CC-4AF2-B963-5BE423BCD2E5}

c:\Program Files\OpenVPN\bin>tapctl.exe create --hwid ovpn-dco --name "My DCO With Space"
{3CFBF630-D210-4CC7-9EEE-A0B6D59DEABB}

c:\Program Files\OpenVPN\bin>tapctl.exe list
{D7F5936F-D623-4EC7-BDAB-BD6E736E39E6}  OpenVPN Wintun
{0A680EC7-27E6-418B-9B3F-E5694418BD01}  Local Area Connection
{52292200-D7C3-4003-8836-410FCD03A0F2}  OpenVPN TAP-Windows6
{3462ADE4-545A-44E2-972D-9800EDDA14FC}  OpenVPN Data Channel Offload
{DA06723C-4181-4634-B7C0-967314E68B00}  OpenVPN Data Channel Offload #1
{1160607E-64CC-4AF2-B963-5BE423BCD2E5}  MyDCO
{3CFBF630-D210-4CC7-9EEE-A0B6D59DEABB}  My DCO With Space

Note that if you just run c:\Program Files\OpenVPN\bin>tapctl.exe create --hwid ovpn-dco you are supposed to get an adapter named OpenVPN Data Channel Offload or OpenVPN Data Channel Offload #1, OpenVPN Data Channel Offload #2 and so on.

Could you try to rename the adapter manually with netsh call? This is basically what tap_set_adapter_name is doing under the hood.

oblomingo commented 2 months ago

It reproduces in a Windows sandbox, but works as expected on my computer. In case I would like to use netsh it would requires an additional actions, like:

  1. An installation proceess need to parse an id from the tapctl.exe create --hwid ovpn-dco command line result.
  2. Probably, use the same tapctl.exe to get interface name by the id value.
  3. Run netsh interface set interface name="Current name" newname="Custom name"

And since we don't know the root case of the issue, the result may be the same. Anyway, thank for the help. Probably, netsh renaming can be implemented as fallback action (plan B) when tapctl fails on renaming.

lstipakov commented 2 months ago

I would really like to fix it but I need to reproduce it first. Would you be willing to try if I'll provide a tapctl version with extended logging?

oblomingo commented 2 months ago

Sure, please provide a link to the updated version and will try.

oblomingo commented 2 months ago

@lstipakov any updates?