WINTUN: Error registering rings (Error 87, INVALID_ARGUMENT)
Simon Rozman
simon at rozman.si
Thu Jul 23 14:29:02 CEST 2020
Hi,
> I am currently trying to create a testtool using the WINTUN driver to
> establish a 1:1 connection to another client and see what wintun is
> capable of. Unfortunately I cannot get the rings to register. I have
> written a small testprogram in order to reproduce this.
>
> #include <windows.h>
> #include <winioctl.h>
> #include <IPHlpApi.h>
> #include <ndisguid.h>
> #include <TlHelp32.h>
> #include <tchar.h>
> #include <securitybaseapi.h>
> #include <cfgmgr32.h>
>
> #include <stdint.h>
> #include <stdio.h>
> #include <string>
> #include <assert.h>
>
> #pragma pack(push, 1)
Remove the #pragma pack(push, 1)!!!
> typedef struct _TUN_PACKET_PROTO {
> ULONG Size;
> UCHAR Data[]; // max packet size as defined by the driver.
> } TUN_PACKET_PROTO;
>
> typedef struct _TUN_RING_PROTO {
> volatile ULONG Head;
> volatile ULONG Tail;
> volatile LONG Alertable;
> UCHAR Data[];
> } TUN_RING_PROTO;
.
.
.
> typedef struct _TUN_RING {
> volatile ULONG Head;
> volatile ULONG Tail;
> volatile LONG Alertable;
> UCHAR Data[WINTUN_RING_CAPACITY + (TUN_MAX_PACKET_SIZE-
> TUN_ALIGNMENT)];
> } TUN_RING;
>
> typedef struct _TUN_PACKET {
> ULONG Size;
> UCHAR Data[WINTUN_MAX_PACKET_SIZE]; // max packet size as
> defined by the driver.
> } TUN_PACKET;
>
> typedef struct _TUN_REGISTER_RINGS {
> struct {
> ULONG RingSize;
> TUN_RING *Ring;
> HANDLE TailMoved;
> } Send, Receive;
> } TUN_REGISTER_RINGS;
> #pragma pack(pop)
Remove #pragma pack(pop)
> I cannot figure out what I am doing wrong. Can somebody point out the
> error for me? Thanks!
With the #pragma removed, your test program kind of works:
Output with #pragma pack:
Opened wintun device.
Could not register ring buffers (87).
Experiment failed.
Size TUNRING: 8454156 (8454156)
Capacity: 8388608
Output without #pragma pack:
Opened wintun device.
Size TUNRING: 8454156 (8454156)
Capacity: 8388608
And one more thing... Markus, please: why all the profanity in your code? Code is a work of art. A poetry. I understand Microsoft is silly a lot of times and difficult to go along with. But don't let that turn *you* into a silly grumpy geek. :)
Regards,
Simon
More information about the WireGuard
mailing list