aboutsummaryrefslogtreecommitdiffstats
path: root/wireguard-go-bridge
diff options
context:
space:
mode:
authorJason A. Donenfeld <Jason@zx2c4.com>2018-10-27 00:57:58 +0200
committerJason A. Donenfeld <Jason@zx2c4.com>2018-10-27 01:03:28 +0200
commit95fefbdb39dfdac91567c6454e74a354203ef03f (patch)
tree161174e725a7273c15c0e3685a46cef18b0e547c /wireguard-go-bridge
parentbridge: go get requires arch paths (diff)
downloadwireguard-apple-95fefbdb39dfdac91567c6454e74a354203ef03f.tar.xz
wireguard-apple-95fefbdb39dfdac91567c6454e74a354203ef03f.zip
Allow customizing MTU
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
Diffstat (limited to 'wireguard-go-bridge')
-rw-r--r--wireguard-go-bridge/example.c6
-rw-r--r--wireguard-go-bridge/src/api-ios.go4
-rw-r--r--wireguard-go-bridge/src/tun/tun_ios.go11
-rw-r--r--wireguard-go-bridge/wireguard.h3
4 files changed, 16 insertions, 8 deletions
diff --git a/wireguard-go-bridge/example.c b/wireguard-go-bridge/example.c
index 912d181d..33ed1f08 100644
--- a/wireguard-go-bridge/example.c
+++ b/wireguard-go-bridge/example.c
@@ -14,14 +14,14 @@ static struct {
static bool is_closed = false;
-ssize_t do_read(const void *ctx, const unsigned char *buf, size_t len)
+ssize_t do_read(void *ctx, unsigned char *buf, size_t len)
{
printf("Reading from instance with ctx %p into buffer %p of length %zu\n", ctx, buf, len);
sleep(1);
return is_closed ? -1 : 0;
}
-ssize_t do_write(const void *ctx, const unsigned char *buf, size_t len)
+ssize_t do_write(void *ctx, unsigned char *buf, size_t len)
{
printf("Writing from instance with ctx %p into buffer %p of length %zu\n", ctx, buf, len);
return len;
@@ -38,7 +38,7 @@ int main(int argc, char *argv[])
printf("WireGuard Go Version %s\n", wgVersion());
wgSetLogger(do_log);
- handle = wgTurnOn((gostring_t){ .p = "test", .n = 4 }, (gostring_t){ .p = "", .n = 0 }, do_read, do_write, &ctx);
+ handle = wgTurnOn((gostring_t){ .p = "test", .n = 4 }, (gostring_t){ .p = "", .n = 0 }, 0, do_read, do_write, &ctx);
sleep(5);
is_closed = true;
wgTurnOff(handle);
diff --git a/wireguard-go-bridge/src/api-ios.go b/wireguard-go-bridge/src/api-ios.go
index dcc588fd..7bb648e5 100644
--- a/wireguard-go-bridge/src/api-ios.go
+++ b/wireguard-go-bridge/src/api-ios.go
@@ -79,7 +79,7 @@ func wgSetLogger(loggerFn uintptr) {
}
//export wgTurnOn
-func wgTurnOn(ifnameRef string, settings string, readFn uintptr, writeFn uintptr, ctx uintptr) int32 {
+func wgTurnOn(ifnameRef string, settings string, mtu uint16, readFn uintptr, writeFn uintptr, ctx uintptr) int32 {
interfaceName := string([]byte(ifnameRef))
logger := &Logger{
@@ -90,7 +90,7 @@ func wgTurnOn(ifnameRef string, settings string, readFn uintptr, writeFn uintptr
logger.Debug.Println("Debug log enabled")
- tun := tun.CreateTUN(1280, unsafe.Pointer(readFn), unsafe.Pointer(writeFn), unsafe.Pointer(ctx))
+ tun := tun.CreateTUN(mtu, unsafe.Pointer(readFn), unsafe.Pointer(writeFn), unsafe.Pointer(ctx))
logger.Info.Println("Attaching to interface")
device := NewDevice(tun, logger)
diff --git a/wireguard-go-bridge/src/tun/tun_ios.go b/wireguard-go-bridge/src/tun/tun_ios.go
index 93a0503f..cafe33b7 100644
--- a/wireguard-go-bridge/src/tun/tun_ios.go
+++ b/wireguard-go-bridge/src/tun/tun_ios.go
@@ -26,10 +26,17 @@ type nativeTun struct {
ctx unsafe.Pointer
}
-func CreateTUN(mtu int, readFn unsafe.Pointer, writeFn unsafe.Pointer, ctx unsafe.Pointer) TUNDevice {
+func CreateTUN(mtu uint16, readFn unsafe.Pointer, writeFn unsafe.Pointer, ctx unsafe.Pointer) TUNDevice {
+ if mtu == 0 {
+ /* 0 means automatic MTU, which iOS makes outerMTU-80-15. The 80 is for
+ * WireGuard and the 15 ensures our padding will work. Therefore, it's
+ * safe to have this code assume a massive MTU.
+ */
+ mtu = ^mtu
+ }
tun := &nativeTun{
events: make(chan TUNEvent, 10),
- mtu: mtu,
+ mtu: int(mtu),
readFn: readFn,
writeFn: writeFn,
ctx: ctx,
diff --git a/wireguard-go-bridge/wireguard.h b/wireguard-go-bridge/wireguard.h
index effae8ea..a0950bf9 100644
--- a/wireguard-go-bridge/wireguard.h
+++ b/wireguard-go-bridge/wireguard.h
@@ -7,12 +7,13 @@
#define WIREGUARD_H
#include <sys/types.h>
+#include <stdint.h>
typedef struct { const char *p; size_t n; } gostring_t;
typedef ssize_t(*read_write_fn_t)(void *ctx, unsigned char *buf, size_t len);
typedef void(*logger_fn_t)(int level, const char *tag, const char *msg);
extern void wgSetLogger(logger_fn_t logger_fn);
-extern int wgTurnOn(gostring_t ifname, gostring_t settings, read_write_fn_t read_fn, read_write_fn_t write_fn, void *ctx);
+extern int wgTurnOn(gostring_t ifname, gostring_t settings, uint16_t mtu, read_write_fn_t read_fn, read_write_fn_t write_fn, void *ctx);
extern void wgTurnOff(int handle);
extern char *wgVersion();