aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJason A. Donenfeld <Jason@zx2c4.com>2019-07-04 21:06:17 +0000
committerJason A. Donenfeld <Jason@zx2c4.com>2019-07-05 06:15:46 +0000
commit74371554461a5f8cc42e4828d6123febc88c1dec (patch)
tree5f983d40f854164c5e27aefb7f54c5e5455193db
parentDo not use _RESOURCES but rather allocate our own copy (diff)
downloadwintun-74371554461a5f8cc42e4828d6123febc88c1dec.tar.xz
wintun-74371554461a5f8cc42e4828d6123febc88c1dec.zip
Decrease alignment requirements to 4
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
-rw-r--r--.clang-format1
-rw-r--r--README.md19
-rw-r--r--wintun.c5
3 files changed, 11 insertions, 14 deletions
diff --git a/.clang-format b/.clang-format
index 9bbe60a..0b702a7 100644
--- a/.clang-format
+++ b/.clang-format
@@ -98,6 +98,7 @@ StatementMacros: [
'__drv_preferredFunction',
'__drv_allocatesMem',
'__drv_freesMem',
+ '_Field_size_bytes_',
]
TabWidth: '4'
UseTab: Never
diff --git a/README.md b/README.md
index 3a01a0d..3b31880 100644
--- a/README.md
+++ b/README.md
@@ -89,11 +89,6 @@ After loading the driver and creating a network interface the typical way using
| 4 bytes, native endian |
+------------------------------+
| |
-| padding |
-| 12 bytes, all zero |
-| |
-+------------------------------+
-| |
| packet_0 |
| size_0 bytes |
| |
@@ -101,22 +96,22 @@ After loading the driver and creating a network interface the typical way using
| |
+------------------------------+
| padding |
-| 16-(size_0&15) bytes, |
-| all zero |
+| 4-(size_0&3) bytes |
+------------------------------+
| size_1 |
| 4 bytes, native endian |
+------------------------------+
| |
-| padding |
-| 12 bytes, all zero |
-| |
-+------------------------------+
-| |
| packet_1 |
| size_1 bytes |
| |
~ ~
+| |
++------------------------------+
+| padding |
+| 4-(size_1&3) bytes |
++------------------------------+
+~ ~
```
Each packet segment should contain a layer 3 IPv4 or IPv6 packet. Up to 15728640 bytes may be read or written during each call to `ReadFile` or `WriteFile`. All calls to `ReadFile` must be called with the same virtual address, for a given handle. This virtual address must reference pages that are writable for the same length as passed to the first call of `ReadFile`.
diff --git a/wintun.c b/wintun.c
index 3ff9e8c..9ba1b1f 100644
--- a/wintun.c
+++ b/wintun.c
@@ -32,7 +32,7 @@
#define TUN_EXCH_MAX_PACKETS 256
/* Maximum exchange packet size - empirically determined by net buffer list (pool) limitations */
#define TUN_EXCH_MAX_PACKET_SIZE 0xF000
-#define TUN_EXCH_ALIGNMENT 16 /* Memory alignment in exchange buffers */
+#define TUN_EXCH_ALIGNMENT sizeof(ULONG) /* Memory alignment in exchange buffers */
/* Maximum IP packet size (headers + payload) */
#define TUN_EXCH_MAX_IP_PACKET_SIZE (TUN_EXCH_MAX_PACKET_SIZE - sizeof(TUN_PACKET))
/* Maximum size of read/write exchange buffer */
@@ -60,7 +60,8 @@
typedef struct _TUN_PACKET
{
ULONG Size; /* Size of packet data (TUN_EXCH_MAX_IP_PACKET_SIZE max) */
- _Field_size_bytes_(Size) __declspec(align(TUN_EXCH_ALIGNMENT)) UCHAR Data[]; /* Packet data */
+ _Field_size_bytes_(Size)
+ UCHAR Data[]; /* Packet data */
} TUN_PACKET;
typedef enum _TUN_FLAGS